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_wrapper.h"
17
18 #include "ohos_adapter/bridge/ark_decoder_callback_adapter_impl.h"
19 #include "ohos_adapter/bridge/ark_decoder_format_adapter_impl.h"
20 #include "ohos_adapter/bridge/ark_audio_cenc_info_adapter_impl.h"
21
22 #include "base/bridge/ark_web_bridge_macros.h"
23
24 namespace OHOS::ArkWeb {
25
ArkMediaCodecDecoderAdapterWrapper(ArkWebRefPtr<ArkMediaCodecDecoderAdapter> ref)26 ArkMediaCodecDecoderAdapterWrapper::ArkMediaCodecDecoderAdapterWrapper(ArkWebRefPtr<ArkMediaCodecDecoderAdapter> ref)
27 : ctocpp_(ref)
28 {}
29
CreateVideoDecoderByMime(const std::string & mimetype)30 OHOS::NWeb::DecoderAdapterCode ArkMediaCodecDecoderAdapterWrapper::CreateVideoDecoderByMime(const std::string& mimetype)
31 {
32 ArkWebString str = ArkWebStringClassToStruct(mimetype);
33 int32_t result = ctocpp_->CreateVideoDecoderByMime(str);
34 ArkWebStringStructRelease(str);
35 return (OHOS::NWeb::DecoderAdapterCode)result;
36 }
37
CreateVideoDecoderByName(const std::string & name)38 OHOS::NWeb::DecoderAdapterCode ArkMediaCodecDecoderAdapterWrapper::CreateVideoDecoderByName(const std::string& name)
39 {
40 ArkWebString str = ArkWebStringClassToStruct(name);
41 int32_t result = ctocpp_->CreateVideoDecoderByName(str);
42 ArkWebStringStructRelease(str);
43 return (OHOS::NWeb::DecoderAdapterCode)result;
44 }
45
ConfigureDecoder(const std::shared_ptr<OHOS::NWeb::DecoderFormatAdapter> format)46 OHOS::NWeb::DecoderAdapterCode ArkMediaCodecDecoderAdapterWrapper::ConfigureDecoder(
47 const std::shared_ptr<OHOS::NWeb::DecoderFormatAdapter> format)
48 {
49 int32_t result;
50 if (CHECK_SHARED_PTR_IS_NULL(format)) {
51 result = ctocpp_->ConfigureDecoder(nullptr);
52 } else {
53 result = ctocpp_->ConfigureDecoder(new ArkDecoderFormatAdapterImpl(format));
54 }
55 return (OHOS::NWeb::DecoderAdapterCode)result;
56 }
57
SetParameterDecoder(const std::shared_ptr<OHOS::NWeb::DecoderFormatAdapter> format)58 OHOS::NWeb::DecoderAdapterCode ArkMediaCodecDecoderAdapterWrapper::SetParameterDecoder(
59 const std::shared_ptr<OHOS::NWeb::DecoderFormatAdapter> format)
60 {
61 int32_t result;
62 if (CHECK_SHARED_PTR_IS_NULL(format)) {
63 result = ctocpp_->SetParameterDecoder(nullptr);
64 } else {
65 result = ctocpp_->SetParameterDecoder(new ArkDecoderFormatAdapterImpl(format));
66 }
67
68 return (OHOS::NWeb::DecoderAdapterCode)result;
69 }
70
SetOutputSurface(void * window)71 OHOS::NWeb::DecoderAdapterCode ArkMediaCodecDecoderAdapterWrapper::SetOutputSurface(void* window)
72 {
73 int32_t result = ctocpp_->SetOutputSurface(window);
74 return (OHOS::NWeb::DecoderAdapterCode)result;
75 }
76
PrepareDecoder()77 OHOS::NWeb::DecoderAdapterCode ArkMediaCodecDecoderAdapterWrapper::PrepareDecoder()
78 {
79 int32_t result = ctocpp_->PrepareDecoder();
80 return (OHOS::NWeb::DecoderAdapterCode)result;
81 }
82
StartDecoder()83 OHOS::NWeb::DecoderAdapterCode ArkMediaCodecDecoderAdapterWrapper::StartDecoder()
84 {
85 int32_t result = ctocpp_->StartDecoder();
86 return (OHOS::NWeb::DecoderAdapterCode)result;
87 }
88
StopDecoder()89 OHOS::NWeb::DecoderAdapterCode ArkMediaCodecDecoderAdapterWrapper::StopDecoder()
90 {
91 int32_t result = ctocpp_->StopDecoder();
92 return (OHOS::NWeb::DecoderAdapterCode)result;
93 }
94
FlushDecoder()95 OHOS::NWeb::DecoderAdapterCode ArkMediaCodecDecoderAdapterWrapper::FlushDecoder()
96 {
97 int32_t result = ctocpp_->FlushDecoder();
98 return (OHOS::NWeb::DecoderAdapterCode)result;
99 }
100
ResetDecoder()101 OHOS::NWeb::DecoderAdapterCode ArkMediaCodecDecoderAdapterWrapper::ResetDecoder()
102 {
103 int32_t result = ctocpp_->ResetDecoder();
104 return (OHOS::NWeb::DecoderAdapterCode)result;
105 }
106
ReleaseDecoder()107 OHOS::NWeb::DecoderAdapterCode ArkMediaCodecDecoderAdapterWrapper::ReleaseDecoder()
108 {
109 int32_t result = ctocpp_->ReleaseDecoder();
110 return (OHOS::NWeb::DecoderAdapterCode)result;
111 }
112
QueueInputBufferDec(uint32_t index,int64_t presentationTimeUs,int32_t size,int32_t offset,OHOS::NWeb::BufferFlag flag)113 OHOS::NWeb::DecoderAdapterCode ArkMediaCodecDecoderAdapterWrapper::QueueInputBufferDec(
114 uint32_t index, int64_t presentationTimeUs, int32_t size, int32_t offset, OHOS::NWeb::BufferFlag flag)
115 {
116 int32_t result = ctocpp_->QueueInputBufferDec(index, presentationTimeUs, size, offset, (uint32_t)flag);
117 return (OHOS::NWeb::DecoderAdapterCode)result;
118 }
119
GetOutputFormatDec(std::shared_ptr<OHOS::NWeb::DecoderFormatAdapter> format)120 OHOS::NWeb::DecoderAdapterCode ArkMediaCodecDecoderAdapterWrapper::GetOutputFormatDec(
121 std::shared_ptr<OHOS::NWeb::DecoderFormatAdapter> format)
122 {
123 int32_t result;
124 if (CHECK_SHARED_PTR_IS_NULL(format)) {
125 result = ctocpp_->GetOutputFormatDec(nullptr);
126 } else {
127 result = ctocpp_->GetOutputFormatDec(new ArkDecoderFormatAdapterImpl(format));
128 }
129
130 return (OHOS::NWeb::DecoderAdapterCode)result;
131 }
132
ReleaseOutputBufferDec(uint32_t index,bool isRender)133 OHOS::NWeb::DecoderAdapterCode ArkMediaCodecDecoderAdapterWrapper::ReleaseOutputBufferDec(uint32_t index, bool isRender)
134 {
135 int32_t result = ctocpp_->ReleaseOutputBufferDec(index, isRender);
136 return (OHOS::NWeb::DecoderAdapterCode)result;
137 }
138
SetCallbackDec(const std::shared_ptr<OHOS::NWeb::DecoderCallbackAdapter> callback)139 OHOS::NWeb::DecoderAdapterCode ArkMediaCodecDecoderAdapterWrapper::SetCallbackDec(
140 const std::shared_ptr<OHOS::NWeb::DecoderCallbackAdapter> callback)
141 {
142 int32_t result;
143 if (CHECK_SHARED_PTR_IS_NULL(callback)) {
144 result = ctocpp_->SetCallbackDec(nullptr);
145 } else {
146 result = ctocpp_->SetCallbackDec(new ArkDecoderCallbackAdapterImpl(callback));
147 }
148
149 return (OHOS::NWeb::DecoderAdapterCode)result;
150 }
151
SetDecryptionConfig(void * session,bool isSecure)152 OHOS::NWeb::DecoderAdapterCode ArkMediaCodecDecoderAdapterWrapper::SetDecryptionConfig(void *session, bool isSecure)
153 {
154 int32_t result = ctocpp_->SetDecryptionConfig(session, isSecure);
155 return (OHOS::NWeb::DecoderAdapterCode)result;
156 }
157
SetAVCencInfo(uint32_t index,const std::shared_ptr<NWeb::AudioCencInfoAdapter> cencInfo)158 OHOS::NWeb::DecoderAdapterCode ArkMediaCodecDecoderAdapterWrapper::SetAVCencInfo(
159 uint32_t index, const std::shared_ptr<NWeb::AudioCencInfoAdapter> cencInfo)
160 {
161 int32_t result;
162 if (CHECK_SHARED_PTR_IS_NULL(cencInfo)) {
163 result = ctocpp_->SetAVCencInfo(index, nullptr);
164 } else {
165 result = ctocpp_->SetAVCencInfo(index, new ArkAudioCencInfoAdapterImpl(cencInfo));
166 }
167
168 return (OHOS::NWeb::DecoderAdapterCode)result;
169 }
170 } // namespace OHOS::ArkWeb
171