Oboe
A library for creating real-time audio apps on Android
Loading...
Searching...
No Matches
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#include "oboe/Utilities.h"
23#include "ResultWithValue.h"
24
25namespace oboe {
26
27 // This depends on AudioStream, so we use forward declaration, it will close and delete the stream
28 struct StreamDeleterFunctor;
29 using ManagedStream = std::unique_ptr<AudioStream, StreamDeleterFunctor>;
30
35public:
36
38
40
53 mChannelMask = ChannelMask::Unspecified;
54 return this;
55 }
56
72 mChannelCount = getChannelCountFromChannelMask(channelMask);
73 return this;
74 }
75
83 return this;
84 }
85
101
108
135
143 mFormat = format;
144 return this;
145 }
146
163
174 AudioApi getAudioApi() const { return mAudioApi; }
175
190 mAudioApi = audioApi;
191 return this;
192 }
193
201 static bool isAAudioSupported();
202
211 static bool isAAudioRecommended();
212
223 return this;
224 }
225
238
239
254 mUsage = usage;
255 return this;
256 }
257
273 return this;
274 }
275
293 return this;
294 }
295
322 return this;
323 }
324
350
368
392
410
428
441 AudioStreamBuilder *setDataCallback(std::shared_ptr<AudioStreamDataCallback> sharedDataCallback) {
442 // Use this raw pointer in the rest of the code to retain backwards compatibility.
444 // Hold a shared_ptr to protect the raw pointer for the lifetime of the stream.
445 mSharedDataCallback = sharedDataCallback;
446 return this;
447 }
448
459 mSharedDataCallback = nullptr;
460 return this;
461 }
462
486 AudioStreamBuilder *setErrorCallback(std::shared_ptr<AudioStreamErrorCallback> sharedErrorCallback) {
487 // Use this raw pointer in the rest of the code to retain backwards compatibility.
489 // Hold a shared_ptr to protect the raw pointer for the lifetime of the stream.
490 mSharedErrorCallback = sharedErrorCallback;
491 return this;
492 }
493
504 mSharedErrorCallback = nullptr;
505 return this;
506 }
507
522 // Use the same callback object for both, dual inheritance.
525 return this;
526 }
527
538 mChannelConversionAllowed = allowed;
539 return this;
540 }
541
550 mFormatConversionAllowed = allowed;
551 return this;
552 }
553
566 mSampleRateConversionQuality = quality;
567 return this;
568 }
569
588 return this;
589 }
590
606
610 bool willUseAAudio() const {
611 return (mAudioApi == AudioApi::AAudio && isAAudioSupported())
612 || (mAudioApi == AudioApi::Unspecified && isAAudioRecommended());
613 }
614
626
637 Result openStream(std::shared_ptr<oboe::AudioStream> &stream);
638
650 Result openManagedStream(ManagedStream &stream);
651
652private:
653
660 Result openStreamInternal(AudioStream **streamPP);
661
666 bool isCompatible(AudioStreamBase &other);
667
675 oboe::AudioStream *build();
676
677 AudioApi mAudioApi = AudioApi::Unspecified;
678};
679
680} // namespace oboe
681
682#endif /* OBOE_STREAM_BUILDER_H_ */
Definition AudioStreamBase.h:30
SpatializationBehavior mSpatializationBehavior
Definition AudioStreamBase.h:296
InputPreset mInputPreset
Definition AudioStreamBase.h:278
int32_t mDeviceId
Definition AudioStreamBase.h:254
Direction mDirection
Definition AudioStreamBase.h:267
int32_t mFramesPerCallback
Definition AudioStreamBase.h:248
Usage mUsage
Definition AudioStreamBase.h:272
ContentType mContentType
Definition AudioStreamBase.h:274
int32_t mChannelCount
Definition AudioStreamBase.h:250
PrivacySensitiveMode mPrivacySensitiveMode
Definition AudioStreamBase.h:286
AudioStreamDataCallback * mDataCallback
Definition AudioStreamBase.h:240
AllowedCapturePolicy mAllowedCapturePolicy
Definition AudioStreamBase.h:283
AudioFormat mFormat
Definition AudioStreamBase.h:265
int32_t mSampleRate
Definition AudioStreamBase.h:252
bool mIsContentSpatialized
Definition AudioStreamBase.h:294
bool isContentSpatialized() const
Definition AudioStreamBase.h:163
ChannelMask mChannelMask
Definition AudioStreamBase.h:260
PerformanceMode mPerformanceMode
Definition AudioStreamBase.h:269
SessionId mSessionId
Definition AudioStreamBase.h:280
std::string mPackageName
Definition AudioStreamBase.h:289
int32_t mBufferCapacityInFrames
Definition AudioStreamBase.h:256
AudioStreamErrorCallback * mErrorCallback
Definition AudioStreamBase.h:244
std::string mAttributionTag
Definition AudioStreamBase.h:291
SharingMode mSharingMode
Definition AudioStreamBase.h:263
Definition AudioStreamBuilder.h:34
AudioStreamBuilder * setSampleRateConversionQuality(SampleRateConversionQuality quality)
Definition AudioStreamBuilder.h:565
AudioStreamBuilder * setChannelMask(ChannelMask channelMask)
Definition AudioStreamBuilder.h:70
static bool isAAudioSupported()
AudioStreamBuilder * setChannelCount(int channelCount)
Definition AudioStreamBuilder.h:51
AudioStreamBuilder * setFramesPerCallback(int framesPerCallback)
Definition AudioStreamBuilder.h:105
AudioStreamBuilder * setAudioApi(AudioApi audioApi)
Definition AudioStreamBuilder.h:189
AudioStreamBuilder * setErrorCallback(AudioStreamErrorCallback *errorCallback)
Definition AudioStreamBuilder.h:502
AudioStreamBuilder * setInputPreset(InputPreset inputPreset)
Definition AudioStreamBuilder.h:291
AudioStreamBuilder * setSessionId(SessionId sessionId)
Definition AudioStreamBuilder.h:320
AudioStreamBuilder * setSpatializationBehavior(SpatializationBehavior spatializationBehavior)
Definition AudioStreamBuilder.h:424
Result openStream(std::shared_ptr< oboe::AudioStream > &stream)
AudioStreamBuilder * setPrivacySensitiveMode(PrivacySensitiveMode privacySensitiveMode)
Definition AudioStreamBuilder.h:388
AudioStreamBuilder * setChannelConversionAllowed(bool allowed)
Definition AudioStreamBuilder.h:537
static bool isAAudioRecommended()
AudioStreamBuilder * setDeviceId(int32_t deviceId)
Definition AudioStreamBuilder.h:346
AudioStreamBuilder * setPackageName(std::string packageName)
Definition AudioStreamBuilder.h:586
AudioStreamBuilder * setSampleRate(int32_t sampleRate)
Definition AudioStreamBuilder.h:97
AudioStreamBuilder * setAllowedCapturePolicy(AllowedCapturePolicy allowedCapturePolicy)
Definition AudioStreamBuilder.h:364
Result openManagedStream(ManagedStream &stream)
AudioStreamBuilder * setDataCallback(std::shared_ptr< AudioStreamDataCallback > sharedDataCallback)
Definition AudioStreamBuilder.h:441
AudioStreamBuilder * setErrorCallback(std::shared_ptr< AudioStreamErrorCallback > sharedErrorCallback)
Definition AudioStreamBuilder.h:486
Result openStream(AudioStream **stream)
AudioStreamBuilder * setUsage(Usage usage)
Definition AudioStreamBuilder.h:253
AudioStreamBuilder * setAttributionTag(std::string attributionTag)
Definition AudioStreamBuilder.h:602
bool willUseAAudio() const
Definition AudioStreamBuilder.h:610
AudioStreamBuilder * setFormatConversionAllowed(bool allowed)
Definition AudioStreamBuilder.h:549
AudioStreamBuilder * setDirection(Direction direction)
Definition AudioStreamBuilder.h:81
AudioStreamBuilder * setSharingMode(SharingMode sharingMode)
Definition AudioStreamBuilder.h:221
AudioStreamBuilder * setFormat(AudioFormat format)
Definition AudioStreamBuilder.h:142
AudioApi getAudioApi() const
Definition AudioStreamBuilder.h:174
AudioStreamBuilder * setPerformanceMode(PerformanceMode performanceMode)
Definition AudioStreamBuilder.h:234
AudioStreamBuilder * setBufferCapacityInFrames(int32_t bufferCapacityInFrames)
Definition AudioStreamBuilder.h:159
AudioStreamBuilder * setContentType(ContentType contentType)
Definition AudioStreamBuilder.h:271
AudioStreamBuilder * setDataCallback(AudioStreamDataCallback *dataCallback)
Definition AudioStreamBuilder.h:457
AudioStreamBuilder * setFramesPerDataCallback(int framesPerCallback)
Definition AudioStreamBuilder.h:131
AudioStreamBuilder * setCallback(AudioStreamCallback *streamCallback)
Definition AudioStreamBuilder.h:521
AudioStreamBuilder * setIsContentSpatialized(bool isContentSpatialized)
Definition AudioStreamBuilder.h:406
Definition AudioStreamCallback.h:187
Definition AudioStreamCallback.h:34
Definition AudioStreamCallback.h:102
Definition AudioStream.h:42
Definition ResultWithValue.h:47