mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2026-05-26 21:38:23 -04:00
alsa: write silence in smaller chunks
With large quantum and many channels, the silence buffer can become quite large (many MB), which can cause a stack overflow. Use a fixed size silence buffer instead and write in smaller chunks.
This commit is contained in:
parent
0ac3cf3c88
commit
6c0a9b31f6
1 changed files with 15 additions and 9 deletions
|
|
@ -2687,16 +2687,22 @@ static int spa_alsa_silence(struct state *state, snd_pcm_uframes_t silence)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
uint8_t buffer[silence * state->frame_size];
|
uint8_t buffer[1024 * 4];
|
||||||
memset(buffer, 0, silence * state->frame_size);
|
void *bufs[state->channels];
|
||||||
|
snd_pcm_uframes_t chunk, remaining = silence;
|
||||||
|
snd_pcm_uframes_t max = sizeof(buffer) / state->frame_size;
|
||||||
|
|
||||||
if (state->planar) {
|
memset(buffer, 0, sizeof(buffer));
|
||||||
void *bufs[state->channels];
|
for (i = 0; i < state->channels; i++)
|
||||||
for (i = 0; i < state->channels; i++)
|
bufs[i] = buffer;
|
||||||
bufs[i] = buffer;
|
|
||||||
snd_pcm_writen(hndl, bufs, silence);
|
while (remaining > 0) {
|
||||||
} else {
|
chunk = SPA_MIN(remaining, max);
|
||||||
snd_pcm_writei(hndl, buffer, silence);
|
if (state->planar)
|
||||||
|
snd_pcm_writen(hndl, bufs, chunk);
|
||||||
|
else
|
||||||
|
snd_pcm_writei(hndl, buffer, chunk);
|
||||||
|
remaining -= chunk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue