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_encoder_adapter_wrapper.h" 17 18 #include "ohos_adapter/bridge/ark_codec_config_para_adapter_impl.h" 19 #include "ohos_adapter/bridge/ark_encoder_callback_adapter_impl.h" 20 #include "ohos_adapter/bridge/ark_producer_surface_adapter_wrapper.h" 21 22 #include "base/bridge/ark_web_bridge_macros.h" 23 24 namespace OHOS::ArkWeb { 25 ArkMediaCodecEncoderAdapterWrapper(ArkWebRefPtr<ArkMediaCodecAdapter> ref)26ArkMediaCodecEncoderAdapterWrapper::ArkMediaCodecEncoderAdapterWrapper(ArkWebRefPtr<ArkMediaCodecAdapter> ref) 27 : ctocpp_(ref) 28 {} 29 CreateVideoCodecByMime(const std::string mimetype)30OHOS::NWeb::CodecCodeAdapter ArkMediaCodecEncoderAdapterWrapper::CreateVideoCodecByMime(const std::string mimetype) 31 { 32 ArkWebString str = ArkWebStringClassToStruct(mimetype); 33 int32_t result = ctocpp_->CreateVideoCodecByMime(str); 34 ArkWebStringStructRelease(str); 35 return (OHOS::NWeb::CodecCodeAdapter)result; 36 } 37 CreateVideoCodecByName(const std::string name)38OHOS::NWeb::CodecCodeAdapter ArkMediaCodecEncoderAdapterWrapper::CreateVideoCodecByName(const std::string name) 39 { 40 ArkWebString str = ArkWebStringClassToStruct(name); 41 int32_t result = ctocpp_->CreateVideoCodecByName(str); 42 ArkWebStringStructRelease(str); 43 return (OHOS::NWeb::CodecCodeAdapter)result; 44 } 45 Configure(const std::shared_ptr<OHOS::NWeb::CodecConfigParaAdapter> config)46OHOS::NWeb::CodecCodeAdapter ArkMediaCodecEncoderAdapterWrapper::Configure( 47 const std::shared_ptr<OHOS::NWeb::CodecConfigParaAdapter> config) 48 { 49 int32_t result; 50 if (CHECK_SHARED_PTR_IS_NULL(config)) { 51 result = ctocpp_->Configure(nullptr); 52 } else { 53 result = ctocpp_->Configure(new ArkCodecConfigParaAdapterImpl(config)); 54 } 55 return (OHOS::NWeb::CodecCodeAdapter)result; 56 } 57 Prepare()58OHOS::NWeb::CodecCodeAdapter ArkMediaCodecEncoderAdapterWrapper::Prepare() 59 { 60 int32_t result = ctocpp_->Prepare(); 61 return (OHOS::NWeb::CodecCodeAdapter)result; 62 } 63 Start()64OHOS::NWeb::CodecCodeAdapter ArkMediaCodecEncoderAdapterWrapper::Start() 65 { 66 int32_t result = ctocpp_->Start(); 67 return (OHOS::NWeb::CodecCodeAdapter)result; 68 } 69 Stop()70OHOS::NWeb::CodecCodeAdapter ArkMediaCodecEncoderAdapterWrapper::Stop() 71 { 72 int32_t result = ctocpp_->Stop(); 73 return (OHOS::NWeb::CodecCodeAdapter)result; 74 } 75 Reset()76OHOS::NWeb::CodecCodeAdapter ArkMediaCodecEncoderAdapterWrapper::Reset() 77 { 78 int32_t result = ctocpp_->Reset(); 79 return (OHOS::NWeb::CodecCodeAdapter)result; 80 } 81 Release()82OHOS::NWeb::CodecCodeAdapter ArkMediaCodecEncoderAdapterWrapper::Release() 83 { 84 int32_t result = ctocpp_->Release(); 85 return (OHOS::NWeb::CodecCodeAdapter)result; 86 } 87 SetCodecCallback(const std::shared_ptr<OHOS::NWeb::CodecCallbackAdapter> callback)88OHOS::NWeb::CodecCodeAdapter ArkMediaCodecEncoderAdapterWrapper::SetCodecCallback( 89 const std::shared_ptr<OHOS::NWeb::CodecCallbackAdapter> callback) 90 { 91 int32_t result; 92 if (CHECK_SHARED_PTR_IS_NULL(callback)) { 93 result = ctocpp_->SetCodecCallback(nullptr); 94 } else { 95 result = ctocpp_->SetCodecCallback(new ArkEncoderCallbackAdapterImpl(callback)); 96 } 97 98 return (OHOS::NWeb::CodecCodeAdapter)result; 99 } 100 CreateInputSurface()101std::shared_ptr<OHOS::NWeb::ProducerSurfaceAdapter> ArkMediaCodecEncoderAdapterWrapper::CreateInputSurface() 102 { 103 ArkWebRefPtr<ArkProducerSurfaceAdapter> surface = ctocpp_->CreateInputSurface(); 104 if (CHECK_REF_PTR_IS_NULL(surface)) { 105 return nullptr; 106 } 107 108 return std::make_shared<ArkProducerSurfaceAdapterWrapper>(surface); 109 } 110 ReleaseOutputBuffer(uint32_t index,bool isRender)111OHOS::NWeb::CodecCodeAdapter ArkMediaCodecEncoderAdapterWrapper::ReleaseOutputBuffer(uint32_t index, bool isRender) 112 { 113 int32_t result = ctocpp_->ReleaseOutputBuffer(index, isRender); 114 return (OHOS::NWeb::CodecCodeAdapter)result; 115 } 116 RequestKeyFrameSoon()117OHOS::NWeb::CodecCodeAdapter ArkMediaCodecEncoderAdapterWrapper::RequestKeyFrameSoon() 118 { 119 int32_t result = ctocpp_->RequestKeyFrameSoon(); 120 return (OHOS::NWeb::CodecCodeAdapter)result; 121 } 122 123 } // namespace OHOS::ArkWeb 124