alsa/0024-pcm-plugin-tidy-snd_pcm_plugin_avail_update.patch
Takashi Iwai 197f321105 Accepting request 860483 from home:tiwai:branches:multimedia:libs
- Backport upstream fixes:
  a PCM plugin regression fix about snd_pcm_status() call, plugin
  directory handling fixes, missing audio timestamp types,
  use-after-free fix for conf parser, PCM plugin delay account fixes,
  etc:
  0001-dlmisc-the-snd_plugin_dir_set-snd_plugin_dir-must-be.patch
  0002-dlmisc-fix-snd_plugin_dir-locking-for-not-DL_ORIGIN_.patch
  0003-pcm-snd_pcm_mmap_readi-fix-typo-in-comment.patch
  0007-pcm-set-the-snd_pcm_ioplug_status-tstamp-field.patch
  0009-pcm-Add-snd_pcm_audio_tstamp_type_t-constants.patch
  0010-test-audio_time-Make-use-of-SND_PCM_AUDIO_TSTAMP_TYP.patch
  0011-pcm-Fix-a-typo-in-SND_PCM_AUDIO_TSTAMP_TYPE_LAST-def.patch
  0012-conf-fix-use-after-free-in-_snd_config_load_with_inc.patch
  0013-ucm-fix-bad-frees-in-get_list0-and-get_list20.patch
  0014-rawmidi-fix-memory-leak-in-snd_rawmidi_virtual_open.patch
  0015-timer-fix-sizeof-operator-mismatch-in-snd_timer_quer.patch
  0016-pcm-remove-dead-assignments-from-snd_pcm_rate_-commi.patch
  0017-pcm_multi-remove-dead-assignment-from-_snd_pcm_multi.patch
  0018-conf-fix-get_hexachar-return-value.patch
  0019-pcm-fix-__snd_pcm_state-return-value.patch
  0020-confmisc-fix-memory-leak-in-snd_func_concat.patch
  0021-conf-fix-return-code-in-_snd_config_load_with_includ.patch
  0022-pcm-plugin-status-fix-the-return-value-regression.patch
  0023-pcm-plugin-status-revert-the-recent-changes.patch
  0024-pcm-plugin-tidy-snd_pcm_plugin_avail_update.patch
  0025-pcm-plugin-optimize-sync-in-snd_pcm_plugin_status.patch
  0026-Revert-pcm_plugin-fix-delay.patch
  0027-pcm-ioplug-fix-the-delay-calculation-in-the-status-c.patch
  0028-pcm-rate-tidy-up-snd_pcm_rate_avail_update.patch
  0029-pcm-ioplug-fix-the-delay-calculation-for-old-plugins.patch

OBS-URL: https://build.opensuse.org/request/show/860483
OBS-URL: https://build.opensuse.org/package/show/multimedia:libs/alsa?expand=0&rev=290
2021-01-05 14:46:39 +00:00

180 lines
5.8 KiB
Diff

