Revert "Revert of Implement the NackModule as part of the new jitter buffer. (patchset #19 id:360001 of https://codereview.webrtc.org/1715673002/ )"

This reverts commit eb648bf0e5a9bae185bcd6b4b3be371e1da3507d.

Re-reverting to fix original CL (https://codereview.webrtc.org/1715673002/).

TBR=stefan@webrtc.org, tommi@webrtc.org, torbjorng@webrtc.org

BUG=webrtc:5514

Review URL: https://codereview.webrtc.org/1769113003

Cr-Commit-Position: refs/heads/master@{#11904}
This commit is contained in:
philipel
2016-03-08 03:36:15 -08:00
committed by Commit bot
parent 55480f5efa
commit 5ab4c6d7e0
13 changed files with 1157 additions and 0 deletions

View File

@ -0,0 +1,62 @@
/*
* Copyright (c) 2016 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/video_coding/histogram.h"
#include <algorithm>
#include "webrtc/base/mod_ops.h"
namespace webrtc {
namespace video_coding {
Histogram::Histogram(size_t num_buckets, size_t max_num_values) {
RTC_DCHECK_GT(num_buckets, 0u);
RTC_DCHECK_GT(max_num_values, 0u);
buckets_.resize(num_buckets);
values_.reserve(max_num_values);
index_ = 0;
}
void Histogram::Add(size_t value) {
RTC_DCHECK_GE(value, 0u);
value = std::min<size_t>(value, buckets_.size() - 1);
if (index_ < values_.size()) {
--buckets_[values_[index_]];
RTC_DCHECK_LT(values_[index_], buckets_.size());
values_[index_] = value;
} else {
values_.emplace_back(value);
}
++buckets_[value];
index_ = (index_ + 1) % values_.capacity();
}
size_t Histogram::InverseCdf(float probability) const {
RTC_DCHECK_GE(probability, 0.f);
RTC_DCHECK_LE(probability, 1.f);
RTC_DCHECK_GT(values_.size(), 0ul);
size_t bucket = 0;
float accumulated_probability = 0;
while (accumulated_probability < probability && bucket < buckets_.size()) {
accumulated_probability +=
static_cast<float>(buckets_[bucket]) / values_.size();
++bucket;
}
return bucket;
}
size_t Histogram::NumValues() const {
return values_.size();
}
} // namespace video_coding
} // namespace webrtc