PulseAudio Configuration Example(s) for OpenWRT

Wiki.TerraBase.info
Jump to navigation Jump to search

Stupefying OpenWRT Configuration

Burying the Lede: remove --disallow-module-loading from the command line start parameter for PulseAudio in /etc/inid.d/pulseaudio

The default configuration in the /etc/init.d/pulseaudio 'start script' makes it impossible for the 'BlueZ' software to add BlueTooth Speakers. Why? Not a clue. Wait! Let's ask ChatGPT;

What would the effect / affect be on BlueTooth Audio if PulseAudio's init.d startup script had this directive?: --disallow-module-loading

Speculate why that would be added to PulseAudio's init.d startup script and explain what would happen to a system's ability to play audio through BlueTooth Speakers.

Effect on Bluetooth Audio:

The --disallow-module-loading flag can have significant consequences on Bluetooth audio, as PulseAudio often dynamically loads modules related to Bluetooth support during runtime. For example, PulseAudio uses the module-bluetooth-discover to handle Bluetooth devices like A2DP sinks (for streaming audio) and HSP/HFP (for hands-free profiles).

If --disallow-module-loading is enabled, PulseAudio will not be able to load any Bluetooth-related modules, effectively disabling Bluetooth audio functionality. This means:
Bluetooth devices (headphones, speakers, etc.) that rely on PulseAudio to manage A2DP or HSP profiles would not be usable.

If someone tries to manually load a Bluetooth module after PulseAudio has started (e.g., using pactl load-module), it will fail because dynamic module loading is disabled.
Speculation on Why Someone Would Use This for Bluetooth:
System Configuration Control: In some specialized environments (e.g., headless systems, embedded devices, or systems that should not handle Bluetooth audio), disabling Bluetooth audio might be a desired action. By using --disallow-module-loading, you ensure that no Bluetooth modules are loaded at startup or after startup.

Prevent Unwanted Audio Connections: In environments where only certain audio outputs are allowed (e.g., using a dedicated audio interface or a fixed set of speakers), disallowing module loading might prevent accidental or unwanted use of Bluetooth audio devices.
Security Reasons: As mentioned, controlling what modules can be loaded might be part of a security strategy to prevent rogue or insecure Bluetooth devices from being accessed via PulseAudio.

The OpenWRT developer that made that decision is clinically insane (or just made an innocent, simple mistake). It is equivalent to unplugging a network cable to keep a server secure. Yes it is secure, but also useless. See the insanity of it?

Solution: remove --disallow-module-loading from /etc/inid.d/pulseaudio


Example 3 (Mature);

#!/usr/bin/pulseaudio -nF

###     /usr/bin/pulseaudio --system --disallow-exit --disable-shm --exit-idle-time=-1 -vvvvvv --log-level=debug --log-target=stderr

######################################################################################################################
load-module module-device-restore
load-module module-stream-restore
load-module module-card-restore
load-module module-switch-on-port-available
load-module module-switch-on-connect

load-module module-default-device-restore
load-module module-always-sink
load-module module-intended-roles
load-module module-position-event-sounds
load-module module-role-cork
load-module module-filter-heuristics
load-module module-filter-apply

### module-http-protocol provides a very, very rudimentary 'report' on PulseAudio Configuration at http://WhatEverIPAddress:4714
load-module module-http-protocol-tcp

### module-native-protocol is what the PACTL Command uses to communicate with the pulseaudio Daemon (Without it, this error occurs: pa_context_connect() failed: Connection refused)
### MPD / MPC also rely on the module-native-protocol-unix Module
load-module module-native-protocol-unix

### The below "protocol tcp / unix" and "cli" are similar to the above item, but only module-native-protocol-unix makes pactl happy
#load-module module-native-protocol-tcp
#load-module module-cli-protocol-tcp
#load-module module-cli-protocol-unix
#load-module module-simple-protocol-unix
#load-module module-simple-protocol-tcp
#load-module module-cli

### module-augment-properties appears to attempt to load a file named .desktop (possibly related to MPD and PulseAudio???)
### load-module module-augment-properties
######################################################################################################################



######################################################################################################################
### The below item works great for automatic detection, but it also prevents custom device= Directives from working
### load-module module-detect
######################################################################################################################



