diff options
author | Dylan Reid <dgreid@chromium.org> | 2013-04-08 21:20:30 -0400 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2013-04-09 02:03:22 -0400 |
commit | 78daea29f2e5312bce9d7781a5400026b71ed29b (patch) | |
tree | 5fd4b8ec656f4cb5cdc2d4360cb08a1351badef5 | |
parent | 423970042e0710cdb4f7135f1ed614b956239a91 (diff) |
ALSA: hda - Apply codec delay to wallclock.
For playback add the codec-side delay to the timestamp, for capture
subtract it. This brings the timestamps in line with the time that
was recently added to the delay reporting.
Signed-off-by: Dylan Reid <dgreid@chromium.org>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r-- | sound/pci/hda/hda_intel.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c index 735567e86f74..3e6f2c6dc53f 100644 --- a/sound/pci/hda/hda_intel.c +++ b/sound/pci/hda/hda_intel.c | |||
@@ -1889,6 +1889,23 @@ static void azx_timecounter_init(struct snd_pcm_substream *substream, | |||
1889 | tc->cycle_last = last; | 1889 | tc->cycle_last = last; |
1890 | } | 1890 | } |
1891 | 1891 | ||
1892 | static u64 azx_subtract_codec_delay(struct snd_pcm_substream *substream, | ||
1893 | u64 nsec) | ||
1894 | { | ||
1895 | struct azx_pcm *apcm = snd_pcm_substream_chip(substream); | ||
1896 | struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; | ||
1897 | u64 codec_frames, codec_nsecs; | ||
1898 | |||
1899 | if (!hinfo->ops.get_delay) | ||
1900 | return nsec; | ||
1901 | |||
1902 | codec_frames = hinfo->ops.get_delay(hinfo, apcm->codec, substream); | ||
1903 | codec_nsecs = div_u64(codec_frames * 1000000000LL, | ||
1904 | substream->runtime->rate); | ||
1905 | |||
1906 | return (nsec > codec_nsecs) ? nsec - codec_nsecs : 0; | ||
1907 | } | ||
1908 | |||
1892 | static int azx_get_wallclock_tstamp(struct snd_pcm_substream *substream, | 1909 | static int azx_get_wallclock_tstamp(struct snd_pcm_substream *substream, |
1893 | struct timespec *ts) | 1910 | struct timespec *ts) |
1894 | { | 1911 | { |
@@ -1897,6 +1914,7 @@ static int azx_get_wallclock_tstamp(struct snd_pcm_substream *substream, | |||
1897 | 1914 | ||
1898 | nsec = timecounter_read(&azx_dev->azx_tc); | 1915 | nsec = timecounter_read(&azx_dev->azx_tc); |
1899 | nsec = div_u64(nsec, 3); /* can be optimized */ | 1916 | nsec = div_u64(nsec, 3); /* can be optimized */ |
1917 | nsec = azx_subtract_codec_delay(substream, nsec); | ||
1900 | 1918 | ||
1901 | *ts = ns_to_timespec(nsec); | 1919 | *ts = ns_to_timespec(nsec); |
1902 | 1920 | ||