Bug 184380 - [pcm] SNDCTL_DSP_SETFMT accepts unsupported values
Summary: [pcm] SNDCTL_DSP_SETFMT accepts unsupported values
Status: Closed Works As Intended
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-multimedia (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-30 01:20 UTC by Jan Beich
Modified: 2019-09-20 06:48 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Beich freebsd_committer freebsd_triage 2013-11-30 01:20:00 UTC
According to SNDCTL_DSP_SETFMT documentation if the ioctl() succeeds
the application must check if value was accepted. Unfortunately, our
OSS implementation may return value that's not actually supported.

http://manuals.opensound.com/developer/SNDCTL_DSP_SETFMT.html

At least the following ports check requested format and would assume
AFMT_FLOAT is accepted if built with sys/soundcard.h from opensound.com.

  devel/allegro-devel
  emulators/wine
  multimedia/audacious-plugins
  multimedia/mplayer
  multimedia/vlc

Probably, only Linux accepts AFMT_FLOAT which means apps built with
OSSv4 wouldn't work under linuxulator either.

How-To-Repeat: # kern/21073, audio/oss
$ ./dsp-record -b float
Trying    8012 Hz 1 Channel float Format
ioctl(SNDCTL_DSP_SETFMT) failed: Tried 16384, Got 16

# kern/21073, native
$ ./dsp-record -b float | head -1 | vis -m
Trying    8012 Hz 1 Channel float Format
Recording 8012 Hz 1 Channel float Format
=00=00=00=80=FF=FF=FF=7F=FA=FF=FF=7Fx=FF=FF=7F=E4=00=00=80=9B=FE=FF=7F

# audio/oss
$ ./test
0x00000010

# native
$ ./test
0x00004000

$ cat test.c
#include <sys/soundcard.h>

#include <fcntl.h>
#include <stdio.h>

#ifndef AFMT_FLOAT
#define AFMT_FLOAT 0x00004000
#endif

int main()
{
  int fd = open("/dev/dsp", O_RDWR, 0);

  int format = AFMT_FLOAT;
  if (ioctl(fd, SNDCTL_DSP_SETFMT, &format) < 0)
    return 1;

  printf("%0#10x\n", format);

  return 0;
}
Comment 1 Eitan Adler freebsd_committer freebsd_triage 2018-05-28 19:50:27 UTC
batch change:

For bugs that match the following
-  Status Is In progress 
AND
- Untouched since 2018-01-01.
AND
- Affects Base System OR Documentation

DO:

Reset to open status.


Note:
I did a quick pass but if you are getting this email it might be worthwhile to double check to see if this bug ought to be closed.
Comment 2 Hans Petter Selasky freebsd_committer freebsd_triage 2019-09-20 06:36:57 UTC
Hi,

AFMT_FLOAT is not defined for the in-kernel OSS. If there is enough bits left we can do that.

Your AFMT_FLOAT definition is actually AFMT_U32_LE, which of-course is supported when using vchans:

/usr/include/sys/soundcard.h:#define AFMT_U32_LE	0x00004000	/* Little endian unsigned 32-bit */

--HPS
Comment 3 Hans Petter Selasky freebsd_committer freebsd_triage 2019-09-20 06:48:53 UTC
We are out of bits in the AFMT field in FreeBSD. So AFMT_FLOAT cannot be defined!

Assume that when AFMT_FLOAT is not defined, that it is not supported.

Also OSS documentation marks this feature as "not recommended".

Please edit the applications in question.

Thank you!

--HPS