mirror of https://git.ffmpeg.org/ffmpeg.git
avdevice: use av_gettime_relative() for elapsed time calculations
av_gettime_relative() is using the monotonic clock therefore more suitable for elapsed time calculations. Packet timestamps are still kept absolute, although that should be configurable in the future. Related to ticket #9089. Signed-off-by: Marton Balint <cus@passwd.hu>
This commit is contained in:
parent
529bf5daf2
commit
2d32aed85c
|
@ -225,14 +225,14 @@ static void bktr_getframe(uint64_t per_frame)
|
|||
{
|
||||
uint64_t curtime;
|
||||
|
||||
curtime = av_gettime();
|
||||
curtime = av_gettime_relative();
|
||||
if (!last_frame_time
|
||||
|| ((last_frame_time + per_frame) > curtime)) {
|
||||
if (!usleep(last_frame_time + per_frame + per_frame / 8 - curtime)) {
|
||||
if (!nsignals)
|
||||
av_log(NULL, AV_LOG_INFO,
|
||||
"SLEPT NO signals - %d microseconds late\n",
|
||||
(int)(av_gettime() - last_frame_time - per_frame));
|
||||
(int)(av_gettime_relative() - last_frame_time - per_frame));
|
||||
}
|
||||
}
|
||||
nsignals = 0;
|
||||
|
|
|
@ -157,11 +157,11 @@ static int fbdev_read_packet(AVFormatContext *avctx, AVPacket *pkt)
|
|||
uint8_t *pin, *pout;
|
||||
|
||||
if (fbdev->time_frame == AV_NOPTS_VALUE)
|
||||
fbdev->time_frame = av_gettime();
|
||||
fbdev->time_frame = av_gettime_relative();
|
||||
|
||||
/* wait based on the frame rate */
|
||||
while (1) {
|
||||
curtime = av_gettime();
|
||||
curtime = av_gettime_relative();
|
||||
delay = fbdev->time_frame - curtime;
|
||||
av_log(avctx, AV_LOG_TRACE,
|
||||
"time_frame:%"PRId64" curtime:%"PRId64" delay:%"PRId64"\n",
|
||||
|
@ -186,7 +186,7 @@ static int fbdev_read_packet(AVFormatContext *avctx, AVPacket *pkt)
|
|||
"Error refreshing variable info: %s\n", av_err2str(AVERROR(errno)));
|
||||
}
|
||||
|
||||
pkt->pts = curtime;
|
||||
pkt->pts = av_gettime();
|
||||
|
||||
/* compute visible data offset */
|
||||
pin = fbdev->data + fbdev->bytes_per_pixel * fbdev->varinfo.xoffset +
|
||||
|
|
|
@ -394,7 +394,7 @@ gdigrab_read_header(AVFormatContext *s1)
|
|||
gdigrab->header_size = sizeof(BITMAPFILEHEADER) + sizeof(BITMAPINFOHEADER) +
|
||||
(bpp <= 8 ? (1 << bpp) : 0) * sizeof(RGBQUAD) /* palette size */;
|
||||
gdigrab->time_base = av_inv_q(gdigrab->framerate);
|
||||
gdigrab->time_frame = av_gettime() / av_q2d(gdigrab->time_base);
|
||||
gdigrab->time_frame = av_gettime_relative() / av_q2d(gdigrab->time_base);
|
||||
|
||||
gdigrab->hwnd = hwnd;
|
||||
gdigrab->source_hdc = source_hdc;
|
||||
|
@ -551,7 +551,7 @@ static int gdigrab_read_packet(AVFormatContext *s1, AVPacket *pkt)
|
|||
|
||||
/* wait based on the frame rate */
|
||||
for (;;) {
|
||||
curtime = av_gettime();
|
||||
curtime = av_gettime_relative();
|
||||
delay = time_frame * av_q2d(time_base) - curtime;
|
||||
if (delay <= 0) {
|
||||
if (delay < INT64_C(-1000000) * av_q2d(time_base)) {
|
||||
|
@ -568,7 +568,7 @@ static int gdigrab_read_packet(AVFormatContext *s1, AVPacket *pkt)
|
|||
|
||||
if (av_new_packet(pkt, file_size) < 0)
|
||||
return AVERROR(ENOMEM);
|
||||
pkt->pts = curtime;
|
||||
pkt->pts = av_gettime();
|
||||
|
||||
/* Blit screen grab */
|
||||
if (!BitBlt(dest_hdc, 0, 0,
|
||||
|
|
|
@ -268,7 +268,7 @@ static int kmsgrab_read_packet(AVFormatContext *avctx, AVPacket *pkt)
|
|||
int64_t now;
|
||||
int err;
|
||||
|
||||
now = av_gettime();
|
||||
now = av_gettime_relative();
|
||||
if (ctx->frame_last) {
|
||||
int64_t delay;
|
||||
while (1) {
|
||||
|
@ -276,10 +276,11 @@ static int kmsgrab_read_packet(AVFormatContext *avctx, AVPacket *pkt)
|
|||
if (delay <= 0)
|
||||
break;
|
||||
av_usleep(delay);
|
||||
now = av_gettime();
|
||||
now = av_gettime_relative();
|
||||
}
|
||||
}
|
||||
ctx->frame_last = now;
|
||||
now = av_gettime();
|
||||
|
||||
plane = drmModeGetPlane(ctx->hwctx->fd, ctx->plane_id);
|
||||
if (!plane) {
|
||||
|
|
|
@ -206,7 +206,7 @@ static int64_t wait_frame(AVFormatContext *s, AVPacket *pkt)
|
|||
c->time_frame += c->frame_duration;
|
||||
|
||||
for (;;) {
|
||||
curtime = av_gettime();
|
||||
curtime = av_gettime_relative();
|
||||
delay = c->time_frame - curtime;
|
||||
if (delay <= 0)
|
||||
break;
|
||||
|
@ -422,7 +422,8 @@ static int xcbgrab_read_packet(AVFormatContext *s, AVPacket *pkt)
|
|||
int ret = 0;
|
||||
int64_t pts;
|
||||
|
||||
pts = wait_frame(s, pkt);
|
||||
wait_frame(s, pkt);
|
||||
pts = av_gettime();
|
||||
|
||||
if (c->follow_mouse || c->draw_mouse) {
|
||||
pc = xcb_query_pointer(c->conn, c->screen->root);
|
||||
|
@ -596,7 +597,7 @@ static int create_stream(AVFormatContext *s)
|
|||
c->time_base = (AVRational){ st->avg_frame_rate.den,
|
||||
st->avg_frame_rate.num };
|
||||
c->frame_duration = av_rescale_q(1, c->time_base, AV_TIME_BASE_Q);
|
||||
c->time_frame = av_gettime();
|
||||
c->time_frame = av_gettime_relative();
|
||||
|
||||
ret = pixfmt_from_pixmap_format(s, geo->depth, &st->codecpar->format, &c->bpp);
|
||||
free(geo);
|
||||
|
|
Loading…
Reference in New Issue