mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-10-31 22:25:38 -04:00
alsa-plugin: clip offset and size in capture
Be a bit more careful with the offset and size in the buffer and make sure we clip them according to the maxsize.
This commit is contained in:
parent
6dab305407
commit
e75282d0f5
1 changed files with 17 additions and 11 deletions
|
|
@ -252,26 +252,30 @@ snd_pcm_pipewire_process(snd_pcm_pipewire_t *pw, struct pw_buffer *b,
|
||||||
unsigned int channel;
|
unsigned int channel;
|
||||||
struct spa_data *d;
|
struct spa_data *d;
|
||||||
void *ptr;
|
void *ptr;
|
||||||
|
uint32_t bl, offset, size;
|
||||||
|
|
||||||
d = b->buffer->datas;
|
d = b->buffer->datas;
|
||||||
pwareas = alloca(io->channels * sizeof(snd_pcm_channel_area_t));
|
pwareas = alloca(io->channels * sizeof(snd_pcm_channel_area_t));
|
||||||
|
|
||||||
if (io->stream == SND_PCM_STREAM_PLAYBACK) {
|
for (bl = 0; bl < pw->blocks; bl++) {
|
||||||
nframes = d[0].maxsize - SPA_MIN(d[0].maxsize, d[0].chunk->offset);
|
if (io->stream == SND_PCM_STREAM_PLAYBACK) {
|
||||||
nframes /= pw->stride;
|
size = SPA_MIN(d[bl].maxsize, pw->min_avail * pw->stride);
|
||||||
nframes = SPA_MIN(nframes, pw->min_avail);
|
} else {
|
||||||
} else {
|
offset = SPA_MIN(d[bl].chunk->offset, d[bl].maxsize);
|
||||||
nframes = d[0].chunk->size / pw->stride;
|
size = SPA_MIN(d[bl].chunk->size, d[bl].maxsize - offset);
|
||||||
|
}
|
||||||
|
want = SPA_MIN(want, size / pw->stride);
|
||||||
}
|
}
|
||||||
want = SPA_MIN(nframes, want);
|
|
||||||
nframes = SPA_MIN(want, *hw_avail);
|
nframes = SPA_MIN(want, *hw_avail);
|
||||||
|
|
||||||
if (pw->blocks == 1) {
|
if (pw->blocks == 1) {
|
||||||
if (io->stream == SND_PCM_STREAM_PLAYBACK) {
|
if (io->stream == SND_PCM_STREAM_PLAYBACK) {
|
||||||
d[0].chunk->size = want * pw->stride;
|
d[0].chunk->size = want * pw->stride;
|
||||||
d[0].chunk->offset = 0;
|
d[0].chunk->offset = offset = 0;
|
||||||
|
} else {
|
||||||
|
offset = SPA_MIN(d[0].chunk->offset, d[0].maxsize);
|
||||||
}
|
}
|
||||||
ptr = SPA_PTROFF(d[0].data, d[0].chunk->offset, void);
|
ptr = SPA_PTROFF(d[0].data, offset, void);
|
||||||
for (channel = 0; channel < io->channels; channel++) {
|
for (channel = 0; channel < io->channels; channel++) {
|
||||||
pwareas[channel].addr = ptr;
|
pwareas[channel].addr = ptr;
|
||||||
pwareas[channel].first = channel * pw->sample_bits;
|
pwareas[channel].first = channel * pw->sample_bits;
|
||||||
|
|
@ -281,9 +285,11 @@ snd_pcm_pipewire_process(snd_pcm_pipewire_t *pw, struct pw_buffer *b,
|
||||||
for (channel = 0; channel < io->channels; channel++) {
|
for (channel = 0; channel < io->channels; channel++) {
|
||||||
if (io->stream == SND_PCM_STREAM_PLAYBACK) {
|
if (io->stream == SND_PCM_STREAM_PLAYBACK) {
|
||||||
d[channel].chunk->size = want * pw->stride;
|
d[channel].chunk->size = want * pw->stride;
|
||||||
d[channel].chunk->offset = 0;
|
d[channel].chunk->offset = offset = 0;
|
||||||
|
} else {
|
||||||
|
offset = SPA_MIN(d[channel].chunk->offset, d[channel].maxsize);
|
||||||
}
|
}
|
||||||
ptr = SPA_PTROFF(d[channel].data, d[channel].chunk->offset, void);
|
ptr = SPA_PTROFF(d[channel].data, offset, void);
|
||||||
pwareas[channel].addr = ptr;
|
pwareas[channel].addr = ptr;
|
||||||
pwareas[channel].first = 0;
|
pwareas[channel].first = 0;
|
||||||
pwareas[channel].step = pw->sample_bits;
|
pwareas[channel].step = pw->sample_bits;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue