From patchwork Tue Jul 3 13:59:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Wischer X-Patchwork-Id: 10504155 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 D7FE660325 for ; Tue, 3 Jul 2018 14:00:15 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C436828BAC for ; Tue, 3 Jul 2018 14:00:15 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C2A6328B3D; Tue, 3 Jul 2018 14:00:15 +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 F25E228BBE for ; Tue, 3 Jul 2018 14:00:14 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id BA429267734; Tue, 3 Jul 2018 15:59:56 +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 63AFB267782; Tue, 3 Jul 2018 15:59:52 +0200 (CEST) Received: from smtp1.de.adit-jv.com (smtp1.de.adit-jv.com [62.225.105.245]) by alsa0.perex.cz (Postfix) with ESMTP id B814D267763; Tue, 3 Jul 2018 15:59:49 +0200 (CEST) Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id 62F053C09AC; Tue, 3 Jul 2018 15:59:49 +0200 (CEST) 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 lfGu3TfjCSoS; Tue, 3 Jul 2018 15:59:42 +0200 (CEST) Received: from HI2EXCH01.adit-jv.com (hi2exch01.adit-jv.com [10.72.92.24]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp1.de.adit-jv.com (Postfix) with ESMTPS id 095AB3C09AF; Tue, 3 Jul 2018 15:59:35 +0200 (CEST) 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.399.0; Tue, 3 Jul 2018 15:59:34 +0200 From: To: , Date: Tue, 3 Jul 2018 15:59:23 +0200 Message-ID: <1530626363-8808-4-git-send-email-twischer@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1530626363-8808-1-git-send-email-twischer@de.adit-jv.com> References: <1530626363-8808-1-git-send-email-twischer@de.adit-jv.com> MIME-Version: 1.0 X-Originating-IP: [10.72.93.172] Cc: Timo Wischer , alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH - JACK IO plug 2/2] jack: Update poll_fd also in draining state 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: Timo Wischer to support snd_pcm_drain for the JACK IO plugin. With this changes there will be an poll_fd event in DRAINING state even if the min_avail was not yet reached. Otherwise the application would never recognize that all samples were processed by JACK. In addition the JACK real-time thread is also processing when in DRAINING state and not only when in RUNNING or PREPARE state. Signed-off-by: Timo Wischer diff --git a/jack/pcm_jack.c b/jack/pcm_jack.c index 5a57e13..98a6f7e 100644 --- a/jack/pcm_jack.c +++ b/jack/pcm_jack.c @@ -66,6 +66,7 @@ static int pcm_poll_block_check(snd_pcm_ioplug_t *io) snd_pcm_jack_t *jack = io->private_data; if (io->state == SND_PCM_STATE_RUNNING || + io->state == SND_PCM_STATE_DRAINING || (io->state == SND_PCM_STATE_PREPARED && io->stream == SND_PCM_STREAM_CAPTURE)) { avail = snd_pcm_ioplug_avail(io, jack->hw_ptr, io->appl_ptr); if (avail < jack->min_avail) { @@ -85,7 +86,12 @@ static int pcm_poll_unblock_check(snd_pcm_ioplug_t *io) snd_pcm_jack_t *jack = io->private_data; avail = snd_pcm_ioplug_avail(io, jack->hw_ptr, io->appl_ptr); - if (avail >= jack->min_avail) { + /* In draining state poll_fd is used to wait + * till all pending frames are played. + * Therefore it has to be guarantee that a poll event is also generated + * if the buffer contains less than min_avail frames + */ + if (avail >= jack->min_avail || io->state == SND_PCM_STATE_DRAINING) { write(jack->fd, &buf, 1); return 1; } @@ -161,7 +167,8 @@ snd_pcm_jack_process_cb(jack_nframes_t nframes, snd_pcm_ioplug_t *io) jack->areas[channel].step = jack->sample_bits; } - if (io->state == SND_PCM_STATE_RUNNING) { + if (io->state == SND_PCM_STATE_RUNNING || + io->state == SND_PCM_STATE_DRAINING) { snd_pcm_uframes_t hw_ptr = jack->hw_ptr; const snd_pcm_uframes_t hw_avail = snd_pcm_ioplug_hw_avail(io, hw_ptr, io->appl_ptr);