summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrevor \\\\ Higgins <[email protected]>2016-02-03 09:10:01 -0500
committerMichael Niedermayer <[email protected]>2016-02-05 01:11:17 +0100
commit6632802aa00c8fe2126697d9eb8e498c600aee79 (patch)
tree24c9496c3d3236b987556499e39dd5961f1e4777
parent1bbfaba196b373496de59b8799849b5eadc3193b (diff)
x11grab: fixed next frame capture time calculation
The next frame time could slip, causing the frame rate to drop until frames were dropped. Now will capture at the next correct moment instead. Signed-off-by: Michael Niedermayer <[email protected]>
-rw-r--r--libavdevice/x11grab.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/libavdevice/x11grab.c b/libavdevice/x11grab.c
index bdfaa66d35..9dc3472187 100644
--- a/libavdevice/x11grab.c
+++ b/libavdevice/x11grab.c
@@ -526,16 +526,11 @@ static int x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
int64_t curtime, delay;
struct timespec ts;
- /* Calculate the time of the next frame */
- s->time_frame += INT64_C(1000000);
-
/* wait based on the frame rate */
for (;;) {
curtime = av_gettime();
delay = s->time_frame * av_q2d(s->time_base) - curtime;
if (delay <= 0) {
- if (delay < INT64_C(-1000000) * av_q2d(s->time_base))
- s->time_frame += INT64_C(1000000);
break;
}
ts.tv_sec = delay / 1000000;
@@ -543,6 +538,11 @@ static int x11grab_read_packet(AVFormatContext *s1, AVPacket *pkt)
nanosleep(&ts, NULL);
}
+ /* Calculate the time of the next frame */
+ do {
+ s->time_frame += INT64_C(1000000);
+ } while ((s->time_frame * av_q2d(s->time_base) - curtime) <= 0);
+
av_init_packet(pkt);
pkt->data = image->data;
pkt->size = s->frame_size;