# Oboe: include/oboe/AudioStreamBuilder.h Source File

AudioStreamBuilder.h
/*
* Copyright 2015 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OBOE_STREAM_BUILDER_H_
#define OBOE_STREAM_BUILDER_H_
#include "oboe/Definitions.h"
#include "oboe/AudioStreamBase.h"
namespace oboe {
// This depends on AudioStream, so we use forward declaration, it will close and delete the stream
struct StreamDeleterFunctor;
using ManagedStream = std::unique_ptr<AudioStream, StreamDeleterFunctor>;
class AudioStreamBuilder : public AudioStreamBase {
public:
AudioStreamBuilder() : AudioStreamBase() {}
AudioStreamBuilder(const AudioStreamBase &audioStreamBase): AudioStreamBase(audioStreamBase) {}
AudioStreamBuilder *setChannelCount(int channelCount) {
mChannelCount = channelCount;
return this;
}
AudioStreamBuilder *setDirection(Direction direction) {
mDirection = direction;
return this;
}
AudioStreamBuilder *setSampleRate(int32_t sampleRate) {
mSampleRate = sampleRate;
return this;
}
AudioStreamBuilder *setFramesPerCallback(int framesPerCallback) {
mFramesPerCallback = framesPerCallback;
return this;
}
AudioStreamBuilder *setFormat(AudioFormat format) {
mFormat = format;
return this;
}
AudioStreamBuilder *setBufferCapacityInFrames(int32_t bufferCapacityInFrames) {
mBufferCapacityInFrames = bufferCapacityInFrames;
return this;
}
AudioApi getAudioApi() const { return mAudioApi; }
AudioStreamBuilder *setAudioApi(AudioApi audioApi) {
mAudioApi = audioApi;
return this;
}
static bool isAAudioSupported();
static bool isAAudioRecommended();
AudioStreamBuilder *setSharingMode(SharingMode sharingMode) {
mSharingMode = sharingMode;
return this;
}
AudioStreamBuilder *setPerformanceMode(PerformanceMode performanceMode) {
mPerformanceMode = performanceMode;
return this;
}
AudioStreamBuilder *setUsage(Usage usage) {
mUsage = usage;
return this;
}
AudioStreamBuilder *setContentType(ContentType contentType) {
mContentType = contentType;
return this;
}
AudioStreamBuilder *setInputPreset(InputPreset inputPreset) {
mInputPreset = inputPreset;
return this;
}
AudioStreamBuilder *setSessionId(SessionId sessionId) {
mSessionId = sessionId;
return this;
}
AudioStreamBuilder *setDeviceId(int32_t deviceId) {
mDeviceId = deviceId;
return this;
}
AudioStreamBuilder *setCallback(AudioStreamCallback *streamCallback) {
mStreamCallback = streamCallback;
return this;
}
AudioStreamBuilder *setChannelConversionAllowed(bool allowed) {
mChannelConversionAllowed = allowed;
return this;
}
AudioStreamBuilder *setFormatConversionAllowed(bool allowed) {
mFormatConversionAllowed = allowed;
return this;
}
AudioStreamBuilder *setSampleRateConversionQuality(SampleRateConversionQuality quality) {
mSampleRateConversionQuality = quality;
return this;
}
bool willUseAAudio() const {
return (mAudioApi == AudioApi::AAudio && isAAudioSupported())
|| (mAudioApi == AudioApi::Unspecified && isAAudioRecommended());
}
Result openStream(AudioStream **stream);
Result openManagedStream(ManagedStream &stream);
private:
bool isCompatible(AudioStreamBase &other);
oboe::AudioStream *build();
AudioApi mAudioApi = AudioApi::Unspecified;
};
} // namespace oboe
#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