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.
This commit is contained in:
wm4 2020-08-22 20:43:15 +02:00
parent b3758db128
commit c06577e291
1 changed files with 5 additions and 0 deletions

View File

@ -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);