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_encoder_callback_adapter_impl.h"
17
18 #include "ohos_adapter/bridge/ark_buffer_info_adapter_wrapper.h"
19 #include "ohos_adapter/bridge/ark_codec_format_adapter_wrapper.h"
20 #include "ohos_adapter/bridge/ark_ohos_buffer_adapter_wrapper.h"
21
22 #include "base/bridge/ark_web_bridge_macros.h"
23
24 namespace OHOS::ArkWeb {
25
ArkEncoderCallbackAdapterImpl(std::shared_ptr<OHOS::NWeb::CodecCallbackAdapter> ref)26 ArkEncoderCallbackAdapterImpl::ArkEncoderCallbackAdapterImpl(std::shared_ptr<OHOS::NWeb::CodecCallbackAdapter> ref)
27 : real_(ref)
28 {}
29
OnError(int32_t errorType,int32_t errorCode)30 void ArkEncoderCallbackAdapterImpl::OnError(int32_t errorType, int32_t errorCode)
31 {
32 real_->OnError((OHOS::NWeb::ErrorType)errorType, errorCode);
33 }
34
OnStreamChanged(const ArkWebRefPtr<ArkCodecFormatAdapter> format)35 void ArkEncoderCallbackAdapterImpl::OnStreamChanged(const ArkWebRefPtr<ArkCodecFormatAdapter> format)
36 {
37 if (CHECK_REF_PTR_IS_NULL(format)) {
38 return real_->OnStreamChanged(nullptr);
39 }
40
41 real_->OnStreamChanged(std::make_shared<ArkCodecFormatAdapterWrapper>(format));
42 }
43
OnNeedInputData(uint32_t index,ArkWebRefPtr<ArkOhosBufferAdapter> buffer)44 void ArkEncoderCallbackAdapterImpl::OnNeedInputData(uint32_t index, ArkWebRefPtr<ArkOhosBufferAdapter> buffer)
45 {
46 if (CHECK_REF_PTR_IS_NULL(buffer)) {
47 return real_->OnNeedInputData(index, nullptr);
48 }
49
50 real_->OnNeedInputData(index, std::make_shared<ArkOhosBufferAdapterWrapper>(buffer));
51 }
52
OnNeedOutputData(uint32_t index,ArkWebRefPtr<ArkBufferInfoAdapter> info,int32_t flag,ArkWebRefPtr<ArkOhosBufferAdapter> buffer)53 void ArkEncoderCallbackAdapterImpl::OnNeedOutputData(
54 uint32_t index, ArkWebRefPtr<ArkBufferInfoAdapter> info, int32_t flag, ArkWebRefPtr<ArkOhosBufferAdapter> buffer)
55 {
56 if (CHECK_REF_PTR_IS_NULL(info) && CHECK_REF_PTR_IS_NULL(buffer)) {
57 real_->OnNeedOutputData(index, nullptr, (OHOS::NWeb::BufferFlag)flag, nullptr);
58 } else if (!CHECK_REF_PTR_IS_NULL(info) && !CHECK_REF_PTR_IS_NULL(buffer)) {
59 real_->OnNeedOutputData(index, std::make_shared<ArkBufferInfoAdapterWrapper>(info),
60 (OHOS::NWeb::BufferFlag)flag, std::make_shared<ArkOhosBufferAdapterWrapper>(buffer));
61 } else if (CHECK_REF_PTR_IS_NULL(info)) {
62 real_->OnNeedOutputData(
63 index, nullptr, (OHOS::NWeb::BufferFlag)flag, std::make_shared<ArkOhosBufferAdapterWrapper>(buffer));
64 } else {
65 real_->OnNeedOutputData(
66 index, std::make_shared<ArkBufferInfoAdapterWrapper>(info), (OHOS::NWeb::BufferFlag)flag, nullptr);
67 }
68 }
69
70 } // namespace OHOS::ArkWeb
71