pulsetest

package
v0.3.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 11 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

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 and playback streams, and can inject server errors, malformed frames, and disconnects.

Index

Constants

View Source
const DefaultVersion = 35

DefaultVersion is the protocol version the fake announces: PulseAudio 17 and pipewire-pulse both speak 35.

Variables

This section is empty.

Functions

func Sink

func Sink(index uint32, name, desc string, monitor uint32) native.DeviceInfo

Sink is a running ALSA sink at 50% volume with two ports, whose monitor source has index monitor.

func Source

func Source(index uint32, name, desc string, monitorOf uint32, monitorName string) native.DeviceInfo

Source is a suspended ALSA source at full volume; monitorOf and monitorName name the sink it monitors (InvalidIndex and "" for a real input).

func StereoMap

func StereoMap() native.ChannelMap

StereoMap is the front-left/front-right channel map.

func StereoSpec

func StereoSpec() native.SampleSpec

StereoSpec is the s16le 48 kHz stereo sample spec the fixtures use.

Types

type Play

type Play struct {
	Name   string
	Sink   string
	Volume native.Volume
	Props  native.PropList
}

Play is one PLAY_SAMPLE the fake answered: Sink is the sink it named, empty for the default one.

type Playback

type Playback struct {
	Channel       uint32
	SinkInput     uint32
	Sink          string
	SinkIndex     uint32
	SampleSpec    native.SampleSpec
	ChannelMap    native.ChannelMap
	TargetLength  uint32
	AdjustLatency bool
	SyncID        uint32
	Props         native.PropList
	// contains filtered or unexported fields
}

Playback is one playback stream a client created. The fake grants the requested target length as the first request, then asks for more only through Request.

func (*Playback) Corked

func (p *Playback) Corked() bool

Corked reports whether the client corked the stream.

func (*Playback) Data

func (p *Playback) Data() []byte

Data is the audio received so far.

func (*Playback) Kill

func (p *Playback) Kill()

Kill ends the stream from the server side (PLAYBACK_STREAM_KILLED).

func (*Playback) Request

func (p *Playback) Request(n uint32)

Request asks the client for n more bytes (REQUEST).

func (*Playback) WaitData

func (p *Playback) WaitData(t testing.TB, n int) []byte

WaitData waits until at least n bytes of audio arrived and returns them.

type Record

type Record struct {
	Channel       uint32
	SourceOutput  uint32
	Source        string
	SourceIndex   uint32
	SampleSpec    native.SampleSpec
	ChannelMap    native.ChannelMap
	FragSize      uint32
	AdjustLatency bool
	Props         native.PropList
	// contains filtered or unexported fields
}

Record is one record stream a client created.

func (*Record) Kill

func (r *Record) Kill()

Kill ends the stream from the server side (RECORD_STREAM_KILLED).

func (*Record) Push

func (r *Record) Push(data []byte)

Push sends one audio chunk on the stream.

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is the fake. Its methods are safe for concurrent use.

func New

func New(t testing.TB) *Server

