Skip to content

Commit

Permalink
A more correct subscription to DV events that prevents possible hangs
Browse files Browse the repository at this point in the history
  • Loading branch information
mdevaev committed Sep 12, 2018
1 parent 55b1ea3 commit 856d237
Showing 1 changed file with 24 additions and 13 deletions.
37 changes: 24 additions & 13 deletions mjpg-streamer-experimental/plugins/input_uvc/v4l2uvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,13 @@ static int init_v4l2(struct vdIn *vd)
if (video_set_dv_timings(vd)) {
goto fatal;
}

struct v4l2_event_subscription sub;
memset(&sub, 0, sizeof(sub));
sub.type = V4L2_EVENT_SOURCE_CHANGE;
if (ioctl(vd->fd, VIDIOC_SUBSCRIBE_EVENT, &sub) < 0) {
IPRINT("Can\'t subscribe to V4L2_EVENT_SOURCE_CHANGE: %s\n", strerror(errno));
}
}

/*
Expand Down Expand Up @@ -534,18 +541,17 @@ int video_set_dv_timings(struct vdIn *vd)
int video_handle_event(struct vdIn *vd)
{
struct v4l2_event ev;

while (!xioctl(vd->fd, VIDIOC_DQEVENT, &ev)) {
if (!ioctl(vd->fd, VIDIOC_DQEVENT, &ev)) {
switch (ev.type) {
case V4L2_EVENT_SOURCE_CHANGE:
IPRINT("V4L2_EVENT_SOURCE_CHANGE: Source changed\n");
if (setResolution(vd, vd->width, vd->height) < 0) {
return -1;
}
break;
case V4L2_EVENT_EOS:
IPRINT("V4L2_EVENT_EOS\n");
break;
case V4L2_EVENT_SOURCE_CHANGE:
IPRINT("V4L2_EVENT_SOURCE_CHANGE: Source changed\n");
if (setResolution(vd, vd->width, vd->height) < 0) {
return -1;
}
break;
case V4L2_EVENT_EOS:
IPRINT("V4L2_EVENT_EOS\n");
break;
}
}
return 0;
Expand Down Expand Up @@ -980,8 +986,13 @@ int setResolution(struct vdIn *vd, int width, int height)
return -1;
}

DBG("setResolution(%d, %d) done, enabling the video...\n", width, height);
return video_enable(vd);
DBG("Resolution changed to %dx%d , enabling the video...\n", width, height);
if (video_enable(vd) < 0) {
IPRINT("Can\'t RE-enable the video after setResolution(%dx%d)", width, height);
return -1;
}

return 0;
}

/*
Expand Down

0 comments on commit 856d237

Please sign in to comment.