Cache and restore forwarder state on resume (#786)

* WIP commit

* Clean up

* spelling mistake

* Run subscribed track onBind in a go routine

* Address comments and more safety net

* Cache and restore forwarder state on resume

* conflicts

* mage generate
This commit is contained in:
Raja Subramanian
2022-06-24 22:02:03 +05:30
committed by GitHub
parent 407996702b
commit 46bce33fb8
8 changed files with 236 additions and 112 deletions
+40
View File
@@ -163,6 +163,14 @@ var (
// -------------------------------------------------------------------
type ForwarderState struct {
LastTSCalc int64
RTP RTPMungerState
VP8 VP8MungerState
}
// -------------------------------------------------------------------
type Forwarder struct {
lock sync.RWMutex
codec webrtc.RTPCodecCapability
@@ -217,6 +225,9 @@ func NewForwarder(kind webrtc.RTPCodecType, logger logger.Logger) *Forwarder {
}
func (f *Forwarder) DetermineCodec(codec webrtc.RTPCodecCapability) {
f.lock.Lock()
defer f.lock.Unlock()
if f.codec.MimeType != "" {
return
}
@@ -233,6 +244,35 @@ func (f *Forwarder) DetermineCodec(codec webrtc.RTPCodecCapability) {
}
}
func (f *Forwarder) GetState() ForwarderState {
f.lock.RLock()
defer f.lock.RUnlock()
state := ForwarderState{
LastTSCalc: f.lTSCalc,
RTP: f.rtpMunger.GetLast(),
}
if f.vp8Munger != nil {
state.VP8 = f.vp8Munger.GetLast()
}
return state
}
func (f *Forwarder) SeedState(state ForwarderState) {
f.lock.Lock()
defer f.lock.Unlock()
f.lTSCalc = state.LastTSCalc
f.rtpMunger.SeedLast(state.RTP)
if f.vp8Munger != nil {
f.vp8Munger.SeedLast(state.VP8)
}
f.started = true
}
func (f *Forwarder) Mute(val bool) (bool, VideoLayers) {
f.lock.Lock()
defer f.lock.Unlock()