Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1257380ybg; Thu, 11 Jun 2020 05:19:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLgQJtxU8rJLpUk9zDkZPRzft2vDi2KmT757aDKX0vuAmFh+sdMyVWH/FPwzWFwgJClUP0 X-Received: by 2002:a17:906:3604:: with SMTP id q4mr8184337ejb.69.1591877997178; Thu, 11 Jun 2020 05:19:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591877997; cv=none; d=google.com; s=arc-20160816; b=Ce5MRW+p5hVn71jrDxYatJjqaJFaXvijtnaC0c7faG0UaJ6ZCRT0Tmp988qTsV5JAl E9UnPvJGYDQlkwtx/t7xjp2UhTY3BG/FPmCRrGsP5Q2fuvuG82A5/y8F7nw3NNnnv7qt P4C0V7XWnaCD0VMScoeW1Y198VgH3dW4fDb6CKXCz52C2I4zRla4VuFNCh1SA/3yQYz/ E/oBZcyYLunCqBVo9bYnOZ3uzImg80666fovZe28mFfL10n6kLh0BAtn3joHKBKbxSqb X+HnVte10kWnvNkU88USkheC3AJEYDaVZvB4RIabihCGewl9weKxHpe8IXWLuvgOCIvG ijLg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=/OI0lOB8HEN36VSYL3FB2e44fEYVBfm6uXR7zc5e8vQ=; b=ZtljR3xYEGhJqRaNUQy9deaM2bBUGH0ImLiZW2Z+ZWrbSiu9QCotjWqv3/I6GZxeGe DqYW/EIx/+czIDAiJtBBZN3lgBk91Qk/D8AGhIOV0vBG5KpSqnTax+g0E1Bbov0b37mk yer9Yx2KgwVj0W6qnWRdoufZjSJvQcabC1EM8QGOY//vQmP/sbTvZ58sfbpt2IyY3V9o hf0wzd3upzOaSCBiN+QVwyhnkzdMm9CuRccBb8QPZw+mt9M/MXGl5hy2AZbQ3o/w5lV2 ysOCI2Bphjl2ZNILxduHdGsmQeu1QJfT/4JZr3FmHxAdQEOpStc6F48bqvbMSi5D2bWG ZRsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jxFLObgR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q7si1889245ejb.504.2020.06.11.05.19.33; Thu, 11 Jun 2020 05:19:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=jxFLObgR; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727901AbgFKLC5 (ORCPT + 99 others); Thu, 11 Jun 2020 07:02:57 -0400 Received: from mail.kernel.org ([198.145.29.99]:40928 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727788AbgFKLCf (ORCPT ); Thu, 11 Jun 2020 07:02:35 -0400 Received: from localhost (unknown [171.61.66.58]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 5C80B20801; Thu, 11 Jun 2020 11:02:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591873354; bh=vm/oU7bN6e1mSo3bB9GgSYG6VFq0cqVPDddNL9y/TLc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=jxFLObgRMQFE3cRyFSckY441H7v2i5CwkHsLLUJ1R9dNLQiObPEdjaUySJXTWrhdP UqUfySIWuafVWSCIIti4KaICTJzUUFGvKANkcNFUbT2oNZ/Mt9720d5DEdhOS7KndU CT700RunbH3BHUhzd7w3+aCJnnd2XsWcMGg7NyE0= Date: Thu, 11 Jun 2020 16:32:28 +0530 From: Vinod Koul To: Jaroslav Kysela Cc: Charles Keepax , alsa-devel@alsa-project.org, broonie@kernel.org, Srinivas Kandagatla , tiwai@suse.com, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH] ALSA: compress: Fix gapless playback state machine Message-ID: <20200611110228.GC1393454@vkoul-mobl> References: <20200610100729.362-1-srinivas.kandagatla@linaro.org> <817d009e-fa09-e897-cfc3-997bf1dd5e30@perex.cz> <20200610105820.GA1393454@vkoul-mobl> <20200611084659.GO71940@ediswmail.ad.cirrus.com> <6a984302-ff01-e326-d338-e50e1f532cd9@perex.cz> <20200611094423.GB1393454@vkoul-mobl> <8bba7e36-af15-33ac-bfc7-d436030f08b7@perex.cz> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8bba7e36-af15-33ac-bfc7-d436030f08b7@perex.cz> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 11-06-20, 12:40, Jaroslav Kysela wrote: > Dne 11. 06. 20 v 11:44 Vinod Koul napsal(a): > > On 11-06-20, 11:09, Jaroslav Kysela wrote: > > > Dne 11. 06. 20 v 10:46 Charles Keepax napsal(a): > > > > On Wed, Jun 10, 2020 at 04:28:20PM +0530, Vinod Koul wrote: > > > > > On 10-06-20, 12:40, Jaroslav Kysela wrote: > > > > > > Dne 10. 06. 20 v 12:07 Srinivas Kandagatla napsal(a): > > > > > > > For gapless playback call to snd_compr_drain_notify() after > > > > > > > partial drain should put the state to SNDRV_PCM_STATE_RUNNING > > > > > > > rather than SNDRV_PCM_STATE_SETUP as the driver is ready to > > > > > > > process the buffers for new track. > > > > > > > > > > > > > > With existing code, if we are playing 3 tracks in gapless, after > > > > > > > partial drain finished on previous track 1 the state is set to > > > > > > > SNDRV_PCM_STATE_SETUP which is then moved to SNDRV_PCM_STATE_PREPARED > > > > > > > after data write. With this state calls to snd_compr_next_track() and > > > > > > > few other calls will fail as they expect the state to be in > > > > > > > SNDRV_PCM_STATE_RUNNING. > > > > > > > > > > > > > > Here is the sequence of events and state transitions: > > > > > > > > > > > > > > 1. set_params (Track 1), state = SNDRV_PCM_STATE_SETUP > > > > > > > 2. set_metadata (Track 1), no state change, state = SNDRV_PCM_STATE_SETUP > > > > > > > 3. fill and trigger start (Track 1), state = SNDRV_PCM_STATE_RUNNING > > > > > > > 4. set_next_track (Track 2), state = SNDRV_PCM_STATE_RUNNING > > > > > > > 5. partial_drain (Track 1), state = SNDRV_PCM_STATE_SETUP > > > > > > > 6 snd_compr_drain_notify (Track 1), state = SNDRV_PCM_STATE_SETUP > > > > > > > 7. fill data (Track 2), state = SNDRV_PCM_STATE_PREPARED > > > > > > > 8. set_metadata (Track 3), no state change, state = SNDRV_PCM_STATE_PREPARED > > > > > > > 9. set_next_track (Track 3), !! FAILURE as state != SNDRV_PCM_STATE_RUNNING > > > > > > > > > > > > > > > > > > The snd_compr_drain_notify() is called only from snd_compr_stop(). Something > > > > > > is missing in this sequence? > > > > > > > > > > It is supposed to be invoked by driver when partial drain is complete.. > > > > > both intel and sprd driver are calling this. snd_compr_stop is stop > > > > > while draining case so legit > > > > > > > > > > > > > Not sure I follow this statement, could you elaborate a bit? > > > > snd_compr_stop putting the state to RUNNING seems fundamentally > > > > broken to me, the whole point of snd_compr_stop is to take the > > > > state out of RUNNING. > > > > > > Yes. I agree. It seems that the acknowledge for the partial drain should be > > > handled differently. > > > > Yeah sorry I overlooked that case and was thinking of it being invoked > > from driver! > > > > Yes this would make the snd_compr_stop() behave incorrectly.. so this > > cant be done as proposed. > > > > But we still need to set the draining stream state properly and I am > > thinking below now: > > > > diff --git a/sound/core/compress_offload.c b/sound/core/compress_offload.c > > index 509290f2efa8..9aba851732d7 100644 > > --- a/sound/core/compress_offload.c > > +++ b/sound/core/compress_offload.c > > @@ -929,7 +929,9 @@ static int snd_compr_partial_drain(struct snd_compr_stream *stream) > > } > > stream->next_track = false; > > - return snd_compress_wait_for_drain(stream); > > + retval = snd_compress_wait_for_drain(stream); > > + stream->runtime->state = SNDRV_PCM_STATE_RUNNING; > > + return retval; > > } > > I see a race possibility when the last track is too small and the driver > signals the end-of-track twice. In this case the partial drain should not > end with the running state. It would be probably better to separate partial > / last track acknowledgements. I completely agree that we should have separate acknowledgements here, and going to rethink all state transitions for gapless here.. Thanks for the help -- ~Vinod