native

package
v0.3.15 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: MIT Imports: 16 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 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. PipeWire's pipewire-pulse serves the same protocol, so this is also how lys-shell talks to PipeWire.

The client speaks protocol version 32 without shared memory, so every reply and every audio chunk arrives inline on the socket, and it decodes servers down to version 24 (PulseAudio 2.0), where every field it reads has a fixed layout.

Index

Constants

View Source
const (
	CmdGetCardInfo     = 88
	CmdGetCardInfoList = 89
	CmdSetCardProfile  = 90
)

Card commands (pulsecore/native-common.h).

View Source
const (
	CmdError                 = 0
	CmdReply                 = 2
	CmdCreateRecordStream    = 5
	CmdDeleteRecordStream    = 6
	CmdCreateUploadStream    = 15
	CmdDeleteUploadStream    = 16
	CmdFinishUploadStream    = 17
	CmdPlaySample            = 18
	CmdAuth                  = 8
	CmdSetClientName         = 9
	CmdGetServerInfo         = 20
	CmdGetSinkInfo           = 21
	CmdGetSinkInfoList       = 22
	CmdGetSourceInfo         = 23
	CmdGetSourceInfoList     = 24
	CmdGetSinkInputInfo      = 29
	CmdGetSinkInputInfoList  = 30
	CmdGetSourceOutputInfo   = 31
	CmdGetSourceOutputList   = 32
	CmdSubscribe             = 35
	CmdSetSinkVolume         = 36
	CmdSetSinkInputVolume    = 37
	CmdSetSourceVolume       = 38
	CmdSetSinkMute           = 39
	CmdSetSourceMute         = 40
	CmdSetDefaultSink        = 44
	CmdSetDefaultSource      = 45
	CmdRecordStreamKilled    = 65
	CmdSubscribeEvent        = 66
	CmdMoveSinkInput         = 67
	CmdMoveSourceOutput      = 68
	CmdSetSinkInputMute      = 69
	CmdSetSinkPort           = 96
	CmdSetSourcePort         = 97
	CmdSetSourceOutputVolume = 98
	CmdSetSourceOutputMute   = 99
)

