Skip to contentSkip to conversation

pcm: null: Do not allow a period size of 0

PATCH Superseded [email protected] 2 participants 2 messages Apr 5, 2019

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pcm: null: Do not allow a period size of 0

From: Timo Wischer <[email protected]>

Some applications do not expect that get_period_size_min() could return 0. Therefore these applications cannot use the null plugin without this patch.
Due to there is no use case for having a period size of 0 this patch disallows a period size of 0 when using the null plugin.

---
 src/pcm/pcm_null.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
src/pcm/pcm_null.c +12 -1
index ff61624..c95fad8 100644
@@ -261,7 +261,18 @@ static snd_pcm_sframes_t snd_pcm_null_mmap_commit(snd_pcm_t *pcm,
 
 static int snd_pcm_null_hw_refine(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params)
 {
-	int err = snd_pcm_hw_refine_soft(pcm, params);
+	int err;
+
+	/* Do not return a period size of 0 because for example portaudio cannot
+	 * handle it. In addition such small buffers would only increase the CPU
+	 * load but there is no benefit when throwing the samples anyway away.
+	 */
+	err = _snd_pcm_hw_param_set_min(params, SND_PCM_HW_PARAM_PERIOD_SIZE,
+					32, 0);
+	if (err < 0)
+		return err;
+
+	err = snd_pcm_hw_refine_soft(pcm, params);
 	params->info = SND_PCM_INFO_MMAP | SND_PCM_INFO_MMAP_VALID |
 		       SND_PCM_INFO_RESUME | SND_PCM_INFO_PAUSE;
 	params->fifo_size = 0;
Signature · 1 line
2.7.4
#1 lore raw
Quoted 21 lines · On Fri, 05 Apr 2019 16:09:53 +0200, <[email protected]> wrote:

From: Timo Wischer <[email protected]>

Some applications do not expect that get_period_size_min() could return 0. Therefore these applications cannot use the null plugin without this patch.
Due to there is no use case for having a period size of 0 this patch disallows a period size of 0 when using the null plugin.

---
 src/pcm/pcm_null.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)
src/pcm/pcm_null.c +0 -0
index ff61624..c95fad8 100644
@@ -261,7 +261,18 @@ static snd_pcm_sframes_t snd_pcm_null_mmap_commit(snd_pcm_t *pcm,
 
 static int snd_pcm_null_hw_refine(snd_pcm_t *pcm ATTRIBUTE_UNUSED, snd_pcm_hw_params_t *params)

src/pcm/pcm_null.c static snd_pcm_sframes_t snd_pcm_null_mmap_commit(snd_pcm_t *pcm, · line 271

Quoted 10 lines
src/pcm/pcm_null.c +8 -1
 {
-	int err = snd_pcm_hw_refine_soft(pcm, params);
+	int err;
+
+	/* Do not return a period size of 0 because for example portaudio cannot
+	 * handle it. In addition such small buffers would only increase the CPU
+	 * load but there is no benefit when throwing the samples anyway away.
+	 */
+	err = _snd_pcm_hw_param_set_min(params, SND_PCM_HW_PARAM_PERIOD_SIZE,
+					32, 0);

Why 32? This is a virtual device, hence we don't need to set any practical limit. If the zero is harmfull, the next preferable alternative is 1, when logically thinking. Or does it cause a problem?

thanks,

Takashi