From 519c3322bb3d4ce6b0057bc36466a4131125e744 Mon Sep 17 00:00:00 2001 From: cnderrauber Date: Fri, 2 Feb 2024 09:36:40 +0800 Subject: [PATCH] Skip padding packet for simulcast probe Skip padding packet for simulcast probe Fix rtx attributes panic for nil map --- peerconnection.go | 9 +++++++-- rtpreceiver.go | 3 +++ rtptransceiver.go | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/peerconnection.go b/peerconnection.go index 379be7b9b2f..c7c92f99fb5 100644 --- a/peerconnection.go +++ b/peerconnection.go @@ -1588,7 +1588,7 @@ func (pc *PeerConnection) handleIncomingSSRC(rtpStream io.Reader, ssrc SSRC) err } var mid, rid, rsid string - payloadType, err := handleUnknownRTPPacket(b[:i], uint8(midExtensionID), uint8(streamIDExtensionID), uint8(repairStreamIDExtensionID), &mid, &rid, &rsid) + payloadType, paddingOnly, err := handleUnknownRTPPacket(b[:i], uint8(midExtensionID), uint8(streamIDExtensionID), uint8(repairStreamIDExtensionID), &mid, &rid, &rsid) if err != nil { return err } @@ -1606,12 +1606,17 @@ func (pc *PeerConnection) handleIncomingSSRC(rtpStream io.Reader, ssrc SSRC) err for readCount := 0; readCount <= simulcastProbeCount; readCount++ { if mid == "" || (rid == "" && rsid == "") { + // skip padding only packets for probing + if paddingOnly { + readCount-- + } + i, _, err := interceptor.Read(b, nil) if err != nil { return err } - if _, err = handleUnknownRTPPacket(b[:i], uint8(midExtensionID), uint8(streamIDExtensionID), uint8(repairStreamIDExtensionID), &mid, &rid, &rsid); err != nil { + if _, paddingOnly, err = handleUnknownRTPPacket(b[:i], uint8(midExtensionID), uint8(streamIDExtensionID), uint8(repairStreamIDExtensionID), &mid, &rid, &rsid); err != nil { return err } diff --git a/rtpreceiver.go b/rtpreceiver.go index f7d83d6fae5..2457ba080a8 100644 --- a/rtpreceiver.go +++ b/rtpreceiver.go @@ -463,6 +463,9 @@ func (r *RTPReceiver) receiveForRtx(ssrc SSRC, rsid string, streamInfo *intercep continue } + if attributes == nil { + attributes = make(interceptor.Attributes) + } attributes.Set(AttributeRtxPayloadType, b[1]&0x7F) attributes.Set(AttributeRtxSequenceNumber, binary.BigEndian.Uint16(b[2:4])) attributes.Set(AttributeRtxSsrc, binary.BigEndian.Uint32(b[8:12])) diff --git a/rtptransceiver.go b/rtptransceiver.go index 15d28f720d1..8c57bf40e8b 100644 --- a/rtptransceiver.go +++ b/rtptransceiver.go @@ -266,7 +266,7 @@ func satisfyTypeAndDirection(remoteKind RTPCodecType, remoteDirection RTPTransce // handleUnknownRTPPacket consumes a single RTP Packet and returns information that is helpful // for demuxing and handling an unknown SSRC (usually for Simulcast) -func handleUnknownRTPPacket(buf []byte, midExtensionID, streamIDExtensionID, repairStreamIDExtensionID uint8, mid, rid, rsid *string) (payloadType PayloadType, err error) { +func handleUnknownRTPPacket(buf []byte, midExtensionID, streamIDExtensionID, repairStreamIDExtensionID uint8, mid, rid, rsid *string) (payloadType PayloadType, paddingOnly bool, err error) { rp := &rtp.Packet{} if err = rp.Unmarshal(buf); err != nil { return @@ -289,5 +289,9 @@ func handleUnknownRTPPacket(buf []byte, midExtensionID, streamIDExtensionID, rep *rsid = string(payload) } + if rp.Padding && len(rp.Payload) == 0 { + paddingOnly = true + } + return }