Branch data Line data Source code
1 : : /* GStreamer
2 : : * (c) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
3 : : *
4 : : * This library is free software; you can redistribute it and/or
5 : : * modify it under the terms of the GNU Library General Public
6 : : * License as published by the Free Software Foundation; either
7 : : * version 2 of the License, or (at your option) any later version.
8 : : *
9 : : * This library is distributed in the hope that it will be useful,
10 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 : : * Library General Public License for more details.
13 : : *
14 : : * You should have received a copy of the GNU Library General Public
15 : : * License along with this library; if not, write to the
16 : : * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 : : * Boston, MA 02111-1307, USA.
18 : : */
19 : : /**
20 : : * SECTION:element-gconfvideosink
21 : : *
22 : : * This element outputs video to the videosink that has been configured in
23 : : * GConf by the user.
24 : : *
25 : : * <refsect2>
26 : : * <title>Example launch line</title>
27 : : * |[
28 : : * gst-launch filesrc location=foo.ogg ! decodebin ! ffmpegcolorspace ! gconfvideosink
29 : : * ]| Play on configured videosink
30 : : * </refsect2>
31 : : */
32 : :
33 : : #ifdef HAVE_CONFIG_H
34 : : #include "config.h"
35 : : #endif
36 : :
37 : : #include <string.h>
38 : :
39 : : #include "gstgconfelements.h"
40 : : #include "gstgconfvideosink.h"
41 : :
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);
49 : :
50 [ + + ]: 26 : GST_BOILERPLATE (GstGConfVideoSink, gst_gconf_video_sink, GstSwitchSink,
51 : 26 : GST_TYPE_SWITCH_SINK);
52 : :
53 : : static void
54 : 7 : gst_gconf_video_sink_base_init (gpointer klass)
55 : : {
56 : 7 : GstElementClass *eklass = GST_ELEMENT_CLASS (klass);
57 : :
58 : 7 : gst_element_class_set_details_simple (eklass, "GConf video sink",
59 : : "Sink/Video",
60 : : "Video sink embedding the GConf-settings for video output",
61 : : "GStreamer maintainers <gstreamer-devel@lists.sourceforge.net>");
62 : 7 : }
63 : :
64 : : static void
65 : 7 : gst_gconf_video_sink_class_init (GstGConfVideoSinkClass * klass)
66 : : {
67 : 7 : GObjectClass *oklass = G_OBJECT_CLASS (klass);
68 : 7 : GstElementClass *eklass = GST_ELEMENT_CLASS (klass);
69 : :
70 : 7 : oklass->dispose = gst_gconf_video_sink_dispose;
71 : 7 : oklass->finalize = (GObjectFinalizeFunc) gst_gconf_video_sink_finalize;
72 : 7 : eklass->change_state = gst_gconf_video_sink_change_state;
73 : 7 : }
74 : :
75 : : /*
76 : : * Hack to make negotiation work.
77 : : */
78 : :
79 : : static void
80 : 3 : gst_gconf_video_sink_reset (GstGConfVideoSink * sink)
81 : : {
82 : 3 : gst_switch_sink_set_child (GST_SWITCH_SINK (sink), NULL);
83 : :
84 : 3 : g_free (sink->gconf_str);
85 : 3 : sink->gconf_str = NULL;
86 : 3 : }
87 : :
88 : : static void
89 : 3 : gst_gconf_video_sink_init (GstGConfVideoSink * sink,
90 : : GstGConfVideoSinkClass * g_class)
91 : : {
92 : 3 : gst_gconf_video_sink_reset (sink);
93 : :
94 : 3 : sink->client = gconf_client_get_default ();
95 : 3 : gconf_client_add_dir (sink->client, GST_GCONF_DIR,
96 : : GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
97 : 3 : sink->notify_id = gconf_client_notify_add (sink->client,
98 : : GST_GCONF_DIR "/" GST_GCONF_VIDEOSINK_KEY,
99 : : cb_toggle_element, sink, NULL, NULL);
100 : 3 : }
101 : :
102 : : static void
103 : 3 : gst_gconf_video_sink_dispose (GObject * object)
104 : : {
105 : 3 : GstGConfVideoSink *sink = GST_GCONF_VIDEO_SINK (object);
106 : :
107 [ + - ]: 3 : if (sink->client) {
108 [ + - ]: 3 : if (sink->notify_id != 0)
109 : 3 : gconf_client_notify_remove (sink->client, sink->notify_id);
110 : :
111 : 3 : g_object_unref (G_OBJECT (sink->client));
112 : 3 : sink->client = NULL;
113 : : }
114 : :
115 [ + - ]: 3 : GST_CALL_PARENT (G_OBJECT_CLASS, dispose, (object));
116 : 3 : }
117 : :
118 : : static void
119 : 3 : gst_gconf_video_sink_finalize (GstGConfVideoSink * sink)
120 : : {
121 : 3 : g_free (sink->gconf_str);
122 : :
123 [ + - ]: 3 : GST_CALL_PARENT (G_OBJECT_CLASS, finalize, ((GObject *) (sink)));
124 : 3 : }
125 : :
126 : : static gboolean
127 : 0 : do_change_child (GstGConfVideoSink * sink)
128 : : {
129 : : gchar *new_gconf_str;
130 : : GstElement *new_kid;
131 : :
132 : 0 : new_gconf_str = gst_gconf_get_string (GST_GCONF_VIDEOSINK_KEY);
133 : :
134 [ # # ][ # # ]: 0 : GST_LOG_OBJECT (sink, "old gconf string: %s", GST_STR_NULL (sink->gconf_str));
135 [ # # ][ # # ]: 0 : GST_LOG_OBJECT (sink, "new gconf string: %s", GST_STR_NULL (new_gconf_str));
136 : :
137 [ # # ][ # # ]: 0 : if (new_gconf_str != NULL && sink->gconf_str != NULL &&
[ # # ]
138 [ # # ]: 0 : (strlen (new_gconf_str) == 0 ||
139 : 0 : strcmp (sink->gconf_str, new_gconf_str) == 0)) {
140 : 0 : g_free (new_gconf_str);
141 [ # # ]: 0 : GST_DEBUG_OBJECT (sink,
142 : : "GConf key was updated, but it didn't change. Ignoring");
143 : 0 : return TRUE;
144 : : }
145 : :
146 [ # # ][ # # ]: 0 : GST_DEBUG_OBJECT (sink, "GConf key changed: '%s' to '%s'",
[ # # ]
147 : : GST_STR_NULL (sink->gconf_str), GST_STR_NULL (new_gconf_str));
148 : :
149 [ # # ]: 0 : GST_DEBUG_OBJECT (sink, "Creating new kid");
150 [ # # ]: 0 : if (!(new_kid = gst_gconf_get_default_video_sink ())) {
151 [ # # ][ # # ]: 0 : GST_ELEMENT_ERROR (sink, LIBRARY, SETTINGS, (NULL),
[ # # ][ # # ]
152 : : ("Failed to render video sink from GConf"));
153 : 0 : return FALSE;
154 : : }
155 : :
156 [ # # ]: 0 : if (!gst_switch_sink_set_child (GST_SWITCH_SINK (sink), new_kid)) {
157 [ # # ]: 0 : GST_WARNING_OBJECT (sink, "Failed to update child element");
158 : 0 : goto fail;
159 : : }
160 : :
161 : 0 : g_free (sink->gconf_str);
162 : 0 : sink->gconf_str = new_gconf_str;
163 : :
164 [ # # ]: 0 : GST_DEBUG_OBJECT (sink, "done changing gconf video sink");
165 : :
166 : 0 : return TRUE;
167 : :
168 : : fail:
169 : 0 : g_free (new_gconf_str);
170 : 0 : return FALSE;
171 : : }
172 : :
173 : : static void
174 : 0 : cb_toggle_element (GConfClient * client,
175 : : guint connection_id, GConfEntry * entry, gpointer data)
176 : : {
177 : 0 : do_change_child (GST_GCONF_VIDEO_SINK (data));
178 : 0 : }
179 : :
180 : : static GstStateChangeReturn
181 : 0 : gst_gconf_video_sink_change_state (GstElement * element,
182 : : GstStateChange transition)
183 : : {
184 : 0 : GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
185 : 0 : GstGConfVideoSink *sink = GST_GCONF_VIDEO_SINK (element);
186 : :
187 [ # # ]: 0 : switch (transition) {
188 : : case GST_STATE_CHANGE_NULL_TO_READY:
189 [ # # ]: 0 : if (!do_change_child (sink)) {
190 : 0 : gst_gconf_video_sink_reset (sink);
191 : 0 : return GST_STATE_CHANGE_FAILURE;
192 : : }
193 : 0 : break;
194 : : default:
195 : 0 : break;
196 : : }
197 : :
198 [ # # ]: 0 : ret = GST_CALL_PARENT_WITH_DEFAULT (GST_ELEMENT_CLASS, change_state,
199 : : (element, transition), GST_STATE_CHANGE_SUCCESS);
200 : :
201 [ # # ]: 0 : switch (transition) {
202 : : case GST_STATE_CHANGE_READY_TO_NULL:
203 : 0 : gst_gconf_video_sink_reset (sink);
204 : 0 : break;
205 : : default:
206 : 0 : break;
207 : : }
208 : :
209 : 0 : return ret;
210 : : }
|