Skip to content
This repository was archived by the owner on Nov 6, 2025. It is now read-only.

Commit 218ae90

Browse files
committed
Do not try to have a "perfect" scale factor in webrtc::VideoAdapter
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.
1 parent c3b602c commit 218ae90

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

media/base/video_adapter.cc

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -219,24 +219,23 @@ bool VideoAdapter::AdaptFrameResolution(int in_width,
219219
}
220220
const Fraction scale = FindScale((*cropped_width) * (*cropped_height),
221221
target_pixel_count, max_pixel_count);
222-
// Adjust cropping slightly to get even integer output size and a perfect
223-
// scale factor. Make sure the resulting dimensions are aligned correctly
224-
// to be nice to hardware encoders.
225-
*cropped_width =
226-
roundUp(*cropped_width,
227-
scale.denominator * required_resolution_alignment_, in_width);
228-
*cropped_height =
229-
roundUp(*cropped_height,
230-
scale.denominator * required_resolution_alignment_, in_height);
231-
RTC_DCHECK_EQ(0, *cropped_width % scale.denominator);
232-
RTC_DCHECK_EQ(0, *cropped_height % scale.denominator);
233-
234-
// Calculate final output size.
235-
*out_width = *cropped_width / scale.denominator * scale.numerator;
236-
*out_height = *cropped_height / scale.denominator * scale.numerator;
222+
223+
// Make sure the resulting dimensions are aligned correctly to be nice to
224+
// hardware encoders.
225+
*out_width =
226+
roundUp(*cropped_width * scale.numerator,
227+
scale.denominator * required_resolution_alignment_,
228+
in_width * scale.numerator) / scale.denominator;
229+
*out_height =
230+
roundUp(*cropped_height * scale.numerator,
231+
scale.denominator * required_resolution_alignment_,
232+
in_height * scale.numerator) / scale.denominator;
237233
RTC_DCHECK_EQ(0, *out_width % required_resolution_alignment_);
238234
RTC_DCHECK_EQ(0, *out_height % required_resolution_alignment_);
239235

236+
*cropped_width = (*out_width * scale.denominator + scale.numerator - 1) / scale.numerator;
237+
*cropped_height = (*out_height * scale.denominator + scale.numerator - 1) / scale.numerator;
238+
240239
++frames_out_;
241240
if (scale.numerator != scale.denominator)
242241
++frames_scaled_;

0 commit comments

Comments
 (0)