Command codes (pulsecore/native-common.h's PA_COMMAND_*), the subset this client sends or receives.

View Source
const (
	PortAvailableUnknown = 0
	PortAvailableNo      = 1
	PortAvailableYes     = 2
)

Port availability (pulse/def.h's pa_port_available).

View Source
const (
	StateRunning   = 0
	StateIdle      = 1
	StateSuspended = 2
)

Device states (pulse/def.h's pa_sink_state / pa_source_state, which share values).

View Source
const ControlChannel = 0xFFFFFFFF

ControlChannel is the channel of command packets; every other channel number carries one stream's audio (memblocks).

View Source
const CookieLength = 256

CookieLength is PA_NATIVE_COOKIE_LENGTH.

View Source
const InvalidIndex = 0xFFFFFFFF

InvalidIndex is PA_INVALID_INDEX: "no such object" in index fields, "use the name" in requests.

View Source
const MinServerVersion = 24

MinServerVersion is the oldest server protocol this client decodes.

View Source
const ProtocolVersion = 32

ProtocolVersion is the native protocol version this client speaks.

Variables

View Source
var ErrClosed = errors.New("pulse: connection closed")

ErrClosed is the terminal error of a connection closed by Close.

View Source
var ErrMalformed = errors.New("pulse: malformed tagstruct")

ErrMalformed marks a tagstruct that does not decode: a wrong tag, a truncated field, an out-of-range length. Decode errors wrap it.

View Source
var ErrNoSample = errors.New("pulse: no such sample in the server's cache")

ErrNoSample is a sample the server's cache does not hold.

View Source
var ErrProtocol = errors.New("pulse: protocol violation")

ErrProtocol marks a stream-level violation: an oversized frame, shared-memory data the client never negotiated, a packet without a command header. The connection cannot resynchronize after one.

View Source
var ErrStreamKilled = errors.New("pulse: record stream killed by the server")

ErrStreamKilled ends a record stream the server killed (its source went away, or it was killed from outside).

Functions

func CommandName

func CommandName(cmd uint32) string

CommandName is the PA_COMMAND_* name, for error messages.

func EncodeCard added in v0.3.15

func EncodeCard(w *Writer, c CardInfo, version uint32)

EncodeCard writes a card as decodeCard reads it at version, for test servers.

func EncodePacket

func EncodePacket(command, tag uint32, body []byte) []byte

EncodePacket builds a command packet payload: command and tag as 'L' fields, then the body.

func WriteFrame

func WriteFrame(w io.Writer, f Frame) error

WriteFrame writes one frame: the descriptor, then the payload.

Types

type CVolume

type CVolume []Volume

CVolume is pa_cvolume: one raw volume per channel.

type CardInfo added in v0.3.15

type CardInfo struct {
	Index         uint32
	Name          string
	OwnerModule   uint32
	Driver        string
	Profiles      []CardProfile
	ActiveProfile string
	Props         PropList
	Ports         []CardPort
}

CardInfo is one card (protocol-native.c's card_fill_tagstruct).

type CardPort added in v0.3.15

type CardPort struct {
	Name        string
	Description string
	Priority    uint32
	Available   uint32
	Direction   uint8
	Profiles    []string
}

CardPort is one port of a card and the profiles it belongs to.

type CardProfile added in v0.3.15

type CardProfile struct {
	Name        string
	Description string
	Sinks       uint32
	Sources     uint32
	Priority    uint32
	Available   bool
}

CardProfile is one profile a card offers: the sinks and sources it gives and whether it can be chosen now (protocol 29 and later; earlier servers report every profile available).

type ChannelMap

type ChannelMap []ChannelPosition

ChannelMap is pa_channel_map: one position per channel.

type ChannelPosition

type ChannelPosition uint8

ChannelPosition is a PA_CHANNEL_POSITION_* value.

const (
	ChannelMono               ChannelPosition = 0
	ChannelFrontLeft          ChannelPosition = 1
	ChannelFrontRight         ChannelPosition = 2
	ChannelFrontCenter        ChannelPosition = 3
	ChannelRearCenter         ChannelPosition = 4
	ChannelRearLeft           ChannelPosition = 5
	ChannelRearRight          ChannelPosition = 6
	ChannelLFE                ChannelPosition = 7
	ChannelFrontLeftOfCenter  ChannelPosition = 8
	ChannelFrontRightOfCenter ChannelPosition = 9
	ChannelSideLeft           ChannelPosition = 10
	ChannelSideRight          ChannelPosition = 11
	ChannelAux0               ChannelPosition = 12
	ChannelTopCenter          ChannelPosition = 44
	ChannelTopFrontLeft       ChannelPosition = 45
	ChannelTopFrontRight      ChannelPosition = 46
	ChannelTopFrontCenter     ChannelPosition = 47
	ChannelTopRearLeft        ChannelPosition = 48
	ChannelTopRearRight       ChannelPosition = 49
	ChannelTopRearCenter      ChannelPosition = 50
)

Channel positions (pulse/channelmap.h). The 32 aux positions sit between SideRight and TopCenter.

func (ChannelPosition) String

func (p ChannelPosition) String() string

String names the position like wayle-audio's ChannelPosition; the aux positions and anything unassigned are "Unknown" (conversion/format.rs's fallback).

type Conn

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

Conn is one authenticated connection. It is safe for concurrent use.

func Dial

func Dial(ctx context.Context, opts Options) (*Conn, error)

Dial connects and authenticates, trying each address of the server string in turn.

func (*Conn) Card added in v0.3.15

func (c *Conn) Card(ctx context.Context, index uint32) (CardInfo, error)

Card queries one card by index.

func (*Conn) Cards added in v0.3.15

func (c *Conn) Cards(ctx context.Context) ([]CardInfo, error)

Cards lists every card.

func (*Conn) Close

func (c *Conn) Close() error

Close tears the connection down. Pending requests fail with ErrClosed.

func (*Conn) CreateRecordStream

func (c *Conn) CreateRecordStream(ctx context.Context, p RecordParams, onData func([]byte)) (*RecordStream, error)

CreateRecordStream opens a record stream (CREATE_RECORD_STREAM with libpulse's defaults for the flags it does not expose). onData receives each audio chunk on the connection's reader goroutine: it must not block, and it owns the slice.

func (*Conn) Done

func (c *Conn) Done() <-chan struct{}

Done closes when the connection is gone (closed, killed, or failed).

func (*Conn) Err

func (c *Conn) Err() error

Err reports why the connection ended; nil while it is up.

func (*Conn) MoveSinkInput

func (c *Conn) MoveSinkInput(ctx context.Context, index, sink uint32) error

MoveSinkInput routes a playback stream to another sink.

func (*Conn) MoveSourceOutput

func (c *Conn) MoveSourceOutput(ctx context.Context, index, source uint32) error

MoveSourceOutput routes a recording stream to another source.

func (*Conn) PlaySample added in v0.3.15

func (c *Conn) PlaySample(ctx context.Context, p SamplePlay) error

PlaySample plays a cached sample (PLAY_SAMPLE). A name the cache lacks is ErrNoSample.

func (*Conn) ServerInfo

func (c *Conn) ServerInfo(ctx context.Context) (ServerInfo, error)

ServerInfo queries the server's defaults.

func (*Conn) SetCardProfile added in v0.3.15

func (c *Conn) SetCardProfile(ctx context.Context, index uint32, profile string) error

SetCardProfile makes profile the card's active one.

func (*Conn) SetDefaultSink

func (c *Conn) SetDefaultSink(ctx context.Context, name string) error

SetDefaultSink makes the named sink the default.

func (*Conn) SetDefaultSource

func (c *Conn) SetDefaultSource(ctx context.Context, name string) error

SetDefaultSource makes the named source the default.

func (*Conn) SetSinkInputMute

func (c *Conn) SetSinkInputMute(ctx context.Context, index uint32, mute bool) error

SetSinkInputMute mutes or unmutes a playback stream.

func (*Conn) SetSinkInputVolume

func (c *Conn) SetSinkInputVolume(ctx context.Context, index uint32, v CVolume) error

SetSinkInputVolume sets a playback stream's volume.

func (*Conn) SetSinkMute

func (c *Conn) SetSinkMute(ctx context.Context, index uint32, mute bool) error

SetSinkMute mutes or unmutes a sink by index.

func (*Conn) SetSinkPort

func (c *Conn) SetSinkPort(ctx context.Context, index uint32, port string) error

SetSinkPort switches a sink's active port.

func (*Conn) SetSinkVolume

func (c *Conn) SetSinkVolume(ctx context.Context, index uint32, v CVolume) error

SetSinkVolume sets a sink's per-channel volume by index.

func (*Conn) SetSourceMute

func (c *Conn) SetSourceMute(ctx context.Context, index uint32, mute bool) error

SetSourceMute mutes or unmutes a source by index.

func (*Conn) SetSourceOutputMute

func (c *Conn) SetSourceOutputMute(ctx context.Context, index uint32, mute bool) error

SetSourceOutputMute mutes or unmutes a recording stream.

func (*Conn) SetSourceOutputVolume

func (c *Conn) SetSourceOutputVolume(ctx context.Context, index uint32, v CVolume) error

SetSourceOutputVolume sets a recording stream's volume.

func (*Conn) SetSourcePort

func (c *Conn) SetSourcePort(ctx context.Context, index uint32, port string) error

SetSourcePort switches a source's active port.

func (*Conn) SetSourceVolume

func (c *Conn) SetSourceVolume(ctx context.Context, index uint32, v CVolume) error

SetSourceVolume sets a source's per-channel volume by index.

func (*Conn) Sink

func (c *Conn) Sink(ctx context.Context, index uint32) (DeviceInfo, error)

Sink queries one sink by index.

func (*Conn) SinkInput

func (c *Conn) SinkInput(ctx context.Context, index uint32) (StreamInfo, error)

SinkInput queries one playback stream by index.

func (*Conn) SinkInputs

func (c *Conn) SinkInputs(ctx context.Context) ([]StreamInfo, error)

SinkInputs lists every playback stream.

func (*Conn) Sinks

func (c *Conn) Sinks(ctx context.Context) ([]DeviceInfo, error)

Sinks lists every sink.

func (*Conn) Source

func (c *Conn) Source(ctx context.Context, index uint32) (DeviceInfo, error)

Source queries one source by index.

func (*Conn) SourceOutput

func (c *Conn) SourceOutput(ctx context.Context, index uint32) (StreamInfo, error)

SourceOutput queries one recording stream by index.

func (*Conn) SourceOutputs

func (c *Conn) SourceOutputs(ctx context.Context) ([]StreamInfo, error)

SourceOutputs lists every recording stream.

func (*Conn) Sources

func (c *Conn) Sources(ctx context.Context) ([]DeviceInfo, error)

Sources lists every source, monitors included.

func (*Conn) Subscribe

func (c *Conn) Subscribe(ctx context.Context, mask SubscriptionMask) error

Subscribe selects the facilities whose changes arrive at Options.OnSubscribe.

func (*Conn) UploadSample added in v0.3.15

func (c *Conn) UploadSample(ctx context.Context, name string, s Sample) error

UploadSample stores s in the server's sample cache under name (CREATE_UPLOAD_STREAM, the audio, FINISH_UPLOAD_STREAM), replacing any sample of that name. PlaySample then plays it without sending it again. The upload's event.id and media.name are name: pipewire-pulse files the sample under those rather than the name argument.

func (*Conn) Version

func (c *Conn) Version() uint32

Version is the negotiated protocol version.

type DeviceInfo

type DeviceInfo struct {
	Index             uint32
	Name              string
	Description       string
	SampleSpec        SampleSpec
	ChannelMap        ChannelMap
	OwnerModule       uint32
	Volume            CVolume
	Mute              bool
	Monitor           uint32
	MonitorName       string
	Latency           uint64
	Driver            string
	Flags             uint32
	Props             PropList
	ConfiguredLatency uint64
	BaseVolume        Volume
	State             uint32
	VolumeSteps       uint32
	Card              uint32
	Ports             []Port
	ActivePort        string
	Formats           []FormatInfo
}

DeviceInfo is one sink or source (protocol-native.c's sink_fill_tagstruct / source_fill_tagstruct share the layout). For a sink, Monitor/MonitorName name its monitor source; for a source they name the sink it monitors, InvalidIndex/"" when it is not a monitor.

type Encoding

type Encoding uint8

Encoding is a PA_ENCODING_* format encoding.

const (
	EncodingAny              Encoding = 0
	EncodingPCM              Encoding = 1
	EncodingAC3IEC61937      Encoding = 2
	EncodingEAC3IEC61937     Encoding = 3
	EncodingMPEGIEC61937     Encoding = 4
	EncodingDTSIEC61937      Encoding = 5
	EncodingMPEG2AACIEC61937 Encoding = 6
	EncodingTrueHDIEC61937   Encoding = 7
	EncodingDTSHDIEC61937    Encoding = 8
	EncodingInvalid          Encoding = 0xFF
)

Format encodings (pulse/format.h).

func (Encoding) String

func (e Encoding) String() string

String is the libpulse-binding Encoding debug name wayle-audio stores in its format strings; out-of-range values are "Invalid".

type Error

type Error uint32

Error is a PA_ERR_* code the server returned for a request. The codes are comparable, so errors.Is(err, native.ErrNoEntity) works on any wrapped request error.

const (
	ErrAccess               Error = 1
	ErrCommand              Error = 2
	ErrInvalid              Error = 3
	ErrExist                Error = 4
	ErrNoEntity             Error = 5
	ErrConnectionRefused    Error = 6
	ErrProtocolCode         Error = 7
	ErrTimeout              Error = 8
	ErrAuthKey              Error = 9
	ErrInternal             Error = 10
	ErrConnectionTerminated Error = 11
	ErrEntityKilled         Error = 12
	ErrInvalidServer        Error = 13
	ErrModInitFailed        Error = 14
	ErrBadState             Error = 15
	ErrNoData               Error = 16
	ErrVersion              Error = 17
	ErrTooLarge             Error = 18
	ErrNotSupported         Error = 19
	ErrUnknown              Error = 20
	ErrNoExtension          Error = 21
	ErrObsolete             Error = 22
	ErrNotImplemented       Error = 23
	ErrForked               Error = 24
	ErrIO                   Error = 25
	ErrBusy                 Error = 26
)

Server error codes (pulse/def.h's pa_error_code).

func (Error) Error

func (e Error) Error() string

type Facility

type Facility uint32

Facility is a subscription event's object class (PA_SUBSCRIPTION_EVENT_FACILITY_MASK bits).

const (
	FacilitySink         Facility = 0
	FacilitySource       Facility = 1
	FacilitySinkInput    Facility = 2
	FacilitySourceOutput Facility = 3
	FacilityModule       Facility = 4
	FacilityClient       Facility = 5
	FacilitySampleCache  Facility = 6
	FacilityServer       Facility = 7
	FacilityCard         Facility = 9
)

Subscription facilities (pulse/def.h).

type FormatInfo

type FormatInfo struct {
	Encoding Encoding
	Props    PropList
}

FormatInfo is pa_format_info.

type Frame

type Frame struct {
	Channel uint32
	Offset  uint64
	Flags   uint32
	Payload []byte
}

Frame is one pstream frame.

func ReadFrame

func ReadFrame(r io.Reader) (Frame, error)

ReadFrame reads one frame. An oversized length or shared-memory flags are ErrProtocol; a short read is the reader's error (io.ErrUnexpectedEOF mid-frame, io.EOF at a frame boundary).

type Operation

type Operation uint32

Operation is a subscription event's change kind (PA_SUBSCRIPTION_EVENT_TYPE_MASK bits).

const (
	OpNew    Operation = 0x00
	OpChange Operation = 0x10
	OpRemove Operation = 0x20
)

Subscription operations.

type Options

type Options struct {
	// Server is a PulseAudio server string ("unix:/path", "/path",
	// "tcp:host:port", optionally several separated by spaces). Empty
	// means $PULSE_SERVER, then $XDG_RUNTIME_DIR/pulse/native.
	Server string
	// ClientName becomes the client's application.name.
	ClientName string
	// Timeout bounds requests whose context has no deadline; zero
	// means five seconds.
	Timeout time.Duration
	// OnSubscribe receives subscription events in order, on one
	// goroutine that is not the socket reader, so it may issue
	// requests on the connection.
	OnSubscribe func(SubscribeEvent)
}

Options configures Dial.

type Packet

type Packet struct {
	Command uint32
	Tag     uint32
	Body    *Reader
}

Packet is a decoded command packet: the command, its tag, and the tagstruct body after the two header fields.

func DecodePacket

func DecodePacket(payload []byte) (Packet, error)

DecodePacket splits a control-channel payload into its header and body. A payload without the two header fields is ErrProtocol.

type Port

type Port struct {
	Name        string
	Description string
	Priority    uint32
	Available   uint32
}

Port is one device port.

type PropList

type PropList map[string]string

PropList is a pa_proplist restricted to its string entries: binary values are dropped on decode, as libpulse's pa_proplist_gets (and wayle-audio's collect_proplist) never returns them.

type Reader

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

Reader decodes one tagstruct. The first failure sticks: later reads return zero values and Err reports the original cause.

func NewReader

func NewReader(data []byte) *Reader

NewReader decodes data.

func (*Reader) Arbitrary

func (r *Reader) Arbitrary() []byte

Arbitrary reads a 'x' blob.

func (*Reader) Bool

func (r *Reader) Bool() bool

Bool reads a '1' or '0' field.

func (*Reader) CVolume

func (r *Reader) CVolume() CVolume

CVolume reads a 'v' field.

func (*Reader) ChannelMap

func (r *Reader) ChannelMap() ChannelMap

ChannelMap reads a 'm' field.

func (*Reader) EOF

func (r *Reader) EOF() bool

EOF reports whether every byte was consumed.

func (*Reader) Err

func (r *Reader) Err() error

Err reports the first decoding error.

func (*Reader) FormatInfo

func (r *Reader) FormatInfo() FormatInfo

FormatInfo reads an 'f' field.

func (*Reader) PropList

func (r *Reader) PropList() PropList

PropList reads a 'P' field, keeping the entries whose value is a NUL-terminated UTF-8 string.

func (*Reader) Rest

func (r *Reader) Rest() []byte

Rest returns the unread bytes.

func (*Reader) S64

func (r *Reader) S64() int64

S64 reads a 'r' field.

func (*Reader) SampleSpec

func (r *Reader) SampleSpec() SampleSpec

SampleSpec reads an 'a' field.

func (*Reader) Str

func (r *Reader) Str() string

Str reads a string field where the null string reads as "".

func (*Reader) String

func (r *Reader) String() (string, bool)

String reads a 't' or 'N' field; ok is false for the null string. Invalid UTF-8 is replaced lossily, as libpulse-binding's to_string_lossy does for wayle-audio.

func (*Reader) U8

func (r *Reader) U8() uint8

U8 reads a 'B' field.

func (*Reader) U32

func (r *Reader) U32() uint32

U32 reads a 'L' field.

func (*Reader) U64

func (r *Reader) U64() uint64

U64 reads a 'R' field.

func (*Reader) Usec

func (r *Reader) Usec() uint64

Usec reads a 'U' field.

func (*Reader) Volume

func (r *Reader) Volume() Volume

Volume reads a 'V' field.

type RecordInfo

type RecordInfo struct {
	SourceOutput uint32
	MaxLength    uint32
	FragSize     uint32
	SampleSpec   SampleSpec
	ChannelMap   ChannelMap
	SourceIndex  uint32
	SourceName   string
	Suspended    bool
	Latency      uint64
	Format       FormatInfo
}

RecordInfo is what the server granted for a record stream.

type RecordParams

type RecordParams struct {
	// SampleSpec is the capture format; the server converts to it.
	SampleSpec SampleSpec
	// ChannelMap must have SampleSpec.Channels entries.
	ChannelMap ChannelMap
	// Source is the source name; empty records from the default.
	Source string
	// FragSize is the preferred chunk size in bytes; zero lets the
	// server choose.
	FragSize uint32
	// Props become the stream's proplist (media.name and friends).
	Props PropList
}

RecordParams describes a record stream.

type RecordStream

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

RecordStream is a live record stream. Its audio arrives at the handler given to CreateRecordStream.

func (*RecordStream) Close

func (s *RecordStream) Close(ctx context.Context) error

Close deletes the stream. Audio stops arriving before the server confirms; a stream that already ended closes without a request.

func (*RecordStream) Ended

func (s *RecordStream) Ended() <-chan struct{}

Ended closes when the stream is gone: deleted, killed by the server, or lost with its connection. Err then says which.

func (*RecordStream) Err

func (s *RecordStream) Err() error

Err reports why the stream ended; nil while it runs.

func (*RecordStream) Info

func (s *RecordStream) Info() RecordInfo

Info is what the server granted.

type Sample added in v0.3.15

type Sample struct {
	SampleSpec SampleSpec
	ChannelMap ChannelMap
	Data       []byte
}

Sample is audio for the server's sample cache: interleaved frames in SampleSpec's format, laid out by ChannelMap.

type SampleFormat

type SampleFormat uint8

SampleFormat is a PA_SAMPLE_* sample format.

const (
	SampleU8        SampleFormat = 0
	SampleALaw      SampleFormat = 1
	SampleULaw      SampleFormat = 2
	SampleS16LE     SampleFormat = 3
	SampleS16BE     SampleFormat = 4
	SampleFloat32LE SampleFormat = 5
	SampleFloat32BE SampleFormat = 6
	SampleS32LE     SampleFormat = 7
	SampleS32BE     SampleFormat = 8
	SampleS24LE     SampleFormat = 9
	SampleS24BE     SampleFormat = 10
	SampleS24_32LE  SampleFormat = 11
	SampleS24_32BE  SampleFormat = 12
	SampleInvalid   SampleFormat = 0xFF
)

Sample formats (pulse/sample.h).

func (SampleFormat) BytesPerSample

func (f SampleFormat) BytesPerSample() int

BytesPerSample is the width of one sample, 0 for unknown formats.

func (SampleFormat) Known

func (f SampleFormat) Known() bool

Known reports whether the format is one PulseAudio defines.

func (SampleFormat) String

func (f SampleFormat) String() string

String names the format like wayle-audio's SampleFormat variants; anything else is "Unknown" (conversion/format.rs's fallback).

type SamplePlay added in v0.3.15

type SamplePlay struct {
	Name   string
	Sink   string
	Volume Volume
	Props  PropList
}

SamplePlay is one play of a cached sample: Name on the sink named Sink, or on the default sink when Sink is empty, at Volume; Props describe this playback (media.role and friends).

type SampleSpec

type SampleSpec struct {
	Format   SampleFormat
	Channels uint8
	Rate     uint32
}

SampleSpec is pa_sample_spec.

func (SampleSpec) FrameSize

func (s SampleSpec) FrameSize() int

FrameSize is the byte width of one frame (all channels of a sample).

type ServerInfo

type ServerInfo struct {
	PackageName    string
	PackageVersion string
	UserName       string
	HostName       string
	SampleSpec     SampleSpec
	DefaultSink    string
	DefaultSource  string
	Cookie         uint32
	ChannelMap     ChannelMap
}

ServerInfo is the GET_SERVER_INFO reply. DefaultSink/DefaultSource are empty when the server has no default.

type StreamInfo

type StreamInfo struct {
	Index          uint32
	Name           string
	OwnerModule    uint32
	Client         uint32
	Device         uint32
	SampleSpec     SampleSpec
	ChannelMap     ChannelMap
	Volume         CVolume
	BufferLatency  uint64
	DeviceLatency  uint64
	ResampleMethod string
	Driver         string
	Mute           bool
	Props          PropList
	Corked         bool
	HasVolume      bool
	VolumeWritable bool
	Format         FormatInfo
}

StreamInfo is one sink input or source output. Device is the sink or source it is connected to.

type SubscribeEvent

type SubscribeEvent struct {
	Facility  Facility
	Operation Operation
	Index     uint32
}

SubscribeEvent is one SUBSCRIBE_EVENT.

type SubscriptionMask

type SubscriptionMask uint32

SubscriptionMask selects the facilities a SUBSCRIBE asks for.

const (
	MaskSink         SubscriptionMask = 1 << FacilitySink
	MaskSource       SubscriptionMask = 1 << FacilitySource
	MaskSinkInput    SubscriptionMask = 1 << FacilitySinkInput
	MaskSourceOutput SubscriptionMask = 1 << FacilitySourceOutput
	MaskServer       SubscriptionMask = 1 << FacilityServer
)

Subscription mask bits (pulse/def.h's PA_SUBSCRIPTION_MASK_*).

const MaskCard SubscriptionMask = 1 << FacilityCard

MaskCard selects card changes.

type Volume

type Volume uint32

Volume is one raw pa_volume_t.

const (
	VolumeMuted   Volume = 0
	VolumeNorm    Volume = 0x10000
	VolumeMax     Volume = 0x7FFFFFFF
	VolumeInvalid Volume = 0xFFFFFFFF
)

Raw volume anchors (pulse/volume.h).

func LinearVolume added in v0.3.15

func LinearVolume(level float64) Volume

LinearVolume is the raw volume of a linear level, 1 being VolumeNorm, truncated.

type Writer

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

Writer builds one tagstruct. The first invalid value (a string with a NUL byte, an oversized field) poisons the writer; Err reports it and the request is never sent.

func (*Writer) Arbitrary

func (w *Writer) Arbitrary(b []byte)

Arbitrary appends a 'x' blob.

func (*Writer) Bool

func (w *Writer) Bool(v bool)

Bool appends a '1' or '0' field.

func (*Writer) Bytes

func (w *Writer) Bytes() []byte

Bytes returns the encoded tagstruct.

func (*Writer) CVolume

func (w *Writer) CVolume(v CVolume)

CVolume appends a 'v' field.

func (*Writer) ChannelMap

func (w *Writer) ChannelMap(m ChannelMap)

ChannelMap appends a 'm' field.

func (*Writer) Count added in v0.3.15

func (w *Writer) Count(n int, what string)

Count appends a 'L' field holding the length of a list of what.

func (*Writer) Err

func (w *Writer) Err() error

Err reports the first encoding error.

func (*Writer) FormatInfo

func (w *Writer) FormatInfo(f FormatInfo)

FormatInfo appends an 'f' field.

func (*Writer) NullString

func (w *Writer) NullString()

NullString appends the 'N' null string.

func (*Writer) OptString

func (w *Writer) OptString(s string)

OptString appends s, or the null string when s is empty: the "name or NULL" arguments where an empty name means "use the index".

func (*Writer) PropList

func (w *Writer) PropList(p PropList)

PropList appends a 'P' field: each entry as key string, length, and the NUL-terminated value blob, closed by the null string. Keys are written sorted so the encoding is deterministic.

func (*Writer) S64

func (w *Writer) S64(v int64)

S64 appends a 'r' field.

func (*Writer) SampleSpec

func (w *Writer) SampleSpec(s SampleSpec)

SampleSpec appends an 'a' field.

func (*Writer) String

func (w *Writer) String(s string)

String appends a 't' field; a string with a NUL byte cannot be encoded and poisons the writer.

func (*Writer) U8

func (w *Writer) U8(v uint8)

U8 appends a 'B' field.

func (*Writer) U32

func (w *Writer) U32(v uint32)

U32 appends a 'L' field.

func (*Writer) U64

func (w *Writer) U64(v uint64)

U64 appends a 'R' field.

func (*Writer) Usec

func (w *Writer) Usec(v uint64)

Usec appends a 'U' field.

func (*Writer) Volume

func (w *Writer) Volume(v Volume)

Volume appends a 'V' field.

Jump to

Keyboard shortcuts

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