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_decoder_callback_adapter_wrapper.h"
17 
18 #include "ohos_adapter/bridge/ark_buffer_info_adapter_impl.h"
19 #include "ohos_adapter/bridge/ark_ohos_buffer_adapter_impl.h"
20 
21 #include "base/bridge/ark_web_bridge_macros.h"
22 
23 namespace OHOS::ArkWeb {
24 
ArkDecoderCallbackAdapterWrapper(ArkWebRefPtr<ArkDecoderCallbackAdapter> ref)25 ArkDecoderCallbackAdapterWrapper::ArkDecoderCallbackAdapterWrapper(ArkWebRefPtr<ArkDecoderCallbackAdapter> ref)
26     : ctocpp_(ref)
27 {}
28 
OnError(OHOS::NWeb::ErrorType errorType,int32_t errorCode)29 void ArkDecoderCallbackAdapterWrapper::OnError(OHOS::NWeb::ErrorType errorType, int32_t errorCode)
30 {
31     ctocpp_->OnError((int32_t)errorType, errorCode);
32 }
33 
OnStreamChanged(int32_t width,int32_t height,double frameRate)34 void ArkDecoderCallbackAdapterWrapper::OnStreamChanged(int32_t width, int32_t height, double frameRate)
35 {
36     ctocpp_->OnStreamChanged(width, height, frameRate);
37 }
38 
OnNeedInputData(uint32_t index,std::shared_ptr<NWeb::OhosBufferAdapter> buffer)39 void ArkDecoderCallbackAdapterWrapper::OnNeedInputData(uint32_t index, std::shared_ptr<NWeb::OhosBufferAdapter> buffer)
40 {
41     if (CHECK_SHARED_PTR_IS_NULL(buffer)) {
42         return ctocpp_->OnNeedInputData(index, nullptr);
43     }
44 
45     ctocpp_->OnNeedInputData(index, new ArkOhosBufferAdapterImpl(buffer));
46 }
47 
OnNeedOutputData(uint32_t index,std::shared_ptr<NWeb::BufferInfoAdapter> info,NWeb::BufferFlag flag)48 void ArkDecoderCallbackAdapterWrapper::OnNeedOutputData(
49     uint32_t index, std::shared_ptr<NWeb::BufferInfoAdapter> info, NWeb::BufferFlag flag)
50 {
51     if (CHECK_SHARED_PTR_IS_NULL(info)) {
52         return ctocpp_->OnNeedOutputData(index, nullptr, (uint32_t)flag);
53     }
54 
55     ctocpp_->OnNeedOutputData(index, new ArkBufferInfoAdapterImpl(info), (uint32_t)flag);
56 }
57 
58 } // namespace OHOS::ArkWeb
59