Commit Graph

119 Commits

Author SHA1 Message Date
nia 5f6355cc9e ossaudio(3): continue getting capabilities if AUDIO_GETFORMAT fails
we want this to work on mixer devices too
2021-06-09 14:49:13 +00:00
nia 200ab436dc ossaudio(3): nested switch statements are hard to read, refactor 2021-06-08 19:26:48 +00:00
nia 8170080d8e ossaudio(3): refactor library into separate files 2021-06-08 18:43:54 +00:00
nia 6383164a17 ossaudio: Set handle on OSSv4 mixer devices 2021-05-09 12:51:45 +00:00
nia 5d7326fb2a libossaudio: Various OSSv4 fixes to allow reference programs to compile
- Define various new AFMT_*. These are not returned as supported
  formats by SNDCTL_DSP_GETFMTS, because it would be very silly to
  have Vorbis in the kernel.

- Implement PLAYTGT and RECSRC. For each NetBSD audio device
  we only return one playback and recording source, "primary".

- Return preferred channel configuration in capabilities.
  Either DSP_CH_STEREO, DSP_CH_MONO, or DSP_CH_MULTI
  depending on the current hardware format.

- SNDCTL_DSP_HALT_* simply flushes the audio device.
2021-05-09 11:28:25 +00:00
nia 53793f01c2 ossv4 mixer API: be extra careful with the inputs to AUDIO_MIXER_READ.
some drivers (not hdaudio(4), but uaudio(4), eap(4), sb(4), various other
old cards) will return error if a AUDIO_MIXER_VALUE is requested and the
number of channels is not specified as input. this is not documented as
well as it should be, unfortunately.
2021-03-15 10:58:05 +00:00
nia c1f0400234 ossaudio(3): Do not reuse results from AUDIO_GETBUFINFO in SETINFO
Should help PR 55876.
2020-12-19 12:55:28 +00:00
nia aab2f38b54 Add some missing channel order related ioctl defines.
These are no-ops (unimplemented) on both FreeBSD and Solaris
and the one piece of code I've found that uses it seems to assume the
call will fail so it should be safe to leave this returning EINVAL.

However, it does need the definitions to compile...
2020-12-03 22:10:21 +00:00
nia f7f198978e ossaudio(3): Clone some useful behaviour from the Solaris kernel
Both SNDCTL_DSP_SPEED and SNDCTL_DSP_CHANNELS support a special value
0 to "query the configured value without changing it". In our case,
this actually means setting and querying the hardware rate.

I don't know if OSSv3 or FreeBSD or other implementations also do this.
But it seems safe and sensible to support.
2020-11-13 09:02:39 +00:00
nia 8a0fd92fc8 ossaudio(3): Set errno and return -1 rather than returning errno. 2020-11-04 22:59:24 +00:00
nia a9d493a299 ossaudio(3): Reduce code duplication for querying capabilities 2020-11-03 09:46:00 +00:00
nia f0eecf651f ossaudio(3): Return device playback and capture capabilities in GETCAPS 2020-11-03 09:36:12 +00:00
nia 54df53aac3 ossaudio(3): More capability defines from OSSv4 2020-11-03 09:33:53 +00:00
nia 7a66cf0ffc ossaudio(3): return correctly initialized return value in unlikely
error case. pointed out by tnn.
2020-11-03 08:24:33 +00:00
nia 2ea12967a0 ossaudio(3): Simplify setting rate (try to supply the nearest one possible) 2020-10-30 21:44:49 +00:00
roy 07a43c5149 libossaudio: return newfd here as we return retval elsewhere 2020-10-24 14:43:53 +00:00
wiz 80fb34196c Fix typo in comment. 2020-10-23 12:13:04 +00:00
nia 2cd43b36c6 ossaudio(3): Add an implementation of SNDCTL_CARDINFO
Correct some of the counts returned by SNDCTL_SYSINFO so this works.
2020-10-23 09:05:20 +00:00
nia 054aefec7a ossaudio(3): This is not compat_linux 2020-10-22 19:39:48 +00:00
nia 41a2db1f31 ossaudio(3): Add SNDCTL_AUDIOINFO_EX as an alias of SNDCTL_AUDIOINFO 2020-10-20 08:57:45 +00:00
wiz 0e2cbe842f Remove trailing whitespace. 2020-10-20 07:52:04 +00:00
nia d1d954926b ossaudio(3): Plug a fd leak in the new mixer API 2020-10-20 06:53:37 +00:00
nia bbfc3fa4fd ossaudio.3: Bump date 2020-10-20 06:43:55 +00:00
nia 6abc2e7583 ossaudio(3): Turn BUGS section into a list of potential compat issues 2020-10-20 06:43:34 +00:00
nia 988ec12f1c ossaudio(3): Add some endian-specific U16 formats
for compatibility with FreeBSD
2020-10-20 06:33:52 +00:00
nia 8bdeed361e ossaudio(3): add some no-op defines for ossv4 compat. 2020-10-19 10:28:47 +00:00
nia 028d2f4db2 ossaudio(3): these ioctls need to return samples, not bytes 2020-10-19 09:07:29 +00:00
nia 27ca241ed7 ossaudio(3): Add SNDCTL_DSP_CURRENT_(I|O)PTR
In OSSv4 these are supposed to avoid the wrapping problems with the
older GET(I|O)PTR ioctls but we don't quite get the same benefit here.

