2 * Copyright (C) 2011 Robert Jobbagy <jobbagy.robert@gmail.com>
5 * gst_motioncells_dynamic_test(): a test tool what can to do dynamic change properties
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include <glib/gprintf.h>
29 #include <gst/interfaces/propertyprobe.h>
30 #include "gstmotioncells_dynamic_test.h"
31 #include "gst_element_print_properties.h"
33 const guint c2w = 21; // column 2 width
34 const guint c3w = 19; // column 3 width
35 const guint c4w = 23; // column 4 width
38 setProperty (GstElement * mcells, char *property, char *prop_value, GType type,
45 g_object_set (G_OBJECT (mcells), property, prop_value, NULL);
50 gboolean flag = (g_strcmp0 (prop_value, "true") == 0) ? TRUE : FALSE;
51 g_object_set (G_OBJECT (mcells), property, flag, NULL);
56 unsigned long ulongval = strtoul (prop_value, NULL, 0);
57 g_object_set (G_OBJECT (mcells), property, ulongval, NULL);
62 long longval = atol (prop_value);
63 g_object_set (G_OBJECT (mcells), property, longval, NULL);
68 unsigned int uintval = atoi (prop_value);
69 g_object_set (G_OBJECT (mcells), property, uintval, NULL);
74 int intval = atoi (prop_value);
75 g_object_set (G_OBJECT (mcells), property, intval, NULL);
80 guint64 guint64val = atoi (prop_value);
81 g_object_set (G_OBJECT (mcells), property, guint64val, NULL);
86 gint64 gint64val = atoi (prop_value);
87 g_object_set (G_OBJECT (mcells), property, gint64val, NULL);
92 float floatval = atof (prop_value);
93 g_object_set (G_OBJECT (mcells), property, floatval, NULL);
98 double doubleval = strtod (prop_value, NULL);
99 g_object_set (G_OBJECT (mcells), property, doubleval, NULL);
103 fprintf (stderr, "You gave me something wrong type of data !!! \n");
108 // gst-launch v4l2src ! videoscale ! videorate ! capsfilter "caps=video/x-raw-yuv,width=320,height=240,framerate=10/1" ! ffmpegcolorspace ! motioncells ! ffmpegcolorspace ! xvimagesink
110 main (int argc, char *argv[])
112 GstElement *pipeline, *source, *videor, *videos, *decodebin, *capsf,
113 *colorsp0, *colorsp1, *mcells, *sink;
116 gchar prop_value[100];
117 GParamSpec **property_specs;
118 guint num_properties, i;
119 GValue value = { 0, };
120 gboolean found_property = FALSE;
124 gst_init (&argc, &argv);
125 fprintf (stderr, "Usage: %s test or rtsp rtsp://your/cam/address\n", argv[0]);
126 // Create gstreamer elements //
127 pipeline = gst_pipeline_new ("moitoncells-pipeline");
128 if (argc == 2 && (g_strcmp0 (argv[1], "test") == 0))
129 source = gst_element_factory_make ("videotestsrc", "vidsrc");
130 else if (argc == 3 && (g_strcmp0 (argv[1], "rtsp") == 0))
131 source = gst_element_factory_make ("rtspsrc", "rtspsrc0");
133 source = gst_element_factory_make ("v4l2src", "v4l2");
135 fprintf (stderr, "Usage: %s test or rtsp rtsp://your/cam/address\n",
140 videor = gst_element_factory_make ("videorate", "videor");
141 videos = gst_element_factory_make ("videoscale", "videos");
142 capsf = gst_element_factory_make ("capsfilter", "capsf");
143 if (argc == 3 && (g_strcmp0 (argv[1], "rtsp") == 0))
144 decodebin = gst_element_factory_make ("decodebin", "decode");
147 colorsp0 = gst_element_factory_make ("ffmpegcolorspace", "colorspace0");
148 mcells = gst_element_factory_make ("motioncells", "mcells");
149 colorsp1 = gst_element_factory_make ("ffmpegcolorspace", "colorspace1");
150 sink = gst_element_factory_make ("xvimagesink", "xv-image-sink");
151 if (!pipeline || !source || !videor || !videos || !capsf || !colorsp0
152 || !mcells || !colorsp1 || !sink) {
153 g_printerr ("One element could not be created. Exiting.\n");
156 if (argc == 3 && (g_strcmp0 (argv[1], "rtsp") == 0) && !decodebin) {
157 g_printerr ("Decodebin could not be created. Exiting.\n");
160 if ((g_strcmp0 (argv[1], "rtsp") == 0)) {
161 g_object_set (G_OBJECT (source), "location", argv[2], NULL);
162 g_object_set (G_OBJECT (source), "latency", 1000, NULL);
163 } else if ((g_strcmp0 (argv[1], "test") == 0))
164 g_object_set (G_OBJECT (source), "pattern", 18, NULL);
168 ("video/x-raw-yuv,width=320,height=240,framerate=10/1");
169 g_object_set (G_OBJECT (capsf), "caps", caps, NULL);
170 //g_object_set (G_OBJECT (sink), "sync",FALSE,NULL);
173 if (g_strcmp0 (argv[1], "test") == 0) {
174 gst_bin_add_many (GST_BIN (pipeline),
175 source, videor, videos, capsf, colorsp0, mcells, colorsp1, sink,
178 gst_element_link_many (source, videor, videos, capsf, colorsp0, mcells,
179 colorsp1, sink, NULL);
180 } else if (g_strcmp0 (argv[1], "rtsp") == 0) {
181 gst_bin_add_many (GST_BIN (pipeline),
182 source, videor, videos, capsf, decodebin, colorsp0, mcells, colorsp1,
185 gst_element_link_many (source, videor, videos, capsf, decodebin, colorsp0,
186 mcells, colorsp1, sink, NULL);
189 gst_bin_add_many (GST_BIN (pipeline),
190 source, videor, videos, capsf, colorsp0, mcells, colorsp1, sink, NULL);
192 gst_element_link_many (source, videor, videos, capsf, colorsp0, mcells,
193 colorsp1, sink, NULL);
196 g_print ("Now playing\n");
197 gst_element_set_state (pipeline, GST_STATE_PLAYING);
198 g_print ("Running...\n");
199 g_print ("You can use these properties : \n");
200 gst_element_print_properties (mcells);
201 g_print ("change property here: example some_property property_value \n");
202 g_print ("Quit with 'q' \n");
204 property_specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (mcells),
207 found_property = FALSE;
210 ret = scanf ("%19s %99s", property, prop_value);
213 g_printerr ("Error parsing command.\n");
215 if ((g_strcmp0 (property, "q") == 0) || (g_strcmp0 (prop_value, "q") == 0))
217 printf ("property: %s -> value: %s \n", property, prop_value);
218 for (i = 0; i < num_properties; i++) {
219 GParamSpec *param = property_specs[i];
220 g_value_init (&value, param->value_type);
221 g_object_get_property (G_OBJECT (mcells), param->name, &value);
222 //fprintf(stderr,"property: %s and param name: %s and property value: %s \n",property,param->name,prop_value);
223 if ((g_strcmp0 (property, param->name) == 0) && !found_property &&
224 (g_strcmp0 (prop_value, "") != 0)
225 && (g_strcmp0 (prop_value, "\"") != 0)
226 && (g_strcmp0 (prop_value, "\'") != 0)) {
228 found_property = TRUE;
229 type = param->value_type;
230 setProperty (mcells, property, prop_value, type, &value);
232 g_value_unset (&value);
238 gst_element_set_state (pipeline, GST_STATE_NULL);
239 gst_object_unref (pipeline);