[Adaptation] Move IsAdaptationUpAllowed/OnAdaptationApplied out of API.

IsAdaptationUpAllowed is moved from Resource to AdaptationConstraint.
OnAdaptationApplied is moved from Resource to AdaptationListener.

In a future CL, Resource will be moved to api/, but
AdaptationConstraint and AdaptationListener will stay in call/.

The processor, encode stream and manager are updated to keep track of
both resources, constraints and listeners. Fakes and tests are updated.
After this CL, the manager's inner classes that prevent adaptation
implement AdaptationConstraint instead of Resource.

Bug: webrtc:11525
Change-Id: Ie9cd5b1ba7d8e161951e131ab8f6bd9d5cf765bf
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/176368
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Evan Shrubsole <eshr@google.com>
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31409}
diff --git a/video/video_stream_encoder_unittest.cc b/video/video_stream_encoder_unittest.cc
index 005118d..6ce6265 100644
--- a/video/video_stream_encoder_unittest.cc
+++ b/video/video_stream_encoder_unittest.cc
@@ -26,6 +26,8 @@
 #include "api/video_codecs/video_encoder.h"
 #include "api/video_codecs/vp8_temporal_layers.h"
 #include "api/video_codecs/vp8_temporal_layers_factory.h"
+#include "call/adaptation/test/fake_adaptation_constraint.h"
+#include "call/adaptation/test/fake_adaptation_listener.h"
 #include "call/adaptation/test/fake_resource.h"
 #include "common_video/h264/h264_common.h"
 #include "common_video/include/video_frame_buffer.h"
@@ -186,12 +188,12 @@
   absl::optional<bool> clear_qp_samples_result_;
 };
 
-class VideoSourceRestrictionsUpdatedListener
-    : public ResourceAdaptationProcessorListener {
+class FakeVideoSourceRestrictionsListener
+    : public VideoSourceRestrictionsListener {
  public:
-  VideoSourceRestrictionsUpdatedListener()
+  FakeVideoSourceRestrictionsListener()
       : was_restrictions_updated_(false), restrictions_updated_event_() {}
-  ~VideoSourceRestrictionsUpdatedListener() override {
+  ~FakeVideoSourceRestrictionsListener() override {
     RTC_DCHECK(was_restrictions_updated_);
   }
 
@@ -199,7 +201,7 @@
     return &restrictions_updated_event_;
   }
 
-  // ResourceAdaptationProcessorListener implementation.
+  // VideoSourceRestrictionsListener implementation.
   void OnVideoSourceRestrictionsUpdated(
       VideoSourceRestrictions restrictions,
       const VideoAdaptationCounters& adaptation_counters,
@@ -317,24 +319,24 @@
                                    new CpuOveruseDetectorProxy(stats_proxy)),
                            task_queue_factory),
         fake_cpu_resource_(FakeResource::Create("FakeResource[CPU]")),
-        fake_quality_resource_(FakeResource::Create("FakeResource[QP]")) {
-    fake_cpu_resource_->RegisterAdaptationTaskQueue(
-        resource_adaptation_queue()->Get());
-    fake_quality_resource_->RegisterAdaptationTaskQueue(
-        resource_adaptation_queue()->Get());
+        fake_quality_resource_(FakeResource::Create("FakeResource[QP]")),
+        fake_adaptation_constraint_("FakeAdaptationConstraint"),
+        fake_adaptation_listener_() {
     InjectAdaptationResource(fake_quality_resource_,
                              VideoAdaptationReason::kQuality);
     InjectAdaptationResource(fake_cpu_resource_, VideoAdaptationReason::kCpu);
+    InjectAdaptationConstraint(&fake_adaptation_constraint_);
+    InjectAdaptationListener(&fake_adaptation_listener_);
   }
 
   void SetSourceAndWaitForRestrictionsUpdated(
       rtc::VideoSourceInterface<VideoFrame>* source,
       const DegradationPreference& degradation_preference) {
-    VideoSourceRestrictionsUpdatedListener listener;
-    AddAdaptationListenerForTesting(&listener);
+    FakeVideoSourceRestrictionsListener listener;
+    AddRestrictionsListenerForTesting(&listener);
     SetSource(source, degradation_preference);
     listener.restrictions_updated_event()->Wait(5000);
-    RemoveAdaptationListenerForTesting(&listener);
+    RemoveRestrictionsListenerForTesting(&listener);
   }
 
   void SetSourceAndWaitForFramerateUpdated(
@@ -379,7 +381,7 @@
   void TriggerCpuOveruse() {
     rtc::Event event;
     resource_adaptation_queue()->PostTask([this, &event] {
-      fake_cpu_resource_->set_usage_state(ResourceUsageState::kOveruse);
+      fake_cpu_resource_->SetUsageState(ResourceUsageState::kOveruse);
       event.Set();
     });
     ASSERT_TRUE(event.Wait(5000));
@@ -387,7 +389,7 @@
   void TriggerCpuUnderuse() {
     rtc::Event event;
     resource_adaptation_queue()->PostTask([this, &event] {
-      fake_cpu_resource_->set_usage_state(ResourceUsageState::kUnderuse);
+      fake_cpu_resource_->SetUsageState(ResourceUsageState::kUnderuse);
       event.Set();
     });
     ASSERT_TRUE(event.Wait(5000));
@@ -397,7 +399,7 @@
   void TriggerQualityLow() {
     rtc::Event event;
     resource_adaptation_queue()->PostTask([this, &event] {
-      fake_quality_resource_->set_usage_state(ResourceUsageState::kOveruse);
+      fake_quality_resource_->SetUsageState(ResourceUsageState::kOveruse);
       event.Set();
     });
     ASSERT_TRUE(event.Wait(5000));
@@ -405,7 +407,7 @@
   void TriggerQualityHigh() {
     rtc::Event event;
     resource_adaptation_queue()->PostTask([this, &event] {
-      fake_quality_resource_->set_usage_state(ResourceUsageState::kUnderuse);
+      fake_quality_resource_->SetUsageState(ResourceUsageState::kUnderuse);
       event.Set();
     });
     ASSERT_TRUE(event.Wait(5000));
@@ -430,6 +432,8 @@
   CpuOveruseDetectorProxy* overuse_detector_proxy_;
   rtc::scoped_refptr<FakeResource> fake_cpu_resource_;
   rtc::scoped_refptr<FakeResource> fake_quality_resource_;
+  FakeAdaptationConstraint fake_adaptation_constraint_;
+  FakeAdaptationListener fake_adaptation_listener_;
 };
 
 class VideoStreamFactory