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

Side by Side Diff: webrtc/modules/video_coding/inter_frame_delay.cc

Issue 1528503003: Lint enabled for webrtc/modules/video_coding folder. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 5 years 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
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/inter_frame_delay.h" 11 #include "webrtc/modules/video_coding/inter_frame_delay.h"
12 12
13 namespace webrtc { 13 namespace webrtc {
14 14
15 VCMInterFrameDelay::VCMInterFrameDelay(int64_t currentWallClock) 15 VCMInterFrameDelay::VCMInterFrameDelay(int64_t currentWallClock) {
16 { 16 Reset(currentWallClock);
17 Reset(currentWallClock);
18 } 17 }
19 18
20 // Resets the delay estimate 19 // Resets the delay estimate
21 void 20 void VCMInterFrameDelay::Reset(int64_t currentWallClock) {
22 VCMInterFrameDelay::Reset(int64_t currentWallClock) 21 _zeroWallClock = currentWallClock;
23 { 22 _wrapArounds = 0;
24 _zeroWallClock = currentWallClock; 23 _prevWallClock = 0;
25 _wrapArounds = 0; 24 _prevTimestamp = 0;
26 _prevWallClock = 0; 25 _dTS = 0;
27 _prevTimestamp = 0;
28 _dTS = 0;
29 } 26 }
30 27
31 // Calculates the delay of a frame with the given timestamp. 28 // Calculates the delay of a frame with the given timestamp.
32 // This method is called when the frame is complete. 29 // This method is called when the frame is complete.
33 bool 30 bool VCMInterFrameDelay::CalculateDelay(uint32_t timestamp,
34 VCMInterFrameDelay::CalculateDelay(uint32_t timestamp, 31 int64_t* delay,
35 int64_t *delay, 32 int64_t currentWallClock) {
36 int64_t currentWallClock) 33 if (_prevWallClock == 0) {
37 { 34 // First set of data, initialization, wait for next frame
38 if (_prevWallClock == 0) 35 _prevWallClock = currentWallClock;
39 { 36 _prevTimestamp = timestamp;
40 // First set of data, initialization, wait for next frame 37 *delay = 0;
41 _prevWallClock = currentWallClock; 38 return true;
42 _prevTimestamp = timestamp; 39 }
43 *delay = 0;
44 return true;
45 }
46 40
47 int32_t prevWrapArounds = _wrapArounds; 41 int32_t prevWrapArounds = _wrapArounds;
48 CheckForWrapArounds(timestamp); 42 CheckForWrapArounds(timestamp);
49 43
50 // This will be -1 for backward wrap arounds and +1 for forward wrap arounds 44 // This will be -1 for backward wrap arounds and +1 for forward wrap arounds
51 int32_t wrapAroundsSincePrev = _wrapArounds - prevWrapArounds; 45 int32_t wrapAroundsSincePrev = _wrapArounds - prevWrapArounds;
52 46
53 // Account for reordering in jitter variance estimate in the future? 47 // Account for reordering in jitter variance estimate in the future?
54 // Note that this also captures incomplete frames which are grabbed 48 // Note that this also captures incomplete frames which are grabbed
55 // for decoding after a later frame has been complete, i.e. real 49 // for decoding after a later frame has been complete, i.e. real
56 // packet losses. 50 // packet losses.
57 if ((wrapAroundsSincePrev == 0 && timestamp < _prevTimestamp) || wrapArounds SincePrev < 0) 51 if ((wrapAroundsSincePrev == 0 && timestamp < _prevTimestamp) ||
58 { 52 wrapAroundsSincePrev < 0) {
59 *delay = 0; 53 *delay = 0;
60 return false; 54 return false;
61 } 55 }
62 56
63 // Compute the compensated timestamp difference and convert it to ms and 57 // Compute the compensated timestamp difference and convert it to ms and
64 // round it to closest integer. 58 // round it to closest integer.
65 _dTS = static_cast<int64_t>((timestamp + wrapAroundsSincePrev * 59 _dTS = static_cast<int64_t>(
66 (static_cast<int64_t>(1)<<32) - _prevTimestamp) / 90.0 + 0.5); 60 (timestamp + wrapAroundsSincePrev * (static_cast<int64_t>(1) << 32) -
61 _prevTimestamp) /
62 90.0 +
63 0.5);
67 64
68 // frameDelay is the difference of dT and dTS -- i.e. the difference of 65 // frameDelay is the difference of dT and dTS -- i.e. the difference of
69 // the wall clock time difference and the timestamp difference between 66 // the wall clock time difference and the timestamp difference between
70 // two following frames. 67 // two following frames.
71 *delay = static_cast<int64_t>(currentWallClock - _prevWallClock - _dTS); 68 *delay = static_cast<int64_t>(currentWallClock - _prevWallClock - _dTS);
72 69
73 _prevTimestamp = timestamp; 70 _prevTimestamp = timestamp;
74 _prevWallClock = currentWallClock; 71 _prevWallClock = currentWallClock;
75 72
76 return true; 73 return true;
77 } 74 }
78 75
79 // Returns the current difference between incoming timestamps 76 // Returns the current difference between incoming timestamps
80 uint32_t VCMInterFrameDelay::CurrentTimeStampDiffMs() const 77 uint32_t VCMInterFrameDelay::CurrentTimeStampDiffMs() const {
81 { 78 if (_dTS < 0) {
82 if (_dTS < 0) 79 return 0;
83 { 80 }
84 return 0; 81 return static_cast<uint32_t>(_dTS);
85 }
86 return static_cast<uint32_t>(_dTS);
87 } 82 }
88 83
89 // Investigates if the timestamp clock has overflowed since the last timestamp a nd 84 // Investigates if the timestamp clock has overflowed since the last timestamp
85 // and
90 // keeps track of the number of wrap arounds since reset. 86 // keeps track of the number of wrap arounds since reset.
91 void 87 void VCMInterFrameDelay::CheckForWrapArounds(uint32_t timestamp) {
92 VCMInterFrameDelay::CheckForWrapArounds(uint32_t timestamp) 88 if (timestamp < _prevTimestamp) {
93 { 89 // This difference will probably be less than -2^31 if we have had a wrap
94 if (timestamp < _prevTimestamp) 90 // around
95 { 91 // (e.g. timestamp = 1, _previousTimestamp = 2^32 - 1). Since it is cast to
96 // This difference will probably be less than -2^31 if we have had a wra p around 92 // a Word32,
97 // (e.g. timestamp = 1, _previousTimestamp = 2^32 - 1). Since it is cast to a Word32, 93 // it should be positive.
98 // it should be positive. 94 if (static_cast<int32_t>(timestamp - _prevTimestamp) > 0) {
99 if (static_cast<int32_t>(timestamp - _prevTimestamp) > 0) 95 // Forward wrap around
100 { 96 _wrapArounds++;
101 // Forward wrap around
102 _wrapArounds++;
103 }
104 } 97 }
105 // This difference will probably be less than -2^31 if we have had a backwar d wrap around. 98 // This difference will probably be less than -2^31 if we have had a
99 // backward
100 // wrap around.
106 // Since it is cast to a Word32, it should be positive. 101 // Since it is cast to a Word32, it should be positive.
107 else if (static_cast<int32_t>(_prevTimestamp - timestamp) > 0) 102 } else if (static_cast<int32_t>(_prevTimestamp - timestamp) > 0) {
108 { 103 // Backward wrap around
109 // Backward wrap around 104 _wrapArounds--;
110 _wrapArounds--; 105 }
111 }
112 } 106 }
113 107 } // namespace webrtc
114 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698