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 encdoer
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 Prepares @a mediacodec for encoding/decoding.
317 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
318 * @param[in] mediacodec The handle to mediacodec
319 * @return @c 0 on success, otherwise a negative error value
320 * @retval #MEDIACODEC_ERROR_NONE Successful
321 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
322 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
323 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
324 * @pre The mediacodec should call mediacodec_set_codec()and mediacodec_set_vdec_info()/mediacodec_set_venc_info() before calling mediacodec_prepare()
325 * If the decoder is set by mediacodec_set_codec(), mediacodec_set_vdec_info() should be called. If the encoder is set by
326 * mediacodec_set_codec(), mediacodec_set_venc_info() should be called.
328 int mediacodec_prepare(mediacodec_h mediacodec);
331 * @brief Unprepares @a mediacodec for encoding/decoding.
332 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
333 * @param[in] mediacodec The handle to mediacodec
334 * @return @c 0 on success, otherwise a negative error value
335 * @retval #MEDIACODEC_ERROR_NONE Successful
336 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
337 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
338 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
340 int mediacodec_unprepare(mediacodec_h mediacodec);
343 * @brief Decodes/Encodes a packet. The function passed undecoded/unencoded packet to the input queue and decode/encode a
344 * frame sequentially.
345 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
346 * @param[in] mediacodec The handle to mediacodec
347 * @param[in] inbuf The current input format for the decoder/encoder
348 * @param[in] timeOutUs The timeout in microseconds. \n
349 * The input buffer wait up to "timeOutUs" microseconds.
350 * @return @c 0 on success, otherwise a negative error value
351 * @retval #MEDIACODEC_ERROR_NONE Successful
352 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
353 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
354 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
355 * @retval #MEDIACODEC_ERROR_OVERFLOW_INBUFFER Overflow inputbuffer
357 int mediacodec_process_input(mediacodec_h mediacodec, media_packet_h inbuf, uint64_t timeOutUs);
360 * @brief Gets the decoded or encoded packet from the output queue.
361 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
362 * @param[in] mediacodec The handle to mediacodec
363 * @param[out] outbuf The current output of the decoder/encoder. this function passed decoded/encoded frame to output
365 * @param[in] timeOutUs The timeout in microseconds. \n
366 * The input buffer wait up to "timeOutUs" microseconds.
367 * @return @c 0 on success, otherwise a negative error value
368 * @retval #MEDIACODEC_ERROR_NONE Successful
369 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
370 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
371 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
373 int mediacodec_get_output(mediacodec_h mediacodec, media_packet_h *outbuf, uint64_t timeOutUs);
376 * @brief Flushes both input and output buffers.
377 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
378 * @param[in] mediacodec The handle to mediacodec
379 * @return @c 0 on success, otherwise a negative error value
380 * @retval #MEDIACODEC_ERROR_NONE Successful
381 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
383 int mediacodec_flush_buffers(mediacodec_h mediacodec);
386 * @brief set empty buffer callback the media codec for process, asynchronously.
387 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
388 * @param[in] mediacodec The handle to mediacodec
389 * @param[in] callback The callback function to register
390 * @param[in] user_data The user data to be passed to the callback function
391 * @return @c 0 on success, otherwise a negative error value
392 * @retval #MEDIACODEC_ERROR_NONE Successful
393 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
394 * @pre mediacodec_set_input_buffer_used_cb should be called before mediacodec_preare().
395 * @post mediacodec_input_buffer_used_cb will be invoked.
396 * @see mediacodec_set_input_buffer_used_cb()
397 * @see mediacodec_unset_input_buffer_used_cb()
399 int mediacodec_set_input_buffer_used_cb(mediacodec_h mediacodec, mediacodec_input_buffer_used_cb callback, void* user_data);
402 * @brief unset input buffer used callback the media codec for process, asynchronously.
403 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
404 * @param[in] mediacodec The handle to mediacodec
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 * @see mediacodec_set_input_buffer_used_cb()
410 int mediacodec_unset_input_buffer_used_cb(mediacodec_h mediacodec);
413 * @brief set output buffer available callback the media codec for process, asynchronously.
414 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
415 * @param[in] mediacodec The handle to mediacodec
416 * @param[in] callback The callback function to register
417 * @param[in] user_data The user data to be passed to the callback function
418 * @return @c 0 on success, otherwise a negative error value
419 * @retval #MEDIACODEC_ERROR_NONE Successful
420 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
421 * @pre mediacodec_set_output_buffer_available_cb should be called before mediacodec_preare().
422 * @post mediacodec_output_buffer_available_cb will be invoked.
423 * @see mediacodec_set_output_buffer_available_cb()
424 * @see mediacodec_unset_output_buffer_available_cb()
426 int mediacodec_set_output_buffer_available_cb(mediacodec_h mediacodec, mediacodec_output_buffer_available_cb callback, void* user_data);
429 * @brief unset output buffer available callback the media codec for process, asynchronously.
430 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
431 * @param[in] mediacodec The handle to mediacodec
432 * @return @c 0 on success, otherwise a negative error value
433 * @retval #MEDIACODEC_ERROR_NONE Successful
434 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
435 * @see mediacodec_set_output_buffer_available_cb()
437 int mediacodec_unset_output_buffer_available_cb(mediacodec_h mediacodec);
440 * @brief set error 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 * @param[in] callback The callback function to register
444 * @param[in] user_data The user data to be passed to the callback function
445 * @return @c 0 on success, otherwise a negative error value
446 * @retval #MEDIACODEC_ERROR_NONE Successful
447 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
448 * @pre mediacodec_set_error_cb should be called before mediacodec_preare().
449 * @post mediacodec_error_cb will be invoked.
450 * @see mediacodec_set_error_cb()
451 * @see mediacodec_unset_error_cb()
453 int mediacodec_set_error_cb(mediacodec_h mediacodec, mediacodec_error_cb callback, void* user_data);
456 * @brief unset error callback the media codec for process, asynchronously.
457 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
458 * @param[in] mediacodec The handle to mediacodec
459 * @return @c 0 on success, otherwise a negative error value
460 * @retval #MEDIACODEC_ERROR_NONE Successful
461 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
462 * @see mediacodec_set_error_cb()
464 int mediacodec_unset_error_cb(mediacodec_h mediacodec);
467 * @brief set eos 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 * @param[in] callback The callback function to register
471 * @param[in] user_data The user data to be passed to the callback function
472 * @return @c 0 on success, otherwise a negative error value
473 * @retval #MEDIACODEC_ERROR_NONE Successful
474 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
475 * @pre mediacodec_set_eos_cb should be called before mediacodec_preare().
476 * @post mediacodec_eos_cb will be invoked.
477 * @see mediacodec_set_eos_cb()
478 * @see mediacodec_unset_eos_cb()
480 int mediacodec_set_eos_cb(mediacodec_h mediacodec, mediacodec_eos_cb callback, void* user_data);
483 * @brief unset eos callback the media codec for process, asynchronously.
484 * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
485 * @param[in] mediacodec The handle to mediacodec
486 * @return @c 0 on success, otherwise a negative error value
487 * @retval #MEDIACODEC_ERROR_NONE Successful
488 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
489 * @see mediacodec_set_event_handler_cb()
491 int mediacodec_unset_eos_cb(mediacodec_h mediacodec);
494 * @brief Registers a callback function to be invoked when the mediacodec needs more data or has enough data.
495 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
496 * @param[in] mediacodec The handle to mediacodec
497 * @param[in] callback The callback function to register
498 * @param[in] user_data The user data to be passed to the callback function
499 * @return @c 0 on success, otherwise a negative error value
500 * @retval #MEDIACODEC_ERROR_NONE Successful
501 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
502 * @pre mediacodec_set_buffer_status_cb should be called before mediacodec_preare().
503 * @post mediacodec_buffer_status_cb will be invoked.
504 * @see mediacodec_set_buffer_status_cb()
505 * @see mediacodec_unset_buffer_status_cb()
507 int mediacodec_set_buffer_status_cb(mediacodec_h mediacodec, mediacodec_buffer_status_cb callback, void* user_data);
510 * @brief Unregisters the callback function.
511 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
512 * @param[in] mediacodec The handle to mediacodec
513 * @return @c 0 on success, otherwise a negative error value
514 * @retval #MEDIACODEC_ERROR_NONE Successful
515 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
517 int mediacodec_unset_buffer_status_cb(mediacodec_h mediacodec);
520 * @brief Retrieves all supported codecs by invoking callback function once for each supported codecs.
521 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
522 * @param[in] mediacodec The handle to mediacodec
523 * @param[in] callback The callback function to invoke
524 * @param[in] user_data The user data to be passed to the callback function
525 * @return @c 0 on success, otherwise a negative error value
526 * @retval #MEDIACODEC_ERROR_NONE Successful
527 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
528 * @see mediacodec_foreach_supported_codec()
530 int mediacodec_foreach_supported_codec(mediacodec_h mediacodec, mediacodec_supported_codec_cb callback, void *user_data);
533 * @brief Verifies whether encoding can be performed with codec_type or not.
534 * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
535 * @param[in] mediacodec The handle to mediacodec
536 * @param[in] codec_type The identifier of the codec type of the encoder.
537 * @param[in] encoder Whether the encoder or decoder : (@c true = encoder, @c false = decoder).
538 * @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)
539 * @return @c 0 on success, otherwise a negative error value
540 * @retval #MEDIACODEC_ERROR_NONE Successful
541 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
543 #include <media_codec.h>
544 mediacodec_h mediacodec;
545 mediacodec_support_type_e type;
546 mediacodec_codec_type_e codec_type = MEDIACODEC_H264;
548 mediacodec_create(&mediacodec);
549 mediacodec_get_supported_type(mediacodec, codec_type, 1, &type);
551 if(type == MEDIACODEC_SUPPORT_TYPE_HW)
552 // only h/w supported
553 else if (type == MEDIACODEC_SUPPORT_TYPE_SW)
554 // only s/w supported
555 else if (type == (MEDIACODEC_SUPPORT_TYPE_HW|MEDIACODEC_SUPPORT_TYPE_SW)
558 mediacodec_set_codec(mediacodec, codec_type, MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_HW);
561 int mediacodec_get_supported_type(mediacodec_h mediacodec, mediacodec_codec_type_e codec_type, bool encoder, int *support_type);
564 * @brief Gets the media packet pool allocated for recycling media packets.
565 * @details The user can get the pool allocated with the number of packets are required to be used in codecs.\n
566 * It is recomended to use media packet pool for better stability and performance.
568 * @remarks The @a pool should be released using media_packet_pool_deallocate() and destroyed using media_packet_pool_destroy().
569 * @param[in] mediacodec The mediacodec handle
570 * @param[out] pool The allocated pool handle
571 * @return @c 0 on success, otherwise a negative error value
572 * @retval #MEDIACODEC_ERROR_NONE Successful
573 * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
574 * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
575 * @retval #MEDIACODEC_ERROR_INVALID_OPERATION The user calls mediacodec_get_packet_pool() before calling mediacodec_prepare().
576 * @pre mediacodec_get_packet_pool() should be called after calling mediacodec_prepare().
577 * @post If the pool is used, media_packet_pool_deallocate() and media_packet_pool_destroy() should be called.
578 * @see media_packet_pool_acquire_packet()
579 * @see media_packet_pool_release_packet()
580 * @see media_packet_pool_deallocate()
581 * @see media_packet_pool_destroy()
583 int mediacodec_get_packet_pool(mediacodec_h mediacodec, media_packet_pool_h *pool);
593 #endif /* __TIZEN_MEDIA_CODEC_H__ */