From: Takashi Iwai Subject: Re: [PATCH] alsa-lib: Provide a CLOCK_MONOTONIC_RAW timestamp type Date: Wed, 09 Jul 2014 15:38:51 +0200 Message-ID: References: <1404831152-8064-1-git-send-email-broonie@kernel.org> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (cantor2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id B931326508D for ; Wed, 9 Jul 2014 15:38:52 +0200 (CEST) In-Reply-To: <1404831152-8064-1-git-send-email-broonie@kernel.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 To: Mark Brown Cc: alsa-devel@alsa-project.org, Mark Brown , Daniel Thompson List-Id: alsa-devel@alsa-project.org At Tue, 8 Jul 2014 16:52:32 +0200, Mark Brown wrote: > > From: Mark Brown > > For applications which need to synchronise with external timebases such > as broadcast TV applications the kernel monotonic time is not optimal as > it includes adjustments from NTP and so may still include discontinuities > due to that. A raw monotonic time which does not include any adjustments > is available in the kernel from getrawmonotonic() so provide userspace with > a new timestamp type SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW which provides > timestamps based on this as an option. > > Reported-by: Daniel Thompson > Signed-off-by: Mark Brown Currently, the timestamp mode is set implicitly in alsa-lib pcm_hw.c: - When kernel PCM protocol version is high enough, alsa-lib hw prefers the monotonic always (if available), then set pcm->monotonic = 1. - Application can ask whether the current timestamp is monotonic or not via snd_pcm_hw_params_is_monotonic(). So, only adding the flag above doesn't suffice. If we need to add a new mode, the API has to be extended as well. But how? The current API assumes that the monotonic mode was already determined before hw_params. We may add a set of new hw_params get and set calls for tstamp mode while keeping the old API. This would be one option. Another option would be to add a new PCM open flag SND_PCM_TSTAMP_MONOTONIC_RAW, and snd_pcm_hw_params_is_monotonic_raw() function. The latter is easier (a simpler addition), while the former is more extensible to newer formats in future. Comments? (I guess tinyalsa has a different story, but let's align genuine alsa-lib first.) Takashi > --- > include/sound/asound.h | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/include/sound/asound.h b/include/sound/asound.h > index 1774a5c..9061cdd 100644 > --- a/include/sound/asound.h > +++ b/include/sound/asound.h > @@ -457,7 +457,8 @@ struct snd_xfern { > enum { > SNDRV_PCM_TSTAMP_TYPE_GETTIMEOFDAY = 0, /* gettimeofday equivalent */ > SNDRV_PCM_TSTAMP_TYPE_MONOTONIC, /* posix_clock_monotonic equivalent */ > - SNDRV_PCM_TSTAMP_TYPE_LAST = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC, > + SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW, /* monotonic_raw (no NTP) */ > + SNDRV_PCM_TSTAMP_TYPE_LAST = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW, > }; > > /* channel positions */ > -- > 2.0.0 >