From fa1895aa2b4f3f154e537bee92860fe793045643 Mon Sep 17 00:00:00 2001
From: Jaroslav Kysela <perex@perex.cz>
Date: Sun, 3 Jan 2021 16:34:04 +0100
Subject: [PATCH 24/33] pcm: plugin - tidy snd_pcm_plugin_avail_update()
No functional changes - move the code to snd_pcm_plugin_sync_hw_ptr()
and put the mmap capture updates to separate function for readability.
Signed-off-by: Jaroslav Kysela <perex@perex.cz>
---
src/pcm/pcm_plugin.c | 142 +++++++++++++++++++++++--------------------
1 file changed, 76 insertions(+), 66 deletions(-)
diff --git a/src/pcm/pcm_plugin.c b/src/pcm/pcm_plugin.c
index ea60eb98986e..83793397a7f0 100644
--- a/src/pcm/pcm_plugin.c
+++ b/src/pcm/pcm_plugin.c
@@ -460,82 +460,92 @@ snd_pcm_plugin_mmap_commit(snd_pcm_t *pcm,
return xfer > 0 ? xfer : err;
}
-static snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
+static snd_pcm_sframes_t
+snd_pcm_plugin_sync_hw_ptr_capture(snd_pcm_t *pcm,
+ snd_pcm_sframes_t slave_size)
{
snd_pcm_plugin_t *plugin = pcm->private_data;
snd_pcm_t *slave = plugin->gen.slave;
- snd_pcm_sframes_t slave_size;
+ const snd_pcm_channel_area_t *areas;
+ snd_pcm_uframes_t xfer, hw_offset, size;
int err;
- slave_size = snd_pcm_avail_update(slave);
+ xfer = snd_pcm_mmap_capture_avail(pcm);
+ size = pcm->buffer_size - xfer;
+ areas = snd_pcm_mmap_areas(pcm);
+ hw_offset = snd_pcm_mmap_hw_offset(pcm);
+ 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;
+ snd_pcm_uframes_t slave_offset;
+ snd_pcm_uframes_t slave_frames = ULONG_MAX;
+ snd_pcm_sframes_t result;
+ /* As mentioned in the ALSA API (see pcm/pcm.c:942):
+ * The function #snd_pcm_avail_update()
+ * have to be called before any mmap begin+commit operation.
+ * Otherwise the snd_pcm_areas_copy will not called a second time.
+ * But this is needed, if the ring buffer wrap is reached and
+ * there is more data available.
+ */
+ slave_size = snd_pcm_avail_update(slave);
+ result = snd_pcm_mmap_begin(slave, &slave_areas, &slave_offset, &slave_frames);
+ if (result < 0) {
+ err = result;
+ goto error;
+ }
+ if (frames > cont)
+ frames = cont;
+ frames = (plugin->read)(pcm, areas, hw_offset, frames,
+ slave_areas, slave_offset, &slave_frames);
+ result = snd_pcm_mmap_commit(slave, slave_offset, slave_frames);
+ if (result > 0 && (snd_pcm_uframes_t)result != slave_frames) {
+ snd_pcm_sframes_t res;
+ res = plugin->undo_read(slave, areas, hw_offset, frames, slave_frames - result);
+ if (res < 0) {
+ err = res;
+ goto error;
+ }
+ frames -= res;
+ }
+ if (result <= 0) {
+ err = result;
+ goto error;
+ }
+ snd_pcm_mmap_hw_forward(pcm, frames);
+ if (frames == cont)
+ hw_offset = 0;
+ else
+ hw_offset += frames;
+ size -= frames;
+ slave_size -= slave_frames;
+ xfer += frames;
+ }
+ return (snd_pcm_sframes_t)xfer;
+error:
+ return xfer > 0 ? (snd_pcm_sframes_t)xfer : err;
+}
+
+static snd_pcm_sframes_t snd_pcm_plugin_sync_hw_ptr(snd_pcm_t *pcm,
+ snd_pcm_uframes_t slave_hw_ptr,
+ snd_pcm_sframes_t slave_size)
+{
if (pcm->stream == SND_PCM_STREAM_CAPTURE &&
pcm->access != SND_PCM_ACCESS_RW_INTERLEAVED &&
pcm->access != SND_PCM_ACCESS_RW_NONINTERLEAVED)
- goto _capture;
- *pcm->hw.ptr = *slave->hw.ptr;
+ return snd_pcm_plugin_sync_hw_ptr_capture(pcm, slave_size);
+ *pcm->hw.ptr = slave_hw_ptr;
return slave_size;
- _capture:
- {
- const snd_pcm_channel_area_t *areas;
- snd_pcm_uframes_t xfer, hw_offset, size;
-
- xfer = snd_pcm_mmap_capture_avail(pcm);
- size = pcm->buffer_size - xfer;
- areas = snd_pcm_mmap_areas(pcm);
- hw_offset = snd_pcm_mmap_hw_offset(pcm);
- 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;
- snd_pcm_uframes_t slave_offset;
- snd_pcm_uframes_t slave_frames = ULONG_MAX;
- snd_pcm_sframes_t result;
- /* As mentioned in the ALSA API (see pcm/pcm.c:942):
- * The function #snd_pcm_avail_update()
- * have to be called before any mmap begin+commit operation.
- * Otherwise the snd_pcm_areas_copy will not called a second time.
- * But this is needed, if the ring buffer wrap is reached and
- * there is more data available.
- */
- slave_size = snd_pcm_avail_update(slave);
- result = snd_pcm_mmap_begin(slave, &slave_areas, &slave_offset, &slave_frames);
- if (result < 0) {
- err = result;
- goto error;
- }
- if (frames > cont)
- frames = cont;
- frames = (plugin->read)(pcm, areas, hw_offset, frames,
- slave_areas, slave_offset, &slave_frames);
- result = snd_pcm_mmap_commit(slave, slave_offset, slave_frames);
- if (result > 0 && (snd_pcm_uframes_t)result != slave_frames) {
- snd_pcm_sframes_t res;
-
- res = plugin->undo_read(slave, areas, hw_offset, frames, slave_frames - result);
- if (res < 0) {
- err = res;
- goto error;
- }
- frames -= res;
- }
- if (result <= 0) {
- err = result;
- goto error;
- }
- snd_pcm_mmap_hw_forward(pcm, frames);
- if (frames == cont)
- hw_offset = 0;
- else
- hw_offset += frames;
- size -= frames;
- slave_size -= slave_frames;
- xfer += frames;
- }
- return (snd_pcm_sframes_t)xfer;
+}
- error:
- return xfer > 0 ? (snd_pcm_sframes_t)xfer : err;
- }
+static snd_pcm_sframes_t snd_pcm_plugin_avail_update(snd_pcm_t *pcm)
+{
+ snd_pcm_plugin_t *plugin = pcm->private_data;
+ snd_pcm_t *slave = plugin->gen.slave;
+ snd_pcm_sframes_t slave_size;
+
+ slave_size = snd_pcm_avail_update(slave);
+ return snd_pcm_plugin_sync_hw_ptr(pcm, *slave->hw.ptr, slave_size);
}
static int snd_pcm_plugin_status(snd_pcm_t *pcm, snd_pcm_status_t * status)
--
2.26.2