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_CAPTURER_ADAPTER_IMPL_H 17 #define AUDIO_CAPTURER_ADAPTER_IMPL_H 18 19 #include "audio_capturer_adapter.h" 20 21 #include <unordered_set> 22 #include "audio_capturer.h" 23 24 namespace OHOS::NWeb { 25 using namespace OHOS::AudioStandard; 26 27 class AudioCapturerReadCallbackImpl : public AudioCapturerReadCallback { 28 public: 29 AudioCapturerReadCallbackImpl(std::shared_ptr<AudioCapturerReadCallbackAdapter> cb); 30 31 ~AudioCapturerReadCallbackImpl() override = default; 32 33 void OnReadData(size_t length) override; 34 35 private: 36 std::shared_ptr<AudioCapturerReadCallbackAdapter> cb_ = nullptr; 37 }; 38 39 class AudioCapturerAdapterImpl : public AudioCapturerAdapter { 40 public: 41 AudioCapturerAdapterImpl() = default; 42 43 ~AudioCapturerAdapterImpl() override = default; 44 45 int32_t Create(const AudioAdapterCapturerOptions &rendererOptions, 46 std::string cachePath = std::string()) override; 47 48 bool Start() override; 49 50 bool Stop() override; 51 52 bool Release() override; 53 54 int32_t SetCapturerReadCallback( 55 const std::shared_ptr<AudioCapturerReadCallbackAdapter> &callbck) override; 56 57 int32_t GetBufferDesc(BufferDescAdapter &buffferDesc) override; 58 59 int32_t Enqueue(const BufferDescAdapter &buffferDesc) const override; 60 61 int32_t GetFrameCount(uint32_t &frameCount) const override; 62 63 int64_t GetAudioTime() override; 64 65 static AudioSamplingRate GetAudioSamplingRate(AudioAdapterSamplingRate samplingRate); 66 67 static AudioEncodingType GetAudioEncodingType(AudioAdapterEncodingType encodingType); 68 69 static AudioSampleFormat GetAudioSampleFormat(AudioAdapterSampleFormat sampleFormat); 70 71 static AudioChannel GetAudioChannel(AudioAdapterChannel channel); 72 73 static SourceType GetAudioSourceType(AudioAdapterSourceType SourceType); 74 75 private: 76 std::unique_ptr<AudioCapturer> audio_capturer_; 77 static std::unordered_set<AudioCapturerAdapterImpl*> audioCapturerAdapterSet_; 78 }; 79 } // namespace OHOS::NWeb 80 81 #endif // AUDIO_CAPTURER_ADAPTER_IMPL_H