linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2 v2] usb-audio misc fix
@ 2016-12-06  5:46 Jiada Wang
  2016-12-06  5:46 ` [PATCH v2 1/2] ALSA: usb-audio: more tolerant packetsize Jiada Wang
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jiada Wang @ 2016-12-06  5:46 UTC (permalink / raw)
  To: perex, tiwai, o-takashi, clemens
  Cc: alsa-devel, linux-kernel, jiada_wang, apape

This patch set contains the following patches

Andreas Pape (1):
  ALSA: usb-audio: more tolerant packetsize

Daniel Girnus (1):
  ALSA: usb-audio: avoid setting of sample rate multiple times on bus

 sound/usb/endpoint.c |  4 ++--
 sound/usb/pcm.c      | 21 +++++++++++----------
 2 files changed, 13 insertions(+), 12 deletions(-)

-- 
2.9.3

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/2] ALSA: usb-audio: more tolerant packetsize
  2016-12-06  5:46 [PATCH 0/2 v2] usb-audio misc fix Jiada Wang
@ 2016-12-06  5:46 ` Jiada Wang
  2016-12-06  7:13   ` Takashi Iwai
  2016-12-06 12:11   ` [alsa-devel] " Clemens Ladisch
  2016-12-06  5:46 ` [PATCH 2/2] ALSA: usb-audio: avoid setting of sample rate multiple times on bus Jiada Wang
  2016-12-06 15:02 ` [PATCH 0/2 v2] usb-audio misc fix Takashi Iwai
  2 siblings, 2 replies; 6+ messages in thread
From: Jiada Wang @ 2016-12-06  5:46 UTC (permalink / raw)
  To: perex, tiwai, o-takashi, clemens
  Cc: alsa-devel, linux-kernel, jiada_wang, apape

From: Andreas Pape <apape@de.adit-jv.com>

