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:
@@ -722,6 +722,14 @@ func (d *DownTrack) MaxLayers() VideoLayers {
|
||||
return d.forwarder.MaxLayers()
|
||||
}
|
||||
|
||||
func (d *DownTrack) GetForwarderState() ForwarderState {
|
||||
return d.forwarder.GetState()
|
||||
}
|
||||
|
||||
func (d *DownTrack) SeedForwarderState(state ForwarderState) {
|
||||
d.forwarder.SeedState(state)
|
||||
}
|
||||
|
||||
func (d *DownTrack) GetForwardingStatus() ForwardingStatus {
|
||||
return d.forwarder.GetForwardingStatus()
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -36,6 +36,11 @@ type SnTs struct {
|
||||
timestamp uint32
|
||||
}
|
||||
|
||||
type RTPMungerState struct {
|
||||
LastSN uint16
|
||||
LastTS uint32
|
||||
}
|
||||
|
||||
type RTPMungerParams struct {
|
||||
highestIncomingSN uint16
|
||||
lastSN uint16
|
||||
@@ -75,6 +80,18 @@ func (r *RTPMunger) GetParams() RTPMungerParams {
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RTPMunger) GetLast() RTPMungerState {
|
||||
return RTPMungerState{
|
||||
LastSN: r.lastSN,
|
||||
LastTS: r.lastTS,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *RTPMunger) SeedLast(state RTPMungerState) {
|
||||
r.lastSN = state.LastSN
|
||||
r.lastTS = state.LastTS
|
||||
}
|
||||
|
||||
func (r *RTPMunger) SetLastSnTs(extPkt *buffer.ExtPacket) {
|
||||
r.highestIncomingSN = extPkt.Packet.SequenceNumber - 1
|
||||
r.lastSN = extPkt.Packet.SequenceNumber
|
||||
|
||||
@@ -15,6 +15,16 @@ type TranslationParamsVP8 struct {
|
||||
Header *buffer.VP8
|
||||
}
|
||||
|
||||
type VP8MungerState struct {
|
||||
ExtLastPictureId int32
|
||||
PictureIdUsed int
|
||||
LastTl0PicIdx uint8
|
||||
Tl0PicIdxUsed int
|
||||
TidUsed int
|
||||
LastKeyIdx uint8
|
||||
KeyIdxUsed int
|
||||
}
|
||||
|
||||
type VP8MungerParams struct {
|
||||
pictureIdWrapHandler VP8PictureIdWrapHandler
|
||||
extLastPictureId int32
|
||||
@@ -48,6 +58,28 @@ func NewVP8Munger(logger logger.Logger) *VP8Munger {
|
||||
}
|
||||
}
|
||||
|
||||
func (v *VP8Munger) GetLast() VP8MungerState {
|
||||
return VP8MungerState{
|
||||
ExtLastPictureId: v.extLastPictureId,
|
||||
PictureIdUsed: v.pictureIdUsed,
|
||||
LastTl0PicIdx: v.lastTl0PicIdx,
|
||||
Tl0PicIdxUsed: v.tl0PicIdxUsed,
|
||||
TidUsed: v.tidUsed,
|
||||
LastKeyIdx: v.lastKeyIdx,
|
||||
KeyIdxUsed: v.keyIdxUsed,
|
||||
}
|
||||
}
|
||||
|
||||
func (v *VP8Munger) SeedLast(state VP8MungerState) {
|
||||
v.extLastPictureId = state.ExtLastPictureId
|
||||
v.pictureIdUsed = state.PictureIdUsed
|
||||
v.lastTl0PicIdx = state.LastTl0PicIdx
|
||||
v.tl0PicIdxUsed = state.Tl0PicIdxUsed
|
||||
v.tidUsed = state.TidUsed
|
||||
v.lastKeyIdx = state.LastKeyIdx
|
||||
v.keyIdxUsed = state.KeyIdxUsed
|
||||
}
|
||||
|
||||
func (v *VP8Munger) SetLast(extPkt *buffer.ExtPacket) {
|
||||
vp8, ok := extPkt.Payload.(buffer.VP8)
|
||||
if !ok {
|
||||
|
||||
Reference in New Issue
Block a user