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.
21 * SECTION:element-playbin
25 * Playbin provides a stand-alone everything-in-one abstraction for an
26 * audio and/or video player.
29 * It can handle both audio and video files and features
32 * automatic file type recognition and based on that automatic
33 * selection and usage of the right audio/video/subtitle demuxers/decoders
36 * visualisations for audio files
39 * subtitle support for video files
42 * stream selection between different audio/subtitles streams
45 * meta info (tag) extraction
48 * easy access to the last video frame
51 * buffering when playing streams over a network
58 * <title>Usage</title>
60 * A playbin element can be created just like any other element using
61 * gst_element_factory_make(). The file/URI to play should be set via the "uri"
62 * property. This must be an absolute URI, relative file paths are not allowed.
63 * Example URIs are file:///home/joe/movie.avi or http://www.joedoe.com/foo.ogg
66 * Playbin is a #GstPipeline. It will notify the application of everything
67 * that's happening (errors, end of stream, tags found, state changes, etc.)
68 * by posting messages on its #GstBus. The application needs to watch the
72 * Playback can be initiated by setting the element to PLAYING state using
73 * gst_element_set_state(). Note that the state change will take place in
74 * the background in a separate thread, when the function returns playback
75 * is probably not happening yet and any errors might not have occured yet.
76 * Applications using playbin should ideally be written to deal with things
77 * completely asynchroneous.
80 * When playback has finished (an EOS message has been received on the bus)
81 * or an error has occured (an ERROR message has been received on the bus) or
82 * the user wants to play a different track, playbin should be set back to
83 * READY or NULL state, then the "uri" property should be set to the new
84 * location and then playbin be set to PLAYING state again.
87 * Seeking can be done using gst_element_seek_simple() or gst_element_seek()
88 * on the playbin element. Again, the seek will not be executed
89 * instantaneously, but will be done in a background thread. When the seek
90 * call returns the seek will most likely still be in process. An application
91 * may wait for the seek to finish (or fail) using gst_element_get_state() with
92 * -1 as the timeout, but this will block the user interface and is not
96 * Applications may query the current position and duration of the stream
97 * via gst_element_query_position() and gst_element_query_duration() and
98 * setting the format passed to GST_FORMAT_TIME. If the query was successful,
99 * the duration or position will have been returned in units of nanoseconds.
101 * <title>Advanced Usage: specifying the audio and video sink</title>
103 * By default, if no audio sink or video sink has been specified via the
104 * "audio-sink" or "video-sink" property, playbin will use the autoaudiosink
105 * and autovideosink elements to find the first-best available output method.
106 * This should work in most cases, but is not always desirable. Often either
107 * the user or application might want to specify more explicitly what to use
108 * for audio and video output.
111 * If the application wants more control over how audio or video should be
112 * output, it may create the audio/video sink elements itself (for example
113 * using gst_element_factory_make()) and provide them to playbin using the
114 * "audio-sink" or "video-sink" property.
117 * GNOME-based applications, for example, will usually want to create
118 * gconfaudiosink and gconfvideosink elements and make playbin use those,
119 * so that output happens to whatever the user has configured in the GNOME
120 * Multimedia System Selector confinguration dialog.
123 * The sink elements do not necessarily need to be ready-made sinks. It is
124 * possible to create container elements that look like a sink to playbin,
125 * but in reality contain a number of custom elements linked together. This
126 * can be achieved by creating a #GstBin and putting elements in there and
127 * linking them, and then creating a sink #GstGhostPad for the bin and pointing
128 * it to the sink pad of the first element within the bin. This can be used
129 * for a number of purposes, for example to force output to a particular
130 * format or to modify or observe the data before it is output.
133 * It is also possible to 'suppress' audio and/or video output by using
134 * 'fakesink' elements (or capture it from there using the fakesink element's
135 * "handoff" signal, which, nota bene, is fired from the streaming thread!).
137 * <title>Retrieving Tags and Other Meta Data</title>
139 * Most of the common meta data (artist, title, etc.) can be retrieved by
140 * watching for TAG messages on the pipeline's bus (see above).
143 * Other more specific meta information like width/height/framerate of video
144 * streams or samplerate/number of channels of audio streams can be obtained
145 * using the "stream-info" property, which will return a GList of stream info
146 * objects, one for each stream. These are opaque objects that can only be
147 * accessed via the standard GObject property interface, ie. g_object_get().
148 * Each stream info object has the following properties:
150 * <listitem>"object" (GstObject) (the decoder source pad usually)</listitem>
151 * <listitem>"type" (enum) (if this is an audio/video/subtitle stream)</listitem>
152 * <listitem>"decoder" (string) (name of decoder used to decode this stream)</listitem>
153 * <listitem>"mute" (boolean) (to mute or unmute this stream)</listitem>
154 * <listitem>"caps" (GstCaps) (caps of the decoded stream)</listitem>
155 * <listitem>"language-code" (string) (ISO-639 language code for this stream, mostly used for audio/subtitle streams)</listitem>
156 * <listitem>"codec" (string) (format this stream was encoded in)</listitem>
158 * Stream information from the stream-info properties is best queried once
159 * playbin has changed into PAUSED or PLAYING state (which can be detected
160 * via a state-changed message on the bus where old_state=READY and
161 * new_state=PAUSED), since before that the list might not be complete yet or
162 * not contain all available information (like language-codes).
164 * <title>Buffering</title>
166 * Playbin handles buffering automatically for the most part, but applications
167 * need to handle parts of the buffering process as well. Whenever playbin is
168 * buffering, it will post BUFFERING messages on the bus with a percentage
169 * value that shows the progress of the buffering process. Applications need
170 * to set playbin to PLAYING or PAUSED state in response to these messages.
171 * They may also want to convey the buffering progress to the user in some
172 * way. Here is how to extract the percentage information from the message
173 * (requires GStreamer >= 0.10.11):
177 * switch (GST_MESSAGE_TYPE (msg)) {
178 * case GST_MESSAGE_BUFFERING: {
180 * gst_message_parse_buffering (msg, &percent);
181 * g_print ("Buffering (%%u percent done)", percent);
187 * Note that applications should keep/set the pipeline in the PAUSED state when
188 * a BUFFERING message is received with a buffer percent value < 100 and set
189 * the pipeline back to PLAYING state when a BUFFERING message with a value
190 * of 100 percent is received (if PLAYING is the desired state, that is).
192 * <title>Embedding the video window in your application</title>
194 * By default, playbin (or rather the video sinks used) will create their own
195 * window. Applications will usually want to force output to a window of their
196 * own, however. This can be done using the GstXOverlay interface, which most
197 * video sinks implement. See the documentation there for more details.
199 * <title>Specifying which CD/DVD device to use</title>
201 * The device to use for CDs/DVDs needs to be set on the source element
202 * playbin creates before it is opened. The only way to do this at the moment
203 * is to connect to playbin's "notify::source" signal, which will be emitted
204 * by playbin when it has created the source element for a particular URI.
205 * In the signal callback you can check if the source element has a "device"
206 * property and set it appropriately. In future ways might be added to specify
207 * the device as part of the URI, but at the time of writing this is not
210 * <title>Examples</title>
212 * Here is a simple pipeline to play back a video or audio file:
214 * gst-launch -v playbin uri=file:///path/to/somefile.avi
216 * This will play back the given AVI video file, given that the video and
217 * audio decoders required to decode the content are installed. Since no
218 * special audio sink or video sink is supplied (not possible via gst-launch),
219 * playbin will try to find a suitable audio and video sink automatically
220 * using the autoaudiosink and autovideosink elements.
223 * Here is a another pipeline to play track 4 of an audio CD:
225 * gst-launch -v playbin uri=cdda://4
227 * This will play back track 4 on an audio CD in your disc drive (assuming
228 * the drive is detected automatically by the plugin).
231 * Here is a another pipeline to play title 1 of a DVD:
233 * gst-launch -v playbin uri=dvd://1
235 * This will play back title 1 of a DVD in your disc drive (assuming
236 * the drive is detected automatically by the plugin).
248 #include <gst/gst-i18n-plugin.h>
249 #include <gst/pbutils/pbutils.h>
251 #include "gstplaybasebin.h"
253 GST_DEBUG_CATEGORY_STATIC (gst_play_bin_debug);
254 #define GST_CAT_DEFAULT gst_play_bin_debug
256 #define GST_TYPE_PLAY_BIN (gst_play_bin_get_type())
257 #define GST_PLAY_BIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PLAY_BIN,GstPlayBin))
258 #define GST_PLAY_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PLAY_BIN,GstPlayBinClass))
259 #define GST_IS_PLAY_BIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PLAY_BIN))
260 #define GST_IS_PLAY_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PLAY_BIN))
262 #define VOLUME_MAX_DOUBLE 10.0
264 typedef struct _GstPlayBin GstPlayBin;
265 typedef struct _GstPlayBinClass GstPlayBinClass;
269 GstPlayBaseBin parent;
271 /* the configurable elements */
272 GstElement *fakesink;
273 GstElement *audio_sink;
274 GstElement *video_sink;
275 GstElement *visualisation;
276 GstElement *pending_visualisation;
277 GstElement *volume_element;
278 GstElement *textoverlay_element;
281 /* these are the currently active sinks */
284 /* the last captured frame for snapshots */
287 /* our cache for the sinks */
290 /* font description */
293 /* indication if the pipeline is live */
297 struct _GstPlayBinClass
299 GstPlayBaseBinClass parent_class;
320 static void gst_play_bin_class_init (GstPlayBinClass * klass);
321 static void gst_play_bin_init (GstPlayBin * play_bin);
322 static void gst_play_bin_dispose (GObject * object);
324 static gboolean setup_sinks (GstPlayBaseBin * play_base_bin,
325 GstPlayBaseGroup * group);
326 static void remove_sinks (GstPlayBin * play_bin);
327 static void playbin_set_subtitles_visible (GstPlayBaseBin * play_base_bin,
330 static void gst_play_bin_set_property (GObject * object, guint prop_id,
331 const GValue * value, GParamSpec * spec);
332 static void gst_play_bin_get_property (GObject * object, guint prop_id,
333 GValue * value, GParamSpec * spec);
335 static gboolean gst_play_bin_send_event (GstElement * element,
337 static GstStateChangeReturn gst_play_bin_change_state (GstElement * element,
338 GstStateChange transition);
340 static void gst_play_bin_handle_message (GstBin * bin, GstMessage * message);
342 static GstElementClass *parent_class;
344 //static guint gst_play_bin_signals[LAST_SIGNAL] = { 0 };
346 static const GstElementDetails gst_play_bin_details =
347 GST_ELEMENT_DETAILS ("Player Bin",
348 "Generic/Bin/Player",
349 "Autoplug and play media from an uri",
350 "Wim Taymans <wim.taymans@gmail.com>");
353 gst_play_bin_get_type (void)
355 static GType gst_play_bin_type = 0;
357 if (!gst_play_bin_type) {
358 static const GTypeInfo gst_play_bin_info = {
359 sizeof (GstPlayBinClass),
362 (GClassInitFunc) gst_play_bin_class_init,
367 (GInstanceInitFunc) gst_play_bin_init,
371 gst_play_bin_type = g_type_register_static (GST_TYPE_PLAY_BASE_BIN,
372 "GstPlayBin", &gst_play_bin_info, 0);
375 return gst_play_bin_type;
379 gst_play_bin_class_init (GstPlayBinClass * klass)
381 GObjectClass *gobject_klass;
382 GstElementClass *gstelement_klass;
383 GstBinClass *gstbin_klass;
384 GstPlayBaseBinClass *playbasebin_klass;
386 gobject_klass = (GObjectClass *) klass;
387 gstelement_klass = (GstElementClass *) klass;
388 gstbin_klass = (GstBinClass *) klass;
389 playbasebin_klass = (GstPlayBaseBinClass *) klass;
391 parent_class = g_type_class_peek_parent (klass);
393 gobject_klass->set_property = gst_play_bin_set_property;
394 gobject_klass->get_property = gst_play_bin_get_property;
396 g_object_class_install_property (gobject_klass, ARG_VIDEO_SINK,
397 g_param_spec_object ("video-sink", "Video Sink",
398 "the video output element to use (NULL = default sink)",
399 GST_TYPE_ELEMENT, G_PARAM_READWRITE));
400 g_object_class_install_property (gobject_klass, ARG_AUDIO_SINK,
401 g_param_spec_object ("audio-sink", "Audio Sink",
402 "the audio output element to use (NULL = default sink)",
403 GST_TYPE_ELEMENT, G_PARAM_READWRITE));
404 g_object_class_install_property (gobject_klass, ARG_VIS_PLUGIN,
405 g_param_spec_object ("vis-plugin", "Vis plugin",
406 "the visualization element to use (NULL = none)",
407 GST_TYPE_ELEMENT, G_PARAM_READWRITE));
408 g_object_class_install_property (gobject_klass, ARG_VOLUME,
409 g_param_spec_double ("volume", "volume", "volume",
410 0.0, VOLUME_MAX_DOUBLE, 1.0, G_PARAM_READWRITE));
411 g_object_class_install_property (gobject_klass, ARG_FRAME,
412 gst_param_spec_mini_object ("frame", "Frame",
413 "The last frame (NULL = no video available)",
414 GST_TYPE_BUFFER, G_PARAM_READABLE));
415 g_object_class_install_property (gobject_klass, ARG_FONT_DESC,
416 g_param_spec_string ("subtitle-font-desc",
417 "Subtitle font description",
418 "Pango font description of font "
419 "to be used for subtitle rendering", NULL, G_PARAM_WRITABLE));
421 gobject_klass->dispose = GST_DEBUG_FUNCPTR (gst_play_bin_dispose);
423 gst_element_class_set_details (gstelement_klass, &gst_play_bin_details);
425 gstelement_klass->change_state =
426 GST_DEBUG_FUNCPTR (gst_play_bin_change_state);
427 gstelement_klass->send_event = GST_DEBUG_FUNCPTR (gst_play_bin_send_event);
429 gstbin_klass->handle_message =
430 GST_DEBUG_FUNCPTR (gst_play_bin_handle_message);
432 playbasebin_klass->setup_output_pads = setup_sinks;
433 playbasebin_klass->set_subtitles_visible = playbin_set_subtitles_visible;
437 gst_play_bin_init (GstPlayBin * play_bin)
439 play_bin->video_sink = NULL;
440 play_bin->audio_sink = NULL;
441 play_bin->visualisation = NULL;
442 play_bin->pending_visualisation = NULL;
443 play_bin->volume_element = NULL;
444 play_bin->textoverlay_element = NULL;
445 play_bin->volume = 1.0;
446 play_bin->sinks = NULL;
447 play_bin->frame = NULL;
448 play_bin->font_desc = NULL;
449 play_bin->cache = g_hash_table_new_full (g_str_hash, g_str_equal,
450 NULL, (GDestroyNotify) gst_object_unref);
454 gst_play_bin_dispose (GObject * object)
456 GstPlayBin *play_bin;
458 play_bin = GST_PLAY_BIN (object);
460 if (play_bin->cache != NULL) {
461 remove_sinks (play_bin);
462 g_hash_table_destroy (play_bin->cache);
463 play_bin->cache = NULL;
466 if (play_bin->audio_sink != NULL) {
467 gst_element_set_state (play_bin->audio_sink, GST_STATE_NULL);
468 gst_object_unref (play_bin->audio_sink);
469 play_bin->audio_sink = NULL;
471 if (play_bin->video_sink != NULL) {
472 gst_element_set_state (play_bin->video_sink, GST_STATE_NULL);
473 gst_object_unref (play_bin->video_sink);
474 play_bin->video_sink = NULL;
476 if (play_bin->visualisation != NULL) {
477 gst_element_set_state (play_bin->visualisation, GST_STATE_NULL);
478 gst_object_unref (play_bin->visualisation);
479 play_bin->visualisation = NULL;
481 if (play_bin->pending_visualisation != NULL) {
482 gst_element_set_state (play_bin->pending_visualisation, GST_STATE_NULL);
483 gst_object_unref (play_bin->pending_visualisation);
484 play_bin->pending_visualisation = NULL;
486 if (play_bin->textoverlay_element != NULL) {
487 gst_object_unref (play_bin->textoverlay_element);
488 play_bin->textoverlay_element = NULL;
490 g_free (play_bin->font_desc);
491 play_bin->font_desc = NULL;
493 G_OBJECT_CLASS (parent_class)->dispose (object);
497 gst_play_bin_vis_unblocked (GstPad * tee_pad, gboolean blocked,
500 GstPlayBin *play_bin = GST_PLAY_BIN (user_data);
502 if (play_bin->pending_visualisation)
503 gst_pad_set_blocked_async (tee_pad, FALSE, gst_play_bin_vis_unblocked,
508 gst_play_bin_vis_blocked (GstPad * tee_pad, gboolean blocked,
511 GstPlayBin *play_bin = GST_PLAY_BIN (user_data);
512 GstBin *vis_bin = NULL;
513 GstPad *vis_sink_pad = NULL, *vis_src_pad = NULL, *vqueue_pad = NULL;
515 GstElement *pending_visualisation;
517 GST_OBJECT_LOCK (play_bin);
518 pending_visualisation = play_bin->pending_visualisation;
519 play_bin->pending_visualisation = NULL;
520 GST_OBJECT_UNLOCK (play_bin);
522 /* We want to disable visualisation */
523 if (!GST_IS_ELEMENT (pending_visualisation)) {
524 /* Set visualisation element to READY */
525 gst_element_set_state (play_bin->visualisation, GST_STATE_READY);
530 GST_BIN_CAST (gst_object_get_parent (GST_OBJECT_CAST (play_bin->
533 if (!GST_IS_BIN (vis_bin) || !GST_IS_PAD (tee_pad)) {
537 vis_src_pad = gst_element_get_pad (play_bin->visualisation, "src");
538 vis_sink_pad = gst_pad_get_peer (tee_pad);
540 /* Can be fakesink */
541 if (GST_IS_PAD (vis_src_pad)) {
542 vqueue_pad = gst_pad_get_peer (vis_src_pad);
545 if (!GST_IS_PAD (vis_sink_pad)) {
549 /* Check the bin's state */
550 GST_OBJECT_LOCK (vis_bin);
551 bin_state = GST_STATE (vis_bin);
552 GST_OBJECT_UNLOCK (vis_bin);
555 gst_pad_unlink (tee_pad, vis_sink_pad);
556 gst_object_unref (vis_sink_pad);
559 if (GST_IS_PAD (vqueue_pad)) {
560 gst_pad_unlink (vis_src_pad, vqueue_pad);
561 gst_object_unref (vis_src_pad);
565 /* Remove from vis_bin */
566 gst_bin_remove (vis_bin, play_bin->visualisation);
567 /* Set state to NULL */
568 gst_element_set_state (play_bin->visualisation, GST_STATE_NULL);
569 /* And loose our ref */
570 gst_object_unref (play_bin->visualisation);
572 if (pending_visualisation) {
573 /* Ref this new visualisation element before adding to the bin */
574 gst_object_ref (pending_visualisation);
575 /* Add the new one */
576 gst_bin_add (vis_bin, pending_visualisation);
577 /* Synchronizing state */
578 gst_element_set_state (pending_visualisation, bin_state);
580 vis_sink_pad = gst_element_get_pad (pending_visualisation, "sink");
581 vis_src_pad = gst_element_get_pad (pending_visualisation, "src");
583 if (!GST_IS_PAD (vis_sink_pad) || !GST_IS_PAD (vis_src_pad)) {
588 gst_pad_link (tee_pad, vis_sink_pad);
589 gst_pad_link (vis_src_pad, vqueue_pad);
593 gst_object_unref (play_bin->visualisation);
594 play_bin->visualisation = pending_visualisation;
598 gst_object_unref (vis_sink_pad);
601 gst_object_unref (vis_src_pad);
604 gst_object_unref (vqueue_pad);
607 gst_object_unref (vis_bin);
610 /* Unblock the pad */
611 gst_pad_set_blocked_async (tee_pad, FALSE, gst_play_bin_vis_unblocked,
616 gst_play_bin_set_property (GObject * object, guint prop_id,
617 const GValue * value, GParamSpec * pspec)
619 GstPlayBin *play_bin;
621 play_bin = GST_PLAY_BIN (object);
625 if (play_bin->video_sink != NULL) {
626 gst_object_unref (play_bin->video_sink);
628 play_bin->video_sink = g_value_get_object (value);
629 if (play_bin->video_sink != NULL) {
630 gst_object_ref (play_bin->video_sink);
631 gst_object_sink (GST_OBJECT_CAST (play_bin->video_sink));
633 /* when changing the videosink, we just remove the
634 * video pipeline from the cache so that it will be
635 * regenerated with the new sink element */
636 g_hash_table_remove (play_bin->cache, "vbin");
639 if (play_bin->audio_sink != NULL) {
640 gst_object_unref (play_bin->audio_sink);
642 play_bin->audio_sink = g_value_get_object (value);
643 if (play_bin->audio_sink != NULL) {
644 gst_object_ref (play_bin->audio_sink);
645 gst_object_sink (GST_OBJECT_CAST (play_bin->audio_sink));
647 g_hash_table_remove (play_bin->cache, "abin");
651 GstElement *pending_visualisation =
652 GST_ELEMENT_CAST (g_value_get_object (value));
655 if (pending_visualisation) {
656 gst_object_ref (pending_visualisation);
657 gst_object_sink (pending_visualisation);
660 /* Do we already have a visualisation change pending ? */
661 GST_OBJECT_LOCK (play_bin);
662 if (play_bin->pending_visualisation) {
663 gst_object_unref (play_bin->pending_visualisation);
664 play_bin->pending_visualisation = pending_visualisation;
665 GST_OBJECT_UNLOCK (play_bin);
667 GST_OBJECT_UNLOCK (play_bin);
668 /* Was there a visualisation already set ? */
669 if (play_bin->visualisation != NULL) {
670 GstBin *vis_bin = NULL;
673 GST_BIN_CAST (gst_object_get_parent (GST_OBJECT_CAST (play_bin->
676 /* Check if the visualisation is already in a bin */
677 if (GST_IS_BIN (vis_bin)) {
678 GstPad *vis_sink_pad = NULL, *tee_pad = NULL;
680 /* Now get tee pad and block it async */
681 vis_sink_pad = gst_element_get_pad (play_bin->visualisation,
683 if (!GST_IS_PAD (vis_sink_pad)) {
686 tee_pad = gst_pad_get_peer (vis_sink_pad);
687 if (!GST_IS_PAD (tee_pad)) {
691 play_bin->pending_visualisation = pending_visualisation;
692 /* Block with callback */
693 gst_pad_set_blocked_async (tee_pad, TRUE, gst_play_bin_vis_blocked,
697 gst_object_unref (vis_sink_pad);
700 gst_object_unref (tee_pad);
702 gst_object_unref (vis_bin);
704 play_bin->visualisation = pending_visualisation;
707 play_bin->visualisation = pending_visualisation;
713 play_bin->volume = g_value_get_double (value);
714 if (play_bin->volume_element) {
715 g_object_set (G_OBJECT (play_bin->volume_element), "volume",
716 play_bin->volume, NULL);
720 g_free (play_bin->font_desc);
721 play_bin->font_desc = g_strdup (g_value_get_string (value));
722 if (play_bin->textoverlay_element) {
723 g_object_set (G_OBJECT (play_bin->textoverlay_element),
724 "font-desc", g_value_get_string (value), NULL);
728 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
734 gst_play_bin_get_property (GObject * object, guint prop_id, GValue * value,
737 GstPlayBin *play_bin;
739 play_bin = GST_PLAY_BIN (object);
743 g_value_set_object (value, play_bin->video_sink);
746 g_value_set_object (value, play_bin->audio_sink);
749 g_value_set_object (value, play_bin->visualisation);
752 g_value_set_double (value, play_bin->volume);
755 GstBuffer *cur_frame = NULL;
757 gst_buffer_replace (&cur_frame, play_bin->frame);
758 gst_value_take_buffer (value, cur_frame);
762 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
767 /* signal fired when the identity has received a new buffer. This is used for
768 * making screenshots.
771 handoff (GstElement * identity, GstBuffer * frame, gpointer data)
773 GstPlayBin *play_bin = GST_PLAY_BIN (data);
775 /* applications need to know the buffer caps,
776 * make sure they are always set on the frame */
777 if (GST_BUFFER_CAPS (frame) == NULL) {
780 if ((pad = gst_element_get_pad (identity, "sink"))) {
781 gst_buffer_set_caps (frame, GST_PAD_CAPS (pad));
782 gst_object_unref (pad);
786 gst_buffer_replace (&play_bin->frame, frame);
790 post_missing_element_message (GstPlayBin * playbin, const gchar * name)
794 msg = gst_missing_element_message_new (GST_ELEMENT_CAST (playbin), name);
795 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
798 /* make the element (bin) that contains the elements needed to perform
799 * video display. We connect a handoff signal to identity so that we
800 * can grab snapshots. Identity's sinkpad is ghosted to vbin.
802 * +-------------------------------------------------------------+
804 * | +--------+ +----------+ +----------+ +---------+ |
805 * | |identity| |colorspace| |videoscale| |videosink| |
806 * | +-sink src-sink src-sink src-sink | |
807 * | | +---+----+ +----------+ +----------+ +---------+ |
809 * +----------|--------------------------------------------------+
813 gen_video_element (GstPlayBin * play_bin)
820 GstElement *identity;
823 /* first see if we have it in the cache */
824 element = g_hash_table_lookup (play_bin->cache, "vbin");
825 if (element != NULL) {
829 if (play_bin->video_sink) {
830 sink = play_bin->video_sink;
832 sink = gst_element_factory_make ("autovideosink", "videosink");
834 sink = gst_element_factory_make ("xvimagesink", "videosink");
839 gst_object_ref (sink);
840 g_hash_table_insert (play_bin->cache, "video_sink", sink);
842 /* create a bin to hold objects, as we create them we add them to this bin so
843 * that when something goes wrong we only need to unref the bin */
844 element = gst_bin_new ("vbin");
845 gst_bin_add (GST_BIN_CAST (element), sink);
847 conv = gst_element_factory_make ("ffmpegcolorspace", "vconv");
850 gst_bin_add (GST_BIN_CAST (element), conv);
852 scale = gst_element_factory_make ("videoscale", "vscale");
855 gst_bin_add (GST_BIN_CAST (element), scale);
857 identity = gst_element_factory_make ("identity", "id");
858 g_object_set (identity, "silent", TRUE, NULL);
859 g_signal_connect (identity, "handoff", G_CALLBACK (handoff), play_bin);
860 gst_bin_add (GST_BIN_CAST (element), identity);
862 gst_element_link_pads (identity, "src", conv, "sink");
863 gst_element_link_pads (conv, "src", scale, "sink");
864 /* be more careful with the pad from the custom sink element, it might not
866 if (!gst_element_link_pads (scale, "src", sink, NULL))
869 pad = gst_element_get_pad (identity, "sink");
870 gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
871 gst_object_unref (pad);
873 gst_element_set_state (element, GST_STATE_READY);
875 /* since we're gonna add it to a bin but don't want to lose it,
876 * we keep a reference. */
877 gst_object_ref (element);
878 g_hash_table_insert (play_bin->cache, "vbin", element);
885 post_missing_element_message (play_bin, "autovideosink");
886 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
887 (_("Both autovideosink and xvimagesink elements are missing.")),
893 post_missing_element_message (play_bin, "ffmpegcolorspace");
894 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
895 (_("Missing element '%s' - check your GStreamer installation."),
896 "ffmpegcolorspace"), (NULL));
897 gst_object_unref (element);
903 post_missing_element_message (play_bin, "videoscale");
904 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
905 (_("Missing element '%s' - check your GStreamer installation."),
906 "videoscale"), ("possibly a liboil version mismatch?"));
907 gst_object_unref (element);
912 GST_ELEMENT_ERROR (play_bin, CORE, PAD,
913 (NULL), ("Failed to configure the video sink."));
914 gst_object_unref (element);
919 /* make an element for playback of video with subtitles embedded.
921 * +--------------------------------------------------+
922 * | tbin +-------------+ |
923 * | +-----+ | textoverlay | +------+ |
924 * | | csp | +--video_sink | | vbin | |
925 * video_sink-sink src+ +-text_sink src-sink | |
926 * | +-----+ | +-------------+ +------+ |
927 * text_sink-------------+ |
928 * +--------------------------------------------------+
930 * If there is no subtitle renderer this function will simply return the
931 * videosink without the text_sink pad.
934 gen_text_element (GstPlayBin * play_bin)
936 GstElement *element, *csp, *overlay, *vbin;
939 /* Create the video rendering bin, error is posted when this fails. */
940 vbin = gen_video_element (play_bin);
945 overlay = gst_element_factory_make ("textoverlay", "overlay");
947 /* If no overlay return the video bin without subtitle support. */
952 element = gst_bin_new ("textbin");
954 /* Set some parameters */
955 g_object_set (G_OBJECT (overlay),
956 "halign", "center", "valign", "bottom", NULL);
957 if (play_bin->font_desc) {
958 g_object_set (G_OBJECT (overlay), "font-desc", play_bin->font_desc, NULL);
962 play_bin->textoverlay_element = GST_ELEMENT_CAST (gst_object_ref (overlay));
964 /* we know this will succeed, as the video bin already created one before */
965 csp = gst_element_factory_make ("ffmpegcolorspace", "subtitlecsp");
967 /* Add our elements */
968 gst_bin_add_many (GST_BIN_CAST (element), csp, overlay, vbin, NULL);
971 gst_element_link_pads (csp, "src", overlay, "video_sink");
972 gst_element_link_pads (overlay, "src", vbin, "sink");
974 /* Add ghost pads on the subtitle bin */
975 pad = gst_element_get_pad (overlay, "text_sink");
976 gst_element_add_pad (element, gst_ghost_pad_new ("text_sink", pad));
977 gst_object_unref (pad);
979 pad = gst_element_get_pad (csp, "sink");
980 gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
981 gst_object_unref (pad);
983 /* Set state to READY */
984 gst_element_set_state (element, GST_STATE_READY);
991 post_missing_element_message (play_bin, "textoverlay");
992 GST_WARNING_OBJECT (play_bin,
993 "No overlay (pango) element, subtitles disabled");
998 /* make the element (bin) that contains the elements needed to perform
1001 * +-------------------------------------------------------------+
1003 * | +---------+ +----------+ +---------+ +---------+ |
1004 * | |audioconv| |audioscale| | volume | |audiosink| |
1005 * | +-sink src-sink src-sink src-sink | |
1006 * | | +---------+ +----------+ +---------+ +---------+ |
1008 * +-------------------------------------------------------------+
1011 gen_audio_element (GstPlayBin * play_bin)
1014 GstElement *element;
1021 element = g_hash_table_lookup (play_bin->cache, "abin");
1022 if (element != NULL)
1025 if (play_bin->audio_sink) {
1026 sink = play_bin->audio_sink;
1028 sink = gst_element_factory_make ("autoaudiosink", "audiosink");
1030 sink = gst_element_factory_make ("alsasink", "audiosink");
1035 play_bin->audio_sink = GST_ELEMENT_CAST (gst_object_ref (sink));
1038 gst_object_ref (sink);
1039 g_hash_table_insert (play_bin->cache, "audio_sink", sink);
1041 element = gst_bin_new ("abin");
1042 gst_bin_add (GST_BIN_CAST (element), sink);
1044 conv = gst_element_factory_make ("audioconvert", "aconv");
1046 goto no_audioconvert;
1047 gst_bin_add (GST_BIN_CAST (element), conv);
1049 scale = gst_element_factory_make ("audioresample", "aresample");
1051 goto no_audioresample;
1052 gst_bin_add (GST_BIN_CAST (element), scale);
1054 volume = gst_element_factory_make ("volume", "volume");
1055 g_object_set (G_OBJECT (volume), "volume", play_bin->volume, NULL);
1056 play_bin->volume_element = volume;
1057 gst_bin_add (GST_BIN_CAST (element), volume);
1059 res = gst_element_link_pads (conv, "src", scale, "sink");
1060 res &= gst_element_link_pads (scale, "src", volume, "sink");
1061 res &= gst_element_link_pads (volume, "src", sink, NULL);
1065 pad = gst_element_get_pad (conv, "sink");
1066 gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
1067 gst_object_unref (pad);
1069 gst_element_set_state (element, GST_STATE_READY);
1071 /* since we're gonna add it to a bin but don't want to lose it,
1072 * we keep a reference. */
1073 gst_object_ref (element);
1074 g_hash_table_insert (play_bin->cache, "abin", element);
1081 post_missing_element_message (play_bin, "autoaudiosink");
1082 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1083 (_("Both autoaudiosink and alsasink elements are missing.")), (NULL));
1088 post_missing_element_message (play_bin, "audioconvert");
1089 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1090 (_("Missing element '%s' - check your GStreamer installation."),
1091 "audioconvert"), ("possibly a liboil version mismatch?"));
1092 gst_object_unref (element);
1098 post_missing_element_message (play_bin, "audioresample");
1099 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1100 (_("Missing element '%s' - check your GStreamer installation."),
1101 "audioresample"), ("possibly a liboil version mismatch?"));
1102 gst_object_unref (element);
1107 GST_ELEMENT_ERROR (play_bin, CORE, PAD,
1108 (NULL), ("Failed to configure the audio sink."));
1109 gst_object_unref (element);
1114 /* make the element (bin) that contains the elements needed to perform
1115 * visualisation ouput. The idea is to split the audio using tee, then
1116 * sending the output to the regular audio bin and the other output to
1117 * the vis plugin that transforms it into a video that is rendered with the
1118 * normal video bin. The video and audio bins are run in threads to make sure
1119 * they don't block eachother.
1121 * +-----------------------------------------------------------------------+
1123 * | +------+ +--------+ +----------------+ |
1124 * | | tee | | aqueue | | abin ... | |
1125 * | +-sink src-sink src-sink | |
1126 * | | | | +--------+ +----------------+ |
1128 * | | | | +------+ +------------+ +------+ +-----------+ |
1129 * | | | | |vqueue| | audioconv | | vis | | vbin ... | |
1130 * | | | src-sink src-sink + samp src-sink src-sink | |
1131 * | | | | +------+ +------------+ +------+ +-----------+ |
1135 * +-----------------------------------------------------------------------+
1138 gen_vis_element (GstPlayBin * play_bin)
1141 GstElement *element;
1149 GstElement *vqueue, *aqueue;
1152 /* errors are already posted when these fail. */
1153 asink = gen_audio_element (play_bin);
1156 vsink = gen_video_element (play_bin);
1158 gst_object_unref (asink);
1162 element = gst_bin_new ("visbin");
1163 tee = gst_element_factory_make ("tee", "tee");
1165 vqueue = gst_element_factory_make ("queue", "vqueue");
1166 aqueue = gst_element_factory_make ("queue", "aqueue");
1168 gst_bin_add (GST_BIN_CAST (element), asink);
1169 gst_bin_add (GST_BIN_CAST (element), vqueue);
1170 gst_bin_add (GST_BIN_CAST (element), aqueue);
1171 gst_bin_add (GST_BIN_CAST (element), vsink);
1172 gst_bin_add (GST_BIN_CAST (element), tee);
1174 conv = gst_element_factory_make ("audioconvert", "aconv");
1176 goto no_audioconvert;
1177 gst_bin_add (GST_BIN_CAST (element), conv);
1179 resamp = gst_element_factory_make ("audioresample", "aresamp");
1181 goto no_audioresample;
1182 gst_bin_add (GST_BIN_CAST (element), resamp);
1184 conv2 = gst_element_factory_make ("audioconvert", "aconv2");
1186 goto no_audioconvert;
1187 gst_bin_add (GST_BIN_CAST (element), conv2);
1189 if (play_bin->visualisation) {
1190 gst_object_ref (play_bin->visualisation);
1191 vis = play_bin->visualisation;
1193 vis = gst_element_factory_make ("goom", "vis");
1197 gst_bin_add (GST_BIN_CAST (element), vis);
1199 res = gst_element_link_pads (vqueue, "src", conv, "sink");
1200 res &= gst_element_link_pads (conv, "src", resamp, "sink");
1201 res &= gst_element_link_pads (resamp, "src", conv2, "sink");
1202 res &= gst_element_link_pads (conv2, "src", vis, "sink");
1203 res &= gst_element_link_pads (vis, "src", vsink, "sink");
1207 pad = gst_element_get_pad (aqueue, "sink");
1208 rpad = gst_element_get_request_pad (tee, "src%d");
1209 gst_pad_link (rpad, pad);
1210 gst_object_unref (rpad);
1211 gst_object_unref (pad);
1212 gst_element_link_pads (aqueue, "src", asink, "sink");
1214 pad = gst_element_get_pad (vqueue, "sink");
1215 rpad = gst_element_get_request_pad (tee, "src%d");
1216 gst_pad_link (rpad, pad);
1217 gst_object_unref (rpad);
1218 gst_object_unref (pad);
1220 pad = gst_element_get_pad (tee, "sink");
1221 gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
1222 gst_object_unref (pad);
1229 post_missing_element_message (play_bin, "audioconvert");
1230 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1231 (_("Missing element '%s' - check your GStreamer installation."),
1232 "audioconvert"), ("possibly a liboil version mismatch?"));
1233 gst_object_unref (element);
1238 post_missing_element_message (play_bin, "audioresample");
1239 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1240 (_("Missing element '%s' - check your GStreamer installation."),
1241 "audioresample"), (NULL));
1242 gst_object_unref (element);
1247 post_missing_element_message (play_bin, "goom");
1248 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1249 (_("Missing element '%s' - check your GStreamer installation."),
1251 gst_object_unref (element);
1256 GST_ELEMENT_ERROR (play_bin, CORE, PAD,
1257 (NULL), ("Failed to configure the visualisation element."));
1258 gst_object_unref (element);
1263 /* get rid of all installed sinks */
1265 remove_sinks (GstPlayBin * play_bin)
1269 GstElement *element;
1272 if (play_bin->cache == NULL)
1275 GST_DEBUG ("removesinks");
1276 element = g_hash_table_lookup (play_bin->cache, "abin");
1277 if (element != NULL) {
1278 parent = gst_element_get_parent (element);
1279 if (parent != NULL) {
1280 /* we remove the element from the parent so that
1281 * there is no unwanted state change when the parent
1283 play_bin->sinks = g_list_remove (play_bin->sinks, element);
1284 gst_element_set_state (element, GST_STATE_NULL);
1285 gst_bin_remove (GST_BIN_CAST (parent), element);
1286 gst_object_unref (parent);
1288 pad = gst_element_get_pad (element, "sink");
1290 peer = gst_pad_get_peer (pad);
1292 gst_pad_unlink (peer, pad);
1293 gst_object_unref (peer);
1295 gst_object_unref (pad);
1298 element = g_hash_table_lookup (play_bin->cache, "vbin");
1299 if (element != NULL) {
1300 parent = gst_element_get_parent (element);
1301 if (parent != NULL) {
1302 play_bin->sinks = g_list_remove (play_bin->sinks, element);
1303 gst_element_set_state (element, GST_STATE_NULL);
1304 gst_bin_remove (GST_BIN_CAST (parent), element);
1305 gst_object_unref (parent);
1307 pad = gst_element_get_pad (element, "sink");
1309 peer = gst_pad_get_peer (pad);
1311 gst_pad_unlink (peer, pad);
1312 gst_object_unref (peer);
1314 gst_object_unref (pad);
1318 for (sinks = play_bin->sinks; sinks; sinks = g_list_next (sinks)) {
1319 GstElement *element = GST_ELEMENT_CAST (sinks->data);
1323 pad = gst_element_get_pad (element, "sink");
1325 GST_LOG ("removing sink %p", element);
1327 peer = gst_pad_get_peer (pad);
1329 gst_pad_unlink (peer, pad);
1330 gst_object_unref (peer);
1332 gst_object_unref (pad);
1334 gst_element_set_state (element, GST_STATE_NULL);
1335 gst_bin_remove (GST_BIN_CAST (play_bin), element);
1337 g_list_free (play_bin->sinks);
1338 play_bin->sinks = NULL;
1340 if (play_bin->visualisation) {
1341 GstElement *vis_bin;
1344 GST_ELEMENT_CAST (gst_element_get_parent (play_bin->visualisation));
1346 gst_element_set_state (play_bin->visualisation, GST_STATE_NULL);
1349 gst_bin_remove (GST_BIN_CAST (vis_bin), play_bin->visualisation);
1350 gst_object_unref (vis_bin);
1354 if (play_bin->frame) {
1355 gst_buffer_unref (play_bin->frame);
1356 play_bin->frame = NULL;
1359 if (play_bin->textoverlay_element) {
1360 gst_object_unref (play_bin->textoverlay_element);
1361 play_bin->textoverlay_element = NULL;
1365 /* loop over the streams and set up the pipeline to play this
1366 * media file. First we count the number of audio and video streams.
1367 * If there is no video stream but there exists an audio stream,
1368 * we install a visualisation pipeline.
1370 * Also make sure to only connect the first audio and video pad. FIXME
1371 * this should eventually be handled with a tuner interface so that
1372 * one can switch the streams.
1374 * This function takes ownership of @sink.*
1377 add_sink (GstPlayBin * play_bin, GstElement * sink, GstPad * srcpad,
1378 GstPad * subtitle_pad)
1381 GstPadLinkReturn linkres;
1383 GstStateChangeReturn stateret;
1386 g_return_val_if_fail (sink != NULL, FALSE);
1388 state = GST_STATE_PAUSED;
1390 /* this is only for debugging */
1391 parent = gst_pad_get_parent_element (srcpad);
1393 GST_DEBUG ("Adding sink %" GST_PTR_FORMAT
1394 " with state %d (parent: %d, peer: %d)", sink,
1395 GST_STATE (sink), GST_STATE (play_bin), GST_STATE (parent));
1396 gst_object_unref (parent);
1398 gst_bin_add (GST_BIN_CAST (play_bin), sink);
1400 /* bring it to the required state so we can link to the peer without
1401 * breaking the flow */
1402 stateret = gst_element_set_state (sink, state);
1403 if (stateret == GST_STATE_CHANGE_FAILURE)
1406 /* we found a sink for this stream, now try to install it */
1407 sinkpad = gst_element_get_pad (sink, "sink");
1408 linkres = gst_pad_link (srcpad, sinkpad);
1409 gst_object_unref (sinkpad);
1411 /* try to link the pad of the sink to the stream */
1412 if (GST_PAD_LINK_FAILED (linkres))
1415 if (GST_IS_PAD (subtitle_pad)) {
1416 sinkpad = gst_element_get_pad (sink, "text_sink");
1417 linkres = gst_pad_link (subtitle_pad, sinkpad);
1418 gst_object_unref (sinkpad);
1421 /* try to link the subtitle pad of the sink to the stream, this is not
1423 if (GST_PAD_LINK_FAILED (linkres))
1424 goto subtitle_failed;
1427 /* we got the sink succesfully linked, now keep the sink
1428 * in our internal list */
1429 play_bin->sinks = g_list_prepend (play_bin->sinks, sink);
1436 gst_element_set_state (sink, GST_STATE_NULL);
1437 gst_bin_remove (GST_BIN_CAST (play_bin), sink);
1438 GST_DEBUG_OBJECT (play_bin, "state change failure when adding sink");
1446 /* could not link this stream */
1447 caps = gst_pad_get_caps (srcpad);
1448 capsstr = gst_caps_to_string (caps);
1449 g_warning ("could not link %s: %d", capsstr, linkres);
1450 GST_DEBUG_OBJECT (play_bin,
1451 "link failed when adding sink, caps %s, reason %d", capsstr, linkres);
1453 gst_caps_unref (caps);
1455 gst_element_set_state (sink, GST_STATE_NULL);
1456 gst_bin_remove (GST_BIN_CAST (play_bin), sink);
1463 /* could not link this stream */
1464 caps = gst_pad_get_caps (subtitle_pad);
1465 GST_WARNING_OBJECT (play_bin, "subtitle link failed when adding sink, "
1466 "caps = %" GST_PTR_FORMAT ", reason %d", caps, linkres);
1467 gst_caps_unref (caps);
1475 dummy_blocked_cb (GstPad * pad, gboolean blocked, gpointer user_data)
1480 setup_sinks (GstPlayBaseBin * play_base_bin, GstPlayBaseGroup * group)
1482 GstPlayBin *play_bin = GST_PLAY_BIN (play_base_bin);
1483 GList *streaminfo = NULL, *s;
1484 gboolean need_vis = FALSE;
1485 gboolean need_text = FALSE;
1486 GstPad *textsrcpad = NULL, *pad = NULL, *origtextsrcpad = NULL;
1488 gboolean res = TRUE;
1490 /* get rid of existing sinks */
1491 if (play_bin->sinks) {
1492 remove_sinks (play_bin);
1494 GST_DEBUG_OBJECT (play_base_bin, "setupsinks");
1496 /* find out what to do */
1497 if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads > 0 &&
1498 group->type[GST_STREAM_TYPE_TEXT - 1].npads > 0) {
1500 } else if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads == 0 &&
1501 group->type[GST_STREAM_TYPE_AUDIO - 1].npads > 0 &&
1502 play_bin->visualisation != NULL) {
1506 /* now actually connect everything */
1507 g_object_get (G_OBJECT (play_base_bin), "stream-info", &streaminfo, NULL);
1508 for (s = streaminfo; s; s = g_list_next (s)) {
1509 GObject *obj = G_OBJECT (s->data);
1513 g_object_get (obj, "type", &type, NULL);
1514 g_object_get (obj, "object", &object, NULL);
1518 if (group->type[GST_STREAM_TYPE_AUDIO - 1].npads > 0) {
1520 sink = gen_vis_element (play_bin);
1522 sink = gen_audio_element (play_bin);
1527 pad = gst_element_get_pad (group->type[GST_STREAM_TYPE_AUDIO - 1].preroll,
1529 res = add_sink (play_bin, sink, pad, NULL);
1530 gst_object_unref (pad);
1534 if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads > 0) {
1536 GstObject *parent = NULL, *grandparent = NULL;
1537 GstPad *ghost = NULL;
1539 sink = gen_text_element (play_bin);
1541 gst_element_get_pad (group->type[GST_STREAM_TYPE_TEXT - 1].preroll,
1544 /* This pad is from subtitle-bin, we need to create a ghost pad to have
1545 common grandparents */
1546 parent = gst_object_get_parent (GST_OBJECT_CAST (textsrcpad));
1548 GST_WARNING_OBJECT (textsrcpad, "subtitle pad has no parent !");
1549 gst_object_unref (textsrcpad);
1554 grandparent = gst_object_get_parent (parent);
1556 GST_WARNING_OBJECT (textsrcpad, "subtitle pad has no grandparent !");
1557 gst_object_unref (parent);
1558 gst_object_unref (textsrcpad);
1563 /* We ghost the pad on subtitle_bin only, if the text pad is from the
1564 media demuxer we keep it as it is */
1565 if (!GST_IS_PLAY_BIN (grandparent)) {
1566 GST_DEBUG_OBJECT (textsrcpad, "this subtitle pad is from a subtitle "
1567 "file, ghosting to a suitable hierarchy");
1568 /* Block the pad first, because as soon as we add a ghostpad, the queue
1569 * will try and start pushing */
1570 gst_pad_set_blocked_async (textsrcpad, TRUE, dummy_blocked_cb, NULL);
1571 origtextsrcpad = gst_object_ref (textsrcpad);
1573 ghost = gst_ghost_pad_new ("text_src", textsrcpad);
1574 if (!GST_IS_PAD (ghost)) {
1575 GST_WARNING_OBJECT (textsrcpad, "failed creating ghost pad for "
1577 gst_object_unref (parent);
1578 gst_object_unref (grandparent);
1579 gst_object_unref (textsrcpad);
1584 gst_pad_set_active (ghost, TRUE);
1585 if (gst_element_add_pad (GST_ELEMENT_CAST (grandparent), ghost)) {
1586 gst_object_unref (textsrcpad);
1587 textsrcpad = gst_object_ref (ghost);
1589 GST_WARNING_OBJECT (ghost, "failed adding ghost pad on subtitle-bin");
1590 gst_pad_set_active (ghost, FALSE);
1591 gst_object_unref (ghost);
1592 gst_object_unref (textsrcpad);
1596 GST_DEBUG_OBJECT (textsrcpad, "this subtitle pad is from the demuxer "
1597 "no changes to hierarchy needed");
1600 gst_object_unref (parent);
1601 gst_object_unref (grandparent);
1603 sink = gen_video_element (play_bin);
1608 pad = gst_element_get_pad (group->type[GST_STREAM_TYPE_VIDEO - 1].preroll,
1610 res = add_sink (play_bin, sink, pad, textsrcpad);
1611 gst_object_unref (pad);
1613 gst_object_unref (textsrcpad);
1614 if (origtextsrcpad) {
1615 gst_pad_set_blocked_async (origtextsrcpad, FALSE, dummy_blocked_cb, NULL);
1616 gst_object_unref (origtextsrcpad);
1620 /* remove the sinks now, pipeline get_state will now wait for the
1621 * sinks to preroll */
1622 if (play_bin->fakesink) {
1623 gst_element_set_state (play_bin->fakesink, GST_STATE_NULL);
1624 gst_bin_remove (GST_BIN_CAST (play_bin), play_bin->fakesink);
1625 play_bin->fakesink = NULL;
1632 playbin_set_subtitles_visible (GstPlayBaseBin * play_base_bin, gboolean visible)
1634 GstPlayBin *playbin = GST_PLAY_BIN (play_base_bin);
1636 /* we're ignoring the case of someone setting the 'current-text' property
1637 * before textoverlay is set up (which is probably okay, since playbasebin
1638 * will just select the first subtitle stream as active stream regardless) */
1639 if (playbin->textoverlay_element != NULL) {
1640 GST_LOG_OBJECT (playbin, "setting subtitle visibility to %d", visible);
1641 g_object_set (playbin->textoverlay_element, "silent", !visible, NULL);
1645 /* Send an event to our sinks until one of them works; don't then send to the
1646 * remaining sinks (unlike GstBin)
1649 gst_play_bin_send_event_to_sink (GstPlayBin * play_bin, GstEvent * event)
1651 GList *sinks = play_bin->sinks;
1652 gboolean res = TRUE;
1655 GstElement *sink = GST_ELEMENT_CAST (sinks->data);
1657 gst_event_ref (event);
1658 if ((res = gst_element_send_event (sink, event))) {
1659 GST_DEBUG_OBJECT (play_bin,
1660 "Sent event succesfully to sink %" GST_PTR_FORMAT, sink);
1663 GST_DEBUG_OBJECT (play_bin,
1664 "Event failed when sent to sink %" GST_PTR_FORMAT, sink);
1666 sinks = g_list_next (sinks);
1669 gst_event_unref (event);
1674 /* We only want to send the event to a single sink (overriding GstBin's
1675 * behaviour), but we want to keep GstPipeline's behaviour - wrapping seek
1676 * events appropriately. So, this is a messy duplication of code. */
1678 gst_play_bin_send_event (GstElement * element, GstEvent * event)
1680 gboolean res = FALSE;
1681 GstEventType event_type = GST_EVENT_TYPE (event);
1683 switch (event_type) {
1684 case GST_EVENT_SEEK:
1685 GST_DEBUG_OBJECT (element, "Sending seek event to a sink");
1686 res = gst_play_bin_send_event_to_sink (GST_PLAY_BIN (element), event);
1689 res = parent_class->send_event (element, event);
1697 value_list_append_structure_list (GValue * list_val, GstStructure ** first,
1698 GList * structure_list)
1702 for (l = structure_list; l != NULL; l = l->next) {
1703 GValue val = { 0, };
1706 *first = gst_structure_copy ((GstStructure *) l->data);
1708 g_value_init (&val, GST_TYPE_STRUCTURE);
1709 g_value_take_boxed (&val, gst_structure_copy ((GstStructure *) l->data));
1710 gst_value_list_append_value (list_val, &val);
1711 g_value_unset (&val);
1715 /* if it's a redirect message with multiple redirect locations we might
1716 * want to pick a different 'best' location depending on the required
1717 * bitrates and the connection speed */
1719 gst_play_bin_handle_redirect_message (GstPlayBin * playbin, GstMessage * msg)
1721 const GValue *locations_list, *location_val;
1722 GstMessage *new_msg;
1723 GstStructure *new_structure = NULL;
1724 GList *l_good = NULL, *l_neutral = NULL, *l_bad = NULL;
1725 GValue new_list = { 0, };
1727 GstPlayBaseBin *playbasebin = GST_PLAY_BASE_BIN (playbin);
1728 guint connection_speed = playbasebin->connection_speed;
1730 GST_DEBUG_OBJECT (playbin, "redirect message: %" GST_PTR_FORMAT, msg);
1731 GST_DEBUG_OBJECT (playbin, "connection speed: %u", connection_speed);
1733 if (connection_speed == 0 || msg->structure == NULL)
1736 locations_list = gst_structure_get_value (msg->structure, "locations");
1737 if (locations_list == NULL)
1740 size = gst_value_list_get_size (locations_list);
1744 /* maintain existing order as much as possible, just sort references
1745 * with too high a bitrate to the end (the assumption being that if
1746 * bitrates are given they are given for all interesting streams and
1747 * that the you-need-at-least-version-xyz redirect has the same bitrate
1748 * as the lowest referenced redirect alternative) */
1749 for (i = 0; i < size; ++i) {
1750 const GstStructure *s;
1753 location_val = gst_value_list_get_value (locations_list, i);
1754 s = (const GstStructure *) g_value_get_boxed (location_val);
1755 if (!gst_structure_get_int (s, "minimum-bitrate", &bitrate) || bitrate <= 0) {
1756 GST_DEBUG_OBJECT (playbin, "no bitrate: %" GST_PTR_FORMAT, s);
1757 l_neutral = g_list_append (l_neutral, (gpointer) s);
1758 } else if (bitrate > connection_speed) {
1759 GST_DEBUG_OBJECT (playbin, "bitrate too high: %" GST_PTR_FORMAT, s);
1760 l_bad = g_list_append (l_bad, (gpointer) s);
1761 } else if (bitrate <= connection_speed) {
1762 GST_DEBUG_OBJECT (playbin, "bitrate OK: %" GST_PTR_FORMAT, s);
1763 l_good = g_list_append (l_good, (gpointer) s);
1767 g_value_init (&new_list, GST_TYPE_LIST);
1768 value_list_append_structure_list (&new_list, &new_structure, l_good);
1769 value_list_append_structure_list (&new_list, &new_structure, l_neutral);
1770 value_list_append_structure_list (&new_list, &new_structure, l_bad);
1771 gst_structure_set_value (new_structure, "locations", &new_list);
1772 g_value_unset (&new_list);
1774 g_list_free (l_good);
1775 g_list_free (l_neutral);
1776 g_list_free (l_bad);
1778 new_msg = gst_message_new_element (msg->src, new_structure);
1779 gst_message_unref (msg);
1781 GST_DEBUG_OBJECT (playbin, "new redirect message: %" GST_PTR_FORMAT, new_msg);
1786 gst_play_bin_handle_message (GstBin * bin, GstMessage * msg)
1788 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ELEMENT && msg->structure != NULL
1789 && gst_structure_has_name (msg->structure, "redirect")) {
1790 msg = gst_play_bin_handle_redirect_message (GST_PLAY_BIN (bin), msg);
1793 GST_BIN_CLASS (parent_class)->handle_message (bin, msg);
1796 static GstStateChangeReturn
1797 gst_play_bin_change_state (GstElement * element, GstStateChange transition)
1799 GstStateChangeReturn ret;
1800 GstPlayBin *play_bin;
1802 play_bin = GST_PLAY_BIN (element);
1805 switch (transition) {
1806 case GST_STATE_CHANGE_READY_TO_PAUSED:
1807 /* this really is the easiest way to make the state change return
1808 * ASYNC until we added the sinks */
1809 if (!play_bin->fakesink) {
1810 play_bin->fakesink = gst_element_factory_make ("fakesink", "test");
1811 gst_bin_add (GST_BIN_CAST (play_bin), play_bin->fakesink);
1818 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1819 if (ret == GST_STATE_CHANGE_FAILURE)
1822 switch (transition) {
1823 case GST_STATE_CHANGE_READY_TO_PAUSED:
1824 /* remember us being a live pipeline */
1825 play_bin->is_live = (ret == GST_STATE_CHANGE_NO_PREROLL);
1826 GST_DEBUG_OBJECT (play_bin, "is live: %d", play_bin->is_live);
1828 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1829 /* FIXME Release audio device when we implement that */
1831 case GST_STATE_CHANGE_PAUSED_TO_READY:
1832 case GST_STATE_CHANGE_READY_TO_NULL:
1833 /* remove sinks we added */
1834 remove_sinks (play_bin);
1835 /* and there might be a fakesink we need to clean up now */
1836 if (play_bin->fakesink) {
1837 gst_element_set_state (play_bin->fakesink, GST_STATE_NULL);
1838 gst_bin_remove (GST_BIN_CAST (play_bin), play_bin->fakesink);
1839 play_bin->fakesink = NULL;
1850 gst_play_bin_plugin_init (GstPlugin * plugin)
1852 GST_DEBUG_CATEGORY_INIT (gst_play_bin_debug, "playbin", 0, "play bin");
1854 return gst_element_register (plugin, "playbin", GST_RANK_NONE,