From 536f587b9877147c66e403ac4a4daeeeeeefa9a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Spr=C3=A5ng?= Date: Fri, 6 May 2022 09:34:59 +0000 Subject: [PATCH] Revert "Calculate video stream max bitrate using expression." MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 45361f78ed18c350b3edcaef19ae4c7cf167e95b. Reason for revert: Perf alerts galore. Original change's description: > Calculate video stream max bitrate using expression. > > This replaces the ealier table-based caps. > Apart from the VGA cap (now 1600kbps instead of 1700kbps), or if using > "in between" resolutions, the caps are unchanged - but now cover high > resolutions better. > > Bug: webrtc:14017 > Change-Id: I8649b528495d6c917e38ea8cb1a272df6c464c03 > Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/260940 > Commit-Queue: Erik Språng > Reviewed-by: Per Kjellander > Cr-Commit-Position: refs/heads/main@{#36776} Bug: webrtc:14017 Change-Id: I18ebc81c6054713c58d49bd227e37090686958c9 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/261309 Reviewed-by: Per Kjellander Auto-Submit: Erik Språng Commit-Queue: Per Kjellander Bot-Commit: rubber-stamper@appspot.gserviceaccount.com Cr-Commit-Position: refs/heads/main@{#36794} --- media/engine/webrtc_video_engine.cc | 34 ++++++++---------- media/engine/webrtc_video_engine_unittest.cc | 36 -------------------- 2 files changed, 14 insertions(+), 56 deletions(-) diff --git a/media/engine/webrtc_video_engine.cc b/media/engine/webrtc_video_engine.cc index 82caab9292..e29d1ea66e 100644 --- a/media/engine/webrtc_video_engine.cc +++ b/media/engine/webrtc_video_engine.cc @@ -343,30 +343,24 @@ bool IsCodecDisabledForSimulcast(const std::string& codec_name, return false; } -// Calculates some reasonable max bitrate thresholds based on resolution. +// The selected thresholds for QVGA and VGA corresponded to a QP around 10. +// The change in QP declined above the selected bitrates. static int GetMaxDefaultVideoBitrateKbps(int width, int height, bool is_screenshare) { - double pixel_count = width * height; - // This expression uses a rectangular hyperbola plus a small exponential - // correction function, with parameters selected so the curve fits well to - // values expected for common resolutions. - // - // Some examples: - // 320x240 => 600 - // 640x480 => 1600 - // 960x540 => 2000 - // 1280x720 => 2500 - // 1920x1080 => 3300 - double max_kbps = (3000 * pixel_count) / (310000 + pixel_count) + - 0.0003 * std::pow(pixel_count, 1.005); - // Round to nearest 100kbps. - int max_bitrate_kbps = - 100 * std::max(1, static_cast(std::round(max_kbps / 100))); - + int max_bitrate; + if (width * height <= 320 * 240) { + max_bitrate = 600; + } else if (width * height <= 640 * 480) { + max_bitrate = 1700; + } else if (width * height <= 960 * 540) { + max_bitrate = 2000; + } else { + max_bitrate = 2500; + } if (is_screenshare) - max_bitrate_kbps = std::max(max_bitrate_kbps, 1200); - return max_bitrate_kbps; + max_bitrate = std::max(max_bitrate, 1200); + return max_bitrate; } // Returns its smallest positive argument. If neither argument is positive, diff --git a/media/engine/webrtc_video_engine_unittest.cc b/media/engine/webrtc_video_engine_unittest.cc index e32d005f61..377ea232c4 100644 --- a/media/engine/webrtc_video_engine_unittest.cc +++ b/media/engine/webrtc_video_engine_unittest.cc @@ -7068,42 +7068,6 @@ TEST_F(WebRtcVideoChannelTest, stream->GetVideoStreams()[0].max_bitrate_bps); } -TEST_F(WebRtcVideoChannelTest, SetsCorrectMaxBitrateForCommonResolutions) { - FakeVideoSendStream* stream = AddSendStream(); - webrtc::test::FrameForwarder frame_forwarder; - VideoOptions options; - EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &frame_forwarder)); - channel_->SetSend(true); - - auto rtp_parameters = channel_->GetRtpSendParameters(last_ssrc_); - auto result = channel_->SetRtpSendParameters(last_ssrc_, rtp_parameters); - ASSERT_TRUE(result.ok()); - - struct ResolutionBitratePairing { - int width; - int height; - int bitrate_kbps; - }; - std::vector resolutions = { - {.width = 320, .height = 240, .bitrate_kbps = 600}, - {.width = 640, .height = 480, .bitrate_kbps = 1600}, - {.width = 960, .height = 540, .bitrate_kbps = 2000}, - {.width = 1280, .height = 720, .bitrate_kbps = 2500}, - {.width = 1920, .height = 1080, .bitrate_kbps = 3300}, - {.width = 3840, .height = 2190, .bitrate_kbps = 5600}}; - for (const ResolutionBitratePairing& resolution : resolutions) { - FakeFrameSource frame_source(resolution.width, resolution.height, - rtc::kNumMicrosecsPerSec / 30); - frame_forwarder.IncomingCapturedFrame(frame_source.GetFrame()); - - ASSERT_EQ(1UL, stream->GetVideoStreams().size()); - EXPECT_EQ(resolution.bitrate_kbps * 1000, - stream->GetVideoStreams()[0].max_bitrate_bps); - } - - EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); -} - TEST_F(WebRtcVideoChannelTest, SetMaxFramerateOneStream) { FakeVideoSendStream* stream = AddSendStream();