Oboe 1.2 A library for creating real-time audio apps on Android

AudioStreamBuilder.h
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 OBOE_STREAM_BUILDER_H_
18 #define OBOE_STREAM_BUILDER_H_
19
20 #include "oboe/Definitions.h"
21 #include "oboe/AudioStreamBase.h"
22
23 namespace oboe {
24
25 // This depends on AudioStream, so we use forward declaration, it will close and delete the stream
26 struct StreamDeleterFunctor;
27 using ManagedStream = std::unique_ptr<AudioStream, StreamDeleterFunctor>;
31 class AudioStreamBuilder : public AudioStreamBase {
32 public:
33
34 AudioStreamBuilder() : AudioStreamBase() {}
35
36 AudioStreamBuilder(const AudioStreamBase &audioStreamBase): AudioStreamBase(audioStreamBase) {}
37
44 AudioStreamBuilder *setChannelCount(int channelCount) {
45 mChannelCount = channelCount;
46 return this;
47 }
48
54 AudioStreamBuilder *setDirection(Direction direction) {
55 mDirection = direction;
56 return this;
57 }
58
70 AudioStreamBuilder *setSampleRate(int32_t sampleRate) {
71 mSampleRate = sampleRate;
72 return this;
73 }
74
89 AudioStreamBuilder *setFramesPerCallback(int framesPerCallback) {
90 mFramesPerCallback = framesPerCallback;
91 return this;
92 }
93
100 AudioStreamBuilder *setFormat(AudioFormat format) {
101 mFormat = format;
102 return this;
103 }
104
117 AudioStreamBuilder *setBufferCapacityInFrames(int32_t bufferCapacityInFrames) {
118 mBufferCapacityInFrames = bufferCapacityInFrames;
119 return this;
120 }
121
132 AudioApi getAudioApi() const { return mAudioApi; }
133
147 AudioStreamBuilder *setAudioApi(AudioApi audioApi) {
148 mAudioApi = audioApi;
149 return this;
150 }
151
159 static bool isAAudioSupported();
160
169 static bool isAAudioRecommended();
170
179 AudioStreamBuilder *setSharingMode(SharingMode sharingMode) {
180 mSharingMode = sharingMode;
181 return this;
182 }
183
192 AudioStreamBuilder *setPerformanceMode(PerformanceMode performanceMode) {
193 mPerformanceMode = performanceMode;
194 return this;
195 }
196
197
210 AudioStreamBuilder *setUsage(Usage usage) {
211 mUsage = usage;
212 return this;
213 }
214
227 AudioStreamBuilder *setContentType(ContentType contentType) {
228 mContentType = contentType;
229 return this;
230 }
231
247 AudioStreamBuilder *setInputPreset(InputPreset inputPreset) {
248 mInputPreset = inputPreset;
249 return this;
250 }
251
276 AudioStreamBuilder *setSessionId(SessionId sessionId) {
277 mSessionId = sessionId;
278 return this;
279 }
280
299 AudioStreamBuilder *setDeviceId(int32_t deviceId) {
300 mDeviceId = deviceId;
301 return this;
302 }
303
325 AudioStreamBuilder *setCallback(AudioStreamCallback *streamCallback) {
326 mStreamCallback = streamCallback;
327 return this;
328 }
329
339 AudioStreamBuilder *setChannelConversionAllowed(bool allowed) {
340 mChannelConversionAllowed = allowed;
341 return this;
342 }
343
351 AudioStreamBuilder *setFormatConversionAllowed(bool allowed) {
352 mFormatConversionAllowed = allowed;
353 return this;
354 }
355
367 AudioStreamBuilder *setSampleRateConversionQuality(SampleRateConversionQuality quality) {
368 mSampleRateConversionQuality = quality;
369 return this;
370 }
371
375 bool willUseAAudio() const {
376 return (mAudioApi == AudioApi::AAudio && isAAudioSupported())
377 || (mAudioApi == AudioApi::Unspecified && isAAudioRecommended());
378 }
379
388 Result openStream(AudioStream **stream);
389
390
400 Result openManagedStream(ManagedStream &stream);
401
402 private:
403
408 bool isCompatible(AudioStreamBase &other);
409
417 oboe::AudioStream *build();
418
419 AudioApi mAudioApi = AudioApi::Unspecified;
420 };
421
422 } // namespace oboe
423
424 #endif /* OBOE_STREAM_BUILDER_H_ */
oboe::AudioStreamBuilder::setDeviceId
AudioStreamBuilder * setDeviceId(int32_t deviceId)
Definition: AudioStreamBuilder.h:299
oboe::AudioApi::AAudio
oboe::AudioStreamBuilder
Definition: AudioStreamBuilder.h:31
oboe::AudioStreamBase::mSessionId
SessionId mSessionId
Definition: AudioStreamBase.h:189
oboe::AudioStreamBuilder::setPerformanceMode
AudioStreamBuilder * setPerformanceMode(PerformanceMode performanceMode)
Definition: AudioStreamBuilder.h:192
oboe::AudioStreamBase::mDirection
Direction mDirection
Definition: AudioStreamBase.h:176
oboe::AudioStreamBase::mFormat
AudioFormat mFormat
Definition: AudioStreamBase.h:174
oboe::AudioStreamBase::mContentType
ContentType mContentType
Definition: AudioStreamBase.h:183
oboe::AudioStreamBuilder::isAAudioRecommended
static bool isAAudioRecommended()
oboe::AudioStreamBuilder::setSampleRateConversionQuality
AudioStreamBuilder * setSampleRateConversionQuality(SampleRateConversionQuality quality)
Definition: AudioStreamBuilder.h:367
oboe::PerformanceMode
PerformanceMode
Definition: Definitions.h:192
oboe::SessionId
SessionId
Definition: Definitions.h:414
oboe::AudioStreamBuilder::setSessionId
AudioStreamBuilder * setSessionId(SessionId sessionId)
Definition: AudioStreamBuilder.h:276
oboe::AudioStreamBase::mPerformanceMode
PerformanceMode mPerformanceMode
Definition: AudioStreamBase.h:178
oboe::AudioStreamCallback
Definition: AudioStreamCallback.h:33
oboe::AudioStreamBase::mSharingMode
SharingMode mSharingMode
Definition: AudioStreamBase.h:172
oboe::AudioStreamBuilder::setContentType
AudioStreamBuilder * setContentType(ContentType contentType)
Definition: AudioStreamBuilder.h:227
oboe::AudioStreamBase::mChannelCount
int32_t mChannelCount
Definition: AudioStreamBase.h:156
oboe::AudioApi
AudioApi
Definition: Definitions.h:213
oboe::ContentType
ContentType
Definition: Definitions.h:339
oboe::AudioStreamBuilder::setUsage
AudioStreamBuilder * setUsage(Usage usage)
Definition: AudioStreamBuilder.h:210
oboe::AudioStreamBase::mDeviceId
int32_t mDeviceId
Definition: AudioStreamBase.h:160
oboe::AudioStreamBuilder::isAAudioSupported
static bool isAAudioSupported()
oboe::AudioStreamBuilder::setChannelConversionAllowed
AudioStreamBuilder * setChannelConversionAllowed(bool allowed)
Definition: AudioStreamBuilder.h:339
oboe::AudioStreamBuilder::setFramesPerCallback
AudioStreamBuilder * setFramesPerCallback(int framesPerCallback)
Definition: AudioStreamBuilder.h:89
oboe::AudioStreamBuilder::setDirection
AudioStreamBuilder * setDirection(Direction direction)
Definition: AudioStreamBuilder.h:54
oboe::AudioStreamBuilder::setFormat
AudioStreamBuilder * setFormat(AudioFormat format)
Definition: AudioStreamBuilder.h:100
oboe::AudioStreamBase::mUsage
Usage mUsage
Definition: AudioStreamBase.h:181
oboe::AudioStream
Definition: AudioStream.h:44
oboe::Usage
Usage
Definition: Definitions.h:263
oboe::AudioStreamBuilder::setAudioApi
AudioStreamBuilder * setAudioApi(AudioApi audioApi)
Definition: AudioStreamBuilder.h:147
oboe::AudioStreamBuilder::setInputPreset
AudioStreamBuilder * setInputPreset(InputPreset inputPreset)
Definition: AudioStreamBuilder.h:247
oboe::AudioStreamBuilder::openManagedStream
Result openManagedStream(ManagedStream &stream)
oboe::AudioStreamBuilder::setSampleRate
AudioStreamBuilder * setSampleRate(int32_t sampleRate)
Definition: AudioStreamBuilder.h:70
oboe::AudioStreamBase::mSampleRate
int32_t mSampleRate
Definition: AudioStreamBase.h:158
oboe::AudioStreamBase
Definition: AudioStreamBase.h:29
oboe::AudioStreamBase::mBufferCapacityInFrames
int32_t mBufferCapacityInFrames
Definition: AudioStreamBase.h:162
oboe::AudioStreamBuilder::setBufferCapacityInFrames
AudioStreamBuilder * setBufferCapacityInFrames(int32_t bufferCapacityInFrames)
Definition: AudioStreamBuilder.h:117
oboe::AudioStreamBuilder::openStream
Result openStream(AudioStream **stream)
oboe::AudioFormat
AudioFormat
Definition: Definitions.h:94
oboe::Result
Result
Definition: Definitions.h:131
oboe::AudioStreamBuilder::setSharingMode
AudioStreamBuilder * setSharingMode(SharingMode sharingMode)
Definition: AudioStreamBuilder.h:179
oboe
Definition: AudioStream.h:31
oboe::AudioStreamBuilder::willUseAAudio
bool willUseAAudio() const
Definition: AudioStreamBuilder.h:375
oboe::SampleRateConversionQuality
SampleRateConversionQuality
Definition: Definitions.h:235
oboe::AudioStreamBase::mInputPreset
InputPreset mInputPreset
Definition: AudioStreamBase.h:187
oboe::AudioStreamBase::mStreamCallback
AudioStreamCallback * mStreamCallback
Definition: AudioStreamBase.h:152
oboe::Direction
Direction
Definition: Definitions.h:78
oboe::SharingMode
SharingMode
Definition: Definitions.h:167
oboe::InputPreset
InputPreset
Definition: Definitions.h:372
oboe::AudioStreamBuilder::setChannelCount
AudioStreamBuilder * setChannelCount(int channelCount)
Definition: AudioStreamBuilder.h:44
oboe::AudioStreamBuilder::setCallback
AudioStreamBuilder * setCallback(AudioStreamCallback *streamCallback)
Definition: AudioStreamBuilder.h:325
oboe::AudioStreamBase::mFramesPerCallback
int32_t mFramesPerCallback
Definition: AudioStreamBase.h:154
oboe::AudioStreamBuilder::setFormatConversionAllowed
AudioStreamBuilder * setFormatConversionAllowed(bool allowed)
Definition: AudioStreamBuilder.h:351
oboe::AudioStreamBuilder::getAudioApi
AudioApi getAudioApi() const
Definition: AudioStreamBuilder.h:132