]> git.alsa-project.org Git - alsa-lib.git/commitdiff
pcm: direct: Propagate error code from snd_pcm_direct_client_chk_xrun()
authorTakashi Iwai <tiwai@suse.de>
Thu, 3 Mar 2022 14:04:09 +0000 (15:04 +0100)
committerTakashi Iwai <tiwai@suse.de>
Thu, 10 Mar 2022 11:58:51 +0000 (12:58 +0100)
Change the snd_pcm_direct_client_chk_xrun() function to return the
current XRUN state via an error code instead of the state change.
This allows the caller more straightforwardly returning its error, and
also covers the case where XRUN has been set but the function gets
called twice.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
src/pcm/pcm_direct.c
src/pcm/pcm_dmix.c
src/pcm/pcm_dshare.c
src/pcm/pcm_dsnoop.c

index 90417b2f45d27bad8c00e35d2807b471ed249e58..193dc3e76d49cde46f56330114ae9975a7bd39c6 100644 (file)
@@ -633,7 +633,7 @@ int snd_pcm_direct_slave_recover(snd_pcm_direct_t *direct)
 
 /*
  * enter xrun state, if slave xrun occurred
- * @return: 0 - no xrun >0: xrun happened
+ * @return: 0 for no xrun or a negative error code for xrun
  */
 int snd_pcm_direct_client_chk_xrun(snd_pcm_direct_t *direct, snd_pcm_t *pcm)
 {
@@ -650,8 +650,9 @@ int snd_pcm_direct_client_chk_xrun(snd_pcm_direct_t *direct, snd_pcm_t *pcm)
                 * snd_pcm_direct_clear_timer_queue(direct);
                 */
                direct->state = SND_PCM_STATE_XRUN;
-               return 1;
        }
+       if (direct->state == SND_PCM_STATE_XRUN)
+               return -EPIPE;
        return 0;
 }
 
index 94dbb1e00621faf26f824397d5ae146fde69914a..dfff18b992c582f4ed2ccb7110f3f0150d5ff3c3 100644 (file)
@@ -437,8 +437,9 @@ static int snd_pcm_dmix_sync_ptr(snd_pcm_t *pcm)
        default:
                break;
        }
-       if (snd_pcm_direct_client_chk_xrun(dmix, pcm))
-               return -EPIPE;
+       err = snd_pcm_direct_client_chk_xrun(dmix, pcm);
+       if (err < 0)
+               return err;
        if (dmix->slowptr)
                snd_pcm_hwsync(dmix->spcm);
 
@@ -840,8 +841,9 @@ static snd_pcm_sframes_t snd_pcm_dmix_mmap_commit(snd_pcm_t *pcm,
        default:
                break;
        }
-       if (snd_pcm_direct_client_chk_xrun(dmix, pcm))
-               return -EPIPE;
+       err = snd_pcm_direct_client_chk_xrun(dmix, pcm);
+       if (err < 0)
+               return err;
        if (! size)
                return 0;
        snd_pcm_mmap_appl_forward(pcm, size);
index 01814dc8e70d69fea6b7f07e640edb8312cedb22..d63c86bd404412b113905929061356932c9e81df 100644 (file)
@@ -212,8 +212,9 @@ static int snd_pcm_dshare_sync_ptr(snd_pcm_t *pcm)
        default:
                break;
        }
-       if (snd_pcm_direct_client_chk_xrun(dshare, pcm))
-               return -EPIPE;
+       err = snd_pcm_direct_client_chk_xrun(dshare, pcm);
+       if (err < 0)
+               return err;
        if (dshare->slowptr)
                snd_pcm_hwsync(dshare->spcm);
 
@@ -539,8 +540,9 @@ static snd_pcm_sframes_t snd_pcm_dshare_mmap_commit(snd_pcm_t *pcm,
        default:
                break;
        }
-       if (snd_pcm_direct_client_chk_xrun(dshare, pcm))
-               return -EPIPE;
+       err = snd_pcm_direct_client_chk_xrun(dshare, pcm);
+       if (err < 0)
+               return err;
        if (! size)
                return 0;
        snd_pcm_mmap_appl_forward(pcm, size);
index 3f28df9924a440a7e821037129a7d44448fea9d5..77ffbada931f2c96988aa8f536fdd07b2287f520 100644 (file)
@@ -145,8 +145,9 @@ static int snd_pcm_dsnoop_sync_ptr(snd_pcm_t *pcm)
        default:
                break;
        }
-       if (snd_pcm_direct_client_chk_xrun(dsnoop, pcm))
-               return -EPIPE;
+       err = snd_pcm_direct_client_chk_xrun(dsnoop, pcm);
+       if (err < 0)
+               return err;
        if (dsnoop->slowptr)
                snd_pcm_hwsync(dsnoop->spcm);
        old_slave_hw_ptr = dsnoop->slave_hw_ptr;
@@ -430,8 +431,9 @@ static snd_pcm_sframes_t snd_pcm_dsnoop_mmap_commit(snd_pcm_t *pcm,
        default:
                break;
        }
-       if (snd_pcm_direct_client_chk_xrun(dsnoop, pcm))
-               return -EPIPE;
+       err = snd_pcm_direct_client_chk_xrun(dsnoop, pcm);
+       if (err < 0)
+               return err;
        if (dsnoop->state == SND_PCM_STATE_RUNNING) {
                err = snd_pcm_dsnoop_sync_ptr(pcm);
                if (err < 0)