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;