本文主要是介绍UVC 设备有哪些描述符,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
一般的USB设备有设备描述符、配置描述符、接口描述符、端点描述符四种描述符。特定的USB设备还有它自己独特的描述符
典型的UVC设备的描述符结构:
以Melis摄像头方案为例,它的描述符在代码中的组织如下图所示:
UVC设备中的概念,以及概念之间的关联:
插入UVC设备,通过/dev/media0节点枚举UVC设备实体:
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/mman.h>
#include <sys/ioctl.h>
#include <linux/videodev2.h>
#include <linux/media.h>int main(void)
{int media_fd;int ret;struct media_device_info media_info;media_fd = open("/dev/media0", O_RDWR);if(media_fd < 0){printf("%s line %d, open media device failure.fd = %d.\n", __func__, __LINE__, media_fd);return -1;}ret = ioctl(media_fd, MEDIA_IOC_DEVICE_INFO, &media_info);if(ret < 0){printf("%s line %d, get media device info failure.\n", __func__, __LINE__);return -1;}printf("=======================================================================\n");printf("Media Device info:\n");printf(" driver:%s.\n", media_info.driver);printf(" model :%s.\n", media_info.model);printf(" serial:%s.\n", media_info.serial);printf(" businf:%s.\n", media_info.bus_info);printf(" media_version 0x%x, hw_revision 0x%x, driver_version 0x%x.\n", media_info.media_version, media_info.hw_revision,media_info.driver_version);printf("=======================================================================\n");unsigned int id;struct media_entity_desc media_desc;int path = 0;for(id = 0; ; id = media_desc.id){media_desc.id = id | MEDIA_ENT_ID_FLAG_NEXT;ret = ioctl(media_fd, MEDIA_IOC_ENUM_ENTITIES, &media_desc);if(ret < 0){printf("%s line %d, return failure.\n", __func__, __LINE__);return -1;}printf("media_entity_desc entity %d:id[0x%x],name[%s],type[0x%x],flags[%d],pads[%d],links[%d],major/minor[%d/%d]\n", path ++, media_desc.id, media_desc.name, media_desc.type,\media_desc.flags, media_desc.pads,media_desc.links,media_desc.v4l.major,media_desc.v4l.minor);int type = media_desc.type & MEDIA_ENT_TYPE_MASK;if(type != MEDIA_ENT_T_DEVNODE && MEDIA_ENT_T_V4L2_SUBDEV){printf("%s line %d, bypass this device.\n", __func__, __LINE__);continue;}char sysname[32];char target[1024];memset(sysname, 0x00, 32);memset(target, 0x00, 1024);sprintf(sysname, "/sys/dev/char/%u:%u", media_desc.v4l.major, media_desc.v4l.minor);ret = readlink(sysname, target, sizeof(target));if(ret < 0){printf("%s line %d, readlink failure.\n", __func__, __LINE__);return -1;}printf("sysname:%s, target %s.\n", sysname, target);}return 0;
}
运行结果:
czl@czl-RedmiBook-14:~/Workspace/camera$ gcc main.c
czl@czl-RedmiBook-14:~/Workspace/camera$ sudo ./a.out
=======================================================================
Media Device info:driver:uvcvideo.model :Integrated Camera: Integrated C.serial:.businf:usb-0000:00:14.0-2.media_version 0x50477, hw_revision 0x1012, driver_version 0x50477.
=======================================================================
media_entity_desc entity 0:id[0x1],name[Integrated Camera: Integrated C],type[0x10001],flags[1],pads[1],links[0],major/minor[81/0]
sysname:/sys/dev/char/81:0, target ../../devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/video4linux/video0.
media_entity_desc entity 1:id[0x4],name[Integrated Camera: Integrated C],type[0x10001],flags[0],pads[0],links[0],major/minor[81/1]
sysname:/sys/dev/char/81:1, target ../../devices/pci0000:00/0000:00:14.0/usb1/1-2/1-2:1.0/video4linux/video1.
media_entity_desc entity 2:id[0x8],name[Extension 4],type[0x20000],flags[0],pads[2],links[1],major/minor[0/0]
main line 65, bypass this device.
media_entity_desc entity 3:id[0xb],name[Extension 3],type[0x20000],flags[0],pads[2],links[1],major/minor[0/0]
main line 65, bypass this device.
media_entity_desc entity 4:id[0xe],name[Processing 2],type[0x20000],flags[0],pads[2],links[1],major/minor[0/0]
main line 65, bypass this device.
media_entity_desc entity 5:id[0x11],name[Camera 1],type[0x20001],flags[0],pads[1],links[1],major/minor[0/0]
main line 65, bypass this device.
main line 55, return failure.
czl@czl-RedmiBook-14:~/Workspace/camera$
结束!
这篇关于UVC 设备有哪些描述符的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!