• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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::AVSession {
24 class AVSession;
25 };
26 
27 namespace OHOS::NWeb {
28 using namespace OHOS::AudioStandard;
29 
30 class AudioRendererCallbackImpl : public AudioRendererCallback {
31 public:
32     AudioRendererCallbackImpl(std::shared_ptr<AudioRendererCallbackAdapter> cb);
33 
34     ~AudioRendererCallbackImpl() override = default;
35 
36     void OnInterrupt(const InterruptEvent &interruptEvent) override;
37 
38     void OnStateChange(const RendererState state, const StateChangeCmdType cmdType = CMD_FROM_CLIENT) override;
39 
40 private:
41     std::shared_ptr<AudioRendererCallbackAdapter> cb_ = nullptr;
42 };
43 
44 class AudioRendererAdapterImpl : public AudioRendererAdapter {
45 public:
46     AudioRendererAdapterImpl() = default;
47 
48     ~AudioRendererAdapterImpl();
49 
50     int32_t Create(const AudioAdapterRendererOptions &rendererOptions,
51         std::string cachePath = std::string()) override;
52 
53     bool Start() override;
54 
55     bool Pause() override;
56 
57     bool Stop() override;
58 
59     bool Release() override;
60 
61     int32_t Write(uint8_t *buffer, size_t bufferSize) override;
62 
63     int32_t GetLatency(uint64_t &latency) const override;
64 
65     int32_t SetVolume(float volume) const override;
66 
67     float GetVolume() const override;
68 
69     int32_t SetAudioRendererCallback(const std::shared_ptr<AudioRendererCallbackAdapter> &callback) override;
70 
71     void SetInterruptMode(bool audioExclusive) override;
72 
73     bool IsRendererStateRunning() override;
74 
75     static AudioSamplingRate GetAudioSamplingRate(AudioAdapterSamplingRate samplingRate);
76 
77     static AudioEncodingType GetAudioEncodingType(AudioAdapterEncodingType encodingType);
78 
79     static AudioSampleFormat GetAudioSampleFormat(AudioAdapterSampleFormat sampleFormat);
80 
81     static AudioChannel GetAudioChannel(AudioAdapterChannel channel);
82 
83     static ContentType GetAudioContentType(AudioAdapterContentType contentType);
84 
85     static StreamUsage GetAudioStreamUsage(AudioAdapterStreamUsage streamUsage);
86 
87 private:
88     std::unique_ptr<AudioRenderer> audio_renderer_;
89     std::shared_ptr<AudioRendererCallbackImpl> callback_;
90     static std::shared_ptr<OHOS::AVSession::AVSession> avsession_;
91 };
92 }  // namespace OHOS::NWeb
93 
94 #endif // AUDIO_RENDERER_ADAPTER_IMPL_H