Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/modules/video_coding/codec_timer.h" | 11 #include "webrtc/modules/video_coding/codec_timer.h" |
| 12 | 12 |
| 13 #include <assert.h> | |
| 14 | |
| 15 namespace webrtc { | 13 namespace webrtc { |
| 16 | 14 |
| 17 // The first kIgnoredSampleCount samples will be ignored. | 15 // The first kIgnoredSampleCount samples will be ignored. |
| 18 static const int32_t kIgnoredSampleCount = 5; | 16 static const int32_t kIgnoredSampleCount = 5; |
|
philipel
2016/03/03 13:34:31
Move all static variables into a namespace { ... }
magjed_webrtc
2016/03/04 14:19:41
Done.
| |
| 17 // Return the |kPercentile| value in RequiredDecodeTimeMs(). | |
| 18 static const float kPercentile = 0.95f; | |
| 19 // The window size in ms. | |
| 20 static const int64_t kTimeLimitMs = 10000; | |
| 19 | 21 |
| 20 VCMCodecTimer::VCMCodecTimer() | 22 VCMCodecTimer::VCMCodecTimer() : ignoredSampleCount_(0), filter_(kPercentile) {} |
| 21 : _filteredMax(0), _ignoredSampleCount(0), _shortMax(0), _history() { | 23 |
| 22 Reset(); | 24 void VCMCodecTimer::Reset() { |
| 25 ignoredSampleCount_ = 0; | |
| 26 while (!history_.empty()) | |
| 27 history_.pop(); | |
| 28 filter_.Clear(); | |
| 23 } | 29 } |
| 24 | 30 |
| 25 void VCMCodecTimer::Reset() { | 31 void VCMCodecTimer::MaxFilter(int32_t decode_time_ms, int64_t now_ms) { |
|
philipel
2016/03/03 13:34:31
int64_t
magjed_webrtc
2016/03/04 14:19:41
Done.
| |
| 26 _filteredMax = 0; | 32 // Ignore the first |kIgnoredSampleCount| samples. |
| 27 _ignoredSampleCount = 0; | 33 if (ignoredSampleCount_ < kIgnoredSampleCount) { |
| 28 _shortMax = 0; | 34 ++ignoredSampleCount_; |
| 29 for (int i = 0; i < MAX_HISTORY_SIZE; i++) { | |
| 30 _history[i].shortMax = 0; | |
| 31 _history[i].timeMs = -1; | |
| 32 } | |
| 33 } | |
| 34 | |
| 35 // Update the max-value filter | |
| 36 void VCMCodecTimer::MaxFilter(int32_t decodeTime, int64_t nowMs) { | |
| 37 if (_ignoredSampleCount >= kIgnoredSampleCount) { | |
| 38 UpdateMaxHistory(decodeTime, nowMs); | |
| 39 ProcessHistory(nowMs); | |
| 40 } else { | |
| 41 _ignoredSampleCount++; | |
| 42 } | |
| 43 } | |
| 44 | |
| 45 void VCMCodecTimer::UpdateMaxHistory(int32_t decodeTime, int64_t now) { | |
| 46 if (_history[0].timeMs >= 0 && now - _history[0].timeMs < SHORT_FILTER_MS) { | |
| 47 if (decodeTime > _shortMax) { | |
| 48 _shortMax = decodeTime; | |
| 49 } | |
| 50 } else { | |
| 51 // Only add a new value to the history once a second | |
| 52 if (_history[0].timeMs == -1) { | |
| 53 // First, no shift | |
| 54 _shortMax = decodeTime; | |
| 55 } else { | |
| 56 // Shift | |
| 57 for (int i = (MAX_HISTORY_SIZE - 2); i >= 0; i--) { | |
| 58 _history[i + 1].shortMax = _history[i].shortMax; | |
| 59 _history[i + 1].timeMs = _history[i].timeMs; | |
| 60 } | |
| 61 } | |
| 62 if (_shortMax == 0) { | |
| 63 _shortMax = decodeTime; | |
| 64 } | |
| 65 | |
| 66 _history[0].shortMax = _shortMax; | |
| 67 _history[0].timeMs = now; | |
| 68 _shortMax = 0; | |
| 69 } | |
| 70 } | |
| 71 | |
| 72 void VCMCodecTimer::ProcessHistory(int64_t nowMs) { | |
| 73 _filteredMax = _shortMax; | |
| 74 if (_history[0].timeMs == -1) { | |
| 75 return; | 35 return; |
| 76 } | 36 } |
| 77 for (int i = 0; i < MAX_HISTORY_SIZE; i++) { | 37 |
| 78 if (_history[i].timeMs == -1) { | 38 // Insert new decode time value. |
| 79 break; | 39 filter_.Insert(decode_time_ms); |
| 80 } | 40 history_.emplace(decode_time_ms, now_ms); |
| 81 if (nowMs - _history[i].timeMs > MAX_HISTORY_SIZE * SHORT_FILTER_MS) { | 41 |
| 82 // This sample (and all samples after this) is too old | 42 // Pop old decode time values. |
| 83 break; | 43 while (!history_.empty() && |
| 84 } | 44 now_ms - history_.front().sample_time_ms > kTimeLimitMs) { |
| 85 if (_history[i].shortMax > _filteredMax) { | 45 filter_.Erase(history_.front().decode_time_ms); |
| 86 // This sample is the largest one this far into the history | 46 history_.pop(); |
| 87 _filteredMax = _history[i].shortMax; | |
| 88 } | |
| 89 } | 47 } |
| 90 } | 48 } |
| 91 | 49 |
| 92 // Get the maximum observed time within a time window | 50 // Get the maximum observed time within a time window |
|
philipel
2016/03/03 13:34:31
Update comment about the 95th percentile stuff.
magjed_webrtc
2016/03/04 14:19:41
Done.
| |
| 93 int32_t VCMCodecTimer::RequiredDecodeTimeMs(FrameType /*frameType*/) const { | 51 int32_t VCMCodecTimer::RequiredDecodeTimeMs(FrameType /*frameType*/) const { |
| 94 return _filteredMax; | 52 return filter_.GetPercentileValue(); |
| 95 } | 53 } |
| 54 | |
| 55 VCMCodecTimer::Sample::Sample(int32_t decode_time_ms, int64_t sample_time_ms) | |
| 56 : decode_time_ms(decode_time_ms), sample_time_ms(sample_time_ms) {} | |
| 57 | |
| 96 } // namespace webrtc | 58 } // namespace webrtc |
| OLD | NEW |