1 /*
2 * GStreamer
3 *
4 * Copyright (C) 2012 Cisco Systems, Inc.
5 * Author: Youness Alaoui <youness.alaoui@collabora.co.uk>
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
24 #ifdef HAVE_CONFIG_H
25 # include <config.h>
26 #endif
27
28 #include "uvc_h264.h"
29
30 GType
uvc_h264_slicemode_get_type(void)31 uvc_h264_slicemode_get_type (void)
32 {
33 static GType type = 0;
34
35 static const GEnumValue types[] = {
36 {UVC_H264_SLICEMODE_IGNORED, "Ignored", "ignored"},
37 {UVC_H264_SLICEMODE_BITSPERSLICE, "Bits per slice", "bits/slice"},
38 {UVC_H264_SLICEMODE_MBSPERSLICE, "MBs per Slice", "MBs/slice"},
39 {UVC_H264_SLICEMODE_SLICEPERFRAME, "Slice Per Frame", "slice/frame"},
40 {0, NULL, NULL}
41 };
42
43 if (!type) {
44 type = g_enum_register_static ("UvcH264SliceMode", types);
45 }
46 return type;
47 }
48
49 GType
uvc_h264_usagetype_get_type(void)50 uvc_h264_usagetype_get_type (void)
51 {
52 static GType type = 0;
53
54 static const GEnumValue types[] = {
55 {UVC_H264_USAGETYPE_REALTIME, "Realtime (video conferencing)", "realtime"},
56 {UVC_H264_USAGETYPE_BROADCAST, "Broadcast", "broadcast"},
57 {UVC_H264_USAGETYPE_STORAGE, "Storage", "storage"},
58 {UVC_H264_USAGETYPE_UCCONFIG_0, "UCConfig 0", "ucconfig0"},
59 {UVC_H264_USAGETYPE_UCCONFIG_1, "UCConfig 1", "ucconfig1"},
60 {UVC_H264_USAGETYPE_UCCONFIG_2Q, "UCConfig 2Q", "ucconfig2q"},
61 {UVC_H264_USAGETYPE_UCCONFIG_2S, "UCConfig 2S", "ucconfig2s"},
62 {UVC_H264_USAGETYPE_UCCONFIG_3, "UCConfig 3", "ucconfig3"},
63 {0, NULL, NULL}
64 };
65
66 if (!type) {
67 type = g_enum_register_static ("UvcH264UsageType", types);
68 }
69 return type;
70 }
71
72 GType
uvc_h264_ratecontrol_get_type(void)73 uvc_h264_ratecontrol_get_type (void)
74 {
75 static GType type = 0;
76
77 static const GEnumValue types[] = {
78 {UVC_H264_RATECONTROL_CBR, "Constant bit rate", "cbr"},
79 {UVC_H264_RATECONTROL_VBR, "Variable bit rate", "vbr"},
80 {UVC_H264_RATECONTROL_CONST_QP, "Constant QP", "qp"},
81 {0, NULL, NULL}
82 };
83
84 if (!type) {
85 type = g_enum_register_static ("UvcH264RateControl", types);
86 }
87 return type;
88 }
89
90 GType
uvc_h264_streamformat_get_type(void)91 uvc_h264_streamformat_get_type (void)
92 {
93 static GType type = 0;
94
95 static const GEnumValue types[] = {
96 {UVC_H264_STREAMFORMAT_ANNEXB, "Byte stream format (Annex B)", "byte"},
97 {UVC_H264_STREAMFORMAT_NAL, "NAL stream format", "nal"},
98 {0, NULL, NULL}
99 };
100
101 if (!type) {
102 type = g_enum_register_static ("UvcH264StreamFormat", types);
103 }
104 return type;
105 }
106
107 GType
uvc_h264_entropy_get_type(void)108 uvc_h264_entropy_get_type (void)
109 {
110 static GType type = 0;
111
112 static const GEnumValue types[] = {
113 {UVC_H264_ENTROPY_CAVLC, "CAVLC", "cavlc"},
114 {UVC_H264_ENTROPY_CABAC, "CABAC", "cabac"},
115 {0, NULL, NULL}
116 };
117
118 if (!type) {
119 type = g_enum_register_static ("UvcH264Entropy", types);
120 }
121 return type;
122 }
123
124 guint8
xu_get_id(GstObject * self,const gchar * devicename,libusb_context ** usb_ctx)125 xu_get_id (GstObject * self, const gchar * devicename,
126 libusb_context ** usb_ctx)
127 {
128 static const __u8 guid[16] = GUID_UVCX_H264_XU;
129 GUdevClient *client;
130 GUdevDevice *udevice;
131 GUdevDevice *parent;
132 guint64 busnum;
133 guint64 devnum;
134 libusb_device **device_list = NULL;
135 libusb_device *device = NULL;
136 ssize_t cnt;
137 int i, j, k;
138
139
140 if (*usb_ctx == NULL)
141 libusb_init (usb_ctx);
142
143 client = g_udev_client_new (NULL);
144 if (client) {
145 udevice = g_udev_client_query_by_device_file (client, devicename);
146 if (udevice) {
147 parent = g_udev_device_get_parent_with_subsystem (udevice, "usb",
148 "usb_device");
149 if (parent) {
150 busnum = g_udev_device_get_sysfs_attr_as_uint64 (parent, "busnum");
151 devnum = g_udev_device_get_sysfs_attr_as_uint64 (parent, "devnum");
152
153 cnt = libusb_get_device_list (*usb_ctx, &device_list);
154 for (i = 0; i < cnt; i++) {
155 if (busnum == libusb_get_bus_number (device_list[i]) &&
156 devnum == libusb_get_device_address (device_list[i])) {
157 device = libusb_ref_device (device_list[i]);
158 break;
159 }
160 }
161 libusb_free_device_list (device_list, 1);
162 g_object_unref (parent);
163 }
164 g_object_unref (udevice);
165 }
166 g_object_unref (client);
167 }
168
169 if (device) {
170 struct libusb_device_descriptor desc;
171
172 if (libusb_get_device_descriptor (device, &desc) == 0) {
173 for (i = 0; i < desc.bNumConfigurations; ++i) {
174 struct libusb_config_descriptor *config = NULL;
175
176 if (libusb_get_config_descriptor (device, i, &config) == 0) {
177 for (j = 0; j < config->bNumInterfaces; j++) {
178 for (k = 0; k < config->interface[j].num_altsetting; k++) {
179 const struct libusb_interface_descriptor *interface;
180 const guint8 *ptr = NULL;
181
182 interface = &config->interface[j].altsetting[k];
183 if (interface->bInterfaceClass != LIBUSB_CLASS_VIDEO ||
184 interface->bInterfaceSubClass != USB_VIDEO_CONTROL)
185 continue;
186 ptr = interface->extra;
187 while (ptr - interface->extra +
188 sizeof (xu_descriptor) < interface->extra_length) {
189 xu_descriptor *desc = (xu_descriptor *) ptr;
190
191 GST_DEBUG_OBJECT (self, "Found VideoControl interface with "
192 "unit id %d : %" GUID_FORMAT, desc->bUnitID,
193 GUID_ARGS (desc->guidExtensionCode));
194 if (desc->bDescriptorType == USB_VIDEO_CONTROL_INTERFACE &&
195 desc->bDescriptorSubType == USB_VIDEO_CONTROL_XU_TYPE &&
196 memcmp (desc->guidExtensionCode, guid, 16) == 0) {
197 guint8 unit_id = desc->bUnitID;
198
199 GST_DEBUG_OBJECT (self, "Found H264 XU unit : %d", unit_id);
200
201 libusb_free_config_descriptor (config);
202 libusb_unref_device (device);
203 return unit_id;
204 }
205 ptr += desc->bLength;
206 }
207 }
208 }
209 libusb_free_config_descriptor (config);
210 }
211 }
212 }
213 libusb_unref_device (device);
214 }
215
216 return 0;
217 }
218