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 22 #include "audio_renderer_adapter.h" 23 24 namespace OHOS::NWeb { 25 26 enum class AudioAdapterSourceType : int32_t { 27 SOURCE_TYPE_INVALID = -1, 28 SOURCE_TYPE_MIC, 29 SOURCE_TYPE_VOICE_RECOGNITION = 1, 30 SOURCE_TYPE_VOICE_COMMUNICATION = 7, 31 SOURCE_TYPE_ULTRASONIC = 8 32 }; 33 34 class AudioCapturerOptionsAdapter { 35 public: 36 AudioCapturerOptionsAdapter() = default; 37 38 virtual ~AudioCapturerOptionsAdapter() = default; 39 40 virtual AudioAdapterSamplingRate GetSamplingRate() = 0; 41 42 virtual AudioAdapterEncodingType GetEncoding() = 0; 43 44 virtual AudioAdapterSampleFormat GetSampleFormat() = 0; 45 46 virtual AudioAdapterChannel GetChannels() = 0; 47 48 virtual AudioAdapterSourceType GetSourceType() = 0; 49 50 virtual int32_t GetCapturerFlags() = 0; 51 }; 52 53 class BufferDescAdapter { 54 public: 55 BufferDescAdapter() = default; 56 57 virtual ~BufferDescAdapter() = default; 58 59 virtual uint8_t* GetBuffer() = 0; 60 61 virtual size_t GetBufLength() = 0; 62 63 virtual size_t GetDataLength() = 0; 64 65 virtual void SetBuffer(uint8_t* buffer) = 0; 66 67 virtual void SetBufLength(size_t bufLength) = 0; 68 69 virtual void SetDataLength(size_t dataLength) = 0; 70 }; 71 72 class AudioCapturerReadCallbackAdapter { 73 public: 74 AudioCapturerReadCallbackAdapter() = default; 75 76 virtual ~AudioCapturerReadCallbackAdapter() = default; 77 78 virtual void OnReadData(size_t length) = 0; 79 }; 80 81 class AudioCapturerAdapter { 82 public: 83 AudioCapturerAdapter() = default; 84 85 virtual ~AudioCapturerAdapter() = default; 86 87 virtual int32_t Create( 88 const std::shared_ptr<AudioCapturerOptionsAdapter> capturerOptions, std::string cachePath = std::string()) = 0; 89 90 virtual bool Start() = 0; 91 92 virtual bool Stop() = 0; 93 94 virtual bool Release() = 0; 95 96 virtual int32_t SetCapturerReadCallback(std::shared_ptr<AudioCapturerReadCallbackAdapter> callbck) = 0; 97 98 virtual int32_t GetBufferDesc(std::shared_ptr<BufferDescAdapter> bufferDesc) = 0; 99 100 virtual int32_t Enqueue(const std::shared_ptr<BufferDescAdapter> bufferDesc) = 0; 101 102 virtual int32_t GetFrameCount(uint32_t& frameCount) = 0; 103 104 virtual int64_t GetAudioTime() = 0; 105 }; 106 107 } // namespace OHOS::NWeb 108 109 #endif // AUDIO_CAPTURE_ADAPTER_H 110