Skip to main content
Version: 14 Oct 2024

ml_media_codec.h

Classes

Name
structMLMediaCodecBufferInfo
structMLMediaCodecInputBufferInfo
MediaCodec Input buffer information.
structMLMediaCodecOutputBufferInfo
MediaCodec Output buffer information.
structMLMediaCodecOutputFormatInfo
MediaCodec Output Format information.
structMLMediaCodecErrorInfo
MediaCodec Output Format information.
structMLMediaCodecCallbacksEx
Callbacks for notifying asynchronously of various codec events to the user/client. If user intends to use codec in asynchronous mode, then the user/client is expected to implement these callbacks and take proper actions where appropriate.
structMLMediaCodecFrameRenderedInfo
MediaCodec Output Frame Rendered information.
structMLMediaCodecOutputFrameListener
Callbacks for notifying when an output frame is available for consumption or has been rendered on the output surface.
structMLMediaCodecCryptoPattern
Metadata describing an encryption pattern for the protected bytes in a subsample.
structMLMediaCodecCryptoInfo
Metadata describing the structure of a (at least partially) encrypted input sample. A buffer's data is considered to be partitioned into "subSamples", each subSample starts with a (potentially empty) run of plain, unencrypted bytes followed by a (also potentially empty) run of encrypted bytes. If pattern encryption applies, each of the encrypted runs is encrypted only partly, according to a repeating pattern of "encrypt" and "skip" blocks. This information encapsulates per-sample metadata as outlined in ISO/IEC FDIS 23001-7:2011 "Common encryption in ISO base media file format files".

Types

Name
typedef struct MLMediaCodecBufferInfoMLMediaCodecBufferInfo
typedef struct MLMediaCodecInputBufferInfoMLMediaCodecInputBufferInfo
MediaCodec Input buffer information.
typedef struct MLMediaCodecOutputBufferInfoMLMediaCodecOutputBufferInfo
MediaCodec Output buffer information.
typedef struct MLMediaCodecOutputFormatInfoMLMediaCodecOutputFormatInfo
MediaCodec Output Format information.
typedef struct MLMediaCodecErrorInfoMLMediaCodecErrorInfo
MediaCodec Output Format information.
typedef struct MLMediaCodecCallbacksExMLMediaCodecCallbacksEx
Callbacks for notifying asynchronously of various codec events to the user/client. If user intends to use codec in asynchronous mode, then the user/client is expected to implement these callbacks and take proper actions where appropriate.
typedef struct MLMediaCodecFrameRenderedInfoMLMediaCodecFrameRenderedInfo
MediaCodec Output Frame Rendered information.
typedef struct MLMediaCodecOutputFrameListenerMLMediaCodecOutputFrameListener
Callbacks for notifying when an output frame is available for consumption or has been rendered on the output surface.
typedef struct MLMediaCodecCryptoPatternMLMediaCodecCryptoPattern
Metadata describing an encryption pattern for the protected bytes in a subsample.
typedef struct MLMediaCodecCryptoInfoMLMediaCodecCryptoInfo
Metadata describing the structure of a (at least partially) encrypted input sample. A buffer's data is considered to be partitioned into "subSamples", each subSample starts with a (potentially empty) run of plain, unencrypted bytes followed by a (also potentially empty) run of encrypted bytes. If pattern encryption applies, each of the encrypted runs is encrypted only partly, according to a repeating pattern of "encrypt" and "skip" blocks. This information encapsulates per-sample metadata as outlined in ISO/IEC FDIS 23001-7:2011 "Common encryption in ISO base media file format files".

Enums

Name
enumMLMediaCodecCreation
{
MLMediaCodecCreation_ByName,
MLMediaCodecCreation_ByType,
MLMediaCodecCreation_Ensure32Bits = 0x7FFFFFFF
}
enumMLMediaCodecType
{
MLMediaCodecType_Encoder,
MLMediaCodecType_Decoder,
MLMediaCodecType_Ensure32Bits = 0x7FFFFFFF
}
enumMLMediaCodecBufferFlag
{
MLMediaCodecBufferFlag_KeyFrame = 1,
MLMediaCodecBufferFlag_CodecConfig = 2,
MLMediaCodecBufferFlag_EOS = 4,
MLMediaCodecBufferFlag_PartialFrame = 8,
MLMediaCodecBufferFlag_MuxerData = 16,
MLMediaCodecBufferFlag_Ensure32Bits = 0x7FFFFFFF
}
Indicate the type of data when queuing the input buffer via MLMediaCodecQueueInputBuffer() or MLMediaCodecQueueSecureInputBuffer().
enumMLMediaCodecOutputBufferStatus
{
MLMediaCodec_OutputBuffersChanged = -1014,
MLMediaCodec_FormatChanged = -1012,
MLMediaCodec_TryAgainLater = -11,
MLMediaCodecOutputBufferStatus_Ensure32Bits = 0x7FFFFFFF
}
Other than the normal buffer index, the output of MLMediaCodecDequeueOutputBuffer() can take on one of these statuses.
enumMLMediaCodecCryptoMode
{
MLMediaCodecCryptoMode_Clear,
MLMediaCodecCryptoMode_CTR,
MLMediaCodecCryptoMode_CBC,
MLMediaCodecCryptoMode_Ensure32Bits = 0x7FFFFFFF
}

Functions

