[Overuse] Make some should-be-const methods const.
The fact that they weren't const is probably a remenant of the good ol' days this class being multi-threaded and having to acquire mutexes. Now they can properly be made const. In order to make GetConstAdaptCounter() const, this CL makes sure a cleared adapt_counters_ map contains mappings for all degradation preferences to default-constructed AdaptCounters. Previously, if the mapping was missing it was implicitly inserted by GetConstAdaptCounter(). Now it can DCHECK that mappings always exists instead, and it always has something to return. Bug: webrtc:11222 Change-Id: If33227fe6572eb1d6cc6b9f851d6d174d035c110 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/168953 Commit-Queue: Henrik Boström <hbos@webrtc.org> Reviewed-by: Evan Shrubsole <eshr@google.com> Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org> Cr-Commit-Position: refs/heads/master@{#30611}
This commit is contained in:

committed by
Commit Bot

parent
aa6fbc156e
commit
d6fb409d46
@ -417,6 +417,7 @@ OveruseFrameDetectorResourceAdaptationModule::
|
|||||||
encoder_stats_observer_(encoder_stats_observer) {
|
encoder_stats_observer_(encoder_stats_observer) {
|
||||||
RTC_DCHECK(adaptation_listener_);
|
RTC_DCHECK(adaptation_listener_);
|
||||||
RTC_DCHECK(encoder_stats_observer_);
|
RTC_DCHECK(encoder_stats_observer_);
|
||||||
|
ClearAdaptCounters();
|
||||||
AddResource(encode_usage_resource_.get(),
|
AddResource(encode_usage_resource_.get(),
|
||||||
AdaptationObserverInterface::AdaptReason::kCpu);
|
AdaptationObserverInterface::AdaptReason::kCpu);
|
||||||
AddResource(quality_scaler_resource_.get(),
|
AddResource(quality_scaler_resource_.get(),
|
||||||
@ -486,7 +487,7 @@ void OveruseFrameDetectorResourceAdaptationModule::SetDegradationPreference(
|
|||||||
// TODO(asapersson): Consider removing |adapt_counters_| map and use one
|
// TODO(asapersson): Consider removing |adapt_counters_| map and use one
|
||||||
// AdaptCounter for all modes.
|
// AdaptCounter for all modes.
|
||||||
source_restrictor_->ClearRestrictions();
|
source_restrictor_->ClearRestrictions();
|
||||||
adapt_counters_.clear();
|
ClearAdaptCounters();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
degradation_preference_ = degradation_preference;
|
degradation_preference_ = degradation_preference;
|
||||||
@ -528,7 +529,7 @@ void OveruseFrameDetectorResourceAdaptationModule::
|
|||||||
ResetVideoSourceRestrictions() {
|
ResetVideoSourceRestrictions() {
|
||||||
last_adaptation_request_.reset();
|
last_adaptation_request_.reset();
|
||||||
source_restrictor_->ClearRestrictions();
|
source_restrictor_->ClearRestrictions();
|
||||||
adapt_counters_.clear();
|
ClearAdaptCounters();
|
||||||
MaybeUpdateVideoSourceRestrictions();
|
MaybeUpdateVideoSourceRestrictions();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -678,7 +679,7 @@ OveruseFrameDetectorResourceAdaptationModule::OnResourceUsageStateMeasured(
|
|||||||
|
|
||||||
bool OveruseFrameDetectorResourceAdaptationModule::CanAdaptUp(
|
bool OveruseFrameDetectorResourceAdaptationModule::CanAdaptUp(
|
||||||
AdaptationObserverInterface::AdaptReason reason,
|
AdaptationObserverInterface::AdaptReason reason,
|
||||||
const AdaptationRequest& adaptation_request) {
|
const AdaptationRequest& adaptation_request) const {
|
||||||
if (!has_input_video_)
|
if (!has_input_video_)
|
||||||
return false;
|
return false;
|
||||||
// We can't adapt up if we're already at the highest setting.
|
// We can't adapt up if we're already at the highest setting.
|
||||||
@ -701,7 +702,7 @@ bool OveruseFrameDetectorResourceAdaptationModule::CanAdaptUp(
|
|||||||
// We shouldn't adapt up if BalancedSettings doesn't allow it, which is only
|
// We shouldn't adapt up if BalancedSettings doesn't allow it, which is only
|
||||||
// applicable if reason is kQuality and preference is BALANCED.
|
// applicable if reason is kQuality and preference is BALANCED.
|
||||||
if (reason == AdaptationObserverInterface::AdaptReason::kQuality &&
|
if (reason == AdaptationObserverInterface::AdaptReason::kQuality &&
|
||||||
EffectiveDegradataionPreference() == DegradationPreference::BALANCED &&
|
EffectiveDegradationPreference() == DegradationPreference::BALANCED &&
|
||||||
!balanced_settings_.CanAdaptUp(GetVideoCodecTypeOrGeneric(),
|
!balanced_settings_.CanAdaptUp(GetVideoCodecTypeOrGeneric(),
|
||||||
LastInputFrameSizeOrDefault(),
|
LastInputFrameSizeOrDefault(),
|
||||||
encoder_target_bitrate_bps_.value_or(0))) {
|
encoder_target_bitrate_bps_.value_or(0))) {
|
||||||
@ -722,7 +723,7 @@ void OveruseFrameDetectorResourceAdaptationModule::OnResourceUnderuse(
|
|||||||
if (!CanAdaptUp(reason, adaptation_request))
|
if (!CanAdaptUp(reason, adaptation_request))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch (EffectiveDegradataionPreference()) {
|
switch (EffectiveDegradationPreference()) {
|
||||||
case DegradationPreference::BALANCED: {
|
case DegradationPreference::BALANCED: {
|
||||||
// Try scale up framerate, if higher.
|
// Try scale up framerate, if higher.
|
||||||
int fps = balanced_settings_.MaxFps(GetVideoCodecTypeOrGeneric(),
|
int fps = balanced_settings_.MaxFps(GetVideoCodecTypeOrGeneric(),
|
||||||
@ -803,7 +804,7 @@ void OveruseFrameDetectorResourceAdaptationModule::OnResourceUnderuse(
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool OveruseFrameDetectorResourceAdaptationModule::CanAdaptDown(
|
bool OveruseFrameDetectorResourceAdaptationModule::CanAdaptDown(
|
||||||
const AdaptationRequest& adaptation_request) {
|
const AdaptationRequest& adaptation_request) const {
|
||||||
if (!has_input_video_)
|
if (!has_input_video_)
|
||||||
return false;
|
return false;
|
||||||
// TODO(hbos): Don't support DISABLED, it doesn't exist in the spec and it
|
// TODO(hbos): Don't support DISABLED, it doesn't exist in the spec and it
|
||||||
@ -817,7 +818,7 @@ bool OveruseFrameDetectorResourceAdaptationModule::CanAdaptDown(
|
|||||||
last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptDown;
|
last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptDown;
|
||||||
// We shouldn't adapt down if our frame rate is below the minimum or if its
|
// We shouldn't adapt down if our frame rate is below the minimum or if its
|
||||||
// currently unknown.
|
// currently unknown.
|
||||||
if (EffectiveDegradataionPreference() ==
|
if (EffectiveDegradationPreference() ==
|
||||||
DegradationPreference::MAINTAIN_RESOLUTION) {
|
DegradationPreference::MAINTAIN_RESOLUTION) {
|
||||||
// TODO(hbos): This usage of |last_adaptation_was_down| looks like a mistake
|
// TODO(hbos): This usage of |last_adaptation_was_down| looks like a mistake
|
||||||
// - delete it.
|
// - delete it.
|
||||||
@ -856,7 +857,7 @@ OveruseFrameDetectorResourceAdaptationModule::OnResourceOveruse(
|
|||||||
|
|
||||||
ResourceListenerResponse response = ResourceListenerResponse::kNothing;
|
ResourceListenerResponse response = ResourceListenerResponse::kNothing;
|
||||||
|
|
||||||
switch (EffectiveDegradataionPreference()) {
|
switch (EffectiveDegradationPreference()) {
|
||||||
case DegradationPreference::BALANCED: {
|
case DegradationPreference::BALANCED: {
|
||||||
// Try scale down framerate, if lower.
|
// Try scale down framerate, if lower.
|
||||||
int fps = balanced_settings_.MinFps(GetVideoCodecTypeOrGeneric(),
|
int fps = balanced_settings_.MinFps(GetVideoCodecTypeOrGeneric(),
|
||||||
@ -1048,8 +1049,9 @@ OveruseFrameDetectorResourceAdaptationModule::GetActiveCounts(
|
|||||||
return counts;
|
return counts;
|
||||||
}
|
}
|
||||||
|
|
||||||
DegradationPreference OveruseFrameDetectorResourceAdaptationModule::
|
DegradationPreference
|
||||||
EffectiveDegradataionPreference() {
|
OveruseFrameDetectorResourceAdaptationModule::EffectiveDegradationPreference()
|
||||||
|
const {
|
||||||
// Balanced mode for screenshare works via automatic animation detection:
|
// Balanced mode for screenshare works via automatic animation detection:
|
||||||
// Resolution is capped for fullscreen animated content.
|
// Resolution is capped for fullscreen animated content.
|
||||||
// Adapatation is done only via framerate downgrade.
|
// Adapatation is done only via framerate downgrade.
|
||||||
@ -1067,9 +1069,23 @@ OveruseFrameDetectorResourceAdaptationModule::GetAdaptCounter() {
|
|||||||
return adapt_counters_[degradation_preference_];
|
return adapt_counters_[degradation_preference_];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OveruseFrameDetectorResourceAdaptationModule::ClearAdaptCounters() {
|
||||||
|
adapt_counters_.clear();
|
||||||
|
adapt_counters_.insert(
|
||||||
|
std::make_pair(DegradationPreference::DISABLED, AdaptCounter()));
|
||||||
|
adapt_counters_.insert(std::make_pair(
|
||||||
|
DegradationPreference::MAINTAIN_FRAMERATE, AdaptCounter()));
|
||||||
|
adapt_counters_.insert(std::make_pair(
|
||||||
|
DegradationPreference::MAINTAIN_RESOLUTION, AdaptCounter()));
|
||||||
|
adapt_counters_.insert(
|
||||||
|
std::make_pair(DegradationPreference::BALANCED, AdaptCounter()));
|
||||||
|
}
|
||||||
|
|
||||||
const OveruseFrameDetectorResourceAdaptationModule::AdaptCounter&
|
const OveruseFrameDetectorResourceAdaptationModule::AdaptCounter&
|
||||||
OveruseFrameDetectorResourceAdaptationModule::GetConstAdaptCounter() {
|
OveruseFrameDetectorResourceAdaptationModule::GetConstAdaptCounter() const {
|
||||||
return adapt_counters_[degradation_preference_];
|
auto it = adapt_counters_.find(degradation_preference_);
|
||||||
|
RTC_DCHECK(it != adapt_counters_.cend());
|
||||||
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OveruseFrameDetectorResourceAdaptationModule::CanAdaptUpResolution(
|
bool OveruseFrameDetectorResourceAdaptationModule::CanAdaptUpResolution(
|
||||||
|
@ -130,12 +130,9 @@ class OveruseFrameDetectorResourceAdaptationModule
|
|||||||
enum class Mode { kAdaptUp, kAdaptDown } mode_;
|
enum class Mode { kAdaptUp, kAdaptDown } mode_;
|
||||||
};
|
};
|
||||||
|
|
||||||
// TODO(https://crbug.com/webrtc/11222): Make CanAdaptUp/CanAdaptDown const.
|
|
||||||
// This requires making other private methods const like GetConstAdaptCounter
|
|
||||||
// and EffectiveDegradataionPreference.
|
|
||||||
// Preconditions for OnResourceUnderuse() to adapt up.
|
// Preconditions for OnResourceUnderuse() to adapt up.
|
||||||
bool CanAdaptUp(AdaptationObserverInterface::AdaptReason reason,
|
bool CanAdaptUp(AdaptationObserverInterface::AdaptReason reason,
|
||||||
const AdaptationRequest& adaptation_request);
|
const AdaptationRequest& adaptation_request) const;
|
||||||
// Adapts up if preconditions apply and VideoSourceRestrictor allows it.
|
// Adapts up if preconditions apply and VideoSourceRestrictor allows it.
|
||||||
// TODO(https://crbug.com/webrtc/11222): This method is still a "Maybe" method
|
// TODO(https://crbug.com/webrtc/11222): This method is still a "Maybe" method
|
||||||
// due to the remaining VideoSourceRestrictor logic and it implicitly
|
// due to the remaining VideoSourceRestrictor logic and it implicitly
|
||||||
@ -145,7 +142,7 @@ class OveruseFrameDetectorResourceAdaptationModule
|
|||||||
// returns a valid target (or null if there is no next target).
|
// returns a valid target (or null if there is no next target).
|
||||||
void OnResourceUnderuse(AdaptationObserverInterface::AdaptReason reason);
|
void OnResourceUnderuse(AdaptationObserverInterface::AdaptReason reason);
|
||||||
// Preconditions for OnResourceOveruse() to adapt down.
|
// Preconditions for OnResourceOveruse() to adapt down.
|
||||||
bool CanAdaptDown(const AdaptationRequest& adaptation_request);
|
bool CanAdaptDown(const AdaptationRequest& adaptation_request) const;
|
||||||
// Adapts down if preconditions apply and VideoSourceRestrictor allows it.
|
// Adapts down if preconditions apply and VideoSourceRestrictor allows it.
|
||||||
ResourceListenerResponse OnResourceOveruse(
|
ResourceListenerResponse OnResourceOveruse(
|
||||||
AdaptationObserverInterface::AdaptReason reason);
|
AdaptationObserverInterface::AdaptReason reason);
|
||||||
@ -155,7 +152,8 @@ class OveruseFrameDetectorResourceAdaptationModule
|
|||||||
int LastInputFrameSizeOrDefault() const;
|
int LastInputFrameSizeOrDefault() const;
|
||||||
VideoStreamEncoderObserver::AdaptationSteps GetActiveCounts(
|
VideoStreamEncoderObserver::AdaptationSteps GetActiveCounts(
|
||||||
AdaptationObserverInterface::AdaptReason reason);
|
AdaptationObserverInterface::AdaptReason reason);
|
||||||
const AdaptCounter& GetConstAdaptCounter();
|
void ClearAdaptCounters();
|
||||||
|
const AdaptCounter& GetConstAdaptCounter() const;
|
||||||
|
|
||||||
// Makes |video_source_restrictions_| up-to-date and informs the
|
// Makes |video_source_restrictions_| up-to-date and informs the
|
||||||
// |adaptation_listener_| if restrictions are changed, allowing the listener
|
// |adaptation_listener_| if restrictions are changed, allowing the listener
|
||||||
@ -170,7 +168,7 @@ class OveruseFrameDetectorResourceAdaptationModule
|
|||||||
absl::optional<VideoEncoder::QpThresholds> qp_thresholds);
|
absl::optional<VideoEncoder::QpThresholds> qp_thresholds);
|
||||||
|
|
||||||
void UpdateAdaptationStats(AdaptationObserverInterface::AdaptReason reason);
|
void UpdateAdaptationStats(AdaptationObserverInterface::AdaptReason reason);
|
||||||
DegradationPreference EffectiveDegradataionPreference();
|
DegradationPreference EffectiveDegradationPreference() const;
|
||||||
AdaptCounter& GetAdaptCounter();
|
AdaptCounter& GetAdaptCounter();
|
||||||
bool CanAdaptUpResolution(int pixels, uint32_t bitrate_bps) const;
|
bool CanAdaptUpResolution(int pixels, uint32_t bitrate_bps) const;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user