From: Alan Young <Alan.Young@IEE.org>
To: Takashi Iwai <tiwai@suse.de>
Cc: alsa-devel@alsa-project.org
Subject: Re: Accurate delay reporting from dshare
Date: Wed, 2 Nov 2016 17:34:49 +0000 [thread overview]
Message-ID: <581A23B9.3050609@IEE.org> (raw)
In-Reply-To: <5819F566.2000404@IEE.org>
On 02/11/16 14:17, Alan Young wrote:
> I am wondering if the earlier call to snd_pcm_dshare_sync_ptr(pcm),
> which I guess forms the basis for the result of
> snd_pcm_mmap_playback_delay(pcm), may be operating on a different set
> of data (because of an intervening interrupt) to that returned by
> snd_pcm_status().
How about this for a revised patch. It seems to be working well for me
(so far). I am not suggesting that this should be considered final yet.
Alan.
diff --git a/src/pcm/pcm_dshare.c b/src/pcm/pcm_dshare.c
index 58e47bb..568448c 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;
}
next prev parent reply other threads:[~2016-11-02 17:34 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-10-26 14:30 Accurate delay reporting from dshare Alan Young
2016-10-27 10:52 ` Takashi Iwai
2016-11-02 14:17 ` Alan Young
2016-11-02 17:34 ` Alan Young [this message]
2016-11-17 8:20 ` [PATCH] pcm_dshare: Do not discard slave reported delay in status result Alan Young
2016-11-17 10:31 ` Takashi Iwai
2016-11-17 14:18 ` Alan Young
2016-11-17 14:21 ` Takashi Iwai
2016-11-17 14:35 ` Alan Young
2016-11-17 15:12 ` Takashi Iwai
2016-11-17 15:18 ` Alan Young
2016-11-17 15:20 ` Takashi Iwai
-- strict thread matches above, loose matches on Subject: below --
2016-10-27 10:15 Accurate delay reporting from dshare Alan Young
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=581A23B9.3050609@IEE.org \
--to=alan.young@iee.org \
--cc=alsa-devel@alsa-project.org \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.