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}
This commit is contained in:
Artem Titov 2023-06-21 15:09:33 +02:00 committed by WebRTC LUCI CQ
parent 84fdf990e8
commit 5246ae20a2
7 changed files with 41 additions and 6 deletions

View file

@ -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",

View file

@ -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);

View file

@ -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_); }

View file

@ -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();

View file

@ -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(

View file

@ -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_;
};

View file

@ -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_); }