Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Muting is delayed with ao_avfoundation #15014

Open
6 tasks done
MarioMastr opened this issue Oct 7, 2024 · 3 comments
Open
6 tasks done

Muting is delayed with ao_avfoundation #15014

MarioMastr opened this issue Oct 7, 2024 · 3 comments

Comments

@MarioMastr
Copy link

mpv Information

mpv 0.39.0 Copyright © 2000-2024 mpv/MPlayer/mplayer2 projects
libplacebo version: v7.349.0
FFmpeg version: 7.1
FFmpeg library versions:
   libavcodec      61.3.100 (runtime 61.19.100)
   libavdevice     61.1.100 (runtime 61.3.100)
   libavfilter     10.1.100 (runtime 10.4.100)
   libavformat     61.1.100 (runtime 61.7.100)
   libavutil       59.8.100 (runtime 59.39.100)
   libswresample   5.1.100 (runtime 5.3.100)
   libswscale      8.1.100 (runtime 8.3.100)

Other Information

- macOS version: Sequoia 15.0.1
- Source of mpv: Homebrew
- Introduced in version: 0.39.0

Reproduction Steps

Play any video with --no-config --ao=avfoundation and toggle mute (either by using the keybind or using the menu bar).

Expected Behavior

Same behaviour as ao_coreaudio, which mutes as soon as toggled.

Actual Behavior

It takes at least a second to actually mute the audio.

Log File

output.txt

Sample Files

No response

I carefully read all instruction and confirm that I did the following:

  • I tested with the latest mpv version to validate that the issue is not already fixed.
  • I provided all required information including system and mpv version.
  • I produced the log file with the exact same set of files, parameters, and conditions used in "Reproduction Steps", with the addition of --log-file=output.txt.
  • I produced the log file while the behaviors described in "Actual Behavior" were actively observed.
  • I attached the full, untruncated log file.
  • I attached the backtrace in the case of a crash.
@Akemi
Copy link
Member

Akemi commented Oct 7, 2024

@ruihe774 mentioning you, in the case you didn't see this issue.

@ruihe774
Copy link
Contributor

ruihe774 commented Oct 7, 2024

No easy fix I'm afraid. Surely we can clear ao buffer on softvol mute:

diff --git a/player/audio.c b/player/audio.c
index e86547c30e..229458da4d 100644
--- a/player/audio.c
+++ b/player/audio.c
@@ -186,6 +186,11 @@ void audio_update_volume(struct MPContext *mpctx)
         gain = 0.0;
 
     ao_set_gain(ao_c->ao, gain);
+
+    if (opts->softvol_mute) {
+        ao_reset(ao_c->ao);
+        ao_start(ao_c->ao);
+    }
 }
 
 // Call this if opts->playback_speed or mpctx->speed_factor_* change.

But this it bound to cause some AV desync.

FWIW this is not a problem specific to ao_avfoundation; all pull-based AOs have this issue if they are used with large device buffers.

For now, a simple workaround is not to use softvol mute but to use ao mute instead; ao_avfoundation works well with ao volume and ao mute with no issues that were encountered in other AOs; I don't think there are reasons not to use them. Simply put this config into your input.conf (or put some similar config into other places if you are not using keybindings to toggle mute):

m cycle ao-mute

# if you also want to use ao volume, add and uncomment these as well:
# WHEEL_UP      add ao-volume 2 
# WHEEL_DOWN    add ao-volume -2

Some AOs (e.g. pipewire) remember ao volume and ao mute even after mpv quits. If you want to prevent this behavior, you can use the following lua script. This does not apply to ao_avfoundation as it does not remember.

mp.register_event("audio-reconfig", function()
    mp.set_property_number("ao-volume", 100)
    mp.set_property_bool("ao-mute", false)  
end)

@ruihe774
Copy link
Contributor

@MarioMastr @low-batt I've added a new option --avfoundation-buffer in #14058. Setting it to a lower value can make the AO reacts quicker; though lower value may lead to underruns. You can have a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants