v4l2 review



设备实例(v4l2_device)

           |______子设备实例(v4l2_subdev)

           |______视频设备节点(video_device)

           |______文件访问控制(v4l2_fh)

           |______视频缓冲的处理(videobuf/videobuf2)



 56     device instances (v4l2_device  struct)
 57       |
 58       +-sub-device instances (v4l2_subdev struct)
 59       |
 60       \-V4L2 device nodes (video_device struct stores V4L2 device node data)
 61       |
 62       \-filehandle instances (in the future a v4l2_fh struct will keep track of filehandle instances)


drivers/media/media-device.c
281 /**
282  * media_device_register - register a media device
283  * @mdev:   The media device
284  *
285  * The caller is responsible for initializing the media device before
286  * registration. The following fields must be set:
287  *  
288  * - dev must point to the parent device
289  * - model must be filled with the device model name
290  */     
291 int __must_check media_device_register(struct media_device *mdev)
292 {   
293     int ret;
294     
295     if (WARN_ON(mdev->dev == NULL || mdev->model[0] == 0))
296         return -EINVAL;
297         
298     mdev->entity_id = 1;
299     INIT_LIST_HEAD(&mdev->entities);
300     spin_lock_init(&mdev->lock);
301     mutex_init(&mdev->graph_mutex);
302                              
303     /* Register the device node. */
304     mdev->devnode.fops = &media_device_fops;
305     mdev->devnode.parent = mdev->dev;
306     mdev->devnode.release = media_device_release;
307     ret = media_devnode_register(&mdev->devnode);
308     if (ret < 0)
309         return ret;
310     
311     ret = device_create_file(&mdev->devnode.dev, &dev_attr_model);
312     if (ret < 0) {
313         media_devnode_unregister(&mdev->devnode);
314         return ret;
315     }
316     
317     return 0;
318 }



include/media/v4l2-dev.h
142 /* Register video devices. Note that if video_register_device fails,
143    the release() callback of the video_device structure is *not* called, so
144    the caller is responsible for freeing any data. Usually that means that
145    you call video_device_release() on failure. */
146 static inline int __must_check video_register_device(struct video_device *vdev,
147         int type, int nr) 
148 {   
149     return __video_register_device(vdev, type, nr, 1, vdev->fops->owner);
150 } 


drivers/media/video/v4l2-device.c
 33 int v4l2_device_register(struct device *dev, struct v4l2_device *v4l2_dev)
 34 {   
 35     if (v4l2_dev == NULL)
 36         return -EINVAL;
 37     
 38     INIT_LIST_HEAD(&v4l2_dev->subdevs);
 39     spin_lock_init(&v4l2_dev->lock);
 40     mutex_init(&v4l2_dev->ioctl_lock);
 41     v4l2_prio_init(&v4l2_dev->prio);
 42     kref_init(&v4l2_dev->ref);
 43     get_device(dev);
 44     v4l2_dev->dev = dev;
 45     if (dev == NULL) {
 46         /* If dev == NULL, then name must be filled in by the caller */
 47         WARN_ON(!v4l2_dev->name[0]);
 48         return 0;
 49     }
 50     
 51     /* Set name to driver name + device name if it is empty. */
 52     if (!v4l2_dev->name[0])
 53         snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), "%s %s",
 54             dev->driver->name, dev_name(dev));
 55     if (!dev_get_drvdata(dev))
 56         dev_set_drvdata(dev, v4l2_dev);
 57     return 0;
 58 }
 59 EXPORT_SYMBOL_GPL(v4l2_device_register);





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值