Skip to content

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 #479

Open

Description

@arunkapale2
No description provided.

Activity

  1. arunkapale2 commented on Oct 31, 2025

    @arunkapale2
    Author

    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

  2. pinned this issue on Oct 31, 2025
  3. perexg commented on Oct 31, 2025

    @perexg
    Member

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

  4. arunkapale2 commented on Oct 31, 2025

    @arunkapale2
    Author

    @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

    err = snd_pcm_direct_slave_recover(dmix);

    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
    

    }

    int snd_pcm_direct_slave_recover(snd_pcm_direct_t *direct)

    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);
    }
    
  5. arunkapale2 commented on Nov 1, 2025

    @arunkapale2
    Author

    @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.

  6. arunkapale2 commented on Nov 25, 2025

    @arunkapale2
    Author

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

  7. unpinned this issue on Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions