Subject: sys/compat/ossaudio/ossaudio.c seems to need ioctl(AUDIO_GETINFO)
To: tech-kern@netbsd.org, Perry E.Metzger <perry@piermont.com>
From: George Michaelson <ggm@apnic.net>
List: tech-kern
Date: 12/05/2005 16:26:06
--MP_Q=h_nLQ9_5ELO+aEMgN3gqS
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
[I've cc'd Perry because he worked last on the head state, yamt ditto
for his branch, and Kent for the kent-audio branch, and the pkg
owner. -ggm]
The ossaudio stuff tries to avoid extra ioctls by using the audio
AUDIO_INITINFO() call to get the current state when writing to the device.
(AUDIO_INITINFO() does a memset of the struct to all-ones from what I
can see. I don't see how that helps.)
However, I've noticed that with kphone, and some other apps, the
mixer/input device is being flipped to 'cd' from 'microphone' under
apps like kphone. It looks like something is not set right in the OSS
compat layer when AUDIO_INITINFO() is used.
I changed the calls to ioctl(AUDIO_GETINFO) into all structs being used
by a subsequent ioctl(AUDIO_SETINFO) (ie, where it called
AUDIO_INITINFO() before) and this no longer happens:
much happyness: I can use kphone to make sip calls, I can use
record->in on audacity. Before, after some unknown amount of I/O the
input mike went dead, had to run /usr/bin/audioctl -w record.port=1
and /usr/bin/audioctl -w record.gain=240 to get it back.
Its possible I've mis-diagnosed things, there is some interaction with
eg other X11 aps snarfing the audio device. However, test-before-set
seems to work better than the newer non-OSS compat 'set the struct'
method for this case. Is the call to AUDIO_GETINFO so much more
expensive than a memset?
YMMV
-George
(diff -bu attached)
--MP_Q=h_nLQ9_5ELO+aEMgN3gqS
Content-Type: application/octet-stream; name=ossaudio.c.diff
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename=ossaudio.c.diff
LS0tIHN5cy9jb21wYXQvb3NzYXVkaW8vb3NzYXVkaW8uYy5kaXN0CTIwMDUtMTItMDUgMTM6NTE6
MzIuMDAwMDAwMDAwICsxMDAwCisrKyBzeXMvY29tcGF0L29zc2F1ZGlvL29zc2F1ZGlvLmMJMjAw
NS0xMi0wNSA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