[FFmpeg-devel] [PATCH 3/6] ffplay: Use av_gettime_relative()

Michael Niedermayer michaelni at gmx.at
Sat May 17 21:11:45 CEST 2014


On Sat, May 17, 2014 at 07:31:26PM +0200, Marton Balint wrote:
> 
> On Tue, 6 May 2014, Olivier Langlois wrote:
> 
> >Whenever av_gettime() is used to measure relative period of time,
> >av_gettime_relative() is prefered as it guarantee monotonic time
> >on supported platforms.
> >
> >Signed-off-by: Olivier Langlois <olivier at trillion01.com>
> >---
> >ffplay.c | 26 +++++++++++++-------------
> >1 file changed, 13 insertions(+), 13 deletions(-)
> >
> >diff --git a/ffplay.c b/ffplay.c
> >index 86b9126..54b1ca8 100644
> >--- a/ffplay.c
> >+++ b/ffplay.c
> >@@ -899,7 +899,7 @@ static void video_audio_display(VideoState *s)
> >        /* to be more precise, we take into account the time spent since
> >           the last buffer computation */
> >        if (audio_callback_time) {
> >-            time_diff = av_gettime() - audio_callback_time;
> >+            time_diff = av_gettime_relative() - audio_callback_time;
> >            delay -= (time_diff * s->audio_tgt.freq) / 1000000;
> >        }
> >
> >@@ -1132,7 +1132,7 @@ static double get_clock(Clock *c)
> >    if (c->paused) {
> >        return c->pts;
> >    } else {
> >-        double time = av_gettime() / 1000000.0;
> >+        double time = av_gettime_relative() / 1000000.0;
> >        return c->pts_drift + time - (time - c->last_updated) * (1.0 - c->speed);
> >    }
> >}
> >@@ -1147,7 +1147,7 @@ static void set_clock_at(Clock *c, double pts, int serial, double time)
> >
> >static void set_clock(Clock *c, double pts, int serial)
> >{
> >-    double time = av_gettime() / 1000000.0;
> >+    double time = av_gettime_relative() / 1000000.0;
> >    set_clock_at(c, pts, serial, time);
> >}
> >
> >@@ -1240,7 +1240,7 @@ static void stream_seek(VideoState *is, int64_t pos, int64_t rel, int seek_by_by
> >static void stream_toggle_pause(VideoState *is)
> >{
> >    if (is->paused) {
> >-        is->frame_timer += av_gettime() / 1000000.0 + is->vidclk.pts_drift - is->vidclk.pts;
> >+        is->frame_timer += av_gettime_relative() / 1000000.0 + is->vidclk.pts_drift - is->vidclk.pts;
> >        if (is->read_pause_return != AVERROR(ENOSYS)) {
> >            is->vidclk.paused = 0;
> >        }
> >@@ -1355,7 +1355,7 @@ static void video_refresh(void *opaque, double *remaining_time)
> >        check_external_clock_speed(is);
> >
> >    if (!display_disable && is->show_mode != SHOW_MODE_VIDEO && is->audio_st) {
> >-        time = av_gettime() / 1000000.0;
> >+        time = av_gettime_relative() / 1000000.0;
> >        if (is->force_refresh || is->last_vis_time + rdftspeed < time) {
> >            video_display(is);
> >            is->last_vis_time = time;
> >@@ -1386,7 +1386,7 @@ retry:
> >            }
> >
> >            if (lastvp->serial != vp->serial && !redisplay)
> >-                is->frame_timer = av_gettime() / 1000000.0;
> >+                is->frame_timer = av_gettime_relative() / 1000000.0;
> >
> >            if (is->paused)
> >                goto display;
> >@@ -1398,7 +1398,7 @@ retry:
> >            else
> >                delay = compute_target_delay(last_duration, is);
> >
> >-            time= av_gettime()/1000000.0;
> >+            time= av_gettime_relative()/1000000.0;
> >            if (time < is->frame_timer + delay && !redisplay) {
> >                *remaining_time = FFMIN(is->frame_timer + delay - time, *remaining_time);
> >                return;
> >@@ -1472,7 +1472,7 @@ display:
> >        int aqsize, vqsize, sqsize;
> >        double av_diff;
> >
> >-        cur_time = av_gettime();
> >+        cur_time = av_gettime_relative();
> >        if (!last_time || (cur_time - last_time) >= 30000) {
> >            aqsize = 0;
> >            vqsize = 0;
> >@@ -1967,7 +1967,7 @@ static int video_thread(void *arg)
> >            goto the_end;
> >
> >        while (ret >= 0) {
> >-            is->frame_last_returned_time = av_gettime() / 1000000.0;
> >+            is->frame_last_returned_time = av_gettime_relative() / 1000000.0;
> >
> >            ret = av_buffersink_get_frame_flags(filt_out, frame, 0);
> >            if (ret < 0) {
> >@@ -1977,7 +1977,7 @@ static int video_thread(void *arg)
> >                break;
> >            }
> >
> >-            is->frame_last_filter_delay = av_gettime() / 1000000.0 - is->frame_last_returned_time;
> >+            is->frame_last_filter_delay = av_gettime_relative() / 1000000.0 - is->frame_last_returned_time;
> >            if (fabs(is->frame_last_filter_delay) > AV_NOSYNC_THRESHOLD / 10.0)
> >                is->frame_last_filter_delay = 0;
> >            tb = filt_out->inputs[0]->time_base;
> >@@ -2378,7 +2378,7 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
> >    VideoState *is = opaque;
> >    int audio_size, len1;
> >
> >-    audio_callback_time = av_gettime();
> >+    audio_callback_time = av_gettime_relative();
> >
> >    while (len > 0) {
> >        if (is->audio_buf_index >= is->audio_buf_size) {
> >@@ -3164,7 +3164,7 @@ static void refresh_loop_wait_event(VideoState *is, SDL_Event *event) {
> >    double remaining_time = 0.0;
> >    SDL_PumpEvents();
> >    while (!SDL_PeepEvents(event, 1, SDL_GETEVENT, SDL_ALLEVENTS)) {
> >-        if (!cursor_hidden && av_gettime() - cursor_last_shown > CURSOR_HIDE_DELAY) {
> >+        if (!cursor_hidden && av_gettime_relative() - cursor_last_shown > CURSOR_HIDE_DELAY) {
> >            SDL_ShowCursor(0);
> >            cursor_hidden = 1;
> >        }
> >@@ -3318,7 +3318,7 @@ static void event_loop(VideoState *cur_stream)
> >                SDL_ShowCursor(1);
> >                cursor_hidden = 0;
> >            }
> >-            cursor_last_shown = av_gettime();
> >+            cursor_last_shown = av_gettime_relative();
> >            if (event.type == SDL_MOUSEBUTTONDOWN) {
> >                x = event.button.x;
> >            } else {
> >-- 
> >1.9.2
> >
> 
> LGTM, thanks.


applied

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Awnsering whenever a program halts or runs forever is
On a turing machine, in general impossible (turings halting problem).
On any real computer, always possible as a real computer has a finite number
of states N, and will either halt in less than N cycles or never halt.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: Digital signature
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20140517/7d735ce2/attachment.asc>


More information about the ffmpeg-devel mailing list