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