Skip to content

Commit dae5e8e

Browse files
cnderrauberdavidzhao
authored andcommitted
Skip padding packet for simulcast probe
Skip padding packet for simulcast probe Fix rtx attributes panic for nil map
1 parent c259e89 commit dae5e8e

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

peerconnection.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,7 +1588,7 @@ func (pc *PeerConnection) handleIncomingSSRC(rtpStream io.Reader, ssrc SSRC) err
15881588
}
15891589

15901590
var mid, rid, rsid string
1591-
payloadType, err := handleUnknownRTPPacket(b[:i], uint8(midExtensionID), uint8(streamIDExtensionID), uint8(repairStreamIDExtensionID), &mid, &rid, &rsid)
1591+
payloadType, paddingOnly, err := handleUnknownRTPPacket(b[:i], uint8(midExtensionID), uint8(streamIDExtensionID), uint8(repairStreamIDExtensionID), &mid, &rid, &rsid)
15921592
if err != nil {
15931593
return err
15941594
}
@@ -1606,12 +1606,17 @@ func (pc *PeerConnection) handleIncomingSSRC(rtpStream io.Reader, ssrc SSRC) err
16061606

16071607
for readCount := 0; readCount <= simulcastProbeCount; readCount++ {
16081608
if mid == "" || (rid == "" && rsid == "") {
1609+
// skip padding only packets for probing
1610+
if paddingOnly {
1611+
readCount--
1612+
}
1613+
16091614
i, _, err := interceptor.Read(b, nil)
16101615
if err != nil {
16111616
return err
16121617
}
16131618

1614-
if _, err = handleUnknownRTPPacket(b[:i], uint8(midExtensionID), uint8(streamIDExtensionID), uint8(repairStreamIDExtensionID), &mid, &rid, &rsid); err != nil {
1619+
if _, paddingOnly, err = handleUnknownRTPPacket(b[:i], uint8(midExtensionID), uint8(streamIDExtensionID), uint8(repairStreamIDExtensionID), &mid, &rid, &rsid); err != nil {
16151620
return err
16161621
}
16171622

peerconnection_media_test.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,28 @@ func TestPeerConnection_Simulcast(t *testing.T) {
12801280

12811281
assert.NoError(t, signalPair(pcOffer, pcAnswer))
12821282

1283-
for sequenceNumber := uint16(0); !ridsFullfilled(); sequenceNumber++ {
1283+
// padding only packets should not affect simulcast probe
1284+
var sequenceNumber uint16
1285+
for sequenceNumber = 0; sequenceNumber < simulcastProbeCount+10; sequenceNumber++ {
1286+
time.Sleep(20 * time.Millisecond)
1287+
1288+
for _, track := range []*TrackLocalStaticRTP{vp8WriterA, vp8WriterB, vp8WriterC} {
1289+
pkt := &rtp.Packet{
1290+
Header: rtp.Header{
1291+
Version: 2,
1292+
SequenceNumber: sequenceNumber,
1293+
PayloadType: 96,
1294+
Padding: true,
1295+
},
1296+
Payload: []byte{0x00, 0x02},
1297+
}
1298+
1299+
assert.NoError(t, track.WriteRTP(pkt))
1300+
}
1301+
}
1302+
assert.False(t, ridsFullfilled(), "Simulcast probe should not be fulfilled by padding only packets")
1303+
1304+
for ; !ridsFullfilled(); sequenceNumber++ {
12841305
time.Sleep(20 * time.Millisecond)
12851306

12861307
for _, track := range []*TrackLocalStaticRTP{vp8WriterA, vp8WriterB, vp8WriterC} {

rtpreceiver.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,9 @@ func (r *RTPReceiver) receiveForRtx(ssrc SSRC, rsid string, streamInfo *intercep
463463
continue
464464
}
465465

466+
if attributes == nil {
467+
attributes = make(interceptor.Attributes)
468+
}
466469
attributes.Set(AttributeRtxPayloadType, b[1]&0x7F)
467470
attributes.Set(AttributeRtxSequenceNumber, binary.BigEndian.Uint16(b[2:4]))
468471
attributes.Set(AttributeRtxSsrc, binary.BigEndian.Uint32(b[8:12]))

rtptransceiver.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,16 @@ func satisfyTypeAndDirection(remoteKind RTPCodecType, remoteDirection RTPTransce
266266

267267
// handleUnknownRTPPacket consumes a single RTP Packet and returns information that is helpful
268268
// for demuxing and handling an unknown SSRC (usually for Simulcast)
269-
func handleUnknownRTPPacket(buf []byte, midExtensionID, streamIDExtensionID, repairStreamIDExtensionID uint8, mid, rid, rsid *string) (payloadType PayloadType, err error) {
269+
func handleUnknownRTPPacket(buf []byte, midExtensionID, streamIDExtensionID, repairStreamIDExtensionID uint8, mid, rid, rsid *string) (payloadType PayloadType, paddingOnly bool, err error) {
270270
rp := &rtp.Packet{}
271271
if err = rp.Unmarshal(buf); err != nil {
272272
return
273273
}
274274

275+
if rp.Padding && len(rp.Payload) == 0 {
276+
paddingOnly = true
277+
}
278+
275279
if !rp.Header.Extension {
276280
return
277281
}

0 commit comments

Comments
 (0)