pulseaudio

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2022 License: MIT Imports: 15 Imported by: 2

README

pulseaudio GoDoc

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

Download:

go get github.com/the-jonsey/pulseaudio

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

This library is a fork of https://github.com/mafik/pulseaudio The original library deliberately tries to hide pulseaudio internals and doesn't expose them.

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

→ wors with pipewire as long as pipewire-pulse is installed and running

Working features

Querying and setting the volume.

Querying and setting mute.

Listing audio sinks/sources/outputs/inputs.

Changing the default audio output.

Notifications on config updates.

Filtering config update notifications by event type.

Documentation

Index

Constants

View Source
const (
	SUBSCRIPTION_MASK_ALL           DevType = 0x02ff
	SUBSCRIPTION_MASK_AUTOLOAD              = 0x0100
	SUBSCRIPTION_MASK_CARD                  = 0x0200
	SUBSCRIPTION_MASK_CLIENT                = 0x0020
	SUBSCRIPTION_MASK_MODULE                = 0x0010
	SUBSCRIPTION_MASK_NULL                  = 0x0000
	SUBSCRIPTION_MASK_SAMPLE_CACHE          = 0x0040
	SUBSCRIPTION_MASK_SERVER                = 0x0080
	SUBSCRIPTION_MASK_SINK                  = 0x0001
	SUBSCRIPTION_MASK_SINK_INPUT            = 0x0004
	SUBSCRIPTION_MASK_SOURCE                = 0x0002
	SUBSCRIPTION_MASK_SOURCE_OUTPUT         = 0x0008
)

Variables

This section is empty.

Functions

func RuntimePath

func RuntimePath(fn string) (string, error)

RuntimePath resolves a file in the pulse runtime path E.g. pass "native" to get the address for pulse' native socket Original implementation: https://github.com/pulseaudio/pulseaudio/blob/6c58c69bb6b937c1e758410d3114fc3bc0606fbe/src/pulsecore/core-util.c Except we do not support legacy $HOME paths

Types

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 Client

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

Client maintains a connection to the PulseAudio server.

func NewClient

func NewClient(addressArr ...string) (*Client, error)

NewClient establishes a connection to the PulseAudio server.

func (*Client) Cards

func (c *Client) Cards() ([]Card, error)

func (*Client) Close

func (c *Client) Close()

Close closes the connection to PulseAudio server and makes the Client unusable.

func (*Client) Connected

func (c *Client) Connected() bool

Connected returns a bool specifying if the connection to pulse is alive

func (*Client) GetDefaultSink

func (c *Client) GetDefaultSink() (Sink, error)

func (*Client) GetDefaultSource

func (c *Client) GetDefaultSource() (Source, error)

func (*Client) GetSinkInputByName

func (c *Client) GetSinkInputByName(name string) (SinkInput, error)

func (*Client) GetSourceOutputByName

func (c *Client) GetSourceOutputByName(name string) (SourceOutput, error)

func (*Client) LoadModule

func (c *Client) LoadModule(name string, argument string) (index uint32, err error)

LoadModule requests pulseaudio to load the module with the specified name and argument string. More information on how to supply these can be found in the pulseaudio documentation: https://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/Modules/#loadablemodules e.g. LoadModule("module-alsa-sink", "sink_name=headphones sink_properties=device.description=Headphones") would be equivalent to the pulse config directive: load-module module-alsa-sink sink_name=headphones sink_properties=device.description=Headphones Returns the index of the loaded module or an error

func (*Client) ModuleList

func (c *Client) ModuleList() ([]Module, error)

ModuleList queries pulseaudio for a list of loaded modules and returns an array

func (*Client) Mute

func (c *Client) Mute() (bool, error)

func (*Client) ServerInfo

func (c *Client) ServerInfo() (*Server, error)

ServerInfo queries the pulseaudio server for its information

func (*Client) SetCardProfile

func (c *Client) SetCardProfile(cardIndex uint32, profileName string) error

func (*Client) SetDefaultSink

func (c *Client) SetDefaultSink(sinkName string) error

func (*Client) SetMute

func (c *Client) SetMute(b bool) error

ToggleMute reverse mute status

func (*Client) SetSinkVolume

func (c *Client) SetSinkVolume(sinkName string, volume float32) error

func (*Client) SetVolume

func (c *Client) SetVolume(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) SinkInputs

func (c *Client) SinkInputs() ([]SinkInput, error)

Sinks queries PulseAudio for a list of sinks and returns an array

func (*Client) Sinks

func (c *Client) Sinks() ([]Sink, error)

Sinks queries PulseAudio for a list of sinks and returns an array

func (*Client) SourceOutputs

func (c *Client) SourceOutputs() ([]SourceOutput, error)

