2 * Copyright (C) <2007> Wim Taymans <wim.taymans@gmail.com>
3 * Copyright (C) <2011> Sebastian Dröge <sebastian.droege@collabora.co.uk>
4 * Copyright (C) <2013> Collabora Ltd.
5 * Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
6 * Copyright (C) <2015> Jan Schmidt <jan@centricular.com>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
24 * SECTION:element-playbin3
27 * playbin3 provides a stand-alone everything-in-one abstraction for an
28 * audio and/or video player. It differs from the previous playbin (playbin2)
29 * by supporting publication and selection of available streams via the
30 * #GstStreamCollection message and #GST_EVENT_SELECT_STREAMS event API.
32 * > playbin3 is still experimental API and a technology preview.
33 * > Its behaviour and exposed API is subject to change.
35 * playbin3 can handle both audio and video files and features
37 * * automatic file type recognition and based on that automatic
38 * selection and usage of the right audio/video/subtitle demuxers/decoders
40 * * auxiliary files - such as external subtitles and audio tracks
41 * * visualisations for audio files
42 * * subtitle support for video files. Subtitles can be store in external
44 * * stream selection between different video/audio/subtitles streams
45 * * meta info (tag) extraction
46 * * easy access to the last video sample
47 * * buffering when playing streams over a network
48 * * volume control with mute option
52 * A playbin element can be created just like any other element using
53 * gst_element_factory_make(). The file/URI to play should be set via the #GstPlayBin3:uri
54 * property. This must be an absolute URI, relative file paths are not allowed.
55 * Example URIs are file:///home/joe/movie.avi or http://www.joedoe.com/foo.ogg
57 * Playbin3 is a #GstPipeline. It will notify the application of everything
58 * that's happening (errors, end of stream, tags found, state changes, etc.)
59 * by posting messages on its #GstBus. The application needs to watch the
62 * Playback can be initiated by setting the element to PLAYING state using
63 * gst_element_set_state(). Note that the state change will take place in
64 * the background in a separate thread, when the function returns playback
65 * is probably not happening yet and any errors might not have occurred yet.
66 * Applications using playbin3 should ideally be written to deal with things
67 * completely asynchroneous.
69 * When playback has finished (an EOS message has been received on the bus)
70 * or an error has occurred (an ERROR message has been received on the bus) or
71 * the user wants to play a different track, playbin3 should be set back to
72 * READY or NULL state, then the #GstPlayBin3:uri property should be set to the
73 * new location and then playbin3 be set to PLAYING state again.
75 * Seeking can be done using gst_element_seek_simple() or gst_element_seek()
76 * on the playbin3 element. Again, the seek will not be executed
77 * instantaneously, but will be done in a background thread. When the seek
78 * call returns the seek will most likely still be in process. An application
79 * may wait for the seek to finish (or fail) using gst_element_get_state() with
80 * -1 as the timeout, but this will block the user interface and is not
83 * Applications may query the current position and duration of the stream
84 * via gst_element_query_position() and gst_element_query_duration() and
85 * setting the format passed to GST_FORMAT_TIME. If the query was successful,
86 * the duration or position will have been returned in units of nanoseconds.
88 * ## Selecting streams
90 * The recommended way to select streams (instead of the default selection) is
91 * to listen to GST_MESSAGE_STREAM_COLLECTION messages on the GstBus and send a
92 * GST_EVENT_SELECT_STREAMS on the pipeline with the selected streams. This
93 * provides more information and flexibility compared to the legacy #GstPlayBin
94 * property and signal-based mechanism.
96 * Note: The application should not assume that collections will not change
97 * throughout a single file. If it wishes to modify the default selection, it
98 * should always respond to new collections posted on the bus with a
99 * GST_EVENT_SELECT_STREAMS.
101 * ## Advanced Usage: specifying the audio and video sink
103 * By default, if no audio sink or video sink has been specified via the
104 * #GstPlayBin3:audio-sink or #GstPlayBin3:video-sink property, playbin3 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.
110 * If the application wants more control over how audio or video should be
111 * output, it may create the audio/video sink elements itself (for example
112 * using gst_element_factory_make()) and provide them to playbin3 using the
113 * #GstPlayBin3:audio-sink or #GstPlayBin3:video-sink property.
115 * GNOME-based applications, for example, will usually want to create
116 * gconfaudiosink and gconfvideosink elements and make playbin3 use those,
117 * so that output happens to whatever the user has configured in the GNOME
118 * Multimedia System Selector configuration dialog.
120 * The sink elements do not necessarily need to be ready-made sinks. It is
121 * possible to create container elements that look like a sink to playbin3,
122 * but in reality contain a number of custom elements linked together. This
123 * can be achieved by creating a #GstBin and putting elements in there and
124 * linking them, and then creating a sink #GstGhostPad for the bin and pointing
125 * it to the sink pad of the first element within the bin. This can be used
126 * for a number of purposes, for example to force output to a particular
127 * format or to modify or observe the data before it is output.
129 * It is also possible to 'suppress' audio and/or video output by using
130 * 'fakesink' elements (or capture it from there using the fakesink element's
131 * "handoff" signal, which, nota bene, is fired from the streaming thread!).
133 * ## Retrieving Tags and Other Meta Data
135 * Most of the common meta data (artist, title, etc.) can be retrieved by
136 * watching for TAG messages on the pipeline's bus (see above).
138 * Other more specific meta information like width/height/framerate of video
139 * streams or samplerate/number of channels of audio streams can be obtained
140 * from the negotiated caps on the sink pads of the sinks.
143 * Playbin3 handles buffering automatically for the most part, but applications
144 * need to handle parts of the buffering process as well. Whenever playbin3 is
145 * buffering, it will post BUFFERING messages on the bus with a percentage
146 * value that shows the progress of the buffering process. Applications need
147 * to set playbin3 to PLAYING or PAUSED state in response to these messages.
148 * They may also want to convey the buffering progress to the user in some
149 * way. Here is how to extract the percentage information from the message:
151 * switch (GST_MESSAGE_TYPE (msg)) {
152 * case GST_MESSAGE_BUFFERING: {
154 * gst_message_parse_buffering (msg, &percent);
155 * g_print ("Buffering (%u percent done)", percent);
162 * Note that applications should keep/set the pipeline in the PAUSED state when
163 * a BUFFERING message is received with a buffer percent value < 100 and set
164 * the pipeline back to PLAYING state when a BUFFERING message with a value
165 * of 100 percent is received (if PLAYING is the desired state, that is).
167 * ## Embedding the video window in your application
168 * By default, playbin3 (or rather the video sinks used) will create their own
169 * window. Applications will usually want to force output to a window of their
170 * own, however. This can be done using the #GstVideoOverlay interface, which most
171 * video sinks implement. See the documentation there for more details.
173 * ## Specifying which CD/DVD device to use
175 * The device to use for CDs/DVDs needs to be set on the source element playbin3
176 * creates before it is opened. The most generic way of doing this is to connect
177 * to playbin3's "source-setup" signal, which will be emitted by playbin3 when
178 * it has created the source element for a particular URI. In the signal
179 * callback you can check if the source element has a "device" property and set
180 * it appropriately. In some cases the device can also be set as part of the
181 * URI, but it depends on the elements involved if this will work or not. For
182 * example, for DVD menu playback, the following syntax might work (if the
183 * resindvd plugin is used): dvd://[/path/to/device]
185 * ## Handling redirects
187 * Some elements may post 'redirect' messages on the bus to tell the
188 * application to open another location. These are element messages containing
189 * a structure named 'redirect' along with a 'new-location' field of string
190 * type. The new location may be a relative or an absolute URI. Examples
191 * for such redirects can be found in many quicktime movie trailers.
195 * gst-launch-1.0 -v playbin3 uri=file:///path/to/somefile.mp4
197 * This will play back the given AVI video file, given that the video and
198 * audio decoders required to decode the content are installed. Since no
199 * special audio sink or video sink is supplied (via playbin3's audio-sink or
200 * video-sink properties) playbin3 will try to find a suitable audio and
201 * video sink automatically using the autoaudiosink and autovideosink elements.
203 * gst-launch-1.0 -v playbin3 uri=cdda://4
205 * This will play back track 4 on an audio CD in your disc drive (assuming
206 * the drive is detected automatically by the plugin).
208 * gst-launch-1.0 -v playbin3 uri=dvd://
210 * This will play back the DVD in your disc drive (assuming
211 * the drive is detected automatically by the plugin).
222 #include <glib/gi18n-lib.h>
223 #include <gst/pbutils/pbutils.h>
224 #include <gst/audio/streamvolume.h>
225 #include <gst/video/video-info.h>
226 #include <gst/video/video-multiview.h>
227 #include <gst/video/videooverlay.h>
228 #include <gst/video/navigation.h>
229 #include <gst/video/colorbalance.h>
230 #include "gstplay-enum.h"
231 #include "gstplaybackelements.h"
232 #include "gstplaysink.h"
233 #include "gstsubtitleoverlay.h"
234 #include "gstplaybackutils.h"
236 GST_DEBUG_CATEGORY_STATIC (gst_play_bin3_debug);
237 #define GST_CAT_DEFAULT gst_play_bin3_debug
239 #define GST_TYPE_PLAY_BIN (gst_play_bin3_get_type())
240 #define GST_PLAY_BIN3(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PLAY_BIN,GstPlayBin3))
241 #define GST_PLAY_BIN3_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PLAY_BIN,GstPlayBin3Class))
242 #define GST_IS_PLAY_BIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PLAY_BIN))
243 #define GST_IS_PLAY_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PLAY_BIN))
245 #define ULONG_TO_POINTER(number) ((gpointer) (guintptr) (number))
246 #define POINTER_TO_ULONG(number) ((guintptr) (number))
248 #define VOLUME_MAX_DOUBLE 10.0
250 typedef struct _GstPlayBin3 GstPlayBin3;
251 typedef struct _GstPlayBin3Class GstPlayBin3Class;
252 typedef struct _GstSourceGroup GstSourceGroup;
253 typedef struct _GstSourceCombine GstSourceCombine;
254 typedef struct _SourcePad SourcePad;
256 /* GstSourceCombine controls all the information regarding a certain
259 * It can control a custom combiner element (by default none)
261 struct _GstSourceCombine
263 GstStreamType stream_type; /* The GstStreamType of the combiner */
265 GstElement *combiner; /* the combiner */
266 GPtrArray *inputpads; /* Array of sink request GstPad of the combiner */
268 GstPad *srcpad; /* the source pad of the combiner */
269 GstPad *sinkpad; /* the sinkpad of the sink when the combiner
272 GPtrArray *streams; /* Sorted array of GstStream for the given type */
274 gboolean has_active_pad; /* stream combiner has the "active-pad" property */
276 gboolean is_concat; /* The stream combiner is the 'concat' element */
279 #define GST_SOURCE_GROUP_GET_LOCK(group) (&((GstSourceGroup*)(group))->lock)
280 #define GST_SOURCE_GROUP_LOCK(group) (g_mutex_lock (GST_SOURCE_GROUP_GET_LOCK(group)))
281 #define GST_SOURCE_GROUP_UNLOCK(group) (g_mutex_unlock (GST_SOURCE_GROUP_GET_LOCK(group)))
285 PLAYBIN_STREAM_AUDIO = 0,
286 PLAYBIN_STREAM_VIDEO,
291 /* names matching the enum above */
292 static const gchar *stream_type_names[] = {
293 "audio", "video", "text"
297 #define STREAM_TYPES_FORMAT "s%s%s"
298 #define STREAM_TYPES_ARGS(s) (s) & GST_STREAM_TYPE_AUDIO ? "audio " : "", \
299 (s) & GST_STREAM_TYPE_VIDEO ? "video " : "", \
300 (s) & GST_STREAM_TYPE_TEXT ? "text " : ""
303 /* a structure to hold information about a uridecodebin pad */
306 GstPad *pad; /* The controlled pad */
307 GstStreamType stream_type; /* stream type of the controlled pad */
308 GstPad *combine_sinkpad; /* Combiner request sinkpad linked to pad */
309 gulong event_probe_id;
312 /* a structure to hold the objects for decoding a uri and the subtitle uri
314 struct _GstSourceGroup
316 GstPlayBin3 *playbin;
320 gboolean valid; /* the group has valid info to start playback */
321 gboolean active; /* the group is active */
323 gboolean playing; /* the group is currently playing
324 * (outputted on the sinks) */
330 /* The currently outputted group_id */
333 /* Bit-wise set of stream types we have requested from uridecodebin3 */
334 GstStreamType selected_stream_types;
336 /* Bit-wise set of stream types for which pads are present */
337 GstStreamType present_stream_types;
339 /* TRUE if a 'about-to-finish' needs to be posted once we have
340 * got source pads for all requested stream types
342 * FIXME : Move this logic to uridecodebin3 later */
343 gboolean pending_about_to_finish;
345 /* uridecodebin to handle uri and suburi */
346 GstElement *uridecodebin;
348 /* Active sinks for each media type. These are initialized with
349 * the configured or currently used sink, otherwise
350 * left as NULL and playbin tries to automatically
351 * select a good sink */
352 GstElement *audio_sink;
353 GstElement *video_sink;
354 GstElement *text_sink;
356 /* List of source pads */
359 /* uridecodebin signals */
361 gulong pad_removed_id;
362 gulong select_stream_id;
363 gulong source_setup_id;
364 gulong about_to_finish_id;
366 gboolean stream_changed_pending;
368 /* Active stream collection */
369 GstStreamCollection *collection;
372 /* buffering message stored for after switching */
373 GstMessage *pending_buffering_msg;
376 #define GST_PLAY_BIN3_GET_LOCK(bin) (&((GstPlayBin3*)(bin))->lock)
377 #define GST_PLAY_BIN3_LOCK(bin) (g_rec_mutex_lock (GST_PLAY_BIN3_GET_LOCK(bin)))
378 #define GST_PLAY_BIN3_UNLOCK(bin) (g_rec_mutex_unlock (GST_PLAY_BIN3_GET_LOCK(bin)))
380 /* lock to protect dynamic callbacks, like no-more-pads */
381 #define GST_PLAY_BIN3_DYN_LOCK(bin) g_mutex_lock (&(bin)->dyn_lock)
382 #define GST_PLAY_BIN3_DYN_UNLOCK(bin) g_mutex_unlock (&(bin)->dyn_lock)
384 /* lock for shutdown */
385 #define GST_PLAY_BIN3_SHUTDOWN_LOCK(bin,label) \
387 if (G_UNLIKELY (g_atomic_int_get (&bin->shutdown))) \
389 GST_PLAY_BIN3_DYN_LOCK (bin); \
390 if (G_UNLIKELY (g_atomic_int_get (&bin->shutdown))) { \
391 GST_PLAY_BIN3_DYN_UNLOCK (bin); \
396 /* unlock for shutdown */
397 #define GST_PLAY_BIN3_SHUTDOWN_UNLOCK(bin) \
398 GST_PLAY_BIN3_DYN_UNLOCK (bin); \
403 * playbin element structure
409 GRecMutex lock; /* to protect group switching */
411 /* the input groups, we use a double buffer to switch between current and next */
412 GstSourceGroup groups[2]; /* array with group info */
413 GstSourceGroup *curr_group; /* pointer to the currently playing group */
414 GstSourceGroup *next_group; /* pointer to the next group */
416 /* combiners for different streams */
417 GstSourceCombine combiner[PLAYBIN_STREAM_LAST];
419 /* Bit-wise set of stream types we have requested from uridecodebin3.
420 * Calculated as the combination of the 'selected_stream_types' of
421 * each sourcegroup */
422 GstStreamType selected_stream_types;
424 /* Bit-wise set of configured output stream types (i.e. active
425 playsink inputs and combiners) */
426 GstStreamType active_stream_types;
429 guint64 connection_speed; /* connection speed in bits/sec (0 = unknown) */
430 gint current_video; /* the currently selected stream */
431 gint current_audio; /* the currently selected stream */
432 gint current_text; /* the currently selected stream */
434 gboolean do_stream_selections; /* Set to TRUE when any of current-{video|audio|text} are set to
435 say playbin should do backwards-compatibility behaviours */
437 guint64 buffer_duration; /* When buffering, the max buffer duration (ns) */
438 guint buffer_size; /* When buffering, the max buffer size (bytes) */
439 gboolean force_aspect_ratio;
441 /* Multiview/stereoscopic overrides */
442 GstVideoMultiviewFramePacking multiview_mode;
443 GstVideoMultiviewFlags multiview_flags;
446 GstPlaySink *playsink;
448 /* Task for (de)activating groups, protected by the activation lock */
449 GstTask *activation_task;
450 GRecMutex activation_lock;
452 /* lock protecting dynamic adding/removing */
454 /* if we are shutting down or not */
456 gboolean async_pending; /* async-start has been emitted */
458 gboolean have_selector; /* set to FALSE when we fail to create an
459 * input-selector, so that we only post a
462 gboolean video_pending_flush_finish; /* whether we are pending to send a custom
463 * custom-video-flush-finish event
464 * on pad activation */
465 gboolean audio_pending_flush_finish; /* whether we are pending to send a custom
466 * custom-audio-flush-finish event
467 * on pad activation */
468 gboolean text_pending_flush_finish; /* whether we are pending to send a custom
469 * custom-subtitle-flush-finish event
470 * on pad activation */
472 GstElement *audio_sink; /* configured audio sink, or NULL */
473 GstElement *video_sink; /* configured video sink, or NULL */
474 GstElement *text_sink; /* configured text sink, or NULL */
476 GstElement *audio_stream_combiner; /* configured audio stream combiner, or NULL */
477 GstElement *video_stream_combiner; /* configured video stream combiner, or NULL */
478 GstElement *text_stream_combiner; /* configured text stream combiner, or NULL */
480 guint64 ring_buffer_max_size; /* 0 means disabled */
482 gboolean is_live; /* Whether our current group is live */
484 GMutex buffering_post_lock; /* Protect serialisation of buffering messages. Must not acquire this while holding any SOURCE_GROUP lock */
487 struct _GstPlayBin3Class
489 GstPipelineClass parent_class;
491 /* notify app that the current uri finished decoding and it is possible to
492 * queue a new one for gapless playback */
493 void (*about_to_finish) (GstPlayBin3 * playbin);
495 /* get the last video sample and convert it to the given caps */
496 GstSample *(*convert_sample) (GstPlayBin3 * playbin, GstCaps * caps);
500 #define DEFAULT_URI NULL
501 #define DEFAULT_SUBURI NULL
502 #define DEFAULT_FLAGS GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_TEXT | \
503 GST_PLAY_FLAG_SOFT_VOLUME | GST_PLAY_FLAG_DEINTERLACE | \
504 GST_PLAY_FLAG_SOFT_COLORBALANCE | GST_PLAY_FLAG_BUFFERING
505 #define DEFAULT_CURRENT_VIDEO -1
506 #define DEFAULT_CURRENT_AUDIO -1
507 #define DEFAULT_CURRENT_TEXT -1
508 #define DEFAULT_SUBTITLE_ENCODING NULL
509 #define DEFAULT_AUDIO_SINK NULL
510 #define DEFAULT_VIDEO_SINK NULL
511 #define DEFAULT_VIS_PLUGIN NULL
512 #define DEFAULT_TEXT_SINK NULL
513 #define DEFAULT_VOLUME 1.0
514 #define DEFAULT_MUTE FALSE
515 #define DEFAULT_FRAME NULL
516 #define DEFAULT_FONT_DESC NULL
517 #define DEFAULT_CONNECTION_SPEED 0
518 #define DEFAULT_BUFFER_DURATION -1
519 #define DEFAULT_BUFFER_SIZE -1
520 #define DEFAULT_RING_BUFFER_MAX_SIZE 0
530 PROP_SUBTITLE_ENCODING,
535 PROP_VIDEO_STREAM_COMBINER,
536 PROP_AUDIO_STREAM_COMBINER,
537 PROP_TEXT_STREAM_COMBINER,
542 PROP_CONNECTION_SPEED,
544 PROP_BUFFER_DURATION,
547 PROP_RING_BUFFER_MAX_SIZE,
548 PROP_FORCE_ASPECT_RATIO,
558 SIGNAL_ABOUT_TO_FINISH,
559 SIGNAL_CONVERT_SAMPLE,
561 SIGNAL_ELEMENT_SETUP,
565 static void gst_play_bin3_finalize (GObject * object);
567 static void gst_play_bin3_set_property (GObject * object, guint prop_id,
568 const GValue * value, GParamSpec * spec);
569 static void gst_play_bin3_get_property (GObject * object, guint prop_id,
570 GValue * value, GParamSpec * spec);
572 static GstStateChangeReturn gst_play_bin3_change_state (GstElement * element,
573 GstStateChange transition);
575 static void gst_play_bin3_handle_message (GstBin * bin, GstMessage * message);
576 static void gst_play_bin3_deep_element_added (GstBin * playbin,
577 GstBin * sub_bin, GstElement * child);
578 static gboolean gst_play_bin3_send_event (GstElement * element,
581 static GstSample *gst_play_bin3_convert_sample (GstPlayBin3 * playbin,
584 static GstStateChangeReturn setup_next_source (GstPlayBin3 * playbin);
586 static void gst_play_bin3_check_group_status (GstPlayBin3 * playbin);
587 static void emit_about_to_finish (GstPlayBin3 * playbin);
588 static void reconfigure_output (GstPlayBin3 * playbin);
589 static void pad_removed_cb (GstElement * decodebin, GstPad * pad,
590 GstSourceGroup * group);
592 static gint select_stream_cb (GstElement * decodebin,
593 GstStreamCollection * collection, GstStream * stream,
594 GstSourceGroup * group);
596 static void do_stream_selection (GstPlayBin3 * playbin, GstSourceGroup * group);
598 static GstElementClass *parent_class;
600 static guint gst_play_bin3_signals[LAST_SIGNAL] = { 0 };
602 #define REMOVE_SIGNAL(obj,id) \
604 g_signal_handler_disconnect (obj, id); \
608 static void gst_play_bin3_overlay_init (gpointer g_iface,
609 gpointer g_iface_data);
610 static void gst_play_bin3_navigation_init (gpointer g_iface,
611 gpointer g_iface_data);
612 static void gst_play_bin3_colorbalance_init (gpointer g_iface,
613 gpointer g_iface_data);
616 _do_init_type (GType type)
618 static const GInterfaceInfo svol_info = {
621 static const GInterfaceInfo ov_info = {
622 gst_play_bin3_overlay_init,
625 static const GInterfaceInfo nav_info = {
626 gst_play_bin3_navigation_init,
629 static const GInterfaceInfo col_info = {
630 gst_play_bin3_colorbalance_init,
634 g_type_add_interface_static (type, GST_TYPE_STREAM_VOLUME, &svol_info);
635 g_type_add_interface_static (type, GST_TYPE_VIDEO_OVERLAY, &ov_info);
636 g_type_add_interface_static (type, GST_TYPE_NAVIGATION, &nav_info);
637 g_type_add_interface_static (type, GST_TYPE_COLOR_BALANCE, &col_info);
640 static GType gst_play_bin3_get_type (void);
641 G_DEFINE_TYPE_WITH_CODE (GstPlayBin3, gst_play_bin3, GST_TYPE_PIPELINE,
642 _do_init_type (g_define_type_id));
644 GST_ELEMENT_REGISTER_DEFINE_CUSTOM (playbin3,
645 gst_play_bin3_custom_element_init);
648 gst_play_bin3_class_init (GstPlayBin3Class * klass)
650 GObjectClass *gobject_klass;
651 GstElementClass *gstelement_klass;
652 GstBinClass *gstbin_klass;
654 gobject_klass = (GObjectClass *) klass;
655 gstelement_klass = (GstElementClass *) klass;
656 gstbin_klass = (GstBinClass *) klass;
658 parent_class = g_type_class_peek_parent (klass);
660 gobject_klass->set_property = gst_play_bin3_set_property;
661 gobject_klass->get_property = gst_play_bin3_get_property;
663 gobject_klass->finalize = gst_play_bin3_finalize;
668 * Set the next URI that playbin will play. This property can be set from the
669 * about-to-finish signal to queue the next media file.
671 g_object_class_install_property (gobject_klass, PROP_URI,
672 g_param_spec_string ("uri", "URI", "URI of the media to play",
673 NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
676 * GstPlayBin3:current-uri
678 * The currently playing uri.
680 g_object_class_install_property (gobject_klass, PROP_CURRENT_URI,
681 g_param_spec_string ("current-uri", "Current URI",
682 "The currently playing URI", NULL,
683 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
688 * Set the next subtitle URI that playbin will play. This property can be
689 * set from the about-to-finish signal to queue the next subtitle media file.
691 g_object_class_install_property (gobject_klass, PROP_SUBURI,
692 g_param_spec_string ("suburi", ".sub-URI", "Optional URI of a subtitle",
693 NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
696 * GstPlayBin3:current-suburi
698 * The currently playing subtitle uri.
700 g_object_class_install_property (gobject_klass, PROP_CURRENT_SUBURI,
701 g_param_spec_string ("current-suburi", "Current .sub-URI",
702 "The currently playing URI of a subtitle",
703 NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
708 * Control the behaviour of playbin.
710 g_object_class_install_property (gobject_klass, PROP_FLAGS,
711 g_param_spec_flags ("flags", "Flags", "Flags to control behaviour",
712 GST_TYPE_PLAY_FLAGS, DEFAULT_FLAGS,
713 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
715 g_object_class_install_property (gobject_klass, PROP_SUBTITLE_ENCODING,
716 g_param_spec_string ("subtitle-encoding", "subtitle encoding",
717 "Encoding to assume if input subtitles are not in UTF-8 encoding. "
718 "If not set, the GST_SUBTITLE_ENCODING environment variable will "
719 "be checked for an encoding to use. If that is not set either, "
720 "ISO-8859-15 will be assumed.", NULL,
721 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
723 g_object_class_install_property (gobject_klass, PROP_VIDEO_FILTER,
724 g_param_spec_object ("video-filter", "Video filter",
725 "the video filter(s) to apply, if possible",
726 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
727 g_object_class_install_property (gobject_klass, PROP_AUDIO_FILTER,
728 g_param_spec_object ("audio-filter", "Audio filter",
729 "the audio filter(s) to apply, if possible",
730 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
732 * GstPlayBin3:video-sink
734 * Get or set the video sink to use for video output. If set to
735 * NULL, one will be auto-selected. To disable video entirely, unset
736 * the VIDEO flag in the #GstPlayBin3:flags property.
739 g_object_class_install_property (gobject_klass, PROP_VIDEO_SINK,
740 g_param_spec_object ("video-sink", "Video Sink",
741 "the video output element to use (NULL = default sink)",
742 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
744 * GstPlayBin3:audio-sink
746 * Get or set the audio sink to use for audio output. If set to
747 * NULL, one will be auto-selected. To disable audio entirely, unset
748 * the AUDIO flag in the #GstPlayBin3:flags property.
751 g_object_class_install_property (gobject_klass, PROP_AUDIO_SINK,
752 g_param_spec_object ("audio-sink", "Audio Sink",
753 "the audio output element to use (NULL = default sink)",
754 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
755 g_object_class_install_property (gobject_klass, PROP_VIS_PLUGIN,
756 g_param_spec_object ("vis-plugin", "Vis plugin",
757 "the visualization element to use (NULL = default)",
758 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
759 g_object_class_install_property (gobject_klass, PROP_TEXT_SINK,
760 g_param_spec_object ("text-sink", "Text plugin",
761 "the text output element to use (NULL = default subtitleoverlay)",
762 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
764 * GstPlayBin3:video-stream-combiner
766 * Get or set the current video stream combiner. By default, no
767 * element is used and the selected stream is used directly.
769 g_object_class_install_property (gobject_klass, PROP_VIDEO_STREAM_COMBINER,
770 g_param_spec_object ("video-stream-combiner", "Video stream combiner",
771 "Current video stream combiner (default: none)",
772 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
775 * GstPlayBin3:audio-stream-combiner
777 * Get or set the current audio stream combiner. By default, no
778 * element is used and the selected stream is used directly.
780 g_object_class_install_property (gobject_klass, PROP_AUDIO_STREAM_COMBINER,
781 g_param_spec_object ("audio-stream-combiner", "Audio stream combiner",
782 "Current audio stream combiner (default: none))",
783 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
786 * GstPlayBin3:text-stream-combiner
788 * Get or set the current text stream combiner. By default, no
789 * element is used and the selected stream is used directly.
791 g_object_class_install_property (gobject_klass, PROP_TEXT_STREAM_COMBINER,
792 g_param_spec_object ("text-stream-combiner", "Text stream combiner",
793 "Current text stream combiner (default: none)",
794 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
797 * GstPlayBin3:volume:
799 * Get or set the current audio stream volume. 1.0 means 100%,
800 * 0.0 means mute. This uses a linear volume scale.
803 g_object_class_install_property (gobject_klass, PROP_VOLUME,
804 g_param_spec_double ("volume", "Volume", "The audio volume, 1.0=100%",
805 0.0, VOLUME_MAX_DOUBLE, 1.0,
806 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
807 g_object_class_install_property (gobject_klass, PROP_MUTE,
808 g_param_spec_boolean ("mute", "Mute",
809 "Mute the audio channel without changing the volume", FALSE,
810 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
813 * GstPlayBin3:sample:
814 * @playbin: a #GstPlayBin3
816 * Get the currently rendered or prerolled sample in the video sink.
817 * The #GstCaps in the sample will describe the format of the buffer.
819 g_object_class_install_property (gobject_klass, PROP_SAMPLE,
820 g_param_spec_boxed ("sample", "Sample",
821 "The last sample (NULL = no video available)",
822 GST_TYPE_SAMPLE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
824 g_object_class_install_property (gobject_klass, PROP_FONT_DESC,
825 g_param_spec_string ("subtitle-font-desc",
826 "Subtitle font description",
827 "Pango font description of font "
828 "to be used for subtitle rendering", NULL,
829 G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
831 g_object_class_install_property (gobject_klass, PROP_CONNECTION_SPEED,
832 g_param_spec_uint64 ("connection-speed", "Connection Speed",
833 "Network connection speed in kbps (0 = unknown)",
834 0, G_MAXUINT64 / 1000, DEFAULT_CONNECTION_SPEED,
835 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
837 g_object_class_install_property (gobject_klass, PROP_BUFFER_SIZE,
838 g_param_spec_int ("buffer-size", "Buffer size (bytes)",
839 "Buffer size when buffering network streams",
840 -1, G_MAXINT, DEFAULT_BUFFER_SIZE,
841 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
842 g_object_class_install_property (gobject_klass, PROP_BUFFER_DURATION,
843 g_param_spec_int64 ("buffer-duration", "Buffer duration (ns)",
844 "Buffer duration when buffering network streams",
845 -1, G_MAXINT64, DEFAULT_BUFFER_DURATION,
846 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
848 * GstPlayBin3:av-offset:
850 * Control the synchronisation offset between the audio and video streams.
851 * Positive values make the audio ahead of the video and negative values make
852 * the audio go behind the video.
854 g_object_class_install_property (gobject_klass, PROP_AV_OFFSET,
855 g_param_spec_int64 ("av-offset", "AV Offset",
856 "The synchronisation offset between audio and video in nanoseconds",
857 G_MININT64, G_MAXINT64, 0,
858 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
860 * GstPlayBin3:text-offset:
862 * Control the synchronisation offset between the text and video streams.
863 * Positive values make the text ahead of the video and negative values make
864 * the text go behind the video.
866 g_object_class_install_property (gobject_klass, PROP_TEXT_OFFSET,
867 g_param_spec_int64 ("text-offset", "Text Offset",
868 "The synchronisation offset between text and video in nanoseconds",
869 G_MININT64, G_MAXINT64, 0,
870 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
873 * GstPlayBin3:ring-buffer-max-size
875 * The maximum size of the ring buffer in bytes. If set to 0, the ring
876 * buffer is disabled. Default 0.
878 g_object_class_install_property (gobject_klass, PROP_RING_BUFFER_MAX_SIZE,
879 g_param_spec_uint64 ("ring-buffer-max-size",
880 "Max. ring buffer size (bytes)",
881 "Max. amount of data in the ring buffer (bytes, 0 = ring buffer disabled)",
882 0, G_MAXUINT, DEFAULT_RING_BUFFER_MAX_SIZE,
883 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
886 * GstPlayBin3::force-aspect-ratio:
888 * Requests the video sink to enforce the video display aspect ratio.
890 g_object_class_install_property (gobject_klass, PROP_FORCE_ASPECT_RATIO,
891 g_param_spec_boolean ("force-aspect-ratio", "Force Aspect Ratio",
892 "When enabled, scaling will respect original aspect ratio", TRUE,
893 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
896 * GstPlayBin3::video-multiview-mode:
898 * Set the stereoscopic mode for video streams that don't contain
899 * any information in the stream, so they can be correctly played
900 * as 3D streams. If a video already has multiview information
901 * encoded, this property can override other modes in the set,
902 * but cannot be used to re-interpret MVC or mixed-mono streams.
904 * See Also: The #GstPlayBin3::video-multiview-flags property
907 g_object_class_install_property (gobject_klass, PROP_MULTIVIEW_MODE,
908 g_param_spec_enum ("video-multiview-mode",
909 "Multiview Mode Override",
910 "Re-interpret a video stream as one of several frame-packed stereoscopic modes.",
911 GST_TYPE_VIDEO_MULTIVIEW_FRAME_PACKING,
912 GST_VIDEO_MULTIVIEW_FRAME_PACKING_NONE,
913 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
916 * GstPlayBin3::video-multiview-flags:
918 * When overriding the multiview mode of an input stream,
919 * these flags modify details of the view layout.
921 * See Also: The #GstPlayBin3::video-multiview-mode property
923 g_object_class_install_property (gobject_klass, PROP_MULTIVIEW_FLAGS,
924 g_param_spec_flags ("video-multiview-flags",
925 "Multiview Flags Override",
926 "Override details of the multiview frame layout",
927 GST_TYPE_VIDEO_MULTIVIEW_FLAGS, GST_VIDEO_MULTIVIEW_FLAGS_NONE,
928 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
931 * GstPlayBin3::about-to-finish
932 * @playbin: a #GstPlayBin3
934 * This signal is emitted when the current uri is about to finish. You can
935 * set the uri and suburi to make sure that playback continues.
937 * This signal is emitted from the context of a GStreamer streaming thread.
939 gst_play_bin3_signals[SIGNAL_ABOUT_TO_FINISH] =
940 g_signal_new ("about-to-finish", G_TYPE_FROM_CLASS (klass),
942 G_STRUCT_OFFSET (GstPlayBin3Class, about_to_finish), NULL, NULL,
943 NULL, G_TYPE_NONE, 0, G_TYPE_NONE);
947 * GstPlayBin3::source-setup:
948 * @playbin: a #GstPlayBin3
949 * @source: source element
951 * This signal is emitted after the source element has been created, so
952 * it can be configured by setting additional properties (e.g. set a
953 * proxy server for an http source, or set the device and read speed for
954 * an audio cd source). This is functionally equivalent to connecting to
955 * the notify::source signal, but more convenient.
957 * This signal is usually emitted from the context of a GStreamer streaming
960 gst_play_bin3_signals[SIGNAL_SOURCE_SETUP] =
961 g_signal_new ("source-setup", G_TYPE_FROM_CLASS (klass),
962 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
965 * GstPlayBin3::element-setup:
966 * @playbin: a #GstPlayBin3
967 * @element: an element that was added to the playbin hierarchy
969 * This signal is emitted when a new element is added to playbin or any of
970 * its sub-bins. This signal can be used to configure elements, e.g. to set
971 * properties on decoders. This is functionally equivalent to connecting to
972 * the deep-element-added signal, but more convenient.
974 * This signal is usually emitted from the context of a GStreamer streaming
975 * thread, so might be called at the same time as code running in the main
976 * application thread.
980 gst_play_bin3_signals[SIGNAL_ELEMENT_SETUP] =
981 g_signal_new ("element-setup", G_TYPE_FROM_CLASS (klass),
982 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
985 * GstPlayBin3::convert-sample
986 * @playbin: a #GstPlayBin3
987 * @caps: the target format of the frame
989 * Action signal to retrieve the currently playing video frame in the format
990 * specified by @caps.
991 * If @caps is %NULL, no conversion will be performed and this function is
992 * equivalent to the #GstPlayBin3:sample property.
994 * Returns: a #GstSample of the current video frame converted to #caps.
995 * The caps on the sample will describe the final layout of the buffer data.
996 * %NULL is returned when no current buffer can be retrieved or when the
999 gst_play_bin3_signals[SIGNAL_CONVERT_SAMPLE] =
1000 g_signal_new ("convert-sample", G_TYPE_FROM_CLASS (klass),
1001 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1002 G_STRUCT_OFFSET (GstPlayBin3Class, convert_sample), NULL, NULL,
1003 NULL, GST_TYPE_SAMPLE, 1, GST_TYPE_CAPS);
1005 klass->convert_sample = gst_play_bin3_convert_sample;
1007 gst_element_class_set_static_metadata (gstelement_klass,
1008 "Player Bin 3", "Generic/Bin/Player",
1009 "Autoplug and play media from an uri",
1010 "Wim Taymans <wim.taymans@gmail.com>");
1012 gstelement_klass->change_state =
1013 GST_DEBUG_FUNCPTR (gst_play_bin3_change_state);
1014 gstelement_klass->send_event = GST_DEBUG_FUNCPTR (gst_play_bin3_send_event);
1016 gstbin_klass->handle_message =
1017 GST_DEBUG_FUNCPTR (gst_play_bin3_handle_message);
1018 gstbin_klass->deep_element_added =
1019 GST_DEBUG_FUNCPTR (gst_play_bin3_deep_element_added);
1023 do_async_start (GstPlayBin3 * playbin)
1025 GstMessage *message;
1027 playbin->async_pending = TRUE;
1029 message = gst_message_new_async_start (GST_OBJECT_CAST (playbin));
1030 GST_BIN_CLASS (parent_class)->handle_message (GST_BIN_CAST (playbin),
1035 do_async_done (GstPlayBin3 * playbin)
1037 GstMessage *message;
1039 if (playbin->async_pending) {
1040 GST_DEBUG_OBJECT (playbin, "posting ASYNC_DONE");
1042 gst_message_new_async_done (GST_OBJECT_CAST (playbin),
1043 GST_CLOCK_TIME_NONE);
1044 GST_BIN_CLASS (parent_class)->handle_message (GST_BIN_CAST (playbin),
1047 playbin->async_pending = FALSE;
1051 /* init combiners. The combiner is found by finding the first prefix that
1052 * matches the media. */
1054 init_combiners (GstPlayBin3 * playbin)
1056 playbin->combiner[PLAYBIN_STREAM_AUDIO].stream_type = GST_STREAM_TYPE_AUDIO;
1057 playbin->combiner[PLAYBIN_STREAM_AUDIO].inputpads =
1058 g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
1059 playbin->combiner[PLAYBIN_STREAM_AUDIO].streams =
1060 g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
1062 playbin->combiner[PLAYBIN_STREAM_VIDEO].stream_type = GST_STREAM_TYPE_VIDEO;
1063 playbin->combiner[PLAYBIN_STREAM_VIDEO].inputpads =
1064 g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
1065 playbin->combiner[PLAYBIN_STREAM_VIDEO].streams =
1066 g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
1068 playbin->combiner[PLAYBIN_STREAM_TEXT].stream_type = GST_STREAM_TYPE_TEXT;
1069 playbin->combiner[PLAYBIN_STREAM_TEXT].inputpads =
1070 g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
1071 playbin->combiner[PLAYBIN_STREAM_TEXT].streams =
1072 g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
1075 /* Update the combiner information to be in sync with the current collection
1077 * FIXME : "current" collection doesn't mean anything until we have a "combined"
1078 * collection of all groups */
1080 update_combiner_info (GstPlayBin3 * playbin, GstStreamCollection * collection)
1084 if (collection == NULL)
1087 GST_DEBUG_OBJECT (playbin, "Updating combiner info");
1089 /* Wipe current combiner streams */
1090 g_ptr_array_free (playbin->combiner[PLAYBIN_STREAM_AUDIO].streams, TRUE);
1091 g_ptr_array_free (playbin->combiner[PLAYBIN_STREAM_VIDEO].streams, TRUE);
1092 g_ptr_array_free (playbin->combiner[PLAYBIN_STREAM_TEXT].streams, TRUE);
1093 playbin->combiner[PLAYBIN_STREAM_AUDIO].streams =
1094 g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
1095 playbin->combiner[PLAYBIN_STREAM_VIDEO].streams =
1096 g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
1097 playbin->combiner[PLAYBIN_STREAM_TEXT].streams =
1098 g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
1100 len = gst_stream_collection_get_size (collection);
1101 for (i = 0; i < len; i++) {
1102 GstStream *stream = gst_stream_collection_get_stream (collection, i);
1103 GstStreamType stype = gst_stream_get_stream_type (stream);
1105 if (stype & GST_STREAM_TYPE_AUDIO) {
1106 g_ptr_array_add (playbin->combiner[PLAYBIN_STREAM_AUDIO].streams,
1107 gst_object_ref (stream));
1108 } else if (stype & GST_STREAM_TYPE_VIDEO) {
1109 g_ptr_array_add (playbin->combiner[PLAYBIN_STREAM_VIDEO].streams,
1110 gst_object_ref (stream));
1111 } else if (stype & GST_STREAM_TYPE_TEXT) {
1112 g_ptr_array_add (playbin->combiner[PLAYBIN_STREAM_TEXT].streams,
1113 gst_object_ref (stream));
1117 GST_DEBUG_OBJECT (playbin, "There are %d audio streams",
1118 playbin->combiner[PLAYBIN_STREAM_AUDIO].streams->len);
1119 GST_DEBUG_OBJECT (playbin, "There are %d video streams",
1120 playbin->combiner[PLAYBIN_STREAM_VIDEO].streams->len);
1121 GST_DEBUG_OBJECT (playbin, "There are %d text streams",
1122 playbin->combiner[PLAYBIN_STREAM_TEXT].streams->len);
1125 #ifndef GST_DISABLE_GST_DEBUG
1126 #define debug_groups(playbin) G_STMT_START { \
1129 for (i = 0; i < 2; i++) { \
1130 GstSourceGroup *group = &playbin->groups[i]; \
1132 GST_DEBUG ("GstSourceGroup #%d (%s) : %s", i, (group == playbin->curr_group) ? "current" : (group == playbin->next_group) ? "next" : "unused", \
1133 group->uridecodebin ? GST_ELEMENT_NAME (group->uridecodebin) : "NULL" ); \
1134 GST_DEBUG (" valid:%d , active:%d , playing:%d", group->valid, group->active, group->playing); \
1135 GST_DEBUG (" uri:%s", group->uri); \
1136 GST_DEBUG (" suburi:%s", group->suburi); \
1137 GST_DEBUG (" group_id:%d", group->group_id); \
1138 GST_DEBUG (" pending_about_to_finish:%d", group->pending_about_to_finish); \
1142 #define debug_groups(p) {}
1146 init_group (GstPlayBin3 * playbin, GstSourceGroup * group)
1148 g_mutex_init (&group->lock);
1150 group->stream_changed_pending = FALSE;
1151 group->group_id = GST_GROUP_ID_INVALID;
1153 group->playbin = playbin;
1157 free_group (GstPlayBin3 * playbin, GstSourceGroup * group)
1159 g_free (group->uri);
1160 g_free (group->suburi);
1162 g_mutex_clear (&group->lock);
1163 group->stream_changed_pending = FALSE;
1165 if (group->pending_buffering_msg)
1166 gst_message_unref (group->pending_buffering_msg);
1167 group->pending_buffering_msg = NULL;
1169 gst_object_replace ((GstObject **) & group->collection, NULL);
1171 gst_object_replace ((GstObject **) & group->audio_sink, NULL);
1172 gst_object_replace ((GstObject **) & group->video_sink, NULL);
1173 gst_object_replace ((GstObject **) & group->text_sink, NULL);
1177 notify_volume_cb (GObject * combiner, GParamSpec * pspec, GstPlayBin3 * playbin)
1179 g_object_notify (G_OBJECT (playbin), "volume");
1183 notify_mute_cb (GObject * combiner, GParamSpec * pspec, GstPlayBin3 * playbin)
1185 g_object_notify (G_OBJECT (playbin), "mute");
1189 colorbalance_value_changed_cb (GstColorBalance * balance,
1190 GstColorBalanceChannel * channel, gint value, GstPlayBin3 * playbin)
1192 gst_color_balance_value_changed (GST_COLOR_BALANCE (playbin), channel, value);
1196 gst_play_bin3_init (GstPlayBin3 * playbin)
1198 g_rec_mutex_init (&playbin->lock);
1199 g_mutex_init (&playbin->dyn_lock);
1201 g_mutex_init (&playbin->buffering_post_lock);
1203 /* assume we can create an input-selector */
1204 playbin->have_selector = TRUE;
1206 init_combiners (playbin);
1209 playbin->curr_group = &playbin->groups[0];
1210 playbin->next_group = &playbin->groups[1];
1211 init_group (playbin, &playbin->groups[0]);
1212 init_group (playbin, &playbin->groups[1]);
1214 g_rec_mutex_init (&playbin->activation_lock);
1218 g_object_new (GST_TYPE_PLAY_SINK, "name", "playsink", "send-event-mode",
1220 gst_bin_add (GST_BIN_CAST (playbin), GST_ELEMENT_CAST (playbin->playsink));
1221 gst_play_sink_set_flags (playbin->playsink, DEFAULT_FLAGS);
1222 /* Connect to notify::volume and notify::mute signals for proxying */
1223 g_signal_connect (playbin->playsink, "notify::volume",
1224 G_CALLBACK (notify_volume_cb), playbin);
1225 g_signal_connect (playbin->playsink, "notify::mute",
1226 G_CALLBACK (notify_mute_cb), playbin);
1227 g_signal_connect (playbin->playsink, "value-changed",
1228 G_CALLBACK (colorbalance_value_changed_cb), playbin);
1230 playbin->current_video = DEFAULT_CURRENT_VIDEO;
1231 playbin->current_audio = DEFAULT_CURRENT_AUDIO;
1232 playbin->current_text = DEFAULT_CURRENT_TEXT;
1234 playbin->buffer_duration = DEFAULT_BUFFER_DURATION;
1235 playbin->buffer_size = DEFAULT_BUFFER_SIZE;
1236 playbin->ring_buffer_max_size = DEFAULT_RING_BUFFER_MAX_SIZE;
1238 playbin->force_aspect_ratio = TRUE;
1240 playbin->multiview_mode = GST_VIDEO_MULTIVIEW_FRAME_PACKING_NONE;
1241 playbin->multiview_flags = GST_VIDEO_MULTIVIEW_FLAGS_NONE;
1243 playbin->is_live = FALSE;
1247 gst_play_bin3_finalize (GObject * object)
1249 GstPlayBin3 *playbin;
1251 playbin = GST_PLAY_BIN3 (object);
1253 free_group (playbin, &playbin->groups[0]);
1254 free_group (playbin, &playbin->groups[1]);
1256 /* Setting states to NULL is safe here because playsink
1257 * will already be gone and none of these sinks will be
1258 * a child of playsink
1260 if (playbin->video_sink) {
1261 gst_element_set_state (playbin->video_sink, GST_STATE_NULL);
1262 gst_object_unref (playbin->video_sink);
1264 if (playbin->audio_sink) {
1265 gst_element_set_state (playbin->audio_sink, GST_STATE_NULL);
1266 gst_object_unref (playbin->audio_sink);
1268 if (playbin->text_sink) {
1269 gst_element_set_state (playbin->text_sink, GST_STATE_NULL);
1270 gst_object_unref (playbin->text_sink);
1273 if (playbin->video_stream_combiner) {
1274 gst_element_set_state (playbin->video_stream_combiner, GST_STATE_NULL);
1275 gst_object_unref (playbin->video_stream_combiner);
1277 if (playbin->audio_stream_combiner) {
1278 gst_element_set_state (playbin->audio_stream_combiner, GST_STATE_NULL);
1279 gst_object_unref (playbin->audio_stream_combiner);
1281 if (playbin->text_stream_combiner) {
1282 gst_element_set_state (playbin->text_stream_combiner, GST_STATE_NULL);
1283 gst_object_unref (playbin->text_stream_combiner);
1286 g_ptr_array_free (playbin->combiner[PLAYBIN_STREAM_AUDIO].streams, TRUE);
1287 g_ptr_array_free (playbin->combiner[PLAYBIN_STREAM_AUDIO].inputpads, TRUE);
1288 g_ptr_array_free (playbin->combiner[PLAYBIN_STREAM_VIDEO].streams, TRUE);
1289 g_ptr_array_free (playbin->combiner[PLAYBIN_STREAM_VIDEO].inputpads, TRUE);
1290 g_ptr_array_free (playbin->combiner[PLAYBIN_STREAM_TEXT].streams, TRUE);
1291 g_ptr_array_free (playbin->combiner[PLAYBIN_STREAM_TEXT].inputpads, TRUE);
1293 g_rec_mutex_clear (&playbin->activation_lock);
1294 g_rec_mutex_clear (&playbin->lock);
1296 g_mutex_clear (&playbin->buffering_post_lock);
1297 g_mutex_clear (&playbin->dyn_lock);
1299 G_OBJECT_CLASS (parent_class)->finalize (object);
1303 gst_playbin_uri_is_valid (GstPlayBin3 * playbin, const gchar * uri)
1307 GST_LOG_OBJECT (playbin, "checking uri '%s'", uri);
1309 /* this just checks the protocol */
1310 if (!gst_uri_is_valid (uri))
1313 for (c = uri; *c != '\0'; ++c) {
1314 if (!g_ascii_isprint (*c))
1324 GST_WARNING_OBJECT (playbin, "uri '%s' not valid, character #%u",
1325 uri, (guint) ((guintptr) c - (guintptr) uri));
1331 gst_play_bin3_set_uri (GstPlayBin3 * playbin, const gchar * uri)
1333 GstSourceGroup *group;
1335 if (uri && !gst_playbin_uri_is_valid (playbin, uri)) {
1336 if (g_str_has_prefix (uri, "file:")) {
1337 GST_WARNING_OBJECT (playbin, "not entirely correct file URI '%s' - make "
1338 "sure to escape spaces and non-ASCII characters properly and specify "
1339 "an absolute path. Use gst_filename_to_uri() to convert filenames "
1342 /* GST_ERROR_OBJECT (playbin, "malformed URI '%s'", uri); */
1346 GST_PLAY_BIN3_LOCK (playbin);
1347 group = playbin->next_group;
1349 GST_SOURCE_GROUP_LOCK (group);
1350 /* store the uri in the next group we will play */
1351 g_free (group->uri);
1353 group->uri = g_strdup (uri);
1354 group->valid = TRUE;
1357 group->valid = FALSE;
1359 GST_SOURCE_GROUP_UNLOCK (group);
1361 GST_DEBUG ("set new uri to %s", GST_STR_NULL (uri));
1362 GST_PLAY_BIN3_UNLOCK (playbin);
1366 gst_play_bin3_set_suburi (GstPlayBin3 * playbin, const gchar * suburi)
1368 GstSourceGroup *group;
1370 GST_PLAY_BIN3_LOCK (playbin);
1371 group = playbin->next_group;
1373 GST_SOURCE_GROUP_LOCK (group);
1374 g_free (group->suburi);
1375 group->suburi = g_strdup (suburi);
1376 GST_SOURCE_GROUP_UNLOCK (group);
1378 GST_DEBUG ("setting new .sub uri to %s", suburi);
1380 GST_PLAY_BIN3_UNLOCK (playbin);
1384 gst_play_bin3_set_flags (GstPlayBin3 * playbin, GstPlayFlags flags)
1386 GstPlayFlags old_flags;
1387 old_flags = gst_play_sink_get_flags (playbin->playsink);
1389 if (flags != old_flags) {
1390 gst_play_sink_set_flags (playbin->playsink, flags);
1391 gst_play_sink_reconfigure (playbin->playsink);
1396 gst_play_bin3_get_flags (GstPlayBin3 * playbin)
1400 flags = gst_play_sink_get_flags (playbin->playsink);
1405 /* get the currently playing group or if nothing is playing, the next
1406 * group. Must be called with the PLAY_BIN_LOCK. */
1407 static GstSourceGroup *
1408 get_group (GstPlayBin3 * playbin)
1410 GstSourceGroup *result;
1412 if (!(result = playbin->curr_group))
1413 result = playbin->next_group;
1420 gst_play_bin3_convert_sample (GstPlayBin3 * playbin, GstCaps * caps)
1422 return gst_play_sink_convert_sample (playbin->playsink, caps);
1426 gst_play_bin3_send_custom_event (GstObject * combiner, const gchar * event_name)
1432 gboolean ret = FALSE;
1434 src = gst_element_get_static_pad (GST_ELEMENT_CAST (combiner), "src");
1435 peer = gst_pad_get_peer (src);
1437 s = gst_structure_new_empty (event_name);
1438 event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_OOB, s);
1439 gst_pad_send_event (peer, event);
1440 gst_object_unref (peer);
1443 gst_object_unref (src);
1448 gst_play_bin3_set_current_stream (GstPlayBin3 * playbin,
1449 gint stream_type, gint * current_value, gint stream,
1450 gboolean * flush_marker)
1452 GstSourceCombine *combine;
1455 GST_PLAY_BIN3_LOCK (playbin);
1456 /* This function is only called if the app sets
1457 * one of the current-* properties, which means it doesn't
1458 * handle collections or select-streams yet */
1459 playbin->do_stream_selections = TRUE;
1461 combine = playbin->combiner + stream_type;
1463 GST_DEBUG_OBJECT (playbin, "Changing current %s stream %d -> %d",
1464 stream_type_names[stream_type], *current_value, stream);
1466 if (combine->combiner == NULL || combine->is_concat) {
1467 /* FIXME: Check that the current_value is within range */
1468 *current_value = stream;
1469 do_stream_selection (playbin, playbin->curr_group);
1470 GST_PLAY_BIN3_UNLOCK (playbin);
1474 GST_DEBUG_OBJECT (playbin, "Using old style combiner");
1476 if (!combine->has_active_pad)
1478 if (combine->inputpads == NULL)
1481 if (stream == -1 || combine->inputpads->len <= stream) {
1484 /* take combiner sink pad for selected stream */
1485 sinkpad = g_ptr_array_index (combine->inputpads, stream);
1489 gst_object_ref (sinkpad);
1490 GST_PLAY_BIN3_UNLOCK (playbin);
1493 GstObject *combiner;
1495 if ((combiner = gst_pad_get_parent (sinkpad))) {
1496 GstPad *old_sinkpad;
1498 g_object_get (combiner, "active-pad", &old_sinkpad, NULL);
1500 if (old_sinkpad != sinkpad) {
1501 /* FIXME: Is there actually any reason playsink
1502 * needs special names for each type of stream we flush? */
1503 gchar *flush_event_name = g_strdup_printf ("playsink-custom-%s-flush",
1504 stream_type_names[stream_type]);
1505 if (gst_play_bin3_send_custom_event (combiner, flush_event_name))
1506 *flush_marker = TRUE;
1507 g_free (flush_event_name);
1509 /* activate the selected pad */
1510 g_object_set (combiner, "active-pad", sinkpad, NULL);
1514 gst_object_unref (old_sinkpad);
1516 gst_object_unref (combiner);
1518 gst_object_unref (sinkpad);
1524 GST_PLAY_BIN3_UNLOCK (playbin);
1525 GST_WARNING_OBJECT (playbin,
1526 "can't switch %s, the stream combiner's sink pads don't have the \"active-pad\" property",
1527 stream_type_names[stream_type]);
1532 GST_PLAY_BIN3_UNLOCK (playbin);
1533 GST_DEBUG_OBJECT (playbin,
1534 "can't switch stream, we have no combiner input pad");
1540 gst_play_bin3_set_current_video_stream (GstPlayBin3 * playbin, gint stream)
1542 return gst_play_bin3_set_current_stream (playbin, PLAYBIN_STREAM_VIDEO,
1543 &playbin->current_video, stream, &playbin->video_pending_flush_finish);
1547 gst_play_bin3_set_current_audio_stream (GstPlayBin3 * playbin, gint stream)
1549 return gst_play_bin3_set_current_stream (playbin, PLAYBIN_STREAM_AUDIO,
1550 &playbin->current_audio, stream, &playbin->audio_pending_flush_finish);
1554 gst_play_bin3_set_current_text_stream (GstPlayBin3 * playbin, gint stream)
1556 return gst_play_bin3_set_current_stream (playbin, PLAYBIN_STREAM_TEXT,
1557 &playbin->current_text, stream, &playbin->text_pending_flush_finish);
1562 gst_play_bin3_set_sink (GstPlayBin3 * playbin, GstPlaySinkType type,
1563 const gchar * dbg, GstElement ** elem, GstElement * sink)
1565 GST_INFO_OBJECT (playbin, "Setting %s sink to %" GST_PTR_FORMAT, dbg, sink);
1567 gst_play_sink_set_sink (playbin->playsink, type, sink);
1570 gst_object_unref (*elem);
1571 *elem = sink ? gst_object_ref (sink) : NULL;
1575 gst_play_bin3_set_stream_combiner (GstPlayBin3 * playbin, GstElement ** elem,
1576 const gchar * dbg, GstElement * combiner)
1578 GST_INFO_OBJECT (playbin, "Setting %s stream combiner to %" GST_PTR_FORMAT,
1581 GST_PLAY_BIN3_LOCK (playbin);
1582 if (*elem != combiner) {
1587 gst_object_ref_sink (combiner);
1591 gst_object_unref (old);
1593 GST_LOG_OBJECT (playbin, "%s stream combiner now %" GST_PTR_FORMAT, dbg,
1595 GST_PLAY_BIN3_UNLOCK (playbin);
1599 gst_play_bin3_set_encoding (GstPlayBin3 * playbin, const gchar * encoding)
1601 GST_PLAY_BIN3_LOCK (playbin);
1602 gst_play_sink_set_subtitle_encoding (playbin->playsink, encoding);
1603 GST_PLAY_BIN3_UNLOCK (playbin);
1607 gst_play_bin3_set_property (GObject * object, guint prop_id,
1608 const GValue * value, GParamSpec * pspec)
1610 GstPlayBin3 *playbin = GST_PLAY_BIN3 (object);
1614 gst_play_bin3_set_uri (playbin, g_value_get_string (value));
1617 gst_play_bin3_set_suburi (playbin, g_value_get_string (value));
1620 gst_play_bin3_set_flags (playbin, g_value_get_flags (value));
1621 if (playbin->curr_group) {
1622 GST_SOURCE_GROUP_LOCK (playbin->curr_group);
1623 if (playbin->curr_group->uridecodebin) {
1624 g_object_set (playbin->curr_group->uridecodebin, "download",
1625 (g_value_get_flags (value) & GST_PLAY_FLAG_DOWNLOAD) != 0, NULL);
1627 GST_SOURCE_GROUP_UNLOCK (playbin->curr_group);
1630 case PROP_SUBTITLE_ENCODING:
1631 gst_play_bin3_set_encoding (playbin, g_value_get_string (value));
1633 case PROP_VIDEO_FILTER:
1634 gst_play_sink_set_filter (playbin->playsink, GST_PLAY_SINK_TYPE_VIDEO,
1635 GST_ELEMENT (g_value_get_object (value)));
1637 case PROP_AUDIO_FILTER:
1638 gst_play_sink_set_filter (playbin->playsink, GST_PLAY_SINK_TYPE_AUDIO,
1639 GST_ELEMENT (g_value_get_object (value)));
1641 case PROP_VIDEO_SINK:
1642 gst_play_bin3_set_sink (playbin, GST_PLAY_SINK_TYPE_VIDEO, "video",
1643 &playbin->video_sink, g_value_get_object (value));
1645 case PROP_AUDIO_SINK:
1646 gst_play_bin3_set_sink (playbin, GST_PLAY_SINK_TYPE_AUDIO, "audio",
1647 &playbin->audio_sink, g_value_get_object (value));
1649 case PROP_VIS_PLUGIN:
1650 gst_play_sink_set_vis_plugin (playbin->playsink,
1651 g_value_get_object (value));
1653 case PROP_TEXT_SINK:
1654 gst_play_bin3_set_sink (playbin, GST_PLAY_SINK_TYPE_TEXT, "text",
1655 &playbin->text_sink, g_value_get_object (value));
1657 case PROP_VIDEO_STREAM_COMBINER:
1658 gst_play_bin3_set_stream_combiner (playbin,
1659 &playbin->video_stream_combiner, "video", g_value_get_object (value));
1661 case PROP_AUDIO_STREAM_COMBINER:
1662 gst_play_bin3_set_stream_combiner (playbin,
1663 &playbin->audio_stream_combiner, "audio", g_value_get_object (value));
1665 case PROP_TEXT_STREAM_COMBINER:
1666 gst_play_bin3_set_stream_combiner (playbin,
1667 &playbin->text_stream_combiner, "text", g_value_get_object (value));
1670 gst_play_sink_set_volume (playbin->playsink, g_value_get_double (value));
1673 gst_play_sink_set_mute (playbin->playsink, g_value_get_boolean (value));
1675 case PROP_FONT_DESC:
1676 gst_play_sink_set_font_desc (playbin->playsink,
1677 g_value_get_string (value));
1679 case PROP_CONNECTION_SPEED:
1680 GST_PLAY_BIN3_LOCK (playbin);
1681 playbin->connection_speed = g_value_get_uint64 (value) * 1000;
1682 GST_PLAY_BIN3_UNLOCK (playbin);
1684 case PROP_BUFFER_SIZE:
1685 playbin->buffer_size = g_value_get_int (value);
1687 case PROP_BUFFER_DURATION:
1688 playbin->buffer_duration = g_value_get_int64 (value);
1690 case PROP_AV_OFFSET:
1691 gst_play_sink_set_av_offset (playbin->playsink,
1692 g_value_get_int64 (value));
1694 case PROP_TEXT_OFFSET:
1695 gst_play_sink_set_text_offset (playbin->playsink,
1696 g_value_get_int64 (value));
1698 case PROP_RING_BUFFER_MAX_SIZE:
1699 playbin->ring_buffer_max_size = g_value_get_uint64 (value);
1700 if (playbin->curr_group) {
1701 GST_SOURCE_GROUP_LOCK (playbin->curr_group);
1702 if (playbin->curr_group->uridecodebin) {
1703 g_object_set (playbin->curr_group->uridecodebin,
1704 "ring-buffer-max-size", playbin->ring_buffer_max_size, NULL);
1706 GST_SOURCE_GROUP_UNLOCK (playbin->curr_group);
1709 case PROP_FORCE_ASPECT_RATIO:
1710 g_object_set (playbin->playsink, "force-aspect-ratio",
1711 g_value_get_boolean (value), NULL);
1713 case PROP_MULTIVIEW_MODE:
1714 GST_PLAY_BIN3_LOCK (playbin);
1715 playbin->multiview_mode = g_value_get_enum (value);
1716 GST_PLAY_BIN3_UNLOCK (playbin);
1718 case PROP_MULTIVIEW_FLAGS:
1719 GST_PLAY_BIN3_LOCK (playbin);
1720 playbin->multiview_flags = g_value_get_flags (value);
1721 GST_PLAY_BIN3_UNLOCK (playbin);
1724 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1730 gst_play_bin3_get_current_sink (GstPlayBin3 * playbin, GstElement ** elem,
1731 const gchar * dbg, GstPlaySinkType type)
1733 GstElement *sink = gst_play_sink_get_sink (playbin->playsink, type);
1735 GST_LOG_OBJECT (playbin, "play_sink_get_sink() returned %s sink %"
1736 GST_PTR_FORMAT ", the originally set %s sink is %" GST_PTR_FORMAT,
1737 dbg, sink, dbg, *elem);
1740 GST_PLAY_BIN3_LOCK (playbin);
1742 gst_object_ref (sink);
1743 GST_PLAY_BIN3_UNLOCK (playbin);
1750 gst_play_bin3_get_current_stream_combiner (GstPlayBin3 * playbin,
1751 GstElement ** elem, const gchar * dbg, int stream_type)
1753 GstElement *combiner;
1755 GST_PLAY_BIN3_LOCK (playbin);
1756 /* The special concat element should never be returned */
1757 if (playbin->combiner[stream_type].is_concat)
1759 else if ((combiner = playbin->combiner[stream_type].combiner))
1760 gst_object_ref (combiner);
1761 else if ((combiner = *elem))
1762 gst_object_ref (combiner);
1763 GST_PLAY_BIN3_UNLOCK (playbin);
1769 gst_play_bin3_get_property (GObject * object, guint prop_id, GValue * value,
1772 GstPlayBin3 *playbin = GST_PLAY_BIN3 (object);
1777 GstSourceGroup *group;
1779 GST_PLAY_BIN3_LOCK (playbin);
1780 group = playbin->next_group;
1781 g_value_set_string (value, group->uri);
1782 GST_PLAY_BIN3_UNLOCK (playbin);
1785 case PROP_CURRENT_URI:
1787 GstSourceGroup *group;
1789 GST_PLAY_BIN3_LOCK (playbin);
1790 group = get_group (playbin);
1791 g_value_set_string (value, group->uri);
1792 GST_PLAY_BIN3_UNLOCK (playbin);
1797 GstSourceGroup *group;
1799 GST_PLAY_BIN3_LOCK (playbin);
1800 group = playbin->next_group;
1801 g_value_set_string (value, group->suburi);
1802 GST_PLAY_BIN3_UNLOCK (playbin);
1805 case PROP_CURRENT_SUBURI:
1807 GstSourceGroup *group;
1809 GST_PLAY_BIN3_LOCK (playbin);
1810 group = get_group (playbin);
1811 g_value_set_string (value, group->suburi);
1812 GST_PLAY_BIN3_UNLOCK (playbin);
1816 g_value_set_flags (value, gst_play_bin3_get_flags (playbin));
1818 case PROP_SUBTITLE_ENCODING:
1819 GST_PLAY_BIN3_LOCK (playbin);
1820 g_value_take_string (value,
1821 gst_play_sink_get_subtitle_encoding (playbin->playsink));
1822 GST_PLAY_BIN3_UNLOCK (playbin);
1824 case PROP_VIDEO_FILTER:
1825 g_value_take_object (value,
1826 gst_play_sink_get_filter (playbin->playsink,
1827 GST_PLAY_SINK_TYPE_VIDEO));
1829 case PROP_AUDIO_FILTER:
1830 g_value_take_object (value,
1831 gst_play_sink_get_filter (playbin->playsink,
1832 GST_PLAY_SINK_TYPE_AUDIO));
1834 case PROP_VIDEO_SINK:
1835 g_value_take_object (value,
1836 gst_play_bin3_get_current_sink (playbin, &playbin->video_sink,
1837 "video", GST_PLAY_SINK_TYPE_VIDEO));
1839 case PROP_AUDIO_SINK:
1840 g_value_take_object (value,
1841 gst_play_bin3_get_current_sink (playbin, &playbin->audio_sink,
1842 "audio", GST_PLAY_SINK_TYPE_AUDIO));
1844 case PROP_VIS_PLUGIN:
1845 g_value_take_object (value,
1846 gst_play_sink_get_vis_plugin (playbin->playsink));
1848 case PROP_TEXT_SINK:
1849 g_value_take_object (value,
1850 gst_play_bin3_get_current_sink (playbin, &playbin->text_sink,
1851 "text", GST_PLAY_SINK_TYPE_TEXT));
1853 case PROP_VIDEO_STREAM_COMBINER:
1854 g_value_take_object (value,
1855 gst_play_bin3_get_current_stream_combiner (playbin,
1856 &playbin->video_stream_combiner, "video", PLAYBIN_STREAM_VIDEO));
1858 case PROP_AUDIO_STREAM_COMBINER:
1859 g_value_take_object (value,
1860 gst_play_bin3_get_current_stream_combiner (playbin,
1861 &playbin->audio_stream_combiner, "audio", PLAYBIN_STREAM_AUDIO));
1863 case PROP_TEXT_STREAM_COMBINER:
1864 g_value_take_object (value,
1865 gst_play_bin3_get_current_stream_combiner (playbin,
1866 &playbin->text_stream_combiner, "text", PLAYBIN_STREAM_TEXT));
1869 g_value_set_double (value, gst_play_sink_get_volume (playbin->playsink));
1872 g_value_set_boolean (value, gst_play_sink_get_mute (playbin->playsink));
1875 gst_value_take_sample (value,
1876 gst_play_sink_get_last_sample (playbin->playsink));
1878 case PROP_FONT_DESC:
1879 g_value_take_string (value,
1880 gst_play_sink_get_font_desc (playbin->playsink));
1882 case PROP_CONNECTION_SPEED:
1883 GST_PLAY_BIN3_LOCK (playbin);
1884 g_value_set_uint64 (value, playbin->connection_speed / 1000);
1885 GST_PLAY_BIN3_UNLOCK (playbin);
1887 case PROP_BUFFER_SIZE:
1888 GST_OBJECT_LOCK (playbin);
1889 g_value_set_int (value, playbin->buffer_size);
1890 GST_OBJECT_UNLOCK (playbin);
1892 case PROP_BUFFER_DURATION:
1893 GST_OBJECT_LOCK (playbin);
1894 g_value_set_int64 (value, playbin->buffer_duration);
1895 GST_OBJECT_UNLOCK (playbin);
1897 case PROP_AV_OFFSET:
1898 g_value_set_int64 (value,
1899 gst_play_sink_get_av_offset (playbin->playsink));
1901 case PROP_TEXT_OFFSET:
1902 g_value_set_int64 (value,
1903 gst_play_sink_get_text_offset (playbin->playsink));
1905 case PROP_RING_BUFFER_MAX_SIZE:
1906 g_value_set_uint64 (value, playbin->ring_buffer_max_size);
1908 case PROP_FORCE_ASPECT_RATIO:{
1911 g_object_get (playbin->playsink, "force-aspect-ratio", &v, NULL);
1912 g_value_set_boolean (value, v);
1915 case PROP_MULTIVIEW_MODE:
1916 GST_OBJECT_LOCK (playbin);
1917 g_value_set_enum (value, playbin->multiview_mode);
1918 GST_OBJECT_UNLOCK (playbin);
1920 case PROP_MULTIVIEW_FLAGS:
1921 GST_OBJECT_LOCK (playbin);
1922 g_value_set_flags (value, playbin->multiview_flags);
1923 GST_OBJECT_UNLOCK (playbin);
1926 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1932 get_combiner_stream_id (GstPlayBin3 * playbin, GstSourceCombine * combine,
1938 for (i = 0; i < combine->streams->len; i++) {
1939 GstStream *stream = (GstStream *) g_ptr_array_index (combine->streams, i);
1940 const gchar *sid = gst_stream_get_stream_id (stream);
1941 for (tmp = full_list; tmp; tmp = tmp->next) {
1942 gchar *orig = (gchar *) tmp->data;
1943 if (!g_strcmp0 (orig, sid))
1953 extend_list_of_streams (GstPlayBin3 * playbin, GstStreamType stype,
1954 GList * list, GstStreamCollection * collection)
1961 nb = gst_stream_collection_get_size (collection);
1962 for (i = 0; i < nb; i++) {
1963 GstStream *stream = gst_stream_collection_get_stream (collection, i);
1964 GstStreamType curtype = gst_stream_get_stream_type (stream);
1965 if (stype == curtype) {
1966 gboolean already_there = FALSE;
1967 const gchar *sid = gst_stream_get_stream_id (stream);
1968 for (tmp = res; tmp; tmp = tmp->next) {
1969 const gchar *other = (const gchar *) tmp->data;
1970 if (!g_strcmp0 (sid, other)) {
1971 already_there = TRUE;
1975 if (!already_there) {
1976 GST_DEBUG_OBJECT (playbin, "Adding stream %s", sid);
1977 res = g_list_append (res, g_strdup (sid));
1986 update_select_streams_event (GstPlayBin3 * playbin, GstEvent * event,
1987 GstSourceGroup * group)
1989 GList *streams = NULL;
1993 if (!playbin->audio_stream_combiner && !playbin->video_stream_combiner &&
1994 !playbin->text_stream_combiner) {
1996 GST_DEBUG_OBJECT (playbin,
1997 "No custom combiners, no need to modify SELECT_STREAMS event");
2001 if (!group->collection) {
2002 GST_DEBUG_OBJECT (playbin,
2003 "No stream collection for group, no need to modify SELECT_STREAMS event");
2007 gst_event_parse_select_streams (event, &streams);
2008 to_use = g_list_copy_deep (streams, (GCopyFunc) g_strdup, NULL);
2010 /* For each combiner, we want to add all streams of that type to the
2012 if (playbin->audio_stream_combiner) {
2014 extend_list_of_streams (playbin, GST_STREAM_TYPE_AUDIO, to_use,
2017 get_combiner_stream_id (playbin,
2018 &playbin->combiner[PLAYBIN_STREAM_AUDIO], streams);
2019 if (combine_id != -1)
2020 gst_play_bin3_set_current_audio_stream (playbin, combine_id);
2022 if (playbin->video_stream_combiner) {
2024 extend_list_of_streams (playbin, GST_STREAM_TYPE_VIDEO, to_use,
2027 get_combiner_stream_id (playbin,
2028 &playbin->combiner[PLAYBIN_STREAM_VIDEO], streams);
2029 if (combine_id != -1)
2030 gst_play_bin3_set_current_video_stream (playbin, combine_id);
2032 if (playbin->text_stream_combiner) {
2034 extend_list_of_streams (playbin, GST_STREAM_TYPE_TEXT, to_use,
2037 get_combiner_stream_id (playbin,
2038 &playbin->combiner[PLAYBIN_STREAM_TEXT], streams);
2039 if (combine_id != -1)
2040 gst_play_bin3_set_current_text_stream (playbin, combine_id);
2043 gst_event_unref (event);
2044 event = gst_event_new_select_streams (to_use);
2047 g_list_free_full (streams, g_free);
2049 g_list_free_full (to_use, g_free);
2054 /* Returns TRUE if the given list of streams belongs to the stream collection */
2056 gst_streams_belong_to_collection (GList * streams,
2057 GstStreamCollection * collection)
2062 if (streams == NULL || collection == NULL)
2064 nb = gst_stream_collection_get_size (collection);
2068 for (tmp = streams; tmp; tmp = tmp->next) {
2069 const gchar *cand = (const gchar *) tmp->data;
2070 gboolean found = FALSE;
2072 for (i = 0; i < nb; i++) {
2073 GstStream *stream = gst_stream_collection_get_stream (collection, i);
2074 if (!g_strcmp0 (cand, gst_stream_get_stream_id (stream))) {
2085 static GstSourceGroup *
2086 get_source_group_for_streams (GstPlayBin3 * playbin, GstEvent * event)
2089 GstSourceGroup *res = NULL;
2091 gst_event_parse_select_streams (event, &streams);
2092 if (playbin->curr_group->collection &&
2093 gst_streams_belong_to_collection (streams,
2094 playbin->curr_group->collection))
2095 res = playbin->curr_group;
2096 else if (playbin->next_group->collection &&
2097 gst_streams_belong_to_collection (streams,
2098 playbin->next_group->collection))
2099 res = playbin->next_group;
2100 g_list_free_full (streams, g_free);
2106 gst_play_bin3_send_event (GstElement * element, GstEvent * event)
2108 GstPlayBin3 *playbin = GST_PLAY_BIN3 (element);
2110 if (GST_EVENT_TYPE (event) == GST_EVENT_SELECT_STREAMS) {
2112 GstSourceGroup *group;
2114 GST_PLAY_BIN3_LOCK (playbin);
2115 GST_LOG_OBJECT (playbin,
2116 "App sent select-streams, we won't do anything ourselves now");
2117 /* This is probably already false, but it doesn't hurt to be sure */
2118 playbin->do_stream_selections = FALSE;
2120 group = get_source_group_for_streams (playbin, event);
2121 if (group == NULL) {
2122 GST_WARNING_OBJECT (playbin,
2123 "Can't figure out to which uridecodebin the select-streams event should be sent to");
2124 GST_PLAY_BIN3_UNLOCK (playbin);
2128 /* If we have custom combiners, we need to extend the selection with
2129 * the list of all streams for that given type since we will be handling
2130 * the selection with that combiner */
2131 event = update_select_streams_event (playbin, event, group);
2133 /* Don't reconfigure playsink just yet, until the streams-selected
2134 * message(s) tell us as streams become active / available */
2136 /* Send this event directly to uridecodebin, so it works even
2137 * if uridecodebin didn't add any pads yet */
2138 res = gst_element_send_event (group->uridecodebin, event);
2139 GST_PLAY_BIN3_UNLOCK (playbin);
2144 /* Send event directly to playsink instead of letting GstBin iterate
2145 * over all sink elements. The latter might send the event multiple times
2146 * in case the SEEK causes a reconfiguration of the pipeline, as can easily
2147 * happen with adaptive streaming demuxers.
2149 * What would then happen is that the iterator would be reset, we send the
2150 * event again, and on the second time it will fail in the majority of cases
2151 * because the pipeline is still being reconfigured
2153 if (GST_EVENT_IS_UPSTREAM (event)) {
2154 return gst_element_send_event (GST_ELEMENT_CAST (playbin->playsink), event);
2157 return GST_ELEMENT_CLASS (parent_class)->send_event (element, event);
2160 /* Called with playbin lock held */
2162 do_stream_selection (GstPlayBin3 * playbin, GstSourceGroup * group)
2164 GstStreamCollection *collection;
2165 guint i, nb_streams;
2166 GList *streams = NULL;
2167 gint nb_video = 0, nb_audio = 0, nb_text = 0;
2168 GstStreamType chosen_stream_types = 0;
2173 collection = group->collection;
2174 if (collection == NULL) {
2175 GST_LOG_OBJECT (playbin, "No stream collection. Not doing stream-select");
2179 nb_streams = gst_stream_collection_get_size (collection);
2180 if (nb_streams == 0) {
2181 GST_INFO_OBJECT (playbin, "Empty collection received! Ignoring");
2184 GST_DEBUG_OBJECT (playbin, "Doing selection on collection with %d streams",
2187 /* Iterate the collection and choose the streams that match
2188 * either the current-* setting, or all streams of a type if there's
2189 * a combiner for that type */
2190 for (i = 0; i < nb_streams; i++) {
2191 GstStream *stream = gst_stream_collection_get_stream (collection, i);
2192 GstStreamType stream_type = gst_stream_get_stream_type (stream);
2193 const gchar *stream_id = gst_stream_get_stream_id (stream);
2194 gint pb_stream_type = -1;
2195 gboolean select_this = FALSE;
2197 GST_LOG_OBJECT (playbin, "Looking at stream #%d : %s", i, stream_id);
2199 if (stream_type & GST_STREAM_TYPE_AUDIO) {
2200 pb_stream_type = PLAYBIN_STREAM_AUDIO;
2201 /* Select the stream if it's the current one or if there's a custom selector */
2203 (nb_audio == playbin->current_audio ||
2204 (playbin->current_audio == -1 && nb_audio == 0) ||
2205 playbin->audio_stream_combiner != NULL);
2207 } else if (stream_type & GST_STREAM_TYPE_VIDEO) {
2208 pb_stream_type = PLAYBIN_STREAM_VIDEO;
2210 (nb_video == playbin->current_video ||
2211 (playbin->current_video == -1 && nb_video == 0) ||
2212 playbin->video_stream_combiner != NULL);
2214 } else if (stream_type & GST_STREAM_TYPE_TEXT) {
2215 pb_stream_type = PLAYBIN_STREAM_TEXT;
2217 (nb_text == playbin->current_text ||
2218 (playbin->current_text == -1 && nb_text == 0) ||
2219 playbin->text_stream_combiner != NULL);
2222 if (pb_stream_type < 0) {
2223 GST_DEBUG_OBJECT (playbin,
2224 "Stream %d (id %s) of unhandled type %s. Ignoring", i, stream_id,
2225 gst_stream_type_get_name (stream_type));
2229 GST_DEBUG_OBJECT (playbin, "Selecting stream %s of type %s",
2230 stream_id, gst_stream_type_get_name (stream_type));
2231 /* Don't build the list if we're not in charge of stream selection */
2232 if (playbin->do_stream_selections)
2233 streams = g_list_append (streams, (gpointer) stream_id);
2234 chosen_stream_types |= stream_type;
2239 if (group->uridecodebin) {
2240 GstEvent *ev = gst_event_new_select_streams (streams);
2241 gst_element_send_event (group->uridecodebin, ev);
2243 g_list_free (streams);
2246 group->selected_stream_types = chosen_stream_types;
2247 /* Update global selected_stream_types */
2248 playbin->selected_stream_types =
2249 playbin->groups[0].selected_stream_types | playbin->groups[1].
2250 selected_stream_types;
2251 if (playbin->active_stream_types != playbin->selected_stream_types)
2252 reconfigure_output (playbin);
2255 /* Return the GstSourceGroup to which this element belongs
2256 * Can be NULL (if it belongs to playsink for example) */
2257 static GstSourceGroup *
2258 find_source_group_owner (GstPlayBin3 * playbin, GstObject * element)
2260 if (playbin->curr_group->uridecodebin
2261 && gst_object_has_as_ancestor (element,
2262 GST_OBJECT_CAST (playbin->curr_group->uridecodebin)))
2263 return playbin->curr_group;
2264 if (playbin->next_group->uridecodebin
2265 && gst_object_has_as_ancestor (element,
2266 GST_OBJECT_CAST (playbin->next_group->uridecodebin)))
2267 return playbin->next_group;
2272 gst_play_bin3_handle_message (GstBin * bin, GstMessage * msg)
2274 GstPlayBin3 *playbin = GST_PLAY_BIN3 (bin);
2275 gboolean do_reset_time = FALSE;
2277 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_STREAM_START) {
2278 GstSourceGroup *group = NULL, *other_group = NULL;
2279 gboolean changed = FALSE;
2281 GstMessage *buffering_msg;
2283 if (!gst_message_parse_group_id (msg, &group_id)) {
2284 GST_ERROR_OBJECT (bin,
2285 "Could not get group_id from STREAM_START message !");
2288 GST_DEBUG_OBJECT (bin, "STREAM_START group_id:%u", group_id);
2290 /* Figure out to which group this group_id corresponds */
2291 GST_PLAY_BIN3_LOCK (playbin);
2292 if (playbin->groups[0].group_id == group_id) {
2293 group = &playbin->groups[0];
2294 other_group = &playbin->groups[1];
2295 } else if (playbin->groups[1].group_id == group_id) {
2296 group = &playbin->groups[1];
2297 other_group = &playbin->groups[0];
2299 if (group == NULL) {
2300 GST_ERROR_OBJECT (bin, "group_id %u is not provided by any group !",
2302 GST_PLAY_BIN3_UNLOCK (playbin);
2306 debug_groups (playbin);
2308 /* Do the switch now ! */
2309 playbin->curr_group = group;
2310 playbin->next_group = other_group;
2312 /* we may need to serialise a buffering
2313 * message, and need to take that lock
2314 * before any source group lock, so
2316 g_mutex_lock (&playbin->buffering_post_lock);
2318 GST_SOURCE_GROUP_LOCK (group);
2319 if (group->playing == FALSE)
2321 group->playing = TRUE;
2323 buffering_msg = group->pending_buffering_msg;
2324 group->pending_buffering_msg = NULL;
2326 GST_SOURCE_GROUP_UNLOCK (group);
2328 GST_SOURCE_GROUP_LOCK (other_group);
2329 other_group->playing = FALSE;
2330 GST_SOURCE_GROUP_UNLOCK (other_group);
2332 debug_groups (playbin);
2333 GST_PLAY_BIN3_UNLOCK (playbin);
2335 gst_play_bin3_check_group_status (playbin);
2337 GST_DEBUG_OBJECT (bin, "Groups didn't changed");
2339 /* If there was a pending buffering message to send, do it now */
2341 GST_BIN_CLASS (parent_class)->handle_message (bin, buffering_msg);
2343 g_mutex_unlock (&playbin->buffering_post_lock);
2345 } else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_BUFFERING) {
2346 GstSourceGroup *group;
2348 /* Only post buffering messages for group which is currently playing */
2349 GST_PLAY_BIN3_LOCK (playbin);
2350 group = find_source_group_owner (playbin, msg->src);
2351 if (group->active) {
2352 g_mutex_lock (&playbin->buffering_post_lock);
2354 GST_SOURCE_GROUP_LOCK (group);
2355 GST_PLAY_BIN3_UNLOCK (playbin);
2357 if (!group->playing) {
2358 GST_DEBUG_OBJECT (playbin,
2359 "Storing buffering message from pending group " "%p %"
2360 GST_PTR_FORMAT, group, msg);
2361 gst_message_replace (&group->pending_buffering_msg, msg);
2362 gst_message_unref (msg);
2365 /* Ensure there's no cached buffering message for this group */
2366 gst_message_replace (&group->pending_buffering_msg, NULL);
2368 GST_SOURCE_GROUP_UNLOCK (group);
2371 GST_BIN_CLASS (parent_class)->handle_message (bin, msg);
2374 g_mutex_unlock (&playbin->buffering_post_lock);
2376 GST_PLAY_BIN3_UNLOCK (playbin);
2378 } else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_STREAM_COLLECTION) {
2379 GstStreamCollection *collection = NULL;
2381 gst_message_parse_stream_collection (msg, &collection);
2384 gboolean pstate = playbin->do_stream_selections;
2385 GstSourceGroup *target_group = NULL;
2387 GST_PLAY_BIN3_LOCK (playbin);
2388 GST_DEBUG_OBJECT (playbin,
2389 "STREAM_COLLECTION: Got a collection from %" GST_PTR_FORMAT,
2391 target_group = find_source_group_owner (playbin, msg->src);
2393 gst_object_replace ((GstObject **) & target_group->collection,
2394 (GstObject *) collection);
2395 /* FIXME: Only do the following if it's the current group? */
2396 if (target_group == playbin->curr_group)
2397 update_combiner_info (playbin, target_group->collection);
2399 playbin->do_stream_selections = FALSE;
2400 do_stream_selection (playbin, target_group);
2402 playbin->do_stream_selections = TRUE;
2403 GST_PLAY_BIN3_UNLOCK (playbin);
2405 gst_object_unref (collection);
2407 } else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_RESET_TIME) {
2408 if (playbin->is_live && GST_STATE_TARGET (playbin) == GST_STATE_PLAYING) {
2409 do_reset_time = TRUE;
2411 } else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_STREAMS_SELECTED) {
2412 GstSourceGroup *target_group;
2414 GST_PLAY_BIN3_LOCK (playbin);
2416 target_group = find_source_group_owner (playbin, msg->src);
2418 GstStreamType selected_types = 0;
2420 nb = gst_message_streams_selected_get_size (msg);
2421 for (i = 0; i < nb; i++) {
2422 GstStream *stream = gst_message_streams_selected_get_stream (msg, i);
2423 selected_types |= gst_stream_get_stream_type (stream);
2424 gst_object_unref (stream);
2426 target_group->selected_stream_types = selected_types;
2427 playbin->selected_stream_types =
2428 playbin->groups[0].selected_stream_types | playbin->groups[1].
2429 selected_stream_types;
2430 if (playbin->active_stream_types != playbin->selected_stream_types) {
2431 GST_DEBUG_OBJECT (playbin,
2432 "selected stream types changed, reconfiguring output");
2433 reconfigure_output (playbin);
2436 GST_PLAY_BIN3_UNLOCK (playbin);
2441 GST_BIN_CLASS (parent_class)->handle_message (bin, msg);
2443 if (do_reset_time) {
2444 /* If we are live, sample a new base_time immediately */
2445 gst_element_change_state (GST_ELEMENT (playbin),
2446 GST_STATE_CHANGE_PAUSED_TO_PLAYING);
2451 gst_play_bin3_deep_element_added (GstBin * playbin, GstBin * sub_bin,
2454 GST_LOG_OBJECT (playbin, "element %" GST_PTR_FORMAT " was added to "
2455 "%" GST_PTR_FORMAT, child, sub_bin);
2457 g_signal_emit (playbin, gst_play_bin3_signals[SIGNAL_ELEMENT_SETUP], 0,
2460 GST_BIN_CLASS (parent_class)->deep_element_added (playbin, sub_bin, child);
2463 /* Returns current stream number, or -1 if none has been selected yet */
2465 get_current_stream_number (GstPlayBin3 * playbin, GstSourceCombine * combine)
2467 /* Internal API cleanup would make this easier... */
2469 GstPad *pad, *current;
2470 GstObject *combiner = NULL;
2473 if (!combine->has_active_pad) {
2474 GST_WARNING_OBJECT (playbin,
2475 "combiner doesn't have the \"active-pad\" property");
2479 for (i = 0; i < combine->inputpads->len; i++) {
2480 pad = g_ptr_array_index (combine->inputpads, i);
2481 if ((combiner = gst_pad_get_parent (pad))) {
2482 g_object_get (combiner, "active-pad", ¤t, NULL);
2483 gst_object_unref (combiner);
2485 if (pad == current) {
2486 gst_object_unref (current);
2492 gst_object_unref (current);
2500 combiner_active_pad_changed (GObject * combiner, GParamSpec * pspec,
2501 GstPlayBin3 * playbin)
2503 GstSourceCombine *combine = NULL;
2506 GST_PLAY_BIN3_LOCK (playbin);
2508 for (i = 0; i < PLAYBIN_STREAM_LAST; i++) {
2509 if (combiner == G_OBJECT (playbin->combiner[i].combiner)) {
2510 combine = &playbin->combiner[i];
2514 /* We got a pad-change after our group got switched out; no need to notify */
2516 GST_PLAY_BIN3_UNLOCK (playbin);
2520 switch (combine->stream_type) {
2521 case GST_STREAM_TYPE_VIDEO:
2522 playbin->current_video = get_current_stream_number (playbin, combine);
2524 if (playbin->video_pending_flush_finish) {
2525 playbin->video_pending_flush_finish = FALSE;
2526 GST_PLAY_BIN3_UNLOCK (playbin);
2527 gst_play_bin3_send_custom_event (GST_OBJECT (combiner),
2528 "playsink-custom-video-flush-finish");
2531 case GST_STREAM_TYPE_AUDIO:
2532 playbin->current_audio = get_current_stream_number (playbin, combine);
2534 if (playbin->audio_pending_flush_finish) {
2535 playbin->audio_pending_flush_finish = FALSE;
2536 GST_PLAY_BIN3_UNLOCK (playbin);
2537 gst_play_bin3_send_custom_event (GST_OBJECT (combiner),
2538 "playsink-custom-audio-flush-finish");
2541 case GST_STREAM_TYPE_TEXT:
2542 playbin->current_text = get_current_stream_number (playbin, combine);
2544 if (playbin->text_pending_flush_finish) {
2545 playbin->text_pending_flush_finish = FALSE;
2546 GST_PLAY_BIN3_UNLOCK (playbin);
2547 gst_play_bin3_send_custom_event (GST_OBJECT (combiner),
2548 "playsink-custom-subtitle-flush-finish");
2554 GST_PLAY_BIN3_UNLOCK (playbin);
2558 update_video_multiview_caps (GstPlayBin3 * playbin, GstCaps * caps)
2560 GstVideoMultiviewMode mv_mode;
2561 GstVideoMultiviewMode cur_mv_mode;
2562 guint mv_flags, cur_mv_flags;
2564 const gchar *mview_mode_str;
2567 GST_OBJECT_LOCK (playbin);
2568 mv_mode = (GstVideoMultiviewMode) playbin->multiview_mode;
2569 mv_flags = playbin->multiview_flags;
2570 GST_OBJECT_UNLOCK (playbin);
2572 if (mv_mode == GST_VIDEO_MULTIVIEW_MODE_NONE)
2575 cur_mv_mode = GST_VIDEO_MULTIVIEW_MODE_NONE;
2576 cur_mv_flags = GST_VIDEO_MULTIVIEW_FLAGS_NONE;
2578 s = gst_caps_get_structure (caps, 0);
2580 gst_structure_get_flagset (s, "multiview-flags", &cur_mv_flags, NULL);
2581 if ((mview_mode_str = gst_structure_get_string (s, "multiview-mode")))
2582 cur_mv_mode = gst_video_multiview_mode_from_caps_string (mview_mode_str);
2584 /* We can't override an existing annotated multiview mode, except
2585 * maybe (in the future) we could change some flags. */
2586 if ((gint) cur_mv_mode > GST_VIDEO_MULTIVIEW_MAX_FRAME_PACKING) {
2587 GST_INFO_OBJECT (playbin, "Cannot override existing multiview mode");
2591 mview_mode_str = gst_video_multiview_mode_to_caps_string (mv_mode);
2592 g_assert (mview_mode_str != NULL);
2593 out_caps = gst_caps_copy (caps);
2594 s = gst_caps_get_structure (out_caps, 0);
2596 gst_structure_set (s, "multiview-mode", G_TYPE_STRING, mview_mode_str,
2597 "multiview-flags", GST_TYPE_VIDEO_MULTIVIEW_FLAGSET, mv_flags,
2598 GST_FLAG_SET_MASK_EXACT, NULL);
2604 emit_about_to_finish (GstPlayBin3 * playbin)
2606 GST_DEBUG_OBJECT (playbin, "Emitting about-to-finish");
2608 /* after this call, we should have a next group to activate or we EOS */
2609 g_signal_emit (G_OBJECT (playbin),
2610 gst_play_bin3_signals[SIGNAL_ABOUT_TO_FINISH], 0, NULL);
2612 debug_groups (playbin);
2614 /* now activate the next group. If the app did not set a uri, this will
2615 * fail and we can do EOS */
2616 setup_next_source (playbin);
2620 find_source_pad (GstSourceGroup * group, GstPad * target)
2624 for (tmp = group->source_pads; tmp; tmp = tmp->next) {
2625 SourcePad *res = (SourcePad *) tmp->data;
2626 if (res->pad == target)
2632 static GstPadProbeReturn
2633 _decodebin_event_probe (GstPad * pad, GstPadProbeInfo * info, gpointer udata)
2635 GstPadProbeReturn ret = GST_PAD_PROBE_OK;
2636 GstSourceGroup *group = (GstSourceGroup *) udata;
2637 GstPlayBin3 *playbin = group->playbin;
2638 GstEvent *event = GST_PAD_PROBE_INFO_DATA (info);
2640 switch (GST_EVENT_TYPE (event)) {
2641 case GST_EVENT_CAPS:{
2642 GstCaps *caps = NULL;
2643 const GstStructure *s;
2646 gst_event_parse_caps (event, &caps);
2647 /* If video caps, check if we should override multiview flags */
2648 s = gst_caps_get_structure (caps, 0);
2649 name = gst_structure_get_name (s);
2650 if (g_str_has_prefix (name, "video/")) {
2651 caps = update_video_multiview_caps (playbin, caps);
2653 gst_event_unref (event);
2654 event = gst_event_new_caps (caps);
2655 GST_PAD_PROBE_INFO_DATA (info) = event;
2656 gst_caps_unref (caps);
2661 case GST_EVENT_STREAM_START:
2664 if (gst_event_parse_group_id (event, &group_id)) {
2665 GST_LOG_OBJECT (pad, "STREAM_START group_id:%u", group_id);
2666 if (group->group_id == GST_GROUP_ID_INVALID)
2667 group->group_id = group_id;
2668 else if (group->group_id != group_id) {
2669 GST_DEBUG_OBJECT (pad, "group_id changing from %u to %u",
2670 group->group_id, group_id);
2671 group->group_id = group_id;
2684 control_source_pad (GstSourceGroup * group, GstPad * pad,
2685 GstPad * combine_pad, GstStreamType stream_type)
2687 SourcePad *sourcepad = g_slice_new0 (SourcePad);
2689 sourcepad->pad = pad;
2690 sourcepad->event_probe_id =
2691 gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
2692 _decodebin_event_probe, group, NULL);
2693 sourcepad->stream_type = stream_type;
2694 sourcepad->combine_sinkpad = combine_pad;
2695 group->source_pads = g_list_append (group->source_pads, sourcepad);
2699 remove_combiner (GstPlayBin3 * playbin, GstSourceCombine * combine)
2703 if (combine->combiner == NULL) {
2704 GST_DEBUG_OBJECT (playbin, "No combiner element to remove");
2708 /* Go over all sink pads and release them ! */
2709 for (n = 0; n < combine->inputpads->len; n++) {
2710 GstPad *sinkpad = g_ptr_array_index (combine->inputpads, n);
2712 gst_element_release_request_pad (combine->combiner, sinkpad);
2714 g_ptr_array_set_size (combine->inputpads, 0);
2716 gst_element_set_state (combine->combiner, GST_STATE_NULL);
2717 gst_bin_remove (GST_BIN_CAST (playbin), combine->combiner);
2718 combine->combiner = NULL;
2722 /* Create the combiner element if needed for the given combine */
2724 create_combiner (GstPlayBin3 * playbin, GstSourceCombine * combine)
2726 GstElement *custom_combiner = NULL;
2728 if (combine->combiner) {
2729 GST_WARNING_OBJECT (playbin, "Combiner element already exists!");
2733 if (combine->stream_type == GST_STREAM_TYPE_VIDEO)
2734 custom_combiner = playbin->video_stream_combiner;
2735 else if (combine->stream_type == GST_STREAM_TYPE_AUDIO)
2736 custom_combiner = playbin->audio_stream_combiner;
2737 else if (combine->stream_type == GST_STREAM_TYPE_TEXT)
2738 custom_combiner = playbin->text_stream_combiner;
2740 combine->combiner = custom_combiner;
2742 if (!combine->combiner) {
2744 GST_DEBUG_OBJECT (playbin,
2745 "No custom combiner requested, using 'concat' element");
2747 g_strdup_printf ("%s-concat",
2748 gst_stream_type_get_name (combine->stream_type));
2749 combine->combiner = gst_element_factory_make ("concat", concat_name);
2750 g_object_set (combine->combiner, "adjust-base", FALSE, NULL);
2751 g_free (concat_name);
2752 combine->is_concat = TRUE;
2755 combine->srcpad = gst_element_get_static_pad (combine->combiner, "src");
2757 /* We only want to use 'active-pad' if it's a regular combiner that
2758 * will consume all streams, and not concat (which is just used for
2760 if (!combine->is_concat) {
2761 combine->has_active_pad =
2762 g_object_class_find_property (G_OBJECT_GET_CLASS (combine->combiner),
2763 "active-pad") != NULL;
2765 if (combine->has_active_pad)
2766 g_signal_connect (combine->combiner, "notify::active-pad",
2767 G_CALLBACK (combiner_active_pad_changed), playbin);
2770 GST_DEBUG_OBJECT (playbin, "adding new stream combiner %" GST_PTR_FORMAT,
2772 gst_bin_add (GST_BIN_CAST (playbin), combine->combiner);
2773 gst_element_sync_state_with_parent (combine->combiner);
2777 combiner_control_pad (GstPlayBin3 * playbin, GstSourceCombine * combine,
2780 GstPadLinkReturn res;
2781 GstPad *combine_pad = NULL;
2783 GST_DEBUG_OBJECT (playbin, "srcpad %" GST_PTR_FORMAT, srcpad);
2785 if (combine->combiner) {
2787 gst_element_request_pad_simple (combine->combiner, "sink_%u");
2789 if (sinkpad == NULL)
2790 goto request_pad_failed;
2792 GST_DEBUG_OBJECT (playbin, "Got new combiner pad %" GST_PTR_FORMAT,
2795 /* store the pad in the array */
2796 GST_DEBUG_OBJECT (playbin, "pad %" GST_PTR_FORMAT " added to array",
2798 g_ptr_array_add (combine->inputpads, sinkpad);
2800 res = gst_pad_link (srcpad, sinkpad);
2801 if (GST_PAD_LINK_FAILED (res))
2802 goto failed_combiner_link;
2804 GST_DEBUG_OBJECT (playbin,
2805 "linked pad %" GST_PTR_FORMAT " to combiner %" GST_PTR_FORMAT, srcpad,
2807 combine_pad = sinkpad;
2809 GST_LOG_OBJECT (playbin, "combine->sinkpad:%" GST_PTR_FORMAT,
2811 g_assert (combine->sinkpad != NULL);
2812 /* Connect directly to playsink */
2813 if (gst_pad_is_linked (combine->sinkpad))
2814 goto sinkpad_already_linked;
2816 GST_DEBUG_OBJECT (playbin, "Linking new pad straight to playsink");
2817 res = gst_pad_link (srcpad, combine->sinkpad);
2819 if (res != GST_PAD_LINK_OK)
2820 goto failed_sinkpad_link;
2827 GST_ELEMENT_ERROR (playbin, CORE, PAD,
2828 ("Internal playbin error."),
2829 ("Failed to get request pad from combiner %p.", combine->combiner));
2833 sinkpad_already_linked:
2834 GST_ELEMENT_ERROR (playbin, CORE, PAD,
2835 ("Internal playbin error."), ("playsink pad already used !"));
2838 failed_sinkpad_link:
2839 GST_ELEMENT_ERROR (playbin, CORE, PAD,
2840 ("Internal playbin error."),
2841 ("Failed to link pad to sink. Error %d", res));
2844 failed_combiner_link:
2845 GST_ELEMENT_ERROR (playbin, CORE, PAD,
2846 ("Internal playbin error."),
2847 ("Failed to link pad to combiner. Error %d", res));
2852 /* Call after pad was unlinked from (potential) combiner */
2854 release_source_pad (GstPlayBin3 * playbin, GstSourceGroup * group,
2855 GstSourceCombine * combine, GstPad * pad)
2857 SourcePad *sourcepad;
2859 GstStreamType alltype = 0;
2861 sourcepad = find_source_pad (group, pad);
2863 GST_DEBUG_OBJECT (playbin, "Not a pad controlled by us ?");
2867 if (sourcepad->event_probe_id) {
2868 gst_pad_remove_probe (pad, sourcepad->event_probe_id);
2869 sourcepad->event_probe_id = 0;
2872 if (sourcepad->combine_sinkpad) {
2873 gst_element_release_request_pad (combine->combiner,
2874 sourcepad->combine_sinkpad);
2875 g_ptr_array_remove (combine->inputpads, sourcepad->combine_sinkpad);
2878 /* Remove from list of controlled pads and check again for EOS status */
2879 group->source_pads = g_list_remove (group->source_pads, sourcepad);
2880 g_slice_free (SourcePad, sourcepad);
2882 /* Update present stream types */
2883 for (tmp = group->source_pads; tmp; tmp = tmp->next) {
2884 SourcePad *cand = (SourcePad *) tmp->data;
2885 alltype |= cand->stream_type;
2887 group->present_stream_types = alltype;
2890 /* this function is called when a new pad is added to decodebin. We check the
2891 * type of the pad and add it to the combiner element
2894 pad_added_cb (GstElement * uridecodebin, GstPad * pad, GstSourceGroup * group)
2896 GstSourceCombine *combine = NULL;
2897 gint pb_stream_type = -1;
2899 GstPlayBin3 *playbin = group->playbin;
2900 GstPad *combine_pad;
2901 GstStreamType selected, active, cur;
2903 GST_PLAY_BIN3_SHUTDOWN_LOCK (playbin, shutdown);
2905 pad_name = gst_object_get_name (GST_OBJECT (pad));
2907 GST_DEBUG_OBJECT (playbin, "decoded pad %s:%s added",
2908 GST_DEBUG_PAD_NAME (pad));
2910 /* major type of the pad, this determines the combiner to use,
2911 try exact match first */
2912 if (g_str_has_prefix (pad_name, "video")) {
2913 pb_stream_type = PLAYBIN_STREAM_VIDEO;
2914 cur = GST_STREAM_TYPE_VIDEO;
2915 } else if (g_str_has_prefix (pad_name, "audio")) {
2916 pb_stream_type = PLAYBIN_STREAM_AUDIO;
2917 cur = GST_STREAM_TYPE_AUDIO;
2918 } else if (g_str_has_prefix (pad_name, "text")) {
2919 pb_stream_type = PLAYBIN_STREAM_TEXT;
2920 cur = GST_STREAM_TYPE_TEXT;
2925 /* no stream type found for the media type, don't bother linking it to a
2926 * combiner. This will leave the pad unlinked and thus ignored. */
2927 if (pb_stream_type < 0) {
2928 GST_PLAY_BIN3_SHUTDOWN_UNLOCK (playbin);
2932 GST_PLAY_BIN3_LOCK (playbin);
2933 combine = &playbin->combiner[pb_stream_type];
2935 /* (uri)decodebin3 will post streams-selected once all pads are expose.
2936 * Therefore this stream might not be marked as selected on pad-added,
2937 * and associated combiner can be null here.
2938 * Marks this stream as selected manually, exposed pad implies it's selected
2940 selected = playbin->selected_stream_types | cur;
2941 active = playbin->active_stream_types;
2943 if (selected != active) {
2944 GST_DEBUG_OBJECT (playbin,
2945 "%s:%s added but not an active stream, marking active",
2946 GST_DEBUG_PAD_NAME (pad));
2947 playbin->selected_stream_types = selected;
2948 reconfigure_output (playbin);
2950 /* shutdown state can be changed meantime then combiner will not be
2952 if (g_atomic_int_get (&playbin->shutdown)) {
2953 GST_PLAY_BIN3_UNLOCK (playbin);
2954 GST_PLAY_BIN3_SHUTDOWN_UNLOCK (playbin);
2959 combine_pad = combiner_control_pad (playbin, combine, pad);
2961 control_source_pad (group, pad, combine_pad, combine->stream_type);
2963 /* Update present stream_types and check whether we should post a pending about-to-finish */
2964 group->present_stream_types |= combine->stream_type;
2966 if (group->playing && group->pending_about_to_finish
2967 && group->present_stream_types == group->selected_stream_types) {
2968 group->pending_about_to_finish = FALSE;
2969 emit_about_to_finish (playbin);
2971 GST_PLAY_BIN3_UNLOCK (playbin);
2973 GST_PLAY_BIN3_SHUTDOWN_UNLOCK (playbin);
2979 GST_DEBUG_OBJECT (playbin, "Ignoring pad with unknown type");
2984 GST_DEBUG ("ignoring, we are shutting down. Pad will be left unlinked");
2985 /* not going to done as we didn't request the caps */
2990 /* called when a pad is removed from the decodebin. We unlink the pad from
2993 pad_removed_cb (GstElement * decodebin, GstPad * pad, GstSourceGroup * group)
2995 GstSourceCombine *combine;
2996 GstPlayBin3 *playbin = group->playbin;
2998 GST_DEBUG_OBJECT (playbin,
2999 "decoded pad %s:%s removed", GST_DEBUG_PAD_NAME (pad));
3001 GST_PLAY_BIN3_LOCK (playbin);
3003 /* Get combiner for pad */
3004 if (g_str_has_prefix (GST_PAD_NAME (pad), "video"))
3005 combine = &playbin->combiner[PLAYBIN_STREAM_VIDEO];
3006 else if (g_str_has_prefix (GST_PAD_NAME (pad), "audio"))
3007 combine = &playbin->combiner[PLAYBIN_STREAM_AUDIO];
3008 else if (g_str_has_prefix (GST_PAD_NAME (pad), "text"))
3009 combine = &playbin->combiner[PLAYBIN_STREAM_TEXT];
3013 release_source_pad (playbin, group, combine, pad);
3016 GST_PLAY_BIN3_UNLOCK (playbin);
3021 select_stream_cb (GstElement * decodebin, GstStreamCollection * collection,
3022 GstStream * stream, GstSourceGroup * group)
3024 GstStreamType stype = gst_stream_get_stream_type (stream);
3025 GstElement *combiner = NULL;
3026 GstPlayBin3 *playbin = group->playbin;
3028 if (stype & GST_STREAM_TYPE_AUDIO)
3029 combiner = playbin->audio_stream_combiner;
3030 else if (stype & GST_STREAM_TYPE_VIDEO)
3031 combiner = playbin->video_stream_combiner;
3032 else if (stype & GST_STREAM_TYPE_TEXT)
3033 combiner = playbin->text_stream_combiner;
3036 GST_DEBUG_OBJECT (playbin, "Got a combiner, requesting stream activation");
3040 /* Let decodebin3 decide otherwise */
3044 /* We get called when the selected stream types change and
3045 * reconfiguration of output (i.e. playsink and potential combiners)
3049 reconfigure_output (GstPlayBin3 * playbin)
3051 GstPadLinkReturn res;
3054 g_assert (playbin->selected_stream_types != playbin->active_stream_types);
3056 GST_DEBUG_OBJECT (playbin, "selected_stream_types : %" STREAM_TYPES_FORMAT,
3057 STREAM_TYPES_ARGS (playbin->selected_stream_types));
3058 GST_DEBUG_OBJECT (playbin, "active_stream_types : %" STREAM_TYPES_FORMAT,
3059 STREAM_TYPES_ARGS (playbin->active_stream_types));
3061 GST_PLAY_BIN3_LOCK (playbin);
3063 /* Make sure combiners/playsink are in sync with selected stream types */
3064 for (i = 0; i < PLAYBIN_STREAM_LAST; i++) {
3065 GstSourceCombine *combine = &playbin->combiner[i];
3066 gboolean is_selected =
3067 (combine->stream_type & playbin->selected_stream_types) ==
3068 combine->stream_type;
3069 gboolean is_active =
3070 (combine->stream_type & playbin->active_stream_types) ==
3071 combine->stream_type;
3073 GST_DEBUG_OBJECT (playbin, "Stream type status: '%s' %s %s",
3074 gst_stream_type_get_name (combine->stream_type),
3075 is_selected ? "selected" : "NOT selected",
3076 is_active ? "active" : "NOT active");
3077 /* FIXME : Remove asserts below once enough testing has been done */
3079 if (is_selected && is_active) {
3080 GST_DEBUG_OBJECT (playbin, "Stream type '%s' already active",
3081 gst_stream_type_get_name (combine->stream_type));
3082 } else if (is_active && !is_selected) {
3083 GST_DEBUG_OBJECT (playbin, "Stream type '%s' is no longer requested",
3084 gst_stream_type_get_name (combine->stream_type));
3086 /* Unlink combiner from sink */
3087 if (combine->srcpad) {
3088 GST_LOG_OBJECT (playbin, "Unlinking from sink");
3089 if (combine->sinkpad)
3090 gst_pad_unlink (combine->srcpad, combine->sinkpad);
3091 gst_object_unref (combine->srcpad);
3092 combine->srcpad = NULL;
3095 if (combine->sinkpad) {
3096 /* Release playsink sink pad */
3097 GST_LOG_OBJECT (playbin, "Releasing playsink pad");
3098 gst_play_sink_release_pad (playbin->playsink, combine->sinkpad);
3099 gst_object_unref (combine->sinkpad);
3100 combine->sinkpad = NULL;
3103 /* Release combiner */
3104 GST_FIXME_OBJECT (playbin, "Release combiner");
3105 remove_combiner (playbin, combine);
3106 } else if (!is_active && is_selected) {
3107 GST_DEBUG_OBJECT (playbin, "Stream type '%s' is now requested",
3108 gst_stream_type_get_name (combine->stream_type));
3110 /* If we are shutting down, do *not* add more combiners */
3111 if (g_atomic_int_get (&playbin->shutdown))
3114 g_assert (combine->sinkpad == NULL);
3116 /* Request playsink sink pad */
3118 gst_play_sink_request_pad (playbin->playsink,
3119 gst_play_sink_type_from_stream_type (combine->stream_type));
3120 gst_object_ref (combine->sinkpad);
3121 /* Create combiner if needed and link it */
3122 create_combiner (playbin, combine);
3123 if (combine->combiner) {
3124 res = gst_pad_link (combine->srcpad, combine->sinkpad);
3125 GST_DEBUG_OBJECT (playbin, "linked type %s, result: %d",
3126 gst_stream_type_get_name (combine->stream_type), res);
3127 if (res != GST_PAD_LINK_OK) {
3128 GST_ELEMENT_ERROR (playbin, CORE, PAD,
3129 ("Internal playbin error."),
3130 ("Failed to link combiner to sink. Error %d", res));
3137 playbin->active_stream_types = playbin->selected_stream_types;
3139 GST_PLAY_BIN3_UNLOCK (playbin);
3141 gst_play_sink_reconfigure (playbin->playsink);
3143 do_async_done (playbin);
3145 GST_DEBUG_OBJECT (playbin, "selected_stream_types : %" STREAM_TYPES_FORMAT,
3146 STREAM_TYPES_ARGS (playbin->selected_stream_types));
3147 GST_DEBUG_OBJECT (playbin, "active_stream_types : %" STREAM_TYPES_FORMAT,
3148 STREAM_TYPES_ARGS (playbin->active_stream_types));
3154 about_to_finish_cb (GstElement * uridecodebin, GstSourceGroup * group)
3156 GstPlayBin3 *playbin = group->playbin;
3157 GST_DEBUG_OBJECT (playbin, "about to finish in group %p", group);
3159 GST_LOG_OBJECT (playbin, "selected_stream_types:%" STREAM_TYPES_FORMAT,
3160 STREAM_TYPES_ARGS (group->selected_stream_types));
3161 GST_LOG_OBJECT (playbin, "present_stream_types:%" STREAM_TYPES_FORMAT,
3162 STREAM_TYPES_ARGS (group->present_stream_types));
3164 if (group->selected_stream_types == 0
3165 || (group->selected_stream_types != group->present_stream_types)) {
3166 GST_LOG_OBJECT (playbin,
3167 "Delaying emission of signal until this group is ready");
3168 group->pending_about_to_finish = TRUE;
3170 emit_about_to_finish (playbin);
3173 static GstBusSyncReply
3174 activate_sink_bus_handler (GstBus * bus, GstMessage * msg,
3175 GstPlayBin3 * playbin)
3177 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
3178 /* Only proxy errors from a fixed sink. If that fails we can just error out
3179 * early as stuff will fail later anyway */
3180 if (playbin->audio_sink
3181 && gst_object_has_as_ancestor (GST_MESSAGE_SRC (msg),
3182 GST_OBJECT_CAST (playbin->audio_sink)))
3183 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
3184 else if (playbin->video_sink
3185 && gst_object_has_as_ancestor (GST_MESSAGE_SRC (msg),
3186 GST_OBJECT_CAST (playbin->video_sink)))
3187 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
3188 else if (playbin->text_sink
3189 && gst_object_has_as_ancestor (GST_MESSAGE_SRC (msg),
3190 GST_OBJECT_CAST (playbin->text_sink)))
3191 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
3193 gst_message_unref (msg);
3194 } else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_HAVE_CONTEXT) {
3195 GstContext *context;
3197 gst_message_parse_have_context (msg, &context);
3198 gst_element_set_context (GST_ELEMENT_CAST (playbin), context);
3199 gst_context_unref (context);
3200 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
3202 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
3205 /* Doesn't really matter, nothing is using this bus */
3206 return GST_BUS_DROP;
3210 activate_sink (GstPlayBin3 * playbin, GstElement * sink, gboolean * activated)
3214 GstStateChangeReturn sret;
3215 gboolean ret = FALSE;
3220 GST_OBJECT_LOCK (sink);
3221 state = GST_STATE (sink);
3222 GST_OBJECT_UNLOCK (sink);
3223 if (state >= GST_STATE_READY) {
3228 if (!GST_OBJECT_PARENT (sink)) {
3229 bus = gst_bus_new ();
3230 gst_bus_set_sync_handler (bus,
3231 (GstBusSyncHandler) activate_sink_bus_handler, playbin, NULL);
3232 gst_element_set_bus (sink, bus);
3235 sret = gst_element_set_state (sink, GST_STATE_READY);
3236 if (sret == GST_STATE_CHANGE_FAILURE)
3245 gst_element_set_bus (sink, NULL);
3246 gst_object_unref (bus);
3252 /* must be called with the group lock */
3254 group_set_locked_state_unlocked (GstPlayBin3 * playbin, GstSourceGroup * group,
3257 GST_DEBUG_OBJECT (playbin, "locked_state %d on group %p", locked, group);
3259 if (group->uridecodebin)
3260 gst_element_set_locked_state (group->uridecodebin, locked);
3266 make_or_reuse_element (GstPlayBin3 * playbin, const gchar * name,
3270 GST_DEBUG_OBJECT (playbin, "reusing existing %s", name);
3271 gst_element_set_state (*elem, GST_STATE_READY);
3272 /* no need to take extra ref, we already have one
3273 * and the bin will add one since it is no longer floating,
3274 * as we added a non-floating ref when removing it from the
3277 GstElement *new_elem;
3278 GST_DEBUG_OBJECT (playbin, "making new %s", name);
3279 new_elem = gst_element_factory_make (name, NULL);
3282 *elem = gst_object_ref (new_elem);
3285 if (GST_OBJECT_PARENT (*elem) != GST_OBJECT_CAST (playbin))
3286 gst_bin_add (GST_BIN_CAST (playbin), *elem);
3292 source_setup_cb (GstElement * element, GstElement * source,
3293 GstSourceGroup * group)
3295 g_signal_emit (group->playbin, gst_play_bin3_signals[SIGNAL_SOURCE_SETUP], 0,
3299 /* must be called with PLAY_BIN_LOCK */
3300 static GstStateChangeReturn
3301 activate_group (GstPlayBin3 * playbin, GstSourceGroup * group)
3303 GstElement *uridecodebin = NULL;
3305 gboolean audio_sink_activated = FALSE;
3306 gboolean video_sink_activated = FALSE;
3307 gboolean text_sink_activated = FALSE;
3308 GstStateChangeReturn state_ret;
3310 g_return_val_if_fail (group->valid, GST_STATE_CHANGE_FAILURE);
3311 g_return_val_if_fail (!group->active, GST_STATE_CHANGE_FAILURE);
3313 GST_DEBUG_OBJECT (playbin, "activating group %p", group);
3315 GST_SOURCE_GROUP_LOCK (group);
3317 /* First set up the custom sinks */
3318 if (playbin->audio_sink)
3319 group->audio_sink = gst_object_ref (playbin->audio_sink);
3322 gst_play_sink_get_sink (playbin->playsink, GST_PLAY_SINK_TYPE_AUDIO);
3324 if (group->audio_sink) {
3325 if (!activate_sink (playbin, group->audio_sink, &audio_sink_activated)) {
3326 if (group->audio_sink == playbin->audio_sink) {
3329 gst_object_unref (group->audio_sink);
3330 group->audio_sink = NULL;
3335 if (playbin->video_sink)
3336 group->video_sink = gst_object_ref (playbin->video_sink);
3339 gst_play_sink_get_sink (playbin->playsink, GST_PLAY_SINK_TYPE_VIDEO);
3341 if (group->video_sink) {
3342 if (!activate_sink (playbin, group->video_sink, &video_sink_activated)) {
3343 if (group->video_sink == playbin->video_sink) {
3346 gst_object_unref (group->video_sink);
3347 group->video_sink = NULL;
3352 if (playbin->text_sink)
3353 group->text_sink = gst_object_ref (playbin->text_sink);
3356 gst_play_sink_get_sink (playbin->playsink, GST_PLAY_SINK_TYPE_TEXT);
3358 if (group->text_sink) {
3359 if (!activate_sink (playbin, group->text_sink, &text_sink_activated)) {
3360 if (group->text_sink == playbin->text_sink) {
3363 gst_object_unref (group->text_sink);
3364 group->text_sink = NULL;
3370 if (!make_or_reuse_element (playbin, "uridecodebin3", &group->uridecodebin))
3371 goto no_uridecodebin;
3372 uridecodebin = group->uridecodebin;
3374 flags = gst_play_sink_get_flags (playbin->playsink);
3376 g_object_set (uridecodebin,
3377 /* configure connection speed */
3378 "connection-speed", playbin->connection_speed / 1000,
3381 /* configure download buffering */
3382 "download", ((flags & GST_PLAY_FLAG_DOWNLOAD) != 0),
3383 /* configure buffering of demuxed/parsed data */
3384 "use-buffering", ((flags & GST_PLAY_FLAG_BUFFERING) != 0),
3385 /* configure buffering parameters */
3386 "buffer-duration", playbin->buffer_duration,
3387 "buffer-size", playbin->buffer_size,
3388 "ring-buffer-max-size", playbin->ring_buffer_max_size, NULL);
3390 group->pad_added_id = g_signal_connect (uridecodebin, "pad-added",
3391 G_CALLBACK (pad_added_cb), group);
3392 group->pad_removed_id = g_signal_connect (uridecodebin,
3393 "pad-removed", G_CALLBACK (pad_removed_cb), group);
3394 group->select_stream_id = g_signal_connect (uridecodebin, "select-stream",
3395 G_CALLBACK (select_stream_cb), group);
3396 group->source_setup_id = g_signal_connect (uridecodebin, "source-setup",
3397 G_CALLBACK (source_setup_cb), group);
3398 group->about_to_finish_id =
3399 g_signal_connect (uridecodebin, "about-to-finish",
3400 G_CALLBACK (about_to_finish_cb), group);
3403 g_object_set (group->uridecodebin, "suburi", group->suburi, NULL);
3405 /* release the group lock before setting the state of the source bins, they
3406 * might fire signals in this thread that we need to handle with the
3407 * group_lock taken. */
3408 GST_SOURCE_GROUP_UNLOCK (group);
3411 gst_element_set_state (uridecodebin,
3412 GST_STATE_PAUSED)) == GST_STATE_CHANGE_FAILURE)
3413 goto uridecodebin_failure;
3415 GST_SOURCE_GROUP_LOCK (group);
3416 /* allow state changes of the playbin affect the group elements now */
3417 group_set_locked_state_unlocked (playbin, group, FALSE);
3418 group->active = TRUE;
3419 GST_SOURCE_GROUP_UNLOCK (group);
3428 GST_SOURCE_GROUP_UNLOCK (group);
3430 gst_missing_element_message_new (GST_ELEMENT_CAST (playbin),
3432 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
3434 GST_ELEMENT_ERROR (playbin, CORE, MISSING_PLUGIN,
3435 (_("Could not create \"uridecodebin3\" element.")), (NULL));
3437 GST_SOURCE_GROUP_LOCK (group);
3441 uridecodebin_failure:
3443 GST_DEBUG_OBJECT (playbin, "failed state change of uridecodebin");
3444 GST_SOURCE_GROUP_LOCK (group);
3449 GST_ERROR_OBJECT (playbin, "failed to activate sinks");
3455 group->selected_stream_types = 0;
3457 /* delete any custom sinks we might have */
3458 if (group->audio_sink) {
3459 /* If this is a automatically created sink set it to NULL */
3460 if (audio_sink_activated)
3461 gst_element_set_state (group->audio_sink, GST_STATE_NULL);
3462 gst_object_unref (group->audio_sink);
3464 group->audio_sink = NULL;
3466 if (group->video_sink) {
3467 /* If this is a automatically created sink set it to NULL */
3468 if (video_sink_activated)
3469 gst_element_set_state (group->video_sink, GST_STATE_NULL);
3470 gst_object_unref (group->video_sink);
3472 group->video_sink = NULL;
3474 if (group->text_sink) {
3475 /* If this is a automatically created sink set it to NULL */
3476 if (text_sink_activated)
3477 gst_element_set_state (group->text_sink, GST_STATE_NULL);
3478 gst_object_unref (group->text_sink);
3480 group->text_sink = NULL;
3483 REMOVE_SIGNAL (group->uridecodebin, group->pad_added_id);
3484 REMOVE_SIGNAL (group->uridecodebin, group->pad_removed_id);
3485 REMOVE_SIGNAL (group->uridecodebin, group->select_stream_id);
3486 REMOVE_SIGNAL (group->uridecodebin, group->source_setup_id);
3487 REMOVE_SIGNAL (group->uridecodebin, group->about_to_finish_id);
3489 gst_element_set_state (uridecodebin, GST_STATE_NULL);
3490 gst_bin_remove (GST_BIN_CAST (playbin), uridecodebin);
3493 GST_SOURCE_GROUP_UNLOCK (group);
3495 return GST_STATE_CHANGE_FAILURE;
3499 /* must be called with PLAY_BIN_LOCK, which is dropped temporarily
3500 * if changing states */
3502 deactivate_group (GstPlayBin3 * playbin, GstSourceGroup * group)
3504 g_return_val_if_fail (group->active, FALSE);
3505 g_return_val_if_fail (group->valid, FALSE);
3507 GST_DEBUG_OBJECT (playbin, "unlinking group %p", group);
3509 GST_SOURCE_GROUP_LOCK (group);
3510 group->active = FALSE;
3511 group->playing = FALSE;
3512 group->group_id = GST_GROUP_ID_INVALID;
3514 group->selected_stream_types = 0;
3515 /* Update global selected_stream_types */
3516 playbin->selected_stream_types =
3517 playbin->groups[0].selected_stream_types | playbin->groups[1].
3518 selected_stream_types;
3519 if (playbin->active_stream_types != playbin->selected_stream_types)
3520 reconfigure_output (playbin);
3522 if (group->uridecodebin) {
3523 REMOVE_SIGNAL (group->uridecodebin, group->select_stream_id);
3524 REMOVE_SIGNAL (group->uridecodebin, group->source_setup_id);
3525 REMOVE_SIGNAL (group->uridecodebin, group->about_to_finish_id);
3527 GST_PLAY_BIN3_UNLOCK (playbin);
3528 gst_element_set_state (group->uridecodebin, GST_STATE_NULL);
3529 gst_bin_remove (GST_BIN_CAST (playbin), group->uridecodebin);
3530 GST_PLAY_BIN3_LOCK (playbin);
3532 REMOVE_SIGNAL (group->uridecodebin, group->pad_added_id);
3533 REMOVE_SIGNAL (group->uridecodebin, group->pad_removed_id);
3536 GST_SOURCE_GROUP_UNLOCK (group);
3538 GST_DEBUG_OBJECT (playbin, "Done");
3543 /* setup the next group to play, this assumes the next_group is valid and
3544 * configured. It swaps out the current_group and activates the valid
3546 static GstStateChangeReturn
3547 setup_next_source (GstPlayBin3 * playbin)
3549 GstSourceGroup *new_group;
3550 GstStateChangeReturn state_ret;
3552 GST_DEBUG_OBJECT (playbin, "setup next source");
3554 debug_groups (playbin);
3556 /* see if there is a next group */
3557 GST_PLAY_BIN3_LOCK (playbin);
3558 new_group = playbin->next_group;
3559 if (!new_group || !new_group->valid || new_group->active)
3562 /* activate the new group */
3563 state_ret = activate_group (playbin, new_group);
3564 if (state_ret == GST_STATE_CHANGE_FAILURE)
3565 goto activate_failed;
3567 GST_PLAY_BIN3_UNLOCK (playbin);
3569 debug_groups (playbin);
3576 GST_DEBUG_OBJECT (playbin, "no next group");
3577 GST_PLAY_BIN3_UNLOCK (playbin);
3578 return GST_STATE_CHANGE_FAILURE;
3582 new_group->stream_changed_pending = FALSE;
3583 GST_DEBUG_OBJECT (playbin, "activate failed");
3584 new_group->valid = FALSE;
3585 GST_PLAY_BIN3_UNLOCK (playbin);
3586 return GST_STATE_CHANGE_FAILURE;
3590 /* The group that is currently playing is copied again to the
3591 * next_group so that it will start playing the next time.
3594 save_current_group (GstPlayBin3 * playbin)
3596 GstSourceGroup *curr_group;
3597 gboolean swapped = FALSE;
3599 GST_DEBUG_OBJECT (playbin, "save current group");
3601 /* see if there is a current group */
3602 GST_PLAY_BIN3_LOCK (playbin);
3603 curr_group = playbin->curr_group;
3604 if (curr_group && curr_group->valid && curr_group->active) {
3607 /* swap old and new */
3608 playbin->curr_group = playbin->next_group;
3609 playbin->next_group = curr_group;
3612 /* unlink our pads with the sink */
3613 deactivate_group (playbin, curr_group);
3615 GST_PLAY_BIN3_UNLOCK (playbin);
3620 /* clear the locked state from all groups. This function is called before a
3621 * state change to NULL is performed on them. */
3623 groups_set_locked_state (GstPlayBin3 * playbin, gboolean locked)
3625 GST_DEBUG_OBJECT (playbin, "setting locked state to %d on all groups",
3628 GST_PLAY_BIN3_LOCK (playbin);
3629 GST_SOURCE_GROUP_LOCK (playbin->curr_group);
3630 group_set_locked_state_unlocked (playbin, playbin->curr_group, locked);
3631 GST_SOURCE_GROUP_UNLOCK (playbin->curr_group);
3632 GST_SOURCE_GROUP_LOCK (playbin->next_group);
3633 group_set_locked_state_unlocked (playbin, playbin->next_group, locked);
3634 GST_SOURCE_GROUP_UNLOCK (playbin->next_group);
3635 GST_PLAY_BIN3_UNLOCK (playbin);
3641 gst_play_bin3_check_group_status (GstPlayBin3 * playbin)
3643 if (playbin->activation_task)
3644 gst_task_start (playbin->activation_task);
3648 gst_play_bin3_activation_thread (GstPlayBin3 * playbin)
3650 GST_DEBUG_OBJECT (playbin, "starting");
3652 debug_groups (playbin);
3654 /* Check if next_group needs to be deactivated */
3655 GST_PLAY_BIN3_LOCK (playbin);
3656 if (playbin->next_group->active) {
3657 deactivate_group (playbin, playbin->next_group);
3658 playbin->next_group->valid = FALSE;
3661 /* Is there a pending about-to-finish to be emitted ? */
3662 GST_SOURCE_GROUP_LOCK (playbin->curr_group);
3663 if (playbin->curr_group->pending_about_to_finish) {
3664 GST_LOG_OBJECT (playbin, "Propagating about-to-finish");
3665 playbin->curr_group->pending_about_to_finish = FALSE;
3666 GST_SOURCE_GROUP_UNLOCK (playbin->curr_group);
3667 /* This will activate the next source afterwards */
3668 emit_about_to_finish (playbin);
3670 GST_SOURCE_GROUP_UNLOCK (playbin->curr_group);
3672 GST_LOG_OBJECT (playbin, "Pausing task");
3673 if (playbin->activation_task)
3674 gst_task_pause (playbin->activation_task);
3675 GST_PLAY_BIN3_UNLOCK (playbin);
3677 GST_DEBUG_OBJECT (playbin, "done");
3682 gst_play_bin3_start (GstPlayBin3 * playbin)
3684 GST_DEBUG_OBJECT (playbin, "starting");
3686 GST_PLAY_BIN3_LOCK (playbin);
3688 if (playbin->activation_task == NULL) {
3689 playbin->activation_task =
3690 gst_task_new ((GstTaskFunction) gst_play_bin3_activation_thread,
3692 if (playbin->activation_task == NULL)
3694 gst_task_set_lock (playbin->activation_task, &playbin->activation_lock);
3696 GST_LOG_OBJECT (playbin, "clearing shutdown flag");
3697 g_atomic_int_set (&playbin->shutdown, 0);
3698 do_async_start (playbin);
3700 GST_PLAY_BIN3_UNLOCK (playbin);
3706 GST_PLAY_BIN3_UNLOCK (playbin);
3707 GST_ERROR_OBJECT (playbin, "Failed to create task");
3713 gst_play_bin3_stop (GstPlayBin3 * playbin)
3717 GST_DEBUG_OBJECT (playbin, "stopping");
3719 /* FIXME unlock our waiting groups */
3720 GST_LOG_OBJECT (playbin, "setting shutdown flag");
3721 g_atomic_int_set (&playbin->shutdown, 1);
3723 /* wait for all callbacks to end by taking the lock.
3724 * No dynamic (critical) new callbacks will
3725 * be able to happen as we set the shutdown flag. */
3726 GST_PLAY_BIN3_DYN_LOCK (playbin);
3727 GST_LOG_OBJECT (playbin, "dynamic lock taken, we can continue shutdown");
3728 GST_PLAY_BIN3_DYN_UNLOCK (playbin);
3730 /* Stop the activation task */
3731 GST_PLAY_BIN3_LOCK (playbin);
3732 if ((task = playbin->activation_task)) {
3733 playbin->activation_task = NULL;
3734 GST_PLAY_BIN3_UNLOCK (playbin);
3736 gst_task_stop (task);
3738 /* Make sure task is not running */
3739 g_rec_mutex_lock (&playbin->activation_lock);
3740 g_rec_mutex_unlock (&playbin->activation_lock);
3742 /* Wait for task to finish and unref it */
3743 gst_task_join (task);
3744 gst_object_unref (task);
3746 GST_PLAY_BIN3_LOCK (playbin);
3748 GST_PLAY_BIN3_UNLOCK (playbin);
3751 static GstStateChangeReturn
3752 gst_play_bin3_change_state (GstElement * element, GstStateChange transition)
3754 GstStateChangeReturn ret;
3755 GstPlayBin3 *playbin;
3756 gboolean do_save = FALSE;
3758 playbin = GST_PLAY_BIN3 (element);
3760 switch (transition) {
3761 case GST_STATE_CHANGE_READY_TO_PAUSED:
3762 if (!gst_play_bin3_start (playbin))
3763 return GST_STATE_CHANGE_FAILURE;
3765 case GST_STATE_CHANGE_PAUSED_TO_READY:
3767 gst_play_bin3_stop (playbin);
3770 case GST_STATE_CHANGE_READY_TO_NULL:
3771 /* we go async to PAUSED, so if that fails, we never make it to PAUSED
3772 * and we will never be called with the GST_STATE_CHANGE_PAUSED_TO_READY.
3773 * Make sure we do go through the same steps (see above) for
3775 if (!g_atomic_int_get (&playbin->shutdown)) {
3780 /* unlock so that all groups go to NULL */
3781 groups_set_locked_state (playbin, FALSE);
3787 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
3788 if (ret == GST_STATE_CHANGE_FAILURE)
3791 switch (transition) {
3792 case GST_STATE_CHANGE_READY_TO_PAUSED:
3793 if ((ret = setup_next_source (playbin)) == GST_STATE_CHANGE_FAILURE)
3795 if (ret == GST_STATE_CHANGE_SUCCESS)
3796 ret = GST_STATE_CHANGE_ASYNC;
3799 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
3800 do_async_done (playbin);
3801 /* FIXME Release audio device when we implement that */
3803 case GST_STATE_CHANGE_PAUSED_TO_READY:
3804 playbin->is_live = FALSE;
3805 save_current_group (playbin);
3807 case GST_STATE_CHANGE_READY_TO_NULL:
3811 /* also do missed state change down to READY */
3813 save_current_group (playbin);
3814 /* Deactivate the groups, set uridecodebin to NULL and unref it */
3815 GST_PLAY_BIN3_LOCK (playbin);
3816 for (i = 0; i < 2; i++) {
3817 if (playbin->groups[i].active && playbin->groups[i].valid) {
3818 deactivate_group (playbin, &playbin->groups[i]);
3819 playbin->groups[i].valid = FALSE;
3822 if (playbin->groups[i].uridecodebin) {
3823 gst_element_set_state (playbin->groups[i].uridecodebin,
3825 gst_object_unref (playbin->groups[i].uridecodebin);
3826 playbin->groups[i].uridecodebin = NULL;
3830 GST_PLAY_BIN3_UNLOCK (playbin);
3832 /* Set our sinks back to NULL, they might not be child of playbin */
3833 if (playbin->audio_sink)
3834 gst_element_set_state (playbin->audio_sink, GST_STATE_NULL);
3835 if (playbin->video_sink)
3836 gst_element_set_state (playbin->video_sink, GST_STATE_NULL);
3837 if (playbin->text_sink)
3838 gst_element_set_state (playbin->text_sink, GST_STATE_NULL);
3840 if (playbin->video_stream_combiner)
3841 gst_element_set_state (playbin->video_stream_combiner, GST_STATE_NULL);
3842 if (playbin->audio_stream_combiner)
3843 gst_element_set_state (playbin->audio_stream_combiner, GST_STATE_NULL);
3844 if (playbin->text_stream_combiner)
3845 gst_element_set_state (playbin->text_stream_combiner, GST_STATE_NULL);
3847 /* make sure the groups don't perform a state change anymore until we
3848 * enable them again */
3849 groups_set_locked_state (playbin, TRUE);
3856 if (GST_STATE_TRANSITION_NEXT (transition) == GST_STATE_PAUSED)
3857 playbin->is_live = ret == GST_STATE_CHANGE_NO_PREROLL;
3859 if (ret == GST_STATE_CHANGE_NO_PREROLL)
3860 do_async_done (playbin);
3867 do_async_done (playbin);
3869 if (transition == GST_STATE_CHANGE_READY_TO_PAUSED) {
3870 GstSourceGroup *curr_group;
3872 GST_PLAY_BIN3_LOCK (playbin);
3874 curr_group = playbin->curr_group;
3876 if (curr_group->active && curr_group->valid) {
3877 /* unlink our pads with the sink */
3878 deactivate_group (playbin, curr_group);
3880 curr_group->valid = FALSE;
3883 /* Swap current and next group back */
3884 playbin->curr_group = playbin->next_group;
3885 playbin->next_group = curr_group;
3887 GST_PLAY_BIN3_UNLOCK (playbin);
3894 gst_play_bin3_overlay_expose (GstVideoOverlay * overlay)
3896 GstPlayBin3 *playbin = GST_PLAY_BIN3 (overlay);
3898 gst_video_overlay_expose (GST_VIDEO_OVERLAY (playbin->playsink));
3902 gst_play_bin3_overlay_handle_events (GstVideoOverlay * overlay,
3903 gboolean handle_events)
3905 GstPlayBin3 *playbin = GST_PLAY_BIN3 (overlay);
3907 gst_video_overlay_handle_events (GST_VIDEO_OVERLAY (playbin->playsink),
3912 gst_play_bin3_overlay_set_render_rectangle (GstVideoOverlay * overlay, gint x,
3913 gint y, gint width, gint height)
3915 GstPlayBin3 *playbin = GST_PLAY_BIN3 (overlay);
3917 gst_video_overlay_set_render_rectangle (GST_VIDEO_OVERLAY (playbin->playsink),
3918 x, y, width, height);
3922 gst_play_bin3_overlay_set_window_handle (GstVideoOverlay * overlay,
3925 GstPlayBin3 *playbin = GST_PLAY_BIN3 (overlay);
3927 gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (playbin->playsink),
3932 gst_play_bin3_overlay_init (gpointer g_iface, gpointer g_iface_data)
3934 GstVideoOverlayInterface *iface = (GstVideoOverlayInterface *) g_iface;
3935 iface->expose = gst_play_bin3_overlay_expose;
3936 iface->handle_events = gst_play_bin3_overlay_handle_events;
3937 iface->set_render_rectangle = gst_play_bin3_overlay_set_render_rectangle;
3938 iface->set_window_handle = gst_play_bin3_overlay_set_window_handle;
3942 gst_play_bin3_navigation_send_event (GstNavigation * navigation,
3945 GstPlayBin3 *playbin = GST_PLAY_BIN3 (navigation);
3947 gst_navigation_send_event_simple (GST_NAVIGATION (playbin->playsink), event);
3951 gst_play_bin3_navigation_init (gpointer g_iface, gpointer g_iface_data)
3953 GstNavigationInterface *iface = (GstNavigationInterface *) g_iface;
3955 iface->send_event_simple = gst_play_bin3_navigation_send_event;
3958 static const GList *
3959 gst_play_bin3_colorbalance_list_channels (GstColorBalance * balance)
3961 GstPlayBin3 *playbin = GST_PLAY_BIN3 (balance);
3964 gst_color_balance_list_channels (GST_COLOR_BALANCE (playbin->playsink));
3968 gst_play_bin3_colorbalance_set_value (GstColorBalance * balance,
3969 GstColorBalanceChannel * channel, gint value)
3971 GstPlayBin3 *playbin = GST_PLAY_BIN3 (balance);
3973 gst_color_balance_set_value (GST_COLOR_BALANCE (playbin->playsink), channel,
3978 gst_play_bin3_colorbalance_get_value (GstColorBalance * balance,
3979 GstColorBalanceChannel * channel)
3981 GstPlayBin3 *playbin = GST_PLAY_BIN3 (balance);
3983 return gst_color_balance_get_value (GST_COLOR_BALANCE (playbin->playsink),
3987 static GstColorBalanceType
3988 gst_play_bin3_colorbalance_get_balance_type (GstColorBalance * balance)
3990 GstPlayBin3 *playbin = GST_PLAY_BIN3 (balance);
3993 gst_color_balance_get_balance_type (GST_COLOR_BALANCE
3994 (playbin->playsink));
3998 gst_play_bin3_colorbalance_init (gpointer g_iface, gpointer g_iface_data)
4000 GstColorBalanceInterface *iface = (GstColorBalanceInterface *) g_iface;
4002 iface->list_channels = gst_play_bin3_colorbalance_list_channels;
4003 iface->set_value = gst_play_bin3_colorbalance_set_value;
4004 iface->get_value = gst_play_bin3_colorbalance_get_value;
4005 iface->get_balance_type = gst_play_bin3_colorbalance_get_balance_type;
4009 gst_play_bin3_custom_element_init (GstPlugin * plugin)
4011 gboolean ret = TRUE;
4013 GST_DEBUG_CATEGORY_INIT (gst_play_bin3_debug, "playbin3", 0, "play bin3");
4015 playback_element_init (plugin);
4017 if (g_getenv ("USE_PLAYBIN3")) {
4018 ret &= gst_element_register (plugin, "playbin", GST_RANK_NONE,
4022 ret &= gst_element_register (plugin, "playbin3", GST_RANK_NONE,