diff --git a/libavdevice/x11grab.c b/libavdevice/x11grab.c
index 0e7b6ae..63d2490 100644
|
a
|
b
|
x11grab_read_header(AVFormatContext *s1)
|
| 319 | 319 | x11grab->frame_size = x11grab->width * x11grab->height * image->bits_per_pixel/8; |
| 320 | 320 | x11grab->dpy = dpy; |
| 321 | 321 | x11grab->time_base = av_inv_q(x11grab->framerate); |
| 322 | | x11grab->time_frame = av_gettime() / av_q2d(x11grab->time_base); |
| | 322 | x11grab->time_frame = av_gettime(); |
| 323 | 323 | x11grab->x_off = x_off; |
| 324 | 324 | x11grab->y_off = y_off; |
| 325 | 325 | x11grab->image = image; |
| … |
… |
x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
|
| 478 | 478 | Window root; |
| 479 | 479 | int follow_mouse = s->follow_mouse; |
| 480 | 480 | |
| 481 | | int64_t curtime, delay; |
| 482 | | struct timespec ts; |
| 483 | | |
| 484 | | /* Calculate the time of the next frame */ |
| 485 | | s->time_frame += INT64_C(1000000); |
| | 481 | int64_t curtime, delay, frame_dur; |
| 486 | 482 | |
| 487 | 483 | /* wait based on the frame rate */ |
| 488 | | for(;;) { |
| 489 | | curtime = av_gettime(); |
| 490 | | delay = s->time_frame * av_q2d(s->time_base) - curtime; |
| 491 | | if (delay <= 0) { |
| 492 | | if (delay < INT64_C(-1000000) * av_q2d(s->time_base)) { |
| 493 | | s->time_frame += INT64_C(1000000); |
| 494 | | } |
| 495 | | break; |
| 496 | | } |
| 497 | | ts.tv_sec = delay / 1000000; |
| 498 | | ts.tv_nsec = (delay % 1000000) * 1000; |
| 499 | | nanosleep(&ts, NULL); |
| 500 | | } |
| | 484 | curtime = av_gettime(); |
| | 485 | frame_dur = INT64_C(1000000) * av_q2d(s->time_base); |
| | 486 | for (delay = s->time_frame - curtime; delay < -frame_dur; delay += frame_dur) { |
| | 487 | s->time_frame += frame_dur; |
| | 488 | av_log(s1, AV_LOG_DEBUG, "X11Grab: Frame skipped\n"); |
| | 489 | } |
| | 490 | if (delay > 0) { |
| | 491 | if (s1->flags & AVFMT_FLAG_NONBLOCK) { |
| | 492 | return AVERROR(EAGAIN); |
| | 493 | } else { |
| | 494 | struct timespec ts; |
| | 495 | ts.tv_sec = delay / 1000000; |
| | 496 | ts.tv_nsec = (delay % 1000000) * 1000; |
| | 497 | nanosleep(&ts, NULL); |
| | 498 | } |
| | 499 | } |
| | 500 | |
| | 501 | /* Calculate the time of the next frame */ |
| | 502 | s->time_frame += frame_dur; |
| 501 | 503 | |
| 502 | 504 | av_init_packet(pkt); |
| 503 | 505 | pkt->data = image->data; |