Extend TestVideoTrackSource API
Bug: b/272350185 Change-Id: Ibc53e7a9ee8f572475d86fc78de1c1ed71078910 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/299140 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/main@{#39678}
This commit is contained in:
parent
86ad48cb37
commit
6fd5f33d45
@ -62,6 +62,16 @@ class TestVideoTrackSource : public Notifier<VideoTrackSourceInterface> {
|
||||
|
||||
virtual void SetScreencast(bool is_screencast) = 0;
|
||||
|
||||
// TODO(titovartem): make next 4 methods pure virtual.
|
||||
virtual void SetEnableAdaptation(bool enable_adaptation) {}
|
||||
|
||||
virtual int GetFrameWidth() const { return 0; }
|
||||
virtual int GetFrameHeight() const { return 0; }
|
||||
|
||||
virtual void OnOutputFormatRequest(int width,
|
||||
int height,
|
||||
const absl::optional<int>& max_fps) {}
|
||||
|
||||
protected:
|
||||
virtual rtc::VideoSourceInterface<VideoFrame>* source() = 0;
|
||||
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
namespace {
|
||||
|
||||
std::string TransformFilePath(std::string path) {
|
||||
static const std::string resource_prefix = "res://";
|
||||
int ext_pos = path.rfind('.');
|
||||
@ -41,6 +42,7 @@ std::string TransformFilePath(std::string path) {
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
FrameGeneratorCapturer::FrameGeneratorCapturer(
|
||||
@ -177,49 +179,39 @@ bool FrameGeneratorCapturer::Init() {
|
||||
}
|
||||
|
||||
void FrameGeneratorCapturer::InsertFrame() {
|
||||
absl::optional<Resolution> resolution;
|
||||
MutexLock lock(&lock_);
|
||||
if (sending_) {
|
||||
FrameGeneratorInterface::VideoFrameData frame_data =
|
||||
frame_generator_->NextFrame();
|
||||
// TODO(srte): Use more advanced frame rate control to allow arbritrary
|
||||
// fractions.
|
||||
int decimation =
|
||||
std::round(static_cast<double>(source_fps_) / target_capture_fps_);
|
||||
for (int i = 1; i < decimation; ++i)
|
||||
frame_data = frame_generator_->NextFrame();
|
||||
|
||||
{
|
||||
MutexLock lock(&lock_);
|
||||
if (sending_) {
|
||||
FrameGeneratorInterface::VideoFrameData frame_data =
|
||||
frame_generator_->NextFrame();
|
||||
// TODO(srte): Use more advanced frame rate control to allow arbritrary
|
||||
// fractions.
|
||||
int decimation =
|
||||
std::round(static_cast<double>(source_fps_) / target_capture_fps_);
|
||||
for (int i = 1; i < decimation; ++i)
|
||||
frame_data = frame_generator_->NextFrame();
|
||||
|
||||
VideoFrame frame =
|
||||
VideoFrame::Builder()
|
||||
.set_video_frame_buffer(frame_data.buffer)
|
||||
.set_rotation(fake_rotation_)
|
||||
.set_timestamp_us(clock_->TimeInMicroseconds())
|
||||
.set_ntp_time_ms(clock_->CurrentNtpInMilliseconds())
|
||||
.set_update_rect(frame_data.update_rect)
|
||||
.set_color_space(fake_color_space_)
|
||||
.build();
|
||||
if (first_frame_capture_time_ == -1) {
|
||||
first_frame_capture_time_ = frame.ntp_time_ms();
|
||||
}
|
||||
|
||||
resolution = Resolution{frame.width(), frame.height()};
|
||||
|
||||
TestVideoCapturer::OnFrame(frame);
|
||||
VideoFrame frame = VideoFrame::Builder()
|
||||
.set_video_frame_buffer(frame_data.buffer)
|
||||
.set_rotation(fake_rotation_)
|
||||
.set_timestamp_us(clock_->TimeInMicroseconds())
|
||||
.set_ntp_time_ms(clock_->CurrentNtpInMilliseconds())
|
||||
.set_update_rect(frame_data.update_rect)
|
||||
.set_color_space(fake_color_space_)
|
||||
.build();
|
||||
if (first_frame_capture_time_ == -1) {
|
||||
first_frame_capture_time_ = frame.ntp_time_ms();
|
||||
}
|
||||
}
|
||||
|
||||
if (resolution) {
|
||||
MutexLock lock(&stats_lock_);
|
||||
source_resolution_ = resolution;
|
||||
TestVideoCapturer::OnFrame(frame);
|
||||
}
|
||||
}
|
||||
|
||||
absl::optional<FrameGeneratorCapturer::Resolution>
|
||||
FrameGeneratorCapturer::GetResolution() {
|
||||
MutexLock lock(&stats_lock_);
|
||||
return source_resolution_;
|
||||
FrameGeneratorCapturer::GetResolution() const {
|
||||
FrameGeneratorInterface::Resolution resolution =
|
||||
frame_generator_->GetResolution();
|
||||
return Resolution{.width = static_cast<int>(resolution.width),
|
||||
.height = static_cast<int>(resolution.height)};
|
||||
}
|
||||
|
||||
void FrameGeneratorCapturer::Start() {
|
||||
@ -266,6 +258,14 @@ void FrameGeneratorCapturer::ChangeFramerate(int target_framerate) {
|
||||
target_capture_fps_ = std::min(source_fps_, target_framerate);
|
||||
}
|
||||
|
||||
int FrameGeneratorCapturer::GetFrameWidth() const {
|
||||
return static_cast<int>(frame_generator_->GetResolution().width);
|
||||
}
|
||||
|
||||
int FrameGeneratorCapturer::GetFrameHeight() const {
|
||||
return static_cast<int>(frame_generator_->GetResolution().height);
|
||||
}
|
||||
|
||||
void FrameGeneratorCapturer::OnOutputFormatRequest(
|
||||
int width,
|
||||
int height,
|
||||
|
||||
@ -132,11 +132,14 @@ class FrameGeneratorCapturer : public TestVideoCapturer {
|
||||
void ChangeResolution(size_t width, size_t height);
|
||||
void ChangeFramerate(int target_framerate);
|
||||
|
||||
int GetFrameWidth() const override;
|
||||
int GetFrameHeight() const override;
|
||||
|
||||
struct Resolution {
|
||||
int width;
|
||||
int height;
|
||||
};
|
||||
absl::optional<Resolution> GetResolution();
|
||||
absl::optional<Resolution> GetResolution() const;
|
||||
|
||||
void OnOutputFormatRequest(int width,
|
||||
int height,
|
||||
@ -178,9 +181,6 @@ class FrameGeneratorCapturer : public TestVideoCapturer {
|
||||
|
||||
int64_t first_frame_capture_time_;
|
||||
|
||||
Mutex stats_lock_;
|
||||
absl::optional<Resolution> source_resolution_ RTC_GUARDED_BY(&stats_lock_);
|
||||
|
||||
// Must be the last field, so it will be deconstructed first as tasks
|
||||
// in the TaskQueue access other fields of the instance of this class.
|
||||
rtc::TaskQueue task_queue_;
|
||||
|
||||
@ -71,7 +71,9 @@ TEST(FrameGeneratorCapturerTest, ChangeResolution) {
|
||||
config.squares_video->framerate = 20;
|
||||
auto capturer = FrameGeneratorCapturer::Create(
|
||||
time.GetClock(), *time.GetTaskQueueFactory(), config);
|
||||
EXPECT_FALSE(capturer->GetResolution());
|
||||
EXPECT_TRUE(capturer->GetResolution());
|
||||
EXPECT_EQ(kWidth, capturer->GetResolution()->width);
|
||||
EXPECT_EQ(kHeight, capturer->GetResolution()->height);
|
||||
capturer->Start();
|
||||
time.AdvanceTime(TimeDelta::Seconds(1));
|
||||
ASSERT_TRUE(capturer->GetResolution());
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#ifndef TEST_MAC_CAPTURER_H_
|
||||
#define TEST_MAC_CAPTURER_H_
|
||||
|
||||
#include <cstddef>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
@ -33,6 +34,9 @@ class MacCapturer : public TestVideoCapturer,
|
||||
|
||||
void OnFrame(const VideoFrame& frame) override;
|
||||
|
||||
int GetFrameWidth() const override { return static_cast<int>(width_); }
|
||||
int GetFrameHeight() const override { return static_cast<int>(height_); }
|
||||
|
||||
private:
|
||||
MacCapturer(size_t width,
|
||||
size_t height,
|
||||
@ -40,6 +44,8 @@ class MacCapturer : public TestVideoCapturer,
|
||||
size_t capture_device_index);
|
||||
void Destroy();
|
||||
|
||||
size_t width_;
|
||||
size_t height_;
|
||||
void* capturer_;
|
||||
void* adapter_;
|
||||
};
|
||||
|
||||
@ -64,6 +64,8 @@ MacCapturer::MacCapturer(size_t width,
|
||||
size_t height,
|
||||
size_t target_fps,
|
||||
size_t capture_device_index) {
|
||||
width_ = width;
|
||||
height_ = height;
|
||||
RTCTestVideoSourceAdapter *adapter = [[RTCTestVideoSourceAdapter alloc] init];
|
||||
adapter_ = (__bridge_retained void *)adapter;
|
||||
adapter.capturer = this;
|
||||
|
||||
@ -49,13 +49,27 @@ class TestVideoCapturerVideoTrackSource : public test::TestVideoTrackSource {
|
||||
|
||||
void Stop() override { SetState(kMuted); }
|
||||
|
||||
int GetFrameWidth() const override {
|
||||
return video_capturer_->GetFrameWidth();
|
||||
}
|
||||
|
||||
int GetFrameHeight() const override {
|
||||
return video_capturer_->GetFrameHeight();
|
||||
}
|
||||
|
||||
bool is_screencast() const override {
|
||||
RTC_DCHECK_RUN_ON(&sequence_checker_);
|
||||
return is_screencast_;
|
||||
}
|
||||
|
||||
void SetDisableAdaptation(bool disable_adaptation) {
|
||||
video_capturer_->SetDisableAdaptation(disable_adaptation);
|
||||
void SetEnableAdaptation(bool enable_adaptation) {
|
||||
video_capturer_->SetEnableAdaptation(enable_adaptation);
|
||||
}
|
||||
|
||||
void OnOutputFormatRequest(int width,
|
||||
int height,
|
||||
const absl::optional<int>& max_fps) override {
|
||||
video_capturer_->OnOutputFormatRequest(width, height, max_fps);
|
||||
}
|
||||
|
||||
void SetScreencast(bool is_screencast) override {
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
|
||||
namespace webrtc {
|
||||
namespace test {
|
||||
|
||||
TestVideoCapturer::~TestVideoCapturer() = default;
|
||||
|
||||
void TestVideoCapturer::OnOutputFormatRequest(
|
||||
@ -40,12 +41,12 @@ void TestVideoCapturer::OnFrame(const VideoFrame& original_frame) {
|
||||
|
||||
VideoFrame frame = MaybePreprocess(original_frame);
|
||||
|
||||
bool disable_adaptation;
|
||||
bool enable_adaptation;
|
||||
{
|
||||
MutexLock lock(&lock_);
|
||||
disable_adaptation = disable_adaptation_;
|
||||
enable_adaptation = enable_adaptation_;
|
||||
}
|
||||
if (disable_adaptation) {
|
||||
if (enable_adaptation) {
|
||||
broadcaster_.OnFrame(frame);
|
||||
}
|
||||
|
||||
|
||||
@ -41,14 +41,17 @@ class TestVideoCapturer : public rtc::VideoSourceInterface<VideoFrame> {
|
||||
MutexLock lock(&lock_);
|
||||
preprocessor_ = std::move(preprocessor);
|
||||
}
|
||||
void SetDisableAdaptation(bool disable_adaptation) {
|
||||
void SetEnableAdaptation(bool enable_adaptation) {
|
||||
MutexLock lock(&lock_);
|
||||
disable_adaptation_ = disable_adaptation;
|
||||
enable_adaptation_ = enable_adaptation;
|
||||
}
|
||||
void OnOutputFormatRequest(int width,
|
||||
int height,
|
||||
const absl::optional<int>& max_fps);
|
||||
|
||||
virtual int GetFrameWidth() const = 0;
|
||||
virtual int GetFrameHeight() const = 0;
|
||||
|
||||
protected:
|
||||
void OnFrame(const VideoFrame& frame);
|
||||
rtc::VideoSinkWants GetSinkWants();
|
||||
@ -59,7 +62,7 @@ class TestVideoCapturer : public rtc::VideoSourceInterface<VideoFrame> {
|
||||
|
||||
Mutex lock_;
|
||||
std::unique_ptr<FramePreprocessor> preprocessor_ RTC_GUARDED_BY(lock_);
|
||||
bool disable_adaptation_ RTC_GUARDED_BY(lock_) = false;
|
||||
bool enable_adaptation_ RTC_GUARDED_BY(lock_) = false;
|
||||
rtc::VideoBroadcaster broadcaster_;
|
||||
cricket::VideoAdapter video_adapter_;
|
||||
};
|
||||
|
||||
@ -27,6 +27,8 @@ bool VcmCapturer::Init(size_t width,
|
||||
size_t height,
|
||||
size_t target_fps,
|
||||
size_t capture_device_index) {
|
||||
width_ = width;
|
||||
height_ = height;
|
||||
std::unique_ptr<VideoCaptureModule::DeviceInfo> device_info(
|
||||
VideoCaptureFactory::CreateDeviceInfo());
|
||||
|
||||
|
||||
@ -31,6 +31,9 @@ class VcmCapturer : public TestVideoCapturer,
|
||||
|
||||
void OnFrame(const VideoFrame& frame) override;
|
||||
|
||||
int GetFrameWidth() const override { return static_cast<int>(width_); }
|
||||
int GetFrameHeight() const override { return static_cast<int>(height_); }
|
||||
|
||||
private:
|
||||
VcmCapturer();
|
||||
bool Init(size_t width,
|
||||
@ -39,6 +42,8 @@ class VcmCapturer : public TestVideoCapturer,
|
||||
size_t capture_device_index);
|
||||
void Destroy();
|
||||
|
||||
size_t width_;
|
||||
size_t height_;
|
||||
rtc::scoped_refptr<VideoCaptureModule> vcm_;
|
||||
VideoCaptureCapability capability_;
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user