Skip to content

Commit

Permalink
QualityManager cleanup (lynckia#1698)
Browse files Browse the repository at this point in the history
  • Loading branch information
jcague authored Apr 27, 2021
1 parent e87be72 commit 3bb99eb
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 86 deletions.
3 changes: 0 additions & 3 deletions erizo/src/erizo/MediaStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,6 @@ void MediaStream::initializePipeline() {
pipeline_->addFront(std::make_shared<PacketWriter>(this));
pipeline_->finalize();

if (connection_) {
quality_manager_->setConnectionQualityLevel(connection_->getConnectionQualityLevel());
}
pipeline_initialized_ = true;
}

Expand Down
73 changes: 4 additions & 69 deletions erizo/src/erizo/rtp/QualityManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,31 +12,24 @@ DEFINE_LOGGER(QualityManager, "rtp.QualityManager");
constexpr duration QualityManager::kMinLayerSwitchInterval;
constexpr duration QualityManager::kActiveLayerInterval;
constexpr float QualityManager::kIncreaseLayerBitrateThreshold;
constexpr duration QualityManager::kIncreaseConnectionQualityLevelInterval;

QualityManager::QualityManager(std::shared_ptr<Clock> the_clock)
: initialized_{false}, enabled_{false}, padding_enabled_{false}, forced_layers_{false},
: initialized_{false}, enabled_{false}, forced_layers_{false},
freeze_fallback_active_{false}, enable_slideshow_below_spatial_layer_{false},
enable_fallback_below_min_layer_{false}, spatial_layer_{0},
temporal_layer_{0}, max_active_spatial_layer_{0},
max_active_temporal_layer_{0}, slideshow_below_spatial_layer_{-1}, max_video_width_{-1},
max_video_height_{-1}, max_video_frame_rate_{-1}, current_estimated_bitrate_{0},
last_quality_check_{the_clock->now()}, last_activity_check_{the_clock->now()}, clock_{the_clock},
connection_quality_level_{ConnectionQualityLevel::GOOD}, connection_quality_level_updated_on_{the_clock->now()},
last_connection_quality_level_received_{ConnectionQualityLevel::GOOD} {}
last_quality_check_{the_clock->now()}, last_activity_check_{the_clock->now()}, clock_{the_clock} {}

void QualityManager::enable() {
ELOG_DEBUG("message: Enabling QualityManager");
enabled_ = true;
if (!forced_layers_) {
setPadding(true);
}
}

void QualityManager::disable() {
ELOG_DEBUG("message: Disabling QualityManager");
enabled_ = false;
setPadding(false);
}

void QualityManager::notifyEvent(MediaEventPtr event) {
Expand All @@ -45,34 +38,6 @@ void QualityManager::notifyEvent(MediaEventPtr event) {
video_frame_width_list_ = layer_event->video_frame_width_list;
video_frame_height_list_ = layer_event->video_frame_height_list;
video_frame_rate_list_ = layer_event->video_frame_rate_list;
} else if (event->getType() == "ConnectionQualityEvent") {
auto quality_event = std::static_pointer_cast<ConnectionQualityEvent>(event);
onConnectionQualityUpdate(quality_event->level);
}
}

void QualityManager::onConnectionQualityUpdate(ConnectionQualityLevel level) {
if (level == connection_quality_level_) {
connection_quality_level_updated_on_ = clock_->now();
} else if (level < connection_quality_level_) {
connection_quality_level_ = level;
connection_quality_level_updated_on_ = clock_->now();
selectLayer(false);
}
last_connection_quality_level_received_ = level;
if (!initialized_) {
return;
}
stats_->getNode()["qualityLayers"].insertStat("currentQualityLevel",
CumulativeStat{level});
}

void QualityManager::checkIfConnectionQualityLevelIsBetterNow() {
if (connection_quality_level_ < last_connection_quality_level_received_ &&
(clock_->now() - connection_quality_level_updated_on_) > kIncreaseConnectionQualityLevelInterval) {
connection_quality_level_ = ConnectionQualityLevel(connection_quality_level_ + 1);
connection_quality_level_updated_on_ = clock_->now();
selectLayer(true);
}
}

Expand Down Expand Up @@ -123,8 +88,6 @@ void QualityManager::notifyQualityUpdate() {
} else if (now - last_quality_check_ > kMinLayerSwitchInterval) {
selectLayer(true);
}

checkIfConnectionQualityLevelIsBetterNow();
}

