diff --git a/multimedia/av_codec/native_avcapability.h b/multimedia/av_codec/native_avcapability.h index dd17584d4298db54d9597ee18d3289351706aa43..64c99b4e01f45f5fc8feb602d35b84c2951b4181 100644 --- a/multimedia/av_codec/native_avcapability.h +++ b/multimedia/av_codec/native_avcapability.h @@ -86,6 +86,10 @@ typedef enum OH_AVCapabilityFeature { VIDEO_ENCODER_LONG_TERM_REFERENCE = 1, /** Feature for codec supports low latency. It is used in video encoder and video decoder. */ VIDEO_LOW_LATENCY = 2, + /** Feature for codec supports B-frame encoding. It is only used in video encoder. + * @since 20 + */ + VIDEO_ENCODER_B_FRAME = 7, } OH_AVCapabilityFeature; /** @@ -448,6 +452,23 @@ bool OH_AVCapability_IsFeatureSupported(OH_AVCapability *capability, OH_AVCapabi */ OH_AVFormat *OH_AVCapability_GetFeatureProperties(OH_AVCapability *capability, OH_AVCapabilityFeature feature); +/** + * @brief Get the audio codec's supported sample rate ranges. + * + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @param capability Audio codec capability pointer. Do not give a video codec capability pointer + * @param sampleRateRanges Output parameter. A pointer to the sample rate ranges array + * @param rangesNum Output parameter. The element number of the sample rate ranges array + * @return Returns AV_ERR_OK if the execution is successful, + * otherwise returns a specific error code, refer to {@link OH_AVErrCode} + * {@link AV_ERR_INVALID_VAL}, the capability is invalid, the sampleRates is nullptr, or sampleRateNum is nullptr. + * {@link AV_ERR_UNKNOWN}, unknown error. + * {@link AV_ERR_NO_MEMORY}, internal use memory malloc failed. + * @since 20 +*/ +OH_AVErrCode OH_AVCapability_GetAudioSupportedSampleRateRanges(OH_AVCapability *capability, + OH_AVRange **sampleRateRanges, uint32_t *rangesNum); + #ifdef __cplusplus } #endif diff --git a/multimedia/av_codec/native_avcodec_audiocodec.h b/multimedia/av_codec/native_avcodec_audiocodec.h index 5495a534b089734ce5776ab21deda788b7c1a27c..bbd90ec7df012b2c44f8a0f01fe27e80209e780a 100644 --- a/multimedia/av_codec/native_avcodec_audiocodec.h +++ b/multimedia/av_codec/native_avcodec_audiocodec.h @@ -295,6 +295,79 @@ OH_AVErrCode OH_AudioCodec_IsValid(OH_AVCodec *codec, bool *isValid); */ OH_AVErrCode OH_AudioCodec_SetDecryptionConfig(OH_AVCodec *codec, MediaKeySession *mediaKeySession, bool secureAudio); + +/** + * @brief Queries the index of the next available input buffer. + * + * This API must be followed by calling {@link OH_AudioCodec_GetInputBuffer} to obtain the buffer handle, + * which should then be passed to the codec via {@link OH_AudioCodec_PushInputBuffer}.\n + * Note: This operation is only supported in synchronous mode.\n + * + * @syscap SystemCapability.Multimedia.Media.AudioCodec + * @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_INVALID_VAL}, input parameter is empty or invalid. + * {@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_AudioCodec_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.AudioCodec + * @param codec Pointer to an OH_AVCodec instance + * @param index Buffer index obtained via {@link OH_AudioCodec_QueryInputBuffer}. + * @return Returns a Pointer to an OH_AVBuffer instance. + * Return nullptr if no buffer available. + * @since 20 + */ +OH_AVBuffer *OH_AudioCodec_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_AudioCodec_GetOutputBuffer} must be + * return to the audio codec via {@link OH_AudioCodec_FreeOutputBuffer}.\n + * Note: This operation is only supported in synchronous mode.\n + * + * @syscap SystemCapability.Multimedia.Media.AudioCodec + * @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_INVALID_VAL}, input parameter is empty or invalid. + * {@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_AudioCodec_GetOutputDescription} to + * retrieve new steam information. + * {@link AV_ERR_TRY_AGAIN_LATER}, query failed, recommended retry after delay. + * @since 20 + */ +OH_AVErrCode OH_AudioCodec_QueryOutputBuffer(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs); + +/** + * @brief Get the available output buffer handle. + * + * Note: This operation is only supported in synchronous mode.\n + * + * @syscap SystemCapability.Multimedia.Media.AudioCodec + * @param codec Pointer to an OH_AVCodec instance + * @param index The index value corresponding to the output buffer, + * should be given by {@link OH_AudioCodec_QueryOutputBuffer}. + * @return Returns a Pointer to an OH_AVBuffer instance. + * Return nullptr if no buffer available. + * @since 20 + */ +OH_AVBuffer *OH_AudioCodec_GetOutputBuffer(struct OH_AVCodec *codec, uint32_t index); #ifdef __cplusplus } #endif diff --git a/multimedia/av_codec/native_avcodec_base.h b/multimedia/av_codec/native_avcodec_base.h index 609dc238e0af050156bd7952e9cbb0237a1cc935..53d04c9f926857b23dfa98377fe392a9d878347b 100644 --- a/multimedia/av_codec/native_avcodec_base.h +++ b/multimedia/av_codec/native_avcodec_base.h @@ -1032,6 +1032,136 @@ 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 for describing the reference relationship between tracks, value type is int32_t*. + * + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @since 20 +*/ +extern const char *OH_MD_KEY_REFERENCE_TRACK_IDS; +/** + * @brief Key for describing the track reference type, value type is string. + * + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @since 20 +*/ +extern const char *OH_MD_KEY_TRACK_REFERENCE_TYPE; +/** + * @brief Key for describing the track description, value type is string. + * + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @since 20 +*/ +extern const char *OH_MD_KEY_TRACK_DESCRIPTION; +/** + * @brief Key to enable B-frame encoding, value type is int32_t (0 or 1): 1 is enabled, 0 otherwise. + * + * This is an optional key that applies only to video encoder, default is 0.\n + * If enabled, the video encoder will use B-frame, the decode order will be different from the display order.\n + * For unsupported platforms, Configuring this key will have no effect.\n + * Platform capability can be checked via {@link OH_AVCapability_IsFeatureSupported} with + * {@link OH_AVCapabilityFeature::VIDEO_ENCODER_B_FRAME}.\n + * It's only used in configuration phase.\n + * + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @since 20 +*/ +extern const char *OH_MD_KEY_VIDEO_ENCODER_ENABLE_B_FRAME; + +/** + * @brief Key for describing the maximum B-frame count of video encoder, value type is int32_t. + * + * Note: This key is only for querying the capability of the codec currently. + * Usage specifications: + * 1. Check feature support via {@link OH_AVCapability_IsFeatureSupported} with + * {@link OH_AVCapabilityFeature::VIDEO_ENCODER_B_FRAME}.\n + * 2. Obtain OH_AVFormat handle via {@link OH_AVCapability_GetFeatureProperties} with + * {@link OH_AVCapabilityFeature::VIDEO_ENCODER_B_FRAME}.\n + * 3. Get maximum B-frame count via {@link OH_AVFormat_GetIntValue} with this key.\n + * + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @since 20 +*/ +extern const char *OH_MD_KEY_VIDEO_ENCODER_MAX_B_FRAMES; + +/** + * @brief Key for the desired encoding quality, value type is int32_t, this key is only + * supported for encoders that are configured in Stable Quality RateControl, the higher + * values generally result in more efficient(smaller-sized) encoding. + * + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @since 20 +*/ +extern const char *OH_MD_KEY_SQR_FACTOR; +/** + * @brief Key for maximum bitrate, value type is int64_t. + * + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @since 20 +*/ +extern const char *OH_MD_KEY_MAX_BITRATE; +/** + * @brief Key to enable Bitrate Control Based on Presentation Time Stamp(PTS), + * value type is int32_t (0 or 1):1 is enabled, 0 otherwise. + * + * This is an optional key that applies only to video encoder, default is 0. + * If enabled, the PTS information must be carried in each video frame and sent to the encoder. + * It is used in configure. + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @since 20 +*/ +extern const char *OH_MD_KEY_VIDEO_ENCODER_ENABLE_PTS_BASED_RATECONTROL; +/** + * @brief Key to set the region of interest(ROI) as QpOffset-Rects, value type is string in the format + * "Top1,Left1-Bottom1,Right1=Offset1;Top2,Left2-Bottom2,Right2=Offset2;". Each "Top,Left-Bottom,Right=Offset" + * represents the coordinate information and quantization parameter of one ROI. Each "=Offset" in the string + * can be omitted, like "Top1,Left1-Bottom1,Right1;Top2,Left2-Bottom2,Right2=Offset2;", the encoder + * will use the default quantization parameter to perform the ROI encoding on the first ROI and + * use Offset2 on the second ROI. + * + * This is an optional key that applies only to video encoder. + * It is used in running process and is set with each frame. + * In surface mode, it is used in {@link OH_VideoEncoder_OnNeedInputParameter}. + * In buffer mode, it is configured via {@link OH_AVBuffer_SetParameter}. + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @since 20 +*/ +extern const char *OH_MD_KEY_VIDEO_ENCODER_ROI_PARAMS; +/** + * @brief Key for front moov of the mp4 and m4a media file, value type is int32_t (0 or 1):1 is enabled, 0 otherwise. + * + * This key may affect the performance of the stop function of the mp4 and m4a muxer. + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @since 20 +*/ +extern const char *OH_MD_KEY_ENABLE_MOOV_FRONT; + +/** + * @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 Key to enable to set input parameters per frame for video encoder, + * value type is (0 or 1):1 is enabled, 0 otherwise. + * + * This is an optional key, default is 0. Only use in synchronous mode.\n + * If enabled, the caller will set parameters for input surface of the encoder.\n + * It is used in configure.\n + * + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @since 20 + */ +extern const char *OH_MD_KEY_VIDEO_ENCODER_ENABLE_INPUT_PARAMETER_SYNC_MODE; + /** * @brief Media type. * @@ -1047,6 +1177,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; /** @@ -1562,7 +1700,11 @@ typedef enum OH_BitrateMode { /** Variable Bit rate mode. */ BITRATE_MODE_VBR = 1, /** Constant Quality mode. */ - BITRATE_MODE_CQ = 2 + BITRATE_MODE_CQ = 2, + /** Stable Quality Rate Control mode. + * @since 20 + */ + BITRATE_MODE_SQR = 3 } OH_BitrateMode; #ifdef __cplusplus diff --git a/multimedia/av_codec/native_avcodec_videodecoder.h b/multimedia/av_codec/native_avcodec_videodecoder.h index 462d5011d07751e01fed1409fb6d8b60e05dac38..7169203ea48abb3043c92b064bc733cfa42aec43 100644 --- a/multimedia/av_codec/native_avcodec_videodecoder.h +++ b/multimedia/av_codec/native_avcodec_videodecoder.h @@ -432,6 +432,86 @@ 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 a0ccb13b6d782a5ea7520a9bc64f7d5d24a346af..a2c092f376fcf3be74a86543d4aaf042eef42420 100644 --- a/multimedia/av_codec/native_avcodec_videoencoder.h +++ b/multimedia/av_codec/native_avcodec_videoencoder.h @@ -406,6 +406,127 @@ OH_AVErrCode OH_VideoEncoder_PushInputParameter(OH_AVCodec *codec, uint32_t inde */ OH_AVErrCode OH_VideoEncoder_FreeOutputBuffer(OH_AVCodec *codec, uint32_t index); +/** + * @brief Get index of next available input parameter. + * + * It's necessary to use {@link OH_VideoEncoder_GetInputParameter} to get the parameter handle, and then + * use {@link OH_VideoEncoder_PushInputParameter} to pass to the encoder.\n + * It's only used in synchronous mode.\n + * It's optional only for input surface + * and it's necessary to configure {@link OH_MD_KEY_VIDEO_ENCODER_ENABLE_INPUT_PARAMETER_SYNC_MODE}.\n + * + * @syscap SystemCapability.Multimedia.Media.VideoEncoder + * @param codec Pointer to an OH_AVCodec instance + * @param index The index value corresponding to the input buffer + * @param timeoutUs the query timeout time, in microseconds. + * @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}, the stream is changed, call {@link OH_VideoEncoder_GetOutputDescription} to + * retrieve steam information. + * {@link AV_ERR_TRY_AGAIN_LATER}, query failed, recommended to wait for a while and try the query again. + * @since 20 + */ +OH_AVErrCode OH_VideoEncoder_QueryInputParameter(struct OH_AVCodec *codec, uint32_t *index, int64_t timeoutUs); + +/** + * @brief Get the input parameter handle. + * + * It's only used 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 input param buffer, + * should be given by {@link OH_VideoEncoder_QueryInputParameter}. + * @return Returns a Pointer to an OH_AVFormat instance. + * Return nullptr when no input parameter is available. + * @since 20 + */ +OH_AVFormat *OH_VideoEncoder_GetInputParameter(struct 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/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 diff --git a/multimedia/media_foundation/native_avformat.h b/multimedia/media_foundation/native_avformat.h index ac30d2d47e37ffb44167ee56b6eef7c65b8f52b0..652be149cf260392ae951d51ee4428fb28bcbc71 100644 --- a/multimedia/media_foundation/native_avformat.h +++ b/multimedia/media_foundation/native_avformat.h @@ -80,6 +80,10 @@ typedef enum OH_AVPixelFormat { * RGBA8888 */ AV_PIXEL_FORMAT_RGBA = 5, + /** RGBA1010102 + * since 20 + */ + AV_PIXEL_FORMAT_RGBA1010102 = 6, } OH_AVPixelFormat; /** @@ -322,6 +326,49 @@ bool OH_AVFormat_GetBuffer(struct OH_AVFormat *format, const char *key, uint8_t */ const char *OH_AVFormat_DumpInfo(struct OH_AVFormat *format); +/** + * @brief Write an array of int32_t values to an OH_AVFormat object. + * + * @syscap SystemCapability.Multimedia.Media.Core + * @param format pointer to an OH_AVFormat instance + * @param key Data identifier key + * @param addr Pointer to the source data buffer + * @param size Number of elements to write (in elements, not bytes) + * @return The return value is TRUE for success, FALSE for failure + * Possible failure causes: + * 1. input format is nullptr. + * 2. input format's magic error. + * 3. key is nullptr. + * 4. addr is nullptr. + * 5. size is zero. + * @since 20 + */ +bool OH_AVFormat_SetIntBuffer(struct OH_AVFormat *format, const char *key, const int32_t *addr, size_t size); + +/** + * @brief Read an array of int32_t values from an OH_AVFormat object. + * + * Note that the obtained buffer's lifetime bound to the OH_AVFormat object, + * it's automatically invalidated when the format object is destroyed.\n + * Applications must explicitly copy the data to newly allocated memory if + * the data needs to outlive the OH_AVFormat instance.\n + * + * @syscap SystemCapability.Multimedia.Media.Core + * @param format pointer to an OH_AVFormat instance + * @param key Data identifier key + * @param addr Pointer to receive the data buffer reference + * @param size Pointer to receive the element count + * @return The return value is TRUE for success, FALSE for failure + * Possible failure causes: + * 1. input format is nullptr. + * 2. input format's magic error. + * 3. key is nullptr. + * 4. addr is nullptr. + * 5. size is nullptr. + * @since 20 + */ +bool OH_AVFormat_GetIntBuffer(struct OH_AVFormat *format, const char *key, int32_t **addr, size_t *size); + #ifdef __cplusplus } #endif