######################################################################################################################
## load-module module-alsa-sink sink_name=alsa_output.0.analog-stereo
## load-module module-alsa-sink device=hw:0,0 sink_name=alsa_output.0.analog-stereo
### Message for future me: Instead of referring to the device=hw:0,0, if it were done using DMIX?
### Note: Tried the ALL strategy
### ...and did try using the alsa_output_ALL, but didn't work
######################################################################################################################



######################################################################################################################
###
### "Simulated" 7.1 (8 Channel) Surround Sound [Using the Surround Sound Capability now]
###
### 
### 
### 
### 
### Below are the three Directives needed for CMedia 6206 based devices with MPD as the 'Input / Source' (with the associated settings in /etc/mpd.conf);
### load-module module-alsa-sink device=surround71:CARD=ICUSBAUDIO7D,0 sink_name=alsa_output.0.surround.71 channels=8 channel_map=front-left,front-right,rear-left,rear-right,center,lfe,side-left,side-right
### load-module module-null-sink sink_name=CMedia6206
### load-module module-loopback source=CMedia6206.monitor sink=alsa_output.0.surround.71
###
### Below is the "Generic Version" of the Alsa Sink Module that will work with both the CMedia and RealTEK Devices (NOTE: It is the 5.1 Surround, as 7.1 is BROKEN with CMedia);
### NOTE: the sink_name has been kept as 71 (instead of 51) so the Loopback Module works
### ...still working on this: load-module module-alsa-sink device=surround51 sink_name=alsa_output.0.surround.71 channels=6 channel_map=front-left,front-right,rear-left,rear-right,center,lfe

### Below is the ONLY Directive needed for the Cubilink CA7 USB Audio Device with MPD as the 'Input / Source' (with the associated settings in /etc/mpd.conf);
#######load-module module-alsa-sink device=surround71:CARD=CA7,0 sink_name=alsa_output.0.surround.71 channels=8 channel_map=front-left,front-right,rear-left,rear-right,center,lfe,side-left,side-right

### Below are the Directives needed for the Cubilink CA7 USB Audio Device with the Line In (or Microphone) Jack as the 'Input / Source';
### NOTE: CMedia 6206 based devices and 7.1 Surround Sound and module-loopback are BROKEN and will produce an endless stream of: "I: [alsa-sink-USB Audio] module-loopback.c: Adding 123 usec of silence to queue" (MPD will still function)
######load-module module-alsa-source device=hw:0,0 source_name=alsa_input.0.analog-stereo
######load-module module-loopback source=alsa_input.0.analog-stereo sink=alsa_output.0.surround.71 latency_msec=800
######################################################################################################################





######################################################################################################################
###
### Input from Line Jack (or Microphone, depending on "restore" or ALSAMIXER Settings.
###
#load-module module-alsa-source device=hw:0,0 source_name=alsa_input.0.analog-stereo

### NOTE: By leaving off the device= Setting, it seems to cause the module-detect Module to be implicitly loaded (IE, no other above module-alsa-sink Directives will work)
# load-module module-alsa-sink device=CSUB sink_name=alsa_output.0.analog-stereo

### NOTE: The module-alsa-source Module must be loaded before module-loopback
### NOTE: Make sure the source= Directive matches the module-alsa-source Module sink-name= Setting
### NOTE: latency_msec= canNOT be set to 0 (zero)
#load-module module-loopback source=alsa_input.0.analog-stereo sink=alsa_output.0.analog-stereo latency_msec=10
#load-module module-loopback source=alsa_input.0.analog-stereo sink=alsa_output_CSUB latency_msec=10
######################################################################################################################




######################################################################################################################
###
### Bluetooth;
###
### NOTE: There needs to be an entry in /etc/mpd.conf that matches the name of the sink= Directive
### Either one of the below will work (notice the latency, that in testing worked to sync the bluetooth and direct line out)
## This is the most basic one.  The above load-module module-alsa-sink device=hw:0,0 sink_name=alsa_output.0.analog-stereo AND load-module module-alsa-source device=hw:0,0 source_name=alsa_input.0.analog-stereo are needed for this one.
## Note: If playing from the 'local' MPD Daemon, there is no need for the below sink!
## load-module module-loopback source=alsa_input.0.analog-stereo sink=alsa_output.0.analog-stereo latency_msec=0

##load-module module-loopback source=alsa_input.0.analog-stereo sink=remapped-surround51 latency_msec=800

######################################################################################################################


