当前位置: 技术问答>linux和unix
关于video4linux的问题啊。。。。急
来源: 互联网 发布时间:2016-12-01
本文导语: 我把video4linux的例子原封不动的在开发板上跑了一下,发现程序会在mmap()之后退出,我试了很久也没有找到原因,希望大家能帮助我一下啊,谢谢,以下就是那个例子 /* * V4L2 video capture example * * This progr...
我把video4linux的例子原封不动的在开发板上跑了一下,发现程序会在mmap()之后退出,我试了很久也没有找到原因,希望大家能帮助我一下啊,谢谢,以下就是那个例子
/*
* V4L2 video capture example
*
* This program can be used and distributed without restrictions.
*/
#include
#include
#include
#include
#include /* getopt_long() */
#include /* low-level i/o */
#include
#include
#include
#include
#include
#include
#include
#include
#include /* for videodev2.h */
#include
#define CLEAR(x) memset (&(x), 0, sizeof (x))
typedef enum {
IO_METHOD_READ,
IO_METHOD_MMAP,
IO_METHOD_USERPTR,
} io_method;
struct buffer {
void * start;
size_t length;
};
static char * dev_name = NULL;
static io_method io = IO_METHOD_MMAP;
static int fd = -1;
struct buffer * buffers = NULL;
static unsigned int n_buffers = 0;
static void
errno_exit (const char * s)
{
fprintf (stderr, "%s error %d, %sn",
s, errno, strerror (errno));
exit (EXIT_FAILURE);
}
static int
xioctl (int fd,
int request,
void * arg)
{
int r;
do r = ioctl (fd, request, arg);
while (-1 == r && EINTR == errno);
return r;
}
static void
process_image (const void * p)
{
fputc ('.', stdout);
fflush (stdout);
}
static int
read_frame (void)
{
struct v4l2_buffer buf;
unsigned int i;
switch (io) {
case IO_METHOD_READ:
if (-1 == read (fd, buffers[0].start, buffers[0].length)) {
switch (errno) {
case EAGAIN:
return 0;
case EIO:
/* Could ignore EIO, see spec. */
/* fall through */
default:
errno_exit ("read");
}
}
process_image (buffers[0].start);
break;
case IO_METHOD_MMAP:
CLEAR (buf);
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
buf.memory = V4L2_MEMORY_MMAP;
if (-1 == xioctl (fd, VIDIOC_DQBUF, &buf)) {
switch (errno) {
case EAGAIN:
return 0;
case EIO:
/* Could ignore EIO, see spec. */
/* fall through */
default:
errno_exit ("VIDIOC_DQBUF");
}
}
assert (buf.index