1 /* 2 * Copyright (c) 2022 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_RENDERER_ADAPTER_IMPL_H 17 #define AUDIO_RENDERER_ADAPTER_IMPL_H 18 19 #include "audio_renderer_adapter.h" 20 21 #include "audio_renderer.h" 22 23 namespace OHOS::NWeb { 24 using namespace OHOS::AudioStandard; 25 26 class AudioRendererWriteCallbackImpl : public AudioRendererWriteCallback { 27 public: 28 explicit AudioRendererWriteCallbackImpl(std::shared_ptr<AudioRendererWriteCallbackAdapter> callback); 29 ~AudioRendererWriteCallbackImpl() override = default; 30 void OnWriteData(size_t length) override; 31 private: 32 std::shared_ptr<AudioRendererWriteCallbackAdapter> callback_ = nullptr; 33 }; 34 35 class AudioRendererAdapterImpl : public AudioRendererAdapter { 36 public: 37 AudioRendererAdapterImpl() = default; 38 39 ~AudioRendererAdapterImpl() override = default; 40 41 int32_t Create(const AudioAdapterRendererOptions &rendererOptions, 42 std::string cachePath = std::string()) override; 43 44 bool Start() override; 45 46 bool Stop() override; 47 48 bool Release() override; 49 50 int32_t Write(uint8_t *buffer, size_t bufferSize) override; 51 52 int32_t GetLatency(uint64_t &latency) const override; 53 54 int32_t SetVolume(float volume) const override; 55 56 float GetVolume() const override; 57 58 int32_t Enqueue(const BufferDescAdapter& bufDesc) override; 59 60 int32_t GetBufferDesc(BufferDescAdapter& bufDesc) override; 61 62 int32_t SetAudioRendererWriteCallbackAdapter( 63 const std::shared_ptr<AudioRendererWriteCallbackAdapter>& callback) 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 ContentType GetAudioContentType(AudioAdapterContentType contentType); 74 75 static StreamUsage GetAudioStreamUsage(AudioAdapterStreamUsage streamUsage); 76 77 private: 78 std::unique_ptr<AudioRenderer> audio_renderer_; 79 std::shared_ptr<AudioRendererWriteCallbackImpl> callback_; 80 }; 81 } // namespace OHOS::NWeb 82 83 #endif // AUDIO_RENDERER_ADAPTER_IMPL_H