目前有一些C代码使用sigaction将处理程序与SIGALRM信号相关联。 现在在代码中,VIDIOCSYNC ioctl on in> fd暂停执行,直到in-> buf已被填充。 相同的网络摄像头设备可以飞轮,所以我的应用程序应该支持这些设备而不会阻止GUI。
#define SYNC_TIMEOUT 5
static int alarms;
static void sigalarm(int signal)
{
alarms++;
}
static void siginit(void)
{
struct sigaction act, old;
memset(&act, 0, sizeof(act));
act.sa_handler = sigalarm;
sigemptyset(&act.sa_mask);
sigaction(SIGALRM, &act, &old);
}
void wait_for_frame(input_t *in, int frameid)
{
alarms = 0;
alarm(SYNC_TIMEOUT);
if (ioctl(in->fd, VIDIOCSYNC, in->buf + frameid) < 0) {
fprintf(stderr, "input: Can't wait for frame %d: %s\n", frameid, strerror(errno));
}
if(alarms) {
fprintf(stderr, "\n"
"Your capture card driver: %s\n"
"is taking too long to provide frames. This could be due\n"
"either to a broken capture card, a signal that has become unstable\n"
"or very noisy, or a driver misconfiguration.\n",
in->drivername);
}
alarm(0);
}
我希望在这种情况下改变这一点:如果没有帧在100毫秒内到达,那么超时并让GUI有机会自行更新。