Tizen(Headed) Native API  6.5

The Media Codec APIs provides functions for encoding and decoding using media data.

Required Header

#include <media_codec.h>

Overview

Related Features

This API is related with the following features:

  • http://tizen.org/feature/multimedia.media_codec

It is recommended to design feature related codes in your application for reliability.

You can check if a device supports the related features for this API by using System Information, thereby controlling the procedure of your application.

To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.

More details on featuring your application can be found from Feature Element.

MEDIA CODEC API allows : The API allows you to direct access to the media codec on device. It operates on "raw" data, so any file headers must be stripped off. media_packet is used for zero-copy.

Functions

int mediacodec_create (mediacodec_h *mediacodec)
 Creates a mediacodec handle for decoding/encoding.
int mediacodec_destroy (mediacodec_h mediacodec)
 Destroys the mediacodec handle and releases all its resources.
int mediacodec_set_codec (mediacodec_h mediacodec, mediacodec_codec_type_e codec_type, int flags)
 Sets the codec type and decoder/encoder.
int mediacodec_set_vdec_info (mediacodec_h mediacodec, int width, int height)
 Sets the default info for the video decoder.
int mediacodec_set_venc_info (mediacodec_h mediacodec, int width, int height, int fps, int target_bits)
 Sets the default info for the video encoder.
int mediacodec_set_adec_info (mediacodec_h mediacodec, int samplerate, int channel, int bit)
 Sets the default info for the audio decoder.
int mediacodec_set_aenc_info (mediacodec_h mediacodec, int samplerate, int channel, int bit, int bitrate)
 Sets the default info for the audio encoder.
int mediacodec_configure_from_media_format (mediacodec_h mediacodec, media_format_h format, int flags)
 Sets the codec type and codec default info via media format.
int mediacodec_prepare (mediacodec_h mediacodec)
 Prepares mediacodec for encoding/decoding.
int mediacodec_unprepare (mediacodec_h mediacodec)
 Unprepares mediacodec for encoding/decoding.
int mediacodec_process_input (mediacodec_h mediacodec, media_packet_h inbuf, uint64_t timeOutUs)
 Decodes/Encodes a packet. The function passed undecoded/unencoded packet to the input queue and decode/encode a frame sequentially.
int mediacodec_get_output (mediacodec_h mediacodec, media_packet_h *packet, uint64_t timeOutUs)
 Gets the decoded or encoded packet from the output queue.
int mediacodec_flush_buffers (mediacodec_h mediacodec)
 Flushes both input and output buffers.
int mediacodec_set_input_buffer_used_cb (mediacodec_h mediacodec, mediacodec_input_buffer_used_cb callback, void *user_data)
 Sets empty buffer callback the media codec for process, asynchronously.
int mediacodec_unset_input_buffer_used_cb (mediacodec_h mediacodec)
 Unsets input buffer used callback the media codec for process, asynchronously.
int mediacodec_set_output_buffer_available_cb (mediacodec_h mediacodec, mediacodec_output_buffer_available_cb callback, void *user_data)
 Sets output buffer available callback the media codec for process, asynchronously.
int mediacodec_unset_output_buffer_available_cb (mediacodec_h mediacodec)
 unsets output buffer available callback the media codec for process, asynchronously.
int mediacodec_set_error_cb (mediacodec_h mediacodec, mediacodec_error_cb callback, void *user_data)
 Sets error callback the media codec for process, asynchronously.
int mediacodec_unset_error_cb (mediacodec_h mediacodec)
 Unsets error callback the media codec for process, asynchronously.
int mediacodec_set_eos_cb (mediacodec_h mediacodec, mediacodec_eos_cb callback, void *user_data)
 Sets eos callback the media codec for process, asynchronously.
int mediacodec_unset_eos_cb (mediacodec_h mediacodec)
 unsets eos callback the media codec for process, asynchronously.
int mediacodec_set_buffer_status_cb (mediacodec_h mediacodec, mediacodec_buffer_status_cb callback, void *user_data)
 Sets a callback function to be invoked when the mediacodec needs more data or has enough data.
int mediacodec_unset_buffer_status_cb (mediacodec_h mediacodec)
 Unsets the callback function.
int mediacodec_foreach_supported_codec (mediacodec_h mediacodec, mediacodec_supported_codec_cb callback, void *user_data)
 Retrieves all supported codecs by invoking callback function once for each supported codecs.
