pcm: support for audio timestamps

add new snd_pcm_status_get_audio_htstamp() routine to
query the audio timestamps provided by the kernel.

This change provides applications with better ways
to track elapsed time. Before this patch, applications
would subtract queued samples (delay) from written samples,
resulting in a 1-2 sample error.

Also add snd_pcm_hw_params_supports_audio_wallclock_ts()
to query what the hardware supports.

TODO: check protocol compatibility?

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Pierre-Louis Bossart 2012-06-12 14:36:40 -05:00 committed by Takashi Iwai
parent 4bdb09126a
commit cf40ea169a
4 changed files with 96 additions and 12 deletions

View file

@ -3123,6 +3123,26 @@ int snd_pcm_hw_params_can_disable_period_wakeup(const snd_pcm_hw_params_t *param
return !!(params->info & SNDRV_PCM_INFO_NO_PERIOD_WAKEUP);
}
/**
* \brief Check if hardware supports audio wallclock timestamps
* \param params Configuration space
* \retval 0 Hardware doesn't support audio wallclock timestamps
* \retval 1 Hardware supports audio wallclock timestamps
*
* This function should only be called when the configuration space
* contains a single configuration. Call #snd_pcm_hw_params to choose
* a single configuration from the configuration space.
*/
int snd_pcm_hw_params_supports_audio_wallclock_ts(const snd_pcm_hw_params_t *params)
{
assert(params);
if (CHECK_SANITY(params->info == ~0U)) {
SNDMSG("invalid PCM info field");
return 0; /* FIXME: should be a negative error? */
}
return !!(params->info & SNDRV_PCM_INFO_HAS_WALL_CLOCK);
}
/**
* \brief Get rate exact info from a configuration space
* \param params Configuration space
@ -6214,6 +6234,17 @@ void snd_pcm_status_get_htstamp(const snd_pcm_status_t *obj, snd_htimestamp_t *p
use_default_symbol_version(__snd_pcm_status_get_htstamp, snd_pcm_status_get_htstamp, ALSA_0.9.0rc8);
/**
* \brief Get "now" hi-res audio timestamp from a PCM status container
* \param obj pointer to #snd_pcm_status_t
* \param ptr Pointer to returned timestamp
*/
void snd_pcm_status_get_audio_htstamp(const snd_pcm_status_t *obj, snd_htimestamp_t *ptr)
{
assert(obj && ptr);
*ptr = obj->audio_tstamp;
}
/**
* \brief Get delay from a PCM status container (see #snd_pcm_delay)
* \return Delay in frames
*