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>
58 #define BUFFER_SIZE 4096
59 #define ENC_BUFFER_SIZE 25
61 #define TRANSCODE_FREE(src) { if(src) {g_free(src); src = NULL;} }
63 #define ACON "auto-audio-convert"
64 #define ACS "auto-colorspace"
66 #define AENC "aenc-name"
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
85 #define VIDEO_RESOLUTION_WIDTH_SQCIF 128
86 #define VIDEO_RESOLUTION_HEIGHT_SQCIF 96
89 GST_AUTOPLUG_SELECT_TRY,
90 GST_AUTOPLUG_SELECT_EXPOSE,
91 GST_AUTOPLUG_SELECT_SKIP
92 } GstAutoplugSelectResult;
94 typedef struct _handle_param_s
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];
105 gboolean segment_done;
107 unsigned int printed;
110 typedef struct _handle_s
112 /* pipeline element*/
113 GstElement *pipeline;
114 GstElement *decsrcbin;
118 GstElement *decaudiobin;
123 GstElement *resample;
125 GstElement *audiofakesink;
127 GstElement *decsinkaudioqueue;
128 GstPad *decaudiosinkpad;
129 GstPad *decaudiosrcpad;
130 GstPad *audiofakesinkcpad;
132 GstPad *sinkdecaudiopad;
133 GstPad *srcdecaudiopad;
136 GstElement *decsinkvideoqueue;
137 GstElement *decvideobin;
138 GstPad *decvideosinkpad;
139 GstPad *decvideosrcpad;
140 GstPad *decxvimagesinkpad;
142 GstElement *videoscale;
143 GstElement *videorate;
145 GstPad *sinkdecvideopad;
146 GstPad *srcdecvideopad;
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;
165 /* pipeline property */
170 char *audiodecodename;
171 char *videodecodename;
175 gulong video_cb_probe_id;
176 gulong audio_cb_probe_id;
177 guint progrss_event_id;
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;
201 /* If transcode is busy */
204 /* repeat thread lock */
206 GMutex *thread_mutex;
207 GMutex *thread_exit_mutex;
209 gboolean repeat_thread_exit;
212 /* seek paramerter */
213 handle_param_s *param;
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);
253 #endif /*__MM_TRANSCODE_INTERNAL_H__*/