From patchwork Thu Nov 17 15:26:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Young X-Patchwork-Id: 9434569 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 F0C9960238 for ; Thu, 17 Nov 2016 16:43:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E15AF29207 for ; Thu, 17 Nov 2016 16:43:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D415229648; Thu, 17 Nov 2016 16:43:29 +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 0925429207 for ; Thu, 17 Nov 2016 16:43:28 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 421072666EF; Thu, 17 Nov 2016 17:43:27 +0100 (CET) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id 988F0265DB7; Thu, 17 Nov 2016 17:41:06 +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 A481926756F; Thu, 17 Nov 2016 16:26:07 +0100 (CET) Received: from mail-wm0-f50.google.com (mail-wm0-f50.google.com [74.125.82.50]) by alsa0.perex.cz (Postfix) with ESMTP id E0F70267566 for ; Thu, 17 Nov 2016 16:26:01 +0100 (CET) Received: by mail-wm0-f50.google.com with SMTP id a197so317253791wmd.0 for ; Thu, 17 Nov 2016 07:26:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:subject:to:references:from:message-id:date:user-agent :mime-version:in-reply-to; bh=CfL50X5fJ6HE0CAkgnr1VaaVdUN5naQOtNNxDQU4Jr8=; b=iIl7jpWa9YIXgz/rFZ+1Rwz15WB/YXpzn/BYiJrztFK8TTB11ZTrQMyUzjexeo3oyC /Y51FX2yfehLSA3Y2MueBFcnzxNboVpeh5vD/HW8aKD4ItA99OWLm0szXroPO7s3IbGR 2Pwj3s7tzB855oT7fyyZT17u56z58qnr1tNoafJsoXmN7sN9G0Y75fS1dPRI8r/5zqSo xbWzxpbkttEpOMHd6p/AYLQ7ssInME8EXzgwk0hQNM10i84qY5+FWTGhqL/PTU4BvgX6 QpxGpz+uqQfroJHtHHZ8zMb1akzR/N0sfH0Bgg35Tilh9xK1DPY+n3YISyfmNud/7Vf6 vBwQ== 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:from:message-id :date:user-agent:mime-version:in-reply-to; bh=CfL50X5fJ6HE0CAkgnr1VaaVdUN5naQOtNNxDQU4Jr8=; b=KngHVLG8kBijc1oz6DM/KxE2k7polLXzoDifKff1Y0XQws4pUnHExKxkj5hT2L242v JG7PNSkb8I1h475t/huu9PZhaKmrIDu4P4a8+y2YE3wiJF1pRky8dv6ZAoPjwKLVrkmR t7SLh+TQSf2wAOEGO5RaUzURWkvAhcTxXHEznshivIyulBZeCIBx2RcNU9pgwVAkRduW CQizoZoG17mLkPC4v+gSdpCBaolCNFjfD1/tnnQLD2C81NyXqsx/M2Z+LoZoTcJJUdWh dVZkmYlFYQjmSDshh+c+yfqFx+8dpqQyMgBSofziYOFzOKalp6SdJsTRSTOLytmEO4bK q6VA== X-Gm-Message-State: AKaTC01wIOGcXV+0xICpkajhSbk0DrnMZia3RI9sb3TYT6GhFyJRYsvXCtt8Sng+DOob4A== X-Received: by 10.194.146.228 with SMTP id tf4mr2492799wjb.183.1479396360915; Thu, 17 Nov 2016 07:26:00 -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 n17sm3827407wjq.6.2016.11.17.07.26.00 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 17 Nov 2016 07:26:00 -0800 (PST) To: alsa-devel@alsa-project.org References: From: Alan Young Message-ID: <98eabe32-669e-c65a-70f4-a419fee31851@IEE.org> Date: Thu, 17 Nov 2016 15:26:00 +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 Subject: Re: [alsa-devel] [PATCH] 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 X-Virus-Scanned: ClamAV using ClamSMTP On 17/11/16 15:24, Alan Young wrote: > > Similar to recent dshare patch. > Update with sign-off 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