[Adaptation] Move EffectiveDegradationPreference to RA-Processor.
This CL is part of the Call-Level Adaptation Processing design doc:
https://docs.google.com/document/d/1ZyC26yOCknrrcYa839ZWLxD6o6Gig5A3lVTh4E41074/edit?usp=sharing
The VideoStreamAdapter is responsible for generating adaptation
suggestions according to its DegradationPreference. Today there is one
DegradationPreference that you set, but internally the preference it
uses to make decisions is EffectiveDegradationPreference() which
reinterprets “balanced” as “maintain-resolution” if screenshare is used.
By moving the “effective” logic to the ResourceAdaptationProcessor, the
VideoStreamAdapter will not need to know about the type of track, and
the responsibility of the adapter is minimized. The “effective” logic
is non-standard and something we want to get rid of - until then, it
should be the responsibility of the processor to configure the adapter
to use the appropriate strategy, rather than for the adapter to know
about more states of the system than it needs to.
Future CLs will further minimize what the adapter needs to know, moving
"decision-making" logic to the Processor and "is adapt up allowed?"
logic to the Resources.
By removing the VideoInputMode enum the VideoStreamAdapter does not
know if we have input which has to be checked externally. Input
handling is followed-up on in the next CL.
Bug: webrtc:11172
Change-Id: I37ec9e7392f835cf8fef9829a2c945183f0e9b65
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/172927
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Evan Shrubsole <eshr@google.com>
Cr-Commit-Position: refs/heads/master@{#31096}
diff --git a/video/adaptation/resource_adaptation_processor.cc b/video/adaptation/resource_adaptation_processor.cc
index 440f96f..fd8207c 100644
--- a/video/adaptation/resource_adaptation_processor.cc
+++ b/video/adaptation/resource_adaptation_processor.cc
@@ -197,6 +197,7 @@
experiment_cpu_load_estimator_(experiment_cpu_load_estimator),
has_input_video_(false),
degradation_preference_(DegradationPreference::DISABLED),
+ effective_degradation_preference_(DegradationPreference::DISABLED),
stream_adapter_(std::make_unique<VideoStreamAdapter>()),
encode_usage_resource_(
std::make_unique<EncodeUsageResource>(std::move(overuse_detector))),
@@ -269,20 +270,13 @@
void ResourceAdaptationProcessor::SetDegradationPreference(
DegradationPreference degradation_preference) {
degradation_preference_ = degradation_preference;
- UpdateStatsAdaptationSettings();
-
- if (stream_adapter_->SetDegradationPreference(degradation_preference) ==
- VideoStreamAdapter::SetDegradationPreferenceResult::
- kRestrictionsCleared) {
- ResetActiveCounts();
- encoder_stats_observer_->ClearAdaptationStats();
- }
- MaybeUpdateVideoSourceRestrictions();
+ MaybeUpdateEffectiveDegradationPreference();
}
void ResourceAdaptationProcessor::SetEncoderSettings(
EncoderSettings encoder_settings) {
encoder_settings_ = std::move(encoder_settings);
+ MaybeUpdateEffectiveDegradationPreference();
quality_rampup_experiment_.SetMaxBitrate(
LastInputFrameSizeOrDefault(),
@@ -455,6 +449,8 @@
void ResourceAdaptationProcessor::OnResourceUnderuse(
VideoAdaptationReason reason) {
+ if (!has_input_video_)
+ return;
// We can't adapt up if we're already at the highest setting.
// Note that this only includes counts relevant to the current degradation
// preference. e.g. we previously adapted resolution, now prefer adpating fps,
@@ -476,7 +472,7 @@
if (num_downgrades == 0)
return;
// Update video input states and encoder settings for accurate adaptation.
- stream_adapter_->SetInput(GetVideoInputMode(), LastInputFrameSizeOrDefault(),
+ stream_adapter_->SetInput(LastInputFrameSizeOrDefault(),
encoder_stats_observer_->GetInputFrameRate(),
encoder_settings_, encoder_target_bitrate_bps_);
// Should we adapt, and if so: how?
@@ -498,7 +494,7 @@
if (!has_input_video_)
return ResourceListenerResponse::kQualityScalerShouldIncreaseFrequency;
// Update video input states and encoder settings for accurate adaptation.
- stream_adapter_->SetInput(GetVideoInputMode(), LastInputFrameSizeOrDefault(),
+ stream_adapter_->SetInput(LastInputFrameSizeOrDefault(),
encoder_stats_observer_->GetInputFrameRate(),
encoder_settings_, encoder_target_bitrate_bps_);
// Should we adapt, and if so: how?
@@ -552,6 +548,25 @@
kDefaultInputPixelsHeight);
}
+void ResourceAdaptationProcessor::MaybeUpdateEffectiveDegradationPreference() {
+ bool is_screenshare = encoder_settings_.has_value() &&
+ encoder_settings_->encoder_config().content_type ==
+ VideoEncoderConfig::ContentType::kScreen;
+ effective_degradation_preference_ =
+ (is_screenshare &&
+ degradation_preference_ == DegradationPreference::BALANCED)
+ ? DegradationPreference::MAINTAIN_RESOLUTION
+ : degradation_preference_;
+ if (stream_adapter_->SetDegradationPreference(
+ effective_degradation_preference_) ==
+ VideoStreamAdapter::SetDegradationPreferenceResult::
+ kRestrictionsCleared) {
+ ResetActiveCounts();
+ encoder_stats_observer_->ClearAdaptationStats();
+ }
+ MaybeUpdateVideoSourceRestrictions();
+}
+
void ResourceAdaptationProcessor::MaybeUpdateVideoSourceRestrictions() {
VideoSourceRestrictions new_restrictions = ApplyDegradationPreference(
stream_adapter_->source_restrictions(), degradation_preference_);
@@ -676,17 +691,6 @@
quality_settings);
}
-VideoStreamAdapter::VideoInputMode
-ResourceAdaptationProcessor::GetVideoInputMode() const {
- if (!has_input_video_)
- return VideoStreamAdapter::VideoInputMode::kNoVideo;
- return (encoder_settings_.has_value() &&
- encoder_settings_->encoder_config().content_type ==
- VideoEncoderConfig::ContentType::kScreen)
- ? VideoStreamAdapter::VideoInputMode::kScreenshareVideo
- : VideoStreamAdapter::VideoInputMode::kNormalVideo;
-}
-
void ResourceAdaptationProcessor::MaybePerformQualityRampupExperiment() {
if (!quality_scaler_resource_->is_started())
return;
diff --git a/video/adaptation/resource_adaptation_processor.h b/video/adaptation/resource_adaptation_processor.h
index 922c624..847a556 100644
--- a/video/adaptation/resource_adaptation_processor.h
+++ b/video/adaptation/resource_adaptation_processor.h
@@ -73,6 +73,9 @@
DegradationPreference degradation_preference() const {
return degradation_preference_;
}
+ DegradationPreference effective_degradation_preference() const {
+ return effective_degradation_preference_;
+ }
// ResourceAdaptationProcessorInterface implementation.
void StartResourceAdaptation(
@@ -140,8 +143,12 @@
CpuOveruseOptions GetCpuOveruseOptions() const;
int LastInputFrameSizeOrDefault() const;
- VideoStreamAdapter::VideoInputMode GetVideoInputMode() const;
+ // Reinterprets "balanced + screenshare" as "maintain-resolution".
+ // TODO(hbos): Don't do this. This is not what "balanced" means. If the
+ // application wants to maintain resolution it should set that degradation
+ // preference rather than depend on non-standard behaviors.
+ void MaybeUpdateEffectiveDegradationPreference();
// Makes |video_source_restrictions_| up-to-date and informs the
// |adaptation_listener_| if restrictions are changed, allowing the listener
// to reconfigure the source accordingly.
@@ -175,12 +182,8 @@
// The restrictions that |adaptation_listener_| is informed of.
VideoSourceRestrictions video_source_restrictions_;
bool has_input_video_;
- // TODO(https://crbug.com/webrtc/11393): DegradationPreference has mostly
- // moved to VideoStreamAdapter. Move it entirely and delete it from this
- // class. If the responsibility of generating next steps for adaptations is
- // owned by the adapter, this class has no buisness relying on implementation
- // details of the adapter.
DegradationPreference degradation_preference_;
+ DegradationPreference effective_degradation_preference_;
// Keeps track of source restrictions that this adaptation processor outputs.
const std::unique_ptr<VideoStreamAdapter> stream_adapter_;
const std::unique_ptr<EncodeUsageResource> encode_usage_resource_;
diff --git a/video/adaptation/video_stream_adapter.cc b/video/adaptation/video_stream_adapter.cc
index 566f67d..abee591 100644
--- a/video/adaptation/video_stream_adapter.cc
+++ b/video/adaptation/video_stream_adapter.cc
@@ -194,9 +194,8 @@
std::numeric_limits<int>::max()));
}
- void ApplyAdaptationStep(
- const Adaptation::Step& step,
- DegradationPreference effective_degradation_preference) {
+ void ApplyAdaptationStep(const Adaptation::Step& step,
+ DegradationPreference degradation_preference) {
switch (step.type) {
case Adaptation::StepType::kIncreaseResolution:
IncreaseResolutionTo(step.target);
@@ -211,8 +210,7 @@
// logic in DecrementFramerate() makes it hard to predict whether this
// will be the last step. Remove the dependency on
// adaptation_counters().
- if (effective_degradation_preference ==
- DegradationPreference::BALANCED &&
+ if (degradation_preference == DegradationPreference::BALANCED &&
adaptation_counters().fps_adaptations == 0 &&
step.target != std::numeric_limits<int>::max()) {
RTC_LOG(LS_INFO) << "Removing framerate down-scaling setting.";
@@ -321,7 +319,6 @@
balanced_settings_(),
adaptation_validation_id_(0),
degradation_preference_(DegradationPreference::DISABLED),
- input_mode_(VideoInputMode::kNoVideo),
input_pixels_(0),
input_fps_(0),
encoder_settings_(absl::nullopt),
@@ -369,14 +366,12 @@
}
void VideoStreamAdapter::SetInput(
- VideoInputMode input_mode,
int input_pixels,
int input_fps,
absl::optional<EncoderSettings> encoder_settings,
absl::optional<uint32_t> encoder_target_bitrate_bps) {
// Invalidate any previously returned Adaptation.
++adaptation_validation_id_;
- input_mode_ = input_mode;
input_pixels_ = input_pixels;
input_fps_ = input_fps;
encoder_settings_ = encoder_settings;
@@ -387,11 +382,6 @@
Adaptation VideoStreamAdapter::GetAdaptationUp(
VideoAdaptationReason reason) const {
- // Don't adapt if we don't have sufficient input.
- if (input_mode_ == VideoInputMode::kNoVideo) {
- return Adaptation(adaptation_validation_id_,
- Adaptation::Status::kInsufficientInput);
- }
// Don't adapt if we're awaiting a previous adaptation to have an effect.
bool last_adaptation_was_up =
last_adaptation_request_ &&
@@ -405,7 +395,7 @@
// Don't adapt if BalancedDegradationSettings applies and determines this will
// exceed bitrate constraints.
if (reason == VideoAdaptationReason::kQuality &&
- EffectiveDegradationPreference() == DegradationPreference::BALANCED &&
+ degradation_preference_ == DegradationPreference::BALANCED &&
!balanced_settings_.CanAdaptUp(
GetVideoCodecTypeOrGeneric(encoder_settings_), input_pixels_,
encoder_target_bitrate_bps_.value_or(0))) {
@@ -414,7 +404,7 @@
}
// Maybe propose targets based on degradation preference.
- switch (EffectiveDegradationPreference()) {
+ switch (degradation_preference_) {
case DegradationPreference::BALANCED: {
// Attempt to increase target frame rate.
int target_fps = balanced_settings_.MaxFps(
@@ -487,11 +477,7 @@
}
Adaptation VideoStreamAdapter::GetAdaptationDown() const {
- // Don't adapt if we don't have sufficient input or adaptation is disabled.
- if (input_mode_ == VideoInputMode::kNoVideo) {
- return Adaptation(adaptation_validation_id_,
- Adaptation::Status::kInsufficientInput);
- }
+ // Don't adapt adaptation is disabled.
if (degradation_preference_ == DegradationPreference::DISABLED) {
return Adaptation(adaptation_validation_id_,
Adaptation::Status::kAdaptationDisabled);
@@ -499,8 +485,7 @@
bool last_adaptation_was_down =
last_adaptation_request_ &&
last_adaptation_request_->mode_ == AdaptationRequest::Mode::kAdaptDown;
- if (EffectiveDegradationPreference() ==
- DegradationPreference::MAINTAIN_RESOLUTION) {
+ if (degradation_preference_ == DegradationPreference::MAINTAIN_RESOLUTION) {
// TODO(hbos): This usage of |last_adaptation_was_down| looks like a mistake
// - delete it.
if (input_fps_ <= 0 ||
@@ -518,7 +503,7 @@
}
// Maybe propose targets based on degradation preference.
- switch (EffectiveDegradationPreference()) {
+ switch (degradation_preference_) {
case DegradationPreference::BALANCED: {
// Try scale down framerate, if lower.
int target_fps = balanced_settings_.MinFps(
@@ -573,7 +558,7 @@
return source_restrictor_->source_restrictions();
VideoSourceRestrictor restrictor_copy = *source_restrictor_;
restrictor_copy.ApplyAdaptationStep(adaptation.step(),
- EffectiveDegradationPreference());
+ degradation_preference_);
return restrictor_copy.source_restrictions();
}
@@ -590,14 +575,14 @@
AdaptationRequest::GetModeFromAdaptationAction(adaptation.step().type)});
// Adapt!
source_restrictor_->ApplyAdaptationStep(adaptation.step(),
- EffectiveDegradationPreference());
+ degradation_preference_);
// In BALANCED, if requested FPS is higher or close to input FPS to the target
// we tell the QualityScaler to increase its frequency.
// TODO(hbos): Don't have QualityScaler-specific logic here. If the
// QualityScaler wants to add special logic depending on what effects
// adaptation had, it should listen to changes to the VideoSourceRestrictions
// instead.
- if (EffectiveDegradationPreference() == DegradationPreference::BALANCED &&
+ if (degradation_preference_ == DegradationPreference::BALANCED &&
adaptation.step().type == Adaptation::StepType::kDecreaseFrameRate) {
absl::optional<int> min_diff = balanced_settings_.MinFpsDiff(input_pixels_);
if (min_diff && input_fps_ > 0) {
@@ -610,16 +595,4 @@
return ResourceListenerResponse::kNothing;
}
-DegradationPreference VideoStreamAdapter::EffectiveDegradationPreference()
- const {
- // Balanced mode for screenshare works via automatic animation detection:
- // Resolution is capped for fullscreen animated content.
- // Adapatation is done only via framerate downgrade.
- // Thus effective degradation preference is MAINTAIN_RESOLUTION.
- return (input_mode_ == VideoInputMode::kScreenshareVideo &&
- degradation_preference_ == DegradationPreference::BALANCED)
- ? DegradationPreference::MAINTAIN_RESOLUTION
- : degradation_preference_;
-}
-
} // namespace webrtc
diff --git a/video/adaptation/video_stream_adapter.h b/video/adaptation/video_stream_adapter.h
index 30f95d0..ca6cdb5 100644
--- a/video/adaptation/video_stream_adapter.h
+++ b/video/adaptation/video_stream_adapter.h
@@ -42,9 +42,9 @@
// TODO(hbos): Don't support DISABLED, it doesn't exist in the spec and it
// causes all adaptation to be ignored, even QP-scaling.
kAdaptationDisabled,
- // Cannot adapt. Adaptation is refused because we don't have video, the
- // input frame rate is not known yet or is less than the minimum allowed
- // (below the limit).
+ // Cannot adapt. Adaptation is refused because we are attempting to adapt
+ // down while the input frame rate is either not known yet or is less than
+ // the minimum.
kInsufficientInput,
// Cannot adapt. The minimum or maximum adaptation has already been reached.
// There are no more steps to take.
@@ -129,12 +129,6 @@
kRestrictionsCleared,
};
- enum class VideoInputMode {
- kNoVideo,
- kNormalVideo,
- kScreenshareVideo,
- };
-
VideoStreamAdapter();
~VideoStreamAdapter();
@@ -153,8 +147,7 @@
SetDegradationPreferenceResult SetDegradationPreference(
DegradationPreference degradation_preference);
// The adaptaiton logic depends on these inputs.
- void SetInput(VideoInputMode input_mode,
- int input_pixels,
+ void SetInput(int input_pixels,
int input_fps,
absl::optional<EncoderSettings> encoder_settings,
absl::optional<uint32_t> encoder_target_bitrate_bps);
@@ -192,12 +185,6 @@
static Mode GetModeFromAdaptationAction(Adaptation::StepType step_type);
};
- // Reinterprets "balanced + screenshare" as "maintain-resolution".
- // TODO(hbos): Don't do this. This is not what "balanced" means. If the
- // application wants to maintain resolution it should set that degradation
- // preference rather than depend on non-standard behaviors.
- DegradationPreference EffectiveDegradationPreference() const;
-
// Owner and modifier of the VideoSourceRestriction of this stream adaptor.
const std::unique_ptr<VideoSourceRestrictor> source_restrictor_;
// Decides the next adaptation target in DegradationPreference::BALANCED.
@@ -209,7 +196,6 @@
// depending on the DegradationPreference.
// https://w3c.github.io/mst-content-hint/#dom-rtcdegradationpreference
DegradationPreference degradation_preference_;
- VideoInputMode input_mode_;
int input_pixels_;
int input_fps_;
absl::optional<EncoderSettings> encoder_settings_;
diff --git a/video/adaptation/video_stream_adapter_unittest.cc b/video/adaptation/video_stream_adapter_unittest.cc
index c85446b..48e231e 100644
--- a/video/adaptation/video_stream_adapter_unittest.cc
+++ b/video/adaptation/video_stream_adapter_unittest.cc
@@ -61,19 +61,17 @@
class FakeVideoStream {
public:
FakeVideoStream(VideoStreamAdapter* adapter,
- VideoStreamAdapter::VideoInputMode input_mode,
int input_pixels,
int input_fps,
absl::optional<EncoderSettings> encoder_settings,
absl::optional<uint32_t> encoder_target_bitrate_bps)
: adapter_(adapter),
- input_mode_(std::move(input_mode)),
input_pixels_(input_pixels),
input_fps_(input_fps),
encoder_settings_(std::move(encoder_settings)),
encoder_target_bitrate_bps_(std::move(encoder_target_bitrate_bps)) {
- adapter_->SetInput(input_mode_, input_pixels_, input_fps_,
- encoder_settings_, encoder_target_bitrate_bps_);
+ adapter_->SetInput(input_pixels_, input_fps_, encoder_settings_,
+ encoder_target_bitrate_bps_);
}
int input_pixels() const { return input_pixels_; }
@@ -96,13 +94,12 @@
if (restrictions.max_frame_rate().has_value()) {
input_fps_ = restrictions.max_frame_rate().value();
}
- adapter_->SetInput(input_mode_, input_pixels_, input_fps_,
- encoder_settings_, encoder_target_bitrate_bps_);
+ adapter_->SetInput(input_pixels_, input_fps_, encoder_settings_,
+ encoder_target_bitrate_bps_);
}
private:
VideoStreamAdapter* adapter_;
- VideoStreamAdapter::VideoInputMode input_mode_;
int input_pixels_;
int input_fps_;
absl::optional<EncoderSettings> encoder_settings_;
@@ -143,8 +140,7 @@
const int kInputPixels = 1280 * 720;
VideoStreamAdapter adapter;
adapter.SetDegradationPreference(DegradationPreference::MAINTAIN_FRAMERATE);
- adapter.SetInput(VideoStreamAdapter::VideoInputMode::kNormalVideo,
- kInputPixels, 30, absl::nullopt, absl::nullopt);
+ adapter.SetInput(kInputPixels, 30, absl::nullopt, absl::nullopt);
Adaptation adaptation = adapter.GetAdaptationDown();
EXPECT_EQ(Adaptation::Status::kValid, adaptation.status());
EXPECT_FALSE(adaptation.min_pixel_limit_reached());
@@ -161,8 +157,7 @@
const int kMinPixelsPerFrame = 640 * 480;
VideoStreamAdapter adapter;
adapter.SetDegradationPreference(DegradationPreference::MAINTAIN_FRAMERATE);
- adapter.SetInput(VideoStreamAdapter::VideoInputMode::kNormalVideo,
- kMinPixelsPerFrame + 1, 30,
+ adapter.SetInput(kMinPixelsPerFrame + 1, 30,
EncoderSettingsWithMinPixelsPerFrame(kMinPixelsPerFrame),
absl::nullopt);
// Even though we are above kMinPixelsPerFrame, because adapting down would
@@ -179,7 +174,6 @@
VideoStreamAdapter adapter;
adapter.SetDegradationPreference(DegradationPreference::MAINTAIN_FRAMERATE);
FakeVideoStream fake_stream(&adapter,
- VideoStreamAdapter::VideoInputMode::kNormalVideo,
1280 * 720, 30, absl::nullopt, absl::nullopt);
// Go down twice, ensuring going back up is still a restricted resolution.
fake_stream.ApplyAdaptation(adapter.GetAdaptationDown());
@@ -201,7 +195,6 @@
VideoStreamAdapter adapter;
adapter.SetDegradationPreference(DegradationPreference::MAINTAIN_FRAMERATE);
FakeVideoStream fake_stream(&adapter,
- VideoStreamAdapter::VideoInputMode::kNormalVideo,
1280 * 720, 30, absl::nullopt, absl::nullopt);
// We are unrestricted by default and should not be able to adapt up.
EXPECT_EQ(Adaptation::Status::kLimitReached,
@@ -218,8 +211,7 @@
const int kInputFps = 30;
VideoStreamAdapter adapter;
adapter.SetDegradationPreference(DegradationPreference::MAINTAIN_RESOLUTION);
- adapter.SetInput(VideoStreamAdapter::VideoInputMode::kNormalVideo, 1280 * 720,
- kInputFps, absl::nullopt, absl::nullopt);
+ adapter.SetInput(1280 * 720, kInputFps, absl::nullopt, absl::nullopt);
Adaptation adaptation = adapter.GetAdaptationDown();
EXPECT_EQ(Adaptation::Status::kValid, adaptation.status());
adapter.ApplyAdaptation(adaptation);
@@ -235,9 +227,8 @@
TEST(VideoStreamAdapterTest, MaintainResolution_DecreasesFpsToLimitReached) {
VideoStreamAdapter adapter;
adapter.SetDegradationPreference(DegradationPreference::MAINTAIN_RESOLUTION);
- FakeVideoStream fake_stream(
- &adapter, VideoStreamAdapter::VideoInputMode::kNormalVideo, 1280 * 720,
- kMinFrameRateFps + 1, absl::nullopt, absl::nullopt);
+ FakeVideoStream fake_stream(&adapter, 1280 * 720, kMinFrameRateFps + 1,
+ absl::nullopt, absl::nullopt);
// If we are not yet at the limit and the next step would exceed it, the step
// is clamped such that we end up exactly on the limit.
Adaptation adaptation = adapter.GetAdaptationDown();
@@ -255,7 +246,6 @@
VideoStreamAdapter adapter;
adapter.SetDegradationPreference(DegradationPreference::MAINTAIN_RESOLUTION);
FakeVideoStream fake_stream(&adapter,
- VideoStreamAdapter::VideoInputMode::kNormalVideo,
1280 * 720, 30, absl::nullopt, absl::nullopt);
// Go down twice, ensuring going back up is still a restricted frame rate.
fake_stream.ApplyAdaptation(adapter.GetAdaptationDown());
@@ -279,7 +269,6 @@
VideoStreamAdapter adapter;
adapter.SetDegradationPreference(DegradationPreference::MAINTAIN_RESOLUTION);
FakeVideoStream fake_stream(&adapter,
- VideoStreamAdapter::VideoInputMode::kNormalVideo,
1280 * 720, 30, absl::nullopt, absl::nullopt);
// We are unrestricted by default and should not be able to adapt up.
EXPECT_EQ(Adaptation::Status::kLimitReached,
@@ -297,8 +286,7 @@
BalancedFieldTrialConfig());
VideoStreamAdapter adapter;
adapter.SetDegradationPreference(DegradationPreference::BALANCED);
- adapter.SetInput(VideoStreamAdapter::VideoInputMode::kNormalVideo,
- kBalancedMediumResolutionPixels, kBalancedHighFrameRateFps,
+ adapter.SetInput(kBalancedMediumResolutionPixels, kBalancedHighFrameRateFps,
absl::nullopt, absl::nullopt);
// If our frame rate is higher than the frame rate associated with our
// resolution we should try to adapt to the frame rate associated with our
@@ -321,10 +309,9 @@
BalancedFieldTrialConfig());
VideoStreamAdapter adapter;
adapter.SetDegradationPreference(DegradationPreference::BALANCED);
- FakeVideoStream fake_stream(
- &adapter, VideoStreamAdapter::VideoInputMode::kNormalVideo,
- kBalancedHighResolutionPixels, kBalancedHighFrameRateFps, absl::nullopt,
- absl::nullopt);
+ FakeVideoStream fake_stream(&adapter, kBalancedHighResolutionPixels,
+ kBalancedHighFrameRateFps, absl::nullopt,
+ absl::nullopt);
// If we are not below the current resolution's frame rate limit, we should
// adapt resolution according to "maintain-framerate" logic (three fifths).
//
@@ -396,10 +383,9 @@
BalancedFieldTrialConfig());
VideoStreamAdapter adapter;
adapter.SetDegradationPreference(DegradationPreference::BALANCED);
- FakeVideoStream fake_stream(
- &adapter, VideoStreamAdapter::VideoInputMode::kNormalVideo,
- kBalancedHighResolutionPixels, kBalancedHighFrameRateFps, absl::nullopt,
- absl::nullopt);
+ FakeVideoStream fake_stream(&adapter, kBalancedHighResolutionPixels,
+ kBalancedHighFrameRateFps, absl::nullopt,
+ absl::nullopt);
// The desired starting point of this test is having adapted frame rate twice.
// This requires performing a number of adaptations.
constexpr size_t kReducedPixelsFirstStep =
@@ -506,10 +492,9 @@
BalancedFieldTrialConfig());
VideoStreamAdapter adapter;
adapter.SetDegradationPreference(DegradationPreference::BALANCED);
- FakeVideoStream fake_stream(
- &adapter, VideoStreamAdapter::VideoInputMode::kNormalVideo,
- kBalancedLowResolutionPixels, kBalancedLowFrameRateFps, absl::nullopt,
- absl::nullopt);
+ FakeVideoStream fake_stream(&adapter, kBalancedLowResolutionPixels,
+ kBalancedLowFrameRateFps, absl::nullopt,
+ absl::nullopt);
// Attempting to adapt up while unrestricted should result in kLimitReached.
EXPECT_EQ(Adaptation::Status::kLimitReached,
adapter.GetAdaptationUp(kReasonDontCare).status());
@@ -549,8 +534,7 @@
TEST(VideoStreamAdapterTest, AdaptationDisabled) {
VideoStreamAdapter adapter;
adapter.SetDegradationPreference(DegradationPreference::DISABLED);
- adapter.SetInput(VideoStreamAdapter::VideoInputMode::kNormalVideo, 1280 * 720,
- 30, absl::nullopt, absl::nullopt);
+ adapter.SetInput(1280 * 720, 30, absl::nullopt, absl::nullopt);
EXPECT_EQ(Adaptation::Status::kAdaptationDisabled,
adapter.GetAdaptationDown().status());
EXPECT_EQ(Adaptation::Status::kAdaptationDisabled,
@@ -560,16 +544,8 @@
TEST(VideoStreamAdapterTest, InsufficientInput) {
VideoStreamAdapter adapter;
adapter.SetDegradationPreference(DegradationPreference::MAINTAIN_RESOLUTION);
- // No vido is insufficient in either direction.
- adapter.SetInput(VideoStreamAdapter::VideoInputMode::kNoVideo, 1280 * 720, 30,
- absl::nullopt, absl::nullopt);
- EXPECT_EQ(Adaptation::Status::kInsufficientInput,
- adapter.GetAdaptationDown().status());
- EXPECT_EQ(Adaptation::Status::kInsufficientInput,
- adapter.GetAdaptationUp(kReasonDontCare).status());
// No frame rate is insufficient when going down.
- adapter.SetInput(VideoStreamAdapter::VideoInputMode::kNormalVideo, 1280 * 720,
- 0, absl::nullopt, absl::nullopt);
+ adapter.SetInput(1280 * 720, 0, absl::nullopt, absl::nullopt);
EXPECT_EQ(Adaptation::Status::kInsufficientInput,
adapter.GetAdaptationDown().status());
}
@@ -578,8 +554,7 @@
TEST(VideoStreamAdapterTest, MaintainFramerate_AwaitingPreviousAdaptationDown) {
VideoStreamAdapter adapter;
adapter.SetDegradationPreference(DegradationPreference::MAINTAIN_FRAMERATE);
- adapter.SetInput(VideoStreamAdapter::VideoInputMode::kNormalVideo, 1280 * 720,
- 30, absl::nullopt, absl::nullopt);
+ adapter.SetInput(1280 * 720, 30, absl::nullopt, absl::nullopt);
// Adapt down once, but don't update the input.
adapter.ApplyAdaptation(adapter.GetAdaptationDown());
EXPECT_EQ(1, adapter.adaptation_counters().resolution_adaptations);
@@ -597,7 +572,6 @@
VideoStreamAdapter adapter;
adapter.SetDegradationPreference(DegradationPreference::MAINTAIN_FRAMERATE);
FakeVideoStream fake_stream(&adapter,
- VideoStreamAdapter::VideoInputMode::kNormalVideo,
1280 * 720, 30, absl::nullopt, absl::nullopt);
// Perform two adaptation down so that adapting up twice is possible.
fake_stream.ApplyAdaptation(adapter.GetAdaptationDown());
@@ -623,8 +597,8 @@
VideoStreamAdapter adapter;
adapter.SetDegradationPreference(DegradationPreference::MAINTAIN_FRAMERATE);
FakeVideoStream fake_stream(
- &adapter, VideoStreamAdapter::VideoInputMode::kNormalVideo, kInputPixels,
- 30, EncoderSettingsWithBitrateLimits(kInputPixels, kBitrateLimit),
+ &adapter, kInputPixels, 30,
+ EncoderSettingsWithBitrateLimits(kInputPixels, kBitrateLimit),
// The target bitrate is one less than necessary
// to adapt up.
kBitrateLimit - 1);
@@ -646,7 +620,6 @@
// Any non-disabled DegradationPreference will do.
adapter.SetDegradationPreference(DegradationPreference::MAINTAIN_FRAMERATE);
FakeVideoStream fake_stream(&adapter,
- VideoStreamAdapter::VideoInputMode::kNormalVideo,
1280 * 720, 30, absl::nullopt, absl::nullopt);
// When adaptation is not possible.
{
@@ -675,32 +648,6 @@
}
}
-// This test covers non-standard behavior. If the application desires
-// "maintain-resolution" it should ask for it rather than relying on this
-// behavior, which should become unsupported.
-TEST(VideoStreamAdapterTest, BalancedScreenshareBehavesLikeMaintainResolution) {
- const int kInputPixels = 1280 * 720;
- const int kInputFps = 30;
- VideoStreamAdapter balanced_adapter;
- balanced_adapter.SetDegradationPreference(DegradationPreference::BALANCED);
- balanced_adapter.SetInput(
- VideoStreamAdapter::VideoInputMode::kScreenshareVideo, kInputPixels,
- kInputFps, absl::nullopt, absl::nullopt);
- VideoStreamAdapter maintain_resolution_adapter;
- maintain_resolution_adapter.SetDegradationPreference(
- DegradationPreference::MAINTAIN_RESOLUTION);
- maintain_resolution_adapter.SetInput(
- VideoStreamAdapter::VideoInputMode::kNormalVideo, kInputPixels, kInputFps,
- absl::nullopt, absl::nullopt);
- EXPECT_EQ(balanced_adapter.source_restrictions(),
- maintain_resolution_adapter.source_restrictions());
- balanced_adapter.ApplyAdaptation(balanced_adapter.GetAdaptationDown());
- maintain_resolution_adapter.ApplyAdaptation(
- maintain_resolution_adapter.GetAdaptationDown());
- EXPECT_EQ(balanced_adapter.source_restrictions(),
- maintain_resolution_adapter.source_restrictions());
-}
-
TEST(VideoStreamAdapterTest,
SetDegradationPreferenceToOrFromBalancedClearsRestrictions) {
VideoStreamAdapter adapter;
@@ -708,8 +655,7 @@
kRestrictionsNotCleared,
adapter.SetDegradationPreference(
DegradationPreference::MAINTAIN_FRAMERATE));
- adapter.SetInput(VideoStreamAdapter::VideoInputMode::kNormalVideo, 1280 * 720,
- 30, absl::nullopt, absl::nullopt);
+ adapter.SetInput(1280 * 720, 30, absl::nullopt, absl::nullopt);
adapter.ApplyAdaptation(adapter.GetAdaptationDown());
EXPECT_NE(VideoSourceRestrictions(), adapter.source_restrictions());
EXPECT_NE(0, adapter.adaptation_counters().Total());
@@ -741,8 +687,7 @@
SetDegradationPreferenceInvalidatesAdaptations) {
VideoStreamAdapter adapter;
adapter.SetDegradationPreference(DegradationPreference::MAINTAIN_FRAMERATE);
- adapter.SetInput(VideoStreamAdapter::VideoInputMode::kNormalVideo, 1280 * 720,
- 30, absl::nullopt, absl::nullopt);
+ adapter.SetInput(1280 * 720, 30, absl::nullopt, absl::nullopt);
Adaptation adaptation = adapter.GetAdaptationDown();
adapter.SetDegradationPreference(DegradationPreference::MAINTAIN_RESOLUTION);
EXPECT_DEATH(adapter.ApplyAdaptation(adaptation), "");
@@ -751,11 +696,9 @@
TEST(VideoStreamAdapterDeathTest, SetInputInvalidatesAdaptations) {
VideoStreamAdapter adapter;
adapter.SetDegradationPreference(DegradationPreference::MAINTAIN_RESOLUTION);
- adapter.SetInput(VideoStreamAdapter::VideoInputMode::kNormalVideo, 1280 * 720,
- 30, absl::nullopt, absl::nullopt);
+ adapter.SetInput(1280 * 720, 30, absl::nullopt, absl::nullopt);
Adaptation adaptation = adapter.GetAdaptationDown();
- adapter.SetInput(VideoStreamAdapter::VideoInputMode::kNormalVideo, 1280 * 720,
- 31, absl::nullopt, absl::nullopt);
+ adapter.SetInput(1280 * 720, 31, absl::nullopt, absl::nullopt);
EXPECT_DEATH(adapter.PeekNextRestrictions(adaptation), "");
}