alsa-lib icon indicating copy to clipboard operation
alsa-lib copied to clipboard

dshare plugin : If we use pcm instead of hw for aplay during suspend resume case always getting Failed and restarting stream is coming before playing back

Open arunkapale2 opened this issue 2 months ago • 5 comments

arunkapale2 avatar Oct 31 '25 10:10 arunkapale2

aplay -D hw:2,0 xyz.wav ==> Working case(hw:2,0 + Alsa library) aplay -D pcm3 xyz.wav ==> not working case ( dshare case plugin case ( snd1_pcm_direct_check_xrun check) This additionally triggers SNDRV_PCM_TRIGGER_STOP ) aplay -D pcm1 xyz.wav ==> (Working case( Plug plugin +Alsa library))

================ log sniffet ==========================
pcm_direct[ 15:09:48.054844871 ] alsa-lib : snd1_pcm_direct_slave_recover:670
pcm_direct[ 15:09:48.054875275 ] alsa-lib : snd1_pcm_direct_slave_recover:682

[ 15:09:48.054963916 ] alsa-lib : snd_pcm_resume:1296

[ 15:09:48.055342992 ]  alsa-lib pcm->fast_ops->resume  : snd_pcm_resume:1308 err=Success
[ 15:09:48.055400608 ] alsa-lib pcm->fast_ops->resume  : snd_pcm_resume:1309 err=0
pcm_direct[ 15:09:48.055425290 ] alsa-lib snd_pcm_resume status ===== : snd1_pcm_direct_slave_recover:687 err=0
[ 15:09:48.055451072 ] alsa-lib : snd_pcm_drop:1463
[ 15:09:48.055959327 ] alsa-lib pcm->fast_ops->drop : snd_pcm_drop:1480 err=0
[ 15:09:48.056080963 ] alsa-lib -ENOSYS : snd_pcm_drop:1486 err=0
pcm_direct[ 15:09:48.056129966 ] snd_pcm_drop alsa-lib  : snd1_pcm_direct_slave_recover:689
[ 15:09:48.056341064 ]  : snd_pcm_prepare:1358
[ 15:09:48.056550671 ] alsa-lib pcm->fast_ops->prepare  : snd_pcm_prepare:1379 err=0
pcm_direct[ 15:09:48.056659261 ] alsa-lib : snd1_pcm_direct_slave_recover:699
pcm_direct[ 15:09:48.056723201 ] alsa-lib type dshare  : snd1_pcm_direct_slave_recover:719
[ 15:09:48.056777356 ] alsa-lib : snd_pcm_start:1428
[ 15:09:48.057454290 ] alsa-lib __snd_pcm_start : snd_pcm_start:1442 err=0
pcm_direct[ 15:09:48.057742203 ]  dshare alsa-lib : snd_pcm_dshare_drop:391

Suspended. Trying resume. [ 15:09:48.057838288 ] alsa-lib : snd_pcm_resume:1296
pcm_direct[ 15:09:48.057895254 ]  snd_pcm_direct_resume immideally alsa-lib : snd1_pcm_direct_resume:1253
pcm_direct[ 15:09:48.057946378 ]  snd_pcm_direct_slave_recover called alsa-lib : snd1_pcm_direct_slave_recover:644
pcm_direct[ 15:09:48.057995300 ] alsa-lib : snd1_pcm_direct_slave_recover:652
pcm_direct[ 15:09:48.058040181 ] alsa-lib : snd1_pcm_direct_slave_recover:658
pcm_direct[ 15:09:48.058085402 ]  snd_pcm_direct_resume  alsa-lib err : snd1_pcm_direct_resume:1259 err=0
[ 15:09:48.058130843 ] mmmm alsa-libsnd_pcm_resume->resume  : snd_pcm_resume:1308 err=Function not implemented
[ 15:09:48.058186129 ] alsa-lib pcm->fast_ops->resume  : snd_pcm_resume:1309 err=-38

Failed. Restarting stream. [ 15:09:48.058253730 ]  : snd_pcm_prepare:1358
[ 15:09:48.058301042 ] alsa-lib : snd_pcm_prepare:1359
[ 15:09:48.058361900 ] alsa-lib : snd_pcm_prepare:1369
pcm_direct[ 15:09:48.058414084 ] alsa-lib : snd1_pcm_direct_prepare:1222
[ 15:09:48.058469820 ] alsa-lib pcm->fast_ops->prepare  : snd_pcm_prepare:1379 err=0
[ 15:09:48.058522375 ] alsa-lib : snd_pcm_prepare:1387

