Added gst-plugins-base-subtitles0.10-0.10.34 for Meego Harmattan 1.2
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / tests / examples / v4l / probe.c
1 /* GStreamer
2  * Copyright (C) 2009 Filippo Argiolas <filippo.argiolas@gmail.com>
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Library General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Library General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include <stdlib.h>
21 #include <gst/gst.h>
22 #include <gst/interfaces/propertyprobe.h>
23
24 int
25 main (int argc, char *argv[])
26 {
27   GstElement *src, *sink;
28   GstElement *bin;
29   GstPropertyProbe *probe = NULL;
30   const GParamSpec *pspec = NULL;
31   GValueArray *array = NULL;
32   gint i, ret;
33   GValue *value;
34   const gchar *device;
35   gchar *name;
36   guint flags;
37
38   gst_init (&argc, &argv);
39
40   bin = gst_pipeline_new ("pipeline");
41   g_assert (bin);
42
43   src = gst_element_factory_make ("v4lsrc", "v4l_source");
44   g_assert (src);
45   sink = gst_element_factory_make ("fakesink", "fake_sink");
46   g_assert (sink);
47
48   /* add objects to the main pipeline */
49   gst_bin_add_many (GST_BIN (bin), src, sink, NULL);
50   /* link the elements */
51   gst_element_link_many (src, sink, NULL);
52
53   /* probe devices */
54   g_print ("Probing devices with propertyprobe...\n");
55   probe = GST_PROPERTY_PROBE (src);
56   pspec = gst_property_probe_get_property (probe, "device");
57   array = gst_property_probe_probe_and_get_values (probe, pspec);
58
59   if (!array) {
60     g_print ("No device found\n");
61     exit (1);
62   }
63
64   for (i = 0; i < array->n_values; i++) {
65     value = g_value_array_get_nth (array, i);
66     device = g_value_get_string (value);
67     g_print ("Device: %s\n", device);
68     g_object_set_property (G_OBJECT (src), "device", value);
69     gst_element_set_state (bin, GST_STATE_READY);
70     ret = gst_element_get_state (bin, NULL, NULL, 10 * GST_SECOND);
71     if (ret != GST_STATE_CHANGE_SUCCESS) {
72       g_print ("Couldn't set STATE_READY\n");
73       continue;
74     }
75     g_object_get (G_OBJECT (src), "device-name", &name, NULL);
76     g_print ("Name: %s\n", name);
77     g_free (name);
78     g_object_get (G_OBJECT (src), "flags", &flags, NULL);
79     g_print ("Flags: 0x%08X\n", flags);
80     gst_element_set_state (bin, GST_STATE_NULL);
81     g_print ("\n");
82   }
83
84   exit (0);
85 }