From patchwork Fri Dec 21 09:29:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Wischer X-Patchwork-Id: 10740215 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 778CD6C5 for ; Fri, 21 Dec 2018 09:30:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64E062863E for ; Fri, 21 Dec 2018 09:30:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 58A6028647; Fri, 21 Dec 2018 09:30:24 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham 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 7B9CD2863E for ; Fri, 21 Dec 2018 09:30:23 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 6AD39267ACE; Fri, 21 Dec 2018 10:30:22 +0100 (CET) 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 03CF9267AC2; Fri, 21 Dec 2018 10:30:20 +0100 (CET) Received: from smtp1.de.adit-jv.com (smtp1.de.adit-jv.com [93.241.18.167]) by alsa0.perex.cz (Postfix) with ESMTP id 12CDC267AC4; Fri, 21 Dec 2018 10:30:16 +0100 (CET) Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id BD60D3C02F6; Fri, 21 Dec 2018 10:30:16 +0100 (CET) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ABKp575X2y1Q; Fri, 21 Dec 2018 10:30:10 +0100 (CET) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id EEE643C02F2; Fri, 21 Dec 2018 10:30:01 +0100 (CET) Received: from vmlxhi-087.adit-jv.com (10.72.93.172) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 21 Dec 2018 10:30:01 +0100 From: To: Date: Fri, 21 Dec 2018 10:29:42 +0100 Message-ID: <1545384583-29955-2-git-send-email-twischer@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545384583-29955-1-git-send-email-twischer@de.adit-jv.com> References: <1545384583-29955-1-git-send-email-twischer@de.adit-jv.com> MIME-Version: 1.0 X-Originating-IP: [10.72.93.172] Cc: Laxmi Devi , alsa-devel@alsa-project.org, Timo Wischer Subject: [alsa-devel] [PATCH - ALSA JACK plugin 1/2] jack: Move jack_activate() and jack_connect() to snd_pcm_jack_prepare() 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Laxmi Devi Since the processing of jack_activate() and jack_connect() take a while longer, snd_pcm_jack_start() was blocked. Consider a usecase of reading the data from capture device and writing to a playback device, since the capture device is already started and the starting of playback device is blocked, it leads to XRUNs for capture device. Therefore these calls are moved to snd_pcm_jack_prepare(), So that the capture and playback devices can be prepared in advance so that starting of the device doesn't take too long. Signed-off-by: Laxmi Devi Signed-off-by: Timo Wischer diff --git a/jack/pcm_jack.c b/jack/pcm_jack.c index b39835e..19d339d 100644 --- a/jack/pcm_jack.c +++ b/jack/pcm_jack.c @@ -222,16 +222,8 @@ snd_pcm_jack_process_cb(jack_nframes_t nframes, snd_pcm_ioplug_t *io) frames, io->format); } - if (io->state == SND_PCM_STATE_PREPARED) { - /* After activating this JACK client with - * jack_activate() this process callback will be called. - * But the processing of snd_pcm_jack_start() would take - * a while longer due to the jack_connect() calls. - * Therefore the device was already started - * but it is not yet in RUNNING state. - * Due to this expected behaviour it is not an Xrun. - */ - } else { + if (io->state == SND_PCM_STATE_RUNNING || + io->state == SND_PCM_STATE_DRAINING) { /* report Xrun to user application */ jack->xrun_detected = true; } @@ -242,6 +234,30 @@ snd_pcm_jack_process_cb(jack_nframes_t nframes, snd_pcm_ioplug_t *io) return 0; } +static void jack_allocate_and_register_ports(snd_pcm_ioplug_t *io) +{ + snd_pcm_jack_t *jack = io->private_data; + unsigned int i; + + jack->ports = calloc(io->channels, sizeof(jack_port_t *)); + + for (i = 0; i < io->channels; i++) { + char port_name[32]; + + if (io->stream == SND_PCM_STREAM_PLAYBACK) { + sprintf(port_name, "out_%03d", i); + jack->ports[i] = jack_port_register(jack->client, port_name, + JACK_DEFAULT_AUDIO_TYPE, + JackPortIsOutput, 0); + } else { + sprintf(port_name, "in_%03d", i); + jack->ports[i] = jack_port_register(jack->client, port_name, + JACK_DEFAULT_AUDIO_TYPE, + JackPortIsInput, 0); + } + } +} + static int snd_pcm_jack_prepare(snd_pcm_ioplug_t *io) { snd_pcm_jack_t *jack = io->private_data; @@ -269,38 +285,16 @@ static int snd_pcm_jack_prepare(snd_pcm_ioplug_t *io) else pcm_poll_block_check(io); /* block capture pcm if that's XRUN recovery */ - if (jack->ports) - return 0; - - jack->ports = calloc(io->channels, sizeof(jack_port_t*)); - - for (i = 0; i < io->channels; i++) { - char port_name[32]; - if (io->stream == SND_PCM_STREAM_PLAYBACK) { - - sprintf(port_name, "out_%03d", i); - jack->ports[i] = jack_port_register(jack->client, port_name, - JACK_DEFAULT_AUDIO_TYPE, - JackPortIsOutput, 0); - } else { - sprintf(port_name, "in_%03d", i); - jack->ports[i] = jack_port_register(jack->client, port_name, - JACK_DEFAULT_AUDIO_TYPE, - JackPortIsInput, 0); - } + if (!jack->ports) { + jack_allocate_and_register_ports(io); + jack_set_process_callback(jack->client, + (JackProcessCallback)snd_pcm_jack_process_cb, io); } - jack_set_process_callback(jack->client, - (JackProcessCallback)snd_pcm_jack_process_cb, io); - return 0; -} + if (jack->activated) + return 0; -static int snd_pcm_jack_start(snd_pcm_ioplug_t *io) -{ - snd_pcm_jack_t *jack = io->private_data; - unsigned int i; - - if (jack_activate (jack->client)) + if (jack_activate(jack->client)) return -EIO; jack->activated = 1; @@ -321,7 +315,23 @@ static int snd_pcm_jack_start(snd_pcm_ioplug_t *io) } } } - + return 0; +} + +static int snd_pcm_jack_start(snd_pcm_ioplug_t *io) +{ + (void)io; + /* + * Since the processing of jack_activate() and jack_connect() take a + * while longer, snd_pcm_jack_start() was blocked. + * Consider a usecase of reading the data from capture device and + * writing to a playback device, since the capture device is + * already started and the starting of playback device is blocked, + * it leads to XRUNs for capture device. + * Therefore these calls are moved to snd_pcm_jack_prepare(), + * So that the capture and playback devices can be prepared in advance + * and starting of the device doesn't take too long. + */ return 0; } From patchwork Fri Dec 21 09:29:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Wischer X-Patchwork-Id: 10740217 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E68C16C5 for ; Fri, 21 Dec 2018 09:30:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D3EBC2863E for ; Fri, 21 Dec 2018 09:30:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C839E28647; Fri, 21 Dec 2018 09:30:31 +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=-2.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham 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 7859F2863E for ; Fri, 21 Dec 2018 09:30:30 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 00E3B267AC9; Fri, 21 Dec 2018 10:30:29 +0100 (CET) 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 7E29E267AC2; Fri, 21 Dec 2018 10:30:26 +0100 (CET) Received: from smtp1.de.adit-jv.com (smtp1.de.adit-jv.com [93.241.18.167]) by alsa0.perex.cz (Postfix) with ESMTP id 44BB0267AC4; Fri, 21 Dec 2018 10:30:23 +0100 (CET) Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id C96103C02F3; Fri, 21 Dec 2018 10:30:23 +0100 (CET) Received: from smtp1.de.adit-jv.com ([127.0.0.1]) by localhost (smtp1.de.adit-jv.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dnfV3oZ_d0Od; Fri, 21 Dec 2018 10:30:16 +0100 (CET) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id E51C23C02F4; Fri, 21 Dec 2018 10:30:03 +0100 (CET) Received: from vmlxhi-087.adit-jv.com (10.72.93.172) by HI2EXCH01.adit-jv.com (10.72.92.24) with Microsoft SMTP Server (TLS) id 14.3.408.0; Fri, 21 Dec 2018 10:30:03 +0100 From: To: Date: Fri, 21 Dec 2018 10:29:43 +0100 Message-ID: <1545384583-29955-3-git-send-email-twischer@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1545384583-29955-1-git-send-email-twischer@de.adit-jv.com> References: <1545384583-29955-1-git-send-email-twischer@de.adit-jv.com> MIME-Version: 1.0 X-Originating-IP: [10.72.93.172] Cc: Laxmi Devi , alsa-devel@alsa-project.org, Timo Wischer Subject: [alsa-devel] [PATCH - ALSA JACK plugin 2/2] jack: Moving jack_deactivate() to snd_pcm_jack_hw_free() to speedup the XRUN Recovery 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Laxmi Devi Removed snd_pcm_jack_stop() from snd_pcm_jack_prepare(),as on XRUN we do not need to reconnect or reconfigure anything. Signed-off-by: Laxmi Devi Signed-off-by: Timo Wischer diff --git a/jack/pcm_jack.c b/jack/pcm_jack.c index 19d339d..af2136e 100644 --- a/jack/pcm_jack.c +++ b/jack/pcm_jack.c @@ -58,8 +58,6 @@ typedef struct { bool xrun_detected; } snd_pcm_jack_t; -static int snd_pcm_jack_stop(snd_pcm_ioplug_t *io); - /* snd_pcm_ioplug_avail() was introduced after alsa-lib 1.1.6 */ #if SND_LIB_VERSION < 0x10107 static snd_pcm_uframes_t snd_pcm_ioplug_avail(const snd_pcm_ioplug_t *io, @@ -277,9 +275,6 @@ static int snd_pcm_jack_prepare(snd_pcm_ioplug_t *io) snd_pcm_sw_params_get_boundary(swparams, &jack->boundary); } - /* deactivate jack connections if this is XRUN recovery */ - snd_pcm_jack_stop(io); - if (io->stream == SND_PCM_STREAM_PLAYBACK) pcm_poll_unblock_check(io); /* playback pcm initially accepts writes */ else @@ -337,8 +332,14 @@ static int snd_pcm_jack_start(snd_pcm_ioplug_t *io) static int snd_pcm_jack_stop(snd_pcm_ioplug_t *io) { + (void)io; + return 0; +} + +static int snd_pcm_jack_hw_free(snd_pcm_ioplug_t *io) +{ snd_pcm_jack_t *jack = io->private_data; - + if (jack->activated) { jack_deactivate(jack->client); jack->activated = 0; @@ -360,6 +361,7 @@ static snd_pcm_ioplug_callback_t jack_pcm_callback = { .start = snd_pcm_jack_start, .stop = snd_pcm_jack_stop, .pointer = snd_pcm_jack_pointer, + .hw_free = snd_pcm_jack_hw_free, .prepare = snd_pcm_jack_prepare, .poll_revents = snd_pcm_jack_poll_revents, };