1 /* GStreamer
2 * Copyright (C) 2011 Robert Jobbagy <jobbagy.robert@gmail.com>
3 * Copyright (C) 2014 Tim-Philipp Müller <tim centricular com>
4 *
5 * motioncells_dynamic_test: test to show effect of property changes at runtime
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library; if not, write to the
19 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20 * Boston, MA 02110-1301, USA.
21 *
22 */
23 #include <gst/gst.h>
24 #include <string.h>
25 #include <stdlib.h>
26 #include <stdio.h>
27
28 static void
print_element_properties(GstElement * element)29 print_element_properties (GstElement * element)
30 {
31 GParamSpec **pspecs, *pspec;
32 guint num, i;
33
34 g_print ("\tProperty : value (type)\n");
35
36 pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (element), &num);
37 for (i = 0; i < num; ++i) {
38 GValue val = G_VALUE_INIT;
39 const gchar *type_name;
40 gchar *s;
41
42 pspec = pspecs[i];
43
44 /* only care about properties we can read and write */
45 if ((pspec->flags & G_PARAM_READWRITE) != G_PARAM_READWRITE)
46 continue;
47 /* and which can be changed after construction */
48 if ((pspec->flags & G_PARAM_CONSTRUCT_ONLY))
49 continue;
50 /* ignore some GstObject properties which are not interesting */
51 if (!strcmp (pspec->name, "name") || !strcmp (pspec->name, "parent"))
52 continue;
53 /* ignore properties we can't change in a meaningful way */
54 if (G_IS_PARAM_SPEC_BOXED (pspec) || G_IS_PARAM_SPEC_OBJECT (pspec)
55 || G_IS_PARAM_SPEC_POINTER (pspec))
56 continue;
57
58 g_value_init (&val, G_PARAM_SPEC_VALUE_TYPE (pspec));
59 g_object_get_property (G_OBJECT (element), pspec->name, &val);
60 s = gst_value_serialize (&val);
61
62 if (G_PARAM_SPEC_VALUE_TYPE (pspec) == G_TYPE_STRING) {
63 type_name = "string";
64 g_free (s);
65 g_object_get (G_OBJECT (element), pspec->name, &s, NULL);
66 if (s == NULL)
67 s = g_strdup ("(null)");
68 } else {
69 type_name = g_type_name (G_PARAM_SPEC_VALUE_TYPE (pspec));
70 }
71
72 g_print ("\t%s: %s (%s)\n", pspec->name, s, type_name);
73 g_free (s);
74 g_value_unset (&val);
75 }
76
77 g_free (pspecs);
78 }
79
80 int
main(int argc,char * argv[])81 main (int argc, char *argv[])
82 {
83 GstElement *pipeline, *source, *videor, *capsf;
84 GstElement *colorsp0, *colorsp1, *mcells, *sink;
85 GstCaps *caps;
86
87 gst_init (&argc, &argv);
88
89 pipeline = gst_pipeline_new ("motioncells-pipeline");
90 if (argc == 2 && strcmp (argv[1], "test") == 0) {
91 source = gst_element_factory_make ("videotestsrc", NULL);
92 gst_util_set_object_arg (G_OBJECT (source), "pattern", "ball");
93 } else if (argc == 1 || strncmp (argv[1], "v4l", 3) == 0) {
94 source = gst_element_factory_make ("v4l2src", NULL);
95 } else {
96 g_printerr ("Usage: %s [v4l2|test]\n", argv[0]);
97 exit (-1);
98 }
99
100 videor = gst_element_factory_make ("videorate", NULL);
101 capsf = gst_element_factory_make ("capsfilter", NULL);
102 colorsp0 = gst_element_factory_make ("videoconvert", NULL);
103 mcells = gst_element_factory_make ("motioncells", NULL);
104 colorsp1 = gst_element_factory_make ("videoconvert", NULL);
105 sink = gst_element_factory_make ("autovideosink", "videosink");
106 if (!pipeline || !source || !videor || !capsf || !colorsp0
107 || !mcells || !colorsp1 || !sink) {
108 g_printerr ("One element could not be created. Exiting.\n");
109 return -1;
110 }
111
112 caps = gst_caps_from_string ("video/x-raw,framerate=10/1");
113 g_object_set (G_OBJECT (capsf), "caps", caps, NULL);
114
115 gst_bin_add_many (GST_BIN (pipeline), source, videor, capsf, colorsp0, mcells,
116 colorsp1, sink, NULL);
117
118 gst_element_link_many (source, videor, capsf, colorsp0, mcells, colorsp1,
119 sink, NULL);
120
121 g_print ("Going to playing..\n");
122 gst_element_set_state (pipeline, GST_STATE_PLAYING);
123
124 g_print ("You can use these properties: \n\n");
125
126 print_element_properties (mcells);
127
128 g_print ("\nSee 'gst-inspect-1.0 motioncells' for all the details.\n");
129 g_print ("Change properties like this: propertyname=value\n");
130 g_print ("Quit with 'q'\n");
131
132 /* Read command line input */
133 while (TRUE) {
134 gchar *prop_name, *prop_value;
135 gchar input_buf[1024];
136
137 memset (input_buf, 0, sizeof (input_buf));
138 if (fgets (input_buf, sizeof (input_buf), stdin) == NULL)
139 break;
140
141 /* strip off trailing newline */
142 g_strdelimit (input_buf, "\n", '\0');
143
144 if (strcmp (input_buf, "q") == 0 || strcmp (input_buf, "quit") == 0)
145 break;
146
147 prop_value = strchr (input_buf, '=');
148 if (prop_value == NULL) {
149 g_printerr ("Please enter either 'property=value' or 'quit'.\n");
150 continue;
151 }
152 *prop_value++ = '\0';
153 prop_name = input_buf;
154
155 gst_util_set_object_arg (G_OBJECT (mcells), prop_name, prop_value);
156 }
157
158 gst_element_set_state (pipeline, GST_STATE_NULL);
159 gst_object_unref (pipeline);
160 return 0;
161 }
162