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 */
48 GstElement *audio_sink;
49 GstElement *video_sink;
50 GstElement *visualisation;
51 GstElement *volume_element;
52 GstElement *textoverlay_element;
55 /* these are the currently active sinks */
58 /* these are the sink elements used for seeking/query etc.. */
61 /* the last captured frame for snapshots */
64 /* our cache for the sinks */
67 /* boolean to see if we're currently switching groups */
68 gboolean group_switch;
70 /* font description */
74 struct _GstPlayBinClass
76 GstPlayBaseBinClass parent_class;
97 static void gst_play_bin_class_init (GstPlayBinClass * klass);
98 static void gst_play_bin_init (GstPlayBin * play_bin);
99 static void gst_play_bin_dispose (GObject * object);
101 static void group_switch (GstPlayBaseBin * play_base_bin);
102 static void setup_sinks (GstPlayBaseBin * play_base_bin);
103 static void remove_sinks (GstPlayBin * play_bin);
105 static void gst_play_bin_set_property (GObject * object, guint prop_id,
106 const GValue * value, GParamSpec * spec);
107 static void gst_play_bin_get_property (GObject * object, guint prop_id,
108 GValue * value, GParamSpec * spec);
109 static GstElementStateReturn gst_play_bin_change_state (GstElement * element);
111 static gboolean gst_play_bin_send_event (GstElement * element,
113 static const GstQueryType *gst_play_bin_get_query_types (GstElement * element);
114 static gboolean gst_play_bin_query (GstElement * element, GstQuery * query);
117 static GstElementClass *parent_class;
119 //static guint gst_play_bin_signals[LAST_SIGNAL] = { 0 };
121 static GstElementDetails gst_play_bin_details = {
123 "Generic/Bin/Player",
124 "Autoplug and play media from an uri",
125 "Wim Taymans <wim@fluendo.com>"
129 gst_play_bin_get_type (void)
131 static GType gst_play_bin_type = 0;
133 if (!gst_play_bin_type) {
134 static const GTypeInfo gst_play_bin_info = {
135 sizeof (GstPlayBinClass),
138 (GClassInitFunc) gst_play_bin_class_init,
143 (GInstanceInitFunc) gst_play_bin_init,
147 gst_play_bin_type = g_type_register_static (GST_TYPE_PLAY_BASE_BIN,
148 "GstPlayBin", &gst_play_bin_info, 0);
151 return gst_play_bin_type;
155 gst_play_bin_class_init (GstPlayBinClass * klass)
157 GObjectClass *gobject_klass;
158 GstElementClass *gstelement_klass;
159 GstBinClass *gstbin_klass;
160 GstPlayBaseBinClass *playbasebin_klass;
162 gobject_klass = (GObjectClass *) klass;
163 gstelement_klass = (GstElementClass *) klass;
164 gstbin_klass = (GstBinClass *) klass;
165 playbasebin_klass = (GstPlayBaseBinClass *) klass;
167 parent_class = g_type_class_ref (gst_play_base_bin_get_type ());
169 gobject_klass->set_property = gst_play_bin_set_property;
170 gobject_klass->get_property = gst_play_bin_get_property;
172 g_object_class_install_property (gobject_klass, ARG_VIDEO_SINK,
173 g_param_spec_object ("video-sink", "Video Sink",
174 "the video output element to use (NULL = default sink)",
175 GST_TYPE_ELEMENT, G_PARAM_READWRITE));
176 g_object_class_install_property (gobject_klass, ARG_AUDIO_SINK,
177 g_param_spec_object ("audio-sink", "Audio Sink",
178 "the audio output element to use (NULL = default sink)",
179 GST_TYPE_ELEMENT, G_PARAM_READWRITE));
180 g_object_class_install_property (gobject_klass, ARG_VIS_PLUGIN,
181 g_param_spec_object ("vis-plugin", "Vis plugin",
182 "the visualization element to use (NULL = none)",
183 GST_TYPE_ELEMENT, G_PARAM_READWRITE));
184 g_object_class_install_property (gobject_klass, ARG_VOLUME,
185 g_param_spec_double ("volume", "volume", "volume",
186 0.0, VOLUME_MAX_DOUBLE, 1.0, G_PARAM_READWRITE));
187 g_object_class_install_property (gobject_klass, ARG_FRAME,
188 g_param_spec_boxed ("frame", "Frame",
189 "The last frame (NULL = no video available)",
190 GST_TYPE_BUFFER, G_PARAM_READABLE));
191 g_object_class_install_property (gobject_klass, ARG_FONT_DESC,
192 g_param_spec_string ("subtitle-font-desc",
193 "Subtitle font description",
194 "Pango font description of font "
195 "to be used for subtitle rendering", NULL, G_PARAM_WRITABLE));
197 gobject_klass->dispose = GST_DEBUG_FUNCPTR (gst_play_bin_dispose);
199 gst_element_class_set_details (gstelement_klass, &gst_play_bin_details);
201 gstelement_klass->change_state =
202 GST_DEBUG_FUNCPTR (gst_play_bin_change_state);
203 gstelement_klass->send_event = GST_DEBUG_FUNCPTR (gst_play_bin_send_event);
204 gstelement_klass->get_query_types =
205 GST_DEBUG_FUNCPTR (gst_play_bin_get_query_types);
206 gstelement_klass->query = GST_DEBUG_FUNCPTR (gst_play_bin_query);
208 playbasebin_klass->setup_output_pads = setup_sinks;
209 playbasebin_klass->group_switch = group_switch;
213 gst_play_bin_init (GstPlayBin * play_bin)
215 play_bin->video_sink = NULL;
216 play_bin->audio_sink = NULL;
217 play_bin->visualisation = NULL;
218 play_bin->volume_element = NULL;
219 play_bin->textoverlay_element = NULL;
220 play_bin->volume = 1.0;
221 play_bin->seekables = NULL;
222 play_bin->sinks = NULL;
223 play_bin->frame = NULL;
224 play_bin->font_desc = NULL;
225 play_bin->cache = g_hash_table_new_full (g_str_hash, g_str_equal,
226 NULL, (GDestroyNotify) gst_object_unref);
227 play_bin->group_switch = FALSE;
231 gst_play_bin_dispose (GObject * object)
233 GstPlayBin *play_bin;
235 play_bin = GST_PLAY_BIN (object);
237 if (play_bin->cache != NULL) {
238 remove_sinks (play_bin);
239 g_hash_table_destroy (play_bin->cache);
240 play_bin->cache = NULL;
243 if (play_bin->audio_sink != NULL) {
244 gst_object_unref (GST_OBJECT (play_bin->audio_sink));
245 play_bin->audio_sink = NULL;
247 if (play_bin->video_sink != NULL) {
248 gst_object_unref (GST_OBJECT (play_bin->video_sink));
249 play_bin->video_sink = NULL;
251 if (play_bin->visualisation != NULL) {
252 gst_object_unref (GST_OBJECT (play_bin->visualisation));
253 play_bin->visualisation = NULL;
255 g_free (play_bin->font_desc);
256 play_bin->font_desc = NULL;
258 if (G_OBJECT_CLASS (parent_class)->dispose) {
259 G_OBJECT_CLASS (parent_class)->dispose (object);
265 gst_play_bin_set_property (GObject * object, guint prop_id,
266 const GValue * value, GParamSpec * pspec)
268 GstPlayBin *play_bin;
270 g_return_if_fail (GST_IS_PLAY_BIN (object));
272 play_bin = GST_PLAY_BIN (object);
276 if (play_bin->video_sink != NULL) {
277 gst_object_unref (GST_OBJECT (play_bin->video_sink));
279 play_bin->video_sink = g_value_get_object (value);
280 if (play_bin->video_sink != NULL) {
281 gst_object_ref (GST_OBJECT (play_bin->video_sink));
282 gst_object_sink (GST_OBJECT (play_bin->video_sink));
284 /* when changing the videosink, we just remove the
285 * video pipeline from the cache so that it will be
286 * regenerated with the new sink element */
287 g_hash_table_remove (play_bin->cache, "vbin");
290 if (play_bin->audio_sink != NULL) {
291 gst_object_unref (GST_OBJECT (play_bin->audio_sink));
293 play_bin->audio_sink = g_value_get_object (value);
294 if (play_bin->audio_sink != NULL) {
295 gst_object_ref (GST_OBJECT (play_bin->audio_sink));
296 gst_object_sink (GST_OBJECT (play_bin->audio_sink));
298 g_hash_table_remove (play_bin->cache, "abin");
301 if (play_bin->visualisation != NULL) {
302 gst_object_unref (GST_OBJECT (play_bin->visualisation));
304 play_bin->visualisation = g_value_get_object (value);
305 if (play_bin->visualisation != NULL) {
306 gst_object_ref (GST_OBJECT (play_bin->visualisation));
307 gst_object_sink (GST_OBJECT (play_bin->visualisation));
311 if (play_bin->volume_element) {
312 play_bin->volume = g_value_get_double (value);
313 g_object_set (G_OBJECT (play_bin->volume_element), "volume",
314 play_bin->volume, NULL);
318 g_free (play_bin->font_desc);
319 play_bin->font_desc = g_strdup (g_value_get_string (value));
320 if (play_bin->textoverlay_element) {
321 g_object_set (G_OBJECT (play_bin->textoverlay_element),
322 "font-desc", g_value_get_string (value), NULL);
326 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
332 gst_play_bin_get_property (GObject * object, guint prop_id, GValue * value,
335 GstPlayBin *play_bin;
337 g_return_if_fail (GST_IS_PLAY_BIN (object));
339 play_bin = GST_PLAY_BIN (object);
343 g_value_set_object (value, play_bin->video_sink);
346 g_value_set_object (value, play_bin->audio_sink);
349 g_value_set_object (value, play_bin->visualisation);
352 g_value_set_double (value, play_bin->volume);
355 g_value_set_boxed (value, play_bin->frame);
358 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
363 /* signal fired when the identity has received a new buffer. This is used for
364 * making screenshots.
367 handoff (GstElement * identity, GstBuffer * frame, gpointer data)
369 GstPlayBin *play_bin = GST_PLAY_BIN (data);
371 if (play_bin->frame) {
372 gst_buffer_unref (play_bin->frame);
374 play_bin->frame = gst_buffer_ref (frame);
377 /* make the element (bin) that contains the elements needed to perform
378 * video display. We connect a handoff signal to identity so that we
379 * can grab snapshots. Identity's sinkpad is ghosted to vbin.
381 * +-------------------------------------------------------------+
383 * | +--------+ +----------+ +----------+ +---------+ |
384 * | |identity| |colorspace| |videoscale| |videosink| |
385 * | +-sink src-sink src-sink src-sink | |
386 * | | +---+----+ +----------+ +----------+ +---------+ |
388 * +----------|--------------------------------------------------+
392 gen_video_element (GstPlayBin * play_bin)
398 GstElement *identity;
400 /* first see if we have it in the cache */
401 element = g_hash_table_lookup (play_bin->cache, "vbin");
402 if (element != NULL) {
403 /* need to get the video sink element as we need to add it to the
404 * list of seekable elements */
405 sink = g_hash_table_lookup (play_bin->cache, "video_sink");
409 element = gst_bin_new ("vbin");
410 identity = gst_element_factory_make ("identity", "id");
411 g_signal_connect (identity, "handoff", G_CALLBACK (handoff), play_bin);
412 conv = gst_element_factory_make ("ffmpegcolorspace", "vconv");
413 scale = gst_element_factory_make ("videoscale", "vscale");
414 if (play_bin->video_sink) {
415 sink = play_bin->video_sink;
417 sink = gst_element_factory_make ("autovideosink", "sink");
419 gst_object_ref (GST_OBJECT (sink));
420 g_hash_table_insert (play_bin->cache, "video_sink", sink);
422 gst_bin_add (GST_BIN (element), identity);
423 gst_bin_add (GST_BIN (element), conv);
424 gst_bin_add (GST_BIN (element), scale);
425 gst_bin_add (GST_BIN (element), sink);
426 gst_element_link_pads (identity, "src", conv, "sink");
427 gst_element_link_pads (conv, "src", scale, "sink");
428 gst_element_link_pads (scale, "src", sink, "sink");
430 gst_element_add_ghost_pad (element, gst_element_get_pad (identity, "sink"),
433 gst_element_set_state (element, GST_STATE_READY);
435 /* since we're gonna add it to a bin but don't want to lose it,
436 * we keep a reference. */
437 gst_object_ref (GST_OBJECT (element));
438 g_hash_table_insert (play_bin->cache, "vbin", element);
441 play_bin->seekables = g_list_append (play_bin->seekables, sink);
446 /* make an element for playback of video with subtitles embedded.
448 * +--------------------------------------------------+
449 * | tbin +-------------+ |
450 * | +-----+ | textoverlay | +------+ |
451 * | | csp | +--video_sink | | vbin | |
452 * video_sink-sink src+ +-text_sink src-sink | |
453 * | +-----+ | +-------------+ +------+ |
454 * text_sink-------------+ |
455 * +--------------------------------------------------+
459 gen_text_element (GstPlayBin * play_bin)
461 GstElement *element, *csp, *overlay, *vbin;
463 overlay = gst_element_factory_make ("textoverlay", "overlay");
464 g_object_set (G_OBJECT (overlay),
465 "halign", "center", "valign", "bottom", NULL);
466 play_bin->textoverlay_element = overlay;
467 if (play_bin->font_desc) {
468 g_object_set (G_OBJECT (play_bin->textoverlay_element),
469 "font-desc", play_bin->font_desc, NULL);
471 vbin = gen_video_element (play_bin);
473 g_warning ("No overlay (pango) element, subtitles disabled");
476 csp = gst_element_factory_make ("ffmpegcolorspace", "subtitlecsp");
477 element = gst_bin_new ("textbin");
478 gst_element_link_many (csp, overlay, vbin, NULL);
479 gst_bin_add_many (GST_BIN (element), csp, overlay, vbin, NULL);
481 gst_element_add_ghost_pad (element,
482 gst_element_get_pad (overlay, "text_sink"), "text_sink");
483 gst_element_add_ghost_pad (element,
484 gst_element_get_pad (csp, "sink"), "sink");
489 /* make the element (bin) that contains the elements needed to perform
492 * +-------------------------------------------------------------+
494 * | +---------+ +----------+ +---------+ +---------+ |
495 * | |audioconv| |audioscale| | volume | |audiosink| |
496 * | +-sink src-sink src-sink src-sink | |
497 * | | +---------+ +----------+ +---------+ +---------+ |
499 * +-------------------------------------------------------------+
503 gen_audio_element (GstPlayBin * play_bin)
511 element = g_hash_table_lookup (play_bin->cache, "abin");
512 if (element != NULL) {
513 sink = g_hash_table_lookup (play_bin->cache, "audio_sink");
516 element = gst_bin_new ("abin");
517 conv = gst_element_factory_make ("audioconvert", "aconv");
518 scale = gst_element_factory_make ("audioscale", "ascale");
520 volume = gst_element_factory_make ("volume", "volume");
521 g_object_set (G_OBJECT (volume), "volume", play_bin->volume, NULL);
522 play_bin->volume_element = volume;
524 if (play_bin->audio_sink) {
525 sink = play_bin->audio_sink;
527 sink = gst_element_factory_make ("autoaudiosink", "sink");
528 play_bin->audio_sink = GST_ELEMENT (gst_object_ref (GST_OBJECT (sink)));
531 gst_object_ref (GST_OBJECT (sink));
532 g_hash_table_insert (play_bin->cache, "audio_sink", sink);
534 gst_bin_add (GST_BIN (element), conv);
535 gst_bin_add (GST_BIN (element), scale);
536 gst_bin_add (GST_BIN (element), volume);
537 gst_bin_add (GST_BIN (element), sink);
539 gst_element_link_pads (conv, "src", scale, "sink");
540 gst_element_link_pads (scale, "src", volume, "sink");
541 gst_element_link_pads (volume, "src", sink, "sink");
543 gst_element_add_ghost_pad (element,
544 gst_element_get_pad (conv, "sink"), "sink");
546 gst_element_set_state (element, GST_STATE_READY);
548 /* since we're gonna add it to a bin but don't want to lose it,
549 * we keep a reference. */
550 gst_object_ref (GST_OBJECT (element));
551 g_hash_table_insert (play_bin->cache, "abin", element);
554 play_bin->seekables = g_list_prepend (play_bin->seekables, sink);
559 /* make the element (bin) that contains the elements needed to perform
560 * visualisation ouput. The idea is to split the audio using tee, then
561 * sending the output to the regular audio bin and the other output to
562 * the vis plugin that transforms it into a video that is rendered with the
563 * normal video bin. The video bin is run in a thread to make sure it does
564 * not block the audio playback pipeline.
566 * +--------------------------------------------------------------------------+
568 * | +------+ +----------------+ |
569 * | | tee | | abin ... | |
570 * | +-sink src-sink | |
571 * | | | | +----------------+ +-------------------+ |
572 * | | | | | vthread | |
573 * | | | | +---------+ +------+ +------+ | +--------------+ | |
574 * | | | | |audioconv| | vis | |vqueue| | | vbin ... | | |
575 * | | | src-sink src-sink src-sink src-sink | | |
576 * | | | | +---------+ +------+ +------+ | +--------------+ | |
577 * | | | | +-------------------+ |
580 +--------------------------------------------------------------------------+
583 gen_vis_element (GstPlayBin * play_bin)
594 element = gst_bin_new ("visbin");
595 tee = gst_element_factory_make ("tee", "tee");
597 vqueue = gst_element_factory_make ("queue", "vqueue");
598 vthread = gst_element_factory_make ("thread", "vthread");
600 asink = gen_audio_element (play_bin);
601 vsink = gen_video_element (play_bin);
603 gst_bin_add (GST_BIN (element), asink);
604 gst_bin_add (GST_BIN (element), vqueue);
605 gst_bin_add (GST_BIN (vthread), vsink);
606 gst_bin_add (GST_BIN (element), vthread);
607 gst_bin_add (GST_BIN (element), tee);
609 conv = gst_element_factory_make ("audioconvert", "aconv");
610 if (play_bin->visualisation) {
611 gst_object_ref (GST_OBJECT (play_bin->visualisation));
612 vis = play_bin->visualisation;
614 vis = gst_element_factory_make ("goom", "vis");
617 gst_bin_add (GST_BIN (element), conv);
618 gst_bin_add (GST_BIN (element), vis);
620 gst_element_link_pads (conv, "src", vis, "sink");
621 gst_element_link_pads (vis, "src", vqueue, "sink");
623 gst_element_link_pads (vqueue, "src", vsink, "sink");
625 gst_pad_link (gst_element_get_request_pad (tee, "src%d"),
626 gst_element_get_pad (asink, "sink"));
628 gst_pad_link (gst_element_get_request_pad (tee, "src%d"),
629 gst_element_get_pad (conv, "sink"));
631 gst_element_add_ghost_pad (element,
632 gst_element_get_pad (tee, "sink"), "sink");
637 /* set for group switch */
639 group_switch (GstPlayBaseBin * play_base_bin)
641 GST_PLAY_BIN (play_base_bin)->group_switch = TRUE;
644 /* get rid of all installed sinks */
646 remove_sinks (GstPlayBin * play_bin)
652 GST_DEBUG ("removesinks");
653 play_bin->group_switch = FALSE;
654 element = g_hash_table_lookup (play_bin->cache, "abin");
655 if (element != NULL) {
656 parent = gst_element_get_parent (element);
657 if (parent != NULL) {
658 /* we remove the element from the parent so that
659 * there is no unwanted state change when the parent
661 gst_bin_remove (GST_BIN (parent), element);
664 element = g_hash_table_lookup (play_bin->cache, "vbin");
665 if (element != NULL) {
666 parent = gst_element_get_parent (element);
667 if (parent != NULL) {
668 gst_bin_remove (GST_BIN (parent), element);
672 for (sinks = play_bin->sinks; sinks; sinks = g_list_next (sinks)) {
673 GstElement *element = GST_ELEMENT (sinks->data);
674 GstPad *pad = gst_element_get_pad (element, "sink");
676 GST_LOG ("removing sink %p", element);
677 if (GST_PAD_PEER (pad))
678 gst_pad_unlink (GST_PAD_PEER (pad), pad);
679 gst_bin_remove (GST_BIN (play_bin), element);
681 g_list_free (play_bin->sinks);
682 g_list_free (play_bin->seekables);
683 play_bin->sinks = NULL;
684 play_bin->seekables = NULL;
686 if (play_bin->frame) {
687 gst_buffer_unref (play_bin->frame);
688 play_bin->frame = NULL;
691 play_bin->textoverlay_element = NULL;
692 play_bin->volume_element = NULL;
695 /* loop over the streams and set up the pipeline to play this
696 * media file. First we count the number of audio and video streams.
697 * If there is no video stream but there exists an audio stream,
698 * we install a visualisation pipeline.
700 * Also make sure to only connect the first audio and video pad. FIXME
701 * this should eventually be handled with a tuner interface so that
702 * one can switch the streams.
705 add_sink (GstPlayBin * play_bin, GstElement * sink, GstPad * srcpad)
710 /* we found a sink for this stream, now try to install it */
711 sinkpad = gst_element_get_pad (sink, "sink");
712 res = gst_pad_link (srcpad, sinkpad);
713 GST_DEBUG ("Adding sink with state %d (parent: %d, peer: %d)\n",
714 GST_STATE (sink), GST_STATE (play_bin),
715 GST_STATE (gst_pad_get_parent (srcpad)));
717 /* try to link the pad of the sink to the stream */
721 /* could not link this stream */
722 capsstr = gst_caps_to_string (gst_pad_get_caps (srcpad));
723 g_warning ("could not link %s", capsstr);
726 /* we got the sink succesfully linked, now keep the sink
727 * in out internal list */
728 play_bin->sinks = g_list_prepend (play_bin->sinks, sink);
729 gst_bin_add (GST_BIN (play_bin), sink);
736 setup_sinks (GstPlayBaseBin * play_base_bin)
738 GstPlayBin *play_bin = GST_PLAY_BIN (play_base_bin);
739 GstPlayBaseGroup *group;
740 GList *streaminfo = NULL, *s;
741 gboolean need_vis = FALSE;
742 gboolean need_text = FALSE;
743 GstPad *textsrcpad = NULL, *textsinkpad = NULL;
746 /* get rid of existing sinks */
747 if (play_bin->sinks) {
748 remove_sinks (play_bin);
750 GST_DEBUG ("setupsinks");
752 /* find out what to do */
753 group = play_base_bin->queued_groups->data;
754 if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads > 0 &&
755 group->type[GST_STREAM_TYPE_TEXT - 1].npads > 0) {
757 } else if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads == 0 &&
758 group->type[GST_STREAM_TYPE_AUDIO - 1].npads > 0 &&
759 play_bin->visualisation != NULL) {
763 /* now actually connect everything */
764 g_object_get (G_OBJECT (play_base_bin), "stream-info", &streaminfo, NULL);
765 for (s = streaminfo; s; s = g_list_next (s)) {
766 GObject *obj = G_OBJECT (s->data);
770 g_object_get (obj, "type", &type, NULL);
771 g_object_get (obj, "object", &object, NULL);
773 /* use the sink elements as seek entry point */
775 play_bin->seekables = g_list_prepend (play_bin->seekables, object);
780 if (group->type[GST_STREAM_TYPE_AUDIO - 1].npads > 0) {
782 sink = gen_vis_element (play_bin);
784 sink = gen_audio_element (play_bin);
786 add_sink (play_bin, sink,
787 gst_element_get_pad (group->type[GST_STREAM_TYPE_AUDIO - 1].preroll,
792 if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads > 0) {
794 sink = gen_text_element (play_bin);
796 textsinkpad = gst_element_get_pad (sink, "text_sink");
798 gst_element_get_pad (group->type[GST_STREAM_TYPE_TEXT - 1].preroll,
800 if (textsinkpad && textsrcpad) {
801 gst_pad_link (textsrcpad, textsinkpad);
804 sink = gen_video_element (play_bin);
806 add_sink (play_bin, sink,
807 gst_element_get_pad (group->type[GST_STREAM_TYPE_VIDEO - 1].preroll,
812 static GstElementStateReturn
813 gst_play_bin_change_state (GstElement * element)
815 GstElementStateReturn ret;
816 GstPlayBin *play_bin;
819 play_bin = GST_PLAY_BIN (element);
821 transition = GST_STATE_TRANSITION (element);
823 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element);
824 if (ret == GST_STATE_FAILURE)
827 switch (transition) {
828 case GST_STATE_PLAYING_TO_PAUSED:
829 /* Set audio sink state to NULL to release the sound device,
830 * but only if we own it (else we might be in chain-transition). */
831 if (play_bin->audio_sink != NULL && !play_bin->group_switch &&
832 GST_STATE (play_bin->audio_sink) == GST_STATE_PAUSED) {
833 gst_element_set_state (play_bin->audio_sink, GST_STATE_NULL);
836 case GST_STATE_PAUSED_TO_READY:
837 /* Check for NULL because the state transition may be done by
838 * gst_bin_dispose which is called by gst_play_bin_dispose, and in that
839 * case, we don't want to run remove_sinks.
840 * FIXME: should the NULL test be done in remove_sinks? Should we just
841 * set the state to NULL in gst_play_bin_dispose?
843 if (play_bin->cache != NULL) {
844 remove_sinks (play_bin);
856 static const GstEventMask *
857 gst_play_bin_get_event_masks (GstElement * element)
859 /* FIXME, get the list from the number of installed sinks */
864 /* send an event to all the sinks */
866 gst_play_bin_send_event (GstElement * element, GstEvent * event)
868 gboolean res = FALSE;
870 GstPlayBin *play_bin;
871 GstElementState state;
872 gboolean need_pause = FALSE;
874 play_bin = GST_PLAY_BIN (element);
876 gst_element_get_state (element, &state, NULL, NULL);
877 /* we pause the pipeline first before sending the event. We only
878 * do this if the pipeline was playing. */
879 if (state == GST_STATE_PLAYING) {
881 gst_element_set_state (element, GST_STATE_PAUSED);
884 /* loop over all seekables and send the event to them */
885 for (s = play_bin->seekables; s; s = g_list_next (s)) {
886 GstElement *element = GST_ELEMENT (s->data);
889 /* ref each event before sending it */
890 gst_event_ref (event);
891 ok = gst_element_send_event (element, event);
894 gst_event_unref (event);
896 /* and restart the pipeline if we paused it */
898 gst_element_set_state (element, GST_STATE_PLAYING);
904 static const GstFormat *
905 gst_play_bin_get_formats (GstElement * element)
907 /* FIXME, compile this list from the installed sinks */
908 static GstFormat formats[] = {
917 static const GstQueryType *
918 gst_play_bin_get_query_types (GstElement * element)
920 /* FIXME, compile from the installed sinks */
921 static const GstQueryType query_types[] = {
931 gst_play_bin_query (GstElement * element, GstQuery * query)
933 gboolean res = FALSE;
935 GstPlayBin *play_bin;
937 play_bin = GST_PLAY_BIN (element);
939 for (s = play_bin->seekables; s; s = g_list_next (s)) {
940 GstElement *element = GST_ELEMENT (s->data);
942 res = gst_element_query (element, query);
950 plugin_init (GstPlugin * plugin)
952 GST_DEBUG_CATEGORY_INIT (gst_play_bin_debug, "playbin", 0, "play bin");
954 return gst_element_register (plugin, "playbin", GST_RANK_NONE,
958 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
961 "player bin", plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN)