Smooth BWE and pass it to Audio Network Adaptor.

BUG=webrtc:6443, webrtc:6303

Review-Url: https://codereview.webrtc.org/2503713003
Cr-Commit-Position: refs/heads/master@{#15257}
This commit is contained in:
michaelt 2016-11-28 02:34:18 -08:00 committed by Commit bot
parent 847f6897f2
commit 2fedf9c69a
5 changed files with 30 additions and 2 deletions

View File

@ -20,6 +20,7 @@ class MockSmoothingFilter : public SmoothingFilter {
public:
MOCK_METHOD1(AddSample, void(float));
MOCK_CONST_METHOD0(GetAverage, rtc::Optional<float>());
MOCK_METHOD1(SetTimeConstantMs, void(int));
};
} // namespace webrtc

View File

@ -59,4 +59,9 @@ rtc::Optional<float> SmoothingFilterImpl::GetAverage() const {
: rtc::Optional<float>(value);
}
void SmoothingFilterImpl::SetTimeConstantMs(int time_constant_ms) {
time_constant_ms_ = time_constant_ms;
filter_.UpdateBase(exp(1.0f / time_constant_ms_));
}
} // namespace webrtc

View File

@ -23,6 +23,7 @@ class SmoothingFilter {
virtual ~SmoothingFilter() = default;
virtual void AddSample(float sample) = 0;
virtual rtc::Optional<float> GetAverage() const = 0;
virtual void SetTimeConstantMs(int time_constant_ms) = 0;
};
// SmoothingFilterImpl applies an exponential filter
@ -35,9 +36,10 @@ class SmoothingFilterImpl final : public SmoothingFilter {
void AddSample(float sample) override;
rtc::Optional<float> GetAverage() const override;
void SetTimeConstantMs(int time_constant_ms) override;
private:
const int time_constant_ms_;
int time_constant_ms_;
const Clock* const clock_;
bool first_sample_received_;

View File

@ -894,7 +894,10 @@ Channel::Channel(int32_t channelId,
rtp_packet_sender_proxy_(new RtpPacketSenderProxy()),
retransmission_rate_limiter_(new RateLimiter(Clock::GetRealTimeClock(),
kMaxRetransmissionWindowMs)),
decoder_factory_(config.acm_config.decoder_factory) {
decoder_factory_(config.acm_config.decoder_factory),
// Bitrate smoother can be initialized with arbitrary time constant
// (0 used here). The actual time constant will be set in SetBitRate.
bitrate_smoother_(0, Clock::GetRealTimeClock()) {
WEBRTC_TRACE(kTraceMemory, kTraceVoice, VoEId(_instanceId, _channelId),
"Channel::Channel() - ctor");
AudioCodingModule::Config acm_config(config.acm_config);
@ -1306,6 +1309,20 @@ void Channel::SetBitRate(int bitrate_bps) {
(*encoder)->OnReceivedTargetAudioBitrate(bitrate_bps);
});
retransmission_rate_limiter_->SetMaxRate(bitrate_bps);
// We give smoothed bitrate allocation to audio network adaptor as
// the uplink bandwidth.
// TODO(michaelt) : Remove kDefaultBitrateSmoothingTimeConstantMs as soon as
// we pass the probing interval to this function.
constexpr int64_t kDefaultBitrateSmoothingTimeConstantMs = 20000;
bitrate_smoother_.SetTimeConstantMs(kDefaultBitrateSmoothingTimeConstantMs);
bitrate_smoother_.AddSample(bitrate_bps);
audio_coding_->ModifyEncoder([&](std::unique_ptr<AudioEncoder>* encoder) {
if (*encoder) {
(*encoder)->OnReceivedUplinkBandwidth(
static_cast<int>(*bitrate_smoother_.GetAverage()));
}
});
}
void Channel::OnIncomingFractionLoss(int fraction_lost) {

View File

@ -17,6 +17,7 @@
#include "webrtc/api/call/audio_sink.h"
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/optional.h"
#include "webrtc/common_audio/smoothing_filter.h"
#include "webrtc/common_audio/resampler/include/push_resampler.h"
#include "webrtc/common_types.h"
#include "webrtc/modules/audio_coding/acm2/codec_manager.h"
@ -543,6 +544,8 @@ class Channel
// TODO(ossu): Remove once GetAudioDecoderFactory() is no longer needed.
rtc::scoped_refptr<AudioDecoderFactory> decoder_factory_;
SmoothingFilterImpl bitrate_smoother_;
};
} // namespace voe