• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
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 
44     OH_AudioStream_Result SetSourceType(SourceType type);
45     OH_AudioStream_Result SetCapturerCallback(OH_AudioCapturer_Callbacks callbacks, void* userData);
46 
47 private:
48     int32_t streamType_;
49     int32_t latencyMode_ = 0; // default value is normal mode
50 
51     // stream params
52     int32_t samplingRate_ = SAMPLE_RATE_48000;
53     int32_t channelCount_ = STEREO;
54     AudioEncodingType encodingType_ = ENCODING_PCM;
55     AudioSampleFormat sampleFormat_ = SAMPLE_S16LE;
56 
57     // renderer params
58     StreamUsage usage_  = STREAM_USAGE_MEDIA;
59     ContentType contentType_ = CONTENT_TYPE_MUSIC;
60 
61     // capturer params
62     SourceType sourceType_ = SOURCE_TYPE_MIC;
63 
64     OH_AudioRenderer_Callbacks rendererCallbacks_ = {
65         NULL
66     };
67     OH_AudioCapturer_Callbacks capturerCallbacks_ = {
68         NULL
69     };
70     void* userData_;
71 };
72 }  // namespace AudioStandard
73 }  // namespace OHOS
74 
75 #endif // OH_AUDIO_STREAM_BUILDER_H
76