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/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>
56 #define BUFFER_SIZE 4096
57 #define ENC_BUFFER_SIZE 25
59 #define TRANSCODE_FREE(src) { if(src) {g_free(src); src = NULL;} }
61 #define ACON "auto-audio-convert"
62 #define ACS "auto-colorspace"
64 #define AENC "aenc-name"
66 #define AMRENC "amrnbenc"
67 #define ARS "auto-audio-resample"
68 #define ASF "asfdemux"
69 #define AVENCMPEG4 "avenc_mpeg4"
70 #define AVENCH263 "avenc_h263p"
71 #define MUX "mux-name"
72 #define MUXAAC "avmux_adts"
73 #define MUX3GP "avmux_3gp"
74 #define MUXGPP "gppmux"
75 #define MUXMP4 "avmux_mp4"
76 #define AACENC "avenc_aac"
77 #define AACCOMPLIANCE "compliance"
78 #define AACCOMPLIANCELEVEL -2
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;
105 gboolean segment_done;
107 unsigned int printed;
110 typedef struct _handle_vidp_plugin_s
112 /* decoder video processing pipeline */
113 GstElement *decvideobin;
114 GstElement *decsinkvideoqueue;
115 GstPad *decvideosinkpad;
116 GstPad *decvideosrcpad;
118 GstElement *videoscale;
119 GstElement *videorate;
121 GstPad *sinkdecvideopad;
122 GstPad *srcdecvideopad;
123 } handle_vidp_plugin_s;
125 typedef struct _handle_audp_plugin_s
127 /* decoder audio processing pipeline */
128 GstElement *decaudiobin;
129 GstElement *decsinkaudioqueue;
130 GstPad *decaudiosinkpad;
131 GstPad *decaudiosrcpad;
134 GstElement *resample;
136 GstElement *audiofakesink;
137 GstPad *sinkdecaudiopad;
138 GstPad *srcdecaudiopad;
141 } handle_audp_plugin_s;
143 typedef struct _handle_encode_s
145 /* encode pipeline */
150 GstElement *vencqueue;
151 GstElement *aencqueue;
152 GstElement *encodepad;
153 GstElement *encodevideo;
154 gulong video_event_probe_id;
155 gulong audio_event_probe_id;
156 int encodebin_profile;
159 typedef struct _handle_property_s
161 /* pipeline property */
166 char *audiodecodename;
167 char *videodecodename;
171 gulong video_cb_probe_id;
172 gulong audio_cb_probe_id;
173 guint progrss_event_id;
175 gchar format[sizeof(GST_VIDEO_FORMATS_ALL)];
184 unsigned int seek_count;
185 unsigned long end_pos;
186 unsigned long current_pos;
187 unsigned long real_duration;
188 unsigned long total_length;
190 unsigned int _MMHandle;
192 mm_containerformat_e containerformat;
193 mm_videoencoder_e videoencoder;
194 mm_audioencoder_e audioencoder;
197 GList *sink_elements;
198 gboolean linked_vidoutbin;
199 gboolean linked_audoutbin;
200 gboolean has_video_stream;
201 gboolean has_audio_stream;
203 /* message callback */
204 mm_transcode_completed_callback completed_cb;
205 void * completed_cb_param;
206 mm_transcode_progress_callback progress_cb;
207 void * progress_cb_param;
209 /* If transcode is busy */
212 /* repeat thread lock */
214 GMutex *thread_mutex;
215 GMutex *thread_exit_mutex;
217 gboolean repeat_thread_exit;
222 typedef struct _handle_s
224 /* Transcode Pipeline Element*/
225 GstElement *pipeline;
227 GstElement *decodebin;
228 handle_vidp_plugin_s *decoder_vidp;
229 handle_audp_plugin_s *decoder_audp;
230 handle_encode_s *encodebin;
231 GstElement *filesink;
233 /* seek paramerter */
234 handle_param_s *param;
236 /* pipeline property */
237 handle_property_s *property;
240 GstPadProbeReturn _mm_cb_audio_output_stream_probe(GstPad *pad, GstPadProbeInfo *info, gpointer user_data);
241 GstAutoplugSelectResult _mm_cb_decode_bin_autoplug_select(GstElement * element, GstPad * pad, GstCaps * caps, GstElementFactory * factory, handle_s *handle);
242 void _mm_cb_decoder_newpad_encoder(GstElement *decodebin, GstPad *pad, handle_s *handle);
243 GstPadProbeReturn _mm_cb_video_output_stream_probe(GstPad *pad, GstPadProbeInfo *info, gpointer user_data);
244 GstPadProbeReturn _mm_cb_encodebin_sinkpad_event_probe(GstPad *pad, GstPadProbeInfo *info, gpointer user_data);
245 gboolean _mm_cb_print_position(handle_s *handle);
246 gboolean _mm_cb_transcode_bus(GstBus * bus, GstMessage * message, gpointer userdata);
247 const gchar* _mm_check_media_type(GstCaps *caps);
248 int _mm_cleanup_encodebin(handle_s *handle);
249 int _mm_cleanup_signal(handle_s *handle);
250 int _mm_cleanup_pipeline(handle_s *handle);
251 int _mm_decodesrcbin_create(handle_s *handle);
252 int _mm_decodesrcbin_link(handle_s *handle);
253 int _mm_encodebin_create(handle_s *handle);
254 int _mm_encodebin_link(handle_s *handle);
255 int _mm_encodebin_set_venc_aenc(handle_s *handle);
256 int _mm_filesink_create(handle_s *handle);
257 int _mm_filesink_link(handle_s *handle);
258 int _mm_setup_pipeline(handle_s *handle);
259 int _mm_transcode_create(handle_s *handle);
260 int _mm_transcode_get_stream_info(handle_s *handle);
261 int _mm_transcode_link(handle_s *handle);
262 int _mm_transcode_param_flush(handle_s *handle);
263 int _mm_transcode_preset_capsfilter(handle_s *handle, unsigned int resolution_width, unsigned int resolution_height);
264 int _mm_transcode_state_change(handle_s *handle, GstState gst_state);
265 int _mm_transcode_set_handle_element(handle_s *handle, const char * in_Filename, mm_containerformat_e containerformat,
266 mm_videoencoder_e videoencoder, mm_audioencoder_e audioencoder);
267 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,
268 unsigned long duration, mm_seek_mode_e seek_mode, const char *out_Filename);
269 int _mm_transcode_get_stream_info(handle_s *handle);
270 int _mm_transcode_thread(handle_s *handle);
277 #endif /*__MM_TRANSCODE_INTERNAL_H__*/