Move more calls to webrtc::field_trial::FindFullName into ctor, thereby minimizing the non-trivial cost of repeated string comparisons.

BUG=webrtc:7059

Review-Url: https://codereview.webrtc.org/2657863002
Cr-Commit-Position: refs/heads/master@{#16378}
This commit is contained in:
elad.alon 2017-01-31 05:48:37 -08:00 committed by Commit bot
parent 89f281c51a
commit 0fe1216c9c
6 changed files with 39 additions and 27 deletions

View File

@ -1226,6 +1226,8 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream
: voe_audio_transport_(voe_audio_transport),
call_(call),
config_(send_transport),
send_side_bwe_with_overhead_(webrtc::field_trial::FindFullName(
"WebRTC-SendSideBwe-WithOverhead") == "Enabled"),
max_send_bitrate_bps_(max_send_bitrate_bps),
rtp_parameters_(CreateRtpParametersWithOneEncoding()) {
RTC_DCHECK_GE(ch, 0);
@ -1458,8 +1460,7 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream
config_.max_bitrate_bps = kOpusBitrateFbBps;
// TODO(mflodman): Keep testing this and set proper values.
// Note: This is an early experiment currently only supported by Opus.
if (webrtc::field_trial::FindFullName(
"WebRTC-SendSideBwe-WithOverhead") == "Enabled") {
if (send_side_bwe_with_overhead_) {
auto packet_sizes_ms = WebRtcVoiceCodecs::GetPacketSizesMs(
config_.send_codec_spec.codec_inst);
if (!packet_sizes_ms.empty()) {
@ -1500,6 +1501,7 @@ class WebRtcVoiceMediaChannel::WebRtcAudioSendStream
webrtc::AudioTransport* const voe_audio_transport_ = nullptr;
webrtc::Call* call_ = nullptr;
webrtc::AudioSendStream::Config config_;
const bool send_side_bwe_with_overhead_;
// The stream is owned by WebRtcAudioSendStream and may be reallocated if
// configuration changes.
webrtc::AudioSendStream* stream_ = nullptr;

View File

@ -174,7 +174,9 @@ AudioEncoderOpus::AudioEncoderOpus(
const Config& config,
AudioNetworkAdaptorCreator&& audio_network_adaptor_creator,
std::unique_ptr<SmoothingFilter> bitrate_smoother)
: packet_loss_rate_(0.0),
: send_side_bwe_with_overhead_(webrtc::field_trial::FindFullName(
"WebRTC-SendSideBwe-WithOverhead") == "Enabled"),
packet_loss_rate_(0.0),
inst_(nullptr),
packet_loss_fraction_smoother_(new PacketLossFractionSmoother(
config.clock)),
@ -314,8 +316,7 @@ void AudioEncoderOpus::OnReceivedUplinkBandwidth(
bitrate_smoother_->AddSample(target_audio_bitrate_bps);
ApplyAudioNetworkAdaptor();
} else if (webrtc::field_trial::FindFullName(
"WebRTC-SendSideBwe-WithOverhead") == "Enabled") {
} else if (send_side_bwe_with_overhead_) {
if (!overhead_bytes_per_packet_) {
LOG(LS_INFO)
<< "AudioEncoderOpus: Overhead unknown, target audio bitrate "

View File

@ -161,6 +161,7 @@ class AudioEncoderOpus final : public AudioEncoder {
void MaybeUpdateUplinkBandwidth();
Config config_;
const bool send_side_bwe_with_overhead_;
float packet_loss_rate_;
std::vector<int16_t> input_buffer_;
OpusEncInst* inst_;

View File

@ -43,7 +43,9 @@ class PacketInfoComparator {
TransportFeedbackAdapter::TransportFeedbackAdapter(
Clock* clock,
BitrateController* bitrate_controller)
: transport_overhead_bytes_per_packet_(0),
: send_side_bwe_with_overhead_(webrtc::field_trial::FindFullName(
"WebRTC-SendSideBwe-WithOverhead") == "Enabled"),
transport_overhead_bytes_per_packet_(0),
send_time_history_(clock, kSendTimeHistoryWindowMs),
clock_(clock),
current_offset_ms_(kNoTimestamp),
@ -61,8 +63,7 @@ void TransportFeedbackAdapter::AddPacket(uint16_t sequence_number,
size_t length,
int probe_cluster_id) {
rtc::CritScope cs(&lock_);
if (webrtc::field_trial::FindFullName("WebRTC-SendSideBwe-WithOverhead") ==
"Enabled") {
if (send_side_bwe_with_overhead_) {
length += transport_overhead_bytes_per_packet_;
}
send_time_history_.AddAndRemoveOld(sequence_number, length, probe_cluster_id);

View File

@ -58,6 +58,7 @@ class TransportFeedbackAdapter : public TransportFeedbackObserver,
std::vector<PacketInfo> GetPacketFeedbackVector(
const rtcp::TransportFeedback& feedback);
const bool send_side_bwe_with_overhead_;
rtc::CriticalSection lock_;
rtc::CriticalSection bwe_lock_;
int transport_overhead_bytes_per_packet_ GUARDED_BY(&lock_);

View File

@ -292,9 +292,6 @@ int CalculateMaxPadBitrateBps(std::vector<VideoStream> streams,
uint32_t CalculateOverheadRateBps(int packets_per_second,
size_t overhead_bytes_per_packet,
uint32_t max_overhead_bps) {
if (webrtc::field_trial::FindFullName("WebRTC-SendSideBwe-WithOverhead") !=
"Enabled")
return 0;
uint32_t overhead_bps =
static_cast<uint32_t>(8 * overhead_bytes_per_packet * packets_per_second);
return std::min(overhead_bps, max_overhead_bps);
@ -398,6 +395,8 @@ class VideoSendStreamImpl : public webrtc::BitrateAllocatorObserver,
void SignalEncoderTimedOut();
void SignalEncoderActive();
const bool send_side_bwe_with_overhead_;
SendStatisticsProxy* const stats_proxy_;
const VideoSendStream::Config* const config_;
std::map<uint32_t, RtpState> suspended_ssrcs_;
@ -758,7 +757,9 @@ VideoSendStreamImpl::VideoSendStreamImpl(
const VideoSendStream::Config* config,
int initial_encoder_max_bitrate,
std::map<uint32_t, RtpState> suspended_ssrcs)
: stats_proxy_(stats_proxy),
: send_side_bwe_with_overhead_(webrtc::field_trial::FindFullName(
"WebRTC-SendSideBwe-WithOverhead") == "Enabled"),
stats_proxy_(stats_proxy),
config_(config),
suspended_ssrcs_(std::move(suspended_ssrcs)),
module_process_thread_(nullptr),
@ -1226,14 +1227,15 @@ uint32_t VideoSendStreamImpl::OnBitrateUpdated(uint32_t bitrate_bps,
// Substract overhead from bitrate.
rtc::CritScope lock(&overhead_bytes_per_packet_crit_);
uint32_t payload_bitrate_bps =
bitrate_bps -
CalculateOverheadRateBps(
CalculatePacketRate(bitrate_bps,
config_->rtp.max_packet_size +
transport_overhead_bytes_per_packet_),
overhead_bytes_per_packet_ + transport_overhead_bytes_per_packet_,
bitrate_bps);
uint32_t payload_bitrate_bps = bitrate_bps;
if (send_side_bwe_with_overhead_) {
payload_bitrate_bps -= CalculateOverheadRateBps(
CalculatePacketRate(bitrate_bps,
config_->rtp.max_packet_size +
transport_overhead_bytes_per_packet_),
overhead_bytes_per_packet_ + transport_overhead_bytes_per_packet_,
bitrate_bps);
}
// Get the encoder target rate. It is the estimated network rate -
// protection overhead.
@ -1241,13 +1243,17 @@ uint32_t VideoSendStreamImpl::OnBitrateUpdated(uint32_t bitrate_bps,
payload_bitrate_bps, stats_proxy_->GetSendFrameRate(), fraction_loss,
rtt);
uint32_t encoder_overhead_rate_bps = CalculateOverheadRateBps(
CalculatePacketRate(encoder_target_rate_bps_,
config_->rtp.max_packet_size +
transport_overhead_bytes_per_packet_ -
overhead_bytes_per_packet_),
overhead_bytes_per_packet_ + transport_overhead_bytes_per_packet_,
bitrate_bps - encoder_target_rate_bps_);
uint32_t encoder_overhead_rate_bps =
send_side_bwe_with_overhead_
? CalculateOverheadRateBps(
CalculatePacketRate(encoder_target_rate_bps_,
config_->rtp.max_packet_size +
transport_overhead_bytes_per_packet_ -
overhead_bytes_per_packet_),
overhead_bytes_per_packet_ +
transport_overhead_bytes_per_packet_,
bitrate_bps - encoder_target_rate_bps_)
: 0;
// When the field trial "WebRTC-SendSideBwe-WithOverhead" is enabled
// protection_bitrate includes overhead.