JFLib

plat/linux_audio.rs (Linux)#

Source: lib/plat/linux_audio.rs

linux_audio -- (audio.rs) sound through a PulseAudio server (pipewire-pulse on current
desktops, WSLg's server), one connection and thread per stream; the freedesktop sound theme

  open(feed, name) -> Dev   the thread connects (linux_pulse.rs), creates a playback stream
                            (float32le, the stream's rate and channels, tlength =
                            Core::dev_ms, ADJUST_LATENCY, no device named: the server's
                            default -- the server moves the stream when the default changes)
                            and answers the server's REQUESTs from the Feed; open waits for
                            that first answer (no server: Unavailable)
  the loop                  poll on the socket and an eventfd (kicks): pause = CORK, start =
                            uncork, stop() = cork + FLUSH, the end = DRAIN (its reply: Ended,
                            corked again); GET_PLAYBACK_LATENCY every 250 ms while playing
                            (the sink's latency + what the server holds); PLAYBACK_STREAM_MOVED:
                            the new device's name, device_changes(); UNDERFLOW counts; a killed
                            stream or a lost connection: State::Lost, reconnected every second
  system_sound(kind)        org.gnome.desktop.sound from the settings portal: event-sounds off
                            -> nothing; theme-name (else freedesktop) with its Inherits=, the
                            names dialog-information / -warning / -error / -question, bell,
                            message-new-instant (and fallbacks) as .disabled / .oga / .ogg /
                            .wav in the theme's Directories= (else stereo) below
                            $XDG_DATA_HOME/sounds and $XDG_DATA_DIRS/sounds; decoded once,
                            played through play(); no file: None (audio.rs plays a tone)
                            (jfgui_SOUND_THEME, jfgui_EVENT_SOUNDS=0|1 override the portal)

ALSA (/dev/snd) is not used: without a sound server there is no output (Unavailable).
  • struct ServerStream (tests) a playback stream as the PulseAudio server lists it

    • index: u32 -- the sink input (Stream::server_id)
    • name: String
    • sink: u32
    • rate: u32
    • channels: u8
    • buffer_us: u64 -- what the server holds and the sink's latency (microseconds)
    • sink_us: u64
    • corked: bool
    • props: Vec<(String, String)>
  • fn server_streams() -> Option<Vec<ServerStream>> (tests) the server's playback streams (GET_SINK_INPUT_INFO_LIST on a connection of its own)

  • fn server_info() -> Option<(String, String, String)> (tests) the server: (its name, its version, the default sink)

  • fn pulse_selftest() -> Vec<(&'static str, bool)> (tests) the wire format against hand-made bytes -> (check, passed)

Source: docs/API.md in the JFLib repository.