• 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 AUDIO_CAPTURE_ADAPTER_H
17 #define AUDIO_CAPTURE_ADAPTER_H
18 
19 #include <memory>
20 #include <string>
21 #include "audio_renderer_adapter.h"
22 
23 namespace OHOS::NWeb {
24 enum class AudioAdapterSourceType {
25     SOURCE_TYPE_INVALID = -1,
26     SOURCE_TYPE_MIC,
27     SOURCE_TYPE_VOICE_RECOGNITION = 1,
28     SOURCE_TYPE_VOICE_COMMUNICATION = 7,
29     SOURCE_TYPE_ULTRASONIC = 8
30 };
31 
32 struct AudioAdapterCapturerOptions {
33     AudioAdapterSamplingRate samplingRate;
34     AudioAdapterEncodingType encoding;
35     AudioAdapterSampleFormat format;
36     AudioAdapterChannel channels;
37     AudioAdapterSourceType sourceType;
38     int32_t capturerFlags;
39 };
40 
41 struct BufferDescAdapter {
42     uint8_t* buffer;
43     size_t bufLength;
44     size_t dataLength;
45 };
46 
47 class AudioCapturerReadCallbackAdapter {
48 public:
49     AudioCapturerReadCallbackAdapter() = default;
50 
51     virtual ~AudioCapturerReadCallbackAdapter() = default;
52 
53     virtual void OnReadData(size_t length) = 0;
54 };
55 
56 class AudioCapturerAdapter {
57 public:
58     AudioCapturerAdapter() = default;
59 
60     virtual ~AudioCapturerAdapter() = default;
61 
62     virtual int32_t Create(const AudioAdapterCapturerOptions &capturerOptions,
63         std::string cachePath = std::string()) = 0;
64 
65     virtual bool Start() = 0;
66 
67     virtual bool Stop() = 0;
68 
69     virtual bool Release() = 0;
70 
71     virtual int32_t SetCapturerReadCallback(
72         const std::shared_ptr<AudioCapturerReadCallbackAdapter> &callbck) = 0;
73 
74     virtual int32_t GetBufferDesc(BufferDescAdapter &buffferDesc) = 0;
75 
76     virtual int32_t Enqueue(const BufferDescAdapter &bufferDesc) const = 0;
77 
78     virtual int32_t GetFrameCount(uint32_t &frameCount) const = 0;
79 
80     virtual int64_t GetAudioTime() = 0;
81 };
82 } // namespace OHOS::NWeb
83 
84 #endif // AUDIO_CAPTURE_ADAPTER_H