Add 'SkipNextFrame' to the FrameGeneratorInterface.

Also fix PRESUBMIT.py following https://webrtc-review.googlesource.com/c/src/+/358160.

Change-Id: I00682209607a184448255cf5ad8fd213fda7f4af
Bug: b/355120692
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/358320
Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org>
Commit-Queue: Jeremy Leconte <jleconte@google.com>
Cr-Commit-Position: refs/heads/main@{#42711}
This commit is contained in:
Jeremy Leconte 2024-08-01 15:45:35 +02:00 committed by WebRTC LUCI CQ
parent d02a216026
commit 53291d49b2
7 changed files with 30 additions and 5 deletions

View File

@ -650,8 +650,8 @@ def CheckGnGen(input_api, output_api):
with _AddToPath( with _AddToPath(
input_api.os_path.join(input_api.PresubmitLocalPath(), input_api.os_path.join(input_api.PresubmitLocalPath(),
'tools_webrtc', 'presubmit_checks_lib')): 'tools_webrtc', 'presubmit_checks_lib')):
from build_helpers import RunGnCheck from build_helpers import run_gn_check
errors = RunGnCheck(input_api.change.RepositoryRoot())[:5] errors = run_gn_check(input_api.change.RepositoryRoot())[:5]
if errors: if errors:
return [ return [
output_api.PresubmitPromptWarning( output_api.PresubmitPromptWarning(

View File

@ -44,6 +44,9 @@ class FrameGeneratorInterface {
// Returns VideoFrameBuffer and area where most of update was done to set them // Returns VideoFrameBuffer and area where most of update was done to set them
// on the VideoFrame object. // on the VideoFrame object.
virtual VideoFrameData NextFrame() = 0; virtual VideoFrameData NextFrame() = 0;
// Skips the next frame in case it doesn't need to be encoded.
// Default implementation is to call NextFrame and ignore the returned value.
virtual void SkipNextFrame() { NextFrame(); }
// Change the capture resolution. // Change the capture resolution.
virtual void ChangeResolution(size_t width, size_t height) = 0; virtual void ChangeResolution(size_t width, size_t height) = 0;

View File

@ -92,15 +92,15 @@ bool FrameGeneratorCapturer::Init() {
void FrameGeneratorCapturer::InsertFrame() { void FrameGeneratorCapturer::InsertFrame() {
MutexLock lock(&lock_); MutexLock lock(&lock_);
if (sending_) { if (sending_) {
FrameGeneratorInterface::VideoFrameData frame_data =
frame_generator_->NextFrame();
// TODO(srte): Use more advanced frame rate control to allow arbitrary // TODO(srte): Use more advanced frame rate control to allow arbitrary
// fractions. // fractions.
int decimation = int decimation =
std::round(static_cast<double>(source_fps_) / target_capture_fps_); std::round(static_cast<double>(source_fps_) / target_capture_fps_);
for (int i = 1; i < decimation; ++i) for (int i = 1; i < decimation; ++i)
frame_data = frame_generator_->NextFrame(); frame_generator_->SkipNextFrame();
FrameGeneratorInterface::VideoFrameData frame_data =
frame_generator_->NextFrame();
VideoFrame frame = VideoFrame::Builder() VideoFrame frame = VideoFrame::Builder()
.set_video_frame_buffer(frame_data.buffer) .set_video_frame_buffer(frame_data.buffer)
.set_rotation(fake_rotation_) .set_rotation(fake_rotation_)

View File

@ -120,6 +120,21 @@ FrameGeneratorInterface::VideoFrameData IvfVideoFrameGenerator::NextFrame() {
return VideoFrameData(buffer, next_frame_->update_rect()); return VideoFrameData(buffer, next_frame_->update_rect());
} }
void IvfVideoFrameGenerator::SkipNextFrame() {
MutexLock lock(&lock_);
next_frame_decoded_.Reset();
RTC_CHECK(file_reader_);
if (!file_reader_->HasMoreFrames()) {
file_reader_->Reset();
}
absl::optional<EncodedImage> image = file_reader_->NextFrame();
RTC_CHECK(image);
// Last parameter is undocumented and there is no usage of it found.
// Frame has to be decoded in case it is a key frame.
RTC_CHECK_EQ(WEBRTC_VIDEO_CODEC_OK,
video_decoder_->Decode(*image, /*render_time_ms=*/0));
}
void IvfVideoFrameGenerator::ChangeResolution(size_t width, size_t height) { void IvfVideoFrameGenerator::ChangeResolution(size_t width, size_t height) {
MutexLock lock(&lock_); MutexLock lock(&lock_);
width_ = width; width_ = width;

View File

@ -36,6 +36,7 @@ class IvfVideoFrameGenerator : public FrameGeneratorInterface {
~IvfVideoFrameGenerator() override; ~IvfVideoFrameGenerator() override;
VideoFrameData NextFrame() override; VideoFrameData NextFrame() override;
void SkipNextFrame() override;
void ChangeResolution(size_t width, size_t height) override; void ChangeResolution(size_t width, size_t height) override;
Resolution GetResolution() const override; Resolution GetResolution() const override;

View File

@ -74,6 +74,10 @@ Y4mFrameGenerator::VideoFrameData Y4mFrameGenerator::NextFrame() {
return VideoFrameData(scaled_buffer, update_rect); return VideoFrameData(scaled_buffer, update_rect);
} }
void Y4mFrameGenerator::SkipNextFrame() {
frame_reader_->PullFrame();
}
void Y4mFrameGenerator::ChangeResolution(size_t width, size_t height) { void Y4mFrameGenerator::ChangeResolution(size_t width, size_t height) {
width_ = width; width_ = width;
height_ = height; height_ = height;

View File

@ -45,6 +45,8 @@ class Y4mFrameGenerator : public FrameGeneratorInterface {
VideoFrameData NextFrame() override; VideoFrameData NextFrame() override;
void SkipNextFrame() override;
void ChangeResolution(size_t width, size_t height) override; void ChangeResolution(size_t width, size_t height) override;
Resolution GetResolution() const override; Resolution GetResolution() const override;