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 = 1200which only applies to RTP video packets but anyway. - In mediasoup, for whatever reason, in
Consts.hppwe haveMtuSize = 1500. - The naming is terrible since an MTU is a property of the link and is measured including the IP header, while the
MtuSizeof mediasoup and thekVideoMtuof libwebrtc refer to the maximum packet sent over UDP or TCP (without taking into account UDP/TCP headers). - In
Consts.hppwe have:/** * 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
MtuSizeto somethig likeMaxPacketLengthand 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 }inConsts.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 replaceRTC::Consts::MtuSizewith a singleRTC::Consts::MaxPacketLength(value to be decided). - Today
RTC::Consts::MtuSizedoes not limit outgoing RTP size, it only feedsRtcpPacketMaxSize, theDirectTransportRTCP input check, one test and one fuzzer. - Today's
RtcpPacketMaxSizeis 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
MaxPacketLengthcounts 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
WebRtcTransportwe 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 againstMaxPacketLength, and a lower value only splits SR, SDES, RR and XR across more compound packets.RTC::Transport::SendRtcp()retriesGetRtcp()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
PipeConsumerwith N streams and a 255-byte CNAME needs about N x 304 bytes, so 4 streams (~1230 bytes) fit only ifMaxPacketLengthis above that, and a Producer needs about 20 encodings with RTX to hit the limit. RTC::Transportwould passMaxPacketLengthas the transport-cc feedback size limit toRTC::TransportCongestionControlServer(or the ongoingRTC::BWE::ReceiverTransportCongestionControl), and whenRTC::RTCP::FeedbackRtpTransportPacket::AddPacket()returnsMAX_SIZE_EXCEEDEDthe 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 aboveMtuSize + 100(1600 today), and it must be decided what that check becomes, since a lower limit changes API behavior.TestTransportCongestionControlServerpassesMtuSizeasmaxRtcpPacketLenandFuzzerRateCalculatoruses it as a random size, and both would switch toMaxPacketLength.- RTCP NACK from
RTC::RTP::RtpStreamRecvignores the RTCP size limit, is only checked againstSerializationBufferSize(65536) and can reach about 4 KB withMaxNackPackets= 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::MaxPacketLengthandProbationGenerator::ProbationPacketMaxLength= 1400, plus SRTP. - DTLS, SCTP, probing and NACK don't use
MtuSize, so they stay where they are unless they are also moved toMaxPacketLength.
Source: versatica/mediasoup