Don't wait rtp packet to fire track (#3246)

* Don't wait rtp packet to fire track

Create track from sdp instead of first rtp packet,
it is consistent with the browser behavior and
will accelerate the track publication.

* fix test
This commit is contained in:
cnderrauber
2024-12-13 15:06:14 +08:00
committed by GitHub
parent 789d0484e2
commit 5dd6858acf
9 changed files with 174 additions and 24 deletions
+50
View File
@@ -706,3 +706,53 @@ func TestSubscribeToCodecUnsupported(t *testing.T) {
})
require.Nil(t, c2.GetSubscriptionResponseAndClear())
}
func TestFireTrackBySdp(t *testing.T) {
_, finish := setupSingleNodeTest("TestFireTrackBySdp")
defer finish()
c1 := createRTCClient("c1", defaultServerPort, &testclient.Options{
ClientInfo: &livekit.ClientInfo{
Sdk: livekit.ClientInfo_JS,
},
})
c2 := createRTCClient("c2", defaultServerPort, &testclient.Options{
AutoSubscribe: true,
ClientInfo: &livekit.ClientInfo{
Sdk: livekit.ClientInfo_JS,
},
})
waitUntilConnected(t, c1, c2)
defer func() {
c1.Stop()
c2.Stop()
}()
codecs := []webrtc.RTPCodecCapability{
{MimeType: "video/H264"},
{MimeType: "audio/opus"},
}
// publish tracks and don't write any packets
for _, codec := range codecs {
_, err := c1.AddStaticTrackWithCodec(codec, codec.MimeType, codec.MimeType, testclient.AddTrackNoWriter())
require.NoError(t, err)
}
require.Eventually(t, func() bool {
return len(c2.SubscribedTracks()[c1.ID()]) == 2
}, 5*time.Second, 10*time.Millisecond)
var found int
for _, pubTrack := range c1.GetPublishedTrackIDs() {
t.Log("pub track", pubTrack)
tracks := c2.SubscribedTracks()[c1.ID()]
for _, track := range tracks {
t.Log("sub track", track.ID(), track.Codec())
if track.Codec().PayloadType == 0 && track.ID() == pubTrack {
found++
break
}
}
}
require.Equal(t, 2, found)
}