summaryrefslogtreecommitdiffstats
path: root/player
diff options
context:
space:
mode:
authorDudemanguy <random342@airmail.cc>2025-02-16 18:15:49 -0600
committerDudemanguy <random342@airmail.cc>2025-02-20 15:50:03 +0000
commit25a0c8307d9302ec4add2f5a8cc07ec2a9934290 (patch)
treefda49b32979ef8b1e9b9571710ff218bad1ad75d /player
parent723da77defac599f13b4a70962f4aac54aa5a64a (diff)
downloadmpv-25a0c8307d9302ec4add2f5a8cc07ec2a9934290.tar.bz2
mpv-25a0c8307d9302ec4add2f5a8cc07ec2a9934290.tar.xz
player: add an optional mute flag when framestepping
Need to shuffle some stuff around but it's pretty simple. Mute the audio stream before the frame step and then unmute it when we're done. It's exactly the same as the default play mode otherwise.
Diffstat (limited to 'player')
-rw-r--r--player/audio.c17
-rw-r--r--player/command.c11
-rw-r--r--player/core.h2
-rw-r--r--player/playloop.c9
-rw-r--r--player/video.c4
5 files changed, 32 insertions, 11 deletions
diff --git a/player/audio.c b/player/audio.c
index a5606d5e48..9d91c25f5a 100644
--- a/player/audio.c
+++ b/player/audio.c
@@ -170,21 +170,26 @@ static float compute_replaygain(struct MPContext *mpctx)
return rgain;
}
-// Called when opts->softvol_volume or opts->softvol_mute were changed.
-void audio_update_volume(struct MPContext *mpctx)
+float audio_get_gain(struct MPContext *mpctx)
{
struct MPOpts *opts = mpctx->opts;
- struct ao_chain *ao_c = mpctx->ao_chain;
- if (!ao_c || !ao_c->ao)
- return;
-
float gain = MPMAX(opts->softvol_volume / 100.0, 0);
gain = pow(gain, 3);
gain *= compute_replaygain(mpctx);
gain *= db_gain(opts->softvol_gain);
if (opts->softvol_mute)
gain = 0.0;
+ return gain;
+}
+
+// Called when opts->softvol_volume or opts->softvol_mute were changed.
+void audio_update_volume(struct MPContext *mpctx)
+{
+ struct ao_chain *ao_c = mpctx->ao_chain;
+ if (!ao_c || !ao_c->ao)
+ return;
+ float gain = audio_get_gain(mpctx);
ao_set_gain(ao_c->ao, gain);
}
diff --git a/player/command.c b/player/command.c
index 5f5675f442..0b21bd5112 100644
--- a/player/command.c
+++ b/player/command.c
@@ -5731,18 +5731,20 @@ static void cmd_frame_step(void *p)
return;
}
- if (flags) {
+ if (flags == 1) {
if (!cmd->cmd->is_up)
- add_step_frame(mpctx, frames, flags);
+ add_step_frame(mpctx, frames, true);
} else {
if (cmd->cmd->is_up) {
if (mpctx->step_frames < 1)
set_pause_state(mpctx, true);
} else {
+ if (flags == 2)
+ step_frame_mute(mpctx, true);
if (cmd->cmd->repeated) {
set_pause_state(mpctx, false);
} else {
- add_step_frame(mpctx, frames, flags);
+ add_step_frame(mpctx, frames, false);
}
}
}
@@ -7038,7 +7040,8 @@ const struct mp_cmd_def mp_cmds[] = {
{"frames", OPT_INT(v.i), OPTDEF_INT(1)},
{"flags", OPT_CHOICE(v.i,
{"play", 0},
- {"seek", 1}),
+ {"seek", 1},
+ {"mute", 2}),
.flags = MP_CMD_OPT_ARG},
},
.allow_auto_repeat = true,
diff --git a/player/core.h b/player/core.h
index 7500471f2f..b1b6c5f935 100644
--- a/player/core.h
+++ b/player/core.h
@@ -506,6 +506,7 @@ void update_playback_speed(struct MPContext *mpctx);
void uninit_audio_out(struct MPContext *mpctx);
void uninit_audio_chain(struct MPContext *mpctx);
void reinit_audio_chain_src(struct MPContext *mpctx, struct track *track);
+float audio_get_gain(struct MPContext *mpctx);
void audio_update_volume(struct MPContext *mpctx);
void reload_audio_output(struct MPContext *mpctx);
void audio_start_ao(struct MPContext *mpctx);
@@ -607,6 +608,7 @@ void set_pause_state(struct MPContext *mpctx, bool user_pause);
void update_internal_pause_state(struct MPContext *mpctx);
void update_core_idle_state(struct MPContext *mpctx);
void add_step_frame(struct MPContext *mpctx, int dir, bool use_seek);
+void step_frame_mute(struct MPContext *mpctx, bool mute);
void queue_seek(struct MPContext *mpctx, enum seek_type type, double amount,
enum seek_precision exact, int flags);
double get_time_length(struct MPContext *mpctx);
diff --git a/player/playloop.c b/player/playloop.c
index bae9c85803..f61cf3a1ff 100644
--- a/player/playloop.c
+++ b/player/playloop.c
@@ -226,6 +226,15 @@ void add_step_frame(struct MPContext *mpctx, int dir, bool use_seek)
}
}
+void step_frame_mute(struct MPContext *mpctx, bool mute)
+{
+ if (!mpctx->ao_chain || !mpctx->ao_chain->ao)
+ return;
+
+ float gain = mute ? 0 : audio_get_gain(mpctx);
+ ao_set_gain(mpctx->ao_chain->ao, gain);
+}
+
// Clear some playback-related fields on file loading or after seeks.
void reset_playback_state(struct MPContext *mpctx)
{
diff --git a/player/video.c b/player/video.c
index 35ddc632e7..a47c6dc359 100644
--- a/player/video.c
+++ b/player/video.c
@@ -1294,8 +1294,10 @@ void write_video(struct MPContext *mpctx)
if (mpctx->video_status != STATUS_EOF) {
if (mpctx->step_frames > 0) {
mpctx->step_frames--;
- if (!mpctx->step_frames)
+ if (!mpctx->step_frames) {
set_pause_state(mpctx, true);
+ step_frame_mute(mpctx, false);
+ }
}
if (mpctx->max_frames == 0 && !mpctx->stop_play)
mpctx->stop_play = AT_END_OF_FILE;