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 #include "ohos_adapter/bridge/ark_audio_renderer_adapter_wrapper.h"
17
18 #include "ohos_adapter/bridge/ark_audio_output_change_callback_adapter_impl.h"
19 #include "ohos_adapter/bridge/ark_audio_renderer_callback_adapter_impl.h"
20 #include "ohos_adapter/bridge/ark_audio_renderer_options_adapter_impl.h"
21
22 #include "base/bridge/ark_web_bridge_macros.h"
23
24 namespace OHOS::ArkWeb {
25
ArkAudioRendererAdapterWrapper(ArkWebRefPtr<ArkAudioRendererAdapter> ref)26 ArkAudioRendererAdapterWrapper::ArkAudioRendererAdapterWrapper(ArkWebRefPtr<ArkAudioRendererAdapter> ref) : ctocpp_(ref)
27 {}
28
Create(const std::shared_ptr<NWeb::AudioRendererOptionsAdapter> options,std::string cachePath)29 int32_t ArkAudioRendererAdapterWrapper::Create(
30 const std::shared_ptr<NWeb::AudioRendererOptionsAdapter> options, std::string cachePath)
31 {
32 ArkWebString str = ArkWebStringClassToStruct(cachePath);
33 int result;
34 if (CHECK_SHARED_PTR_IS_NULL(options)) {
35 result = ctocpp_->Create(nullptr, str);
36 } else {
37 result = ctocpp_->Create(new ArkAudioRendererOptionsAdapterImpl(options), str);
38 }
39
40 ArkWebStringStructRelease(str);
41 return result;
42 }
43
Start()44 bool ArkAudioRendererAdapterWrapper::Start()
45 {
46 return ctocpp_->Start();
47 }
48
Pause()49 bool ArkAudioRendererAdapterWrapper::Pause()
50 {
51 return ctocpp_->Pause();
52 }
53
Stop()54 bool ArkAudioRendererAdapterWrapper::Stop()
55 {
56 return ctocpp_->Stop();
57 }
58
Release()59 bool ArkAudioRendererAdapterWrapper::Release()
60 {
61 return ctocpp_->Release2();
62 }
63
Write(uint8_t * buffer,size_t bufferSize)64 int32_t ArkAudioRendererAdapterWrapper::Write(uint8_t* buffer, size_t bufferSize)
65 {
66 return ctocpp_->Write(buffer, bufferSize);
67 }
68
GetLatency(uint64_t & latency)69 int32_t ArkAudioRendererAdapterWrapper::GetLatency(uint64_t& latency)
70 {
71 return ctocpp_->GetLatency(latency);
72 }
73
SetVolume(float volume)74 int32_t ArkAudioRendererAdapterWrapper::SetVolume(float volume)
75 {
76 return ctocpp_->SetVolume(volume);
77 }
78
GetVolume()79 float ArkAudioRendererAdapterWrapper::GetVolume()
80 {
81 return ctocpp_->GetVolume();
82 }
83
SetAudioRendererCallback(const std::shared_ptr<NWeb::AudioRendererCallbackAdapter> & callback)84 int32_t ArkAudioRendererAdapterWrapper::SetAudioRendererCallback(
85 const std::shared_ptr<NWeb::AudioRendererCallbackAdapter>& callback)
86 {
87 if (CHECK_SHARED_PTR_IS_NULL(callback)) {
88 return ctocpp_->SetAudioRendererCallback(nullptr);
89 }
90
91 return ctocpp_->SetAudioRendererCallback(new ArkAudioRendererCallbackAdapterImpl(callback));
92 }
93
SetInterruptMode(bool audioExclusive)94 void ArkAudioRendererAdapterWrapper::SetInterruptMode(bool audioExclusive)
95 {
96 ctocpp_->SetInterruptMode(audioExclusive);
97 }
98
SetAudioSilentMode(bool isSilentMode)99 void ArkAudioRendererAdapterWrapper::SetAudioSilentMode(bool isSilentMode)
100 {
101 ctocpp_->SetAudioSilentMode(isSilentMode);
102 }
103
IsRendererStateRunning()104 bool ArkAudioRendererAdapterWrapper::IsRendererStateRunning()
105 {
106 return ctocpp_->IsRendererStateRunning();
107 }
108
SetAudioOutputChangeCallback(const std::shared_ptr<NWeb::AudioOutputChangeCallbackAdapter> & callback)109 int32_t ArkAudioRendererAdapterWrapper::SetAudioOutputChangeCallback(
110 const std::shared_ptr<NWeb::AudioOutputChangeCallbackAdapter>& callback)
111 {
112 if (CHECK_SHARED_PTR_IS_NULL(callback)) {
113 return ctocpp_->SetAudioOutputChangeCallback(nullptr);
114 }
115
116 return ctocpp_->SetAudioOutputChangeCallback(new ArkAudioOutputChangeCallbackAdapterImpl(callback));
117 }
118
119 } // namespace OHOS::ArkWeb
120