int mediacodec_get_supported_type (mediacodec_h mediacodec, mediacodec_codec_type_e codec_type, bool encoder, int *support_type)
 Verifies whether encoding can be performed with codec_type or not.
int mediacodec_get_packet_pool (mediacodec_h mediacodec, media_packet_pool_h *pool)
 Gets the media packet pool allocated for recycling media packets.

Typedefs

typedef struct mediacodec_s * mediacodec_h
 Media Codec type handle.
typedef void(* mediacodec_input_buffer_used_cb )(media_packet_h packet, void *user_data)
 Called when the input buffer(packet) used up.
typedef void(* mediacodec_output_buffer_available_cb )(media_packet_h packet, void *user_data)
 Called when the output buffer is available.
typedef void(* mediacodec_error_cb )(mediacodec_error_e error, void *user_data)
 Called when the error has occurred.
typedef void(* mediacodec_eos_cb )(void *user_data)
 Called when there is no data to decode/encode.
typedef void(* mediacodec_buffer_status_cb )(mediacodec_status_e status, void *user_data)
 Called when the mediacodec needs more data or has enough data.
typedef bool(* mediacodec_supported_codec_cb )(mediacodec_codec_type_e codec_type, void *user_data)
 Called once for each supported codec types.

Typedef Documentation

typedef void(* mediacodec_buffer_status_cb)(mediacodec_status_e status, void *user_data)

Called when the mediacodec needs more data or has enough data.

It is recommended that the application stops calling mediacodec_process_input() when MEDIACODEC_ENOUGH_DATA

Since :
2.4 is invoked.
Parameters:
[in]statusThe state of the buffer
[in]user_dataThe user data passed from the callback registration function
See also:
mediacodec_set_buffer_status_cb()
mediacodec_unset_buffer_status_cb()
typedef void(* mediacodec_eos_cb)(void *user_data)

Called when there is no data to decode/encode.

It will be invoked when the end-of-stream is reached.

Since :
2.3
Parameters:
[in]user_dataThe user data passed from the callback registration function
Precondition:
It will be invoked when the eos event generate if you register this callback using mediacodec_set_eos_cb().
See also:
mediacodec_set_eos_cb()
mediacodec_unset_eos_cb()
typedef void(* mediacodec_error_cb)(mediacodec_error_e error, void *user_data)

Called when the error has occurred.

It will be invoked when the error has occurred. Following error codes can be delivered. MEDIACODEC_ERROR_INTERNAL, MEDIACODEC_ERROR_INVALID_STREAM, MEDIACODEC_ERROR_NOT_SUPPORTED_FORMAT, MEDIACODEC_ERROR_RESOURCE_CONFLICT

Since :
2.3
Parameters:
[in]errorThe error code
[in]user_dataThe user data passed from the callback registration function
Precondition:
It will be invoked when the error has occurred if you register this callback using mediacodec_set_error_cb().
See also:
mediacodec_set_error_cb()
mediacodec_unset_error_cb()
typedef struct mediacodec_s* mediacodec_h

Media Codec type handle.

Since :
2.3
typedef void(* mediacodec_input_buffer_used_cb)(media_packet_h packet, void *user_data)

Called when the input buffer(packet) used up.

It will be invoked when mediacodec has used input buffer.

Since :
2.3
Remarks:
The packet should be released using media_packet_destroy().
Parameters:
[in]packetThe media packet handle
[in]user_dataThe user data passed from the callback registration function
Precondition:
It will be invoked when input buffer process completed if you register this callback using mediacodec_set_input_buffer_used_cb().
See also:
mediacodec_set_input_buffer_used_cb()
mediacodec_unset_input_buffer_used_cb()
typedef void(* mediacodec_output_buffer_available_cb)(media_packet_h packet, void *user_data)

Called when the output buffer is available.

It will be invoked when mediacodec has output buffer.

Since :
2.3
Remarks:
The packet should be released using media_packet_destroy().
Parameters:
[in]packetThe media packet handle
[in]user_dataThe user data passed from the callback registration function
Precondition:
It will be invoked when mediacodec process completed(had output buffer) if you register this callback using mediacodec_set_fill_buffer_cb().
See also:
mediacodec_set_output_buffer_available_cb()
mediacodec_unset_output_buffer_available_cb()
typedef bool(* mediacodec_supported_codec_cb)(mediacodec_codec_type_e codec_type, void *user_data)

