4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: YoungHun Kim <yh8004.kim@samsung.com>
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 #ifndef __MM_TRANSCODE_INTERNAL_H__
23 #define __MM_TRANSCODE_INTERNAL_H__
29 #include "mm_transcode.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>
57 #define BUFFER_SIZE 4096
58 #define ENC_BUFFER_SIZE 25
60 #define TRANSCODE_FREE(src) { if(src) {g_free(src); src = NULL;} }
62 #define ACON "auto-audio-convert"
63 #define ACS "auto-colorspace"
65 #define AENC "aenc-name"
67 #define AMRENC "amrnbenc"
68 #define ARS "auto-audio-resample"
69 #define ASF "asfdemux"
70 #define FFENCMPEG4 "ffenc_mpeg4"
71 #define FFENCH263 "ffenc_h263p"
72 #define MUX "mux-name"
73 #define MUXAAC "ffmux_adts"
74 #define MUX3GP "ffmux_3gp"
75 #define MUXGPP "gppmux"
76 #define MUXMP4 "ffmux_mp4"
77 #define AACENC "ffenc_aac"
78 #define PROFILE "profile"
79 #define VENC "venc-name"
80 #define MIN_DURATION 1000
81 #define LAZY_PAUSE_TIMEOUT_MSEC 500
84 #define VIDEO_RESOLUTION_WIDTH_SQCIF 128
85 #define VIDEO_RESOLUTION_HEIGHT_SQCIF 96
88 GST_AUTOPLUG_SELECT_TRY,
89 GST_AUTOPLUG_SELECT_EXPOSE,
90 GST_AUTOPLUG_SELECT_SKIP
91 } GstAutoplugSelectResult;
93 typedef struct _handle_param_s
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;
104 gboolean segment_done;
106 unsigned int printed;
109 typedef struct _handle_vidp_plugin_s
111 /* decoder video processing pipeline */
112 GstElement *decvideobin;
113 GstElement *decsinkvideoqueue;
114 GstPad *decvideosinkpad;
115 GstPad *decvideosrcpad;
117 GstElement *videoscale;
118 GstElement *videorate;
120 GstPad *sinkdecvideopad;
121 GstPad *srcdecvideopad;
122 } handle_vidp_plugin_s;
124 typedef struct _handle_audp_plugin_s
126 /* decoder audio processing pipeline */
127 GstElement *decaudiobin;
128 GstElement *decsinkaudioqueue;
129 GstPad *decaudiosinkpad;
130 GstPad *decaudiosrcpad;
133 GstElement *resample;
135 GstElement *audiofakesink;
136 GstPad *sinkdecaudiopad;
137 GstPad *srcdecaudiopad;
140 } handle_audp_plugin_s;
142 typedef struct _handle_encode_s
144 /* encode pipeline */
151 GstElement *encodepad;
152 GstElement *encodevideo;
153 int encodebin_profile;
156 typedef struct _handle_property_s
158 /* pipeline property */
163 char *audiodecodename;
164 char *videodecodename;
168 gulong video_cb_probe_id;
169 gulong audio_cb_probe_id;
170 guint progrss_event_id;
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;
187 unsigned int _MMHandle;
189 mm_containerformat_e containerformat;
190 mm_videoencoder_e videoencoder;
191 mm_audioencoder_e audioencoder;
194 GList *sink_elements;
195 gboolean linked_vidoutbin;
196 gboolean linked_audoutbin;
197 gboolean has_video_stream;
198 gboolean has_audio_stream;
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;
206 /* If transcode is busy */
209 /* repeat thread lock */
211 GMutex *thread_mutex;
212 GMutex *thread_exit_mutex;
214 gboolean repeat_thread_exit;
219 typedef struct _handle_s
221 /* Transcode Pipeline Element*/
222 GstElement *pipeline;
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;
230 /* seek paramerter */
231 handle_param_s *param;
233 /* pipeline property */
234 handle_property_s *property;
237 gboolean _mm_cb_audio_output_stream_probe(GstPad *pad, GstBuffer *buffer, 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, gboolean last, handle_s *handle);
240 gboolean _mm_cb_video_output_stream_probe(GstPad *pad, GstBuffer *buffer, 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);
272 #endif /*__MM_TRANSCODE_INTERNAL_H__*/