Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(220)

Unified Diff: webrtc/audio/audio_send_stream.cc

Issue 2165743003: Variable audio bitrate. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/audio/audio_send_stream.h ('k') | webrtc/audio/audio_send_stream_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/audio/audio_send_stream.cc
diff --git a/webrtc/audio/audio_send_stream.cc b/webrtc/audio/audio_send_stream.cc
index d08bfeaa1ef70c43de1de0fd57f1e252966542ec..17979d5760c0a2ca9ceecf9b7ad0cb5e545d3acc 100644
--- a/webrtc/audio/audio_send_stream.cc
+++ b/webrtc/audio/audio_send_stream.cc
@@ -59,8 +59,11 @@ namespace internal {
AudioSendStream::AudioSendStream(
const webrtc::AudioSendStream::Config& config,
const rtc::scoped_refptr<webrtc::AudioState>& audio_state,
- CongestionController* congestion_controller)
- : config_(config), audio_state_(audio_state) {
+ CongestionController* congestion_controller,
+ BitrateAllocator* bitrate_allocator)
+ : config_(config),
+ audio_state_(audio_state),
+ bitrate_allocator_(bitrate_allocator) {
LOG(LS_INFO) << "AudioSendStream: " << config_.ToString();
RTC_DCHECK_NE(config_.voe_channel_id, -1);
RTC_DCHECK(audio_state_.get());
@@ -104,6 +107,12 @@ AudioSendStream::~AudioSendStream() {
void AudioSendStream::Start() {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
+ if (config_.min_bitrate_kbps != -1 && config_.max_bitrate_kbps != -1) {
+ RTC_DCHECK_GE(config_.max_bitrate_kbps, config_.min_bitrate_kbps);
+ bitrate_allocator_->AddObserver(this, config_.min_bitrate_kbps * 1000,
+ config_.max_bitrate_kbps * 1000, 0, true);
+ }
+
ScopedVoEInterface<VoEBase> base(voice_engine());
int error = base->StartSend(config_.voe_channel_id);
if (error != 0) {
@@ -113,6 +122,7 @@ void AudioSendStream::Start() {
void AudioSendStream::Stop() {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
+ bitrate_allocator_->RemoveObserver(this);
ScopedVoEInterface<VoEBase> base(voice_engine());
int error = base->StopSend(config_.voe_channel_id);
if (error != 0) {
@@ -227,6 +237,24 @@ bool AudioSendStream::DeliverRtcp(const uint8_t* packet, size_t length) {
return channel_proxy_->ReceivedRTCPPacket(packet, length);
}
+uint32_t AudioSendStream::OnBitrateUpdated(uint32_t bitrate_bps,
+ uint8_t fraction_loss,
+ int64_t rtt) {
+ RTC_DCHECK_GE(bitrate_bps,
+ static_cast<uint32_t>(config_.min_bitrate_kbps * 1000));
+ // The bitrate allocator might allocate an higher than max configured bitrate
+ // if there is room, to allow for, as example, extra FEC. Ignore that for now.
+ const uint32_t max_bitrate_bps = config_.max_bitrate_kbps * 1000;
+ if (bitrate_bps > max_bitrate_bps)
+ bitrate_bps = max_bitrate_bps;
+
+ channel_proxy_->SetBitrate(bitrate_bps);
+
+ // The amount of audio protection is not exposed by the encoder, hence
+ // always returning 0.
+ return 0;
+}
+
const webrtc::AudioSendStream::Config& AudioSendStream::config() const {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
return config_;
« no previous file with comments | « webrtc/audio/audio_send_stream.h ('k') | webrtc/audio/audio_send_stream_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698