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.
28 #include <gst/gst-i18n-plugin.h>
29 #include <gst/pbutils/pbutils.h>
30 #include <gst/video/video.h>
31 #include <gst/audio/streamvolume.h>
32 #include <gst/video/colorbalance.h>
33 #include <gst/video/videooverlay.h>
34 #include <gst/interfaces/navigation.h>
36 #include "gstplaysink.h"
37 #include "gststreamsynchronizer.h"
38 #include "gstplaysinkvideoconvert.h"
39 #include "gstplaysinkaudioconvert.h"
41 GST_DEBUG_CATEGORY_STATIC (gst_play_sink_debug);
42 #define GST_CAT_DEFAULT gst_play_sink_debug
44 #define VOLUME_MAX_DOUBLE 10.0
46 #define DEFAULT_FLAGS GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_TEXT | \
47 GST_PLAY_FLAG_SOFT_VOLUME | GST_PLAY_FLAG_SOFT_COLORBALANCE
49 #define GST_PLAY_CHAIN(c) ((GstPlayChain *)(c))
53 * GstPlaySinkSendEventMode:
54 * @MODE_DEFAULT: default GstBin's send_event handling
55 * @MODE_FIRST: send event only to the first sink that return true
57 * Send event handling to use
63 } GstPlaySinkSendEventMode;
66 #define GST_TYPE_PLAY_SINK_SEND_EVENT_MODE (gst_play_sink_send_event_mode_get_type ())
68 gst_play_sink_send_event_mode_get_type (void)
70 static GType gtype = 0;
73 static const GEnumValue values[] = {
74 {MODE_DEFAULT, "Default GstBin's send_event handling (default)",
76 {MODE_FIRST, "Sends the event to sinks until the first one handles it",
81 gtype = g_enum_register_static ("GstPlaySinkSendEventMode", values);
86 /* holds the common data fields for the audio and video pipelines. We keep them
87 * in a structure to more easily have all the info available. */
90 GstPlaySink *playsink;
103 GstElement *volume; /* element with the volume property */
104 gboolean sink_volume; /* if the volume was provided by the sink */
105 GstElement *mute; /* element with the mute property */
107 GstElement *ts_offset;
113 GstPad *sinkpad, *srcpad;
115 GstElement *deinterlace;
116 } GstPlayVideoDeinterlaceChain;
126 GstElement *ts_offset;
135 GstElement *resample;
136 GstPad *blockpad; /* srcpad of resample, used for switching the vis */
137 GstPad *vissinkpad; /* visualisation sinkpad, */
139 GstPad *vissrcpad; /* visualisation srcpad, */
140 GstPad *srcpad; /* outgoing srcpad, used to connect to the next
149 GstElement *identity;
151 GstPad *videosinkpad;
153 GstPad *srcpad; /* outgoing srcpad, used to connect to the next
155 GstElement *sink; /* custom sink to receive subtitle buffers */
158 #define GST_PLAY_SINK_GET_LOCK(playsink) (&((GstPlaySink *)playsink)->lock)
159 #define GST_PLAY_SINK_LOCK(playsink) G_STMT_START { \
160 GST_LOG_OBJECT (playsink, "locking from thread %p", g_thread_self ()); \
161 g_rec_mutex_lock (GST_PLAY_SINK_GET_LOCK (playsink)); \
162 GST_LOG_OBJECT (playsink, "locked from thread %p", g_thread_self ()); \
164 #define GST_PLAY_SINK_UNLOCK(playsink) G_STMT_START { \
165 GST_LOG_OBJECT (playsink, "unlocking from thread %p", g_thread_self ()); \
166 g_rec_mutex_unlock (GST_PLAY_SINK_GET_LOCK (playsink)); \
169 #define PENDING_FLAG_SET(playsink, flagtype) \
170 ((playsink->pending_blocked_pads) |= (1 << flagtype))
171 #define PENDING_FLAG_UNSET(playsink, flagtype) \
172 ((playsink->pending_blocked_pads) &= ~(1 << flagtype))
173 #define PENDING_FLAG_IS_SET(playsink, flagtype) \
174 ((playsink->pending_blocked_pads) & (1 << flagtype))
175 #define PENDING_VIDEO_BLOCK(playsink) \
176 ((playsink->pending_blocked_pads) & (1 << GST_PLAY_SINK_TYPE_VIDEO_RAW | 1 << GST_PLAY_SINK_TYPE_VIDEO))
177 #define PENDING_AUDIO_BLOCK(playsink) \
178 ((playsink->pending_blocked_pads) & (1 << GST_PLAY_SINK_TYPE_AUDIO_RAW | 1 << GST_PLAY_SINK_TYPE_AUDIO))
179 #define PENDING_TEXT_BLOCK(playsink) \
180 PENDING_FLAG_IS_SET(playsink, GST_PLAY_SINK_TYPE_TEXT)
188 gboolean async_pending;
189 gboolean need_async_start;
193 GstStreamSynchronizer *stream_synchronizer;
196 GstPlayAudioChain *audiochain;
197 GstPlayVideoDeinterlaceChain *videodeinterlacechain;
198 GstPlayVideoChain *videochain;
199 GstPlayVisChain *vischain;
200 GstPlayTextChain *textchain;
204 gboolean audio_pad_raw;
205 gboolean audio_pad_blocked;
206 GstPad *audio_srcpad_stream_synchronizer;
207 GstPad *audio_sinkpad_stream_synchronizer;
208 gulong audio_block_id;
210 GstElement *audio_tee;
211 GstPad *audio_tee_sink;
212 GstPad *audio_tee_asrc;
213 GstPad *audio_tee_vissrc;
216 gboolean video_pad_raw;
217 gboolean video_pad_blocked;
218 GstPad *video_srcpad_stream_synchronizer;
219 GstPad *video_sinkpad_stream_synchronizer;
220 gulong video_block_id;
223 gboolean text_pad_blocked;
224 GstPad *text_srcpad_stream_synchronizer;
225 GstPad *text_sinkpad_stream_synchronizer;
226 gulong text_block_id;
228 guint32 pending_blocked_pads;
231 GstElement *audio_sink;
232 GstElement *video_sink;
233 GstElement *visualisation;
234 GstElement *text_sink;
237 gchar *font_desc; /* font description */
238 gchar *subtitle_encoding; /* subtitle encoding */
239 guint connection_speed; /* connection speed in bits/sec (0 = unknown) */
241 gboolean volume_changed; /* volume/mute changed while no audiochain */
242 gboolean mute_changed; /* ... has been created yet */
244 GstPlaySinkSendEventMode send_event_mode;
246 /* videooverlay proxy interface */
247 GstVideoOverlay *overlay_element; /* protected with LOCK */
248 gboolean overlay_handle_set;
249 guintptr overlay_handle;
250 gboolean overlay_render_rectangle_set;
251 gint overlay_x, overlay_y, overlay_width, overlay_height;
252 gboolean overlay_handle_events_set;
253 gboolean overlay_handle_events;
255 /* colorbalance proxy interface */
256 GstColorBalance *colorbalance_element;
257 GList *colorbalance_channels; /* CONTRAST, BRIGHTNESS, HUE, SATURATION */
258 gint colorbalance_values[4];
261 struct _GstPlaySinkClass
263 GstBinClass parent_class;
265 gboolean (*reconfigure) (GstPlaySink * playsink);
267 GstSample *(*convert_sample) (GstPlaySink * playsink, GstCaps * caps);
271 static GstStaticPadTemplate audiotemplate =
272 GST_STATIC_PAD_TEMPLATE ("audio_sink",
275 GST_STATIC_CAPS_ANY);
276 static GstStaticPadTemplate videotemplate =
277 GST_STATIC_PAD_TEMPLATE ("video_sink",
280 GST_STATIC_CAPS_ANY);
281 static GstStaticPadTemplate texttemplate = GST_STATIC_PAD_TEMPLATE ("text_sink",
284 GST_STATIC_CAPS_ANY);
286 /* FIXME 0.11: Remove */
287 static GstStaticPadTemplate audiorawtemplate =
288 GST_STATIC_PAD_TEMPLATE ("audio_raw_sink",
291 GST_STATIC_CAPS_ANY);
292 static GstStaticPadTemplate videorawtemplate =
293 GST_STATIC_PAD_TEMPLATE ("video_raw_sink",
296 GST_STATIC_CAPS_ANY);
307 PROP_SUBTITLE_ENCODING,
314 PROP_SEND_EVENT_MODE,
324 static void gst_play_sink_dispose (GObject * object);
325 static void gst_play_sink_finalize (GObject * object);
326 static void gst_play_sink_set_property (GObject * object, guint prop_id,
327 const GValue * value, GParamSpec * spec);
328 static void gst_play_sink_get_property (GObject * object, guint prop_id,
329 GValue * value, GParamSpec * spec);
331 static GstPad *gst_play_sink_request_new_pad (GstElement * element,
332 GstPadTemplate * templ, const gchar * name, const GstCaps * caps);
333 static void gst_play_sink_release_request_pad (GstElement * element,
335 static gboolean gst_play_sink_send_event (GstElement * element,
337 static GstStateChangeReturn gst_play_sink_change_state (GstElement * element,
338 GstStateChange transition);
340 static void gst_play_sink_handle_message (GstBin * bin, GstMessage * message);
342 static void notify_volume_cb (GObject * object, GParamSpec * pspec,
343 GstPlaySink * playsink);
344 static void notify_mute_cb (GObject * object, GParamSpec * pspec,
345 GstPlaySink * playsink);
347 static void update_av_offset (GstPlaySink * playsink);
349 /* static guint gst_play_sink_signals[LAST_SIGNAL] = { 0 }; */
351 static void gst_play_sink_overlay_init (gpointer g_iface,
352 gpointer g_iface_data);
353 static void gst_play_sink_navigation_init (gpointer g_iface,
354 gpointer g_iface_data);
355 static void gst_play_sink_colorbalance_init (gpointer g_iface,
356 gpointer g_iface_data);
359 _do_init (GType type)
361 static const GInterfaceInfo svol_info = {
364 static const GInterfaceInfo ov_info = {
365 gst_play_sink_overlay_init,
368 static const GInterfaceInfo nav_info = {
369 gst_play_sink_navigation_init,
372 static const GInterfaceInfo col_info = {
373 gst_play_sink_colorbalance_init,
377 g_type_add_interface_static (type, GST_TYPE_STREAM_VOLUME, &svol_info);
378 g_type_add_interface_static (type, GST_TYPE_VIDEO_OVERLAY, &ov_info);
379 g_type_add_interface_static (type, GST_TYPE_NAVIGATION, &nav_info);
380 g_type_add_interface_static (type, GST_TYPE_COLOR_BALANCE, &col_info);
383 G_DEFINE_TYPE_WITH_CODE (GstPlaySink, gst_play_sink, GST_TYPE_BIN,
384 _do_init (g_define_type_id));
387 gst_play_sink_class_init (GstPlaySinkClass * klass)
389 GObjectClass *gobject_klass;
390 GstElementClass *gstelement_klass;
391 GstBinClass *gstbin_klass;
393 gobject_klass = (GObjectClass *) klass;
394 gstelement_klass = (GstElementClass *) klass;
395 gstbin_klass = (GstBinClass *) klass;
397 gobject_klass->dispose = gst_play_sink_dispose;
398 gobject_klass->finalize = gst_play_sink_finalize;
399 gobject_klass->set_property = gst_play_sink_set_property;
400 gobject_klass->get_property = gst_play_sink_get_property;
406 * Control the behaviour of playsink.
408 g_object_class_install_property (gobject_klass, PROP_FLAGS,
409 g_param_spec_flags ("flags", "Flags", "Flags to control behaviour",
410 GST_TYPE_PLAY_FLAGS, DEFAULT_FLAGS,
411 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
414 * GstPlaySink:volume:
416 * Get or set the current audio stream volume. 1.0 means 100%,
417 * 0.0 means mute. This uses a linear volume scale.
420 g_object_class_install_property (gobject_klass, PROP_VOLUME,
421 g_param_spec_double ("volume", "Volume", "The audio volume, 1.0=100%",
422 0.0, VOLUME_MAX_DOUBLE, 1.0,
423 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
424 g_object_class_install_property (gobject_klass, PROP_MUTE,
425 g_param_spec_boolean ("mute", "Mute",
426 "Mute the audio channel without changing the volume", FALSE,
427 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
428 g_object_class_install_property (gobject_klass, PROP_FONT_DESC,
429 g_param_spec_string ("subtitle-font-desc",
430 "Subtitle font description",
431 "Pango font description of font "
432 "to be used for subtitle rendering", NULL,
433 G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
434 g_object_class_install_property (gobject_klass, PROP_SUBTITLE_ENCODING,
435 g_param_spec_string ("subtitle-encoding", "subtitle encoding",
436 "Encoding to assume if input subtitles are not in UTF-8 encoding. "
437 "If not set, the GST_SUBTITLE_ENCODING environment variable will "
438 "be checked for an encoding to use. If that is not set either, "
439 "ISO-8859-15 will be assumed.", NULL,
440 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
441 g_object_class_install_property (gobject_klass, PROP_VIS_PLUGIN,
442 g_param_spec_object ("vis-plugin", "Vis plugin",
443 "the visualization element to use (NULL = default)",
444 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
446 * GstPlaySink:sample:
448 * Get the currently rendered or prerolled sample in the video sink.
449 * The #GstCaps in the sample will describe the format of the buffer.
451 g_object_class_install_property (gobject_klass, PROP_SAMPLE,
452 g_param_spec_boxed ("sample", "Sample",
453 "The last sample (NULL = no video available)",
454 GST_TYPE_SAMPLE, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
456 * GstPlaySink:av-offset:
458 * Control the synchronisation offset between the audio and video streams.
459 * Positive values make the audio ahead of the video and negative values make
460 * the audio go behind the video.
464 g_object_class_install_property (gobject_klass, PROP_AV_OFFSET,
465 g_param_spec_int64 ("av-offset", "AV Offset",
466 "The synchronisation offset between audio and video in nanoseconds",
467 G_MININT64, G_MAXINT64, 0,
468 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
471 * GstPlaySink:video-sink:
473 * Set the used video sink element. NULL will use the default sink. playsink
474 * must be in %GST_STATE_NULL
478 g_object_class_install_property (gobject_klass, PROP_VIDEO_SINK,
479 g_param_spec_object ("video-sink", "Video Sink",
480 "the video output element to use (NULL = default sink)",
481 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
483 * GstPlaySink:audio-sink:
485 * Set the used audio sink element. NULL will use the default sink. playsink
486 * must be in %GST_STATE_NULL
490 g_object_class_install_property (gobject_klass, PROP_AUDIO_SINK,
491 g_param_spec_object ("audio-sink", "Audio Sink",
492 "the audio output element to use (NULL = default sink)",
493 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
496 * GstPlaySink:text-sink:
498 * Set the used text sink element. NULL will use the default sink. playsink
499 * must be in %GST_STATE_NULL
503 g_object_class_install_property (gobject_klass, PROP_TEXT_SINK,
504 g_param_spec_object ("text-sink", "Text sink",
505 "the text output element to use (NULL = default textoverlay)",
506 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
509 * GstPlaySink::send-event-mode:
511 * Sets the handling method used for events received from send_event
512 * function. The default is %MODE_DEFAULT, that uses %GstBin's default
513 * handling (push the event to all internal sinks).
517 g_object_class_install_property (gobject_klass, PROP_SEND_EVENT_MODE,
518 g_param_spec_enum ("send-event-mode", "Send event mode",
519 "How to send events received in send_event function",
520 GST_TYPE_PLAY_SINK_SEND_EVENT_MODE, MODE_DEFAULT,
521 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
523 g_signal_new ("reconfigure", G_TYPE_FROM_CLASS (klass),
524 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstPlaySinkClass,
525 reconfigure), NULL, NULL, g_cclosure_marshal_generic, G_TYPE_BOOLEAN,
528 * GstPlaySink::convert-sample
529 * @playsink: a #GstPlaySink
530 * @caps: the target format of the sample
532 * Action signal to retrieve the currently playing video sample in the format
533 * specified by @caps.
534 * If @caps is %NULL, no conversion will be performed and this function is
535 * equivalent to the #GstPlaySink::sample property.
537 * Returns: a #GstSample of the current video sample converted to #caps.
538 * The caps in the sample will describe the final layout of the buffer data.
539 * %NULL is returned when no current sample can be retrieved or when the
542 g_signal_new ("convert-sample", G_TYPE_FROM_CLASS (klass),
543 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
544 G_STRUCT_OFFSET (GstPlaySinkClass, convert_sample), NULL, NULL,
545 g_cclosure_marshal_generic, GST_TYPE_SAMPLE, 1, GST_TYPE_CAPS);
547 gst_element_class_add_pad_template (gstelement_klass,
548 gst_static_pad_template_get (&audiorawtemplate));
549 gst_element_class_add_pad_template (gstelement_klass,
550 gst_static_pad_template_get (&audiotemplate));
551 gst_element_class_add_pad_template (gstelement_klass,
552 gst_static_pad_template_get (&videorawtemplate));
553 gst_element_class_add_pad_template (gstelement_klass,
554 gst_static_pad_template_get (&videotemplate));
555 gst_element_class_add_pad_template (gstelement_klass,
556 gst_static_pad_template_get (&texttemplate));
557 gst_element_class_set_static_metadata (gstelement_klass, "Player Sink",
559 "Convenience sink for multiple streams",
560 "Wim Taymans <wim.taymans@gmail.com>");
562 gstelement_klass->change_state =
563 GST_DEBUG_FUNCPTR (gst_play_sink_change_state);
564 gstelement_klass->send_event = GST_DEBUG_FUNCPTR (gst_play_sink_send_event);
565 gstelement_klass->request_new_pad =
566 GST_DEBUG_FUNCPTR (gst_play_sink_request_new_pad);
567 gstelement_klass->release_pad =
568 GST_DEBUG_FUNCPTR (gst_play_sink_release_request_pad);
570 gstbin_klass->handle_message =
571 GST_DEBUG_FUNCPTR (gst_play_sink_handle_message);
573 klass->reconfigure = GST_DEBUG_FUNCPTR (gst_play_sink_reconfigure);
574 klass->convert_sample = GST_DEBUG_FUNCPTR (gst_play_sink_convert_sample);
578 gst_play_sink_init (GstPlaySink * playsink)
580 GstColorBalanceChannel *channel;
583 playsink->video_sink = NULL;
584 playsink->audio_sink = NULL;
585 playsink->visualisation = NULL;
586 playsink->text_sink = NULL;
587 playsink->volume = 1.0;
588 playsink->font_desc = NULL;
589 playsink->subtitle_encoding = NULL;
590 playsink->flags = DEFAULT_FLAGS;
591 playsink->send_event_mode = MODE_DEFAULT;
593 playsink->stream_synchronizer =
594 g_object_new (GST_TYPE_STREAM_SYNCHRONIZER, NULL);
595 gst_bin_add (GST_BIN_CAST (playsink),
596 GST_ELEMENT_CAST (playsink->stream_synchronizer));
598 g_rec_mutex_init (&playsink->lock);
599 GST_OBJECT_FLAG_SET (playsink, GST_ELEMENT_FLAG_SINK);
602 GST_COLOR_BALANCE_CHANNEL (g_object_new (GST_TYPE_COLOR_BALANCE_CHANNEL,
604 channel->label = g_strdup ("CONTRAST");
605 channel->min_value = -1000;
606 channel->max_value = 1000;
607 playsink->colorbalance_channels =
608 g_list_append (playsink->colorbalance_channels, channel);
609 playsink->colorbalance_values[0] = 0;
612 GST_COLOR_BALANCE_CHANNEL (g_object_new (GST_TYPE_COLOR_BALANCE_CHANNEL,
614 channel->label = g_strdup ("BRIGHTNESS");
615 channel->min_value = -1000;
616 channel->max_value = 1000;
617 playsink->colorbalance_channels =
618 g_list_append (playsink->colorbalance_channels, channel);
619 playsink->colorbalance_values[1] = 0;
622 GST_COLOR_BALANCE_CHANNEL (g_object_new (GST_TYPE_COLOR_BALANCE_CHANNEL,
624 channel->label = g_strdup ("HUE");
625 channel->min_value = -1000;
626 channel->max_value = 1000;
627 playsink->colorbalance_channels =
628 g_list_append (playsink->colorbalance_channels, channel);
629 playsink->colorbalance_values[2] = 0;
632 GST_COLOR_BALANCE_CHANNEL (g_object_new (GST_TYPE_COLOR_BALANCE_CHANNEL,
634 channel->label = g_strdup ("SATURATION");
635 channel->min_value = -1000;
636 channel->max_value = 1000;
637 playsink->colorbalance_channels =
638 g_list_append (playsink->colorbalance_channels, channel);
639 playsink->colorbalance_values[3] = 0;
643 disconnect_chain (GstPlayAudioChain * chain, GstPlaySink * playsink)
647 g_signal_handlers_disconnect_by_func (chain->volume, notify_volume_cb,
650 g_signal_handlers_disconnect_by_func (chain->mute, notify_mute_cb,
656 free_chain (GstPlayChain * chain)
660 gst_object_unref (chain->bin);
666 gst_play_sink_dispose (GObject * object)
668 GstPlaySink *playsink;
670 playsink = GST_PLAY_SINK (object);
672 if (playsink->audio_sink != NULL) {
673 gst_element_set_state (playsink->audio_sink, GST_STATE_NULL);
674 gst_object_unref (playsink->audio_sink);
675 playsink->audio_sink = NULL;
677 if (playsink->video_sink != NULL) {
678 gst_element_set_state (playsink->video_sink, GST_STATE_NULL);
679 gst_object_unref (playsink->video_sink);
680 playsink->video_sink = NULL;
682 if (playsink->visualisation != NULL) {
683 gst_element_set_state (playsink->visualisation, GST_STATE_NULL);
684 gst_object_unref (playsink->visualisation);
685 playsink->visualisation = NULL;
687 if (playsink->text_sink != NULL) {
688 gst_element_set_state (playsink->text_sink, GST_STATE_NULL);
689 gst_object_unref (playsink->text_sink);
690 playsink->text_sink = NULL;
693 free_chain ((GstPlayChain *) playsink->videodeinterlacechain);
694 playsink->videodeinterlacechain = NULL;
695 free_chain ((GstPlayChain *) playsink->videochain);
696 playsink->videochain = NULL;
697 free_chain ((GstPlayChain *) playsink->audiochain);
698 playsink->audiochain = NULL;
699 free_chain ((GstPlayChain *) playsink->vischain);
700 playsink->vischain = NULL;
701 free_chain ((GstPlayChain *) playsink->textchain);
702 playsink->textchain = NULL;
704 if (playsink->audio_tee_sink) {
705 gst_object_unref (playsink->audio_tee_sink);
706 playsink->audio_tee_sink = NULL;
709 if (playsink->audio_tee_vissrc) {
710 gst_element_release_request_pad (playsink->audio_tee,
711 playsink->audio_tee_vissrc);
712 gst_object_unref (playsink->audio_tee_vissrc);
713 playsink->audio_tee_vissrc = NULL;
716 if (playsink->audio_tee_asrc) {
717 gst_element_release_request_pad (playsink->audio_tee,
718 playsink->audio_tee_asrc);
719 gst_object_unref (playsink->audio_tee_asrc);
720 playsink->audio_tee_asrc = NULL;
723 g_free (playsink->font_desc);
724 playsink->font_desc = NULL;
726 g_free (playsink->subtitle_encoding);
727 playsink->subtitle_encoding = NULL;
729 playsink->stream_synchronizer = NULL;
731 g_list_foreach (playsink->colorbalance_channels, (GFunc) gst_object_unref,
733 g_list_free (playsink->colorbalance_channels);
734 playsink->colorbalance_channels = NULL;
736 G_OBJECT_CLASS (gst_play_sink_parent_class)->dispose (object);
740 gst_play_sink_finalize (GObject * object)
742 GstPlaySink *playsink;
744 playsink = GST_PLAY_SINK (object);
746 g_rec_mutex_clear (&playsink->lock);
748 G_OBJECT_CLASS (gst_play_sink_parent_class)->finalize (object);
752 gst_play_sink_set_sink (GstPlaySink * playsink, GstPlaySinkType type,
755 GstElement **elem = NULL, *old = NULL;
757 GST_LOG ("Setting sink %" GST_PTR_FORMAT " as sink type %d", sink, type);
759 GST_PLAY_SINK_LOCK (playsink);
761 case GST_PLAY_SINK_TYPE_AUDIO:
762 case GST_PLAY_SINK_TYPE_AUDIO_RAW:
763 elem = &playsink->audio_sink;
765 case GST_PLAY_SINK_TYPE_VIDEO:
766 case GST_PLAY_SINK_TYPE_VIDEO_RAW:
767 elem = &playsink->video_sink;
769 case GST_PLAY_SINK_TYPE_TEXT:
770 elem = &playsink->text_sink;
778 gst_object_ref (sink);
781 GST_PLAY_SINK_UNLOCK (playsink);
785 gst_element_set_state (old, GST_STATE_NULL);
786 gst_object_unref (old);
791 gst_play_sink_get_sink (GstPlaySink * playsink, GstPlaySinkType type)
793 GstElement *result = NULL;
794 GstElement *elem = NULL, *chainp = NULL;
796 GST_PLAY_SINK_LOCK (playsink);
798 case GST_PLAY_SINK_TYPE_AUDIO:
799 case GST_PLAY_SINK_TYPE_AUDIO_RAW:
801 GstPlayAudioChain *chain;
802 if ((chain = (GstPlayAudioChain *) playsink->audiochain))
803 chainp = chain->sink;
804 elem = playsink->audio_sink;
807 case GST_PLAY_SINK_TYPE_VIDEO:
808 case GST_PLAY_SINK_TYPE_VIDEO_RAW:
810 GstPlayVideoChain *chain;
811 if ((chain = (GstPlayVideoChain *) playsink->videochain))
812 chainp = chain->sink;
813 elem = playsink->video_sink;
816 case GST_PLAY_SINK_TYPE_TEXT:
818 GstPlayTextChain *chain;
819 if ((chain = (GstPlayTextChain *) playsink->textchain))
820 chainp = chain->sink;
821 elem = playsink->text_sink;
828 /* we have an active chain with a sink, get the sink */
829 result = gst_object_ref (chainp);
831 /* nothing found, return last configured sink */
832 if (result == NULL && elem)
833 result = gst_object_ref (elem);
834 GST_PLAY_SINK_UNLOCK (playsink);
839 static GstPadProbeReturn
840 gst_play_sink_vis_blocked (GstPad * tee_pad, GstPadProbeInfo * info,
843 GstPlaySink *playsink;
844 GstPlayVisChain *chain;
846 playsink = GST_PLAY_SINK (user_data);
848 GST_PLAY_SINK_LOCK (playsink);
849 GST_DEBUG_OBJECT (playsink, "vis pad blocked");
850 /* now try to change the plugin in the running vis chain */
851 if (!(chain = (GstPlayVisChain *) playsink->vischain))
854 /* unlink the old plugin and unghost the pad */
855 gst_pad_unlink (chain->blockpad, chain->vissinkpad);
856 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (chain->srcpad), NULL);
858 /* set the old plugin to NULL and remove */
859 gst_element_set_state (chain->vis, GST_STATE_NULL);
860 gst_bin_remove (GST_BIN_CAST (chain->chain.bin), chain->vis);
862 /* add new plugin and set state to playing */
863 chain->vis = playsink->visualisation;
864 gst_bin_add (GST_BIN_CAST (chain->chain.bin), chain->vis);
865 gst_element_set_state (chain->vis, GST_STATE_PLAYING);
868 chain->vissinkpad = gst_element_get_static_pad (chain->vis, "sink");
869 chain->vissrcpad = gst_element_get_static_pad (chain->vis, "src");
872 gst_pad_link_full (chain->blockpad, chain->vissinkpad,
873 GST_PAD_LINK_CHECK_NOTHING);
874 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (chain->srcpad),
878 GST_PLAY_SINK_UNLOCK (playsink);
880 /* remove the probe and unblock the pad */
881 return GST_PAD_PROBE_REMOVE;
885 gst_play_sink_set_vis_plugin (GstPlaySink * playsink, GstElement * vis)
887 GstPlayVisChain *chain;
889 /* setting NULL means creating the default vis plugin */
891 vis = gst_element_factory_make ("goom", "vis");
893 /* simply return if we don't have a vis plugin here */
897 GST_PLAY_SINK_LOCK (playsink);
898 /* first store the new vis */
899 if (playsink->visualisation)
900 gst_object_unref (playsink->visualisation);
902 gst_object_ref_sink (vis);
903 playsink->visualisation = vis;
905 /* now try to change the plugin in the running vis chain, if we have no chain,
906 * we don't bother, any future vis chain will be created with the new vis
908 if (!(chain = (GstPlayVisChain *) playsink->vischain))
911 /* block the pad, the next time the callback is called we can change the
912 * visualisation. It's possible that this never happens or that the pad was
913 * already blocked. If the callback never happens, we don't have new data so
914 * we don't need the new vis plugin. If the pad was already blocked, the
915 * function returns FALSE but the previous pad block will do the right thing
917 GST_DEBUG_OBJECT (playsink, "blocking vis pad");
918 gst_pad_add_probe (chain->blockpad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
919 gst_play_sink_vis_blocked, playsink, NULL);
921 GST_PLAY_SINK_UNLOCK (playsink);
927 gst_play_sink_get_vis_plugin (GstPlaySink * playsink)
929 GstElement *result = NULL;
930 GstPlayVisChain *chain;
932 GST_PLAY_SINK_LOCK (playsink);
933 if ((chain = (GstPlayVisChain *) playsink->vischain)) {
934 /* we have an active chain, get the sink */
936 result = gst_object_ref (chain->vis);
938 /* nothing found, return last configured sink */
939 if (result == NULL && playsink->visualisation)
940 result = gst_object_ref (playsink->visualisation);
941 GST_PLAY_SINK_UNLOCK (playsink);
947 gst_play_sink_set_volume (GstPlaySink * playsink, gdouble volume)
949 GstPlayAudioChain *chain;
951 GST_PLAY_SINK_LOCK (playsink);
952 playsink->volume = volume;
953 chain = (GstPlayAudioChain *) playsink->audiochain;
954 if (chain && chain->volume) {
955 GST_LOG_OBJECT (playsink, "elements: volume=%" GST_PTR_FORMAT ", mute=%"
956 GST_PTR_FORMAT "; new volume=%.03f, mute=%d", chain->volume,
957 chain->mute, volume, playsink->mute);
958 /* if there is a mute element or we are not muted, set the volume */
959 if (chain->mute || !playsink->mute)
960 g_object_set (chain->volume, "volume", volume, NULL);
962 GST_LOG_OBJECT (playsink, "no volume element");
963 playsink->volume_changed = TRUE;
965 GST_PLAY_SINK_UNLOCK (playsink);
969 gst_play_sink_get_volume (GstPlaySink * playsink)
972 GstPlayAudioChain *chain;
974 GST_PLAY_SINK_LOCK (playsink);
975 chain = (GstPlayAudioChain *) playsink->audiochain;
976 result = playsink->volume;
977 if (chain && chain->volume) {
978 if (chain->mute || !playsink->mute) {
979 g_object_get (chain->volume, "volume", &result, NULL);
980 playsink->volume = result;
983 GST_PLAY_SINK_UNLOCK (playsink);
989 gst_play_sink_set_mute (GstPlaySink * playsink, gboolean mute)
991 GstPlayAudioChain *chain;
993 GST_PLAY_SINK_LOCK (playsink);
994 playsink->mute = mute;
995 chain = (GstPlayAudioChain *) playsink->audiochain;
998 g_object_set (chain->mute, "mute", mute, NULL);
999 } else if (chain->volume) {
1001 g_object_set (chain->volume, "volume", (gdouble) 0.0, NULL);
1003 g_object_set (chain->volume, "volume", (gdouble) playsink->volume,
1007 playsink->mute_changed = TRUE;
1009 GST_PLAY_SINK_UNLOCK (playsink);
1013 gst_play_sink_get_mute (GstPlaySink * playsink)
1016 GstPlayAudioChain *chain;
1018 GST_PLAY_SINK_LOCK (playsink);
1019 chain = (GstPlayAudioChain *) playsink->audiochain;
1020 if (chain && chain->mute) {
1021 g_object_get (chain->mute, "mute", &result, NULL);
1022 playsink->mute = result;
1024 result = playsink->mute;
1026 GST_PLAY_SINK_UNLOCK (playsink);
1032 post_missing_element_message (GstPlaySink * playsink, const gchar * name)
1036 msg = gst_missing_element_message_new (GST_ELEMENT_CAST (playsink), name);
1037 gst_element_post_message (GST_ELEMENT_CAST (playsink), msg);
1041 add_chain (GstPlayChain * chain, gboolean add)
1043 if (chain->added == add)
1047 gst_bin_add (GST_BIN_CAST (chain->playsink), chain->bin);
1049 gst_bin_remove (GST_BIN_CAST (chain->playsink), chain->bin);
1050 /* we don't want to lose our sink status */
1051 GST_OBJECT_FLAG_SET (chain->playsink, GST_ELEMENT_FLAG_SINK);
1060 activate_chain (GstPlayChain * chain, gboolean activate)
1064 if (chain->activated == activate)
1067 GST_OBJECT_LOCK (chain->playsink);
1068 state = GST_STATE_TARGET (chain->playsink);
1069 GST_OBJECT_UNLOCK (chain->playsink);
1072 gst_element_set_state (chain->bin, state);
1074 gst_element_set_state (chain->bin, GST_STATE_NULL);
1076 chain->activated = activate;
1082 element_is_sink (GstElement * element)
1086 GST_OBJECT_LOCK (element);
1087 is_sink = GST_OBJECT_FLAG_IS_SET (element, GST_ELEMENT_FLAG_SINK);
1088 GST_OBJECT_UNLOCK (element);
1090 GST_DEBUG_OBJECT (element, "is a sink: %s", (is_sink) ? "yes" : "no");
1095 element_has_property (GstElement * element, const gchar * pname, GType type)
1099 pspec = g_object_class_find_property (G_OBJECT_GET_CLASS (element), pname);
1101 if (pspec == NULL) {
1102 GST_DEBUG_OBJECT (element, "no %s property", pname);
1106 if (type == G_TYPE_INVALID || type == pspec->value_type ||
1107 g_type_is_a (pspec->value_type, type)) {
1108 GST_DEBUG_OBJECT (element, "has %s property of type %s", pname,
1109 (type == G_TYPE_INVALID) ? "any type" : g_type_name (type));
1113 GST_WARNING_OBJECT (element, "has %s property, but property is of type %s "
1114 "and we expected it to be of type %s", pname,
1115 g_type_name (pspec->value_type), g_type_name (type));
1122 const gchar *prop_name;
1125 } FindPropertyHelper;
1128 find_property (const GValue * item, FindPropertyHelper * helper)
1130 GstElement *element = g_value_get_object (item);
1131 if (helper->need_sink && !element_is_sink (element)) {
1135 if (!element_has_property (element, helper->prop_name, helper->prop_type)) {
1139 GST_INFO_OBJECT (element, "found %s with %s property", helper->prop_name,
1140 (helper->need_sink) ? "sink" : "element");
1141 return 0; /* keep it */
1144 /* FIXME: why not move these functions into core? */
1145 /* find a sink in the hierarchy with a property named @name. This function does
1146 * not increase the refcount of the returned object and thus remains valid as
1147 * long as the bin is valid. */
1149 gst_play_sink_find_property_sinks (GstPlaySink * playsink, GstElement * obj,
1150 const gchar * name, GType expected_type)
1152 GstElement *result = NULL;
1155 if (element_has_property (obj, name, expected_type)) {
1157 } else if (GST_IS_BIN (obj)) {
1159 GValue item = { 0, };
1160 FindPropertyHelper helper = { name, expected_type, TRUE };
1162 it = gst_bin_iterate_recurse (GST_BIN_CAST (obj));
1163 found = gst_iterator_find_custom (it,
1164 (GCompareFunc) find_property, &item, &helper);
1165 gst_iterator_free (it);
1167 result = g_value_get_object (&item);
1168 /* we don't need the extra ref */
1169 g_value_unset (&item);
1175 /* find an object in the hierarchy with a property named @name */
1177 gst_play_sink_find_property (GstPlaySink * playsink, GstElement * obj,
1178 const gchar * name, GType expected_type)
1180 GstElement *result = NULL;
1183 if (GST_IS_BIN (obj)) {
1185 GValue item = { 0, };
1186 FindPropertyHelper helper = { name, expected_type, FALSE };
1188 it = gst_bin_iterate_recurse (GST_BIN_CAST (obj));
1189 found = gst_iterator_find_custom (it,
1190 (GCompareFunc) find_property, &item, &helper);
1191 gst_iterator_free (it);
1193 result = g_value_dup_object (&item);
1194 g_value_unset (&item);
1196 if (element_has_property (obj, name, expected_type)) {
1198 gst_object_ref (obj);
1205 do_async_start (GstPlaySink * playsink)
1207 GstMessage *message;
1209 if (!playsink->need_async_start) {
1210 GST_INFO_OBJECT (playsink, "no async_start needed");
1214 playsink->async_pending = TRUE;
1216 GST_INFO_OBJECT (playsink, "Sending async_start message");
1217 message = gst_message_new_async_start (GST_OBJECT_CAST (playsink));
1218 GST_BIN_CLASS (gst_play_sink_parent_class)->handle_message (GST_BIN_CAST
1219 (playsink), message);
1223 do_async_done (GstPlaySink * playsink)
1225 GstMessage *message;
1227 if (playsink->async_pending) {
1228 GST_INFO_OBJECT (playsink, "Sending async_done message");
1229 message = gst_message_new_async_done (GST_OBJECT_CAST (playsink), FALSE);
1230 GST_BIN_CLASS (gst_play_sink_parent_class)->handle_message (GST_BIN_CAST
1231 (playsink), message);
1233 playsink->async_pending = FALSE;
1236 playsink->need_async_start = FALSE;
1239 /* try to change the state of an element. This function returns the element when
1240 * the state change could be performed. When this function returns NULL an error
1241 * occured and the element is unreffed if @unref is TRUE. */
1243 try_element (GstPlaySink * playsink, GstElement * element, gboolean unref)
1245 GstStateChangeReturn ret;
1248 ret = gst_element_set_state (element, GST_STATE_READY);
1249 if (ret == GST_STATE_CHANGE_FAILURE) {
1250 GST_DEBUG_OBJECT (playsink, "failed state change..");
1251 gst_element_set_state (element, GST_STATE_NULL);
1253 gst_object_unref (element);
1260 /* make the element (bin) that contains the elements needed to perform
1261 * video display. Only used for *raw* video streams.
1263 * +------------------------------------------------------------+
1265 * | +-------+ +----------+ +----------+ +---------+ |
1266 * | | queue | |colorspace| |videoscale| |videosink| |
1267 * | +-sink src-sink src-sink src-sink | |
1268 * | | +-------+ +----------+ +----------+ +---------+ |
1270 * +------------------------------------------------------------+
1273 static GstPlayVideoDeinterlaceChain *
1274 gen_video_deinterlace_chain (GstPlaySink * playsink)
1276 GstPlayVideoDeinterlaceChain *chain;
1279 GstElement *head = NULL, *prev = NULL;
1281 chain = g_new0 (GstPlayVideoDeinterlaceChain, 1);
1282 chain->chain.playsink = playsink;
1284 GST_DEBUG_OBJECT (playsink, "making video deinterlace chain %p", chain);
1286 /* create a bin to hold objects, as we create them we add them to this bin so
1287 * that when something goes wrong we only need to unref the bin */
1288 chain->chain.bin = gst_bin_new ("vdbin");
1289 bin = GST_BIN_CAST (chain->chain.bin);
1290 gst_object_ref_sink (bin);
1292 GST_DEBUG_OBJECT (playsink, "creating " COLORSPACE);
1293 chain->conv = gst_element_factory_make (COLORSPACE, "vdconv");
1294 if (chain->conv == NULL) {
1295 post_missing_element_message (playsink, COLORSPACE);
1296 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1297 (_("Missing element '%s' - check your GStreamer installation."),
1298 COLORSPACE), ("video rendering might fail"));
1300 gst_bin_add (bin, chain->conv);
1305 GST_DEBUG_OBJECT (playsink, "creating deinterlace");
1306 chain->deinterlace = gst_element_factory_make ("deinterlace", "deinterlace");
1307 if (chain->deinterlace == NULL) {
1308 post_missing_element_message (playsink, "deinterlace");
1309 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1310 (_("Missing element '%s' - check your GStreamer installation."),
1311 "deinterlace"), ("deinterlacing won't work"));
1313 gst_bin_add (bin, chain->deinterlace);
1315 if (!gst_element_link_pads_full (prev, "src", chain->deinterlace, "sink",
1316 GST_PAD_LINK_CHECK_TEMPLATE_CAPS))
1319 head = chain->deinterlace;
1321 prev = chain->deinterlace;
1325 pad = gst_element_get_static_pad (head, "sink");
1326 chain->sinkpad = gst_ghost_pad_new ("sink", pad);
1327 gst_object_unref (pad);
1329 chain->sinkpad = gst_ghost_pad_new_no_target ("sink", GST_PAD_SINK);
1333 pad = gst_element_get_static_pad (prev, "src");
1334 chain->srcpad = gst_ghost_pad_new ("src", pad);
1335 gst_object_unref (pad);
1337 chain->srcpad = gst_ghost_pad_new ("src", chain->sinkpad);
1340 gst_element_add_pad (chain->chain.bin, chain->sinkpad);
1341 gst_element_add_pad (chain->chain.bin, chain->srcpad);
1347 GST_ELEMENT_ERROR (playsink, CORE, PAD,
1348 (NULL), ("Failed to configure the video deinterlace chain."));
1349 free_chain ((GstPlayChain *) chain);
1355 is_valid_color_balance_element (GstColorBalance * bal)
1357 gboolean have_brightness = FALSE;
1358 gboolean have_contrast = FALSE;
1359 gboolean have_hue = FALSE;
1360 gboolean have_saturation = FALSE;
1361 const GList *channels, *l;
1363 channels = gst_color_balance_list_channels (bal);
1364 for (l = channels; l; l = l->next) {
1365 GstColorBalanceChannel *ch = l->data;
1367 if (g_strrstr (ch->label, "BRIGHTNESS"))
1368 have_brightness = TRUE;
1369 else if (g_strrstr (ch->label, "CONTRAST"))
1370 have_contrast = TRUE;
1371 else if (g_strrstr (ch->label, "HUE"))
1373 else if (g_strrstr (ch->label, "SATURATION"))
1374 have_saturation = TRUE;
1377 return have_brightness && have_contrast && have_hue && have_saturation;
1381 iterate_color_balance_elements (const GValue * item, gpointer user_data)
1384 GstColorBalance *cb, **cb_out = user_data;
1386 cb = GST_COLOR_BALANCE (g_value_get_object (item));
1387 valid = is_valid_color_balance_element (cb);
1390 && gst_color_balance_get_balance_type (*cb_out) ==
1391 GST_COLOR_BALANCE_SOFTWARE) {
1392 gst_object_unref (*cb_out);
1393 *cb_out = GST_COLOR_BALANCE (gst_object_ref (cb));
1394 } else if (!*cb_out) {
1395 *cb_out = GST_COLOR_BALANCE (gst_object_ref (cb));
1400 static GstColorBalance *
1401 find_color_balance_element (GstElement * element)
1404 GstColorBalance *cb = NULL;
1406 if (GST_IS_COLOR_BALANCE (element)
1407 && is_valid_color_balance_element (GST_COLOR_BALANCE (element)))
1408 return GST_COLOR_BALANCE (gst_object_ref (element));
1409 else if (!GST_IS_BIN (element))
1412 it = gst_bin_iterate_all_by_interface (GST_BIN (element),
1413 GST_TYPE_COLOR_BALANCE);
1414 while (gst_iterator_foreach (it, iterate_color_balance_elements,
1415 &cb) == GST_ITERATOR_RESYNC)
1416 gst_iterator_resync (it);
1417 gst_iterator_free (it);
1423 colorbalance_value_changed_cb (GstColorBalance * balance,
1424 GstColorBalanceChannel * channel, gint value, GstPlaySink * playsink)
1429 for (i = 0, l = playsink->colorbalance_channels; l; l = l->next, i++) {
1430 GstColorBalanceChannel *proxy = l->data;
1432 if (g_strrstr (channel->label, proxy->label)) {
1435 /* Convert to [0, 1] range */
1438 (gdouble) channel->min_value) / ((gdouble) channel->max_value -
1439 (gdouble) channel->min_value);
1440 /* Convert to proxy range */
1442 proxy->min_value + new_val * ((gdouble) proxy->max_value -
1443 (gdouble) proxy->min_value);
1444 playsink->colorbalance_values[i] = (gint) (0.5 + new_val);
1446 gst_color_balance_value_changed (GST_COLOR_BALANCE (playsink), proxy,
1447 playsink->colorbalance_values[i]);
1454 update_colorbalance (GstPlaySink * playsink)
1456 GstColorBalance *balance = NULL;
1460 GST_OBJECT_LOCK (playsink);
1461 if (playsink->colorbalance_element) {
1463 GST_COLOR_BALANCE (gst_object_ref (playsink->colorbalance_element));
1465 GST_OBJECT_UNLOCK (playsink);
1469 g_signal_handlers_block_by_func (balance,
1470 G_CALLBACK (colorbalance_value_changed_cb), playsink);
1472 for (i = 0, l = playsink->colorbalance_channels; l; l = l->next, i++) {
1473 GstColorBalanceChannel *proxy = l->data;
1474 GstColorBalanceChannel *channel = NULL;
1475 const GList *channels, *k;
1477 channels = gst_color_balance_list_channels (balance);
1478 for (k = channels; k; k = k->next) {
1479 GstColorBalanceChannel *tmp = k->data;
1481 if (g_strrstr (tmp->label, proxy->label)) {
1489 gst_color_balance_set_value (balance, channel,
1490 playsink->colorbalance_values[i]);
1493 g_signal_handlers_unblock_by_func (balance,
1494 G_CALLBACK (colorbalance_value_changed_cb), playsink);
1497 /* make the element (bin) that contains the elements needed to perform
1500 * +------------------------------------------------------------+
1502 * | +-------+ +----------+ +----------+ +---------+ |
1503 * | | queue | |colorspace| |videoscale| |videosink| |
1504 * | +-sink src-sink src-sink src-sink | |
1505 * | | +-------+ +----------+ +----------+ +---------+ |
1507 * +------------------------------------------------------------+
1510 static GstPlayVideoChain *
1511 gen_video_chain (GstPlaySink * playsink, gboolean raw, gboolean async)
1513 GstPlayVideoChain *chain;
1516 GstElement *head = NULL, *prev = NULL, *elem = NULL;
1518 chain = g_new0 (GstPlayVideoChain, 1);
1519 chain->chain.playsink = playsink;
1520 chain->chain.raw = raw;
1522 GST_DEBUG_OBJECT (playsink, "making video chain %p", chain);
1524 if (playsink->video_sink) {
1525 GST_DEBUG_OBJECT (playsink, "trying configured videosink");
1526 chain->sink = try_element (playsink, playsink->video_sink, FALSE);
1528 /* only try fallback if no specific sink was chosen */
1529 if (chain->sink == NULL) {
1530 GST_DEBUG_OBJECT (playsink, "trying autovideosink");
1531 elem = gst_element_factory_make ("autovideosink", "videosink");
1532 chain->sink = try_element (playsink, elem, TRUE);
1534 if (chain->sink == NULL) {
1535 /* if default sink from config.h is different then try it too */
1536 if (strcmp (DEFAULT_VIDEOSINK, "autovideosink")) {
1537 GST_DEBUG_OBJECT (playsink, "trying " DEFAULT_VIDEOSINK);
1538 elem = gst_element_factory_make (DEFAULT_VIDEOSINK, "videosink");
1539 chain->sink = try_element (playsink, elem, TRUE);
1543 playsink->video_sink = gst_object_ref (chain->sink);
1545 if (chain->sink == NULL)
1549 /* if we can disable async behaviour of the sink, we can avoid adding a
1550 * queue for the audio chain. */
1552 gst_play_sink_find_property_sinks (playsink, chain->sink, "async",
1555 GST_DEBUG_OBJECT (playsink, "setting async property to %d on element %s",
1556 async, GST_ELEMENT_NAME (elem));
1557 g_object_set (elem, "async", async, NULL);
1558 chain->async = async;
1560 GST_DEBUG_OBJECT (playsink, "no async property on the sink");
1561 chain->async = TRUE;
1564 /* Make sure the aspect ratio is kept */
1566 gst_play_sink_find_property_sinks (playsink, chain->sink,
1567 "force-aspect-ratio", G_TYPE_BOOLEAN);
1569 g_object_set (elem, "force-aspect-ratio", TRUE, NULL);
1571 /* find ts-offset element */
1572 gst_object_replace ((GstObject **) & chain->ts_offset, (GstObject *)
1573 gst_play_sink_find_property_sinks (playsink, chain->sink, "ts-offset",
1576 /* create a bin to hold objects, as we create them we add them to this bin so
1577 * that when something goes wrong we only need to unref the bin */
1578 chain->chain.bin = gst_bin_new ("vbin");
1579 bin = GST_BIN_CAST (chain->chain.bin);
1580 gst_object_ref_sink (bin);
1581 gst_bin_add (bin, chain->sink);
1583 /* Get the VideoOverlay element */
1585 GstVideoOverlay *overlay = NULL;
1587 GST_OBJECT_LOCK (playsink);
1588 if (playsink->overlay_element)
1589 gst_object_unref (playsink->overlay_element);
1590 playsink->overlay_element =
1591 GST_VIDEO_OVERLAY (gst_bin_get_by_interface (GST_BIN (chain->chain.bin),
1592 GST_TYPE_VIDEO_OVERLAY));
1593 if (playsink->overlay_element)
1594 overlay = GST_VIDEO_OVERLAY (gst_object_ref (playsink->overlay_element));
1595 GST_OBJECT_UNLOCK (playsink);
1598 if (playsink->overlay_handle_set)
1599 gst_video_overlay_set_window_handle (overlay, playsink->overlay_handle);
1600 if (playsink->overlay_handle_events_set)
1601 gst_video_overlay_handle_events (overlay,
1602 playsink->overlay_handle_events);
1603 if (playsink->overlay_render_rectangle_set)
1604 gst_video_overlay_set_render_rectangle (overlay,
1605 playsink->overlay_x, playsink->overlay_y,
1606 playsink->overlay_width, playsink->overlay_height);
1607 gst_object_unref (overlay);
1611 /* decouple decoder from sink, this improves playback quite a lot since the
1612 * decoder can continue while the sink blocks for synchronisation. We don't
1613 * need a lot of buffers as this consumes a lot of memory and we don't want
1614 * too little because else we would be context switching too quickly. */
1615 chain->queue = gst_element_factory_make ("queue", "vqueue");
1616 if (chain->queue == NULL) {
1617 post_missing_element_message (playsink, "queue");
1618 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1619 (_("Missing element '%s' - check your GStreamer installation."),
1620 "queue"), ("video rendering might be suboptimal"));
1624 g_object_set (G_OBJECT (chain->queue), "max-size-buffers", 3,
1625 "max-size-bytes", 0, "max-size-time", (gint64) 0, "silent", TRUE, NULL);
1626 gst_bin_add (bin, chain->queue);
1627 head = prev = chain->queue;
1630 GST_OBJECT_LOCK (playsink);
1631 if (playsink->colorbalance_element) {
1632 g_signal_handlers_disconnect_by_func (playsink->colorbalance_element,
1633 G_CALLBACK (colorbalance_value_changed_cb), playsink);
1634 gst_object_unref (playsink->colorbalance_element);
1636 playsink->colorbalance_element = find_color_balance_element (chain->sink);
1637 GST_OBJECT_UNLOCK (playsink);
1639 if (!(playsink->flags & GST_PLAY_FLAG_NATIVE_VIDEO)
1640 || (!playsink->colorbalance_element
1641 && (playsink->flags & GST_PLAY_FLAG_SOFT_COLORBALANCE))) {
1642 gboolean use_converters = !(playsink->flags & GST_PLAY_FLAG_NATIVE_VIDEO);
1643 gboolean use_balance = !playsink->colorbalance_element
1644 && (playsink->flags & GST_PLAY_FLAG_SOFT_COLORBALANCE);
1646 GST_DEBUG_OBJECT (playsink, "creating videoconverter");
1648 g_object_new (GST_TYPE_PLAY_SINK_VIDEO_CONVERT, "name", "vconv",
1649 "use-converters", use_converters, "use-balance", use_balance, NULL);
1651 GST_OBJECT_LOCK (playsink);
1652 if (use_balance && GST_PLAY_SINK_VIDEO_CONVERT (chain->conv)->balance)
1653 playsink->colorbalance_element =
1654 GST_COLOR_BALANCE (gst_object_ref (GST_PLAY_SINK_VIDEO_CONVERT
1655 (chain->conv)->balance));
1656 GST_OBJECT_UNLOCK (playsink);
1658 gst_bin_add (bin, chain->conv);
1660 if (!gst_element_link_pads_full (prev, "src", chain->conv, "sink",
1661 GST_PAD_LINK_CHECK_TEMPLATE_CAPS))
1669 update_colorbalance (playsink);
1672 GST_DEBUG_OBJECT (playsink, "linking to sink");
1673 if (!gst_element_link_pads_full (prev, "src", chain->sink, NULL,
1674 GST_PAD_LINK_CHECK_TEMPLATE_CAPS))
1678 pad = gst_element_get_static_pad (head, "sink");
1679 chain->sinkpad = gst_ghost_pad_new ("sink", pad);
1680 gst_object_unref (pad);
1682 gst_element_add_pad (chain->chain.bin, chain->sinkpad);
1689 if (!elem && !playsink->video_sink) {
1690 post_missing_element_message (playsink, "autovideosink");
1691 if (strcmp (DEFAULT_VIDEOSINK, "autovideosink")) {
1692 post_missing_element_message (playsink, DEFAULT_VIDEOSINK);
1693 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
1694 (_("Both autovideosink and %s elements are missing."),
1695 DEFAULT_VIDEOSINK), (NULL));
1697 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
1698 (_("The autovideosink element is missing.")), (NULL));
1701 if (playsink->video_sink) {
1702 GST_ELEMENT_ERROR (playsink, CORE, STATE_CHANGE,
1703 (_("Configured videosink %s is not working."),
1704 GST_ELEMENT_NAME (playsink->video_sink)), (NULL));
1705 } else if (strcmp (DEFAULT_VIDEOSINK, "autovideosink")) {
1706 GST_ELEMENT_ERROR (playsink, CORE, STATE_CHANGE,
1707 (_("Both autovideosink and %s elements are not working."),
1708 DEFAULT_VIDEOSINK), (NULL));
1710 GST_ELEMENT_ERROR (playsink, CORE, STATE_CHANGE,
1711 (_("The autovideosink element is not working.")), (NULL));
1714 free_chain ((GstPlayChain *) chain);
1720 GST_ELEMENT_ERROR (playsink, CORE, PAD,
1721 (NULL), ("Failed to configure the video sink."));
1722 /* checking sink made it READY */
1723 gst_element_set_state (chain->sink, GST_STATE_NULL);
1724 /* Remove chain from the bin to allow reuse later */
1725 gst_bin_remove (bin, chain->sink);
1726 free_chain ((GstPlayChain *) chain);
1732 setup_video_chain (GstPlaySink * playsink, gboolean raw, gboolean async)
1735 GstPlayVideoChain *chain;
1736 GstStateChangeReturn ret;
1738 chain = playsink->videochain;
1740 chain->chain.raw = raw;
1742 /* if the chain was active we don't do anything */
1743 if (GST_PLAY_CHAIN (chain)->activated == TRUE)
1746 /* try to set the sink element to READY again */
1747 ret = gst_element_set_state (chain->sink, GST_STATE_READY);
1748 if (ret == GST_STATE_CHANGE_FAILURE)
1751 /* Get the VideoOverlay element */
1753 GstVideoOverlay *overlay = NULL;
1755 GST_OBJECT_LOCK (playsink);
1756 if (playsink->overlay_element)
1757 gst_object_unref (playsink->overlay_element);
1758 playsink->overlay_element =
1759 GST_VIDEO_OVERLAY (gst_bin_get_by_interface (GST_BIN (chain->chain.bin),
1760 GST_TYPE_VIDEO_OVERLAY));
1761 if (playsink->overlay_element)
1762 overlay = GST_VIDEO_OVERLAY (gst_object_ref (playsink->overlay_element));
1763 GST_OBJECT_UNLOCK (playsink);
1766 if (playsink->overlay_handle_set)
1767 gst_video_overlay_set_window_handle (overlay, playsink->overlay_handle);
1768 if (playsink->overlay_handle_events_set)
1769 gst_video_overlay_handle_events (overlay,
1770 playsink->overlay_handle_events);
1771 if (playsink->overlay_render_rectangle_set)
1772 gst_video_overlay_set_render_rectangle (overlay,
1773 playsink->overlay_x, playsink->overlay_y,
1774 playsink->overlay_width, playsink->overlay_height);
1775 gst_object_unref (overlay);
1779 /* find ts-offset element */
1780 gst_object_replace ((GstObject **) & chain->ts_offset, (GstObject *)
1781 gst_play_sink_find_property_sinks (playsink, chain->sink, "ts-offset",
1784 /* if we can disable async behaviour of the sink, we can avoid adding a
1785 * queue for the audio chain. */
1787 gst_play_sink_find_property_sinks (playsink, chain->sink, "async",
1790 GST_DEBUG_OBJECT (playsink, "setting async property to %d on element %s",
1791 async, GST_ELEMENT_NAME (elem));
1792 g_object_set (elem, "async", async, NULL);
1793 chain->async = async;
1795 GST_DEBUG_OBJECT (playsink, "no async property on the sink");
1796 chain->async = TRUE;
1799 /* Make sure the aspect ratio is kept */
1801 gst_play_sink_find_property_sinks (playsink, chain->sink,
1802 "force-aspect-ratio", G_TYPE_BOOLEAN);
1804 g_object_set (elem, "force-aspect-ratio", TRUE, NULL);
1806 GST_OBJECT_LOCK (playsink);
1807 if (playsink->colorbalance_element) {
1808 g_signal_handlers_disconnect_by_func (playsink->colorbalance_element,
1809 G_CALLBACK (colorbalance_value_changed_cb), playsink);
1810 gst_object_unref (playsink->colorbalance_element);
1812 playsink->colorbalance_element = find_color_balance_element (chain->sink);
1813 GST_OBJECT_UNLOCK (playsink);
1816 gboolean use_balance = !playsink->colorbalance_element
1817 && (playsink->flags & GST_PLAY_FLAG_SOFT_COLORBALANCE);
1819 g_object_set (chain->conv, "use-balance", use_balance, NULL);
1821 GST_OBJECT_LOCK (playsink);
1822 if (use_balance && GST_PLAY_SINK_VIDEO_CONVERT (chain->conv)->balance)
1823 playsink->colorbalance_element =
1824 GST_COLOR_BALANCE (gst_object_ref (GST_PLAY_SINK_VIDEO_CONVERT
1825 (chain->conv)->balance));
1826 GST_OBJECT_UNLOCK (playsink);
1829 update_colorbalance (playsink);
1834 /* make an element for playback of video with subtitles embedded.
1835 * Only used for *raw* video streams.
1837 * +--------------------------------------------+
1839 * | +--------+ +-----------------+ |
1840 * | | queue | | subtitleoverlay | |
1841 * video--src sink---video_sink | |
1842 * | +--------+ | src--src
1843 * text------------------text_sink | |
1844 * | +-----------------+ |
1845 * +--------------------------------------------+
1848 static GstPlayTextChain *
1849 gen_text_chain (GstPlaySink * playsink)
1851 GstPlayTextChain *chain;
1854 GstPad *videosinkpad, *textsinkpad, *srcpad;
1856 chain = g_new0 (GstPlayTextChain, 1);
1857 chain->chain.playsink = playsink;
1859 GST_DEBUG_OBJECT (playsink, "making text chain %p", chain);
1861 chain->chain.bin = gst_bin_new ("tbin");
1862 bin = GST_BIN_CAST (chain->chain.bin);
1863 gst_object_ref_sink (bin);
1865 videosinkpad = textsinkpad = srcpad = NULL;
1867 /* first try to hook the text pad to the custom sink */
1868 if (playsink->text_sink) {
1869 GST_DEBUG_OBJECT (playsink, "trying configured textsink");
1870 chain->sink = try_element (playsink, playsink->text_sink, FALSE);
1873 gst_play_sink_find_property_sinks (playsink, chain->sink, "async",
1876 /* make sure the sparse subtitles don't participate in the preroll */
1877 g_object_set (elem, "async", FALSE, NULL);
1878 GST_DEBUG_OBJECT (playsink, "adding custom text sink");
1879 gst_bin_add (bin, chain->sink);
1880 /* NOTE streamsynchronizer needs streams decoupled */
1881 /* make a little queue */
1882 chain->queue = gst_element_factory_make ("queue", "subqueue");
1883 if (chain->queue == NULL) {
1884 post_missing_element_message (playsink, "queue");
1885 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1886 (_("Missing element '%s' - check your GStreamer installation."),
1887 "queue"), ("rendering might be suboptimal"));
1889 g_object_set (G_OBJECT (chain->queue), "max-size-buffers", 3,
1890 "max-size-bytes", 0, "max-size-time", (gint64) 0,
1891 "silent", TRUE, NULL);
1892 gst_bin_add (bin, chain->queue);
1894 /* we have a custom sink, this will be our textsinkpad */
1895 if (gst_element_link_pads_full (chain->queue, "src", chain->sink,
1896 "sink", GST_PAD_LINK_CHECK_TEMPLATE_CAPS)) {
1897 /* we're all fine now and we can add the sink to the chain */
1898 GST_DEBUG_OBJECT (playsink, "using custom text sink");
1899 textsinkpad = gst_element_get_static_pad (chain->queue, "sink");
1901 GST_WARNING_OBJECT (playsink,
1902 "can't find a sink pad on custom text sink");
1903 gst_bin_remove (bin, chain->sink);
1904 gst_bin_remove (bin, chain->queue);
1906 chain->queue = NULL;
1908 /* try to set sync to true but it's no biggie when we can't */
1909 if (chain->sink && (elem =
1910 gst_play_sink_find_property_sinks (playsink, chain->sink,
1911 "sync", G_TYPE_BOOLEAN)))
1912 g_object_set (elem, "sync", TRUE, NULL);
1915 gst_bin_remove (bin, chain->sink);
1917 GST_WARNING_OBJECT (playsink,
1918 "can't find async property in custom text sink");
1921 if (textsinkpad == NULL) {
1922 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1923 (_("Custom text sink element is not usable.")),
1924 ("fallback to default textoverlay"));
1928 if (textsinkpad == NULL) {
1929 if (!(playsink->flags & GST_PLAY_FLAG_NATIVE_VIDEO)) {
1930 /* make a little queue */
1931 chain->queue = gst_element_factory_make ("queue", "vqueue");
1932 if (chain->queue == NULL) {
1933 post_missing_element_message (playsink, "queue");
1934 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1935 (_("Missing element '%s' - check your GStreamer installation."),
1936 "queue"), ("video rendering might be suboptimal"));
1938 g_object_set (G_OBJECT (chain->queue), "max-size-buffers", 3,
1939 "max-size-bytes", 0, "max-size-time", (gint64) 0,
1940 "silent", TRUE, NULL);
1941 gst_bin_add (bin, chain->queue);
1942 videosinkpad = gst_element_get_static_pad (chain->queue, "sink");
1946 gst_element_factory_make ("subtitleoverlay", "suboverlay");
1947 if (chain->overlay == NULL) {
1948 post_missing_element_message (playsink, "subtitleoverlay");
1949 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1950 (_("Missing element '%s' - check your GStreamer installation."),
1951 "subtitleoverlay"), ("subtitle rendering disabled"));
1953 GstElement *element;
1955 gst_bin_add (bin, chain->overlay);
1957 g_object_set (G_OBJECT (chain->overlay), "silent", FALSE, NULL);
1958 if (playsink->font_desc) {
1959 g_object_set (G_OBJECT (chain->overlay), "font-desc",
1960 playsink->font_desc, NULL);
1962 if (playsink->subtitle_encoding) {
1963 g_object_set (G_OBJECT (chain->overlay), "subtitle-encoding",
1964 playsink->subtitle_encoding, NULL);
1967 gst_element_link_pads_full (chain->queue, "src", chain->overlay,
1968 "video_sink", GST_PAD_LINK_CHECK_TEMPLATE_CAPS);
1970 /* make another little queue to decouple streams */
1971 element = gst_element_factory_make ("queue", "subqueue");
1972 if (element == NULL) {
1973 post_missing_element_message (playsink, "queue");
1974 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1975 (_("Missing element '%s' - check your GStreamer installation."),
1976 "queue"), ("rendering might be suboptimal"));
1978 g_object_set (G_OBJECT (element), "max-size-buffers", 3,
1979 "max-size-bytes", 0, "max-size-time", (gint64) 0,
1980 "silent", TRUE, NULL);
1981 gst_bin_add (bin, element);
1982 if (gst_element_link_pads_full (element, "src", chain->overlay,
1983 "subtitle_sink", GST_PAD_LINK_CHECK_TEMPLATE_CAPS)) {
1984 textsinkpad = gst_element_get_static_pad (element, "sink");
1985 srcpad = gst_element_get_static_pad (chain->overlay, "src");
1987 gst_bin_remove (bin, chain->sink);
1988 gst_bin_remove (bin, chain->overlay);
1990 chain->overlay = NULL;
1991 gst_object_unref (videosinkpad);
1992 videosinkpad = NULL;
1999 if (videosinkpad == NULL) {
2000 /* if we still don't have a videosink, we don't have an overlay. the only
2001 * thing we can do is insert an identity and ghost the src
2003 chain->identity = gst_element_factory_make ("identity", "tidentity");
2004 if (chain->identity == NULL) {
2005 post_missing_element_message (playsink, "identity");
2006 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
2007 (_("Missing element '%s' - check your GStreamer installation."),
2008 "identity"), (NULL));
2010 g_object_set (chain->identity, "signal-handoffs", FALSE, NULL);
2011 g_object_set (chain->identity, "silent", TRUE, NULL);
2012 gst_bin_add (bin, chain->identity);
2013 srcpad = gst_element_get_static_pad (chain->identity, "src");
2014 videosinkpad = gst_element_get_static_pad (chain->identity, "sink");
2018 /* expose the ghostpads */
2020 chain->videosinkpad = gst_ghost_pad_new ("sink", videosinkpad);
2021 gst_object_unref (videosinkpad);
2022 gst_element_add_pad (chain->chain.bin, chain->videosinkpad);
2025 chain->textsinkpad = gst_ghost_pad_new ("text_sink", textsinkpad);
2026 gst_object_unref (textsinkpad);
2027 gst_element_add_pad (chain->chain.bin, chain->textsinkpad);
2030 chain->srcpad = gst_ghost_pad_new ("src", srcpad);
2031 gst_object_unref (srcpad);
2032 gst_element_add_pad (chain->chain.bin, chain->srcpad);
2039 notify_volume_cb (GObject * object, GParamSpec * pspec, GstPlaySink * playsink)
2043 g_object_get (object, "volume", &vol, NULL);
2044 playsink->volume = vol;
2046 g_object_notify (G_OBJECT (playsink), "volume");
2050 notify_mute_cb (GObject * object, GParamSpec * pspec, GstPlaySink * playsink)
2054 g_object_get (object, "mute", &mute, NULL);
2055 playsink->mute = mute;
2057 g_object_notify (G_OBJECT (playsink), "mute");
2060 /* make the chain that contains the elements needed to perform
2063 * We add a tee as the first element so that we can link the visualisation chain
2064 * to it when requested.
2066 * +-------------------------------------------------------------+
2068 * | +---------+ +----------+ +---------+ +---------+ |
2069 * | |audioconv| |audioscale| | volume | |audiosink| |
2070 * | +-srck src-sink src-sink src-sink | |
2071 * | | +---------+ +----------+ +---------+ +---------+ |
2073 * +-------------------------------------------------------------+
2075 static GstPlayAudioChain *
2076 gen_audio_chain (GstPlaySink * playsink, gboolean raw)
2078 GstPlayAudioChain *chain;
2080 gboolean have_volume;
2082 GstElement *head, *prev, *elem = NULL;
2084 chain = g_new0 (GstPlayAudioChain, 1);
2085 chain->chain.playsink = playsink;
2086 chain->chain.raw = raw;
2088 GST_DEBUG_OBJECT (playsink, "making audio chain %p", chain);
2090 if (playsink->audio_sink) {
2091 GST_DEBUG_OBJECT (playsink, "trying configured audiosink %" GST_PTR_FORMAT,
2092 playsink->audio_sink);
2093 chain->sink = try_element (playsink, playsink->audio_sink, FALSE);
2095 /* only try fallback if no specific sink was chosen */
2096 if (chain->sink == NULL) {
2097 GST_DEBUG_OBJECT (playsink, "trying autoaudiosink");
2098 elem = gst_element_factory_make ("autoaudiosink", "audiosink");
2099 chain->sink = try_element (playsink, elem, TRUE);
2101 if (chain->sink == NULL) {
2102 /* if default sink from config.h is different then try it too */
2103 if (strcmp (DEFAULT_AUDIOSINK, "autoaudiosink")) {
2104 GST_DEBUG_OBJECT (playsink, "trying " DEFAULT_AUDIOSINK);
2105 elem = gst_element_factory_make (DEFAULT_AUDIOSINK, "audiosink");
2106 chain->sink = try_element (playsink, elem, TRUE);
2110 playsink->audio_sink = gst_object_ref (chain->sink);
2112 if (chain->sink == NULL)
2115 chain->chain.bin = gst_bin_new ("abin");
2116 bin = GST_BIN_CAST (chain->chain.bin);
2117 gst_object_ref_sink (bin);
2118 gst_bin_add (bin, chain->sink);
2120 /* we have to add a queue when we need to decouple for the video sink in
2121 * visualisations and for streamsynchronizer */
2122 GST_DEBUG_OBJECT (playsink, "adding audio queue");
2123 chain->queue = gst_element_factory_make ("queue", "aqueue");
2124 if (chain->queue == NULL) {
2125 post_missing_element_message (playsink, "queue");
2126 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
2127 (_("Missing element '%s' - check your GStreamer installation."),
2128 "queue"), ("audio playback and visualizations might not work"));
2132 g_object_set (chain->queue, "silent", TRUE, NULL);
2133 gst_bin_add (bin, chain->queue);
2134 prev = head = chain->queue;
2137 /* find ts-offset element */
2138 gst_object_replace ((GstObject **) & chain->ts_offset, (GstObject *)
2139 gst_play_sink_find_property_sinks (playsink, chain->sink, "ts-offset",
2142 /* check if the sink, or something within the sink, has the volume property.
2143 * If it does we don't need to add a volume element. */
2145 gst_play_sink_find_property_sinks (playsink, chain->sink, "volume",
2148 chain->volume = elem;
2150 g_signal_connect (chain->volume, "notify::volume",
2151 G_CALLBACK (notify_volume_cb), playsink);
2153 GST_DEBUG_OBJECT (playsink, "the sink has a volume property");
2155 chain->sink_volume = TRUE;
2156 /* if the sink also has a mute property we can use this as well. We'll only
2157 * use the mute property if there is a volume property. We can simulate the
2158 * mute with the volume otherwise. */
2160 gst_play_sink_find_property_sinks (playsink, chain->sink, "mute",
2163 GST_DEBUG_OBJECT (playsink, "the sink has a mute property");
2164 g_signal_connect (chain->mute, "notify::mute",
2165 G_CALLBACK (notify_mute_cb), playsink);
2167 /* use the sink to control the volume and mute */
2168 if (playsink->volume_changed) {
2169 g_object_set (G_OBJECT (chain->volume), "volume", playsink->volume, NULL);
2170 playsink->volume_changed = FALSE;
2172 if (playsink->mute_changed) {
2174 g_object_set (chain->mute, "mute", playsink->mute, NULL);
2177 g_object_set (chain->volume, "volume", (gdouble) 0.0, NULL);
2179 playsink->mute_changed = FALSE;
2182 /* no volume, we need to add a volume element when we can */
2183 GST_DEBUG_OBJECT (playsink, "the sink has no volume property");
2184 have_volume = FALSE;
2185 chain->sink_volume = FALSE;
2188 if (!(playsink->flags & GST_PLAY_FLAG_NATIVE_AUDIO) || (!have_volume
2189 && (playsink->flags & GST_PLAY_FLAG_SOFT_VOLUME))) {
2190 gboolean use_converters = !(playsink->flags & GST_PLAY_FLAG_NATIVE_AUDIO);
2191 gboolean use_volume =
2192 !have_volume && (playsink->flags & GST_PLAY_FLAG_SOFT_VOLUME);
2193 GST_DEBUG_OBJECT (playsink,
2194 "creating audioconvert with use-converters %d, use-volume %d",
2195 use_converters, use_volume);
2197 g_object_new (GST_TYPE_PLAY_SINK_AUDIO_CONVERT, "name", "aconv",
2198 "use-converters", use_converters, "use-volume", use_volume, NULL);
2199 gst_bin_add (bin, chain->conv);
2201 if (!gst_element_link_pads_full (prev, "src", chain->conv, "sink",
2202 GST_PAD_LINK_CHECK_TEMPLATE_CAPS))
2209 if (!have_volume && (playsink->flags & GST_PLAY_FLAG_SOFT_VOLUME)) {
2210 GstPlaySinkAudioConvert *conv =
2211 GST_PLAY_SINK_AUDIO_CONVERT_CAST (chain->conv);
2214 chain->volume = conv->volume;
2217 g_signal_connect (chain->volume, "notify::volume",
2218 G_CALLBACK (notify_volume_cb), playsink);
2220 /* volume also has the mute property */
2221 chain->mute = chain->volume;
2222 g_signal_connect (chain->mute, "notify::mute",
2223 G_CALLBACK (notify_mute_cb), playsink);
2225 /* configure with the latest volume and mute */
2226 g_object_set (G_OBJECT (chain->volume), "volume", playsink->volume,
2228 g_object_set (G_OBJECT (chain->mute), "mute", playsink->mute, NULL);
2234 /* we only have to link to the previous element if we have something in
2235 * front of the sink */
2236 GST_DEBUG_OBJECT (playsink, "linking to sink");
2237 if (!gst_element_link_pads_full (prev, "src", chain->sink, NULL,
2238 GST_PAD_LINK_CHECK_TEMPLATE_CAPS))
2242 /* post a warning if we have no way to configure the volume */
2244 GST_ELEMENT_WARNING (playsink, STREAM, NOT_IMPLEMENTED,
2245 (_("No volume control found")), ("Volume/mute is not available"));
2248 /* and ghost the sinkpad of the headmost element */
2249 GST_DEBUG_OBJECT (playsink, "ghosting sink pad");
2250 pad = gst_element_get_static_pad (head, "sink");
2251 chain->sinkpad = gst_ghost_pad_new ("sink", pad);
2252 gst_object_unref (pad);
2253 gst_element_add_pad (chain->chain.bin, chain->sinkpad);
2260 if (!elem && !playsink->audio_sink) {
2261 post_missing_element_message (playsink, "autoaudiosink");
2262 if (strcmp (DEFAULT_AUDIOSINK, "autoaudiosink")) {
2263 post_missing_element_message (playsink, DEFAULT_AUDIOSINK);
2264 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
2265 (_("Both autoaudiosink and %s elements are missing."),
2266 DEFAULT_AUDIOSINK), (NULL));
2268 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
2269 (_("The autoaudiosink element is missing.")), (NULL));
2272 if (playsink->audio_sink) {
2273 GST_ELEMENT_ERROR (playsink, CORE, STATE_CHANGE,
2274 (_("Configured audiosink %s is not working."),
2275 GST_ELEMENT_NAME (playsink->audio_sink)), (NULL));
2276 } else if (strcmp (DEFAULT_AUDIOSINK, "autoaudiosink")) {
2277 GST_ELEMENT_ERROR (playsink, CORE, STATE_CHANGE,
2278 (_("Both autoaudiosink and %s elements are not working."),
2279 DEFAULT_AUDIOSINK), (NULL));
2281 GST_ELEMENT_ERROR (playsink, CORE, STATE_CHANGE,
2282 (_("The autoaudiosink element is not working.")), (NULL));
2285 free_chain ((GstPlayChain *) chain);
2290 GST_ELEMENT_ERROR (playsink, CORE, PAD,
2291 (NULL), ("Failed to configure the audio sink."));
2292 /* checking sink made it READY */
2293 gst_element_set_state (chain->sink, GST_STATE_NULL);
2294 /* Remove chain from the bin to allow reuse later */
2295 gst_bin_remove (bin, chain->sink);
2296 free_chain ((GstPlayChain *) chain);
2302 setup_audio_chain (GstPlaySink * playsink, gboolean raw)
2305 GstPlayAudioChain *chain;
2306 GstStateChangeReturn ret;
2307 GstPlaySinkAudioConvert *conv;
2309 chain = playsink->audiochain;
2310 conv = GST_PLAY_SINK_AUDIO_CONVERT_CAST (chain->conv);
2312 chain->chain.raw = raw;
2314 /* if the chain was active we don't do anything */
2315 if (GST_PLAY_CHAIN (chain)->activated == TRUE)
2318 /* try to set the sink element to READY again */
2319 ret = gst_element_set_state (chain->sink, GST_STATE_READY);
2320 if (ret == GST_STATE_CHANGE_FAILURE)
2323 /* find ts-offset element */
2324 gst_object_replace ((GstObject **) & chain->ts_offset, (GstObject *)
2325 gst_play_sink_find_property_sinks (playsink, chain->sink, "ts-offset",
2328 /* check if the sink, or something within the sink, has the volume property.
2329 * If it does we don't need to add a volume element. */
2331 gst_play_sink_find_property_sinks (playsink, chain->sink, "volume",
2334 chain->volume = elem;
2336 if (playsink->volume_changed) {
2337 GST_DEBUG_OBJECT (playsink, "the sink has a volume property, setting %f",
2339 /* use the sink to control the volume */
2340 g_object_set (G_OBJECT (chain->volume), "volume", playsink->volume, NULL);
2341 playsink->volume_changed = FALSE;
2344 g_signal_connect (chain->volume, "notify::volume",
2345 G_CALLBACK (notify_volume_cb), playsink);
2346 /* if the sink also has a mute property we can use this as well. We'll only
2347 * use the mute property if there is a volume property. We can simulate the
2348 * mute with the volume otherwise. */
2350 gst_play_sink_find_property_sinks (playsink, chain->sink, "mute",
2353 GST_DEBUG_OBJECT (playsink, "the sink has a mute property");
2354 g_signal_connect (chain->mute, "notify::mute",
2355 G_CALLBACK (notify_mute_cb), playsink);
2358 g_object_set (chain->conv, "use-volume", FALSE, NULL);
2360 /* no volume, we need to add a volume element when we can */
2361 g_object_set (chain->conv, "use-volume",
2362 ! !(playsink->flags & GST_PLAY_FLAG_SOFT_VOLUME), NULL);
2363 GST_DEBUG_OBJECT (playsink, "the sink has no volume property");
2365 /* Disconnect signals */
2366 disconnect_chain (chain, playsink);
2368 if (conv->volume && (playsink->flags & GST_PLAY_FLAG_SOFT_VOLUME)) {
2369 chain->volume = conv->volume;
2370 chain->mute = chain->volume;
2372 g_signal_connect (chain->volume, "notify::volume",
2373 G_CALLBACK (notify_volume_cb), playsink);
2375 g_signal_connect (chain->mute, "notify::mute",
2376 G_CALLBACK (notify_mute_cb), playsink);
2378 /* configure with the latest volume and mute */
2379 g_object_set (G_OBJECT (chain->volume), "volume", playsink->volume, NULL);
2380 g_object_set (G_OBJECT (chain->mute), "mute", playsink->mute, NULL);
2383 GST_DEBUG_OBJECT (playsink, "reusing existing volume element");
2389 * +-------------------------------------------------------------------+
2391 * | +----------+ +------------+ +----------+ +-------+ |
2392 * | | visqueue | | audioconv | | audiores | | vis | |
2393 * | +-sink src-sink + samp src-sink src-sink src-+ |
2394 * | | +----------+ +------------+ +----------+ +-------+ | |
2396 * +-------------------------------------------------------------------+
2399 static GstPlayVisChain *
2400 gen_vis_chain (GstPlaySink * playsink)
2402 GstPlayVisChain *chain;
2408 chain = g_new0 (GstPlayVisChain, 1);
2409 chain->chain.playsink = playsink;
2411 GST_DEBUG_OBJECT (playsink, "making vis chain %p", chain);
2413 chain->chain.bin = gst_bin_new ("visbin");
2414 bin = GST_BIN_CAST (chain->chain.bin);
2415 gst_object_ref_sink (bin);
2417 /* we're queuing raw audio here, we can remove this queue when we can disable
2418 * async behaviour in the video sink. */
2419 chain->queue = gst_element_factory_make ("queue", "visqueue");
2420 if (chain->queue == NULL)
2422 g_object_set (chain->queue, "silent", TRUE, NULL);
2423 gst_bin_add (bin, chain->queue);
2425 chain->conv = gst_element_factory_make ("audioconvert", "aconv");
2426 if (chain->conv == NULL)
2427 goto no_audioconvert;
2428 gst_bin_add (bin, chain->conv);
2430 chain->resample = gst_element_factory_make ("audioresample", "aresample");
2431 if (chain->resample == NULL)
2432 goto no_audioresample;
2433 gst_bin_add (bin, chain->resample);
2435 /* this pad will be used for blocking the dataflow and switching the vis
2437 chain->blockpad = gst_element_get_static_pad (chain->resample, "src");
2439 if (playsink->visualisation) {
2440 GST_DEBUG_OBJECT (playsink, "trying configure vis");
2441 chain->vis = try_element (playsink, playsink->visualisation, FALSE);
2443 if (chain->vis == NULL) {
2444 GST_DEBUG_OBJECT (playsink, "trying goom");
2445 elem = gst_element_factory_make ("goom", "vis");
2446 chain->vis = try_element (playsink, elem, TRUE);
2448 if (chain->vis == NULL)
2451 gst_bin_add (bin, chain->vis);
2453 res = gst_element_link_pads_full (chain->queue, "src", chain->conv, "sink",
2454 GST_PAD_LINK_CHECK_NOTHING);
2456 gst_element_link_pads_full (chain->conv, "src", chain->resample, "sink",
2457 GST_PAD_LINK_CHECK_NOTHING);
2459 gst_element_link_pads_full (chain->resample, "src", chain->vis, "sink",
2460 GST_PAD_LINK_CHECK_NOTHING);
2464 chain->vissinkpad = gst_element_get_static_pad (chain->vis, "sink");
2465 chain->vissrcpad = gst_element_get_static_pad (chain->vis, "src");
2467 pad = gst_element_get_static_pad (chain->queue, "sink");
2468 chain->sinkpad = gst_ghost_pad_new ("sink", pad);
2469 gst_object_unref (pad);
2470 gst_element_add_pad (chain->chain.bin, chain->sinkpad);
2472 chain->srcpad = gst_ghost_pad_new ("src", chain->vissrcpad);
2473 gst_element_add_pad (chain->chain.bin, chain->srcpad);
2480 post_missing_element_message (playsink, "queue");
2481 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
2482 (_("Missing element '%s' - check your GStreamer installation."),
2484 free_chain ((GstPlayChain *) chain);
2489 post_missing_element_message (playsink, "audioconvert");
2490 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
2491 (_("Missing element '%s' - check your GStreamer installation."),
2492 "audioconvert"), ("possibly a liboil version mismatch?"));
2493 free_chain ((GstPlayChain *) chain);
2498 post_missing_element_message (playsink, "audioresample");
2499 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
2500 (_("Missing element '%s' - check your GStreamer installation."),
2501 "audioresample"), (NULL));
2502 free_chain ((GstPlayChain *) chain);
2507 post_missing_element_message (playsink, "goom");
2508 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
2509 (_("Missing element '%s' - check your GStreamer installation."),
2511 free_chain ((GstPlayChain *) chain);
2516 GST_ELEMENT_ERROR (playsink, CORE, PAD,
2517 (NULL), ("Failed to configure the visualisation element."));
2518 /* element made it to READY */
2519 gst_element_set_state (chain->vis, GST_STATE_NULL);
2520 free_chain ((GstPlayChain *) chain);
2525 /* this function is called when all the request pads are requested and when we
2526 * have to construct the final pipeline. Based on the flags we construct the
2527 * final output pipelines.
2530 gst_play_sink_reconfigure (GstPlaySink * playsink)
2533 gboolean need_audio, need_video, need_deinterlace, need_vis, need_text;
2535 GST_DEBUG_OBJECT (playsink, "reconfiguring");
2537 /* assume we need nothing */
2538 need_audio = need_video = need_deinterlace = need_vis = need_text = FALSE;
2540 GST_PLAY_SINK_LOCK (playsink);
2541 GST_OBJECT_LOCK (playsink);
2542 /* get flags, there are protected with the object lock */
2543 flags = playsink->flags;
2544 GST_OBJECT_UNLOCK (playsink);
2546 /* figure out which components we need */
2547 if (flags & GST_PLAY_FLAG_TEXT && playsink->text_pad) {
2548 /* we have subtitles and we are requested to show it */
2552 GST_OBJECT_LOCK (playsink);
2553 if (playsink->overlay_element)
2554 gst_object_unref (playsink->overlay_element);
2555 playsink->overlay_element = NULL;
2557 if (playsink->colorbalance_element) {
2558 g_signal_handlers_disconnect_by_func (playsink->colorbalance_element,
2559 G_CALLBACK (colorbalance_value_changed_cb), playsink);
2560 gst_object_unref (playsink->colorbalance_element);
2562 playsink->colorbalance_element = NULL;
2563 GST_OBJECT_UNLOCK (playsink);
2565 if (((flags & GST_PLAY_FLAG_VIDEO)
2566 || (flags & GST_PLAY_FLAG_NATIVE_VIDEO)) && playsink->video_pad) {
2567 /* we have video and we are requested to show it */
2570 /* we only deinterlace if native video is not requested and
2571 * we have raw video */
2572 if ((flags & GST_PLAY_FLAG_DEINTERLACE)
2573 && !(flags & GST_PLAY_FLAG_NATIVE_VIDEO) && playsink->video_pad_raw)
2574 need_deinterlace = TRUE;
2577 if (playsink->audio_pad) {
2578 if ((flags & GST_PLAY_FLAG_AUDIO) || (flags & GST_PLAY_FLAG_NATIVE_AUDIO)) {
2581 if (playsink->audio_pad_raw) {
2582 /* only can do vis with raw uncompressed audio */
2583 if (flags & GST_PLAY_FLAG_VIS && !need_video) {
2584 /* also add video when we add visualisation */
2591 /* we have a text_pad and we need text rendering, in this case we need a
2592 * video_pad to combine the video with the text or visualizations */
2593 if (need_text && !need_video && !playsink->text_sink) {
2594 if (playsink->video_pad) {
2596 } else if (need_audio) {
2597 GST_ELEMENT_WARNING (playsink, STREAM, FORMAT,
2598 (_("Can't play a text file without video or visualizations.")),
2599 ("Have text pad but no video pad or visualizations"));
2602 GST_ELEMENT_ERROR (playsink, STREAM, FORMAT,
2603 (_("Can't play a text file without video or visualizations.")),
2604 ("Have text pad but no video pad or visualizations"));
2605 GST_PLAY_SINK_UNLOCK (playsink);
2610 GST_DEBUG_OBJECT (playsink, "audio:%d, video:%d, vis:%d, text:%d", need_audio,
2611 need_video, need_vis, need_text);
2613 /* set up video pipeline */
2615 gboolean raw, async;
2617 /* we need a raw sink when we do vis or when we have a raw pad */
2618 raw = need_vis ? TRUE : playsink->video_pad_raw;
2619 /* we try to set the sink async=FALSE when we need vis, this way we can
2620 * avoid a queue in the audio chain. */
2623 GST_DEBUG_OBJECT (playsink, "adding video, raw %d",
2624 playsink->video_pad_raw);
2626 if (playsink->videochain) {
2627 /* try to reactivate the chain */
2628 if (!setup_video_chain (playsink, raw, async)) {
2629 if (playsink->video_sinkpad_stream_synchronizer) {
2630 gst_element_release_request_pad (GST_ELEMENT_CAST
2631 (playsink->stream_synchronizer),
2632 playsink->video_sinkpad_stream_synchronizer);
2633 gst_object_unref (playsink->video_sinkpad_stream_synchronizer);
2634 playsink->video_sinkpad_stream_synchronizer = NULL;
2635 gst_object_unref (playsink->video_srcpad_stream_synchronizer);
2636 playsink->video_srcpad_stream_synchronizer = NULL;
2639 add_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE);
2641 /* Remove the sink from the bin to keep its state
2642 * and unparent it to allow reuse */
2643 if (playsink->videochain->sink)
2644 gst_bin_remove (GST_BIN_CAST (playsink->videochain->chain.bin),
2645 playsink->videochain->sink);
2647 activate_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE);
2648 free_chain ((GstPlayChain *) playsink->videochain);
2649 playsink->videochain = NULL;
2653 if (!playsink->videochain)
2654 playsink->videochain = gen_video_chain (playsink, raw, async);
2655 if (!playsink->videochain)
2658 if (!playsink->video_sinkpad_stream_synchronizer) {
2659 GValue item = { 0, };
2662 playsink->video_sinkpad_stream_synchronizer =
2663 gst_element_get_request_pad (GST_ELEMENT_CAST
2664 (playsink->stream_synchronizer), "sink_%u");
2665 it = gst_pad_iterate_internal_links
2666 (playsink->video_sinkpad_stream_synchronizer);
2668 gst_iterator_next (it, &item);
2669 playsink->video_srcpad_stream_synchronizer = g_value_dup_object (&item);
2670 g_value_unset (&item);
2671 g_assert (playsink->video_srcpad_stream_synchronizer);
2672 gst_iterator_free (it);
2675 if (playsink->video_pad)
2676 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (playsink->video_pad),
2677 playsink->video_sinkpad_stream_synchronizer);
2679 if (need_deinterlace) {
2680 if (!playsink->videodeinterlacechain)
2681 playsink->videodeinterlacechain =
2682 gen_video_deinterlace_chain (playsink);
2683 if (!playsink->videodeinterlacechain)
2686 GST_DEBUG_OBJECT (playsink, "adding video deinterlace chain");
2688 GST_DEBUG_OBJECT (playsink, "setting up deinterlacing chain");
2690 add_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain), TRUE);
2691 activate_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain), TRUE);
2693 gst_pad_link_full (playsink->video_srcpad_stream_synchronizer,
2694 playsink->videodeinterlacechain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2696 if (playsink->videodeinterlacechain) {
2697 add_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain), FALSE);
2698 activate_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain),
2703 GST_DEBUG_OBJECT (playsink, "adding video chain");
2704 add_chain (GST_PLAY_CHAIN (playsink->videochain), TRUE);
2705 activate_chain (GST_PLAY_CHAIN (playsink->videochain), TRUE);
2706 /* if we are not part of vis or subtitles, set the ghostpad target */
2707 if (!need_vis && !need_text && (!playsink->textchain
2708 || !playsink->text_pad)) {
2709 GST_DEBUG_OBJECT (playsink, "ghosting video sinkpad");
2710 if (need_deinterlace)
2711 gst_pad_link_full (playsink->videodeinterlacechain->srcpad,
2712 playsink->videochain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2714 gst_pad_link_full (playsink->video_srcpad_stream_synchronizer,
2715 playsink->videochain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2718 GST_DEBUG_OBJECT (playsink, "no video needed");
2719 if (playsink->videochain) {
2720 GST_DEBUG_OBJECT (playsink, "removing video chain");
2721 if (playsink->vischain) {
2724 GST_DEBUG_OBJECT (playsink, "unlinking vis chain");
2726 /* also had visualisation, release the tee srcpad before we then
2727 * unlink the video from it */
2728 if (playsink->audio_tee_vissrc) {
2729 gst_element_release_request_pad (playsink->audio_tee,
2730 playsink->audio_tee_vissrc);
2731 gst_object_unref (playsink->audio_tee_vissrc);
2732 playsink->audio_tee_vissrc = NULL;
2735 gst_element_get_static_pad (playsink->vischain->chain.bin, "src");
2736 gst_pad_unlink (srcpad, playsink->videochain->sinkpad);
2739 if (playsink->video_sinkpad_stream_synchronizer) {
2740 gst_element_release_request_pad (GST_ELEMENT_CAST
2741 (playsink->stream_synchronizer),
2742 playsink->video_sinkpad_stream_synchronizer);
2743 gst_object_unref (playsink->video_sinkpad_stream_synchronizer);
2744 playsink->video_sinkpad_stream_synchronizer = NULL;
2745 gst_object_unref (playsink->video_srcpad_stream_synchronizer);
2746 playsink->video_srcpad_stream_synchronizer = NULL;
2749 add_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE);
2750 activate_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE);
2751 if (playsink->videochain->ts_offset)
2752 gst_object_unref (playsink->videochain->ts_offset);
2753 playsink->videochain->ts_offset = NULL;
2756 if (playsink->videodeinterlacechain) {
2757 add_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain), FALSE);
2758 activate_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain), FALSE);
2761 if (playsink->video_pad)
2762 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (playsink->video_pad), NULL);
2768 GST_DEBUG_OBJECT (playsink, "adding audio");
2770 /* get a raw sink if we are asked for a raw pad */
2771 raw = playsink->audio_pad_raw;
2773 if (playsink->audiochain) {
2774 /* try to reactivate the chain */
2775 if (!setup_audio_chain (playsink, raw)) {
2776 GST_DEBUG_OBJECT (playsink, "removing current audio chain");
2777 if (playsink->audio_tee_asrc) {
2778 gst_element_release_request_pad (playsink->audio_tee,
2779 playsink->audio_tee_asrc);
2780 gst_object_unref (playsink->audio_tee_asrc);
2781 playsink->audio_tee_asrc = NULL;
2784 if (playsink->audio_sinkpad_stream_synchronizer) {
2785 gst_element_release_request_pad (GST_ELEMENT_CAST
2786 (playsink->stream_synchronizer),
2787 playsink->audio_sinkpad_stream_synchronizer);
2788 gst_object_unref (playsink->audio_sinkpad_stream_synchronizer);
2789 playsink->audio_sinkpad_stream_synchronizer = NULL;
2790 gst_object_unref (playsink->audio_srcpad_stream_synchronizer);
2791 playsink->audio_srcpad_stream_synchronizer = NULL;
2794 add_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE);
2796 /* Remove the sink from the bin to keep its state
2797 * and unparent it to allow reuse */
2798 if (playsink->audiochain->sink)
2799 gst_bin_remove (GST_BIN_CAST (playsink->audiochain->chain.bin),
2800 playsink->audiochain->sink);
2802 activate_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE);
2803 disconnect_chain (playsink->audiochain, playsink);
2804 playsink->audiochain->volume = NULL;
2805 playsink->audiochain->mute = NULL;
2806 if (playsink->audiochain->ts_offset)
2807 gst_object_unref (playsink->audiochain->ts_offset);
2808 playsink->audiochain->ts_offset = NULL;
2809 free_chain ((GstPlayChain *) playsink->audiochain);
2810 playsink->audiochain = NULL;
2811 playsink->volume_changed = playsink->mute_changed = FALSE;
2815 if (!playsink->audiochain) {
2816 GST_DEBUG_OBJECT (playsink, "creating new audio chain");
2817 playsink->audiochain = gen_audio_chain (playsink, raw);
2820 if (!playsink->audio_sinkpad_stream_synchronizer) {
2821 GValue item = { 0, };
2824 playsink->audio_sinkpad_stream_synchronizer =
2825 gst_element_get_request_pad (GST_ELEMENT_CAST
2826 (playsink->stream_synchronizer), "sink_%u");
2827 it = gst_pad_iterate_internal_links
2828 (playsink->audio_sinkpad_stream_synchronizer);
2830 gst_iterator_next (it, &item);
2831 playsink->audio_srcpad_stream_synchronizer = g_value_dup_object (&item);
2832 g_value_unset (&item);
2833 g_assert (playsink->audio_srcpad_stream_synchronizer);
2834 gst_iterator_free (it);
2837 if (playsink->audiochain) {
2838 GST_DEBUG_OBJECT (playsink, "adding audio chain");
2839 if (playsink->audio_tee_asrc == NULL) {
2840 playsink->audio_tee_asrc =
2841 gst_element_get_request_pad (playsink->audio_tee, "src_%u");
2843 add_chain (GST_PLAY_CHAIN (playsink->audiochain), TRUE);
2844 activate_chain (GST_PLAY_CHAIN (playsink->audiochain), TRUE);
2845 gst_pad_link_full (playsink->audio_tee_asrc,
2846 playsink->audio_sinkpad_stream_synchronizer,
2847 GST_PAD_LINK_CHECK_NOTHING);
2848 gst_pad_link_full (playsink->audio_srcpad_stream_synchronizer,
2849 playsink->audiochain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2852 GST_DEBUG_OBJECT (playsink, "no audio needed");
2853 /* we have no audio or we are requested to not play audio */
2854 if (playsink->audiochain) {
2855 GST_DEBUG_OBJECT (playsink, "removing audio chain");
2856 /* release the audio pad */
2857 if (playsink->audio_tee_asrc) {
2858 gst_element_release_request_pad (playsink->audio_tee,
2859 playsink->audio_tee_asrc);
2860 gst_object_unref (playsink->audio_tee_asrc);
2861 playsink->audio_tee_asrc = NULL;
2864 if (playsink->audio_sinkpad_stream_synchronizer) {
2865 gst_element_release_request_pad (GST_ELEMENT_CAST
2866 (playsink->stream_synchronizer),
2867 playsink->audio_sinkpad_stream_synchronizer);
2868 gst_object_unref (playsink->audio_sinkpad_stream_synchronizer);
2869 playsink->audio_sinkpad_stream_synchronizer = NULL;
2870 gst_object_unref (playsink->audio_srcpad_stream_synchronizer);
2871 playsink->audio_srcpad_stream_synchronizer = NULL;
2874 if (playsink->audiochain->sink_volume) {
2875 disconnect_chain (playsink->audiochain, playsink);
2876 playsink->audiochain->volume = NULL;
2877 playsink->audiochain->mute = NULL;
2878 if (playsink->audiochain->ts_offset)
2879 gst_object_unref (playsink->audiochain->ts_offset);
2880 playsink->audiochain->ts_offset = NULL;
2882 add_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE);
2883 activate_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE);
2890 if (!playsink->vischain)
2891 playsink->vischain = gen_vis_chain (playsink);
2893 GST_DEBUG_OBJECT (playsink, "adding visualisation");
2895 if (playsink->vischain) {
2896 GST_DEBUG_OBJECT (playsink, "setting up vis chain");
2898 gst_element_get_static_pad (playsink->vischain->chain.bin, "src");
2899 add_chain (GST_PLAY_CHAIN (playsink->vischain), TRUE);
2900 activate_chain (GST_PLAY_CHAIN (playsink->vischain), TRUE);
2901 if (playsink->audio_tee_vissrc == NULL) {
2902 playsink->audio_tee_vissrc =
2903 gst_element_get_request_pad (playsink->audio_tee, "src_%u");
2905 gst_pad_link_full (playsink->audio_tee_vissrc,
2906 playsink->vischain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2907 gst_pad_link_full (srcpad, playsink->video_sinkpad_stream_synchronizer,
2908 GST_PAD_LINK_CHECK_NOTHING);
2909 gst_pad_link_full (playsink->video_srcpad_stream_synchronizer,
2910 playsink->videochain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2911 gst_object_unref (srcpad);
2914 GST_DEBUG_OBJECT (playsink, "no vis needed");
2915 if (playsink->vischain) {
2916 if (playsink->audio_tee_vissrc) {
2917 gst_element_release_request_pad (playsink->audio_tee,
2918 playsink->audio_tee_vissrc);
2919 gst_object_unref (playsink->audio_tee_vissrc);
2920 playsink->audio_tee_vissrc = NULL;
2922 GST_DEBUG_OBJECT (playsink, "removing vis chain");
2923 add_chain (GST_PLAY_CHAIN (playsink->vischain), FALSE);
2924 activate_chain (GST_PLAY_CHAIN (playsink->vischain), FALSE);
2929 GST_DEBUG_OBJECT (playsink, "adding text");
2930 if (!playsink->textchain) {
2931 GST_DEBUG_OBJECT (playsink, "creating text chain");
2932 playsink->textchain = gen_text_chain (playsink);
2934 if (playsink->textchain) {
2937 GST_DEBUG_OBJECT (playsink, "adding text chain");
2938 if (playsink->textchain->overlay)
2939 g_object_set (G_OBJECT (playsink->textchain->overlay), "silent", FALSE,
2941 add_chain (GST_PLAY_CHAIN (playsink->textchain), TRUE);
2943 if (!playsink->text_sinkpad_stream_synchronizer) {
2944 GValue item = { 0, };
2946 playsink->text_sinkpad_stream_synchronizer =
2947 gst_element_get_request_pad (GST_ELEMENT_CAST
2948 (playsink->stream_synchronizer), "sink_%u");
2949 it = gst_pad_iterate_internal_links
2950 (playsink->text_sinkpad_stream_synchronizer);
2952 gst_iterator_next (it, &item);
2953 playsink->text_srcpad_stream_synchronizer = g_value_dup_object (&item);
2954 g_value_unset (&item);
2955 g_assert (playsink->text_srcpad_stream_synchronizer);
2956 gst_iterator_free (it);
2958 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (playsink->text_pad),
2959 playsink->text_sinkpad_stream_synchronizer);
2960 gst_pad_link_full (playsink->text_srcpad_stream_synchronizer,
2961 playsink->textchain->textsinkpad, GST_PAD_LINK_CHECK_NOTHING);
2964 if (need_vis || need_video) {
2969 gst_element_get_static_pad (playsink->vischain->chain.bin, "src");
2970 gst_pad_unlink (srcpad, playsink->videochain->sinkpad);
2971 gst_pad_link_full (srcpad, playsink->textchain->videosinkpad,
2972 GST_PAD_LINK_CHECK_NOTHING);
2973 gst_object_unref (srcpad);
2975 if (need_deinterlace)
2976 gst_pad_link_full (playsink->videodeinterlacechain->srcpad,
2977 playsink->textchain->videosinkpad, GST_PAD_LINK_CHECK_NOTHING);
2979 gst_pad_link_full (playsink->video_srcpad_stream_synchronizer,
2980 playsink->textchain->videosinkpad, GST_PAD_LINK_CHECK_NOTHING);
2982 gst_pad_link_full (playsink->textchain->srcpad,
2983 playsink->videochain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2986 activate_chain (GST_PLAY_CHAIN (playsink->textchain), TRUE);
2989 GST_DEBUG_OBJECT (playsink, "no text needed");
2990 /* we have no subtitles/text or we are requested to not show them */
2992 if (playsink->text_sinkpad_stream_synchronizer) {
2993 gst_element_release_request_pad (GST_ELEMENT_CAST
2994 (playsink->stream_synchronizer),
2995 playsink->text_sinkpad_stream_synchronizer);
2996 gst_object_unref (playsink->text_sinkpad_stream_synchronizer);
2997 playsink->text_sinkpad_stream_synchronizer = NULL;
2998 gst_object_unref (playsink->text_srcpad_stream_synchronizer);
2999 playsink->text_srcpad_stream_synchronizer = NULL;
3002 if (playsink->textchain) {
3003 if (playsink->text_pad == NULL) {
3004 /* no text pad, remove the chain entirely */
3005 GST_DEBUG_OBJECT (playsink, "removing text chain");
3006 add_chain (GST_PLAY_CHAIN (playsink->textchain), FALSE);
3007 activate_chain (GST_PLAY_CHAIN (playsink->textchain), FALSE);
3009 /* we have a chain and a textpad, turn the subtitles off */
3010 GST_DEBUG_OBJECT (playsink, "turning off the text");
3011 if (playsink->textchain->overlay)
3012 g_object_set (G_OBJECT (playsink->textchain->overlay), "silent", TRUE,
3016 if (!need_video && playsink->video_pad) {
3017 if (playsink->video_sinkpad_stream_synchronizer) {
3018 gst_element_release_request_pad (GST_ELEMENT_CAST
3019 (playsink->stream_synchronizer),
3020 playsink->video_sinkpad_stream_synchronizer);
3021 gst_object_unref (playsink->video_sinkpad_stream_synchronizer);
3022 playsink->video_sinkpad_stream_synchronizer = NULL;
3023 gst_object_unref (playsink->video_srcpad_stream_synchronizer);
3024 playsink->video_srcpad_stream_synchronizer = NULL;
3027 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (playsink->video_pad), NULL);
3030 if (playsink->text_pad && !playsink->textchain)
3031 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (playsink->text_pad), NULL);
3033 update_av_offset (playsink);
3034 do_async_done (playsink);
3035 GST_PLAY_SINK_UNLOCK (playsink);
3042 /* gen_ chain already posted error */
3043 GST_DEBUG_OBJECT (playsink, "failed to setup chain");
3044 GST_PLAY_SINK_UNLOCK (playsink);
3050 * gst_play_sink_set_flags:
3051 * @playsink: a #GstPlaySink
3052 * @flags: #GstPlayFlags
3054 * Configure @flags on @playsink. The flags control the behaviour of @playsink
3055 * when constructing the sink pipelins.
3057 * Returns: TRUE if the flags could be configured.
3060 gst_play_sink_set_flags (GstPlaySink * playsink, GstPlayFlags flags)
3062 g_return_val_if_fail (GST_IS_PLAY_SINK (playsink), FALSE);
3064 GST_OBJECT_LOCK (playsink);
3065 playsink->flags = flags;
3066 GST_OBJECT_UNLOCK (playsink);
3072 * gst_play_sink_get_flags:
3073 * @playsink: a #GstPlaySink
3075 * Get the flags of @playsink. That flags control the behaviour of the sink when
3076 * it constructs the sink pipelines.
3078 * Returns: the currently configured #GstPlayFlags.
3081 gst_play_sink_get_flags (GstPlaySink * playsink)
3085 g_return_val_if_fail (GST_IS_PLAY_SINK (playsink), 0);
3087 GST_OBJECT_LOCK (playsink);
3088 res = playsink->flags;
3089 GST_OBJECT_UNLOCK (playsink);
3095 gst_play_sink_set_font_desc (GstPlaySink * playsink, const gchar * desc)
3097 GstPlayTextChain *chain;
3099 GST_PLAY_SINK_LOCK (playsink);
3100 chain = (GstPlayTextChain *) playsink->textchain;
3101 g_free (playsink->font_desc);
3102 playsink->font_desc = g_strdup (desc);
3103 if (chain && chain->overlay) {
3104 g_object_set (chain->overlay, "font-desc", desc, NULL);
3106 GST_PLAY_SINK_UNLOCK (playsink);
3110 gst_play_sink_get_font_desc (GstPlaySink * playsink)
3112 gchar *result = NULL;
3113 GstPlayTextChain *chain;
3115 GST_PLAY_SINK_LOCK (playsink);
3116 chain = (GstPlayTextChain *) playsink->textchain;
3117 if (chain && chain->overlay) {
3118 g_object_get (chain->overlay, "font-desc", &result, NULL);
3119 playsink->font_desc = g_strdup (result);
3121 result = g_strdup (playsink->font_desc);
3123 GST_PLAY_SINK_UNLOCK (playsink);
3129 gst_play_sink_set_subtitle_encoding (GstPlaySink * playsink,
3130 const gchar * encoding)
3132 GstPlayTextChain *chain;
3134 GST_PLAY_SINK_LOCK (playsink);
3135 chain = (GstPlayTextChain *) playsink->textchain;
3136 g_free (playsink->subtitle_encoding);
3137 playsink->subtitle_encoding = g_strdup (encoding);
3138 if (chain && chain->overlay) {
3139 g_object_set (chain->overlay, "subtitle-encoding", encoding, NULL);
3141 GST_PLAY_SINK_UNLOCK (playsink);
3145 gst_play_sink_get_subtitle_encoding (GstPlaySink * playsink)
3147 gchar *result = NULL;
3148 GstPlayTextChain *chain;
3150 GST_PLAY_SINK_LOCK (playsink);
3151 chain = (GstPlayTextChain *) playsink->textchain;
3152 if (chain && chain->overlay) {
3153 g_object_get (chain->overlay, "subtitle-encoding", &result, NULL);
3154 playsink->subtitle_encoding = g_strdup (result);
3156 result = g_strdup (playsink->subtitle_encoding);
3158 GST_PLAY_SINK_UNLOCK (playsink);
3164 update_av_offset (GstPlaySink * playsink)
3167 GstPlayAudioChain *achain;
3168 GstPlayVideoChain *vchain;
3170 av_offset = playsink->av_offset;
3171 achain = (GstPlayAudioChain *) playsink->audiochain;
3172 vchain = (GstPlayVideoChain *) playsink->videochain;
3174 if (achain && vchain && achain->ts_offset && vchain->ts_offset) {
3175 g_object_set (achain->ts_offset, "ts-offset", MAX (0, -av_offset), NULL);
3176 g_object_set (vchain->ts_offset, "ts-offset", MAX (0, av_offset), NULL);
3178 GST_LOG_OBJECT (playsink, "no ts_offset elements");
3183 gst_play_sink_set_av_offset (GstPlaySink * playsink, gint64 av_offset)
3185 GST_PLAY_SINK_LOCK (playsink);
3186 playsink->av_offset = av_offset;
3187 update_av_offset (playsink);
3188 GST_PLAY_SINK_UNLOCK (playsink);
3192 gst_play_sink_get_av_offset (GstPlaySink * playsink)
3196 GST_PLAY_SINK_LOCK (playsink);
3197 result = playsink->av_offset;
3198 GST_PLAY_SINK_UNLOCK (playsink);
3204 * gst_play_sink_get_last_sample:
3205 * @playsink: a #GstPlaySink
3207 * Get the last displayed sample from @playsink. This sample is in the native
3208 * format of the sink element, the caps in the result sample contain the format
3209 * of the frame data.
3211 * Returns: a #GstSample with the frame data or %NULL when no video frame is
3215 gst_play_sink_get_last_sample (GstPlaySink * playsink)
3217 GstSample *result = NULL;
3218 GstPlayVideoChain *chain;
3220 GST_PLAY_SINK_LOCK (playsink);
3221 GST_DEBUG_OBJECT (playsink, "taking last sample");
3222 /* get the video chain if we can */
3223 if ((chain = (GstPlayVideoChain *) playsink->videochain)) {
3224 GST_DEBUG_OBJECT (playsink, "found video chain");
3225 /* see if the chain is active */
3226 if (chain->chain.activated && chain->sink) {
3229 GST_DEBUG_OBJECT (playsink, "video chain active and has a sink");
3231 /* find and get the last-buffer property now */
3233 gst_play_sink_find_property (playsink, chain->sink,
3234 "last-sample", GST_TYPE_SAMPLE))) {
3235 GST_DEBUG_OBJECT (playsink, "getting last-sample property");
3236 g_object_get (elem, "last-sample", &result, NULL);
3237 gst_object_unref (elem);
3241 GST_PLAY_SINK_UNLOCK (playsink);
3247 * gst_play_sink_convert_sample:
3248 * @playsink: a #GstPlaySink
3251 * Get the last displayed frame from @playsink. If caps is %NULL, the video will
3252 * be in the native format of the sink element and the caps on the buffer
3253 * describe the format of the frame. If @caps is not %NULL, the video
3254 * frame will be converted to the format of the caps.
3256 * Returns: a #GstBuffer with the frame data or %NULL when no video frame is
3257 * available or when the conversion failed.
3260 gst_play_sink_convert_sample (GstPlaySink * playsink, GstCaps * caps)
3265 result = gst_play_sink_get_last_sample (playsink);
3266 if (result != NULL && caps != NULL) {
3269 temp = gst_video_convert_sample (result, caps, 25 * GST_SECOND, &err);
3270 if (temp == NULL && err)
3273 gst_sample_unref (result);
3281 /* I'm really uncertain whether we should make playsink post an error
3282 * on the bus or not. It's not like it's a critical issue regarding
3283 * playsink behaviour. */
3284 GST_ERROR ("Error converting frame: %s", err->message);
3285 gst_sample_unref (result);
3292 is_raw_structure (GstStructure * s)
3296 name = gst_structure_get_name (s);
3298 if (g_str_equal (name, "video/x-raw") || g_str_equal (name, "audio/x-raw"))
3304 is_raw_pad (GstPad * pad)
3306 GstPad *peer = gst_pad_get_peer (pad);
3308 gboolean raw = TRUE;
3313 caps = gst_pad_get_current_caps (peer);
3317 caps = gst_pad_query_caps (peer, NULL);
3319 n = gst_caps_get_size (caps);
3320 for (i = 0; i < n; i++) {
3321 gboolean r = is_raw_structure (gst_caps_get_structure (caps, i));
3325 } else if (raw != r) {
3326 GST_ERROR_OBJECT (pad,
3327 "Caps contains raw and non-raw structures: %" GST_PTR_FORMAT, caps);
3333 raw = is_raw_structure (gst_caps_get_structure (caps, 0));
3335 gst_caps_unref (caps);
3336 gst_object_unref (peer);
3341 static GstPadProbeReturn
3342 sinkpad_blocked_cb (GstPad * blockedpad, GstPadProbeInfo * info,
3343 gpointer user_data);
3346 video_set_blocked (GstPlaySink * playsink, gboolean blocked)
3348 if (playsink->video_pad) {
3350 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3351 (playsink->video_pad)));
3352 if (blocked && playsink->video_block_id == 0) {
3353 playsink->video_block_id =
3354 gst_pad_add_probe (opad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
3355 sinkpad_blocked_cb, playsink, NULL);
3356 } else if (!blocked && playsink->video_block_id) {
3357 gst_pad_remove_probe (opad, playsink->video_block_id);
3358 PENDING_FLAG_UNSET (playsink, GST_PLAY_SINK_TYPE_VIDEO_RAW);
3359 PENDING_FLAG_UNSET (playsink, GST_PLAY_SINK_TYPE_VIDEO);
3360 playsink->video_block_id = 0;
3361 playsink->video_pad_blocked = FALSE;
3363 gst_object_unref (opad);
3368 audio_set_blocked (GstPlaySink * playsink, gboolean blocked)
3370 if (playsink->audio_pad) {
3372 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3373 (playsink->audio_pad)));
3374 if (blocked && playsink->audio_block_id == 0) {
3375 playsink->audio_block_id =
3376 gst_pad_add_probe (opad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
3377 sinkpad_blocked_cb, playsink, NULL);
3378 } else if (!blocked && playsink->audio_block_id) {
3379 gst_pad_remove_probe (opad, playsink->audio_block_id);
3380 PENDING_FLAG_UNSET (playsink, GST_PLAY_SINK_TYPE_AUDIO_RAW);
3381 PENDING_FLAG_UNSET (playsink, GST_PLAY_SINK_TYPE_AUDIO);
3382 playsink->audio_block_id = 0;
3383 playsink->audio_pad_blocked = FALSE;
3385 gst_object_unref (opad);
3390 text_set_blocked (GstPlaySink * playsink, gboolean blocked)
3392 if (playsink->text_pad) {
3394 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3395 (playsink->text_pad)));
3396 if (blocked && playsink->text_block_id == 0) {
3397 playsink->text_block_id =
3398 gst_pad_add_probe (opad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
3399 sinkpad_blocked_cb, playsink, NULL);
3400 } else if (!blocked && playsink->text_block_id) {
3401 gst_pad_remove_probe (opad, playsink->text_block_id);
3402 PENDING_FLAG_UNSET (playsink, GST_PLAY_SINK_TYPE_TEXT);
3403 playsink->text_block_id = 0;
3404 playsink->text_pad_blocked = FALSE;
3406 gst_object_unref (opad);
3410 static GstPadProbeReturn
3411 sinkpad_blocked_cb (GstPad * blockedpad, GstPadProbeInfo * info,
3414 GstPlaySink *playsink = (GstPlaySink *) user_data;
3417 GST_PLAY_SINK_LOCK (playsink);
3419 pad = GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD (blockedpad)));
3420 if (pad == playsink->video_pad) {
3421 playsink->video_pad_blocked = TRUE;
3422 GST_DEBUG_OBJECT (pad, "Video pad blocked");
3423 } else if (pad == playsink->audio_pad) {
3424 playsink->audio_pad_blocked = TRUE;
3425 GST_DEBUG_OBJECT (pad, "Audio pad blocked");
3426 } else if (pad == playsink->text_pad) {
3427 playsink->text_pad_blocked = TRUE;
3428 GST_DEBUG_OBJECT (pad, "Text pad blocked");
3431 /* We reconfigure when for ALL streams:
3432 * * there isn't a pad
3433 * * OR the pad is blocked
3434 * * OR there are no pending blocks on that pad
3437 if ((!playsink->video_pad || playsink->video_pad_blocked
3438 || !PENDING_VIDEO_BLOCK (playsink)) && (!playsink->audio_pad
3439 || playsink->audio_pad_blocked || !PENDING_AUDIO_BLOCK (playsink))
3440 && (!playsink->text_pad || playsink->text_pad_blocked
3441 || !PENDING_TEXT_BLOCK (playsink))) {
3442 GST_DEBUG_OBJECT (playsink, "All pads blocked -- reconfiguring");
3444 if (playsink->video_pad) {
3445 playsink->video_pad_raw = is_raw_pad (playsink->video_pad);
3446 GST_DEBUG_OBJECT (playsink, "Video pad is raw: %d",
3447 playsink->video_pad_raw);
3450 if (playsink->audio_pad) {
3451 playsink->audio_pad_raw = is_raw_pad (playsink->audio_pad);
3452 GST_DEBUG_OBJECT (playsink, "Audio pad is raw: %d",
3453 playsink->audio_pad_raw);
3456 gst_play_sink_reconfigure (playsink);
3458 video_set_blocked (playsink, FALSE);
3459 audio_set_blocked (playsink, FALSE);
3460 text_set_blocked (playsink, FALSE);
3463 gst_object_unref (pad);
3465 GST_PLAY_SINK_UNLOCK (playsink);
3467 return GST_PAD_PROBE_OK;
3471 caps_notify_cb (GstPad * pad, GParamSpec * unused, GstPlaySink * playsink)
3473 gboolean reconfigure = FALSE;
3477 g_object_get (pad, "caps", &caps, NULL);
3481 if (pad == playsink->audio_pad) {
3482 raw = is_raw_pad (pad);
3483 reconfigure = (! !playsink->audio_pad_raw != ! !raw)
3484 && playsink->audiochain;
3485 GST_DEBUG_OBJECT (pad,
3486 "Audio caps changed: raw %d reconfigure %d caps %" GST_PTR_FORMAT, raw,
3488 } else if (pad == playsink->video_pad) {
3489 raw = is_raw_pad (pad);
3490 reconfigure = (! !playsink->video_pad_raw != ! !raw)
3491 && playsink->videochain;
3492 GST_DEBUG_OBJECT (pad,
3493 "Video caps changed: raw %d reconfigure %d caps %" GST_PTR_FORMAT, raw,
3497 gst_caps_unref (caps);
3500 GST_PLAY_SINK_LOCK (playsink);
3501 video_set_blocked (playsink, TRUE);
3502 audio_set_blocked (playsink, TRUE);
3503 text_set_blocked (playsink, TRUE);
3504 GST_PLAY_SINK_UNLOCK (playsink);
3509 * gst_play_sink_request_pad
3510 * @playsink: a #GstPlaySink
3511 * @type: a #GstPlaySinkType
3513 * Create or return a pad of @type.
3515 * Returns: a #GstPad of @type or %NULL when the pad could not be created.
3518 gst_play_sink_request_pad (GstPlaySink * playsink, GstPlaySinkType type)
3521 gboolean created = FALSE;
3522 gboolean activate = TRUE;
3523 const gchar *pad_name = NULL;
3524 gulong *block_id = NULL;
3526 GST_DEBUG_OBJECT (playsink, "request pad type %d", type);
3528 GST_PLAY_SINK_LOCK (playsink);
3530 case GST_PLAY_SINK_TYPE_AUDIO_RAW:
3531 case GST_PLAY_SINK_TYPE_AUDIO:
3532 pad_name = "audio_sink";
3533 if (!playsink->audio_tee) {
3534 GST_LOG_OBJECT (playsink, "creating tee");
3535 /* create tee when needed. This element will feed the audio sink chain
3536 * and the vis chain. */
3537 playsink->audio_tee = gst_element_factory_make ("tee", "audiotee");
3538 if (playsink->audio_tee == NULL) {
3539 post_missing_element_message (playsink, "tee");
3540 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
3541 (_("Missing element '%s' - check your GStreamer installation."),
3546 playsink->audio_tee_sink =
3547 gst_element_get_static_pad (playsink->audio_tee, "sink");
3548 gst_bin_add (GST_BIN_CAST (playsink), playsink->audio_tee);
3549 gst_element_set_state (playsink->audio_tee, GST_STATE_PAUSED);
3552 gst_element_set_state (playsink->audio_tee, GST_STATE_PAUSED);
3554 if (!playsink->audio_pad) {
3555 GST_LOG_OBJECT (playsink, "ghosting tee sinkpad");
3556 playsink->audio_pad =
3557 gst_ghost_pad_new (pad_name, playsink->audio_tee_sink);
3558 g_signal_connect (G_OBJECT (playsink->audio_pad), "notify::caps",
3559 G_CALLBACK (caps_notify_cb), playsink);
3562 playsink->audio_pad_raw = FALSE;
3563 res = playsink->audio_pad;
3564 block_id = &playsink->audio_block_id;
3566 case GST_PLAY_SINK_TYPE_VIDEO_RAW:
3567 case GST_PLAY_SINK_TYPE_VIDEO:
3568 pad_name = "video_sink";
3569 if (!playsink->video_pad) {
3570 GST_LOG_OBJECT (playsink, "ghosting videosink");
3571 playsink->video_pad =
3572 gst_ghost_pad_new_no_target (pad_name, GST_PAD_SINK);
3573 g_signal_connect (G_OBJECT (playsink->video_pad), "notify::caps",
3574 G_CALLBACK (caps_notify_cb), playsink);
3577 playsink->video_pad_raw = FALSE;
3578 res = playsink->video_pad;
3579 block_id = &playsink->video_block_id;
3581 case GST_PLAY_SINK_TYPE_TEXT:
3582 GST_LOG_OBJECT (playsink, "ghosting text");
3583 if (!playsink->text_pad) {
3584 playsink->text_pad =
3585 gst_ghost_pad_new_no_target ("text_sink", GST_PAD_SINK);
3588 res = playsink->text_pad;
3589 block_id = &playsink->text_block_id;
3591 case GST_PLAY_SINK_TYPE_FLUSHING:
3595 /* we need a unique padname for the flushing pad. */
3596 padname = g_strdup_printf ("flushing_%u", playsink->count);
3597 res = gst_ghost_pad_new_no_target (padname, GST_PAD_SINK);
3608 GST_PLAY_SINK_UNLOCK (playsink);
3610 if (created && res) {
3611 /* we have to add the pad when it's active or we get an error when the
3612 * element is 'running' */
3613 gst_pad_set_active (res, TRUE);
3614 gst_element_add_pad (GST_ELEMENT_CAST (playsink), res);
3615 if (block_id && *block_id == 0) {
3617 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD (res)));
3620 gst_pad_add_probe (blockpad, GST_PAD_PROBE_TYPE_BLOCK_DOWNSTREAM,
3621 sinkpad_blocked_cb, playsink, NULL);
3622 PENDING_FLAG_SET (playsink, type);
3623 gst_object_unref (blockpad);
3626 gst_pad_set_active (res, activate);
3633 gst_play_sink_request_new_pad (GstElement * element, GstPadTemplate * templ,
3634 const gchar * name, const GstCaps * caps)
3638 GstPlaySinkType type;
3639 const gchar *tplname;
3641 g_return_val_if_fail (templ != NULL, NULL);
3643 GST_DEBUG_OBJECT (element, "name:%s", name);
3645 psink = GST_PLAY_SINK (element);
3646 tplname = GST_PAD_TEMPLATE_NAME_TEMPLATE (templ);
3648 /* Figure out the GstPlaySinkType based on the template */
3649 if (!strcmp (tplname, "audio_sink"))
3650 type = GST_PLAY_SINK_TYPE_AUDIO;
3651 else if (!strcmp (tplname, "audio_raw_sink"))
3652 type = GST_PLAY_SINK_TYPE_AUDIO_RAW;
3653 else if (!strcmp (tplname, "video_sink"))
3654 type = GST_PLAY_SINK_TYPE_VIDEO;
3655 else if (!strcmp (tplname, "video_raw_sink"))
3656 type = GST_PLAY_SINK_TYPE_VIDEO_RAW;
3657 else if (!strcmp (tplname, "text_sink"))
3658 type = GST_PLAY_SINK_TYPE_TEXT;
3660 goto unknown_template;
3662 pad = gst_play_sink_request_pad (psink, type);
3666 GST_WARNING_OBJECT (element, "Unknown pad template");
3671 gst_play_sink_release_pad (GstPlaySink * playsink, GstPad * pad)
3673 GstPad **res = NULL;
3674 gboolean untarget = TRUE;
3676 GST_DEBUG_OBJECT (playsink, "release pad %" GST_PTR_FORMAT, pad);
3678 GST_PLAY_SINK_LOCK (playsink);
3679 if (pad == playsink->video_pad) {
3680 res = &playsink->video_pad;
3681 g_signal_handlers_disconnect_by_func (playsink->video_pad, caps_notify_cb,
3683 } else if (pad == playsink->audio_pad) {
3684 res = &playsink->audio_pad;
3685 g_signal_handlers_disconnect_by_func (playsink->audio_pad, caps_notify_cb,
3687 } else if (pad == playsink->text_pad) {
3688 res = &playsink->text_pad;
3690 /* try to release the given pad anyway, these could be the FLUSHING pads. */
3694 GST_PLAY_SINK_UNLOCK (playsink);
3697 GST_DEBUG_OBJECT (playsink, "deactivate pad %" GST_PTR_FORMAT, *res);
3698 gst_pad_set_active (*res, FALSE);
3700 GST_DEBUG_OBJECT (playsink, "untargeting pad %" GST_PTR_FORMAT, *res);
3701 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (*res), NULL);
3703 GST_DEBUG_OBJECT (playsink, "remove pad %" GST_PTR_FORMAT, *res);
3704 gst_element_remove_pad (GST_ELEMENT_CAST (playsink), *res);
3710 gst_play_sink_release_request_pad (GstElement * element, GstPad * pad)
3712 GstPlaySink *psink = GST_PLAY_SINK (element);
3714 gst_play_sink_release_pad (psink, pad);
3718 gst_play_sink_handle_message (GstBin * bin, GstMessage * message)
3720 GstPlaySink *playsink;
3722 playsink = GST_PLAY_SINK_CAST (bin);
3724 switch (GST_MESSAGE_TYPE (message)) {
3725 case GST_MESSAGE_STEP_DONE:
3730 gboolean flush, intermediate, eos;
3733 GST_INFO_OBJECT (playsink, "Handling step-done message");
3734 gst_message_parse_step_done (message, &format, &amount, &rate, &flush,
3735 &intermediate, &duration, &eos);
3737 if (format == GST_FORMAT_BUFFERS) {
3738 /* for the buffer format, we align the other streams */
3739 if (playsink->audiochain) {
3743 gst_event_new_step (GST_FORMAT_TIME, duration, rate, flush,
3746 if (!gst_element_send_event (playsink->audiochain->chain.bin, event)) {
3747 GST_DEBUG_OBJECT (playsink, "Event failed when sent to audio sink");
3751 GST_BIN_CLASS (gst_play_sink_parent_class)->handle_message (bin, message);
3754 case GST_MESSAGE_ELEMENT:{
3755 if (gst_is_video_overlay_prepare_window_handle_message (message)) {
3756 GstVideoOverlay *overlay;
3758 GST_OBJECT_LOCK (playsink);
3759 if (playsink->overlay_element
3760 && GST_OBJECT_CAST (playsink->overlay_element) !=
3761 GST_MESSAGE_SRC (message)) {
3762 gst_object_unref (playsink->overlay_element);
3763 playsink->overlay_element = NULL;
3766 if (!playsink->overlay_element)
3767 playsink->overlay_element =
3768 GST_VIDEO_OVERLAY (gst_object_ref (GST_MESSAGE_SRC (message)));
3770 GST_VIDEO_OVERLAY (gst_object_ref (playsink->overlay_element));
3771 GST_OBJECT_UNLOCK (playsink);
3773 GST_DEBUG_OBJECT (playsink, "Got prepare-xwindow-id message");
3775 if (playsink->overlay_handle_set)
3776 gst_video_overlay_set_window_handle (playsink->overlay_element,
3777 playsink->overlay_handle);
3778 if (playsink->overlay_handle_events_set)
3779 gst_video_overlay_handle_events (playsink->overlay_element,
3780 playsink->overlay_handle_events);
3781 if (playsink->overlay_render_rectangle_set)
3782 gst_video_overlay_set_render_rectangle (playsink->overlay_element,
3783 playsink->overlay_x, playsink->overlay_y,
3784 playsink->overlay_width, playsink->overlay_height);
3786 gst_object_unref (overlay);
3787 gst_message_unref (message);
3788 gst_video_overlay_prepare_window_handle (GST_VIDEO_OVERLAY (playsink));
3790 GST_BIN_CLASS (gst_play_sink_parent_class)->handle_message (bin,
3796 GST_BIN_CLASS (gst_play_sink_parent_class)->handle_message (bin, message);
3801 /* Send an event to our sinks until one of them works; don't then send to the
3802 * remaining sinks (unlike GstBin)
3803 * Special case: If a text sink is set we need to send the event
3804 * to them in case it's source is different from the a/v stream's source.
3807 gst_play_sink_send_event_to_sink (GstPlaySink * playsink, GstEvent * event)
3809 gboolean res = TRUE;
3810 if (playsink->send_event_mode == MODE_FIRST) {
3811 if (playsink->textchain && playsink->textchain->sink) {
3812 gst_event_ref (event);
3814 gst_element_send_event (playsink->textchain->chain.bin, event))) {
3815 GST_DEBUG_OBJECT (playsink, "Sent event successfully to text sink");
3817 GST_DEBUG_OBJECT (playsink, "Event failed when sent to text sink");
3821 if (playsink->videochain) {
3822 gst_event_ref (event);
3824 gst_element_send_event (playsink->videochain->chain.bin,
3826 GST_DEBUG_OBJECT (playsink, "Sent event successfully to video sink");
3829 GST_DEBUG_OBJECT (playsink, "Event failed when sent to video sink");
3831 if (playsink->audiochain) {
3832 gst_event_ref (event);
3834 gst_element_send_event (playsink->audiochain->chain.bin,
3836 GST_DEBUG_OBJECT (playsink, "Sent event successfully to audio sink");
3839 GST_DEBUG_OBJECT (playsink, "Event failed when sent to audio sink");
3843 GST_ELEMENT_CLASS (gst_play_sink_parent_class)->send_event
3844 (GST_ELEMENT_CAST (playsink), event);
3848 gst_event_unref (event);
3852 /* We only want to send the event to a single sink (overriding GstBin's
3853 * behaviour), but we want to keep GstPipeline's behaviour - wrapping seek
3854 * events appropriately. So, this is a messy duplication of code. */
3856 gst_play_sink_send_event (GstElement * element, GstEvent * event)
3858 gboolean res = FALSE;
3859 GstEventType event_type = GST_EVENT_TYPE (event);
3860 GstPlaySink *playsink;
3861 playsink = GST_PLAY_SINK_CAST (element);
3862 switch (event_type) {
3863 case GST_EVENT_SEEK:
3864 GST_DEBUG_OBJECT (element, "Sending event to a sink");
3865 res = gst_play_sink_send_event_to_sink (playsink, event);
3867 case GST_EVENT_STEP:
3872 gboolean flush, intermediate;
3873 gst_event_parse_step (event, &format, &amount, &rate, &flush,
3875 if (format == GST_FORMAT_BUFFERS) {
3876 /* for buffers, we will try to step video frames, for other formats we
3877 * send the step to all sinks */
3878 res = gst_play_sink_send_event_to_sink (playsink, event);
3881 GST_ELEMENT_CLASS (gst_play_sink_parent_class)->send_event (element,
3888 GST_ELEMENT_CLASS (gst_play_sink_parent_class)->send_event (element,
3895 static GstStateChangeReturn
3896 gst_play_sink_change_state (GstElement * element, GstStateChange transition)
3898 GstStateChangeReturn ret;
3899 GstStateChangeReturn bret;
3900 GstPlaySink *playsink;
3901 playsink = GST_PLAY_SINK (element);
3902 switch (transition) {
3903 case GST_STATE_CHANGE_READY_TO_PAUSED:
3904 playsink->need_async_start = TRUE;
3905 /* we want to go async to PAUSED until we managed to configure and add the
3907 do_async_start (playsink);
3908 ret = GST_STATE_CHANGE_ASYNC;
3910 case GST_STATE_CHANGE_PAUSED_TO_READY:
3911 /* unblock all pads here */
3912 GST_PLAY_SINK_LOCK (playsink);
3913 video_set_blocked (playsink, FALSE);
3914 audio_set_blocked (playsink, FALSE);
3915 text_set_blocked (playsink, FALSE);
3916 GST_PLAY_SINK_UNLOCK (playsink);
3918 case GST_STATE_CHANGE_READY_TO_NULL:
3919 if (playsink->audiochain && playsink->audiochain->sink_volume) {
3920 /* remove our links to the mute and volume elements when they were
3921 * provided by a sink */
3922 disconnect_chain (playsink->audiochain, playsink);
3923 playsink->audiochain->volume = NULL;
3924 playsink->audiochain->mute = NULL;
3927 if (playsink->audiochain && playsink->audiochain->ts_offset) {
3928 gst_object_unref (playsink->audiochain->ts_offset);
3929 playsink->audiochain->ts_offset = NULL;
3932 if (playsink->videochain && playsink->videochain->ts_offset) {
3933 gst_object_unref (playsink->videochain->ts_offset);
3934 playsink->videochain->ts_offset = NULL;
3937 GST_OBJECT_LOCK (playsink);
3938 if (playsink->overlay_element)
3939 gst_object_unref (playsink->overlay_element);
3940 playsink->overlay_element = NULL;
3942 if (playsink->colorbalance_element) {
3943 g_signal_handlers_disconnect_by_func (playsink->colorbalance_element,
3944 G_CALLBACK (colorbalance_value_changed_cb), playsink);
3945 gst_object_unref (playsink->colorbalance_element);
3947 playsink->colorbalance_element = NULL;
3948 GST_OBJECT_UNLOCK (playsink);
3950 ret = GST_STATE_CHANGE_SUCCESS;
3953 /* all other state changes return SUCCESS by default, this value can be
3954 * overridden by the result of the children */
3955 ret = GST_STATE_CHANGE_SUCCESS;
3959 /* do the state change of the children */
3961 GST_ELEMENT_CLASS (gst_play_sink_parent_class)->change_state (element,
3963 /* now look at the result of our children and adjust the return value */
3965 case GST_STATE_CHANGE_FAILURE:
3966 /* failure, we stop */
3967 goto activate_failed;
3968 case GST_STATE_CHANGE_NO_PREROLL:
3969 /* some child returned NO_PREROLL. This is strange but we never know. We
3970 * commit our async state change (if any) and return the NO_PREROLL */
3971 do_async_done (playsink);
3974 case GST_STATE_CHANGE_ASYNC:
3975 /* some child was async, return this */
3979 /* return our previously configured return value */
3983 switch (transition) {
3984 case GST_STATE_CHANGE_READY_TO_PAUSED:
3986 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
3987 /* FIXME Release audio device when we implement that */
3988 playsink->need_async_start = TRUE;
3990 case GST_STATE_CHANGE_PAUSED_TO_READY:{
3991 if (playsink->video_sinkpad_stream_synchronizer) {
3992 gst_element_release_request_pad (GST_ELEMENT_CAST
3993 (playsink->stream_synchronizer),
3994 playsink->video_sinkpad_stream_synchronizer);
3995 gst_object_unref (playsink->video_sinkpad_stream_synchronizer);
3996 playsink->video_sinkpad_stream_synchronizer = NULL;
3997 gst_object_unref (playsink->video_srcpad_stream_synchronizer);
3998 playsink->video_srcpad_stream_synchronizer = NULL;
4000 if (playsink->audio_sinkpad_stream_synchronizer) {
4001 gst_element_release_request_pad (GST_ELEMENT_CAST
4002 (playsink->stream_synchronizer),
4003 playsink->audio_sinkpad_stream_synchronizer);
4004 gst_object_unref (playsink->audio_sinkpad_stream_synchronizer);
4005 playsink->audio_sinkpad_stream_synchronizer = NULL;
4006 gst_object_unref (playsink->audio_srcpad_stream_synchronizer);
4007 playsink->audio_srcpad_stream_synchronizer = NULL;
4009 if (playsink->text_sinkpad_stream_synchronizer) {
4010 gst_element_release_request_pad (GST_ELEMENT_CAST
4011 (playsink->stream_synchronizer),
4012 playsink->text_sinkpad_stream_synchronizer);
4013 gst_object_unref (playsink->text_sinkpad_stream_synchronizer);
4014 playsink->text_sinkpad_stream_synchronizer = NULL;
4015 gst_object_unref (playsink->text_srcpad_stream_synchronizer);
4016 playsink->text_srcpad_stream_synchronizer = NULL;
4020 case GST_STATE_CHANGE_READY_TO_NULL:
4021 /* remove sinks we added */
4022 if (playsink->videodeinterlacechain) {
4023 activate_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain),
4025 add_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain), FALSE);
4027 if (playsink->videochain) {
4028 activate_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE);
4029 add_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE);
4031 if (playsink->audiochain) {
4032 activate_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE);
4033 add_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE);
4035 if (playsink->vischain) {
4036 activate_chain (GST_PLAY_CHAIN (playsink->vischain), FALSE);
4037 add_chain (GST_PLAY_CHAIN (playsink->vischain), FALSE);
4039 if (playsink->textchain) {
4040 activate_chain (GST_PLAY_CHAIN (playsink->textchain), FALSE);
4041 add_chain (GST_PLAY_CHAIN (playsink->textchain), FALSE);
4043 do_async_done (playsink);
4044 /* when going to READY, keep elements around as long as possible,
4045 * so they may be re-used faster next time/url around.
4046 * when really going to NULL, clean up everything completely. */
4047 if (transition == GST_STATE_CHANGE_READY_TO_NULL) {
4049 /* Unparent the sinks to allow reuse */
4050 if (playsink->videochain && playsink->videochain->sink)
4051 gst_bin_remove (GST_BIN_CAST (playsink->videochain->chain.bin),
4052 playsink->videochain->sink);
4053 if (playsink->audiochain && playsink->audiochain->sink)
4054 gst_bin_remove (GST_BIN_CAST (playsink->audiochain->chain.bin),
4055 playsink->audiochain->sink);
4056 if (playsink->textchain && playsink->textchain->sink)
4057 gst_bin_remove (GST_BIN_CAST (playsink->textchain->chain.bin),
4058 playsink->textchain->sink);
4059 if (playsink->audio_sink != NULL)
4060 gst_element_set_state (playsink->audio_sink, GST_STATE_NULL);
4061 if (playsink->video_sink != NULL)
4062 gst_element_set_state (playsink->video_sink, GST_STATE_NULL);
4063 if (playsink->visualisation != NULL)
4064 gst_element_set_state (playsink->visualisation, GST_STATE_NULL);
4065 if (playsink->text_sink != NULL)
4066 gst_element_set_state (playsink->text_sink, GST_STATE_NULL);
4067 free_chain ((GstPlayChain *) playsink->videodeinterlacechain);
4068 playsink->videodeinterlacechain = NULL;
4069 free_chain ((GstPlayChain *) playsink->videochain);
4070 playsink->videochain = NULL;
4071 free_chain ((GstPlayChain *) playsink->audiochain);
4072 playsink->audiochain = NULL;
4073 free_chain ((GstPlayChain *) playsink->vischain);
4074 playsink->vischain = NULL;
4075 free_chain ((GstPlayChain *) playsink->textchain);
4076 playsink->textchain = NULL;
4086 GST_DEBUG_OBJECT (element,
4087 "element failed to change states -- activation problem?");
4088 return GST_STATE_CHANGE_FAILURE;
4093 gst_play_sink_set_property (GObject * object, guint prop_id,
4094 const GValue * value, GParamSpec * spec)
4096 GstPlaySink *playsink = GST_PLAY_SINK (object);
4099 gst_play_sink_set_flags (playsink, g_value_get_flags (value));
4102 gst_play_sink_set_volume (playsink, g_value_get_double (value));
4105 gst_play_sink_set_mute (playsink, g_value_get_boolean (value));
4107 case PROP_FONT_DESC:
4108 gst_play_sink_set_font_desc (playsink, g_value_get_string (value));
4110 case PROP_SUBTITLE_ENCODING:
4111 gst_play_sink_set_subtitle_encoding (playsink,
4112 g_value_get_string (value));
4114 case PROP_VIS_PLUGIN:
4115 gst_play_sink_set_vis_plugin (playsink, g_value_get_object (value));
4117 case PROP_AV_OFFSET:
4118 gst_play_sink_set_av_offset (playsink, g_value_get_int64 (value));
4120 case PROP_VIDEO_SINK:
4121 gst_play_sink_set_sink (playsink, GST_PLAY_SINK_TYPE_VIDEO,
4122 g_value_get_object (value));
4124 case PROP_AUDIO_SINK:
4125 gst_play_sink_set_sink (playsink, GST_PLAY_SINK_TYPE_AUDIO,
4126 g_value_get_object (value));
4128 case PROP_TEXT_SINK:
4129 gst_play_sink_set_sink (playsink, GST_PLAY_SINK_TYPE_TEXT,
4130 g_value_get_object (value));
4132 case PROP_SEND_EVENT_MODE:
4133 playsink->send_event_mode = g_value_get_enum (value);
4136 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec);
4142 gst_play_sink_get_property (GObject * object, guint prop_id,
4143 GValue * value, GParamSpec * spec)
4145 GstPlaySink *playsink = GST_PLAY_SINK (object);
4148 g_value_set_flags (value, gst_play_sink_get_flags (playsink));
4151 g_value_set_double (value, gst_play_sink_get_volume (playsink));
4154 g_value_set_boolean (value, gst_play_sink_get_mute (playsink));
4156 case PROP_FONT_DESC:
4157 g_value_take_string (value, gst_play_sink_get_font_desc (playsink));
4159 case PROP_SUBTITLE_ENCODING:
4160 g_value_take_string (value,
4161 gst_play_sink_get_subtitle_encoding (playsink));
4163 case PROP_VIS_PLUGIN:
4164 g_value_take_object (value, gst_play_sink_get_vis_plugin (playsink));
4167 gst_value_take_sample (value, gst_play_sink_get_last_sample (playsink));
4169 case PROP_AV_OFFSET:
4170 g_value_set_int64 (value, gst_play_sink_get_av_offset (playsink));
4172 case PROP_VIDEO_SINK:
4173 g_value_take_object (value, gst_play_sink_get_sink (playsink,
4174 GST_PLAY_SINK_TYPE_VIDEO));
4176 case PROP_AUDIO_SINK:
4177 g_value_take_object (value, gst_play_sink_get_sink (playsink,
4178 GST_PLAY_SINK_TYPE_AUDIO));
4180 case PROP_TEXT_SINK:
4181 g_value_take_object (value, gst_play_sink_get_sink (playsink,
4182 GST_PLAY_SINK_TYPE_TEXT));
4184 case PROP_SEND_EVENT_MODE:
4185 g_value_set_enum (value, playsink->send_event_mode);
4188 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec);
4194 gst_play_sink_overlay_expose (GstVideoOverlay * overlay)
4196 GstPlaySink *playsink = GST_PLAY_SINK (overlay);
4197 GstVideoOverlay *overlay_element;
4199 GST_OBJECT_LOCK (playsink);
4200 if (playsink->overlay_element)
4202 GST_VIDEO_OVERLAY (gst_object_ref (playsink->overlay_element));
4204 overlay_element = NULL;
4205 GST_OBJECT_UNLOCK (playsink);
4207 if (overlay_element) {
4208 gst_video_overlay_expose (overlay_element);
4209 gst_object_unref (overlay_element);
4214 gst_play_sink_overlay_handle_events (GstVideoOverlay * overlay,
4215 gboolean handle_events)
4217 GstPlaySink *playsink = GST_PLAY_SINK (overlay);
4218 GstVideoOverlay *overlay_element;
4220 GST_OBJECT_LOCK (playsink);
4221 if (playsink->overlay_element)
4223 GST_VIDEO_OVERLAY (gst_object_ref (playsink->overlay_element));
4225 overlay_element = NULL;
4226 GST_OBJECT_UNLOCK (playsink);
4228 playsink->overlay_handle_events_set = TRUE;
4229 playsink->overlay_handle_events = handle_events;
4231 if (overlay_element) {
4232 gst_video_overlay_handle_events (overlay_element, handle_events);
4233 gst_object_unref (overlay_element);
4238 gst_play_sink_overlay_set_render_rectangle (GstVideoOverlay * overlay, gint x,
4239 gint y, gint width, gint height)
4241 GstPlaySink *playsink = GST_PLAY_SINK (overlay);
4242 GstVideoOverlay *overlay_element;
4244 GST_OBJECT_LOCK (playsink);
4245 if (playsink->overlay_element)
4247 GST_VIDEO_OVERLAY (gst_object_ref (playsink->overlay_element));
4249 overlay_element = NULL;
4250 GST_OBJECT_UNLOCK (playsink);
4252 playsink->overlay_render_rectangle_set = TRUE;
4253 playsink->overlay_x = x;
4254 playsink->overlay_y = y;
4255 playsink->overlay_width = width;
4256 playsink->overlay_height = height;
4258 if (overlay_element) {
4259 gst_video_overlay_set_render_rectangle (overlay_element, x, y, width,
4261 gst_object_unref (overlay_element);
4266 gst_play_sink_overlay_set_window_handle (GstVideoOverlay * overlay,
4269 GstPlaySink *playsink = GST_PLAY_SINK (overlay);
4270 GstVideoOverlay *overlay_element;
4272 GST_OBJECT_LOCK (playsink);
4273 if (playsink->overlay_element)
4275 GST_VIDEO_OVERLAY (gst_object_ref (playsink->overlay_element));
4277 overlay_element = NULL;
4278 GST_OBJECT_UNLOCK (playsink);
4280 playsink->overlay_handle_set = TRUE;
4281 playsink->overlay_handle = handle;
4283 if (overlay_element) {
4284 gst_video_overlay_set_window_handle (overlay_element, handle);
4285 gst_object_unref (overlay_element);
4290 gst_play_sink_overlay_init (gpointer g_iface, gpointer g_iface_data)
4292 GstVideoOverlayInterface *iface = (GstVideoOverlayInterface *) g_iface;
4293 iface->expose = gst_play_sink_overlay_expose;
4294 iface->handle_events = gst_play_sink_overlay_handle_events;
4295 iface->set_render_rectangle = gst_play_sink_overlay_set_render_rectangle;
4296 iface->set_window_handle = gst_play_sink_overlay_set_window_handle;
4300 gst_play_sink_navigation_send_event (GstNavigation * navigation,
4301 GstStructure * structure)
4303 GstPlaySink *playsink = GST_PLAY_SINK (navigation);
4306 GST_PLAY_SINK_LOCK (playsink);
4307 if (playsink->videochain && playsink->videochain->chain.bin)
4308 bin = GST_BIN (gst_object_ref (playsink->videochain->chain.bin));
4309 GST_PLAY_SINK_UNLOCK (playsink);
4312 GstElement *nav = gst_bin_get_by_interface (bin, GST_TYPE_NAVIGATION);
4315 gst_navigation_send_event (GST_NAVIGATION (nav), structure);
4317 gst_object_unref (nav);
4319 GstEvent *event = gst_event_new_navigation (structure);
4321 gst_element_send_event (GST_ELEMENT (bin), event);
4324 gst_object_unref (bin);
4328 gst_structure_free (structure);
4332 gst_play_sink_navigation_init (gpointer g_iface, gpointer g_iface_data)
4334 GstNavigationInterface *iface = (GstNavigationInterface *) g_iface;
4336 iface->send_event = gst_play_sink_navigation_send_event;
4339 static const GList *
4340 gst_play_sink_colorbalance_list_channels (GstColorBalance * balance)
4342 GstPlaySink *playsink = GST_PLAY_SINK (balance);
4344 return playsink->colorbalance_channels;
4348 gst_play_sink_colorbalance_set_value (GstColorBalance * balance,
4349 GstColorBalanceChannel * proxy, gint value)
4351 GstPlaySink *playsink = GST_PLAY_SINK (balance);
4354 GstColorBalance *balance_element = NULL;
4356 GST_OBJECT_LOCK (playsink);
4357 if (playsink->colorbalance_element)
4359 GST_COLOR_BALANCE (gst_object_ref (playsink->colorbalance_element));
4360 GST_OBJECT_UNLOCK (playsink);
4362 for (i = 0, l = playsink->colorbalance_channels; l; l = l->next, i++) {
4363 GstColorBalanceChannel *proxy_tmp = l->data;
4366 if (proxy_tmp != proxy)
4369 playsink->colorbalance_values[i] = value;
4371 if (balance_element) {
4372 GstColorBalanceChannel *channel = NULL;
4373 const GList *channels, *k;
4375 channels = gst_color_balance_list_channels (balance_element);
4376 for (k = channels; k; k = k->next) {
4377 GstColorBalanceChannel *tmp = l->data;
4379 if (g_strrstr (tmp->label, proxy->label)) {
4387 /* Convert to [0, 1] range */
4390 (gdouble) proxy->min_value) / ((gdouble) proxy->max_value -
4391 (gdouble) proxy->min_value);
4392 /* Convert to channel range */
4394 channel->min_value + new_val * ((gdouble) channel->max_value -
4395 (gdouble) channel->min_value);
4397 gst_color_balance_set_value (balance_element, channel,
4398 (gint) (new_val + 0.5));
4400 gst_object_unref (balance_element);
4403 gst_color_balance_value_changed (balance, proxy, value);
4409 gst_play_sink_colorbalance_get_value (GstColorBalance * balance,
4410 GstColorBalanceChannel * proxy)
4412 GstPlaySink *playsink = GST_PLAY_SINK (balance);
4416 for (i = 0, l = playsink->colorbalance_channels; l; l = l->next, i++) {
4417 GstColorBalanceChannel *proxy_tmp = l->data;
4419 if (proxy_tmp != proxy)
4422 return playsink->colorbalance_values[i];
4425 g_return_val_if_reached (0);
4428 static GstColorBalanceType
4429 gst_play_sink_colorbalance_get_balance_type (GstColorBalance * balance)
4431 GstPlaySink *playsink = GST_PLAY_SINK (balance);
4432 GstColorBalance *balance_element = NULL;
4433 GstColorBalanceType t = GST_COLOR_BALANCE_SOFTWARE;
4435 GST_OBJECT_LOCK (playsink);
4436 if (playsink->colorbalance_element)
4438 GST_COLOR_BALANCE (gst_object_ref (playsink->colorbalance_element));
4439 GST_OBJECT_UNLOCK (playsink);
4441 if (balance_element) {
4442 t = gst_color_balance_get_balance_type (balance_element);
4443 gst_object_unref (balance_element);
4450 gst_play_sink_colorbalance_init (gpointer g_iface, gpointer g_iface_data)
4452 GstColorBalanceInterface *iface = (GstColorBalanceInterface *) g_iface;
4454 iface->list_channels = gst_play_sink_colorbalance_list_channels;
4455 iface->set_value = gst_play_sink_colorbalance_set_value;
4456 iface->get_value = gst_play_sink_colorbalance_get_value;
4457 iface->get_balance_type = gst_play_sink_colorbalance_get_balance_type;
4461 gst_play_sink_plugin_init (GstPlugin * plugin)
4463 GST_DEBUG_CATEGORY_INIT (gst_play_sink_debug, "playsink", 0, "play bin");
4464 return gst_element_register (plugin, "playsink", GST_RANK_NONE,
4465 GST_TYPE_PLAY_SINK);