add support for av1 svc (#669)

* add support for av1 svc
This commit is contained in:
cnderrauber
2022-05-06 18:24:29 +08:00
committed by GitHub
parent 7f38164ef6
commit 07b93e2e5b
20 changed files with 2107 additions and 243 deletions
+122 -108
View File
@@ -11,6 +11,7 @@ import (
"github.com/livekit/protocol/logger"
"github.com/livekit/livekit-server/pkg/sfu/buffer"
dd "github.com/livekit/livekit-server/pkg/sfu/dependencydescriptor"
)
//
@@ -135,46 +136,28 @@ type TranslationParams struct {
isSwitchingToMaxLayer bool
rtp *TranslationParamsRTP
vp8 *TranslationParamsVP8
ddExtension *dd.DependencyDescriptorExtension
marker bool
// indicates this frame has 'Switch' decode indication for target layer
// TODO : in theory, we need check frame chain is not broken for the target
// but we don't have frame queue now, so just use decode target indication
switchingToTargetLayer bool
}
// -------------------------------------------------------------------
type VideoLayers struct {
spatial int32
temporal int32
}
func (v VideoLayers) String() string {
return fmt.Sprintf("VideoLayers{s: %d, t: %d}", v.spatial, v.temporal)
}
func (v VideoLayers) GreaterThan(v2 VideoLayers) bool {
return v.spatial > v2.spatial || (v.spatial == v2.spatial && v.temporal > v2.temporal)
}
func (v VideoLayers) SpatialGreaterThanOrEqual(v2 VideoLayers) bool {
return v.spatial >= v2.spatial
}
func (v VideoLayers) IsValid() bool {
return v.spatial != InvalidLayerSpatial && v.temporal != InvalidLayerTemporal
}
// -------------------------------------------------------------------
type VideoLayers = buffer.VideoLayer
const (
InvalidLayerSpatial = int32(-1)
InvalidLayerTemporal = int32(-1)
InvalidLayerSpatial = buffer.InvalidLayerSpatial
InvalidLayerTemporal = buffer.InvalidLayerTemporal
DefaultMaxLayerSpatial = int32(2)
DefaultMaxLayerTemporal = int32(3)
DefaultMaxLayerSpatial = buffer.DefaultMaxLayerSpatial
DefaultMaxLayerTemporal = buffer.DefaultMaxLayerTemporal
)
var (
InvalidLayers = VideoLayers{
spatial: InvalidLayerSpatial,
temporal: InvalidLayerTemporal,
}
InvalidLayers = buffer.InvalidLayers
)
// -------------------------------------------------------------------
@@ -205,6 +188,8 @@ type Forwarder struct {
vp8Munger *VP8Munger
isTemporalSupported bool
ddLayerSelector *DDVideoLayerSelector
}
func NewForwarder(codec webrtc.RTPCodecCapability, kind webrtc.RTPCodecType, logger logger.Logger) *Forwarder {
@@ -227,8 +212,14 @@ func NewForwarder(codec webrtc.RTPCodecCapability, kind webrtc.RTPCodecType, log
f.vp8Munger = NewVP8Munger(logger)
}
// TODO : we only enable dd layer selector for av1 now, at future we can
// enable it for vp9 too
if strings.ToLower(codec.MimeType) == "video/av1" {
f.ddLayerSelector = NewDDVideoLayerSelector(f.logger)
}
if f.kind == webrtc.RTPCodecTypeVideo {
f.maxLayers = VideoLayers{spatial: InvalidLayerSpatial, temporal: DefaultMaxLayerTemporal}
f.maxLayers = VideoLayers{Spatial: InvalidLayerSpatial, Temporal: DefaultMaxLayerTemporal}
} else {
f.maxLayers = InvalidLayers
}
@@ -265,11 +256,11 @@ func (f *Forwarder) SetMaxSpatialLayer(spatialLayer int32) (bool, VideoLayers, V
f.lock.Lock()
defer f.lock.Unlock()
if f.kind == webrtc.RTPCodecTypeAudio || spatialLayer == f.maxLayers.spatial {
if f.kind == webrtc.RTPCodecTypeAudio || spatialLayer == f.maxLayers.Spatial {
return false, f.maxLayers, f.currentLayers
}
f.maxLayers.spatial = spatialLayer
f.maxLayers.Spatial = spatialLayer
return true, f.maxLayers, f.currentLayers
}
@@ -278,11 +269,11 @@ func (f *Forwarder) SetMaxTemporalLayer(temporalLayer int32) (bool, VideoLayers,
f.lock.Lock()
defer f.lock.Unlock()
if f.kind == webrtc.RTPCodecTypeAudio || temporalLayer == f.maxLayers.temporal {
if f.kind == webrtc.RTPCodecTypeAudio || temporalLayer == f.maxLayers.Temporal {
return false, f.maxLayers, f.currentLayers
}
f.maxLayers.temporal = temporalLayer
f.maxLayers.Temporal = temporalLayer
return true, f.maxLayers, f.currentLayers
}
@@ -320,7 +311,7 @@ func (f *Forwarder) GetForwardingStatus() ForwardingStatus {
return ForwardingStatusOff
}
if f.targetLayers.spatial < f.maxLayers.spatial && f.targetLayers.spatial < f.availableLayers[len(f.availableLayers)-1] {
if f.targetLayers.Spatial < f.maxLayers.Spatial && f.targetLayers.Spatial < f.availableLayers[len(f.availableLayers)-1] {
return ForwardingStatusPartial
}
@@ -335,8 +326,8 @@ func (f *Forwarder) UpTrackLayersChange(availableLayers []int32) {
}
func (f *Forwarder) getOptimalBandwidthNeeded(brs Bitrates) int64 {
for i := f.maxLayers.spatial; i >= 0; i-- {
for j := f.maxLayers.temporal; j >= 0; j-- {
for i := f.maxLayers.Spatial; i >= 0; i-- {
for j := f.maxLayers.Temporal; j >= 0; j-- {
if brs[i][j] == 0 {
continue
}
@@ -352,12 +343,12 @@ func (f *Forwarder) bitrateAvailable(brs Bitrates, availableLayers []int32) bool
neededLayers := 0
var bitrateAvailableLayers []int32
for _, layer := range f.availableLayers {
if layer > f.maxLayers.spatial {
if layer > f.maxLayers.Spatial {
continue
}
neededLayers++
for t := f.maxLayers.temporal; t >= 0; t-- {
for t := f.maxLayers.Temporal; t >= 0; t-- {
if brs[layer][t] != 0 {
bitrateAvailableLayers = append(bitrateAvailableLayers, layer)
break
@@ -374,13 +365,13 @@ func (f *Forwarder) getDistanceToDesired(brs Bitrates, targetLayers VideoLayers)
}
distance := int32(0)
for s := f.maxLayers.spatial; s >= 0; s-- {
for s := f.maxLayers.Spatial; s >= 0; s-- {
found := false
for t := f.maxLayers.temporal; t >= 0; t-- {
for t := f.maxLayers.Temporal; t >= 0; t-- {
if brs[s][t] == 0 {
continue
}
if s == targetLayers.spatial && t == targetLayers.temporal {
if s == targetLayers.Spatial && t == targetLayers.Temporal {
found = true
break
}
@@ -411,7 +402,7 @@ func (f *Forwarder) BandwidthRequested(brs Bitrates) int64 {
return 0
}
return brs[f.targetLayers.spatial][f.targetLayers.temporal]
return brs[f.targetLayers.Spatial][f.targetLayers.Temporal]
}
func (f *Forwarder) DistanceToDesired() int32 {
@@ -448,23 +439,23 @@ func (f *Forwarder) AllocateOptimal(brs Bitrates) VideoAllocation {
// Resume with the highest layer available <= max subscribed layer
// If already resumed, move allocation to the highest available layer <= max subscribed layer
//
targetLayers.spatial = int32(math.Min(float64(f.maxLayers.spatial), float64(f.availableLayers[len(f.availableLayers)-1])))
targetLayers.temporal = int32(math.Max(0, float64(f.maxLayers.temporal)))
targetLayers.Spatial = int32(math.Min(float64(f.maxLayers.Spatial), float64(f.availableLayers[len(f.availableLayers)-1])))
targetLayers.Temporal = int32(math.Max(0, float64(f.maxLayers.Temporal)))
if f.targetLayers == InvalidLayers && targetLayers.IsValid() {
change = VideoStreamingChangeResuming
}
default:
// allocate best layer available
for s := f.maxLayers.spatial; s >= 0; s-- {
for t := f.maxLayers.temporal; t >= 0; t-- {
for s := f.maxLayers.Spatial; s >= 0; s-- {
for t := f.maxLayers.Temporal; t >= 0; t-- {
if brs[s][t] == 0 {
continue
}
targetLayers = VideoLayers{
spatial: s,
temporal: t,
Spatial: s,
Temporal: t,
}
bandwidthRequested = brs[s][t]
@@ -495,7 +486,7 @@ func (f *Forwarder) AllocateOptimal(brs Bitrates) VideoAllocation {
targetLayers: targetLayers,
distanceToDesired: f.getDistanceToDesired(brs, targetLayers),
}
f.targetLayers = f.lastAllocation.targetLayers
f.setTargetLayers(f.lastAllocation.targetLayers)
if f.targetLayers == InvalidLayers {
f.resyncLocked()
}
@@ -524,14 +515,14 @@ func (f *Forwarder) ProvisionalAllocate(availableChannelCapacity int64, layers V
return 0
}
requiredBitrate := f.provisional.bitrates[layers.spatial][layers.temporal]
requiredBitrate := f.provisional.bitrates[layers.Spatial][layers.Temporal]
if requiredBitrate == 0 {
return 0
}
alreadyAllocatedBitrate := int64(0)
if f.provisional.layers != InvalidLayers {
alreadyAllocatedBitrate = f.provisional.bitrates[f.provisional.layers.spatial][f.provisional.layers.temporal]
alreadyAllocatedBitrate = f.provisional.bitrates[f.provisional.layers.Spatial][f.provisional.layers.Temporal]
}
if requiredBitrate <= (availableChannelCapacity + alreadyAllocatedBitrate) {
@@ -586,10 +577,10 @@ func (f *Forwarder) ProvisionalAllocateGetCooperativeTransition() VideoTransitio
// what is the highest that is available
maximalLayers := InvalidLayers
maximalBandwidthRequired := int64(0)
for s := f.provisional.maxLayers.spatial; s >= 0; s-- {
for t := f.provisional.maxLayers.temporal; t >= 0; t-- {
for s := f.provisional.maxLayers.Spatial; s >= 0; s-- {
for t := f.provisional.maxLayers.Temporal; t >= 0; t-- {
if f.provisional.bitrates[s][t] != 0 {
maximalLayers = VideoLayers{spatial: s, temporal: t}
maximalLayers = VideoLayers{Spatial: s, Temporal: t}
maximalBandwidthRequired = f.provisional.bitrates[s][t]
break
}
@@ -601,7 +592,7 @@ func (f *Forwarder) ProvisionalAllocateGetCooperativeTransition() VideoTransitio
}
if maximalLayers != InvalidLayers {
if !f.targetLayers.GreaterThan(maximalLayers) && (f.provisional.bitrates[f.targetLayers.spatial][f.targetLayers.temporal] != 0) {
if !f.targetLayers.GreaterThan(maximalLayers) && (f.provisional.bitrates[f.targetLayers.Spatial][f.targetLayers.Temporal] != 0) {
// currently streaming and wanting an upgrade, just preserve current target in the cooperative scheme of things
f.provisional.layers = f.targetLayers
return VideoTransition{
@@ -628,10 +619,10 @@ func (f *Forwarder) ProvisionalAllocateGetCooperativeTransition() VideoTransitio
// but the cooperative scheme knocks things back to minimal
minimalLayers := InvalidLayers
bandwidthRequired := int64(0)
for s := int32(0); s <= f.provisional.maxLayers.spatial; s++ {
for t := int32(0); t <= f.provisional.maxLayers.temporal; t++ {
for s := int32(0); s <= f.provisional.maxLayers.Spatial; s++ {
for t := int32(0); t <= f.provisional.maxLayers.Temporal; t++ {
if f.provisional.bitrates[s][t] != 0 {
minimalLayers = VideoLayers{spatial: s, temporal: t}
minimalLayers = VideoLayers{Spatial: s, Temporal: t}
bandwidthRequired = f.provisional.bitrates[s][t]
break
}
@@ -643,7 +634,7 @@ func (f *Forwarder) ProvisionalAllocateGetCooperativeTransition() VideoTransitio
}
targetLayers := f.targetLayers
if targetLayers == InvalidLayers || targetLayers.GreaterThan(minimalLayers) || (f.provisional.bitrates[targetLayers.spatial][targetLayers.temporal] == 0) {
if targetLayers == InvalidLayers || targetLayers.GreaterThan(minimalLayers) || (f.provisional.bitrates[targetLayers.Spatial][targetLayers.Temporal] == 0) {
targetLayers = minimalLayers
}
@@ -684,8 +675,8 @@ func (f *Forwarder) ProvisionalAllocateGetBestWeightedTransition() VideoTransiti
}
maxReachableLayerTemporal := InvalidLayerTemporal
for t := f.provisional.maxLayers.temporal; t >= 0; t-- {
for s := f.provisional.maxLayers.spatial; s >= 0; s-- {
for t := f.provisional.maxLayers.Temporal; t >= 0; t-- {
for s := f.provisional.maxLayers.Spatial; s >= 0; s-- {
if f.provisional.bitrates[s][t] != 0 {
maxReachableLayerTemporal = t
break
@@ -712,20 +703,20 @@ func (f *Forwarder) ProvisionalAllocateGetBestWeightedTransition() VideoTransiti
bestLayers := InvalidLayers
bestBandwidthDelta := int64(0)
bestValue := float32(0)
for s := int32(0); s <= f.targetLayers.spatial; s++ {
for t := int32(0); t <= f.targetLayers.temporal; t++ {
if s == f.targetLayers.spatial && t == f.targetLayers.temporal {
for s := int32(0); s <= f.targetLayers.Spatial; s++ {
for t := int32(0); t <= f.targetLayers.Temporal; t++ {
if s == f.targetLayers.Spatial && t == f.targetLayers.Temporal {
break
}
bandwidthDelta := int64(math.Max(float64(0), float64(f.lastAllocation.bandwidthRequested-f.provisional.bitrates[s][t])))
transitionCost := int32(0)
if f.targetLayers.spatial != s {
if f.targetLayers.Spatial != s {
transitionCost = TransitionCostSpatial
}
qualityCost := (maxReachableLayerTemporal+1)*(f.targetLayers.spatial-s) + (f.targetLayers.temporal - t)
qualityCost := (maxReachableLayerTemporal+1)*(f.targetLayers.Spatial-s) + (f.targetLayers.Temporal - t)
value := float32(0)
if (transitionCost + qualityCost) != 0 {
@@ -734,7 +725,7 @@ func (f *Forwarder) ProvisionalAllocateGetBestWeightedTransition() VideoTransiti
if value > bestValue || (value == bestValue && bandwidthDelta > bestBandwidthDelta) {
bestValue = value
bestBandwidthDelta = bandwidthDelta
bestLayers = VideoLayers{spatial: s, temporal: t}
bestLayers = VideoLayers{Spatial: s, Temporal: t}
}
}
}
@@ -768,7 +759,7 @@ func (f *Forwarder) ProvisionalAllocateCommit() VideoAllocation {
change = VideoStreamingChangePausing
}
default:
bandwidthRequested = f.provisional.bitrates[f.provisional.layers.spatial][f.provisional.layers.temporal]
bandwidthRequested = f.provisional.bitrates[f.provisional.layers.Spatial][f.provisional.layers.Temporal]
if bandwidthRequested == f.getOptimalBandwidthNeeded(f.provisional.bitrates) {
state = VideoAllocationStateOptimal
} else {
@@ -790,7 +781,7 @@ func (f *Forwarder) ProvisionalAllocateCommit() VideoAllocation {
targetLayers: f.provisional.layers,
distanceToDesired: f.getDistanceToDesired(f.provisional.bitrates, f.provisional.layers),
}
f.targetLayers = f.lastAllocation.targetLayers
f.setTargetLayers(f.lastAllocation.targetLayers)
if f.targetLayers == InvalidLayers {
f.resyncLocked()
}
@@ -823,13 +814,13 @@ func (f *Forwarder) AllocateNextHigher(availableChannelCapacity int64, brs Bitra
alreadyAllocated := int64(0)
if f.targetLayers != InvalidLayers {
alreadyAllocated = brs[f.targetLayers.spatial][f.targetLayers.temporal]
alreadyAllocated = brs[f.targetLayers.Spatial][f.targetLayers.Temporal]
}
// try moving temporal layer up in currently streaming spatial layer
if f.targetLayers != InvalidLayers {
for t := f.targetLayers.temporal + 1; t <= f.maxLayers.temporal; t++ {
bandwidthRequested := brs[f.targetLayers.spatial][t]
for t := f.targetLayers.Temporal + 1; t <= f.maxLayers.Temporal; t++ {
bandwidthRequested := brs[f.targetLayers.Spatial][t]
if bandwidthRequested == 0 {
continue
}
@@ -845,7 +836,7 @@ func (f *Forwarder) AllocateNextHigher(availableChannelCapacity int64, brs Bitra
state = VideoAllocationStateDeficient
}
targetLayers := VideoLayers{spatial: f.targetLayers.spatial, temporal: t}
targetLayers := VideoLayers{Spatial: f.targetLayers.Spatial, Temporal: t}
f.lastAllocation = VideoAllocation{
state: state,
change: VideoStreamingChangeNone,
@@ -856,14 +847,14 @@ func (f *Forwarder) AllocateNextHigher(availableChannelCapacity int64, brs Bitra
targetLayers: targetLayers,
distanceToDesired: f.getDistanceToDesired(brs, targetLayers),
}
f.targetLayers = f.lastAllocation.targetLayers
f.setTargetLayers(f.lastAllocation.targetLayers)
return f.lastAllocation, true
}
}
// try moving spatial layer up if temporal layer move up is not available
for s := f.targetLayers.spatial + 1; s <= f.maxLayers.spatial; s++ {
for t := int32(0); t <= f.maxLayers.temporal; t++ {
for s := f.targetLayers.Spatial + 1; s <= f.maxLayers.Spatial; s++ {
for t := int32(0); t <= f.maxLayers.Temporal; t++ {
bandwidthRequested := brs[s][t]
if bandwidthRequested == 0 {
continue
@@ -885,7 +876,7 @@ func (f *Forwarder) AllocateNextHigher(availableChannelCapacity int64, brs Bitra
change = VideoStreamingChangeResuming
}
targetLayers := VideoLayers{spatial: s, temporal: t}
targetLayers := VideoLayers{Spatial: s, Temporal: t}
f.lastAllocation = VideoAllocation{
state: state,
change: change,
@@ -896,7 +887,7 @@ func (f *Forwarder) AllocateNextHigher(availableChannelCapacity int64, brs Bitra
targetLayers: targetLayers,
distanceToDesired: f.getDistanceToDesired(brs, targetLayers),
}
f.targetLayers = f.lastAllocation.targetLayers
f.setTargetLayers(f.lastAllocation.targetLayers)
return f.lastAllocation, true
}
}
@@ -925,20 +916,20 @@ func (f *Forwarder) GetNextHigherTransition(brs Bitrates) (VideoTransition, bool
alreadyAllocated := int64(0)
if f.targetLayers != InvalidLayers {
alreadyAllocated = brs[f.targetLayers.spatial][f.targetLayers.temporal]
alreadyAllocated = brs[f.targetLayers.Spatial][f.targetLayers.Temporal]
}
// try moving temporal layer up in currently streaming spatial layer
if f.targetLayers != InvalidLayers {
for t := f.targetLayers.temporal + 1; t <= f.maxLayers.temporal; t++ {
bandwidthRequested := brs[f.targetLayers.spatial][t]
for t := f.targetLayers.Temporal + 1; t <= f.maxLayers.Temporal; t++ {
bandwidthRequested := brs[f.targetLayers.Spatial][t]
if bandwidthRequested == 0 {
continue
}
transition := VideoTransition{
from: f.targetLayers,
to: VideoLayers{spatial: f.targetLayers.spatial, temporal: t},
to: VideoLayers{Spatial: f.targetLayers.Spatial, Temporal: t},
bandwidthDelta: bandwidthRequested - alreadyAllocated,
}
@@ -947,8 +938,8 @@ func (f *Forwarder) GetNextHigherTransition(brs Bitrates) (VideoTransition, bool
}
// try moving spatial layer up if temporal layer move up is not available
for s := f.targetLayers.spatial + 1; s <= f.maxLayers.spatial; s++ {
for t := int32(0); t <= f.maxLayers.temporal; t++ {
for s := f.targetLayers.Spatial + 1; s <= f.maxLayers.Spatial; s++ {
for t := int32(0); t <= f.maxLayers.Temporal; t++ {
bandwidthRequested := brs[s][t]
if bandwidthRequested == 0 {
continue
@@ -956,7 +947,7 @@ func (f *Forwarder) GetNextHigherTransition(brs Bitrates) (VideoTransition, bool
transition := VideoTransition{
from: f.targetLayers,
to: VideoLayers{spatial: s, temporal: t},
to: VideoLayers{Spatial: s, Temporal: t},
bandwidthDelta: bandwidthRequested - alreadyAllocated,
}
@@ -999,7 +990,7 @@ func (f *Forwarder) Pause(brs Bitrates) VideoAllocation {
targetLayers: InvalidLayers,
distanceToDesired: f.getDistanceToDesired(brs, InvalidLayers),
}
f.targetLayers = f.lastAllocation.targetLayers
f.setTargetLayers(f.lastAllocation.targetLayers)
if f.targetLayers == InvalidLayers {
f.resyncLocked()
}
@@ -1007,6 +998,13 @@ func (f *Forwarder) Pause(brs Bitrates) VideoAllocation {
return f.lastAllocation
}
func (f *Forwarder) setTargetLayers(targetLayers VideoLayers) {
f.targetLayers = targetLayers
if f.ddLayerSelector != nil {
f.ddLayerSelector.SelectLayer(targetLayers)
}
}
func (f *Forwarder) Resync() {
f.lock.Lock()
defer f.lock.Unlock()
@@ -1023,8 +1021,8 @@ func (f *Forwarder) CheckSync() (locked bool, layer int32) {
f.lock.RLock()
defer f.lock.RUnlock()
layer = f.targetLayers.spatial
locked = f.targetLayers.spatial == f.currentLayers.spatial
layer = f.targetLayers.Spatial
locked = f.targetLayers.Spatial == f.currentLayers.Spatial
return
}
@@ -1050,7 +1048,7 @@ func (f *Forwarder) FilterRTX(nacks []uint16) (filtered []uint16, disallowedLaye
//
for layer := int32(0); layer < DefaultMaxLayerSpatial+1; layer++ {
if f.lastAllocation.state == VideoAllocationStateDeficient &&
(f.targetLayers.spatial < f.currentLayers.spatial || layer > f.currentLayers.spatial) {
(f.targetLayers.Spatial < f.currentLayers.Spatial || layer > f.currentLayers.Spatial) {
disallowedLayers[layer] = true
}
}
@@ -1079,7 +1077,7 @@ func (f *Forwarder) GetTranslationParams(extPkt *buffer.ExtPacket, layer int32)
}
// should be called with lock held
func (f *Forwarder) getTranslationParamsCommon(extPkt *buffer.ExtPacket) (*TranslationParams, error) {
func (f *Forwarder) getTranslationParamsCommon(extPkt *buffer.ExtPacket, tp *TranslationParams) (*TranslationParams, error) {
if f.lastSSRC != extPkt.Packet.SSRC {
if !f.started {
f.started = true
@@ -1121,7 +1119,9 @@ func (f *Forwarder) getTranslationParamsCommon(extPkt *buffer.ExtPacket) (*Trans
f.lTSCalc = extPkt.Arrival
tp := &TranslationParams{}
if tp == nil {
tp = &TranslationParams{}
}
tpRTP, err := f.rtpMunger.UpdateAndGetSnTs(extPkt)
if err != nil {
tp.shouldDrop = true
@@ -1142,7 +1142,7 @@ func (f *Forwarder) getTranslationParamsCommon(extPkt *buffer.ExtPacket) (*Trans
// should be called with lock held
func (f *Forwarder) getTranslationParamsAudio(extPkt *buffer.ExtPacket) (*TranslationParams, error) {
return f.getTranslationParamsCommon(extPkt)
return f.getTranslationParamsCommon(extPkt, nil)
}
// should be called with lock held
@@ -1155,28 +1155,42 @@ func (f *Forwarder) getTranslationParamsVideo(extPkt *buffer.ExtPacket, layer in
return tp, nil
}
if f.targetLayers.spatial != f.currentLayers.spatial {
if f.targetLayers.spatial == layer {
if extPkt.KeyFrame {
if f.ddLayerSelector != nil {
if selected := f.ddLayerSelector.Select(extPkt, tp); !selected {
tp.shouldDrop = true
f.rtpMunger.PacketDropped(extPkt)
return tp, nil
}
}
if f.targetLayers.Spatial != f.currentLayers.Spatial {
if f.targetLayers.Spatial == layer {
if extPkt.KeyFrame || tp.switchingToTargetLayer {
// lock to target layer
f.logger.Debugw("locking to target layer", "current", f.currentLayers, "target", f.targetLayers)
f.currentLayers.spatial = f.targetLayers.spatial
f.currentLayers.Spatial = f.targetLayers.Spatial
if !f.isTemporalSupported {
f.currentLayers.temporal = f.targetLayers.temporal
f.currentLayers.Temporal = f.targetLayers.Temporal
}
if f.currentLayers.spatial == f.maxLayers.spatial {
// TODO : we switch to target layer immediately now since we assume all frame chain is integrity
// if we have frame chain check, should switch only if target chain is not broken and decodable
// if f.ddLayerSelector != nil {
// f.ddLayerSelector.SelectLayer(f.currentLayers)
// }
if f.currentLayers.Spatial == f.maxLayers.Spatial {
tp.isSwitchingToMaxLayer = true
}
}
}
}
if f.currentLayers.spatial != layer {
// if we have layer selector, let it decide whether to drop or not
if f.ddLayerSelector == nil && f.currentLayers.Spatial != layer {
tp.shouldDrop = true
return tp, nil
}
if FlagPauseOnDowngrade && f.targetLayers.spatial < f.currentLayers.spatial && f.lastAllocation.state == VideoAllocationStateDeficient {
if FlagPauseOnDowngrade && f.targetLayers.Spatial < f.currentLayers.Spatial && f.lastAllocation.state == VideoAllocationStateDeficient {
//
// If target layer is lower than both the current and
// maximum subscribed layer, it is due to bandwidth
@@ -1200,22 +1214,22 @@ func (f *Forwarder) getTranslationParamsVideo(extPkt *buffer.ExtPacket, layer in
return tp, nil
}
tp, err := f.getTranslationParamsCommon(extPkt)
_, err := f.getTranslationParamsCommon(extPkt, tp)
if tp.shouldDrop || f.vp8Munger == nil || len(extPkt.Packet.Payload) == 0 {
return tp, err
}
// catch up temporal layer if necessary
if f.currentLayers.temporal != f.targetLayers.temporal {
if f.currentLayers.Temporal != f.targetLayers.Temporal {
incomingVP8, ok := extPkt.Payload.(buffer.VP8)
if ok {
if incomingVP8.TIDPresent == 1 && incomingVP8.TID <= uint8(f.targetLayers.temporal) {
f.currentLayers.temporal = f.targetLayers.temporal
if incomingVP8.TIDPresent == 1 && incomingVP8.TID <= uint8(f.targetLayers.Temporal) {
f.currentLayers.Temporal = f.targetLayers.Temporal
}
}
}
tpVP8, err := f.vp8Munger.UpdateAndGet(extPkt, tp.rtp.snOrdering, f.currentLayers.temporal)
tpVP8, err := f.vp8Munger.UpdateAndGet(extPkt, tp.rtp.snOrdering, f.currentLayers.Temporal)
if err != nil {
tp.rtp = nil
tp.shouldDrop = true