Skip to contentSkip to conversation

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

PATCH In review [email protected] 2 participants 2 messages Apr 8, 2019

lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

---

Hi Takashi,

Quoted 1 line

Why 32?

I thought there is also no use case for a period of 1 frame. Therefore I increased it to a 2^n value to also lower the CPU usage in case of null plugin.

Quoted 1 line

Or does it cause a problem?

I do not see any issues here. But for example portaudio will automatically choose a period size of 1 frame which will result in a higher CPU load.

But anyway I would also be fine with this higher CPU load if you prefer this patch.

Best regards

Timo

 src/pcm/pcm_null.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
src/pcm/pcm_null.c +11 -1
index ff61624..1d81548 100644
@@ -261,7 +261,17 @@ 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.
+	 */
+	err = _snd_pcm_hw_param_set_min(params, SND_PCM_HW_PARAM_PERIOD_SIZE, 1,
+					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 19 lines · On Mon, 08 Apr 2019 10:55:54 +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.

---

Hi Takashi,

Quoted 1 line

Why 32?

I thought there is also no use case for a period of 1 frame. Therefore I increased it to a 2^n value to also lower the CPU usage in case of null plugin.

Quoted 6 lines
Quoted 1 line

Or does it cause a problem?

I do not see any issues here. But for example portaudio will automatically choose a period size of 1 frame which will result in a higher CPU load.

But anyway I would also be fine with this higher CPU load if you prefer this patch.

Well, this is rather a bug in portaudio, then. Clearly it's nonsense to return zero for the minimal size, but any positive number can be seen as a theoretically valid number. This doesn't mean that any value is usable for the practical use case, because such parameters strongly depend on the other components like the CPU speed, memory speed, whatever. From the same reason, this can't be fixed from the driver or the plugin itself.

So, I took now your v2 patch as is. The rest should be a tuning issue.

thanks,

Takashi