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