Bug 236118 - audio/portaudio: default_unit /dev/dsp[0-9]* cannot be used if sysctl -n hw.snd.basename_clone is 0
Summary: audio/portaudio: default_unit /dev/dsp[0-9]* cannot be used if sysctl -n hw.s...
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Tobias Kortkamp
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-03-01 02:23 UTC by Tatsuki Makino
Modified: 2019-03-01 10:42 UTC (History)
0 users

See Also:
tobik: maintainer-feedback+


Attachments
proposal patch (switch between /dev/dsp and default_unit /dev/dsp[0-9]*) (2.28 KB, patch)
2019-03-01 02:23 UTC, Tatsuki Makino
no flags Details | Diff
proposal patch (switch the existence of /dev/dsp) (2.42 KB, patch)
2019-03-01 02:25 UTC, Tatsuki Makino
no flags Details | Diff
portaudio.diff (2.40 KB, patch)
2019-03-01 03:40 UTC, Tobias Kortkamp
tobik: maintainer-approval+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tatsuki Makino 2019-03-01 02:23:52 UTC
Created attachment 202465 [details]
proposal patch (switch between /dev/dsp and default_unit /dev/dsp[0-9]*)

I have 4 sound devices, device 1 is the default.
portaudio hides /dev/dsp1, sysctl hw.snd.basename_clone=0 hides /dev/dsp.
Since the default output sink is hidden, no sound can be obtained.
Comment 1 Tatsuki Makino 2019-03-01 02:25:18 UTC
Created attachment 202466 [details]
proposal patch (switch the existence of /dev/dsp)
Comment 2 Tatsuki Makino 2019-03-01 02:28:11 UTC
The command for the experiment was made as follows.
clang -I/usr/local/include/ /usr/local/share/examples/portaudio/pa_devs.c -L/usr/local/lib -lportaudio
Comment 3 Tobias Kortkamp freebsd_committer freebsd_triage 2019-03-01 03:40:28 UTC
Created attachment 202467 [details]
portaudio.diff

Hmm, the code seems quite broken indeed.  I don't think your patch
is quite right/simple enough though.  I think we can do what you propose
(always add /dev/dsp to the device list first) and simplify the code a
lot in the process.

We don't really need to care about hw.snd.basename_clone in portaudio.
QueryDevice() for /dev/dsp will fail if it does not exist and it
will never be added to the device list in the first place.

The default device will appear twice (once as /dev/dsp and /dev/dsp1)
in the list, but that shouldn't matter much.
Comment 4 Tatsuki Makino 2019-03-01 04:50:57 UTC
Comment on attachment 202466 [details]
proposal patch (switch the existence of /dev/dsp)

(In reply to Tobias Kortkamp from comment #3)

I made it difficult because I thought that #ifdef __FreeBSD__ had meaning.
It is better to simply as attachment 202467 [details] if #ifdef __FreeBSD__ is not important.

I think the default device should be appeared twice, for example because Audacity stores configuration as following.

[AudioIO]
RecordingDevice=/dev/dsp1
PlaybackDevice=/dev/dsp1

If hw.snd.basename_clone changes, it will not lose sight of /dev/dsp[0-9]*.

In addition, hw.snd.basename_clone is changed by virtual_oss (audio/virtual_oss) when virtual_oss is run with option -d dsp.
Comment 5 commit-hook freebsd_committer freebsd_triage 2019-03-01 09:41:06 UTC
A commit references this bug:

Author: tobik
Date: Fri Mar  1 09:40:25 UTC 2019
New revision: 494248
URL: https://svnweb.freebsd.org/changeset/ports/494248

Log:
  audio/portaudio: Amend r419598 and always add OSS default device first

  r419598 tried to solve a problem where when hw.snd.default_unit is
  set to anything except zero /dev/dsp0 is not available to programs
  using portaudio since it assumes that /dev/dsp and /dev/dsp0 are
  the same device.

  However with that fix, when hw.snd.default_unit=1 and
  hw.snd.basename_clone=0, portaudio will hide /dev/dsp1 from the
  device list since it will use /dev/dsp for it instead of /dev/dsp1.
  However since /dev/dsp is not available, QueryDevice() will fail
  and /dev/dsp1 will never be added to the device list.

  Instead of looking up hw.snd.default_unit we can solve this by
  always trying to add /dev/dsp to the device list first.

  PR:		236118
  Submitted by:	Tatsuki Makino <tatsuki_makino@hotmail.com>

Changes:
  head/audio/portaudio/Makefile
  head/audio/portaudio/files/patch-src_hostapi_oss_pa__unix__oss.c
Comment 6 Tobias Kortkamp freebsd_committer freebsd_triage 2019-03-01 09:42:39 UTC
(In reply to Tatsuki Makino from comment #4)
> I think the default device should be appeared twice, for example because
> Audacity stores configuration as following.
> 
> [AudioIO]
> RecordingDevice=/dev/dsp1
> PlaybackDevice=/dev/dsp1
> 
> If hw.snd.basename_clone changes, it will not lose sight of /dev/dsp[0-9]*.

Aha, that's good to know!

I committed the patch. Thanks for this!
Comment 7 Tatsuki Makino 2019-03-01 10:42:42 UTC
Thank you very much.