From 88768679aabacc102c03829f70448f6ab4be9b54 Mon Sep 17 00:00:00 2001 From: lzm Date: Tue, 17 Jun 2025 16:00:57 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=A8=A1=E5=BC=8Fsdk?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lzm --- .../libnative_media_codecbase.ndk.json | 4 + multimedia/av_codec/native_avcodec_base.h | 22 +++++ .../av_codec/native_avcodec_videodecoder.h | 81 +++++++++++++++++++ .../av_codec/native_avcodec_videoencoder.h | 78 ++++++++++++++++++ .../libnative_media_vdec.ndk.json | 16 ++++ .../libnative_media_venc.ndk.json | 16 ++++ multimedia/media_foundation/native_averrors.h | 17 +++- 7 files changed, 231 insertions(+), 3 deletions(-) diff --git a/multimedia/av_codec/codec_base/libnative_media_codecbase.ndk.json b/multimedia/av_codec/codec_base/libnative_media_codecbase.ndk.json index 8077a4119..459ef7707 100644 --- a/multimedia/av_codec/codec_base/libnative_media_codecbase.ndk.json +++ b/multimedia/av_codec/codec_base/libnative_media_codecbase.ndk.json @@ -529,5 +529,9 @@ { "first_introduced": "12", "name": "OH_AVCapability_GetFeatureProperties" + }, + { + "first_introduced": "20", + "name": "OH_MD_KEY_ENABLE_SYNC_MODE" } ] diff --git a/multimedia/av_codec/native_avcodec_base.h b/multimedia/av_codec/native_avcodec_base.h index 609dc238e..fcca46a26 100644 --- a/multimedia/av_codec/native_avcodec_base.h +++ b/multimedia/av_codec/native_avcodec_base.h @@ -1032,6 +1032,20 @@ extern const char *OH_MD_KEY_VIDEO_ENCODER_REPEAT_PREVIOUS_FRAME_AFTER; */ extern const char *OH_MD_KEY_VIDEO_ENCODER_REPEAT_PREVIOUS_MAX_COUNT; +/** + * @brief Key to enable synchronous mode, value type is (0 or 1): 1 is enabled, 0 otherwise. + * + * This is an optional key, default is 0.\n + * When enabled: + * - Callbacks should NOT be set for codecs + * - Buffer query APIs must be used instead + * - Only used in configuration phase + * + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @since 20 + */ +extern const char *OH_MD_KEY_ENABLE_SYNC_MODE; + /** * @brief Media type. * @@ -1047,6 +1061,14 @@ typedef enum OH_MediaType { * @since 12 */ MEDIA_TYPE_SUBTITLE = 2, + /** track is timed meta. + * @since 20 + */ + MEDIA_TYPE_TIMED_METADATA=5, + /** track is auxiliary. + * @since 20 + */ + MEDIA_TYPE_AUXILIARY=6, } OH_MediaType; /** diff --git a/multimedia/av_codec/native_avcodec_videodecoder.h b/multimedia/av_codec/native_avcodec_videodecoder.h index 462d5011d..91f9a9095 100644 --- a/multimedia/av_codec/native_avcodec_videodecoder.h +++ b/multimedia/av_codec/native_avcodec_videodecoder.h @@ -432,6 +432,87 @@ OH_AVErrCode OH_VideoDecoder_RenderOutputBufferAtTime(OH_AVCodec *codec, uint32_ */ OH_AVErrCode OH_VideoDecoder_FreeOutputBuffer(OH_AVCodec *codec, uint32_t index); +/** + * @brief Queries the index of the next available input buffer. + * + * This API must be followed by calling {@link OH_VideoDecoder_GetInputBuffer} to obtain the buffer handle, + * which should then be passed to the decoder via {@link OH_VideoDecoder_PushInputBuffer}.\n + * Note: This operation is only supported in synchronous mode.\n + * + * @syscap SystemCapability.Multimedia.Media.VideoDecoder + * @param codec Pointer to an OH_AVCodec instance. + * @param index The index of the input buffer. + * @param timeoutUs Timeout duration in microseconds, negative value indicates infinite wait. + * @return Returns AV_ERR_OK if the execution is successful, + * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. + * {@link AV_ERR_NO_MEMORY}, internal errors in the input decode instance, such as an abnormal NULL. + * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid. + * {@link AV_ERR_UNKNOWN}, unknown error. + * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. + * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. + + * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permitted in asynchronous mode. + * {@link AV_ERR_TRY_AGAIN_LATER}, query failed, recommended retry after delay. + * @since 20 + */ +OH_AVErrCode OH_VideoDecoder_QueryInputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs); + +/** + * @brief Acquires the handle of an available input buffer. + * + * Note: It's only applicable in synchronous mode.\n + * + * @syscap SystemCapability.Multimedia.Media.VideoDecoder + * @param codec Pointer to an OH_AVCodec instance + * @param index Buffer index obtained via {@link OH_VideoDecoder_QueryInputBuffer}. + * @return Returns a Pointer to an OH_AVBuffer instance. + * Return nullptr if no buffer available. + * @since 20 + */ +OH_AVBuffer *OH_VideoDecoder_GetInputBuffer(struct OH_AVCodec *codec, uint32_t index); + +/** + * @brief Queries the index of the next available output buffer. + * + * The obtained buffer handle through {@link OH_VideoDecoder_GetOutputBuffer} must be: + * - Return to the decoder via {@link OH_VideoDecoder_FreeOutputBuffer}, or + * - Rendered using {@link OH_VideoDecoder_RenderOutputBuffer}, or + * - Scheduled for rendering with {@link OH_VideoDecoder_RenderOutputBufferAtTime}\n + * Note: This operation is only supported in synchronous mode.\n + * + * @syscap SystemCapability.Multimedia.Media.VideoDecoder + * @param codec Pointer to an OH_AVCodec instance + * @param index The index of the output buffer + * @param timeoutUs Timeout duration in microseconds, negative value indicates infinite wait. + * @return Returns AV_ERR_OK if the execution is successful, + * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. + * {@link AV_ERR_NO_MEMORY}, internal errors in the input decode instance, such as an abnormal NULL. + * {@link AV_ERR_INVALID_VAL}, the decoder is nullptr or invalid. + * {@link AV_ERR_UNKNOWN}, unknown error. + * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. + * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. + * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permitted in asynchronous mode. + * {@link AV_ERR_STREAM_CHANGED}, stream format changed, call {@link OH_VideoDecoder_GetOutputDescription} to + * retrieve new steam information. + * {@link AV_ERR_TRY_AGAIN_LATER}, query failed, recommended retry after delay. + * @since 20 + */ +OH_AVErrCode OH_VideoDecoder_QueryOutputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs); + +/** + * @brief Acquires the handle of an available output buffer. + * + * Note: It's only applicable in synchronous mode.\n + * + * @syscap SystemCapability.Multimedia.Media.VideoDecoder + * @param codec Pointer to an OH_AVCodec instance + * @param index Buffer index obtained via {@link OH_VideoDecoder_QueryOutputBuffer}. + * @return Returns a Pointer to an OH_AVBuffer instance. + * Return nullptr if no buffer available. + * @since 20 + */ +OH_AVBuffer *OH_VideoDecoder_GetOutputBuffer(struct OH_AVCodec *codec, uint32_t index); + /** * @brief Check whether the current codec instance is valid. It can be used fault recovery or app * switchback from the background. diff --git a/multimedia/av_codec/native_avcodec_videoencoder.h b/multimedia/av_codec/native_avcodec_videoencoder.h index a0ccb13b6..7eb5f9a75 100644 --- a/multimedia/av_codec/native_avcodec_videoencoder.h +++ b/multimedia/av_codec/native_avcodec_videoencoder.h @@ -406,6 +406,84 @@ OH_AVErrCode OH_VideoEncoder_PushInputParameter(OH_AVCodec *codec, uint32_t inde */ OH_AVErrCode OH_VideoEncoder_FreeOutputBuffer(OH_AVCodec *codec, uint32_t index); +/** + * @brief Queries the index of the next available input buffer. + * + * This API must be followed by calling {@link OH_VideoEncoder_GetInputBuffer} to obtain the buffer handle, + * which should then be passed to the encoder via {@link OH_VideoEncoder_PushInputBuffer}.\n + * Note: This operation is only supported in synchronous mode.\n + * + * @syscap SystemCapability.Multimedia.Media.VideoEncoder + * @param codec Pointer to an OH_AVCodec instance + * @param index The index of the input buffer + * @param timeoutUs Timeout duration in microseconds, negative value indicates infinite wait. + * @return Returns AV_ERR_OK if the execution is successful, + * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. + * {@link AV_ERR_NO_MEMORY}, internal errors in the input encode instance, such as an abnormal NULL. + * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. + * {@link AV_ERR_UNKNOWN}, unknown error. + * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. + * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. + * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permitted in asynchronous mode. + * {@link AV_ERR_TRY_AGAIN_LATER}, query failed, recommended retry after delay.. + * @since 20 + */ +OH_AVErrCode OH_VideoEncoder_QueryInputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs); + +/** + * @brief Acquires the handle of an available input buffer. + * + * Note: It's only applicable in synchronous mode.\n + * + * @syscap SystemCapability.Multimedia.Media.VideoEncoder + * @param codec Pointer to an OH_AVCodec instance + * @param index Buffer index obtained via {@link OH_VideoEncoder_QueryInputBuffer}. + * @return Returns a Pointer to an OH_AVBuffer instance. + * Return nullptr if no buffer available. + * @since 20 + */ +OH_AVBuffer *OH_VideoEncoder_GetInputBuffer(struct OH_AVCodec *codec, uint32_t index); + +/** + * @brief Queries the index of the next available output buffer. + * + * The obtained buffer handle through {@link OH_VideoEncoder_GetOutputBuffer} must be + * return to the encoder via {@link OH_VideoEncoder_FreeOutputBuffer}.\n + * Note: This operation is only supported in synchronous mode.\n + * + * @syscap SystemCapability.Multimedia.Media.VideoEncoder + * @param codec Pointer to an OH_AVCodec instance + * @param index The index value corresponding to the output buffer + * @param timeoutUs Timeout duration in microseconds, negative value indicates infinite wait. + * @return Returns AV_ERR_OK if the execution is successful, + * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. + * {@link AV_ERR_NO_MEMORY}, internal errors in the input encode instance, such as an abnormal NULL. + * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. + * {@link AV_ERR_UNKNOWN}, unknown error. + * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. + * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. + * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permitted in asynchronous mode. + * {@link AV_ERR_STREAM_CHANGED}, stream format changed, call {@link OH_VideoEncoder_GetOutputDescription} to + * retrieve new steam information. + * {@link AV_ERR_TRY_AGAIN_LATER}, query failed, recommended retry after delay. + * @since 20 + */ +OH_AVErrCode OH_VideoEncoder_QueryOutputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs); + +/** + * @brief Acquires the handle of an available output buffer. + * + * Note: It's only applicable in synchronous mode.\n + * + * @syscap SystemCapability.Multimedia.Media.VideoEncoder + * @param codec Pointer to an OH_AVCodec instance + * @param index Buffer index obtained via {@link OH_VideoEncoder_QueryOutputBuffer}. + * @return Returns a Pointer to an OH_AVBuffer instance. + * Return nullptr if no buffer available. + * @since 20 + */ +OH_AVBuffer *OH_VideoEncoder_GetOutputBuffer(struct OH_AVCodec *codec, uint32_t index); + /** * @brief Get the input data description of the encoder after call {@OH_VideoEncoder_Configure}, * refer to {@link OH_AVFormat} for details. It should be noted that the life cycle of the OH_AVFormat diff --git a/multimedia/av_codec/video_decoder/libnative_media_vdec.ndk.json b/multimedia/av_codec/video_decoder/libnative_media_vdec.ndk.json index 3e0b25771..be50faf10 100644 --- a/multimedia/av_codec/video_decoder/libnative_media_vdec.ndk.json +++ b/multimedia/av_codec/video_decoder/libnative_media_vdec.ndk.json @@ -90,6 +90,22 @@ { "first_introduced": "12", "name": "OH_VideoDecoder_RenderOutputBufferAtTime" + }, + { + "first_introduced": "20", + "name": "OH_VideoDecoder_QueryInputBuffer" + }, + { + "first_introduced": "20", + "name": "OH_VideoDecoder_QueryOutputBuffer" + }, + { + "first_introduced": "20", + "name": "OH_VideoDecoder_GetInputBuffer" + }, + { + "first_introduced": "20", + "name": "OH_VideoDecoder_GetOutputBuffer" } ] diff --git a/multimedia/av_codec/video_encoder/libnative_media_venc.ndk.json b/multimedia/av_codec/video_encoder/libnative_media_venc.ndk.json index 0f61de3ea..87dd03ac8 100644 --- a/multimedia/av_codec/video_encoder/libnative_media_venc.ndk.json +++ b/multimedia/av_codec/video_encoder/libnative_media_venc.ndk.json @@ -90,5 +90,21 @@ { "first_introduced": "12", "name": "OH_VideoEncoder_PushInputParameter" + }, + { + "first_introduced": "20", + "name": "OH_VideoEncoder_QueryInputBuffer" + }, + { + "first_introduced": "20", + "name": "OH_VideoEncoder_QueryOutputBuffer" + }, + { + "first_introduced": "20", + "name": "OH_VideoEncoder_GetInputBuffer" + }, + { + "first_introduced": "20", + "name": "OH_VideoEncoder_GetOutputBuffer" } ] diff --git a/multimedia/media_foundation/native_averrors.h b/multimedia/media_foundation/native_averrors.h index 398a16f0f..d028f97f8 100644 --- a/multimedia/media_foundation/native_averrors.h +++ b/multimedia/media_foundation/native_averrors.h @@ -176,10 +176,21 @@ typedef enum OH_AVErrCode { */ AV_ERR_IO_SSL_SERVER_CERT_UNTRUSTED = 5411010, /** - * @error unsupported request due to network protocols. - * @since 14 + * @error Signals a stream format change in synchronous mode. + * Required follow-up actions: + * - For video encoders: Call {@link OH_VideoEncoder_GetOutputDescription} + * - For video decoders: Call {@link OH_VideoDecoder_GetOutputDescription} + * - For audio decoders : Call {@link OH_AudioCodec_GetOutputDescription} + * to retrieve updated stream configuration. + * @since 20 + */ + AV_ERR_STREAM_CHANGED = 5410005, + /** + * @error Indicates temporary buffer query failure in synchronous mode, + * it's recommended to wait and retry the operation after a short interval. + * @since 20 */ - AV_ERR_IO_UNSUPPORTED_REQUEST = 5411011, + AV_ERR_TRY_AGAIN_LATER = 5410006, } OH_AVErrCode; #ifdef __cplusplus -- Gitee From db193706547339f0075e4d70790128919f27ea7a Mon Sep 17 00:00:00 2001 From: lzm Date: Tue, 17 Jun 2025 17:10:28 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=88=A0=E9=99=A4=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lzm --- multimedia/av_codec/native_avcodec_base.h | 8 -- .../av_codec/native_avcodec_videoencoder.h | 78 ------------------- .../libnative_media_venc.ndk.json | 16 ---- multimedia/media_foundation/native_averrors.h | 5 ++ 4 files changed, 5 insertions(+), 102 deletions(-) diff --git a/multimedia/av_codec/native_avcodec_base.h b/multimedia/av_codec/native_avcodec_base.h index fcca46a26..377eb8682 100644 --- a/multimedia/av_codec/native_avcodec_base.h +++ b/multimedia/av_codec/native_avcodec_base.h @@ -1061,14 +1061,6 @@ typedef enum OH_MediaType { * @since 12 */ MEDIA_TYPE_SUBTITLE = 2, - /** track is timed meta. - * @since 20 - */ - MEDIA_TYPE_TIMED_METADATA=5, - /** track is auxiliary. - * @since 20 - */ - MEDIA_TYPE_AUXILIARY=6, } OH_MediaType; /** diff --git a/multimedia/av_codec/native_avcodec_videoencoder.h b/multimedia/av_codec/native_avcodec_videoencoder.h index 7eb5f9a75..a0ccb13b6 100644 --- a/multimedia/av_codec/native_avcodec_videoencoder.h +++ b/multimedia/av_codec/native_avcodec_videoencoder.h @@ -406,84 +406,6 @@ OH_AVErrCode OH_VideoEncoder_PushInputParameter(OH_AVCodec *codec, uint32_t inde */ OH_AVErrCode OH_VideoEncoder_FreeOutputBuffer(OH_AVCodec *codec, uint32_t index); -/** - * @brief Queries the index of the next available input buffer. - * - * This API must be followed by calling {@link OH_VideoEncoder_GetInputBuffer} to obtain the buffer handle, - * which should then be passed to the encoder via {@link OH_VideoEncoder_PushInputBuffer}.\n - * Note: This operation is only supported in synchronous mode.\n - * - * @syscap SystemCapability.Multimedia.Media.VideoEncoder - * @param codec Pointer to an OH_AVCodec instance - * @param index The index of the input buffer - * @param timeoutUs Timeout duration in microseconds, negative value indicates infinite wait. - * @return Returns AV_ERR_OK if the execution is successful, - * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. - * {@link AV_ERR_NO_MEMORY}, internal errors in the input encode instance, such as an abnormal NULL. - * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. - * {@link AV_ERR_UNKNOWN}, unknown error. - * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. - * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. - * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permitted in asynchronous mode. - * {@link AV_ERR_TRY_AGAIN_LATER}, query failed, recommended retry after delay.. - * @since 20 - */ -OH_AVErrCode OH_VideoEncoder_QueryInputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs); - -/** - * @brief Acquires the handle of an available input buffer. - * - * Note: It's only applicable in synchronous mode.\n - * - * @syscap SystemCapability.Multimedia.Media.VideoEncoder - * @param codec Pointer to an OH_AVCodec instance - * @param index Buffer index obtained via {@link OH_VideoEncoder_QueryInputBuffer}. - * @return Returns a Pointer to an OH_AVBuffer instance. - * Return nullptr if no buffer available. - * @since 20 - */ -OH_AVBuffer *OH_VideoEncoder_GetInputBuffer(struct OH_AVCodec *codec, uint32_t index); - -/** - * @brief Queries the index of the next available output buffer. - * - * The obtained buffer handle through {@link OH_VideoEncoder_GetOutputBuffer} must be - * return to the encoder via {@link OH_VideoEncoder_FreeOutputBuffer}.\n - * Note: This operation is only supported in synchronous mode.\n - * - * @syscap SystemCapability.Multimedia.Media.VideoEncoder - * @param codec Pointer to an OH_AVCodec instance - * @param index The index value corresponding to the output buffer - * @param timeoutUs Timeout duration in microseconds, negative value indicates infinite wait. - * @return Returns AV_ERR_OK if the execution is successful, - * otherwise returns a specific error code, refer to {@link OH_AVErrCode}. - * {@link AV_ERR_NO_MEMORY}, internal errors in the input encode instance, such as an abnormal NULL. - * {@link AV_ERR_INVALID_VAL}, the encoder is nullptr or invalid. - * {@link AV_ERR_UNKNOWN}, unknown error. - * {@link AV_ERR_SERVICE_DIED}, avcodec service is died. - * {@link AV_ERR_INVALID_STATE}, this interface was called in invalid state. - * {@link AV_ERR_OPERATE_NOT_PERMIT}, not permitted in asynchronous mode. - * {@link AV_ERR_STREAM_CHANGED}, stream format changed, call {@link OH_VideoEncoder_GetOutputDescription} to - * retrieve new steam information. - * {@link AV_ERR_TRY_AGAIN_LATER}, query failed, recommended retry after delay. - * @since 20 - */ -OH_AVErrCode OH_VideoEncoder_QueryOutputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs); - -/** - * @brief Acquires the handle of an available output buffer. - * - * Note: It's only applicable in synchronous mode.\n - * - * @syscap SystemCapability.Multimedia.Media.VideoEncoder - * @param codec Pointer to an OH_AVCodec instance - * @param index Buffer index obtained via {@link OH_VideoEncoder_QueryOutputBuffer}. - * @return Returns a Pointer to an OH_AVBuffer instance. - * Return nullptr if no buffer available. - * @since 20 - */ -OH_AVBuffer *OH_VideoEncoder_GetOutputBuffer(struct OH_AVCodec *codec, uint32_t index); - /** * @brief Get the input data description of the encoder after call {@OH_VideoEncoder_Configure}, * refer to {@link OH_AVFormat} for details. It should be noted that the life cycle of the OH_AVFormat diff --git a/multimedia/av_codec/video_encoder/libnative_media_venc.ndk.json b/multimedia/av_codec/video_encoder/libnative_media_venc.ndk.json index 87dd03ac8..0f61de3ea 100644 --- a/multimedia/av_codec/video_encoder/libnative_media_venc.ndk.json +++ b/multimedia/av_codec/video_encoder/libnative_media_venc.ndk.json @@ -90,21 +90,5 @@ { "first_introduced": "12", "name": "OH_VideoEncoder_PushInputParameter" - }, - { - "first_introduced": "20", - "name": "OH_VideoEncoder_QueryInputBuffer" - }, - { - "first_introduced": "20", - "name": "OH_VideoEncoder_QueryOutputBuffer" - }, - { - "first_introduced": "20", - "name": "OH_VideoEncoder_GetInputBuffer" - }, - { - "first_introduced": "20", - "name": "OH_VideoEncoder_GetOutputBuffer" } ] diff --git a/multimedia/media_foundation/native_averrors.h b/multimedia/media_foundation/native_averrors.h index d028f97f8..93b6704f7 100644 --- a/multimedia/media_foundation/native_averrors.h +++ b/multimedia/media_foundation/native_averrors.h @@ -175,6 +175,11 @@ typedef enum OH_AVErrCode { * @since 14 */ AV_ERR_IO_SSL_SERVER_CERT_UNTRUSTED = 5411010, + /** + * @error unsupported request due to network protocols. + * @since 14 + */ + AV_ERR_IO_UNSUPPORTED_REQUEST = 5411011, /** * @error Signals a stream format change in synchronous mode. * Required follow-up actions: -- Gitee