mirror of
https://github.com/mpv-player/mpv
synced 2025-03-01 11:50:48 +00:00
core: simplify handling of --pause
Rename the struct MPOpts "start_pause" field to "pause". Store the user- pause state in that field, so that both runtime pause toggling and the --pause switch change the same variable. Simplify the initialization of pause so that using --pause and changing the file while paused is exactly the same case (changing the file while paused doesn't unpause, this has been always this way). Also make it a bit more consistent. Before, starting with --pause would reset the pause state for every file, instead of following the usual semantics for option switches (compare with behavior of --fs).
This commit is contained in:
parent
e1fccfdcd8
commit
3765cfcf57
@ -352,7 +352,7 @@ const m_option_t common_opts[] = {
|
||||
OPT_REL_TIME("end", play_end, 0),
|
||||
OPT_REL_TIME("length", play_length, 0),
|
||||
|
||||
OPT_FLAG("pause", start_paused, 0),
|
||||
OPT_FLAG("pause", pause, 0),
|
||||
OPT_FLAG("keep-open", keep_open, 0),
|
||||
|
||||
// AVI specific: force non-interleaved mode
|
||||
|
@ -518,19 +518,15 @@ static int mp_property_pause(m_option_t *prop, int action, void *arg,
|
||||
{
|
||||
MPContext *mpctx = ctx;
|
||||
|
||||
switch (action) {
|
||||
case M_PROPERTY_SET:
|
||||
if (action == M_PROPERTY_SET) {
|
||||
if (*(int *)arg) {
|
||||
pause_player(mpctx);
|
||||
} else {
|
||||
unpause_player(mpctx);
|
||||
}
|
||||
return M_PROPERTY_OK;
|
||||
case M_PROPERTY_GET:
|
||||
*(int *)arg = mpctx->paused_user;
|
||||
return M_PROPERTY_OK;
|
||||
}
|
||||
return M_PROPERTY_NOT_IMPLEMENTED;
|
||||
return mp_property_generic_option(prop, action, arg, ctx);
|
||||
}
|
||||
|
||||
static int mp_property_cache(m_option_t *prop, int action, void *arg,
|
||||
@ -1365,8 +1361,7 @@ static const m_option_t mp_properties[] = {
|
||||
CONF_RANGE, -2, 10, NULL },
|
||||
{ "metadata", mp_property_metadata, CONF_TYPE_STRING_LIST,
|
||||
0, 0, 0, NULL },
|
||||
{ "pause", mp_property_pause, CONF_TYPE_FLAG,
|
||||
M_OPT_RANGE, 0, 1, NULL },
|
||||
M_OPTION_PROPERTY_CUSTOM("pause", mp_property_pause),
|
||||
{ "cache", mp_property_cache, CONF_TYPE_INT },
|
||||
M_OPTION_PROPERTY("pts-association-mode"),
|
||||
M_OPTION_PROPERTY("hr-seek"),
|
||||
@ -2303,7 +2298,7 @@ void run_command(MPContext *mpctx, mp_cmd_t *cmd)
|
||||
pause_player(mpctx);
|
||||
break;
|
||||
case 3: // "pausing_toggle"
|
||||
if (mpctx->paused_user)
|
||||
if (opts->pause)
|
||||
unpause_player(mpctx);
|
||||
else
|
||||
pause_player(mpctx);
|
||||
|
@ -265,14 +265,14 @@ typedef struct MPContext {
|
||||
int last_dvb_step;
|
||||
int dvbin_reopen;
|
||||
|
||||
int paused;
|
||||
bool paused;
|
||||
// step this many frames, then pause
|
||||
int step_frames;
|
||||
// Counted down each frame, stop playback if 0 is reached. (-1 = disable)
|
||||
int max_frames;
|
||||
bool playing_msg_shown;
|
||||
|
||||
bool paused_for_cache, paused_user;
|
||||
bool paused_for_cache;
|
||||
|
||||
// Set after showing warning about decoding being too slow for realtime
|
||||
// playback rate. Used to avoid showing it multiple times.
|
||||
|
@ -1065,7 +1065,7 @@ static void print_status(struct MPContext *mpctx)
|
||||
char *line = NULL;
|
||||
|
||||
// Playback status
|
||||
if (mpctx->paused_for_cache && !mpctx->paused_user) {
|
||||
if (mpctx->paused_for_cache && !opts->pause) {
|
||||
saddf(&line, "(Buffering) ");
|
||||
} else if (mpctx->paused) {
|
||||
saddf(&line, "(Paused) ");
|
||||
@ -1429,7 +1429,7 @@ static void sadd_osd_status(char **buffer, struct MPContext *mpctx, bool full)
|
||||
bool fractions = mpctx->opts.osd_fractions;
|
||||
int sym = mpctx->osd_function;
|
||||
if (!sym) {
|
||||
if (mpctx->paused_for_cache && !mpctx->paused_user) {
|
||||
if (mpctx->paused_for_cache && !mpctx->opts.pause) {
|
||||
sym = OSD_CLOCK;
|
||||
} else if (mpctx->paused || mpctx->step_frames) {
|
||||
sym = OSD_PAUSE;
|
||||
@ -2638,11 +2638,11 @@ static double update_video(struct MPContext *mpctx, double endpts)
|
||||
|
||||
void pause_player(struct MPContext *mpctx)
|
||||
{
|
||||
mpctx->paused_user = true;
|
||||
mpctx->opts.pause = 1;
|
||||
|
||||
if (mpctx->paused)
|
||||
return;
|
||||
mpctx->paused = 1;
|
||||
mpctx->paused = true;
|
||||
mpctx->step_frames = 0;
|
||||
mpctx->time_frame -= get_relative_time(mpctx);
|
||||
mpctx->osd_function = 0;
|
||||
@ -2664,14 +2664,14 @@ void pause_player(struct MPContext *mpctx)
|
||||
|
||||
void unpause_player(struct MPContext *mpctx)
|
||||
{
|
||||
mpctx->paused_user = false;
|
||||
mpctx->opts.pause = 0;
|
||||
|
||||
if (!mpctx->paused)
|
||||
return;
|
||||
// Don't actually unpause while cache is loading.
|
||||
if (mpctx->paused_for_cache)
|
||||
return;
|
||||
mpctx->paused = 0;
|
||||
mpctx->paused = false;
|
||||
mpctx->osd_function = 0;
|
||||
|
||||
if (mpctx->ao && mpctx->sh_audio)
|
||||
@ -3201,15 +3201,15 @@ static void handle_pause_on_low_cache(struct MPContext *mpctx)
|
||||
if (mpctx->paused && mpctx->paused_for_cache) {
|
||||
if (cache < 0 || cache >= opts->stream_cache_min_percent || idle) {
|
||||
mpctx->paused_for_cache = false;
|
||||
if (!mpctx->paused_user)
|
||||
if (!opts->pause)
|
||||
unpause_player(mpctx);
|
||||
}
|
||||
} else {
|
||||
if (cache >= 0 && cache <= opts->stream_cache_pause && !idle) {
|
||||
bool prev_paused_user = mpctx->paused_user;
|
||||
bool prev_paused_user = opts->pause;
|
||||
pause_player(mpctx);
|
||||
mpctx->paused_for_cache = true;
|
||||
mpctx->paused_user = prev_paused_user;
|
||||
opts->pause = prev_paused_user;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4238,6 +4238,8 @@ goto_enable_cache: ;
|
||||
mpctx->total_avsync_change = 0;
|
||||
mpctx->last_chapter_seek = -2;
|
||||
mpctx->playing_msg_shown = false;
|
||||
mpctx->paused = false;
|
||||
mpctx->paused_for_cache = false;
|
||||
|
||||
// If there's a timeline force an absolute seek to initialize state
|
||||
double startpos = rel_time_to_abs(mpctx, opts->play_start, -1);
|
||||
@ -4257,14 +4259,7 @@ goto_enable_cache: ;
|
||||
mpctx->seek = (struct seek_params){ 0 };
|
||||
get_relative_time(mpctx); // reset current delta
|
||||
|
||||
mpctx->paused = mpctx->paused_user;
|
||||
mpctx->paused_for_cache = false;
|
||||
// Make sure VO knows current pause state
|
||||
if (mpctx->sh_video)
|
||||
vo_control(mpctx->video_out,
|
||||
mpctx->paused ? VOCTRL_PAUSE : VOCTRL_RESUME, NULL);
|
||||
|
||||
if (mpctx->opts.start_paused)
|
||||
if (mpctx->opts.pause)
|
||||
pause_player(mpctx);
|
||||
|
||||
while (!mpctx->stop_play)
|
||||
@ -4285,7 +4280,7 @@ goto_enable_cache: ;
|
||||
terminate_playback: // don't jump here after ao/vo/getch initialization!
|
||||
|
||||
if (mpctx->step_frames)
|
||||
mpctx->paused = 1;
|
||||
opts->pause = 1;
|
||||
|
||||
mp_msg(MSGT_CPLAYER, MSGL_INFO, "\n");
|
||||
|
||||
|
@ -125,7 +125,7 @@ typedef struct MPOpts {
|
||||
int play_frames;
|
||||
double step_sec;
|
||||
int64_t seek_to_byte;
|
||||
int start_paused;
|
||||
int pause;
|
||||
int keep_open;
|
||||
int audio_id;
|
||||
int video_id;
|
||||
|
Loading…
Reference in New Issue
Block a user