From: Alan Young Subject: Re: [PATCH] pcm_dshare: Do not discard slave reported delay in status result. Date: Thu, 17 Nov 2016 15:18:53 +0000 Message-ID: References: <5810BDF9.1020204@IEE.org> <5819F566.2000404@IEE.org> <581A23B9.3050609@IEE.org> <67297312-c4f9-e47d-4b58-893ddb55d2c8@IEE.org> <8e7fb17d-bf2e-bb4b-8c75-7762f773abe6@IEE.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------9F901CCE96563A51CA7D50F1" Return-path: Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) by alsa0.perex.cz (Postfix) with ESMTP id 0E103266A28 for ; Thu, 17 Nov 2016 16:18:54 +0100 (CET) Received: by mail-wm0-f43.google.com with SMTP id g23so317287942wme.1 for ; Thu, 17 Nov 2016 07:18:54 -0800 (PST) In-Reply-To: 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 To: Takashi Iwai Cc: alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org This is a multi-part message in MIME format. --------------9F901CCE96563A51CA7D50F1 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit On 17/11/16 15:12, Takashi Iwai wrote: > On Thu, 17 Nov 2016 15:35:55 +0100, > Alan Young wrote: >> 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. >> >> Signed-off-by: Alan Young > Unfortunately, your MUA seems malforming the texts and does > line-break and replacing the tabs, so the patch is broken. > Please either fix your MUA setup or use an attachment as a fallback. Let's try an attachment. --------------9F901CCE96563A51CA7D50F1 Content-Type: text/x-patch; name="0001-pcm_dshare-Do-not-discard-slave-reported-delay-in-st.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename*0="0001-pcm_dshare-Do-not-discard-slave-reported-delay-in-st.pa"; filename*1="tch" >From f459991615254066f687ca8d0aef2bdfeff33964 Mon Sep 17 00:00:00 2001 From: Alan Young Date: Wed, 2 Nov 2016 17:40:32 +0000 Subject: [PATCH] pcm_dshare: Do not discard slave reported delay in status result. 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. Signed-off-by: Alan Young --- 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; } -- 2.5.5 --------------9F901CCE96563A51CA7D50F1 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --------------9F901CCE96563A51CA7D50F1--