• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023-2025 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_screen_capture_adapter_wrapper.h"
17 
18 #include "ohos_adapter/bridge/ark_screen_capture_callback_adapter_impl.h"
19 #include "ohos_adapter/bridge/ark_screen_capture_config_adapter_impl.h"
20 #include "ohos_adapter/bridge/ark_surface_buffer_adapter_wrapper.h"
21 #include "ohos_adapter/bridge/ark_audio_buffer_adapter_impl.h"
22 
23 #include "base/bridge/ark_web_bridge_macros.h"
24 
25 namespace OHOS::ArkWeb {
26 
ArkScreenCaptureAdapterWrapper(ArkWebRefPtr<ArkScreenCaptureAdapter> ref)27 ArkScreenCaptureAdapterWrapper::ArkScreenCaptureAdapterWrapper(ArkWebRefPtr<ArkScreenCaptureAdapter> ref) : ctocpp_(ref)
28 {}
29 
Init(const std::shared_ptr<NWeb::ScreenCaptureConfigAdapter> config)30 int32_t ArkScreenCaptureAdapterWrapper::Init(const std::shared_ptr<NWeb::ScreenCaptureConfigAdapter> config)
31 {
32     if (CHECK_SHARED_PTR_IS_NULL(config)) {
33         return ctocpp_->Init(nullptr);
34     }
35     return ctocpp_->Init(new ArkScreenCaptureConfigAdapterImpl(config));
36 }
37 
SetMicrophoneEnable(bool enable)38 int32_t ArkScreenCaptureAdapterWrapper::SetMicrophoneEnable(bool enable)
39 {
40     return ctocpp_->SetMicrophoneEnable(enable);
41 }
42 
StartCapture()43 int32_t ArkScreenCaptureAdapterWrapper::StartCapture()
44 {
45     return ctocpp_->StartCapture();
46 }
47 
StopCapture()48 int32_t ArkScreenCaptureAdapterWrapper::StopCapture()
49 {
50     return ctocpp_->StopCapture();
51 }
52 
SetCaptureCallback(const std::shared_ptr<OHOS::NWeb::ScreenCaptureCallbackAdapter> callback)53 int32_t ArkScreenCaptureAdapterWrapper::SetCaptureCallback(
54     const std::shared_ptr<OHOS::NWeb::ScreenCaptureCallbackAdapter> callback)
55 {
56     if (CHECK_SHARED_PTR_IS_NULL(callback)) {
57         return ctocpp_->SetCaptureCallback(nullptr);
58     }
59 
60     return ctocpp_->SetCaptureCallback(new ArkScreenCaptureCallbackAdapterImpl(callback));
61 }
62 
AcquireVideoBuffer()63 std::shared_ptr<OHOS::NWeb::SurfaceBufferAdapter> ArkScreenCaptureAdapterWrapper::AcquireVideoBuffer()
64 {
65     ArkWebRefPtr<ArkSurfaceBufferAdapter> ref = ctocpp_->AcquireVideoBuffer();
66     if (CHECK_REF_PTR_IS_NULL(ref)) {
67         return nullptr;
68     }
69 
70     return std::make_shared<ArkSurfaceBufferAdapterWrapper>(ref);
71 }
72 
ReleaseVideoBuffer()73 int32_t ArkScreenCaptureAdapterWrapper::ReleaseVideoBuffer()
74 {
75     return ctocpp_->ReleaseVideoBuffer();
76 }
77 
AcquireAudioBuffer(std::shared_ptr<OHOS::NWeb::AudioBufferAdapter> audiobuffer,NWeb::AudioCaptureSourceTypeAdapter type)78 int32_t ArkScreenCaptureAdapterWrapper::AcquireAudioBuffer(
79     std::shared_ptr<OHOS::NWeb::AudioBufferAdapter> audiobuffer, NWeb::AudioCaptureSourceTypeAdapter type)
80 {
81     if (CHECK_SHARED_PTR_IS_NULL(audiobuffer)) {
82         return ctocpp_->AcquireAudioBuffer(nullptr, (int32_t)type);
83     }
84 
85     return ctocpp_->AcquireAudioBuffer(new ArkAudioBufferAdapterImpl(audiobuffer), (int32_t)type);
86 }
87 
ReleaseAudioBuffer(NWeb::AudioCaptureSourceTypeAdapter type)88 int32_t ArkScreenCaptureAdapterWrapper::ReleaseAudioBuffer(NWeb::AudioCaptureSourceTypeAdapter type)
89 {
90     return ctocpp_->ReleaseAudioBuffer((int32_t)type);
91 }
92 
93 } // namespace OHOS::ArkWeb
94