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

Side by Side Diff: webrtc/modules/video_coding/utility/moving_average.cc

Issue 2310853002: Refactor QualityScaler and MovingAverage (Closed)
Patch Set: 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) 2015 The WebRTC project authors. All Rights Reserved.
sakal 2016/09/05 12:28:10 You probably mean 2016.
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 */
sakal 2016/09/05 12:28:11 nit: add an empty line here
10 #include "webrtc/modules/video_coding/utility/moving_average.h"
sakal 2016/09/05 12:28:10 nit: add an empty line here
11 #include <algorithm>
12
13 namespace webrtc {
14
15 MovingAverage::MovingAverage() : MovingAverage(1024) {}
sakal 2016/09/05 12:28:11 I would leave out the default constructor. I don't
16
17 MovingAverage::MovingAverage(size_t s) : samples_(s, 0) {}
sakal 2016/09/05 12:28:11 nit: samples(s) would be enough, values are initia
18
19 void MovingAverage::AddSample(int sample) {
20 sum_ += sample;
21 count_++;
22 samples_[count_ % samples_.size()] = sum_;
23 }
24
25 int MovingAverage::GetAverage() const {
26 return GetAverage(count_ + 1);
sakal 2016/09/05 12:28:10 Why +1? I saw you commented it is an array index o
magjed_webrtc 2016/09/05 15:01:52 Yes, I'm also pretty sure this is a bug. |count_|
27 }
28
29 int MovingAverage::GetAverage(size_t num_samples) const {
sakal 2016/09/05 12:28:11 I would rather this method return rtc::Optional in
30 num_samples = std::min(num_samples, this->size());
magjed_webrtc 2016/09/05 15:01:52 Is this check really needed if you use size() in t
31 if (num_samples == 0) return 0;
32 int sum = sum_ - samples_[(count_ - num_samples) % samples_.size()];
magjed_webrtc 2016/09/05 15:01:52 nit: Use const.
33 return sum / num_samples;
sakal 2016/09/05 12:28:10 This will always round down. Is this the desired b
34 }
35
36 void MovingAverage::Reset() {
37 count_ = 0;
38 sum_ = 0;
39 std::fill(samples_.begin(), samples_.end(), 0);
sakal 2016/09/05 12:28:11 nit: This is not necessarily required because we w
40 }
41
42 size_t MovingAverage::size() const {
43 return std::min(count_, samples_.size() - 1);
44 }
sakal 2016/09/05 12:28:10 nit: add an empty line here
45 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698