Name
voidMLMediaCodecCallbacksExInit(MLMediaCodecCallbacksEx * inout_callbacks)
Initializes MLMediaCodecCallbacksEx with default values.
voidMLMediaCodecOutputFrameListenerInit(MLMediaCodecOutputFrameListener * inout_callbacks)
Initializes MLMediaCodecOutputFrameListener with default values.
voidMLMediaCodecCryptoInfoInit(MLMediaCodecCryptoInfo * inout_crypto_info)
Initializes MLMediaCodecCryptoInfo with default values.
MLResultMLMediaCodecCreateCryptoInfo(const MLMediaCodecCryptoInfo crypto_info, MLHandle out_crypto_info_handle)
Create a Crypto Info object.
MLResultMLMediaCodecReleaseCryptoInfo(MLHandle crypto_info_handle)
Release the Crypto Info created by MLMediaCodecCreateCryptoInfo.
MLResultMLMediaCodecCreateCodec(MLMediaCodecCreation method, MLMediaCodecType type, const char name_str, MLHandle out_handle)
Create a new MLMediaCodec.
MLResultMLMediaCodecDestroy(MLHandle handle)
Destroy a MLMediaCodec.
MLResultMLMediaCodecSetCallbacksEx(MLHandle handle, MLMediaCodecCallbacksEx callbacks, void user_data)
Set callbacks to notify client codec events. Client needs to implement the callback functions.
MLResultMLMediaCodecSetOutputFrameListener(MLHandle handle, MLMediaCodecOutputFrameListener callbacks, void user_data)
Registers a callback to be invoked when an output frame is available or rendered on the output surface.
MLResultMLMediaCodecGetName(MLHandle handle, char * out_name)
Obtain the name of the created codec.
MLResultMLMediaCodecConfigure(MLHandle handle, MLHandle format_handle, MLHandle surface_handle, MLHandle crypto_handle)
Configure the MLMediaCodec.
MLResultMLMediaCodecStart(MLHandle handle)
Start the codec.
MLResultMLMediaCodecStop(MLHandle handle)
Stop the codec.
MLResultMLMediaCodecReset(MLHandle handle)
Reset the codec.
MLResultMLMediaCodecFlush(MLHandle handle)
Flush the both the input and output ports of the codec.
MLResultMLMediaCodecSetParameters(MLHandle handle, MLHandle format_handle)
Communicate additional parameter changes to a codec.
MLResultMLMediaCodecGetInputBufferPointer(MLHandle handle, int64_t buffer_index, uint8_t * out_buffer_ptr, size_t out_buffer_size)
Obtain a writable buffer pointer for a dequeued input buffer index to contain the input data.
MLResultMLMediaCodecGetOutputBufferPointer(MLHandle handle, int64_t buffer_index, const uint8_t * out_buffer_ptr, size_t out_buffer_size)
Obtain a read-only buffer pointer for a dequeued output buffer index.
MLResultMLMediaCodecQueueInputBuffer(MLHandle handle, int64_t buffer_index, int64_t offset, size_t size, uint64_t time_us, int flags)
After filling a range of the input buffer at the specified index submit it to the component.
MLResultMLMediaCodecQueueSecureInputBuffer(MLHandle handle, int64_t buffer_index, int64_t offset, MLHandle crypto_info_handle, uint64_t time_us, int flags)
Similar to queueInputBuffer but submits a buffer that is potentially encrypted.
MLResultMLMediaCodecDequeueInputBuffer(MLHandle handle, int64_t timeout_us, int64_t * out_buffer_index)
Dequeue an input buffer from buffer queue.
MLResultMLMediaCodecDequeueOutputBuffer(MLHandle handle, MLMediaCodecBufferInfo out_buffer_info, int64_t timeout_us, int64_t out_buffer_index)
Dequeue an output buffer from buffer queue.
MLResultMLMediaCodecGetInputFormat(MLHandle handle, MLHandle * out_format_handle)
Obtain input format supported by the codec.
MLResultMLMediaCodecGetOutputFormat(MLHandle handle, MLHandle * out_format_handle)
Return output format supported by the codec, or the format to which the configuration has changed.
MLResultMLMediaCodecCreateInputSurface(MLHandle handle, MLHandle * out_input_surface_handle)
Create an input surface for a hardware encoder.
MLResultMLMediaCodecDestroyInputSurface(MLHandle handle, MLHandle input_surface_handle)
Release the Surface that was created by MLMediaCodecCreateInputSurface.
MLResultMLMediaCodecSignalEndOfInputStream(MLHandle handle)
Signal end-of-stream on input to a surface.
MLResultMLMediaCodecReleaseOutputBuffer(MLHandle handle, int64_t buffer_index, bool render)
Release buffer to codec or to render it on output surface.
MLResultMLMediaCodecReleaseOutputBufferAtTime(MLHandle handle, int64_t buffer_index, int64_t timestamp_ns)
Update surface timestamp and returns it to the codec to render it on the output surface. If codec is not configured with output surface, this call simply returns the buffer to codec.

Defines

Name
MAX_CODEC_NAME_SIZE

Enums Documentation

MLMediaCodecCreation

EnumeratorValueDescription
MLMediaCodecCreation_ByNameCreate by name.
MLMediaCodecCreation_ByTypeCreate by type.
MLMediaCodecCreation_Ensure32Bits0x7FFFFFFFEnsure enum is represented as 32 bits.

Media codec creation method.


MLMediaCodecType

EnumeratorValueDescription
MLMediaCodecType_EncoderEncoder.
MLMediaCodecType_DecoderDecoder.
MLMediaCodecType_Ensure32Bits0x7FFFFFFFEnsure enum is represented as 32 bits.

Media codec type.


MLMediaCodecBufferFlag

EnumeratorValueDescription
MLMediaCodecBufferFlag_KeyFrame1The (encoded) buffer contains the data for a key frame.
MLMediaCodecBufferFlag_CodecConfig2Buffer contains codec initialization OR codec specific data instead of media data.
MLMediaCodecBufferFlag_EOS4Signals the end of stream, i.e. no buffers will be available after this.
MLMediaCodecBufferFlag_PartialFrame8Buffer only contains part of a frame, and the decoder should batch the data until a buffer without this flag appears before decoding the frame.
MLMediaCodecBufferFlag_MuxerData16Buffer contains muxer data - Supported only for Exif data block.
MLMediaCodecBufferFlag_Ensure32Bits0x7FFFFFFFEnsure enum is represented as 32 bits.

Indicate the type of data when queuing the input buffer via MLMediaCodecQueueInputBuffer() or MLMediaCodecQueueSecureInputBuffer().

Deprecated

Deprecated since 1.4.0. Scheduled for removal.


MLMediaCodecOutputBufferStatus

EnumeratorValueDescription
MLMediaCodec_OutputBuffersChanged-1014Output buffer changed.
MLMediaCodec_FormatChanged-1012Format changed.
MLMediaCodec_TryAgainLater-11Try again later.
MLMediaCodecOutputBufferStatus_Ensure32Bits0x7FFFFFFFEnsure enum is represented as 32 bits.

Other than the normal buffer index, the output of MLMediaCodecDequeueOutputBuffer() can take on one of these statuses.

Deprecated

Deprecated since 1.4.0. Scheduled for removal.


MLMediaCodecCryptoMode

EnumeratorValueDescription
MLMediaCodecCryptoMode_ClearClear samples.
MLMediaCodecCryptoMode_CTRSample encrypted with AES CTR mode.
MLMediaCodecCryptoMode_CBCSample encrypted with AES CBC mode.
MLMediaCodecCryptoMode_Ensure32Bits0x7FFFFFFFEnsure enum is represented as 32 bits.

Crypto mode using which media samples are encrypted.


