Make frame generators return the target resolution.

Bug: b/269577953
Change-Id: Ib3db0017becb8a6a680997f59e0f9050a42a3a79
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/293940
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Artem Titov <titovartem@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#39331}
This commit is contained in:
Mirko Bonadei 2023-02-17 12:49:58 +00:00 committed by WebRTC LUCI CQ
parent cd7ea3ef46
commit f1e392214d
5 changed files with 46 additions and 1 deletions

View file

@ -23,6 +23,10 @@ namespace test {
class FrameGeneratorInterface {
public:
struct Resolution {
size_t width;
size_t height;
};
struct VideoFrameData {
VideoFrameData(rtc::scoped_refptr<VideoFrameBuffer> buffer,
absl::optional<VideoFrame::UpdateRect> 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

View file

@ -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<size_t>(width_),
.height = static_cast<size_t>(height_)};
}
rtc::scoped_refptr<I420Buffer> SquareGenerator::CreateI420Buffer(int width,
int height) {
rtc::scoped_refptr<I420Buffer> 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<FILE*> 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<size_t>(width_),
.height = static_cast<size_t>(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<size_t>(target_width_),
.height = static_cast<size_t>(target_height_)};
}
void ScrollingImageFrameGenerator::UpdateSourceFrame(size_t frame_num) {
VideoFrame::UpdateRect acc_update{0, 0, 0, 0};
while (current_frame_num_ != frame_num) {

View file

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

View file

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

View file

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