mirror of
https://github.com/mollyim/webrtc.git
synced 2025-05-12 21:30:45 +01:00
Remove lbred experiment
This commit is contained in:
parent
2cf10f1072
commit
7c9970cacb
4 changed files with 7 additions and 201 deletions
|
@ -106,9 +106,6 @@ class AudioEncoderOpusImpl final : public AudioEncoder {
|
|||
// RingRTC change to configure opus
|
||||
bool Configure(const webrtc::AudioEncoder::Config& config) override;
|
||||
|
||||
// RingRTC change to add low bitrate redundancy
|
||||
void Clear() { input_buffer_.clear(); }
|
||||
|
||||
// Getters for testing.
|
||||
float packet_loss_rate() const { return packet_loss_rate_; }
|
||||
AudioEncoderOpusConfig::ApplicationMode application() const {
|
||||
|
|
|
@ -20,10 +20,6 @@
|
|||
#include "rtc_base/checks.h"
|
||||
#include "rtc_base/logging.h"
|
||||
|
||||
// RingRTC change to add low bitrate redundancy
|
||||
#include "rtc_base/experiments/field_trial_parser.h"
|
||||
#include "system_wrappers/include/field_trial.h"
|
||||
|
||||
namespace webrtc {
|
||||
static constexpr const int kRedMaxPacketSize =
|
||||
1 << 10; // RED packets must be less than 1024 bytes to fit the 10 bit
|
||||
|
@ -60,12 +56,7 @@ AudioEncoderCopyRed::AudioEncoderCopyRed(Config&& config,
|
|||
: speech_encoder_(std::move(config.speech_encoder)),
|
||||
primary_encoded_(0, kAudioMaxRtpPacketLen),
|
||||
max_packet_length_(kAudioMaxRtpPacketLen),
|
||||
red_payload_type_(config.payload_type),
|
||||
// RingRTC change to add low bitrate redundancy
|
||||
use_lbred_(false),
|
||||
use_loss_primary_(true),
|
||||
use_loss_secondary_(false),
|
||||
secondary_encoded_(0, kAudioMaxRtpPacketLen) {
|
||||
red_payload_type_(config.payload_type) {
|
||||
RTC_CHECK(speech_encoder_) << "Speech encoder not provided.";
|
||||
|
||||
auto number_of_redundant_encodings =
|
||||
|
@ -75,79 +66,10 @@ AudioEncoderCopyRed::AudioEncoderCopyRed(Config&& config,
|
|||
redundant.second.EnsureCapacity(kAudioMaxRtpPacketLen);
|
||||
redundant_encodings_.push_front(std::move(redundant));
|
||||
}
|
||||
|
||||
// RingRTC change to add low bitrate redundancy
|
||||
ConfigureLBRedExperiment();
|
||||
}
|
||||
|
||||
AudioEncoderCopyRed::~AudioEncoderCopyRed() = default;
|
||||
|
||||
// RingRTC change to add low bitrate redundancy
|
||||
void AudioEncoderCopyRed::ConfigureLBRedExperiment() {
|
||||
constexpr char kFieldTrialName[] = "RingRTC-Audio-LBRed-For-Opus";
|
||||
|
||||
if (field_trial::IsEnabled(kFieldTrialName)) {
|
||||
FieldTrialFlag enabled("Enabled", false);
|
||||
|
||||
// Default values are from the best results during testing.
|
||||
FieldTrialParameter<bool> cbr("cbr", true);
|
||||
FieldTrialParameter<bool> dtx("dtx", false);
|
||||
FieldTrialConstrained<int> complexity("complexity", 4, 0, 10);
|
||||
FieldTrialConstrained<int> bandwidth("bandwidth", 1103, -1000, 1105);
|
||||
FieldTrialConstrained<int> bitrate("bitrate", 10000, 6000, 40000);
|
||||
FieldTrialConstrained<int> ptime("ptime", 60, 20, 120);
|
||||
FieldTrialParameter<bool> loss_pri("loss_pri", true);
|
||||
FieldTrialParameter<bool> loss_sec("loss_sec", false);
|
||||
FieldTrialConstrained<int> bitrate_pri("bitrate_pri", 22000, 6000, 40000);
|
||||
|
||||
ParseFieldTrial(
|
||||
{&enabled,&cbr,&dtx,&complexity,&bandwidth,
|
||||
&bitrate,&ptime,&loss_pri,&loss_sec,&bitrate_pri},
|
||||
field_trial::FindFullName(kFieldTrialName));
|
||||
|
||||
RTC_LOG(LS_WARNING) << "ConfigureLBRedExperiment:"
|
||||
<< " cbr: " << cbr.Get()
|
||||
<< ", dtx: " << dtx.Get()
|
||||
<< ", complexity: " << complexity.Get()
|
||||
<< ", bandwidth: " << bandwidth.Get()
|
||||
<< ", bitrate: " << bitrate.Get()
|
||||
<< ", ptime: " << ptime.Get()
|
||||
<< ", loss_pri: " << loss_pri.Get()
|
||||
<< ", loss_sec: " << loss_sec.Get()
|
||||
<< ", bitrate_pri: " << bitrate_pri.Get();
|
||||
|
||||
use_lbred_ = true;
|
||||
use_loss_primary_ = loss_pri.Get();
|
||||
use_loss_secondary_ = loss_sec.Get();
|
||||
bitrate_primary_ = bitrate_pri.Get();
|
||||
|
||||
AudioEncoderOpusConfig config;
|
||||
constexpr int opus_payload_type = 102;
|
||||
|
||||
speech_encoder_secondary_ = std::make_unique<AudioEncoderOpusImpl>(config, opus_payload_type);
|
||||
|
||||
webrtc::AudioEncoder::Config config_secondary;
|
||||
config_secondary.enable_cbr = cbr.Get();
|
||||
config_secondary.enable_dtx = dtx.Get();
|
||||
config_secondary.complexity = complexity.Get();
|
||||
config_secondary.bandwidth = bandwidth.Get();
|
||||
config_secondary.initial_bitrate_bps = bitrate.Get();
|
||||
config_secondary.initial_packet_size_ms = ptime.Get();
|
||||
|
||||
// Fields that don't change for redundancy.
|
||||
config_secondary.min_bitrate_bps = config_secondary.initial_bitrate_bps;
|
||||
config_secondary.max_bitrate_bps = config_secondary.initial_bitrate_bps;
|
||||
config_secondary.min_packet_size_ms = config_secondary.initial_packet_size_ms;
|
||||
config_secondary.max_packet_size_ms = config_secondary.initial_packet_size_ms;
|
||||
config_secondary.enable_fec = false;
|
||||
config_secondary.adaptation = 0;
|
||||
|
||||
speech_encoder_secondary_->Configure(config_secondary);
|
||||
|
||||
last_packet_speech_ = false;
|
||||
}
|
||||
}
|
||||
|
||||
int AudioEncoderCopyRed::SampleRateHz() const {
|
||||
return speech_encoder_->SampleRateHz();
|
||||
}
|
||||
|
@ -182,63 +104,6 @@ AudioEncoder::EncodedInfo AudioEncoderCopyRed::EncodeImpl(
|
|||
RTC_CHECK(info.redundant.empty()) << "Cannot use nested redundant encoders.";
|
||||
RTC_DCHECK_EQ(primary_encoded_.size(), info.encoded_bytes);
|
||||
|
||||
// RingRTC change to add low bitrate redundancy
|
||||
bool use_secondary = false;
|
||||
|
||||
if (info.send_even_if_empty) {
|
||||
RTC_LOG(LS_VERBOSE) << "info encoded_bytes: " << info.encoded_bytes
|
||||
<< ", encoded_timestamp: " << info.encoded_timestamp
|
||||
<< ", payload_type: " << info.payload_type
|
||||
<< ", speech: " << info.speech
|
||||
<< ", encoder_type: " << info.encoder_type;
|
||||
}
|
||||
|
||||
// We will pre-fill the buffers of the secondary encoder every time. This
|
||||
// function is called every 10ms, so the encoder needs to be ready for the
|
||||
// actual encoding when a complete packet is collected. If it turns out
|
||||
// that the primary did not encode speech, the secondary encoder will be
|
||||
// cleared.
|
||||
|
||||
EncodedInfo info_secondary;
|
||||
|
||||
if (use_lbred_) {
|
||||
// The secondary encoder is enabled.
|
||||
secondary_encoded_.Clear();
|
||||
|
||||
if (info.send_even_if_empty) {
|
||||
// The primary encoder has completed an encoding (N * 10ms).
|
||||
|
||||
// We only want to encode with the secondary when the primary encoder
|
||||
// detects speech OR the last packet was speech and the current primary
|
||||
// encoding includes at least _some_ speech.
|
||||
if (info.speech || (last_packet_speech_ && info.encoded_bytes > 2)) {
|
||||
// We have the final primary encoding AND it is speech.
|
||||
info_secondary = speech_encoder_secondary_->Encode(rtp_timestamp, audio, &secondary_encoded_);
|
||||
if (info.send_even_if_empty != info_secondary.send_even_if_empty) {
|
||||
// This should currently be impossible, but check for now.
|
||||
RTC_LOG(LS_ERROR) << "Primary and secondary encoders are NOT IN SYNC!";
|
||||
} else {
|
||||
use_secondary = true;
|
||||
|
||||
RTC_LOG(LS_VERBOSE) << "info_secondary encoded_bytes: " << info_secondary.encoded_bytes
|
||||
<< ", encoded_timestamp: " << info_secondary.encoded_timestamp
|
||||
<< ", payload_type: " << info_secondary.payload_type
|
||||
<< ", speech: " << info_secondary.speech
|
||||
<< ", encoder_type: " << info_secondary.encoder_type;
|
||||
}
|
||||
} else {
|
||||
// We have the final primary encoding AND it is NOT speech. Clear the
|
||||
// secondary encoder to and be ready for the next packet.
|
||||
speech_encoder_secondary_->Clear();
|
||||
}
|
||||
|
||||
last_packet_speech_ = info.speech;
|
||||
} else {
|
||||
// Pre-fill the secondary encoder's buffer to be ready for encoding.
|
||||
info_secondary = speech_encoder_secondary_->Encode(rtp_timestamp, audio, &secondary_encoded_);
|
||||
}
|
||||
}
|
||||
|
||||
if (info.encoded_bytes == 0) {
|
||||
return info;
|
||||
}
|
||||
|
@ -312,22 +177,9 @@ AudioEncoder::EncodedInfo AudioEncoderCopyRed::EncodeImpl(
|
|||
rit->second.SetData(next->second);
|
||||
}
|
||||
it = redundant_encodings_.begin();
|
||||
|
||||
// RingRTC change to add low bitrate redundancy
|
||||
if (use_lbred_) {
|
||||
if (use_secondary) {
|
||||
// Store the secondary encoder's result as redundant data.
|
||||
if (it != redundant_encodings_.end()) {
|
||||
it->first = info_secondary;
|
||||
it->second.SetData(secondary_encoded_);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Store the primary encoder's result as redundant data.
|
||||
if (it != redundant_encodings_.end()) {
|
||||
it->first = info;
|
||||
it->second.SetData(primary_encoded_);
|
||||
}
|
||||
if (it != redundant_encodings_.end()) {
|
||||
it->first = info;
|
||||
it->second.SetData(primary_encoded_);
|
||||
}
|
||||
|
||||
// Update main EncodedInfo.
|
||||
|
@ -338,10 +190,6 @@ AudioEncoder::EncodedInfo AudioEncoderCopyRed::EncodeImpl(
|
|||
|
||||
void AudioEncoderCopyRed::Reset() {
|
||||
speech_encoder_->Reset();
|
||||
// RingRTC change to add low bitrate redundancy
|
||||
if (use_lbred_) {
|
||||
speech_encoder_secondary_->Reset();
|
||||
}
|
||||
auto number_of_redundant_encodings = redundant_encodings_.size();
|
||||
redundant_encodings_.clear();
|
||||
for (size_t i = 0; i < number_of_redundant_encodings; i++) {
|
||||
|
@ -383,15 +231,8 @@ void AudioEncoderCopyRed::DisableAudioNetworkAdaptor() {
|
|||
|
||||
void AudioEncoderCopyRed::OnReceivedUplinkPacketLossFraction(
|
||||
float uplink_packet_loss_fraction) {
|
||||
// RingRTC change to add low bitrate redundancy
|
||||
if (use_loss_primary_) {
|
||||
speech_encoder_->OnReceivedUplinkPacketLossFraction(
|
||||
uplink_packet_loss_fraction);
|
||||
}
|
||||
if (use_loss_secondary_) {
|
||||
speech_encoder_secondary_->OnReceivedUplinkPacketLossFraction(
|
||||
uplink_packet_loss_fraction);
|
||||
}
|
||||
speech_encoder_->OnReceivedUplinkPacketLossFraction(
|
||||
uplink_packet_loss_fraction);
|
||||
}
|
||||
|
||||
void AudioEncoderCopyRed::OnReceivedUplinkBandwidth(
|
||||
|
@ -437,19 +278,7 @@ AudioEncoderCopyRed::ReclaimContainedEncoders() {
|
|||
|
||||
// RingRTC change to configure opus (the only codec we use RED with)
|
||||
bool AudioEncoderCopyRed::Configure(const webrtc::AudioEncoder::Config& config) {
|
||||
if (use_lbred_) {
|
||||
webrtc::AudioEncoder::Config new_config = config;
|
||||
|
||||
// Override some configuration parameters if using LBRED.
|
||||
new_config.initial_bitrate_bps = bitrate_primary_;
|
||||
new_config.min_bitrate_bps = bitrate_primary_;
|
||||
new_config.max_bitrate_bps = bitrate_primary_;
|
||||
new_config.enable_fec = false;
|
||||
|
||||
return speech_encoder_->Configure(new_config);
|
||||
} else {
|
||||
return speech_encoder_->Configure(config);
|
||||
}
|
||||
return speech_encoder_->Configure(config);
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
|
|
|
@ -25,9 +25,6 @@
|
|||
#include "api/units/time_delta.h"
|
||||
#include "rtc_base/buffer.h"
|
||||
|
||||
// RingRTC change to add low bitrate redundancy
|
||||
#include "modules/audio_coding/codecs/opus/audio_encoder_opus.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// This class implements redundant audio coding as described in
|
||||
|
@ -101,16 +98,6 @@ class AudioEncoderCopyRed final : public AudioEncoder {
|
|||
size_t max_packet_length_;
|
||||
int red_payload_type_;
|
||||
std::list<std::pair<EncodedInfo, rtc::Buffer>> redundant_encodings_;
|
||||
|
||||
// RingRTC change to add low bitrate redundancy
|
||||
void ConfigureLBRedExperiment();
|
||||
bool use_lbred_;
|
||||
bool use_loss_primary_;
|
||||
bool use_loss_secondary_;
|
||||
int bitrate_primary_;
|
||||
std::unique_ptr<AudioEncoderOpusImpl> speech_encoder_secondary_;
|
||||
rtc::Buffer secondary_encoded_;
|
||||
bool last_packet_speech_;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include "rffi/src/stats_observer.h"
|
||||
#include "rtc_base/message_digest.h"
|
||||
#include "rtc_base/string_encode.h"
|
||||
#include "system_wrappers/include/field_trial.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
@ -366,12 +365,6 @@ Rust_sessionDescriptionFromV4(bool offer,
|
|||
auto opus_red = cricket::CreateAudioCodec(OPUS_RED_PT, cricket::kRedCodecName, 48000, 2);
|
||||
opus_red.SetParam("", std::to_string(OPUS_PT) + "/" + std::to_string(OPUS_PT));
|
||||
|
||||
// If the LBRED field trial is enabled, force RED.
|
||||
constexpr char kFieldTrialName[] = "RingRTC-Audio-LBRed-For-Opus";
|
||||
if (field_trial::IsEnabled(kFieldTrialName)) {
|
||||
enable_red_audio = true;
|
||||
}
|
||||
|
||||
if (enable_red_audio) {
|
||||
// Add RED before Opus to use it by default when sending.
|
||||
audio->AddCodec(opus_red);
|
||||
|
|
Loading…
Reference in a new issue