linux3.0字符设备驱动,v4l2驱动3-linux3.0.8中v4l2_format详解

首先是

//四字符代码,为了标示视频数据流格式

//在次文件的下,比如大家熟悉的mjpeg

//#define V4L2_PIX_FMT_MJPEG v4l2_fourcc(’M’, ’J’, ’P’, ’G’) /* Motion-JPEG */

/* Four-character-code (FOURCC) */

#define v4l2_fourcc(a, b, c, d)

((__u32)(a) | ((__u32)(b) << 8) | ((__u32)(c) << 16) | ((__u32)(d) << 24))

/*

* F O R M A T E N U M E R A T I O N

*/

struct v4l2_fmtdesc {

__u32 index; /* Format number */ //格式索引

enum v4l2_buf_type type; /* buffer type */ //缓冲类型

/*

ioctl会根据这个type选择对应的函数,例如VIDIOC_ENUM_FMT时type为V4L2_BUF_TYPE_VIDEO_CAPTURE,

那么就会调用 int (*vidioc_enum_fmt_vid_cap)(struct file *file, void *fh, struct v4l2_fmtdesc *f);

enum v4l2_buf_type {

V4L2_BUF_TYPE_VIDEO_CAPTURE = 1,

V4L2_BUF_TYPE_VIDEO_OUTPUT = 2,

V4L2_BUF_TYPE_VIDEO_OVERLAY = 3,

V4L2_BUF_TYPE_VBI_CAPTURE = 4,

V4L2_BUF_TYPE_VBI_OUTPUT = 5,

V4L2_BUF_TYPE_SLICED_VBI_CAPTURE = 6,

V4L2_BUF_TYPE_SLICED_VBI_OUTPUT = 7,

V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY = 8,

V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE = 9,

V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE = 10,

V4L2_BUF_TYPE_PRIVATE = 0x80,

};

*/

__u32 flags;//标志

__u8 description[32]; /* Description string */ //描述

__u32 pixelformat; /* Format fourcc */ //用定义好的的宏v4l2_fourcc

__u32 reserved[4];

};

//经常在应用层使用VIDIOC_ENUM_FMT去获取支持的格式,主要就是获取这个结构体。有的可能支持几种格式,可以通过

//设置v4l2_fmtdesc对应的index去获取。

/**

* struct v4l2_format - stream data format

* @type: type of the data stream

* @pix: definition of an image format

* @pix_mp: definition of a multiplanar image format

* @win: definition of an overlaid image

* @vbi: raw VBI capture or output parameters

* @sliced: sliced VBI capture or output parameters

* @raw_data: placeholder for future extensions and custom formats

*/

//这个结构体在设置格式和获取当然格式时会用到。

struct v4l2_format {

enum v4l2_buf_type type;//类型,已说过

union {

struct v4l2_pix_format pix; /* V4L2_BUF_TYPE_VIDEO_CAPTURE */

struct v4l2_pix_format_mplane pix_mp; /* V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE */

struct v4l2_window win; /* V4L2_BUF_TYPE_VIDEO_OVERLAY */

struct v4l2_vbi_format vbi; /* V4L2_BUF_TYPE_VBI_CAPTURE */

struct v4l2_sliced_vbi_format sliced; /* V4L2_BUF_TYPE_SLICED_VBI_CAPTURE */

__u8 raw_data[200]; /* user-defined */

} fmt;

};

下面我们重点说union中的东西,vbi就不说了

struct v4l2_pix_format {

__u32 width; //宽

__u32 height; //高

__u32 pixelformat;//图素格式, rgb565 rgb888 yuv422 yuv420等等

enum v4l2_field field; //场格式,下面详细说

__u32 bytesperline; /* for padding, zero if unused */ //表明缓冲区中有多少字节用于表示图像中一行像素的所有像素值。

//由于一个像素可能有多个字节表示,所以 bytesPerLine 可能是字段 width 值的若干倍

__u32 sizeimage;//图像大小

enum v4l2_colorspace colorspace;//色彩空间 SMPTE170M等 http://linuxtv.org/downloads/v4l-dvb-apis/colorspaces.html介绍了转换方法

//http://vektor.theorem.ca/graphics/ycbcr/介绍

__u32 priv; /* private data, depends on pixelformat */

};

