ALSA: usb: update trigger timestamp on first non-zero URB submitted
authorPierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Fri, 6 Feb 2015 21:55:53 +0000 (15:55 -0600)
committerTakashi Iwai <tiwai@suse.de>
Mon, 9 Feb 2015 15:02:43 +0000 (16:02 +0100)
The first URBs are submitted during the prepare stage. When .trigger is
called, the ALSA core saves a trigger tstamp that doesn't correspond to
the actual time when the samples are submitted. The trigger_tstamp is
now updated when the first data are submitted to avoid any time offsets.

A usb-specific trigger_tstamp_pending_update flag is used for now,
at some point the flag would need to move to the ALSA core, USB
is not the only interface where silent block transfers are programmed
as part of the prepare stage, with actual data enabled when .trigger
is called.

Signed-off-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/usb/card.h
sound/usb/pcm.c

index 97acb906acc27041cebb340abaa9d69c36c34634..ef580b43f1e3b1e71dcc4ed0f6a16f11928e071e 100644 (file)
@@ -153,6 +153,8 @@ struct snd_usb_substream {
                int channel;
                int byte_idx;
        } dsd_dop;
+
+       bool trigger_tstamp_pending_update; /* trigger timestamp being updated from initial estimate */
 };
 
 struct snd_usb_stream {
index 0d8aba5fe1a839abdb60197edfdfc0023802bb65..b4ef410e5a982b31adc933153773b34f9ccbbc2b 100644 (file)
@@ -1464,6 +1464,14 @@ static void prepare_playback_urb(struct snd_usb_substream *subs,
        subs->last_frame_number = usb_get_current_frame_number(subs->dev);
        subs->last_frame_number &= 0xFF; /* keep 8 LSBs */
 
+       if (subs->trigger_tstamp_pending_update) {
+               /* this is the first actual URB submitted,
+                * update trigger timestamp to reflect actual start time
+                */
+               snd_pcm_gettime(runtime, &runtime->trigger_tstamp);
+               subs->trigger_tstamp_pending_update = false;
+       }
+
        spin_unlock_irqrestore(&subs->lock, flags);
        urb->transfer_buffer_length = bytes;
        if (period_elapsed)
@@ -1550,6 +1558,7 @@ static int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substrea
 
        switch (cmd) {
        case SNDRV_PCM_TRIGGER_START:
+               subs->trigger_tstamp_pending_update = true;
        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
                subs->data_endpoint->prepare_data_urb = prepare_playback_urb;
                subs->data_endpoint->retire_data_urb = retire_playback_urb;