From f1f5b8dafead8d5031416c6c2d6e206f0b857ac3 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Sun, 7 Feb 2021 23:06:16 -0800 Subject: [PATCH] use proper fix for using shared bufferFactory, remove resync hack --- go.mod | 2 +- go.sum | 2 ++ pkg/rtc/mediatrack.go | 1 + pkg/rtc/participant.go | 15 ---------- pkg/rtc/subscribedtrack.go | 8 ----- pkg/rtc/types/interfaces.go | 1 - .../types/typesfakes/fake_subscribed_track.go | 30 ------------------- 7 files changed, 4 insertions(+), 55 deletions(-) diff --git a/go.mod b/go.mod index cf89ca0b2..8009926bc 100644 --- a/go.mod +++ b/go.mod @@ -34,4 +34,4 @@ require ( gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 ) -replace github.com/pion/ion-sfu => github.com/pion/ion-sfu v1.8.4-0.20210205220645-c9ec7ad1db86 +replace github.com/pion/ion-sfu => github.com/davidzhao/ion-sfu v1.8.3-0.20210208065837-f6e01b2d7aeb diff --git a/go.sum b/go.sum index 6692af481..68c1766bd 100644 --- a/go.sum +++ b/go.sum @@ -73,6 +73,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davidzhao/ion-sfu v1.8.3-0.20210205220645-c9ec7ad1db86 h1:POGjEQ8fyEQn96DMXMG7xhvWxHjNRMQ5aoiRzQOzOdY= github.com/davidzhao/ion-sfu v1.8.3-0.20210205220645-c9ec7ad1db86/go.mod h1:MKDh4JSLpBA/hFeYAYALb6nYpe6Ruknd3pmxPMbdpM8= +github.com/davidzhao/ion-sfu v1.8.3-0.20210208065837-f6e01b2d7aeb h1:zrB9w2vGSzorwRYykHFMeMshWjMx/WU7J0T20Ta5WGo= +github.com/davidzhao/ion-sfu v1.8.3-0.20210208065837-f6e01b2d7aeb/go.mod h1:MKDh4JSLpBA/hFeYAYALb6nYpe6Ruknd3pmxPMbdpM8= github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f/go.mod h1:xH/i4TFMt8koVQZ6WFms69WAsDWr2XsYL3Hkl7jkoLE= github.com/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM= github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ= diff --git a/pkg/rtc/mediatrack.go b/pkg/rtc/mediatrack.go index 239e0de72..f6c8234b9 100644 --- a/pkg/rtc/mediatrack.go +++ b/pkg/rtc/mediatrack.go @@ -137,6 +137,7 @@ func (t *MediaTrack) AddSubscriber(sub types.Participant) error { if err != nil { return err } + downTrack.SetBufferFactory(bufferFactory) subTrack := NewSubscribedTrack(downTrack) transceiver, err := sub.PeerConnection().AddTransceiverFromTrack(downTrack, webrtc.RTPTransceiverInit{ diff --git a/pkg/rtc/participant.go b/pkg/rtc/participant.go index 5300e92ec..e814896c8 100644 --- a/pkg/rtc/participant.go +++ b/pkg/rtc/participant.go @@ -580,8 +580,6 @@ func (p *ParticipantImpl) onMediaTrack(track *webrtc.TrackRemote, rtpReceiver *w if newTrack { p.handleTrackPublished(mt) } - - p.resyncSubscriptions() } func (p *ParticipantImpl) onDataChannel(dc *webrtc.DataChannel) { @@ -646,7 +644,6 @@ func (p *ParticipantImpl) handleTrackPublished(track types.PublishedTrack) { p.onTrackUpdated(p, track) } track.OnClose(nil) - go p.resyncSubscriptions() }) if p.onTrackPublished != nil { @@ -654,18 +651,6 @@ func (p *ParticipantImpl) handleTrackPublished(track types.PublishedTrack) { } } -func (p *ParticipantImpl) resyncSubscriptions() { - // TODO: video tracks the current participant is subscribed to tends to freeze when the participant adds/removes tracks - // to get around this, we'll trigger a resync on all tracks it's subscribed to - p.lock.RLock() - defer p.lock.RUnlock() - for _, tracks := range p.subscribedTracks { - for _, subTrack := range tracks { - subTrack.Resync() - } - } -} - // downTracksRTCPWorker sends SenderReports periodically when the participant is subscribed to // other publishedTracks in the room. func (p *ParticipantImpl) downTracksRTCPWorker() { diff --git a/pkg/rtc/subscribedtrack.go b/pkg/rtc/subscribedtrack.go index c5eb1dbc9..775957bab 100644 --- a/pkg/rtc/subscribedtrack.go +++ b/pkg/rtc/subscribedtrack.go @@ -38,14 +38,6 @@ func (t *SubscribedTrack) SetPublisherMuted(muted bool) { t.updateDownTrackMute() } -// cause downtrack to resync and request a keyframe -// this is sort of a hack to prevent a subscriber from having tracks freeze on the client due to missing -// keyframes -func (t *SubscribedTrack) Resync() { - t.dt.Mute(true) - t.updateDownTrackMute() -} - func (t *SubscribedTrack) updateDownTrackMute() { muted := t.subMuted.Get() || t.pubMuted.Get() t.dt.Mute(muted) diff --git a/pkg/rtc/types/interfaces.go b/pkg/rtc/types/interfaces.go index e06b0e8b3..78ac021b3 100644 --- a/pkg/rtc/types/interfaces.go +++ b/pkg/rtc/types/interfaces.go @@ -109,7 +109,6 @@ type SubscribedTrack interface { IsMuted() bool SetMuted(muted bool) SetPublisherMuted(muted bool) - Resync() } // interface for properties of webrtc.TrackRemote diff --git a/pkg/rtc/types/typesfakes/fake_subscribed_track.go b/pkg/rtc/types/typesfakes/fake_subscribed_track.go index a4f0eaef8..004394a3d 100644 --- a/pkg/rtc/types/typesfakes/fake_subscribed_track.go +++ b/pkg/rtc/types/typesfakes/fake_subscribed_track.go @@ -29,10 +29,6 @@ type FakeSubscribedTrack struct { isMutedReturnsOnCall map[int]struct { result1 bool } - ResyncStub func() - resyncMutex sync.RWMutex - resyncArgsForCall []struct { - } SetMutedStub func(bool) setMutedMutex sync.RWMutex setMutedArgsForCall []struct { @@ -153,30 +149,6 @@ func (fake *FakeSubscribedTrack) IsMutedReturnsOnCall(i int, result1 bool) { }{result1} } -func (fake *FakeSubscribedTrack) Resync() { - fake.resyncMutex.Lock() - fake.resyncArgsForCall = append(fake.resyncArgsForCall, struct { - }{}) - stub := fake.ResyncStub - fake.recordInvocation("Resync", []interface{}{}) - fake.resyncMutex.Unlock() - if stub != nil { - fake.ResyncStub() - } -} - -func (fake *FakeSubscribedTrack) ResyncCallCount() int { - fake.resyncMutex.RLock() - defer fake.resyncMutex.RUnlock() - return len(fake.resyncArgsForCall) -} - -func (fake *FakeSubscribedTrack) ResyncCalls(stub func()) { - fake.resyncMutex.Lock() - defer fake.resyncMutex.Unlock() - fake.ResyncStub = stub -} - func (fake *FakeSubscribedTrack) SetMuted(arg1 bool) { fake.setMutedMutex.Lock() fake.setMutedArgsForCall = append(fake.setMutedArgsForCall, struct { @@ -248,8 +220,6 @@ func (fake *FakeSubscribedTrack) Invocations() map[string][][]interface{} { defer fake.downTrackMutex.RUnlock() fake.isMutedMutex.RLock() defer fake.isMutedMutex.RUnlock() - fake.resyncMutex.RLock() - defer fake.resyncMutex.RUnlock() fake.setMutedMutex.RLock() defer fake.setMutedMutex.RUnlock() fake.setPublisherMutedMutex.RLock()