Called once for each supported codec types.

Since :
2.4
Parameters:
[in]codec_typeThe codec type
[in]user_dataThe user data passed from the foreach function
Returns:
true to continue with the next iteration of the loop, false to break out of the loop.
Precondition:
mediacodec_foreach_supported_codec() will invoke this callback.
See also:
mediacodec_foreach_supported_codec()

Enumeration Type Documentation

Enumerations of media codec type.

Since :
2.3
Enumerator:
MEDIACODEC_NONE 

NONE

MEDIACODEC_L16 

L16

MEDIACODEC_ALAW 

ALAW

MEDIACODEC_ULAW 

ULAW

MEDIACODEC_AMR 

MEDIACDEC_AMR indicates AMR-NB (Since 2.4)

MEDIACODEC_AMR_NB 

AMR-NB (Since 2.4)

MEDIACODEC_AMR_WB 

AMR-WB (Since 2.4)

MEDIACODEC_G729 

G729

MEDIACODEC_AAC 

MEDIACDEC_AAC indicates AAC-LC (Since 2.4)

MEDIACODEC_AAC_LC 

AAC-LC (Since 2.4)

MEDIACODEC_AAC_HE 

HE-AAC (Since 2.4)

MEDIACODEC_AAC_HE_PS 

HE-AAC-PS (Since 2.4)

MEDIACODEC_MP3 

MP3

MEDIACODEC_VORBIS 

VORBIS (Since 2.4)

MEDIACODEC_FLAC 

FLAC (Since 2.4)

MEDIACODEC_WMAV1 

WMA version 1 (Since 2.4)

MEDIACODEC_WMAV2 

WMA version 2 (Since 2.4)

MEDIACODEC_WMAPRO 

WMA Professional (Since 2.4)

MEDIACODEC_WMALSL 

WMA Lossless (Since 2.4)

MEDIACODEC_OPUS 

OPUS (Since 6.0)

MEDIACODEC_H261 

H.261

MEDIACODEC_H263 

H.263

MEDIACODEC_H264 

H.264

MEDIACODEC_MJPEG 

MJPEG

MEDIACODEC_MPEG1 

MPEG1

MEDIACODEC_MPEG2 

MPEG2

MEDIACODEC_MPEG4 

MPEG4

MEDIACODEC_HEVC 

HEVC (Since 2.4)

MEDIACODEC_VP8 

VP8 (Since 2.4)

MEDIACODEC_VP9 

VP9 (Since 2.4)

MEDIACODEC_VC1 

VC1 (Since 2.4)

Enumeration of media codec error.

Since :
2.3
Enumerator:
MEDIACODEC_ERROR_NONE 

Successful

MEDIACODEC_ERROR_OUT_OF_MEMORY 

Out of memory

MEDIACODEC_ERROR_INVALID_PARAMETER 

Invalid parameter

MEDIACODEC_ERROR_INVALID_OPERATION 

Invalid operation

MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE 

Not supported

MEDIACODEC_ERROR_PERMISSION_DENIED 

Permission denied

MEDIACODEC_ERROR_INVALID_STATE 

Invalid state

MEDIACODEC_ERROR_INVALID_INBUFFER 

Invalid input buffer

MEDIACODEC_ERROR_INVALID_OUTBUFFER 

Invalid output buffer

MEDIACODEC_ERROR_INTERNAL 

Internal error

MEDIACODEC_ERROR_NOT_INITIALIZED 

Not initialized mediacodec

MEDIACODEC_ERROR_INVALID_STREAM 

Invalid stream

MEDIACODEC_ERROR_CODEC_NOT_FOUND 

Not supported format

MEDIACODEC_ERROR_DECODE 

Error while decoding data

MEDIACODEC_ERROR_NO_FREE_SPACE 

Out of storage

MEDIACODEC_ERROR_STREAM_NOT_FOUND 

Cannot find stream

MEDIACODEC_ERROR_NOT_SUPPORTED_FORMAT 

Not supported format

MEDIACODEC_ERROR_BUFFER_NOT_AVAILABLE 

Not available buffer

MEDIACODEC_ERROR_OVERFLOW_INBUFFER 

Overflow input buffer (Since 2.4)

MEDIACODEC_ERROR_RESOURCE_OVERLOADED 

Exceed the instance limits (Since 2.4)

MEDIACODEC_ERROR_RESOURCE_CONFLICT 

Interrupted by a resource conflict (Since 5.0)

Enumeration of buffer status.

Since :
2.4
Enumerator:
MEDIACODEC_NEED_DATA 

The internal queue is running out of data

MEDIACODEC_ENOUGH_DATA 

The internal queue is full

Enumeration of media codec support type.

Since :
2.3
Remarks:
If this codec is to be used as an encoder or decoder, the codec flag must be set to MEDIACODEC_ENCODER or MEDIACODEC_DECODER. If user doesn't set optional flag, default flags will be set to MEDIACODEC_SUPPORT_TYPE_SW.
Enumerator:
MEDIACODEC_ENCODER 

This flag is for using the encoder

MEDIACODEC_DECODER 

This flag is for using the decoder

MEDIACODEC_SUPPORT_TYPE_HW 

This is an optional flag for using the h/w codec

MEDIACODEC_SUPPORT_TYPE_SW 

This is an optional flag for using the s/w codec


Function Documentation

int mediacodec_configure_from_media_format ( mediacodec_h  mediacodec,
media_format_h  format,
int  flags 
)

Sets the codec type and codec default info via media format.

Sets the value via media format instead of mediacodec_set_codec(), mediacodec_set_venc_info(), mediacodec_set_vdec_info(), mediacodec_set_aenc_info(), and mediacodec_set_adec_info().

Since :
4.0
Remarks:
When using the format parameter from the output of the media demuxer, you can use media format via media_packet_get_format(). Otherwise, you must set the following values after creating media format. Set the audio or video codec type via media_format_set_video_mime() or media_format_set_audio_mime(). For video decoding, width, height must be set via media_format_set_video_width() and media_format_set_video_height(). For video encoding, width, height, target bitrate, and frame rate must be set via media_format_set_video_avg_bps() and media_format_set_video_frame_rate(). For audio decoding, samplerate, channel, and bit must be set via media_format_set_audio_samplerate(), media_format_set_audio_channel() and media_format_set_audio_bit(). For audio encoding, samplerate, channel, bit, and bitrate must be set via media_format_set_audio_avg_bps().
If this codec is to be used as a decoder, pass the MEDIACODEC_DECODER flag. If this codec is to be used as an encoder, pass the MEDIACODEC_ENCODER flag.
The software codec is used as default setting (MEDIACODEC_SUPPORT_TYPE_SW) if user doesn't set hardware flag. If you wants to use h/w decoder, you needs to pass the MEDIACODEC_DECODER | MEDIACODEC_SUPPORT_TYPE_HW.
Parameters:
[in]mediacodecThe mediacodec handle
[in]formatThe media_format_h of input data
[in]flagsThe encoding/decoding scheme, values of mediacodec_support_type_e combined with bitwise 'or'
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_CODEC_NOT_FOUNDUnsupported codec
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
Precondition:
The media format has been created and the required values for configuration have been set.
See also:
media_format_set_video_mime()
media_format_set_audio_mime()
media_format_set_video_width()
media_format_set_video_height()
media_format_set_video_avg_bps()
media_format_set_video_frame_rate()
media_format_set_audio_channel()
media_format_set_audio_samplerate()
media_format_set_audio_bit()
media_format_set_audio_avg_bps()
int mediacodec_create ( mediacodec_h mediacodec)

Creates a mediacodec handle for decoding/encoding.

Since :
2.3
Remarks:
you must release mediacodec using mediacodec_destroy().
Although you can create multiple mediacodec handles at the same time, the mediacodec cannot guarantee proper operation because of limited resources, like audio or display device.
Parameters:
[out]mediacodecA new handle to mediacodec
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_OUT_OF_MEMORYOut of memory
MEDIACODEC_ERROR_INVALID_OPERATIONInvalid operation
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
int mediacodec_destroy ( mediacodec_h  mediacodec)

Destroys the mediacodec handle and releases all its resources.

Since :
2.3
Remarks:
To completely shutdown the mediacodec operation, call this function with a valid player handle from any mediacodec
Parameters:
[in]mediacodecThe handle to mediacodec to be destroyed.
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_OUT_OF_MEMORYOut of memory
MEDIACODEC_ERROR_INVALID_OPERATIONInvalid operation
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)

Flushes both input and output buffers.

Since :
2.4
Parameters:
[in]mediacodecThe handle to mediacodec
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
int mediacodec_foreach_supported_codec ( mediacodec_h  mediacodec,
mediacodec_supported_codec_cb  callback,
void *  user_data 
)

