From 5246ae20a2c2d47c4ebe1013ea36f469cb89e295 Mon Sep 17 00:00:00 2001 From: Artem Titov <titovartem@webrtc.org> Date: Wed, 21 Jun 2023 15:09:33 +0200 Subject: [PATCH] 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} --- test/BUILD.gn | 1 + test/frame_generator_capturer.h | 4 ++-- test/mac_capturer.h | 10 ++++++++++ .../e2e/media/test_video_capturer_video_track_source.h | 10 ++++++++-- test/test_video_capturer.cc | 3 ++- test/test_video_capturer.h | 9 ++++++++- test/vcm_capturer.h | 10 ++++++++++ 7 files changed, 41 insertions(+), 6 deletions(-) diff --git a/test/BUILD.gn b/test/BUILD.gn index cce1b61bd6..3a0a35926f 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -255,6 +255,7 @@ if (!build_with_chromium) { "../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 b1fd7ebfc7..6824ba681e 100644 --- a/test/frame_generator_capturer.h +++ b/test/frame_generator_capturer.h @@ -52,8 +52,8 @@ class FrameGeneratorCapturer : public TestVideoCapturer { 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 35cd1ccd1e..58ccfc0675 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 @@ class MacCapturer : public TestVideoCapturer, 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 70db07b31c..846721d864 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 @@ class TestVideoCapturerVideoTrackSource : public test::TestVideoTrackSource { ~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 3098731eb3..385af12b80 100644 --- a/test/test_video_capturer.cc +++ b/test/test_video_capturer.cc @@ -46,8 +46,9 @@ void TestVideoCapturer::OnFrame(const VideoFrame& original_frame) { 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 48b7f7a7f8..49660d8972 100644 --- a/test/test_video_capturer.h +++ b/test/test_video_capturer.h @@ -49,6 +49,13 @@ class TestVideoCapturer : public rtc::VideoSourceInterface<VideoFrame> { 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 @@ class TestVideoCapturer : public rtc::VideoSourceInterface<VideoFrame> { 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 da2b948fe0..1deea21229 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 @@ class VcmCapturer : public TestVideoCapturer, 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_); }