Adobe-Runtime-Support icon indicating copy to clipboard operation
Adobe-Runtime-Support copied to clipboard

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

Open itlancer opened this issue 1 year ago • 2 comments

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: https://github.com/airsdk/Adobe-Runtime-Support/issues/3450 https://github.com/airsdk/Adobe-Runtime-Support/issues/1984 https://github.com/airsdk/Adobe-Runtime-Support/issues/365 https://github.com/airsdk/Adobe-Runtime-Support/issues/224 https://github.com/airsdk/Adobe-Runtime-Support/issues/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 https://github.com/airsdk/Adobe-Runtime-Support/issues/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.

itlancer avatar Sep 07 '24 21:09 itlancer

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

ajwfrost avatar Sep 16 '24 09:09 ajwfrost

@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.

itlancer avatar Sep 20 '24 18:09 itlancer

@ajwfrost, issue still exists with latest AIR 51.2.2.6. And right now it happens even without sudo usage. After AudioDeviceManager.audioDeviceManager.deviceNames call audio playback stop working. Sometimes it could works if you trying to use audio-jack output. But using Ubuntu 24.04 with HDMI output (TV/monitor with speakers) - no sound in any case.

itlancer avatar Nov 24 '25 15:11 itlancer