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
97
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
149
154
159
164
169
181
194
199 return mChannelConversionAllowed;
200 }
201
206 return mFormatConversionAllowed;
207 }
208
213 return mSampleRateConversionQuality;
214 }
215
220 return mChannelMask;
221 }
222
227
232
237
238protected:
241 std::shared_ptr<AudioStreamDataCallback> mSharedDataCallback;
242
245 std::shared_ptr<AudioStreamErrorCallback> mSharedErrorCallback;
246
260 ChannelMask mChannelMask = ChannelMask::Unspecified;
261
270
281
284
287
289 std::string mPackageName;
291 std::string mAttributionTag;
292
297
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.
311
314 switch (mFormat) {
316 case AudioFormat::I16:
318 case AudioFormat::I24:
319 case AudioFormat::I32:
321 break;
322
323 default:
324 return Result::ErrorInvalidFormat;
325 }
326
327 switch (mSampleRateConversionQuality) {
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
Definition AudioClock.h:24
Usage
Definition Definitions.h:316
PerformanceMode
Definition Definitions.h:233
ContentType
Definition Definitions.h:392
@ Music
Definition Definitions.h:402
InputPreset
Definition Definitions.h:425
@ VoiceRecognition
Definition Definitions.h:439
Result
Definition Definitions.h:172
PrivacySensitiveMode
Definition Definitions.h:775
SessionId
Definition Definitions.h:467
@ None
Definition Definitions.h:473
AllowedCapturePolicy
Definition Definitions.h:802
SampleRateConversionQuality
Definition Definitions.h:279
SharingMode
Definition Definitions.h:208
AudioFormat
Definition Definitions.h:93
constexpr int32_t kUnspecified
Definition Definitions.h:31
ChannelMask
Definition Definitions.h:526
Direction
Definition Definitions.h:77
SpatializationBehavior
Definition Definitions.h:748