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);
104 static GstElementStateReturn gst_play_bin_change_state (GstElement * element);
106 static GstElementClass *parent_class;
108 //static guint gst_play_bin_signals[LAST_SIGNAL] = { 0 };
110 static GstElementDetails gst_play_bin_details = {
112 "Generic/Bin/Player",
113 "Autoplug and play media from an uri",
114 "Wim Taymans <wim@fluendo.com>"
118 gst_play_bin_get_type (void)
120 static GType gst_play_bin_type = 0;
122 if (!gst_play_bin_type) {
123 static const GTypeInfo gst_play_bin_info = {
124 sizeof (GstPlayBinClass),
127 (GClassInitFunc) gst_play_bin_class_init,
132 (GInstanceInitFunc) gst_play_bin_init,
136 gst_play_bin_type = g_type_register_static (GST_TYPE_PLAY_BASE_BIN,
137 "GstPlayBin", &gst_play_bin_info, 0);
140 return gst_play_bin_type;
144 gst_play_bin_class_init (GstPlayBinClass * klass)
146 GObjectClass *gobject_klass;
147 GstElementClass *gstelement_klass;
148 GstBinClass *gstbin_klass;
149 GstPlayBaseBinClass *playbasebin_klass;
151 gobject_klass = (GObjectClass *) klass;
152 gstelement_klass = (GstElementClass *) klass;
153 gstbin_klass = (GstBinClass *) klass;
154 playbasebin_klass = (GstPlayBaseBinClass *) klass;
156 parent_class = g_type_class_ref (gst_play_base_bin_get_type ());
158 gobject_klass->set_property = gst_play_bin_set_property;
159 gobject_klass->get_property = gst_play_bin_get_property;
161 g_object_class_install_property (gobject_klass, ARG_VIDEO_SINK,
162 g_param_spec_object ("video-sink", "Video Sink",
163 "the video output element to use (NULL = default sink)",
164 GST_TYPE_ELEMENT, G_PARAM_READWRITE));
165 g_object_class_install_property (gobject_klass, ARG_AUDIO_SINK,
166 g_param_spec_object ("audio-sink", "Audio Sink",
167 "the audio output element to use (NULL = default sink)",
168 GST_TYPE_ELEMENT, G_PARAM_READWRITE));
169 g_object_class_install_property (gobject_klass, ARG_VIS_PLUGIN,
170 g_param_spec_object ("vis-plugin", "Vis plugin",
171 "the visualization element to use (NULL = none)",
172 GST_TYPE_ELEMENT, G_PARAM_READWRITE));
173 g_object_class_install_property (gobject_klass, ARG_VOLUME,
174 g_param_spec_double ("volume", "volume", "volume",
175 0.0, VOLUME_MAX_DOUBLE, 1.0, G_PARAM_READWRITE));
176 g_object_class_install_property (gobject_klass, ARG_FRAME,
177 gst_param_spec_mini_object ("frame", "Frame",
178 "The last frame (NULL = no video available)",
179 GST_TYPE_BUFFER, G_PARAM_READABLE));
180 g_object_class_install_property (gobject_klass, ARG_FONT_DESC,
181 g_param_spec_string ("subtitle-font-desc",
182 "Subtitle font description",
183 "Pango font description of font "
184 "to be used for subtitle rendering", NULL, G_PARAM_WRITABLE));
186 gobject_klass->dispose = GST_DEBUG_FUNCPTR (gst_play_bin_dispose);
188 gst_element_class_set_details (gstelement_klass, &gst_play_bin_details);
190 gstelement_klass->change_state =
191 GST_DEBUG_FUNCPTR (gst_play_bin_change_state);
193 playbasebin_klass->setup_output_pads = setup_sinks;
197 gst_play_bin_init (GstPlayBin * play_bin)
199 play_bin->video_sink = NULL;
200 play_bin->audio_sink = NULL;
201 play_bin->visualisation = NULL;
202 play_bin->volume_element = NULL;
203 play_bin->textoverlay_element = NULL;
204 play_bin->volume = 1.0;
205 play_bin->sinks = NULL;
206 play_bin->frame = NULL;
207 play_bin->font_desc = NULL;
208 play_bin->cache = g_hash_table_new_full (g_str_hash, g_str_equal,
209 NULL, (GDestroyNotify) gst_object_unref);
213 gst_play_bin_dispose (GObject * object)
215 GstPlayBin *play_bin;
217 play_bin = GST_PLAY_BIN (object);
219 if (play_bin->cache != NULL) {
220 remove_sinks (play_bin);
221 g_hash_table_destroy (play_bin->cache);
222 play_bin->cache = NULL;
225 if (play_bin->audio_sink != NULL) {
226 gst_object_unref (play_bin->audio_sink);
227 play_bin->audio_sink = NULL;
229 if (play_bin->video_sink != NULL) {
230 gst_object_unref (play_bin->video_sink);
231 play_bin->video_sink = NULL;
233 if (play_bin->visualisation != NULL) {
234 gst_object_unref (play_bin->visualisation);
235 play_bin->visualisation = NULL;
237 g_free (play_bin->font_desc);
238 play_bin->font_desc = NULL;
240 G_OBJECT_CLASS (parent_class)->dispose (object);
245 gst_play_bin_set_property (GObject * object, guint prop_id,
246 const GValue * value, GParamSpec * pspec)
248 GstPlayBin *play_bin;
250 g_return_if_fail (GST_IS_PLAY_BIN (object));
252 play_bin = GST_PLAY_BIN (object);
256 if (play_bin->video_sink != NULL) {
257 gst_object_unref (play_bin->video_sink);
259 play_bin->video_sink = g_value_get_object (value);
260 if (play_bin->video_sink != NULL) {
261 gst_object_ref (play_bin->video_sink);
262 gst_object_sink (GST_OBJECT (play_bin->video_sink));
264 /* when changing the videosink, we just remove the
265 * video pipeline from the cache so that it will be
266 * regenerated with the new sink element */
267 g_hash_table_remove (play_bin->cache, "vbin");
270 if (play_bin->audio_sink != NULL) {
271 gst_object_unref (play_bin->audio_sink);
273 play_bin->audio_sink = g_value_get_object (value);
274 if (play_bin->audio_sink != NULL) {
275 gst_object_ref (play_bin->audio_sink);
276 gst_object_sink (GST_OBJECT (play_bin->audio_sink));
278 g_hash_table_remove (play_bin->cache, "abin");
281 if (play_bin->visualisation != NULL) {
282 gst_object_unref (play_bin->visualisation);
284 play_bin->visualisation = g_value_get_object (value);
285 if (play_bin->visualisation != NULL) {
286 gst_object_ref (play_bin->visualisation);
287 gst_object_sink (GST_OBJECT (play_bin->visualisation));
291 play_bin->volume = g_value_get_double (value);
292 if (play_bin->volume_element) {
293 g_object_set (G_OBJECT (play_bin->volume_element), "volume",
294 play_bin->volume, NULL);
298 g_free (play_bin->font_desc);
299 play_bin->font_desc = g_strdup (g_value_get_string (value));
300 if (play_bin->textoverlay_element) {
301 g_object_set (G_OBJECT (play_bin->textoverlay_element),
302 "font-desc", g_value_get_string (value), NULL);
306 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
312 gst_play_bin_get_property (GObject * object, guint prop_id, GValue * value,
315 GstPlayBin *play_bin;
317 g_return_if_fail (GST_IS_PLAY_BIN (object));
319 play_bin = GST_PLAY_BIN (object);
323 g_value_set_object (value, play_bin->video_sink);
326 g_value_set_object (value, play_bin->audio_sink);
329 g_value_set_object (value, play_bin->visualisation);
332 g_value_set_double (value, play_bin->volume);
335 gst_value_set_mini_object (value, GST_MINI_OBJECT (play_bin->frame));
338 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
343 /* signal fired when the identity has received a new buffer. This is used for
344 * making screenshots.
347 handoff (GstElement * identity, GstBuffer * frame, gpointer data)
349 GstPlayBin *play_bin = GST_PLAY_BIN (data);
351 if (play_bin->frame) {
352 gst_buffer_unref (play_bin->frame);
354 play_bin->frame = gst_buffer_ref (frame);
357 /* make the element (bin) that contains the elements needed to perform
358 * video display. We connect a handoff signal to identity so that we
359 * can grab snapshots. Identity's sinkpad is ghosted to vbin.
361 * +-------------------------------------------------------------+
363 * | +--------+ +----------+ +----------+ +---------+ |
364 * | |identity| |colorspace| |videoscale| |videosink| |
365 * | +-sink src-sink src-sink src-sink | |
366 * | | +---+----+ +----------+ +----------+ +---------+ |
368 * +----------|--------------------------------------------------+
372 gen_video_element (GstPlayBin * play_bin)
379 GstElement *identity;
382 /* first see if we have it in the cache */
383 element = g_hash_table_lookup (play_bin->cache, "vbin");
384 if (element != NULL) {
388 element = gst_bin_new ("vbin");
389 identity = gst_element_factory_make ("identity", "id");
390 g_object_set (identity, "silent", TRUE, NULL);
391 g_signal_connect (identity, "handoff", G_CALLBACK (handoff), play_bin);
392 conv = gst_element_factory_make ("ffmpegcolorspace", "vconv");
393 scale = gst_element_factory_make ("videoscale", "vscale");
394 if (play_bin->video_sink) {
395 sink = play_bin->video_sink;
397 sink = gst_element_factory_make ("autovideosink", "videosink");
399 gst_object_ref (sink);
400 g_hash_table_insert (play_bin->cache, "video_sink", sink);
402 gst_bin_add (GST_BIN (element), identity);
403 gst_bin_add (GST_BIN (element), conv);
404 gst_bin_add (GST_BIN (element), scale);
405 gst_bin_add (GST_BIN (element), sink);
406 gst_element_link_pads (identity, "src", conv, "sink");
407 gst_element_link_pads (conv, "src", scale, "sink");
408 gst_element_link_pads (scale, "src", sink, "sink");
410 pad = gst_element_get_pad (identity, "sink");
411 gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
412 gst_object_unref (pad);
414 gst_element_set_state (element, GST_STATE_READY);
416 /* since we're gonna add it to a bin but don't want to lose it,
417 * we keep a reference. */
418 gst_object_ref (element);
419 g_hash_table_insert (play_bin->cache, "vbin", element);
424 /* make an element for playback of video with subtitles embedded.
426 * +--------------------------------------------------+
427 * | tbin +-------------+ |
428 * | +-----+ | textoverlay | +------+ |
429 * | | csp | +--video_sink | | vbin | |
430 * video_sink-sink src+ +-text_sink src-sink | |
431 * | +-----+ | +-------------+ +------+ |
432 * text_sink-------------+ |
433 * +--------------------------------------------------+
437 gen_text_element (GstPlayBin * play_bin)
439 GstElement *element, *csp, *overlay, *vbin;
442 overlay = gst_element_factory_make ("textoverlay", "overlay");
443 g_object_set (G_OBJECT (overlay),
444 "halign", "center", "valign", "bottom", NULL);
445 play_bin->textoverlay_element = overlay;
446 if (play_bin->font_desc) {
447 g_object_set (G_OBJECT (play_bin->textoverlay_element),
448 "font-desc", play_bin->font_desc, NULL);
450 vbin = gen_video_element (play_bin);
452 g_warning ("No overlay (pango) element, subtitles disabled");
455 csp = gst_element_factory_make ("ffmpegcolorspace", "subtitlecsp");
456 element = gst_bin_new ("textbin");
457 gst_element_link_many (csp, overlay, vbin, NULL);
458 gst_bin_add_many (GST_BIN (element), csp, overlay, vbin, NULL);
460 pad = gst_element_get_pad (overlay, "text_sink");
461 #define gst_element_add_ghost_pad(element, pad, name) \
462 gst_element_add_pad (element, gst_ghost_pad_new (name, pad))
463 gst_element_add_ghost_pad (element, pad, "text_sink");
464 gst_object_unref (pad);
466 pad = gst_element_get_pad (csp, "sink");
467 gst_element_add_ghost_pad (element, pad, "sink");
468 gst_object_unref (pad);
473 /* make the element (bin) that contains the elements needed to perform
476 * +-------------------------------------------------------------+
478 * | +---------+ +----------+ +---------+ +---------+ |
479 * | |audioconv| |audioscale| | volume | |audiosink| |
480 * | +-sink src-sink src-sink src-sink | |
481 * | | +---------+ +----------+ +---------+ +---------+ |
483 * +-------------------------------------------------------------+
487 gen_audio_element (GstPlayBin * play_bin)
496 element = g_hash_table_lookup (play_bin->cache, "abin");
497 if (element != NULL) {
500 element = gst_bin_new ("abin");
501 conv = gst_element_factory_make ("audioconvert", "aconv");
502 scale = gst_element_factory_make ("audioscale", "ascale");
504 volume = gst_element_factory_make ("volume", "volume");
505 g_object_set (G_OBJECT (volume), "volume", play_bin->volume, NULL);
506 play_bin->volume_element = volume;
508 if (play_bin->audio_sink) {
509 sink = play_bin->audio_sink;
511 sink = gst_element_factory_make ("autoaudiosink", "audiosink");
512 play_bin->audio_sink = GST_ELEMENT (gst_object_ref (sink));
515 gst_object_ref (sink);
516 g_hash_table_insert (play_bin->cache, "audio_sink", sink);
518 gst_bin_add (GST_BIN (element), conv);
519 //gst_bin_add (GST_BIN (element), scale);
520 gst_bin_add (GST_BIN (element), volume);
521 gst_bin_add (GST_BIN (element), sink);
523 gst_element_link_pads (conv, "src", /*scale, "sink");
524 gst_element_link_pads (scale, "src", */ volume, "sink");
525 gst_element_link_pads (volume, "src", sink, "sink");
527 pad = gst_element_get_pad (conv, "sink");
528 gst_element_add_ghost_pad (element, pad, "sink");
529 gst_object_unref (pad);
531 gst_element_set_state (element, GST_STATE_READY);
533 /* since we're gonna add it to a bin but don't want to lose it,
534 * we keep a reference. */
535 gst_object_ref (element);
536 g_hash_table_insert (play_bin->cache, "abin", element);
541 /* make the element (bin) that contains the elements needed to perform
542 * visualisation ouput. The idea is to split the audio using tee, then
543 * sending the output to the regular audio bin and the other output to
544 * the vis plugin that transforms it into a video that is rendered with the
545 * normal video bin. The video bin is run in a thread to make sure it does
546 * not block the audio playback pipeline.
548 * +--------------------------------------------------------------------------+
550 * | +------+ +----------------+ |
551 * | | tee | | abin ... | |
552 * | +-sink src-sink | |
553 * | | | | +----------------+ +-------------------+ |
554 * | | | | | vthread | |
555 * | | | | +---------+ +------+ +------+ | +--------------+ | |
556 * | | | | |audioconv| | vis | |vqueue| | | vbin ... | | |
557 * | | | src-sink src-sink src-sink src-sink | | |
558 * | | | | +---------+ +------+ +------+ | +--------------+ | |
559 * | | | | +-------------------+ |
562 +--------------------------------------------------------------------------+
565 gen_vis_element (GstPlayBin * play_bin)
573 GstElement *vqueue, *aqueue;
576 element = gst_bin_new ("visbin");
577 tee = gst_element_factory_make ("tee", "tee");
579 vqueue = gst_element_factory_make ("queue", "vqueue");
580 aqueue = gst_element_factory_make ("queue", "aqueue");
582 asink = gen_audio_element (play_bin);
583 vsink = gen_video_element (play_bin);
585 gst_bin_add (GST_BIN (element), asink);
586 gst_bin_add (GST_BIN (element), vqueue);
587 gst_bin_add (GST_BIN (element), aqueue);
588 gst_bin_add (GST_BIN (element), vsink);
589 gst_bin_add (GST_BIN (element), tee);
591 conv = gst_element_factory_make ("audioconvert", "aconv");
592 if (play_bin->visualisation) {
593 gst_object_ref (play_bin->visualisation);
594 vis = play_bin->visualisation;
596 vis = gst_element_factory_make ("goom", "vis");
599 gst_bin_add (GST_BIN (element), conv);
600 gst_bin_add (GST_BIN (element), vis);
602 gst_element_link_pads (conv, "src", vis, "sink");
603 gst_element_link_pads (vis, "src", vqueue, "sink");
605 gst_element_link_pads (vqueue, "src", vsink, "sink");
607 pad = gst_element_get_pad (aqueue, "sink");
608 rpad = gst_element_get_request_pad (tee, "src%d");
609 gst_pad_link (rpad, pad);
610 gst_object_unref (rpad);
611 gst_object_unref (pad);
612 gst_element_link_pads (aqueue, "src", asink, "sink");
614 pad = gst_element_get_pad (conv, "sink");
615 rpad = gst_element_get_request_pad (tee, "src%d");
616 gst_pad_link (rpad, pad);
617 gst_object_unref (rpad);
618 gst_object_unref (pad);
620 pad = gst_element_get_pad (tee, "sink");
621 gst_element_add_ghost_pad (element, pad, "sink");
622 gst_object_unref (pad);
627 /* get rid of all installed sinks */
629 remove_sinks (GstPlayBin * play_bin)
636 GST_DEBUG ("removesinks");
637 element = g_hash_table_lookup (play_bin->cache, "abin");
638 if (element != NULL) {
639 parent = gst_element_get_parent (element);
640 if (parent != NULL) {
641 /* we remove the element from the parent so that
642 * there is no unwanted state change when the parent
644 play_bin->sinks = g_list_remove (play_bin->sinks, element);
645 gst_bin_remove (GST_BIN (parent), element);
646 gst_object_unref (parent);
648 pad = gst_element_get_pad (element, "sink");
650 peer = gst_pad_get_peer (pad);
652 gst_pad_unlink (peer, pad);
653 gst_object_unref (peer);
655 gst_object_unref (pad);
658 element = g_hash_table_lookup (play_bin->cache, "vbin");
659 if (element != NULL) {
660 parent = gst_element_get_parent (element);
661 if (parent != NULL) {
662 play_bin->sinks = g_list_remove (play_bin->sinks, element);
663 gst_bin_remove (GST_BIN (parent), element);
664 gst_object_unref (parent);
666 pad = gst_element_get_pad (element, "sink");
668 peer = gst_pad_get_peer (pad);
670 gst_pad_unlink (peer, pad);
671 gst_object_unref (peer);
673 gst_object_unref (pad);
677 for (sinks = play_bin->sinks; sinks; sinks = g_list_next (sinks)) {
678 GstElement *element = GST_ELEMENT (sinks->data);
682 pad = gst_element_get_pad (element, "sink");
684 GST_LOG ("removing sink %p", element);
686 peer = gst_pad_get_peer (pad);
688 gst_pad_unlink (peer, pad);
689 gst_object_unref (peer);
691 gst_object_unref (pad);
693 gst_bin_remove (GST_BIN (play_bin), element);
695 g_list_free (play_bin->sinks);
696 play_bin->sinks = NULL;
698 /* FIXME: this is probably some refcounting problem */
699 if (play_bin->visualisation && GST_OBJECT_PARENT (play_bin->visualisation)) {
700 gst_bin_remove (GST_BIN (GST_OBJECT_PARENT (play_bin->visualisation)),
701 play_bin->visualisation);
702 gst_element_set_state (play_bin->visualisation, GST_STATE_NULL);
705 if (play_bin->frame) {
706 gst_buffer_unref (play_bin->frame);
707 play_bin->frame = NULL;
710 play_bin->textoverlay_element = NULL;
713 /* loop over the streams and set up the pipeline to play this
714 * media file. First we count the number of audio and video streams.
715 * If there is no video stream but there exists an audio stream,
716 * we install a visualisation pipeline.
718 * Also make sure to only connect the first audio and video pad. FIXME
719 * this should eventually be handled with a tuner interface so that
720 * one can switch the streams.
723 add_sink (GstPlayBin * play_bin, GstElement * sink, GstPad * srcpad)
726 GstPadLinkReturn res;
729 gst_bin_add (GST_BIN (play_bin), sink);
731 /* we found a sink for this stream, now try to install it */
732 sinkpad = gst_element_get_pad (sink, "sink");
733 res = gst_pad_link (srcpad, sinkpad);
734 gst_object_unref (sinkpad);
736 /* this is only for debugging */
737 parent = gst_pad_get_parent_element (srcpad);
739 GST_DEBUG ("Adding sink with state %d (parent: %d, peer: %d)",
740 GST_STATE (sink), GST_STATE (play_bin), GST_STATE (parent));
741 gst_object_unref (parent);
744 /* try to link the pad of the sink to the stream */
748 /* could not link this stream */
749 capsstr = gst_caps_to_string (gst_pad_get_caps (srcpad));
750 g_warning ("could not link %s: %d", capsstr, res);
753 gst_bin_remove (GST_BIN (play_bin), sink);
755 /* we got the sink succesfully linked, now keep the sink
756 * in out internal list */
757 play_bin->sinks = g_list_prepend (play_bin->sinks, sink);
758 gst_element_set_state (sink,
759 (GST_STATE (play_bin) == GST_STATE_PLAYING) ?
760 GST_STATE_PLAYING : GST_STATE_PAUSED);
767 setup_sinks (GstPlayBaseBin * play_base_bin, GstPlayBaseGroup * group)
769 GstPlayBin *play_bin = GST_PLAY_BIN (play_base_bin);
770 GList *streaminfo = NULL, *s;
771 gboolean need_vis = FALSE;
772 gboolean need_text = FALSE;
773 GstPad *textsrcpad = NULL, *textsinkpad = NULL, *pad;
776 /* get rid of existing sinks */
777 if (play_bin->sinks) {
778 remove_sinks (play_bin);
780 GST_DEBUG ("setupsinks");
782 /* find out what to do */
783 if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads > 0 &&
784 group->type[GST_STREAM_TYPE_TEXT - 1].npads > 0) {
786 } else if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads == 0 &&
787 group->type[GST_STREAM_TYPE_AUDIO - 1].npads > 0 &&
788 play_bin->visualisation != NULL) {
792 /* now actually connect everything */
793 g_object_get (G_OBJECT (play_base_bin), "stream-info", &streaminfo, NULL);
794 for (s = streaminfo; s; s = g_list_next (s)) {
795 GObject *obj = G_OBJECT (s->data);
799 g_object_get (obj, "type", &type, NULL);
800 g_object_get (obj, "object", &object, NULL);
804 if (group->type[GST_STREAM_TYPE_AUDIO - 1].npads > 0) {
806 sink = gen_vis_element (play_bin);
808 sink = gen_audio_element (play_bin);
810 pad = gst_element_get_pad (group->type[GST_STREAM_TYPE_AUDIO - 1].preroll,
812 add_sink (play_bin, sink, pad);
813 gst_object_unref (pad);
817 if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads > 0) {
819 sink = gen_text_element (play_bin);
821 textsinkpad = gst_element_get_pad (sink, "text_sink");
823 gst_element_get_pad (group->type[GST_STREAM_TYPE_TEXT - 1].preroll,
825 gst_pad_link (textsrcpad, textsinkpad);
826 gst_object_unref (textsinkpad);
827 gst_object_unref (textsrcpad);
829 sink = gen_video_element (play_bin);
831 pad = gst_element_get_pad (group->type[GST_STREAM_TYPE_VIDEO - 1].preroll,
833 add_sink (play_bin, sink, pad);
834 gst_object_unref (pad);
837 /* remove the sinks now, pipeline get_state will now wait for the
838 * sinks to preroll */
839 if (play_bin->fakesink) {
840 gst_bin_remove (GST_BIN (play_bin), play_bin->fakesink);
841 play_bin->fakesink = NULL;
845 static GstElementStateReturn
846 gst_play_bin_change_state (GstElement * element)
848 GstElementStateReturn ret;
849 GstPlayBin *play_bin;
852 play_bin = GST_PLAY_BIN (element);
854 transition = GST_STATE_TRANSITION (element);
856 switch (transition) {
857 case GST_STATE_READY_TO_PAUSED:
858 /* this really is the easiest way to make the state change return
859 * ASYNC until we added the sinks */
860 if (!play_bin->fakesink) {
861 play_bin->fakesink = gst_element_factory_make ("fakesink", "test");
862 gst_bin_add (GST_BIN (play_bin), play_bin->fakesink);
869 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element);
870 if (ret == GST_STATE_FAILURE)
873 switch (transition) {
874 case GST_STATE_PLAYING_TO_PAUSED:
875 /* Set audio sink state to NULL to release the sound device,
876 * but only if we own it (else we might be in chain-transition). */
877 //if (play_bin->audio_sink != NULL &&
878 // GST_STATE (play_bin->audio_sink) == GST_STATE_PAUSED) {
879 // gst_element_set_state (play_bin->audio_sink, GST_STATE_NULL);
882 case GST_STATE_PAUSED_TO_READY:
883 /* Check for NULL because the state transition may be done by
884 * gst_bin_dispose which is called by gst_play_bin_dispose, and in that
885 * case, we don't want to run remove_sinks.
886 * FIXME: should the NULL test be done in remove_sinks? Should we just
887 * set the state to NULL in gst_play_bin_dispose?
889 if (play_bin->cache != NULL) {
890 remove_sinks (play_bin);
892 if (play_bin->fakesink) {
893 gst_bin_remove (GST_BIN (play_bin), play_bin->fakesink);
894 play_bin->fakesink = NULL;
905 plugin_init (GstPlugin * plugin)
907 GST_DEBUG_CATEGORY_INIT (gst_play_bin_debug, "playbin", 0, "play bin");
909 return gst_element_register (plugin, "playbin", GST_RANK_NONE,
913 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
916 "player bin", plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN)