protocol to synchronize published tracks

This commit is contained in:
David Zhao
2020-12-05 00:03:26 -08:00
parent 0dcfffb9d8
commit abd17af4d4
5 changed files with 81 additions and 40 deletions
+21
View File
@@ -9,6 +9,7 @@ import (
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/livekit-server/pkg/utils"
"github.com/livekit/livekit-server/proto/livekit"
)
var (
@@ -57,6 +58,10 @@ func (t *Track) Start() {
go t.forwardWorker()
}
func (t *Track) Kind() webrtc.RTPCodecType {
return t.mediaTrack.Kind()
}
// subscribes participant to current mediaTrack
// creates and add necessary forwarders and starts them
func (t *Track) AddSubscriber(participant *Participant) error {
@@ -125,6 +130,22 @@ func (t *Track) RemoveAllSubscribers() {
}
}
func (t *Track) ToProto() *livekit.TrackInfo {
var kind livekit.TrackInfo_Type
switch t.Kind() {
case webrtc.RTPCodecTypeAudio:
kind = livekit.TrackInfo_AUDIO
case webrtc.RTPCodecTypeVideo:
kind = livekit.TrackInfo_VIDEO
}
return &livekit.TrackInfo{
Sid: t.id,
Type: kind,
Name: t.mediaTrack.Label(),
}
}
// forwardWorker reads from the receiver and writes to each sender
func (t *Track) forwardWorker() {
for pkt := range t.receiver.RTPChan() {