#1941·mediasoup

Reduce `MtuSize` from 1500 bytes to 1200 and rename it

Author: ibcCreated Sep 23, 2026Updated Sep 23, 2026
Labelsenhancement

Context

  • libwebrtc has a hardcoded MTU of 1200 bytes, meaning that it never sends packet bigger than 1200 bytes. Well, actually it doesn't have a limit for everything it sends. It has a kVideoMtu = 1200 which only applies to RTP video packets but anyway.
  • In mediasoup, for whatever reason, in Consts.hpp we have MtuSize = 1500.
  • The naming is terrible since an MTU is a property of the link and is measured including the IP header, while the MtuSize of mediasoup and the kVideoMtu of libwebrtc refer to the maximum packet sent over UDP or TCP (without taking into account UDP/TCP headers).
  • In Consts.hpp we have:
    cpp
    /**
     * Maximum size for a RTCP compound packet.
     * IPv4|Ipv6 header size (20|40 bytes). IPv6 considered.
     * UDP|TCP header size (8|20  bytes). TCP considered.
     * SRTP Encryption (148 bytes):
     *   - SRTP_MAX_TRAILER_LEN + 4 is the maximum number of octects that will
     *     be added to an RTCP packet by srtp_protect_rtcp().
     *   - srtp.h: SRTP_MAX_TRAILER_LEN (SRTP_MAX_TAG_LEN + SRTP_MAX_MKI_LEN).
     */
    constexpr size_t RtcpPacketMaxSize{ RTC::Consts::MtuSize - 40 - 20 - 148 };

TODO

  • We should rename MtuSize to somethig like MaxPacketLength and document is as the maximum message sent over UDP or TCP.
  • We must take into account that, when sending over TCP, and due to the 2 bytes framing defined in https://datatracker.ietf.org/doc/html/rfc4571, we need to prefix the packet with 2 extra bytes. See constexpr size_t TcpFramingSize{ 2 } in Consts.hpp.
  • We should assign a proper value to MaxPacketLength. 1200 seems correct because, as per discussions in libwebrtc forums/tracker, a higher value could not work everywhere.
  • We must verify if we are really limiting all generated packets (no matter they are RTP, SRTP, RTCP, DTLS, STUN, SCTP) to that max value.
  • Remove RTC::Consts::RtcpPacketMaxSize (MtuSize - 40 - 20 - 148) and replace RTC::Consts::MtuSize with a single RTC::Consts::MaxPacketLength (value to be decided).
  • Today RTC::Consts::MtuSize does not limit outgoing RTP size, it only feeds RtcpPacketMaxSize, the DirectTransport RTCP input check, one test and one fuzzer.
  • Today's RtcpPacketMaxSize is 1292 bytes, and its 148-byte SRTP allowance includes 128 bytes of MKI while real SRTCP overhead is about 20 bytes.
  • It must be decided whether MaxPacketLength counts the packet before SRTP or the UDP payload after it, since the RTCP limit is checked before SRTP is applied.
  • We must take into account that in WebRtcTransport we send SCTP over DTLS, however in other transports (PlainTransport, etc) we send SCTP directly over UDP/TCP.
  • RTC::RTCP::CompoundPacket::Add() (3 overloads) would compare against MaxPacketLength, and a lower value only splits SR, SDES, RR and XR across more compound packets.
  • RTC::Transport::SendRtcp() retries GetRtcp() on a fresh compound packet without checking the result, so a Consumer or Producer whose RTCP doesn't fit in an empty packet never sends SR/RR again, and the receiver loses A/V sync.
  • A PipeConsumer with N streams and a 255-byte CNAME needs about N x 304 bytes, so 4 streams (~1230 bytes) fit only if MaxPacketLength is above that, and a Producer needs about 20 encodings with RTX to hit the limit.
  • RTC::Transport would pass MaxPacketLength as the transport-cc feedback size limit to RTC::TransportCongestionControlServer (or the ongoing RTC::BWE::ReceiverTransportCongestionControl), and when RTC::RTCP::FeedbackRtpTransportPacket::AddPacket() returns MAX_SIZE_EXCEEDED the ongoing feedback is sent, a new one is started and the packet is added again, so a lower value only means more feedbacks.
  • RTC::DirectTransport::HandleNotification() rejects app-sent RTCP above MtuSize + 100 (1600 today), and it must be decided what that check becomes, since a lower limit changes API behavior.
  • TestTransportCongestionControlServer passes MtuSize as maxRtcpPacketLen and FuzzerRateCalculator uses it as a random size, and both would switch to MaxPacketLength.
  • RTCP NACK from RTC::RTP::RtpStreamRecv ignores the RTCP size limit, is only checked against SerializationBufferSize (65536) and can reach about 4 KB with MaxNackPackets = 1000 and gaps over 16.
  • DTLS uses its own DtlsMtu = 1350 with a memory BIO, so handshake datagrams can reach 1350 bytes of UDP payload, 1398 bytes total over IPv6, above the 1280 minimum.
  • SCTP uses its own MaxSafeMtuSizeForSctp = 1191, about 1228 bytes of UDP payload after DTLS.
  • BWE probing uses its own ProbePacketGenerator::MaxPacketLength and ProbationGenerator::ProbationPacketMaxLength = 1400, plus SRTP.
  • DTLS, SCTP, probing and NACK don't use MtuSize, so they stay where they are unless they are also moved to MaxPacketLength.