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