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 const GstEventMask *gst_play_bin_get_event_masks (GstElement * element);
112 static gboolean gst_play_bin_send_event (GstElement * element,
114 static const GstFormat *gst_play_bin_get_formats (GstElement * element);
115 static gboolean gst_play_bin_convert (GstElement * element,
116 GstFormat src_format, gint64 src_value,
117 GstFormat * dest_format, gint64 * dest_value);
118 static const GstQueryType *gst_play_bin_get_query_types (GstElement * element);
119 static gboolean gst_play_bin_query (GstElement * element, GstQueryType type,
120 GstFormat * format, gint64 * value);
123 static GstElementClass *parent_class;
125 //static guint gst_play_bin_signals[LAST_SIGNAL] = { 0 };
127 static GstElementDetails gst_play_bin_details = {
129 "Generic/Bin/Player",
130 "Autoplug and play media from an uri",
131 "Wim Taymans <wim@fluendo.com>"
135 gst_play_bin_get_type (void)
137 static GType gst_play_bin_type = 0;
139 if (!gst_play_bin_type) {
140 static const GTypeInfo gst_play_bin_info = {
141 sizeof (GstPlayBinClass),
144 (GClassInitFunc) gst_play_bin_class_init,
149 (GInstanceInitFunc) gst_play_bin_init,
153 gst_play_bin_type = g_type_register_static (GST_TYPE_PLAY_BASE_BIN,
154 "GstPlayBin", &gst_play_bin_info, 0);
157 return gst_play_bin_type;
161 gst_play_bin_class_init (GstPlayBinClass * klass)
163 GObjectClass *gobject_klass;
164 GstElementClass *gstelement_klass;
165 GstBinClass *gstbin_klass;
166 GstPlayBaseBinClass *playbasebin_klass;
168 gobject_klass = (GObjectClass *) klass;
169 gstelement_klass = (GstElementClass *) klass;
170 gstbin_klass = (GstBinClass *) klass;
171 playbasebin_klass = (GstPlayBaseBinClass *) klass;
173 parent_class = g_type_class_ref (gst_play_base_bin_get_type ());
175 gobject_klass->set_property = gst_play_bin_set_property;
176 gobject_klass->get_property = gst_play_bin_get_property;
178 g_object_class_install_property (gobject_klass, ARG_VIDEO_SINK,
179 g_param_spec_object ("video-sink", "Video Sink",
180 "the video output element to use (NULL = default sink)",
181 GST_TYPE_ELEMENT, G_PARAM_READWRITE));
182 g_object_class_install_property (gobject_klass, ARG_AUDIO_SINK,
183 g_param_spec_object ("audio-sink", "Audio Sink",
184 "the audio output element to use (NULL = default sink)",
185 GST_TYPE_ELEMENT, G_PARAM_READWRITE));
186 g_object_class_install_property (gobject_klass, ARG_VIS_PLUGIN,
187 g_param_spec_object ("vis-plugin", "Vis plugin",
188 "the visualization element to use (NULL = none)",
189 GST_TYPE_ELEMENT, G_PARAM_READWRITE));
190 g_object_class_install_property (gobject_klass, ARG_VOLUME,
191 g_param_spec_double ("volume", "volume", "volume",
192 0.0, VOLUME_MAX_DOUBLE, 1.0, G_PARAM_READWRITE));
193 g_object_class_install_property (gobject_klass, ARG_FRAME,
194 g_param_spec_boxed ("frame", "Frame",
195 "The last frame (NULL = no video available)",
196 GST_TYPE_BUFFER, G_PARAM_READABLE));
197 g_object_class_install_property (gobject_klass, ARG_FONT_DESC,
198 g_param_spec_string ("subtitle-font-desc",
199 "Subtitle font description",
200 "Pango font description of font "
201 "to be used for subtitle rendering", NULL, G_PARAM_WRITABLE));
203 gobject_klass->dispose = GST_DEBUG_FUNCPTR (gst_play_bin_dispose);
205 gst_element_class_set_details (gstelement_klass, &gst_play_bin_details);
207 gstelement_klass->change_state =
208 GST_DEBUG_FUNCPTR (gst_play_bin_change_state);
209 gstelement_klass->get_event_masks =
210 GST_DEBUG_FUNCPTR (gst_play_bin_get_event_masks);
211 gstelement_klass->send_event = GST_DEBUG_FUNCPTR (gst_play_bin_send_event);
212 gstelement_klass->get_formats = GST_DEBUG_FUNCPTR (gst_play_bin_get_formats);
213 gstelement_klass->convert = GST_DEBUG_FUNCPTR (gst_play_bin_convert);
214 gstelement_klass->get_query_types =
215 GST_DEBUG_FUNCPTR (gst_play_bin_get_query_types);
216 gstelement_klass->query = GST_DEBUG_FUNCPTR (gst_play_bin_query);
218 playbasebin_klass->setup_output_pads = setup_sinks;
219 playbasebin_klass->group_switch = group_switch;
223 gst_play_bin_init (GstPlayBin * play_bin)
225 play_bin->video_sink = NULL;
226 play_bin->audio_sink = NULL;
227 play_bin->visualisation = NULL;
228 play_bin->volume_element = NULL;
229 play_bin->textoverlay_element = NULL;
230 play_bin->volume = 1.0;
231 play_bin->seekables = NULL;
232 play_bin->sinks = NULL;
233 play_bin->frame = NULL;
234 play_bin->font_desc = NULL;
235 play_bin->cache = g_hash_table_new_full (g_str_hash, g_str_equal,
236 NULL, (GDestroyNotify) gst_object_unref);
237 play_bin->group_switch = FALSE;
241 gst_play_bin_dispose (GObject * object)
243 GstPlayBin *play_bin;
245 play_bin = GST_PLAY_BIN (object);
247 if (play_bin->cache != NULL) {
248 remove_sinks (play_bin);
249 g_hash_table_destroy (play_bin->cache);
250 play_bin->cache = NULL;
253 if (play_bin->audio_sink != NULL) {
254 gst_object_unref (GST_OBJECT (play_bin->audio_sink));
255 play_bin->audio_sink = NULL;
257 if (play_bin->video_sink != NULL) {
258 gst_object_unref (GST_OBJECT (play_bin->video_sink));
259 play_bin->video_sink = NULL;
261 if (play_bin->visualisation != NULL) {
262 gst_object_unref (GST_OBJECT (play_bin->visualisation));
263 play_bin->visualisation = NULL;
265 g_free (play_bin->font_desc);
266 play_bin->font_desc = NULL;
268 if (G_OBJECT_CLASS (parent_class)->dispose) {
269 G_OBJECT_CLASS (parent_class)->dispose (object);
275 gst_play_bin_set_property (GObject * object, guint prop_id,
276 const GValue * value, GParamSpec * pspec)
278 GstPlayBin *play_bin;
280 g_return_if_fail (GST_IS_PLAY_BIN (object));
282 play_bin = GST_PLAY_BIN (object);
286 if (play_bin->video_sink != NULL) {
287 gst_object_unref (GST_OBJECT (play_bin->video_sink));
289 play_bin->video_sink = g_value_get_object (value);
290 if (play_bin->video_sink != NULL) {
291 gst_object_ref (GST_OBJECT (play_bin->video_sink));
292 gst_object_sink (GST_OBJECT (play_bin->video_sink));
294 /* when changing the videosink, we just remove the
295 * video pipeline from the cache so that it will be
296 * regenerated with the new sink element */
297 g_hash_table_remove (play_bin->cache, "vbin");
300 if (play_bin->audio_sink != NULL) {
301 gst_object_unref (GST_OBJECT (play_bin->audio_sink));
303 play_bin->audio_sink = g_value_get_object (value);
304 if (play_bin->audio_sink != NULL) {
305 gst_object_ref (GST_OBJECT (play_bin->audio_sink));
306 gst_object_sink (GST_OBJECT (play_bin->audio_sink));
308 g_hash_table_remove (play_bin->cache, "abin");
311 if (play_bin->visualisation != NULL) {
312 gst_object_unref (GST_OBJECT (play_bin->visualisation));
314 play_bin->visualisation = g_value_get_object (value);
315 if (play_bin->visualisation != NULL) {
316 gst_object_ref (GST_OBJECT (play_bin->visualisation));
317 gst_object_sink (GST_OBJECT (play_bin->visualisation));
321 if (play_bin->volume_element) {
322 play_bin->volume = g_value_get_double (value);
323 g_object_set (G_OBJECT (play_bin->volume_element), "volume",
324 play_bin->volume, NULL);
328 g_free (play_bin->font_desc);
329 play_bin->font_desc = g_strdup (g_value_get_string (value));
330 if (play_bin->textoverlay_element) {
331 g_object_set (G_OBJECT (play_bin->textoverlay_element),
332 "font-desc", g_value_get_string (value), NULL);
336 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
342 gst_play_bin_get_property (GObject * object, guint prop_id, GValue * value,
345 GstPlayBin *play_bin;
347 g_return_if_fail (GST_IS_PLAY_BIN (object));
349 play_bin = GST_PLAY_BIN (object);
353 g_value_set_object (value, play_bin->video_sink);
356 g_value_set_object (value, play_bin->audio_sink);
359 g_value_set_object (value, play_bin->visualisation);
362 g_value_set_double (value, play_bin->volume);
365 g_value_set_boxed (value, play_bin->frame);
368 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
373 /* signal fired when the identity has received a new buffer. This is used for
374 * making screenshots.
377 handoff (GstElement * identity, GstBuffer * frame, gpointer data)
379 GstPlayBin *play_bin = GST_PLAY_BIN (data);
381 if (play_bin->frame) {
382 gst_buffer_unref (play_bin->frame);
384 play_bin->frame = gst_buffer_ref (frame);
387 /* make the element (bin) that contains the elements needed to perform
388 * video display. We connect a handoff signal to identity so that we
389 * can grab snapshots. Identity's sinkpad is ghosted to vbin.
391 * +-------------------------------------------------------------+
393 * | +--------+ +----------+ +----------+ +---------+ |
394 * | |identity| |colorspace| |videoscale| |videosink| |
395 * | +-sink src-sink src-sink src-sink | |
396 * | | +---+----+ +----------+ +----------+ +---------+ |
398 * +----------|--------------------------------------------------+
402 gen_video_element (GstPlayBin * play_bin)
408 GstElement *identity;
410 /* first see if we have it in the cache */
411 element = g_hash_table_lookup (play_bin->cache, "vbin");
412 if (element != NULL) {
413 /* need to get the video sink element as we need to add it to the
414 * list of seekable elements */
415 sink = g_hash_table_lookup (play_bin->cache, "video_sink");
419 element = gst_bin_new ("vbin");
420 identity = gst_element_factory_make ("identity", "id");
421 g_signal_connect (identity, "handoff", G_CALLBACK (handoff), play_bin);
422 conv = gst_element_factory_make ("ffmpegcolorspace", "vconv");
423 scale = gst_element_factory_make ("videoscale", "vscale");
424 if (play_bin->video_sink) {
425 sink = play_bin->video_sink;
427 sink = gst_element_factory_make ("autovideosink", "sink");
429 gst_object_ref (GST_OBJECT (sink));
430 g_hash_table_insert (play_bin->cache, "video_sink", sink);
432 gst_bin_add (GST_BIN (element), identity);
433 gst_bin_add (GST_BIN (element), conv);
434 gst_bin_add (GST_BIN (element), scale);
435 gst_bin_add (GST_BIN (element), sink);
436 gst_element_link_pads (identity, "src", conv, "sink");
437 gst_element_link_pads (conv, "src", scale, "sink");
438 gst_element_link_pads (scale, "src", sink, "sink");
440 gst_element_add_ghost_pad (element, gst_element_get_pad (identity, "sink"),
443 gst_element_set_state (element, GST_STATE_READY);
445 /* since we're gonna add it to a bin but don't want to lose it,
446 * we keep a reference. */
447 gst_object_ref (GST_OBJECT (element));
448 g_hash_table_insert (play_bin->cache, "vbin", element);
451 play_bin->seekables = g_list_append (play_bin->seekables, sink);
456 /* make an element for playback of video with subtitles embedded.
458 * +--------------------------------------------------+
459 * | tbin +-------------+ |
460 * | +-----+ | textoverlay | +------+ |
461 * | | csp | +--video_sink | | vbin | |
462 * video_sink-sink src+ +-text_sink src-sink | |
463 * | +-----+ | +-------------+ +------+ |
464 * text_sink-------------+ |
465 * +--------------------------------------------------+
469 gen_text_element (GstPlayBin * play_bin)
471 GstElement *element, *csp, *overlay, *vbin;
473 overlay = gst_element_factory_make ("textoverlay", "overlay");
474 g_object_set (G_OBJECT (overlay),
475 "halign", "center", "valign", "bottom", NULL);
476 play_bin->textoverlay_element = overlay;
477 if (play_bin->font_desc) {
478 g_object_set (G_OBJECT (play_bin->textoverlay_element),
479 "font-desc", play_bin->font_desc, NULL);
481 vbin = gen_video_element (play_bin);
483 g_warning ("No overlay (pango) element, subtitles disabled");
486 csp = gst_element_factory_make ("ffmpegcolorspace", "subtitlecsp");
487 element = gst_bin_new ("textbin");
488 gst_element_link_many (csp, overlay, vbin, NULL);
489 gst_bin_add_many (GST_BIN (element), csp, overlay, vbin, NULL);
491 gst_element_add_ghost_pad (element,
492 gst_element_get_pad (overlay, "text_sink"), "text_sink");
493 gst_element_add_ghost_pad (element,
494 gst_element_get_pad (csp, "sink"), "sink");
499 /* make the element (bin) that contains the elements needed to perform
502 * +-------------------------------------------------------------+
504 * | +---------+ +----------+ +---------+ +---------+ |
505 * | |audioconv| |audioscale| | volume | |audiosink| |
506 * | +-sink src-sink src-sink src-sink | |
507 * | | +---------+ +----------+ +---------+ +---------+ |
509 * +-------------------------------------------------------------+
513 gen_audio_element (GstPlayBin * play_bin)
521 element = g_hash_table_lookup (play_bin->cache, "abin");
522 if (element != NULL) {
523 sink = g_hash_table_lookup (play_bin->cache, "audio_sink");
526 element = gst_bin_new ("abin");
527 conv = gst_element_factory_make ("audioconvert", "aconv");
528 scale = gst_element_factory_make ("audioscale", "ascale");
530 volume = gst_element_factory_make ("volume", "volume");
531 g_object_set (G_OBJECT (volume), "volume", play_bin->volume, NULL);
532 play_bin->volume_element = volume;
534 if (play_bin->audio_sink) {
535 sink = play_bin->audio_sink;
537 sink = gst_element_factory_make ("autoaudiosink", "sink");
538 play_bin->audio_sink = GST_ELEMENT (gst_object_ref (GST_OBJECT (sink)));
541 gst_object_ref (GST_OBJECT (sink));
542 g_hash_table_insert (play_bin->cache, "audio_sink", sink);
544 gst_bin_add (GST_BIN (element), conv);
545 gst_bin_add (GST_BIN (element), scale);
546 gst_bin_add (GST_BIN (element), volume);
547 gst_bin_add (GST_BIN (element), sink);
549 gst_element_link_pads (conv, "src", scale, "sink");
550 gst_element_link_pads (scale, "src", volume, "sink");
551 gst_element_link_pads (volume, "src", sink, "sink");
553 gst_element_add_ghost_pad (element,
554 gst_element_get_pad (conv, "sink"), "sink");
556 gst_element_set_state (element, GST_STATE_READY);
558 /* since we're gonna add it to a bin but don't want to lose it,
559 * we keep a reference. */
560 gst_object_ref (GST_OBJECT (element));
561 g_hash_table_insert (play_bin->cache, "abin", element);
564 play_bin->seekables = g_list_prepend (play_bin->seekables, sink);
569 /* make the element (bin) that contains the elements needed to perform
570 * visualisation ouput. The idea is to split the audio using tee, then
571 * sending the output to the regular audio bin and the other output to
572 * the vis plugin that transforms it into a video that is rendered with the
573 * normal video bin. The video bin is run in a thread to make sure it does
574 * not block the audio playback pipeline.
576 * +--------------------------------------------------------------------------+
578 * | +------+ +----------------+ |
579 * | | tee | | abin ... | |
580 * | +-sink src-sink | |
581 * | | | | +----------------+ +-------------------+ |
582 * | | | | | vthread | |
583 * | | | | +---------+ +------+ +------+ | +--------------+ | |
584 * | | | | |audioconv| | vis | |vqueue| | | vbin ... | | |
585 * | | | src-sink src-sink src-sink src-sink | | |
586 * | | | | +---------+ +------+ +------+ | +--------------+ | |
587 * | | | | +-------------------+ |
590 +--------------------------------------------------------------------------+
593 gen_vis_element (GstPlayBin * play_bin)
604 element = gst_bin_new ("visbin");
605 tee = gst_element_factory_make ("tee", "tee");
607 vqueue = gst_element_factory_make ("queue", "vqueue");
608 vthread = gst_element_factory_make ("thread", "vthread");
610 asink = gen_audio_element (play_bin);
611 vsink = gen_video_element (play_bin);
613 gst_bin_add (GST_BIN (element), asink);
614 gst_bin_add (GST_BIN (element), vqueue);
615 gst_bin_add (GST_BIN (vthread), vsink);
616 gst_bin_add (GST_BIN (element), vthread);
617 gst_bin_add (GST_BIN (element), tee);
619 conv = gst_element_factory_make ("audioconvert", "aconv");
620 if (play_bin->visualisation) {
621 gst_object_ref (GST_OBJECT (play_bin->visualisation));
622 vis = play_bin->visualisation;
624 vis = gst_element_factory_make ("goom", "vis");
627 gst_bin_add (GST_BIN (element), conv);
628 gst_bin_add (GST_BIN (element), vis);
630 gst_element_link_pads (conv, "src", vis, "sink");
631 gst_element_link_pads (vis, "src", vqueue, "sink");
633 gst_element_link_pads (vqueue, "src", vsink, "sink");
635 gst_pad_link (gst_element_get_request_pad (tee, "src%d"),
636 gst_element_get_pad (asink, "sink"));
638 gst_pad_link (gst_element_get_request_pad (tee, "src%d"),
639 gst_element_get_pad (conv, "sink"));
641 gst_element_add_ghost_pad (element,
642 gst_element_get_pad (tee, "sink"), "sink");
647 /* set for group switch */
649 group_switch (GstPlayBaseBin * play_base_bin)
651 GST_PLAY_BIN (play_base_bin)->group_switch = TRUE;
654 /* get rid of all installed sinks */
656 remove_sinks (GstPlayBin * play_bin)
662 GST_DEBUG ("removesinks");
663 play_bin->group_switch = FALSE;
664 element = g_hash_table_lookup (play_bin->cache, "abin");
665 if (element != NULL) {
666 parent = gst_element_get_parent (element);
667 if (parent != NULL) {
668 /* we remove the element from the parent so that
669 * there is no unwanted state change when the parent
671 gst_bin_remove (GST_BIN (parent), element);
674 element = g_hash_table_lookup (play_bin->cache, "vbin");
675 if (element != NULL) {
676 parent = gst_element_get_parent (element);
677 if (parent != NULL) {
678 gst_bin_remove (GST_BIN (parent), element);
682 for (sinks = play_bin->sinks; sinks; sinks = g_list_next (sinks)) {
683 GstElement *element = GST_ELEMENT (sinks->data);
684 GstPad *pad = gst_element_get_pad (element, "sink");
686 GST_LOG ("removing sink %p", element);
687 if (GST_PAD_PEER (pad))
688 gst_pad_unlink (GST_PAD_PEER (pad), pad);
689 gst_bin_remove (GST_BIN (play_bin), element);
691 g_list_free (play_bin->sinks);
692 g_list_free (play_bin->seekables);
693 play_bin->sinks = NULL;
694 play_bin->seekables = NULL;
696 if (play_bin->frame) {
697 gst_buffer_unref (play_bin->frame);
698 play_bin->frame = NULL;
701 play_bin->textoverlay_element = NULL;
702 play_bin->volume_element = NULL;
705 /* loop over the streams and set up the pipeline to play this
706 * media file. First we count the number of audio and video streams.
707 * If there is no video stream but there exists an audio stream,
708 * we install a visualisation pipeline.
710 * Also make sure to only connect the first audio and video pad. FIXME
711 * this should eventually be handled with a tuner interface so that
712 * one can switch the streams.
715 add_sink (GstPlayBin * play_bin, GstElement * sink, GstPad * srcpad)
720 /* we found a sink for this stream, now try to install it */
721 sinkpad = gst_element_get_pad (sink, "sink");
722 res = gst_pad_link (srcpad, sinkpad);
723 GST_DEBUG ("Adding sink with state %d (parent: %d, peer: %d)\n",
724 GST_STATE (sink), GST_STATE (play_bin),
725 GST_STATE (gst_pad_get_parent (srcpad)));
727 /* try to link the pad of the sink to the stream */
731 /* could not link this stream */
732 capsstr = gst_caps_to_string (gst_pad_get_caps (srcpad));
733 g_warning ("could not link %s", capsstr);
736 /* we got the sink succesfully linked, now keep the sink
737 * in out internal list */
738 play_bin->sinks = g_list_prepend (play_bin->sinks, sink);
739 gst_bin_add (GST_BIN (play_bin), sink);
746 setup_sinks (GstPlayBaseBin * play_base_bin)
748 GstPlayBin *play_bin = GST_PLAY_BIN (play_base_bin);
749 GstPlayBaseGroup *group;
750 GList *streaminfo = NULL, *s;
751 gboolean need_vis = FALSE;
752 gboolean need_text = FALSE;
753 GstPad *textsrcpad = NULL, *textsinkpad = NULL;
756 /* get rid of existing sinks */
757 if (play_bin->sinks) {
758 remove_sinks (play_bin);
760 GST_DEBUG ("setupsinks");
762 /* find out what to do */
763 group = play_base_bin->queued_groups->data;
764 if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads > 0 &&
765 group->type[GST_STREAM_TYPE_TEXT - 1].npads > 0) {
767 } else if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads == 0 &&
768 group->type[GST_STREAM_TYPE_AUDIO - 1].npads > 0 &&
769 play_bin->visualisation != NULL) {
773 /* now actually connect everything */
774 g_object_get (G_OBJECT (play_base_bin), "stream-info", &streaminfo, NULL);
775 for (s = streaminfo; s; s = g_list_next (s)) {
776 GObject *obj = G_OBJECT (s->data);
780 g_object_get (obj, "type", &type, NULL);
781 g_object_get (obj, "object", &object, NULL);
783 /* use the sink elements as seek entry point */
785 play_bin->seekables = g_list_prepend (play_bin->seekables, object);
790 if (group->type[GST_STREAM_TYPE_AUDIO - 1].npads > 0) {
792 sink = gen_vis_element (play_bin);
794 sink = gen_audio_element (play_bin);
796 add_sink (play_bin, sink,
797 gst_element_get_pad (group->type[GST_STREAM_TYPE_AUDIO - 1].preroll,
802 if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads > 0) {
804 sink = gen_text_element (play_bin);
806 textsinkpad = gst_element_get_pad (sink, "text_sink");
808 gst_element_get_pad (group->type[GST_STREAM_TYPE_TEXT - 1].preroll,
810 if (textsinkpad && textsrcpad) {
811 gst_pad_link (textsrcpad, textsinkpad);
814 sink = gen_video_element (play_bin);
816 add_sink (play_bin, sink,
817 gst_element_get_pad (group->type[GST_STREAM_TYPE_VIDEO - 1].preroll,
822 static GstElementStateReturn
823 gst_play_bin_change_state (GstElement * element)
825 GstElementStateReturn ret;
826 GstPlayBin *play_bin;
829 play_bin = GST_PLAY_BIN (element);
831 transition = GST_STATE_TRANSITION (element);
833 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element);
834 if (ret == GST_STATE_FAILURE)
837 switch (transition) {
838 case GST_STATE_PLAYING_TO_PAUSED:
839 /* Set audio sink state to NULL to release the sound device,
840 * but only if we own it (else we might be in chain-transition). */
841 if (play_bin->audio_sink != NULL && !play_bin->group_switch &&
842 GST_STATE (play_bin->audio_sink) == GST_STATE_PAUSED) {
843 gst_element_set_state (play_bin->audio_sink, GST_STATE_NULL);
846 case GST_STATE_PAUSED_TO_READY:
847 /* Check for NULL because the state transition may be done by
848 * gst_bin_dispose which is called by gst_play_bin_dispose, and in that
849 * case, we don't want to run remove_sinks.
850 * FIXME: should the NULL test be done in remove_sinks? Should we just
851 * set the state to NULL in gst_play_bin_dispose?
853 if (play_bin->cache != NULL) {
854 remove_sinks (play_bin);
865 static const GstEventMask *
866 gst_play_bin_get_event_masks (GstElement * element)
868 /* FIXME, get the list from the number of installed sinks */
872 /* send an event to all the sinks */
874 gst_play_bin_send_event (GstElement * element, GstEvent * event)
876 gboolean res = FALSE;
878 GstPlayBin *play_bin;
879 GstElementState state;
880 gboolean need_pause = FALSE;
882 play_bin = GST_PLAY_BIN (element);
884 gst_element_get_state (element, &state, NULL, NULL);
885 /* we pause the pipeline first before sending the event. We only
886 * do this if the pipeline was playing. */
887 if (state == GST_STATE_PLAYING) {
889 gst_element_set_state (element, GST_STATE_PAUSED);
892 /* loop over all seekables and send the event to them */
893 for (s = play_bin->seekables; s; s = g_list_next (s)) {
894 GstElement *element = GST_ELEMENT (s->data);
897 /* ref each event before sending it */
898 gst_event_ref (event);
899 ok = gst_element_send_event (element, event);
902 gst_event_unref (event);
904 /* and restart the pipeline if we paused it */
906 gst_element_set_state (element, GST_STATE_PLAYING);
911 static const GstFormat *
912 gst_play_bin_get_formats (GstElement * element)
914 /* FIXME, compile this list from the installed sinks */
915 static GstFormat formats[] = {
924 gst_play_bin_convert (GstElement * element,
925 GstFormat src_format, gint64 src_value,
926 GstFormat * dest_format, gint64 * dest_value)
928 gboolean res = FALSE;
930 GstPlayBin *play_bin;
932 play_bin = GST_PLAY_BIN (element);
934 /* do a conversion, loop over all sinks, stop as soon as one of the
935 * sinks returns a successful result */
936 for (s = play_bin->seekables; s; s = g_list_next (s)) {
937 GstElement *element = GST_ELEMENT (s->data);
939 res = gst_element_convert (element, src_format, src_value,
940 dest_format, dest_value);
947 static const GstQueryType *
948 gst_play_bin_get_query_types (GstElement * element)
950 /* FIXME, compile from the installed sinks */
951 static const GstQueryType query_types[] = {
961 gst_play_bin_query (GstElement * element, GstQueryType type,
962 GstFormat * format, gint64 * value)
964 gboolean res = FALSE;
966 GstPlayBin *play_bin;
968 play_bin = GST_PLAY_BIN (element);
970 for (s = play_bin->seekables; s; s = g_list_next (s)) {
971 GstElement *element = GST_ELEMENT (s->data);
973 res = gst_element_query (element, type, format, value);
981 plugin_init (GstPlugin * plugin)
983 GST_DEBUG_CATEGORY_INIT (gst_play_bin_debug, "playbin", 0, "play bin");
985 return gst_element_register (plugin, "playbin", GST_RANK_NONE,
989 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
992 "player bin", plugin_init, VERSION, GST_LICENSE, GST_PACKAGE, GST_ORIGIN)