sio_initpar() generates invalid parameters

From: Roman Bogorodskiy <>
Date: Fri, 11 Jun 2021 20:01:35 +0400

I have sndio-1.7.0 on FreeBSD. My initial problem that mpg123 wasn't
working with sndio backend (and oss backend worked fine). I've reported
the problem here:

It turns out that the problem might be actually on sndio side.

Specifically, it looks like sio_oss_setpar() fails on setting CHANNELS
which are coming unchanged from a structure initialized by

Thomas Orgis has shared the following test code:

#include <sndio.h>
#include <stdio.h>

int main()
	int ret=1;
	struct sio_hdl *hdl;
	struct sio_par par;
//	par.pchan = 0;
	printf("initpar channels: %u\n", par.pchan);
	hdl = sio_open(NULL, SIO_PLAY, 0);
		return ret;
	if(sio_setpar(hdl, &par))
		printf("setpar successful\n");
		struct sio_par par2;
		if(sio_getpar(hdl, &par2))
			printf("default format: %u ch, %u Hz\n", par2.pchan, par2.rate);
			ret = 0;
		} else
			printf("failure in getpar\n");
	} else
		printf("failure in setpar\n");
	return ret;

With "par.pchan = 0" line commented out it fails:

$ SNDIO_DEBUG=2 ./sndiotest
initpar channels: 4294967295
_aucat_open: host= unit=0 devnum=0 opt=default
/tmp/sndio-1001/sock0: No such file or directory
/tmp/sndio/sock0: No such file or directory
sio_oss_setpar: CHANNELS: Invalid argument
failure in setpar

With that line uncommented it works:

SNDIO_DEBUG=2 ./sndiotest                                                 
initpar channels: 0
_aucat_open: host= unit=0 devnum=0 opt=default
/tmp/sndio-1001/sock0: No such file or directory
/tmp/sndio/sock0: No such file or directory
setpar successful
default format: 1 ch, 48000 Hz

Quoting the manpage:

     •   Initialize a sio_par structure using sio_initpar() and fill it with
         the desired parameters.  Then call sio_setpar() to request the device
         to use them.  Parameters left unset in the sio_par structure will be
         set to device-specific defaults.

As in the failing case we don't override 'par.pchat', should not it use
some reasonable device-specific default which allows sio_initpar() to
complete successfully?

Roman Bogorodskiy

Received on Fri Jun 11 2021 - 18:01:35 CEST

This archive was generated by hypermail 2.3.0 : Tue Aug 09 2022 - 16:23:51 CEST