kernel: Add snd_pcm_start_at
RFC 1/1 kernel: Add snd_pcm_start_at
snd_pcm_start_at() - kernel-side
The headlines:
- Provide snd_pcm_start_at ioctl
- Add SND_PCM_TSTAMP_TYPE_AUDIO_WALLCLOCK
- Use the stream tstamp_type to interpret the start_at timespec
- snd_pcm_start_at_ops defines handler for a TSTAMP_TYPE
- handler requirements clearly defined
- If posix clock, use a high-res timer implementation (thx Nick Stoughton!)
- If audio wallclock, delegate to the pcm driver if possible, otherwise error
- Further implementations easily added
- Cancel pending timer on:
- Subsequent call to snd_pcm_start_at()
- Any /attempt/ to change the stream state
Major points for discussion:
- snd_pcm_start_at_ops requirements aren't clear enough
- callback must not do cleanup
- cancel is guaranteed to be called - do cleanup here
- snd_pcm_gettime() can't currently return a value when tstamp_type is AUDIO_WALLCLOCK
- start_at timer callbacks *should* probably lock the stream, contrary to Nick's note
- The user story for start_at cancellation from userspace is a bit weird...
- Cancellation on state-change seems necessary, but not sufficient
- Maybe add snd_pcm_start_at_cancel()?
Future thoughts:
- Perhaps snd_pcm_start_at should be a blocking call (EAGAIN when stream is non-blocking)
- Maybe tstamp_types and startat_types should be different things
I've become convinced that exposing the nature of the pcm clock is troublesome, and unnecessary,
and fell back to Takashi's suggestion of a DEVICE_SPECIFIC tstamp_type. I note thatAUDIO_WALLCLOCK seems to capture the concept of 'pcm time', so I've called it that.
Because I'm using SND_PCM_TSTAMP_TYPE_AUDIO_WALLCLOCK instead of SNDRV_PCM_TSTAMP_TYPE_PTP, there's no additional payload required for snd_pcm_sw_set_tstamp_type().
Comments and suggestions welcome :)
Tim
include/sound/pcm.h +9 -0
@@ -82,6 +82,8 @@ struct snd_pcm_ops { unsigned long offset);int (*mmap)(struct snd_pcm_substream *substream,struct vm_area_struct *vma);int (*ack)(struct snd_pcm_substream *substream); +int (*wall_clock_start_at)(struct snd_pcm_substream *substream,const struct timespec *ts); +int (*wall_clock_start_at_cancel)(struct snd_pcm_substream *substream); };/*
@@ -210,6 +212,8 @@ struct snd_pcm_ops {#define SNDRV_PCM_FMTBIT_IEC958_SUBFRAME SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE#endif +#define SNDRV_PCM_START_AT_TSTAMP_TYPE_NULL (SNDRV_PCM_TSTAMP_TYPE_LAST+1) +struct snd_pcm_file {struct snd_pcm_substream *substream;int no_compat_mmap;
@@ -364,6 +368,10 @@ struct snd_pcm_runtime {#ifdef CONFIG_SND_PCM_XRUN_DEBUG struct snd_pcm_hwptr_log *hwptr_log;#endif + +int start_at_tstamp_type;/* start_at timer tstamp_type Set to +SNDRV_PCM_START_AT_TSTAMP_TYPE_NULL if not active */ +void *start_at_timer_data;/* start_at timer data */ };struct snd_pcm_group {/* keep linked substreams */
@@ -1069,6 +1077,7 @@ static inline void snd_pcm_gettime(struct snd_pcm_runtime *runtime,case SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW :getrawmonotonic (tv);break ; +case SNDRV_PCM_TSTAMP_TYPE_AUDIO_WALLCLOCK :default :getnstimeofday (tv);break ;
include/uapi/sound/asound.h +4 -2
@@ -467,8 +467,9 @@ 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_MONOTONIC_RAW ,/* monotonic_raw (no NTP) */ -SNDRV_PCM_TSTAMP_TYPE_LAST =SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW , +SNDRV_PCM_TSTAMP_TYPE_MONOTONIC_RAW ,/* monotonic_raw (no NTP) */ +SNDRV_PCM_TSTAMP_TYPE_AUDIO_WALLCLOCK ,/* audio wallclock timestamp */ +SNDRV_PCM_TSTAMP_TYPE_LAST =SNDRV_PCM_TSTAMP_TYPE_AUDIO_WALLCLOCK , };/* channel positions */
@@ -549,6 +550,7 @@ enum {#define SNDRV_PCM_IOCTL_READN_FRAMES _IOR('A', 0x53, struct snd_xfern)#define SNDRV_PCM_IOCTL_LINK _IOW('A', 0x60, int)#define SNDRV_PCM_IOCTL_UNLINK _IO('A', 0x61) +#define SNDRV_PCM_IOCTL_START_AT _IOW('A', 0x62, struct timespec)/***************************************************************************** * *
sound/core/pcm.c +1 -0
@@ -1003,6 +1003,7 @@ int snd_pcm_attach_substream(struct snd_pcm *pcm, int stream,init_waitqueue_head (&runtime->tsleep); runtime->status->state =SNDRV_PCM_STATE_OPEN ; + runtime->start_at_tstamp_type =SNDRV_PCM_START_AT_TSTAMP_TYPE_NULL ; substream->runtime = runtime; substream->private_data = pcm->private_data;
sound/core/pcm_native.c +246 -0
288 lines not on this page · raw message
Signature · 1 line
1.9.1