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

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

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

Powered by Google App Engine
This is Rietveld 408576698