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 status</title>
166 * Playbin handles buffering automatically. When playbin is buffering, it
167 * will post BUFFERING messages on the bus with a percentage value that
168 * shows the progress of the buffering. Applications may want to show this
169 * information to the user in some form or another. Here is how to extract
170 * the percentage information from the message:
174 * switch (GST_MESSAGE_TYPE (msg)) {
175 * case GST_MESSAGE_BUFFERING: {
177 * gst_structure_get_int (msg->structure, "buffer-percent", &percent);
178 * g_print ("Buffering (%%u percent done)", percent);
185 * <title>Embedding the video window in your application</title>
187 * By default, playbin (or rather the video sinks used) will create their own
188 * window. Applications will usually want to force output to a window of their
189 * own, however. This can be done using the GstXOverlay interface, which most
190 * video sinks implement. See the documentation there for more details.
192 * <title>Specifying which CD/DVD device to use</title>
194 * The device to use for CDs/DVDs needs to be set on the source element
195 * playbin creates before it is opened. The only way to do this at the moment
196 * is to connect to playbin's "notify::source" signal, which will be emitted
197 * by playbin when it has created the source element for a particular URI.
198 * In the signal callback you can check if the source element has a "device"
199 * property and set it appropriately. In future ways might be added to specify
200 * the device as part of the URI, but at the time of writing this is not
203 * <title>Examples</title>
205 * Here is a simple pipeline to play back a video or audio file:
207 * gst-launch -v playbin uri=file:///path/to/somefile.avi
209 * This will play back the given AVI video file, given that the video and
210 * audio decoders required to decode the content are installed. Since no
211 * special audio sink or video sink is supplied (not possible via gst-launch),
212 * playbin will try to find a suitable audio and video sink automatically
213 * using the autoaudiosink and autovideosink elements.
216 * Here is a another pipeline to play track 4 of an audio CD:
218 * gst-launch -v playbin uri=cdda://4
220 * This will play back track 4 on an audio CD in your disc drive (assuming
221 * the drive is detected automatically by the plugin).
224 * Here is a another pipeline to play title 1 of a DVD:
226 * gst-launch -v playbin uri=dvd://1
228 * This will play back title 1 of a DVD in your disc drive (assuming
229 * the drive is detected automatically by the plugin).
241 #include <gst/gst-i18n-plugin.h>
243 #include "gstplaybasebin.h"
245 GST_DEBUG_CATEGORY_STATIC (gst_play_bin_debug);
246 #define GST_CAT_DEFAULT gst_play_bin_debug
248 #define GST_TYPE_PLAY_BIN (gst_play_bin_get_type())
249 #define GST_PLAY_BIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PLAY_BIN,GstPlayBin))
250 #define GST_PLAY_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PLAY_BIN,GstPlayBinClass))
251 #define GST_IS_PLAY_BIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PLAY_BIN))
252 #define GST_IS_PLAY_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PLAY_BIN))
254 #define VOLUME_MAX_DOUBLE 10.0
255 #define CONNECTION_SPEED_DEFAULT 0
257 typedef struct _GstPlayBin GstPlayBin;
258 typedef struct _GstPlayBinClass GstPlayBinClass;
262 GstPlayBaseBin parent;
264 /* the configurable elements */
265 GstElement *fakesink;
266 GstElement *audio_sink;
267 GstElement *video_sink;
268 GstElement *visualisation;
269 GstElement *pending_visualisation;
270 GstElement *volume_element;
271 GstElement *textoverlay_element;
274 /* these are the currently active sinks */
277 /* the last captured frame for snapshots */
280 /* our cache for the sinks */
283 /* font description */
286 /* connection speed in bits/sec (0 = unknown) */
287 guint connection_speed;
290 struct _GstPlayBinClass
292 GstPlayBaseBinClass parent_class;
314 static void gst_play_bin_class_init (GstPlayBinClass * klass);
315 static void gst_play_bin_init (GstPlayBin * play_bin);
316 static void gst_play_bin_dispose (GObject * object);
318 static gboolean setup_sinks (GstPlayBaseBin * play_base_bin,
319 GstPlayBaseGroup * group);
320 static void remove_sinks (GstPlayBin * play_bin);
322 static void gst_play_bin_set_property (GObject * object, guint prop_id,
323 const GValue * value, GParamSpec * spec);
324 static void gst_play_bin_get_property (GObject * object, guint prop_id,
325 GValue * value, GParamSpec * spec);
327 static gboolean gst_play_bin_send_event (GstElement * element,
329 static GstStateChangeReturn gst_play_bin_change_state (GstElement * element,
330 GstStateChange transition);
331 static void gst_play_bin_handle_message (GstBin * bin, GstMessage * message);
333 static GstElementClass *parent_class;
335 //static guint gst_play_bin_signals[LAST_SIGNAL] = { 0 };
337 static const GstElementDetails gst_play_bin_details =
338 GST_ELEMENT_DETAILS ("Player Bin",
339 "Generic/Bin/Player",
340 "Autoplug and play media from an uri",
341 "Wim Taymans <wim@fluendo.com>");
344 gst_play_bin_get_type (void)
346 static GType gst_play_bin_type = 0;
348 if (!gst_play_bin_type) {
349 static const GTypeInfo gst_play_bin_info = {
350 sizeof (GstPlayBinClass),
353 (GClassInitFunc) gst_play_bin_class_init,
358 (GInstanceInitFunc) gst_play_bin_init,
362 gst_play_bin_type = g_type_register_static (GST_TYPE_PLAY_BASE_BIN,
363 "GstPlayBin", &gst_play_bin_info, 0);
366 return gst_play_bin_type;
370 gst_play_bin_class_init (GstPlayBinClass * klass)
372 GObjectClass *gobject_klass;
373 GstElementClass *gstelement_klass;
374 GstBinClass *gstbin_klass;
375 GstPlayBaseBinClass *playbasebin_klass;
377 gobject_klass = (GObjectClass *) klass;
378 gstelement_klass = (GstElementClass *) klass;
379 gstbin_klass = (GstBinClass *) klass;
380 playbasebin_klass = (GstPlayBaseBinClass *) klass;
382 parent_class = g_type_class_peek_parent (klass);
384 gobject_klass->set_property = gst_play_bin_set_property;
385 gobject_klass->get_property = gst_play_bin_get_property;
387 g_object_class_install_property (gobject_klass, ARG_VIDEO_SINK,
388 g_param_spec_object ("video-sink", "Video Sink",
389 "the video output element to use (NULL = default sink)",
390 GST_TYPE_ELEMENT, G_PARAM_READWRITE));
391 g_object_class_install_property (gobject_klass, ARG_AUDIO_SINK,
392 g_param_spec_object ("audio-sink", "Audio Sink",
393 "the audio output element to use (NULL = default sink)",
394 GST_TYPE_ELEMENT, G_PARAM_READWRITE));
395 g_object_class_install_property (gobject_klass, ARG_VIS_PLUGIN,
396 g_param_spec_object ("vis-plugin", "Vis plugin",
397 "the visualization element to use (NULL = none)",
398 GST_TYPE_ELEMENT, G_PARAM_READWRITE));
399 g_object_class_install_property (gobject_klass, ARG_VOLUME,
400 g_param_spec_double ("volume", "volume", "volume",
401 0.0, VOLUME_MAX_DOUBLE, 1.0, G_PARAM_READWRITE));
402 g_object_class_install_property (gobject_klass, ARG_FRAME,
403 gst_param_spec_mini_object ("frame", "Frame",
404 "The last frame (NULL = no video available)",
405 GST_TYPE_BUFFER, G_PARAM_READABLE));
406 g_object_class_install_property (gobject_klass, ARG_FONT_DESC,
407 g_param_spec_string ("subtitle-font-desc",
408 "Subtitle font description",
409 "Pango font description of font "
410 "to be used for subtitle rendering", NULL, G_PARAM_WRITABLE));
412 * GstPlayBin:connection-speed
414 * Network connection speed in kbps (0 = unknown)
418 g_object_class_install_property (gobject_klass, ARG_CONNECTION_SPEED,
419 g_param_spec_uint ("connection-speed", "Connection Speed",
420 "Network connection speed in kbps (0 = unknown)",
421 0, G_MAXUINT, CONNECTION_SPEED_DEFAULT, G_PARAM_READWRITE));
423 gobject_klass->dispose = GST_DEBUG_FUNCPTR (gst_play_bin_dispose);
425 gst_element_class_set_details (gstelement_klass, &gst_play_bin_details);
427 gstelement_klass->change_state =
428 GST_DEBUG_FUNCPTR (gst_play_bin_change_state);
429 gstelement_klass->send_event = GST_DEBUG_FUNCPTR (gst_play_bin_send_event);
431 gstbin_klass->handle_message =
432 GST_DEBUG_FUNCPTR (gst_play_bin_handle_message);
434 playbasebin_klass->setup_output_pads = setup_sinks;
438 gst_play_bin_init (GstPlayBin * play_bin)
440 play_bin->video_sink = NULL;
441 play_bin->audio_sink = NULL;
442 play_bin->visualisation = NULL;
443 play_bin->pending_visualisation = NULL;
444 play_bin->volume_element = NULL;
445 play_bin->textoverlay_element = NULL;
446 play_bin->volume = 1.0;
447 play_bin->sinks = NULL;
448 play_bin->frame = NULL;
449 play_bin->font_desc = NULL;
450 play_bin->cache = g_hash_table_new_full (g_str_hash, g_str_equal,
451 NULL, (GDestroyNotify) gst_object_unref);
455 gst_play_bin_dispose (GObject * object)
457 GstPlayBin *play_bin;
459 play_bin = GST_PLAY_BIN (object);
461 if (play_bin->cache != NULL) {
462 remove_sinks (play_bin);
463 g_hash_table_destroy (play_bin->cache);
464 play_bin->cache = NULL;
467 if (play_bin->audio_sink != NULL) {
468 gst_element_set_state (play_bin->audio_sink, GST_STATE_NULL);
469 gst_object_unref (play_bin->audio_sink);
470 play_bin->audio_sink = NULL;
472 if (play_bin->video_sink != NULL) {
473 gst_element_set_state (play_bin->video_sink, GST_STATE_NULL);
474 gst_object_unref (play_bin->video_sink);
475 play_bin->video_sink = NULL;
477 if (play_bin->visualisation != NULL) {
478 gst_element_set_state (play_bin->visualisation, GST_STATE_NULL);
479 gst_object_unref (play_bin->visualisation);
480 play_bin->visualisation = NULL;
482 if (play_bin->pending_visualisation != NULL) {
483 gst_element_set_state (play_bin->pending_visualisation, GST_STATE_NULL);
484 gst_object_unref (play_bin->pending_visualisation);
485 play_bin->pending_visualisation = NULL;
487 if (play_bin->textoverlay_element != NULL) {
488 gst_object_unref (play_bin->textoverlay_element);
489 play_bin->textoverlay_element = NULL;
491 g_free (play_bin->font_desc);
492 play_bin->font_desc = NULL;
494 G_OBJECT_CLASS (parent_class)->dispose (object);
498 gst_play_bin_vis_unblocked (GstPad * tee_pad, gboolean blocked,
505 gst_play_bin_vis_blocked (GstPad * tee_pad, gboolean blocked,
508 GstPlayBin *play_bin = GST_PLAY_BIN (user_data);
509 GstBin *vis_bin = NULL;
510 GstPad *vis_sink_pad = NULL, *vis_src_pad = NULL, *vqueue_pad = NULL;
513 /* We want to disable visualisation */
514 if (!GST_IS_ELEMENT (play_bin->pending_visualisation)) {
515 /* Set visualisation element to READY */
516 gst_element_set_state (play_bin->visualisation, GST_STATE_READY);
521 GST_BIN (gst_object_get_parent (GST_OBJECT (play_bin->visualisation)));
523 if (!GST_IS_BIN (vis_bin) || !GST_IS_PAD (tee_pad)) {
527 vis_src_pad = gst_element_get_pad (play_bin->visualisation, "src");
528 vis_sink_pad = gst_pad_get_peer (tee_pad);
530 /* Can be fakesink */
531 if (GST_IS_PAD (vis_src_pad)) {
532 vqueue_pad = gst_pad_get_peer (vis_src_pad);
535 if (!GST_IS_PAD (vis_sink_pad)) {
539 /* Check the bin's state */
540 GST_OBJECT_LOCK (vis_bin);
541 bin_state = GST_STATE (vis_bin);
542 GST_OBJECT_UNLOCK (vis_bin);
545 gst_pad_unlink (tee_pad, vis_sink_pad);
546 gst_object_unref (vis_sink_pad);
549 if (GST_IS_PAD (vqueue_pad)) {
550 gst_pad_unlink (vis_src_pad, vqueue_pad);
551 gst_object_unref (vis_src_pad);
555 /* Remove from vis_bin */
556 gst_bin_remove (vis_bin, play_bin->visualisation);
557 /* Set state to NULL */
558 gst_element_set_state (play_bin->visualisation, GST_STATE_NULL);
559 /* And loose our ref */
560 gst_object_unref (play_bin->visualisation);
562 if (play_bin->pending_visualisation) {
563 /* Ref this new visualisation element before adding to the bin */
564 gst_object_ref (play_bin->pending_visualisation);
565 /* Add the new one */
566 gst_bin_add (vis_bin, play_bin->pending_visualisation);
567 /* Synchronizing state */
568 gst_element_set_state (play_bin->pending_visualisation, bin_state);
570 vis_sink_pad = gst_element_get_pad (play_bin->pending_visualisation,
572 vis_src_pad = gst_element_get_pad (play_bin->pending_visualisation, "src");
574 if (!GST_IS_PAD (vis_sink_pad) || !GST_IS_PAD (vis_src_pad)) {
579 gst_pad_link (tee_pad, vis_sink_pad);
580 gst_pad_link (vis_src_pad, vqueue_pad);
584 gst_object_unref (play_bin->visualisation);
585 play_bin->visualisation = play_bin->pending_visualisation;
586 play_bin->pending_visualisation = NULL;
590 gst_object_unref (vis_sink_pad);
593 gst_object_unref (vis_src_pad);
596 gst_object_unref (vqueue_pad);
599 gst_object_unref (vis_bin);
602 /* Unblock the pad */
603 gst_pad_set_blocked_async (tee_pad, FALSE, gst_play_bin_vis_unblocked,
608 gst_play_bin_set_property (GObject * object, guint prop_id,
609 const GValue * value, GParamSpec * pspec)
611 GstPlayBin *play_bin;
613 play_bin = GST_PLAY_BIN (object);
617 if (play_bin->video_sink != NULL) {
618 gst_object_unref (play_bin->video_sink);
620 play_bin->video_sink = g_value_get_object (value);
621 if (play_bin->video_sink != NULL) {
622 gst_object_ref (play_bin->video_sink);
623 gst_object_sink (GST_OBJECT (play_bin->video_sink));
625 /* when changing the videosink, we just remove the
626 * video pipeline from the cache so that it will be
627 * regenerated with the new sink element */
628 g_hash_table_remove (play_bin->cache, "vbin");
631 if (play_bin->audio_sink != NULL) {
632 gst_object_unref (play_bin->audio_sink);
634 play_bin->audio_sink = g_value_get_object (value);
635 if (play_bin->audio_sink != NULL) {
636 gst_object_ref (play_bin->audio_sink);
637 gst_object_sink (GST_OBJECT (play_bin->audio_sink));
639 g_hash_table_remove (play_bin->cache, "abin");
643 /* Do we already have a visualisation change pending ? */
644 if (play_bin->pending_visualisation) {
645 gst_object_unref (play_bin->pending_visualisation);
646 play_bin->pending_visualisation = g_value_get_object (value);
648 if (play_bin->pending_visualisation) {
649 gst_object_ref (play_bin->pending_visualisation);
650 gst_object_sink (GST_OBJECT (play_bin->pending_visualisation));
653 play_bin->pending_visualisation = g_value_get_object (value);
656 if (play_bin->pending_visualisation) {
657 gst_object_ref (play_bin->pending_visualisation);
658 gst_object_sink (GST_OBJECT (play_bin->pending_visualisation));
661 /* Was there a visualisation already set ? */
662 if (play_bin->visualisation != NULL) {
663 GstBin *vis_bin = NULL;
666 GST_BIN (gst_object_get_parent (GST_OBJECT (play_bin->
669 /* Check if the visualisation is already in a bin */
670 if (GST_IS_BIN (vis_bin)) {
671 GstPad *vis_sink_pad = NULL, *tee_pad = NULL;
673 /* Now get tee pad and block it async */
674 vis_sink_pad = gst_element_get_pad (play_bin->visualisation,
676 if (!GST_IS_PAD (vis_sink_pad)) {
679 tee_pad = gst_pad_get_peer (vis_sink_pad);
680 if (!GST_IS_PAD (tee_pad)) {
684 /* Block with callback */
685 gst_pad_set_blocked_async (tee_pad, TRUE, gst_play_bin_vis_blocked,
689 gst_object_unref (vis_sink_pad);
692 gst_object_unref (tee_pad);
694 gst_object_unref (vis_bin);
696 play_bin->visualisation = play_bin->pending_visualisation;
697 play_bin->pending_visualisation = NULL;
700 play_bin->visualisation = play_bin->pending_visualisation;
701 play_bin->pending_visualisation = NULL;
707 play_bin->volume = g_value_get_double (value);
708 if (play_bin->volume_element) {
709 g_object_set (G_OBJECT (play_bin->volume_element), "volume",
710 play_bin->volume, NULL);
714 g_free (play_bin->font_desc);
715 play_bin->font_desc = g_strdup (g_value_get_string (value));
716 if (play_bin->textoverlay_element) {
717 g_object_set (G_OBJECT (play_bin->textoverlay_element),
718 "font-desc", g_value_get_string (value), NULL);
721 case ARG_CONNECTION_SPEED:
722 play_bin->connection_speed = g_value_get_uint (value) * 1000;
725 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
731 gst_play_bin_get_property (GObject * object, guint prop_id, GValue * value,
734 GstPlayBin *play_bin;
736 play_bin = GST_PLAY_BIN (object);
740 g_value_set_object (value, play_bin->video_sink);
743 g_value_set_object (value, play_bin->audio_sink);
746 g_value_set_object (value, play_bin->visualisation);
749 g_value_set_double (value, play_bin->volume);
752 gst_value_set_mini_object (value, GST_MINI_OBJECT (play_bin->frame));
754 case ARG_CONNECTION_SPEED:
755 g_value_set_uint (value, play_bin->connection_speed / 1000);
758 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
763 /* signal fired when the identity has received a new buffer. This is used for
764 * making screenshots.
767 handoff (GstElement * identity, GstBuffer * frame, gpointer data)
769 GstPlayBin *play_bin = GST_PLAY_BIN (data);
770 GstBuffer **frame_p = &play_bin->frame;
772 gst_mini_object_replace ((GstMiniObject **) frame_p,
773 GST_MINI_OBJECT_CAST (frame));
775 /* applications need to know the buffer caps,
776 * make sure they are always set on the frame */
777 if (GST_BUFFER_CAPS (play_bin->frame) == NULL) {
780 if ((pad = gst_element_get_pad (identity, "sink"))) {
781 gst_buffer_set_caps (play_bin->frame, GST_PAD_CAPS (pad));
782 gst_object_unref (pad);
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 * +----------|--------------------------------------------------+
801 /* FIXME: this might return NULL if no videosink was found, handle
804 gen_video_element (GstPlayBin * play_bin)
811 GstElement *identity;
814 /* first see if we have it in the cache */
815 element = g_hash_table_lookup (play_bin->cache, "vbin");
816 if (element != NULL) {
820 if (play_bin->video_sink) {
821 sink = play_bin->video_sink;
823 sink = gst_element_factory_make ("autovideosink", "videosink");
825 sink = gst_element_factory_make ("xvimagesink", "videosink");
827 /* FIXME: this warrants adding a CORE error category for missing
828 * elements/plugins */
830 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
831 (_("Both autovideosink and xvimagesink elements are missing.")),
836 gst_object_ref (sink);
837 g_hash_table_insert (play_bin->cache, "video_sink", sink);
840 element = gst_bin_new ("vbin");
841 identity = gst_element_factory_make ("identity", "id");
842 g_object_set (identity, "silent", TRUE, NULL);
843 g_signal_connect (identity, "handoff", G_CALLBACK (handoff), play_bin);
844 gst_bin_add (GST_BIN (element), identity);
845 conv = gst_element_factory_make ("ffmpegcolorspace", "vconv");
848 scale = gst_element_factory_make ("videoscale", "vscale");
851 gst_bin_add (GST_BIN (element), conv);
852 gst_bin_add (GST_BIN (element), scale);
853 gst_bin_add (GST_BIN (element), sink);
854 gst_element_link_pads (identity, "src", conv, "sink");
855 gst_element_link_pads (conv, "src", scale, "sink");
856 gst_element_link_pads (scale, "src", sink, "sink");
858 pad = gst_element_get_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);
873 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
874 (_("Missing element '%s' - check your GStreamer installation."),
875 "ffmpegcolorspace"), (NULL));
876 gst_object_unref (element);
882 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
883 (_("Missing element '%s' - check your GStreamer installation."),
884 "videoscale"), ("possibly a liboil version mismatch?"));
885 gst_object_unref (element);
890 /* make an element for playback of video with subtitles embedded.
892 * +--------------------------------------------------+
893 * | tbin +-------------+ |
894 * | +-----+ | textoverlay | +------+ |
895 * | | csp | +--video_sink | | vbin | |
896 * video_sink-sink src+ +-text_sink src-sink | |
897 * | +-----+ | +-------------+ +------+ |
898 * text_sink-------------+ |
899 * +--------------------------------------------------+
903 gen_text_element (GstPlayBin * play_bin)
905 GstElement *element, *csp, *overlay, *vbin;
909 element = gst_bin_new ("textbin");
912 overlay = gst_element_factory_make ("textoverlay", "overlay");
914 /* Create the video rendering bin */
915 vbin = gen_video_element (play_bin);
917 /* If no overlay return the video bin */
919 GST_WARNING ("No overlay (pango) element, subtitles disabled");
923 /* Set some parameters */
924 g_object_set (G_OBJECT (overlay),
925 "halign", "center", "valign", "bottom", NULL);
926 if (play_bin->font_desc) {
927 g_object_set (G_OBJECT (overlay), "font-desc", play_bin->font_desc, NULL);
931 play_bin->textoverlay_element = GST_ELEMENT (gst_object_ref (overlay));
933 /* we know this will succeed, as the video bin already created one before */
934 csp = gst_element_factory_make ("ffmpegcolorspace", "subtitlecsp");
936 /* Add our elements */
937 gst_bin_add_many (GST_BIN (element), csp, overlay, vbin, NULL);
940 gst_element_link_pads (csp, "src", overlay, "video_sink");
941 gst_element_link_pads (overlay, "src", vbin, "sink");
943 /* Add ghost pads on the subtitle bin */
944 pad = gst_element_get_pad (overlay, "text_sink");
945 gst_element_add_pad (element, gst_ghost_pad_new ("text_sink", pad));
946 gst_object_unref (pad);
948 pad = gst_element_get_pad (csp, "sink");
949 gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
950 gst_object_unref (pad);
952 /* Set state to READY */
953 gst_element_set_state (element, GST_STATE_READY);
958 /* make the element (bin) that contains the elements needed to perform
961 * +-------------------------------------------------------------+
963 * | +---------+ +----------+ +---------+ +---------+ |
964 * | |audioconv| |audioscale| | volume | |audiosink| |
965 * | +-sink src-sink src-sink src-sink | |
966 * | | +---------+ +----------+ +---------+ +---------+ |
968 * +-------------------------------------------------------------+
972 gen_audio_element (GstPlayBin * play_bin)
981 element = g_hash_table_lookup (play_bin->cache, "abin");
982 if (element != NULL) {
985 element = gst_bin_new ("abin");
986 conv = gst_element_factory_make ("audioconvert", "aconv");
988 goto no_audioconvert;
990 scale = gst_element_factory_make ("audioresample", "aresample");
992 goto no_audioresample;
994 volume = gst_element_factory_make ("volume", "volume");
995 g_object_set (G_OBJECT (volume), "volume", play_bin->volume, NULL);
996 play_bin->volume_element = volume;
998 if (play_bin->audio_sink) {
999 sink = play_bin->audio_sink;
1001 sink = gst_element_factory_make ("autoaudiosink", "audiosink");
1003 sink = gst_element_factory_make ("alsasink", "audiosink");
1006 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1007 (_("Both autoaudiosink and alsasink elements are missing.")), (NULL));
1010 play_bin->audio_sink = GST_ELEMENT (gst_object_ref (sink));
1013 gst_object_ref (sink);
1014 g_hash_table_insert (play_bin->cache, "audio_sink", sink);
1016 gst_bin_add (GST_BIN (element), conv);
1017 gst_bin_add (GST_BIN (element), scale);
1018 gst_bin_add (GST_BIN (element), volume);
1019 gst_bin_add (GST_BIN (element), sink);
1021 gst_element_link_pads (conv, "src", scale, "sink");
1022 gst_element_link_pads (scale, "src", volume, "sink");
1023 gst_element_link_pads (volume, "src", sink, "sink");
1025 pad = gst_element_get_pad (conv, "sink");
1026 gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
1027 gst_object_unref (pad);
1029 gst_element_set_state (element, GST_STATE_READY);
1031 /* since we're gonna add it to a bin but don't want to lose it,
1032 * we keep a reference. */
1033 gst_object_ref (element);
1034 g_hash_table_insert (play_bin->cache, "abin", element);
1040 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1041 (_("Missing element '%s' - check your GStreamer installation."),
1042 "audioconvert"), ("possibly a liboil version mismatch?"));
1043 gst_object_unref (element);
1049 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1050 (_("Missing element '%s' - check your GStreamer installation."),
1051 "audioresample"), ("possibly a liboil version mismatch?"));
1052 gst_object_unref (element);
1057 /* make the element (bin) that contains the elements needed to perform
1058 * visualisation ouput. The idea is to split the audio using tee, then
1059 * sending the output to the regular audio bin and the other output to
1060 * the vis plugin that transforms it into a video that is rendered with the
1061 * normal video bin. The video bin is run in a thread to make sure it does
1062 * not block the audio playback pipeline.
1064 * +--------------------------------------------------------------------+
1066 * | +------+ +--------+ +----------------+ |
1067 * | | tee | | aqueue | | abin ... | |
1068 * | +-sink src-sink src-sink | |
1069 * | | | | +--------+ +----------------+ |
1071 * | | | | +------+ +---------+ +------+ +-----------+ |
1072 * | | | | |vqueue| |audioconv| | vis | | vbin ... | |
1073 * | | | src-sink src-sink src-sink src-sink | |
1074 * | | | | +------+ +---------+ +------+ +-----------+ |
1078 +---------------------------------------------------------------------+
1081 gen_vis_element (GstPlayBin * play_bin)
1083 GstElement *element;
1089 GstElement *vqueue, *aqueue;
1092 asink = gen_audio_element (play_bin);
1095 vsink = gen_video_element (play_bin);
1097 gst_object_unref (asink);
1101 element = gst_bin_new ("visbin");
1102 tee = gst_element_factory_make ("tee", "tee");
1104 vqueue = gst_element_factory_make ("queue", "vqueue");
1105 aqueue = gst_element_factory_make ("queue", "aqueue");
1107 gst_bin_add (GST_BIN (element), asink);
1108 gst_bin_add (GST_BIN (element), vqueue);
1109 gst_bin_add (GST_BIN (element), aqueue);
1110 gst_bin_add (GST_BIN (element), vsink);
1111 gst_bin_add (GST_BIN (element), tee);
1113 conv = gst_element_factory_make ("audioconvert", "aconv");
1115 goto no_audioconvert;
1117 if (play_bin->visualisation) {
1118 gst_object_ref (play_bin->visualisation);
1119 vis = play_bin->visualisation;
1121 vis = gst_element_factory_make ("goom", "vis");
1124 gst_bin_add (GST_BIN (element), conv);
1125 gst_bin_add (GST_BIN (element), vis);
1127 gst_element_link_pads (vqueue, "src", conv, "sink");
1128 gst_element_link_pads (conv, "src", vis, "sink");
1129 gst_element_link_pads (vis, "src", vsink, "sink");
1131 pad = gst_element_get_pad (aqueue, "sink");
1132 rpad = gst_element_get_request_pad (tee, "src%d");
1133 gst_pad_link (rpad, pad);
1134 gst_object_unref (rpad);
1135 gst_object_unref (pad);
1136 gst_element_link_pads (aqueue, "src", asink, "sink");
1138 pad = gst_element_get_pad (vqueue, "sink");
1139 rpad = gst_element_get_request_pad (tee, "src%d");
1140 gst_pad_link (rpad, pad);
1141 gst_object_unref (rpad);
1142 gst_object_unref (pad);
1144 pad = gst_element_get_pad (tee, "sink");
1145 gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
1146 gst_object_unref (pad);
1152 GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1153 (_("Missing element '%s' - check your GStreamer installation."),
1154 "audioconvert"), ("possibly a liboil version mismatch?"));
1155 gst_object_unref (element);
1160 /* get rid of all installed sinks */
1162 remove_sinks (GstPlayBin * play_bin)
1166 GstElement *element;
1169 GST_DEBUG ("removesinks");
1170 element = g_hash_table_lookup (play_bin->cache, "abin");
1171 if (element != NULL) {
1172 parent = gst_element_get_parent (element);
1173 if (parent != NULL) {
1174 /* we remove the element from the parent so that
1175 * there is no unwanted state change when the parent
1177 play_bin->sinks = g_list_remove (play_bin->sinks, element);
1178 gst_element_set_state (element, GST_STATE_NULL);
1179 gst_bin_remove (GST_BIN (parent), element);
1180 gst_object_unref (parent);
1182 pad = gst_element_get_pad (element, "sink");
1184 peer = gst_pad_get_peer (pad);
1186 gst_pad_unlink (peer, pad);
1187 gst_object_unref (peer);
1189 gst_object_unref (pad);
1192 element = g_hash_table_lookup (play_bin->cache, "vbin");
1193 if (element != NULL) {
1194 parent = gst_element_get_parent (element);
1195 if (parent != NULL) {
1196 play_bin->sinks = g_list_remove (play_bin->sinks, element);
1197 gst_element_set_state (element, GST_STATE_NULL);
1198 gst_bin_remove (GST_BIN (parent), element);
1199 gst_object_unref (parent);
1201 pad = gst_element_get_pad (element, "sink");
1203 peer = gst_pad_get_peer (pad);
1205 gst_pad_unlink (peer, pad);
1206 gst_object_unref (peer);
1208 gst_object_unref (pad);
1212 for (sinks = play_bin->sinks; sinks; sinks = g_list_next (sinks)) {
1213 GstElement *element = GST_ELEMENT (sinks->data);
1217 pad = gst_element_get_pad (element, "sink");
1219 GST_LOG ("removing sink %p", element);
1221 peer = gst_pad_get_peer (pad);
1223 gst_pad_unlink (peer, pad);
1224 gst_object_unref (peer);
1226 gst_object_unref (pad);
1228 gst_element_set_state (element, GST_STATE_NULL);
1229 gst_bin_remove (GST_BIN (play_bin), element);
1231 g_list_free (play_bin->sinks);
1232 play_bin->sinks = NULL;
1234 /* FIXME: this is probably some refcounting problem */
1235 if (play_bin->visualisation && GST_OBJECT_PARENT (play_bin->visualisation)) {
1236 gst_element_set_state (play_bin->visualisation, GST_STATE_NULL);
1237 gst_bin_remove (GST_BIN (GST_OBJECT_PARENT (play_bin->visualisation)),
1238 play_bin->visualisation);
1241 if (play_bin->frame) {
1242 gst_buffer_unref (play_bin->frame);
1243 play_bin->frame = NULL;
1246 if (play_bin->textoverlay_element) {
1247 gst_object_unref (play_bin->textoverlay_element);
1248 play_bin->textoverlay_element = NULL;
1252 /* loop over the streams and set up the pipeline to play this
1253 * media file. First we count the number of audio and video streams.
1254 * If there is no video stream but there exists an audio stream,
1255 * we install a visualisation pipeline.
1257 * Also make sure to only connect the first audio and video pad. FIXME
1258 * this should eventually be handled with a tuner interface so that
1259 * one can switch the streams.
1262 add_sink (GstPlayBin * play_bin, GstElement * sink, GstPad * srcpad,
1263 GstPad * subtitle_pad)
1266 GstPadLinkReturn linkres;
1268 GstStateChangeReturn stateret;
1270 g_return_val_if_fail (sink != NULL, FALSE);
1271 /* this is only for debugging */
1272 parent = gst_pad_get_parent_element (srcpad);
1274 GST_DEBUG ("Adding sink with state %d (parent: %d, peer: %d)",
1275 GST_STATE (sink), GST_STATE (play_bin), GST_STATE (parent));
1276 gst_object_unref (parent);
1279 /* bring it to the PAUSED state so we can link to the peer without
1280 * breaking the flow */
1281 if ((stateret = gst_element_set_state (sink, GST_STATE_PAUSED)) ==
1282 GST_STATE_CHANGE_FAILURE)
1285 gst_bin_add (GST_BIN (play_bin), sink);
1287 /* we found a sink for this stream, now try to install it */
1288 sinkpad = gst_element_get_pad (sink, "sink");
1289 linkres = gst_pad_link (srcpad, sinkpad);
1290 gst_object_unref (sinkpad);
1292 /* try to link the pad of the sink to the stream */
1293 if (GST_PAD_LINK_FAILED (linkres))
1296 if (GST_IS_PAD (subtitle_pad)) {
1297 sinkpad = gst_element_get_pad (sink, "text_sink");
1298 linkres = gst_pad_link (subtitle_pad, sinkpad);
1299 gst_object_unref (sinkpad);
1302 /* try to link the subtitle pad of the sink to the stream */
1303 if (GST_PAD_LINK_FAILED (linkres)) {
1304 goto subtitle_failed;
1307 /* we got the sink succesfully linked, now keep the sink
1308 * in our internal list */
1309 play_bin->sinks = g_list_prepend (play_bin->sinks, sink);
1316 GST_DEBUG_OBJECT (play_bin, "state change failure when adding sink");
1324 /* could not link this stream */
1325 caps = gst_pad_get_caps (srcpad);
1326 capsstr = gst_caps_to_string (caps);
1327 g_warning ("could not link %s: %d", capsstr, linkres);
1328 GST_DEBUG_OBJECT (play_bin,
1329 "link failed when adding sink, caps %s, reason %d", capsstr, linkres);
1331 gst_caps_unref (caps);
1333 gst_element_set_state (sink, GST_STATE_NULL);
1334 gst_bin_remove (GST_BIN (play_bin), sink);
1342 /* could not link this stream */
1343 caps = gst_pad_get_caps (subtitle_pad);
1344 capsstr = gst_caps_to_string (caps);
1345 GST_DEBUG_OBJECT (play_bin,
1346 "subtitle link failed when adding sink, caps %s, reason %d", capsstr,
1349 gst_caps_unref (caps);
1356 setup_sinks (GstPlayBaseBin * play_base_bin, GstPlayBaseGroup * group)
1358 GstPlayBin *play_bin = GST_PLAY_BIN (play_base_bin);
1359 GList *streaminfo = NULL, *s;
1360 gboolean need_vis = FALSE;
1361 gboolean need_text = FALSE;
1362 GstPad *textsrcpad = NULL, *pad = NULL;
1364 gboolean res = TRUE;
1366 /* get rid of existing sinks */
1367 if (play_bin->sinks) {
1368 remove_sinks (play_bin);
1370 GST_DEBUG_OBJECT (play_base_bin, "setupsinks");
1372 /* find out what to do */
1373 if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads > 0 &&
1374 group->type[GST_STREAM_TYPE_TEXT - 1].npads > 0) {
1376 } else if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads == 0 &&
1377 group->type[GST_STREAM_TYPE_AUDIO - 1].npads > 0 &&
1378 play_bin->visualisation != NULL) {
1382 /* now actually connect everything */
1383 g_object_get (G_OBJECT (play_base_bin), "stream-info", &streaminfo, NULL);
1384 for (s = streaminfo; s; s = g_list_next (s)) {
1385 GObject *obj = G_OBJECT (s->data);
1389 g_object_get (obj, "type", &type, NULL);
1390 g_object_get (obj, "object", &object, NULL);
1394 if (group->type[GST_STREAM_TYPE_AUDIO - 1].npads > 0) {
1396 sink = gen_vis_element (play_bin);
1398 sink = gen_audio_element (play_bin);
1402 pad = gst_element_get_pad (group->type[GST_STREAM_TYPE_AUDIO - 1].preroll,
1404 res = add_sink (play_bin, sink, pad, NULL);
1405 gst_object_unref (pad);
1409 if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads > 0) {
1411 GstObject *parent = NULL, *grandparent = NULL;
1412 GstPad *ghost = NULL;
1414 sink = gen_text_element (play_bin);
1416 gst_element_get_pad (group->type[GST_STREAM_TYPE_TEXT - 1].preroll,
1418 /* This pad is from subtitle-bin, we need to create a ghost pad to have
1419 common grandparents */
1420 parent = gst_object_get_parent (GST_OBJECT (textsrcpad));
1422 GST_WARNING_OBJECT (textsrcpad, "subtitle pad has no parent !");
1423 gst_object_unref (textsrcpad);
1428 grandparent = gst_object_get_parent (parent);
1430 GST_WARNING_OBJECT (textsrcpad, "subtitle pad has no grandparent !");
1431 gst_object_unref (parent);
1432 gst_object_unref (textsrcpad);
1437 /* We ghost the pad on subtitle_bin only, if the text pad is from the
1438 media demuxer we keep it as it is */
1439 if (!GST_IS_PLAY_BIN (grandparent)) {
1440 GST_DEBUG_OBJECT (textsrcpad, "this subtitle pad is from a subtitle "
1441 "file, ghosting to a suitable hierarchy");
1442 ghost = gst_ghost_pad_new ("text_src", textsrcpad);
1443 if (!GST_IS_PAD (ghost)) {
1444 GST_WARNING_OBJECT (textsrcpad, "failed creating ghost pad for "
1446 gst_object_unref (parent);
1447 gst_object_unref (grandparent);
1448 gst_object_unref (textsrcpad);
1453 if (gst_element_add_pad (GST_ELEMENT (grandparent), ghost)) {
1454 gst_object_unref (textsrcpad);
1455 textsrcpad = gst_object_ref (ghost);
1457 GST_WARNING_OBJECT (ghost, "failed adding ghost pad on subtitle-bin");
1458 gst_object_unref (ghost);
1459 gst_object_unref (textsrcpad);
1463 GST_DEBUG_OBJECT (textsrcpad, "this subtitle pad is from the demuxer "
1464 "no changes to hierarchy needed");
1467 gst_object_unref (parent);
1468 gst_object_unref (grandparent);
1470 sink = gen_video_element (play_bin);
1475 pad = gst_element_get_pad (group->type[GST_STREAM_TYPE_VIDEO - 1].preroll,
1477 res = add_sink (play_bin, sink, pad, textsrcpad);
1478 gst_object_unref (pad);
1480 gst_object_unref (textsrcpad);
1484 /* remove the sinks now, pipeline get_state will now wait for the
1485 * sinks to preroll */
1486 if (play_bin->fakesink) {
1487 gst_element_set_state (play_bin->fakesink, GST_STATE_NULL);
1488 gst_bin_remove (GST_BIN (play_bin), play_bin->fakesink);
1489 play_bin->fakesink = NULL;
1495 /* Send an event to our sinks until one of them works; don't then send to the
1496 * remaining sinks (unlike GstBin)
1499 gst_play_bin_send_event_to_sink (GstPlayBin * play_bin, GstEvent * event)
1501 GList *sinks = play_bin->sinks;
1502 gboolean res = TRUE;
1505 GstElement *sink = GST_ELEMENT_CAST (sinks->data);
1507 gst_event_ref (event);
1508 if ((res = gst_element_send_event (sink, event))) {
1509 GST_DEBUG_OBJECT (play_bin,
1510 "Sent event succesfully to sink %" GST_PTR_FORMAT, sink);
1513 GST_DEBUG_OBJECT (play_bin,
1514 "Event failed when sent to sink %" GST_PTR_FORMAT, sink);
1516 sinks = g_list_next (sinks);
1519 gst_event_unref (event);
1525 do_playbin_seek (GstElement * element, GstEvent * event)
1530 gboolean was_playing = FALSE;
1533 gst_event_parse_seek (event, &rate, NULL, &flags, NULL, NULL, NULL, NULL);
1535 flush = flags & GST_SEEK_FLAG_FLUSH;
1540 /* need to call _get_state() since a bin state is only updated
1541 * with this call. */
1542 gst_element_get_state (element, &state, NULL, 0);
1543 was_playing = state == GST_STATE_PLAYING;
1546 gst_element_set_state (element, GST_STATE_PAUSED);
1547 gst_element_get_state (element, NULL, NULL, 50 * GST_MSECOND);
1551 GST_DEBUG_OBJECT (element, "Sending seek event to a sink");
1552 res = gst_play_bin_send_event_to_sink (GST_PLAY_BIN (element), event);
1555 /* need to reset the stream time to 0 after a flushing seek */
1557 gst_pipeline_set_new_stream_time (GST_PIPELINE (element), 0);
1560 /* and continue playing */
1561 gst_element_set_state (element, GST_STATE_PLAYING);
1566 /* We only want to send the event to a single sink (overriding GstBin's
1567 * behaviour), but we want to keep GstPipeline's behaviour - wrapping seek
1568 * events appropriately. So, this is a messy duplication of code. */
1570 gst_play_bin_send_event (GstElement * element, GstEvent * event)
1572 gboolean res = FALSE;
1573 GstEventType event_type = GST_EVENT_TYPE (event);
1576 switch (event_type) {
1577 case GST_EVENT_SEEK:
1578 res = do_playbin_seek (element, event);
1581 res = gst_play_bin_send_event_to_sink (GST_PLAY_BIN (element), event);
1589 value_list_append_structure_list (GValue * list_val, GstStructure ** first,
1590 GList * structure_list)
1594 for (l = structure_list; l != NULL; l = l->next) {
1595 GValue val = { 0, };
1598 *first = gst_structure_copy ((GstStructure *) l->data);
1600 g_value_init (&val, GST_TYPE_STRUCTURE);
1601 g_value_take_boxed (&val, gst_structure_copy ((GstStructure *) l->data));
1602 gst_value_list_append_value (list_val, &val);
1603 g_value_unset (&val);
1607 /* if it's a redirect message with multiple redirect locations we might
1608 * want to pick a different 'best' location depending on the required
1609 * bitrates and the connection speed */
1611 gst_play_bin_handle_redirect_message (GstPlayBin * playbin, GstMessage * msg)
1613 const GValue *locations_list, *location_val;
1614 GstMessage *new_msg;
1615 GstStructure *new_structure = NULL;
1616 GList *l_good = NULL, *l_neutral = NULL, *l_bad = NULL;
1617 GValue new_list = { 0, };
1620 GST_DEBUG_OBJECT (playbin, "redirect message: %" GST_PTR_FORMAT, msg);
1621 GST_DEBUG_OBJECT (playbin, "connection speed: %u", playbin->connection_speed);
1623 if (playbin->connection_speed == 0 || msg->structure == NULL)
1626 locations_list = gst_structure_get_value (msg->structure, "locations");
1627 if (locations_list == NULL)
1630 size = gst_value_list_get_size (locations_list);
1634 /* maintain existing order as much as possible, just sort references
1635 * with too high a bitrate to the end (the assumption being that if
1636 * bitrates are given they are given for all interesting streams and
1637 * that the you-need-at-least-version-xyz redirect has the same bitrate
1638 * as the lowest referenced redirect alternative) */
1639 for (i = 0; i < size; ++i) {
1640 const GstStructure *s;
1643 location_val = gst_value_list_get_value (locations_list, i);
1644 s = (const GstStructure *) g_value_get_boxed (location_val);
1645 if (!gst_structure_get_int (s, "minimum-bitrate", &bitrate) || bitrate <= 0) {
1646 GST_DEBUG_OBJECT (playbin, "no bitrate: %" GST_PTR_FORMAT, s);
1647 l_neutral = g_list_append (l_neutral, (gpointer) s);
1648 } else if (bitrate > playbin->connection_speed) {
1649 GST_DEBUG_OBJECT (playbin, "bitrate too high: %" GST_PTR_FORMAT, s);
1650 l_bad = g_list_append (l_bad, (gpointer) s);
1651 } else if (bitrate <= playbin->connection_speed) {
1652 GST_DEBUG_OBJECT (playbin, "bitrate OK: %" GST_PTR_FORMAT, s);
1653 l_good = g_list_append (l_good, (gpointer) s);
1657 g_value_init (&new_list, GST_TYPE_LIST);
1658 value_list_append_structure_list (&new_list, &new_structure, l_good);
1659 value_list_append_structure_list (&new_list, &new_structure, l_neutral);
1660 value_list_append_structure_list (&new_list, &new_structure, l_bad);
1661 gst_structure_set_value (new_structure, "locations", &new_list);
1662 g_value_unset (&new_list);
1664 g_list_free (l_good);
1665 g_list_free (l_neutral);
1666 g_list_free (l_bad);
1668 new_msg = gst_message_new_element (msg->src, new_structure);
1669 gst_message_unref (msg);
1671 GST_DEBUG_OBJECT (playbin, "new redirect message: %" GST_PTR_FORMAT, new_msg);
1676 gst_play_bin_handle_message (GstBin * bin, GstMessage * msg)
1678 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ELEMENT && msg->structure != NULL
1679 && gst_structure_has_name (msg->structure, "redirect")) {
1680 msg = gst_play_bin_handle_redirect_message (GST_PLAY_BIN (bin), msg);
1683 GST_BIN_CLASS (parent_class)->handle_message (bin, msg);
1686 static GstStateChangeReturn
1687 gst_play_bin_change_state (GstElement * element, GstStateChange transition)
1689 GstStateChangeReturn ret;
1690 GstPlayBin *play_bin;
1692 play_bin = GST_PLAY_BIN (element);
1695 switch (transition) {
1696 case GST_STATE_CHANGE_READY_TO_PAUSED:
1697 /* this really is the easiest way to make the state change return
1698 * ASYNC until we added the sinks */
1699 if (!play_bin->fakesink) {
1700 play_bin->fakesink = gst_element_factory_make ("fakesink", "test");
1701 gst_bin_add (GST_BIN (play_bin), play_bin->fakesink);
1708 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1709 if (ret == GST_STATE_CHANGE_FAILURE)
1712 switch (transition) {
1713 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1714 /* Set audio sink state to NULL to release the sound device,
1715 * but only if we own it (else we might be in chain-transition). */
1716 //if (play_bin->audio_sink != NULL &&
1717 // GST_STATE (play_bin->audio_sink) == GST_STATE_PAUSED) {
1718 // gst_element_set_state (play_bin->audio_sink, GST_STATE_NULL);
1721 case GST_STATE_CHANGE_PAUSED_TO_READY:
1722 /* Check for NULL because the state transition may be done by
1723 * gst_bin_dispose which is called by gst_play_bin_dispose, and in that
1724 * case, we don't want to run remove_sinks.
1725 * FIXME: should the NULL test be done in remove_sinks? Should we just
1726 * set the state to NULL in gst_play_bin_dispose?
1728 if (play_bin->cache != NULL) {
1729 remove_sinks (play_bin);
1731 if (play_bin->fakesink) {
1732 gst_element_set_state (play_bin->fakesink, GST_STATE_NULL);
1733 gst_bin_remove (GST_BIN (play_bin), play_bin->fakesink);
1734 play_bin->fakesink = NULL;
1745 plugin_init (GstPlugin * plugin)
1747 GST_DEBUG_CATEGORY_INIT (gst_play_bin_debug, "playbin", 0, "play bin");
1750 GST_DEBUG ("binding text domain %s to locale dir %s", GETTEXT_PACKAGE,
1752 bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR);
1753 #endif /* ENABLE_NLS */
1755 return gst_element_register (plugin, "playbin", GST_RANK_NONE,
1759 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
1762 "player bin", plugin_init, VERSION, GST_LICENSE, GST_PACKAGE_NAME,