2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
27 #include "gstplaybasebin.h"
29 GST_DEBUG_CATEGORY_STATIC (gst_play_bin_debug);
30 #define GST_CAT_DEFAULT gst_play_bin_debug
32 #define GST_TYPE_PLAY_BIN (gst_play_bin_get_type())
33 #define GST_PLAY_BIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PLAY_BIN,GstPlayBin))
34 #define GST_PLAY_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PLAY_BIN,GstPlayBinClass))
35 #define GST_IS_PLAY_BIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PLAY_BIN))
36 #define GST_IS_PLAY_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PLAY_BIN))
38 #define VOLUME_MAX_DOUBLE 4.0
40 typedef struct _GstPlayBin GstPlayBin;
41 typedef struct _GstPlayBinClass GstPlayBinClass;
45 GstPlayBaseBin parent;
47 /* the configurable elements */
49 GstElement *audio_sink;
50 GstElement *video_sink;
51 GstElement *visualisation;
52 GstElement *volume_element;
53 GstElement *textoverlay_element;
56 /* these are the currently active sinks */
59 /* the last captured frame for snapshots */
62 /* our cache for the sinks */
65 /* font description */
69 struct _GstPlayBinClass
71 GstPlayBaseBinClass parent_class;
92 static void gst_play_bin_class_init (GstPlayBinClass * klass);
93 static void gst_play_bin_init (GstPlayBin * play_bin);
94 static void gst_play_bin_dispose (GObject * object);
96 static void setup_sinks (GstPlayBaseBin * play_base_bin,
97 GstPlayBaseGroup * group);
98 static void remove_sinks (GstPlayBin * play_bin);
100 static void gst_play_bin_set_property (GObject * object, guint prop_id,
101 const GValue * value, GParamSpec * spec);
102 static void gst_play_bin_get_property (GObject * object, guint prop_id,
103 GValue * value, GParamSpec * spec);
105 static gboolean gst_play_bin_send_event (GstElement * element,
107 static GstStateChangeReturn gst_play_bin_change_state (GstElement * element,
108 GstStateChange transition);
110 static GstElementClass *parent_class;
112 //static guint gst_play_bin_signals[LAST_SIGNAL] = { 0 };
114 static GstElementDetails gst_play_bin_details = {
116 "Generic/Bin/Player",
117 "Autoplug and play media from an uri",
118 "Wim Taymans <wim@fluendo.com>"
122 gst_play_bin_get_type (void)
124 static GType gst_play_bin_type = 0;
126 if (!gst_play_bin_type) {
127 static const GTypeInfo gst_play_bin_info = {
128 sizeof (GstPlayBinClass),
131 (GClassInitFunc) gst_play_bin_class_init,
136 (GInstanceInitFunc) gst_play_bin_init,
140 gst_play_bin_type = g_type_register_static (GST_TYPE_PLAY_BASE_BIN,
141 "GstPlayBin", &gst_play_bin_info, 0);
144 return gst_play_bin_type;
148 gst_play_bin_class_init (GstPlayBinClass * klass)
150 GObjectClass *gobject_klass;
151 GstElementClass *gstelement_klass;
152 GstBinClass *gstbin_klass;
153 GstPlayBaseBinClass *playbasebin_klass;
155 gobject_klass = (GObjectClass *) klass;
156 gstelement_klass = (GstElementClass *) klass;
157 gstbin_klass = (GstBinClass *) klass;
158 playbasebin_klass = (GstPlayBaseBinClass *) klass;
160 parent_class = g_type_class_ref (gst_play_base_bin_get_type ());
162 gobject_klass->set_property = gst_play_bin_set_property;
163 gobject_klass->get_property = gst_play_bin_get_property;
165 g_object_class_install_property (gobject_klass, ARG_VIDEO_SINK,
166 g_param_spec_object ("video-sink", "Video Sink",
167 "the video output element to use (NULL = default sink)",
168 GST_TYPE_ELEMENT, G_PARAM_READWRITE));
169 g_object_class_install_property (gobject_klass, ARG_AUDIO_SINK,
170 g_param_spec_object ("audio-sink", "Audio Sink",
171 "the audio output element to use (NULL = default sink)",
172 GST_TYPE_ELEMENT, G_PARAM_READWRITE));
173 g_object_class_install_property (gobject_klass, ARG_VIS_PLUGIN,
174 g_param_spec_object ("vis-plugin", "Vis plugin",
175 "the visualization element to use (NULL = none)",
176 GST_TYPE_ELEMENT, G_PARAM_READWRITE));
177 g_object_class_install_property (gobject_klass, ARG_VOLUME,
178 g_param_spec_double ("volume", "volume", "volume",
179 0.0, VOLUME_MAX_DOUBLE, 1.0, G_PARAM_READWRITE));
180 g_object_class_install_property (gobject_klass, ARG_FRAME,
181 gst_param_spec_mini_object ("frame", "Frame",
182 "The last frame (NULL = no video available)",
183 GST_TYPE_BUFFER, G_PARAM_READABLE));
184 g_object_class_install_property (gobject_klass, ARG_FONT_DESC,
185 g_param_spec_string ("subtitle-font-desc",
186 "Subtitle font description",
187 "Pango font description of font "
188 "to be used for subtitle rendering", NULL, G_PARAM_WRITABLE));
190 gobject_klass->dispose = GST_DEBUG_FUNCPTR (gst_play_bin_dispose);
192 gst_element_class_set_details (gstelement_klass, &gst_play_bin_details);
194 gstelement_klass->change_state =
195 GST_DEBUG_FUNCPTR (gst_play_bin_change_state);
196 gstelement_klass->send_event = GST_DEBUG_FUNCPTR (gst_play_bin_send_event);
198 playbasebin_klass->setup_output_pads = setup_sinks;
202 gst_play_bin_init (GstPlayBin * play_bin)
204 play_bin->video_sink = NULL;
205 play_bin->audio_sink = NULL;
206 play_bin->visualisation = NULL;
207 play_bin->volume_element = NULL;
208 play_bin->textoverlay_element = NULL;
209 play_bin->volume = 1.0;
210 play_bin->sinks = NULL;
211 play_bin->frame = NULL;
212 play_bin->font_desc = NULL;
213 play_bin->cache = g_hash_table_new_full (g_str_hash, g_str_equal,
214 NULL, (GDestroyNotify) gst_object_unref);
218 gst_play_bin_dispose (GObject * object)
220 GstPlayBin *play_bin;
222 play_bin = GST_PLAY_BIN (object);
224 if (play_bin->cache != NULL) {
225 remove_sinks (play_bin);
226 g_hash_table_destroy (play_bin->cache);
227 play_bin->cache = NULL;
230 if (play_bin->audio_sink != NULL) {
231 gst_object_unref (play_bin->audio_sink);
232 play_bin->audio_sink = NULL;
234 if (play_bin->video_sink != NULL) {
235 gst_object_unref (play_bin->video_sink);
236 play_bin->video_sink = NULL;
238 if (play_bin->visualisation != NULL) {
239 gst_object_unref (play_bin->visualisation);
240 play_bin->visualisation = NULL;
242 g_free (play_bin->font_desc);
243 play_bin->font_desc = NULL;
245 G_OBJECT_CLASS (parent_class)->dispose (object);
250 gst_play_bin_set_property (GObject * object, guint prop_id,
251 const GValue * value, GParamSpec * pspec)
253 GstPlayBin *play_bin;
255 g_return_if_fail (GST_IS_PLAY_BIN (object));
257 play_bin = GST_PLAY_BIN (object);
261 if (play_bin->video_sink != NULL) {
262 gst_object_unref (play_bin->video_sink);
264 play_bin->video_sink = g_value_get_object (value);
265 if (play_bin->video_sink != NULL) {
266 gst_object_ref (play_bin->video_sink);
267 gst_object_sink (GST_OBJECT (play_bin->video_sink));
269 /* when changing the videosink, we just remove the
270 * video pipeline from the cache so that it will be
271 * regenerated with the new sink element */
272 g_hash_table_remove (play_bin->cache, "vbin");
275 if (play_bin->audio_sink != NULL) {
276 gst_object_unref (play_bin->audio_sink);
278 play_bin->audio_sink = g_value_get_object (value);
279 if (play_bin->audio_sink != NULL) {
280 gst_object_ref (play_bin->audio_sink);
281 gst_object_sink (GST_OBJECT (play_bin->audio_sink));
283 g_hash_table_remove (play_bin->cache, "abin");
286 if (play_bin->visualisation != NULL) {
287 gst_object_unref (play_bin->visualisation);
289 play_bin->visualisation = g_value_get_object (value);
290 if (play_bin->visualisation != NULL) {
291 gst_object_ref (play_bin->visualisation);
292 gst_object_sink (GST_OBJECT (play_bin->visualisation));
296 play_bin->volume = g_value_get_double (value);
297 if (play_bin->volume_element) {
298 g_object_set (G_OBJECT (play_bin->volume_element), "volume",
299 play_bin->volume, NULL);
303 g_free (play_bin->font_desc);
304 play_bin->font_desc = g_strdup (g_value_get_string (value));
305 if (play_bin->textoverlay_element) {
306 g_object_set (G_OBJECT (play_bin->textoverlay_element),
307 "font-desc", g_value_get_string (value), NULL);
311 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
317 gst_play_bin_get_property (GObject * object, guint prop_id, GValue * value,
320 GstPlayBin *play_bin;
322 g_return_if_fail (GST_IS_PLAY_BIN (object));
324 play_bin = GST_PLAY_BIN (object);
328 g_value_set_object (value, play_bin->video_sink);
331 g_value_set_object (value, play_bin->audio_sink);
334 g_value_set_object (value, play_bin->visualisation);
337 g_value_set_double (value, play_bin->volume);
340 gst_value_set_mini_object (value, GST_MINI_OBJECT (play_bin->frame));
343 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
348 /* signal fired when the identity has received a new buffer. This is used for
349 * making screenshots.
352 handoff (GstElement * identity, GstBuffer * frame, gpointer data)
354 GstPlayBin *play_bin = GST_PLAY_BIN (data);
356 if (play_bin->frame) {
357 gst_buffer_unref (play_bin->frame);
359 play_bin->frame = gst_buffer_ref (frame);
362 /* make the element (bin) that contains the elements needed to perform
363 * video display. We connect a handoff signal to identity so that we
364 * can grab snapshots. Identity's sinkpad is ghosted to vbin.
366 * +-------------------------------------------------------------+
368 * | +--------+ +----------+ +----------+ +---------+ |
369 * | |identity| |colorspace| |videoscale| |videosink| |
370 * | +-sink src-sink src-sink src-sink | |
371 * | | +---+----+ +----------+ +----------+ +---------+ |
373 * +----------|--------------------------------------------------+
377 gen_video_element (GstPlayBin * play_bin)
384 GstElement *identity;
387 /* first see if we have it in the cache */
388 element = g_hash_table_lookup (play_bin->cache, "vbin");
389 if (element != NULL) {
393 element = gst_bin_new ("vbin");
394 identity = gst_element_factory_make ("identity", "id");
395 g_object_set (identity, "silent", TRUE, NULL);
396 g_signal_connect (identity, "handoff", G_CALLBACK (handoff), play_bin);
397 conv = gst_element_factory_make ("ffmpegcolorspace", "vconv");
398 scale = gst_element_factory_make ("videoscale", "vscale");
399 if (play_bin->video_sink) {
400 sink = play_bin->video_sink;
402 sink = gst_element_factory_make ("autovideosink", "videosink");
404 g_warning ("could not create autovideosink element");
407 gst_object_ref (sink);
408 g_hash_table_insert (play_bin->cache, "video_sink", sink);
410 gst_bin_add (GST_BIN (element), identity);
411 gst_bin_add (GST_BIN (element), conv);
412 gst_bin_add (GST_BIN (element), scale);
413 gst_bin_add (GST_BIN (element), sink);
414 gst_element_link_pads (identity, "src", conv, "sink");
415 gst_element_link_pads (conv, "src", scale, "sink");
416 gst_element_link_pads (scale, "src", sink, "sink");
418 pad = gst_element_get_pad (identity, "sink");
419 gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
420 gst_object_unref (pad);
422 gst_element_set_state (element, GST_STATE_READY);
424 /* since we're gonna add it to a bin but don't want to lose it,
425 * we keep a reference. */
426 gst_object_ref (element);
427 g_hash_table_insert (play_bin->cache, "vbin", element);
432 /* make an element for playback of video with subtitles embedded.
434 * +--------------------------------------------------+
435 * | tbin +-------------+ |
436 * | +-----+ | textoverlay | +------+ |
437 * | | csp | +--video_sink | | vbin | |
438 * video_sink-sink src+ +-text_sink src-sink | |
439 * | +-----+ | +-------------+ +------+ |
440 * text_sink-------------+ |
441 * +--------------------------------------------------+
445 gen_text_element (GstPlayBin * play_bin)
447 GstElement *element, *csp, *overlay, *vbin;
450 overlay = gst_element_factory_make ("textoverlay", "overlay");
451 g_object_set (G_OBJECT (overlay),
452 "halign", "center", "valign", "bottom", NULL);
453 play_bin->textoverlay_element = overlay;
454 if (play_bin->font_desc) {
455 g_object_set (G_OBJECT (play_bin->textoverlay_element),
456 "font-desc", play_bin->font_desc, NULL);
458 vbin = gen_video_element (play_bin);
460 g_warning ("No overlay (pango) element, subtitles disabled");
463 csp = gst_element_factory_make ("ffmpegcolorspace", "subtitlecsp");
464 element = gst_bin_new ("textbin");
465 gst_element_link_many (csp, overlay, vbin, NULL);
466 gst_bin_add_many (GST_BIN (element), csp, overlay, vbin, NULL);
468 pad = gst_element_get_pad (overlay, "text_sink");
469 #define gst_element_add_ghost_pad(element, pad, name) \
470 gst_element_add_pad (element, gst_ghost_pad_new (name, pad))
471 gst_element_add_ghost_pad (element, pad, "text_sink");
472 gst_object_unref (pad);
474 pad = gst_element_get_pad (csp, "sink");
475 gst_element_add_ghost_pad (element, pad, "sink");
476 gst_object_unref (pad);
481 /* make the element (bin) that contains the elements needed to perform
484 * +-------------------------------------------------------------+
486 * | +---------+ +----------+ +---------+ +---------+ |
487 * | |audioconv| |audioscale| | volume | |audiosink| |
488 * | +-sink src-sink src-sink src-sink | |
489 * | | +---------+ +----------+ +---------+ +---------+ |
491 * +-------------------------------------------------------------+
495 gen_audio_element (GstPlayBin * play_bin)
504 element = g_hash_table_lookup (play_bin->cache, "abin");
505 if (element != NULL) {
508 element = gst_bin_new ("abin");
509 conv = gst_element_factory_make ("audioconvert", "aconv");
510 scale = gst_element_factory_make ("audioscale", "ascale");
512 volume = gst_element_factory_make ("volume", "volume");
513 g_object_set (G_OBJECT (volume), "volume", play_bin->volume, NULL);
514 play_bin->volume_element = volume;
516 if (play_bin->audio_sink) {
517 sink = play_bin->audio_sink;
519 sink = gst_element_factory_make ("autoaudiosink", "audiosink");
521 g_warning ("could not create autoaudiosink element");
523 play_bin->audio_sink = GST_ELEMENT (gst_object_ref (sink));
526 gst_object_ref (sink);
527 g_hash_table_insert (play_bin->cache, "audio_sink", sink);
529 gst_bin_add (GST_BIN (element), conv);
530 //gst_bin_add (GST_BIN (element), scale);
531 gst_bin_add (GST_BIN (element), volume);
532 gst_bin_add (GST_BIN (element), sink);
534 gst_element_link_pads (conv, "src", /*scale, "sink");
535 gst_element_link_pads (scale, "src", */ volume, "sink");
536 gst_element_link_pads (volume, "src", sink, "sink");
538 pad = gst_element_get_pad (conv, "sink");
539 gst_element_add_ghost_pad (element, pad, "sink");
540 gst_object_unref (pad);
542 gst_element_set_state (element, GST_STATE_READY);
544 /* since we're gonna add it to a bin but don't want to lose it,
545 * we keep a reference. */
546 gst_object_ref (element);
547 g_hash_table_insert (play_bin->cache, "abin", element);
552 /* make the element (bin) that contains the elements needed to perform
553 * visualisation ouput. The idea is to split the audio using tee, then
554 * sending the output to the regular audio bin and the other output to
555 * the vis plugin that transforms it into a video that is rendered with the
556 * normal video bin. The video bin is run in a thread to make sure it does
557 * not block the audio playback pipeline.
559 * +--------------------------------------------------------------------------+
561 * | +------+ +----------------+ |
562 * | | tee | | abin ... | |
563 * | +-sink src-sink | |
564 * | | | | +----------------+ +-------------------+ |
565 * | | | | | vthread | |
566 * | | | | +---------+ +------+ +------+ | +--------------+ | |
567 * | | | | |audioconv| | vis | |vqueue| | | vbin ... | | |
568 * | | | src-sink src-sink src-sink src-sink | | |
569 * | | | | +---------+ +------+ +------+ | +--------------+ | |
570 * | | | | +-------------------+ |
573 +--------------------------------------------------------------------------+
576 gen_vis_element (GstPlayBin * play_bin)
584 GstElement *vqueue, *aqueue;
587 element = gst_bin_new ("visbin");
588 tee = gst_element_factory_make ("tee", "tee");
590 vqueue = gst_element_factory_make ("queue", "vqueue");
591 aqueue = gst_element_factory_make ("queue", "aqueue");
593 asink = gen_audio_element (play_bin);
594 vsink = gen_video_element (play_bin);
596 gst_bin_add (GST_BIN (element), asink);
597 gst_bin_add (GST_BIN (element), vqueue);
598 gst_bin_add (GST_BIN (element), aqueue);
599 gst_bin_add (GST_BIN (element), vsink);
600 gst_bin_add (GST_BIN (element), tee);
602 conv = gst_element_factory_make ("audioconvert", "aconv");
603 if (play_bin->visualisation) {
604 gst_object_ref (play_bin->visualisation);
605 vis = play_bin->visualisation;
607 vis = gst_element_factory_make ("goom", "vis");
610 gst_bin_add (GST_BIN (element), conv);
611 gst_bin_add (GST_BIN (element), vis);
613 gst_element_link_pads (conv, "src", vis, "sink");
614 gst_element_link_pads (vis, "src", vqueue, "sink");
616 gst_element_link_pads (vqueue, "src", vsink, "sink");
618 pad = gst_element_get_pad (aqueue, "sink");
619 rpad = gst_element_get_request_pad (tee, "src%d");
620 gst_pad_link (rpad, pad);
621 gst_object_unref (rpad);
622 gst_object_unref (pad);
623 gst_element_link_pads (aqueue, "src", asink, "sink");
625 pad = gst_element_get_pad (conv, "sink");
626 rpad = gst_element_get_request_pad (tee, "src%d");
627 gst_pad_link (rpad, pad);
628 gst_object_unref (rpad);
629 gst_object_unref (pad);
631 pad = gst_element_get_pad (tee, "sink");
632 gst_element_add_ghost_pad (element, pad, "sink");
633 gst_object_unref (pad);
638 /* get rid of all installed sinks */
640 remove_sinks (GstPlayBin * play_bin)
647 GST_DEBUG ("removesinks");
648 element = g_hash_table_lookup (play_bin->cache, "abin");
649 if (element != NULL) {
650 parent = gst_element_get_parent (element);
651 if (parent != NULL) {
652 /* we remove the element from the parent so that
653 * there is no unwanted state change when the parent
655 play_bin->sinks = g_list_remove (play_bin->sinks, element);
656 gst_bin_remove (GST_BIN (parent), element);
657 gst_object_unref (parent);
659 pad = gst_element_get_pad (element, "sink");
661 peer = gst_pad_get_peer (pad);
663 gst_pad_unlink (peer, pad);
664 gst_object_unref (peer);
666 gst_object_unref (pad);
669 element = g_hash_table_lookup (play_bin->cache, "vbin");
670 if (element != NULL) {
671 parent = gst_element_get_parent (element);
672 if (parent != NULL) {
673 play_bin->sinks = g_list_remove (play_bin->sinks, element);
674 gst_bin_remove (GST_BIN (parent), element);
675 gst_object_unref (parent);
677 pad = gst_element_get_pad (element, "sink");
679 peer = gst_pad_get_peer (pad);
681 gst_pad_unlink (peer, pad);
682 gst_object_unref (peer);
684 gst_object_unref (pad);
688 for (sinks = play_bin->sinks; sinks; sinks = g_list_next (sinks)) {
689 GstElement *element = GST_ELEMENT (sinks->data);
693 pad = gst_element_get_pad (element, "sink");
695 GST_LOG ("removing sink %p", element);
697 peer = gst_pad_get_peer (pad);
699 gst_pad_unlink (peer, pad);
700 gst_object_unref (peer);
702 gst_object_unref (pad);
704 gst_bin_remove (GST_BIN (play_bin), element);
706 g_list_free (play_bin->sinks);
707 play_bin->sinks = NULL;
709 /* FIXME: this is probably some refcounting problem */
710 if (play_bin->visualisation && GST_OBJECT_PARENT (play_bin->visualisation)) {
711 gst_bin_remove (GST_BIN (GST_OBJECT_PARENT (play_bin->visualisation)),
712 play_bin->visualisation);
713 gst_element_set_state (play_bin->visualisation, GST_STATE_NULL);
716 if (play_bin->frame) {
717 gst_buffer_unref (play_bin->frame);
718 play_bin->frame = NULL;
721 play_bin->textoverlay_element = NULL;
724 /* loop over the streams and set up the pipeline to play this
725 * media file. First we count the number of audio and video streams.
726 * If there is no video stream but there exists an audio stream,
727 * we install a visualisation pipeline.
729 * Also make sure to only connect the first audio and video pad. FIXME
730 * this should eventually be handled with a tuner interface so that
731 * one can switch the streams.
734 add_sink (GstPlayBin * play_bin, GstElement * sink, GstPad * srcpad)
737 GstPadLinkReturn res;
740 gst_bin_add (GST_BIN (play_bin), sink);
742 /* we found a sink for this stream, now try to install it */
743 sinkpad = gst_element_get_pad (sink, "sink");
744 res = gst_pad_link (srcpad, sinkpad);
745 gst_object_unref (sinkpad);
747 /* this is only for debugging */
748 parent = gst_pad_get_parent_element (srcpad);
750 GST_DEBUG ("Adding sink with state %d (parent: %d, peer: %d)",
751 GST_STATE (sink), GST_STATE (play_bin), GST_STATE (parent));
752 gst_object_unref (parent);
755 /* try to link the pad of the sink to the stream */
759 /* could not link this stream */
760 capsstr = gst_caps_to_string (gst_pad_get_caps (srcpad));
761 g_warning ("could not link %s: %d", capsstr, res);
764 gst_bin_remove (GST_BIN (play_bin), sink);
766 /* we got the sink succesfully linked, now keep the sink
767 * in out internal list */
768 play_bin->sinks = g_list_prepend (play_bin->sinks, sink);
769 gst_element_set_state (sink,
770 (GST_STATE (play_bin) == GST_STATE_PLAYING) ?
771 GST_STATE_PLAYING : GST_STATE_PAUSED);
778 setup_sinks (GstPlayBaseBin * play_base_bin, GstPlayBaseGroup * group)
780 GstPlayBin *play_bin = GST_PLAY_BIN (play_base_bin);
781 GList *streaminfo = NULL, *s;
782 gboolean need_vis = FALSE;
783 gboolean need_text = FALSE;
784 GstPad *textsrcpad = NULL, *textsinkpad = NULL, *pad;
787 /* get rid of existing sinks */
788 if (play_bin->sinks) {
789 remove_sinks (play_bin);
791 GST_DEBUG ("setupsinks");
793 /* find out what to do */
794 if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads > 0 &&
795 group->type[GST_STREAM_TYPE_TEXT - 1].npads > 0) {
797 } else if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads == 0 &&
798 group->type[GST_STREAM_TYPE_AUDIO - 1].npads > 0 &&
799 play_bin->visualisation != NULL) {
803 /* now actually connect everything */
804 g_object_get (G_OBJECT (play_base_bin), "stream-info", &streaminfo, NULL);
805 for (s = streaminfo; s; s = g_list_next (s)) {
806 GObject *obj = G_OBJECT (s->data);
810 g_object_get (obj, "type", &type, NULL);
811 g_object_get (obj, "object", &object, NULL);
815 if (group->type[GST_STREAM_TYPE_AUDIO - 1].npads > 0) {
817 sink = gen_vis_element (play_bin);
819 sink = gen_audio_element (play_bin);
821 pad = gst_element_get_pad (group->type[GST_STREAM_TYPE_AUDIO - 1].preroll,
823 add_sink (play_bin, sink, pad);
824 gst_object_unref (pad);
828 if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads > 0) {
830 sink = gen_text_element (play_bin);
832 textsinkpad = gst_element_get_pad (sink, "text_sink");
834 gst_element_get_pad (group->type[GST_STREAM_TYPE_TEXT - 1].preroll,
836 gst_pad_link (textsrcpad, textsinkpad);
837 gst_object_unref (textsinkpad);
838 gst_object_unref (textsrcpad);
840 sink = gen_video_element (play_bin);
842 pad = gst_element_get_pad (group->type[GST_STREAM_TYPE_VIDEO - 1].preroll,
844 add_sink (play_bin, sink, pad);
845 gst_object_unref (pad);
848 /* remove the sinks now, pipeline get_state will now wait for the
849 * sinks to preroll */
850 if (play_bin->fakesink) {
851 gst_bin_remove (GST_BIN (play_bin), play_bin->fakesink);
852 play_bin->fakesink = NULL;
857 gst_play_bin_send_event (GstElement * element, GstEvent * event)
859 GstPlayBin *play_bin;
861 gboolean res = FALSE;
863 play_bin = GST_PLAY_BIN (element);
865 sinks = play_bin->sinks;
867 GstElement *sink = GST_ELEMENT_CAST (sinks->data);
869 gst_event_ref (event);
870 if ((res = gst_element_send_event (sink, event)))
873 sinks = g_list_next (sinks);
876 gst_event_unref (event);
881 static GstStateChangeReturn
882 gst_play_bin_change_state (GstElement * element, GstStateChange transition)
884 GstStateChangeReturn ret;
885 GstPlayBin *play_bin;
887 play_bin = GST_PLAY_BIN (element);
890 switch (transition) {
891 case GST_STATE_CHANGE_READY_TO_PAUSED:
892 /* this really is the easiest way to make the state change return
893 * ASYNC until we added the sinks */
894 if (!play_bin->fakesink) {
895 play_bin->fakesink = gst_element_factory_make ("fakesink", "test");
896 gst_bin_add (GST_BIN (play_bin), play_bin->fakesink);
903 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
904 if (ret == GST_STATE_CHANGE_FAILURE)
907 switch (transition) {
908 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
909 /* Set audio sink state to NULL to release the sound device,
910 * but only if we own it (else we might be in chain-transition). */
911 //if (play_bin->audio_sink != NULL &&
912 // GST_STATE (play_bin->audio_sink) == GST_STATE_PAUSED) {
913 // gst_element_set_state (play_bin->audio_sink, GST_STATE_NULL);
916 case GST_STATE_CHANGE_PAUSED_TO_READY:
917 /* Check for NULL because the state transition may be done by
918 * gst_bin_dispose which is called by gst_play_bin_dispose, and in that
919 * case, we don't want to run remove_sinks.
920 * FIXME: should the NULL test be done in remove_sinks? Should we just
921 * set the state to NULL in gst_play_bin_dispose?
923 if (play_bin->cache != NULL) {
924 remove_sinks (play_bin);
926 if (play_bin->fakesink) {
927 gst_bin_remove (GST_BIN (play_bin), play_bin->fakesink);
928 play_bin->fakesink = NULL;
939 plugin_init (GstPlugin * plugin)
941 GST_DEBUG_CATEGORY_INIT (gst_play_bin_debug, "playbin", 0, "play bin");
943 return gst_element_register (plugin, "playbin", GST_RANK_NONE,
947 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
950 "player bin", plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN)