| 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> | 13 #include <assert.h> |
| 14 | 14 |
| 15 namespace webrtc | 15 namespace webrtc { |
| 16 { | |
| 17 | 16 |
| 18 // The first kIgnoredSampleCount samples will be ignored. | 17 // The first kIgnoredSampleCount samples will be ignored. |
| 19 static const int32_t kIgnoredSampleCount = 5; | 18 static const int32_t kIgnoredSampleCount = 5; |
| 20 | 19 |
| 21 VCMCodecTimer::VCMCodecTimer() | 20 VCMCodecTimer::VCMCodecTimer() |
| 22 : | 21 : _filteredMax(0), _ignoredSampleCount(0), _shortMax(0), _history() { |
| 23 _filteredMax(0), | 22 Reset(); |
| 24 _ignoredSampleCount(0), | |
| 25 _shortMax(0), | |
| 26 _history() | |
| 27 { | |
| 28 Reset(); | |
| 29 } | 23 } |
| 30 | 24 |
| 31 void VCMCodecTimer::Reset() | 25 void VCMCodecTimer::Reset() { |
| 32 { | 26 _filteredMax = 0; |
| 33 _filteredMax = 0; | 27 _ignoredSampleCount = 0; |
| 34 _ignoredSampleCount = 0; | 28 _shortMax = 0; |
| 35 _shortMax = 0; | 29 for (int i = 0; i < MAX_HISTORY_SIZE; i++) { |
| 36 for (int i=0; i < MAX_HISTORY_SIZE; i++) | 30 _history[i].shortMax = 0; |
| 37 { | 31 _history[i].timeMs = -1; |
| 38 _history[i].shortMax = 0; | 32 } |
| 39 _history[i].timeMs = -1; | |
| 40 } | |
| 41 } | 33 } |
| 42 | 34 |
| 43 // Update the max-value filter | 35 // Update the max-value filter |
| 44 void VCMCodecTimer::MaxFilter(int32_t decodeTime, int64_t nowMs) | 36 void VCMCodecTimer::MaxFilter(int32_t decodeTime, int64_t nowMs) { |
| 45 { | 37 if (_ignoredSampleCount >= kIgnoredSampleCount) { |
| 46 if (_ignoredSampleCount >= kIgnoredSampleCount) | 38 UpdateMaxHistory(decodeTime, nowMs); |
| 47 { | 39 ProcessHistory(nowMs); |
| 48 UpdateMaxHistory(decodeTime, nowMs); | 40 } else { |
| 49 ProcessHistory(nowMs); | 41 _ignoredSampleCount++; |
| 50 } | 42 } |
| 51 else | |
| 52 { | |
| 53 _ignoredSampleCount++; | |
| 54 } | |
| 55 } | 43 } |
| 56 | 44 |
| 57 void | 45 void VCMCodecTimer::UpdateMaxHistory(int32_t decodeTime, int64_t now) { |
| 58 VCMCodecTimer::UpdateMaxHistory(int32_t decodeTime, int64_t now) | 46 if (_history[0].timeMs >= 0 && now - _history[0].timeMs < SHORT_FILTER_MS) { |
| 59 { | 47 if (decodeTime > _shortMax) { |
| 60 if (_history[0].timeMs >= 0 && | 48 _shortMax = decodeTime; |
| 61 now - _history[0].timeMs < SHORT_FILTER_MS) | |
| 62 { | |
| 63 if (decodeTime > _shortMax) | |
| 64 { | |
| 65 _shortMax = decodeTime; | |
| 66 } | |
| 67 } | 49 } |
| 68 else | 50 } else { |
| 69 { | 51 // Only add a new value to the history once a second |
| 70 // Only add a new value to the history once a second | 52 if (_history[0].timeMs == -1) { |
| 71 if(_history[0].timeMs == -1) | 53 // First, no shift |
| 72 { | 54 _shortMax = decodeTime; |
| 73 // First, no shift | 55 } else { |
| 74 _shortMax = decodeTime; | 56 // Shift |
| 75 } | 57 for (int i = (MAX_HISTORY_SIZE - 2); i >= 0; i--) { |
| 76 else | 58 _history[i + 1].shortMax = _history[i].shortMax; |
| 77 { | 59 _history[i + 1].timeMs = _history[i].timeMs; |
| 78 // Shift | 60 } |
| 79 for(int i = (MAX_HISTORY_SIZE - 2); i >= 0 ; i--) | 61 } |
| 80 { | 62 if (_shortMax == 0) { |
| 81 _history[i+1].shortMax = _history[i].shortMax; | 63 _shortMax = decodeTime; |
| 82 _history[i+1].timeMs = _history[i].timeMs; | 64 } |
| 83 } | |
| 84 } | |
| 85 if (_shortMax == 0) | |
| 86 { | |
| 87 _shortMax = decodeTime; | |
| 88 } | |
| 89 | 65 |
| 90 _history[0].shortMax = _shortMax; | 66 _history[0].shortMax = _shortMax; |
| 91 _history[0].timeMs = now; | 67 _history[0].timeMs = now; |
| 92 _shortMax = 0; | 68 _shortMax = 0; |
| 93 } | 69 } |
| 94 } | 70 } |
| 95 | 71 |
| 96 void | 72 void VCMCodecTimer::ProcessHistory(int64_t nowMs) { |
| 97 VCMCodecTimer::ProcessHistory(int64_t nowMs) | 73 _filteredMax = _shortMax; |
| 98 { | 74 if (_history[0].timeMs == -1) { |
| 99 _filteredMax = _shortMax; | 75 return; |
| 100 if (_history[0].timeMs == -1) | 76 } |
| 101 { | 77 for (int i = 0; i < MAX_HISTORY_SIZE; i++) { |
| 102 return; | 78 if (_history[i].timeMs == -1) { |
| 79 break; |
| 103 } | 80 } |
| 104 for (int i=0; i < MAX_HISTORY_SIZE; i++) | 81 if (nowMs - _history[i].timeMs > MAX_HISTORY_SIZE * SHORT_FILTER_MS) { |
| 105 { | 82 // This sample (and all samples after this) is too old |
| 106 if (_history[i].timeMs == -1) | 83 break; |
| 107 { | |
| 108 break; | |
| 109 } | |
| 110 if (nowMs - _history[i].timeMs > MAX_HISTORY_SIZE * SHORT_FILTER_MS) | |
| 111 { | |
| 112 // This sample (and all samples after this) is too old | |
| 113 break; | |
| 114 } | |
| 115 if (_history[i].shortMax > _filteredMax) | |
| 116 { | |
| 117 // This sample is the largest one this far into the history | |
| 118 _filteredMax = _history[i].shortMax; | |
| 119 } | |
| 120 } | 84 } |
| 85 if (_history[i].shortMax > _filteredMax) { |
| 86 // This sample is the largest one this far into the history |
| 87 _filteredMax = _history[i].shortMax; |
| 88 } |
| 89 } |
| 121 } | 90 } |
| 122 | 91 |
| 123 // Get the maximum observed time within a time window | 92 // Get the maximum observed time within a time window |
| 124 int32_t VCMCodecTimer::RequiredDecodeTimeMs(FrameType /*frameType*/) const | 93 int32_t VCMCodecTimer::RequiredDecodeTimeMs(FrameType /*frameType*/) const { |
| 125 { | 94 return _filteredMax; |
| 126 return _filteredMax; | |
| 127 } | 95 } |
| 128 | 96 } // namespace webrtc |
| 129 } | |
| OLD | NEW |