New starts a fake on a socket in a short per-test dir (sockdir: a long test name under CI's TMPDIR overflows sun_path); it shuts down with the test.

func (*Server) Addr

func (s *Server) Addr() string

Addr is the server string for native.Options.Server / PULSE_SERVER.

func (*Server) Calls

func (s *Server) Calls() []uint32

Calls lists every command received so far, in order.

func (*Server) Card

func (s *Server) Card(index uint32) (native.CardInfo, bool)

Card is the card at index as the server holds it.

func (*Server) Clients

func (s *Server) Clients() int

Clients counts the live connections.

func (*Server) Close

func (s *Server) Close()

Close stops accepting and drops every client: the server is down until Listen.

func (*Server) Defaults

func (s *Server) Defaults() (sink, source string)

Defaults reports the current default names.

func (*Server) Disconnect

func (s *Server) Disconnect()

Disconnect drops every client connection, and with each the record and playback streams its client created.

func (*Server) Emit

func (s *Server) Emit(ev native.SubscribeEvent)

Emit sends a subscription event to every client subscribed to its facility.

func (*Server) FailNext

func (s *Server) FailNext(cmd uint32, code native.Error)

FailNext makes the next request of cmd fail with code.

func (*Server) ForgetSamples

func (s *Server) ForgetSamples()

ForgetSamples empties the cache, as a server restart does.

func (*Server) Listen

func (s *Server) Listen(t testing.TB)

Listen brings a closed server back on the same socket, its devices, defaults and the streams the test put kept, as a restarted sound server; the streams clients created went with their connections.

func (*Server) Playbacks

func (s *Server) Playbacks() []*Playback

Playbacks lists the live playback streams.

func (*Server) Plays

func (s *Server) Plays() []Play

Plays lists the samples played, in order.

func (*Server) PutCard

func (s *Server) PutCard(c native.CardInfo)

PutCard adds or replaces a card and announces it.

func (*Server) PutSink

func (s *Server) PutSink(d native.DeviceInfo)

PutSink adds or replaces a sink, announcing it to subscribers.

func (*Server) PutSinkInput

func (s *Server) PutSinkInput(st native.StreamInfo)

PutSinkInput adds or replaces a playback stream.

func (*Server) PutSource

func (s *Server) PutSource(d native.DeviceInfo)

PutSource adds or replaces a source.

func (*Server) PutSourceOutput

func (s *Server) PutSourceOutput(st native.StreamInfo)

PutSourceOutput adds or replaces a recording stream.

func (*Server) Records

func (s *Server) Records() []*Record

Records lists the live record streams.

func (*Server) RemoveSink

func (s *Server) RemoveSink(index uint32)

RemoveSink drops a sink and announces the removal.

func (*Server) RemoveSinkInput

func (s *Server) RemoveSinkInput(index uint32)

RemoveSinkInput drops a playback stream.

func (*Server) RemoveSource

func (s *Server) RemoveSource(index uint32)

RemoveSource drops a source.

func (*Server) RemoveSourceOutput

func (s *Server) RemoveSourceOutput(index uint32)

RemoveSourceOutput drops a recording stream.

func (*Server) Samples

func (s *Server) Samples() map[string]native.Sample

Samples is the sample cache by name.

func (*Server) SendFrame

func (s *Server) SendFrame(f native.Frame)

SendFrame writes one frame to every client.

func (*Server) SendRaw

func (s *Server) SendRaw(b []byte)

SendRaw writes raw bytes to every client, for malformed-frame tests.

func (*Server) SetDefaults

func (s *Server) SetDefaults(sink, source string)

SetDefaults names the default sink and source (empty for none) and announces a server change.

func (*Server) SetVersion

func (s *Server) SetVersion(v uint32)

SetVersion changes the protocol version later handshakes announce.

func (*Server) Sink

func (s *Server) Sink(index uint32) (native.DeviceInfo, bool)

Sink snapshots one sink.

func (*Server) SinkInput

func (s *Server) SinkInput(index uint32) (native.StreamInfo, bool)

SinkInput snapshots one playback stream.

func (*Server) Source

func (s *Server) Source(index uint32) (native.DeviceInfo, bool)

Source snapshots one source.

func (*Server) SourceOutput

func (s *Server) SourceOutput(index uint32) (native.StreamInfo, bool)

SourceOutput snapshots one recording stream.

func (*Server) Uploads

func (s *Server) Uploads() int

Uploads counts the finished uploads.

func (*Server) WaitPlaybacks

func (s *Server) WaitPlaybacks(t testing.TB, n int) []*Playback

WaitPlaybacks waits until n playback streams are live and returns them.

func (*Server) WaitRecords

func (s *Server) WaitRecords(t testing.TB, n int) []*Record

WaitRecords waits until n record streams are live and returns them.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL