NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: kern/54264: audio(4) API fails to detect a capture-only device



The following reply was made to PR kern/54264; it has been noted by GNATS.

From: Tetsuya Isaki <isaki%pastel-flower.jp@localhost>
To: gnats-bugs%netbsd.org@localhost
Cc: kern-bug-people%netbsd.org@localhost,
	gnats-admin%netbsd.org@localhost,
	netbsd-bugs%netbsd.org@localhost
Subject: Re: kern/54264: audio(4) API fails to detect a capture-only device
Date: Tue, 04 Jun 2019 21:34:31 +0900

 At Sun,  2 Jun 2019 13:35:00 +0000 (UTC),
 nia%netbsd.org@localhost wrote:
 > First I query the device with AUDIO_GETPROPS.  It claims that the
 > device has playback support.  This is incorrect.
 
 Please try this patch.
 uaudio doesn't return correct property on unidirectional device.
 current audio (isaki-audio2) requires that the hardware driver's
 get_props() returns exact property.
 
 nakayama@-san,
 dev/audio/audio.c,v 1.5 and 1.7 look wrong.  It assumes that the
 hardware driver may return incorrect property.  But this assumption
 is not right (and not good).  The condition
  (unidirection && full duplex), or
  (unidirection && the device can set play and rec independently)
 are obviously strange and such hardware driver should be fixed.
 Would you test this patch?
 
 --- sys/dev/usb/uaudio.c
 +++ sys/dev/usb/uaudio.c
 @@ -2264,8 +2264,21 @@ uaudio_round_blocksize(void *addr, int blk,
  Static int
  uaudio_get_props(void *addr)
  {
 -	return AUDIO_PROP_FULLDUPLEX | AUDIO_PROP_INDEPENDENT;
 +	struct uaudio_softc *sc;
 +	int props;
 +
 +	sc = addr;
 +	props = 0;
 +	if ((sc->sc_mode & AUMODE_PLAY))
 +		props |= AUDIO_PROP_PLAYBACK;
 +	if ((sc->sc_mode & AUMODE_RECORD))
 +		props |= AUDIO_PROP_CAPTURE;
 +
 +	/* XXX I'm not sure all bidirectional devices support FULLDUP&INDEP */
 +	if (props == (AUDIO_PROP_PLAYBACK | AUDIO_PROP_CAPTURE))
 +		props |= AUDIO_PROP_FULLDUPLEX | AUDIO_PROP_INDEPENDENT;
  
 +	return props;
  }
  
  Static void
 Index: sys/dev/audio/audio.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/audio/audio.c,v
 retrieving revision 1.5
 retrieving revision 1.4
 diff -u -r1.5 -r1.4
 --- sys/dev/audio/audio.c	13 May 2019 04:11:04 -0000	1.5
 +++ sys/dev/audio/audio.c	13 May 2019 04:09:35 -0000	1.4
 @@ -6149,23 +6149,17 @@
  	    "invalid mode = %x", mode);
  
  	if (is_indep) {
 -		int errorp = 0, errorr = 0;
 -
  		/* On independent devices, probe separately. */
  		if ((mode & AUMODE_PLAY) != 0) {
 -			errorp = audio_hw_probe_fmt(sc, phwfmt, AUMODE_PLAY);
 -			if (errorp)
 +			error = audio_hw_probe_fmt(sc, phwfmt, AUMODE_PLAY);
 +			if (error)
  				mode &= ~AUMODE_PLAY;
  		}
  		if ((mode & AUMODE_RECORD) != 0) {
 -			errorr = audio_hw_probe_fmt(sc, rhwfmt, AUMODE_RECORD);
 -			if (errorr)
 +			error = audio_hw_probe_fmt(sc, rhwfmt, AUMODE_RECORD);
 +			if (error)
  				mode &= ~AUMODE_RECORD;
  		}
 -
 -		/* Return error if both play and record probes failed. */
 -		if (errorp && errorr)
 -			error = errorp;
  	} else {
  		/* On non independent devices, probe simultaneously. */
  		error = audio_hw_probe_fmt(sc, &fmt, mode);
 Index: sys/dev/audio/audio.c
 ===================================================================
 RCS file: /cvsroot/src/sys/dev/audio/audio.c,v
 retrieving revision 1.7
 retrieving revision 1.6
 diff -u -r1.7 -r1.6
 --- sys/dev/audio/audio.c	13 May 2019 08:50:25 -0000	1.7
 +++ sys/dev/audio/audio.c	13 May 2019 07:53:56 -0000	1.6
 @@ -2046,17 +2046,12 @@
  			 * hw_if->open() is always (FREAD | FWRITE)
  			 * regardless of this open()'s flags.
  			 * see also dev/isa/aria.c
 -			 * but ckeck its playback or recording capability.
  			 * On half duplex hardware, the flags passed to
  			 * hw_if->open() is either FREAD or FWRITE.
  			 * see also arch/evbarm/mini2440/audio_mini2440.c
  			 */
  			if (fullduplex) {
  				hwflags = FREAD | FWRITE;
 -				if (!audio_can_playback(sc))
 -					hwflags &= ~FWRITE;
 -				if (!audio_can_capture(sc))
 -					hwflags &= ~FREAD;
  			} else {
  				/* Construct hwflags from af->mode. */
  				hwflags = 0;
 
 ---
 Tetsuya Isaki <isaki%pastel-flower.jp@localhost / isaki%NetBSD.org@localhost>
 


Home | Main Index | Thread Index | Old Index