#include "v4l2-ctl.h"
+struct v4l2_decoder_cmd dec_cmd; /* (try_)decoder_cmd */
+static struct v4l2_encoder_cmd enc_cmd; /* (try_)encoder_cmd */
static struct v4l2_jpegcompression jpegcomp; /* jpeg compression */
static struct v4l2_streamparm parm; /* get/set parm */
-static struct v4l2_encoder_cmd enc_cmd; /* (try_)encoder_cmd */
-static struct v4l2_decoder_cmd dec_cmd; /* (try_)decoder_cmd */
static double fps = 0; /* set framerate speed, in fps */
static double output_fps = 0; /* set framerate speed, in fps */
{
if (options[OptStreamMmap] || options[OptStreamUser]) {
struct v4l2_requestbuffers reqbufs;
+ struct v4l2_event_subscription sub;
int fd_flags = fcntl(fd, F_GETFL);
bool is_mplane = capabilities &
(V4L2_CAP_VIDEO_CAPTURE_MPLANE |
reqbufs.count = reqbufs_count;
reqbufs.type = type;
reqbufs.memory = is_mmap ? V4L2_MEMORY_MMAP : V4L2_MEMORY_USERPTR;
+ memset(&sub, 0, sizeof(sub));
+ sub.type = V4L2_EVENT_EOS;
+ ioctl(fd, VIDIOC_SUBSCRIBE_EVENT, &sub);
if (file) {
if (!strcmp(file, "-"))
unsigned count = 0, last = 0;
struct timeval tv_last;
+ bool eos = false;
- for (;;) {
+ while (!eos) {
struct v4l2_plane planes[VIDEO_MAX_PLANES];
struct v4l2_buffer buf;
+ fd_set read_fds;
+ fd_set exception_fds;
char ch = '.';
int ret;
if (use_poll) {
- fd_set fds;
struct timeval tv;
int r;
- FD_ZERO(&fds);
- FD_SET(fd, &fds);
+ FD_ZERO(&read_fds);
+ FD_SET(fd, &read_fds);
+ FD_ZERO(&exception_fds);
+ FD_SET(fd, &exception_fds);
/* Timeout. */
tv.tv_sec = 2;
tv.tv_usec = 0;
- r = select(fd + 1, &fds, NULL, NULL, &tv);
+ r = select(fd + 1, &read_fds, NULL, &exception_fds, &tv);
if (r == -1) {
if (EINTR == errno)
}
}
+ if (FD_ISSET(fd, &exception_fds)) {
+ struct v4l2_event ev;
+
+ while (!ioctl(fd, VIDIOC_DQEVENT, &ev)) {
+ if (ev.type != V4L2_EVENT_EOS)
+ continue;
+ eos = true;
+ break;
+ }
+ }
+ if (!FD_ISSET(fd, &read_fds))
+ continue;
+
memset(&buf, 0, sizeof(buf));
memset(planes, 0, sizeof(planes));
buf.type = reqbufs.type;
if (--stream_count == 0)
break;
}
+ if (options[OptDecoderCmd]) {
+ doioctl(fd, VIDIOC_DECODER_CMD, &dec_cmd);
+ options[OptDecoderCmd] = false;
+ }
doioctl(fd, VIDIOC_STREAMOFF, &type);
fcntl(fd, F_SETFL, fd_flags);
fprintf(stderr, "\n");