1 /* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef OH_AUDIO_STREAM_BUILDER_H 17 #define OH_AUDIO_STREAM_BUILDER_H 18 19 #include <cstdint> 20 #include "native_audiostream_base.h" 21 #include "audio_info.h" 22 23 namespace OHOS { 24 namespace AudioStandard { 25 class OHAudioStreamBuilder { 26 public: 27 explicit OHAudioStreamBuilder(const int32_t type); 28 29 ~OHAudioStreamBuilder(); 30 31 OH_AudioStream_Result Generate(OH_AudioRenderer** renderer); 32 OH_AudioStream_Result Generate(OH_AudioCapturer** capturer); 33 34 OH_AudioStream_Result SetSamplingRate(int32_t rate); 35 OH_AudioStream_Result SetChannelCount(int32_t channelCount); 36 OH_AudioStream_Result SetSampleFormat(AudioSampleFormat sampleFormat); 37 OH_AudioStream_Result SetEncodingType(AudioEncodingType encodingType); 38 OH_AudioStream_Result SetPreferredFrameSize(int32_t frameSize); 39 OH_AudioStream_Result SetLatencyMode(int32_t latencyMode); 40 41 OH_AudioStream_Result SetRendererInfo(StreamUsage usage, ContentType contentType); 42 OH_AudioStream_Result SetRendererCallback(OH_AudioRenderer_Callbacks callbacks, void* userData); 43 OH_AudioStream_Result SetRendererOutputDeviceChangeCallback(OH_AudioRenderer_OutputDeviceChangeCallback callback, 44 void* userData); 45 46 OH_AudioStream_Result SetSourceType(SourceType type); 47 OH_AudioStream_Result SetCapturerCallback(OH_AudioCapturer_Callbacks callbacks, void* userData); 48 49 private: 50 int32_t streamType_; 51 int32_t latencyMode_ = 0; // default value is normal mode 52 int32_t preferredFrameSize_ = -1; // undefined clientBufferSizeInFrame 53 54 // stream params 55 int32_t samplingRate_ = SAMPLE_RATE_48000; 56 int32_t channelCount_ = STEREO; 57 AudioEncodingType encodingType_ = ENCODING_PCM; 58 AudioSampleFormat sampleFormat_ = SAMPLE_S16LE; 59 60 // renderer params 61 StreamUsage usage_ = STREAM_USAGE_MEDIA; 62 ContentType contentType_ = CONTENT_TYPE_MUSIC; 63 64 // capturer params 65 SourceType sourceType_ = SOURCE_TYPE_MIC; 66 67 OH_AudioRenderer_Callbacks rendererCallbacks_ = { 68 NULL 69 }; 70 OH_AudioCapturer_Callbacks capturerCallbacks_ = { 71 NULL 72 }; 73 void* userData_; 74 75 OH_AudioRenderer_OutputDeviceChangeCallback outputDeviceChangecallback_ = nullptr; 76 void* outputDeviceChangeuserData_ = nullptr; 77 }; 78 } // namespace AudioStandard 79 } // namespace OHOS 80 81 #endif // OH_AUDIO_STREAM_BUILDER_H 82