Types Documentation

MLMediaCodecBufferInfo

typedef struct MLMediaCodecBufferInfo MLMediaCodecBufferInfo;

Media codec buffer info.

More Info


MLMediaCodecInputBufferInfo

typedef struct MLMediaCodecInputBufferInfo MLMediaCodecInputBufferInfo;

MediaCodec Input buffer information.

More Info

Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

MLMediaCodecOutputBufferInfo

typedef struct MLMediaCodecOutputBufferInfo MLMediaCodecOutputBufferInfo;

MediaCodec Output buffer information.

More Info

Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

MLMediaCodecOutputFormatInfo

typedef struct MLMediaCodecOutputFormatInfo MLMediaCodecOutputFormatInfo;

MediaCodec Output Format information.

More Info

Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

MLMediaCodecErrorInfo

typedef struct MLMediaCodecErrorInfo MLMediaCodecErrorInfo;

MediaCodec Output Format information.

More Info

Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

MLMediaCodecCallbacksEx

typedef struct MLMediaCodecCallbacksEx MLMediaCodecCallbacksEx;

Callbacks for notifying asynchronously of various codec events to the user/client. If user intends to use codec in asynchronous mode, then the user/client is expected to implement these callbacks and take proper actions where appropriate.

More Info

Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

MLMediaCodecFrameRenderedInfo

typedef struct MLMediaCodecFrameRenderedInfo MLMediaCodecFrameRenderedInfo;

MediaCodec Output Frame Rendered information.

More Info

Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

MLMediaCodecOutputFrameListener

typedef struct MLMediaCodecOutputFrameListener MLMediaCodecOutputFrameListener;

Callbacks for notifying when an output frame is available for consumption or has been rendered on the output surface.

More Info

Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

MLMediaCodecCryptoPattern

typedef struct MLMediaCodecCryptoPattern MLMediaCodecCryptoPattern;

Metadata describing an encryption pattern for the protected bytes in a subsample.

More Info

Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

MLMediaCodecCryptoInfo

typedef struct MLMediaCodecCryptoInfo MLMediaCodecCryptoInfo;

Metadata describing the structure of a (at least partially) encrypted input sample. A buffer's data is considered to be partitioned into "subSamples", each subSample starts with a (potentially empty) run of plain, unencrypted bytes followed by a (also potentially empty) run of encrypted bytes. If pattern encryption applies, each of the encrypted runs is encrypted only partly, according to a repeating pattern of "encrypt" and "skip" blocks. This information encapsulates per-sample metadata as outlined in ISO/IEC FDIS 23001-7:2011 "Common encryption in ISO base media file format files".

More Info

Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

Functions Documentation

MLMediaCodecCallbacksExInit

static inline void MLMediaCodecCallbacksExInit(
MLMediaCodecCallbacksEx * inout_callbacks
)

Initializes MLMediaCodecCallbacksEx with default values.

Parameters

MLMediaCodecCallbacksEx *inout_callbacksMediaCodec Callback structure defined by MLMediaCodecCallbacksEx that needs to be initialized.
Deprecated

Deprecated since 1.4.0. Scheduled for removal.


MLMediaCodecOutputFrameListenerInit

static inline void MLMediaCodecOutputFrameListenerInit(
MLMediaCodecOutputFrameListener * inout_callbacks
)

Initializes MLMediaCodecOutputFrameListener with default values.

Parameters

MLMediaCodecOutputFrameListener *inout_callbacksMediaCodec Callback structure defined by MLMediaCodecOutputFrameListener that needs to be initialized.
Deprecated

Deprecated since 1.4.0. Scheduled for removal.


MLMediaCodecCryptoInfoInit

static inline void MLMediaCodecCryptoInfoInit(
MLMediaCodecCryptoInfo * inout_crypto_info
)

Initializes MLMediaCodecCryptoInfo with default values.

Parameters

MLMediaCodecCryptoInfo *inout_crypto_infoCryptoInfo structure defined by MLMediaCodecCryptoInfo that needs to be initialized.
Deprecated

Deprecated since 1.4.0. Scheduled for removal.


MLMediaCodecCreateCryptoInfo

MLResult MLMediaCodecCreateCryptoInfo(
const MLMediaCodecCryptoInfo * crypto_info,
MLHandle * out_crypto_info_handle
)

Create a Crypto Info object.

Parameters

const MLMediaCodecCryptoInfo *crypto_infoInput Structure that encapsulates sample crypto info.
MLHandle *out_crypto_info_handleUpon successful return will point to handle to the created Crypto info. Or else, it will point to ML_INVALID_HANDLE.

Returns

MLResultMLResult_InvalidParamIf one of parameters is invalid.
MLResultMLResult_OkIf operation succeeded.

Required Permissions:

  • None

The CryptoInfo object should be released by calling MLMediaCodecReleaseCryptoInfo.

Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

MLMediaCodecReleaseCryptoInfo

MLResult MLMediaCodecReleaseCryptoInfo(
MLHandle crypto_info_handle
)

Release the Crypto Info created by MLMediaCodecCreateCryptoInfo.

Parameters

MLHandlecrypto_info_handleHandle to Crypto info that needs to be released.

Returns

MLResultMLResult_InvalidParamIf one of parameters is invalid.
MLResultMLResult_OkIf operation succeeded.

Required Permissions:

  • None
Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

MLMediaCodecCreateCodec

MLResult MLMediaCodecCreateCodec(
MLMediaCodecCreation method,
MLMediaCodecType type,
const char * name_str,
MLHandle * out_handle
)

Create a new MLMediaCodec.

Parameters

MLMediaCodecCreationmethodOne of the creation methods defined by MLMediaCodecCreation.
MLMediaCodecTypetypeOne of the codec types defined by MLMediaCodecType.
const char *name_strIf creating a codec by name, this is the name of the codec. If creating a codec by type, this is the mime type of the codec. Refer to APIs in MLMediaCodecList for retrieving the list of names and mime types of supported codecs.
MLHandle *out_handleUpon successful return will point to handle to the created MLMediaCodec. Or else, it will point to ML_INVALID_HANDLE.

Returns

MLResultMLResult_InvalidParamOne of the parameters is invalid.
MLResultMLResult_OkMLMediaCodec object was created successfully.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None
Deprecated

Deprecated since 1.4.0. Scheduled for removal.


MLMediaCodecDestroy

MLResult MLMediaCodecDestroy(
MLHandle handle
)

Destroy a MLMediaCodec.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.

Returns

