From patchwork Wed Nov 2 17:34:49 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Young X-Patchwork-Id: 9410019 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 C1CBD60721 for ; Thu, 3 Nov 2016 00:16:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AF02D2A65D for ; Thu, 3 Nov 2016 00:16:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9FB942A6AD; Thu, 3 Nov 2016 00:16:36 +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 D6FC02A65D for ; Thu, 3 Nov 2016 00:16:35 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id EB96C2670A1; Thu, 3 Nov 2016 01:16:33 +0100 (CET) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id A0C5B266615; Thu, 3 Nov 2016 01:14:14 +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 CA196266F5C; Wed, 2 Nov 2016 18:34:53 +0100 (CET) Received: from mail-wm0-f68.google.com (mail-wm0-f68.google.com [74.125.82.68]) by alsa0.perex.cz (Postfix) with ESMTP id 0ED16265654 for ; Wed, 2 Nov 2016 18:34:51 +0100 (CET) Received: by mail-wm0-f68.google.com with SMTP id u144so4129631wmu.0 for ; Wed, 02 Nov 2016 10:34:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to; bh=CBa9ipvBt4saDEg/2TtqcjybiEWT/kwyrT1Thg8OSUw=; b=fPChysn6RK4O4rWdtCt0C4tGSjbTIrhb2YyfPWx6yTUQ5bdlm9fCGYj93qbtEIGYzY mtcKCECxVsDNWPopi6iZ2bkugrhrl39XGHWEm1+JorhG/liuGii9y6oquiAbB0UV7sSZ 4WPxoOOmOuIc/oOAQnRMsIFqvaTcGsrnkw15WNEWHskHmDJI4XJwPhHkBU/9XJnK1LZG VMOrson8A4+Z7tHpwuah08ZjUehrjzgUYX4S6lxrEgJBI8/Lf3/xMU+DN8E6KKqloTWF yrMl0BfoqFZZ8J5fBIhyFigGz7/sc7kpu0sSJ0vTJ9ZJOvbof1I0JEFgRkb4RZcIZYwm woew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:subject:to:references:cc:from:message-id :date:user-agent:mime-version:in-reply-to; bh=CBa9ipvBt4saDEg/2TtqcjybiEWT/kwyrT1Thg8OSUw=; b=P0UGCwFUFsnXPGPvDNlVxNGpBQJC0DytXHbK7WYArGT+pGaI9IK6E18sJH3VCbjZGC 4uS1pohV6xO5ag0DVxBUBLATORtwE4aC+mBJltmzPXBVU7R/X8QcjwYsAzay0BdAQdU1 yBbVGWpG5zrmtUa+jb/V7Og7PXohikuLUdeQ/VoF/BFFnD8V6N2x/IGzXZtj5Vl08Qmi YgQaiaUad1Mie9QEQtkKSeuSWXLhg2zeNqXz/xRJ4IHlVGjMJB466lJkRoYNQde8Z8KQ 3Zy4evtkqOFe0yHgYi8xUxsFXk79+oLUoY7VX4G+YoQvcB1UK1gMH2kLHCkpLkzyzywG bu6g== X-Gm-Message-State: ABUngveVgZYTZlOOFFopnBVWtPf86kmERVmVZFIa02LCv7VkU/A6dwCZW3jFUbDJLKK68w== X-Received: by 10.194.179.193 with SMTP id di1mr3851866wjc.72.1478108091332; Wed, 02 Nov 2016 10:34:51 -0700 (PDT) Received: from [192.168.11.11] (13.110.6.51.dyn.plus.net. [51.6.110.13]) by smtp.googlemail.com with ESMTPSA id yo1sm3989243wjc.16.2016.11.02.10.34.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Nov 2016 10:34:50 -0700 (PDT) To: Takashi Iwai References: <5810BDF9.1020204@IEE.org> <5819F566.2000404@IEE.org> From: Alan Young Message-ID: <581A23B9.3050609@IEE.org> Date: Wed, 2 Nov 2016 17:34:49 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.6.0 MIME-Version: 1.0 In-Reply-To: <5819F566.2000404@IEE.org> X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: alsa-devel@alsa-project.org Subject: Re: [alsa-devel] Accurate delay reporting from dshare 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 On 02/11/16 14:17, Alan Young wrote: > I am wondering if the earlier call to snd_pcm_dshare_sync_ptr(pcm), > which I guess forms the basis for the result of > snd_pcm_mmap_playback_delay(pcm), may be operating on a different set > of data (because of an intervening interrupt) to that returned by > snd_pcm_status(). How about this for a revised patch. It seems to be working well for me (so far). I am not suggesting that this should be considered final yet. Alan. diff --git a/src/pcm/pcm_dshare.c b/src/pcm/pcm_dshare.c index 58e47bb..568448c 100644 --- a/src/pcm/pcm_dshare.c +++ b/src/pcm/pcm_dshare.c @@ -157,23 +157,14 @@ static void snd_pcm_dshare_sync_area(snd_pcm_t *pcm) /* * synchronize hardware pointer (hw_ptr) with ours */ -static int snd_pcm_dshare_sync_ptr(snd_pcm_t *pcm) +static int snd_pcm_dshare_sync_ptr0(snd_pcm_t *pcm, snd_pcm_uframes_t slave_hw_ptr) { snd_pcm_direct_t *dshare = pcm->private_data; - snd_pcm_uframes_t slave_hw_ptr, old_slave_hw_ptr, avail; + snd_pcm_uframes_t old_slave_hw_ptr, avail; snd_pcm_sframes_t diff; - switch (snd_pcm_state(dshare->spcm)) { - case SND_PCM_STATE_DISCONNECTED: - dshare->state = SNDRV_PCM_STATE_DISCONNECTED; - return -ENODEV; - default: - break; - } - if (dshare->slowptr) - snd_pcm_hwsync(dshare->spcm); old_slave_hw_ptr = dshare->slave_hw_ptr; - slave_hw_ptr = dshare->slave_hw_ptr = *dshare->spcm->hw.ptr; + dshare->slave_hw_ptr = slave_hw_ptr; diff = slave_hw_ptr - old_slave_hw_ptr; if (diff == 0) /* fast path */ return 0; @@ -207,6 +198,24 @@ static int snd_pcm_dshare_sync_ptr(snd_pcm_t *pcm) return 0; } +static int snd_pcm_dshare_sync_ptr(snd_pcm_t *pcm) +{ + snd_pcm_direct_t *dshare = pcm->private_data; + + switch (snd_pcm_state(dshare->spcm)) { + case SND_PCM_STATE_DISCONNECTED: + dshare->state = SNDRV_PCM_STATE_DISCONNECTED; + return -ENODEV; + default: + break; + } + + if (dshare->slowptr) + snd_pcm_hwsync(dshare->spcm); + + return snd_pcm_dshare_sync_ptr0(pcm, *dshare->spcm->hw.ptr); +} + /* * plugin implementation */ @@ -215,22 +224,24 @@ static int snd_pcm_dshare_status(snd_pcm_t *pcm, snd_pcm_status_t * status) { snd_pcm_direct_t *dshare = pcm->private_data; + memset(status, 0, sizeof(*status)); + snd_pcm_status(dshare->spcm, status); + switch (dshare->state) { case SNDRV_PCM_STATE_DRAINING: case SNDRV_PCM_STATE_RUNNING: - snd_pcm_dshare_sync_ptr(pcm); + snd_pcm_dshare_sync_ptr0(pcm, status->hw_ptr); + status->delay += snd_pcm_mmap_playback_delay(pcm) + + status->avail - dshare->spcm->buffer_size; break; default: break; } - memset(status, 0, sizeof(*status)); - snd_pcm_status(dshare->spcm, status); - status->state = snd_pcm_state(dshare->spcm); + status->trigger_tstamp = dshare->trigger_tstamp; status->avail = snd_pcm_mmap_playback_avail(pcm); status->avail_max = status->avail > dshare->avail_max ? status->avail : dshare->avail_max; dshare->avail_max = 0; - status->delay = snd_pcm_mmap_playback_delay(pcm); return 0; }