Update header file for documentation (#2)
[platform/core/api/mediacodec.git] / include / media_codec.h
1 /*
2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
3 *
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16
17 #ifndef __TIZEN_MEDIA_CODEC_H__
18 #define __TIZEN_MEDIA_CODEC_H__
19
20 #include <tizen.h>
21 #include <stdint.h>
22 #include <media_packet.h>
23 #include <media_packet_pool.h>
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 /**
30 * @file media_codec.h
31 * @brief This file contains the capi media codec API.
32 */
33
34 /**
35 * @addtogroup CAPI_MEDIA_CODEC_MODULE
36 * @{
37 */
38
39 /**
40  * @brief Media Codec type handle.
41  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
42  */
43 typedef struct mediacodec_s *mediacodec_h;
44
45 /**
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.
50  */
51 typedef enum {
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;
57
58 /**
59  * @brief Enumerations of media codec type.
60  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
61  */
62 typedef enum {
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)*/
82         MEDIACODEC_OPUS         = 0x10D0,   /**< OPUS (Since 6.0)*/
83
84         MEDIACODEC_H261         = 0x2010,   /**< H.261*/
85         MEDIACODEC_H263         = 0x2020,   /**< H.263*/
86         MEDIACODEC_H264         = 0x2030,   /**< H.264*/
87         MEDIACODEC_MJPEG        = 0x2040,   /**< MJPEG*/
88         MEDIACODEC_MPEG1        = 0x2050,   /**< MPEG1*/
89         MEDIACODEC_MPEG2        = 0x2060,   /**< MPEG2*/
90         MEDIACODEC_MPEG4        = 0x2070,   /**< MPEG4*/
91         MEDIACODEC_HEVC         = 0x2080,   /**< HEVC (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
92         MEDIACODEC_VP8          = 0x2090,   /**< VP8 (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
93         MEDIACODEC_VP9          = 0x20A0,   /**< VP9 (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
94         MEDIACODEC_VC1          = 0x20B0,   /**< VC1 (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
95 } mediacodec_codec_type_e;
96
97 /**
98  * @brief Enumeration of media codec error.
99  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
100  */
101 typedef enum {
102         MEDIACODEC_ERROR_NONE                       = TIZEN_ERROR_NONE,                     /**< Successful */
103         MEDIACODEC_ERROR_OUT_OF_MEMORY              = TIZEN_ERROR_OUT_OF_MEMORY,            /**< Out of memory */
104         MEDIACODEC_ERROR_INVALID_PARAMETER          = TIZEN_ERROR_INVALID_PARAMETER,        /**< Invalid parameter */
105         MEDIACODEC_ERROR_INVALID_OPERATION          = TIZEN_ERROR_INVALID_OPERATION,        /**< Invalid operation */
106         MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE    = TIZEN_ERROR_NOT_SUPPORTED,            /**< Not supported */
107         MEDIACODEC_ERROR_PERMISSION_DENIED          = TIZEN_ERROR_PERMISSION_DENIED,        /**< Permission denied */
108         MEDIACODEC_ERROR_INVALID_STATE              = TIZEN_ERROR_MEDIACODEC | 0x01,        /**< Invalid state */
109         MEDIACODEC_ERROR_INVALID_INBUFFER           = TIZEN_ERROR_MEDIACODEC | 0x02,        /**< Invalid input buffer */
110         MEDIACODEC_ERROR_INVALID_OUTBUFFER          = TIZEN_ERROR_MEDIACODEC | 0x03,        /**< Invalid output buffer */
111         MEDIACODEC_ERROR_INTERNAL                   = TIZEN_ERROR_MEDIACODEC | 0x04,        /**< Internal error */
112         MEDIACODEC_ERROR_NOT_INITIALIZED            = TIZEN_ERROR_MEDIACODEC | 0x05,        /**< Not initialized mediacodec */
113         MEDIACODEC_ERROR_INVALID_STREAM             = TIZEN_ERROR_MEDIACODEC | 0x06,        /**< Invalid stream */
114         MEDIACODEC_ERROR_CODEC_NOT_FOUND            = TIZEN_ERROR_MEDIACODEC | 0x07,        /**< Not supported format */
115         MEDIACODEC_ERROR_DECODE                     = TIZEN_ERROR_MEDIACODEC | 0x08,        /**< Error while decoding data */
116         MEDIACODEC_ERROR_NO_FREE_SPACE              = TIZEN_ERROR_MEDIACODEC | 0x09,        /**< Out of storage */
117         MEDIACODEC_ERROR_STREAM_NOT_FOUND           = TIZEN_ERROR_MEDIACODEC | 0x0a,        /**< Cannot find stream */
118         MEDIACODEC_ERROR_NOT_SUPPORTED_FORMAT       = TIZEN_ERROR_MEDIACODEC | 0x0b,        /**< Not supported format */
119         MEDIACODEC_ERROR_BUFFER_NOT_AVAILABLE       = TIZEN_ERROR_MEDIACODEC | 0x0c,        /**< Not available buffer */
120         MEDIACODEC_ERROR_OVERFLOW_INBUFFER          = TIZEN_ERROR_MEDIACODEC | 0x0d,        /**< Overflow input buffer (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
121         MEDIACODEC_ERROR_RESOURCE_OVERLOADED        = TIZEN_ERROR_MEDIACODEC | 0x0e,        /**< Exceed the instance limits (Since @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif)*/
122         MEDIACODEC_ERROR_RESOURCE_CONFLICT          = TIZEN_ERROR_MEDIACODEC | 0x0f,        /**< Interrupted by a resource conflict (Since 5.0)*/
123 } mediacodec_error_e;
124
125 /**
126  * @brief Enumeration of buffer status.
127  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
128  */
129 typedef enum {
130         MEDIACODEC_NEED_DATA,    /**< The internal queue is running out of data */
131         MEDIACODEC_ENOUGH_DATA  /**< The internal queue is full */
132 } mediacodec_status_e;
133
134 /**
135  * @brief Called when the input buffer(packet) used up.
136  * @details It will be invoked when mediacodec has used input buffer.
137  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
138  * @remarks The @a packet should be released using media_packet_destroy().
139  * @param[in] packet    The media packet handle
140  * @param[in] user_data The user data passed from the callback registration function
141  * @pre It will be invoked when input buffer process completed if you register this callback using mediacodec_set_input_buffer_used_cb().
142  * @see mediacodec_set_input_buffer_used_cb()
143  * @see mediacodec_unset_input_buffer_used_cb()
144  */
145 typedef void (*mediacodec_input_buffer_used_cb)(media_packet_h packet, void *user_data);
146
147 /**
148  * @brief Called when the output buffer is available.
149  * @details It will be invoked when mediacodec has output buffer.
150  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
151  * @remarks The @a packet should be released using media_packet_destroy().
152  * @param[in] packet    The media packet handle
153  * @param[in] user_data The user data passed from the callback registration function
154  * @pre It will be invoked when mediacodec process completed(had output buffer) if you register this callback using mediacodec_set_fill_buffer_cb().
155  * @see mediacodec_set_output_buffer_available_cb()
156  * @see mediacodec_unset_output_buffer_available_cb()
157  */
158 typedef void (*mediacodec_output_buffer_available_cb)(media_packet_h packet, void *user_data);
159
160 /**
161  * @brief Called when the error has occurred.
162  * @details It will be invoked when the error has occurred.
163  *          Following error codes can be delivered.
164  *          #MEDIACODEC_ERROR_INTERNAL,
165  *          #MEDIACODEC_ERROR_INVALID_STREAM,
166  *          #MEDIACODEC_ERROR_NOT_SUPPORTED_FORMAT,
167  *          #MEDIACODEC_ERROR_RESOURCE_CONFLICT
168  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
169  * @param[in] error The error code
170  * @param[in] user_data  The user data passed from the callback registration function
171  * @pre It will be invoked when the error has occurred if you register this callback using mediacodec_set_error_cb().
172  * @see mediacodec_set_error_cb()
173  * @see mediacodec_unset_error_cb()
174  */
175 typedef void (*mediacodec_error_cb)(mediacodec_error_e error, void *user_data);
176
177 /**
178  * @brief Called when there is no data to decode/encode.
179  * @details It will be invoked when the end-of-stream is reached.
180  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
181  * @param[in] user_data The user data passed from the callback registration function
182  * @pre It will be invoked when the eos event generate if you register this callback using mediacodec_set_eos_cb().
183  * @see mediacodec_set_eos_cb()
184  * @see mediacodec_unset_eos_cb()
185  */
186 typedef void (*mediacodec_eos_cb)(void *user_data);
187
188 /**
189  * @brief Called when the mediacodec needs more data or has enough data.
190  * @details It is recommended that the application stops calling mediacodec_process_input() when #MEDIACODEC_ENOUGH_DATA
191  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
192  * is invoked.
193  * @param[in] status    The state of the buffer
194  * @param[in] user_data The user data passed from the callback registration function
195  * @see mediacodec_set_buffer_status_cb()
196  * @see mediacodec_unset_buffer_status_cb()
197  */
198 typedef void (*mediacodec_buffer_status_cb)(mediacodec_status_e status, void *user_data);
199
200 /**
201  * @brief Called once for each supported codec types.
202  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
203  * @param[in] codec_type  The codec type
204  * @param[in] user_data   The user data passed from the foreach function
205  * @return  @c true to continue with the next iteration of the loop, @c false to break out of the loop.
206  * @pre mediacodec_foreach_supported_codec() will invoke this callback.
207  * @see mediacodec_foreach_supported_codec()
208  */
209 typedef bool (*mediacodec_supported_codec_cb)(mediacodec_codec_type_e codec_type, void *user_data);
210
211 /**
212  * @brief Creates a mediacodec handle for decoding/encoding.
213  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
214  * @remarks you must release @a mediacodec using mediacodec_destroy().\n
215  *          Although you can create multiple mediacodec handles at the same time,
216  *          the mediacodec cannot guarantee proper operation because of limited resources, like
217  *          audio or display device.
218  *
219  * @param[out] mediacodec  A new handle to mediacodec
220  * @return @c 0 on success, otherwise a negative error value
221  * @retval #MEDIACODEC_ERROR_NONE Successful
222  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
223  * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
224  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
225  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
226  */
227 int mediacodec_create(mediacodec_h *mediacodec);
228
229 /**
230  * @brief Destroys the mediacodec handle and releases all its resources.
231  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
232  * @remarks To completely shutdown the mediacodec operation, call this function with a valid player handle from any
233  *          mediacodec
234  *
235  * @param[in] mediacodec The handle to mediacodec to be destroyed.
236  * @return @c 0 on success, otherwise a negative error value
237  * @retval #MEDIACODEC_ERROR_NONE Successful
238  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
239  * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
240  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
241  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
242  */
243 int mediacodec_destroy(mediacodec_h mediacodec);
244
245 /**
246  * @brief Sets the codec type and decoder/encoder.
247  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
248  * @remarks If this codec is to be used as a decoder, pass the #MEDIACODEC_DECODER flag.
249  *          If this codec is to be used as an encoder, pass the #MEDIACODEC_ENCODER flag.\n
250  *          The software codec is used as default setting(#MEDIACODEC_SUPPORT_TYPE_SW) if user doesn't set hardware flag.
251  *          If user wants to use h/w decoder, user needs to pass the #MEDIACODEC_DECODER | #MEDIACODEC_SUPPORT_TYPE_HW.
252  * @param[in] mediacodec  The handle of mediacodec
253  * @param[in] codec_type  The identifier of the codec type of the decoder/encoder
254  * @param[in] flags  The encoding/decoding scheme, defined by #mediacodec_support_type_e
255  * @return @c 0 on success, otherwise a negative error value
256  * @retval #MEDIACODEC_ERROR_NONE Successful
257  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
258  * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
259  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
260  * @retval #MEDIACODEC_ERROR_CODEC_NOT_FOUND Codec not found
261  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
262  */
263 int mediacodec_set_codec(mediacodec_h mediacodec, mediacodec_codec_type_e codec_type, int flags);
264
265 /**
266  * @brief Sets the default info for the video decoder.
267  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
268  * @param[in] mediacodec The handle to mediacodec
269  * @param[in] width      The width for video decoding.
270  * @param[in] height     The height for video decoding.
271  * @return @c 0 on success, otherwise a negative error value
272  * @retval #MEDIACODEC_ERROR_NONE Successful
273  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
274  * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
275  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
276  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
277  */
278 int mediacodec_set_vdec_info(mediacodec_h mediacodec, int width, int height);
279
280 /**
281  * @brief Sets the default info for the video encoder.
282  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
283  * @remarks The frame rate is the speed of recording and the speed of playback.
284  *          If user wants the default setting for ratecontrol, set @a target_bits to @c 0.
285  * @param[in] mediacodec  The handle to mediacodec
286  * @param[in] width  The width for video encoding.
287  * @param[in] height  The height for video encoding.
288  * @param[in] fps  The frame rate in frames per second.
289  * @param[in] target_bits The target bitrates in bits per second.(a unit of kbit)
290  * @return @c 0 on success, otherwise a negative error value
291  * @retval #MEDIACODEC_ERROR_NONE Successful
292  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
293  * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
294  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
295  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
296  */
297 int mediacodec_set_venc_info(mediacodec_h mediacodec, int width, int height, int fps, int target_bits);
298
299 /**
300  * @brief Sets the default info for the audio decoder.
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 decoding.
304  * @param[in] channel    The channels for audio decoding.
305  * @param[in] bit        The bits resolution for audio decoding.
306  * @return @c 0 on success, otherwise a negative error value
307  * @retval #MEDIACODEC_ERROR_NONE Successful
308  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
309  * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
310  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
311  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
312  */
313 int mediacodec_set_adec_info(mediacodec_h mediacodec, int samplerate, int channel, int bit);
314
315 /**
316  * @brief Sets the default info for the audio encoder.
317  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
318  * @param[in] mediacodec The handle to mediacodec
319  * @param[in] samplerate The samplerate for audio encoding.
320  * @param[in] channel    The channels for audio encoding.
321  * @param[in] bit        The bits resolution for audio encoding.
322  * @param[in] bitrate  The bitrate for audio encoding.
323  * @return @c 0 on success, otherwise a negative error value
324  * @retval #MEDIACODEC_ERROR_NONE Successful
325  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
326  * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
327  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
328  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
329  */
330 int mediacodec_set_aenc_info(mediacodec_h mediacodec, int samplerate, int channel, int bit, int bitrate);
331
332 /**
333  * @brief Sets the codec type and codec default info via media format.
334  * @details Sets the value via media format instead of mediacodec_set_codec(), mediacodec_set_venc_info(),
335  *          mediacodec_set_vdec_info(), mediacodec_set_aenc_info(), and mediacodec_set_adec_info().
336  * @since_tizen 4.0
337  * @remarks When using the @a format parameter from the output of the media demuxer, you can use media format via media_packet_get_format().
338  *          Otherwise, you must set the following values after creating media format.
339  *          Set the audio or video codec type via media_format_set_video_mime() or media_format_set_audio_mime().
340  *          For video decoding, width, height must be set via media_format_set_video_width() and media_format_set_video_height().
341  *          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().
342  *          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().
343  *          For audio encoding, samplerate, channel, bit, and bitrate must be set via media_format_set_audio_avg_bps().\n
344  *          If this codec is to be used as a decoder, pass the #MEDIACODEC_DECODER flag.
345  *          If this codec is to be used as an encoder, pass the #MEDIACODEC_ENCODER flag.\n
346  *          The software codec is used as default setting (#MEDIACODEC_SUPPORT_TYPE_SW) if user doesn't set hardware flag.
347  *          If you wants to use h/w decoder, you needs to pass the #MEDIACODEC_DECODER | #MEDIACODEC_SUPPORT_TYPE_HW.
348  * @param[in] mediacodec The mediacodec handle
349  * @param[in] format     The #media_format_h of input data
350  * @param[in] flags      The encoding/decoding scheme,
351  *                       values of #mediacodec_support_type_e combined with bitwise 'or'
352  * @return @c 0 on success, otherwise a negative error value
353  * @retval #MEDIACODEC_ERROR_NONE Successful
354  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
355  * @retval #MEDIACODEC_ERROR_CODEC_NOT_FOUND Unsupported codec
356  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
357  * @pre The media format has been created and the required values for configuration have been set.
358  * @see media_format_set_video_mime()
359  * @see media_format_set_audio_mime()
360  * @see media_format_set_video_width()
361  * @see media_format_set_video_height()
362  * @see media_format_set_video_avg_bps()
363  * @see media_format_set_video_frame_rate()
364  * @see media_format_set_audio_channel()
365  * @see media_format_set_audio_samplerate()
366  * @see media_format_set_audio_bit()
367  * @see media_format_set_audio_avg_bps()
368  */
369 int mediacodec_configure_from_media_format(mediacodec_h mediacodec, media_format_h format, int flags);
370
371 /**
372  * @brief Prepares @a mediacodec for encoding/decoding.
373  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
374  * @param[in] mediacodec The handle to mediacodec
375  * @return @c 0 on success, otherwise a negative error value
376  * @retval #MEDIACODEC_ERROR_NONE Successful
377  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
378  * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
379  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
380  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
381  * @retval #MEDIACODEC_ERROR_RESOURCE_OVERLOADED Exceed the instance limits (Since 5.0)
382  * @retval #MEDIACODEC_ERROR_INTERNAL Internal error (Since 5.0)
383  * @pre The mediacodec should call mediacodec_set_codec()and mediacodec_set_vdec_info()/mediacodec_set_venc_info() before calling mediacodec_prepare()
384  *      If the decoder is set by mediacodec_set_codec(), mediacodec_set_vdec_info() should be called. If the encoder is set by
385  *      mediacodec_set_codec(), mediacodec_set_venc_info() should be called.
386  */
387 int mediacodec_prepare(mediacodec_h mediacodec);
388
389 /**
390  * @brief Unprepares @a mediacodec for encoding/decoding.
391  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
392  * @param[in] mediacodec The handle to mediacodec
393  * @return @c 0 on success, otherwise a negative error value
394  * @retval #MEDIACODEC_ERROR_NONE Successful
395  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
396  * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
397  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
398  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
399  */
400 int mediacodec_unprepare(mediacodec_h mediacodec);
401
402 /**
403  * @brief Decodes/Encodes a packet. The function passed undecoded/unencoded packet to the input queue and decode/encode a
404  *        frame sequentially.
405  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
406  * @param[in] mediacodec The handle to mediacodec
407  * @param[in] inbuf      The current input format for the decoder/encoder
408  * @param[in] timeOutUs  The timeout in microseconds. \n
409  *                       The input buffer wait up to "timeOutUs" microseconds.
410  * @return @c 0 on success, otherwise a negative error value
411  * @retval #MEDIACODEC_ERROR_NONE Successful
412  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
413  * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
414  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
415  * @retval #MEDIACODEC_ERROR_OVERFLOW_INBUFFER Overflow inputbuffer
416  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
417  */
418 int mediacodec_process_input(mediacodec_h mediacodec, media_packet_h inbuf, uint64_t timeOutUs);
419
420 /**
421  * @brief Gets the decoded or encoded packet from the output queue.
422  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
423  * @remarks The @a packet should be released using media_packet_destroy().
424  * @param[in] mediacodec The handle to mediacodec
425  * @param[out] packet    The current output of the decoder/encoder.
426  *                       this function passed decoded/encoded frame to output queue.
427  * @param[in] timeOutUs  The timeout in microseconds. \n
428  *                       The input buffer wait up to "timeOutUs" microseconds.
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  * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY Out of memory
433  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION Invalid operation
434  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
435  */
436 int mediacodec_get_output(mediacodec_h mediacodec, media_packet_h *packet, uint64_t timeOutUs);
437
438 /**
439  * @brief Flushes both input and output buffers.
440  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
441  * @param[in] mediacodec The handle to mediacodec
442  * @return @c 0 on success, otherwise a negative error value
443  * @retval #MEDIACODEC_ERROR_NONE Successful
444  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
445  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
446  */
447 int mediacodec_flush_buffers(mediacodec_h mediacodec);
448
449 /**
450  * @brief Sets empty buffer callback the media codec for process, asynchronously.
451  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
452  * @param[in] mediacodec The handle to mediacodec
453  * @param[in] callback   The callback function to register
454  * @param[in] user_data  The user data to be passed to the callback function
455  * @return @c 0 on success, otherwise a negative error value
456  * @retval #MEDIACODEC_ERROR_NONE Successful
457  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
458  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
459  * @pre mediacodec_set_input_buffer_used_cb() should be called before mediacodec_preare().
460  * @post mediacodec_input_buffer_used_cb() will be invoked.
461  * @see mediacodec_input_buffer_used_cb()
462  * @see mediacodec_unset_input_buffer_used_cb()
463  */
464 int mediacodec_set_input_buffer_used_cb(mediacodec_h mediacodec, mediacodec_input_buffer_used_cb callback, void* user_data);
465
466 /**
467  * @brief Unsets input buffer used 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  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
474  * @see mediacodec_set_input_buffer_used_cb()
475  */
476 int mediacodec_unset_input_buffer_used_cb(mediacodec_h mediacodec);
477
478 /**
479  * @brief Sets output buffer available callback the media codec for process, asynchronously.
480  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
481  * @param[in] mediacodec The handle to mediacodec
482  * @param[in] callback   The callback function to register
483  * @param[in] user_data  The user data to be passed to the callback function
484  * @return @c 0 on success, otherwise a negative error value
485  * @retval #MEDIACODEC_ERROR_NONE Successful
486  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
487  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
488  * @pre mediacodec_set_output_buffer_available_cb() should be called before mediacodec_preare().
489  * @post mediacodec_output_buffer_available_cb() will be invoked.
490  * @see mediacodec_output_buffer_available_cb()
491  * @see mediacodec_unset_output_buffer_available_cb()
492  */
493 int mediacodec_set_output_buffer_available_cb(mediacodec_h mediacodec, mediacodec_output_buffer_available_cb callback, void* user_data);
494
495 /**
496  * @brief unsets output buffer available callback the media codec for process, asynchronously.
497  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
498  * @param[in] mediacodec The handle to mediacodec
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  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
503  * @see mediacodec_set_output_buffer_available_cb()
504  */
505 int mediacodec_unset_output_buffer_available_cb(mediacodec_h mediacodec);
506
507 /**
508  * @brief Sets error callback the media codec for process, asynchronously.
509  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
510  * @param[in] mediacodec The handle to mediacodec
511  * @param[in] callback   The callback function to register
512  * @param[in] user_data  The user data to be passed to the callback function
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
516  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
517  * @pre mediacodec_set_error_cb() should be called before mediacodec_preare().
518  * @post mediacodec_error_cb() will be invoked.
519  * @see mediacodec_error_cb()
520  * @see mediacodec_unset_error_cb()
521  */
522 int mediacodec_set_error_cb(mediacodec_h mediacodec, mediacodec_error_cb callback, void* user_data);
523
524 /**
525  * @brief Unsets error callback the media codec for process, asynchronously.
526  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
527  * @param[in] mediacodec The handle to mediacodec
528  * @return @c 0 on success, otherwise a negative error value
529  * @retval #MEDIACODEC_ERROR_NONE Successful
530  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
531  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
532  * @see mediacodec_set_error_cb()
533  */
534 int mediacodec_unset_error_cb(mediacodec_h mediacodec);
535
536 /**
537  * @brief Sets eos callback the media codec for process, asynchronously.
538  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
539  * @param[in] mediacodec The handle to mediacodec
540  * @param[in] callback   The callback function to register
541  * @param[in] user_data  The user data to be passed to the callback function
542  * @return @c 0 on success, otherwise a negative error value
543  * @retval #MEDIACODEC_ERROR_NONE Successful
544  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
545  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
546  * @pre mediacodec_set_eos_cb() should be called before mediacodec_preare().
547  * @post mediacodec_eos_cb() will be invoked.
548  * @see mediacodec_eos_cb()
549  * @see mediacodec_unset_eos_cb()
550  */
551 int mediacodec_set_eos_cb(mediacodec_h mediacodec, mediacodec_eos_cb callback, void* user_data);
552
553 /**
554  * @brief unsets eos callback the media codec for process, asynchronously.
555  * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif
556  * @param[in] mediacodec The handle to mediacodec
557  * @return @c 0 on success, otherwise a negative error value
558  * @retval #MEDIACODEC_ERROR_NONE Successful
559  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
560  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
561  * @see mediacodec_set_eos_cb()
562  */
563 int mediacodec_unset_eos_cb(mediacodec_h mediacodec);
564
565 /**
566  * @brief Sets a callback function to be invoked when the mediacodec needs more data or has enough data.
567  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
568  * @param[in] mediacodec The handle to mediacodec
569  * @param[in] callback   The callback function to register
570  * @param[in] user_data  The user data to be passed to the callback function
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_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
575  * @pre mediacodec_set_buffer_status_cb() should be called before mediacodec_preare().
576  * @post mediacodec_buffer_status_cb() will be invoked.
577  * @see mediacodec_buffer_status_cb()
578  * @see mediacodec_unset_buffer_status_cb()
579  */
580 int mediacodec_set_buffer_status_cb(mediacodec_h mediacodec, mediacodec_buffer_status_cb callback, void* user_data);
581
582 /**
583  * @brief Unsets the callback function.
584  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
585  * @param[in] mediacodec The handle to mediacodec
586  * @return @c 0 on success, otherwise a negative error value
587  * @retval #MEDIACODEC_ERROR_NONE Successful
588  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
589  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
590  * @see mediacodec_set_buffer_status_cb()
591  */
592 int mediacodec_unset_buffer_status_cb(mediacodec_h mediacodec);
593
594 /**
595  * @brief Retrieves all supported codecs by invoking callback function once for each supported codecs.
596  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
597  * @param[in] mediacodec The handle to mediacodec
598  * @param[in] callback   The callback function to invoke
599  * @param[in] user_data  The user data to be passed to the callback function
600  * @return @c 0 on success, otherwise a negative error value
601  * @retval #MEDIACODEC_ERROR_NONE Successful
602  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
603  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
604  * @see mediacodec_supported_codec_cb()
605  */
606 int mediacodec_foreach_supported_codec(mediacodec_h mediacodec, mediacodec_supported_codec_cb callback, void *user_data);
607
608 /**
609  * @brief Verifies whether encoding can be performed with codec_type or not.
610  * @since_tizen @if MOBILE 2.4 @elseif WEARABLE 3.0 @endif
611  * @param[in]  mediacodec   The handle to mediacodec
612  * @param[in]  codec_type   The identifier of the codec type of the encoder.
613  * @param[in]  encoder      Whether the encoder or decoder : (@c true = encoder, @c false = decoder).
614  * @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)
615  * @return @c 0 on success, otherwise a negative error value
616  * @retval #MEDIACODEC_ERROR_NONE Successful
617  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
618  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
619  @code
620  #include <media_codec.h>
621  mediacodec_h mediacodec;
622  mediacodec_support_type_e type;
623  mediacodec_codec_type_e codec_type = MEDIACODEC_H264;
624
625  mediacodec_create(&mediacodec);
626  mediacodec_get_supported_type(mediacodec, codec_type, 1, &type);
627
628  if(type == MEDIACODEC_SUPPORT_TYPE_HW)
629      // only h/w supported
630  else if (type == MEDIACODEC_SUPPORT_TYPE_SW)
631      // only s/w supported
632  else if (type == (MEDIACODEC_SUPPORT_TYPE_HW|MEDIACODEC_SUPPORT_TYPE_SW)
633      // both supported
634
635  mediacodec_set_codec(mediacodec, codec_type, MEDIACODEC_ENCODER | MEDIACODEC_SUPPORT_TYPE_HW);
636  @endcode
637  */
638 int mediacodec_get_supported_type(mediacodec_h mediacodec, mediacodec_codec_type_e codec_type, bool encoder, int *support_type);
639
640 /**
641  * @brief Gets the media packet pool allocated for recycling media packets.
642  * @details The user can get the pool allocated with the number of packets are required to be used in codecs.\n
643  *          It is recommended to use media packet pool for better stability and performance.
644  * @since_tizen 3.0
645  * @remarks The @a pool should be released using media_packet_pool_deallocate() and destroyed using media_packet_pool_destroy().
646  * @param[in]  mediacodec The mediacodec handle
647  * @param[out] pool       The allocated pool handle
648  * @return @c 0 on success, otherwise a negative error value
649  * @retval #MEDIACODEC_ERROR_NONE Successful
650  * @retval #MEDIACODEC_ERROR_INVALID_PARAMETER Invalid parameter
651  * @retval #MEDIACODEC_ERROR_OUT_OF_MEMORY  Out of memory
652  * @retval #MEDIACODEC_ERROR_INVALID_OPERATION The user calls mediacodec_get_packet_pool() before calling mediacodec_prepare().
653  * @retval #MEDIACODEC_ERROR_NOT_SUPPORTED_ON_DEVICE Not supported on device (Since 4.0)
654  * @pre mediacodec_get_packet_pool() should be called after calling mediacodec_prepare().
655  * @post If the pool is used, media_packet_pool_deallocate() and media_packet_pool_destroy() should be called.
656  * @see media_packet_pool_acquire_packet()
657  * @see media_packet_pool_release_packet()
658  * @see media_packet_pool_deallocate()
659  * @see media_packet_pool_destroy()
660  */
661 int mediacodec_get_packet_pool(mediacodec_h mediacodec, media_packet_pool_h *pool);
662
663 /**
664  * @}
665  */
666
667 #ifdef __cplusplus
668 }
669 #endif
670
671 #endif /* __TIZEN_MEDIA_CODEC_H__ */
672