module-rtp-sink: handle buffer offset and size correctly

This commit is contained in:
Wim Taymans 2023-02-02 16:08:40 +01:00
parent aed394cf89
commit 7e2dab876a

View file

@ -350,8 +350,8 @@ static void stream_process(void *data)
struct impl *impl = data; struct impl *impl = data;
struct pw_buffer *buf; struct pw_buffer *buf;
struct spa_data *d; struct spa_data *d;
uint32_t timestamp, expected_timestamp, stride; uint32_t offs, size, timestamp, expected_timestamp, stride;
int32_t filled, wanted; int32_t filled, wanted;
if ((buf = pw_stream_dequeue_buffer(impl->stream)) == NULL) { if ((buf = pw_stream_dequeue_buffer(impl->stream)) == NULL) {
pw_log_debug("Out of stream buffers: %m"); pw_log_debug("Out of stream buffers: %m");
@ -359,8 +359,10 @@ static void stream_process(void *data)
} }
d = buf->buffer->datas; d = buf->buffer->datas;
offs = SPA_MIN(d[0].chunk->offset, d[0].maxsize);
size = SPA_MIN(d[0].chunk->size, d[0].maxsize - offs);
stride = impl->stride; stride = impl->stride;
wanted = d[0].chunk->size / stride; wanted = size / stride;
filled = spa_ringbuffer_get_write_index(&impl->ring, &expected_timestamp); filled = spa_ringbuffer_get_write_index(&impl->ring, &expected_timestamp);
if (SPA_LIKELY(impl->io_position)) if (SPA_LIKELY(impl->io_position))
@ -372,7 +374,7 @@ static void stream_process(void *data)
if (expected_timestamp != timestamp) { if (expected_timestamp != timestamp) {
pw_log_warn("expected %u != timestamp %u", expected_timestamp, timestamp); pw_log_warn("expected %u != timestamp %u", expected_timestamp, timestamp);
impl->sync = false; impl->sync = false;
} else if ((filled + wanted) * stride > (int32_t)BUFFER_SIZE) { } else if (filled + wanted > (int32_t)(BUFFER_SIZE / stride)) {
pw_log_warn("overrun %u + %u > %u", filled, wanted, BUFFER_SIZE / stride); pw_log_warn("overrun %u + %u > %u", filled, wanted, BUFFER_SIZE / stride);
impl->sync = false; impl->sync = false;
} }
@ -387,7 +389,7 @@ static void stream_process(void *data)
impl->buffer, impl->buffer,
BUFFER_SIZE, BUFFER_SIZE,
(timestamp * stride) & BUFFER_MASK, (timestamp * stride) & BUFFER_MASK,
d[0].data, wanted * stride); SPA_PTROFF(d[0].data, offs, void), wanted * stride);
timestamp += wanted; timestamp += wanted;
spa_ringbuffer_write_update(&impl->ring, timestamp); spa_ringbuffer_write_update(&impl->ring, timestamp);