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

Side by Side Diff: webrtc/modules/audio_coding/audio_network_adaptor/bitrate_controller.cc

Issue 2353293002: Relanding of "Adding BitrateController to audio network adaptor." (Closed)
Patch Set: rebasing Created 4 years, 2 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 unified diff | Download patch
OLDNEW
(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 "webrtc/modules/audio_coding/audio_network_adaptor/bitrate_controller.h "
12
13 #include <algorithm>
14
15 #include "webrtc/base/checks.h"
16
17 namespace webrtc {
18 namespace audio_network_adaptor {
19
20 namespace {
21 // TODO(minyue): consider passing this from a higher layer through
22 // SetConstraints().
23 // L2(14B) + IPv4(20B) + UDP(8B) + RTP(12B) + SRTP_AUTH(10B) = 64B = 512 bits
24 constexpr int kPacketOverheadBits = 512;
25 }
26
27 BitrateController::Config::Config(int initial_bitrate_bps,
28 int initial_frame_length_ms)
29 : initial_bitrate_bps(initial_bitrate_bps),
30 initial_frame_length_ms(initial_frame_length_ms) {}
31
32 BitrateController::Config::~Config() = default;
33
34 BitrateController::BitrateController(const Config& config)
35 : config_(config),
36 bitrate_bps_(config_.initial_bitrate_bps),
37 overhead_rate_bps_(kPacketOverheadBits * 1000 /
38 config_.initial_frame_length_ms) {
39 RTC_DCHECK_GT(bitrate_bps_, 0);
40 RTC_DCHECK_GT(overhead_rate_bps_, 0);
41 }
42
43 void BitrateController::MakeDecision(
44 const NetworkMetrics& metrics,
45 AudioNetworkAdaptor::EncoderRuntimeConfig* config) {
46 // Decision on |bitrate_bps| should not have been made.
47 RTC_DCHECK(!config->bitrate_bps);
48
49 if (metrics.target_audio_bitrate_bps) {
50 int overhead_rate =
51 config->frame_length_ms
52 ? kPacketOverheadBits * 1000 / *config->frame_length_ms
53 : overhead_rate_bps_;
54 // If |metrics.target_audio_bitrate_bps| had included overhead, we would
55 // simply do:
56 // bitrate_bps_ = metrics.target_audio_bitrate_bps - overhead_rate;
57 // Follow https://bugs.chromium.org/p/webrtc/issues/detail?id=6315 to track
58 // progress regarding this.
59 // Now we assume that |metrics.target_audio_bitrate_bps| can handle the
60 // overhead of most recent packets.
61 bitrate_bps_ = std::max(0, *metrics.target_audio_bitrate_bps +
62 overhead_rate_bps_ - overhead_rate);
63 // TODO(minyue): apply a smoothing on the |overhead_rate_bps_|.
64 overhead_rate_bps_ = overhead_rate;
65 }
66 config->bitrate_bps = rtc::Optional<int>(bitrate_bps_);
67 }
68
69 } // namespace audio_network_adaptor
70 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698