MLResultMLResult_InvalidParamMLMediaCodec object is invalid.
MLResultMLResult_OkMLMediaCodec object was successfully destroyed.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None
Deprecated

Deprecated since 1.4.0. Scheduled for removal.


MLMediaCodecSetCallbacksEx

MLResult MLMediaCodecSetCallbacksEx(
MLHandle handle,
MLMediaCodecCallbacksEx * callbacks,
void * user_data
)

Set callbacks to notify client codec events. Client needs to implement the callback functions.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.
MLMediaCodecCallbacksEx *callbacksSet of codec callbacks. Can be set to NULL to unset all the callback altogether.
void *user_dataPointer to user payload data.

Returns

MLResultMLResult_InvalidParamMLMediaCodec object is invalid.
MLResultMLResult_Okcallback was set successfully.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None

If the client intends to use the codec component in asynchronous mode, a valid callback should be provided before MLMediaCodecConfigure is called. When asynchronous callback is enabled, the client should not call:

  • MLMediaCodecDequeueInputBuffer
  • MLMediaCodecDequeueOutputBuffer Calling those functions will return MLMediaGenericResult_InvalidOperation. Also, MLMediaCodecFlush() behaves differently in asynchronous mode. After calling MLMediaCodecFlush, you must call MLMediaCodecStart() to "resume" receiving input buffers, even if an input surface was created.
Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

MLMediaCodecSetOutputFrameListener

MLResult MLMediaCodecSetOutputFrameListener(
MLHandle handle,
MLMediaCodecOutputFrameListener * callbacks,
void * user_data
)

Registers a callback to be invoked when an output frame is available or rendered on the output surface.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.
MLMediaCodecOutputFrameListener *callbacksSet of codec callbacks. Can be set to NULL to unset all the callback altogether.
void *user_dataPointer to user payload data.

Returns

MLResultMLResult_InvalidParamMLMediaCodec object is invalid.
MLResultMLResult_Okcallback was set successfully.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None

This method can be called in any codec state, but will only have an effect in the "Executing" state for codecs that render buffers to the output surface.

Note:

  • This callback is for informational purposes only: to get precise render timing samples, and can be significantly delayed and batched. Some frames may have been rendered even if there was no callback generated.
  • This callback doesn't set the codec to operate in asynchrous mode.
  • Since audio codec doesn't use Surface, this callback as no effect when audio codec is instantiated.
Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

MLMediaCodecGetName

MLResult MLMediaCodecGetName(
MLHandle handle,
char * out_name
)

Obtain the name of the created codec.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.
char *out_namePointer to the user-maintained buffer for storing the output C-style name string.

Returns

MLResultMLResult_InvalidParamOne of the parameters is invalid.
MLResultMLResult_OkMLMediaCodec name was retrieved successfully.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None

User shall allocate at least MAX_CODEC_NAME_SIZE bytes of memory for storing the output name string.

Deprecated

Deprecated since 1.4.0. Scheduled for removal.


MLMediaCodecConfigure

MLResult MLMediaCodecConfigure(
MLHandle handle,
MLHandle format_handle,
MLHandle surface_handle,
MLHandle crypto_handle
)

Configure the MLMediaCodec.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.
MLHandleformat_handleMLHandle to the #MediaFormat object.
MLHandlesurface_handleMLHandle to the Surface object.
MLHandlecrypto_handleMLHandle to the #MediaCrypto object. Pass 0 for clear content.

Returns

MLResultMLResult_InvalidParamOne of the parameters is invalid.
MLResultMLResult_OkMLMediaCodec was configured successfully.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None

Encoder configuration: surface_handle and crypto_handle should be 0. Decoder Configuration: The surface_handle should be provided if using output surface. The crypto_handle should be provided for encrypted content.

The output surface can be:

  1. For the first 3 cases (above), the decoded output of the decoder will be consumed direclty by the surface. This allows implementation of fast, zero-copy raw video consumption operation. Also, calling MLMediaCodecGetOutputBufferPointer will return MLMediaGenericResult_InvalidOperation
  2. For the last case, user will have to explictly consume the output of the decoder by calling MLMediaCodecGetOutputBufferPointer.
Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 6

MLMediaCodecStart

MLResult MLMediaCodecStart(
MLHandle handle
)

Start the codec.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.

Returns

MLResultMLResult_InvalidParamMLMediaCodec object is invalid.
MLResultMLResult_OkMLMediaCodec was started successfully.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None

Shall be called upon successful configuration.

Deprecated

Deprecated since 1.4.0. Scheduled for removal.


MLMediaCodecStop

MLResult MLMediaCodecStop(
MLHandle handle
)

Stop the codec.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.

Returns

MLResultMLResult_InvalidParamMLMediaCodec object is invalid.
MLResultMLResult_OkMLMediaCodec was stopped successfully.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None

Codec is stopped and not destroyed, therefore can be started again.

Deprecated

Deprecated since 1.4.0. Scheduled for removal.


MLMediaCodecReset

MLResult MLMediaCodecReset(
MLHandle handle
)

Reset the codec.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.

Returns

MLResultMLResult_InvalidParamMLMediaCodec object is invalid.
MLResultMLResult_OkMLMediaCodec was stopped successfully.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None

This will reset the codec to initial (Uninitialized) state. Call this when:

  • Input or output queuing operation fails.
  • An error is notified through the asynchronous event MLMediaCodecCallbacks.on_error. Resetting a codec can fail when an unrecoverable error occurs (which is Hardare codec implementation specific), in which case codec will be in unusable state and should be destroyed using MLMediaCodecDestroy.
Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

MLMediaCodecFlush

MLResult MLMediaCodecFlush(
MLHandle handle
)

Flush the both the input and output ports of the codec.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.

Returns

MLResultMLResult_InvalidParamMLMediaCodec object is invalid.
MLResultMLResult_OkMLMediaCodec was flushed successfully.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None

Upon return, all indices previously returned in calls to MLMediaCodecDequeueInputBuffer() and MLMediaCodecDequeueOutputBuffer() become invalid, and all buffers are owned by the codec.

Deprecated

Deprecated since 1.4.0. Scheduled for removal.


MLMediaCodecSetParameters

MLResult MLMediaCodecSetParameters(
MLHandle handle,
MLHandle format_handle
)

Communicate additional parameter changes to a codec.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.
MLHandleformat_handleMLHandle to the MLMediaFormat containing the parameters to set.

Returns

MLResultMLResult_InvalidParamAt least one of the input parameters or one of the format parameter values is invalid.
MLResultMLResult_OkThe operation was successful.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.
MLResultMLMediaGenericResult_InvalidOperationAt least one format parameter is not applicable.
MLResultMLMediaGenericResult_NoInitMLMediaCodec was not initialized.

