2 * Copyright (C) 2001 Steve Baker <stevebaker_org@yahoo.co.uk>
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.
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.
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.
30 #include <gst/control/control.h>
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))
38 typedef struct _GstDpTest GstDpTest;
39 typedef struct _GstDpTestClass GstDpTestClass;
47 GstDParamManager *dpman;
55 struct _GstDpTestClass
57 GstElementClass parent_class;
60 GType gst_dptest_get_type (void);
68 static void gst_dptest_base_init (gpointer g_class);
69 static void gst_dptest_class_init (GstDpTestClass * klass);
70 static void gst_dptest_init (GstDpTest * dptest);
72 static void gst_dptest_set_property (GObject * object, guint prop_id,
73 const GValue * value, GParamSpec * pspec);
75 static GstElementStateReturn gst_dptest_change_state (GstElement * element);
76 static void gst_dptest_chain (GstPad * pad, GstData * buf);
78 static GstElementClass *parent_class = NULL;
81 gst_dptest_get_type (void)
83 static GType dptest_type = 0;
86 static const GTypeInfo dptest_info = {
87 sizeof (GstDpTestClass),
90 (GClassInitFunc) gst_dptest_class_init,
95 (GInstanceInitFunc) gst_dptest_init,
99 g_type_register_static (GST_TYPE_ELEMENT, "GstDpTest", &dptest_info, 0);
105 gst_dptest_base_init (gpointer g_class)
107 static GstElementDetails dptest_details = GST_ELEMENT_DETAILS ("DParamTest",
109 "Test for the GstDParam code",
110 "Steve Baker <stevebaker_org@yahoo.co.uk>");
111 GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
113 gst_element_class_set_details (element_class, &dptest_details);
115 g_print ("got here %d\n", __LINE__);
119 gst_dptest_class_init (GstDpTestClass * klass)
121 GObjectClass *gobject_class;
122 GstElementClass *gstelement_class;
124 gobject_class = (GObjectClass *) klass;
125 gstelement_class = (GstElementClass *) klass;
127 parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
129 gobject_class->set_property = GST_DEBUG_FUNCPTR (gst_dptest_set_property);
131 gstelement_class->change_state = gst_dptest_change_state;
136 gst_dptest_init (GstDpTest * dptest)
139 dptest->sinkpad = gst_pad_new ("sink", GST_PAD_SINK);
140 gst_element_add_pad (GST_ELEMENT (dptest), dptest->sinkpad);
141 gst_pad_set_chain_function (dptest->sinkpad, gst_dptest_chain);
143 dptest->srcpad = gst_pad_new ("src", GST_PAD_SRC);
144 gst_element_add_pad (GST_ELEMENT (dptest), dptest->srcpad);
146 dptest->dpman = gst_dpman_new ("dptest_dpman", GST_ELEMENT (dptest));
148 gst_dpman_add_required_dparam_direct (dptest->dpman,
149 g_param_spec_float ("float1", "float1", "float1",
150 0.0, 1.0, 0.5, G_PARAM_READWRITE), "float", &(dptest->float1)
153 dptest->float1 = 0.0;
157 gst_dptest_set_property (GObject * object, guint prop_id, const GValue * value,
162 /* it's not null if we got it, but it might not be ours */
163 g_return_if_fail (GST_IS_DPTEST (object));
165 dptest = GST_DPTEST (object);
169 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
174 static GstElementStateReturn
175 gst_dptest_change_state (GstElement * element)
179 g_return_val_if_fail (GST_IS_DPTEST (element), GST_STATE_FAILURE);
180 g_print ("changing state\n");
182 dptest = GST_DPTEST (element);
183 if (GST_ELEMENT_CLASS (parent_class)->change_state)
184 return GST_ELEMENT_CLASS (parent_class)->change_state (element);
186 return GST_STATE_SUCCESS;
190 gst_dptest_chain (GstPad * pad, GstData * data)
193 gint frame_countdown;
195 dptest = GST_DPTEST (gst_pad_get_parent (pad));
198 /* we're using a made up buffer size of 64 and a timestamp of zero */
199 frame_countdown = GST_DPMAN_PREPROCESS (dptest->dpman, 64, 0LL);
201 while (GST_DPMAN_PROCESS (dptest->dpman, frame_countdown));
203 g_print ("dp chain\n");
207 gst_dptest_register_elements (GstPlugin * plugin)
209 return gst_element_register (plugin, "dptest", GST_RANK_NONE,
213 static GstPluginDesc plugin_desc = {
218 &gst_dptest_register_elements,
227 main (int argc, char *argv[])
232 GstElement *testelement;
233 GstElement *pipeline;
234 GstDParamManager *dpman;
235 GstDParam *dp_float1;
236 GValue *dp_float1_value;
240 gst_init (&argc, &argv);
241 gst_control_init (&argc, &argv);
243 _gst_plugin_register_static (&plugin_desc);
245 pipeline = gst_element_factory_make ("pipeline", "pipeline");
248 src = gst_element_factory_make ("fakesrc", "src");
251 sink = gst_element_factory_make ("fakesink", "sink");
254 testelement = gst_element_factory_make ("dptest", "testelement");
255 g_assert (testelement);
257 gst_element_link (src, testelement);
258 gst_element_link (testelement, sink);
260 gst_bin_add (GST_BIN (pipeline), src);
261 gst_bin_add (GST_BIN (pipeline), testelement);
262 gst_bin_add (GST_BIN (pipeline), sink);
264 g_print ("playing pipeline\n");
266 g_object_set (G_OBJECT (src), "num_buffers", 1, NULL);
268 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
270 /* test that dparam manager is accessable */
271 g_print ("getting dparam manager\n");
272 dpman = gst_dpman_get_manager (testelement);
273 gst_dpman_set_mode (dpman, "synchronous");
276 g_assert (GST_IS_DPMAN (dpman));
278 g_print ("creating dparam for float1\n");
279 dp_float1 = gst_dparam_new (G_TYPE_FLOAT);;
280 g_assert (dp_float1);
281 g_assert (GST_IS_DPARAM (dp_float1));
283 g_print ("attach dparam to float1\n");
284 g_assert (gst_dpman_attach_dparam (dpman, "float1", dp_float1));
286 dp_float1_value = g_new0 (GValue, 1);
287 g_value_init (dp_float1_value, G_TYPE_FLOAT);
289 g_value_set_float (dp_float1_value, 0.1);
290 g_object_set_property (G_OBJECT (dp_float1), "value_float", dp_float1_value);
292 g_print ("iterate once\n");
293 gst_bin_iterate (GST_BIN (pipeline));
295 g_print ("check that value changed\n");
296 g_assert (GST_DPTEST (testelement)->float1 == 0.1F);
297 g_assert (!GST_DPARAM_READY_FOR_UPDATE (dp_float1));
299 g_print ("nulling pipeline\n");
300 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
302 g_print ("playing pipeline\n");
303 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
305 g_print ("iterate twice\n");
307 g_object_set (G_OBJECT (src), "num_buffers", 2, NULL);
308 gst_bin_iterate (GST_BIN (pipeline));