ext/raw1394/: Implement GstPropertyProbe interface and add "device-name" property...
[platform/upstream/gst-plugins-good.git] / ext / raw1394 / gst1394probe.c
1 /* GStreamer
2  * Copyright (C) 2007 Julien Puydt <jpuydt@free.fr>
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 <libavc1394/avc1394.h>
21 #include <libavc1394/avc1394_vcr.h>
22 #include <libavc1394/rom1394.h>
23 #include <libraw1394/raw1394.h>
24
25 #include <gst/gst.h>
26
27 #include "gst1394probe.h"
28 #include "gst/interfaces/propertyprobe.h"
29
30 static GValueArray *
31 gst_1394_get_guid_array (void)
32 {
33   GValueArray *result = NULL;
34   raw1394handle_t handle = NULL;
35   int num_ports = 0;
36   int port = 0;
37   int num_nodes = 0;
38   int node = 0;
39   rom1394_directory directory;
40   GValue value = { 0, };
41
42   handle = raw1394_new_handle ();
43
44   if (handle == NULL)
45     return NULL;
46
47   num_ports = raw1394_get_port_info (handle, NULL, 0);
48   for (port = 0; port < num_ports; port++) {
49     if (raw1394_set_port (handle, port) >= 0) {
50       num_nodes = raw1394_get_nodecount (handle);
51       for (node = 0; node < num_nodes; node++) {
52         rom1394_get_directory (handle, node, &directory);
53         if (rom1394_get_node_type (&directory) == ROM1394_NODE_TYPE_AVC &&
54             avc1394_check_subunit_type (handle, node,
55                 AVC1394_SUBUNIT_TYPE_VCR)) {
56           if (result == NULL)
57             result = g_value_array_new (3);     /* looks like a sensible default */
58           g_value_init (&value, G_TYPE_UINT64);
59           g_value_set_uint64 (&value, rom1394_get_guid (handle, node));
60           g_value_array_append (result, &value);
61           g_value_unset (&value);
62         }
63       }
64     }
65   }
66
67   return result;
68 }
69
70 static const GList *
71 gst_1394_property_probe_get_properties (GstPropertyProbe * probe)
72 {
73   static GList *result = NULL;
74   GObjectClass *klass = NULL;
75   GParamSpec *spec = NULL;
76
77   if (result == NULL) {
78     klass = G_OBJECT_GET_CLASS (probe);
79     spec = g_object_class_find_property (klass, "guid");
80     result = g_list_append (result, spec);
81   }
82
83   return result;
84 }
85
86 static void
87 gst_1394_property_probe_probe_property (GstPropertyProbe * probe, guint prop_id,
88     const GParamSpec * pspec)
89 {
90   if (!g_str_equal (pspec->name, "guid"))
91     G_OBJECT_WARN_INVALID_PROPERTY_ID (probe, prop_id, pspec);
92 }
93
94 static gboolean
95 gst_1394_property_probe_needs_probe (GstPropertyProbe * probe, guint prop_id,
96     const GParamSpec * pspec)
97 {
98   return TRUE;
99 }
100
101 static GValueArray *
102 gst_1394_property_probe_get_values (GstPropertyProbe * probe, guint prop_id,
103     const GParamSpec * pspec)
104 {
105   GValueArray *result = NULL;
106
107   if (!g_str_equal (pspec->name, "guid")) {
108     G_OBJECT_WARN_INVALID_PROPERTY_ID (probe, prop_id, pspec);
109     return NULL;
110   }
111
112   result = gst_1394_get_guid_array ();
113
114   if (result == NULL)
115     GST_LOG_OBJECT (probe, "No guid found");
116
117   return result;
118 }
119
120 static void
121 gst_1394_property_probe_interface_init (GstPropertyProbeInterface * iface)
122 {
123   iface->get_properties = gst_1394_property_probe_get_properties;
124   iface->probe_property = gst_1394_property_probe_probe_property;
125   iface->needs_probe = gst_1394_property_probe_needs_probe;
126   iface->get_values = gst_1394_property_probe_get_values;
127 }
128
129 void
130 gst_1394_type_add_property_probe_interface (GType type)
131 {
132   static const GInterfaceInfo probe_iface_info = {
133     (GInterfaceInitFunc) gst_1394_property_probe_interface_init,
134     NULL,
135     NULL,
136   };
137
138   g_type_add_interface_static (type, GST_TYPE_PROPERTY_PROBE,
139       &probe_iface_info);
140 }