系统相关
首页 > 系统相关> > Linux3.5—视屏模块学习与分析

Linux3.5—视屏模块学习与分析

作者:互联网

插入USB摄像头后,我看到了识别出的一些信息,在内核源码中搜到了相关信息:

 

 

帮助文档:linux-3.5/Documentation/video4linux/v4l2-framework.txt 

这个帮助文档写的让人不是很好的能理解,查找前辈的学习资料,使用vivid.c 分析起来可以更好的让人理解。

    /linux-3.5/drivers/media/video/vivi.c

 

 

 

 

分析驱动程序最好的方法就是跟踪应用程序对他的调用过程。

 开始分析  /linux-3.5/drivers/media/video/uvc/uvc_driver.c 

  usb_register(&uvc_driver.driver);

下面查看probe函数:

/* USB探针、断开连接、挂起和恢复*/

  

  (uvc_register_chains(dev)

    

        

    

 1 static int uvc_register_video(struct uvc_device *dev,
 2                 struct uvc_streaming *stream)
 3 {
 4         struct video_device *vdev;
 5         int ret;
 6 
 7         /* Initialize the streaming interface with default streaming
 8          * parameters.
 9          */
10         ret = uvc_video_init(stream);
11         if (ret < 0) {
12                 uvc_printk(KERN_ERR, "Failed to initialize the device "
13                         "(%d).\n", ret);
14                 return ret;
15         }
16 
17         uvc_debugfs_init_stream(stream);
18 ////////////////////////////标记///////////////////////////// 19 /* Register the device with V4L. */ 20 vdev = video_device_alloc(); 21 if (vdev == NULL) { 22 uvc_printk(KERN_ERR, "Failed to allocate video device (%d).\n", 23 ret); 24 return -ENOMEM; 25 } 26 27 /* We already hold a reference to dev->udev. The video device will be 28 * unregistered before the reference is released, so we don't need to 29 * get another one. 30 */ 31 vdev->v4l2_dev = &dev->vdev;
///////////////////////标记///////////////////////////////// 32 vdev->fops = &uvc_fops; 33 34 vdev->release = uvc_release; 35 strlcpy(vdev->name, dev->name, sizeof vdev->name); 36 37 /* Set the driver data before calling video_register_device, otherwise 38 * uvc_v4l2_open might race us. 39 */ 40 stream->vdev = vdev; 41 video_set_drvdata(vdev, stream); 42
/////////////////////////////////标记///////////////////////////////////////////////// 43 ret = video_register_device(vdev, VFL_TYPE_GRABBER, -1); 44 if (ret < 0) { 45 uvc_printk(KERN_ERR, "Failed to register video device (%d).\n", 46 ret); 47 stream->vdev = NULL; 48 video_device_release(vdev); 49 return ret; 50 } 51 52 atomic_inc(&dev->nstreams); 53 return 0; 54 }

 先了解USB摄像头内部框架:uvc specification

参考: USB_Video_Example 1.5.pdf

    UVC 1.5Class specification.pdf

下载地址    https://github.com/Jason543716996/USB_class.git

 

 

 

    

 未完。。。

标签:ret,video,dev,模块,vdev,device,uvc,Linux3.5,视屏
来源: https://www.cnblogs.com/jason-linux/p/10503112.html