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 8077a4119567a7bc3f9a471c6a9ffd51076c841b..459ef7707e04ef282f44634ed0cdc5f7832b5e87 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 609dc238e0af050156bd7952e9cbb0237a1cc935..377eb8682d5c40499a38e45bedb1ee1c2a1468f9 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. * diff --git a/multimedia/av_codec/native_avcodec_videodecoder.h b/multimedia/av_codec/native_avcodec_videodecoder.h index 462d5011d07751e01fed1409fb6d8b60e05dac38..91f9a9095042eb44a0fe17ed020732d37d231056 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/video_decoder/libnative_media_vdec.ndk.json b/multimedia/av_codec/video_decoder/libnative_media_vdec.ndk.json index 3e0b2577178759128117962d43684e7369ffd6c2..be50faf10e4edda4ccffaeb8ca15aac7a7101491 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/media_foundation/native_averrors.h b/multimedia/media_foundation/native_averrors.h index 398a16f0fc334460d5a1d30647f198677c9def9a..93b6704f77a4f4e8e6ce87bee48faf7e2eadf94f 100644 --- a/multimedia/media_foundation/native_averrors.h +++ b/multimedia/media_foundation/native_averrors.h @@ -180,6 +180,22 @@ typedef enum OH_AVErrCode { * @since 14 */ AV_ERR_IO_UNSUPPORTED_REQUEST = 5411011, + /** + * @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_TRY_AGAIN_LATER = 5410006, } OH_AVErrCode; #ifdef __cplusplus