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

[Linux] No sound under sudo after AudioDeviceManager.audioDeviceManager.deviceNames call #3452

Open
itlancer opened this issue Sep 7, 2024 · 2 comments
Labels

Comments

@itlancer
Copy link

itlancer commented Sep 7, 2024

Problem Description

No sound can be played after AudioDeviceManager.audioDeviceManager.deviceNames call when AIR application run under sudo with Linux.
Sometimes multimedia applications should be run with root privileges (for example when autostart enabled). That's why it is crucial.
Same issues with Video with audio playback too, with NetStream::appendBytes() and with M4A audio playback via NetStream.

Tested with multiple AIR versions, even with latest AIR 51.1.1.3 with multiple different Linux x86_64 devices (VM and real), different OS versions and different applications.
There is no such issue without sudo.
There is no such issue using aplay.
There is no such issue with other platforms.

Related issues:
#3450
#1984
#365
#224
#15

Steps to Reproduce

Launch application with code below with any Linux under sudo:
sudo -E ./linux_audiodevicemanager_sound_root_bug
Note: parameter -E mandatory cause #3450
It should generate audio via Sound.

Application example with sources sample attached.
linux_audiodevicemanager_sound_root_bug.zip

package {
	import flash.display.Sprite;
	import flash.events.SampleDataEvent;
	import flash.media.AudioDeviceManager;
	import flash.media.Sound;
	
	public class LinuxAudioDeviceManagerSoundRootBug extends Sprite {
		
		public function LinuxAudioDeviceManagerSoundRootBug() {
			trace(AudioDeviceManager.audioDeviceManager.deviceNames);//Sound doesn't work after this line
			var generatedSound:Sound = new Sound();
			generatedSound.addEventListener(SampleDataEvent.SAMPLE_DATA, sineWaveGenerator);
			generatedSound.play();
		}
		
		private function sineWaveGenerator(e:SampleDataEvent):void {
			//Generate any sound
			var noteFreq:Number = 261.63 / 2;
			for (var i:int = 0; i < 8192; i++) {
				var n:Number = Math.sin((i+e.position)*noteFreq*2.0*Math.PI/44100.0);
				e.data.writeFloat(n);
			}
		}
	}
}

Actual Result:
No audio played. No exceptions or errors in Scout.
In terminal you will see:

XDG_RUNTIME_DIR (/run/user/1000) is not owned by us (uid 0), but by uid 1000! (This could e.g. happen if you try to connect to a non-root PulseAudio as a root user, over the native protocol. Don't do that.)

XDG_RUNTIME_DIR (/run/user/1000) is not owned by us (uid 0), but by uid 1000! (This could e.g. happen if you try to connect to a non-root PulseAudio as a root user, over the native protocol. Don't do that.)

Expected Result:
Audio will be played.

Known Workarounds

Don't use AudioDeviceManager.audioDeviceManager.deviceNames.

@ajwfrost
Copy link
Collaborator

Hi

These audio issues, when trying to run AIR as root, appear to be caused by the fact that AIR on Linux is using PulseAudio, and per the above messages, this may not be set up to work for a 'root' client.

The best workaround might be to set up your PulseAudio system to run as root or to allow root connections. e.g. try:
sudo pulseaudio -D
We get the result:

W: [pulseaudio] main.c: This program is not intended to be run as root (unless --system is specified).

So maybe if you can change the Linux machine to allow PulseAudio to run as root, or to allow connections from a root process, this could then work?

See also https://www.reddit.com/r/linux_gaming/comments/5tidzc/a_solution_for_pulseaudio_pa_context_connect/
https://forums.raspberrypi.com/viewtopic.php?t=340709

@itlancer
Copy link
Author

@ajwfrost
Thank you for suggestions!
Unfortunately it doesn't work with Ubuntu 24 cause seems it use Pipewire instead of PulseAudio right now by default. I didn't found the way to workaround it still via machine configuration.

But for other Linux under root sound issues (not related to AudioDeviceManager.audioDeviceManager.deviceNames) it could be avoided by launching via sudo -E or passing XDG_RUNTIME_DIR (as mentioned in workarounds).
Even with latest Ubuntu 24.

I will try to research Ubuntu 24 with Pipewire more and also check suggestions with Ubuntu 22 or below.

But specifically for current issue main problem is that audio stop working at all if AIR application under root call AudioDeviceManager.audioDeviceManager.deviceNames for Linux.

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

No branches or pull requests

2 participants