Don't use bad gst_element_get_pad().
[platform/upstream/gstreamer.git] / gst / playback / gstplaybin.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /**
21  * SECTION:element-playbin
22  *
23  * <refsect2>
24  * <para>
25  * Playbin provides a stand-alone everything-in-one abstraction for an
26  * audio and/or video player.
27  * </para>
28  * <para>
29  * It can handle both audio and video files and features
30  * <itemizedlist>
31  * <listitem>
32  * automatic file type recognition and based on that automatic
33  * selection and usage of the right audio/video/subtitle demuxers/decoders
34  * </listitem>
35  * <listitem>
36  * visualisations for audio files
37  * </listitem>
38  * <listitem>
39  * subtitle support for video files
40  * </listitem>
41  * <listitem>
42  * stream selection between different audio/subtitles streams
43  * </listitem>
44  * <listitem>
45  * meta info (tag) extraction
46  * </listitem>
47  * <listitem>
48  * easy access to the last video frame
49  * </listitem>
50  * <listitem>
51  * buffering when playing streams over a network
52  * </listitem>
53  * <listitem>
54  * volume control
55  * </listitem>
56  * </itemizedlist>
57  * </para>
58  * <title>Usage</title>
59  * <para>
60  * A playbin element can be created just like any other element using
61  * gst_element_factory_make(). The file/URI to play should be set via the "uri"
62  * property. This must be an absolute URI, relative file paths are not allowed.
63  * Example URIs are file:///home/joe/movie.avi or http://www.joedoe.com/foo.ogg
64  * </para>
65  * <para>
66  * Playbin is a #GstPipeline. It will notify the application of everything
67  * that's happening (errors, end of stream, tags found, state changes, etc.)
68  * by posting messages on its #GstBus. The application needs to watch the
69  * bus.
70  * </para>
71  * <para>
72  * Playback can be initiated by setting the element to PLAYING state using
73  * gst_element_set_state(). Note that the state change will take place in
74  * the background in a separate thread, when the function returns playback
75  * is probably not happening yet and any errors might not have occured yet.
76  * Applications using playbin should ideally be written to deal with things
77  * completely asynchroneous.
78  * </para>
79  * <para>
80  * When playback has finished (an EOS message has been received on the bus)
81  * or an error has occured (an ERROR message has been received on the bus) or
82  * the user wants to play a different track, playbin should be set back to
83  * READY or NULL state, then the "uri" property should be set to the new
84  * location and then playbin be set to PLAYING state again.
85  * </para>
86  * <para>
87  * Seeking can be done using gst_element_seek_simple() or gst_element_seek()
88  * on the playbin element. Again, the seek will not be executed
89  * instantaneously, but will be done in a background thread. When the seek
90  * call returns the seek will most likely still be in process. An application
91  * may wait for the seek to finish (or fail) using gst_element_get_state() with
92  * -1 as the timeout, but this will block the user interface and is not
93  * recommended at all.
94  * </para>
95  * <para>
96  * Applications may query the current position and duration of the stream
97  * via gst_element_query_position() and gst_element_query_duration() and
98  * setting the format passed to GST_FORMAT_TIME. If the query was successful,
99  * the duration or position will have been returned in units of nanoseconds.
100  * </para>
101  * <title>Advanced Usage: specifying the audio and video sink</title>
102  * <para>
103  * By default, if no audio sink or video sink has been specified via the
104  * "audio-sink" or "video-sink" property, playbin will use the autoaudiosink
105  * and autovideosink elements to find the first-best available output method.
106  * This should work in most cases, but is not always desirable. Often either
107  * the user or application might want to specify more explicitly what to use
108  * for audio and video output.
109  * </para>
110  * <para>
111  * If the application wants more control over how audio or video should be
112  * output, it may create the audio/video sink elements itself (for example
113  * using gst_element_factory_make()) and provide them to playbin using the
114  * "audio-sink" or "video-sink" property.
115  * </para>
116  * <para>
117  * GNOME-based applications, for example, will usually want to create
118  * gconfaudiosink and gconfvideosink elements and make playbin use those,
119  * so that output happens to whatever the user has configured in the GNOME
120  * Multimedia System Selector confinguration dialog.
121  * </para>
122  * <para>
123  * The sink elements do not necessarily need to be ready-made sinks. It is
124  * possible to create container elements that look like a sink to playbin,
125  * but in reality contain a number of custom elements linked together. This
126  * can be achieved by creating a #GstBin and putting elements in there and
127  * linking them, and then creating a sink #GstGhostPad for the bin and pointing
128  * it to the sink pad of the first element within the bin. This can be used
129  * for a number of purposes, for example to force output to a particular
130  * format or to modify or observe the data before it is output.
131  * </para>
132  * <para>
133  * It is also possible to 'suppress' audio and/or video output by using
134  * 'fakesink' elements (or capture it from there using the fakesink element's
135  * "handoff" signal, which, nota bene, is fired from the streaming thread!).
136  * </para>
137  * <title>Retrieving Tags and Other Meta Data</title>
138  * <para>
139  * Most of the common meta data (artist, title, etc.) can be retrieved by
140  * watching for TAG messages on the pipeline's bus (see above).
141  * </para>
142  * <para>
143  * Other more specific meta information like width/height/framerate of video
144  * streams or samplerate/number of channels of audio streams can be obtained
145  * using the "stream-info" property, which will return a GList of stream info
146  * objects, one for each stream. These are opaque objects that can only be
147  * accessed via the standard GObject property interface, ie. g_object_get().
148  * Each stream info object has the following properties:
149  * <itemizedlist>
150  * <listitem>"object" (GstObject) (the decoder source pad usually)</listitem>
151  * <listitem>"type" (enum) (if this is an audio/video/subtitle stream)</listitem>
152  * <listitem>"decoder" (string) (name of decoder used to decode this stream)</listitem>
153  * <listitem>"mute" (boolean) (to mute or unmute this stream)</listitem>
154  * <listitem>"caps" (GstCaps) (caps of the decoded stream)</listitem>
155  * <listitem>"language-code" (string) (ISO-639 language code for this stream, mostly used for audio/subtitle streams)</listitem>
156  * <listitem>"codec" (string) (format this stream was encoded in)</listitem>
157  * </itemizedlist>
158  * Stream information from the stream-info properties is best queried once
159  * playbin has changed into PAUSED or PLAYING state (which can be detected
160  * via a state-changed message on the bus where old_state=READY and
161  * new_state=PAUSED), since before that the list might not be complete yet or
162  * not contain all available information (like language-codes).
163  * </para>
164  * <title>Buffering</title>
165  * <para>
166  * Playbin handles buffering automatically for the most part, but applications
167  * need to handle parts of the buffering process as well. Whenever playbin is
168  * buffering, it will post BUFFERING messages on the bus with a percentage
169  * value that shows the progress of the buffering process. Applications need
170  * to set playbin to PLAYING or PAUSED state in response to these messages.
171  * They may also want to convey the buffering progress to the user in some
172  * way. Here is how to extract the percentage information from the message
173  * (requires GStreamer >= 0.10.11):
174  * </para>
175  * <para>
176  * <programlisting>
177  * switch (GST_MESSAGE_TYPE (msg)) {
178  *   case GST_MESSAGE_BUFFERING: {
179  *     gint percent = 0;
180  *     gst_message_parse_buffering (msg, &amp;percent);
181  *     g_print ("Buffering (%%u percent done)", percent);
182  *     break;
183  *   }
184  *   ...
185  * }
186  * </programlisting>
187  * Note that applications should keep/set the pipeline in the PAUSED state when
188  * a BUFFERING message is received with a buffer percent value < 100 and set
189  * the pipeline back to PLAYING state when a BUFFERING message with a value
190  * of 100 percent is received (if PLAYING is the desired state, that is).
191  * </para>
192  * <title>Embedding the video window in your application</title>
193  * <para>
194  * By default, playbin (or rather the video sinks used) will create their own
195  * window. Applications will usually want to force output to a window of their
196  * own, however. This can be done using the GstXOverlay interface, which most
197  * video sinks implement. See the documentation there for more details.
198  * </para>
199  * <title>Specifying which CD/DVD device to use</title>
200  * <para>
201  * The device to use for CDs/DVDs needs to be set on the source element
202  * playbin creates before it is opened. The only way to do this at the moment
203  * is to connect to playbin's "notify::source" signal, which will be emitted
204  * by playbin when it has created the source element for a particular URI.
205  * In the signal callback you can check if the source element has a "device"
206  * property and set it appropriately. In future ways might be added to specify
207  * the device as part of the URI, but at the time of writing this is not
208  * possible yet.
209  * </para>
210  * <title>Examples</title>
211  * <para>
212  * Here is a simple pipeline to play back a video or audio file:
213  * <programlisting>
214  * gst-launch -v playbin uri=file:///path/to/somefile.avi
215  * </programlisting>
216  * This will play back the given AVI video file, given that the video and
217  * audio decoders required to decode the content are installed. Since no
218  * special audio sink or video sink is supplied (not possible via gst-launch),
219  * playbin will try to find a suitable audio and video sink automatically
220  * using the autoaudiosink and autovideosink elements.
221  * </para>
222  * <para>
223  * Here is a another pipeline to play track 4 of an audio CD:
224  * <programlisting>
225  * gst-launch -v playbin uri=cdda://4
226  * </programlisting>
227  * This will play back track 4 on an audio CD in your disc drive (assuming
228  * the drive is detected automatically by the plugin).
229  * </para>
230  * <para>
231  * Here is a another pipeline to play title 1 of a DVD:
232  * <programlisting>
233  * gst-launch -v playbin uri=dvd://1
234  * </programlisting>
235  * This will play back title 1 of a DVD in your disc drive (assuming
236  * the drive is detected automatically by the plugin).
237  * </para>
238  * </refsect2>
239  */
240
241 #ifdef HAVE_CONFIG_H
242 #include "config.h"
243 #endif
244
245 #include <string.h>
246 #include <gst/gst.h>
247
248 #include <gst/gst-i18n-plugin.h>
249 #include <gst/pbutils/pbutils.h>
250
251 #include "gstplaybasebin.h"
252
253 GST_DEBUG_CATEGORY_STATIC (gst_play_bin_debug);
254 #define GST_CAT_DEFAULT gst_play_bin_debug
255
256 #define GST_TYPE_PLAY_BIN               (gst_play_bin_get_type())
257 #define GST_PLAY_BIN(obj)               (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_PLAY_BIN,GstPlayBin))
258 #define GST_PLAY_BIN_CLASS(klass)       (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_PLAY_BIN,GstPlayBinClass))
259 #define GST_IS_PLAY_BIN(obj)            (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_PLAY_BIN))
260 #define GST_IS_PLAY_BIN_CLASS(klass)    (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_PLAY_BIN))
261
262 #define VOLUME_MAX_DOUBLE 10.0
263
264 typedef struct _GstPlayBin GstPlayBin;
265 typedef struct _GstPlayBinClass GstPlayBinClass;
266
267 struct _GstPlayBin
268 {
269   GstPlayBaseBin parent;
270
271   /* the configurable elements */
272   GstElement *fakesink;
273   GstElement *audio_sink;
274   GstElement *video_sink;
275   GstElement *visualisation;
276   GstElement *pending_visualisation;
277   GstElement *volume_element;
278   GstElement *textoverlay_element;
279   gfloat volume;
280
281   /* these are the currently active sinks */
282   GList *sinks;
283
284   /* the last captured frame for snapshots */
285   GstBuffer *frame;
286
287   /* our cache for the sinks */
288   GHashTable *cache;
289
290   /* font description */
291   gchar *font_desc;
292
293   /* indication if the pipeline is live */
294   gboolean is_live;
295 };
296
297 struct _GstPlayBinClass
298 {
299   GstPlayBaseBinClass parent_class;
300 };
301
302 /* props */
303 enum
304 {
305   ARG_0,
306   ARG_AUDIO_SINK,
307   ARG_VIDEO_SINK,
308   ARG_VIS_PLUGIN,
309   ARG_VOLUME,
310   ARG_FRAME,
311   ARG_FONT_DESC
312 };
313
314 /* signals */
315 enum
316 {
317   LAST_SIGNAL
318 };
319
320 static void gst_play_bin_class_init (GstPlayBinClass * klass);
321 static void gst_play_bin_init (GstPlayBin * play_bin);
322 static void gst_play_bin_dispose (GObject * object);
323
324 static gboolean setup_sinks (GstPlayBaseBin * play_base_bin,
325     GstPlayBaseGroup * group);
326 static void remove_sinks (GstPlayBin * play_bin);
327 static void playbin_set_subtitles_visible (GstPlayBaseBin * play_base_bin,
328     gboolean visible);
329 static void playbin_set_audio_mute (GstPlayBaseBin * play_base_bin,
330     gboolean mute);
331
332 static void gst_play_bin_set_property (GObject * object, guint prop_id,
333     const GValue * value, GParamSpec * spec);
334 static void gst_play_bin_get_property (GObject * object, guint prop_id,
335     GValue * value, GParamSpec * spec);
336
337 static gboolean gst_play_bin_send_event (GstElement * element,
338     GstEvent * event);
339 static GstStateChangeReturn gst_play_bin_change_state (GstElement * element,
340     GstStateChange transition);
341
342 static void gst_play_bin_handle_message (GstBin * bin, GstMessage * message);
343
344 static GstElementClass *parent_class;
345
346 //static guint gst_play_bin_signals[LAST_SIGNAL] = { 0 };
347
348 static const GstElementDetails gst_play_bin_details =
349 GST_ELEMENT_DETAILS ("Player Bin",
350     "Generic/Bin/Player",
351     "Autoplug and play media from an uri",
352     "Wim Taymans <wim.taymans@gmail.com>");
353
354 static GType
355 gst_play_bin_get_type (void)
356 {
357   static GType gst_play_bin_type = 0;
358
359   if (!gst_play_bin_type) {
360     static const GTypeInfo gst_play_bin_info = {
361       sizeof (GstPlayBinClass),
362       NULL,
363       NULL,
364       (GClassInitFunc) gst_play_bin_class_init,
365       NULL,
366       NULL,
367       sizeof (GstPlayBin),
368       0,
369       (GInstanceInitFunc) gst_play_bin_init,
370       NULL
371     };
372
373     gst_play_bin_type = g_type_register_static (GST_TYPE_PLAY_BASE_BIN,
374         "GstPlayBin", &gst_play_bin_info, 0);
375   }
376
377   return gst_play_bin_type;
378 }
379
380 static void
381 gst_play_bin_class_init (GstPlayBinClass * klass)
382 {
383   GObjectClass *gobject_klass;
384   GstElementClass *gstelement_klass;
385   GstBinClass *gstbin_klass;
386   GstPlayBaseBinClass *playbasebin_klass;
387
388   gobject_klass = (GObjectClass *) klass;
389   gstelement_klass = (GstElementClass *) klass;
390   gstbin_klass = (GstBinClass *) klass;
391   playbasebin_klass = (GstPlayBaseBinClass *) klass;
392
393   parent_class = g_type_class_peek_parent (klass);
394
395   gobject_klass->set_property = gst_play_bin_set_property;
396   gobject_klass->get_property = gst_play_bin_get_property;
397
398   g_object_class_install_property (gobject_klass, ARG_VIDEO_SINK,
399       g_param_spec_object ("video-sink", "Video Sink",
400           "the video output element to use (NULL = default sink)",
401           GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
402   g_object_class_install_property (gobject_klass, ARG_AUDIO_SINK,
403       g_param_spec_object ("audio-sink", "Audio Sink",
404           "the audio output element to use (NULL = default sink)",
405           GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
406   g_object_class_install_property (gobject_klass, ARG_VIS_PLUGIN,
407       g_param_spec_object ("vis-plugin", "Vis plugin",
408           "the visualization element to use (NULL = none)",
409           GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
410   g_object_class_install_property (gobject_klass, ARG_VOLUME,
411       g_param_spec_double ("volume", "volume", "volume",
412           0.0, VOLUME_MAX_DOUBLE, 1.0,
413           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
414   g_object_class_install_property (gobject_klass, ARG_FRAME,
415       gst_param_spec_mini_object ("frame", "Frame",
416           "The last frame (NULL = no video available)", GST_TYPE_BUFFER,
417           G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
418   g_object_class_install_property (gobject_klass, ARG_FONT_DESC,
419       g_param_spec_string ("subtitle-font-desc", "Subtitle font description",
420           "Pango font description of font " "to be used for subtitle rendering",
421           NULL, G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
422
423   gobject_klass->dispose = GST_DEBUG_FUNCPTR (gst_play_bin_dispose);
424
425   gst_element_class_set_details (gstelement_klass, &gst_play_bin_details);
426
427   gstelement_klass->change_state =
428       GST_DEBUG_FUNCPTR (gst_play_bin_change_state);
429   gstelement_klass->send_event = GST_DEBUG_FUNCPTR (gst_play_bin_send_event);
430
431   gstbin_klass->handle_message =
432       GST_DEBUG_FUNCPTR (gst_play_bin_handle_message);
433
434   playbasebin_klass->setup_output_pads = setup_sinks;
435   playbasebin_klass->set_subtitles_visible = playbin_set_subtitles_visible;
436   playbasebin_klass->set_audio_mute = playbin_set_audio_mute;
437 }
438
439 static void
440 gst_play_bin_init (GstPlayBin * play_bin)
441 {
442   play_bin->video_sink = NULL;
443   play_bin->audio_sink = NULL;
444   play_bin->visualisation = NULL;
445   play_bin->pending_visualisation = NULL;
446   play_bin->volume_element = NULL;
447   play_bin->textoverlay_element = NULL;
448   play_bin->volume = 1.0;
449   play_bin->sinks = NULL;
450   play_bin->frame = NULL;
451   play_bin->font_desc = NULL;
452   play_bin->cache = g_hash_table_new_full (g_str_hash, g_str_equal,
453       NULL, (GDestroyNotify) gst_object_unref);
454 }
455
456 static void
457 gst_play_bin_dispose (GObject * object)
458 {
459   GstPlayBin *play_bin;
460
461   play_bin = GST_PLAY_BIN (object);
462
463   if (play_bin->cache != NULL) {
464     remove_sinks (play_bin);
465     g_hash_table_destroy (play_bin->cache);
466     play_bin->cache = NULL;
467   }
468
469   if (play_bin->audio_sink != NULL) {
470     gst_element_set_state (play_bin->audio_sink, GST_STATE_NULL);
471     gst_object_unref (play_bin->audio_sink);
472     play_bin->audio_sink = NULL;
473   }
474   if (play_bin->video_sink != NULL) {
475     gst_element_set_state (play_bin->video_sink, GST_STATE_NULL);
476     gst_object_unref (play_bin->video_sink);
477     play_bin->video_sink = NULL;
478   }
479   if (play_bin->visualisation != NULL) {
480     gst_element_set_state (play_bin->visualisation, GST_STATE_NULL);
481     gst_object_unref (play_bin->visualisation);
482     play_bin->visualisation = NULL;
483   }
484   if (play_bin->pending_visualisation != NULL) {
485     gst_element_set_state (play_bin->pending_visualisation, GST_STATE_NULL);
486     gst_object_unref (play_bin->pending_visualisation);
487     play_bin->pending_visualisation = NULL;
488   }
489   if (play_bin->textoverlay_element != NULL) {
490     gst_object_unref (play_bin->textoverlay_element);
491     play_bin->textoverlay_element = NULL;
492   }
493   g_free (play_bin->font_desc);
494   play_bin->font_desc = NULL;
495
496   G_OBJECT_CLASS (parent_class)->dispose (object);
497 }
498
499 static void
500 gst_play_bin_vis_unblocked (GstPad * tee_pad, gboolean blocked,
501     gpointer user_data)
502 {
503   GstPlayBin *play_bin = GST_PLAY_BIN (user_data);
504
505   if (play_bin->pending_visualisation)
506     gst_pad_set_blocked_async (tee_pad, FALSE, gst_play_bin_vis_unblocked,
507         play_bin);
508 }
509
510 static void
511 gst_play_bin_vis_blocked (GstPad * tee_pad, gboolean blocked,
512     gpointer user_data)
513 {
514   GstPlayBin *play_bin = GST_PLAY_BIN (user_data);
515   GstBin *vis_bin = NULL;
516   GstPad *vis_sink_pad = NULL, *vis_src_pad = NULL, *vqueue_pad = NULL;
517   GstState bin_state;
518   GstElement *pending_visualisation;
519
520   GST_OBJECT_LOCK (play_bin);
521   pending_visualisation = play_bin->pending_visualisation;
522   play_bin->pending_visualisation = NULL;
523   GST_OBJECT_UNLOCK (play_bin);
524
525   /* We want to disable visualisation */
526   if (!GST_IS_ELEMENT (pending_visualisation)) {
527     /* Set visualisation element to READY */
528     gst_element_set_state (play_bin->visualisation, GST_STATE_READY);
529     goto beach;
530   }
531
532   vis_bin =
533       GST_BIN_CAST (gst_object_get_parent (GST_OBJECT_CAST (play_bin->
534               visualisation)));
535
536   if (!GST_IS_BIN (vis_bin) || !GST_IS_PAD (tee_pad)) {
537     goto beach;
538   }
539
540   vis_src_pad = gst_element_get_static_pad (play_bin->visualisation, "src");
541   vis_sink_pad = gst_pad_get_peer (tee_pad);
542
543   /* Can be fakesink */
544   if (GST_IS_PAD (vis_src_pad)) {
545     vqueue_pad = gst_pad_get_peer (vis_src_pad);
546   }
547
548   if (!GST_IS_PAD (vis_sink_pad)) {
549     goto beach;
550   }
551
552   /* Check the bin's state */
553   GST_OBJECT_LOCK (vis_bin);
554   bin_state = GST_STATE (vis_bin);
555   GST_OBJECT_UNLOCK (vis_bin);
556
557   /* Unlink */
558   gst_pad_unlink (tee_pad, vis_sink_pad);
559   gst_object_unref (vis_sink_pad);
560   vis_sink_pad = NULL;
561
562   if (GST_IS_PAD (vqueue_pad)) {
563     gst_pad_unlink (vis_src_pad, vqueue_pad);
564     gst_object_unref (vis_src_pad);
565     vis_src_pad = NULL;
566   }
567
568   /* Remove from vis_bin */
569   gst_bin_remove (vis_bin, play_bin->visualisation);
570   /* Set state to NULL */
571   gst_element_set_state (play_bin->visualisation, GST_STATE_NULL);
572   /* And loose our ref */
573   gst_object_unref (play_bin->visualisation);
574
575   if (pending_visualisation) {
576     /* Ref this new visualisation element before adding to the bin */
577     gst_object_ref (pending_visualisation);
578     /* Add the new one */
579     gst_bin_add (vis_bin, pending_visualisation);
580     /* Synchronizing state */
581     gst_element_set_state (pending_visualisation, bin_state);
582
583     vis_sink_pad = gst_element_get_static_pad (pending_visualisation, "sink");
584     vis_src_pad = gst_element_get_static_pad (pending_visualisation, "src");
585
586     if (!GST_IS_PAD (vis_sink_pad) || !GST_IS_PAD (vis_src_pad)) {
587       goto beach;
588     }
589
590     /* Link */
591     gst_pad_link (tee_pad, vis_sink_pad);
592     gst_pad_link (vis_src_pad, vqueue_pad);
593   }
594
595   /* We are done */
596   gst_object_unref (play_bin->visualisation);
597   play_bin->visualisation = pending_visualisation;
598
599 beach:
600   if (vis_sink_pad) {
601     gst_object_unref (vis_sink_pad);
602   }
603   if (vis_src_pad) {
604     gst_object_unref (vis_src_pad);
605   }
606   if (vqueue_pad) {
607     gst_object_unref (vqueue_pad);
608   }
609   if (vis_bin) {
610     gst_object_unref (vis_bin);
611   }
612
613   /* Unblock the pad */
614   gst_pad_set_blocked_async (tee_pad, FALSE, gst_play_bin_vis_unblocked,
615       play_bin);
616 }
617
618 static void
619 gst_play_bin_set_property (GObject * object, guint prop_id,
620     const GValue * value, GParamSpec * pspec)
621 {
622   GstPlayBin *play_bin;
623
624   play_bin = GST_PLAY_BIN (object);
625
626   switch (prop_id) {
627     case ARG_VIDEO_SINK:
628       if (play_bin->video_sink != NULL) {
629         gst_object_unref (play_bin->video_sink);
630       }
631       play_bin->video_sink = g_value_get_object (value);
632       if (play_bin->video_sink != NULL) {
633         gst_object_ref (play_bin->video_sink);
634         gst_object_sink (GST_OBJECT_CAST (play_bin->video_sink));
635       }
636       /* when changing the videosink, we just remove the
637        * video pipeline from the cache so that it will be
638        * regenerated with the new sink element */
639       g_hash_table_remove (play_bin->cache, "vbin");
640       break;
641     case ARG_AUDIO_SINK:
642       if (play_bin->audio_sink != NULL) {
643         gst_object_unref (play_bin->audio_sink);
644       }
645       play_bin->audio_sink = g_value_get_object (value);
646       if (play_bin->audio_sink != NULL) {
647         gst_object_ref (play_bin->audio_sink);
648         gst_object_sink (GST_OBJECT_CAST (play_bin->audio_sink));
649       }
650       g_hash_table_remove (play_bin->cache, "abin");
651       break;
652     case ARG_VIS_PLUGIN:
653     {
654       GstElement *pending_visualisation =
655           GST_ELEMENT_CAST (g_value_get_object (value));
656
657       /* Take ownership */
658       if (pending_visualisation) {
659         gst_object_ref (pending_visualisation);
660         gst_object_sink (pending_visualisation);
661       }
662
663       /* Do we already have a visualisation change pending ? */
664       GST_OBJECT_LOCK (play_bin);
665       if (play_bin->pending_visualisation) {
666         gst_object_unref (play_bin->pending_visualisation);
667         play_bin->pending_visualisation = pending_visualisation;
668         GST_OBJECT_UNLOCK (play_bin);
669       } else {
670         GST_OBJECT_UNLOCK (play_bin);
671         /* Was there a visualisation already set ? */
672         if (play_bin->visualisation != NULL) {
673           GstBin *vis_bin = NULL;
674
675           vis_bin =
676               GST_BIN_CAST (gst_object_get_parent (GST_OBJECT_CAST (play_bin->
677                       visualisation)));
678
679           /* Check if the visualisation is already in a bin */
680           if (GST_IS_BIN (vis_bin)) {
681             GstPad *vis_sink_pad = NULL, *tee_pad = NULL;
682
683             /* Now get tee pad and block it async */
684             vis_sink_pad = gst_element_get_static_pad (play_bin->visualisation,
685                 "sink");
686             if (!GST_IS_PAD (vis_sink_pad)) {
687               goto beach;
688             }
689             tee_pad = gst_pad_get_peer (vis_sink_pad);
690             if (!GST_IS_PAD (tee_pad)) {
691               goto beach;
692             }
693
694             play_bin->pending_visualisation = pending_visualisation;
695             /* Block with callback */
696             gst_pad_set_blocked_async (tee_pad, TRUE, gst_play_bin_vis_blocked,
697                 play_bin);
698           beach:
699             if (vis_sink_pad) {
700               gst_object_unref (vis_sink_pad);
701             }
702             if (tee_pad) {
703               gst_object_unref (tee_pad);
704             }
705             gst_object_unref (vis_bin);
706           } else {
707             play_bin->visualisation = pending_visualisation;
708           }
709         } else {
710           play_bin->visualisation = pending_visualisation;
711         }
712       }
713       break;
714     }
715     case ARG_VOLUME:
716       play_bin->volume = g_value_get_double (value);
717       if (play_bin->volume_element) {
718         g_object_set (G_OBJECT (play_bin->volume_element), "volume",
719             play_bin->volume, NULL);
720       }
721       break;
722     case ARG_FONT_DESC:
723       g_free (play_bin->font_desc);
724       play_bin->font_desc = g_strdup (g_value_get_string (value));
725       if (play_bin->textoverlay_element) {
726         g_object_set (G_OBJECT (play_bin->textoverlay_element),
727             "font-desc", g_value_get_string (value), NULL);
728       }
729       break;
730     default:
731       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
732       break;
733   }
734 }
735
736 static void
737 gst_play_bin_get_property (GObject * object, guint prop_id, GValue * value,
738     GParamSpec * pspec)
739 {
740   GstPlayBin *play_bin;
741
742   play_bin = GST_PLAY_BIN (object);
743
744   switch (prop_id) {
745     case ARG_VIDEO_SINK:
746       g_value_set_object (value, play_bin->video_sink);
747       break;
748     case ARG_AUDIO_SINK:
749       g_value_set_object (value, play_bin->audio_sink);
750       break;
751     case ARG_VIS_PLUGIN:
752       g_value_set_object (value, play_bin->visualisation);
753       break;
754     case ARG_VOLUME:
755       g_value_set_double (value, play_bin->volume);
756       break;
757     case ARG_FRAME:{
758       GstBuffer *cur_frame = NULL;
759
760       gst_buffer_replace (&cur_frame, play_bin->frame);
761       gst_value_take_buffer (value, cur_frame);
762       break;
763     }
764     default:
765       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
766       break;
767   }
768 }
769
770 /* signal fired when the identity has received a new buffer. This is used for
771  * making screenshots.
772  */
773 static void
774 handoff (GstElement * identity, GstBuffer * frame, gpointer data)
775 {
776   GstPlayBin *play_bin = GST_PLAY_BIN (data);
777
778   /* applications need to know the buffer caps,
779    * make sure they are always set on the frame */
780   if (GST_BUFFER_CAPS (frame) == NULL) {
781     GstPad *pad;
782
783     if ((pad = gst_element_get_static_pad (identity, "sink"))) {
784       gst_buffer_set_caps (frame, GST_PAD_CAPS (pad));
785       gst_object_unref (pad);
786     }
787   }
788
789   gst_buffer_replace (&play_bin->frame, frame);
790 }
791
792 static void
793 post_missing_element_message (GstPlayBin * playbin, const gchar * name)
794 {
795   GstMessage *msg;
796
797   msg = gst_missing_element_message_new (GST_ELEMENT_CAST (playbin), name);
798   gst_element_post_message (GST_ELEMENT_CAST (playbin), msg);
799 }
800
801 /* make the element (bin) that contains the elements needed to perform
802  * video display. We connect a handoff signal to identity so that we
803  * can grab snapshots. Identity's sinkpad is ghosted to vbin.
804  *
805  *  +-------------------------------------------------------------+
806  *  | vbin                                                        |
807  *  |      +--------+   +----------+   +----------+   +---------+ |
808  *  |      |identity|   |colorspace|   |videoscale|   |videosink| |
809  *  |   +-sink     src-sink       src-sink       src-sink       | |
810  *  |   |  +---+----+   +----------+   +----------+   +---------+ |
811  * sink-+      |                                                  |
812  *  +----------|--------------------------------------------------+
813  *           handoff
814  */
815 static GstElement *
816 gen_video_element (GstPlayBin * play_bin)
817 {
818   GstElement *element;
819   GstElement *conv;
820
821   GstElement *scale;
822   GstElement *sink;
823   GstElement *identity;
824   GstPad *pad;
825
826   /* first see if we have it in the cache */
827   element = g_hash_table_lookup (play_bin->cache, "vbin");
828   if (element != NULL) {
829     return element;
830   }
831
832   if (play_bin->video_sink) {
833     sink = play_bin->video_sink;
834   } else {
835     sink = gst_element_factory_make ("autovideosink", "videosink");
836     if (sink == NULL) {
837       sink = gst_element_factory_make ("xvimagesink", "videosink");
838     }
839     if (sink == NULL)
840       goto no_sinks;
841   }
842   gst_object_ref (sink);
843   g_hash_table_insert (play_bin->cache, "video_sink", sink);
844
845   /* create a bin to hold objects, as we create them we add them to this bin so
846    * that when something goes wrong we only need to unref the bin */
847   element = gst_bin_new ("vbin");
848   gst_bin_add (GST_BIN_CAST (element), sink);
849
850   conv = gst_element_factory_make ("ffmpegcolorspace", "vconv");
851   if (conv == NULL)
852     goto no_colorspace;
853   gst_bin_add (GST_BIN_CAST (element), conv);
854
855   scale = gst_element_factory_make ("videoscale", "vscale");
856   if (scale == NULL)
857     goto no_videoscale;
858   gst_bin_add (GST_BIN_CAST (element), scale);
859
860   identity = gst_element_factory_make ("identity", "id");
861   g_object_set (identity, "silent", TRUE, NULL);
862   g_signal_connect (identity, "handoff", G_CALLBACK (handoff), play_bin);
863   gst_bin_add (GST_BIN_CAST (element), identity);
864
865   gst_element_link_pads (identity, "src", conv, "sink");
866   gst_element_link_pads (conv, "src", scale, "sink");
867   /* be more careful with the pad from the custom sink element, it might not
868    * be named 'sink' */
869   if (!gst_element_link_pads (scale, "src", sink, NULL))
870     goto link_failed;
871
872   pad = gst_element_get_static_pad (identity, "sink");
873   gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
874   gst_object_unref (pad);
875
876   gst_element_set_state (element, GST_STATE_READY);
877
878   /* since we're gonna add it to a bin but don't want to lose it,
879    * we keep a reference. */
880   gst_object_ref (element);
881   g_hash_table_insert (play_bin->cache, "vbin", element);
882
883   return element;
884
885   /* ERRORS */
886 no_sinks:
887   {
888     post_missing_element_message (play_bin, "autovideosink");
889     GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
890         (_("Both autovideosink and xvimagesink elements are missing.")),
891         (NULL));
892     return NULL;
893   }
894 no_colorspace:
895   {
896     post_missing_element_message (play_bin, "ffmpegcolorspace");
897     GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
898         (_("Missing element '%s' - check your GStreamer installation."),
899             "ffmpegcolorspace"), (NULL));
900     gst_object_unref (element);
901     return NULL;
902   }
903
904 no_videoscale:
905   {
906     post_missing_element_message (play_bin, "videoscale");
907     GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
908         (_("Missing element '%s' - check your GStreamer installation."),
909             "videoscale"), ("possibly a liboil version mismatch?"));
910     gst_object_unref (element);
911     return NULL;
912   }
913 link_failed:
914   {
915     GST_ELEMENT_ERROR (play_bin, CORE, PAD,
916         (NULL), ("Failed to configure the video sink."));
917     gst_object_unref (element);
918     return NULL;
919   }
920 }
921
922 /* make an element for playback of video with subtitles embedded.
923  *
924  *  +--------------------------------------------------+
925  *  | tbin                  +-------------+            |
926  *  |          +-----+      | textoverlay |   +------+ |
927  *  |          | csp | +--video_sink      |   | vbin | |
928  * video_sink-sink  src+ +-text_sink     src-sink    | |
929  *  |          +-----+   |  +-------------+   +------+ |
930  * text_sink-------------+                             |
931  *  +--------------------------------------------------+
932  *
933  *  If there is no subtitle renderer this function will simply return the
934  *  videosink without the text_sink pad.
935  */
936 static GstElement *
937 gen_text_element (GstPlayBin * play_bin)
938 {
939   GstElement *element, *csp, *overlay, *vbin;
940   GstPad *pad;
941
942   /* Create the video rendering bin, error is posted when this fails. */
943   vbin = gen_video_element (play_bin);
944   if (!vbin)
945     return NULL;
946
947   /* Text overlay */
948   overlay = gst_element_factory_make ("textoverlay", "overlay");
949
950   /* If no overlay return the video bin without subtitle support. */
951   if (!overlay)
952     goto no_overlay;
953
954   /* Create our bin */
955   element = gst_bin_new ("textbin");
956
957   /* Set some parameters */
958   g_object_set (G_OBJECT (overlay),
959       "halign", "center", "valign", "bottom", NULL);
960   if (play_bin->font_desc) {
961     g_object_set (G_OBJECT (overlay), "font-desc", play_bin->font_desc, NULL);
962   }
963
964   /* Take a ref */
965   play_bin->textoverlay_element = GST_ELEMENT_CAST (gst_object_ref (overlay));
966
967   /* we know this will succeed, as the video bin already created one before */
968   csp = gst_element_factory_make ("ffmpegcolorspace", "subtitlecsp");
969
970   /* Add our elements */
971   gst_bin_add_many (GST_BIN_CAST (element), csp, overlay, vbin, NULL);
972
973   /* Link */
974   gst_element_link_pads (csp, "src", overlay, "video_sink");
975   gst_element_link_pads (overlay, "src", vbin, "sink");
976
977   /* Add ghost pads on the subtitle bin */
978   pad = gst_element_get_static_pad (overlay, "text_sink");
979   gst_element_add_pad (element, gst_ghost_pad_new ("text_sink", pad));
980   gst_object_unref (pad);
981
982   pad = gst_element_get_static_pad (csp, "sink");
983   gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
984   gst_object_unref (pad);
985
986   /* Set state to READY */
987   gst_element_set_state (element, GST_STATE_READY);
988
989   return element;
990
991   /* ERRORS */
992 no_overlay:
993   {
994     post_missing_element_message (play_bin, "textoverlay");
995     GST_WARNING_OBJECT (play_bin,
996         "No overlay (pango) element, subtitles disabled");
997     return vbin;
998   }
999 }
1000
1001 /* make the element (bin) that contains the elements needed to perform
1002  * audio playback.
1003  *
1004  *  +-------------------------------------------------------------+
1005  *  | abin                                                        |
1006  *  |      +---------+   +----------+   +---------+   +---------+ |
1007  *  |      |audioconv|   |audioscale|   | volume  |   |audiosink| |
1008  *  |   +-sink      src-sink       src-sink      src-sink       | |
1009  *  |   |  +---------+   +----------+   +---------+   +---------+ |
1010  * sink-+                                                         |
1011  *  +-------------------------------------------------------------+
1012  */
1013 static GstElement *
1014 gen_audio_element (GstPlayBin * play_bin)
1015 {
1016   gboolean res;
1017   GstElement *element;
1018   GstElement *conv;
1019   GstElement *scale;
1020   GstElement *sink;
1021   GstElement *volume;
1022   GstPad *pad;
1023
1024   element = g_hash_table_lookup (play_bin->cache, "abin");
1025   if (element != NULL)
1026     return element;
1027
1028   if (play_bin->audio_sink) {
1029     sink = play_bin->audio_sink;
1030   } else {
1031     sink = gst_element_factory_make ("autoaudiosink", "audiosink");
1032     if (sink == NULL) {
1033       sink = gst_element_factory_make ("alsasink", "audiosink");
1034     }
1035     if (sink == NULL)
1036       goto no_sinks;
1037
1038     play_bin->audio_sink = GST_ELEMENT_CAST (gst_object_ref (sink));
1039   }
1040
1041   gst_object_ref (sink);
1042   g_hash_table_insert (play_bin->cache, "audio_sink", sink);
1043
1044   element = gst_bin_new ("abin");
1045   gst_bin_add (GST_BIN_CAST (element), sink);
1046
1047   conv = gst_element_factory_make ("audioconvert", "aconv");
1048   if (conv == NULL)
1049     goto no_audioconvert;
1050   gst_bin_add (GST_BIN_CAST (element), conv);
1051
1052   scale = gst_element_factory_make ("audioresample", "aresample");
1053   if (scale == NULL)
1054     goto no_audioresample;
1055   gst_bin_add (GST_BIN_CAST (element), scale);
1056
1057   volume = gst_element_factory_make ("volume", "volume");
1058   if (volume == NULL)
1059     goto no_volume;
1060   g_object_set (G_OBJECT (volume), "volume", play_bin->volume, NULL);
1061   play_bin->volume_element = volume;
1062   gst_bin_add (GST_BIN_CAST (element), volume);
1063
1064   res = gst_element_link_pads (conv, "src", scale, "sink");
1065   res &= gst_element_link_pads (scale, "src", volume, "sink");
1066   res &= gst_element_link_pads (volume, "src", sink, NULL);
1067   if (!res)
1068     goto link_failed;
1069
1070   pad = gst_element_get_static_pad (conv, "sink");
1071   gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
1072   gst_object_unref (pad);
1073
1074   gst_element_set_state (element, GST_STATE_READY);
1075
1076   /* since we're gonna add it to a bin but don't want to lose it,
1077    * we keep a reference. */
1078   gst_object_ref (element);
1079   g_hash_table_insert (play_bin->cache, "abin", element);
1080
1081   return element;
1082
1083   /* ERRORS */
1084 no_sinks:
1085   {
1086     post_missing_element_message (play_bin, "autoaudiosink");
1087     GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1088         (_("Both autoaudiosink and alsasink elements are missing.")), (NULL));
1089     return NULL;
1090   }
1091 no_audioconvert:
1092   {
1093     post_missing_element_message (play_bin, "audioconvert");
1094     GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1095         (_("Missing element '%s' - check your GStreamer installation."),
1096             "audioconvert"), ("possibly a liboil version mismatch?"));
1097     gst_object_unref (element);
1098     return NULL;
1099   }
1100 no_audioresample:
1101   {
1102     post_missing_element_message (play_bin, "audioresample");
1103     GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1104         (_("Missing element '%s' - check your GStreamer installation."),
1105             "audioresample"), ("possibly a liboil version mismatch?"));
1106     gst_object_unref (element);
1107     return NULL;
1108   }
1109 no_volume:
1110   {
1111     post_missing_element_message (play_bin, "volume");
1112     GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1113         (_("Missing element '%s' - check your GStreamer installation."),
1114             "volume"), ("possibly a liboil version mismatch?"));
1115     gst_object_unref (element);
1116     return NULL;
1117   }
1118 link_failed:
1119   {
1120     GST_ELEMENT_ERROR (play_bin, CORE, PAD,
1121         (NULL), ("Failed to configure the audio sink."));
1122     gst_object_unref (element);
1123     return NULL;
1124   }
1125 }
1126
1127 /* make the element (bin) that contains the elements needed to perform
1128  * visualisation ouput.  The idea is to split the audio using tee, then
1129  * sending the output to the regular audio bin and the other output to
1130  * the vis plugin that transforms it into a video that is rendered with the
1131  * normal video bin. The video and audio bins are run in threads to make sure
1132  * they don't block eachother.
1133  *
1134  *  +-----------------------------------------------------------------------+
1135  *  | visbin                                                                |
1136  *  |      +------+   +--------+   +----------------+                       |
1137  *  |      | tee  |   | aqueue |   |   abin ...     |                       |
1138  *  |   +-sink   src-sink     src-sink              |                       |
1139  *  |   |  |      |   +--------+   +----------------+                       |
1140  *  |   |  |      |                                                         |
1141  *  |   |  |      |   +------+   +------------+   +------+   +-----------+  |
1142  *  |   |  |      |   |vqueue|   | audioconv  |   | vis  |   | vbin ...  |  |
1143  *  |   |  |     src-sink   src-sink + samp  src-sink   src-sink         |  |
1144  *  |   |  |      |   +------+   +------------+   +------+   +-----------+  |
1145  *  |   |  |      |                                                         |
1146  *  |   |  +------+                                                         |
1147  * sink-+                                                                   |
1148  *  +-----------------------------------------------------------------------+
1149  */
1150 static GstElement *
1151 gen_vis_element (GstPlayBin * play_bin)
1152 {
1153   gboolean res;
1154   GstElement *element;
1155   GstElement *tee;
1156   GstElement *asink;
1157   GstElement *vsink;
1158   GstElement *conv;
1159   GstElement *resamp;
1160   GstElement *conv2;
1161   GstElement *vis;
1162   GstElement *vqueue, *aqueue;
1163   GstPad *pad, *rpad;
1164
1165   /* errors are already posted when these fail. */
1166   asink = gen_audio_element (play_bin);
1167   if (!asink)
1168     return NULL;
1169   vsink = gen_video_element (play_bin);
1170   if (!vsink) {
1171     gst_object_unref (asink);
1172     return NULL;
1173   }
1174
1175   element = gst_bin_new ("visbin");
1176   tee = gst_element_factory_make ("tee", "tee");
1177
1178   vqueue = gst_element_factory_make ("queue", "vqueue");
1179   aqueue = gst_element_factory_make ("queue", "aqueue");
1180
1181   gst_bin_add (GST_BIN_CAST (element), asink);
1182   gst_bin_add (GST_BIN_CAST (element), vqueue);
1183   gst_bin_add (GST_BIN_CAST (element), aqueue);
1184   gst_bin_add (GST_BIN_CAST (element), vsink);
1185   gst_bin_add (GST_BIN_CAST (element), tee);
1186
1187   conv = gst_element_factory_make ("audioconvert", "aconv");
1188   if (conv == NULL)
1189     goto no_audioconvert;
1190   gst_bin_add (GST_BIN_CAST (element), conv);
1191
1192   resamp = gst_element_factory_make ("audioresample", "aresamp");
1193   if (resamp == NULL)
1194     goto no_audioresample;
1195   gst_bin_add (GST_BIN_CAST (element), resamp);
1196
1197   conv2 = gst_element_factory_make ("audioconvert", "aconv2");
1198   if (conv2 == NULL)
1199     goto no_audioconvert;
1200   gst_bin_add (GST_BIN_CAST (element), conv2);
1201
1202   if (play_bin->visualisation) {
1203     gst_object_ref (play_bin->visualisation);
1204     vis = play_bin->visualisation;
1205   } else {
1206     vis = gst_element_factory_make ("goom", "vis");
1207     if (!vis)
1208       goto no_goom;
1209   }
1210   gst_bin_add (GST_BIN_CAST (element), vis);
1211
1212   res = gst_element_link_pads (vqueue, "src", conv, "sink");
1213   res &= gst_element_link_pads (conv, "src", resamp, "sink");
1214   res &= gst_element_link_pads (resamp, "src", conv2, "sink");
1215   res &= gst_element_link_pads (conv2, "src", vis, "sink");
1216   res &= gst_element_link_pads (vis, "src", vsink, "sink");
1217   if (!res)
1218     goto link_failed;
1219
1220   pad = gst_element_get_static_pad (aqueue, "sink");
1221   rpad = gst_element_get_request_pad (tee, "src%d");
1222   gst_pad_link (rpad, pad);
1223   gst_object_unref (rpad);
1224   gst_object_unref (pad);
1225   gst_element_link_pads (aqueue, "src", asink, "sink");
1226
1227   pad = gst_element_get_static_pad (vqueue, "sink");
1228   rpad = gst_element_get_request_pad (tee, "src%d");
1229   gst_pad_link (rpad, pad);
1230   gst_object_unref (rpad);
1231   gst_object_unref (pad);
1232
1233   pad = gst_element_get_static_pad (tee, "sink");
1234   gst_element_add_pad (element, gst_ghost_pad_new ("sink", pad));
1235   gst_object_unref (pad);
1236
1237   return element;
1238
1239   /* ERRORS */
1240 no_audioconvert:
1241   {
1242     post_missing_element_message (play_bin, "audioconvert");
1243     GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1244         (_("Missing element '%s' - check your GStreamer installation."),
1245             "audioconvert"), ("possibly a liboil version mismatch?"));
1246     gst_object_unref (element);
1247     return NULL;
1248   }
1249 no_audioresample:
1250   {
1251     post_missing_element_message (play_bin, "audioresample");
1252     GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1253         (_("Missing element '%s' - check your GStreamer installation."),
1254             "audioresample"), (NULL));
1255     gst_object_unref (element);
1256     return NULL;
1257   }
1258 no_goom:
1259   {
1260     post_missing_element_message (play_bin, "goom");
1261     GST_ELEMENT_ERROR (play_bin, CORE, MISSING_PLUGIN,
1262         (_("Missing element '%s' - check your GStreamer installation."),
1263             "goom"), (NULL));
1264     gst_object_unref (element);
1265     return NULL;
1266   }
1267 link_failed:
1268   {
1269     GST_ELEMENT_ERROR (play_bin, CORE, PAD,
1270         (NULL), ("Failed to configure the visualisation element."));
1271     gst_object_unref (element);
1272     return NULL;
1273   }
1274 }
1275
1276 /* get rid of all installed sinks */
1277 static void
1278 remove_sinks (GstPlayBin * play_bin)
1279 {
1280   GList *sinks;
1281   GstObject *parent;
1282   GstElement *element;
1283   GstPad *pad, *peer;
1284
1285   if (play_bin->cache == NULL)
1286     return;
1287
1288   GST_DEBUG ("removesinks");
1289   element = g_hash_table_lookup (play_bin->cache, "abin");
1290   if (element != NULL) {
1291     parent = gst_element_get_parent (element);
1292     if (parent != NULL) {
1293       /* we remove the element from the parent so that
1294        * there is no unwanted state change when the parent
1295        * is disposed */
1296       play_bin->sinks = g_list_remove (play_bin->sinks, element);
1297       gst_element_set_state (element, GST_STATE_NULL);
1298       gst_bin_remove (GST_BIN_CAST (parent), element);
1299       gst_object_unref (parent);
1300     }
1301     pad = gst_element_get_static_pad (element, "sink");
1302     if (pad != NULL) {
1303       peer = gst_pad_get_peer (pad);
1304       if (peer != NULL) {
1305         gst_pad_unlink (peer, pad);
1306         gst_object_unref (peer);
1307       }
1308       gst_object_unref (pad);
1309     }
1310   }
1311   element = g_hash_table_lookup (play_bin->cache, "vbin");
1312   if (element != NULL) {
1313     parent = gst_element_get_parent (element);
1314     if (parent != NULL) {
1315       play_bin->sinks = g_list_remove (play_bin->sinks, element);
1316       gst_element_set_state (element, GST_STATE_NULL);
1317       gst_bin_remove (GST_BIN_CAST (parent), element);
1318       gst_object_unref (parent);
1319     }
1320     pad = gst_element_get_static_pad (element, "sink");
1321     if (pad != NULL) {
1322       peer = gst_pad_get_peer (pad);
1323       if (peer != NULL) {
1324         gst_pad_unlink (peer, pad);
1325         gst_object_unref (peer);
1326       }
1327       gst_object_unref (pad);
1328     }
1329   }
1330
1331   for (sinks = play_bin->sinks; sinks; sinks = g_list_next (sinks)) {
1332     GstElement *element = GST_ELEMENT_CAST (sinks->data);
1333     GstPad *pad;
1334     GstPad *peer;
1335
1336     pad = gst_element_get_static_pad (element, "sink");
1337
1338     GST_LOG ("removing sink %p", element);
1339
1340     peer = gst_pad_get_peer (pad);
1341     if (peer) {
1342       gst_pad_unlink (peer, pad);
1343       gst_object_unref (peer);
1344     }
1345     gst_object_unref (pad);
1346
1347     gst_element_set_state (element, GST_STATE_NULL);
1348     gst_bin_remove (GST_BIN_CAST (play_bin), element);
1349   }
1350   g_list_free (play_bin->sinks);
1351   play_bin->sinks = NULL;
1352
1353   if (play_bin->visualisation) {
1354     GstElement *vis_bin;
1355
1356     vis_bin =
1357         GST_ELEMENT_CAST (gst_element_get_parent (play_bin->visualisation));
1358
1359     gst_element_set_state (play_bin->visualisation, GST_STATE_NULL);
1360
1361     if (vis_bin) {
1362       gst_bin_remove (GST_BIN_CAST (vis_bin), play_bin->visualisation);
1363       gst_object_unref (vis_bin);
1364     }
1365   }
1366
1367   if (play_bin->frame) {
1368     gst_buffer_unref (play_bin->frame);
1369     play_bin->frame = NULL;
1370   }
1371
1372   if (play_bin->textoverlay_element) {
1373     gst_object_unref (play_bin->textoverlay_element);
1374     play_bin->textoverlay_element = NULL;
1375   }
1376 }
1377
1378 /* loop over the streams and set up the pipeline to play this
1379  * media file. First we count the number of audio and video streams.
1380  * If there is no video stream but there exists an audio stream,
1381  * we install a visualisation pipeline.
1382  *
1383  * Also make sure to only connect the first audio and video pad. FIXME
1384  * this should eventually be handled with a tuner interface so that
1385  * one can switch the streams.
1386  *
1387  * This function takes ownership of @sink.*
1388  */
1389 static gboolean
1390 add_sink (GstPlayBin * play_bin, GstElement * sink, GstPad * srcpad,
1391     GstPad * subtitle_pad)
1392 {
1393   GstPad *sinkpad;
1394   GstPadLinkReturn linkres;
1395   GstElement *parent;
1396   GstStateChangeReturn stateret;
1397   GstState state;
1398
1399   g_return_val_if_fail (sink != NULL, FALSE);
1400
1401   state = GST_STATE_PAUSED;
1402
1403   /* this is only for debugging */
1404   parent = gst_pad_get_parent_element (srcpad);
1405   if (parent) {
1406     GST_DEBUG ("Adding sink %" GST_PTR_FORMAT
1407         " with state %d (parent: %d, peer: %d)", sink,
1408         GST_STATE (sink), GST_STATE (play_bin), GST_STATE (parent));
1409     gst_object_unref (parent);
1410   }
1411   gst_bin_add (GST_BIN_CAST (play_bin), sink);
1412
1413   /* bring it to the required state so we can link to the peer without
1414    * breaking the flow */
1415   stateret = gst_element_set_state (sink, state);
1416   if (stateret == GST_STATE_CHANGE_FAILURE)
1417     goto state_failed;
1418
1419   /* we found a sink for this stream, now try to install it */
1420   sinkpad = gst_element_get_static_pad (sink, "sink");
1421   linkres = gst_pad_link (srcpad, sinkpad);
1422   gst_object_unref (sinkpad);
1423
1424   /* try to link the pad of the sink to the stream */
1425   if (GST_PAD_LINK_FAILED (linkres))
1426     goto link_failed;
1427
1428   if (GST_IS_PAD (subtitle_pad)) {
1429     sinkpad = gst_element_get_static_pad (sink, "text_sink");
1430     linkres = gst_pad_link (subtitle_pad, sinkpad);
1431     gst_object_unref (sinkpad);
1432   }
1433
1434   /* try to link the subtitle pad of the sink to the stream, this is not
1435    * fatal. */
1436   if (GST_PAD_LINK_FAILED (linkres))
1437     goto subtitle_failed;
1438
1439 done:
1440   /* we got the sink succesfully linked, now keep the sink
1441    * in our internal list */
1442   play_bin->sinks = g_list_prepend (play_bin->sinks, sink);
1443
1444   return TRUE;
1445
1446   /* ERRORS */
1447 state_failed:
1448   {
1449     gst_element_set_state (sink, GST_STATE_NULL);
1450     gst_bin_remove (GST_BIN_CAST (play_bin), sink);
1451     GST_DEBUG_OBJECT (play_bin, "state change failure when adding sink");
1452     return FALSE;
1453   }
1454 link_failed:
1455   {
1456     gchar *capsstr;
1457     GstCaps *caps;
1458
1459     /* could not link this stream */
1460     caps = gst_pad_get_caps (srcpad);
1461     capsstr = gst_caps_to_string (caps);
1462     g_warning ("could not link %s: %d", capsstr, linkres);
1463     GST_DEBUG_OBJECT (play_bin,
1464         "link failed when adding sink, caps %s, reason %d", capsstr, linkres);
1465     g_free (capsstr);
1466     gst_caps_unref (caps);
1467
1468     gst_element_set_state (sink, GST_STATE_NULL);
1469     gst_bin_remove (GST_BIN_CAST (play_bin), sink);
1470     return FALSE;
1471   }
1472 subtitle_failed:
1473   {
1474     GstCaps *caps;
1475
1476     /* could not link this stream */
1477     caps = gst_pad_get_caps (subtitle_pad);
1478     GST_WARNING_OBJECT (play_bin, "subtitle link failed when adding sink, "
1479         "caps = %" GST_PTR_FORMAT ", reason %d", caps, linkres);
1480     gst_caps_unref (caps);
1481
1482     /* not fatal */
1483     goto done;
1484   }
1485 }
1486
1487 static void
1488 dummy_blocked_cb (GstPad * pad, gboolean blocked, gpointer user_data)
1489 {
1490 }
1491
1492 static gboolean
1493 setup_sinks (GstPlayBaseBin * play_base_bin, GstPlayBaseGroup * group)
1494 {
1495   GstPlayBin *play_bin = GST_PLAY_BIN (play_base_bin);
1496   gboolean need_vis = FALSE;
1497   gboolean need_text = FALSE;
1498   GstPad *textsrcpad = NULL, *pad = NULL, *origtextsrcpad = NULL;
1499   GstElement *sink;
1500   gboolean res = TRUE;
1501
1502   /* get rid of existing sinks */
1503   if (play_bin->sinks) {
1504     remove_sinks (play_bin);
1505   }
1506   GST_DEBUG_OBJECT (play_base_bin, "setupsinks");
1507
1508   /* find out what to do */
1509   if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads > 0 &&
1510       group->type[GST_STREAM_TYPE_TEXT - 1].npads > 0) {
1511     need_text = TRUE;
1512   } else if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads == 0 &&
1513       group->type[GST_STREAM_TYPE_AUDIO - 1].npads > 0 &&
1514       play_bin->visualisation != NULL) {
1515     need_vis = TRUE;
1516   }
1517
1518   /* now actually connect everything */
1519
1520   /* link audio */
1521   if (group->type[GST_STREAM_TYPE_AUDIO - 1].npads > 0) {
1522     if (need_vis) {
1523       sink = gen_vis_element (play_bin);
1524     } else {
1525       sink = gen_audio_element (play_bin);
1526     }
1527     if (!sink)
1528       return FALSE;
1529
1530     pad =
1531         gst_element_get_static_pad (group->type[GST_STREAM_TYPE_AUDIO -
1532             1].preroll, "src");
1533     res = add_sink (play_bin, sink, pad, NULL);
1534     gst_object_unref (pad);
1535   }
1536
1537   /* link video */
1538   if (group->type[GST_STREAM_TYPE_VIDEO - 1].npads > 0) {
1539     if (need_text) {
1540       GstObject *parent = NULL, *grandparent = NULL;
1541       GstPad *ghost = NULL;
1542
1543       sink = gen_text_element (play_bin);
1544       textsrcpad =
1545           gst_element_get_static_pad (group->type[GST_STREAM_TYPE_TEXT -
1546               1].preroll, "src");
1547
1548       /* This pad is from subtitle-bin, we need to create a ghost pad to have
1549          common grandparents */
1550       parent = gst_object_get_parent (GST_OBJECT_CAST (textsrcpad));
1551       if (!parent) {
1552         GST_WARNING_OBJECT (textsrcpad, "subtitle pad has no parent !");
1553         gst_object_unref (textsrcpad);
1554         textsrcpad = NULL;
1555         goto beach;
1556       }
1557
1558       grandparent = gst_object_get_parent (parent);
1559       if (!grandparent) {
1560         GST_WARNING_OBJECT (textsrcpad, "subtitle pad has no grandparent !");
1561         gst_object_unref (parent);
1562         gst_object_unref (textsrcpad);
1563         textsrcpad = NULL;
1564         goto beach;
1565       }
1566
1567       /* We ghost the pad on subtitle_bin only, if the text pad is from the
1568          media demuxer we keep it as it is */
1569       if (!GST_IS_PLAY_BIN (grandparent)) {
1570         GST_DEBUG_OBJECT (textsrcpad, "this subtitle pad is from a subtitle "
1571             "file, ghosting to a suitable hierarchy");
1572         /* Block the pad first, because as soon as we add a ghostpad, the queue
1573          * will try and start pushing */
1574         gst_pad_set_blocked_async (textsrcpad, TRUE, dummy_blocked_cb, NULL);
1575         origtextsrcpad = gst_object_ref (textsrcpad);
1576
1577         ghost = gst_ghost_pad_new ("text_src", textsrcpad);
1578         if (!GST_IS_PAD (ghost)) {
1579           GST_WARNING_OBJECT (textsrcpad, "failed creating ghost pad for "
1580               "subtitle-bin");
1581           gst_object_unref (parent);
1582           gst_object_unref (grandparent);
1583           gst_object_unref (textsrcpad);
1584           textsrcpad = NULL;
1585           goto beach;
1586         }
1587
1588         gst_pad_set_active (ghost, TRUE);
1589         if (gst_element_add_pad (GST_ELEMENT_CAST (grandparent), ghost)) {
1590           gst_object_unref (textsrcpad);
1591           textsrcpad = gst_object_ref (ghost);
1592         } else {
1593           GST_WARNING_OBJECT (ghost, "failed adding ghost pad on subtitle-bin");
1594           gst_pad_set_active (ghost, FALSE);
1595           gst_object_unref (ghost);
1596           gst_object_unref (textsrcpad);
1597           textsrcpad = NULL;
1598         }
1599       } else {
1600         GST_DEBUG_OBJECT (textsrcpad, "this subtitle pad is from the demuxer "
1601             "no changes to hierarchy needed");
1602       }
1603
1604       gst_object_unref (parent);
1605       gst_object_unref (grandparent);
1606     } else {
1607       sink = gen_video_element (play_bin);
1608     }
1609   beach:
1610     if (!sink)
1611       return FALSE;
1612     pad =
1613         gst_element_get_static_pad (group->type[GST_STREAM_TYPE_VIDEO -
1614             1].preroll, "src");
1615     res = add_sink (play_bin, sink, pad, textsrcpad);
1616     gst_object_unref (pad);
1617     if (textsrcpad)
1618       gst_object_unref (textsrcpad);
1619     if (origtextsrcpad) {
1620       gst_pad_set_blocked_async (origtextsrcpad, FALSE, dummy_blocked_cb, NULL);
1621       gst_object_unref (origtextsrcpad);
1622     }
1623   }
1624
1625   /* remove the sinks now, pipeline get_state will now wait for the
1626    * sinks to preroll */
1627   if (play_bin->fakesink) {
1628     gst_element_set_state (play_bin->fakesink, GST_STATE_NULL);
1629     gst_bin_remove (GST_BIN_CAST (play_bin), play_bin->fakesink);
1630     play_bin->fakesink = NULL;
1631   }
1632
1633   return res;
1634 }
1635
1636 static void
1637 playbin_set_subtitles_visible (GstPlayBaseBin * play_base_bin, gboolean visible)
1638 {
1639   GstPlayBin *playbin = GST_PLAY_BIN (play_base_bin);
1640
1641   /* we're ignoring the case of someone setting the 'current-text' property
1642    * before textoverlay is set up (which is probably okay, since playbasebin
1643    * will just select the first subtitle stream as active stream regardless) */
1644   if (playbin->textoverlay_element != NULL) {
1645     GST_LOG_OBJECT (playbin, "setting subtitle visibility to %d", visible);
1646     g_object_set (playbin->textoverlay_element, "silent", !visible, NULL);
1647   }
1648 }
1649
1650 static void
1651 playbin_set_audio_mute (GstPlayBaseBin * play_base_bin, gboolean mute)
1652 {
1653   GstPlayBin *playbin = GST_PLAY_BIN (play_base_bin);
1654
1655   if (playbin->volume_element) {
1656     g_object_set (G_OBJECT (playbin->volume_element), "mute", mute, NULL);
1657   }
1658 }
1659
1660 /* Send an event to our sinks until one of them works; don't then send to the
1661  * remaining sinks (unlike GstBin)
1662  */
1663 static gboolean
1664 gst_play_bin_send_event_to_sink (GstPlayBin * play_bin, GstEvent * event)
1665 {
1666   GList *sinks = play_bin->sinks;
1667   gboolean res = TRUE;
1668
1669   while (sinks) {
1670     GstElement *sink = GST_ELEMENT_CAST (sinks->data);
1671
1672     gst_event_ref (event);
1673     if ((res = gst_element_send_event (sink, event))) {
1674       GST_DEBUG_OBJECT (play_bin,
1675           "Sent event succesfully to sink %" GST_PTR_FORMAT, sink);
1676       break;
1677     }
1678     GST_DEBUG_OBJECT (play_bin,
1679         "Event failed when sent to sink %" GST_PTR_FORMAT, sink);
1680
1681     sinks = g_list_next (sinks);
1682   }
1683
1684   gst_event_unref (event);
1685
1686   return res;
1687 }
1688
1689 /* We only want to send the event to a single sink (overriding GstBin's
1690  * behaviour), but we want to keep GstPipeline's behaviour - wrapping seek
1691  * events appropriately. So, this is a messy duplication of code. */
1692 static gboolean
1693 gst_play_bin_send_event (GstElement * element, GstEvent * event)
1694 {
1695   gboolean res = FALSE;
1696   GstEventType event_type = GST_EVENT_TYPE (event);
1697
1698   switch (event_type) {
1699     case GST_EVENT_SEEK:
1700       GST_DEBUG_OBJECT (element, "Sending seek event to a sink");
1701       res = gst_play_bin_send_event_to_sink (GST_PLAY_BIN (element), event);
1702       break;
1703     default:
1704       res = parent_class->send_event (element, event);
1705       break;
1706   }
1707
1708   return res;
1709 }
1710
1711 static void
1712 value_list_append_structure_list (GValue * list_val, GstStructure ** first,
1713     GList * structure_list)
1714 {
1715   GList *l;
1716
1717   for (l = structure_list; l != NULL; l = l->next) {
1718     GValue val = { 0, };
1719
1720     if (*first == NULL)
1721       *first = gst_structure_copy ((GstStructure *) l->data);
1722
1723     g_value_init (&val, GST_TYPE_STRUCTURE);
1724     g_value_take_boxed (&val, gst_structure_copy ((GstStructure *) l->data));
1725     gst_value_list_append_value (list_val, &val);
1726     g_value_unset (&val);
1727   }
1728 }
1729
1730 /* if it's a redirect message with multiple redirect locations we might
1731  * want to pick a different 'best' location depending on the required
1732  * bitrates and the connection speed */
1733 static GstMessage *
1734 gst_play_bin_handle_redirect_message (GstPlayBin * playbin, GstMessage * msg)
1735 {
1736   const GValue *locations_list, *location_val;
1737   GstMessage *new_msg;
1738   GstStructure *new_structure = NULL;
1739   GList *l_good = NULL, *l_neutral = NULL, *l_bad = NULL;
1740   GValue new_list = { 0, };
1741   guint size, i;
1742   GstPlayBaseBin *playbasebin = GST_PLAY_BASE_BIN (playbin);
1743   guint connection_speed = playbasebin->connection_speed;
1744
1745   GST_DEBUG_OBJECT (playbin, "redirect message: %" GST_PTR_FORMAT, msg);
1746   GST_DEBUG_OBJECT (playbin, "connection speed: %u", connection_speed);
1747
1748   if (connection_speed == 0 || msg->structure == NULL)
1749     return msg;
1750
1751   locations_list = gst_structure_get_value (msg->structure, "locations");
1752   if (locations_list == NULL)
1753     return msg;
1754
1755   size = gst_value_list_get_size (locations_list);
1756   if (size < 2)
1757     return msg;
1758
1759   /* maintain existing order as much as possible, just sort references
1760    * with too high a bitrate to the end (the assumption being that if
1761    * bitrates are given they are given for all interesting streams and
1762    * that the you-need-at-least-version-xyz redirect has the same bitrate
1763    * as the lowest referenced redirect alternative) */
1764   for (i = 0; i < size; ++i) {
1765     const GstStructure *s;
1766     gint bitrate = 0;
1767
1768     location_val = gst_value_list_get_value (locations_list, i);
1769     s = (const GstStructure *) g_value_get_boxed (location_val);
1770     if (!gst_structure_get_int (s, "minimum-bitrate", &bitrate) || bitrate <= 0) {
1771       GST_DEBUG_OBJECT (playbin, "no bitrate: %" GST_PTR_FORMAT, s);
1772       l_neutral = g_list_append (l_neutral, (gpointer) s);
1773     } else if (bitrate > connection_speed) {
1774       GST_DEBUG_OBJECT (playbin, "bitrate too high: %" GST_PTR_FORMAT, s);
1775       l_bad = g_list_append (l_bad, (gpointer) s);
1776     } else if (bitrate <= connection_speed) {
1777       GST_DEBUG_OBJECT (playbin, "bitrate OK: %" GST_PTR_FORMAT, s);
1778       l_good = g_list_append (l_good, (gpointer) s);
1779     }
1780   }
1781
1782   g_value_init (&new_list, GST_TYPE_LIST);
1783   value_list_append_structure_list (&new_list, &new_structure, l_good);
1784   value_list_append_structure_list (&new_list, &new_structure, l_neutral);
1785   value_list_append_structure_list (&new_list, &new_structure, l_bad);
1786   gst_structure_set_value (new_structure, "locations", &new_list);
1787   g_value_unset (&new_list);
1788
1789   g_list_free (l_good);
1790   g_list_free (l_neutral);
1791   g_list_free (l_bad);
1792
1793   new_msg = gst_message_new_element (msg->src, new_structure);
1794   gst_message_unref (msg);
1795
1796   GST_DEBUG_OBJECT (playbin, "new redirect message: %" GST_PTR_FORMAT, new_msg);
1797   return new_msg;
1798 }
1799
1800 static void
1801 gst_play_bin_handle_message (GstBin * bin, GstMessage * msg)
1802 {
1803   if (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ELEMENT && msg->structure != NULL
1804       && gst_structure_has_name (msg->structure, "redirect")) {
1805     msg = gst_play_bin_handle_redirect_message (GST_PLAY_BIN (bin), msg);
1806   }
1807
1808   GST_BIN_CLASS (parent_class)->handle_message (bin, msg);
1809 }
1810
1811 static GstStateChangeReturn
1812 gst_play_bin_change_state (GstElement * element, GstStateChange transition)
1813 {
1814   GstStateChangeReturn ret;
1815   GstPlayBin *play_bin;
1816
1817   play_bin = GST_PLAY_BIN (element);
1818
1819
1820   switch (transition) {
1821     case GST_STATE_CHANGE_READY_TO_PAUSED:
1822       /* this really is the easiest way to make the state change return
1823        * ASYNC until we added the sinks */
1824       if (!play_bin->fakesink) {
1825         play_bin->fakesink = gst_element_factory_make ("fakesink", "test");
1826         gst_bin_add (GST_BIN_CAST (play_bin), play_bin->fakesink);
1827       }
1828       break;
1829     default:
1830       break;
1831   }
1832
1833   ret = GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
1834   if (ret == GST_STATE_CHANGE_FAILURE)
1835     return ret;
1836
1837   switch (transition) {
1838     case GST_STATE_CHANGE_READY_TO_PAUSED:
1839       /* remember us being a live pipeline */
1840       play_bin->is_live = (ret == GST_STATE_CHANGE_NO_PREROLL);
1841       GST_DEBUG_OBJECT (play_bin, "is live: %d", play_bin->is_live);
1842       break;
1843     case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
1844       /* FIXME Release audio device when we implement that */
1845       break;
1846     case GST_STATE_CHANGE_PAUSED_TO_READY:
1847     case GST_STATE_CHANGE_READY_TO_NULL:
1848       /* remove sinks we added */
1849       remove_sinks (play_bin);
1850       /* and there might be a fakesink we need to clean up now */
1851       if (play_bin->fakesink) {
1852         gst_element_set_state (play_bin->fakesink, GST_STATE_NULL);
1853         gst_bin_remove (GST_BIN_CAST (play_bin), play_bin->fakesink);
1854         play_bin->fakesink = NULL;
1855       }
1856       break;
1857     default:
1858       break;
1859   }
1860
1861   return ret;
1862 }
1863
1864 gboolean
1865 gst_play_bin_plugin_init (GstPlugin * plugin)
1866 {
1867   GST_DEBUG_CATEGORY_INIT (gst_play_bin_debug, "playbin", 0, "play bin");
1868
1869   return gst_element_register (plugin, "playbin", GST_RANK_NONE,
1870       GST_TYPE_PLAY_BIN);
1871 }