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_media_codec_decoder_adapter_impl.h"
17 
18 #include "ohos_adapter/bridge/ark_decoder_callback_adapter_wrapper.h"
19 #include "ohos_adapter/bridge/ark_decoder_format_adapter_wrapper.h"
20 
21 #include "base/bridge/ark_web_bridge_macros.h"
22 
23 namespace OHOS::ArkWeb {
24 
ArkMediaCodecDecoderAdapterImpl(std::shared_ptr<OHOS::NWeb::MediaCodecDecoderAdapter> ref)25 ArkMediaCodecDecoderAdapterImpl::ArkMediaCodecDecoderAdapterImpl(
26     std::shared_ptr<OHOS::NWeb::MediaCodecDecoderAdapter> ref)
27     : real_(ref)
28 {}
29 
CreateVideoDecoderByMime(const ArkWebString & mimetype)30 int32_t ArkMediaCodecDecoderAdapterImpl::CreateVideoDecoderByMime(const ArkWebString& mimetype)
31 {
32     return (int32_t)real_->CreateVideoDecoderByMime(ArkWebStringStructToClass(mimetype));
33 }
34 
CreateVideoDecoderByName(const ArkWebString & name)35 int32_t ArkMediaCodecDecoderAdapterImpl::CreateVideoDecoderByName(const ArkWebString& name)
36 {
37     return (int32_t)real_->CreateVideoDecoderByName(ArkWebStringStructToClass(name));
38 }
39 
ConfigureDecoder(const ArkWebRefPtr<ArkDecoderFormatAdapter> format)40 int32_t ArkMediaCodecDecoderAdapterImpl::ConfigureDecoder(const ArkWebRefPtr<ArkDecoderFormatAdapter> format)
41 {
42     if (CHECK_REF_PTR_IS_NULL(format)) {
43         return (int32_t)real_->ConfigureDecoder(nullptr);
44     }
45     return (int32_t)real_->ConfigureDecoder(std::make_shared<ArkDecoderFormatAdapterWrapper>(format));
46 }
47 
SetParameterDecoder(const ArkWebRefPtr<ArkDecoderFormatAdapter> format)48 int32_t ArkMediaCodecDecoderAdapterImpl::SetParameterDecoder(const ArkWebRefPtr<ArkDecoderFormatAdapter> format)
49 {
50     if (CHECK_REF_PTR_IS_NULL(format)) {
51         return (int32_t)real_->SetParameterDecoder(nullptr);
52     }
53     return (int32_t)real_->SetParameterDecoder(std::make_shared<ArkDecoderFormatAdapterWrapper>(format));
54 }
55 
SetOutputSurface(void * window)56 int32_t ArkMediaCodecDecoderAdapterImpl::SetOutputSurface(void* window)
57 {
58     return (int32_t)real_->SetOutputSurface(window);
59 }
60 
PrepareDecoder()61 int32_t ArkMediaCodecDecoderAdapterImpl::PrepareDecoder()
62 {
63     return (int32_t)real_->PrepareDecoder();
64 }
65 
StartDecoder()66 int32_t ArkMediaCodecDecoderAdapterImpl::StartDecoder()
67 {
68     return (int32_t)real_->StartDecoder();
69 }
70 
StopDecoder()71 int32_t ArkMediaCodecDecoderAdapterImpl::StopDecoder()
72 {
73     return (int32_t)real_->StopDecoder();
74 }
75 
FlushDecoder()76 int32_t ArkMediaCodecDecoderAdapterImpl::FlushDecoder()
77 {
78     return (int32_t)real_->FlushDecoder();
79 }
80 
ResetDecoder()81 int32_t ArkMediaCodecDecoderAdapterImpl::ResetDecoder()
82 {
83     return (int32_t)real_->ResetDecoder();
84 }
85 
ReleaseDecoder()86 int32_t ArkMediaCodecDecoderAdapterImpl::ReleaseDecoder()
87 {
88     return (int32_t)real_->ReleaseDecoder();
89 }
90 
QueueInputBufferDec(uint32_t index,int64_t presentationTimeUs,int32_t size,int32_t offset,uint32_t flag)91 int32_t ArkMediaCodecDecoderAdapterImpl::QueueInputBufferDec(
92     uint32_t index, int64_t presentationTimeUs, int32_t size, int32_t offset, uint32_t flag)
93 {
94     return (int32_t)real_->QueueInputBufferDec(index, presentationTimeUs, size, offset, (NWeb::BufferFlag)flag);
95 }
96 
GetOutputFormatDec(ArkWebRefPtr<ArkDecoderFormatAdapter> format)97 int32_t ArkMediaCodecDecoderAdapterImpl::GetOutputFormatDec(ArkWebRefPtr<ArkDecoderFormatAdapter> format)
98 {
99     if (CHECK_REF_PTR_IS_NULL(format)) {
100         return (int32_t)real_->GetOutputFormatDec(nullptr);
101     }
102     return (int32_t)real_->GetOutputFormatDec(std::make_shared<ArkDecoderFormatAdapterWrapper>(format));
103 }
104 
ReleaseOutputBufferDec(uint32_t index,bool isRender)105 int32_t ArkMediaCodecDecoderAdapterImpl::ReleaseOutputBufferDec(uint32_t index, bool isRender)
106 {
107     return (int32_t)real_->ReleaseOutputBufferDec(index, isRender);
108 }
109 
SetCallbackDec(const ArkWebRefPtr<ArkDecoderCallbackAdapter> callback)110 int32_t ArkMediaCodecDecoderAdapterImpl::SetCallbackDec(const ArkWebRefPtr<ArkDecoderCallbackAdapter> callback)
111 {
112     if (CHECK_REF_PTR_IS_NULL(callback)) {
113         return (int32_t)real_->SetCallbackDec(nullptr);
114     }
115 
116     return (int32_t)real_->SetCallbackDec(std::make_shared<ArkDecoderCallbackAdapterWrapper>(callback));
117 }
118 
119 } // namespace OHOS::ArkWeb
120