diff --git a/src/modules/module-rtp/audio.c b/src/modules/module-rtp/audio.c index 7adf0a5e9..4686c895f 100644 --- a/src/modules/module-rtp/audio.c +++ b/src/modules/module-rtp/audio.c @@ -361,7 +361,8 @@ static void rtp_audio_process_capture(void *data) pw_log_warn("expected %u != timestamp %u", expected_timestamp, timestamp); impl->have_sync = false; } else if (filled + wanted > (int32_t)SPA_MIN(impl->target_buffer * 8, BUFFER_SIZE / stride)) { - pw_log_warn("overrun %u + %u > %u", filled, wanted, BUFFER_SIZE / stride); + pw_log_warn("overrun %u + %u > %u/%u", filled, wanted, + impl->target_buffer * 8, BUFFER_SIZE / stride); impl->have_sync = false; filled = 0; } diff --git a/src/modules/module-rtp/midi.c b/src/modules/module-rtp/midi.c index d01414aff..6e243e83a 100644 --- a/src/modules/module-rtp/midi.c +++ b/src/modules/module-rtp/midi.c @@ -363,7 +363,7 @@ static void rtp_midi_flush_packets(struct impl *impl, struct rtp_header header; struct rtp_midi_header midi_header; struct iovec iov[3]; - uint32_t len, prev_offset, base; + uint32_t len, prev_offset, base, max_size; spa_zero(header); header.v = 2; @@ -380,6 +380,7 @@ static void rtp_midi_flush_packets(struct impl *impl, iov[2].iov_len = 0; prev_offset = len = base = 0; + max_size = impl->payload_size - sizeof(midi_header); SPA_POD_SEQUENCE_FOREACH(sequence, c) { uint32_t delta, offset; @@ -396,7 +397,7 @@ static void rtp_midi_flush_packets(struct impl *impl, offset = c->offset * impl->rate / rate; - if (len > 0 && (len + size > impl->mtu || + if (len > 0 && (len + size > max_size || offset - base > impl->psamples)) { /* flush packet when we have one and when it's either * too large or has too much data. */ diff --git a/src/modules/module-rtp/stream.c b/src/modules/module-rtp/stream.c index 5b0d08834..c2e7f651a 100644 --- a/src/modules/module-rtp/stream.c +++ b/src/modules/module-rtp/stream.c @@ -71,6 +71,7 @@ struct impl { uint32_t ts_offset; uint32_t psamples; uint32_t mtu; + uint32_t payload_size; struct spa_ringbuffer ring; uint8_t buffer[BUFFER_SIZE]; @@ -440,6 +441,11 @@ struct rtp_stream *rtp_stream_new(struct pw_core *core, impl->payload = pw_properties_get_uint32(props, "rtp.payload", impl->payload); impl->mtu = pw_properties_get_uint32(props, "net.mtu", DEFAULT_MTU); + if (impl->mtu <= PACKET_HEADER_SIZE) { + pw_log_error("invalid MTU %d, using %d", impl->mtu, DEFAULT_MTU); + impl->mtu = DEFAULT_MTU; + } + impl->payload_size = impl->mtu - PACKET_HEADER_SIZE; impl->seq = pw_rand32(); @@ -477,7 +483,7 @@ struct rtp_stream *rtp_stream_new(struct pw_core *core, pw_log_warn("rtp.ptime doesn't match rtp.framecount. Choosing rtp.ptime"); } } else { - impl->psamples = impl->mtu / impl->stride; + impl->psamples = impl->payload_size / impl->stride; impl->psamples = SPA_CLAMP(impl->psamples, min_samples, max_samples); if (direction == PW_DIRECTION_INPUT) { pw_properties_set(props, "rtp.ptime", diff --git a/src/modules/module-rtp/stream.h b/src/modules/module-rtp/stream.h index 0221b5f1e..e4c09edbc 100644 --- a/src/modules/module-rtp/stream.h +++ b/src/modules/module-rtp/stream.h @@ -19,6 +19,9 @@ struct rtp_stream; #define ERROR_MSEC 2.0f #define DEFAULT_SESS_LATENCY 100.0f +/* 28 bytes IP/UDP, 12 bytes RTP header */ +#define PACKET_HEADER_SIZE (12+28) + #define DEFAULT_MTU 1280 #define DEFAULT_MIN_PTIME 2.0f #define DEFAULT_MAX_PTIME 20.0f