2 * (c) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
20 * SECTION:element-gconfvideosink
22 * This element outputs video to the videosink that has been configured in
26 * <title>Example launch line</title>
28 * gst-launch filesrc location=foo.ogg ! decodebin ! ffmpegcolorspace ! gconfvideosink
29 * ]| Play on configured videosink
39 #include "gstgconfelements.h"
40 #include "gstgconfvideosink.h"
42 static void gst_gconf_video_sink_dispose (GObject * object);
43 static void gst_gconf_video_sink_finalize (GstGConfVideoSink * sink);
44 static void cb_toggle_element (GConfClient * client,
45 guint connection_id, GConfEntry * entry, gpointer data);
46 static GstStateChangeReturn
47 gst_gconf_video_sink_change_state (GstElement * element,
48 GstStateChange transition);
50 GST_BOILERPLATE (GstGConfVideoSink, gst_gconf_video_sink, GstSwitchSink,
51 GST_TYPE_SWITCH_SINK);
54 gst_gconf_video_sink_base_init (gpointer klass)
56 GstElementClass *eklass = GST_ELEMENT_CLASS (klass);
58 gst_element_class_set_details_simple (eklass, "GConf video sink",
60 "Video sink embedding the GConf-settings for video output",
61 "GStreamer maintainers <gstreamer-devel@lists.sourceforge.net>");
65 gst_gconf_video_sink_class_init (GstGConfVideoSinkClass * klass)
67 GObjectClass *oklass = G_OBJECT_CLASS (klass);
68 GstElementClass *eklass = GST_ELEMENT_CLASS (klass);
70 oklass->dispose = gst_gconf_video_sink_dispose;
71 oklass->finalize = (GObjectFinalizeFunc) gst_gconf_video_sink_finalize;
72 eklass->change_state = gst_gconf_video_sink_change_state;
76 * Hack to make negotiation work.
80 gst_gconf_video_sink_reset (GstGConfVideoSink * sink)
82 gst_switch_sink_set_child (GST_SWITCH_SINK (sink), NULL);
84 g_free (sink->gconf_str);
85 sink->gconf_str = NULL;
89 gst_gconf_video_sink_init (GstGConfVideoSink * sink,
90 GstGConfVideoSinkClass * g_class)
92 gst_gconf_video_sink_reset (sink);
94 sink->client = gconf_client_get_default ();
95 gconf_client_add_dir (sink->client, GST_GCONF_DIR,
96 GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
97 sink->notify_id = gconf_client_notify_add (sink->client,
98 GST_GCONF_DIR "/" GST_GCONF_VIDEOSINK_KEY,
99 cb_toggle_element, sink, NULL, NULL);
103 gst_gconf_video_sink_dispose (GObject * object)
105 GstGConfVideoSink *sink = GST_GCONF_VIDEO_SINK (object);
108 if (sink->notify_id != 0)
109 gconf_client_notify_remove (sink->client, sink->notify_id);
111 g_object_unref (G_OBJECT (sink->client));
115 GST_CALL_PARENT (G_OBJECT_CLASS, dispose, (object));
119 gst_gconf_video_sink_finalize (GstGConfVideoSink * sink)
121 g_free (sink->gconf_str);
123 GST_CALL_PARENT (G_OBJECT_CLASS, finalize, ((GObject *) (sink)));
127 do_change_child (GstGConfVideoSink * sink)
129 gchar *new_gconf_str;
132 new_gconf_str = gst_gconf_get_string (GST_GCONF_VIDEOSINK_KEY);
134 GST_LOG_OBJECT (sink, "old gconf string: %s", GST_STR_NULL (sink->gconf_str));
135 GST_LOG_OBJECT (sink, "new gconf string: %s", GST_STR_NULL (new_gconf_str));
137 if (new_gconf_str != NULL && sink->gconf_str != NULL &&
138 (strlen (new_gconf_str) == 0 ||
139 strcmp (sink->gconf_str, new_gconf_str) == 0)) {
140 g_free (new_gconf_str);
141 GST_DEBUG_OBJECT (sink,
142 "GConf key was updated, but it didn't change. Ignoring");
146 GST_DEBUG_OBJECT (sink, "GConf key changed: '%s' to '%s'",
147 GST_STR_NULL (sink->gconf_str), GST_STR_NULL (new_gconf_str));
149 GST_DEBUG_OBJECT (sink, "Creating new kid");
150 if (!(new_kid = gst_gconf_get_default_video_sink ())) {
151 GST_ELEMENT_ERROR (sink, LIBRARY, SETTINGS, (NULL),
152 ("Failed to render video sink from GConf"));
156 if (!gst_switch_sink_set_child (GST_SWITCH_SINK (sink), new_kid)) {
157 GST_WARNING_OBJECT (sink, "Failed to update child element");
161 g_free (sink->gconf_str);
162 sink->gconf_str = new_gconf_str;
164 GST_DEBUG_OBJECT (sink, "done changing gconf video sink");
169 g_free (new_gconf_str);
174 cb_toggle_element (GConfClient * client,
175 guint connection_id, GConfEntry * entry, gpointer data)
177 do_change_child (GST_GCONF_VIDEO_SINK (data));
180 static GstStateChangeReturn
181 gst_gconf_video_sink_change_state (GstElement * element,
182 GstStateChange transition)
184 GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
185 GstGConfVideoSink *sink = GST_GCONF_VIDEO_SINK (element);
187 switch (transition) {
188 case GST_STATE_CHANGE_NULL_TO_READY:
189 if (!do_change_child (sink)) {
190 gst_gconf_video_sink_reset (sink);
191 return GST_STATE_CHANGE_FAILURE;
198 ret = GST_CALL_PARENT_WITH_DEFAULT (GST_ELEMENT_CLASS, change_state,
199 (element, transition), GST_STATE_CHANGE_SUCCESS);
201 switch (transition) {
202 case GST_STATE_CHANGE_READY_TO_NULL:
203 gst_gconf_video_sink_reset (sink);