From patchwork Thu Nov 17 08:20:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Young X-Patchwork-Id: 9433617 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 E28F460238 for ; Thu, 17 Nov 2016 08:23:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C541829329 for ; Thu, 17 Nov 2016 08:23:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B4B642932C; Thu, 17 Nov 2016 08:23:05 +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 1275929329 for ; Thu, 17 Nov 2016 08:23:00 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 95992266967; Thu, 17 Nov 2016 09:22:59 +0100 (CET) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id E04FC266801; Thu, 17 Nov 2016 09:20:33 +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 352B2266834; Thu, 17 Nov 2016 09:20:24 +0100 (CET) Received: from mail-wm0-f66.google.com (mail-wm0-f66.google.com [74.125.82.66]) by alsa0.perex.cz (Postfix) with ESMTP id 828C32614A0 for ; Thu, 17 Nov 2016 09:20:18 +0100 (CET) Received: by mail-wm0-f66.google.com with SMTP id a20so18812028wme.2 for ; Thu, 17 Nov 2016 00:20:18 -0800 (PST) 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:content-transfer-encoding; bh=WDSLJSbScihjw/j9H+1C5icKRrXnsb6VnQz/IzbuXFM=; b=tTLu15qqf6e8OunDibWaIapGNlMibMH997l9SthItbD9Cw/F3HBNO1Ihx7Ewi+mmu3 Nu98Tgz0y89C+49kMO5ZgI1ju9kQP7tV3AxIFGDeNrP0pGAQHgK6IUMqiYd4ANF/uke3 jHYGW9Y42azPCLnGEddXggWpEOM8HKFKFIUZ+4xx/Aqk0p9XMCFFbADNYCbvFgdtp043 WvWxwWg3xPyUTd0mf4NnxQu7pz9J4iw4SqrhMYgv0tEkdvJKTCm0ZhDpSa5BVnj311hq YERV6Ct/vUZoYYzQykE8hLrqr0yG4nOUNKJLEpwHGaSZtV+KG/j77167CwGzaC0KHpn/ 7tFg== 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:content-transfer-encoding; bh=WDSLJSbScihjw/j9H+1C5icKRrXnsb6VnQz/IzbuXFM=; b=SO4GwXwofXMc2I4SsRuHE1FyTWyrpXpnTQFPev7rTu2Y1OpBTqjTiT/pCZX9SOpu+s d4Z491OhTTVGsM873p6l5SgerEjmgjbn6m5gvjj9zspKZm79Q55WLocd/KL7ZvV9WMRf ewAzEBRpB0BrKixHZrxuDCsLSk1ipC2NVb4eBxtFFg4itauTMmANsHuyvmLNPkhJT+Mn tfiW/1EqRB3vJR9jUvplhKDhiHkiKBZGTgg76Wjegrzb3IN0Ou0PmY/qhYJkUiyAuT0f i3kAIxbSR3MuJljW7ryQKQ6Fi91+igsPAXfhMgvI/U2UL4GxENOrS1JyS9ciHmandjvG ewXQ== X-Gm-Message-State: ABUngvfUU0tNd17cJSbZVrYLV7pbdTMi7l4cTGYQEl6iW2+YEdL44myg2icxWH34hnY5ew== X-Received: by 10.28.47.196 with SMTP id v187mr14188592wmv.75.1479370817667; Thu, 17 Nov 2016 00:20:17 -0800 (PST) Received: from [192.168.11.11] (178.55.208.46.dyn.plus.net. [46.208.55.178]) by smtp.googlemail.com with ESMTPSA id l67sm14211634wmf.20.2016.11.17.00.20.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Nov 2016 00:20:17 -0800 (PST) To: Takashi Iwai References: <5810BDF9.1020204@IEE.org> <5819F566.2000404@IEE.org> <581A23B9.3050609@IEE.org> From: Alan Young Message-ID: Date: Thu, 17 Nov 2016 08:20:16 +0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.4.0 MIME-Version: 1.0 In-Reply-To: <581A23B9.3050609@IEE.org> Cc: alsa-devel@alsa-project.org Subject: [alsa-devel] [PATCH] pcm_dshare: Do not discard slave reported delay in status result. 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 snd_pcm_dshare_status() gets the underlying status from the slave PCM. This may contain a delay value that includes elements such as codec and other transfer delays. Use this as the base for the returned delay value, adjusted for any frames buffered locally (within the dshare plugin). Note: snd_pcm_dshare_delay() is not updated. --- src/pcm/pcm_dshare.c | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/src/pcm/pcm_dshare.c b/src/pcm/pcm_dshare.c index c5b3178..9b478a7 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; }