v4l2 学习

1。控制命令

VIDIOC_REQBUFS分配内存

VIDIOC_QUERYBUF       //VIDIOC_REQBUFS中分配的数据缓存转换成物理地址

VIDIOC_QUERYCAP      //查询驱动功能

VIDIOC_ENUM_FMT      //获取当前驱动支持的视频格式

VIDIOC_S_FMT        //设置当前驱动的频捕获格式

VIDIOC_G_FMT        //读取当前驱动的频捕获格式

VIDIOC_TRY_FMT       //验证当前驱动的显示格式

VIDIOC_CROPCAP       //查询驱动的修剪能力

VIDIOC_S_CROP        //设置视频信号的矩形边框

VIDIOC_G_CROP        /读取视频信号的矩形边框


VIDIOC_QBUF         //把数据从缓存中读取出来

VIDIOC_DQBUF        //把数据放回缓存队列

VIDIOC_STREAMON       //开始视频显示函数

VIDIOC_STREAMOFF      //结束视频显示函数

VIDIOC_QUERYSTD       //检查当前视频设备支持的标准,例如PALNTSC


struct v4l2_subdev *v4l2_i2c_new_subdev_board(struct v4l2_device *v4l2_dev,
       struct i2c_adapter *adapter, struct i2c_board_info *info,
       const unsigned short *probe_addrs)
{
   struct v4l2_subdev *sd = NULL;
   struct i2c_client *client;

   BUG_ON(!v4l2_dev);
   //加载I2C驱动,通过modprobe加载
   request_module(I2C_MODULE_PREFIX "%s", info->type);
   

   创建i2c设备时从设备地址是明确的还是要通过探测。  

   在这两个调用中会向系统中增加sysfs,会把驱动和设备关联起来,并会调用i2c驱动中的probe接口

   /* Create the i2c client */
   if (info->addr == 0 && probe_addrs)
       client = i2c_new_probed_device(adapter, info, probe_addrs,
                          NULL);
   else
       client = i2c_new_device(adapter, info);

   /* Note: by loading the module first we are certain that c->driver
      will be set if the driver was found. If the module was not loaded
      first, then the i2c core tries to delay-load the module for us,
      and then c->driver is still NULL until the module is finally
      loaded. This delay-load mechanism doesn't work if other drivers
      want to use the i2c device, so explicitly loading the module
      is the best alternative. */
   if (client == NULL || client->driver == NULL)
       goto error;

   /* Lock the module so we can safely get the v4l2_subdev pointer */
   if (!try_module_get(client->driver->driver.owner))
       goto error;

       从客户端驱动私有数据获得SD
   sd = i2c_get_clientdata(client);
     注册子设备到系统
   /* Register with the v4l2_device which increases the module's
      use count as well. */
   if (v4l2_device_register_subdev(v4l2_dev, sd))
       sd = NULL;
   /* Decrease the module use count to match the first try_module_get. */
   module_put(client->driver->driver.owner);

error:
   /* If we have a client but no subdev, then something went wrong and
      we must unregister the client. */
   if (client && sd == NULL)
       i2c_unregister_device(client);
   return sd;


你可能感兴趣的:(v4l2)