alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Takashi Iwai <tiwai@suse.de>
To: Robert Giaraffa <Robert.Giaraffa@silabs.com>
Cc: "alsa-devel@alsa-project.org" <alsa-devel@alsa-project.org>,
	Daniel Mack <daniel@zonque.org>
Subject: Re: Simultaneous play/record on implicit feedback device causes 'endpoint in use' error
Date: Wed, 31 Oct 2018 12:57:36 +0100	[thread overview]
Message-ID: <s5hy3aeuy4v.wl-tiwai@suse.de> (raw)
In-Reply-To: <BN7PR11MB2755B1BC150703C0DFC2DA919CCC0@BN7PR11MB2755.namprd11.prod.outlook.com>

On Wed, 31 Oct 2018 00:15:51 +0100,
Robert Giaraffa wrote:
> 
> My company (Silicon Labs) makes a CP2615 USB audio class 1.0 device which uses implicit feedback.  I saw these two issues when testing with aplay/arecord/alsabat/alsaloop:
> 
> 
>   *   During playback-only operation, the implicit feedback (IN) endpoint was not active.
> 
> 
>   *   During play/record operation, the implicit feedback values were not acted on, i.e. the host always sent 192 bytes per OUT packet even if previous IN packets had been 188 or 196 bytes.
> 
> This behavior was observed on these systems:
> 
> RaspberryPi2:    Raspbian 9 (stretch), kernel v4.14.72
> x86-64:                 Ubuntu 18.04, kernel v4.15.0-36
> 
> I was able to get implicit feedback working properly in playback mode by adding a device-specific quirk to 'pcm.c' that is similar to existing quirks for implicit-feedback devices, e.g. M-Audio Fast Track Ultra.  (Note: The following patch applies to kernel v4.14.72.  In v4.18, the set_sync_ep_implicit_fb_quirk function was changed so that there is a single call to usb_ifnum_to_if(), rather than a call for each device-dependent quirk.)
> 
> $ git diff pcm.c
> diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
> index b9c9a19f..6fb5567b 100644
> --- a/sound/usb/pcm.c
> +++ b/sound/usb/pcm.c
> @@ -358,6 +358,21 @@ static int set_sync_ep_implicit_fb_quirk(struct snd_usb_substream *subs,
>                 alts = &iface->altsetting[1];
>                 goto add_sync_ep;
> 
> +       case USB_ID(0x10C4, 0xEAC1):    // Silicon Labs CP2615
> +               // Ensure CP2615 is configured in Async Mode
> +               if (attr != USB_ENDPOINT_SYNC_ASYNC)
> +                       return 0;
> +
> +               // In P16R16 async mode, AudioIN EP (IF:4 EP:0x83) used for implicit feedback
> +               ep = 0x83;
> +               iface = usb_ifnum_to_if(dev, 4);
> +
> +               if (!iface || iface->num_altsetting == 0)
> +                       return -EINVAL;
> +
> +               alts = &iface->altsetting[1];
> +               goto add_sync_ep;
> +
>         }
>         if (attr == USB_ENDPOINT_SYNC_ASYNC &&
>             altsd->bInterfaceClass == USB_CLASS_VENDOR_SPEC &&
> 
> After adding the patch, I verified that implicit feedback worked properly for playback, i.e. the OUT samples per packet tracked previous IN values.  However, when attempting to perform simultaneous play and record via alsabat, alsaloop, or separate aplay/arecord, the system reports the 'endpoint already in use' error when attempting to set the format for the IN endpoint that is already in use (note that this dmesg log has customized printk messages):
> 
>     [Oct23 10:13] snd_usb_hw_params->set_format()
>     [  +0.000014] set_format(): dev:b3856c00 alts:b67e8824 ifnum: 3
>     [  +0.001654] set_format()->usb_set_interface 3:1
>     [  +0.000006] Creating new playback data endpoint 03
>     [  +0.000004] Creating new capture data endpoint 83
> 
> <Begin Playback. SYNC endpoint also starts because feedback is implicit>
> 
>     [  +0.000027] snd_usb_pcm_prepare->set_format()
>     [  +0.000005] set_format(): dev:b3856c00 alts:b67e8824 ifnum: 3
>     [  +0.000755] Setting params for EP 03 (type 0, 12 urbs), ret=0
>     [  +0.000017] Setting params for EP 83 (type 0, 12 urbs), ret=0
>     [  +0.000004] Starting DATA_EP 03 @b9224000
>     [  +0.000004] snd_usb_endpoint_implicit_feedback_sink (03) is TRUE
>     [  +0.001495] Starting SYNC_EP 83 @b9222000
> 
> <After playing for 0.5s, start recording. Failure occurs because EP83 is already in use.>
> 
>     [  +0.493035] snd_usb_hw_params->set_format()
>     [  +0.000016] set_format(): dev:b3856c00 alts:b67e88a4 ifnum: 4
>     [  +0.001549] set_format()->usb_set_interface 4:1
>     [  +0.000005] Re-using EP 83 in iface 4:1
>     [  +0.000028] snd_usb_pcm_prepare->set_format()
>     [  +0.000004] set_format(): dev:b3856c00 alts:b67e88a4 ifnum: 4
> *** [  +0.003196] *** snd_usb_endpoint_set_params(): EP #83: already in use
>     [  +0.000003] configure_endpoint->endpoint_set_params: err=FFFFFFF0
> 
> I bought a used Fast Track Ultra device for comparison testing, and found that it behaved the same way as the CP2615 does with the implicit feedback quirk: in playback-only mode implicit feedback works properly, but play/record causes the 'EP already in use' error.
> 
> Are there any suggestions on how I can resolve this issue?  Any help would be greatly appreciated!

How about starting the recording before the playback?

Adding Daniel to Cc, who implemented the code originally.


Takashi

  reply	other threads:[~2018-10-31 11:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-30 23:15 Simultaneous play/record on implicit feedback device causes 'endpoint in use' error Robert Giaraffa
2018-10-31 11:57 ` Takashi Iwai [this message]
2018-10-31 19:45   ` [EXT] " Robert Giaraffa
2018-11-02 15:57     ` Takashi Iwai
2020-01-15 15:33       ` [alsa-devel] " Alexander Tsoy

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=s5hy3aeuy4v.wl-tiwai@suse.de \
    --to=tiwai@suse.de \
    --cc=Robert.Giaraffa@silabs.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=daniel@zonque.org \
    /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;
as well as URLs for NNTP newsgroup(s).