Documentation
¶
Overview ¶
Package pulse implements the pulseaudio protocol in pure go.
Index ¶
- Constants
- type Client
- func (c *Client) Close()
- func (c *Client) DefaultSink() (*Sink, error)
- func (c *Client) DefaultSource() (*Source, error)
- func (c *Client) ListSinks() ([]*Sink, error)
- func (c *Client) ListSources() ([]*Source, error)
- func (c *Client) NewPlayback(r Reader, opts ...PlaybackOption) (*PlaybackStream, error)
- func (c *Client) NewRecord(w Writer, opts ...RecordOption) (*RecordStream, error)
- func (c *Client) RawRequest(req proto.RequestArgs, rpl proto.Reply) error
- func (c *Client) SetDefaultSink(sinkName string) error
- func (c *Client) SetSinkPort(sinkIndex uint32, sinkName, port string) error
- func (c *Client) SetSinkVolume(sinkIndex uint32, sinkName string, volume float64) error
- func (c *Client) SinkByID(name string) (*Sink, error)
- func (c *Client) SinkMuteToggle(sinkIndex uint32, sinkName string) error
- func (c *Client) SourceByID(name string) (*Source, error)
- type ClientOption
- type Float32Reader
- type Float32Writer
- type Int16Reader
- type Int16Writer
- type Int32Reader
- type Int32Writer
- type PlaybackOption
- func PlaybackBufferSize(samples int) PlaybackOption
- func PlaybackChannels(m proto.ChannelMap) PlaybackOption
- func PlaybackLatency(seconds float64) PlaybackOption
- func PlaybackMediaIconName(name string) PlaybackOption
- func PlaybackMediaName(name string) PlaybackOption
- func PlaybackRawOption(o func(*proto.CreatePlaybackStream)) PlaybackOption
- func PlaybackSampleRate(rate int) PlaybackOption
- func PlaybackSink(sink *Sink) PlaybackOption
- type PlaybackStream
- func (p *PlaybackStream) BufferSize() int
- func (p *PlaybackStream) BufferSizeBytes() int
- func (p *PlaybackStream) Channels() int
- func (p *PlaybackStream) Close()
- func (p *PlaybackStream) Closed() bool
- func (p *PlaybackStream) Drain()
- func (p *PlaybackStream) Error() error
- func (p *PlaybackStream) Pause()
- func (p *PlaybackStream) Resume()
- func (p *PlaybackStream) Running() bool
- func (p *PlaybackStream) SampleRate() int
- func (p *PlaybackStream) Start()
- func (p *PlaybackStream) Stop()
- func (p *PlaybackStream) StreamIndex() uint32
- func (p *PlaybackStream) StreamInputIndex() uint32
- func (p *PlaybackStream) Underflow() bool
- type Reader
- type RecordOption
- func RecordBufferFragmentSize(size uint32) RecordOption
- func RecordChannels(m proto.ChannelMap) RecordOption
- func RecordLatency(seconds float64) RecordOption
- func RecordMediaIconName(name string) RecordOption
- func RecordMediaName(name string) RecordOption
- func RecordMonitor(sink *Sink) RecordOption
- func RecordRawOption(o func(*proto.CreateRecordStream)) RecordOption
- func RecordSampleRate(rate int) RecordOption
- func RecordSource(source *Source) RecordOption
- type RecordStream
- func (r *RecordStream) Channels() int
- func (r *RecordStream) Close()
- func (r *RecordStream) Closed() bool
- func (r *RecordStream) Error() error
- func (r *RecordStream) Running() bool
- func (r *RecordStream) SampleRate() int
- func (r *RecordStream) Start()
- func (r *RecordStream) Stop()
- func (r *RecordStream) StreamIndex() uint32
- type Sink
- type Source
- type Uint8Reader
- type Uint8Writer
- type Writer
Constants ¶
const EndOfData endOfData = false
EndOfData is a special error value that can be returned by a reader to stop the stream.
const ErrConnectionClosed = pulseError("pulseaudio: connection closed")
ErrConnectionClosed is a special error value indicating that the server closed the connection.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
The Client is the connection to the pulseaudio server. An application typically only uses a single client.
func NewClient ¶
func NewClient(opts ...ClientOption) (*Client, error)
NewClient connects to the server.
func (*Client) Close ¶
func (c *Client) Close()
Close closes the client. Calling methods on a closed client may panic.
func (*Client) DefaultSink ¶
DefaultSink returns the default output device.
func (*Client) DefaultSource ¶
DefaultSource returns the default input device.
func (*Client) ListSources ¶
ListSources returns a list of all available input devices.
func (*Client) NewPlayback ¶
func (c *Client) NewPlayback(r Reader, opts ...PlaybackOption) (*PlaybackStream, error)
NewPlayback creates a playback stream. The created stream wil not be running, it must be started with Start(). If the reader returns any error, the stream will be stopped. The special error value EndOfData can be used to intentionally stop the stream from within the callback. The order of options is important in some cases, see the documentation of the individual PlaybackOptions.
func (*Client) NewRecord ¶
func (c *Client) NewRecord(w Writer, opts ...RecordOption) (*RecordStream, error)
NewRecord creates a record stream. If the reader returns any error, the stream will be stopped. The created stream wil not be running, it must be started with Start(). The order of options is important in some cases, see the documentation of the individual RecordOptions.
func (*Client) RawRequest ¶
RawRequest can be used to send arbitrary requests.
req should be one of the request types defined by the proto package.
rpl must be a pointer to the correct reply type or nil. This funcion will panic if rpl has the wrong type.
The returned error can be compared against errors defined by the proto package to check for specific errors.
The function will always block until the server has replied, even if rpl is nil.
func (*Client) SetDefaultSink ¶
SetDefaultSink sets the default sink.
func (*Client) SetSinkPort ¶
SetSinkPort sets port to the sink.
func (*Client) SetSinkVolume ¶ added in v0.0.3
SetSinkVolume toggles mute on a sink.
func (*Client) SinkMuteToggle ¶ added in v0.0.3
SinkMuteToggle toggles mute on a sink.
type ClientOption ¶
type ClientOption func(*Client)
A ClientOption supplies configuration when creating the client.
func ClientApplicationIconName ¶
func ClientApplicationIconName(name string) ClientOption
ClientApplicationIconName sets the application icon using an xdg icon name. This will e.g. be displayed by a volume control application to identity the application.
func ClientApplicationName ¶
func ClientApplicationName(name string) ClientOption
ClientApplicationName sets the application name. This will e.g. be displayed by a volume control application to identity the application. It should be human-readable and localized.
func ClientServerString ¶
func ClientServerString(s string) ClientOption
ClientServerString will override the default server strings. Server strings are used to connect to the server. For the server string format see https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/ServerStrings/
type Float32Reader ¶
Float32Reader implements the Reader interface. The semantics are the same as io.Reader's Read, but it returns the number of float32 values read, not the number of bytes.
func (Float32Reader) Format ¶
func (c Float32Reader) Format() byte
type Float32Writer ¶
Float32Writer implements the Writer interface. The semantics are the same as io.Writer's Write, but it returns the number of float32 values written, not the number of bytes.
func (Float32Writer) Format ¶
func (c Float32Writer) Format() byte
type Int16Reader ¶
Int16Reader implements the Reader interface. The semantics are the same as io.Reader's Read, but it returns the number of int16 values read, not the number of bytes.
func (Int16Reader) Format ¶
func (c Int16Reader) Format() byte
type Int16Writer ¶
Int16Writer implements the Writer interface. The semantics are the same as io.Writer's Write, but it returns the number of int16 values written, not the number of bytes.
func (Int16Writer) Format ¶
func (c Int16Writer) Format() byte
type Int32Reader ¶
Int32Reader implements the Reader interface. The semantics are the same as io.Reader's Read, but it returns the number of int32 values read, not the number of bytes.
func (Int32Reader) Format ¶
func (c Int32Reader) Format() byte
type Int32Writer ¶
Int32Writer implements the Writer interface. The semantics are the same as io.Writer's Write, but it returns the number of int32 values written, not the number of bytes.
func (Int32Writer) Format ¶
func (c Int32Writer) Format() byte
type PlaybackOption ¶
type PlaybackOption func(*PlaybackStream)
A PlaybackOption supplies configuration when creating streams.
var PlaybackMono PlaybackOption = func(p *PlaybackStream) { p.createRequest.ChannelMap = proto.ChannelMap{proto.ChannelMono} p.createRequest.Channels = 1 }
PlaybackMono sets a stream to a single channel.
var PlaybackStereo PlaybackOption = func(p *PlaybackStream) { p.createRequest.ChannelMap = proto.ChannelMap{proto.ChannelLeft, proto.ChannelRight} p.createRequest.Channels = 2 }
PlaybackStereo sets a stream to two channels.
func PlaybackBufferSize ¶
func PlaybackBufferSize(samples int) PlaybackOption
PlaybackBufferSize sets the size of the server-side buffer. Setting the buffer size too small causes underflows, resulting in audible artifacts.
Buffer size and latency should not be set at the same time.
func PlaybackChannels ¶
func PlaybackChannels(m proto.ChannelMap) PlaybackOption
PlaybackChannels sets a stream to use a custom channel map.
func PlaybackLatency ¶
func PlaybackLatency(seconds float64) PlaybackOption
PlaybackLatency sets the stream's latency in seconds. Setting the latency too low causes underflows, resulting in audible artifacts. Applications should generally use the highest acceptable latency.
This should be set after sample rate and channel options.
Buffer size and latency should not be set at the same time.
func PlaybackMediaIconName ¶
func PlaybackMediaIconName(name string) PlaybackOption
PlaybackMediaIconName sets the streams media icon using an xdg icon name. This will e.g. be displayed by a volume control application to identity the stream.
func PlaybackMediaName ¶
func PlaybackMediaName(name string) PlaybackOption
PlaybackMediaName sets the streams media name. This will e.g. be displayed by a volume control application to identity the stream.
func PlaybackRawOption ¶
func PlaybackRawOption(o func(*proto.CreatePlaybackStream)) PlaybackOption
PlaybackRawOption can be used to create custom options.
This is an advanced function, similar to (*Client).RawRequest.
func PlaybackSampleRate ¶
func PlaybackSampleRate(rate int) PlaybackOption
PlaybackSampleRate sets the stream's sample rate.
func PlaybackSink ¶
func PlaybackSink(sink *Sink) PlaybackOption
PlaybackSink sets the sink the stream should send audio to.
type PlaybackStream ¶
type PlaybackStream struct {
// contains filtered or unexported fields
}
A PlaybackStream is used for playing audio. When creating a stream, the user must provide a callback that will be used to buffer audio data.
func (*PlaybackStream) BufferSize ¶
func (p *PlaybackStream) BufferSize() int
BufferSize returns the size of the server-side buffer in samples.
func (*PlaybackStream) BufferSizeBytes ¶
func (p *PlaybackStream) BufferSizeBytes() int
BufferSizeBytes returns the size of the server-side buffer in bytes.
func (*PlaybackStream) Channels ¶
func (p *PlaybackStream) Channels() int
Channels returns the number of channels.
func (*PlaybackStream) Closed ¶
func (p *PlaybackStream) Closed() bool
Closed returns wether the stream was closed.
func (*PlaybackStream) Drain ¶
func (p *PlaybackStream) Drain()
Drain waits until the playback has ended. Drain does not return when the stream is paused.
func (*PlaybackStream) Error ¶
func (p *PlaybackStream) Error() error
Error returns the last error returned by the stream's reader.
func (*PlaybackStream) Pause ¶
func (p *PlaybackStream) Pause()
Pause stops playing audio immediately.
func (*PlaybackStream) Running ¶
func (p *PlaybackStream) Running() bool
Running returns wether the stream is currently playing.
func (*PlaybackStream) SampleRate ¶
func (p *PlaybackStream) SampleRate() int
SampleRate returns the stream's sample rate (samples per second).
func (*PlaybackStream) Stop ¶
func (p *PlaybackStream) Stop()
Stop stops playing audio; the callback will no longer be called. If the buffer size/latency is large, audio may continue to play for some time after the call to Stop.
func (*PlaybackStream) StreamIndex ¶
func (p *PlaybackStream) StreamIndex() uint32
StreamIndex returns the stream index. This should only be used together with (*Cient).RawRequest.
func (*PlaybackStream) StreamInputIndex ¶
func (p *PlaybackStream) StreamInputIndex() uint32
func (*PlaybackStream) Underflow ¶
func (p *PlaybackStream) Underflow() bool
Underflow returns true if any underflows happend since the last call to Start or Resume. Underflows usually happen because the latency/buffer size is too low or because the callback takes too long to run.
type Reader ¶
type Reader interface { io.Reader Format() byte // Format should return one of the format constants defined by the proto package }
A Reader provides audio data in a specific format.
type RecordOption ¶
type RecordOption func(*RecordStream)
A RecordOption supplies configuration when creating streams.
var RecordMono RecordOption = func(r *RecordStream) { r.createRequest.ChannelMap = proto.ChannelMap{proto.ChannelMono} r.createRequest.Channels = 1 }
RecordMono sets a stream to a single channel.
var RecordStereo RecordOption = func(r *RecordStream) { r.createRequest.ChannelMap = proto.ChannelMap{proto.ChannelLeft, proto.ChannelRight} r.createRequest.Channels = 2 }
RecordStereo sets a stream to two channels.
func RecordBufferFragmentSize ¶
func RecordBufferFragmentSize(size uint32) RecordOption
RecordBufferFragmentSize sets the fragment size. This is the size (in bytes) of the buffer passed to the callback. Lower values reduce latency, at the cost of more overhead.
Fragment size and latency should not be set at the same time.
func RecordChannels ¶
func RecordChannels(m proto.ChannelMap) RecordOption
RecordChannels sets a stream to use a custom channel map.
func RecordLatency ¶
func RecordLatency(seconds float64) RecordOption
RecordLatency sets the stream's latency in seconds.
This should be set after sample rate and channel options.
Fragment size and latency should not be set at the same time.
func RecordMediaIconName ¶
func RecordMediaIconName(name string) RecordOption
RecordMediaIconName sets the streams media icon using an xdg icon name. This will e.g. be displayed by a volume control application to identity the stream.
func RecordMediaName ¶
func RecordMediaName(name string) RecordOption
RecordMediaName sets the streams media name. This will e.g. be displayed by a volume control application to identity the stream.
func RecordMonitor ¶
func RecordMonitor(sink *Sink) RecordOption
RecordMonitor sets the stream to receive audio sent to the sink.
func RecordRawOption ¶
func RecordRawOption(o func(*proto.CreateRecordStream)) RecordOption
RecordRawOption can be used to create custom options.
This is an advanced function, similar to (*Client).RawRequest.
func RecordSampleRate ¶
func RecordSampleRate(rate int) RecordOption
RecordSampleRate sets the stream's sample rate.
func RecordSource ¶
func RecordSource(source *Source) RecordOption
RecordSource sets the source the stream should receive audio from.
type RecordStream ¶
type RecordStream struct {
// contains filtered or unexported fields
}
A RecordStream is used for recording audio. When creating a stream, the user must provide a callback that will be called with the recorded audio data.
func (*RecordStream) Channels ¶
func (r *RecordStream) Channels() int
Channels returns the number of channels.
func (*RecordStream) Closed ¶
func (r *RecordStream) Closed() bool
Closed returns wether the stream was closed. Calling other methods on a closed stream may panic.
func (*RecordStream) Error ¶
func (r *RecordStream) Error() error
Error returns the last error returned by the stream's writer.
func (*RecordStream) Running ¶
func (r *RecordStream) Running() bool
Running returns wether the stream is currently recording.
func (*RecordStream) SampleRate ¶
func (r *RecordStream) SampleRate() int
SampleRate returns the stream's sample rate (samples per second).
func (*RecordStream) Stop ¶
func (r *RecordStream) Stop()
Stop stops recording audio; the callback will no longer be called.
func (*RecordStream) StreamIndex ¶
func (r *RecordStream) StreamIndex() uint32
StreamIndex returns the stream index. This should only be used together with (*Cient).RawRequest.
type Sink ¶
type Sink struct {
// contains filtered or unexported fields
}
A Sink is an output device.
func (*Sink) Channels ¶
func (s *Sink) Channels() proto.ChannelMap
Channels returns the default channel map.
func (*Sink) ID ¶
ID returns the sink name. Sink names are unique identifiers, but not necessarily human-readable.
func (*Sink) Info ¶
func (s *Sink) Info() proto.GetSinkInfoReply
Info is a helper method that exposes Sink properties.
func (*Sink) SampleRate ¶
SampleRate returns the default sample rate.
type Source ¶
type Source struct {
// contains filtered or unexported fields
}
A Source is an input device.
func (*Source) Channels ¶
func (s *Source) Channels() proto.ChannelMap
Channels returns the default channel map.
func (*Source) ID ¶
ID returns the source name. Source names are unique identifiers, but not necessarily human-readable.
func (*Source) SampleRate ¶
SampleRate returns the default sample rate.
func (*Source) SourceIndex ¶
SourceIndex returns the source index. This should only be used together with (*Cient).RawRequest.
type Uint8Reader ¶
Uint8Reader implements the Reader interface. The semantics are the same as io.Reader's Read.
func (Uint8Reader) Format ¶
func (c Uint8Reader) Format() byte
type Uint8Writer ¶
Uint8Writer implements the Writer interface. The semantics are the same as io.Writer's Write.
func (Uint8Writer) Format ¶
func (c Uint8Writer) Format() byte