Skip to content

Commit

Permalink
Make connection quality level depend on strategy (#1767)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcague authored Nov 22, 2021
1 parent fe3826e commit 58722d1
Show file tree
Hide file tree
Showing 15 changed files with 133 additions and 397 deletions.
4 changes: 2 additions & 2 deletions erizo/src/erizo/MediaStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ class MediaStream: public MediaSink, public MediaSource, public FeedbackSink,
int sendPLI() override;
void sendPLIToFeedback();
void setQualityLayer(int spatial_layer, int temporal_layer);
void enableSlideShowBelowSpatialLayer(bool enabled, int spatial_layer);
void enableFallbackBelowMinLayer(bool enabled);
virtual void enableSlideShowBelowSpatialLayer(bool enabled, int spatial_layer);
virtual void enableFallbackBelowMinLayer(bool enabled);
void setPeriodicKeyframeRequests(bool activate, uint32_t interval_in_ms = 0);

WebRTCEvent getCurrentState();
Expand Down
12 changes: 4 additions & 8 deletions erizo/src/erizo/WebRtcConnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,11 +312,10 @@ bool WebRtcConnection::createOfferSync(bool bundle) {
}

ConnectionQualityLevel WebRtcConnection::getConnectionQualityLevel() {
return connection_quality_check_.getLevel();
}

bool WebRtcConnection::werePacketLossesRecently() {
return connection_quality_check_.werePacketLossesRecently();
if (distributor_->tooLowBandwidthEstimation()) {
return ConnectionQualityLevel::VERY_LOW;
}
return ConnectionQualityLevel::GOOD;
}

void WebRtcConnection::associateMediaStreamToTransceiver(std::shared_ptr<MediaStream> media_stream,
Expand Down Expand Up @@ -996,9 +995,6 @@ void WebRtcConnection::onREMBFromTransport(RtcpHeader *chead, Transport *transpo
}

void WebRtcConnection::onRtcpFromTransport(std::shared_ptr<DataPacket> packet, Transport *transport) {
if (enable_connection_quality_check_) {
connection_quality_check_.onFeedback(packet, streams_);
}
RtpUtils::forEachRtcpBlock(packet, [this, packet, transport](RtcpHeader *chead) {
uint32_t ssrc = chead->isFeedback() ? chead->getSourceSSRC() : chead->getSSRC();
if (chead->isREMB()) {
Expand Down
9 changes: 6 additions & 3 deletions erizo/src/erizo/WebRtcConnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "./Transport.h"
#include "./Stats.h"
#include "bandwidth/BandwidthDistributionAlgorithm.h"
#include "bandwidth/ConnectionQualityCheck.h"
#include "bandwidth/BwDistributionConfig.h"
#include "pipeline/Pipeline.h"
#include "thread/Worker.h"
Expand All @@ -40,6 +39,12 @@ class IceConfig;
class MediaStream;
class Transceiver;

enum ConnectionQualityLevel {
VERY_LOW = 0,
LOW = 1,
GOOD = 2
};

/**
* WebRTC Events
*/
Expand Down Expand Up @@ -179,7 +184,6 @@ class WebRtcConnection: public TransportListener, public LogContext, public Hand
void write(std::shared_ptr<DataPacket> packet);
void notifyUpdateToHandlers() override;
ConnectionQualityLevel getConnectionQualityLevel();
bool werePacketLossesRecently();
void getJSONStats(std::function<void(std::string)> callback);

private:
Expand Down Expand Up @@ -238,7 +242,6 @@ class WebRtcConnection: public TransportListener, public LogContext, public Hand

std::unique_ptr<BandwidthDistributionAlgorithm> distributor_;
BwDistributionConfig bw_distribution_config_;
ConnectionQualityCheck connection_quality_check_;
bool enable_connection_quality_check_;
bool encrypt_transport_;
std::atomic <uint32_t> connection_target_bw_;
Expand Down
1 change: 1 addition & 0 deletions erizo/src/erizo/bandwidth/BandwidthDistributionAlgorithm.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class BandwidthDistributionAlgorithm {
virtual ~BandwidthDistributionAlgorithm() {}
virtual void distribute(uint32_t remb, uint32_t ssrc, std::vector<std::shared_ptr<MediaStream>> streams,
Transport *transport) = 0;
virtual bool tooLowBandwidthEstimation() = 0;
};

} // namespace erizo
Expand Down
127 changes: 0 additions & 127 deletions erizo/src/erizo/bandwidth/ConnectionQualityCheck.cpp

This file was deleted.

63 changes: 0 additions & 63 deletions erizo/src/erizo/bandwidth/ConnectionQualityCheck.h

This file was deleted.

1 change: 1 addition & 0 deletions erizo/src/erizo/bandwidth/MaxVideoBWDistributor.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class MaxVideoBWDistributor : public BandwidthDistributionAlgorithm {
virtual ~MaxVideoBWDistributor() {}
void distribute(uint32_t remb, uint32_t ssrc, std::vector<std::shared_ptr<MediaStream>> streams,
Transport *transport) override;
bool tooLowBandwidthEstimation() override { return false; }
};

} // namespace erizo
Expand Down
14 changes: 13 additions & 1 deletion erizo/src/erizo/bandwidth/StreamPriorityBWDistributor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace erizo {
DEFINE_LOGGER(StreamPriorityBWDistributor, "bandwidth.StreamPriorityBWDistributor");
StreamPriorityBWDistributor::StreamPriorityBWDistributor(StreamPriorityStrategy strategy,
std::shared_ptr<Stats>stats): strategy_{strategy}, stats_{stats} {
std::shared_ptr<Stats>stats): strategy_{strategy}, stats_{stats}, not_using_spatial_layers_{false} {
}

std::string StreamPriorityBWDistributor::getStrategyId() {
Expand All @@ -32,6 +32,10 @@ void StreamPriorityBWDistributor::distribute(uint32_t remb, uint32_t ssrc,
}
ELOG_DEBUG("Starting distribution with bitrate %lu for strategy %s", remaining_bitrate, getStrategyId().c_str());
strategy_.reset();

bool has_spatial_levels = false;
bool distribute_bitrate_to_spatial_levels = false;

while (strategy_.hasNextStep()) {
StreamPriorityStep step = strategy_.getNextStep();
std::string priority = step.priority;
Expand All @@ -54,11 +58,16 @@ void StreamPriorityBWDistributor::distribute(uint32_t remb, uint32_t ssrc,
}
continue;
}

has_spatial_levels = true;

if (remaining_bitrate == 0) {
ELOG_DEBUG("No more bitrate to distribute");
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 Down Expand Up @@ -106,6 +115,9 @@ void StreamPriorityBWDistributor::distribute(uint32_t remb, uint32_t ssrc,
remb, stream_info.stream->getId().c_str(), remaining_bitrate);
}
}

not_using_spatial_layers_ = has_spatial_levels && !distribute_bitrate_to_spatial_levels;

stats_->getNode()["total"].insertStat("unnasignedBitrate", CumulativeStat{remaining_bitrate});
for (const auto& kv_pair : stream_infos) {
for (MediaStreamPriorityInfo& stream_info : stream_infos[kv_pair.first]) {
Expand Down
3 changes: 3 additions & 0 deletions erizo/src/erizo/bandwidth/StreamPriorityBWDistributor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ DECLARE_LOGGER();
Transport *transport) override;
std::string getStrategyId();

bool tooLowBandwidthEstimation() override { return not_using_spatial_layers_; }

private:
StreamPriorityStrategy strategy_;
std::shared_ptr<Stats> stats_;
bool not_using_spatial_layers_;
};

} // namespace erizo
Expand Down
1 change: 1 addition & 0 deletions erizo/src/erizo/bandwidth/TargetVideoBWDistributor.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class TargetVideoBWDistributor : public BandwidthDistributionAlgorithm {
virtual ~TargetVideoBWDistributor() {}
void distribute(uint32_t remb, uint32_t ssrc, std::vector<std::shared_ptr<MediaStream>> streams,
Transport *transport) override;
bool tooLowBandwidthEstimation() override { return false; }
};

} // namespace erizo
Expand Down
Loading

0 comments on commit 58722d1

Please sign in to comment.