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;
}
...全文
209 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

1,318

社区成员

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

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