LINUX&UVC输出终端描述符分析
2024-03-19
86
1
UVC输出终端描述符用于描述UVC视频流的输出端。
关于UVC输出终端描述符各字段的分析详见:https://www.usbzh.com/article/detail-10.html
UVC输出终端描述符比较简单,没有什么特别的字段。惟一要关注的就是bSourceID。
bSourceID:此终端所连接的设备或终端的ID。一个UVC输出端惟有惟一的源ID。使用这些ID功能,可以建立起UVC设备的拓扑结构。
case UVC_VC_OUTPUT_TERMINAL:
if (buflen < 9) {
uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
"interface %d OUTPUT_TERMINAL error\n",
udev->devnum, alts->desc.bInterfaceNumber);
return -EINVAL;
}
/* Make sure the terminal type MSB is not null, otherwise it
* could be confused with a unit.
*/
type = get_unaligned_le16(&buffer[4]);
if ((type & 0xff00) == 0) {
uvc_trace(UVC_TRACE_DESCR, "device %d videocontrol "
"interface %d OUTPUT_TERMINAL %d has invalid "
"type 0x%04x, skipping\n", udev->devnum,
alts->desc.bInterfaceNumber, buffer[3], type);
return 0;
}
term = uvc_alloc_entity(type | UVC_TERM_OUTPUT, buffer[3],1, 0);
if (term == NULL)
return -ENOMEM;
memcpy(term->baSourceID, &buffer[7], 1);
if (buffer[8] != 0)
usb_string(udev, buffer[8], term->name,
sizeof(term->name));
else
sprintf(term->name, "Output %u", buffer[3]);
list_add_tail(&term->list, &dev->entities);
break;
这里需要关注的是uvc_alloc_entity函数,该函数原型
static struct uvc_entity *uvc_alloc_entity(u16 type, u8 id,
unsigned int num_pads, unsigned int extra_size)
num_pads指定了额外的内存空间,在UVC输出端描述符中为1,其关联uvc_entity结构体baSourceID的内存空间。
故会有:
memcpy(term->baSourceID, &buffer[7], 1);
通过分析uvc_alloc_entity函数会知,uvc_entity结构体baSourceID的内存空间其实是成员pads的内存空间。