Skip to content

Commit 0ac8a52

Browse files
broonietiwai
authored andcommitted
ALSA: Provide a CLOCK_MONOTONIC_RAW timestamp type
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. [dropped tstamp_type assignment code, as it's no longer needed -- tiwai] Reported-by: Daniel Thompson <daniel.thompson@linaro.org> Signed-off-by: Mark Brown <broonie@linaro.org> Acked-by: Jaroslav Kysela <perex@perex.cz> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 2408c21 commit 0ac8a52

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎include/sound/pcm.h‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,10 +931,17 @@ void snd_pcm_timer_done(struct snd_pcm_substream *substream);
931931
static inline void snd_pcm_gettime(struct snd_pcm_runtime *runtime,
932932
struct timespec *tv)
933933
{
934-
if (runtime->tstamp_type == SNDRV_PCM_TSTAMP_TYPE_MONOTONIC)
934+
switch (runtime->tstamp_type) {
935+
case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC:
935936
ktime_get_ts(tv);
936-
else
937+
break;
938+
case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW:
939+
getrawmonotonic(tv);
940+
break;
941+
default:
937942
getnstimeofday(tv);
943+
break;
944+
}
938945
}
939946

940947
/*

‎include/uapi/sound/asound.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,8 @@ struct snd_xfern {
462462
enum {
463463
SNDRV_PCM_TSTAMP_TYPE_GETTIMEOFDAY = 0, /* gettimeofday equivalent */
464464
SNDRV_PCM_TSTAMP_TYPE_MONOTONIC, /* posix_clock_monotonic equivalent */
465-
SNDRV_PCM_TSTAMP_TYPE_LAST = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC,
465+
SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW, /* monotonic_raw (no NTP) */
466+
SNDRV_PCM_TSTAMP_TYPE_LAST = SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW,
466467
};
467468

468469
/* channel positions */

0 commit comments

Comments
 (0)