Fix TestVideoCapturer and subclasses to support pause/resume video

Bug: b/272350185
Change-Id: I8e2e1a833430f78627ec6301ea23f2f8337a01ca
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/309622
Reviewed-by: Jeremy Leconte <jleconte@google.com>
Commit-Queue: Artem Titov <titovartem@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#40329}
diff --git a/test/BUILD.gn b/test/BUILD.gn
index cce1b61..3a0a359 100644
--- a/test/BUILD.gn
+++ b/test/BUILD.gn
@@ -255,6 +255,7 @@
         "../api:media_stream_interface",
         "../api:scoped_refptr",
         "../modules/video_capture:video_capture_module",
+        "../rtc_base:logging",
         "../rtc_base:threading",
         "../sdk:base_objc",
         "../sdk:native_api",
diff --git a/test/frame_generator_capturer.h b/test/frame_generator_capturer.h
index b1fd7eb..6824ba6 100644
--- a/test/frame_generator_capturer.h
+++ b/test/frame_generator_capturer.h
@@ -52,8 +52,8 @@
       TaskQueueFactory& task_queue_factory);
   virtual ~FrameGeneratorCapturer();
 
-  void Start();
-  void Stop();
+  void Start() override;
+  void Stop() override;
   void ChangeResolution(size_t width, size_t height);
   void ChangeFramerate(int target_framerate);
 
diff --git a/test/mac_capturer.h b/test/mac_capturer.h
index 35cd1cc..58ccfc0 100644
--- a/test/mac_capturer.h
+++ b/test/mac_capturer.h
@@ -17,6 +17,7 @@
 #include "api/media_stream_interface.h"
 #include "api/scoped_refptr.h"
 #include "modules/video_capture/video_capture.h"
+#include "rtc_base/logging.h"
 #include "rtc_base/thread.h"
 #include "test/test_video_capturer.h"
 
@@ -32,6 +33,15 @@
                              size_t capture_device_index);
   ~MacCapturer() override;
 
+  void Start() override {
+    RTC_LOG(LS_WARNING) << "Capturer doesn't support resume/pause and always "
+                           "produces the video";
+  }
+  void Stop() override {
+    RTC_LOG(LS_WARNING) << "Capturer doesn't support resume/pause and always "
+                           "produces the video";
+  }
+
   void OnFrame(const VideoFrame& frame) override;
 
   int GetFrameWidth() const override { return static_cast<int>(width_); }
diff --git a/test/pc/e2e/media/test_video_capturer_video_track_source.h b/test/pc/e2e/media/test_video_capturer_video_track_source.h
index 70db07b..846721d 100644
--- a/test/pc/e2e/media/test_video_capturer_video_track_source.h
+++ b/test/pc/e2e/media/test_video_capturer_video_track_source.h
@@ -45,9 +45,15 @@
 
   ~TestVideoCapturerVideoTrackSource() = default;
 
-  void Start() override { SetState(kLive); }
+  void Start() override {
+    SetState(kLive);
+    video_capturer_->Start();
+  }
 
-  void Stop() override { SetState(kMuted); }
+  void Stop() override {
+    SetState(kMuted);
+    video_capturer_->Stop();
+  }
 
   int GetFrameWidth() const override {
     return video_capturer_->GetFrameWidth();
diff --git a/test/test_video_capturer.cc b/test/test_video_capturer.cc
index 3098731..385af12 100644
--- a/test/test_video_capturer.cc
+++ b/test/test_video_capturer.cc
@@ -46,8 +46,9 @@
     MutexLock lock(&lock_);
     enable_adaptation = enable_adaptation_;
   }
-  if (enable_adaptation) {
+  if (!enable_adaptation) {
     broadcaster_.OnFrame(frame);
+    return;
   }
 
   if (!video_adapter_.AdaptFrameResolution(
diff --git a/test/test_video_capturer.h b/test/test_video_capturer.h
index 48b7f7a..49660d8 100644
--- a/test/test_video_capturer.h
+++ b/test/test_video_capturer.h
@@ -49,6 +49,13 @@
                              int height,
                              const absl::optional<int>& max_fps);
 
+  // Starts or resumes video capturing. Can be called multiple times during
+  // lifetime of this object.
+  virtual void Start() = 0;
+  // Stops or pauses video capturing. Can be called multiple times during
+  // lifetime of this object.
+  virtual void Stop() = 0;
+
   virtual int GetFrameWidth() const = 0;
   virtual int GetFrameHeight() const = 0;
 
@@ -62,7 +69,7 @@
 
   Mutex lock_;
   std::unique_ptr<FramePreprocessor> preprocessor_ RTC_GUARDED_BY(lock_);
-  bool enable_adaptation_ RTC_GUARDED_BY(lock_) = false;
+  bool enable_adaptation_ RTC_GUARDED_BY(lock_) = true;
   rtc::VideoBroadcaster broadcaster_;
   cricket::VideoAdapter video_adapter_;
 };
diff --git a/test/vcm_capturer.h b/test/vcm_capturer.h
index da2b948..1deea21 100644
--- a/test/vcm_capturer.h
+++ b/test/vcm_capturer.h
@@ -15,6 +15,7 @@
 
 #include "api/scoped_refptr.h"
 #include "modules/video_capture/video_capture.h"
+#include "rtc_base/logging.h"
 #include "test/test_video_capturer.h"
 
 namespace webrtc {
@@ -29,6 +30,15 @@
                              size_t capture_device_index);
   virtual ~VcmCapturer();
 
+  void Start() override {
+    RTC_LOG(LS_WARNING) << "Capturer doesn't support resume/pause and always "
+                           "produces the video";
+  }
+  void Stop() override {
+    RTC_LOG(LS_WARNING) << "Capturer doesn't support resume/pause and always "
+                           "produces the video";
+  }
+
   void OnFrame(const VideoFrame& frame) override;
 
   int GetFrameWidth() const override { return static_cast<int>(width_); }