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 <gst/gst-i18n-plugin.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 typedef GstCaps *(*SourceCombineGetMediaCapsFunc) (void);
258 /* GstSourceCombine controls all the information regarding a certain
261 * It can control a custom combiner element (by default none)
263 struct _GstSourceCombine
265 const gchar *media_type; /* the media type for the combiner */
266 SourceCombineGetMediaCapsFunc get_media_caps; /* more complex caps for the combiner */
267 GstPlaySinkType type; /* the sink pad type of the combiner */
268 GstStreamType stream_type; /* The GstStreamType of the combiner */
270 GstElement *combiner; /* the combiner */
271 GPtrArray *channels; /* Array of GstPad ? */
273 GstPad *srcpad; /* the source pad of the combiner */
274 GstPad *sinkpad; /* the sinkpad of the sink when the combiner
277 GPtrArray *streams; /* Sorted array of GstStream for the given type */
279 gboolean has_active_pad; /* stream combiner has the "active-pad" property */
281 gboolean is_concat; /* The stream combiner is the 'concat' element */
284 #define GST_SOURCE_GROUP_GET_LOCK(group) (&((GstSourceGroup*)(group))->lock)
285 #define GST_SOURCE_GROUP_LOCK(group) (g_mutex_lock (GST_SOURCE_GROUP_GET_LOCK(group)))
286 #define GST_SOURCE_GROUP_UNLOCK(group) (g_mutex_unlock (GST_SOURCE_GROUP_GET_LOCK(group)))
290 PLAYBIN_STREAM_AUDIO = 0,
291 PLAYBIN_STREAM_VIDEO,
296 /* names matching the enum above */
297 static const gchar *stream_type_names[] = {
298 "audio", "video", "text"
302 #define STREAM_TYPES_FORMAT "s%s%s"
303 #define STREAM_TYPES_ARGS(s) (s) & GST_STREAM_TYPE_AUDIO ? "audio " : "", \
304 (s) & GST_STREAM_TYPE_VIDEO ? "video " : "", \
305 (s) & GST_STREAM_TYPE_TEXT ? "text " : ""
309 #if 0 /* AUTOPLUG DISABLED */
310 static void avelements_free (gpointer data);
311 static GSequence *avelements_create (GstPlayBin3 * playbin,
312 gboolean isaudioelement);
315 /* The GstAudioVideoElement structure holding the audio/video decoder
316 * and the audio/video sink factories together with field indicating
317 * the number of common caps features */
320 GstElementFactory *dec; /* audio:video decoder */
321 GstElementFactory *sink; /* audio:video sink */
322 guint n_comm_cf; /* number of common caps features */
325 /* a structure to hold information about a uridecodebin pad */
328 GstPad *pad; /* The controlled pad */
329 GstStreamType stream_type; /* stream type of the controlled pad */
330 gulong event_probe_id;
333 /* a structure to hold the objects for decoding a uri and the subtitle uri
335 struct _GstSourceGroup
337 GstPlayBin3 *playbin;
341 gboolean valid; /* the group has valid info to start playback */
342 gboolean active; /* the group is active */
344 gboolean playing; /* the group is currently playing
345 * (outputted on the sinks) */
351 /* The currently outputted group_id */
354 /* Bit-wise set of stream types we have requested from uridecodebin3 */
355 GstStreamType selected_stream_types;
357 /* Bit-wise set of stream types for which pads are present */
358 GstStreamType present_stream_types;
360 /* TRUE if a 'about-to-finish' needs to be posted once we have
361 * got source pads for all requested stream types
363 * FIXME : Move this logic to uridecodebin3 later */
364 gboolean pending_about_to_finish;
366 /* uridecodebin to handle uri and suburi */
367 GstElement *uridecodebin;
369 /* Active sinks for each media type. These are initialized with
370 * the configured or currently used sink, otherwise
371 * left as NULL and playbin tries to automatically
372 * select a good sink */
373 GstElement *audio_sink;
374 GstElement *video_sink;
375 GstElement *text_sink;
377 /* List of source pads */
380 /* uridecodebin signals */
382 gulong pad_removed_id;
383 gulong select_stream_id;
384 gulong source_setup_id;
385 gulong about_to_finish_id;
387 #if 0 /* AUTOPLUG DISABLED */
388 gulong autoplug_factories_id;
389 gulong autoplug_select_id;
390 gulong autoplug_continue_id;
391 gulong autoplug_query_id;
394 gboolean stream_changed_pending;
396 /* Active stream collection */
397 GstStreamCollection *collection;
400 /* buffering message stored for after switching */
401 GstMessage *pending_buffering_msg;
404 #define GST_PLAY_BIN3_GET_LOCK(bin) (&((GstPlayBin3*)(bin))->lock)
405 #define GST_PLAY_BIN3_LOCK(bin) (g_rec_mutex_lock (GST_PLAY_BIN3_GET_LOCK(bin)))
406 #define GST_PLAY_BIN3_UNLOCK(bin) (g_rec_mutex_unlock (GST_PLAY_BIN3_GET_LOCK(bin)))
408 /* lock to protect dynamic callbacks, like no-more-pads */
409 #define GST_PLAY_BIN3_DYN_LOCK(bin) g_mutex_lock (&(bin)->dyn_lock)
410 #define GST_PLAY_BIN3_DYN_UNLOCK(bin) g_mutex_unlock (&(bin)->dyn_lock)
412 /* lock for shutdown */
413 #define GST_PLAY_BIN3_SHUTDOWN_LOCK(bin,label) \
415 if (G_UNLIKELY (g_atomic_int_get (&bin->shutdown))) \
417 GST_PLAY_BIN3_DYN_LOCK (bin); \
418 if (G_UNLIKELY (g_atomic_int_get (&bin->shutdown))) { \
419 GST_PLAY_BIN3_DYN_UNLOCK (bin); \
424 /* unlock for shutdown */
425 #define GST_PLAY_BIN3_SHUTDOWN_UNLOCK(bin) \
426 GST_PLAY_BIN3_DYN_UNLOCK (bin); \
431 * playbin element structure
437 GRecMutex lock; /* to protect group switching */
439 /* the input groups, we use a double buffer to switch between current and next */
440 GstSourceGroup groups[2]; /* array with group info */
441 GstSourceGroup *curr_group; /* pointer to the currently playing group */
442 GstSourceGroup *next_group; /* pointer to the next group */
444 /* Array of GstPad controlled by each combiner */
445 GPtrArray *channels[PLAYBIN_STREAM_LAST]; /* links to combiner pads */
447 /* combiners for different streams */
448 GstSourceCombine combiner[PLAYBIN_STREAM_LAST];
450 /* Bit-wise set of stream types we have requested from uridecodebin3.
451 * Calculated as the combination of the 'selected_stream_types' of
452 * each sourcegroup */
453 GstStreamType selected_stream_types;
455 /* Bit-wise set of configured output stream types (i.e. active
456 playsink inputs and combiners) */
457 GstStreamType active_stream_types;
460 guint64 connection_speed; /* connection speed in bits/sec (0 = unknown) */
461 gint current_video; /* the currently selected stream */
462 gint current_audio; /* the currently selected stream */
463 gint current_text; /* the currently selected stream */
465 gboolean do_stream_selections; /* Set to TRUE when any of current-{video|audio|text} are set to
466 say playbin should do backwards-compatibility behaviours */
468 guint64 buffer_duration; /* When buffering, the max buffer duration (ns) */
469 guint buffer_size; /* When buffering, the max buffer size (bytes) */
470 gboolean force_aspect_ratio;
472 /* Multiview/stereoscopic overrides */
473 GstVideoMultiviewFramePacking multiview_mode;
474 GstVideoMultiviewFlags multiview_flags;
477 GstPlaySink *playsink;
479 /* Task for (de)activating groups, protected by the activation lock */
480 GstTask *activation_task;
481 GRecMutex activation_lock;
483 /* lock protecting dynamic adding/removing */
485 /* if we are shutting down or not */
487 gboolean async_pending; /* async-start has been emitted */
489 GMutex elements_lock;
490 guint32 elements_cookie;
491 GList *elements; /* factories we can use for selecting elements */
493 gboolean have_selector; /* set to FALSE when we fail to create an
494 * input-selector, so that we only post a
497 gboolean video_pending_flush_finish; /* whether we are pending to send a custom
498 * custom-video-flush-finish event
499 * on pad activation */
500 gboolean audio_pending_flush_finish; /* whether we are pending to send a custom
501 * custom-audio-flush-finish event
502 * on pad activation */
503 gboolean text_pending_flush_finish; /* whether we are pending to send a custom
504 * custom-subtitle-flush-finish event
505 * on pad activation */
507 GstElement *audio_sink; /* configured audio sink, or NULL */
508 GstElement *video_sink; /* configured video sink, or NULL */
509 GstElement *text_sink; /* configured text sink, or NULL */
511 GstElement *audio_stream_combiner; /* configured audio stream combiner, or NULL */
512 GstElement *video_stream_combiner; /* configured video stream combiner, or NULL */
513 GstElement *text_stream_combiner; /* configured text stream combiner, or NULL */
515 GSequence *aelements; /* a list of GstAVElements for audio stream */
516 GSequence *velements; /* a list of GstAVElements for video stream */
518 guint64 ring_buffer_max_size; /* 0 means disabled */
521 struct _GstPlayBin3Class
523 GstPipelineClass parent_class;
525 /* notify app that the current uri finished decoding and it is possible to
526 * queue a new one for gapless playback */
527 void (*about_to_finish) (GstPlayBin3 * playbin);
529 /* get the last video sample and convert it to the given caps */
530 GstSample *(*convert_sample) (GstPlayBin3 * playbin, GstCaps * caps);
534 #define DEFAULT_URI NULL
535 #define DEFAULT_SUBURI NULL
536 #define DEFAULT_FLAGS GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_TEXT | \
537 GST_PLAY_FLAG_SOFT_VOLUME | GST_PLAY_FLAG_DEINTERLACE | \
538 GST_PLAY_FLAG_SOFT_COLORBALANCE | GST_PLAY_FLAG_BUFFERING
539 #define DEFAULT_CURRENT_VIDEO -1
540 #define DEFAULT_CURRENT_AUDIO -1
541 #define DEFAULT_CURRENT_TEXT -1
542 #define DEFAULT_SUBTITLE_ENCODING NULL
543 #define DEFAULT_AUDIO_SINK NULL
544 #define DEFAULT_VIDEO_SINK NULL
545 #define DEFAULT_VIS_PLUGIN NULL
546 #define DEFAULT_TEXT_SINK NULL
547 #define DEFAULT_VOLUME 1.0
548 #define DEFAULT_MUTE FALSE
549 #define DEFAULT_FRAME NULL
550 #define DEFAULT_FONT_DESC NULL
551 #define DEFAULT_CONNECTION_SPEED 0
552 #define DEFAULT_BUFFER_DURATION -1
553 #define DEFAULT_BUFFER_SIZE -1
554 #define DEFAULT_RING_BUFFER_MAX_SIZE 0
564 PROP_SUBTITLE_ENCODING,
569 PROP_VIDEO_STREAM_COMBINER,
570 PROP_AUDIO_STREAM_COMBINER,
571 PROP_TEXT_STREAM_COMBINER,
576 PROP_CONNECTION_SPEED,
578 PROP_BUFFER_DURATION,
581 PROP_RING_BUFFER_MAX_SIZE,
582 PROP_FORCE_ASPECT_RATIO,
592 SIGNAL_ABOUT_TO_FINISH,
593 SIGNAL_CONVERT_SAMPLE,
595 SIGNAL_ELEMENT_SETUP,
599 #if 0 /* AUTOPLUG DISABLED */
600 static GstStaticCaps raw_audio_caps = GST_STATIC_CAPS ("audio/x-raw(ANY)");
601 static GstStaticCaps raw_video_caps = GST_STATIC_CAPS ("video/x-raw(ANY)");
604 static void gst_play_bin3_finalize (GObject * object);
606 static void gst_play_bin3_set_property (GObject * object, guint prop_id,
607 const GValue * value, GParamSpec * spec);
608 static void gst_play_bin3_get_property (GObject * object, guint prop_id,
609 GValue * value, GParamSpec * spec);
611 static GstStateChangeReturn gst_play_bin3_change_state (GstElement * element,
612 GstStateChange transition);
614 static void gst_play_bin3_handle_message (GstBin * bin, GstMessage * message);
615 static void gst_play_bin3_deep_element_added (GstBin * playbin,
616 GstBin * sub_bin, GstElement * child);
617 static gboolean gst_play_bin3_send_event (GstElement * element,
620 static GstSample *gst_play_bin3_convert_sample (GstPlayBin3 * playbin,
623 static GstStateChangeReturn setup_next_source (GstPlayBin3 * playbin);
625 static void gst_play_bin3_check_group_status (GstPlayBin3 * playbin);
626 static void emit_about_to_finish (GstPlayBin3 * playbin);
627 static void reconfigure_output (GstPlayBin3 * playbin);
628 static void pad_removed_cb (GstElement * decodebin, GstPad * pad,
629 GstSourceGroup * group);
631 static gint select_stream_cb (GstElement * decodebin,
632 GstStreamCollection * collection, GstStream * stream,
633 GstSourceGroup * group);
635 static void do_stream_selection (GstPlayBin3 * playbin, GstSourceGroup * group);
637 static GstElementClass *parent_class;
639 static guint gst_play_bin3_signals[LAST_SIGNAL] = { 0 };
641 #define REMOVE_SIGNAL(obj,id) \
643 g_signal_handler_disconnect (obj, id); \
647 static void gst_play_bin3_overlay_init (gpointer g_iface,
648 gpointer g_iface_data);
649 static void gst_play_bin3_navigation_init (gpointer g_iface,
650 gpointer g_iface_data);
651 static void gst_play_bin3_colorbalance_init (gpointer g_iface,
652 gpointer g_iface_data);
655 _do_init_type (GType type)
657 static const GInterfaceInfo svol_info = {
660 static const GInterfaceInfo ov_info = {
661 gst_play_bin3_overlay_init,
664 static const GInterfaceInfo nav_info = {
665 gst_play_bin3_navigation_init,
668 static const GInterfaceInfo col_info = {
669 gst_play_bin3_colorbalance_init,
673 g_type_add_interface_static (type, GST_TYPE_STREAM_VOLUME, &svol_info);
674 g_type_add_interface_static (type, GST_TYPE_VIDEO_OVERLAY, &ov_info);
675 g_type_add_interface_static (type, GST_TYPE_NAVIGATION, &nav_info);
676 g_type_add_interface_static (type, GST_TYPE_COLOR_BALANCE, &col_info);
679 static GType gst_play_bin3_get_type (void);
680 G_DEFINE_TYPE_WITH_CODE (GstPlayBin3, gst_play_bin3, GST_TYPE_PIPELINE,
681 _do_init_type (g_define_type_id));
683 GST_ELEMENT_REGISTER_DEFINE_CUSTOM (playbin3,
684 gst_play_bin3_custom_element_init);
687 gst_play_bin3_class_init (GstPlayBin3Class * klass)
689 GObjectClass *gobject_klass;
690 GstElementClass *gstelement_klass;
691 GstBinClass *gstbin_klass;
693 gobject_klass = (GObjectClass *) klass;
694 gstelement_klass = (GstElementClass *) klass;
695 gstbin_klass = (GstBinClass *) klass;
697 parent_class = g_type_class_peek_parent (klass);
699 gobject_klass->set_property = gst_play_bin3_set_property;
700 gobject_klass->get_property = gst_play_bin3_get_property;
702 gobject_klass->finalize = gst_play_bin3_finalize;
707 * Set the next URI that playbin will play. This property can be set from the
708 * about-to-finish signal to queue the next media file.
710 g_object_class_install_property (gobject_klass, PROP_URI,
711 g_param_spec_string ("uri", "URI", "URI of the media to play",
712 NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
715 * GstPlayBin3:current-uri
717 * The currently playing uri.
719 g_object_class_install_property (gobject_klass, PROP_CURRENT_URI,
720 g_param_spec_string ("current-uri", "Current URI",
721 "The currently playing URI", NULL,
722 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
727 * Set the next subtitle URI that playbin will play. This property can be
728 * set from the about-to-finish signal to queue the next subtitle media file.
730 g_object_class_install_property (gobject_klass, PROP_SUBURI,
731 g_param_spec_string ("suburi", ".sub-URI", "Optional URI of a subtitle",
732 NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
735 * GstPlayBin3:current-suburi
737 * The currently playing subtitle uri.
739 g_object_class_install_property (gobject_klass, PROP_CURRENT_SUBURI,
740 g_param_spec_string ("current-suburi", "Current .sub-URI",
741 "The currently playing URI of a subtitle",
742 NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
747 * Control the behaviour of playbin.
749 g_object_class_install_property (gobject_klass, PROP_FLAGS,
750 g_param_spec_flags ("flags", "Flags", "Flags to control behaviour",
751 GST_TYPE_PLAY_FLAGS, DEFAULT_FLAGS,
752 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
754 g_object_class_install_property (gobject_klass, PROP_SUBTITLE_ENCODING,
755 g_param_spec_string ("subtitle-encoding", "subtitle encoding",
756 "Encoding to assume if input subtitles are not in UTF-8 encoding. "
757 "If not set, the GST_SUBTITLE_ENCODING environment variable will "
758 "be checked for an encoding to use. If that is not set either, "
759 "ISO-8859-15 will be assumed.", NULL,
760 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
762 g_object_class_install_property (gobject_klass, PROP_VIDEO_FILTER,
763 g_param_spec_object ("video-filter", "Video filter",
764 "the video filter(s) to apply, if possible",
765 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
766 g_object_class_install_property (gobject_klass, PROP_AUDIO_FILTER,
767 g_param_spec_object ("audio-filter", "Audio filter",
768 "the audio filter(s) to apply, if possible",
769 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
771 * GstPlayBin3:video-sink
773 * Get or set the video sink to use for video output. If set to
774 * NULL, one will be auto-selected. To disable video entirely, unset
775 * the VIDEO flag in the #GstPlayBin3:flags property.
778 g_object_class_install_property (gobject_klass, PROP_VIDEO_SINK,
779 g_param_spec_object ("video-sink", "Video Sink",
780 "the video output element to use (NULL = default sink)",
781 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
783 * GstPlayBin3:audio-sink
785 * Get or set the audio sink to use for audio output. If set to
786 * NULL, one will be auto-selected. To disable audio entirely, unset
787 * the AUDIO flag in the #GstPlayBin3:flags property.
790 g_object_class_install_property (gobject_klass, PROP_AUDIO_SINK,
791 g_param_spec_object ("audio-sink", "Audio Sink",
792 "the audio output element to use (NULL = default sink)",
793 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
794 g_object_class_install_property (gobject_klass, PROP_VIS_PLUGIN,
795 g_param_spec_object ("vis-plugin", "Vis plugin",
796 "the visualization element to use (NULL = default)",
797 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
798 g_object_class_install_property (gobject_klass, PROP_TEXT_SINK,
799 g_param_spec_object ("text-sink", "Text plugin",
800 "the text output element to use (NULL = default subtitleoverlay)",
801 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
803 * GstPlayBin3:video-stream-combiner
805 * Get or set the current video stream combiner. By default, no
806 * element is used and the selected stream is used directly.
808 g_object_class_install_property (gobject_klass, PROP_VIDEO_STREAM_COMBINER,
809 g_param_spec_object ("video-stream-combiner", "Video stream combiner",
810 "Current video stream combiner (default: none)",
811 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
814 * GstPlayBin3:audio-stream-combiner
816 * Get or set the current audio stream combiner. By default, no
817 * element is used and the selected stream is used directly.
819 g_object_class_install_property (gobject_klass, PROP_AUDIO_STREAM_COMBINER,
820 g_param_spec_object ("audio-stream-combiner", "Audio stream combiner",
821 "Current audio stream combiner (default: none))",
822 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
825 * GstPlayBin3:text-stream-combiner
827 * Get or set the current text stream combiner. By default, no
828 * element is used and the selected stream is used directly.
830 g_object_class_install_property (gobject_klass, PROP_TEXT_STREAM_COMBINER,
831 g_param_spec_object ("text-stream-combiner", "Text stream combiner",
832 "Current text stream combiner (default: none)",
833 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
836 * GstPlayBin3:volume:
838 * Get or set the current audio stream volume. 1.0 means 100%,
839 * 0.0 means mute. This uses a linear volume scale.
842 g_object_class_install_property (gobject_klass, PROP_VOLUME,
843 g_param_spec_double ("volume", "Volume", "The audio volume, 1.0=100%",
844 0.0, VOLUME_MAX_DOUBLE, 1.0,
845 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
846 g_object_class_install_property (gobject_klass, PROP_MUTE,
847 g_param_spec_boolean ("mute", "Mute",
848 "Mute the audio channel without changing the volume", FALSE,
849 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
852 * GstPlayBin3:sample:
853 * @playbin: a #GstPlayBin3
855 * Get the currently rendered or prerolled sample in the video sink.
856 * The #GstCaps in the sample will describe the format of the buffer.
858 g_object_class_install_property (gobject_klass, PROP_SAMPLE,
859 g_param_spec_boxed ("sample", "Sample",
860 "The last sample (NULL = no video available)",
861 GST_TYPE_SAMPLE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
863 g_object_class_install_property (gobject_klass, PROP_FONT_DESC,
864 g_param_spec_string ("subtitle-font-desc",
865 "Subtitle font description",
866 "Pango font description of font "
867 "to be used for subtitle rendering", NULL,
868 G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
870 g_object_class_install_property (gobject_klass, PROP_CONNECTION_SPEED,
871 g_param_spec_uint64 ("connection-speed", "Connection Speed",
872 "Network connection speed in kbps (0 = unknown)",
873 0, G_MAXUINT64 / 1000, DEFAULT_CONNECTION_SPEED,
874 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
876 g_object_class_install_property (gobject_klass, PROP_BUFFER_SIZE,
877 g_param_spec_int ("buffer-size", "Buffer size (bytes)",
878 "Buffer size when buffering network streams",
879 -1, G_MAXINT, DEFAULT_BUFFER_SIZE,
880 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
881 g_object_class_install_property (gobject_klass, PROP_BUFFER_DURATION,
882 g_param_spec_int64 ("buffer-duration", "Buffer duration (ns)",
883 "Buffer duration when buffering network streams",
884 -1, G_MAXINT64, DEFAULT_BUFFER_DURATION,
885 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
887 * GstPlayBin3:av-offset:
889 * Control the synchronisation offset between the audio and video streams.
890 * Positive values make the audio ahead of the video and negative values make
891 * the audio go behind the video.
893 g_object_class_install_property (gobject_klass, PROP_AV_OFFSET,
894 g_param_spec_int64 ("av-offset", "AV Offset",
895 "The synchronisation offset between audio and video in nanoseconds",
896 G_MININT64, G_MAXINT64, 0,
897 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
899 * GstPlayBin3:text-offset:
901 * Control the synchronisation offset between the text and video streams.
902 * Positive values make the text ahead of the video and negative values make
903 * the text go behind the video.
905 g_object_class_install_property (gobject_klass, PROP_TEXT_OFFSET,
906 g_param_spec_int64 ("text-offset", "Text Offset",
907 "The synchronisation offset between text and video in nanoseconds",
908 G_MININT64, G_MAXINT64, 0,
909 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
912 * GstPlayBin3:ring-buffer-max-size
914 * The maximum size of the ring buffer in bytes. If set to 0, the ring
915 * buffer is disabled. Default 0.
917 g_object_class_install_property (gobject_klass, PROP_RING_BUFFER_MAX_SIZE,
918 g_param_spec_uint64 ("ring-buffer-max-size",
919 "Max. ring buffer size (bytes)",
920 "Max. amount of data in the ring buffer (bytes, 0 = ring buffer disabled)",
921 0, G_MAXUINT, DEFAULT_RING_BUFFER_MAX_SIZE,
922 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
925 * GstPlayBin3::force-aspect-ratio:
927 * Requests the video sink to enforce the video display aspect ratio.
929 g_object_class_install_property (gobject_klass, PROP_FORCE_ASPECT_RATIO,
930 g_param_spec_boolean ("force-aspect-ratio", "Force Aspect Ratio",
931 "When enabled, scaling will respect original aspect ratio", TRUE,
932 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
935 * GstPlayBin3::video-multiview-mode:
937 * Set the stereoscopic mode for video streams that don't contain
938 * any information in the stream, so they can be correctly played
939 * as 3D streams. If a video already has multiview information
940 * encoded, this property can override other modes in the set,
941 * but cannot be used to re-interpret MVC or mixed-mono streams.
943 * See Also: The #GstPlayBin3::video-multiview-flags property
946 g_object_class_install_property (gobject_klass, PROP_MULTIVIEW_MODE,
947 g_param_spec_enum ("video-multiview-mode",
948 "Multiview Mode Override",
949 "Re-interpret a video stream as one of several frame-packed stereoscopic modes.",
950 GST_TYPE_VIDEO_MULTIVIEW_FRAME_PACKING,
951 GST_VIDEO_MULTIVIEW_FRAME_PACKING_NONE,
952 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
955 * GstPlayBin3::video-multiview-flags:
957 * When overriding the multiview mode of an input stream,
958 * these flags modify details of the view layout.
960 * See Also: The #GstPlayBin3::video-multiview-mode property
962 g_object_class_install_property (gobject_klass, PROP_MULTIVIEW_FLAGS,
963 g_param_spec_flags ("video-multiview-flags",
964 "Multiview Flags Override",
965 "Override details of the multiview frame layout",
966 GST_TYPE_VIDEO_MULTIVIEW_FLAGS, GST_VIDEO_MULTIVIEW_FLAGS_NONE,
967 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
970 * GstPlayBin3::about-to-finish
971 * @playbin: a #GstPlayBin3
973 * This signal is emitted when the current uri is about to finish. You can
974 * set the uri and suburi to make sure that playback continues.
976 * This signal is emitted from the context of a GStreamer streaming thread.
978 gst_play_bin3_signals[SIGNAL_ABOUT_TO_FINISH] =
979 g_signal_new ("about-to-finish", G_TYPE_FROM_CLASS (klass),
981 G_STRUCT_OFFSET (GstPlayBin3Class, about_to_finish), NULL, NULL,
982 NULL, G_TYPE_NONE, 0, G_TYPE_NONE);
986 * GstPlayBin3::source-setup:
987 * @playbin: a #GstPlayBin3
988 * @source: source element
990 * This signal is emitted after the source element has been created, so
991 * it can be configured by setting additional properties (e.g. set a
992 * proxy server for an http source, or set the device and read speed for
993 * an audio cd source). This is functionally equivalent to connecting to
994 * the notify::source signal, but more convenient.
996 * This signal is usually emitted from the context of a GStreamer streaming
999 gst_play_bin3_signals[SIGNAL_SOURCE_SETUP] =
1000 g_signal_new ("source-setup", G_TYPE_FROM_CLASS (klass),
1001 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
1004 * GstPlayBin3::element-setup:
1005 * @playbin: a #GstPlayBin3
1006 * @element: an element that was added to the playbin hierarchy
1008 * This signal is emitted when a new element is added to playbin or any of
1009 * its sub-bins. This signal can be used to configure elements, e.g. to set
1010 * properties on decoders. This is functionally equivalent to connecting to
1011 * the deep-element-added signal, but more convenient.
1013 * This signal is usually emitted from the context of a GStreamer streaming
1014 * thread, so might be called at the same time as code running in the main
1015 * application thread.
1019 gst_play_bin3_signals[SIGNAL_ELEMENT_SETUP] =
1020 g_signal_new ("element-setup", G_TYPE_FROM_CLASS (klass),
1021 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
1024 * GstPlayBin3::convert-sample
1025 * @playbin: a #GstPlayBin3
1026 * @caps: the target format of the frame
1028 * Action signal to retrieve the currently playing video frame in the format
1029 * specified by @caps.
1030 * If @caps is %NULL, no conversion will be performed and this function is
1031 * equivalent to the #GstPlayBin3:sample property.
1033 * Returns: a #GstSample of the current video frame converted to #caps.
1034 * The caps on the sample will describe the final layout of the buffer data.
1035 * %NULL is returned when no current buffer can be retrieved or when the
1036 * conversion failed.
1038 gst_play_bin3_signals[SIGNAL_CONVERT_SAMPLE] =
1039 g_signal_new ("convert-sample", G_TYPE_FROM_CLASS (klass),
1040 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1041 G_STRUCT_OFFSET (GstPlayBin3Class, convert_sample), NULL, NULL,
1042 NULL, GST_TYPE_SAMPLE, 1, GST_TYPE_CAPS);
1044 klass->convert_sample = gst_play_bin3_convert_sample;
1046 gst_element_class_set_static_metadata (gstelement_klass,
1047 "Player Bin 3", "Generic/Bin/Player",
1048 "Autoplug and play media from an uri",
1049 "Wim Taymans <wim.taymans@gmail.com>");
1051 gstelement_klass->change_state =
1052 GST_DEBUG_FUNCPTR (gst_play_bin3_change_state);
1053 gstelement_klass->send_event = GST_DEBUG_FUNCPTR (gst_play_bin3_send_event);
1055 gstbin_klass->handle_message =
1056 GST_DEBUG_FUNCPTR (gst_play_bin3_handle_message);
1057 gstbin_klass->deep_element_added =
1058 GST_DEBUG_FUNCPTR (gst_play_bin3_deep_element_added);
1062 do_async_start (GstPlayBin3 * playbin)
1064 GstMessage *message;
1066 playbin->async_pending = TRUE;
1068 message = gst_message_new_async_start (GST_OBJECT_CAST (playbin));
1069 GST_BIN_CLASS (parent_class)->handle_message (GST_BIN_CAST (playbin),
1074 do_async_done (GstPlayBin3 * playbin)
1076 GstMessage *message;
1078 if (playbin->async_pending) {
1079 GST_DEBUG_OBJECT (playbin, "posting ASYNC_DONE");
1081 gst_message_new_async_done (GST_OBJECT_CAST (playbin),
1082 GST_CLOCK_TIME_NONE);
1083 GST_BIN_CLASS (parent_class)->handle_message (GST_BIN_CAST (playbin),
1086 playbin->async_pending = FALSE;
1090 /* init combiners. The combiner is found by finding the first prefix that
1091 * matches the media. */
1093 init_combiners (GstPlayBin3 * playbin)
1097 /* store the array for the different channels */
1098 for (i = 0; i < PLAYBIN_STREAM_LAST; i++)
1099 playbin->channels[i] = g_ptr_array_new ();
1101 playbin->combiner[PLAYBIN_STREAM_AUDIO].media_type = "audio";
1102 playbin->combiner[PLAYBIN_STREAM_AUDIO].type = GST_PLAY_SINK_TYPE_AUDIO;
1103 playbin->combiner[PLAYBIN_STREAM_AUDIO].stream_type = GST_STREAM_TYPE_AUDIO;
1104 playbin->combiner[PLAYBIN_STREAM_AUDIO].channels = playbin->channels[0];
1105 playbin->combiner[PLAYBIN_STREAM_AUDIO].streams =
1106 g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
1108 playbin->combiner[PLAYBIN_STREAM_VIDEO].media_type = "video";
1109 playbin->combiner[PLAYBIN_STREAM_VIDEO].type = GST_PLAY_SINK_TYPE_VIDEO;
1110 playbin->combiner[PLAYBIN_STREAM_VIDEO].stream_type = GST_STREAM_TYPE_VIDEO;
1111 playbin->combiner[PLAYBIN_STREAM_VIDEO].channels = playbin->channels[1];
1112 playbin->combiner[PLAYBIN_STREAM_VIDEO].streams =
1113 g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
1115 playbin->combiner[PLAYBIN_STREAM_TEXT].media_type = "text";
1116 playbin->combiner[PLAYBIN_STREAM_TEXT].get_media_caps =
1117 gst_subtitle_overlay_create_factory_caps;
1118 playbin->combiner[PLAYBIN_STREAM_TEXT].type = GST_PLAY_SINK_TYPE_TEXT;
1119 playbin->combiner[PLAYBIN_STREAM_TEXT].stream_type = GST_STREAM_TYPE_TEXT;
1120 playbin->combiner[PLAYBIN_STREAM_TEXT].channels = playbin->channels[2];
1121 playbin->combiner[PLAYBIN_STREAM_TEXT].streams =
1122 g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
1125 /* Update the combiner information to be in sync with the current collection
1127 * FIXME : "current" collection doesn't mean anything until we have a "combined"
1128 * collection of all groups */
1130 update_combiner_info (GstPlayBin3 * playbin, GstStreamCollection * collection)
1134 if (collection == NULL)
1137 GST_DEBUG_OBJECT (playbin, "Updating combiner info");
1139 /* Wipe current combiner streams */
1140 g_ptr_array_free (playbin->combiner[PLAYBIN_STREAM_AUDIO].streams, TRUE);
1141 g_ptr_array_free (playbin->combiner[PLAYBIN_STREAM_VIDEO].streams, TRUE);
1142 g_ptr_array_free (playbin->combiner[PLAYBIN_STREAM_TEXT].streams, TRUE);
1143 playbin->combiner[PLAYBIN_STREAM_AUDIO].streams =
1144 g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
1145 playbin->combiner[PLAYBIN_STREAM_VIDEO].streams =
1146 g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
1147 playbin->combiner[PLAYBIN_STREAM_TEXT].streams =
1148 g_ptr_array_new_with_free_func ((GDestroyNotify) gst_object_unref);
1150 len = gst_stream_collection_get_size (collection);
1151 for (i = 0; i < len; i++) {
1152 GstStream *stream = gst_stream_collection_get_stream (collection, i);
1153 GstStreamType stype = gst_stream_get_stream_type (stream);
1155 if (stype & GST_STREAM_TYPE_AUDIO) {
1156 g_ptr_array_add (playbin->combiner[PLAYBIN_STREAM_AUDIO].streams,
1157 gst_object_ref (stream));
1158 } else if (stype & GST_STREAM_TYPE_VIDEO) {
1159 g_ptr_array_add (playbin->combiner[PLAYBIN_STREAM_VIDEO].streams,
1160 gst_object_ref (stream));
1161 } else if (stype & GST_STREAM_TYPE_TEXT) {
1162 g_ptr_array_add (playbin->combiner[PLAYBIN_STREAM_TEXT].streams,
1163 gst_object_ref (stream));
1167 GST_DEBUG_OBJECT (playbin, "There are %d audio streams",
1168 playbin->combiner[PLAYBIN_STREAM_AUDIO].streams->len);
1169 GST_DEBUG_OBJECT (playbin, "There are %d video streams",
1170 playbin->combiner[PLAYBIN_STREAM_VIDEO].streams->len);
1171 GST_DEBUG_OBJECT (playbin, "There are %d text streams",
1172 playbin->combiner[PLAYBIN_STREAM_TEXT].streams->len);
1175 #ifndef GST_DISABLE_GST_DEBUG
1176 #define debug_groups(playbin) G_STMT_START { \
1179 for (i = 0; i < 2; i++) { \
1180 GstSourceGroup *group = &playbin->groups[i]; \
1182 GST_DEBUG ("GstSourceGroup #%d (%s)", i, (group == playbin->curr_group) ? "current" : (group == playbin->next_group) ? "next" : "unused"); \
1183 GST_DEBUG (" valid:%d , active:%d , playing:%d", group->valid, group->active, group->playing); \
1184 GST_DEBUG (" uri:%s", group->uri); \
1185 GST_DEBUG (" suburi:%s", group->suburi); \
1186 GST_DEBUG (" group_id:%d", group->group_id); \
1187 GST_DEBUG (" pending_about_to_finish:%d", group->pending_about_to_finish); \
1191 #define debug_groups(p) {}
1195 init_group (GstPlayBin3 * playbin, GstSourceGroup * group)
1197 g_mutex_init (&group->lock);
1199 group->stream_changed_pending = FALSE;
1200 group->group_id = GST_GROUP_ID_INVALID;
1202 group->playbin = playbin;
1206 free_group (GstPlayBin3 * playbin, GstSourceGroup * group)
1208 g_free (group->uri);
1209 g_free (group->suburi);
1211 g_mutex_clear (&group->lock);
1212 group->stream_changed_pending = FALSE;
1214 if (group->pending_buffering_msg)
1215 gst_message_unref (group->pending_buffering_msg);
1216 group->pending_buffering_msg = NULL;
1218 gst_object_replace ((GstObject **) & group->collection, NULL);
1220 gst_object_replace ((GstObject **) & group->audio_sink, NULL);
1221 gst_object_replace ((GstObject **) & group->video_sink, NULL);
1222 gst_object_replace ((GstObject **) & group->text_sink, NULL);
1226 notify_volume_cb (GObject * combiner, GParamSpec * pspec, GstPlayBin3 * playbin)
1228 g_object_notify (G_OBJECT (playbin), "volume");
1232 notify_mute_cb (GObject * combiner, GParamSpec * pspec, GstPlayBin3 * playbin)
1234 g_object_notify (G_OBJECT (playbin), "mute");
1238 colorbalance_value_changed_cb (GstColorBalance * balance,
1239 GstColorBalanceChannel * channel, gint value, GstPlayBin3 * playbin)
1241 gst_color_balance_value_changed (GST_COLOR_BALANCE (playbin), channel, value);
1244 #if 0 /* AUTOPLUG DISABLED */
1246 compare_factories_func (gconstpointer p1, gconstpointer p2)
1248 GstPluginFeature *f1, *f2;
1249 gboolean is_sink1, is_sink2;
1250 gboolean is_parser1, is_parser2;
1252 f1 = (GstPluginFeature *) p1;
1253 f2 = (GstPluginFeature *) p2;
1255 is_sink1 = gst_element_factory_list_is_type (GST_ELEMENT_FACTORY_CAST (f1),
1256 GST_ELEMENT_FACTORY_TYPE_SINK);
1257 is_sink2 = gst_element_factory_list_is_type (GST_ELEMENT_FACTORY_CAST (f2),
1258 GST_ELEMENT_FACTORY_TYPE_SINK);
1259 is_parser1 = gst_element_factory_list_is_type (GST_ELEMENT_FACTORY_CAST (f1),
1260 GST_ELEMENT_FACTORY_TYPE_PARSER);
1261 is_parser2 = gst_element_factory_list_is_type (GST_ELEMENT_FACTORY_CAST (f2),
1262 GST_ELEMENT_FACTORY_TYPE_PARSER);
1264 /* First we want all sinks as we prefer a sink if it directly
1265 * supports the current caps */
1266 if (is_sink1 && !is_sink2)
1268 else if (!is_sink1 && is_sink2)
1271 /* Then we want all parsers as we always want to plug parsers
1272 * before decoders */
1273 if (is_parser1 && !is_parser2)
1275 else if (!is_parser1 && is_parser2)
1278 /* And if it's a both a parser or sink we first sort by rank
1279 * and then by factory name */
1280 return gst_plugin_feature_rank_compare_func (p1, p2);
1283 /* Must be called with elements lock! */
1285 gst_play_bin3_update_elements_list (GstPlayBin3 * playbin)
1290 cookie = gst_registry_get_feature_list_cookie (gst_registry_get ());
1292 if (!playbin->elements || playbin->elements_cookie != cookie) {
1293 if (playbin->elements)
1294 gst_plugin_feature_list_free (playbin->elements);
1296 gst_element_factory_list_get_elements
1297 (GST_ELEMENT_FACTORY_TYPE_DECODABLE, GST_RANK_MARGINAL);
1299 gst_element_factory_list_get_elements
1300 (GST_ELEMENT_FACTORY_TYPE_AUDIOVIDEO_SINKS, GST_RANK_MARGINAL);
1301 playbin->elements = g_list_concat (res, tmp);
1302 playbin->elements = g_list_sort (playbin->elements, compare_factories_func);
1305 if (!playbin->aelements || playbin->elements_cookie != cookie) {
1306 if (playbin->aelements)
1307 g_sequence_free (playbin->aelements);
1308 playbin->aelements = avelements_create (playbin, TRUE);
1311 if (!playbin->velements || playbin->elements_cookie != cookie) {
1312 if (playbin->velements)
1313 g_sequence_free (playbin->velements);
1314 playbin->velements = avelements_create (playbin, FALSE);
1317 playbin->elements_cookie = cookie;
1322 gst_play_bin3_init (GstPlayBin3 * playbin)
1324 g_rec_mutex_init (&playbin->lock);
1325 g_mutex_init (&playbin->dyn_lock);
1327 /* assume we can create an input-selector */
1328 playbin->have_selector = TRUE;
1330 init_combiners (playbin);
1333 playbin->curr_group = &playbin->groups[0];
1334 playbin->next_group = &playbin->groups[1];
1335 init_group (playbin, &playbin->groups[0]);
1336 init_group (playbin, &playbin->groups[1]);
1338 /* first filter out the interesting element factories */
1339 g_mutex_init (&playbin->elements_lock);
1341 g_rec_mutex_init (&playbin->activation_lock);
1345 g_object_new (GST_TYPE_PLAY_SINK, "name", "playsink", "send-event-mode",
1347 gst_bin_add (GST_BIN_CAST (playbin), GST_ELEMENT_CAST (playbin->playsink));
1348 gst_play_sink_set_flags (playbin->playsink, DEFAULT_FLAGS);
1349 /* Connect to notify::volume and notify::mute signals for proxying */
1350 g_signal_connect (playbin->playsink, "notify::volume",
1351 G_CALLBACK (notify_volume_cb), playbin);
1352 g_signal_connect (playbin->playsink, "notify::mute",
1353 G_CALLBACK (notify_mute_cb), playbin);
1354 g_signal_connect (playbin->playsink, "value-changed",
1355 G_CALLBACK (colorbalance_value_changed_cb), playbin);
1357 playbin->current_video = DEFAULT_CURRENT_VIDEO;
1358 playbin->current_audio = DEFAULT_CURRENT_AUDIO;
1359 playbin->current_text = DEFAULT_CURRENT_TEXT;
1361 playbin->buffer_duration = DEFAULT_BUFFER_DURATION;
1362 playbin->buffer_size = DEFAULT_BUFFER_SIZE;
1363 playbin->ring_buffer_max_size = DEFAULT_RING_BUFFER_MAX_SIZE;
1365 playbin->force_aspect_ratio = TRUE;
1367 playbin->multiview_mode = GST_VIDEO_MULTIVIEW_FRAME_PACKING_NONE;
1368 playbin->multiview_flags = GST_VIDEO_MULTIVIEW_FLAGS_NONE;
1372 gst_play_bin3_finalize (GObject * object)
1374 GstPlayBin3 *playbin;
1377 playbin = GST_PLAY_BIN3 (object);
1379 free_group (playbin, &playbin->groups[0]);
1380 free_group (playbin, &playbin->groups[1]);
1382 for (i = 0; i < PLAYBIN_STREAM_LAST; i++)
1383 g_ptr_array_free (playbin->channels[i], TRUE);
1385 /* Setting states to NULL is safe here because playsink
1386 * will already be gone and none of these sinks will be
1387 * a child of playsink
1389 if (playbin->video_sink) {
1390 gst_element_set_state (playbin->video_sink, GST_STATE_NULL);
1391 gst_object_unref (playbin->video_sink);
1393 if (playbin->audio_sink) {
1394 gst_element_set_state (playbin->audio_sink, GST_STATE_NULL);
1395 gst_object_unref (playbin->audio_sink);
1397 if (playbin->text_sink) {
1398 gst_element_set_state (playbin->text_sink, GST_STATE_NULL);
1399 gst_object_unref (playbin->text_sink);
1402 if (playbin->video_stream_combiner) {
1403 gst_element_set_state (playbin->video_stream_combiner, GST_STATE_NULL);
1404 gst_object_unref (playbin->video_stream_combiner);
1406 if (playbin->audio_stream_combiner) {
1407 gst_element_set_state (playbin->audio_stream_combiner, GST_STATE_NULL);
1408 gst_object_unref (playbin->audio_stream_combiner);
1410 if (playbin->text_stream_combiner) {
1411 gst_element_set_state (playbin->text_stream_combiner, GST_STATE_NULL);
1412 gst_object_unref (playbin->text_stream_combiner);
1415 g_ptr_array_free (playbin->combiner[PLAYBIN_STREAM_AUDIO].streams, TRUE);
1416 g_ptr_array_free (playbin->combiner[PLAYBIN_STREAM_VIDEO].streams, TRUE);
1417 g_ptr_array_free (playbin->combiner[PLAYBIN_STREAM_TEXT].streams, TRUE);
1419 if (playbin->elements)
1420 gst_plugin_feature_list_free (playbin->elements);
1422 if (playbin->aelements)
1423 g_sequence_free (playbin->aelements);
1425 if (playbin->velements)
1426 g_sequence_free (playbin->velements);
1428 g_rec_mutex_clear (&playbin->activation_lock);
1429 g_rec_mutex_clear (&playbin->lock);
1430 g_mutex_clear (&playbin->dyn_lock);
1431 g_mutex_clear (&playbin->elements_lock);
1433 G_OBJECT_CLASS (parent_class)->finalize (object);
1437 gst_playbin_uri_is_valid (GstPlayBin3 * playbin, const gchar * uri)
1441 GST_LOG_OBJECT (playbin, "checking uri '%s'", uri);
1443 /* this just checks the protocol */
1444 if (!gst_uri_is_valid (uri))
1447 for (c = uri; *c != '\0'; ++c) {
1448 if (!g_ascii_isprint (*c))
1458 GST_WARNING_OBJECT (playbin, "uri '%s' not valid, character #%u",
1459 uri, (guint) ((guintptr) c - (guintptr) uri));
1465 gst_play_bin3_set_uri (GstPlayBin3 * playbin, const gchar * uri)
1467 GstSourceGroup *group;
1470 g_warning ("cannot set NULL uri");
1474 if (!gst_playbin_uri_is_valid (playbin, uri)) {
1475 if (g_str_has_prefix (uri, "file:")) {
1476 GST_WARNING_OBJECT (playbin, "not entirely correct file URI '%s' - make "
1477 "sure to escape spaces and non-ASCII characters properly and specify "
1478 "an absolute path. Use gst_filename_to_uri() to convert filenames "
1481 /* GST_ERROR_OBJECT (playbin, "malformed URI '%s'", uri); */
1485 GST_PLAY_BIN3_LOCK (playbin);
1486 group = playbin->next_group;
1488 GST_SOURCE_GROUP_LOCK (group);
1489 /* store the uri in the next group we will play */
1490 g_free (group->uri);
1491 group->uri = g_strdup (uri);
1492 group->valid = TRUE;
1493 GST_SOURCE_GROUP_UNLOCK (group);
1495 GST_DEBUG ("set new uri to %s", uri);
1496 GST_PLAY_BIN3_UNLOCK (playbin);
1500 gst_play_bin3_set_suburi (GstPlayBin3 * playbin, const gchar * suburi)
1502 GstSourceGroup *group;
1504 GST_PLAY_BIN3_LOCK (playbin);
1505 group = playbin->next_group;
1507 GST_SOURCE_GROUP_LOCK (group);
1508 g_free (group->suburi);
1509 group->suburi = g_strdup (suburi);
1510 GST_SOURCE_GROUP_UNLOCK (group);
1512 GST_DEBUG ("setting new .sub uri to %s", suburi);
1514 GST_PLAY_BIN3_UNLOCK (playbin);
1518 gst_play_bin3_set_flags (GstPlayBin3 * playbin, GstPlayFlags flags)
1520 GstPlayFlags old_flags;
1521 old_flags = gst_play_sink_get_flags (playbin->playsink);
1523 if (flags != old_flags) {
1524 gst_play_sink_set_flags (playbin->playsink, flags);
1525 gst_play_sink_reconfigure (playbin->playsink);
1530 gst_play_bin3_get_flags (GstPlayBin3 * playbin)
1534 flags = gst_play_sink_get_flags (playbin->playsink);
1539 /* get the currently playing group or if nothing is playing, the next
1540 * group. Must be called with the PLAY_BIN_LOCK. */
1541 static GstSourceGroup *
1542 get_group (GstPlayBin3 * playbin)
1544 GstSourceGroup *result;
1546 if (!(result = playbin->curr_group))
1547 result = playbin->next_group;
1554 gst_play_bin3_convert_sample (GstPlayBin3 * playbin, GstCaps * caps)
1556 return gst_play_sink_convert_sample (playbin->playsink, caps);
1560 gst_play_bin3_send_custom_event (GstObject * combiner, const gchar * event_name)
1566 gboolean ret = FALSE;
1568 src = gst_element_get_static_pad (GST_ELEMENT_CAST (combiner), "src");
1569 peer = gst_pad_get_peer (src);
1571 s = gst_structure_new_empty (event_name);
1572 event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_OOB, s);
1573 gst_pad_send_event (peer, event);
1574 gst_object_unref (peer);
1577 gst_object_unref (src);
1582 gst_play_bin3_set_current_stream (GstPlayBin3 * playbin,
1583 gint stream_type, gint * current_value, gint stream,
1584 gboolean * flush_marker)
1586 GstSourceCombine *combine;
1587 GPtrArray *channels;
1590 GST_PLAY_BIN3_LOCK (playbin);
1591 /* This function is only called if the app sets
1592 * one of the current-* properties, which means it doesn't
1593 * handle collections or select-streams yet */
1594 playbin->do_stream_selections = TRUE;
1596 combine = playbin->combiner + stream_type;
1597 channels = playbin->channels[stream_type];
1599 GST_DEBUG_OBJECT (playbin, "Changing current %s stream %d -> %d",
1600 stream_type_names[stream_type], *current_value, stream);
1602 if (combine->combiner == NULL || combine->is_concat) {
1603 /* FIXME: Check that the current_value is within range */
1604 *current_value = stream;
1605 do_stream_selection (playbin, playbin->curr_group);
1606 GST_PLAY_BIN3_UNLOCK (playbin);
1610 GST_DEBUG_OBJECT (playbin, "Using old style combiner");
1612 if (!combine->has_active_pad)
1614 if (channels == NULL)
1617 if (stream == -1 || channels->len <= stream) {
1620 /* take channel from selected stream */
1621 sinkpad = g_ptr_array_index (channels, stream);
1625 gst_object_ref (sinkpad);
1626 GST_PLAY_BIN3_UNLOCK (playbin);
1629 GstObject *combiner;
1631 if ((combiner = gst_pad_get_parent (sinkpad))) {
1632 GstPad *old_sinkpad;
1634 g_object_get (combiner, "active-pad", &old_sinkpad, NULL);
1636 if (old_sinkpad != sinkpad) {
1637 /* FIXME: Is there actually any reason playsink
1638 * needs special names for each type of stream we flush? */
1639 gchar *flush_event_name = g_strdup_printf ("playsink-custom-%s-flush",
1640 stream_type_names[stream_type]);
1641 if (gst_play_bin3_send_custom_event (combiner, flush_event_name))
1642 *flush_marker = TRUE;
1643 g_free (flush_event_name);
1645 /* activate the selected pad */
1646 g_object_set (combiner, "active-pad", sinkpad, NULL);
1650 gst_object_unref (old_sinkpad);
1652 gst_object_unref (combiner);
1654 gst_object_unref (sinkpad);
1660 GST_PLAY_BIN3_UNLOCK (playbin);
1661 GST_WARNING_OBJECT (playbin,
1662 "can't switch %s, the stream combiner's sink pads don't have the \"active-pad\" property",
1663 stream_type_names[stream_type]);
1668 GST_PLAY_BIN3_UNLOCK (playbin);
1669 GST_DEBUG_OBJECT (playbin, "can't switch video, we have no channels");
1675 gst_play_bin3_set_current_video_stream (GstPlayBin3 * playbin, gint stream)
1677 return gst_play_bin3_set_current_stream (playbin, PLAYBIN_STREAM_VIDEO,
1678 &playbin->current_video, stream, &playbin->video_pending_flush_finish);
1682 gst_play_bin3_set_current_audio_stream (GstPlayBin3 * playbin, gint stream)
1684 return gst_play_bin3_set_current_stream (playbin, PLAYBIN_STREAM_AUDIO,
1685 &playbin->current_audio, stream, &playbin->audio_pending_flush_finish);
1689 gst_play_bin3_set_current_text_stream (GstPlayBin3 * playbin, gint stream)
1691 return gst_play_bin3_set_current_stream (playbin, PLAYBIN_STREAM_TEXT,
1692 &playbin->current_text, stream, &playbin->text_pending_flush_finish);
1697 gst_play_bin3_set_sink (GstPlayBin3 * playbin, GstPlaySinkType type,
1698 const gchar * dbg, GstElement ** elem, GstElement * sink)
1700 GST_INFO_OBJECT (playbin, "Setting %s sink to %" GST_PTR_FORMAT, dbg, sink);
1702 gst_play_sink_set_sink (playbin->playsink, type, sink);
1705 gst_object_unref (*elem);
1706 *elem = sink ? gst_object_ref (sink) : NULL;
1710 gst_play_bin3_set_stream_combiner (GstPlayBin3 * playbin, GstElement ** elem,
1711 const gchar * dbg, GstElement * combiner)
1713 GST_INFO_OBJECT (playbin, "Setting %s stream combiner to %" GST_PTR_FORMAT,
1716 GST_PLAY_BIN3_LOCK (playbin);
1717 if (*elem != combiner) {
1722 gst_object_ref_sink (combiner);
1726 gst_object_unref (old);
1728 GST_LOG_OBJECT (playbin, "%s stream combiner now %" GST_PTR_FORMAT, dbg,
1730 GST_PLAY_BIN3_UNLOCK (playbin);
1734 gst_play_bin3_set_encoding (GstPlayBin3 * playbin, const gchar * encoding)
1736 GST_PLAY_BIN3_LOCK (playbin);
1737 gst_play_sink_set_subtitle_encoding (playbin->playsink, encoding);
1738 GST_PLAY_BIN3_UNLOCK (playbin);
1742 gst_play_bin3_set_property (GObject * object, guint prop_id,
1743 const GValue * value, GParamSpec * pspec)
1745 GstPlayBin3 *playbin = GST_PLAY_BIN3 (object);
1749 gst_play_bin3_set_uri (playbin, g_value_get_string (value));
1752 gst_play_bin3_set_suburi (playbin, g_value_get_string (value));
1755 gst_play_bin3_set_flags (playbin, g_value_get_flags (value));
1756 if (playbin->curr_group) {
1757 GST_SOURCE_GROUP_LOCK (playbin->curr_group);
1758 if (playbin->curr_group->uridecodebin) {
1759 g_object_set (playbin->curr_group->uridecodebin, "download",
1760 (g_value_get_flags (value) & GST_PLAY_FLAG_DOWNLOAD) != 0, NULL);
1762 GST_SOURCE_GROUP_UNLOCK (playbin->curr_group);
1765 case PROP_SUBTITLE_ENCODING:
1766 gst_play_bin3_set_encoding (playbin, g_value_get_string (value));
1768 case PROP_VIDEO_FILTER:
1769 gst_play_sink_set_filter (playbin->playsink, GST_PLAY_SINK_TYPE_VIDEO,
1770 GST_ELEMENT (g_value_get_object (value)));
1772 case PROP_AUDIO_FILTER:
1773 gst_play_sink_set_filter (playbin->playsink, GST_PLAY_SINK_TYPE_AUDIO,
1774 GST_ELEMENT (g_value_get_object (value)));
1776 case PROP_VIDEO_SINK:
1777 gst_play_bin3_set_sink (playbin, GST_PLAY_SINK_TYPE_VIDEO, "video",
1778 &playbin->video_sink, g_value_get_object (value));
1780 case PROP_AUDIO_SINK:
1781 gst_play_bin3_set_sink (playbin, GST_PLAY_SINK_TYPE_AUDIO, "audio",
1782 &playbin->audio_sink, g_value_get_object (value));
1784 case PROP_VIS_PLUGIN:
1785 gst_play_sink_set_vis_plugin (playbin->playsink,
1786 g_value_get_object (value));
1788 case PROP_TEXT_SINK:
1789 gst_play_bin3_set_sink (playbin, GST_PLAY_SINK_TYPE_TEXT, "text",
1790 &playbin->text_sink, g_value_get_object (value));
1792 case PROP_VIDEO_STREAM_COMBINER:
1793 gst_play_bin3_set_stream_combiner (playbin,
1794 &playbin->video_stream_combiner, "video", g_value_get_object (value));
1796 case PROP_AUDIO_STREAM_COMBINER:
1797 gst_play_bin3_set_stream_combiner (playbin,
1798 &playbin->audio_stream_combiner, "audio", g_value_get_object (value));
1800 case PROP_TEXT_STREAM_COMBINER:
1801 gst_play_bin3_set_stream_combiner (playbin,
1802 &playbin->text_stream_combiner, "text", g_value_get_object (value));
1805 gst_play_sink_set_volume (playbin->playsink, g_value_get_double (value));
1808 gst_play_sink_set_mute (playbin->playsink, g_value_get_boolean (value));
1810 case PROP_FONT_DESC:
1811 gst_play_sink_set_font_desc (playbin->playsink,
1812 g_value_get_string (value));
1814 case PROP_CONNECTION_SPEED:
1815 GST_PLAY_BIN3_LOCK (playbin);
1816 playbin->connection_speed = g_value_get_uint64 (value) * 1000;
1817 GST_PLAY_BIN3_UNLOCK (playbin);
1819 case PROP_BUFFER_SIZE:
1820 playbin->buffer_size = g_value_get_int (value);
1822 case PROP_BUFFER_DURATION:
1823 playbin->buffer_duration = g_value_get_int64 (value);
1825 case PROP_AV_OFFSET:
1826 gst_play_sink_set_av_offset (playbin->playsink,
1827 g_value_get_int64 (value));
1829 case PROP_TEXT_OFFSET:
1830 gst_play_sink_set_text_offset (playbin->playsink,
1831 g_value_get_int64 (value));
1833 case PROP_RING_BUFFER_MAX_SIZE:
1834 playbin->ring_buffer_max_size = g_value_get_uint64 (value);
1835 if (playbin->curr_group) {
1836 GST_SOURCE_GROUP_LOCK (playbin->curr_group);
1837 if (playbin->curr_group->uridecodebin) {
1838 g_object_set (playbin->curr_group->uridecodebin,
1839 "ring-buffer-max-size", playbin->ring_buffer_max_size, NULL);
1841 GST_SOURCE_GROUP_UNLOCK (playbin->curr_group);
1844 case PROP_FORCE_ASPECT_RATIO:
1845 g_object_set (playbin->playsink, "force-aspect-ratio",
1846 g_value_get_boolean (value), NULL);
1848 case PROP_MULTIVIEW_MODE:
1849 GST_PLAY_BIN3_LOCK (playbin);
1850 playbin->multiview_mode = g_value_get_enum (value);
1851 GST_PLAY_BIN3_UNLOCK (playbin);
1853 case PROP_MULTIVIEW_FLAGS:
1854 GST_PLAY_BIN3_LOCK (playbin);
1855 playbin->multiview_flags = g_value_get_flags (value);
1856 GST_PLAY_BIN3_UNLOCK (playbin);
1859 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
1865 gst_play_bin3_get_current_sink (GstPlayBin3 * playbin, GstElement ** elem,
1866 const gchar * dbg, GstPlaySinkType type)
1868 GstElement *sink = gst_play_sink_get_sink (playbin->playsink, type);
1870 GST_LOG_OBJECT (playbin, "play_sink_get_sink() returned %s sink %"
1871 GST_PTR_FORMAT ", the originally set %s sink is %" GST_PTR_FORMAT,
1872 dbg, sink, dbg, *elem);
1875 GST_PLAY_BIN3_LOCK (playbin);
1877 gst_object_ref (sink);
1878 GST_PLAY_BIN3_UNLOCK (playbin);
1885 gst_play_bin3_get_current_stream_combiner (GstPlayBin3 * playbin,
1886 GstElement ** elem, const gchar * dbg, int stream_type)
1888 GstElement *combiner;
1890 GST_PLAY_BIN3_LOCK (playbin);
1891 /* The special concat element should never be returned */
1892 if (playbin->combiner[stream_type].is_concat)
1894 else if ((combiner = playbin->combiner[stream_type].combiner))
1895 gst_object_ref (combiner);
1896 else if ((combiner = *elem))
1897 gst_object_ref (combiner);
1898 GST_PLAY_BIN3_UNLOCK (playbin);
1904 gst_play_bin3_get_property (GObject * object, guint prop_id, GValue * value,
1907 GstPlayBin3 *playbin = GST_PLAY_BIN3 (object);
1912 GstSourceGroup *group;
1914 GST_PLAY_BIN3_LOCK (playbin);
1915 group = playbin->next_group;
1916 g_value_set_string (value, group->uri);
1917 GST_PLAY_BIN3_UNLOCK (playbin);
1920 case PROP_CURRENT_URI:
1922 GstSourceGroup *group;
1924 GST_PLAY_BIN3_LOCK (playbin);
1925 group = get_group (playbin);
1926 g_value_set_string (value, group->uri);
1927 GST_PLAY_BIN3_UNLOCK (playbin);
1932 GstSourceGroup *group;
1934 GST_PLAY_BIN3_LOCK (playbin);
1935 group = playbin->next_group;
1936 g_value_set_string (value, group->suburi);
1937 GST_PLAY_BIN3_UNLOCK (playbin);
1940 case PROP_CURRENT_SUBURI:
1942 GstSourceGroup *group;
1944 GST_PLAY_BIN3_LOCK (playbin);
1945 group = get_group (playbin);
1946 g_value_set_string (value, group->suburi);
1947 GST_PLAY_BIN3_UNLOCK (playbin);
1951 g_value_set_flags (value, gst_play_bin3_get_flags (playbin));
1953 case PROP_SUBTITLE_ENCODING:
1954 GST_PLAY_BIN3_LOCK (playbin);
1955 g_value_take_string (value,
1956 gst_play_sink_get_subtitle_encoding (playbin->playsink));
1957 GST_PLAY_BIN3_UNLOCK (playbin);
1959 case PROP_VIDEO_FILTER:
1960 g_value_take_object (value,
1961 gst_play_sink_get_filter (playbin->playsink,
1962 GST_PLAY_SINK_TYPE_VIDEO));
1964 case PROP_AUDIO_FILTER:
1965 g_value_take_object (value,
1966 gst_play_sink_get_filter (playbin->playsink,
1967 GST_PLAY_SINK_TYPE_AUDIO));
1969 case PROP_VIDEO_SINK:
1970 g_value_take_object (value,
1971 gst_play_bin3_get_current_sink (playbin, &playbin->video_sink,
1972 "video", GST_PLAY_SINK_TYPE_VIDEO));
1974 case PROP_AUDIO_SINK:
1975 g_value_take_object (value,
1976 gst_play_bin3_get_current_sink (playbin, &playbin->audio_sink,
1977 "audio", GST_PLAY_SINK_TYPE_AUDIO));
1979 case PROP_VIS_PLUGIN:
1980 g_value_take_object (value,
1981 gst_play_sink_get_vis_plugin (playbin->playsink));
1983 case PROP_TEXT_SINK:
1984 g_value_take_object (value,
1985 gst_play_bin3_get_current_sink (playbin, &playbin->text_sink,
1986 "text", GST_PLAY_SINK_TYPE_TEXT));
1988 case PROP_VIDEO_STREAM_COMBINER:
1989 g_value_take_object (value,
1990 gst_play_bin3_get_current_stream_combiner (playbin,
1991 &playbin->video_stream_combiner, "video", PLAYBIN_STREAM_VIDEO));
1993 case PROP_AUDIO_STREAM_COMBINER:
1994 g_value_take_object (value,
1995 gst_play_bin3_get_current_stream_combiner (playbin,
1996 &playbin->audio_stream_combiner, "audio", PLAYBIN_STREAM_AUDIO));
1998 case PROP_TEXT_STREAM_COMBINER:
1999 g_value_take_object (value,
2000 gst_play_bin3_get_current_stream_combiner (playbin,
2001 &playbin->text_stream_combiner, "text", PLAYBIN_STREAM_TEXT));
2004 g_value_set_double (value, gst_play_sink_get_volume (playbin->playsink));
2007 g_value_set_boolean (value, gst_play_sink_get_mute (playbin->playsink));
2010 gst_value_take_sample (value,
2011 gst_play_sink_get_last_sample (playbin->playsink));
2013 case PROP_FONT_DESC:
2014 g_value_take_string (value,
2015 gst_play_sink_get_font_desc (playbin->playsink));
2017 case PROP_CONNECTION_SPEED:
2018 GST_PLAY_BIN3_LOCK (playbin);
2019 g_value_set_uint64 (value, playbin->connection_speed / 1000);
2020 GST_PLAY_BIN3_UNLOCK (playbin);
2022 case PROP_BUFFER_SIZE:
2023 GST_OBJECT_LOCK (playbin);
2024 g_value_set_int (value, playbin->buffer_size);
2025 GST_OBJECT_UNLOCK (playbin);
2027 case PROP_BUFFER_DURATION:
2028 GST_OBJECT_LOCK (playbin);
2029 g_value_set_int64 (value, playbin->buffer_duration);
2030 GST_OBJECT_UNLOCK (playbin);
2032 case PROP_AV_OFFSET:
2033 g_value_set_int64 (value,
2034 gst_play_sink_get_av_offset (playbin->playsink));
2036 case PROP_TEXT_OFFSET:
2037 g_value_set_int64 (value,
2038 gst_play_sink_get_text_offset (playbin->playsink));
2040 case PROP_RING_BUFFER_MAX_SIZE:
2041 g_value_set_uint64 (value, playbin->ring_buffer_max_size);
2043 case PROP_FORCE_ASPECT_RATIO:{
2046 g_object_get (playbin->playsink, "force-aspect-ratio", &v, NULL);
2047 g_value_set_boolean (value, v);
2050 case PROP_MULTIVIEW_MODE:
2051 GST_OBJECT_LOCK (playbin);
2052 g_value_set_enum (value, playbin->multiview_mode);
2053 GST_OBJECT_UNLOCK (playbin);
2055 case PROP_MULTIVIEW_FLAGS:
2056 GST_OBJECT_LOCK (playbin);
2057 g_value_set_flags (value, playbin->multiview_flags);
2058 GST_OBJECT_UNLOCK (playbin);
2061 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2067 get_combiner_stream_id (GstPlayBin3 * playbin, GstSourceCombine * combine,
2073 for (i = 0; i < combine->streams->len; i++) {
2074 GstStream *stream = (GstStream *) g_ptr_array_index (combine->streams, i);
2075 const gchar *sid = gst_stream_get_stream_id (stream);
2076 for (tmp = full_list; tmp; tmp = tmp->next) {
2077 gchar *orig = (gchar *) tmp->data;
2078 if (!g_strcmp0 (orig, sid))
2088 extend_list_of_streams (GstPlayBin3 * playbin, GstStreamType stype,
2089 GList * list, GstStreamCollection * collection)
2096 nb = gst_stream_collection_get_size (collection);
2097 for (i = 0; i < nb; i++) {
2098 GstStream *stream = gst_stream_collection_get_stream (collection, i);
2099 GstStreamType curtype = gst_stream_get_stream_type (stream);
2100 if (stype == curtype) {
2101 gboolean already_there = FALSE;
2102 const gchar *sid = gst_stream_get_stream_id (stream);
2103 for (tmp = res; tmp; tmp = tmp->next) {
2104 const gchar *other = (const gchar *) tmp->data;
2105 if (!g_strcmp0 (sid, other)) {
2106 already_there = TRUE;
2110 if (!already_there) {
2111 GST_DEBUG_OBJECT (playbin, "Adding stream %s", sid);
2112 res = g_list_append (res, g_strdup (sid));
2121 update_select_streams_event (GstPlayBin3 * playbin, GstEvent * event,
2122 GstSourceGroup * group)
2124 GList *streams = NULL;
2128 if (!playbin->audio_stream_combiner && !playbin->video_stream_combiner &&
2129 !playbin->text_stream_combiner) {
2131 GST_DEBUG_OBJECT (playbin,
2132 "No custom combiners, no need to modify SELECT_STREAMS event");
2136 if (!group->collection) {
2137 GST_DEBUG_OBJECT (playbin,
2138 "No stream collection for group, no need to modify SELECT_STREAMS event");
2142 gst_event_parse_select_streams (event, &streams);
2143 to_use = g_list_copy_deep (streams, (GCopyFunc) g_strdup, NULL);
2145 /* For each combiner, we want to add all streams of that type to the
2147 if (playbin->audio_stream_combiner) {
2149 extend_list_of_streams (playbin, GST_STREAM_TYPE_AUDIO, to_use,
2152 get_combiner_stream_id (playbin,
2153 &playbin->combiner[PLAYBIN_STREAM_AUDIO], streams);
2154 if (combine_id != -1)
2155 gst_play_bin3_set_current_audio_stream (playbin, combine_id);
2157 if (playbin->video_stream_combiner) {
2159 extend_list_of_streams (playbin, GST_STREAM_TYPE_VIDEO, to_use,
2162 get_combiner_stream_id (playbin,
2163 &playbin->combiner[PLAYBIN_STREAM_VIDEO], streams);
2164 if (combine_id != -1)
2165 gst_play_bin3_set_current_video_stream (playbin, combine_id);
2167 if (playbin->text_stream_combiner) {
2169 extend_list_of_streams (playbin, GST_STREAM_TYPE_TEXT, to_use,
2172 get_combiner_stream_id (playbin,
2173 &playbin->combiner[PLAYBIN_STREAM_TEXT], streams);
2174 if (combine_id != -1)
2175 gst_play_bin3_set_current_text_stream (playbin, combine_id);
2178 gst_event_unref (event);
2179 event = gst_event_new_select_streams (to_use);
2182 g_list_free_full (streams, g_free);
2184 g_list_free_full (to_use, g_free);
2189 /* Returns TRUE if the given list of streams belongs to the stream collection */
2191 gst_streams_belong_to_collection (GList * streams,
2192 GstStreamCollection * collection)
2197 if (streams == NULL || collection == NULL)
2199 nb = gst_stream_collection_get_size (collection);
2203 for (tmp = streams; tmp; tmp = tmp->next) {
2204 const gchar *cand = (const gchar *) tmp->data;
2205 gboolean found = FALSE;
2207 for (i = 0; i < nb; i++) {
2208 GstStream *stream = gst_stream_collection_get_stream (collection, i);
2209 if (!g_strcmp0 (cand, gst_stream_get_stream_id (stream))) {
2220 static GstSourceGroup *
2221 get_source_group_for_streams (GstPlayBin3 * playbin, GstEvent * event)
2224 GstSourceGroup *res = NULL;
2226 gst_event_parse_select_streams (event, &streams);
2227 if (playbin->curr_group->collection &&
2228 gst_streams_belong_to_collection (streams,
2229 playbin->curr_group->collection))
2230 res = playbin->curr_group;
2231 else if (playbin->next_group->collection &&
2232 gst_streams_belong_to_collection (streams,
2233 playbin->next_group->collection))
2234 res = playbin->next_group;
2235 g_list_free_full (streams, g_free);
2240 static GstStreamType
2241 get_stream_type_for_event (GstStreamCollection * collection, GstEvent * event)
2243 GList *stream_list = NULL;
2245 GstStreamType res = 0;
2248 gst_event_parse_select_streams (event, &stream_list);
2249 len = gst_stream_collection_get_size (collection);
2250 for (tmp = stream_list; tmp; tmp = tmp->next) {
2251 gchar *stid = (gchar *) tmp->data;
2253 for (i = 0; i < len; i++) {
2254 GstStream *stream = gst_stream_collection_get_stream (collection, i);
2255 if (!g_strcmp0 (stid, gst_stream_get_stream_id (stream))) {
2256 res |= gst_stream_get_stream_type (stream);
2260 g_list_free_full (stream_list, g_free);
2266 gst_play_bin3_send_event (GstElement * element, GstEvent * event)
2268 GstPlayBin3 *playbin = GST_PLAY_BIN3 (element);
2270 if (GST_EVENT_TYPE (event) == GST_EVENT_SELECT_STREAMS) {
2272 GstSourceGroup *group;
2274 GST_PLAY_BIN3_LOCK (playbin);
2275 GST_LOG_OBJECT (playbin,
2276 "App sent select-streams, we won't do anything ourselves now");
2277 /* This is probably already false, but it doesn't hurt to be sure */
2278 playbin->do_stream_selections = FALSE;
2280 group = get_source_group_for_streams (playbin, event);
2281 if (group == NULL) {
2282 GST_WARNING_OBJECT (playbin,
2283 "Can't figure out to which uridecodebin the select-streams event should be sent to");
2284 GST_PLAY_BIN3_UNLOCK (playbin);
2288 /* If we have custom combiners, we need to extend the selection with
2289 * the list of all streams for that given type since we will be handling
2290 * the selection with that combiner */
2291 event = update_select_streams_event (playbin, event, group);
2293 if (group->collection) {
2294 group->selected_stream_types =
2295 get_stream_type_for_event (group->collection, event);
2296 playbin->selected_stream_types =
2297 playbin->groups[0].selected_stream_types | playbin->
2298 groups[1].selected_stream_types;
2299 if (playbin->active_stream_types != playbin->selected_stream_types)
2300 reconfigure_output (playbin);
2303 /* Send this event directly to uridecodebin, so it works even
2304 * if uridecodebin didn't add any pads yet */
2305 res = gst_element_send_event (group->uridecodebin, event);
2306 GST_PLAY_BIN3_UNLOCK (playbin);
2311 /* Send event directly to playsink instead of letting GstBin iterate
2312 * over all sink elements. The latter might send the event multiple times
2313 * in case the SEEK causes a reconfiguration of the pipeline, as can easily
2314 * happen with adaptive streaming demuxers.
2316 * What would then happen is that the iterator would be reset, we send the
2317 * event again, and on the second time it will fail in the majority of cases
2318 * because the pipeline is still being reconfigured
2320 if (GST_EVENT_IS_UPSTREAM (event)) {
2321 return gst_element_send_event (GST_ELEMENT_CAST (playbin->playsink), event);
2324 return GST_ELEMENT_CLASS (parent_class)->send_event (element, event);
2327 /* Called with playbin lock held */
2329 do_stream_selection (GstPlayBin3 * playbin, GstSourceGroup * group)
2331 GstStreamCollection *collection;
2332 guint i, nb_streams;
2333 GList *streams = NULL;
2334 gint nb_video = 0, nb_audio = 0, nb_text = 0;
2335 GstStreamType chosen_stream_types = 0;
2340 collection = group->collection;
2341 if (collection == NULL) {
2342 GST_LOG_OBJECT (playbin, "No stream collection. Not doing stream-select");
2346 nb_streams = gst_stream_collection_get_size (collection);
2347 if (nb_streams == 0) {
2348 GST_INFO_OBJECT (playbin, "Empty collection received! Ignoring");
2351 GST_DEBUG_OBJECT (playbin, "Doing selection on collection with %d streams",
2354 /* Iterate the collection and choose the streams that match
2355 * either the current-* setting, or all streams of a type if there's
2356 * a combiner for that type */
2357 for (i = 0; i < nb_streams; i++) {
2358 GstStream *stream = gst_stream_collection_get_stream (collection, i);
2359 GstStreamType stream_type = gst_stream_get_stream_type (stream);
2360 const gchar *stream_id = gst_stream_get_stream_id (stream);
2361 gint pb_stream_type = -1;
2362 gboolean select_this = FALSE;
2364 GST_LOG_OBJECT (playbin, "Looking at stream #%d : %s", i, stream_id);
2366 if (stream_type & GST_STREAM_TYPE_AUDIO) {
2367 pb_stream_type = PLAYBIN_STREAM_AUDIO;
2368 /* Select the stream if it's the current one or if there's a custom selector */
2370 (nb_audio == playbin->current_audio ||
2371 (playbin->current_audio == -1 && nb_audio == 0) ||
2372 playbin->audio_stream_combiner != NULL);
2374 } else if (stream_type & GST_STREAM_TYPE_VIDEO) {
2375 pb_stream_type = PLAYBIN_STREAM_VIDEO;
2377 (nb_video == playbin->current_video ||
2378 (playbin->current_video == -1 && nb_video == 0) ||
2379 playbin->video_stream_combiner != NULL);
2381 } else if (stream_type & GST_STREAM_TYPE_TEXT) {
2382 pb_stream_type = PLAYBIN_STREAM_TEXT;
2384 (nb_text == playbin->current_text ||
2385 (playbin->current_text == -1 && nb_text == 0) ||
2386 playbin->text_stream_combiner != NULL);
2389 if (pb_stream_type < 0) {
2390 GST_DEBUG_OBJECT (playbin,
2391 "Stream %d (id %s) of unhandled type %s. Ignoring", i, stream_id,
2392 gst_stream_type_get_name (stream_type));
2396 GST_DEBUG_OBJECT (playbin, "Selecting stream %s of type %s",
2397 stream_id, gst_stream_type_get_name (stream_type));
2398 /* Don't build the list if we're not in charge of stream selection */
2399 if (playbin->do_stream_selections)
2400 streams = g_list_append (streams, (gpointer) stream_id);
2401 chosen_stream_types |= stream_type;
2406 if (group->uridecodebin) {
2407 GstEvent *ev = gst_event_new_select_streams (streams);
2408 gst_element_send_event (group->uridecodebin, ev);
2410 g_list_free (streams);
2413 group->selected_stream_types = chosen_stream_types;
2414 /* Update global selected_stream_types */
2415 playbin->selected_stream_types =
2416 playbin->groups[0].selected_stream_types | playbin->
2417 groups[1].selected_stream_types;
2418 if (playbin->active_stream_types != playbin->selected_stream_types)
2419 reconfigure_output (playbin);
2422 /* Return the GstSourceGroup to which this element belongs
2423 * Can be NULL (if it belongs to playsink for example) */
2424 static GstSourceGroup *
2425 find_source_group_owner (GstPlayBin3 * playbin, GstObject * element)
2427 if (playbin->curr_group->uridecodebin
2428 && gst_object_has_as_ancestor (element,
2429 GST_OBJECT_CAST (playbin->curr_group->uridecodebin)))
2430 return playbin->curr_group;
2431 if (playbin->next_group->uridecodebin
2432 && gst_object_has_as_ancestor (element,
2433 GST_OBJECT_CAST (playbin->next_group->uridecodebin)))
2434 return playbin->next_group;
2439 gst_play_bin3_handle_message (GstBin * bin, GstMessage * msg)
2441 GstPlayBin3 *playbin = GST_PLAY_BIN3 (bin);
2443 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_STREAM_START) {
2444 GstSourceGroup *group = NULL, *other_group = NULL;
2445 gboolean changed = FALSE;
2447 GstMessage *buffering_msg;
2449 if (!gst_message_parse_group_id (msg, &group_id)) {
2450 GST_ERROR_OBJECT (bin,
2451 "Could not get group_id from STREAM_START message !");
2454 GST_DEBUG_OBJECT (bin, "STREAM_START group_id:%u", group_id);
2456 /* Figure out to which group this group_id corresponds */
2457 GST_PLAY_BIN3_LOCK (playbin);
2458 if (playbin->groups[0].group_id == group_id) {
2459 group = &playbin->groups[0];
2460 other_group = &playbin->groups[1];
2461 } else if (playbin->groups[1].group_id == group_id) {
2462 group = &playbin->groups[1];
2463 other_group = &playbin->groups[0];
2465 if (group == NULL) {
2466 GST_ERROR_OBJECT (bin, "group_id %u is not provided by any group !",
2468 GST_PLAY_BIN3_UNLOCK (playbin);
2472 debug_groups (playbin);
2474 /* Do the switch now ! */
2475 playbin->curr_group = group;
2476 playbin->next_group = other_group;
2478 GST_SOURCE_GROUP_LOCK (group);
2479 if (group->playing == FALSE)
2481 group->playing = TRUE;
2482 buffering_msg = group->pending_buffering_msg;
2483 group->pending_buffering_msg = NULL;
2484 GST_SOURCE_GROUP_UNLOCK (group);
2486 GST_SOURCE_GROUP_LOCK (other_group);
2487 other_group->playing = FALSE;
2488 GST_SOURCE_GROUP_UNLOCK (other_group);
2490 debug_groups (playbin);
2491 GST_PLAY_BIN3_UNLOCK (playbin);
2493 gst_play_bin3_check_group_status (playbin);
2495 GST_DEBUG_OBJECT (bin, "Groups didn't changed");
2496 /* If there was a pending buffering message to send, do it now */
2498 GST_BIN_CLASS (parent_class)->handle_message (bin, buffering_msg);
2499 } else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_BUFFERING) {
2500 GstSourceGroup *group;
2502 /* Only post buffering messages for group which is currently playing */
2503 group = find_source_group_owner (playbin, msg->src);
2504 GST_SOURCE_GROUP_LOCK (group);
2505 if (!group->playing) {
2506 GST_DEBUG_OBJECT (playbin, "Storing buffering message from pending group "
2507 "%p %" GST_PTR_FORMAT, group, msg);
2508 gst_message_replace (&group->pending_buffering_msg, msg);
2509 gst_message_unref (msg);
2512 GST_SOURCE_GROUP_UNLOCK (group);
2513 } else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_STREAM_COLLECTION) {
2514 GstStreamCollection *collection = NULL;
2516 gst_message_parse_stream_collection (msg, &collection);
2519 gboolean pstate = playbin->do_stream_selections;
2520 GstSourceGroup *target_group = NULL;
2522 GST_PLAY_BIN3_LOCK (playbin);
2523 GST_DEBUG_OBJECT (playbin,
2524 "STREAM_COLLECTION: Got a collection from %" GST_PTR_FORMAT,
2526 target_group = find_source_group_owner (playbin, msg->src);
2528 gst_object_replace ((GstObject **) & target_group->collection,
2529 (GstObject *) collection);
2530 /* FIXME: Only do the following if it's the current group? */
2531 if (target_group == playbin->curr_group)
2532 update_combiner_info (playbin, target_group->collection);
2534 playbin->do_stream_selections = FALSE;
2535 do_stream_selection (playbin, target_group);
2537 playbin->do_stream_selections = TRUE;
2538 GST_PLAY_BIN3_UNLOCK (playbin);
2540 gst_object_unref (collection);
2546 GST_BIN_CLASS (parent_class)->handle_message (bin, msg);
2550 gst_play_bin3_deep_element_added (GstBin * playbin, GstBin * sub_bin,
2553 GST_LOG_OBJECT (playbin, "element %" GST_PTR_FORMAT " was added to "
2554 "%" GST_PTR_FORMAT, child, sub_bin);
2556 g_signal_emit (playbin, gst_play_bin3_signals[SIGNAL_ELEMENT_SETUP], 0,
2559 GST_BIN_CLASS (parent_class)->deep_element_added (playbin, sub_bin, child);
2562 /* Returns current stream number, or -1 if none has been selected yet */
2564 get_current_stream_number (GstPlayBin3 * playbin, GstSourceCombine * combine,
2565 GPtrArray * channels)
2567 /* Internal API cleanup would make this easier... */
2569 GstPad *pad, *current;
2570 GstObject *combiner = NULL;
2573 if (!combine->has_active_pad) {
2574 GST_WARNING_OBJECT (playbin,
2575 "combiner doesn't have the \"active-pad\" property");
2579 for (i = 0; i < channels->len; i++) {
2580 pad = g_ptr_array_index (channels, i);
2581 if ((combiner = gst_pad_get_parent (pad))) {
2582 g_object_get (combiner, "active-pad", ¤t, NULL);
2583 gst_object_unref (combiner);
2585 if (pad == current) {
2586 gst_object_unref (current);
2592 gst_object_unref (current);
2600 combiner_active_pad_changed (GObject * combiner, GParamSpec * pspec,
2601 GstPlayBin3 * playbin)
2603 GstSourceCombine *combine = NULL;
2604 GPtrArray *channels = NULL;
2607 GST_PLAY_BIN3_LOCK (playbin);
2609 for (i = 0; i < PLAYBIN_STREAM_LAST; i++) {
2610 if (combiner == G_OBJECT (playbin->combiner[i].combiner)) {
2611 combine = &playbin->combiner[i];
2612 channels = playbin->channels[i];
2616 /* We got a pad-change after our group got switched out; no need to notify */
2618 GST_PLAY_BIN3_UNLOCK (playbin);
2622 switch (combine->type) {
2623 case GST_PLAY_SINK_TYPE_VIDEO:
2624 playbin->current_video = get_current_stream_number (playbin,
2627 if (playbin->video_pending_flush_finish) {
2628 playbin->video_pending_flush_finish = FALSE;
2629 GST_PLAY_BIN3_UNLOCK (playbin);
2630 gst_play_bin3_send_custom_event (GST_OBJECT (combiner),
2631 "playsink-custom-video-flush-finish");
2634 case GST_PLAY_SINK_TYPE_AUDIO:
2635 playbin->current_audio = get_current_stream_number (playbin,
2638 if (playbin->audio_pending_flush_finish) {
2639 playbin->audio_pending_flush_finish = FALSE;
2640 GST_PLAY_BIN3_UNLOCK (playbin);
2641 gst_play_bin3_send_custom_event (GST_OBJECT (combiner),
2642 "playsink-custom-audio-flush-finish");
2645 case GST_PLAY_SINK_TYPE_TEXT:
2646 playbin->current_text = get_current_stream_number (playbin,
2649 if (playbin->text_pending_flush_finish) {
2650 playbin->text_pending_flush_finish = FALSE;
2651 GST_PLAY_BIN3_UNLOCK (playbin);
2652 gst_play_bin3_send_custom_event (GST_OBJECT (combiner),
2653 "playsink-custom-subtitle-flush-finish");
2659 GST_PLAY_BIN3_UNLOCK (playbin);
2663 update_video_multiview_caps (GstPlayBin3 * playbin, GstCaps * caps)
2665 GstVideoMultiviewMode mv_mode;
2666 GstVideoMultiviewMode cur_mv_mode;
2667 guint mv_flags, cur_mv_flags;
2669 const gchar *mview_mode_str;
2672 GST_OBJECT_LOCK (playbin);
2673 mv_mode = (GstVideoMultiviewMode) playbin->multiview_mode;
2674 mv_flags = playbin->multiview_flags;
2675 GST_OBJECT_UNLOCK (playbin);
2677 if (mv_mode == GST_VIDEO_MULTIVIEW_MODE_NONE)
2680 cur_mv_mode = GST_VIDEO_MULTIVIEW_MODE_NONE;
2681 cur_mv_flags = GST_VIDEO_MULTIVIEW_FLAGS_NONE;
2683 s = gst_caps_get_structure (caps, 0);
2685 gst_structure_get_flagset (s, "multiview-flags", &cur_mv_flags, NULL);
2686 if ((mview_mode_str = gst_structure_get_string (s, "multiview-mode")))
2687 cur_mv_mode = gst_video_multiview_mode_from_caps_string (mview_mode_str);
2689 /* We can't override an existing annotated multiview mode, except
2690 * maybe (in the future) we could change some flags. */
2691 if ((gint) cur_mv_mode > GST_VIDEO_MULTIVIEW_MAX_FRAME_PACKING) {
2692 GST_INFO_OBJECT (playbin, "Cannot override existing multiview mode");
2696 mview_mode_str = gst_video_multiview_mode_to_caps_string (mv_mode);
2697 g_assert (mview_mode_str != NULL);
2698 out_caps = gst_caps_copy (caps);
2699 s = gst_caps_get_structure (out_caps, 0);
2701 gst_structure_set (s, "multiview-mode", G_TYPE_STRING, mview_mode_str,
2702 "multiview-flags", GST_TYPE_VIDEO_MULTIVIEW_FLAGSET, mv_flags,
2703 GST_FLAG_SET_MASK_EXACT, NULL);
2709 emit_about_to_finish (GstPlayBin3 * playbin)
2711 GST_DEBUG_OBJECT (playbin, "Emitting about-to-finish");
2713 /* after this call, we should have a next group to activate or we EOS */
2714 g_signal_emit (G_OBJECT (playbin),
2715 gst_play_bin3_signals[SIGNAL_ABOUT_TO_FINISH], 0, NULL);
2717 debug_groups (playbin);
2719 /* now activate the next group. If the app did not set a uri, this will
2720 * fail and we can do EOS */
2721 setup_next_source (playbin);
2725 find_source_pad (GstSourceGroup * group, GstPad * target)
2729 for (tmp = group->source_pads; tmp; tmp = tmp->next) {
2730 SourcePad *res = (SourcePad *) tmp->data;
2731 if (res->pad == target)
2737 static GstPadProbeReturn
2738 _decodebin_event_probe (GstPad * pad, GstPadProbeInfo * info, gpointer udata)
2740 GstPadProbeReturn ret = GST_PAD_PROBE_OK;
2741 GstSourceGroup *group = (GstSourceGroup *) udata;
2742 GstPlayBin3 *playbin = group->playbin;
2743 GstEvent *event = GST_PAD_PROBE_INFO_DATA (info);
2745 switch (GST_EVENT_TYPE (event)) {
2746 case GST_EVENT_CAPS:{
2747 GstCaps *caps = NULL;
2748 const GstStructure *s;
2751 gst_event_parse_caps (event, &caps);
2752 /* If video caps, check if we should override multiview flags */
2753 s = gst_caps_get_structure (caps, 0);
2754 name = gst_structure_get_name (s);
2755 if (g_str_has_prefix (name, "video/")) {
2756 caps = update_video_multiview_caps (playbin, caps);
2758 gst_event_unref (event);
2759 event = gst_event_new_caps (caps);
2760 GST_PAD_PROBE_INFO_DATA (info) = event;
2761 gst_caps_unref (caps);
2766 case GST_EVENT_STREAM_START:
2769 if (gst_event_parse_group_id (event, &group_id)) {
2770 GST_LOG_OBJECT (pad, "STREAM_START group_id:%u", group_id);
2771 if (group->group_id == GST_GROUP_ID_INVALID)
2772 group->group_id = group_id;
2773 else if (group->group_id != group_id) {
2774 GST_DEBUG_OBJECT (pad, "group_id changing from %u to %u",
2775 group->group_id, group_id);
2776 group->group_id = group_id;
2789 control_source_pad (GstSourceGroup * group, GstPad * pad,
2790 GstStreamType stream_type)
2792 SourcePad *sourcepad = g_slice_new0 (SourcePad);
2794 sourcepad->pad = pad;
2795 sourcepad->event_probe_id =
2796 gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
2797 _decodebin_event_probe, group, NULL);
2798 sourcepad->stream_type = stream_type;
2799 group->source_pads = g_list_append (group->source_pads, sourcepad);
2803 remove_combiner (GstPlayBin3 * playbin, GstSourceCombine * combine)
2807 if (combine->combiner == NULL) {
2808 GST_DEBUG_OBJECT (playbin, "No combiner element to remove");
2812 /* Go over all sink pads and release them ! */
2813 for (n = 0; n < combine->channels->len; n++) {
2814 GstPad *sinkpad = g_ptr_array_index (combine->channels, n);
2816 gst_element_release_request_pad (combine->combiner, sinkpad);
2817 gst_object_unref (sinkpad);
2819 g_ptr_array_set_size (combine->channels, 0);
2821 gst_element_set_state (combine->combiner, GST_STATE_NULL);
2822 gst_bin_remove (GST_BIN_CAST (playbin), combine->combiner);
2823 combine->combiner = NULL;
2827 /* Create the combiner element if needed for the given combine */
2829 create_combiner (GstPlayBin3 * playbin, GstSourceCombine * combine)
2831 GstElement *custom_combiner = NULL;
2833 if (combine->combiner) {
2834 GST_WARNING_OBJECT (playbin, "Combiner element already exists!");
2838 if (combine->stream_type == GST_STREAM_TYPE_VIDEO)
2839 custom_combiner = playbin->video_stream_combiner;
2840 else if (combine->stream_type == GST_STREAM_TYPE_AUDIO)
2841 custom_combiner = playbin->audio_stream_combiner;
2842 else if (combine->stream_type == GST_STREAM_TYPE_TEXT)
2843 custom_combiner = playbin->text_stream_combiner;
2845 combine->combiner = custom_combiner;
2847 if (!combine->combiner) {
2849 GST_DEBUG_OBJECT (playbin,
2850 "No custom combiner requested, using 'concat' element");
2851 concat_name = g_strdup_printf ("%s-concat", combine->media_type);
2852 combine->combiner = gst_element_factory_make ("concat", concat_name);
2853 g_object_set (combine->combiner, "adjust-base", FALSE, NULL);
2854 g_free (concat_name);
2855 combine->is_concat = TRUE;
2858 combine->srcpad = gst_element_get_static_pad (combine->combiner, "src");
2860 /* We only want to use 'active-pad' if it's a regular combiner that
2861 * will consume all streams, and not concat (which is just used for
2863 if (!combine->is_concat) {
2864 combine->has_active_pad =
2865 g_object_class_find_property (G_OBJECT_GET_CLASS (combine->combiner),
2866 "active-pad") != NULL;
2868 if (combine->has_active_pad)
2869 g_signal_connect (combine->combiner, "notify::active-pad",
2870 G_CALLBACK (combiner_active_pad_changed), playbin);
2873 GST_DEBUG_OBJECT (playbin, "adding new stream combiner %" GST_PTR_FORMAT,
2875 gst_bin_add (GST_BIN_CAST (playbin), combine->combiner);
2876 gst_element_sync_state_with_parent (combine->combiner);
2880 combiner_control_pad (GstPlayBin3 * playbin, GstSourceCombine * combine,
2883 GstPadLinkReturn res;
2885 GST_DEBUG_OBJECT (playbin, "srcpad %" GST_PTR_FORMAT, srcpad);
2887 if (combine->combiner) {
2889 gst_element_get_request_pad (combine->combiner, "sink_%u");
2891 if (sinkpad == NULL)
2892 goto request_pad_failed;
2894 GST_DEBUG_OBJECT (playbin, "Got new combiner pad %" GST_PTR_FORMAT,
2897 /* store the pad in the array */
2898 GST_DEBUG_OBJECT (playbin, "pad %" GST_PTR_FORMAT " added to array",
2900 g_ptr_array_add (combine->channels, sinkpad);
2902 res = gst_pad_link (srcpad, sinkpad);
2903 if (GST_PAD_LINK_FAILED (res))
2904 goto failed_combiner_link;
2906 GST_DEBUG_OBJECT (playbin,
2907 "linked pad %" GST_PTR_FORMAT " to combiner %" GST_PTR_FORMAT, srcpad,
2911 GST_LOG_OBJECT (playbin, "combine->sinkpad:%" GST_PTR_FORMAT,
2913 g_assert (combine->sinkpad != NULL);
2914 /* Connect directly to playsink */
2915 if (gst_pad_is_linked (combine->sinkpad))
2916 goto sinkpad_already_linked;
2918 GST_DEBUG_OBJECT (playbin, "Linking new pad straight to playsink");
2919 res = gst_pad_link (srcpad, combine->sinkpad);
2921 if (res != GST_PAD_LINK_OK)
2922 goto failed_sinkpad_link;
2929 GST_ELEMENT_ERROR (playbin, CORE, PAD,
2930 ("Internal playbin error."),
2931 ("Failed to get request pad from combiner %p.", combine->combiner));
2935 sinkpad_already_linked:
2936 GST_ELEMENT_ERROR (playbin, CORE, PAD,
2937 ("Internal playbin error."), ("playsink pad already used !"));
2940 failed_sinkpad_link:
2941 GST_ELEMENT_ERROR (playbin, CORE, PAD,
2942 ("Internal playbin error."),
2943 ("Failed to link pad to sink. Error %d", res));
2946 failed_combiner_link:
2947 GST_ELEMENT_ERROR (playbin, CORE, PAD,
2948 ("Internal playbin error."),
2949 ("Failed to link pad to combiner. Error %d", res));
2954 combiner_release_pad (GstPlayBin3 * playbin, GstSourceCombine * combine,
2957 if (combine->combiner) {
2958 GstPad *peer = gst_pad_get_peer (pad);
2961 GST_DEBUG_OBJECT (playbin, "Removing combiner pad %" GST_PTR_FORMAT,
2963 g_ptr_array_remove (combine->channels, peer);
2965 gst_element_release_request_pad (combine->combiner, peer);
2966 gst_object_unref (peer);
2969 /* Release direct link if present */
2970 if (combine->sinkpad) {
2971 GST_DEBUG_OBJECT (playbin, "Unlinking pad from playsink sinkpad");
2972 gst_pad_unlink (pad, combine->sinkpad);
2977 /* Call after pad was unlinked from (potential) combiner */
2979 release_source_pad (GstPlayBin3 * playbin, GstSourceGroup * group, GstPad * pad)
2981 SourcePad *sourcepad;
2983 GstStreamType alltype = 0;
2985 sourcepad = find_source_pad (group, pad);
2987 GST_DEBUG_OBJECT (playbin, "Not a pad controlled by us ?");
2991 if (sourcepad->event_probe_id) {
2992 gst_pad_remove_probe (pad, sourcepad->event_probe_id);
2993 sourcepad->event_probe_id = 0;
2996 /* Remove from list of controlled pads and check again for EOS status */
2997 group->source_pads = g_list_remove (group->source_pads, sourcepad);
2998 g_slice_free (SourcePad, sourcepad);
3000 /* Update present stream types */
3001 for (tmp = group->source_pads; tmp; tmp = tmp->next) {
3002 SourcePad *cand = (SourcePad *) tmp->data;
3003 alltype |= cand->stream_type;
3005 group->present_stream_types = alltype;
3008 /* this function is called when a new pad is added to decodebin. We check the
3009 * type of the pad and add it to the combiner element
3012 pad_added_cb (GstElement * uridecodebin, GstPad * pad, GstSourceGroup * group)
3014 GstSourceCombine *combine = NULL;
3015 gint pb_stream_type = -1;
3017 GstPlayBin3 *playbin = group->playbin;
3019 GST_PLAY_BIN3_SHUTDOWN_LOCK (playbin, shutdown);
3021 pad_name = gst_object_get_name (GST_OBJECT (pad));
3023 GST_DEBUG_OBJECT (playbin, "decoded pad %s:%s added",
3024 GST_DEBUG_PAD_NAME (pad));
3026 /* major type of the pad, this determines the combiner to use,
3027 try exact match first */
3028 if (g_str_has_prefix (pad_name, "video")) {
3029 pb_stream_type = PLAYBIN_STREAM_VIDEO;
3030 } else if (g_str_has_prefix (pad_name, "audio")) {
3031 pb_stream_type = PLAYBIN_STREAM_AUDIO;
3032 } else if (g_str_has_prefix (pad_name, "text")) {
3033 pb_stream_type = PLAYBIN_STREAM_TEXT;
3038 /* no stream type found for the media type, don't bother linking it to a
3039 * combiner. This will leave the pad unlinked and thus ignored. */
3040 if (pb_stream_type < 0) {
3041 GST_PLAY_BIN3_SHUTDOWN_UNLOCK (playbin);
3045 combine = &playbin->combiner[pb_stream_type];
3047 combiner_control_pad (playbin, combine, pad);
3049 control_source_pad (group, pad, combine->stream_type);
3051 /* Update present stream_types and check whether we should post a pending about-to-finish */
3052 group->present_stream_types |= combine->stream_type;
3054 if (group->playing && group->pending_about_to_finish
3055 && group->present_stream_types == group->selected_stream_types) {
3056 group->pending_about_to_finish = FALSE;
3057 emit_about_to_finish (playbin);
3060 GST_PLAY_BIN3_SHUTDOWN_UNLOCK (playbin);
3066 GST_DEBUG_OBJECT (playbin, "Ignoring pad with unknown type");
3071 GST_DEBUG ("ignoring, we are shutting down. Pad will be left unlinked");
3072 /* not going to done as we didn't request the caps */
3077 /* called when a pad is removed from the decodebin. We unlink the pad from
3080 pad_removed_cb (GstElement * decodebin, GstPad * pad, GstSourceGroup * group)
3082 GstSourceCombine *combine;
3083 GstPlayBin3 *playbin = group->playbin;
3085 GST_DEBUG_OBJECT (playbin,
3086 "decoded pad %s:%s removed", GST_DEBUG_PAD_NAME (pad));
3088 GST_PLAY_BIN3_LOCK (playbin);
3090 /* Get combiner for pad */
3091 if (g_str_has_prefix (GST_PAD_NAME (pad), "video"))
3092 combine = &playbin->combiner[PLAYBIN_STREAM_VIDEO];
3093 else if (g_str_has_prefix (GST_PAD_NAME (pad), "audio"))
3094 combine = &playbin->combiner[PLAYBIN_STREAM_AUDIO];
3095 else if (g_str_has_prefix (GST_PAD_NAME (pad), "text"))
3096 combine = &playbin->combiner[PLAYBIN_STREAM_TEXT];
3100 combiner_release_pad (playbin, combine, pad);
3101 release_source_pad (playbin, group, pad);
3103 GST_PLAY_BIN3_UNLOCK (playbin);
3108 select_stream_cb (GstElement * decodebin, GstStreamCollection * collection,
3109 GstStream * stream, GstSourceGroup * group)
3111 GstStreamType stype = gst_stream_get_stream_type (stream);
3112 GstElement *combiner = NULL;
3113 GstPlayBin3 *playbin = group->playbin;
3115 if (stype & GST_STREAM_TYPE_AUDIO)
3116 combiner = playbin->audio_stream_combiner;
3117 else if (stype & GST_STREAM_TYPE_VIDEO)
3118 combiner = playbin->video_stream_combiner;
3119 else if (stype & GST_STREAM_TYPE_TEXT)
3120 combiner = playbin->text_stream_combiner;
3123 GST_DEBUG_OBJECT (playbin, "Got a combiner, requesting stream activation");
3127 /* Let decodebin3 decide otherwise */
3131 /* We get called when the selected stream types change and
3132 * reconfiguration of output (i.e. playsink and potential combiners)
3136 reconfigure_output (GstPlayBin3 * playbin)
3138 GstPadLinkReturn res;
3141 g_assert (playbin->selected_stream_types != playbin->active_stream_types);
3143 GST_DEBUG_OBJECT (playbin, "selected_stream_types : %" STREAM_TYPES_FORMAT,
3144 STREAM_TYPES_ARGS (playbin->selected_stream_types));
3145 GST_DEBUG_OBJECT (playbin, "active_stream_types : %" STREAM_TYPES_FORMAT,
3146 STREAM_TYPES_ARGS (playbin->active_stream_types));
3148 GST_PLAY_BIN3_LOCK (playbin);
3150 /* Make sure combiners/playsink are in sync with selected stream types */
3151 for (i = 0; i < PLAYBIN_STREAM_LAST; i++) {
3152 GstSourceCombine *combine = &playbin->combiner[i];
3153 gboolean is_selected =
3154 (combine->stream_type & playbin->selected_stream_types) ==
3155 combine->stream_type;
3156 gboolean is_active =
3157 (combine->stream_type & playbin->active_stream_types) ==
3158 combine->stream_type;
3160 GST_DEBUG_OBJECT (playbin, "Stream type status: '%s' %s %s",
3161 combine->media_type, is_selected ? "selected" : "NOT selected",
3162 is_active ? "active" : "NOT active");
3163 /* FIXME : Remove asserts below once enough testing has been done */
3165 if (is_selected && is_active) {
3166 GST_DEBUG_OBJECT (playbin, "Stream type '%s' already active",
3167 combine->media_type);
3168 } else if (is_active && !is_selected) {
3169 GST_DEBUG_OBJECT (playbin, "Stream type '%s' is no longer requested",
3170 combine->media_type);
3172 /* Unlink combiner from sink */
3173 if (combine->srcpad) {
3174 GST_LOG_OBJECT (playbin, "Unlinking from sink");
3175 if (combine->sinkpad)
3176 gst_pad_unlink (combine->srcpad, combine->sinkpad);
3177 gst_object_unref (combine->srcpad);
3178 combine->srcpad = NULL;
3181 if (combine->sinkpad) {
3182 /* Release playsink sink pad */
3183 GST_LOG_OBJECT (playbin, "Releasing playsink pad");
3184 gst_play_sink_release_pad (playbin->playsink, combine->sinkpad);
3185 gst_object_unref (combine->sinkpad);
3186 combine->sinkpad = NULL;
3189 /* Release combiner */
3190 GST_FIXME_OBJECT (playbin, "Release combiner");
3191 remove_combiner (playbin, combine);
3192 } else if (!is_active && is_selected) {
3193 GST_DEBUG_OBJECT (playbin, "Stream type '%s' is now requested",
3194 combine->media_type);
3196 /* If we are shutting down, do *not* add more combiners */
3197 if (g_atomic_int_get (&playbin->shutdown))
3200 g_assert (combine->sinkpad == NULL);
3202 /* Request playsink sink pad */
3204 gst_play_sink_request_pad (playbin->playsink, combine->type);
3205 gst_object_ref (combine->sinkpad);
3206 /* Create combiner if needed and link it */
3207 create_combiner (playbin, combine);
3208 if (combine->combiner) {
3209 res = gst_pad_link (combine->srcpad, combine->sinkpad);
3210 GST_DEBUG_OBJECT (playbin, "linked type %s, result: %d",
3211 combine->media_type, res);
3212 if (res != GST_PAD_LINK_OK) {
3213 GST_ELEMENT_ERROR (playbin, CORE, PAD,
3214 ("Internal playbin error."),
3215 ("Failed to link combiner to sink. Error %d", res));
3222 playbin->active_stream_types = playbin->selected_stream_types;
3224 GST_PLAY_BIN3_UNLOCK (playbin);
3226 gst_play_sink_reconfigure (playbin->playsink);
3228 do_async_done (playbin);
3230 GST_DEBUG_OBJECT (playbin, "selected_stream_types : %" STREAM_TYPES_FORMAT,
3231 STREAM_TYPES_ARGS (playbin->selected_stream_types));
3232 GST_DEBUG_OBJECT (playbin, "active_stream_types : %" STREAM_TYPES_FORMAT,
3233 STREAM_TYPES_ARGS (playbin->active_stream_types));
3239 about_to_finish_cb (GstElement * uridecodebin, GstSourceGroup * group)
3241 GstPlayBin3 *playbin = group->playbin;
3242 GST_DEBUG_OBJECT (playbin, "about to finish in group %p", group);
3244 GST_LOG_OBJECT (playbin, "selected_stream_types:%" STREAM_TYPES_FORMAT,
3245 STREAM_TYPES_ARGS (group->selected_stream_types));
3246 GST_LOG_OBJECT (playbin, "present_stream_types:%" STREAM_TYPES_FORMAT,
3247 STREAM_TYPES_ARGS (group->present_stream_types));
3249 if (group->selected_stream_types == 0
3250 || (group->selected_stream_types != group->present_stream_types)) {
3251 GST_LOG_OBJECT (playbin,
3252 "Delaying emission of signal until this group is ready");
3253 group->pending_about_to_finish = TRUE;
3255 emit_about_to_finish (playbin);
3258 #if 0 /* AUTOPLUG DISABLED */
3259 /* Like gst_element_factory_can_sink_any_caps() but doesn't
3260 * allow ANY caps on the sinkpad template */
3262 _factory_can_sink_caps (GstElementFactory * factory, GstCaps * caps)
3264 const GList *templs;
3266 templs = gst_element_factory_get_static_pad_templates (factory);
3269 GstStaticPadTemplate *templ = (GstStaticPadTemplate *) templs->data;
3271 if (templ->direction == GST_PAD_SINK) {
3272 GstCaps *templcaps = gst_static_caps_get (&templ->static_caps);
3274 if (!gst_caps_is_any (templcaps)
3275 && gst_caps_is_subset (caps, templcaps)) {
3276 gst_caps_unref (templcaps);
3279 gst_caps_unref (templcaps);
3281 templs = g_list_next (templs);
3288 avelements_free (gpointer avelement)
3290 GstAVElement *elm = (GstAVElement *) avelement;
3293 gst_object_unref (elm->dec);
3295 gst_object_unref (elm->sink);
3296 g_slice_free (GstAVElement, elm);
3300 avelement_compare_decoder (gconstpointer p1, gconstpointer p2,
3303 GstAVElement *v1, *v2;
3305 v1 = (GstAVElement *) p1;
3306 v2 = (GstAVElement *) p2;
3308 return strcmp (GST_OBJECT_NAME (v1->dec), GST_OBJECT_NAME (v2->dec));
3312 avelement_lookup_decoder (gconstpointer p1, gconstpointer p2,
3316 GstElementFactory *f2;
3318 v1 = (GstAVElement *) p1;
3319 f2 = (GstElementFactory *) p2;
3321 return strcmp (GST_OBJECT_NAME (v1->dec), GST_OBJECT_NAME (f2));
3325 avelement_compare (gconstpointer p1, gconstpointer p2)
3327 GstAVElement *v1, *v2;
3328 GstPluginFeature *fd1, *fd2, *fs1, *fs2;
3329 gint64 diff, v1_rank, v2_rank;
3331 v1 = (GstAVElement *) p1;
3332 v2 = (GstAVElement *) p2;
3334 fd1 = (GstPluginFeature *) v1->dec;
3335 fd2 = (GstPluginFeature *) v2->dec;
3337 /* If both have a sink, we also compare their ranks */
3338 if (v1->sink && v2->sink) {
3339 fs1 = (GstPluginFeature *) v1->sink;
3340 fs2 = (GstPluginFeature *) v2->sink;
3341 v1_rank = (gint64) gst_plugin_feature_get_rank (fd1) *
3342 gst_plugin_feature_get_rank (fs1);
3343 v2_rank = (gint64) gst_plugin_feature_get_rank (fd2) *
3344 gst_plugin_feature_get_rank (fs2);
3346 v1_rank = gst_plugin_feature_get_rank (fd1);
3347 v2_rank = gst_plugin_feature_get_rank (fd2);
3351 /* comparison based on the rank */
3352 diff = v2_rank - v1_rank;
3358 /* comparison based on number of common caps features */
3359 diff = v2->n_comm_cf - v1->n_comm_cf;
3364 /* comparison based on the name of sink elements */
3365 diff = strcmp (GST_OBJECT_NAME (fs1), GST_OBJECT_NAME (fs2));
3370 /* comparison based on the name of decoder elements */
3371 return strcmp (GST_OBJECT_NAME (fd1), GST_OBJECT_NAME (fd2));
3375 avelements_create (GstPlayBin3 * playbin, gboolean isaudioelement)
3377 GstElementFactory *d_factory, *s_factory;
3378 GList *dec_list, *sink_list, *dl, *sl;
3379 GSequence *ave_seq = NULL;
3381 guint n_common_cf = 0;
3383 if (isaudioelement) {
3384 sink_list = gst_element_factory_list_get_elements
3385 (GST_ELEMENT_FACTORY_TYPE_SINK |
3386 GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO, GST_RANK_MARGINAL);
3388 gst_element_factory_list_get_elements (GST_ELEMENT_FACTORY_TYPE_DECODER
3389 | GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO, GST_RANK_MARGINAL);
3391 sink_list = gst_element_factory_list_get_elements
3392 (GST_ELEMENT_FACTORY_TYPE_SINK |
3393 GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO |
3394 GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE, GST_RANK_MARGINAL);
3397 gst_element_factory_list_get_elements (GST_ELEMENT_FACTORY_TYPE_DECODER
3398 | GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO |
3399 GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE, GST_RANK_MARGINAL);
3402 /* create a list of audio/video elements. Each element in the list
3403 * is holding an audio/video decoder and an audio/video sink in which
3404 * the decoders srcpad template caps and sink element's sinkpad template
3405 * caps are compatible */
3409 ave_seq = g_sequence_new ((GDestroyNotify) avelements_free);
3411 for (; dl; dl = dl->next) {
3412 d_factory = (GstElementFactory *) dl->data;
3413 for (; sl; sl = sl->next) {
3414 s_factory = (GstElementFactory *) sl->data;
3417 gst_playback_utils_get_n_common_capsfeatures (d_factory, s_factory,
3418 gst_play_bin3_get_flags (playbin), isaudioelement);
3419 if (n_common_cf < 1)
3422 ave = g_slice_new (GstAVElement);
3423 ave->dec = gst_object_ref (d_factory);
3424 ave->sink = gst_object_ref (s_factory);
3425 ave->n_comm_cf = n_common_cf;
3426 g_sequence_append (ave_seq, ave);
3430 g_sequence_sort (ave_seq, (GCompareDataFunc) avelement_compare_decoder, NULL);
3432 gst_plugin_feature_list_free (dec_list);
3433 gst_plugin_feature_list_free (sink_list);
3439 avelement_iter_is_equal (GSequenceIter * iter, GstElementFactory * factory)
3446 ave = g_sequence_get (iter);
3450 return strcmp (GST_OBJECT_NAME (ave->dec), GST_OBJECT_NAME (factory)) == 0;
3454 create_decoders_list (GList * factory_list, GSequence * avelements)
3456 GList *dec_list = NULL, *tmp;
3457 GList *ave_list = NULL;
3458 GList *ave_free_list = NULL;
3459 GstAVElement *ave, *best_ave;
3461 g_return_val_if_fail (factory_list != NULL, NULL);
3462 g_return_val_if_fail (avelements != NULL, NULL);
3464 for (tmp = factory_list; tmp; tmp = tmp->next) {
3465 GstElementFactory *factory = (GstElementFactory *) tmp->data;
3467 /* if there are parsers or sink elements, add them first */
3468 if (gst_element_factory_list_is_type (factory,
3469 GST_ELEMENT_FACTORY_TYPE_PARSER) ||
3470 gst_element_factory_list_is_type (factory,
3471 GST_ELEMENT_FACTORY_TYPE_SINK)) {
3472 dec_list = g_list_prepend (dec_list, gst_object_ref (factory));
3474 GSequenceIter *seq_iter;
3477 g_sequence_lookup (avelements, factory,
3478 (GCompareDataFunc) avelement_lookup_decoder, NULL);
3480 GstAVElement *ave = g_slice_new0 (GstAVElement);
3484 /* There's at least raw */
3487 ave_list = g_list_prepend (ave_list, ave);
3489 /* We need to free these later */
3490 ave_free_list = g_list_prepend (ave_free_list, ave);
3494 /* Go to first iter with that decoder */
3496 GSequenceIter *tmp_seq_iter;
3498 tmp_seq_iter = g_sequence_iter_prev (seq_iter);
3499 if (!avelement_iter_is_equal (tmp_seq_iter, factory))
3501 seq_iter = tmp_seq_iter;
3502 } while (!g_sequence_iter_is_begin (seq_iter));
3504 /* Get the best ranked GstAVElement for that factory */
3506 while (!g_sequence_iter_is_end (seq_iter)
3507 && avelement_iter_is_equal (seq_iter, factory)) {
3508 ave = g_sequence_get (seq_iter);
3510 if (!best_ave || avelement_compare (ave, best_ave) < 0)
3513 seq_iter = g_sequence_iter_next (seq_iter);
3515 ave_list = g_list_prepend (ave_list, best_ave);
3519 /* Sort all GstAVElements by their relative ranks and insert
3520 * into the decoders list */
3521 ave_list = g_list_sort (ave_list, (GCompareFunc) avelement_compare);
3522 for (tmp = ave_list; tmp; tmp = tmp->next) {
3523 ave = (GstAVElement *) tmp->data;
3524 dec_list = g_list_prepend (dec_list, gst_object_ref (ave->dec));
3526 g_list_free (ave_list);
3527 gst_plugin_feature_list_free (factory_list);
3529 for (tmp = ave_free_list; tmp; tmp = tmp->next)
3530 g_slice_free (GstAVElement, tmp->data);
3531 g_list_free (ave_free_list);
3533 dec_list = g_list_reverse (dec_list);
3538 /* Called when we must provide a list of factories to plug to @pad with @caps.
3539 * We first check if we have a sink that can handle the format and if we do, we
3540 * return NULL, to expose the pad. If we have no sink (or the sink does not
3541 * work), we return the list of elements that can connect. */
3542 static GValueArray *
3543 autoplug_factories_cb (GstElement * decodebin, GstPad * pad,
3544 GstCaps * caps, GstSourceGroup * group)
3546 GstPlayBin3 *playbin;
3547 GList *factory_list, *tmp;
3548 GValueArray *result;
3549 gboolean unref_caps = FALSE;
3550 gboolean isaudiodeclist = FALSE;
3551 gboolean isvideodeclist = FALSE;
3554 caps = gst_caps_new_any ();
3558 playbin = group->playbin;
3560 GST_DEBUG_OBJECT (playbin, "factories group %p for %s:%s, %" GST_PTR_FORMAT,
3561 group, GST_DEBUG_PAD_NAME (pad), caps);
3563 /* filter out the elements based on the caps. */
3564 g_mutex_lock (&playbin->elements_lock);
3565 gst_play_bin3_update_elements_list (playbin);
3567 gst_element_factory_list_filter (playbin->elements, caps, GST_PAD_SINK,
3568 gst_caps_is_fixed (caps));
3569 g_mutex_unlock (&playbin->elements_lock);
3571 GST_DEBUG_OBJECT (playbin, "found factories %p", factory_list);
3572 GST_PLUGIN_FEATURE_LIST_DEBUG (factory_list);
3574 /* check whether the caps are asking for a list of audio/video decoders */
3576 if (!gst_caps_is_any (caps)) {
3577 for (; tmp; tmp = tmp->next) {
3578 GstElementFactory *factory = (GstElementFactory *) tmp->data;
3580 isvideodeclist = gst_element_factory_list_is_type (factory,
3581 GST_ELEMENT_FACTORY_TYPE_DECODER |
3582 GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO |
3583 GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE);
3584 isaudiodeclist = gst_element_factory_list_is_type (factory,
3585 GST_ELEMENT_FACTORY_TYPE_DECODER |
3586 GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO);
3588 if (isaudiodeclist || isvideodeclist)
3593 if (isaudiodeclist || isvideodeclist) {
3594 GSequence **ave_list;
3596 ave_list = &playbin->aelements;
3598 ave_list = &playbin->velements;
3600 g_mutex_lock (&playbin->elements_lock);
3601 /* sort factory_list based on the GstAVElement list priority */
3602 factory_list = create_decoders_list (factory_list, *ave_list);
3603 g_mutex_unlock (&playbin->elements_lock);
3606 /* 2 additional elements for the already set audio/video sinks */
3607 result = g_value_array_new (g_list_length (factory_list) + 2);
3609 /* Check if we already have an audio/video sink and if this is the case
3610 * put it as the first element of the array */
3611 if (group->audio_sink) {
3612 GstElementFactory *factory = gst_element_get_factory (group->audio_sink);
3614 if (factory && _factory_can_sink_caps (factory, caps)) {
3615 GValue val = { 0, };
3617 g_value_init (&val, G_TYPE_OBJECT);
3618 g_value_set_object (&val, factory);
3619 result = g_value_array_append (result, &val);
3620 g_value_unset (&val);
3624 if (group->video_sink) {
3625 GstElementFactory *factory = gst_element_get_factory (group->video_sink);
3627 if (factory && _factory_can_sink_caps (factory, caps)) {
3628 GValue val = { 0, };
3630 g_value_init (&val, G_TYPE_OBJECT);
3631 g_value_set_object (&val, factory);
3632 result = g_value_array_append (result, &val);
3633 g_value_unset (&val);
3637 for (tmp = factory_list; tmp; tmp = tmp->next) {
3638 GstElementFactory *factory = GST_ELEMENT_FACTORY_CAST (tmp->data);
3639 GValue val = { 0, };
3641 if (group->audio_sink && gst_element_factory_list_is_type (factory,
3642 GST_ELEMENT_FACTORY_TYPE_SINK |
3643 GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO)) {
3646 if (group->video_sink && gst_element_factory_list_is_type (factory,
3647 GST_ELEMENT_FACTORY_TYPE_SINK | GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO
3648 | GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE)) {
3652 g_value_init (&val, G_TYPE_OBJECT);
3653 g_value_set_object (&val, factory);
3654 g_value_array_append (result, &val);
3655 g_value_unset (&val);
3657 gst_plugin_feature_list_free (factory_list);
3660 gst_caps_unref (caps);
3666 static GstBusSyncReply
3667 activate_sink_bus_handler (GstBus * bus, GstMessage * msg,
3668 GstPlayBin3 * playbin)
3670 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
3671 /* Only proxy errors from a fixed sink. If that fails we can just error out
3672 * early as stuff will fail later anyway */
3673 if (playbin->audio_sink
3674 && gst_object_has_as_ancestor (GST_MESSAGE_SRC (msg),
3675 GST_OBJECT_CAST (playbin->audio_sink)))
3676 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
3677 else if (playbin->video_sink
3678 && gst_object_has_as_ancestor (GST_MESSAGE_SRC (msg),
3679 GST_OBJECT_CAST (playbin->video_sink)))
3680 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
3681 else if (playbin->text_sink
3682 && gst_object_has_as_ancestor (GST_MESSAGE_SRC (msg),
3683 GST_OBJECT_CAST (playbin->text_sink)))
3684 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
3686 gst_message_unref (msg);
3687 } else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_HAVE_CONTEXT) {
3688 GstContext *context;
3690 gst_message_parse_have_context (msg, &context);
3691 gst_element_set_context (GST_ELEMENT_CAST (playbin), context);
3692 gst_context_unref (context);
3693 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
3695 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
3698 /* Doesn't really matter, nothing is using this bus */
3699 return GST_BUS_DROP;
3703 activate_sink (GstPlayBin3 * playbin, GstElement * sink, gboolean * activated)
3707 GstStateChangeReturn sret;
3708 gboolean ret = FALSE;
3713 GST_OBJECT_LOCK (sink);
3714 state = GST_STATE (sink);
3715 GST_OBJECT_UNLOCK (sink);
3716 if (state >= GST_STATE_READY) {
3721 if (!GST_OBJECT_PARENT (sink)) {
3722 bus = gst_bus_new ();
3723 gst_bus_set_sync_handler (bus,
3724 (GstBusSyncHandler) activate_sink_bus_handler, playbin, NULL);
3725 gst_element_set_bus (sink, bus);
3728 sret = gst_element_set_state (sink, GST_STATE_READY);
3729 if (sret == GST_STATE_CHANGE_FAILURE)
3738 gst_element_set_bus (sink, NULL);
3739 gst_object_unref (bus);
3745 #if 0 /* AUTOPLUG DISABLED */
3746 /* autoplug-continue decides, if a pad has raw caps that can be exposed
3747 * directly or if further decoding is necessary. We use this to expose
3748 * supported subtitles directly */
3750 /* FIXME 0.11: Remove the checks for ANY caps, a sink should specify
3751 * explicitly the caps it supports and if it claims to support ANY
3752 * caps it really should support everything */
3754 autoplug_continue_cb (GstElement * element, GstPad * pad, GstCaps * caps,
3755 GstSourceGroup * group)
3757 gboolean ret = TRUE;
3758 GstPad *sinkpad = NULL;
3759 gboolean activated_sink;
3761 GST_SOURCE_GROUP_LOCK (group);
3763 if (group->text_sink &&
3764 activate_sink (group->playbin, group->text_sink, &activated_sink)) {
3765 sinkpad = gst_element_get_static_pad (group->text_sink, "sink");
3769 sinkcaps = gst_pad_query_caps (sinkpad, NULL);
3770 if (!gst_caps_is_any (sinkcaps))
3771 ret = !gst_pad_query_accept_caps (sinkpad, caps);
3772 gst_caps_unref (sinkcaps);
3773 gst_object_unref (sinkpad);
3776 gst_element_set_state (group->text_sink, GST_STATE_NULL);
3778 GstCaps *subcaps = gst_subtitle_overlay_create_factory_caps ();
3779 ret = !gst_caps_is_subset (caps, subcaps);
3780 gst_caps_unref (subcaps);
3782 /* If autoplugging can stop don't do additional checks */
3786 if (group->audio_sink &&
3787 activate_sink (group->playbin, group->audio_sink, &activated_sink)) {
3789 sinkpad = gst_element_get_static_pad (group->audio_sink, "sink");
3793 sinkcaps = gst_pad_query_caps (sinkpad, NULL);
3794 if (!gst_caps_is_any (sinkcaps))
3795 ret = !gst_pad_query_accept_caps (sinkpad, caps);
3796 gst_caps_unref (sinkcaps);
3797 gst_object_unref (sinkpad);
3800 gst_element_set_state (group->audio_sink, GST_STATE_NULL);
3805 if (group->video_sink
3806 && activate_sink (group->playbin, group->video_sink, &activated_sink)) {
3807 sinkpad = gst_element_get_static_pad (group->video_sink, "sink");
3811 sinkcaps = gst_pad_query_caps (sinkpad, NULL);
3812 if (!gst_caps_is_any (sinkcaps))
3813 ret = !gst_pad_query_accept_caps (sinkpad, caps);
3814 gst_caps_unref (sinkcaps);
3815 gst_object_unref (sinkpad);
3818 gst_element_set_state (group->video_sink, GST_STATE_NULL);
3822 GST_SOURCE_GROUP_UNLOCK (group);
3824 GST_DEBUG_OBJECT (group->playbin,
3825 "continue autoplugging group %p for %s:%s, %" GST_PTR_FORMAT ": %d",
3826 group, GST_DEBUG_PAD_NAME (pad), caps, ret);
3832 sink_accepts_caps (GstPlayBin3 * playbin, GstElement * sink, GstCaps * caps)
3836 if ((sinkpad = gst_element_get_static_pad (sink, "sink"))) {
3837 /* Got the sink pad, now let's see if the element actually does accept the
3838 * caps that we have */
3839 if (!gst_pad_query_accept_caps (sinkpad, caps)) {
3840 gst_object_unref (sinkpad);
3843 gst_object_unref (sinkpad);
3849 /* We are asked to select an element. See if the next element to check
3850 * is a sink. If this is the case, we see if the sink works by setting it to
3851 * READY. If the sink works, we return SELECT_EXPOSE to make decodebin
3852 * expose the raw pad so that we can setup the mixers. */
3853 static GstAutoplugSelectResult
3854 autoplug_select_cb (GstElement * decodebin, GstPad * pad,
3855 GstCaps * caps, GstElementFactory * factory, GstSourceGroup * group)
3857 GstPlayBin3 *playbin;
3858 GstElement *element;
3860 GstPlaySinkType type;
3862 GList *ave_list = NULL, *l;
3863 GstAVElement *ave = NULL;
3864 GSequence *ave_seq = NULL;
3865 GSequenceIter *seq_iter;
3867 playbin = group->playbin;
3869 GST_DEBUG_OBJECT (playbin, "select group %p for %s:%s, %" GST_PTR_FORMAT,
3870 group, GST_DEBUG_PAD_NAME (pad), caps);
3872 GST_DEBUG_OBJECT (playbin, "checking factory %s", GST_OBJECT_NAME (factory));
3874 /* if it's not a sink, we make sure the element is compatible with
3876 if (!gst_element_factory_list_is_type (factory,
3877 GST_ELEMENT_FACTORY_TYPE_SINK)) {
3878 gboolean isvideodec = gst_element_factory_list_is_type (factory,
3879 GST_ELEMENT_FACTORY_TYPE_DECODER |
3880 GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO |
3881 GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE);
3882 gboolean isaudiodec = gst_element_factory_list_is_type (factory,
3883 GST_ELEMENT_FACTORY_TYPE_DECODER |
3884 GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO);
3886 if (!isvideodec && !isaudiodec)
3887 return GST_AUTOPLUG_SELECT_TRY;
3889 GST_SOURCE_GROUP_LOCK (group);
3890 g_mutex_lock (&playbin->elements_lock);
3893 ave_seq = playbin->aelements;
3894 sinkp = &group->audio_sink;
3896 ave_seq = playbin->velements;
3897 sinkp = &group->video_sink;
3901 g_sequence_lookup (ave_seq, factory,
3902 (GCompareDataFunc) avelement_lookup_decoder, NULL);
3904 /* Go to first iter with that decoder */
3906 GSequenceIter *tmp_seq_iter;
3908 tmp_seq_iter = g_sequence_iter_prev (seq_iter);
3909 if (!avelement_iter_is_equal (tmp_seq_iter, factory))
3911 seq_iter = tmp_seq_iter;
3912 } while (!g_sequence_iter_is_begin (seq_iter));
3914 while (!g_sequence_iter_is_end (seq_iter)
3915 && avelement_iter_is_equal (seq_iter, factory)) {
3916 ave = g_sequence_get (seq_iter);
3917 ave_list = g_list_prepend (ave_list, ave);
3918 seq_iter = g_sequence_iter_next (seq_iter);
3921 /* Sort all GstAVElements by their relative ranks and insert
3922 * into the decoders list */
3923 ave_list = g_list_sort (ave_list, (GCompareFunc) avelement_compare);
3925 ave_list = g_list_prepend (ave_list, NULL);
3928 /* if it is a decoder and we don't have a fixed sink, then find out
3929 * the matching audio/video sink from GstAVElements list */
3930 for (l = ave_list; l; l = l->next) {
3931 gboolean created_sink = FALSE;
3933 ave = (GstAVElement *) l->data;
3935 if (((isaudiodec && !group->audio_sink) ||
3936 (isvideodec && !group->video_sink))) {
3937 if (ave && ave->sink) {
3938 GST_DEBUG_OBJECT (playbin,
3939 "Trying to create sink '%s' for decoder '%s'",
3940 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (ave->sink)),
3941 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
3942 if ((*sinkp = gst_element_factory_create (ave->sink, NULL)) == NULL) {
3943 GST_WARNING_OBJECT (playbin,
3944 "Could not create an element from %s",
3945 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (ave->sink)));
3948 if (!activate_sink (playbin, *sinkp, NULL)) {
3949 gst_object_unref (*sinkp);
3951 GST_WARNING_OBJECT (playbin,
3952 "Could not activate sink %s",
3953 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (ave->sink)));
3956 gst_object_ref_sink (*sinkp);
3957 created_sink = TRUE;
3962 /* If it is a decoder and we have a fixed sink for the media
3963 * type it outputs, check that the decoder is compatible with this sink */
3964 if ((isaudiodec && group->audio_sink) || (isvideodec
3965 && group->video_sink)) {
3966 gboolean compatible = FALSE;
3973 if ((sinkpad = gst_element_get_static_pad (sink, "sink"))) {
3974 GstPlayFlags flags = gst_play_bin3_get_flags (playbin);
3976 (isaudiodec) ? gst_static_caps_get (&raw_audio_caps) :
3977 gst_static_caps_get (&raw_video_caps);
3979 caps = gst_pad_query_caps (sinkpad, NULL);
3981 /* If the sink supports raw audio/video, we first check
3982 * if the decoder could output any raw audio/video format
3983 * and assume it is compatible with the sink then. We don't
3984 * do a complete compatibility check here if converters
3985 * are plugged between the decoder and the sink because
3986 * the converters will convert between raw formats and
3987 * even if the decoder format is not supported by the decoder
3988 * a converter will convert it.
3990 * We assume here that the converters can convert between
3993 if ((isaudiodec && !(flags & GST_PLAY_FLAG_NATIVE_AUDIO)
3994 && gst_caps_can_intersect (caps, raw_caps)) || (!isaudiodec
3995 && !(flags & GST_PLAY_FLAG_NATIVE_VIDEO)
3996 && gst_caps_can_intersect (caps, raw_caps))) {
3998 gst_element_factory_can_src_any_caps (factory, raw_caps)
3999 || gst_element_factory_can_src_any_caps (factory, caps);
4001 compatible = gst_element_factory_can_src_any_caps (factory, caps);
4004 gst_object_unref (sinkpad);
4005 gst_caps_unref (caps);
4011 GST_DEBUG_OBJECT (playbin, "%s not compatible with the fixed sink",
4012 GST_OBJECT_NAME (factory));
4014 /* If it is not compatible, either continue with the next possible
4015 * sink or if we have a fixed sink, skip the decoder */
4017 gst_element_set_state (*sinkp, GST_STATE_NULL);
4018 gst_object_unref (*sinkp);
4021 g_mutex_unlock (&playbin->elements_lock);
4022 GST_SOURCE_GROUP_UNLOCK (group);
4023 return GST_AUTOPLUG_SELECT_SKIP;
4027 g_list_free (ave_list);
4028 g_mutex_unlock (&playbin->elements_lock);
4029 GST_SOURCE_GROUP_UNLOCK (group);
4030 return GST_AUTOPLUG_SELECT_TRY;
4033 /* it's a sink, see if an instance of it actually works */
4034 GST_DEBUG_OBJECT (playbin, "we found a sink '%s'", GST_OBJECT_NAME (factory));
4037 gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
4039 /* figure out the klass */
4040 if (strstr (klass, "Audio")) {
4041 GST_DEBUG_OBJECT (playbin, "we found an audio sink");
4042 type = GST_PLAY_SINK_TYPE_AUDIO;
4043 sinkp = &group->audio_sink;
4044 } else if (strstr (klass, "Video")) {
4045 GST_DEBUG_OBJECT (playbin, "we found a video sink");
4046 type = GST_PLAY_SINK_TYPE_VIDEO;
4047 sinkp = &group->video_sink;
4049 /* unknown klass, skip this element */
4050 GST_WARNING_OBJECT (playbin, "unknown sink klass %s found", klass);
4051 return GST_AUTOPLUG_SELECT_SKIP;
4054 /* if we are asked to do visualisations and it's an audio sink, skip the
4055 * element. We can only do visualisations with raw sinks */
4056 if (gst_play_sink_get_flags (playbin->playsink) & GST_PLAY_FLAG_VIS) {
4057 if (type == GST_PLAY_SINK_TYPE_AUDIO) {
4058 GST_DEBUG_OBJECT (playbin, "skip audio sink because of vis");
4059 return GST_AUTOPLUG_SELECT_SKIP;
4063 /* now see if we already have a sink element */
4064 GST_SOURCE_GROUP_LOCK (group);
4065 if (*sinkp && GST_STATE (*sinkp) >= GST_STATE_READY) {
4066 GstElement *sink = gst_object_ref (*sinkp);
4068 if (sink_accepts_caps (playbin, sink, caps)) {
4069 GST_DEBUG_OBJECT (playbin,
4070 "Existing sink '%s' accepts caps: %" GST_PTR_FORMAT,
4071 GST_ELEMENT_NAME (sink), caps);
4072 gst_object_unref (sink);
4073 GST_SOURCE_GROUP_UNLOCK (group);
4074 return GST_AUTOPLUG_SELECT_EXPOSE;
4076 GST_DEBUG_OBJECT (playbin,
4077 "Existing sink '%s' does not accept caps: %" GST_PTR_FORMAT,
4078 GST_ELEMENT_NAME (sink), caps);
4079 gst_object_unref (sink);
4080 GST_SOURCE_GROUP_UNLOCK (group);
4081 return GST_AUTOPLUG_SELECT_SKIP;
4084 GST_DEBUG_OBJECT (playbin, "we have no pending sink, try to create '%s'",
4085 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
4087 if ((*sinkp = gst_element_factory_create (factory, NULL)) == NULL) {
4088 GST_WARNING_OBJECT (playbin, "Could not create an element from %s",
4089 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
4090 GST_SOURCE_GROUP_UNLOCK (group);
4091 return GST_AUTOPLUG_SELECT_SKIP;
4096 if (!activate_sink (playbin, element, NULL)) {
4097 GST_WARNING_OBJECT (playbin, "Could not activate sink %s",
4098 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
4100 gst_object_unref (element);
4101 GST_SOURCE_GROUP_UNLOCK (group);
4102 return GST_AUTOPLUG_SELECT_SKIP;
4105 /* Check if the selected sink actually supports the
4106 * caps and can be set to READY*/
4107 if (!sink_accepts_caps (playbin, element, caps)) {
4109 gst_element_set_state (element, GST_STATE_NULL);
4110 gst_object_unref (element);
4111 GST_SOURCE_GROUP_UNLOCK (group);
4112 return GST_AUTOPLUG_SELECT_SKIP;
4115 /* remember the sink in the group now, the element is floating, we take
4118 * store the sink in the group, we will configure it later when we
4119 * reconfigure the sink */
4120 GST_DEBUG_OBJECT (playbin, "remember sink");
4121 gst_object_ref_sink (element);
4122 GST_SOURCE_GROUP_UNLOCK (group);
4124 /* tell decodebin to expose the pad because we are going to use this
4126 GST_DEBUG_OBJECT (playbin, "we found a working sink, expose pad");
4128 return GST_AUTOPLUG_SELECT_EXPOSE;
4131 #define GST_PLAY_BIN3_FILTER_CAPS(filter,caps) G_STMT_START { \
4133 GstCaps *intersection = \
4134 gst_caps_intersect_full ((filter), (caps), GST_CAPS_INTERSECT_FIRST); \
4135 gst_caps_unref ((caps)); \
4136 (caps) = intersection; \
4141 autoplug_query_caps (GstElement * uridecodebin, GstPad * pad,
4142 GstElement * element, GstQuery * query, GstSourceGroup * group)
4144 GstCaps *filter, *result = NULL;
4146 GstPad *sinkpad = NULL;
4147 GstElementFactory *factory;
4148 GstElementFactoryListType factory_type;
4149 gboolean have_sink = FALSE;
4151 GST_SOURCE_GROUP_LOCK (group);
4152 gst_query_parse_caps (query, &filter);
4154 factory = gst_element_get_factory (element);
4158 if (gst_element_factory_list_is_type (factory,
4159 GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO |
4160 GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE)) {
4162 GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO |
4163 GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE;
4165 if ((sink = group->video_sink)) {
4166 sinkpad = gst_element_get_static_pad (sink, "sink");
4170 sinkcaps = gst_pad_query_caps (sinkpad, filter);
4171 if (!gst_caps_is_any (sinkcaps)) {
4175 result = gst_caps_merge (result, sinkcaps);
4177 gst_caps_unref (sinkcaps);
4179 gst_object_unref (sinkpad);
4183 } else if (gst_element_factory_list_is_type (factory,
4184 GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO)) {
4185 factory_type = GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO;
4187 if ((sink = group->audio_sink)) {
4188 sinkpad = gst_element_get_static_pad (sink, "sink");
4192 sinkcaps = gst_pad_query_caps (sinkpad, filter);
4193 if (!gst_caps_is_any (sinkcaps)) {
4197 result = gst_caps_merge (result, sinkcaps);
4199 gst_caps_unref (sinkcaps);
4201 gst_object_unref (sinkpad);
4205 } else if (gst_element_factory_list_is_type (factory,
4206 GST_ELEMENT_FACTORY_TYPE_MEDIA_SUBTITLE)) {
4207 factory_type = GST_ELEMENT_FACTORY_TYPE_MEDIA_SUBTITLE;
4209 if ((sink = group->playbin->text_sink)) {
4210 sinkpad = gst_element_get_static_pad (sink, "sink");
4214 sinkcaps = gst_pad_query_caps (sinkpad, filter);
4215 if (!gst_caps_is_any (sinkcaps)) {
4219 result = gst_caps_merge (result, sinkcaps);
4221 gst_caps_unref (sinkcaps);
4223 gst_object_unref (sinkpad);
4227 GstCaps *subcaps = gst_subtitle_overlay_create_factory_caps ();
4228 GST_PLAY_BIN3_FILTER_CAPS (filter, subcaps);
4232 result = gst_caps_merge (result, subcaps);
4239 GValueArray *factories;
4242 factories = autoplug_factories_cb (uridecodebin, pad, NULL, group);
4243 n = factories->n_values;
4244 for (i = 0; i < n; i++) {
4245 GValue *v = g_value_array_get_nth (factories, i);
4246 GstElementFactory *f = g_value_get_object (v);
4247 const GList *templates;
4249 GstCaps *templ_caps;
4251 if (!gst_element_factory_list_is_type (f, factory_type))
4254 templates = gst_element_factory_get_static_pad_templates (f);
4256 for (l = templates; l; l = l->next) {
4257 templ_caps = gst_static_pad_template_get_caps (l->data);
4259 if (!gst_caps_is_any (templ_caps)) {
4260 GST_PLAY_BIN3_FILTER_CAPS (filter, templ_caps);
4262 result = templ_caps;
4264 result = gst_caps_merge (result, templ_caps);
4266 gst_caps_unref (templ_caps);
4270 g_value_array_free (factories);
4274 GST_SOURCE_GROUP_UNLOCK (group);
4279 /* Add the actual decoder/parser/etc caps at the very end to
4280 * make sure we don't cause empty caps to be returned, e.g.
4281 * if a parser asks us but a decoder is required after it
4282 * because no sink can handle the format directly.
4285 GstPad *target = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
4288 GstCaps *target_caps = gst_pad_get_pad_template_caps (target);
4289 GST_PLAY_BIN3_FILTER_CAPS (filter, target_caps);
4290 result = gst_caps_merge (result, target_caps);
4291 gst_object_unref (target);
4296 gst_query_set_caps_result (query, result);
4297 gst_caps_unref (result);
4303 autoplug_query_context (GstElement * uridecodebin, GstPad * pad,
4304 GstElement * element, GstQuery * query, GstSourceGroup * group)
4307 GstPad *sinkpad = NULL;
4308 GstElementFactory *factory;
4309 gboolean res = FALSE;
4311 GST_SOURCE_GROUP_LOCK (group);
4313 factory = gst_element_get_factory (element);
4317 if (gst_element_factory_list_is_type (factory,
4318 GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO |
4319 GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE)) {
4320 if ((sink = group->video_sink)) {
4321 sinkpad = gst_element_get_static_pad (sink, "sink");
4323 res = gst_pad_query (sinkpad, query);
4324 gst_object_unref (sinkpad);
4327 } else if (gst_element_factory_list_is_type (factory,
4328 GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO)) {
4329 if ((sink = group->audio_sink)) {
4330 sinkpad = gst_element_get_static_pad (sink, "sink");
4332 res = gst_pad_query (sinkpad, query);
4333 gst_object_unref (sinkpad);
4336 } else if (gst_element_factory_list_is_type (factory,
4337 GST_ELEMENT_FACTORY_TYPE_MEDIA_SUBTITLE)) {
4338 if ((sink = group->playbin->text_sink)) {
4339 sinkpad = gst_element_get_static_pad (sink, "sink");
4341 res = gst_pad_query (sinkpad, query);
4342 gst_object_unref (sinkpad);
4350 GST_SOURCE_GROUP_UNLOCK (group);
4356 autoplug_query_cb (GstElement * uridecodebin, GstPad * pad,
4357 GstElement * element, GstQuery * query, GstSourceGroup * group)
4360 switch (GST_QUERY_TYPE (query)) {
4361 case GST_QUERY_CAPS:
4362 return autoplug_query_caps (uridecodebin, pad, element, query, group);
4363 case GST_QUERY_CONTEXT:
4364 return autoplug_query_context (uridecodebin, pad, element, query, group);
4371 /* must be called with the group lock */
4373 group_set_locked_state_unlocked (GstPlayBin3 * playbin, GstSourceGroup * group,
4376 GST_DEBUG_OBJECT (playbin, "locked_state %d on group %p", locked, group);
4378 if (group->uridecodebin)
4379 gst_element_set_locked_state (group->uridecodebin, locked);
4385 make_or_reuse_element (GstPlayBin3 * playbin, const gchar * name,
4389 GST_DEBUG_OBJECT (playbin, "reusing existing %s", name);
4390 gst_element_set_state (*elem, GST_STATE_READY);
4391 /* no need to take extra ref, we already have one
4392 * and the bin will add one since it is no longer floating,
4393 * as we added a non-floating ref when removing it from the
4396 GstElement *new_elem;
4397 GST_DEBUG_OBJECT (playbin, "making new %s", name);
4398 new_elem = gst_element_factory_make (name, NULL);
4401 *elem = gst_object_ref (new_elem);
4404 if (GST_OBJECT_PARENT (*elem) != GST_OBJECT_CAST (playbin))
4405 gst_bin_add (GST_BIN_CAST (playbin), *elem);
4411 source_setup_cb (GstElement * element, GstElement * source,
4412 GstSourceGroup * group)
4414 g_signal_emit (group->playbin, gst_play_bin3_signals[SIGNAL_SOURCE_SETUP], 0,
4418 /* must be called with PLAY_BIN_LOCK */
4419 static GstStateChangeReturn
4420 activate_group (GstPlayBin3 * playbin, GstSourceGroup * group)
4422 GstElement *uridecodebin = NULL;
4424 gboolean audio_sink_activated = FALSE;
4425 gboolean video_sink_activated = FALSE;
4426 gboolean text_sink_activated = FALSE;
4427 GstStateChangeReturn state_ret;
4429 g_return_val_if_fail (group->valid, GST_STATE_CHANGE_FAILURE);
4430 g_return_val_if_fail (!group->active, GST_STATE_CHANGE_FAILURE);
4432 GST_DEBUG_OBJECT (playbin, "activating group %p", group);
4434 GST_SOURCE_GROUP_LOCK (group);
4436 /* First set up the custom sinks */
4437 if (playbin->audio_sink)
4438 group->audio_sink = gst_object_ref (playbin->audio_sink);
4441 gst_play_sink_get_sink (playbin->playsink, GST_PLAY_SINK_TYPE_AUDIO);
4443 if (group->audio_sink) {
4444 if (!activate_sink (playbin, group->audio_sink, &audio_sink_activated)) {
4445 if (group->audio_sink == playbin->audio_sink) {
4448 gst_object_unref (group->audio_sink);
4449 group->audio_sink = NULL;
4454 if (playbin->video_sink)
4455 group->video_sink = gst_object_ref (playbin->video_sink);
4458 gst_play_sink_get_sink (playbin->playsink, GST_PLAY_SINK_TYPE_VIDEO);
4460 if (group->video_sink) {
4461 if (!activate_sink (playbin, group->video_sink, &video_sink_activated)) {
4462 if (group->video_sink == playbin->video_sink) {
4465 gst_object_unref (group->video_sink);
4466 group->video_sink = NULL;
4471 if (playbin->text_sink)
4472 group->text_sink = gst_object_ref (playbin->text_sink);
4475 gst_play_sink_get_sink (playbin->playsink, GST_PLAY_SINK_TYPE_TEXT);
4477 if (group->text_sink) {
4478 if (!activate_sink (playbin, group->text_sink, &text_sink_activated)) {
4479 if (group->text_sink == playbin->text_sink) {
4482 gst_object_unref (group->text_sink);
4483 group->text_sink = NULL;
4489 if (!make_or_reuse_element (playbin, "uridecodebin3", &group->uridecodebin))
4490 goto no_uridecodebin;
4491 uridecodebin = group->uridecodebin;
4493 flags = gst_play_sink_get_flags (playbin->playsink);
4495 g_object_set (uridecodebin,
4496 /* configure connection speed */
4497 "connection-speed", playbin->connection_speed / 1000,
4500 /* configure download buffering */
4501 "download", ((flags & GST_PLAY_FLAG_DOWNLOAD) != 0),
4502 /* configure buffering of demuxed/parsed data */
4503 "use-buffering", ((flags & GST_PLAY_FLAG_BUFFERING) != 0),
4504 /* configure buffering parameters */
4505 "buffer-duration", playbin->buffer_duration,
4506 "buffer-size", playbin->buffer_size,
4507 "ring-buffer-max-size", playbin->ring_buffer_max_size, NULL);
4509 group->pad_added_id = g_signal_connect (uridecodebin, "pad-added",
4510 G_CALLBACK (pad_added_cb), group);
4511 group->pad_removed_id = g_signal_connect (uridecodebin,
4512 "pad-removed", G_CALLBACK (pad_removed_cb), group);
4513 group->select_stream_id = g_signal_connect (uridecodebin, "select-stream",
4514 G_CALLBACK (select_stream_cb), group);
4515 group->source_setup_id = g_signal_connect (uridecodebin, "source-setup",
4516 G_CALLBACK (source_setup_cb), group);
4517 group->about_to_finish_id =
4518 g_signal_connect (uridecodebin, "about-to-finish",
4519 G_CALLBACK (about_to_finish_cb), group);
4522 g_object_set (group->uridecodebin, "suburi", group->suburi, NULL);
4524 /* release the group lock before setting the state of the source bins, they
4525 * might fire signals in this thread that we need to handle with the
4526 * group_lock taken. */
4527 GST_SOURCE_GROUP_UNLOCK (group);
4530 gst_element_set_state (uridecodebin,
4531 GST_STATE_PAUSED)) == GST_STATE_CHANGE_FAILURE)
4532 goto uridecodebin_failure;
4534 GST_SOURCE_GROUP_LOCK (group);
4535 /* allow state changes of the playbin affect the group elements now */
4536 group_set_locked_state_unlocked (playbin, group, FALSE);
4537 group->active = TRUE;
4538 GST_SOURCE_GROUP_UNLOCK (group);
4547 GST_SOURCE_GROUP_UNLOCK (group);
4549 gst_missing_element_message_new (GST_ELEMENT_CAST (playbin),
4551 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
4553 GST_ELEMENT_ERROR (playbin, CORE, MISSING_PLUGIN,
4554 (_("Could not create \"uridecodebin3\" element.")), (NULL));
4556 GST_SOURCE_GROUP_LOCK (group);
4560 uridecodebin_failure:
4562 GST_DEBUG_OBJECT (playbin, "failed state change of uridecodebin");
4563 GST_SOURCE_GROUP_LOCK (group);
4568 GST_ERROR_OBJECT (playbin, "failed to activate sinks");
4574 group->selected_stream_types = 0;
4576 /* delete any custom sinks we might have */
4577 if (group->audio_sink) {
4578 /* If this is a automatically created sink set it to NULL */
4579 if (audio_sink_activated)
4580 gst_element_set_state (group->audio_sink, GST_STATE_NULL);
4581 gst_object_unref (group->audio_sink);
4583 group->audio_sink = NULL;
4585 if (group->video_sink) {
4586 /* If this is a automatically created sink set it to NULL */
4587 if (video_sink_activated)
4588 gst_element_set_state (group->video_sink, GST_STATE_NULL);
4589 gst_object_unref (group->video_sink);
4591 group->video_sink = NULL;
4593 if (group->text_sink) {
4594 /* If this is a automatically created sink set it to NULL */
4595 if (text_sink_activated)
4596 gst_element_set_state (group->text_sink, GST_STATE_NULL);
4597 gst_object_unref (group->text_sink);
4599 group->text_sink = NULL;
4602 REMOVE_SIGNAL (group->uridecodebin, group->pad_added_id);
4603 REMOVE_SIGNAL (group->uridecodebin, group->pad_removed_id);
4604 REMOVE_SIGNAL (group->uridecodebin, group->select_stream_id);
4605 REMOVE_SIGNAL (group->uridecodebin, group->source_setup_id);
4606 REMOVE_SIGNAL (group->uridecodebin, group->about_to_finish_id);
4608 REMOVE_SIGNAL (group->urisourcebin, group->autoplug_factories_id);
4609 REMOVE_SIGNAL (group->urisourcebin, group->autoplug_select_id);
4610 REMOVE_SIGNAL (group->urisourcebin, group->autoplug_continue_id);
4611 REMOVE_SIGNAL (group->urisourcebin, group->autoplug_query_id);
4614 gst_element_set_state (uridecodebin, GST_STATE_NULL);
4615 gst_bin_remove (GST_BIN_CAST (playbin), uridecodebin);
4618 GST_SOURCE_GROUP_UNLOCK (group);
4620 return GST_STATE_CHANGE_FAILURE;
4624 /* must be called with PLAY_BIN_LOCK */
4626 deactivate_group (GstPlayBin3 * playbin, GstSourceGroup * group)
4628 g_return_val_if_fail (group->active, FALSE);
4629 g_return_val_if_fail (group->valid, FALSE);
4631 GST_DEBUG_OBJECT (playbin, "unlinking group %p", group);
4633 GST_SOURCE_GROUP_LOCK (group);
4634 group->active = FALSE;
4635 group->playing = FALSE;
4636 group->group_id = GST_GROUP_ID_INVALID;
4638 group->selected_stream_types = 0;
4639 /* Update global selected_stream_types */
4640 playbin->selected_stream_types =
4641 playbin->groups[0].selected_stream_types | playbin->
4642 groups[1].selected_stream_types;
4643 if (playbin->active_stream_types != playbin->selected_stream_types)
4644 reconfigure_output (playbin);
4647 /* delete any custom sinks we might have.
4648 * conditionally set them to null if they aren't inside playsink yet */
4649 if (group->audio_sink) {
4650 if (!gst_object_has_as_ancestor (GST_OBJECT_CAST (group->audio_sink),
4651 GST_OBJECT_CAST (playbin->playsink))) {
4652 gst_element_set_state (group->audio_sink, GST_STATE_NULL);
4654 gst_object_unref (group->audio_sink);
4656 group->audio_sink = NULL;
4657 if (group->video_sink) {
4658 if (!gst_object_has_as_ancestor (GST_OBJECT_CAST (group->video_sink),
4659 GST_OBJECT_CAST (playbin->playsink))) {
4660 gst_element_set_state (group->video_sink, GST_STATE_NULL);
4662 gst_object_unref (group->video_sink);
4664 group->video_sink = NULL;
4665 if (group->text_sink) {
4666 if (!gst_object_has_as_ancestor (GST_OBJECT_CAST (group->text_sink),
4667 GST_OBJECT_CAST (playbin->playsink))) {
4668 gst_element_set_state (group->text_sink, GST_STATE_NULL);
4670 gst_object_unref (group->text_sink);
4672 group->text_sink = NULL;
4675 if (group->uridecodebin) {
4676 REMOVE_SIGNAL (group->uridecodebin, group->select_stream_id);
4677 REMOVE_SIGNAL (group->uridecodebin, group->source_setup_id);
4678 REMOVE_SIGNAL (group->uridecodebin, group->about_to_finish_id);
4680 gst_element_set_state (group->uridecodebin, GST_STATE_NULL);
4681 gst_bin_remove (GST_BIN_CAST (playbin), group->uridecodebin);
4683 REMOVE_SIGNAL (group->uridecodebin, group->pad_added_id);
4684 REMOVE_SIGNAL (group->uridecodebin, group->pad_removed_id);
4686 REMOVE_SIGNAL (group->urisourcebin, group->autoplug_factories_id);
4687 REMOVE_SIGNAL (group->urisourcebin, group->autoplug_select_id);
4688 REMOVE_SIGNAL (group->urisourcebin, group->autoplug_continue_id);
4689 REMOVE_SIGNAL (group->urisourcebin, group->autoplug_query_id);
4693 GST_SOURCE_GROUP_UNLOCK (group);
4695 GST_DEBUG_OBJECT (playbin, "Done");
4700 /* setup the next group to play, this assumes the next_group is valid and
4701 * configured. It swaps out the current_group and activates the valid
4703 static GstStateChangeReturn
4704 setup_next_source (GstPlayBin3 * playbin)
4706 GstSourceGroup *new_group;
4707 GstStateChangeReturn state_ret;
4709 GST_DEBUG_OBJECT (playbin, "setup next source");
4711 debug_groups (playbin);
4713 /* see if there is a next group */
4714 GST_PLAY_BIN3_LOCK (playbin);
4715 new_group = playbin->next_group;
4716 if (!new_group || !new_group->valid || new_group->active)
4719 /* activate the new group */
4720 state_ret = activate_group (playbin, new_group);
4721 if (state_ret == GST_STATE_CHANGE_FAILURE)
4722 goto activate_failed;
4724 GST_PLAY_BIN3_UNLOCK (playbin);
4726 debug_groups (playbin);
4733 GST_DEBUG_OBJECT (playbin, "no next group");
4734 GST_PLAY_BIN3_UNLOCK (playbin);
4735 return GST_STATE_CHANGE_FAILURE;
4739 new_group->stream_changed_pending = FALSE;
4740 GST_DEBUG_OBJECT (playbin, "activate failed");
4741 new_group->valid = FALSE;
4742 GST_PLAY_BIN3_UNLOCK (playbin);
4743 return GST_STATE_CHANGE_FAILURE;
4747 /* The group that is currently playing is copied again to the
4748 * next_group so that it will start playing the next time.
4751 save_current_group (GstPlayBin3 * playbin)
4753 GstSourceGroup *curr_group;
4755 GST_DEBUG_OBJECT (playbin, "save current group");
4757 /* see if there is a current group */
4758 GST_PLAY_BIN3_LOCK (playbin);
4759 curr_group = playbin->curr_group;
4760 if (curr_group && curr_group->valid && curr_group->active) {
4761 /* unlink our pads with the sink */
4762 deactivate_group (playbin, curr_group);
4764 /* swap old and new */
4765 playbin->curr_group = playbin->next_group;
4766 playbin->next_group = curr_group;
4767 GST_PLAY_BIN3_UNLOCK (playbin);
4772 /* clear the locked state from all groups. This function is called before a
4773 * state change to NULL is performed on them. */
4775 groups_set_locked_state (GstPlayBin3 * playbin, gboolean locked)
4777 GST_DEBUG_OBJECT (playbin, "setting locked state to %d on all groups",
4780 GST_PLAY_BIN3_LOCK (playbin);
4781 GST_SOURCE_GROUP_LOCK (playbin->curr_group);
4782 group_set_locked_state_unlocked (playbin, playbin->curr_group, locked);
4783 GST_SOURCE_GROUP_UNLOCK (playbin->curr_group);
4784 GST_SOURCE_GROUP_LOCK (playbin->next_group);
4785 group_set_locked_state_unlocked (playbin, playbin->next_group, locked);
4786 GST_SOURCE_GROUP_UNLOCK (playbin->next_group);
4787 GST_PLAY_BIN3_UNLOCK (playbin);
4793 gst_play_bin3_check_group_status (GstPlayBin3 * playbin)
4795 if (playbin->activation_task)
4796 gst_task_start (playbin->activation_task);
4800 gst_play_bin3_activation_thread (GstPlayBin3 * playbin)
4802 GST_DEBUG_OBJECT (playbin, "starting");
4804 debug_groups (playbin);
4806 /* Check if next_group needs to be deactivated */
4807 GST_PLAY_BIN3_LOCK (playbin);
4808 if (playbin->next_group->active) {
4809 deactivate_group (playbin, playbin->next_group);
4810 playbin->next_group->valid = FALSE;
4813 /* Is there a pending about-to-finish to be emitted ? */
4814 GST_SOURCE_GROUP_LOCK (playbin->curr_group);
4815 if (playbin->curr_group->pending_about_to_finish) {
4816 GST_LOG_OBJECT (playbin, "Propagating about-to-finish");
4817 playbin->curr_group->pending_about_to_finish = FALSE;
4818 GST_SOURCE_GROUP_UNLOCK (playbin->curr_group);
4819 /* This will activate the next source afterwards */
4820 emit_about_to_finish (playbin);
4822 GST_SOURCE_GROUP_UNLOCK (playbin->curr_group);
4824 GST_LOG_OBJECT (playbin, "Pausing task");
4825 if (playbin->activation_task)
4826 gst_task_pause (playbin->activation_task);
4827 GST_PLAY_BIN3_UNLOCK (playbin);
4829 GST_DEBUG_OBJECT (playbin, "done");
4834 gst_play_bin3_start (GstPlayBin3 * playbin)
4836 GST_DEBUG_OBJECT (playbin, "starting");
4838 GST_PLAY_BIN3_LOCK (playbin);
4840 if (playbin->activation_task == NULL) {
4841 playbin->activation_task =
4842 gst_task_new ((GstTaskFunction) gst_play_bin3_activation_thread,
4844 if (playbin->activation_task == NULL)
4846 gst_task_set_lock (playbin->activation_task, &playbin->activation_lock);
4848 GST_LOG_OBJECT (playbin, "clearing shutdown flag");
4849 g_atomic_int_set (&playbin->shutdown, 0);
4850 do_async_start (playbin);
4852 GST_PLAY_BIN3_UNLOCK (playbin);
4858 GST_PLAY_BIN3_UNLOCK (playbin);
4859 GST_ERROR_OBJECT (playbin, "Failed to create task");
4865 gst_play_bin3_stop (GstPlayBin3 * playbin)
4869 GST_DEBUG_OBJECT (playbin, "stopping");
4871 /* FIXME unlock our waiting groups */
4872 GST_LOG_OBJECT (playbin, "setting shutdown flag");
4873 g_atomic_int_set (&playbin->shutdown, 1);
4875 /* wait for all callbacks to end by taking the lock.
4876 * No dynamic (critical) new callbacks will
4877 * be able to happen as we set the shutdown flag. */
4878 GST_PLAY_BIN3_DYN_LOCK (playbin);
4879 GST_LOG_OBJECT (playbin, "dynamic lock taken, we can continue shutdown");
4880 GST_PLAY_BIN3_DYN_UNLOCK (playbin);
4882 /* Stop the activation task */
4883 GST_PLAY_BIN3_LOCK (playbin);
4884 if ((task = playbin->activation_task)) {
4885 playbin->activation_task = NULL;
4886 GST_PLAY_BIN3_UNLOCK (playbin);
4888 gst_task_stop (task);
4890 /* Make sure task is not running */
4891 g_rec_mutex_lock (&playbin->activation_lock);
4892 g_rec_mutex_unlock (&playbin->activation_lock);
4894 /* Wait for task to finish and unref it */
4895 gst_task_join (task);
4896 gst_object_unref (task);
4898 GST_PLAY_BIN3_LOCK (playbin);
4900 GST_PLAY_BIN3_UNLOCK (playbin);
4903 static GstStateChangeReturn
4904 gst_play_bin3_change_state (GstElement * element, GstStateChange transition)
4906 GstStateChangeReturn ret;
4907 GstPlayBin3 *playbin;
4908 gboolean do_save = FALSE;
4910 playbin = GST_PLAY_BIN3 (element);
4912 switch (transition) {
4913 case GST_STATE_CHANGE_READY_TO_PAUSED:
4914 if (!gst_play_bin3_start (playbin))
4915 return GST_STATE_CHANGE_FAILURE;
4917 case GST_STATE_CHANGE_PAUSED_TO_READY:
4919 gst_play_bin3_stop (playbin);
4922 case GST_STATE_CHANGE_READY_TO_NULL:
4923 /* we go async to PAUSED, so if that fails, we never make it to PAUSED
4924 * and we will never be called with the GST_STATE_CHANGE_PAUSED_TO_READY.
4925 * Make sure we do go through the same steps (see above) for
4927 if (!g_atomic_int_get (&playbin->shutdown)) {
4932 /* unlock so that all groups go to NULL */
4933 groups_set_locked_state (playbin, FALSE);
4939 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
4940 if (ret == GST_STATE_CHANGE_FAILURE)
4943 switch (transition) {
4944 case GST_STATE_CHANGE_READY_TO_PAUSED:
4945 if ((ret = setup_next_source (playbin)) == GST_STATE_CHANGE_FAILURE)
4947 if (ret == GST_STATE_CHANGE_SUCCESS)
4948 ret = GST_STATE_CHANGE_ASYNC;
4951 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
4952 do_async_done (playbin);
4953 /* FIXME Release audio device when we implement that */
4955 case GST_STATE_CHANGE_PAUSED_TO_READY:
4956 save_current_group (playbin);
4958 case GST_STATE_CHANGE_READY_TO_NULL:
4962 /* also do missed state change down to READY */
4964 save_current_group (playbin);
4965 /* Deactivate the groups, set uridecodebin to NULL and unref it */
4966 for (i = 0; i < 2; i++) {
4967 if (playbin->groups[i].active && playbin->groups[i].valid) {
4968 deactivate_group (playbin, &playbin->groups[i]);
4969 playbin->groups[i].valid = FALSE;
4972 if (playbin->groups[i].uridecodebin) {
4973 gst_element_set_state (playbin->groups[i].uridecodebin,
4975 gst_object_unref (playbin->groups[i].uridecodebin);
4976 playbin->groups[i].uridecodebin = NULL;
4981 /* Set our sinks back to NULL, they might not be child of playbin */
4982 if (playbin->audio_sink)
4983 gst_element_set_state (playbin->audio_sink, GST_STATE_NULL);
4984 if (playbin->video_sink)
4985 gst_element_set_state (playbin->video_sink, GST_STATE_NULL);
4986 if (playbin->text_sink)
4987 gst_element_set_state (playbin->text_sink, GST_STATE_NULL);
4989 if (playbin->video_stream_combiner)
4990 gst_element_set_state (playbin->video_stream_combiner, GST_STATE_NULL);
4991 if (playbin->audio_stream_combiner)
4992 gst_element_set_state (playbin->audio_stream_combiner, GST_STATE_NULL);
4993 if (playbin->text_stream_combiner)
4994 gst_element_set_state (playbin->text_stream_combiner, GST_STATE_NULL);
4996 /* make sure the groups don't perform a state change anymore until we
4997 * enable them again */
4998 groups_set_locked_state (playbin, TRUE);
5005 if (ret == GST_STATE_CHANGE_NO_PREROLL)
5006 do_async_done (playbin);
5013 do_async_done (playbin);
5015 if (transition == GST_STATE_CHANGE_READY_TO_PAUSED) {
5016 GstSourceGroup *curr_group;
5018 curr_group = playbin->curr_group;
5020 if (curr_group->active && curr_group->valid) {
5021 /* unlink our pads with the sink */
5022 deactivate_group (playbin, curr_group);
5024 curr_group->valid = FALSE;
5027 /* Swap current and next group back */
5028 playbin->curr_group = playbin->next_group;
5029 playbin->next_group = curr_group;
5036 gst_play_bin3_overlay_expose (GstVideoOverlay * overlay)
5038 GstPlayBin3 *playbin = GST_PLAY_BIN3 (overlay);
5040 gst_video_overlay_expose (GST_VIDEO_OVERLAY (playbin->playsink));
5044 gst_play_bin3_overlay_handle_events (GstVideoOverlay * overlay,
5045 gboolean handle_events)
5047 GstPlayBin3 *playbin = GST_PLAY_BIN3 (overlay);
5049 gst_video_overlay_handle_events (GST_VIDEO_OVERLAY (playbin->playsink),
5054 gst_play_bin3_overlay_set_render_rectangle (GstVideoOverlay * overlay, gint x,
5055 gint y, gint width, gint height)
5057 GstPlayBin3 *playbin = GST_PLAY_BIN3 (overlay);
5059 gst_video_overlay_set_render_rectangle (GST_VIDEO_OVERLAY (playbin->playsink),
5060 x, y, width, height);
5064 gst_play_bin3_overlay_set_window_handle (GstVideoOverlay * overlay,
5067 GstPlayBin3 *playbin = GST_PLAY_BIN3 (overlay);
5069 gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (playbin->playsink),
5074 gst_play_bin3_overlay_init (gpointer g_iface, gpointer g_iface_data)
5076 GstVideoOverlayInterface *iface = (GstVideoOverlayInterface *) g_iface;
5077 iface->expose = gst_play_bin3_overlay_expose;
5078 iface->handle_events = gst_play_bin3_overlay_handle_events;
5079 iface->set_render_rectangle = gst_play_bin3_overlay_set_render_rectangle;
5080 iface->set_window_handle = gst_play_bin3_overlay_set_window_handle;
5084 gst_play_bin3_navigation_send_event (GstNavigation * navigation,
5085 GstStructure * structure)
5087 GstPlayBin3 *playbin = GST_PLAY_BIN3 (navigation);
5089 gst_navigation_send_event (GST_NAVIGATION (playbin->playsink), structure);
5093 gst_play_bin3_navigation_init (gpointer g_iface, gpointer g_iface_data)
5095 GstNavigationInterface *iface = (GstNavigationInterface *) g_iface;
5097 iface->send_event = gst_play_bin3_navigation_send_event;
5100 static const GList *
5101 gst_play_bin3_colorbalance_list_channels (GstColorBalance * balance)
5103 GstPlayBin3 *playbin = GST_PLAY_BIN3 (balance);
5106 gst_color_balance_list_channels (GST_COLOR_BALANCE (playbin->playsink));
5110 gst_play_bin3_colorbalance_set_value (GstColorBalance * balance,
5111 GstColorBalanceChannel * channel, gint value)
5113 GstPlayBin3 *playbin = GST_PLAY_BIN3 (balance);
5115 gst_color_balance_set_value (GST_COLOR_BALANCE (playbin->playsink), channel,
5120 gst_play_bin3_colorbalance_get_value (GstColorBalance * balance,
5121 GstColorBalanceChannel * channel)
5123 GstPlayBin3 *playbin = GST_PLAY_BIN3 (balance);
5125 return gst_color_balance_get_value (GST_COLOR_BALANCE (playbin->playsink),
5129 static GstColorBalanceType
5130 gst_play_bin3_colorbalance_get_balance_type (GstColorBalance * balance)
5132 GstPlayBin3 *playbin = GST_PLAY_BIN3 (balance);
5135 gst_color_balance_get_balance_type (GST_COLOR_BALANCE
5136 (playbin->playsink));
5140 gst_play_bin3_colorbalance_init (gpointer g_iface, gpointer g_iface_data)
5142 GstColorBalanceInterface *iface = (GstColorBalanceInterface *) g_iface;
5144 iface->list_channels = gst_play_bin3_colorbalance_list_channels;
5145 iface->set_value = gst_play_bin3_colorbalance_set_value;
5146 iface->get_value = gst_play_bin3_colorbalance_get_value;
5147 iface->get_balance_type = gst_play_bin3_colorbalance_get_balance_type;
5151 gst_play_bin3_custom_element_init (GstPlugin * plugin)
5153 gboolean ret = TRUE;
5155 GST_DEBUG_CATEGORY_INIT (gst_play_bin3_debug, "playbin3", 0, "play bin3");
5157 playback_element_init (plugin);
5159 if (g_getenv ("USE_PLAYBIN3"))
5160 ret &= gst_element_register (plugin, "playbin", GST_RANK_NONE,
5163 ret &= gst_element_register (plugin, "playbin3", GST_RANK_NONE,