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)) { \
45 LOGE("failed to set state %s to %s\n", #x_state, GST_ELEMENT_NAME(x_element)); \
46 goto STATE_CHANGE_FAILED; \
50 #define SCMN_IMGB_MAX_PLANE 4
51 #define TBM_API_CHANGE
52 #define DEFAULT_DEC_POOL_SIZE 20
53 #define DEFAULT_ENC_POOL_SIZE 13
54 #define CODECDATA_NOT_USE 0x7FFFFFFF
55 #define AAC_CODECDATA_SIZE 16
56 #define WMA_CODECDATA_SIZE 64
57 #define VORBIS_CODECDATA_SIZE 4096
58 #define MAXINUM_QNUM 15
59 #define THRESHOLD_QNUM 5
62 typedef struct _mc_gst_port_t mc_gst_port_t;
63 typedef struct _mc_gst_core_t mc_gst_core_t;
64 typedef struct _GstMCBuffer GstMCBuffer;
65 typedef struct _ion_mmu_data_t ion_mmu_data_t;
68 BUF_SHARE_METHOD_PADDR = 0,
70 BUF_SHARE_METHOD_TIZEN_BUFFER,
71 BUF_SHARE_METHOD_FLUSH_BUFFER
74 #ifdef TIZEN_PROFILE_LITE
75 struct _ion_mmu_data_t {
78 unsigned long iova_addr;
83 struct _mc_gst_port_t {
85 unsigned int num_buffers;
86 unsigned int buffer_size;
89 media_packet_h *buffers;
95 struct _mc_gst_core_t {
101 GstElement *audioconvert;
102 GstElement *capsfilter;
104 GstElement *fakesink;
110 GMainContext *thread_default;
111 gulong signal_handoff;
116 GMutex eos_wait_mutex;
120 GCond out_buffer_cond;
122 GCond eos_waiting_cond;
124 bool output_allocated;
133 bool need_codec_data;
136 unsigned int prepare_count;
137 unsigned int num_live_buffers;
138 unsigned int etb_count;
139 unsigned int ftb_count;
141 mediacodec_codec_type_e codec_id;
142 media_format_mimetype_e out_mime;
143 media_format_h output_fmt;
144 mc_gst_port_t *ports[2];
147 mc_aqueue_t *available_queue;
148 GQueue *output_queue;
151 GstBuffer *codec_data;
153 void* user_cb[_MEDIACODEC_EVENT_TYPE_NUM];
154 void* user_data[_MEDIACODEC_EVENT_TYPE_NUM];
157 struct _GstMCBuffer {
161 media_packet_h packet;
165 enum { fill_inbuf, fill_outbuf };
167 int __mc_fill_input_buffer(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer);
168 int __mc_fill_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_packet);
170 int __mc_fill_input_buffer_with_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer);
171 int __mc_fill_input_buffer_with_adec_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer);
172 int __mc_fill_input_buffer_with_venc_packet(mc_gst_core_t *core, media_packet_h packet, GstMCBuffer *mcbuffer);
174 int __mc_fill_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_packet);
175 int __mc_fill_aenc_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_packet);
176 int __mc_fill_venc_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *out_packet);
177 int __mc_fill_vdec_packet_with_output_buffer(mc_gst_core_t *core, void *data, int size, media_packet_h *packet);
179 mc_gst_core_t *mc_gst_core_new();
180 void mc_gst_core_free(mc_gst_core_t *core);
182 mc_gst_port_t *mc_gst_port_new(mc_gst_core_t *core);
183 void mc_gst_port_free(mc_gst_port_t *port);
185 mc_ret_e mc_gst_prepare(mc_handle_t *mc_handle);
186 mc_ret_e mc_gst_unprepare(mc_handle_t *mc_handle);
188 mc_ret_e mc_gst_process_input(mc_handle_t *mc_handle, media_packet_h inbuf, uint64_t timeOutUs);
189 mc_ret_e mc_gst_get_output(mc_handle_t *mc_handle, media_packet_h *outbuf, uint64_t timeOutUs);
191 mc_ret_e mc_gst_flush_buffers(mc_handle_t *mc_handle);
193 mc_ret_e mc_gst_get_packet_pool(mc_handle_t *mc_handle, media_packet_pool_h *packet_pool);
199 #endif /* __TIZEN_MEDIA_CODEC_PORT_GST_H__ */