[svn r593] Fixed internal reference to gmyth.h. We can not include this header in src/gmyth_* files. Also fixed gmyth_debug link error. In the current implementation we need to include gmyth_debug.h in all files using gmyth_debug(), otherwise we will get library linking error
11 #define G_MENCODER_GET_PRIVATE(obj) \
12 (G_TYPE_INSTANCE_GET_PRIVATE ((obj), G_TYPE_MENCODER, GMencoderPrivate))
15 typedef struct _GMencoderPrivate GMencoderPrivate;
17 struct _GMencoderPrivate
36 static void g_mencoder_class_init (GMencoderClass *klass);
37 static void g_mencoder_init (GMencoder *object);
38 static void g_mencoder_dispose (GObject *object);
39 static void g_mencoder_finalize (GObject *object);
41 _pipeline_bus_cb (GstBus *bus,
45 static void _decodebin_new_pad_cb (GstElement* object,
49 static void _decodebin_unknown_type_cb (GstElement* object,
54 static guint g_mencoder_signals[LAST_SIGNAL] = { 0 };
56 G_DEFINE_TYPE(GMencoder, g_mencoder, G_TYPE_OBJECT)
59 g_mencoder_class_init (GMencoderClass *klass)
61 GObjectClass *object_class;
63 object_class = (GObjectClass *) klass;
65 g_type_class_add_private (klass, sizeof (GMencoderPrivate));
67 object_class->dispose = g_mencoder_dispose;
68 object_class->finalize = g_mencoder_finalize;
70 g_mencoder_signals[READY] =
71 g_signal_new ("ready",
72 G_OBJECT_CLASS_TYPE (object_class),
75 g_cclosure_marshal_VOID__VOID,
78 g_mencoder_signals[PAUSED] =
79 g_signal_new ("paused",
80 G_OBJECT_CLASS_TYPE (object_class),
83 g_cclosure_marshal_VOID__VOID,
86 g_mencoder_signals[PLAYING] =
87 g_signal_new ("playing",
88 G_OBJECT_CLASS_TYPE (object_class),
91 g_cclosure_marshal_VOID__VOID,
94 g_mencoder_signals[STOPED] =
95 g_signal_new ("stoped",
96 G_OBJECT_CLASS_TYPE (object_class),
99 g_cclosure_marshal_VOID__VOID,
102 g_mencoder_signals[EOS] =
104 G_OBJECT_CLASS_TYPE (object_class),
107 g_cclosure_marshal_VOID__VOID,
111 g_mencoder_signals[ERROR] =
112 g_signal_new ("error",
113 G_OBJECT_CLASS_TYPE (object_class),
116 g_cclosure_marshal_VOID__STRING,
117 G_TYPE_NONE, 1, G_TYPE_STRING);
121 g_mencoder_init (GMencoder *self)
126 g_mencoder_dispose (GObject *object)
131 g_mencoder_finalize (GObject *object)
133 g_mencoder_close_stream (G_MENCODER (object));
137 g_mencoder_new (void)
139 return g_object_new (G_TYPE_MENCODER, NULL);
144 g_mencoder_setup_stream (GMencoder *self,
146 guint width, guint height,
150 GstElement *pipe = NULL;
151 GstElement *decode = NULL;
152 GstElement *fdsink = NULL;
153 GstElement *mux = NULL;
155 GstCaps *vscale_caps = NULL;
156 GstPad *asinkpad = NULL;
157 GstPad *vsinkpad = NULL;
158 GstPad *video_src_pad = NULL;
159 GstPad *audio_src_pad = NULL;
160 GstPad *mux_pad = NULL;
161 GstElement *src = NULL;
162 GstElement *vbin, *vqueue, *vcolorspace, *vscale, *vrate, *vencode, *vqueue_src;
163 GstElement *abin, *aqueue, *aconvert, *aencode, *aqueue_src;
164 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self);
166 vbin = vqueue = vscale = vrate = vencode = vqueue_src = NULL;
167 abin = aqueue = aconvert = aencode = aqueue_src = NULL;
169 pipe = gst_pipeline_new ("pipe");
170 src = gst_element_make_from_uri (GST_URI_SRC, uri, "src");
174 decode = gst_element_factory_make ("decodebin", "decode");
178 mux = gst_element_factory_make ("ffmux_mpeg", "mux");
182 fdsink = gst_element_factory_make ("fdsink", "sink");
186 g_debug ("Setting fd to %d", out_fd);
187 g_object_set (G_OBJECT (fdsink), "fd", out_fd, NULL);
189 //queue ! videoscale ! video/x-raw-yuv,width=240,height=144 ! videorate ! ffenc_h263p bitrate=256000 me-method=2 ! rtph263ppay ! udpsink host=224.0.0.1 port=5000
191 vbin = gst_bin_new ("vbin");
192 vqueue = gst_element_factory_make ("queue", "vqueue");
193 vscale = gst_element_factory_make ("videoscale", "vscale");
194 vcolorspace = gst_element_factory_make ("ffmpegcolorspace", "colorspace");
195 vrate = gst_element_factory_make ("videorate", "vrate");
196 vencode = gst_element_factory_make ("ffenc_mpeg1video", "vencode");
197 vqueue_src = gst_element_factory_make ("queue", "queue_src");
200 if ((vbin == NULL) || (vqueue == NULL) || (vcolorspace == NULL)
201 || (vscale == NULL) || (vrate == NULL)
202 || (vencode == NULL) || (vqueue_src == NULL)) {
203 g_warning ("Video elements not found");
207 g_object_set (G_OBJECT (vencode), "bitrate", 200, "pass", 2, "quantizer", 5, NULL);
209 gst_bin_add_many (GST_BIN (vbin), vqueue, vscale, vcolorspace, vrate, vencode, vqueue_src, NULL);
210 gst_element_link (vqueue, vscale);
213 vscale_caps = gst_caps_new_simple ("video/x-raw-yuv",
214 "width", G_TYPE_INT, 320,
215 "height", G_TYPE_INT, 288,
218 if (gst_element_link_filtered (vscale, vcolorspace, vscale_caps) == FALSE) {
219 g_warning ("Fail to resize video");
223 if (gst_element_link (vcolorspace, vrate) == FALSE) {
224 g_warning ("Fail to link video elements");
228 gst_caps_unref (vscale_caps);
230 vscale_caps = gst_caps_new_simple ("video/x-raw-yuv",
231 "framerate", GST_TYPE_FRACTION, 10, 1, NULL);
233 if (gst_element_link_filtered (vrate, vencode, vscale_caps) == FALSE) {
234 g_warning ("Fail to link vrate with vencode.");
239 gst_element_link (vencode, vqueue_src);
241 // ghost pad the video bin
242 vsinkpad = gst_element_get_pad (vqueue, "sink");
243 gst_element_add_pad (vbin, gst_ghost_pad_new ("sink", vsinkpad));
244 gst_object_unref (vsinkpad);
246 video_src_pad = gst_element_get_pad (vqueue_src, "src");
247 gst_element_add_pad (vbin, gst_ghost_pad_new ("src", video_src_pad));
248 gst_object_unref (video_src_pad);
251 //audio/x-raw-int ! queue ! audioconvert ! faac ! rtpmp4gpay ! udpsink name=upd_audio host=224.0.0.1 port=5002
252 abin = gst_bin_new ("abin");
253 aqueue = gst_element_factory_make ("queue", "aqueue");
254 aconvert= gst_element_factory_make ("audioconvert", "aconvert");
255 aencode = gst_element_factory_make ("lame", "aencode");
256 aqueue_src= gst_element_factory_make ("queue", "aqueue_src");
258 if ((abin == NULL) || (aqueue == NULL) || (aconvert == NULL)
259 || (aencode == NULL) || (aqueue_src == NULL)) {
260 g_warning ("Audio elements not found");
264 gst_bin_add_many (GST_BIN (abin), aqueue, aconvert, aencode, aqueue_src, NULL);
265 gst_element_link_many (aqueue, aconvert, aencode, aqueue_src, NULL);
268 // ghost pad the audio bin
269 asinkpad = gst_element_get_pad (aqueue, "sink");
270 gst_element_add_pad (abin, gst_ghost_pad_new("sink", asinkpad));
271 gst_object_unref (asinkpad);
273 audio_src_pad = gst_element_get_pad (aqueue_src, "src");
274 gst_element_add_pad (abin, gst_ghost_pad_new("src", audio_src_pad));
275 gst_object_unref (audio_src_pad);
279 gst_bin_add_many (GST_BIN (pipe), src, decode, abin, vbin, mux, fdsink, NULL);
280 gst_element_link (src, decode);
283 audio_src_pad = gst_element_get_pad (abin, "src");
284 mux_pad = gst_element_get_pad (mux, "audio_0");
285 if (gst_pad_link (audio_src_pad, mux_pad) != GST_PAD_LINK_OK) {
286 g_warning ("Fail link audio and mux");
290 gst_object_unref (audio_src_pad);
291 gst_object_unref (mux_pad);
292 audio_src_pad = NULL;
295 video_src_pad = gst_element_get_pad (vbin, "src");
296 mux_pad = gst_element_get_pad (mux, "video_0");
297 if (gst_pad_link (video_src_pad, mux_pad) != GST_PAD_LINK_OK) {
298 g_warning ("Fail link video and mux");
301 gst_object_unref (video_src_pad);
302 gst_object_unref (mux_pad);
303 video_src_pad = NULL;
307 gst_element_link (mux, fdsink);
309 bus = gst_pipeline_get_bus (GST_PIPELINE (pipe));
310 gst_bus_add_watch (bus, _pipeline_bus_cb, self);
311 gst_object_unref (bus);
313 g_signal_connect (G_OBJECT (decode),
315 G_CALLBACK (_decodebin_new_pad_cb),
318 g_signal_connect (G_OBJECT (decode),
320 G_CALLBACK (_decodebin_unknown_type_cb),
323 g_debug ("Setting pipe to PAUSE");
331 gst_element_set_state (pipe, GST_STATE_PAUSED);
332 g_debug ("End SETUP");
336 g_warning ("Invalid uri");
339 gst_object_unref (pipe);
342 gst_object_unref (src);
345 gst_object_unref (decode);
347 if (vscale_caps != NULL)
348 gst_caps_unref (vscale_caps);
351 gst_object_unref (vbin);
354 gst_object_unref (vqueue);
357 gst_object_unref (vrate);
360 gst_object_unref (vencode);
362 if (vqueue_src != NULL)
363 gst_object_unref (vqueue_src);
366 gst_object_unref (abin);
369 gst_object_unref (aqueue);
371 if (aconvert != NULL)
372 gst_object_unref (aconvert);
375 gst_object_unref (aencode);
377 if (aqueue_src != NULL)
378 gst_object_unref (aqueue_src);
380 if (video_src_pad != NULL) {
381 gst_object_unref (video_src_pad);
384 if (audio_src_pad != NULL) {
385 gst_object_unref (audio_src_pad);
389 gst_object_unref (mux);
392 if (mux_pad != NULL) {
393 gst_object_unref (mux_pad);
397 gst_object_unref (fdsink);
403 g_mencoder_play_stream (GMencoder *self)
405 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self);
407 g_return_val_if_fail (priv->ready == TRUE, FALSE);
409 if (gst_element_set_state (priv->pipe, GST_STATE_PLAYING) != GST_STATE_CHANGE_FAILURE) {
417 g_mencoder_pause_stream (GMencoder *self)
419 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self);
421 g_return_val_if_fail (priv->ready == TRUE, FALSE);
423 if (gst_element_set_state (priv->pipe, GST_STATE_PAUSED) != GST_STATE_CHANGE_FAILURE) {
431 g_mencoder_close_stream (GMencoder *self)
434 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (self);
436 g_return_if_fail (priv->ready == TRUE);
438 gst_element_set_state (priv->pipe, GST_STATE_NULL);
439 gst_object_unref (priv->pipe);
448 _pipeline_bus_cb (GstBus *bus,
452 switch (GST_MESSAGE_TYPE (msg))
454 case GST_MESSAGE_STATE_CHANGED:
458 GstState pendingstate;
460 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (user_data);
462 gst_message_parse_state_changed (msg, &oldstate,
463 &newstate, &pendingstate);
465 if (pendingstate != GST_STATE_VOID_PENDING)
468 if ((oldstate == GST_STATE_READY) &&
469 (newstate == GST_STATE_PAUSED)) {
471 g_signal_emit (user_data, g_mencoder_signals[PAUSED], 0);
474 g_signal_emit (user_data, g_mencoder_signals[READY], 0);
476 } else if ((oldstate == GST_STATE_PAUSED) &&
477 (newstate == GST_STATE_PLAYING)) {
478 g_signal_emit (user_data, g_mencoder_signals[PLAYING], 0);
479 } else if ((oldstate == GST_STATE_READY) &&
480 (newstate == GST_STATE_NULL)) {
481 g_signal_emit (user_data, g_mencoder_signals[STOPED], 0);
485 case GST_MESSAGE_ERROR:
491 gst_message_parse_error (msg, &error, &debug);
492 err_str = g_strdup_printf ("Error [%d] %s (%s)", error->code,
495 g_signal_emit (user_data, g_mencoder_signals[ERROR], 0, err_str);
497 g_clear_error (&error);
502 case GST_MESSAGE_EOS:
503 g_signal_emit (user_data, g_mencoder_signals[EOS], 0);
512 _decodebin_new_pad_cb (GstElement* object,
518 gchar *str_caps = NULL;
519 GMencoderPrivate *priv = G_MENCODER_GET_PRIVATE (user_data);
521 caps = gst_pad_get_caps (pad);
522 str_caps = gst_caps_to_string (caps);
523 g_debug ("CAPS : %s", str_caps);
525 if (strstr (str_caps, "audio") != NULL) {
526 GstPad *apad = gst_element_get_pad (priv->abin, "sink");
527 g_debug ("Linked with Audio");
528 gst_pad_link (pad, apad);
529 gst_object_unref (apad);
530 } else if (strstr (str_caps, "video") != NULL) {
531 GstPad *vpad = gst_element_get_pad (priv->vbin, "sink");
532 g_debug ("Linked with Video");
533 gst_pad_link (pad, vpad);
534 gst_object_unref (vpad);
536 g_warning ("invalid caps %s", str_caps);
540 gst_caps_unref (caps);
545 _decodebin_unknown_type_cb (GstElement* object,
550 g_warning ("Unknown Type");