From patchwork Fri Mar 16 14:23:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Wischer X-Patchwork-Id: 10287567 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 2D18E601A0 for ; Fri, 16 Mar 2018 14:23:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C6FE25223 for ; Fri, 16 Mar 2018 14:23:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1141728D07; Fri, 16 Mar 2018 14:23:58 +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.9 required=2.0 tests=BAYES_00, 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 2D20125223 for ; Fri, 16 Mar 2018 14:23:57 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 66DDD26753D; Fri, 16 Mar 2018 15:23:54 +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 1A8CB267544; Fri, 16 Mar 2018 15:23:52 +0100 (CET) Received: from smtp1.de.adit-jv.com (smtp1.de.adit-jv.com [62.225.105.245]) by alsa0.perex.cz (Postfix) with ESMTP id EA3A026753D for ; Fri, 16 Mar 2018 15:23:47 +0100 (CET) Received: from localhost (smtp1.de.adit-jv.com [127.0.0.1]) by smtp1.de.adit-jv.com (Postfix) with ESMTP id 507903C09A2; Fri, 16 Mar 2018 15:23:47 +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 Vbw2F6HPUpus; Fri, 16 Mar 2018 15:23:41 +0100 (CET) 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 115A83C0BA5; Fri, 16 Mar 2018 15:23:38 +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.382.0; Fri, 16 Mar 2018 15:23:37 +0100 From: To: Date: Fri, 16 Mar 2018 15:23:32 +0100 Message-ID: <1521210212-30923-2-git-send-email-twischer@de.adit-jv.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521210212-30923-1-git-send-email-twischer@de.adit-jv.com> References: <1519910048-19732-4-git-send-email-twischer@de.adit-jv.com> <1521210212-30923-1-git-send-email-twischer@de.adit-jv.com> MIME-Version: 1.0 X-Originating-IP: [10.72.93.172] Cc: tiwai@suse.de, Timo Wischer Subject: [alsa-devel] [PATCH - JACK 1/1] jack: Report Xruns to user application 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 Only increasing the hw_ptr is not sufficient because it will not be evaluated by the ALSA library to detect an Xrun. In addition there is a raise where an Xrun detected by the JACK thread could not be detected in the ALSA thread. - In playback use case - The hw_ptr will be increased by the JACK thread (hw_ptr > appl_ptr => Xrun) - But the ALSA thread increases the appl_ptr before evaluating the hw_ptr - Therefore the hw_ptr < appl_ptr again - ALSA will not detect the Xrun which was already detected by the JACK thread Therefore an additional variable is required to report an Xrun from the JACK thread to ALSA. Signed-off-by: Timo Wischer diff --git a/jack/pcm_jack.c b/jack/pcm_jack.c index 7c7c230..a655668 100644 --- a/jack/pcm_jack.c +++ b/jack/pcm_jack.c @@ -20,6 +20,7 @@ * */ +#include #include #include #include @@ -50,6 +51,9 @@ typedef struct { jack_port_t **ports; jack_client_t *client; + + /* JACK thread -> ALSA thread */ + bool xrun_detected; } snd_pcm_jack_t; static int snd_pcm_jack_stop(snd_pcm_ioplug_t *io); @@ -133,6 +137,9 @@ static snd_pcm_sframes_t snd_pcm_jack_pointer(snd_pcm_ioplug_t *io) { snd_pcm_jack_t *jack = io->private_data; + if (jack->xrun_detected) + return -EPIPE; + #ifdef SND_PCM_IOPLUG_FLAG_BOUNDARY_WA return jack->hw_ptr; #else @@ -196,6 +203,20 @@ snd_pcm_jack_process_cb(jack_nframes_t nframes, snd_pcm_ioplug_t *io) snd_pcm_areas_silence(jack->areas, io->channels, xfer, 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 { + /* report Xrun to user application */ + jack->xrun_detected = true; + } } pcm_poll_unblock_check(io); /* unblock socket for polling if needed */ @@ -211,6 +232,7 @@ static int snd_pcm_jack_prepare(snd_pcm_ioplug_t *io) int err; jack->hw_ptr = 0; + jack->xrun_detected = false; jack->min_avail = io->period_size; snd_pcm_sw_params_alloca(&swparams);