From 55111934dfa60b11a39af901f8dbdeb930349cd2 Mon Sep 17 00:00:00 2001 From: zhanghongran Date: Sat, 1 Apr 2023 11:50:12 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E8=B0=83=E6=95=B4=E5=8C=97=E5=90=91=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E9=A1=BA=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhanghongran --- frameworks/native/avcodec/avcodec_impl.cpp | 3 +- interfaces/kits/c/native_avcodec_codec.h | 62 +++++++++++----------- 2 files changed, 34 insertions(+), 31 deletions(-) diff --git a/frameworks/native/avcodec/avcodec_impl.cpp b/frameworks/native/avcodec/avcodec_impl.cpp index 9411ae33b..e90e5b264 100644 --- a/frameworks/native/avcodec/avcodec_impl.cpp +++ b/frameworks/native/avcodec/avcodec_impl.cpp @@ -158,7 +158,7 @@ int32_t AVCodecImpl::SetCallback(const std::shared_ptr &callbac return codecService_->SetCallback(callback); } -sptr AVCodecVideoEncoderImpl::CreateInputSurface() +sptr AVCodecImpl::CreateInputSurface() { CHECK_AND_RETURN_RET_LOG(codecService_ != nullptr, nullptr, "service died"); surface_ = codecService_->CreateInputSurface(); @@ -183,5 +183,6 @@ int32_t AVCodecImpl::DequeueOutputBuffer(size_t *index, int64_t timetUs) return codecService_->DequeueOutputBuffer(surface); } + } // namespace AVCodec } // namespace OHOS diff --git a/interfaces/kits/c/native_avcodec_codec.h b/interfaces/kits/c/native_avcodec_codec.h index ba1c5432a..c43c0554f 100644 --- a/interfaces/kits/c/native_avcodec_codec.h +++ b/interfaces/kits/c/native_avcodec_codec.h @@ -82,8 +82,8 @@ OH_AVErrCode OH_AVCodec_Destroy(OH_AVCodec *codec); OH_AVErrCode OH_AVCodec_SetCallback(OH_AVCodec *codec, OH_AVCodecCallback callback, void *userData); /** - * @brief To configure the codec, typically, you need to configure the description information of the decoded - * video track, which can be extracted from the container. This interface must be called before Start is called. + * @brief To configure the codec, typically, you would get the fotmat from an extractor for decoding. + * This interface must be called before Start is called. * @syscap SystemCapability.Multimedia.AVCodec.Codec * @param codec Pointer to an OH_AVCodec instance * @param format A pointer to an OH_AVFormat to give the description of the video track to be decoded @@ -168,6 +168,30 @@ OH_AVFormat *OH_AVCodec_GetOutputFormat(OH_AVCodec *codec); */ OH_AVErrCode OH_AVCodec_SetParameter(OH_AVCodec *codec, OH_AVFormat *format); +/** + * @brief Get the index of the next ready input buffer. + * @syscap SystemCapability.Multimedia.AVCodec.Codec + * @param codec Pointer to an OH_AVCodec instance + * @param timeoutUs timeoutUs + * @return Returns non-negtive value of the buffer index, + * otherwise returns negtive value for invalid buffer index + * @since 10 + * @version 4.0 + */ +int32_t OH_AVCodec_DequeueInputBuffer(OH_AVCodec *codec, int64_t timeoutUs); + +/** + * @brief Get an input buffer. + * The buffer index must be odbtained from OH_AVCodec_DequeueInputBuffer, and not queued yet. + * @syscap SystemCapability.Multimedia.AVCodec.Codec + * @param codec Pointer to an OH_AVCodec instance + * @param index The index value corresponding to the input Buffer + * @return Returns a pointer to an BufferElement instance + * @since 10 + * @version 4.0 + */ +OH_AVBufferElement* OH_AVCodec_GetInputBuffer(OH_AVCodec *codec, size_t index); + /** * @brief Submit the input buffer filled with data to the codec. The {@link OH_AVCodecOnInputDataReady} callback * will report the available input buffer and the corresponding index value. Once the buffer with the specified index @@ -187,18 +211,20 @@ OH_AVErrCode OH_AVCodec_SetParameter(OH_AVCodec *codec, OH_AVFormat *format); OH_AVErrCode OH_AVCodec_QueueInputBuffer(OH_AVCodec *codec, uint32_t index, OH_AVCodecBufferAttr attr); /** - * @brief Get an input buffer. + * @brief Get the index of the next ready output buffer of processed data. * @syscap SystemCapability.Multimedia.AVCodec.Codec * @param codec Pointer to an OH_AVCodec instance - * @param index The index value corresponding to the input Buffer - * @return Returns a pointer to an BufferElement instance + * @param timeoutUs timeoutUs + * @return Returns non-negtive value of the buffer index, + * otherwise returns negtive value for invalid buffer index * @since 10 * @version 4.0 */ -OH_AVBufferElement* OH_AVCodec_GetInputBuffer(OH_AVCodec *codec, size_t index); +int32_t OH_AVCodec_DequeueOutputBuffer(OH_AVCodec *codec, int64_t timeoutUs); /** * @brief Get an output buffer. + * The buffer index must be odbtained from OH_AVCodec_DequeueOutputBuffer. * @syscap SystemCapability.Multimedia.AVCodec.Codec * @param codec Pointer to an OH_AVCodec instance * @param index The index value corresponding to the output Buffer @@ -208,30 +234,6 @@ OH_AVBufferElement* OH_AVCodec_GetInputBuffer(OH_AVCodec *codec, size_t index); */ OH_AVBufferElement* OH_AVCodec_GetOutputBuffer(OH_AVCodec *codec, size_t index); -/** - * @brief Get the index of the next ready input buffer. - * @syscap SystemCapability.Multimedia.AVCodec.Codec - * @param codec Pointer to an OH_AVCodec instance - * @param timeoutUs timeoutUs - * @return Returns 0 or positive of the buffer index, - * otherwise returns negtive value for invalid buffer index - * @since 10 - * @version 4.0 - */ -int32_t OH_AVCodec_DequeueInputBuffer(OH_AVCodec *codec, int64_t timeoutUs); - -/** - * @brief Get the index of the next ready output buffer of processed data. - * @syscap SystemCapability.Multimedia.AVCodec.Codec - * @param codec Pointer to an OH_AVCodec instance - * @param timeoutUs timeoutUs - * @return Returns 0 or positive of the buffer index, - * otherwise returns negtive value for invalid buffer index - * @since 10 - * @version 4.0 - */ -int32_t OH_AVCodec_DequeueOutputBuffer(OH_AVCodec *codec, int64_t timeoutUs); - /** * @brief Return the processed output Buffer to the codec. * @syscap SystemCapability.Multimedia.AVCodec.Codec From ab85b46f21d4f590d539e678a7c04dc4b7a767bb Mon Sep 17 00:00:00 2001 From: zhanghongran Date: Sat, 1 Apr 2023 11:54:46 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E3=80=90=E4=BF=AE=E6=94=B9=E8=AF=B4?= =?UTF-8?q?=E6=98=8E=E3=80=91=E4=BC=98=E5=8C=96=E6=9D=A1=E4=BB=B6=E8=AF=AD?= =?UTF-8?q?=E5=8F=A5=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: zhanghongran --- frameworks/native/avcodec/avcodec_impl.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/frameworks/native/avcodec/avcodec_impl.cpp b/frameworks/native/avcodec/avcodec_impl.cpp index e90e5b264..251519137 100644 --- a/frameworks/native/avcodec/avcodec_impl.cpp +++ b/frameworks/native/avcodec/avcodec_impl.cpp @@ -29,12 +29,8 @@ std::shared_ptr CodecFactory::CreateByMime(const std::string &mime, boo std::shared_ptr impl = std::make_shared(); CHECK_AND_RETURN_RET_LOG(impl != nullptr, nullptr, "failed to new AVCodecImpl"); - int32_t ret; - if (encoder) { - ret = impl->Init(AVCODEC_TYPE_ENCODER, true, mime); - } else { - ret = impl->Init(AVCODEC_TYPE_DECODER, true, mime); - } + AVCodecType codeType = encoder ? AVCODEC_TYPE_ENCODER : AVCODEC_TYPE_DECODER; + int32_t ret = impl->Init(codeType, true, mime);; CHECK_AND_RETURN_RET_LOG(ret == MSERR_OK, nullptr, "failed to init AVCodecImpl"); return impl;