SourceOutputs queries PulseAudio for a list of source outputs and returns an array

func (*Client) Sources

func (c *Client) Sources() ([]Source, error)

Sources queries pulseaudio for a list of all it's sources and returns an array of them

func (*Client) ToggleMute

func (c *Client) ToggleMute() (bool, error)

ToggleMute reverse mute status

func (*Client) UnloadModule

func (c *Client) UnloadModule(index uint32) error

UnloadModule requests pulseaudio to unload the module with the specified index. The index can be found e.g. with ModuleList()

func (*Client) Updates

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

Updates returns a channel with PulseAudio updates.

func (*Client) UpdatesByType

func (c *Client) UpdatesByType(devType DevType) (updates <-chan struct{}, err error)

func (*Client) Volume

func (c *Client) Volume() (float32, error)

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

type DevType

type DevType int

type Device

type Device interface {
	SetVolume(volume float32) error
	SetMute(b bool) error
	ToggleMute() error
	IsMute() bool
	GetVolume() float32
}

type Error

type Error struct {
	Cmd  string
	Code uint32
}

func (*Error) Error

func (err *Error) Error() string

type Module

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

Module contains information about a pulseaudio module

func (*Module) ReadFrom

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

ReadFrom deserializes a PA module packet

type Server

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

Server contains information about the pulseaudio server

func (*Server) ReadFrom

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

ReadFrom deserializes a pulseaudio server info packet

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
	Client             *Client
}

Sink contains information about a sink in pulseaudio

func (Sink) GetVolume

func (s Sink) GetVolume() float32

func (Sink) IsMute

func (s Sink) IsMute() bool

func (*Sink) ReadFrom

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

ReadFrom deserializes a sink packet from pulseaudio

func (Sink) SetMute

func (s Sink) SetMute(b bool) error

func (Sink) SetVolume

func (s Sink) SetVolume(volume float32) error

func (Sink) ToggleMute

func (s Sink) ToggleMute() error

type SinkInput

type SinkInput struct {
	Index          uint32
	Name           string
	OwnerModule    uint32
	ClientIndex    uint32
	Sink           uint32
	SampleSpec     sampleSpec
	ChannelMap     channelMap
	Cvolume        cvolume
	BufferUsec     uint64
	SinkUsec       uint64
	ResampleMethod string
	Driver         string
	Muted          bool
	PropList       map[string]string
	Corked         bool
	HasVolume      bool
	VolumeWritable bool
	Format         formatInfo
	Client         *Client
}

SinkInput contains information about a sink in pulseaudio

func (SinkInput) GetVolume

func (s SinkInput) GetVolume() float32

func (SinkInput) IsMute

func (s SinkInput) IsMute() bool

func (*SinkInput) ReadFrom

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

ReadFrom deserializes a sink packet from pulseaudio

func (SinkInput) SetMute

func (s SinkInput) SetMute(b bool) error

func (SinkInput) SetVolume

func (s SinkInput) SetVolume(volume float32) error

func (SinkInput) ToggleMute

func (s SinkInput) ToggleMute() error

type Source

type Source 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
	Client             *Client
}

Source contains information about a source in pulseaudio, e.g. a microphone

func (Source) GetVolume

func (s Source) GetVolume() float32

func (Source) IsMute

func (s Source) IsMute() bool

func (*Source) ReadFrom

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

ReadFrom deserialized a PA source packet

func (Source) SetMute

func (s Source) SetMute(b bool) error

func (Source) SetVolume

func (s Source) SetVolume(volume float32) error

func (Source) ToggleMute

func (s Source) ToggleMute() error

type SourceOutput

type SourceOutput struct {
	Index          uint32
	Name           string
	OwnerModule    uint32
	ClientIndex    uint32
	Source         uint32
	SampleSpec     sampleSpec
	ChannelMap     channelMap
	Cvolume        cvolume
	BufferUsec     uint64
	SourceUsec     uint64
	ResampleMethod string
	Driver         string
	Muted          bool
	PropList       map[string]string
	Corked         bool
	HasVolume      bool
	VolumeWritable bool
	Format         formatInfo
	Client         *Client
}

SourceOutput contains information about a source output in pulseaudio

func (SourceOutput) GetVolume

func (s SourceOutput) GetVolume() float32

func (SourceOutput) IsMute

func (s SourceOutput) IsMute() bool

func (*SourceOutput) ReadFrom

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

ReadFrom deserializes a source output packet from pulseaudio

func (SourceOutput) SetMute

func (s SourceOutput) SetMute(b bool) error

func (SourceOutput) SetVolume

func (s SourceOutput) SetVolume(volume float32) error

func (SourceOutput) ToggleMute

func (s SourceOutput) ToggleMute() error

Jump to

Keyboard shortcuts

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