File: remb_suppressor.cc

package info (click to toggle)
chromium-browser 41.0.2272.118-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 2,189,132 kB
  • sloc: cpp: 9,691,462; ansic: 3,341,451; python: 712,689; asm: 518,779; xml: 208,926; java: 169,820; sh: 119,353; perl: 68,907; makefile: 28,311; yacc: 13,305; objc: 11,385; tcl: 3,186; cs: 2,225; sql: 2,217; lex: 2,215; lisp: 1,349; pascal: 1,256; awk: 407; ruby: 155; sed: 53; php: 14; exp: 11
file content (121 lines) | stat: -rw-r--r-- 3,640 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
 *  Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
 *
 *  Use of this source code is governed by a BSD-style license
 *  that can be found in the LICENSE file in the root of the source
 *  tree. An additional intellectual property rights grant can be found
 *  in the file PATENTS.  All contributing project authors may
 *  be found in the AUTHORS file in the root of the source tree.
 *
 */

#include "webrtc/modules/bitrate_controller/remb_suppressor.h"

#include <math.h>

#include "webrtc/system_wrappers/interface/field_trial.h"

namespace webrtc {

// If BWE falls more than this fraction from one REMB to the next,
// classify this as a glitch.
static const double kMaxBweDropRatio = 0.45;

// If we are sending less then this fraction of the last REMB when a glitch
// is detected, start suppressing REMB.
static const double kMinSendBitrateFraction = 0.75;

// Minimum fractional BWE growth per second needed to keep suppressing.
static const double kMinGrowth = 0.015;

RembSuppressor::RembSuppressor(Clock* clock)
    : enabled_(false),
      clock_(clock),
      last_remb_bps_(0),
      bitrate_sent_bps_(0),
      last_remb_ignored_bps_(0),
      last_remb_ignore_time_ms_(0),
      remb_silence_start_(0) {
}

RembSuppressor::~RembSuppressor() {
}

bool RembSuppressor::SuppresNewRemb(uint32_t bitrate_bps) {
  if (!Enabled())
    return false;

  if (remb_silence_start_ == 0) {
    // Not currently suppressing. Check if there is a bit rate drop
    // significant enough to warrant suppression.
    return StartSuppressing(bitrate_bps);
  }

  // Check if signs point to recovery, otherwise back off suppression.
  if (!ContinueSuppressing(bitrate_bps)) {
    remb_silence_start_ = 0;
    last_remb_ignored_bps_ = 0;
    last_remb_ignore_time_ms_ = 0;
    return false;
  }
  return true;
}

bool RembSuppressor::StartSuppressing(uint32_t bitrate_bps) {
  if (bitrate_bps <
      static_cast<uint32_t>(last_remb_bps_ * kMaxBweDropRatio + 0.5)) {
    if (bitrate_sent_bps_ <
        static_cast<uint32_t>(last_remb_bps_ * kMinSendBitrateFraction + 0.5)) {
      int64_t now = clock_->TimeInMilliseconds();
      remb_silence_start_ = now;
      last_remb_ignore_time_ms_ = now;
      last_remb_ignored_bps_ = bitrate_bps;
      return true;
    }
  }
  last_remb_bps_ = bitrate_bps;
  return false;
}

bool RembSuppressor::ContinueSuppressing(uint32_t bitrate_bps) {
  int64_t now = clock_->TimeInMilliseconds();

  if (bitrate_bps >= last_remb_bps_) {
    // We have fully recovered, stop suppressing!
    return false;
  }

  // If exactly the same REMB, we probably don't have a new estimate. Keep on
  // suppressing. However, if REMB is going down or just not increasing fast
  // enough (kMinGrowth = 0.015 => REMB should increase by at least 1.5% / s)
  // it looks like the link capacity has actually deteriorated and we are
  // currently over-utilizing; back off.
  if (bitrate_bps != last_remb_ignored_bps_) {
    double delta_t = (now - last_remb_ignore_time_ms_) / 1000.0;
    double min_increase = pow(1.0 + kMinGrowth, delta_t);
    if (bitrate_bps < last_remb_ignored_bps_ * min_increase) {
      return false;
    }
  }

  last_remb_ignored_bps_ = bitrate_bps;
  last_remb_ignore_time_ms_ = now;

  return true;
}

void RembSuppressor::SetBitrateSent(uint32_t bitrate_bps) {
  bitrate_sent_bps_ = bitrate_bps;
}

bool RembSuppressor::Enabled() {
  return enabled_;
}

void RembSuppressor::SetEnabled(bool enabled) {
  enabled_ = enabled &&
             webrtc::field_trial::FindFullName(
                 "WebRTC-ConditionalRembSuppression") == "Enabled";
}

}  // namespace webrtc