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