Pass TrackInfo entirely to ensure fields aren't missing (#150)
This commit is contained in:
+19
-25
@@ -33,9 +33,7 @@ var (
|
|||||||
type MediaTrack struct {
|
type MediaTrack struct {
|
||||||
params MediaTrackParams
|
params MediaTrackParams
|
||||||
ssrc webrtc.SSRC
|
ssrc webrtc.SSRC
|
||||||
name string
|
|
||||||
streamID string
|
streamID string
|
||||||
kind livekit.TrackType
|
|
||||||
codec webrtc.RTPCodecParameters
|
codec webrtc.RTPCodecParameters
|
||||||
muted utils.AtomicFlag
|
muted utils.AtomicFlag
|
||||||
numUpTracks uint32
|
numUpTracks uint32
|
||||||
@@ -54,15 +52,13 @@ type MediaTrack struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type MediaTrackParams struct {
|
type MediaTrackParams struct {
|
||||||
TrackID string
|
TrackInfo *livekit.TrackInfo
|
||||||
ParticipantID string
|
ParticipantID string
|
||||||
RTCPChan chan []rtcp.Packet
|
RTCPChan chan []rtcp.Packet
|
||||||
BufferFactory *buffer.Factory
|
BufferFactory *buffer.Factory
|
||||||
ReceiverConfig ReceiverConfig
|
ReceiverConfig ReceiverConfig
|
||||||
AudioConfig config.AudioConfig
|
AudioConfig config.AudioConfig
|
||||||
Stats *stats.RoomStatsReporter
|
Stats *stats.RoomStatsReporter
|
||||||
Width uint32
|
|
||||||
Height uint32
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMediaTrack(track *webrtc.TrackRemote, params MediaTrackParams) *MediaTrack {
|
func NewMediaTrack(track *webrtc.TrackRemote, params MediaTrackParams) *MediaTrack {
|
||||||
@@ -70,11 +66,13 @@ func NewMediaTrack(track *webrtc.TrackRemote, params MediaTrackParams) *MediaTra
|
|||||||
params: params,
|
params: params,
|
||||||
ssrc: track.SSRC(),
|
ssrc: track.SSRC(),
|
||||||
streamID: track.StreamID(),
|
streamID: track.StreamID(),
|
||||||
kind: ToProtoTrackKind(track.Kind()),
|
|
||||||
codec: track.Codec(),
|
codec: track.Codec(),
|
||||||
subscribedTracks: make(map[string]*SubscribedTrack),
|
subscribedTracks: make(map[string]*SubscribedTrack),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if params.TrackInfo.Muted {
|
||||||
|
t.SetMuted(true)
|
||||||
|
}
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,15 +80,15 @@ func (t *MediaTrack) Start() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *MediaTrack) ID() string {
|
func (t *MediaTrack) ID() string {
|
||||||
return t.params.TrackID
|
return t.params.TrackInfo.Sid
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MediaTrack) Kind() livekit.TrackType {
|
func (t *MediaTrack) Kind() livekit.TrackType {
|
||||||
return t.kind
|
return t.params.TrackInfo.Type
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MediaTrack) Name() string {
|
func (t *MediaTrack) Name() string {
|
||||||
return t.name
|
return t.params.TrackInfo.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *MediaTrack) IsMuted() bool {
|
func (t *MediaTrack) IsMuted() bool {
|
||||||
@@ -220,7 +218,7 @@ func (t *MediaTrack) AddSubscriber(sub types.Participant) error {
|
|||||||
delete(t.subscribedTracks, sub.ID())
|
delete(t.subscribedTracks, sub.ID())
|
||||||
t.lock.Unlock()
|
t.lock.Unlock()
|
||||||
|
|
||||||
t.params.Stats.SubSubscribedTrack(t.kind.String())
|
t.params.Stats.SubSubscribedTrack(t.Kind().String())
|
||||||
|
|
||||||
// ignore if the subscribing sub is not connected
|
// ignore if the subscribing sub is not connected
|
||||||
if sub.SubscriberPC().ConnectionState() == webrtc.PeerConnectionStateClosed {
|
if sub.SubscriberPC().ConnectionState() == webrtc.PeerConnectionStateClosed {
|
||||||
@@ -233,7 +231,7 @@ func (t *MediaTrack) AddSubscriber(sub types.Participant) error {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
logger.Debugw("removing peerconnection track",
|
logger.Debugw("removing peerconnection track",
|
||||||
"track", t.params.TrackID,
|
"track", t.ID(),
|
||||||
"pIDs", []string{t.params.ParticipantID, sub.ID()},
|
"pIDs", []string{t.params.ParticipantID, sub.ID()},
|
||||||
"participant", sub.Identity(),
|
"participant", sub.Identity(),
|
||||||
)
|
)
|
||||||
@@ -263,7 +261,7 @@ func (t *MediaTrack) AddSubscriber(sub types.Participant) error {
|
|||||||
sub.Negotiate()
|
sub.Negotiate()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
t.params.Stats.AddSubscribedTrack(t.kind.String())
|
t.params.Stats.AddSubscribedTrack(t.Kind().String())
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -327,7 +325,7 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Tra
|
|||||||
onclose := t.onClose
|
onclose := t.onClose
|
||||||
t.lock.Unlock()
|
t.lock.Unlock()
|
||||||
t.RemoveAllSubscribers()
|
t.RemoveAllSubscribers()
|
||||||
t.params.Stats.SubPublishedTrack(t.kind.String())
|
t.params.Stats.SubPublishedTrack(t.Kind().String())
|
||||||
if onclose != nil {
|
if onclose != nil {
|
||||||
onclose()
|
onclose()
|
||||||
}
|
}
|
||||||
@@ -335,10 +333,11 @@ func (t *MediaTrack) AddReceiver(receiver *webrtc.RTPReceiver, track *webrtc.Tra
|
|||||||
t.receiver.OnFractionLostFB(func(lost uint8) {
|
t.receiver.OnFractionLostFB(func(lost uint8) {
|
||||||
buff.SetLastFractionLostReport(lost)
|
buff.SetLastFractionLostReport(lost)
|
||||||
})
|
})
|
||||||
t.params.Stats.AddPublishedTrack(t.kind.String())
|
t.params.Stats.AddPublishedTrack(t.Kind().String())
|
||||||
}
|
}
|
||||||
t.receiver.AddUpTrack(track, buff, t.shouldStartWithBestQuality())
|
t.receiver.AddUpTrack(track, buff, t.shouldStartWithBestQuality())
|
||||||
// when RID is set, track is simulcasted
|
// when RID is set, track is simulcasted
|
||||||
|
// TODO: how does this work with FF, SSRC based simulcast?
|
||||||
t.simulcasted = track.RID() != ""
|
t.simulcasted = track.RID() != ""
|
||||||
atomic.AddUint32(&t.numUpTracks, 1)
|
atomic.AddUint32(&t.numUpTracks, 1)
|
||||||
|
|
||||||
@@ -359,7 +358,7 @@ func (t *MediaTrack) RemoveSubscriber(participantId string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *MediaTrack) RemoveAllSubscribers() {
|
func (t *MediaTrack) RemoveAllSubscribers() {
|
||||||
logger.Debugw("removing all subscribers", "track", t.params.TrackID)
|
logger.Debugw("removing all subscribers", "track", t.ID())
|
||||||
t.lock.Lock()
|
t.lock.Lock()
|
||||||
defer t.lock.Unlock()
|
defer t.lock.Unlock()
|
||||||
for _, subTrack := range t.subscribedTracks {
|
for _, subTrack := range t.subscribedTracks {
|
||||||
@@ -369,15 +368,10 @@ func (t *MediaTrack) RemoveAllSubscribers() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *MediaTrack) ToProto() *livekit.TrackInfo {
|
func (t *MediaTrack) ToProto() *livekit.TrackInfo {
|
||||||
return &livekit.TrackInfo{
|
info := t.params.TrackInfo
|
||||||
Sid: t.ID(),
|
info.Muted = t.IsMuted()
|
||||||
Type: t.Kind(),
|
info.Simulcast = t.simulcasted
|
||||||
Name: t.Name(),
|
return info
|
||||||
Muted: t.IsMuted(),
|
|
||||||
Width: t.params.Width,
|
|
||||||
Height: t.params.Height,
|
|
||||||
Simulcast: t.simulcasted,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// this function assumes caller holds lock
|
// this function assumes caller holds lock
|
||||||
@@ -430,7 +424,7 @@ func (t *MediaTrack) DebugInfo() map[string]interface{} {
|
|||||||
info := map[string]interface{}{
|
info := map[string]interface{}{
|
||||||
"ID": t.ID(),
|
"ID": t.ID(),
|
||||||
"SSRC": t.ssrc,
|
"SSRC": t.ssrc,
|
||||||
"Kind": t.kind.String(),
|
"Kind": t.Kind().String(),
|
||||||
"PubMuted": t.muted.Get(),
|
"PubMuted": t.muted.Get(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
package rtc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
livekit "github.com/livekit/protocol/proto"
|
||||||
|
"github.com/pion/webrtc/v3"
|
||||||
|
"github.com/stretchr/testify/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTrackInfo(t *testing.T) {
|
||||||
|
// ensures that persisted trackinfo is being returned
|
||||||
|
ti := livekit.TrackInfo{
|
||||||
|
Sid: "testsid",
|
||||||
|
Name: "testtrack",
|
||||||
|
Source: livekit.TrackSource_SCREEN_SHARE,
|
||||||
|
Type: livekit.TrackType_VIDEO,
|
||||||
|
Simulcast: false,
|
||||||
|
Width: 100,
|
||||||
|
Height: 80,
|
||||||
|
Muted: true,
|
||||||
|
}
|
||||||
|
|
||||||
|
ti2 := ti
|
||||||
|
mt := NewMediaTrack(&webrtc.TrackRemote{}, MediaTrackParams{
|
||||||
|
TrackInfo: &ti2,
|
||||||
|
})
|
||||||
|
outInfo := mt.ToProto()
|
||||||
|
require.Equal(t, ti.Muted, outInfo.Muted)
|
||||||
|
require.Equal(t, ti.Name, outInfo.Name)
|
||||||
|
require.Equal(t, ti.Name, mt.Name())
|
||||||
|
require.Equal(t, ti.Sid, mt.ID())
|
||||||
|
require.Equal(t, ti.Type, outInfo.Type)
|
||||||
|
require.Equal(t, ti.Type, mt.Kind())
|
||||||
|
require.Equal(t, ti.Source, outInfo.Source)
|
||||||
|
require.Equal(t, ti.Width, outInfo.Width)
|
||||||
|
require.Equal(t, ti.Height, outInfo.Height)
|
||||||
|
require.Equal(t, ti.Simulcast, outInfo.Simulcast)
|
||||||
|
|
||||||
|
// make it simulcasted
|
||||||
|
mt.simulcasted = true
|
||||||
|
require.True(t, mt.ToProto().Simulcast)
|
||||||
|
}
|
||||||
@@ -833,18 +833,14 @@ func (p *ParticipantImpl) onMediaTrack(track *webrtc.TrackRemote, rtpReceiver *w
|
|||||||
mt = trk
|
mt = trk
|
||||||
} else {
|
} else {
|
||||||
mt = NewMediaTrack(track, MediaTrackParams{
|
mt = NewMediaTrack(track, MediaTrackParams{
|
||||||
TrackID: ti.Sid,
|
TrackInfo: ti,
|
||||||
ParticipantID: p.id,
|
ParticipantID: p.id,
|
||||||
RTCPChan: p.rtcpCh,
|
RTCPChan: p.rtcpCh,
|
||||||
BufferFactory: p.params.Config.BufferFactory,
|
BufferFactory: p.params.Config.BufferFactory,
|
||||||
ReceiverConfig: p.params.Config.Receiver,
|
ReceiverConfig: p.params.Config.Receiver,
|
||||||
AudioConfig: p.params.AudioConfig,
|
AudioConfig: p.params.AudioConfig,
|
||||||
Stats: p.params.Stats,
|
Stats: p.params.Stats,
|
||||||
Width: ti.Width,
|
|
||||||
Height: ti.Height,
|
|
||||||
})
|
})
|
||||||
mt.name = ti.Name
|
|
||||||
mt.SetMuted(ti.Muted)
|
|
||||||
newTrack = true
|
newTrack = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user