XXX: We could probably fake it by maintaining some state in-between calls.
2020-10-19 09:01:24 +00:00
nia 1f7ebca62c ossaudio(3): Add initial support for the OSSv4.1 Mixer API
One or two calls from this API were supported previously and have been
moved to the correct place.

Mapping the controls correctly is a difficult task. There is a define
hidden in the OSS headers that would allow an AUDIO_MIXER_SET control
to be represented perfectly, but it seems to _only_ exist there, and
no software supports it. So for now only one member of a set can be
set at a time - unfortunate. I've hidden code that should unlock
doing this the proper way under #notyet.

I'm not too happy with the way this code is managing file descriptors.
Currently it has to open a new fd for each ioctl due to OSSv4 deciding
to specify the device number in a structure rather than in the filename.
In the future, we could reuse the file descriptor if the correct one is
detected open.

This allows the mixer programs provided with the OSSv4 sources to compile
and work cleanly. I've observed problems with it failing to work on
secondary devices, and should investigate this later. There may be
a fd leak somewhere.
2020-10-17 23:23:06 +00:00
wiz e3d011e985 Use Fx and Nx. End Rs block. Remove trailing whitespace.
Remove unnecessary Pp.
2020-10-17 09:04:59 +00:00
nia b32d7310bd ossaudio.3: note this is most/all of ossv3 and some of ossv4 2020-10-16 20:51:54 +00:00
nia d53a6cbc32 ossaudio(3): Add SNDCTL_DSP_COOKEDMODE, SNDCTL_DSP_GETERROR
SNDCTL_DSP_COOKEDMODE simply always returns 1.
"Cooked mode" is a silly way the OSSv4 authors chose to refer to allowing
for reprocessed streams. The NetBSD kernel always performs format
conversion and it can't be turned off.

SNDCTL_DSP_GETERROR provides access to the read/write over/underrun
counters. There are other things it might return, but they don't make
sense for our implementation.
2020-10-16 20:24:35 +00:00
nia ad3ea96832 ossaudio.3: Sort sections. 2020-10-16 16:48:07 +00:00
nia 381a0b036e ossaudio.3: More information about the history and status of this API 2020-10-16 16:30:53 +00:00
nia 9613c80501 ossaudio: Bump copyright date and improve description. 2020-10-16 15:40:16 +00:00
nia d9a5cdad2e ossaudio: Add comments for the more obscure parts of SNDCTL_AUDIOINFO 2020-10-16 12:36:01 +00:00
nia 2874e967ea ossaudio: Various OSSv4 fixes for SNDCTL_AUDIOINFO
- Per OSSv4, make this ioctl work on the main mixer device.
  Since the native NetBSD API uses queries on individual audio devices,
  we have to reopen the correct audio device specified in the input to the
  ioctl and fetch information from that.
- Correctly return whether the device is for playback, capture, or both.
- Return the full name of the device in the name field.
- The "handle" has to be a globally unique identifier. The closest thing
  we have to that is device numbers, so use device numbers.
- Return reasonable values in min_rate/max_rate and min_channels/max_channels.

