• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2025 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_audio_codec_decoder_adapter_wrapper.h"
17 #include "ohos_adapter/bridge/ark_audio_decoder_callback_adapter_impl.h"
18 #include "ohos_adapter/bridge/ark_audio_decoder_format_adapter_impl.h"
19 #include "ohos_adapter/bridge/ark_audio_cenc_info_adapter_impl.h"
20 #include "base/bridge/ark_web_bridge_macros.h"
21 
22 namespace OHOS::ArkWeb {
23 
ArkAudioCodecDecoderAdapterWrapper(ArkWebRefPtr<ArkAudioCodecDecoderAdapter> ref)24 ArkAudioCodecDecoderAdapterWrapper::ArkAudioCodecDecoderAdapterWrapper(ArkWebRefPtr<ArkAudioCodecDecoderAdapter> ref)
25     : ctocpp_(ref)
26 {}
27 
CreateAudioDecoderByMime(const std::string & mimetype)28 OHOS::NWeb::AudioDecoderAdapterCode ArkAudioCodecDecoderAdapterWrapper::CreateAudioDecoderByMime(
29     const std::string& mimetype)
30 {
31     ArkWebString str = ArkWebStringClassToStruct(mimetype);
32     int32_t result = ctocpp_->CreateAudioDecoderByMime(str);
33     ArkWebStringStructRelease(str);
34     return (OHOS::NWeb::AudioDecoderAdapterCode)result;
35 }
36 
CreateAudioDecoderByName(const std::string & name)37 OHOS::NWeb::AudioDecoderAdapterCode ArkAudioCodecDecoderAdapterWrapper::CreateAudioDecoderByName(
38     const std::string& name)
39 {
40     ArkWebString str = ArkWebStringClassToStruct(name);
41     int32_t result = ctocpp_->CreateAudioDecoderByName(str);
42     ArkWebStringStructRelease(str);
43     return (OHOS::NWeb::AudioDecoderAdapterCode)result;
44 }
45 
ConfigureDecoder(const std::shared_ptr<OHOS::NWeb::AudioDecoderFormatAdapter> format)46 OHOS::NWeb::AudioDecoderAdapterCode ArkAudioCodecDecoderAdapterWrapper::ConfigureDecoder(
47     const std::shared_ptr<OHOS::NWeb::AudioDecoderFormatAdapter> 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 ArkAudioDecoderFormatAdapterImpl(format));
54     }
55     return (OHOS::NWeb::AudioDecoderAdapterCode)result;
56 }
57 
SetParameterDecoder(const std::shared_ptr<OHOS::NWeb::AudioDecoderFormatAdapter> format)58 OHOS::NWeb::AudioDecoderAdapterCode ArkAudioCodecDecoderAdapterWrapper::SetParameterDecoder(
59     const std::shared_ptr<OHOS::NWeb::AudioDecoderFormatAdapter> 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 ArkAudioDecoderFormatAdapterImpl(format));
66     }
67 
68     return (OHOS::NWeb::AudioDecoderAdapterCode)result;
69 }
70 
PrepareDecoder()71 OHOS::NWeb::AudioDecoderAdapterCode ArkAudioCodecDecoderAdapterWrapper::PrepareDecoder()
72 {
73     int32_t result = ctocpp_->PrepareDecoder();
74     return (OHOS::NWeb::AudioDecoderAdapterCode)result;
75 }
76 
StartDecoder()77 OHOS::NWeb::AudioDecoderAdapterCode ArkAudioCodecDecoderAdapterWrapper::StartDecoder()
78 {
79     int32_t result = ctocpp_->StartDecoder();
80     return (OHOS::NWeb::AudioDecoderAdapterCode)result;
81 }
82 
StopDecoder()83 OHOS::NWeb::AudioDecoderAdapterCode ArkAudioCodecDecoderAdapterWrapper::StopDecoder()
84 {
85     int32_t result = ctocpp_->StopDecoder();
86     return (OHOS::NWeb::AudioDecoderAdapterCode)result;
87 }
88 
FlushDecoder()89 OHOS::NWeb::AudioDecoderAdapterCode ArkAudioCodecDecoderAdapterWrapper::FlushDecoder()
90 {
91     int32_t result = ctocpp_->FlushDecoder();
92     return (OHOS::NWeb::AudioDecoderAdapterCode)result;
93 }
94 
ResetDecoder()95 OHOS::NWeb::AudioDecoderAdapterCode ArkAudioCodecDecoderAdapterWrapper::ResetDecoder()
96 {
97     int32_t result = ctocpp_->ResetDecoder();
98     return (OHOS::NWeb::AudioDecoderAdapterCode)result;
99 }
100 
ReleaseDecoder()101 OHOS::NWeb::AudioDecoderAdapterCode ArkAudioCodecDecoderAdapterWrapper::ReleaseDecoder()
102 {
103     int32_t result = ctocpp_->ReleaseDecoder();
104     return (OHOS::NWeb::AudioDecoderAdapterCode)result;
105 }
106 
QueueInputBufferDec(uint32_t index,int64_t presentationTimeUs,uint8_t * bufferData,int32_t bufferSize,const std::shared_ptr<OHOS::NWeb::AudioCencInfoAdapter> cencInfo,bool isEncrypted,NWeb::BufferFlag flag)107 OHOS::NWeb::AudioDecoderAdapterCode ArkAudioCodecDecoderAdapterWrapper::QueueInputBufferDec(uint32_t index,
108     int64_t presentationTimeUs, uint8_t *bufferData, int32_t bufferSize,
109     const std::shared_ptr<OHOS::NWeb::AudioCencInfoAdapter> cencInfo, bool isEncrypted, NWeb::BufferFlag flag)
110 {
111     int32_t result = ctocpp_->QueueInputBufferDec(index, presentationTimeUs, bufferData, bufferSize,
112         new ArkAudioCencInfoAdapterImpl(cencInfo), isEncrypted, (uint32_t)flag);
113     return (OHOS::NWeb::AudioDecoderAdapterCode)result;
114 }
115 
GetOutputFormatDec(std::shared_ptr<OHOS::NWeb::AudioDecoderFormatAdapter> format)116 OHOS::NWeb::AudioDecoderAdapterCode ArkAudioCodecDecoderAdapterWrapper::GetOutputFormatDec(
117     std::shared_ptr<OHOS::NWeb::AudioDecoderFormatAdapter> format)
118 {
119     int32_t result;
120     if (CHECK_SHARED_PTR_IS_NULL(format)) {
121         result = ctocpp_->GetOutputFormatDec(nullptr);
122     } else {
123         result = ctocpp_->GetOutputFormatDec(new ArkAudioDecoderFormatAdapterImpl(format));
124     }
125 
126     return (OHOS::NWeb::AudioDecoderAdapterCode)result;
127 }
128 
129 
ReleaseOutputBufferDec(uint32_t index)130 OHOS::NWeb::AudioDecoderAdapterCode ArkAudioCodecDecoderAdapterWrapper::ReleaseOutputBufferDec(uint32_t index)
131 {
132     int32_t result = ctocpp_->ReleaseOutputBufferDec(index);
133     return (OHOS::NWeb::AudioDecoderAdapterCode)result;
134 }
135 
SetCallbackDec(const std::shared_ptr<OHOS::NWeb::AudioDecoderCallbackAdapter> callback)136 OHOS::NWeb::AudioDecoderAdapterCode ArkAudioCodecDecoderAdapterWrapper::SetCallbackDec(
137     const std::shared_ptr<OHOS::NWeb::AudioDecoderCallbackAdapter> callback)
138 {
139     int32_t result;
140     if (CHECK_SHARED_PTR_IS_NULL(callback)) {
141         result = ctocpp_->SetCallbackDec(nullptr);
142     } else {
143         result = ctocpp_->SetCallbackDec(new ArkAudioDecoderCallbackAdapterImpl(callback));
144     }
145 
146     return (OHOS::NWeb::AudioDecoderAdapterCode)result;
147 }
148 
SetDecryptionConfig(void * session,bool secureAudio)149 OHOS::NWeb::AudioDecoderAdapterCode ArkAudioCodecDecoderAdapterWrapper::SetDecryptionConfig(
150     void *session, bool secureAudio)
151 {
152     int32_t result = ctocpp_->SetDecryptionConfig(session, secureAudio);
153     return (OHOS::NWeb::AudioDecoderAdapterCode)result;
154 }
155 
156 } // namespace OHOS::ArkWeb
157