enum v4l2_field {

V4L2_FIELD_ANY = 0, /* driver can choose from none,

top, bottom, interlaced

depending on whatever it thinks

is approximate ...

V4L2_FIELD_NONE = 1, /* this device has no fields ...

V4L2_FIELD_TOP = 2, /* top field only

V4L2_FIELD_BOTTOM = 3, /* bottom field only

V4L2_FIELD_INTERLACED = 4, /* both fields interlaced

V4L2_FIELD_SEQ_TB = 5, /* both fields sequential into one

buffer, top-bottom order

V4L2_FIELD_SEQ_BT = 6, /* same as above + bottom-top order

V4L2_FIELD_ALTERNATE = 7, /* both fields alternating into

separate buffers

V4L2_FIELD_INTERLACED_TB = 8, /* both fields interlaced, top field

first and the top field is

transmitted first

V4L2_FIELD_INTERLACED_BT = 9, /* both fields interlaced, top field

first and the bottom field is

transmitted first

};

隔行和逐行:video的帧可区分为隔行和逐行:

逐行顺序的传输一帧所有的行,而隔行则把一帧划分成两个fields,分别保存帧的奇数行和偶数行,被称作奇场和偶场.

阴极射线电视机需要交替的显示两场来组成一个完整的帧,交替的时延需要我们交替的传输奇场和偶场。这个奇怪技术的引入是因为:在刷新率接近电影时,图片会

消退的过快。使用奇偶场可以避免使用双倍的buffer以及额外的带宽需求。

瞬间序:首先要明确模拟camera(数字摄像头不在这个讨论之列。)并不是在同一时间曝光一帧,camera通过场来传输这些帧的,这些场是在不

同瞬间拍摄的。屏幕上的一个运动对象因此会在两个field之间产生动画效果。这种情况下需要识别哪一帧更老一点,也称作“瞬间序”。

顶场和低场:当驱动通过场提供或者接收images,应用应该知道如何通过这些场组合成帧,通过划分为top bottom

场,顶场的第一行是帧的第一行,底场的第一行是帧的第二行。然而因为field是一个跟着一个拍的,争论帧是由top还是bottom开始的是没意义的,

任何两个相邻的top bottom场, 或者 bottom top场都可以组成一个有效的帧。与直觉相反,top 场不一定排在bottom前面,

top和bottom到底谁先谁后,是由video标准决定的。因此要区分瞬间序和空间序,下面的图会给出清晰的解释。

post-1454.html

post-1454.html

我只说一下:PAL + V4L2_FIELD_INTERLACED_BT

从上图看PAL下 top: 红绿红 bottom:蓝黄蓝

V4L2_FIELD_INTERLACED_BT是两场隔行扫描,top在先,bottom场先发送

那就会是黄红蓝绿,就出现了红黄和绿蓝彩条。其他的自己分析吧!

struct v4l2_plane_pix_format {

__u32 sizeimage; //被使用层的最大字节数

__u16 bytesperline;//每行字节数

__u16 reserved[7];

} __attribute__ ((packed));

/**

* struct v4l2_pix_format_mplane - multiplanar format definition

* @width: image width in pixels

* @height: image height in pixels

* @pixelformat: little endian four character code (fourcc)

* @field: field order (for interlaced video)

* @colorspace: supplemental to pixelformat

* @plane_fmt: per-plane information

* @num_planes: number of planes for this format

*/

struct v4l2_pix_format_mplane {

__u32 width; //宽

__u32 height; //高

__u32 pixelformat; //像素格式 fourcc定义

enum v4l2_field field; //见struct v4l2_pix_format

enum v4l2_colorspace colorspace; //struct v4l2_pix_format

struct v4l2_plane_pix_format plane_fmt[VIDEO_MAX_PLANES]; //每平面信息

__u8 num_planes; //此格式的平面数

__u8 reserved[11];

} __attribute__ ((packed));

多层的格式有,只是举几个例子

/* two non contiguous planes - one Y, one Cr + Cb interleaved */ //两层的

#define V4L2_PIX_FMT_NV12M v4l2_fourcc(’N’, ’M’, ’1’, ’2’) /* 12 Y/CbCr 4:2:0 */

#define V4L2_PIX_FMT_NV12MT v4l2_fourcc(’T’, ’M’, ’1’, ’2’) /* 12 Y/CbCr 4:2:0 64x32 macroblocks */

/* three non contiguous planes - Y, Cb, Cr */ //三层的

#define V4L2_PIX_FMT_YUV420M v4l2_fourcc(’Y’, ’M’, ’1’, ’2’) /* 12 YUV420 planar */

struct v4l2_clip {

struct v4l2_rect c;

struct v4l2_clip __user *next;

};

//这是video overlay使用的结构体

struct v4l2_window {

struct v4l2_rect w; //窗口位置

enum v4l2_field field; //也说过

__u32 chromakey; //色度:色调和饱和度

struct v4l2_clip __user *clips; //剪切

__u32 clipcount; //剪切计数

void __user *bitmap; //每个位对应覆盖图像的一个像素,此位置一时对应像素才显示。

__u8 global_alpha; //全局alpha值

};

vbi不说了

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值