V4L2 driver 整體架構

2022-06-15 18:24:10 字數 2336 閱讀 3916

熟悉v4l2使用者空間程式設計的都知道, v4l2程式設計主要是呼叫一系列的ioctl函式去對v4l2裝置進行開啟, 關閉, 查詢, 設定等操作. v4l2裝置是乙個字元裝置, 而且其驅動的主要工作就是實現各種各樣的ioctl.

v4l2的整體框架如下圖所示:

在v4l2的核心中對這個file_operations的實現如下:

static const struct file_operations v4l2_fops = ;
這個v4l2_fops函式最終繫結在乙個cdev上, 並註冊到系統中。

v4l2_open為例(**在kernel\drivers\media\v4l2-core中):

/* override for the open function */

static int v4l2_open(struct inode *inode, struct file *filp)

/* and increase the device refcount */

video_get(vdev);

mutex_unlock(&videodev_lock);

if (vdev->fops->open)

if (vdev->debug)

printk(kern_debug "%s: open (%d)\n",

video_device_node_name(vdev), ret);

/* decrease the refcount in case of an error */

if (ret)

video_put(vdev);

return ret;

}

video_device結構體用於在/dev目錄下生成裝置節點檔案,把操作裝置的介面暴露給使用者空間。

我們是使用video_device來操作的,看看video_device這個結構體:

struct video_device

;

這個結構體中包含了乙個非常重要的結構體v4l2_device

struct v4l2_device ;
int v4l2_device_register(struct device*dev, struct v4l2_device *v4l2_dev)

static void v4l2_device_release(struct kref *ref)

struct v4l2_subdev ;
其中 list 域作為鍊錶節點鏈結至 v4l2_dev 指向的 v4l2_device 結構中,這個結構中最重要的成員就是 struct v4l2_subdev_ops *ops,該域包含了 v4l2 裝置支援的所有操作,定義如下:

struct v4l2_subdev_ops ;
v4l2_subdev_core_ops 包含的操作合集是各種型別裝置通用的:

struct v4l2_subdev_core_ops ;
v4l2_subdev_tuner_ops 包含的操作合集則是調諧器獨有的:

struct v4l2_subdev_tuner_ops ;
v4l2_subdev_audio_ops 包含的操作合集則是音訊部分獨有的:

struct v4l2_subdev_audio_ops ;
struct v4l2_subdev_video_ops ;
當我們把v4l2_subdev需要實現的成員都已經實現,就可以呼叫以下函式把子裝置註冊到v4l2核心層:

int v4l2_device_register_subdev(struct v4l2_device*v4l2_dev, struct v4l2_subdev *sd)
當解除安裝子裝置時,可以呼叫以下函式進行登出:

void v4l2_device_unregister_subdev(struct v4l2_subdev*sd)
我們使用一張圖來體現吧:

v4l2 程式設計介面 二 driver

1 video device cpp view plain copy struct video device 其中 struct cdev struct v4l2 file operations cpp view plain copy static const struct v4l2 ioctl o...

V4L2學習(一)整體說明

1 概述 字元裝置驅動程式核心 v4l2本身就是乙個字元裝置,具有字元裝置所有的特性,暴露介面給使用者空間 v4l2的核心原始碼位於drivers media v4l2 core,原始碼以實現的功能可以劃分為四類 v4l2框架 由v4l2 device.c v4l2 subdev.c v4l2 fh...

linux 驅動 camera 架構 V4L2

2012 11 14 v4l2應用程式框架 v4l2應用程式框架 用非阻塞模式開啟攝像頭裝置int camerafd camerafd open dev video0 o rdwr o nonblock,0 如果用阻塞模式開啟攝像頭裝置,上述 變為 camerafd open dev video0 ...