From 0917ba63b0dc5c93bb976359166aa46dbe413442 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Sat, 8 Dec 2001 21:02:20 +0000 Subject: [PATCH] Changed result of mmap_commit callback (follows description of snd_pcm_mmap_commit function). --- src/pcm/pcm_file.c | 6 +++--- src/pcm/pcm_hooks.c | 6 +++--- src/pcm/pcm_local.h | 2 +- src/pcm/pcm_meter.c | 11 +++++------ src/pcm/pcm_multi.c | 24 ++++++++++-------------- src/pcm/pcm_null.c | 14 ++++++++++---- src/pcm/pcm_params.c | 4 ++-- src/pcm/pcm_plugin.c | 19 +++++++++++-------- src/pcm/pcm_plugin.h | 2 +- src/pcm/pcm_share.c | 16 ++++++++-------- src/pcm/pcm_shm.c | 6 +++--- 11 files changed, 57 insertions(+), 53 deletions(-) diff --git a/src/pcm/pcm_file.c b/src/pcm/pcm_file.c index b65b7f1d..9efca539 100644 --- a/src/pcm/pcm_file.c +++ b/src/pcm/pcm_file.c @@ -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; diff --git a/src/pcm/pcm_hooks.c b/src/pcm/pcm_hooks.c index e8349b84..892d4356 100644 --- a/src/pcm/pcm_hooks.c +++ b/src/pcm/pcm_hooks.c @@ -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); diff --git a/src/pcm/pcm_local.h b/src/pcm/pcm_local.h index bf963d52..6d33f7da 100644 --- a/src/pcm/pcm_local.h +++ b/src/pcm/pcm_local.h @@ -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 { diff --git a/src/pcm/pcm_meter.c b/src/pcm/pcm_meter.c index 4a1876d0..a03305e9 100644 --- a/src/pcm/pcm_meter.c +++ b/src/pcm/pcm_meter.c @@ -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) diff --git a/src/pcm/pcm_multi.c b/src/pcm/pcm_multi.c index 0a9de427..5196b3e9 100644 --- a/src/pcm/pcm_multi.c +++ b/src/pcm/pcm_multi.c @@ -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) diff --git a/src/pcm/pcm_null.c b/src/pcm/pcm_null.c index 4e30cab4..a5f7b057 100644 --- a/src/pcm/pcm_null.c +++ b/src/pcm/pcm_null.c @@ -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) diff --git a/src/pcm/pcm_params.c b/src/pcm/pcm_params.c index 235db645..2119cbce 100644 --- a/src/pcm/pcm_params.c +++ b/src/pcm/pcm_params.c @@ -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); diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c index 2908ff6a..78712e31 100644 --- a/src/pcm/pcm_plugin.c +++ b/src/pcm/pcm_plugin.c @@ -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) diff --git a/src/pcm/pcm_plugin.h b/src/pcm/pcm_plugin.h index ba8d52c7..0779bc86 100644 --- a/src/pcm/pcm_plugin.h +++ b/src/pcm/pcm_plugin.h @@ -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); diff --git a/src/pcm/pcm_share.c b/src/pcm/pcm_share.c index 6f4f39cd..c3690e30 100644 --- a/src/pcm/pcm_share.c +++ b/src/pcm/pcm_share.c @@ -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; diff --git a/src/pcm/pcm_shm.c b/src/pcm/pcm_shm.c index cb6b0cfb..3fe2a061 100644 --- a/src/pcm/pcm_shm.c +++ b/src/pcm/pcm_shm.c @@ -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; -- 2.47.1