Branch data Line data Source code
1 : : /* GStreamer
2 : : * (c) 2005 Ronald S. Bultje <rbultje@ronald.bitfreak.net>
3 : : * (c) 2005 Tim-Philipp Müller <tim centricular net>
4 : : *
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.
9 : : *
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.
14 : : *
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.
19 : : */
20 : : /**
21 : : * SECTION:element-gconfvideosrc
22 : : * @see_also: #GstAlsaSrc, #GstAutoVideoSrc
23 : : *
24 : : * This element records video from the videosink that has been configured in
25 : : * GConf by the user.
26 : : *
27 : : * <refsect2>
28 : : * <title>Example launch line</title>
29 : : * |[
30 : : * gst-launch gconfvideosrc ! theoraenc ! oggmux ! filesink location=record.ogg
31 : : * ]| Record from configured videoinput
32 : : * </refsect2>
33 : : */
34 : :
35 : : #ifdef HAVE_CONFIG_H
36 : : #include "config.h"
37 : : #endif
38 : :
39 : : #include <string.h>
40 : :
41 : : #include "gstgconfelements.h"
42 : : #include "gstgconfvideosrc.h"
43 : :
44 : : static void gst_gconf_video_src_dispose (GObject * object);
45 : : static void gst_gconf_video_src_finalize (GstGConfVideoSrc * src);
46 : : static void cb_toggle_element (GConfClient * client,
47 : : guint connection_id, GConfEntry * entry, gpointer data);
48 : : static GstStateChangeReturn
49 : : gst_gconf_video_src_change_state (GstElement * element,
50 : : GstStateChange transition);
51 : :
52 [ + + ]: 26 : GST_BOILERPLATE (GstGConfVideoSrc, gst_gconf_video_src, GstSwitchSrc,
53 : 26 : GST_TYPE_SWITCH_SRC);
54 : :
55 : : static void
56 : 7 : gst_gconf_video_src_base_init (gpointer klass)
57 : : {
58 : 7 : GstElementClass *eklass = GST_ELEMENT_CLASS (klass);
59 : :
60 : 7 : gst_element_class_set_details_simple (eklass, "GConf video source",
61 : : "Source/Video",
62 : : "Video source embedding the GConf-settings for video input",
63 : : "GStreamer maintainers <gstreamer-devel@lists.sourceforge.net>");
64 : 7 : }
65 : :
66 : : static void
67 : 7 : gst_gconf_video_src_class_init (GstGConfVideoSrcClass * klass)
68 : : {
69 : 7 : GObjectClass *oklass = G_OBJECT_CLASS (klass);
70 : 7 : GstElementClass *eklass = GST_ELEMENT_CLASS (klass);
71 : :
72 : 7 : oklass->dispose = gst_gconf_video_src_dispose;
73 : 7 : oklass->finalize = (GObjectFinalizeFunc) gst_gconf_video_src_finalize;
74 : 7 : eklass->change_state = gst_gconf_video_src_change_state;
75 : 7 : }
76 : :
77 : : /*
78 : : * Hack to make negotiation work.
79 : : */
80 : :
81 : : static gboolean
82 : 3 : gst_gconf_video_src_reset (GstGConfVideoSrc * src)
83 : : {
84 : 3 : gst_switch_src_set_child (GST_SWITCH_SRC (src), NULL);
85 : :
86 : 3 : g_free (src->gconf_str);
87 : 3 : src->gconf_str = NULL;
88 : :
89 : 3 : return TRUE;
90 : : }
91 : :
92 : : static void
93 : 3 : gst_gconf_video_src_init (GstGConfVideoSrc * src,
94 : : GstGConfVideoSrcClass * g_class)
95 : : {
96 : 3 : gst_gconf_video_src_reset (src);
97 : :
98 : 3 : src->client = gconf_client_get_default ();
99 : 3 : gconf_client_add_dir (src->client, GST_GCONF_DIR,
100 : : GCONF_CLIENT_PRELOAD_RECURSIVE, NULL);
101 : 3 : src->notify_id = gconf_client_notify_add (src->client,
102 : : GST_GCONF_DIR "/" GST_GCONF_VIDEOSRC_KEY,
103 : : cb_toggle_element, src, NULL, NULL);
104 : 3 : }
105 : :
106 : : static void
107 : 3 : gst_gconf_video_src_dispose (GObject * object)
108 : : {
109 : 3 : GstGConfVideoSrc *src = GST_GCONF_VIDEO_SRC (object);
110 : :
111 [ + - ]: 3 : if (src->client) {
112 [ + - ]: 3 : if (src->notify_id != 0)
113 : 3 : gconf_client_notify_remove (src->client, src->notify_id);
114 : :
115 : 3 : g_object_unref (G_OBJECT (src->client));
116 : 3 : src->client = NULL;
117 : : }
118 : :
119 [ + - ]: 3 : GST_CALL_PARENT (G_OBJECT_CLASS, dispose, (object));
120 : 3 : }
121 : :
122 : : static void
123 : 3 : gst_gconf_video_src_finalize (GstGConfVideoSrc * src)
124 : : {
125 : 3 : g_free (src->gconf_str);
126 : :
127 [ + - ]: 3 : GST_CALL_PARENT (G_OBJECT_CLASS, finalize, ((GObject *) (src)));
128 : 3 : }
129 : :
130 : : static gboolean
131 : 0 : do_toggle_element (GstGConfVideoSrc * src)
132 : : {
133 : : GstElement *new_kid;
134 : : gchar *new_gconf_str;
135 : :
136 : 0 : new_gconf_str = gst_gconf_get_string (GST_GCONF_VIDEOSRC_KEY);
137 [ # # ][ # # ]: 0 : if (new_gconf_str != NULL && src->gconf_str != NULL &&
[ # # ]
138 [ # # ]: 0 : (strlen (new_gconf_str) == 0 ||
139 : 0 : strcmp (src->gconf_str, new_gconf_str) == 0)) {
140 : 0 : g_free (new_gconf_str);
141 [ # # ]: 0 : GST_DEBUG_OBJECT (src, "GConf key was updated, but it didn't change");
142 : 0 : return TRUE;
143 : : }
144 : :
145 [ # # ][ # # ]: 0 : GST_DEBUG_OBJECT (src, "GConf key changed: '%s' to '%s'",
[ # # ]
146 : : GST_STR_NULL (src->gconf_str), GST_STR_NULL (new_gconf_str));
147 : :
148 [ # # ]: 0 : GST_DEBUG_OBJECT (src, "Creating new kid");
149 [ # # ]: 0 : if (!(new_kid = gst_gconf_get_default_video_src ())) {
150 [ # # ][ # # ]: 0 : GST_ELEMENT_ERROR (src, LIBRARY, SETTINGS, (NULL),
[ # # ][ # # ]
151 : : ("Failed to render video src from GConf"));
152 : 0 : return FALSE;
153 : : }
154 : :
155 [ # # ]: 0 : if (!gst_switch_src_set_child (GST_SWITCH_SRC (src), new_kid)) {
156 [ # # ]: 0 : GST_WARNING_OBJECT (src, "Failed to update child element");
157 : 0 : goto fail;
158 : : }
159 : :
160 : 0 : g_free (src->gconf_str);
161 : 0 : src->gconf_str = new_gconf_str;
162 : :
163 [ # # ]: 0 : GST_DEBUG_OBJECT (src, "done changing gconf video src");
164 : :
165 : 0 : return TRUE;
166 : : fail:
167 : 0 : g_free (new_gconf_str);
168 : 0 : return FALSE;
169 : : }
170 : :
171 : : static void
172 : 0 : cb_toggle_element (GConfClient * client,
173 : : guint connection_id, GConfEntry * entry, gpointer data)
174 : : {
175 : 0 : do_toggle_element (GST_GCONF_VIDEO_SRC (data));
176 : 0 : }
177 : :
178 : : static GstStateChangeReturn
179 : 0 : gst_gconf_video_src_change_state (GstElement * element,
180 : : GstStateChange transition)
181 : : {
182 : 0 : GstStateChangeReturn ret = GST_STATE_CHANGE_SUCCESS;
183 : 0 : GstGConfVideoSrc *src = GST_GCONF_VIDEO_SRC (element);
184 : :
185 [ # # ]: 0 : switch (transition) {
186 : : case GST_STATE_CHANGE_NULL_TO_READY:
187 [ # # ]: 0 : if (!do_toggle_element (src)) {
188 : 0 : gst_gconf_video_src_reset (src);
189 : 0 : return GST_STATE_CHANGE_FAILURE;
190 : : }
191 : 0 : break;
192 : : default:
193 : 0 : break;
194 : : }
195 : :
196 [ # # ]: 0 : ret = GST_CALL_PARENT_WITH_DEFAULT (GST_ELEMENT_CLASS, change_state,
197 : : (element, transition), GST_STATE_CHANGE_SUCCESS);
198 : :
199 [ # # ]: 0 : switch (transition) {
200 : : case GST_STATE_CHANGE_READY_TO_NULL:
201 [ # # ]: 0 : if (!gst_gconf_video_src_reset (src))
202 : 0 : ret = GST_STATE_CHANGE_FAILURE;
203 : 0 : break;
204 : : default:
205 : 0 : break;
206 : : }
207 : :
208 : 0 : return ret;
209 : : }
|