History

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.

Dudemanguy committed 1 year ago

Commit 25a0c831 parent 723da777 files · +36 −11Browse files

Unified · Split

7 files
  1. DOCS/interface-changes/frame-step.txt +1 −0
  2. DOCS/man/input.rst +3 −0
  3. player/audio.c +11 −6
  4. player/command.c +7 −4
  5. player/core.h +2 −0
  6. player/playloop.c +9 −0
  7. player/video.c +3 −1
DOCS/interface-changes/frame-step.txt+1−0
@@ -1 +1,2 @@
11 - add optional `frames` and `flags` arguments to `frame-step` command controlling the direction and amount of frames mpv steps through
2+- add optional `mute` flag to `frame-step` command which mutes the player during the duration of the frame step
DOCS/man/input.rst+3−0
@@ -370,6 +370,9 @@ Playback Control · 369 unmodified lines
370370 Perform a very exact seek that attempts to seek by the desired amount
371371 of frames. If ``<frames>`` is ``-1``, this will go exactly to the
372372 previous frame.
373+ mute
374+ The same as ``play`` but mutes the audio stream if there is any during
375+ the duration of the frame step.
373376
374377 Note that the default frameskip mode, play, is more accurate but can be
375378 slow depending on how many frames you are skipping (i.e. skipping forward
player/audio.c+11−6
@@ -170,21 +170,26 @@ static float compute_replaygain(struct MPContext *mpctx) · 169 unmodified lines
170170 return rgain;
171171 }
172172
173−// Called when opts->softvol_volume or opts->softvol_mute were changed.
174−void audio_update_volume(struct MPContext *mpctx)
173+float audio_get_gain(struct MPContext *mpctx)
175174 {
176175 struct MPOpts *opts = mpctx->opts;
177− struct ao_chain *ao_c = mpctx->ao_chain;
178− if (!ao_c || !ao_c->ao)
179− return;
180−
181176 float gain = MPMAX(opts->softvol_volume / 100.0, 0);
182177 gain = pow(gain, 3);
183178 gain *= compute_replaygain(mpctx);
184179 gain *= db_gain(opts->softvol_gain);
185180 if (opts->softvol_mute)
186181 gain = 0.0;
182+ return gain;
183+}
184+
185+// Called when opts->softvol_volume or opts->softvol_mute were changed.
186+void audio_update_volume(struct MPContext *mpctx)
187+{
188+ struct ao_chain *ao_c = mpctx->ao_chain;
189+ if (!ao_c || !ao_c->ao)
190+ return;
187191
192+ float gain = audio_get_gain(mpctx);
188193 ao_set_gain(ao_c->ao, gain);
189194 }
190195
player/command.c+7−4
@@ -5731,18 +5731,20 @@ static void cmd_frame_step(void *p) · 5730 unmodified lines
57315731 return;
57325732 }
57335733
5734− if (flags) {
5734+ if (flags == 1) {
57355735 if (!cmd->cmd->is_up)
5736− add_step_frame(mpctx, frames, flags);
5736+ add_step_frame(mpctx, frames, true);
57375737 } else {
57385738 if (cmd->cmd->is_up) {
57395739 if (mpctx->step_frames < 1)
57405740 set_pause_state(mpctx, true);
57415741 } else {
5742+ if (flags == 2)
5743+ step_frame_mute(mpctx, true);
57425744 if (cmd->cmd->repeated) {
57435745 set_pause_state(mpctx, false);
57445746 } else {
5745− add_step_frame(mpctx, frames, flags);
5747+ add_step_frame(mpctx, frames, false);
57465748 }
57475749 }
57485750 }
@@ -7038,7 +7040,8 @@ const struct mp_cmd_def mp_cmds[] = { · 1289 unmodified lines
70387040 {"frames", OPT_INT(v.i), OPTDEF_INT(1)},
70397041 {"flags", OPT_CHOICE(v.i,
70407042 {"play", 0},
7041− {"seek", 1}),
7043+ {"seek", 1},
7044+ {"mute", 2}),
70427045 .flags = MP_CMD_OPT_ARG},
70437046 },
70447047 .allow_auto_repeat = true,
player/core.h+2−0
@@ -506,6 +506,7 @@ void update_playback_speed(struct MPContext *mpctx); · 505 unmodified lines
506506 void uninit_audio_out(struct MPContext *mpctx);
507507 void uninit_audio_chain(struct MPContext *mpctx);
508508 void reinit_audio_chain_src(struct MPContext *mpctx, struct track *track);
509+float audio_get_gain(struct MPContext *mpctx);
509510 void audio_update_volume(struct MPContext *mpctx);
510511 void reload_audio_output(struct MPContext *mpctx);
511512 void audio_start_ao(struct MPContext *mpctx);
@@ -607,6 +608,7 @@ void set_pause_state(struct MPContext *mpctx, bool user_pause); · 95 unmodified lines
607608 void update_internal_pause_state(struct MPContext *mpctx);
608609 void update_core_idle_state(struct MPContext *mpctx);
609610 void add_step_frame(struct MPContext *mpctx, int dir, bool use_seek);
611+void step_frame_mute(struct MPContext *mpctx, bool mute);
610612 void queue_seek(struct MPContext *mpctx, enum seek_type type, double amount,
611613 enum seek_precision exact, int flags);
612614 double get_time_length(struct MPContext *mpctx);
player/playloop.c+9−0
@@ -226,6 +226,15 @@ void add_step_frame(struct MPContext *mpctx, int dir, bool use_seek) · 225 unmodified lines
226226 }
227227 }
228228
229+void step_frame_mute(struct MPContext *mpctx, bool mute)
230+{
231+ if (!mpctx->ao_chain || !mpctx->ao_chain->ao)
232+ return;
233+
234+ float gain = mute ? 0 : audio_get_gain(mpctx);
235+ ao_set_gain(mpctx->ao_chain->ao, gain);
236+}
237+
229238 // Clear some playback-related fields on file loading or after seeks.
230239 void reset_playback_state(struct MPContext *mpctx)
231240 {
player/video.c+3−1
@@ -1294,8 +1294,10 @@ void write_video(struct MPContext *mpctx) · 1293 unmodified lines
12941294 if (mpctx->video_status != STATUS_EOF) {
12951295 if (mpctx->step_frames > 0) {
12961296 mpctx->step_frames--;
1297− if (!mpctx->step_frames)
1297+ if (!mpctx->step_frames) {
12981298 set_pause_state(mpctx, true);
1299+ step_frame_mute(mpctx, false);
1300+ }
12991301 }
13001302 if (mpctx->max_frames == 0 && !mpctx->stop_play)
13011303 mpctx->stop_play = AT_END_OF_FILE;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t