Cleaning up availableLayers and exemptedLayers (#1407)
* WIP commit * Send stream state paused only when it is paused due to bandwidth limitation. When stream is resumed after a stream is paused, an active update is sent. Note that this means if there are intervening events like mute/unmute between pause and resume, resume will be sent. * WIP commit * fix compile * WIP commit * fixing tests * clean up exempted layers * clean up unused stuff * correct comment * Don't need ops queue as order is not important now * static check * kick off allocation when callbacks are set up, calling from receiver means callbacks may not be set up
This commit is contained in:
@@ -165,7 +165,6 @@ type StreamTrackerFrameConfig struct {
|
|||||||
type StreamTrackerConfig struct {
|
type StreamTrackerConfig struct {
|
||||||
StreamTrackerType StreamTrackerType `yaml:"stream_tracker_type,omitempty"`
|
StreamTrackerType StreamTrackerType `yaml:"stream_tracker_type,omitempty"`
|
||||||
BitrateReportInterval map[int32]time.Duration `yaml:"bitrate_report_interval,omitempty"`
|
BitrateReportInterval map[int32]time.Duration `yaml:"bitrate_report_interval,omitempty"`
|
||||||
ExemptedLayers []int32 `yaml:"exempted_layers,omitempty"`
|
|
||||||
PacketTracker map[int32]StreamTrackerPacketConfig `yaml:"packet_tracker,omitempty"`
|
PacketTracker map[int32]StreamTrackerPacketConfig `yaml:"packet_tracker,omitempty"`
|
||||||
FrameTracker map[int32]StreamTrackerFrameConfig `yaml:"frame_tracker,omitempty"`
|
FrameTracker map[int32]StreamTrackerFrameConfig `yaml:"frame_tracker,omitempty"`
|
||||||
}
|
}
|
||||||
@@ -304,7 +303,6 @@ func NewConfig(confString string, strictMode bool, c *cli.Context, baseFlags []c
|
|||||||
1: 1 * time.Second,
|
1: 1 * time.Second,
|
||||||
2: 1 * time.Second,
|
2: 1 * time.Second,
|
||||||
},
|
},
|
||||||
ExemptedLayers: []int32{},
|
|
||||||
PacketTracker: map[int32]StreamTrackerPacketConfig{
|
PacketTracker: map[int32]StreamTrackerPacketConfig{
|
||||||
0: StreamTrackerPacketConfig{
|
0: StreamTrackerPacketConfig{
|
||||||
SamplesRequired: 1,
|
SamplesRequired: 1,
|
||||||
@@ -341,7 +339,6 @@ func NewConfig(confString string, strictMode bool, c *cli.Context, baseFlags []c
|
|||||||
1: 4 * time.Second,
|
1: 4 * time.Second,
|
||||||
2: 4 * time.Second,
|
2: 4 * time.Second,
|
||||||
},
|
},
|
||||||
ExemptedLayers: []int32{0},
|
|
||||||
PacketTracker: map[int32]StreamTrackerPacketConfig{
|
PacketTracker: map[int32]StreamTrackerPacketConfig{
|
||||||
0: StreamTrackerPacketConfig{
|
0: StreamTrackerPacketConfig{
|
||||||
SamplesRequired: 1,
|
SamplesRequired: 1,
|
||||||
|
|||||||
+10
-13
@@ -27,7 +27,7 @@ import (
|
|||||||
|
|
||||||
// TrackSender defines an interface send media to remote peer
|
// TrackSender defines an interface send media to remote peer
|
||||||
type TrackSender interface {
|
type TrackSender interface {
|
||||||
UpTrackLayersChange(availableLayers []int32, exemptedLayers []int32)
|
UpTrackLayersChange()
|
||||||
UpTrackBitrateAvailabilityChange()
|
UpTrackBitrateAvailabilityChange()
|
||||||
WriteRTP(p *buffer.ExtPacket, layer int32) error
|
WriteRTP(p *buffer.ExtPacket, layer int32) error
|
||||||
Close()
|
Close()
|
||||||
@@ -555,12 +555,12 @@ func (d *DownTrack) WriteRTP(extPkt *buffer.ExtPacket, layer int32) error {
|
|||||||
d.stopKeyFrameRequester()
|
d.stopKeyFrameRequester()
|
||||||
}
|
}
|
||||||
|
|
||||||
if !tp.isSwitchingToTargetLayer {
|
if extPkt.KeyFrame {
|
||||||
d.logger.Debugw("forwarding key frame", "layer", layer)
|
d.logger.Debugw("forwarding key frame", "layer", layer)
|
||||||
} else {
|
|
||||||
if d.onTargetLayerFound != nil {
|
|
||||||
d.onTargetLayerFound(d)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if tp.isSwitchingToTargetLayer && d.onTargetLayerFound != nil {
|
||||||
|
d.onTargetLayerFound(d)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -859,13 +859,7 @@ func (d *DownTrack) SeedState(state DownTrackState) {
|
|||||||
d.forwarder.SeedState(state.ForwarderState)
|
d.forwarder.SeedState(state.ForwarderState)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DownTrack) GetForwardingStatus() ForwardingStatus {
|
func (d *DownTrack) UpTrackLayersChange() {
|
||||||
return d.forwarder.GetForwardingStatus()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (d *DownTrack) UpTrackLayersChange(availableLayers []int32, exemptedLayers []int32) {
|
|
||||||
d.forwarder.UpTrackLayersChange(availableLayers, exemptedLayers)
|
|
||||||
|
|
||||||
if onAvailableLayersChanged, ok := d.onAvailableLayersChanged.Load().(func(dt *DownTrack)); ok {
|
if onAvailableLayersChanged, ok := d.onAvailableLayersChanged.Load().(func(dt *DownTrack)); ok {
|
||||||
onAvailableLayersChanged(d)
|
onAvailableLayersChanged(d)
|
||||||
}
|
}
|
||||||
@@ -911,6 +905,9 @@ func (d *DownTrack) OnBitrateAvailabilityChanged(fn func(dt *DownTrack)) {
|
|||||||
|
|
||||||
func (d *DownTrack) OnSubscriptionChanged(fn func(dt *DownTrack)) {
|
func (d *DownTrack) OnSubscriptionChanged(fn func(dt *DownTrack)) {
|
||||||
d.onSubscriptionChanged = fn
|
d.onSubscriptionChanged = fn
|
||||||
|
|
||||||
|
// kick off an allocation just in case other events happened before callbacks were set up
|
||||||
|
go fn(d)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DownTrack) OnSubscribedLayersChanged(fn func(dt *DownTrack, layers VideoLayers)) {
|
func (d *DownTrack) OnSubscribedLayersChanged(fn func(dt *DownTrack, layers VideoLayers)) {
|
||||||
@@ -1220,7 +1217,7 @@ func (d *DownTrack) handleRTCP(bytes []byte) {
|
|||||||
sendPliOnce := func() {
|
sendPliOnce := func() {
|
||||||
if pliOnce {
|
if pliOnce {
|
||||||
targetLayers := d.forwarder.TargetLayers()
|
targetLayers := d.forwarder.TargetLayers()
|
||||||
if targetLayers != InvalidLayers {
|
if targetLayers != InvalidLayers && !d.forwarder.IsAnyMuted() {
|
||||||
d.logger.Debugw("sending PLI RTCP", "layer", targetLayers.Spatial)
|
d.logger.Debugw("sending PLI RTCP", "layer", targetLayers.Spatial)
|
||||||
d.receiver.SendPLI(targetLayers.Spatial, false)
|
d.receiver.SendPLI(targetLayers.Spatial, false)
|
||||||
d.isNACKThrottled.Store(true)
|
d.isNACKThrottled.Store(true)
|
||||||
|
|||||||
+84
-124
@@ -25,16 +25,6 @@ const (
|
|||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
|
|
||||||
type ForwardingStatus int
|
|
||||||
|
|
||||||
const (
|
|
||||||
ForwardingStatusOff ForwardingStatus = iota
|
|
||||||
ForwardingStatusPartial
|
|
||||||
ForwardingStatusOptimal
|
|
||||||
)
|
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
|
||||||
|
|
||||||
type VideoPauseReason int
|
type VideoPauseReason int
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -69,21 +59,22 @@ type VideoAllocation struct {
|
|||||||
isDeficient bool
|
isDeficient bool
|
||||||
bandwidthRequested int64
|
bandwidthRequested int64
|
||||||
bandwidthDelta int64
|
bandwidthDelta int64
|
||||||
availableLayers []int32
|
|
||||||
exemptedLayers []int32
|
|
||||||
bitrates Bitrates
|
bitrates Bitrates
|
||||||
targetLayers VideoLayers
|
targetLayers VideoLayers
|
||||||
|
maxLayers VideoLayers
|
||||||
distanceToDesired int32
|
distanceToDesired int32
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v VideoAllocation) String() string {
|
func (v VideoAllocation) String() string {
|
||||||
return fmt.Sprintf("VideoAllocation{pause: %s, def: %+v, bw: %d, del: %d, avail: %+v, exempt: %+v, rates: %+v, target: %s, dist: %d}",
|
return fmt.Sprintf("VideoAllocation{pause: %s, def: %+v, bw: %d, del: %d, rates: %+v, target: %s, max: %s, dist: %d}",
|
||||||
v.pauseReason, v.isDeficient, v.bandwidthRequested, v.bandwidthDelta, v.availableLayers, v.exemptedLayers, v.bitrates, v.targetLayers, v.distanceToDesired)
|
v.pauseReason, v.isDeficient, v.bandwidthRequested, v.bandwidthDelta, v.bitrates, v.targetLayers, v.maxLayers, v.distanceToDesired)
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
VideoAllocationDefault = VideoAllocation{
|
VideoAllocationDefault = VideoAllocation{
|
||||||
|
pauseReason: VideoPauseReasonFeedDry, // start with no feed till feed is seen
|
||||||
targetLayers: InvalidLayers,
|
targetLayers: InvalidLayers,
|
||||||
|
maxLayers: InvalidLayers,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -93,8 +84,6 @@ type VideoAllocationProvisional struct {
|
|||||||
muted bool
|
muted bool
|
||||||
pubMuted bool
|
pubMuted bool
|
||||||
bitrates Bitrates
|
bitrates Bitrates
|
||||||
availableLayers []int32
|
|
||||||
exemptedLayers []int32
|
|
||||||
maxLayers VideoLayers
|
maxLayers VideoLayers
|
||||||
currentLayers VideoLayers
|
currentLayers VideoLayers
|
||||||
parkedLayers VideoLayers
|
parkedLayers VideoLayers
|
||||||
@@ -144,6 +133,11 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
InvalidLayers = buffer.InvalidLayers
|
InvalidLayers = buffer.InvalidLayers
|
||||||
|
|
||||||
|
DefaultMaxLayers = VideoLayers{
|
||||||
|
Spatial: DefaultMaxLayerSpatial,
|
||||||
|
Temporal: DefaultMaxLayerTemporal,
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// -------------------------------------------------------------------
|
// -------------------------------------------------------------------
|
||||||
@@ -186,9 +180,6 @@ type Forwarder struct {
|
|||||||
|
|
||||||
lastAllocation VideoAllocation
|
lastAllocation VideoAllocation
|
||||||
|
|
||||||
availableLayers []int32
|
|
||||||
exemptedLayers []int32
|
|
||||||
|
|
||||||
rtpMunger *RTPMunger
|
rtpMunger *RTPMunger
|
||||||
vp8Munger *VP8Munger
|
vp8Munger *VP8Munger
|
||||||
|
|
||||||
@@ -361,6 +352,13 @@ func (f *Forwarder) IsPubMuted() bool {
|
|||||||
return f.pubMuted
|
return f.pubMuted
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *Forwarder) IsAnyMuted() bool {
|
||||||
|
f.lock.RLock()
|
||||||
|
defer f.lock.RUnlock()
|
||||||
|
|
||||||
|
return f.muted || f.pubMuted
|
||||||
|
}
|
||||||
|
|
||||||
func (f *Forwarder) SetMaxSpatialLayer(spatialLayer int32) (bool, VideoLayers, VideoLayers) {
|
func (f *Forwarder) SetMaxSpatialLayer(spatialLayer int32) (bool, VideoLayers, VideoLayers) {
|
||||||
f.lock.Lock()
|
f.lock.Lock()
|
||||||
defer f.lock.Unlock()
|
defer f.lock.Unlock()
|
||||||
@@ -421,30 +419,11 @@ func (f *Forwarder) GetReferenceLayerSpatial() int32 {
|
|||||||
return f.referenceLayerSpatial
|
return f.referenceLayerSpatial
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Forwarder) GetForwardingStatus() ForwardingStatus {
|
|
||||||
f.lock.RLock()
|
|
||||||
defer f.lock.RUnlock()
|
|
||||||
|
|
||||||
if f.muted || f.pubMuted || len(f.availableLayers) == 0 {
|
|
||||||
return ForwardingStatusOptimal
|
|
||||||
}
|
|
||||||
|
|
||||||
if f.targetLayers == InvalidLayers {
|
|
||||||
return ForwardingStatusOff
|
|
||||||
}
|
|
||||||
|
|
||||||
if f.targetLayers.Spatial < f.maxLayers.Spatial && f.targetLayers.Spatial < f.availableLayers[len(f.availableLayers)-1] {
|
|
||||||
return ForwardingStatusPartial
|
|
||||||
}
|
|
||||||
|
|
||||||
return ForwardingStatusOptimal
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Forwarder) IsReducedQuality() (int32, bool) {
|
func (f *Forwarder) IsReducedQuality() (int32, bool) {
|
||||||
f.lock.RLock()
|
f.lock.RLock()
|
||||||
defer f.lock.RUnlock()
|
defer f.lock.RUnlock()
|
||||||
|
|
||||||
if f.muted || f.pubMuted || len(f.availableLayers) == 0 || f.targetLayers.Spatial == InvalidLayerSpatial {
|
if f.muted || f.pubMuted || f.lastAllocation.pauseReason == VideoPauseReasonFeedDry || f.targetLayers.Spatial == InvalidLayerSpatial {
|
||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -464,25 +443,6 @@ func (f *Forwarder) IsReducedQuality() (int32, bool) {
|
|||||||
return distance, f.isDeficientLocked()
|
return distance, f.isDeficientLocked()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Forwarder) UpTrackLayersChange(availableLayers []int32, exemptedLayers []int32) {
|
|
||||||
f.lock.Lock()
|
|
||||||
defer f.lock.Unlock()
|
|
||||||
|
|
||||||
if len(availableLayers) > 0 {
|
|
||||||
f.availableLayers = make([]int32, len(availableLayers))
|
|
||||||
copy(f.availableLayers, availableLayers)
|
|
||||||
} else {
|
|
||||||
f.availableLayers = nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(exemptedLayers) > 0 {
|
|
||||||
f.exemptedLayers = make([]int32, len(exemptedLayers))
|
|
||||||
copy(f.exemptedLayers, exemptedLayers)
|
|
||||||
} else {
|
|
||||||
f.exemptedLayers = nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (f *Forwarder) getOptimalBandwidthNeeded(brs Bitrates, maxLayers VideoLayers) int64 {
|
func (f *Forwarder) getOptimalBandwidthNeeded(brs Bitrates, maxLayers VideoLayers) int64 {
|
||||||
if f.muted || f.pubMuted {
|
if f.muted || f.pubMuted {
|
||||||
return 0
|
return 0
|
||||||
@@ -506,42 +466,36 @@ func (f *Forwarder) getOptimalBandwidthNeeded(brs Bitrates, maxLayers VideoLayer
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Forwarder) bitrateAvailable(brs Bitrates) bool {
|
func (f *Forwarder) getLayerChanges(brs Bitrates) (addedLayers []int32, removedLayers []int32) {
|
||||||
neededLayers := 0
|
lastAllocationLayers := f.lastAllocation.bitrates.GetLayers()
|
||||||
bitrateAvailableLayers := 0
|
nowLayers := brs.GetLayers()
|
||||||
for _, layer := range f.availableLayers {
|
|
||||||
if layer > f.maxLayers.Spatial {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
for _, ln := range nowLayers {
|
||||||
// Layers could be exempted from stream tracker.
|
found := false
|
||||||
// If such a layer actually stops, it will not
|
for _, lla := range lastAllocationLayers {
|
||||||
// be removed from available layers as it is exempt.
|
if lla == ln {
|
||||||
// But, it could have zero bit rate as it actually stopped.
|
found = true
|
||||||
// So, do not take exempt layers into bitrate availability condition.
|
|
||||||
//
|
|
||||||
exempt := false
|
|
||||||
for _, el := range f.exemptedLayers {
|
|
||||||
if layer == el {
|
|
||||||
exempt = true
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if exempt {
|
if !found {
|
||||||
continue
|
addedLayers = append(addedLayers, ln)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
neededLayers++
|
for _, lla := range lastAllocationLayers {
|
||||||
for t := f.maxLayers.Temporal; t >= 0; t-- {
|
found := false
|
||||||
if brs[layer][t] != 0 {
|
for _, ln := range nowLayers {
|
||||||
bitrateAvailableLayers++
|
if ln == lla {
|
||||||
|
found = true
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if !found {
|
||||||
|
removedLayers = append(removedLayers, lla)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return bitrateAvailableLayers == neededLayers
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Forwarder) getDistanceToDesired(brs Bitrates, targetLayers VideoLayers, maxLayers VideoLayers) int32 {
|
func (f *Forwarder) getDistanceToDesired(brs Bitrates, targetLayers VideoLayers, maxLayers VideoLayers) int32 {
|
||||||
@@ -624,10 +578,12 @@ func (f *Forwarder) AllocateOptimal(brs Bitrates, allowOvershoot bool) VideoAllo
|
|||||||
|
|
||||||
alloc := VideoAllocation{
|
alloc := VideoAllocation{
|
||||||
pauseReason: VideoPauseReasonNone,
|
pauseReason: VideoPauseReasonNone,
|
||||||
availableLayers: f.availableLayers,
|
|
||||||
exemptedLayers: f.exemptedLayers,
|
|
||||||
bitrates: brs,
|
bitrates: brs,
|
||||||
targetLayers: InvalidLayers,
|
targetLayers: InvalidLayers,
|
||||||
|
maxLayers: f.maxLayers,
|
||||||
|
}
|
||||||
|
if f.getOptimalBandwidthNeeded(brs, f.maxLayers) == 0 {
|
||||||
|
alloc.pauseReason = VideoPauseReasonFeedDry
|
||||||
}
|
}
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
@@ -643,23 +599,48 @@ func (f *Forwarder) AllocateOptimal(brs Bitrates, allowOvershoot bool) VideoAllo
|
|||||||
// if parked on a layer, let it continue
|
// if parked on a layer, let it continue
|
||||||
alloc.targetLayers = f.parkedLayers
|
alloc.targetLayers = f.parkedLayers
|
||||||
|
|
||||||
case !f.bitrateAvailable(brs):
|
case !f.targetLayers.IsValid():
|
||||||
// Feed bitrate not yet calculated for all available layers
|
if f.maxLayers.IsValid() {
|
||||||
//
|
if allowOvershoot {
|
||||||
// Target the highest layer available <= max subscribed layer.
|
|
||||||
//
|
|
||||||
// If target already set, move allocation to the highest available layer <= max subscribed layer only if that is higher than existing target.
|
|
||||||
// It is possible that in situations like coming out of publisher mute, target is already set higher due to parked layers.
|
|
||||||
if f.availableLayers[len(f.availableLayers)-1] > f.targetLayers.Spatial {
|
|
||||||
alloc.targetLayers = VideoLayers{
|
alloc.targetLayers = VideoLayers{
|
||||||
Spatial: int32(math.Min(float64(f.maxLayers.Spatial), float64(f.availableLayers[len(f.availableLayers)-1]))),
|
Spatial: int32(math.Max(0, float64(f.numAdvertisedLayers-1))),
|
||||||
Temporal: int32(math.Max(0, float64(f.maxLayers.Temporal))),
|
Temporal: DefaultMaxLayerTemporal,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
alloc.targetLayers = f.targetLayers
|
alloc.targetLayers = f.maxLayers
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case f.lastAllocation.maxLayers != f.maxLayers:
|
||||||
|
alloc.targetLayers = f.maxLayers
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
doAlloc := false
|
||||||
|
added, removed := f.getLayerChanges(brs)
|
||||||
|
|
||||||
|
// check for an added higher than current target
|
||||||
|
for _, l := range added {
|
||||||
|
if l > f.targetLayers.Spatial {
|
||||||
|
doAlloc = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// check for current target being removed
|
||||||
|
if !doAlloc {
|
||||||
|
for _, l := range removed {
|
||||||
|
if l == f.targetLayers.Spatial {
|
||||||
|
doAlloc = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !doAlloc {
|
||||||
|
// no layer changes, leave target as is
|
||||||
|
alloc.targetLayers = f.targetLayers
|
||||||
|
alloc.bandwidthRequested = brs[alloc.targetLayers.Spatial][alloc.targetLayers.Temporal]
|
||||||
|
} else {
|
||||||
// allocate best layer available
|
// allocate best layer available
|
||||||
for s := f.maxLayers.Spatial; s >= 0; s-- {
|
for s := f.maxLayers.Spatial; s >= 0; s-- {
|
||||||
for t := f.maxLayers.Temporal; t >= 0; t-- {
|
for t := f.maxLayers.Temporal; t >= 0; t-- {
|
||||||
@@ -700,6 +681,7 @@ func (f *Forwarder) AllocateOptimal(brs Bitrates, allowOvershoot bool) VideoAllo
|
|||||||
}
|
}
|
||||||
|
|
||||||
alloc.bandwidthRequested = brs[s][t]
|
alloc.bandwidthRequested = brs[s][t]
|
||||||
|
alloc.pauseReason = VideoPauseReasonNone
|
||||||
f.logger.Infow("allowing overshoot", "maxLayer", f.maxLayers, "targetLayers", alloc.targetLayers)
|
f.logger.Infow("allowing overshoot", "maxLayer", f.maxLayers, "targetLayers", alloc.targetLayers)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
@@ -712,8 +694,7 @@ func (f *Forwarder) AllocateOptimal(brs Bitrates, allowOvershoot bool) VideoAllo
|
|||||||
|
|
||||||
// feed may be dry, leave target at current if already started for opportunistic resume
|
// feed may be dry, leave target at current if already started for opportunistic resume
|
||||||
if alloc.bandwidthRequested == 0 && f.maxLayers.IsValid() {
|
if alloc.bandwidthRequested == 0 && f.maxLayers.IsValid() {
|
||||||
alloc.pauseReason = VideoPauseReasonFeedDry
|
if f.started && f.currentLayers.IsValid() {
|
||||||
if f.started {
|
|
||||||
alloc.targetLayers = f.currentLayers
|
alloc.targetLayers = f.currentLayers
|
||||||
} else {
|
} else {
|
||||||
// opportunisitically latch on to anything
|
// opportunisitically latch on to anything
|
||||||
@@ -724,6 +705,7 @@ func (f *Forwarder) AllocateOptimal(brs Bitrates, allowOvershoot bool) VideoAllo
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !alloc.targetLayers.IsValid() {
|
if !alloc.targetLayers.IsValid() {
|
||||||
alloc.targetLayers = InvalidLayers
|
alloc.targetLayers = InvalidLayers
|
||||||
@@ -747,14 +729,6 @@ func (f *Forwarder) ProvisionalAllocatePrepare(bitrates Bitrates) {
|
|||||||
currentLayers: f.currentLayers,
|
currentLayers: f.currentLayers,
|
||||||
parkedLayers: f.parkedLayers,
|
parkedLayers: f.parkedLayers,
|
||||||
}
|
}
|
||||||
if len(f.availableLayers) > 0 {
|
|
||||||
f.provisional.availableLayers = make([]int32, len(f.availableLayers))
|
|
||||||
copy(f.provisional.availableLayers, f.availableLayers)
|
|
||||||
}
|
|
||||||
if len(f.exemptedLayers) > 0 {
|
|
||||||
f.provisional.exemptedLayers = make([]int32, len(f.exemptedLayers))
|
|
||||||
copy(f.provisional.exemptedLayers, f.exemptedLayers)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f *Forwarder) ProvisionalAllocate(availableChannelCapacity int64, layers VideoLayers, allowPause bool, allowOvershoot bool) int64 {
|
func (f *Forwarder) ProvisionalAllocate(availableChannelCapacity int64, layers VideoLayers, allowPause bool, allowOvershoot bool) int64 {
|
||||||
@@ -1043,10 +1017,9 @@ func (f *Forwarder) ProvisionalAllocateCommit() VideoAllocation {
|
|||||||
alloc := VideoAllocation{
|
alloc := VideoAllocation{
|
||||||
bandwidthRequested: 0,
|
bandwidthRequested: 0,
|
||||||
bandwidthDelta: -f.lastAllocation.bandwidthRequested,
|
bandwidthDelta: -f.lastAllocation.bandwidthRequested,
|
||||||
availableLayers: f.provisional.availableLayers,
|
|
||||||
exemptedLayers: f.provisional.exemptedLayers,
|
|
||||||
bitrates: f.provisional.bitrates,
|
bitrates: f.provisional.bitrates,
|
||||||
targetLayers: f.provisional.allocatedLayers,
|
targetLayers: f.provisional.allocatedLayers,
|
||||||
|
maxLayers: f.provisional.maxLayers,
|
||||||
distanceToDesired: f.getDistanceToDesired(f.provisional.bitrates, f.provisional.allocatedLayers, f.provisional.maxLayers),
|
distanceToDesired: f.getDistanceToDesired(f.provisional.bitrates, f.provisional.allocatedLayers, f.provisional.maxLayers),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1063,7 +1036,6 @@ func (f *Forwarder) ProvisionalAllocateCommit() VideoAllocation {
|
|||||||
alloc.bandwidthRequested = f.provisional.bitrates[f.provisional.allocatedLayers.Spatial][f.provisional.allocatedLayers.Temporal]
|
alloc.bandwidthRequested = f.provisional.bitrates[f.provisional.allocatedLayers.Spatial][f.provisional.allocatedLayers.Temporal]
|
||||||
alloc.bandwidthDelta = alloc.bandwidthRequested - f.lastAllocation.bandwidthRequested
|
alloc.bandwidthDelta = alloc.bandwidthRequested - f.lastAllocation.bandwidthRequested
|
||||||
} else {
|
} else {
|
||||||
// some exempt layer may be available, but technically the feed is dry
|
|
||||||
alloc.pauseReason = VideoPauseReasonFeedDry
|
alloc.pauseReason = VideoPauseReasonFeedDry
|
||||||
|
|
||||||
// leave target at current for opportunistic forwarding
|
// leave target at current for opportunistic forwarding
|
||||||
@@ -1141,10 +1113,9 @@ func (f *Forwarder) AllocateNextHigher(availableChannelCapacity int64, brs Bitra
|
|||||||
isDeficient: true,
|
isDeficient: true,
|
||||||
bandwidthRequested: bandwidthRequested,
|
bandwidthRequested: bandwidthRequested,
|
||||||
bandwidthDelta: bandwidthRequested - alreadyAllocated,
|
bandwidthDelta: bandwidthRequested - alreadyAllocated,
|
||||||
availableLayers: f.availableLayers,
|
|
||||||
exemptedLayers: f.exemptedLayers,
|
|
||||||
bitrates: brs,
|
bitrates: brs,
|
||||||
targetLayers: targetLayers,
|
targetLayers: targetLayers,
|
||||||
|
maxLayers: f.maxLayers,
|
||||||
distanceToDesired: f.getDistanceToDesired(brs, targetLayers, f.maxLayers),
|
distanceToDesired: f.getDistanceToDesired(brs, targetLayers, f.maxLayers),
|
||||||
}
|
}
|
||||||
if targetLayers.GreaterThan(f.maxLayers) || bandwidthRequested >= optimalBandwidthNeeded {
|
if targetLayers.GreaterThan(f.maxLayers) || bandwidthRequested >= optimalBandwidthNeeded {
|
||||||
@@ -1286,10 +1257,9 @@ func (f *Forwarder) Pause(brs Bitrates) VideoAllocation {
|
|||||||
alloc := VideoAllocation{
|
alloc := VideoAllocation{
|
||||||
bandwidthRequested: 0,
|
bandwidthRequested: 0,
|
||||||
bandwidthDelta: 0 - f.lastAllocation.bandwidthRequested,
|
bandwidthDelta: 0 - f.lastAllocation.bandwidthRequested,
|
||||||
availableLayers: f.availableLayers,
|
|
||||||
exemptedLayers: f.exemptedLayers,
|
|
||||||
bitrates: brs,
|
bitrates: brs,
|
||||||
targetLayers: InvalidLayers,
|
targetLayers: InvalidLayers,
|
||||||
|
maxLayers: f.maxLayers,
|
||||||
distanceToDesired: f.getDistanceToDesired(brs, InvalidLayers, f.maxLayers),
|
distanceToDesired: f.getDistanceToDesired(brs, InvalidLayers, f.maxLayers),
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1301,7 +1271,6 @@ func (f *Forwarder) Pause(brs Bitrates) VideoAllocation {
|
|||||||
alloc.pauseReason = VideoPauseReasonPubMuted
|
alloc.pauseReason = VideoPauseReasonPubMuted
|
||||||
|
|
||||||
case f.getOptimalBandwidthNeeded(brs, f.maxLayers) == 0:
|
case f.getOptimalBandwidthNeeded(brs, f.maxLayers) == 0:
|
||||||
// some exempt layer may be available, but technically the feed is dry
|
|
||||||
alloc.pauseReason = VideoPauseReasonFeedDry
|
alloc.pauseReason = VideoPauseReasonFeedDry
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -1320,16 +1289,7 @@ func (f *Forwarder) updateAllocation(alloc VideoAllocation, reason string) Video
|
|||||||
alloc.targetLayers != f.lastAllocation.targetLayers {
|
alloc.targetLayers != f.lastAllocation.targetLayers {
|
||||||
f.logger.Infow(fmt.Sprintf("stream allocation: %s", reason), "allocation", alloc)
|
f.logger.Infow(fmt.Sprintf("stream allocation: %s", reason), "allocation", alloc)
|
||||||
}
|
}
|
||||||
|
|
||||||
f.lastAllocation = alloc
|
f.lastAllocation = alloc
|
||||||
if len(alloc.availableLayers) > 0 {
|
|
||||||
f.lastAllocation.availableLayers = make([]int32, len(alloc.availableLayers))
|
|
||||||
copy(f.lastAllocation.availableLayers, alloc.availableLayers)
|
|
||||||
}
|
|
||||||
if len(alloc.exemptedLayers) > 0 {
|
|
||||||
f.lastAllocation.exemptedLayers = make([]int32, len(alloc.exemptedLayers))
|
|
||||||
copy(f.lastAllocation.exemptedLayers, alloc.exemptedLayers)
|
|
||||||
}
|
|
||||||
|
|
||||||
f.setTargetLayers(f.lastAllocation.targetLayers)
|
f.setTargetLayers(f.lastAllocation.targetLayers)
|
||||||
if f.targetLayers == InvalidLayers {
|
if f.targetLayers == InvalidLayers {
|
||||||
|
|||||||
+177
-275
@@ -110,61 +110,6 @@ func TestForwarderLayersVideo(t *testing.T) {
|
|||||||
require.Equal(t, VideoLayers{Spatial: 0, Temporal: 1}, currentLayers)
|
require.Equal(t, VideoLayers{Spatial: 0, Temporal: 1}, currentLayers)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestForwarderGetForwardingStatus(t *testing.T) {
|
|
||||||
f := newForwarder(testutils.TestVP8Codec, webrtc.RTPCodecTypeVideo)
|
|
||||||
f.SetMaxSpatialLayer(DefaultMaxLayerSpatial)
|
|
||||||
f.SetMaxTemporalLayer(DefaultMaxLayerTemporal)
|
|
||||||
|
|
||||||
// no available layers, should be optimal
|
|
||||||
require.Equal(t, ForwardingStatusOptimal, f.GetForwardingStatus())
|
|
||||||
|
|
||||||
// with available layers, should be off
|
|
||||||
availableLayers := []int32{0, 1, 2}
|
|
||||||
f.UpTrackLayersChange(availableLayers, []int32{})
|
|
||||||
require.Equal(t, ForwardingStatusOff, f.GetForwardingStatus())
|
|
||||||
|
|
||||||
// when muted, should be optimal
|
|
||||||
f.Mute(true)
|
|
||||||
require.Equal(t, ForwardingStatusOptimal, f.GetForwardingStatus())
|
|
||||||
|
|
||||||
// when target is the max, should be optimal
|
|
||||||
f.Mute(false)
|
|
||||||
f.targetLayers.Spatial = DefaultMaxLayerSpatial
|
|
||||||
require.Equal(t, ForwardingStatusOptimal, f.GetForwardingStatus())
|
|
||||||
|
|
||||||
// when target is less than max subscribed and max available, should be partial
|
|
||||||
f.targetLayers.Spatial = DefaultMaxLayerSpatial - 1
|
|
||||||
require.Equal(t, ForwardingStatusPartial, f.GetForwardingStatus())
|
|
||||||
|
|
||||||
// when available layers are lower than max subscribed, optimal as long as target is at max available
|
|
||||||
availableLayers = []int32{0, 1}
|
|
||||||
f.UpTrackLayersChange(availableLayers, []int32{})
|
|
||||||
require.Equal(t, ForwardingStatusOptimal, f.GetForwardingStatus())
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestForwarderUpTrackLayersChange(t *testing.T) {
|
|
||||||
f := newForwarder(testutils.TestVP8Codec, webrtc.RTPCodecTypeVideo)
|
|
||||||
|
|
||||||
require.Nil(t, f.availableLayers)
|
|
||||||
|
|
||||||
availableLayers := []int32{0, 1, 2}
|
|
||||||
exemptedLayers := []int32{0}
|
|
||||||
f.UpTrackLayersChange(availableLayers, exemptedLayers)
|
|
||||||
require.Equal(t, availableLayers, f.availableLayers)
|
|
||||||
require.Equal(t, exemptedLayers, f.exemptedLayers)
|
|
||||||
|
|
||||||
availableLayers = []int32{0, 2}
|
|
||||||
f.UpTrackLayersChange(availableLayers, []int32{})
|
|
||||||
require.Equal(t, availableLayers, f.availableLayers)
|
|
||||||
require.Nil(t, f.exemptedLayers)
|
|
||||||
|
|
||||||
availableLayers = []int32{}
|
|
||||||
exemptedLayers = []int32{}
|
|
||||||
f.UpTrackLayersChange(availableLayers, exemptedLayers)
|
|
||||||
require.Nil(t, f.availableLayers)
|
|
||||||
require.Nil(t, f.exemptedLayers)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestForwarderAllocateOptimal(t *testing.T) {
|
func TestForwarderAllocateOptimal(t *testing.T) {
|
||||||
f := newForwarder(testutils.TestVP8Codec, webrtc.RTPCodecTypeVideo)
|
f := newForwarder(testutils.TestVP8Codec, webrtc.RTPCodecTypeVideo)
|
||||||
f.SetMaxSpatialLayer(DefaultMaxLayerSpatial)
|
f.SetMaxSpatialLayer(DefaultMaxLayerSpatial)
|
||||||
@@ -184,9 +129,9 @@ func TestForwarderAllocateOptimal(t *testing.T) {
|
|||||||
pauseReason: VideoPauseReasonMuted,
|
pauseReason: VideoPauseReasonMuted,
|
||||||
bandwidthRequested: 0,
|
bandwidthRequested: 0,
|
||||||
bandwidthDelta: 0,
|
bandwidthDelta: 0,
|
||||||
availableLayers: nil,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: InvalidLayers,
|
targetLayers: InvalidLayers,
|
||||||
|
maxLayers: DefaultMaxLayers,
|
||||||
distanceToDesired: 0,
|
distanceToDesired: 0,
|
||||||
}
|
}
|
||||||
result := f.AllocateOptimal(bitrates, true)
|
result := f.AllocateOptimal(bitrates, true)
|
||||||
@@ -195,7 +140,27 @@ func TestForwarderAllocateOptimal(t *testing.T) {
|
|||||||
|
|
||||||
f.Mute(false)
|
f.Mute(false)
|
||||||
|
|
||||||
// feed dry, target set to maximum for opportunistic start
|
// when parked layers valid, should stay there
|
||||||
|
f.parkedLayers = VideoLayers{
|
||||||
|
Spatial: 0,
|
||||||
|
Temporal: 1,
|
||||||
|
}
|
||||||
|
expectedResult = VideoAllocation{
|
||||||
|
pauseReason: VideoPauseReasonFeedDry,
|
||||||
|
bandwidthRequested: 0,
|
||||||
|
bandwidthDelta: 0,
|
||||||
|
bitrates: emptyBitrates,
|
||||||
|
targetLayers: f.parkedLayers,
|
||||||
|
maxLayers: DefaultMaxLayers,
|
||||||
|
distanceToDesired: 0,
|
||||||
|
}
|
||||||
|
result = f.AllocateOptimal(emptyBitrates, true)
|
||||||
|
require.Equal(t, expectedResult, result)
|
||||||
|
require.Equal(t, expectedResult, f.lastAllocation)
|
||||||
|
require.Equal(t, f.parkedLayers, f.TargetLayers())
|
||||||
|
f.parkedLayers = InvalidLayers
|
||||||
|
|
||||||
|
// when target is invalid, should set up for opportunistic forwarding
|
||||||
f.SetNumAdvertisedLayers(3)
|
f.SetNumAdvertisedLayers(3)
|
||||||
disable(f)
|
disable(f)
|
||||||
expectedTargetLayers := VideoLayers{
|
expectedTargetLayers := VideoLayers{
|
||||||
@@ -206,9 +171,9 @@ func TestForwarderAllocateOptimal(t *testing.T) {
|
|||||||
pauseReason: VideoPauseReasonFeedDry,
|
pauseReason: VideoPauseReasonFeedDry,
|
||||||
bandwidthRequested: 0,
|
bandwidthRequested: 0,
|
||||||
bandwidthDelta: 0,
|
bandwidthDelta: 0,
|
||||||
availableLayers: nil,
|
|
||||||
bitrates: emptyBitrates,
|
bitrates: emptyBitrates,
|
||||||
targetLayers: expectedTargetLayers,
|
targetLayers: expectedTargetLayers,
|
||||||
|
maxLayers: DefaultMaxLayers,
|
||||||
distanceToDesired: 0,
|
distanceToDesired: 0,
|
||||||
}
|
}
|
||||||
result = f.AllocateOptimal(emptyBitrates, true)
|
result = f.AllocateOptimal(emptyBitrates, true)
|
||||||
@@ -216,127 +181,63 @@ func TestForwarderAllocateOptimal(t *testing.T) {
|
|||||||
require.Equal(t, expectedResult, f.lastAllocation)
|
require.Equal(t, expectedResult, f.lastAllocation)
|
||||||
require.Equal(t, expectedTargetLayers, f.TargetLayers())
|
require.Equal(t, expectedTargetLayers, f.TargetLayers())
|
||||||
|
|
||||||
f.parkedLayers = VideoLayers{
|
f.targetLayers = VideoLayers{Spatial: 0, Temporal: 0} // set to valid to trigger paths in tests below
|
||||||
|
|
||||||
|
// max layers changing should adopt that
|
||||||
|
f.SetMaxSpatialLayer(0)
|
||||||
|
f.SetMaxTemporalLayer(3)
|
||||||
|
expectedTargetLayers = VideoLayers{
|
||||||
|
Spatial: 0,
|
||||||
|
Temporal: DefaultMaxLayerTemporal,
|
||||||
|
}
|
||||||
|
expectedMaxLayers := VideoLayers{
|
||||||
|
Spatial: 0,
|
||||||
|
Temporal: DefaultMaxLayerTemporal,
|
||||||
|
}
|
||||||
|
expectedResult = VideoAllocation{
|
||||||
|
pauseReason: VideoPauseReasonFeedDry,
|
||||||
|
bandwidthRequested: 0,
|
||||||
|
bandwidthDelta: 0,
|
||||||
|
bitrates: emptyBitrates,
|
||||||
|
targetLayers: expectedTargetLayers,
|
||||||
|
maxLayers: expectedMaxLayers,
|
||||||
|
distanceToDesired: 0,
|
||||||
|
}
|
||||||
|
result = f.AllocateOptimal(emptyBitrates, true)
|
||||||
|
require.Equal(t, expectedResult, result)
|
||||||
|
require.Equal(t, expectedResult, f.lastAllocation)
|
||||||
|
require.Equal(t, expectedTargetLayers, f.TargetLayers())
|
||||||
|
|
||||||
|
// when no layer changes, should not change target
|
||||||
|
expectedTargetLayers = VideoLayers{
|
||||||
|
Spatial: 0,
|
||||||
|
Temporal: 3,
|
||||||
|
}
|
||||||
|
expectedResult = VideoAllocation{
|
||||||
|
pauseReason: VideoPauseReasonFeedDry,
|
||||||
|
bandwidthRequested: 0,
|
||||||
|
bandwidthDelta: 0,
|
||||||
|
bitrates: emptyBitrates,
|
||||||
|
targetLayers: expectedTargetLayers,
|
||||||
|
maxLayers: expectedMaxLayers,
|
||||||
|
distanceToDesired: 0,
|
||||||
|
}
|
||||||
|
result = f.AllocateOptimal(emptyBitrates, true)
|
||||||
|
require.Equal(t, expectedResult, result)
|
||||||
|
require.Equal(t, expectedResult, f.lastAllocation)
|
||||||
|
|
||||||
|
// allocate using bitrates, allocation should choose optimal
|
||||||
|
f.currentLayers = InvalidLayers
|
||||||
|
expectedTargetLayers = VideoLayers{
|
||||||
Spatial: 0,
|
Spatial: 0,
|
||||||
Temporal: 1,
|
Temporal: 1,
|
||||||
}
|
}
|
||||||
expectedResult = VideoAllocation{
|
expectedResult = VideoAllocation{
|
||||||
bandwidthRequested: 0,
|
bandwidthRequested: bitrates[0][1],
|
||||||
bandwidthDelta: 0,
|
bandwidthDelta: bitrates[0][1],
|
||||||
availableLayers: nil,
|
|
||||||
bitrates: emptyBitrates,
|
|
||||||
targetLayers: f.parkedLayers,
|
|
||||||
distanceToDesired: 0,
|
|
||||||
}
|
|
||||||
result = f.AllocateOptimal(emptyBitrates, true)
|
|
||||||
require.Equal(t, expectedResult, result)
|
|
||||||
require.Equal(t, expectedResult, f.lastAllocation)
|
|
||||||
require.Equal(t, f.parkedLayers, f.TargetLayers())
|
|
||||||
f.parkedLayers = InvalidLayers
|
|
||||||
|
|
||||||
// awaiting measurement, i.e. bitrates are not available, but layers available
|
|
||||||
disable(f)
|
|
||||||
f.UpTrackLayersChange([]int32{0}, []int32{})
|
|
||||||
expectedTargetLayers = VideoLayers{
|
|
||||||
Spatial: 0,
|
|
||||||
Temporal: DefaultMaxLayerTemporal,
|
|
||||||
}
|
|
||||||
expectedResult = VideoAllocation{
|
|
||||||
bandwidthRequested: 0,
|
|
||||||
bandwidthDelta: 0,
|
|
||||||
availableLayers: []int32{0},
|
|
||||||
bitrates: emptyBitrates,
|
|
||||||
targetLayers: expectedTargetLayers,
|
|
||||||
distanceToDesired: 0,
|
|
||||||
}
|
|
||||||
result = f.AllocateOptimal(emptyBitrates, true)
|
|
||||||
require.Equal(t, expectedResult, result)
|
|
||||||
require.Equal(t, expectedResult, f.lastAllocation)
|
|
||||||
require.Equal(t, expectedTargetLayers, f.TargetLayers())
|
|
||||||
require.Equal(t, InvalidLayers, f.CurrentLayers())
|
|
||||||
|
|
||||||
// layers are available, but all layers <= max are exempted.
|
|
||||||
// forwarder not started yet, so should set target to max.
|
|
||||||
// pauseReason should be populated to indicate feed is dry
|
|
||||||
// because exempt layers are actually detected as stopped.
|
|
||||||
f.SetMaxSpatialLayer(0)
|
|
||||||
f.currentLayers = VideoLayers{Spatial: 0, Temporal: 0}
|
|
||||||
f.UpTrackLayersChange([]int32{0, 1, 2}, []int32{0})
|
|
||||||
expectedTargetLayers = VideoLayers{
|
|
||||||
Spatial: DefaultMaxLayerSpatial,
|
|
||||||
Temporal: DefaultMaxLayerTemporal,
|
|
||||||
}
|
|
||||||
expectedResult = VideoAllocation{
|
|
||||||
pauseReason: VideoPauseReasonFeedDry,
|
|
||||||
bandwidthRequested: 0,
|
|
||||||
bandwidthDelta: 0,
|
|
||||||
availableLayers: []int32{0, 1, 2},
|
|
||||||
exemptedLayers: []int32{0},
|
|
||||||
bitrates: emptyBitrates,
|
|
||||||
targetLayers: expectedTargetLayers,
|
|
||||||
distanceToDesired: 0,
|
|
||||||
}
|
|
||||||
result = f.AllocateOptimal(emptyBitrates, true)
|
|
||||||
require.Equal(t, expectedResult, result)
|
|
||||||
require.Equal(t, expectedResult, f.lastAllocation)
|
|
||||||
require.Equal(t, expectedTargetLayers, f.TargetLayers())
|
|
||||||
|
|
||||||
// when started, should just leave it at current for opportunistic resume
|
|
||||||
f.started = true
|
|
||||||
expectedTargetLayers = VideoLayers{
|
|
||||||
Spatial: 0,
|
|
||||||
Temporal: 0,
|
|
||||||
}
|
|
||||||
expectedResult = VideoAllocation{
|
|
||||||
pauseReason: VideoPauseReasonFeedDry,
|
|
||||||
bandwidthRequested: 0,
|
|
||||||
bandwidthDelta: 0,
|
|
||||||
availableLayers: []int32{0, 1, 2},
|
|
||||||
exemptedLayers: []int32{0},
|
|
||||||
bitrates: emptyBitrates,
|
|
||||||
targetLayers: expectedTargetLayers,
|
|
||||||
distanceToDesired: 0,
|
|
||||||
}
|
|
||||||
result = f.AllocateOptimal(emptyBitrates, true)
|
|
||||||
require.Equal(t, expectedResult, result)
|
|
||||||
require.Equal(t, expectedResult, f.lastAllocation)
|
|
||||||
require.Equal(t, expectedTargetLayers, f.TargetLayers())
|
|
||||||
|
|
||||||
// if current is not exempt, should still leave at current for opportunistic resume
|
|
||||||
f.currentLayers = VideoLayers{Spatial: 1, Temporal: 0}
|
|
||||||
expectedTargetLayers = VideoLayers{
|
|
||||||
Spatial: 1,
|
|
||||||
Temporal: 0,
|
|
||||||
}
|
|
||||||
expectedResult = VideoAllocation{
|
|
||||||
pauseReason: VideoPauseReasonFeedDry,
|
|
||||||
bandwidthRequested: 0,
|
|
||||||
bandwidthDelta: 0,
|
|
||||||
availableLayers: []int32{0, 1, 2},
|
|
||||||
exemptedLayers: []int32{0},
|
|
||||||
bitrates: emptyBitrates,
|
|
||||||
targetLayers: expectedTargetLayers,
|
|
||||||
distanceToDesired: 0,
|
|
||||||
}
|
|
||||||
result = f.AllocateOptimal(emptyBitrates, true)
|
|
||||||
require.Equal(t, expectedResult, result)
|
|
||||||
require.Equal(t, expectedResult, f.lastAllocation)
|
|
||||||
require.Equal(t, expectedTargetLayers, f.TargetLayers())
|
|
||||||
|
|
||||||
// allocate using bitrates, allocation should choose optimal
|
|
||||||
f.currentLayers = InvalidLayers
|
|
||||||
f.UpTrackLayersChange([]int32{0, 1, 2}, []int32{})
|
|
||||||
f.maxLayers = VideoLayers{Spatial: 1, Temporal: 3}
|
|
||||||
expectedTargetLayers = VideoLayers{
|
|
||||||
Spatial: 1,
|
|
||||||
Temporal: 3,
|
|
||||||
}
|
|
||||||
expectedResult = VideoAllocation{
|
|
||||||
bandwidthRequested: bitrates[1][3],
|
|
||||||
bandwidthDelta: bitrates[1][3],
|
|
||||||
availableLayers: []int32{0, 1, 2},
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: expectedTargetLayers,
|
targetLayers: expectedTargetLayers,
|
||||||
|
maxLayers: expectedMaxLayers,
|
||||||
distanceToDesired: 0,
|
distanceToDesired: 0,
|
||||||
}
|
}
|
||||||
result = f.AllocateOptimal(bitrates, true)
|
result = f.AllocateOptimal(bitrates, true)
|
||||||
@@ -346,7 +247,6 @@ func TestForwarderAllocateOptimal(t *testing.T) {
|
|||||||
require.Equal(t, expectedTargetLayers, f.TargetLayers())
|
require.Equal(t, expectedTargetLayers, f.TargetLayers())
|
||||||
|
|
||||||
// allocate using bitrates above maximum layer, allowing overshoot
|
// allocate using bitrates above maximum layer, allowing overshoot
|
||||||
f.UpTrackLayersChange([]int32{2}, []int32{})
|
|
||||||
sparseBitrates := Bitrates{
|
sparseBitrates := Bitrates{
|
||||||
{0, 0, 0, 0},
|
{0, 0, 0, 0},
|
||||||
{0, 0, 0, 0},
|
{0, 0, 0, 0},
|
||||||
@@ -358,10 +258,10 @@ func TestForwarderAllocateOptimal(t *testing.T) {
|
|||||||
}
|
}
|
||||||
expectedResult = VideoAllocation{
|
expectedResult = VideoAllocation{
|
||||||
bandwidthRequested: sparseBitrates[2][1],
|
bandwidthRequested: sparseBitrates[2][1],
|
||||||
bandwidthDelta: sparseBitrates[2][1] - bitrates[1][3],
|
bandwidthDelta: sparseBitrates[2][1] - bitrates[0][1],
|
||||||
availableLayers: []int32{2},
|
|
||||||
bitrates: sparseBitrates,
|
bitrates: sparseBitrates,
|
||||||
targetLayers: expectedTargetLayers,
|
targetLayers: expectedTargetLayers,
|
||||||
|
maxLayers: expectedMaxLayers,
|
||||||
distanceToDesired: -1,
|
distanceToDesired: -1,
|
||||||
}
|
}
|
||||||
result = f.AllocateOptimal(sparseBitrates, true)
|
result = f.AllocateOptimal(sparseBitrates, true)
|
||||||
@@ -370,21 +270,73 @@ func TestForwarderAllocateOptimal(t *testing.T) {
|
|||||||
require.Equal(t, InvalidLayers, f.CurrentLayers())
|
require.Equal(t, InvalidLayers, f.CurrentLayers())
|
||||||
require.Equal(t, expectedTargetLayers, f.TargetLayers())
|
require.Equal(t, expectedTargetLayers, f.TargetLayers())
|
||||||
|
|
||||||
// when not allowing overshoot, should leave it at current (current is InvalidLayers in this test)
|
// when not allowing overshoot, should leave it at current when started and current is valid
|
||||||
|
sparseBitrates[1][2] = 10
|
||||||
|
sparseBitrates[2][1] = 0
|
||||||
|
f.started = true
|
||||||
|
f.currentLayers = VideoLayers{Spatial: 0, Temporal: 1}
|
||||||
|
expectedTargetLayers = VideoLayers{
|
||||||
|
Spatial: 0,
|
||||||
|
Temporal: 1,
|
||||||
|
}
|
||||||
expectedResult = VideoAllocation{
|
expectedResult = VideoAllocation{
|
||||||
pauseReason: VideoPauseReasonFeedDry,
|
pauseReason: VideoPauseReasonFeedDry,
|
||||||
bandwidthRequested: 0,
|
bandwidthRequested: 0,
|
||||||
bandwidthDelta: -sparseBitrates[2][1],
|
bandwidthDelta: -7,
|
||||||
availableLayers: []int32{2},
|
|
||||||
bitrates: sparseBitrates,
|
bitrates: sparseBitrates,
|
||||||
targetLayers: InvalidLayers,
|
targetLayers: expectedTargetLayers,
|
||||||
|
maxLayers: expectedMaxLayers,
|
||||||
distanceToDesired: 0,
|
distanceToDesired: 0,
|
||||||
}
|
}
|
||||||
result = f.AllocateOptimal(sparseBitrates, false)
|
result = f.AllocateOptimal(sparseBitrates, false)
|
||||||
require.Equal(t, expectedResult, result)
|
require.Equal(t, expectedResult, result)
|
||||||
require.Equal(t, expectedResult, f.lastAllocation)
|
require.Equal(t, expectedResult, f.lastAllocation)
|
||||||
|
require.Equal(t, expectedTargetLayers, f.CurrentLayers())
|
||||||
|
require.Equal(t, expectedTargetLayers, f.TargetLayers())
|
||||||
|
|
||||||
|
// when not allowing overshoot, should leave it at max when started and current is not valid
|
||||||
|
sparseBitrates[1][2] = 0
|
||||||
|
sparseBitrates[2][1] = 7
|
||||||
|
f.started = true
|
||||||
|
f.currentLayers = InvalidLayers
|
||||||
|
expectedTargetLayers = VideoLayers{
|
||||||
|
Spatial: 2,
|
||||||
|
Temporal: 3,
|
||||||
|
}
|
||||||
|
expectedResult = VideoAllocation{
|
||||||
|
pauseReason: VideoPauseReasonFeedDry,
|
||||||
|
bandwidthRequested: 0,
|
||||||
|
bandwidthDelta: 0,
|
||||||
|
bitrates: sparseBitrates,
|
||||||
|
targetLayers: expectedTargetLayers,
|
||||||
|
maxLayers: expectedMaxLayers,
|
||||||
|
distanceToDesired: -1,
|
||||||
|
}
|
||||||
|
result = f.AllocateOptimal(sparseBitrates, false)
|
||||||
|
require.Equal(t, expectedResult, result)
|
||||||
|
require.Equal(t, expectedResult, f.lastAllocation)
|
||||||
require.Equal(t, InvalidLayers, f.CurrentLayers())
|
require.Equal(t, InvalidLayers, f.CurrentLayers())
|
||||||
require.Equal(t, InvalidLayers, f.TargetLayers())
|
require.Equal(t, expectedTargetLayers, f.TargetLayers())
|
||||||
|
|
||||||
|
// when not allowing overshoot, should leave it at max for opportunistic forwarding when not started
|
||||||
|
f.started = false
|
||||||
|
f.targetLayers = VideoLayers{Spatial: 2, Temporal: 3}
|
||||||
|
sparseBitrates[1][2] = 10
|
||||||
|
sparseBitrates[2][1] = 0
|
||||||
|
expectedResult = VideoAllocation{
|
||||||
|
pauseReason: VideoPauseReasonFeedDry,
|
||||||
|
bandwidthRequested: 0,
|
||||||
|
bandwidthDelta: 0,
|
||||||
|
bitrates: sparseBitrates,
|
||||||
|
targetLayers: expectedTargetLayers,
|
||||||
|
maxLayers: expectedMaxLayers,
|
||||||
|
distanceToDesired: -1,
|
||||||
|
}
|
||||||
|
result = f.AllocateOptimal(sparseBitrates, false)
|
||||||
|
require.Equal(t, expectedResult, result)
|
||||||
|
require.Equal(t, expectedResult, f.lastAllocation)
|
||||||
|
require.Equal(t, InvalidLayers, f.CurrentLayers())
|
||||||
|
require.Equal(t, DefaultMaxLayers, f.TargetLayers())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestForwarderProvisionalAllocate(t *testing.T) {
|
func TestForwarderProvisionalAllocate(t *testing.T) {
|
||||||
@@ -392,14 +344,12 @@ func TestForwarderProvisionalAllocate(t *testing.T) {
|
|||||||
f.SetMaxSpatialLayer(DefaultMaxLayerSpatial)
|
f.SetMaxSpatialLayer(DefaultMaxLayerSpatial)
|
||||||
f.SetMaxTemporalLayer(DefaultMaxLayerTemporal)
|
f.SetMaxTemporalLayer(DefaultMaxLayerTemporal)
|
||||||
|
|
||||||
availableLayers := []int32{0, 1, 2}
|
|
||||||
bitrates := Bitrates{
|
bitrates := Bitrates{
|
||||||
{1, 2, 3, 4},
|
{1, 2, 3, 4},
|
||||||
{5, 6, 7, 8},
|
{5, 6, 7, 8},
|
||||||
{9, 10, 11, 12},
|
{9, 10, 11, 12},
|
||||||
}
|
}
|
||||||
|
|
||||||
f.availableLayers = availableLayers
|
|
||||||
f.ProvisionalAllocatePrepare(bitrates)
|
f.ProvisionalAllocatePrepare(bitrates)
|
||||||
|
|
||||||
usedBitrate := f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 0, Temporal: 0}, true, false)
|
usedBitrate := f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 0, Temporal: 0}, true, false)
|
||||||
@@ -427,9 +377,9 @@ func TestForwarderProvisionalAllocate(t *testing.T) {
|
|||||||
isDeficient: true,
|
isDeficient: true,
|
||||||
bandwidthRequested: bitrates[1][2],
|
bandwidthRequested: bitrates[1][2],
|
||||||
bandwidthDelta: bitrates[1][2],
|
bandwidthDelta: bitrates[1][2],
|
||||||
availableLayers: availableLayers,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: expectedTargetLayers,
|
targetLayers: expectedTargetLayers,
|
||||||
|
maxLayers: DefaultMaxLayers,
|
||||||
distanceToDesired: 5,
|
distanceToDesired: 5,
|
||||||
}
|
}
|
||||||
result := f.ProvisionalAllocateCommit()
|
result := f.ProvisionalAllocateCommit()
|
||||||
@@ -452,9 +402,9 @@ func TestForwarderProvisionalAllocate(t *testing.T) {
|
|||||||
isDeficient: true,
|
isDeficient: true,
|
||||||
bandwidthRequested: bitrates[0][0],
|
bandwidthRequested: bitrates[0][0],
|
||||||
bandwidthDelta: bitrates[0][0] - bitrates[1][2],
|
bandwidthDelta: bitrates[0][0] - bitrates[1][2],
|
||||||
availableLayers: availableLayers,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: expectedTargetLayers,
|
targetLayers: expectedTargetLayers,
|
||||||
|
maxLayers: DefaultMaxLayers,
|
||||||
distanceToDesired: 11,
|
distanceToDesired: 11,
|
||||||
}
|
}
|
||||||
result = f.ProvisionalAllocateCommit()
|
result = f.ProvisionalAllocateCommit()
|
||||||
@@ -465,19 +415,14 @@ func TestForwarderProvisionalAllocate(t *testing.T) {
|
|||||||
//
|
//
|
||||||
// Test allowOvershoot.
|
// Test allowOvershoot.
|
||||||
// Max spatial set to 0 and layer 0 bit rates are not available.
|
// Max spatial set to 0 and layer 0 bit rates are not available.
|
||||||
// Layer 0 is exempted layer.
|
|
||||||
//
|
//
|
||||||
f.SetMaxSpatialLayer(0)
|
f.SetMaxSpatialLayer(0)
|
||||||
availableLayers = []int32{0, 1, 2}
|
|
||||||
exemptedLayers := []int32{0}
|
|
||||||
bitrates = Bitrates{
|
bitrates = Bitrates{
|
||||||
{0, 0, 0, 0},
|
{0, 0, 0, 0},
|
||||||
{5, 6, 7, 8},
|
{5, 6, 7, 8},
|
||||||
{9, 10, 11, 12},
|
{9, 10, 11, 12},
|
||||||
}
|
}
|
||||||
|
|
||||||
f.availableLayers = availableLayers
|
|
||||||
f.exemptedLayers = exemptedLayers
|
|
||||||
f.ProvisionalAllocatePrepare(bitrates)
|
f.ProvisionalAllocatePrepare(bitrates)
|
||||||
|
|
||||||
usedBitrate = f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 0, Temporal: 0}, false, true)
|
usedBitrate = f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 0, Temporal: 0}, false, true)
|
||||||
@@ -496,13 +441,16 @@ func TestForwarderProvisionalAllocate(t *testing.T) {
|
|||||||
Spatial: 1,
|
Spatial: 1,
|
||||||
Temporal: 3,
|
Temporal: 3,
|
||||||
}
|
}
|
||||||
|
expectedMaxLayers := VideoLayers{
|
||||||
|
Spatial: 0,
|
||||||
|
Temporal: 3,
|
||||||
|
}
|
||||||
expectedResult = VideoAllocation{
|
expectedResult = VideoAllocation{
|
||||||
bandwidthRequested: bitrates[1][3],
|
bandwidthRequested: bitrates[1][3],
|
||||||
bandwidthDelta: bitrates[1][3] - 1, // 1 is the last allocation bandwith requested
|
bandwidthDelta: bitrates[1][3] - 1, // 1 is the last allocation bandwith requested
|
||||||
availableLayers: availableLayers,
|
|
||||||
exemptedLayers: exemptedLayers,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: expectedTargetLayers,
|
targetLayers: expectedTargetLayers,
|
||||||
|
maxLayers: expectedMaxLayers,
|
||||||
distanceToDesired: -4,
|
distanceToDesired: -4,
|
||||||
}
|
}
|
||||||
result = f.ProvisionalAllocateCommit()
|
result = f.ProvisionalAllocateCommit()
|
||||||
@@ -511,25 +459,18 @@ func TestForwarderProvisionalAllocate(t *testing.T) {
|
|||||||
require.Equal(t, expectedTargetLayers, f.TargetLayers())
|
require.Equal(t, expectedTargetLayers, f.TargetLayers())
|
||||||
|
|
||||||
//
|
//
|
||||||
// Test exemptedLayers
|
// Even if overshoot is allowed, but if higher layers do not have bit rates, should continue with current layer.
|
||||||
// Even if overshoot is allowed, but if higher layers do not have bit rates and the current layer is exempted,
|
|
||||||
// should continue with current layer.
|
|
||||||
//
|
//
|
||||||
f.SetMaxSpatialLayer(0)
|
|
||||||
availableLayers = []int32{0, 1, 2}
|
|
||||||
exemptedLayers = []int32{0}
|
|
||||||
bitrates = Bitrates{
|
bitrates = Bitrates{
|
||||||
{0, 0, 0, 0},
|
{0, 0, 0, 0},
|
||||||
{0, 0, 0, 0},
|
{0, 0, 0, 0},
|
||||||
{0, 0, 0, 0},
|
{0, 0, 0, 0},
|
||||||
}
|
}
|
||||||
|
|
||||||
f.availableLayers = availableLayers
|
|
||||||
f.exemptedLayers = exemptedLayers
|
|
||||||
f.currentLayers = VideoLayers{Spatial: 0, Temporal: 2}
|
f.currentLayers = VideoLayers{Spatial: 0, Temporal: 2}
|
||||||
f.ProvisionalAllocatePrepare(bitrates)
|
f.ProvisionalAllocatePrepare(bitrates)
|
||||||
|
|
||||||
// all the provisional allocations below should fall back to exempted layer
|
// all the provisional allocations should not succeed because the feed is dry
|
||||||
usedBitrate = f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 0, Temporal: 0}, false, true)
|
usedBitrate = f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 0, Temporal: 0}, false, true)
|
||||||
require.Equal(t, int64(0), usedBitrate)
|
require.Equal(t, int64(0), usedBitrate)
|
||||||
|
|
||||||
@@ -541,7 +482,7 @@ func TestForwarderProvisionalAllocate(t *testing.T) {
|
|||||||
usedBitrate = f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 1, Temporal: 3}, false, true)
|
usedBitrate = f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 1, Temporal: 3}, false, true)
|
||||||
require.Equal(t, int64(0), usedBitrate)
|
require.Equal(t, int64(0), usedBitrate)
|
||||||
|
|
||||||
// committing should set target to (0, 2)
|
// committing should set target to (0, 2), i. e. leave it at current for opportunistic forwarding
|
||||||
expectedTargetLayers = VideoLayers{
|
expectedTargetLayers = VideoLayers{
|
||||||
Spatial: 0,
|
Spatial: 0,
|
||||||
Temporal: 2,
|
Temporal: 2,
|
||||||
@@ -550,10 +491,9 @@ func TestForwarderProvisionalAllocate(t *testing.T) {
|
|||||||
pauseReason: VideoPauseReasonFeedDry,
|
pauseReason: VideoPauseReasonFeedDry,
|
||||||
bandwidthRequested: bitrates[0][2],
|
bandwidthRequested: bitrates[0][2],
|
||||||
bandwidthDelta: bitrates[0][2] - 8, // 8 is the last allocation bandwith requested
|
bandwidthDelta: bitrates[0][2] - 8, // 8 is the last allocation bandwith requested
|
||||||
availableLayers: availableLayers,
|
|
||||||
exemptedLayers: exemptedLayers,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: expectedTargetLayers,
|
targetLayers: expectedTargetLayers,
|
||||||
|
maxLayers: expectedMaxLayers,
|
||||||
distanceToDesired: 0,
|
distanceToDesired: 0,
|
||||||
}
|
}
|
||||||
result = f.ProvisionalAllocateCommit()
|
result = f.ProvisionalAllocateCommit()
|
||||||
@@ -562,23 +502,12 @@ func TestForwarderProvisionalAllocate(t *testing.T) {
|
|||||||
require.Equal(t, expectedTargetLayers, f.TargetLayers())
|
require.Equal(t, expectedTargetLayers, f.TargetLayers())
|
||||||
|
|
||||||
//
|
//
|
||||||
// Test currentLayers not in exemptedLayers
|
// Same case as above, but current is above max, so target should go to invalid
|
||||||
//
|
//
|
||||||
f.SetMaxSpatialLayer(0)
|
|
||||||
availableLayers = []int32{0, 1, 2}
|
|
||||||
exemptedLayers = []int32{0}
|
|
||||||
bitrates = Bitrates{
|
|
||||||
{0, 0, 0, 0},
|
|
||||||
{0, 0, 0, 0},
|
|
||||||
{0, 0, 0, 0},
|
|
||||||
}
|
|
||||||
|
|
||||||
f.availableLayers = availableLayers
|
|
||||||
f.exemptedLayers = exemptedLayers
|
|
||||||
f.currentLayers = VideoLayers{Spatial: 1, Temporal: 2}
|
f.currentLayers = VideoLayers{Spatial: 1, Temporal: 2}
|
||||||
f.ProvisionalAllocatePrepare(bitrates)
|
f.ProvisionalAllocatePrepare(bitrates)
|
||||||
|
|
||||||
// all the provisional allocations below should not succeed
|
// all the provisional allocations below should not succeed because the feed is dry
|
||||||
usedBitrate = f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 0, Temporal: 0}, false, true)
|
usedBitrate = f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 0, Temporal: 0}, false, true)
|
||||||
require.Equal(t, int64(0), usedBitrate)
|
require.Equal(t, int64(0), usedBitrate)
|
||||||
|
|
||||||
@@ -594,20 +523,22 @@ func TestForwarderProvisionalAllocate(t *testing.T) {
|
|||||||
pauseReason: VideoPauseReasonFeedDry,
|
pauseReason: VideoPauseReasonFeedDry,
|
||||||
bandwidthRequested: 0,
|
bandwidthRequested: 0,
|
||||||
bandwidthDelta: 0,
|
bandwidthDelta: 0,
|
||||||
availableLayers: availableLayers,
|
|
||||||
exemptedLayers: exemptedLayers,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: InvalidLayers,
|
targetLayers: InvalidLayers,
|
||||||
|
maxLayers: expectedMaxLayers,
|
||||||
distanceToDesired: 0,
|
distanceToDesired: 0,
|
||||||
}
|
}
|
||||||
result = f.ProvisionalAllocateCommit()
|
result = f.ProvisionalAllocateCommit()
|
||||||
require.Equal(t, expectedResult, result)
|
require.Equal(t, expectedResult, result)
|
||||||
require.Equal(t, expectedResult, f.lastAllocation)
|
require.Equal(t, expectedResult, f.lastAllocation)
|
||||||
require.Equal(t, InvalidLayers, f.TargetLayers())
|
require.Equal(t, InvalidLayers, f.TargetLayers())
|
||||||
|
require.Equal(t, InvalidLayers, f.CurrentLayers())
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestForwarderProvisionalAllocateMute(t *testing.T) {
|
func TestForwarderProvisionalAllocateMute(t *testing.T) {
|
||||||
f := newForwarder(testutils.TestVP8Codec, webrtc.RTPCodecTypeVideo)
|
f := newForwarder(testutils.TestVP8Codec, webrtc.RTPCodecTypeVideo)
|
||||||
|
f.SetMaxSpatialLayer(DefaultMaxLayerSpatial)
|
||||||
|
f.SetMaxTemporalLayer(DefaultMaxLayerTemporal)
|
||||||
|
|
||||||
bitrates := Bitrates{
|
bitrates := Bitrates{
|
||||||
{1, 2, 3, 4},
|
{1, 2, 3, 4},
|
||||||
@@ -629,9 +560,9 @@ func TestForwarderProvisionalAllocateMute(t *testing.T) {
|
|||||||
pauseReason: VideoPauseReasonMuted,
|
pauseReason: VideoPauseReasonMuted,
|
||||||
bandwidthRequested: 0,
|
bandwidthRequested: 0,
|
||||||
bandwidthDelta: 0,
|
bandwidthDelta: 0,
|
||||||
availableLayers: nil,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: InvalidLayers,
|
targetLayers: InvalidLayers,
|
||||||
|
maxLayers: DefaultMaxLayers,
|
||||||
distanceToDesired: 0,
|
distanceToDesired: 0,
|
||||||
}
|
}
|
||||||
result := f.ProvisionalAllocateCommit()
|
result := f.ProvisionalAllocateCommit()
|
||||||
@@ -645,14 +576,12 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
|||||||
f.SetMaxSpatialLayer(DefaultMaxLayerSpatial)
|
f.SetMaxSpatialLayer(DefaultMaxLayerSpatial)
|
||||||
f.SetMaxTemporalLayer(DefaultMaxLayerTemporal)
|
f.SetMaxTemporalLayer(DefaultMaxLayerTemporal)
|
||||||
|
|
||||||
availableLayers := []int32{0, 1, 2}
|
|
||||||
bitrates := Bitrates{
|
bitrates := Bitrates{
|
||||||
{1, 2, 3, 4},
|
{1, 2, 3, 4},
|
||||||
{5, 6, 7, 8},
|
{5, 6, 7, 8},
|
||||||
{9, 10, 0, 0},
|
{9, 10, 0, 0},
|
||||||
}
|
}
|
||||||
|
|
||||||
f.availableLayers = availableLayers
|
|
||||||
f.ProvisionalAllocatePrepare(bitrates)
|
f.ProvisionalAllocatePrepare(bitrates)
|
||||||
|
|
||||||
// from scratch (InvalidLayers) should give back layer (0, 0)
|
// from scratch (InvalidLayers) should give back layer (0, 0)
|
||||||
@@ -670,9 +599,9 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
|||||||
isDeficient: true,
|
isDeficient: true,
|
||||||
bandwidthRequested: 1,
|
bandwidthRequested: 1,
|
||||||
bandwidthDelta: 1,
|
bandwidthDelta: 1,
|
||||||
availableLayers: availableLayers,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: expectedLayers,
|
targetLayers: expectedLayers,
|
||||||
|
maxLayers: DefaultMaxLayers,
|
||||||
distanceToDesired: 9,
|
distanceToDesired: 9,
|
||||||
}
|
}
|
||||||
result := f.ProvisionalAllocateCommit()
|
result := f.ProvisionalAllocateCommit()
|
||||||
@@ -697,9 +626,9 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
|||||||
expectedResult = VideoAllocation{
|
expectedResult = VideoAllocation{
|
||||||
bandwidthRequested: 10,
|
bandwidthRequested: 10,
|
||||||
bandwidthDelta: 0,
|
bandwidthDelta: 0,
|
||||||
availableLayers: availableLayers,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: expectedLayers,
|
targetLayers: expectedLayers,
|
||||||
|
maxLayers: DefaultMaxLayers,
|
||||||
distanceToDesired: 0,
|
distanceToDesired: 0,
|
||||||
}
|
}
|
||||||
result = f.ProvisionalAllocateCommit()
|
result = f.ProvisionalAllocateCommit()
|
||||||
@@ -741,8 +670,6 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
|||||||
f.Mute(false)
|
f.Mute(false)
|
||||||
f.SetMaxSpatialLayer(0)
|
f.SetMaxSpatialLayer(0)
|
||||||
|
|
||||||
availableLayers = []int32{0, 1, 2}
|
|
||||||
exemptedLayers := []int32{0}
|
|
||||||
bitrates = Bitrates{
|
bitrates = Bitrates{
|
||||||
{0, 0, 0, 0},
|
{0, 0, 0, 0},
|
||||||
{5, 6, 7, 8},
|
{5, 6, 7, 8},
|
||||||
@@ -750,8 +677,6 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
f.targetLayers = InvalidLayers
|
f.targetLayers = InvalidLayers
|
||||||
f.availableLayers = availableLayers
|
|
||||||
f.exemptedLayers = exemptedLayers
|
|
||||||
f.ProvisionalAllocatePrepare(bitrates)
|
f.ProvisionalAllocatePrepare(bitrates)
|
||||||
|
|
||||||
// from scratch (InvalidLayers) should go to a layer past maximum as overshoot is allowed
|
// from scratch (InvalidLayers) should go to a layer past maximum as overshoot is allowed
|
||||||
@@ -765,13 +690,13 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
|||||||
|
|
||||||
// committing should set target to (1, 0)
|
// committing should set target to (1, 0)
|
||||||
expectedLayers = VideoLayers{Spatial: 1, Temporal: 0}
|
expectedLayers = VideoLayers{Spatial: 1, Temporal: 0}
|
||||||
|
expectedMaxLayers := VideoLayers{Spatial: 0, Temporal: DefaultMaxLayerTemporal}
|
||||||
expectedResult = VideoAllocation{
|
expectedResult = VideoAllocation{
|
||||||
bandwidthRequested: 5,
|
bandwidthRequested: 5,
|
||||||
bandwidthDelta: 5,
|
bandwidthDelta: 5,
|
||||||
availableLayers: availableLayers,
|
|
||||||
exemptedLayers: exemptedLayers,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: expectedLayers,
|
targetLayers: expectedLayers,
|
||||||
|
maxLayers: expectedMaxLayers,
|
||||||
distanceToDesired: -1,
|
distanceToDesired: -1,
|
||||||
}
|
}
|
||||||
result = f.ProvisionalAllocateCommit()
|
result = f.ProvisionalAllocateCommit()
|
||||||
@@ -779,11 +704,9 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
|||||||
require.Equal(t, expectedResult, f.lastAllocation)
|
require.Equal(t, expectedResult, f.lastAllocation)
|
||||||
require.Equal(t, expectedLayers, f.TargetLayers())
|
require.Equal(t, expectedLayers, f.TargetLayers())
|
||||||
|
|
||||||
// Test exemptedLayers matching current layers
|
//
|
||||||
f.SetMaxSpatialLayer(0)
|
// Test continuting at current layers when feed is dry
|
||||||
|
//
|
||||||
availableLayers = []int32{0, 1, 2}
|
|
||||||
exemptedLayers = []int32{0}
|
|
||||||
bitrates = Bitrates{
|
bitrates = Bitrates{
|
||||||
{0, 0, 0, 0},
|
{0, 0, 0, 0},
|
||||||
{0, 0, 0, 0},
|
{0, 0, 0, 0},
|
||||||
@@ -792,11 +715,9 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
|||||||
|
|
||||||
f.currentLayers = VideoLayers{Spatial: 0, Temporal: 2}
|
f.currentLayers = VideoLayers{Spatial: 0, Temporal: 2}
|
||||||
f.targetLayers = InvalidLayers
|
f.targetLayers = InvalidLayers
|
||||||
f.availableLayers = availableLayers
|
|
||||||
f.exemptedLayers = exemptedLayers
|
|
||||||
f.ProvisionalAllocatePrepare(bitrates)
|
f.ProvisionalAllocatePrepare(bitrates)
|
||||||
|
|
||||||
// from scratch (InvalidLayers) should go to an exempted layer
|
// from scratch (InvalidLayers) should go to current layer
|
||||||
// NOTE: targetLayer is set to InvalidLayers for testing, but in practice current layers valid and target layers invalid should not happen
|
// NOTE: targetLayer is set to InvalidLayers for testing, but in practice current layers valid and target layers invalid should not happen
|
||||||
expectedTransition = VideoTransition{
|
expectedTransition = VideoTransition{
|
||||||
from: InvalidLayers,
|
from: InvalidLayers,
|
||||||
@@ -811,10 +732,9 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
|||||||
expectedResult = VideoAllocation{
|
expectedResult = VideoAllocation{
|
||||||
bandwidthRequested: 0,
|
bandwidthRequested: 0,
|
||||||
bandwidthDelta: -5,
|
bandwidthDelta: -5,
|
||||||
availableLayers: availableLayers,
|
|
||||||
exemptedLayers: exemptedLayers,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: expectedLayers,
|
targetLayers: expectedLayers,
|
||||||
|
maxLayers: expectedMaxLayers,
|
||||||
distanceToDesired: 0,
|
distanceToDesired: 0,
|
||||||
}
|
}
|
||||||
result = f.ProvisionalAllocateCommit()
|
result = f.ProvisionalAllocateCommit()
|
||||||
@@ -822,31 +742,13 @@ func TestForwarderProvisionalAllocateGetCooperativeTransition(t *testing.T) {
|
|||||||
require.Equal(t, expectedResult, f.lastAllocation)
|
require.Equal(t, expectedResult, f.lastAllocation)
|
||||||
require.Equal(t, expectedLayers, f.TargetLayers())
|
require.Equal(t, expectedLayers, f.TargetLayers())
|
||||||
|
|
||||||
// Test exemptedLayers not matching current layers,
|
|
||||||
// leave target at current if no transition available to facilitate opportunistic forwarding
|
|
||||||
f.currentLayers = VideoLayers{Spatial: 2, Temporal: 2}
|
|
||||||
f.targetLayers = f.currentLayers
|
|
||||||
f.availableLayers = availableLayers
|
|
||||||
f.exemptedLayers = exemptedLayers
|
|
||||||
f.ProvisionalAllocatePrepare(bitrates)
|
|
||||||
|
|
||||||
expectedLayers = VideoLayers{Spatial: 2, Temporal: 2}
|
|
||||||
expectedTransition = VideoTransition{
|
|
||||||
from: VideoLayers{Spatial: 2, Temporal: 2},
|
|
||||||
to: expectedLayers,
|
|
||||||
bandwidthDelta: 0,
|
|
||||||
}
|
|
||||||
transition = f.ProvisionalAllocateGetCooperativeTransition(true)
|
|
||||||
require.Equal(t, expectedTransition, transition)
|
|
||||||
|
|
||||||
// committing should set target to current layers to enable opportunistic forwarding
|
// committing should set target to current layers to enable opportunistic forwarding
|
||||||
expectedResult = VideoAllocation{
|
expectedResult = VideoAllocation{
|
||||||
bandwidthRequested: 0,
|
bandwidthRequested: 0,
|
||||||
bandwidthDelta: 0,
|
bandwidthDelta: 0,
|
||||||
availableLayers: availableLayers,
|
|
||||||
exemptedLayers: exemptedLayers,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: expectedLayers,
|
targetLayers: expectedLayers,
|
||||||
|
maxLayers: expectedMaxLayers,
|
||||||
distanceToDesired: 0,
|
distanceToDesired: 0,
|
||||||
}
|
}
|
||||||
result = f.ProvisionalAllocateCommit()
|
result = f.ProvisionalAllocateCommit()
|
||||||
@@ -905,6 +807,7 @@ func TestForwarderAllocateNextHigher(t *testing.T) {
|
|||||||
require.False(t, boosted)
|
require.False(t, boosted)
|
||||||
|
|
||||||
// if layers have not caught up, should not allocate next layer even if deficient
|
// if layers have not caught up, should not allocate next layer even if deficient
|
||||||
|
f.lastAllocation.pauseReason = VideoPauseReasonNone
|
||||||
f.lastAllocation.isDeficient = true
|
f.lastAllocation.isDeficient = true
|
||||||
f.targetLayers = VideoLayers{
|
f.targetLayers = VideoLayers{
|
||||||
Spatial: 0,
|
Spatial: 0,
|
||||||
@@ -914,9 +817,9 @@ func TestForwarderAllocateNextHigher(t *testing.T) {
|
|||||||
isDeficient: true,
|
isDeficient: true,
|
||||||
bandwidthRequested: 0,
|
bandwidthRequested: 0,
|
||||||
bandwidthDelta: 0,
|
bandwidthDelta: 0,
|
||||||
availableLayers: nil,
|
|
||||||
bitrates: emptyBitrates,
|
bitrates: emptyBitrates,
|
||||||
targetLayers: InvalidLayers,
|
targetLayers: InvalidLayers,
|
||||||
|
maxLayers: InvalidLayers,
|
||||||
distanceToDesired: 0,
|
distanceToDesired: 0,
|
||||||
}
|
}
|
||||||
result, boosted = f.AllocateNextHigher(ChannelCapacityInfinity, bitrates, false)
|
result, boosted = f.AllocateNextHigher(ChannelCapacityInfinity, bitrates, false)
|
||||||
@@ -939,9 +842,9 @@ func TestForwarderAllocateNextHigher(t *testing.T) {
|
|||||||
isDeficient: true,
|
isDeficient: true,
|
||||||
bandwidthRequested: 2,
|
bandwidthRequested: 2,
|
||||||
bandwidthDelta: 0,
|
bandwidthDelta: 0,
|
||||||
availableLayers: nil,
|
|
||||||
bitrates: emptyBitrates,
|
bitrates: emptyBitrates,
|
||||||
targetLayers: InvalidLayers,
|
targetLayers: InvalidLayers,
|
||||||
|
maxLayers: InvalidLayers,
|
||||||
distanceToDesired: 0,
|
distanceToDesired: 0,
|
||||||
}
|
}
|
||||||
result, boosted = f.AllocateNextHigher(ChannelCapacityInfinity, emptyBitrates, false)
|
result, boosted = f.AllocateNextHigher(ChannelCapacityInfinity, emptyBitrates, false)
|
||||||
@@ -958,9 +861,9 @@ func TestForwarderAllocateNextHigher(t *testing.T) {
|
|||||||
isDeficient: true,
|
isDeficient: true,
|
||||||
bandwidthRequested: 3,
|
bandwidthRequested: 3,
|
||||||
bandwidthDelta: 1,
|
bandwidthDelta: 1,
|
||||||
availableLayers: nil,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: expectedTargetLayers,
|
targetLayers: expectedTargetLayers,
|
||||||
|
maxLayers: DefaultMaxLayers,
|
||||||
distanceToDesired: 3,
|
distanceToDesired: 3,
|
||||||
}
|
}
|
||||||
result, boosted = f.AllocateNextHigher(ChannelCapacityInfinity, bitrates, false)
|
result, boosted = f.AllocateNextHigher(ChannelCapacityInfinity, bitrates, false)
|
||||||
@@ -979,9 +882,9 @@ func TestForwarderAllocateNextHigher(t *testing.T) {
|
|||||||
isDeficient: true,
|
isDeficient: true,
|
||||||
bandwidthRequested: 4,
|
bandwidthRequested: 4,
|
||||||
bandwidthDelta: 1,
|
bandwidthDelta: 1,
|
||||||
availableLayers: nil,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: expectedTargetLayers,
|
targetLayers: expectedTargetLayers,
|
||||||
|
maxLayers: DefaultMaxLayers,
|
||||||
distanceToDesired: 2,
|
distanceToDesired: 2,
|
||||||
}
|
}
|
||||||
result, boosted = f.AllocateNextHigher(ChannelCapacityInfinity, bitrates, false)
|
result, boosted = f.AllocateNextHigher(ChannelCapacityInfinity, bitrates, false)
|
||||||
@@ -1001,9 +904,9 @@ func TestForwarderAllocateNextHigher(t *testing.T) {
|
|||||||
isDeficient: true,
|
isDeficient: true,
|
||||||
bandwidthRequested: 5,
|
bandwidthRequested: 5,
|
||||||
bandwidthDelta: 1,
|
bandwidthDelta: 1,
|
||||||
availableLayers: nil,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: expectedTargetLayers,
|
targetLayers: expectedTargetLayers,
|
||||||
|
maxLayers: DefaultMaxLayers,
|
||||||
distanceToDesired: 1,
|
distanceToDesired: 1,
|
||||||
}
|
}
|
||||||
result, boosted = f.AllocateNextHigher(ChannelCapacityInfinity, bitrates, false)
|
result, boosted = f.AllocateNextHigher(ChannelCapacityInfinity, bitrates, false)
|
||||||
@@ -1021,9 +924,9 @@ func TestForwarderAllocateNextHigher(t *testing.T) {
|
|||||||
expectedResult = VideoAllocation{
|
expectedResult = VideoAllocation{
|
||||||
bandwidthRequested: 7,
|
bandwidthRequested: 7,
|
||||||
bandwidthDelta: 2,
|
bandwidthDelta: 2,
|
||||||
availableLayers: nil,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: expectedTargetLayers,
|
targetLayers: expectedTargetLayers,
|
||||||
|
maxLayers: DefaultMaxLayers,
|
||||||
distanceToDesired: 0,
|
distanceToDesired: 0,
|
||||||
}
|
}
|
||||||
result, boosted = f.AllocateNextHigher(ChannelCapacityInfinity, bitrates, false)
|
result, boosted = f.AllocateNextHigher(ChannelCapacityInfinity, bitrates, false)
|
||||||
@@ -1054,9 +957,9 @@ func TestForwarderAllocateNextHigher(t *testing.T) {
|
|||||||
isDeficient: true,
|
isDeficient: true,
|
||||||
bandwidthRequested: 2,
|
bandwidthRequested: 2,
|
||||||
bandwidthDelta: 2,
|
bandwidthDelta: 2,
|
||||||
availableLayers: nil,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: expectedTargetLayers,
|
targetLayers: expectedTargetLayers,
|
||||||
|
maxLayers: DefaultMaxLayers,
|
||||||
distanceToDesired: 4,
|
distanceToDesired: 4,
|
||||||
}
|
}
|
||||||
result, boosted = f.AllocateNextHigher(ChannelCapacityInfinity, bitrates, false)
|
result, boosted = f.AllocateNextHigher(ChannelCapacityInfinity, bitrates, false)
|
||||||
@@ -1070,9 +973,9 @@ func TestForwarderAllocateNextHigher(t *testing.T) {
|
|||||||
isDeficient: true,
|
isDeficient: true,
|
||||||
bandwidthRequested: 2,
|
bandwidthRequested: 2,
|
||||||
bandwidthDelta: 2,
|
bandwidthDelta: 2,
|
||||||
availableLayers: nil,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: expectedTargetLayers,
|
targetLayers: expectedTargetLayers,
|
||||||
|
maxLayers: DefaultMaxLayers,
|
||||||
distanceToDesired: 4,
|
distanceToDesired: 4,
|
||||||
}
|
}
|
||||||
result, boosted = f.AllocateNextHigher(0, bitrates, false)
|
result, boosted = f.AllocateNextHigher(0, bitrates, false)
|
||||||
@@ -1096,13 +999,16 @@ func TestForwarderAllocateNextHigher(t *testing.T) {
|
|||||||
Spatial: 1,
|
Spatial: 1,
|
||||||
Temporal: 0,
|
Temporal: 0,
|
||||||
}
|
}
|
||||||
|
expectedMaxLayers := VideoLayers{
|
||||||
|
Spatial: 0,
|
||||||
|
Temporal: DefaultMaxLayerTemporal,
|
||||||
|
}
|
||||||
expectedResult = VideoAllocation{
|
expectedResult = VideoAllocation{
|
||||||
bandwidthRequested: bitrates[1][0],
|
bandwidthRequested: bitrates[1][0],
|
||||||
bandwidthDelta: bitrates[1][0],
|
bandwidthDelta: bitrates[1][0],
|
||||||
availableLayers: nil,
|
|
||||||
exemptedLayers: nil,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: expectedTargetLayers,
|
targetLayers: expectedTargetLayers,
|
||||||
|
maxLayers: expectedMaxLayers,
|
||||||
distanceToDesired: -1,
|
distanceToDesired: -1,
|
||||||
}
|
}
|
||||||
// overshoot should return (1, 0) even if there is not enough capacity
|
// overshoot should return (1, 0) even if there is not enough capacity
|
||||||
@@ -1118,14 +1024,12 @@ func TestForwarderPause(t *testing.T) {
|
|||||||
f.SetMaxSpatialLayer(DefaultMaxLayerSpatial)
|
f.SetMaxSpatialLayer(DefaultMaxLayerSpatial)
|
||||||
f.SetMaxTemporalLayer(DefaultMaxLayerTemporal)
|
f.SetMaxTemporalLayer(DefaultMaxLayerTemporal)
|
||||||
|
|
||||||
availableLayers := []int32{0, 1, 2}
|
|
||||||
bitrates := Bitrates{
|
bitrates := Bitrates{
|
||||||
{1, 2, 3, 4},
|
{1, 2, 3, 4},
|
||||||
{5, 6, 7, 8},
|
{5, 6, 7, 8},
|
||||||
{9, 10, 11, 12},
|
{9, 10, 11, 12},
|
||||||
}
|
}
|
||||||
|
|
||||||
f.availableLayers = availableLayers
|
|
||||||
f.ProvisionalAllocatePrepare(bitrates)
|
f.ProvisionalAllocatePrepare(bitrates)
|
||||||
f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 0, Temporal: 0}, true, false)
|
f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 0, Temporal: 0}, true, false)
|
||||||
// should have set target at (0, 0)
|
// should have set target at (0, 0)
|
||||||
@@ -1136,9 +1040,9 @@ func TestForwarderPause(t *testing.T) {
|
|||||||
isDeficient: true,
|
isDeficient: true,
|
||||||
bandwidthRequested: 0,
|
bandwidthRequested: 0,
|
||||||
bandwidthDelta: 0 - bitrates[0][0],
|
bandwidthDelta: 0 - bitrates[0][0],
|
||||||
availableLayers: availableLayers,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: InvalidLayers,
|
targetLayers: InvalidLayers,
|
||||||
|
maxLayers: DefaultMaxLayers,
|
||||||
distanceToDesired: 12,
|
distanceToDesired: 12,
|
||||||
}
|
}
|
||||||
result := f.Pause(bitrates)
|
result := f.Pause(bitrates)
|
||||||
@@ -1152,14 +1056,12 @@ func TestForwarderPauseMute(t *testing.T) {
|
|||||||
f.SetMaxSpatialLayer(DefaultMaxLayerSpatial)
|
f.SetMaxSpatialLayer(DefaultMaxLayerSpatial)
|
||||||
f.SetMaxTemporalLayer(DefaultMaxLayerTemporal)
|
f.SetMaxTemporalLayer(DefaultMaxLayerTemporal)
|
||||||
|
|
||||||
availableLayers := []int32{0, 1, 2}
|
|
||||||
bitrates := Bitrates{
|
bitrates := Bitrates{
|
||||||
{1, 2, 3, 4},
|
{1, 2, 3, 4},
|
||||||
{5, 6, 7, 8},
|
{5, 6, 7, 8},
|
||||||
{9, 10, 11, 12},
|
{9, 10, 11, 12},
|
||||||
}
|
}
|
||||||
|
|
||||||
f.availableLayers = availableLayers
|
|
||||||
f.ProvisionalAllocatePrepare(bitrates)
|
f.ProvisionalAllocatePrepare(bitrates)
|
||||||
f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 0, Temporal: 0}, true, true)
|
f.ProvisionalAllocate(bitrates[2][3], VideoLayers{Spatial: 0, Temporal: 0}, true, true)
|
||||||
// should have set target at (0, 0)
|
// should have set target at (0, 0)
|
||||||
@@ -1170,9 +1072,9 @@ func TestForwarderPauseMute(t *testing.T) {
|
|||||||
pauseReason: VideoPauseReasonMuted,
|
pauseReason: VideoPauseReasonMuted,
|
||||||
bandwidthRequested: 0,
|
bandwidthRequested: 0,
|
||||||
bandwidthDelta: 0 - bitrates[0][0],
|
bandwidthDelta: 0 - bitrates[0][0],
|
||||||
availableLayers: availableLayers,
|
|
||||||
bitrates: bitrates,
|
bitrates: bitrates,
|
||||||
targetLayers: InvalidLayers,
|
targetLayers: InvalidLayers,
|
||||||
|
maxLayers: DefaultMaxLayers,
|
||||||
distanceToDesired: 0,
|
distanceToDesired: 0,
|
||||||
}
|
}
|
||||||
result := f.Pause(bitrates)
|
result := f.Pause(bitrates)
|
||||||
|
|||||||
+21
-10
@@ -30,8 +30,27 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type AudioLevelHandle func(level uint8, duration uint32)
|
type AudioLevelHandle func(level uint8, duration uint32)
|
||||||
|
|
||||||
|
// ---------------------------------------------------
|
||||||
|
|
||||||
type Bitrates [DefaultMaxLayerSpatial + 1][DefaultMaxLayerTemporal + 1]int64
|
type Bitrates [DefaultMaxLayerSpatial + 1][DefaultMaxLayerTemporal + 1]int64
|
||||||
|
|
||||||
|
func (b *Bitrates) GetLayers() []int32 {
|
||||||
|
layers := []int32{}
|
||||||
|
for i := 0; i < len(b); i++ {
|
||||||
|
for j := 0; j < len(b[0]); j++ {
|
||||||
|
if b[i][j] != 0 {
|
||||||
|
layers = append(layers, int32(i))
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return layers
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------
|
||||||
|
|
||||||
// TrackReceiver defines an interface receive media from remote peer
|
// TrackReceiver defines an interface receive media from remote peer
|
||||||
type TrackReceiver interface {
|
type TrackReceiver interface {
|
||||||
TrackID() livekit.TrackID
|
TrackID() livekit.TrackID
|
||||||
@@ -197,7 +216,6 @@ func NewWebRTCReceiver(
|
|||||||
w.streamTrackerManager = NewStreamTrackerManager(logger, trackInfo, w.isSVC, w.codec.ClockRate, trackersConfig)
|
w.streamTrackerManager = NewStreamTrackerManager(logger, trackInfo, w.isSVC, w.codec.ClockRate, trackersConfig)
|
||||||
w.streamTrackerManager.OnAvailableLayersChanged(w.downTrackLayerChange)
|
w.streamTrackerManager.OnAvailableLayersChanged(w.downTrackLayerChange)
|
||||||
w.streamTrackerManager.OnBitrateAvailabilityChanged(w.downTrackBitrateAvailabilityChange)
|
w.streamTrackerManager.OnBitrateAvailabilityChanged(w.downTrackBitrateAvailabilityChange)
|
||||||
w.streamTrackerManager.Start()
|
|
||||||
|
|
||||||
for _, opt := range opts {
|
for _, opt := range opts {
|
||||||
w = opt(w)
|
w = opt(w)
|
||||||
@@ -381,11 +399,6 @@ func (w *WebRTCReceiver) AddDownTrack(track TrackSender) error {
|
|||||||
w.logger.Infow("subscriberID already exists, replacing downtrack", "subscriberID", track.SubscriberID())
|
w.logger.Infow("subscriberID already exists, replacing downtrack", "subscriberID", track.SubscriberID())
|
||||||
}
|
}
|
||||||
|
|
||||||
if w.Kind() == webrtc.RTPCodecTypeVideo {
|
|
||||||
// notify added down track of available layers
|
|
||||||
availableLayers, exemptedLayers := w.streamTrackerManager.GetAvailableLayers()
|
|
||||||
track.UpTrackLayersChange(availableLayers, exemptedLayers)
|
|
||||||
}
|
|
||||||
track.TrackInfoAvailable()
|
track.TrackInfoAvailable()
|
||||||
|
|
||||||
w.downTrackSpreader.Store(track)
|
w.downTrackSpreader.Store(track)
|
||||||
@@ -396,9 +409,9 @@ func (w *WebRTCReceiver) SetMaxExpectedSpatialLayer(layer int32) {
|
|||||||
w.streamTrackerManager.SetMaxExpectedSpatialLayer(layer)
|
w.streamTrackerManager.SetMaxExpectedSpatialLayer(layer)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w *WebRTCReceiver) downTrackLayerChange(availableLayers []int32, exemptedLayers []int32) {
|
func (w *WebRTCReceiver) downTrackLayerChange() {
|
||||||
for _, dt := range w.downTrackSpreader.GetDownTracks() {
|
for _, dt := range w.downTrackSpreader.GetDownTracks() {
|
||||||
dt.UpTrackLayersChange(availableLayers, exemptedLayers)
|
dt.UpTrackLayersChange()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -563,8 +576,6 @@ func (w *WebRTCReceiver) forwardRTP(layer int32) {
|
|||||||
if pr := w.redReceiver.Load(); pr != nil {
|
if pr := w.redReceiver.Load(); pr != nil {
|
||||||
pr.(*RedReceiver).Close()
|
pr.(*RedReceiver).Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
w.streamTrackerManager.Stop()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
w.streamTrackerManager.RemoveTracker(layer)
|
w.streamTrackerManager.RemoveTracker(layer)
|
||||||
|
|||||||
@@ -217,6 +217,15 @@ func (s *StreamTracker) BitrateTemporalCumulative() []int64 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// clear higher layers
|
||||||
|
for i := 0; i < len(brs); i++ {
|
||||||
|
if brs[i] == 0 {
|
||||||
|
for j := i + 1; j < len(brs); j++ {
|
||||||
|
brs[j] = 0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return brs
|
return brs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+15
-103
@@ -7,7 +7,6 @@ import (
|
|||||||
"github.com/livekit/livekit-server/pkg/config"
|
"github.com/livekit/livekit-server/pkg/config"
|
||||||
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
||||||
"github.com/livekit/livekit-server/pkg/sfu/streamtracker"
|
"github.com/livekit/livekit-server/pkg/sfu/streamtracker"
|
||||||
"github.com/livekit/livekit-server/pkg/utils"
|
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
)
|
)
|
||||||
@@ -21,18 +20,15 @@ type StreamTrackerManager struct {
|
|||||||
|
|
||||||
trackerConfig config.StreamTrackerConfig
|
trackerConfig config.StreamTrackerConfig
|
||||||
|
|
||||||
layersNotifyOpQueue *utils.OpsQueue
|
|
||||||
|
|
||||||
lock sync.RWMutex
|
lock sync.RWMutex
|
||||||
|
|
||||||
trackers [DefaultMaxLayerSpatial + 1]*streamtracker.StreamTracker
|
trackers [DefaultMaxLayerSpatial + 1]*streamtracker.StreamTracker
|
||||||
|
|
||||||
availableLayers []int32
|
availableLayers []int32
|
||||||
exemptedLayers []int32
|
|
||||||
maxExpectedLayer int32
|
maxExpectedLayer int32
|
||||||
paused bool
|
paused bool
|
||||||
|
|
||||||
onAvailableLayersChanged func(availableLayers []int32, exemptedLayers []int32)
|
onAvailableLayersChanged func()
|
||||||
onBitrateAvailabilityChanged func()
|
onBitrateAvailabilityChanged func()
|
||||||
onMaxLayerChanged func(maxLayer int32)
|
onMaxLayerChanged func(maxLayer int32)
|
||||||
}
|
}
|
||||||
@@ -50,7 +46,6 @@ func NewStreamTrackerManager(
|
|||||||
isSVC: isSVC,
|
isSVC: isSVC,
|
||||||
maxPublishedLayer: 0,
|
maxPublishedLayer: 0,
|
||||||
clockRate: clockRate,
|
clockRate: clockRate,
|
||||||
layersNotifyOpQueue: utils.NewOpsQueue(logger, "layer-notify", 10),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch s.trackInfo.Source {
|
switch s.trackInfo.Source {
|
||||||
@@ -73,15 +68,7 @@ func NewStreamTrackerManager(
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StreamTrackerManager) Start() {
|
func (s *StreamTrackerManager) OnAvailableLayersChanged(f func()) {
|
||||||
s.layersNotifyOpQueue.Start()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *StreamTrackerManager) Stop() {
|
|
||||||
s.layersNotifyOpQueue.Stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *StreamTrackerManager) OnAvailableLayersChanged(f func(availableLayers []int32, exemptedLayers []int32)) {
|
|
||||||
s.onAvailableLayersChanged = f
|
s.onAvailableLayersChanged = f
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +132,6 @@ func (s *StreamTrackerManager) AddTracker(layer int32) *streamtracker.StreamTrac
|
|||||||
|
|
||||||
s.logger.Debugw("StreamTrackerManager add track", "layer", layer)
|
s.logger.Debugw("StreamTrackerManager add track", "layer", layer)
|
||||||
tracker.OnStatusChanged(func(status streamtracker.StreamStatus) {
|
tracker.OnStatusChanged(func(status streamtracker.StreamStatus) {
|
||||||
s.layersNotifyOpQueue.Enqueue(func() {
|
|
||||||
s.logger.Debugw("StreamTrackerManager OnStatusChanged", "layer", layer, "status", status)
|
s.logger.Debugw("StreamTrackerManager OnStatusChanged", "layer", layer, "status", status)
|
||||||
if status == streamtracker.StreamStatusStopped {
|
if status == streamtracker.StreamStatusStopped {
|
||||||
s.removeAvailableLayer(layer)
|
s.removeAvailableLayer(layer)
|
||||||
@@ -153,7 +139,6 @@ func (s *StreamTrackerManager) AddTracker(layer int32) *streamtracker.StreamTrac
|
|||||||
s.addAvailableLayer(layer)
|
s.addAvailableLayer(layer)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
|
||||||
tracker.OnBitrateAvailable(func() {
|
tracker.OnBitrateAvailable(func() {
|
||||||
if s.onBitrateAvailabilityChanged != nil {
|
if s.onBitrateAvailabilityChanged != nil {
|
||||||
s.onBitrateAvailabilityChanged()
|
s.onBitrateAvailabilityChanged()
|
||||||
@@ -188,7 +173,6 @@ func (s *StreamTrackerManager) RemoveAllTrackers() {
|
|||||||
s.trackers[layer] = nil
|
s.trackers[layer] = nil
|
||||||
}
|
}
|
||||||
s.availableLayers = make([]int32, 0)
|
s.availableLayers = make([]int32, 0)
|
||||||
s.exemptedLayers = make([]int32, 0)
|
|
||||||
s.maxExpectedLayer = DefaultMaxLayerSpatial
|
s.maxExpectedLayer = DefaultMaxLayerSpatial
|
||||||
s.paused = false
|
s.paused = false
|
||||||
s.lock.Unlock()
|
s.lock.Unlock()
|
||||||
@@ -353,26 +337,6 @@ func (s *StreamTrackerManager) GetLayeredBitrate() Bitrates {
|
|||||||
return br
|
return br
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StreamTrackerManager) GetAvailableLayers() ([]int32, []int32) {
|
|
||||||
s.lock.RLock()
|
|
||||||
defer s.lock.RUnlock()
|
|
||||||
|
|
||||||
var availableLayers []int32
|
|
||||||
availableLayers = append(availableLayers, s.availableLayers...)
|
|
||||||
|
|
||||||
var exemptedLayers []int32
|
|
||||||
exemptedLayers = append(exemptedLayers, s.exemptedLayers...)
|
|
||||||
|
|
||||||
return availableLayers, exemptedLayers
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *StreamTrackerManager) HasSpatialLayer(layer int32) bool {
|
|
||||||
s.lock.RLock()
|
|
||||||
defer s.lock.RUnlock()
|
|
||||||
|
|
||||||
return s.hasSpatialLayerLocked(layer)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *StreamTrackerManager) hasSpatialLayerLocked(layer int32) bool {
|
func (s *StreamTrackerManager) hasSpatialLayerLocked(layer int32) bool {
|
||||||
for _, l := range s.availableLayers {
|
for _, l := range s.availableLayers {
|
||||||
if l == layer {
|
if l == layer {
|
||||||
@@ -400,35 +364,21 @@ func (s *StreamTrackerManager) addAvailableLayer(layer int32) {
|
|||||||
s.availableLayers = append(s.availableLayers, layer)
|
s.availableLayers = append(s.availableLayers, layer)
|
||||||
sort.Slice(s.availableLayers, func(i, j int) bool { return s.availableLayers[i] < s.availableLayers[j] })
|
sort.Slice(s.availableLayers, func(i, j int) bool { return s.availableLayers[i] < s.availableLayers[j] })
|
||||||
|
|
||||||
for idx, el := range s.exemptedLayers {
|
// check if new layer is the max layer
|
||||||
if el == layer {
|
isMaxLayerChange := s.availableLayers[len(s.availableLayers)-1] == layer
|
||||||
s.exemptedLayers[idx] = s.exemptedLayers[len(s.exemptedLayers)-1]
|
|
||||||
s.exemptedLayers = s.exemptedLayers[:len(s.exemptedLayers)-1]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sort.Slice(s.exemptedLayers, func(i, j int) bool { return s.exemptedLayers[i] < s.exemptedLayers[j] })
|
|
||||||
|
|
||||||
var availableLayers []int32
|
|
||||||
availableLayers = append(availableLayers, s.availableLayers...)
|
|
||||||
|
|
||||||
var exemptedLayers []int32
|
|
||||||
exemptedLayers = append(exemptedLayers, s.exemptedLayers...)
|
|
||||||
s.lock.Unlock()
|
|
||||||
|
|
||||||
s.logger.Infow(
|
s.logger.Infow(
|
||||||
"available layers changed - layer seen",
|
"available layers changed - layer seen",
|
||||||
"added", layer,
|
"added", layer,
|
||||||
"availableLayers", availableLayers,
|
"availableLayers", s.availableLayers,
|
||||||
"exemptedLayers", exemptedLayers,
|
|
||||||
)
|
)
|
||||||
|
s.lock.Unlock()
|
||||||
|
|
||||||
if s.onAvailableLayersChanged != nil {
|
if s.onAvailableLayersChanged != nil {
|
||||||
s.onAvailableLayersChanged(availableLayers, exemptedLayers)
|
s.onAvailableLayersChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if new layer was the max layer
|
if isMaxLayerChange && s.onMaxLayerChanged != nil {
|
||||||
if availableLayers[len(availableLayers)-1] == layer && s.onMaxLayerChanged != nil {
|
|
||||||
s.onMaxLayerChanged(layer)
|
s.onMaxLayerChanged(layer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -440,52 +390,21 @@ func (s *StreamTrackerManager) removeAvailableLayer(layer int32) {
|
|||||||
prevMaxLayer = s.availableLayers[len(s.availableLayers)-1]
|
prevMaxLayer = s.availableLayers[len(s.availableLayers)-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// remove from available if not exempt
|
|
||||||
//
|
|
||||||
exempt := false
|
|
||||||
for _, l := range s.trackerConfig.ExemptedLayers {
|
|
||||||
if layer == l {
|
|
||||||
exempt = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if exempt {
|
|
||||||
if layer > s.maxExpectedLayer || s.paused {
|
|
||||||
exempt = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
newLayers := make([]int32, 0, DefaultMaxLayerSpatial+1)
|
newLayers := make([]int32, 0, DefaultMaxLayerSpatial+1)
|
||||||
for _, l := range s.availableLayers {
|
for _, l := range s.availableLayers {
|
||||||
// do not remove layers for non-simulcast
|
// do not remove layers for non-simulcast
|
||||||
if exempt || l != layer || len(s.trackInfo.Layers) < 2 {
|
if l != layer || len(s.trackInfo.Layers) < 2 {
|
||||||
newLayers = append(newLayers, l)
|
newLayers = append(newLayers, l)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sort.Slice(newLayers, func(i, j int) bool { return newLayers[i] < newLayers[j] })
|
sort.Slice(newLayers, func(i, j int) bool { return newLayers[i] < newLayers[j] })
|
||||||
s.availableLayers = newLayers
|
s.availableLayers = newLayers
|
||||||
|
|
||||||
//
|
s.logger.Infow(
|
||||||
// add to exempt if not already present
|
"available layers changed - layer gone",
|
||||||
//
|
"removed", layer,
|
||||||
if exempt {
|
"availableLayers", newLayers,
|
||||||
found := false
|
)
|
||||||
for _, el := range s.exemptedLayers {
|
|
||||||
if el == layer {
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !found {
|
|
||||||
s.exemptedLayers = append(s.exemptedLayers, layer)
|
|
||||||
sort.Slice(s.exemptedLayers, func(i, j int) bool { return s.exemptedLayers[i] < s.exemptedLayers[j] })
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var exemptedLayers []int32
|
|
||||||
exemptedLayers = append(exemptedLayers, s.exemptedLayers...)
|
|
||||||
|
|
||||||
curMaxLayer := InvalidLayerSpatial
|
curMaxLayer := InvalidLayerSpatial
|
||||||
if len(s.availableLayers) > 0 {
|
if len(s.availableLayers) > 0 {
|
||||||
@@ -493,16 +412,9 @@ func (s *StreamTrackerManager) removeAvailableLayer(layer int32) {
|
|||||||
}
|
}
|
||||||
s.lock.Unlock()
|
s.lock.Unlock()
|
||||||
|
|
||||||
s.logger.Infow(
|
|
||||||
"available layers changed - layer gone",
|
|
||||||
"removed", layer,
|
|
||||||
"availableLayers", newLayers,
|
|
||||||
"exeptedLayers", exemptedLayers,
|
|
||||||
)
|
|
||||||
|
|
||||||
// need to immediately switch off unavailable layers
|
// need to immediately switch off unavailable layers
|
||||||
if s.onAvailableLayersChanged != nil {
|
if s.onAvailableLayersChanged != nil {
|
||||||
s.onAvailableLayersChanged(newLayers, exemptedLayers)
|
s.onAvailableLayersChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
// if maxLayer was removed, send the new maxLayer
|
// if maxLayer was removed, send the new maxLayer
|
||||||
|
|||||||
Reference in New Issue
Block a user