Skip to content

Commit

Permalink
Notify about low conn quality levels if bw is not enough for first la…
Browse files Browse the repository at this point in the history
…yers (#1776)
  • Loading branch information
jcague authored Dec 13, 2021
1 parent 654aa32 commit 2af0268
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 6 deletions.
12 changes: 12 additions & 0 deletions erizo/src/erizo/MediaStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1137,4 +1137,16 @@ uint64_t MediaStream::getBitrateForHigherTemporalInSpatialLayer(int spatial_laye
return 0;
}

uint64_t MediaStream::getBitrateForLowerTemporalInSpatialLayer(int spatial_layer) {
boost::mutex::scoped_lock lock(layer_bitrates_mutex_);
if (spatial_layer < 0) {
return 0;
}
if (static_cast<int>(layer_bitrates_.size()) > spatial_layer &&
layer_bitrates_[spatial_layer].size() > 0) {
return layer_bitrates_[spatial_layer][0];
}
return 0;
}

} // namespace erizo
1 change: 1 addition & 0 deletions erizo/src/erizo/MediaStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ class MediaStream: public MediaSink, public MediaSource, public FeedbackSink,
void setBitrateForLayer(int temporal_layer, int spatial_layer, uint64_t bitrate);
uint64_t getBitrateForLayer(int spatial_layer, int temporal_layer);
uint64_t getBitrateForHigherTemporalInSpatialLayer(int spatial_layer);
uint64_t getBitrateForLowerTemporalInSpatialLayer(int spatial_layer);

inline std::string toLog() {
return "id: " + stream_id_ + ", role:" + (is_publisher_ ? "publisher" : "subscriber")
Expand Down
23 changes: 17 additions & 6 deletions erizo/src/erizo/bandwidth/StreamPriorityBWDistributor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ void StreamPriorityBWDistributor::distribute(uint32_t remb, uint32_t ssrc,
break;
}

distribute_bitrate_to_spatial_levels = true;

bool is_max = step.isLevelMax();
int layer = step.getSpatialLayer();
ELOG_DEBUG("Step with priority %s, layer %d, is_max %u remaining %lu, bitrate assigned to priority %lu",
Expand All @@ -79,11 +77,18 @@ void StreamPriorityBWDistributor::distribute(uint32_t remb, uint32_t ssrc,
if (stream_infos[priority].size() > 0) {
remaining_avg_bitrate = remaining_bitrate / stream_infos[priority].size();
}
uint64_t bitrate_for_lower_temporal_in_spatial = 0;
for (MediaStreamPriorityInfo& stream_info : stream_infos[priority]) {
uint64_t needed_bitrate_for_stream = 0;
if (is_max) {
stream_info.stream->setTargetIsMaxVideoBW(true);
needed_bitrate_for_stream = stream_info.stream->getMaxVideoBW();
bitrate_for_lower_temporal_in_spatial = stream_info.stream->getBitrateForLowerTemporalInSpatialLayer(layer);

// We know that we will be able to send at least bytes from one stream.
if (remaining_avg_bitrate >= bitrate_for_lower_temporal_in_spatial) {
distribute_bitrate_to_spatial_levels = true;
}
} else if (!stream_info.stream->isSimulcast()) {
ELOG_DEBUG("Stream %s is not simulcast", stream_info.stream->getId());
int number_of_layers = strategy_.getHighestLayerForPriority(priority) + 1;
Expand All @@ -96,6 +101,12 @@ void StreamPriorityBWDistributor::distribute(uint32_t remb, uint32_t ssrc,
uint64_t bitrate_for_higher_temporal_in_spatial =
stream_info.stream->getBitrateForHigherTemporalInSpatialLayer(layer);
uint64_t max_bitrate_that_meets_constraints = stream_info.stream->getBitrateFromMaxQualityLayer();
bitrate_for_lower_temporal_in_spatial = stream_info.stream->getBitrateForLowerTemporalInSpatialLayer(layer);

// We know that we will be able to send at least bytes from one stream.
if (remaining_avg_bitrate >= bitrate_for_lower_temporal_in_spatial) {
distribute_bitrate_to_spatial_levels = true;
}

needed_bitrate_for_stream =
bitrate_for_higher_temporal_in_spatial == 0 ? max_bitrate_that_meets_constraints :
Expand All @@ -107,12 +118,12 @@ void StreamPriorityBWDistributor::distribute(uint32_t remb, uint32_t ssrc,
stream_info.assigned_bitrate = remb;
bitrate_for_priority[priority] += remb;
remaining_bitrate -= remb;
ELOG_DEBUG("needed_bitrate %lu, max_bitrate %u, bitrate %u, streams_in_priority %d",
ELOG_DEBUG("needed_bitrate %lu, max_bitrate %u, bitrate %u, streams_in_priority %d, min_bitrate %u",
needed_bitrate_for_stream,
stream_info.stream->getMaxVideoBW(),
bitrate, stream_infos[priority].size());
ELOG_DEBUG("Assigning bitrate %lu to stream %s, remaining %lu",
remb, stream_info.stream->getId().c_str(), remaining_bitrate);
bitrate, stream_infos[priority].size(), bitrate_for_lower_temporal_in_spatial);
ELOG_DEBUG("Assigning bitrate %lu to stream %s, remaining %lu, distribute_bitrate_to_spatial_levels %d",
remb, stream_info.stream->getId().c_str(), remaining_bitrate, distribute_bitrate_to_spatial_levels);
}
}

Expand Down
15 changes: 15 additions & 0 deletions erizo/src/test/bandwidth/StreamPriorityBWDistributor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,21 @@ INSTANTIATE_TEST_CASE_P(
StreamPriorityStep("20", "2")
},
100, EnabledList{1, 1, 1, 1}, ExpectedList{50, 50, 0, 0},
true),
make_tuple(StreamConfigList{
{1000, 0, 450, "20", std::vector<std::vector<uint64_t>>({ { 50, 150, 300 }, { 250, 300, 450} }), false, true},
{1000, 0, 450, "20", std::vector<std::vector<uint64_t>>({ { 50, 150, 300 }, { 250, 300, 450} }), false, true},
{1000, 0, 450, "0", std::vector<std::vector<uint64_t>>({ { 50, 150, 300 }, { 250, 300, 450} }), false, true},
{1000, 0, 450, "0", std::vector<std::vector<uint64_t>>({ { 50, 150, 300 }, { 250, 300, 450} }), false, true}
},
StrategyVector{
StreamPriorityStep("20", "0"),
StreamPriorityStep("10", "0"),
StreamPriorityStep("0", "0"),
StreamPriorityStep("20", "1"),
StreamPriorityStep("20", "2")
},
100, EnabledList{1, 1, 1, 1}, ExpectedList{50, 50, 0, 0},
false),
make_tuple(StreamConfigList{
{1000, 0, 450, "0", std::vector<std::vector<uint64_t>>({ { 100, 150, 200 }, { 250, 300, 450} }), false, true},
Expand Down
2 changes: 2 additions & 0 deletions erizo/src/test/log4cxx.properties
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,5 @@ log4j.logger.rtp.SRPacketHandler=ERROR
log4j.logger.rtp.SenderBandwidthEstimationHandler=ERROR
log4j.logger.rtp.StatsCalculator=ERROR
log4j.logger.rtp.RtpPaddingGeneratorHandler=ERROR

log4j.logger.bandwidth.StreamPriorityBWDistributor=ERROR

0 comments on commit 2af0268

Please sign in to comment.