Oboe
A library for creating real-time audio apps on Android
Loading...
Searching...
No Matches
AudioStreamBase.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_BASE_H_
18#define OBOE_STREAM_BASE_H_
19
20#include <memory>
21#include <string>
22#include "oboe/AudioStreamCallback.h"
23#include "oboe/Definitions.h"
24
25namespace oboe {
26
31
32public:
33
35
36 virtual ~AudioStreamBase() = default;
37
38 // This class only contains primitives so we can use default constructor and copy methods.
39
44
49
53 int32_t getChannelCount() const { return mChannelCount; }
54
58 Direction getDirection() const { return mDirection; }
59
63 int32_t getSampleRate() const { return mSampleRate; }
64
68 int32_t getFramesPerCallback() const { return getFramesPerDataCallback(); }
69
73 int32_t getFramesPerDataCallback() const { return mFramesPerCallback; }
74
78 AudioFormat getFormat() const { return mFormat; }
79
86 virtual int32_t getBufferSizeInFrames() { return mBufferSizeInFrames; }
87
91 virtual int32_t getBufferCapacityInFrames() const { return mBufferCapacityInFrames; }
92
97
102
106 int32_t getDeviceId() const { return mDeviceId; }
107
113 return mDataCallback;
114 }
115
121 return mErrorCallback;
122 }
123
128 return mDataCallback != nullptr;
129 }
130
137 return mErrorCallback != nullptr;
138 }
139
143 Usage getUsage() const { return mUsage; }
144
149
154
159
164 return mChannelConversionAllowed;
165 }
166
171 return mFormatConversionAllowed;
172 }
173
178 return mSampleRateConversionQuality;
179 }
180
185 return mChannelMask;
186 }
187
188protected:
191 std::shared_ptr<AudioStreamDataCallback> mSharedDataCallback;
192
195 std::shared_ptr<AudioStreamErrorCallback> mSharedErrorCallback;
196
210 ChannelMask mChannelMask = ChannelMask::Unspecified;
211
220
231
233 std::string mPackageName;
235 std::string mAttributionTag;
236
237 // Control whether Oboe can convert channel counts to achieve optimal results.
238 bool mChannelConversionAllowed = false;
239 // Control whether Oboe can convert data formats to achieve optimal results.
240 bool mFormatConversionAllowed = false;
241 // Control whether and how Oboe can convert sample rates to achieve optimal results.
243
246 switch (mFormat) {
248 case AudioFormat::I16:
250 case AudioFormat::I24:
251 case AudioFormat::I32:
252 break;
253
254 default:
255 return Result::ErrorInvalidFormat;
256 }
257
258 switch (mSampleRateConversionQuality) {
265 return Result::OK;
266 default:
267 return Result::ErrorIllegalArgument;
268 }
269 }
270};
271
272} // namespace oboe
273
274#endif /* OBOE_STREAM_BASE_H_ */
Definition: AudioStreamBase.h:30
int32_t getDeviceId() const
Definition: AudioStreamBase.h:106
Usage getUsage() const
Definition: AudioStreamBase.h:143
AudioStreamDataCallback * getDataCallback() const
Definition: AudioStreamBase.h:112
SampleRateConversionQuality getSampleRateConversionQuality() const
Definition: AudioStreamBase.h:177
InputPreset mInputPreset
Definition: AudioStreamBase.h:228
SharingMode getSharingMode() const
Definition: AudioStreamBase.h:96
int32_t mDeviceId
Definition: AudioStreamBase.h:204
Direction mDirection
Definition: AudioStreamBase.h:217
PerformanceMode getPerformanceMode() const
Definition: AudioStreamBase.h:101
int32_t mFramesPerCallback
Definition: AudioStreamBase.h:198
int32_t mBufferSizeInFrames
Definition: AudioStreamBase.h:208
Usage mUsage
Definition: AudioStreamBase.h:222
InputPreset getInputPreset() const
Definition: AudioStreamBase.h:153
virtual Result isValidConfig()
Definition: AudioStreamBase.h:245
ContentType mContentType
Definition: AudioStreamBase.h:224
int32_t mChannelCount
Definition: AudioStreamBase.h:200
AudioStreamDataCallback * mDataCallback
Definition: AudioStreamBase.h:190
Direction getDirection() const
Definition: AudioStreamBase.h:58
AudioStreamErrorCallback * getErrorCallback() const
Definition: AudioStreamBase.h:120
AudioFormat mFormat
Definition: AudioStreamBase.h:215
int32_t getChannelCount() const
Definition: AudioStreamBase.h:53
int32_t getFramesPerCallback() const
Definition: AudioStreamBase.h:68
ChannelMask getChannelMask() const
Definition: AudioStreamBase.h:184
int32_t mSampleRate
Definition: AudioStreamBase.h:202
bool isDataCallbackSpecified() const
Definition: AudioStreamBase.h:127
SessionId getSessionId() const
Definition: AudioStreamBase.h:158
ChannelMask mChannelMask
Definition: AudioStreamBase.h:210
bool isChannelConversionAllowed() const
Definition: AudioStreamBase.h:163
AudioStreamBase(const AudioStreamBase &)=default
ContentType getContentType() const
Definition: AudioStreamBase.h:148
virtual int32_t getBufferCapacityInFrames() const
Definition: AudioStreamBase.h:91
AudioFormat getFormat() const
Definition: AudioStreamBase.h:78
PerformanceMode mPerformanceMode
Definition: AudioStreamBase.h:219
int32_t getFramesPerDataCallback() const
Definition: AudioStreamBase.h:73
SessionId mSessionId
Definition: AudioStreamBase.h:230
std::string mPackageName
Definition: AudioStreamBase.h:233
int32_t mBufferCapacityInFrames
Definition: AudioStreamBase.h:206
bool isFormatConversionAllowed() const
Definition: AudioStreamBase.h:170
AudioStreamErrorCallback * mErrorCallback
Definition: AudioStreamBase.h:194
AudioStreamBase & operator=(const AudioStreamBase &)=default
std::string mAttributionTag
Definition: AudioStreamBase.h:235
SharingMode mSharingMode
Definition: AudioStreamBase.h:213
int32_t getSampleRate() const
Definition: AudioStreamBase.h:63
bool isErrorCallbackSpecified() const
Definition: AudioStreamBase.h:136
virtual int32_t getBufferSizeInFrames()
Definition: AudioStreamBase.h:86
Definition: AudioStreamCallback.h:34
Definition: AudioStreamCallback.h:101
Definition: AudioStream.h:31
Usage
Definition: Definitions.h:301
PerformanceMode
Definition: Definitions.h:218
ContentType
Definition: Definitions.h:377
@ Music
Definition: Definitions.h:387
InputPreset
Definition: Definitions.h:410
@ VoiceRecognition
Definition: Definitions.h:424
Result
Definition: Definitions.h:157
SessionId
Definition: Definitions.h:452
@ None
Definition: Definitions.h:458
SampleRateConversionQuality
Definition: Definitions.h:264
SharingMode
Definition: Definitions.h:193
AudioFormat
Definition: Definitions.h:93
constexpr int32_t kUnspecified
Definition: Definitions.h:31
ChannelMask
Definition: Definitions.h:506
Direction
Definition: Definitions.h:77