###### Trying to get MPD and Line In to work with both local and RTP
### Route Line In/Mic input to the local speakers (surround) and RTP sink
# load-module module-loopback source=alsa_input.0.analog-stereo sink=alsa_output.0.surround.71 latency_msec=10
# load-module module-loopback source=alsa_input.0.analog-stereo sink=rtp_sink





######################################################################################################################
###
### RTP
###


### The below item enables RTP Send output ONLY from the MIC or Line IN as a Source (does not allow MPD to output to RTP Receive Clients)
######load-module module-rtp-send source=alsa_input.0.analog-stereo source_ip=192.168.2.45 port=6666 destination_ip=192.168.2.46
######load-module module-rtp-send source=alsa_input.0.analog-stereo source_ip=192.168.2.45 port=6666 destination_ip=192.168.2.24

### The below two items are needed to enable MPD to ouput to a remote RTP Receive Client via a "Combined" Module (see below)
######load-module module-null-sink sink_name=rtp_sink
######load-module module-rtp-send source=rtp_sink.monitor source_ip=192.168.2.45 port=6666 destination_ip=192.168.2.46


### ...OR, the following three items;
### load-module module-null-sink sink_name=rtp format=s16be channels=2 rate=44100 sink_properties="device.description='RTP Monitor Sink'"
### load-module module-loopback source=alsa_input.0.analog-stereo sink=rtp
### load-module module-loopback source=rtp.monitor sink=alsa_output.0.analog-stereo
###
### For "receiving"
load-module module-rtp-recv sap_address=0.0.0.0
######################################################################################################################



###### load-module module-native-protocol-tcp auth-anonymous=1


### The below Combine Module (along with the above RTP Send lines) allows for output to both local Speakers and remote RTP Clients
######load-module module-combine-sink sink_name=combined slaves=alsa_output.0.surround.71,rtp_sink




#load-module module-loopback source=module-rtp-recv.c sink=alsa_output.0.analog-stereo




#load-module module-loopback source=alsa_input.0.analog-stereo sink=alsa_output.0.analog-stereo.monitor





###...the below works, but with latency.

### I think asound.conf might be the answer to creating one device that contains both audio devices

###  Otherwise, it will need to go rtp -> Null Sink --> Monitor for Null Sink -> output(s)

#load-module module-detect
load-module module-alsa-sink device=hw:0,0 sink_name=alsa_output.0.analog-stereo
load-module module-alsa-sink device=hw:1,0 sink_name=alsa_output.1.analog-stereo
load-module module-loopback source=alsa_output.1.analog-stereo.monitor sink=alsa_output.0.analog-stereo

Example 2 (Mid-Life);


Example 2 (Early);

#!/usr/bin/pulseaudio -nF


# This startup script is used only if PulseAudio is started in system
# mode.

### OK, for module-loopback no configuration is necessary, if...;
###
### By default PulseAudio will detect an Alsa Source with the module-alsa-source
###
### If there is only one sound device, nothing needs to be configured in /etc/asound.conf
###
###
###
###
###
###
###
###
###
### ...oh, and it sounds better than if done this way (IE, use mono over stereo): pactl load-module module-loopback source=alsa_input.0.analog-stereo sink=bluez_sink.B3_55_35_2F_CC_56.a2dp_sink



### Automatically restore the volume of streams and devices
load-module module-device-restore
load-module module-stream-restore
load-module module-card-restore

### Automatically augment property information from .desktop files
### stored in /usr/share/application
load-module module-augment-properties

### Should be after module-*-restore but before module-*-detect
load-module module-switch-on-port-available

load-module module-switch-on-connect

### Load audio drivers statically
### (it's probably better to not load these drivers manually, but instead
### use module-udev-detect -- see below -- for doing this automatically)
#load-module module-alsa-sink
#load-module module-alsa-source device=hw:1,0
#load-module module-oss device="/dev/dsp" sink_name=output source_name=input
#load-module module-oss-mmap device="/dev/dsp" sink_name=output source_name=input
#load-module module-null-sink
#load-module module-pipe-sink

### Automatically load driver modules depending on the hardware available
.ifexists module-detect.so
### Use the static hardware detection module (for systems that lack udev support)
load-module module-detect
.endif

### Automatically connect sink and source if JACK server is present
.ifexists module-jackdbus-detect.so
.nofail
load-module module-jackdbus-detect channels=2
.fail
.endif

### Automatically load driver modules for Bluetooth hardware
.ifexists module-bluetooth-policy.so
load-module module-bluetooth-policy
.endif

