Add logging for video restrictions

This will help show what the restrictions are before
and after they transform into sink wants.

These will not be so spammy as adaptations do not happen
very often.

Bug: None
Change-Id: Ib72b313f68c6934d7833d8a3f14ce00df602832b
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/175800
Reviewed-by: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Commit-Queue: Evan Shrubsole <eshr@google.com>
Cr-Commit-Position: refs/heads/master@{#31341}
diff --git a/call/adaptation/video_source_restrictions.h b/call/adaptation/video_source_restrictions.h
index 506bae6..9ee670d 100644
--- a/call/adaptation/video_source_restrictions.h
+++ b/call/adaptation/video_source_restrictions.h
@@ -11,9 +11,11 @@
 #ifndef CALL_ADAPTATION_VIDEO_SOURCE_RESTRICTIONS_H_
 #define CALL_ADAPTATION_VIDEO_SOURCE_RESTRICTIONS_H_
 
+#include <string>
 #include <utility>
 
 #include "absl/types/optional.h"
+#include "rtc_base/strings/string_builder.h"
 
 namespace webrtc {
 
@@ -38,6 +40,19 @@
     return !(*this == rhs);
   }
 
+  std::string ToString() const {
+    rtc::StringBuilder ss;
+    ss << "{";
+    if (max_frame_rate_)
+      ss << " max_fps=" << max_frame_rate_.value();
+    if (max_pixels_per_frame_)
+      ss << " max_pixels_per_frame=" << max_pixels_per_frame_.value();
+    if (target_pixels_per_frame_)
+      ss << " target_pixels_per_frame=" << target_pixels_per_frame_.value();
+    ss << " }";
+    return ss.Release();
+  }
+
   // The source must produce a resolution less than or equal to
   // max_pixels_per_frame().
   const absl::optional<size_t>& max_pixels_per_frame() const;
diff --git a/video/video_source_sink_controller.cc b/video/video_source_sink_controller.cc
index a649adc..ea1059c 100644
--- a/video/video_source_sink_controller.cc
+++ b/video/video_source_sink_controller.cc
@@ -14,10 +14,27 @@
 #include <limits>
 #include <utility>
 
+#include "rtc_base/logging.h"
 #include "rtc_base/numerics/safe_conversions.h"
 
 namespace webrtc {
 
+namespace {
+
+std::string WantsToString(const rtc::VideoSinkWants& wants) {
+  rtc::StringBuilder ss;
+
+  ss << "max_fps=" << wants.max_framerate_fps
+     << " max_pixel_count=" << wants.max_pixel_count << " target_pixel_count="
+     << (wants.target_pixel_count.has_value()
+             ? std::to_string(wants.target_pixel_count.value())
+             : "null");
+
+  return ss.Release();
+}
+
+}  // namespace
+
 VideoSourceSinkController::VideoSourceSinkController(
     rtc::VideoSinkInterface<VideoFrame>* sink,
     rtc::VideoSourceInterface<VideoFrame>* source)
@@ -46,7 +63,9 @@
   rtc::CritScope lock(&crit_);
   if (!source_)
     return;
-  source_->AddOrUpdateSink(sink_, CurrentSettingsToSinkWants());
+  rtc::VideoSinkWants wants = CurrentSettingsToSinkWants();
+  RTC_LOG(INFO) << "Pushing SourceSink restrictions: " << WantsToString(wants);
+  source_->AddOrUpdateSink(sink_, wants);
 }
 
 VideoSourceRestrictions VideoSourceSinkController::restrictions() const {
diff --git a/video/video_source_sink_controller.h b/video/video_source_sink_controller.h
index 68fef3f..665493a 100644
--- a/video/video_source_sink_controller.h
+++ b/video/video_source_sink_controller.h
@@ -11,6 +11,8 @@
 #ifndef VIDEO_VIDEO_SOURCE_SINK_CONTROLLER_H_
 #define VIDEO_VIDEO_SOURCE_SINK_CONTROLLER_H_
 
+#include <string>
+
 #include "absl/types/optional.h"
 #include "api/video/video_frame.h"
 #include "api/video/video_sink_interface.h"
diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc
index 1dd8d82..6d148cd 100644
--- a/video/video_stream_encoder.cc
+++ b/video/video_stream_encoder.cc
@@ -1698,6 +1698,9 @@
     const VideoAdaptationCounters& adaptation_counters,
     rtc::scoped_refptr<Resource> reason) {
   RTC_DCHECK_RUN_ON(&resource_adaptation_queue_);
+  std::string resource_name = reason ? reason->name() : "<null>";
+  RTC_LOG(INFO) << "Updating sink restrictions from " << resource_name << " to "
+                << restrictions.ToString();
   video_source_sink_controller_.SetRestrictions(std::move(restrictions));
   video_source_sink_controller_.PushSourceSinkSettings();
 }