Dynamically modify or add configuration parameters to a configured or started codec.

Create an empty MLMediaFormat object using MLMediaFormatCreate() and set the appropriate parameters. For more details, refer to ml_media_format.h.

Parameters and associated values that may be applied are:

  • MLMediaFormat_Key_Parameter_Video_Bitrate: Dynamically change the video encoder's target bitrate. Associated value is an int32_t representing the new encode bitrate in bits-per-second. Applicable to any video encoder.
  • MLMediaFormat_Key_Parameter_Request_Sync_Frame: Communicate to the encoder to produce a sync frame soon. Associated value is an int32_t with the value 0. Applicable to any video encoder.
  • MLMediaFormat_Key_Parameter_Drop_After: Set the time after which samples should be dropped and not submitted to the encoder. Associated value is an int64_t value representing the system time in micro-seconds. Applicable to an encoder receiving input from a surface.
  • MLMediaFormat_Key_Parameter_Drop_Before: Set the time before which samples should be dropped and not submitted to the encoder. Associated value is an int64_t value representing the system time in micro-seconds. Applicable to an encoder receiving input from a surface.
  • MLMediaFormat_Key_Parameter_Set_Suspend: Temporarily suspend or resume video encoding of input data. When suspended, all incoming buffers are discarded until suspension is lifted. Used in conjunction with MLMediaFormat_Key_Parameter_Set_Suspend_Time to speficy the time of suspension or resumption. Associated value is an int32_t value with the value 1 or 0 to suspend or resume, respectively. Applicable to an encoder receiving input from a surface.
  • MLMediaFormat_Key_Parameter_Set_Suspend_Time: Specifies the time when the action associated with the value of MLMediaFormat_Key_Parameter_Set_Suspend should take effect. Associated value is an int64_t value representing the system time, in micro-seconds, indicating when suspendion or resumption takes effect. Applicable to an encoder receiving input from a surface.
  • MLMediaFormat_Key_Parameter_Time_Offset: Describes an offset to adjust timestamps going forward on a video endcoder. Associated value is an int64_t value representing the offset timestamp, in micro-seconds. Applicable to an encoder receiving input from a surface.
  • MLMediaFormat_Key_Operating_Rate: Describes the rate at which a codec is expected to operate. For video, this is the operating frame rate; for audio, this is the sample rate. Associated value is a float value representing either the frames-per-second or the samples-per-second for video or audio, respectively. Applicable to any codec. Note: This key is ignored if it fails to apply. Note: This key can also be set as part of the MLMediaFormat provided at configure-time.
  • MLMediaFormat_Key_Intra_Refresh_Period: Describes the period of intra refresh in frames. Associated value is a int32_t value representing the period in frames after which the whole frame is completely refreshed. Applicable to any video encoder. Note: This key is ignored if not supported by the codec or it fails to apply. Note: This key can also be set as part of the MLMediaFormat provided at configure-time.
  • MLMediaFormat_Key_Latency: Describes the latency, in frames, a video encoder should have queued up before outputting at least one output frame. Associated value is an int32_t value representing the latency, in number of frames. Applicable to any video encoder. Note: This key is ignored if not supported by the codec or it fails to apply. Note: This key can also be set as part of the MLMediaFormat provided at configure-time.
Deprecated

Deprecated since 1.4.0. Scheduled for removal.

note

Some of these parameter changes may silently fail to apply. Unless specified below, an error will be returned on unsuccesful application.

API Level:

  • 9

MLMediaCodecGetInputBufferPointer

MLResult MLMediaCodecGetInputBufferPointer(
MLHandle handle,
int64_t buffer_index,
uint8_t ** out_buffer_ptr,
size_t * out_buffer_size
)

Obtain a writable buffer pointer for a dequeued input buffer index to contain the input data.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.
int64_tbuffer_indexThe index of a client-owned input buffer previously returned from a call to MLMediaCodecDequeueInputBuffer().
uint8_t **out_buffer_ptrPointer to returned input buffer.
size_t *out_buffer_sizeSize of returned input buffer.

Returns

MLResultMLResult_InvalidParamOne of the parameters is invalid.
MLResultMLResult_OkInput buffer pointer is retrieved successfully.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.
MLResultMLMediaGenericResult_InvalidOperationBuffer pointer could not be retrieved. Note that this API returns MLMediaGenericResult_InvalidOperation especially if video encoder has hardware input surface (see MLMediaCodecCreateInputSurface), and thus, out_buffer_ptr will be set to NULL and out_buffer_size set to 0.

Required Permissions:

  • None

After calling this method any buffer pointer previously returned for the same input index MUST no longer be used.

Note: For VIDEO encoder, this API will fail if an input surface was created by MLMediaCodecCreateInputSurface (see return value documentation below).

Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

MLMediaCodecGetOutputBufferPointer

MLResult MLMediaCodecGetOutputBufferPointer(
MLHandle handle,
int64_t buffer_index,
const uint8_t ** out_buffer_ptr,
size_t * out_buffer_size
)

Obtain a read-only buffer pointer for a dequeued output buffer index.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.
int64_tbuffer_indexThe index of a client-owned output buffer previously returned from a call to MLMediaCodecDequeueOutputBuffer().
const uint8_t **out_buffer_ptrPointer to returned output buffer.
size_t *out_buffer_sizeSize of returned output buffer.

Returns

MLResultMLResult_InvalidParamOne of the parameters is invalid.
MLResultMLResult_OkOutput buffer pointer is retrieved successfully.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.
MLResultMLMediaGenericResult_InvalidOperationBuffer pointer could not be retrieved. Note that this API returns MLMediaGenericResult_InvalidOperation especially if codec was VIDEO and configured with a hardware surface using MLMediaCodecConfigure(), and thus, out_buffer_ptr will be set to NULL and out_buffer_size set to 0 since decoded buffer lives in GPU memory and is not accessible via a pointer.

Required Permissions:

  • None

The position and limit of the returned buffer are set to the valid output data. After calling this method any buffer pointer previously returned for the same output index MUST no longer be used.

Note: For VIDEO decoder, this API will fail if codec was configured with a hardware surface (see return value documentation below).

Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

MLMediaCodecQueueInputBuffer

MLResult MLMediaCodecQueueInputBuffer(
MLHandle handle,
int64_t buffer_index,
int64_t offset,
size_t size,
uint64_t time_us,
int flags
)

