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_interrupt_info.h" 22 #include "audio_info.h" 23 #include "OHAudioRenderer.h" 24 25 namespace OHOS { 26 namespace AudioStandard { 27 class OHAudioStreamBuilder { 28 public: 29 explicit OHAudioStreamBuilder(const int32_t type); 30 31 ~OHAudioStreamBuilder(); 32 33 OH_AudioStream_Result Generate(OH_AudioRenderer **renderer); 34 OH_AudioStream_Result Generate(OH_AudioCapturer **capturer); 35 36 OH_AudioStream_Result SetSamplingRate(int32_t rate); 37 OH_AudioStream_Result SetChannelCount(int32_t channelCount); 38 OH_AudioStream_Result SetSampleFormat(AudioSampleFormat sampleFormat); 39 OH_AudioStream_Result SetEncodingType(AudioEncodingType encodingType); 40 OH_AudioStream_Result SetPreferredFrameSize(int32_t frameSize); 41 OH_AudioStream_Result SetLatencyMode(int32_t latencyMode); 42 OH_AudioStream_Result SetChannelLayout(AudioChannelLayout channelLayout); 43 44 OH_AudioStream_Result SetRendererInfo(StreamUsage usage); 45 OH_AudioStream_Result SetRendererCallback(OH_AudioRenderer_Callbacks callbacks, void *userData); 46 OH_AudioStream_Result SetRendererOutputDeviceChangeCallback(OH_AudioRenderer_OutputDeviceChangeCallback callback, 47 void *userData); 48 OH_AudioStream_Result SetRendererPrivacy(AudioPrivacyType privacyType); 49 OH_AudioStream_Result SetWriteDataWithMetadataCallback(OH_AudioRenderer_WriteDataWithMetadataCallback callback, 50 void *userData); 51 OH_AudioStream_Result SetRendererWriteDataCallback(OH_AudioRenderer_OnWriteDataCallback callback, 52 void* userData); 53 54 OH_AudioStream_Result SetSourceType(SourceType type); 55 OH_AudioStream_Result SetCapturerCallback(OH_AudioCapturer_Callbacks callbacks, void *userData); 56 OH_AudioStream_Result SetInterruptMode(InterruptMode mode); 57 58 private: 59 int32_t streamType_; 60 int32_t latencyMode_ = 0; // default value is normal mode 61 int32_t preferredFrameSize_ = -1; // undefined clientBufferSizeInFrame 62 63 // stream params 64 int32_t samplingRate_ = SAMPLE_RATE_48000; 65 int32_t channelCount_ = STEREO; 66 AudioEncodingType encodingType_ = ENCODING_PCM; 67 AudioSampleFormat sampleFormat_ = SAMPLE_S16LE; 68 AudioChannelLayout channelLayout_ = CH_LAYOUT_UNKNOWN; 69 70 // renderer params 71 StreamUsage usage_ = STREAM_USAGE_UNKNOWN; 72 AudioPrivacyType privacyType_ = PRIVACY_TYPE_PUBLIC; 73 74 // capturer params 75 SourceType sourceType_ = SOURCE_TYPE_MIC; 76 77 OH_AudioCapturer_Callbacks capturerCallbacks_ = { 78 NULL 79 }; 80 WriteDataCallbackType writeDataCallbackType_ = WRITE_DATA_CALLBACK_WITHOUT_RESULT; 81 RendererCallback rendererCallbacks_ = { 82 {nullptr}, 83 84 nullptr, 85 86 nullptr 87 }; 88 void *userData_ = nullptr; 89 90 OH_AudioRenderer_OutputDeviceChangeCallback outputDeviceChangecallback_ = nullptr; 91 void *outputDeviceChangeuserData_ = nullptr; 92 InterruptMode interruptMode_ = SHARE_MODE; 93 void *metadataUserData_ = nullptr; 94 }; 95 } // namespace AudioStandard 96 } // namespace OHOS 97 98 #endif // OH_AUDIO_STREAM_BUILDER_H 99