command: add drop_buffers

This command was actually requested on IRC ages ago, but I forgot about
it.

The main purpose is that the decoding state can be reset without issuing
a seek, in particular in situations where you can't seek.

This restarts decoding from the middle of the packet stream; since it
discards the packet buffer intentionally, and the decoder will typically
not output "incomplete" frames until it has recovered, it can skip a
large amount of data.

It doesn't clear the byte stream cache - I'm not sure if it should.
This commit is contained in:
wm4 2014-11-20 22:41:50 +01:00
parent 7df909e9fc
commit 2d039e691f
4 changed files with 18 additions and 0 deletions

View File

@ -556,6 +556,10 @@ Input Commands that are Possibly Subject to Change
those which can will be reset even if they don't appear in the argument.
This command might be changed or removed in the future.
``drop_buffers``
Drop audio/video/demuxer buffers, and restart from fresh. Might help with
unseekable streams that are going out of sync.
This command might be changed or removed in the future.
Undocumented commands: ``tv_last_channel`` (TV/DVB only), ``get_property`` (?),
``ao_reload`` (experimental/internal).

View File

@ -157,6 +157,8 @@ const struct mp_cmd_def mp_cmds[] = {
{ MP_CMD_AB_LOOP, "ab_loop", },
{ MP_CMD_DROP_BUFFERS, "drop_buffers", },
{ MP_CMD_AF, "af", { ARG_STRING, ARG_STRING } },
{ MP_CMD_AO_RELOAD, "ao_reload", },

View File

@ -80,6 +80,8 @@ enum mp_command_type {
MP_CMD_AB_LOOP,
MP_CMD_DROP_BUFFERS,
/// Audio Filter commands
MP_CMD_AF,
MP_CMD_AO_RELOAD,

View File

@ -4440,6 +4440,16 @@ int run_command(MPContext *mpctx, mp_cmd_t *cmd)
return r > 0;
}
case MP_CMD_DROP_BUFFERS: {
reset_audio_state(mpctx);
reset_video_state(mpctx);
if (mpctx->demuxer)
demux_flush(mpctx->demuxer);
break;
}
case MP_CMD_VO_CMDLINE:
if (mpctx->video_out) {
char *s = cmd->args[0].v.s;