>From 9657b4d069d6c39d866dc9ec641a7c30cf4fa566 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Sat, 8 Jan 2011 10:07:25 +0100 Subject: [PATCH] Factorize code checking if we are at the end. --- mplayer.c | 32 ++++++++++++++++++++++---------- 1 files changed, 22 insertions(+), 10 deletions(-) diff --git a/mplayer.c b/mplayer.c index 3de123f..80dfe92 100644 --- a/mplayer.c +++ b/mplayer.c @@ -2679,6 +2679,21 @@ static int seek(MPContext *mpctx, double amount, int style) return 0; } +static int is_at_end(MPContext *mpctx) +{ + switch (end_at.type) { + case END_AT_TIME: + if (mpctx->sh_audio) + return playing_audio_pts(mpctx->sh_audio, mpctx->d_audio, + mpctx->audio_out) >= end_at.pos; + else if (mpctx->sh_video) + return mpctx->sh_video->pts >= end_at.pos; + case END_AT_SIZE: + return stream_tell(mpctx->stream) >= end_at.pos; + } + return 0; +} + /* This preprocessor directive is a hack to generate a mplayer-nomain.o object * file for some tools to link against. */ #ifndef DISABLE_MAIN @@ -3694,14 +3709,13 @@ if(!mpctx->sh_video) { double a_pos=0; // sh_audio can be NULL due to video stream switching // TODO: handle this better - if((!quiet || end_at.type == END_AT_TIME) && mpctx->sh_audio) - a_pos = playing_audio_pts(mpctx->sh_audio, mpctx->d_audio, mpctx->audio_out); - - if(!quiet) - print_status(a_pos, 0, 0); + if (!quiet) { + if (mpctx->sh_audio) + a_pos = playing_audio_pts(mpctx->sh_audio, mpctx->d_audio, mpctx->audio_out); + print_status(a_pos, 0, 0); + } - if(end_at.type == END_AT_TIME && end_at.pos < a_pos || - end_at.type == END_AT_SIZE && end_at.pos < stream_tell(mpctx->stream)) + if (is_at_end(mpctx)) mpctx->eof = PT_NEXT_ENTRY; update_subtitles(NULL, a_pos, mpctx->d_sub, 0); update_osd_msg(); @@ -3809,9 +3823,7 @@ if(auto_quality>0){ if (play_n_frames <= 0) mpctx->eof = PT_NEXT_ENTRY; } - if (!frame_time_remaining && - ((end_at.type == END_AT_TIME && mpctx->sh_video->pts >= end_at.pos) || - (end_at.type == END_AT_SIZE && stream_tell(mpctx->stream) >= end_at.pos))) + if (!frame_time_remaining && is_at_end(mpctx)) mpctx->eof = PT_NEXT_ENTRY; } // end if(mpctx->sh_video) -- 1.7.3.5