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 |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
48 clock.TimeInMilliseconds()); | 48 clock.TimeInMilliseconds()); |
49 // First update initializes the render time. Since we have no decode delay | 49 // First update initializes the render time. Since we have no decode delay |
50 // we get waitTime = renderTime - now - renderDelay = jitter. | 50 // we get waitTime = renderTime - now - renderDelay = jitter. |
51 EXPECT_EQ(jitterDelayMs, waitTime); | 51 EXPECT_EQ(jitterDelayMs, waitTime); |
52 | 52 |
53 jitterDelayMs += VCMTiming::kDelayMaxChangeMsPerS + 10; | 53 jitterDelayMs += VCMTiming::kDelayMaxChangeMsPerS + 10; |
54 timeStamp += 90000; | 54 timeStamp += 90000; |
55 clock.AdvanceTimeMilliseconds(1000); | 55 clock.AdvanceTimeMilliseconds(1000); |
56 timing.SetJitterDelay(jitterDelayMs); | 56 timing.SetJitterDelay(jitterDelayMs); |
57 timing.UpdateCurrentDelay(timeStamp); | 57 timing.UpdateCurrentDelay(timeStamp); |
58 waitTime = timing.MaxWaitingTime(timing.RenderTimeMs( | 58 waitTime = timing.MaxWaitingTime( |
59 timeStamp, clock.TimeInMilliseconds()), clock.TimeInMilliseconds()); | 59 timing.RenderTimeMs(timeStamp, clock.TimeInMilliseconds()), |
| 60 clock.TimeInMilliseconds()); |
60 // Since we gradually increase the delay we only get 100 ms every second. | 61 // Since we gradually increase the delay we only get 100 ms every second. |
61 EXPECT_EQ(jitterDelayMs - 10, waitTime); | 62 EXPECT_EQ(jitterDelayMs - 10, waitTime); |
62 | 63 |
63 timeStamp += 90000; | 64 timeStamp += 90000; |
64 clock.AdvanceTimeMilliseconds(1000); | 65 clock.AdvanceTimeMilliseconds(1000); |
65 timing.UpdateCurrentDelay(timeStamp); | 66 timing.UpdateCurrentDelay(timeStamp); |
66 waitTime = timing.MaxWaitingTime( | 67 waitTime = timing.MaxWaitingTime( |
67 timing.RenderTimeMs(timeStamp, clock.TimeInMilliseconds()), | 68 timing.RenderTimeMs(timeStamp, clock.TimeInMilliseconds()), |
68 clock.TimeInMilliseconds()); | 69 clock.TimeInMilliseconds()); |
69 EXPECT_EQ(waitTime, jitterDelayMs); | 70 EXPECT_EQ(waitTime, jitterDelayMs); |
70 | 71 |
71 // 300 incoming frames without jitter, verify that this gives the exact wait | 72 // 300 incoming frames without jitter, verify that this gives the exact wait |
72 // time. | 73 // time. |
73 for (int i = 0; i < 300; i++) { | 74 for (int i = 0; i < 300; i++) { |
74 clock.AdvanceTimeMilliseconds(1000 / 25); | 75 clock.AdvanceTimeMilliseconds(1000 / 25); |
75 timeStamp += 90000 / 25; | 76 timeStamp += 90000 / 25; |
76 timing.IncomingTimestamp(timeStamp, clock.TimeInMilliseconds()); | 77 timing.IncomingTimestamp(timeStamp, clock.TimeInMilliseconds()); |
77 } | 78 } |
78 timing.UpdateCurrentDelay(timeStamp); | 79 timing.UpdateCurrentDelay(timeStamp); |
79 waitTime = timing.MaxWaitingTime( | 80 waitTime = timing.MaxWaitingTime( |
80 timing.RenderTimeMs(timeStamp, clock.TimeInMilliseconds()), | 81 timing.RenderTimeMs(timeStamp, clock.TimeInMilliseconds()), |
81 clock.TimeInMilliseconds()); | 82 clock.TimeInMilliseconds()); |
82 EXPECT_EQ(waitTime, jitterDelayMs); | 83 EXPECT_EQ(waitTime, jitterDelayMs); |
83 | 84 |
84 // Add decode time estimates. | 85 // Add decode time estimates. |
85 for (int i = 0; i < 10; i++) { | 86 for (int i = 0; i < 10; i++) { |
86 int64_t startTimeMs = clock.TimeInMilliseconds(); | 87 int64_t startTimeMs = clock.TimeInMilliseconds(); |
87 clock.AdvanceTimeMilliseconds(10); | 88 clock.AdvanceTimeMilliseconds(10); |
88 timing.StopDecodeTimer(timeStamp, | 89 timing.StopDecodeTimer( |
89 clock.TimeInMilliseconds() - startTimeMs, | 90 timeStamp, clock.TimeInMilliseconds() - startTimeMs, |
90 clock.TimeInMilliseconds(), | 91 clock.TimeInMilliseconds(), |
91 timing.RenderTimeMs( | 92 timing.RenderTimeMs(timeStamp, clock.TimeInMilliseconds())); |
92 timeStamp, clock.TimeInMilliseconds())); | |
93 timeStamp += 90000 / 25; | 93 timeStamp += 90000 / 25; |
94 clock.AdvanceTimeMilliseconds(1000 / 25 - 10); | 94 clock.AdvanceTimeMilliseconds(1000 / 25 - 10); |
95 timing.IncomingTimestamp(timeStamp, clock.TimeInMilliseconds()); | 95 timing.IncomingTimestamp(timeStamp, clock.TimeInMilliseconds()); |
96 } | 96 } |
97 maxDecodeTimeMs = 10; | 97 maxDecodeTimeMs = 10; |
98 timing.SetJitterDelay(jitterDelayMs); | 98 timing.SetJitterDelay(jitterDelayMs); |
99 clock.AdvanceTimeMilliseconds(1000); | 99 clock.AdvanceTimeMilliseconds(1000); |
100 timeStamp += 90000; | 100 timeStamp += 90000; |
101 timing.UpdateCurrentDelay(timeStamp); | 101 timing.UpdateCurrentDelay(timeStamp); |
102 waitTime = timing.MaxWaitingTime( | 102 waitTime = timing.MaxWaitingTime( |
103 timing.RenderTimeMs(timeStamp, clock.TimeInMilliseconds()), | 103 timing.RenderTimeMs(timeStamp, clock.TimeInMilliseconds()), |
104 clock.TimeInMilliseconds()); | 104 clock.TimeInMilliseconds()); |
105 EXPECT_EQ(waitTime, jitterDelayMs); | 105 EXPECT_EQ(waitTime, jitterDelayMs); |
106 | 106 |
107 uint32_t minTotalDelayMs = 200; | 107 uint32_t minTotalDelayMs = 200; |
108 timing.set_min_playout_delay(minTotalDelayMs); | 108 timing.set_min_playout_delay(minTotalDelayMs); |
109 clock.AdvanceTimeMilliseconds(5000); | 109 clock.AdvanceTimeMilliseconds(5000); |
110 timeStamp += 5*90000; | 110 timeStamp += 5 * 90000; |
111 timing.UpdateCurrentDelay(timeStamp); | 111 timing.UpdateCurrentDelay(timeStamp); |
112 const int kRenderDelayMs = 10; | 112 const int kRenderDelayMs = 10; |
113 timing.set_render_delay(kRenderDelayMs); | 113 timing.set_render_delay(kRenderDelayMs); |
114 waitTime = timing.MaxWaitingTime( | 114 waitTime = timing.MaxWaitingTime( |
115 timing.RenderTimeMs(timeStamp, clock.TimeInMilliseconds()), | 115 timing.RenderTimeMs(timeStamp, clock.TimeInMilliseconds()), |
116 clock.TimeInMilliseconds()); | 116 clock.TimeInMilliseconds()); |
117 // We should at least have minTotalDelayMs - decodeTime (10) - renderTime | 117 // We should at least have minTotalDelayMs - decodeTime (10) - renderTime |
118 // (10) to wait. | 118 // (10) to wait. |
119 EXPECT_EQ(waitTime, minTotalDelayMs - maxDecodeTimeMs - kRenderDelayMs); | 119 EXPECT_EQ(waitTime, minTotalDelayMs - maxDecodeTimeMs - kRenderDelayMs); |
120 // The total video delay should be equal to the min total delay. | 120 // The total video delay should be equal to the min total delay. |
121 EXPECT_EQ(minTotalDelayMs, timing.TargetVideoDelay()); | 121 EXPECT_EQ(minTotalDelayMs, timing.TargetVideoDelay()); |
122 | 122 |
123 // Reset playout delay. | 123 // Reset playout delay. |
124 timing.set_min_playout_delay(0); | 124 timing.set_min_playout_delay(0); |
125 clock.AdvanceTimeMilliseconds(5000); | 125 clock.AdvanceTimeMilliseconds(5000); |
126 timeStamp += 5*90000; | 126 timeStamp += 5 * 90000; |
127 timing.UpdateCurrentDelay(timeStamp); | 127 timing.UpdateCurrentDelay(timeStamp); |
128 } | 128 } |
129 | 129 |
130 TEST(ReceiverTiming, WrapAround) { | 130 TEST(ReceiverTiming, WrapAround) { |
131 const int kFramerate = 25; | 131 const int kFramerate = 25; |
132 SimulatedClock clock(0); | 132 SimulatedClock clock(0); |
133 VCMTiming timing(&clock); | 133 VCMTiming timing(&clock); |
134 // Provoke a wrap-around. The forth frame will have wrapped at 25 fps. | 134 // Provoke a wrap-around. The forth frame will have wrapped at 25 fps. |
135 uint32_t timestamp = 0xFFFFFFFFu - 3 * 90000 / kFramerate; | 135 uint32_t timestamp = 0xFFFFFFFFu - 3 * 90000 / kFramerate; |
136 for (int i = 0; i < 4; ++i) { | 136 for (int i = 0; i < 4; ++i) { |
137 timing.IncomingTimestamp(timestamp, clock.TimeInMilliseconds()); | 137 timing.IncomingTimestamp(timestamp, clock.TimeInMilliseconds()); |
138 clock.AdvanceTimeMilliseconds(1000 / kFramerate); | 138 clock.AdvanceTimeMilliseconds(1000 / kFramerate); |
139 timestamp += 90000 / kFramerate; | 139 timestamp += 90000 / kFramerate; |
140 int64_t render_time = timing.RenderTimeMs(0xFFFFFFFFu, | 140 int64_t render_time = |
141 clock.TimeInMilliseconds()); | 141 timing.RenderTimeMs(0xFFFFFFFFu, clock.TimeInMilliseconds()); |
142 EXPECT_EQ(3 * 1000 / kFramerate, render_time); | 142 EXPECT_EQ(3 * 1000 / kFramerate, render_time); |
143 render_time = timing.RenderTimeMs(89u, // One second later in 90 kHz. | 143 render_time = timing.RenderTimeMs(89u, // One second later in 90 kHz. |
144 clock.TimeInMilliseconds()); | 144 clock.TimeInMilliseconds()); |
145 EXPECT_EQ(3 * 1000 / kFramerate + 1, render_time); | 145 EXPECT_EQ(3 * 1000 / kFramerate + 1, render_time); |
146 } | 146 } |
147 } | 147 } |
148 | 148 |
149 } // namespace webrtc | 149 } // namespace webrtc |
OLD | NEW |