This should allow Mumble's device enumeration to work with a lot less
patching.
2020-10-16 12:23:34 +00:00
nia ab8a3679da ossaudio: removed outdated comment 2020-04-20 12:01:44 +00:00
nia 8e9e149d7d ossaudio: Implement SNDCTL_DSP_(SET|GET)TRIGGER. 2020-04-19 13:44:50 +00:00
nia d4490f2a9c ossaudio: Make SNDCTL_DSP_[GET|SET][PLAY|RECORD]VOL closer to OSSv4
Problems in the previous code include returning values in the 0-255
range NetBSD uses instead of the 0-100 range OSSv4 expects, using
AUDIO_GETBUFINFO (which doesn't even return the mixer bits), and
not encoding channels as specified: "level=(left)|(right << 8)".

In reality, setting the gain in this way (through /dev/audio rather
than /dev/mixer) doesn't seem to work properly, and the mixer-set
value seems to be retained.

However, these changes at least ensure that the return values are
correct and the balance is set correctly.

I've only found one application using this API (audio/audacious), and
OSSv4 support in it is currently disabled precisely because it breaks
when it attempts to set the track volume using it.
2020-04-19 11:27:40 +00:00
nia 87706eec7d ossaudio: If the user's channel count is rejected, use the hardware count 2020-04-15 16:39:06 +00:00
nia 0eb796bf71 ossaudio: Make SNDCTL_DSP_SETFMT conform with OSSv4.
The OSSv4 spec says we shouldn't really error if an invalid format is
chosen by an application. Things are especially likely to be confused
if we return MULAW, since in OSSv4 terms that means that's the native
hardware format. Instead, set and return the current hardware format
if an invalid format is chosen.

For the 24-bit sample formats, note that the NetBSD kernel currently
can't handle them in its default configuration, and will return an error
code if you attempt to use them. So, if an applicaton requests 24-bit PCM,
promote it to 32-bit PCM. According to the spec, this is valid and
applications should be checking the return value anyway.

In the Linux compat layer, we just use S16LE as a fallback. The OSSv3
headers that are still being shipped with Linux don't contain definitions
for fancier formats and we can reasonably expect all applications to
support S16LE.
2020-04-15 15:25:33 +00:00
nia 6476938d92 ossaudio: Make SNDCTL_DSP_SPEED more robust when using invalid rates.
From the perspective of reading the OSSv4 specification, NetBSD's
behaviour when an invalid sample rate is set makes no sense at all:
AUDIO_SETINFO simply returns an error code, and then we immediately
fall through to getting the sample rate, which is still set to the
legacy default of 8000 Hz.

Instead, what OSS applications generally expect is that they will be
able to receive the actual hardware sample rate. This is very, very
unlikely to be 8000 Hz on a modern machine.

No functional change when setting a sample rate between the supported
rates of 1000 and 192000 Hz. When a rate outside this range is requested,
the hardware rate is returned (on modern hardware, generally always 48000
Hz or a multiple of 48000 Hz).
2020-04-15 14:54:34 +00:00
isaki 5b3dd8b1b9 Use record field for recording even on
SNDCTL_DSP_STEREO, SNDCTL_DSP_SETFMT, and SNDCTL_DSP_CHANNELS.
2019-11-03 11:13:45 +00:00
isaki d97643b742 Use record.sample_rate for recording on SNDCTL_DSP_SPEED.
Fix PR lib/54667.
2019-11-02 11:48:23 +00:00
isaki 8b1980912d Fix minor bugs of SNDCTL_DSP_GETISPACE.
- hiwat is playback-only parameter.
- 'bytes' should not be rounded down.
2019-02-02 04:52:16 +00:00
isaki 6b4163e9ca Revert a wrong SNDCTL_DSP_GETOSPACE part of rev1.33.
- 'fragments' is the number of full free blocks and should not be
  negative value.
- 'bytes' should not be rounded down.
It makes mpv work correctly (fixes a second half of kern/53028).
Reviewed by mlelstv@
2019-01-29 11:54:02 +00:00
mrg bfe7e5d8b3 memset to zero the entire array, not just 8 bytes of it.
picked up by gcc7's checker that the array size has not
been multipled by the member size.

here, we had 8 but should have had 8 * sizeof(int).

XXX: real bug - pullup-7, pullup-8
2019-01-23 00:08:06 +00:00
nat e5d1b604d5 ABI of libossaudio did not change, so there was no need to bump the version
number.

Pointed out by mrg@
2017-03-24 11:46:52 +00:00
nat dab5456581 Calculate GETISPACE/GETOSPACE properly.
Bump version.

Addresses PR kern/51999.
2017-03-23 15:50:48 +00:00