AnsweredAssumed Answered

ERROR: v4l2 capture: mxc_v4l_dqueue timeout enc_counter 0

Question asked by jie jia on May 21, 2017
Latest reply on May 25, 2017 by Joan Xie

board: refer to mx6q-sabresd

BSP: linux3.0.15

我在板子上面接了一个1080P的摄像头,按照Support BT1120 progressive mode in Mx6Q 提供的patch,给内核打上补丁。 

当我使用如下命令进行测试时,摄像头的图像是可以正常显示的:

./mxc_v4l2_overlay.out -iw 1920 -ih 1080 -it 0 -il 0 -ow 1280 -oh 800 -ot 0 -ol 0 -fr 30

 

但是当我使用自己写的一个v4l2程序来测试该摄像头时,执行到ioctl (v4l2_fd, VIDIOC_DQBUF, &tV4l2Buf),内核打印:ERROR: v4l2 capture: mxc_v4l_dqueue timeout enc_counter 0, 并且ioctl (v4l2_fd, VIDIOC_DQBUF, &tV4l2Buf)函数返回-1; 想请问下为什么会出现这种情况??

 

以下是测试程序的部分代码:

struct v4l2_format fmt;
struct v4l2_requestbuffers requestbuffers;
int v4l2_fd = -1;
int iError,i;

int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

v4l2_fd = open("/dev/video0", O_RDWR);
if (v4l2_fd < 0)
{
   printf(" open video ERR\n");
   return -1;
}

 

 

memset(&fmt, 0, sizeof(struct v4l2_format));
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
fmt.fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
fmt.fmt.pix.width = 1920;
fmt.fmt.pix.height = 1080;
fmt.fmt.pix.field = V4L2_FIELD_ANY;
if((ioctl(v4l2_fd, VIDIOC_S_FMT, &fmt))<0)
{
   printf("Unable to set format: %d.\n", errno);
   return -1;
}

 

memset(&requestbuffers, 0, sizeof(struct v4l2_requestbuffers));
requestbuffers.count = 4;
requestbuffers.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
requestbuffers.memory = V4L2_MEMORY_MMAP;
if((ioctl(v4l2_fd, VIDIOC_REQBUFS, &requestbuffers))<0)
{
   printf("Error: failed to request buffers.\n");
   return -1;
}

 

buffers = calloc (4, sizeof (*buffers));
for (i = 0; i < 4; i++)
{
   memset(&tV4l2Buf, 0, sizeof(struct v4l2_buffer));
   tV4l2Buf.index = i;
   tV4l2Buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
   tV4l2Buf.memory = V4L2_MEMORY_MMAP;
   iError = ioctl(v4l2_fd, VIDIOC_QUERYBUF, &tV4l2Buf);
   if (iError)
   {
      printf("Unable to query buffer.\n");
      return -1;
  }
   buffers[i].start = mmap(0, tV4l2Buf.length, PROT_READ, MAP_SHARED, v4l2_fd,  tV4l2Buf.m.offset);
   if (buffers[i].start == MAP_FAILED)
   {
      printf("Unable to map buffer\n");
      return -1;
   }
}

 

for (i = 0; i < 4; ++i)
{
   tV4l2Buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
   tV4l2Buf.memory = V4L2_MEMORY_MMAP;
   tV4l2Buf.index = i;
   ioctl(v4l2_fd, VIDIOC_QBUF, &tV4l2Buf);
}

 

if((ioctl(v4l2_fd, VIDIOC_STREAMON, &type))<0)
{
   printf("error ioctl streamon\n");
   return -1;
}


fd_set fds;
FD_ZERO (&fds);
FD_SET (v4l2_fd, &fds);
select(v4l2_fd + 1, &fds, NULL, NULL, NULL);


tV4l2Buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
tV4l2Buf.memory = V4L2_MEMORY_MMAP;
iError = ioctl (v4l2_fd, VIDIOC_DQBUF, &tV4l2Buf); //在这里一直没有数据,然后内核打印超时,该函数返回-1
if (iError)
{
   printf("Unable to dqueue buffer. %d\n", iError);
   return -1;
}

 

 

Outcomes