From patchwork Thu Mar 23 11:40:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: sutar.mounesh@gmail.com X-Patchwork-Id: 9640895 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id F27C8602D6 for ; Thu, 23 Mar 2017 11:41:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DD76B26E81 for ; Thu, 23 Mar 2017 11:41:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D0A0728495; Thu, 23 Mar 2017 11:41:07 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_SPAM, T_DKIM_INVALID,WEIRD_QUOTING autolearn=no version=3.3.1 Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF3D226E81 for ; Thu, 23 Mar 2017 11:41:05 +0000 (UTC) Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id CC3D8266871; Thu, 23 Mar 2017 12:41:03 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 613F5266871; Thu, 23 Mar 2017 12:41:01 +0100 (CET) Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by alsa0.perex.cz (Postfix) with ESMTP id E5EFB26684C; Thu, 23 Mar 2017 12:40:54 +0100 (CET) Received: by mail-wr0-f193.google.com with SMTP id l37so30696985wrc.3; Thu, 23 Mar 2017 04:40:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=6RGpH539OMwNkxyyADRnUWuHs0fWzocr02QSPmvJLr0=; b=Kik/2RDiS2/KYKpDzAXxYeXZgLhkkVcFXOCW3X3GlX7MfKnn7Gcv7qOoIs1tzLH3IL ocHRvx5RnQ+Ev+S46MHHgHLgpZZryVZ7GFuPx8daCIiDPHb59OVGnjWysubZDc0ifFcM PAzO3oUaQqXlScAzSa1tVFL0Izdt8YJJ3iubYnPdFSlm2l7a9ouj+IMLgerIk02E0DGj acW/AS5eDGAy7bF+Bwfm5uTUZkYloN5GPoNHk9DOk0bIENq6uOrQ7vLkxJ4En7/0ObgW IMEy7Wk4cbgFLp+qJnWNONqS6zqp02eF6Luiv+Bq4UvppQ4UD3iol5LD/euI91R8LTsG kBHg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=6RGpH539OMwNkxyyADRnUWuHs0fWzocr02QSPmvJLr0=; b=dWvRLLZbWWZfOzKY4AvaDJ/CY3kPxlJtSESJ07K4EfBWfjdE60JUOtxNMA9FwtwCOw NTMey8R+is7DyofqhQAfl43K9mw+Z0MHVO0Uc8/Y8Av8DoJcNv1ERvUC3tYRxhHcFBs1 TCTjcbT6Sh752Fft5G30q5burUP+qEn6FQ470HZ5Hez3p8UsB/XNovQC7pSion8mXkM6 S8Js80nG3yHbr1e9uvNip6QeIBkJ60QLkMR1AflrPhl7QG1q9QG9S6JhXiMBtt+ahrK/ zQpzjwKA6e0X8FIErGmWU7Seokq8mNpz662MqznyQ4i4SzTqpincXvxSGV0S/FdmwxZ6 difg== X-Gm-Message-State: AFeK/H39s+OV34CvK4vdh1kKTxecifFi6QTRvhT0Z4hMLKssEERYU6HqoitPFv6Y4sczBw== X-Received: by 10.223.183.46 with SMTP id l46mr2154549wre.89.1490269254003; Thu, 23 Mar 2017 04:40:54 -0700 (PDT) Received: from msutar-VirtualBox.inp.mentorg.com ([139.181.35.34]) by smtp.gmail.com with ESMTPSA id f48sm5490513wrf.17.2017.03.23.04.40.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 23 Mar 2017 04:40:53 -0700 (PDT) From: sutar.mounesh@gmail.com To: patch@alsa-project.org Date: Thu, 23 Mar 2017 17:10:45 +0530 Message-Id: <1490269245-16858-1-git-send-email-sutar.mounesh@gmail.com> X-Mailer: git-send-email 2.7.4 Cc: Mounesh Sutar , alsa-devel@alsa-project.org, Andreas Pape , mounesh_sutar@mentor.com Subject: [alsa-devel] [PATCH 1/1] pcm:file: delegate htimestamping to slave instead of always getting real_htimestamp X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP From: Andreas Pape purpose of this fix, is to read most accurate timestamps. From documentation of /src/pcm/pcm.c, we can see: """" \par Timestamp mode The timestamp mode specifies, if timestamps are activated. Currently, only #SND_PCM_TSTAMP_NONE and #SND_PCM_TSTAMP_MMAP modes are known. The mmap mode means that timestamp is taken on every period time boundary. Corresponding position in the ring buffer assigned to timestamp can be obtained using #snd_pcm_htimestamp() function. """" As snd_pcm_generic_htimestamp() internally calls snd_pcm_htimestamp() to read time, so accurate timestamp can be read from snd_pcm_generic_htimestamp(). Also, in case of pcm_file, if the underlying slave is hardware, then we would wish to read elapsed hardware time, as it will be the most accurate, as opposed to the elapsed wall time. This will provide pcm_file with the most accurate timestamps. Following are the timesamps read with timestamp enabled, for with fix and without fix scenarios: 1> With fix: :~#time aplay --enable-tstamp -Dhtstamp_test --period-time=5000 -v -fdat /dev/urandom Playing raw data '/dev/urandom' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo File PCM (file=/tmp/swarate_out.wav) Final file PCM (file=/tmp/swarate_out.wav) .. Slave: Hardware PCM card 0 'imx6q-sabresd-wm8962' device 0 subdevice 0 Its setup is: stream : PLAYBACK access : RW_INTERLEAVED format : S16_LE subformat : STD channels : 2 rate : 48000 exact rate : 48000 (48000/1) msbits : 16 buffer_size : 24000 period_size : 240 period_time : 5000 tstamp_mode : ENABLE . . Before sleep = 142:409.807623 After sleep = 142:409.807623 Before sleep = 142:414.806016 (calling snd_pcm_htimestamp(handle, &avail, &tstamp_before)) sleep of 2 milisec After sleep = 142:414.806016 (calling snd_pcm_htimestamp(handle, &avail, &tstamp_after) From the above timestamps, we can see that slave has returned the same timestamps, as --period-time choosen is 5msec. 2> Without this fix: The timestamps are returned with realtime value. :~# time aplay --enable-tstamp -Dhtstamp_test --period-time=5000 -v -fdat /dev/urandom Playing raw data '/dev/urandom' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo File PCM (file=/tmp/swarate_out.wav) Final file PCM (file=/tmp/swarate_out.wav) . . Slave: Hardware PCM card 0 'imx6q-sabresd-wm8962' device 0 subdevice 0 Its setup is: stream : PLAYBACK access : RW_INTERLEAVED format : S16_LE subformat : STD channels : 2 rate : 48000 exact rate : 48000 (48000/1) msbits : 16 buffer_size : 24000 period_size : 240 period_time : 5000 tstamp_mode : ENABLE . . Before sleep = 241:136.875845 (calling snd_pcm_htimestamp(handle, &avail, &tstamp_before)) sleep of 2 milisec After sleep = 241:139.076376 (calling snd_pcm_htimestamp(handle, &avail, &tstamp_after) We can observe here, the timestamps shows time diff of ~2ms, which is the time gap of sleep duration. Before sleep = 241:139.617588 After sleep = 241:141.746845 Before sleep = 241:142.291618 After sleep = 241:144.406406 Before sleep = 241:144.951421 After sleep = 241:147.066118 Before sleep = 241:147.623421 After sleep = 241:149.740573 Signed-off-by: Andreas Pape Signed-off-by: Mounesh Sutar diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c index 8012251..fe36a1c 100644 --- a/src/pcm/pcm_file.c +++ b/src/pcm/pcm_file.c @@ -728,7 +728,7 @@ static const snd_pcm_fast_ops_t snd_pcm_file_fast_ops = { .poll_descriptors_count = snd_pcm_generic_poll_descriptors_count, .poll_descriptors = snd_pcm_generic_poll_descriptors, .poll_revents = snd_pcm_generic_poll_revents, - .htimestamp = snd_pcm_generic_real_htimestamp, + .htimestamp = snd_pcm_generic_htimestamp, }; /**