Let ViEEncoder express resolution requests as Sinkwants.
This removes the VideoSendStream::LoadObserver interface and the implementation in WebrtcVideoSendStream and replace it with VideoSinkWants through the VideoSourceInterface.

To do that that, some stats for CPU adaptation is moved into VideoSendStream. Also handling of the CVO rtp header extension is moved to VideoSendStreamImpl.

BUG=webrtc:5687
TBR=mflodman@webrtc.org

Review-Url: https://codereview.webrtc.org/2304363002
Cr-Commit-Position: refs/heads/master@{#14877}
diff --git a/webrtc/video/send_statistics_proxy_unittest.cc b/webrtc/video/send_statistics_proxy_unittest.cc
index e661e0e..fcab7d1 100644
--- a/webrtc/video/send_statistics_proxy_unittest.cc
+++ b/webrtc/video/send_statistics_proxy_unittest.cc
@@ -26,7 +26,6 @@
 const uint32_t kFirstRtxSsrc = 18;
 const uint32_t kSecondRtxSsrc = 43;
 
-const int kMinRequiredSamples = 200;
 const int kQpIdx0 = 21;
 const int kQpIdx1 = 39;
 }  // namespace
@@ -337,7 +336,7 @@
   const int kWidth = 640;
   const int kHeight = 480;
 
-  for (int i = 0; i < kMinRequiredSamples; ++i)
+  for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i)
     statistics_proxy_->OnIncomingFrame(kWidth, kHeight);
 
   // No switch, stats should not be updated.
@@ -352,6 +351,25 @@
   EXPECT_EQ(1, metrics::NumSamples("WebRTC.Video.InputWidthInPixels"));
 }
 
+TEST_F(SendStatisticsProxyTest, CpuLimitedResolutionUpdated) {
+  const int kWidth = 640;
+  const int kHeight = 480;
+
+  for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i)
+    statistics_proxy_->OnIncomingFrame(kWidth, kHeight);
+
+  statistics_proxy_->OnCpuRestrictedResolutionChanged(true);
+
+  for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i)
+    statistics_proxy_->OnIncomingFrame(kWidth, kHeight);
+
+  statistics_proxy_.reset();
+  EXPECT_EQ(1,
+            metrics::NumSamples("WebRTC.Video.CpuLimitedResolutionInPercent"));
+  EXPECT_EQ(
+      1, metrics::NumEvents("WebRTC.Video.CpuLimitedResolutionInPercent", 50));
+}
+
 TEST_F(SendStatisticsProxyTest, LifetimeHistogramIsUpdated) {
   const int64_t kTimeSec = 3;
   fake_clock_.AdvanceTimeMilliseconds(kTimeSec * 1000);
@@ -372,7 +390,7 @@
   CodecSpecificInfo codec_info;
   codec_info.codecType = kVideoCodecVP8;
 
-  for (int i = 0; i < kMinRequiredSamples; ++i) {
+  for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) {
     codec_info.codecSpecific.VP8.simulcastIdx = 0;
     encoded_image.qp_ = kQpIdx0;
     statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
@@ -397,7 +415,7 @@
   CodecSpecificInfo codec_info;
   codec_info.codecType = kVideoCodecVP8;
 
-  for (int i = 0; i < kMinRequiredSamples; ++i) {
+  for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) {
     codec_info.codecSpecific.VP8.simulcastIdx = 0;
     encoded_image.qp_ = kQpIdx0;
     statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
@@ -413,7 +431,7 @@
   codec_info.codecType = kVideoCodecVP9;
   codec_info.codecSpecific.VP9.num_spatial_layers = 2;
 
-  for (int i = 0; i < kMinRequiredSamples; ++i) {
+  for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) {
     encoded_image.qp_ = kQpIdx0;
     codec_info.codecSpecific.VP9.spatial_idx = 0;
     statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
@@ -439,7 +457,7 @@
   codec_info.codecType = kVideoCodecVP9;
   codec_info.codecSpecific.VP9.num_spatial_layers = 1;
 
-  for (int i = 0; i < kMinRequiredSamples; ++i) {
+  for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i) {
     encoded_image.qp_ = kQpIdx0;
     codec_info.codecSpecific.VP9.spatial_idx = 0;
     statistics_proxy_->OnSendEncodedImage(encoded_image, &codec_info);
@@ -453,7 +471,7 @@
        BandwidthLimitedHistogramsNotUpdatedWhenDisabled) {
   EncodedImage encoded_image;
   // encoded_image.adapt_reason_.bw_resolutions_disabled by default: -1
-  for (int i = 0; i < kMinRequiredSamples; ++i)
+  for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i)
     statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr);
 
   // Histograms are updated when the statistics_proxy_ is deleted.
@@ -469,7 +487,7 @@
   const int kResolutionsDisabled = 0;
   EncodedImage encoded_image;
   encoded_image.adapt_reason_.bw_resolutions_disabled = kResolutionsDisabled;
-  for (int i = 0; i < kMinRequiredSamples; ++i)
+  for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i)
     statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr);
 
   // Histograms are updated when the statistics_proxy_ is deleted.
@@ -488,7 +506,7 @@
   const int kResolutionsDisabled = 1;
   EncodedImage encoded_image;
   encoded_image.adapt_reason_.bw_resolutions_disabled = kResolutionsDisabled;
-  for (int i = 0; i < kMinRequiredSamples; ++i)
+  for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i)
     statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr);
 
   // Histograms are updated when the statistics_proxy_ is deleted.
@@ -510,7 +528,7 @@
   EncodedImage encoded_image;
   // encoded_image.adapt_reason_.quality_resolution_downscales disabled by
   // default: -1
-  for (int i = 0; i < kMinRequiredSamples; ++i)
+  for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i)
     statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr);
 
   // Histograms are updated when the statistics_proxy_ is deleted.
@@ -526,7 +544,7 @@
   const int kDownscales = 0;
   EncodedImage encoded_image;
   encoded_image.adapt_reason_.quality_resolution_downscales = kDownscales;
-  for (int i = 0; i < kMinRequiredSamples; ++i)
+  for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i)
     statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr);
 
   // Histograms are updated when the statistics_proxy_ is deleted.
@@ -545,7 +563,7 @@
   const int kDownscales = 2;
   EncodedImage encoded_image;
   encoded_image.adapt_reason_.quality_resolution_downscales = kDownscales;
-  for (int i = 0; i < kMinRequiredSamples; ++i)
+  for (int i = 0; i < SendStatisticsProxy::kMinRequiredMetricsSamples; ++i)
     statistics_proxy_->OnSendEncodedImage(encoded_image, nullptr);
 
   // Histograms are updated when the statistics_proxy_ is deleted.