linux平台下如何强制TVP5146M2工作在PAL制式

haowow0703 2013-06-04 06:01:08
TVP5146M2所在的模块无法支持NTSC制式,纠结!
开发的时候用的摄像头默认是PAL制式,实际调试时采用的摄像头默认为NTSC制式,不知道如何设置这块,让TVP5146M2强制为PAL制式。

static int initCapture(int *capture_fd, int *numbuffers, char *inputname,
char *stdname, struct v4l2_format *fmt)
{
int ret, i, j;
struct v4l2_requestbuffers reqbuf;
struct v4l2_buffer buf;
struct v4l2_capability capability;
struct v4l2_input input;
v4l2_std_id std_id;
struct v4l2_standard standard;
int index;

/* Open the capture device */
*capture_fd = open((const char *) CAPTURE_DEVICE, O_RDWR);
if (*capture_fd <= 0) {
printf("Cannot open = %s device\n", CAPTURE_DEVICE);
return -1;
}
printf("\n%s: Opened Channel\n", CAPTURE_NAME);

/* Get any active input */
if (ioctl(*capture_fd, VIDIOC_G_INPUT, &index) < 0) {
perror("VIDIOC_G_INPUT");
goto ERROR;
}

/* Enumerate input to get the name of the input detected */
memset(&input, 0, sizeof(input));
input.index = index;
if (ioctl(*capture_fd, VIDIOC_ENUMINPUT, &input) < 0) {
perror("VIDIOC_ENUMINPUT");
goto ERROR;
}

printf("Get input oK\n");
printf("%s: Current Input: %s\n", CAPTURE_NAME, input.name);
/* Store the name of the output as per the input detected */
strcpy(inputname, input.name);

printf("start query\n");
/* Detect the standard in the input detected */
if (ioctl(*capture_fd, VIDIOC_QUERYSTD, &std_id) < 0) {
perror("VIDIOC_QUERYSTD");
//goto ERROR;
}

//查询支持的格式
struct v4l2_fmtdesc fmt1;
memset(&fmt1, 0, sizeof(fmt1));
fmt1.index = 0;
fmt1.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

while ((ret = ioctl(*capture_fd, VIDIOC_ENUM_FMT, &fmt1)) == 0) {

fmt1.index++;

printf("{ pixelformat = '%c%c%c%c', description = '%s' ,fmt1.index = %d}\n",

fmt1.pixelformat & 0xFF, (fmt1.pixelformat >> 8) & 0xFF,

(fmt1.pixelformat >> 16) & 0xFF, (fmt1.pixelformat >> 24) & 0xFF,

fmt1.description,fmt1.index);

/*ret = enum_frame_sizes(*capture_fd, fmt1.pixelformat);

if (ret != 0)

printf(" Unable to enumerate frame sizes.\n");

*/
}
//
printf("start get std\n");
/* Get the standard*/
if (ioctl(*capture_fd, VIDIOC_G_STD, &std_id) < 0) {
/* Note when VIDIOC_ENUMSTD always returns EINVAL this
is no video device or it falls under the USB exception,
and VIDIOC_G_STD returning EINVAL is no error. */
perror("VIDIOC_G_STD");
goto ERROR;
}
//printf("std_id= %s", std_id.)

memset(&standard, 0, sizeof(standard));
standard.index = 0;
while (1) {
if (ioctl(*capture_fd, VIDIOC_ENUMSTD, &standard) < 0) {
perror("VIDIOC_ENUMSTD");
goto ERROR;
}

/* Store the name of the standard */
if (standard.id & std_id) {
strcpy(stdname, standard.name);
printf("%s: Current standard: %s\n",
CAPTURE_NAME, standard.name);
break;
}
standard.index++;
}

/* Check if the device is capable of streaming */
if (ioctl(*capture_fd, VIDIOC_QUERYCAP, &capability) < 0) {
perror("VIDIOC_QUERYCAP");
goto ERROR;
}
if (capability.capabilities & V4L2_CAP_STREAMING)
printf("%s: Capable of streaming\n", CAPTURE_NAME);
else {
printf("%s: Not capable of streaming\n", CAPTURE_NAME);
goto ERROR;
}
fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
ret = ioctl(*capture_fd, VIDIOC_G_FMT, fmt);
if (ret < 0) {
perror("VIDIOC_G_FMT");
goto ERROR;
}

fmt->fmt.pix.pixelformat = DEF_PIX_FMT;
//fmt->fmt.pix.height = HEIGHT;
//fmt->fmt.pix.width = WIDTH;
ret = ioctl(*capture_fd, VIDIOC_S_FMT, fmt);
if (ret < 0) {
perror("VIDIOC_S_FMT");
goto ERROR;
}

ret = ioctl(*capture_fd, VIDIOC_G_FMT, fmt);
if (ret < 0) {
perror("VIDIOC_G_FMT");
goto ERROR;
}

if (fmt->fmt.pix.pixelformat != DEF_PIX_FMT) {
printf("%s: Requested pixel format not supported\n",
CAPTURE_NAME);
goto ERROR;
}

/* Buffer allocation
* Buffer can be allocated either from capture driver or
* user pointer can be used
*/
/* Request for MAX_BUFFER input buffers. As far as Physically contiguous
* memory is available, driver can allocate as many buffers as
* possible. If memory is not available, it returns number of
* buffers it has allocated in count member of reqbuf.
* HERE count = number of buffer to be allocated.
* type = type of device for which buffers are to be allocated.
* memory = type of the buffers requested i.e. driver allocated or
* user pointer */
reqbuf.count = *numbuffers;
reqbuf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
reqbuf.memory = V4L2_MEMORY_MMAP;
ret = ioctl(*capture_fd, VIDIOC_REQBUFS, &reqbuf);
if (ret < 0) {
perror("Cannot allocate memory");
goto ERROR;
}
/* Store the number of buffers actually allocated */
*numbuffers = reqbuf.count;
printf("%s: Number of requested buffers = %d\n", CAPTURE_NAME,
*numbuffers);

memset(&buf, 0, sizeof(buf));

/* Mmap the buffers
* To access driver allocated buffer in application space, they have
* to be mmapped in the application space using mmap system call */
for (i = 0; i < (*numbuffers); i++) {
buf.type = reqbuf.type;
buf.index = i;
buf.memory = reqbuf.memory;
ret = ioctl(*capture_fd, VIDIOC_QUERYBUF, &buf);
if (ret < 0) {
perror("VIDIOC_QUERYCAP");
*numbuffers = i;
goto ERROR1;
}


capture_buff_info[i].length = buf.length;
capture_buff_info[i].index = i;
capture_buff_info[i].start = mmap(NULL, buf.length,
PROT_READ |
PROT_WRITE,
MAP_SHARED,
*capture_fd,
buf.m.offset);

if (capture_buff_info[i].start == MAP_FAILED) {
printf("Cannot mmap = %d buffer\n", i);
*numbuffers = i;
goto ERROR1;
}

memset((void *) capture_buff_info[i].start, 0x80,
capture_buff_info[i].length);
/* Enqueue buffers
* Before starting streaming, all the buffers needs to be
* en-queued in the driver incoming queue. These buffers will
* be used by thedrive for storing captured frames. */
ret = ioctl(*capture_fd, VIDIOC_QBUF, &buf);
if (ret < 0) {
perror("VIDIOC_QBUF");
*numbuffers = i + 1;
goto ERROR1;
}
}

printf("%s: Init done successfully\n\n", CAPTURE_NAME);
return 0;

ERROR1:
for (j = 0; j < *numbuffers; j++)
munmap(capture_buff_info[j].start,
capture_buff_info[j].length);
ERROR:
close(*capture_fd);

return -1;
}
...全文
265 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
随着通信电子技术的迅速发展,信息技术给家居行业产生了深远的影响,家居环境的智能化监控已经成为智能家居的一个重要的发展方向。人们逐渐对自己的生活提出一种更高的要求,他们需要一种智能化、可交互,并且融合现代创新科技的产品来改善他们的生活环境,使他们生活更加安全、舒适、便捷、智能。本文根据智能家居的发展背景和研究现状,并且从实用性和可行性角度出发,研究设计了一种基于STM32单片机的智能家居系统。该系统由一个多功能综合的技术系统组成,各个多功能子系统间具有协同配合能力。基于STM32单片机实现的功能子系统包括:智能温度检测,智能湿度检测,智能烟雾/火灾检测智能检测,无线传输,人机交互机构,风扇调节,报警模块。 整个系统分为前端51单片机采集板和后端STM32单片机接收板。 采集板使用DHT11温湿度传感器、MQ烟雾传感器完成室内家居环境的采集。然后通过nRFL24L01将采集到的数据发送给后端。接收板使用LCD1602完成数据显示、使用蜂鸣器模块报警,使用风扇驱动模块调节室内家居环境。本文完成了智能家居控制系统前端、后端软硬件的设计,使用Altium designer绘制了电路原理图,使用Keil C完成了51单片机和STM32单片机的编程与调试。 最后,对本文设计的基于STM32的智能家居控制系统进行部署调试。试验结果表明,该系统可成功应用在智能家居环境检测调节和火灾安全防护的领域,可提高家居生活智能化水平。

1,323

社区成员

发帖
与我相关
我的任务
社区描述
主要是开发驱动技术
社区管理员
  • 驱动程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