1 | /* GStreamer |
---|
2 | * Copyright (C) 2001 Steve Baker <stevebaker_org@yahoo.co.uk> |
---|
3 | * |
---|
4 | * dparamstest.c: |
---|
5 | * |
---|
6 | * This library is free software; you can redistribute it and/or |
---|
7 | * modify it under the terms of the GNU Library General Public |
---|
8 | * License as published by the Free Software Foundation; either |
---|
9 | * version 2 of the License, or (at your option) any later version. |
---|
10 | * |
---|
11 | * This library is distributed in the hope that it will be useful, |
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | * Library General Public License for more details. |
---|
15 | * |
---|
16 | * You should have received a copy of the GNU Library General Public |
---|
17 | * License along with this library; if not, write to the |
---|
18 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
---|
19 | * Boston, MA 02111-1307, USA. |
---|
20 | */ |
---|
21 | |
---|
22 | #include <stdlib.h> |
---|
23 | #include <string.h> |
---|
24 | #include <unistd.h> |
---|
25 | #ifdef HAVE_CONFIG_H |
---|
26 | #include "config.h" |
---|
27 | #endif |
---|
28 | |
---|
29 | #include <gst/gst.h> |
---|
30 | #include <gst/control/control.h> |
---|
31 | |
---|
32 | #define GST_TYPE_DPTEST (gst_dptest_get_type()) |
---|
33 | #define GST_DPTEST(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_DPTEST,GstDpTest)) |
---|
34 | #define GST_DPTEST_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_DPTEST,GstDpTestClass)) |
---|
35 | #define GST_IS_DPTEST(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_DPTEST)) |
---|
36 | #define GST_IS_DPTEST_CLASS(obj) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_DPTEST)) |
---|
37 | |
---|
38 | typedef struct _GstDpTest GstDpTest; |
---|
39 | typedef struct _GstDpTestClass GstDpTestClass; |
---|
40 | |
---|
41 | struct _GstDpTest |
---|
42 | { |
---|
43 | GstElement element; |
---|
44 | |
---|
45 | GstPad *sinkpad; |
---|
46 | GstPad *srcpad; |
---|
47 | GstDParamManager *dpman; |
---|
48 | |
---|
49 | gfloat float1; |
---|
50 | gfloat float2; |
---|
51 | gboolean bool1; |
---|
52 | gdouble double1; |
---|
53 | }; |
---|
54 | |
---|
55 | struct _GstDpTestClass |
---|
56 | { |
---|
57 | GstElementClass parent_class; |
---|
58 | }; |
---|
59 | |
---|
60 | GType gst_dptest_get_type (void); |
---|
61 | |
---|
62 | enum |
---|
63 | { |
---|
64 | ARG_0, |
---|
65 | }; |
---|
66 | |
---|
67 | GstStaticPadTemplate srctemplate = GST_STATIC_PAD_TEMPLATE ("src", |
---|
68 | GST_PAD_SRC, |
---|
69 | GST_PAD_ALWAYS, |
---|
70 | GST_STATIC_CAPS_ANY); |
---|
71 | |
---|
72 | GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink", |
---|
73 | GST_PAD_SINK, |
---|
74 | GST_PAD_ALWAYS, |
---|
75 | GST_STATIC_CAPS_ANY); |
---|
76 | |
---|
77 | |
---|
78 | static void gst_dptest_base_init (gpointer g_class); |
---|
79 | static void gst_dptest_class_init (GstDpTestClass * klass); |
---|
80 | static void gst_dptest_init (GstDpTest * dptest); |
---|
81 | |
---|
82 | static void gst_dptest_set_property (GObject * object, guint prop_id, |
---|
83 | const GValue * value, GParamSpec * pspec); |
---|
84 | |
---|
85 | static GstElementStateReturn gst_dptest_change_state (GstElement * element); |
---|
86 | static void gst_dptest_chain (GstPad * pad, GstData * buf); |
---|
87 | |
---|
88 | static GstElementClass *parent_class = NULL; |
---|
89 | |
---|
90 | GType |
---|
91 | gst_dptest_get_type (void) |
---|
92 | { |
---|
93 | static GType dptest_type = 0; |
---|
94 | |
---|
95 | if (!dptest_type) { |
---|
96 | static const GTypeInfo dptest_info = { |
---|
97 | sizeof (GstDpTestClass), |
---|
98 | gst_dptest_base_init, |
---|
99 | NULL, |
---|
100 | (GClassInitFunc) gst_dptest_class_init, |
---|
101 | NULL, |
---|
102 | NULL, |
---|
103 | sizeof (GstDpTest), |
---|
104 | 0, |
---|
105 | (GInstanceInitFunc) gst_dptest_init, |
---|
106 | }; |
---|
107 | |
---|
108 | dptest_type = |
---|
109 | g_type_register_static (GST_TYPE_ELEMENT, "GstDpTest", &dptest_info, 0); |
---|
110 | } |
---|
111 | return dptest_type; |
---|
112 | } |
---|
113 | |
---|
114 | static void |
---|
115 | gst_dptest_base_init (gpointer g_class) |
---|
116 | { |
---|
117 | static GstElementDetails dptest_details = GST_ELEMENT_DETAILS ("DParamTest", |
---|
118 | "Filter", |
---|
119 | "Test for the GstDParam code", |
---|
120 | "Steve Baker <stevebaker_org@yahoo.co.uk>"); |
---|
121 | GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); |
---|
122 | |
---|
123 | gst_element_class_set_details (element_class, &dptest_details); |
---|
124 | } |
---|
125 | |
---|
126 | static void |
---|
127 | gst_dptest_class_init (GstDpTestClass * klass) |
---|
128 | { |
---|
129 | GObjectClass *gobject_class; |
---|
130 | GstElementClass *gstelement_class; |
---|
131 | |
---|
132 | gobject_class = (GObjectClass *) klass; |
---|
133 | gstelement_class = (GstElementClass *) klass; |
---|
134 | |
---|
135 | parent_class = g_type_class_ref (GST_TYPE_ELEMENT); |
---|
136 | |
---|
137 | gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_dptest_set_property); |
---|
138 | |
---|
139 | gstelement_class->change_state = gst_dptest_change_state; |
---|
140 | |
---|
141 | } |
---|
142 | |
---|
143 | static void |
---|
144 | gst_dptest_init (GstDpTest * dptest) |
---|
145 | { |
---|
146 | |
---|
147 | dptest->sinkpad = |
---|
148 | gst_pad_new_from_template (gst_static_pad_template_get (&sinktemplate), |
---|
149 | "sink"); |
---|
150 | gst_element_add_pad (GST_ELEMENT (dptest), dptest->sinkpad); |
---|
151 | gst_pad_set_chain_function (dptest->sinkpad, gst_dptest_chain); |
---|
152 | |
---|
153 | dptest->srcpad = |
---|
154 | gst_pad_new_from_template (gst_static_pad_template_get (&srctemplate), |
---|
155 | "src"); |
---|
156 | gst_element_add_pad (GST_ELEMENT (dptest), dptest->srcpad); |
---|
157 | |
---|
158 | dptest->dpman = gst_dpman_new ("dptest_dpman", GST_ELEMENT (dptest)); |
---|
159 | |
---|
160 | gst_dpman_add_required_dparam_direct (dptest->dpman, |
---|
161 | g_param_spec_float ("float1", "float1", "float1", |
---|
162 | 0.0, 1.0, 0.5, G_PARAM_READWRITE), "float", &(dptest->float1) |
---|
163 | ); |
---|
164 | |
---|
165 | dptest->float1 = 0.0; |
---|
166 | } |
---|
167 | |
---|
168 | static void |
---|
169 | gst_dptest_set_property (GObject * object, guint prop_id, const GValue * value, |
---|
170 | GParamSpec * pspec) |
---|
171 | { |
---|
172 | GstDpTest *dptest; |
---|
173 | |
---|
174 | /* it's not null if we got it, but it might not be ours */ |
---|
175 | g_return_if_fail (GST_IS_DPTEST (object)); |
---|
176 | |
---|
177 | dptest = GST_DPTEST (object); |
---|
178 | |
---|
179 | switch (prop_id) { |
---|
180 | default: |
---|
181 | G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); |
---|
182 | break; |
---|
183 | } |
---|
184 | } |
---|
185 | |
---|
186 | static GstElementStateReturn |
---|
187 | gst_dptest_change_state (GstElement * element) |
---|
188 | { |
---|
189 | GstDpTest *dptest; |
---|
190 | |
---|
191 | g_return_val_if_fail (GST_IS_DPTEST (element), GST_STATE_FAILURE); |
---|
192 | |
---|
193 | dptest = GST_DPTEST (element); |
---|
194 | if (GST_ELEMENT_CLASS (parent_class)->change_state) |
---|
195 | return GST_ELEMENT_CLASS (parent_class)->change_state (element); |
---|
196 | |
---|
197 | return GST_STATE_SUCCESS; |
---|
198 | } |
---|
199 | |
---|
200 | static void |
---|
201 | gst_dptest_chain (GstPad * pad, GstData * data) |
---|
202 | { |
---|
203 | GstDpTest *dptest; |
---|
204 | gint frame_count; |
---|
205 | |
---|
206 | dptest = GST_DPTEST (gst_pad_get_parent (pad)); |
---|
207 | g_assert (dptest); |
---|
208 | g_print ("dp chain\n"); |
---|
209 | |
---|
210 | /* we're using a made up buffer size of 64 and a timestamp of zero */ |
---|
211 | g_print ("preprocess\n"); |
---|
212 | frame_count = 0; |
---|
213 | GST_DPMAN_PREPROCESS (dptest->dpman, 64, 0LL); |
---|
214 | |
---|
215 | while (GST_DPMAN_PROCESS (dptest->dpman, frame_count)) { |
---|
216 | ++frame_count; |
---|
217 | } |
---|
218 | g_print ("dp chain done\n"); |
---|
219 | } |
---|
220 | |
---|
221 | gboolean |
---|
222 | gst_dptest_register_elements (GstPlugin * plugin) |
---|
223 | { |
---|
224 | return gst_element_register (plugin, "dptest", GST_RANK_NONE, |
---|
225 | GST_TYPE_DPTEST); |
---|
226 | } |
---|
227 | |
---|
228 | static GstPluginDesc plugin_desc = { |
---|
229 | GST_VERSION_MAJOR, |
---|
230 | GST_VERSION_MINOR, |
---|
231 | "dptest_elements", |
---|
232 | "test elements", |
---|
233 | &gst_dptest_register_elements, |
---|
234 | NULL, |
---|
235 | VERSION, |
---|
236 | GST_LICENSE, |
---|
237 | GST_PACKAGE, |
---|
238 | GST_ORIGIN |
---|
239 | }; |
---|
240 | |
---|
241 | int |
---|
242 | main (int argc, char *argv[]) |
---|
243 | { |
---|
244 | |
---|
245 | GstElement *src; |
---|
246 | GstElement *sink; |
---|
247 | GstElement *testelement; |
---|
248 | GstElement *pipeline; |
---|
249 | GstDParamManager *dpman; |
---|
250 | GstDParam *dp_float1; |
---|
251 | GValue *dp_float1_value; |
---|
252 | |
---|
253 | gst_init (&argc, &argv); |
---|
254 | gst_control_init (&argc, &argv); |
---|
255 | |
---|
256 | _gst_plugin_register_static (&plugin_desc); |
---|
257 | |
---|
258 | pipeline = gst_element_factory_make ("pipeline", "pipeline"); |
---|
259 | g_assert (pipeline); |
---|
260 | |
---|
261 | src = gst_element_factory_make ("fakesrc", "src"); |
---|
262 | g_assert (src); |
---|
263 | |
---|
264 | sink = gst_element_factory_make ("fakesink", "sink"); |
---|
265 | g_assert (sink); |
---|
266 | |
---|
267 | testelement = gst_element_factory_make ("dptest", "testelement"); |
---|
268 | g_assert (testelement); |
---|
269 | |
---|
270 | gst_bin_add_many (GST_BIN (pipeline), src, testelement, sink, NULL); |
---|
271 | gst_element_link_many (src, testelement, sink, NULL); |
---|
272 | |
---|
273 | g_object_set (G_OBJECT (src), "num_buffers", 1, NULL); |
---|
274 | |
---|
275 | g_print ("setting pipeline to play\n"); |
---|
276 | gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); |
---|
277 | |
---|
278 | /* test that dparam manager is accessable */ |
---|
279 | g_print ("getting dparam manager\n"); |
---|
280 | dpman = gst_dpman_get_manager (testelement); |
---|
281 | gst_dpman_set_mode (dpman, "synchronous"); |
---|
282 | |
---|
283 | g_assert (dpman); |
---|
284 | g_assert (GST_IS_DPMAN (dpman)); |
---|
285 | |
---|
286 | g_print ("creating dparam for float1\n"); |
---|
287 | dp_float1 = gst_dparam_new (G_TYPE_FLOAT);; |
---|
288 | g_assert (dp_float1); |
---|
289 | g_assert (GST_IS_DPARAM (dp_float1)); |
---|
290 | |
---|
291 | g_print ("attach dparam to float1\n"); |
---|
292 | g_assert (gst_dpman_attach_dparam (dpman, "float1", dp_float1)); |
---|
293 | |
---|
294 | dp_float1_value = g_new0 (GValue, 1); |
---|
295 | g_value_init (dp_float1_value, G_TYPE_FLOAT); |
---|
296 | |
---|
297 | g_value_set_float (dp_float1_value, 0.1); |
---|
298 | g_object_set_property (G_OBJECT (dp_float1), "value_float", dp_float1_value); |
---|
299 | |
---|
300 | g_print ("iterate once\n"); |
---|
301 | gst_bin_iterate (GST_BIN (pipeline)); |
---|
302 | |
---|
303 | g_print ("check that value changed\n"); |
---|
304 | g_assert (GST_DPTEST (testelement)->float1 == 0.1F); |
---|
305 | g_assert (!GST_DPARAM_READY_FOR_UPDATE (dp_float1)); |
---|
306 | |
---|
307 | g_print ("nulling pipeline\n"); |
---|
308 | gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL); |
---|
309 | |
---|
310 | g_print ("playing pipeline\n"); |
---|
311 | gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING); |
---|
312 | |
---|
313 | g_print ("iterate twice\n"); |
---|
314 | |
---|
315 | g_object_set (G_OBJECT (src), "num_buffers", 2, NULL); |
---|
316 | gst_bin_iterate (GST_BIN (pipeline)); |
---|
317 | |
---|
318 | return 0; |
---|
319 | } |
---|