[PATCH] ALSA: compress: allow pause and resume during draining
Jaroslav Kysela
perex at perex.cz
Wed Sep 30 11:57:45 CEST 2020
Dne 30. 09. 20 v 11:35 Takashi Iwai napsal(a):
> On Tue, 29 Sep 2020 19:27:17 +0200,
> Jaroslav Kysela wrote:
>>
>> Dne 29. 09. 20 v 9:12 Takashi Iwai napsal(a):
>>> On Tue, 29 Sep 2020 03:51:35 +0200,
>>> Gyeongtaek Lee wrote:
>>>>
>>>> On 9/28/20 11:35 PM, Pierre-Louis Bossart wrote:
>>>>> On 9/28/20 6:13 AM, Jaroslav Kysela wrote:
>>>>>> Dne 28. 09. 20 v 12:50 Gyeongtaek Lee napsal(a):
>>>>>>> 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.
>>>>>>> If pause and resume is allowed during draining, user experience can be
>>>>>>> enhanced.
>>>>>>
>>>>>> It seems that we need a new state to handle the pause + drain condition for
>>>>>> this case.
>>>>>>
>>>>>> With this proposed change, the pause state in drain is invisible.
>>>>>
>>>>> Indeed it's be much nicer to have a new state, e..g
>>>>> SNDRV_PCM_STATE_DRAINING_PAUSED.
>>>> Ok. I will add the new state.
>>>>>
>>>>> One concern is that states are defined in uapi/sound/asoc.h, so wouldn't
>>>>> this have impacts on userspace as well? We'd change the value of
>>>>> SNDRV_PCM_STATE_LAST.
>>>>>
>>>> I also agree that adding new state and increase LAST value in the header of uapi
>>>> could be dangerous. So, I added it to comress_offload.h for now.
>>>> It could be merged into snd_pcm_state_t in someday with big changes.
>>>> Could you review the fixed patch below?
>>
>> I don't see a big problem to improve the API, but don't forget to increase the
>> SNDRV_COMPRESS_VERSION, so the user space apps can check for this new behaviour.
>>
>>> Hrm, this resulted in rather more complex changes than the original
>>> patch. It shows that introducing yet another state is no good idea
>>> for this particular case.
>>
>> I don't think so. The states should be isolated and it's clearly a new state
>> and the resulted code at least gives a commented idea, what's going on. It
>> seems that the compress driver state is not exported to the user space at the
>> moment, so I would consider this extension as harmless. We can add this state
>> to asound.h so the user space can be updated. We may use this state for the
>> standard PCM devices one day, too. It makes sense to reserve it sooner than later.
>
> Well, adding a new state can be cumbersome sometimes. For example, the
> code like below may hit a segfault out of sudden after the upgrade:
>
> const char *states[SNDRV_PCM_STATE_LAST + 1] = {
> [SNDRV_PCM_STATE_RUNNING] = "running",
> ....
> };
>
> printf("current state = %s\n", states[s]);
>
> It's not much frequent breakage, but this can give certainly some
> incompatibilities even in the source code level.
alsa-lib has already the correct protection for this case:
const char *snd_pcm_state_name(const snd_pcm_state_t state)
{
if (state > SND_PCM_STATE_LAST)
return NULL;
return snd_pcm_state_names[state];
}
If there's no check, it's a clear bug.
> That's the reason I'm reluctant to add a new state unless it's a must.
> As mentioned, the expected application's behavior is just like the
> normal pause state, either resuming pause or dropping. The only case
> where a new state would help for application is at most that they may
> foresee beforehand which state it'll go after the resume, to drain or
> to running. If this is a must-to-have feature, we can reconsider.
I don't agree here. It's much better to not hide the state related transitions
even in the kernel in my eyes. For example drivers may behave differently when
they resume from running+pause or drain+pause states.
The correct SNDRV_PCM_STATE_LAST is just an implementation issue, which can be
easily solved.
Jaroslav
--
Jaroslav Kysela <perex at perex.cz>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
More information about the Alsa-devel
mailing list