since commit 57e6dae1087b ("ALSA: usb-audio: do not trust too-big
wMaxPacketSize values"), the expected packetsize is always limited
to nominal + 25%. It was discovered, that some devices have a much
higher jitter in used packetsizes than 25% which would result in BABBLE
condition and dropping of packets.
A better solution is so assume the jitter to be the nominal packetsize:
-one nearly empty packet followed by a almost 150% sized one.

V2: changed to assume max frequency is +50 of nominal packetsize.

Signed-off-by: Andreas Pape <apape@de.adit-jv.com>
Signed-off-by: Jiada Wang <jiada_wang@mentor.com>
---
 sound/usb/endpoint.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
index c470251..a2931f4 100644
--- a/sound/usb/endpoint.c
+++ b/sound/usb/endpoint.c
@@ -632,8 +632,8 @@ static int data_ep_set_params(struct snd_usb_endpoint *ep,
 	ep->stride = frame_bits >> 3;
 	ep->silence_value = pcm_format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0;
 
-	/* assume max. frequency is 25% higher than nominal */
-	ep->freqmax = ep->freqn + (ep->freqn >> 2);
+	/* assume max. frequency is 50% higher than nominal */
+	ep->freqmax = ep->freqn + (ep->freqn >> 1);
 	/* Round up freqmax to nearest integer in order to calculate maximum
 	 * packet size, which must represent a whole number of frames.
 	 * This is accomplished by adding 0x0.ffff before converting the
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH 2/2] ALSA: usb-audio: avoid setting of sample rate multiple times on bus
  2016-12-06  5:46 [PATCH 0/2 v2] usb-audio misc fix Jiada Wang
  2016-12-06  5:46 ` [PATCH v2 1/2] ALSA: usb-audio: more tolerant packetsize Jiada Wang
@ 2016-12-06  5:46 ` Jiada Wang
  2016-12-06 15:02 ` [PATCH 0/2 v2] usb-audio misc fix Takashi Iwai
  2 siblings, 0 replies; 6+ messages in thread
From: Jiada Wang @ 2016-12-06  5:46 UTC (permalink / raw)
  To: perex, tiwai, o-takashi, clemens
  Cc: alsa-devel, linux-kernel, jiada_wang, apape

From: Daniel Girnus <dgirnus@de.adit-jv.com>

Some of userland applications call 'snd_pcm_hw_params()' and
'snd_pcm_hw_prepare()' sequentially, which means 'snd_pcm_hw_prepare()'
is called twice and the second 'snd_pcm_hw_prepare()' is called in
'SNDRV_PCM_STATE_PREPARED' state.

Some devices are not able to manage this and they will stop playback
if the sample rate will be configured several times over USB protocol.

V2: updated Changelog

Signed-off-by: Daniel Girnus <dgirnus@de.adit-jv.com>
Signed-off-by: Jens Lorenz <jlorenz@de.adit-jv.com>
Signed-off-by: Jiada Wang <jiada_wang@mentor.com>
---
 sound/usb/pcm.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index 44d178e..a522c9a 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -806,17 +806,18 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream)
 	if (ret < 0)
 		goto unlock;
 
-	iface = usb_ifnum_to_if(subs->dev, subs->cur_audiofmt->iface);
-	alts = &iface->altsetting[subs->cur_audiofmt->altset_idx];
-	ret = snd_usb_init_sample_rate(subs->stream->chip,
-				       subs->cur_audiofmt->iface,
-				       alts,
-				       subs->cur_audiofmt,
-				       subs->cur_rate);
-	if (ret < 0)
-		goto unlock;
-
 	if (subs->need_setup_ep) {
+
+		iface = usb_ifnum_to_if(subs->dev, subs->cur_audiofmt->iface);
+		alts = &iface->altsetting[subs->cur_audiofmt->altset_idx];
+		ret = snd_usb_init_sample_rate(subs->stream->chip,
+					       subs->cur_audiofmt->iface,
+					       alts,
+					       subs->cur_audiofmt,
+					       subs->cur_rate);
+		if (ret < 0)
+			goto unlock;
+
 		ret = configure_endpoint(subs);
 		if (ret < 0)
 			goto unlock;
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 1/2] ALSA: usb-audio: more tolerant packetsize
  2016-12-06  5:46 ` [PATCH v2 1/2] ALSA: usb-audio: more tolerant packetsize Jiada Wang
@ 2016-12-06  7:13   ` Takashi Iwai
  2016-12-06 12:11   ` [alsa-devel] " Clemens Ladisch
  1 sibling, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2016-12-06  7:13 UTC (permalink / raw)
  To: Jiada Wang; +Cc: clemens, perex, o-takashi, alsa-devel, apape, linux-kernel

On Tue, 06 Dec 2016 06:46:14 +0100,
Jiada Wang wrote:
> 
> From: Andreas Pape <apape@de.adit-jv.com>
> 
> since commit 57e6dae1087b ("ALSA: usb-audio: do not trust too-big
> wMaxPacketSize values"), the expected packetsize is always limited
> to nominal + 25%. It was discovered, that some devices have a much
> higher jitter in used packetsizes than 25% which would result in BABBLE
> condition and dropping of packets.
> A better solution is so assume the jitter to be the nominal packetsize:
> -one nearly empty packet followed by a almost 150% sized one.
> 
> V2: changed to assume max frequency is +50 of nominal packetsize.

Clemens, are you OK with this change?


Takashi

> 
> Signed-off-by: Andreas Pape <apape@de.adit-jv.com>
> Signed-off-by: Jiada Wang <jiada_wang@mentor.com>
> ---
>  sound/usb/endpoint.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
> index c470251..a2931f4 100644
> --- a/sound/usb/endpoint.c
> +++ b/sound/usb/endpoint.c
> @@ -632,8 +632,8 @@ static int data_ep_set_params(struct snd_usb_endpoint *ep,
>  	ep->stride = frame_bits >> 3;
>  	ep->silence_value = pcm_format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0;
>  
> -	/* assume max. frequency is 25% higher than nominal */
> -	ep->freqmax = ep->freqn + (ep->freqn >> 2);
> +	/* assume max. frequency is 50% higher than nominal */
> +	ep->freqmax = ep->freqn + (ep->freqn >> 1);
>  	/* Round up freqmax to nearest integer in order to calculate maximum
>  	 * packet size, which must represent a whole number of frames.
>  	 * This is accomplished by adding 0x0.ffff before converting the
> -- 
> 2.9.3
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [alsa-devel] [PATCH v2 1/2] ALSA: usb-audio: more tolerant packetsize
  2016-12-06  5:46 ` [PATCH v2 1/2] ALSA: usb-audio: more tolerant packetsize Jiada Wang
  2016-12-06  7:13   ` Takashi Iwai
@ 2016-12-06 12:11   ` Clemens Ladisch
  1 sibling, 0 replies; 6+ messages in thread
From: Clemens Ladisch @ 2016-12-06 12:11 UTC (permalink / raw)
  To: tiwai; +Cc: Jiada Wang, perex, o-takashi, alsa-devel, apape, linux-kernel

Jiada Wang wrote:
> since commit 57e6dae1087b ("ALSA: usb-audio: do not trust too-big
> wMaxPacketSize values"), the expected packetsize is always limited
> to nominal + 25%. It was discovered, that some devices

Android audio accessory

> have a much
> higher jitter in used packetsizes than 25% which would result in BABBLE
> condition and dropping of packets.
> A better solution is so assume the jitter to be the nominal packetsize:
> -one nearly empty packet followed by a almost 150% sized one.
>
> V2: changed to assume max frequency is +50 of nominal packetsize.
>
> Signed-off-by: Andreas Pape <apape@de.adit-jv.com>
> Signed-off-by: Jiada Wang <jiada_wang@mentor.com>

Acked-by: Clemens Ladisch <clemens@ladisch.de>

> --- a/sound/usb/endpoint.c
> +++ b/sound/usb/endpoint.c
> @@ -632,8 +632,8 @@ static int data_ep_set_params(struct snd_usb_endpoint *ep,
>  	ep->stride = frame_bits >> 3;
>  	ep->silence_value = pcm_format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0;
>
> -	/* assume max. frequency is 25% higher than nominal */
> -	ep->freqmax = ep->freqn + (ep->freqn >> 2);
> +	/* assume max. frequency is 50% higher than nominal */
> +	ep->freqmax = ep->freqn + (ep->freqn >> 1);
>  	/* Round up freqmax to nearest integer in order to calculate maximum
>  	 * packet size, which must represent a whole number of frames.
>  	 * This is accomplished by adding 0x0.ffff before converting the

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH 0/2 v2] usb-audio misc fix
  2016-12-06  5:46 [PATCH 0/2 v2] usb-audio misc fix Jiada Wang
  2016-12-06  5:46 ` [PATCH v2 1/2] ALSA: usb-audio: more tolerant packetsize Jiada Wang
  2016-12-06  5:46 ` [PATCH 2/2] ALSA: usb-audio: avoid setting of sample rate multiple times on bus Jiada Wang
@ 2016-12-06 15:02 ` Takashi Iwai
  2 siblings, 0 replies; 6+ messages in thread
From: Takashi Iwai @ 2016-12-06 15:02 UTC (permalink / raw)
  To: Jiada Wang; +Cc: clemens, perex, o-takashi, alsa-devel, apape, linux-kernel

On Tue, 06 Dec 2016 06:46:13 +0100,
Jiada Wang wrote:
> 
> This patch set contains the following patches
> 
> Andreas Pape (1):
>   ALSA: usb-audio: more tolerant packetsize
> 
> Daniel Girnus (1):
>   ALSA: usb-audio: avoid setting of sample rate multiple times on bus

Applied both patches, thanks.


Takashi

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-12-06 15:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-06  5:46 [PATCH 0/2 v2] usb-audio misc fix Jiada Wang
2016-12-06  5:46 ` [PATCH v2 1/2] ALSA: usb-audio: more tolerant packetsize Jiada Wang
2016-12-06  7:13   ` Takashi Iwai
2016-12-06 12:11   ` [alsa-devel] " Clemens Ladisch
2016-12-06  5:46 ` [PATCH 2/2] ALSA: usb-audio: avoid setting of sample rate multiple times on bus Jiada Wang
2016-12-06 15:02 ` [PATCH 0/2 v2] usb-audio misc fix Takashi Iwai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).