aboutsummaryrefslogtreecommitdiff
path: root/call
diff options
context:
space:
mode:
Diffstat (limited to 'call')
-rw-r--r--call/adaptation/BUILD.gn8
-rw-r--r--call/adaptation/adaptation_constraint.cc17
-rw-r--r--call/adaptation/adaptation_constraint.h43
-rw-r--r--call/adaptation/adaptation_listener.cc17
-rw-r--r--call/adaptation/adaptation_listener.h41
-rw-r--r--call/adaptation/resource.h34
-rw-r--r--call/adaptation/resource_adaptation_processor.cc103
-rw-r--r--call/adaptation/resource_adaptation_processor.h25
-rw-r--r--call/adaptation/resource_adaptation_processor_interface.cc2
-rw-r--r--call/adaptation/resource_adaptation_processor_interface.h22
-rw-r--r--call/adaptation/resource_adaptation_processor_unittest.cc201
-rw-r--r--call/adaptation/resource_unittest.cc48
-rw-r--r--call/adaptation/test/fake_adaptation_constraint.cc39
-rw-r--r--call/adaptation/test/fake_adaptation_constraint.h42
-rw-r--r--call/adaptation/test/fake_adaptation_listener.cc32
-rw-r--r--call/adaptation/test/fake_adaptation_listener.h38
-rw-r--r--call/adaptation/test/fake_resource.cc69
-rw-r--r--call/adaptation/test/fake_resource.h31
18 files changed, 518 insertions, 294 deletions
diff --git a/call/adaptation/BUILD.gn b/call/adaptation/BUILD.gn
index 291911ab22..b5c72efbb1 100644
--- a/call/adaptation/BUILD.gn
+++ b/call/adaptation/BUILD.gn
@@ -10,6 +10,10 @@ import("../../webrtc.gni")
rtc_library("resource_adaptation") {
sources = [
+ "adaptation_constraint.cc",
+ "adaptation_constraint.h",
+ "adaptation_listener.cc",
+ "adaptation_listener.h",
"encoder_settings.cc",
"encoder_settings.h",
"resource.cc",
@@ -80,6 +84,10 @@ if (rtc_include_tests) {
testonly = true
sources = [
+ "test/fake_adaptation_constraint.cc",
+ "test/fake_adaptation_constraint.h",
+ "test/fake_adaptation_listener.cc",
+ "test/fake_adaptation_listener.h",
"test/fake_frame_rate_provider.cc",
"test/fake_frame_rate_provider.h",
"test/fake_resource.cc",
diff --git a/call/adaptation/adaptation_constraint.cc b/call/adaptation/adaptation_constraint.cc
new file mode 100644
index 0000000000..d62bb74f87
--- /dev/null
+++ b/call/adaptation/adaptation_constraint.cc
@@ -0,0 +1,17 @@
+/*
+ * Copyright 2020 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "call/adaptation/adaptation_constraint.h"
+
+namespace webrtc {
+
+AdaptationConstraint::~AdaptationConstraint() {}
+
+} // namespace webrtc
diff --git a/call/adaptation/adaptation_constraint.h b/call/adaptation/adaptation_constraint.h
new file mode 100644
index 0000000000..ce15e32a13
--- /dev/null
+++ b/call/adaptation/adaptation_constraint.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2020 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef CALL_ADAPTATION_ADAPTATION_CONSTRAINT_H_
+#define CALL_ADAPTATION_ADAPTATION_CONSTRAINT_H_
+
+#include <string>
+
+#include "api/scoped_refptr.h"
+#include "call/adaptation/resource.h"
+#include "call/adaptation/video_source_restrictions.h"
+#include "call/adaptation/video_stream_input_state.h"
+
+namespace webrtc {
+
+// Adaptation constraints have the ability to prevent applying a proposed
+// adaptation (expressed as restrictions before/after adaptation).
+class AdaptationConstraint {
+ public:
+ virtual ~AdaptationConstraint();
+
+ virtual std::string Name() const = 0;
+
+ // TODO(https://crbug.com/webrtc/11172): When we have multi-stream adaptation
+ // support, this interface needs to indicate which stream the adaptation
+ // applies to.
+ virtual bool IsAdaptationUpAllowed(
+ const VideoStreamInputState& input_state,
+ const VideoSourceRestrictions& restrictions_before,
+ const VideoSourceRestrictions& restrictions_after,
+ rtc::scoped_refptr<Resource> reason_resource) const = 0;
+};
+
+} // namespace webrtc
+
+#endif // CALL_ADAPTATION_ADAPTATION_CONSTRAINT_H_
diff --git a/call/adaptation/adaptation_listener.cc b/call/adaptation/adaptation_listener.cc
new file mode 100644
index 0000000000..acc1564f77
--- /dev/null
+++ b/call/adaptation/adaptation_listener.cc
@@ -0,0 +1,17 @@
+/*
+ * Copyright 2020 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "call/adaptation/adaptation_listener.h"
+
+namespace webrtc {
+
+AdaptationListener::~AdaptationListener() {}
+
+} // namespace webrtc
diff --git a/call/adaptation/adaptation_listener.h b/call/adaptation/adaptation_listener.h
new file mode 100644
index 0000000000..028897ea9d
--- /dev/null
+++ b/call/adaptation/adaptation_listener.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2020 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef CALL_ADAPTATION_ADAPTATION_LISTENER_H_
+#define CALL_ADAPTATION_ADAPTATION_LISTENER_H_
+
+#include "api/scoped_refptr.h"
+#include "call/adaptation/resource.h"
+#include "call/adaptation/video_source_restrictions.h"
+#include "call/adaptation/video_stream_input_state.h"
+
+namespace webrtc {
+
+// TODO(hbos): Can this be consolidated with
+// ResourceAdaptationProcessorListener::OnVideoSourceRestrictionsUpdated()? Both
+// listen to adaptations being applied, but on different layers with different
+// arguments.
+class AdaptationListener {
+ public:
+ virtual ~AdaptationListener();
+
+ // TODO(https://crbug.com/webrtc/11172): When we have multi-stream adaptation
+ // support, this interface needs to indicate which stream the adaptation
+ // applies to.
+ virtual void OnAdaptationApplied(
+ const VideoStreamInputState& input_state,
+ const VideoSourceRestrictions& restrictions_before,
+ const VideoSourceRestrictions& restrictions_after,
+ rtc::scoped_refptr<Resource> reason_resource) = 0;
+};
+
+} // namespace webrtc
+
+#endif // CALL_ADAPTATION_ADAPTATION_LISTENER_H_
diff --git a/call/adaptation/resource.h b/call/adaptation/resource.h
index febc29c9bb..ddc0fe855f 100644
--- a/call/adaptation/resource.h
+++ b/call/adaptation/resource.h
@@ -48,8 +48,8 @@ class ResourceListener {
// kOveruse or kUnderuse when resource usage is high or low enough that we
// should perform some sort of mitigation to fulfil the resource's constraints.
//
-// All methods defined in this interface, except RegisterAdaptationTaskQueue(),
-// MUST be invoked on the resource adaptation task queue.
+// All methods defined in this interface, except SetResourceListener(), MUST be
+// invoked on the resource adaptation task queue.
//
// Usage measurements may be performed on an implementation-specific task queue.
// The Resource is reference counted to prevent use-after-free when posting
@@ -61,21 +61,9 @@ class Resource : public rtc::RefCountInterface {
// Destruction may happen on any task queue.
~Resource() override;
- // Provides a pointer to the adaptation task queue. After this call, all
- // methods defined in this interface, including
- // UnregisterAdaptationTaskQueue() MUST be invoked on the adaptation task
- // queue. Registering the adaptation task queue may, however, happen off the
- // adaptation task queue.
- virtual void RegisterAdaptationTaskQueue(
- TaskQueueBase* resource_adaptation_queue) = 0;
- // Signals that the adaptation task queue is no longer safe to use. No
- // assumptions must be made as to whether or not tasks in-flight will run.
- virtual void UnregisterAdaptationTaskQueue() = 0;
-
- // The listeners MUST be informed any time UsageState() changes.
- virtual void SetResourceListener(ResourceListener* listener) = 0;
-
virtual std::string Name() const = 0;
+ // The listener MUST be informed any time UsageState() changes.
+ virtual void SetResourceListener(ResourceListener* listener) = 0;
// Within a single task running on the adaptation task queue, UsageState()
// MUST return the same value every time it is called.
// TODO(https://crbug.com/webrtc/11618): Remove the UsageState() getter in
@@ -86,20 +74,6 @@ class Resource : public rtc::RefCountInterface {
// Invalidates current usage measurements, i.e. in response to the system load
// changing. Example: an adaptation was just applied.
virtual void ClearUsageState() = 0;
-
- // This method allows the Resource to reject a proposed adaptation in the "up"
- // direction if it predicts this would cause overuse of this resource.
- virtual bool IsAdaptationUpAllowed(
- const VideoStreamInputState& input_state,
- const VideoSourceRestrictions& restrictions_before,
- const VideoSourceRestrictions& restrictions_after,
- rtc::scoped_refptr<Resource> reason_resource) const = 0;
-
- virtual void OnAdaptationApplied(
- const VideoStreamInputState& input_state,
- const VideoSourceRestrictions& restrictions_before,
- const VideoSourceRestrictions& restrictions_after,
- rtc::scoped_refptr<Resource> reason_resource) = 0;
};
} // namespace webrtc
diff --git a/call/adaptation/resource_adaptation_processor.cc b/call/adaptation/resource_adaptation_processor.cc
index a705ccfa55..ed8f78ddfd 100644
--- a/call/adaptation/resource_adaptation_processor.cc
+++ b/call/adaptation/resource_adaptation_processor.cc
@@ -49,12 +49,18 @@ ResourceAdaptationProcessor::ResourceAdaptationProcessor(
ResourceAdaptationProcessor::~ResourceAdaptationProcessor() {
RTC_DCHECK_RUN_ON(&sequence_checker_);
RTC_DCHECK(!is_resource_adaptation_enabled_);
- RTC_DCHECK(adaptation_listeners_.empty())
- << "There are listener(s) depending on a ResourceAdaptationProcessor "
- << "being destroyed.";
+ RTC_DCHECK(restrictions_listeners_.empty())
+ << "There are restrictions listener(s) depending on a "
+ << "ResourceAdaptationProcessor being destroyed.";
RTC_DCHECK(resources_.empty())
<< "There are resource(s) attached to a ResourceAdaptationProcessor "
<< "being destroyed.";
+ RTC_DCHECK(adaptation_constraints_.empty())
+ << "There are constaint(s) attached to a ResourceAdaptationProcessor "
+ << "being destroyed.";
+ RTC_DCHECK(adaptation_listeners_.empty())
+ << "There are listener(s) attached to a ResourceAdaptationProcessor "
+ << "being destroyed.";
}
void ResourceAdaptationProcessor::InitializeOnResourceAdaptationQueue() {
@@ -95,22 +101,22 @@ void ResourceAdaptationProcessor::StopResourceAdaptation() {
is_resource_adaptation_enabled_ = false;
}
-void ResourceAdaptationProcessor::AddAdaptationListener(
- ResourceAdaptationProcessorListener* adaptation_listener) {
+void ResourceAdaptationProcessor::AddRestrictionsListener(
+ VideoSourceRestrictionsListener* restrictions_listener) {
RTC_DCHECK_RUN_ON(&sequence_checker_);
- RTC_DCHECK(std::find(adaptation_listeners_.begin(),
- adaptation_listeners_.end(),
- adaptation_listener) == adaptation_listeners_.end());
- adaptation_listeners_.push_back(adaptation_listener);
+ RTC_DCHECK(std::find(restrictions_listeners_.begin(),
+ restrictions_listeners_.end(),
+ restrictions_listener) == restrictions_listeners_.end());
+ restrictions_listeners_.push_back(restrictions_listener);
}
-void ResourceAdaptationProcessor::RemoveAdaptationListener(
- ResourceAdaptationProcessorListener* adaptation_listener) {
+void ResourceAdaptationProcessor::RemoveRestrictionsListener(
+ VideoSourceRestrictionsListener* restrictions_listener) {
RTC_DCHECK_RUN_ON(&sequence_checker_);
- auto it = std::find(adaptation_listeners_.begin(),
- adaptation_listeners_.end(), adaptation_listener);
- RTC_DCHECK(it != adaptation_listeners_.end());
- adaptation_listeners_.erase(it);
+ auto it = std::find(restrictions_listeners_.begin(),
+ restrictions_listeners_.end(), restrictions_listener);
+ RTC_DCHECK(it != restrictions_listeners_.end());
+ restrictions_listeners_.erase(it);
}
void ResourceAdaptationProcessor::AddResource(
@@ -136,6 +142,42 @@ void ResourceAdaptationProcessor::RemoveResource(
resources_.erase(it);
}
+void ResourceAdaptationProcessor::AddAdaptationConstraint(
+ AdaptationConstraint* adaptation_constraint) {
+ RTC_DCHECK_RUN_ON(&sequence_checker_);
+ RTC_DCHECK(std::find(adaptation_constraints_.begin(),
+ adaptation_constraints_.end(),
+ adaptation_constraint) == adaptation_constraints_.end());
+ adaptation_constraints_.push_back(adaptation_constraint);
+}
+
+void ResourceAdaptationProcessor::RemoveAdaptationConstraint(
+ AdaptationConstraint* adaptation_constraint) {
+ RTC_DCHECK_RUN_ON(&sequence_checker_);
+ auto it = std::find(adaptation_constraints_.begin(),
+ adaptation_constraints_.end(), adaptation_constraint);
+ RTC_DCHECK(it != adaptation_constraints_.end());
+ adaptation_constraints_.erase(it);
+}
+
+void ResourceAdaptationProcessor::AddAdaptationListener(
+ AdaptationListener* adaptation_listener) {
+ RTC_DCHECK_RUN_ON(&sequence_checker_);
+ RTC_DCHECK(std::find(adaptation_listeners_.begin(),
+ adaptation_listeners_.end(),
+ adaptation_listener) == adaptation_listeners_.end());
+ adaptation_listeners_.push_back(adaptation_listener);
+}
+
+void ResourceAdaptationProcessor::RemoveAdaptationListener(
+ AdaptationListener* adaptation_listener) {
+ RTC_DCHECK_RUN_ON(&sequence_checker_);
+ auto it = std::find(adaptation_listeners_.begin(),
+ adaptation_listeners_.end(), adaptation_listener);
+ RTC_DCHECK(it != adaptation_listeners_.end());
+ adaptation_listeners_.erase(it);
+}
+
void ResourceAdaptationProcessor::SetDegradationPreference(
DegradationPreference degradation_preference) {
RTC_DCHECK_RUN_ON(&sequence_checker_);
@@ -181,8 +223,8 @@ void ResourceAdaptationProcessor::MaybeUpdateVideoSourceRestrictions(
effective_degradation_preference_)
<< "): " << new_source_restrictions.ToString();
last_reported_source_restrictions_ = std::move(new_source_restrictions);
- for (auto* adaptation_listener : adaptation_listeners_) {
- adaptation_listener->OnVideoSourceRestrictionsUpdated(
+ for (auto* restrictions_listener : restrictions_listeners_) {
+ restrictions_listener->OnVideoSourceRestrictionsUpdated(
last_reported_source_restrictions_,
stream_adapter_->adaptation_counters(), reason);
}
@@ -284,25 +326,26 @@ ResourceAdaptationProcessor::OnResourceUnderuse(
stream_adapter_->source_restrictions();
VideoSourceRestrictions restrictions_after =
stream_adapter_->PeekNextRestrictions(adaptation);
- for (const auto& resource : resources_) {
- if (!resource->IsAdaptationUpAllowed(input_state, restrictions_before,
- restrictions_after, reason_resource)) {
+ for (const auto* constraint : adaptation_constraints_) {
+ if (!constraint->IsAdaptationUpAllowed(input_state, restrictions_before,
+ restrictions_after,
+ reason_resource)) {
processing_in_progress_ = false;
rtc::StringBuilder message;
- message << "Not adapting up because resource \"" << resource->Name()
+ message << "Not adapting up because constraint \"" << constraint->Name()
<< "\" disallowed it";
return MitigationResultAndLogMessage(
- MitigationResult::kRejectedByResource, message.Release());
+ MitigationResult::kRejectedByConstraint, message.Release());
}
}
// Apply adaptation.
stream_adapter_->ApplyAdaptation(adaptation);
- for (const auto& resource : resources_) {
- resource->OnAdaptationApplied(input_state, restrictions_before,
- restrictions_after, reason_resource);
+ for (auto* adaptation_listener : adaptation_listeners_) {
+ adaptation_listener->OnAdaptationApplied(
+ input_state, restrictions_before, restrictions_after, reason_resource);
}
// Update VideoSourceRestrictions based on adaptation. This also informs the
- // |adaptation_listeners_|.
+ // |restrictions_listeners_|.
MaybeUpdateVideoSourceRestrictions(reason_resource);
processing_in_progress_ = false;
rtc::StringBuilder message;
@@ -359,12 +402,12 @@ ResourceAdaptationProcessor::OnResourceOveruse(
VideoSourceRestrictions restrictions_after =
stream_adapter_->PeekNextRestrictions(adaptation);
stream_adapter_->ApplyAdaptation(adaptation);
- for (const auto& resource : resources_) {
- resource->OnAdaptationApplied(input_state, restrictions_before,
- restrictions_after, reason_resource);
+ for (auto* adaptation_listener : adaptation_listeners_) {
+ adaptation_listener->OnAdaptationApplied(
+ input_state, restrictions_before, restrictions_after, reason_resource);
}
// Update VideoSourceRestrictions based on adaptation. This also informs the
- // |adaptation_listeners_|.
+ // |restrictions_listeners_|.
MaybeUpdateVideoSourceRestrictions(reason_resource);
processing_in_progress_ = false;
rtc::StringBuilder message;
diff --git a/call/adaptation/resource_adaptation_processor.h b/call/adaptation/resource_adaptation_processor.h
index 06b9a4c1cd..7988439002 100644
--- a/call/adaptation/resource_adaptation_processor.h
+++ b/call/adaptation/resource_adaptation_processor.h
@@ -21,6 +21,8 @@
#include "api/scoped_refptr.h"
#include "api/video/video_frame.h"
#include "api/video/video_stream_encoder_observer.h"
+#include "call/adaptation/adaptation_constraint.h"
+#include "call/adaptation/adaptation_listener.h"
#include "call/adaptation/resource.h"
#include "call/adaptation/resource_adaptation_processor_interface.h"
#include "call/adaptation/video_source_restrictions.h"
@@ -63,12 +65,19 @@ class ResourceAdaptationProcessor : public ResourceAdaptationProcessorInterface,
void StartResourceAdaptation() override;
void StopResourceAdaptation() override;
- void AddAdaptationListener(
- ResourceAdaptationProcessorListener* adaptation_listener) override;
- void RemoveAdaptationListener(
- ResourceAdaptationProcessorListener* adaptation_listener) override;
+ void AddRestrictionsListener(
+ VideoSourceRestrictionsListener* restrictions_listener) override;
+ void RemoveRestrictionsListener(
+ VideoSourceRestrictionsListener* restrictions_listener) override;
void AddResource(rtc::scoped_refptr<Resource> resource) override;
void RemoveResource(rtc::scoped_refptr<Resource> resource) override;
+ void AddAdaptationConstraint(
+ AdaptationConstraint* adaptation_constraint) override;
+ void RemoveAdaptationConstraint(
+ AdaptationConstraint* adaptation_constraint) override;
+ void AddAdaptationListener(AdaptationListener* adaptation_listener) override;
+ void RemoveAdaptationListener(
+ AdaptationListener* adaptation_listener) override;
void SetDegradationPreference(
DegradationPreference degradation_preference) override;
@@ -95,7 +104,7 @@ class ResourceAdaptationProcessor : public ResourceAdaptationProcessorInterface,
kInsufficientInput,
kRejectedByAdaptationCounts,
kRejectedByAdapter,
- kRejectedByResource,
+ kRejectedByConstraint,
kAdaptationApplied,
};
@@ -139,10 +148,14 @@ class ResourceAdaptationProcessor : public ResourceAdaptationProcessorInterface,
RTC_GUARDED_BY(sequence_checker_);
VideoStreamEncoderObserver* const encoder_stats_observer_
RTC_GUARDED_BY(sequence_checker_);
- std::vector<ResourceAdaptationProcessorListener*> adaptation_listeners_
+ std::vector<VideoSourceRestrictionsListener*> restrictions_listeners_
RTC_GUARDED_BY(sequence_checker_);
std::vector<rtc::scoped_refptr<Resource>> resources_
RTC_GUARDED_BY(sequence_checker_);
+ std::vector<AdaptationConstraint*> adaptation_constraints_
+ RTC_GUARDED_BY(sequence_checker_);
+ std::vector<AdaptationListener*> adaptation_listeners_
+ RTC_GUARDED_BY(sequence_checker_);
// Purely used for statistics, does not ensure mapped resources stay alive.
std::map<const Resource*, int> adaptations_counts_by_resource_
RTC_GUARDED_BY(sequence_checker_);
diff --git a/call/adaptation/resource_adaptation_processor_interface.cc b/call/adaptation/resource_adaptation_processor_interface.cc
index 4e5251ce90..f7381d3ff4 100644
--- a/call/adaptation/resource_adaptation_processor_interface.cc
+++ b/call/adaptation/resource_adaptation_processor_interface.cc
@@ -12,7 +12,7 @@
namespace webrtc {
-ResourceAdaptationProcessorListener::~ResourceAdaptationProcessorListener() {}
+VideoSourceRestrictionsListener::~VideoSourceRestrictionsListener() {}
ResourceAdaptationProcessorInterface::~ResourceAdaptationProcessorInterface() {}
diff --git a/call/adaptation/resource_adaptation_processor_interface.h b/call/adaptation/resource_adaptation_processor_interface.h
index d6295c4d75..8dafefaf2c 100644
--- a/call/adaptation/resource_adaptation_processor_interface.h
+++ b/call/adaptation/resource_adaptation_processor_interface.h
@@ -16,6 +16,8 @@
#include "api/scoped_refptr.h"
#include "api/video/video_adaptation_counters.h"
#include "api/video/video_frame.h"
+#include "call/adaptation/adaptation_constraint.h"
+#include "call/adaptation/adaptation_listener.h"
#include "call/adaptation/encoder_settings.h"
#include "call/adaptation/resource.h"
#include "call/adaptation/video_source_restrictions.h"
@@ -25,9 +27,9 @@ namespace webrtc {
// The listener is responsible for carrying out the reconfiguration of the video
// source such that the VideoSourceRestrictions are fulfilled.
-class ResourceAdaptationProcessorListener {
+class VideoSourceRestrictionsListener {
public:
- virtual ~ResourceAdaptationProcessorListener();
+ virtual ~VideoSourceRestrictionsListener();
// The |restrictions| are filtered by degradation preference but not the
// |adaptation_counters|, which are currently only reported for legacy stats
@@ -63,12 +65,20 @@ class ResourceAdaptationProcessorInterface {
// over time.
virtual void StartResourceAdaptation() = 0;
virtual void StopResourceAdaptation() = 0;
- virtual void AddAdaptationListener(
- ResourceAdaptationProcessorListener* adaptation_listener) = 0;
- virtual void RemoveAdaptationListener(
- ResourceAdaptationProcessorListener* adaptation_listener) = 0;
+ virtual void AddRestrictionsListener(
+ VideoSourceRestrictionsListener* restrictions_listener) = 0;
+ virtual void RemoveRestrictionsListener(
+ VideoSourceRestrictionsListener* restrictions_listener) = 0;
virtual void AddResource(rtc::scoped_refptr<Resource> resource) = 0;
virtual void RemoveResource(rtc::scoped_refptr<Resource> resource) = 0;
+ virtual void AddAdaptationConstraint(
+ AdaptationConstraint* adaptation_constraint) = 0;
+ virtual void RemoveAdaptationConstraint(
+ AdaptationConstraint* adaptation_constraint) = 0;
+ virtual void AddAdaptationListener(
+ AdaptationListener* adaptation_listener) = 0;
+ virtual void RemoveAdaptationListener(
+ AdaptationListener* adaptation_listener) = 0;
virtual void SetDegradationPreference(
DegradationPreference degradation_preference) = 0;
diff --git a/call/adaptation/resource_adaptation_processor_unittest.cc b/call/adaptation/resource_adaptation_processor_unittest.cc
index c150700ae8..6ff24b165f 100644
--- a/call/adaptation/resource_adaptation_processor_unittest.cc
+++ b/call/adaptation/resource_adaptation_processor_unittest.cc
@@ -14,6 +14,8 @@
#include "api/video/video_adaptation_counters.h"
#include "call/adaptation/resource.h"
#include "call/adaptation/resource_adaptation_processor_interface.h"
+#include "call/adaptation/test/fake_adaptation_constraint.h"
+#include "call/adaptation/test/fake_adaptation_listener.h"
#include "call/adaptation/test/fake_frame_rate_provider.h"
#include "call/adaptation/test/fake_resource.h"
#include "call/adaptation/video_source_restrictions.h"
@@ -29,15 +31,15 @@ namespace {
const int kDefaultFrameRate = 30;
const int kDefaultFrameSize = 1280 * 720;
-class ResourceAdaptationProcessorListenerForTesting
- : public ResourceAdaptationProcessorListener {
+class VideoSourceRestrictionsListenerForTesting
+ : public VideoSourceRestrictionsListener {
public:
- ResourceAdaptationProcessorListenerForTesting()
+ VideoSourceRestrictionsListenerForTesting()
: restrictions_updated_count_(0),
restrictions_(),
adaptation_counters_(),
reason_(nullptr) {}
- ~ResourceAdaptationProcessorListenerForTesting() override {}
+ ~VideoSourceRestrictionsListenerForTesting() override {}
size_t restrictions_updated_count() const {
return restrictions_updated_count_;
@@ -48,7 +50,7 @@ class ResourceAdaptationProcessorListenerForTesting
}
rtc::scoped_refptr<Resource> reason() const { return reason_; }
- // ResourceAdaptationProcessorListener implementation.
+ // VideoSourceRestrictionsListener implementation.
void OnVideoSourceRestrictionsUpdated(
VideoSourceRestrictions restrictions,
const VideoAdaptationCounters& adaptation_counters,
@@ -74,18 +76,19 @@ class ResourceAdaptationProcessorTest : public ::testing::Test {
input_state_provider_(&frame_rate_provider_),
resource_(FakeResource::Create("FakeResource")),
other_resource_(FakeResource::Create("OtherFakeResource")),
+ adaptation_constraint_("FakeAdaptationConstraint"),
+ adaptation_listener_(),
processor_(std::make_unique<ResourceAdaptationProcessor>(
&input_state_provider_,
/*encoder_stats_observer=*/&frame_rate_provider_)) {
- resource_->RegisterAdaptationTaskQueue(resource_adaptation_queue_.Get());
- other_resource_->RegisterAdaptationTaskQueue(
- resource_adaptation_queue_.Get());
rtc::Event event;
resource_adaptation_queue_.PostTask([this, &event] {
processor_->InitializeOnResourceAdaptationQueue();
- processor_->AddAdaptationListener(&processor_listener_);
+ processor_->AddRestrictionsListener(&restrictions_listener_);
processor_->AddResource(resource_);
processor_->AddResource(other_resource_);
+ processor_->AddAdaptationConstraint(&adaptation_constraint_);
+ processor_->AddAdaptationListener(&adaptation_listener_);
event.Set();
});
event.Wait(rtc::Event::kForever);
@@ -94,9 +97,11 @@ class ResourceAdaptationProcessorTest : public ::testing::Test {
rtc::Event event;
resource_adaptation_queue_.PostTask([this, &event] {
processor_->StopResourceAdaptation();
+ processor_->RemoveRestrictionsListener(&restrictions_listener_);
processor_->RemoveResource(resource_);
processor_->RemoveResource(other_resource_);
- processor_->RemoveAdaptationListener(&processor_listener_);
+ processor_->RemoveAdaptationConstraint(&adaptation_constraint_);
+ processor_->RemoveAdaptationListener(&adaptation_listener_);
processor_.reset();
event.Set();
});
@@ -123,8 +128,10 @@ class ResourceAdaptationProcessorTest : public ::testing::Test {
VideoStreamInputStateProvider input_state_provider_;
rtc::scoped_refptr<FakeResource> resource_;
rtc::scoped_refptr<FakeResource> other_resource_;
+ FakeAdaptationConstraint adaptation_constraint_;
+ FakeAdaptationListener adaptation_listener_;
std::unique_ptr<ResourceAdaptationProcessor> processor_;
- ResourceAdaptationProcessorListenerForTesting processor_listener_;
+ VideoSourceRestrictionsListenerForTesting restrictions_listener_;
};
} // namespace
@@ -139,8 +146,8 @@ TEST_F(ResourceAdaptationProcessorTest, DisabledByDefault) {
SetInputStates(true, kDefaultFrameRate, kDefaultFrameSize);
processor_->StartResourceAdaptation();
// Adaptation does not happen when disabled.
- resource_->set_usage_state(ResourceUsageState::kOveruse);
- EXPECT_EQ(0u, processor_listener_.restrictions_updated_count());
+ resource_->SetUsageState(ResourceUsageState::kOveruse);
+ EXPECT_EQ(0u, restrictions_listener_.restrictions_updated_count());
},
RTC_FROM_HERE);
}
@@ -154,12 +161,12 @@ TEST_F(ResourceAdaptationProcessorTest, InsufficientInput) {
// Adaptation does not happen if input is insufficient.
// When frame size is missing (OnFrameSizeObserved not called yet).
input_state_provider_.OnHasInputChanged(true);
- resource_->set_usage_state(ResourceUsageState::kOveruse);
- EXPECT_EQ(0u, processor_listener_.restrictions_updated_count());
+ resource_->SetUsageState(ResourceUsageState::kOveruse);
+ EXPECT_EQ(0u, restrictions_listener_.restrictions_updated_count());
// When "has input" is missing.
SetInputStates(false, kDefaultFrameRate, kDefaultFrameSize);
- resource_->set_usage_state(ResourceUsageState::kOveruse);
- EXPECT_EQ(0u, processor_listener_.restrictions_updated_count());
+ resource_->SetUsageState(ResourceUsageState::kOveruse);
+ EXPECT_EQ(0u, restrictions_listener_.restrictions_updated_count());
// Note: frame rate cannot be missing, if unset it is 0.
},
RTC_FROM_HERE);
@@ -177,9 +184,9 @@ TEST_F(ResourceAdaptationProcessorTest,
DegradationPreference::MAINTAIN_FRAMERATE);
processor_->StartResourceAdaptation();
SetInputStates(true, kDefaultFrameRate, kDefaultFrameSize);
- resource_->set_usage_state(ResourceUsageState::kOveruse);
- EXPECT_EQ(1u, processor_listener_.restrictions_updated_count());
- EXPECT_TRUE(processor_listener_.restrictions()
+ resource_->SetUsageState(ResourceUsageState::kOveruse);
+ EXPECT_EQ(1u, restrictions_listener_.restrictions_updated_count());
+ EXPECT_TRUE(restrictions_listener_.restrictions()
.max_pixels_per_frame()
.has_value());
},
@@ -194,10 +201,10 @@ TEST_F(ResourceAdaptationProcessorTest,
DegradationPreference::MAINTAIN_RESOLUTION);
processor_->StartResourceAdaptation();
SetInputStates(true, kDefaultFrameRate, kDefaultFrameSize);
- resource_->set_usage_state(ResourceUsageState::kOveruse);
- EXPECT_EQ(1u, processor_listener_.restrictions_updated_count());
+ resource_->SetUsageState(ResourceUsageState::kOveruse);
+ EXPECT_EQ(1u, restrictions_listener_.restrictions_updated_count());
EXPECT_TRUE(
- processor_listener_.restrictions().max_frame_rate().has_value());
+ restrictions_listener_.restrictions().max_frame_rate().has_value());
},
RTC_FROM_HERE);
}
@@ -214,15 +221,15 @@ TEST_F(ResourceAdaptationProcessorTest,
// BalancedDegradationSettings, VideoStreamAdapter and default input
// states. This test requires it to be achieved within 4 adaptations.
for (size_t i = 0; i < 4; ++i) {
- resource_->set_usage_state(ResourceUsageState::kOveruse);
- EXPECT_EQ(i + 1, processor_listener_.restrictions_updated_count());
- RestrictSource(processor_listener_.restrictions());
+ resource_->SetUsageState(ResourceUsageState::kOveruse);
+ EXPECT_EQ(i + 1, restrictions_listener_.restrictions_updated_count());
+ RestrictSource(restrictions_listener_.restrictions());
}
- EXPECT_TRUE(processor_listener_.restrictions()
+ EXPECT_TRUE(restrictions_listener_.restrictions()
.max_pixels_per_frame()
.has_value());
EXPECT_TRUE(
- processor_listener_.restrictions().max_frame_rate().has_value());
+ restrictions_listener_.restrictions().max_frame_rate().has_value());
},
RTC_FROM_HERE);
}
@@ -234,12 +241,12 @@ TEST_F(ResourceAdaptationProcessorTest, AwaitingPreviousAdaptation) {
DegradationPreference::MAINTAIN_FRAMERATE);
processor_->StartResourceAdaptation();
SetInputStates(true, kDefaultFrameRate, kDefaultFrameSize);
- resource_->set_usage_state(ResourceUsageState::kOveruse);
- EXPECT_EQ(1u, processor_listener_.restrictions_updated_count());
+ resource_->SetUsageState(ResourceUsageState::kOveruse);
+ EXPECT_EQ(1u, restrictions_listener_.restrictions_updated_count());
// If we don't restrict the source then adaptation will not happen again
// due to "awaiting previous adaptation". This prevents "double-adapt".
- resource_->set_usage_state(ResourceUsageState::kOveruse);
- EXPECT_EQ(1u, processor_listener_.restrictions_updated_count());
+ resource_->SetUsageState(ResourceUsageState::kOveruse);
+ EXPECT_EQ(1u, restrictions_listener_.restrictions_updated_count());
},
RTC_FROM_HERE);
}
@@ -251,8 +258,8 @@ TEST_F(ResourceAdaptationProcessorTest, CannotAdaptUpWhenUnrestricted) {
DegradationPreference::MAINTAIN_FRAMERATE);
processor_->StartResourceAdaptation();
SetInputStates(true, kDefaultFrameRate, kDefaultFrameSize);
- resource_->set_usage_state(ResourceUsageState::kUnderuse);
- EXPECT_EQ(0u, processor_listener_.restrictions_updated_count());
+ resource_->SetUsageState(ResourceUsageState::kUnderuse);
+ EXPECT_EQ(0u, restrictions_listener_.restrictions_updated_count());
},
RTC_FROM_HERE);
}
@@ -264,13 +271,13 @@ TEST_F(ResourceAdaptationProcessorTest, UnderuseTakesUsBackToUnrestricted) {
DegradationPreference::MAINTAIN_FRAMERATE);
processor_->StartResourceAdaptation();
SetInputStates(true, kDefaultFrameRate, kDefaultFrameSize);
- resource_->set_usage_state(ResourceUsageState::kOveruse);
- EXPECT_EQ(1u, processor_listener_.restrictions_updated_count());
- RestrictSource(processor_listener_.restrictions());
- resource_->set_usage_state(ResourceUsageState::kUnderuse);
- EXPECT_EQ(2u, processor_listener_.restrictions_updated_count());
+ resource_->SetUsageState(ResourceUsageState::kOveruse);
+ EXPECT_EQ(1u, restrictions_listener_.restrictions_updated_count());
+ RestrictSource(restrictions_listener_.restrictions());
+ resource_->SetUsageState(ResourceUsageState::kUnderuse);
+ EXPECT_EQ(2u, restrictions_listener_.restrictions_updated_count());
EXPECT_EQ(VideoSourceRestrictions(),
- processor_listener_.restrictions());
+ restrictions_listener_.restrictions());
},
RTC_FROM_HERE);
}
@@ -283,13 +290,13 @@ TEST_F(ResourceAdaptationProcessorTest, ResourcesCanPreventAdaptingUp) {
processor_->StartResourceAdaptation();
SetInputStates(true, kDefaultFrameRate, kDefaultFrameSize);
// Adapt down so that we can adapt up.
- resource_->set_usage_state(ResourceUsageState::kOveruse);
- EXPECT_EQ(1u, processor_listener_.restrictions_updated_count());
- RestrictSource(processor_listener_.restrictions());
+ resource_->SetUsageState(ResourceUsageState::kOveruse);
+ EXPECT_EQ(1u, restrictions_listener_.restrictions_updated_count());
+ RestrictSource(restrictions_listener_.restrictions());
// Adapting up is prevented.
- resource_->set_is_adaptation_up_allowed(false);
- resource_->set_usage_state(ResourceUsageState::kUnderuse);
- EXPECT_EQ(1u, processor_listener_.restrictions_updated_count());
+ adaptation_constraint_.set_is_adaptation_up_allowed(false);
+ resource_->SetUsageState(ResourceUsageState::kUnderuse);
+ EXPECT_EQ(1u, restrictions_listener_.restrictions_updated_count());
},
RTC_FROM_HERE);
}
@@ -302,13 +309,13 @@ TEST_F(ResourceAdaptationProcessorTest,
DegradationPreference::MAINTAIN_FRAMERATE);
processor_->StartResourceAdaptation();
SetInputStates(true, kDefaultFrameRate, kDefaultFrameSize);
- resource_->set_usage_state(ResourceUsageState::kOveruse);
- EXPECT_EQ(1u, processor_listener_.restrictions_updated_count());
- RestrictSource(processor_listener_.restrictions());
+ resource_->SetUsageState(ResourceUsageState::kOveruse);
+ EXPECT_EQ(1u, restrictions_listener_.restrictions_updated_count());
+ RestrictSource(restrictions_listener_.restrictions());
// Other resource signals under-use
- other_resource_->set_usage_state(ResourceUsageState::kUnderuse);
- EXPECT_EQ(1u, processor_listener_.restrictions_updated_count());
+ other_resource_->SetUsageState(ResourceUsageState::kUnderuse);
+ EXPECT_EQ(1u, restrictions_listener_.restrictions_updated_count());
},
RTC_FROM_HERE);
}
@@ -321,19 +328,19 @@ TEST_F(ResourceAdaptationProcessorTest,
DegradationPreference::MAINTAIN_FRAMERATE);
processor_->StartResourceAdaptation();
SetInputStates(true, kDefaultFrameRate, kDefaultFrameSize);
- resource_->set_usage_state(ResourceUsageState::kOveruse);
- EXPECT_EQ(1u, processor_listener_.restrictions_updated_count());
+ resource_->SetUsageState(ResourceUsageState::kOveruse);
+ EXPECT_EQ(1u, restrictions_listener_.restrictions_updated_count());
processor_->ResetVideoSourceRestrictions();
- EXPECT_EQ(0, processor_listener_.adaptation_counters().Total());
- other_resource_->set_usage_state(ResourceUsageState::kOveruse);
- EXPECT_EQ(1, processor_listener_.adaptation_counters().Total());
- RestrictSource(processor_listener_.restrictions());
+ EXPECT_EQ(0, restrictions_listener_.adaptation_counters().Total());
+ other_resource_->SetUsageState(ResourceUsageState::kOveruse);
+ EXPECT_EQ(1, restrictions_listener_.adaptation_counters().Total());
+ RestrictSource(restrictions_listener_.restrictions());
// resource_ did not overuse after we reset the restrictions, so adapt
// up should be disallowed.
- resource_->set_usage_state(ResourceUsageState::kUnderuse);
- EXPECT_EQ(1, processor_listener_.adaptation_counters().Total());
+ resource_->SetUsageState(ResourceUsageState::kUnderuse);
+ EXPECT_EQ(1, restrictions_listener_.adaptation_counters().Total());
},
RTC_FROM_HERE);
}
@@ -346,30 +353,30 @@ TEST_F(ResourceAdaptationProcessorTest,
DegradationPreference::MAINTAIN_FRAMERATE);
processor_->StartResourceAdaptation();
SetInputStates(true, kDefaultFrameRate, kDefaultFrameSize);
- resource_->set_usage_state(ResourceUsageState::kOveruse);
- EXPECT_EQ(1, processor_listener_.adaptation_counters().Total());
- RestrictSource(processor_listener_.restrictions());
- other_resource_->set_usage_state(ResourceUsageState::kOveruse);
- EXPECT_EQ(2, processor_listener_.adaptation_counters().Total());
- RestrictSource(processor_listener_.restrictions());
- other_resource_->set_usage_state(ResourceUsageState::kOveruse);
- EXPECT_EQ(3, processor_listener_.adaptation_counters().Total());
- RestrictSource(processor_listener_.restrictions());
-
- resource_->set_usage_state(ResourceUsageState::kUnderuse);
- EXPECT_EQ(2, processor_listener_.adaptation_counters().Total());
- RestrictSource(processor_listener_.restrictions());
+ resource_->SetUsageState(ResourceUsageState::kOveruse);
+ EXPECT_EQ(1, restrictions_listener_.adaptation_counters().Total());
+ RestrictSource(restrictions_listener_.restrictions());
+ other_resource_->SetUsageState(ResourceUsageState::kOveruse);
+ EXPECT_EQ(2, restrictions_listener_.adaptation_counters().Total());
+ RestrictSource(restrictions_listener_.restrictions());
+ other_resource_->SetUsageState(ResourceUsageState::kOveruse);
+ EXPECT_EQ(3, restrictions_listener_.adaptation_counters().Total());
+ RestrictSource(restrictions_listener_.restrictions());
+
+ resource_->SetUsageState(ResourceUsageState::kUnderuse);
+ EXPECT_EQ(2, restrictions_listener_.adaptation_counters().Total());
+ RestrictSource(restrictions_listener_.restrictions());
// Does not trigger adaptation since resource has no adaptations left.
- resource_->set_usage_state(ResourceUsageState::kUnderuse);
- EXPECT_EQ(2, processor_listener_.adaptation_counters().Total());
- RestrictSource(processor_listener_.restrictions());
-
- other_resource_->set_usage_state(ResourceUsageState::kUnderuse);
- EXPECT_EQ(1, processor_listener_.adaptation_counters().Total());
- RestrictSource(processor_listener_.restrictions());
- other_resource_->set_usage_state(ResourceUsageState::kUnderuse);
- EXPECT_EQ(0, processor_listener_.adaptation_counters().Total());
- RestrictSource(processor_listener_.restrictions());
+ resource_->SetUsageState(ResourceUsageState::kUnderuse);
+ EXPECT_EQ(2, restrictions_listener_.adaptation_counters().Total());
+ RestrictSource(restrictions_listener_.restrictions());
+
+ other_resource_->SetUsageState(ResourceUsageState::kUnderuse);
+ EXPECT_EQ(1, restrictions_listener_.adaptation_counters().Total());
+ RestrictSource(restrictions_listener_.restrictions());
+ other_resource_->SetUsageState(ResourceUsageState::kUnderuse);
+ EXPECT_EQ(0, restrictions_listener_.adaptation_counters().Total());
+ RestrictSource(restrictions_listener_.restrictions());
},
RTC_FROM_HERE);
}
@@ -381,8 +388,8 @@ TEST_F(ResourceAdaptationProcessorTest, AdaptingTriggersOnAdaptationApplied) {
DegradationPreference::MAINTAIN_FRAMERATE);
processor_->StartResourceAdaptation();
SetInputStates(true, kDefaultFrameRate, kDefaultFrameSize);
- resource_->set_usage_state(ResourceUsageState::kOveruse);
- EXPECT_EQ(1u, resource_->num_adaptations_applied());
+ resource_->SetUsageState(ResourceUsageState::kOveruse);
+ EXPECT_EQ(1u, adaptation_listener_.num_adaptations_applied());
},
RTC_FROM_HERE);
}
@@ -394,8 +401,8 @@ TEST_F(ResourceAdaptationProcessorTest, AdaptingClearsResourceUsageState) {
DegradationPreference::MAINTAIN_FRAMERATE);
processor_->StartResourceAdaptation();
SetInputStates(true, kDefaultFrameRate, kDefaultFrameSize);
- resource_->set_usage_state(ResourceUsageState::kOveruse);
- EXPECT_EQ(1u, processor_listener_.restrictions_updated_count());
+ resource_->SetUsageState(ResourceUsageState::kOveruse);
+ EXPECT_EQ(1u, restrictions_listener_.restrictions_updated_count());
EXPECT_FALSE(resource_->UsageState().has_value());
},
RTC_FROM_HERE);
@@ -407,8 +414,8 @@ TEST_F(ResourceAdaptationProcessorTest,
[this] {
processor_->SetDegradationPreference(DegradationPreference::DISABLED);
processor_->StartResourceAdaptation();
- resource_->set_usage_state(ResourceUsageState::kOveruse);
- EXPECT_EQ(0u, processor_listener_.restrictions_updated_count());
+ resource_->SetUsageState(ResourceUsageState::kOveruse);
+ EXPECT_EQ(0u, restrictions_listener_.restrictions_updated_count());
EXPECT_FALSE(resource_->UsageState().has_value());
},
RTC_FROM_HERE);
@@ -422,20 +429,20 @@ TEST_F(ResourceAdaptationProcessorTest,
DegradationPreference::MAINTAIN_FRAMERATE);
processor_->StartResourceAdaptation();
SetInputStates(true, kDefaultFrameRate, kDefaultFrameSize);
- other_resource_->set_usage_state(ResourceUsageState::kUnderuse);
+ other_resource_->SetUsageState(ResourceUsageState::kUnderuse);
// Does not trigger adapataion because there's no restriction.
- EXPECT_EQ(0, processor_listener_.adaptation_counters().Total());
+ EXPECT_EQ(0, restrictions_listener_.adaptation_counters().Total());
- RestrictSource(processor_listener_.restrictions());
- resource_->set_usage_state(ResourceUsageState::kOveruse);
+ RestrictSource(restrictions_listener_.restrictions());
+ resource_->SetUsageState(ResourceUsageState::kOveruse);
// Adapts down even if other resource asked for adapting up.
- EXPECT_EQ(1, processor_listener_.adaptation_counters().Total());
+ EXPECT_EQ(1, restrictions_listener_.adaptation_counters().Total());
- RestrictSource(processor_listener_.restrictions());
- other_resource_->set_usage_state(ResourceUsageState::kUnderuse);
+ RestrictSource(restrictions_listener_.restrictions());
+ other_resource_->SetUsageState(ResourceUsageState::kUnderuse);
// Doesn't adapt up because adaptation is due to another resource.
- EXPECT_EQ(1, processor_listener_.adaptation_counters().Total());
- RestrictSource(processor_listener_.restrictions());
+ EXPECT_EQ(1, restrictions_listener_.adaptation_counters().Total());
+ RestrictSource(restrictions_listener_.restrictions());
},
RTC_FROM_HERE);
}
diff --git a/call/adaptation/resource_unittest.cc b/call/adaptation/resource_unittest.cc
index ad93fbd2fa..afa32f0879 100644
--- a/call/adaptation/resource_unittest.cc
+++ b/call/adaptation/resource_unittest.cc
@@ -14,8 +14,6 @@
#include "api/scoped_refptr.h"
#include "call/adaptation/test/fake_resource.h"
-#include "rtc_base/event.h"
-#include "rtc_base/task_queue_for_test.h"
#include "test/gmock.h"
#include "test/gtest.h"
@@ -34,46 +32,30 @@ class MockResourceListener : public ResourceListener {
class ResourceTest : public ::testing::Test {
public:
- ResourceTest()
- : resource_adaptation_queue_("ResourceAdaptationQueue"),
- fake_resource_(FakeResource::Create("FakeResource")) {
- fake_resource_->RegisterAdaptationTaskQueue(
- resource_adaptation_queue_.Get());
- }
+ ResourceTest() : fake_resource_(FakeResource::Create("FakeResource")) {}
protected:
- const std::unique_ptr<TaskQueueFactory> task_queue_factory_;
- TaskQueueForTest resource_adaptation_queue_;
rtc::scoped_refptr<FakeResource> fake_resource_;
};
TEST_F(ResourceTest, RegisteringListenerReceivesCallbacks) {
- resource_adaptation_queue_.SendTask(
- [this] {
- StrictMock<MockResourceListener> resource_listener;
- fake_resource_->SetResourceListener(&resource_listener);
- EXPECT_CALL(resource_listener, OnResourceUsageStateMeasured(_))
- .Times(1)
- .WillOnce([](rtc::scoped_refptr<Resource> resource) {
- EXPECT_EQ(ResourceUsageState::kOveruse, resource->UsageState());
- });
- fake_resource_->set_usage_state(ResourceUsageState::kOveruse);
- fake_resource_->SetResourceListener(nullptr);
- },
- RTC_FROM_HERE);
+ StrictMock<MockResourceListener> resource_listener;
+ fake_resource_->SetResourceListener(&resource_listener);
+ EXPECT_CALL(resource_listener, OnResourceUsageStateMeasured(_))
+ .Times(1)
+ .WillOnce([](rtc::scoped_refptr<Resource> resource) {
+ EXPECT_EQ(ResourceUsageState::kOveruse, resource->UsageState());
+ });
+ fake_resource_->SetUsageState(ResourceUsageState::kOveruse);
+ fake_resource_->SetResourceListener(nullptr);
}
TEST_F(ResourceTest, UnregisteringListenerStopsCallbacks) {
- resource_adaptation_queue_.SendTask(
- [this] {
- StrictMock<MockResourceListener> resource_listener;
- fake_resource_->SetResourceListener(&resource_listener);
- fake_resource_->SetResourceListener(nullptr);
- EXPECT_CALL(resource_listener, OnResourceUsageStateMeasured(_))
- .Times(0);
- fake_resource_->set_usage_state(ResourceUsageState::kOveruse);
- },
- RTC_FROM_HERE);
+ StrictMock<MockResourceListener> resource_listener;
+ fake_resource_->SetResourceListener(&resource_listener);
+ fake_resource_->SetResourceListener(nullptr);
+ EXPECT_CALL(resource_listener, OnResourceUsageStateMeasured(_)).Times(0);
+ fake_resource_->SetUsageState(ResourceUsageState::kOveruse);
}
} // namespace webrtc
diff --git a/call/adaptation/test/fake_adaptation_constraint.cc b/call/adaptation/test/fake_adaptation_constraint.cc
new file mode 100644
index 0000000000..983885e58a
--- /dev/null
+++ b/call/adaptation/test/fake_adaptation_constraint.cc
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2020 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "call/adaptation/test/fake_adaptation_constraint.h"
+
+#include <utility>
+
+namespace webrtc {
+
+FakeAdaptationConstraint::FakeAdaptationConstraint(std::string name)
+ : name_(std::move(name)), is_adaptation_up_allowed_(true) {}
+
+FakeAdaptationConstraint::~FakeAdaptationConstraint() {}
+
+void FakeAdaptationConstraint::set_is_adaptation_up_allowed(
+ bool is_adaptation_up_allowed) {
+ is_adaptation_up_allowed_ = is_adaptation_up_allowed;
+}
+
+std::string FakeAdaptationConstraint::Name() const {
+ return name_;
+}
+
+bool FakeAdaptationConstraint::IsAdaptationUpAllowed(
+ const VideoStreamInputState& input_state,
+ const VideoSourceRestrictions& restrictions_before,
+ const VideoSourceRestrictions& restrictions_after,
+ rtc::scoped_refptr<Resource> reason_resource) const {
+ return is_adaptation_up_allowed_;
+}
+
+} // namespace webrtc
diff --git a/call/adaptation/test/fake_adaptation_constraint.h b/call/adaptation/test/fake_adaptation_constraint.h
new file mode 100644
index 0000000000..74637f48fd
--- /dev/null
+++ b/call/adaptation/test/fake_adaptation_constraint.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2020 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef CALL_ADAPTATION_TEST_FAKE_ADAPTATION_CONSTRAINT_H_
+#define CALL_ADAPTATION_TEST_FAKE_ADAPTATION_CONSTRAINT_H_
+
+#include <string>
+
+#include "call/adaptation/adaptation_constraint.h"
+
+namespace webrtc {
+
+class FakeAdaptationConstraint : public AdaptationConstraint {
+ public:
+ explicit FakeAdaptationConstraint(std::string name);
+ ~FakeAdaptationConstraint() override;
+
+ void set_is_adaptation_up_allowed(bool is_adaptation_up_allowed);
+
+ // AdaptationConstraint implementation.
+ std::string Name() const override;
+ bool IsAdaptationUpAllowed(
+ const VideoStreamInputState& input_state,
+ const VideoSourceRestrictions& restrictions_before,
+ const VideoSourceRestrictions& restrictions_after,
+ rtc::scoped_refptr<Resource> reason_resource) const override;
+
+ private:
+ const std::string name_;
+ bool is_adaptation_up_allowed_;
+};
+
+} // namespace webrtc
+
+#endif // CALL_ADAPTATION_TEST_FAKE_ADAPTATION_CONSTRAINT_H_
diff --git a/call/adaptation/test/fake_adaptation_listener.cc b/call/adaptation/test/fake_adaptation_listener.cc
new file mode 100644
index 0000000000..7feecd6367
--- /dev/null
+++ b/call/adaptation/test/fake_adaptation_listener.cc
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2020 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#include "call/adaptation/test/fake_adaptation_listener.h"
+
+namespace webrtc {
+
+FakeAdaptationListener::FakeAdaptationListener()
+ : num_adaptations_applied_(0) {}
+
+FakeAdaptationListener::~FakeAdaptationListener() {}
+
+size_t FakeAdaptationListener::num_adaptations_applied() const {
+ return num_adaptations_applied_;
+}
+
+void FakeAdaptationListener::OnAdaptationApplied(
+ const VideoStreamInputState& input_state,
+ const VideoSourceRestrictions& restrictions_before,
+ const VideoSourceRestrictions& restrictions_after,
+ rtc::scoped_refptr<Resource> reason_resource) {
+ ++num_adaptations_applied_;
+}
+
+} // namespace webrtc
diff --git a/call/adaptation/test/fake_adaptation_listener.h b/call/adaptation/test/fake_adaptation_listener.h
new file mode 100644
index 0000000000..c60ba3089b
--- /dev/null
+++ b/call/adaptation/test/fake_adaptation_listener.h
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2020 The WebRTC Project Authors. All rights reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+
+#ifndef CALL_ADAPTATION_TEST_FAKE_ADAPTATION_LISTENER_H_
+#define CALL_ADAPTATION_TEST_FAKE_ADAPTATION_LISTENER_H_
+
+#include "call/adaptation/adaptation_listener.h"
+
+namespace webrtc {
+
+class FakeAdaptationListener : public AdaptationListener {
+ public:
+ FakeAdaptationListener();
+ ~FakeAdaptationListener() override;
+
+ size_t num_adaptations_applied() const;
+
+ // AdaptationListener implementation.
+ void OnAdaptationApplied(
+ const VideoStreamInputState& input_state,
+ const VideoSourceRestrictions& restrictions_before,
+ const VideoSourceRestrictions& restrictions_after,
+ rtc::scoped_refptr<Resource> reason_resource) override;
+
+ private:
+ size_t num_adaptations_applied_;
+};
+
+} // namespace webrtc
+
+#endif // CALL_ADAPTATION_TEST_FAKE_ADAPTATION_LISTENER_H_
diff --git a/call/adaptation/test/fake_resource.cc b/call/adaptation/test/fake_resource.cc
index fef765b9e4..113f4b5450 100644
--- a/call/adaptation/test/fake_resource.cc
+++ b/call/adaptation/test/fake_resource.cc
@@ -14,7 +14,6 @@
#include <utility>
#include "rtc_base/ref_counted_object.h"
-#include "rtc_base/task_utils/to_queued_task.h"
namespace webrtc {
@@ -25,91 +24,33 @@ rtc::scoped_refptr<FakeResource> FakeResource::Create(std::string name) {
FakeResource::FakeResource(std::string name)
: Resource(),
- lock_(),
name_(std::move(name)),
- resource_adaptation_queue_(nullptr),
- is_adaptation_up_allowed_(true),
- num_adaptations_applied_(0),
- usage_state_(absl::nullopt),
- listener_(nullptr) {}
+ listener_(nullptr),
+ usage_state_(absl::nullopt) {}
FakeResource::~FakeResource() {}
-void FakeResource::set_usage_state(ResourceUsageState usage_state) {
- if (!resource_adaptation_queue_->IsCurrent()) {
- resource_adaptation_queue_->PostTask(ToQueuedTask(
- [this_ref = rtc::scoped_refptr<FakeResource>(this), usage_state] {
- this_ref->set_usage_state(usage_state);
- }));
- return;
- }
- RTC_DCHECK_RUN_ON(resource_adaptation_queue_);
+void FakeResource::SetUsageState(ResourceUsageState usage_state) {
usage_state_ = usage_state;
if (listener_) {
listener_->OnResourceUsageStateMeasured(this);
}
}
-void FakeResource::set_is_adaptation_up_allowed(bool is_adaptation_up_allowed) {
- rtc::CritScope crit(&lock_);
- is_adaptation_up_allowed_ = is_adaptation_up_allowed;
-}
-
-size_t FakeResource::num_adaptations_applied() const {
- rtc::CritScope crit(&lock_);
- return num_adaptations_applied_;
-}
-
-void FakeResource::RegisterAdaptationTaskQueue(
- TaskQueueBase* resource_adaptation_queue) {
- RTC_DCHECK(!resource_adaptation_queue_);
- RTC_DCHECK(resource_adaptation_queue);
- resource_adaptation_queue_ = resource_adaptation_queue;
-}
-
-void FakeResource::UnregisterAdaptationTaskQueue() {
- RTC_DCHECK(resource_adaptation_queue_);
- RTC_DCHECK_RUN_ON(resource_adaptation_queue_);
- resource_adaptation_queue_ = nullptr;
+std::string FakeResource::Name() const {
+ return name_;
}
void FakeResource::SetResourceListener(ResourceListener* listener) {
- RTC_DCHECK_RUN_ON(resource_adaptation_queue_);
listener_ = listener;
}
-std::string FakeResource::Name() const {
- return name_;
-}
-
absl::optional<ResourceUsageState> FakeResource::UsageState() const {
- RTC_DCHECK_RUN_ON(resource_adaptation_queue_);
return usage_state_;
}
void FakeResource::ClearUsageState() {
- RTC_DCHECK_RUN_ON(resource_adaptation_queue_);
usage_state_ = absl::nullopt;
}
-bool FakeResource::IsAdaptationUpAllowed(
- const VideoStreamInputState& input_state,
- const VideoSourceRestrictions& restrictions_before,
- const VideoSourceRestrictions& restrictions_after,
- rtc::scoped_refptr<Resource> reason_resource) const {
- RTC_DCHECK_RUN_ON(resource_adaptation_queue_);
- rtc::CritScope crit(&lock_);
- return is_adaptation_up_allowed_;
-}
-
-void FakeResource::OnAdaptationApplied(
- const VideoStreamInputState& input_state,
- const VideoSourceRestrictions& restrictions_before,
- const VideoSourceRestrictions& restrictions_after,
- rtc::scoped_refptr<Resource> reason_resource) {
- RTC_DCHECK_RUN_ON(resource_adaptation_queue_);
- rtc::CritScope crit(&lock_);
- ++num_adaptations_applied_;
-}
-
} // namespace webrtc
diff --git a/call/adaptation/test/fake_resource.h b/call/adaptation/test/fake_resource.h
index 19f93ad612..c67dc3af3d 100644
--- a/call/adaptation/test/fake_resource.h
+++ b/call/adaptation/test/fake_resource.h
@@ -16,10 +16,7 @@
#include "absl/types/optional.h"
#include "api/scoped_refptr.h"
-#include "api/task_queue/task_queue_base.h"
#include "call/adaptation/resource.h"
-#include "rtc_base/critical_section.h"
-#include "rtc_base/synchronization/sequence_checker.h"
namespace webrtc {
@@ -31,38 +28,18 @@ class FakeResource : public Resource {
explicit FakeResource(std::string name);
~FakeResource() override;
- void set_usage_state(ResourceUsageState usage_state);
- void set_is_adaptation_up_allowed(bool is_adaptation_up_allowed);
- size_t num_adaptations_applied() const;
+ void SetUsageState(ResourceUsageState usage_state);
// Resource implementation.
- void RegisterAdaptationTaskQueue(
- TaskQueueBase* resource_adaptation_queue) override;
- void UnregisterAdaptationTaskQueue() override;
- void SetResourceListener(ResourceListener* listener) override;
std::string Name() const override;
+ void SetResourceListener(ResourceListener* listener) override;
absl::optional<ResourceUsageState> UsageState() const override;
void ClearUsageState() override;
- bool IsAdaptationUpAllowed(
- const VideoStreamInputState& input_state,
- const VideoSourceRestrictions& restrictions_before,
- const VideoSourceRestrictions& restrictions_after,
- rtc::scoped_refptr<Resource> reason_resource) const override;
- void OnAdaptationApplied(
- const VideoStreamInputState& input_state,
- const VideoSourceRestrictions& restrictions_before,
- const VideoSourceRestrictions& restrictions_after,
- rtc::scoped_refptr<Resource> reason_resource) override;
private:
- rtc::CriticalSection lock_;
const std::string name_;
- TaskQueueBase* resource_adaptation_queue_;
- bool is_adaptation_up_allowed_ RTC_GUARDED_BY(lock_);
- size_t num_adaptations_applied_ RTC_GUARDED_BY(lock_);
- absl::optional<ResourceUsageState> usage_state_
- RTC_GUARDED_BY(resource_adaptation_queue_);
- ResourceListener* listener_ RTC_GUARDED_BY(resource_adaptation_queue_);
+ ResourceListener* listener_;
+ absl::optional<ResourceUsageState> usage_state_;
};
} // namespace webrtc