AudioStreamBuilder.h revision 901f65deb49786f4dffd39ac965c0bb681392c0b
1/*
2 * Copyright 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef AAUDIO_AUDIO_STREAM_BUILDER_H
18#define AAUDIO_AUDIO_STREAM_BUILDER_H
19
20#include <stdint.h>
21
22#include <aaudio/AAudio.h>
23
24#include "AAudioStreamParameters.h"
25#include "AudioStream.h"
26
27namespace aaudio {
28
29/**
30 * Factory class for an AudioStream.
31 */
32class AudioStreamBuilder : public AAudioStreamParameters {
33public:
34    AudioStreamBuilder();
35
36    ~AudioStreamBuilder();
37
38    aaudio_direction_t getDirection() const {
39        return mDirection;
40    }
41
42    AudioStreamBuilder* setDirection(aaudio_direction_t direction) {
43        mDirection = direction;
44        return this;
45    }
46
47    bool isSharingModeMatchRequired() const {
48        return mSharingModeMatchRequired;
49    }
50
51    AudioStreamBuilder* setSharingModeMatchRequired(bool required) {
52        mSharingModeMatchRequired = required;
53        return this;
54    }
55
56    int32_t getPerformanceMode() const {
57        return mPerformanceMode;
58    }
59
60    AudioStreamBuilder* setPerformanceMode(aaudio_performance_mode_t performanceMode) {
61        mPerformanceMode = performanceMode;
62        return this;
63    }
64
65    AAudioStream_dataCallback getDataCallbackProc() const {
66        return mDataCallbackProc;
67    }
68
69    AudioStreamBuilder* setDataCallbackProc(AAudioStream_dataCallback proc) {
70        mDataCallbackProc = proc;
71        return this;
72    }
73
74    void *getDataCallbackUserData() const {
75        return mDataCallbackUserData;
76    }
77
78    AudioStreamBuilder* setDataCallbackUserData(void *userData) {
79        mDataCallbackUserData = userData;
80        return this;
81    }
82
83    AAudioStream_errorCallback getErrorCallbackProc() const {
84        return mErrorCallbackProc;
85    }
86
87    AudioStreamBuilder* setErrorCallbackProc(AAudioStream_errorCallback proc) {
88        mErrorCallbackProc = proc;
89        return this;
90    }
91
92    AudioStreamBuilder* setErrorCallbackUserData(void *userData) {
93        mErrorCallbackUserData = userData;
94        return this;
95    }
96
97    void *getErrorCallbackUserData() const {
98        return mErrorCallbackUserData;
99    }
100
101    int32_t getFramesPerDataCallback() const {
102        return mFramesPerDataCallback;
103    }
104
105    AudioStreamBuilder* setFramesPerDataCallback(int32_t sizeInFrames) {
106        mFramesPerDataCallback = sizeInFrames;
107        return this;
108    }
109
110    aaudio_result_t build(AudioStream **streamPtr);
111
112    virtual aaudio_result_t validate() const override;
113
114private:
115    bool                       mSharingModeMatchRequired = false; // must match sharing mode requested
116    aaudio_direction_t         mDirection = AAUDIO_DIRECTION_OUTPUT;
117    aaudio_performance_mode_t  mPerformanceMode = AAUDIO_PERFORMANCE_MODE_NONE;
118
119    AAudioStream_dataCallback  mDataCallbackProc = nullptr;  // external callback functions
120    void                      *mDataCallbackUserData = nullptr;
121    int32_t                    mFramesPerDataCallback = AAUDIO_UNSPECIFIED; // frames
122
123    AAudioStream_errorCallback mErrorCallbackProc = nullptr;
124    void                      *mErrorCallbackUserData = nullptr;
125};
126
127} /* namespace aaudio */
128
129#endif //AAUDIO_AUDIO_STREAM_BUILDER_H
130