Sync with tizen_2.4
[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
30
31 /*===========================================================================================
32 |                                                                                                                                                                                      |
33 |  GLOBAL DEFINITIONS AND DECLARATIONS FOR MODULE                                                                                      |
34 |                                                                                                                                                                                      |
35 ========================================================================================== */
36
37 /*---------------------------------------------------------------------------
38 |    GLOBAL #defines:                                                                                                                    |
39 ---------------------------------------------------------------------------*/
40 #define CHECK_BIT(x, y) (((x) >> (y)) & 0x01)
41 #define GET_IS_ENCODER(x) CHECK_BIT(x, 0)
42 #define GET_IS_DECODER(x) CHECK_BIT(x, 1)
43 #define GET_IS_HW(x) CHECK_BIT(x, 2)
44 #define GET_IS_SW(x) CHECK_BIT(x, 3)
45
46 //#define GET_IS_OMX(x) CHECK_BIT(x, 4)
47 //#define GET_IS_GEN(x) CHECK_BIT(x, 5)
48
49 #if 1
50 #define MEDIACODEC_FENTER();
51 #define MEDIACODEC_FLEAVE();
52 #else
53 #define MEDIACODEC_FENTER();          LOGW("%s Enter",__FUNCTION__);
54 #define MEDIACODEC_FLEAVE();          LOGW("%s Exit",__FUNCTION__);
55 #endif
56
57 /*---------------------------------------------------------------------------
58 |    GLOBAL CONSTANT DEFINITIONS:                                                                                          |
59 ---------------------------------------------------------------------------*/
60 /**
61  * @brief Enumerations of media codec port's retrun value
62  */
63 typedef enum
64 {
65     MC_ERROR_NONE               =    0,
66     MC_ERROR                    =   -1,     /**< codec happens error */
67     MC_MEMORY_ERROR             =   -2,     /**< codec memory is not enough */
68     MC_PARAM_ERROR              =   -3,     /**< codec parameter is error */
69     MC_INVALID_ARG              =   -4,     /** < codec has invalid arguments */
70     MC_PERMISSION_DENIED        =   -5,
71     MC_INVALID_STATUS           =   -6,     /**< codec works at invalid status */
72     MC_NOT_SUPPORTED            =   -7,     /**< codec can't support this specific video format */
73     MC_INVALID_IN_BUF           =   -8,
74     MC_INVALID_OUT_BUF          =   -9,
75     MC_INTERNAL_ERROR           =   -10,
76     MC_HW_ERROR                 =   -11,    /**< codec happens hardware error */
77     MC_NOT_INITIALIZED          =   -12,
78     MC_INVALID_STREAM           =   -13,
79     MC_CODEC_NOT_FOUND          =   -14,
80     MC_ERROR_DECODE             =   -15,
81     MC_OUTPUT_BUFFER_EMPTY      =   -16,
82     MC_OUTPUT_BUFFER_OVERFLOW   =   -17,    /**< codec output buffer is overflow */
83     MC_MEMORY_ALLOCED           =   -18,    /**< codec has got memory and can decode one frame */
84 } mc_ret_e;
85
86 /*---------------------------------------------------------------------------
87 |    GLOBAL DATA TYPE DEFINITIONS:                                                                                         |
88 ---------------------------------------------------------------------------*/
89 /**
90  * @brief Called when the dequeue input buffer done
91  * @details It will be invoked when mediacodec has released dequeue buffer.
92  * @param[in]   user_data  The user data passed from the callback registration function
93  * @pre It will be invoked when dequeue buffer process completed if you register this callback using mediacodec_set_dequeue_input_buffer_cb().
94  * @see mediacodec_set_dequeue_input_buffer_cb()
95  * @see mediacodec_unset_dequeue_input_buffer_cb()
96  */
97
98
99 typedef struct _mc_decoder_info_t mc_decoder_info_t;
100 typedef struct _mc_encoder_info_t mc_encoder_info_t;
101 typedef struct _mc_handle_t mc_handle_t;
102
103 #define MEDIACODEC_CMD_LOCK(x_mediacodec) g_mutex_lock(&((mc_handle_t*)x_mediacodec)->cmd_lock )
104 #define MEDIACODEC_CMD_UNLOCK(x_mediacodec) g_mutex_unlock( &((mc_handle_t*)x_mediacodec)->cmd_lock )
105
106 typedef void (*mc_dequeue_input_buffer_cb)(media_packet_h pkt, void *user_data);
107 typedef void (*mc_empty_buffer_cb)(media_packet_h pkt, void *user_data);
108 typedef void (*mc_fill_buffer_cb)(media_packet_h pkt, void *user_data);
109 typedef void (*mc_error_cb)(mediacodec_error_e error, void *user_data);
110 typedef void (*mc_eos_cb)(void *user_data);
111 typedef void (*mc_buffer_status_cb)(mediacodec_status_e status, void *user_data);
112 typedef void (*mc_supported_codec_cb)(mediacodec_codec_type_e codec_type, void *user_data);
113
114 int (*mc_sniff_bitstream)(mc_handle_t *handle, media_packet_h pkt);
115
116 int mc_sniff_h264_bitstream(mc_handle_t *handle, media_packet_h pkt);
117 int mc_sniff_mpeg4_bitstream(mc_handle_t *handle, media_packet_h pkt);
118 int mc_sniff_h263_bitstream(mc_handle_t *handle, media_packet_h pkt);
119 int mc_sniff_yuv(mc_handle_t *handle, media_packet_h pkt);
120
121 typedef enum {
122     _MEDIACODEC_EVENT_TYPE_COMPLETE,
123     _MEDIACODEC_EVENT_TYPE_EMPTYBUFFER,
124     _MEDIACODEC_EVENT_TYPE_FILLBUFFER,
125     _MEDIACODEC_EVENT_TYPE_ERROR,
126     _MEDIACODEC_EVENT_TYPE_EOS,
127     _MEDIACODEC_EVENT_TYPE_BUFFER_STATUS,
128     _MEDIACODEC_EVENT_TYPE_INTERNAL_FILLBUFFER,
129     _MEDIACODEC_EVENT_TYPE_SUPPORTED_CODEC,
130     _MEDIACODEC_EVENT_TYPE_NUM
131 } _mediacodec_event_e;
132
133
134 typedef enum _mc_codec_port_type_e
135 {
136         CODEC_PORT_TYPE_GENERAL,
137         CODEC_PORT_TYPE_OMX,
138         CODEC_PORT_TYPE_GST,
139         CODEC_PORT_TYPE_MAX,
140 } mc_codec_port_type_e;
141
142 typedef enum _mc_vendor_e
143 {
144     MC_VENDOR_DEFAULT,
145     MC_VENDOR_SLSI_SEC,
146     MC_VENDOR_SLSI_EXYNOS,
147     MC_VENDOR_QCT,
148     MC_VENDOR_SPRD
149 } mc_vendor_e;
150
151 struct _mc_decoder_info_t
152 {
153     int width;
154     int height;
155     int actwidth;
156     int actheight;
157
158     int samplerate;
159     int channel;
160     int bit;
161 };
162
163 struct _mc_encoder_info_t
164 {
165     int width;
166     int height;
167     int bitrate;
168     int format;
169     int fps;
170     int qp_min;
171     int qp_max;
172     int vbvbuffer_size;
173     int level;
174     int profile;
175
176     int samplerate;
177     int channel;
178     int bit;
179 };
180
181 /* Codec Private data */
182 struct _mc_handle_t
183 {
184     int state;                                  /**<  mc current state */
185     bool is_encoder;
186     bool is_video;
187     bool is_hw;
188     bool is_prepared;
189
190     GList *supported_codecs;
191     GMutex cmd_lock;
192     mediacodec_port_type_e port_type;
193     mediacodec_codec_type_e codec_id;
194     mc_vendor_e vendor;
195
196     void *ports[2];
197     void *core;
198
199     union
200     {
201         mc_decoder_info_t decoder;
202         mc_encoder_info_t encoder;
203     } info;
204
205     /* for process done cb */
206     void* user_cb[_MEDIACODEC_EVENT_TYPE_NUM];
207     void* user_data[_MEDIACODEC_EVENT_TYPE_NUM];
208
209 };
210
211 /*===========================================================================================
212 |                                                                                                                                                                                      |
213 |  GLOBAL FUNCTION PROTOTYPES                                                                                                                            |
214 |                                                                                                                                                                                      |
215 ========================================================================================== */
216
217 #ifdef __cplusplus
218 extern "C" {
219 #endif
220
221 int mc_create(MMHandleType *mediacodec);
222 int mc_destroy(MMHandleType mediacodec);
223
224 int mc_set_codec(MMHandleType mediacodec, mediacodec_codec_type_e codec_id, mediacodec_support_type_e flags);
225
226 int mc_set_vdec_info(MMHandleType mediacodec, int width, int height);
227 int mc_set_venc_info(MMHandleType mediacodec, int width, int height, int fps, int target_bits);
228
229 int mc_set_adec_info(MMHandleType mediacodec, int samplerate, int channel, int bit);
230 int mc_set_aenc_info(MMHandleType mediacodec, int samplerate, int channel, int bit,  int bitrate);
231
232 int mc_prepare(MMHandleType mediacodec);
233 int mc_unprepare(MMHandleType mediacodec);
234
235 int mc_process_input(MMHandleType mediacodec, media_packet_h inbuf, uint64_t timeOutUs);
236 int mc_get_output(MMHandleType mediacodec, media_packet_h *outbuf, uint64_t timeOutUs);
237
238 int mc_flush_buffers(MMHandleType mediacodec);
239 int mc_get_supported_type(MMHandleType mediacodec, mediacodec_codec_type_e codec_type, bool encoder, int *support_type);
240
241 int mc_set_empty_buffer_cb(MMHandleType mediacodec, mediacodec_input_buffer_used_cb callback, void* user_data);
242 int mc_unset_empty_buffer_cb(MMHandleType mediacodec);
243
244 int mc_set_fill_buffer_cb(MMHandleType mediacodec, mediacodec_output_buffer_available_cb callback, void* user_data);
245 int mc_unset_fill_buffer_cb(MMHandleType mediacodec);
246
247 int mc_set_error_cb(MMHandleType mediacodec, mediacodec_error_cb callback, void* user_data);
248 int mc_unset_error_cb(MMHandleType mediacodec);
249
250 int mc_set_eos_cb(MMHandleType mediacodec, mediacodec_eos_cb callback, void* user_data);
251 int mc_unset_eos_cb(MMHandleType mediacodec);
252
253 int mc_set_need_data_cb(MMHandleType mediacodec, mediacodec_buffer_status_cb callback, void* user_data);
254 int mc_unset_need_data_cb(MMHandleType mediacodec);
255
256
257 #ifdef __cplusplus
258 }
259 #endif
260
261 #endif /* __TIZEN_MEDIA_CODEC_PORT_H__ */