static int mmap_read_frame(struct video_data *s, void *frame, int64_t *ts)

{

    struct v4l2_buffer buf;

    int res;



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

    buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

    buf.memory = V4L2_MEMORY_MMAP;



    /* FIXME: Some special treatment might be needed in case of loss of signal... */

    while ((res = ioctl(s->fd, VIDIOC_DQBUF, &buf)) < 0 &&

           ((errno == EAGAIN) || (errno == EINTR)));

    if (res < 0) {

        av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n", strerror(errno));



        return -1;

    }

    assert (buf.index < s->buffers);

    assert(buf.bytesused == s->frame_size);

    /* Image is at s->buff_start[buf.index] */

    memcpy(frame, s->buf_start[buf.index], buf.bytesused);

    *ts = buf.timestamp.tv_sec * int64_t_C(1000000) + buf.timestamp.tv_usec;



    res = ioctl (s->fd, VIDIOC_QBUF, &buf);

    if (res < 0) {

        av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF)\n");



        return -1;

    }



    return s->buf_len[buf.index];

}

static int mmap_read_frame(struct video_data *s, void *frame, int64_t *ts)

{

    struct v4l2_buffer buf;

    int res;



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

    buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

    buf.memory = V4L2_MEMORY_MMAP;



    

    while ((res = ioctl(s->fd, VIDIOC_DQBUF, &buf)) < 0 &&

           ((errno == EAGAIN) || (errno == EINTR)));

    if (res < 0) {

        av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %s\n", strerror(errno));



        return -1;

    }

    assert (buf.index < s->buffers);

    assert(buf.bytesused == s->frame_size);

    

    memcpy(frame, s->buf_start[buf.index], buf.bytesused);

    *ts = buf.timestamp.tv_sec * int64_t_C(1000000) + buf.timestamp.tv_usec;



    res = ioctl (s->fd, VIDIOC_QBUF, &buf);

    if (res < 0) {

        av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF)\n");



        return -1;

    }



    return s->buf_len[buf.index];

}

    assert(buf.bytesused == s->frame_size);
static int FUNC_0(struct video_data *VAR_0, void *VAR_1, int64_t *VAR_2)

{

    struct v4l2_buffer VAR_3;

    int VAR_4;



    memset(&VAR_3, 0, sizeof(struct v4l2_buffer));

    VAR_3.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;

    VAR_3.memory = V4L2_MEMORY_MMAP;



    

    while ((VAR_4 = ioctl(VAR_0->fd, VIDIOC_DQBUF, &VAR_3)) < 0 &&

           ((errno == EAGAIN) || (errno == EINTR)));

    if (VAR_4 < 0) {

        av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %VAR_0\n", strerror(errno));



        return -1;

    }

    assert (VAR_3.index < VAR_0->buffers);

    assert(VAR_3.bytesused == VAR_0->frame_size);

    

    memcpy(VAR_1, VAR_0->buf_start[VAR_3.index], VAR_3.bytesused);

    *VAR_2 = VAR_3.timestamp.tv_sec * int64_t_C(1000000) + VAR_3.timestamp.tv_usec;



    VAR_4 = ioctl (VAR_0->fd, VIDIOC_QBUF, &VAR_3);

    if (VAR_4 < 0) {

        av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF)\n");



        return -1;

    }



    return VAR_0->buf_len[VAR_3.index];

}

static int FUNC_0(struct video_data *VAR_0, void *VAR_1, int64_t *VAR_2)
{ struct v4l2_buffer VAR_3; int VAR_4; memset(&VAR_3, 0, sizeof(struct v4l2_buffer)); VAR_3.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; VAR_3.memory = V4L2_MEMORY_MMAP; while ((VAR_4 = ioctl(VAR_0->fd, VIDIOC_DQBUF, &VAR_3)) < 0 &&
((errno == EAGAIN) || (errno == EINTR))); if (VAR_4 < 0) { av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_DQBUF): %VAR_0\n", strerror(errno)); return -1; } assert (VAR_3.index < VAR_0->buffers); assert(VAR_3.bytesused == VAR_0->frame_size); memcpy(VAR_1, VAR_0->buf_start[VAR_3.index], VAR_3.bytesused); *VAR_2 = VAR_3.timestamp.tv_sec * int64_t_C(1000000) + VAR_3.timestamp.tv_usec; VAR_4 = ioctl (VAR_0->fd, VIDIOC_QBUF, &VAR_3); if (VAR_4 < 0) { av_log(NULL, AV_LOG_ERROR, "ioctl(VIDIOC_QBUF)\n"); return -1; } return VAR_0->buf_len[VAR_3.index]; }