add dual track support for tm
This commit is contained in:
1 parent
d7b43786ca
commit
7f603bdb24
8 files changed
+302
-41
No files matched your search
@@ -36,11 +36,11 @@ type TelemostHeadlessJoiner struct {
|
||||
// joiner uses these to install /32 bypass routes before the
|
||||
// candidate is added to Pion's PeerConnection.
|
||||
OnRemoteCandidate func(target int, candidateOrSDP string)
|
||||
ResolveFn ResolveFunc
|
||||
Status StatusEmitter
|
||||
PCConfig PeerConnectionConfigurer
|
||||
AddTracks AddTunnelTracksFunc
|
||||
ReadTrackFn ReadTrackFunc
|
||||
ResolveFn ResolveFunc
|
||||
Status StatusEmitter
|
||||
PCConfig PeerConnectionConfigurer
|
||||
AddTracks AddTunnelTracksFunc
|
||||
ReadTrackFn ReadTrackFunc
|
||||
|
||||
joinLink string
|
||||
displayName string
|
||||
@@ -64,6 +64,7 @@ type TelemostHeadlessJoiner struct {
|
||||
vp8FPS int
|
||||
vp8Batch int
|
||||
reliable bool
|
||||
dualTrack bool
|
||||
|
||||
httpClient *http.Client
|
||||
instanceID string
|
||||
@@ -84,11 +85,13 @@ type TelemostHeadlessJoiner struct {
|
||||
configAck configAckTracker
|
||||
reconnectAttempt atomic.Int32
|
||||
|
||||
setSlotsKey int
|
||||
initBundleSent bool
|
||||
boundPeers map[string]bool
|
||||
unboundPeers map[string]bool
|
||||
boundMu sync.Mutex
|
||||
setSlotsKey int
|
||||
slotsMu sync.Mutex
|
||||
screenshareAsked bool
|
||||
initBundleSent bool
|
||||
boundPeers map[string]bool
|
||||
unboundPeers map[string]bool
|
||||
boundMu sync.Mutex
|
||||
}
|
||||
|
||||
func NewTelemostHeadlessJoiner(logFn func(string, ...any), resolveFn ResolveFunc, status StatusEmitter, pcConfig PeerConnectionConfigurer, addTracks AddTunnelTracksFunc, readTrackFn ReadTrackFunc) *TelemostHeadlessJoiner {
|
||||
@@ -111,6 +114,7 @@ func (j *TelemostHeadlessJoiner) RunWithParams(jsonParams string) {
|
||||
VP8FPS int `json:"vp8Fps"`
|
||||
VP8Batch int `json:"vp8Batch"`
|
||||
Reliable bool `json:"reliable"`
|
||||
DualTrack bool `json:"dualTrack"`
|
||||
}
|
||||
if err := json.Unmarshal([]byte(jsonParams), ¶ms); err != nil {
|
||||
j.logFn("telemost-joiner: failed to parse params: %v", err)
|
||||
@@ -132,8 +136,9 @@ func (j *TelemostHeadlessJoiner) RunWithParams(jsonParams string) {
|
||||
j.vp8FPS = params.VP8FPS
|
||||
j.vp8Batch = params.VP8Batch
|
||||
j.reliable = params.Reliable
|
||||
j.logFn("telemost-joiner: link=%s name=%s vp8Fps=%d vp8Batch=%d localEpoch=0x%08x",
|
||||
j.joinLink, j.displayName, params.VP8FPS, params.VP8Batch, obf.LocalEpoch())
|
||||
j.dualTrack = params.DualTrack
|
||||
j.logFn("telemost-joiner: link=%s name=%s vp8Fps=%d vp8Batch=%d dualTrack=%v localEpoch=0x%08x",
|
||||
j.joinLink, j.displayName, params.VP8FPS, params.VP8Batch, j.dualTrack, obf.LocalEpoch())
|
||||
|
||||
j.Status.EmitStatus(common.StatusConnecting)
|
||||
if err := j.runOnce(); err != nil {
|
||||
@@ -384,13 +389,13 @@ func (j *TelemostHeadlessJoiner) sendHello() {
|
||||
"hello": map[string]interface{}{
|
||||
"participantMeta": map[string]interface{}{"name": j.displayName, "role": "SPEAKER", "description": "", "sendAudio": false, "sendVideo": true},
|
||||
"participantAttributes": map[string]interface{}{"name": j.displayName, "role": "SPEAKER", "description": ""},
|
||||
"sendAudio": false, "sendVideo": true, "sendSharing": false,
|
||||
"sendAudio": false, "sendVideo": true, "sendSharing": false,
|
||||
"participantId": j.peerID, "roomId": j.roomID,
|
||||
"serviceName": j.serviceName, "credentials": j.credentials,
|
||||
"capabilitiesOffer": tmapi.CapabilitiesOffer,
|
||||
"capabilitiesOffer": tmapi.CapabilitiesOffer,
|
||||
"sdkInfo": map[string]interface{}{"implementation": "browser", "version": "6.0.0", "userAgent": common.UserAgent, "hwConcurrency": 8},
|
||||
"sdkInitializationId": uuid.New().String(),
|
||||
"disablePublisher": false, "disableSubscriber": false, "disableSubscriberAudio": false,
|
||||
"disablePublisher": false, "disableSubscriber": false, "disableSubscriberAudio": false,
|
||||
},
|
||||
})
|
||||
j.logFn("telemost-joiner: -> hello")
|
||||
@@ -489,9 +494,13 @@ func (j *TelemostHeadlessJoiner) initPC() {
|
||||
j.logFn("telemost-joiner: per-track kcp reliability active over video tunnel")
|
||||
}
|
||||
if !j.configAck.acknowledged() {
|
||||
trackCount := 1
|
||||
if j.dualTrack {
|
||||
trackCount = 2
|
||||
}
|
||||
acked, cancel := j.configAck.arm()
|
||||
go sendVP8ConfigUntilAcked(acked, cancel, j.stopCh, active,
|
||||
vp8tun.FPS(), vp8tun.Batch(), 1, j.logFn, "telemost-joiner")
|
||||
vp8tun.FPS(), vp8tun.Batch(), trackCount, j.logFn, "telemost-joiner")
|
||||
j.logFn("telemost-joiner: pushed vp8 config to creator fps=%d batch=%d", vp8tun.FPS(), vp8tun.Batch())
|
||||
}
|
||||
if j.OnConnected != nil {
|
||||
@@ -569,10 +578,29 @@ func (j *TelemostHeadlessJoiner) sendInitBundle() {
|
||||
j.sendStartupSlotsRamp()
|
||||
}
|
||||
|
||||
func (j *TelemostHeadlessJoiner) requestVideoSlots() {
|
||||
func (j *TelemostHeadlessJoiner) nextSlotsKey() int {
|
||||
j.slotsMu.Lock()
|
||||
defer j.slotsMu.Unlock()
|
||||
j.setSlotsKey++
|
||||
j.logFn("telemost-joiner: -> setSlots key=%d", j.setSlotsKey)
|
||||
j.wsSend(tmapi.SetSlotsMessage(j.setSlotsKey))
|
||||
return j.setSlotsKey
|
||||
}
|
||||
|
||||
func (j *TelemostHeadlessJoiner) requestVideoSlots() {
|
||||
key := j.nextSlotsKey()
|
||||
j.logFn("telemost-joiner: -> setSlots key=%d", key)
|
||||
j.wsSend(tmapi.SetSlotsMessage(key))
|
||||
}
|
||||
|
||||
func (j *TelemostHeadlessJoiner) pollScreenshareSlots() {
|
||||
for i := 0; i < 8; i++ {
|
||||
select {
|
||||
case <-j.stopCh:
|
||||
return
|
||||
case <-time.After(3 * time.Second):
|
||||
}
|
||||
j.logFn("telemost-joiner: -> setSlots re-request %d to bind screenshare", i+1)
|
||||
j.requestVideoSlots()
|
||||
}
|
||||
}
|
||||
|
||||
func (j *TelemostHeadlessJoiner) forceReconnect(reason string) {
|
||||
@@ -597,9 +625,12 @@ func (j *TelemostHeadlessJoiner) forceReconnect(reason string) {
|
||||
|
||||
func (j *TelemostHeadlessJoiner) sendStartupSlotsRamp() {
|
||||
for i := 0; i < 4; i++ {
|
||||
j.setSlotsKey++
|
||||
j.logFn("telemost-joiner: -> setSlots key=%d (startup %d/4)", j.setSlotsKey, i+1)
|
||||
j.wsSend(tmapi.StartupSetSlotsMessage(i, j.setSlotsKey))
|
||||
key := j.nextSlotsKey()
|
||||
j.logFn("telemost-joiner: -> setSlots key=%d (startup %d/4)", key, i+1)
|
||||
j.wsSend(tmapi.StartupSetSlotsMessage(i, key))
|
||||
}
|
||||
if j.dualTrack {
|
||||
go j.pollScreenshareSlots()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -763,6 +794,24 @@ func (j *TelemostHeadlessJoiner) handleMessage(raw []byte) {
|
||||
if common.Debug {
|
||||
j.logFn("telemost-joiner: <- slotsConfig %s", tmapi.BriefJSON(sc))
|
||||
}
|
||||
if j.dualTrack {
|
||||
unboundScreenshare := false
|
||||
for _, ev := range tmapi.ScreenShareBindings(sc) {
|
||||
pid := ev.ParticipantID
|
||||
if len(pid) > 8 {
|
||||
pid = pid[:8]
|
||||
}
|
||||
j.logFn("telemost-joiner: [screenshare] slot=%d pid=%s mid=%q reason=%q", ev.Slot, pid, ev.Mid, ev.Reason)
|
||||
if ev.Mid == "" {
|
||||
unboundScreenshare = true
|
||||
}
|
||||
}
|
||||
if unboundScreenshare && !j.screenshareAsked {
|
||||
j.screenshareAsked = true
|
||||
j.logFn("telemost-joiner: [screenshare] advertised with empty mid, re-requesting sized slots once")
|
||||
j.requestVideoSlots()
|
||||
}
|
||||
}
|
||||
needRebind := false
|
||||
presentPids := make(map[string]bool)
|
||||
for _, ev := range tmapi.SlotsConfigBindings(sc) {
|
||||
|
||||
@@ -167,6 +167,25 @@ func SlotsConfigBindings(v interface{}) []SlotBindEvent {
|
||||
return out
|
||||
}
|
||||
|
||||
func ScreenShareBindings(v interface{}) []SlotBindEvent {
|
||||
m, ok := v.(map[string]interface{})
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
slots, _ := m["slots"].([]interface{})
|
||||
var out []SlotBindEvent
|
||||
for idx, s := range slots {
|
||||
sm, _ := s.(map[string]interface{})
|
||||
if ss, _ := sm["participantScreenSharingByMid"].(map[string]interface{}); ss != nil {
|
||||
pid, _ := ss["participantId"].(string)
|
||||
mid, _ := ss["mid"].(string)
|
||||
reason, _ := ss["limitationReason"].(string)
|
||||
out = append(out, SlotBindEvent{Slot: idx, ParticipantID: pid, Mid: mid, Reason: reason})
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func BriefJSON(v interface{}) string {
|
||||
const max = 240
|
||||
b, err := json.Marshal(v)
|
||||
@@ -302,6 +321,40 @@ func SdkCodecsInfoMessage() map[string]interface{} {
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateMeMessage(name string, sendVideo, sendSharing bool) map[string]interface{} {
|
||||
meta := map[string]interface{}{
|
||||
"name": name, "description": "", "role": "SPEAKER",
|
||||
"sendAudio": false, "sendVideo": sendVideo,
|
||||
}
|
||||
return map[string]interface{}{
|
||||
"uid": uuid.New().String(),
|
||||
"updateMe": map[string]interface{}{
|
||||
"participantMeta": meta,
|
||||
"participantAttributes": map[string]interface{}{"name": name, "role": "SPEAKER", "description": ""},
|
||||
"sendAudio": false,
|
||||
"sendVideo": sendVideo,
|
||||
"sendSharing": sendSharing,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func DisplayVideoTrack(label string) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"kind": "DISPLAY_VIDEO", "label": label, "priority": 0, "dcLabel": "sharing", "mid": "",
|
||||
"codecs": map[string]interface{}{"96": map[string]interface{}{"channels": 0, "clockRate": 90000, "mimeType": "video/VP8", "sdpFmtpLine": ""}},
|
||||
"groupId": 2, "description": "",
|
||||
}
|
||||
}
|
||||
|
||||
func UpdatePublisherSharingTrackMessage(label string) map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"uid": uuid.New().String(),
|
||||
"updatePublisherTrackDescription": map[string]interface{}{
|
||||
"publisherTrackDescriptions": []map[string]interface{}{DisplayVideoTrack(label)},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func UpdatePublisherTrackDescriptionMessage(pc *webrtc.PeerConnection, audioLabel, videoLabel string) map[string]interface{} {
|
||||
descs := []map[string]interface{}{}
|
||||
for _, tr := range pc.GetTransceivers() {
|
||||
|
||||
@@ -18,7 +18,7 @@ const (
|
||||
// loses only its own frame, not a two-packet frame that readVP8Track
|
||||
// would discard whole. 1200 RTP budget - 1 VP8 descriptor - interframe
|
||||
// header - 24 XChaCha20 nonce - 16 Poly1305 tag - 1 channel tag.
|
||||
kcpSegmentMTU = 1200 - 1 - interframeHdrLen - 24 - 16 - 1
|
||||
kcpSegmentMTU = 1200 - 1 - interframeHdrLen - 24 - 16 - 1
|
||||
kcpReceiveBufSize = 128 * 1024
|
||||
kcpStatsEvery = 500
|
||||
|
||||
|
||||
@@ -50,6 +50,8 @@ type VP8DataTunnel struct {
|
||||
OnData func([]byte)
|
||||
OnClose func()
|
||||
OnPeerRestart func()
|
||||
|
||||
WriteFrame func([]byte) error
|
||||
}
|
||||
|
||||
func (t *VP8DataTunnel) SetOnData(fn func([]byte)) { t.OnData = fn }
|
||||
@@ -276,7 +278,14 @@ func (t *VP8DataTunnel) writerLoop() {
|
||||
if sample == nil {
|
||||
continue
|
||||
}
|
||||
if err := t.track.WriteSample(media.Sample{Data: sample, Duration: sampleInterval}); err != nil {
|
||||
if t.WriteFrame != nil {
|
||||
if err := t.WriteFrame(sample); err != nil {
|
||||
if common.Debug {
|
||||
t.logFn("vp8tunnel: WriteFrame error: %v", err)
|
||||
}
|
||||
continue
|
||||
}
|
||||
} else if err := t.track.WriteSample(media.Sample{Data: sample, Duration: sampleInterval}); err != nil {
|
||||
if common.Debug {
|
||||
t.logFn("vp8tunnel: WriteSample error: %v", err)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user