3 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #ifndef __TIZEN_MEDIA_CODEC_PORT_GST_H__
19 #define __TIZEN_MEDIA_CODEC_PORT_GST_H__
23 #include <media_codec.h>
24 #include <media_codec_private.h>
25 #include <media_codec_port.h>
26 #include <media_codec_bitstream.h>
29 #include <tbm_surface.h>
30 #include <tbm_bufmgr.h>
31 #include <tbm_surface_internal.h>
32 #include <gst/video/video-format.h>
38 #define GST_INIT_STRUCTURE(param) \
39 memset(&(param), 0, sizeof(param));
41 #define MEDIACODEC_ELEMENT_SET_STATE( x_element, x_state ) \
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) ) \
46 LOGE("failed to set state %s to %s\n", #x_state, GST_ELEMENT_NAME( x_element )); \
47 goto STATE_CHANGE_FAILED; \
51 #define SCMN_IMGB_MAX_PLANE 4
52 #define TBM_API_CHANGE
53 #define DEFAULT_POOL_SIZE 20
56 typedef struct _mc_gst_port_t mc_gst_port_t;
57 typedef struct _mc_gst_core_t mc_gst_core_t;
58 typedef struct _GstMCBuffer GstMCBuffer;
61 BUF_SHARE_METHOD_PADDR = 0,
63 BUF_SHARE_METHOD_TIZEN_BUFFER,
64 BUF_SHARE_METHOD_FLUSH_BUFFER
67 #ifdef TIZEN_PROFILE_LITE
71 unsigned long iova_addr;
79 unsigned int num_buffers;
80 unsigned int buffer_size;
83 media_packet_h *buffers;
96 GstElement* capsfilter;
103 GMainContext *thread_default;
104 gulong signal_handoff;
109 GMutex eos_wait_mutex;
113 GCond eos_waiting_cond;
115 bool output_allocated;
123 bool need_codec_data;
126 unsigned int prepare_count;
127 unsigned int num_live_buffers;
128 unsigned int etb_count;
129 unsigned int ftb_count;
131 mediacodec_codec_type_e codec_id;
132 media_format_mimetype_e out_mime;
133 media_format_h output_fmt;
134 mc_gst_port_t *ports[2];
137 mc_aqueue_t *available_queue;
138 GQueue *output_queue;
142 void* user_cb[_MEDIACODEC_EVENT_TYPE_NUM];
143 void* user_data[_MEDIACODEC_EVENT_TYPE_NUM];
155 enum { fill_inbuf, fill_outbuf, create_caps };
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 int __mc_create_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, bool codec_config);
161 int __mc_fill_input_buffer_with_packet(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *buff);
162 int __mc_fill_input_buffer_with_venc_packet(mc_gst_core_t *core, media_packet_h pkt, GstMCBuffer *mc_buffer);
164 int __mc_fill_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt);
165 int __mc_fill_venc_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_pkt);
166 int __mc_fill_vdec_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *pkt);
168 int __mc_vdec_sw_h264_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
169 int __mc_vdec_hw_h264_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
170 int __mc_venc_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
171 int __mc_vdec_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
172 int __mc_vdec_sw_h263_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
173 int __mc_vdec_hw_h263_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
174 int __mc_vdec_h263_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
175 int __mc_vdec_mpeg4_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
176 int __mc_h264dec_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
177 int __mc_aenc_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
178 int __mc_adec_aac_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
179 int __mc_aenc_aac_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
180 int __mc_adec_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
181 int __mc_adec_aacv12_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
182 int __mc_adec_mp3_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
183 int __mc_adec_amrnb_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
184 int __mc_adec_amrwb_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
185 int __mc_aenc_amrnb_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
186 int __mc_adec_vorbis_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
187 int __mc_adec_flac_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
188 int __mc_adec_wma_caps(mc_gst_core_t *core, GstCaps **caps, GstMCBuffer* buff, gboolean codec_config);
190 void _mc_create_codec_map_from_ini(mc_handle_t *mc_handle, mc_codec_spec_t *spec_emul);
191 void _mc_create_decoder_map_from_ini(mc_handle_t *mc_handle);
192 void _mc_create_encoder_map_from_ini(mc_handle_t *mc_handle);
193 mc_gst_core_t *mc_gst_core_new();
194 void mc_gst_core_free(mc_gst_core_t *core);
196 mc_gst_port_t *mc_gst_port_new(mc_gst_core_t *core);
197 void mc_gst_port_free(mc_gst_port_t *port);
199 mc_ret_e mc_gst_prepare(mc_handle_t *mc_handle);
200 mc_ret_e mc_gst_unprepare(mc_handle_t *mc_handle);
202 mc_ret_e mc_gst_process_input(mc_handle_t *mc_handle, media_packet_h inbuf, uint64_t timeOutUs);
203 mc_ret_e mc_gst_get_output(mc_handle_t *mc_handle, media_packet_h *outbuf, uint64_t timeOutUs);
205 mc_ret_e mc_gst_flush_buffers(mc_handle_t *mc_handle);
207 mc_ret_e mc_gst_get_packet_pool(mc_handle_t *mc_handle, media_packet_pool_h *pkt_pool);
213 #endif /* __TIZEN_MEDIA_CODEC_PORT_GST_H__ */