diff --git a/api/test/frame_generator_interface.h b/api/test/frame_generator_interface.h index 90e60debac..84aa1dcafb 100644 --- a/api/test/frame_generator_interface.h +++ b/api/test/frame_generator_interface.h @@ -23,6 +23,10 @@ namespace test { class FrameGeneratorInterface { public: + struct Resolution { + size_t width; + size_t height; + }; struct VideoFrameData { VideoFrameData(rtc::scoped_refptr buffer, absl::optional update_rect) @@ -43,6 +47,11 @@ class FrameGeneratorInterface { // Change the capture resolution. virtual void ChangeResolution(size_t width, size_t height) = 0; + + virtual Resolution GetResolution() const { + // TODO(mbonadei): Remove and make it pure virtual. + return {.width = 0, .height = 0}; + } }; } // namespace test diff --git a/test/frame_generator.cc b/test/frame_generator.cc index b6f16a573d..d2fa95352d 100644 --- a/test/frame_generator.cc +++ b/test/frame_generator.cc @@ -45,6 +45,12 @@ void SquareGenerator::ChangeResolution(size_t width, size_t height) { RTC_CHECK(height_ > 0); } +FrameGeneratorInterface::Resolution SquareGenerator::GetResolution() const { + MutexLock lock(&mutex_); + return {.width = static_cast(width_), + .height = static_cast(height_)}; +} + rtc::scoped_refptr SquareGenerator::CreateI420Buffer(int width, int height) { rtc::scoped_refptr buffer(I420Buffer::Create(width, height)); @@ -205,6 +211,10 @@ bool YuvFileGenerator::ReadNextFrame() { return frame_index_ != prev_frame_index || file_index_ != prev_file_index; } +FrameGeneratorInterface::Resolution YuvFileGenerator::GetResolution() const { + return {.width = width_, .height = height_}; +} + NV12FileGenerator::NV12FileGenerator(std::vector files, size_t width, size_t height, @@ -247,6 +257,10 @@ FrameGeneratorInterface::VideoFrameData NV12FileGenerator::NextFrame() { return VideoFrameData(last_read_buffer_, update_rect); } +FrameGeneratorInterface::Resolution NV12FileGenerator::GetResolution() const { + return {.width = width_, .height = height_}; +} + bool NV12FileGenerator::ReadNextFrame() { size_t prev_frame_index = frame_index_; size_t prev_file_index = file_index_; @@ -287,6 +301,11 @@ FrameGeneratorInterface::VideoFrameData SlideGenerator::NextFrame() { return VideoFrameData(buffer_, absl::nullopt); } +FrameGeneratorInterface::Resolution SlideGenerator::GetResolution() const { + return {.width = static_cast(width_), + .height = static_cast(height_)}; +} + void SlideGenerator::GenerateNewFrame() { // The squares should have a varying order of magnitude in order // to simulate variation in the slides' complexity. @@ -390,6 +409,12 @@ ScrollingImageFrameGenerator::NextFrame() { return current_frame_; } +FrameGeneratorInterface::Resolution +ScrollingImageFrameGenerator::GetResolution() const { + return {.width = static_cast(target_width_), + .height = static_cast(target_height_)}; +} + void ScrollingImageFrameGenerator::UpdateSourceFrame(size_t frame_num) { VideoFrame::UpdateRect acc_update{0, 0, 0, 0}; while (current_frame_num_ != frame_num) { diff --git a/test/frame_generator.h b/test/frame_generator.h index 9a8f08cea6..6eb6bf77cd 100644 --- a/test/frame_generator.h +++ b/test/frame_generator.h @@ -38,6 +38,7 @@ class SquareGenerator : public FrameGeneratorInterface { void ChangeResolution(size_t width, size_t height) override; VideoFrameData NextFrame() override; + Resolution GetResolution() const override; private: rtc::scoped_refptr CreateI420Buffer(int width, int height); @@ -59,7 +60,7 @@ class SquareGenerator : public FrameGeneratorInterface { const uint8_t yuv_a_; }; - Mutex mutex_; + mutable Mutex mutex_; const OutputType type_; int width_ RTC_GUARDED_BY(&mutex_); int height_ RTC_GUARDED_BY(&mutex_); @@ -79,6 +80,7 @@ class YuvFileGenerator : public FrameGeneratorInterface { void ChangeResolution(size_t width, size_t height) override { RTC_LOG(LS_WARNING) << "YuvFileGenerator::ChangeResolution not implemented"; } + Resolution GetResolution() const override; private: // Returns true if the new frame was loaded. @@ -111,6 +113,7 @@ class NV12FileGenerator : public FrameGeneratorInterface { RTC_LOG(LS_WARNING) << "NV12FileGenerator::ChangeResolution not implemented"; } + Resolution GetResolution() const override; private: // Returns true if the new frame was loaded. @@ -140,6 +143,7 @@ class SlideGenerator : public FrameGeneratorInterface { void ChangeResolution(size_t width, size_t height) override { RTC_LOG(LS_WARNING) << "SlideGenerator::ChangeResolution not implemented"; } + Resolution GetResolution() const override; private: // Generates some randomly sized and colored squares scattered @@ -171,6 +175,7 @@ class ScrollingImageFrameGenerator : public FrameGeneratorInterface { RTC_LOG(LS_WARNING) << "ScrollingImageFrameGenerator::ChangeResolution not implemented"; } + Resolution GetResolution() const override; private: void UpdateSourceFrame(size_t frame_num); diff --git a/test/testsupport/ivf_video_frame_generator.cc b/test/testsupport/ivf_video_frame_generator.cc index 92700e192f..ae87fb8b04 100644 --- a/test/testsupport/ivf_video_frame_generator.cc +++ b/test/testsupport/ivf_video_frame_generator.cc @@ -105,6 +105,11 @@ void IvfVideoFrameGenerator::ChangeResolution(size_t width, size_t height) { height_ = height; } +FrameGeneratorInterface::Resolution IvfVideoFrameGenerator::GetResolution() + const { + return {.width = width_, .height = height_}; +} + int32_t IvfVideoFrameGenerator::DecodedCallback::Decoded( VideoFrame& decoded_image) { Decoded(decoded_image, 0, 0); diff --git a/test/testsupport/ivf_video_frame_generator.h b/test/testsupport/ivf_video_frame_generator.h index 4b6d116383..9a4c1e2858 100644 --- a/test/testsupport/ivf_video_frame_generator.h +++ b/test/testsupport/ivf_video_frame_generator.h @@ -35,6 +35,7 @@ class IvfVideoFrameGenerator : public FrameGeneratorInterface { VideoFrameData NextFrame() override; void ChangeResolution(size_t width, size_t height) override; + Resolution GetResolution() const override; private: class DecodedCallback : public DecodedImageCallback {