From 450b548cade5498bbdef6eddce0703f52296bf65 Mon Sep 17 00:00:00 2001 From: Florent Castelli Date: Thu, 29 Nov 2018 17:32:47 +0100 Subject: [PATCH] Encode frames at the largest layer resolution instead of last layer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The current code assumes that layers are ordered from the smallest to the largest. If that assumption is broken and the last layer is smaller than the others, all layers that are bigger will be scaled up. Bug: webrtc:10069 Change-Id: Iff87ddba741d5dfe3d0cc25a8f75d898a417eec7 Reviewed-on: https://webrtc-review.googlesource.com/c/112460 Reviewed-by: Erik Språng Commit-Queue: Florent Castelli Cr-Commit-Position: refs/heads/master@{#25878} --- video/video_stream_encoder.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/video/video_stream_encoder.cc b/video/video_stream_encoder.cc index a22d58adf1..410c331359 100644 --- a/video/video_stream_encoder.cc +++ b/video/video_stream_encoder.cc @@ -526,8 +526,13 @@ void VideoStreamEncoder::ReconfigureEncoder() { // Stream dimensions may be not equal to given because of a simulcast // restrictions. - int highest_stream_width = static_cast(streams.back().width); - int highest_stream_height = static_cast(streams.back().height); + auto highest_stream = std::max_element( + streams.begin(), streams.end(), + [](const webrtc::VideoStream& a, const webrtc::VideoStream& b) { + return std::tie(a.width, a.height) < std::tie(b.width, b.height); + }); + int highest_stream_width = static_cast(highest_stream->width); + int highest_stream_height = static_cast(highest_stream->height); // Dimension may be reduced to be, e.g. divisible by 4. RTC_CHECK_GE(last_frame_info_->width, highest_stream_width); RTC_CHECK_GE(last_frame_info_->height, highest_stream_height);