6 #include <gst/interfaces/tuner.h>
7 #include <gst/interfaces/colorbalance.h>
9 GstElement *pipeline, *source, *sink;
11 volatile int exit_read = 0;
16 printf ("\nf - to change the fequency\n");
17 printf ("i - to change the input\n");
18 printf ("n - to change the norm\n");
19 printf ("c - list color balance\n");
20 printf ("e - to exit\n");
24 run_options (char opt)
29 GstTuner *tuner = GST_TUNER (source);
30 GstTunerChannel *channel;
33 channel = gst_tuner_get_channel (tuner);
35 freq = gst_tuner_get_frequency (tuner, channel);
37 printf ("type the new frequency (current = %lu) (-1 to cancel): ", freq);
40 gst_tuner_set_frequency (tuner, channel, freq);
45 GstTuner *tuner = GST_TUNER (source);
46 const GList *item, *list;
47 const GstTunerNorm *current_norm;
48 GstTunerNorm *norm = NULL;
49 gint index, next_norm;
52 list = gst_tuner_list_norms (tuner);
54 current_norm = gst_tuner_get_norm (tuner);
56 printf ("\nlist of norms:\n");
57 for (item = list, index = 0; item != NULL; item = item->next, ++index) {
59 if (current_norm == norm) {
60 printf (" * %u - %s\n", index, norm->label);
62 printf (" %u - %s\n", index, norm->label);
65 printf ("\ntype the number of norm you want (-1 to cancel): ");
66 scanf ("%d", &next_norm);
70 if (index <= next_norm) {
71 printf ("Norm %d not available\n", next_norm);
74 for (item = list, index = 0; item != NULL && index <= next_norm;
75 item = item->next, ++index) {
79 gst_tuner_set_norm (tuner, norm);
84 GstTuner *tuner = GST_TUNER (source);
85 const GList *item, *list;
86 const GstTunerChannel *current_channel;
87 GstTunerChannel *channel = NULL;
88 gint index, next_channel;
91 list = gst_tuner_list_channels (tuner);
93 current_channel = gst_tuner_get_channel (tuner);
95 printf ("\nlist of inputs:\n");
96 for (item = list, index = 0; item != NULL; item = item->next, ++index) {
98 if (current_channel == channel) {
99 printf (" * %u - %s\n", index, channel->label);
101 printf (" %u - %s\n", index, channel->label);
104 printf ("\ntype the number of input you want (-1 to cancel): ");
105 scanf ("%d", &next_channel);
106 if (next_channel < 0) {
109 if (index <= next_channel) {
110 printf ("Input %d not available\n", next_channel);
113 for (item = list, index = 0; item != NULL && index <= next_channel;
114 item = item->next, ++index) {
115 channel = item->data;
118 gst_tuner_set_channel (tuner, channel);
122 gst_element_set_state (pipeline, GST_STATE_NULL);
123 g_main_loop_quit (loop);
129 GstColorBalance *balance = GST_COLOR_BALANCE (source);
130 const GList *controls;
131 GstColorBalanceChannel *channel;
133 gint index, new_value;
135 controls = gst_color_balance_list_channels (balance);
137 if (controls == NULL) {
138 printf ("There is no list of colorbalance controls\n");
143 printf ("\nlist of controls:\n");
144 for (item = controls, index = 0; item != NULL;
145 item = item->next, ++index) {
146 channel = item->data;
147 printf (" %u - %s (%d - %d) = %d\n", index, channel->label,
148 channel->min_value, channel->max_value,
149 gst_color_balance_get_value (balance, channel));
151 printf ("\ntype the number of color control you want (-1 to cancel): ");
152 scanf ("%d", &new_value);
155 for (item = controls, index = 0; item != NULL && index <= new_value;
156 item = item->next, ++index) {
157 channel = item->data;
159 printf (" %u - %s (%d - %d) = %d, type the new value: ", index - 1,
160 channel->label, channel->min_value, channel->max_value,
161 gst_color_balance_get_value (balance, channel));
162 scanf ("%d", &new_value);
165 gst_color_balance_set_value (balance, channel, new_value);
171 printf ("error: invalid option %c", opt);
182 read_user (gpointer data)
196 } while (opt == '\n');
207 my_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
210 switch (GST_MESSAGE_TYPE (message)) {
211 case GST_MESSAGE_ERROR:{
215 gst_message_parse_error (message, &err, &debug);
216 g_print ("%s error: %s\n",
217 gst_element_get_name (message->src), err->message);
218 g_print ("Debug: %s\n", debug);
223 printf ("presse <ENTER> key to exit\n");
225 g_main_loop_quit (loop);
227 case GST_MESSAGE_EOS:
229 printf ("presse any key to exit\n");
231 g_main_loop_quit (loop);
241 main (int argc, char *argv[])
244 GThread *input_thread;
245 gint numbuffers = -1;
246 gchar device[128] = { '\0' };
247 gchar input[128] = { '\0' };
248 gulong frequency = 0;
249 gboolean nofixedfps = TRUE;
252 /* see for input option */
257 static char long_options_desc[][64] = {
258 {"Number of buffers to output before sending EOS"},
259 {"Device location. Common in /dev/video0"},
260 {"input/output (channel) to switch to"},
261 {"frequency to tune to (in Hz)"},
262 {"set use-fixed-fps to FALSE"},
265 static struct option long_options[] = {
266 {"numbuffers", 1, 0, 'n'},
267 {"device", 1, 0, 'd'},
268 {"input", 1, 0, 'i'},
269 {"frequency", 1, 0, 'f'},
270 {"nofixedfps", 0, 0, 's'},
273 /* getopt_long stores the option index here. */
274 int option_index = 0;
276 c = getopt_long (argc, argv, "n:d:i:f:sh:", long_options, &option_index);
278 /* Detect the end of the options. */
280 printf ("tip: use -h to see help message.\n");
286 /* If this option set a flag, do nothing else now. */
287 if (long_options[option_index].flag != 0)
289 printf ("option %s", long_options[option_index].name);
291 printf (" with arg %s", optarg);
296 numbuffers = atoi (optarg);
300 strncpy (device, optarg, sizeof (device) / sizeof (device[0]));
304 strncpy (input, optarg, sizeof (input) / sizeof (input[0]));
308 frequency = atol (optarg);
316 printf ("Usage: v4l2src-test [OPTION]...\n");
317 for (c = 0; long_options[c].name; ++c) {
318 printf ("-%c, --%s\r\t\t\t\t%s\n", long_options[c].val,
319 long_options[c].name, long_options_desc[c]);
325 /* getopt_long already printed an error message. */
326 printf ("Use -h to see help message.\n");
335 /* Print any remaining command line arguments (not options). */
337 printf ("Use -h to see help message.\n" "non-option ARGV-elements: ");
338 while (optind < argc)
339 printf ("%s ", argv[optind++]);
346 gst_init (&argc, &argv);
348 /* create elements */
349 if (!(pipeline = gst_pipeline_new ("my_pipeline"))) {
350 fprintf (stderr, "error: gst_pipeline_new return NULL");
354 if (!(source = gst_element_factory_make ("v4l2src", NULL))) {
356 "error: gst_element_factory_make (\"v4l2src\", NULL) return NULL");
360 if (!(sink = gst_element_factory_make ("xvimagesink", NULL))) {
362 "error: gst_element_factory_make (\"xvimagesink\", NULL) return NULL");
366 if (numbuffers > -1) {
367 g_object_set (source, "num-buffers", numbuffers, NULL);
370 g_object_set (source, "device", device, NULL);
373 g_object_set (source, "input", input, NULL);
376 g_object_set (source, "frequency", frequency, NULL);
379 g_object_set (source, "use-fixed-fps", nofixedfps, NULL);
382 /* you would normally check that the elements were created properly */
383 gst_bus_add_watch (gst_pipeline_get_bus (GST_PIPELINE (pipeline)),
384 my_bus_callback, NULL);
386 /* put together a pipeline */
387 gst_bin_add_many (GST_BIN (pipeline), source, sink, NULL);
388 gst_element_link_pads (source, "src", sink, "sink");
390 /* start the pipeline */
391 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
392 loop = g_main_loop_new (NULL, FALSE);
394 if (!(input_thread = g_thread_create (read_user, source, TRUE, NULL))) {
395 fprintf (stderr, "error: g_thread_create return NULL");
399 g_main_loop_run (loop);
400 g_thread_join (input_thread);
402 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
404 gst_object_unref (pipeline);