module-rtp: calculate payload_size based on MTU

The actual payload size depends on the MTU but should not include the
IP/UDP and RTP headers.

Fixes #4396
This commit is contained in:
Wim Taymans 2024-11-11 11:49:20 +01:00
parent 73b5a10021
commit a53bc035c0
4 changed files with 15 additions and 4 deletions

View file

@ -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;
}

View file

@ -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. */

View file

@ -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",

View file

@ -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