.ifexists module-bluetooth-discover.so
load-module module-bluetooth-discover
.endif

### Load several protocols
.ifexists module-esound-protocol-unix.so
load-module module-esound-protocol-unix
.endif
load-module module-native-protocol-unix

### Network access (may be configured with paprefs, so leave this commented
### here if you plan to use paprefs)
#load-module module-esound-protocol-tcp
#load-module module-native-protocol-tcp

### Holy fuck me christ, the TCP module isn't even necessary for remote connectivity, only the RTP Module!
###load-module module-native-protocol-tcp auth-ip-acl=W.X.Y.Z/24
###load-module module-native-protocol-tcp auth-ip-acl=W.X.Y.Z
load-module module-native-protocol-tcp auth-anonymous=1

#load-module module-zeroconf-publish















### Load the RTP receiver module (also configured via paprefs, see above)
### latency_msec=10 can be messed around with
### sap_address=0.0.0.0 seems to turn off multicast mode, thus allowing destination_ip to work on the server.
### On the server: Setting Multicast IP: Ensure destination_ip is a valid multicast address.  Multicast IP addresses range from 224.0.0.0 to 239.255.255.255.

### load-module module-tunnel-source server=W.X.Y.Z source_name=tunnel_source




load-module module-rtp-recv sap_address=0.0.0.0















### Load the RTP sender module (also configured via paprefs, see above)
#load-module module-null-sink sink_name=rtp format=s16be channels=2 rate=44100 sink_properties="device.description='RTP Multicast Sink'"
#load-module module-rtp-send source=rtp.monitor



### Automatically restore the default sink/source when changed by the user
### during runtime
### NOTE: This should be loaded as early as possible so that subsequent modules
### that look up the default sink/source get the right value
load-module module-default-device-restore

### Make sure we always have a sink around, even if it is a null sink.
load-module module-always-sink

### Honour intended role device property
load-module module-intended-roles

### Automatically suspend sinks/sources that become idle for too long
###### load-module module-suspend-on-idle

### If autoexit on idle is enabled we want to make sure we only quit
### when no local session needs us anymore.
##.ifexists module-console-kit.so
##load-module module-console-kit
##.endif
.ifexists module-systemd-login.so
load-module module-systemd-login
.endif

### Enable positioned event sounds
load-module module-position-event-sounds

### Cork music/video streams when a phone stream is active
load-module module-role-cork

### Modules to allow autoloading of filters (such as echo cancellation)
### on demand. module-filter-heuristics tries to determine what filters
### make sense, and module-filter-apply does the heavy-lifting of
### loading modules and rerouting streams.
load-module module-filter-heuristics
load-module module-filter-apply



### Needs an HRIR .WAV file as an example or something;
###load-module module-virtual-surround-sink sink_name=virtual_surround
### pactl load-module module-loopback source=virtual_surround.monitor sink=bluez_sink.FC_58_FA_2E_BA_7C.a2dp_sink


### load-module module-loopback source=alsa_input.0.analog-stereo sink=bluez_sink.B3_55_35_2F_CC_56.a2dp_sink



### load-module module-role-ducking


#######################load-module module-loopback
#set-default-source tunnel_source




# pactl info for configuration information;




####set-default-sink output alsa_output.0.analog-stereo
###set-default-sink alsa_output.0.analog-stereo

### set-default-sink bluez_sink.B3_55_35_2F_CC_56.a2dp_sink



### For the small USB Audio Device with an output and input;
###
### The below is the default source noted by: pactl list sources short
###


### Can be used, but watch out as it will override other sources (like network sources)
###set-default-source alsa_input.0.mono-fallback
### set-default-sink bluez_sink.B3_55_35_2F_CC_56.a2dp_sink

### To combine output(s), but won't work with OpenWRT Bluetooth as the sinks disappear!
### load-module module-combine-sink sink_name=HyperBooms slaves="bluez_sink.EC_81_93_FD_D5_A5.a2dp_sink","bluez_sink.EC_81_93_FD_D4_DC.a2dp_sink"
###load-module module-combine-sink sink_name=combined sink_properties=device.description=Combined slaves=bluez_sink.EC_81_93_FD_D4_DC.a2dp_sink,bluez_sink.EC_81_93_FD_D5_A5.a2dp_sink
###pactl set-default-sink combined


### See the /etc/bluetooth.sh and /etc/init.d/pulseaudio file for the module-combine-sink Settings for the Hyperbooms