Done.
pcm_direct[ 15:09:49.947074516 ] alsa-lib =========> count  : snd1_pcm_direct_check_xrun:759 err=4001

================================== Failure Case in case of PCM dshare plugin scenario Suspended. Trying resume. Failed. Restarting stream. // This creates confusion to user. Need help in fixing this error. Done.

Success Case in case of Plug as plugin scenario even direct hw working fine. Suspended. Trying resume. Done.

======================================== @tiwai , @perexg How to avoid device resumed before prepared, when a device has RESUME flag and is in SUSPENDED state? So that in pcm3 dshare case error ( "Failed. Restarting stream") should not display before resume playback

arunkapale2 avatar Oct 31 '25 10:10 arunkapale2

Could you show lines against the latest alsa-lib code? It's not clear where code is failing.

perexg avatar Oct 31 '25 10:10 perexg

@perexg,

I have added new prints in alsa-lib to debug the issue. Actual with latest code with virtul pcm device (asound.conf) I'm getting following error message.

============================================= $ aplay -D pcm3 Audio_WAV_48k_16bit_2ch.wav Playing WAVE 'Audio_WAV_48k_16bit_2ch.wav' : Signed 16 bit Little Endian, Rate 48000 Hz, Stereo Suspended. Trying resume. Failed. Restarting stream. Done.

@perexg , Code sniffet is as below https://github.com/alsa-project/alsa-lib/blob/d62b1d540781c61403681c1d903b7c74af6d1fa9/src/pcm/pcm_direct.c#L1150

int snd_pcm_direct_resume(snd_pcm_t *pcm) { snd_pcm_direct_t *dmix = pcm->private_data; int err;

err = snd_pcm_direct_slave_recover(dmix);
return err < 0 ? err : -ENOSYS;            //// This is always return other than 0 i.e only failure

}

https://github.com/alsa-project/alsa-lib/blob/d62b1d540781c61403681c1d903b7c74af6d1fa9/src/pcm/pcm_direct.c#L578

int snd_pcm_direct_slave_recover(snd_pcm_direct_t *direct) { unsigned int recoveries; int state; int ret; int semerr;

semerr = snd_pcm_direct_semaphore_down(direct,
					   DIRECT_IPC_SEM_CLIENT);
if (semerr < 0) {
	SNDERR("SEMDOWN FAILED with err %d", semerr);
	return semerr;
}

state = snd_pcm_state(direct->spcm);
   //// Second time it is enters here and return 0 
if (state != SND_PCM_STATE_XRUN && state != SND_PCM_STATE_SUSPENDED) {
	/* ignore... someone else already did recovery */
	semerr = snd_pcm_direct_semaphore_up(direct,
					     DIRECT_IPC_SEM_CLIENT);
	if (semerr < 0) {
		SNDERR("SEMUP FAILED with err %d", semerr);
		return semerr;
	}
	return 0;
}

recoveries = direct->shmptr->s.recoveries;
recoveries = (recoveries + 1) & RECOVERIES_MASK;
if (state == SND_PCM_STATE_SUSPENDED)
	recoveries |= RECOVERIES_FLAG_SUSPENDED;
direct->shmptr->s.recoveries = recoveries;

/* some buggy drivers require the device resumed before prepared;
 * when a device has RESUME flag and is in SUSPENDED state, resume
 * here but immediately drop to bring it to a sane active state.
 */
   //// First time it is enters here and success 
if (state == SND_PCM_STATE_SUSPENDED &&
    (direct->spcm->info & SND_PCM_INFO_RESUME)) {
	snd_pcm_resume(direct->spcm);
	snd_pcm_drop(direct->spcm);
	snd_pcm_direct_timer_stop(direct);
	snd_pcm_direct_clear_timer_queue(direct);
}

arunkapale2 avatar Oct 31 '25 11:10 arunkapale2

@tiwai , @perexg , dshare plugin : If we use pcm instead of hw for aplay during suspend resume case always getting Failed and restarting stream is coming before playing back properly, in aplay is getting EAGAIN error code from alsa-lib and in pcm_direct_resume always returning as failure and alsa-lib restarting stream to resume playback, how to avoid restarting stream. Please suggest how to proceed.

arunkapale2 avatar Nov 01 '25 13:11 arunkapale2

@tiwai , @perexg , @broonie , @henrikau @sandsmark Anyone can help on the above issue.

arunkapale2 avatar Nov 25 '25 06:11 arunkapale2