From c06577e291aaf598981be2b0c3999ea04da31d82 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 22 Aug 2020 20:43:15 +0200 Subject: player: do not loop if there's nothing to loop This can happen if a file contains headers only, or if decoding of all data failed, and such. Interestingly, it also happened when doing "mpv --loop emptyfile.png", because demux_mf still detects file formats by file extension. In this situation, the player burned a lot of CPU by restarting playback after doing nothing. Although such "degenerate" behavior can't be avoided in all situations (what if you loop a file with 1 audio sample?), detecting this seems to make sense. For now, this actually decrements the loop count by 1, and then errors out with a warning. Works for --loop and --ab-loop, while --loop-playlist already avoids this situation with an existing mechanism. --- player/playloop.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/player/playloop.c b/player/playloop.c index 01ad5e63c6..f5c13abe7b 100644 --- a/player/playloop.c +++ b/player/playloop.c @@ -894,6 +894,11 @@ static void handle_loop_file(struct MPContext *mpctx) } if (target != MP_NOPTS_VALUE) { + if (!mpctx->shown_aframes && !mpctx->shown_vframes) { + MP_WARN(mpctx, "No media data to loop.\n"); + return; + } + mpctx->stop_play = KEEP_PLAYING; set_osd_function(mpctx, OSD_FFW); mark_seek(mpctx); -- cgit v1.2.3