After filling a range of the input buffer at the specified index submit it to the component.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.
int64_tbuffer_indexIndex of a client-owned input buffer previously returned in a call to MLMediaCodecDequeueInputBuffer().
int64_toffsetByte offset into the input buffer at which the data starts.
size_tsizeNumber of bytes of valid input data.
uint64_ttime_usPresentation timestamp in microseconds for this buffer. This is normally the media time at which this buffer should be presented (rendered).
intflagsA bitmask of flags defined by MLMediaCodecBufferFlag. While not prohibited, most codecs do not use the MLMediaCodecBufferFlag_KeyFrame flag for input buffers.

Returns

MLResultMLResult_InvalidParamOne of the parameters is invalid.
MLResultMLResult_OkIntput buffer is queued successfully.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None

Once an input buffer is queued to the codec, it MUST NOT be used until it is later retrieved by MLMediaCodecGetInputBufferPointer() in response to a MLMediaCodecDequeueInputBuffer() return value.

Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

MLMediaCodecQueueSecureInputBuffer

MLResult MLMediaCodecQueueSecureInputBuffer(
MLHandle handle,
int64_t buffer_index,
int64_t offset,
MLHandle crypto_info_handle,
uint64_t time_us,
int flags
)

Similar to queueInputBuffer but submits a buffer that is potentially encrypted.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.
int64_tbuffer_indexIndex of a client-owned input buffer previously returned in a call to MLMediaCodecDequeueInputBuffer().
int64_toffsetByte offset into the input buffer at which the data starts.
MLHandlecrypto_info_handleMetadata required to facilitate decryption, the object can be reused immediately after this call returns.
uint64_ttime_usPresentation timestamp in microseconds for this buffer. This is normally the media time at which this buffer should be presented (rendered).
intflagsA bitmask of flags defined by MLMediaCodecBufferFlag. While not prohibited, most codecs do not use the MLMediaCodecBufferFlag_KeyFrame flag for input buffers.

Returns

MLResultMLResult_InvalidParamOne of the parameters is invalid.
MLResultMLResult_OkSecure Intput buffer is queued successfully.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None
Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

MLMediaCodecDequeueInputBuffer

MLResult MLMediaCodecDequeueInputBuffer(
MLHandle handle,
int64_t timeout_us,
int64_t * out_buffer_index
)

Dequeue an input buffer from buffer queue.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.
int64_ttimeout_usTimeout in microseconds. Negative timeout indicates "infinite".
int64_t *out_buffer_indexIndex of an Input buffer from buffer queue, or MLMediaCodec_TryAgainLater status.

Returns

MLResultMLResult_InvalidParamOne of the parameters is invalid.
MLResultMLResult_OkIntput buffer is dequeued successfully.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.
MLResultMLMediaGenericResult_InvalidOperationif the codec is configured to operate in async mode.

Required Permissions:

  • None

This method will return immediately if timeoutUs == 0, wait indefinitely for the availability of an input buffer if timeoutUs < 0 or wait up to "timeoutUs" microseconds if timeoutUs > 0.

Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

MLMediaCodecDequeueOutputBuffer

MLResult MLMediaCodecDequeueOutputBuffer(
MLHandle handle,
MLMediaCodecBufferInfo * out_buffer_info,
int64_t timeout_us,
int64_t * out_buffer_index
)

Dequeue an output buffer from buffer queue.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.
MLMediaCodecBufferInfo *out_buffer_infoWill be filled with buffer meta data.
int64_ttimeout_usTimeout in microseconds. Negative timeout indicates "infinite".
int64_t *out_buffer_indexIndex of an output buffer from buffer queue, or one of the statuses defined by MLMediaCodecOutputBufferStatus.

Returns

MLResultMLResult_InvalidParamOne of the parameters is invalid.
MLResultMLResult_OkOutput buffer is dequeued successfully.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.
MLResultMLMediaGenericResult_InvalidOperationif the codec is configured to operate in async mode.

Required Permissions:

  • None

This method will return immediately if timeoutUs == 0, wait indefinitely for the availability of an input buffer if timeoutUs < 0 or wait up to "timeoutUs" microseconds if timeoutUs > 0.

Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

MLMediaCodecGetInputFormat

MLResult MLMediaCodecGetInputFormat(
MLHandle handle,
MLHandle * out_format_handle
)

Obtain input format supported by the codec.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.
MLHandle *out_format_handleInput format supported by the codec.

Returns

MLResultMLResult_InvalidParamOne of the parameters is invalid.
MLResultMLResult_OkInput Media format is retrieved successfully.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None

Call this function, after successful codec configuration, to determine what optional configuration parameters were supported by the codec.

Deprecated

Deprecated since 1.4.0. Scheduled for removal.


MLMediaCodecGetOutputFormat

MLResult MLMediaCodecGetOutputFormat(
MLHandle handle,
MLHandle * out_format_handle
)

Return output format supported by the codec, or the format to which the configuration has changed.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.
MLHandle *out_format_handleOutput format supported by the codec, or the format to which the configuration has changed.

Returns

MLResultMLResult_InvalidParamOne of the parameters is invalid.
MLResultMLResult_OkOutput Media format is retrieved successfully.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None
Deprecated

Deprecated since 1.4.0. Scheduled for removal.


MLMediaCodecCreateInputSurface

MLResult MLMediaCodecCreateInputSurface(
MLHandle handle,
MLHandle * out_input_surface_handle
)

Create an input surface for a hardware encoder.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.
MLHandle *out_input_surface_handleMLHandle to created input native surface. Valid only if result is MLResult_Ok.

Returns

MLResultMLResult_AllocFailedThe operation failed to allocate the surface.
MLResultMLResult_InvalidParamOne of the parameters is invalid.
MLResultMLResult_OkInput input surface was created successfully.
MLResultMLMediaGenericResult_AlreadyExistsAn input surface has already been created for the given handle.
MLResultMLMediaGenericResult_InvalidOperationMLMediaCodec is not an encoder.
MLResultMLMediaGenericResult_NoInitMLMediaCodec was not initialized.
MLResultMLMediaGenericResult_UnspecifiedFailureInput surface could not be created.

Required Permissions:

  • None

Requests an input surface to use as the input to an encoder, in place of input buffers.

This API must only be called after MLMediaCodecConfigure() and before MLMediaCodecStart() otherwise the operation will fail and an input surface cannot be created.

An input surface allows video consumers, such as a video encoder, to process raw input video buffers natively. The input surface is intended to act as a destination surface for your input data.

