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