pulse-tunnel: Make sure we send available data

Round down the size and avail to the frame size to make sure we always
send aligned frames.

When we don't have the required size, set the buffer to 0 but still send
whatever we have in the ringbuffer or else it stays there until some
unknown time when it gets flushed out again with new data.
This commit is contained in:
Wim Taymans 2023-08-30 18:27:19 +02:00
parent f404168739
commit 3d0b662c5e

View file

@ -393,23 +393,26 @@ static void capture_stream_process(void *d)
req = 4096 * impl->frame_size;
size = SPA_MIN(bd->maxsize, req);
size = SPA_ROUND_DOWN(size, impl->frame_size);
avail = spa_ringbuffer_get_read_index(&impl->ring, &index);
if (avail < (int32_t)size) {
if (avail < (int32_t)size)
memset(bd->data, 0, size);
} else {
if (avail > (int32_t)RINGBUFFER_SIZE) {
avail = impl->target_buffer;
index += avail - impl->target_buffer;
} else {
update_rate(impl, avail / impl->frame_size);
}
if (avail > (int32_t)RINGBUFFER_SIZE) {
avail = impl->target_buffer;
index += avail - impl->target_buffer;
}
if (avail > 0) {
avail = SPA_ROUND_DOWN(avail, impl->frame_size);
update_rate(impl, avail / impl->frame_size);
avail = SPA_MIN(size, (uint32_t)avail);
spa_ringbuffer_read_data(&impl->ring,
impl->buffer, RINGBUFFER_SIZE,
index & RINGBUFFER_MASK,
bd->data, size);
bd->data, avail);
index += size;
index += avail;
spa_ringbuffer_read_update(&impl->ring, index);
}
bd->chunk->offset = 0;