2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #ifndef __TIZEN_MEDIA_CODEC_H__
18 #define __TIZEN_MEDIA_CODEC_H__
22 #include <media_packet.h>
23 #include <media_packet_pool.h>
31 * @brief This file contains the capi media codec API.
35 * @addtogroup CAPI_MEDIA_CODEC_MODULE
40 * @brief Media Codec type handle.
41 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
43 typedef struct mediacodec_s *mediacodec_h;
46 * @brief Enumeration of media codec support type.
47 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
48 * @remarks If this codec is to be used as an encoder or decoder, the codec flag must be set to #MEDIACODEC_ENCODER or
49 * #MEDIACODEC_DECODER. If user doesn't set optional flag, default flags will be set to #MEDIACODEC_SUPPORT_TYPE_SW.
52 MEDIACODEC_ENCODER = 0x1, /**< This flag is for using the encoder */
53 MEDIACODEC_DECODER = 0x2, /**< This flag is for using the decoder */
54 MEDIACODEC_SUPPORT_TYPE_HW = 0x4, /**< This is an optional flag for using the h/w codec */
55 MEDIACODEC_SUPPORT_TYPE_SW = 0x8, /**< This is an optional flag for using the s/w codec */
56 } mediacodec_support_type_e;
59 * @brief Enumerations of media codec type.
60 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
63 MEDIACODEC_NONE = 0x0, /**< NONE*/
64 MEDIACODEC_L16 = 0x1010, /**< L16*/
65 MEDIACODEC_ALAW = 0x1020, /**< ALAW*/
66 MEDIACODEC_ULAW = 0x1030, /**< ULAW*/
67 MEDIACODEC_AMR = 0x1040, /**< MEDIACDEC_AMR indicates AMR-NB (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
68 MEDIACODEC_AMR_NB = 0x1040, /**< AMR-NB (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
69 MEDIACODEC_AMR_WB = 0x1041, /**< AMR-WB (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
70 MEDIACODEC_G729 = 0x1050, /**< G729*/
71 MEDIACODEC_AAC = 0x1060, /**< MEDIACDEC_AAC indicates AAC-LC (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
72 MEDIACODEC_AAC_LC = 0x1060, /**< AAC-LC (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
73 MEDIACODEC_AAC_HE = 0x1061, /**< HE-AAC (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
74 MEDIACODEC_AAC_HE_PS = 0x1062, /**< HE-AAC-PS (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
75 MEDIACODEC_MP3 = 0x1070, /**< MP3*/
76 MEDIACODEC_VORBIS = 0x1080, /**< VORBIS (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
77 MEDIACODEC_FLAC = 0x1090, /**< FLAC (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
78 MEDIACODEC_WMAV1 = 0x10A0, /**< WMA version 1 (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
79 MEDIACODEC_WMAV2 = 0x10A1, /**< WMA version 2 (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
80 MEDIACODEC_WMAPRO = 0x10A2, /**< WMA Professional (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
81 MEDIACODEC_WMALSL = 0x10A3, /**< WMA Lossless (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
83 MEDIACODEC_H261 = 0x2010, /**< H.261*/
84 MEDIACODEC_H263 = 0x2020, /**< H.263*/
85 MEDIACODEC_H264 = 0x2030, /**< H.264*/
86 MEDIACODEC_MJPEG = 0x2040, /**< MJPEG*/
87 MEDIACODEC_MPEG1 = 0x2050, /**< MPEG1*/
88 MEDIACODEC_MPEG2 = 0x2060, /**< MPEG2*/
89 MEDIACODEC_MPEG4 = 0x2070, /**< MPEG4*/
90 MEDIACODEC_HEVC = 0x2080, /**< HEVC (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
91 MEDIACODEC_VP8 = 0x2090, /**< VP8 (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
92 MEDIACODEC_VP9 = 0x20A0, /**< VP9 (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
93 MEDIACODEC_VC1 = 0x20B0, /**< VC1 (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
94 } mediacodec_codec_type_e;
97 * @brief Enumeration of media codec error.
98 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
101 MEDIACODEC_ERROR_NONE = TIZEN_ERROR_NONE, /**< Successful */
102 MEDIACODEC_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */
103 MEDIACODEC_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */
104 MEDIACODEC_ERROR_INVALID_OPERATION = TIZEN_ERROR_INVALID_OPERATION, /**< Invalid operation */
105 MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE = TIZEN_ERROR_NOT_SUPPORTED, /**< Not supported */
106 MEDIACODEC_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Permission denied */
107 MEDIACODEC_ERROR_INVALID_STATE = TIZEN_ERROR_MEDIACODEC | 0x01, /**< Invalid state */
108 MEDIACODEC_ERROR_INVALID_INBUFFER = TIZEN_ERROR_MEDIACODEC | 0x02, /**< Invalid input buffer */
109 MEDIACODEC_ERROR_INVALID_OUTBUFFER = TIZEN_ERROR_MEDIACODEC | 0x03, /**< Invalid output buffer */
110 MEDIACODEC_ERROR_INTERNAL = TIZEN_ERROR_MEDIACODEC | 0x04, /**< Internal error */
111 MEDIACODEC_ERROR_NOT_INITIALIZED = TIZEN_ERROR_MEDIACODEC | 0x05, /**< Not initialized mediacodec */
112 MEDIACODEC_ERROR_INVALID_STREAM = TIZEN_ERROR_MEDIACODEC | 0x06, /**< Invalid stream */
113 MEDIACODEC_ERROR_CODEC_NOT_FOUND = TIZEN_ERROR_MEDIACODEC | 0x07, /**< Not supported format */
114 MEDIACODEC_ERROR_DECODE = TIZEN_ERROR_MEDIACODEC | 0x08, /**< Error while decoding data */
115 MEDIACODEC_ERROR_NO_FREE_SPACE = TIZEN_ERROR_MEDIACODEC | 0x09, /**< Out of storage */
116 MEDIACODEC_ERROR_STREAM_NOT_FOUND = TIZEN_ERROR_MEDIACODEC | 0x0a, /**< Cannot find stream */
117 MEDIACODEC_ERROR_NOT_SUPPORTED_FORMAT = TIZEN_ERROR_MEDIACODEC | 0x0b, /**< Not supported format */
118 MEDIACODEC_ERROR_BUFFER_NOT_AVAILABLE = TIZEN_ERROR_MEDIACODEC | 0x0c, /**< Not available buffer */
119 MEDIACODEC_ERROR_OVERFLOW_INBUFFER = TIZEN_ERROR_MEDIACODEC | 0x0d, /**< Overflow input buffer (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
120 MEDIACODEC_ERROR_RESOURCE_OVERLOADED = TIZEN_ERROR_MEDIACODEC | 0x0e, /**< Exceed the instance limits (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
121 MEDIACODEC_ERROR_RESOURCE_CONFLICT = TIZEN_ERROR_MEDIACODEC | 0x0f, /**< Interrupted by a resource conflict (Since 5.0)*/
122 } mediacodec_error_e;
125 * @brief Enumeration of buffer status.
126 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
129 MEDIACODEC_NEED_DATA, /**< The internal queue is running out of data */
130 MEDIACODEC_ENOUGH_DATA /**< The internal queue is full */
131 } mediacodec_status_e;
134 * @brief Called when the input buffer(packet) used up.
135 * @details It will be invoked when mediacodec has used input buffer.
136 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
137 * @remarks The @a packet should be released using media_packet_destroy().
138 * @param[in] packet The media packet handle
139 * @param[in] user_data The user data passed from the callback registration function
140 * @pre It will be invoked when input buffer process completed if you register this callback using mediacodec_set_input_buffer_used_cb().
141 * @see mediacodec_set_input_buffer_used_cb()
142 * @see mediacodec_unset_input_buffer_used_cb()
144 typedef void (*mediacodec_input_buffer_used_cb)(media_packet_h packet, void *user_data);
147 * @brief Called when the output buffer is available.
148 * @details It will be invoked when mediacodec has output buffer.
149 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
150 * @remarks The @a packet should be released using media_packet_destroy().
151 * @param[in] packet The media packet handle
152 * @param[in] user_data The user data passed from the callback registration function
153 * @pre It will be invoked when mediacodec process completed(had output buffer) if you register this callback using mediacodec_set_fill_buffer_cb().
154 * @see mediacodec_set_output_buffer_available_cb()
155 * @see mediacodec_unset_output_buffer_available_cb()
157 typedef void (*mediacodec_output_buffer_available_cb)(media_packet_h packet, void *user_data);
160 * @brief Called when the error has occurred.
161 * @details It will be invoked when the error has occurred.
162 * Following error codes can be delivered.
163 * #MEDIACODEC_ERROR_INTERNAL,
164 * #MEDIACODEC_ERROR_INVALID_STREAM,
165 * #MEDIACODEC_ERROR_NOT_SUPPORTED_FORMAT,
166 * #MEDIACODEC_ERROR_RESOURCE_CONFLICT
167 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
168 * @param[in] error The error code
169 * @param[in] user_data The user data passed from the callback registration function
170 * @pre It will be invoked when the error has occurred if you register this callback using mediacodec_set_error_cb().
171 * @see mediacodec_set_error_cb()
172 * @see mediacodec_unset_error_cb()
174 typedef void (*mediacodec_error_cb)(mediacodec_error_e error, void *user_data);
177 * @brief Called when there is no data to decode/encode.
178 * @details It will be invoked when the end-of-stream is reached.
179 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
180 * @param[in] user_data The user data passed from the callback registration function
181 * @pre It will be invoked when the eos event generate if you register this callback using mediacodec_set_eos_cb().
182 * @see mediacodec_set_eos_cb()
183 * @see mediacodec_unset_eos_cb()
185 typedef void (*mediacodec_eos_cb)(void *user_data);
188 * @brief Called when the mediacodec needs more data or has enough data.
189 * @details It is recommended that the application stops calling mediacodec_process_input() when #MEDIACODEC_ENOUGH_DATA
190 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
192 * @param[in] status The state of the buffer
193 * @param[in] user_data The user data passed from the callback registration function
194 * @see mediacodec_set_buffer_status_cb()
195 * @see mediacodec_unset_buffer_status_cb()
197 typedef void (*mediacodec_buffer_status_cb)(mediacodec_status_e status, void *user_data);
200 * @brief Called once for each supported codec types.
201 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
202 * @param[in] codec_type The codec type
203 * @param[in] user_data The user data passed from the foreach function
204 * @return @c true to continue with the next iteration of the loop, @c false to break out of the loop.
205 * @pre mediacodec_foreach_supported_codec() will invoke this callback.
206 * @see mediacodec_foreach_supported_codec()
208 typedef bool (*mediacodec_supported_codec_cb)(mediacodec_codec_type_e codec_type, void *user_data);
211 * @brief Creates a mediacodec handle for decoding/encoding.
212 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
213 * @remarks you must release @a mediacodec using mediacodec_destroy().\n
214 * Although you can create multiple mediacodec handles at the same time,
215 * the mediacodec cannot guarantee proper operation because of limited resources, like
216 * audio or display device.
218 * @param[out] mediacodec A new handle to mediacodec
219 * @return @c 0 on success, otherwise a negative error value
220 * @retval #MEDIACODEC_ERROR_NONE Successful
221 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
222 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
223 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
224 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
226 int mediacodec_create(mediacodec_h *mediacodec);
229 * @brief Destroys the mediacodec handle and releases all its resources.
230 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
231 * @remarks To completely shutdown the mediacodec operation, call this function with a valid player handle from any
234 * @param[in] mediacodec The handle to mediacodec to be destroyed.
235 * @return @c 0 on success, otherwise a negative error value
236 * @retval #MEDIACODEC_ERROR_NONE Successful
237 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
238 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
239 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
240 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
242 int mediacodec_destroy(mediacodec_h mediacodec);
245 * @brief Sets the codec type and decoder/encoder.
246 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
247 * @remarks If this codec is to be used as a decoder, pass the #MEDIACODEC_DECODER flag.
248 * If this codec is to be used as an encoder, pass the #MEDIACODEC_ENCODER flag.\n
249 * The software codec is used as default setting(#MEDIACODEC_SUPPORT_TYPE_SW) if user doesn't set hardware flag.
250 * If user wants to use h/w decoder, user needs to pass the #MEDIACODEC_DECODER | #MEDIACODEC_SUPPORT_TYPE_HW.
251 * @param[in] mediacodec The handle of mediacodec
252 * @param[in] codec_type The identifier of the codec type of the decoder/encoder
253 * @param[in] flags The encoding/decoding scheme, defined by #mediacodec_support_type_e
254 * @return @c 0 on success, otherwise a negative error value
255 * @retval #MEDIACODEC_ERROR_NONE Successful
256 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
257 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
258 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
259 * @retval #MEDIACODEC_ERROR_CODEC_NOT_FOUND Codec not found
260 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
262 int mediacodec_set_codec(mediacodec_h mediacodec, mediacodec_codec_type_e codec_type, int flags);
265 * @brief Sets the default info for the video decoder.
266 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
267 * @param[in] mediacodec The handle to mediacodec
268 * @param[in] width The width for video decoding.
269 * @param[in] height The height for video decoding.
270 * @return @c 0 on success, otherwise a negative error value
271 * @retval #MEDIACODEC_ERROR_NONE Successful
272 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
273 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
274 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
275 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
277 int mediacodec_set_vdec_info(mediacodec_h mediacodec, int width, int height);
280 * @brief Sets the default info for the video encoder.
281 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
282 * @remarks The frame rate is the speed of recording and the speed of playback.
283 * If user wants the default setting for ratecontrol, set @a target_bits to @c 0.
284 * @param[in] mediacodec The handle to mediacodec
285 * @param[in] width The width for video encoding.
286 * @param[in] height The height for video encoding.
287 * @param[in] fps The frame rate in frames per second.
288 * @param[in] target_bits The target bitrates in bits per second.(a unit of kbit)
289 * @return @c 0 on success, otherwise a negative error value
290 * @retval #MEDIACODEC_ERROR_NONE Successful
291 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
292 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
293 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
294 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
296 int mediacodec_set_venc_info(mediacodec_h mediacodec, int width, int height, int fps, int target_bits);
299 * @brief Sets the default info for the audio decoder.
300 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
301 * @param[in] mediacodec The handle to mediacodec
302 * @param[in] samplerate The samplerate for audio decoding.
303 * @param[in] channel The channels for audio decoding.
304 * @param[in] bit The bits resolution for audio decoding.
305 * @return @c 0 on success, otherwise a negative error value
306 * @retval #MEDIACODEC_ERROR_NONE Successful
307 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
308 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
309 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
310 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
312 int mediacodec_set_adec_info(mediacodec_h mediacodec, int samplerate, int channel, int bit);
315 * @brief Sets the default info for the audio encoder.
316 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
317 * @param[in] mediacodec The handle to mediacodec
318 * @param[in] samplerate The samplerate for audio encoding.
319 * @param[in] channel The channels for audio encoding.
320 * @param[in] bit The bits resolution for audio encoding.
321 * @param[in] bitrate The bitrate for audio encoding.
322 * @return @c 0 on success, otherwise a negative error value
323 * @retval #MEDIACODEC_ERROR_NONE Successful
324 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
325 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
326 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
327 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
329 int mediacodec_set_aenc_info(mediacodec_h mediacodec, int samplerate, int channel, int bit, int bitrate);
332 * @brief Sets the codec type and codec default info via media format.
333 * @details Sets the value via media format instead of mediacodec_set_codec(), mediacodec_set_venc_info(),
334 * mediacodec_set_vdec_info(), mediacodec_set_aenc_info(), and mediacodec_set_adec_info().
336 * @remarks When using the @a format parameter from the output of the media demuxer, you can use media format via media_packet_get_format().
337 * Otherwise, you must set the following values after creating media format.
338 * Set the audio or video codec type via media_format_set_video_mime() or media_format_set_audio_mime().
339 * For video decoding, width, height must be set via media_format_set_video_width() and media_format_set_video_height().
340 * 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().
341 * 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().
342 * For audio encoding, samplerate, channel, bit, and bitrate must be set via media_format_set_audio_avg_bps().\n
343 * If this codec is to be used as a decoder, pass the #MEDIACODEC_DECODER flag.
344 * If this codec is to be used as an encoder, pass the #MEDIACODEC_ENCODER flag.\n
345 * The software codec is used as default setting (#MEDIACODEC_SUPPORT_TYPE_SW) if user doesn't set hardware flag.
346 * If you wants to use h/w decoder, you needs to pass the #MEDIACODEC_DECODER | #MEDIACODEC_SUPPORT_TYPE_HW.
347 * @param[in] mediacodec The mediacodec handle
348 * @param[in] format The #media_format_h of input data
349 * @param[in] flags The encoding/decoding scheme,
350 * values of #mediacodec_support_type_e combined with bitwise 'or'
351 * @return @c 0 on success, otherwise a negative error value
352 * @retval #MEDIACODEC_ERROR_NONE Successful
353 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
354 * @retval #MEDIACODEC_ERROR_CODEC_NOT_FOUND Unsupported codec
355 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
356 * @pre The media format has been created and the required values for configuration have been set.
357 * @see media_format_set_video_mime()
358 * @see media_format_set_audio_mime()
359 * @see media_format_set_video_width()
360 * @see media_format_set_video_height()
361 * @see media_format_set_video_avg_bps()
362 * @see media_format_set_video_frame_rate()
363 * @see media_format_set_audio_channel()
364 * @see media_format_set_audio_samplerate()
365 * @see media_format_set_audio_bit()
366 * @see media_format_set_audio_avg_bps()
368 int mediacodec_configure_from_media_format(mediacodec_h mediacodec, media_format_h format, int flags);
371 * @brief Prepares @a mediacodec for encoding/decoding.
372 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
373 * @param[in] mediacodec The handle to mediacodec
374 * @return @c 0 on success, otherwise a negative error value
375 * @retval #MEDIACODEC_ERROR_NONE Successful
376 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
377 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
378 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
379 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
380 * @retval #MEDIACODEC_ERROR_RESOURCE_OVERLOADED Exceed the instance limits (Since 5.0)
381 * @retval #MEDIACODEC_ERROR_INTERNAL Internal error (Since 5.0)
382 * @pre The mediacodec should call mediacodec_set_codec()and mediacodec_set_vdec_info()/mediacodec_set_venc_info() before calling mediacodec_prepare()
383 * If the decoder is set by mediacodec_set_codec(), mediacodec_set_vdec_info() should be called. If the encoder is set by
384 * mediacodec_set_codec(), mediacodec_set_venc_info() should be called.
386 int mediacodec_prepare(mediacodec_h mediacodec);
389 * @brief Unprepares @a mediacodec for encoding/decoding.
390 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
391 * @param[in] mediacodec The handle to mediacodec
392 * @return @c 0 on success, otherwise a negative error value
393 * @retval #MEDIACODEC_ERROR_NONE Successful
394 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
395 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
396 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
397 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
399 int mediacodec_unprepare(mediacodec_h mediacodec);
402 * @brief Decodes/Encodes a packet. The function passed undecoded/unencoded packet to the input queue and decode/encode a
403 * frame sequentially.
404 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
405 * @param[in] mediacodec The handle to mediacodec
406 * @param[in] inbuf The current input format for the decoder/encoder
407 * @param[in] timeOutUs The timeout in microseconds. \n
408 * The input buffer wait up to "timeOutUs" microseconds.
409 * @return @c 0 on success, otherwise a negative error value
410 * @retval #MEDIACODEC_ERROR_NONE Successful
411 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
412 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
413 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
414 * @retval #MEDIACODEC_ERROR_OVERFLOW_INBUFFER Overflow inputbuffer
415 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
417 int mediacodec_process_input(mediacodec_h mediacodec, media_packet_h inbuf, uint64_t timeOutUs);
420 * @brief Gets the decoded or encoded packet from the output queue.
421 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
422 * @remarks The @a packet should be released using media_packet_destroy().
423 * @param[in] mediacodec The handle to mediacodec
424 * @param[out] packet The current output of the decoder/encoder.
425 * this function passed decoded/encoded frame to output queue.
426 * @param[in] timeOutUs The timeout in microseconds. \n
427 * The input buffer wait up to "timeOutUs" microseconds.
428 * @return @c 0 on success, otherwise a negative error value
429 * @retval #MEDIACODEC_ERROR_NONE Successful
430 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
431 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
432 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
433 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
435 int mediacodec_get_output(mediacodec_h mediacodec, media_packet_h *packet, uint64_t timeOutUs);
438 * @brief Flushes both input and output buffers.
439 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
440 * @param[in] mediacodec The handle to mediacodec
441 * @return @c 0 on success, otherwise a negative error value
442 * @retval #MEDIACODEC_ERROR_NONE Successful
443 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
444 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
446 int mediacodec_flush_buffers(mediacodec_h mediacodec);
449 * @brief Sets empty buffer callback the media codec for process, asynchronously.
450 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
451 * @param[in] mediacodec The handle to mediacodec
452 * @param[in] callback The callback function to register
453 * @param[in] user_data The user data to be passed to the callback function
454 * @return @c 0 on success, otherwise a negative error value
455 * @retval #MEDIACODEC_ERROR_NONE Successful
456 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
457 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
458 * @pre mediacodec_set_input_buffer_used_cb() should be called before mediacodec_preare().
459 * @post mediacodec_input_buffer_used_cb() will be invoked.
460 * @see mediacodec_set_input_buffer_used_cb()
461 * @see mediacodec_unset_input_buffer_used_cb()
463 int mediacodec_set_input_buffer_used_cb(mediacodec_h mediacodec, mediacodec_input_buffer_used_cb callback, void* user_data);
466 * @brief Unsets input buffer used callback the media codec for process, asynchronously.
467 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
468 * @param[in] mediacodec The handle to mediacodec
469 * @return @c 0 on success, otherwise a negative error value
470 * @retval #MEDIACODEC_ERROR_NONE Successful
471 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
472 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
473 * @see mediacodec_set_input_buffer_used_cb()
475 int mediacodec_unset_input_buffer_used_cb(mediacodec_h mediacodec);
478 * @brief Sets output buffer available callback the media codec for process, asynchronously.
479 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
480 * @param[in] mediacodec The handle to mediacodec
481 * @param[in] callback The callback function to register
482 * @param[in] user_data The user data to be passed to the callback function
483 * @return @c 0 on success, otherwise a negative error value
484 * @retval #MEDIACODEC_ERROR_NONE Successful
485 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
486 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
487 * @pre mediacodec_set_output_buffer_available_cb() should be called before mediacodec_preare().
488 * @post mediacodec_output_buffer_available_cb() will be invoked.
489 * @see mediacodec_set_output_buffer_available_cb()
490 * @see mediacodec_unset_output_buffer_available_cb()
492 int mediacodec_set_output_buffer_available_cb(mediacodec_h mediacodec, mediacodec_output_buffer_available_cb callback, void* user_data);
495 * @brief unsets output buffer available callback the media codec for process, asynchronously.
496 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
497 * @param[in] mediacodec The handle to mediacodec
498 * @return @c 0 on success, otherwise a negative error value
499 * @retval #MEDIACODEC_ERROR_NONE Successful
500 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
501 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
502 * @see mediacodec_set_output_buffer_available_cb()
504 int mediacodec_unset_output_buffer_available_cb(mediacodec_h mediacodec);
507 * @brief Sets error callback the media codec for process, asynchronously.
508 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
509 * @param[in] mediacodec The handle to mediacodec
510 * @param[in] callback The callback function to register
511 * @param[in] user_data The user data to be passed to the callback function
512 * @return @c 0 on success, otherwise a negative error value
513 * @retval #MEDIACODEC_ERROR_NONE Successful
514 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
515 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
516 * @pre mediacodec_set_error_cb() should be called before mediacodec_preare().
517 * @post mediacodec_error_cb() will be invoked.
518 * @see mediacodec_set_error_cb()
519 * @see mediacodec_unset_error_cb()
521 int mediacodec_set_error_cb(mediacodec_h mediacodec, mediacodec_error_cb callback, void* user_data);
524 * @brief Unsets error callback the media codec for process, asynchronously.
525 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
526 * @param[in] mediacodec The handle to mediacodec
527 * @return @c 0 on success, otherwise a negative error value
528 * @retval #MEDIACODEC_ERROR_NONE Successful
529 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
530 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
531 * @see mediacodec_set_error_cb()
533 int mediacodec_unset_error_cb(mediacodec_h mediacodec);
536 * @brief Sets eos callback the media codec for process, asynchronously.
537 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
538 * @param[in] mediacodec The handle to mediacodec
539 * @param[in] callback The callback function to register
540 * @param[in] user_data The user data to be passed to the callback function
541 * @return @c 0 on success, otherwise a negative error value
542 * @retval #MEDIACODEC_ERROR_NONE Successful
543 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
544 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
545 * @pre mediacodec_set_eos_cb() should be called before mediacodec_preare().
546 * @post mediacodec_eos_cb() will be invoked.
547 * @see mediacodec_set_eos_cb()
548 * @see mediacodec_unset_eos_cb()
550 int mediacodec_set_eos_cb(mediacodec_h mediacodec, mediacodec_eos_cb callback, void* user_data);
553 * @brief unsets eos callback the media codec for process, asynchronously.
554 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
555 * @param[in] mediacodec The handle to mediacodec
556 * @return @c 0 on success, otherwise a negative error value
557 * @retval #MEDIACODEC_ERROR_NONE Successful
558 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
559 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
560 * @see mediacodec_set_event_handler_cb()
562 int mediacodec_unset_eos_cb(mediacodec_h mediacodec);
565 * @brief Sets a callback function to be invoked when the mediacodec needs more data or has enough data.
566 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
567 * @param[in] mediacodec The handle to mediacodec
568 * @param[in] callback The callback function to register
569 * @param[in] user_data The user data to be passed to the callback function
570 * @return @c 0 on success, otherwise a negative error value
571 * @retval #MEDIACODEC_ERROR_NONE Successful
572 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
573 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
574 * @pre mediacodec_set_buffer_status_cb() should be called before mediacodec_preare().
575 * @post mediacodec_buffer_status_cb() will be invoked.
576 * @see mediacodec_set_buffer_status_cb()
577 * @see mediacodec_unset_buffer_status_cb()
579 int mediacodec_set_buffer_status_cb(mediacodec_h mediacodec, mediacodec_buffer_status_cb callback, void* user_data);
582 * @brief Unsets the callback function.
583 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
584 * @param[in] mediacodec The handle to mediacodec
585 * @return @c 0 on success, otherwise a negative error value
586 * @retval #MEDIACODEC_ERROR_NONE Successful
587 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
588 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
590 int mediacodec_unset_buffer_status_cb(mediacodec_h mediacodec);
593 * @brief Retrieves all supported codecs by invoking callback function once for each supported codecs.
594 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
595 * @param[in] mediacodec The handle to mediacodec
596 * @param[in] callback The callback function to invoke
597 * @param[in] user_data The user data to be passed to the callback function
598 * @return @c 0 on success, otherwise a negative error value
599 * @retval #MEDIACODEC_ERROR_NONE Successful
600 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
601 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
602 * @see mediacodec_foreach_supported_codec()
604 int mediacodec_foreach_supported_codec(mediacodec_h mediacodec, mediacodec_supported_codec_cb callback, void *user_data);
607 * @brief Verifies whether encoding can be performed with codec_type or not.
608 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
609 * @param[in] mediacodec The handle to mediacodec
610 * @param[in] codec_type The identifier of the codec type of the encoder.
611 * @param[in] encoder Whether the encoder or decoder : (@c true = encoder, @c false = decoder).
612 * @param[out] support_type (@c #MEDIACODEC_SUPPORT_TYPE_HW = mediacodec can be performed with hardware codec, @c #MEDIACODEC_SUPPORT_TYPE_SW = mediacodec can be performed with software codec)
613 * @return @c 0 on success, otherwise a negative error value
614 * @retval #MEDIACODEC_ERROR_NONE Successful
615 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
616 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
618 #include <media_codec.h>
619 mediacodec_h mediacodec;
620 mediacodec_support_type_e type;
621 mediacodec_codec_type_e codec_type = MEDIACODEC_H264;
623 mediacodec_create(&mediacodec);
624 mediacodec_get_supported_type(mediacodec, codec_type, 1, &type);
626 if(type == MEDIACODEC_SUPPORT_TYPE_HW)
627 // only h/w supported
628 else if (type == MEDIACODEC_SUPPORT_TYPE_SW)
629 // only s/w supported
630 else if (type == (MEDIACODEC_SUPPORT_TYPE_HW|MEDIACODEC_SUPPORT_TYPE_SW)
633 mediacodec_set_codec(mediacodec, codec_type, MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_HW);
636 int mediacodec_get_supported_type(mediacodec_h mediacodec, mediacodec_codec_type_e codec_type, bool encoder, int *support_type);
639 * @brief Gets the media packet pool allocated for recycling media packets.
640 * @details The user can get the pool allocated with the number of packets are required to be used in codecs.\n
641 * It is recommended to use media packet pool for better stability and performance.
643 * @remarks The @a pool should be released using media_packet_pool_deallocate() and destroyed using media_packet_pool_destroy().
644 * @param[in] mediacodec The mediacodec handle
645 * @param[out] pool The allocated pool handle
646 * @return @c 0 on success, otherwise a negative error value
647 * @retval #MEDIACODEC_ERROR_NONE Successful
648 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
649 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
650 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION The user calls mediacodec_get_packet_pool() before calling mediacodec_prepare().
651 * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
652 * @pre mediacodec_get_packet_pool() should be called after calling mediacodec_prepare().
653 * @post If the pool is used, media_packet_pool_deallocate() and media_packet_pool_destroy() should be called.
654 * @see media_packet_pool_acquire_packet()
655 * @see media_packet_pool_release_packet()
656 * @see media_packet_pool_deallocate()
657 * @see media_packet_pool_destroy()
659 int mediacodec_get_packet_pool(mediacodec_h mediacodec, media_packet_pool_h *pool);
669 #endif /* __TIZEN_MEDIA_CODEC_H__ */