Retrieves all supported codecs by invoking callback function once for each supported codecs.

Since :
2.4
Parameters:
[in]mediacodecThe handle to mediacodec
[in]callbackThe callback function to invoke
[in]user_dataThe user data to be passed to the callback function
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
See also:
mediacodec_supported_codec_cb()
int mediacodec_get_output ( mediacodec_h  mediacodec,
media_packet_h packet,
uint64_t  timeOutUs 
)

Gets the decoded or encoded packet from the output queue.

Since :
2.3
Remarks:
The packet should be released using media_packet_destroy().
Parameters:
[in]mediacodecThe handle to mediacodec
[out]packetThe current output of the decoder/encoder. this function passed decoded/encoded frame to output queue.
[in]timeOutUsThe timeout in microseconds.
The input buffer wait up to "timeOutUs" microseconds.
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_OUT_OF_MEMORYOut of memory
MEDIACODEC_ERROR_INVALID_OPERATIONInvalid operation
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)

Gets the media packet pool allocated for recycling media packets.

The user can get the pool allocated with the number of packets are required to be used in codecs.
It is recommended to use media packet pool for better stability and performance.

Since :
3.0
Remarks:
The pool should be released using media_packet_pool_deallocate() and destroyed using media_packet_pool_destroy().
Parameters:
[in]mediacodecThe mediacodec handle
[out]poolThe allocated pool handle
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_OUT_OF_MEMORYOut of memory
MEDIACODEC_ERROR_INVALID_OPERATIONThe user calls mediacodec_get_packet_pool() before calling mediacodec_prepare().
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
Precondition:
mediacodec_get_packet_pool() should be called after calling mediacodec_prepare().
Postcondition:
If the pool is used, media_packet_pool_deallocate() and media_packet_pool_destroy() should be called.
See also:
media_packet_pool_acquire_packet()
media_packet_pool_release_packet()
media_packet_pool_deallocate()
media_packet_pool_destroy()
int mediacodec_get_supported_type ( mediacodec_h  mediacodec,
mediacodec_codec_type_e  codec_type,
bool  encoder,
int *  support_type 
)

Verifies whether encoding can be performed with codec_type or not.

