{"record":{"id":"8cb685093125571b","repo":"AlexxIT/go2rtc","slug":"alsa-prepare-w","errorCode":null,"errorMessage":"[alsa] prepare: %w","messagePattern":"\\[alsa\\] prepare: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/alsa/device/device_linux.go","lineNumber":163,"sourceCode":"\tswparams := snd_pcm_sw_params{\n\t\t//tstamp_mode: SNDRV_PCM_TSTAMP_ENABLE,\n\t\tperiod_step:    1,\n\t\tavail_min:      1, // start as soon as possible\n\t\tstop_threshold: threshold,\n\t}\n\n\tif d.IsCapture() {\n\t\tswparams.start_threshold = 1\n\t} else {\n\t\tswparams.start_threshold = threshold\n\t}\n\n\tif err := ioctl(d.fd, SNDRV_PCM_IOCTL_SW_PARAMS, &swparams); err != nil {\n\t\treturn fmt.Errorf(\"[alsa] set sw_params: %w\", err)\n\t}\n\n\tif err := ioctl(d.fd, SNDRV_PCM_IOCTL_PREPARE, nil); err != nil {\n\t\treturn fmt.Errorf(\"[alsa] prepare: %w\", err)\n\t}\n\n\treturn nil\n}\n\nfunc (d *Device) Write(b []byte) (n int, err error) {\n\txfer := &snd_xferi{\n\t\tbuf:    uintptr(unsafe.Pointer(&b[0])),\n\t\tframes: snd_pcm_uframes_t(len(b) / d.frameBytes),\n\t}\n\terr = ioctl(d.fd, SNDRV_PCM_IOCTL_WRITEI_FRAMES, xfer)\n\tif err == syscall.EPIPE {\n\t\t// auto handle underrun state\n\t\t// https://stackoverflow.com/questions/59396728/how-to-properly-handle-xrun-in-alsa-programming-when-playing-audio-with-snd-pcm\n\t\terr = ioctl(d.fd, SNDRV_PCM_IOCTL_PREPARE, nil)\n\t}\n\tn = int(xfer.result) * d.frameBytes\n\treturn","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/alsa/device/device_linux.go#L145-L181","documentation":"The SNDRV_PCM_IOCTL_PREPARE ioctl failed, so the ALSA PCM device could not be moved into the PREPARED state after hardware and software parameters were set. Wraps the errno; without preparation the device cannot start reading/writing. Called by Start and AddTrack.","triggerScenarios":"Thrown at pkg/alsa/device/device_linux.go:163 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Close and reopen the ALSA device, then re-run SetHWParams","Ensure no other process holds the PCM device","Check dmesg for ALSA driver errors"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"c245815e75e2a5fd60b4290f12bfc04e55a984d3","analyzedAt":"2026-09-07T11:47:02.965Z","contentChangedAt":"2026-09-07T11:47:02.965Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}