From patchwork Thu Feb 16 13:59:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Young X-Patchwork-Id: 654095 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 583BAC64EC4 for ; Thu, 16 Feb 2023 14:00:34 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id CEFA7E93; Thu, 16 Feb 2023 14:59:41 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz CEFA7E93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1676556031; bh=0JztOxvWSCiaB+sFFIIzyvw66U2GE3J2wqP5jkNRols=; h=From:To:Subject:Date:CC:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=RaekixPospwfmkL9EbkN3pFY6dvad+RMvAQ9QZo7iPhr1x/3jwQFhTm3EsCkeLZkD dtpXcdZJuZpu6FfL5jVKFKfjqYdRNhdoRYzRQzdGAA8MKWgEJLobqQvymEBTFc9ppF M35F7cke1mFc8xIvELYVd7aXE2JTNkHYX1rgRw5I= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 7F154F801C0; Thu, 16 Feb 2023 14:59:41 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 4DA7DF801C0; Thu, 16 Feb 2023 14:59:38 +0100 (CET) Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 56FCBF800E3 for ; Thu, 16 Feb 2023 14:59:36 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 56FCBF800E3 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=Cu5h0JEW Received: by mail-wm1-x32c.google.com with SMTP id l21-20020a05600c1d1500b003dfe462b7e4so4288834wms.0 for ; Thu, 16 Feb 2023 05:59:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=wptKg8ei4rb26lOj2FWnUT5QGC63y861aTdm4Jmh/so=; b=Cu5h0JEWFNUZYLCe+OM65B9wh7Gso2ULkOBoxuVk4qlDwa00JTFoc2IaYja6zTwn7k z472ONmp4m4Y114GIbXhpGuJFF95ceTzoHDK2gBWUtC1ZWi6d2Y+6MUHFAZORfahZqlu mgpkngOE+bF+GOnMslJbv1AMCKBKiQttvCsePeLie4fcuVNQtYtXqNFqVy4p6tSRZLJk bYk1w9n1JmQOSQcjTCLkFNcCjLPD9fsw4KfZSAJCtmAXocHF6vaH45E/oxxTfgK/Ccib QIY4Z7aQm2YLu+f9ni+4F9xkiOZ+nwupu2Xa/USXMIxmhVpxTG+qfp9OwYdDPEiXN7mQ 5ZAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=wptKg8ei4rb26lOj2FWnUT5QGC63y861aTdm4Jmh/so=; b=e2g5pJZCptNlnDW6qvfN3cNDZWhxEeiI+Z3uxR4KdBz6NwCofUbyTi4qaEGiocgNHb JpWnBk3uU8ogbD2hBA/8rg8rYvn9EuwCi5iXkvwCSA4doZA2OYOXxrkOTNgfz+maLfiU QloAxMO+hiSMBtnT51E3hAiNTBzVq4jfdCg392jz2Fw3+/YLtFg+YhBCAyCzPj1IcqZL bM1hzfgbc7mXEdfI/QSaz18XpXwevgCDpy3Rybi39QYms5OIkibC6hDfPL2/HDKq4xct mt7m8pRUD5nWO/c8D2MbJ6HTBjxQQpWv+xer/wfg6mQ4V1bTb9369HTmKLRcOAFlUxj1 0bbA== X-Gm-Message-State: AO0yUKW29T0rBoQeJkUTmV4zdC5xnKKElgbrEXnDYTH5JuGRd7GQ7bOG eCNuLvWO5x+fXZ/QW4ez5TRGiQWS55c= X-Google-Smtp-Source: AK7set9O/bjqrUZfCZ2l+PbFTcf1WFfgVXhqc+t++r+35+bxqP5mugvgmtJAXhlxxHVO6Vl2Qioqqw== X-Received: by 2002:a05:600c:1c1c:b0:3e0:e77:3056 with SMTP id j28-20020a05600c1c1c00b003e00e773056mr5013586wms.30.1676555974582; Thu, 16 Feb 2023 05:59:34 -0800 (PST) Received: from localhost.localdomain (awyoung.plus.com. [81.174.138.22]) by smtp.gmail.com with ESMTPSA id n14-20020a05600c4f8e00b003dc4480df80sm6137498wmq.34.2023.02.16.05.59.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 05:59:34 -0800 (PST) From: Alan Young To: alsa-devel@alsa-project.org Subject: [PATCH 1/2] ALSA: pcm: generate default audio timestamp Date: Thu, 16 Feb 2023 13:59:28 +0000 Message-Id: <20230216135928.1974403-1-consult.awy@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Message-ID-Hash: 2PHSFBTLURCDKYWHQHICZEEHX7WAM3U3 X-Message-ID-Hash: 2PHSFBTLURCDKYWHQHICZEEHX7WAM3U3 X-MailFrom: consult.awy@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: pierre-louis.bossart@linux.intel.com, Alan Young X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: If there is no get_time_info() available or the requested audio timestamp type is AUDIO_TSTAMP_TYPE_DEFAULT then need to set audio_tstamp_report.actual_type = AUDIO_TSTAMP_TYPE_DEFAULT (in the else clause near the start of snd_pcm_update_hw_ptr0()) in order for update_audio_tstamp() to generate the audio timestamp from the number of frames. Fixes: 3179f6200188 ("ALSA: core: add .get_time_info") Signed-off-by: consult.awy@gmail.com --- sound/core/pcm_lib.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index 8b6aeb8a78f7..943f5396fc60 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -289,8 +289,10 @@ static int snd_pcm_update_hw_ptr0(struct snd_pcm_substream *substream, /* re-test in case tstamp type is not supported in hardware and was demoted to DEFAULT */ if (runtime->audio_tstamp_report.actual_type == SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT) snd_pcm_gettime(runtime, &curr_tstamp); - } else + } else { + runtime->audio_tstamp_report.actual_type = SNDRV_PCM_AUDIO_TSTAMP_TYPE_DEFAULT; snd_pcm_gettime(runtime, &curr_tstamp); + } } if (pos == SNDRV_PCM_POS_XRUN) { From patchwork Thu Feb 16 13:58:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Young X-Patchwork-Id: 654470 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3A985C636CC for ; Thu, 16 Feb 2023 13:59:48 +0000 (UTC) Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 69C64EA0; Thu, 16 Feb 2023 14:58:55 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 69C64EA0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1676555985; bh=44H9/Duy6AWAhUV1DCUB5QmPBxaaOwrv0NaQQAJEQd8=; h=From:To:Subject:Date:CC:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=VYVt2DLydE0qbA9wy6qqiRJx9Aeowu95mMfWBtTFx6dFpmrm0Meql0c136UolBfXR C1BERn+D7Ubn9kkrli+lFzP+Tdsq274drGUhM9W01CbAzBuXmPXcyOXNXuQTI7FreC fN3eh6L/r/RlwiP+uV6hQAdWxmQo3AXkR5m5ACmo= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 1668FF80171; Thu, 16 Feb 2023 14:58:31 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 4C8E1F80171; Thu, 16 Feb 2023 14:58:28 +0100 (CET) Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 4316AF80083 for ; Thu, 16 Feb 2023 14:58:25 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 4316AF80083 Authentication-Results: alsa1.perex.cz; dkim=pass (2048-bit key, unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=dFBid76Q Received: by mail-wr1-x434.google.com with SMTP id m14so1895524wrg.13 for ; Thu, 16 Feb 2023 05:58:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Zrh5pA5EZwJvRJHIXwlRKWCv9rTSdcO4kjwh/+0PhoI=; b=dFBid76QJ3Riay/IcehoB3Pwl4Yrb/cZPs8n6Ks+il6qEogRIocW+lXLWkUCJe7YHZ RT1ztTI1J//5K17e8gpX9NeHGlLa9HXCbPvzhcJVmkw0E4RtAhmZe8mv4nLObD+AmC3P n2clN5rreMu4Kq8b/9b6Q5n0KF5MM70IPGu4dZ9UVhDUYk0xH4A2QiclJi8hFhEZ7yFA FbvHfN4vmF9+wta7rP1rdvrUAqxOa8rSsexqJhV23DqrKRcZa8mtkzwzFolgrW2Qd/B8 dauePjdE4SqW3kDk8hKrGwVd6TVRVi3/uh+g6osxMG2KYYtURT4XE+SHyzcpAqaGU3lx tuUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Zrh5pA5EZwJvRJHIXwlRKWCv9rTSdcO4kjwh/+0PhoI=; b=CJpmR9OpzGc7jfs4UkHGnQ2HZquC1zRUQYpGfwYoV7ee0cOiJyEc5jNRC6BBk+8DzH R8dTIf4U4Iapdyy5baSX8xK6vwHDij76MdKyuI9Lx24NzVemM4Nr7aZsyvKLDdz3b2lV j4lZLXVhPp8NJp44ZGA+K9qslYJbrQ/YB/TIk1gZN39QuAr4Mht6+hyDGYEBn8pqGQ2O qe1Fh5PpxpWkdoY8aUn17DY7RnnCFWnsE94Qmia0+gUygjK47qi6nux8ETD/GhkwYS0L tCzlg8xEYvdDP7xrCL+xn4JSQJWZB93tnYnRSu7wFNTvAAVLFK41tc+6AbZJxGR6Y9+R s9rA== X-Gm-Message-State: AO0yUKVN1ioEs8dEy5NLwQL6lNuyRd6M3Z3wCPVM5hErrfMOuXFuusuY Ow5CkQI7dN/u8wxuEsyh8DZYyXDYORs= X-Google-Smtp-Source: AK7set9KxxH3avslLG43xYYX0iZm6rfbuR3a8etKh/7C1nveKoIhhtF0LtnE6Ib0KF0WB+XKDnp11A== X-Received: by 2002:adf:e851:0:b0:2c3:ea92:3494 with SMTP id d17-20020adfe851000000b002c3ea923494mr4630161wrn.55.1676555904111; Thu, 16 Feb 2023 05:58:24 -0800 (PST) Received: from localhost.localdomain (awyoung.plus.com. [81.174.138.22]) by smtp.gmail.com with ESMTPSA id d8-20020adfe2c8000000b002c3ea5ebc73sm1569060wrj.101.2023.02.16.05.58.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 05:58:22 -0800 (PST) From: Alan Young To: alsa-devel@alsa-project.org Subject: [PATCH 2/2] ALSA: Change calculation of audio time from frames Date: Thu, 16 Feb 2023 13:58:06 +0000 Message-Id: <20230216135806.1973959-1-consult.awy@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Message-ID-Hash: HNW6KVT66KOJLFDOJZREOCWNAF3MQNXT X-Message-ID-Hash: HNW6KVT66KOJLFDOJZREOCWNAF3MQNXT X-MailFrom: consult.awy@gmail.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-alsa-devel.alsa-project.org-0; header-match-alsa-devel.alsa-project.org-1; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: pierre-louis.bossart@linux.intel.com, Alan Young X-Mailman-Version: 3.3.8 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Introduce snd_pcm_lib_frames_to_timespec64() to replace the calculation audio_nsecs = div_u64(audio_frames * 1000000000LL, runtime->rate); which overflows after a playback duration of 4.8 days @ 44100 HZ or 0.56 days @ 384000 Hz. The implementation of snd_pcm_lib_frames_to_timespec64() extends these limits, to 1.5 million years (@ 384000 Hz), or the 68 year limit of struct timespec on 32-bit systems. Fixes: 3179f6200188 ("ALSA: core: add .get_time_info") Fixes: 4eeaaeaea1ce ("ALSA: core: add hooks for audio timestamps") Signed-off-by: consult.awy@gmail.com --- sound/core/pcm_lib.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c index 943f5396fc60..e0a6556d33ee 100644 --- a/sound/core/pcm_lib.c +++ b/sound/core/pcm_lib.c @@ -205,12 +205,19 @@ int snd_pcm_update_state(struct snd_pcm_substream *substream, return 0; } +static inline void snd_pcm_lib_frames_to_timespec64(u64 frames, unsigned int rate, struct timespec64 *audio_tstamp) +{ + u32 remainder; + audio_tstamp->tv_sec = div_u64_rem(frames, rate, &remainder); + audio_tstamp->tv_nsec = div_u64(mul_u32_u32(remainder, NSEC_PER_SEC), rate); +} + static void update_audio_tstamp(struct snd_pcm_substream *substream, struct timespec64 *curr_tstamp, struct timespec64 *audio_tstamp) { struct snd_pcm_runtime *runtime = substream->runtime; - u64 audio_frames, audio_nsecs; + u64 audio_frames; struct timespec64 driver_tstamp; if (runtime->tstamp_mode != SNDRV_PCM_TSTAMP_ENABLE) @@ -233,9 +240,7 @@ static void update_audio_tstamp(struct snd_pcm_substream *substream, else audio_frames += runtime->delay; } - audio_nsecs = div_u64(audio_frames * 1000000000LL, - runtime->rate); - *audio_tstamp = ns_to_timespec64(audio_nsecs); + snd_pcm_lib_frames_to_timespec64(audio_frames, runtime->rate, audio_tstamp); } if (runtime->status->audio_tstamp.tv_sec != audio_tstamp->tv_sec ||