2 * Copyright (C) <2007> Wim Taymans <wim.taymans@gmail.com>
3 * Copyright (C) <2011> Sebastian Dröge <sebastian.droege@collabora.co.uk>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
25 /* FIXME 0.11: suppress warnings for deprecated API such as GStaticRecMutex
26 * with newer GLib versions (>= 2.31.0) */
27 #define GLIB_DISABLE_DEPRECATION_WARNINGS
32 #include <gst/gst-i18n-plugin.h>
33 #include <gst/pbutils/pbutils.h>
34 #include <gst/video/video.h>
35 #include <gst/interfaces/streamvolume.h>
36 #include <gst/interfaces/colorbalance.h>
38 #include "gstplaysink.h"
39 #include "gststreamsynchronizer.h"
40 #include "gstplaysinkvideoconvert.h"
41 #include "gstplaysinkaudioconvert.h"
43 GST_DEBUG_CATEGORY_STATIC (gst_play_sink_debug);
44 #define GST_CAT_DEFAULT gst_play_sink_debug
46 #define VOLUME_MAX_DOUBLE 10.0
48 #define DEFAULT_FLAGS GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_TEXT | \
49 GST_PLAY_FLAG_SOFT_VOLUME | GST_PLAY_FLAG_SOFT_COLORBALANCE
51 #define GST_PLAY_CHAIN(c) ((GstPlayChain *)(c))
53 /* holds the common data fields for the audio and video pipelines. We keep them
54 * in a structure to more easily have all the info available. */
57 GstPlaySink *playsink;
70 GstElement *volume; /* element with the volume property */
71 gboolean sink_volume; /* if the volume was provided by the sink */
72 GstElement *mute; /* element with the mute property */
74 GstElement *ts_offset;
80 GstPad *sinkpad, *srcpad;
82 GstElement *deinterlace;
83 } GstPlayVideoDeinterlaceChain;
93 GstElement *ts_offset;
102 GstElement *resample;
103 GstPad *blockpad; /* srcpad of resample, used for switching the vis */
104 GstPad *vissinkpad; /* visualisation sinkpad, */
106 GstPad *vissrcpad; /* visualisation srcpad, */
107 GstPad *srcpad; /* outgoing srcpad, used to connect to the next
116 GstElement *identity;
118 GstPad *videosinkpad;
120 GstPad *srcpad; /* outgoing srcpad, used to connect to the next
122 GstElement *sink; /* custom sink to receive subtitle buffers */
125 #define GST_PLAY_SINK_GET_LOCK(playsink) (&((GstPlaySink *)playsink)->lock)
126 #define GST_PLAY_SINK_LOCK(playsink) G_STMT_START { \
127 GST_LOG_OBJECT (playsink, "locking from thread %p", g_thread_self ()); \
128 g_static_rec_mutex_lock (GST_PLAY_SINK_GET_LOCK (playsink)); \
129 GST_LOG_OBJECT (playsink, "locked from thread %p", g_thread_self ()); \
131 #define GST_PLAY_SINK_UNLOCK(playsink) G_STMT_START { \
132 GST_LOG_OBJECT (playsink, "unlocking from thread %p", g_thread_self ()); \
133 g_static_rec_mutex_unlock (GST_PLAY_SINK_GET_LOCK (playsink)); \
136 #define PENDING_FLAG_SET(playsink, flagtype) \
137 ((playsink->pending_blocked_pads) |= (1 << flagtype))
138 #define PENDING_FLAG_UNSET(playsink, flagtype) \
139 ((playsink->pending_blocked_pads) &= ~(1 << flagtype))
140 #define PENDING_FLAG_IS_SET(playsink, flagtype) \
141 ((playsink->pending_blocked_pads) & (1 << flagtype))
142 #define PENDING_VIDEO_BLOCK(playsink) \
143 ((playsink->pending_blocked_pads) & (1 << GST_PLAY_SINK_TYPE_VIDEO_RAW | 1 << GST_PLAY_SINK_TYPE_VIDEO))
144 #define PENDING_AUDIO_BLOCK(playsink) \
145 ((playsink->pending_blocked_pads) & (1 << GST_PLAY_SINK_TYPE_AUDIO_RAW | 1 << GST_PLAY_SINK_TYPE_AUDIO))
146 #define PENDING_TEXT_BLOCK(playsink) \
147 PENDING_FLAG_IS_SET(playsink, GST_PLAY_SINK_TYPE_TEXT)
153 GStaticRecMutex lock;
155 gboolean async_pending;
156 gboolean need_async_start;
160 GstStreamSynchronizer *stream_synchronizer;
163 GstPlayAudioChain *audiochain;
164 GstPlayVideoDeinterlaceChain *videodeinterlacechain;
165 GstPlayVideoChain *videochain;
166 GstPlayVisChain *vischain;
167 GstPlayTextChain *textchain;
171 gboolean audio_pad_raw;
172 gboolean audio_pad_blocked;
173 GstPad *audio_srcpad_stream_synchronizer;
174 GstPad *audio_sinkpad_stream_synchronizer;
176 GstElement *audio_tee;
177 GstPad *audio_tee_sink;
178 GstPad *audio_tee_asrc;
179 GstPad *audio_tee_vissrc;
182 gboolean video_pad_raw;
183 gboolean video_pad_blocked;
184 GstPad *video_srcpad_stream_synchronizer;
185 GstPad *video_sinkpad_stream_synchronizer;
188 gboolean text_pad_blocked;
189 GstPad *text_srcpad_stream_synchronizer;
190 GstPad *text_sinkpad_stream_synchronizer;
192 guint32 pending_blocked_pads;
195 GstElement *audio_sink;
196 GstElement *video_sink;
197 GstElement *visualisation;
198 GstElement *text_sink;
201 gchar *font_desc; /* font description */
202 gchar *subtitle_encoding; /* subtitle encoding */
203 guint connection_speed; /* connection speed in bits/sec (0 = unknown) */
205 gboolean volume_changed; /* volume/mute changed while no audiochain */
206 gboolean mute_changed; /* ... has been created yet */
210 struct _GstPlaySinkClass
212 GstBinClass parent_class;
214 gboolean (*reconfigure) (GstPlaySink * playsink);
216 GstBuffer *(*convert_frame) (GstPlaySink * playsink, GstCaps * caps);
220 static GstStaticPadTemplate audiotemplate =
221 GST_STATIC_PAD_TEMPLATE ("audio_sink",
224 GST_STATIC_CAPS_ANY);
225 static GstStaticPadTemplate videotemplate =
226 GST_STATIC_PAD_TEMPLATE ("video_sink",
229 GST_STATIC_CAPS_ANY);
230 static GstStaticPadTemplate texttemplate = GST_STATIC_PAD_TEMPLATE ("text_sink",
233 GST_STATIC_CAPS_ANY);
235 /* FIXME 0.11: Remove */
236 static GstStaticPadTemplate audiorawtemplate =
237 GST_STATIC_PAD_TEMPLATE ("audio_raw_sink",
240 GST_STATIC_CAPS_ANY);
241 static GstStaticPadTemplate videorawtemplate =
242 GST_STATIC_PAD_TEMPLATE ("video_raw_sink",
245 GST_STATIC_CAPS_ANY);
256 PROP_SUBTITLE_ENCODING,
272 static void gst_play_sink_dispose (GObject * object);
273 static void gst_play_sink_finalize (GObject * object);
274 static void gst_play_sink_set_property (GObject * object, guint prop_id,
275 const GValue * value, GParamSpec * spec);
276 static void gst_play_sink_get_property (GObject * object, guint prop_id,
277 GValue * value, GParamSpec * spec);
279 static GstPad *gst_play_sink_request_new_pad (GstElement * element,
280 GstPadTemplate * templ, const gchar * name);
281 static void gst_play_sink_release_request_pad (GstElement * element,
283 static gboolean gst_play_sink_send_event (GstElement * element,
285 static GstStateChangeReturn gst_play_sink_change_state (GstElement * element,
286 GstStateChange transition);
288 static void gst_play_sink_handle_message (GstBin * bin, GstMessage * message);
290 static void notify_volume_cb (GObject * object, GParamSpec * pspec,
291 GstPlaySink * playsink);
292 static void notify_mute_cb (GObject * object, GParamSpec * pspec,
293 GstPlaySink * playsink);
295 static void update_av_offset (GstPlaySink * playsink);
298 gst_play_marshal_BUFFER__BOXED (GClosure * closure,
299 GValue * return_value G_GNUC_UNUSED,
300 guint n_param_values,
301 const GValue * param_values,
302 gpointer invocation_hint G_GNUC_UNUSED, gpointer marshal_data)
304 typedef GstBuffer *(*GMarshalFunc_OBJECT__BOXED) (gpointer data1,
305 gpointer arg_1, gpointer data2);
306 register GMarshalFunc_OBJECT__BOXED callback;
307 register GCClosure *cc = (GCClosure *) closure;
308 register gpointer data1, data2;
310 g_return_if_fail (return_value != NULL);
311 g_return_if_fail (n_param_values == 2);
313 if (G_CCLOSURE_SWAP_DATA (closure)) {
314 data1 = closure->data;
315 data2 = g_value_peek_pointer (param_values + 0);
317 data1 = g_value_peek_pointer (param_values + 0);
318 data2 = closure->data;
321 (GMarshalFunc_OBJECT__BOXED) (marshal_data ? marshal_data : cc->callback);
323 v_return = callback (data1, g_value_get_boxed (param_values + 1), data2);
325 gst_value_take_buffer (return_value, v_return);
328 /* static guint gst_play_sink_signals[LAST_SIGNAL] = { 0 }; */
331 _do_init (GType type)
333 static const GInterfaceInfo svol_info = {
337 g_type_add_interface_static (type, GST_TYPE_STREAM_VOLUME, &svol_info);
340 G_DEFINE_TYPE_WITH_CODE (GstPlaySink, gst_play_sink, GST_TYPE_BIN,
341 _do_init (g_define_type_id));
344 gst_play_sink_class_init (GstPlaySinkClass * klass)
346 GObjectClass *gobject_klass;
347 GstElementClass *gstelement_klass;
348 GstBinClass *gstbin_klass;
350 gobject_klass = (GObjectClass *) klass;
351 gstelement_klass = (GstElementClass *) klass;
352 gstbin_klass = (GstBinClass *) klass;
354 gobject_klass->dispose = gst_play_sink_dispose;
355 gobject_klass->finalize = gst_play_sink_finalize;
356 gobject_klass->set_property = gst_play_sink_set_property;
357 gobject_klass->get_property = gst_play_sink_get_property;
363 * Control the behaviour of playsink.
365 g_object_class_install_property (gobject_klass, PROP_FLAGS,
366 g_param_spec_flags ("flags", "Flags", "Flags to control behaviour",
367 GST_TYPE_PLAY_FLAGS, DEFAULT_FLAGS,
368 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
371 * GstPlaySink:volume:
373 * Get or set the current audio stream volume. 1.0 means 100%,
374 * 0.0 means mute. This uses a linear volume scale.
377 g_object_class_install_property (gobject_klass, PROP_VOLUME,
378 g_param_spec_double ("volume", "Volume", "The audio volume, 1.0=100%",
379 0.0, VOLUME_MAX_DOUBLE, 1.0,
380 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
381 g_object_class_install_property (gobject_klass, PROP_MUTE,
382 g_param_spec_boolean ("mute", "Mute",
383 "Mute the audio channel without changing the volume", FALSE,
384 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
385 g_object_class_install_property (gobject_klass, PROP_FONT_DESC,
386 g_param_spec_string ("subtitle-font-desc",
387 "Subtitle font description",
388 "Pango font description of font "
389 "to be used for subtitle rendering", NULL,
390 G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
391 g_object_class_install_property (gobject_klass, PROP_SUBTITLE_ENCODING,
392 g_param_spec_string ("subtitle-encoding", "subtitle encoding",
393 "Encoding to assume if input subtitles are not in UTF-8 encoding. "
394 "If not set, the GST_SUBTITLE_ENCODING environment variable will "
395 "be checked for an encoding to use. If that is not set either, "
396 "ISO-8859-15 will be assumed.", NULL,
397 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
398 g_object_class_install_property (gobject_klass, PROP_VIS_PLUGIN,
399 g_param_spec_object ("vis-plugin", "Vis plugin",
400 "the visualization element to use (NULL = default)",
401 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
405 * Get the currently rendered or prerolled frame in the video sink.
406 * The #GstCaps on the buffer will describe the format of the buffer.
410 g_object_class_install_property (gobject_klass, PROP_FRAME,
411 gst_param_spec_mini_object ("frame", "Frame",
412 "The last frame (NULL = no video available)",
413 GST_TYPE_BUFFER, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
415 * GstPlaySink:av-offset:
417 * Control the synchronisation offset between the audio and video streams.
418 * Positive values make the audio ahead of the video and negative values make
419 * the audio go behind the video.
423 g_object_class_install_property (gobject_klass, PROP_AV_OFFSET,
424 g_param_spec_int64 ("av-offset", "AV Offset",
425 "The synchronisation offset between audio and video in nanoseconds",
426 G_MININT64, G_MAXINT64, 0,
427 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
430 * GstPlaySink:video-sink:
432 * Set the used video sink element. NULL will use the default sink. playsink
433 * must be in %GST_STATE_NULL
437 g_object_class_install_property (gobject_klass, PROP_VIDEO_SINK,
438 g_param_spec_object ("video-sink", "Video Sink",
439 "the video output element to use (NULL = default sink)",
440 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
442 * GstPlaySink:audio-sink:
444 * Set the used audio sink element. NULL will use the default sink. playsink
445 * must be in %GST_STATE_NULL
449 g_object_class_install_property (gobject_klass, PROP_AUDIO_SINK,
450 g_param_spec_object ("audio-sink", "Audio Sink",
451 "the audio output element to use (NULL = default sink)",
452 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
454 * GstPlaySink:text-sink:
456 * Set the used text sink element. NULL will use the default sink. playsink
457 * must be in %GST_STATE_NULL
461 g_object_class_install_property (gobject_klass, PROP_TEXT_SINK,
462 g_param_spec_object ("text-sink", "Text sink",
463 "the text output element to use (NULL = default textoverlay)",
464 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
467 g_signal_new ("reconfigure", G_TYPE_FROM_CLASS (klass),
468 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstPlaySinkClass,
469 reconfigure), NULL, NULL, gst_marshal_BOOLEAN__VOID, G_TYPE_BOOLEAN,
472 * GstPlaySink::convert-frame
473 * @playsink: a #GstPlaySink
474 * @caps: the target format of the frame
476 * Action signal to retrieve the currently playing video frame in the format
477 * specified by @caps.
478 * If @caps is %NULL, no conversion will be performed and this function is
479 * equivalent to the #GstPlaySink::frame property.
481 * Returns: a #GstBuffer of the current video frame converted to #caps.
482 * The caps on the buffer will describe the final layout of the buffer data.
483 * %NULL is returned when no current buffer can be retrieved or when the
488 g_signal_new ("convert-frame", G_TYPE_FROM_CLASS (klass),
489 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
490 G_STRUCT_OFFSET (GstPlaySinkClass, convert_frame), NULL, NULL,
491 gst_play_marshal_BUFFER__BOXED, GST_TYPE_BUFFER, 1, GST_TYPE_CAPS);
493 gst_element_class_add_static_pad_template (gstelement_klass,
495 gst_element_class_add_static_pad_template (gstelement_klass, &audiotemplate);
496 gst_element_class_add_static_pad_template (gstelement_klass,
498 gst_element_class_add_static_pad_template (gstelement_klass, &videotemplate);
499 gst_element_class_add_static_pad_template (gstelement_klass, &texttemplate);
500 gst_element_class_set_details_simple (gstelement_klass, "Player Sink",
502 "Convenience sink for multiple streams",
503 "Wim Taymans <wim.taymans@gmail.com>");
505 gstelement_klass->change_state =
506 GST_DEBUG_FUNCPTR (gst_play_sink_change_state);
507 gstelement_klass->send_event = GST_DEBUG_FUNCPTR (gst_play_sink_send_event);
508 gstelement_klass->request_new_pad =
509 GST_DEBUG_FUNCPTR (gst_play_sink_request_new_pad);
510 gstelement_klass->release_pad =
511 GST_DEBUG_FUNCPTR (gst_play_sink_release_request_pad);
513 gstbin_klass->handle_message =
514 GST_DEBUG_FUNCPTR (gst_play_sink_handle_message);
516 klass->reconfigure = GST_DEBUG_FUNCPTR (gst_play_sink_reconfigure);
517 klass->convert_frame = GST_DEBUG_FUNCPTR (gst_play_sink_convert_frame);
521 gst_play_sink_init (GstPlaySink * playsink)
524 playsink->video_sink = NULL;
525 playsink->audio_sink = NULL;
526 playsink->visualisation = NULL;
527 playsink->text_sink = NULL;
528 playsink->volume = 1.0;
529 playsink->font_desc = NULL;
530 playsink->subtitle_encoding = NULL;
531 playsink->flags = DEFAULT_FLAGS;
533 playsink->stream_synchronizer =
534 g_object_new (GST_TYPE_STREAM_SYNCHRONIZER, NULL);
535 gst_bin_add (GST_BIN_CAST (playsink),
536 GST_ELEMENT_CAST (playsink->stream_synchronizer));
538 g_static_rec_mutex_init (&playsink->lock);
539 GST_OBJECT_FLAG_SET (playsink, GST_ELEMENT_IS_SINK);
543 disconnect_chain (GstPlayAudioChain * chain, GstPlaySink * playsink)
547 g_signal_handlers_disconnect_by_func (chain->volume, notify_volume_cb,
550 g_signal_handlers_disconnect_by_func (chain->mute, notify_mute_cb,
556 free_chain (GstPlayChain * chain)
560 gst_object_unref (chain->bin);
566 gst_play_sink_dispose (GObject * object)
568 GstPlaySink *playsink;
570 playsink = GST_PLAY_SINK (object);
572 if (playsink->audio_sink != NULL) {
573 gst_element_set_state (playsink->audio_sink, GST_STATE_NULL);
574 gst_object_unref (playsink->audio_sink);
575 playsink->audio_sink = NULL;
577 if (playsink->video_sink != NULL) {
578 gst_element_set_state (playsink->video_sink, GST_STATE_NULL);
579 gst_object_unref (playsink->video_sink);
580 playsink->video_sink = NULL;
582 if (playsink->visualisation != NULL) {
583 gst_element_set_state (playsink->visualisation, GST_STATE_NULL);
584 gst_object_unref (playsink->visualisation);
585 playsink->visualisation = NULL;
587 if (playsink->text_sink != NULL) {
588 gst_element_set_state (playsink->text_sink, GST_STATE_NULL);
589 gst_object_unref (playsink->text_sink);
590 playsink->text_sink = NULL;
593 free_chain ((GstPlayChain *) playsink->videodeinterlacechain);
594 playsink->videodeinterlacechain = NULL;
595 free_chain ((GstPlayChain *) playsink->videochain);
596 playsink->videochain = NULL;
597 free_chain ((GstPlayChain *) playsink->audiochain);
598 playsink->audiochain = NULL;
599 free_chain ((GstPlayChain *) playsink->vischain);
600 playsink->vischain = NULL;
601 free_chain ((GstPlayChain *) playsink->textchain);
602 playsink->textchain = NULL;
604 if (playsink->audio_tee_sink) {
605 gst_object_unref (playsink->audio_tee_sink);
606 playsink->audio_tee_sink = NULL;
609 if (playsink->audio_tee_vissrc) {
610 gst_element_release_request_pad (playsink->audio_tee,
611 playsink->audio_tee_vissrc);
612 gst_object_unref (playsink->audio_tee_vissrc);
613 playsink->audio_tee_vissrc = NULL;
616 if (playsink->audio_tee_asrc) {
617 gst_element_release_request_pad (playsink->audio_tee,
618 playsink->audio_tee_asrc);
619 gst_object_unref (playsink->audio_tee_asrc);
620 playsink->audio_tee_asrc = NULL;
623 g_free (playsink->font_desc);
624 playsink->font_desc = NULL;
626 g_free (playsink->subtitle_encoding);
627 playsink->subtitle_encoding = NULL;
629 playsink->stream_synchronizer = NULL;
631 G_OBJECT_CLASS (gst_play_sink_parent_class)->dispose (object);
635 gst_play_sink_finalize (GObject * object)
637 GstPlaySink *playsink;
639 playsink = GST_PLAY_SINK (object);
641 g_static_rec_mutex_free (&playsink->lock);
643 G_OBJECT_CLASS (gst_play_sink_parent_class)->finalize (object);
647 gst_play_sink_set_sink (GstPlaySink * playsink, GstPlaySinkType type,
650 GstElement **elem = NULL, *old = NULL;
652 GST_LOG ("Setting sink %" GST_PTR_FORMAT " as sink type %d", sink, type);
654 GST_PLAY_SINK_LOCK (playsink);
656 case GST_PLAY_SINK_TYPE_AUDIO:
657 case GST_PLAY_SINK_TYPE_AUDIO_RAW:
658 elem = &playsink->audio_sink;
660 case GST_PLAY_SINK_TYPE_VIDEO:
661 case GST_PLAY_SINK_TYPE_VIDEO_RAW:
662 elem = &playsink->video_sink;
664 case GST_PLAY_SINK_TYPE_TEXT:
665 elem = &playsink->text_sink;
673 gst_object_ref (sink);
676 GST_PLAY_SINK_UNLOCK (playsink);
680 gst_element_set_state (old, GST_STATE_NULL);
681 gst_object_unref (old);
686 gst_play_sink_get_sink (GstPlaySink * playsink, GstPlaySinkType type)
688 GstElement *result = NULL;
689 GstElement *elem = NULL, *chainp = NULL;
691 GST_PLAY_SINK_LOCK (playsink);
693 case GST_PLAY_SINK_TYPE_AUDIO:
694 case GST_PLAY_SINK_TYPE_AUDIO_RAW:
696 GstPlayAudioChain *chain;
697 if ((chain = (GstPlayAudioChain *) playsink->audiochain))
698 chainp = chain->sink;
699 elem = playsink->audio_sink;
702 case GST_PLAY_SINK_TYPE_VIDEO:
703 case GST_PLAY_SINK_TYPE_VIDEO_RAW:
705 GstPlayVideoChain *chain;
706 if ((chain = (GstPlayVideoChain *) playsink->videochain))
707 chainp = chain->sink;
708 elem = playsink->video_sink;
711 case GST_PLAY_SINK_TYPE_TEXT:
713 GstPlayTextChain *chain;
714 if ((chain = (GstPlayTextChain *) playsink->textchain))
715 chainp = chain->sink;
716 elem = playsink->text_sink;
723 /* we have an active chain with a sink, get the sink */
724 result = gst_object_ref (chainp);
726 /* nothing found, return last configured sink */
727 if (result == NULL && elem)
728 result = gst_object_ref (elem);
729 GST_PLAY_SINK_UNLOCK (playsink);
735 gst_play_sink_vis_unblocked (GstPad * tee_pad, gboolean blocked,
738 GstPlaySink *playsink;
740 playsink = GST_PLAY_SINK (user_data);
741 /* nothing to do here, we need a dummy callback here to make the async call
743 GST_DEBUG_OBJECT (playsink, "vis pad unblocked");
747 gst_play_sink_vis_blocked (GstPad * tee_pad, gboolean blocked,
750 GstPlaySink *playsink;
751 GstPlayVisChain *chain;
753 playsink = GST_PLAY_SINK (user_data);
755 GST_PLAY_SINK_LOCK (playsink);
756 GST_DEBUG_OBJECT (playsink, "vis pad blocked");
757 /* now try to change the plugin in the running vis chain */
758 if (!(chain = (GstPlayVisChain *) playsink->vischain))
761 /* unlink the old plugin and unghost the pad */
762 gst_pad_unlink (chain->blockpad, chain->vissinkpad);
763 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (chain->srcpad), NULL);
765 /* set the old plugin to NULL and remove */
766 gst_element_set_state (chain->vis, GST_STATE_NULL);
767 gst_bin_remove (GST_BIN_CAST (chain->chain.bin), chain->vis);
769 /* add new plugin and set state to playing */
770 chain->vis = playsink->visualisation;
771 gst_bin_add (GST_BIN_CAST (chain->chain.bin), chain->vis);
772 gst_element_set_state (chain->vis, GST_STATE_PLAYING);
775 chain->vissinkpad = gst_element_get_static_pad (chain->vis, "sink");
776 chain->vissrcpad = gst_element_get_static_pad (chain->vis, "src");
779 gst_pad_link_full (chain->blockpad, chain->vissinkpad,
780 GST_PAD_LINK_CHECK_NOTHING);
781 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (chain->srcpad),
785 /* Unblock the pad */
786 gst_pad_set_blocked_async (tee_pad, FALSE, gst_play_sink_vis_unblocked,
788 GST_PLAY_SINK_UNLOCK (playsink);
792 gst_play_sink_set_vis_plugin (GstPlaySink * playsink, GstElement * vis)
794 GstPlayVisChain *chain;
796 /* setting NULL means creating the default vis plugin */
798 vis = gst_element_factory_make ("goom", "vis");
800 /* simply return if we don't have a vis plugin here */
804 GST_PLAY_SINK_LOCK (playsink);
805 /* first store the new vis */
806 if (playsink->visualisation)
807 gst_object_unref (playsink->visualisation);
809 gst_object_ref_sink (vis);
810 playsink->visualisation = vis;
812 /* now try to change the plugin in the running vis chain, if we have no chain,
813 * we don't bother, any future vis chain will be created with the new vis
815 if (!(chain = (GstPlayVisChain *) playsink->vischain))
818 /* block the pad, the next time the callback is called we can change the
819 * visualisation. It's possible that this never happens or that the pad was
820 * already blocked. If the callback never happens, we don't have new data so
821 * we don't need the new vis plugin. If the pad was already blocked, the
822 * function returns FALSE but the previous pad block will do the right thing
824 GST_DEBUG_OBJECT (playsink, "blocking vis pad");
825 gst_pad_set_blocked_async (chain->blockpad, TRUE, gst_play_sink_vis_blocked,
828 GST_PLAY_SINK_UNLOCK (playsink);
834 gst_play_sink_get_vis_plugin (GstPlaySink * playsink)
836 GstElement *result = NULL;
837 GstPlayVisChain *chain;
839 GST_PLAY_SINK_LOCK (playsink);
840 if ((chain = (GstPlayVisChain *) playsink->vischain)) {
841 /* we have an active chain, get the sink */
843 result = gst_object_ref (chain->vis);
845 /* nothing found, return last configured sink */
846 if (result == NULL && playsink->visualisation)
847 result = gst_object_ref (playsink->visualisation);
848 GST_PLAY_SINK_UNLOCK (playsink);
854 gst_play_sink_set_volume (GstPlaySink * playsink, gdouble volume)
856 GstPlayAudioChain *chain;
858 GST_PLAY_SINK_LOCK (playsink);
859 playsink->volume = volume;
860 chain = (GstPlayAudioChain *) playsink->audiochain;
861 if (chain && chain->volume) {
862 GST_LOG_OBJECT (playsink, "elements: volume=%" GST_PTR_FORMAT ", mute=%"
863 GST_PTR_FORMAT "; new volume=%.03f, mute=%d", chain->volume,
864 chain->mute, volume, playsink->mute);
865 /* if there is a mute element or we are not muted, set the volume */
866 if (chain->mute || !playsink->mute)
867 g_object_set (chain->volume, "volume", volume, NULL);
869 GST_LOG_OBJECT (playsink, "no volume element");
870 playsink->volume_changed = TRUE;
872 GST_PLAY_SINK_UNLOCK (playsink);
876 gst_play_sink_get_volume (GstPlaySink * playsink)
879 GstPlayAudioChain *chain;
881 GST_PLAY_SINK_LOCK (playsink);
882 chain = (GstPlayAudioChain *) playsink->audiochain;
883 result = playsink->volume;
884 if (chain && chain->volume) {
885 if (chain->mute || !playsink->mute) {
886 g_object_get (chain->volume, "volume", &result, NULL);
887 playsink->volume = result;
890 GST_PLAY_SINK_UNLOCK (playsink);
896 gst_play_sink_set_mute (GstPlaySink * playsink, gboolean mute)
898 GstPlayAudioChain *chain;
900 GST_PLAY_SINK_LOCK (playsink);
901 playsink->mute = mute;
902 chain = (GstPlayAudioChain *) playsink->audiochain;
905 g_object_set (chain->mute, "mute", mute, NULL);
906 } else if (chain->volume) {
908 g_object_set (chain->volume, "volume", (gdouble) 0.0, NULL);
910 g_object_set (chain->volume, "volume", (gdouble) playsink->volume,
914 playsink->mute_changed = TRUE;
916 GST_PLAY_SINK_UNLOCK (playsink);
920 gst_play_sink_get_mute (GstPlaySink * playsink)
923 GstPlayAudioChain *chain;
925 GST_PLAY_SINK_LOCK (playsink);
926 chain = (GstPlayAudioChain *) playsink->audiochain;
927 if (chain && chain->mute) {
928 g_object_get (chain->mute, "mute", &result, NULL);
929 playsink->mute = result;
931 result = playsink->mute;
933 GST_PLAY_SINK_UNLOCK (playsink);
939 post_missing_element_message (GstPlaySink * playsink, const gchar * name)
943 msg = gst_missing_element_message_new (GST_ELEMENT_CAST (playsink), name);
944 gst_element_post_message (GST_ELEMENT_CAST (playsink), msg);
948 add_chain (GstPlayChain * chain, gboolean add)
950 if (chain->added == add)
954 gst_bin_add (GST_BIN_CAST (chain->playsink), chain->bin);
956 gst_bin_remove (GST_BIN_CAST (chain->playsink), chain->bin);
957 /* we don't want to lose our sink status */
958 GST_OBJECT_FLAG_SET (chain->playsink, GST_ELEMENT_IS_SINK);
967 activate_chain (GstPlayChain * chain, gboolean activate)
971 if (chain->activated == activate)
974 GST_OBJECT_LOCK (chain->playsink);
975 state = GST_STATE_TARGET (chain->playsink);
976 GST_OBJECT_UNLOCK (chain->playsink);
979 gst_element_set_state (chain->bin, state);
981 gst_element_set_state (chain->bin, GST_STATE_NULL);
983 chain->activated = activate;
989 element_is_sink (GstElement * element)
993 GST_OBJECT_LOCK (element);
994 is_sink = GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_IS_SINK);
995 GST_OBJECT_UNLOCK (element);
997 GST_DEBUG_OBJECT (element, "is a sink: %s", (is_sink) ? "yes" : "no");
1002 element_has_property (GstElement * element, const gchar * pname, GType type)
1006 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (element), pname);
1008 if (pspec == NULL) {
1009 GST_DEBUG_OBJECT (element, "no %s property", pname);
1013 if (type == G_TYPE_INVALID || type == pspec->value_type ||
1014 g_type_is_a (pspec->value_type, type)) {
1015 GST_DEBUG_OBJECT (element, "has %s property of type %s", pname,
1016 (type == G_TYPE_INVALID) ? "any type" : g_type_name (type));
1020 GST_WARNING_OBJECT (element, "has %s property, but property is of type %s "
1021 "and we expected it to be of type %s", pname,
1022 g_type_name (pspec->value_type), g_type_name (type));
1029 const gchar *prop_name;
1032 } FindPropertyHelper;
1035 find_property (GstElement * element, FindPropertyHelper * helper)
1037 if (helper->need_sink && !element_is_sink (element)) {
1038 gst_object_unref (element);
1042 if (!element_has_property (element, helper->prop_name, helper->prop_type)) {
1043 gst_object_unref (element);
1047 GST_INFO_OBJECT (element, "found %s with %s property", helper->prop_name,
1048 (helper->need_sink) ? "sink" : "element");
1049 return 0; /* keep it */
1052 /* FIXME: why not move these functions into core? */
1053 /* find a sink in the hierarchy with a property named @name. This function does
1054 * not increase the refcount of the returned object and thus remains valid as
1055 * long as the bin is valid. */
1057 gst_play_sink_find_property_sinks (GstPlaySink * playsink, GstElement * obj,
1058 const gchar * name, GType expected_type)
1060 GstElement *result = NULL;
1063 if (element_has_property (obj, name, expected_type)) {
1065 } else if (GST_IS_BIN (obj)) {
1066 FindPropertyHelper helper = { name, expected_type, TRUE };
1068 it = gst_bin_iterate_recurse (GST_BIN_CAST (obj));
1069 result = gst_iterator_find_custom (it,
1070 (GCompareFunc) find_property, &helper);
1071 gst_iterator_free (it);
1072 /* we don't need the extra ref */
1074 gst_object_unref (result);
1079 /* find an object in the hierarchy with a property named @name */
1081 gst_play_sink_find_property (GstPlaySink * playsink, GstElement * obj,
1082 const gchar * name, GType expected_type)
1084 GstElement *result = NULL;
1087 if (GST_IS_BIN (obj)) {
1088 FindPropertyHelper helper = { name, expected_type, FALSE };
1090 it = gst_bin_iterate_recurse (GST_BIN_CAST (obj));
1091 result = gst_iterator_find_custom (it,
1092 (GCompareFunc) find_property, &helper);
1093 gst_iterator_free (it);
1095 if (element_has_property (obj, name, expected_type)) {
1097 gst_object_ref (obj);
1104 do_async_start (GstPlaySink * playsink)
1106 GstMessage *message;
1108 if (!playsink->need_async_start) {
1109 GST_INFO_OBJECT (playsink, "no async_start needed");
1113 playsink->async_pending = TRUE;
1115 GST_INFO_OBJECT (playsink, "Sending async_start message");
1116 message = gst_message_new_async_start (GST_OBJECT_CAST (playsink), FALSE);
1117 GST_BIN_CLASS (gst_play_sink_parent_class)->handle_message (GST_BIN_CAST
1118 (playsink), message);
1122 do_async_done (GstPlaySink * playsink)
1124 GstMessage *message;
1126 if (playsink->async_pending) {
1127 GST_INFO_OBJECT (playsink, "Sending async_done message");
1128 message = gst_message_new_async_done (GST_OBJECT_CAST (playsink));
1129 GST_BIN_CLASS (gst_play_sink_parent_class)->handle_message (GST_BIN_CAST
1130 (playsink), message);
1132 playsink->async_pending = FALSE;
1135 playsink->need_async_start = FALSE;
1138 /* try to change the state of an element. This function returns the element when
1139 * the state change could be performed. When this function returns NULL an error
1140 * occured and the element is unreffed if @unref is TRUE. */
1142 try_element (GstPlaySink * playsink, GstElement * element, gboolean unref)
1144 GstStateChangeReturn ret;
1147 ret = gst_element_set_state (element, GST_STATE_READY);
1148 if (ret == GST_STATE_CHANGE_FAILURE) {
1149 GST_DEBUG_OBJECT (playsink, "failed state change..");
1150 gst_element_set_state (element, GST_STATE_NULL);
1152 gst_object_unref (element);
1159 /* make the element (bin) that contains the elements needed to perform
1160 * video display. Only used for *raw* video streams.
1162 * +------------------------------------------------------------+
1164 * | +-------+ +----------+ +----------+ +---------+ |
1165 * | | queue | |colorspace| |videoscale| |videosink| |
1166 * | +-sink src-sink src-sink src-sink | |
1167 * | | +-------+ +----------+ +----------+ +---------+ |
1169 * +------------------------------------------------------------+
1172 static GstPlayVideoDeinterlaceChain *
1173 gen_video_deinterlace_chain (GstPlaySink * playsink)
1175 GstPlayVideoDeinterlaceChain *chain;
1178 GstElement *head = NULL, *prev = NULL;
1180 chain = g_new0 (GstPlayVideoDeinterlaceChain, 1);
1181 chain->chain.playsink = playsink;
1183 GST_DEBUG_OBJECT (playsink, "making video deinterlace chain %p", chain);
1185 /* create a bin to hold objects, as we create them we add them to this bin so
1186 * that when something goes wrong we only need to unref the bin */
1187 chain->chain.bin = gst_bin_new ("vdbin");
1188 bin = GST_BIN_CAST (chain->chain.bin);
1189 gst_object_ref_sink (bin);
1191 GST_DEBUG_OBJECT (playsink, "creating " COLORSPACE);
1192 chain->conv = gst_element_factory_make (COLORSPACE, "vdconv");
1193 if (chain->conv == NULL) {
1194 post_missing_element_message (playsink, COLORSPACE);
1195 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1196 (_("Missing element '%s' - check your GStreamer installation."),
1197 COLORSPACE), ("video rendering might fail"));
1199 gst_bin_add (bin, chain->conv);
1204 GST_DEBUG_OBJECT (playsink, "creating deinterlace");
1205 chain->deinterlace = gst_element_factory_make ("deinterlace", "deinterlace");
1206 if (chain->deinterlace == NULL) {
1207 post_missing_element_message (playsink, "deinterlace");
1208 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1209 (_("Missing element '%s' - check your GStreamer installation."),
1210 "deinterlace"), ("deinterlacing won't work"));
1212 gst_bin_add (bin, chain->deinterlace);
1214 if (!gst_element_link_pads_full (prev, "src", chain->deinterlace, "sink",
1215 GST_PAD_LINK_CHECK_TEMPLATE_CAPS))
1218 head = chain->deinterlace;
1220 prev = chain->deinterlace;
1224 pad = gst_element_get_static_pad (head, "sink");
1225 chain->sinkpad = gst_ghost_pad_new ("sink", pad);
1226 gst_object_unref (pad);
1228 chain->sinkpad = gst_ghost_pad_new_no_target ("sink", GST_PAD_SINK);
1232 pad = gst_element_get_static_pad (prev, "src");
1233 chain->srcpad = gst_ghost_pad_new ("src", pad);
1234 gst_object_unref (pad);
1236 chain->srcpad = gst_ghost_pad_new ("src", chain->sinkpad);
1239 gst_element_add_pad (chain->chain.bin, chain->sinkpad);
1240 gst_element_add_pad (chain->chain.bin, chain->srcpad);
1246 GST_ELEMENT_ERROR (playsink, CORE, PAD,
1247 (NULL), ("Failed to configure the video deinterlace chain."));
1248 free_chain ((GstPlayChain *) chain);
1254 has_color_balance_element (GstElement * element)
1256 GstElement *cb = NULL;
1258 if (GST_IS_COLOR_BALANCE (element))
1260 else if (!GST_IS_BIN (element))
1263 cb = gst_bin_get_by_interface (GST_BIN (element), GST_TYPE_COLOR_BALANCE);
1264 gst_object_unref (cb);
1266 return (cb != NULL);
1269 /* make the element (bin) that contains the elements needed to perform
1272 * +------------------------------------------------------------+
1274 * | +-------+ +----------+ +----------+ +---------+ |
1275 * | | queue | |colorspace| |videoscale| |videosink| |
1276 * | +-sink src-sink src-sink src-sink | |
1277 * | | +-------+ +----------+ +----------+ +---------+ |
1279 * +------------------------------------------------------------+
1282 static GstPlayVideoChain *
1283 gen_video_chain (GstPlaySink * playsink, gboolean raw, gboolean async)
1285 GstPlayVideoChain *chain;
1288 GstElement *head = NULL, *prev = NULL, *elem = NULL;
1290 chain = g_new0 (GstPlayVideoChain, 1);
1291 chain->chain.playsink = playsink;
1292 chain->chain.raw = raw;
1294 GST_DEBUG_OBJECT (playsink, "making video chain %p", chain);
1296 if (playsink->video_sink) {
1297 GST_DEBUG_OBJECT (playsink, "trying configured videosink");
1298 chain->sink = try_element (playsink, playsink->video_sink, FALSE);
1300 /* only try fallback if no specific sink was chosen */
1301 if (chain->sink == NULL) {
1302 GST_DEBUG_OBJECT (playsink, "trying autovideosink");
1303 elem = gst_element_factory_make ("autovideosink", "videosink");
1304 chain->sink = try_element (playsink, elem, TRUE);
1306 if (chain->sink == NULL) {
1307 /* if default sink from config.h is different then try it too */
1308 if (strcmp (DEFAULT_VIDEOSINK, "autovideosink")) {
1309 GST_DEBUG_OBJECT (playsink, "trying " DEFAULT_VIDEOSINK);
1310 elem = gst_element_factory_make (DEFAULT_VIDEOSINK, "videosink");
1311 chain->sink = try_element (playsink, elem, TRUE);
1315 playsink->video_sink = gst_object_ref (chain->sink);
1317 if (chain->sink == NULL)
1321 /* if we can disable async behaviour of the sink, we can avoid adding a
1322 * queue for the audio chain. */
1324 gst_play_sink_find_property_sinks (playsink, chain->sink, "async",
1327 GST_DEBUG_OBJECT (playsink, "setting async property to %d on element %s",
1328 async, GST_ELEMENT_NAME (elem));
1329 g_object_set (elem, "async", async, NULL);
1330 chain->async = async;
1332 GST_DEBUG_OBJECT (playsink, "no async property on the sink");
1333 chain->async = TRUE;
1336 /* find ts-offset element */
1337 gst_object_replace ((GstObject **) & chain->ts_offset, (GstObject *)
1338 gst_play_sink_find_property_sinks (playsink, chain->sink, "ts-offset",
1341 /* create a bin to hold objects, as we create them we add them to this bin so
1342 * that when something goes wrong we only need to unref the bin */
1343 chain->chain.bin = gst_bin_new ("vbin");
1344 bin = GST_BIN_CAST (chain->chain.bin);
1345 gst_object_ref_sink (bin);
1346 gst_bin_add (bin, chain->sink);
1348 /* decouple decoder from sink, this improves playback quite a lot since the
1349 * decoder can continue while the sink blocks for synchronisation. We don't
1350 * need a lot of buffers as this consumes a lot of memory and we don't want
1351 * too little because else we would be context switching too quickly. */
1352 chain->queue = gst_element_factory_make ("queue", "vqueue");
1353 if (chain->queue == NULL) {
1354 post_missing_element_message (playsink, "queue");
1355 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1356 (_("Missing element '%s' - check your GStreamer installation."),
1357 "queue"), ("video rendering might be suboptimal"));
1361 g_object_set (G_OBJECT (chain->queue), "max-size-buffers", 3,
1362 "max-size-bytes", 0, "max-size-time", (gint64) 0, "silent", TRUE, NULL);
1363 gst_bin_add (bin, chain->queue);
1364 head = prev = chain->queue;
1367 if (!(playsink->flags & GST_PLAY_FLAG_NATIVE_VIDEO)
1368 || (!has_color_balance_element (chain->sink)
1369 && (playsink->flags & GST_PLAY_FLAG_SOFT_COLORBALANCE))) {
1370 gboolean use_converters = !(playsink->flags & GST_PLAY_FLAG_NATIVE_VIDEO);
1371 gboolean use_balance = !has_color_balance_element (chain->sink)
1372 && (playsink->flags & GST_PLAY_FLAG_SOFT_COLORBALANCE);
1374 GST_DEBUG_OBJECT (playsink, "creating videoconverter");
1376 g_object_new (GST_TYPE_PLAY_SINK_VIDEO_CONVERT, "name", "vconv",
1377 "use-converters", use_converters, "use-balance", use_balance, NULL);
1378 gst_bin_add (bin, chain->conv);
1380 if (!gst_element_link_pads_full (prev, "src", chain->conv, "sink",
1381 GST_PAD_LINK_CHECK_TEMPLATE_CAPS))
1390 GST_DEBUG_OBJECT (playsink, "linking to sink");
1391 if (!gst_element_link_pads_full (prev, "src", chain->sink, NULL,
1392 GST_PAD_LINK_CHECK_TEMPLATE_CAPS))
1396 pad = gst_element_get_static_pad (head, "sink");
1397 chain->sinkpad = gst_ghost_pad_new ("sink", pad);
1398 gst_object_unref (pad);
1400 gst_element_add_pad (chain->chain.bin, chain->sinkpad);
1407 if (!elem && !playsink->video_sink) {
1408 post_missing_element_message (playsink, "autovideosink");
1409 if (strcmp (DEFAULT_VIDEOSINK, "autovideosink")) {
1410 post_missing_element_message (playsink, DEFAULT_VIDEOSINK);
1411 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
1412 (_("Both autovideosink and %s elements are missing."),
1413 DEFAULT_VIDEOSINK), (NULL));
1415 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
1416 (_("The autovideosink element is missing.")), (NULL));
1419 if (playsink->video_sink) {
1420 GST_ELEMENT_ERROR (playsink, CORE, STATE_CHANGE,
1421 (_("Configured videosink %s is not working."),
1422 GST_ELEMENT_NAME (playsink->video_sink)), (NULL));
1423 } else if (strcmp (DEFAULT_VIDEOSINK, "autovideosink")) {
1424 GST_ELEMENT_ERROR (playsink, CORE, STATE_CHANGE,
1425 (_("Both autovideosink and %s elements are not working."),
1426 DEFAULT_VIDEOSINK), (NULL));
1428 GST_ELEMENT_ERROR (playsink, CORE, STATE_CHANGE,
1429 (_("The autovideosink element is not working.")), (NULL));
1432 free_chain ((GstPlayChain *) chain);
1437 GST_ELEMENT_ERROR (playsink, CORE, PAD,
1438 (NULL), ("Failed to configure the video sink."));
1439 /* checking sink made it READY */
1440 gst_element_set_state (chain->sink, GST_STATE_NULL);
1441 /* Remove chain from the bin to allow reuse later */
1442 gst_bin_remove (bin, chain->sink);
1443 free_chain ((GstPlayChain *) chain);
1449 setup_video_chain (GstPlaySink * playsink, gboolean raw, gboolean async)
1452 GstPlayVideoChain *chain;
1453 GstStateChangeReturn ret;
1455 chain = playsink->videochain;
1457 chain->chain.raw = raw;
1459 /* if the chain was active we don't do anything */
1460 if (GST_PLAY_CHAIN (chain)->activated == TRUE)
1463 /* try to set the sink element to READY again */
1464 ret = gst_element_set_state (chain->sink, GST_STATE_READY);
1465 if (ret == GST_STATE_CHANGE_FAILURE)
1468 /* find ts-offset element */
1470 gst_object_replace ((GstObject **) & chain->ts_offset, (GstObject *)
1471 gst_play_sink_find_property_sinks (playsink, chain->sink, "ts-offset",
1474 /* if we can disable async behaviour of the sink, we can avoid adding a
1475 * queue for the audio chain. */
1477 gst_play_sink_find_property_sinks (playsink, chain->sink, "async",
1480 GST_DEBUG_OBJECT (playsink, "setting async property to %d on element %s",
1481 async, GST_ELEMENT_NAME (elem));
1482 g_object_set (elem, "async", async, NULL);
1483 chain->async = async;
1485 GST_DEBUG_OBJECT (playsink, "no async property on the sink");
1486 chain->async = TRUE;
1490 g_object_set (chain->conv, "use-balance",
1491 !has_color_balance_element (chain->sink)
1492 && (playsink->flags & GST_PLAY_FLAG_SOFT_COLORBALANCE), NULL);
1497 /* make an element for playback of video with subtitles embedded.
1498 * Only used for *raw* video streams.
1500 * +--------------------------------------------+
1502 * | +--------+ +-----------------+ |
1503 * | | queue | | subtitleoverlay | |
1504 * video--src sink---video_sink | |
1505 * | +--------+ | src--src
1506 * text------------------text_sink | |
1507 * | +-----------------+ |
1508 * +--------------------------------------------+
1511 static GstPlayTextChain *
1512 gen_text_chain (GstPlaySink * playsink)
1514 GstPlayTextChain *chain;
1517 GstPad *videosinkpad, *textsinkpad, *srcpad;
1519 chain = g_new0 (GstPlayTextChain, 1);
1520 chain->chain.playsink = playsink;
1522 GST_DEBUG_OBJECT (playsink, "making text chain %p", chain);
1524 chain->chain.bin = gst_bin_new ("tbin");
1525 bin = GST_BIN_CAST (chain->chain.bin);
1526 gst_object_ref_sink (bin);
1528 videosinkpad = textsinkpad = srcpad = NULL;
1530 /* first try to hook the text pad to the custom sink */
1531 if (playsink->text_sink) {
1532 GST_DEBUG_OBJECT (playsink, "trying configured textsink");
1533 chain->sink = try_element (playsink, playsink->text_sink, FALSE);
1536 gst_play_sink_find_property_sinks (playsink, chain->sink, "async",
1539 /* make sure the sparse subtitles don't participate in the preroll */
1540 g_object_set (elem, "async", FALSE, NULL);
1541 GST_DEBUG_OBJECT (playsink, "adding custom text sink");
1542 gst_bin_add (bin, chain->sink);
1543 /* NOTE streamsynchronizer needs streams decoupled */
1544 /* make a little queue */
1545 chain->queue = gst_element_factory_make ("queue", "subqueue");
1546 if (chain->queue == NULL) {
1547 post_missing_element_message (playsink, "queue");
1548 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1549 (_("Missing element '%s' - check your GStreamer installation."),
1550 "queue"), ("rendering might be suboptimal"));
1552 g_object_set (G_OBJECT (chain->queue), "max-size-buffers", 3,
1553 "max-size-bytes", 0, "max-size-time", (gint64) 0,
1554 "silent", TRUE, NULL);
1555 gst_bin_add (bin, chain->queue);
1557 /* we have a custom sink, this will be our textsinkpad */
1558 if (gst_element_link_pads_full (chain->queue, "src", chain->sink,
1559 "sink", GST_PAD_LINK_CHECK_TEMPLATE_CAPS)) {
1560 /* we're all fine now and we can add the sink to the chain */
1561 GST_DEBUG_OBJECT (playsink, "using custom text sink");
1562 textsinkpad = gst_element_get_static_pad (chain->queue, "sink");
1564 GST_WARNING_OBJECT (playsink,
1565 "can't find a sink pad on custom text sink");
1566 gst_bin_remove (bin, chain->sink);
1567 gst_bin_remove (bin, chain->queue);
1569 chain->queue = NULL;
1571 /* try to set sync to true but it's no biggie when we can't */
1572 if (chain->sink && (elem =
1573 gst_play_sink_find_property_sinks (playsink, chain->sink,
1574 "sync", G_TYPE_BOOLEAN)))
1575 g_object_set (elem, "sync", TRUE, NULL);
1578 gst_bin_remove (bin, chain->sink);
1580 GST_WARNING_OBJECT (playsink,
1581 "can't find async property in custom text sink");
1584 if (textsinkpad == NULL) {
1585 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1586 (_("Custom text sink element is not usable.")),
1587 ("fallback to default textoverlay"));
1591 if (textsinkpad == NULL) {
1592 if (!(playsink->flags & GST_PLAY_FLAG_NATIVE_VIDEO)) {
1593 /* make a little queue */
1594 chain->queue = gst_element_factory_make ("queue", "vqueue");
1595 if (chain->queue == NULL) {
1596 post_missing_element_message (playsink, "queue");
1597 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1598 (_("Missing element '%s' - check your GStreamer installation."),
1599 "queue"), ("video rendering might be suboptimal"));
1601 g_object_set (G_OBJECT (chain->queue), "max-size-buffers", 3,
1602 "max-size-bytes", 0, "max-size-time", (gint64) 0,
1603 "silent", TRUE, NULL);
1604 gst_bin_add (bin, chain->queue);
1605 videosinkpad = gst_element_get_static_pad (chain->queue, "sink");
1609 gst_element_factory_make ("subtitleoverlay", "suboverlay");
1610 if (chain->overlay == NULL) {
1611 post_missing_element_message (playsink, "subtitleoverlay");
1612 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1613 (_("Missing element '%s' - check your GStreamer installation."),
1614 "subtitleoverlay"), ("subtitle rendering disabled"));
1616 GstElement *element;
1618 gst_bin_add (bin, chain->overlay);
1620 g_object_set (G_OBJECT (chain->overlay), "silent", FALSE, NULL);
1621 if (playsink->font_desc) {
1622 g_object_set (G_OBJECT (chain->overlay), "font-desc",
1623 playsink->font_desc, NULL);
1625 if (playsink->subtitle_encoding) {
1626 g_object_set (G_OBJECT (chain->overlay), "subtitle-encoding",
1627 playsink->subtitle_encoding, NULL);
1630 gst_element_link_pads_full (chain->queue, "src", chain->overlay,
1631 "video_sink", GST_PAD_LINK_CHECK_TEMPLATE_CAPS);
1633 /* make another little queue to decouple streams */
1634 element = gst_element_factory_make ("queue", "subqueue");
1635 if (element == NULL) {
1636 post_missing_element_message (playsink, "queue");
1637 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1638 (_("Missing element '%s' - check your GStreamer installation."),
1639 "queue"), ("rendering might be suboptimal"));
1641 g_object_set (G_OBJECT (element), "max-size-buffers", 3,
1642 "max-size-bytes", 0, "max-size-time", (gint64) 0,
1643 "silent", TRUE, NULL);
1644 gst_bin_add (bin, element);
1645 if (gst_element_link_pads_full (element, "src", chain->overlay,
1646 "subtitle_sink", GST_PAD_LINK_CHECK_TEMPLATE_CAPS)) {
1647 textsinkpad = gst_element_get_static_pad (element, "sink");
1648 srcpad = gst_element_get_static_pad (chain->overlay, "src");
1650 gst_bin_remove (bin, chain->sink);
1651 gst_bin_remove (bin, chain->overlay);
1653 chain->overlay = NULL;
1654 gst_object_unref (videosinkpad);
1655 videosinkpad = NULL;
1662 if (videosinkpad == NULL) {
1663 /* if we still don't have a videosink, we don't have an overlay. the only
1664 * thing we can do is insert an identity and ghost the src
1666 chain->identity = gst_element_factory_make ("identity", "tidentity");
1667 if (chain->identity == NULL) {
1668 post_missing_element_message (playsink, "identity");
1669 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
1670 (_("Missing element '%s' - check your GStreamer installation."),
1671 "identity"), (NULL));
1673 g_object_set (chain->identity, "signal-handoffs", FALSE, NULL);
1674 g_object_set (chain->identity, "silent", TRUE, NULL);
1675 gst_bin_add (bin, chain->identity);
1676 srcpad = gst_element_get_static_pad (chain->identity, "src");
1677 videosinkpad = gst_element_get_static_pad (chain->identity, "sink");
1681 /* expose the ghostpads */
1683 chain->videosinkpad = gst_ghost_pad_new ("sink", videosinkpad);
1684 gst_object_unref (videosinkpad);
1685 gst_element_add_pad (chain->chain.bin, chain->videosinkpad);
1688 chain->textsinkpad = gst_ghost_pad_new ("text_sink", textsinkpad);
1689 gst_object_unref (textsinkpad);
1690 gst_element_add_pad (chain->chain.bin, chain->textsinkpad);
1693 chain->srcpad = gst_ghost_pad_new ("src", srcpad);
1694 gst_object_unref (srcpad);
1695 gst_element_add_pad (chain->chain.bin, chain->srcpad);
1702 notify_volume_cb (GObject * object, GParamSpec * pspec, GstPlaySink * playsink)
1706 g_object_get (object, "volume", &vol, NULL);
1707 playsink->volume = vol;
1709 g_object_notify (G_OBJECT (playsink), "volume");
1713 notify_mute_cb (GObject * object, GParamSpec * pspec, GstPlaySink * playsink)
1717 g_object_get (object, "mute", &mute, NULL);
1718 playsink->mute = mute;
1720 g_object_notify (G_OBJECT (playsink), "mute");
1723 /* make the chain that contains the elements needed to perform
1726 * We add a tee as the first element so that we can link the visualisation chain
1727 * to it when requested.
1729 * +-------------------------------------------------------------+
1731 * | +---------+ +----------+ +---------+ +---------+ |
1732 * | |audioconv| |audioscale| | volume | |audiosink| |
1733 * | +-srck src-sink src-sink src-sink | |
1734 * | | +---------+ +----------+ +---------+ +---------+ |
1736 * +-------------------------------------------------------------+
1738 static GstPlayAudioChain *
1739 gen_audio_chain (GstPlaySink * playsink, gboolean raw)
1741 GstPlayAudioChain *chain;
1743 gboolean have_volume;
1745 GstElement *head, *prev, *elem = NULL;
1747 chain = g_new0 (GstPlayAudioChain, 1);
1748 chain->chain.playsink = playsink;
1749 chain->chain.raw = raw;
1751 GST_DEBUG_OBJECT (playsink, "making audio chain %p", chain);
1753 if (playsink->audio_sink) {
1754 GST_DEBUG_OBJECT (playsink, "trying configured audiosink %" GST_PTR_FORMAT,
1755 playsink->audio_sink);
1756 chain->sink = try_element (playsink, playsink->audio_sink, FALSE);
1758 /* only try fallback if no specific sink was chosen */
1759 if (chain->sink == NULL) {
1760 GST_DEBUG_OBJECT (playsink, "trying autoaudiosink");
1761 elem = gst_element_factory_make ("autoaudiosink", "audiosink");
1762 chain->sink = try_element (playsink, elem, TRUE);
1764 if (chain->sink == NULL) {
1765 /* if default sink from config.h is different then try it too */
1766 if (strcmp (DEFAULT_AUDIOSINK, "autoaudiosink")) {
1767 GST_DEBUG_OBJECT (playsink, "trying " DEFAULT_AUDIOSINK);
1768 elem = gst_element_factory_make (DEFAULT_AUDIOSINK, "audiosink");
1769 chain->sink = try_element (playsink, elem, TRUE);
1773 playsink->audio_sink = gst_object_ref (chain->sink);
1775 if (chain->sink == NULL)
1778 chain->chain.bin = gst_bin_new ("abin");
1779 bin = GST_BIN_CAST (chain->chain.bin);
1780 gst_object_ref_sink (bin);
1781 gst_bin_add (bin, chain->sink);
1783 /* we have to add a queue when we need to decouple for the video sink in
1784 * visualisations and for streamsynchronizer */
1785 GST_DEBUG_OBJECT (playsink, "adding audio queue");
1786 chain->queue = gst_element_factory_make ("queue", "aqueue");
1787 if (chain->queue == NULL) {
1788 post_missing_element_message (playsink, "queue");
1789 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1790 (_("Missing element '%s' - check your GStreamer installation."),
1791 "queue"), ("audio playback and visualizations might not work"));
1795 g_object_set (chain->queue, "silent", TRUE, NULL);
1796 gst_bin_add (bin, chain->queue);
1797 prev = head = chain->queue;
1800 /* find ts-offset element */
1801 gst_object_replace ((GstObject **) & chain->ts_offset, (GstObject *)
1802 gst_play_sink_find_property_sinks (playsink, chain->sink, "ts-offset",
1805 /* check if the sink, or something within the sink, has the volume property.
1806 * If it does we don't need to add a volume element. */
1808 gst_play_sink_find_property_sinks (playsink, chain->sink, "volume",
1811 chain->volume = elem;
1813 g_signal_connect (chain->volume, "notify::volume",
1814 G_CALLBACK (notify_volume_cb), playsink);
1816 GST_DEBUG_OBJECT (playsink, "the sink has a volume property");
1818 chain->sink_volume = TRUE;
1819 /* if the sink also has a mute property we can use this as well. We'll only
1820 * use the mute property if there is a volume property. We can simulate the
1821 * mute with the volume otherwise. */
1823 gst_play_sink_find_property_sinks (playsink, chain->sink, "mute",
1826 GST_DEBUG_OBJECT (playsink, "the sink has a mute property");
1827 g_signal_connect (chain->mute, "notify::mute",
1828 G_CALLBACK (notify_mute_cb), playsink);
1830 /* use the sink to control the volume and mute */
1831 if (playsink->volume_changed) {
1832 g_object_set (G_OBJECT (chain->volume), "volume", playsink->volume, NULL);
1833 playsink->volume_changed = FALSE;
1835 if (playsink->mute_changed) {
1837 g_object_set (chain->mute, "mute", playsink->mute, NULL);
1840 g_object_set (chain->volume, "volume", (gdouble) 0.0, NULL);
1842 playsink->mute_changed = FALSE;
1845 /* no volume, we need to add a volume element when we can */
1846 GST_DEBUG_OBJECT (playsink, "the sink has no volume property");
1847 have_volume = FALSE;
1848 chain->sink_volume = FALSE;
1851 if (!(playsink->flags & GST_PLAY_FLAG_NATIVE_AUDIO) || (!have_volume
1852 && (playsink->flags & GST_PLAY_FLAG_SOFT_VOLUME))) {
1853 gboolean use_converters = !(playsink->flags & GST_PLAY_FLAG_NATIVE_AUDIO);
1854 gboolean use_volume =
1855 !have_volume && (playsink->flags & GST_PLAY_FLAG_SOFT_VOLUME);
1856 GST_DEBUG_OBJECT (playsink,
1857 "creating audioconvert with use-converters %d, use-volume %d",
1858 use_converters, use_volume);
1860 g_object_new (GST_TYPE_PLAY_SINK_AUDIO_CONVERT, "name", "aconv",
1861 "use-converters", use_converters, "use-volume", use_volume, NULL);
1862 gst_bin_add (bin, chain->conv);
1864 if (!gst_element_link_pads_full (prev, "src", chain->conv, "sink",
1865 GST_PAD_LINK_CHECK_TEMPLATE_CAPS))
1872 if (!have_volume && (playsink->flags & GST_PLAY_FLAG_SOFT_VOLUME)) {
1873 GstPlaySinkAudioConvert *conv =
1874 GST_PLAY_SINK_AUDIO_CONVERT_CAST (chain->conv);
1877 chain->volume = conv->volume;
1880 g_signal_connect (chain->volume, "notify::volume",
1881 G_CALLBACK (notify_volume_cb), playsink);
1883 /* volume also has the mute property */
1884 chain->mute = chain->volume;
1885 g_signal_connect (chain->mute, "notify::mute",
1886 G_CALLBACK (notify_mute_cb), playsink);
1888 /* configure with the latest volume and mute */
1889 g_object_set (G_OBJECT (chain->volume), "volume", playsink->volume,
1891 g_object_set (G_OBJECT (chain->mute), "mute", playsink->mute, NULL);
1897 /* we only have to link to the previous element if we have something in
1898 * front of the sink */
1899 GST_DEBUG_OBJECT (playsink, "linking to sink");
1900 if (!gst_element_link_pads_full (prev, "src", chain->sink, NULL,
1901 GST_PAD_LINK_CHECK_TEMPLATE_CAPS))
1905 /* post a warning if we have no way to configure the volume */
1907 GST_ELEMENT_WARNING (playsink, STREAM, NOT_IMPLEMENTED,
1908 (_("No volume control found")), ("Volume/mute is not available"));
1911 /* and ghost the sinkpad of the headmost element */
1912 GST_DEBUG_OBJECT (playsink, "ghosting sink pad");
1913 pad = gst_element_get_static_pad (head, "sink");
1914 chain->sinkpad = gst_ghost_pad_new ("sink", pad);
1915 gst_object_unref (pad);
1916 gst_element_add_pad (chain->chain.bin, chain->sinkpad);
1923 if (!elem && !playsink->audio_sink) {
1924 post_missing_element_message (playsink, "autoaudiosink");
1925 if (strcmp (DEFAULT_AUDIOSINK, "autoaudiosink")) {
1926 post_missing_element_message (playsink, DEFAULT_AUDIOSINK);
1927 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
1928 (_("Both autoaudiosink and %s elements are missing."),
1929 DEFAULT_AUDIOSINK), (NULL));
1931 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
1932 (_("The autoaudiosink element is missing.")), (NULL));
1935 if (playsink->audio_sink) {
1936 GST_ELEMENT_ERROR (playsink, CORE, STATE_CHANGE,
1937 (_("Configured audiosink %s is not working."),
1938 GST_ELEMENT_NAME (playsink->audio_sink)), (NULL));
1939 } else if (strcmp (DEFAULT_AUDIOSINK, "autoaudiosink")) {
1940 GST_ELEMENT_ERROR (playsink, CORE, STATE_CHANGE,
1941 (_("Both autoaudiosink and %s elements are not working."),
1942 DEFAULT_AUDIOSINK), (NULL));
1944 GST_ELEMENT_ERROR (playsink, CORE, STATE_CHANGE,
1945 (_("The autoaudiosink element is not working.")), (NULL));
1948 free_chain ((GstPlayChain *) chain);
1953 GST_ELEMENT_ERROR (playsink, CORE, PAD,
1954 (NULL), ("Failed to configure the audio sink."));
1955 /* checking sink made it READY */
1956 gst_element_set_state (chain->sink, GST_STATE_NULL);
1957 /* Remove chain from the bin to allow reuse later */
1958 gst_bin_remove (bin, chain->sink);
1959 free_chain ((GstPlayChain *) chain);
1965 setup_audio_chain (GstPlaySink * playsink, gboolean raw)
1968 GstPlayAudioChain *chain;
1969 GstStateChangeReturn ret;
1971 chain = playsink->audiochain;
1973 chain->chain.raw = raw;
1975 /* if the chain was active we don't do anything */
1976 if (GST_PLAY_CHAIN (chain)->activated == TRUE)
1979 /* try to set the sink element to READY again */
1980 ret = gst_element_set_state (chain->sink, GST_STATE_READY);
1981 if (ret == GST_STATE_CHANGE_FAILURE)
1984 /* find ts-offset element */
1985 gst_object_replace ((GstObject **) & chain->ts_offset, (GstObject *)
1986 gst_play_sink_find_property_sinks (playsink, chain->sink, "ts-offset",
1989 /* check if the sink, or something within the sink, has the volume property.
1990 * If it does we don't need to add a volume element. */
1992 gst_play_sink_find_property_sinks (playsink, chain->sink, "volume",
1995 chain->volume = elem;
1997 if (playsink->volume_changed) {
1998 GST_DEBUG_OBJECT (playsink, "the sink has a volume property, setting %f",
2000 /* use the sink to control the volume */
2001 g_object_set (G_OBJECT (chain->volume), "volume", playsink->volume, NULL);
2002 playsink->volume_changed = FALSE;
2005 g_signal_connect (chain->volume, "notify::volume",
2006 G_CALLBACK (notify_volume_cb), playsink);
2007 /* if the sink also has a mute property we can use this as well. We'll only
2008 * use the mute property if there is a volume property. We can simulate the
2009 * mute with the volume otherwise. */
2011 gst_play_sink_find_property_sinks (playsink, chain->sink, "mute",
2014 GST_DEBUG_OBJECT (playsink, "the sink has a mute property");
2015 g_signal_connect (chain->mute, "notify::mute",
2016 G_CALLBACK (notify_mute_cb), playsink);
2019 g_object_set (chain->conv, "use-volume", FALSE, NULL);
2021 GstPlaySinkAudioConvert *conv =
2022 GST_PLAY_SINK_AUDIO_CONVERT_CAST (chain->conv);
2024 /* no volume, we need to add a volume element when we can */
2025 g_object_set (chain->conv, "use-volume",
2026 ! !(playsink->flags & GST_PLAY_FLAG_SOFT_VOLUME), NULL);
2027 GST_DEBUG_OBJECT (playsink, "the sink has no volume property");
2029 /* Disconnect signals */
2030 disconnect_chain (chain, playsink);
2032 if (conv->volume && (playsink->flags & GST_PLAY_FLAG_SOFT_VOLUME)) {
2033 chain->volume = conv->volume;
2034 chain->mute = chain->volume;
2036 g_signal_connect (chain->volume, "notify::volume",
2037 G_CALLBACK (notify_volume_cb), playsink);
2039 g_signal_connect (chain->mute, "notify::mute",
2040 G_CALLBACK (notify_mute_cb), playsink);
2042 /* configure with the latest volume and mute */
2043 g_object_set (G_OBJECT (chain->volume), "volume", playsink->volume, NULL);
2044 g_object_set (G_OBJECT (chain->mute), "mute", playsink->mute, NULL);
2047 GST_DEBUG_OBJECT (playsink, "reusing existing volume element");
2053 * +-------------------------------------------------------------------+
2055 * | +----------+ +------------+ +----------+ +-------+ |
2056 * | | visqueue | | audioconv | | audiores | | vis | |
2057 * | +-sink src-sink + samp src-sink src-sink src-+ |
2058 * | | +----------+ +------------+ +----------+ +-------+ | |
2060 * +-------------------------------------------------------------------+
2063 static GstPlayVisChain *
2064 gen_vis_chain (GstPlaySink * playsink)
2066 GstPlayVisChain *chain;
2072 chain = g_new0 (GstPlayVisChain, 1);
2073 chain->chain.playsink = playsink;
2075 GST_DEBUG_OBJECT (playsink, "making vis chain %p", chain);
2077 chain->chain.bin = gst_bin_new ("visbin");
2078 bin = GST_BIN_CAST (chain->chain.bin);
2079 gst_object_ref_sink (bin);
2081 /* we're queuing raw audio here, we can remove this queue when we can disable
2082 * async behaviour in the video sink. */
2083 chain->queue = gst_element_factory_make ("queue", "visqueue");
2084 if (chain->queue == NULL)
2086 g_object_set (chain->queue, "silent", TRUE, NULL);
2087 gst_bin_add (bin, chain->queue);
2089 chain->conv = gst_element_factory_make ("audioconvert", "aconv");
2090 if (chain->conv == NULL)
2091 goto no_audioconvert;
2092 gst_bin_add (bin, chain->conv);
2094 chain->resample = gst_element_factory_make ("audioresample", "aresample");
2095 if (chain->resample == NULL)
2096 goto no_audioresample;
2097 gst_bin_add (bin, chain->resample);
2099 /* this pad will be used for blocking the dataflow and switching the vis
2101 chain->blockpad = gst_element_get_static_pad (chain->resample, "src");
2103 if (playsink->visualisation) {
2104 GST_DEBUG_OBJECT (playsink, "trying configure vis");
2105 chain->vis = try_element (playsink, playsink->visualisation, FALSE);
2107 if (chain->vis == NULL) {
2108 GST_DEBUG_OBJECT (playsink, "trying goom");
2109 elem = gst_element_factory_make ("goom", "vis");
2110 chain->vis = try_element (playsink, elem, TRUE);
2112 if (chain->vis == NULL)
2115 gst_bin_add (bin, chain->vis);
2117 res = gst_element_link_pads_full (chain->queue, "src", chain->conv, "sink",
2118 GST_PAD_LINK_CHECK_NOTHING);
2120 gst_element_link_pads_full (chain->conv, "src", chain->resample, "sink",
2121 GST_PAD_LINK_CHECK_NOTHING);
2123 gst_element_link_pads_full (chain->resample, "src", chain->vis, "sink",
2124 GST_PAD_LINK_CHECK_NOTHING);
2128 chain->vissinkpad = gst_element_get_static_pad (chain->vis, "sink");
2129 chain->vissrcpad = gst_element_get_static_pad (chain->vis, "src");
2131 pad = gst_element_get_static_pad (chain->queue, "sink");
2132 chain->sinkpad = gst_ghost_pad_new ("sink", pad);
2133 gst_object_unref (pad);
2134 gst_element_add_pad (chain->chain.bin, chain->sinkpad);
2136 chain->srcpad = gst_ghost_pad_new ("src", chain->vissrcpad);
2137 gst_element_add_pad (chain->chain.bin, chain->srcpad);
2144 post_missing_element_message (playsink, "queue");
2145 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
2146 (_("Missing element '%s' - check your GStreamer installation."),
2148 free_chain ((GstPlayChain *) chain);
2153 post_missing_element_message (playsink, "audioconvert");
2154 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
2155 (_("Missing element '%s' - check your GStreamer installation."),
2156 "audioconvert"), ("possibly a liboil version mismatch?"));
2157 free_chain ((GstPlayChain *) chain);
2162 post_missing_element_message (playsink, "audioresample");
2163 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
2164 (_("Missing element '%s' - check your GStreamer installation."),
2165 "audioresample"), (NULL));
2166 free_chain ((GstPlayChain *) chain);
2171 post_missing_element_message (playsink, "goom");
2172 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
2173 (_("Missing element '%s' - check your GStreamer installation."),
2175 free_chain ((GstPlayChain *) chain);
2180 GST_ELEMENT_ERROR (playsink, CORE, PAD,
2181 (NULL), ("Failed to configure the visualisation element."));
2182 /* element made it to READY */
2183 gst_element_set_state (chain->vis, GST_STATE_NULL);
2184 free_chain ((GstPlayChain *) chain);
2189 /* this function is called when all the request pads are requested and when we
2190 * have to construct the final pipeline. Based on the flags we construct the
2191 * final output pipelines.
2194 gst_play_sink_reconfigure (GstPlaySink * playsink)
2197 gboolean need_audio, need_video, need_deinterlace, need_vis, need_text;
2199 GST_DEBUG_OBJECT (playsink, "reconfiguring");
2201 /* assume we need nothing */
2202 need_audio = need_video = need_deinterlace = need_vis = need_text = FALSE;
2204 GST_PLAY_SINK_LOCK (playsink);
2205 GST_OBJECT_LOCK (playsink);
2206 /* get flags, there are protected with the object lock */
2207 flags = playsink->flags;
2208 GST_OBJECT_UNLOCK (playsink);
2210 /* figure out which components we need */
2211 if (flags & GST_PLAY_FLAG_TEXT && playsink->text_pad) {
2212 /* we have subtitles and we are requested to show it */
2216 if (((flags & GST_PLAY_FLAG_VIDEO)
2217 || (flags & GST_PLAY_FLAG_NATIVE_VIDEO)) && playsink->video_pad) {
2218 /* we have video and we are requested to show it */
2221 /* we only deinterlace if native video is not requested and
2222 * we have raw video */
2223 if ((flags & GST_PLAY_FLAG_DEINTERLACE)
2224 && !(flags & GST_PLAY_FLAG_NATIVE_VIDEO) && playsink->video_pad_raw)
2225 need_deinterlace = TRUE;
2228 if (playsink->audio_pad) {
2229 if ((flags & GST_PLAY_FLAG_AUDIO) || (flags & GST_PLAY_FLAG_NATIVE_AUDIO)) {
2232 if (playsink->audio_pad_raw) {
2233 /* only can do vis with raw uncompressed audio */
2234 if (flags & GST_PLAY_FLAG_VIS && !need_video) {
2235 /* also add video when we add visualisation */
2242 /* we have a text_pad and we need text rendering, in this case we need a
2243 * video_pad to combine the video with the text or visualizations */
2244 if (need_text && !need_video) {
2245 if (playsink->video_pad) {
2247 } else if (need_audio) {
2248 GST_ELEMENT_WARNING (playsink, STREAM, FORMAT,
2249 (_("Can't play a text file without video or visualizations.")),
2250 ("Have text pad but no video pad or visualizations"));
2253 GST_ELEMENT_ERROR (playsink, STREAM, FORMAT,
2254 (_("Can't play a text file without video or visualizations.")),
2255 ("Have text pad but no video pad or visualizations"));
2256 GST_PLAY_SINK_UNLOCK (playsink);
2261 GST_DEBUG_OBJECT (playsink, "audio:%d, video:%d, vis:%d, text:%d", need_audio,
2262 need_video, need_vis, need_text);
2264 /* set up video pipeline */
2266 gboolean raw, async;
2268 /* we need a raw sink when we do vis or when we have a raw pad */
2269 raw = need_vis ? TRUE : playsink->video_pad_raw;
2270 /* we try to set the sink async=FALSE when we need vis, this way we can
2271 * avoid a queue in the audio chain. */
2274 GST_DEBUG_OBJECT (playsink, "adding video, raw %d",
2275 playsink->video_pad_raw);
2277 if (playsink->videochain) {
2278 /* try to reactivate the chain */
2279 if (!setup_video_chain (playsink, raw, async)) {
2280 if (playsink->video_sinkpad_stream_synchronizer) {
2281 gst_element_release_request_pad (GST_ELEMENT_CAST
2282 (playsink->stream_synchronizer),
2283 playsink->video_sinkpad_stream_synchronizer);
2284 gst_object_unref (playsink->video_sinkpad_stream_synchronizer);
2285 playsink->video_sinkpad_stream_synchronizer = NULL;
2286 gst_object_unref (playsink->video_srcpad_stream_synchronizer);
2287 playsink->video_srcpad_stream_synchronizer = NULL;
2290 add_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE);
2292 /* Remove the sink from the bin to keep its state
2293 * and unparent it to allow reuse */
2294 if (playsink->videochain->sink)
2295 gst_bin_remove (GST_BIN_CAST (playsink->videochain->chain.bin),
2296 playsink->videochain->sink);
2298 activate_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE);
2299 free_chain ((GstPlayChain *) playsink->videochain);
2300 playsink->videochain = NULL;
2304 if (!playsink->videochain)
2305 playsink->videochain = gen_video_chain (playsink, raw, async);
2306 if (!playsink->videochain)
2309 if (!playsink->video_sinkpad_stream_synchronizer) {
2312 playsink->video_sinkpad_stream_synchronizer =
2313 gst_element_get_request_pad (GST_ELEMENT_CAST
2314 (playsink->stream_synchronizer), "sink_%d");
2315 it = gst_pad_iterate_internal_links
2316 (playsink->video_sinkpad_stream_synchronizer);
2318 gst_iterator_next (it,
2319 (gpointer *) & playsink->video_srcpad_stream_synchronizer);
2320 g_assert (playsink->video_srcpad_stream_synchronizer);
2321 gst_iterator_free (it);
2324 if (playsink->video_pad)
2325 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (playsink->video_pad),
2326 playsink->video_sinkpad_stream_synchronizer);
2328 if (need_deinterlace) {
2329 if (!playsink->videodeinterlacechain)
2330 playsink->videodeinterlacechain =
2331 gen_video_deinterlace_chain (playsink);
2332 if (!playsink->videodeinterlacechain)
2335 GST_DEBUG_OBJECT (playsink, "adding video deinterlace chain");
2337 GST_DEBUG_OBJECT (playsink, "setting up deinterlacing chain");
2339 add_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain), TRUE);
2340 activate_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain), TRUE);
2342 gst_pad_link_full (playsink->video_srcpad_stream_synchronizer,
2343 playsink->videodeinterlacechain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2345 if (playsink->videodeinterlacechain) {
2346 add_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain), FALSE);
2347 activate_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain),
2352 GST_DEBUG_OBJECT (playsink, "adding video chain");
2353 add_chain (GST_PLAY_CHAIN (playsink->videochain), TRUE);
2354 activate_chain (GST_PLAY_CHAIN (playsink->videochain), TRUE);
2355 /* if we are not part of vis or subtitles, set the ghostpad target */
2356 if (!need_vis && !need_text && (!playsink->textchain
2357 || !playsink->text_pad)) {
2358 GST_DEBUG_OBJECT (playsink, "ghosting video sinkpad");
2359 if (need_deinterlace)
2360 gst_pad_link_full (playsink->videodeinterlacechain->srcpad,
2361 playsink->videochain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2363 gst_pad_link_full (playsink->video_srcpad_stream_synchronizer,
2364 playsink->videochain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2367 GST_DEBUG_OBJECT (playsink, "no video needed");
2368 if (playsink->videochain) {
2369 GST_DEBUG_OBJECT (playsink, "removing video chain");
2370 if (playsink->vischain) {
2373 GST_DEBUG_OBJECT (playsink, "unlinking vis chain");
2375 /* also had visualisation, release the tee srcpad before we then
2376 * unlink the video from it */
2377 if (playsink->audio_tee_vissrc) {
2378 gst_element_release_request_pad (playsink->audio_tee,
2379 playsink->audio_tee_vissrc);
2380 gst_object_unref (playsink->audio_tee_vissrc);
2381 playsink->audio_tee_vissrc = NULL;
2384 gst_element_get_static_pad (playsink->vischain->chain.bin, "src");
2385 gst_pad_unlink (srcpad, playsink->videochain->sinkpad);
2388 if (playsink->video_sinkpad_stream_synchronizer) {
2389 gst_element_release_request_pad (GST_ELEMENT_CAST
2390 (playsink->stream_synchronizer),
2391 playsink->video_sinkpad_stream_synchronizer);
2392 gst_object_unref (playsink->video_sinkpad_stream_synchronizer);
2393 playsink->video_sinkpad_stream_synchronizer = NULL;
2394 gst_object_unref (playsink->video_srcpad_stream_synchronizer);
2395 playsink->video_srcpad_stream_synchronizer = NULL;
2398 add_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE);
2399 activate_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE);
2400 if (playsink->videochain->ts_offset)
2401 gst_object_unref (playsink->videochain->ts_offset);
2402 playsink->videochain->ts_offset = NULL;
2405 if (playsink->videodeinterlacechain) {
2406 add_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain), FALSE);
2407 activate_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain), FALSE);
2410 if (playsink->video_pad)
2411 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (playsink->video_pad), NULL);
2417 GST_DEBUG_OBJECT (playsink, "adding audio");
2419 /* get a raw sink if we are asked for a raw pad */
2420 raw = playsink->audio_pad_raw;
2422 if (playsink->audiochain) {
2423 /* try to reactivate the chain */
2424 if (!setup_audio_chain (playsink, raw)) {
2425 GST_DEBUG_OBJECT (playsink, "removing current audio chain");
2426 if (playsink->audio_tee_asrc) {
2427 gst_element_release_request_pad (playsink->audio_tee,
2428 playsink->audio_tee_asrc);
2429 gst_object_unref (playsink->audio_tee_asrc);
2430 playsink->audio_tee_asrc = NULL;
2433 if (playsink->audio_sinkpad_stream_synchronizer) {
2434 gst_element_release_request_pad (GST_ELEMENT_CAST
2435 (playsink->stream_synchronizer),
2436 playsink->audio_sinkpad_stream_synchronizer);
2437 gst_object_unref (playsink->audio_sinkpad_stream_synchronizer);
2438 playsink->audio_sinkpad_stream_synchronizer = NULL;
2439 gst_object_unref (playsink->audio_srcpad_stream_synchronizer);
2440 playsink->audio_srcpad_stream_synchronizer = NULL;
2443 add_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE);
2445 /* Remove the sink from the bin to keep its state
2446 * and unparent it to allow reuse */
2447 if (playsink->audiochain->sink)
2448 gst_bin_remove (GST_BIN_CAST (playsink->audiochain->chain.bin),
2449 playsink->audiochain->sink);
2451 activate_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE);
2452 disconnect_chain (playsink->audiochain, playsink);
2453 playsink->audiochain->volume = NULL;
2454 playsink->audiochain->mute = NULL;
2455 if (playsink->audiochain->ts_offset)
2456 gst_object_unref (playsink->audiochain->ts_offset);
2457 playsink->audiochain->ts_offset = NULL;
2458 free_chain ((GstPlayChain *) playsink->audiochain);
2459 playsink->audiochain = NULL;
2460 playsink->volume_changed = playsink->mute_changed = FALSE;
2464 if (!playsink->audiochain) {
2465 GST_DEBUG_OBJECT (playsink, "creating new audio chain");
2466 playsink->audiochain = gen_audio_chain (playsink, raw);
2469 if (!playsink->audio_sinkpad_stream_synchronizer) {
2472 playsink->audio_sinkpad_stream_synchronizer =
2473 gst_element_get_request_pad (GST_ELEMENT_CAST
2474 (playsink->stream_synchronizer), "sink_%d");
2475 it = gst_pad_iterate_internal_links
2476 (playsink->audio_sinkpad_stream_synchronizer);
2478 gst_iterator_next (it,
2479 (gpointer *) & playsink->audio_srcpad_stream_synchronizer);
2480 g_assert (playsink->audio_srcpad_stream_synchronizer);
2481 gst_iterator_free (it);
2484 if (playsink->audiochain) {
2485 GST_DEBUG_OBJECT (playsink, "adding audio chain");
2486 if (playsink->audio_tee_asrc == NULL) {
2487 playsink->audio_tee_asrc =
2488 gst_element_get_request_pad (playsink->audio_tee, "src%d");
2490 add_chain (GST_PLAY_CHAIN (playsink->audiochain), TRUE);
2491 activate_chain (GST_PLAY_CHAIN (playsink->audiochain), TRUE);
2492 gst_pad_link_full (playsink->audio_tee_asrc,
2493 playsink->audio_sinkpad_stream_synchronizer,
2494 GST_PAD_LINK_CHECK_NOTHING);
2495 gst_pad_link_full (playsink->audio_srcpad_stream_synchronizer,
2496 playsink->audiochain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2499 GST_DEBUG_OBJECT (playsink, "no audio needed");
2500 /* we have no audio or we are requested to not play audio */
2501 if (playsink->audiochain) {
2502 GST_DEBUG_OBJECT (playsink, "removing audio chain");
2503 /* release the audio pad */
2504 if (playsink->audio_tee_asrc) {
2505 gst_element_release_request_pad (playsink->audio_tee,
2506 playsink->audio_tee_asrc);
2507 gst_object_unref (playsink->audio_tee_asrc);
2508 playsink->audio_tee_asrc = NULL;
2511 if (playsink->audio_sinkpad_stream_synchronizer) {
2512 gst_element_release_request_pad (GST_ELEMENT_CAST
2513 (playsink->stream_synchronizer),
2514 playsink->audio_sinkpad_stream_synchronizer);
2515 gst_object_unref (playsink->audio_sinkpad_stream_synchronizer);
2516 playsink->audio_sinkpad_stream_synchronizer = NULL;
2517 gst_object_unref (playsink->audio_srcpad_stream_synchronizer);
2518 playsink->audio_srcpad_stream_synchronizer = NULL;
2521 if (playsink->audiochain->sink_volume) {
2522 disconnect_chain (playsink->audiochain, playsink);
2523 playsink->audiochain->volume = NULL;
2524 playsink->audiochain->mute = NULL;
2525 if (playsink->audiochain->ts_offset)
2526 gst_object_unref (playsink->audiochain->ts_offset);
2527 playsink->audiochain->ts_offset = NULL;
2529 add_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE);
2530 activate_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE);
2537 if (!playsink->vischain)
2538 playsink->vischain = gen_vis_chain (playsink);
2540 GST_DEBUG_OBJECT (playsink, "adding visualisation");
2542 if (playsink->vischain) {
2543 GST_DEBUG_OBJECT (playsink, "setting up vis chain");
2545 gst_element_get_static_pad (playsink->vischain->chain.bin, "src");
2546 add_chain (GST_PLAY_CHAIN (playsink->vischain), TRUE);
2547 activate_chain (GST_PLAY_CHAIN (playsink->vischain), TRUE);
2548 if (playsink->audio_tee_vissrc == NULL) {
2549 playsink->audio_tee_vissrc =
2550 gst_element_get_request_pad (playsink->audio_tee, "src%d");
2552 gst_pad_link_full (playsink->audio_tee_vissrc,
2553 playsink->vischain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2554 gst_pad_link_full (srcpad, playsink->video_sinkpad_stream_synchronizer,
2555 GST_PAD_LINK_CHECK_NOTHING);
2556 gst_pad_link_full (playsink->video_srcpad_stream_synchronizer,
2557 playsink->videochain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2558 gst_object_unref (srcpad);
2561 GST_DEBUG_OBJECT (playsink, "no vis needed");
2562 if (playsink->vischain) {
2563 if (playsink->audio_tee_vissrc) {
2564 gst_element_release_request_pad (playsink->audio_tee,
2565 playsink->audio_tee_vissrc);
2566 gst_object_unref (playsink->audio_tee_vissrc);
2567 playsink->audio_tee_vissrc = NULL;
2569 GST_DEBUG_OBJECT (playsink, "removing vis chain");
2570 add_chain (GST_PLAY_CHAIN (playsink->vischain), FALSE);
2571 activate_chain (GST_PLAY_CHAIN (playsink->vischain), FALSE);
2576 GST_DEBUG_OBJECT (playsink, "adding text");
2577 if (!playsink->textchain) {
2578 GST_DEBUG_OBJECT (playsink, "creating text chain");
2579 playsink->textchain = gen_text_chain (playsink);
2581 if (playsink->textchain) {
2584 GST_DEBUG_OBJECT (playsink, "adding text chain");
2585 if (playsink->textchain->overlay)
2586 g_object_set (G_OBJECT (playsink->textchain->overlay), "silent", FALSE,
2588 add_chain (GST_PLAY_CHAIN (playsink->textchain), TRUE);
2590 if (!playsink->text_sinkpad_stream_synchronizer) {
2591 playsink->text_sinkpad_stream_synchronizer =
2592 gst_element_get_request_pad (GST_ELEMENT_CAST
2593 (playsink->stream_synchronizer), "sink_%d");
2594 it = gst_pad_iterate_internal_links
2595 (playsink->text_sinkpad_stream_synchronizer);
2597 gst_iterator_next (it,
2598 (gpointer *) & playsink->text_srcpad_stream_synchronizer);
2599 g_assert (playsink->text_srcpad_stream_synchronizer);
2600 gst_iterator_free (it);
2602 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (playsink->text_pad),
2603 playsink->text_sinkpad_stream_synchronizer);
2604 gst_pad_link_full (playsink->text_srcpad_stream_synchronizer,
2605 playsink->textchain->textsinkpad, GST_PAD_LINK_CHECK_NOTHING);
2612 gst_element_get_static_pad (playsink->vischain->chain.bin, "src");
2613 gst_pad_unlink (srcpad, playsink->videochain->sinkpad);
2614 gst_pad_link_full (srcpad, playsink->textchain->videosinkpad,
2615 GST_PAD_LINK_CHECK_NOTHING);
2616 gst_object_unref (srcpad);
2618 if (need_deinterlace)
2619 gst_pad_link_full (playsink->videodeinterlacechain->srcpad,
2620 playsink->textchain->videosinkpad, GST_PAD_LINK_CHECK_NOTHING);
2622 gst_pad_link_full (playsink->video_srcpad_stream_synchronizer,
2623 playsink->textchain->videosinkpad, GST_PAD_LINK_CHECK_NOTHING);
2625 gst_pad_link_full (playsink->textchain->srcpad,
2626 playsink->videochain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2628 activate_chain (GST_PLAY_CHAIN (playsink->textchain), TRUE);
2631 GST_DEBUG_OBJECT (playsink, "no text needed");
2632 /* we have no subtitles/text or we are requested to not show them */
2634 if (playsink->text_sinkpad_stream_synchronizer) {
2635 gst_element_release_request_pad (GST_ELEMENT_CAST
2636 (playsink->stream_synchronizer),
2637 playsink->text_sinkpad_stream_synchronizer);
2638 gst_object_unref (playsink->text_sinkpad_stream_synchronizer);
2639 playsink->text_sinkpad_stream_synchronizer = NULL;
2640 gst_object_unref (playsink->text_srcpad_stream_synchronizer);
2641 playsink->text_srcpad_stream_synchronizer = NULL;
2644 if (playsink->textchain) {
2645 if (playsink->text_pad == NULL) {
2646 /* no text pad, remove the chain entirely */
2647 GST_DEBUG_OBJECT (playsink, "removing text chain");
2648 add_chain (GST_PLAY_CHAIN (playsink->textchain), FALSE);
2649 activate_chain (GST_PLAY_CHAIN (playsink->textchain), FALSE);
2651 /* we have a chain and a textpad, turn the subtitles off */
2652 GST_DEBUG_OBJECT (playsink, "turning off the text");
2653 if (playsink->textchain->overlay)
2654 g_object_set (G_OBJECT (playsink->textchain->overlay), "silent", TRUE,
2658 if (!need_video && playsink->video_pad) {
2659 if (playsink->video_sinkpad_stream_synchronizer) {
2660 gst_element_release_request_pad (GST_ELEMENT_CAST
2661 (playsink->stream_synchronizer),
2662 playsink->video_sinkpad_stream_synchronizer);
2663 gst_object_unref (playsink->video_sinkpad_stream_synchronizer);
2664 playsink->video_sinkpad_stream_synchronizer = NULL;
2665 gst_object_unref (playsink->video_srcpad_stream_synchronizer);
2666 playsink->video_srcpad_stream_synchronizer = NULL;
2669 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (playsink->video_pad), NULL);
2672 if (playsink->text_pad && !playsink->textchain)
2673 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (playsink->text_pad), NULL);
2675 update_av_offset (playsink);
2676 do_async_done (playsink);
2677 GST_PLAY_SINK_UNLOCK (playsink);
2684 /* gen_ chain already posted error */
2685 GST_DEBUG_OBJECT (playsink, "failed to setup chain");
2686 GST_PLAY_SINK_UNLOCK (playsink);
2692 * gst_play_sink_set_flags:
2693 * @playsink: a #GstPlaySink
2694 * @flags: #GstPlayFlags
2696 * Configure @flags on @playsink. The flags control the behaviour of @playsink
2697 * when constructing the sink pipelins.
2699 * Returns: TRUE if the flags could be configured.
2702 gst_play_sink_set_flags (GstPlaySink * playsink, GstPlayFlags flags)
2704 g_return_val_if_fail (GST_IS_PLAY_SINK (playsink), FALSE);
2706 GST_OBJECT_LOCK (playsink);
2707 playsink->flags = flags;
2708 GST_OBJECT_UNLOCK (playsink);
2714 * gst_play_sink_get_flags:
2715 * @playsink: a #GstPlaySink
2717 * Get the flags of @playsink. That flags control the behaviour of the sink when
2718 * it constructs the sink pipelines.
2720 * Returns: the currently configured #GstPlayFlags.
2723 gst_play_sink_get_flags (GstPlaySink * playsink)
2727 g_return_val_if_fail (GST_IS_PLAY_SINK (playsink), 0);
2729 GST_OBJECT_LOCK (playsink);
2730 res = playsink->flags;
2731 GST_OBJECT_UNLOCK (playsink);
2737 gst_play_sink_set_font_desc (GstPlaySink * playsink, const gchar * desc)
2739 GstPlayTextChain *chain;
2741 GST_PLAY_SINK_LOCK (playsink);
2742 chain = (GstPlayTextChain *) playsink->textchain;
2743 g_free (playsink->font_desc);
2744 playsink->font_desc = g_strdup (desc);
2745 if (chain && chain->overlay) {
2746 g_object_set (chain->overlay, "font-desc", desc, NULL);
2748 GST_PLAY_SINK_UNLOCK (playsink);
2752 gst_play_sink_get_font_desc (GstPlaySink * playsink)
2754 gchar *result = NULL;
2755 GstPlayTextChain *chain;
2757 GST_PLAY_SINK_LOCK (playsink);
2758 chain = (GstPlayTextChain *) playsink->textchain;
2759 if (chain && chain->overlay) {
2760 g_object_get (chain->overlay, "font-desc", &result, NULL);
2761 playsink->font_desc = g_strdup (result);
2763 result = g_strdup (playsink->font_desc);
2765 GST_PLAY_SINK_UNLOCK (playsink);
2771 gst_play_sink_set_subtitle_encoding (GstPlaySink * playsink,
2772 const gchar * encoding)
2774 GstPlayTextChain *chain;
2776 GST_PLAY_SINK_LOCK (playsink);
2777 chain = (GstPlayTextChain *) playsink->textchain;
2778 g_free (playsink->subtitle_encoding);
2779 playsink->subtitle_encoding = g_strdup (encoding);
2780 if (chain && chain->overlay) {
2781 g_object_set (chain->overlay, "subtitle-encoding", encoding, NULL);
2783 GST_PLAY_SINK_UNLOCK (playsink);
2787 gst_play_sink_get_subtitle_encoding (GstPlaySink * playsink)
2789 gchar *result = NULL;
2790 GstPlayTextChain *chain;
2792 GST_PLAY_SINK_LOCK (playsink);
2793 chain = (GstPlayTextChain *) playsink->textchain;
2794 if (chain && chain->overlay) {
2795 g_object_get (chain->overlay, "subtitle-encoding", &result, NULL);
2796 playsink->subtitle_encoding = g_strdup (result);
2798 result = g_strdup (playsink->subtitle_encoding);
2800 GST_PLAY_SINK_UNLOCK (playsink);
2806 update_av_offset (GstPlaySink * playsink)
2809 GstPlayAudioChain *achain;
2810 GstPlayVideoChain *vchain;
2812 av_offset = playsink->av_offset;
2813 achain = (GstPlayAudioChain *) playsink->audiochain;
2814 vchain = (GstPlayVideoChain *) playsink->videochain;
2816 if (achain && vchain && achain->ts_offset && vchain->ts_offset) {
2817 g_object_set (achain->ts_offset, "ts-offset", MAX (0, -av_offset), NULL);
2818 g_object_set (vchain->ts_offset, "ts-offset", MAX (0, av_offset), NULL);
2820 GST_LOG_OBJECT (playsink, "no ts_offset elements");
2825 gst_play_sink_set_av_offset (GstPlaySink * playsink, gint64 av_offset)
2827 GST_PLAY_SINK_LOCK (playsink);
2828 playsink->av_offset = av_offset;
2829 update_av_offset (playsink);
2830 GST_PLAY_SINK_UNLOCK (playsink);
2834 gst_play_sink_get_av_offset (GstPlaySink * playsink)
2838 GST_PLAY_SINK_LOCK (playsink);
2839 result = playsink->av_offset;
2840 GST_PLAY_SINK_UNLOCK (playsink);
2846 * gst_play_sink_get_last_frame:
2847 * @playsink: a #GstPlaySink
2849 * Get the last displayed frame from @playsink. This frame is in the native
2850 * format of the sink element, the caps on the result buffer contain the format
2851 * of the frame data.
2853 * Returns: a #GstBuffer with the frame data or %NULL when no video frame is
2857 gst_play_sink_get_last_frame (GstPlaySink * playsink)
2859 GstBuffer *result = NULL;
2860 GstPlayVideoChain *chain;
2862 GST_PLAY_SINK_LOCK (playsink);
2863 GST_DEBUG_OBJECT (playsink, "taking last frame");
2864 /* get the video chain if we can */
2865 if ((chain = (GstPlayVideoChain *) playsink->videochain)) {
2866 GST_DEBUG_OBJECT (playsink, "found video chain");
2867 /* see if the chain is active */
2868 if (chain->chain.activated && chain->sink) {
2871 GST_DEBUG_OBJECT (playsink, "video chain active and has a sink");
2873 /* find and get the last-buffer property now */
2875 gst_play_sink_find_property (playsink, chain->sink,
2876 "last-buffer", GST_TYPE_BUFFER))) {
2877 GST_DEBUG_OBJECT (playsink, "getting last-buffer property");
2878 g_object_get (elem, "last-buffer", &result, NULL);
2879 gst_object_unref (elem);
2883 GST_PLAY_SINK_UNLOCK (playsink);
2889 * gst_play_sink_convert_frame:
2890 * @playsink: a #GstPlaySink
2893 * Get the last displayed frame from @playsink. If caps is %NULL, the video will
2894 * be in the native format of the sink element and the caps on the buffer
2895 * describe the format of the frame. If @caps is not %NULL, the video
2896 * frame will be converted to the format of the caps.
2898 * Returns: a #GstBuffer with the frame data or %NULL when no video frame is
2899 * available or when the conversion failed.
2902 gst_play_sink_convert_frame (GstPlaySink * playsink, GstCaps * caps)
2906 result = gst_play_sink_get_last_frame (playsink);
2907 if (result != NULL && caps != NULL) {
2911 temp = gst_video_convert_frame (result, caps, 25 * GST_SECOND, &err);
2912 gst_buffer_unref (result);
2913 if (temp == NULL && err) {
2914 /* I'm really uncertain whether we should make playsink post an error
2915 * on the bus or not. It's not like it's a critical issue regarding
2916 * playsink behaviour. */
2917 GST_ERROR ("Error converting frame: %s", err->message);
2926 is_raw_structure (GstStructure * s)
2930 name = gst_structure_get_name (s);
2932 if (g_str_has_prefix (name, "video/x-raw-") ||
2933 g_str_has_prefix (name, "audio/x-raw-"))
2939 is_raw_pad (GstPad * pad)
2941 GstPad *peer = gst_pad_get_peer (pad);
2943 gboolean raw = TRUE;
2948 caps = gst_pad_get_negotiated_caps (peer);
2952 caps = gst_pad_get_caps_reffed (peer);
2954 n = gst_caps_get_size (caps);
2955 for (i = 0; i < n; i++) {
2956 gboolean r = is_raw_structure (gst_caps_get_structure (caps, i));
2960 } else if (raw != r) {
2961 GST_ERROR_OBJECT (pad,
2962 "Caps contains raw and non-raw structures: %" GST_PTR_FORMAT, caps);
2968 raw = is_raw_structure (gst_caps_get_structure (caps, 0));
2970 gst_caps_unref (caps);
2971 gst_object_unref (peer);
2977 sinkpad_blocked_cb (GstPad * blockedpad, gboolean blocked, gpointer user_data)
2979 GstPlaySink *playsink = (GstPlaySink *) user_data;
2982 GST_PLAY_SINK_LOCK (playsink);
2984 pad = GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD (blockedpad)));
2985 if (pad == playsink->video_pad) {
2986 playsink->video_pad_blocked = blocked;
2987 GST_DEBUG_OBJECT (pad, "Video pad blocked: %d", blocked);
2989 PENDING_FLAG_UNSET (playsink, GST_PLAY_SINK_TYPE_VIDEO_RAW);
2990 PENDING_FLAG_UNSET (playsink, GST_PLAY_SINK_TYPE_VIDEO);
2992 } else if (pad == playsink->audio_pad) {
2993 playsink->audio_pad_blocked = blocked;
2994 GST_DEBUG_OBJECT (pad, "Audio pad blocked: %d", blocked);
2996 PENDING_FLAG_UNSET (playsink, GST_PLAY_SINK_TYPE_AUDIO_RAW);
2997 PENDING_FLAG_UNSET (playsink, GST_PLAY_SINK_TYPE_AUDIO);
2999 } else if (pad == playsink->text_pad) {
3000 playsink->text_pad_blocked = blocked;
3001 GST_DEBUG_OBJECT (pad, "Text pad blocked: %d", blocked);
3003 PENDING_FLAG_UNSET (playsink, GST_PLAY_SINK_TYPE_TEXT);
3007 gst_object_unref (pad);
3008 GST_PLAY_SINK_UNLOCK (playsink);
3012 /* We reconfigure when for ALL streams:
3013 * * there isn't a pad
3014 * * OR the pad is blocked
3015 * * OR there are no pending blocks on that pad
3018 if ((!playsink->video_pad || playsink->video_pad_blocked
3019 || !PENDING_VIDEO_BLOCK (playsink)) && (!playsink->audio_pad
3020 || playsink->audio_pad_blocked || !PENDING_AUDIO_BLOCK (playsink))
3021 && (!playsink->text_pad || playsink->text_pad_blocked
3022 || !PENDING_TEXT_BLOCK (playsink))) {
3023 GST_DEBUG_OBJECT (playsink, "All pads blocked -- reconfiguring");
3025 if (playsink->video_pad) {
3026 playsink->video_pad_raw = is_raw_pad (playsink->video_pad);
3027 GST_DEBUG_OBJECT (playsink, "Video pad is raw: %d",
3028 playsink->video_pad_raw);
3031 if (playsink->audio_pad) {
3032 playsink->audio_pad_raw = is_raw_pad (playsink->audio_pad);
3033 GST_DEBUG_OBJECT (playsink, "Audio pad is raw: %d",
3034 playsink->audio_pad_raw);
3037 gst_play_sink_reconfigure (playsink);
3039 if (playsink->video_pad) {
3041 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3042 (playsink->video_pad)));
3043 gst_pad_set_blocked_async_full (opad, FALSE, sinkpad_blocked_cb,
3044 gst_object_ref (playsink), (GDestroyNotify) gst_object_unref);
3045 gst_object_unref (opad);
3048 if (playsink->audio_pad) {
3050 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3051 (playsink->audio_pad)));
3052 gst_pad_set_blocked_async_full (opad, FALSE, sinkpad_blocked_cb,
3053 gst_object_ref (playsink), (GDestroyNotify) gst_object_unref);
3054 gst_object_unref (opad);
3057 if (playsink->text_pad) {
3059 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3060 (playsink->text_pad)));
3061 gst_pad_set_blocked_async_full (opad, FALSE, sinkpad_blocked_cb,
3062 gst_object_ref (playsink), (GDestroyNotify) gst_object_unref);
3063 gst_object_unref (opad);
3067 gst_object_unref (pad);
3069 GST_PLAY_SINK_UNLOCK (playsink);
3073 caps_notify_cb (GstPad * pad, GParamSpec * unused, GstPlaySink * playsink)
3075 gboolean reconfigure = FALSE;
3079 g_object_get (pad, "caps", &caps, NULL);
3083 if (pad == playsink->audio_pad) {
3084 raw = is_raw_pad (pad);
3085 reconfigure = (! !playsink->audio_pad_raw != ! !raw)
3086 && playsink->audiochain;
3087 GST_DEBUG_OBJECT (pad,
3088 "Audio caps changed: raw %d reconfigure %d caps %" GST_PTR_FORMAT, raw,
3090 } else if (pad == playsink->video_pad) {
3091 raw = is_raw_pad (pad);
3092 reconfigure = (! !playsink->video_pad_raw != ! !raw)
3093 && playsink->videochain;
3094 GST_DEBUG_OBJECT (pad,
3095 "Video caps changed: raw %d reconfigure %d caps %" GST_PTR_FORMAT, raw,
3099 gst_caps_unref (caps);
3102 GST_PLAY_SINK_LOCK (playsink);
3103 if (playsink->video_pad) {
3105 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3106 (playsink->video_pad)));
3107 gst_pad_set_blocked_async_full (opad, TRUE, sinkpad_blocked_cb,
3108 gst_object_ref (playsink), (GDestroyNotify) gst_object_unref);
3109 gst_object_unref (opad);
3112 if (playsink->audio_pad) {
3114 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3115 (playsink->audio_pad)));
3116 gst_pad_set_blocked_async_full (opad, TRUE, sinkpad_blocked_cb,
3117 gst_object_ref (playsink), (GDestroyNotify) gst_object_unref);
3118 gst_object_unref (opad);
3121 if (playsink->text_pad) {
3123 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3124 (playsink->text_pad)));
3125 gst_pad_set_blocked_async_full (opad, TRUE, sinkpad_blocked_cb,
3126 gst_object_ref (playsink), (GDestroyNotify) gst_object_unref);
3127 gst_object_unref (opad);
3129 GST_PLAY_SINK_UNLOCK (playsink);
3134 * gst_play_sink_request_pad
3135 * @playsink: a #GstPlaySink
3136 * @type: a #GstPlaySinkType
3138 * Create or return a pad of @type.
3140 * Returns: a #GstPad of @type or %NULL when the pad could not be created.
3143 gst_play_sink_request_pad (GstPlaySink * playsink, GstPlaySinkType type)
3146 gboolean created = FALSE;
3147 gboolean activate = TRUE;
3148 const gchar *pad_name = NULL;
3150 GST_DEBUG_OBJECT (playsink, "request pad type %d", type);
3152 GST_PLAY_SINK_LOCK (playsink);
3154 case GST_PLAY_SINK_TYPE_AUDIO_RAW:
3155 case GST_PLAY_SINK_TYPE_AUDIO:
3156 pad_name = "audio_sink";
3157 if (!playsink->audio_tee) {
3158 GST_LOG_OBJECT (playsink, "creating tee");
3159 /* create tee when needed. This element will feed the audio sink chain
3160 * and the vis chain. */
3161 playsink->audio_tee = gst_element_factory_make ("tee", "audiotee");
3162 if (playsink->audio_tee == NULL) {
3163 post_missing_element_message (playsink, "tee");
3164 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
3165 (_("Missing element '%s' - check your GStreamer installation."),
3170 playsink->audio_tee_sink =
3171 gst_element_get_static_pad (playsink->audio_tee, "sink");
3172 gst_bin_add (GST_BIN_CAST (playsink), playsink->audio_tee);
3173 gst_element_set_state (playsink->audio_tee, GST_STATE_PAUSED);
3176 gst_element_set_state (playsink->audio_tee, GST_STATE_PAUSED);
3178 if (!playsink->audio_pad) {
3179 GST_LOG_OBJECT (playsink, "ghosting tee sinkpad");
3180 playsink->audio_pad =
3181 gst_ghost_pad_new (pad_name, playsink->audio_tee_sink);
3182 g_signal_connect (G_OBJECT (playsink->audio_pad), "notify::caps",
3183 G_CALLBACK (caps_notify_cb), playsink);
3186 playsink->audio_pad_raw = FALSE;
3187 res = playsink->audio_pad;
3189 case GST_PLAY_SINK_TYPE_VIDEO_RAW:
3190 case GST_PLAY_SINK_TYPE_VIDEO:
3191 pad_name = "video_sink";
3192 if (!playsink->video_pad) {
3193 GST_LOG_OBJECT (playsink, "ghosting videosink");
3194 playsink->video_pad =
3195 gst_ghost_pad_new_no_target (pad_name, GST_PAD_SINK);
3196 g_signal_connect (G_OBJECT (playsink->video_pad), "notify::caps",
3197 G_CALLBACK (caps_notify_cb), playsink);
3200 playsink->video_pad_raw = FALSE;
3201 res = playsink->video_pad;
3203 case GST_PLAY_SINK_TYPE_TEXT:
3204 GST_LOG_OBJECT (playsink, "ghosting text");
3205 if (!playsink->text_pad) {
3206 playsink->text_pad =
3207 gst_ghost_pad_new_no_target ("text_sink", GST_PAD_SINK);
3210 res = playsink->text_pad;
3212 case GST_PLAY_SINK_TYPE_FLUSHING:
3216 /* we need a unique padname for the flushing pad. */
3217 padname = g_strdup_printf ("flushing_%d", playsink->count);
3218 res = gst_ghost_pad_new_no_target (padname, GST_PAD_SINK);
3229 GST_PLAY_SINK_UNLOCK (playsink);
3231 if (created && res) {
3232 /* we have to add the pad when it's active or we get an error when the
3233 * element is 'running' */
3234 gst_pad_set_active (res, TRUE);
3235 gst_element_add_pad (GST_ELEMENT_CAST (playsink), res);
3236 if (type != GST_PLAY_SINK_TYPE_FLUSHING) {
3238 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD (res)));
3240 gst_pad_set_blocked_async_full (blockpad, TRUE, sinkpad_blocked_cb,
3241 gst_object_ref (playsink), (GDestroyNotify) gst_object_unref);
3242 PENDING_FLAG_SET (playsink, type);
3243 gst_object_unref (blockpad);
3246 gst_pad_set_active (res, activate);
3253 gst_play_sink_request_new_pad (GstElement * element, GstPadTemplate * templ,
3258 GstPlaySinkType type;
3259 const gchar *tplname;
3261 g_return_val_if_fail (templ != NULL, NULL);
3263 GST_DEBUG_OBJECT (element, "name:%s", name);
3265 psink = GST_PLAY_SINK (element);
3266 tplname = GST_PAD_TEMPLATE_NAME_TEMPLATE (templ);
3268 /* Figure out the GstPlaySinkType based on the template */
3269 if (!strcmp (tplname, "audio_sink"))
3270 type = GST_PLAY_SINK_TYPE_AUDIO;
3271 else if (!strcmp (tplname, "audio_raw_sink"))
3272 type = GST_PLAY_SINK_TYPE_AUDIO_RAW;
3273 else if (!strcmp (tplname, "video_sink"))
3274 type = GST_PLAY_SINK_TYPE_VIDEO;
3275 else if (!strcmp (tplname, "video_raw_sink"))
3276 type = GST_PLAY_SINK_TYPE_VIDEO_RAW;
3277 else if (!strcmp (tplname, "text_sink"))
3278 type = GST_PLAY_SINK_TYPE_TEXT;
3280 goto unknown_template;
3282 pad = gst_play_sink_request_pad (psink, type);
3286 GST_WARNING_OBJECT (element, "Unknown pad template");
3291 gst_play_sink_release_pad (GstPlaySink * playsink, GstPad * pad)
3293 GstPad **res = NULL;
3294 gboolean untarget = TRUE;
3296 GST_DEBUG_OBJECT (playsink, "release pad %" GST_PTR_FORMAT, pad);
3298 GST_PLAY_SINK_LOCK (playsink);
3299 if (pad == playsink->video_pad) {
3300 res = &playsink->video_pad;
3301 g_signal_handlers_disconnect_by_func (playsink->video_pad, caps_notify_cb,
3303 } else if (pad == playsink->audio_pad) {
3304 res = &playsink->audio_pad;
3305 g_signal_handlers_disconnect_by_func (playsink->audio_pad, caps_notify_cb,
3307 } else if (pad == playsink->text_pad) {
3308 res = &playsink->text_pad;
3310 /* try to release the given pad anyway, these could be the FLUSHING pads. */
3314 GST_PLAY_SINK_UNLOCK (playsink);
3317 GST_DEBUG_OBJECT (playsink, "deactivate pad %" GST_PTR_FORMAT, *res);
3318 gst_pad_set_active (*res, FALSE);
3320 GST_DEBUG_OBJECT (playsink, "untargeting pad %" GST_PTR_FORMAT, *res);
3321 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (*res), NULL);
3323 GST_DEBUG_OBJECT (playsink, "remove pad %" GST_PTR_FORMAT, *res);
3324 gst_element_remove_pad (GST_ELEMENT_CAST (playsink), *res);
3330 gst_play_sink_release_request_pad (GstElement * element, GstPad * pad)
3332 GstPlaySink *psink = GST_PLAY_SINK (element);
3334 gst_play_sink_release_pad (psink, pad);
3338 gst_play_sink_handle_message (GstBin * bin, GstMessage * message)
3340 GstPlaySink *playsink;
3342 playsink = GST_PLAY_SINK_CAST (bin);
3344 switch (GST_MESSAGE_TYPE (message)) {
3345 case GST_MESSAGE_STEP_DONE:
3350 gboolean flush, intermediate, eos;
3353 GST_INFO_OBJECT (playsink, "Handling step-done message");
3354 gst_message_parse_step_done (message, &format, &amount, &rate, &flush,
3355 &intermediate, &duration, &eos);
3357 if (format == GST_FORMAT_BUFFERS) {
3358 /* for the buffer format, we align the other streams */
3359 if (playsink->audiochain) {
3363 gst_event_new_step (GST_FORMAT_TIME, duration, rate, flush,
3366 if (!gst_element_send_event (playsink->audiochain->chain.bin, event)) {
3367 GST_DEBUG_OBJECT (playsink, "Event failed when sent to audio sink");
3371 GST_BIN_CLASS (gst_play_sink_parent_class)->handle_message (bin, message);
3375 GST_BIN_CLASS (gst_play_sink_parent_class)->handle_message (bin, message);
3380 /* Send an event to our sinks until one of them works; don't then send to the
3381 * remaining sinks (unlike GstBin)
3382 * Special case: If a text sink is set we need to send the event
3383 * to them in case it's source is different from the a/v stream's source.
3386 gst_play_sink_send_event_to_sink (GstPlaySink * playsink, GstEvent * event)
3388 gboolean res = TRUE;
3390 if (playsink->textchain && playsink->textchain->sink) {
3391 gst_event_ref (event);
3392 if ((res = gst_element_send_event (playsink->textchain->chain.bin, event))) {
3393 GST_DEBUG_OBJECT (playsink, "Sent event successfully to text sink");
3395 GST_DEBUG_OBJECT (playsink, "Event failed when sent to text sink");
3399 if (playsink->videochain) {
3400 gst_event_ref (event);
3401 if ((res = gst_element_send_event (playsink->videochain->chain.bin, event))) {
3402 GST_DEBUG_OBJECT (playsink, "Sent event successfully to video sink");
3405 GST_DEBUG_OBJECT (playsink, "Event failed when sent to video sink");
3407 if (playsink->audiochain) {
3408 gst_event_ref (event);
3409 if ((res = gst_element_send_event (playsink->audiochain->chain.bin, event))) {
3410 GST_DEBUG_OBJECT (playsink, "Sent event successfully to audio sink");
3413 GST_DEBUG_OBJECT (playsink, "Event failed when sent to audio sink");
3417 gst_event_unref (event);
3421 /* We only want to send the event to a single sink (overriding GstBin's
3422 * behaviour), but we want to keep GstPipeline's behaviour - wrapping seek
3423 * events appropriately. So, this is a messy duplication of code. */
3425 gst_play_sink_send_event (GstElement * element, GstEvent * event)
3427 gboolean res = FALSE;
3428 GstEventType event_type = GST_EVENT_TYPE (event);
3429 GstPlaySink *playsink;
3431 playsink = GST_PLAY_SINK_CAST (element);
3433 switch (event_type) {
3434 case GST_EVENT_SEEK:
3435 GST_DEBUG_OBJECT (element, "Sending event to a sink");
3436 res = gst_play_sink_send_event_to_sink (playsink, event);
3438 case GST_EVENT_STEP:
3443 gboolean flush, intermediate;
3445 gst_event_parse_step (event, &format, &amount, &rate, &flush,
3448 if (format == GST_FORMAT_BUFFERS) {
3449 /* for buffers, we will try to step video frames, for other formats we
3450 * send the step to all sinks */
3451 res = gst_play_sink_send_event_to_sink (playsink, event);
3454 GST_ELEMENT_CLASS (gst_play_sink_parent_class)->send_event (element,
3461 GST_ELEMENT_CLASS (gst_play_sink_parent_class)->send_event (element,
3468 static GstStateChangeReturn
3469 gst_play_sink_change_state (GstElement * element, GstStateChange transition)
3471 GstStateChangeReturn ret;
3472 GstStateChangeReturn bret;
3474 GstPlaySink *playsink;
3476 playsink = GST_PLAY_SINK (element);
3478 switch (transition) {
3479 case GST_STATE_CHANGE_READY_TO_PAUSED:
3480 playsink->need_async_start = TRUE;
3481 /* we want to go async to PAUSED until we managed to configure and add the
3483 do_async_start (playsink);
3484 ret = GST_STATE_CHANGE_ASYNC;
3486 case GST_STATE_CHANGE_PAUSED_TO_READY:
3487 /* unblock all pads here */
3488 GST_PLAY_SINK_LOCK (playsink);
3489 if (playsink->video_pad) {
3491 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3492 (playsink->video_pad)));
3493 if (gst_pad_is_blocked (opad)) {
3494 gst_pad_set_blocked_async_full (opad, FALSE, sinkpad_blocked_cb,
3495 gst_object_ref (playsink), (GDestroyNotify) gst_object_unref);
3497 gst_object_unref (opad);
3498 playsink->video_pad_blocked = FALSE;
3501 if (playsink->audio_pad) {
3503 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3504 (playsink->audio_pad)));
3506 if (gst_pad_is_blocked (opad)) {
3507 gst_pad_set_blocked_async_full (opad, FALSE, sinkpad_blocked_cb,
3508 gst_object_ref (playsink), (GDestroyNotify) gst_object_unref);
3510 gst_object_unref (opad);
3511 playsink->audio_pad_blocked = FALSE;
3514 if (playsink->text_pad) {
3516 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3517 (playsink->text_pad)));
3518 if (gst_pad_is_blocked (opad)) {
3519 gst_pad_set_blocked_async_full (opad, FALSE, sinkpad_blocked_cb,
3520 gst_object_ref (playsink), (GDestroyNotify) gst_object_unref);
3522 gst_object_unref (opad);
3523 playsink->text_pad_blocked = FALSE;
3525 GST_PLAY_SINK_UNLOCK (playsink);
3527 case GST_STATE_CHANGE_READY_TO_NULL:
3528 if (playsink->audiochain && playsink->audiochain->sink_volume) {
3529 /* remove our links to the mute and volume elements when they were
3530 * provided by a sink */
3531 disconnect_chain (playsink->audiochain, playsink);
3532 playsink->audiochain->volume = NULL;
3533 playsink->audiochain->mute = NULL;
3536 if (playsink->audiochain && playsink->audiochain->ts_offset) {
3537 gst_object_unref (playsink->audiochain->ts_offset);
3538 playsink->audiochain->ts_offset = NULL;
3541 if (playsink->videochain && playsink->videochain->ts_offset) {
3542 gst_object_unref (playsink->videochain->ts_offset);
3543 playsink->videochain->ts_offset = NULL;
3545 ret = GST_STATE_CHANGE_SUCCESS;
3548 /* all other state changes return SUCCESS by default, this value can be
3549 * overridden by the result of the children */
3550 ret = GST_STATE_CHANGE_SUCCESS;
3554 /* do the state change of the children */
3556 GST_ELEMENT_CLASS (gst_play_sink_parent_class)->change_state (element,
3558 /* now look at the result of our children and adjust the return value */
3560 case GST_STATE_CHANGE_FAILURE:
3561 /* failure, we stop */
3562 goto activate_failed;
3563 case GST_STATE_CHANGE_NO_PREROLL:
3564 /* some child returned NO_PREROLL. This is strange but we never know. We
3565 * commit our async state change (if any) and return the NO_PREROLL */
3566 do_async_done (playsink);
3569 case GST_STATE_CHANGE_ASYNC:
3570 /* some child was async, return this */
3574 /* return our previously configured return value */
3578 switch (transition) {
3579 case GST_STATE_CHANGE_READY_TO_PAUSED:
3581 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
3582 /* FIXME Release audio device when we implement that */
3583 playsink->need_async_start = TRUE;
3585 case GST_STATE_CHANGE_PAUSED_TO_READY:{
3586 if (playsink->video_sinkpad_stream_synchronizer) {
3587 gst_element_release_request_pad (GST_ELEMENT_CAST
3588 (playsink->stream_synchronizer),
3589 playsink->video_sinkpad_stream_synchronizer);
3590 gst_object_unref (playsink->video_sinkpad_stream_synchronizer);
3591 playsink->video_sinkpad_stream_synchronizer = NULL;
3592 gst_object_unref (playsink->video_srcpad_stream_synchronizer);
3593 playsink->video_srcpad_stream_synchronizer = NULL;
3595 if (playsink->audio_sinkpad_stream_synchronizer) {
3596 gst_element_release_request_pad (GST_ELEMENT_CAST
3597 (playsink->stream_synchronizer),
3598 playsink->audio_sinkpad_stream_synchronizer);
3599 gst_object_unref (playsink->audio_sinkpad_stream_synchronizer);
3600 playsink->audio_sinkpad_stream_synchronizer = NULL;
3601 gst_object_unref (playsink->audio_srcpad_stream_synchronizer);
3602 playsink->audio_srcpad_stream_synchronizer = NULL;
3604 if (playsink->text_sinkpad_stream_synchronizer) {
3605 gst_element_release_request_pad (GST_ELEMENT_CAST
3606 (playsink->stream_synchronizer),
3607 playsink->text_sinkpad_stream_synchronizer);
3608 gst_object_unref (playsink->text_sinkpad_stream_synchronizer);
3609 playsink->text_sinkpad_stream_synchronizer = NULL;
3610 gst_object_unref (playsink->text_srcpad_stream_synchronizer);
3611 playsink->text_srcpad_stream_synchronizer = NULL;
3615 case GST_STATE_CHANGE_READY_TO_NULL:
3616 /* remove sinks we added */
3617 if (playsink->videodeinterlacechain) {
3618 activate_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain),
3620 add_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain), FALSE);
3622 if (playsink->videochain) {
3623 activate_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE);
3624 add_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE);
3626 if (playsink->audiochain) {
3627 activate_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE);
3628 add_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE);
3630 if (playsink->vischain) {
3631 activate_chain (GST_PLAY_CHAIN (playsink->vischain), FALSE);
3632 add_chain (GST_PLAY_CHAIN (playsink->vischain), FALSE);
3634 if (playsink->textchain) {
3635 activate_chain (GST_PLAY_CHAIN (playsink->textchain), FALSE);
3636 add_chain (GST_PLAY_CHAIN (playsink->textchain), FALSE);
3638 do_async_done (playsink);
3639 /* when going to READY, keep elements around as long as possible,
3640 * so they may be re-used faster next time/url around.
3641 * when really going to NULL, clean up everything completely. */
3642 if (transition == GST_STATE_CHANGE_READY_TO_NULL) {
3644 /* Unparent the sinks to allow reuse */
3645 if (playsink->videochain && playsink->videochain->sink)
3646 gst_bin_remove (GST_BIN_CAST (playsink->videochain->chain.bin),
3647 playsink->videochain->sink);
3648 if (playsink->audiochain && playsink->audiochain->sink)
3649 gst_bin_remove (GST_BIN_CAST (playsink->audiochain->chain.bin),
3650 playsink->audiochain->sink);
3651 if (playsink->textchain && playsink->textchain->sink)
3652 gst_bin_remove (GST_BIN_CAST (playsink->textchain->chain.bin),
3653 playsink->textchain->sink);
3655 if (playsink->audio_sink != NULL)
3656 gst_element_set_state (playsink->audio_sink, GST_STATE_NULL);
3657 if (playsink->video_sink != NULL)
3658 gst_element_set_state (playsink->video_sink, GST_STATE_NULL);
3659 if (playsink->visualisation != NULL)
3660 gst_element_set_state (playsink->visualisation, GST_STATE_NULL);
3661 if (playsink->text_sink != NULL)
3662 gst_element_set_state (playsink->text_sink, GST_STATE_NULL);
3664 free_chain ((GstPlayChain *) playsink->videodeinterlacechain);
3665 playsink->videodeinterlacechain = NULL;
3666 free_chain ((GstPlayChain *) playsink->videochain);
3667 playsink->videochain = NULL;
3668 free_chain ((GstPlayChain *) playsink->audiochain);
3669 playsink->audiochain = NULL;
3670 free_chain ((GstPlayChain *) playsink->vischain);
3671 playsink->vischain = NULL;
3672 free_chain ((GstPlayChain *) playsink->textchain);
3673 playsink->textchain = NULL;
3684 GST_DEBUG_OBJECT (element,
3685 "element failed to change states -- activation problem?");
3686 return GST_STATE_CHANGE_FAILURE;
3691 gst_play_sink_set_property (GObject * object, guint prop_id,
3692 const GValue * value, GParamSpec * spec)
3694 GstPlaySink *playsink = GST_PLAY_SINK (object);
3698 gst_play_sink_set_flags (playsink, g_value_get_flags (value));
3701 gst_play_sink_set_volume (playsink, g_value_get_double (value));
3704 gst_play_sink_set_mute (playsink, g_value_get_boolean (value));
3706 case PROP_FONT_DESC:
3707 gst_play_sink_set_font_desc (playsink, g_value_get_string (value));
3709 case PROP_SUBTITLE_ENCODING:
3710 gst_play_sink_set_subtitle_encoding (playsink,
3711 g_value_get_string (value));
3713 case PROP_VIS_PLUGIN:
3714 gst_play_sink_set_vis_plugin (playsink, g_value_get_object (value));
3716 case PROP_AV_OFFSET:
3717 gst_play_sink_set_av_offset (playsink, g_value_get_int64 (value));
3719 case PROP_VIDEO_SINK:
3720 gst_play_sink_set_sink (playsink, GST_PLAY_SINK_TYPE_VIDEO,
3721 g_value_get_object (value));
3723 case PROP_AUDIO_SINK:
3724 gst_play_sink_set_sink (playsink, GST_PLAY_SINK_TYPE_AUDIO,
3725 g_value_get_object (value));
3727 case PROP_TEXT_SINK:
3728 gst_play_sink_set_sink (playsink, GST_PLAY_SINK_TYPE_TEXT,
3729 g_value_get_object (value));
3732 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec);
3738 gst_play_sink_get_property (GObject * object, guint prop_id,
3739 GValue * value, GParamSpec * spec)
3741 GstPlaySink *playsink = GST_PLAY_SINK (object);
3745 g_value_set_flags (value, gst_play_sink_get_flags (playsink));
3748 g_value_set_double (value, gst_play_sink_get_volume (playsink));
3751 g_value_set_boolean (value, gst_play_sink_get_mute (playsink));
3753 case PROP_FONT_DESC:
3754 g_value_take_string (value, gst_play_sink_get_font_desc (playsink));
3756 case PROP_SUBTITLE_ENCODING:
3757 g_value_take_string (value,
3758 gst_play_sink_get_subtitle_encoding (playsink));
3760 case PROP_VIS_PLUGIN:
3761 g_value_take_object (value, gst_play_sink_get_vis_plugin (playsink));
3764 gst_value_take_buffer (value, gst_play_sink_get_last_frame (playsink));
3766 case PROP_AV_OFFSET:
3767 g_value_set_int64 (value, gst_play_sink_get_av_offset (playsink));
3769 case PROP_VIDEO_SINK:
3770 g_value_take_object (value, gst_play_sink_get_sink (playsink,
3771 GST_PLAY_SINK_TYPE_VIDEO));
3773 case PROP_AUDIO_SINK:
3774 g_value_take_object (value, gst_play_sink_get_sink (playsink,
3775 GST_PLAY_SINK_TYPE_AUDIO));
3777 case PROP_TEXT_SINK:
3778 g_value_take_object (value, gst_play_sink_get_sink (playsink,
3779 GST_PLAY_SINK_TYPE_TEXT));
3782 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec);
3788 gst_play_sink_plugin_init (GstPlugin * plugin)
3790 GST_DEBUG_CATEGORY_INIT (gst_play_sink_debug, "playsink", 0, "play bin");
3792 return gst_element_register (plugin, "playsink", GST_RANK_NONE,
3793 GST_TYPE_PLAY_SINK);