Updated to version 0.9 from tizendev
[platform/core/multimedia/libmm-transcode.git] / transcode / include / mm_transcode_internal.h
1 /*
2  * libmm-transcode
3  *
4  * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Contact: YoungHun Kim <yh8004.kim@samsung.com>
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  *
20  */
21
22 #ifndef __MM_TRANSCODE_INTERNAL_H__
23 #define __MM_TRANSCODE_INTERNAL_H__
24
25 #ifdef __cplusplus
26 extern "C" {
27 #endif
28
29 #include "mm_transcode.h"
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <unistd.h>
34 #include "mm_log.h"
35 #include <mm_debug.h>
36 #include <mm_error.h>
37 #include <mm_debug.h>
38 #include <mm_attrs.h>
39 #include <glib.h>
40 #include <gst/gst.h>
41 #include <gst/gstpipeline.h>
42 #include <gst/gstbuffer.h>
43 #include <gst/app/gstappsrc.h>
44 #include <gst/video/video.h>
45 #include <gst/app/gstappsink.h>
46 #include <glib/gprintf.h>
47 #include <gst/gstelement.h>
48 #include <gst/check/gstcheck.h>
49 #include <gst/pbutils/pbutils.h>
50 #include <gst/pbutils/encoding-profile.h>
51 #include <gst/pbutils/pbutils-enumtypes.h>
52 #include <gst/video/video-format.h>
53 #include <pthread.h>
54 #include <mm_file.h>
55 #include <gmodule.h>
56 #include <mm_ta.h>
57 #define BUFFER_SIZE 4096
58 #define ENC_BUFFER_SIZE 25
59
60 #define TRANSCODE_FREE(src) { if(src) {g_free(src); src = NULL;} }
61 #define AAC "aac"
62 #define ACON "auto-audio-convert"
63 #define ACS "auto-colorspace"
64 #define ACAPS "acaps"
65 #define AENC "aenc-name"
66 #define AMR "amr"
67 #define AMRENC "amrnbenc"
68 #define ARS "auto-audio-resample"
69 #define ASF "asfdemux"
70 #define AVENCMPEG4 "avenc_mpeg4"
71 #define AVENCH263 "avenc_h263p"
72 #define MUX "mux-name"
73 #define MUXAAC "avmux_adts"
74 #define MUX3GP "avmux_3gp"
75 #define MUXGPP "gppmux"
76 #define MUXMP4 "avmux_mp4"
77 #define AACENC "avenc_aac"
78 #define PROFILE "profile"
79 #define VENC "venc-name"
80 #define MIN_DURATION 1000
81 #define LAZY_PAUSE_TIMEOUT_MSEC 500
82
83 /*SQCIF */
84 #define VIDEO_RESOLUTION_WIDTH_SQCIF 128
85 #define VIDEO_RESOLUTION_HEIGHT_SQCIF 96
86
87 typedef enum {
88         GST_AUTOPLUG_SELECT_TRY,
89         GST_AUTOPLUG_SELECT_EXPOSE,
90         GST_AUTOPLUG_SELECT_SKIP
91 } GstAutoplugSelectResult;
92
93 typedef struct _handle_param_s
94 {
95         unsigned int resolution_width;
96         unsigned int resolution_height;
97         unsigned int fps_value;
98         unsigned long start_pos;
99         unsigned long duration;
100         mm_seek_mode_e seek_mode;
101         char outputfile[BUFFER_SIZE];
102         gboolean seeking;
103         gboolean async_done;
104         gboolean segment_done;
105         gboolean completed;
106         unsigned int printed;
107 } handle_param_s;
108
109 typedef struct _handle_vidp_plugin_s
110 {
111         /* decoder video processing pipeline */
112         GstElement *decvideobin;
113         GstElement *decsinkvideoqueue;
114         GstPad *decvideosinkpad;
115         GstPad *decvideosrcpad;
116         GstElement *vidflt;
117         GstElement *videoscale;
118         GstElement *videorate;
119         GstPad *videopad;
120         GstPad *sinkdecvideopad;
121         GstPad *srcdecvideopad;
122 } handle_vidp_plugin_s;
123
124 typedef struct _handle_audp_plugin_s
125 {
126         /* decoder audio processing pipeline */
127         GstElement *decaudiobin;
128         GstElement *decsinkaudioqueue;
129         GstPad *decaudiosinkpad;
130         GstPad *decaudiosrcpad;
131         GstElement *valve;
132         GstElement *aconv;
133         GstElement *resample;
134         GstElement *audflt;
135         GstElement *audiofakesink;
136         GstPad *sinkdecaudiopad;
137         GstPad *srcdecaudiopad;
138         GstPad *decaudiopad;
139         GstPad *decvideopad;
140 } handle_audp_plugin_s;
141
142 typedef struct _handle_encode_s
143 {
144         /* encode pipeline */
145         GstElement *encbin;
146         GstPad *encaudiopad;
147         GstPad *encvideopad;
148         GstElement *ffmux;
149         int use_vencqueue;
150         int use_aencqueue;
151         GstElement *encodepad;
152         GstElement *encodevideo;
153         int encodebin_profile;
154 } handle_encode_s;
155
156 typedef struct _handle_property_s
157 {
158         /* pipeline property */
159         guint bus_watcher;
160         int AUDFLAG;
161         int VIDFLAG;
162
163         char *audiodecodename;
164         char *videodecodename;
165         gchar *venc;
166         gchar *aenc;
167         gchar *mux;
168         gulong video_cb_probe_id;
169         gulong audio_cb_probe_id;
170         guint progrss_event_id;
171         const gchar *mime;
172         gchar format[sizeof(GST_VIDEO_FORMATS_ALL)];
173         gint in_width;
174         gint in_height;
175         gint width;
176         gint height;
177         gint fps_n;
178         gint fps_d;
179         gint aspect_x;
180         gint aspect_y;
181         unsigned int seek_count;
182         unsigned long end_pos;
183         unsigned long current_pos;
184         unsigned long real_duration;
185         unsigned long total_length;
186         char sourcefile[BUFFER_SIZE];
187         unsigned int _MMHandle;
188
189         mm_containerformat_e containerformat;
190         mm_videoencoder_e videoencoder;
191         mm_audioencoder_e audioencoder;
192
193         GstCaps *caps;
194         GList *sink_elements;
195         gboolean linked_vidoutbin;
196         gboolean linked_audoutbin;
197         gboolean has_video_stream;
198         gboolean has_audio_stream;
199
200         /* message callback */
201         mm_transcode_completed_callback completed_cb;
202         void * completed_cb_param;
203         mm_transcode_progress_callback progress_cb;
204         void * progress_cb_param;
205
206         /* If transcode is busy */
207         bool is_busy;
208
209         /* repeat thread lock */
210         GCond* thread_cond;
211         GMutex *thread_mutex;
212         GMutex *thread_exit_mutex;
213         GThread* thread;
214         gboolean repeat_thread_exit;
215         GAsyncQueue *queue;
216         int seek_idx;
217 } handle_property_s;
218
219 typedef struct _handle_s
220 {
221         /* Transcode Pipeline Element*/
222         GstElement *pipeline;
223         GstElement *filesrc;
224         GstElement *decodebin;
225         handle_vidp_plugin_s *decoder_vidp;
226         handle_audp_plugin_s *decoder_audp;
227         handle_encode_s *encodebin;
228         GstElement *filesink;
229
230         /* seek paramerter */
231         handle_param_s *param;
232
233         /* pipeline property */
234         handle_property_s *property;
235 } handle_s;
236
237 GstPadProbeReturn _mm_cb_audio_output_stream_probe(GstPad *pad, GstPadProbeInfo *info, gpointer user_data);
238 GstAutoplugSelectResult _mm_cb_decode_bin_autoplug_select(GstElement * element, GstPad * pad, GstCaps * caps, GstElementFactory * factory, handle_s *handle);
239 void _mm_cb_decoder_newpad_encoder(GstElement *decodebin, GstPad *pad, handle_s *handle);
240 GstPadProbeReturn _mm_cb_video_output_stream_probe(GstPad *pad, GstPadProbeInfo *info, gpointer user_data);
241 gboolean _mm_cb_print_position(handle_s *handle);
242 gboolean _mm_cb_transcode_bus(GstBus * bus, GstMessage * message, gpointer userdata);
243 const gchar* _mm_check_media_type(GstCaps *caps);
244 int _mm_cleanup_encodebin(handle_s *handle);
245 int _mm_cleanup_pipeline(handle_s *handle);
246 int _mm_decodesrcbin_create(handle_s *handle);
247 int _mm_decodesrcbin_link(handle_s *handle);
248 int _mm_encodebin_create(handle_s *handle);
249 int _mm_encodebin_link(handle_s *handle);
250 int _mm_encodebin_set_venc_aenc(handle_s *handle);
251 int _mm_filesink_create(handle_s *handle);
252 int _mm_filesink_link(handle_s *handle);
253 int _mm_setup_pipeline(handle_s *handle);
254 int _mm_transcode_create(handle_s *handle);
255 int _mm_transcode_get_stream_info(handle_s *handle);
256 int _mm_transcode_link(handle_s *handle);
257 int _mm_transcode_param_flush(handle_s *handle);
258 int _mm_transcode_preset_capsfilter(handle_s *handle, unsigned int resolution_width, unsigned int resolution_height);
259 int _mm_transcode_state_change(handle_s *handle, GstState gst_state);
260 int _mm_transcode_set_handle_element(handle_s *handle, const char * in_Filename, mm_containerformat_e containerformat,
261         mm_videoencoder_e videoencoder, mm_audioencoder_e audioencoder);
262 int _mm_transcode_set_handle_parameter(handle_param_s *param, unsigned int resolution_width, unsigned int resolution_height, unsigned int fps_value, unsigned long start_pos,
263         unsigned long duration, mm_seek_mode_e seek_mode, const char *out_Filename);
264 int _mm_transcode_get_stream_info(handle_s *handle);
265 int _mm_transcode_thread(handle_s *handle);
266
267
268 #ifdef __cplusplus
269 }
270 #endif
271
272 #endif  /*__MM_TRANSCODE_INTERNAL_H__*/