c - How to wait for frame and alarm signal -
i have problem webcam. can hardware 1 i'm convinced no. apps can see stream freezes. because of following output used app when problem occurs:
v4l: timeout (got sigalrm), hardware/driver problems?
i have checked out code , interesting part:
/* how many seconds wait before deciding it's driver problem. */ #define sync_timeout 3 int alarms; void sigalarm(int signal) { alarms++; } ................................................................................. void wait_for_frame_v4l1( input_t *vidin, int frameid ) { alarms = 0; alarm(sync_timeout); if (ioctl(vidin->fd, vidiocsync, vidin->buf + frameid) < 0 ) fprintf(stderr, "input: can't wait frame %d: %s\n", frameid, strerror(errno)); if (alarms) fprintf(stderr, "v4l: timeout (got sigalrm), hardware/driver problems?"); alarm(0); }
from conclude sync_timeout problem. value 3 secondes seems quite enough.
my request me chage code don't block indefinitely waiting frames:
if no frame arrives within 100 ms, timeout , give gui chance update itself. not devices can free wheel, app should support such devices without blocking gui.
how can sub-second waiting?
v4l2 devices work this:
/* how many milliseconds wait before deciding it's driver problem. */ #define sync_timeout_msecs 100 int wait_for_frame_v4l2(input_t * vidin) { struct timeval timeout; fd_set rdset; int n; fd_zero(&rdset); fd_set(vidin->fd, &rdset); timeout.tv_sec = 0; timeout.tv_usec = sync_timeout_msecs * 1000; n = select(vidin->fd + 1, &rdset, 0, 0, &timeout); if(n == -1) { fprintf(stderr, "input: can't wait frame: %s\n", strerror(errno)); } else if(n == 0) { sigalarm(0); return 1; } return 0; }
but have v4l1 device.
what (usb) webcam , kernel version using?
- update driver/kernel
- if it's usb-cam, try connecting without usb-hub
the vidiocsync ioctl on vidin->fd suspends execution until vidin->buf has been filled. can wait filled buffer become available via select or poll
Comments
Post a Comment