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