summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2020-08-22 20:43:15 +0200
committerwm4 <wm4@nowhere>2020-08-22 20:43:15 +0200
commitc06577e291aaf598981be2b0c3999ea04da31d82 (patch)
treebd3641a03803135cec897e7369b6a570d135b0f9
parentb3758db128fd732358a45a4719e01558a0f4bf1b (diff)
downloadmpv-c06577e291aaf598981be2b0c3999ea04da31d82.tar.bz2
mpv-c06577e291aaf598981be2b0c3999ea04da31d82.tar.xz
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.
-rw-r--r--player/playloop.c5
1 files changed, 5 insertions, 0 deletions
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);