Пример #1
0
static void *read_thread(void *arg)
{
	struct vidsrc_st *st = arg;

	while (st->run) {
		ssize_t n;

		n = read(st->fd, st->mb->buf, st->mb->size);
		if ((ssize_t)st->mb->size != n) {
			DEBUG_WARNING("video read: %d -> %d bytes\n",
				      st->mb->size, n);
			continue;
		}

		call_frame_handler(st, st->mb->buf);
	}

	return NULL;
}
Пример #2
0
static int read_frame(struct vidsrc_st *st)
{
	struct v4l2_buffer buf;

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

	buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
	buf.memory = V4L2_MEMORY_MMAP;

	if (-1 == xioctl (st->fd, VIDIOC_DQBUF, &buf)) {
		switch (errno) {

		case EAGAIN:
			return 0;

		case EIO:
			/* Could ignore EIO, see spec. */

			/* fall through */

		default:
			warning("v4l2: VIDIOC_DQBUF: %m\n", errno);
			return errno;
		}
	}

	if (buf.index >= st->n_buffers) {
		warning("v4l2: index >= n_buffers\n");
	}

	call_frame_handler(st, st->buffers[buf.index].start);

	if (-1 == xioctl (st->fd, VIDIOC_QBUF, &buf)) {
		warning("v4l2: VIDIOC_QBUF\n");
		return errno;
	}

	return 0;
}