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>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
24 * SECTION:element-playbin
27 * Playbin provides a stand-alone everything-in-one abstraction for an
28 * audio and/or video player.
30 * Playbin can handle both audio and video files and features
32 * * automatic file type recognition and based on that automatic
33 * selection and usage of the right audio/video/subtitle demuxers/decoders
34 * * visualisations for audio files
35 * * subtitle support for video files. Subtitles can be store in external
37 * * stream selection between different video/audio/subtitles streams
38 * * meta info (tag) extraction
39 * * easy access to the last video sample
40 * * buffering when playing streams over a network
41 * * volume control with mute option
45 * A playbin element can be created just like any other element using
46 * gst_element_factory_make(). The file/URI to play should be set via the #GstPlayBin:uri
47 * property. This must be an absolute URI, relative file paths are not allowed.
48 * Example URIs are file:///home/joe/movie.avi or http://www.joedoe.com/foo.ogg
50 * Playbin is a #GstPipeline. It will notify the application of everything
51 * that's happening (errors, end of stream, tags found, state changes, etc.)
52 * by posting messages on its #GstBus. The application needs to watch the
55 * Playback can be initiated by setting the element to PLAYING state using
56 * gst_element_set_state(). Note that the state change will take place in
57 * the background in a separate thread, when the function returns playback
58 * is probably not happening yet and any errors might not have occurred yet.
59 * Applications using playbin should ideally be written to deal with things
60 * completely asynchroneous.
62 * When playback has finished (an EOS message has been received on the bus)
63 * or an error has occurred (an ERROR message has been received on the bus) or
64 * the user wants to play a different track, playbin should be set back to
65 * READY or NULL state, then the #GstPlayBin:uri property should be set to the
66 * new location and then playbin be set to PLAYING state again.
68 * Seeking can be done using gst_element_seek_simple() or gst_element_seek()
69 * on the playbin element. Again, the seek will not be executed
70 * instantaneously, but will be done in a background thread. When the seek
71 * call returns the seek will most likely still be in process. An application
72 * may wait for the seek to finish (or fail) using gst_element_get_state() with
73 * -1 as the timeout, but this will block the user interface and is not
76 * Applications may query the current position and duration of the stream
77 * via gst_element_query_position() and gst_element_query_duration() and
78 * setting the format passed to GST_FORMAT_TIME. If the query was successful,
79 * the duration or position will have been returned in units of nanoseconds.
81 * ## Advanced Usage: specifying the audio and video sink
83 * By default, if no audio sink or video sink has been specified via the
84 * #GstPlayBin:audio-sink or #GstPlayBin:video-sink property, playbin will use the autoaudiosink
85 * and autovideosink elements to find the first-best available output method.
86 * This should work in most cases, but is not always desirable. Often either
87 * the user or application might want to specify more explicitly what to use
88 * for audio and video output.
90 * If the application wants more control over how audio or video should be
91 * output, it may create the audio/video sink elements itself (for example
92 * using gst_element_factory_make()) and provide them to playbin using the
93 * #GstPlayBin:audio-sink or #GstPlayBin:video-sink property.
95 * GNOME-based applications, for example, will usually want to create
96 * gconfaudiosink and gconfvideosink elements and make playbin use those,
97 * so that output happens to whatever the user has configured in the GNOME
98 * Multimedia System Selector configuration dialog.
100 * The sink elements do not necessarily need to be ready-made sinks. It is
101 * possible to create container elements that look like a sink to playbin,
102 * but in reality contain a number of custom elements linked together. This
103 * can be achieved by creating a #GstBin and putting elements in there and
104 * linking them, and then creating a sink #GstGhostPad for the bin and pointing
105 * it to the sink pad of the first element within the bin. This can be used
106 * for a number of purposes, for example to force output to a particular
107 * format or to modify or observe the data before it is output.
109 * It is also possible to 'suppress' audio and/or video output by using
110 * 'fakesink' elements (or capture it from there using the fakesink element's
111 * "handoff" signal, which, nota bene, is fired from the streaming thread!).
113 * ## Retrieving Tags and Other Meta Data
115 * Most of the common meta data (artist, title, etc.) can be retrieved by
116 * watching for TAG messages on the pipeline's bus (see above).
118 * Other more specific meta information like width/height/framerate of video
119 * streams or samplerate/number of channels of audio streams can be obtained
120 * from the negotiated caps on the sink pads of the sinks.
123 * Playbin handles buffering automatically for the most part, but applications
124 * need to handle parts of the buffering process as well. Whenever playbin is
125 * buffering, it will post BUFFERING messages on the bus with a percentage
126 * value that shows the progress of the buffering process. Applications need
127 * to set playbin to PLAYING or PAUSED state in response to these messages.
128 * They may also want to convey the buffering progress to the user in some
129 * way. Here is how to extract the percentage information from the message:
131 * switch (GST_MESSAGE_TYPE (msg)) {
132 * case GST_MESSAGE_BUFFERING: {
134 * gst_message_parse_buffering (msg, &percent);
135 * g_print ("Buffering (%u percent done)", percent);
142 * Note that applications should keep/set the pipeline in the PAUSED state when
143 * a BUFFERING message is received with a buffer percent value < 100 and set
144 * the pipeline back to PLAYING state when a BUFFERING message with a value
145 * of 100 percent is received (if PLAYING is the desired state, that is).
147 * ## Embedding the video window in your application
148 * By default, playbin (or rather the video sinks used) will create their own
149 * window. Applications will usually want to force output to a window of their
150 * own, however. This can be done using the #GstVideoOverlay interface, which most
151 * video sinks implement. See the documentation there for more details.
153 * ## Specifying which CD/DVD device to use
154 * The device to use for CDs/DVDs needs to be set on the source element
155 * playbin creates before it is opened. The most generic way of doing this
156 * is to connect to playbin's "source-setup" (or "notify::source") signal,
157 * which will be emitted by playbin when it has created the source element
158 * for a particular URI. In the signal callback you can check if the source
159 * element has a "device" property and set it appropriately. In some cases
160 * the device can also be set as part of the URI, but it depends on the
161 * elements involved if this will work or not. For example, for DVD menu
162 * playback, the following syntax might work (if the resindvd plugin is used):
163 * dvd://[/path/to/device]
165 * ## Handling redirects
167 * Some elements may post 'redirect' messages on the bus to tell the
168 * application to open another location. These are element messages containing
169 * a structure named 'redirect' along with a 'new-location' field of string
170 * type. The new location may be a relative or an absolute URI. Examples
171 * for such redirects can be found in many quicktime movie trailers.
173 * NOTE: playbin will internally handle the redirect messages in the case
174 * that the redirecting stream doesn't contain any tracks and thus
175 * needs to report an error message on the bus.
179 * gst-launch-1.0 -v playbin uri=file:///path/to/somefile.mp4
181 * This will play back the given AVI video file, given that the video and
182 * audio decoders required to decode the content are installed. Since no
183 * special audio sink or video sink is supplied (via playbin's audio-sink or
184 * video-sink properties) playbin will try to find a suitable audio and
185 * video sink automatically using the autoaudiosink and autovideosink elements.
187 * gst-launch-1.0 -v playbin uri=cdda://4
189 * This will play back track 4 on an audio CD in your disc drive (assuming
190 * the drive is detected automatically by the plugin).
192 * gst-launch-1.0 -v playbin uri=dvd://
194 * This will play back the DVD in your disc drive (assuming
195 * the drive is detected automatically by the plugin).
199 /* FIXME 0.11: suppress warnings for deprecated API such as GValueArray
200 * with newer GLib versions (>= 2.31.0) */
201 #define GLIB_DISABLE_DEPRECATION_WARNINGS
210 #include <gst/gst-i18n-plugin.h>
211 #include <gst/pbutils/pbutils.h>
212 #include <gst/audio/streamvolume.h>
213 #include <gst/video/video-info.h>
214 #include <gst/video/video-multiview.h>
215 #include <gst/video/videooverlay.h>
216 #include <gst/video/navigation.h>
217 #include <gst/video/colorbalance.h>
218 #include "gstplay-enum.h"
219 #include "gstplayback.h"
220 #include "gstplaysink.h"
221 #include "gstsubtitleoverlay.h"
222 #include "gstplaybackutils.h"
224 GST_DEBUG_CATEGORY_STATIC (gst_play_bin_debug);
225 #define GST_CAT_DEFAULT gst_play_bin_debug
227 #define GST_TYPE_PLAY_BIN (gst_play_bin_get_type())
228 #define GST_PLAY_BIN(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PLAY_BIN,GstPlayBin))
229 #define GST_PLAY_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PLAY_BIN,GstPlayBinClass))
230 #define GST_IS_PLAY_BIN(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PLAY_BIN))
231 #define GST_IS_PLAY_BIN_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PLAY_BIN))
233 #define ULONG_TO_POINTER(number) ((gpointer) (guintptr) (number))
234 #define POINTER_TO_ULONG(number) ((guintptr) (number))
236 #define VOLUME_MAX_DOUBLE 10.0
238 typedef struct _GstPlayBin GstPlayBin;
239 typedef struct _GstPlayBinClass GstPlayBinClass;
240 typedef struct _GstSourceGroup GstSourceGroup;
241 typedef struct _GstSourceCombine GstSourceCombine;
243 typedef GstCaps *(*SourceCombineGetMediaCapsFunc) (void);
245 /* has the info for a combiner and provides the link to the sink */
246 struct _GstSourceCombine
248 const gchar *media_list[8]; /* the media types for the combiner */
249 SourceCombineGetMediaCapsFunc get_media_caps; /* more complex caps for the combiner */
250 GstPlaySinkType type; /* the sink pad type of the combiner */
252 GstElement *combiner; /* the combiner */
254 GstPad *srcpad; /* the source pad of the combiner */
255 GstPad *sinkpad; /* the sinkpad of the sink when the combiner
260 gboolean has_active_pad; /* stream combiner has the "active-pad" property */
262 gboolean has_always_ok; /* stream combiner's sink pads have the "always-ok" property */
263 gboolean has_tags; /* stream combiner's sink pads have the "tags" property */
266 #define GST_SOURCE_GROUP_GET_LOCK(group) (&((GstSourceGroup*)(group))->lock)
267 #define GST_SOURCE_GROUP_LOCK(group) (g_mutex_lock (GST_SOURCE_GROUP_GET_LOCK(group)))
268 #define GST_SOURCE_GROUP_UNLOCK(group) (g_mutex_unlock (GST_SOURCE_GROUP_GET_LOCK(group)))
272 PLAYBIN_STREAM_AUDIO = 0,
273 PLAYBIN_STREAM_VIDEO,
278 static void avelements_free (gpointer data);
279 static GSequence *avelements_create (GstPlayBin * playbin,
280 gboolean isaudioelement);
282 /* The GstAudioVideoElement structure holding the audio/video decoder
283 * and the audio/video sink factories together with field indicating
284 * the number of common caps features */
287 GstElementFactory *dec; /* audio:video decoder */
288 GstElementFactory *sink; /* audio:video sink */
289 guint n_comm_cf; /* number of common caps features */
292 /* a structure to hold the objects for decoding a uri and the subtitle uri
294 struct _GstSourceGroup
300 gboolean valid; /* the group has valid info to start playback */
301 gboolean active; /* the group is active */
306 GValueArray *streaminfo;
309 GPtrArray *video_channels; /* links to combiner pads */
310 GPtrArray *audio_channels; /* links to combiner pads */
311 GPtrArray *text_channels; /* links to combiner pads */
313 /* Sinks for this group. These are initialized with
314 * the configure or currently used sink, otherwise
315 * left as NULL and playbin tries to automatically
318 GstElement *audio_sink;
319 GstElement *video_sink;
320 GstElement *text_sink;
322 /* uridecodebins for uri and subtitle uri */
323 GstElement *uridecodebin;
324 GstElement *suburidecodebin;
326 gboolean sub_pending;
328 gboolean have_group_id;
332 gulong pad_removed_id;
333 gulong no_more_pads_id;
334 gulong notify_source_id;
336 gulong autoplug_factories_id;
337 gulong autoplug_select_id;
338 gulong autoplug_continue_id;
339 gulong autoplug_query_id;
341 gulong sub_pad_added_id;
342 gulong sub_pad_removed_id;
343 gulong sub_no_more_pads_id;
344 gulong sub_autoplug_continue_id;
345 gulong sub_autoplug_query_id;
349 GMutex stream_changed_pending_lock;
350 gboolean stream_changed_pending;
352 /* to prevent that suburidecodebin seek flushes disrupt playback */
353 GMutex suburi_flushes_to_drop_lock;
354 GSList *suburi_flushes_to_drop;
356 /* buffering message stored for after switching */
357 GstMessage *pending_buffering_msg;
359 /* combiners for different streams */
360 GstSourceCombine combiner[PLAYBIN_STREAM_LAST];
363 #define GST_PLAY_BIN_GET_LOCK(bin) (&((GstPlayBin*)(bin))->lock)
364 #define GST_PLAY_BIN_LOCK(bin) (g_rec_mutex_lock (GST_PLAY_BIN_GET_LOCK(bin)))
365 #define GST_PLAY_BIN_UNLOCK(bin) (g_rec_mutex_unlock (GST_PLAY_BIN_GET_LOCK(bin)))
367 /* lock to protect dynamic callbacks, like no-more-pads */
368 #define GST_PLAY_BIN_DYN_LOCK(bin) g_mutex_lock (&(bin)->dyn_lock)
369 #define GST_PLAY_BIN_DYN_UNLOCK(bin) g_mutex_unlock (&(bin)->dyn_lock)
371 /* lock for shutdown */
372 #define GST_PLAY_BIN_SHUTDOWN_LOCK(bin,label) \
374 if (G_UNLIKELY (g_atomic_int_get (&bin->shutdown))) \
376 GST_PLAY_BIN_DYN_LOCK (bin); \
377 if (G_UNLIKELY (g_atomic_int_get (&bin->shutdown))) { \
378 GST_PLAY_BIN_DYN_UNLOCK (bin); \
383 /* unlock for shutdown */
384 #define GST_PLAY_BIN_SHUTDOWN_UNLOCK(bin) \
385 GST_PLAY_BIN_DYN_UNLOCK (bin); \
390 * playbin element structure
396 GRecMutex lock; /* to protect group switching */
398 /* the groups, we use a double buffer to switch between current and next */
399 GstSourceGroup groups[2]; /* array with group info */
400 GstSourceGroup *curr_group; /* pointer to the currently playing group */
401 GstSourceGroup *next_group; /* pointer to the next group */
404 guint64 connection_speed; /* connection speed in bits/sec (0 = unknown) */
405 gint current_video; /* the currently selected stream */
406 gint current_audio; /* the currently selected stream */
407 gint current_text; /* the currently selected stream */
409 guint64 buffer_duration; /* When buffering, the max buffer duration (ns) */
410 guint buffer_size; /* When buffering, the max buffer size (bytes) */
411 gboolean force_aspect_ratio;
413 /* Multiview/stereoscopic overrides */
414 GstVideoMultiviewFramePacking multiview_mode;
415 GstVideoMultiviewFlags multiview_flags;
418 GstPlaySink *playsink;
420 /* the last activated source */
423 /* lock protecting dynamic adding/removing */
425 /* if we are shutting down or not */
427 gboolean async_pending; /* async-start has been emitted */
429 GMutex elements_lock;
430 guint32 elements_cookie;
431 GList *elements; /* factories we can use for selecting elements */
433 gboolean have_selector; /* set to FALSE when we fail to create an
434 * input-selector, so that we only post a
437 gboolean video_pending_flush_finish; /* whether we are pending to send a custom
438 * custom-video-flush-finish event
439 * on pad activation */
440 gboolean audio_pending_flush_finish; /* whether we are pending to send a custom
441 * custom-audio-flush-finish event
442 * on pad activation */
443 gboolean text_pending_flush_finish; /* whether we are pending to send a custom
444 * custom-subtitle-flush-finish event
445 * on pad activation */
447 GstElement *audio_sink; /* configured audio sink, or NULL */
448 GstElement *video_sink; /* configured video sink, or NULL */
449 GstElement *text_sink; /* configured text sink, or NULL */
451 GstElement *audio_stream_combiner; /* configured audio stream combiner, or NULL */
452 GstElement *video_stream_combiner; /* configured video stream combiner, or NULL */
453 GstElement *text_stream_combiner; /* configured text stream combiner, or NULL */
455 GSequence *aelements; /* a list of GstAVElements for audio stream */
456 GSequence *velements; /* a list of GstAVElements for video stream */
463 } duration[5]; /* cached durations */
465 guint64 ring_buffer_max_size; /* 0 means disabled */
470 struct _GstPlayBinClass
472 GstPipelineClass parent_class;
474 /* notify app that the current uri finished decoding and it is possible to
475 * queue a new one for gapless playback */
476 void (*about_to_finish) (GstPlayBin * playbin);
478 /* notify app that number of audio/video/text streams changed */
479 void (*video_changed) (GstPlayBin * playbin);
480 void (*audio_changed) (GstPlayBin * playbin);
481 void (*text_changed) (GstPlayBin * playbin);
483 /* notify app that the tags of audio/video/text streams changed */
484 void (*video_tags_changed) (GstPlayBin * playbin, gint stream);
485 void (*audio_tags_changed) (GstPlayBin * playbin, gint stream);
486 void (*text_tags_changed) (GstPlayBin * playbin, gint stream);
488 /* get audio/video/text tags for a stream */
489 GstTagList *(*get_video_tags) (GstPlayBin * playbin, gint stream);
490 GstTagList *(*get_audio_tags) (GstPlayBin * playbin, gint stream);
491 GstTagList *(*get_text_tags) (GstPlayBin * playbin, gint stream);
493 /* get the last video sample and convert it to the given caps */
494 GstSample *(*convert_sample) (GstPlayBin * playbin, GstCaps * caps);
496 /* get audio/video/text pad for a stream */
497 GstPad *(*get_video_pad) (GstPlayBin * playbin, gint stream);
498 GstPad *(*get_audio_pad) (GstPlayBin * playbin, gint stream);
499 GstPad *(*get_text_pad) (GstPlayBin * playbin, gint stream);
503 #define DEFAULT_URI NULL
504 #define DEFAULT_SUBURI NULL
505 #define DEFAULT_SOURCE NULL
506 #define DEFAULT_FLAGS GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_TEXT | \
507 GST_PLAY_FLAG_SOFT_VOLUME | GST_PLAY_FLAG_DEINTERLACE | \
508 GST_PLAY_FLAG_SOFT_COLORBALANCE
509 #define DEFAULT_N_VIDEO 0
510 #define DEFAULT_CURRENT_VIDEO -1
511 #define DEFAULT_N_AUDIO 0
512 #define DEFAULT_CURRENT_AUDIO -1
513 #define DEFAULT_N_TEXT 0
514 #define DEFAULT_CURRENT_TEXT -1
515 #define DEFAULT_SUBTITLE_ENCODING NULL
516 #define DEFAULT_AUDIO_SINK NULL
517 #define DEFAULT_VIDEO_SINK NULL
518 #define DEFAULT_VIS_PLUGIN NULL
519 #define DEFAULT_TEXT_SINK NULL
520 #define DEFAULT_VOLUME 1.0
521 #define DEFAULT_MUTE FALSE
522 #define DEFAULT_FRAME NULL
523 #define DEFAULT_FONT_DESC NULL
524 #define DEFAULT_CONNECTION_SPEED 0
525 #define DEFAULT_BUFFER_DURATION -1
526 #define DEFAULT_BUFFER_SIZE -1
527 #define DEFAULT_RING_BUFFER_MAX_SIZE 0
544 PROP_SUBTITLE_ENCODING,
549 PROP_VIDEO_STREAM_COMBINER,
550 PROP_AUDIO_STREAM_COMBINER,
551 PROP_TEXT_STREAM_COMBINER,
556 PROP_CONNECTION_SPEED,
558 PROP_BUFFER_DURATION,
561 PROP_RING_BUFFER_MAX_SIZE,
562 PROP_FORCE_ASPECT_RATIO,
572 SIGNAL_ABOUT_TO_FINISH,
573 SIGNAL_CONVERT_SAMPLE,
574 SIGNAL_VIDEO_CHANGED,
575 SIGNAL_AUDIO_CHANGED,
577 SIGNAL_VIDEO_TAGS_CHANGED,
578 SIGNAL_AUDIO_TAGS_CHANGED,
579 SIGNAL_TEXT_TAGS_CHANGED,
580 SIGNAL_GET_VIDEO_TAGS,
581 SIGNAL_GET_AUDIO_TAGS,
582 SIGNAL_GET_TEXT_TAGS,
583 SIGNAL_GET_VIDEO_PAD,
584 SIGNAL_GET_AUDIO_PAD,
587 SIGNAL_ELEMENT_SETUP,
591 static GstStaticCaps raw_audio_caps = GST_STATIC_CAPS ("audio/x-raw(ANY)");
592 static GstStaticCaps raw_video_caps = GST_STATIC_CAPS ("video/x-raw(ANY)");
594 static void gst_play_bin_class_init (GstPlayBinClass * klass);
595 static void gst_play_bin_init (GstPlayBin * playbin);
596 static void gst_play_bin_finalize (GObject * object);
598 static void gst_play_bin_set_property (GObject * object, guint prop_id,
599 const GValue * value, GParamSpec * spec);
600 static void gst_play_bin_get_property (GObject * object, guint prop_id,
601 GValue * value, GParamSpec * spec);
603 static GstStateChangeReturn gst_play_bin_change_state (GstElement * element,
604 GstStateChange transition);
606 static void gst_play_bin_handle_message (GstBin * bin, GstMessage * message);
607 static void gst_play_bin_deep_element_added (GstBin * playbin, GstBin * sub_bin,
609 static gboolean gst_play_bin_query (GstElement * element, GstQuery * query);
610 static void gst_play_bin_set_context (GstElement * element,
611 GstContext * context);
612 static gboolean gst_play_bin_send_event (GstElement * element,
615 static GstTagList *gst_play_bin_get_video_tags (GstPlayBin * playbin,
617 static GstTagList *gst_play_bin_get_audio_tags (GstPlayBin * playbin,
619 static GstTagList *gst_play_bin_get_text_tags (GstPlayBin * playbin,
622 static GstSample *gst_play_bin_convert_sample (GstPlayBin * playbin,
625 static GstPad *gst_play_bin_get_video_pad (GstPlayBin * playbin, gint stream);
626 static GstPad *gst_play_bin_get_audio_pad (GstPlayBin * playbin, gint stream);
627 static GstPad *gst_play_bin_get_text_pad (GstPlayBin * playbin, gint stream);
629 static GstStateChangeReturn setup_next_source (GstPlayBin * playbin,
632 static void no_more_pads_cb (GstElement * decodebin, GstSourceGroup * group);
633 static void pad_removed_cb (GstElement * decodebin, GstPad * pad,
634 GstSourceGroup * group);
636 static void gst_play_bin_suburidecodebin_block (GstSourceGroup * group,
637 GstElement * suburidecodebin, gboolean block);
638 static void gst_play_bin_suburidecodebin_seek_to_start (GstSourceGroup * group);
640 gst_play_bin_update_context (GstPlayBin * playbin, GstContext * context);
642 static GstElementClass *parent_class;
644 static guint gst_play_bin_signals[LAST_SIGNAL] = { 0 };
646 #define REMOVE_SIGNAL(obj,id) \
648 g_signal_handler_disconnect (obj, id); \
652 static void gst_play_bin_overlay_init (gpointer g_iface, gpointer g_iface_data);
653 static void gst_play_bin_navigation_init (gpointer g_iface,
654 gpointer g_iface_data);
655 static void gst_play_bin_colorbalance_init (gpointer g_iface,
656 gpointer g_iface_data);
659 gst_play_bin_get_type (void)
661 static GType gst_play_bin_type = 0;
663 if (!gst_play_bin_type) {
664 static const GTypeInfo gst_play_bin_info = {
665 sizeof (GstPlayBinClass),
668 (GClassInitFunc) gst_play_bin_class_init,
673 (GInstanceInitFunc) gst_play_bin_init,
676 static const GInterfaceInfo svol_info = {
679 static const GInterfaceInfo ov_info = {
680 gst_play_bin_overlay_init,
683 static const GInterfaceInfo nav_info = {
684 gst_play_bin_navigation_init,
687 static const GInterfaceInfo col_info = {
688 gst_play_bin_colorbalance_init,
692 gst_play_bin_type = g_type_register_static (GST_TYPE_PIPELINE,
693 "GstPlayBin", &gst_play_bin_info, 0);
695 g_type_add_interface_static (gst_play_bin_type, GST_TYPE_STREAM_VOLUME,
697 g_type_add_interface_static (gst_play_bin_type, GST_TYPE_VIDEO_OVERLAY,
699 g_type_add_interface_static (gst_play_bin_type, GST_TYPE_NAVIGATION,
701 g_type_add_interface_static (gst_play_bin_type, GST_TYPE_COLOR_BALANCE,
705 return gst_play_bin_type;
709 gst_play_bin_class_init (GstPlayBinClass * klass)
711 GObjectClass *gobject_klass;
712 GstElementClass *gstelement_klass;
713 GstBinClass *gstbin_klass;
715 gobject_klass = (GObjectClass *) klass;
716 gstelement_klass = (GstElementClass *) klass;
717 gstbin_klass = (GstBinClass *) klass;
719 parent_class = g_type_class_peek_parent (klass);
721 gobject_klass->set_property = gst_play_bin_set_property;
722 gobject_klass->get_property = gst_play_bin_get_property;
724 gobject_klass->finalize = gst_play_bin_finalize;
729 * Set the next URI that playbin will play. This property can be set from the
730 * about-to-finish signal to queue the next media file.
732 g_object_class_install_property (gobject_klass, PROP_URI,
733 g_param_spec_string ("uri", "URI", "URI of the media to play",
734 NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
737 * GstPlayBin:current-uri
739 * The currently playing uri.
741 g_object_class_install_property (gobject_klass, PROP_CURRENT_URI,
742 g_param_spec_string ("current-uri", "Current URI",
743 "The currently playing URI", NULL,
744 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
749 * Set the next subtitle URI that playbin will play. This property can be
750 * set from the about-to-finish signal to queue the next subtitle media file.
752 g_object_class_install_property (gobject_klass, PROP_SUBURI,
753 g_param_spec_string ("suburi", ".sub-URI", "Optional URI of a subtitle",
754 NULL, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
757 * GstPlayBin:current-suburi
759 * The currently playing subtitle uri.
761 g_object_class_install_property (gobject_klass, PROP_CURRENT_SUBURI,
762 g_param_spec_string ("current-suburi", "Current .sub-URI",
763 "The currently playing URI of a subtitle",
764 NULL, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
766 g_object_class_install_property (gobject_klass, PROP_SOURCE,
767 g_param_spec_object ("source", "Source", "Source element",
768 GST_TYPE_ELEMENT, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
773 * Control the behaviour of playbin.
775 g_object_class_install_property (gobject_klass, PROP_FLAGS,
776 g_param_spec_flags ("flags", "Flags", "Flags to control behaviour",
777 GST_TYPE_PLAY_FLAGS, DEFAULT_FLAGS,
778 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
783 * Get the total number of available video streams.
785 g_object_class_install_property (gobject_klass, PROP_N_VIDEO,
786 g_param_spec_int ("n-video", "Number Video",
787 "Total number of video streams", 0, G_MAXINT, 0,
788 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
790 * GstPlayBin:current-video
792 * Get or set the currently playing video stream. By default the first video
793 * stream with data is played.
795 g_object_class_install_property (gobject_klass, PROP_CURRENT_VIDEO,
796 g_param_spec_int ("current-video", "Current Video",
797 "Currently playing video stream (-1 = auto)",
798 -1, G_MAXINT, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
802 * Get the total number of available audio streams.
804 g_object_class_install_property (gobject_klass, PROP_N_AUDIO,
805 g_param_spec_int ("n-audio", "Number Audio",
806 "Total number of audio streams", 0, G_MAXINT, 0,
807 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
809 * GstPlayBin:current-audio
811 * Get or set the currently playing audio stream. By default the first audio
812 * stream with data is played.
814 g_object_class_install_property (gobject_klass, PROP_CURRENT_AUDIO,
815 g_param_spec_int ("current-audio", "Current audio",
816 "Currently playing audio stream (-1 = auto)",
817 -1, G_MAXINT, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
821 * Get the total number of available subtitle streams.
823 g_object_class_install_property (gobject_klass, PROP_N_TEXT,
824 g_param_spec_int ("n-text", "Number Text",
825 "Total number of text streams", 0, G_MAXINT, 0,
826 G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
828 * GstPlayBin:current-text:
830 * Get or set the currently playing subtitle stream. By default the first
831 * subtitle stream with data is played.
833 g_object_class_install_property (gobject_klass, PROP_CURRENT_TEXT,
834 g_param_spec_int ("current-text", "Current Text",
835 "Currently playing text stream (-1 = auto)",
836 -1, G_MAXINT, -1, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
838 g_object_class_install_property (gobject_klass, PROP_SUBTITLE_ENCODING,
839 g_param_spec_string ("subtitle-encoding", "subtitle encoding",
840 "Encoding to assume if input subtitles are not in UTF-8 encoding. "
841 "If not set, the GST_SUBTITLE_ENCODING environment variable will "
842 "be checked for an encoding to use. If that is not set either, "
843 "ISO-8859-15 will be assumed.", NULL,
844 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
846 g_object_class_install_property (gobject_klass, PROP_VIDEO_FILTER,
847 g_param_spec_object ("video-filter", "Video filter",
848 "the video filter(s) to apply, if possible",
849 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
850 g_object_class_install_property (gobject_klass, PROP_AUDIO_FILTER,
851 g_param_spec_object ("audio-filter", "Audio filter",
852 "the audio filter(s) to apply, if possible",
853 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
854 g_object_class_install_property (gobject_klass, PROP_VIDEO_SINK,
855 g_param_spec_object ("video-sink", "Video Sink",
856 "the video output element to use (NULL = default sink)",
857 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
858 g_object_class_install_property (gobject_klass, PROP_AUDIO_SINK,
859 g_param_spec_object ("audio-sink", "Audio Sink",
860 "the audio output element to use (NULL = default sink)",
861 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
862 g_object_class_install_property (gobject_klass, PROP_VIS_PLUGIN,
863 g_param_spec_object ("vis-plugin", "Vis plugin",
864 "the visualization element to use (NULL = default)",
865 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
866 g_object_class_install_property (gobject_klass, PROP_TEXT_SINK,
867 g_param_spec_object ("text-sink", "Text plugin",
868 "the text output element to use (NULL = default subtitleoverlay)",
869 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
871 * GstPlayBin:video-stream-combiner
873 * Get or set the current video stream combiner. By default, an input-selector
874 * is created and deleted as-needed.
876 g_object_class_install_property (gobject_klass, PROP_VIDEO_STREAM_COMBINER,
877 g_param_spec_object ("video-stream-combiner", "Video stream combiner",
878 "Current video stream combiner (NULL = input-selector)",
879 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
881 * GstPlayBin:audio-stream-combiner
883 * Get or set the current audio stream combiner. By default, an input-selector
884 * is created and deleted as-needed.
886 g_object_class_install_property (gobject_klass, PROP_AUDIO_STREAM_COMBINER,
887 g_param_spec_object ("audio-stream-combiner", "Audio stream combiner",
888 "Current audio stream combiner (NULL = input-selector)",
889 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
891 * GstPlayBin:text-stream-combiner
893 * Get or set the current text stream combiner. By default, an input-selector
894 * is created and deleted as-needed.
896 g_object_class_install_property (gobject_klass, PROP_TEXT_STREAM_COMBINER,
897 g_param_spec_object ("text-stream-combiner", "Text stream combiner",
898 "Current text stream combiner (NULL = input-selector)",
899 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
904 * Get or set the current audio stream volume. 1.0 means 100%,
905 * 0.0 means mute. This uses a linear volume scale.
908 g_object_class_install_property (gobject_klass, PROP_VOLUME,
909 g_param_spec_double ("volume", "Volume", "The audio volume, 1.0=100%",
910 0.0, VOLUME_MAX_DOUBLE, 1.0,
911 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
912 g_object_class_install_property (gobject_klass, PROP_MUTE,
913 g_param_spec_boolean ("mute", "Mute",
914 "Mute the audio channel without changing the volume", FALSE,
915 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
919 * @playbin: a #GstPlayBin
921 * Get the currently rendered or prerolled sample in the video sink.
922 * The #GstCaps in the sample will describe the format of the buffer.
924 g_object_class_install_property (gobject_klass, PROP_SAMPLE,
925 g_param_spec_boxed ("sample", "Sample",
926 "The last sample (NULL = no video available)",
927 GST_TYPE_SAMPLE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
929 g_object_class_install_property (gobject_klass, PROP_FONT_DESC,
930 g_param_spec_string ("subtitle-font-desc",
931 "Subtitle font description",
932 "Pango font description of font "
933 "to be used for subtitle rendering", NULL,
934 G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
936 g_object_class_install_property (gobject_klass, PROP_CONNECTION_SPEED,
937 g_param_spec_uint64 ("connection-speed", "Connection Speed",
938 "Network connection speed in kbps (0 = unknown)",
939 0, G_MAXUINT64 / 1000, DEFAULT_CONNECTION_SPEED,
940 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
942 g_object_class_install_property (gobject_klass, PROP_BUFFER_SIZE,
943 g_param_spec_int ("buffer-size", "Buffer size (bytes)",
944 "Buffer size when buffering network streams",
945 -1, G_MAXINT, DEFAULT_BUFFER_SIZE,
946 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
947 g_object_class_install_property (gobject_klass, PROP_BUFFER_DURATION,
948 g_param_spec_int64 ("buffer-duration", "Buffer duration (ns)",
949 "Buffer duration when buffering network streams",
950 -1, G_MAXINT64, DEFAULT_BUFFER_DURATION,
951 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
953 * GstPlayBin:av-offset:
955 * Control the synchronisation offset between the audio and video streams.
956 * Positive values make the audio ahead of the video and negative values make
957 * the audio go behind the video.
959 g_object_class_install_property (gobject_klass, PROP_AV_OFFSET,
960 g_param_spec_int64 ("av-offset", "AV Offset",
961 "The synchronisation offset between audio and video in nanoseconds",
962 G_MININT64, G_MAXINT64, 0,
963 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
966 * GstPlayBin:text-offset:
968 * Control the synchronisation offset between the text and video streams.
969 * Positive values make the text ahead of the video and negative values make
970 * the text go behind the video.
972 g_object_class_install_property (gobject_klass, PROP_TEXT_OFFSET,
973 g_param_spec_int64 ("text-offset", "Text Offset",
974 "The synchronisation offset between text and video in nanoseconds",
975 G_MININT64, G_MAXINT64, 0,
976 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
979 * GstPlayBin:ring-buffer-max-size:
981 * The maximum size of the ring buffer in bytes. If set to 0, the ring
982 * buffer is disabled. Default 0.
984 g_object_class_install_property (gobject_klass, PROP_RING_BUFFER_MAX_SIZE,
985 g_param_spec_uint64 ("ring-buffer-max-size",
986 "Max. ring buffer size (bytes)",
987 "Max. amount of data in the ring buffer (bytes, 0 = ring buffer disabled)",
988 0, G_MAXUINT, DEFAULT_RING_BUFFER_MAX_SIZE,
989 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
992 * GstPlayBin::force-aspect-ratio:
994 * Requests the video sink to enforce the video display aspect ratio.
996 g_object_class_install_property (gobject_klass, PROP_FORCE_ASPECT_RATIO,
997 g_param_spec_boolean ("force-aspect-ratio", "Force Aspect Ratio",
998 "When enabled, scaling will respect original aspect ratio", TRUE,
999 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1002 * GstPlayBin::video-multiview-mode:
1004 * Set the stereoscopic mode for video streams that don't contain
1005 * any information in the stream, so they can be correctly played
1006 * as 3D streams. If a video already has multiview information
1007 * encoded, this property can override other modes in the set,
1008 * but cannot be used to re-interpret MVC or mixed-mono streams.
1010 * See Also: The #GstPlayBin::video-multiview-flags property
1013 g_object_class_install_property (gobject_klass, PROP_MULTIVIEW_MODE,
1014 g_param_spec_enum ("video-multiview-mode",
1015 "Multiview Mode Override",
1016 "Re-interpret a video stream as one of several frame-packed stereoscopic modes.",
1017 GST_TYPE_VIDEO_MULTIVIEW_FRAME_PACKING,
1018 GST_VIDEO_MULTIVIEW_FRAME_PACKING_NONE,
1019 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1022 * GstPlayBin::video-multiview-flags:
1024 * When overriding the multiview mode of an input stream,
1025 * these flags modify details of the view layout.
1027 * See Also: The #GstPlayBin::video-multiview-mode property
1029 g_object_class_install_property (gobject_klass, PROP_MULTIVIEW_FLAGS,
1030 g_param_spec_flags ("video-multiview-flags",
1031 "Multiview Flags Override",
1032 "Override details of the multiview frame layout",
1033 GST_TYPE_VIDEO_MULTIVIEW_FLAGS, GST_VIDEO_MULTIVIEW_FLAGS_NONE,
1034 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
1037 * GstPlayBin::about-to-finish
1038 * @playbin: a #GstPlayBin
1040 * This signal is emitted when the current uri is about to finish. You can
1041 * set the uri and suburi to make sure that playback continues.
1043 * This signal is emitted from the context of a GStreamer streaming thread.
1045 gst_play_bin_signals[SIGNAL_ABOUT_TO_FINISH] =
1046 g_signal_new ("about-to-finish", G_TYPE_FROM_CLASS (klass),
1048 G_STRUCT_OFFSET (GstPlayBinClass, about_to_finish), NULL, NULL, NULL,
1049 G_TYPE_NONE, 0, G_TYPE_NONE);
1052 * GstPlayBin::video-changed:
1053 * @playbin: a #GstPlayBin
1055 * This signal is emitted whenever the number or order of the video
1056 * streams has changed. The application will most likely want to select
1057 * a new video stream.
1059 * This signal is usually emitted from the context of a GStreamer streaming
1060 * thread. You can use gst_message_new_application() and
1061 * gst_element_post_message() to notify your application's main thread.
1063 /* FIXME 0.11: turn video-changed signal into message? */
1064 gst_play_bin_signals[SIGNAL_VIDEO_CHANGED] =
1065 g_signal_new ("video-changed", G_TYPE_FROM_CLASS (klass),
1067 G_STRUCT_OFFSET (GstPlayBinClass, video_changed), NULL, NULL, NULL,
1068 G_TYPE_NONE, 0, G_TYPE_NONE);
1070 * GstPlayBin::audio-changed
1071 * @playbin: a #GstPlayBin
1073 * This signal is emitted whenever the number or order of the audio
1074 * streams has changed. The application will most likely want to select
1075 * a new audio stream.
1077 * This signal may be emitted from the context of a GStreamer streaming thread.
1078 * You can use gst_message_new_application() and gst_element_post_message()
1079 * to notify your application's main thread.
1081 /* FIXME 0.11: turn audio-changed signal into message? */
1082 gst_play_bin_signals[SIGNAL_AUDIO_CHANGED] =
1083 g_signal_new ("audio-changed", G_TYPE_FROM_CLASS (klass),
1085 G_STRUCT_OFFSET (GstPlayBinClass, audio_changed), NULL, NULL, NULL,
1086 G_TYPE_NONE, 0, G_TYPE_NONE);
1088 * GstPlayBin::text-changed:
1089 * @playbin: a #GstPlayBin
1091 * This signal is emitted whenever the number or order of the text
1092 * streams has changed. The application will most likely want to select
1093 * a new text stream.
1095 * This signal may be emitted from the context of a GStreamer streaming thread.
1096 * You can use gst_message_new_application() and gst_element_post_message()
1097 * to notify your application's main thread.
1099 /* FIXME 0.11: turn text-changed signal into message? */
1100 gst_play_bin_signals[SIGNAL_TEXT_CHANGED] =
1101 g_signal_new ("text-changed", G_TYPE_FROM_CLASS (klass),
1103 G_STRUCT_OFFSET (GstPlayBinClass, text_changed), NULL, NULL, NULL,
1104 G_TYPE_NONE, 0, G_TYPE_NONE);
1107 * GstPlayBin::video-tags-changed:
1108 * @playbin: a #GstPlayBin
1109 * @stream: stream index with changed tags
1111 * This signal is emitted whenever the tags of a video stream have changed.
1112 * The application will most likely want to get the new tags.
1114 * This signal may be emitted from the context of a GStreamer streaming thread.
1115 * You can use gst_message_new_application() and gst_element_post_message()
1116 * to notify your application's main thread.
1118 gst_play_bin_signals[SIGNAL_VIDEO_TAGS_CHANGED] =
1119 g_signal_new ("video-tags-changed", G_TYPE_FROM_CLASS (klass),
1121 G_STRUCT_OFFSET (GstPlayBinClass, video_tags_changed), NULL, NULL, NULL,
1122 G_TYPE_NONE, 1, G_TYPE_INT);
1125 * GstPlayBin::audio-tags-changed:
1126 * @playbin: a #GstPlayBin
1127 * @stream: stream index with changed tags
1129 * This signal is emitted whenever the tags of an audio stream have changed.
1130 * The application will most likely want to get the new tags.
1132 * This signal may be emitted from the context of a GStreamer streaming thread.
1133 * You can use gst_message_new_application() and gst_element_post_message()
1134 * to notify your application's main thread.
1136 gst_play_bin_signals[SIGNAL_AUDIO_TAGS_CHANGED] =
1137 g_signal_new ("audio-tags-changed", G_TYPE_FROM_CLASS (klass),
1139 G_STRUCT_OFFSET (GstPlayBinClass, audio_tags_changed), NULL, NULL, NULL,
1140 G_TYPE_NONE, 1, G_TYPE_INT);
1143 * GstPlayBin::text-tags-changed:
1144 * @playbin: a #GstPlayBin
1145 * @stream: stream index with changed tags
1147 * This signal is emitted whenever the tags of a text stream have changed.
1148 * The application will most likely want to get the new tags.
1150 * This signal may be emitted from the context of a GStreamer streaming thread.
1151 * You can use gst_message_new_application() and gst_element_post_message()
1152 * to notify your application's main thread.
1154 gst_play_bin_signals[SIGNAL_TEXT_TAGS_CHANGED] =
1155 g_signal_new ("text-tags-changed", G_TYPE_FROM_CLASS (klass),
1157 G_STRUCT_OFFSET (GstPlayBinClass, text_tags_changed), NULL, NULL, NULL,
1158 G_TYPE_NONE, 1, G_TYPE_INT);
1161 * GstPlayBin::source-setup:
1162 * @playbin: a #GstPlayBin
1163 * @source: source element
1165 * This signal is emitted after the source element has been created, so
1166 * it can be configured by setting additional properties (e.g. set a
1167 * proxy server for an http source, or set the device and read speed for
1168 * an audio cd source). This is functionally equivalent to connecting to
1169 * the notify::source signal, but more convenient.
1171 * This signal is usually emitted from the context of a GStreamer streaming
1174 gst_play_bin_signals[SIGNAL_SOURCE_SETUP] =
1175 g_signal_new ("source-setup", G_TYPE_FROM_CLASS (klass),
1176 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
1179 * GstPlayBin::element-setup:
1180 * @playbin: a #GstPlayBin
1181 * @element: an element that was added to the playbin hierarchy
1183 * This signal is emitted when a new element is added to playbin or any of
1184 * its sub-bins. This signal can be used to configure elements, e.g. to set
1185 * properties on decoders. This is functionally equivalent to connecting to
1186 * the deep-element-added signal, but more convenient.
1188 * This signal is usually emitted from the context of a GStreamer streaming
1189 * thread, so might be called at the same time as code running in the main
1190 * application thread.
1194 gst_play_bin_signals[SIGNAL_ELEMENT_SETUP] =
1195 g_signal_new ("element-setup", G_TYPE_FROM_CLASS (klass),
1196 G_SIGNAL_RUN_LAST, 0, NULL, NULL, NULL, G_TYPE_NONE, 1, GST_TYPE_ELEMENT);
1199 * GstPlayBin::get-video-tags:
1200 * @playbin: a #GstPlayBin
1201 * @stream: a video stream number
1203 * Action signal to retrieve the tags of a specific video stream number.
1204 * This information can be used to select a stream.
1206 * Returns: a GstTagList with tags or NULL when the stream number does not
1209 gst_play_bin_signals[SIGNAL_GET_VIDEO_TAGS] =
1210 g_signal_new ("get-video-tags", G_TYPE_FROM_CLASS (klass),
1211 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1212 G_STRUCT_OFFSET (GstPlayBinClass, get_video_tags), NULL, NULL, NULL,
1213 GST_TYPE_TAG_LIST, 1, G_TYPE_INT);
1215 * GstPlayBin::get-audio-tags:
1216 * @playbin: a #GstPlayBin
1217 * @stream: an audio stream number
1219 * Action signal to retrieve the tags of a specific audio stream number.
1220 * This information can be used to select a stream.
1222 * Returns: a GstTagList with tags or NULL when the stream number does not
1225 gst_play_bin_signals[SIGNAL_GET_AUDIO_TAGS] =
1226 g_signal_new ("get-audio-tags", G_TYPE_FROM_CLASS (klass),
1227 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1228 G_STRUCT_OFFSET (GstPlayBinClass, get_audio_tags), NULL, NULL, NULL,
1229 GST_TYPE_TAG_LIST, 1, G_TYPE_INT);
1231 * GstPlayBin::get-text-tags:
1232 * @playbin: a #GstPlayBin
1233 * @stream: a text stream number
1235 * Action signal to retrieve the tags of a specific text stream number.
1236 * This information can be used to select a stream.
1238 * Returns: a GstTagList with tags or NULL when the stream number does not
1241 gst_play_bin_signals[SIGNAL_GET_TEXT_TAGS] =
1242 g_signal_new ("get-text-tags", G_TYPE_FROM_CLASS (klass),
1243 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1244 G_STRUCT_OFFSET (GstPlayBinClass, get_text_tags), NULL, NULL, NULL,
1245 GST_TYPE_TAG_LIST, 1, G_TYPE_INT);
1247 * GstPlayBin::convert-sample:
1248 * @playbin: a #GstPlayBin
1249 * @caps: the target format of the frame
1251 * Action signal to retrieve the currently playing video frame in the format
1252 * specified by @caps.
1253 * If @caps is %NULL, no conversion will be performed and this function is
1254 * equivalent to the #GstPlayBin:sample property.
1256 * Returns: a #GstSample of the current video frame converted to #caps.
1257 * The caps on the sample will describe the final layout of the buffer data.
1258 * %NULL is returned when no current buffer can be retrieved or when the
1259 * conversion failed.
1261 gst_play_bin_signals[SIGNAL_CONVERT_SAMPLE] =
1262 g_signal_new ("convert-sample", G_TYPE_FROM_CLASS (klass),
1263 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1264 G_STRUCT_OFFSET (GstPlayBinClass, convert_sample), NULL, NULL, NULL,
1265 GST_TYPE_SAMPLE, 1, GST_TYPE_CAPS);
1268 * GstPlayBin::get-video-pad:
1269 * @playbin: a #GstPlayBin
1270 * @stream: a video stream number
1272 * Action signal to retrieve the stream-combiner sinkpad for a specific
1274 * This pad can be used for notifications of caps changes, stream-specific
1277 * Returns: a #GstPad, or NULL when the stream number does not exist.
1279 gst_play_bin_signals[SIGNAL_GET_VIDEO_PAD] =
1280 g_signal_new ("get-video-pad", G_TYPE_FROM_CLASS (klass),
1281 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1282 G_STRUCT_OFFSET (GstPlayBinClass, get_video_pad), NULL, NULL, NULL,
1283 GST_TYPE_PAD, 1, G_TYPE_INT);
1285 * GstPlayBin::get-audio-pad:
1286 * @playbin: a #GstPlayBin
1287 * @stream: an audio stream number
1289 * Action signal to retrieve the stream-combiner sinkpad for a specific
1291 * This pad can be used for notifications of caps changes, stream-specific
1294 * Returns: a #GstPad, or NULL when the stream number does not exist.
1296 gst_play_bin_signals[SIGNAL_GET_AUDIO_PAD] =
1297 g_signal_new ("get-audio-pad", G_TYPE_FROM_CLASS (klass),
1298 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1299 G_STRUCT_OFFSET (GstPlayBinClass, get_audio_pad), NULL, NULL, NULL,
1300 GST_TYPE_PAD, 1, G_TYPE_INT);
1302 * GstPlayBin::get-text-pad:
1303 * @playbin: a #GstPlayBin
1304 * @stream: a text stream number
1306 * Action signal to retrieve the stream-combiner sinkpad for a specific
1308 * This pad can be used for notifications of caps changes, stream-specific
1311 * Returns: a #GstPad, or NULL when the stream number does not exist.
1313 gst_play_bin_signals[SIGNAL_GET_TEXT_PAD] =
1314 g_signal_new ("get-text-pad", G_TYPE_FROM_CLASS (klass),
1315 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
1316 G_STRUCT_OFFSET (GstPlayBinClass, get_text_pad), NULL, NULL, NULL,
1317 GST_TYPE_PAD, 1, G_TYPE_INT);
1319 klass->get_video_tags = gst_play_bin_get_video_tags;
1320 klass->get_audio_tags = gst_play_bin_get_audio_tags;
1321 klass->get_text_tags = gst_play_bin_get_text_tags;
1323 klass->convert_sample = gst_play_bin_convert_sample;
1325 klass->get_video_pad = gst_play_bin_get_video_pad;
1326 klass->get_audio_pad = gst_play_bin_get_audio_pad;
1327 klass->get_text_pad = gst_play_bin_get_text_pad;
1329 gst_element_class_set_static_metadata (gstelement_klass,
1330 "Player Bin 2", "Generic/Bin/Player",
1331 "Autoplug and play media from an uri",
1332 "Wim Taymans <wim.taymans@gmail.com>");
1334 gstelement_klass->change_state =
1335 GST_DEBUG_FUNCPTR (gst_play_bin_change_state);
1336 gstelement_klass->query = GST_DEBUG_FUNCPTR (gst_play_bin_query);
1337 gstelement_klass->set_context = GST_DEBUG_FUNCPTR (gst_play_bin_set_context);
1338 gstelement_klass->send_event = GST_DEBUG_FUNCPTR (gst_play_bin_send_event);
1340 gstbin_klass->handle_message =
1341 GST_DEBUG_FUNCPTR (gst_play_bin_handle_message);
1342 gstbin_klass->deep_element_added =
1343 GST_DEBUG_FUNCPTR (gst_play_bin_deep_element_added);
1345 gst_type_mark_as_plugin_api (GST_TYPE_PLAY_FLAGS, 0);
1349 do_async_start (GstPlayBin * playbin)
1351 GstMessage *message;
1353 playbin->async_pending = TRUE;
1355 message = gst_message_new_async_start (GST_OBJECT_CAST (playbin));
1356 GST_BIN_CLASS (parent_class)->handle_message (GST_BIN_CAST (playbin),
1361 do_async_done (GstPlayBin * playbin)
1363 GstMessage *message;
1365 if (playbin->async_pending) {
1366 GST_DEBUG_OBJECT (playbin, "posting ASYNC_DONE");
1368 gst_message_new_async_done (GST_OBJECT_CAST (playbin),
1369 GST_CLOCK_TIME_NONE);
1370 GST_BIN_CLASS (parent_class)->handle_message (GST_BIN_CAST (playbin),
1373 playbin->async_pending = FALSE;
1378 init_group (GstPlayBin * playbin, GstSourceGroup * group)
1380 /* store the array for the different channels */
1381 group->video_channels = g_ptr_array_new ();
1382 group->audio_channels = g_ptr_array_new ();
1383 group->text_channels = g_ptr_array_new ();
1384 g_mutex_init (&group->lock);
1386 group->stream_changed_pending = FALSE;
1387 g_mutex_init (&group->stream_changed_pending_lock);
1389 /* init combiners. The combiner is found by finding the first prefix that
1390 * matches the media. */
1391 group->playbin = playbin;
1392 /* If you add any items to these lists, check that media_list[] is defined
1393 * above to be large enough to hold MAX(items)+1, so as to accommodate a
1394 * NULL terminator (set when the memory is zeroed on allocation) */
1395 group->combiner[PLAYBIN_STREAM_AUDIO].media_list[0] = "audio/";
1396 group->combiner[PLAYBIN_STREAM_AUDIO].type = GST_PLAY_SINK_TYPE_AUDIO;
1397 group->combiner[PLAYBIN_STREAM_AUDIO].channels = group->audio_channels;
1398 group->combiner[PLAYBIN_STREAM_VIDEO].media_list[0] = "video/";
1399 group->combiner[PLAYBIN_STREAM_VIDEO].media_list[1] = "image/";
1400 group->combiner[PLAYBIN_STREAM_VIDEO].type = GST_PLAY_SINK_TYPE_VIDEO;
1401 group->combiner[PLAYBIN_STREAM_VIDEO].channels = group->video_channels;
1402 group->combiner[PLAYBIN_STREAM_TEXT].media_list[0] = "text/";
1403 group->combiner[PLAYBIN_STREAM_TEXT].media_list[1] = "application/x-subtitle";
1404 group->combiner[PLAYBIN_STREAM_TEXT].media_list[2] = "application/x-ssa";
1405 group->combiner[PLAYBIN_STREAM_TEXT].media_list[3] = "application/x-ass";
1406 group->combiner[PLAYBIN_STREAM_TEXT].media_list[4] = "subpicture/x-dvd";
1407 group->combiner[PLAYBIN_STREAM_TEXT].media_list[5] = "subpicture/";
1408 group->combiner[PLAYBIN_STREAM_TEXT].media_list[6] = "subtitle/";
1409 group->combiner[PLAYBIN_STREAM_TEXT].get_media_caps =
1410 gst_subtitle_overlay_create_factory_caps;
1411 group->combiner[PLAYBIN_STREAM_TEXT].type = GST_PLAY_SINK_TYPE_TEXT;
1412 group->combiner[PLAYBIN_STREAM_TEXT].channels = group->text_channels;
1416 free_group (GstPlayBin * playbin, GstSourceGroup * group)
1418 g_free (group->uri);
1419 g_free (group->suburi);
1420 g_ptr_array_free (group->video_channels, TRUE);
1421 g_ptr_array_free (group->audio_channels, TRUE);
1422 g_ptr_array_free (group->text_channels, TRUE);
1424 g_mutex_clear (&group->lock);
1425 if (group->audio_sink)
1426 gst_object_unref (group->audio_sink);
1427 group->audio_sink = NULL;
1428 if (group->video_sink)
1429 gst_object_unref (group->video_sink);
1430 group->video_sink = NULL;
1431 if (group->text_sink)
1432 gst_object_unref (group->text_sink);
1433 group->text_sink = NULL;
1435 group->stream_changed_pending = FALSE;
1436 g_mutex_clear (&group->stream_changed_pending_lock);
1438 g_slist_free (group->suburi_flushes_to_drop);
1439 group->suburi_flushes_to_drop = NULL;
1441 if (group->suburi_flushes_to_drop_lock.p)
1442 g_mutex_clear (&group->suburi_flushes_to_drop_lock);
1443 group->suburi_flushes_to_drop_lock.p = NULL;
1445 if (group->pending_buffering_msg)
1446 gst_message_unref (group->pending_buffering_msg);
1447 group->pending_buffering_msg = NULL;
1451 notify_volume_cb (GObject * combiner, GParamSpec * pspec, GstPlayBin * playbin)
1453 g_object_notify (G_OBJECT (playbin), "volume");
1457 notify_mute_cb (GObject * combiner, GParamSpec * pspec, GstPlayBin * playbin)
1459 g_object_notify (G_OBJECT (playbin), "mute");
1463 colorbalance_value_changed_cb (GstColorBalance * balance,
1464 GstColorBalanceChannel * channel, gint value, GstPlayBin * playbin)
1466 gst_color_balance_value_changed (GST_COLOR_BALANCE (playbin), channel, value);
1470 compare_factories_func (gconstpointer p1, gconstpointer p2)
1472 GstPluginFeature *f1, *f2;
1473 gboolean is_sink1, is_sink2;
1474 gboolean is_parser1, is_parser2;
1476 f1 = (GstPluginFeature *) p1;
1477 f2 = (GstPluginFeature *) p2;
1479 is_sink1 = gst_element_factory_list_is_type (GST_ELEMENT_FACTORY_CAST (f1),
1480 GST_ELEMENT_FACTORY_TYPE_SINK);
1481 is_sink2 = gst_element_factory_list_is_type (GST_ELEMENT_FACTORY_CAST (f2),
1482 GST_ELEMENT_FACTORY_TYPE_SINK);
1483 is_parser1 = gst_element_factory_list_is_type (GST_ELEMENT_FACTORY_CAST (f1),
1484 GST_ELEMENT_FACTORY_TYPE_PARSER);
1485 is_parser2 = gst_element_factory_list_is_type (GST_ELEMENT_FACTORY_CAST (f2),
1486 GST_ELEMENT_FACTORY_TYPE_PARSER);
1488 /* First we want all sinks as we prefer a sink if it directly
1489 * supports the current caps */
1490 if (is_sink1 && !is_sink2)
1492 else if (!is_sink1 && is_sink2)
1495 /* Then we want all parsers as we always want to plug parsers
1496 * before decoders */
1497 if (is_parser1 && !is_parser2)
1499 else if (!is_parser1 && is_parser2)
1502 /* And if it's a both a parser or sink we first sort by rank
1503 * and then by factory name */
1504 return gst_plugin_feature_rank_compare_func (p1, p2);
1507 /* Must be called with elements lock! */
1509 gst_play_bin_update_elements_list (GstPlayBin * playbin)
1514 cookie = gst_registry_get_feature_list_cookie (gst_registry_get ());
1516 if (!playbin->elements || playbin->elements_cookie != cookie) {
1517 if (playbin->elements)
1518 gst_plugin_feature_list_free (playbin->elements);
1520 gst_element_factory_list_get_elements
1521 (GST_ELEMENT_FACTORY_TYPE_DECODABLE, GST_RANK_MARGINAL);
1523 gst_element_factory_list_get_elements
1524 (GST_ELEMENT_FACTORY_TYPE_AUDIOVIDEO_SINKS, GST_RANK_MARGINAL);
1525 playbin->elements = g_list_concat (res, tmp);
1526 playbin->elements = g_list_sort (playbin->elements, compare_factories_func);
1529 if (!playbin->aelements || playbin->elements_cookie != cookie) {
1530 if (playbin->aelements)
1531 g_sequence_free (playbin->aelements);
1532 playbin->aelements = avelements_create (playbin, TRUE);
1535 if (!playbin->velements || playbin->elements_cookie != cookie) {
1536 if (playbin->velements)
1537 g_sequence_free (playbin->velements);
1538 playbin->velements = avelements_create (playbin, FALSE);
1541 playbin->elements_cookie = cookie;
1545 gst_play_bin_init (GstPlayBin * playbin)
1547 g_rec_mutex_init (&playbin->lock);
1548 g_mutex_init (&playbin->dyn_lock);
1550 /* assume we can create an input-selector */
1551 playbin->have_selector = TRUE;
1554 playbin->curr_group = &playbin->groups[0];
1555 playbin->next_group = &playbin->groups[1];
1556 init_group (playbin, &playbin->groups[0]);
1557 init_group (playbin, &playbin->groups[1]);
1559 /* first filter out the interesting element factories */
1560 g_mutex_init (&playbin->elements_lock);
1564 g_object_new (GST_TYPE_PLAY_SINK, "name", "playsink", "send-event-mode",
1566 gst_bin_add (GST_BIN_CAST (playbin), GST_ELEMENT_CAST (playbin->playsink));
1567 gst_play_sink_set_flags (playbin->playsink, DEFAULT_FLAGS);
1568 /* Connect to notify::volume and notify::mute signals for proxying */
1569 g_signal_connect (playbin->playsink, "notify::volume",
1570 G_CALLBACK (notify_volume_cb), playbin);
1571 g_signal_connect (playbin->playsink, "notify::mute",
1572 G_CALLBACK (notify_mute_cb), playbin);
1573 g_signal_connect (playbin->playsink, "value-changed",
1574 G_CALLBACK (colorbalance_value_changed_cb), playbin);
1576 playbin->current_video = DEFAULT_CURRENT_VIDEO;
1577 playbin->current_audio = DEFAULT_CURRENT_AUDIO;
1578 playbin->current_text = DEFAULT_CURRENT_TEXT;
1580 playbin->buffer_duration = DEFAULT_BUFFER_DURATION;
1581 playbin->buffer_size = DEFAULT_BUFFER_SIZE;
1582 playbin->ring_buffer_max_size = DEFAULT_RING_BUFFER_MAX_SIZE;
1584 playbin->force_aspect_ratio = TRUE;
1586 playbin->multiview_mode = GST_VIDEO_MULTIVIEW_FRAME_PACKING_NONE;
1587 playbin->multiview_flags = GST_VIDEO_MULTIVIEW_FLAGS_NONE;
1591 gst_play_bin_finalize (GObject * object)
1593 GstPlayBin *playbin;
1595 playbin = GST_PLAY_BIN (object);
1597 free_group (playbin, &playbin->groups[0]);
1598 free_group (playbin, &playbin->groups[1]);
1600 if (playbin->source)
1601 gst_object_unref (playbin->source);
1603 /* Setting states to NULL is safe here because playsink
1604 * will already be gone and none of these sinks will be
1605 * a child of playsink
1607 if (playbin->video_sink) {
1608 gst_element_set_state (playbin->video_sink, GST_STATE_NULL);
1609 gst_object_unref (playbin->video_sink);
1611 if (playbin->audio_sink) {
1612 gst_element_set_state (playbin->audio_sink, GST_STATE_NULL);
1613 gst_object_unref (playbin->audio_sink);
1615 if (playbin->text_sink) {
1616 gst_element_set_state (playbin->text_sink, GST_STATE_NULL);
1617 gst_object_unref (playbin->text_sink);
1620 if (playbin->video_stream_combiner) {
1621 gst_element_set_state (playbin->video_stream_combiner, GST_STATE_NULL);
1622 gst_object_unref (playbin->video_stream_combiner);
1624 if (playbin->audio_stream_combiner) {
1625 gst_element_set_state (playbin->audio_stream_combiner, GST_STATE_NULL);
1626 gst_object_unref (playbin->audio_stream_combiner);
1628 if (playbin->text_stream_combiner) {
1629 gst_element_set_state (playbin->text_stream_combiner, GST_STATE_NULL);
1630 gst_object_unref (playbin->text_stream_combiner);
1633 if (playbin->elements)
1634 gst_plugin_feature_list_free (playbin->elements);
1636 if (playbin->aelements)
1637 g_sequence_free (playbin->aelements);
1639 if (playbin->velements)
1640 g_sequence_free (playbin->velements);
1642 g_list_free_full (playbin->contexts, (GDestroyNotify) gst_context_unref);
1644 g_rec_mutex_clear (&playbin->lock);
1645 g_mutex_clear (&playbin->dyn_lock);
1646 g_mutex_clear (&playbin->elements_lock);
1648 G_OBJECT_CLASS (parent_class)->finalize (object);
1652 gst_playbin_uri_is_valid (GstPlayBin * playbin, const gchar * uri)
1656 GST_LOG_OBJECT (playbin, "checking uri '%s'", uri);
1658 /* this just checks the protocol */
1659 if (!gst_uri_is_valid (uri))
1662 for (c = uri; *c != '\0'; ++c) {
1663 if (!g_ascii_isprint (*c))
1673 GST_WARNING_OBJECT (playbin, "uri '%s' not valid, character #%u",
1674 uri, (guint) ((guintptr) c - (guintptr) uri));
1680 gst_play_bin_set_uri (GstPlayBin * playbin, const gchar * uri)
1682 GstSourceGroup *group;
1685 g_warning ("cannot set NULL uri");
1689 if (!gst_playbin_uri_is_valid (playbin, uri)) {
1690 if (g_str_has_prefix (uri, "file:")) {
1691 GST_WARNING_OBJECT (playbin, "not entirely correct file URI '%s' - make "
1692 "sure to escape spaces and non-ASCII characters properly and specify "
1693 "an absolute path. Use gst_filename_to_uri() to convert filenames "
1696 /* GST_ERROR_OBJECT (playbin, "malformed URI '%s'", uri); */
1700 GST_PLAY_BIN_LOCK (playbin);
1701 group = playbin->next_group;
1703 GST_SOURCE_GROUP_LOCK (group);
1704 /* store the uri in the next group we will play */
1705 g_free (group->uri);
1706 group->uri = g_strdup (uri);
1707 group->valid = TRUE;
1708 GST_SOURCE_GROUP_UNLOCK (group);
1710 GST_DEBUG ("set new uri to %s", uri);
1711 GST_PLAY_BIN_UNLOCK (playbin);
1715 gst_play_bin_set_suburi (GstPlayBin * playbin, const gchar * suburi)
1717 GstSourceGroup *group;
1719 GST_PLAY_BIN_LOCK (playbin);
1720 group = playbin->next_group;
1722 GST_SOURCE_GROUP_LOCK (group);
1723 g_free (group->suburi);
1724 group->suburi = g_strdup (suburi);
1725 GST_SOURCE_GROUP_UNLOCK (group);
1727 GST_DEBUG ("setting new .sub uri to %s", suburi);
1729 GST_PLAY_BIN_UNLOCK (playbin);
1733 gst_play_bin_set_flags (GstPlayBin * playbin, GstPlayFlags flags)
1735 GstPlayFlags old_flags;
1736 old_flags = gst_play_sink_get_flags (playbin->playsink);
1738 if (flags != old_flags) {
1739 gst_play_sink_set_flags (playbin->playsink, flags);
1740 gst_play_sink_reconfigure (playbin->playsink);
1745 gst_play_bin_get_flags (GstPlayBin * playbin)
1749 flags = gst_play_sink_get_flags (playbin->playsink);
1754 /* get the currently playing group or if nothing is playing, the next
1755 * group. Must be called with the PLAY_BIN_LOCK. */
1756 static GstSourceGroup *
1757 get_group (GstPlayBin * playbin)
1759 GstSourceGroup *result;
1761 if (!(result = playbin->curr_group))
1762 result = playbin->next_group;
1768 gst_play_bin_get_video_pad (GstPlayBin * playbin, gint stream)
1770 GstPad *sinkpad = NULL;
1771 GstSourceGroup *group;
1773 GST_PLAY_BIN_LOCK (playbin);
1774 group = get_group (playbin);
1775 if (stream < group->video_channels->len) {
1776 sinkpad = g_ptr_array_index (group->video_channels, stream);
1777 gst_object_ref (sinkpad);
1779 GST_PLAY_BIN_UNLOCK (playbin);
1785 gst_play_bin_get_audio_pad (GstPlayBin * playbin, gint stream)
1787 GstPad *sinkpad = NULL;
1788 GstSourceGroup *group;
1790 GST_PLAY_BIN_LOCK (playbin);
1791 group = get_group (playbin);
1792 if (stream < group->audio_channels->len) {
1793 sinkpad = g_ptr_array_index (group->audio_channels, stream);
1794 gst_object_ref (sinkpad);
1796 GST_PLAY_BIN_UNLOCK (playbin);
1802 gst_play_bin_get_text_pad (GstPlayBin * playbin, gint stream)
1804 GstPad *sinkpad = NULL;
1805 GstSourceGroup *group;
1807 GST_PLAY_BIN_LOCK (playbin);
1808 group = get_group (playbin);
1809 if (stream < group->text_channels->len) {
1810 sinkpad = g_ptr_array_index (group->text_channels, stream);
1811 gst_object_ref (sinkpad);
1813 GST_PLAY_BIN_UNLOCK (playbin);
1820 get_tags (GstPlayBin * playbin, GstSourceGroup * group, gint type, gint stream)
1823 GPtrArray *channels;
1827 case PLAYBIN_STREAM_AUDIO:
1828 channels = group->audio_channels;
1830 case PLAYBIN_STREAM_VIDEO:
1831 channels = group->video_channels;
1833 case PLAYBIN_STREAM_TEXT:
1834 channels = group->text_channels;
1841 if (!channels || stream >= channels->len || !group->combiner[type].has_tags)
1844 sinkpad = g_ptr_array_index (channels, stream);
1845 g_object_get (sinkpad, "tags", &result, NULL);
1851 gst_play_bin_get_video_tags (GstPlayBin * playbin, gint stream)
1854 GstSourceGroup *group;
1856 GST_PLAY_BIN_LOCK (playbin);
1857 group = get_group (playbin);
1858 result = get_tags (playbin, group, PLAYBIN_STREAM_VIDEO, stream);
1859 GST_PLAY_BIN_UNLOCK (playbin);
1865 gst_play_bin_get_audio_tags (GstPlayBin * playbin, gint stream)
1868 GstSourceGroup *group;
1870 GST_PLAY_BIN_LOCK (playbin);
1871 group = get_group (playbin);
1872 result = get_tags (playbin, group, PLAYBIN_STREAM_AUDIO, stream);
1873 GST_PLAY_BIN_UNLOCK (playbin);
1879 gst_play_bin_get_text_tags (GstPlayBin * playbin, gint stream)
1882 GstSourceGroup *group;
1884 GST_PLAY_BIN_LOCK (playbin);
1885 group = get_group (playbin);
1886 result = get_tags (playbin, group, PLAYBIN_STREAM_TEXT, stream);
1887 GST_PLAY_BIN_UNLOCK (playbin);
1893 gst_play_bin_convert_sample (GstPlayBin * playbin, GstCaps * caps)
1895 return gst_play_sink_convert_sample (playbin->playsink, caps);
1898 /* Returns current stream number, or -1 if none has been selected yet */
1900 get_current_stream_number (GstPlayBin * playbin, GstSourceCombine * combine,
1901 GPtrArray * channels)
1903 /* Internal API cleanup would make this easier... */
1905 GstPad *pad, *current;
1906 GstObject *combiner = NULL;
1909 if (!combine->has_active_pad) {
1910 GST_WARNING_OBJECT (playbin,
1911 "combiner doesn't have the \"active-pad\" property");
1915 for (i = 0; i < channels->len; i++) {
1916 pad = g_ptr_array_index (channels, i);
1917 if ((combiner = gst_pad_get_parent (pad))) {
1918 g_object_get (combiner, "active-pad", ¤t, NULL);
1919 gst_object_unref (combiner);
1921 if (pad == current) {
1922 gst_object_unref (current);
1928 gst_object_unref (current);
1936 gst_play_bin_send_custom_event (GstObject * combiner, const gchar * event_name)
1942 gboolean ret = FALSE;
1944 src = gst_element_get_static_pad (GST_ELEMENT_CAST (combiner), "src");
1945 peer = gst_pad_get_peer (src);
1947 s = gst_structure_new_empty (event_name);
1948 event = gst_event_new_custom (GST_EVENT_CUSTOM_DOWNSTREAM_OOB, s);
1949 gst_pad_send_event (peer, event);
1950 gst_object_unref (peer);
1953 gst_object_unref (src);
1958 gst_play_bin_set_current_video_stream (GstPlayBin * playbin, gint stream)
1960 GstSourceGroup *group;
1961 GPtrArray *channels;
1964 GST_PLAY_BIN_LOCK (playbin);
1966 GST_DEBUG_OBJECT (playbin, "Changing current video stream %d -> %d",
1967 playbin->current_video, stream);
1969 group = get_group (playbin);
1970 if (!group->combiner[PLAYBIN_STREAM_VIDEO].has_active_pad)
1972 if (!(channels = group->video_channels))
1975 if (stream == -1 || channels->len <= stream) {
1978 /* take channel from selected stream */
1979 sinkpad = g_ptr_array_index (channels, stream);
1983 gst_object_ref (sinkpad);
1984 GST_PLAY_BIN_UNLOCK (playbin);
1987 GstObject *combiner;
1989 if ((combiner = gst_pad_get_parent (sinkpad))) {
1990 GstPad *old_sinkpad;
1992 g_object_get (combiner, "active-pad", &old_sinkpad, NULL);
1994 if (old_sinkpad != sinkpad) {
1995 if (gst_play_bin_send_custom_event (combiner,
1996 "playsink-custom-video-flush"))
1997 playbin->video_pending_flush_finish = TRUE;
1999 /* activate the selected pad */
2000 g_object_set (combiner, "active-pad", sinkpad, NULL);
2004 gst_object_unref (old_sinkpad);
2006 gst_object_unref (combiner);
2008 gst_object_unref (sinkpad);
2014 GST_PLAY_BIN_UNLOCK (playbin);
2015 GST_WARNING_OBJECT (playbin,
2016 "can't switch video, the stream combiner's sink pads don't have the \"active-pad\" property");
2021 GST_PLAY_BIN_UNLOCK (playbin);
2022 GST_DEBUG_OBJECT (playbin, "can't switch video, we have no channels");
2028 gst_play_bin_set_current_audio_stream (GstPlayBin * playbin, gint stream)
2030 GstSourceGroup *group;
2031 GPtrArray *channels;
2034 GST_PLAY_BIN_LOCK (playbin);
2036 GST_DEBUG_OBJECT (playbin, "Changing current audio stream %d -> %d",
2037 playbin->current_audio, stream);
2039 group = get_group (playbin);
2040 if (!group->combiner[PLAYBIN_STREAM_AUDIO].has_active_pad)
2042 if (!(channels = group->audio_channels))
2045 if (stream == -1 || channels->len <= stream) {
2048 /* take channel from selected stream */
2049 sinkpad = g_ptr_array_index (channels, stream);
2053 gst_object_ref (sinkpad);
2054 GST_PLAY_BIN_UNLOCK (playbin);
2057 GstObject *combiner;
2059 if ((combiner = gst_pad_get_parent (sinkpad))) {
2060 GstPad *old_sinkpad;
2062 g_object_get (combiner, "active-pad", &old_sinkpad, NULL);
2064 if (old_sinkpad != sinkpad) {
2065 if (gst_play_bin_send_custom_event (combiner,
2066 "playsink-custom-audio-flush"))
2067 playbin->audio_pending_flush_finish = TRUE;
2069 /* activate the selected pad */
2070 g_object_set (combiner, "active-pad", sinkpad, NULL);
2074 gst_object_unref (old_sinkpad);
2076 gst_object_unref (combiner);
2078 gst_object_unref (sinkpad);
2084 GST_PLAY_BIN_UNLOCK (playbin);
2085 GST_WARNING_OBJECT (playbin,
2086 "can't switch audio, the stream combiner's sink pads don't have the \"active-pad\" property");
2091 GST_PLAY_BIN_UNLOCK (playbin);
2092 GST_DEBUG_OBJECT (playbin, "can't switch audio, we have no channels");
2098 gst_play_bin_suburidecodebin_seek_to_start (GstSourceGroup * group)
2100 GstElement *suburidecodebin = group->suburidecodebin;
2101 GstIterator *it = gst_element_iterate_src_pads (suburidecodebin);
2103 GValue item = { 0, };
2105 if (it && gst_iterator_next (it, &item) == GST_ITERATOR_OK
2106 && ((sinkpad = g_value_get_object (&item)) != NULL)) {
2111 gst_event_new_seek (1.0, GST_FORMAT_BYTES, GST_SEEK_FLAG_FLUSH,
2112 GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_NONE, -1);
2113 seqnum = gst_event_get_seqnum (event);
2115 /* store the seqnum to drop flushes from this seek later */
2116 g_mutex_lock (&group->suburi_flushes_to_drop_lock);
2117 group->suburi_flushes_to_drop =
2118 g_slist_append (group->suburi_flushes_to_drop,
2119 GUINT_TO_POINTER (seqnum));
2120 g_mutex_unlock (&group->suburi_flushes_to_drop_lock);
2122 if (!gst_pad_send_event (sinkpad, event)) {
2124 gst_event_new_seek (1.0, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH,
2125 GST_SEEK_TYPE_SET, 0, GST_SEEK_TYPE_NONE, -1);
2126 gst_event_set_seqnum (event, seqnum);
2127 if (!gst_pad_send_event (sinkpad, event)) {
2128 GST_DEBUG_OBJECT (suburidecodebin, "Seeking to the beginning failed!");
2130 g_mutex_lock (&group->suburi_flushes_to_drop_lock);
2131 group->suburi_flushes_to_drop =
2132 g_slist_remove (group->suburi_flushes_to_drop,
2133 GUINT_TO_POINTER (seqnum));
2134 g_mutex_unlock (&group->suburi_flushes_to_drop_lock);
2138 g_value_unset (&item);
2142 gst_iterator_free (it);
2146 source_combine_remove_pads (GstPlayBin * playbin, GstSourceCombine * combine)
2148 if (combine->sinkpad) {
2149 GST_LOG_OBJECT (playbin, "unlinking from sink");
2150 gst_pad_unlink (combine->srcpad, combine->sinkpad);
2153 GST_LOG_OBJECT (playbin, "release sink pad");
2154 gst_play_sink_release_pad (playbin->playsink, combine->sinkpad);
2155 gst_object_unref (combine->sinkpad);
2156 combine->sinkpad = NULL;
2158 gst_object_unref (combine->srcpad);
2159 combine->srcpad = NULL;
2162 static GstPadProbeReturn
2163 block_serialized_data_cb (GstPad * pad, GstPadProbeInfo * info,
2166 if (GST_IS_EVENT (info->data) && !GST_EVENT_IS_SERIALIZED (info->data)) {
2167 GST_DEBUG_OBJECT (pad, "Letting non-serialized event %s pass",
2168 GST_EVENT_TYPE_NAME (info->data));
2169 return GST_PAD_PROBE_PASS;
2172 return GST_PAD_PROBE_OK;
2176 gst_play_bin_suburidecodebin_block (GstSourceGroup * group,
2177 GstElement * suburidecodebin, gboolean block)
2179 GstIterator *it = gst_element_iterate_src_pads (suburidecodebin);
2180 gboolean done = FALSE;
2181 GValue item = { 0, };
2183 GST_DEBUG_OBJECT (suburidecodebin, "Blocking suburidecodebin: %d", block);
2190 switch (gst_iterator_next (it, &item)) {
2191 case GST_ITERATOR_OK:
2192 sinkpad = g_value_get_object (&item);
2195 gst_pad_add_probe (sinkpad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
2196 block_serialized_data_cb, NULL, NULL);
2197 } else if (group->block_id) {
2198 gst_pad_remove_probe (sinkpad, group->block_id);
2199 group->block_id = 0;
2201 g_value_reset (&item);
2203 case GST_ITERATOR_DONE:
2206 case GST_ITERATOR_RESYNC:
2207 gst_iterator_resync (it);
2209 case GST_ITERATOR_ERROR:
2214 g_value_unset (&item);
2215 gst_iterator_free (it);
2219 gst_play_bin_set_current_text_stream (GstPlayBin * playbin, gint stream)
2221 GstSourceGroup *group;
2222 GPtrArray *channels;
2225 GST_PLAY_BIN_LOCK (playbin);
2227 GST_DEBUG_OBJECT (playbin, "Changing current text stream %d -> %d",
2228 playbin->current_text, stream);
2230 group = get_group (playbin);
2231 if (!group->combiner[PLAYBIN_STREAM_TEXT].has_active_pad)
2233 if (!(channels = group->text_channels))
2236 if (stream == -1 || channels->len <= stream) {
2239 /* take channel from selected stream */
2240 sinkpad = g_ptr_array_index (channels, stream);
2244 gst_object_ref (sinkpad);
2245 GST_PLAY_BIN_UNLOCK (playbin);
2248 GstObject *combiner;
2250 if ((combiner = gst_pad_get_parent (sinkpad))) {
2251 GstPad *old_sinkpad;
2253 g_object_get (combiner, "active-pad", &old_sinkpad, NULL);
2255 if (old_sinkpad != sinkpad) {
2256 gboolean need_unblock, need_block, need_seek;
2257 GstPad *peer = NULL, *oldpeer = NULL;
2258 GstElement *parent_element = NULL, *old_parent_element = NULL;
2260 /* Now check if we need to seek the suburidecodebin to the beginning
2261 * or if we need to block all suburidecodebin sinkpads or if we need
2262 * to unblock all suburidecodebin sinkpads
2265 peer = gst_pad_get_peer (sinkpad);
2267 oldpeer = gst_pad_get_peer (old_sinkpad);
2270 parent_element = gst_pad_get_parent_element (peer);
2272 old_parent_element = gst_pad_get_parent_element (oldpeer);
2274 need_block = (old_parent_element == group->suburidecodebin
2275 && parent_element != old_parent_element);
2276 need_unblock = (parent_element == group->suburidecodebin
2277 && parent_element != old_parent_element);
2278 need_seek = (parent_element == group->suburidecodebin);
2281 gst_object_unref (peer);
2283 gst_object_unref (oldpeer);
2285 gst_object_unref (parent_element);
2286 if (old_parent_element)
2287 gst_object_unref (old_parent_element);
2289 /* Block all suburidecodebin sinkpads */
2291 gst_play_bin_suburidecodebin_block (group, group->suburidecodebin,
2294 if (gst_play_bin_send_custom_event (combiner,
2295 "playsink-custom-subtitle-flush"))
2296 playbin->text_pending_flush_finish = TRUE;
2298 /* activate the selected pad */
2299 g_object_set (combiner, "active-pad", sinkpad, NULL);
2301 /* Unblock pads if necessary */
2303 gst_play_bin_suburidecodebin_block (group, group->suburidecodebin,
2306 /* seek to the beginning */
2308 gst_play_bin_suburidecodebin_seek_to_start (group);
2310 gst_object_unref (combiner);
2313 gst_object_unref (old_sinkpad);
2315 gst_object_unref (sinkpad);
2321 GST_PLAY_BIN_UNLOCK (playbin);
2322 GST_WARNING_OBJECT (playbin,
2323 "can't switch text, the stream combiner's sink pads don't have the \"active-pad\" property");
2328 GST_PLAY_BIN_UNLOCK (playbin);
2334 gst_play_bin_set_sink (GstPlayBin * playbin, GstPlaySinkType type,
2335 const gchar * dbg, GstElement ** elem, GstElement * sink)
2337 GST_INFO_OBJECT (playbin, "Setting %s sink to %" GST_PTR_FORMAT, dbg, sink);
2339 gst_play_sink_set_sink (playbin->playsink, type, sink);
2342 gst_object_unref (*elem);
2343 *elem = sink ? gst_object_ref (sink) : NULL;
2347 gst_play_bin_set_stream_combiner (GstPlayBin * playbin, GstElement ** elem,
2348 const gchar * dbg, GstElement * combiner)
2350 GST_INFO_OBJECT (playbin, "Setting %s stream combiner to %" GST_PTR_FORMAT,
2353 GST_PLAY_BIN_LOCK (playbin);
2354 if (*elem != combiner) {
2359 gst_object_ref_sink (combiner);
2363 gst_object_unref (old);
2365 GST_LOG_OBJECT (playbin, "%s stream combiner now %" GST_PTR_FORMAT, dbg,
2367 GST_PLAY_BIN_UNLOCK (playbin);
2371 gst_play_bin_set_encoding (GstPlayBin * playbin, const gchar * encoding)
2375 GST_PLAY_BIN_LOCK (playbin);
2377 /* set subtitles on all current and next decodebins. */
2378 if ((elem = playbin->groups[0].uridecodebin))
2379 g_object_set (G_OBJECT (elem), "subtitle-encoding", encoding, NULL);
2380 if ((elem = playbin->groups[0].suburidecodebin))
2381 g_object_set (G_OBJECT (elem), "subtitle-encoding", encoding, NULL);
2382 if ((elem = playbin->groups[1].uridecodebin))
2383 g_object_set (G_OBJECT (elem), "subtitle-encoding", encoding, NULL);
2384 if ((elem = playbin->groups[1].suburidecodebin))
2385 g_object_set (G_OBJECT (elem), "subtitle-encoding", encoding, NULL);
2387 gst_play_sink_set_subtitle_encoding (playbin->playsink, encoding);
2388 GST_PLAY_BIN_UNLOCK (playbin);
2392 gst_play_bin_set_property (GObject * object, guint prop_id,
2393 const GValue * value, GParamSpec * pspec)
2395 GstPlayBin *playbin = GST_PLAY_BIN (object);
2399 gst_play_bin_set_uri (playbin, g_value_get_string (value));
2402 gst_play_bin_set_suburi (playbin, g_value_get_string (value));
2405 gst_play_bin_set_flags (playbin, g_value_get_flags (value));
2406 if (playbin->curr_group) {
2407 GST_SOURCE_GROUP_LOCK (playbin->curr_group);
2408 if (playbin->curr_group->uridecodebin) {
2409 guint flags = g_value_get_flags (value);
2410 g_object_set (playbin->curr_group->uridecodebin,
2411 "download", (flags & GST_PLAY_FLAG_DOWNLOAD) != 0,
2412 "force-sw-decoders",
2413 (flags & GST_PLAY_FLAG_FORCE_SW_DECODERS) != 0, NULL);
2415 GST_SOURCE_GROUP_UNLOCK (playbin->curr_group);
2418 case PROP_CURRENT_VIDEO:
2419 gst_play_bin_set_current_video_stream (playbin, g_value_get_int (value));
2421 case PROP_CURRENT_AUDIO:
2422 gst_play_bin_set_current_audio_stream (playbin, g_value_get_int (value));
2424 case PROP_CURRENT_TEXT:
2425 gst_play_bin_set_current_text_stream (playbin, g_value_get_int (value));
2427 case PROP_SUBTITLE_ENCODING:
2428 gst_play_bin_set_encoding (playbin, g_value_get_string (value));
2430 case PROP_VIDEO_FILTER:
2431 gst_play_sink_set_filter (playbin->playsink, GST_PLAY_SINK_TYPE_VIDEO,
2432 GST_ELEMENT (g_value_get_object (value)));
2434 case PROP_AUDIO_FILTER:
2435 gst_play_sink_set_filter (playbin->playsink, GST_PLAY_SINK_TYPE_AUDIO,
2436 GST_ELEMENT (g_value_get_object (value)));
2438 case PROP_VIDEO_SINK:
2439 gst_play_bin_set_sink (playbin, GST_PLAY_SINK_TYPE_VIDEO, "video",
2440 &playbin->video_sink, g_value_get_object (value));
2442 case PROP_AUDIO_SINK:
2443 gst_play_bin_set_sink (playbin, GST_PLAY_SINK_TYPE_AUDIO, "audio",
2444 &playbin->audio_sink, g_value_get_object (value));
2446 case PROP_VIS_PLUGIN:
2447 gst_play_sink_set_vis_plugin (playbin->playsink,
2448 g_value_get_object (value));
2450 case PROP_TEXT_SINK:
2451 gst_play_bin_set_sink (playbin, GST_PLAY_SINK_TYPE_TEXT, "text",
2452 &playbin->text_sink, g_value_get_object (value));
2454 case PROP_VIDEO_STREAM_COMBINER:
2455 gst_play_bin_set_stream_combiner (playbin,
2456 &playbin->video_stream_combiner, "video", g_value_get_object (value));
2458 case PROP_AUDIO_STREAM_COMBINER:
2459 gst_play_bin_set_stream_combiner (playbin,
2460 &playbin->audio_stream_combiner, "audio", g_value_get_object (value));
2462 case PROP_TEXT_STREAM_COMBINER:
2463 gst_play_bin_set_stream_combiner (playbin,
2464 &playbin->text_stream_combiner, "text", g_value_get_object (value));
2467 gst_play_sink_set_volume (playbin->playsink, g_value_get_double (value));
2470 gst_play_sink_set_mute (playbin->playsink, g_value_get_boolean (value));
2472 case PROP_FONT_DESC:
2473 gst_play_sink_set_font_desc (playbin->playsink,
2474 g_value_get_string (value));
2476 case PROP_CONNECTION_SPEED:
2477 GST_PLAY_BIN_LOCK (playbin);
2478 playbin->connection_speed = g_value_get_uint64 (value) * 1000;
2479 GST_PLAY_BIN_UNLOCK (playbin);
2481 case PROP_BUFFER_SIZE:
2482 playbin->buffer_size = g_value_get_int (value);
2484 case PROP_BUFFER_DURATION:
2485 playbin->buffer_duration = g_value_get_int64 (value);
2487 case PROP_AV_OFFSET:
2488 gst_play_sink_set_av_offset (playbin->playsink,
2489 g_value_get_int64 (value));
2491 case PROP_TEXT_OFFSET:
2492 gst_play_sink_set_text_offset (playbin->playsink,
2493 g_value_get_int64 (value));
2495 case PROP_RING_BUFFER_MAX_SIZE:
2496 playbin->ring_buffer_max_size = g_value_get_uint64 (value);
2497 if (playbin->curr_group) {
2498 GST_SOURCE_GROUP_LOCK (playbin->curr_group);
2499 if (playbin->curr_group->uridecodebin) {
2500 g_object_set (playbin->curr_group->uridecodebin,
2501 "ring-buffer-max-size", playbin->ring_buffer_max_size, NULL);
2503 GST_SOURCE_GROUP_UNLOCK (playbin->curr_group);
2506 case PROP_FORCE_ASPECT_RATIO:
2507 g_object_set (playbin->playsink, "force-aspect-ratio",
2508 g_value_get_boolean (value), NULL);
2510 case PROP_MULTIVIEW_MODE:
2511 GST_PLAY_BIN_LOCK (playbin);
2512 playbin->multiview_mode = g_value_get_enum (value);
2513 GST_PLAY_BIN_UNLOCK (playbin);
2515 case PROP_MULTIVIEW_FLAGS:
2516 GST_PLAY_BIN_LOCK (playbin);
2517 playbin->multiview_flags = g_value_get_flags (value);
2518 GST_PLAY_BIN_UNLOCK (playbin);
2521 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2527 gst_play_bin_get_current_sink (GstPlayBin * playbin, GstElement ** elem,
2528 const gchar * dbg, GstPlaySinkType type)
2530 GstElement *sink = gst_play_sink_get_sink (playbin->playsink, type);
2532 GST_LOG_OBJECT (playbin, "play_sink_get_sink() returned %s sink %"
2533 GST_PTR_FORMAT ", the originally set %s sink is %" GST_PTR_FORMAT,
2534 dbg, sink, dbg, *elem);
2537 GST_PLAY_BIN_LOCK (playbin);
2539 gst_object_ref (sink);
2540 GST_PLAY_BIN_UNLOCK (playbin);
2547 gst_play_bin_get_current_stream_combiner (GstPlayBin * playbin,
2548 GstElement ** elem, const gchar * dbg, int stream_type)
2550 GstElement *combiner;
2552 GST_PLAY_BIN_LOCK (playbin);
2553 if ((combiner = playbin->curr_group->combiner[stream_type].combiner))
2554 gst_object_ref (combiner);
2555 else if ((combiner = *elem))
2556 gst_object_ref (combiner);
2557 GST_PLAY_BIN_UNLOCK (playbin);
2563 gst_play_bin_get_property (GObject * object, guint prop_id, GValue * value,
2566 GstPlayBin *playbin = GST_PLAY_BIN (object);
2571 GstSourceGroup *group;
2573 GST_PLAY_BIN_LOCK (playbin);
2574 group = playbin->next_group;
2575 g_value_set_string (value, group->uri);
2576 GST_PLAY_BIN_UNLOCK (playbin);
2579 case PROP_CURRENT_URI:
2581 GstSourceGroup *group;
2583 GST_PLAY_BIN_LOCK (playbin);
2584 group = get_group (playbin);
2585 g_value_set_string (value, group->uri);
2586 GST_PLAY_BIN_UNLOCK (playbin);
2591 GstSourceGroup *group;
2593 GST_PLAY_BIN_LOCK (playbin);
2594 group = playbin->next_group;
2595 g_value_set_string (value, group->suburi);
2596 GST_PLAY_BIN_UNLOCK (playbin);
2599 case PROP_CURRENT_SUBURI:
2601 GstSourceGroup *group;
2603 GST_PLAY_BIN_LOCK (playbin);
2604 group = get_group (playbin);
2605 g_value_set_string (value, group->suburi);
2606 GST_PLAY_BIN_UNLOCK (playbin);
2611 GST_OBJECT_LOCK (playbin);
2612 g_value_set_object (value, playbin->source);
2613 GST_OBJECT_UNLOCK (playbin);
2617 g_value_set_flags (value, gst_play_bin_get_flags (playbin));
2621 GstSourceGroup *group;
2624 GST_PLAY_BIN_LOCK (playbin);
2625 group = get_group (playbin);
2626 n_video = (group->video_channels ? group->video_channels->len : 0);
2627 g_value_set_int (value, n_video);
2628 GST_PLAY_BIN_UNLOCK (playbin);
2631 case PROP_CURRENT_VIDEO:
2632 GST_PLAY_BIN_LOCK (playbin);
2633 g_value_set_int (value, playbin->current_video);
2634 GST_PLAY_BIN_UNLOCK (playbin);
2638 GstSourceGroup *group;
2641 GST_PLAY_BIN_LOCK (playbin);
2642 group = get_group (playbin);
2643 n_audio = (group->audio_channels ? group->audio_channels->len : 0);
2644 g_value_set_int (value, n_audio);
2645 GST_PLAY_BIN_UNLOCK (playbin);
2648 case PROP_CURRENT_AUDIO:
2649 GST_PLAY_BIN_LOCK (playbin);
2650 g_value_set_int (value, playbin->current_audio);
2651 GST_PLAY_BIN_UNLOCK (playbin);
2655 GstSourceGroup *group;
2658 GST_PLAY_BIN_LOCK (playbin);
2659 group = get_group (playbin);
2660 n_text = (group->text_channels ? group->text_channels->len : 0);
2661 g_value_set_int (value, n_text);
2662 GST_PLAY_BIN_UNLOCK (playbin);
2665 case PROP_CURRENT_TEXT:
2666 GST_PLAY_BIN_LOCK (playbin);
2667 g_value_set_int (value, playbin->current_text);
2668 GST_PLAY_BIN_UNLOCK (playbin);
2670 case PROP_SUBTITLE_ENCODING:
2671 GST_PLAY_BIN_LOCK (playbin);
2672 g_value_take_string (value,
2673 gst_play_sink_get_subtitle_encoding (playbin->playsink));
2674 GST_PLAY_BIN_UNLOCK (playbin);
2676 case PROP_VIDEO_FILTER:
2677 g_value_take_object (value,
2678 gst_play_sink_get_filter (playbin->playsink,
2679 GST_PLAY_SINK_TYPE_VIDEO));
2681 case PROP_AUDIO_FILTER:
2682 g_value_take_object (value,
2683 gst_play_sink_get_filter (playbin->playsink,
2684 GST_PLAY_SINK_TYPE_AUDIO));
2686 case PROP_VIDEO_SINK:
2687 g_value_take_object (value,
2688 gst_play_bin_get_current_sink (playbin, &playbin->video_sink,
2689 "video", GST_PLAY_SINK_TYPE_VIDEO));
2691 case PROP_AUDIO_SINK:
2692 g_value_take_object (value,
2693 gst_play_bin_get_current_sink (playbin, &playbin->audio_sink,
2694 "audio", GST_PLAY_SINK_TYPE_AUDIO));
2696 case PROP_VIS_PLUGIN:
2697 g_value_take_object (value,
2698 gst_play_sink_get_vis_plugin (playbin->playsink));
2700 case PROP_TEXT_SINK:
2701 g_value_take_object (value,
2702 gst_play_bin_get_current_sink (playbin, &playbin->text_sink,
2703 "text", GST_PLAY_SINK_TYPE_TEXT));
2705 case PROP_VIDEO_STREAM_COMBINER:
2706 g_value_take_object (value,
2707 gst_play_bin_get_current_stream_combiner (playbin,
2708 &playbin->video_stream_combiner, "video", PLAYBIN_STREAM_VIDEO));
2710 case PROP_AUDIO_STREAM_COMBINER:
2711 g_value_take_object (value,
2712 gst_play_bin_get_current_stream_combiner (playbin,
2713 &playbin->audio_stream_combiner, "audio", PLAYBIN_STREAM_AUDIO));
2715 case PROP_TEXT_STREAM_COMBINER:
2716 g_value_take_object (value,
2717 gst_play_bin_get_current_stream_combiner (playbin,
2718 &playbin->text_stream_combiner, "text", PLAYBIN_STREAM_TEXT));
2721 g_value_set_double (value, gst_play_sink_get_volume (playbin->playsink));
2724 g_value_set_boolean (value, gst_play_sink_get_mute (playbin->playsink));
2727 gst_value_take_sample (value,
2728 gst_play_sink_get_last_sample (playbin->playsink));
2730 case PROP_FONT_DESC:
2731 g_value_take_string (value,
2732 gst_play_sink_get_font_desc (playbin->playsink));
2734 case PROP_CONNECTION_SPEED:
2735 GST_PLAY_BIN_LOCK (playbin);
2736 g_value_set_uint64 (value, playbin->connection_speed / 1000);
2737 GST_PLAY_BIN_UNLOCK (playbin);
2739 case PROP_BUFFER_SIZE:
2740 GST_OBJECT_LOCK (playbin);
2741 g_value_set_int (value, playbin->buffer_size);
2742 GST_OBJECT_UNLOCK (playbin);
2744 case PROP_BUFFER_DURATION:
2745 GST_OBJECT_LOCK (playbin);
2746 g_value_set_int64 (value, playbin->buffer_duration);
2747 GST_OBJECT_UNLOCK (playbin);
2749 case PROP_AV_OFFSET:
2750 g_value_set_int64 (value,
2751 gst_play_sink_get_av_offset (playbin->playsink));
2753 case PROP_TEXT_OFFSET:
2754 g_value_set_int64 (value,
2755 gst_play_sink_get_text_offset (playbin->playsink));
2757 case PROP_RING_BUFFER_MAX_SIZE:
2758 g_value_set_uint64 (value, playbin->ring_buffer_max_size);
2760 case PROP_FORCE_ASPECT_RATIO:{
2763 g_object_get (playbin->playsink, "force-aspect-ratio", &v, NULL);
2764 g_value_set_boolean (value, v);
2767 case PROP_MULTIVIEW_MODE:
2768 GST_OBJECT_LOCK (playbin);
2769 g_value_set_enum (value, playbin->multiview_mode);
2770 GST_OBJECT_UNLOCK (playbin);
2772 case PROP_MULTIVIEW_FLAGS:
2773 GST_OBJECT_LOCK (playbin);
2774 g_value_set_flags (value, playbin->multiview_flags);
2775 GST_OBJECT_UNLOCK (playbin);
2778 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
2784 gst_play_bin_update_cached_duration_from_query (GstPlayBin * playbin,
2785 gboolean valid, GstQuery * query)
2791 GST_DEBUG_OBJECT (playbin, "Updating cached duration from query");
2792 gst_query_parse_duration (query, &fmt, &duration);
2794 for (i = 0; i < G_N_ELEMENTS (playbin->duration); i++) {
2795 if (playbin->duration[i].format == 0 || fmt == playbin->duration[i].format) {
2796 playbin->duration[i].valid = valid;
2797 playbin->duration[i].format = fmt;
2798 playbin->duration[i].duration = valid ? duration : -1;
2805 gst_play_bin_update_cached_duration (GstPlayBin * playbin)
2807 const GstFormat formats[] =
2808 { GST_FORMAT_TIME, GST_FORMAT_BYTES, GST_FORMAT_DEFAULT };
2813 GST_DEBUG_OBJECT (playbin, "Updating cached durations before group switch");
2814 for (i = 0; i < G_N_ELEMENTS (formats); i++) {
2815 query = gst_query_new_duration (formats[i]);
2817 GST_ELEMENT_CLASS (parent_class)->query (GST_ELEMENT_CAST (playbin),
2819 gst_play_bin_update_cached_duration_from_query (playbin, ret, query);
2820 gst_query_unref (query);
2825 gst_play_bin_query (GstElement * element, GstQuery * query)
2827 GstPlayBin *playbin = GST_PLAY_BIN (element);
2830 /* During a group switch we shouldn't allow duration queries
2831 * because it's not clear if the old or new group's duration
2832 * is returned and if the sinks are already playing new data
2833 * or old data. See bug #585969
2835 * While we're at it, also don't do any other queries during
2836 * a group switch or any other event that causes topology changes
2837 * by taking the playbin lock in any case.
2839 GST_PLAY_BIN_LOCK (playbin);
2841 if (GST_QUERY_TYPE (query) == GST_QUERY_DURATION) {
2842 GstSourceGroup *group = playbin->curr_group;
2845 GST_SOURCE_GROUP_LOCK (group);
2847 pending = group->pending || group->stream_changed_pending;
2854 gst_query_parse_duration (query, &fmt, NULL);
2855 for (i = 0; i < G_N_ELEMENTS (playbin->duration); i++) {
2856 if (fmt == playbin->duration[i].format) {
2857 ret = playbin->duration[i].valid;
2858 gst_query_set_duration (query, fmt,
2859 (ret ? playbin->duration[i].duration : -1));
2863 /* if nothing cached yet, we might as well request duration,
2864 * such as during initial startup */
2866 GST_DEBUG_OBJECT (playbin,
2867 "Taking cached duration because of pending group switch: %d", ret);
2868 GST_SOURCE_GROUP_UNLOCK (group);
2869 GST_PLAY_BIN_UNLOCK (playbin);
2873 GST_SOURCE_GROUP_UNLOCK (group);
2876 ret = GST_ELEMENT_CLASS (parent_class)->query (element, query);
2878 if (GST_QUERY_TYPE (query) == GST_QUERY_DURATION)
2879 gst_play_bin_update_cached_duration_from_query (playbin, ret, query);
2880 GST_PLAY_BIN_UNLOCK (playbin);
2885 /* mime types we are not handling on purpose right now, don't post a
2886 * missing-plugin message for these */
2887 static const gchar *blacklisted_mimes[] = {
2892 gst_play_bin_handle_message (GstBin * bin, GstMessage * msg)
2894 GstPlayBin *playbin = GST_PLAY_BIN (bin);
2895 GstSourceGroup *group;
2897 if (gst_is_missing_plugin_message (msg)) {
2901 detail = gst_missing_plugin_message_get_installer_detail (msg);
2902 for (i = 0; detail != NULL && blacklisted_mimes[i] != NULL; ++i) {
2903 if (strstr (detail, "|decoder-") && strstr (detail, blacklisted_mimes[i])) {
2904 GST_LOG_OBJECT (bin, "suppressing message %" GST_PTR_FORMAT, msg);
2905 gst_message_unref (msg);
2911 } else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ASYNC_START ||
2912 GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ASYNC_DONE) {
2913 GstObject *src = GST_OBJECT_CAST (msg->src);
2915 /* Ignore async state changes from the uridecodebin children,
2916 * see bug #602000. */
2917 group = playbin->curr_group;
2919 ((group->uridecodebin && src == GST_OBJECT_CAST (group->uridecodebin))
2920 || (group->suburidecodebin
2921 && src == GST_OBJECT_CAST (group->suburidecodebin)))) {
2922 GST_DEBUG_OBJECT (playbin,
2923 "Ignoring async state change of uridecodebin: %s",
2924 GST_OBJECT_NAME (src));
2925 gst_message_unref (msg);
2928 } else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_STREAM_START) {
2929 GstSourceGroup *new_group = playbin->curr_group;
2930 GstMessage *buffering_msg = NULL;
2932 GST_SOURCE_GROUP_LOCK (new_group);
2933 new_group->stream_changed_pending = FALSE;
2934 if (new_group->pending_buffering_msg) {
2935 buffering_msg = new_group->pending_buffering_msg;
2936 new_group->pending_buffering_msg = NULL;
2938 GST_SOURCE_GROUP_UNLOCK (new_group);
2940 GST_DEBUG_OBJECT (playbin, "Stream start from new group %p", new_group);
2942 if (buffering_msg) {
2943 GST_DEBUG_OBJECT (playbin, "Posting pending buffering message: %"
2944 GST_PTR_FORMAT, buffering_msg);
2945 GST_BIN_CLASS (parent_class)->handle_message (bin, buffering_msg);
2948 } else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_BUFFERING) {
2949 GstSourceGroup *group = playbin->curr_group;
2952 /* drop buffering messages from child queues while we are switching
2953 * groups (because the application set a new uri in about-to-finish)
2954 * if the playsink queue still has buffers to play */
2956 GST_SOURCE_GROUP_LOCK (group);
2957 pending = group->stream_changed_pending;
2960 GST_DEBUG_OBJECT (playbin, "Storing buffering message from pending group "
2961 "%p %" GST_PTR_FORMAT, group, msg);
2962 gst_message_replace (&group->pending_buffering_msg, msg);
2963 gst_message_unref (msg);
2966 GST_SOURCE_GROUP_UNLOCK (group);
2967 } else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
2968 /* If we get an error of the subtitle uridecodebin transform
2969 * them into warnings and disable the subtitles */
2970 group = playbin->curr_group;
2971 if (group && group->suburidecodebin) {
2972 if (G_UNLIKELY (gst_object_has_as_ancestor (msg->src, GST_OBJECT_CAST
2973 (group->suburidecodebin)))) {
2975 gchar *debug = NULL;
2976 GstMessage *new_msg;
2978 gboolean done = FALSE;
2979 GValue item = { 0, };
2981 gst_message_parse_error (msg, &err, &debug);
2982 new_msg = gst_message_new_warning (msg->src, err, debug);
2984 gst_message_unref (msg);
2989 REMOVE_SIGNAL (group->suburidecodebin, group->sub_pad_added_id);
2990 REMOVE_SIGNAL (group->suburidecodebin, group->sub_pad_removed_id);
2991 REMOVE_SIGNAL (group->suburidecodebin, group->sub_no_more_pads_id);
2992 REMOVE_SIGNAL (group->suburidecodebin, group->sub_autoplug_continue_id);
2993 REMOVE_SIGNAL (group->suburidecodebin, group->sub_autoplug_query_id);
2995 it = gst_element_iterate_src_pads (group->suburidecodebin);
2996 while (it && !done) {
2998 GstIteratorResult res;
3000 res = gst_iterator_next (it, &item);
3003 case GST_ITERATOR_DONE:
3006 case GST_ITERATOR_OK:
3007 p = g_value_get_object (&item);
3008 pad_removed_cb (NULL, p, group);
3009 g_value_reset (&item);
3012 case GST_ITERATOR_RESYNC:
3013 gst_iterator_resync (it);
3015 case GST_ITERATOR_ERROR:
3020 g_value_unset (&item);
3022 gst_iterator_free (it);
3024 gst_object_ref (group->suburidecodebin);
3025 gst_bin_remove (bin, group->suburidecodebin);
3026 gst_element_set_locked_state (group->suburidecodebin, FALSE);
3027 gst_object_unref (group->suburidecodebin);
3029 GST_SOURCE_GROUP_LOCK (group);
3030 g_free (group->suburi);
3031 group->suburi = NULL;
3032 GST_SOURCE_GROUP_UNLOCK (group);
3034 if (group->sub_pending) {
3035 group->sub_pending = FALSE;
3036 no_more_pads_cb (NULL, group);
3040 const GstStructure *details = NULL;
3042 gst_message_parse_error_details (msg, &details);
3043 if (details && gst_structure_has_field (details, "redirect-location")) {
3045 const gchar *location =
3046 gst_structure_get_string ((GstStructure *) details,
3047 "redirect-location");
3049 if (gst_uri_is_valid (location)) {
3050 uri = g_strdup (location);
3052 uri = gst_uri_join_strings (group->uri, location);
3055 if (g_strcmp0 (uri, group->uri)) {
3056 GST_PLAY_BIN_LOCK (playbin);
3057 if (playbin->next_group && playbin->next_group->valid) {
3058 GST_DEBUG_OBJECT (playbin,
3059 "User already setup next uri %s, using it",
3060 playbin->next_group->uri);
3062 GST_DEBUG_OBJECT (playbin,
3063 "Using newly configured redirect URI: %s", uri);
3064 gst_play_bin_set_uri (playbin, uri);
3066 GST_PLAY_BIN_UNLOCK (playbin);
3068 setup_next_source (playbin, GST_STATE_PAUSED);
3069 gst_message_unref (msg);
3076 } else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_NEED_CONTEXT) {
3077 const gchar *context_type;
3080 gst_message_parse_context_type (msg, &context_type);
3081 GST_OBJECT_LOCK (playbin);
3082 for (iter = playbin->contexts; iter; iter = g_list_next (iter)) {
3083 GstContext *tmp = iter->data;
3084 const gchar *tmp_type = gst_context_get_context_type (tmp);
3086 if (strcmp (context_type, tmp_type) == 0) {
3087 gst_element_set_context (GST_ELEMENT (GST_MESSAGE_SRC (msg)), tmp);
3091 GST_OBJECT_UNLOCK (playbin);
3093 /* don't need to post upward this if it's answered by us */
3095 gst_message_unref (msg);
3098 } else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_HAVE_CONTEXT) {
3099 GstContext *context;
3101 gst_message_parse_have_context (msg, &context);
3102 gst_play_bin_update_context (playbin, context);
3103 gst_context_unref (context);
3107 GST_BIN_CLASS (parent_class)->handle_message (bin, msg);
3111 gst_play_bin_deep_element_added (GstBin * playbin, GstBin * sub_bin,
3114 GST_LOG_OBJECT (playbin, "element %" GST_PTR_FORMAT " was added to "
3115 "%" GST_PTR_FORMAT, child, sub_bin);
3117 g_signal_emit (playbin, gst_play_bin_signals[SIGNAL_ELEMENT_SETUP], 0, child);
3119 GST_BIN_CLASS (parent_class)->deep_element_added (playbin, sub_bin, child);
3123 combiner_active_pad_changed (GObject * combiner, GParamSpec * pspec,
3124 GstPlayBin * playbin)
3126 const gchar *property;
3127 GstSourceGroup *group;
3128 GstSourceCombine *combine = NULL;
3131 GST_PLAY_BIN_LOCK (playbin);
3132 group = get_group (playbin);
3134 for (i = 0; i < PLAYBIN_STREAM_LAST; i++) {
3135 if (combiner == G_OBJECT (group->combiner[i].combiner)) {
3136 combine = &group->combiner[i];
3140 /* We got a pad-change after our group got switched out; no need to notify */
3142 GST_PLAY_BIN_UNLOCK (playbin);
3146 switch (combine->type) {
3147 case GST_PLAY_SINK_TYPE_VIDEO:
3148 property = "current-video";
3149 playbin->current_video = get_current_stream_number (playbin,
3150 combine, group->video_channels);
3152 if (playbin->video_pending_flush_finish) {
3153 playbin->video_pending_flush_finish = FALSE;
3154 GST_PLAY_BIN_UNLOCK (playbin);
3155 gst_play_bin_send_custom_event (GST_OBJECT (combiner),
3156 "playsink-custom-video-flush-finish");
3160 case GST_PLAY_SINK_TYPE_AUDIO:
3161 property = "current-audio";
3162 playbin->current_audio = get_current_stream_number (playbin,
3163 combine, group->audio_channels);
3165 if (playbin->audio_pending_flush_finish) {
3166 playbin->audio_pending_flush_finish = FALSE;
3167 GST_PLAY_BIN_UNLOCK (playbin);
3168 gst_play_bin_send_custom_event (GST_OBJECT (combiner),
3169 "playsink-custom-audio-flush-finish");
3173 case GST_PLAY_SINK_TYPE_TEXT:
3174 property = "current-text";
3175 playbin->current_text = get_current_stream_number (playbin,
3176 combine, group->text_channels);
3178 if (playbin->text_pending_flush_finish) {
3179 playbin->text_pending_flush_finish = FALSE;
3180 GST_PLAY_BIN_UNLOCK (playbin);
3181 gst_play_bin_send_custom_event (GST_OBJECT (combiner),
3182 "playsink-custom-subtitle-flush-finish");
3189 GST_PLAY_BIN_UNLOCK (playbin);
3193 g_object_notify (G_OBJECT (playbin), property);
3197 update_video_multiview_caps (GstPlayBin * playbin, GstCaps * caps)
3199 GstVideoMultiviewMode mv_mode;
3200 GstVideoMultiviewMode cur_mv_mode;
3201 guint mv_flags, cur_mv_flags;
3203 const gchar *mview_mode_str;
3206 GST_OBJECT_LOCK (playbin);
3207 mv_mode = (GstVideoMultiviewMode) playbin->multiview_mode;
3208 mv_flags = playbin->multiview_flags;
3209 GST_OBJECT_UNLOCK (playbin);
3211 if (mv_mode == GST_VIDEO_MULTIVIEW_MODE_NONE)
3214 cur_mv_mode = GST_VIDEO_MULTIVIEW_MODE_NONE;
3215 cur_mv_flags = GST_VIDEO_MULTIVIEW_FLAGS_NONE;
3217 s = gst_caps_get_structure (caps, 0);
3219 gst_structure_get_flagset (s, "multiview-flags", &cur_mv_flags, NULL);
3220 if ((mview_mode_str = gst_structure_get_string (s, "multiview-mode")))
3221 cur_mv_mode = gst_video_multiview_mode_from_caps_string (mview_mode_str);
3223 /* We can't override an existing annotated multiview mode, except
3224 * maybe (in the future) we could change some flags. */
3225 if ((gint) cur_mv_mode > GST_VIDEO_MULTIVIEW_MAX_FRAME_PACKING) {
3226 GST_INFO_OBJECT (playbin, "Cannot override existing multiview mode");
3230 mview_mode_str = gst_video_multiview_mode_to_caps_string (mv_mode);
3231 g_assert (mview_mode_str != NULL);
3232 out_caps = gst_caps_copy (caps);
3233 s = gst_caps_get_structure (out_caps, 0);
3235 gst_structure_set (s, "multiview-mode", G_TYPE_STRING, mview_mode_str,
3236 "multiview-flags", GST_TYPE_VIDEO_MULTIVIEW_FLAGSET, mv_flags,
3237 GST_FLAG_SET_MASK_EXACT, NULL);
3242 static GstPadProbeReturn
3243 _uridecodebin_event_probe (GstPad * pad, GstPadProbeInfo * info, gpointer udata)
3245 GstPadProbeReturn ret = GST_PAD_PROBE_OK;
3246 GstSourceGroup *group = udata;
3247 GstEvent *event = GST_PAD_PROBE_INFO_DATA (info);
3248 gboolean suburidecodebin = (GST_PAD_PARENT (pad) == group->suburidecodebin);
3250 if (suburidecodebin) {
3251 /* Drop flushes that we caused from the suburidecodebin */
3252 switch (GST_EVENT_TYPE (event)) {
3253 case GST_EVENT_FLUSH_START:
3254 case GST_EVENT_FLUSH_STOP:
3256 guint32 seqnum = gst_event_get_seqnum (event);
3257 GSList *item = g_slist_find (group->suburi_flushes_to_drop,
3258 GUINT_TO_POINTER (seqnum));
3260 if (GST_EVENT_TYPE (event) == GST_EVENT_FLUSH_STOP) {
3261 group->suburi_flushes_to_drop =
3262 g_slist_delete_link (group->suburi_flushes_to_drop, item);
3271 switch (GST_EVENT_TYPE (event)) {
3272 case GST_EVENT_STREAM_START:{
3275 GST_SOURCE_GROUP_LOCK (group);
3276 if (gst_event_parse_group_id (event, &group_id)) {
3277 if (group->have_group_id) {
3278 if (group->group_id != group_id) {
3279 event = gst_event_copy (event);
3280 gst_event_set_group_id (event, group->group_id);
3281 gst_event_replace ((GstEvent **) & info->data, event);
3282 gst_event_unref (event);
3285 group->group_id = group_id;
3286 group->have_group_id = TRUE;
3289 GST_FIXME_OBJECT (pad,
3290 "Consider implementing group-id handling on stream-start event");
3292 if (!group->have_group_id) {
3293 group->group_id = gst_util_group_id_next ();
3294 group->have_group_id = TRUE;
3297 event = gst_event_copy (event);
3298 gst_event_set_group_id (event, group->group_id);
3299 gst_event_replace ((GstEvent **) & info->data, event);
3300 gst_event_unref (event);
3302 GST_SOURCE_GROUP_UNLOCK (group);
3305 case GST_EVENT_CAPS:{
3306 GstCaps *caps = NULL;
3307 const GstStructure *s;
3310 gst_event_parse_caps (event, &caps);
3311 /* If video caps, check if we should override multiview flags */
3312 s = gst_caps_get_structure (caps, 0);
3313 name = gst_structure_get_name (s);
3314 if (g_str_has_prefix (name, "video/")) {
3315 caps = update_video_multiview_caps (group->playbin, caps);
3317 gst_event_unref (event);
3318 event = gst_event_new_caps (caps);
3319 GST_PAD_PROBE_INFO_DATA (info) = event;
3320 gst_caps_unref (caps);
3332 /* helper function to lookup stuff in lists */
3334 array_has_value (const gchar * values[], const gchar * value, gboolean exact)
3338 for (i = 0; values[i]; i++) {
3339 if (exact && !strcmp (value, values[i]))
3341 if (!exact && g_str_has_prefix (value, values[i]))
3349 GstPlayBin *playbin;
3351 GstPlaySinkType type;
3355 notify_tags_cb (GObject * object, GParamSpec * pspec, gpointer user_data)
3357 NotifyTagsData *ntdata = (NotifyTagsData *) user_data;
3360 GST_DEBUG_OBJECT (ntdata->playbin, "Tags on pad %" GST_PTR_FORMAT
3361 " with stream id %d and type %d have changed",
3362 object, ntdata->stream_id, ntdata->type);
3364 switch (ntdata->type) {
3365 case GST_PLAY_SINK_TYPE_VIDEO:
3366 signal = SIGNAL_VIDEO_TAGS_CHANGED;
3368 case GST_PLAY_SINK_TYPE_AUDIO:
3369 signal = SIGNAL_AUDIO_TAGS_CHANGED;
3371 case GST_PLAY_SINK_TYPE_TEXT:
3372 signal = SIGNAL_TEXT_TAGS_CHANGED;
3380 g_signal_emit (G_OBJECT (ntdata->playbin), gst_play_bin_signals[signal], 0,
3384 /* this function is called when a new pad is added to decodebin. We check the
3385 * type of the pad and add it to the combiner element of the group.
3388 pad_added_cb (GstElement * decodebin, GstPad * pad, GstSourceGroup * group)
3390 GstPlayBin *playbin;
3392 const GstStructure *s;
3395 GstPadLinkReturn res;
3396 GstSourceCombine *combine = NULL;
3398 gboolean changed = FALSE;
3399 GstElement *custom_combiner = NULL;
3400 gulong group_id_probe_handler;
3402 playbin = group->playbin;
3404 GST_PLAY_BIN_SHUTDOWN_LOCK (playbin, shutdown);
3406 caps = gst_pad_get_current_caps (pad);
3408 caps = gst_pad_query_caps (pad, NULL);
3409 s = gst_caps_get_structure (caps, 0);
3410 name = gst_structure_get_name (s);
3412 GST_DEBUG_OBJECT (playbin,
3413 "pad %s:%s with caps %" GST_PTR_FORMAT " added in group %p",
3414 GST_DEBUG_PAD_NAME (pad), caps, group);
3416 /* major type of the pad, this determines the combiner to use,
3417 try exact match first */
3418 for (pass = 0; !combine && pass < 2; pass++) {
3419 for (i = 0; i < PLAYBIN_STREAM_LAST; i++) {
3420 if (array_has_value (group->combiner[i].media_list, name, pass == 0)) {
3421 combine = &group->combiner[i];
3423 } else if (group->combiner[i].get_media_caps) {
3424 GstCaps *media_caps = group->combiner[i].get_media_caps ();
3426 if (media_caps && gst_caps_can_intersect (media_caps, caps)) {
3427 combine = &group->combiner[i];
3428 gst_caps_unref (media_caps);
3431 gst_caps_unref (media_caps);
3434 /* get custom stream combiner if there is one */
3436 if (i == PLAYBIN_STREAM_AUDIO) {
3437 custom_combiner = playbin->audio_stream_combiner;
3438 } else if (i == PLAYBIN_STREAM_TEXT) {
3439 custom_combiner = playbin->text_stream_combiner;
3440 } else if (i == PLAYBIN_STREAM_VIDEO) {
3441 custom_combiner = playbin->video_stream_combiner;
3445 /* no combiner found for the media type, don't bother linking it to a
3446 * combiner. This will leave the pad unlinked and thus ignored. */
3447 if (combine == NULL) {
3448 GST_PLAY_BIN_SHUTDOWN_UNLOCK (playbin);
3452 GST_SOURCE_GROUP_LOCK (group);
3453 if (combine->combiner == NULL && playbin->have_selector) {
3454 /* no combiner, create one */
3455 GST_DEBUG_OBJECT (playbin, "creating new input selector");
3456 if (custom_combiner)
3457 combine->combiner = custom_combiner;
3459 combine->combiner = gst_element_factory_make ("input-selector", NULL);
3461 if (combine->combiner == NULL) {
3462 /* post the missing input-selector message only once */
3463 playbin->have_selector = FALSE;
3464 gst_element_post_message (GST_ELEMENT_CAST (playbin),
3465 gst_missing_element_message_new (GST_ELEMENT_CAST (playbin),
3467 GST_ELEMENT_WARNING (playbin, CORE, MISSING_PLUGIN,
3468 (_("Missing element '%s' - check your GStreamer installation."),
3469 "input-selector"), (NULL));
3471 /* find out which properties the stream combiner supports */
3472 combine->has_active_pad =
3473 g_object_class_find_property (G_OBJECT_GET_CLASS (combine->combiner),
3474 "active-pad") != NULL;
3476 if (!custom_combiner) {
3477 /* sync-mode=1, use clock */
3478 if (combine->type == GST_PLAY_SINK_TYPE_TEXT)
3479 g_object_set (combine->combiner, "sync-streams", TRUE,
3480 "sync-mode", 1, "cache-buffers", TRUE, NULL);
3482 g_object_set (combine->combiner, "sync-streams", TRUE, NULL);
3485 if (combine->has_active_pad)
3486 g_signal_connect (combine->combiner, "notify::active-pad",
3487 G_CALLBACK (combiner_active_pad_changed), playbin);
3489 GST_DEBUG_OBJECT (playbin, "adding new stream combiner %p",
3491 gst_element_set_state (combine->combiner, GST_STATE_PAUSED);
3492 gst_bin_add (GST_BIN_CAST (playbin), combine->combiner);
3496 GST_PLAY_BIN_SHUTDOWN_UNLOCK (playbin);
3498 if (combine->srcpad == NULL) {
3499 if (combine->combiner) {
3500 /* save source pad of the combiner */
3501 combine->srcpad = gst_element_get_static_pad (combine->combiner, "src");
3503 /* no combiner, use the pad as the source pad then */
3504 combine->srcpad = gst_object_ref (pad);
3507 /* block the combiner srcpad. It's possible that multiple decodebins start
3508 * pushing data into the combiners before we have a chance to collect all
3509 * streams and connect the sinks, resulting in not-linked errors. After we
3510 * configured the sinks we will unblock them all. */
3511 GST_DEBUG_OBJECT (playbin, "blocking %" GST_PTR_FORMAT, combine->srcpad);
3513 gst_pad_add_probe (combine->srcpad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
3514 block_serialized_data_cb, NULL, NULL);
3517 /* get sinkpad for the new stream */
3518 if (combine->combiner) {
3519 if ((sinkpad = gst_element_get_request_pad (combine->combiner, "sink_%u"))) {
3521 GST_DEBUG_OBJECT (playbin, "got pad %s:%s from combiner",
3522 GST_DEBUG_PAD_NAME (sinkpad));
3524 /* find out which properties the sink pad supports */
3525 combine->has_always_ok =
3526 g_object_class_find_property (G_OBJECT_GET_CLASS (sinkpad),
3527 "always-ok") != NULL;
3529 g_object_class_find_property (G_OBJECT_GET_CLASS (sinkpad),
3532 /* store the combiner for the pad */
3533 g_object_set_data (G_OBJECT (sinkpad), "playbin.combine", combine);
3535 if (combine->has_tags) {
3536 gulong notify_tags_handler = 0;
3537 NotifyTagsData *ntdata;
3539 /* connect to the notify::tags signal for our
3540 * own *-tags-changed signals
3542 ntdata = g_new0 (NotifyTagsData, 1);
3543 ntdata->playbin = playbin;
3544 ntdata->stream_id = combine->channels->len;
3545 ntdata->type = combine->type;
3547 notify_tags_handler =
3548 g_signal_connect_data (G_OBJECT (sinkpad), "notify::tags",
3549 G_CALLBACK (notify_tags_cb), ntdata, (GClosureNotify) g_free,
3551 g_object_set_data (G_OBJECT (sinkpad), "playbin.notify_tags_handler",
3552 ULONG_TO_POINTER (notify_tags_handler));
3555 /* store the pad in the array */
3556 GST_DEBUG_OBJECT (playbin, "pad %p added to array", sinkpad);
3557 g_ptr_array_add (combine->channels, sinkpad);
3559 res = gst_pad_link (pad, sinkpad);
3560 if (GST_PAD_LINK_FAILED (res))
3563 /* store combiner pad so we can release it */
3564 g_object_set_data (G_OBJECT (pad), "playbin.sinkpad", sinkpad);
3567 GST_DEBUG_OBJECT (playbin, "linked pad %s:%s to combiner %p",
3568 GST_DEBUG_PAD_NAME (pad), combine->combiner);
3570 goto request_pad_failed;
3573 /* no combiner, don't configure anything, we'll link the new pad directly to
3578 /* store the combiner for the pad */
3579 g_object_set_data (G_OBJECT (pad), "playbin.combine", combine);
3581 GST_SOURCE_GROUP_UNLOCK (group);
3583 group_id_probe_handler =
3584 gst_pad_add_probe (pad, GST_PAD_PROBE_TYPE_EVENT_DOWNSTREAM,
3585 _uridecodebin_event_probe, group, NULL);
3586 g_object_set_data (G_OBJECT (pad), "playbin.event_probe_id",
3587 ULONG_TO_POINTER (group_id_probe_handler));
3592 switch (combine->type) {
3593 case GST_PLAY_SINK_TYPE_VIDEO:
3594 signal = SIGNAL_VIDEO_CHANGED;
3596 case GST_PLAY_SINK_TYPE_AUDIO:
3597 signal = SIGNAL_AUDIO_CHANGED;
3599 case GST_PLAY_SINK_TYPE_TEXT:
3600 signal = SIGNAL_TEXT_CHANGED;
3607 /* we want to return NOT_LINKED for unselected pads but only for pads
3608 * from the normal uridecodebin. This makes sure that subtitle streams
3609 * are not raced past audio/video from decodebin's multiqueue.
3610 * For pads from suburidecodebin OK should always be returned, otherwise
3611 * it will most likely stop. */
3612 if (combine->has_always_ok) {
3613 gboolean always_ok = (decodebin == group->suburidecodebin);
3614 g_object_set (sinkpad, "always-ok", always_ok, NULL);
3616 g_signal_emit (G_OBJECT (playbin), gst_play_bin_signals[signal], 0, NULL);
3621 gst_caps_unref (caps);
3627 GST_ERROR_OBJECT (playbin, "unknown type %s for pad %s:%s",
3628 name, GST_DEBUG_PAD_NAME (pad));
3633 GST_ERROR_OBJECT (playbin,
3634 "failed to link pad %s:%s to combiner, reason %s (%d)",
3635 GST_DEBUG_PAD_NAME (pad), gst_pad_link_get_name (res), res);
3636 GST_SOURCE_GROUP_UNLOCK (group);
3640 GST_ELEMENT_ERROR (playbin, CORE, PAD,
3641 ("Internal playbin error."),
3642 ("Failed to get request pad from combiner %p.", combine->combiner));
3643 GST_SOURCE_GROUP_UNLOCK (group);
3647 GST_DEBUG ("ignoring, we are shutting down. Pad will be left unlinked");
3648 /* not going to done as we didn't request the caps */
3653 /* called when a pad is removed from the uridecodebin. We unlink the pad from
3654 * the combiner. This will make the combiner select a new pad. */
3656 pad_removed_cb (GstElement * decodebin, GstPad * pad, GstSourceGroup * group)
3658 GstPlayBin *playbin;
3660 GstElement *combiner;
3661 GstSourceCombine *combine;
3663 gulong group_id_probe_handler;
3665 playbin = group->playbin;
3667 GST_DEBUG_OBJECT (playbin,
3668 "pad %s:%s removed from group %p", GST_DEBUG_PAD_NAME (pad), group);
3670 GST_SOURCE_GROUP_LOCK (group);
3672 if ((group_id_probe_handler =
3673 POINTER_TO_ULONG (g_object_get_data (G_OBJECT (pad),
3674 "playbin.event_probe_id")))) {
3675 gst_pad_remove_probe (pad, group_id_probe_handler);
3676 g_object_set_data (G_OBJECT (pad), "playbin.event_probe_id", NULL);
3679 if ((combine = g_object_get_data (G_OBJECT (pad), "playbin.combine"))) {
3680 g_assert (combine->combiner == NULL);
3681 g_assert (combine->srcpad == pad);
3682 source_combine_remove_pads (playbin, combine);
3686 /* get the combiner sinkpad */
3687 if (!(peer = g_object_get_data (G_OBJECT (pad), "playbin.sinkpad")))
3690 /* unlink the pad now (can fail, the pad is unlinked before it's removed) */
3691 gst_pad_unlink (pad, peer);
3694 combiner = GST_ELEMENT_CAST (gst_pad_get_parent (peer));
3695 g_assert (combiner != NULL);
3697 if ((combine = g_object_get_data (G_OBJECT (peer), "playbin.combine"))) {
3698 if (combine->has_tags) {
3699 gulong notify_tags_handler;
3701 notify_tags_handler =
3702 POINTER_TO_ULONG (g_object_get_data (G_OBJECT (peer),
3703 "playbin.notify_tags_handler"));
3704 if (notify_tags_handler != 0)
3705 g_signal_handler_disconnect (G_OBJECT (peer), notify_tags_handler);
3706 g_object_set_data (G_OBJECT (peer), "playbin.notify_tags_handler", NULL);
3709 /* remove the pad from the array */
3710 g_ptr_array_remove (combine->channels, peer);
3711 GST_DEBUG_OBJECT (playbin, "pad %p removed from array", peer);
3713 /* get the correct type-changed signal */
3714 switch (combine->type) {
3715 case GST_PLAY_SINK_TYPE_VIDEO:
3716 signal = SIGNAL_VIDEO_CHANGED;
3718 case GST_PLAY_SINK_TYPE_AUDIO:
3719 signal = SIGNAL_AUDIO_CHANGED;
3721 case GST_PLAY_SINK_TYPE_TEXT:
3722 signal = SIGNAL_TEXT_CHANGED;
3728 if (!combine->channels->len && combine->combiner) {
3729 GST_DEBUG_OBJECT (playbin, "all combiner sinkpads removed");
3730 GST_DEBUG_OBJECT (playbin, "removing combiner %p", combine->combiner);
3731 source_combine_remove_pads (playbin, combine);
3732 gst_element_set_state (combine->combiner, GST_STATE_NULL);
3733 gst_bin_remove (GST_BIN_CAST (playbin), combine->combiner);
3734 combine->combiner = NULL;
3738 /* release the pad to the combiner, this will make the combiner choose a new
3740 gst_element_release_request_pad (combiner, peer);
3741 gst_object_unref (peer);
3743 gst_object_unref (combiner);
3745 GST_SOURCE_GROUP_UNLOCK (group);
3748 g_signal_emit (G_OBJECT (playbin), gst_play_bin_signals[signal], 0, NULL);
3755 GST_DEBUG_OBJECT (playbin, "pad not linked");
3760 /* we get called when all pads are available and we must connect the sinks to
3762 * The main purpose of the code is to see if we have video/audio and subtitles
3763 * and pick the right pipelines to display them.
3765 * The combiners installed on the group tell us about the presence of
3766 * audio/video and subtitle streams. This allows us to see if we need
3767 * visualisation, video or/and audio.
3770 no_more_pads_cb (GstElement * decodebin, GstSourceGroup * group)
3772 GstPlayBin *playbin;
3773 GstPadLinkReturn res;
3777 playbin = group->playbin;
3779 GST_DEBUG_OBJECT (playbin, "no more pads in group %p", group);
3781 GST_PLAY_BIN_SHUTDOWN_LOCK (playbin, shutdown);
3783 GST_SOURCE_GROUP_LOCK (group);
3784 for (i = 0; i < PLAYBIN_STREAM_LAST; i++) {
3785 GstSourceCombine *combine = &group->combiner[i];
3787 /* check if the specific media type was detected and thus has a combiner
3788 * created for it. If there is the media type, get a sinkpad from the sink
3789 * and link it. We only do this if we have not yet requested the sinkpad
3791 if (combine->srcpad && combine->sinkpad == NULL) {
3792 GST_DEBUG_OBJECT (playbin, "requesting new sink pad %d", combine->type);
3794 gst_play_sink_request_pad (playbin->playsink, combine->type);
3795 gst_object_ref (combine->sinkpad);
3796 } else if (combine->srcpad && combine->sinkpad) {
3797 GST_DEBUG_OBJECT (playbin, "refreshing new sink pad %d", combine->type);
3798 gst_play_sink_refresh_pad (playbin->playsink, combine->sinkpad,
3800 } else if (combine->sinkpad && combine->srcpad == NULL) {
3801 GST_DEBUG_OBJECT (playbin, "releasing sink pad %d", combine->type);
3802 gst_play_sink_release_pad (playbin->playsink, combine->sinkpad);
3803 gst_object_unref (combine->sinkpad);
3804 combine->sinkpad = NULL;
3806 if (combine->sinkpad && combine->srcpad &&
3807 !gst_pad_is_linked (combine->srcpad)) {
3808 res = gst_pad_link (combine->srcpad, combine->sinkpad);
3809 GST_DEBUG_OBJECT (playbin, "linked type %s, result: %d",
3810 combine->media_list[0], res);
3811 if (res != GST_PAD_LINK_OK) {
3812 GST_ELEMENT_ERROR (playbin, CORE, PAD,
3813 ("Internal playbin error."),
3814 ("Failed to link combiner to sink. Error %d", res));
3818 GST_DEBUG_OBJECT (playbin, "pending %d > %d", group->pending,
3819 group->pending - 1);
3821 if (group->pending > 0)
3824 if (group->suburidecodebin == decodebin)
3825 group->sub_pending = FALSE;
3827 if (group->pending == 0) {
3828 /* we are the last group to complete, we will configure the output and then
3829 * signal the other waiters. */
3830 GST_LOG_OBJECT (playbin, "last group complete");
3833 GST_LOG_OBJECT (playbin, "have more pending groups");
3836 GST_SOURCE_GROUP_UNLOCK (group);
3839 /* if we have custom sinks, configure them now */
3840 GST_SOURCE_GROUP_LOCK (group);
3842 if (group->audio_sink) {
3843 GST_INFO_OBJECT (playbin, "setting custom audio sink %" GST_PTR_FORMAT,
3845 gst_play_sink_set_sink (playbin->playsink, GST_PLAY_SINK_TYPE_AUDIO,
3849 if (group->video_sink) {
3850 GST_INFO_OBJECT (playbin, "setting custom video sink %" GST_PTR_FORMAT,
3852 gst_play_sink_set_sink (playbin->playsink, GST_PLAY_SINK_TYPE_VIDEO,
3856 if (group->text_sink) {
3857 GST_INFO_OBJECT (playbin, "setting custom text sink %" GST_PTR_FORMAT,
3859 gst_play_sink_set_sink (playbin->playsink, GST_PLAY_SINK_TYPE_TEXT,
3863 GST_SOURCE_GROUP_UNLOCK (group);
3865 /* signal the other decodebins that they can continue now. */
3866 GST_SOURCE_GROUP_LOCK (group);
3867 /* unblock all combiners */
3868 for (i = 0; i < PLAYBIN_STREAM_LAST; i++) {
3869 GstSourceCombine *combine = &group->combiner[i];
3871 if (combine->srcpad) {
3872 GST_DEBUG_OBJECT (playbin, "unblocking %" GST_PTR_FORMAT,
3874 if (combine->block_id) {
3875 gst_pad_remove_probe (combine->srcpad, combine->block_id);
3876 combine->block_id = 0;
3880 GST_SOURCE_GROUP_UNLOCK (group);
3881 gst_play_sink_reconfigure (playbin->playsink);
3884 GST_PLAY_BIN_SHUTDOWN_UNLOCK (playbin);
3887 do_async_done (playbin);
3894 GST_DEBUG ("ignoring, we are shutting down");
3895 /* Request a flushing pad from playsink that we then link to the combiner.
3896 * Then we unblock the combiners so that they stop with a WRONG_STATE
3897 * instead of a NOT_LINKED error.
3899 GST_SOURCE_GROUP_LOCK (group);
3900 for (i = 0; i < PLAYBIN_STREAM_LAST; i++) {
3901 GstSourceCombine *combine = &group->combiner[i];
3903 if (combine->srcpad) {
3904 if (combine->sinkpad == NULL) {
3905 GST_DEBUG_OBJECT (playbin, "requesting new flushing sink pad");
3907 gst_play_sink_request_pad (playbin->playsink,
3908 GST_PLAY_SINK_TYPE_FLUSHING);
3909 gst_object_ref (combine->sinkpad);
3910 res = gst_pad_link (combine->srcpad, combine->sinkpad);
3911 GST_DEBUG_OBJECT (playbin, "linked flushing, result: %d", res);
3913 GST_DEBUG_OBJECT (playbin, "unblocking %" GST_PTR_FORMAT,
3915 if (combine->block_id) {
3916 gst_pad_remove_probe (combine->srcpad, combine->block_id);
3917 combine->block_id = 0;
3921 GST_SOURCE_GROUP_UNLOCK (group);
3927 drained_cb (GstElement * decodebin, GstSourceGroup * group)
3929 GstPlayBin *playbin;
3931 playbin = group->playbin;
3933 GST_DEBUG_OBJECT (playbin, "about to finish in group %p", group);
3935 /* after this call, we should have a next group to activate or we EOS */
3936 g_signal_emit (G_OBJECT (playbin),
3937 gst_play_bin_signals[SIGNAL_ABOUT_TO_FINISH], 0, NULL);
3939 /* now activate the next group. If the app did not set a uri, this will
3940 * fail and we can do EOS */
3941 setup_next_source (playbin, GST_STATE_PAUSED);
3944 /* Like gst_element_factory_can_sink_any_caps() but doesn't
3945 * allow ANY caps on the sinkpad template */
3947 _factory_can_sink_caps (GstElementFactory * factory, GstCaps * caps)
3949 const GList *templs;
3951 templs = gst_element_factory_get_static_pad_templates (factory);
3954 GstStaticPadTemplate *templ = (GstStaticPadTemplate *) templs->data;
3956 if (templ->direction == GST_PAD_SINK) {
3957 GstCaps *templcaps = gst_static_caps_get (&templ->static_caps);
3959 if (!gst_caps_is_any (templcaps)
3960 && gst_caps_is_subset (caps, templcaps)) {
3961 gst_caps_unref (templcaps);
3964 gst_caps_unref (templcaps);
3966 templs = g_list_next (templs);
3973 avelements_free (gpointer avelement)
3975 GstAVElement *elm = (GstAVElement *) avelement;
3978 gst_object_unref (elm->dec);
3980 gst_object_unref (elm->sink);
3981 g_slice_free (GstAVElement, elm);
3985 avelement_compare_decoder (gconstpointer p1, gconstpointer p2,
3988 GstAVElement *v1, *v2;
3990 v1 = (GstAVElement *) p1;
3991 v2 = (GstAVElement *) p2;
3993 return strcmp (GST_OBJECT_NAME (v1->dec), GST_OBJECT_NAME (v2->dec));
3997 avelement_lookup_decoder (gconstpointer p1, gconstpointer p2,
4001 GstElementFactory *f2;
4003 v1 = (GstAVElement *) p1;
4004 f2 = (GstElementFactory *) p2;
4006 return strcmp (GST_OBJECT_NAME (v1->dec), GST_OBJECT_NAME (f2));
4010 avelement_compare (gconstpointer p1, gconstpointer p2)
4012 GstAVElement *v1, *v2;
4013 GstPluginFeature *fd1, *fd2, *fs1, *fs2;
4014 gint64 diff, v1_rank, v2_rank;
4016 v1 = (GstAVElement *) p1;
4017 v2 = (GstAVElement *) p2;
4019 fd1 = (GstPluginFeature *) v1->dec;
4020 fd2 = (GstPluginFeature *) v2->dec;
4022 /* If both have a sink, we also compare their ranks */
4023 if (v1->sink && v2->sink) {
4024 fs1 = (GstPluginFeature *) v1->sink;
4025 fs2 = (GstPluginFeature *) v2->sink;
4026 v1_rank = (gint64) gst_plugin_feature_get_rank (fd1) *
4027 gst_plugin_feature_get_rank (fs1);
4028 v2_rank = (gint64) gst_plugin_feature_get_rank (fd2) *
4029 gst_plugin_feature_get_rank (fs2);
4031 v1_rank = gst_plugin_feature_get_rank (fd1);
4032 v2_rank = gst_plugin_feature_get_rank (fd2);
4036 /* comparison based on the rank */
4037 diff = v2_rank - v1_rank;
4043 /* comparison based on number of common caps features */
4044 diff = v2->n_comm_cf - v1->n_comm_cf;
4049 /* comparison based on the name of sink elements */
4050 diff = strcmp (GST_OBJECT_NAME (fs1), GST_OBJECT_NAME (fs2));
4055 /* comparison based on the name of decoder elements */
4056 return strcmp (GST_OBJECT_NAME (fd1), GST_OBJECT_NAME (fd2));
4060 avelements_create (GstPlayBin * playbin, gboolean isaudioelement)
4062 GstElementFactory *d_factory, *s_factory;
4063 GList *dec_list, *sink_list, *dl, *sl;
4064 GSequence *ave_seq = NULL;
4066 guint n_common_cf = 0;
4068 if (isaudioelement) {
4069 sink_list = gst_element_factory_list_get_elements
4070 (GST_ELEMENT_FACTORY_TYPE_SINK |
4071 GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO, GST_RANK_MARGINAL);
4073 gst_element_factory_list_get_elements (GST_ELEMENT_FACTORY_TYPE_DECODER
4074 | GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO, GST_RANK_MARGINAL);
4076 sink_list = gst_element_factory_list_get_elements
4077 (GST_ELEMENT_FACTORY_TYPE_SINK |
4078 GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO |
4079 GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE, GST_RANK_MARGINAL);
4082 gst_element_factory_list_get_elements (GST_ELEMENT_FACTORY_TYPE_DECODER
4083 | GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO |
4084 GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE, GST_RANK_MARGINAL);
4087 /* create a list of audio/video elements. Each element in the list
4088 * is holding an audio/video decoder and an audio/video sink in which
4089 * the decoders srcpad template caps and sink element's sinkpad template
4090 * caps are compatible */
4094 ave_seq = g_sequence_new ((GDestroyNotify) avelements_free);
4096 for (; dl; dl = dl->next) {
4097 d_factory = (GstElementFactory *) dl->data;
4098 for (; sl; sl = sl->next) {
4099 s_factory = (GstElementFactory *) sl->data;
4102 gst_playback_utils_get_n_common_capsfeatures (d_factory, s_factory,
4103 gst_play_bin_get_flags (playbin), isaudioelement);
4104 if (n_common_cf < 1)
4107 ave = g_slice_new (GstAVElement);
4108 ave->dec = gst_object_ref (d_factory);
4109 ave->sink = gst_object_ref (s_factory);
4110 ave->n_comm_cf = n_common_cf;
4111 g_sequence_append (ave_seq, ave);
4115 g_sequence_sort (ave_seq, (GCompareDataFunc) avelement_compare_decoder, NULL);
4117 gst_plugin_feature_list_free (dec_list);
4118 gst_plugin_feature_list_free (sink_list);
4124 avelement_iter_is_equal (GSequenceIter * iter, GstElementFactory * factory)
4131 ave = g_sequence_get (iter);
4135 return strcmp (GST_OBJECT_NAME (ave->dec), GST_OBJECT_NAME (factory)) == 0;
4139 create_decoders_list (GList * factory_list, GSequence * avelements,
4142 GList *dec_list = NULL, *tmp;
4143 GList *ave_list = NULL;
4144 GList *ave_free_list = NULL;
4145 GstAVElement *ave, *best_ave;
4147 g_return_val_if_fail (factory_list != NULL, NULL);
4148 g_return_val_if_fail (avelements != NULL, NULL);
4150 for (tmp = factory_list; tmp; tmp = tmp->next) {
4151 GstElementFactory *factory = (GstElementFactory *) tmp->data;
4153 /* if there are parsers or sink elements, add them first */
4154 if (gst_element_factory_list_is_type (factory,
4155 GST_ELEMENT_FACTORY_TYPE_PARSER) ||
4156 gst_element_factory_list_is_type (factory,
4157 GST_ELEMENT_FACTORY_TYPE_SINK)) {
4158 dec_list = g_list_prepend (dec_list, gst_object_ref (factory));
4159 } else if (!(((flags & GST_PLAY_FLAG_FORCE_SW_DECODERS) != 0)
4160 && gst_element_factory_list_is_type (factory,
4161 GST_ELEMENT_FACTORY_TYPE_HARDWARE))) {
4162 GSequenceIter *seq_iter;
4165 g_sequence_lookup (avelements, factory,
4166 (GCompareDataFunc) avelement_lookup_decoder, NULL);
4168 GstAVElement *ave = g_slice_new0 (GstAVElement);
4172 /* There's at least raw */
4175 ave_list = g_list_prepend (ave_list, ave);
4177 /* We need to free these later */
4178 ave_free_list = g_list_prepend (ave_free_list, ave);
4182 /* Go to first iter with that decoder */
4184 GSequenceIter *tmp_seq_iter;
4186 tmp_seq_iter = g_sequence_iter_prev (seq_iter);
4187 if (!avelement_iter_is_equal (tmp_seq_iter, factory))
4189 seq_iter = tmp_seq_iter;
4190 } while (!g_sequence_iter_is_begin (seq_iter));
4192 /* Get the best ranked GstAVElement for that factory */
4194 while (!g_sequence_iter_is_end (seq_iter)
4195 && avelement_iter_is_equal (seq_iter, factory)) {
4196 ave = g_sequence_get (seq_iter);
4198 if (!best_ave || avelement_compare (ave, best_ave) < 0)
4201 seq_iter = g_sequence_iter_next (seq_iter);
4203 ave_list = g_list_prepend (ave_list, best_ave);
4207 /* Sort all GstAVElements by their relative ranks and insert
4208 * into the decoders list */
4209 ave_list = g_list_sort (ave_list, (GCompareFunc) avelement_compare);
4210 for (tmp = ave_list; tmp; tmp = tmp->next) {
4211 ave = (GstAVElement *) tmp->data;
4212 dec_list = g_list_prepend (dec_list, gst_object_ref (ave->dec));
4214 g_list_free (ave_list);
4215 gst_plugin_feature_list_free (factory_list);
4217 for (tmp = ave_free_list; tmp; tmp = tmp->next)
4218 g_slice_free (GstAVElement, tmp->data);
4219 g_list_free (ave_free_list);
4221 dec_list = g_list_reverse (dec_list);
4226 /* Called when we must provide a list of factories to plug to @pad with @caps.
4227 * We first check if we have a sink that can handle the format and if we do, we
4228 * return NULL, to expose the pad. If we have no sink (or the sink does not
4229 * work), we return the list of elements that can connect. */
4230 static GValueArray *
4231 autoplug_factories_cb (GstElement * decodebin, GstPad * pad,
4232 GstCaps * caps, GstSourceGroup * group)
4234 GstPlayBin *playbin;
4235 GList *factory_list, *tmp;
4236 GValueArray *result;
4237 gboolean unref_caps = FALSE;
4238 gboolean isaudiodeclist = FALSE;
4239 gboolean isvideodeclist = FALSE;
4242 caps = gst_caps_new_any ();
4246 playbin = group->playbin;
4248 GST_DEBUG_OBJECT (playbin, "factories group %p for %s:%s, %" GST_PTR_FORMAT,
4249 group, GST_DEBUG_PAD_NAME (pad), caps);
4251 /* filter out the elements based on the caps. */
4252 g_mutex_lock (&playbin->elements_lock);
4253 gst_play_bin_update_elements_list (playbin);
4255 gst_element_factory_list_filter (playbin->elements, caps, GST_PAD_SINK,
4256 gst_caps_is_fixed (caps));
4257 g_mutex_unlock (&playbin->elements_lock);
4259 GST_DEBUG_OBJECT (playbin, "found factories %p", factory_list);
4260 GST_PLUGIN_FEATURE_LIST_DEBUG (factory_list);
4262 /* check whether the caps are asking for a list of audio/video decoders */
4264 if (!gst_caps_is_any (caps)) {
4265 for (; tmp; tmp = tmp->next) {
4266 GstElementFactory *factory = (GstElementFactory *) tmp->data;
4268 isvideodeclist = gst_element_factory_list_is_type (factory,
4269 GST_ELEMENT_FACTORY_TYPE_DECODER |
4270 GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO |
4271 GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE);
4272 isaudiodeclist = gst_element_factory_list_is_type (factory,
4273 GST_ELEMENT_FACTORY_TYPE_DECODER |
4274 GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO);
4276 if (isaudiodeclist || isvideodeclist)
4281 if (isaudiodeclist || isvideodeclist) {
4282 GSequence **ave_list;
4286 ave_list = &playbin->aelements;
4288 ave_list = &playbin->velements;
4290 flags = gst_play_bin_get_flags (playbin);
4292 g_mutex_lock (&playbin->elements_lock);
4293 /* sort factory_list based on the GstAVElement list priority */
4294 factory_list = create_decoders_list (factory_list, *ave_list, flags);
4295 g_mutex_unlock (&playbin->elements_lock);
4298 /* 2 additional elements for the already set audio/video sinks */
4299 result = g_value_array_new (g_list_length (factory_list) + 2);
4301 /* Check if we already have an audio/video sink and if this is the case
4302 * put it as the first element of the array */
4303 if (group->audio_sink) {
4304 GstElementFactory *factory = gst_element_get_factory (group->audio_sink);
4306 if (factory && _factory_can_sink_caps (factory, caps)) {
4307 GValue val = { 0, };
4309 g_value_init (&val, G_TYPE_OBJECT);
4310 g_value_set_object (&val, factory);
4311 result = g_value_array_append (result, &val);
4312 g_value_unset (&val);
4316 if (group->video_sink) {
4317 GstElementFactory *factory = gst_element_get_factory (group->video_sink);
4319 if (factory && _factory_can_sink_caps (factory, caps)) {
4320 GValue val = { 0, };
4322 g_value_init (&val, G_TYPE_OBJECT);
4323 g_value_set_object (&val, factory);
4324 result = g_value_array_append (result, &val);
4325 g_value_unset (&val);
4329 for (tmp = factory_list; tmp; tmp = tmp->next) {
4330 GstElementFactory *factory = GST_ELEMENT_FACTORY_CAST (tmp->data);
4331 GValue val = { 0, };
4333 if (group->audio_sink && gst_element_factory_list_is_type (factory,
4334 GST_ELEMENT_FACTORY_TYPE_SINK |
4335 GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO)) {
4338 if (group->video_sink && gst_element_factory_list_is_type (factory,
4339 GST_ELEMENT_FACTORY_TYPE_SINK | GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO
4340 | GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE)) {
4344 g_value_init (&val, G_TYPE_OBJECT);
4345 g_value_set_object (&val, factory);
4346 g_value_array_append (result, &val);
4347 g_value_unset (&val);
4349 gst_plugin_feature_list_free (factory_list);
4352 gst_caps_unref (caps);
4358 gst_play_bin_send_event (GstElement * element, GstEvent * event)
4360 GstPlayBin *playbin = GST_PLAY_BIN (element);
4362 /* Send event directly to playsink instead of letting GstBin iterate
4363 * over all sink elements. The latter might send the event multiple times
4364 * in case the SEEK causes a reconfiguration of the pipeline, as can easily
4365 * happen with adaptive streaming demuxers.
4367 * What would then happen is that the iterator would be reset, we send the
4368 * event again, and on the second time it will fail in the majority of cases
4369 * because the pipeline is still being reconfigured
4371 if (GST_EVENT_IS_UPSTREAM (event)) {
4372 return gst_element_send_event (GST_ELEMENT_CAST (playbin->playsink), event);
4375 return GST_ELEMENT_CLASS (parent_class)->send_event (element, event);
4379 gst_play_bin_set_context (GstElement * element, GstContext * context)
4381 GstPlayBin *playbin = GST_PLAY_BIN (element);
4383 /* Proxy contexts to the sinks, they might not be in playsink yet */
4384 GST_PLAY_BIN_LOCK (playbin);
4385 if (playbin->audio_sink)
4386 gst_element_set_context (playbin->audio_sink, context);
4387 if (playbin->video_sink)
4388 gst_element_set_context (playbin->video_sink, context);
4389 if (playbin->text_sink)
4390 gst_element_set_context (playbin->text_sink, context);
4392 GST_SOURCE_GROUP_LOCK (playbin->curr_group);
4394 if (playbin->curr_group->audio_sink)
4395 gst_element_set_context (playbin->curr_group->audio_sink, context);
4396 if (playbin->curr_group->video_sink)
4397 gst_element_set_context (playbin->curr_group->video_sink, context);
4398 if (playbin->curr_group->text_sink)
4399 gst_element_set_context (playbin->curr_group->text_sink, context);
4401 GST_SOURCE_GROUP_UNLOCK (playbin->curr_group);
4402 GST_PLAY_BIN_UNLOCK (playbin);
4404 GST_ELEMENT_CLASS (parent_class)->set_context (element, context);
4407 /* Pass sink messages to the application, e.g. NEED_CONTEXT messages */
4409 gst_play_bin_update_context (GstPlayBin * playbin, GstContext * context)
4412 const gchar *context_type;
4414 GST_OBJECT_LOCK (playbin);
4415 context_type = gst_context_get_context_type (context);
4416 for (l = playbin->contexts; l; l = l->next) {
4417 GstContext *tmp = l->data;
4418 const gchar *tmp_type = gst_context_get_context_type (tmp);
4420 /* Always store newest context but never replace
4421 * a persistent one by a non-persistent one */
4422 if (strcmp (context_type, tmp_type) == 0 &&
4423 (gst_context_is_persistent (context) ||
4424 !gst_context_is_persistent (tmp))) {
4425 gst_context_replace ((GstContext **) & l->data, context);
4429 /* Not found? Add */
4432 g_list_prepend (playbin->contexts, gst_context_ref (context));
4433 GST_OBJECT_UNLOCK (playbin);
4436 static GstBusSyncReply
4437 activate_sink_bus_handler (GstBus * bus, GstMessage * msg, GstPlayBin * playbin)
4439 if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) {
4440 /* Only proxy errors from a fixed sink. If that fails we can just error out
4441 * early as stuff will fail later anyway */
4442 if (playbin->audio_sink
4443 && gst_object_has_as_ancestor (GST_MESSAGE_SRC (msg),
4444 GST_OBJECT_CAST (playbin->audio_sink)))
4445 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
4446 else if (playbin->video_sink
4447 && gst_object_has_as_ancestor (GST_MESSAGE_SRC (msg),
4448 GST_OBJECT_CAST (playbin->video_sink)))
4449 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
4450 else if (playbin->text_sink
4451 && gst_object_has_as_ancestor (GST_MESSAGE_SRC (msg),
4452 GST_OBJECT_CAST (playbin->text_sink)))
4453 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
4455 gst_message_unref (msg);
4456 } else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_NEED_CONTEXT) {
4457 const gchar *context_type;
4460 gst_message_parse_context_type (msg, &context_type);
4461 GST_OBJECT_LOCK (playbin);
4462 for (l = playbin->contexts; l; l = l->next) {
4463 GstContext *tmp = l->data;
4464 const gchar *tmp_type = gst_context_get_context_type (tmp);
4466 if (strcmp (context_type, tmp_type) == 0) {
4467 gst_element_set_context (GST_ELEMENT (GST_MESSAGE_SRC (msg)), l->data);
4471 GST_OBJECT_UNLOCK (playbin);
4473 /* Forward if we couldn't answer the message */
4475 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
4477 gst_message_unref (msg);
4479 } else if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_HAVE_CONTEXT) {
4480 GstContext *context;
4482 gst_message_parse_have_context (msg, &context);
4483 gst_play_bin_update_context (playbin, context);
4484 gst_context_unref (context);
4486 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
4488 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
4491 /* Doesn't really matter, nothing is using this bus */
4492 return GST_BUS_DROP;
4496 activate_sink (GstPlayBin * playbin, GstElement * sink, gboolean * activated)
4500 GstStateChangeReturn sret;
4501 gboolean ret = FALSE;
4506 GST_OBJECT_LOCK (sink);
4507 state = GST_STATE (sink);
4508 GST_OBJECT_UNLOCK (sink);
4509 if (state >= GST_STATE_READY) {
4514 if (!GST_OBJECT_PARENT (sink)) {
4515 bus = gst_bus_new ();
4516 gst_bus_set_sync_handler (bus,
4517 (GstBusSyncHandler) activate_sink_bus_handler, playbin, NULL);
4518 gst_element_set_bus (sink, bus);
4521 sret = gst_element_set_state (sink, GST_STATE_READY);
4522 if (sret == GST_STATE_CHANGE_FAILURE)
4531 gst_element_set_bus (sink, NULL);
4532 gst_object_unref (bus);
4538 /* autoplug-continue decides, if a pad has raw caps that can be exposed
4539 * directly or if further decoding is necessary. We use this to expose
4540 * supported subtitles directly */
4542 /* FIXME 0.11: Remove the checks for ANY caps, a sink should specify
4543 * explicitly the caps it supports and if it claims to support ANY
4544 * caps it really should support everything */
4546 autoplug_continue_cb (GstElement * element, GstPad * pad, GstCaps * caps,
4547 GstSourceGroup * group)
4549 gboolean ret = TRUE;
4550 GstPad *sinkpad = NULL;
4551 gboolean activated_sink;
4553 GST_SOURCE_GROUP_LOCK (group);
4555 if (group->text_sink &&
4556 activate_sink (group->playbin, group->text_sink, &activated_sink)) {
4557 sinkpad = gst_element_get_static_pad (group->text_sink, "sink");
4561 sinkcaps = gst_pad_query_caps (sinkpad, NULL);
4562 if (!gst_caps_is_any (sinkcaps))
4563 ret = !gst_caps_is_subset (caps, sinkcaps);
4564 gst_caps_unref (sinkcaps);
4565 gst_object_unref (sinkpad);
4568 gst_element_set_state (group->text_sink, GST_STATE_NULL);
4570 GstCaps *subcaps = gst_subtitle_overlay_create_factory_caps ();
4571 ret = !gst_caps_is_subset (caps, subcaps);
4572 gst_caps_unref (subcaps);
4574 /* If autoplugging can stop don't do additional checks */
4578 /* If this is from the subtitle uridecodebin we don't need to
4579 * check the audio and video sink */
4580 if (group->suburidecodebin
4581 && gst_object_has_as_ancestor (GST_OBJECT_CAST (element),
4582 GST_OBJECT_CAST (group->suburidecodebin)))
4585 if (group->audio_sink &&
4586 activate_sink (group->playbin, group->audio_sink, &activated_sink)) {
4588 sinkpad = gst_element_get_static_pad (group->audio_sink, "sink");
4592 sinkcaps = gst_pad_query_caps (sinkpad, NULL);
4593 if (!gst_caps_is_any (sinkcaps))
4594 ret = !gst_caps_is_subset (caps, sinkcaps);
4595 gst_caps_unref (sinkcaps);
4596 gst_object_unref (sinkpad);
4599 gst_element_set_state (group->audio_sink, GST_STATE_NULL);
4604 if (group->video_sink
4605 && activate_sink (group->playbin, group->video_sink, &activated_sink)) {
4606 sinkpad = gst_element_get_static_pad (group->video_sink, "sink");
4610 sinkcaps = gst_pad_query_caps (sinkpad, NULL);
4611 if (!gst_caps_is_any (sinkcaps))
4612 ret = !gst_caps_is_subset (caps, sinkcaps);
4613 gst_caps_unref (sinkcaps);
4614 gst_object_unref (sinkpad);
4617 gst_element_set_state (group->video_sink, GST_STATE_NULL);
4621 GST_SOURCE_GROUP_UNLOCK (group);
4623 GST_DEBUG_OBJECT (group->playbin,
4624 "continue autoplugging group %p for %s:%s, %" GST_PTR_FORMAT ": %d",
4625 group, GST_DEBUG_PAD_NAME (pad), caps, ret);
4631 sink_accepts_caps (GstPlayBin * playbin, GstElement * sink, GstCaps * caps)
4634 gboolean ret = TRUE;
4636 if ((sinkpad = gst_element_get_static_pad (sink, "sink"))) {
4639 sinkcaps = gst_pad_query_caps (sinkpad, NULL);
4640 /* Got the sink pad, now let's see if the element actually does accept the
4641 * caps that we have */
4642 ret = gst_caps_is_subset (caps, sinkcaps);
4643 gst_caps_unref (sinkcaps);
4644 gst_object_unref (sinkpad);
4650 /* We are asked to select an element. See if the next element to check
4651 * is a sink. If this is the case, we see if the sink works by setting it to
4652 * READY. If the sink works, we return SELECT_EXPOSE to make decodebin
4653 * expose the raw pad so that we can setup the mixers. */
4654 static GstAutoplugSelectResult
4655 autoplug_select_cb (GstElement * decodebin, GstPad * pad,
4656 GstCaps * caps, GstElementFactory * factory, GstSourceGroup * group)
4658 GstPlayBin *playbin;
4659 GstElement *element;
4661 GstPlaySinkType type;
4663 GList *ave_list = NULL, *l;
4664 GstAVElement *ave = NULL;
4665 GSequence *ave_seq = NULL;
4666 GSequenceIter *seq_iter;
4667 gboolean created_sink = FALSE;
4669 playbin = group->playbin;
4671 GST_DEBUG_OBJECT (playbin, "select group %p for %s:%s, %" GST_PTR_FORMAT,
4672 group, GST_DEBUG_PAD_NAME (pad), caps);
4674 GST_DEBUG_OBJECT (playbin, "checking factory %s", GST_OBJECT_NAME (factory));
4676 /* if it's not a sink, we make sure the element is compatible with
4678 if (!gst_element_factory_list_is_type (factory,
4679 GST_ELEMENT_FACTORY_TYPE_SINK)) {
4680 gboolean isvideodec = gst_element_factory_list_is_type (factory,
4681 GST_ELEMENT_FACTORY_TYPE_DECODER |
4682 GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO |
4683 GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE);
4684 gboolean isaudiodec = gst_element_factory_list_is_type (factory,
4685 GST_ELEMENT_FACTORY_TYPE_DECODER |
4686 GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO);
4688 if (!isvideodec && !isaudiodec)
4689 return GST_AUTOPLUG_SELECT_TRY;
4691 GST_SOURCE_GROUP_LOCK (group);
4692 g_mutex_lock (&playbin->elements_lock);
4695 ave_seq = playbin->aelements;
4696 sinkp = &group->audio_sink;
4698 ave_seq = playbin->velements;
4699 sinkp = &group->video_sink;
4703 g_sequence_lookup (ave_seq, factory,
4704 (GCompareDataFunc) avelement_lookup_decoder, NULL);
4706 /* Go to first iter with that decoder */
4708 GSequenceIter *tmp_seq_iter;
4710 tmp_seq_iter = g_sequence_iter_prev (seq_iter);
4711 if (!avelement_iter_is_equal (tmp_seq_iter, factory))
4713 seq_iter = tmp_seq_iter;
4714 } while (!g_sequence_iter_is_begin (seq_iter));
4716 while (!g_sequence_iter_is_end (seq_iter)
4717 && avelement_iter_is_equal (seq_iter, factory)) {
4718 ave = g_sequence_get (seq_iter);
4719 ave_list = g_list_prepend (ave_list, ave);
4720 seq_iter = g_sequence_iter_next (seq_iter);
4723 /* Sort all GstAVElements by their relative ranks and insert
4724 * into the decoders list */
4725 ave_list = g_list_sort (ave_list, (GCompareFunc) avelement_compare);
4727 ave_list = g_list_prepend (ave_list, NULL);
4730 /* if it is a decoder and we don't have a fixed sink, then find out
4731 * the matching audio/video sink from GstAVElements list */
4732 for (l = ave_list; l; l = l->next) {
4733 ave = (GstAVElement *) l->data;
4735 if (((isaudiodec && !group->audio_sink) ||
4736 (isvideodec && !group->video_sink))) {
4737 if (ave && ave->sink) {
4738 GST_DEBUG_OBJECT (playbin,
4739 "Trying to create sink '%s' for decoder '%s'",
4740 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (ave->sink)),
4741 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
4742 if ((*sinkp = gst_element_factory_create (ave->sink, NULL)) == NULL) {
4743 GST_WARNING_OBJECT (playbin,
4744 "Could not create an element from %s",
4745 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (ave->sink)));
4748 /* The sink is ours now, don't leak the floating reference in the
4749 * state-changed messages */
4750 gst_object_ref_sink (*sinkp);
4752 if (!activate_sink (playbin, *sinkp, NULL)) {
4753 gst_object_unref (*sinkp);
4755 GST_WARNING_OBJECT (playbin,
4756 "Could not activate sink %s",
4757 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (ave->sink)));
4760 created_sink = TRUE;
4765 /* If it is a decoder and we have a fixed sink for the media
4766 * type it outputs, check that the decoder is compatible with this sink */
4767 if ((isaudiodec && group->audio_sink) || (isvideodec
4768 && group->video_sink)) {
4769 gboolean compatible = FALSE;
4776 if ((sinkpad = gst_element_get_static_pad (sink, "sink"))) {
4777 GstPlayFlags flags = gst_play_bin_get_flags (playbin);
4779 (isaudiodec) ? gst_static_caps_get (&raw_audio_caps) :
4780 gst_static_caps_get (&raw_video_caps);
4782 caps = gst_pad_query_caps (sinkpad, NULL);
4784 /* If the sink supports raw audio/video, we first check
4785 * if the decoder could output any raw audio/video format
4786 * and assume it is compatible with the sink then. We don't
4787 * do a complete compatibility check here if converters
4788 * are plugged between the decoder and the sink because
4789 * the converters will convert between raw formats and
4790 * even if the decoder format is not supported by the decoder
4791 * a converter will convert it.
4793 * We assume here that the converters can convert between
4796 if ((isaudiodec && !(flags & GST_PLAY_FLAG_NATIVE_AUDIO)
4797 && gst_caps_can_intersect (caps, raw_caps)) || (!isaudiodec
4798 && !(flags & GST_PLAY_FLAG_NATIVE_VIDEO)
4799 && gst_caps_can_intersect (caps, raw_caps))) {
4801 gst_element_factory_can_src_any_caps (factory, raw_caps)
4802 || gst_element_factory_can_src_any_caps (factory, caps);
4804 compatible = gst_element_factory_can_src_any_caps (factory, caps);
4807 gst_object_unref (sinkpad);
4808 gst_caps_unref (raw_caps);
4809 gst_caps_unref (caps);
4815 GST_DEBUG_OBJECT (playbin, "%s not compatible with the fixed sink",
4816 GST_OBJECT_NAME (factory));
4818 /* If it is not compatible, either continue with the next possible
4819 * sink or if we have a fixed sink, skip the decoder */
4821 gst_element_set_state (*sinkp, GST_STATE_NULL);
4822 gst_object_unref (*sinkp);
4824 created_sink = FALSE;
4826 g_mutex_unlock (&playbin->elements_lock);
4827 GST_SOURCE_GROUP_UNLOCK (group);
4828 return GST_AUTOPLUG_SELECT_SKIP;
4832 g_list_free (ave_list);
4833 g_mutex_unlock (&playbin->elements_lock);
4834 GST_SOURCE_GROUP_UNLOCK (group);
4835 return GST_AUTOPLUG_SELECT_TRY;
4838 /* it's a sink, see if an instance of it actually works */
4839 GST_DEBUG_OBJECT (playbin, "we found a sink '%s'", GST_OBJECT_NAME (factory));
4842 gst_element_factory_get_metadata (factory, GST_ELEMENT_METADATA_KLASS);
4844 /* figure out the klass */
4845 if (strstr (klass, "Audio")) {
4846 GST_DEBUG_OBJECT (playbin, "we found an audio sink");
4847 type = GST_PLAY_SINK_TYPE_AUDIO;
4848 sinkp = &group->audio_sink;
4849 } else if (strstr (klass, "Video")) {
4850 GST_DEBUG_OBJECT (playbin, "we found a video sink");
4851 type = GST_PLAY_SINK_TYPE_VIDEO;
4852 sinkp = &group->video_sink;
4854 /* unknown klass, skip this element */
4855 GST_WARNING_OBJECT (playbin, "unknown sink klass %s found", klass);
4856 return GST_AUTOPLUG_SELECT_SKIP;
4859 /* if we are asked to do visualisations and it's an audio sink, skip the
4860 * element. We can only do visualisations with raw sinks */
4861 if (gst_play_sink_get_flags (playbin->playsink) & GST_PLAY_FLAG_VIS) {
4862 if (type == GST_PLAY_SINK_TYPE_AUDIO) {
4863 GST_DEBUG_OBJECT (playbin, "skip audio sink because of vis");
4864 return GST_AUTOPLUG_SELECT_SKIP;
4868 /* now see if we already have a sink element */
4869 GST_SOURCE_GROUP_LOCK (group);
4870 if (*sinkp && GST_STATE (*sinkp) >= GST_STATE_READY) {
4871 GstElement *sink = gst_object_ref (*sinkp);
4873 if (sink_accepts_caps (playbin, sink, caps)) {
4874 GST_DEBUG_OBJECT (playbin,
4875 "Existing sink '%s' accepts caps: %" GST_PTR_FORMAT,
4876 GST_ELEMENT_NAME (sink), caps);
4877 gst_object_unref (sink);
4878 GST_SOURCE_GROUP_UNLOCK (group);
4879 return GST_AUTOPLUG_SELECT_EXPOSE;
4881 GST_DEBUG_OBJECT (playbin,
4882 "Existing sink '%s' does not accept caps: %" GST_PTR_FORMAT,
4883 GST_ELEMENT_NAME (sink), caps);
4884 gst_object_unref (sink);
4885 GST_SOURCE_GROUP_UNLOCK (group);
4886 return GST_AUTOPLUG_SELECT_SKIP;
4889 GST_DEBUG_OBJECT (playbin, "we have no pending sink, try to create '%s'",
4890 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
4892 if ((*sinkp = gst_element_factory_create (factory, NULL)) == NULL) {
4893 GST_WARNING_OBJECT (playbin, "Could not create an element from %s",
4894 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
4895 GST_SOURCE_GROUP_UNLOCK (group);
4896 return GST_AUTOPLUG_SELECT_SKIP;
4899 /* The sink is ours now, don't leak floating references in the state-changed
4900 * messages, but only do that if we didn't just create the sink above and
4901 * already ref_sink'd it there */
4903 gst_object_ref_sink (*sinkp);
4907 if (!activate_sink (playbin, element, NULL)) {
4908 GST_WARNING_OBJECT (playbin, "Could not activate sink %s",
4909 gst_plugin_feature_get_name (GST_PLUGIN_FEATURE (factory)));
4911 gst_object_unref (element);
4912 GST_SOURCE_GROUP_UNLOCK (group);
4913 return GST_AUTOPLUG_SELECT_SKIP;
4916 /* Check if the selected sink actually supports the
4917 * caps and can be set to READY*/
4918 if (!sink_accepts_caps (playbin, element, caps)) {
4920 gst_element_set_state (element, GST_STATE_NULL);
4921 gst_object_unref (element);
4922 GST_SOURCE_GROUP_UNLOCK (group);
4923 return GST_AUTOPLUG_SELECT_SKIP;
4926 /* remember the sink in the group now
4928 * store the sink in the group, we will configure it later when we
4929 * reconfigure the sink */
4930 GST_DEBUG_OBJECT (playbin, "remember sink");
4931 GST_SOURCE_GROUP_UNLOCK (group);
4933 /* tell decodebin to expose the pad because we are going to use this
4935 GST_DEBUG_OBJECT (playbin, "we found a working sink, expose pad");
4937 return GST_AUTOPLUG_SELECT_EXPOSE;
4940 #define GST_PLAY_BIN_FILTER_CAPS(filter,caps) G_STMT_START { \
4942 GstCaps *intersection = \
4943 gst_caps_intersect_full ((filter), (caps), GST_CAPS_INTERSECT_FIRST); \
4944 gst_caps_unref ((caps)); \
4945 (caps) = intersection; \
4950 autoplug_query_caps (GstElement * uridecodebin, GstPad * pad,
4951 GstElement * element, GstQuery * query, GstSourceGroup * group)
4953 GstCaps *filter, *result = NULL;
4955 GstPad *sinkpad = NULL;
4956 GstElementFactory *factory;
4957 GstElementFactoryListType factory_type;
4958 gboolean have_sink = FALSE;
4960 GST_SOURCE_GROUP_LOCK (group);
4961 gst_query_parse_caps (query, &filter);
4963 factory = gst_element_get_factory (element);
4967 if (gst_element_factory_list_is_type (factory,
4968 GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO |
4969 GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE)) {
4971 GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO |
4972 GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE;
4974 /* If this is from the subtitle uridecodebin we don't need to
4975 * check the audio and video sink */
4976 if (group->suburidecodebin
4977 && gst_object_has_as_ancestor (GST_OBJECT_CAST (pad),
4978 GST_OBJECT_CAST (group->suburidecodebin))) {
4982 if ((sink = group->video_sink)) {
4983 sinkpad = gst_element_get_static_pad (sink, "sink");
4987 sinkcaps = gst_pad_query_caps (sinkpad, filter);
4988 if (!gst_caps_is_any (sinkcaps)) {
4992 result = gst_caps_merge (result, sinkcaps);
4994 gst_caps_unref (sinkcaps);
4996 gst_object_unref (sinkpad);
5000 } else if (gst_element_factory_list_is_type (factory,
5001 GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO)) {
5002 factory_type = GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO;
5004 /* If this is from the subtitle uridecodebin we don't need to
5005 * check the audio and video sink */
5006 if (group->suburidecodebin
5007 && gst_object_has_as_ancestor (GST_OBJECT_CAST (pad),
5008 GST_OBJECT_CAST (group->suburidecodebin))) {
5012 if ((sink = group->audio_sink)) {
5013 sinkpad = gst_element_get_static_pad (sink, "sink");
5017 sinkcaps = gst_pad_query_caps (sinkpad, filter);
5018 if (!gst_caps_is_any (sinkcaps)) {
5022 result = gst_caps_merge (result, sinkcaps);
5024 gst_caps_unref (sinkcaps);
5026 gst_object_unref (sinkpad);
5030 } else if (gst_element_factory_list_is_type (factory,
5031 GST_ELEMENT_FACTORY_TYPE_MEDIA_SUBTITLE)) {
5032 factory_type = GST_ELEMENT_FACTORY_TYPE_MEDIA_SUBTITLE;
5034 if ((sink = group->playbin->text_sink)) {
5035 sinkpad = gst_element_get_static_pad (sink, "sink");
5039 sinkcaps = gst_pad_query_caps (sinkpad, filter);
5040 if (!gst_caps_is_any (sinkcaps)) {
5044 result = gst_caps_merge (result, sinkcaps);
5046 gst_caps_unref (sinkcaps);
5048 gst_object_unref (sinkpad);
5052 GstCaps *subcaps = gst_subtitle_overlay_create_factory_caps ();
5053 GST_PLAY_BIN_FILTER_CAPS (filter, subcaps);
5057 result = gst_caps_merge (result, subcaps);
5064 GValueArray *factories;
5067 factories = autoplug_factories_cb (uridecodebin, pad, NULL, group);
5068 n = factories->n_values;
5069 for (i = 0; i < n; i++) {
5070 GValue *v = g_value_array_get_nth (factories, i);
5071 GstElementFactory *f = g_value_get_object (v);
5072 const GList *templates;
5074 GstCaps *templ_caps;
5076 if (!gst_element_factory_list_is_type (f, factory_type))
5079 templates = gst_element_factory_get_static_pad_templates (f);
5081 for (l = templates; l; l = l->next) {
5082 templ_caps = gst_static_pad_template_get_caps (l->data);
5084 if (!gst_caps_is_any (templ_caps)) {
5085 GST_PLAY_BIN_FILTER_CAPS (filter, templ_caps);
5087 result = templ_caps;
5089 result = gst_caps_merge (result, templ_caps);
5091 gst_caps_unref (templ_caps);
5095 g_value_array_free (factories);
5099 GST_SOURCE_GROUP_UNLOCK (group);
5104 /* Add the actual decoder/parser/etc caps at the very end to
5105 * make sure we don't cause empty caps to be returned, e.g.
5106 * if a parser asks us but a decoder is required after it
5107 * because no sink can handle the format directly.
5110 GstPad *target = gst_ghost_pad_get_target (GST_GHOST_PAD (pad));
5113 GstCaps *target_caps = gst_pad_get_pad_template_caps (target);
5115 GST_PLAY_BIN_FILTER_CAPS (filter, target_caps);
5116 if (!gst_caps_is_any (target_caps)) {
5118 GstCapsFeatures *features;
5122 n = gst_caps_get_size (target_caps);
5123 tmp = gst_caps_new_empty ();
5124 for (i = 0; i < n; i++) {
5125 features = gst_caps_get_features (target_caps, i);
5126 s = gst_caps_get_structure (target_caps, i);
5128 if (!gst_structure_has_name (s, "video/x-raw") &&
5129 !gst_structure_has_name (s, "audio/x-raw")) {
5130 gst_caps_append_structure_full (tmp,
5131 gst_structure_copy (s), gst_caps_features_copy (features));
5132 } else if (gst_caps_features_is_any (features)
5133 || gst_caps_features_is_equal (features,
5134 GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY)) {
5135 gst_caps_append_structure (tmp, gst_structure_copy (s));
5138 gst_caps_unref (target_caps);
5143 result = gst_caps_merge (result, target_caps);
5144 gst_object_unref (target);
5149 gst_query_set_caps_result (query, result);
5150 gst_caps_unref (result);
5156 autoplug_query_context (GstElement * uridecodebin, GstPad * pad,
5157 GstElement * element, GstQuery * query, GstSourceGroup * group)
5160 GstPad *sinkpad = NULL;
5161 GstElementFactory *factory;
5162 gboolean res = FALSE;
5164 GST_SOURCE_GROUP_LOCK (group);
5166 factory = gst_element_get_factory (element);
5170 if (gst_element_factory_list_is_type (factory,
5171 GST_ELEMENT_FACTORY_TYPE_MEDIA_VIDEO |
5172 GST_ELEMENT_FACTORY_TYPE_MEDIA_IMAGE)) {
5173 /* If this is from the subtitle uridecodebin we don't need to
5174 * check the audio and video sink */
5175 if (group->suburidecodebin
5176 && gst_object_has_as_ancestor (GST_OBJECT_CAST (pad),
5177 GST_OBJECT_CAST (group->suburidecodebin))) {
5181 if ((sink = group->video_sink)) {
5182 sinkpad = gst_element_get_static_pad (sink, "sink");
5184 res = gst_pad_query (sinkpad, query);
5185 gst_object_unref (sinkpad);
5188 } else if (gst_element_factory_list_is_type (factory,
5189 GST_ELEMENT_FACTORY_TYPE_MEDIA_AUDIO)) {
5190 /* If this is from the subtitle uridecodebin we don't need to
5191 * check the audio and video sink */
5192 if (group->suburidecodebin
5193 && gst_object_has_as_ancestor (GST_OBJECT_CAST (pad),
5194 GST_OBJECT_CAST (group->suburidecodebin))) {
5198 if ((sink = group->audio_sink)) {
5199 sinkpad = gst_element_get_static_pad (sink, "sink");
5201 res = gst_pad_query (sinkpad, query);
5202 gst_object_unref (sinkpad);
5205 } else if (gst_element_factory_list_is_type (factory,
5206 GST_ELEMENT_FACTORY_TYPE_MEDIA_SUBTITLE)) {
5207 if ((sink = group->playbin->text_sink)) {
5208 sinkpad = gst_element_get_static_pad (sink, "sink");
5210 res = gst_pad_query (sinkpad, query);
5211 gst_object_unref (sinkpad);
5219 GST_SOURCE_GROUP_UNLOCK (group);
5225 autoplug_query_cb (GstElement * uridecodebin, GstPad * pad,
5226 GstElement * element, GstQuery * query, GstSourceGroup * group)
5229 switch (GST_QUERY_TYPE (query)) {
5230 case GST_QUERY_CAPS:
5231 return autoplug_query_caps (uridecodebin, pad, element, query, group);
5232 case GST_QUERY_CONTEXT:
5233 return autoplug_query_context (uridecodebin, pad, element, query, group);
5240 notify_source_cb (GstElement * uridecodebin, GParamSpec * pspec,
5241 GstSourceGroup * group)
5243 GstPlayBin *playbin;
5246 playbin = group->playbin;
5248 g_object_get (group->uridecodebin, "source", &source, NULL);
5250 GST_OBJECT_LOCK (playbin);
5251 if (playbin->source)
5252 gst_object_unref (playbin->source);
5253 playbin->source = source;
5254 GST_OBJECT_UNLOCK (playbin);
5256 g_object_notify (G_OBJECT (playbin), "source");
5258 g_signal_emit (playbin, gst_play_bin_signals[SIGNAL_SOURCE_SETUP],
5259 0, playbin->source);
5262 /* must be called with the group lock */
5264 group_set_locked_state_unlocked (GstPlayBin * playbin, GstSourceGroup * group,
5267 GST_DEBUG_OBJECT (playbin, "locked_state %d on group %p", locked, group);
5269 if (group->uridecodebin)
5270 gst_element_set_locked_state (group->uridecodebin, locked);
5271 if (group->suburidecodebin)
5272 gst_element_set_locked_state (group->suburidecodebin, locked);
5277 /* must be called with PLAY_BIN_LOCK */
5278 static GstStateChangeReturn
5279 activate_group (GstPlayBin * playbin, GstSourceGroup * group, GstState target)
5281 GstElement *uridecodebin = NULL;
5282 GstElement *suburidecodebin = NULL;
5284 gboolean audio_sink_activated = FALSE;
5285 gboolean video_sink_activated = FALSE;
5286 gboolean text_sink_activated = FALSE;
5287 GstStateChangeReturn state_ret;
5289 g_return_val_if_fail (group->valid, GST_STATE_CHANGE_FAILURE);
5290 g_return_val_if_fail (!group->active, GST_STATE_CHANGE_FAILURE);
5292 GST_DEBUG_OBJECT (playbin, "activating group %p", group);
5294 GST_SOURCE_GROUP_LOCK (group);
5296 /* First set up the custom sources */
5297 if (playbin->audio_sink)
5298 group->audio_sink = gst_object_ref (playbin->audio_sink);
5301 gst_play_sink_get_sink (playbin->playsink, GST_PLAY_SINK_TYPE_AUDIO);
5303 if (group->audio_sink) {
5304 if (!activate_sink (playbin, group->audio_sink, &audio_sink_activated)) {
5305 if (group->audio_sink == playbin->audio_sink) {
5308 gst_object_unref (group->audio_sink);
5309 group->audio_sink = NULL;
5314 if (playbin->video_sink)
5315 group->video_sink = gst_object_ref (playbin->video_sink);
5318 gst_play_sink_get_sink (playbin->playsink, GST_PLAY_SINK_TYPE_VIDEO);
5320 if (group->video_sink) {
5321 if (!activate_sink (playbin, group->video_sink, &video_sink_activated)) {
5322 if (group->video_sink == playbin->video_sink) {
5325 gst_object_unref (group->video_sink);
5326 group->video_sink = NULL;
5331 if (playbin->text_sink)
5332 group->text_sink = gst_object_ref (playbin->text_sink);
5335 gst_play_sink_get_sink (playbin->playsink, GST_PLAY_SINK_TYPE_TEXT);
5337 if (group->text_sink) {
5338 if (!activate_sink (playbin, group->text_sink, &text_sink_activated)) {
5339 if (group->text_sink == playbin->text_sink) {
5342 gst_object_unref (group->text_sink);
5343 group->text_sink = NULL;
5348 g_slist_free (group->suburi_flushes_to_drop);
5349 group->suburi_flushes_to_drop = NULL;
5350 if (!group->suburi_flushes_to_drop_lock.p)
5351 g_mutex_init (&group->suburi_flushes_to_drop_lock);
5353 if (group->uridecodebin) {
5354 GST_DEBUG_OBJECT (playbin, "reusing existing uridecodebin");
5355 uridecodebin = group->uridecodebin;
5356 gst_element_set_state (uridecodebin, GST_STATE_READY);
5357 /* no need to take extra ref, we already have one
5358 * and the bin will add one since it is no longer floating,
5359 * as it was at least added once before (below) */
5360 gst_bin_add (GST_BIN_CAST (playbin), uridecodebin);
5362 GST_DEBUG_OBJECT (playbin, "making new uridecodebin");
5363 uridecodebin = gst_element_factory_make ("uridecodebin", NULL);
5366 gst_bin_add (GST_BIN_CAST (playbin), uridecodebin);
5367 group->uridecodebin = gst_object_ref (uridecodebin);
5370 flags = gst_play_sink_get_flags (playbin->playsink);
5372 g_object_set (uridecodebin,
5373 /* configure connection speed */
5374 "connection-speed", playbin->connection_speed / 1000,
5377 /* configure download buffering */
5378 "download", ((flags & GST_PLAY_FLAG_DOWNLOAD) != 0),
5379 /* configure buffering of demuxed/parsed data */
5380 "use-buffering", ((flags & GST_PLAY_FLAG_BUFFERING) != 0),
5381 /* enable hardware-based elements */
5382 "force-sw-decoders", ((flags & GST_PLAY_FLAG_FORCE_SW_DECODERS) != 0),
5383 /* configure buffering parameters */
5384 "buffer-duration", playbin->buffer_duration,
5385 "buffer-size", playbin->buffer_size,
5386 "ring-buffer-max-size", playbin->ring_buffer_max_size, NULL);
5388 /* connect pads and other things */
5389 group->pad_added_id = g_signal_connect (uridecodebin, "pad-added",
5390 G_CALLBACK (pad_added_cb), group);
5391 group->pad_removed_id = g_signal_connect (uridecodebin, "pad-removed",
5392 G_CALLBACK (pad_removed_cb), group);
5393 group->no_more_pads_id = g_signal_connect (uridecodebin, "no-more-pads",
5394 G_CALLBACK (no_more_pads_cb), group);
5395 group->notify_source_id = g_signal_connect (uridecodebin, "notify::source",
5396 G_CALLBACK (notify_source_cb), group);
5398 /* we have 1 pending no-more-pads */
5401 /* is called when the uridecodebin is out of data and we can switch to the
5404 g_signal_connect (uridecodebin, "drained", G_CALLBACK (drained_cb),
5407 /* will be called when a new media type is found. We return a list of decoders
5408 * including sinks for decodebin to try */
5409 group->autoplug_factories_id =
5410 g_signal_connect (uridecodebin, "autoplug-factories",
5411 G_CALLBACK (autoplug_factories_cb), group);
5412 group->autoplug_select_id =
5413 g_signal_connect (uridecodebin, "autoplug-select",
5414 G_CALLBACK (autoplug_select_cb), group);
5415 group->autoplug_continue_id =
5416 g_signal_connect (uridecodebin, "autoplug-continue",
5417 G_CALLBACK (autoplug_continue_cb), group);
5418 group->autoplug_query_id =
5419 g_signal_connect (uridecodebin, "autoplug-query",
5420 G_CALLBACK (autoplug_query_cb), group);
5422 if (group->suburi) {
5424 if (group->suburidecodebin) {
5425 GST_DEBUG_OBJECT (playbin, "reusing existing suburidecodebin");
5426 suburidecodebin = group->suburidecodebin;
5427 gst_element_set_state (suburidecodebin, GST_STATE_READY);
5428 /* no need to take extra ref, we already have one
5429 * and the bin will add one since it is no longer floating,
5430 * as it was at least added once before (below) */
5431 gst_bin_add (GST_BIN_CAST (playbin), suburidecodebin);
5433 GST_DEBUG_OBJECT (playbin, "making new suburidecodebin");
5434 suburidecodebin = gst_element_factory_make ("uridecodebin", NULL);
5435 if (!suburidecodebin)
5438 gst_bin_add (GST_BIN_CAST (playbin), suburidecodebin);
5439 group->suburidecodebin = gst_object_ref (suburidecodebin);
5442 g_object_set (suburidecodebin,
5443 /* configure connection speed */
5444 "connection-speed", playbin->connection_speed,
5446 "uri", group->suburi, NULL);
5448 /* connect pads and other things */
5449 group->sub_pad_added_id = g_signal_connect (suburidecodebin, "pad-added",
5450 G_CALLBACK (pad_added_cb), group);
5451 group->sub_pad_removed_id = g_signal_connect (suburidecodebin,
5452 "pad-removed", G_CALLBACK (pad_removed_cb), group);
5453 group->sub_no_more_pads_id = g_signal_connect (suburidecodebin,
5454 "no-more-pads", G_CALLBACK (no_more_pads_cb), group);
5456 group->sub_autoplug_continue_id =
5457 g_signal_connect (suburidecodebin, "autoplug-continue",
5458 G_CALLBACK (autoplug_continue_cb), group);
5460 group->sub_autoplug_query_id =
5461 g_signal_connect (suburidecodebin, "autoplug-query",
5462 G_CALLBACK (autoplug_query_cb), group);
5464 /* we have 2 pending no-more-pads */
5466 group->sub_pending = TRUE;
5468 group->sub_pending = FALSE;
5471 /* release the group lock before setting the state of the decodebins, they
5472 * might fire signals in this thread that we need to handle with the
5473 * group_lock taken. */
5474 GST_SOURCE_GROUP_UNLOCK (group);
5476 if (suburidecodebin) {
5477 if (gst_element_set_state (suburidecodebin,
5478 target) == GST_STATE_CHANGE_FAILURE) {
5479 GST_DEBUG_OBJECT (playbin,
5480 "failed state change of subtitle uridecodebin");
5481 GST_SOURCE_GROUP_LOCK (group);
5483 REMOVE_SIGNAL (group->suburidecodebin, group->sub_pad_added_id);
5484 REMOVE_SIGNAL (group->suburidecodebin, group->sub_pad_removed_id);
5485 REMOVE_SIGNAL (group->suburidecodebin, group->sub_no_more_pads_id);
5486 REMOVE_SIGNAL (group->suburidecodebin, group->sub_autoplug_continue_id);
5487 REMOVE_SIGNAL (group->suburidecodebin, group->sub_autoplug_query_id);
5488 /* Might already be removed because of an error message */
5489 if (GST_OBJECT_PARENT (suburidecodebin) == GST_OBJECT_CAST (playbin))
5490 gst_bin_remove (GST_BIN_CAST (playbin), suburidecodebin);
5491 if (group->sub_pending) {
5493 group->sub_pending = FALSE;
5495 gst_element_set_state (suburidecodebin, GST_STATE_READY);
5496 g_free (group->suburi);
5497 group->suburi = NULL;
5498 GST_SOURCE_GROUP_UNLOCK (group);
5502 gst_element_set_state (uridecodebin,
5503 target)) == GST_STATE_CHANGE_FAILURE)
5504 goto uridecodebin_failure;
5506 GST_SOURCE_GROUP_LOCK (group);
5507 /* allow state changes of the playbin affect the group elements now */
5508 group_set_locked_state_unlocked (playbin, group, FALSE);
5509 group->active = TRUE;
5510 GST_SOURCE_GROUP_UNLOCK (group);
5519 GST_SOURCE_GROUP_UNLOCK (group);
5521 gst_missing_element_message_new (GST_ELEMENT_CAST (playbin),
5523 gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
5525 GST_ELEMENT_ERROR (playbin, CORE, MISSING_PLUGIN,
5526 (_("Could not create \"uridecodebin\" element.")), (NULL));
5528 GST_SOURCE_GROUP_LOCK (group);
5532 uridecodebin_failure:
5534 GST_DEBUG_OBJECT (playbin, "failed state change of uridecodebin");
5535 GST_SOURCE_GROUP_LOCK (group);
5540 GST_ERROR_OBJECT (playbin, "failed to activate sinks");
5546 /* delete any custom sinks we might have */
5547 if (group->audio_sink) {
5548 /* If this is a automatically created sink set it to NULL */
5549 if (audio_sink_activated)
5550 gst_element_set_state (group->audio_sink, GST_STATE_NULL);
5551 gst_object_unref (group->audio_sink);
5553 group->audio_sink = NULL;
5555 if (group->video_sink) {
5556 /* If this is a automatically created sink set it to NULL */
5557 if (video_sink_activated)
5558 gst_element_set_state (group->video_sink, GST_STATE_NULL);
5559 gst_object_unref (group->video_sink);
5561 group->video_sink = NULL;
5563 if (group->text_sink) {
5564 /* If this is a automatically created sink set it to NULL */
5565 if (text_sink_activated)
5566 gst_element_set_state (group->text_sink, GST_STATE_NULL);
5567 gst_object_unref (group->text_sink);
5569 group->text_sink = NULL;
5572 REMOVE_SIGNAL (group->uridecodebin, group->pad_added_id);
5573 REMOVE_SIGNAL (group->uridecodebin, group->pad_removed_id);
5574 REMOVE_SIGNAL (group->uridecodebin, group->no_more_pads_id);
5575 REMOVE_SIGNAL (group->uridecodebin, group->notify_source_id);
5576 REMOVE_SIGNAL (group->uridecodebin, group->drained_id);
5577 REMOVE_SIGNAL (group->uridecodebin, group->autoplug_factories_id);
5578 REMOVE_SIGNAL (group->uridecodebin, group->autoplug_select_id);
5579 REMOVE_SIGNAL (group->uridecodebin, group->autoplug_continue_id);
5580 REMOVE_SIGNAL (group->uridecodebin, group->autoplug_query_id);
5582 gst_element_set_state (uridecodebin, GST_STATE_NULL);
5583 gst_bin_remove (GST_BIN_CAST (playbin), uridecodebin);
5586 GST_SOURCE_GROUP_UNLOCK (group);
5588 return GST_STATE_CHANGE_FAILURE;
5592 /* unlink a group of uridecodebins from the sink.
5593 * must be called with PLAY_BIN_LOCK */
5595 deactivate_group (GstPlayBin * playbin, GstSourceGroup * group)
5599 g_return_val_if_fail (group->active, FALSE);
5600 g_return_val_if_fail (group->valid, FALSE);
5602 GST_DEBUG_OBJECT (playbin, "unlinking group %p", group);
5604 GST_SOURCE_GROUP_LOCK (group);
5605 group->active = FALSE;
5606 for (i = 0; i < PLAYBIN_STREAM_LAST; i++) {
5607 GstSourceCombine *combine = &group->combiner[i];
5609 GST_DEBUG_OBJECT (playbin, "unlinking combiner %s", combine->media_list[0]);
5611 if (combine->srcpad) {
5612 source_combine_remove_pads (playbin, combine);
5615 if (combine->combiner) {
5618 /* release and unref requests pad from the combiner */
5619 for (n = 0; n < combine->channels->len; n++) {
5620 GstPad *sinkpad = g_ptr_array_index (combine->channels, n);
5622 gst_element_release_request_pad (combine->combiner, sinkpad);
5623 gst_object_unref (sinkpad);
5625 g_ptr_array_set_size (combine->channels, 0);
5627 gst_element_set_state (combine->combiner, GST_STATE_NULL);
5628 gst_bin_remove (GST_BIN_CAST (playbin), combine->combiner);
5629 combine->combiner = NULL;
5632 /* delete any custom sinks we might have.
5633 * conditionally set them to null if they aren't inside playsink yet */
5634 if (group->audio_sink) {
5635 if (!gst_object_has_as_ancestor (GST_OBJECT_CAST (group->audio_sink),
5636 GST_OBJECT_CAST (playbin->playsink))) {
5637 gst_element_set_state (group->audio_sink, GST_STATE_NULL);
5639 gst_object_unref (group->audio_sink);
5641 group->audio_sink = NULL;
5642 if (group->video_sink) {
5643 if (!gst_object_has_as_ancestor (GST_OBJECT_CAST (group->video_sink),
5644 GST_OBJECT_CAST (playbin->playsink))) {
5645 gst_element_set_state (group->video_sink, GST_STATE_NULL);
5647 gst_object_unref (group->video_sink);
5649 group->video_sink = NULL;
5650 if (group->text_sink) {
5651 if (!gst_object_has_as_ancestor (GST_OBJECT_CAST (group->text_sink),
5652 GST_OBJECT_CAST (playbin->playsink))) {
5653 gst_element_set_state (group->text_sink, GST_STATE_NULL);
5655 gst_object_unref (group->text_sink);
5657 group->text_sink = NULL;
5659 if (group->uridecodebin) {
5660 REMOVE_SIGNAL (group->uridecodebin, group->pad_added_id);
5661 REMOVE_SIGNAL (group->uridecodebin, group->pad_removed_id);
5662 REMOVE_SIGNAL (group->uridecodebin, group->no_more_pads_id);
5663 REMOVE_SIGNAL (group->uridecodebin, group->notify_source_id);
5664 REMOVE_SIGNAL (group->uridecodebin, group->drained_id);
5665 REMOVE_SIGNAL (group->uridecodebin, group->autoplug_factories_id);
5666 REMOVE_SIGNAL (group->uridecodebin, group->autoplug_select_id);
5667 REMOVE_SIGNAL (group->uridecodebin, group->autoplug_continue_id);
5668 REMOVE_SIGNAL (group->uridecodebin, group->autoplug_query_id);
5669 gst_bin_remove (GST_BIN_CAST (playbin), group->uridecodebin);
5672 if (group->suburidecodebin) {
5673 REMOVE_SIGNAL (group->suburidecodebin, group->sub_pad_added_id);
5674 REMOVE_SIGNAL (group->suburidecodebin, group->sub_pad_removed_id);
5675 REMOVE_SIGNAL (group->suburidecodebin, group->sub_no_more_pads_id);
5676 REMOVE_SIGNAL (group->suburidecodebin, group->sub_autoplug_continue_id);
5677 REMOVE_SIGNAL (group->suburidecodebin, group->sub_autoplug_query_id);
5679 /* Might already be removed because of errors */
5680 if (GST_OBJECT_PARENT (group->suburidecodebin) == GST_OBJECT_CAST (playbin))
5681 gst_bin_remove (GST_BIN_CAST (playbin), group->suburidecodebin);
5684 group->have_group_id = FALSE;
5686 GST_SOURCE_GROUP_UNLOCK (group);
5691 /* setup the next group to play, this assumes the next_group is valid and
5692 * configured. It swaps out the current_group and activates the valid
5694 static GstStateChangeReturn
5695 setup_next_source (GstPlayBin * playbin, GstState target)
5697 GstSourceGroup *new_group, *old_group;
5698 GstStateChangeReturn state_ret;
5700 GST_DEBUG_OBJECT (playbin, "setup sources");
5702 /* see if there is a next group */
5703 GST_PLAY_BIN_LOCK (playbin);
5704 new_group = playbin->next_group;
5705 if (!new_group || !new_group->valid)
5708 /* first unlink the current source, if any */
5709 old_group = playbin->curr_group;
5710 if (old_group && old_group->valid && old_group->active) {
5711 new_group->stream_changed_pending = TRUE;
5713 gst_play_bin_update_cached_duration (playbin);
5714 /* unlink our pads with the sink */
5715 deactivate_group (playbin, old_group);
5716 old_group->valid = FALSE;
5719 /* swap old and new */
5720 playbin->curr_group = new_group;
5721 playbin->next_group = old_group;
5723 /* activate the new group */
5725 activate_group (playbin, new_group,
5726 target)) == GST_STATE_CHANGE_FAILURE)
5727 goto activate_failed;
5729 GST_PLAY_BIN_UNLOCK (playbin);
5736 GST_DEBUG_OBJECT (playbin, "no next group");
5737 if (target == GST_STATE_READY && new_group && new_group->uri == NULL)
5738 GST_ELEMENT_ERROR (playbin, RESOURCE, NOT_FOUND, ("No URI set"), (NULL));
5739 GST_PLAY_BIN_UNLOCK (playbin);
5740 return GST_STATE_CHANGE_FAILURE;
5744 new_group->stream_changed_pending = FALSE;
5745 GST_DEBUG_OBJECT (playbin, "activate failed");
5746 new_group->valid = FALSE;
5747 GST_PLAY_BIN_UNLOCK (playbin);
5748 return GST_STATE_CHANGE_FAILURE;
5752 /* The group that is currently playing is copied again to the
5753 * next_group so that it will start playing the next time.
5756 save_current_group (GstPlayBin * playbin)
5758 GstSourceGroup *curr_group;
5760 GST_DEBUG_OBJECT (playbin, "save current group");
5762 /* see if there is a current group */
5763 GST_PLAY_BIN_LOCK (playbin);
5764 curr_group = playbin->curr_group;
5765 if (curr_group && curr_group->valid && curr_group->active) {
5766 /* unlink our pads with the sink */
5767 deactivate_group (playbin, curr_group);
5769 /* swap old and new */
5770 playbin->curr_group = playbin->next_group;
5771 playbin->next_group = curr_group;
5772 GST_PLAY_BIN_UNLOCK (playbin);
5777 /* clear the locked state from all groups. This function is called before a
5778 * state change to NULL is performed on them. */
5780 groups_set_locked_state (GstPlayBin * playbin, gboolean locked)
5782 GST_DEBUG_OBJECT (playbin, "setting locked state to %d on all groups",
5785 GST_PLAY_BIN_LOCK (playbin);
5786 GST_SOURCE_GROUP_LOCK (playbin->curr_group);
5787 group_set_locked_state_unlocked (playbin, playbin->curr_group, locked);
5788 GST_SOURCE_GROUP_UNLOCK (playbin->curr_group);
5789 GST_SOURCE_GROUP_LOCK (playbin->next_group);
5790 group_set_locked_state_unlocked (playbin, playbin->next_group, locked);
5791 GST_SOURCE_GROUP_UNLOCK (playbin->next_group);
5792 GST_PLAY_BIN_UNLOCK (playbin);
5797 static GstStateChangeReturn
5798 gst_play_bin_change_state (GstElement * element, GstStateChange transition)
5800 GstStateChangeReturn ret;
5801 GstPlayBin *playbin;
5802 gboolean do_save = FALSE;
5804 playbin = GST_PLAY_BIN (element);
5806 switch (transition) {
5807 case GST_STATE_CHANGE_NULL_TO_READY:
5808 memset (&playbin->duration, 0, sizeof (playbin->duration));
5810 case GST_STATE_CHANGE_READY_TO_PAUSED:
5811 GST_LOG_OBJECT (playbin, "clearing shutdown flag");
5812 memset (&playbin->duration, 0, sizeof (playbin->duration));
5813 g_atomic_int_set (&playbin->shutdown, 0);
5814 do_async_start (playbin);
5816 case GST_STATE_CHANGE_PAUSED_TO_READY:
5818 /* FIXME unlock our waiting groups */
5819 GST_LOG_OBJECT (playbin, "setting shutdown flag");
5820 g_atomic_int_set (&playbin->shutdown, 1);
5821 memset (&playbin->duration, 0, sizeof (playbin->duration));
5823 /* wait for all callbacks to end by taking the lock.
5824 * No dynamic (critical) new callbacks will
5825 * be able to happen as we set the shutdown flag. */
5826 GST_PLAY_BIN_DYN_LOCK (playbin);
5827 GST_LOG_OBJECT (playbin, "dynamic lock taken, we can continue shutdown");
5828 GST_PLAY_BIN_DYN_UNLOCK (playbin);
5831 case GST_STATE_CHANGE_READY_TO_NULL:
5832 /* we go async to PAUSED, so if that fails, we never make it to PAUSED
5833 * and no state change PAUSED to READY passes here,
5834 * though it is a nice-to-have ... */
5835 if (!g_atomic_int_get (&playbin->shutdown)) {
5839 memset (&playbin->duration, 0, sizeof (playbin->duration));
5841 /* unlock so that all groups go to NULL */
5842 groups_set_locked_state (playbin, FALSE);
5848 ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
5849 if (ret == GST_STATE_CHANGE_FAILURE)
5852 switch (transition) {
5853 case GST_STATE_CHANGE_READY_TO_PAUSED:
5855 setup_next_source (playbin,
5856 GST_STATE_PAUSED)) == GST_STATE_CHANGE_FAILURE)
5858 if (ret == GST_STATE_CHANGE_SUCCESS)
5859 ret = GST_STATE_CHANGE_ASYNC;
5862 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
5863 do_async_done (playbin);
5864 /* FIXME Release audio device when we implement that */
5866 case GST_STATE_CHANGE_PAUSED_TO_READY:
5867 save_current_group (playbin);
5869 case GST_STATE_CHANGE_READY_TO_NULL:
5874 /* also do missed state change down to READY */
5876 save_current_group (playbin);
5877 /* Deactivate the groups, set the uridecodebins to NULL
5880 for (i = 0; i < 2; i++) {
5881 if (playbin->groups[i].active && playbin->groups[i].valid) {
5882 deactivate_group (playbin, &playbin->groups[i]);
5883 playbin->groups[i].valid = FALSE;
5886 if (playbin->groups[i].uridecodebin) {
5887 gst_element_set_state (playbin->groups[i].uridecodebin,
5889 gst_object_unref (playbin->groups[i].uridecodebin);
5890 playbin->groups[i].uridecodebin = NULL;
5893 if (playbin->groups[i].suburidecodebin) {
5894 gst_element_set_state (playbin->groups[i].suburidecodebin,
5896 gst_object_unref (playbin->groups[i].suburidecodebin);
5897 playbin->groups[i].suburidecodebin = NULL;
5901 /* Set our sinks back to NULL, they might not be child of playbin */
5902 if (playbin->audio_sink)
5903 gst_element_set_state (playbin->audio_sink, GST_STATE_NULL);
5904 if (playbin->video_sink)
5905 gst_element_set_state (playbin->video_sink, GST_STATE_NULL);
5906 if (playbin->text_sink)
5907 gst_element_set_state (playbin->text_sink, GST_STATE_NULL);
5909 if (playbin->video_stream_combiner)
5910 gst_element_set_state (playbin->video_stream_combiner, GST_STATE_NULL);
5911 if (playbin->audio_stream_combiner)
5912 gst_element_set_state (playbin->audio_stream_combiner, GST_STATE_NULL);
5913 if (playbin->text_stream_combiner)
5914 gst_element_set_state (playbin->text_stream_combiner, GST_STATE_NULL);
5916 /* make sure the groups don't perform a state change anymore until we
5917 * enable them again */
5918 groups_set_locked_state (playbin, TRUE);
5920 /* Remove all non-persistent contexts */
5921 GST_OBJECT_LOCK (playbin);
5922 for (l = playbin->contexts; l;) {
5923 GstContext *context = l->data;
5925 if (!gst_context_is_persistent (context)) {
5928 gst_context_unref (context);
5931 playbin->contexts = g_list_delete_link (playbin->contexts, l);
5938 if (playbin->source) {
5939 gst_object_unref (playbin->source);
5940 playbin->source = NULL;
5943 GST_OBJECT_UNLOCK (playbin);
5950 if (ret == GST_STATE_CHANGE_NO_PREROLL)
5951 do_async_done (playbin);
5958 do_async_done (playbin);
5960 if (transition == GST_STATE_CHANGE_READY_TO_PAUSED) {
5961 GstSourceGroup *curr_group;
5963 curr_group = playbin->curr_group;
5965 if (curr_group->active && curr_group->valid) {
5966 /* unlink our pads with the sink */
5967 deactivate_group (playbin, curr_group);
5969 curr_group->valid = FALSE;
5972 /* Swap current and next group back */
5973 playbin->curr_group = playbin->next_group;
5974 playbin->next_group = curr_group;
5981 gst_play_bin_overlay_expose (GstVideoOverlay * overlay)
5983 GstPlayBin *playbin = GST_PLAY_BIN (overlay);
5985 gst_video_overlay_expose (GST_VIDEO_OVERLAY (playbin->playsink));
5989 gst_play_bin_overlay_handle_events (GstVideoOverlay * overlay,
5990 gboolean handle_events)
5992 GstPlayBin *playbin = GST_PLAY_BIN (overlay);
5994 gst_video_overlay_handle_events (GST_VIDEO_OVERLAY (playbin->playsink),
5999 gst_play_bin_overlay_set_render_rectangle (GstVideoOverlay * overlay, gint x,
6000 gint y, gint width, gint height)
6002 GstPlayBin *playbin = GST_PLAY_BIN (overlay);
6004 gst_video_overlay_set_render_rectangle (GST_VIDEO_OVERLAY (playbin->playsink),
6005 x, y, width, height);
6009 gst_play_bin_overlay_set_window_handle (GstVideoOverlay * overlay,
6012 GstPlayBin *playbin = GST_PLAY_BIN (overlay);
6014 gst_video_overlay_set_window_handle (GST_VIDEO_OVERLAY (playbin->playsink),
6019 gst_play_bin_overlay_init (gpointer g_iface, gpointer g_iface_data)
6021 GstVideoOverlayInterface *iface = (GstVideoOverlayInterface *) g_iface;
6022 iface->expose = gst_play_bin_overlay_expose;
6023 iface->handle_events = gst_play_bin_overlay_handle_events;
6024 iface->set_render_rectangle = gst_play_bin_overlay_set_render_rectangle;
6025 iface->set_window_handle = gst_play_bin_overlay_set_window_handle;
6029 gst_play_bin_navigation_send_event (GstNavigation * navigation,
6030 GstStructure * structure)
6032 GstPlayBin *playbin = GST_PLAY_BIN (navigation);
6034 gst_navigation_send_event (GST_NAVIGATION (playbin->playsink), structure);
6038 gst_play_bin_navigation_init (gpointer g_iface, gpointer g_iface_data)
6040 GstNavigationInterface *iface = (GstNavigationInterface *) g_iface;
6042 iface->send_event = gst_play_bin_navigation_send_event;
6045 static const GList *
6046 gst_play_bin_colorbalance_list_channels (GstColorBalance * balance)
6048 GstPlayBin *playbin = GST_PLAY_BIN (balance);
6051 gst_color_balance_list_channels (GST_COLOR_BALANCE (playbin->playsink));
6055 gst_play_bin_colorbalance_set_value (GstColorBalance * balance,
6056 GstColorBalanceChannel * channel, gint value)
6058 GstPlayBin *playbin = GST_PLAY_BIN (balance);
6060 gst_color_balance_set_value (GST_COLOR_BALANCE (playbin->playsink), channel,
6065 gst_play_bin_colorbalance_get_value (GstColorBalance * balance,
6066 GstColorBalanceChannel * channel)
6068 GstPlayBin *playbin = GST_PLAY_BIN (balance);
6070 return gst_color_balance_get_value (GST_COLOR_BALANCE (playbin->playsink),
6074 static GstColorBalanceType
6075 gst_play_bin_colorbalance_get_balance_type (GstColorBalance * balance)
6077 GstPlayBin *playbin = GST_PLAY_BIN (balance);
6080 gst_color_balance_get_balance_type (GST_COLOR_BALANCE
6081 (playbin->playsink));
6085 gst_play_bin_colorbalance_init (gpointer g_iface, gpointer g_iface_data)
6087 GstColorBalanceInterface *iface = (GstColorBalanceInterface *) g_iface;
6089 iface->list_channels = gst_play_bin_colorbalance_list_channels;
6090 iface->set_value = gst_play_bin_colorbalance_set_value;
6091 iface->get_value = gst_play_bin_colorbalance_get_value;
6092 iface->get_balance_type = gst_play_bin_colorbalance_get_balance_type;
6096 gst_play_bin2_plugin_init (GstPlugin * plugin)
6098 GST_DEBUG_CATEGORY_INIT (gst_play_bin_debug, "playbin", 0, "play bin");
6100 return gst_element_register (plugin, "playbin", GST_RANK_NONE,