Since :
2.4
Parameters:
[in]mediacodecThe handle to mediacodec
[in]codec_typeThe identifier of the codec type of the encoder.
[in]encoderWhether the encoder or decoder : (true = encoder, false = decoder).
[out]support_type(MEDIACODEC_SUPPORT_TYPE_HW = mediacodec can be performed with hardware codec, MEDIACODEC_SUPPORT_TYPE_SW = mediacodec can be performed with software codec)
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
 #include <media_codec.h>
 mediacodec_h mediacodec;
 mediacodec_support_type_e type;
 mediacodec_codec_type_e codec_type = MEDIACODEC_H264;

 mediacodec_create(&mediacodec);
 mediacodec_get_supported_type(mediacodec, codec_type, 1, &type);

 if(type == MEDIACODEC_SUPPORT_TYPE_HW)
     // only h/w supported
 else if (type == MEDIACODEC_SUPPORT_TYPE_SW)
     // only s/w supported
 else if (type == (MEDIACODEC_SUPPORT_TYPE_HW|MEDIACODEC_SUPPORT_TYPE_SW)
     // both supported

 mediacodec_set_codec(mediacodec, codec_type, MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_HW);
int mediacodec_prepare ( mediacodec_h  mediacodec)

Prepares mediacodec for encoding/decoding.

Since :
2.3
Parameters:
[in]mediacodecThe handle to mediacodec
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_OUT_OF_MEMORYOut of memory
MEDIACODEC_ERROR_INVALID_OPERATIONInvalid operation
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
MEDIACODEC_ERROR_RESOURCE_OVERLOADEDExceed the instance limits (Since 5.0)
MEDIACODEC_ERROR_INTERNALInternal error (Since 5.0)
Precondition:
The mediacodec should call mediacodec_set_codec()and mediacodec_set_vdec_info()/mediacodec_set_venc_info() before calling mediacodec_prepare() If the decoder is set by mediacodec_set_codec(), mediacodec_set_vdec_info() should be called. If the encoder is set by mediacodec_set_codec(), mediacodec_set_venc_info() should be called.
int mediacodec_process_input ( mediacodec_h  mediacodec,
media_packet_h  inbuf,
uint64_t  timeOutUs 
)

Decodes/Encodes a packet. The function passed undecoded/unencoded packet to the input queue and decode/encode a frame sequentially.

Since :
2.3
Parameters:
[in]mediacodecThe handle to mediacodec
[in]inbufThe current input format for the decoder/encoder
[in]timeOutUsThe timeout in microseconds.
The input buffer wait up to "timeOutUs" microseconds.
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_OUT_OF_MEMORYOut of memory
MEDIACODEC_ERROR_INVALID_OPERATIONInvalid operation
MEDIACODEC_ERROR_OVERFLOW_INBUFFEROverflow inputbuffer
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
int mediacodec_set_adec_info ( mediacodec_h  mediacodec,
int  samplerate,
int  channel,
int  bit 
)

Sets the default info for the audio decoder.

Since :
2.3
Parameters:
[in]mediacodecThe handle to mediacodec
[in]samplerateThe samplerate for audio decoding.
[in]channelThe channels for audio decoding.
[in]bitThe bits resolution for audio decoding.
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_OUT_OF_MEMORYOut of memory
MEDIACODEC_ERROR_INVALID_OPERATIONInvalid operation
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
int mediacodec_set_aenc_info ( mediacodec_h  mediacodec,
int  samplerate,
int  channel,
int  bit,
int  bitrate 
)

Sets the default info for the audio encoder.

Since :
2.3
Parameters:
[in]mediacodecThe handle to mediacodec
[in]samplerateThe samplerate for audio encoding.
[in]channelThe channels for audio encoding.
[in]bitThe bits resolution for audio encoding.
[in]bitrateThe bitrate for audio encoding.
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_OUT_OF_MEMORYOut of memory
MEDIACODEC_ERROR_INVALID_OPERATIONInvalid operation
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
int mediacodec_set_buffer_status_cb ( mediacodec_h  mediacodec,
mediacodec_buffer_status_cb  callback,
void *  user_data 
)

Sets a callback function to be invoked when the mediacodec needs more data or has enough data.

Since :
2.4
Parameters:
[in]mediacodecThe handle to mediacodec
[in]callbackThe callback function to register
[in]user_dataThe user data to be passed to the callback function
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
Precondition:
mediacodec_set_buffer_status_cb() should be called before mediacodec_preare().
Postcondition:
mediacodec_buffer_status_cb() will be invoked.
See also:
mediacodec_buffer_status_cb()
mediacodec_unset_buffer_status_cb()
int mediacodec_set_codec ( mediacodec_h  mediacodec,
mediacodec_codec_type_e  codec_type,
int  flags 
)

Sets the codec type and decoder/encoder.

Since :
2.3
Remarks:
If this codec is to be used as a decoder, pass the MEDIACODEC_DECODER flag. If this codec is to be used as an encoder, pass the MEDIACODEC_ENCODER flag.
The software codec is used as default setting(MEDIACODEC_SUPPORT_TYPE_SW) if user doesn't set hardware flag. If user wants to use h/w decoder, user needs to pass the MEDIACODEC_DECODER | MEDIACODEC_SUPPORT_TYPE_HW.
Parameters:
[in]mediacodecThe handle of mediacodec
[in]codec_typeThe identifier of the codec type of the decoder/encoder
[in]flagsThe encoding/decoding scheme, defined by mediacodec_support_type_e
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_OUT_OF_MEMORYOut of memory
MEDIACODEC_ERROR_INVALID_OPERATIONInvalid operation
MEDIACODEC_ERROR_CODEC_NOT_FOUNDCodec not found
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
int mediacodec_set_eos_cb ( mediacodec_h  mediacodec,
mediacodec_eos_cb  callback,
void *  user_data 
)

Sets eos callback the media codec for process, asynchronously.

Since :
2.3
Parameters:
[in]mediacodecThe handle to mediacodec
[in]callbackThe callback function to register
[in]user_dataThe user data to be passed to the callback function
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
Precondition:
mediacodec_set_eos_cb() should be called before mediacodec_preare().
Postcondition:
mediacodec_eos_cb() will be invoked.
See also:
mediacodec_eos_cb()
mediacodec_unset_eos_cb()
int mediacodec_set_error_cb ( mediacodec_h  mediacodec,
mediacodec_error_cb  callback,
void *  user_data 
)

Sets error callback the media codec for process, asynchronously.

Since :
2.3
Parameters:
[in]mediacodecThe handle to mediacodec
[in]callbackThe callback function to register
[in]user_dataThe user data to be passed to the callback function
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
Precondition:
mediacodec_set_error_cb() should be called before mediacodec_preare().
Postcondition:
mediacodec_error_cb() will be invoked.
See also:
mediacodec_error_cb()
mediacodec_unset_error_cb()
int mediacodec_set_input_buffer_used_cb ( mediacodec_h  mediacodec,
mediacodec_input_buffer_used_cb  callback,
void *  user_data 
)

Sets empty buffer callback the media codec for process, asynchronously.

Since :
2.3
Parameters:
[in]mediacodecThe handle to mediacodec
[in]callbackThe callback function to register
[in]user_dataThe user data to be passed to the callback function
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
Precondition:
mediacodec_set_input_buffer_used_cb() should be called before mediacodec_preare().
Postcondition:
mediacodec_input_buffer_used_cb() will be invoked.
See also:
mediacodec_input_buffer_used_cb()
mediacodec_unset_input_buffer_used_cb()

Sets output buffer available callback the media codec for process, asynchronously.

Since :
2.3
Parameters:
[in]mediacodecThe handle to mediacodec
[in]callbackThe callback function to register
[in]user_dataThe user data to be passed to the callback function
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
Precondition:
mediacodec_set_output_buffer_available_cb() should be called before mediacodec_preare().
Postcondition:
mediacodec_output_buffer_available_cb() will be invoked.
See also:
mediacodec_output_buffer_available_cb()
mediacodec_unset_output_buffer_available_cb()
int mediacodec_set_vdec_info ( mediacodec_h  mediacodec,
int  width,
int  height 
)

Sets the default info for the video decoder.

Since :
2.3
Parameters:
[in]mediacodecThe handle to mediacodec
[in]widthThe width for video decoding.
[in]heightThe height for video decoding.
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_OUT_OF_MEMORYOut of memory
MEDIACODEC_ERROR_INVALID_OPERATIONInvalid operation
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
int mediacodec_set_venc_info ( mediacodec_h  mediacodec,
int  width,
int  height,
int  fps,
int  target_bits 
)

Sets the default info for the video encoder.

Since :
2.3
Remarks:
The frame rate is the speed of recording and the speed of playback. If user wants the default setting for ratecontrol, set target_bits to 0.
Parameters:
[in]mediacodecThe handle to mediacodec
[in]widthThe width for video encoding.
[in]heightThe height for video encoding.
[in]fpsThe frame rate in frames per second.
[in]target_bitsThe target bitrates in bits per second.(a unit of kbit)
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_OUT_OF_MEMORYOut of memory
MEDIACODEC_ERROR_INVALID_OPERATIONInvalid operation
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
int mediacodec_unprepare ( mediacodec_h  mediacodec)

Unprepares mediacodec for encoding/decoding.

Since :
2.3
Parameters:
[in]mediacodecThe handle to mediacodec
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_OUT_OF_MEMORYOut of memory
MEDIACODEC_ERROR_INVALID_OPERATIONInvalid operation
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)

Unsets the callback function.

Since :
2.4
Parameters:
[in]mediacodecThe handle to mediacodec
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
See also:
mediacodec_set_buffer_status_cb()

unsets eos callback the media codec for process, asynchronously.

Since :
2.3
Parameters:
[in]mediacodecThe handle to mediacodec
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
See also:
mediacodec_set_eos_cb()

Unsets error callback the media codec for process, asynchronously.

Since :
2.3
Parameters:
[in]mediacodecThe handle to mediacodec
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
See also:
mediacodec_set_error_cb()

Unsets input buffer used callback the media codec for process, asynchronously.

Since :
2.3
Parameters:
[in]mediacodecThe handle to mediacodec
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
See also:
mediacodec_set_input_buffer_used_cb()

unsets output buffer available callback the media codec for process, asynchronously.

Since :
2.3
Parameters:
[in]mediacodecThe handle to mediacodec
Returns:
0 on success, otherwise a negative error value
Return values:
MEDIACODEC_ERROR_NONESuccessful
MEDIACODEC_ERROR_INVALID_PARAMETERInvalid parameter
MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICENot supported on device (Since 4.0)
See also:
mediacodec_set_output_buffer_available_cb()