Documentation
¶
Overview ¶
Package audio defines bounded, transport-free audio device observation and caller-selected capture or playback. It opens no device, process, or connection itself: a backend such as the PulseAudio or ALSA adapter implements the interfaces, and the consumer selects the device and grants access.
Index ¶
- Constants
- Variables
- func Code(err error) string
- func ValidatePacket(packet media.PCM16, limits Limits) error
- func ValidateSnapshot(snapshot Snapshot, limits Limits) error
- type CaptureBackend
- type Device
- type Kind
- type Limits
- type Observer
- type ObserverFunc
- type PlaybackBackend
- type Sink
- type Snapshot
- type Source
- type Status
Constants ¶
const ( // DefaultMaxDevices bounds one observation. DefaultMaxDevices = 64 // MaxDevices is the library ceiling for MaxDevices. MaxDevices = 1024 // DefaultMaxPacketBytes bounds one read or written PCM packet. DefaultMaxPacketBytes = 192_000 // MaxPacketBytes is the library ceiling for MaxPacketBytes. MaxPacketBytes = 1 << 20 )
Variables ¶
Functions ¶
func Code ¶ added in v0.4.0
Code is the stable error code of err for another language to match: invalid, too_large or unavailable. It is empty for an error this package does not define.
func ValidatePacket ¶
ValidatePacket checks PCM format, alignment, and the caller's packet ceiling: a packet with no data, a rate outside 8 to 192 kHz, 1 to 8 channels or a size that is not whole frames is invalid, and one over the ceiling is too large. The format is judged first.
func ValidateSnapshot ¶
ValidateSnapshot checks identity, kind, format, and device bounds.
Types ¶
type CaptureBackend ¶
CaptureBackend opens a bounded source for one caller-selected device.
type Device ¶
type Device struct {
ID string `json:"id"`
Name string `json:"name"`
Kind Kind `json:"kind"`
State string `json:"state,omitempty"`
SampleFormat string `json:"sample_format,omitempty"`
SampleRate int `json:"sample_rate,omitempty"`
Channels int `json:"channels,omitempty"`
}
Device is one observed endpoint. ID is backend-local and opaque to the library; Name is display metadata. Sample values are zero when the backend does not know them.
type Kind ¶
type Kind string
Kind classifies a device without exposing a native endpoint or routing rule.
type Limits ¶
type Limits struct {
MaxDevices int `json:"max_devices"`
MaxPacketBytes int `json:"max_packet_bytes"`
}
Limits bound an observation and one PCM packet. Zero values select defaults.
type Observer ¶
Observer reports caller-visible local audio devices. It sends no audio and starts no stream.
type ObserverFunc ¶
type PlaybackBackend ¶
PlaybackBackend opens a bounded sink for one caller-selected device.
type Snapshot ¶
type Snapshot struct {
Backend string `json:"backend"`
ObservedAt time.Time `json:"observed_at"`
Devices []Device `json:"devices"`
Status Status `json:"status"`
}
Snapshot is one bounded observation. Backend names the selected native mechanism for diagnostics; the library never chooses it.
type Source ¶
Source produces bounded PCM16 packets. Read must respect the limits supplied when the source was opened and must not block forever after context cancellation.
type Status ¶
type Status struct {
State string `json:"state"`
Reason string `json:"reason,omitempty"`
Detail string `json:"detail,omitempty"`
}
Status distinguishes an empty device list from an unavailable backend. State is complete, partial or unsupported; an unsupported status says why in Reason, from the set every package shares (testdata/capability/v1): unsupported on this platform, or tool_missing when the native tool is not installed (the adapter that owns the tool reports that).