When using an input surface, there are no accessible input buffers, as buffers are automatically passed from the input surface to the codec. In synchronous mode, calling MLMediaCodecDequeueInputBuffer() will return MLMediaGenericResult_InvalidOperation. In asynchronous mode, the client will not be notified when an input buffer is available (i.e. the on_input_buffer_available callback will not fire).

The returned input surface can be passed as a destination surface to a decoder when calling MLMediaCodecConfigure(). Decoded output of the decoder can be consumed direclty as input to an encoder without copying. This allows implementation of fast, zero-copy transcoding.

The returned input surface can also be passed as a destination surface to:

Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 9

MLMediaCodecDestroyInputSurface

MLResult MLMediaCodecDestroyInputSurface(
MLHandle handle,
MLHandle input_surface_handle
)

Release the Surface that was created by MLMediaCodecCreateInputSurface.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.
MLHandleinput_surface_handleMLHandle to the internal Surface object.

Returns

MLResultMLResult_InvalidParamMLHandle is invalid.
MLResultMLResult_OkSurface object was successfully released.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.
MLResultMLMediaGenericResult_InvalidOperationMLMediaCodec is not an encoder.
MLResultMLMediaGenericResult_NoInitMLMediaCodec was not initialized.

Required Permissions:

  • None
Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 9

MLMediaCodecSignalEndOfInputStream

MLResult MLMediaCodecSignalEndOfInputStream(
MLHandle handle
)

Signal end-of-stream on input to a surface.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec.

Returns

MLResultMLResult_InvalidOperationMLMediaCodec is not an encoder or MLMediaCodec is not receving input from a surface.
MLResultMLResult_InvalidParamOne of the parameters is invalid.
MLResultMLResult_OkThe operation was successful.
MLResultMLMediaGenericResult_NoInitMLMediaCodec was not initialized.

This may only be used with encoders receiving input from a surface created by MLMediaCodecCreateInputSurface().

Equivalent to submitting an empty buffer with MLMediaCodecBufferFlag_EOS set when queueing an input buffer.

Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 9

MLMediaCodecReleaseOutputBuffer

MLResult MLMediaCodecReleaseOutputBuffer(
MLHandle handle,
int64_t buffer_index,
bool render
)

Release buffer to codec or to render it on output surface.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec object.
int64_tbuffer_indexIndex of a client-owned output buffer previously returned from a call to MLMediaCodecDequeueOutputBuffer().
boolrenderIf a valid surface was specified when configuring the codec, passing true renders this output buffer to the surface.

Returns

MLResultMLResult_InvalidParamOne of the parameters is invalid.
MLResultMLResult_OkOutput buffer was released successfully.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None

If codec is configured with an output surface, setting render to true will send the buffer to that output surface. The surface will release the buffer back to the codec once it is no longer used/displayed.

Once an output buffer is released to codec, it MUST NOT be used until it is later retrieved by MLMediaCodecGetOutputBufferPointer() in response to a MLMediaCodecDequeueOutputBuffer() return value.

Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

MLMediaCodecReleaseOutputBufferAtTime

MLResult MLMediaCodecReleaseOutputBufferAtTime(
MLHandle handle,
int64_t buffer_index,
int64_t timestamp_ns
)

Update surface timestamp and returns it to the codec to render it on the output surface. If codec is not configured with output surface, this call simply returns the buffer to codec.

Parameters

MLHandlehandleMLHandle to the MLMediaCodec object.
int64_tbuffer_indexIndex of a client-owned output buffer previously returned from a call to MLMediaCodecDequeueOutputBuffer().
int64_ttimestamp_nsThe timestamp in nanoseconds to associate with this buffer when it is sent to the Surface.

Returns

MLResultMLResult_InvalidParamOne of the parameters is invalid.
MLResultMLResult_OkOutput buffer was released successfully.
MLResultMLResult_UnspecifiedFailureThe operation failed with an unspecified error.

Required Permissions:

  • None

The timestamp may have special meaning depending on the destination surface.

Deprecated

Deprecated since 1.4.0. Scheduled for removal.

API Level:

  • 20

Macros Documentation

MAX_CODEC_NAME_SIZE

#define MAX_CODEC_NAME_SIZE 64

Source code

// %BANNER_BEGIN%
// ---------------------------------------------------------------------
// %COPYRIGHT_BEGIN%
// Copyright (c) 2017 Magic Leap, Inc. All Rights Reserved.
// Use of this file is governed by the Software License Agreement,
// located here: https://www.magicleap.com/software-license-agreement-ml2
// Terms and conditions applicable to third-party materials accompanying
// this distribution may also be found in the top-level NOTICE file
// appearing herein.
// %COPYRIGHT_END%
// ---------------------------------------------------------------------
// %BANNER_END%

#pragma once

#include "ml_api.h"

ML_EXTERN_C_BEGIN

typedef ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.") struct MLMediaCodecBufferInfo {
size_t offset;
size_t size;
size_t flags;
int64_t presentation_time_us;
} MLMediaCodecBufferInfo;

typedef enum MLMediaCodecCreation {
MLMediaCodecCreation_ByName,
MLMediaCodecCreation_ByType,
MLMediaCodecCreation_Ensure32Bits = 0x7FFFFFFF
} MLMediaCodecCreation;

typedef enum MLMediaCodecType {
MLMediaCodecType_Encoder,
MLMediaCodecType_Decoder,
MLMediaCodecType_Ensure32Bits = 0x7FFFFFFF
} MLMediaCodecType;

typedef enum MLMediaCodecBufferFlag {
MLMediaCodecBufferFlag_KeyFrame = 1,
MLMediaCodecBufferFlag_CodecConfig = 2,
MLMediaCodecBufferFlag_EOS = 4,
MLMediaCodecBufferFlag_PartialFrame = 8,
MLMediaCodecBufferFlag_MuxerData = 16,
MLMediaCodecBufferFlag_Ensure32Bits = 0x7FFFFFFF
} MLMediaCodecBufferFlag;

typedef enum MLMediaCodecOutputBufferStatus {
MLMediaCodec_OutputBuffersChanged = -1014,
MLMediaCodec_FormatChanged = -1012,
MLMediaCodec_TryAgainLater = -11,
MLMediaCodecOutputBufferStatus_Ensure32Bits = 0x7FFFFFFF
} MLMediaCodecOutputBufferStatus;

#define MAX_CODEC_NAME_SIZE 64

typedef ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.") struct MLMediaCodecInputBufferInfo {
int64_t input_buffer_index;
void *data;
} MLMediaCodecInputBufferInfo;

