OLD | NEW |
1 /* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 1 /* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. |
2 * | 2 * |
3 * Use of this source code is governed by a BSD-style license | 3 * Use of this source code is governed by a BSD-style license |
4 * that can be found in the LICENSE file in the root of the source | 4 * that can be found in the LICENSE file in the root of the source |
5 * tree. An additional intellectual property rights grant can be found | 5 * tree. An additional intellectual property rights grant can be found |
6 * in the file PATENTS. All contributing project authors may | 6 * in the file PATENTS. All contributing project authors may |
7 * be found in the AUTHORS file in the root of the source tree. | 7 * be found in the AUTHORS file in the root of the source tree. |
8 */ | 8 */ |
9 | 9 |
10 #include <string.h> | 10 #include <string.h> |
11 | 11 |
12 #include <list> | 12 #include <list> |
13 #include <queue> | 13 #include <queue> |
| 14 #include <vector> |
14 | 15 |
15 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
17 #include "webrtc/modules/video_coding/encoded_frame.h" | 18 #include "webrtc/modules/video_coding/encoded_frame.h" |
18 #include "webrtc/modules/video_coding/packet.h" | 19 #include "webrtc/modules/video_coding/packet.h" |
19 #include "webrtc/modules/video_coding/receiver.h" | 20 #include "webrtc/modules/video_coding/receiver.h" |
20 #include "webrtc/modules/video_coding/test/stream_generator.h" | 21 #include "webrtc/modules/video_coding/test/stream_generator.h" |
21 #include "webrtc/modules/video_coding/timing.h" | 22 #include "webrtc/modules/video_coding/timing.h" |
22 #include "webrtc/modules/video_coding/test/test_util.h" | 23 #include "webrtc/modules/video_coding/test/test_util.h" |
23 #include "webrtc/system_wrappers/include/clock.h" | 24 #include "webrtc/system_wrappers/include/clock.h" |
24 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 25 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
25 | 26 |
26 namespace webrtc { | 27 namespace webrtc { |
27 | 28 |
28 class TestVCMReceiver : public ::testing::Test { | 29 class TestVCMReceiver : public ::testing::Test { |
29 protected: | 30 protected: |
30 enum { kWidth = 640 }; | 31 enum { kWidth = 640 }; |
31 enum { kHeight = 480 }; | 32 enum { kHeight = 480 }; |
32 | 33 |
33 TestVCMReceiver() | 34 TestVCMReceiver() |
34 : clock_(new SimulatedClock(0)), | 35 : clock_(new SimulatedClock(0)), |
35 timing_(clock_.get()), | 36 timing_(clock_.get()), |
36 receiver_(&timing_, clock_.get(), &event_factory_) { | 37 receiver_(&timing_, clock_.get(), &event_factory_) { |
37 | 38 stream_generator_.reset( |
38 stream_generator_.reset(new | 39 new StreamGenerator(0, clock_->TimeInMilliseconds())); |
39 StreamGenerator(0, clock_->TimeInMilliseconds())); | |
40 } | 40 } |
41 | 41 |
42 virtual void SetUp() { | 42 virtual void SetUp() { receiver_.Reset(); } |
43 receiver_.Reset(); | |
44 } | |
45 | 43 |
46 int32_t InsertPacket(int index) { | 44 int32_t InsertPacket(int index) { |
47 VCMPacket packet; | 45 VCMPacket packet; |
48 bool packet_available = stream_generator_->GetPacket(&packet, index); | 46 bool packet_available = stream_generator_->GetPacket(&packet, index); |
49 EXPECT_TRUE(packet_available); | 47 EXPECT_TRUE(packet_available); |
50 if (!packet_available) | 48 if (!packet_available) |
51 return kGeneralError; // Return here to avoid crashes below. | 49 return kGeneralError; // Return here to avoid crashes below. |
52 return receiver_.InsertPacket(packet, kWidth, kHeight); | 50 return receiver_.InsertPacket(packet, kWidth, kHeight); |
53 } | 51 } |
54 | 52 |
(...skipping 17 matching lines...) Expand all Loading... |
72 VCMPacket packet; | 70 VCMPacket packet; |
73 stream_generator_->PopPacket(&packet, 0); | 71 stream_generator_->PopPacket(&packet, 0); |
74 } | 72 } |
75 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs); | 73 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs); |
76 return ret; | 74 return ret; |
77 } | 75 } |
78 | 76 |
79 bool DecodeNextFrame() { | 77 bool DecodeNextFrame() { |
80 int64_t render_time_ms = 0; | 78 int64_t render_time_ms = 0; |
81 VCMEncodedFrame* frame = | 79 VCMEncodedFrame* frame = |
82 receiver_.FrameForDecoding(0, render_time_ms, false); | 80 receiver_.FrameForDecoding(0, &render_time_ms, false); |
83 if (!frame) | 81 if (!frame) |
84 return false; | 82 return false; |
85 receiver_.ReleaseFrame(frame); | 83 receiver_.ReleaseFrame(frame); |
86 return true; | 84 return true; |
87 } | 85 } |
88 | 86 |
89 rtc::scoped_ptr<SimulatedClock> clock_; | 87 rtc::scoped_ptr<SimulatedClock> clock_; |
90 VCMTiming timing_; | 88 VCMTiming timing_; |
91 NullEventFactory event_factory_; | 89 NullEventFactory event_factory_; |
92 VCMReceiver receiver_; | 90 VCMReceiver receiver_; |
(...skipping 16 matching lines...) Expand all Loading... |
109 const int kNumOfNonDecodableFrames = 2; | 107 const int kNumOfNonDecodableFrames = 2; |
110 for (int i = 0; i < kNumOfNonDecodableFrames; ++i) { | 108 for (int i = 0; i < kNumOfNonDecodableFrames; ++i) { |
111 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); | 109 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); |
112 } | 110 } |
113 const int kNumOfFrames = 10; | 111 const int kNumOfFrames = 10; |
114 EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError); | 112 EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError); |
115 for (int i = 0; i < kNumOfFrames - 1; ++i) { | 113 for (int i = 0; i < kNumOfFrames - 1; ++i) { |
116 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); | 114 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); |
117 } | 115 } |
118 EXPECT_EQ((kNumOfFrames - 1) * kDefaultFramePeriodMs, | 116 EXPECT_EQ((kNumOfFrames - 1) * kDefaultFramePeriodMs, |
119 receiver_.RenderBufferSizeMs()); | 117 receiver_.RenderBufferSizeMs()); |
120 } | 118 } |
121 | 119 |
122 TEST_F(TestVCMReceiver, RenderBufferSize_NotAllComplete) { | 120 TEST_F(TestVCMReceiver, RenderBufferSize_NotAllComplete) { |
123 EXPECT_EQ(0, receiver_.RenderBufferSizeMs()); | 121 EXPECT_EQ(0, receiver_.RenderBufferSizeMs()); |
124 EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError); | 122 EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError); |
125 int num_of_frames = 10; | 123 int num_of_frames = 10; |
126 for (int i = 0; i < num_of_frames; ++i) { | 124 for (int i = 0; i < num_of_frames; ++i) { |
127 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); | 125 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); |
128 } | 126 } |
129 num_of_frames++; | 127 num_of_frames++; |
130 EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError); | 128 EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError); |
131 for (int i = 0; i < num_of_frames; ++i) { | 129 for (int i = 0; i < num_of_frames; ++i) { |
132 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); | 130 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); |
133 } | 131 } |
134 EXPECT_EQ((num_of_frames - 1) * kDefaultFramePeriodMs, | 132 EXPECT_EQ((num_of_frames - 1) * kDefaultFramePeriodMs, |
135 receiver_.RenderBufferSizeMs()); | 133 receiver_.RenderBufferSizeMs()); |
136 } | 134 } |
137 | 135 |
138 TEST_F(TestVCMReceiver, RenderBufferSize_NoKeyFrame) { | 136 TEST_F(TestVCMReceiver, RenderBufferSize_NoKeyFrame) { |
139 EXPECT_EQ(0, receiver_.RenderBufferSizeMs()); | 137 EXPECT_EQ(0, receiver_.RenderBufferSizeMs()); |
140 int num_of_frames = 10; | 138 int num_of_frames = 10; |
141 for (int i = 0; i < num_of_frames; ++i) { | 139 for (int i = 0; i < num_of_frames; ++i) { |
142 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); | 140 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); |
143 } | 141 } |
144 int64_t next_render_time_ms = 0; | 142 int64_t next_render_time_ms = 0; |
145 VCMEncodedFrame* frame = | 143 VCMEncodedFrame* frame = |
146 receiver_.FrameForDecoding(10, next_render_time_ms, false); | 144 receiver_.FrameForDecoding(10, &next_render_time_ms, false); |
147 EXPECT_TRUE(frame == NULL); | 145 EXPECT_TRUE(frame == NULL); |
148 receiver_.ReleaseFrame(frame); | 146 receiver_.ReleaseFrame(frame); |
149 EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError); | 147 EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError); |
150 for (int i = 0; i < num_of_frames; ++i) { | 148 for (int i = 0; i < num_of_frames; ++i) { |
151 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); | 149 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); |
152 } | 150 } |
153 EXPECT_EQ(0, receiver_.RenderBufferSizeMs()); | 151 EXPECT_EQ(0, receiver_.RenderBufferSizeMs()); |
154 } | 152 } |
155 | 153 |
156 TEST_F(TestVCMReceiver, NonDecodableDuration_Empty) { | 154 TEST_F(TestVCMReceiver, NonDecodableDuration_Empty) { |
157 // Enable NACK and with no RTT thresholds for disabling retransmission delay. | 155 // Enable NACK and with no RTT thresholds for disabling retransmission delay. |
158 receiver_.SetNackMode(kNack, -1, -1); | 156 receiver_.SetNackMode(kNack, -1, -1); |
159 const size_t kMaxNackListSize = 1000; | 157 const size_t kMaxNackListSize = 1000; |
160 const int kMaxPacketAgeToNack = 1000; | 158 const int kMaxPacketAgeToNack = 1000; |
161 const int kMaxNonDecodableDuration = 500; | 159 const int kMaxNonDecodableDuration = 500; |
162 const int kMinDelayMs = 500; | 160 const int kMinDelayMs = 500; |
163 receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack, | 161 receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack, |
164 kMaxNonDecodableDuration); | 162 kMaxNonDecodableDuration); |
165 EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError); | 163 EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError); |
166 // Advance time until it's time to decode the key frame. | 164 // Advance time until it's time to decode the key frame. |
167 clock_->AdvanceTimeMilliseconds(kMinDelayMs); | 165 clock_->AdvanceTimeMilliseconds(kMinDelayMs); |
168 EXPECT_TRUE(DecodeNextFrame()); | 166 EXPECT_TRUE(DecodeNextFrame()); |
169 bool request_key_frame = false; | 167 bool request_key_frame = false; |
170 std::vector<uint16_t> nack_list = receiver_.NackList(&request_key_frame); | 168 std::vector<uint16_t> nack_list = receiver_.NackList(&request_key_frame); |
171 EXPECT_FALSE(request_key_frame); | 169 EXPECT_FALSE(request_key_frame); |
172 } | 170 } |
173 | 171 |
174 TEST_F(TestVCMReceiver, NonDecodableDuration_NoKeyFrame) { | 172 TEST_F(TestVCMReceiver, NonDecodableDuration_NoKeyFrame) { |
175 // Enable NACK and with no RTT thresholds for disabling retransmission delay. | 173 // Enable NACK and with no RTT thresholds for disabling retransmission delay. |
176 receiver_.SetNackMode(kNack, -1, -1); | 174 receiver_.SetNackMode(kNack, -1, -1); |
177 const size_t kMaxNackListSize = 1000; | 175 const size_t kMaxNackListSize = 1000; |
178 const int kMaxPacketAgeToNack = 1000; | 176 const int kMaxPacketAgeToNack = 1000; |
179 const int kMaxNonDecodableDuration = 500; | 177 const int kMaxNonDecodableDuration = 500; |
180 receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack, | 178 receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack, |
181 kMaxNonDecodableDuration); | 179 kMaxNonDecodableDuration); |
182 const int kNumFrames = kDefaultFrameRate * kMaxNonDecodableDuration / 1000; | 180 const int kNumFrames = kDefaultFrameRate * kMaxNonDecodableDuration / 1000; |
183 for (int i = 0; i < kNumFrames; ++i) { | 181 for (int i = 0; i < kNumFrames; ++i) { |
184 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); | 182 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); |
185 } | 183 } |
186 bool request_key_frame = false; | 184 bool request_key_frame = false; |
187 std::vector<uint16_t> nack_list = receiver_.NackList(&request_key_frame); | 185 std::vector<uint16_t> nack_list = receiver_.NackList(&request_key_frame); |
188 EXPECT_TRUE(request_key_frame); | 186 EXPECT_TRUE(request_key_frame); |
189 } | 187 } |
190 | 188 |
191 TEST_F(TestVCMReceiver, NonDecodableDuration_OneIncomplete) { | 189 TEST_F(TestVCMReceiver, NonDecodableDuration_OneIncomplete) { |
192 // Enable NACK and with no RTT thresholds for disabling retransmission delay. | 190 // Enable NACK and with no RTT thresholds for disabling retransmission delay. |
193 receiver_.SetNackMode(kNack, -1, -1); | 191 receiver_.SetNackMode(kNack, -1, -1); |
194 const size_t kMaxNackListSize = 1000; | 192 const size_t kMaxNackListSize = 1000; |
195 const int kMaxPacketAgeToNack = 1000; | 193 const int kMaxPacketAgeToNack = 1000; |
196 const int kMaxNonDecodableDuration = 500; | 194 const int kMaxNonDecodableDuration = 500; |
197 const int kMaxNonDecodableDurationFrames = (kDefaultFrameRate * | 195 const int kMaxNonDecodableDurationFrames = |
198 kMaxNonDecodableDuration + 500) / 1000; | 196 (kDefaultFrameRate * kMaxNonDecodableDuration + 500) / 1000; |
199 const int kMinDelayMs = 500; | 197 const int kMinDelayMs = 500; |
200 receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack, | 198 receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack, |
201 kMaxNonDecodableDuration); | 199 kMaxNonDecodableDuration); |
202 receiver_.SetMinReceiverDelay(kMinDelayMs); | 200 receiver_.SetMinReceiverDelay(kMinDelayMs); |
203 int64_t key_frame_inserted = clock_->TimeInMilliseconds(); | 201 int64_t key_frame_inserted = clock_->TimeInMilliseconds(); |
204 EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError); | 202 EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError); |
205 // Insert an incomplete frame. | 203 // Insert an incomplete frame. |
206 EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError); | 204 EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError); |
207 // Insert enough frames to have too long non-decodable sequence. | 205 // Insert enough frames to have too long non-decodable sequence. |
208 for (int i = 0; i < kMaxNonDecodableDurationFrames; | 206 for (int i = 0; i < kMaxNonDecodableDurationFrames; ++i) { |
209 ++i) { | |
210 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); | 207 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); |
211 } | 208 } |
212 // Advance time until it's time to decode the key frame. | 209 // Advance time until it's time to decode the key frame. |
213 clock_->AdvanceTimeMilliseconds(kMinDelayMs - clock_->TimeInMilliseconds() - | 210 clock_->AdvanceTimeMilliseconds(kMinDelayMs - clock_->TimeInMilliseconds() - |
214 key_frame_inserted); | 211 key_frame_inserted); |
215 EXPECT_TRUE(DecodeNextFrame()); | 212 EXPECT_TRUE(DecodeNextFrame()); |
216 // Make sure we get a key frame request. | 213 // Make sure we get a key frame request. |
217 bool request_key_frame = false; | 214 bool request_key_frame = false; |
218 std::vector<uint16_t> nack_list = receiver_.NackList(&request_key_frame); | 215 std::vector<uint16_t> nack_list = receiver_.NackList(&request_key_frame); |
219 EXPECT_TRUE(request_key_frame); | 216 EXPECT_TRUE(request_key_frame); |
220 } | 217 } |
221 | 218 |
222 TEST_F(TestVCMReceiver, NonDecodableDuration_NoTrigger) { | 219 TEST_F(TestVCMReceiver, NonDecodableDuration_NoTrigger) { |
223 // Enable NACK and with no RTT thresholds for disabling retransmission delay. | 220 // Enable NACK and with no RTT thresholds for disabling retransmission delay. |
224 receiver_.SetNackMode(kNack, -1, -1); | 221 receiver_.SetNackMode(kNack, -1, -1); |
225 const size_t kMaxNackListSize = 1000; | 222 const size_t kMaxNackListSize = 1000; |
226 const int kMaxPacketAgeToNack = 1000; | 223 const int kMaxPacketAgeToNack = 1000; |
227 const int kMaxNonDecodableDuration = 500; | 224 const int kMaxNonDecodableDuration = 500; |
228 const int kMaxNonDecodableDurationFrames = (kDefaultFrameRate * | 225 const int kMaxNonDecodableDurationFrames = |
229 kMaxNonDecodableDuration + 500) / 1000; | 226 (kDefaultFrameRate * kMaxNonDecodableDuration + 500) / 1000; |
230 const int kMinDelayMs = 500; | 227 const int kMinDelayMs = 500; |
231 receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack, | 228 receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack, |
232 kMaxNonDecodableDuration); | 229 kMaxNonDecodableDuration); |
233 receiver_.SetMinReceiverDelay(kMinDelayMs); | 230 receiver_.SetMinReceiverDelay(kMinDelayMs); |
234 int64_t key_frame_inserted = clock_->TimeInMilliseconds(); | 231 int64_t key_frame_inserted = clock_->TimeInMilliseconds(); |
235 EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError); | 232 EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError); |
236 // Insert an incomplete frame. | 233 // Insert an incomplete frame. |
237 EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError); | 234 EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError); |
238 // Insert all but one frame to not trigger a key frame request due to | 235 // Insert all but one frame to not trigger a key frame request due to |
239 // too long duration of non-decodable frames. | 236 // too long duration of non-decodable frames. |
240 for (int i = 0; i < kMaxNonDecodableDurationFrames - 1; | 237 for (int i = 0; i < kMaxNonDecodableDurationFrames - 1; ++i) { |
241 ++i) { | |
242 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); | 238 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); |
243 } | 239 } |
244 // Advance time until it's time to decode the key frame. | 240 // Advance time until it's time to decode the key frame. |
245 clock_->AdvanceTimeMilliseconds(kMinDelayMs - clock_->TimeInMilliseconds() - | 241 clock_->AdvanceTimeMilliseconds(kMinDelayMs - clock_->TimeInMilliseconds() - |
246 key_frame_inserted); | 242 key_frame_inserted); |
247 EXPECT_TRUE(DecodeNextFrame()); | 243 EXPECT_TRUE(DecodeNextFrame()); |
248 // Make sure we don't get a key frame request since we haven't generated | 244 // Make sure we don't get a key frame request since we haven't generated |
249 // enough frames. | 245 // enough frames. |
250 bool request_key_frame = false; | 246 bool request_key_frame = false; |
251 std::vector<uint16_t> nack_list = receiver_.NackList(&request_key_frame); | 247 std::vector<uint16_t> nack_list = receiver_.NackList(&request_key_frame); |
252 EXPECT_FALSE(request_key_frame); | 248 EXPECT_FALSE(request_key_frame); |
253 } | 249 } |
254 | 250 |
255 TEST_F(TestVCMReceiver, NonDecodableDuration_NoTrigger2) { | 251 TEST_F(TestVCMReceiver, NonDecodableDuration_NoTrigger2) { |
256 // Enable NACK and with no RTT thresholds for disabling retransmission delay. | 252 // Enable NACK and with no RTT thresholds for disabling retransmission delay. |
257 receiver_.SetNackMode(kNack, -1, -1); | 253 receiver_.SetNackMode(kNack, -1, -1); |
258 const size_t kMaxNackListSize = 1000; | 254 const size_t kMaxNackListSize = 1000; |
259 const int kMaxPacketAgeToNack = 1000; | 255 const int kMaxPacketAgeToNack = 1000; |
260 const int kMaxNonDecodableDuration = 500; | 256 const int kMaxNonDecodableDuration = 500; |
261 const int kMaxNonDecodableDurationFrames = (kDefaultFrameRate * | 257 const int kMaxNonDecodableDurationFrames = |
262 kMaxNonDecodableDuration + 500) / 1000; | 258 (kDefaultFrameRate * kMaxNonDecodableDuration + 500) / 1000; |
263 const int kMinDelayMs = 500; | 259 const int kMinDelayMs = 500; |
264 receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack, | 260 receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack, |
265 kMaxNonDecodableDuration); | 261 kMaxNonDecodableDuration); |
266 receiver_.SetMinReceiverDelay(kMinDelayMs); | 262 receiver_.SetMinReceiverDelay(kMinDelayMs); |
267 int64_t key_frame_inserted = clock_->TimeInMilliseconds(); | 263 int64_t key_frame_inserted = clock_->TimeInMilliseconds(); |
268 EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError); | 264 EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError); |
269 // Insert enough frames to have too long non-decodable sequence, except that | 265 // Insert enough frames to have too long non-decodable sequence, except that |
270 // we don't have any losses. | 266 // we don't have any losses. |
271 for (int i = 0; i < kMaxNonDecodableDurationFrames; | 267 for (int i = 0; i < kMaxNonDecodableDurationFrames; ++i) { |
272 ++i) { | |
273 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); | 268 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); |
274 } | 269 } |
275 // Insert an incomplete frame. | 270 // Insert an incomplete frame. |
276 EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError); | 271 EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError); |
277 // Advance time until it's time to decode the key frame. | 272 // Advance time until it's time to decode the key frame. |
278 clock_->AdvanceTimeMilliseconds(kMinDelayMs - clock_->TimeInMilliseconds() - | 273 clock_->AdvanceTimeMilliseconds(kMinDelayMs - clock_->TimeInMilliseconds() - |
279 key_frame_inserted); | 274 key_frame_inserted); |
280 EXPECT_TRUE(DecodeNextFrame()); | 275 EXPECT_TRUE(DecodeNextFrame()); |
281 // Make sure we don't get a key frame request since the non-decodable duration | 276 // Make sure we don't get a key frame request since the non-decodable duration |
282 // is only one frame. | 277 // is only one frame. |
283 bool request_key_frame = false; | 278 bool request_key_frame = false; |
284 std::vector<uint16_t> nack_list = receiver_.NackList(&request_key_frame); | 279 std::vector<uint16_t> nack_list = receiver_.NackList(&request_key_frame); |
285 EXPECT_FALSE(request_key_frame); | 280 EXPECT_FALSE(request_key_frame); |
286 } | 281 } |
287 | 282 |
288 TEST_F(TestVCMReceiver, NonDecodableDuration_KeyFrameAfterIncompleteFrames) { | 283 TEST_F(TestVCMReceiver, NonDecodableDuration_KeyFrameAfterIncompleteFrames) { |
289 // Enable NACK and with no RTT thresholds for disabling retransmission delay. | 284 // Enable NACK and with no RTT thresholds for disabling retransmission delay. |
290 receiver_.SetNackMode(kNack, -1, -1); | 285 receiver_.SetNackMode(kNack, -1, -1); |
291 const size_t kMaxNackListSize = 1000; | 286 const size_t kMaxNackListSize = 1000; |
292 const int kMaxPacketAgeToNack = 1000; | 287 const int kMaxPacketAgeToNack = 1000; |
293 const int kMaxNonDecodableDuration = 500; | 288 const int kMaxNonDecodableDuration = 500; |
294 const int kMaxNonDecodableDurationFrames = (kDefaultFrameRate * | 289 const int kMaxNonDecodableDurationFrames = |
295 kMaxNonDecodableDuration + 500) / 1000; | 290 (kDefaultFrameRate * kMaxNonDecodableDuration + 500) / 1000; |
296 const int kMinDelayMs = 500; | 291 const int kMinDelayMs = 500; |
297 receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack, | 292 receiver_.SetNackSettings(kMaxNackListSize, kMaxPacketAgeToNack, |
298 kMaxNonDecodableDuration); | 293 kMaxNonDecodableDuration); |
299 receiver_.SetMinReceiverDelay(kMinDelayMs); | 294 receiver_.SetMinReceiverDelay(kMinDelayMs); |
300 int64_t key_frame_inserted = clock_->TimeInMilliseconds(); | 295 int64_t key_frame_inserted = clock_->TimeInMilliseconds(); |
301 EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError); | 296 EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError); |
302 // Insert an incomplete frame. | 297 // Insert an incomplete frame. |
303 EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError); | 298 EXPECT_GE(InsertFrame(kVideoFrameDelta, false), kNoError); |
304 // Insert enough frames to have too long non-decodable sequence. | 299 // Insert enough frames to have too long non-decodable sequence. |
305 for (int i = 0; i < kMaxNonDecodableDurationFrames; | 300 for (int i = 0; i < kMaxNonDecodableDurationFrames; ++i) { |
306 ++i) { | |
307 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); | 301 EXPECT_GE(InsertFrame(kVideoFrameDelta, true), kNoError); |
308 } | 302 } |
309 EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError); | 303 EXPECT_GE(InsertFrame(kVideoFrameKey, true), kNoError); |
310 // Advance time until it's time to decode the key frame. | 304 // Advance time until it's time to decode the key frame. |
311 clock_->AdvanceTimeMilliseconds(kMinDelayMs - clock_->TimeInMilliseconds() - | 305 clock_->AdvanceTimeMilliseconds(kMinDelayMs - clock_->TimeInMilliseconds() - |
312 key_frame_inserted); | 306 key_frame_inserted); |
313 EXPECT_TRUE(DecodeNextFrame()); | 307 EXPECT_TRUE(DecodeNextFrame()); |
314 // Make sure we don't get a key frame request since we have a key frame | 308 // Make sure we don't get a key frame request since we have a key frame |
315 // in the list. | 309 // in the list. |
316 bool request_key_frame = false; | 310 bool request_key_frame = false; |
317 std::vector<uint16_t> nack_list = receiver_.NackList(&request_key_frame); | 311 std::vector<uint16_t> nack_list = receiver_.NackList(&request_key_frame); |
318 EXPECT_FALSE(request_key_frame); | 312 EXPECT_FALSE(request_key_frame); |
319 } | 313 } |
320 | 314 |
321 // A simulated clock, when time elapses, will insert frames into the jitter | 315 // A simulated clock, when time elapses, will insert frames into the jitter |
322 // buffer, based on initial settings. | 316 // buffer, based on initial settings. |
(...skipping 10 matching lines...) Expand all Loading... |
333 // now+|milliseconds|, the clock will be advanced to the arrival time of next | 327 // now+|milliseconds|, the clock will be advanced to the arrival time of next |
334 // frame. | 328 // frame. |
335 // Otherwise, the clock will be advanced by |milliseconds|. | 329 // Otherwise, the clock will be advanced by |milliseconds|. |
336 // | 330 // |
337 // For both cases, a frame will be inserted into the jitter buffer at the | 331 // For both cases, a frame will be inserted into the jitter buffer at the |
338 // instant when the clock time is timestamps_.front().arrive_time. | 332 // instant when the clock time is timestamps_.front().arrive_time. |
339 // | 333 // |
340 // Return true if some frame arrives between now and now+|milliseconds|. | 334 // Return true if some frame arrives between now and now+|milliseconds|. |
341 bool AdvanceTimeMilliseconds(int64_t milliseconds, bool stop_on_frame) { | 335 bool AdvanceTimeMilliseconds(int64_t milliseconds, bool stop_on_frame) { |
342 return AdvanceTimeMicroseconds(milliseconds * 1000, stop_on_frame); | 336 return AdvanceTimeMicroseconds(milliseconds * 1000, stop_on_frame); |
343 }; | 337 } |
344 | 338 |
345 bool AdvanceTimeMicroseconds(int64_t microseconds, bool stop_on_frame) { | 339 bool AdvanceTimeMicroseconds(int64_t microseconds, bool stop_on_frame) { |
346 int64_t start_time = TimeInMicroseconds(); | 340 int64_t start_time = TimeInMicroseconds(); |
347 int64_t end_time = start_time + microseconds; | 341 int64_t end_time = start_time + microseconds; |
348 bool frame_injected = false; | 342 bool frame_injected = false; |
349 while (!timestamps_.empty() && | 343 while (!timestamps_.empty() && |
350 timestamps_.front().arrive_time <= end_time) { | 344 timestamps_.front().arrive_time <= end_time) { |
351 RTC_DCHECK(timestamps_.front().arrive_time >= start_time); | 345 RTC_DCHECK(timestamps_.front().arrive_time >= start_time); |
352 | 346 |
353 SimulatedClock::AdvanceTimeMicroseconds(timestamps_.front().arrive_time - | 347 SimulatedClock::AdvanceTimeMicroseconds(timestamps_.front().arrive_time - |
354 TimeInMicroseconds()); | 348 TimeInMicroseconds()); |
355 GenerateAndInsertFrame((timestamps_.front().render_time + 500) / 1000); | 349 GenerateAndInsertFrame((timestamps_.front().render_time + 500) / 1000); |
356 timestamps_.pop(); | 350 timestamps_.pop(); |
357 frame_injected = true; | 351 frame_injected = true; |
358 | 352 |
359 if (stop_on_frame) | 353 if (stop_on_frame) |
360 return frame_injected; | 354 return frame_injected; |
361 } | 355 } |
362 | 356 |
363 if (TimeInMicroseconds() < end_time) { | 357 if (TimeInMicroseconds() < end_time) { |
364 SimulatedClock::AdvanceTimeMicroseconds(end_time - TimeInMicroseconds()); | 358 SimulatedClock::AdvanceTimeMicroseconds(end_time - TimeInMicroseconds()); |
365 } | 359 } |
366 return frame_injected; | 360 return frame_injected; |
367 }; | 361 } |
368 | 362 |
369 // Input timestamps are in unit Milliseconds. | 363 // Input timestamps are in unit Milliseconds. |
370 // And |arrive_timestamps| must be positive and in increasing order. | 364 // And |arrive_timestamps| must be positive and in increasing order. |
371 // |arrive_timestamps| determine when we are going to insert frames into the | 365 // |arrive_timestamps| determine when we are going to insert frames into the |
372 // jitter buffer. | 366 // jitter buffer. |
373 // |render_timestamps| are the timestamps on the frame. | 367 // |render_timestamps| are the timestamps on the frame. |
374 void SetFrames(const int64_t* arrive_timestamps, | 368 void SetFrames(const int64_t* arrive_timestamps, |
375 const int64_t* render_timestamps, | 369 const int64_t* render_timestamps, |
376 size_t size) { | 370 size_t size) { |
377 int64_t previous_arrive_timestamp = 0; | 371 int64_t previous_arrive_timestamp = 0; |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 // This is used to simulate the JitterBuffer getting packets from internet as | 418 // This is used to simulate the JitterBuffer getting packets from internet as |
425 // time elapses. | 419 // time elapses. |
426 | 420 |
427 class FrameInjectEvent : public EventWrapper { | 421 class FrameInjectEvent : public EventWrapper { |
428 public: | 422 public: |
429 FrameInjectEvent(SimulatedClockWithFrames* clock, bool stop_on_frame) | 423 FrameInjectEvent(SimulatedClockWithFrames* clock, bool stop_on_frame) |
430 : clock_(clock), stop_on_frame_(stop_on_frame) {} | 424 : clock_(clock), stop_on_frame_(stop_on_frame) {} |
431 | 425 |
432 bool Set() override { return true; } | 426 bool Set() override { return true; } |
433 | 427 |
434 EventTypeWrapper Wait(unsigned long max_time) override { | 428 EventTypeWrapper Wait(uint64_t max_time) override { |
435 if (clock_->AdvanceTimeMilliseconds(max_time, stop_on_frame_) && | 429 if (clock_->AdvanceTimeMilliseconds(max_time, stop_on_frame_) && |
436 stop_on_frame_) { | 430 stop_on_frame_) { |
437 return EventTypeWrapper::kEventSignaled; | 431 return EventTypeWrapper::kEventSignaled; |
438 } else { | 432 } else { |
439 return EventTypeWrapper::kEventTimeout; | 433 return EventTypeWrapper::kEventTimeout; |
440 } | 434 } |
441 } | 435 } |
442 | 436 |
443 private: | 437 private: |
444 SimulatedClockWithFrames* clock_; | 438 SimulatedClockWithFrames* clock_; |
445 bool stop_on_frame_; | 439 bool stop_on_frame_; |
446 }; | 440 }; |
447 | 441 |
448 class VCMReceiverTimingTest : public ::testing::Test { | 442 class VCMReceiverTimingTest : public ::testing::Test { |
449 protected: | 443 protected: |
450 | |
451 VCMReceiverTimingTest() | 444 VCMReceiverTimingTest() |
452 | 445 |
453 : clock_(&stream_generator_, &receiver_), | 446 : clock_(&stream_generator_, &receiver_), |
454 stream_generator_(0, clock_.TimeInMilliseconds()), | 447 stream_generator_(0, clock_.TimeInMilliseconds()), |
455 timing_(&clock_), | 448 timing_(&clock_), |
456 receiver_( | 449 receiver_( |
457 &timing_, | 450 &timing_, |
458 &clock_, | 451 &clock_, |
459 rtc::scoped_ptr<EventWrapper>(new FrameInjectEvent(&clock_, false)), | 452 rtc::scoped_ptr<EventWrapper>(new FrameInjectEvent(&clock_, false)), |
460 rtc::scoped_ptr<EventWrapper>( | 453 rtc::scoped_ptr<EventWrapper>( |
461 new FrameInjectEvent(&clock_, true))) {} | 454 new FrameInjectEvent(&clock_, true))) {} |
462 | 455 |
463 | |
464 virtual void SetUp() { receiver_.Reset(); } | 456 virtual void SetUp() { receiver_.Reset(); } |
465 | 457 |
466 SimulatedClockWithFrames clock_; | 458 SimulatedClockWithFrames clock_; |
467 StreamGenerator stream_generator_; | 459 StreamGenerator stream_generator_; |
468 VCMTiming timing_; | 460 VCMTiming timing_; |
469 VCMReceiver receiver_; | 461 VCMReceiver receiver_; |
470 }; | 462 }; |
471 | 463 |
472 // Test whether VCMReceiver::FrameForDecoding handles parameter | 464 // Test whether VCMReceiver::FrameForDecoding handles parameter |
473 // |max_wait_time_ms| correctly: | 465 // |max_wait_time_ms| correctly: |
(...skipping 25 matching lines...) Expand all Loading... |
499 size_t num_frames_return = 0; | 491 size_t num_frames_return = 0; |
500 | 492 |
501 const int64_t kMaxWaitTime = 30; | 493 const int64_t kMaxWaitTime = 30; |
502 | 494 |
503 // Ideally, we should get all frames that we input in InitializeFrames. | 495 // Ideally, we should get all frames that we input in InitializeFrames. |
504 // In the case that FrameForDecoding kills frames by error, we rely on the | 496 // In the case that FrameForDecoding kills frames by error, we rely on the |
505 // build bot to kill the test. | 497 // build bot to kill the test. |
506 while (num_frames_return < kNumFrames) { | 498 while (num_frames_return < kNumFrames) { |
507 int64_t start_time = clock_.TimeInMilliseconds(); | 499 int64_t start_time = clock_.TimeInMilliseconds(); |
508 VCMEncodedFrame* frame = | 500 VCMEncodedFrame* frame = |
509 receiver_.FrameForDecoding(kMaxWaitTime, next_render_time, false); | 501 receiver_.FrameForDecoding(kMaxWaitTime, &next_render_time, false); |
510 int64_t end_time = clock_.TimeInMilliseconds(); | 502 int64_t end_time = clock_.TimeInMilliseconds(); |
511 | 503 |
512 // In any case the FrameForDecoding should not wait longer than | 504 // In any case the FrameForDecoding should not wait longer than |
513 // max_wait_time. | 505 // max_wait_time. |
514 // In the case that we did not get a frame, it should have been waiting for | 506 // In the case that we did not get a frame, it should have been waiting for |
515 // exactly max_wait_time. (By the testing samples we constructed above, we | 507 // exactly max_wait_time. (By the testing samples we constructed above, we |
516 // are sure there is no timing error, so the only case it returns with NULL | 508 // are sure there is no timing error, so the only case it returns with NULL |
517 // is that it runs out of time.) | 509 // is that it runs out of time.) |
518 if (frame) { | 510 if (frame) { |
519 receiver_.ReleaseFrame(frame); | 511 receiver_.ReleaseFrame(frame); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 | 551 |
560 clock_.SetFrames(arrive_timestamps, render_timestamps, kNumFrames); | 552 clock_.SetFrames(arrive_timestamps, render_timestamps, kNumFrames); |
561 | 553 |
562 // Record how many frames we finally get out of the receiver. | 554 // Record how many frames we finally get out of the receiver. |
563 size_t num_frames_return = 0; | 555 size_t num_frames_return = 0; |
564 const int64_t kMaxWaitTime = 30; | 556 const int64_t kMaxWaitTime = 30; |
565 bool prefer_late_decoding = true; | 557 bool prefer_late_decoding = true; |
566 while (num_frames_return < kNumFrames) { | 558 while (num_frames_return < kNumFrames) { |
567 int64_t start_time = clock_.TimeInMilliseconds(); | 559 int64_t start_time = clock_.TimeInMilliseconds(); |
568 | 560 |
569 VCMEncodedFrame* frame = | 561 VCMEncodedFrame* frame = receiver_.FrameForDecoding( |
570 receiver_.FrameForDecoding(kMaxWaitTime, next_render_time, | 562 kMaxWaitTime, &next_render_time, prefer_late_decoding); |
571 prefer_late_decoding); | |
572 int64_t end_time = clock_.TimeInMilliseconds(); | 563 int64_t end_time = clock_.TimeInMilliseconds(); |
573 if (frame) { | 564 if (frame) { |
574 EXPECT_EQ(frame->RenderTimeMs() - max_decode_ms - render_delay_ms, | 565 EXPECT_EQ(frame->RenderTimeMs() - max_decode_ms - render_delay_ms, |
575 end_time); | 566 end_time); |
576 receiver_.ReleaseFrame(frame); | 567 receiver_.ReleaseFrame(frame); |
577 ++num_frames_return; | 568 ++num_frames_return; |
578 } else { | 569 } else { |
579 EXPECT_EQ(kMaxWaitTime, end_time - start_time); | 570 EXPECT_EQ(kMaxWaitTime, end_time - start_time); |
580 } | 571 } |
581 } | 572 } |
582 } | 573 } |
583 | 574 |
584 } // namespace webrtc | 575 } // namespace webrtc |
OLD | NEW |