Skip to content

Commit

Permalink
Fix tests for simulcast rtx on v3
Browse files Browse the repository at this point in the history
  • Loading branch information
aalekseevx committed May 14, 2024
1 parent 7cad104 commit e029893
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
13 changes: 13 additions & 0 deletions interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,19 @@ func ConfigureTWCCSender(mediaEngine *MediaEngine, interceptorRegistry *intercep
return nil
}

// ConfigureSimulcastExtensionHeaders enables the RTP Extension Headers needed for Simulcast
func ConfigureSimulcastExtensionHeaders(mediaEngine *MediaEngine) error {
if err := mediaEngine.RegisterHeaderExtension(RTPHeaderExtensionCapability{URI: sdp.SDESMidURI}, RTPCodecTypeVideo); err != nil {
return err

Check warning on line 115 in interceptor.go

View check run for this annotation

Codecov / codecov/patch

interceptor.go#L115

Added line #L115 was not covered by tests
}

if err := mediaEngine.RegisterHeaderExtension(RTPHeaderExtensionCapability{URI: sdp.SDESRTPStreamIDURI}, RTPCodecTypeVideo); err != nil {
return err

Check warning on line 119 in interceptor.go

View check run for this annotation

Codecov / codecov/patch

interceptor.go#L119

Added line #L119 was not covered by tests
}

return mediaEngine.RegisterHeaderExtension(RTPHeaderExtensionCapability{URI: sdesRepairRTPStreamIDURI}, RTPCodecTypeVideo)
}

type interceptorToTrackLocalWriter struct{ interceptor atomic.Value } // interceptor.RTPWriter }

func (i *interceptorToTrackLocalWriter) WriteRTP(header *rtp.Header, payload []byte) (int, error) {
Expand Down
44 changes: 31 additions & 13 deletions peerconnection_media_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"
"time"

"github.com/pion/interceptor"
"github.com/pion/logging"
"github.com/pion/randutil"
"github.com/pion/rtcp"
Expand Down Expand Up @@ -1397,23 +1398,40 @@ func TestPeerConnection_Simulcast_RTX(t *testing.T) {
report := test.CheckRoutines(t)
defer report()

m := &MediaEngine{}
err := m.RegisterDefaultCodecs()
require.NoError(t, err)

i := &interceptor.Registry{}
err = RegisterDefaultInterceptors(m, i)
require.NoError(t, err)

err = ConfigureSimulcastExtensionHeaders(m)
require.NoError(t, err)

api := NewAPI(WithMediaEngine(m), WithInterceptorRegistry(i))

pcOffer, err := api.NewPeerConnection(Configuration{})
require.NoError(t, err)

pcAnswer, err := api.NewPeerConnection(Configuration{})
require.NoError(t, err)

rids := []string{"a", "b"}
pcOffer, pcAnswer, err := newPair()
assert.NoError(t, err)

vp8WriterAStatic, err := NewTrackLocalStaticRTP(RTPCodecCapability{MimeType: MimeTypeVP8}, "video", "pion2", WithRTPStreamID(rids[0]))
assert.NoError(t, err)
require.NoError(t, err)

vp8WriterBStatic, err := NewTrackLocalStaticRTP(RTPCodecCapability{MimeType: MimeTypeVP8}, "video", "pion2", WithRTPStreamID(rids[1]))
assert.NoError(t, err)
require.NoError(t, err)

vp8WriterA, vp8WriterB := &simulcastTestTrackLocal{vp8WriterAStatic}, &simulcastTestTrackLocal{vp8WriterBStatic}

sender, err := pcOffer.AddTrack(vp8WriterA)
assert.NoError(t, err)
assert.NotNil(t, sender)
require.NoError(t, err)
require.NotNil(t, sender)

assert.NoError(t, sender.AddEncoding(vp8WriterB))
require.NoError(t, sender.AddEncoding(vp8WriterB))

var ridMapLock sync.RWMutex
ridMap := map[string]int{}
Expand Down Expand Up @@ -1461,8 +1479,8 @@ func TestPeerConnection_Simulcast_RTX(t *testing.T) {
})

parameters := sender.GetParameters()
assert.Equal(t, "a", parameters.Encodings[0].RID)
assert.Equal(t, "b", parameters.Encodings[1].RID)
require.Equal(t, "a", parameters.Encodings[0].RID)
require.Equal(t, "b", parameters.Encodings[1].RID)

var midID, ridID, rsid uint8
for _, extension := range parameters.HeaderExtensions {
Expand All @@ -1475,17 +1493,17 @@ func TestPeerConnection_Simulcast_RTX(t *testing.T) {
rsid = uint8(extension.ID)
}
}
assert.NotZero(t, midID)
assert.NotZero(t, ridID)
assert.NotZero(t, rsid)
require.NotZero(t, midID)
require.NotZero(t, ridID)
require.NotZero(t, rsid)

err = signalPairWithModification(pcOffer, pcAnswer, func(sdp string) string {
// Original chrome sdp contains no ssrc info https://pastebin.com/raw/JTjX6zg6
re := regexp.MustCompile("(?m)[\r\n]+^.*a=ssrc.*$")
res := re.ReplaceAllString(sdp, "")
return res
})
assert.NoError(t, err)
require.NoError(t, err)

// padding only packets should not affect simulcast probe
var sequenceNumber uint16
Expand Down

0 comments on commit e029893

Please sign in to comment.