]> git.alsa-project.org Git - alsa-lib.git/commitdiff
Enhanced snd_pcm_mmap_read/write_areas to support the blocking behaviour.
authorJaroslav Kysela <perex@perex.cz>
Mon, 14 May 2001 14:31:45 +0000 (14:31 +0000)
committerJaroslav Kysela <perex@perex.cz>
Mon, 14 May 2001 14:31:45 +0000 (14:31 +0000)
Removed wrong asserts.

src/pcm/pcm_mmap.c

index c8d588d93d445c596d5a136f517fb49de36bf8f2..8ab00e2883d3d1db4f8b1be12403b1f79eb431a5 100644 (file)
@@ -86,19 +86,27 @@ static snd_pcm_uframes_t snd_pcm_mmap_write_areas(snd_pcm_t *pcm,
                                                  snd_pcm_uframes_t size)
 {
        snd_pcm_uframes_t xfer = size;
-       assert(snd_pcm_mmap_playback_avail(pcm) >= size);
+       int res;
        while (size > 0) {
                const snd_pcm_channel_area_t *pcm_areas;
                snd_pcm_uframes_t pcm_offset;
                snd_pcm_uframes_t frames = size;
                snd_pcm_mmap_begin(pcm, &pcm_areas, &pcm_offset, &frames);
-               snd_pcm_areas_copy(pcm_areas, pcm_offset,
-                                  areas, offset, 
-                                  pcm->channels, 
-                                  frames, pcm->format);
+               if (frames > 0)
+                       snd_pcm_areas_copy(pcm_areas, pcm_offset,
+                                          areas, offset, 
+                                          pcm->channels, 
+                                          frames, pcm->format);
                snd_pcm_mmap_commit(pcm, pcm_offset, frames);
-               offset += frames;
-               size -= frames;
+               if (frames == 0) {
+                       if (pcm->mode & SND_PCM_NONBLOCK)
+                               return xfer;
+                       if ((res = snd_pcm_wait(pcm, -1)) < 0)
+                               return xfer > 0 ? xfer : res;
+               } else {
+                       offset += frames;
+                       size -= frames;
+               }
        }
        return xfer;
 }
@@ -109,19 +117,27 @@ static snd_pcm_uframes_t snd_pcm_mmap_read_areas(snd_pcm_t *pcm,
                                                 snd_pcm_uframes_t size)
 {
        snd_pcm_uframes_t xfer = size;
-       assert(snd_pcm_mmap_capture_avail(pcm) >= size);
+       int res;
        while (size > 0) {
                const snd_pcm_channel_area_t *pcm_areas;
                snd_pcm_uframes_t pcm_offset;
                snd_pcm_uframes_t frames = size;
                snd_pcm_mmap_begin(pcm, &pcm_areas, &pcm_offset, &frames);
-               snd_pcm_areas_copy(areas, offset, 
-                                  pcm_areas, pcm_offset,
-                                  pcm->channels, 
-                                  frames, pcm->format);
+               if (frames > 0)
+                       snd_pcm_areas_copy(areas, offset, 
+                                          pcm_areas, pcm_offset,
+                                          pcm->channels, 
+                                          frames, pcm->format);
                snd_pcm_mmap_commit(pcm, pcm_offset, frames);
-               offset += frames;
-               size -= frames;
+               if (frames == 0) {
+                       if (pcm->mode & SND_PCM_NONBLOCK)
+                               return xfer;
+                       if ((res = snd_pcm_wait(pcm, -1)) < 0)
+                               return xfer > 0 ? xfer : res;
+               } else {
+                       offset += frames;
+                       size -= frames;
+               }
        }
        return xfer;
 }