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