From patchwork Tue Dec 13 13:05:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Young X-Patchwork-Id: 9472267 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 4290E60476 for ; Tue, 13 Dec 2016 13:18:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 37FBF28585 for ; Tue, 13 Dec 2016 13:18:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C6DB2858D; Tue, 13 Dec 2016 13:18:35 +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 D32FA28585 for ; Tue, 13 Dec 2016 13:18:33 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 3B66E266E28; Tue, 13 Dec 2016 14:18:31 +0100 (CET) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id D327C266DEC; Tue, 13 Dec 2016 14:16:09 +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 B2C57266E04; Tue, 13 Dec 2016 14:05:43 +0100 (CET) Received: from mail-wm0-f41.google.com (mail-wm0-f41.google.com [74.125.82.41]) by alsa0.perex.cz (Postfix) with ESMTP id 20970266DEC for ; Tue, 13 Dec 2016 14:05:39 +0100 (CET) Received: by mail-wm0-f41.google.com with SMTP id a197so108773098wmd.0 for ; Tue, 13 Dec 2016 05:05:39 -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; bh=IZIcPNWHQrCDm9/ICcRF0UHB2M0VIgQkHXxEbgbxklM=; b=yzf6VMhIWipN6vioQ+Qw7kXQX1Z1DyS2S548W8XwSwFZwJpbLHfG4cduvaRS9ijf9a i/0mv0ZWB6D02BxfzV5HgYZjCJK3739oPjPtY8AZYcCM4l5TgUcii93TPUXLwMAsvhlY 3yunsm1GpTpQuNbFNkt72s6m7Y/a/jt8vru400Kxlugy3B/bR95uhFQp/NU1ZkRyt1z2 NqTFUuucjvgjKkoHDMwO9+gMFBbfNAHIUJxd3ERPYLuzlSzvd1NbfDO9VTeTPO2hUyPq PSXyL/tLzDYnQqypJaUzOxEDSPI6pg55XDIvjvWtAPBLW9WL4e/lLj/qJb7UyPkcT0P5 fVHw== 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=IZIcPNWHQrCDm9/ICcRF0UHB2M0VIgQkHXxEbgbxklM=; b=fYbrlVIQAODVs2l8SHNeVLfVlDy7yksrCr4LsgpxugrbOjCxQO48+AhWhVlh0OUyPU IjCgT5Wat1RP9W5/1wy0roCY/05xsu68KA+Hpt5YaoopRon8X2fb6lSDunq2G1fzxEWR AvVTXhrTDrfvF7nscxWnlhGZQZKWe4ml7sSxkUTLASi5DqQO00mGiBhaPB7+eaBytQaI GoIu7sHfczO3lHtvIWWBd1cLrgijmNbUtiSL7SvuJqKFp8V6b/XWGhirhzYcP2vMEPhd aCMdwRveFhHyOdDfRFXwnIQQxDWp6pMyMD/qUzaYnzsFC0T1ToEhsSta7FQDxefIC8WD qJ2Q== X-Gm-Message-State: AKaTC00xg2K658QvfLUEAvaY9oITFA1Mz0cqTu7RdmRPsdwoVfr48Jv9MrVBGRnRPCR7OA== X-Received: by 10.28.109.156 with SMTP id b28mr2555374wmi.116.1481634337952; Tue, 13 Dec 2016 05:05:37 -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 d64sm2553035wmh.3.2016.12.13.05.05.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 13 Dec 2016 05:05:37 -0800 (PST) To: Takashi Iwai References: <52e39131-9141-b466-e92a-ff19ffab6d3a@IEE.org> <372cbe9d-2456-75e0-cdaf-056df21a4b31@IEE.org> From: Alan Young Message-ID: <29c0939c-685e-375f-73d6-167e40f6a388@IEE.org> Date: Tue, 13 Dec 2016 13:05:36 +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: alsa-devel@alsa-project.org 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 X-Virus-Scanned: ClamAV using ClamSMTP On 13/12/16 11:49, Takashi Iwai wrote: > Compare the argument you passed there and the function definition, > it's obvious:) !$$"%%! Ouch. Sorry about that. One of those things that can happen when a patch is cherry-picked and "fixed". Not really sure why it compiles with just a warning. Fixed patch attached. Alan. From b3aacdcee7431142748d675ebc8792cb0ca02630 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 | 49 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/src/pcm/pcm_rate.c b/src/pcm/pcm_rate.c index 6184def..f340b67 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,20 @@ 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(pcm, 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); + // Maybe possible to somthing similar to + // snd_pcm_rate_playback_internal_delay() + // for the capture case. status->avail = snd_pcm_mmap_capture_avail(pcm); status->avail_max = rate->ops.output_frames(rate->obj, status->avail_max); } -- 2.5.5