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;
|
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:
|
protected:
|
||||||
virtual rtc::VideoSourceInterface<VideoFrame>* source() = 0;
|
virtual rtc::VideoSourceInterface<VideoFrame>* source() = 0;
|
||||||
|
|
||||||
|
|||||||
@ -29,6 +29,7 @@
|
|||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace test {
|
namespace test {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
std::string TransformFilePath(std::string path) {
|
std::string TransformFilePath(std::string path) {
|
||||||
static const std::string resource_prefix = "res://";
|
static const std::string resource_prefix = "res://";
|
||||||
int ext_pos = path.rfind('.');
|
int ext_pos = path.rfind('.');
|
||||||
@ -41,6 +42,7 @@ std::string TransformFilePath(std::string path) {
|
|||||||
}
|
}
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
FrameGeneratorCapturer::FrameGeneratorCapturer(
|
FrameGeneratorCapturer::FrameGeneratorCapturer(
|
||||||
@ -177,9 +179,6 @@ bool FrameGeneratorCapturer::Init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void FrameGeneratorCapturer::InsertFrame() {
|
void FrameGeneratorCapturer::InsertFrame() {
|
||||||
absl::optional<Resolution> resolution;
|
|
||||||
|
|
||||||
{
|
|
||||||
MutexLock lock(&lock_);
|
MutexLock lock(&lock_);
|
||||||
if (sending_) {
|
if (sending_) {
|
||||||
FrameGeneratorInterface::VideoFrameData frame_data =
|
FrameGeneratorInterface::VideoFrameData frame_data =
|
||||||
@ -191,8 +190,7 @@ void FrameGeneratorCapturer::InsertFrame() {
|
|||||||
for (int i = 1; i < decimation; ++i)
|
for (int i = 1; i < decimation; ++i)
|
||||||
frame_data = frame_generator_->NextFrame();
|
frame_data = frame_generator_->NextFrame();
|
||||||
|
|
||||||
VideoFrame frame =
|
VideoFrame frame = VideoFrame::Builder()
|
||||||
VideoFrame::Builder()
|
|
||||||
.set_video_frame_buffer(frame_data.buffer)
|
.set_video_frame_buffer(frame_data.buffer)
|
||||||
.set_rotation(fake_rotation_)
|
.set_rotation(fake_rotation_)
|
||||||
.set_timestamp_us(clock_->TimeInMicroseconds())
|
.set_timestamp_us(clock_->TimeInMicroseconds())
|
||||||
@ -204,22 +202,16 @@ void FrameGeneratorCapturer::InsertFrame() {
|
|||||||
first_frame_capture_time_ = frame.ntp_time_ms();
|
first_frame_capture_time_ = frame.ntp_time_ms();
|
||||||
}
|
}
|
||||||
|
|
||||||
resolution = Resolution{frame.width(), frame.height()};
|
|
||||||
|
|
||||||
TestVideoCapturer::OnFrame(frame);
|
TestVideoCapturer::OnFrame(frame);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (resolution) {
|
|
||||||
MutexLock lock(&stats_lock_);
|
|
||||||
source_resolution_ = resolution;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::optional<FrameGeneratorCapturer::Resolution>
|
absl::optional<FrameGeneratorCapturer::Resolution>
|
||||||
FrameGeneratorCapturer::GetResolution() {
|
FrameGeneratorCapturer::GetResolution() const {
|
||||||
MutexLock lock(&stats_lock_);
|
FrameGeneratorInterface::Resolution resolution =
|
||||||
return source_resolution_;
|
frame_generator_->GetResolution();
|
||||||
|
return Resolution{.width = static_cast<int>(resolution.width),
|
||||||
|
.height = static_cast<int>(resolution.height)};
|
||||||
}
|
}
|
||||||
|
|
||||||
void FrameGeneratorCapturer::Start() {
|
void FrameGeneratorCapturer::Start() {
|
||||||
@ -266,6 +258,14 @@ void FrameGeneratorCapturer::ChangeFramerate(int target_framerate) {
|
|||||||
target_capture_fps_ = std::min(source_fps_, 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(
|
void FrameGeneratorCapturer::OnOutputFormatRequest(
|
||||||
int width,
|
int width,
|
||||||
int height,
|
int height,
|
||||||
|
|||||||
@ -132,11 +132,14 @@ class FrameGeneratorCapturer : public TestVideoCapturer {
|
|||||||
void ChangeResolution(size_t width, size_t height);
|
void ChangeResolution(size_t width, size_t height);
|
||||||
void ChangeFramerate(int target_framerate);
|
void ChangeFramerate(int target_framerate);
|
||||||
|
|
||||||
|
int GetFrameWidth() const override;
|
||||||
|
int GetFrameHeight() const override;
|
||||||
|
|
||||||
struct Resolution {
|
struct Resolution {
|
||||||
int width;
|
int width;
|
||||||
int height;
|
int height;
|
||||||
};
|
};
|
||||||
absl::optional<Resolution> GetResolution();
|
absl::optional<Resolution> GetResolution() const;
|
||||||
|
|
||||||
void OnOutputFormatRequest(int width,
|
void OnOutputFormatRequest(int width,
|
||||||
int height,
|
int height,
|
||||||
@ -178,9 +181,6 @@ class FrameGeneratorCapturer : public TestVideoCapturer {
|
|||||||
|
|
||||||
int64_t first_frame_capture_time_;
|
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
|
// 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.
|
// in the TaskQueue access other fields of the instance of this class.
|
||||||
rtc::TaskQueue task_queue_;
|
rtc::TaskQueue task_queue_;
|
||||||
|
|||||||
@ -71,7 +71,9 @@ TEST(FrameGeneratorCapturerTest, ChangeResolution) {
|
|||||||
config.squares_video->framerate = 20;
|
config.squares_video->framerate = 20;
|
||||||
auto capturer = FrameGeneratorCapturer::Create(
|
auto capturer = FrameGeneratorCapturer::Create(
|
||||||
time.GetClock(), *time.GetTaskQueueFactory(), config);
|
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();
|
capturer->Start();
|
||||||
time.AdvanceTime(TimeDelta::Seconds(1));
|
time.AdvanceTime(TimeDelta::Seconds(1));
|
||||||
ASSERT_TRUE(capturer->GetResolution());
|
ASSERT_TRUE(capturer->GetResolution());
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
#ifndef TEST_MAC_CAPTURER_H_
|
#ifndef TEST_MAC_CAPTURER_H_
|
||||||
#define TEST_MAC_CAPTURER_H_
|
#define TEST_MAC_CAPTURER_H_
|
||||||
|
|
||||||
|
#include <cstddef>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
@ -33,6 +34,9 @@ class MacCapturer : public TestVideoCapturer,
|
|||||||
|
|
||||||
void OnFrame(const VideoFrame& frame) override;
|
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:
|
private:
|
||||||
MacCapturer(size_t width,
|
MacCapturer(size_t width,
|
||||||
size_t height,
|
size_t height,
|
||||||
@ -40,6 +44,8 @@ class MacCapturer : public TestVideoCapturer,
|
|||||||
size_t capture_device_index);
|
size_t capture_device_index);
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
|
size_t width_;
|
||||||
|
size_t height_;
|
||||||
void* capturer_;
|
void* capturer_;
|
||||||
void* adapter_;
|
void* adapter_;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -64,6 +64,8 @@ MacCapturer::MacCapturer(size_t width,
|
|||||||
size_t height,
|
size_t height,
|
||||||
size_t target_fps,
|
size_t target_fps,
|
||||||
size_t capture_device_index) {
|
size_t capture_device_index) {
|
||||||
|
width_ = width;
|
||||||
|
height_ = height;
|
||||||
RTCTestVideoSourceAdapter *adapter = [[RTCTestVideoSourceAdapter alloc] init];
|
RTCTestVideoSourceAdapter *adapter = [[RTCTestVideoSourceAdapter alloc] init];
|
||||||
adapter_ = (__bridge_retained void *)adapter;
|
adapter_ = (__bridge_retained void *)adapter;
|
||||||
adapter.capturer = this;
|
adapter.capturer = this;
|
||||||
|
|||||||
@ -49,13 +49,27 @@ class TestVideoCapturerVideoTrackSource : public test::TestVideoTrackSource {
|
|||||||
|
|
||||||
void Stop() override { SetState(kMuted); }
|
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 {
|
bool is_screencast() const override {
|
||||||
RTC_DCHECK_RUN_ON(&sequence_checker_);
|
RTC_DCHECK_RUN_ON(&sequence_checker_);
|
||||||
return is_screencast_;
|
return is_screencast_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetDisableAdaptation(bool disable_adaptation) {
|
void SetEnableAdaptation(bool enable_adaptation) {
|
||||||
video_capturer_->SetDisableAdaptation(disable_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 {
|
void SetScreencast(bool is_screencast) override {
|
||||||
|
|||||||
@ -19,6 +19,7 @@
|
|||||||
|
|
||||||
namespace webrtc {
|
namespace webrtc {
|
||||||
namespace test {
|
namespace test {
|
||||||
|
|
||||||
TestVideoCapturer::~TestVideoCapturer() = default;
|
TestVideoCapturer::~TestVideoCapturer() = default;
|
||||||
|
|
||||||
void TestVideoCapturer::OnOutputFormatRequest(
|
void TestVideoCapturer::OnOutputFormatRequest(
|
||||||
@ -40,12 +41,12 @@ void TestVideoCapturer::OnFrame(const VideoFrame& original_frame) {
|
|||||||
|
|
||||||
VideoFrame frame = MaybePreprocess(original_frame);
|
VideoFrame frame = MaybePreprocess(original_frame);
|
||||||
|
|
||||||
bool disable_adaptation;
|
bool enable_adaptation;
|
||||||
{
|
{
|
||||||
MutexLock lock(&lock_);
|
MutexLock lock(&lock_);
|
||||||
disable_adaptation = disable_adaptation_;
|
enable_adaptation = enable_adaptation_;
|
||||||
}
|
}
|
||||||
if (disable_adaptation) {
|
if (enable_adaptation) {
|
||||||
broadcaster_.OnFrame(frame);
|
broadcaster_.OnFrame(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -41,14 +41,17 @@ class TestVideoCapturer : public rtc::VideoSourceInterface<VideoFrame> {
|
|||||||
MutexLock lock(&lock_);
|
MutexLock lock(&lock_);
|
||||||
preprocessor_ = std::move(preprocessor);
|
preprocessor_ = std::move(preprocessor);
|
||||||
}
|
}
|
||||||
void SetDisableAdaptation(bool disable_adaptation) {
|
void SetEnableAdaptation(bool enable_adaptation) {
|
||||||
MutexLock lock(&lock_);
|
MutexLock lock(&lock_);
|
||||||
disable_adaptation_ = disable_adaptation;
|
enable_adaptation_ = enable_adaptation;
|
||||||
}
|
}
|
||||||
void OnOutputFormatRequest(int width,
|
void OnOutputFormatRequest(int width,
|
||||||
int height,
|
int height,
|
||||||
const absl::optional<int>& max_fps);
|
const absl::optional<int>& max_fps);
|
||||||
|
|
||||||
|
virtual int GetFrameWidth() const = 0;
|
||||||
|
virtual int GetFrameHeight() const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void OnFrame(const VideoFrame& frame);
|
void OnFrame(const VideoFrame& frame);
|
||||||
rtc::VideoSinkWants GetSinkWants();
|
rtc::VideoSinkWants GetSinkWants();
|
||||||
@ -59,7 +62,7 @@ class TestVideoCapturer : public rtc::VideoSourceInterface<VideoFrame> {
|
|||||||
|
|
||||||
Mutex lock_;
|
Mutex lock_;
|
||||||
std::unique_ptr<FramePreprocessor> preprocessor_ RTC_GUARDED_BY(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_;
|
rtc::VideoBroadcaster broadcaster_;
|
||||||
cricket::VideoAdapter video_adapter_;
|
cricket::VideoAdapter video_adapter_;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -27,6 +27,8 @@ bool VcmCapturer::Init(size_t width,
|
|||||||
size_t height,
|
size_t height,
|
||||||
size_t target_fps,
|
size_t target_fps,
|
||||||
size_t capture_device_index) {
|
size_t capture_device_index) {
|
||||||
|
width_ = width;
|
||||||
|
height_ = height;
|
||||||
std::unique_ptr<VideoCaptureModule::DeviceInfo> device_info(
|
std::unique_ptr<VideoCaptureModule::DeviceInfo> device_info(
|
||||||
VideoCaptureFactory::CreateDeviceInfo());
|
VideoCaptureFactory::CreateDeviceInfo());
|
||||||
|
|
||||||
|
|||||||
@ -31,6 +31,9 @@ class VcmCapturer : public TestVideoCapturer,
|
|||||||
|
|
||||||
void OnFrame(const VideoFrame& frame) override;
|
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:
|
private:
|
||||||
VcmCapturer();
|
VcmCapturer();
|
||||||
bool Init(size_t width,
|
bool Init(size_t width,
|
||||||
@ -39,6 +42,8 @@ class VcmCapturer : public TestVideoCapturer,
|
|||||||
size_t capture_device_index);
|
size_t capture_device_index);
|
||||||
void Destroy();
|
void Destroy();
|
||||||
|
|
||||||
|
size_t width_;
|
||||||
|
size_t height_;
|
||||||
rtc::scoped_refptr<VideoCaptureModule> vcm_;
|
rtc::scoped_refptr<VideoCaptureModule> vcm_;
|
||||||
VideoCaptureCapability capability_;
|
VideoCaptureCapability capability_;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user