Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F14EEC2D0A3 for ; Wed, 4 Nov 2020 03:09:12 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 2CADB223C7 for ; Wed, 4 Nov 2020 03:09:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="XxbNMYKa"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="CzyPVTBz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2CADB223C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=samsung.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 8E0E5169E; Wed, 4 Nov 2020 04:08:18 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 8E0E5169E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1604459348; bh=B/eoybxluxfKkCChyU16SWAY0sv6u45VlO0frmq64kw=; h=From:To:Subject:Date:References:Cc:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From; b=XxbNMYKa9HRvlvDuujgSPHgCoF0DDccyAz1w5GtvxtisG5Q1pdmDJ3QRsQIVWiqIb 4kqQzgFm3BM6a9K/SGi746ye+O/EPEF1Dmhg3kVe8LtbMRKVF55/X4Vuc4i3+nxKXQ TXU7+AnAw6rq1V9fQBY5x2EMxIWA8wX6QqNScgaw= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id 21F4AF80229; Wed, 4 Nov 2020 04:08:18 +0100 (CET) Received: by alsa1.perex.cz (Postfix, from userid 50401) id 7BE5BF8023E; Wed, 4 Nov 2020 04:08:16 +0100 (CET) Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa1.perex.cz (Postfix) with ESMTPS id 4EAA0F800EC for ; Wed, 4 Nov 2020 04:08:09 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 4EAA0F800EC Authentication-Results: alsa1.perex.cz; dkim=pass (1024-bit key) header.d=samsung.com header.i=@samsung.com header.b="CzyPVTBz" Received: from epcas2p1.samsung.com (unknown [182.195.41.53]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20201104030805epoutp032cfed58f559b2245d5406cb37fdfe618~ELzg7--Jp2826428264epoutp03i for ; Wed, 4 Nov 2020 03:08:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20201104030805epoutp032cfed58f559b2245d5406cb37fdfe618~ELzg7--Jp2826428264epoutp03i DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1604459285; bh=rhFor7HOID1/BRCifiDxOTT5PjmjzvoIwTFygN5tSoo=; h=From:To:Cc:Subject:Date:References:From; b=CzyPVTBzBlN7lK6QN6UXbISs3Nd/eX3QEcQ75SjXw1rJf0oNbNtk0Ok7I7Xjy9hOX qKDMygCyK5/Osjhey54NqvfAjcFxdIqepk+fWGjbhH1e0r5lKTPZ44YOjEMzlBzUiD 209AiuETz4pObMRAKMWdzBtLVbKmZU+Ks/d04HFk= Received: from epsnrtp3.localdomain (unknown [182.195.42.164]) by epcas2p4.samsung.com (KnoxPortal) with ESMTP id 20201104030805epcas2p481be255b865bad7e3eaf356b6aebacda~ELzgizq7D0145201452epcas2p4i; Wed, 4 Nov 2020 03:08:05 +0000 (GMT) Received: from epsmges2p4.samsung.com (unknown [182.195.40.181]) by epsnrtp3.localdomain (Postfix) with ESMTP id 4CQs6C15zzzMqYkV; Wed, 4 Nov 2020 03:08:03 +0000 (GMT) Received: from epcas2p1.samsung.com ( [182.195.41.53]) by epsmges2p4.samsung.com (Symantec Messaging Gateway) with SMTP id 87.AE.52511.11B12AF5; Wed, 4 Nov 2020 12:08:01 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas2p2.samsung.com (KnoxPortal) with ESMTPA id 20201104030801epcas2p23ba139ff40fca7f3988d72622c58a0f5~ELzc3bYA-1727017270epcas2p2p; Wed, 4 Nov 2020 03:08:01 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20201104030801epsmtrp1831dd3d2b5f19dae741b87ee7f17cbf3~ELzc2aDiP0498804988epsmtrp1i; Wed, 4 Nov 2020 03:08:01 +0000 (GMT) X-AuditID: b6c32a48-a9948a800000cd1f-73-5fa21b11775f Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id EC.41.08745.11B12AF5; Wed, 4 Nov 2020 12:08:01 +0900 (KST) Received: from KORDO025540 (unknown [12.36.182.130]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20201104030801epsmtip14433db5b185d61b4a5359ad4bdc9304f~ELzcqV2sv2905029050epsmtip1b; Wed, 4 Nov 2020 03:08:01 +0000 (GMT) From: "Gyeongtaek Lee" To: "'Takashi Iwai'" Subject: [PATCH v2 1/1] ALSA: compress: allow pause and resume during draining Date: Wed, 4 Nov 2020 12:08:01 +0900 Message-ID: <000101d6b257$b46b0620$1d411260$@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdayV1qJKikvGkxVQ+2Fdrz6iBk1dw== Content-Language: ko X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrNJsWRmVeSWpSXmKPExsWy7bCmqa6g9KJ4g0mfDS2uXDzEZDFjWzeL ReO9CWwWq69uYbL4dqWDyeLX/2dMFkcvLmayaLjbzG6x4ftaRouXm98wWRxpnMJksfPOCWYH Ho8Nn5vYPHbOusvusWlVJ5vHvJOBHn1bVjF6rN9ylcVj8+nqAPaoHJuM1MSU1CKF1Lzk/JTM vHRbJe/geOd4UzMDQ11DSwtzJYW8xNxUWyUXnwBdt8wcoEOVFMoSc0qBQgGJxcVK+nY2Rfml JakKGfnFJbZKqQUpOQWGhgV6xYm5xaV56XrJ+blWhgYGRqZAlQk5Gddb2lkKTmpWzN61mrGB cYNSFyMnh4SAicTrKf8Yuxi5OIQEdjBKLN16mRXC+cQo8XB9MwuE85lRYtXF2YwwLadPzGKH SOxilPh38QxUy0tGib7OKewgVWwCuhJf7t1hBrFFBFQknvauYwIpYhY4wiTx7cFrsCJhgQCJ F/eOMoHYLEBFfzY/AFvBK2ApMeHAbCYIW1Di5MwnLCA2s4C8xPa3c5ghzlCQ+Pl0GSvEAj2J nRvaWCFqRCRmd7YxgyyTEFjLIbHi9XcWiAYXibUzNkDZwhKvjm9hh7ClJF72t7FDNDQzSrw7 +wcqMYVRorNbCMI2ltgy9xTQRRxAGzQl1u/SBzElBJQljtyCuo1PouPwX3aIMK9ERxtUo5LE xlP/mCDCEhLzNkDN9pA4Pf8N0w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tVyv ODG3uDQvXS85P3cTIzi+tLR2MO5Z9UHvECMTB+MhRgkOZiUR3prIefFCvCmJlVWpRfnxRaU5 qcWHGKU5WJTEeb/OWhgnJJCeWJKanZpakFoEk2Xi4JRqYDL1kEtq3fM660yNppr0A21NOZf2 SBYW/iMTPZO3bG9qkTfevuyewJ/jwSyrZfbOnNkx67HY/19/YivtrT996G39HJvZtF/rV3XD DCPOWxtarybL3xJd4jRjW/WrGZ3a2T/Fd2z45eu3qOmhrt6XV6lJyW9Pbey5d+CZ0bSUkiad Q6639E5xC31wP2YqPVda8edWwfbTt9/zGW8PD7/551KQdkq43/8As+str3/uC5L7uFBbXeCl xYepYs6bjHOnfjHcHRm4RXP9q0u562qrjvNalZ1pehIlU5mUU+nRaWrg3y0/NaKYT6T6yL68 2HrLQywvnsyskrif8+K8+M5MPRHlL3krNzj847p9W+o7jxJLcUaioRZzUXEiAJo1yiseAwAA X-CMS-MailID: 20201104030801epcas2p23ba139ff40fca7f3988d72622c58a0f5 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: AUTO_CONFIDENTIAL CMS-TYPE: 102P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20201104030801epcas2p23ba139ff40fca7f3988d72622c58a0f5 References: Cc: 'Pierre-Louis Bossart' , alsa-devel@alsa-project.org, khw0178.kim@samsung.com, kimty@samsung.com, tiwai@suse.com, lgirdwood@gmail.com, 'Vinod Koul' , hmseo@samsung.com, s47.kang@samsung.com, pilsun.jang@samsung.com, tkjung@samsung.com X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 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: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" With a stream with low bitrate, user can't pause or resume the stream near the end of the stream because current ALSA doesn't allow it. If the stream has very low bitrate enough to store whole stream into the buffer, user can't do anything except stop the stream and then restart it from the first because most of applications call draining after sending last frame to the kernel. If pause, resume are allowed during draining, user experience can be enhanced. To prevent malfunction in HW drivers which don't support pause during draining, pause during draining will only work if HW driver enable this feature explicitly by calling snd_compr_use_pause_in_draining(). Signed-off-by: Gyeongtaek Lee Cc: stable@vger.kernel.org --- include/sound/compress_driver.h | 17 +++++++++++++ sound/core/compress_offload.c | 44 +++++++++++++++++++++++++++------ 2 files changed, 53 insertions(+), 8 deletions(-) diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h index 70cbc5095e72..5a0d6737de5e 100644 --- a/include/sound/compress_driver.h +++ b/include/sound/compress_driver.h @@ -67,6 +67,7 @@ struct snd_compr_runtime { * @metadata_set: metadata set flag, true when set * @next_track: has userspace signal next track transition, true when set * @partial_drain: undergoing partial_drain for stream, true when set + * @pause_in_draining: paused during draining state, true when set * @private_data: pointer to DSP private data * @dma_buffer: allocated buffer if any */ @@ -80,6 +81,7 @@ struct snd_compr_stream { bool metadata_set; bool next_track; bool partial_drain; + bool pause_in_draining; void *private_data; struct snd_dma_buffer dma_buffer; }; @@ -142,6 +144,7 @@ struct snd_compr_ops { * @direction: Playback or capture direction * @lock: device lock * @device: device id + * @use_pause_in_draining: allow pause in draining, true when set */ struct snd_compr { const char *name; @@ -152,6 +155,7 @@ struct snd_compr { unsigned int direction; struct mutex lock; int device; + bool use_pause_in_draining; #ifdef CONFIG_SND_VERBOSE_PROCFS /* private: */ char id[64]; @@ -166,6 +170,19 @@ int snd_compress_deregister(struct snd_compr *device); int snd_compress_new(struct snd_card *card, int device, int type, const char *id, struct snd_compr *compr); +/** + * snd_compr_use_pause_in_draining - Allow pause and resume in draining state + * @substream: compress substream to set + * + * Allow pause and resume in draining state. + * Only HW driver supports this transition can call this API. + */ +static inline void snd_compr_use_pause_in_draining( + struct snd_compr_stream *substream) +{ + substream->device->use_pause_in_draining = true; +} + /* dsp driver callback apis * For playback: driver should call snd_compress_fragment_elapsed() to let the * framework know that a fragment has been consumed from the ring buffer diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c index c1fec932c49d..3f4e14cdd15a 100644 --- a/sound/core/compress_offload.c +++ b/sound/core/compress_offload.c @@ -709,11 +709,24 @@ static int snd_compr_pause(struct snd_compr_stream *stream) { int retval; - if (stream->runtime->state != SNDRV_PCM_STATE_RUNNING) + switch (stream->runtime->state) { + case SNDRV_PCM_STATE_RUNNING: + retval = stream->ops->trigger(stream, + SNDRV_PCM_TRIGGER_PAUSE_PUSH); + if (!retval) + stream->runtime->state = SNDRV_PCM_STATE_PAUSED; + break; + case SNDRV_PCM_STATE_DRAINING: + if (!stream->device->use_pause_in_draining) + return -EPERM; + retval = stream->ops->trigger(stream, + SNDRV_PCM_TRIGGER_PAUSE_PUSH); + if (!retval) + stream->pause_in_draining = true; + break; + default: return -EPERM; - retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_PUSH); - if (!retval) - stream->runtime->state = SNDRV_PCM_STATE_PAUSED; + } return retval; } @@ -721,11 +734,25 @@ static int snd_compr_resume(struct snd_compr_stream *stream) { int retval; - if (stream->runtime->state != SNDRV_PCM_STATE_PAUSED) + switch (stream->runtime->state) { + case SNDRV_PCM_STATE_PAUSED: + retval = stream->ops->trigger(stream, + SNDRV_PCM_TRIGGER_PAUSE_RELEASE); + if (!retval) + stream->runtime->state = SNDRV_PCM_STATE_RUNNING; + break; + case SNDRV_PCM_STATE_DRAINING: + if (!stream->device->use_pause_in_draining || + !stream->pause_in_draining) + return -EPERM; + retval = stream->ops->trigger(stream, + SNDRV_PCM_TRIGGER_PAUSE_RELEASE); + if (!retval) + stream->pause_in_draining = false; + break; + default: return -EPERM; - retval = stream->ops->trigger(stream, SNDRV_PCM_TRIGGER_PAUSE_RELEASE); - if (!retval) - stream->runtime->state = SNDRV_PCM_STATE_RUNNING; + } return retval; } @@ -768,6 +795,7 @@ static int snd_compr_stop(struct snd_compr_stream *stream) /* clear flags and stop any drain wait */ stream->partial_drain = false; stream->metadata_set = false; + stream->pause_in_draining = false; snd_compr_drain_notify(stream); stream->runtime->total_bytes_available = 0; stream->runtime->total_bytes_transferred = 0; -- 2.21.0