1
mirror of https://github.com/mpv-player/mpv synced 2024-11-14 22:48:35 +01:00

command: do not exit playback if the B point of A-B loop is past EOF

The previous behavior is confusing if the B point is near EOF (consider
B being the duration of the file, which is strictly speaking past the
last video timestamp). The new behavior is fine as well for B being far
past EOF.

Achieve this by checking the EOF state in addition to whether playback
has reached the B point. Also, move the A-B loop code out of
command_event(). It just isn't useful anymore, and obfuscates the code
more than it makes it loop simple.

Fixes #2046.
This commit is contained in:
wm4 2015-06-16 23:11:14 +02:00
parent dbdc46c97a
commit 72808be6f8
3 changed files with 25 additions and 18 deletions

View File

@ -4903,30 +4903,12 @@ void command_init(struct MPContext *mpctx)
static void command_event(struct MPContext *mpctx, int event, void *arg)
{
struct command_ctx *ctx = mpctx->command_ctx;
struct MPOpts *opts = mpctx->opts;
if (event == MPV_EVENT_START_FILE) {
ctx->last_seek_pts = MP_NOPTS_VALUE;
ctx->marked_pts = MP_NOPTS_VALUE;
}
if (event == MPV_EVENT_TICK) {
double now =
mpctx->restart_complete ? mpctx->playback_pts : MP_NOPTS_VALUE;
if (now != MP_NOPTS_VALUE && opts->ab_loop[0] != MP_NOPTS_VALUE &&
opts->ab_loop[1] != MP_NOPTS_VALUE)
{
if (ctx->prev_pts >= opts->ab_loop[0] &&
ctx->prev_pts < opts->ab_loop[1] &&
now >= opts->ab_loop[1])
{
mark_seek(mpctx);
queue_seek(mpctx, MPSEEK_ABSOLUTE, opts->ab_loop[0],
MPSEEK_EXACT, false);
}
}
ctx->prev_pts = now;
}
if (event == MPV_EVENT_SEEK)
ctx->prev_pts = MP_NOPTS_VALUE;
if (event == MPV_EVENT_IDLE)
@ -4939,6 +4921,27 @@ static void command_event(struct MPContext *mpctx, int event, void *arg)
}
}
void handle_ab_loop(struct MPContext *mpctx)
{
struct command_ctx *ctx = mpctx->command_ctx;
struct MPOpts *opts = mpctx->opts;
double now = mpctx->restart_complete ? mpctx->playback_pts : MP_NOPTS_VALUE;
if (now != MP_NOPTS_VALUE && opts->ab_loop[0] != MP_NOPTS_VALUE &&
opts->ab_loop[1] != MP_NOPTS_VALUE)
{
if (ctx->prev_pts >= opts->ab_loop[0] &&
ctx->prev_pts < opts->ab_loop[1] &&
(now >= opts->ab_loop[1] || mpctx->stop_play == AT_END_OF_FILE))
{
mark_seek(mpctx);
queue_seek(mpctx, MPSEEK_ABSOLUTE, opts->ab_loop[0],
MPSEEK_EXACT, false);
}
}
ctx->prev_pts = now;
}
void handle_command_updates(struct MPContext *mpctx)
{
struct command_ctx *ctx = mpctx->command_ctx;

View File

@ -54,4 +54,6 @@ enum {
bool mp_hook_test_completion(struct MPContext *mpctx, char *type);
void mp_hook_run(struct MPContext *mpctx, char *client, char *type);
void handle_ab_loop(struct MPContext *mpctx);
#endif /* MPLAYER_COMMAND_H */

View File

@ -1043,6 +1043,8 @@ void run_playloop(struct MPContext *mpctx)
handle_loop_file(mpctx);
handle_ab_loop(mpctx);
handle_keep_open(mpctx);
handle_sstep(mpctx);