From patchwork Thu Feb 16 14:28:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Young X-Patchwork-Id: 13143275 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 D7294C636CC for ; Thu, 16 Feb 2023 14:29:53 +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 3EB5AEB0; Thu, 16 Feb 2023 15:29:01 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 3EB5AEB0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1676557791; bh=VIGNX+nJcCFPEeWabI5oHob/hcgsvWcaskG8e9nhRww=; h=From:To:Subject:Date:CC:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=gRvrfdHq4zVetKSRMyoz6SK4r566m3lukB72UFW58qNiPcnHMWNZRIYyiuV3+fwBW URN4OnpV01I0+t+FR+uxtLRcAbtkQ75VXu1YOnsIiX7BxWjVGabuEDkSpzvJ39fBTi TEIC/DESHVxzQriKsPMMHVsbJUtCdjXdOjSJsZgk= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id E64ADF801C0; Thu, 16 Feb 2023 15:29:00 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id D9F47F80496; Thu, 16 Feb 2023 15:28:56 +0100 (CET) Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) (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 B622DF800B6 for ; Thu, 16 Feb 2023 15:28:53 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz B622DF800B6 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=Kh/nCKeu Received: by mail-wm1-x329.google.com with SMTP id p5so1694301wmg.4 for ; Thu, 16 Feb 2023 06:28:53 -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=rNK4VnHvNCmP8XNvu7i14YGbIOfy1cUxhBAjEemW9tw=; b=Kh/nCKeu3jPS1d16sHhwKPrki0sxEDOQsmPYGznYiV+osvzll3h01HxEO9Efctrtgb sJaWKAgvHJze8LLpT0Tk4XCOcETwbgAjvNYklm6e4H3rtDggkXiQP+c0mBbiD7h1LM54 gSn0rWlOQMkfcjYmWjpA23VX2m/cTtkussYgXCU+dAVyLBTyFD4AFhvRko24eg0YGU+g k00hcF97XtLXRqMR1UHLSmhzL3DsANS7PGU8ZJDboL1wBVQnkib4NPrkiQpx+awv2dAr 1c74yRORghWDv54TOndHkA5TCSQGuX4Q0D+FxpTThojeqARhb9DaCz9bsDcFHF9/czfB cOHg== 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=rNK4VnHvNCmP8XNvu7i14YGbIOfy1cUxhBAjEemW9tw=; b=Y+S9G6NI7j2euhvQni3NSvvkhJI40HNzu89rXrRzKdKoVuj9M53jdhRIf7hNY0O/au RXLXPo7On/g4YUm5/YneFKRQ/9jrcr7VqvA7OLg71bH8tDTnlchohymhLeUtU8t+dAUi 12ZjuRFWVSg6Gne82AwOxBrMz2ZhqdkAhFBwKMfuBSXmtfzoA2hgKI4yIw0LfAreNOVn g3CxGp/KM5PTXYhTDF3u3TtLp8XKDQnFaFGsqeURDEDHp9wshmreUKPA6718Vktwm+62 THka6bANIrw7q2GGUrjB8cBh7TyxIqju8k1YTkntIAEXzW05XChRrVzPfGEoEl/TUCUa /Agg== X-Gm-Message-State: AO0yUKXc7QV8BbLbCzwFHzCdw/PivzzSpNYkBlUHwc+55KDjxls/k64L 8GSgWcZjvRlnGSX93yTrrjNMd8zZXeg= X-Google-Smtp-Source: AK7set9PXoHvU/hPA35RL84BO65vAFb9t3q71WQmzMI4/WaVibvFWY9lopGs1Db8qGYEsdgr9qABPg== X-Received: by 2002:a05:600c:43d3:b0:3db:2df0:f2b8 with SMTP id f19-20020a05600c43d300b003db2df0f2b8mr5466011wmn.36.1676557731832; Thu, 16 Feb 2023 06:28:51 -0800 (PST) Received: from localhost.localdomain (awyoung.plus.com. [81.174.138.22]) by smtp.gmail.com with ESMTPSA id t14-20020a05600c198e00b003db0ee277b2sm5709726wmq.5.2023.02.16.06.28.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 06:28:51 -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 14:28:46 +0000 Message-Id: <20230216142846.1984099-1-consult.awy@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Message-ID-Hash: IHQ52WLM6U5E46TE7C2I3Q2DTHZAZADJ X-Message-ID-Hash: IHQ52WLM6U5E46TE7C2I3Q2DTHZAZADJ 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 Reviewed-by: Jaroslav Kysela --- 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 14:27:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Young X-Patchwork-Id: 13143259 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 99BF6C636CC for ; Thu, 16 Feb 2023 14:29:24 +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 0FB9FEAA; Thu, 16 Feb 2023 15:28:32 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 0FB9FEAA DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1676557762; bh=WgNKs+LLAn7qr7DMApk5ikuqamjmUzpT9q0b9SZ6GOg=; h=From:To:Subject:Date:CC:List-Id:List-Archive:List-Help:List-Owner: List-Post:List-Subscribe:List-Unsubscribe:From; b=hjCRebErojHJUNwEpVU3h+2ZqiG16dLQJIL21QmDNyKailaURioSbEVLYJfiB7ItA RrZVVeIaY0uZMywNhoXBJ+s94yFwOFXiz6TveNiotlvp5Vlxaf0+afZjEhIkEvlwXP /saJWYtUI7a46pFMnx8KQSTDWFElRwyIkv8ZO8uI= Received: from mailman-core.alsa-project.org (mailman-core.alsa-project.org [10.254.200.10]) by alsa1.perex.cz (Postfix) with ESMTP id 6E12AF80171; Thu, 16 Feb 2023 15:28:08 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 12D7CF801C0; Thu, 16 Feb 2023 15:28:04 +0100 (CET) Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) (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 3D947F80083 for ; Thu, 16 Feb 2023 15:27:58 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 3D947F80083 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=WuHX8LyR Received: by mail-wm1-x331.google.com with SMTP id l21-20020a05600c1d1500b003dfe462b7e4so4328223wms.0 for ; Thu, 16 Feb 2023 06:27:58 -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=P1Nz32PTC4cYcrHhpCvR0yjGez/KUmnS43OBx6qcE3Q=; b=WuHX8LyR3sDtCJ2pSEUglFfcrjqVHW9F9iLbRjbRb4Yog6hfv2hrWCig9GocgB2bP2 6Ic/kOugH4WCgef5LTmI1IJ/OtLjZCPnL0yQYQjd03yI1PXUuFXh6aDpRYvRkqjxIYXC 07/dVGj0i73WPZtvUQc4C+B4+M2XxcNhXx+p6hjzpylrRpIpzwOAslaheshDFTyB2h8K gk7ieOvwXKrSG2yui+sQi/qLviEZPs6iaNehfR9QOXAztkcQQ2rKA6hhnKTuFdno6A2T RaqoCNfgGUTX0l/lwi7/O2dZKrO083rzCzYqgLGjidV8ylGesl899JsUQ+QkimX4IQFe pNrA== 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=P1Nz32PTC4cYcrHhpCvR0yjGez/KUmnS43OBx6qcE3Q=; b=bX16fqiMaFsbiYhcZVfNzCQibCHHgmossdG1SHpWgAzTs7vaMRBSqnJMJb1xB1ihAA bJCRW1uhtxO6QB9YWg0gzm1+LhR0laNx++uGwWOYh3d8NRV5ZIFDKCWyEYbq6ENerJBO yk5p2MOz9yHmEbMPOIZI4uDbFcnSQcWnkiTEfYTS71rrjj6GKmJKQ83OcvCQQCIzjPYS kmB80kYDBaiqiPcjATeSK+eEI6/Z5uYw3yxs3abiPjRX/hahLYSeqMCEJdhcy6OJHeax qjpEzZ41CvWnrwTdkLr4QpwU8ikdLQlFHo30FzF8/em6ofibDawfIpVyfvcVK2dPJ5Zy O7pA== X-Gm-Message-State: AO0yUKWVQYavDzeKa0JoQx1RIB/DvHjrZd9NHROlxrQbuRRd0K2fmXLL Q+DiRO8sO2/uU1q4LINgsSCXal3/EjA= X-Google-Smtp-Source: AK7set+eAWWSNaTr3G+0Lhk6WHJd7J76wUSKMOUYpAbJoHJfNgnOuubr0kQiZUHSnoaLrw+Lx5b8ww== X-Received: by 2002:a05:600c:996:b0:3cf:68d3:3047 with SMTP id w22-20020a05600c099600b003cf68d33047mr4588800wmp.41.1676557677103; Thu, 16 Feb 2023 06:27:57 -0800 (PST) Received: from localhost.localdomain (awyoung.plus.com. [81.174.138.22]) by smtp.gmail.com with ESMTPSA id p15-20020a7bcdef000000b003e21356bddcsm1978194wmj.33.2023.02.16.06.27.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 06:27:56 -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 14:27:51 +0000 Message-Id: <20230216142751.1983620-1-consult.awy@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Message-ID-Hash: 7O36KUOCCUOC76SKVEAIP4KFETJWE54N X-Message-ID-Hash: 7O36KUOCCUOC76SKVEAIP4KFETJWE54N 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 Suggested-by: Jaroslav Kysela Reviewed-by: Jaroslav Kysela --- 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 ||