public inbox for alsa-devel@alsa-project.org
 help / color / mirror / Atom feed
From: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
To: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org
Subject: Re: [PATCH 1/2] ALSA: usb: fix corrupted pointers due to interface setting change
Date: Fri, 14 Aug 2015 10:39:32 -0500	[thread overview]
Message-ID: <55CE0BB4.2070303@linux.intel.com> (raw)
In-Reply-To: <s5hvbchsxd0.wl-tiwai@suse.de>

On 8/14/15 10:28 AM, Takashi Iwai wrote:
> On Fri, 14 Aug 2015 17:03:10 +0200,
> Takashi Iwai wrote:
>>
>> On Fri, 14 Aug 2015 00:42:32 +0200,
>> Pierre-Louis Bossart wrote:
>>>
>>> When a transition occurs between alternate settings that do not use the
>>> same synchronization method, the substream pointers were not reset.
>>> This prevents audio from being played during the second transition.
>>>
>>> Identified and tested with M-Audio Transit device
>>> (0763:2006 Midiman M-Audio Transit)
>>
>> Hmm, I have this old device, too, but couldn't reproduce the problem.
>> Is there any special setup with it?
>
> OK, I could see it after switching a few times.  But, also your patch
> didn't cure, either...

I tested this with Ubuntu 14.04 and the default madfuload package that 
comes with it for the firmware.

I think you need both patches to get the device to work. I split the 
patches in two since I think the second problem is device specific while 
the first one is a generic one that can happen on other devices.

I generated three chirps test files with audacity, one stereo 96kHz 
24bits (3 bytes), one stereo 48kHz 24 bits (3 bytes) and then stereo 
48kHz 16 bits. This matches the capabilities of the three endpoints.
If you try first with the 48kHz 16bits one then typically the others 
won't work.

>
>
> Takashi
>
>>
>>
>> Takashi
>>
>>>
>>> Details of the issue:
>>>
>>> First playback to adaptive endpoint:
>>> $ aplay -Dhw:1,0 ~/24_96.wav
>>> Playing WAVE '/home/plb/24_96.wav' : Signed 24 bit Little Endian in 3bytes,
>>> Rate 96000 Hz, Stereo
>>>
>>> [ 3169.297556] usb 1-2: setting usb interface 1:1
>>> [ 3169.297568] usb 1-2: Creating new playback data endpoint #3
>>> [ 3169.298563] usb 1-2: Setting params for ep #3 (type 0, 3 urbs), ret=0
>>> [ 3169.298574] usb 1-2: Starting data EP @ffff880035fc8000
>>>
>>> first playback to asynchronous endpoint:
>>> $ aplay -Dhw:1,0 ~/16_48.wav
>>> Playing WAVE '/home/plb/16_48.wav' : Signed 16 bit Little Endian,
>>> Rate 48000 Hz, Stereo
>>>
>>> [ 3204.520251] usb 1-2: setting usb interface 1:3
>>> [ 3204.520264] usb 1-2: Creating new playback data endpoint #3
>>> [ 3204.520272] usb 1-2: Creating new capture sync endpoint #83
>>> [ 3204.521162] usb 1-2: Setting params for ep #3 (type 0, 4 urbs), ret=0
>>> [ 3204.521177] usb 1-2: Setting params for ep #83 (type 1, 4 urbs), ret=0
>>> [ 3204.521182] usb 1-2: Starting data EP @ffff880035fce000
>>> [ 3204.521204] usb 1-2: Starting sync EP @ffff8800bd616000
>>>
>>> second playback to adaptive endpoint: no audio and error on terminal:
>>> $ aplay -Dhw:1,0 ~/24_96.wav
>>> Playing WAVE '/home/plb/24_96.wav' : Signed 24 bit Little Endian in 3bytes,
>>> Rate 96000 Hz, Stereo
>>> aplay: pcm_write:1939: write error: Input/output error
>>>
>>> [ 3239.483589] usb 1-2: setting usb interface 1:1
>>> [ 3239.483601] usb 1-2: Re-using EP 3 in iface 1,1 @ffff880035fc8000
>>> [ 3239.484590] usb 1-2: Setting params for ep #3 (type 0, 4 urbs), ret=0
>>> [ 3239.484606] usb 1-2: Setting params for ep #83 (type 1, 4 urbs), ret=0
>>>
>>> This last line shows that a sync endpoint is used when it shouldn't.
>>> The sync endpoint is no longer valid and the pointers are corrupted
>>>
>>> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
>>> ---
>>>   sound/usb/pcm.c | 13 +++++++++++++
>>>   1 file changed, 13 insertions(+)
>>>
>>> diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
>>> index b4ef410..7cd7c03 100644
>>> --- a/sound/usb/pcm.c
>>> +++ b/sound/usb/pcm.c
>>> @@ -395,6 +395,19 @@ static int set_sync_endpoint(struct snd_usb_substream *subs,
>>>   	if (err < 0)
>>>   		return err;
>>>
>>> +	if ((is_playback && (attr != USB_ENDPOINT_SYNC_ASYNC)) ||
>>> +		(!is_playback && (attr != USB_ENDPOINT_SYNC_ADAPTIVE))) {
>>> +
>>> +		/*
>>> +		 * Clean-up subs pointers to make sure sync_endpoint is never
>>> +		 * configured. This is needed in case of a transition between
>>> +		 * alternate settings using different synchronization modes
>>> +		 * where the previous sync_endpoint may no longer be valid.
>>> +		 */
>>> +		subs->sync_endpoint = NULL;
>>> +		subs->data_endpoint->sync_master = NULL;
>>> +	}
>>> +
>>>   	if (altsd->bNumEndpoints < 2)
>>>   		return 0;
>>>
>>> --
>>> 1.9.1
>>>

  reply	other threads:[~2015-08-14 15:39 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-13 22:42 [PATCH 0/2] USB audio fixes Pierre-Louis Bossart
2015-08-13 22:42 ` [PATCH 1/2] ALSA: usb: fix corrupted pointers due to interface setting change Pierre-Louis Bossart
2015-08-14 15:03   ` Takashi Iwai
2015-08-14 15:28     ` Takashi Iwai
2015-08-14 15:39       ` Pierre-Louis Bossart [this message]
2015-08-14 15:47         ` Takashi Iwai
2015-08-14 15:54           ` Takashi Iwai
2015-08-14 15:57   ` Takashi Iwai
2015-08-14 16:05     ` Pierre-Louis Bossart
2015-08-13 22:42 ` [PATCH 2/2] ALSA: usb: handle descriptor with SYNC_NONE illegal value Pierre-Louis Bossart
2015-08-14 16:03   ` Takashi Iwai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=55CE0BB4.2070303@linux.intel.com \
    --to=pierre-louis.bossart@linux.intel.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox