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, the subscription events, record and playback streams, and the sample cache. PipeWire's pipewire-pulse serves the same protocol, so this is also how the lys programs talk 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
- Variables
- func CommandName(cmd uint32) string
- func EncodeCard(w *Writer, c CardInfo, version uint32)
- func EncodePacket(command, tag uint32, body []byte) []byte
- func WriteFrame(w io.Writer, f Frame) error
- type CVolume
- type CardInfo
- type CardPort
- type CardProfile
- type ChannelMap
- type ChannelPosition
- type Conn
- func (c *Conn) Card(ctx context.Context, index uint32) (CardInfo, error)
- func (c *Conn) Cards(ctx context.Context) ([]CardInfo, error)
- func (c *Conn) Close() error
- func (c *Conn) CreatePlaybackStream(ctx context.Context, p PlaybackParams) (*PlaybackStream, error)
- func (c *Conn) CreateRecordStream(ctx context.Context, p RecordParams, onData func([]byte)) (*RecordStream, error)
- func (c *Conn) Done() <-chan struct{}
- func (c *Conn) Err() error
- func (c *Conn) MoveSinkInput(ctx context.Context, index, sink uint32) error
- func (c *Conn) MoveSourceOutput(ctx context.Context, index, source uint32) error
- func (c *Conn) PlaySample(ctx context.Context, p SamplePlay) error
- func (c *Conn) ServerInfo(ctx context.Context) (ServerInfo, error)
- func (c *Conn) SetCardProfile(ctx context.Context, index uint32, profile string) error
- func (c *Conn) SetDefaultSink(ctx context.Context, name string) error
- func (c *Conn) SetDefaultSource(ctx context.Context, name string) error
- func (c *Conn) SetSinkInputMute(ctx context.Context, index uint32, mute bool) error
- func (c *Conn) SetSinkInputVolume(ctx context.Context, index uint32, v CVolume) error
- func (c *Conn) SetSinkMute(ctx context.Context, index uint32, mute bool) error
- func (c *Conn) SetSinkPort(ctx context.Context, index uint32, port string) error
- func (c *Conn) SetSinkVolume(ctx context.Context, index uint32, v CVolume) error
- func (c *Conn) SetSourceMute(ctx context.Context, index uint32, mute bool) error
- func (c *Conn) SetSourceOutputMute(ctx context.Context, index uint32, mute bool) error
- func (c *Conn) SetSourceOutputVolume(ctx context.Context, index uint32, v CVolume) error
- func (c *Conn) SetSourcePort(ctx context.Context, index uint32, port string) error
- func (c *Conn) SetSourceVolume(ctx context.Context, index uint32, v CVolume) error
- func (c *Conn) Sink(ctx context.Context, index uint32) (DeviceInfo, error)
- func (c *Conn) SinkInput(ctx context.Context, index uint32) (StreamInfo, error)
- func (c *Conn) SinkInputs(ctx context.Context) ([]StreamInfo, error)
- func (c *Conn) Sinks(ctx context.Context) ([]DeviceInfo, error)
- func (c *Conn) Source(ctx context.Context, index uint32) (DeviceInfo, error)
- func (c *Conn) SourceOutput(ctx context.Context, index uint32) (StreamInfo, error)
- func (c *Conn) SourceOutputs(ctx context.Context) ([]StreamInfo, error)
- func (c *Conn) Sources(ctx context.Context) ([]DeviceInfo, error)
- func (c *Conn) Subscribe(ctx context.Context, mask SubscriptionMask) error
- func (c *Conn) UploadSample(ctx context.Context, name string, s Sample) error
- func (c *Conn) Version() uint32
- type DeviceInfo
- type Encoding
- type Error
- type Facility
- type FormatInfo
- type Frame
- type Operation
- type Options
- type Packet
- type PlaybackInfo
- type PlaybackParams
- type PlaybackStream
- func (s *PlaybackStream) Close(ctx context.Context) error
- func (s *PlaybackStream) Cork(ctx context.Context, corked bool) error
- func (l *PlaybackStream) Ended() <-chan struct{}
- func (l *PlaybackStream) Err() error
- func (s *PlaybackStream) Info() PlaybackInfo
- func (s *PlaybackStream) Write(ctx context.Context, p []byte) error
- type Port
- type PropList
- type Reader
- func (r *Reader) Arbitrary() []byte
- func (r *Reader) Bool() bool
- func (r *Reader) CVolume() CVolume
- func (r *Reader) ChannelMap() ChannelMap
- func (r *Reader) EOF() bool
- func (r *Reader) Err() error
- func (r *Reader) FormatInfo() FormatInfo
- func (r *Reader) PropList() PropList
- func (r *Reader) Rest() []byte
- func (r *Reader) S64() int64
- func (r *Reader) SampleSpec() SampleSpec
- func (r *Reader) Str() string
- func (r *Reader) String() (string, bool)
- func (r *Reader) U8() uint8
- func (r *Reader) U32() uint32
- func (r *Reader) U64() uint64
- func (r *Reader) Usec() uint64
- func (r *Reader) Volume() Volume
- type RecordInfo
- type RecordParams
- type RecordStream
- type Sample
- type SampleFormat
- type SamplePlay
- type SampleSpec
- type ServerInfo
- type StreamInfo
- type SubscribeEvent
- type SubscriptionMask
- type Volume
- type Writer
- func (w *Writer) Arbitrary(b []byte)
- func (w *Writer) Bool(v bool)
- func (w *Writer) Bytes() []byte
- func (w *Writer) CVolume(v CVolume)
- func (w *Writer) ChannelMap(m ChannelMap)
- func (w *Writer) Count(n int, what string)
- func (w *Writer) Err() error
- func (w *Writer) FormatInfo(f FormatInfo)
- func (w *Writer) NullString()
- func (w *Writer) OptString(s string)
- func (w *Writer) PropList(p PropList)
- func (w *Writer) S64(v int64)
- func (w *Writer) SampleSpec(s SampleSpec)
- func (w *Writer) String(s string)
- func (w *Writer) U8(v uint8)
- func (w *Writer) U32(v uint32)
- func (w *Writer) U64(v uint64)
- func (w *Writer) Usec(v uint64)
- func (w *Writer) Volume(v Volume)
Constants ¶
const ( CmdGetCardInfo = 88 CmdGetCardInfoList = 89 CmdSetCardProfile = 90 )
Card commands (pulsecore/native-common.h).
const ( CmdError = 0 CmdReply = 2 CmdCreatePlaybackStream = 3 CmdDeletePlaybackStream = 4 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 CmdCorkPlaybackStream = 41 CmdSetDefaultSink = 44 CmdSetDefaultSource = 45 CmdRequest = 61 CmdPlaybackStreamKilled = 64 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.
const ( PortAvailableUnknown = 0 PortAvailableNo = 1 PortAvailableYes = 2 )
Port availability (pulse/def.h's pa_port_available).
const ( StateRunning = 0 StateIdle = 1 StateSuspended = 2 )
Device states (pulse/def.h's pa_sink_state / pa_source_state, which share values).
const ControlChannel = 0xFFFFFFFF
ControlChannel is the channel of command packets; every other channel number carries one stream's audio (memblocks).
const CookieLength = 256
CookieLength is PA_NATIVE_COOKIE_LENGTH.
const InvalidIndex = 0xFFFFFFFF
InvalidIndex is PA_INVALID_INDEX: "no such object" in index fields, "use the name" in requests.
const MinServerVersion = 24
MinServerVersion is the oldest server protocol this client decodes.
const ProtocolVersion = 32
ProtocolVersion is the native protocol version this client speaks.
Variables ¶
var ErrClosed = errors.New("pulse: connection closed")
ErrClosed is the terminal error of a connection closed by Close.
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.
var ErrNoSample = errors.New("pulse: no such sample in the server's cache")
ErrNoSample is a sample the server's cache does not hold.
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.
var ErrStreamKilled = errors.New("pulse: stream killed by the server")
ErrStreamKilled ends a stream the server killed (its device went away, or it was killed from outside).
Functions ¶
func CommandName ¶
CommandName is the PA_COMMAND_* name, for error messages.
func EncodeCard ¶
EncodeCard writes a card as decodeCard reads it at version, for test servers.
func EncodePacket ¶
EncodePacket builds a command packet payload: command and tag as 'L' fields, then the body.
Types ¶
type CardInfo ¶
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 ¶
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 ¶
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; the aux positions and anything unassigned are "Unknown".
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn is one authenticated connection. It is safe for concurrent use.
func (*Conn) Close ¶
Close tears the connection down and returns once the goroutines it ran have ended, a subscription handler still running on one included. Pending requests fail with ErrClosed, and so does every request made after, so a handler querying the connection returns promptly. Called from a subscription or record data handler, Close does not wait for the goroutine it runs on, which ends when the handler returns.
func (*Conn) CreatePlaybackStream ¶
func (c *Conn) CreatePlaybackStream(ctx context.Context, p PlaybackParams) (*PlaybackStream, error)
CreatePlaybackStream opens an uncorked playback stream (CREATE_PLAYBACK_STREAM with libpulse's defaults for the flags it does not expose). With a Latency the server adjusts its buffering so the whole path meets it.
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) MoveSinkInput ¶
MoveSinkInput routes a playback stream to another sink.
func (*Conn) MoveSourceOutput ¶
MoveSourceOutput routes a recording stream to another source.
func (*Conn) PlaySample ¶
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 ¶
SetCardProfile makes profile the card's active one.
func (*Conn) SetDefaultSink ¶
SetDefaultSink makes the named sink the default.
func (*Conn) SetDefaultSource ¶
SetDefaultSource makes the named source the default.
func (*Conn) SetSinkInputMute ¶
SetSinkInputMute mutes or unmutes a playback stream.
func (*Conn) SetSinkInputVolume ¶
SetSinkInputVolume sets a playback stream's volume.
func (*Conn) SetSinkMute ¶
SetSinkMute mutes or unmutes a sink by index.
func (*Conn) SetSinkPort ¶
SetSinkPort switches a sink's active port.
func (*Conn) SetSinkVolume ¶
SetSinkVolume sets a sink's per-channel volume by index.
func (*Conn) SetSourceMute ¶
SetSourceMute mutes or unmutes a source by index.
func (*Conn) SetSourceOutputMute ¶
SetSourceOutputMute mutes or unmutes a recording stream.
func (*Conn) SetSourceOutputVolume ¶
SetSourceOutputVolume sets a recording stream's volume.
func (*Conn) SetSourcePort ¶
SetSourcePort switches a source's active port.
func (*Conn) SetSourceVolume ¶
SetSourceVolume sets a source's per-channel volume 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) SourceOutput ¶
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 ¶
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.
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).
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).
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 ¶
FormatInfo is pa_format_info.
type Operation ¶
type Operation uint32
Operation is a subscription event's change kind (PA_SUBSCRIPTION_EVENT_TYPE_MASK bits).
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. Close waits for a call still
// running, unless the call is Close's caller.
OnSubscribe func(SubscribeEvent)
}
Options configures Dial.
type Packet ¶
Packet is a decoded command packet: the command, its tag, and the tagstruct body after the two header fields.
func DecodePacket ¶
DecodePacket splits a control-channel payload into its header and body. A payload without the two header fields is ErrProtocol.
type PlaybackInfo ¶
type PlaybackInfo struct {
SinkInput uint32
MaxLength uint32
TargetLength uint32
PreBuffer uint32
MinRequest uint32
SampleSpec SampleSpec
ChannelMap ChannelMap
SinkIndex uint32
SinkName string
Suspended bool
Latency uint64
Format FormatInfo
}
PlaybackInfo is what the server granted for a playback stream. Latency is the sink's, in microseconds.
type PlaybackParams ¶
type PlaybackParams struct {
// SampleSpec is the format Write takes; the server converts from it.
SampleSpec SampleSpec
// ChannelMap must have SampleSpec.Channels entries.
ChannelMap ChannelMap
// Sink is the sink name; empty plays on the default.
Sink string
// Latency is the target from a written byte to the speaker; zero
// lets the server choose.
Latency time.Duration
// Props become the stream's proplist (media.name and friends).
Props PropList
}
PlaybackParams describes a playback stream.
type PlaybackStream ¶
type PlaybackStream struct {
// contains filtered or unexported fields
}
PlaybackStream is a live playback stream: Write feeds it as the server requests audio and Cork pauses it. Its volume and mute are the sink input Info().SinkInput names (SetSinkInputVolume).
func (*PlaybackStream) Close ¶
func (s *PlaybackStream) Close(ctx context.Context) error
Close deletes the stream: a blocked Write returns ErrClosed. A stream that already ended closes without a request.
func (*PlaybackStream) Cork ¶
func (s *PlaybackStream) Cork(ctx context.Context, corked bool) error
Cork pauses (true) or resumes (false) playback. A corked stream keeps what it buffered and requests nothing until it is uncorked.
func (*PlaybackStream) Ended ¶
func (l *PlaybackStream) 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 (*PlaybackStream) Err ¶
func (l *PlaybackStream) Err() error
Err reports why the stream ended; nil while it runs.
func (*PlaybackStream) Info ¶
func (s *PlaybackStream) Info() PlaybackInfo
Info is what the server granted.
func (*PlaybackStream) Write ¶
func (s *PlaybackStream) Write(ctx context.Context, p []byte) error
Write sends p, whole frames in the stream's sample spec, as fast as the server requests audio, and returns once all of it is sent. A corked stream requests nothing, so Write then waits until the stream is uncorked, ends, or ctx is done. Write does not allocate; it is for one writer at a time.
type PropList ¶
PropList is a pa_proplist restricted to its string entries: binary values are dropped on decode, as libpulse's pa_proplist_gets 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 (*Reader) PropList ¶
PropList reads a 'P' field, keeping the entries whose value is a NUL-terminated UTF-8 string.
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 (l *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 (l *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 ¶
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 a known format; anything else is "Unknown".
type SamplePlay ¶
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 ¶
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 ¶
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) ChannelMap ¶
func (w *Writer) ChannelMap(m ChannelMap)
ChannelMap appends a 'm' field.
func (*Writer) FormatInfo ¶
func (w *Writer) FormatInfo(f FormatInfo)
FormatInfo appends an 'f' field.
func (*Writer) OptString ¶
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 ¶
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) SampleSpec ¶
func (w *Writer) SampleSpec(s SampleSpec)
SampleSpec appends an 'a' field.