[alsa-devel] [PATCH v3 2/3] ALSA: core: add hooks for audio timestamps
Takashi Iwai
tiwai at suse.de
Mon Oct 15 14:20:09 CEST 2012
At Fri, 12 Oct 2012 12:05:36 -0500,
Pierre-Louis Bossart wrote:
>
> ALSA did not provide any direct means to infer the audio time for A/V
> sync and system/audio time correlations (eg. PulseAudio).
> Applications had to track the number of samples read/written and
> add/subtract the number of samples queued in the ring buffer. This
> accounting led to small errors, typically several samples, due to the
> two-step process. Computing the audio time in the kernel is more
> direct, as all the information is available in the same routines.
>
> Also add new .audio_wallclock routine to enable fine-grain synchronization
> between monotonic system time and audio hardware time.
> Using the wallclock, if supported in hardware, allows for a
> much better sub-microsecond precision and a common drift tracking for
> all devices sharing the same wall clock (master clock).
>
> Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart at linux.intel.com>
> ---
> include/sound/asound.h | 7 +++++--
> include/sound/pcm.h | 2 ++
> sound/core/pcm_compat.c | 19 +++++++++++--------
> sound/core/pcm_lib.c | 32 ++++++++++++++++++++++++++++++--
> sound/core/pcm_native.c | 2 ++
> 5 files changed, 50 insertions(+), 12 deletions(-)
>
> diff --git a/include/sound/asound.h b/include/sound/asound.h
> index 0876a1e..2d1ba63 100644
> --- a/include/sound/asound.h
> +++ b/include/sound/asound.h
> @@ -152,7 +152,7 @@ struct snd_hwdep_dsp_image {
> * *
> *****************************************************************************/
>
> -#define SNDRV_PCM_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 10)
> +#define SNDRV_PCM_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 11)
>
> typedef unsigned long snd_pcm_uframes_t;
> typedef signed long snd_pcm_sframes_t;
> @@ -274,6 +274,7 @@ typedef int __bitwise snd_pcm_subformat_t;
> #define SNDRV_PCM_INFO_JOINT_DUPLEX 0x00200000 /* playback and capture stream are somewhat correlated */
> #define SNDRV_PCM_INFO_SYNC_START 0x00400000 /* pcm support some kind of sync go */
> #define SNDRV_PCM_INFO_NO_PERIOD_WAKEUP 0x00800000 /* period wakeup can be disabled */
> +#define SNDRV_PCM_INFO_HAS_WALL_CLOCK 0x01000000 /* has audio wall clock for audio/system time sync */
> #define SNDRV_PCM_INFO_FIFO_IN_FRAMES 0x80000000 /* internal kernel flag - FIFO size is in frames */
>
> typedef int __bitwise snd_pcm_state_t;
> @@ -422,7 +423,8 @@ struct snd_pcm_status {
> snd_pcm_uframes_t avail_max; /* max frames available on hw since last status */
> snd_pcm_uframes_t overrange; /* count of ADC (capture) overrange detections from last status */
> snd_pcm_state_t suspended_state; /* suspended stream state */
> - unsigned char reserved[60]; /* must be filled with zero */
> + struct timespec audio_tstamp; /* from sample counter or wall clock */
> + unsigned char reserved[60-sizeof(struct timespec)]; /* must be filled with zero */
> };
>
> struct snd_pcm_mmap_status {
> @@ -431,6 +433,7 @@ struct snd_pcm_mmap_status {
> snd_pcm_uframes_t hw_ptr; /* RO: hw ptr (0...boundary-1) */
> struct timespec tstamp; /* Timestamp */
> snd_pcm_state_t suspended_state; /* RO: suspended stream state */
> + struct timespec audio_tstamp; /* from sample counter or wall clock */
> };
>
> struct snd_pcm_mmap_control {
> diff --git a/include/sound/pcm.h b/include/sound/pcm.h
> index ba13e0b..e2f1d48 100644
> --- a/include/sound/pcm.h
> +++ b/include/sound/pcm.h
> @@ -71,6 +71,8 @@ struct snd_pcm_ops {
> int (*prepare)(struct snd_pcm_substream *substream);
> int (*trigger)(struct snd_pcm_substream *substream, int cmd);
> snd_pcm_uframes_t (*pointer)(struct snd_pcm_substream *substream);
> + int (*wall_clock)(struct snd_pcm_substream *substream,
> + struct timespec *audio_ts);
> int (*copy)(struct snd_pcm_substream *substream, int channel,
> snd_pcm_uframes_t pos,
> void __user *buf, snd_pcm_uframes_t count);
> diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
> index 91cdf94..3648ae3 100644
> --- a/sound/core/pcm_compat.c
> +++ b/sound/core/pcm_compat.c
> @@ -190,7 +190,8 @@ struct snd_pcm_status32 {
> u32 avail_max;
> u32 overrange;
> s32 suspended_state;
> - unsigned char reserved[60];
> + struct compat_timespec audio_tstamp;
> + unsigned char reserved[60-sizeof(struct timespec)];
This must be sizeof(struct compat_timespec).
Takashi
More information about the Alsa-devel
mailing list