Add new internal API to enable extra video convert element
[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 <media_codec.h>
23 #include <media_codec_private.h>
24 #include <media_codec_port.h>
25 #include <media_codec_bitstream.h>
26
27 #include <tbm_surface.h>
28 #include <tbm_surface_internal.h>
29 #include <gst/video/video-format.h>
30 #include <gst/allocators/gsttizenmemory.h>
31
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35
36 #define GST_INIT_STRUCTURE(param) \
37         memset(&(param), 0, sizeof(param));
38
39
40 #define SCMN_IMGB_MAX_PLANE 4
41 #define TBM_API_CHANGE
42 #define DEFAULT_DEC_POOL_SIZE 20
43 #define DEFAULT_ENC_POOL_SIZE 13
44 #define CODECDATA_NOT_USE       0x7FFFFFFF
45 #define AAC_CODECDATA_SIZE      16
46 #define WMA_CODECDATA_SIZE      64
47 #define VORBIS_CODECDATA_SIZE   4096
48 #define MAXINUM_QNUM    20
49 #define THRESHOLD_QNUM  5
50
51 /* gst port layer */
52 typedef struct _mc_gst_port_def_t mc_gst_port_def_t;
53 typedef struct _mc_gst_port_t mc_gst_port_t;
54 typedef struct _mc_gst_core_t mc_gst_core_t;
55 typedef struct _GstMCBuffer GstMCBuffer;
56
57
58 typedef enum {
59         in_port_index = 0,
60         out_port_index
61 } port_index_e;
62
63
64 struct _mc_gst_port_def_t {
65         gchar *mime_type;
66         media_format_mimetype_e coding_type;
67         union {
68                 mc_audio_port_definition_t audio;
69                 mc_video_port_definition_t video;
70         } info;
71 };
72
73 struct _mc_gst_port_t {
74         mc_gst_core_t *core;
75         guint num_buffers;
76         guint buffer_size;
77         guint index;
78         gboolean is_allocated;
79         GQueue *queue;
80         GMutex mutex;
81         GCond buffer_cond;
82         mc_gst_port_def_t port_def;
83 };
84
85 struct _mc_gst_core_t {
86         gint(**vtable)();
87         const gchar *mime;
88         GstElement *pipeline;
89         GstElement *appsrc;
90         GstElement *audioconvert;
91         GstElement *audioresample;
92         GstElement *videoscale;
93         GstElement *videoconvert;
94         GstElement *capsfilter;
95         GstElement *parser;
96         GstElement *fakesink;
97         GstElement *codec;
98         GstCaps *caps;
99         tbm_bufmgr bufmgr;
100         gint drm_fd;
101
102         GMainContext *thread_default;
103         gulong signal_handoff;
104         gint bus_watch_id;
105         gint probe_id;
106
107         GMutex eos_mutex;
108         GMutex eos_wait_mutex;
109         GMutex prepare_lock;
110         GMutex drain_lock;
111         GCond buffer_cond;
112         GCond out_buffer_cond;
113         GCond eos_cond;
114         GCond eos_waiting_cond;
115
116         gboolean output_allocated;
117         gboolean encoder;
118         gboolean video;
119         gboolean is_hw;
120         gboolean eos;
121         gboolean eos_waiting;
122         gboolean codec_config;
123         gboolean need_drain;
124         gboolean need_feed;
125         gboolean need_codec_data;
126         gboolean need_sync_flag;
127         gboolean unprepare_flag;
128         guint prepare_count;
129         guint num_live_buffers;
130         guint etb_count;
131         gint64 offset;
132
133         mediacodec_codec_type_e codec_id;
134         media_format_mimetype_e out_mime;
135         media_format_h output_fmt;
136         mc_gst_port_t *ports[2];
137         mc_bitstream_t bits;
138         mc_codec_type_t *codec_type;
139
140         mc_aqueue_t *available_queue;
141         GQueue *output_queue;
142
143         GstBuffer *codec_data;
144         gboolean (*mc_caps_new)(mc_gst_core_t *, mediacodec_codec_type_e, gint);
145         GstAllocator *allocator;
146
147         void* user_cb[_MEDIACODEC_EVENT_TYPE_NUM];
148         void* user_data[_MEDIACODEC_EVENT_TYPE_NUM];
149
150         GstVideoInfo *video_info;
151
152         mc_extra_converter_t *extra_converter;
153 };
154
155 struct _GstMCBuffer {
156         GstBuffer *buffer;
157         gint buf_size;
158         mc_gst_core_t* core;
159         media_packet_h packet;
160         void *ext_mem;
161         gboolean has_tbm;
162 };
163
164 enum { fill_inbuf, fill_outbuf };
165 mc_ret_e mc_gst_prepare(mc_handle_t *mc_handle);
166 mc_ret_e mc_gst_unprepare(mc_handle_t *mc_handle);
167
168 mc_ret_e mc_gst_process_input(mc_handle_t *mc_handle, media_packet_h inbuf, uint64_t timeout_us);
169 mc_ret_e mc_gst_get_output(mc_handle_t *mc_handle, media_packet_h *outbuf, uint64_t timeout_us);
170
171 mc_ret_e mc_gst_flush_buffers(mc_handle_t *mc_handle);
172
173 mc_ret_e mc_gst_get_packet_pool(mc_handle_t *mc_handle, media_packet_pool_h *packet_pool);
174
175 mc_ret_e mc_gst_set_property_array_int(GstElement *element, const gchar *property_name, gint *array, guint array_length);
176
177 #ifdef __cplusplus
178 }
179 #endif
180
181 #endif /* __TIZEN_MEDIA_CODEC_PORT_GST_H__ */