]> git.alsa-project.org Git - alsa-lib.git/commitdiff
Changed result of mmap_commit callback
authorJaroslav Kysela <perex@perex.cz>
Sat, 8 Dec 2001 21:02:20 +0000 (21:02 +0000)
committerJaroslav Kysela <perex@perex.cz>
Sat, 8 Dec 2001 21:02:20 +0000 (21:02 +0000)
(follows description of snd_pcm_mmap_commit function).

src/pcm/pcm_file.c
src/pcm/pcm_hooks.c
src/pcm/pcm_local.h
src/pcm/pcm_meter.c
src/pcm/pcm_multi.c
src/pcm/pcm_null.c
src/pcm/pcm_params.c
src/pcm/pcm_plugin.c
src/pcm/pcm_plugin.h
src/pcm/pcm_share.c
src/pcm/pcm_shm.c

index b65b7f1d63d551cd52cf6911d277e540ebafe9cf..9efca5393c2589cca3c6611d8209ab05d15d0ee4 100644 (file)
@@ -279,9 +279,9 @@ static snd_pcm_sframes_t snd_pcm_file_readn(snd_pcm_t *pcm, void **bufs, snd_pcm
        return n;
 }
 
-static snd_pcm_sframes_t snd_pcm_file_mmap_commit(snd_pcm_t *pcm,
-                                                 snd_pcm_uframes_t offset,
-                                                 snd_pcm_uframes_t size)
+static int snd_pcm_file_mmap_commit(snd_pcm_t *pcm,
+                                   snd_pcm_uframes_t offset,
+                                   snd_pcm_uframes_t size)
 {
        snd_pcm_file_t *file = pcm->private_data;
        snd_pcm_uframes_t ofs;
index e8349b84da861df941ed2886eee3105b8eed5911..892d43564b5f20d41ad754c81e0bd1100eb16518 100644 (file)
@@ -185,9 +185,9 @@ static snd_pcm_sframes_t snd_pcm_hooks_readn(snd_pcm_t *pcm, void **bufs, snd_pc
        return snd_pcm_readn(h->slave, bufs, size);
 }
 
-static snd_pcm_sframes_t snd_pcm_hooks_mmap_commit(snd_pcm_t *pcm,
-                                                  snd_pcm_uframes_t offset,
-                                                  snd_pcm_uframes_t size)
+static int snd_pcm_hooks_mmap_commit(snd_pcm_t *pcm,
+                                    snd_pcm_uframes_t offset,
+                                    snd_pcm_uframes_t size)
 {
        snd_pcm_hooks_t *h = pcm->private_data;
        return snd_pcm_mmap_commit(h->slave, offset, size);
index bf963d52a30f2bd4e2c6ba9c15d2127ace014a9d..6d33f7da62cd1ded5553519f5d2881ab7d85dc71 100644 (file)
@@ -142,7 +142,7 @@ typedef struct {
        snd_pcm_sframes_t (*readi)(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size);
        snd_pcm_sframes_t (*readn)(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size);
        snd_pcm_sframes_t (*avail_update)(snd_pcm_t *pcm);
-       snd_pcm_sframes_t (*mmap_commit)(snd_pcm_t *pcm, snd_pcm_uframes_t offset, snd_pcm_uframes_t size);
+       int (*mmap_commit)(snd_pcm_t *pcm, snd_pcm_uframes_t offset, snd_pcm_uframes_t size);
 } snd_pcm_fast_ops_t;
 
 struct _snd_pcm {
index 4a1876d0db4974867403f95c662964396aaf3ffb..a03305e9742152c69df970120542be086e7189a8 100644 (file)
@@ -396,9 +396,9 @@ static int snd_pcm_meter_resume(snd_pcm_t *pcm)
        return snd_pcm_resume(meter->slave);
 }
 
-static snd_pcm_sframes_t snd_pcm_meter_mmap_commit(snd_pcm_t *pcm,
-                                                  snd_pcm_uframes_t offset,
-                                                  snd_pcm_uframes_t size)
+static int snd_pcm_meter_mmap_commit(snd_pcm_t *pcm,
+                                    snd_pcm_uframes_t offset,
+                                    snd_pcm_uframes_t size)
 {
        snd_pcm_meter_t *meter = pcm->private_data;
        snd_pcm_uframes_t old_rptr = *pcm->appl_ptr;
@@ -406,11 +406,10 @@ static snd_pcm_sframes_t snd_pcm_meter_mmap_commit(snd_pcm_t *pcm,
        if (result <= 0)
                return result;
        if (pcm->stream == SND_PCM_STREAM_PLAYBACK) {
-               snd_pcm_meter_add_frames(pcm, snd_pcm_mmap_areas(pcm), old_rptr,
-                                        (snd_pcm_uframes_t) result);
+               snd_pcm_meter_add_frames(pcm, snd_pcm_mmap_areas(pcm), old_rptr, size);
                meter->rptr = *pcm->appl_ptr;
        }
-       return result;
+       return 0;
 }
 
 static snd_pcm_sframes_t snd_pcm_meter_avail_update(snd_pcm_t *pcm)
index 0a9de427b0ea98bde7e51f7faff7861245e112fb..5196b3e94fdb296746a7dbedb4f670d987ea72a1 100644 (file)
@@ -506,26 +506,22 @@ static int snd_pcm_multi_resume(snd_pcm_t *pcm)
        return err;
 }
 
-static snd_pcm_sframes_t snd_pcm_multi_mmap_commit(snd_pcm_t *pcm,
-                                                  snd_pcm_uframes_t offset,
-                                                  snd_pcm_uframes_t size)
+static int snd_pcm_multi_mmap_commit(snd_pcm_t *pcm,
+                                    snd_pcm_uframes_t offset,
+                                    snd_pcm_uframes_t size)
 {
        snd_pcm_multi_t *multi = pcm->private_data;
+       snd_pcm_t *slave;
        unsigned int i;
+       int err;
 
        for (i = 0; i < multi->slaves_count; ++i) {
-               snd_pcm_t *slave = multi->slaves[i].pcm;
-               snd_pcm_sframes_t frames = snd_pcm_mmap_commit(slave, offset, size);
-               if (frames < 0)
-                       return frames;
-               if (i == 0) {
-                       size = frames;
-                       continue;
-               }
-               if ((snd_pcm_uframes_t) frames != size)
-                       return -EBADFD;
+               slave = multi->slaves[i].pcm;
+               err = snd_pcm_mmap_commit(slave, offset, size);
+               if (err < 0)
+                       return err;
        }
-       return size;
+       return 0;
 }
 
 static int snd_pcm_multi_mmap(snd_pcm_t *pcm ATTRIBUTE_UNUSED)
index 4e30cab48c51cdfe710ecb59f00fc24b7750ff9d..a5f7b057155611b5fbdd4579083d877a118f01a9 100644 (file)
@@ -221,11 +221,17 @@ static snd_pcm_sframes_t snd_pcm_null_readn(snd_pcm_t *pcm, void **bufs ATTRIBUT
        return snd_pcm_read_areas(pcm, NULL, 0, size, snd_pcm_null_xfer_areas);
 }
 
-static snd_pcm_sframes_t snd_pcm_null_mmap_commit(snd_pcm_t *pcm,
-                                                 snd_pcm_uframes_t offset ATTRIBUTE_UNUSED,
-                                                 snd_pcm_uframes_t size)
+static int snd_pcm_null_mmap_commit(snd_pcm_t *pcm,
+                                   snd_pcm_uframes_t offset ATTRIBUTE_UNUSED,
+                                   snd_pcm_uframes_t size)
 {
-       return snd_pcm_null_fwd(pcm, size);
+       snd_pcm_sframes_t res;
+       
+       res = snd_pcm_null_fwd(pcm, size);
+       if (res < 0)
+               return res;
+       assert((snd_pcm_uframes_t)res == size);
+       return 0;
 }
 
 static snd_pcm_sframes_t snd_pcm_null_avail_update(snd_pcm_t *pcm)
index 235db6453238d510ed4c274d90f54de90c5b6e20..2119cbce29cebfc27837c25b03784721ac896258 100644 (file)
@@ -1821,7 +1821,7 @@ static snd_interval_t refine_intervals[SND_PCM_HW_PARAM_LAST_INTERVAL - SND_PCM_
        },
 };
 
-#undef RULES_DEBUG
+#define RULES_DEBUG
 
 int snd_pcm_hw_refine_soft(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params)
 {
@@ -1995,7 +1995,7 @@ int snd_pcm_hw_refine_slave(snd_pcm_t *pcm, snd_pcm_hw_params_t *params,
                }
                if (err < 0) {
 #ifdef RULES_DEBUG
-                       snd_output_printf(log, "cchange '%s', schange < 0\n", pcm->name);
+                       snd_output_printf(log, "cchange '%s', (schange || srefine) < 0\n", pcm->name);
                        snd_pcm_hw_params_dump(params, log);
 #endif
                        cchange(pcm, params, &sparams);
index 2908ff6ad07c4955c234f5fae6d3ed37f9946933..78712e3148bd9fe7fffb314bc41bc0f311ce1c4d 100644 (file)
@@ -286,28 +286,30 @@ snd_pcm_sframes_t snd_pcm_plugin_readn(snd_pcm_t *pcm, void **bufs, snd_pcm_ufra
                                  snd_pcm_plugin_read_areas);
 }
 
-snd_pcm_sframes_t snd_pcm_plugin_mmap_commit(snd_pcm_t *pcm,
-                                            snd_pcm_uframes_t offset ATTRIBUTE_UNUSED,
-                                            snd_pcm_uframes_t size)
+int snd_pcm_plugin_mmap_commit(snd_pcm_t *pcm,
+                              snd_pcm_uframes_t offset ATTRIBUTE_UNUSED,
+                              snd_pcm_uframes_t size)
 {
        snd_pcm_plugin_t *plugin = pcm->private_data;
        snd_pcm_t *slave = plugin->slave;
        const snd_pcm_channel_area_t *areas;
        snd_pcm_uframes_t xfer, hw_offset;
-       snd_pcm_uframes_t slave_size;
+       snd_pcm_sframes_t slave_size;
        if (pcm->stream == SND_PCM_STREAM_CAPTURE) {
                snd_atomic_write_begin(&plugin->watom);
                snd_pcm_mmap_appl_forward(pcm, size);
                snd_atomic_write_end(&plugin->watom);
-               return size;
+               return 0;
        }
        slave_size = snd_pcm_avail_update(slave);
-       if (slave_size <= 0)
+       if (slave_size < 0)
                return slave_size;
+       if (slave_size == 0)
+               return -EIO;
        areas = snd_pcm_mmap_areas(pcm);
        hw_offset = snd_pcm_mmap_hw_offset(pcm);
        xfer = 0;
-       while (size && slave_size) {
+       while (size > 0 && slave_size > 0) {
                snd_pcm_uframes_t frames = size;
                snd_pcm_uframes_t cont = pcm->buffer_size - hw_offset;
                const snd_pcm_channel_area_t *slave_areas;
@@ -331,7 +333,8 @@ snd_pcm_sframes_t snd_pcm_plugin_mmap_commit(snd_pcm_t *pcm,
                size -= frames;
                slave_size -= slave_frames;
        }
-       return xfer;
+       assert(size == 0);
+       return 0;
 }
 
 snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
index ba8d52c731a18e6e3033d6bb64c25ca45e360a0a..0779bc86de414a326f23788550bd07f04799ff82 100644 (file)
@@ -65,7 +65,7 @@ snd_pcm_sframes_t snd_pcm_plugin_writei(snd_pcm_t *pcm, const void *buffer, snd_
 snd_pcm_sframes_t snd_pcm_plugin_writen(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size);
 snd_pcm_sframes_t snd_pcm_plugin_readi(snd_pcm_t *pcm, void *buffer, snd_pcm_uframes_t size);
 snd_pcm_sframes_t snd_pcm_plugin_readn(snd_pcm_t *pcm, void **bufs, snd_pcm_uframes_t size);
-snd_pcm_sframes_t snd_pcm_plugin_mmap_commit(snd_pcm_t *pcm, snd_pcm_uframes_t offset, snd_pcm_uframes_t size);
+int snd_pcm_plugin_mmap_commit(snd_pcm_t *pcm, snd_pcm_uframes_t offset, snd_pcm_uframes_t size);
 snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm);
 int snd_pcm_plugin_mmap_status(snd_pcm_t *pcm);
 int snd_pcm_plugin_mmap_control(snd_pcm_t *pcm);
index 6f4f39cd938e0168169c014c8238753ec93b98a9..c3690e30fbea7c0d321f50e00256a3d24cd79571 100644 (file)
@@ -759,14 +759,14 @@ static snd_pcm_sframes_t snd_pcm_share_avail_update(snd_pcm_t *pcm)
 }
 
 /* Call it with mutex held */
-static snd_pcm_sframes_t _snd_pcm_share_mmap_commit(snd_pcm_t *pcm,
-                                                   snd_pcm_uframes_t offset ATTRIBUTE_UNUSED,
-                                                   snd_pcm_uframes_t size)
+static int _snd_pcm_share_mmap_commit(snd_pcm_t *pcm,
+                                     snd_pcm_uframes_t offset ATTRIBUTE_UNUSED,
+                                     snd_pcm_uframes_t size)
 {
        snd_pcm_share_t *share = pcm->private_data;
        snd_pcm_share_slave_t *slave = share->slave;
        snd_pcm_t *spcm = slave->pcm;
-       snd_pcm_sframes_t ret = 0;
+       snd_pcm_sframes_t ret;
        snd_pcm_sframes_t frames;
        if (pcm->stream == SND_PCM_STREAM_PLAYBACK &&
            share->state == SND_PCM_STATE_RUNNING) {
@@ -792,12 +792,12 @@ static snd_pcm_sframes_t _snd_pcm_share_mmap_commit(snd_pcm_t *pcm,
                }
                _snd_pcm_share_update(pcm);
        }
-       return size;
+       return 0;
 }
 
-static snd_pcm_sframes_t snd_pcm_share_mmap_commit(snd_pcm_t *pcm,
-                                                  snd_pcm_uframes_t offset,
-                                                  snd_pcm_uframes_t size)
+static int snd_pcm_share_mmap_commit(snd_pcm_t *pcm,
+                                    snd_pcm_uframes_t offset,
+                                    snd_pcm_uframes_t size)
 {
        snd_pcm_share_t *share = pcm->private_data;
        snd_pcm_share_slave_t *slave = share->slave;
index cb6b0cfba3bd134a8699a0ee1f73453b7e6f071f..3fe2a0619545564c7e4bee09c7e5cdfa17fab26c 100644 (file)
@@ -446,9 +446,9 @@ static int snd_pcm_shm_resume(snd_pcm_t *pcm)
        return snd_pcm_shm_action(pcm);
 }
 
-static snd_pcm_sframes_t snd_pcm_shm_mmap_commit(snd_pcm_t *pcm,
-                                                snd_pcm_uframes_t offset ATTRIBUTE_UNUSED,
-                                                snd_pcm_uframes_t size)
+static int snd_pcm_shm_mmap_commit(snd_pcm_t *pcm,
+                                  snd_pcm_uframes_t offset ATTRIBUTE_UNUSED,
+                                  snd_pcm_uframes_t size)
 {
        snd_pcm_shm_t *shm = pcm->private_data;
        volatile snd_pcm_shm_ctrl_t *ctrl = shm->ctrl;