removed unused code
[platform/core/api/mediacodec.git] / include / media_codec_port.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_PORT_H__
18 #define __TIZEN_MEDIA_CODEC_PORT_H__
19
20 #include <tizen.h>
21 #include <glib.h>
22 #include <dlfcn.h>
23 #include <gst/gst.h>
24
25 #include <media_codec.h>
26 #include <media_codec_queue.h>
27 #include <media_codec_bitstream.h>
28 #include <media_codec_spec_emul.h>
29 #include <media_codec_ini.h>
30
31
32 /*===========================================================================================
33 |                                                                                                                                                                                      |
34 |  GLOBAL DEFINITIONS AND DECLARATIONS FOR MODULE                                                                                      |
35 |                                                                                                                                                                                      |
36 ========================================================================================== */
37
38 /*---------------------------------------------------------------------------
39 |    GLOBAL #defines:                                                                                                                    |
40 ---------------------------------------------------------------------------*/
41 #define CHECK_BIT(x, y) (((x) >> (y)) & 0x01)
42 #define GET_IS_ENCODER(x) CHECK_BIT(x, 0)
43 #define GET_IS_DECODER(x) CHECK_BIT(x, 1)
44 #define GET_IS_HW(x) CHECK_BIT(x, 2)
45 #define GET_IS_SW(x) CHECK_BIT(x, 3)
46 /*
47 #define GET_IS_OMX(x) CHECK_BIT(x, 4)
48 #define GET_IS_GEN(x) CHECK_BIT(x, 5)
49 */
50
51 #if 1
52 #define MEDIACODEC_FENTER();
53 #define MEDIACODEC_FLEAVE();
54 #else
55 #define MEDIACODEC_FENTER();    LOGW("%s Enter", __FUNCTION__);
56 #define MEDIACODEC_FLEAVE();    LOGW("%s Exit", __FUNCTION__);
57 #endif
58
59 /*---------------------------------------------------------------------------
60 |    GLOBAL CONSTANT DEFINITIONS:                                                                                          |
61 ---------------------------------------------------------------------------*/
62 /**
63  * @brief Enumerations of media codec port's retrun value
64  */
65 typedef enum {
66         MC_ERROR_NONE               =    0,
67         MC_ERROR                    =   -1,     /**< codec happens error */
68         MC_MEMORY_ERROR             =   -2,     /**< codec memory is not enough */
69         MC_PARAM_ERROR              =   -3,     /**< codec parameter is error */
70         MC_INVALID_ARG              =   -4,     /** < codec has invalid arguments */
71         MC_PERMISSION_DENIED        =   -5,
72         MC_INVALID_STATUS           =   -6,     /**< codec works at invalid status */
73         MC_NOT_SUPPORTED            =   -7,     /**< codec can't support this specific video format */
74         MC_INVALID_IN_BUF           =   -8,
75         MC_INVALID_OUT_BUF          =   -9,
76         MC_INTERNAL_ERROR           =   -10,
77         MC_HW_ERROR                 =   -11,    /**< codec happens hardware error */
78         MC_NOT_INITIALIZED          =   -12,
79         MC_INVALID_STREAM           =   -13,
80         MC_CODEC_NOT_FOUND          =   -14,
81         MC_ERROR_DECODE             =   -15,
82         MC_OUTPUT_BUFFER_EMPTY      =   -16,
83         MC_OUTPUT_BUFFER_OVERFLOW   =   -17,    /**< codec output buffer is overflow */
84         MC_MEMORY_ALLOCED           =   -18,    /**< codec has got memory and can decode one frame */
85         MC_COURRPTED_INI            =   -19,
86         MC_OUT_OF_MEMORY                        =       -20,    /**< when memory is not allocated */
87 } mc_ret_e;
88
89 typedef enum {
90         NONE,
91         L16,
92         ALAW,
93         ULAW,
94         AMR_NB,
95         AMR_WB,
96         G729,
97         AAC_LC,
98         AAC_HE,
99         AAC_HE_PS,
100         MP3,
101         VORBIS,
102         FLAC,
103         WMAV1,
104         WMAV2,
105         WMAPRO,
106         WMALSL,
107         H261,
108         H263,
109         H264,
110         MJPEG,
111         MPEG1,
112         MPEG2,
113         MPEG4,
114         HEVC,
115         VP8,
116         VP9,
117         VC1,
118         CODEC_NR_ITEMS
119 } codec_type_e;
120
121 /*---------------------------------------------------------------------------
122 |    GLOBAL DATA TYPE DEFINITIONS:                                                                                         |
123 ---------------------------------------------------------------------------*/
124 /**
125  * @brief Called when the dequeue input buffer done
126  * @details It will be invoked when mediacodec has released dequeue buffer.
127  * @param[in]   user_data  The user data passed from the callback registration function
128  * @pre It will be invoked when dequeue buffer process completed if you register this callback using mediacodec_set_dequeue_input_buffer_cb().
129  * @see mediacodec_set_dequeue_input_buffer_cb()
130  * @see mediacodec_unset_dequeue_input_buffer_cb()
131  */
132
133
134 typedef struct _mc_decoder_info_t mc_decoder_info_t;
135 typedef struct _mc_encoder_info_t mc_encoder_info_t;
136 typedef struct _mc_handle_t mc_handle_t;
137
138 typedef void (*mc_dequeue_input_buffer_cb)(media_packet_h pkt, void *user_data);
139 typedef void (*mc_empty_buffer_cb)(media_packet_h pkt, void *user_data);
140 typedef void (*mc_fill_buffer_cb)(media_packet_h pkt, void *user_data);
141 typedef void (*mc_error_cb)(mediacodec_error_e error, void *user_data);
142 typedef void (*mc_eos_cb)(void *user_data);
143 typedef void (*mc_buffer_status_cb)(mediacodec_status_e status, void *user_data);
144 typedef void (*mc_supported_codec_cb)(mediacodec_codec_type_e codec_type, void *user_data);
145
146 typedef enum {
147         _MEDIACODEC_EVENT_TYPE_COMPLETE,
148         _MEDIACODEC_EVENT_TYPE_EMPTYBUFFER,
149         _MEDIACODEC_EVENT_TYPE_FILLBUFFER,
150         _MEDIACODEC_EVENT_TYPE_ERROR,
151         _MEDIACODEC_EVENT_TYPE_EOS,
152         _MEDIACODEC_EVENT_TYPE_BUFFER_STATUS,
153         _MEDIACODEC_EVENT_TYPE_INTERNAL_FILLBUFFER,
154         _MEDIACODEC_EVENT_TYPE_SUPPORTED_CODEC,
155         _MEDIACODEC_EVENT_TYPE_NUM
156 } _mediacodec_event_e;
157
158
159 typedef enum _mc_codec_port_type_e {
160         CODEC_PORT_TYPE_GENERAL,
161         CODEC_PORT_TYPE_OMX,
162         CODEC_PORT_TYPE_GST,
163         CODEC_PORT_TYPE_MAX,
164 } mc_codec_port_type_e;
165
166 typedef enum _mc_vendor_e {
167         MC_VENDOR_DEFAULT,
168         MC_VENDOR_SLSI_SEC,
169         MC_VENDOR_SLSI_EXYNOS,
170         MC_VENDOR_QCT,
171         MC_VENDOR_SPRD
172 } mc_vendor_e;
173
174 struct _mc_decoder_info_t {
175         int width;
176         int height;
177         int actwidth;
178         int actheight;
179
180         int samplerate;
181         int channel;
182         int bit;
183 };
184
185 struct _mc_encoder_info_t {
186         int width;
187         int height;
188         int bitrate;
189         int format;
190         int fps;
191         int qp_min;
192         int qp_max;
193         int vbvbuffer_size;
194         int level;
195         int profile;
196
197         int samplerate;
198         int channel;
199         int bit;
200 };
201
202 /* Codec Private data */
203 struct _mc_handle_t {
204         int state;                                  /**<  mc current state */
205         bool is_encoder;
206         bool is_video;
207         bool is_hw;
208         bool is_prepared;
209
210         mediacodec_port_type_e port_type;
211         mediacodec_codec_type_e codec_id;
212         mc_vendor_e vendor;
213
214         void *ports[2];
215         void *core;
216
217         union {
218                 mc_decoder_info_t decoder;
219                 mc_encoder_info_t encoder;
220         } info;
221
222         /* for process done cb */
223         void* user_cb[_MEDIACODEC_EVENT_TYPE_NUM];
224         void* user_data[_MEDIACODEC_EVENT_TYPE_NUM];
225
226         mc_codec_map_t encoder_map[MEDIA_CODEC_MAX_CODEC_TYPE];
227         mc_codec_map_t decoder_map[MEDIA_CODEC_MAX_CODEC_TYPE];
228
229         int num_supported_decoder;
230         int num_supported_encoder;
231
232         mc_ini_t *ini;
233 };
234
235 /*===========================================================================================
236 |                                                                                                                                                                                      |
237 |  GLOBAL FUNCTION PROTOTYPES                                                                                                                            |
238 |                                                                                                                                                                                      |
239 ========================================================================================== */
240
241 #ifdef __cplusplus
242 extern "C" {
243 #endif
244
245 int mc_create(MMHandleType *mediacodec);
246 int mc_destroy(MMHandleType mediacodec);
247
248 int mc_set_codec(MMHandleType mediacodec, mediacodec_codec_type_e codec_id, int flags);
249
250 int mc_set_vdec_info(MMHandleType mediacodec, int width, int height);
251 int mc_set_venc_info(MMHandleType mediacodec, int width, int height, int fps, int target_bits);
252
253 int mc_set_adec_info(MMHandleType mediacodec, int samplerate, int channel, int bit);
254 int mc_set_aenc_info(MMHandleType mediacodec, int samplerate, int channel, int bit,  int bitrate);
255
256 int mc_prepare(MMHandleType mediacodec);
257 int mc_unprepare(MMHandleType mediacodec);
258
259 int mc_process_input(MMHandleType mediacodec, media_packet_h inbuf, uint64_t timeOutUs);
260 int mc_get_output(MMHandleType mediacodec, media_packet_h *outbuf, uint64_t timeOutUs);
261
262 int mc_flush_buffers(MMHandleType mediacodec);
263 int mc_get_supported_type(MMHandleType mediacodec, mediacodec_codec_type_e codec_type, bool encoder, int *support_type);
264
265 int mc_get_packet_pool(MMHandleType mediacodec, media_packet_pool_h *pool);
266
267 int mc_set_empty_buffer_cb(MMHandleType mediacodec, mediacodec_input_buffer_used_cb callback, void* user_data);
268 int mc_unset_empty_buffer_cb(MMHandleType mediacodec);
269
270 int mc_set_fill_buffer_cb(MMHandleType mediacodec, mediacodec_output_buffer_available_cb callback, void* user_data);
271 int mc_unset_fill_buffer_cb(MMHandleType mediacodec);
272
273 int mc_set_error_cb(MMHandleType mediacodec, mediacodec_error_cb callback, void* user_data);
274 int mc_unset_error_cb(MMHandleType mediacodec);
275
276 int mc_set_eos_cb(MMHandleType mediacodec, mediacodec_eos_cb callback, void* user_data);
277 int mc_unset_eos_cb(MMHandleType mediacodec);
278
279 int mc_set_buffer_status_cb(MMHandleType mediacodec, mediacodec_buffer_status_cb callback, void* user_data);
280 int mc_unset_buffer_status_cb(MMHandleType mediacodec);
281 int mc_set_supported_codec_cb(MMHandleType mediacodec, mediacodec_supported_codec_cb callback, void* user_data);
282 int _mediacodec_foreach_supported_codec(mediacodec_supported_codec_cb callback, void* user_data);
283
284 void _mc_create_codec_map_from_ini(mc_handle_t *mc_handle, mc_codec_spec_t *spec_emul);
285 void _mc_create_codec_map_from_ini_static(mc_ini_t *ini, mc_codec_spec_t *spec_emul);
286 void _mc_create_decoder_map_from_ini(mc_handle_t *mc_handle);
287 void _mc_create_encoder_map_from_ini(mc_handle_t *mc_handle);
288
289 const int simple_to_codec_type_enumeration(codec_type_e codec_id);
290 const int codec_type_to_simple_enumeration(mediacodec_codec_type_e media_codec_id);
291
292 #ifdef __cplusplus
293 }
294 #endif
295
296 #endif /* __TIZEN_MEDIA_CODEC_PORT_H__ */