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
54
58 Direction getDirection() const { return mDirection; }
59
63 int32_t getSampleRate() const { return mSampleRate; }
64
69
74
78 AudioFormat getFormat() const { return mFormat; }
79
87
92
96 SharingMode getSharingMode() const { return mSharingMode; }
97
101 PerformanceMode getPerformanceMode() const { return mPerformanceMode; }
102
106 int32_t getDeviceId() const { return mDeviceId; }
107
115
123
128 return mDataCallback != nullptr;
129 }
130
137 return mErrorCallback != nullptr;
138 }
139
143 Usage getUsage() const { return mUsage; }
144
148 ContentType getContentType() const { return mContentType; }
149
153 InputPreset getInputPreset() const { return mInputPreset; }
154
158 SessionId getSessionId() const { return mSessionId; }
159
164
168 SpatializationBehavior getSpatializationBehavior() const { return mSpatializationBehavior; }
169
180 AllowedCapturePolicy getAllowedCapturePolicy() const { return mAllowedCapturePolicy; }
181
193 PrivacySensitiveMode getPrivacySensitiveMode() const { return mPrivacySensitiveMode; }
194
199 return mChannelConversionAllowed;
200 }
201
206 return mFormatConversionAllowed;
207 }
208
212 SampleRateConversionQuality getSampleRateConversionQuality() const {
213 return mSampleRateConversionQuality;
214 }
215
219 ChannelMask getChannelMask() const {
220 return mChannelMask;
221 }
222
227
232
236 AudioFormat getHardwareFormat() const { return mHardwareFormat; }
237
238protected:
241 std::shared_ptr<AudioStreamDataCallback> mSharedDataCallback;
242
245 std::shared_ptr<AudioStreamErrorCallback> mSharedErrorCallback;
246
250 int32_t mChannelCount = kUnspecified;
252 int32_t mSampleRate = kUnspecified;
254 int32_t mDeviceId = kUnspecified;
260 ChannelMask mChannelMask = ChannelMask::Unspecified;
261
263 SharingMode mSharingMode = SharingMode::Shared;
265 AudioFormat mFormat = AudioFormat::Unspecified;
267 Direction mDirection = Direction::Output;
269 PerformanceMode mPerformanceMode = PerformanceMode::None;
270
272 Usage mUsage = Usage::Media;
274 ContentType mContentType = ContentType::Music;
278 InputPreset mInputPreset = InputPreset::VoiceRecognition;
280 SessionId mSessionId = SessionId::None;
281
283 AllowedCapturePolicy mAllowedCapturePolicy = AllowedCapturePolicy::Unspecified;
284
286 PrivacySensitiveMode mPrivacySensitiveMode = PrivacySensitiveMode::Unspecified;
287
289 std::string mPackageName;
291 std::string mAttributionTag;
292
296 SpatializationBehavior mSpatializationBehavior = SpatializationBehavior::Unspecified;
297
303 AudioFormat mHardwareFormat = AudioFormat::Unspecified;
304
305 // Control whether Oboe can convert channel counts to achieve optimal results.
306 bool mChannelConversionAllowed = false;
307 // Control whether Oboe can convert data formats to achieve optimal results.
308 bool mFormatConversionAllowed = false;
309 // Control whether and how Oboe can convert sample rates to achieve optimal results.
310 SampleRateConversionQuality mSampleRateConversionQuality = SampleRateConversionQuality::Medium;
311
313 virtual Result isValidConfig() {
314 switch (mFormat) {
315 case AudioFormat::Unspecified:
316 case AudioFormat::I16:
317 case AudioFormat::Float:
318 case AudioFormat::I24:
319 case AudioFormat::I32:
320 case AudioFormat::IEC61937:
321 break;
322
323 default:
324 return Result::ErrorInvalidFormat;
325 }
326
327 switch (mSampleRateConversionQuality) {
328 case SampleRateConversionQuality::None:
329 case SampleRateConversionQuality::Fastest:
330 case SampleRateConversionQuality::Low:
331 case SampleRateConversionQuality::Medium:
332 case SampleRateConversionQuality::High:
333 case SampleRateConversionQuality::Best:
334 return Result::OK;
335 default:
336 return Result::ErrorIllegalArgument;
337 }
338 }
339};
340
341} // namespace oboe
342
343#endif /* OBOE_STREAM_BASE_H_ */
Definition AudioStreamBase.h:30
int32_t mHardwareSampleRate
Definition AudioStreamBase.h:301
int32_t getDeviceId() const
Definition AudioStreamBase.h:106
Usage getUsage() const
Definition AudioStreamBase.h:143
AudioFormat mHardwareFormat
Definition AudioStreamBase.h:303
SpatializationBehavior mSpatializationBehavior
Definition AudioStreamBase.h:296
AudioStreamDataCallback * getDataCallback() const
Definition AudioStreamBase.h:112
SampleRateConversionQuality getSampleRateConversionQuality() const
Definition AudioStreamBase.h:212
InputPreset mInputPreset
Definition AudioStreamBase.h:278
SharingMode getSharingMode() const
Definition AudioStreamBase.h:96
int32_t mDeviceId
Definition AudioStreamBase.h:254
Direction mDirection
Definition AudioStreamBase.h:267
PerformanceMode getPerformanceMode() const
Definition AudioStreamBase.h:101
int32_t mFramesPerCallback
Definition AudioStreamBase.h:248
int32_t mBufferSizeInFrames
Definition AudioStreamBase.h:258
PrivacySensitiveMode getPrivacySensitiveMode() const
Definition AudioStreamBase.h:193
AudioFormat getHardwareFormat() const
Definition AudioStreamBase.h:236
Usage mUsage
Definition AudioStreamBase.h:272
InputPreset getInputPreset() const
Definition AudioStreamBase.h:153
virtual Result isValidConfig()
Definition AudioStreamBase.h:313
ContentType mContentType
Definition AudioStreamBase.h:274
int32_t mChannelCount
Definition AudioStreamBase.h:250
PrivacySensitiveMode mPrivacySensitiveMode
Definition AudioStreamBase.h:286
int32_t getHardwareSampleRate() const
Definition AudioStreamBase.h:231
AudioStreamDataCallback * mDataCallback
Definition AudioStreamBase.h:240
AllowedCapturePolicy mAllowedCapturePolicy
Definition AudioStreamBase.h:283
Direction getDirection() const
Definition AudioStreamBase.h:58
AudioStreamErrorCallback * getErrorCallback() const
Definition AudioStreamBase.h:120
AudioFormat mFormat
Definition AudioStreamBase.h:265
int32_t mHardwareChannelCount
Definition AudioStreamBase.h:299
int32_t getChannelCount() const
Definition AudioStreamBase.h:53
int32_t getFramesPerCallback() const
Definition AudioStreamBase.h:68
ChannelMask getChannelMask() const
Definition AudioStreamBase.h:219
int32_t mSampleRate
Definition AudioStreamBase.h:252
bool isDataCallbackSpecified() const
Definition AudioStreamBase.h:127
bool mIsContentSpatialized
Definition AudioStreamBase.h:294
bool isContentSpatialized() const
Definition AudioStreamBase.h:163
SessionId getSessionId() const
Definition AudioStreamBase.h:158
ChannelMask mChannelMask
Definition AudioStreamBase.h:260
bool isChannelConversionAllowed() const
Definition AudioStreamBase.h:198
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:269
int32_t getFramesPerDataCallback() const
Definition AudioStreamBase.h:73
SessionId mSessionId
Definition AudioStreamBase.h:280
std::string mPackageName
Definition AudioStreamBase.h:289
int32_t mBufferCapacityInFrames
Definition AudioStreamBase.h:256
bool isFormatConversionAllowed() const
Definition AudioStreamBase.h:205
AllowedCapturePolicy getAllowedCapturePolicy() const
Definition AudioStreamBase.h:180
int32_t getHardwareChannelCount() const
Definition AudioStreamBase.h:226
AudioStreamErrorCallback * mErrorCallback
Definition AudioStreamBase.h:244
SpatializationBehavior getSpatializationBehavior() const
Definition AudioStreamBase.h:168
AudioStreamBase & operator=(const AudioStreamBase &)=default
std::string mAttributionTag
Definition AudioStreamBase.h:291
SharingMode mSharingMode
Definition AudioStreamBase.h:263
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:102
Definition ResultWithValue.h:47