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_wrapper.h" 17 18 #include "ohos_adapter/bridge/ark_audio_capturer_options_adapter_impl.h" 19 #include "ohos_adapter/bridge/ark_audio_capturer_read_callback_adapter_impl.h" 20 #include "ohos_adapter/bridge/ark_buffer_desc_adapter_impl.h" 21 22 #include "base/bridge/ark_web_bridge_macros.h" 23 24 namespace OHOS::ArkWeb { 25 ArkAudioCapturerAdapterWrapper(ArkWebRefPtr<ArkAudioCapturerAdapter> ref)26ArkAudioCapturerAdapterWrapper::ArkAudioCapturerAdapterWrapper(ArkWebRefPtr<ArkAudioCapturerAdapter> ref) : ctocpp_(ref) 27 {} 28 Create(const std::shared_ptr<NWeb::AudioCapturerOptionsAdapter> capturerOptions,std::string cachePath)29int32_t ArkAudioCapturerAdapterWrapper::Create( 30 const std::shared_ptr<NWeb::AudioCapturerOptionsAdapter> capturerOptions, std::string cachePath) 31 { 32 ArkWebString str = ArkWebStringClassToStruct(cachePath); 33 int result; 34 if (CHECK_SHARED_PTR_IS_NULL(capturerOptions)) { 35 result = ctocpp_->Create(nullptr, str); 36 } else { 37 result = ctocpp_->Create(new ArkAudioCapturerOptionsAdapterImpl(capturerOptions), str); 38 } 39 40 ArkWebStringStructRelease(str); 41 return result; 42 } 43 Start()44bool ArkAudioCapturerAdapterWrapper::Start() 45 { 46 return ctocpp_->Start(); 47 } 48 Stop()49bool ArkAudioCapturerAdapterWrapper::Stop() 50 { 51 return ctocpp_->Stop(); 52 } 53 Release()54bool ArkAudioCapturerAdapterWrapper::Release() 55 { 56 return ctocpp_->Release2(); 57 } 58 SetCapturerReadCallback(std::shared_ptr<NWeb::AudioCapturerReadCallbackAdapter> callback)59int32_t ArkAudioCapturerAdapterWrapper::SetCapturerReadCallback( 60 std::shared_ptr<NWeb::AudioCapturerReadCallbackAdapter> callback) 61 { 62 if (CHECK_SHARED_PTR_IS_NULL(callback)) { 63 return ctocpp_->SetCapturerReadCallback(nullptr); 64 } 65 66 return ctocpp_->SetCapturerReadCallback(new ArkAudioCapturerReadCallbackAdapterImpl(callback)); 67 } 68 GetBufferDesc(std::shared_ptr<NWeb::BufferDescAdapter> bufferDesc)69int32_t ArkAudioCapturerAdapterWrapper::GetBufferDesc(std::shared_ptr<NWeb::BufferDescAdapter> bufferDesc) 70 { 71 if (CHECK_SHARED_PTR_IS_NULL(bufferDesc)) { 72 return ctocpp_->GetBufferDesc(nullptr); 73 } 74 return ctocpp_->GetBufferDesc(new ArkBufferDescAdapterImpl(bufferDesc)); 75 } 76 Enqueue(const std::shared_ptr<NWeb::BufferDescAdapter> bufferDesc)77int32_t ArkAudioCapturerAdapterWrapper::Enqueue(const std::shared_ptr<NWeb::BufferDescAdapter> bufferDesc) 78 { 79 if (CHECK_SHARED_PTR_IS_NULL(bufferDesc)) { 80 return ctocpp_->Enqueue(nullptr); 81 } 82 return ctocpp_->Enqueue(new ArkBufferDescAdapterImpl(bufferDesc)); 83 } 84 GetFrameCount(uint32_t & frameCount)85int32_t ArkAudioCapturerAdapterWrapper::GetFrameCount(uint32_t& frameCount) 86 { 87 return ctocpp_->GetFrameCount(frameCount); 88 } 89 GetAudioTime()90int64_t ArkAudioCapturerAdapterWrapper::GetAudioTime() 91 { 92 return ctocpp_->GetAudioTime(); 93 } 94 } // namespace OHOS::ArkWeb 95