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_e;
124 * @brief Enumeration of buffer status
125 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
128 MEDIACODEC_NEED_DATA,
129 MEDIACODEC_ENOUGH_DATA
130 } mediacodec_status_e;
133 * @brief Called when the input buffer(pkt) used up.
134 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
135 * @details It will be invoked when mediacodec has used input buffer.
136 * @param[in] pkt The media packet handle
137 * @param[in] user_data The user data passed from the callback registration function
138 * @pre It will be invoked when input buffer process completed if you register this callback using mediacodec_set_input_buffer_used_cb().
139 * @see mediacodec_set_input_buffer_used_cb()
140 * @see mediacodec_unset_input_buffer_used_cb()
142 typedef void (*mediacodec_input_buffer_used_cb)(media_packet_h pkt, void *user_data);
145 * @brief Called when the output buffer is available.
146 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
147 * @details It will be invoked when mediacodec has output buffer.
148 * @param[in] pkt The media packet handle
149 * @param[in] user_data The user data passed from the callback registration function
150 * @pre It will be invoked when mediacodec process completed(had output buffer) if you register this callback using mediacodec_set_fill_buffer_cb().
151 * @see mediacodec_set_output_buffer_available_cb()
152 * @see mediacodec_unset_output_buffer_available_cb()
154 typedef void (*mediacodec_output_buffer_available_cb)(media_packet_h pkt, void *user_data);
157 * @brief Called when the error has occured
158 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
159 * @details It will be invoked when the error has occured.
160 * @param[in] error_code The error code
161 * @param[in] user_data The user data passed from the callback registration function
162 * @pre It will be invoked when the error has occured if you register this callback using mediacodec_set_error_cb().
163 * @see mediacodec_set_error_cb()
164 * @see mediacodec_unset_error_cb()
166 typedef void (*mediacodec_error_cb)(mediacodec_error_e error, void *user_data);
169 * @brief Called when there is no data to decode/encode
170 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
171 * @details It will be invoked when the end-of-stream is reached.
172 * @param[in] user_data The user data passed from the callback registration function
173 * @pre It will be invoked when the eos event generate if you register this callback using mediacodec_set_eos_cb().
174 * @see mediacodec_set_eos_cb()
175 * @see mediacodec_unset_eos_cb()
177 typedef void (*mediacodec_eos_cb)(void *user_data);
180 * @brief Called when the mediacodec needs more data or has enough data.
181 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
182 * @details It is recommended that the application stops calling mediacodec_process_input() when MEDIACODEC_ENOUGH_DATA
184 * @param[in] user_data The user data passed from the callback registration function
185 * @see mediacodec_set_buffer_status_cb()
186 * @see mediacodec_unset_buffer_status_cb()
188 typedef void (*mediacodec_buffer_status_cb)(mediacodec_status_e status, void *user_data);
191 * @brief Called once for each supported codec types.
192 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
193 * @param[in] codec_type The codec type
194 * @param[in] user_data The user data passed from the foreach function
195 * @return @c true to continue with the next iteration of the loop, @c false to break out of the loop.
196 * @pre mediacodec_foreach_supported_codec() will invoke this callback.
197 * @see mediacodec_foreach_supported_codec()
199 typedef bool (*mediacodec_supported_codec_cb)(mediacodec_codec_type_e codec_type, void *user_data);
202 * @brief Creates a mediacodec handle for decoding/encoding
203 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
204 * @remarks you must release @a mediacodec using mediacodec_destroy().\n
205 * Although you can create multiple mediacodec handles at the same time,
206 * the mediacodec cannot guarantee proper operation because of limited resources, like
207 * audio or display device.
209 * @param[out] mediacodec A new handle to mediacodec
210 * @return @c 0 on success, otherwise a negative error value
211 * @retval #MEDIACODEC_ERROR_NONE Successful
212 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
213 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
214 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
216 int mediacodec_create(mediacodec_h *mediacodec);
219 * @brief Destroys the mediacodec handle and releases all its resources.
220 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
221 * @remarks To completely shutdown the mediacodec operation, call this function with a valid player handle from any
224 * @param[in] mediacodec The handle to mediacodec to be destroyed.
225 * @return @c 0 on success, otherwise a negative error value
226 * @retval #MEDIACODEC_ERROR_NONE Successful
227 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
228 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
229 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
231 int mediacodec_destroy(mediacodec_h mediacodec);
234 * @brief Sets the codec type and decoder/encoder.
235 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
236 * @remarks If this codec is to be used as a decoder, pass the #MEDIACODEC_DECODER flag.
237 * If this codec is to be used as an encoder, pass the #MEDIACODEC_ENCODER flag.\n
238 * The software codec is used as default setting(#MEDIACODEC_SUPPORT_TYPE_SW) if user doesn't set hardware flag.
239 * If user wants to use h/w decoder, user needs to pass the #MEDIACODEC_DECODER | #MEDIACODEC_SUPPORT_TYPE_HW.
240 * @param[in] mediacodec The handle of mediacodec
241 * @param[in] codec_type The identifier of the codec type of the decoder/encoder
242 * @param[in] flags The encoding/decoding scheme, defined by #mediacodec_support_type_e
243 * @return @c 0 on success, otherwise a negative error value
244 * @retval #MEDIACODEC_ERROR_NONE Successful
245 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
246 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
247 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
248 * @retval #MEDIACODEC_ERROR_CODEC_NOT_FOUND Codec not found
250 int mediacodec_set_codec(mediacodec_h mediacodec, mediacodec_codec_type_e codec_type, int flags);
253 * @brief Sets the default info for the video decoder
254 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
255 * @param[in] mediacodec The handle to mediacodec
256 * @param[in] width The width for video decoding.
257 * @param[in] height The height for video decoding.
258 * @return @c 0 on success, otherwise a negative error value
259 * @retval #MEDIACODEC_ERROR_NONE Successful
260 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
261 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
262 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
264 int mediacodec_set_vdec_info(mediacodec_h mediacodec, int width, int height);
267 * @brief Sets the default info for the video encoder
268 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
269 * @remarks The frame rate is the speed of recording and the speed of playback.
270 * If user wants the default setting for ratecontrol, set @a target_bits to @c 0.
271 * @param[in] mediacodec The handle to mediacodec
272 * @param[in] width The width for video encoding.
273 * @param[in] height The height for video encoding.
274 * @param[in] fps The frame rate in frames per second.
275 * @param[in] target_bits The target bitrates in bits per second.(a unit of kbit)
276 * @return @c 0 on success, otherwise a negative error value
277 * @retval #MEDIACODEC_ERROR_NONE Successful
278 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
279 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
280 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
282 int mediacodec_set_venc_info(mediacodec_h mediacodec, int width, int height, int fps, int target_bits);
285 * @brief Sets the default info for the audio decoder
286 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
287 * @param[in] mediacodec The handle to mediacodec
288 * @param[in] samplerate The samplerate for audio decoding.
289 * @param[in] channel The channels for audio decoding.
290 * @param[in] bit The bits resolution for audio decoding.
291 * @return @c 0 on success, otherwise a negative error value
292 * @retval #MEDIACODEC_ERROR_NONE Successful
293 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
294 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
295 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
297 int mediacodec_set_adec_info(mediacodec_h mediacodec, int samplerate, int channel, int bit);
300 * @brief Sets the default info for the audio encoder
301 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
302 * @param[in] mediacodec The handle to mediacodec
303 * @param[in] samplerate The samplerate for audio encoding.
304 * @param[in] channel The channels for audio encoding.
305 * @param[in] bit The bits resolution for audio encoding.
306 * @param[in] bitrate The bitrate for audio encoding.
307 * @return @c 0 on success, otherwise a negative error value
308 * @retval #MEDIACODEC_ERROR_NONE Successful
309 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
310 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
311 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
313 int mediacodec_set_aenc_info(mediacodec_h mediacodec, int samplerate, int channel, int bit, int bitrate);
316 * @brief Sets the codec type and codec default info via media format.
317 * @details Sets the value via media format instead of mediacodec_set_codec(), mediacodec_set_venc_info(),
318 * mediacodec_set_vdec_info(), mediacodec_set_aenc_info(), and mediacodec_set_adec_info().
320 * @remarks When using the @a format parameter from the output of the media demuxer, you can use media format via media_packet_get_format().
321 * Otherwise, you must set the following values after creating media format.
322 * Set the audio or video codec type via media_format_set_video_mime() or media_format_set_audio_mime().
323 * For video decoding, width, height must be set via media_format_set_video_width() and media_format_set_video_height().
324 * 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().
325 * 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().
326 * For audio encoding, samplerate, channel, bit, and bitrate must be set via media_format_set_audio_avg_bps().\n
327 * If this codec is to be used as a decoder, pass the #MEDIACODEC_DECODER flag.
328 * If this codec is to be used as an encoder, pass the #MEDIACODEC_ENCODER flag.\n
329 * The software codec is used as default setting (#MEDIACODEC_SUPPORT_TYPE_SW) if user doesn't set hardware flag.
330 * If you wants to use h/w decoder, you needs to pass the #MEDIACODEC_DECODER | #MEDIACODEC_SUPPORT_TYPE_HW.
331 * @param[in] mediacodec The mediacodec handle
332 * @param[in] format The #media_format_h of input data
333 * @param[in] flags The encoding/decoding scheme,
334 * values of #mediacodec_support_type_e combined with bitwise 'or'
335 * @return @c 0 on success, otherwise a negative error value
336 * @retval #MEDIACODEC_ERROR_NONE Successful
337 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
338 * @retval #MEDIACODEC_ERROR_CODEC_NOT_FOUND Unsupported codec
339 * @pre The media format has been created and the required values for configuration have been set.
340 * @see media_format_set_video_mime()
341 * @see media_format_set_audio_mime()
342 * @see media_format_set_video_width()
343 * @see media_format_set_video_height()
344 * @see media_format_set_video_avg_bps()
345 * @see media_format_set_video_frame_rate()
346 * @see media_format_set_audio_channel()
347 * @see media_format_set_audio_samplerate()
348 * @see media_format_set_audio_bit()
349 * @see media_format_set_audio_avg_bps()
351 int mediacodec_configure_from_media_format(mediacodec_h mediacodec, media_format_h format, int flags);
354 * @brief Prepares @a mediacodec for encoding/decoding.
355 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
356 * @param[in] mediacodec The handle to mediacodec
357 * @return @c 0 on success, otherwise a negative error value
358 * @retval #MEDIACODEC_ERROR_NONE Successful
359 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
360 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
361 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
362 * @pre The mediacodec should call mediacodec_set_codec()and mediacodec_set_vdec_info()/mediacodec_set_venc_info() before calling mediacodec_prepare()
363 * If the decoder is set by mediacodec_set_codec(), mediacodec_set_vdec_info() should be called. If the encoder is set by
364 * mediacodec_set_codec(), mediacodec_set_venc_info() should be called.
366 int mediacodec_prepare(mediacodec_h mediacodec);
369 * @brief Unprepares @a mediacodec for encoding/decoding.
370 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
371 * @param[in] mediacodec The handle to mediacodec
372 * @return @c 0 on success, otherwise a negative error value
373 * @retval #MEDIACODEC_ERROR_NONE Successful
374 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
375 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
376 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
378 int mediacodec_unprepare(mediacodec_h mediacodec);
381 * @brief Decodes/Encodes a packet. The function passed undecoded/unencoded packet to the input queue and decode/encode a
382 * frame sequentially.
383 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
384 * @param[in] mediacodec The handle to mediacodec
385 * @param[in] inbuf The current input format for the decoder/encoder
386 * @param[in] timeOutUs The timeout in microseconds. \n
387 * The input buffer wait up to "timeOutUs" microseconds.
388 * @return @c 0 on success, otherwise a negative error value
389 * @retval #MEDIACODEC_ERROR_NONE Successful
390 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
391 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
392 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
393 * @retval #MEDIACODEC_ERROR_OVERFLOW_INBUFFER Overflow inputbuffer
395 int mediacodec_process_input(mediacodec_h mediacodec, media_packet_h inbuf, uint64_t timeOutUs);
398 * @brief Gets the decoded or encoded packet from the output queue.
399 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
400 * @param[in] mediacodec The handle to mediacodec
401 * @param[out] outbuf The current output of the decoder/encoder.
402 * this function passed decoded/encoded frame to output queue.
403 * @param[in] timeOutUs The timeout in microseconds. \n
404 * The input buffer wait up to "timeOutUs" microseconds.
405 * @return @c 0 on success, otherwise a negative error value
406 * @retval #MEDIACODEC_ERROR_NONE Successful
407 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
408 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
409 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
411 int mediacodec_get_output(mediacodec_h mediacodec, media_packet_h *outbuf, uint64_t timeOutUs);
414 * @brief Flushes both input and output buffers.
415 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
416 * @param[in] mediacodec The handle to mediacodec
417 * @return @c 0 on success, otherwise a negative error value
418 * @retval #MEDIACODEC_ERROR_NONE Successful
419 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
421 int mediacodec_flush_buffers(mediacodec_h mediacodec);
424 * @brief set empty buffer callback the media codec for process, asynchronously.
425 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
426 * @param[in] mediacodec The handle to mediacodec
427 * @param[in] callback The callback function to register
428 * @param[in] user_data The user data to be passed to the callback function
429 * @return @c 0 on success, otherwise a negative error value
430 * @retval #MEDIACODEC_ERROR_NONE Successful
431 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
432 * @pre mediacodec_set_input_buffer_used_cb should be called before mediacodec_preare().
433 * @post mediacodec_input_buffer_used_cb will be invoked.
434 * @see mediacodec_set_input_buffer_used_cb()
435 * @see mediacodec_unset_input_buffer_used_cb()
437 int mediacodec_set_input_buffer_used_cb(mediacodec_h mediacodec, mediacodec_input_buffer_used_cb callback, void* user_data);
440 * @brief unset input buffer used callback the media codec for process, asynchronously.
441 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
442 * @param[in] mediacodec The handle to mediacodec
443 * @return @c 0 on success, otherwise a negative error value
444 * @retval #MEDIACODEC_ERROR_NONE Successful
445 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
446 * @see mediacodec_set_input_buffer_used_cb()
448 int mediacodec_unset_input_buffer_used_cb(mediacodec_h mediacodec);
451 * @brief set output buffer available callback the media codec for process, asynchronously.
452 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
453 * @param[in] mediacodec The handle to mediacodec
454 * @param[in] callback The callback function to register
455 * @param[in] user_data The user data to be passed to the callback function
456 * @return @c 0 on success, otherwise a negative error value
457 * @retval #MEDIACODEC_ERROR_NONE Successful
458 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
459 * @pre mediacodec_set_output_buffer_available_cb should be called before mediacodec_preare().
460 * @post mediacodec_output_buffer_available_cb will be invoked.
461 * @see mediacodec_set_output_buffer_available_cb()
462 * @see mediacodec_unset_output_buffer_available_cb()
464 int mediacodec_set_output_buffer_available_cb(mediacodec_h mediacodec, mediacodec_output_buffer_available_cb callback, void* user_data);
467 * @brief unset output buffer available callback the media codec for process, asynchronously.
468 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
469 * @param[in] mediacodec The handle to mediacodec
470 * @return @c 0 on success, otherwise a negative error value
471 * @retval #MEDIACODEC_ERROR_NONE Successful
472 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
473 * @see mediacodec_set_output_buffer_available_cb()
475 int mediacodec_unset_output_buffer_available_cb(mediacodec_h mediacodec);
478 * @brief set error 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 * @pre mediacodec_set_error_cb should be called before mediacodec_preare().
487 * @post mediacodec_error_cb will be invoked.
488 * @see mediacodec_set_error_cb()
489 * @see mediacodec_unset_error_cb()
491 int mediacodec_set_error_cb(mediacodec_h mediacodec, mediacodec_error_cb callback, void* user_data);
494 * @brief unset error callback the media codec for process, asynchronously.
495 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
496 * @param[in] mediacodec The handle to mediacodec
497 * @return @c 0 on success, otherwise a negative error value
498 * @retval #MEDIACODEC_ERROR_NONE Successful
499 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
500 * @see mediacodec_set_error_cb()
502 int mediacodec_unset_error_cb(mediacodec_h mediacodec);
505 * @brief set eos callback the media codec for process, asynchronously.
506 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
507 * @param[in] mediacodec The handle to mediacodec
508 * @param[in] callback The callback function to register
509 * @param[in] user_data The user data to be passed to the callback function
510 * @return @c 0 on success, otherwise a negative error value
511 * @retval #MEDIACODEC_ERROR_NONE Successful
512 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
513 * @pre mediacodec_set_eos_cb should be called before mediacodec_preare().
514 * @post mediacodec_eos_cb will be invoked.
515 * @see mediacodec_set_eos_cb()
516 * @see mediacodec_unset_eos_cb()
518 int mediacodec_set_eos_cb(mediacodec_h mediacodec, mediacodec_eos_cb callback, void* user_data);
521 * @brief unset eos callback the media codec for process, asynchronously.
522 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
523 * @param[in] mediacodec The handle to mediacodec
524 * @return @c 0 on success, otherwise a negative error value
525 * @retval #MEDIACODEC_ERROR_NONE Successful
526 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
527 * @see mediacodec_set_event_handler_cb()
529 int mediacodec_unset_eos_cb(mediacodec_h mediacodec);
532 * @brief Registers a callback function to be invoked when the mediacodec needs more data or has enough data.
533 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
534 * @param[in] mediacodec The handle to mediacodec
535 * @param[in] callback The callback function to register
536 * @param[in] user_data The user data to be passed to the callback function
537 * @return @c 0 on success, otherwise a negative error value
538 * @retval #MEDIACODEC_ERROR_NONE Successful
539 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
540 * @pre mediacodec_set_buffer_status_cb should be called before mediacodec_preare().
541 * @post mediacodec_buffer_status_cb will be invoked.
542 * @see mediacodec_set_buffer_status_cb()
543 * @see mediacodec_unset_buffer_status_cb()
545 int mediacodec_set_buffer_status_cb(mediacodec_h mediacodec, mediacodec_buffer_status_cb callback, void* user_data);
548 * @brief Unregisters the callback function.
549 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
550 * @param[in] mediacodec The handle to mediacodec
551 * @return @c 0 on success, otherwise a negative error value
552 * @retval #MEDIACODEC_ERROR_NONE Successful
553 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
555 int mediacodec_unset_buffer_status_cb(mediacodec_h mediacodec);
558 * @brief Retrieves all supported codecs by invoking callback function once for each supported codecs.
559 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
560 * @param[in] mediacodec The handle to mediacodec
561 * @param[in] callback The callback function to invoke
562 * @param[in] user_data The user data to be passed to the callback function
563 * @return @c 0 on success, otherwise a negative error value
564 * @retval #MEDIACODEC_ERROR_NONE Successful
565 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
566 * @see mediacodec_foreach_supported_codec()
568 int mediacodec_foreach_supported_codec(mediacodec_h mediacodec, mediacodec_supported_codec_cb callback, void *user_data);
571 * @brief Verifies whether encoding can be performed with codec_type or not.
572 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
573 * @param[in] mediacodec The handle to mediacodec
574 * @param[in] codec_type The identifier of the codec type of the encoder.
575 * @param[in] encoder Whether the encoder or decoder : (@c true = encoder, @c false = decoder).
576 * @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)
577 * @return @c 0 on success, otherwise a negative error value
578 * @retval #MEDIACODEC_ERROR_NONE Successful
579 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
581 #include <media_codec.h>
582 mediacodec_h mediacodec;
583 mediacodec_support_type_e type;
584 mediacodec_codec_type_e codec_type = MEDIACODEC_H264;
586 mediacodec_create(&mediacodec);
587 mediacodec_get_supported_type(mediacodec, codec_type, 1, &type);
589 if(type == MEDIACODEC_SUPPORT_TYPE_HW)
590 // only h/w supported
591 else if (type == MEDIACODEC_SUPPORT_TYPE_SW)
592 // only s/w supported
593 else if (type == (MEDIACODEC_SUPPORT_TYPE_HW|MEDIACODEC_SUPPORT_TYPE_SW)
596 mediacodec_set_codec(mediacodec, codec_type, MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_HW);
599 int mediacodec_get_supported_type(mediacodec_h mediacodec, mediacodec_codec_type_e codec_type, bool encoder, int *support_type);
602 * @brief Gets the media packet pool allocated for recycling media packets.
603 * @details The user can get the pool allocated with the number of packets are required to be used in codecs.\n
604 * It is recomended to use media packet pool for better stability and performance.
606 * @remarks The @a pool should be released using media_packet_pool_deallocate() and destroyed using media_packet_pool_destroy().
607 * @param[in] mediacodec The mediacodec handle
608 * @param[out] pool The allocated pool handle
609 * @return @c 0 on success, otherwise a negative error value
610 * @retval #MEDIACODEC_ERROR_NONE Successful
611 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
612 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
613 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION The user calls mediacodec_get_packet_pool() before calling mediacodec_prepare().
614 * @pre mediacodec_get_packet_pool() should be called after calling mediacodec_prepare().
615 * @post If the pool is used, media_packet_pool_deallocate() and media_packet_pool_destroy() should be called.
616 * @see media_packet_pool_acquire_packet()
617 * @see media_packet_pool_release_packet()
618 * @see media_packet_pool_deallocate()
619 * @see media_packet_pool_destroy()
621 int mediacodec_get_packet_pool(mediacodec_h mediacodec, media_packet_pool_h *pool);
631 #endif /* __TIZEN_MEDIA_CODEC_H__ */