From: Takashi Iwai Subject: Re: [PATCH v2] ALSA: core: update tstamp only if audio_tstamp changed Date: Tue, 21 Nov 2017 13:59:41 +0100 Message-ID: References: <20171121082921.GA25386@lnxhenriken2.se.axis.com> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by alsa0.perex.cz (Postfix) with ESMTP id B7AE6266F52 for ; Tue, 21 Nov 2017 13:59:43 +0100 (CET) In-Reply-To: <20171121082921.GA25386@lnxhenriken2.se.axis.com> List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org To: Henrik Eriksson Cc: alsa-devel@alsa-project.org List-Id: alsa-devel@alsa-project.org On Tue, 21 Nov 2017 09:29:28 +0100, Henrik Eriksson wrote: > > commit 3179f6200188 ("ALSA: core: add .get_time_info") had a side effect > of changing the behaviour of the PCM runtime tstamp. Prior to this > change tstamp was not updated by snd_pcm_update_hw_ptr0() unless the > hw_ptr had moved, after this change tstamp was always updated. > > For an application using alsa-lib, doing snd_pcm_readi() followed by > snd_pcm_status() to estimate the age of the read samples by subtracting > status->avail * [sample rate] from status->tstamp this change degraded > the accuracy of the estimate on devices where the pcm hw does not > provide a granular hw_ptr, e.g., devices using > soc-generic-dmaengine-pcm.c and a dma-engine with residue_granularity > DMA_RESIDUE_GRANULARITY_DESCRIPTOR. The accuracy of the estimate > depended on the latency between the PCM hw completing a period and the > driver called snd_pcm_period_elapsed() to notify ALSA core, typically > determined by interrupt handling latency. After the change the accuracy > of the estimate depended on the latency between the PCM hw completing a > period and the application calling snd_pcm_status(), determined by the > scheduling of the application process. The maximum error of the > estimate is one period length in both cases, but the error average and > variance is smaller when it depends on interrupt latency. > > Instead of always updating tstamp, update it only if audio_tstamp > changed. > > Fixes: 3179f6200188 ("ALSA: core: add .get_time_info") > Suggested-by: Pierre-Louis Bossart > Signed-off-by: Henrik Eriksson > --- > Changes since v1: > - Use Pierre-Louis Bossart's suggested fix > - Clean up commit log Applied, thanks. Takashi