pulseaudio

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2022 License: MIT Imports: 18 Imported by: 0

README

pulseaudio GoDoc

Package pulseaudio is a pure-Go (no libpulse) implementation of the PulseAudio native protocol.

Download:

go get mrogalski.eu/go/pulseaudio

Package pulseaudio is a pure-Go (no libpulse) implementation of the PulseAudio native protocol.

Rather than exposing the PulseAudio protocol directly this library attempts to hide the PulseAudio complexity behind a Go interface. Some of the things which are deliberately not exposed in the API are:

→ backwards compatibility for old PulseAudio servers

→ transport mechanism used for the connection (Unix sockets / memfd / shm)

→ encoding used in the pulseaudio-native protocol

Working features

Querying and setting the volume.

Listing audio outputs.

Changing the default audio output.

Notifications on config updates.


Automatically generated by autoreadme on 2018.06.22

Documentation

Overview

Package pulseaudio is a pure-Go (no libpulse) implementation of the PulseAudio native protocol.

Rather than exposing the PulseAudio protocol directly this library attempts to hide the PulseAudio complexity behind a Go interface. Some of the things which are deliberately not exposed in the API are:

→ backwards compatibility for old PulseAudio servers

→ transport mechanism used for the connection (Unix sockets / memfd / shm)

→ encoding used in the pulseaudio-native protocol

Working features

Querying and setting the volume.

Listing audio outputs.

Changing the default audio output.

Notifications on config updates.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrClientClosed        = errors.New("pulseaudio client was closed")
	ErrClientDisabled      = errors.New("client disabled")
	ErrCouldNotSendRequest = errors.New("could not send packet")
)
View Source
var ErrSinkNotFound = errs.New("sink not found in output")

Functions

This section is empty.

Types

type CVolume

type CVolume []uint32

func (*CVolume) ReadFrom

func (v *CVolume) ReadFrom(r io.Reader) (int64, error)

type Card

type Card struct {
	Index         uint32
	Name          string
	Module        uint32
	Driver        string
	Profiles      map[string]*Profile
	ActiveProfile *Profile
	PropList      map[string]string
	Ports         []Port
}

type ChannelMap

type ChannelMap []byte

func (*ChannelMap) ReadFrom

func (m *ChannelMap) ReadFrom(r io.Reader) (int64, error)

type CliClient

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

func NewCliClient

func NewCliClient(defaultSink string, logger Logger) *CliClient

func (*CliClient) Mute

func (cli *CliClient) Mute() (bool, error)

func (*CliClient) SetMute

func (cli *CliClient) SetMute(mute bool) error

func (*CliClient) SetVolume

func (cli *CliClient) SetVolume(volume float32) error

func (*CliClient) Volume

func (cli *CliClient) Volume() (float32, error)

type Client

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

Client maintains a connection to the PulseAudio server.

func NewClient

func NewClient(opts Opts) *Client

NewClient establishes a connection to the PulseAudio server.

func (*Client) Cards

func (c *Client) Cards(ctx context.Context) ([]Card, error)

func (*Client) Close

func (c *Client) Close()

func (*Client) Connect added in v0.2.0

func (c *Client) Connect(ctx context.Context, interval time.Duration, wg *sync.WaitGroup)

func (*Client) Modules

func (c *Client) Modules(ctx context.Context) ([]Module, error)

func (*Client) Mute

func (c *Client) Mute(ctx context.Context) (bool, error)

func (*Client) Outputs

func (c *Client) Outputs(ctx context.Context) (outputs []Output, activeIndex int, err error)

Outputs returns a list of all audio outputs and an index of the active audio output.

The last audio output is always called "None" and indicates that audio is disabled.

func (*Client) ServerInfo

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

func (*Client) SetCardProfile

func (c *Client) SetCardProfile(ctx context.Context, cardIndex uint32, profileName string) error

func (*Client) SetMute

func (c *Client) SetMute(ctx context.Context, mute bool) error

SetMute reverse mute status

func (*Client) SetSinkMute

func (c *Client) SetSinkMute(ctx context.Context, sinkName string, mute bool) error

SetSinkMute reverse mute status

func (*Client) SetSinkVolume

func (c *Client) SetSinkVolume(ctx context.Context, sinkName string, volume float32) error

func (*Client) SetVolume

