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
23 * Playbin provides a stand-alone everything-in-one abstraction for an
24 * audio and/or video player.
26 * It can handle both audio and video files and features
29 * automatic file type recognition and based on that automatic
30 * selection and usage of the right audio/video/subtitle demuxers/decoders
33 * visualisations for audio files
36 * subtitle support for video files
39 * stream selection between different audio/subtitles streams
42 * meta info (tag) extraction
45 * easy access to the last video frame
48 * buffering when playing streams over a network
56 * <title>Usage</title>
58 * A playbin element can be created just like any other element using
59 * gst_element_factory_make(). The file/URI to play should be set via the #GstPlayBin:uri
60 * property. This must be an absolute URI, relative file paths are not allowed.
61 * Example URIs are file:///home/joe/movie.avi or http://www.joedoe.com/foo.ogg
63 * Playbin is a #GstPipeline. It will notify the application of everything
64 * that's happening (errors, end of stream, tags found, state changes, etc.)
65 * by posting messages on its #GstBus. The application needs to watch the
68 * Playback can be initiated by setting the element to PLAYING state using
69 * gst_element_set_state(). Note that the state change will take place in
70 * the background in a separate thread, when the function returns playback
71 * is probably not happening yet and any errors might not have occured yet.
72 * Applications using playbin should ideally be written to deal with things
73 * completely asynchroneous.
75 * When playback has finished (an EOS message has been received on the bus)
76 * or an error has occured (an ERROR message has been received on the bus) or
77 * the user wants to play a different track, playbin should be set back to
78 * READY or NULL state, then the #GstPlayBin:uri property should be set to the
79 * new location and then playbin be set to PLAYING state again.
81 * Seeking can be done using gst_element_seek_simple() or gst_element_seek()
82 * on the playbin element. Again, the seek will not be executed
83 * instantaneously, but will be done in a background thread. When the seek
84 * call returns the seek will most likely still be in process. An application
85 * may wait for the seek to finish (or fail) using gst_element_get_state() with
86 * -1 as the timeout, but this will block the user interface and is not
89 * Applications may query the current position and duration of the stream
90 * via gst_element_query_position() and gst_element_query_duration() and
91 * setting the format passed to GST_FORMAT_TIME. If the query was successful,
92 * the duration or position will have been returned in units of nanoseconds.
96 * <title>Advanced Usage: specifying the audio and video sink</title>
98 * By default, if no audio sink or video sink has been specified via the
99 * #GstPlayBin:audio-sink or #GstPlayBin:video-sink property, playbin will use
100 * the autoaudiosink and autovideosink elements to find the first-best
101 * available output method.
102 * This should work in most cases, but is not always desirable. Often either
103 * the user or application might want to specify more explicitly what to use
104 * for audio and video output.
106 * If the application wants more control over how audio or video should be
107 * output, it may create the audio/video sink elements itself (for example
108 * using gst_element_factory_make()) and provide them to playbin using the
109 * #GstPlayBin:audio-sink or #GstPlayBin:video-sink property.
111 * GNOME-based applications, for example, will usually want to create
112 * gconfaudiosink and gconfvideosink elements and make playbin use those,
113 * so that output happens to whatever the user has configured in the GNOME
114 * Multimedia System Selector confinguration dialog.
116 * The sink elements do not necessarily need to be ready-made sinks. It is
117 * possible to create container elements that look like a sink to playbin,
118 * but in reality contain a number of custom elements linked together. This
119 * can be achieved by creating a #GstBin and putting elements in there and
120 * linking them, and then creating a sink #GstGhostPad for the bin and pointing
121 * it to the sink pad of the first element within the bin. This can be used
122 * for a number of purposes, for example to force output to a particular
123 * format or to modify or observe the data before it is output.
125 * It is also possible to 'suppress' audio and/or video output by using
126 * 'fakesink' elements (or capture it from there using the fakesink element's
127 * "handoff" signal, which, nota bene, is fired from the streaming thread!).
131 * <title>Retrieving Tags and Other Meta Data</title>
133 * Most of the common meta data (artist, title, etc.) can be retrieved by
134 * watching for TAG messages on the pipeline's bus (see above).
136 * Other more specific meta information like width/height/framerate of video
137 * streams or samplerate/number of channels of audio streams can be obtained
138 * using the #GstPlayBaseBin:stream-info property, which will return a GList of
139 * stream info objects, one for each stream. These are opaque objects that can
140 * only be accessed via the standard GObject property interface, ie. g_object_get().
141 * Each stream info object has the following properties:
143 * <listitem>"object" (GstObject) (the decoder source pad usually)</listitem>
144 * <listitem>"type" (enum) (if this is an audio/video/subtitle stream)</listitem>
145 * <listitem>"decoder" (string) (name of decoder used to decode this stream)</listitem>
146 * <listitem>"mute" (boolean) (to mute or unmute this stream)</listitem>
147 * <listitem>"caps" (GstCaps) (caps of the decoded stream)</listitem>
148 * <listitem>"language-code" (string) (ISO-639 language code for this stream, mostly used for audio/subtitle streams)</listitem>
149 * <listitem>"codec" (string) (format this stream was encoded in)</listitem>
151 * Stream information from the #GstPlayBaseBin:stream-info property is best queried once
152 * playbin has changed into PAUSED or PLAYING state (which can be detected
153 * via a state-changed message on the #GstBus where old_state=READY and
154 * new_state=PAUSED), since before that the list might not be complete yet or
155 * not contain all available information (like language-codes).
159 * <title>Buffering</title>
160 * Playbin handles buffering automatically for the most part, but applications
161 * need to handle parts of the buffering process as well. Whenever playbin is
162 * buffering, it will post BUFFERING messages on the bus with a percentage
163 * value that shows the progress of the buffering process. Applications need
164 * to set playbin to PLAYING or PAUSED state in response to these messages.
165 * They may also want to convey the buffering progress to the user in some
166 * way. Here is how to extract the percentage information from the message
167 * (requires GStreamer >= 0.10.11):
169 * switch (GST_MESSAGE_TYPE (msg)) {
170 * case GST_MESSAGE_BUFFERING: {
172 * gst_message_parse_buffering (msg, &percent);
173 * g_print ("Buffering (%%u percent done)", percent);
179 * Note that applications should keep/set the pipeline in the PAUSED state when
180 * a BUFFERING message is received with a buffer percent value < 100 and set
181 * the pipeline back to PLAYING state when a BUFFERING message with a value
182 * of 100 percent is received (if PLAYING is the desired state, that is).
185 * <title>Embedding the video window in your application</title>
186 * By default, playbin (or rather the video sinks used) will create their own
187 * window. Applications will usually want to force output to a window of their
188 * own, however. This can be done using the GstXOverlay interface, which most
189 * video sinks implement. See the documentation there for more details.
192 * <title>Specifying which CD/DVD device to use</title>
193 * The device to use for CDs/DVDs needs to be set on the source element
194 * playbin creates before it is opened. The only way to do this at the moment
195 * is to connect to playbin's "notify::source" signal, which will be emitted
196 * by playbin when it has created the source element for a particular URI.
197 * In the signal callback you can check if the source element has a "device"
198 * property and set it appropriately. In future ways might be added to specify
199 * the device as part of the URI, but at the time of writing this is not
203 * <title>Examples</title>
205 * gst-launch -v playbin uri=file:///path/to/somefile.avi
206 * ]| This will play back the given AVI video file, given that the video and
207 * audio decoders required to decode the content are installed. Since no
208 * special audio sink or video sink is supplied (not possible via gst-launch),
209 * playbin will try to find a suitable audio and video sink automatically
210 * using the autoaudiosink and autovideosink elements.
212 * gst-launch -v playbin uri=cdda://4
213 * ]| This will play back track 4 on an audio CD in your disc drive (assuming
214 * the drive is detected automatically by the plugin).
216 * gst-launch -v playbin uri=dvd://1
217 * ]| This will play back title 1 of a DVD in your disc drive (assuming
218 * the drive is detected automatically by the plugin).
229 #include <gst/gst-i18n-plugin.h>
230 #include <gst/pbutils/pbutils.h>
232 #include "gstplaybasebin.h"
234 GST_DEBUG_CATEGORY_STATIC (gst_play_bin_debug);
235 #define GST_CAT_DEFAULT gst_play_bin_debug
237 #define GST_TYPE_PLAY_BIN (gst_play_bin_get_type())
238 #define GST_PLAY_BIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PLAY_BIN,GstPlayBin))
239 #define GST_PLAY_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PLAY_BIN,GstPlayBinClass))
240 #define GST_IS_PLAY_BIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PLAY_BIN))
241 #define GST_IS_PLAY_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PLAY_BIN))
243 #define VOLUME_MAX_DOUBLE 10.0
245 typedef struct _GstPlayBin GstPlayBin;
246 typedef struct _GstPlayBinClass GstPlayBinClass;
251 * High-level player element
255 GstPlayBaseBin parent;
257 /* the configurable elements */
258 GstElement *fakesink;
259 GstElement *audio_sink;
260 GstElement *video_sink;
261 GstElement *visualisation;
262 GstElement *pending_visualisation;
263 GstElement *volume_element;
264 GstElement *textoverlay_element;
267 /* these are the currently active sinks */
270 /* the last captured frame for snapshots */
273 /* our cache for the sinks */
276 /* font description */
279 /* indication if the pipeline is live */
283 struct _GstPlayBinClass
285 GstPlayBaseBinClass parent_class;
306 static void gst_play_bin_class_init (GstPlayBinClass * klass);
307 static void gst_play_bin_init (GstPlayBin * play_bin);
308 static void gst_play_bin_dispose (GObject * object);
310 static gboolean setup_sinks (GstPlayBaseBin * play_base_bin,
311 GstPlayBaseGroup * group);
312 static void remove_sinks (GstPlayBin * play_bin);
313 static void playbin_set_subtitles_visible (GstPlayBaseBin * play_base_bin,
315 static void playbin_set_audio_mute (GstPlayBaseBin * play_base_bin,
318 static void gst_play_bin_set_property (GObject * object, guint prop_id,
319 const GValue * value, GParamSpec * spec);
320 static void gst_play_bin_get_property (GObject * object, guint prop_id,
321 GValue * value, GParamSpec * spec);
323 static gboolean gst_play_bin_send_event (GstElement * element,
325 static GstStateChangeReturn gst_play_bin_change_state (GstElement * element,
326 GstStateChange transition);
328 static void gst_play_bin_handle_message (GstBin * bin, GstMessage * message);
330 static GstElementClass *parent_class;
332 //static guint gst_play_bin_signals[LAST_SIGNAL] = { 0 };
334 static const GstElementDetails gst_play_bin_details =
335 GST_ELEMENT_DETAILS ("Player Bin",
336 "Generic/Bin/Player",
337 "Autoplug and play media from an uri",
338 "Wim Taymans <wim.taymans@gmail.com>");
341 gst_play_bin_get_type (void)
343 static GType gst_play_bin_type = 0;
345 if (!gst_play_bin_type) {
346 static const GTypeInfo gst_play_bin_info = {
347 sizeof (GstPlayBinClass),
350 (GClassInitFunc) gst_play_bin_class_init,
355 (GInstanceInitFunc) gst_play_bin_init,
359 gst_play_bin_type = g_type_register_static (GST_TYPE_PLAY_BASE_BIN,
360 "GstPlayBin", &gst_play_bin_info, 0);
363 return gst_play_bin_type;
367 gst_play_bin_class_init (GstPlayBinClass * klass)
369 GObjectClass *gobject_klass;
370 GstElementClass *gstelement_klass;
371 GstBinClass *gstbin_klass;
372 GstPlayBaseBinClass *playbasebin_klass;
374 gobject_klass = (GObjectClass *) klass;
375 gstelement_klass = (GstElementClass *) klass;
376 gstbin_klass = (GstBinClass *) klass;
377 playbasebin_klass = (GstPlayBaseBinClass *) klass;
379 parent_class = g_type_class_peek_parent (klass);
381 gobject_klass->set_property = gst_play_bin_set_property;
382 gobject_klass->get_property = gst_play_bin_get_property;
384 g_object_class_install_property (gobject_klass, ARG_VIDEO_SINK,
385 g_param_spec_object ("video-sink", "Video Sink",
386 "the video output element to use (NULL = default sink)",
387 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
388 g_object_class_install_property (gobject_klass, ARG_AUDIO_SINK,
389 g_param_spec_object ("audio-sink", "Audio Sink",
390 "the audio output element to use (NULL = default sink)",
391 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
392 g_object_class_install_property (gobject_klass, ARG_VIS_PLUGIN,
393 g_param_spec_object ("vis-plugin", "Vis plugin",
394 "the visualization element to use (NULL = none)",
395 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
396 g_object_class_install_property (gobject_klass, ARG_VOLUME,
397 g_param_spec_double ("volume", "volume", "volume",
398 0.0, VOLUME_MAX_DOUBLE, 1.0,
399 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
400 g_object_class_install_property (gobject_klass, ARG_FRAME,
401 gst_param_spec_mini_object ("frame", "Frame",
402 "The last frame (NULL = no video available)", GST_TYPE_BUFFER,
403 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
404 g_object_class_install_property (gobject_klass, ARG_FONT_DESC,
405 g_param_spec_string ("subtitle-font-desc", "Subtitle font description",
406 "Pango font description of font " "to be used for subtitle rendering",
407 NULL, G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
409 gobject_klass->dispose = GST_DEBUG_FUNCPTR (gst_play_bin_dispose);
411 gst_element_class_set_details (gstelement_klass, &gst_play_bin_details);
413 gstelement_klass->change_state =
414 GST_DEBUG_FUNCPTR (gst_play_bin_change_state);
415 gstelement_klass->send_event = GST_DEBUG_FUNCPTR (gst_play_bin_send_event);
417 gstbin_klass->handle_message =
418 GST_DEBUG_FUNCPTR (gst_play_bin_handle_message);
420 playbasebin_klass->setup_output_pads = setup_sinks;
421 playbasebin_klass->set_subtitles_visible = playbin_set_subtitles_visible;
422 playbasebin_klass->set_audio_mute = playbin_set_audio_mute;
426 gst_play_bin_init (GstPlayBin * play_bin)
428 play_bin->video_sink = NULL;
429 play_bin->audio_sink = NULL;
430 play_bin->visualisation = NULL;
431 play_bin->pending_visualisation = NULL;
432 play_bin->volume_element = NULL;
433 play_bin->textoverlay_element = NULL;
434 play_bin->volume = 1.0;
435 play_bin->sinks = NULL;
436 play_bin->frame = NULL;
437 play_bin->font_desc = NULL;
438 play_bin->cache = g_hash_table_new_full (g_str_hash, g_str_equal,
439 NULL, (GDestroyNotify) gst_object_unref);
443 gst_play_bin_dispose (GObject * object)
445 GstPlayBin *play_bin;
447 play_bin = GST_PLAY_BIN (object);
449 if (play_bin->cache != NULL) {
450 remove_sinks (play_bin);
451 g_hash_table_destroy (play_bin->cache);
452 play_bin->cache = NULL;
455 if (play_bin->audio_sink != NULL) {
456 gst_element_set_state (play_bin->audio_sink, GST_STATE_NULL);
457 gst_object_unref (play_bin->audio_sink);
458 play_bin->audio_sink = NULL;
460 if (play_bin->video_sink != NULL) {
461 gst_element_set_state (play_bin->video_sink, GST_STATE_NULL);
462 gst_object_unref (play_bin->video_sink);
463 play_bin->video_sink = NULL;
465 if (play_bin->visualisation != NULL) {
466 gst_element_set_state (play_bin->visualisation, GST_STATE_NULL);
467 gst_object_unref (play_bin->visualisation);
468 play_bin->visualisation = NULL;
470 if (play_bin->pending_visualisation != NULL) {
471 gst_element_set_state (play_bin->pending_visualisation, GST_STATE_NULL);
472 gst_object_unref (play_bin->pending_visualisation);
473 play_bin->pending_visualisation = NULL;
475 if (play_bin->textoverlay_element != NULL) {
476 gst_object_unref (play_bin->textoverlay_element);
477 play_bin->textoverlay_element = NULL;
479 g_free (play_bin->font_desc);
480 play_bin->font_desc = NULL;
482 G_OBJECT_CLASS (parent_class)->dispose (object);
486 gst_play_bin_vis_unblocked (GstPad * tee_pad, gboolean blocked,
489 GstPlayBin *play_bin = GST_PLAY_BIN (user_data);
491 if (play_bin->pending_visualisation)
492 gst_pad_set_blocked_async (tee_pad, FALSE, gst_play_bin_vis_unblocked,
497 gst_play_bin_vis_blocked (GstPad * tee_pad, gboolean blocked,
500 GstPlayBin *play_bin = GST_PLAY_BIN (user_data);
501 GstBin *vis_bin = NULL;
502 GstPad *vis_sink_pad = NULL, *vis_src_pad = NULL, *vqueue_pad = NULL;
504 GstElement *pending_visualisation;
506 GST_OBJECT_LOCK (play_bin);
507 pending_visualisation = play_bin->pending_visualisation;
508 play_bin->pending_visualisation = NULL;
509 GST_OBJECT_UNLOCK (play_bin);
511 /* We want to disable visualisation */
512 if (!GST_IS_ELEMENT (pending_visualisation)) {
513 /* Set visualisation element to READY */
514 gst_element_set_state (play_bin->visualisation, GST_STATE_READY);
519 GST_BIN_CAST (gst_object_get_parent (GST_OBJECT_CAST (play_bin->
522 if (!GST_IS_BIN (vis_bin) || !GST_IS_PAD (tee_pad)) {
526 vis_src_pad = gst_element_get_static_pad (play_bin->visualisation, "src");
527 vis_sink_pad = gst_pad_get_peer (tee_pad);
529 /* Can be fakesink */
530 if (GST_IS_PAD (vis_src_pad)) {
531 vqueue_pad = gst_pad_get_peer (vis_src_pad);
534 if (!GST_IS_PAD (vis_sink_pad)) {
538 /* Check the bin's state */
539 GST_OBJECT_LOCK (vis_bin);
540 bin_state = GST_STATE (vis_bin);
541 GST_OBJECT_UNLOCK (vis_bin);
544 gst_pad_unlink (tee_pad, vis_sink_pad);
545 gst_object_unref (vis_sink_pad);
548 if (GST_IS_PAD (vqueue_pad)) {
549 gst_pad_unlink (vis_src_pad, vqueue_pad);
550 gst_object_unref (vis_src_pad);
554 /* Remove from vis_bin */
555 gst_bin_remove (vis_bin, play_bin->visualisation);
556 /* Set state to NULL */
557 gst_element_set_state (play_bin->visualisation, GST_STATE_NULL);
558 /* And loose our ref */
559 gst_object_unref (play_bin->visualisation);
561 if (pending_visualisation) {
562 /* Ref this new visualisation element before adding to the bin */
563 gst_object_ref (pending_visualisation);
564 /* Add the new one */
565 gst_bin_add (vis_bin, pending_visualisation);
566 /* Synchronizing state */
567 gst_element_set_state (pending_visualisation, bin_state);
569 vis_sink_pad = gst_element_get_static_pad (pending_visualisation, "sink");
570 vis_src_pad = gst_element_get_static_pad (pending_visualisation, "src");
572 if (!GST_IS_PAD (vis_sink_pad) || !GST_IS_PAD (vis_src_pad)) {
577 gst_pad_link (tee_pad, vis_sink_pad);
578 gst_pad_link (vis_src_pad, vqueue_pad);
582 gst_object_unref (play_bin->visualisation);
583 play_bin->visualisation = pending_visualisation;
587 gst_object_unref (vis_sink_pad);
590 gst_object_unref (vis_src_pad);
593 gst_object_unref (vqueue_pad);
596 gst_object_unref (vis_bin);
599 /* Unblock the pad */
600 gst_pad_set_blocked_async (tee_pad, FALSE, gst_play_bin_vis_unblocked,
605 gst_play_bin_set_property (GObject * object, guint prop_id,
606 const GValue * value, GParamSpec * pspec)
608 GstPlayBin *play_bin;
610 play_bin = GST_PLAY_BIN (object);
614 if (play_bin->video_sink != NULL) {
615 gst_object_unref (play_bin->video_sink);
617 play_bin->video_sink = g_value_get_object (value);
618 if (play_bin->video_sink != NULL) {
619 gst_object_ref (play_bin->video_sink);
620 gst_object_sink (GST_OBJECT_CAST (play_bin->video_sink));
622 /* when changing the videosink, we just remove the
623 * video pipeline from the cache so that it will be
624 * regenerated with the new sink element */
625 g_hash_table_remove (play_bin->cache, "vbin");
628 if (play_bin->audio_sink != NULL) {
629 gst_object_unref (play_bin->audio_sink);
631 play_bin->audio_sink = g_value_get_object (value);
632 if (play_bin->audio_sink != NULL) {
633 gst_object_ref (play_bin->audio_sink);
634 gst_object_sink (GST_OBJECT_CAST (play_bin->audio_sink));
636 g_hash_table_remove (play_bin->cache, "abin");
640 GstElement *pending_visualisation =
641 GST_ELEMENT_CAST (g_value_get_object (value));
644 if (pending_visualisation) {
645 gst_object_ref (pending_visualisation);
646 gst_object_sink (pending_visualisation);
649 /* Do we already have a visualisation change pending ? */
650 GST_OBJECT_LOCK (play_bin);
651 if (play_bin->pending_visualisation) {
652 gst_object_unref (play_bin->pending_visualisation);
653 play_bin->pending_visualisation = pending_visualisation;
654 GST_OBJECT_UNLOCK (play_bin);
656 GST_OBJECT_UNLOCK (play_bin);
657 /* Was there a visualisation already set ? */
658 if (play_bin->visualisation != NULL) {
659 GstBin *vis_bin = NULL;
662 GST_BIN_CAST (gst_object_get_parent (GST_OBJECT_CAST (play_bin->
665 /* Check if the visualisation is already in a bin */
666 if (GST_IS_BIN (vis_bin)) {
667 GstPad *vis_sink_pad = NULL, *tee_pad = NULL;
669 /* Now get tee pad and block it async */
670 vis_sink_pad = gst_element_get_static_pad (play_bin->visualisation,
672 if (!GST_IS_PAD (vis_sink_pad)) {
675 tee_pad = gst_pad_get_peer (vis_sink_pad);
676 if (!GST_IS_PAD (tee_pad)) {
680 play_bin->pending_visualisation = pending_visualisation;
681 /* Block with callback */
682 gst_pad_set_blocked_async (tee_pad, TRUE, gst_play_bin_vis_blocked,
686 gst_object_unref (vis_sink_pad);
689 gst_object_unref (tee_pad);
691 gst_object_unref (vis_bin);
693 play_bin->visualisation = pending_visualisation;
696 play_bin->visualisation = pending_visualisation;
702 play_bin->volume = g_value_get_double (value);
703 if (play_bin->volume_element) {
704 g_object_set (G_OBJECT (play_bin->volume_element), "volume",
705 play_bin->volume, NULL);
709 g_free (play_bin->font_desc);
710 play_bin->font_desc = g_strdup (g_value_get_string (value));
711 if (play_bin->textoverlay_element) {
712 g_object_set (G_OBJECT (play_bin->textoverlay_element),
713 "font-desc", g_value_get_string (value), NULL);
717 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
723 gst_play_bin_get_property (GObject * object, guint prop_id, GValue * value,
726 GstPlayBin *play_bin;
728 play_bin = GST_PLAY_BIN (object);
732 g_value_set_object (value, play_bin->video_sink);
735 g_value_set_object (value, play_bin->audio_sink);
738 g_value_set_object (value, play_bin->visualisation);
741 g_value_set_double (value, play_bin->volume);
744 GstBuffer *cur_frame = NULL;
746 gst_buffer_replace (&cur_frame, play_bin->frame);
747 gst_value_take_buffer (value, cur_frame);
751 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
756 /* signal fired when the identity has received a new buffer. This is used for
757 * making screenshots.
760 handoff (GstElement * identity, GstBuffer * frame, gpointer data)
762 GstPlayBin *play_bin = GST_PLAY_BIN (data);
764 /* applications need to know the buffer caps,
765 * make sure they are always set on the frame */
766 if (GST_BUFFER_CAPS (frame) == NULL) {
769 if ((pad = gst_element_get_static_pad (identity, "sink"))) {
770 gst_buffer_set_caps (frame, GST_PAD_CAPS (pad));
771 gst_object_unref (pad);
775 gst_buffer_replace (&play_bin->frame, frame);
779 post_missing_element_message (GstPlayBin * playbin, const gchar * name)
783 msg = gst_missing_element_message_new (GST_ELEMENT_CAST (playbin), name);
784 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
787 /* make the element (bin) that contains the elements needed to perform
788 * video display. We connect a handoff signal to identity so that we
789 * can grab snapshots. Identity's sinkpad is ghosted to vbin.
791 * +-------------------------------------------------------------+
793 * | +--------+ +----------+ +----------+ +---------+ |
794 * | |identity| |colorspace| |videoscale| |videosink| |
795 * | +-sink src-sink src-sink src-sink | |
796 * | | +---+----+ +----------+ +----------+ +---------+ |
798 * +----------|--------------------------------------------------+
802 gen_video_element (GstPlayBin * play_bin)
809 GstElement *identity;
812 /* first see if we have it in the cache */
813 element = g_hash_table_lookup (play_bin->cache, "vbin");
814 if (element != NULL) {
818 if (play_bin->video_sink) {
819 sink = play_bin->video_sink;
821 sink = gst_element_factory_make ("autovideosink", "videosink");
823 sink = gst_element_factory_make ("xvimagesink", "videosink");
828 gst_object_ref (sink);
829 g_hash_table_insert (play_bin->cache, "video_sink", sink);
831 /* create a bin to hold objects, as we create them we add them to this bin so
832 * that when something goes wrong we only need to unref the bin */
833 element = gst_bin_new ("vbin");
834 gst_bin_add (GST_BIN_CAST (element), sink);
836 conv = gst_element_factory_make ("ffmpegcolorspace", "vconv");
839 gst_bin_add (GST_BIN_CAST (element), conv);
841 scale = gst_element_factory_make ("videoscale", "vscale");
844 gst_bin_add (GST_BIN_CAST (element), scale);
846 identity = gst_element_factory_make ("identity", "id");
847 g_object_set (identity, "silent", TRUE, NULL);
848 g_signal_connect (identity, "handoff", G_CALLBACK (handoff), play_bin);
849 gst_bin_add (GST_BIN_CAST (element), identity);
851 gst_element_link_pads (identity, "src", conv, "sink");
852 gst_element_link_pads (conv, "src", scale, "sink");
853 /* be more careful with the pad from the custom sink element, it might not
855 if (!gst_element_link_pads (scale, "src", sink, NULL))
858 pad = gst_element_get_static_pad (identity, "sink");
859 gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
860 gst_object_unref (pad);
862 gst_element_set_state (element, GST_STATE_READY);
864 /* since we're gonna add it to a bin but don't want to lose it,
865 * we keep a reference. */
866 gst_object_ref (element);
867 g_hash_table_insert (play_bin->cache, "vbin", element);
874 post_missing_element_message (play_bin, "autovideosink");
875 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
876 (_("Both autovideosink and xvimagesink elements are missing.")),
882 post_missing_element_message (play_bin, "ffmpegcolorspace");
883 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
884 (_("Missing element '%s' - check your GStreamer installation."),
885 "ffmpegcolorspace"), (NULL));
886 gst_object_unref (element);
892 post_missing_element_message (play_bin, "videoscale");
893 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
894 (_("Missing element '%s' - check your GStreamer installation."),
895 "videoscale"), ("possibly a liboil version mismatch?"));
896 gst_object_unref (element);
901 GST_ELEMENT_ERROR (play_bin, CORE, PAD,
902 (NULL), ("Failed to configure the video sink."));
903 gst_object_unref (element);
908 /* make an element for playback of video with subtitles embedded.
910 * +--------------------------------------------------+
911 * | tbin +-------------+ |
912 * | +-----+ | textoverlay | +------+ |
913 * | | csp | +--video_sink | | vbin | |
914 * video_sink-sink src+ +-text_sink src-sink | |
915 * | +-----+ | +-------------+ +------+ |
916 * text_sink-------------+ |
917 * +--------------------------------------------------+
919 * If there is no subtitle renderer this function will simply return the
920 * videosink without the text_sink pad.
923 gen_text_element (GstPlayBin * play_bin)
925 GstElement *element, *csp, *overlay, *vbin;
928 /* Create the video rendering bin, error is posted when this fails. */
929 vbin = gen_video_element (play_bin);
934 overlay = gst_element_factory_make ("textoverlay", "overlay");
936 /* If no overlay return the video bin without subtitle support. */
941 element = gst_bin_new ("textbin");
943 /* Set some parameters */
944 g_object_set (G_OBJECT (overlay),
945 "halign", "center", "valign", "bottom", NULL);
946 if (play_bin->font_desc) {
947 g_object_set (G_OBJECT (overlay), "font-desc", play_bin->font_desc, NULL);
951 play_bin->textoverlay_element = GST_ELEMENT_CAST (gst_object_ref (overlay));
953 /* we know this will succeed, as the video bin already created one before */
954 csp = gst_element_factory_make ("ffmpegcolorspace", "subtitlecsp");
956 /* Add our elements */
957 gst_bin_add_many (GST_BIN_CAST (element), csp, overlay, vbin, NULL);
960 gst_element_link_pads (csp, "src", overlay, "video_sink");
961 gst_element_link_pads (overlay, "src", vbin, "sink");
963 /* Add ghost pads on the subtitle bin */
964 pad = gst_element_get_static_pad (overlay, "text_sink");
965 gst_element_add_pad (element, gst_ghost_pad_new ("text_sink", pad));
966 gst_object_unref (pad);
968 pad = gst_element_get_static_pad (csp, "sink");
969 gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
970 gst_object_unref (pad);
972 /* Set state to READY */
973 gst_element_set_state (element, GST_STATE_READY);
980 post_missing_element_message (play_bin, "textoverlay");
981 GST_WARNING_OBJECT (play_bin,
982 "No overlay (pango) element, subtitles disabled");
987 /* make the element (bin) that contains the elements needed to perform
990 * +-------------------------------------------------------------+
992 * | +---------+ +----------+ +---------+ +---------+ |
993 * | |audioconv| |audioscale| | volume | |audiosink| |
994 * | +-sink src-sink src-sink src-sink | |
995 * | | +---------+ +----------+ +---------+ +---------+ |
997 * +-------------------------------------------------------------+
1000 gen_audio_element (GstPlayBin * play_bin)
1003 GstElement *element;
1010 element = g_hash_table_lookup (play_bin->cache, "abin");
1011 if (element != NULL)
1014 if (play_bin->audio_sink) {
1015 sink = play_bin->audio_sink;
1017 sink = gst_element_factory_make ("autoaudiosink", "audiosink");
1019 sink = gst_element_factory_make ("alsasink", "audiosink");
1024 play_bin->audio_sink = GST_ELEMENT_CAST (gst_object_ref (sink));
1027 gst_object_ref (sink);
1028 g_hash_table_insert (play_bin->cache, "audio_sink", sink);
1030 element = gst_bin_new ("abin");
1031 gst_bin_add (GST_BIN_CAST (element), sink);
1033 conv = gst_element_factory_make ("audioconvert", "aconv");
1035 goto no_audioconvert;
1036 gst_bin_add (GST_BIN_CAST (element), conv);
1038 scale = gst_element_factory_make ("audioresample", "aresample");
1040 goto no_audioresample;
1041 gst_bin_add (GST_BIN_CAST (element), scale);
1043 volume = gst_element_factory_make ("volume", "volume");
1046 g_object_set (G_OBJECT (volume), "volume", play_bin->volume, NULL);
1047 play_bin->volume_element = volume;
1048 gst_bin_add (GST_BIN_CAST (element), volume);
1050 res = gst_element_link_pads (conv, "src", scale, "sink");
1051 res &= gst_element_link_pads (scale, "src", volume, "sink");
1052 res &= gst_element_link_pads (volume, "src", sink, NULL);
1056 pad = gst_element_get_static_pad (conv, "sink");
1057 gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
1058 gst_object_unref (pad);
1060 gst_element_set_state (element, GST_STATE_READY);
1062 /* since we're gonna add it to a bin but don't want to lose it,
1063 * we keep a reference. */
1064 gst_object_ref (element);
1065 g_hash_table_insert (play_bin->cache, "abin", element);
1072 post_missing_element_message (play_bin, "autoaudiosink");
1073 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1074 (_("Both autoaudiosink and alsasink elements are missing.")), (NULL));
1079 post_missing_element_message (play_bin, "audioconvert");
1080 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1081 (_("Missing element '%s' - check your GStreamer installation."),
1082 "audioconvert"), ("possibly a liboil version mismatch?"));
1083 gst_object_unref (element);
1088 post_missing_element_message (play_bin, "audioresample");
1089 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1090 (_("Missing element '%s' - check your GStreamer installation."),
1091 "audioresample"), ("possibly a liboil version mismatch?"));
1092 gst_object_unref (element);
1097 post_missing_element_message (play_bin, "volume");
1098 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1099 (_("Missing element '%s' - check your GStreamer installation."),
1100 "volume"), ("possibly a liboil version mismatch?"));
1101 gst_object_unref (element);
1106 GST_ELEMENT_ERROR (play_bin, CORE, PAD,
1107 (NULL), ("Failed to configure the audio sink."));
1108 gst_object_unref (element);
1113 /* make the element (bin) that contains the elements needed to perform
1114 * visualisation ouput. The idea is to split the audio using tee, then
1115 * sending the output to the regular audio bin and the other output to
1116 * the vis plugin that transforms it into a video that is rendered with the
1117 * normal video bin. The video and audio bins are run in threads to make sure
1118 * they don't block eachother.
1120 * +-----------------------------------------------------------------------+
1122 * | +------+ +--------+ +----------------+ |
1123 * | | tee | | aqueue | | abin ... | |
1124 * | +-sink src-sink src-sink | |
1125 * | | | | +--------+ +----------------+ |
1127 * | | | | +------+ +------------+ +------+ +-----------+ |
1128 * | | | | |vqueue| | audioconv | | vis | | vbin ... | |
1129 * | | | src-sink src-sink + samp src-sink src-sink | |
1130 * | | | | +------+ +------------+ +------+ +-----------+ |
1134 * +-----------------------------------------------------------------------+
1137 gen_vis_element (GstPlayBin * play_bin)
1140 GstElement *element;
1148 GstElement *vqueue, *aqueue;
1151 /* errors are already posted when these fail. */
1152 asink = gen_audio_element (play_bin);
1155 vsink = gen_video_element (play_bin);
1157 gst_object_unref (asink);
1161 element = gst_bin_new ("visbin");
1162 tee = gst_element_factory_make ("tee", "tee");
1164 vqueue = gst_element_factory_make ("queue", "vqueue");
1165 aqueue = gst_element_factory_make ("queue", "aqueue");
1167 gst_bin_add (GST_BIN_CAST (element), asink);
1168 gst_bin_add (GST_BIN_CAST (element), vqueue);
1169 gst_bin_add (GST_BIN_CAST (element), aqueue);
1170 gst_bin_add (GST_BIN_CAST (element), vsink);
1171 gst_bin_add (GST_BIN_CAST (element), tee);
1173 conv = gst_element_factory_make ("audioconvert", "aconv");
1175 goto no_audioconvert;
1176 gst_bin_add (GST_BIN_CAST (element), conv);
1178 resamp = gst_element_factory_make ("audioresample", "aresamp");
1180 goto no_audioresample;
1181 gst_bin_add (GST_BIN_CAST (element), resamp);
1183 conv2 = gst_element_factory_make ("audioconvert", "aconv2");
1185 goto no_audioconvert;
1186 gst_bin_add (GST_BIN_CAST (element), conv2);
1188 if (play_bin->visualisation) {
1189 gst_object_ref (play_bin->visualisation);
1190 vis = play_bin->visualisation;
1192 vis = gst_element_factory_make ("goom", "vis");
1196 gst_bin_add (GST_BIN_CAST (element), vis);
1198 res = gst_element_link_pads (vqueue, "src", conv, "sink");
1199 res &= gst_element_link_pads (conv, "src", resamp, "sink");
1200 res &= gst_element_link_pads (resamp, "src", conv2, "sink");
1201 res &= gst_element_link_pads (conv2, "src", vis, "sink");
1202 res &= gst_element_link_pads (vis, "src", vsink, "sink");
1206 pad = gst_element_get_static_pad (aqueue, "sink");
1207 rpad = gst_element_get_request_pad (tee, "src%d");
1208 gst_pad_link (rpad, pad);
1209 gst_object_unref (rpad);
1210 gst_object_unref (pad);
1211 gst_element_link_pads (aqueue, "src", asink, "sink");
1213 pad = gst_element_get_static_pad (vqueue, "sink");
1214 rpad = gst_element_get_request_pad (tee, "src%d");
1215 gst_pad_link (rpad, pad);
1216 gst_object_unref (rpad);
1217 gst_object_unref (pad);
1219 pad = gst_element_get_static_pad (tee, "sink");
1220 gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
1221 gst_object_unref (pad);
1228 post_missing_element_message (play_bin, "audioconvert");
1229 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1230 (_("Missing element '%s' - check your GStreamer installation."),
1231 "audioconvert"), ("possibly a liboil version mismatch?"));
1232 gst_object_unref (element);
1237 post_missing_element_message (play_bin, "audioresample");
1238 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1239 (_("Missing element '%s' - check your GStreamer installation."),
1240 "audioresample"), (NULL));
1241 gst_object_unref (element);
1246 post_missing_element_message (play_bin, "goom");
1247 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1248 (_("Missing element '%s' - check your GStreamer installation."),
1250 gst_object_unref (element);
1255 GST_ELEMENT_ERROR (play_bin, CORE, PAD,
1256 (NULL), ("Failed to configure the visualisation element."));
1257 gst_object_unref (element);
1262 /* get rid of all installed sinks */
1264 remove_sinks (GstPlayBin * play_bin)
1268 GstElement *element;
1271 if (play_bin->cache == NULL)
1274 GST_DEBUG ("removesinks");
1275 element = g_hash_table_lookup (play_bin->cache, "abin");
1276 if (element != NULL) {
1277 parent = gst_element_get_parent (element);
1278 if (parent != NULL) {
1279 /* we remove the element from the parent so that
1280 * there is no unwanted state change when the parent
1282 play_bin->sinks = g_list_remove (play_bin->sinks, element);
1283 gst_element_set_state (element, GST_STATE_NULL);
1284 gst_bin_remove (GST_BIN_CAST (parent), element);
1285 gst_object_unref (parent);
1287 pad = gst_element_get_static_pad (element, "sink");
1289 peer = gst_pad_get_peer (pad);
1291 gst_pad_unlink (peer, pad);
1292 gst_object_unref (peer);
1294 gst_object_unref (pad);
1297 element = g_hash_table_lookup (play_bin->cache, "vbin");
1298 if (element != NULL) {
1299 parent = gst_element_get_parent (element);
1300 if (parent != NULL) {
1301 play_bin->sinks = g_list_remove (play_bin->sinks, element);
1302 gst_element_set_state (element, GST_STATE_NULL);
1303 gst_bin_remove (GST_BIN_CAST (parent), element);
1304 gst_object_unref (parent);
1306 pad = gst_element_get_static_pad (element, "sink");
1308 peer = gst_pad_get_peer (pad);
1310 gst_pad_unlink (peer, pad);
1311 gst_object_unref (peer);
1313 gst_object_unref (pad);
1317 for (sinks = play_bin->sinks; sinks; sinks = g_list_next (sinks)) {
1318 GstElement *element = GST_ELEMENT_CAST (sinks->data);
1322 pad = gst_element_get_static_pad (element, "sink");
1324 GST_LOG ("removing sink %p", element);
1326 peer = gst_pad_get_peer (pad);
1328 gst_pad_unlink (peer, pad);
1329 gst_object_unref (peer);
1331 gst_object_unref (pad);
1333 gst_element_set_state (element, GST_STATE_NULL);
1334 gst_bin_remove (GST_BIN_CAST (play_bin), element);
1336 g_list_free (play_bin->sinks);
1337 play_bin->sinks = NULL;
1339 if (play_bin->visualisation) {
1340 GstElement *vis_bin;
1343 GST_ELEMENT_CAST (gst_element_get_parent (play_bin->visualisation));
1345 gst_element_set_state (play_bin->visualisation, GST_STATE_NULL);
1348 gst_bin_remove (GST_BIN_CAST (vis_bin), play_bin->visualisation);
1349 gst_object_unref (vis_bin);
1353 if (play_bin->frame) {
1354 gst_buffer_unref (play_bin->frame);
1355 play_bin->frame = NULL;
1358 if (play_bin->textoverlay_element) {
1359 gst_object_unref (play_bin->textoverlay_element);
1360 play_bin->textoverlay_element = NULL;
1364 /* loop over the streams and set up the pipeline to play this
1365 * media file. First we count the number of audio and video streams.
1366 * If there is no video stream but there exists an audio stream,
1367 * we install a visualisation pipeline.
1369 * Also make sure to only connect the first audio and video pad. FIXME
1370 * this should eventually be handled with a tuner interface so that
1371 * one can switch the streams.
1373 * This function takes ownership of @sink.*
1376 add_sink (GstPlayBin * play_bin, GstElement * sink, GstPad * srcpad,
1377 GstPad * subtitle_pad)
1380 GstPadLinkReturn linkres;
1382 GstStateChangeReturn stateret;
1385 g_return_val_if_fail (sink != NULL, FALSE);
1387 state = GST_STATE_PAUSED;
1389 /* this is only for debugging */
1390 parent = gst_pad_get_parent_element (srcpad);
1392 GST_DEBUG ("Adding sink %" GST_PTR_FORMAT
1393 " with state %d (parent: %d, peer: %d)", sink,
1394 GST_STATE (sink), GST_STATE (play_bin), GST_STATE (parent));
1395 gst_object_unref (parent);
1397 gst_bin_add (GST_BIN_CAST (play_bin), sink);
1399 /* bring it to the required state so we can link to the peer without
1400 * breaking the flow */
1401 stateret = gst_element_set_state (sink, state);
1402 if (stateret == GST_STATE_CHANGE_FAILURE)
1405 /* we found a sink for this stream, now try to install it */
1406 sinkpad = gst_element_get_static_pad (sink, "sink");
1407 linkres = gst_pad_link (srcpad, sinkpad);
1408 gst_object_unref (sinkpad);
1410 /* try to link the pad of the sink to the stream */
1411 if (GST_PAD_LINK_FAILED (linkres))
1414 if (GST_IS_PAD (subtitle_pad)) {
1415 sinkpad = gst_element_get_static_pad (sink, "text_sink");
1416 linkres = gst_pad_link (subtitle_pad, sinkpad);
1417 gst_object_unref (sinkpad);
1420 /* try to link the subtitle pad of the sink to the stream, this is not
1422 if (GST_PAD_LINK_FAILED (linkres))
1423 goto subtitle_failed;
1426 /* we got the sink succesfully linked, now keep the sink
1427 * in our internal list */
1428 play_bin->sinks = g_list_prepend (play_bin->sinks, sink);
1435 gst_element_set_state (sink, GST_STATE_NULL);
1436 gst_bin_remove (GST_BIN_CAST (play_bin), sink);
1437 GST_DEBUG_OBJECT (play_bin, "state change failure when adding sink");
1445 /* could not link this stream */
1446 caps = gst_pad_get_caps (srcpad);
1447 capsstr = gst_caps_to_string (caps);
1448 g_warning ("could not link %s: %d", capsstr, linkres);
1449 GST_DEBUG_OBJECT (play_bin,
1450 "link failed when adding sink, caps %s, reason %d", capsstr, linkres);
1452 gst_caps_unref (caps);
1454 gst_element_set_state (sink, GST_STATE_NULL);
1455 gst_bin_remove (GST_BIN_CAST (play_bin), sink);
1462 /* could not link this stream */
1463 caps = gst_pad_get_caps (subtitle_pad);
1464 GST_WARNING_OBJECT (play_bin, "subtitle link failed when adding sink, "
1465 "caps = %" GST_PTR_FORMAT ", reason %d", caps, linkres);
1466 gst_caps_unref (caps);
1474 dummy_blocked_cb (GstPad * pad, gboolean blocked, gpointer user_data)
1479 setup_sinks (GstPlayBaseBin * play_base_bin, GstPlayBaseGroup * group)
1481 GstPlayBin *play_bin = GST_PLAY_BIN (play_base_bin);
1482 gboolean need_vis = FALSE;
1483 gboolean need_text = FALSE;
1484 GstPad *textsrcpad = NULL, *pad = NULL, *origtextsrcpad = NULL;
1486 gboolean res = TRUE;
1488 /* get rid of existing sinks */
1489 if (play_bin->sinks) {
1490 remove_sinks (play_bin);
1492 GST_DEBUG_OBJECT (play_base_bin, "setupsinks");
1494 /* find out what to do */
1495 if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads > 0 &&
1496 group->type[GST_STREAM_TYPE_TEXT - 1].npads > 0) {
1498 } else if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads == 0 &&
1499 group->type[GST_STREAM_TYPE_AUDIO - 1].npads > 0 &&
1500 play_bin->visualisation != NULL) {
1504 /* now actually connect everything */
1507 if (group->type[GST_STREAM_TYPE_AUDIO - 1].npads > 0) {
1509 sink = gen_vis_element (play_bin);
1511 sink = gen_audio_element (play_bin);
1517 gst_element_get_static_pad (group->type[GST_STREAM_TYPE_AUDIO -
1519 res = add_sink (play_bin, sink, pad, NULL);
1520 gst_object_unref (pad);
1524 if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads > 0) {
1526 GstObject *parent = NULL, *grandparent = NULL;
1527 GstPad *ghost = NULL;
1529 sink = gen_text_element (play_bin);
1531 gst_element_get_static_pad (group->type[GST_STREAM_TYPE_TEXT -
1534 /* This pad is from subtitle-bin, we need to create a ghost pad to have
1535 common grandparents */
1536 parent = gst_object_get_parent (GST_OBJECT_CAST (textsrcpad));
1538 GST_WARNING_OBJECT (textsrcpad, "subtitle pad has no parent !");
1539 gst_object_unref (textsrcpad);
1544 grandparent = gst_object_get_parent (parent);
1546 GST_WARNING_OBJECT (textsrcpad, "subtitle pad has no grandparent !");
1547 gst_object_unref (parent);
1548 gst_object_unref (textsrcpad);
1553 /* We ghost the pad on subtitle_bin only, if the text pad is from the
1554 media demuxer we keep it as it is */
1555 if (!GST_IS_PLAY_BIN (grandparent)) {
1556 GST_DEBUG_OBJECT (textsrcpad, "this subtitle pad is from a subtitle "
1557 "file, ghosting to a suitable hierarchy");
1558 /* Block the pad first, because as soon as we add a ghostpad, the queue
1559 * will try and start pushing */
1560 gst_pad_set_blocked_async (textsrcpad, TRUE, dummy_blocked_cb, NULL);
1561 origtextsrcpad = gst_object_ref (textsrcpad);
1563 ghost = gst_ghost_pad_new ("text_src", textsrcpad);
1564 if (!GST_IS_PAD (ghost)) {
1565 GST_WARNING_OBJECT (textsrcpad, "failed creating ghost pad for "
1567 gst_object_unref (parent);
1568 gst_object_unref (grandparent);
1569 gst_object_unref (textsrcpad);
1574 gst_pad_set_active (ghost, TRUE);
1575 if (gst_element_add_pad (GST_ELEMENT_CAST (grandparent), ghost)) {
1576 gst_object_unref (textsrcpad);
1577 textsrcpad = gst_object_ref (ghost);
1579 GST_WARNING_OBJECT (ghost, "failed adding ghost pad on subtitle-bin");
1580 gst_pad_set_active (ghost, FALSE);
1581 gst_object_unref (ghost);
1582 gst_object_unref (textsrcpad);
1586 GST_DEBUG_OBJECT (textsrcpad, "this subtitle pad is from the demuxer "
1587 "no changes to hierarchy needed");
1590 gst_object_unref (parent);
1591 gst_object_unref (grandparent);
1593 sink = gen_video_element (play_bin);
1599 gst_element_get_static_pad (group->type[GST_STREAM_TYPE_VIDEO -
1601 res = add_sink (play_bin, sink, pad, textsrcpad);
1602 gst_object_unref (pad);
1604 gst_object_unref (textsrcpad);
1605 if (origtextsrcpad) {
1606 gst_pad_set_blocked_async (origtextsrcpad, FALSE, dummy_blocked_cb, NULL);
1607 gst_object_unref (origtextsrcpad);
1611 /* remove the sinks now, pipeline get_state will now wait for the
1612 * sinks to preroll */
1613 if (play_bin->fakesink) {
1614 gst_element_set_state (play_bin->fakesink, GST_STATE_NULL);
1615 gst_bin_remove (GST_BIN_CAST (play_bin), play_bin->fakesink);
1616 play_bin->fakesink = NULL;
1623 playbin_set_subtitles_visible (GstPlayBaseBin * play_base_bin, gboolean visible)
1625 GstPlayBin *playbin = GST_PLAY_BIN (play_base_bin);
1627 /* we're ignoring the case of someone setting the 'current-text' property
1628 * before textoverlay is set up (which is probably okay, since playbasebin
1629 * will just select the first subtitle stream as active stream regardless) */
1630 if (playbin->textoverlay_element != NULL) {
1631 GST_LOG_OBJECT (playbin, "setting subtitle visibility to %d", visible);
1632 g_object_set (playbin->textoverlay_element, "silent", !visible, NULL);
1637 playbin_set_audio_mute (GstPlayBaseBin * play_base_bin, gboolean mute)
1639 GstPlayBin *playbin = GST_PLAY_BIN (play_base_bin);
1641 if (playbin->volume_element) {
1642 g_object_set (G_OBJECT (playbin->volume_element), "mute", mute, NULL);
1646 /* Send an event to our sinks until one of them works; don't then send to the
1647 * remaining sinks (unlike GstBin)
1650 gst_play_bin_send_event_to_sink (GstPlayBin * play_bin, GstEvent * event)
1652 GList *sinks = play_bin->sinks;
1653 gboolean res = TRUE;
1656 GstElement *sink = GST_ELEMENT_CAST (sinks->data);
1658 gst_event_ref (event);
1659 if ((res = gst_element_send_event (sink, event))) {
1660 GST_DEBUG_OBJECT (play_bin,
1661 "Sent event succesfully to sink %" GST_PTR_FORMAT, sink);
1664 GST_DEBUG_OBJECT (play_bin,
1665 "Event failed when sent to sink %" GST_PTR_FORMAT, sink);
1667 sinks = g_list_next (sinks);
1670 gst_event_unref (event);
1675 /* We only want to send the event to a single sink (overriding GstBin's
1676 * behaviour), but we want to keep GstPipeline's behaviour - wrapping seek
1677 * events appropriately. So, this is a messy duplication of code. */
1679 gst_play_bin_send_event (GstElement * element, GstEvent * event)
1681 gboolean res = FALSE;
1682 GstEventType event_type = GST_EVENT_TYPE (event);
1684 switch (event_type) {
1685 case GST_EVENT_SEEK:
1686 GST_DEBUG_OBJECT (element, "Sending seek event to a sink");
1687 res = gst_play_bin_send_event_to_sink (GST_PLAY_BIN (element), event);
1690 res = parent_class->send_event (element, event);
1698 value_list_append_structure_list (GValue * list_val, GstStructure ** first,
1699 GList * structure_list)
1703 for (l = structure_list; l != NULL; l = l->next) {
1704 GValue val = { 0, };
1707 *first = gst_structure_copy ((GstStructure *) l->data);
1709 g_value_init (&val, GST_TYPE_STRUCTURE);
1710 g_value_take_boxed (&val, gst_structure_copy ((GstStructure *) l->data));
1711 gst_value_list_append_value (list_val, &val);
1712 g_value_unset (&val);
1716 /* if it's a redirect message with multiple redirect locations we might
1717 * want to pick a different 'best' location depending on the required
1718 * bitrates and the connection speed */
1720 gst_play_bin_handle_redirect_message (GstPlayBin * playbin, GstMessage * msg)
1722 const GValue *locations_list, *location_val;
1723 GstMessage *new_msg;
1724 GstStructure *new_structure = NULL;
1725 GList *l_good = NULL, *l_neutral = NULL, *l_bad = NULL;
1726 GValue new_list = { 0, };
1728 GstPlayBaseBin *playbasebin = GST_PLAY_BASE_BIN (playbin);
1729 guint connection_speed = playbasebin->connection_speed;
1731 GST_DEBUG_OBJECT (playbin, "redirect message: %" GST_PTR_FORMAT, msg);
1732 GST_DEBUG_OBJECT (playbin, "connection speed: %u", connection_speed);
1734 if (connection_speed == 0 || msg->structure == NULL)
1737 locations_list = gst_structure_get_value (msg->structure, "locations");
1738 if (locations_list == NULL)
1741 size = gst_value_list_get_size (locations_list);
1745 /* maintain existing order as much as possible, just sort references
1746 * with too high a bitrate to the end (the assumption being that if
1747 * bitrates are given they are given for all interesting streams and
1748 * that the you-need-at-least-version-xyz redirect has the same bitrate
1749 * as the lowest referenced redirect alternative) */
1750 for (i = 0; i < size; ++i) {
1751 const GstStructure *s;
1754 location_val = gst_value_list_get_value (locations_list, i);
1755 s = (const GstStructure *) g_value_get_boxed (location_val);
1756 if (!gst_structure_get_int (s, "minimum-bitrate", &bitrate) || bitrate <= 0) {
1757 GST_DEBUG_OBJECT (playbin, "no bitrate: %" GST_PTR_FORMAT, s);
1758 l_neutral = g_list_append (l_neutral, (gpointer) s);
1759 } else if (bitrate > connection_speed) {
1760 GST_DEBUG_OBJECT (playbin, "bitrate too high: %" GST_PTR_FORMAT, s);
1761 l_bad = g_list_append (l_bad, (gpointer) s);
1762 } else if (bitrate <= connection_speed) {
1763 GST_DEBUG_OBJECT (playbin, "bitrate OK: %" GST_PTR_FORMAT, s);
1764 l_good = g_list_append (l_good, (gpointer) s);
1768 g_value_init (&new_list, GST_TYPE_LIST);
1769 value_list_append_structure_list (&new_list, &new_structure, l_good);
1770 value_list_append_structure_list (&new_list, &new_structure, l_neutral);
1771 value_list_append_structure_list (&new_list, &new_structure, l_bad);
1772 gst_structure_set_value (new_structure, "locations", &new_list);
1773 g_value_unset (&new_list);
1775 g_list_free (l_good);
1776 g_list_free (l_neutral);
1777 g_list_free (l_bad);
1779 new_msg = gst_message_new_element (msg->src, new_structure);
1780 gst_message_unref (msg);
1782 GST_DEBUG_OBJECT (playbin, "new redirect message: %" GST_PTR_FORMAT, new_msg);
1787 gst_play_bin_handle_message (GstBin * bin, GstMessage * msg)
1789 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ELEMENT && msg->structure != NULL
1790 && gst_structure_has_name (msg->structure, "redirect")) {
1791 msg = gst_play_bin_handle_redirect_message (GST_PLAY_BIN (bin), msg);
1794 GST_BIN_CLASS (parent_class)->handle_message (bin, msg);
1797 static GstStateChangeReturn
1798 gst_play_bin_change_state (GstElement * element, GstStateChange transition)
1800 GstStateChangeReturn ret;
1801 GstPlayBin *play_bin;
1803 play_bin = GST_PLAY_BIN (element);
1806 switch (transition) {
1807 case GST_STATE_CHANGE_READY_TO_PAUSED:
1808 /* this really is the easiest way to make the state change return
1809 * ASYNC until we added the sinks */
1810 if (!play_bin->fakesink) {
1811 play_bin->fakesink = gst_element_factory_make ("fakesink", "test");
1812 gst_bin_add (GST_BIN_CAST (play_bin), play_bin->fakesink);
1819 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1820 if (ret == GST_STATE_CHANGE_FAILURE)
1823 switch (transition) {
1824 case GST_STATE_CHANGE_READY_TO_PAUSED:
1825 /* remember us being a live pipeline */
1826 play_bin->is_live = (ret == GST_STATE_CHANGE_NO_PREROLL);
1827 GST_DEBUG_OBJECT (play_bin, "is live: %d", play_bin->is_live);
1829 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1830 /* FIXME Release audio device when we implement that */
1832 case GST_STATE_CHANGE_PAUSED_TO_READY:
1833 case GST_STATE_CHANGE_READY_TO_NULL:
1834 /* remove sinks we added */
1835 remove_sinks (play_bin);
1836 /* and there might be a fakesink we need to clean up now */
1837 if (play_bin->fakesink) {
1838 gst_element_set_state (play_bin->fakesink, GST_STATE_NULL);
1839 gst_bin_remove (GST_BIN_CAST (play_bin), play_bin->fakesink);
1840 play_bin->fakesink = NULL;
1851 gst_play_bin_plugin_init (GstPlugin * plugin)
1853 GST_DEBUG_CATEGORY_INIT (gst_play_bin_debug, "playbin", 0, "play bin");
1855 return gst_element_register (plugin, "playbin", GST_RANK_NONE,