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

Launching hyprnotify on hyprland start causes System to loose Audio #2

Open
LukasLichten opened this issue Jun 9, 2024 · 4 comments
Labels
bug Something isn't working

Comments

@LukasLichten
Copy link

LukasLichten commented Jun 9, 2024

After starting into Hyprland I had no Audio from, anything.
Pavucontrol (and software like Discord/Vesktop) show no input device and only dumy output.

Except notifications still play a sound, and when I killed hyprnotify it restore sound immediatly.
Launching hyprnotify through a terminal will result in Audio being retained, sort of, as the audio starts glitching, notifications are not reliable.

My guess this is Hyprnotify is taking over the Audio device. I am kind of too tired right now to tired to look into the code or even triage further for today.
I have pipewire-pulse and alsa-lib installed, I feel like that could be the culprit.

PS: As a workaround hyprnotify --silent works

@codelif
Copy link
Owner

codelif commented Jun 11, 2024

Sorry for the late reply, I am kinda busy in exams stuff.

I could replicate your issue on Fedora and ArchLinux with pipewire-pulse. The issue is not present with pulseaudio. I currently suspect it is either due a misconfiguration on my part when setting up beep (the audio library I use), or an issue with beep itself.

I am not familiar with audio stuff, so I won't be able to help with the latter. As for the former, I will try some configurations if I find free time. I am unfortunately preoccupied with exams till the 26th this month.

If you want to hack on it yourself, I will give some context below:

The audio setup is present in internal/audio.go.
An audio file is present in internal/audio/ which is packed along with the binary.

On startup, if --silent flag is not present, the InitSpeaker function is called in internal/dbus.go (line 202). This function sets up the audio driver.

After initial setup,
On every notification request, the server runs the function PlayAudio (present in audio.go, called from dbus.go(line 110)) in a goroutine. PlayAudio reads the audio file, plays the audio and then returns.

Side note: I have realized recently that beep provides an option to buffer an audio file instead of reading it every time the function is called. However I don't think this matters much because the audio file is packed with the binary in a virtual file system, so it is loaded in memory anyway.

@codelif codelif added the bug Something isn't working label Jun 20, 2024
@LukasLichten
Copy link
Author

LukasLichten commented Jun 21, 2024

I have been on and off poking at this problem for the past couple days, and have somewhat solved it.

It can work

When I downloaded the code and ran it I noticed that it... work? It threw some errors, but worked, showing up in the mixer and everything, and so did the packaged version too.
So I rebooted and it didn't work anymore.

After a bunch of trial and error I was able to distill it down to a certain sequence:

  • Start Hyprland without hyprnotify (or in silent, but kill it later)
  • Do playback for a bit, for example VLC (I don't know, but without it the chance of failure increases)
  • Launch hyprnotify

If successful (and launched in terminal instead of hyprctl disptach) you will get:
ALSA lib pcm_dmix.c:1000:(snd_pcm_dmix_open) unable to open slave logged twice.
Also you will see PipeWire ALSA [hyprnotify]: ALSA Playback in pavu (and sounds will play on notifications).
If it was not successful, nothing will show in the terminal or mixer, and no sounds will be played on notifications. Most of the time the rest of the audio will still be fine, on other runs some pops occur, but it won't take over the Audio system like launched at the start. To retry you at minimum have to restart Hyprland, probably best to reboot.

The error message does not give much of a hint, the error is associated with audio not working, not with it suddenly working. The message does give the precise line in alsa-lib, but that one doesn't give much of a hint either...

Installing pipewire-alsa

Getting nowhere I thought "huh, lets retry with a different sound system", but reading package lists in pacman I noticed I didn't have pipewire-alsa installed (I did have pipewire-jack and pipewire-pulse already installed).

One reboot later and now hyprnotify reliably shows up in pavu (with the same name as above).
It would be nice if the only thing left was to discuss how to package/inform users that they need pipewire-alsa also installed if running pipewire... but unfortunately no, we are not done...

On the first Hyprland after boot it will show up alright, but it has suddenly become shy and is just not emitting any sound.
Restarting Hyprland and once software has finished launching you try to notify-send and it returns the dreaded freedesktop error as hyprnotify has somehow died quietly (most of the time this is the outcome).
Third time it will finally stick and work as expected.

Although I have from time to time, even when running it silently, experienced hyprnotify just not running anymore, just checking in on it randomly and it had died. I have now attached the output to a file, maybe it will snitch what is causing this

@codelif
Copy link
Owner

codelif commented Jul 3, 2024

Thanks for your investigation. I recently tried reproducing the bug but couldn't. I only have pipewire-pulse installed still.

Try out this patch or directly try the branch pipewire-fix.

If this doesn't work I will try switching to portaudio

@codelif
Copy link
Owner

codelif commented Jul 3, 2024

Also, could you share more details on hyprnotify randomly dying even with --silent? I haven't seen that one before.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants