NetBSD Problem Report #17159

Received: (qmail 5054 invoked by uid 605); 4 Jun 2002 00:58:33 -0000
Message-Id: <200206040058.MAA08091@ub1.grace.cri.nz>
Date: Tue, 4 Jun 2002 12:58:13 +1200
From: Gregory McGarry <g.mcgarry@ieee.org>
Sender: gnats-bugs-owner@netbsd.org
Reply-To:
To: gnats-bugs@gnats.netbsd.org
Subject: Incompatible change to audio(4) between NetBSD 1.5 and 1.6
X-Send-Pr-Version: 3.95

>Number:         17159
>Category:       kern
>Synopsis:       audio(4) interface change
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    fredb
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Jun 04 00:59:00 +0000 2002
>Closed-Date:    Wed Mar 31 05:07:52 +0000 2004
>Last-Modified:  Wed Mar 31 05:07:52 +0000 2004
>Originator:     Gregory McGarry
>Release:        NetBSD 1.6_BETA1
>Organization:

>Environment:

System: NetBSD 1.6_BETA1
Architecture: i686

eap0 at pci0 dev 10 function 0: vendor 0x1274 product 0x5880 CT5880C (rev. 0x02)
eap0: interrupting at irq 5
eap0: SigmaTel STAC9721/23 codec; 18 bit DAC, 18 bit ADC, SigmaTel 3D
audio0 at eap0: full duplex, mmap, independent
midi0 at eap0: AudioPCI MIDI UART

>Description:

This code fragment works on NetBSD 1.5:

	AUDIO_INITINFO(&info);
	if (ioctl(fd, AUDIO_GETINFO, &info) == -1)
		err(EXIT_FAILURE, "AUDIO_GETINFO");
	if (ioctl(fd, AUDIO_SETINFO, &info) == -1)
		err(EXIT_FAILURE, "AUDIO_SETINFO");

On NetBSD 1.6, the AUDIO_SETINFO ioctl fails, returning EINVAL.

audio(4) provides the following documentation:

   When setting the current state with AUDIO_SETINFO, the audio_info
   structure should first be initialized with AUDIO_INITINFO (&info)
   and then the particular values to be changed should be set.  This
   allows the audio driver to only set those things that you wish to
   change and eliminates the need to query the device with
   AUDIO_GETINFO first.

With the current state, it is not sufficient to say "eliminates the
need to query the device with AUDIO_GETINFO first".  In fact, it
is mandatory to do it this way.

The original 1.5 behaviour such that the AUDIO_GETINFO ioctl can be
called to initialise struct audio_info should be preserved.  Certainly,
it's less likely to break existing code which worked before the
auconv changes.

>How-To-Repeat:

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <err.h>
#include <sys/ioctl.h>
#include <sys/audioio.h>

int main (int argc, char *argv[])
{
	struct audio_info info;
	int fd;

	if ((fd = open("/dev/audio", O_RDWR, 0666)) == -1)
		err(EXIT_FAILURE, "/dev/audio");

	AUDIO_INITINFO(&info);
	if (ioctl(fd, AUDIO_GETINFO, &info) == -1)
		err(EXIT_FAILURE, "AUDIO_GETINFO");
	if (ioctl(fd, AUDIO_SETINFO, &info) == -1)
		err(EXIT_FAILURE, "AUDIO_SETINFO");

	close(fd);
}

>Fix:

N/A
>Release-Note:
>Audit-Trail:

From: Gregory McGarry <g.mcgarry@ieee.org>
To: jmc@netbsd.org
Cc: gnats-bugs@gnats.netbsd.org, augustss@netbsd.org
Subject: Re: kern/17159: Incompatible change to audio(4) between NetBSD 1.5 and 1.6
Date: Wed, 5 Jun 2002 11:39:28 +1200

 Gregory McGarry wrote:

 > >Number:         17159
 > >Category:       kern
 > >Synopsis:       audio(4) interface change
 > >Description:
 > 
 > This code fragment works on NetBSD 1.5:
 > 
 > 	AUDIO_INITINFO(&info);
 > 	if (ioctl(fd, AUDIO_GETINFO, &info) == -1)
 > 		err(EXIT_FAILURE, "AUDIO_GETINFO");
 > 	if (ioctl(fd, AUDIO_SETINFO, &info) == -1)
 > 		err(EXIT_FAILURE, "AUDIO_SETINFO");
 > 
 > On NetBSD 1.6, the AUDIO_SETINFO ioctl fails, returning EINVAL.
 > 
 > The original 1.5 behaviour such that the AUDIO_GETINFO ioctl can be
 > called to initialise struct audio_info should be preserved.  Certainly,
 > it's less likely to break existing code which worked before the
 > auconv changes.

 Here is the relevant change that broke binary compatibility:

 Revision 1.132, Mon Dec 25 00:01:39 2000 UTC (17 months, 1 week ago) by jmc 

 Back out changes from 1.124 since the additions of *ports.master=-1 wasn't
 documented as to why it was added in and it breaks the ability to set the
 gain on playback. A longer term fix to set these correctly should be done but
 none of the drivers today are doing this and not being able to set the playback
 volume otherwise is a bit silly.


 Unless there is a correct fix to this problem, I want to back-out this
 change so that binary compatibility is preserved.  A pull-up request
 would then be sent to releng.

 	-- Gregory McGarry <g.mcgarry@ieee.org>

From: James Chacon <jchacon@genuity.net>
To: g.mcgarry@ieee.org (Gregory McGarry)
Cc: jmc@netbsd.org, gnats-bugs@gnats.netbsd.org, augustss@netbsd.org
Subject: Re: kern/17159: Incompatible change to audio(4) between NetBSD 1.5 and 1.6
Date: Tue, 4 Jun 2002 21:23:37 -0400 (EDT)

 A proper fix has to be done. Not being able to set the playback volume for
 anything breaks a lot of things...

 James

 >
 >Gregory McGarry wrote:
 >
 >> >Number:         17159
 >> >Category:       kern
 >> >Synopsis:       audio(4) interface change
 >> >Description:
 >> 
 >> This code fragment works on NetBSD 1.5:
 >> 
 >> 	AUDIO_INITINFO(&info);
 >> 	if (ioctl(fd, AUDIO_GETINFO, &info) == -1)
 >> 		err(EXIT_FAILURE, "AUDIO_GETINFO");
 >> 	if (ioctl(fd, AUDIO_SETINFO, &info) == -1)
 >> 		err(EXIT_FAILURE, "AUDIO_SETINFO");
 >> 
 >> On NetBSD 1.6, the AUDIO_SETINFO ioctl fails, returning EINVAL.
 >> 
 >> The original 1.5 behaviour such that the AUDIO_GETINFO ioctl can be
 >> called to initialise struct audio_info should be preserved.  Certainly,
 >> it's less likely to break existing code which worked before the
 >> auconv changes.
 >
 >Here is the relevant change that broke binary compatibility:
 >
 >Revision 1.132, Mon Dec 25 00:01:39 2000 UTC (17 months, 1 week ago) by jmc 
 >
 >Back out changes from 1.124 since the additions of *ports.master=-1 wasn't
 >documented as to why it was added in and it breaks the ability to set the
 >gain on playback. A longer term fix to set these correctly should be done but
 >none of the drivers today are doing this and not being able to set the playback
 >volume otherwise is a bit silly.
 >
 >
 >Unless there is a correct fix to this problem, I want to back-out this
 >change so that binary compatibility is preserved.  A pull-up request
 >would then be sent to releng.
 >
 >	-- Gregory McGarry <g.mcgarry@ieee.org>
 >
 >
 >
 >

State-Changed-From-To: open->analyzed 
State-Changed-By: fredb 
State-Changed-When: Tue Dec 23 19:46:45 CST 2003 
State-Changed-Why:  

Diddling the master volume control is a hack, anyway. What you really 
want, for most devices, is to utilize the on-chip mixer: the application 
using the simpified audio interface adjusts the input to the mixer, while 
the output, the master, can be left to some very simple mixer-using 
volume-control type application, perhaps a simple gnome-panel widget, or 
a function key enabled by the window manager. 



Responsible-Changed-From-To: kern-bug-people->fredb 
Responsible-Changed-By: fredb 
Responsible-Changed-When: Tue Dec 23 19:46:45 CST 2003 
Responsible-Changed-Why:  

Here's a patch to current as of 1.6ZG, and another to the netbsd-1-6 branch. 

ftp://ftp.netbsd.org/pub/NetBSD/misc/fredb/audio-volume-control.diff 
ftp://ftp.netbsd.org/pub/NetBSD/misc/fredb/audio-volume-control-1-6.diff 

There are only minor changes to the post I made to tech-kern nearly a 
year ago 

http://mail-index.netbsd.org/tech-kern/2003/01/25/0009.html 

so I've been using it for about that long on a few different machines, 
and it seems to do exactly the right thing. 


From: Frederick Bruckman <fredb@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc:  
Subject: pr/17159 CVS commit: src
Date: Sat, 31 Jan 2004 00:07:56 +0000 (UTC)

 Module Name:	src
 Committed By:	fredb
 Date:		Sat Jan 31 00:07:56 UTC 2004

 Modified Files:
 	src/share/man/man4: audio.4
 	src/share/man/man9: audio.9
 	src/sys/dev: audio.c audiovar.h

 Log Message:
 Fix a couple of long-standing bugs in the volume control(s) part of the
 audio device interface:

 1) When attempting to match the appropriate mixer control, we weren't
 checking the class label, but only the second level label, so for
 devices that had both an "inputs.cd" and a "record.cd", for example,
 we could never do the right thing except by chance. For this reason,
 evidently, all the record masters were labeled (by the underlying
 drivers) either "record.record" or "record.volume", to distinguish
 from "outputs.master". We'll now accept "record.master", and document
 that as the the new preferred way.

 2) More importantly, the model was deficient. Selecting a port on many
 chips completely disables most of the level controls, which doesn't play
 nice with other applications which are trying to use the interface. Now,
 selecting a port simply sets which mixer input control shall be changed,
 setting state in the audio layer. In other words, the "mixerout" port
 is really selected all the time, enabling the final stage mixer, and
 setting "gain" sets the level of the appropriate input. It should be
 possible for separate applications to each control the mic, dac, and cd
 inputs at the same time using this interface, simply by reiterating their
 port selections with each change, but applications that don't bother to
 do that aren't any worse off than they were before.

 The user is expected to set the master output with another application,
 dedicated to that task. Though it is now meaningful to select "no port"
 with the audio device interface, to manipulate the master output, there's
 no particular reason for an audio device consumer to do that. (I added
 the capability in order to restore the initial state of the audio device,
 for testing purposes. It might also be useful to users of broken binary-
 only applications.)

 Observe that the mixer device interface (and so, "mixerctl") still
 retains all capabilities, including the ability to set the actual input
 port on the chip, overriding the level controls. No change is being made
 to the mixer device interface. The mixer device simply presents all the
 controls on the chip, with no attempt at abstraction, so there are no
 bugs there.

 The upshot is, that applications that have been trying to use the audio
 device interface to change the volume, such as mplayer, now "just work".

 I've tested these changes extensively with "eso" and "eap" since first
 proposing them on tech-kern last January, and somewhat with "esm" and a
 few others. This closes both PR kern/10221, and PR kern/17159.


 To generate a diff of this commit:
 cvs rdiff -r1.56 -r1.57 src/share/man/man4/audio.4
 cvs rdiff -r1.25 -r1.26 src/share/man/man9/audio.9
 cvs rdiff -r1.181 -r1.182 src/sys/dev/audio.c
 cvs rdiff -r1.29 -r1.30 src/sys/dev/audiovar.h

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

State-Changed-From-To: analyzed->feedback 
State-Changed-By: fredb 
State-Changed-When: Wed Feb 4 14:41:18 CST 2004 
State-Changed-Why:  
Gregory -- since my last commit, your test case runs without 
errors. OK to close this? 

State-Changed-From-To: feedback->closed 
State-Changed-By: tls 
State-Changed-When: Wed Mar 31 05:07:02 UTC 2004 
State-Changed-Why:  
developer believes problem solved; two months with no response to feedback 
request. 
>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.