bool QualityManager::doesLayerMeetConstraints(int spatial_layer, int temporal_layer) {
Expand Down Expand Up @@ -237,18 +200,9 @@ void QualityManager::selectLayer(bool try_higher_layers) {
aux_temporal_layer = 0;
aux_spatial_layer++;
}
bool padding_disabled_by_bad_connection = false;
if (!(enable_slideshow_below_spatial_layer_ || enable_fallback_below_min_layer_)
&& connection_quality_level_ == ConnectionQualityLevel::GOOD) {

if (!(enable_slideshow_below_spatial_layer_ || enable_fallback_below_min_layer_)) {
below_min_layer = false;
} else if (connection_quality_level_ == ConnectionQualityLevel::HIGH_LOSSES) {
next_temporal_layer = 0;
next_spatial_layer = 0;
below_min_layer = true;
padding_disabled_by_bad_connection = true;
} else if (connection_quality_level_ == ConnectionQualityLevel::LOW_LOSSES) {
// We'll enable fallback when needed by not updating below_min_layer to false
padding_disabled_by_bad_connection = true;
}

ELOG_DEBUG("message: below_min_layer %u, freeze_fallback_active_: %u", below_min_layer, freeze_fallback_active_);
Expand Down Expand Up @@ -285,12 +239,9 @@ void QualityManager::selectLayer(bool try_higher_layers) {
setSpatialLayer(next_spatial_layer);

// TODO(javier): should we wait for the actual spatial switch?
// should we disable padding temporarily to avoid congestion (old padding + new bitrate)?
}
stats_->getNode()["qualityLayers"].insertStat("qualityCappedByConstraints",
CumulativeStat{layer_capped_by_constraints});
setPadding(!isInMaxLayer() && !layer_capped_by_constraints && !padding_disabled_by_bad_connection);
ELOG_DEBUG("message: Is padding enabled, padding_enabled_: %d", padding_enabled_);
}

void QualityManager::calculateMaxActiveLayer() {
Expand Down Expand Up @@ -342,7 +293,6 @@ void QualityManager::forceLayers(int spatial_layer, int temporal_layer) {
return;
}
forced_layers_ = true;
setPadding(false);

spatial_layer_ = spatial_layer;
temporal_layer_ = temporal_layer;
Expand Down Expand Up @@ -405,19 +355,4 @@ void QualityManager::setTemporalLayer(int temporal_layer) {
CumulativeStat{static_cast<uint64_t>(temporal_layer_)});
}

void QualityManager::setPadding(bool enabled) {
if (padding_enabled_ != enabled) {
padding_enabled_ = enabled;
HandlerManager *manager = getContext()->getPipelineShared()->getService<HandlerManager>().get();
if (manager) {
manager->notifyUpdateToHandlers();
}
}
}

void QualityManager::setConnectionQualityLevel(ConnectionQualityLevel level) {
connection_quality_level_ = level;
connection_quality_level_updated_on_ = clock_->now();
}

} // namespace erizo
13 changes: 0 additions & 13 deletions erizo/src/erizo/rtp/QualityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include "Stats.h"
#include "lib/Clock.h"
#include "pipeline/Service.h"
#include "bandwidth/ConnectionQualityCheck.h"

namespace erizo {

Expand All @@ -18,7 +17,6 @@ class QualityManager: public Service, public std::enable_shared_from_this<Qualit
static constexpr duration kMinLayerSwitchInterval = std::chrono::seconds(10);
static constexpr duration kActiveLayerInterval = std::chrono::milliseconds(500);
static constexpr float kIncreaseLayerBitrateThreshold = 0.1;
static constexpr duration kIncreaseConnectionQualityLevelInterval = std::chrono::seconds(20);

public:
explicit QualityManager(std::shared_ptr<Clock> the_clock = std::make_shared<SteadyClock>());
Expand All @@ -36,29 +34,22 @@ class QualityManager: public Service, public std::enable_shared_from_this<Qualit
void enableSlideShowBelowSpatialLayer(bool enabled, int spatial_layer);
void enableFallbackBelowMinLayer(bool enabled);
void setVideoConstraints(int max_video_width, int max_video_height, int max_video_frame_rate);
void setConnectionQualityLevel(ConnectionQualityLevel level);
void notifyEvent(MediaEventPtr event) override;
void notifyQualityUpdate();

virtual bool isPaddingEnabled() const { return padding_enabled_; }

private:
void calculateMaxActiveLayer();
void calculateMaxBitrateThatMeetsConstraints();
void selectLayer(bool try_higher_layers);
uint64_t getInstantLayerBitrate(int spatial_layer, int temporal_layer);
bool isInBaseLayer();
bool isInMaxLayer();
void setPadding(bool enabled);
bool doesLayerMeetConstraints(int spatial_layer, int temporal_layer);
void onConnectionQualityUpdate(ConnectionQualityLevel level);
void checkIfConnectionQualityLevelIsBetterNow();

private:
MediaStream* stream_;
bool initialized_;
bool enabled_;
bool padding_enabled_;
bool forced_layers_;
bool freeze_fallback_active_;
bool enable_slideshow_below_spatial_layer_;
Expand All @@ -80,10 +71,6 @@ class QualityManager: public Service, public std::enable_shared_from_this<Qualit
std::vector<uint32_t> video_frame_width_list_;
std::vector<uint32_t> video_frame_height_list_;
std::vector<uint64_t> video_frame_rate_list_;

ConnectionQualityLevel connection_quality_level_;
time_point connection_quality_level_updated_on_;
ConnectionQualityLevel last_connection_quality_level_received_;
};
} // namespace erizo

Expand Down
1 change: 0 additions & 1 deletion erizo/src/test/utils/Mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class MockQualityManager : public QualityManager {
MockQualityManager() : QualityManager() {}
MOCK_CONST_METHOD0(getSpatialLayer, int());
MOCK_CONST_METHOD0(getTemporalLayer, int());
MOCK_CONST_METHOD0(isPaddingEnabled, bool());
};

class MockMediaSink : public MediaSink {
Expand Down

0 comments on commit 3bb99eb

Please sign in to comment.