func (c *Client) SetVolume(ctx context.Context, volume float32) error

SetVolume changes the current volume to a specified value from 0 to 1 (or more than 1 - if volume should be boosted).

func (*Client) Sinks

func (c *Client) Sinks(ctx context.Context) ([]Sink, error)

func (*Client) ToggleMute

func (c *Client) ToggleMute(ctx context.Context) (bool, error)

ToggleMute reverse mute status

func (*Client) Updates

func (c *Client) Updates(ctx context.Context) (updates <-chan struct{}, err error)

Updates returns a channel with PulseAudio updates.

func (*Client) Volume

func (c *Client) Volume(ctx context.Context) (float32, error)

Volume returns current audio volume as a number from 0 to 1 (or more than 1 - if volume is boosted).

type ClientOpt

type ClientOpt func(*Client)

ClientOpt defines a client modifier routine

func WithDialTimeout added in v0.2.0

func WithDialTimeout(timeout time.Duration) ClientOpt

type Error

type Error struct {
	Cmd  string
	Code uint32
}

func (*Error) Error

func (err *Error) Error() string

type FormatInfo

type FormatInfo struct {
	Encoding byte
	PropList map[string]string
}

func (*FormatInfo) ReadFrom

func (i *FormatInfo) ReadFrom(r io.Reader) (int64, error)

type Logger

type Logger interface {
	Info(msg string)
	Infof(msg string, args ...interface{})
	Errorf(msg string, args ...interface{})
}

type Module

type Module struct {
	Index    uint32
	Name     string
	Argument string
	NUsed    uint32
	PropList map[string]string
}

func (*Module) ReadFrom

func (m *Module) ReadFrom(r io.Reader) (int64, error)

type Opts added in v0.3.0

type Opts struct {
	DialTimeout    time.Duration
	RequestTimeout time.Duration
	Logger         Logger
	Protocol       string
	Addr           string
	Cookie         string
}

Opts wraps all available config options

type Output

type Output struct {
	CardID    string
	PortID    string
	CardName  string
	PortName  string
	Available bool
	// contains filtered or unexported fields
}

Output represents PulseAudio output.

func (Output) Activate

func (o Output) Activate(ctx context.Context) error

Activate sets this output as the main one.

type Port

type Port struct {
	Card              *Card
	Name, Description string
	Pririty           uint32
	Available         uint32
	Direction         byte
	PropList          map[string]string
	Profiles          []*Profile
	LatencyOffset     int64
}

func (*Port) ReadFrom

func (p *Port) ReadFrom(r io.Reader) (int64, error)

type Profile

type Profile struct {
	Name, Description string
	Nsinks, Nsources  uint32
	Priority          uint32
	Available         uint32
}

type SampleSpec

type SampleSpec struct {
	Format   byte
	Channels byte
	Rate     uint32
}

func (*SampleSpec) ReadFrom

func (s *SampleSpec) ReadFrom(r io.Reader) (int64, error)

type Server

type Server struct {
	PackageName    string
	PackageVersion string
	User           string
	Hostname       string
	SampleSpec     SampleSpec
	DefaultSink    string
	DefaultSource  string
	Cookie         uint32
	ChannelMap     ChannelMap
}

func (*Server) ReadFrom

func (s *Server) ReadFrom(r io.Reader) (int64, error)

type Sink

type Sink struct {
	Index              uint32
	Name               string
	Description        string
	SampleSpec         SampleSpec
	ChannelMap         ChannelMap
	ModuleIndex        uint32
	CVolume            CVolume
	Muted              bool
	MonitorSourceIndex uint32
	MonitorSourceName  string
	Latency            uint64
	Driver             string
	Flags              uint32
	PropList           map[string]string
	RequestedLatency   uint64
	BaseVolume         uint32
	SinkState          uint32
	NVolumeSteps       uint32
	CardIndex          uint32
	Ports              []SinkPort
	ActivePortName     string
	Formats            []FormatInfo
}

func (*Sink) ReadFrom

func (s *Sink) ReadFrom(r io.Reader) (int64, error)

type SinkPort

type SinkPort struct {
	Name, Description string
	Priority          uint32
	Available         uint32
}

func (*SinkPort) ReadFrom

func (p *SinkPort) ReadFrom(r io.Reader) (int64, error)

Jump to

Keyboard shortcuts

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