AlexxIT/go2rtc · error
[alsa] set sw_params
Error message
[alsa] set sw_params: %w
What it means
The SNDRV_PCM_IOCTL_SW_PARAMS ioctl failed while applying software parameters (period step, avail_min, start/stop thresholds) to the ALSA PCM device. Wraps the kernel errno; usually the software params are inconsistent with previously set hardware params. Called by Start and AddTrack.
Solutions
- Retry after re-negotiating hardware params
- Verify the device is not busy or in an invalid state (restart the stream)
- Check dmesg for ALSA driver errors
Defensive patterns
Strategy: retry
When it happens
Trigger: Thrown at pkg/alsa/device/device_linux.go:159 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of AlexxIT/go2rtc@c245815e75 (2026-09-07).
Data as JSON: /api/errors/0ec5cb71e2f95e39.
Report an issue: GitHub.
Appendix: source
Thrown at pkg/alsa/device/device_linux.go:159
_, periods := d.getInterval(SNDRV_PCM_HW_PARAM_PERIODS)
_, periodSize := d.getInterval(SNDRV_PCM_HW_PARAM_PERIOD_SIZE)
threshold := snd_pcm_uframes_t(periods * periodSize) // same as bufferSize
swparams := snd_pcm_sw_params{
//tstamp_mode: SNDRV_PCM_TSTAMP_ENABLE,
period_step: 1,
avail_min: 1, // start as soon as possible
stop_threshold: threshold,
}
if d.IsCapture() {
swparams.start_threshold = 1
} else {
swparams.start_threshold = threshold
}
if err := ioctl(d.fd, SNDRV_PCM_IOCTL_SW_PARAMS, &swparams); err != nil {
return fmt.Errorf("[alsa] set sw_params: %w", err)
}
if err := ioctl(d.fd, SNDRV_PCM_IOCTL_PREPARE, nil); err != nil {
return fmt.Errorf("[alsa] prepare: %w", err)
}
return nil
}
func (d *Device) Write(b []byte) (n int, err error) {
xfer := &snd_xferi{
buf: uintptr(unsafe.Pointer(&b[0])),
frames: snd_pcm_uframes_t(len(b) / d.frameBytes),
}
err = ioctl(d.fd, SNDRV_PCM_IOCTL_WRITEI_FRAMES, xfer)
if err == syscall.EPIPE {
// auto handle underrun state
// https://stackoverflow.com/questions/59396728/how-to-properly-handle-xrun-in-alsa-programming-when-playing-audio-with-snd-pcmView on GitHub (pinned to c245815e75)