Pass along mime type with TrackInfo (#292)

This commit is contained in:
David Zhao
2021-12-27 23:43:30 -08:00
committed by GitHub
parent 87a799bae2
commit b747cdb822
3 changed files with 27 additions and 18 deletions
+2
View File
@@ -328,6 +328,8 @@ func (u *UptrackManager) MediaTrackReceived(track *webrtc.TrackRemote, rtpReceiv
return
}
ti.MimeType = track.Codec().MimeType
mt = NewMediaTrack(track, MediaTrackParams{
TrackInfo: ti,
SignalCid: signalCid,
+10 -4
View File
@@ -306,14 +306,14 @@ func (c *RTCClient) Run() error {
return err
}
case *livekit.SignalResponse_Update:
participants := make(map[string]*livekit.ParticipantInfo)
c.lock.Lock()
for _, p := range msg.Update.Participants {
if p.State != livekit.ParticipantInfo_DISCONNECTED {
participants[p.Sid] = p
c.remoteParticipants[p.Sid] = p
} else {
delete(c.remoteParticipants, p.Sid)
}
}
c.lock.Lock()
c.remoteParticipants = participants
c.lock.Unlock()
case *livekit.SignalResponse_TrackPublished:
@@ -389,6 +389,12 @@ func (c *RTCClient) RemoteParticipants() []*livekit.ParticipantInfo {
return funk.Values(c.remoteParticipants).([]*livekit.ParticipantInfo)
}
func (c *RTCClient) GetRemoteParticipant(sid string) *livekit.ParticipantInfo {
c.lock.Lock()
defer c.lock.Unlock()
return c.remoteParticipants[sid]
}
func (c *RTCClient) Stop() {
logger.Infow("stopping client", "ID", c.ID())
_ = c.SendRequest(&livekit.SignalRequest{
+15 -14
View File
@@ -6,13 +6,14 @@ import (
"testing"
"time"
"github.com/livekit/protocol/auth"
"github.com/pion/webrtc/v3"
"github.com/stretchr/testify/require"
"github.com/livekit/livekit-server/pkg/rtc"
"github.com/livekit/livekit-server/pkg/testutils"
testclient "github.com/livekit/livekit-server/test/client"
"github.com/livekit/protocol/auth"
"github.com/livekit/protocol/livekit"
"github.com/pion/webrtc/v3"
"github.com/stretchr/testify/require"
"github.com/thoas/go-funk"
)
func TestClientCouldConnect(t *testing.T) {
@@ -124,14 +125,14 @@ func TestSinglePublisher(t *testing.T) {
waitUntilConnected(t, c1, c2)
// publish a track and ensure clients receive it ok
t1, err := c1.AddStaticTrack("audio/opus", "audio", "webcam")
t1, err := c1.AddStaticTrack("audio/opus", "audio", "webcamaudio")
require.NoError(t, err)
defer t1.Stop()
t2, err := c1.AddStaticTrack("video/vp8", "video", "webcam")
t2, err := c1.AddStaticTrack("video/vp8", "video", "webcamvideo")
require.NoError(t, err)
defer t2.Stop()
success := testutils.WithTimeout(t, "c2 should receive two tracks", func() bool {
testutils.WithTimeout(t, "c2 should receive two tracks", func() bool {
if len(c2.SubscribedTracks()) == 0 {
return false
}
@@ -145,16 +146,19 @@ func TestSinglePublisher(t *testing.T) {
require.Equal(t, c1.ID(), participantId)
return true
})
if !success {
t.FailNow()
}
// ensure mime type is received
remoteC1 := c2.GetRemoteParticipant(c1.ID())
audioTrack := funk.Find(remoteC1.Tracks, func(ti *livekit.TrackInfo) bool {
return ti.Name == "webcamaudio"
}).(*livekit.TrackInfo)
require.Equal(t, "audio/opus", audioTrack.MimeType)
// a new client joins and should get the initial stream
c3 := createRTCClient("c3", defaultServerPort, nil)
// ensure that new client that has joined also received tracks
waitUntilConnected(t, c3)
success = testutils.WithTimeout(t, "c3 should receive two tracks", func() bool {
testutils.WithTimeout(t, "c3 should receive two tracks", func() bool {
if len(c3.SubscribedTracks()) == 0 {
return false
}
@@ -164,9 +168,6 @@ func TestSinglePublisher(t *testing.T) {
}
return true
})
if !success {
t.FailNow()
}
// ensure that the track ids are generated by server
tracks := c3.SubscribedTracks()[c1.ID()]