2 * Copyright (C) <2007> Wim Taymans <wim.taymans@gmail.com>
3 * Copyright (C) <2011> Sebastian Dröge <sebastian.droege@collabora.co.uk>
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public
16 * License along with this library; if not, write to the
17 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
25 /* FIXME 0.11: suppress warnings for deprecated API such as GStaticRecMutex
26 * with newer GLib versions (>= 2.31.0) */
27 #define GLIB_DISABLE_DEPRECATION_WARNINGS
32 #include <gst/gst-i18n-plugin.h>
33 #include <gst/pbutils/pbutils.h>
34 #include <gst/video/video.h>
35 #include <gst/interfaces/streamvolume.h>
36 #include <gst/interfaces/colorbalance.h>
37 #include <gst/interfaces/xoverlay.h>
38 #include <gst/interfaces/navigation.h>
40 #include "gstplaysink.h"
41 #include "gststreamsynchronizer.h"
42 #include "gstplaysinkvideoconvert.h"
43 #include "gstplaysinkaudioconvert.h"
45 GST_DEBUG_CATEGORY_STATIC (gst_play_sink_debug);
46 #define GST_CAT_DEFAULT gst_play_sink_debug
48 #define VOLUME_MAX_DOUBLE 10.0
50 #define DEFAULT_FLAGS GST_PLAY_FLAG_AUDIO | GST_PLAY_FLAG_VIDEO | GST_PLAY_FLAG_TEXT | \
51 GST_PLAY_FLAG_SOFT_VOLUME | GST_PLAY_FLAG_SOFT_COLORBALANCE
53 #define GST_PLAY_CHAIN(c) ((GstPlayChain *)(c))
55 /* holds the common data fields for the audio and video pipelines. We keep them
56 * in a structure to more easily have all the info available. */
59 GstPlaySink *playsink;
72 GstElement *volume; /* element with the volume property */
73 gboolean sink_volume; /* if the volume was provided by the sink */
74 GstElement *mute; /* element with the mute property */
76 GstElement *ts_offset;
82 GstPad *sinkpad, *srcpad;
84 GstElement *deinterlace;
85 } GstPlayVideoDeinterlaceChain;
95 GstElement *ts_offset;
104 GstElement *resample;
105 GstPad *blockpad; /* srcpad of resample, used for switching the vis */
106 GstPad *vissinkpad; /* visualisation sinkpad, */
108 GstPad *vissrcpad; /* visualisation srcpad, */
109 GstPad *srcpad; /* outgoing srcpad, used to connect to the next
118 GstElement *identity;
120 GstPad *videosinkpad;
122 GstPad *srcpad; /* outgoing srcpad, used to connect to the next
124 GstElement *sink; /* custom sink to receive subtitle buffers */
127 #define GST_PLAY_SINK_GET_LOCK(playsink) (&((GstPlaySink *)playsink)->lock)
128 #define GST_PLAY_SINK_LOCK(playsink) G_STMT_START { \
129 GST_LOG_OBJECT (playsink, "locking from thread %p", g_thread_self ()); \
130 g_static_rec_mutex_lock (GST_PLAY_SINK_GET_LOCK (playsink)); \
131 GST_LOG_OBJECT (playsink, "locked from thread %p", g_thread_self ()); \
133 #define GST_PLAY_SINK_UNLOCK(playsink) G_STMT_START { \
134 GST_LOG_OBJECT (playsink, "unlocking from thread %p", g_thread_self ()); \
135 g_static_rec_mutex_unlock (GST_PLAY_SINK_GET_LOCK (playsink)); \
138 #define PENDING_FLAG_SET(playsink, flagtype) \
139 ((playsink->pending_blocked_pads) |= (1 << flagtype))
140 #define PENDING_FLAG_UNSET(playsink, flagtype) \
141 ((playsink->pending_blocked_pads) &= ~(1 << flagtype))
142 #define PENDING_FLAG_IS_SET(playsink, flagtype) \
143 ((playsink->pending_blocked_pads) & (1 << flagtype))
144 #define PENDING_VIDEO_BLOCK(playsink) \
145 ((playsink->pending_blocked_pads) & (1 << GST_PLAY_SINK_TYPE_VIDEO_RAW | 1 << GST_PLAY_SINK_TYPE_VIDEO))
146 #define PENDING_AUDIO_BLOCK(playsink) \
147 ((playsink->pending_blocked_pads) & (1 << GST_PLAY_SINK_TYPE_AUDIO_RAW | 1 << GST_PLAY_SINK_TYPE_AUDIO))
148 #define PENDING_TEXT_BLOCK(playsink) \
149 PENDING_FLAG_IS_SET(playsink, GST_PLAY_SINK_TYPE_TEXT)
155 GStaticRecMutex lock;
157 gboolean async_pending;
158 gboolean need_async_start;
162 GstStreamSynchronizer *stream_synchronizer;
165 GstPlayAudioChain *audiochain;
166 GstPlayVideoDeinterlaceChain *videodeinterlacechain;
167 GstPlayVideoChain *videochain;
168 GstPlayVisChain *vischain;
169 GstPlayTextChain *textchain;
173 gboolean audio_pad_raw;
174 gboolean audio_pad_blocked;
175 GstPad *audio_srcpad_stream_synchronizer;
176 GstPad *audio_sinkpad_stream_synchronizer;
178 GstElement *audio_tee;
179 GstPad *audio_tee_sink;
180 GstPad *audio_tee_asrc;
181 GstPad *audio_tee_vissrc;
184 gboolean video_pad_raw;
185 gboolean video_pad_blocked;
186 GstPad *video_srcpad_stream_synchronizer;
187 GstPad *video_sinkpad_stream_synchronizer;
190 gboolean text_pad_blocked;
191 GstPad *text_srcpad_stream_synchronizer;
192 GstPad *text_sinkpad_stream_synchronizer;
194 guint32 pending_blocked_pads;
197 GstElement *audio_sink;
198 GstElement *video_sink;
199 GstElement *visualisation;
200 GstElement *text_sink;
203 gchar *font_desc; /* font description */
204 gchar *subtitle_encoding; /* subtitle encoding */
205 guint connection_speed; /* connection speed in bits/sec (0 = unknown) */
207 gboolean volume_changed; /* volume/mute changed while no audiochain */
208 gboolean mute_changed; /* ... has been created yet */
211 /* xoverlay proxy interface */
212 GstXOverlay *xoverlay_element; /* protected with LOCK */
213 gboolean xoverlay_handle_set;
214 guintptr xoverlay_handle;
215 gboolean xoverlay_render_rectangle_set;
216 gint xoverlay_x, xoverlay_y, xoverlay_width, xoverlay_height;
217 gboolean xoverlay_handle_events_set;
218 gboolean xoverlay_handle_events;
220 /* colorbalance proxy interface */
221 GstColorBalance *colorbalance_element;
222 GList *colorbalance_channels; /* CONTRAST, BRIGHTNESS, HUE, SATURATION */
223 gint colorbalance_values[4];
226 struct _GstPlaySinkClass
228 GstBinClass parent_class;
230 gboolean (*reconfigure) (GstPlaySink * playsink);
232 GstBuffer *(*convert_frame) (GstPlaySink * playsink, GstCaps * caps);
236 static GstStaticPadTemplate audiotemplate =
237 GST_STATIC_PAD_TEMPLATE ("audio_sink",
240 GST_STATIC_CAPS_ANY);
241 static GstStaticPadTemplate videotemplate =
242 GST_STATIC_PAD_TEMPLATE ("video_sink",
245 GST_STATIC_CAPS_ANY);
246 static GstStaticPadTemplate texttemplate = GST_STATIC_PAD_TEMPLATE ("text_sink",
249 GST_STATIC_CAPS_ANY);
251 /* FIXME 0.11: Remove */
252 static GstStaticPadTemplate audiorawtemplate =
253 GST_STATIC_PAD_TEMPLATE ("audio_raw_sink",
256 GST_STATIC_CAPS_ANY);
257 static GstStaticPadTemplate videorawtemplate =
258 GST_STATIC_PAD_TEMPLATE ("video_raw_sink",
261 GST_STATIC_CAPS_ANY);
272 PROP_SUBTITLE_ENCODING,
288 static void gst_play_sink_dispose (GObject * object);
289 static void gst_play_sink_finalize (GObject * object);
290 static void gst_play_sink_set_property (GObject * object, guint prop_id,
291 const GValue * value, GParamSpec * spec);
292 static void gst_play_sink_get_property (GObject * object, guint prop_id,
293 GValue * value, GParamSpec * spec);
295 static GstPad *gst_play_sink_request_new_pad (GstElement * element,
296 GstPadTemplate * templ, const gchar * name);
297 static void gst_play_sink_release_request_pad (GstElement * element,
299 static gboolean gst_play_sink_send_event (GstElement * element,
301 static GstStateChangeReturn gst_play_sink_change_state (GstElement * element,
302 GstStateChange transition);
304 static void gst_play_sink_handle_message (GstBin * bin, GstMessage * message);
306 static void notify_volume_cb (GObject * object, GParamSpec * pspec,
307 GstPlaySink * playsink);
308 static void notify_mute_cb (GObject * object, GParamSpec * pspec,
309 GstPlaySink * playsink);
311 static void update_av_offset (GstPlaySink * playsink);
314 gst_play_marshal_BUFFER__BOXED (GClosure * closure,
315 GValue * return_value G_GNUC_UNUSED,
316 guint n_param_values,
317 const GValue * param_values,
318 gpointer invocation_hint G_GNUC_UNUSED, gpointer marshal_data)
320 typedef GstBuffer *(*GMarshalFunc_OBJECT__BOXED) (gpointer data1,
321 gpointer arg_1, gpointer data2);
322 register GMarshalFunc_OBJECT__BOXED callback;
323 register GCClosure *cc = (GCClosure *) closure;
324 register gpointer data1, data2;
326 g_return_if_fail (return_value != NULL);
327 g_return_if_fail (n_param_values == 2);
329 if (G_CCLOSURE_SWAP_DATA (closure)) {
330 data1 = closure->data;
331 data2 = g_value_peek_pointer (param_values + 0);
333 data1 = g_value_peek_pointer (param_values + 0);
334 data2 = closure->data;
337 (GMarshalFunc_OBJECT__BOXED) (marshal_data ? marshal_data : cc->callback);
339 v_return = callback (data1, g_value_get_boxed (param_values + 1), data2);
341 gst_value_take_buffer (return_value, v_return);
344 /* static guint gst_play_sink_signals[LAST_SIGNAL] = { 0 }; */
346 static void gst_play_sink_implements_interface_init (gpointer g_iface,
347 gpointer g_iface_data);
348 static void gst_play_sink_xoverlay_init (gpointer g_iface,
349 gpointer g_iface_data);
350 static void gst_play_sink_navigation_init (gpointer g_iface,
351 gpointer g_iface_data);
352 static void gst_play_sink_colorbalance_init (gpointer g_iface,
353 gpointer g_iface_data);
356 _do_init (GType type)
358 static const GInterfaceInfo impl_info = {
359 gst_play_sink_implements_interface_init,
362 static const GInterfaceInfo svol_info = {
365 static const GInterfaceInfo xov_info = {
366 gst_play_sink_xoverlay_init,
369 static const GInterfaceInfo nav_info = {
370 gst_play_sink_navigation_init,
373 static const GInterfaceInfo col_info = {
374 gst_play_sink_colorbalance_init,
378 g_type_add_interface_static (type, GST_TYPE_IMPLEMENTS_INTERFACE, &impl_info);
379 g_type_add_interface_static (type, GST_TYPE_STREAM_VOLUME, &svol_info);
380 g_type_add_interface_static (type, GST_TYPE_X_OVERLAY, &xov_info);
381 g_type_add_interface_static (type, GST_TYPE_NAVIGATION, &nav_info);
382 g_type_add_interface_static (type, GST_TYPE_COLOR_BALANCE, &col_info);
385 G_DEFINE_TYPE_WITH_CODE (GstPlaySink, gst_play_sink, GST_TYPE_BIN,
386 _do_init (g_define_type_id));
389 gst_play_sink_class_init (GstPlaySinkClass * klass)
391 GObjectClass *gobject_klass;
392 GstElementClass *gstelement_klass;
393 GstBinClass *gstbin_klass;
395 gobject_klass = (GObjectClass *) klass;
396 gstelement_klass = (GstElementClass *) klass;
397 gstbin_klass = (GstBinClass *) klass;
399 gobject_klass->dispose = gst_play_sink_dispose;
400 gobject_klass->finalize = gst_play_sink_finalize;
401 gobject_klass->set_property = gst_play_sink_set_property;
402 gobject_klass->get_property = gst_play_sink_get_property;
408 * Control the behaviour of playsink.
410 g_object_class_install_property (gobject_klass, PROP_FLAGS,
411 g_param_spec_flags ("flags", "Flags", "Flags to control behaviour",
412 GST_TYPE_PLAY_FLAGS, DEFAULT_FLAGS,
413 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
416 * GstPlaySink:volume:
418 * Get or set the current audio stream volume. 1.0 means 100%,
419 * 0.0 means mute. This uses a linear volume scale.
422 g_object_class_install_property (gobject_klass, PROP_VOLUME,
423 g_param_spec_double ("volume", "Volume", "The audio volume, 1.0=100%",
424 0.0, VOLUME_MAX_DOUBLE, 1.0,
425 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
426 g_object_class_install_property (gobject_klass, PROP_MUTE,
427 g_param_spec_boolean ("mute", "Mute",
428 "Mute the audio channel without changing the volume", FALSE,
429 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
430 g_object_class_install_property (gobject_klass, PROP_FONT_DESC,
431 g_param_spec_string ("subtitle-font-desc",
432 "Subtitle font description",
433 "Pango font description of font "
434 "to be used for subtitle rendering", NULL,
435 G_PARAM_WRITABLE | G_PARAM_STATIC_STRINGS));
436 g_object_class_install_property (gobject_klass, PROP_SUBTITLE_ENCODING,
437 g_param_spec_string ("subtitle-encoding", "subtitle encoding",
438 "Encoding to assume if input subtitles are not in UTF-8 encoding. "
439 "If not set, the GST_SUBTITLE_ENCODING environment variable will "
440 "be checked for an encoding to use. If that is not set either, "
441 "ISO-8859-15 will be assumed.", NULL,
442 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
443 g_object_class_install_property (gobject_klass, PROP_VIS_PLUGIN,
444 g_param_spec_object ("vis-plugin", "Vis plugin",
445 "the visualization element to use (NULL = default)",
446 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
450 * Get the currently rendered or prerolled frame in the video sink.
451 * The #GstCaps on the buffer will describe the format of the buffer.
455 g_object_class_install_property (gobject_klass, PROP_FRAME,
456 gst_param_spec_mini_object ("frame", "Frame",
457 "The last frame (NULL = no video available)",
458 GST_TYPE_BUFFER, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS));
460 * GstPlaySink:av-offset:
462 * Control the synchronisation offset between the audio and video streams.
463 * Positive values make the audio ahead of the video and negative values make
464 * the audio go behind the video.
468 g_object_class_install_property (gobject_klass, PROP_AV_OFFSET,
469 g_param_spec_int64 ("av-offset", "AV Offset",
470 "The synchronisation offset between audio and video in nanoseconds",
471 G_MININT64, G_MAXINT64, 0,
472 G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
475 * GstPlaySink:video-sink:
477 * Set the used video sink element. NULL will use the default sink. playsink
478 * must be in %GST_STATE_NULL
482 g_object_class_install_property (gobject_klass, PROP_VIDEO_SINK,
483 g_param_spec_object ("video-sink", "Video Sink",
484 "the video output element to use (NULL = default sink)",
485 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
487 * GstPlaySink:audio-sink:
489 * Set the used audio sink element. NULL will use the default sink. playsink
490 * must be in %GST_STATE_NULL
494 g_object_class_install_property (gobject_klass, PROP_AUDIO_SINK,
495 g_param_spec_object ("audio-sink", "Audio Sink",
496 "the audio output element to use (NULL = default sink)",
497 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
500 * GstPlaySink:text-sink:
502 * Set the used text sink element. NULL will use the default sink. playsink
503 * must be in %GST_STATE_NULL
507 g_object_class_install_property (gobject_klass, PROP_TEXT_SINK,
508 g_param_spec_object ("text-sink", "Text sink",
509 "the text output element to use (NULL = default textoverlay)",
510 GST_TYPE_ELEMENT, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS));
513 g_signal_new ("reconfigure", G_TYPE_FROM_CLASS (klass),
514 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, G_STRUCT_OFFSET (GstPlaySinkClass,
515 reconfigure), NULL, NULL, gst_marshal_BOOLEAN__VOID, G_TYPE_BOOLEAN,
518 * GstPlaySink::convert-frame
519 * @playsink: a #GstPlaySink
520 * @caps: the target format of the frame
522 * Action signal to retrieve the currently playing video frame in the format
523 * specified by @caps.
524 * If @caps is %NULL, no conversion will be performed and this function is
525 * equivalent to the #GstPlaySink::frame property.
527 * Returns: a #GstBuffer of the current video frame converted to #caps.
528 * The caps on the buffer will describe the final layout of the buffer data.
529 * %NULL is returned when no current buffer can be retrieved or when the
534 g_signal_new ("convert-frame", G_TYPE_FROM_CLASS (klass),
535 G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
536 G_STRUCT_OFFSET (GstPlaySinkClass, convert_frame), NULL, NULL,
537 gst_play_marshal_BUFFER__BOXED, GST_TYPE_BUFFER, 1, GST_TYPE_CAPS);
539 gst_element_class_add_static_pad_template (gstelement_klass,
541 gst_element_class_add_static_pad_template (gstelement_klass, &audiotemplate);
542 gst_element_class_add_static_pad_template (gstelement_klass,
544 gst_element_class_add_static_pad_template (gstelement_klass, &videotemplate);
545 gst_element_class_add_static_pad_template (gstelement_klass, &texttemplate);
546 gst_element_class_set_details_simple (gstelement_klass, "Player Sink",
548 "Convenience sink for multiple streams",
549 "Wim Taymans <wim.taymans@gmail.com>");
551 gstelement_klass->change_state =
552 GST_DEBUG_FUNCPTR (gst_play_sink_change_state);
553 gstelement_klass->send_event = GST_DEBUG_FUNCPTR (gst_play_sink_send_event);
554 gstelement_klass->request_new_pad =
555 GST_DEBUG_FUNCPTR (gst_play_sink_request_new_pad);
556 gstelement_klass->release_pad =
557 GST_DEBUG_FUNCPTR (gst_play_sink_release_request_pad);
559 gstbin_klass->handle_message =
560 GST_DEBUG_FUNCPTR (gst_play_sink_handle_message);
562 klass->reconfigure = GST_DEBUG_FUNCPTR (gst_play_sink_reconfigure);
563 klass->convert_frame = GST_DEBUG_FUNCPTR (gst_play_sink_convert_frame);
567 gst_play_sink_init (GstPlaySink * playsink)
569 GstColorBalanceChannel *channel;
572 playsink->video_sink = NULL;
573 playsink->audio_sink = NULL;
574 playsink->visualisation = NULL;
575 playsink->text_sink = NULL;
576 playsink->volume = 1.0;
577 playsink->font_desc = NULL;
578 playsink->subtitle_encoding = NULL;
579 playsink->flags = DEFAULT_FLAGS;
581 playsink->stream_synchronizer =
582 g_object_new (GST_TYPE_STREAM_SYNCHRONIZER, NULL);
583 gst_bin_add (GST_BIN_CAST (playsink),
584 GST_ELEMENT_CAST (playsink->stream_synchronizer));
586 g_static_rec_mutex_init (&playsink->lock);
587 GST_OBJECT_FLAG_SET (playsink, GST_ELEMENT_IS_SINK);
590 GST_COLOR_BALANCE_CHANNEL (g_object_new (GST_TYPE_COLOR_BALANCE_CHANNEL,
592 channel->label = g_strdup ("CONTRAST");
593 channel->min_value = -1000;
594 channel->max_value = 1000;
595 playsink->colorbalance_channels =
596 g_list_append (playsink->colorbalance_channels, channel);
597 playsink->colorbalance_values[0] = 0;
600 GST_COLOR_BALANCE_CHANNEL (g_object_new (GST_TYPE_COLOR_BALANCE_CHANNEL,
602 channel->label = g_strdup ("BRIGHTNESS");
603 channel->min_value = -1000;
604 channel->max_value = 1000;
605 playsink->colorbalance_channels =
606 g_list_append (playsink->colorbalance_channels, channel);
607 playsink->colorbalance_values[1] = 0;
610 GST_COLOR_BALANCE_CHANNEL (g_object_new (GST_TYPE_COLOR_BALANCE_CHANNEL,
612 channel->label = g_strdup ("HUE");
613 channel->min_value = -1000;
614 channel->max_value = 1000;
615 playsink->colorbalance_channels =
616 g_list_append (playsink->colorbalance_channels, channel);
617 playsink->colorbalance_values[2] = 0;
620 GST_COLOR_BALANCE_CHANNEL (g_object_new (GST_TYPE_COLOR_BALANCE_CHANNEL,
622 channel->label = g_strdup ("SATURATION");
623 channel->min_value = -1000;
624 channel->max_value = 1000;
625 playsink->colorbalance_channels =
626 g_list_append (playsink->colorbalance_channels, channel);
627 playsink->colorbalance_values[3] = 0;
631 disconnect_chain (GstPlayAudioChain * chain, GstPlaySink * playsink)
635 g_signal_handlers_disconnect_by_func (chain->volume, notify_volume_cb,
638 g_signal_handlers_disconnect_by_func (chain->mute, notify_mute_cb,
644 free_chain (GstPlayChain * chain)
648 gst_object_unref (chain->bin);
654 gst_play_sink_dispose (GObject * object)
656 GstPlaySink *playsink;
658 playsink = GST_PLAY_SINK (object);
660 if (playsink->audio_sink != NULL) {
661 gst_element_set_state (playsink->audio_sink, GST_STATE_NULL);
662 gst_object_unref (playsink->audio_sink);
663 playsink->audio_sink = NULL;
665 if (playsink->video_sink != NULL) {
666 gst_element_set_state (playsink->video_sink, GST_STATE_NULL);
667 gst_object_unref (playsink->video_sink);
668 playsink->video_sink = NULL;
670 if (playsink->visualisation != NULL) {
671 gst_element_set_state (playsink->visualisation, GST_STATE_NULL);
672 gst_object_unref (playsink->visualisation);
673 playsink->visualisation = NULL;
675 if (playsink->text_sink != NULL) {
676 gst_element_set_state (playsink->text_sink, GST_STATE_NULL);
677 gst_object_unref (playsink->text_sink);
678 playsink->text_sink = NULL;
681 free_chain ((GstPlayChain *) playsink->videodeinterlacechain);
682 playsink->videodeinterlacechain = NULL;
683 free_chain ((GstPlayChain *) playsink->videochain);
684 playsink->videochain = NULL;
685 free_chain ((GstPlayChain *) playsink->audiochain);
686 playsink->audiochain = NULL;
687 free_chain ((GstPlayChain *) playsink->vischain);
688 playsink->vischain = NULL;
689 free_chain ((GstPlayChain *) playsink->textchain);
690 playsink->textchain = NULL;
692 if (playsink->audio_tee_sink) {
693 gst_object_unref (playsink->audio_tee_sink);
694 playsink->audio_tee_sink = NULL;
697 if (playsink->audio_tee_vissrc) {
698 gst_element_release_request_pad (playsink->audio_tee,
699 playsink->audio_tee_vissrc);
700 gst_object_unref (playsink->audio_tee_vissrc);
701 playsink->audio_tee_vissrc = NULL;
704 if (playsink->audio_tee_asrc) {
705 gst_element_release_request_pad (playsink->audio_tee,
706 playsink->audio_tee_asrc);
707 gst_object_unref (playsink->audio_tee_asrc);
708 playsink->audio_tee_asrc = NULL;
711 g_free (playsink->font_desc);
712 playsink->font_desc = NULL;
714 g_free (playsink->subtitle_encoding);
715 playsink->subtitle_encoding = NULL;
717 playsink->stream_synchronizer = NULL;
719 g_list_foreach (playsink->colorbalance_channels, (GFunc) gst_object_unref,
721 g_list_free (playsink->colorbalance_channels);
722 playsink->colorbalance_channels = NULL;
724 G_OBJECT_CLASS (gst_play_sink_parent_class)->dispose (object);
728 gst_play_sink_finalize (GObject * object)
730 GstPlaySink *playsink;
732 playsink = GST_PLAY_SINK (object);
734 g_static_rec_mutex_free (&playsink->lock);
736 G_OBJECT_CLASS (gst_play_sink_parent_class)->finalize (object);
740 gst_play_sink_set_sink (GstPlaySink * playsink, GstPlaySinkType type,
743 GstElement **elem = NULL, *old = NULL;
745 GST_LOG ("Setting sink %" GST_PTR_FORMAT " as sink type %d", sink, type);
747 GST_PLAY_SINK_LOCK (playsink);
749 case GST_PLAY_SINK_TYPE_AUDIO:
750 case GST_PLAY_SINK_TYPE_AUDIO_RAW:
751 elem = &playsink->audio_sink;
753 case GST_PLAY_SINK_TYPE_VIDEO:
754 case GST_PLAY_SINK_TYPE_VIDEO_RAW:
755 elem = &playsink->video_sink;
757 case GST_PLAY_SINK_TYPE_TEXT:
758 elem = &playsink->text_sink;
766 gst_object_ref (sink);
769 GST_PLAY_SINK_UNLOCK (playsink);
773 gst_element_set_state (old, GST_STATE_NULL);
774 gst_object_unref (old);
779 gst_play_sink_get_sink (GstPlaySink * playsink, GstPlaySinkType type)
781 GstElement *result = NULL;
782 GstElement *elem = NULL, *chainp = NULL;
784 GST_PLAY_SINK_LOCK (playsink);
786 case GST_PLAY_SINK_TYPE_AUDIO:
787 case GST_PLAY_SINK_TYPE_AUDIO_RAW:
789 GstPlayAudioChain *chain;
790 if ((chain = (GstPlayAudioChain *) playsink->audiochain))
791 chainp = chain->sink;
792 elem = playsink->audio_sink;
795 case GST_PLAY_SINK_TYPE_VIDEO:
796 case GST_PLAY_SINK_TYPE_VIDEO_RAW:
798 GstPlayVideoChain *chain;
799 if ((chain = (GstPlayVideoChain *) playsink->videochain))
800 chainp = chain->sink;
801 elem = playsink->video_sink;
804 case GST_PLAY_SINK_TYPE_TEXT:
806 GstPlayTextChain *chain;
807 if ((chain = (GstPlayTextChain *) playsink->textchain))
808 chainp = chain->sink;
809 elem = playsink->text_sink;
816 /* we have an active chain with a sink, get the sink */
817 result = gst_object_ref (chainp);
819 /* nothing found, return last configured sink */
820 if (result == NULL && elem)
821 result = gst_object_ref (elem);
822 GST_PLAY_SINK_UNLOCK (playsink);
828 gst_play_sink_vis_unblocked (GstPad * tee_pad, gboolean blocked,
831 GstPlaySink *playsink;
833 playsink = GST_PLAY_SINK (user_data);
834 /* nothing to do here, we need a dummy callback here to make the async call
836 GST_DEBUG_OBJECT (playsink, "vis pad unblocked");
840 gst_play_sink_vis_blocked (GstPad * tee_pad, gboolean blocked,
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 /* Unblock the pad */
879 gst_pad_set_blocked_async (tee_pad, FALSE, gst_play_sink_vis_unblocked,
881 GST_PLAY_SINK_UNLOCK (playsink);
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_set_blocked_async (chain->blockpad, TRUE, gst_play_sink_vis_blocked,
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_IS_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_IS_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 (GstElement * element, FindPropertyHelper * helper)
1130 if (helper->need_sink && !element_is_sink (element)) {
1131 gst_object_unref (element);
1135 if (!element_has_property (element, helper->prop_name, helper->prop_type)) {
1136 gst_object_unref (element);
1140 GST_INFO_OBJECT (element, "found %s with %s property", helper->prop_name,
1141 (helper->need_sink) ? "sink" : "element");
1142 return 0; /* keep it */
1145 /* FIXME: why not move these functions into core? */
1146 /* find a sink in the hierarchy with a property named @name. This function does
1147 * not increase the refcount of the returned object and thus remains valid as
1148 * long as the bin is valid. */
1150 gst_play_sink_find_property_sinks (GstPlaySink * playsink, GstElement * obj,
1151 const gchar * name, GType expected_type)
1153 GstElement *result = NULL;
1156 if (element_has_property (obj, name, expected_type)) {
1158 } else if (GST_IS_BIN (obj)) {
1159 FindPropertyHelper helper = { name, expected_type, TRUE };
1161 it = gst_bin_iterate_recurse (GST_BIN_CAST (obj));
1162 result = gst_iterator_find_custom (it,
1163 (GCompareFunc) find_property, &helper);
1164 gst_iterator_free (it);
1165 /* we don't need the extra ref */
1167 gst_object_unref (result);
1172 /* find an object in the hierarchy with a property named @name */
1174 gst_play_sink_find_property (GstPlaySink * playsink, GstElement * obj,
1175 const gchar * name, GType expected_type)
1177 GstElement *result = NULL;
1180 if (GST_IS_BIN (obj)) {
1181 FindPropertyHelper helper = { name, expected_type, FALSE };
1183 it = gst_bin_iterate_recurse (GST_BIN_CAST (obj));
1184 result = gst_iterator_find_custom (it,
1185 (GCompareFunc) find_property, &helper);
1186 gst_iterator_free (it);
1188 if (element_has_property (obj, name, expected_type)) {
1190 gst_object_ref (obj);
1197 do_async_start (GstPlaySink * playsink)
1199 GstMessage *message;
1201 if (!playsink->need_async_start) {
1202 GST_INFO_OBJECT (playsink, "no async_start needed");
1206 playsink->async_pending = TRUE;
1208 GST_INFO_OBJECT (playsink, "Sending async_start message");
1209 message = gst_message_new_async_start (GST_OBJECT_CAST (playsink), FALSE);
1210 GST_BIN_CLASS (gst_play_sink_parent_class)->handle_message (GST_BIN_CAST
1211 (playsink), message);
1215 do_async_done (GstPlaySink * playsink)
1217 GstMessage *message;
1219 if (playsink->async_pending) {
1220 GST_INFO_OBJECT (playsink, "Sending async_done message");
1221 message = gst_message_new_async_done (GST_OBJECT_CAST (playsink));
1222 GST_BIN_CLASS (gst_play_sink_parent_class)->handle_message (GST_BIN_CAST
1223 (playsink), message);
1225 playsink->async_pending = FALSE;
1228 playsink->need_async_start = FALSE;
1231 /* try to change the state of an element. This function returns the element when
1232 * the state change could be performed. When this function returns NULL an error
1233 * occured and the element is unreffed if @unref is TRUE. */
1235 try_element (GstPlaySink * playsink, GstElement * element, gboolean unref)
1237 GstStateChangeReturn ret;
1240 ret = gst_element_set_state (element, GST_STATE_READY);
1241 if (ret == GST_STATE_CHANGE_FAILURE) {
1242 GST_DEBUG_OBJECT (playsink, "failed state change..");
1243 gst_element_set_state (element, GST_STATE_NULL);
1245 gst_object_unref (element);
1252 /* make the element (bin) that contains the elements needed to perform
1253 * video display. Only used for *raw* video streams.
1255 * +------------------------------------------------------------+
1257 * | +-------+ +----------+ +----------+ +---------+ |
1258 * | | queue | |colorspace| |videoscale| |videosink| |
1259 * | +-sink src-sink src-sink src-sink | |
1260 * | | +-------+ +----------+ +----------+ +---------+ |
1262 * +------------------------------------------------------------+
1265 static GstPlayVideoDeinterlaceChain *
1266 gen_video_deinterlace_chain (GstPlaySink * playsink)
1268 GstPlayVideoDeinterlaceChain *chain;
1271 GstElement *head = NULL, *prev = NULL;
1273 chain = g_new0 (GstPlayVideoDeinterlaceChain, 1);
1274 chain->chain.playsink = playsink;
1276 GST_DEBUG_OBJECT (playsink, "making video deinterlace chain %p", chain);
1278 /* create a bin to hold objects, as we create them we add them to this bin so
1279 * that when something goes wrong we only need to unref the bin */
1280 chain->chain.bin = gst_bin_new ("vdbin");
1281 bin = GST_BIN_CAST (chain->chain.bin);
1282 gst_object_ref_sink (bin);
1284 GST_DEBUG_OBJECT (playsink, "creating " COLORSPACE);
1285 chain->conv = gst_element_factory_make (COLORSPACE, "vdconv");
1286 if (chain->conv == NULL) {
1287 post_missing_element_message (playsink, COLORSPACE);
1288 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1289 (_("Missing element '%s' - check your GStreamer installation."),
1290 COLORSPACE), ("video rendering might fail"));
1292 gst_bin_add (bin, chain->conv);
1297 GST_DEBUG_OBJECT (playsink, "creating deinterlace");
1298 chain->deinterlace = gst_element_factory_make ("deinterlace", "deinterlace");
1299 if (chain->deinterlace == NULL) {
1300 post_missing_element_message (playsink, "deinterlace");
1301 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1302 (_("Missing element '%s' - check your GStreamer installation."),
1303 "deinterlace"), ("deinterlacing won't work"));
1305 gst_bin_add (bin, chain->deinterlace);
1307 if (!gst_element_link_pads_full (prev, "src", chain->deinterlace, "sink",
1308 GST_PAD_LINK_CHECK_TEMPLATE_CAPS))
1311 head = chain->deinterlace;
1313 prev = chain->deinterlace;
1317 pad = gst_element_get_static_pad (head, "sink");
1318 chain->sinkpad = gst_ghost_pad_new ("sink", pad);
1319 gst_object_unref (pad);
1321 chain->sinkpad = gst_ghost_pad_new_no_target ("sink", GST_PAD_SINK);
1325 pad = gst_element_get_static_pad (prev, "src");
1326 chain->srcpad = gst_ghost_pad_new ("src", pad);
1327 gst_object_unref (pad);
1329 chain->srcpad = gst_ghost_pad_new ("src", chain->sinkpad);
1332 gst_element_add_pad (chain->chain.bin, chain->sinkpad);
1333 gst_element_add_pad (chain->chain.bin, chain->srcpad);
1339 GST_ELEMENT_ERROR (playsink, CORE, PAD,
1340 (NULL), ("Failed to configure the video deinterlace chain."));
1341 free_chain ((GstPlayChain *) chain);
1347 is_valid_color_balance_element (GstElement * element)
1349 GstColorBalance *bal = GST_COLOR_BALANCE (element);
1350 gboolean have_brightness = FALSE;
1351 gboolean have_contrast = FALSE;
1352 gboolean have_hue = FALSE;
1353 gboolean have_saturation = FALSE;
1354 const GList *channels, *l;
1356 channels = gst_color_balance_list_channels (bal);
1357 for (l = channels; l; l = l->next) {
1358 GstColorBalanceChannel *ch = l->data;
1360 if (g_strrstr (ch->label, "BRIGHTNESS"))
1361 have_brightness = TRUE;
1362 else if (g_strrstr (ch->label, "CONTRAST"))
1363 have_contrast = TRUE;
1364 else if (g_strrstr (ch->label, "HUE"))
1366 else if (g_strrstr (ch->label, "SATURATION"))
1367 have_saturation = TRUE;
1370 return have_brightness && have_contrast && have_hue && have_saturation;
1374 iterate_color_balance_elements (gpointer data, gpointer user_data)
1376 gboolean valid = is_valid_color_balance_element (data);
1377 GstColorBalance **cb_out = user_data;
1381 && gst_color_balance_get_balance_type (*cb_out) ==
1382 GST_COLOR_BALANCE_SOFTWARE) {
1383 gst_object_unref (*cb_out);
1384 *cb_out = GST_COLOR_BALANCE (gst_object_ref (data));
1385 } else if (!*cb_out) {
1386 *cb_out = GST_COLOR_BALANCE (gst_object_ref (data));
1390 gst_object_unref (data);
1393 static GstColorBalance *
1394 find_color_balance_element (GstElement * element)
1397 GstColorBalance *cb = NULL;
1399 if (GST_IS_COLOR_BALANCE (element)
1400 && is_valid_color_balance_element (element))
1401 return GST_COLOR_BALANCE (gst_object_ref (element));
1402 else if (!GST_IS_BIN (element))
1405 it = gst_bin_iterate_all_by_interface (GST_BIN (element),
1406 GST_TYPE_COLOR_BALANCE);
1407 while (gst_iterator_foreach (it, iterate_color_balance_elements,
1408 &cb) == GST_ITERATOR_RESYNC)
1409 gst_iterator_resync (it);
1410 gst_iterator_free (it);
1416 colorbalance_value_changed_cb (GstColorBalance * balance,
1417 GstColorBalanceChannel * channel, gint value, GstPlaySink * playsink)
1422 for (i = 0, l = playsink->colorbalance_channels; l; l = l->next, i++) {
1423 GstColorBalanceChannel *proxy = l->data;
1425 if (g_strrstr (channel->label, proxy->label)) {
1428 /* Convert to [0, 1] range */
1431 (gdouble) channel->min_value) / ((gdouble) channel->max_value -
1432 (gdouble) channel->min_value);
1433 /* Convert to proxy range */
1435 proxy->min_value + new_val * ((gdouble) proxy->max_value -
1436 (gdouble) proxy->min_value);
1437 playsink->colorbalance_values[i] = (gint) (0.5 + new_val);
1439 gst_color_balance_value_changed (GST_COLOR_BALANCE (playsink), proxy,
1440 playsink->colorbalance_values[i]);
1447 update_colorbalance (GstPlaySink * playsink)
1449 GstColorBalance *balance = NULL;
1453 GST_OBJECT_LOCK (playsink);
1454 if (playsink->colorbalance_element) {
1456 GST_COLOR_BALANCE (gst_object_ref (playsink->colorbalance_element));
1458 GST_OBJECT_UNLOCK (playsink);
1462 g_signal_handlers_block_by_func (balance,
1463 G_CALLBACK (colorbalance_value_changed_cb), playsink);
1465 for (i = 0, l = playsink->colorbalance_channels; l; l = l->next, i++) {
1466 GstColorBalanceChannel *proxy = l->data;
1467 GstColorBalanceChannel *channel = NULL;
1468 const GList *channels, *k;
1470 channels = gst_color_balance_list_channels (balance);
1471 for (k = channels; k; k = k->next) {
1472 GstColorBalanceChannel *tmp = k->data;
1474 if (g_strrstr (tmp->label, proxy->label)) {
1482 gst_color_balance_set_value (balance, channel,
1483 playsink->colorbalance_values[i]);
1486 g_signal_handlers_unblock_by_func (balance,
1487 G_CALLBACK (colorbalance_value_changed_cb), playsink);
1490 /* make the element (bin) that contains the elements needed to perform
1493 * +------------------------------------------------------------+
1495 * | +-------+ +----------+ +----------+ +---------+ |
1496 * | | queue | |colorspace| |videoscale| |videosink| |
1497 * | +-sink src-sink src-sink src-sink | |
1498 * | | +-------+ +----------+ +----------+ +---------+ |
1500 * +------------------------------------------------------------+
1503 static GstPlayVideoChain *
1504 gen_video_chain (GstPlaySink * playsink, gboolean raw, gboolean async)
1506 GstPlayVideoChain *chain;
1509 GstElement *head = NULL, *prev = NULL, *elem = NULL;
1511 chain = g_new0 (GstPlayVideoChain, 1);
1512 chain->chain.playsink = playsink;
1513 chain->chain.raw = raw;
1515 GST_DEBUG_OBJECT (playsink, "making video chain %p", chain);
1517 if (playsink->video_sink) {
1518 GST_DEBUG_OBJECT (playsink, "trying configured videosink");
1519 chain->sink = try_element (playsink, playsink->video_sink, FALSE);
1521 /* only try fallback if no specific sink was chosen */
1522 if (chain->sink == NULL) {
1523 GST_DEBUG_OBJECT (playsink, "trying autovideosink");
1524 elem = gst_element_factory_make ("autovideosink", "videosink");
1525 chain->sink = try_element (playsink, elem, TRUE);
1527 if (chain->sink == NULL) {
1528 /* if default sink from config.h is different then try it too */
1529 if (strcmp (DEFAULT_VIDEOSINK, "autovideosink")) {
1530 GST_DEBUG_OBJECT (playsink, "trying " DEFAULT_VIDEOSINK);
1531 elem = gst_element_factory_make (DEFAULT_VIDEOSINK, "videosink");
1532 chain->sink = try_element (playsink, elem, TRUE);
1536 playsink->video_sink = gst_object_ref (chain->sink);
1538 if (chain->sink == NULL)
1542 /* if we can disable async behaviour of the sink, we can avoid adding a
1543 * queue for the audio chain. */
1545 gst_play_sink_find_property_sinks (playsink, chain->sink, "async",
1548 GST_DEBUG_OBJECT (playsink, "setting async property to %d on element %s",
1549 async, GST_ELEMENT_NAME (elem));
1550 g_object_set (elem, "async", async, NULL);
1551 chain->async = async;
1553 GST_DEBUG_OBJECT (playsink, "no async property on the sink");
1554 chain->async = TRUE;
1557 /* Make sure the aspect ratio is kept */
1559 gst_play_sink_find_property_sinks (playsink, chain->sink,
1560 "force-aspect-ratio", G_TYPE_BOOLEAN);
1562 g_object_set (elem, "force-aspect-ratio", TRUE, NULL);
1564 /* find ts-offset element */
1565 gst_object_replace ((GstObject **) & chain->ts_offset, (GstObject *)
1566 gst_play_sink_find_property_sinks (playsink, chain->sink, "ts-offset",
1569 /* create a bin to hold objects, as we create them we add them to this bin so
1570 * that when something goes wrong we only need to unref the bin */
1571 chain->chain.bin = gst_bin_new ("vbin");
1572 bin = GST_BIN_CAST (chain->chain.bin);
1573 gst_object_ref_sink (bin);
1574 gst_bin_add (bin, chain->sink);
1576 /* Get the XOverlay element */
1578 GstXOverlay *xoverlay = NULL;
1580 GST_OBJECT_LOCK (playsink);
1581 if (playsink->xoverlay_element)
1582 gst_object_unref (playsink->xoverlay_element);
1583 playsink->xoverlay_element =
1584 GST_X_OVERLAY (gst_bin_get_by_interface (GST_BIN (chain->chain.bin),
1585 GST_TYPE_X_OVERLAY));
1586 if (playsink->xoverlay_element)
1587 xoverlay = GST_X_OVERLAY (gst_object_ref (playsink->xoverlay_element));
1588 GST_OBJECT_UNLOCK (playsink);
1591 if (playsink->xoverlay_handle_set)
1592 gst_x_overlay_set_window_handle (xoverlay, playsink->xoverlay_handle);
1593 if (playsink->xoverlay_handle_events_set)
1594 gst_x_overlay_handle_events (xoverlay,
1595 playsink->xoverlay_handle_events);
1596 if (playsink->xoverlay_render_rectangle_set)
1597 gst_x_overlay_set_render_rectangle (xoverlay,
1598 playsink->xoverlay_x, playsink->xoverlay_y,
1599 playsink->xoverlay_width, playsink->xoverlay_height);
1600 gst_object_unref (xoverlay);
1604 /* decouple decoder from sink, this improves playback quite a lot since the
1605 * decoder can continue while the sink blocks for synchronisation. We don't
1606 * need a lot of buffers as this consumes a lot of memory and we don't want
1607 * too little because else we would be context switching too quickly. */
1608 chain->queue = gst_element_factory_make ("queue", "vqueue");
1609 if (chain->queue == NULL) {
1610 post_missing_element_message (playsink, "queue");
1611 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1612 (_("Missing element '%s' - check your GStreamer installation."),
1613 "queue"), ("video rendering might be suboptimal"));
1617 g_object_set (G_OBJECT (chain->queue), "max-size-buffers", 3,
1618 "max-size-bytes", 0, "max-size-time", (gint64) 0, "silent", TRUE, NULL);
1619 gst_bin_add (bin, chain->queue);
1620 head = prev = chain->queue;
1623 GST_OBJECT_LOCK (playsink);
1624 if (playsink->colorbalance_element) {
1625 g_signal_handlers_disconnect_by_func (playsink->colorbalance_element,
1626 G_CALLBACK (colorbalance_value_changed_cb), playsink);
1627 gst_object_unref (playsink->colorbalance_element);
1629 playsink->colorbalance_element = find_color_balance_element (chain->sink);
1630 GST_OBJECT_UNLOCK (playsink);
1632 if (!(playsink->flags & GST_PLAY_FLAG_NATIVE_VIDEO)
1633 || (!playsink->colorbalance_element
1634 && (playsink->flags & GST_PLAY_FLAG_SOFT_COLORBALANCE))) {
1635 gboolean use_converters = !(playsink->flags & GST_PLAY_FLAG_NATIVE_VIDEO);
1636 gboolean use_balance = !playsink->colorbalance_element
1637 && (playsink->flags & GST_PLAY_FLAG_SOFT_COLORBALANCE);
1639 GST_DEBUG_OBJECT (playsink, "creating videoconverter");
1641 g_object_new (GST_TYPE_PLAY_SINK_VIDEO_CONVERT, "name", "vconv",
1642 "use-converters", use_converters, "use-balance", use_balance, NULL);
1644 GST_OBJECT_LOCK (playsink);
1645 if (use_balance && GST_PLAY_SINK_VIDEO_CONVERT (chain->conv)->balance)
1646 playsink->colorbalance_element =
1647 GST_COLOR_BALANCE (gst_object_ref (GST_PLAY_SINK_VIDEO_CONVERT
1648 (chain->conv)->balance));
1649 GST_OBJECT_UNLOCK (playsink);
1651 gst_bin_add (bin, chain->conv);
1653 if (!gst_element_link_pads_full (prev, "src", chain->conv, "sink",
1654 GST_PAD_LINK_CHECK_TEMPLATE_CAPS))
1662 update_colorbalance (playsink);
1665 GST_DEBUG_OBJECT (playsink, "linking to sink");
1666 if (!gst_element_link_pads_full (prev, "src", chain->sink, NULL,
1667 GST_PAD_LINK_CHECK_TEMPLATE_CAPS))
1671 pad = gst_element_get_static_pad (head, "sink");
1672 chain->sinkpad = gst_ghost_pad_new ("sink", pad);
1673 gst_object_unref (pad);
1675 gst_element_add_pad (chain->chain.bin, chain->sinkpad);
1682 if (!elem && !playsink->video_sink) {
1683 post_missing_element_message (playsink, "autovideosink");
1684 if (strcmp (DEFAULT_VIDEOSINK, "autovideosink")) {
1685 post_missing_element_message (playsink, DEFAULT_VIDEOSINK);
1686 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
1687 (_("Both autovideosink and %s elements are missing."),
1688 DEFAULT_VIDEOSINK), (NULL));
1690 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
1691 (_("The autovideosink element is missing.")), (NULL));
1694 if (playsink->video_sink) {
1695 GST_ELEMENT_ERROR (playsink, CORE, STATE_CHANGE,
1696 (_("Configured videosink %s is not working."),
1697 GST_ELEMENT_NAME (playsink->video_sink)), (NULL));
1698 } else if (strcmp (DEFAULT_VIDEOSINK, "autovideosink")) {
1699 GST_ELEMENT_ERROR (playsink, CORE, STATE_CHANGE,
1700 (_("Both autovideosink and %s elements are not working."),
1701 DEFAULT_VIDEOSINK), (NULL));
1703 GST_ELEMENT_ERROR (playsink, CORE, STATE_CHANGE,
1704 (_("The autovideosink element is not working.")), (NULL));
1707 free_chain ((GstPlayChain *) chain);
1713 GST_ELEMENT_ERROR (playsink, CORE, PAD,
1714 (NULL), ("Failed to configure the video sink."));
1715 /* checking sink made it READY */
1716 gst_element_set_state (chain->sink, GST_STATE_NULL);
1717 /* Remove chain from the bin to allow reuse later */
1718 gst_bin_remove (bin, chain->sink);
1719 free_chain ((GstPlayChain *) chain);
1725 setup_video_chain (GstPlaySink * playsink, gboolean raw, gboolean async)
1728 GstPlayVideoChain *chain;
1729 GstStateChangeReturn ret;
1731 chain = playsink->videochain;
1733 chain->chain.raw = raw;
1735 /* if the chain was active we don't do anything */
1736 if (GST_PLAY_CHAIN (chain)->activated == TRUE)
1739 /* try to set the sink element to READY again */
1740 ret = gst_element_set_state (chain->sink, GST_STATE_READY);
1741 if (ret == GST_STATE_CHANGE_FAILURE)
1744 /* Get the XOverlay element */
1746 GstXOverlay *xoverlay = NULL;
1748 GST_OBJECT_LOCK (playsink);
1749 if (playsink->xoverlay_element)
1750 gst_object_unref (playsink->xoverlay_element);
1751 playsink->xoverlay_element =
1752 GST_X_OVERLAY (gst_bin_get_by_interface (GST_BIN (chain->chain.bin),
1753 GST_TYPE_X_OVERLAY));
1754 if (playsink->xoverlay_element)
1755 xoverlay = GST_X_OVERLAY (gst_object_ref (playsink->xoverlay_element));
1756 GST_OBJECT_UNLOCK (playsink);
1759 if (playsink->xoverlay_handle_set)
1760 gst_x_overlay_set_window_handle (xoverlay, playsink->xoverlay_handle);
1761 if (playsink->xoverlay_handle_events_set)
1762 gst_x_overlay_handle_events (xoverlay,
1763 playsink->xoverlay_handle_events);
1764 if (playsink->xoverlay_render_rectangle_set)
1765 gst_x_overlay_set_render_rectangle (xoverlay,
1766 playsink->xoverlay_x, playsink->xoverlay_y,
1767 playsink->xoverlay_width, playsink->xoverlay_height);
1768 gst_object_unref (xoverlay);
1772 /* find ts-offset element */
1773 gst_object_replace ((GstObject **) & chain->ts_offset, (GstObject *)
1774 gst_play_sink_find_property_sinks (playsink, chain->sink, "ts-offset",
1777 /* if we can disable async behaviour of the sink, we can avoid adding a
1778 * queue for the audio chain. */
1780 gst_play_sink_find_property_sinks (playsink, chain->sink, "async",
1783 GST_DEBUG_OBJECT (playsink, "setting async property to %d on element %s",
1784 async, GST_ELEMENT_NAME (elem));
1785 g_object_set (elem, "async", async, NULL);
1786 chain->async = async;
1788 GST_DEBUG_OBJECT (playsink, "no async property on the sink");
1789 chain->async = TRUE;
1792 /* Make sure the aspect ratio is kept */
1794 gst_play_sink_find_property_sinks (playsink, chain->sink,
1795 "force-aspect-ratio", G_TYPE_BOOLEAN);
1797 g_object_set (elem, "force-aspect-ratio", TRUE, NULL);
1799 GST_OBJECT_LOCK (playsink);
1800 if (playsink->colorbalance_element) {
1801 g_signal_handlers_disconnect_by_func (playsink->colorbalance_element,
1802 G_CALLBACK (colorbalance_value_changed_cb), playsink);
1803 gst_object_unref (playsink->colorbalance_element);
1805 playsink->colorbalance_element = find_color_balance_element (chain->sink);
1806 GST_OBJECT_UNLOCK (playsink);
1809 gboolean use_balance = !playsink->colorbalance_element
1810 && (playsink->flags & GST_PLAY_FLAG_SOFT_COLORBALANCE);
1812 g_object_set (chain->conv, "use-balance", use_balance, NULL);
1814 GST_OBJECT_LOCK (playsink);
1815 if (use_balance && GST_PLAY_SINK_VIDEO_CONVERT (chain->conv)->balance)
1816 playsink->colorbalance_element =
1817 GST_COLOR_BALANCE (gst_object_ref (GST_PLAY_SINK_VIDEO_CONVERT
1818 (chain->conv)->balance));
1819 GST_OBJECT_UNLOCK (playsink);
1822 update_colorbalance (playsink);
1827 /* make an element for playback of video with subtitles embedded.
1828 * Only used for *raw* video streams.
1830 * +--------------------------------------------+
1832 * | +--------+ +-----------------+ |
1833 * | | queue | | subtitleoverlay | |
1834 * video--src sink---video_sink | |
1835 * | +--------+ | src--src
1836 * text------------------text_sink | |
1837 * | +-----------------+ |
1838 * +--------------------------------------------+
1841 static GstPlayTextChain *
1842 gen_text_chain (GstPlaySink * playsink)
1844 GstPlayTextChain *chain;
1847 GstPad *videosinkpad, *textsinkpad, *srcpad;
1849 chain = g_new0 (GstPlayTextChain, 1);
1850 chain->chain.playsink = playsink;
1852 GST_DEBUG_OBJECT (playsink, "making text chain %p", chain);
1854 chain->chain.bin = gst_bin_new ("tbin");
1855 bin = GST_BIN_CAST (chain->chain.bin);
1856 gst_object_ref_sink (bin);
1858 videosinkpad = textsinkpad = srcpad = NULL;
1860 /* first try to hook the text pad to the custom sink */
1861 if (playsink->text_sink) {
1862 GST_DEBUG_OBJECT (playsink, "trying configured textsink");
1863 chain->sink = try_element (playsink, playsink->text_sink, FALSE);
1866 gst_play_sink_find_property_sinks (playsink, chain->sink, "async",
1869 /* make sure the sparse subtitles don't participate in the preroll */
1870 g_object_set (elem, "async", FALSE, NULL);
1871 GST_DEBUG_OBJECT (playsink, "adding custom text sink");
1872 gst_bin_add (bin, chain->sink);
1873 /* NOTE streamsynchronizer needs streams decoupled */
1874 /* make a little queue */
1875 chain->queue = gst_element_factory_make ("queue", "subqueue");
1876 if (chain->queue == NULL) {
1877 post_missing_element_message (playsink, "queue");
1878 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1879 (_("Missing element '%s' - check your GStreamer installation."),
1880 "queue"), ("rendering might be suboptimal"));
1882 g_object_set (G_OBJECT (chain->queue), "max-size-buffers", 3,
1883 "max-size-bytes", 0, "max-size-time", (gint64) 0,
1884 "silent", TRUE, NULL);
1885 gst_bin_add (bin, chain->queue);
1887 /* we have a custom sink, this will be our textsinkpad */
1888 if (gst_element_link_pads_full (chain->queue, "src", chain->sink,
1889 "sink", GST_PAD_LINK_CHECK_TEMPLATE_CAPS)) {
1890 /* we're all fine now and we can add the sink to the chain */
1891 GST_DEBUG_OBJECT (playsink, "using custom text sink");
1892 textsinkpad = gst_element_get_static_pad (chain->queue, "sink");
1894 GST_WARNING_OBJECT (playsink,
1895 "can't find a sink pad on custom text sink");
1896 gst_bin_remove (bin, chain->sink);
1897 gst_bin_remove (bin, chain->queue);
1899 chain->queue = NULL;
1901 /* try to set sync to true but it's no biggie when we can't */
1902 if (chain->sink && (elem =
1903 gst_play_sink_find_property_sinks (playsink, chain->sink,
1904 "sync", G_TYPE_BOOLEAN)))
1905 g_object_set (elem, "sync", TRUE, NULL);
1908 gst_bin_remove (bin, chain->sink);
1910 GST_WARNING_OBJECT (playsink,
1911 "can't find async property in custom text sink");
1914 if (textsinkpad == NULL) {
1915 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1916 (_("Custom text sink element is not usable.")),
1917 ("fallback to default textoverlay"));
1921 if (textsinkpad == NULL) {
1922 if (!(playsink->flags & GST_PLAY_FLAG_NATIVE_VIDEO)) {
1923 /* make a little queue */
1924 chain->queue = gst_element_factory_make ("queue", "vqueue");
1925 if (chain->queue == NULL) {
1926 post_missing_element_message (playsink, "queue");
1927 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1928 (_("Missing element '%s' - check your GStreamer installation."),
1929 "queue"), ("video rendering might be suboptimal"));
1931 g_object_set (G_OBJECT (chain->queue), "max-size-buffers", 3,
1932 "max-size-bytes", 0, "max-size-time", (gint64) 0,
1933 "silent", TRUE, NULL);
1934 gst_bin_add (bin, chain->queue);
1935 videosinkpad = gst_element_get_static_pad (chain->queue, "sink");
1939 gst_element_factory_make ("subtitleoverlay", "suboverlay");
1940 if (chain->overlay == NULL) {
1941 post_missing_element_message (playsink, "subtitleoverlay");
1942 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1943 (_("Missing element '%s' - check your GStreamer installation."),
1944 "subtitleoverlay"), ("subtitle rendering disabled"));
1946 GstElement *element;
1948 gst_bin_add (bin, chain->overlay);
1950 g_object_set (G_OBJECT (chain->overlay), "silent", FALSE, NULL);
1951 if (playsink->font_desc) {
1952 g_object_set (G_OBJECT (chain->overlay), "font-desc",
1953 playsink->font_desc, NULL);
1955 if (playsink->subtitle_encoding) {
1956 g_object_set (G_OBJECT (chain->overlay), "subtitle-encoding",
1957 playsink->subtitle_encoding, NULL);
1960 gst_element_link_pads_full (chain->queue, "src", chain->overlay,
1961 "video_sink", GST_PAD_LINK_CHECK_TEMPLATE_CAPS);
1963 /* make another little queue to decouple streams */
1964 element = gst_element_factory_make ("queue", "subqueue");
1965 if (element == NULL) {
1966 post_missing_element_message (playsink, "queue");
1967 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
1968 (_("Missing element '%s' - check your GStreamer installation."),
1969 "queue"), ("rendering might be suboptimal"));
1971 g_object_set (G_OBJECT (element), "max-size-buffers", 3,
1972 "max-size-bytes", 0, "max-size-time", (gint64) 0,
1973 "silent", TRUE, NULL);
1974 gst_bin_add (bin, element);
1975 if (gst_element_link_pads_full (element, "src", chain->overlay,
1976 "subtitle_sink", GST_PAD_LINK_CHECK_TEMPLATE_CAPS)) {
1977 textsinkpad = gst_element_get_static_pad (element, "sink");
1978 srcpad = gst_element_get_static_pad (chain->overlay, "src");
1980 gst_bin_remove (bin, chain->sink);
1981 gst_bin_remove (bin, chain->overlay);
1983 chain->overlay = NULL;
1984 gst_object_unref (videosinkpad);
1985 videosinkpad = NULL;
1992 if (videosinkpad == NULL) {
1993 /* if we still don't have a videosink, we don't have an overlay. the only
1994 * thing we can do is insert an identity and ghost the src
1996 chain->identity = gst_element_factory_make ("identity", "tidentity");
1997 if (chain->identity == NULL) {
1998 post_missing_element_message (playsink, "identity");
1999 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
2000 (_("Missing element '%s' - check your GStreamer installation."),
2001 "identity"), (NULL));
2003 g_object_set (chain->identity, "signal-handoffs", FALSE, NULL);
2004 g_object_set (chain->identity, "silent", TRUE, NULL);
2005 gst_bin_add (bin, chain->identity);
2006 srcpad = gst_element_get_static_pad (chain->identity, "src");
2007 videosinkpad = gst_element_get_static_pad (chain->identity, "sink");
2011 /* expose the ghostpads */
2013 chain->videosinkpad = gst_ghost_pad_new ("sink", videosinkpad);
2014 gst_object_unref (videosinkpad);
2015 gst_element_add_pad (chain->chain.bin, chain->videosinkpad);
2018 chain->textsinkpad = gst_ghost_pad_new ("text_sink", textsinkpad);
2019 gst_object_unref (textsinkpad);
2020 gst_element_add_pad (chain->chain.bin, chain->textsinkpad);
2023 chain->srcpad = gst_ghost_pad_new ("src", srcpad);
2024 gst_object_unref (srcpad);
2025 gst_element_add_pad (chain->chain.bin, chain->srcpad);
2032 notify_volume_cb (GObject * object, GParamSpec * pspec, GstPlaySink * playsink)
2036 g_object_get (object, "volume", &vol, NULL);
2037 playsink->volume = vol;
2039 g_object_notify (G_OBJECT (playsink), "volume");
2043 notify_mute_cb (GObject * object, GParamSpec * pspec, GstPlaySink * playsink)
2047 g_object_get (object, "mute", &mute, NULL);
2048 playsink->mute = mute;
2050 g_object_notify (G_OBJECT (playsink), "mute");
2053 /* make the chain that contains the elements needed to perform
2056 * We add a tee as the first element so that we can link the visualisation chain
2057 * to it when requested.
2059 * +-------------------------------------------------------------+
2061 * | +---------+ +----------+ +---------+ +---------+ |
2062 * | |audioconv| |audioscale| | volume | |audiosink| |
2063 * | +-srck src-sink src-sink src-sink | |
2064 * | | +---------+ +----------+ +---------+ +---------+ |
2066 * +-------------------------------------------------------------+
2068 static GstPlayAudioChain *
2069 gen_audio_chain (GstPlaySink * playsink, gboolean raw)
2071 GstPlayAudioChain *chain;
2073 gboolean have_volume;
2075 GstElement *head, *prev, *elem = NULL;
2077 chain = g_new0 (GstPlayAudioChain, 1);
2078 chain->chain.playsink = playsink;
2079 chain->chain.raw = raw;
2081 GST_DEBUG_OBJECT (playsink, "making audio chain %p", chain);
2083 if (playsink->audio_sink) {
2084 GST_DEBUG_OBJECT (playsink, "trying configured audiosink %" GST_PTR_FORMAT,
2085 playsink->audio_sink);
2086 chain->sink = try_element (playsink, playsink->audio_sink, FALSE);
2088 /* only try fallback if no specific sink was chosen */
2089 if (chain->sink == NULL) {
2090 GST_DEBUG_OBJECT (playsink, "trying autoaudiosink");
2091 elem = gst_element_factory_make ("autoaudiosink", "audiosink");
2092 chain->sink = try_element (playsink, elem, TRUE);
2094 if (chain->sink == NULL) {
2095 /* if default sink from config.h is different then try it too */
2096 if (strcmp (DEFAULT_AUDIOSINK, "autoaudiosink")) {
2097 GST_DEBUG_OBJECT (playsink, "trying " DEFAULT_AUDIOSINK);
2098 elem = gst_element_factory_make (DEFAULT_AUDIOSINK, "audiosink");
2099 chain->sink = try_element (playsink, elem, TRUE);
2103 playsink->audio_sink = gst_object_ref (chain->sink);
2105 if (chain->sink == NULL)
2108 chain->chain.bin = gst_bin_new ("abin");
2109 bin = GST_BIN_CAST (chain->chain.bin);
2110 gst_object_ref_sink (bin);
2111 gst_bin_add (bin, chain->sink);
2113 /* we have to add a queue when we need to decouple for the video sink in
2114 * visualisations and for streamsynchronizer */
2115 GST_DEBUG_OBJECT (playsink, "adding audio queue");
2116 chain->queue = gst_element_factory_make ("queue", "aqueue");
2117 if (chain->queue == NULL) {
2118 post_missing_element_message (playsink, "queue");
2119 GST_ELEMENT_WARNING (playsink, CORE, MISSING_PLUGIN,
2120 (_("Missing element '%s' - check your GStreamer installation."),
2121 "queue"), ("audio playback and visualizations might not work"));
2125 g_object_set (chain->queue, "silent", TRUE, NULL);
2126 gst_bin_add (bin, chain->queue);
2127 prev = head = chain->queue;
2130 /* find ts-offset element */
2131 gst_object_replace ((GstObject **) & chain->ts_offset, (GstObject *)
2132 gst_play_sink_find_property_sinks (playsink, chain->sink, "ts-offset",
2135 /* check if the sink, or something within the sink, has the volume property.
2136 * If it does we don't need to add a volume element. */
2138 gst_play_sink_find_property_sinks (playsink, chain->sink, "volume",
2141 chain->volume = elem;
2143 g_signal_connect (chain->volume, "notify::volume",
2144 G_CALLBACK (notify_volume_cb), playsink);
2146 GST_DEBUG_OBJECT (playsink, "the sink has a volume property");
2148 chain->sink_volume = TRUE;
2149 /* if the sink also has a mute property we can use this as well. We'll only
2150 * use the mute property if there is a volume property. We can simulate the
2151 * mute with the volume otherwise. */
2153 gst_play_sink_find_property_sinks (playsink, chain->sink, "mute",
2156 GST_DEBUG_OBJECT (playsink, "the sink has a mute property");
2157 g_signal_connect (chain->mute, "notify::mute",
2158 G_CALLBACK (notify_mute_cb), playsink);
2160 /* use the sink to control the volume and mute */
2161 if (playsink->volume_changed) {
2162 g_object_set (G_OBJECT (chain->volume), "volume", playsink->volume, NULL);
2163 playsink->volume_changed = FALSE;
2165 if (playsink->mute_changed) {
2167 g_object_set (chain->mute, "mute", playsink->mute, NULL);
2170 g_object_set (chain->volume, "volume", (gdouble) 0.0, NULL);
2172 playsink->mute_changed = FALSE;
2175 /* no volume, we need to add a volume element when we can */
2176 GST_DEBUG_OBJECT (playsink, "the sink has no volume property");
2177 have_volume = FALSE;
2178 chain->sink_volume = FALSE;
2181 if (!(playsink->flags & GST_PLAY_FLAG_NATIVE_AUDIO) || (!have_volume
2182 && (playsink->flags & GST_PLAY_FLAG_SOFT_VOLUME))) {
2183 gboolean use_converters = !(playsink->flags & GST_PLAY_FLAG_NATIVE_AUDIO);
2184 gboolean use_volume =
2185 !have_volume && (playsink->flags & GST_PLAY_FLAG_SOFT_VOLUME);
2186 GST_DEBUG_OBJECT (playsink,
2187 "creating audioconvert with use-converters %d, use-volume %d",
2188 use_converters, use_volume);
2190 g_object_new (GST_TYPE_PLAY_SINK_AUDIO_CONVERT, "name", "aconv",
2191 "use-converters", use_converters, "use-volume", use_volume, NULL);
2192 gst_bin_add (bin, chain->conv);
2194 if (!gst_element_link_pads_full (prev, "src", chain->conv, "sink",
2195 GST_PAD_LINK_CHECK_TEMPLATE_CAPS))
2202 if (!have_volume && (playsink->flags & GST_PLAY_FLAG_SOFT_VOLUME)) {
2203 GstPlaySinkAudioConvert *conv =
2204 GST_PLAY_SINK_AUDIO_CONVERT_CAST (chain->conv);
2207 chain->volume = conv->volume;
2210 g_signal_connect (chain->volume, "notify::volume",
2211 G_CALLBACK (notify_volume_cb), playsink);
2213 /* volume also has the mute property */
2214 chain->mute = chain->volume;
2215 g_signal_connect (chain->mute, "notify::mute",
2216 G_CALLBACK (notify_mute_cb), playsink);
2218 /* configure with the latest volume and mute */
2219 g_object_set (G_OBJECT (chain->volume), "volume", playsink->volume,
2221 g_object_set (G_OBJECT (chain->mute), "mute", playsink->mute, NULL);
2227 /* we only have to link to the previous element if we have something in
2228 * front of the sink */
2229 GST_DEBUG_OBJECT (playsink, "linking to sink");
2230 if (!gst_element_link_pads_full (prev, "src", chain->sink, NULL,
2231 GST_PAD_LINK_CHECK_TEMPLATE_CAPS))
2235 /* post a warning if we have no way to configure the volume */
2237 GST_ELEMENT_WARNING (playsink, STREAM, NOT_IMPLEMENTED,
2238 (_("No volume control found")), ("Volume/mute is not available"));
2241 /* and ghost the sinkpad of the headmost element */
2242 GST_DEBUG_OBJECT (playsink, "ghosting sink pad");
2243 pad = gst_element_get_static_pad (head, "sink");
2244 chain->sinkpad = gst_ghost_pad_new ("sink", pad);
2245 gst_object_unref (pad);
2246 gst_element_add_pad (chain->chain.bin, chain->sinkpad);
2253 if (!elem && !playsink->audio_sink) {
2254 post_missing_element_message (playsink, "autoaudiosink");
2255 if (strcmp (DEFAULT_AUDIOSINK, "autoaudiosink")) {
2256 post_missing_element_message (playsink, DEFAULT_AUDIOSINK);
2257 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
2258 (_("Both autoaudiosink and %s elements are missing."),
2259 DEFAULT_AUDIOSINK), (NULL));
2261 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
2262 (_("The autoaudiosink element is missing.")), (NULL));
2265 if (playsink->audio_sink) {
2266 GST_ELEMENT_ERROR (playsink, CORE, STATE_CHANGE,
2267 (_("Configured audiosink %s is not working."),
2268 GST_ELEMENT_NAME (playsink->audio_sink)), (NULL));
2269 } else if (strcmp (DEFAULT_AUDIOSINK, "autoaudiosink")) {
2270 GST_ELEMENT_ERROR (playsink, CORE, STATE_CHANGE,
2271 (_("Both autoaudiosink and %s elements are not working."),
2272 DEFAULT_AUDIOSINK), (NULL));
2274 GST_ELEMENT_ERROR (playsink, CORE, STATE_CHANGE,
2275 (_("The autoaudiosink element is not working.")), (NULL));
2278 free_chain ((GstPlayChain *) chain);
2283 GST_ELEMENT_ERROR (playsink, CORE, PAD,
2284 (NULL), ("Failed to configure the audio sink."));
2285 /* checking sink made it READY */
2286 gst_element_set_state (chain->sink, GST_STATE_NULL);
2287 /* Remove chain from the bin to allow reuse later */
2288 gst_bin_remove (bin, chain->sink);
2289 free_chain ((GstPlayChain *) chain);
2295 setup_audio_chain (GstPlaySink * playsink, gboolean raw)
2298 GstPlayAudioChain *chain;
2299 GstStateChangeReturn ret;
2300 GstPlaySinkAudioConvert *conv;
2302 chain = playsink->audiochain;
2303 conv = GST_PLAY_SINK_AUDIO_CONVERT_CAST (chain->conv);
2305 chain->chain.raw = raw;
2307 /* if the chain was active we don't do anything */
2308 if (GST_PLAY_CHAIN (chain)->activated == TRUE)
2311 /* try to set the sink element to READY again */
2312 ret = gst_element_set_state (chain->sink, GST_STATE_READY);
2313 if (ret == GST_STATE_CHANGE_FAILURE)
2316 /* find ts-offset element */
2317 gst_object_replace ((GstObject **) & chain->ts_offset, (GstObject *)
2318 gst_play_sink_find_property_sinks (playsink, chain->sink, "ts-offset",
2321 /* check if the sink, or something within the sink, has the volume property.
2322 * If it does we don't need to add a volume element. */
2324 gst_play_sink_find_property_sinks (playsink, chain->sink, "volume",
2327 chain->volume = elem;
2329 if (playsink->volume_changed) {
2330 GST_DEBUG_OBJECT (playsink, "the sink has a volume property, setting %f",
2332 /* use the sink to control the volume */
2333 g_object_set (G_OBJECT (chain->volume), "volume", playsink->volume, NULL);
2334 playsink->volume_changed = FALSE;
2337 g_signal_connect (chain->volume, "notify::volume",
2338 G_CALLBACK (notify_volume_cb), playsink);
2339 /* if the sink also has a mute property we can use this as well. We'll only
2340 * use the mute property if there is a volume property. We can simulate the
2341 * mute with the volume otherwise. */
2343 gst_play_sink_find_property_sinks (playsink, chain->sink, "mute",
2346 GST_DEBUG_OBJECT (playsink, "the sink has a mute property");
2347 g_signal_connect (chain->mute, "notify::mute",
2348 G_CALLBACK (notify_mute_cb), playsink);
2351 g_object_set (chain->conv, "use-volume", FALSE, NULL);
2353 /* no volume, we need to add a volume element when we can */
2354 g_object_set (chain->conv, "use-volume",
2355 ! !(playsink->flags & GST_PLAY_FLAG_SOFT_VOLUME), NULL);
2356 GST_DEBUG_OBJECT (playsink, "the sink has no volume property");
2358 /* Disconnect signals */
2359 disconnect_chain (chain, playsink);
2361 if (conv->volume && (playsink->flags & GST_PLAY_FLAG_SOFT_VOLUME)) {
2362 chain->volume = conv->volume;
2363 chain->mute = chain->volume;
2365 g_signal_connect (chain->volume, "notify::volume",
2366 G_CALLBACK (notify_volume_cb), playsink);
2368 g_signal_connect (chain->mute, "notify::mute",
2369 G_CALLBACK (notify_mute_cb), playsink);
2371 /* configure with the latest volume and mute */
2372 g_object_set (G_OBJECT (chain->volume), "volume", playsink->volume, NULL);
2373 g_object_set (G_OBJECT (chain->mute), "mute", playsink->mute, NULL);
2376 GST_DEBUG_OBJECT (playsink, "reusing existing volume element");
2382 * +-------------------------------------------------------------------+
2384 * | +----------+ +------------+ +----------+ +-------+ |
2385 * | | visqueue | | audioconv | | audiores | | vis | |
2386 * | +-sink src-sink + samp src-sink src-sink src-+ |
2387 * | | +----------+ +------------+ +----------+ +-------+ | |
2389 * +-------------------------------------------------------------------+
2392 static GstPlayVisChain *
2393 gen_vis_chain (GstPlaySink * playsink)
2395 GstPlayVisChain *chain;
2401 chain = g_new0 (GstPlayVisChain, 1);
2402 chain->chain.playsink = playsink;
2404 GST_DEBUG_OBJECT (playsink, "making vis chain %p", chain);
2406 chain->chain.bin = gst_bin_new ("visbin");
2407 bin = GST_BIN_CAST (chain->chain.bin);
2408 gst_object_ref_sink (bin);
2410 /* we're queuing raw audio here, we can remove this queue when we can disable
2411 * async behaviour in the video sink. */
2412 chain->queue = gst_element_factory_make ("queue", "visqueue");
2413 if (chain->queue == NULL)
2415 g_object_set (chain->queue, "silent", TRUE, NULL);
2416 gst_bin_add (bin, chain->queue);
2418 chain->conv = gst_element_factory_make ("audioconvert", "aconv");
2419 if (chain->conv == NULL)
2420 goto no_audioconvert;
2421 gst_bin_add (bin, chain->conv);
2423 chain->resample = gst_element_factory_make ("audioresample", "aresample");
2424 if (chain->resample == NULL)
2425 goto no_audioresample;
2426 gst_bin_add (bin, chain->resample);
2428 /* this pad will be used for blocking the dataflow and switching the vis
2430 chain->blockpad = gst_element_get_static_pad (chain->resample, "src");
2432 if (playsink->visualisation) {
2433 GST_DEBUG_OBJECT (playsink, "trying configure vis");
2434 chain->vis = try_element (playsink, playsink->visualisation, FALSE);
2436 if (chain->vis == NULL) {
2437 GST_DEBUG_OBJECT (playsink, "trying goom");
2438 elem = gst_element_factory_make ("goom", "vis");
2439 chain->vis = try_element (playsink, elem, TRUE);
2441 if (chain->vis == NULL)
2444 gst_bin_add (bin, chain->vis);
2446 res = gst_element_link_pads_full (chain->queue, "src", chain->conv, "sink",
2447 GST_PAD_LINK_CHECK_NOTHING);
2449 gst_element_link_pads_full (chain->conv, "src", chain->resample, "sink",
2450 GST_PAD_LINK_CHECK_NOTHING);
2452 gst_element_link_pads_full (chain->resample, "src", chain->vis, "sink",
2453 GST_PAD_LINK_CHECK_NOTHING);
2457 chain->vissinkpad = gst_element_get_static_pad (chain->vis, "sink");
2458 chain->vissrcpad = gst_element_get_static_pad (chain->vis, "src");
2460 pad = gst_element_get_static_pad (chain->queue, "sink");
2461 chain->sinkpad = gst_ghost_pad_new ("sink", pad);
2462 gst_object_unref (pad);
2463 gst_element_add_pad (chain->chain.bin, chain->sinkpad);
2465 chain->srcpad = gst_ghost_pad_new ("src", chain->vissrcpad);
2466 gst_element_add_pad (chain->chain.bin, chain->srcpad);
2473 post_missing_element_message (playsink, "queue");
2474 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
2475 (_("Missing element '%s' - check your GStreamer installation."),
2477 free_chain ((GstPlayChain *) chain);
2482 post_missing_element_message (playsink, "audioconvert");
2483 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
2484 (_("Missing element '%s' - check your GStreamer installation."),
2485 "audioconvert"), ("possibly a liboil version mismatch?"));
2486 free_chain ((GstPlayChain *) chain);
2491 post_missing_element_message (playsink, "audioresample");
2492 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
2493 (_("Missing element '%s' - check your GStreamer installation."),
2494 "audioresample"), (NULL));
2495 free_chain ((GstPlayChain *) chain);
2500 post_missing_element_message (playsink, "goom");
2501 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
2502 (_("Missing element '%s' - check your GStreamer installation."),
2504 free_chain ((GstPlayChain *) chain);
2509 GST_ELEMENT_ERROR (playsink, CORE, PAD,
2510 (NULL), ("Failed to configure the visualisation element."));
2511 /* element made it to READY */
2512 gst_element_set_state (chain->vis, GST_STATE_NULL);
2513 free_chain ((GstPlayChain *) chain);
2518 /* this function is called when all the request pads are requested and when we
2519 * have to construct the final pipeline. Based on the flags we construct the
2520 * final output pipelines.
2523 gst_play_sink_reconfigure (GstPlaySink * playsink)
2526 gboolean need_audio, need_video, need_deinterlace, need_vis, need_text;
2528 GST_DEBUG_OBJECT (playsink, "reconfiguring");
2530 /* assume we need nothing */
2531 need_audio = need_video = need_deinterlace = need_vis = need_text = FALSE;
2533 GST_PLAY_SINK_LOCK (playsink);
2534 GST_OBJECT_LOCK (playsink);
2535 /* get flags, there are protected with the object lock */
2536 flags = playsink->flags;
2537 GST_OBJECT_UNLOCK (playsink);
2539 /* figure out which components we need */
2540 if (flags & GST_PLAY_FLAG_TEXT && playsink->text_pad) {
2541 /* we have subtitles and we are requested to show it */
2545 GST_OBJECT_LOCK (playsink);
2546 if (playsink->xoverlay_element)
2547 gst_object_unref (playsink->xoverlay_element);
2548 playsink->xoverlay_element = NULL;
2550 if (playsink->colorbalance_element) {
2551 g_signal_handlers_disconnect_by_func (playsink->colorbalance_element,
2552 G_CALLBACK (colorbalance_value_changed_cb), playsink);
2553 gst_object_unref (playsink->colorbalance_element);
2555 playsink->colorbalance_element = NULL;
2556 GST_OBJECT_UNLOCK (playsink);
2558 if (((flags & GST_PLAY_FLAG_VIDEO)
2559 || (flags & GST_PLAY_FLAG_NATIVE_VIDEO)) && playsink->video_pad) {
2560 /* we have video and we are requested to show it */
2563 /* we only deinterlace if native video is not requested and
2564 * we have raw video */
2565 if ((flags & GST_PLAY_FLAG_DEINTERLACE)
2566 && !(flags & GST_PLAY_FLAG_NATIVE_VIDEO) && playsink->video_pad_raw)
2567 need_deinterlace = TRUE;
2570 if (playsink->audio_pad) {
2571 if ((flags & GST_PLAY_FLAG_AUDIO) || (flags & GST_PLAY_FLAG_NATIVE_AUDIO)) {
2574 if (playsink->audio_pad_raw) {
2575 /* only can do vis with raw uncompressed audio */
2576 if (flags & GST_PLAY_FLAG_VIS && !need_video) {
2577 /* also add video when we add visualisation */
2584 /* we have a text_pad and we need text rendering, in this case we need a
2585 * video_pad to combine the video with the text or visualizations */
2586 if (need_text && !need_video && !playsink->text_sink) {
2587 if (playsink->video_pad) {
2589 } else if (need_audio) {
2590 GST_ELEMENT_WARNING (playsink, STREAM, FORMAT,
2591 (_("Can't play a text file without video or visualizations.")),
2592 ("Have text pad but no video pad or visualizations"));
2595 GST_ELEMENT_ERROR (playsink, STREAM, FORMAT,
2596 (_("Can't play a text file without video or visualizations.")),
2597 ("Have text pad but no video pad or visualizations"));
2598 GST_PLAY_SINK_UNLOCK (playsink);
2603 GST_DEBUG_OBJECT (playsink, "audio:%d, video:%d, vis:%d, text:%d", need_audio,
2604 need_video, need_vis, need_text);
2606 /* set up video pipeline */
2608 gboolean raw, async;
2610 /* we need a raw sink when we do vis or when we have a raw pad */
2611 raw = need_vis ? TRUE : playsink->video_pad_raw;
2612 /* we try to set the sink async=FALSE when we need vis, this way we can
2613 * avoid a queue in the audio chain. */
2616 GST_DEBUG_OBJECT (playsink, "adding video, raw %d",
2617 playsink->video_pad_raw);
2619 if (playsink->videochain) {
2620 /* try to reactivate the chain */
2621 if (!setup_video_chain (playsink, raw, async)) {
2622 if (playsink->video_sinkpad_stream_synchronizer) {
2623 gst_element_release_request_pad (GST_ELEMENT_CAST
2624 (playsink->stream_synchronizer),
2625 playsink->video_sinkpad_stream_synchronizer);
2626 gst_object_unref (playsink->video_sinkpad_stream_synchronizer);
2627 playsink->video_sinkpad_stream_synchronizer = NULL;
2628 gst_object_unref (playsink->video_srcpad_stream_synchronizer);
2629 playsink->video_srcpad_stream_synchronizer = NULL;
2632 add_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE);
2634 /* Remove the sink from the bin to keep its state
2635 * and unparent it to allow reuse */
2636 if (playsink->videochain->sink)
2637 gst_bin_remove (GST_BIN_CAST (playsink->videochain->chain.bin),
2638 playsink->videochain->sink);
2640 activate_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE);
2641 free_chain ((GstPlayChain *) playsink->videochain);
2642 playsink->videochain = NULL;
2646 if (!playsink->videochain)
2647 playsink->videochain = gen_video_chain (playsink, raw, async);
2648 if (!playsink->videochain)
2651 if (!playsink->video_sinkpad_stream_synchronizer) {
2654 playsink->video_sinkpad_stream_synchronizer =
2655 gst_element_get_request_pad (GST_ELEMENT_CAST
2656 (playsink->stream_synchronizer), "sink_%d");
2657 it = gst_pad_iterate_internal_links
2658 (playsink->video_sinkpad_stream_synchronizer);
2660 gst_iterator_next (it,
2661 (gpointer *) & playsink->video_srcpad_stream_synchronizer);
2662 g_assert (playsink->video_srcpad_stream_synchronizer);
2663 gst_iterator_free (it);
2666 if (playsink->video_pad)
2667 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (playsink->video_pad),
2668 playsink->video_sinkpad_stream_synchronizer);
2670 if (need_deinterlace) {
2671 if (!playsink->videodeinterlacechain)
2672 playsink->videodeinterlacechain =
2673 gen_video_deinterlace_chain (playsink);
2674 if (!playsink->videodeinterlacechain)
2677 GST_DEBUG_OBJECT (playsink, "adding video deinterlace chain");
2679 GST_DEBUG_OBJECT (playsink, "setting up deinterlacing chain");
2681 add_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain), TRUE);
2682 activate_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain), TRUE);
2684 gst_pad_link_full (playsink->video_srcpad_stream_synchronizer,
2685 playsink->videodeinterlacechain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2687 if (playsink->videodeinterlacechain) {
2688 add_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain), FALSE);
2689 activate_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain),
2694 GST_DEBUG_OBJECT (playsink, "adding video chain");
2695 add_chain (GST_PLAY_CHAIN (playsink->videochain), TRUE);
2696 activate_chain (GST_PLAY_CHAIN (playsink->videochain), TRUE);
2697 /* if we are not part of vis or subtitles, set the ghostpad target */
2698 if (!need_vis && !need_text && (!playsink->textchain
2699 || !playsink->text_pad)) {
2700 GST_DEBUG_OBJECT (playsink, "ghosting video sinkpad");
2701 if (need_deinterlace)
2702 gst_pad_link_full (playsink->videodeinterlacechain->srcpad,
2703 playsink->videochain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2705 gst_pad_link_full (playsink->video_srcpad_stream_synchronizer,
2706 playsink->videochain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2709 GST_DEBUG_OBJECT (playsink, "no video needed");
2710 if (playsink->videochain) {
2711 GST_DEBUG_OBJECT (playsink, "removing video chain");
2712 if (playsink->vischain) {
2715 GST_DEBUG_OBJECT (playsink, "unlinking vis chain");
2717 /* also had visualisation, release the tee srcpad before we then
2718 * unlink the video from it */
2719 if (playsink->audio_tee_vissrc) {
2720 gst_element_release_request_pad (playsink->audio_tee,
2721 playsink->audio_tee_vissrc);
2722 gst_object_unref (playsink->audio_tee_vissrc);
2723 playsink->audio_tee_vissrc = NULL;
2726 gst_element_get_static_pad (playsink->vischain->chain.bin, "src");
2727 gst_pad_unlink (srcpad, playsink->videochain->sinkpad);
2730 if (playsink->video_sinkpad_stream_synchronizer) {
2731 gst_element_release_request_pad (GST_ELEMENT_CAST
2732 (playsink->stream_synchronizer),
2733 playsink->video_sinkpad_stream_synchronizer);
2734 gst_object_unref (playsink->video_sinkpad_stream_synchronizer);
2735 playsink->video_sinkpad_stream_synchronizer = NULL;
2736 gst_object_unref (playsink->video_srcpad_stream_synchronizer);
2737 playsink->video_srcpad_stream_synchronizer = NULL;
2740 add_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE);
2741 activate_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE);
2742 if (playsink->videochain->ts_offset)
2743 gst_object_unref (playsink->videochain->ts_offset);
2744 playsink->videochain->ts_offset = NULL;
2747 if (playsink->videodeinterlacechain) {
2748 add_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain), FALSE);
2749 activate_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain), FALSE);
2752 if (playsink->video_pad)
2753 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (playsink->video_pad), NULL);
2759 GST_DEBUG_OBJECT (playsink, "adding audio");
2761 /* get a raw sink if we are asked for a raw pad */
2762 raw = playsink->audio_pad_raw;
2764 if (playsink->audiochain) {
2765 /* try to reactivate the chain */
2766 if (!setup_audio_chain (playsink, raw)) {
2767 GST_DEBUG_OBJECT (playsink, "removing current audio chain");
2768 if (playsink->audio_tee_asrc) {
2769 gst_element_release_request_pad (playsink->audio_tee,
2770 playsink->audio_tee_asrc);
2771 gst_object_unref (playsink->audio_tee_asrc);
2772 playsink->audio_tee_asrc = NULL;
2775 if (playsink->audio_sinkpad_stream_synchronizer) {
2776 gst_element_release_request_pad (GST_ELEMENT_CAST
2777 (playsink->stream_synchronizer),
2778 playsink->audio_sinkpad_stream_synchronizer);
2779 gst_object_unref (playsink->audio_sinkpad_stream_synchronizer);
2780 playsink->audio_sinkpad_stream_synchronizer = NULL;
2781 gst_object_unref (playsink->audio_srcpad_stream_synchronizer);
2782 playsink->audio_srcpad_stream_synchronizer = NULL;
2785 add_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE);
2787 /* Remove the sink from the bin to keep its state
2788 * and unparent it to allow reuse */
2789 if (playsink->audiochain->sink)
2790 gst_bin_remove (GST_BIN_CAST (playsink->audiochain->chain.bin),
2791 playsink->audiochain->sink);
2793 activate_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE);
2794 disconnect_chain (playsink->audiochain, playsink);
2795 playsink->audiochain->volume = NULL;
2796 playsink->audiochain->mute = NULL;
2797 if (playsink->audiochain->ts_offset)
2798 gst_object_unref (playsink->audiochain->ts_offset);
2799 playsink->audiochain->ts_offset = NULL;
2800 free_chain ((GstPlayChain *) playsink->audiochain);
2801 playsink->audiochain = NULL;
2802 playsink->volume_changed = playsink->mute_changed = FALSE;
2806 if (!playsink->audiochain) {
2807 GST_DEBUG_OBJECT (playsink, "creating new audio chain");
2808 playsink->audiochain = gen_audio_chain (playsink, raw);
2811 if (!playsink->audio_sinkpad_stream_synchronizer) {
2814 playsink->audio_sinkpad_stream_synchronizer =
2815 gst_element_get_request_pad (GST_ELEMENT_CAST
2816 (playsink->stream_synchronizer), "sink_%d");
2817 it = gst_pad_iterate_internal_links
2818 (playsink->audio_sinkpad_stream_synchronizer);
2820 gst_iterator_next (it,
2821 (gpointer *) & playsink->audio_srcpad_stream_synchronizer);
2822 g_assert (playsink->audio_srcpad_stream_synchronizer);
2823 gst_iterator_free (it);
2826 if (playsink->audiochain) {
2827 GST_DEBUG_OBJECT (playsink, "adding audio chain");
2828 if (playsink->audio_tee_asrc == NULL) {
2829 playsink->audio_tee_asrc =
2830 gst_element_get_request_pad (playsink->audio_tee, "src%d");
2832 add_chain (GST_PLAY_CHAIN (playsink->audiochain), TRUE);
2833 activate_chain (GST_PLAY_CHAIN (playsink->audiochain), TRUE);
2834 gst_pad_link_full (playsink->audio_tee_asrc,
2835 playsink->audio_sinkpad_stream_synchronizer,
2836 GST_PAD_LINK_CHECK_NOTHING);
2837 gst_pad_link_full (playsink->audio_srcpad_stream_synchronizer,
2838 playsink->audiochain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2841 GST_DEBUG_OBJECT (playsink, "no audio needed");
2842 /* we have no audio or we are requested to not play audio */
2843 if (playsink->audiochain) {
2844 GST_DEBUG_OBJECT (playsink, "removing audio chain");
2845 /* release the audio pad */
2846 if (playsink->audio_tee_asrc) {
2847 gst_element_release_request_pad (playsink->audio_tee,
2848 playsink->audio_tee_asrc);
2849 gst_object_unref (playsink->audio_tee_asrc);
2850 playsink->audio_tee_asrc = NULL;
2853 if (playsink->audio_sinkpad_stream_synchronizer) {
2854 gst_element_release_request_pad (GST_ELEMENT_CAST
2855 (playsink->stream_synchronizer),
2856 playsink->audio_sinkpad_stream_synchronizer);
2857 gst_object_unref (playsink->audio_sinkpad_stream_synchronizer);
2858 playsink->audio_sinkpad_stream_synchronizer = NULL;
2859 gst_object_unref (playsink->audio_srcpad_stream_synchronizer);
2860 playsink->audio_srcpad_stream_synchronizer = NULL;
2863 if (playsink->audiochain->sink_volume) {
2864 disconnect_chain (playsink->audiochain, playsink);
2865 playsink->audiochain->volume = NULL;
2866 playsink->audiochain->mute = NULL;
2867 if (playsink->audiochain->ts_offset)
2868 gst_object_unref (playsink->audiochain->ts_offset);
2869 playsink->audiochain->ts_offset = NULL;
2871 add_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE);
2872 activate_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE);
2879 if (!playsink->vischain)
2880 playsink->vischain = gen_vis_chain (playsink);
2882 GST_DEBUG_OBJECT (playsink, "adding visualisation");
2884 if (playsink->vischain) {
2885 GST_DEBUG_OBJECT (playsink, "setting up vis chain");
2887 gst_element_get_static_pad (playsink->vischain->chain.bin, "src");
2888 add_chain (GST_PLAY_CHAIN (playsink->vischain), TRUE);
2889 activate_chain (GST_PLAY_CHAIN (playsink->vischain), TRUE);
2890 if (playsink->audio_tee_vissrc == NULL) {
2891 playsink->audio_tee_vissrc =
2892 gst_element_get_request_pad (playsink->audio_tee, "src%d");
2894 gst_pad_link_full (playsink->audio_tee_vissrc,
2895 playsink->vischain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2896 gst_pad_link_full (srcpad, playsink->video_sinkpad_stream_synchronizer,
2897 GST_PAD_LINK_CHECK_NOTHING);
2898 gst_pad_link_full (playsink->video_srcpad_stream_synchronizer,
2899 playsink->videochain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2900 gst_object_unref (srcpad);
2903 GST_DEBUG_OBJECT (playsink, "no vis needed");
2904 if (playsink->vischain) {
2905 if (playsink->audio_tee_vissrc) {
2906 gst_element_release_request_pad (playsink->audio_tee,
2907 playsink->audio_tee_vissrc);
2908 gst_object_unref (playsink->audio_tee_vissrc);
2909 playsink->audio_tee_vissrc = NULL;
2911 GST_DEBUG_OBJECT (playsink, "removing vis chain");
2912 add_chain (GST_PLAY_CHAIN (playsink->vischain), FALSE);
2913 activate_chain (GST_PLAY_CHAIN (playsink->vischain), FALSE);
2918 GST_DEBUG_OBJECT (playsink, "adding text");
2919 if (!playsink->textchain) {
2920 GST_DEBUG_OBJECT (playsink, "creating text chain");
2921 playsink->textchain = gen_text_chain (playsink);
2923 if (playsink->textchain) {
2926 GST_DEBUG_OBJECT (playsink, "adding text chain");
2927 if (playsink->textchain->overlay)
2928 g_object_set (G_OBJECT (playsink->textchain->overlay), "silent", FALSE,
2930 add_chain (GST_PLAY_CHAIN (playsink->textchain), TRUE);
2932 if (!playsink->text_sinkpad_stream_synchronizer) {
2933 playsink->text_sinkpad_stream_synchronizer =
2934 gst_element_get_request_pad (GST_ELEMENT_CAST
2935 (playsink->stream_synchronizer), "sink_%d");
2936 it = gst_pad_iterate_internal_links
2937 (playsink->text_sinkpad_stream_synchronizer);
2939 gst_iterator_next (it,
2940 (gpointer *) & playsink->text_srcpad_stream_synchronizer);
2941 g_assert (playsink->text_srcpad_stream_synchronizer);
2942 gst_iterator_free (it);
2944 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (playsink->text_pad),
2945 playsink->text_sinkpad_stream_synchronizer);
2946 gst_pad_link_full (playsink->text_srcpad_stream_synchronizer,
2947 playsink->textchain->textsinkpad, GST_PAD_LINK_CHECK_NOTHING);
2950 if (need_vis || need_video) {
2955 gst_element_get_static_pad (playsink->vischain->chain.bin, "src");
2956 gst_pad_unlink (srcpad, playsink->videochain->sinkpad);
2957 gst_pad_link_full (srcpad, playsink->textchain->videosinkpad,
2958 GST_PAD_LINK_CHECK_NOTHING);
2959 gst_object_unref (srcpad);
2961 if (need_deinterlace)
2962 gst_pad_link_full (playsink->videodeinterlacechain->srcpad,
2963 playsink->textchain->videosinkpad, GST_PAD_LINK_CHECK_NOTHING);
2965 gst_pad_link_full (playsink->video_srcpad_stream_synchronizer,
2966 playsink->textchain->videosinkpad, GST_PAD_LINK_CHECK_NOTHING);
2968 gst_pad_link_full (playsink->textchain->srcpad,
2969 playsink->videochain->sinkpad, GST_PAD_LINK_CHECK_NOTHING);
2972 activate_chain (GST_PLAY_CHAIN (playsink->textchain), TRUE);
2975 GST_DEBUG_OBJECT (playsink, "no text needed");
2976 /* we have no subtitles/text or we are requested to not show them */
2978 if (playsink->text_sinkpad_stream_synchronizer) {
2979 gst_element_release_request_pad (GST_ELEMENT_CAST
2980 (playsink->stream_synchronizer),
2981 playsink->text_sinkpad_stream_synchronizer);
2982 gst_object_unref (playsink->text_sinkpad_stream_synchronizer);
2983 playsink->text_sinkpad_stream_synchronizer = NULL;
2984 gst_object_unref (playsink->text_srcpad_stream_synchronizer);
2985 playsink->text_srcpad_stream_synchronizer = NULL;
2988 if (playsink->textchain) {
2989 if (playsink->text_pad == NULL) {
2990 /* no text pad, remove the chain entirely */
2991 GST_DEBUG_OBJECT (playsink, "removing text chain");
2992 add_chain (GST_PLAY_CHAIN (playsink->textchain), FALSE);
2993 activate_chain (GST_PLAY_CHAIN (playsink->textchain), FALSE);
2995 /* we have a chain and a textpad, turn the subtitles off */
2996 GST_DEBUG_OBJECT (playsink, "turning off the text");
2997 if (playsink->textchain->overlay)
2998 g_object_set (G_OBJECT (playsink->textchain->overlay), "silent", TRUE,
3002 if (!need_video && playsink->video_pad) {
3003 if (playsink->video_sinkpad_stream_synchronizer) {
3004 gst_element_release_request_pad (GST_ELEMENT_CAST
3005 (playsink->stream_synchronizer),
3006 playsink->video_sinkpad_stream_synchronizer);
3007 gst_object_unref (playsink->video_sinkpad_stream_synchronizer);
3008 playsink->video_sinkpad_stream_synchronizer = NULL;
3009 gst_object_unref (playsink->video_srcpad_stream_synchronizer);
3010 playsink->video_srcpad_stream_synchronizer = NULL;
3013 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (playsink->video_pad), NULL);
3016 if (playsink->text_pad && !playsink->textchain)
3017 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (playsink->text_pad), NULL);
3019 update_av_offset (playsink);
3020 do_async_done (playsink);
3021 GST_PLAY_SINK_UNLOCK (playsink);
3028 /* gen_ chain already posted error */
3029 GST_DEBUG_OBJECT (playsink, "failed to setup chain");
3030 GST_PLAY_SINK_UNLOCK (playsink);
3036 * gst_play_sink_set_flags:
3037 * @playsink: a #GstPlaySink
3038 * @flags: #GstPlayFlags
3040 * Configure @flags on @playsink. The flags control the behaviour of @playsink
3041 * when constructing the sink pipelins.
3043 * Returns: TRUE if the flags could be configured.
3046 gst_play_sink_set_flags (GstPlaySink * playsink, GstPlayFlags flags)
3048 g_return_val_if_fail (GST_IS_PLAY_SINK (playsink), FALSE);
3050 GST_OBJECT_LOCK (playsink);
3051 playsink->flags = flags;
3052 GST_OBJECT_UNLOCK (playsink);
3058 * gst_play_sink_get_flags:
3059 * @playsink: a #GstPlaySink
3061 * Get the flags of @playsink. That flags control the behaviour of the sink when
3062 * it constructs the sink pipelines.
3064 * Returns: the currently configured #GstPlayFlags.
3067 gst_play_sink_get_flags (GstPlaySink * playsink)
3071 g_return_val_if_fail (GST_IS_PLAY_SINK (playsink), 0);
3073 GST_OBJECT_LOCK (playsink);
3074 res = playsink->flags;
3075 GST_OBJECT_UNLOCK (playsink);
3081 gst_play_sink_set_font_desc (GstPlaySink * playsink, const gchar * desc)
3083 GstPlayTextChain *chain;
3085 GST_PLAY_SINK_LOCK (playsink);
3086 chain = (GstPlayTextChain *) playsink->textchain;
3087 g_free (playsink->font_desc);
3088 playsink->font_desc = g_strdup (desc);
3089 if (chain && chain->overlay) {
3090 g_object_set (chain->overlay, "font-desc", desc, NULL);
3092 GST_PLAY_SINK_UNLOCK (playsink);
3096 gst_play_sink_get_font_desc (GstPlaySink * playsink)
3098 gchar *result = NULL;
3099 GstPlayTextChain *chain;
3101 GST_PLAY_SINK_LOCK (playsink);
3102 chain = (GstPlayTextChain *) playsink->textchain;
3103 if (chain && chain->overlay) {
3104 g_object_get (chain->overlay, "font-desc", &result, NULL);
3105 playsink->font_desc = g_strdup (result);
3107 result = g_strdup (playsink->font_desc);
3109 GST_PLAY_SINK_UNLOCK (playsink);
3115 gst_play_sink_set_subtitle_encoding (GstPlaySink * playsink,
3116 const gchar * encoding)
3118 GstPlayTextChain *chain;
3120 GST_PLAY_SINK_LOCK (playsink);
3121 chain = (GstPlayTextChain *) playsink->textchain;
3122 g_free (playsink->subtitle_encoding);
3123 playsink->subtitle_encoding = g_strdup (encoding);
3124 if (chain && chain->overlay) {
3125 g_object_set (chain->overlay, "subtitle-encoding", encoding, NULL);
3127 GST_PLAY_SINK_UNLOCK (playsink);
3131 gst_play_sink_get_subtitle_encoding (GstPlaySink * playsink)
3133 gchar *result = NULL;
3134 GstPlayTextChain *chain;
3136 GST_PLAY_SINK_LOCK (playsink);
3137 chain = (GstPlayTextChain *) playsink->textchain;
3138 if (chain && chain->overlay) {
3139 g_object_get (chain->overlay, "subtitle-encoding", &result, NULL);
3140 playsink->subtitle_encoding = g_strdup (result);
3142 result = g_strdup (playsink->subtitle_encoding);
3144 GST_PLAY_SINK_UNLOCK (playsink);
3150 update_av_offset (GstPlaySink * playsink)
3153 GstPlayAudioChain *achain;
3154 GstPlayVideoChain *vchain;
3156 av_offset = playsink->av_offset;
3157 achain = (GstPlayAudioChain *) playsink->audiochain;
3158 vchain = (GstPlayVideoChain *) playsink->videochain;
3160 if (achain && vchain && achain->ts_offset && vchain->ts_offset) {
3161 g_object_set (achain->ts_offset, "ts-offset", MAX (0, -av_offset), NULL);
3162 g_object_set (vchain->ts_offset, "ts-offset", MAX (0, av_offset), NULL);
3164 GST_LOG_OBJECT (playsink, "no ts_offset elements");
3169 gst_play_sink_set_av_offset (GstPlaySink * playsink, gint64 av_offset)
3171 GST_PLAY_SINK_LOCK (playsink);
3172 playsink->av_offset = av_offset;
3173 update_av_offset (playsink);
3174 GST_PLAY_SINK_UNLOCK (playsink);
3178 gst_play_sink_get_av_offset (GstPlaySink * playsink)
3182 GST_PLAY_SINK_LOCK (playsink);
3183 result = playsink->av_offset;
3184 GST_PLAY_SINK_UNLOCK (playsink);
3190 * gst_play_sink_get_last_frame:
3191 * @playsink: a #GstPlaySink
3193 * Get the last displayed frame from @playsink. This frame is in the native
3194 * format of the sink element, the caps on the result buffer contain the format
3195 * of the frame data.
3197 * Returns: a #GstBuffer with the frame data or %NULL when no video frame is
3201 gst_play_sink_get_last_frame (GstPlaySink * playsink)
3203 GstBuffer *result = NULL;
3204 GstPlayVideoChain *chain;
3206 GST_PLAY_SINK_LOCK (playsink);
3207 GST_DEBUG_OBJECT (playsink, "taking last frame");
3208 /* get the video chain if we can */
3209 if ((chain = (GstPlayVideoChain *) playsink->videochain)) {
3210 GST_DEBUG_OBJECT (playsink, "found video chain");
3211 /* see if the chain is active */
3212 if (chain->chain.activated && chain->sink) {
3215 GST_DEBUG_OBJECT (playsink, "video chain active and has a sink");
3217 /* find and get the last-buffer property now */
3219 gst_play_sink_find_property (playsink, chain->sink,
3220 "last-buffer", GST_TYPE_BUFFER))) {
3221 GST_DEBUG_OBJECT (playsink, "getting last-buffer property");
3222 g_object_get (elem, "last-buffer", &result, NULL);
3223 gst_object_unref (elem);
3227 GST_PLAY_SINK_UNLOCK (playsink);
3233 * gst_play_sink_convert_frame:
3234 * @playsink: a #GstPlaySink
3237 * Get the last displayed frame from @playsink. If caps is %NULL, the video will
3238 * be in the native format of the sink element and the caps on the buffer
3239 * describe the format of the frame. If @caps is not %NULL, the video
3240 * frame will be converted to the format of the caps.
3242 * Returns: a #GstBuffer with the frame data or %NULL when no video frame is
3243 * available or when the conversion failed.
3246 gst_play_sink_convert_frame (GstPlaySink * playsink, GstCaps * caps)
3250 result = gst_play_sink_get_last_frame (playsink);
3251 if (result != NULL && caps != NULL) {
3255 temp = gst_video_convert_frame (result, caps, 25 * GST_SECOND, &err);
3256 gst_buffer_unref (result);
3257 if (temp == NULL && err) {
3258 /* I'm really uncertain whether we should make playsink post an error
3259 * on the bus or not. It's not like it's a critical issue regarding
3260 * playsink behaviour. */
3261 GST_ERROR ("Error converting frame: %s", err->message);
3270 is_raw_structure (GstStructure * s)
3274 name = gst_structure_get_name (s);
3276 if (g_str_has_prefix (name, "video/x-raw-") ||
3277 g_str_has_prefix (name, "audio/x-raw-"))
3283 is_raw_pad (GstPad * pad)
3285 GstPad *peer = gst_pad_get_peer (pad);
3287 gboolean raw = TRUE;
3292 caps = gst_pad_get_negotiated_caps (peer);
3296 caps = gst_pad_get_caps_reffed (peer);
3298 n = gst_caps_get_size (caps);
3299 for (i = 0; i < n; i++) {
3300 gboolean r = is_raw_structure (gst_caps_get_structure (caps, i));
3304 } else if (raw != r) {
3305 GST_ERROR_OBJECT (pad,
3306 "Caps contains raw and non-raw structures: %" GST_PTR_FORMAT, caps);
3312 raw = is_raw_structure (gst_caps_get_structure (caps, 0));
3314 gst_caps_unref (caps);
3315 gst_object_unref (peer);
3321 sinkpad_blocked_cb (GstPad * blockedpad, gboolean blocked, gpointer user_data)
3323 GstPlaySink *playsink = (GstPlaySink *) user_data;
3326 GST_PLAY_SINK_LOCK (playsink);
3328 pad = GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD (blockedpad)));
3329 if (pad == playsink->video_pad) {
3330 playsink->video_pad_blocked = blocked;
3331 GST_DEBUG_OBJECT (pad, "Video pad blocked: %d", blocked);
3333 PENDING_FLAG_UNSET (playsink, GST_PLAY_SINK_TYPE_VIDEO_RAW);
3334 PENDING_FLAG_UNSET (playsink, GST_PLAY_SINK_TYPE_VIDEO);
3336 } else if (pad == playsink->audio_pad) {
3337 playsink->audio_pad_blocked = blocked;
3338 GST_DEBUG_OBJECT (pad, "Audio pad blocked: %d", blocked);
3340 PENDING_FLAG_UNSET (playsink, GST_PLAY_SINK_TYPE_AUDIO_RAW);
3341 PENDING_FLAG_UNSET (playsink, GST_PLAY_SINK_TYPE_AUDIO);
3343 } else if (pad == playsink->text_pad) {
3344 playsink->text_pad_blocked = blocked;
3345 GST_DEBUG_OBJECT (pad, "Text pad blocked: %d", blocked);
3347 PENDING_FLAG_UNSET (playsink, GST_PLAY_SINK_TYPE_TEXT);
3351 gst_object_unref (pad);
3352 GST_PLAY_SINK_UNLOCK (playsink);
3356 /* We reconfigure when for ALL streams:
3357 * * there isn't a pad
3358 * * OR the pad is blocked
3359 * * OR there are no pending blocks on that pad
3362 if ((!playsink->video_pad || playsink->video_pad_blocked
3363 || !PENDING_VIDEO_BLOCK (playsink)) && (!playsink->audio_pad
3364 || playsink->audio_pad_blocked || !PENDING_AUDIO_BLOCK (playsink))
3365 && (!playsink->text_pad || playsink->text_pad_blocked
3366 || !PENDING_TEXT_BLOCK (playsink))) {
3367 GST_DEBUG_OBJECT (playsink, "All pads blocked -- reconfiguring");
3369 if (playsink->video_pad) {
3370 playsink->video_pad_raw = is_raw_pad (playsink->video_pad);
3371 GST_DEBUG_OBJECT (playsink, "Video pad is raw: %d",
3372 playsink->video_pad_raw);
3375 if (playsink->audio_pad) {
3376 playsink->audio_pad_raw = is_raw_pad (playsink->audio_pad);
3377 GST_DEBUG_OBJECT (playsink, "Audio pad is raw: %d",
3378 playsink->audio_pad_raw);
3381 gst_play_sink_reconfigure (playsink);
3383 if (playsink->video_pad) {
3385 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3386 (playsink->video_pad)));
3387 gst_pad_set_blocked_async (opad, FALSE, sinkpad_blocked_cb, playsink);
3388 gst_object_unref (opad);
3391 if (playsink->audio_pad) {
3393 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3394 (playsink->audio_pad)));
3395 gst_pad_set_blocked_async (opad, FALSE, sinkpad_blocked_cb, playsink);
3396 gst_object_unref (opad);
3399 if (playsink->text_pad) {
3401 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3402 (playsink->text_pad)));
3403 gst_pad_set_blocked_async (opad, FALSE, sinkpad_blocked_cb, playsink);
3404 gst_object_unref (opad);
3408 gst_object_unref (pad);
3410 GST_PLAY_SINK_UNLOCK (playsink);
3414 caps_notify_cb (GstPad * pad, GParamSpec * unused, GstPlaySink * playsink)
3416 gboolean reconfigure = FALSE;
3420 g_object_get (pad, "caps", &caps, NULL);
3424 if (pad == playsink->audio_pad) {
3425 raw = is_raw_pad (pad);
3426 reconfigure = (! !playsink->audio_pad_raw != ! !raw)
3427 && playsink->audiochain;
3428 GST_DEBUG_OBJECT (pad,
3429 "Audio caps changed: raw %d reconfigure %d caps %" GST_PTR_FORMAT, raw,
3431 } else if (pad == playsink->video_pad) {
3432 raw = is_raw_pad (pad);
3433 reconfigure = (! !playsink->video_pad_raw != ! !raw)
3434 && playsink->videochain;
3435 GST_DEBUG_OBJECT (pad,
3436 "Video caps changed: raw %d reconfigure %d caps %" GST_PTR_FORMAT, raw,
3440 gst_caps_unref (caps);
3443 GST_PLAY_SINK_LOCK (playsink);
3444 if (playsink->video_pad) {
3446 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3447 (playsink->video_pad)));
3448 gst_pad_set_blocked_async (opad, TRUE, sinkpad_blocked_cb, playsink);
3449 gst_object_unref (opad);
3452 if (playsink->audio_pad) {
3454 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3455 (playsink->audio_pad)));
3456 gst_pad_set_blocked_async (opad, TRUE, sinkpad_blocked_cb, playsink);
3457 gst_object_unref (opad);
3460 if (playsink->text_pad) {
3462 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3463 (playsink->text_pad)));
3464 gst_pad_set_blocked_async (opad, TRUE, sinkpad_blocked_cb, playsink);
3465 gst_object_unref (opad);
3467 GST_PLAY_SINK_UNLOCK (playsink);
3472 * gst_play_sink_request_pad
3473 * @playsink: a #GstPlaySink
3474 * @type: a #GstPlaySinkType
3476 * Create or return a pad of @type.
3478 * Returns: a #GstPad of @type or %NULL when the pad could not be created.
3481 gst_play_sink_request_pad (GstPlaySink * playsink, GstPlaySinkType type)
3484 gboolean created = FALSE;
3485 gboolean activate = TRUE;
3486 const gchar *pad_name = NULL;
3488 GST_DEBUG_OBJECT (playsink, "request pad type %d", type);
3490 GST_PLAY_SINK_LOCK (playsink);
3492 case GST_PLAY_SINK_TYPE_AUDIO_RAW:
3493 case GST_PLAY_SINK_TYPE_AUDIO:
3494 pad_name = "audio_sink";
3495 if (!playsink->audio_tee) {
3496 GST_LOG_OBJECT (playsink, "creating tee");
3497 /* create tee when needed. This element will feed the audio sink chain
3498 * and the vis chain. */
3499 playsink->audio_tee = gst_element_factory_make ("tee", "audiotee");
3500 if (playsink->audio_tee == NULL) {
3501 post_missing_element_message (playsink, "tee");
3502 GST_ELEMENT_ERROR (playsink, CORE, MISSING_PLUGIN,
3503 (_("Missing element '%s' - check your GStreamer installation."),
3508 playsink->audio_tee_sink =
3509 gst_element_get_static_pad (playsink->audio_tee, "sink");
3510 gst_bin_add (GST_BIN_CAST (playsink), playsink->audio_tee);
3511 gst_element_set_state (playsink->audio_tee, GST_STATE_PAUSED);
3514 gst_element_set_state (playsink->audio_tee, GST_STATE_PAUSED);
3516 if (!playsink->audio_pad) {
3517 GST_LOG_OBJECT (playsink, "ghosting tee sinkpad");
3518 playsink->audio_pad =
3519 gst_ghost_pad_new (pad_name, playsink->audio_tee_sink);
3520 g_signal_connect (G_OBJECT (playsink->audio_pad), "notify::caps",
3521 G_CALLBACK (caps_notify_cb), playsink);
3524 playsink->audio_pad_raw = FALSE;
3525 res = playsink->audio_pad;
3527 case GST_PLAY_SINK_TYPE_VIDEO_RAW:
3528 case GST_PLAY_SINK_TYPE_VIDEO:
3529 pad_name = "video_sink";
3530 if (!playsink->video_pad) {
3531 GST_LOG_OBJECT (playsink, "ghosting videosink");
3532 playsink->video_pad =
3533 gst_ghost_pad_new_no_target (pad_name, GST_PAD_SINK);
3534 g_signal_connect (G_OBJECT (playsink->video_pad), "notify::caps",
3535 G_CALLBACK (caps_notify_cb), playsink);
3538 playsink->video_pad_raw = FALSE;
3539 res = playsink->video_pad;
3541 case GST_PLAY_SINK_TYPE_TEXT:
3542 GST_LOG_OBJECT (playsink, "ghosting text");
3543 if (!playsink->text_pad) {
3544 playsink->text_pad =
3545 gst_ghost_pad_new_no_target ("text_sink", GST_PAD_SINK);
3548 res = playsink->text_pad;
3550 case GST_PLAY_SINK_TYPE_FLUSHING:
3554 /* we need a unique padname for the flushing pad. */
3555 padname = g_strdup_printf ("flushing_%d", playsink->count);
3556 res = gst_ghost_pad_new_no_target (padname, GST_PAD_SINK);
3567 GST_PLAY_SINK_UNLOCK (playsink);
3569 if (created && res) {
3570 /* we have to add the pad when it's active or we get an error when the
3571 * element is 'running' */
3572 gst_pad_set_active (res, TRUE);
3573 gst_element_add_pad (GST_ELEMENT_CAST (playsink), res);
3574 if (type != GST_PLAY_SINK_TYPE_FLUSHING) {
3576 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD (res)));
3578 gst_pad_set_blocked_async (blockpad, TRUE, sinkpad_blocked_cb, playsink);
3579 PENDING_FLAG_SET (playsink, type);
3580 gst_object_unref (blockpad);
3583 gst_pad_set_active (res, activate);
3590 gst_play_sink_request_new_pad (GstElement * element, GstPadTemplate * templ,
3595 GstPlaySinkType type;
3596 const gchar *tplname;
3598 g_return_val_if_fail (templ != NULL, NULL);
3600 GST_DEBUG_OBJECT (element, "name:%s", name);
3602 psink = GST_PLAY_SINK (element);
3603 tplname = GST_PAD_TEMPLATE_NAME_TEMPLATE (templ);
3605 /* Figure out the GstPlaySinkType based on the template */
3606 if (!strcmp (tplname, "audio_sink"))
3607 type = GST_PLAY_SINK_TYPE_AUDIO;
3608 else if (!strcmp (tplname, "audio_raw_sink"))
3609 type = GST_PLAY_SINK_TYPE_AUDIO_RAW;
3610 else if (!strcmp (tplname, "video_sink"))
3611 type = GST_PLAY_SINK_TYPE_VIDEO;
3612 else if (!strcmp (tplname, "video_raw_sink"))
3613 type = GST_PLAY_SINK_TYPE_VIDEO_RAW;
3614 else if (!strcmp (tplname, "text_sink"))
3615 type = GST_PLAY_SINK_TYPE_TEXT;
3617 goto unknown_template;
3619 pad = gst_play_sink_request_pad (psink, type);
3623 GST_WARNING_OBJECT (element, "Unknown pad template");
3628 gst_play_sink_release_pad (GstPlaySink * playsink, GstPad * pad)
3630 GstPad **res = NULL;
3631 gboolean untarget = TRUE;
3633 GST_DEBUG_OBJECT (playsink, "release pad %" GST_PTR_FORMAT, pad);
3635 GST_PLAY_SINK_LOCK (playsink);
3636 if (pad == playsink->video_pad) {
3637 res = &playsink->video_pad;
3638 g_signal_handlers_disconnect_by_func (playsink->video_pad, caps_notify_cb,
3640 } else if (pad == playsink->audio_pad) {
3641 res = &playsink->audio_pad;
3642 g_signal_handlers_disconnect_by_func (playsink->audio_pad, caps_notify_cb,
3644 } else if (pad == playsink->text_pad) {
3645 res = &playsink->text_pad;
3647 /* try to release the given pad anyway, these could be the FLUSHING pads. */
3651 GST_PLAY_SINK_UNLOCK (playsink);
3654 GST_DEBUG_OBJECT (playsink, "deactivate pad %" GST_PTR_FORMAT, *res);
3655 gst_pad_set_active (*res, FALSE);
3657 GST_DEBUG_OBJECT (playsink, "untargeting pad %" GST_PTR_FORMAT, *res);
3658 gst_ghost_pad_set_target (GST_GHOST_PAD_CAST (*res), NULL);
3660 GST_DEBUG_OBJECT (playsink, "remove pad %" GST_PTR_FORMAT, *res);
3661 gst_element_remove_pad (GST_ELEMENT_CAST (playsink), *res);
3667 gst_play_sink_release_request_pad (GstElement * element, GstPad * pad)
3669 GstPlaySink *psink = GST_PLAY_SINK (element);
3671 gst_play_sink_release_pad (psink, pad);
3675 gst_play_sink_handle_message (GstBin * bin, GstMessage * message)
3677 GstPlaySink *playsink;
3679 playsink = GST_PLAY_SINK_CAST (bin);
3681 switch (GST_MESSAGE_TYPE (message)) {
3682 case GST_MESSAGE_STEP_DONE:
3687 gboolean flush, intermediate, eos;
3690 GST_INFO_OBJECT (playsink, "Handling step-done message");
3691 gst_message_parse_step_done (message, &format, &amount, &rate, &flush,
3692 &intermediate, &duration, &eos);
3694 if (format == GST_FORMAT_BUFFERS) {
3695 /* for the buffer format, we align the other streams */
3696 if (playsink->audiochain) {
3700 gst_event_new_step (GST_FORMAT_TIME, duration, rate, flush,
3703 if (!gst_element_send_event (playsink->audiochain->chain.bin, event)) {
3704 GST_DEBUG_OBJECT (playsink, "Event failed when sent to audio sink");
3708 GST_BIN_CLASS (gst_play_sink_parent_class)->handle_message (bin, message);
3711 case GST_MESSAGE_ELEMENT:{
3712 if (gst_structure_has_name (message->structure, "prepare-xwindow-id")) {
3713 GstXOverlay *xoverlay;
3715 GST_OBJECT_LOCK (playsink);
3716 if (playsink->xoverlay_element
3717 && GST_OBJECT_CAST (playsink->xoverlay_element) !=
3718 GST_MESSAGE_SRC (message)) {
3719 gst_object_unref (playsink->xoverlay_element);
3720 playsink->xoverlay_element = NULL;
3723 if (!playsink->xoverlay_element)
3724 playsink->xoverlay_element =
3725 GST_X_OVERLAY (gst_object_ref (GST_MESSAGE_SRC (message)));
3726 xoverlay = GST_X_OVERLAY (gst_object_ref (playsink->xoverlay_element));
3727 GST_OBJECT_UNLOCK (playsink);
3729 GST_DEBUG_OBJECT (playsink, "Got prepare-xwindow-id message");
3731 if (playsink->xoverlay_handle_set)
3732 gst_x_overlay_set_window_handle (playsink->xoverlay_element,
3733 playsink->xoverlay_handle);
3734 if (playsink->xoverlay_handle_events_set)
3735 gst_x_overlay_handle_events (playsink->xoverlay_element,
3736 playsink->xoverlay_handle_events);
3737 if (playsink->xoverlay_render_rectangle_set)
3738 gst_x_overlay_set_render_rectangle (playsink->xoverlay_element,
3739 playsink->xoverlay_x, playsink->xoverlay_y,
3740 playsink->xoverlay_width, playsink->xoverlay_height);
3742 gst_object_unref (xoverlay);
3743 gst_message_unref (message);
3744 gst_x_overlay_prepare_xwindow_id (GST_X_OVERLAY (playsink));
3746 GST_BIN_CLASS (gst_play_sink_parent_class)->handle_message (bin,
3752 GST_BIN_CLASS (gst_play_sink_parent_class)->handle_message (bin, message);
3757 /* Send an event to our sinks until one of them works; don't then send to the
3758 * remaining sinks (unlike GstBin)
3759 * Special case: If a text sink is set we need to send the event
3760 * to them in case it's source is different from the a/v stream's source.
3763 gst_play_sink_send_event_to_sink (GstPlaySink * playsink, GstEvent * event)
3765 gboolean res = TRUE;
3766 if (playsink->textchain && playsink->textchain->sink) {
3767 gst_event_ref (event);
3768 if ((res = gst_element_send_event (playsink->textchain->chain.bin, event))) {
3769 GST_DEBUG_OBJECT (playsink, "Sent event successfully to text sink");
3771 GST_DEBUG_OBJECT (playsink, "Event failed when sent to text sink");
3775 if (playsink->videochain) {
3776 gst_event_ref (event);
3777 if ((res = gst_element_send_event (playsink->videochain->chain.bin, event))) {
3778 GST_DEBUG_OBJECT (playsink, "Sent event successfully to video sink");
3781 GST_DEBUG_OBJECT (playsink, "Event failed when sent to video sink");
3783 if (playsink->audiochain) {
3784 gst_event_ref (event);
3785 if ((res = gst_element_send_event (playsink->audiochain->chain.bin, event))) {
3786 GST_DEBUG_OBJECT (playsink, "Sent event successfully to audio sink");
3789 GST_DEBUG_OBJECT (playsink, "Event failed when sent to audio sink");
3793 gst_event_unref (event);
3797 /* We only want to send the event to a single sink (overriding GstBin's
3798 * behaviour), but we want to keep GstPipeline's behaviour - wrapping seek
3799 * events appropriately. So, this is a messy duplication of code. */
3801 gst_play_sink_send_event (GstElement * element, GstEvent * event)
3803 gboolean res = FALSE;
3804 GstEventType event_type = GST_EVENT_TYPE (event);
3805 GstPlaySink *playsink;
3806 playsink = GST_PLAY_SINK_CAST (element);
3807 switch (event_type) {
3808 case GST_EVENT_SEEK:
3809 GST_DEBUG_OBJECT (element, "Sending event to a sink");
3810 res = gst_play_sink_send_event_to_sink (playsink, event);
3812 case GST_EVENT_STEP:
3817 gboolean flush, intermediate;
3818 gst_event_parse_step (event, &format, &amount, &rate, &flush,
3820 if (format == GST_FORMAT_BUFFERS) {
3821 /* for buffers, we will try to step video frames, for other formats we
3822 * send the step to all sinks */
3823 res = gst_play_sink_send_event_to_sink (playsink, event);
3826 GST_ELEMENT_CLASS (gst_play_sink_parent_class)->send_event (element,
3833 GST_ELEMENT_CLASS (gst_play_sink_parent_class)->send_event (element,
3840 static GstStateChangeReturn
3841 gst_play_sink_change_state (GstElement * element, GstStateChange transition)
3843 GstStateChangeReturn ret;
3844 GstStateChangeReturn bret;
3845 GstPlaySink *playsink;
3846 playsink = GST_PLAY_SINK (element);
3847 switch (transition) {
3848 case GST_STATE_CHANGE_READY_TO_PAUSED:
3849 playsink->need_async_start = TRUE;
3850 /* we want to go async to PAUSED until we managed to configure and add the
3852 do_async_start (playsink);
3853 ret = GST_STATE_CHANGE_ASYNC;
3855 case GST_STATE_CHANGE_PAUSED_TO_READY:
3856 /* unblock all pads here */
3857 GST_PLAY_SINK_LOCK (playsink);
3858 if (playsink->video_pad) {
3860 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3861 (playsink->video_pad)));
3862 if (gst_pad_is_blocked (opad)) {
3863 gst_pad_set_blocked_async (opad, FALSE, sinkpad_blocked_cb, playsink);
3865 gst_object_unref (opad);
3866 playsink->video_pad_blocked = FALSE;
3869 if (playsink->audio_pad) {
3871 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3872 (playsink->audio_pad)));
3873 if (gst_pad_is_blocked (opad)) {
3874 gst_pad_set_blocked_async (opad, FALSE, sinkpad_blocked_cb, playsink);
3876 gst_object_unref (opad);
3877 playsink->audio_pad_blocked = FALSE;
3880 if (playsink->text_pad) {
3882 GST_PAD_CAST (gst_proxy_pad_get_internal (GST_PROXY_PAD
3883 (playsink->text_pad)));
3884 if (gst_pad_is_blocked (opad)) {
3885 gst_pad_set_blocked_async (opad, FALSE, sinkpad_blocked_cb, playsink);
3887 gst_object_unref (opad);
3888 playsink->text_pad_blocked = FALSE;
3890 GST_PLAY_SINK_UNLOCK (playsink);
3892 case GST_STATE_CHANGE_READY_TO_NULL:
3893 if (playsink->audiochain && playsink->audiochain->sink_volume) {
3894 /* remove our links to the mute and volume elements when they were
3895 * provided by a sink */
3896 disconnect_chain (playsink->audiochain, playsink);
3897 playsink->audiochain->volume = NULL;
3898 playsink->audiochain->mute = NULL;
3901 if (playsink->audiochain && playsink->audiochain->ts_offset) {
3902 gst_object_unref (playsink->audiochain->ts_offset);
3903 playsink->audiochain->ts_offset = NULL;
3906 if (playsink->videochain && playsink->videochain->ts_offset) {
3907 gst_object_unref (playsink->videochain->ts_offset);
3908 playsink->videochain->ts_offset = NULL;
3911 GST_OBJECT_LOCK (playsink);
3912 if (playsink->xoverlay_element)
3913 gst_object_unref (playsink->xoverlay_element);
3914 playsink->xoverlay_element = NULL;
3916 if (playsink->colorbalance_element) {
3917 g_signal_handlers_disconnect_by_func (playsink->colorbalance_element,
3918 G_CALLBACK (colorbalance_value_changed_cb), playsink);
3919 gst_object_unref (playsink->colorbalance_element);
3921 playsink->colorbalance_element = NULL;
3922 GST_OBJECT_UNLOCK (playsink);
3924 ret = GST_STATE_CHANGE_SUCCESS;
3927 /* all other state changes return SUCCESS by default, this value can be
3928 * overridden by the result of the children */
3929 ret = GST_STATE_CHANGE_SUCCESS;
3933 /* do the state change of the children */
3935 GST_ELEMENT_CLASS (gst_play_sink_parent_class)->change_state (element,
3937 /* now look at the result of our children and adjust the return value */
3939 case GST_STATE_CHANGE_FAILURE:
3940 /* failure, we stop */
3941 goto activate_failed;
3942 case GST_STATE_CHANGE_NO_PREROLL:
3943 /* some child returned NO_PREROLL. This is strange but we never know. We
3944 * commit our async state change (if any) and return the NO_PREROLL */
3945 do_async_done (playsink);
3948 case GST_STATE_CHANGE_ASYNC:
3949 /* some child was async, return this */
3953 /* return our previously configured return value */
3957 switch (transition) {
3958 case GST_STATE_CHANGE_READY_TO_PAUSED:
3960 case GST_STATE_CHANGE_PLAYING_TO_PAUSED:
3961 /* FIXME Release audio device when we implement that */
3962 playsink->need_async_start = TRUE;
3964 case GST_STATE_CHANGE_PAUSED_TO_READY:{
3965 if (playsink->video_sinkpad_stream_synchronizer) {
3966 gst_element_release_request_pad (GST_ELEMENT_CAST
3967 (playsink->stream_synchronizer),
3968 playsink->video_sinkpad_stream_synchronizer);
3969 gst_object_unref (playsink->video_sinkpad_stream_synchronizer);
3970 playsink->video_sinkpad_stream_synchronizer = NULL;
3971 gst_object_unref (playsink->video_srcpad_stream_synchronizer);
3972 playsink->video_srcpad_stream_synchronizer = NULL;
3974 if (playsink->audio_sinkpad_stream_synchronizer) {
3975 gst_element_release_request_pad (GST_ELEMENT_CAST
3976 (playsink->stream_synchronizer),
3977 playsink->audio_sinkpad_stream_synchronizer);
3978 gst_object_unref (playsink->audio_sinkpad_stream_synchronizer);
3979 playsink->audio_sinkpad_stream_synchronizer = NULL;
3980 gst_object_unref (playsink->audio_srcpad_stream_synchronizer);
3981 playsink->audio_srcpad_stream_synchronizer = NULL;
3983 if (playsink->text_sinkpad_stream_synchronizer) {
3984 gst_element_release_request_pad (GST_ELEMENT_CAST
3985 (playsink->stream_synchronizer),
3986 playsink->text_sinkpad_stream_synchronizer);
3987 gst_object_unref (playsink->text_sinkpad_stream_synchronizer);
3988 playsink->text_sinkpad_stream_synchronizer = NULL;
3989 gst_object_unref (playsink->text_srcpad_stream_synchronizer);
3990 playsink->text_srcpad_stream_synchronizer = NULL;
3994 case GST_STATE_CHANGE_READY_TO_NULL:
3995 /* remove sinks we added */
3996 if (playsink->videodeinterlacechain) {
3997 activate_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain),
3999 add_chain (GST_PLAY_CHAIN (playsink->videodeinterlacechain), FALSE);
4001 if (playsink->videochain) {
4002 activate_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE);
4003 add_chain (GST_PLAY_CHAIN (playsink->videochain), FALSE);
4005 if (playsink->audiochain) {
4006 activate_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE);
4007 add_chain (GST_PLAY_CHAIN (playsink->audiochain), FALSE);
4009 if (playsink->vischain) {
4010 activate_chain (GST_PLAY_CHAIN (playsink->vischain), FALSE);
4011 add_chain (GST_PLAY_CHAIN (playsink->vischain), FALSE);
4013 if (playsink->textchain) {
4014 activate_chain (GST_PLAY_CHAIN (playsink->textchain), FALSE);
4015 add_chain (GST_PLAY_CHAIN (playsink->textchain), FALSE);
4017 do_async_done (playsink);
4018 /* when going to READY, keep elements around as long as possible,
4019 * so they may be re-used faster next time/url around.
4020 * when really going to NULL, clean up everything completely. */
4021 if (transition == GST_STATE_CHANGE_READY_TO_NULL) {
4023 /* Unparent the sinks to allow reuse */
4024 if (playsink->videochain && playsink->videochain->sink)
4025 gst_bin_remove (GST_BIN_CAST (playsink->videochain->chain.bin),
4026 playsink->videochain->sink);
4027 if (playsink->audiochain && playsink->audiochain->sink)
4028 gst_bin_remove (GST_BIN_CAST (playsink->audiochain->chain.bin),
4029 playsink->audiochain->sink);
4030 if (playsink->textchain && playsink->textchain->sink)
4031 gst_bin_remove (GST_BIN_CAST (playsink->textchain->chain.bin),
4032 playsink->textchain->sink);
4033 if (playsink->audio_sink != NULL)
4034 gst_element_set_state (playsink->audio_sink, GST_STATE_NULL);
4035 if (playsink->video_sink != NULL)
4036 gst_element_set_state (playsink->video_sink, GST_STATE_NULL);
4037 if (playsink->visualisation != NULL)
4038 gst_element_set_state (playsink->visualisation, GST_STATE_NULL);
4039 if (playsink->text_sink != NULL)
4040 gst_element_set_state (playsink->text_sink, GST_STATE_NULL);
4041 free_chain ((GstPlayChain *) playsink->videodeinterlacechain);
4042 playsink->videodeinterlacechain = NULL;
4043 free_chain ((GstPlayChain *) playsink->videochain);
4044 playsink->videochain = NULL;
4045 free_chain ((GstPlayChain *) playsink->audiochain);
4046 playsink->audiochain = NULL;
4047 free_chain ((GstPlayChain *) playsink->vischain);
4048 playsink->vischain = NULL;
4049 free_chain ((GstPlayChain *) playsink->textchain);
4050 playsink->textchain = NULL;
4060 GST_DEBUG_OBJECT (element,
4061 "element failed to change states -- activation problem?");
4062 return GST_STATE_CHANGE_FAILURE;
4067 gst_play_sink_set_property (GObject * object, guint prop_id,
4068 const GValue * value, GParamSpec * spec)
4070 GstPlaySink *playsink = GST_PLAY_SINK (object);
4073 gst_play_sink_set_flags (playsink, g_value_get_flags (value));
4076 gst_play_sink_set_volume (playsink, g_value_get_double (value));
4079 gst_play_sink_set_mute (playsink, g_value_get_boolean (value));
4081 case PROP_FONT_DESC:
4082 gst_play_sink_set_font_desc (playsink, g_value_get_string (value));
4084 case PROP_SUBTITLE_ENCODING:
4085 gst_play_sink_set_subtitle_encoding (playsink,
4086 g_value_get_string (value));
4088 case PROP_VIS_PLUGIN:
4089 gst_play_sink_set_vis_plugin (playsink, g_value_get_object (value));
4091 case PROP_AV_OFFSET:
4092 gst_play_sink_set_av_offset (playsink, g_value_get_int64 (value));
4094 case PROP_VIDEO_SINK:
4095 gst_play_sink_set_sink (playsink, GST_PLAY_SINK_TYPE_VIDEO,
4096 g_value_get_object (value));
4098 case PROP_AUDIO_SINK:
4099 gst_play_sink_set_sink (playsink, GST_PLAY_SINK_TYPE_AUDIO,
4100 g_value_get_object (value));
4102 case PROP_TEXT_SINK:
4103 gst_play_sink_set_sink (playsink, GST_PLAY_SINK_TYPE_TEXT,
4104 g_value_get_object (value));
4107 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec);
4113 gst_play_sink_get_property (GObject * object, guint prop_id,
4114 GValue * value, GParamSpec * spec)
4116 GstPlaySink *playsink = GST_PLAY_SINK (object);
4119 g_value_set_flags (value, gst_play_sink_get_flags (playsink));
4122 g_value_set_double (value, gst_play_sink_get_volume (playsink));
4125 g_value_set_boolean (value, gst_play_sink_get_mute (playsink));
4127 case PROP_FONT_DESC:
4128 g_value_take_string (value, gst_play_sink_get_font_desc (playsink));
4130 case PROP_SUBTITLE_ENCODING:
4131 g_value_take_string (value,
4132 gst_play_sink_get_subtitle_encoding (playsink));
4134 case PROP_VIS_PLUGIN:
4135 g_value_take_object (value, gst_play_sink_get_vis_plugin (playsink));
4138 gst_value_take_buffer (value, gst_play_sink_get_last_frame (playsink));
4140 case PROP_AV_OFFSET:
4141 g_value_set_int64 (value, gst_play_sink_get_av_offset (playsink));
4143 case PROP_VIDEO_SINK:
4144 g_value_take_object (value, gst_play_sink_get_sink (playsink,
4145 GST_PLAY_SINK_TYPE_VIDEO));
4147 case PROP_AUDIO_SINK:
4148 g_value_take_object (value, gst_play_sink_get_sink (playsink,
4149 GST_PLAY_SINK_TYPE_AUDIO));
4151 case PROP_TEXT_SINK:
4152 g_value_take_object (value, gst_play_sink_get_sink (playsink,
4153 GST_PLAY_SINK_TYPE_TEXT));
4156 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, spec);
4162 gst_play_sink_xoverlay_expose (GstXOverlay * overlay)
4164 GstPlaySink *playsink = GST_PLAY_SINK (overlay);
4165 GstXOverlay *xoverlay;
4167 GST_OBJECT_LOCK (playsink);
4168 if (playsink->xoverlay_element)
4169 xoverlay = GST_X_OVERLAY (gst_object_ref (playsink->xoverlay_element));
4172 GST_OBJECT_UNLOCK (playsink);
4175 gst_x_overlay_expose (xoverlay);
4176 gst_object_unref (xoverlay);
4181 gst_play_sink_xoverlay_handle_events (GstXOverlay * overlay,
4182 gboolean handle_events)
4184 GstPlaySink *playsink = GST_PLAY_SINK (overlay);
4185 GstXOverlay *xoverlay;
4187 GST_OBJECT_LOCK (playsink);
4188 if (playsink->xoverlay_element)
4189 xoverlay = GST_X_OVERLAY (gst_object_ref (playsink->xoverlay_element));
4192 GST_OBJECT_UNLOCK (playsink);
4194 playsink->xoverlay_handle_events_set = TRUE;
4195 playsink->xoverlay_handle_events = handle_events;
4198 gst_x_overlay_handle_events (xoverlay, handle_events);
4199 gst_object_unref (xoverlay);
4204 gst_play_sink_xoverlay_set_render_rectangle (GstXOverlay * overlay, gint x,
4205 gint y, gint width, gint height)
4207 GstPlaySink *playsink = GST_PLAY_SINK (overlay);
4208 GstXOverlay *xoverlay;
4210 GST_OBJECT_LOCK (playsink);
4211 if (playsink->xoverlay_element)
4212 xoverlay = GST_X_OVERLAY (gst_object_ref (playsink->xoverlay_element));
4215 GST_OBJECT_UNLOCK (playsink);
4217 playsink->xoverlay_render_rectangle_set = TRUE;
4218 playsink->xoverlay_x = x;
4219 playsink->xoverlay_y = y;
4220 playsink->xoverlay_width = width;
4221 playsink->xoverlay_height = height;
4224 gst_x_overlay_set_render_rectangle (xoverlay, x, y, width, height);
4225 gst_object_unref (xoverlay);
4230 gst_play_sink_xoverlay_set_window_handle (GstXOverlay * overlay,
4233 GstPlaySink *playsink = GST_PLAY_SINK (overlay);
4234 GstXOverlay *xoverlay;
4236 GST_OBJECT_LOCK (playsink);
4237 if (playsink->xoverlay_element)
4238 xoverlay = GST_X_OVERLAY (gst_object_ref (playsink->xoverlay_element));
4241 GST_OBJECT_UNLOCK (playsink);
4243 playsink->xoverlay_handle_set = TRUE;
4244 playsink->xoverlay_handle = handle;
4247 gst_x_overlay_set_window_handle (xoverlay, handle);
4248 gst_object_unref (xoverlay);
4253 gst_play_sink_xoverlay_init (gpointer g_iface, gpointer g_iface_data)
4255 GstXOverlayClass *iface = (GstXOverlayClass *) g_iface;
4256 iface->expose = gst_play_sink_xoverlay_expose;
4257 iface->handle_events = gst_play_sink_xoverlay_handle_events;
4258 iface->set_render_rectangle = gst_play_sink_xoverlay_set_render_rectangle;
4259 iface->set_window_handle = gst_play_sink_xoverlay_set_window_handle;
4263 gst_play_sink_implements_interface_supported (GstImplementsInterface * iface,
4266 if (type == GST_TYPE_X_OVERLAY || type == GST_TYPE_STREAM_VOLUME ||
4267 type == GST_TYPE_NAVIGATION || type == GST_TYPE_COLOR_BALANCE)
4274 gst_play_sink_implements_interface_init (gpointer g_iface,
4275 gpointer g_iface_data)
4277 GstImplementsInterfaceClass *iface = (GstImplementsInterfaceClass *) g_iface;
4278 iface->supported = gst_play_sink_implements_interface_supported;
4282 gst_play_sink_navigation_send_event (GstNavigation * navigation,
4283 GstStructure * structure)
4285 GstPlaySink *playsink = GST_PLAY_SINK (navigation);
4288 GST_PLAY_SINK_LOCK (playsink);
4289 if (playsink->videochain && playsink->videochain->chain.bin)
4290 bin = GST_BIN (gst_object_ref (playsink->videochain->chain.bin));
4291 GST_PLAY_SINK_UNLOCK (playsink);
4294 GstElement *nav = gst_bin_get_by_interface (bin, GST_TYPE_NAVIGATION);
4297 gst_navigation_send_event (GST_NAVIGATION (nav), structure);
4299 gst_object_unref (nav);
4301 GstEvent *event = gst_event_new_navigation (structure);
4303 gst_element_send_event (GST_ELEMENT (bin), event);
4306 gst_object_unref (bin);
4310 gst_structure_free (structure);
4314 gst_play_sink_navigation_init (gpointer g_iface, gpointer g_iface_data)
4316 GstNavigationInterface *iface = (GstNavigationInterface *) g_iface;
4318 iface->send_event = gst_play_sink_navigation_send_event;
4321 static const GList *
4322 gst_play_sink_colorbalance_list_channels (GstColorBalance * balance)
4324 GstPlaySink *playsink = GST_PLAY_SINK (balance);
4326 return playsink->colorbalance_channels;
4330 gst_play_sink_colorbalance_set_value (GstColorBalance * balance,
4331 GstColorBalanceChannel * proxy, gint value)
4333 GstPlaySink *playsink = GST_PLAY_SINK (balance);
4336 GstColorBalance *balance_element = NULL;
4338 GST_OBJECT_LOCK (playsink);
4339 if (playsink->colorbalance_element)
4341 GST_COLOR_BALANCE (gst_object_ref (playsink->colorbalance_element));
4342 GST_OBJECT_UNLOCK (playsink);
4344 for (i = 0, l = playsink->colorbalance_channels; l; l = l->next, i++) {
4345 GstColorBalanceChannel *proxy_tmp = l->data;
4348 if (proxy_tmp != proxy)
4351 playsink->colorbalance_values[i] = value;
4353 if (balance_element) {
4354 GstColorBalanceChannel *channel = NULL;
4355 const GList *channels, *k;
4357 channels = gst_color_balance_list_channels (balance_element);
4358 for (k = channels; k; k = k->next) {
4359 GstColorBalanceChannel *tmp = l->data;
4361 if (g_strrstr (tmp->label, proxy->label)) {
4369 /* Convert to [0, 1] range */
4372 (gdouble) proxy->min_value) / ((gdouble) proxy->max_value -
4373 (gdouble) proxy->min_value);
4374 /* Convert to channel range */
4376 channel->min_value + new_val * ((gdouble) channel->max_value -
4377 (gdouble) channel->min_value);
4379 gst_color_balance_set_value (balance_element, channel,
4380 (gint) (new_val + 0.5));
4382 gst_object_unref (balance_element);
4385 gst_color_balance_value_changed (balance, proxy, value);
4391 gst_play_sink_colorbalance_get_value (GstColorBalance * balance,
4392 GstColorBalanceChannel * proxy)
4394 GstPlaySink *playsink = GST_PLAY_SINK (balance);
4398 for (i = 0, l = playsink->colorbalance_channels; l; l = l->next, i++) {
4399 GstColorBalanceChannel *proxy_tmp = l->data;
4401 if (proxy_tmp != proxy)
4404 return playsink->colorbalance_values[i];
4407 g_return_val_if_reached (0);
4410 static GstColorBalanceType
4411 gst_play_sink_colorbalance_get_balance_type (GstColorBalance * balance)
4413 GstPlaySink *playsink = GST_PLAY_SINK (balance);
4414 GstColorBalance *balance_element = NULL;
4415 GstColorBalanceType t = GST_COLOR_BALANCE_SOFTWARE;
4417 GST_OBJECT_LOCK (playsink);
4418 if (playsink->colorbalance_element)
4420 GST_COLOR_BALANCE (gst_object_ref (playsink->colorbalance_element));
4421 GST_OBJECT_UNLOCK (playsink);
4423 if (balance_element) {
4424 t = gst_color_balance_get_balance_type (balance_element);
4425 gst_object_unref (balance_element);
4432 gst_play_sink_colorbalance_init (gpointer g_iface, gpointer g_iface_data)
4434 GstColorBalanceClass *iface = (GstColorBalanceClass *) g_iface;
4436 iface->list_channels = gst_play_sink_colorbalance_list_channels;
4437 iface->set_value = gst_play_sink_colorbalance_set_value;
4438 iface->get_value = gst_play_sink_colorbalance_get_value;
4439 iface->get_balance_type = gst_play_sink_colorbalance_get_balance_type;
4443 gst_play_sink_plugin_init (GstPlugin * plugin)
4445 GST_DEBUG_CATEGORY_INIT (gst_play_sink_debug, "playsink", 0, "play bin");
4446 return gst_element_register (plugin, "playsink", GST_RANK_NONE,
4447 GST_TYPE_PLAY_SINK);