modify to create caps
[platform/core/api/mediacodec.git] / include / media_codec_port_gst.h
1
2 /*
3 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 #ifndef __TIZEN_MEDIA_CODEC_PORT_GST_H__
19 #define __TIZEN_MEDIA_CODEC_PORT_GST_H__
20
21 #include <unistd.h>
22 #include <tizen.h>
23 #include <media_codec.h>
24 #include <media_codec_private.h>
25 #include <media_codec_port.h>
26 #include <media_codec_bitstream.h>
27
28 #include <tbm_type.h>
29 #include <tbm_surface.h>
30 #include <tbm_bufmgr.h>
31 #include <tbm_surface_internal.h>
32 #include <gst/video/video-format.h>
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 #define GST_INIT_STRUCTURE(param) \
39         memset(&(param), 0, sizeof(param));
40
41 #define MEDIACODEC_ELEMENT_SET_STATE(x_element, x_state)                                          \
42         do {                                                                                            \
43                 LOGD("setting state [%s:%d] to [%s]\n", #x_state, x_state, GST_ELEMENT_NAME(x_element)); \
44                 if (GST_STATE_CHANGE_FAILURE == gst_element_set_state(x_element, x_state)) {                    \
45                         LOGE("failed to set state %s to %s\n", #x_state, GST_ELEMENT_NAME(x_element));        \
46                         goto STATE_CHANGE_FAILED;                                                               \
47                 }                                                                                           \
48         } while (0)
49
50 #define SCMN_IMGB_MAX_PLANE 4
51 #define TBM_API_CHANGE
52 #define DEFAULT_POOL_SIZE 20
53 #define AAC_CODECDATA_SIZE      16
54 #define WMA_CODECDATA_SIZE      64
55 #define VORBIS_CODECDATA_SIZE   4096
56
57 /* gst port layer */
58 typedef struct _mc_gst_port_t mc_gst_port_t;
59 typedef struct _mc_gst_core_t mc_gst_core_t;
60 typedef struct _GstMCBuffer GstMCBuffer;
61
62 typedef enum {
63         BUF_SHARE_METHOD_PADDR = 0,
64         BUF_SHARE_METHOD_FD,
65         BUF_SHARE_METHOD_TIZEN_BUFFER,
66         BUF_SHARE_METHOD_FLUSH_BUFFER
67 } buf_share_method_t;
68
69 #ifdef TIZEN_PROFILE_LITE
70 struct ion_mmu_data {
71         int master_id;
72         int fd_buffer;
73         unsigned long iova_addr;
74         size_t iova_size;
75 };
76 #endif
77
78 struct _mc_gst_port_t {
79         mc_gst_core_t *core;
80         unsigned int num_buffers;
81         unsigned int buffer_size;
82         unsigned int index;
83         bool is_allocated;
84         media_packet_h *buffers;
85         GQueue *queue;
86         GMutex mutex;
87         GCond buffer_cond;
88 };
89
90 struct _mc_gst_core_t {
91         int(**vtable)();
92         const char *mime;
93         gchar *format;
94         GstElement *pipeline;
95         GstElement *appsrc;
96         GstElement *capsfilter;
97         GstElement *parser;
98         GstElement *fakesink;
99         GstElement *codec;
100         GstCaps *caps;
101         tbm_bufmgr bufmgr;
102         int drm_fd;
103
104         GMainContext *thread_default;
105         gulong signal_handoff;
106         gint bus_whatch_id;
107         gint probe_id;
108
109         GMutex eos_mutex;
110         GMutex eos_wait_mutex;
111         GMutex prepare_lock;
112         GMutex drain_lock;
113         GCond eos_cond;
114         GCond eos_waiting_cond;
115
116         bool output_allocated;
117         bool encoder;
118         bool video;
119         bool is_hw;
120         bool eos;
121         bool eos_waiting;
122         bool codec_config;
123         bool need_feed;
124         bool need_codec_data;
125         bool need_sync_flag;
126         bool unprepare_flag;
127         unsigned int prepare_count;
128         unsigned int num_live_buffers;
129         unsigned int etb_count;
130         unsigned int ftb_count;
131
132         mediacodec_codec_type_e codec_id;
133         media_format_mimetype_e out_mime;
134         media_format_h output_fmt;
135         mc_gst_port_t *ports[2];
136         mc_bitstream_t bits;
137
138         mc_aqueue_t *available_queue;
139         GQueue *output_queue;
140
141         void *codec_info;
142
143         void* user_cb[_MEDIACODEC_EVENT_TYPE_NUM];
144         void* user_data[_MEDIACODEC_EVENT_TYPE_NUM];
145 };
146
147 struct _GstMCBuffer {
148         GstBuffer *buffer;
149         int buf_size;
150         mc_gst_core_t* core;
151         media_packet_h pkt;
152         bool has_imgb;
153 };
154
155 enum { fill_inbuf, fill_outbuf };
156
157 int __mc_fill_input_buffer(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *buff);
158 int __mc_fill_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt);
159
160 int __mc_fill_input_buffer_with_packet(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *buff);
161 int __mc_fill_input_buffer_with_venc_packet(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *mc_buffer);
162
163 int __mc_fill_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt);
164 int __mc_fill_venc_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt);
165 int __mc_fill_vdec_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *pkt);
166
167 mc_gst_core_t *mc_gst_core_new();
168 void mc_gst_core_free(mc_gst_core_t *core);
169
170 mc_gst_port_t *mc_gst_port_new(mc_gst_core_t *core);
171 void mc_gst_port_free(mc_gst_port_t *port);
172
173 mc_ret_e mc_gst_prepare(mc_handle_t *mc_handle);
174 mc_ret_e mc_gst_unprepare(mc_handle_t *mc_handle);
175
176 mc_ret_e mc_gst_process_input(mc_handle_t *mc_handle, media_packet_h inbuf, uint64_t timeOutUs);
177 mc_ret_e mc_gst_get_output(mc_handle_t *mc_handle, media_packet_h *outbuf, uint64_t timeOutUs);
178
179 mc_ret_e mc_gst_flush_buffers(mc_handle_t *mc_handle);
180
181 mc_ret_e mc_gst_get_packet_pool(mc_handle_t *mc_handle, media_packet_pool_h *pkt_pool);
182
183 #ifdef __cplusplus
184 }
185 #endif
186
187 #endif /* __TIZEN_MEDIA_CODEC_PORT_GST_H__ */