From 438663e7fc11657d109b0b055aed2c0db1328f55 Mon Sep 17 00:00:00 2001 From: Seth Hampson Date: Tue, 9 Jan 2018 11:14:14 -0800 Subject: [PATCH] DCHECKS added to GetSimulcastConfig. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit GetSimulcastConfig should never return an empty vector of VideoStreams, because lower layers in the code expect atleast one VideoStream. It should also never be given input of max_streams equal to 0. Bug: webrtc:8648 Change-Id: I60f59b3b267a732f07001e4c8a7fa64963802887 Reviewed-on: https://webrtc-review.googlesource.com/38061 Commit-Queue: Erik Språng Reviewed-by: Taylor Brandstetter Reviewed-by: Erik Språng Cr-Commit-Position: refs/heads/master@{#21545} --- media/engine/simulcast.cc | 48 ++++++++------------------------------- 1 file changed, 9 insertions(+), 39 deletions(-) diff --git a/media/engine/simulcast.cc b/media/engine/simulcast.cc index f815256f5b..aa042468ad 100644 --- a/media/engine/simulcast.cc +++ b/media/engine/simulcast.cc @@ -69,31 +69,23 @@ void GetSimulcastSsrcs(const StreamParams& sp, std::vector* ssrcs) { } } -void MaybeExchangeWidthHeight(int* width, int* height) { - // |kSimulcastFormats| assumes |width| >= |height|. If not, exchange them - // before comparing. - if (*width < *height) { - int temp = *width; - *width = *height; - *height = temp; - } -} - int FindSimulcastFormatIndex(int width, int height) { - MaybeExchangeWidthHeight(&width, &height); - + RTC_DCHECK_GE(width, 0); + RTC_DCHECK_GE(height, 0); for (uint32_t i = 0; i < arraysize(kSimulcastFormats); ++i) { if (width * height >= kSimulcastFormats[i].width * kSimulcastFormats[i].height) { return i; } } + RTC_NOTREACHED(); return -1; } int FindSimulcastFormatIndex(int width, int height, size_t max_layers) { - MaybeExchangeWidthHeight(&width, &height); - + RTC_DCHECK_GE(width, 0); + RTC_DCHECK_GE(height, 0); + RTC_DCHECK_GT(max_layers, 0); for (uint32_t i = 0; i < arraysize(kSimulcastFormats); ++i) { if (width * height >= kSimulcastFormats[i].width * kSimulcastFormats[i].height && @@ -101,6 +93,7 @@ int FindSimulcastFormatIndex(int width, int height, size_t max_layers) { return i; } } + RTC_NOTREACHED(); return -1; } @@ -113,51 +106,30 @@ int NormalizeSimulcastSize(int size, size_t simulcast_layers) { size_t FindSimulcastMaxLayers(int width, int height) { int index = FindSimulcastFormatIndex(width, height); - if (index == -1) { - return -1; - } return kSimulcastFormats[index].max_layers; } -// TODO(marpan): Investigate if we should return 0 instead of -1 in -// FindSimulcast[Max/Target/Min]Bitrate functions below, since the -// codec struct max/min/targeBitrates are unsigned. int FindSimulcastMaxBitrateBps(int width, int height) { const int format_index = FindSimulcastFormatIndex(width, height); - if (format_index == -1) { - return -1; - } return kSimulcastFormats[format_index].max_bitrate_kbps * 1000; } int FindSimulcastTargetBitrateBps(int width, int height) { const int format_index = FindSimulcastFormatIndex(width, height); - if (format_index == -1) { - return -1; - } return kSimulcastFormats[format_index].target_bitrate_kbps * 1000; } int FindSimulcastMinBitrateBps(int width, int height) { const int format_index = FindSimulcastFormatIndex(width, height); - if (format_index == -1) { - return -1; - } return kSimulcastFormats[format_index].min_bitrate_kbps * 1000; } -bool SlotSimulcastMaxResolution(size_t max_layers, int* width, int* height) { +void SlotSimulcastMaxResolution(size_t max_layers, int* width, int* height) { int index = FindSimulcastFormatIndex(*width, *height, max_layers); - if (index == -1) { - RTC_LOG(LS_ERROR) << "SlotSimulcastMaxResolution"; - return false; - } - *width = kSimulcastFormats[index].width; *height = kSimulcastFormats[index].height; RTC_LOG(LS_INFO) << "SlotSimulcastMaxResolution to width:" << *width << " height:" << *height; - return true; } int GetTotalMaxBitrateBps(const std::vector& streams) { @@ -206,9 +178,7 @@ std::vector GetSimulcastConfig(size_t max_streams, // If the number of SSRCs in the group differs from our target // number of simulcast streams for current resolution, switch down // to a resolution that matches our number of SSRCs. - if (!SlotSimulcastMaxResolution(max_streams, &width, &height)) { - return std::vector(); - } + SlotSimulcastMaxResolution(max_streams, &width, &height); num_simulcast_layers = max_streams; } std::vector streams;