From patchwork Thu Nov 17 17:12:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Young X-Patchwork-Id: 82795 Delivered-To: patch@linaro.org Received: by 10.140.97.165 with SMTP id m34csp973546qge; Thu, 17 Nov 2016 12:41:35 -0800 (PST) X-Received: by 10.194.121.6 with SMTP id lg6mr4049517wjb.105.1479415294982; Thu, 17 Nov 2016 12:41:34 -0800 (PST) Return-Path: Received: from alsa0.perex.cz (alsa0.perex.cz. [77.48.224.243]) by mx.google.com with ESMTP id f1si4418482wjl.229.2016.11.17.12.41.34; Thu, 17 Nov 2016 12:41:34 -0800 (PST) Received-SPF: pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) client-ip=77.48.224.243; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com; spf=pass (google.com: domain of alsa-devel-bounces@alsa-project.org designates 77.48.224.243 as permitted sender) smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 8201B26761B; Thu, 17 Nov 2016 21:41:33 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on mail1.perex.cz X-Spam-Level: X-Spam-Status: No, score=0.6 required=5.0 tests=DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM,T_DKIM_INVALID autolearn=disabled version=3.4.0 Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id E17062675F3; Thu, 17 Nov 2016 21:39:10 +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 EE05326699B; Thu, 17 Nov 2016 18:13:04 +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 4E6B52663E8 for ; Thu, 17 Nov 2016 18:12:59 +0100 (CET) Received: by mail-wm0-f68.google.com with SMTP id m203so23128049wma.3 for ; Thu, 17 Nov 2016 09:12:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:subject:to:references:cc:message-id:date:user-agent :mime-version:in-reply-to; bh=Vm+7e6rpptuCWrPjpS+v6QrnM2RAUcKtOggnRKyTDEc=; b=TQ9+CvUvSG1WgN7Ab20QAx6hUuEnhAks8lpzVnzMAnkqJ7DjFbjDjE/nyinm9JAL+2 pjuNHGM5m/R8Z0Yj/o2EWux9yNsnA1IRvKkTea12KLJznRXE2M0hQYpvDZJm3iTbtSd9 RQTHsSmbluUEUiqA4X1FsX3b4Eawu0X+Qq8RkrceS9axE15zNOnU+xlJflQRy/cCx0PG 03/nqINSfjYKRg/2V1GGrT6acCi3j+FjC88Ko+77yWvfGB6TkBDX0WCBTKjPCAEFo0yf V8n9HGxGvzaIhVVlqonunJHLKaSUcL8CGMjrRCFAh3I48V9uwR2VtIdNY5YFCbkyZiy1 NsAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:sender:from:subject:to:references:cc:message-id :date:user-agent:mime-version:in-reply-to; bh=Vm+7e6rpptuCWrPjpS+v6QrnM2RAUcKtOggnRKyTDEc=; b=iWRTIE3oq170jLm79S/xxhhM6bWKMJGU2fOZeRZ/GoKmi+1fenDH+k9yk5m/79JxxG f/Y46K0qdDfNDkr4tlbeckdxF9uNV/qZnp2fbnKfznHg9NIQfIUoGUw0xQdXPsKoBBRo eqsngZZCYPp86QvD6wYFEW2UE+Tx7va8lFkOy6Z7T6XMiIy5l96M4gJiwqg8GQ+MLkZY aePBaOb1x87PUUCNZenJhfkAkFQZNhAcVbuvxmkWmKo4+EuSB7vGzpj5QXcHuG2Emv1U e6+H7+cZBRHlsA7sT94+B5nQvltCFkzIR3/192EdW/D5qtKf7kOkFM3BLaq6/JFaIdwg Ikug== X-Gm-Message-State: ABUngvdTFUBO5Q2INe09t4M46yPUPRYQ6ohZHQrv7jcxLRezCWKHvCVvpBJquVIX5TcevQ== X-Received: by 10.28.40.67 with SMTP id o64mr16769779wmo.40.1479402778760; Thu, 17 Nov 2016 09:12:58 -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 c81sm4748385wmf.22.2016.11.17.09.12.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Nov 2016 09:12:58 -0800 (PST) From: Alan Young To: alsa-devel@alsa-project.org References: Message-ID: <52e39131-9141-b466-e92a-ff19ffab6d3a@IEE.org> Date: Thu, 17 Nov 2016 17:12:57 +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: X-Content-Filtered-By: Mailman/MimeDel 2.1.14 Cc: Takashi Iwai Subject: Re: [alsa-devel] [PATCH RESEND] pcm_rate: 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 On 17/11/16 15:24, Alan Young wrote: > > Similar to recent dshare patch. > Update with sign-off _______________________________________________ Alsa-devel mailing list Alsa-devel@alsa-project.org http://mailman.alsa-project.org/mailman/listinfo/alsa-devel >From 6f93ee59846d2c0058ef702c1fa68d723bfb14f6 Mon Sep 17 00:00:00 2001 From: Alan Young Date: Tue, 14 Jun 2016 10:15:01 +0100 Subject: [PATCH] pcm_rate: Do not discard slave reported delay in status result. snd_pcm_rate_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 rate plugin). Also update snd_pcm_rate_delay() similarly. Signed-off-by: Alan Young --- src/pcm/pcm_rate.c | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c index 6184def..15383ae 100644 --- a/src/pcm/pcm_rate.c +++ b/src/pcm/pcm_rate.c @@ -559,10 +559,9 @@ snd_pcm_rate_read_areas1(snd_pcm_t *pcm, pcm->channels, rate); } -static inline void snd_pcm_rate_sync_hwptr(snd_pcm_t *pcm) +static inline void snd_pcm_rate_sync_hwptr0(snd_pcm_t *pcm, snd_pcm_uframes_t slave_hw_ptr) { snd_pcm_rate_t *rate = pcm->private_data; - snd_pcm_uframes_t slave_hw_ptr = *rate->gen.slave->hw.ptr; if (pcm->stream != SND_PCM_STREAM_PLAYBACK) return; @@ -576,6 +575,12 @@ static inline void snd_pcm_rate_sync_hwptr(snd_pcm_t *pcm) rate->hw_ptr %= pcm->boundary; } +static inline void snd_pcm_rate_sync_hwptr(snd_pcm_t *pcm) +{ + snd_pcm_rate_t *rate = pcm->private_data; + snd_pcm_rate_sync_hwptr0(pcm, *rate->gen.slave->hw.ptr); +} + static int snd_pcm_rate_hwsync(snd_pcm_t *pcm) { snd_pcm_rate_t *rate = pcm->private_data; @@ -586,10 +591,37 @@ static int snd_pcm_rate_hwsync(snd_pcm_t *pcm) return 0; } +static snd_pcm_uframes_t snd_pcm_rate_playback_internal_delay(snd_pcm_t *pcm) +{ + snd_pcm_rate_t *rate = pcm->private_data; + + if (rate->appl_ptr < rate->last_commit_ptr) { + return rate->appl_ptr - rate->last_commit_ptr + pcm->boundary; + } else { + return rate->appl_ptr - rate->last_commit_ptr; + } +} + static int snd_pcm_rate_delay(snd_pcm_t *pcm, snd_pcm_sframes_t *delayp) { + snd_pcm_rate_t *rate = pcm->private_data; + snd_pcm_sframes_t slave_delay; + int err; + snd_pcm_rate_hwsync(pcm); - *delayp = snd_pcm_mmap_hw_avail(pcm); + + err = snd_pcm_delay(rate->gen.slave, &slave_delay); + if (err < 0) { + return err; + } + + if (pcm->stream == SND_PCM_STREAM_PLAYBACK) { + *delayp = rate->ops.input_frames(rate->obj, slave_delay) + + snd_pcm_rate_playback_internal_delay(pcm); + } else { + *delayp = rate->ops.output_frames(rate->obj, slave_delay) + + snd_pcm_mmap_capture_hw_avail(pcm); + } return 0; } @@ -1083,15 +1115,17 @@ static int snd_pcm_rate_status(snd_pcm_t *pcm, snd_pcm_status_t * status) status->state = SND_PCM_STATE_RUNNING; status->trigger_tstamp = rate->trigger_tstamp; } - snd_pcm_rate_sync_hwptr(pcm); + snd_pcm_rate_sync_hwptr0(rate, status->hw_ptr); status->appl_ptr = *pcm->appl.ptr; status->hw_ptr = *pcm->hw.ptr; if (pcm->stream == SND_PCM_STREAM_PLAYBACK) { - status->delay = snd_pcm_mmap_playback_hw_avail(pcm); + status->delay = rate->ops.input_frames(rate->obj, status->delay) + + snd_pcm_rate_playback_internal_delay(pcm); status->avail = snd_pcm_mmap_playback_avail(pcm); status->avail_max = rate->ops.input_frames(rate->obj, status->avail_max); } else { - status->delay = snd_pcm_mmap_capture_hw_avail(pcm); + status->delay = rate->ops.output_frames(rate->obj, status->delay) + + snd_pcm_mmap_capture_hw_avail(pcm); status->avail = snd_pcm_mmap_capture_avail(pcm); status->avail_max = rate->ops.output_frames(rate->obj, status->avail_max); } -- 2.5.5