Skip to content

Commit

Permalink
Do not try to have a "perfect" scale factor in webrtc::VideoAdapter
Browse files Browse the repository at this point in the history
Without this change, webrtc::VideoAdapter tries to have a scale factor
which can be represented in an easy fraction. That behavior requires
the cropped image to be aligned with scale fraction denominator multiplied
with the output alignment requirement, which can be much larger for
relatively large output alignment requirement.

The behavior does not seem to be required by any implementation so just
abandon it to avoid such a large alignment requirement.
  • Loading branch information
akihikodaki committed Dec 11, 2019
1 parent c3b602c commit 218ae90
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions media/base/video_adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,24 +219,23 @@ bool VideoAdapter::AdaptFrameResolution(int in_width,
}
const Fraction scale = FindScale((*cropped_width) * (*cropped_height),
target_pixel_count, max_pixel_count);
// Adjust cropping slightly to get even integer output size and a perfect
// scale factor. Make sure the resulting dimensions are aligned correctly
// to be nice to hardware encoders.
*cropped_width =
roundUp(*cropped_width,
scale.denominator * required_resolution_alignment_, in_width);
*cropped_height =
roundUp(*cropped_height,
scale.denominator * required_resolution_alignment_, in_height);
RTC_DCHECK_EQ(0, *cropped_width % scale.denominator);
RTC_DCHECK_EQ(0, *cropped_height % scale.denominator);

// Calculate final output size.
*out_width = *cropped_width / scale.denominator * scale.numerator;
*out_height = *cropped_height / scale.denominator * scale.numerator;

// Make sure the resulting dimensions are aligned correctly to be nice to
// hardware encoders.
*out_width =
roundUp(*cropped_width * scale.numerator,
scale.denominator * required_resolution_alignment_,
in_width * scale.numerator) / scale.denominator;
*out_height =
roundUp(*cropped_height * scale.numerator,
scale.denominator * required_resolution_alignment_,
in_height * scale.numerator) / scale.denominator;
RTC_DCHECK_EQ(0, *out_width % required_resolution_alignment_);
RTC_DCHECK_EQ(0, *out_height % required_resolution_alignment_);

*cropped_width = (*out_width * scale.denominator + scale.numerator - 1) / scale.numerator;
*cropped_height = (*out_height * scale.denominator + scale.numerator - 1) / scale.numerator;

++frames_out_;
if (scale.numerator != scale.denominator)
++frames_scaled_;
Expand Down

0 comments on commit 218ae90

Please sign in to comment.