{"record":{"id":"8fb80eda95d12115","repo":"AlexxIT/go2rtc","slug":"alsa-set-hw-params-w","errorCode":null,"errorMessage":"[alsa] set hw_params: %w","messagePattern":"\\[alsa\\] set hw_params: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/alsa/device/device_linux.go","lineNumber":135,"sourceCode":"\t\treturn c2\n\t}\n\treturn channels\n}\n\nconst bufferSize = 4096\n\nfunc (d *Device) SetHWParams(format byte, rate uint32, channels byte) error {\n\td.setInterval(SNDRV_PCM_HW_PARAM_CHANNELS, uint32(channels))\n\td.setInterval(SNDRV_PCM_HW_PARAM_RATE, rate)\n\td.setMask(SNDRV_PCM_HW_PARAM_FORMAT, uint32(format))\n\t//d.setMask(SNDRV_PCM_HW_PARAM_SUBFORMAT, 0)\n\n\t// important for smooth playback\n\td.setInterval(SNDRV_PCM_HW_PARAM_BUFFER_SIZE, bufferSize)\n\t//d.setInterval(SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 2000)\n\n\tif err := ioctl(d.fd, SNDRV_PCM_IOCTL_HW_PARAMS, &d.hwparams); err != nil {\n\t\treturn fmt.Errorf(\"[alsa] set hw_params: %w\", err)\n\t}\n\n\t_, i := d.getInterval(SNDRV_PCM_HW_PARAM_FRAME_BITS)\n\td.frameBytes = int(i / 8)\n\n\t_, periods := d.getInterval(SNDRV_PCM_HW_PARAM_PERIODS)\n\t_, periodSize := d.getInterval(SNDRV_PCM_HW_PARAM_PERIOD_SIZE)\n\tthreshold := snd_pcm_uframes_t(periods * periodSize) // same as bufferSize\n\n\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","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/AlexxIT/go2rtc/blob/c245815e75e2a5fd60b4290f12bfc04e55a984d3/pkg/alsa/device/device_linux.go#L117-L153","documentation":"The SNDRV_PCM_IOCTL_HW_PARAMS ioctl failed while applying hardware parameters (format, rate, channels, buffer size) to the ALSA PCM device. Wraps the errno from the kernel; common causes are unsupported sample format/rate/channel count for the device or the device being in an incompatible state. Called by Start and AddTrack.","triggerScenarios":"Thrown at pkg/alsa/device/device_linux.go:135 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Request a different sample format, rate, or channel count supported by the device","Free other streams using the same PCM device and retry","Check dmesg for ALSA driver details on why params were rejected"],"exampleFix":null,"handlingStrategy":"fallback","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-15T23:17:13.987Z"}