3 #include <gst/interfaces/tuner.h>
4 #include <gst/interfaces/colorbalance.h>
6 GstElement *pipeline, *source, *sink;
8 volatile int exit_read = 0;
14 ("\nLaunch \"./v4l2src-test.c devname\" to choose the device (default: /dev/video0)\n");
15 printf ("\nf - to change the fequency\n");
16 printf ("i - to change the input\n");
17 printf ("c - list color balance\n");
18 printf ("e - to exit\n");
22 run_options (char opt)
27 GstTuner *tuner = GST_TUNER (source);
28 GstTunerChannel *channel = gst_tuner_get_channel (tuner);
31 printf ("type the new frequency (current = %lu) (-1 to cancel): ",
32 gst_tuner_get_frequency (tuner, channel));
35 gst_tuner_set_frequency (tuner, channel, freq);
40 GstTuner *tuner = GST_TUNER (source);
41 const GList *item, *list;
42 const GstTunerChannel *current_channel;
43 GstTunerChannel *channel = NULL;
44 gint index, next_channel;
46 list = gst_tuner_list_channels (tuner);
47 current_channel = gst_tuner_get_channel (tuner);
49 printf ("\nlist of inputs:\n");
50 for (item = list, index = 0; item != NULL; item = item->next, ++index) {
52 if (current_channel == channel) {
53 printf (" * %u - %s\n", index, channel->label);
55 printf (" %u - %s\n", index, channel->label);
58 printf ("\ntype the number of input you want (-1 to cancel): ");
59 scanf ("%d", &next_channel);
60 if (next_channel < 0 || index <= next_channel) {
63 for (item = list, index = 0; item != NULL && index <= next_channel;
64 item = item->next, ++index) {
68 gst_tuner_set_channel (tuner, channel);
72 gst_element_set_state (pipeline, GST_STATE_NULL);
73 g_main_loop_quit (loop);
79 GstColorBalance *balance = GST_COLOR_BALANCE (source);
80 const GList *controls = gst_color_balance_list_channels (balance);
81 GstColorBalanceChannel *channel;
83 gint index, new_value;
86 printf ("\nlist of controls:\n");
87 for (item = controls, index = 0; item != NULL;
88 item = item->next, ++index) {
90 printf (" %u - %s (%d - %d) = %d\n", index, channel->label,
91 channel->min_value, channel->max_value,
92 gst_color_balance_get_value (balance, channel));
94 printf ("\ntype the number of color control you want (-1 to cancel): ");
95 scanf ("%d", &new_value);
98 for (item = controls, index = 0; item != NULL && index <= new_value;
99 item = item->next, ++index) {
100 channel = item->data;
102 printf (" %u - %s (%d - %d) = %d, type the new value: ", index,
103 channel->label, channel->min_value, channel->max_value,
104 gst_color_balance_get_value (balance, channel));
105 scanf ("%d", &new_value);
108 gst_color_balance_set_value (balance, channel, new_value);
114 printf ("error: invalid option %c", opt);
121 read_user (gpointer data)
144 my_bus_callback (GstBus * bus, GstMessage * message, gpointer data)
147 switch (GST_MESSAGE_TYPE (message)) {
148 case GST_MESSAGE_ERROR:{
152 gst_message_parse_error (message, &err, &debug);
153 g_print ("Error: %s - element %s\n", err->message,
154 gst_element_get_name (message->src));
158 printf ("presse any key to exit\n");
160 g_main_loop_quit (loop);
162 case GST_MESSAGE_EOS:
164 printf ("presse any key to exit\n");
166 g_main_loop_quit (loop);
176 main (int argc, char *argv[])
179 GThread *input_thread;
182 gst_init (&argc, &argv);
184 /* create elements */
185 if (!(pipeline = gst_pipeline_new ("my_pipeline"))) {
186 fprintf (stderr, "error: gst_pipeline_new return NULL");
190 if (!(source = gst_element_factory_make ("v4l2src", NULL))) {
192 "error: gst_element_factory_make (\"v4l2src\", NULL) return NULL");
196 if (!(sink = gst_element_factory_make ("xvimagesink", NULL))) {
198 "error: gst_element_factory_make (\"xvimagesink\", NULL) return NULL");
203 g_object_set (source, "device", "/dev/video0", NULL);
205 g_object_set (source, "device", argv[1], NULL);
208 /* you would normally check that the elements were created properly */
209 gst_bus_add_watch (gst_pipeline_get_bus (GST_PIPELINE (pipeline)),
210 my_bus_callback, NULL);
212 /* put together a pipeline */
213 gst_bin_add_many (GST_BIN (pipeline), source, sink, NULL);
214 gst_element_link_pads (source, "src", sink, "sink");
216 /* start the pipeline */
217 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_PLAYING);
218 loop = g_main_loop_new (NULL, FALSE);
220 if (!(input_thread = g_thread_create (read_user, source, TRUE, NULL))) {
221 fprintf (stderr, "error: g_thread_create return NULL");
227 ("\nOpening /dev/video0. Launch ./v4l2src-test.c devname to try another one\n");
230 g_main_loop_run (loop);
231 g_thread_join (input_thread);
233 gst_element_set_state (GST_ELEMENT (pipeline), GST_STATE_NULL);
235 gst_object_unref (pipeline);