 Chromium Code Reviews
 Chromium Code Reviews Issue 2334613002:
  Adding BitrateController to audio network adaptor.  (Closed)
    
  
    Issue 2334613002:
  Adding BitrateController to audio network adaptor.  (Closed) 
  | OLD | NEW | 
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | |
| 3 * | |
| 4 * Use of this source code is governed by a BSD-style license | |
| 5 * that can be found in the LICENSE file in the root of the source | |
| 6 * tree. An additional intellectual property rights grant can be found | |
| 7 * in the file PATENTS. All contributing project authors may | |
| 8 * be found in the AUTHORS file in the root of the source tree. | |
| 9 */ | |
| 10 | |
| 11 #include <algorithm> | |
| 12 | |
| 13 #include "webrtc/modules/audio_coding/audio_network_adaptor/bitrate_controller.h " | |
| 
hlundin-webrtc
2016/09/15 11:01:09
Goes before any other #includes.
 
minyue-webrtc
2016/09/15 12:12:15
oh, really! I have been putting <xxx> at the top.
 
hlundin-webrtc
2016/09/19 11:08:57
Yes. Include foo.h first of all in foo.cc. https:/
 | |
| 14 | |
| 15 #include "webrtc/base/checks.h" | |
| 16 | |
| 17 namespace webrtc { | |
| 18 | |
| 19 namespace { | |
| 20 // L2(14B) + IPv4(20B) + UDP(8B) + RTP(12B) + SRTP_AUTH(10B) = 64B = 512 bits | |
| 
hlundin-webrtc
2016/09/15 11:01:09
This is dependent on transport type. Can it be mad
 
minyue-webrtc
2016/09/15 12:12:15
I'd prefer to keep it local since there is an effo
 
hlundin-webrtc
2016/09/19 11:08:57
Acknowledged.
 
minyue-webrtc
2016/09/19 13:16:30
I discussed this with Michael again and realized t
 | |
| 21 constexpr int kPacketOverheadBits = 512; | |
| 22 } | |
| 23 | |
| 24 BitrateController::Config::Config(int initial_bitrate_bps, | |
| 25 int initial_frame_length_ms) | |
| 26 : initial_bitrate_bps(initial_bitrate_bps), | |
| 27 initial_frame_length_ms(initial_frame_length_ms) {} | |
| 28 | |
| 29 BitrateController::Config::~Config() = default; | |
| 30 | |
| 31 BitrateController::BitrateController(const Config& config) | |
| 32 : config_(config), | |
| 33 bitrate_bps_(config_.initial_bitrate_bps), | |
| 34 overhead_rate_bps_(kPacketOverheadBits * 1000 / | |
| 35 config_.initial_frame_length_ms) { | |
| 36 RTC_DCHECK_GT(bitrate_bps_, 0); | |
| 37 RTC_DCHECK_GT(overhead_rate_bps_, 0); | |
| 38 } | |
| 39 | |
| 40 void BitrateController::MakeDecision( | |
| 41 const NetworkMetrics& metrics, | |
| 42 AudioNetworkAdaptor::EncoderRuntimeConfig* config) { | |
| 43 // Decision on |bitrate_bps| should not have been made. | |
| 44 RTC_DCHECK(!config->bitrate_bps); | |
| 45 | |
| 46 if (metrics.target_audio_bitrate_bps) { | |
| 47 int overhead_rate = | |
| 48 config->frame_length_ms | |
| 49 ? kPacketOverheadBits * 1000 / *config->frame_length_ms | |
| 50 : overhead_rate_bps_; | |
| 51 // If |metrics.target_audio_bitrate_bps| had included overhead, we would | |
| 52 // simply do: | |
| 53 // bitrate_bps_ = metrics.target_audio_bitrate_bps - overhead_rate; | |
| 54 // Follow https://bugs.chromium.org/p/webrtc/issues/detail?id=6315 to track | |
| 55 // progress regarding this. | |
| 56 // Now we assume that |metrics.target_audio_bitrate_bps| can handle the | |
| 57 // overhead of most recent packets. | |
| 58 bitrate_bps_ = std::max(0, *metrics.target_audio_bitrate_bps + | |
| 59 overhead_rate_bps_ - overhead_rate); | |
| 60 // TODO(minyue): apply a smoothing on the |overhead_rate_bps_|. | |
| 61 overhead_rate_bps_ = overhead_rate; | |
| 62 } | |
| 63 config->bitrate_bps = rtc::Optional<int>(bitrate_bps_); | |
| 64 } | |
| 65 | |
| 66 } // namespace webrtc | |
| OLD | NEW |