Removes caching SimulcastEncoderAdapter::GetEncoderInfo()

There are edge cases where the caching of encoder info will cause
issues. For instance if a sub-encoder fails en Encode call and falls
back to some other implementation, or if the fps targets shift due to
SetRates() triggering new layers to be enabled.

This CL forces a complete rebuild on every call to GetEncoderInfo().

It also adds new logging of when the info changes, as debugging issues
can be very time consuming if we can't tell that happened.

Bug: webrtc:11000
Change-Id: I7ec7962a589ccba0e188e60a11f851c9de874fab
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/160960
Commit-Queue: Erik Språng <sprang@webrtc.org>
Reviewed-by: Rasmus Brandt <brandtr@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#29938}
This commit is contained in:
Erik Språng
2019-11-27 17:26:58 +01:00
committed by Commit Bot
parent 840394c6eb
commit 7968530418
6 changed files with 198 additions and 58 deletions

View File

@ -13,6 +13,7 @@
#include <string.h>
#include "rtc_base/checks.h"
#include "rtc_base/strings/string_builder.h"
namespace webrtc {
@ -81,6 +82,14 @@ constexpr VideoEncoder::ScalingSettings::KOff
// static
constexpr uint8_t VideoEncoder::EncoderInfo::kMaxFramerateFraction;
bool VideoEncoder::ResolutionBitrateLimits::operator==(
const ResolutionBitrateLimits& rhs) const {
return frame_size_pixels == rhs.frame_size_pixels &&
min_start_bitrate_bps == rhs.min_start_bitrate_bps &&
min_bitrate_bps == rhs.min_bitrate_bps &&
max_bitrate_bps == rhs.max_bitrate_bps;
}
VideoEncoder::EncoderInfo::EncoderInfo()
: scaling_settings(VideoEncoder::ScalingSettings::kOff),
supports_native_handle(false),
@ -97,6 +106,101 @@ VideoEncoder::EncoderInfo::EncoderInfo(const EncoderInfo&) = default;
VideoEncoder::EncoderInfo::~EncoderInfo() = default;
std::string VideoEncoder::EncoderInfo::ToString() const {
char string_buf[2048];
rtc::SimpleStringBuilder oss(string_buf);
oss << "EncoderInfo { "
<< "ScalingSettings { ";
if (scaling_settings.thresholds) {
oss << "Thresholds { "
<< "low = " << scaling_settings.thresholds->low
<< ", high = " << scaling_settings.thresholds->high << "}, ";
}
oss << "min_pixels_per_frame = " << scaling_settings.min_pixels_per_frame
<< " }";
oss << ", supports_native_handle = " << supports_native_handle
<< ", implementation_name = '" << implementation_name << "'"
<< ", has_trusted_rate_controller = " << has_trusted_rate_controller
<< ", is_hardware_accelerated = " << is_hardware_accelerated
<< ", has_internal_source = " << has_internal_source
<< ", fps_allocation = [";
bool first = true;
for (size_t i = 0; i < fps_allocation->size(); ++i) {
if (!first) {
oss << ", ";
}
const absl::InlinedVector<uint8_t, kMaxTemporalStreams>& fractions =
fps_allocation[i];
if (!fractions.empty()) {
first = false;
oss << "[ ";
for (size_t i = 0; i < fractions.size(); ++i) {
if (i > 0) {
oss << ", ";
}
oss << (static_cast<double>(fractions[i]) / kMaxFramerateFraction);
}
oss << "] ";
}
}
oss << "]";
oss << ", resolution_bitrate_limits = [";
for (size_t i = 0; i < resolution_bitrate_limits.size(); ++i) {
if (i > 0) {
oss << ", ";
}
ResolutionBitrateLimits l = resolution_bitrate_limits[i];
oss << "Limits { "
<< "frame_size_pixels = " << l.frame_size_pixels
<< ", min_start_bitrate_bps = " << l.min_start_bitrate_bps
<< ", min_bitrate_bps = " << l.min_bitrate_bps
<< ", max_bitrate_bps = " << l.max_bitrate_bps << "} ";
}
oss << "] "
<< ", supports_simulcast = " << supports_simulcast << "}";
return oss.str();
}
bool VideoEncoder::EncoderInfo::operator==(const EncoderInfo& rhs) const {
if (scaling_settings.thresholds.has_value() !=
rhs.scaling_settings.thresholds.has_value()) {
return false;
}
if (scaling_settings.thresholds.has_value()) {
QpThresholds l = *scaling_settings.thresholds;
QpThresholds r = *rhs.scaling_settings.thresholds;
if (l.low != r.low || l.high != r.high) {
return false;
}
}
if (scaling_settings.min_pixels_per_frame !=
rhs.scaling_settings.min_pixels_per_frame) {
return false;
}
if (supports_native_handle != rhs.supports_native_handle ||
implementation_name != rhs.implementation_name ||
has_trusted_rate_controller != rhs.has_trusted_rate_controller ||
is_hardware_accelerated != rhs.is_hardware_accelerated ||
has_internal_source != rhs.has_internal_source) {
return false;
}
for (size_t i = 0; i < kMaxSpatialLayers; ++i) {
if (fps_allocation[i] != rhs.fps_allocation[i]) {
return false;
}
}
if (resolution_bitrate_limits != rhs.resolution_bitrate_limits ||
supports_simulcast != rhs.supports_simulcast) {
return false;
}
return true;
}
VideoEncoder::RateControlParameters::RateControlParameters()
: bitrate(VideoBitrateAllocation()),
framerate_fps(0.0),

View File

@ -141,6 +141,11 @@ class RTC_EXPORT VideoEncoder {
int min_bitrate_bps = 0;
// Recommended maximum bitrate.
int max_bitrate_bps = 0;
bool operator==(const ResolutionBitrateLimits& rhs) const;
bool operator!=(const ResolutionBitrateLimits& rhs) const {
return !(*this == rhs);
}
};
// Struct containing metadata about the encoder implementing this interface.
@ -153,6 +158,10 @@ class RTC_EXPORT VideoEncoder {
~EncoderInfo();
std::string ToString() const;
bool operator==(const EncoderInfo& rhs) const;
bool operator!=(const EncoderInfo& rhs) const { return !(*this == rhs); }
// Any encoder implementation wishing to use the WebRTC provided
// quality scaler must populate this field.
ScalingSettings scaling_settings;