Skip to content

Commit

Permalink
Skip padding packet for simulcast probe
Browse files Browse the repository at this point in the history
Skip padding packet for simulcast probe
Fix rtx attributes panic for nil map
  • Loading branch information
cnderrauber committed Feb 2, 2024
1 parent c259e89 commit 519c332
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
9 changes: 7 additions & 2 deletions peerconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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--
}

Check warning on line 1612 in peerconnection.go

View check run for this annotation

Codecov / codecov/patch

peerconnection.go#L1611-L1612

Added lines #L1611 - L1612 were not covered by tests

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
}

Expand Down
3 changes: 3 additions & 0 deletions rtpreceiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,9 @@ func (r *RTPReceiver) receiveForRtx(ssrc SSRC, rsid string, streamInfo *intercep
continue
}

if attributes == nil {
attributes = make(interceptor.Attributes)
}

Check warning on line 468 in rtpreceiver.go

View check run for this annotation

Codecov / codecov/patch

rtpreceiver.go#L466-L468

Added lines #L466 - L468 were not covered by tests
attributes.Set(AttributeRtxPayloadType, b[1]&0x7F)
attributes.Set(AttributeRtxSequenceNumber, binary.BigEndian.Uint16(b[2:4]))
attributes.Set(AttributeRtxSsrc, binary.BigEndian.Uint32(b[8:12]))
Expand Down
6 changes: 5 additions & 1 deletion rtptransceiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -289,5 +289,9 @@ func handleUnknownRTPPacket(buf []byte, midExtensionID, streamIDExtensionID, rep
*rsid = string(payload)
}

if rp.Padding && len(rp.Payload) == 0 {
paddingOnly = true
}

Check warning on line 294 in rtptransceiver.go

View check run for this annotation

Codecov / codecov/patch

rtptransceiver.go#L293-L294

Added lines #L293 - L294 were not covered by tests

return
}

0 comments on commit 519c332

Please sign in to comment.