if (delay < -per_frame) {
if (delay < int64_t_C(-1000000) * s->frame_rate_base / s->frame_rate) {
static int grab_read_packet(AVFormatContext *s1, AVPacket *pkt){    VideoData *s = s1->priv_data;    int64_t curtime, delay;    struct timespec ts;    int64_t per_frame = (int64_t_C(1000000) * s->frame_rate_base) / s->frame_rate;    /* Calculate the time of the next frame */    s->time_frame += per_frame;    /* wait based on the frame rate */    for(;;) {        curtime = av_gettime();        delay = s->time_frame - curtime;        if (delay <= 0) {            if (delay < -per_frame) {                /* printf("grabbing is %d frames late (dropping)\n", (int) -(delay / 16666)); */                s->time_frame += per_frame;            }            break;        }            ts.tv_sec = delay / 1000000;        ts.tv_nsec = (delay % 1000000) * 1000;        nanosleep(&ts, NULL);    }    if (av_new_packet(pkt, s->frame_size) < 0)        return -EIO;    pkt->pts = curtime & ((1LL << 48) - 1);    /* read one frame */    if (s->aiw_enabled) {        return aiw_read_picture(s, pkt->data);    } else if (s->use_mmap) {        return v4l_mm_read_picture(s, pkt->data);    } else {        if (read(s->fd, pkt->data, pkt->size) != pkt->size)            return -EIO;        return s->frame_size;    }}