From patchwork Fri Sep 16 09:12:47 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrej Krutak X-Patchwork-Id: 9335371 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1DB1D6077F for ; Fri, 16 Sep 2016 10:07:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0D82429EF1 for ; Fri, 16 Sep 2016 10:07:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 016E829F19; Fri, 16 Sep 2016 10:07:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM,T_DKIM_INVALID autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 918D729EF1 for ; Fri, 16 Sep 2016 10:07:45 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 4E91D266829; Fri, 16 Sep 2016 12:07:44 +0200 (CEST) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id D58F3261560; Fri, 16 Sep 2016 12:05:25 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 847F12667E7; Fri, 16 Sep 2016 11:13:23 +0200 (CEST) Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by alsa0.perex.cz (Postfix) with ESMTP id 66854266735 for ; Fri, 16 Sep 2016 11:13:17 +0200 (CEST) Received: by mail-wm0-f66.google.com with SMTP id l132so1524269wmf.1 for ; Fri, 16 Sep 2016 02:13:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=Z3n1vqoDrWY3XSH1tSw1YMerWtJG4QPOvwJ+D7EUCkA=; b=XfXyDgK0LAHLPSgQei8sjkYxoG1I5jbNK5uuo35ddxt2MxIzmpJX5UNmoxLSjhmMqO ELPf0COcM54t/Zj3XAIUw+ZXfuQilVYsTeL+ZYU1jTqAiQj+XRhT3xsJM5iWTxsd4XAT QOrtdS1XnUqZO7uKvKkhokOdDxC9IGSQhBY0ySuMSA2p/nSmbGc+ejKXMF1KIh7M1Hoq ZJxzAWMt3ge5vs2FozuVOlcwva6A7p7a8ShmAlkg613FTt09cAxijQ+uIsPn21DOAPmy oHkiMKtiAspDn38zF43aqy0UJ1cIO2pexAUwihw2Becll3Ug0yz/AeRTlO9neqRvhel8 oufw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=Z3n1vqoDrWY3XSH1tSw1YMerWtJG4QPOvwJ+D7EUCkA=; b=ZVo73zg/TcFMjRErOlYTmuyJ2TR+LmxOpHKRtm957sc9ZJEPvP8umUcT4PbJ8incbC 0FGNSpTMbah0enBmSpgQ1Vszxeo3UZWtpqPQi0kZFRQUMOzabzEesHDRO96XV6cj1cGF WXPwjNxWd9+CQrEnl3QFL3Q2EuPIrOdpUVytAkxxy4i2BLrel57mcCoGHUNOn6dSloFi 51y2kLto0r1NdZqkaS9WJMn09DG1YshuPvnLkcbvC75EUAKhWs9Lk8rUSauv02NRuxPG l9Cjwb4EaR7in9OQzcZylBfBldcnrUBCENGOljDDPCm6dXkpLUPNJZXWI5gI56Kicu8A LM4w== X-Gm-Message-State: AE9vXwPLNUD48LuDz2nv7KMinq2yvGzwCeTog2bWzP+OVPdIimXk8GBJ7BxIQzN7wPwyXw== X-Received: by 10.194.140.14 with SMTP id rc14mr11723783wjb.104.1474017196981; Fri, 16 Sep 2016 02:13:16 -0700 (PDT) Received: from localhost.localdomain ([217.30.74.231]) by smtp.gmail.com with ESMTPSA id u124sm6391513wmu.10.2016.09.16.02.13.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Sep 2016 02:13:16 -0700 (PDT) From: Andrej Krutak To: tiwai@suse.com, perex@perex.cz, stefanha@gmail.com, grabner@icg.tugraz.at, alsa-devel@alsa-project.org Date: Fri, 16 Sep 2016 11:12:47 +0200 Message-Id: <1474017177-23769-4-git-send-email-dev@andree.sk> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1474017177-23769-1-git-send-email-dev@andree.sk> References: <1470942147-19848-1-git-send-email-dev@andree.sk> <1474017177-23769-1-git-send-email-dev@andree.sk> Cc: Andrej Krutak Subject: [alsa-devel] [PATCH v3 03/12] ALSA: line6: Support assymetrical in/out configurations X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Splits max_packet_size to max_packet_size_in/out (e.g. for different channel counts). Signed-off-by: Andrej Krutak --- sound/usb/line6/capture.c | 10 +++++----- sound/usb/line6/pcm.c | 28 ++++++++++++++++------------ sound/usb/line6/pcm.h | 5 +++-- sound/usb/line6/playback.c | 2 +- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/sound/usb/line6/capture.c b/sound/usb/line6/capture.c index 44e9a8c..73cea26 100644 --- a/sound/usb/line6/capture.c +++ b/sound/usb/line6/capture.c @@ -44,13 +44,13 @@ static int submit_audio_in_urb(struct snd_line6_pcm *line6pcm) struct usb_iso_packet_descriptor *fin = &urb_in->iso_frame_desc[i]; fin->offset = urb_size; - fin->length = line6pcm->max_packet_size; - urb_size += line6pcm->max_packet_size; + fin->length = line6pcm->max_packet_size_in; + urb_size += line6pcm->max_packet_size_in; } urb_in->transfer_buffer = line6pcm->in.buffer + - index * LINE6_ISO_PACKETS * line6pcm->max_packet_size; + index * LINE6_ISO_PACKETS * line6pcm->max_packet_size_in; urb_in->transfer_buffer_length = urb_size; urb_in->context = line6pcm; @@ -173,10 +173,10 @@ static void audio_in_callback(struct urb *urb) fbuf = urb->transfer_buffer + fin->offset; fsize = fin->actual_length; - if (fsize > line6pcm->max_packet_size) { + if (fsize > line6pcm->max_packet_size_in) { dev_err(line6pcm->line6->ifcdev, "driver and/or device bug: packet too large (%d > %d)\n", - fsize, line6pcm->max_packet_size); + fsize, line6pcm->max_packet_size_in); } length += fsize; diff --git a/sound/usb/line6/pcm.c b/sound/usb/line6/pcm.c index 6c9b7cf..5fc1394 100644 --- a/sound/usb/line6/pcm.c +++ b/sound/usb/line6/pcm.c @@ -146,16 +146,20 @@ get_stream(struct snd_line6_pcm *line6pcm, int direction) } /* allocate a buffer if not opened yet; - * call this in line6pcm.state_change mutex + * call this in line6pcm.state_mutex */ static int line6_buffer_acquire(struct snd_line6_pcm *line6pcm, - struct line6_pcm_stream *pstr, int type) + struct line6_pcm_stream *pstr, int direction, int type) { + const int pkt_size = + (direction == SNDRV_PCM_STREAM_PLAYBACK) ? + line6pcm->max_packet_size_out : + line6pcm->max_packet_size_in; + /* Invoked multiple times in a row so allocate once only */ if (!test_and_set_bit(type, &pstr->opened) && !pstr->buffer) { pstr->buffer = kmalloc(line6pcm->line6->iso_buffers * - LINE6_ISO_PACKETS * - line6pcm->max_packet_size, GFP_KERNEL); + LINE6_ISO_PACKETS * pkt_size, GFP_KERNEL); if (!pstr->buffer) return -ENOMEM; } @@ -163,12 +167,11 @@ static int line6_buffer_acquire(struct snd_line6_pcm *line6pcm, } /* free a buffer if all streams are closed; - * call this in line6pcm.state_change mutex + * call this in line6pcm.state_mutex */ static void line6_buffer_release(struct snd_line6_pcm *line6pcm, struct line6_pcm_stream *pstr, int type) { - clear_bit(type, &pstr->opened); if (!pstr->opened) { line6_wait_clear_audio_urbs(line6pcm, pstr); @@ -195,6 +198,7 @@ static int line6_stream_start(struct snd_line6_pcm *line6pcm, int direction, else ret = line6_submit_audio_in_all_urbs(line6pcm); } + if (ret < 0) clear_bit(type, &pstr->running); spin_unlock_irqrestore(&pstr->lock, flags); @@ -530,12 +534,12 @@ int line6_init_pcm(struct usb_line6 *line6, line6pcm->volume_monitor = 255; line6pcm->line6 = line6; - /* Read and write buffers are sized identically, so choose minimum */ - line6pcm->max_packet_size = min( - usb_maxpacket(line6->usbdev, - usb_rcvisocpipe(line6->usbdev, ep_read), 0), - usb_maxpacket(line6->usbdev, - usb_sndisocpipe(line6->usbdev, ep_write), 1)); + line6pcm->max_packet_size_in = + usb_maxpacket(line6->usbdev, + usb_rcvisocpipe(line6->usbdev, ep_read), 0); + line6pcm->max_packet_size_out = + usb_maxpacket(line6->usbdev, + usb_sndisocpipe(line6->usbdev, ep_write), 1); spin_lock_init(&line6pcm->out.lock); spin_lock_init(&line6pcm->in.lock); diff --git a/sound/usb/line6/pcm.h b/sound/usb/line6/pcm.h index 38bf4df..f408d15 100644 --- a/sound/usb/line6/pcm.h +++ b/sound/usb/line6/pcm.h @@ -155,11 +155,12 @@ struct snd_line6_pcm { /* Previously captured frame (for software monitoring) */ unsigned char *prev_fbuf; - /* Size of previously captured frame (for software monitoring) */ + /* Size of previously captured frame (for software monitoring/sync) */ int prev_fsize; /* Maximum size of USB packet */ - int max_packet_size; + int max_packet_size_in; + int max_packet_size_out; /* PCM playback volume (left and right) */ int volume_playback[2]; diff --git a/sound/usb/line6/playback.c b/sound/usb/line6/playback.c index d53aad1..7b2644f 100644 --- a/sound/usb/line6/playback.c +++ b/sound/usb/line6/playback.c @@ -195,7 +195,7 @@ static int submit_audio_out_urb(struct snd_line6_pcm *line6pcm) urb_frames = urb_size / bytes_per_frame; urb_out->transfer_buffer = line6pcm->out.buffer + - index * LINE6_ISO_PACKETS * line6pcm->max_packet_size; + index * LINE6_ISO_PACKETS * line6pcm->max_packet_size_out; urb_out->transfer_buffer_length = urb_size; urb_out->context = line6pcm;