typedef ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.") struct MLMediaCodecOutputBufferInfo {
int64_t output_buffer_index;
MLMediaCodecBufferInfo *buffer_info;
void *data;
} MLMediaCodecOutputBufferInfo;

typedef ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.") struct MLMediaCodecOutputFormatInfo {
MLHandle new_output_format;
void *data;
} MLMediaCodecOutputFormatInfo;

typedef ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.") struct MLMediaCodecErrorInfo {
int error_code;
void *data;
} MLMediaCodecErrorInfo;

typedef ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.") struct MLMediaCodecCallbacksEx {
uint32_t version;

void (*on_input_buffer_available)(MLHandle media_codec, const MLMediaCodecInputBufferInfo *info);

void (*on_output_buffer_available)(MLHandle media_codec, const MLMediaCodecOutputBufferInfo *info);

void (*on_output_format_changed)(MLHandle media_codec, const MLMediaCodecOutputFormatInfo *info);

void (*on_error)(MLHandle media_codec, const MLMediaCodecErrorInfo *info);
} MLMediaCodecCallbacksEx;

ML_STATIC_INLINE void MLMediaCodecCallbacksExInit(MLMediaCodecCallbacksEx *inout_callbacks) {
if (inout_callbacks) {
inout_callbacks->version = 1;
inout_callbacks->on_input_buffer_available = NULL;
inout_callbacks->on_output_buffer_available = NULL;
inout_callbacks->on_output_format_changed = NULL;
inout_callbacks->on_error = NULL;
}
}

typedef ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.") struct MLMediaCodecFrameRenderedInfo {
int64_t presentation_time_us;
int64_t system_time_nano;
void *data;
} MLMediaCodecFrameRenderedInfo;

typedef ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.") struct MLMediaCodecOutputFrameListener {
uint32_t version;

void (*on_frame_rendered)(MLHandle media_codec, const MLMediaCodecFrameRenderedInfo *info);
} MLMediaCodecOutputFrameListener;

ML_STATIC_INLINE void MLMediaCodecOutputFrameListenerInit(MLMediaCodecOutputFrameListener *inout_callbacks) {
if (inout_callbacks) {
inout_callbacks->version = 1;
inout_callbacks->on_frame_rendered = NULL;
}
}

typedef enum MLMediaCodecCryptoMode {
MLMediaCodecCryptoMode_Clear,
MLMediaCodecCryptoMode_CTR,
MLMediaCodecCryptoMode_CBC,
MLMediaCodecCryptoMode_Ensure32Bits = 0x7FFFFFFF
} MLMediaCodecCryptoMode;

typedef ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.") struct MLMediaCodecCryptoPattern {
size_t encrypt_blocks;
size_t skip_blocks;
} MLMediaCodecCryptoPattern;

typedef ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.") struct MLMediaCodecCryptoInfo {
uint32_t version;

size_t number_of_subsamples;
MLMediaCodecCryptoMode crypto_mode;
MLMediaCodecCryptoPattern crypto_pattern;
const uint8_t* key;
const uint8_t* iv;
const size_t* bytes_of_clear_data;
const size_t* bytes_of_encrypted_data;
} MLMediaCodecCryptoInfo;

ML_STATIC_INLINE void MLMediaCodecCryptoInfoInit(MLMediaCodecCryptoInfo *inout_crypto_info) {
if (inout_crypto_info) {
inout_crypto_info->version = 1;
inout_crypto_info->number_of_subsamples = 0;
inout_crypto_info->crypto_mode = MLMediaCodecCryptoMode_Clear;
inout_crypto_info->crypto_pattern.encrypt_blocks = 0;
inout_crypto_info->crypto_pattern.skip_blocks = 0;
inout_crypto_info->key = NULL;
inout_crypto_info->iv = NULL;
inout_crypto_info->bytes_of_clear_data = NULL;
inout_crypto_info->bytes_of_encrypted_data = NULL;
}
}

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecCreateCryptoInfo(const MLMediaCodecCryptoInfo *crypto_info, MLHandle *out_crypto_info_handle);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecReleaseCryptoInfo(MLHandle crypto_info_handle);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecCreateCodec(MLMediaCodecCreation method, MLMediaCodecType type, const char *name_str, MLHandle *out_handle);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecDestroy(MLHandle handle);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecSetCallbacksEx(MLHandle handle, MLMediaCodecCallbacksEx *callbacks, void *user_data);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecSetOutputFrameListener(MLHandle handle, MLMediaCodecOutputFrameListener *callbacks, void *user_data);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecGetName(MLHandle handle, char *out_name);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecConfigure(MLHandle handle, MLHandle format_handle, MLHandle surface_handle, MLHandle crypto_handle);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecStart(MLHandle handle);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecStop(MLHandle handle);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecReset(MLHandle handle);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecFlush(MLHandle handle);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecSetParameters(MLHandle handle, MLHandle format_handle);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecGetInputBufferPointer(MLHandle handle, int64_t buffer_index, uint8_t **out_buffer_ptr, size_t *out_buffer_size);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecGetOutputBufferPointer(MLHandle handle, int64_t buffer_index, const uint8_t **out_buffer_ptr, size_t *out_buffer_size);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecQueueInputBuffer(MLHandle handle, int64_t buffer_index, int64_t offset, size_t size, uint64_t time_us, int flags);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecQueueSecureInputBuffer(MLHandle handle, int64_t buffer_index, int64_t offset, MLHandle crypto_info_handle, uint64_t time_us, int flags);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecDequeueInputBuffer(MLHandle handle, int64_t timeout_us, int64_t *out_buffer_index);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecDequeueOutputBuffer(MLHandle handle, MLMediaCodecBufferInfo *out_buffer_info, int64_t timeout_us, int64_t *out_buffer_index);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecGetInputFormat(MLHandle handle, MLHandle *out_format_handle);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecGetOutputFormat(MLHandle handle, MLHandle *out_format_handle);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecCreateInputSurface(MLHandle handle, MLHandle *out_input_surface_handle);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecDestroyInputSurface(MLHandle handle, MLHandle input_surface_handle);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecSignalEndOfInputStream(MLHandle handle);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecReleaseOutputBuffer(MLHandle handle, int64_t buffer_index, bool render);

ML_DEPRECATED_MSG("Use standard Android SDK and NDK APIs.")
ML_API MLResult ML_CALL MLMediaCodecReleaseOutputBufferAtTime(MLHandle handle, int64_t buffer_index, int64_t timestamp_ns);

ML_EXTERN_C_END