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

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: 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
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..b72d3d094c86823379130572a58a2dea15e3191a 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,23 @@ 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);
+
+ // Possible audio protection used is ignored for now.
stefan-webrtc 2016/07/20 10:14:59 Maybe rewrite as: TODO(mflodman): Return amount of
mflodman 2016/07/22 13:50:29 This information isn't available to us and would r
stefan-webrtc 2016/07/25 15:06:20 Acknowledged.
+ return 0;
minyue-webrtc 2016/07/21 10:59:19 do we need to return max_bitrate_bps - bitrate_bp
mflodman 2016/07/22 13:50:29 We should return the bitrate used for FEC, but we
minyue-webrtc 2016/07/25 14:33:47 OK, the comment on OnBitrateUpdated says " Returns
+}
+
const webrtc::AudioSendStream::Config& AudioSendStream::config() const {
RTC_DCHECK(thread_checker_.CalledOnValidThread());
return config_;

Powered by Google App Engine
This is Rietveld 408576698