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 #include "ohos_adapter/bridge/ark_audio_capturer_adapter_impl.h"
17 
18 #include "ohos_adapter/bridge/ark_audio_capturer_options_adapter_wrapper.h"
19 #include "ohos_adapter/bridge/ark_audio_capturer_read_callback_adapter_wrapper.h"
20 #include "ohos_adapter/bridge/ark_buffer_desc_adapter_wrapper.h"
21 
22 #include "base/bridge/ark_web_bridge_macros.h"
23 
24 namespace OHOS::ArkWeb {
25 
ArkAudioCapturerAdapterImpl(std::shared_ptr<OHOS::NWeb::AudioCapturerAdapter> ref)26 ArkAudioCapturerAdapterImpl::ArkAudioCapturerAdapterImpl(std::shared_ptr<OHOS::NWeb::AudioCapturerAdapter> ref)
27     : real_(ref)
28 {}
29 
Create(const ArkWebRefPtr<ArkAudioCapturerOptionsAdapter> capturerOptions,ArkWebString & cachePath)30 int32_t ArkAudioCapturerAdapterImpl::Create(
31     const ArkWebRefPtr<ArkAudioCapturerOptionsAdapter> capturerOptions, ArkWebString& cachePath)
32 {
33     std::string str = ArkWebStringStructToClass(cachePath);
34     if (CHECK_REF_PTR_IS_NULL(capturerOptions)) {
35         return real_->Create(nullptr, str);
36     }
37     return real_->Create(std::make_shared<ArkAudioCapturerOptionsAdapterWrapper>(capturerOptions), str);
38 }
39 
Start()40 bool ArkAudioCapturerAdapterImpl::Start()
41 {
42     return real_->Start();
43 }
44 
Stop()45 bool ArkAudioCapturerAdapterImpl::Stop()
46 {
47     return real_->Stop();
48 }
49 
Release2()50 bool ArkAudioCapturerAdapterImpl::Release2()
51 {
52     return real_->Release();
53 }
54 
SetCapturerReadCallback(const ArkWebRefPtr<ArkAudioCapturerReadCallbackAdapter> callback)55 int32_t ArkAudioCapturerAdapterImpl::SetCapturerReadCallback(
56     const ArkWebRefPtr<ArkAudioCapturerReadCallbackAdapter> callback)
57 {
58     if (CHECK_REF_PTR_IS_NULL(callback)) {
59         return real_->SetCapturerReadCallback(nullptr);
60     }
61 
62     return real_->SetCapturerReadCallback(std::make_shared<ArkAudioCapturerReadCallbackAdapterWrapper>(callback));
63 }
64 
GetBufferDesc(ArkWebRefPtr<ArkBufferDescAdapter> bufferDesc)65 int32_t ArkAudioCapturerAdapterImpl::GetBufferDesc(ArkWebRefPtr<ArkBufferDescAdapter> bufferDesc)
66 {
67     if (CHECK_REF_PTR_IS_NULL(bufferDesc)) {
68         return real_->GetBufferDesc(nullptr);
69     }
70     return real_->GetBufferDesc(std::make_shared<ArkBufferDescAdapterWrapper>(bufferDesc));
71 }
72 
Enqueue(const ArkWebRefPtr<ArkBufferDescAdapter> bufferDesc)73 int32_t ArkAudioCapturerAdapterImpl::Enqueue(const ArkWebRefPtr<ArkBufferDescAdapter> bufferDesc)
74 {
75     if (CHECK_REF_PTR_IS_NULL(bufferDesc)) {
76         return real_->Enqueue(nullptr);
77     }
78     return real_->Enqueue(std::make_shared<ArkBufferDescAdapterWrapper>(bufferDesc));
79 }
80 
GetFrameCount(uint32_t & frameCount)81 int32_t ArkAudioCapturerAdapterImpl::GetFrameCount(uint32_t& frameCount)
82 {
83     return real_->GetFrameCount(frameCount);
84 }
85 
GetAudioTime()86 int64_t ArkAudioCapturerAdapterImpl::GetAudioTime()
87 {
88     return real_->GetAudioTime();
89 }
90 
91 } // namespace OHOS::ArkWeb
92