Received: by 2002:a25:683:0:0:0:0:0 with SMTP id 125csp1168866ybg; Thu, 11 Jun 2020 02:48:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwbp9SCzVJJScpMD9FS7Dgo2jtI1A/a+Iji3v3WxPnUici7DaV7d7JhweemYJ0/do7IjkC+ X-Received: by 2002:a50:d556:: with SMTP id f22mr6438326edj.307.1591868927824; Thu, 11 Jun 2020 02:48:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1591868927; cv=none; d=google.com; s=arc-20160816; b=kZbKLohA6GpaU7r9pRfiNwONrUbBxRW3oEuUi5Tc82CdDzx3jn/VYZ6hcQGqWj8iTl ZTp4VTmgUOCF/cp+lDt6L8nCHwY8aNs00CfQ4f7BNceYFOo16sqmf17UOdMRpTQEqD0Q +j2YdOUPoJDYTnaLAh8wyloS08/ih54bEwQJtflcHwo9kIhaiwMzkXRhRPbPLrUmQZls kyuNCU28S3yTCfr8JKAKIcCOzHXAdFRMfa6iC4PPIdUZwD/Vmz9wVbMux9nF/7c8K0fb 8fT9NyXrN4IuZqevF0M7uDsFHReMtLMGDIMDoWoR4MoJL0DEVaJKYbouldm6ZMDkGJIE QpTQ== 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=WSbhCC6ummGSyKbfuWkacc5xDV+Gj2uVcV+HCGJgpm0=; b=TWK44t26pWsboux0G2OIUgQeDAjwweF/x6S0HOz2abNSNLVXDOfCjqig7pNC634d9z I412Btgt4cG4cKxnDSAjXqRhwgX7K8fbflfCxZLqnc9n6W2CotVqnTa8eDurDAg5W+70 YujVGxSUX8+AT8qn6oZE75jO9uGyH2NwWtL2xc9fpQqtYgngh2ayhYpv5TAYXW40vQnT G0UFUuUZsRRaoQ7917jL93ZNtt9GcxUA2afuFKkFxPfx3Bbt2p8FC2uyiq9f0hRPYHYg dSPxNd8fud7hntt6D8oOhYTwiRvhULDLmUpsEK4LwzQidWOQANZAJNSl274KV1Gc6uS1 yeLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=iS63csge; 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 38si1388281edr.532.2020.06.11.02.48.24; Thu, 11 Jun 2020 02:48:47 -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=iS63csge; 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 S1726854AbgFKJo3 (ORCPT + 99 others); Thu, 11 Jun 2020 05:44:29 -0400 Received: from mail.kernel.org ([198.145.29.99]:45678 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726684AbgFKJo3 (ORCPT ); Thu, 11 Jun 2020 05:44:29 -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 4211A207C3; Thu, 11 Jun 2020 09:44:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1591868669; bh=6dGlga2y8rs+Zft++wIUw+5mJiFU392Srhnvy/j+baA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=iS63csgenQ2UIlmq3F8RtVppTk3Q3dC2Q98LgAd8E6EZj3G/iH8wqNBoU+tqhHIiV jrSaLwL0tEOws48ZCq3hfqsgVItkmxQSRynqncIHFRuC2acWnsD9hNEbpsEhs4HoPM bNm5tMTuV2Pz2+w3egb3tnrCDCa6kS5x5O3crTs0= Date: Thu, 11 Jun 2020 15:14:23 +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: <20200611094423.GB1393454@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> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6a984302-ff01-e326-d338-e50e1f532cd9@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, 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; } -- ~Vinod