Documentation
¶
Overview ¶
Package pulse is the audio service, the Go port of crates/wayle-audio: sinks, sources, and per-application streams kept live from PulseAudio's subscription events, the default devices, per-channel volume and mute, ports, stream routing, and record streams, all over the native protocol (package native), so it works against PulseAudio and pipewire-pulse alike with no libpulse.
Index ¶
- Constants
- Variables
- type AudioFormat
- type AudioStream
- type Capture
- type CaptureSpec
- type CaptureTarget
- type Card
- type CardEntry
- type ChannelMap
- type Client
- func (c *Client) AdjustInputVolume(ctx context.Context, delta float64) (float64, error)
- func (c *Client) AdjustOutputVolume(ctx context.Context, delta float64) (float64, error)
- func (c *Client) DefaultSink(ctx context.Context) (string, error)
- func (c *Client) DefaultSource(ctx context.Context) (string, error)
- func (c *Client) GetDefaultSinkInfo(ctx context.Context) (map[string]string, error)
- func (c *Client) GetDefaultSourceInfo(ctx context.Context) (map[string]string, error)
- func (c *Client) InputMuted(ctx context.Context) (bool, error)
- func (c *Client) InputVolume(ctx context.Context) (float64, error)
- func (c *Client) ListCards(ctx context.Context) ([]CardEntry, error)
- func (c *Client) ListSinks(ctx context.Context) ([]DeviceEntry, error)
- func (c *Client) ListSources(ctx context.Context) ([]DeviceEntry, error)
- func (c *Client) OutputMuted(ctx context.Context) (bool, error)
- func (c *Client) OutputVolume(ctx context.Context) (float64, error)
- func (c *Client) SetCardProfile(ctx context.Context, card uint32, profile string) error
- func (c *Client) SetDefaultSink(ctx context.Context, index uint32) error
- func (c *Client) SetDefaultSource(ctx context.Context, index uint32) error
- func (c *Client) SetInputMute(ctx context.Context, muted bool) error
- func (c *Client) SetInputVolume(ctx context.Context, volume float64) (float64, error)
- func (c *Client) SetOutputMute(ctx context.Context, muted bool) error
- func (c *Client) SetOutputVolume(ctx context.Context, volume float64) (float64, error)
- func (c *Client) SinkCount(ctx context.Context) (uint32, error)
- func (c *Client) SourceCount(ctx context.Context) (uint32, error)
- func (c *Client) ToggleInputMute(ctx context.Context) (bool, error)
- func (c *Client) ToggleOutputMute(ctx context.Context) (bool, error)
- type Daemon
- type Device
- type DeviceEntry
- type DeviceKey
- type DeviceNotFoundError
- type DevicePort
- type DeviceState
- type DeviceType
- type InputDevice
- type InvalidChannelError
- type InvalidVolumeError
- type MediaInfo
- type OptIndex
- type OutputDevice
- type SampleSpec
- type Service
- func (s *Service) AudioStream(key StreamKey) (AudioStream, error)
- func (s *Service) Capture(target CaptureTarget, spec CaptureSpec, onData func([]byte)) (*Capture, error)
- func (s *Service) Cards() []Card
- func (s *Service) Close() error
- func (s *Service) DefaultInput() (InputDevice, bool)
- func (s *Service) DefaultOutput() (OutputDevice, bool)
- func (s *Service) DefaultSink(context.Context) (OutputDevice, error)
- func (s *Service) DefaultSource(context.Context) (InputDevice, error)
- func (s *Service) InputDevice(index uint32) (InputDevice, error)
- func (s *Service) InputDevices() []InputDevice
- func (s *Service) MoveStream(ctx context.Context, key StreamKey, device DeviceKey) error
- func (s *Service) OutputDevice(index uint32) (OutputDevice, error)
- func (s *Service) OutputDevices() []OutputDevice
- func (s *Service) PlaySample(ctx context.Context, p native.SamplePlay, load func() (native.Sample, error)) error
- func (s *Service) PlaybackStreams() []AudioStream
- func (s *Service) RecordingStreams() []AudioStream
- func (s *Service) SetCardProfile(ctx context.Context, index uint32, profile string) error
- func (s *Service) SetDefault(ctx context.Context, key DeviceKey) error
- func (s *Service) SetDeviceMute(ctx context.Context, key DeviceKey, muted bool) error
- func (s *Service) SetDevicePort(ctx context.Context, key DeviceKey, port string) error
- func (s *Service) SetDeviceVolume(ctx context.Context, key DeviceKey, v Volume) error
- func (s *Service) SetMuted(ctx context.Context, muted bool) error
- func (s *Service) SetSourceMuted(ctx context.Context, muted bool) error
- func (s *Service) SetStreamMute(ctx context.Context, key StreamKey, muted bool) error
- func (s *Service) SetStreamVolume(ctx context.Context, key StreamKey, v Volume) error
- func (s *Service) SetVolume(ctx context.Context, percent float64) error
- func (s *Service) Subscribe(ctx context.Context) (<-chan struct{}, func(), error)
- type Source
- type StreamKey
- type StreamNotFoundError
- type StreamState
- type StreamType
- type Volume
- func MonoVolume(v float64) Volume
- func MutedVolume(channels int) Volume
- func NewVolume(levels []float64) Volume
- func NormalVolume(channels int) Volume
- func StereoVolume(left, right float64) Volume
- func VolumeFromPercentage(percent float64, channels int) Volume
- func VolumeWithAmplification(levels []float64) (Volume, error)
- func (v Volume) Average() float64
- func (v Volume) AveragePercentage() float64
- func (v Volume) Channel(i int) (float64, bool)
- func (v Volume) Channels() int
- func (v Volume) Equal(o Volume) bool
- func (v Volume) IsMuted() bool
- func (v Volume) IsNormal() bool
- func (v Volume) Levels() []float64
- func (v Volume) ToPercentage() []float64
- func (v Volume) WithChannel(i int, level float64) (Volume, error)
Constants ¶
const ( ServiceName = "dev.stubbe.lys.Audio1" ServicePath = "/dev/stubbe/lys/Audio" // Interface is the object's interface name. Interface = "dev.stubbe.lys.Audio1" )
D-Bus identity (crates/wayle-audio/src/dbus/mod.rs).
Variables ¶
var ErrClosed = errors.New("pulse: service closed")
ErrClosed reports a request made after Close.
var ErrDisconnected = errors.New("pulse: not connected to the server")
ErrDisconnected reports a request made while the service has no connection to the server.
var ErrEmptyVolume = errors.New("pulse: volume has no channels")
ErrEmptyVolume rejects a volume with no channels (PulseAudio would answer PA_ERR_INVALID).
var ErrNoDefaultDevice = errors.New("pulse: no default device")
ErrNoDefaultDevice reports that the server names no default device of the requested kind, or names one not discovered yet.
Functions ¶
This section is empty.
Types ¶
type AudioFormat ¶
AudioFormat is one supported format: the encoding's name and its properties.
type AudioStream ¶
type AudioStream struct {
Key StreamKey
Name string
ApplicationName string
Binary string
PID uint32
OwnerModule OptIndex
Client OptIndex
State StreamState
Volume Volume
Muted bool
Corked bool
HasVolume bool
VolumeWritable bool
DeviceIndex uint32
SampleSpec SampleSpec
ChannelMap ChannelMap
Properties map[string]string
Media MediaInfo
BufferLatency time.Duration
DeviceLatency time.Duration
ResampleMethod string
Driver string
Format string
}
AudioStream is one application stream (core/stream). The application fields are empty, and PID zero, when the client did not set them.
type Capture ¶
type Capture struct {
// contains filtered or unexported fields
}
Capture is a running record stream that keeps itself pointed at its target: it reopens on the new source when the target resolves differently (the default changed) and after the server kills the stream, and waits while the target does not exist.
type CaptureSpec ¶
CaptureSpec is the PCM a capture delivers: signed 16-bit little-endian samples at Rate, Channels interleaved (1 or 2; the server mixes down or up), in chunks of about FragmentFrames frames. Name becomes the stream's media.name.
type CaptureTarget ¶
type CaptureTarget struct {
// contains filtered or unexported fields
}
CaptureTarget selects what a capture records. The zero value is the default sink's monitor.
func CaptureDefaultInput ¶
func CaptureDefaultInput() CaptureTarget
CaptureDefaultInput records the default source, following it.
func CaptureDefaultMonitor ¶
func CaptureDefaultMonitor() CaptureTarget
CaptureDefaultMonitor records whatever the default sink plays, and follows the default when it changes.
func CaptureNamed ¶
func CaptureNamed(name string) (CaptureTarget, error)
CaptureNamed records one device by name: a source, or a sink, whose monitor it then records (PipeWire's target.object semantics).
func (CaptureTarget) String ¶
func (t CaptureTarget) String() string
type CardEntry ¶ added in v0.3.15
type CardEntry struct {
Index uint32
Name string
Description string
Active string
Profiles []string
}
CardEntry is one ListCards row: (index, name, description, active profile, the profiles that can be chosen now) on the wire.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is the CLI side (dbus/client.rs's AudioProxy).
func (*Client) AdjustInputVolume ¶
AdjustInputVolume shifts the input volume.
func (*Client) AdjustOutputVolume ¶
AdjustOutputVolume shifts the output volume.
func (*Client) DefaultSink ¶
DefaultSink reads the DefaultSink property.
func (*Client) DefaultSource ¶
DefaultSource reads the DefaultSource property.
func (*Client) GetDefaultSinkInfo ¶
GetDefaultSinkInfo describes the default output.
func (*Client) GetDefaultSourceInfo ¶
GetDefaultSourceInfo describes the default input.
func (*Client) InputMuted ¶
InputMuted reads the InputMuted property.
func (*Client) InputVolume ¶
InputVolume reads the InputVolume property.
func (*Client) ListSinks ¶
func (c *Client) ListSinks(ctx context.Context) ([]DeviceEntry, error)
ListSinks lists the outputs.
func (*Client) ListSources ¶
func (c *Client) ListSources(ctx context.Context) ([]DeviceEntry, error)
ListSources lists the inputs.
func (*Client) OutputMuted ¶
OutputMuted reads the OutputMuted property.
func (*Client) OutputVolume ¶
OutputVolume reads the OutputVolume property.
func (*Client) SetCardProfile ¶ added in v0.3.15
SetCardProfile switches a card's profile.
func (*Client) SetDefaultSink ¶
SetDefaultSink makes a sink the default by index.
func (*Client) SetDefaultSource ¶
SetDefaultSource makes a source the default by index.
func (*Client) SetInputMute ¶
SetInputMute sets the input mute.
func (*Client) SetInputVolume ¶
SetInputVolume sets the input volume percentage.
func (*Client) SetOutputMute ¶
SetOutputMute sets the output mute.
func (*Client) SetOutputVolume ¶
SetOutputVolume sets the output volume percentage.
func (*Client) SourceCount ¶
SourceCount reads the SourceCount property.
func (*Client) ToggleInputMute ¶
ToggleInputMute flips the input mute.
type Daemon ¶
type Daemon struct {
// contains filtered or unexported fields
}
Daemon serves the audio service on the session bus (dbus/server.rs's AudioDaemon) for the `lys-shell audio` CLI and scripts.
type Device ¶
type Device struct {
Key DeviceKey
Name string
Description string
Card OptIndex
OwnerModule OptIndex
Driver string
State DeviceState
Volume Volume
BaseVolume Volume
VolumeSteps uint32
Muted bool
Properties map[string]string
Ports []DevicePort
ActivePort string // empty when the device has no active port
Formats []AudioFormat
SampleSpec SampleSpec
ChannelMap ChannelMap
Latency time.Duration
ConfiguredLatency time.Duration
Flags uint32
}
Device is what sinks and sources share (types/device.rs's DeviceInfo).
type DeviceEntry ¶
DeviceEntry is one ListSinks/ListSources row, (index, name, description) on the wire.
type DeviceKey ¶
type DeviceKey struct {
Index uint32
Type DeviceType
}
DeviceKey identifies a device: PulseAudio indexes sinks and sources separately, so the index alone is ambiguous.
type DeviceNotFoundError ¶
type DeviceNotFoundError struct {
Key DeviceKey
}
DeviceNotFoundError reports a lookup of a device the service does not hold (error.rs's DeviceNotFound).
func (*DeviceNotFoundError) Error ¶
func (e *DeviceNotFoundError) Error() string
type DevicePort ¶
DevicePort is one port; Available is false only when PulseAudio reports the port unavailable (unknown counts as available).
type DeviceState ¶
type DeviceState int
DeviceState is the device's run state.
const ( StateRunning DeviceState = iota StateIdle StateSuspended StateOffline )
Device states; an invalid PulseAudio state reads as Offline (conversion/device.rs's fallback).
func (DeviceState) String ¶
func (s DeviceState) String() string
String is the Rust variant name the DBus info map carries.
type DeviceType ¶
type DeviceType int
DeviceType is input (source) or output (sink) (types/device.rs).
const ( DeviceInput DeviceType = iota DeviceOutput )
Device types.
func (DeviceType) String ¶
func (t DeviceType) String() string
type InputDevice ¶
type InputDevice struct {
Device
MonitorOfSink OptIndex
MonitorOfSinkName string // empty unless IsMonitor
}
InputDevice is a source (core/device/input); monitors of sinks are sources too.
func (InputDevice) IsMonitor ¶
func (d InputDevice) IsMonitor() bool
IsMonitor reports whether the source monitors a sink.
type InvalidChannelError ¶
type InvalidChannelError struct {
Channel int
}
InvalidChannelError rejects a channel index the volume lacks.
func (*InvalidChannelError) Error ¶
func (e *InvalidChannelError) Error() string
type InvalidVolumeError ¶
InvalidVolumeError rejects an out-of-range level (volume/error.rs).
func (*InvalidVolumeError) Error ¶
func (e *InvalidVolumeError) Error() string
type OptIndex ¶
type OptIndex struct {
// contains filtered or unexported fields
}
OptIndex is an object index that may be absent (PA_INVALID_INDEX on the wire, Option<u32> in wayle-audio).
type OutputDevice ¶
OutputDevice is a sink (core/device/output).
type SampleSpec ¶
type SampleSpec = native.SampleSpec
SampleSpec is the device or stream sample format.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service is the live audio state. Every change PulseAudio announces is folded in as it arrives; the getters return snapshots that the caller owns. A lost connection empties the state and is redialled until Close, refilling it. It is safe for concurrent use.
func Connect ¶
Connect dials the server (server "" resolves like libpulse: $PULSE_SERVER, then $XDG_RUNTIME_DIR/pulse/native) and discovers every device, stream, and default before returning, so the first snapshot is complete; a later loss reconnects as Start does.
func Start ¶ added in v0.2.0
Start returns at once and connects in the background, retrying until the server is up and again whenever the connection is lost; the state is empty while there is none.
func (*Service) AudioStream ¶
func (s *Service) AudioStream(key StreamKey) (AudioStream, error)
AudioStream snapshots one stream.
func (*Service) Capture ¶
func (s *Service) Capture(target CaptureTarget, spec CaptureSpec, onData func([]byte)) (*Capture, error)
Capture starts recording target. onData receives each chunk on the connection's reader goroutine: it must not block, and it owns the slice. A target that does not resolve yet is not an error; the capture waits for it.
func (*Service) DefaultInput ¶
func (s *Service) DefaultInput() (InputDevice, bool)
DefaultInput is the default source.
func (*Service) DefaultOutput ¶
func (s *Service) DefaultOutput() (OutputDevice, bool)
DefaultOutput is the default sink. The default resolves by name on every read, so a default naming a sink not discovered yet appears the moment it is, rather than the previous device lingering.
func (*Service) DefaultSink ¶
func (s *Service) DefaultSink(context.Context) (OutputDevice, error)
DefaultSink implements Source.
func (*Service) DefaultSource ¶
func (s *Service) DefaultSource(context.Context) (InputDevice, error)
DefaultSource implements Source.
func (*Service) InputDevice ¶
func (s *Service) InputDevice(index uint32) (InputDevice, error)
InputDevice snapshots one source.
func (*Service) InputDevices ¶
func (s *Service) InputDevices() []InputDevice
InputDevices lists every source by index, monitors included.
func (*Service) MoveStream ¶
MoveStream routes a stream to another device: a playback stream to a sink, a recording stream to a source.
func (*Service) OutputDevice ¶
func (s *Service) OutputDevice(index uint32) (OutputDevice, error)
OutputDevice snapshots one sink.
func (*Service) OutputDevices ¶
func (s *Service) OutputDevices() []OutputDevice
OutputDevices lists every sink by index.
func (*Service) PlaySample ¶ added in v0.3.15
func (s *Service) PlaySample(ctx context.Context, p native.SamplePlay, load func() (native.Sample, error)) error
PlaySample plays p through the server's sample cache: the first play of p.Name on a connection uploads what load returns, every later one sends only the name. p.Props describe the playback (media.role and friends), so it follows the user's routing.
func (*Service) PlaybackStreams ¶
func (s *Service) PlaybackStreams() []AudioStream
PlaybackStreams lists the applications playing audio.
func (*Service) RecordingStreams ¶
func (s *Service) RecordingStreams() []AudioStream
RecordingStreams lists the applications recording audio.
func (*Service) SetCardProfile ¶ added in v0.3.15
SetCardProfile switches the card at index to profile (A2DP and HFP on a headset, analog and HDMI on a card).
func (*Service) SetDefault ¶
SetDefault makes a device the default of its kind.
func (*Service) SetDeviceMute ¶
SetDeviceMute mutes or unmutes a device.
func (*Service) SetDevicePort ¶
SetDevicePort switches a device's active port (headphones vs speakers).
func (*Service) SetDeviceVolume ¶
SetDeviceVolume sets a device's per-channel volume.
func (*Service) SetSourceMuted ¶
SetSourceMuted implements Source.
func (*Service) SetStreamMute ¶
SetStreamMute mutes or unmutes a stream.
func (*Service) SetStreamVolume ¶
SetStreamVolume sets a stream's per-channel volume.
func (*Service) SetVolume ¶
SetVolume implements Source: the DBus SetOutputVolume semantics, 0-100 over the device's channel count.
type Source ¶
type Source interface {
// DefaultSink returns the default output's snapshot, or
// ErrNoDefaultDevice.
DefaultSink(ctx context.Context) (OutputDevice, error)
// DefaultSource returns the default input's snapshot.
DefaultSource(ctx context.Context) (InputDevice, error)
// Subscribe ticks on audio state changes (see Service.Subscribe).
Subscribe(ctx context.Context) (<-chan struct{}, func(), error)
// SetVolume applies a percentage, clamped to 0-100, to every
// channel of the default sink.
SetVolume(ctx context.Context, percent float64) error
// SetMuted mutes or unmutes the default sink.
SetMuted(ctx context.Context, muted bool) error
// SetSourceMuted mutes or unmutes the default source.
SetSourceMuted(ctx context.Context, muted bool) error
// OutputDevices, InputDevices, and PlaybackStreams snapshot the
// lists the audio dropdown renders.
OutputDevices() []OutputDevice
InputDevices() []InputDevice
PlaybackStreams() []AudioStream
// RecordingStreams snapshots the record streams, what captures a
// source.
RecordingStreams() []AudioStream
// SetDeviceVolume, SetDeviceMute, and SetDefault control one
// device; SetStreamVolume and SetStreamMute one stream.
SetDeviceVolume(ctx context.Context, key DeviceKey, v Volume) error
SetDeviceMute(ctx context.Context, key DeviceKey, muted bool) error
SetDefault(ctx context.Context, key DeviceKey) error
SetStreamVolume(ctx context.Context, key StreamKey, v Volume) error
SetStreamMute(ctx context.Context, key StreamKey, muted bool) error
// Capture records a target until closed (see Service.Capture).
Capture(target CaptureTarget, spec CaptureSpec, onData func([]byte)) (*Capture, error)
}
Source is the shell's seam onto the audio service: the default devices the volume and microphone modules, the OSD, and the audio dropdown render, their controls, and the monitor capture the cava visualizer records. *Service implements it; tests substitute fakes.
type StreamKey ¶
type StreamKey struct {
Index uint32
Type StreamType
}
StreamKey identifies a stream.
type StreamNotFoundError ¶
type StreamNotFoundError struct {
Key StreamKey
}
StreamNotFoundError reports a lookup of an unknown stream.
func (*StreamNotFoundError) Error ¶
func (e *StreamNotFoundError) Error() string
type StreamState ¶
type StreamState int
StreamState is a stream's state. PulseAudio's introspection only distinguishes corked from running, so those are the two the service produces (conversion/stream.rs).
const ( StreamRunning StreamState = iota StreamCorked )
Stream states.
func (StreamState) String ¶
func (s StreamState) String() string
type StreamType ¶
type StreamType int
StreamType is playback (sink input) or record (source output).
const ( StreamPlayback StreamType = iota StreamRecord )
Stream types.
func (StreamType) String ¶
func (t StreamType) String() string
type Volume ¶
type Volume struct {
// contains filtered or unexported fields
}
Volume is a per-channel linear volume (volume/types.rs's Volume): 0.0 is silent, 1.0 normal, up to 4.0 amplified. It is immutable; the With* methods return a changed copy.
func NewVolume ¶
NewVolume clamps each channel into 0..4, logging the clamps and the levels past the safe 2.0, as Volume::new does.
func StereoVolume ¶
StereoVolume is a left/right volume.
func VolumeFromPercentage ¶
VolumeFromPercentage spreads one percentage (100 = 1.0) over channels.
func VolumeWithAmplification ¶
VolumeWithAmplification validates instead of clamping (Volume::with_amplification): any level outside 0..4 is an error.
func (Volume) AveragePercentage ¶
AveragePercentage is the channel mean as a percentage.
func (Volume) ToPercentage ¶
ToPercentage is each channel as a percentage.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package native is a PulseAudio native-protocol client in pure Go: the pstream framing, the tagstruct encoding, the handshake, the introspection and control commands wayle-audio drives through libpulse, the subscription events, and record streams.
|
Package native is a PulseAudio native-protocol client in pure Go: the pstream framing, the tagstruct encoding, the handshake, the introspection and control commands wayle-audio drives through libpulse, the subscription events, and record streams. |
|
Package pulsetest is a fake PulseAudio server for tests: a unix socket speaking the native protocol's real frames, backed by a scriptable object model (sinks, sources, streams, defaults) that answers introspection, applies control commands, emits subscription events the way pulsecore does, serves record streams, and can inject server errors, malformed frames, and disconnects.
|
Package pulsetest is a fake PulseAudio server for tests: a unix socket speaking the native protocol's real frames, backed by a scriptable object model (sinks, sources, streams, defaults) that answers introspection, applies control commands, emits subscription events the way pulsecore does, serves record streams, and can inject server errors, malformed frames, and disconnects. |