Tizen 2.1 base
[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/app/gstappbuffer.h>
45 #include <gst/app/gstappsink.h>
46 #include <glib-2.0/glib/gprintf.h>
47 #include <gstreamer-0.10/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/check/gstcheck.h>
53 #include <glibconfig.h>
54 #include <pthread.h>
55 #include <mm_file.h>
56 #include <gmodule.h>
57 #include <mm_ta.h>
58 #define BUFFER_SIZE 4096
59 #define ENC_BUFFER_SIZE 25
60
61 #define TRANSCODE_FREE(src) { if(src) {g_free(src); src = NULL;} }
62 #define AAC "aac"
63 #define ACON "auto-audio-convert"
64 #define ACS "auto-colorspace"
65 #define ACAPS "acaps"
66 #define AENC "aenc-name"
67 #define AMR "amr"
68 #define AMRENC "amrnbenc"
69 #define ARS "auto-audio-resample"
70 #define ASF "asfdemux"
71 #define FFENCMPEG4 "ffenc_mpeg4"
72 #define FFENCH263 "ffenc_h263p"
73 #define MUX "mux-name"
74 #define MUXAAC "ffmux_adts"
75 #define MUX3GP "ffmux_3gp"
76 #define MUXGPP "gppmux"
77 #define MUXMP4 "ffmux_mp4"
78 #define AACENC "ffenc_aac"
79 #define PROFILE "profile"
80 #define VENC "venc-name"
81 #define MIN_DURATION 1000
82 #define LAZY_PAUSE_TIMEOUT_MSEC 500
83
84 /*SQCIF */
85 #define VIDEO_RESOLUTION_WIDTH_SQCIF 128
86 #define VIDEO_RESOLUTION_HEIGHT_SQCIF 96
87
88 typedef enum {
89         GST_AUTOPLUG_SELECT_TRY,
90         GST_AUTOPLUG_SELECT_EXPOSE,
91         GST_AUTOPLUG_SELECT_SKIP
92 } GstAutoplugSelectResult;
93
94 typedef struct _handle_param_s
95 {
96         unsigned int resolution_width;
97         unsigned int resolution_height;
98         unsigned int fps_value;
99         unsigned long start_pos;
100         unsigned long duration;
101         mm_seek_mode_e seek_mode;
102         char outputfile[BUFFER_SIZE];
103         gboolean seeking;
104         gboolean async_done;
105         gboolean segment_done;
106         gboolean completed;
107         unsigned int printed;
108 } handle_param_s;
109
110 typedef struct _handle_s
111 {
112         /* pipeline element*/
113         GstElement *pipeline;
114         GstElement *decsrcbin;
115         GstElement *filesrc;
116         GstPad *filesrcpad;
117         GstElement *decbin;
118         GstElement *decaudiobin;
119         GstPad *decaudiopad;
120         GstPad *decvideopad;
121         GstElement *valve;
122         GstElement *aconv;
123         GstElement *resample;
124         GstElement *audflt;
125         GstElement *audiofakesink;
126         GstCaps *caps;
127         GstElement *decsinkaudioqueue;
128         GstPad *decaudiosinkpad;
129         GstPad *decaudiosrcpad;
130         GstPad *audiofakesinkcpad;
131         GstPad *audiopad;
132         GstPad *sinkdecaudiopad;
133         GstPad *srcdecaudiopad;
134         GstPad *encaudiopad;
135
136         GstElement *decsinkvideoqueue;
137         GstElement *decvideobin;
138         GstPad *decvideosinkpad;
139         GstPad *decvideosrcpad;
140         GstPad *decxvimagesinkpad;
141         GstElement *vidflt;
142         GstElement *videoscale;
143         GstElement *videorate;
144         GstPad *videopad;
145         GstPad *sinkdecvideopad;
146         GstPad *srcdecvideopad;
147         GstPad *encvideopad;
148
149         GstElement *encbin;
150         GstElement *ffmux;
151         int use_vencqueue;
152         int use_aencqueue;
153         GstElement *encodepad;
154         GstElement *filesink;
155         GList *sink_elements;
156         int encodebin_profile;
157         gboolean linked_vidoutbin;
158         gboolean linked_audoutbin;
159         mm_containerformat_e containerformat;
160         mm_videoencoder_e videoencoder;
161         mm_audioencoder_e audioencoder;
162         gboolean has_video_stream;
163         gboolean has_audio_stream;
164
165         /* pipeline property */
166         guint bus_watcher;
167         int AUDFLAG;
168         int VIDFLAG;
169
170         char *audiodecodename;
171         char *videodecodename;
172         gchar *venc;
173         gchar *aenc;
174         gchar *mux;
175         gulong video_cb_probe_id;
176         gulong audio_cb_probe_id;
177         guint progrss_event_id;
178         const gchar *mime;
179         guint32 fourcc;
180         gint in_width;
181         gint in_height;
182         gint width;
183         gint height;
184         gint fps_n;
185         gint fps_d;
186         gint aspect_x;
187         gint aspect_y;
188         unsigned int seek_count;
189         unsigned long end_pos;
190         unsigned long current_pos;
191         unsigned long real_duration;
192         unsigned long total_length;
193         char sourcefile[BUFFER_SIZE];
194         unsigned int _MMHandle;
195         /* message callback */
196         mm_transcode_completed_callback completed_cb;
197         void * completed_cb_param;
198         mm_transcode_progress_callback progress_cb;
199         void * progress_cb_param;
200
201         /* If transcode is busy */
202         bool is_busy;
203
204         /* repeat thread lock */
205         GCond* thread_cond;
206         GMutex *thread_mutex;
207         GMutex *thread_exit_mutex;
208         GThread* thread;
209         gboolean repeat_thread_exit;
210         GAsyncQueue *queue;
211
212         /* seek paramerter */
213         handle_param_s *param;
214
215         int seek_idx;
216 } handle_s;
217
218 gboolean _mm_cb_audio_output_stream_probe(GstPad *pad, GstBuffer *buffer, gpointer user_data);
219 GstAutoplugSelectResult _mm_cb_decode_bin_autoplug_select(GstElement * element, GstPad * pad, GstCaps * caps, GstElementFactory * factory, handle_s *handle);
220 void _mm_cb_decoder_newpad_encoder(GstElement *decodebin, GstPad *pad, gboolean last, handle_s *handle);
221 gboolean _mm_cb_video_output_stream_probe(GstPad *pad, GstBuffer *buffer, gpointer user_data);
222 gboolean _mm_cb_print_position(handle_s *handle);
223 gboolean _mm_cb_transcode_bus(GstBus * bus, GstMessage * message, gpointer userdata);
224 const gchar* _mm_check_media_type(GstCaps *caps);
225 int _mm_cleanup_encodebin(handle_s *handle);
226 int _mm_cleanup_pipeline(handle_s *handle);
227 int _mm_decodesrcbin_create(handle_s *handle);
228 int _mm_decodesrcbin_link(handle_s *handle);
229 int _mm_encodebin_create(handle_s *handle);
230 int _mm_encodebin_link(handle_s *handle);
231 int _mm_encodebin_set_venc_aenc(handle_s *handle);
232 int _mm_filesink_create(handle_s *handle);
233 int _mm_filesink_link(handle_s *handle);
234 int _mm_setup_pipeline(handle_s *handle);
235 int _mm_transcode_create(handle_s *handle);
236 int _mm_transcode_get_stream_info(handle_s *handle);
237 int _mm_transcode_link(handle_s *handle);
238 int _mm_transcode_param_flush(handle_s *handle);
239 int _mm_transcode_preset_capsfilter(handle_s *handle, unsigned int resolution_width, unsigned int resolution_height);
240 int _mm_transcode_state_change(handle_s *handle, GstState gst_state);
241 int _mm_transcode_set_handle_element(handle_s *handle, const char * in_Filename, mm_containerformat_e containerformat,
242         mm_videoencoder_e videoencoder, mm_audioencoder_e audioencoder);
243 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,
244         unsigned long duration, mm_seek_mode_e seek_mode, const char *out_Filename);
245 int _mm_transcode_get_stream_info(handle_s *handle);
246 int _mm_transcode_thread(handle_s *handle);
247
248
249 #ifdef __cplusplus
250 }
251 #endif
252
253 #endif  /*__MM_TRANSCODE_INTERNAL_H__*/