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

Side by Side Diff: webrtc/modules/video_coding/main/source/jitter_buffer_unittest.cc

Issue 1417283007: modules/video_coding refactorings (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Fix the other copy of the mock include header Created 5 years, 1 month 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
(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 <string.h>
12
13 #include <list>
14
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "webrtc/modules/video_coding/main/source/frame_buffer.h"
17 #include "webrtc/modules/video_coding/main/source/jitter_buffer.h"
18 #include "webrtc/modules/video_coding/main/source/media_opt_util.h"
19 #include "webrtc/modules/video_coding/main/source/packet.h"
20 #include "webrtc/modules/video_coding/main/source/test/stream_generator.h"
21 #include "webrtc/modules/video_coding/main/test/test_util.h"
22 #include "webrtc/system_wrappers/include/clock.h"
23 #include "webrtc/system_wrappers/include/metrics.h"
24 #include "webrtc/test/histogram.h"
25
26 namespace webrtc {
27
28 namespace {
29 const uint32_t kProcessIntervalSec = 60;
30 } // namespace
31
32 class Vp9SsMapTest : public ::testing::Test {
33 protected:
34 Vp9SsMapTest()
35 : packet_(data_, 1400, 1234, 1, true) {}
36
37 virtual void SetUp() {
38 packet_.isFirstPacket = true;
39 packet_.markerBit = true;
40 packet_.frameType = kVideoFrameKey;
41 packet_.codec = kVideoCodecVP9;
42 packet_.codecSpecificHeader.codec = kRtpVideoVp9;
43 packet_.codecSpecificHeader.codecHeader.VP9.flexible_mode = false;
44 packet_.codecSpecificHeader.codecHeader.VP9.gof_idx = 0;
45 packet_.codecSpecificHeader.codecHeader.VP9.temporal_idx = kNoTemporalIdx;
46 packet_.codecSpecificHeader.codecHeader.VP9.temporal_up_switch = false;
47 packet_.codecSpecificHeader.codecHeader.VP9.ss_data_available = true;
48 packet_.codecSpecificHeader.codecHeader.VP9.gof.SetGofInfoVP9(
49 kTemporalStructureMode3); // kTemporalStructureMode3: 0-2-1-2..
50 }
51
52 Vp9SsMap map_;
53 uint8_t data_[1500];
54 VCMPacket packet_;
55 };
56
57 TEST_F(Vp9SsMapTest, Insert) {
58 EXPECT_TRUE(map_.Insert(packet_));
59 }
60
61 TEST_F(Vp9SsMapTest, Insert_NoSsData) {
62 packet_.codecSpecificHeader.codecHeader.VP9.ss_data_available = false;
63 EXPECT_FALSE(map_.Insert(packet_));
64 }
65
66 TEST_F(Vp9SsMapTest, Find) {
67 EXPECT_TRUE(map_.Insert(packet_));
68 Vp9SsMap::SsMap::iterator it;
69 EXPECT_TRUE(map_.Find(packet_.timestamp, &it));
70 EXPECT_EQ(packet_.timestamp, it->first);
71 }
72
73 TEST_F(Vp9SsMapTest, Find_WithWrap) {
74 const uint32_t kSsTimestamp1 = 0xFFFFFFFF;
75 const uint32_t kSsTimestamp2 = 100;
76 packet_.timestamp = kSsTimestamp1;
77 EXPECT_TRUE(map_.Insert(packet_));
78 packet_.timestamp = kSsTimestamp2;
79 EXPECT_TRUE(map_.Insert(packet_));
80 Vp9SsMap::SsMap::iterator it;
81 EXPECT_FALSE(map_.Find(kSsTimestamp1 - 1, &it));
82 EXPECT_TRUE(map_.Find(kSsTimestamp1, &it));
83 EXPECT_EQ(kSsTimestamp1, it->first);
84 EXPECT_TRUE(map_.Find(0, &it));
85 EXPECT_EQ(kSsTimestamp1, it->first);
86 EXPECT_TRUE(map_.Find(kSsTimestamp2 - 1, &it));
87 EXPECT_EQ(kSsTimestamp1, it->first);
88 EXPECT_TRUE(map_.Find(kSsTimestamp2, &it));
89 EXPECT_EQ(kSsTimestamp2, it->first);
90 EXPECT_TRUE(map_.Find(kSsTimestamp2 + 1, &it));
91 EXPECT_EQ(kSsTimestamp2, it->first);
92 }
93
94 TEST_F(Vp9SsMapTest, Reset) {
95 EXPECT_TRUE(map_.Insert(packet_));
96 Vp9SsMap::SsMap::iterator it;
97 EXPECT_TRUE(map_.Find(packet_.timestamp, &it));
98 EXPECT_EQ(packet_.timestamp, it->first);
99
100 map_.Reset();
101 EXPECT_FALSE(map_.Find(packet_.timestamp, &it));
102 }
103
104 TEST_F(Vp9SsMapTest, RemoveOld) {
105 Vp9SsMap::SsMap::iterator it;
106 const uint32_t kSsTimestamp1 = 10000;
107 packet_.timestamp = kSsTimestamp1;
108 EXPECT_TRUE(map_.Insert(packet_));
109
110 const uint32_t kTimestamp = kSsTimestamp1 + kProcessIntervalSec * 90000;
111 map_.RemoveOld(kTimestamp - 1); // Interval not passed.
112 EXPECT_TRUE(map_.Find(kSsTimestamp1, &it)); // Should not been removed.
113
114 map_.RemoveOld(kTimestamp);
115 EXPECT_FALSE(map_.Find(kSsTimestamp1, &it));
116 EXPECT_TRUE(map_.Find(kTimestamp, &it));
117 EXPECT_EQ(kTimestamp, it->first);
118 }
119
120 TEST_F(Vp9SsMapTest, RemoveOld_WithWrap) {
121 Vp9SsMap::SsMap::iterator it;
122 const uint32_t kSsTimestamp1 = 0xFFFFFFFF - kProcessIntervalSec * 90000;
123 const uint32_t kSsTimestamp2 = 10;
124 const uint32_t kSsTimestamp3 = 1000;
125 packet_.timestamp = kSsTimestamp1;
126 EXPECT_TRUE(map_.Insert(packet_));
127 packet_.timestamp = kSsTimestamp2;
128 EXPECT_TRUE(map_.Insert(packet_));
129 packet_.timestamp = kSsTimestamp3;
130 EXPECT_TRUE(map_.Insert(packet_));
131
132 map_.RemoveOld(kSsTimestamp3);
133 EXPECT_FALSE(map_.Find(kSsTimestamp1, &it));
134 EXPECT_FALSE(map_.Find(kSsTimestamp2, &it));
135 EXPECT_TRUE(map_.Find(kSsTimestamp3, &it));
136 }
137
138 TEST_F(Vp9SsMapTest, UpdatePacket_NoSsData) {
139 packet_.codecSpecificHeader.codecHeader.VP9.gof_idx = 0;
140 EXPECT_FALSE(map_.UpdatePacket(&packet_));
141 }
142
143 TEST_F(Vp9SsMapTest, UpdatePacket_NoGofIdx) {
144 EXPECT_TRUE(map_.Insert(packet_));
145 packet_.codecSpecificHeader.codecHeader.VP9.gof_idx = kNoGofIdx;
146 EXPECT_FALSE(map_.UpdatePacket(&packet_));
147 }
148
149 TEST_F(Vp9SsMapTest, UpdatePacket_InvalidGofIdx) {
150 EXPECT_TRUE(map_.Insert(packet_));
151 packet_.codecSpecificHeader.codecHeader.VP9.gof_idx = 4;
152 EXPECT_FALSE(map_.UpdatePacket(&packet_));
153 }
154
155 TEST_F(Vp9SsMapTest, UpdatePacket) {
156 EXPECT_TRUE(map_.Insert(packet_)); // kTemporalStructureMode3: 0-2-1-2..
157
158 packet_.codecSpecificHeader.codecHeader.VP9.gof_idx = 0;
159 EXPECT_TRUE(map_.UpdatePacket(&packet_));
160 EXPECT_EQ(0, packet_.codecSpecificHeader.codecHeader.VP9.temporal_idx);
161 EXPECT_FALSE(packet_.codecSpecificHeader.codecHeader.VP9.temporal_up_switch);
162 EXPECT_EQ(1U, packet_.codecSpecificHeader.codecHeader.VP9.num_ref_pics);
163 EXPECT_EQ(4, packet_.codecSpecificHeader.codecHeader.VP9.pid_diff[0]);
164
165 packet_.codecSpecificHeader.codecHeader.VP9.gof_idx = 1;
166 EXPECT_TRUE(map_.UpdatePacket(&packet_));
167 EXPECT_EQ(2, packet_.codecSpecificHeader.codecHeader.VP9.temporal_idx);
168 EXPECT_TRUE(packet_.codecSpecificHeader.codecHeader.VP9.temporal_up_switch);
169 EXPECT_EQ(1U, packet_.codecSpecificHeader.codecHeader.VP9.num_ref_pics);
170 EXPECT_EQ(1, packet_.codecSpecificHeader.codecHeader.VP9.pid_diff[0]);
171
172 packet_.codecSpecificHeader.codecHeader.VP9.gof_idx = 2;
173 EXPECT_TRUE(map_.UpdatePacket(&packet_));
174 EXPECT_EQ(1, packet_.codecSpecificHeader.codecHeader.VP9.temporal_idx);
175 EXPECT_TRUE(packet_.codecSpecificHeader.codecHeader.VP9.temporal_up_switch);
176 EXPECT_EQ(1U, packet_.codecSpecificHeader.codecHeader.VP9.num_ref_pics);
177 EXPECT_EQ(2, packet_.codecSpecificHeader.codecHeader.VP9.pid_diff[0]);
178
179 packet_.codecSpecificHeader.codecHeader.VP9.gof_idx = 3;
180 EXPECT_TRUE(map_.UpdatePacket(&packet_));
181 EXPECT_EQ(2, packet_.codecSpecificHeader.codecHeader.VP9.temporal_idx);
182 EXPECT_FALSE(packet_.codecSpecificHeader.codecHeader.VP9.temporal_up_switch);
183 EXPECT_EQ(2U, packet_.codecSpecificHeader.codecHeader.VP9.num_ref_pics);
184 EXPECT_EQ(1, packet_.codecSpecificHeader.codecHeader.VP9.pid_diff[0]);
185 EXPECT_EQ(2, packet_.codecSpecificHeader.codecHeader.VP9.pid_diff[1]);
186 }
187
188 class TestBasicJitterBuffer : public ::testing::Test {
189 protected:
190 virtual void SetUp() {
191 clock_.reset(new SimulatedClock(0));
192 jitter_buffer_.reset(new VCMJitterBuffer(
193 clock_.get(),
194 rtc::scoped_ptr<EventWrapper>(event_factory_.CreateEvent())));
195 jitter_buffer_->Start();
196 seq_num_ = 1234;
197 timestamp_ = 0;
198 size_ = 1400;
199 // Data vector - 0, 0, 0x80, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0x80, 3....
200 data_[0] = 0;
201 data_[1] = 0;
202 data_[2] = 0x80;
203 int count = 3;
204 for (unsigned int i = 3; i < sizeof(data_) - 3; ++i) {
205 data_[i] = count;
206 count++;
207 if (count == 10) {
208 data_[i + 1] = 0;
209 data_[i + 2] = 0;
210 data_[i + 3] = 0x80;
211 count = 3;
212 i += 3;
213 }
214 }
215 packet_.reset(new VCMPacket(data_, size_, seq_num_, timestamp_, true));
216 }
217
218 VCMEncodedFrame* DecodeCompleteFrame() {
219 uint32_t timestamp = 0;
220 bool found_frame = jitter_buffer_->NextCompleteTimestamp(10, &timestamp);
221 if (!found_frame)
222 return NULL;
223 VCMEncodedFrame* frame = jitter_buffer_->ExtractAndSetDecode(timestamp);
224 return frame;
225 }
226
227 VCMEncodedFrame* DecodeIncompleteFrame() {
228 uint32_t timestamp = 0;
229 bool found_frame = jitter_buffer_->NextMaybeIncompleteTimestamp(&timestamp);
230 if (!found_frame)
231 return NULL;
232 VCMEncodedFrame* frame = jitter_buffer_->ExtractAndSetDecode(timestamp);
233 return frame;
234 }
235
236 void CheckOutFrame(VCMEncodedFrame* frame_out,
237 unsigned int size,
238 bool startCode) {
239 ASSERT_TRUE(frame_out);
240
241 const uint8_t* outData = frame_out->Buffer();
242 unsigned int i = 0;
243
244 if (startCode) {
245 EXPECT_EQ(0, outData[0]);
246 EXPECT_EQ(0, outData[1]);
247 EXPECT_EQ(0, outData[2]);
248 EXPECT_EQ(1, outData[3]);
249 i += 4;
250 }
251
252 EXPECT_EQ(size, frame_out->Length());
253 int count = 3;
254 for (; i < size; i++) {
255 if (outData[i] == 0 && outData[i + 1] == 0 && outData[i + 2] == 0x80) {
256 i += 2;
257 } else if (startCode && outData[i] == 0 && outData[i + 1] == 0) {
258 EXPECT_EQ(0, outData[0]);
259 EXPECT_EQ(0, outData[1]);
260 EXPECT_EQ(0, outData[2]);
261 EXPECT_EQ(1, outData[3]);
262 i += 3;
263 } else {
264 EXPECT_EQ(count, outData[i]);
265 count++;
266 if (count == 10) {
267 count = 3;
268 }
269 }
270 }
271 }
272
273 uint16_t seq_num_;
274 uint32_t timestamp_;
275 int size_;
276 uint8_t data_[1500];
277 rtc::scoped_ptr<VCMPacket> packet_;
278 rtc::scoped_ptr<SimulatedClock> clock_;
279 NullEventFactory event_factory_;
280 rtc::scoped_ptr<VCMJitterBuffer> jitter_buffer_;
281 };
282
283
284 class TestRunningJitterBuffer : public ::testing::Test {
285 protected:
286 enum { kDataBufferSize = 10 };
287
288 virtual void SetUp() {
289 clock_.reset(new SimulatedClock(0));
290 max_nack_list_size_ = 150;
291 oldest_packet_to_nack_ = 250;
292 jitter_buffer_ = new VCMJitterBuffer(
293 clock_.get(),
294 rtc::scoped_ptr<EventWrapper>(event_factory_.CreateEvent()));
295 stream_generator_ = new StreamGenerator(0, clock_->TimeInMilliseconds());
296 jitter_buffer_->Start();
297 jitter_buffer_->SetNackSettings(max_nack_list_size_,
298 oldest_packet_to_nack_, 0);
299 memset(data_buffer_, 0, kDataBufferSize);
300 }
301
302 virtual void TearDown() {
303 jitter_buffer_->Stop();
304 delete stream_generator_;
305 delete jitter_buffer_;
306 }
307
308 VCMFrameBufferEnum InsertPacketAndPop(int index) {
309 VCMPacket packet;
310 packet.dataPtr = data_buffer_;
311 bool packet_available = stream_generator_->PopPacket(&packet, index);
312 EXPECT_TRUE(packet_available);
313 if (!packet_available)
314 return kGeneralError; // Return here to avoid crashes below.
315 bool retransmitted = false;
316 return jitter_buffer_->InsertPacket(packet, &retransmitted);
317 }
318
319 VCMFrameBufferEnum InsertPacket(int index) {
320 VCMPacket packet;
321 packet.dataPtr = data_buffer_;
322 bool packet_available = stream_generator_->GetPacket(&packet, index);
323 EXPECT_TRUE(packet_available);
324 if (!packet_available)
325 return kGeneralError; // Return here to avoid crashes below.
326 bool retransmitted = false;
327 return jitter_buffer_->InsertPacket(packet, &retransmitted);
328 }
329
330 VCMFrameBufferEnum InsertFrame(FrameType frame_type) {
331 stream_generator_->GenerateFrame(
332 frame_type, (frame_type != kEmptyFrame) ? 1 : 0,
333 (frame_type == kEmptyFrame) ? 1 : 0, clock_->TimeInMilliseconds());
334 VCMFrameBufferEnum ret = InsertPacketAndPop(0);
335 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs);
336 return ret;
337 }
338
339 VCMFrameBufferEnum InsertFrames(int num_frames, FrameType frame_type) {
340 VCMFrameBufferEnum ret_for_all = kNoError;
341 for (int i = 0; i < num_frames; ++i) {
342 VCMFrameBufferEnum ret = InsertFrame(frame_type);
343 if (ret < kNoError) {
344 ret_for_all = ret;
345 } else if (ret_for_all >= kNoError) {
346 ret_for_all = ret;
347 }
348 }
349 return ret_for_all;
350 }
351
352 void DropFrame(int num_packets) {
353 stream_generator_->GenerateFrame(kVideoFrameDelta, num_packets, 0,
354 clock_->TimeInMilliseconds());
355 for (int i = 0; i < num_packets; ++i)
356 stream_generator_->DropLastPacket();
357 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs);
358 }
359
360 bool DecodeCompleteFrame() {
361 uint32_t timestamp = 0;
362 bool found_frame = jitter_buffer_->NextCompleteTimestamp(0, &timestamp);
363 if (!found_frame)
364 return false;
365
366 VCMEncodedFrame* frame = jitter_buffer_->ExtractAndSetDecode(timestamp);
367 bool ret = (frame != NULL);
368 jitter_buffer_->ReleaseFrame(frame);
369 return ret;
370 }
371
372 bool DecodeIncompleteFrame() {
373 uint32_t timestamp = 0;
374 bool found_frame = jitter_buffer_->NextMaybeIncompleteTimestamp(&timestamp);
375 if (!found_frame)
376 return false;
377 VCMEncodedFrame* frame = jitter_buffer_->ExtractAndSetDecode(timestamp);
378 bool ret = (frame != NULL);
379 jitter_buffer_->ReleaseFrame(frame);
380 return ret;
381 }
382
383 VCMJitterBuffer* jitter_buffer_;
384 StreamGenerator* stream_generator_;
385 rtc::scoped_ptr<SimulatedClock> clock_;
386 NullEventFactory event_factory_;
387 size_t max_nack_list_size_;
388 int oldest_packet_to_nack_;
389 uint8_t data_buffer_[kDataBufferSize];
390 };
391
392 class TestJitterBufferNack : public TestRunningJitterBuffer {
393 protected:
394 virtual void SetUp() {
395 TestRunningJitterBuffer::SetUp();
396 jitter_buffer_->SetNackMode(kNack, -1, -1);
397 }
398
399 virtual void TearDown() {
400 TestRunningJitterBuffer::TearDown();
401 }
402 };
403
404 TEST_F(TestBasicJitterBuffer, StopRunning) {
405 jitter_buffer_->Stop();
406 EXPECT_TRUE(NULL == DecodeCompleteFrame());
407 EXPECT_TRUE(NULL == DecodeIncompleteFrame());
408 jitter_buffer_->Start();
409 // Allow selective errors.
410 jitter_buffer_->SetDecodeErrorMode(kSelectiveErrors);
411
412 // No packets inserted.
413 EXPECT_TRUE(NULL == DecodeCompleteFrame());
414 EXPECT_TRUE(NULL == DecodeIncompleteFrame());
415
416 // Allow decoding with errors.
417 jitter_buffer_->SetDecodeErrorMode(kWithErrors);
418
419 // No packets inserted.
420 EXPECT_TRUE(NULL == DecodeCompleteFrame());
421 EXPECT_TRUE(NULL == DecodeIncompleteFrame());
422 }
423
424 TEST_F(TestBasicJitterBuffer, SinglePacketFrame) {
425 // Always start with a complete key frame when not allowing errors.
426 jitter_buffer_->SetDecodeErrorMode(kNoErrors);
427 packet_->frameType = kVideoFrameKey;
428 packet_->isFirstPacket = true;
429 packet_->markerBit = true;
430 packet_->timestamp += 123 * 90;
431
432 // Insert the packet to the jitter buffer and get a frame.
433 bool retransmitted = false;
434 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
435 &retransmitted));
436 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
437 CheckOutFrame(frame_out, size_, false);
438 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
439 jitter_buffer_->ReleaseFrame(frame_out);
440 }
441
442 TEST_F(TestBasicJitterBuffer, VerifyHistogramStats) {
443 test::ClearHistograms();
444 // Always start with a complete key frame when not allowing errors.
445 jitter_buffer_->SetDecodeErrorMode(kNoErrors);
446 packet_->frameType = kVideoFrameKey;
447 packet_->isFirstPacket = true;
448 packet_->markerBit = true;
449 packet_->timestamp += 123 * 90;
450
451 // Insert single packet frame to the jitter buffer and get a frame.
452 bool retransmitted = false;
453 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
454 &retransmitted));
455 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
456 CheckOutFrame(frame_out, size_, false);
457 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
458 jitter_buffer_->ReleaseFrame(frame_out);
459
460 // Verify that histograms are updated when the jitter buffer is stopped.
461 clock_->AdvanceTimeMilliseconds(metrics::kMinRunTimeInSeconds * 1000);
462 jitter_buffer_->Stop();
463 EXPECT_EQ(0, test::LastHistogramSample(
464 "WebRTC.Video.DiscardedPacketsInPercent"));
465 EXPECT_EQ(0, test::LastHistogramSample(
466 "WebRTC.Video.DuplicatedPacketsInPercent"));
467 EXPECT_NE(-1, test::LastHistogramSample(
468 "WebRTC.Video.CompleteFramesReceivedPerSecond"));
469 EXPECT_EQ(1000, test::LastHistogramSample(
470 "WebRTC.Video.KeyFramesReceivedInPermille"));
471
472 // Verify that histograms are not updated if stop is called again.
473 jitter_buffer_->Stop();
474 EXPECT_EQ(1, test::NumHistogramSamples(
475 "WebRTC.Video.DiscardedPacketsInPercent"));
476 EXPECT_EQ(1, test::NumHistogramSamples(
477 "WebRTC.Video.DuplicatedPacketsInPercent"));
478 EXPECT_EQ(1, test::NumHistogramSamples(
479 "WebRTC.Video.CompleteFramesReceivedPerSecond"));
480 EXPECT_EQ(1, test::NumHistogramSamples(
481 "WebRTC.Video.KeyFramesReceivedInPermille"));
482 }
483
484 TEST_F(TestBasicJitterBuffer, DualPacketFrame) {
485 packet_->frameType = kVideoFrameKey;
486 packet_->isFirstPacket = true;
487 packet_->markerBit = false;
488
489 bool retransmitted = false;
490 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
491 &retransmitted));
492 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
493 // Should not be complete.
494 EXPECT_TRUE(frame_out == NULL);
495
496 ++seq_num_;
497 packet_->isFirstPacket = false;
498 packet_->markerBit = true;
499 packet_->seqNum = seq_num_;
500
501 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
502 &retransmitted));
503
504 frame_out = DecodeCompleteFrame();
505 CheckOutFrame(frame_out, 2 * size_, false);
506
507 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
508 jitter_buffer_->ReleaseFrame(frame_out);
509 }
510
511 TEST_F(TestBasicJitterBuffer, 100PacketKeyFrame) {
512 packet_->frameType = kVideoFrameKey;
513 packet_->isFirstPacket = true;
514 packet_->markerBit = false;
515
516 bool retransmitted = false;
517 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
518 &retransmitted));
519
520 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
521
522 // Frame should not be complete.
523 EXPECT_TRUE(frame_out == NULL);
524
525 // Insert 98 frames.
526 int loop = 0;
527 do {
528 seq_num_++;
529 packet_->isFirstPacket = false;
530 packet_->markerBit = false;
531 packet_->seqNum = seq_num_;
532
533 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
534 &retransmitted));
535 loop++;
536 } while (loop < 98);
537
538 // Insert last packet.
539 ++seq_num_;
540 packet_->isFirstPacket = false;
541 packet_->markerBit = true;
542 packet_->seqNum = seq_num_;
543
544 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
545 &retransmitted));
546
547 frame_out = DecodeCompleteFrame();
548
549 CheckOutFrame(frame_out, 100 * size_, false);
550 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
551 jitter_buffer_->ReleaseFrame(frame_out);
552 }
553
554 TEST_F(TestBasicJitterBuffer, 100PacketDeltaFrame) {
555 // Always start with a complete key frame.
556 packet_->frameType = kVideoFrameKey;
557 packet_->isFirstPacket = true;
558 packet_->markerBit = true;
559
560 bool retransmitted = false;
561 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
562 &retransmitted));
563 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
564 EXPECT_FALSE(frame_out == NULL);
565 jitter_buffer_->ReleaseFrame(frame_out);
566
567 ++seq_num_;
568 packet_->seqNum = seq_num_;
569 packet_->markerBit = false;
570 packet_->frameType = kVideoFrameDelta;
571 packet_->timestamp += 33 * 90;
572
573 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
574 &retransmitted));
575
576 frame_out = DecodeCompleteFrame();
577
578 // Frame should not be complete.
579 EXPECT_TRUE(frame_out == NULL);
580
581 packet_->isFirstPacket = false;
582 // Insert 98 frames.
583 int loop = 0;
584 do {
585 ++seq_num_;
586 packet_->seqNum = seq_num_;
587
588 // Insert a packet into a frame.
589 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
590 &retransmitted));
591 loop++;
592 } while (loop < 98);
593
594 // Insert the last packet.
595 ++seq_num_;
596 packet_->isFirstPacket = false;
597 packet_->markerBit = true;
598 packet_->seqNum = seq_num_;
599
600 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
601 &retransmitted));
602
603 frame_out = DecodeCompleteFrame();
604
605 CheckOutFrame(frame_out, 100 * size_, false);
606 EXPECT_EQ(kVideoFrameDelta, frame_out->FrameType());
607 jitter_buffer_->ReleaseFrame(frame_out);
608 }
609
610 TEST_F(TestBasicJitterBuffer, PacketReorderingReverseOrder) {
611 // Insert the "first" packet last.
612 seq_num_ += 100;
613 packet_->frameType = kVideoFrameKey;
614 packet_->isFirstPacket = false;
615 packet_->markerBit = true;
616 packet_->seqNum = seq_num_;
617 packet_->timestamp = timestamp_;
618
619 bool retransmitted = false;
620 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
621 &retransmitted));
622
623 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
624
625 EXPECT_TRUE(frame_out == NULL);
626
627 // Insert 98 packets.
628 int loop = 0;
629 do {
630 seq_num_--;
631 packet_->isFirstPacket = false;
632 packet_->markerBit = false;
633 packet_->seqNum = seq_num_;
634
635 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
636 &retransmitted));
637 loop++;
638 } while (loop < 98);
639
640 // Insert the last packet.
641 seq_num_--;
642 packet_->isFirstPacket = true;
643 packet_->markerBit = false;
644 packet_->seqNum = seq_num_;
645
646 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
647 &retransmitted));
648
649 frame_out = DecodeCompleteFrame();;
650
651 CheckOutFrame(frame_out, 100 * size_, false);
652
653 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
654 jitter_buffer_->ReleaseFrame(frame_out);
655 }
656
657 TEST_F(TestBasicJitterBuffer, FrameReordering2Frames2PacketsEach) {
658 packet_->frameType = kVideoFrameDelta;
659 packet_->isFirstPacket = true;
660 packet_->markerBit = false;
661
662 bool retransmitted = false;
663 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
664 &retransmitted));
665
666 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
667
668 EXPECT_TRUE(frame_out == NULL);
669
670 seq_num_++;
671 packet_->isFirstPacket = false;
672 packet_->markerBit = true;
673 packet_->seqNum = seq_num_;
674
675 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
676 &retransmitted));
677
678 // check that we fail to get frame since seqnum is not continuous
679 frame_out = DecodeCompleteFrame();
680 EXPECT_TRUE(frame_out == NULL);
681
682 seq_num_ -= 3;
683 timestamp_ -= 33*90;
684 packet_->frameType = kVideoFrameKey;
685 packet_->isFirstPacket = true;
686 packet_->markerBit = false;
687 packet_->seqNum = seq_num_;
688 packet_->timestamp = timestamp_;
689
690 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
691 &retransmitted));
692
693 frame_out = DecodeCompleteFrame();
694
695 // It should not be complete.
696 EXPECT_TRUE(frame_out == NULL);
697
698 seq_num_++;
699 packet_->isFirstPacket = false;
700 packet_->markerBit = true;
701 packet_->seqNum = seq_num_;
702
703 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
704 &retransmitted));
705
706 frame_out = DecodeCompleteFrame();
707 CheckOutFrame(frame_out, 2 * size_, false);
708 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
709 jitter_buffer_->ReleaseFrame(frame_out);
710
711 frame_out = DecodeCompleteFrame();
712 CheckOutFrame(frame_out, 2 * size_, false);
713 EXPECT_EQ(kVideoFrameDelta, frame_out->FrameType());
714 jitter_buffer_->ReleaseFrame(frame_out);
715 }
716
717 TEST_F(TestBasicJitterBuffer, TestReorderingWithPadding) {
718 packet_->frameType = kVideoFrameKey;
719 packet_->isFirstPacket = true;
720 packet_->markerBit = true;
721
722 // Send in an initial good packet/frame (Frame A) to start things off.
723 bool retransmitted = false;
724 EXPECT_EQ(kCompleteSession,
725 jitter_buffer_->InsertPacket(*packet_, &retransmitted));
726 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
727 EXPECT_TRUE(frame_out != NULL);
728 jitter_buffer_->ReleaseFrame(frame_out);
729
730 // Now send in a complete delta frame (Frame C), but with a sequence number
731 // gap. No pic index either, so no temporal scalability cheating :)
732 packet_->frameType = kVideoFrameDelta;
733 // Leave a gap of 2 sequence numbers and two frames.
734 packet_->seqNum = seq_num_ + 3;
735 packet_->timestamp = timestamp_ + (66 * 90);
736 // Still isFirst = marker = true.
737 // Session should be complete (frame is complete), but there's nothing to
738 // decode yet.
739 EXPECT_EQ(kCompleteSession,
740 jitter_buffer_->InsertPacket(*packet_, &retransmitted));
741 frame_out = DecodeCompleteFrame();
742 EXPECT_TRUE(frame_out == NULL);
743
744 // Now send in a complete delta frame (Frame B) that is continuous from A, but
745 // doesn't fill the full gap to C. The rest of the gap is going to be padding.
746 packet_->seqNum = seq_num_ + 1;
747 packet_->timestamp = timestamp_ + (33 * 90);
748 // Still isFirst = marker = true.
749 EXPECT_EQ(kCompleteSession,
750 jitter_buffer_->InsertPacket(*packet_, &retransmitted));
751 frame_out = DecodeCompleteFrame();
752 EXPECT_TRUE(frame_out != NULL);
753 jitter_buffer_->ReleaseFrame(frame_out);
754
755 // But Frame C isn't continuous yet.
756 frame_out = DecodeCompleteFrame();
757 EXPECT_TRUE(frame_out == NULL);
758
759 // Add in the padding. These are empty packets (data length is 0) with no
760 // marker bit and matching the timestamp of Frame B.
761 VCMPacket empty_packet(data_, 0, seq_num_ + 2, timestamp_ + (33 * 90), false);
762 EXPECT_EQ(kOldPacket,
763 jitter_buffer_->InsertPacket(empty_packet, &retransmitted));
764 empty_packet.seqNum += 1;
765 EXPECT_EQ(kOldPacket,
766 jitter_buffer_->InsertPacket(empty_packet, &retransmitted));
767
768 // But now Frame C should be ready!
769 frame_out = DecodeCompleteFrame();
770 EXPECT_TRUE(frame_out != NULL);
771 jitter_buffer_->ReleaseFrame(frame_out);
772 }
773
774 TEST_F(TestBasicJitterBuffer, DuplicatePackets) {
775 packet_->frameType = kVideoFrameKey;
776 packet_->isFirstPacket = true;
777 packet_->markerBit = false;
778 packet_->seqNum = seq_num_;
779 packet_->timestamp = timestamp_;
780 EXPECT_EQ(0, jitter_buffer_->num_packets());
781 EXPECT_EQ(0, jitter_buffer_->num_duplicated_packets());
782
783 bool retransmitted = false;
784 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
785 &retransmitted));
786
787 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
788
789 EXPECT_TRUE(frame_out == NULL);
790 EXPECT_EQ(1, jitter_buffer_->num_packets());
791 EXPECT_EQ(0, jitter_buffer_->num_duplicated_packets());
792
793 // Insert a packet into a frame.
794 EXPECT_EQ(kDuplicatePacket, jitter_buffer_->InsertPacket(*packet_,
795 &retransmitted));
796 EXPECT_EQ(2, jitter_buffer_->num_packets());
797 EXPECT_EQ(1, jitter_buffer_->num_duplicated_packets());
798
799 seq_num_++;
800 packet_->seqNum = seq_num_;
801 packet_->markerBit = true;
802 packet_->isFirstPacket = false;
803
804 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
805 &retransmitted));
806
807 frame_out = DecodeCompleteFrame();
808 ASSERT_TRUE(frame_out != NULL);
809 CheckOutFrame(frame_out, 2 * size_, false);
810
811 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
812 EXPECT_EQ(3, jitter_buffer_->num_packets());
813 EXPECT_EQ(1, jitter_buffer_->num_duplicated_packets());
814 jitter_buffer_->ReleaseFrame(frame_out);
815 }
816
817 TEST_F(TestBasicJitterBuffer, DuplicatePreviousDeltaFramePacket) {
818 packet_->frameType = kVideoFrameKey;
819 packet_->isFirstPacket = true;
820 packet_->markerBit = true;
821 packet_->seqNum = seq_num_;
822 packet_->timestamp = timestamp_;
823 jitter_buffer_->SetDecodeErrorMode(kNoErrors);
824 EXPECT_EQ(0, jitter_buffer_->num_packets());
825 EXPECT_EQ(0, jitter_buffer_->num_duplicated_packets());
826
827 bool retransmitted = false;
828 // Insert first complete frame.
829 EXPECT_EQ(kCompleteSession,
830 jitter_buffer_->InsertPacket(*packet_, &retransmitted));
831
832 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
833 ASSERT_TRUE(frame_out != NULL);
834 CheckOutFrame(frame_out, size_, false);
835 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
836 jitter_buffer_->ReleaseFrame(frame_out);
837
838 // Insert 3 delta frames.
839 for (uint16_t i = 1; i <= 3; ++i) {
840 packet_->seqNum = seq_num_ + i;
841 packet_->timestamp = timestamp_ + (i * 33) * 90;
842 packet_->frameType = kVideoFrameDelta;
843 EXPECT_EQ(kCompleteSession,
844 jitter_buffer_->InsertPacket(*packet_, &retransmitted));
845 EXPECT_EQ(i + 1, jitter_buffer_->num_packets());
846 EXPECT_EQ(0, jitter_buffer_->num_duplicated_packets());
847 }
848
849 // Retransmit second delta frame.
850 packet_->seqNum = seq_num_ + 2;
851 packet_->timestamp = timestamp_ + 66 * 90;
852
853 EXPECT_EQ(kDuplicatePacket,
854 jitter_buffer_->InsertPacket(*packet_, &retransmitted));
855
856 EXPECT_EQ(5, jitter_buffer_->num_packets());
857 EXPECT_EQ(1, jitter_buffer_->num_duplicated_packets());
858
859 // Should be able to decode 3 delta frames, key frame already decoded.
860 for (size_t i = 0; i < 3; ++i) {
861 frame_out = DecodeCompleteFrame();
862 ASSERT_TRUE(frame_out != NULL);
863 CheckOutFrame(frame_out, size_, false);
864 EXPECT_EQ(kVideoFrameDelta, frame_out->FrameType());
865 jitter_buffer_->ReleaseFrame(frame_out);
866 }
867 }
868
869 TEST_F(TestBasicJitterBuffer, TestSkipForwardVp9) {
870 // Verify that JB skips forward to next base layer frame.
871 // -------------------------------------------------
872 // | 65485 | 65486 | 65487 | 65488 | 65489 | ...
873 // | pid:5 | pid:6 | pid:7 | pid:8 | pid:9 | ...
874 // | tid:0 | tid:2 | tid:1 | tid:2 | tid:0 | ...
875 // | ss | x | x | x | |
876 // -------------------------------------------------
877 // |<----------tl0idx:200--------->|<---tl0idx:201---
878
879 bool re = false;
880 packet_->codec = kVideoCodecVP9;
881 packet_->codecSpecificHeader.codec = kRtpVideoVp9;
882 packet_->isFirstPacket = true;
883 packet_->markerBit = true;
884 packet_->codecSpecificHeader.codecHeader.VP9.flexible_mode = false;
885 packet_->codecSpecificHeader.codecHeader.VP9.spatial_idx = 0;
886 packet_->codecSpecificHeader.codecHeader.VP9.beginning_of_frame = true;
887 packet_->codecSpecificHeader.codecHeader.VP9.end_of_frame = true;
888 packet_->codecSpecificHeader.codecHeader.VP9.temporal_up_switch = false;
889
890 packet_->seqNum = 65485;
891 packet_->timestamp = 1000;
892 packet_->frameType = kVideoFrameKey;
893 packet_->codecSpecificHeader.codecHeader.VP9.picture_id = 5;
894 packet_->codecSpecificHeader.codecHeader.VP9.tl0_pic_idx = 200;
895 packet_->codecSpecificHeader.codecHeader.VP9.temporal_idx = 0;
896 packet_->codecSpecificHeader.codecHeader.VP9.ss_data_available = true;
897 packet_->codecSpecificHeader.codecHeader.VP9.gof.SetGofInfoVP9(
898 kTemporalStructureMode3); // kTemporalStructureMode3: 0-2-1-2..
899 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, &re));
900
901 // Insert next temporal layer 0.
902 packet_->seqNum = 65489;
903 packet_->timestamp = 13000;
904 packet_->frameType = kVideoFrameDelta;
905 packet_->codecSpecificHeader.codecHeader.VP9.picture_id = 9;
906 packet_->codecSpecificHeader.codecHeader.VP9.tl0_pic_idx = 201;
907 packet_->codecSpecificHeader.codecHeader.VP9.temporal_idx = 0;
908 packet_->codecSpecificHeader.codecHeader.VP9.ss_data_available = false;
909 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, &re));
910
911 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
912 EXPECT_EQ(1000U, frame_out->TimeStamp());
913 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
914 jitter_buffer_->ReleaseFrame(frame_out);
915
916 frame_out = DecodeCompleteFrame();
917 EXPECT_EQ(13000U, frame_out->TimeStamp());
918 EXPECT_EQ(kVideoFrameDelta, frame_out->FrameType());
919 jitter_buffer_->ReleaseFrame(frame_out);
920 }
921
922 TEST_F(TestBasicJitterBuffer, ReorderedVp9SsData_3TlLayers) {
923 // Verify that frames are updated with SS data when SS packet is reordered.
924 // --------------------------------
925 // | 65486 | 65487 | 65485 |...
926 // | pid:6 | pid:7 | pid:5 |...
927 // | tid:2 | tid:1 | tid:0 |...
928 // | | | ss |
929 // --------------------------------
930 // |<--------tl0idx:200--------->|
931
932 bool re = false;
933 packet_->codec = kVideoCodecVP9;
934 packet_->codecSpecificHeader.codec = kRtpVideoVp9;
935 packet_->isFirstPacket = true;
936 packet_->markerBit = true;
937 packet_->codecSpecificHeader.codecHeader.VP9.flexible_mode = false;
938 packet_->codecSpecificHeader.codecHeader.VP9.spatial_idx = 0;
939 packet_->codecSpecificHeader.codecHeader.VP9.beginning_of_frame = true;
940 packet_->codecSpecificHeader.codecHeader.VP9.end_of_frame = true;
941 packet_->codecSpecificHeader.codecHeader.VP9.tl0_pic_idx = 200;
942
943 packet_->seqNum = 65486;
944 packet_->timestamp = 6000;
945 packet_->frameType = kVideoFrameDelta;
946 packet_->codecSpecificHeader.codecHeader.VP9.picture_id = 6;
947 packet_->codecSpecificHeader.codecHeader.VP9.temporal_idx = 2;
948 packet_->codecSpecificHeader.codecHeader.VP9.temporal_up_switch = true;
949 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, &re));
950
951 packet_->seqNum = 65487;
952 packet_->timestamp = 9000;
953 packet_->frameType = kVideoFrameDelta;
954 packet_->codecSpecificHeader.codecHeader.VP9.picture_id = 7;
955 packet_->codecSpecificHeader.codecHeader.VP9.temporal_idx = 1;
956 packet_->codecSpecificHeader.codecHeader.VP9.temporal_up_switch = true;
957 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, &re));
958
959 // Insert first frame with SS data.
960 packet_->seqNum = 65485;
961 packet_->timestamp = 3000;
962 packet_->frameType = kVideoFrameKey;
963 packet_->width = 352;
964 packet_->height = 288;
965 packet_->codecSpecificHeader.codecHeader.VP9.picture_id = 5;
966 packet_->codecSpecificHeader.codecHeader.VP9.temporal_idx = 0;
967 packet_->codecSpecificHeader.codecHeader.VP9.temporal_up_switch = false;
968 packet_->codecSpecificHeader.codecHeader.VP9.ss_data_available = true;
969 packet_->codecSpecificHeader.codecHeader.VP9.gof.SetGofInfoVP9(
970 kTemporalStructureMode3); // kTemporalStructureMode3: 0-2-1-2..
971 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, &re));
972
973 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
974 EXPECT_EQ(3000U, frame_out->TimeStamp());
975 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
976 EXPECT_EQ(0, frame_out->CodecSpecific()->codecSpecific.VP9.temporal_idx);
977 EXPECT_FALSE(
978 frame_out->CodecSpecific()->codecSpecific.VP9.temporal_up_switch);
979 jitter_buffer_->ReleaseFrame(frame_out);
980
981 frame_out = DecodeCompleteFrame();
982 EXPECT_EQ(6000U, frame_out->TimeStamp());
983 EXPECT_EQ(kVideoFrameDelta, frame_out->FrameType());
984 EXPECT_EQ(2, frame_out->CodecSpecific()->codecSpecific.VP9.temporal_idx);
985 EXPECT_TRUE(frame_out->CodecSpecific()->codecSpecific.VP9.temporal_up_switch);
986 jitter_buffer_->ReleaseFrame(frame_out);
987
988 frame_out = DecodeCompleteFrame();
989 EXPECT_EQ(9000U, frame_out->TimeStamp());
990 EXPECT_EQ(kVideoFrameDelta, frame_out->FrameType());
991 EXPECT_EQ(1, frame_out->CodecSpecific()->codecSpecific.VP9.temporal_idx);
992 EXPECT_TRUE(frame_out->CodecSpecific()->codecSpecific.VP9.temporal_up_switch);
993 jitter_buffer_->ReleaseFrame(frame_out);
994 }
995
996 TEST_F(TestBasicJitterBuffer, ReorderedVp9SsData_2Tl2SLayers) {
997 // Verify that frames are updated with SS data when SS packet is reordered.
998 // -----------------------------------------
999 // | 65486 | 65487 | 65485 | 65484 |...
1000 // | pid:6 | pid:6 | pid:5 | pid:5 |...
1001 // | tid:1 | tid:1 | tid:0 | tid:0 |...
1002 // | sid:0 | sid:1 | sid:1 | sid:0 |...
1003 // | t:6000 | t:6000 | t:3000 | t:3000 |
1004 // | | | | ss |
1005 // -----------------------------------------
1006 // |<-----------tl0idx:200------------>|
1007
1008 bool re = false;
1009 packet_->codec = kVideoCodecVP9;
1010 packet_->codecSpecificHeader.codec = kRtpVideoVp9;
1011 packet_->codecSpecificHeader.codecHeader.VP9.flexible_mode = false;
1012 packet_->codecSpecificHeader.codecHeader.VP9.beginning_of_frame = true;
1013 packet_->codecSpecificHeader.codecHeader.VP9.end_of_frame = true;
1014 packet_->codecSpecificHeader.codecHeader.VP9.tl0_pic_idx = 200;
1015
1016 packet_->isFirstPacket = true;
1017 packet_->markerBit = false;
1018 packet_->seqNum = 65486;
1019 packet_->timestamp = 6000;
1020 packet_->frameType = kVideoFrameDelta;
1021 packet_->codecSpecificHeader.codecHeader.VP9.spatial_idx = 0;
1022 packet_->codecSpecificHeader.codecHeader.VP9.picture_id = 6;
1023 packet_->codecSpecificHeader.codecHeader.VP9.temporal_idx = 1;
1024 packet_->codecSpecificHeader.codecHeader.VP9.temporal_up_switch = true;
1025 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, &re));
1026
1027 packet_->isFirstPacket = false;
1028 packet_->markerBit = true;
1029 packet_->seqNum = 65487;
1030 packet_->frameType = kVideoFrameDelta;
1031 packet_->codecSpecificHeader.codecHeader.VP9.spatial_idx = 1;
1032 packet_->codecSpecificHeader.codecHeader.VP9.picture_id = 6;
1033 packet_->codecSpecificHeader.codecHeader.VP9.temporal_idx = 1;
1034 packet_->codecSpecificHeader.codecHeader.VP9.temporal_up_switch = true;
1035 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, &re));
1036
1037 packet_->isFirstPacket = false;
1038 packet_->markerBit = true;
1039 packet_->seqNum = 65485;
1040 packet_->timestamp = 3000;
1041 packet_->frameType = kVideoFrameKey;
1042 packet_->codecSpecificHeader.codecHeader.VP9.spatial_idx = 1;
1043 packet_->codecSpecificHeader.codecHeader.VP9.picture_id = 5;
1044 packet_->codecSpecificHeader.codecHeader.VP9.temporal_idx = 0;
1045 packet_->codecSpecificHeader.codecHeader.VP9.temporal_up_switch = false;
1046 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_, &re));
1047
1048 // Insert first frame with SS data.
1049 packet_->isFirstPacket = true;
1050 packet_->markerBit = false;
1051 packet_->seqNum = 65484;
1052 packet_->frameType = kVideoFrameKey;
1053 packet_->width = 352;
1054 packet_->height = 288;
1055 packet_->codecSpecificHeader.codecHeader.VP9.spatial_idx = 0;
1056 packet_->codecSpecificHeader.codecHeader.VP9.picture_id = 5;
1057 packet_->codecSpecificHeader.codecHeader.VP9.temporal_idx = 0;
1058 packet_->codecSpecificHeader.codecHeader.VP9.temporal_up_switch = false;
1059 packet_->codecSpecificHeader.codecHeader.VP9.ss_data_available = true;
1060 packet_->codecSpecificHeader.codecHeader.VP9.gof.SetGofInfoVP9(
1061 kTemporalStructureMode2); // kTemporalStructureMode3: 0-1-0-1..
1062 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_, &re));
1063
1064 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
1065 EXPECT_EQ(3000U, frame_out->TimeStamp());
1066 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
1067 EXPECT_EQ(0, frame_out->CodecSpecific()->codecSpecific.VP9.temporal_idx);
1068 EXPECT_FALSE(
1069 frame_out->CodecSpecific()->codecSpecific.VP9.temporal_up_switch);
1070 jitter_buffer_->ReleaseFrame(frame_out);
1071
1072 frame_out = DecodeCompleteFrame();
1073 EXPECT_EQ(6000U, frame_out->TimeStamp());
1074 EXPECT_EQ(kVideoFrameDelta, frame_out->FrameType());
1075 EXPECT_EQ(1, frame_out->CodecSpecific()->codecSpecific.VP9.temporal_idx);
1076 EXPECT_TRUE(frame_out->CodecSpecific()->codecSpecific.VP9.temporal_up_switch);
1077 jitter_buffer_->ReleaseFrame(frame_out);
1078 }
1079
1080 TEST_F(TestBasicJitterBuffer, H264InsertStartCode) {
1081 packet_->frameType = kVideoFrameKey;
1082 packet_->isFirstPacket = true;
1083 packet_->markerBit = false;
1084 packet_->seqNum = seq_num_;
1085 packet_->timestamp = timestamp_;
1086 packet_->insertStartCode = true;
1087
1088 bool retransmitted = false;
1089 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
1090 &retransmitted));
1091
1092 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
1093
1094 // Frame should not be complete.
1095 EXPECT_TRUE(frame_out == NULL);
1096
1097 seq_num_++;
1098 packet_->isFirstPacket = false;
1099 packet_->markerBit = true;
1100 packet_->seqNum = seq_num_;
1101
1102 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
1103 &retransmitted));
1104
1105 frame_out = DecodeCompleteFrame();
1106 CheckOutFrame(frame_out, size_ * 2 + 4 * 2, true);
1107 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
1108 jitter_buffer_->ReleaseFrame(frame_out);
1109 }
1110
1111 // Test threshold conditions of decodable state.
1112 TEST_F(TestBasicJitterBuffer, PacketLossWithSelectiveErrorsThresholdCheck) {
1113 jitter_buffer_->SetDecodeErrorMode(kSelectiveErrors);
1114 // Always start with a key frame. Use 10 packets to test Decodable State
1115 // boundaries.
1116 packet_->frameType = kVideoFrameKey;
1117 packet_->isFirstPacket = true;
1118 packet_->markerBit = false;
1119 packet_->seqNum = seq_num_;
1120 packet_->timestamp = timestamp_;
1121
1122 bool retransmitted = false;
1123 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
1124 &retransmitted));
1125 uint32_t timestamp = 0;
1126 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, &timestamp));
1127 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(&timestamp));
1128
1129 packet_->isFirstPacket = false;
1130 for (int i = 1; i < 9; ++i) {
1131 packet_->seqNum++;
1132 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
1133 &retransmitted));
1134 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, &timestamp));
1135 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(&timestamp));
1136 }
1137
1138 // last packet
1139 packet_->markerBit = true;
1140 packet_->seqNum++;
1141
1142 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
1143 &retransmitted));
1144 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
1145 CheckOutFrame(frame_out, 10 * size_, false);
1146 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
1147 jitter_buffer_->ReleaseFrame(frame_out);
1148
1149 // An incomplete frame can only be decoded once a subsequent frame has begun
1150 // to arrive. Insert packet in distant frame for this purpose.
1151 packet_->frameType = kVideoFrameDelta;
1152 packet_->isFirstPacket = true;
1153 packet_->markerBit = false;
1154 packet_->seqNum += 100;
1155 packet_->timestamp += 33 * 90 * 8;
1156
1157 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
1158 &retransmitted));
1159 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, &timestamp));
1160 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(&timestamp));
1161
1162 // Insert second frame
1163 packet_->seqNum -= 99;
1164 packet_->timestamp -= 33 * 90 * 7;
1165
1166 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
1167 &retransmitted));
1168 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, &timestamp));
1169 EXPECT_TRUE(jitter_buffer_->NextMaybeIncompleteTimestamp(&timestamp));
1170
1171 packet_->isFirstPacket = false;
1172 for (int i = 1; i < 8; ++i) {
1173 packet_->seqNum++;
1174 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
1175 &retransmitted));
1176 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, &timestamp));
1177 EXPECT_TRUE(jitter_buffer_->NextMaybeIncompleteTimestamp(&timestamp));
1178 }
1179
1180 packet_->seqNum++;
1181 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
1182 &retransmitted));
1183 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, &timestamp));
1184 EXPECT_TRUE(jitter_buffer_->NextMaybeIncompleteTimestamp(&timestamp));
1185
1186 frame_out = DecodeIncompleteFrame();
1187 ASSERT_FALSE(NULL == frame_out);
1188 CheckOutFrame(frame_out, 9 * size_, false);
1189 EXPECT_EQ(kVideoFrameDelta, frame_out->FrameType());
1190 jitter_buffer_->ReleaseFrame(frame_out);
1191
1192 packet_->markerBit = true;
1193 packet_->seqNum++;
1194 EXPECT_EQ(kOldPacket, jitter_buffer_->InsertPacket(*packet_,
1195 &retransmitted));
1196 }
1197
1198 // Make sure first packet is present before a frame can be decoded.
1199 TEST_F(TestBasicJitterBuffer, PacketLossWithSelectiveErrorsIncompleteKey) {
1200 jitter_buffer_->SetDecodeErrorMode(kSelectiveErrors);
1201 // Always start with a key frame.
1202 packet_->frameType = kVideoFrameKey;
1203 packet_->isFirstPacket = true;
1204 packet_->markerBit = true;
1205 packet_->seqNum = seq_num_;
1206 packet_->timestamp = timestamp_;
1207
1208 bool retransmitted = false;
1209 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
1210 &retransmitted));
1211 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
1212 CheckOutFrame(frame_out, size_, false);
1213 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
1214 jitter_buffer_->ReleaseFrame(frame_out);
1215
1216 // An incomplete frame can only be decoded once a subsequent frame has begun
1217 // to arrive. Insert packet in distant frame for this purpose.
1218 packet_->frameType = kVideoFrameDelta;
1219 packet_->isFirstPacket = false;
1220 packet_->markerBit = false;
1221 packet_->seqNum += 100;
1222 packet_->timestamp += 33*90*8;
1223 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
1224 &retransmitted));
1225 uint32_t timestamp;
1226 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, &timestamp));
1227 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(&timestamp));
1228
1229 // Insert second frame - an incomplete key frame.
1230 packet_->frameType = kVideoFrameKey;
1231 packet_->isFirstPacket = true;
1232 packet_->seqNum -= 99;
1233 packet_->timestamp -= 33*90*7;
1234
1235 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
1236 &retransmitted));
1237 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, &timestamp));
1238 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(&timestamp));
1239
1240 // Insert a few more packets. Make sure we're waiting for the key frame to be
1241 // complete.
1242 packet_->isFirstPacket = false;
1243 for (int i = 1; i < 5; ++i) {
1244 packet_->seqNum++;
1245 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
1246 &retransmitted));
1247 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, &timestamp));
1248 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(&timestamp));
1249 }
1250
1251 // Complete key frame.
1252 packet_->markerBit = true;
1253 packet_->seqNum++;
1254 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
1255 &retransmitted));
1256 frame_out = DecodeCompleteFrame();
1257 CheckOutFrame(frame_out, 6 * size_, false);
1258 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
1259 jitter_buffer_->ReleaseFrame(frame_out);
1260 }
1261
1262 // Make sure first packet is present before a frame can be decoded.
1263 TEST_F(TestBasicJitterBuffer, PacketLossWithSelectiveErrorsMissingFirstPacket) {
1264 jitter_buffer_->SetDecodeErrorMode(kSelectiveErrors);
1265 // Always start with a key frame.
1266 packet_->frameType = kVideoFrameKey;
1267 packet_->isFirstPacket = true;
1268 packet_->markerBit = true;
1269 packet_->seqNum = seq_num_;
1270 packet_->timestamp = timestamp_;
1271
1272 bool retransmitted = false;
1273 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
1274 &retransmitted));
1275 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
1276 CheckOutFrame(frame_out, size_, false);
1277 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
1278 jitter_buffer_->ReleaseFrame(frame_out);
1279
1280 // An incomplete frame can only be decoded once a subsequent frame has begun
1281 // to arrive. Insert packet in distant frame for this purpose.
1282 packet_->frameType = kVideoFrameDelta;
1283 packet_->isFirstPacket = false;
1284 packet_->markerBit = false;
1285 packet_->seqNum += 100;
1286 packet_->timestamp += 33*90*8;
1287 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
1288 &retransmitted));
1289 uint32_t timestamp;
1290 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, &timestamp));
1291 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(&timestamp));
1292
1293 // Insert second frame with the first packet missing. Make sure we're waiting
1294 // for the key frame to be complete.
1295 packet_->seqNum -= 98;
1296 packet_->timestamp -= 33*90*7;
1297
1298 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
1299 &retransmitted));
1300 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, &timestamp));
1301 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(&timestamp));
1302
1303 for (int i = 0; i < 5; ++i) {
1304 packet_->seqNum++;
1305 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
1306 &retransmitted));
1307 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, &timestamp));
1308 EXPECT_FALSE(jitter_buffer_->NextMaybeIncompleteTimestamp(&timestamp));
1309 }
1310
1311 // Add first packet. Frame should now be decodable, but incomplete.
1312 packet_->isFirstPacket = true;
1313 packet_->seqNum -= 6;
1314 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
1315 &retransmitted));
1316 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, &timestamp));
1317 EXPECT_TRUE(jitter_buffer_->NextMaybeIncompleteTimestamp(&timestamp));
1318
1319 frame_out = DecodeIncompleteFrame();
1320 CheckOutFrame(frame_out, 7 * size_, false);
1321 EXPECT_EQ(kVideoFrameDelta, frame_out->FrameType());
1322 jitter_buffer_->ReleaseFrame(frame_out);
1323 }
1324
1325 TEST_F(TestBasicJitterBuffer, DiscontinuousStreamWhenDecodingWithErrors) {
1326 // Will use one packet per frame.
1327 jitter_buffer_->SetDecodeErrorMode(kWithErrors);
1328 packet_->frameType = kVideoFrameKey;
1329 packet_->isFirstPacket = true;
1330 packet_->markerBit = true;
1331 packet_->seqNum = seq_num_;
1332 packet_->timestamp = timestamp_;
1333 bool retransmitted = false;
1334 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
1335 &retransmitted));
1336 uint32_t next_timestamp;
1337 EXPECT_TRUE(jitter_buffer_->NextCompleteTimestamp(0, &next_timestamp));
1338 EXPECT_EQ(packet_->timestamp, next_timestamp);
1339 VCMEncodedFrame* frame = jitter_buffer_->ExtractAndSetDecode(next_timestamp);
1340 EXPECT_TRUE(frame != NULL);
1341 jitter_buffer_->ReleaseFrame(frame);
1342
1343 // Drop a complete frame.
1344 timestamp_ += 2 * 33 * 90;
1345 seq_num_ += 2;
1346 packet_->frameType = kVideoFrameDelta;
1347 packet_->isFirstPacket = true;
1348 packet_->markerBit = false;
1349 packet_->seqNum = seq_num_;
1350 packet_->timestamp = timestamp_;
1351 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
1352 &retransmitted));
1353 // Insert a packet (so the previous one will be released).
1354 timestamp_ += 33 * 90;
1355 seq_num_ += 2;
1356 packet_->frameType = kVideoFrameDelta;
1357 packet_->isFirstPacket = true;
1358 packet_->markerBit = false;
1359 packet_->seqNum = seq_num_;
1360 packet_->timestamp = timestamp_;
1361 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
1362 &retransmitted));
1363 EXPECT_FALSE(jitter_buffer_->NextCompleteTimestamp(0, &next_timestamp));
1364 EXPECT_TRUE(jitter_buffer_->NextMaybeIncompleteTimestamp(&next_timestamp));
1365 EXPECT_EQ(packet_->timestamp - 33 * 90, next_timestamp);
1366 }
1367
1368 TEST_F(TestBasicJitterBuffer, PacketLoss) {
1369 // Verify missing packets statistics and not decodable packets statistics.
1370 // Insert 10 frames consisting of 4 packets and remove one from all of them.
1371 // The last packet is an empty (non-media) packet.
1372
1373 // Select a start seqNum which triggers a difficult wrap situation
1374 // The JB will only output (incomplete)frames if the next one has started
1375 // to arrive. Start by inserting one frame (key).
1376 jitter_buffer_->SetDecodeErrorMode(kWithErrors);
1377 seq_num_ = 0xffff - 4;
1378 seq_num_++;
1379 packet_->frameType = kVideoFrameKey;
1380 packet_->isFirstPacket = true;
1381 packet_->markerBit = false;
1382 packet_->seqNum = seq_num_;
1383 packet_->timestamp = timestamp_;
1384 packet_->completeNALU = kNaluStart;
1385
1386 bool retransmitted = false;
1387 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
1388 &retransmitted));
1389 for (int i = 0; i < 11; ++i) {
1390 webrtc::FrameType frametype = kVideoFrameDelta;
1391 seq_num_++;
1392 timestamp_ += 33*90;
1393 packet_->frameType = frametype;
1394 packet_->isFirstPacket = true;
1395 packet_->markerBit = false;
1396 packet_->seqNum = seq_num_;
1397 packet_->timestamp = timestamp_;
1398 packet_->completeNALU = kNaluStart;
1399
1400 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
1401 &retransmitted));
1402
1403 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
1404
1405 // Should not be complete.
1406 EXPECT_TRUE(frame_out == NULL);
1407
1408 seq_num_ += 2;
1409 packet_->isFirstPacket = false;
1410 packet_->markerBit = true;
1411 packet_->seqNum = seq_num_;
1412 packet_->completeNALU = kNaluEnd;
1413
1414 EXPECT_EQ(jitter_buffer_->InsertPacket(*packet_, &retransmitted),
1415 kDecodableSession);
1416
1417 // Insert an empty (non-media) packet.
1418 seq_num_++;
1419 packet_->isFirstPacket = false;
1420 packet_->markerBit = false;
1421 packet_->seqNum = seq_num_;
1422 packet_->completeNALU = kNaluEnd;
1423 packet_->frameType = kEmptyFrame;
1424
1425 EXPECT_EQ(jitter_buffer_->InsertPacket(*packet_, &retransmitted),
1426 kDecodableSession);
1427 frame_out = DecodeIncompleteFrame();
1428
1429 // One of the packets has been discarded by the jitter buffer.
1430 // Last frame can't be extracted yet.
1431 if (i < 10) {
1432 CheckOutFrame(frame_out, size_, false);
1433
1434 if (i == 0) {
1435 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
1436 } else {
1437 EXPECT_EQ(frametype, frame_out->FrameType());
1438 }
1439 EXPECT_FALSE(frame_out->Complete());
1440 EXPECT_FALSE(frame_out->MissingFrame());
1441 }
1442
1443 jitter_buffer_->ReleaseFrame(frame_out);
1444 }
1445
1446 // Insert 3 old packets and verify that we have 3 discarded packets
1447 // Match value to actual latest timestamp decoded.
1448 timestamp_ -= 33 * 90;
1449 packet_->timestamp = timestamp_ - 1000;
1450
1451 EXPECT_EQ(kOldPacket, jitter_buffer_->InsertPacket(*packet_,
1452 &retransmitted));
1453
1454 packet_->timestamp = timestamp_ - 500;
1455
1456 EXPECT_EQ(kOldPacket, jitter_buffer_->InsertPacket(*packet_,
1457 &retransmitted));
1458
1459 packet_->timestamp = timestamp_ - 100;
1460
1461 EXPECT_EQ(kOldPacket, jitter_buffer_->InsertPacket(*packet_,
1462 &retransmitted));
1463
1464 EXPECT_EQ(3, jitter_buffer_->num_discarded_packets());
1465
1466 jitter_buffer_->Flush();
1467
1468 // This statistic shouldn't be reset by a flush.
1469 EXPECT_EQ(3, jitter_buffer_->num_discarded_packets());
1470 }
1471
1472 TEST_F(TestBasicJitterBuffer, DeltaFrame100PacketsWithSeqNumWrap) {
1473 seq_num_ = 0xfff0;
1474 packet_->frameType = kVideoFrameKey;
1475 packet_->isFirstPacket = true;
1476 packet_->markerBit = false;
1477 packet_->seqNum = seq_num_;
1478 packet_->timestamp = timestamp_;
1479
1480 bool retransmitted = false;
1481 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
1482 &retransmitted));
1483
1484 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
1485
1486 EXPECT_TRUE(frame_out == NULL);
1487
1488 int loop = 0;
1489 do {
1490 seq_num_++;
1491 packet_->isFirstPacket = false;
1492 packet_->markerBit = false;
1493 packet_->seqNum = seq_num_;
1494
1495 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
1496 &retransmitted));
1497
1498 frame_out = DecodeCompleteFrame();
1499
1500 EXPECT_TRUE(frame_out == NULL);
1501
1502 loop++;
1503 } while (loop < 98);
1504
1505 seq_num_++;
1506 packet_->isFirstPacket = false;
1507 packet_->markerBit = true;
1508 packet_->seqNum = seq_num_;
1509
1510 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
1511 &retransmitted));
1512
1513 frame_out = DecodeCompleteFrame();
1514
1515 CheckOutFrame(frame_out, 100 * size_, false);
1516
1517 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
1518 jitter_buffer_->ReleaseFrame(frame_out);
1519 }
1520
1521 TEST_F(TestBasicJitterBuffer, PacketReorderingReverseWithNegSeqNumWrap) {
1522 // Insert "first" packet last seqnum.
1523 seq_num_ = 10;
1524 packet_->frameType = kVideoFrameKey;
1525 packet_->isFirstPacket = false;
1526 packet_->markerBit = true;
1527 packet_->seqNum = seq_num_;
1528
1529 bool retransmitted = false;
1530 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
1531 &retransmitted));
1532 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
1533
1534 // Should not be complete.
1535 EXPECT_TRUE(frame_out == NULL);
1536
1537 // Insert 98 frames.
1538 int loop = 0;
1539 do {
1540 seq_num_--;
1541 packet_->isFirstPacket = false;
1542 packet_->markerBit = false;
1543 packet_->seqNum = seq_num_;
1544
1545 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
1546 &retransmitted));
1547
1548 frame_out = DecodeCompleteFrame();
1549
1550 EXPECT_TRUE(frame_out == NULL);
1551
1552 loop++;
1553 } while (loop < 98);
1554
1555 // Insert last packet.
1556 seq_num_--;
1557 packet_->isFirstPacket = true;
1558 packet_->markerBit = false;
1559 packet_->seqNum = seq_num_;
1560
1561 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
1562 &retransmitted));
1563
1564 frame_out = DecodeCompleteFrame();
1565 CheckOutFrame(frame_out, 100 * size_, false);
1566 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
1567 jitter_buffer_->ReleaseFrame(frame_out);
1568 }
1569
1570 TEST_F(TestBasicJitterBuffer, TestInsertOldFrame) {
1571 // ------- -------
1572 // | 2 | | 1 |
1573 // ------- -------
1574 // t = 3000 t = 2000
1575 seq_num_ = 2;
1576 timestamp_ = 3000;
1577 packet_->frameType = kVideoFrameKey;
1578 packet_->isFirstPacket = true;
1579 packet_->markerBit = true;
1580 packet_->timestamp = timestamp_;
1581 packet_->seqNum = seq_num_;
1582
1583 bool retransmitted = false;
1584 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
1585 &retransmitted));
1586
1587 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
1588 EXPECT_EQ(3000u, frame_out->TimeStamp());
1589 CheckOutFrame(frame_out, size_, false);
1590 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
1591 jitter_buffer_->ReleaseFrame(frame_out);
1592
1593 seq_num_--;
1594 timestamp_ = 2000;
1595 packet_->frameType = kVideoFrameDelta;
1596 packet_->isFirstPacket = true;
1597 packet_->markerBit = true;
1598 packet_->seqNum = seq_num_;
1599 packet_->timestamp = timestamp_;
1600
1601 EXPECT_EQ(kOldPacket, jitter_buffer_->InsertPacket(*packet_,
1602 &retransmitted));
1603 }
1604
1605 TEST_F(TestBasicJitterBuffer, TestInsertOldFrameWithSeqNumWrap) {
1606 // ------- -------
1607 // | 2 | | 1 |
1608 // ------- -------
1609 // t = 3000 t = 0xffffff00
1610
1611 seq_num_ = 2;
1612 timestamp_ = 3000;
1613 packet_->frameType = kVideoFrameKey;
1614 packet_->isFirstPacket = true;
1615 packet_->markerBit = true;
1616 packet_->seqNum = seq_num_;
1617 packet_->timestamp = timestamp_;
1618
1619 bool retransmitted = false;
1620 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
1621 &retransmitted));
1622
1623 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
1624 EXPECT_EQ(timestamp_, frame_out->TimeStamp());
1625
1626 CheckOutFrame(frame_out, size_, false);
1627
1628 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
1629
1630 jitter_buffer_->ReleaseFrame(frame_out);
1631
1632 seq_num_--;
1633 timestamp_ = 0xffffff00;
1634 packet_->frameType = kVideoFrameDelta;
1635 packet_->isFirstPacket = true;
1636 packet_->markerBit = true;
1637 packet_->seqNum = seq_num_;
1638 packet_->timestamp = timestamp_;
1639
1640
1641 // This timestamp is old.
1642 EXPECT_EQ(kOldPacket, jitter_buffer_->InsertPacket(*packet_,
1643 &retransmitted));
1644 }
1645
1646 TEST_F(TestBasicJitterBuffer, TimestampWrap) {
1647 // --------------- ---------------
1648 // | 1 | 2 | | 3 | 4 |
1649 // --------------- ---------------
1650 // t = 0xffffff00 t = 33*90
1651
1652 timestamp_ = 0xffffff00;
1653 packet_->frameType = kVideoFrameKey;
1654 packet_->isFirstPacket = true;
1655 packet_->markerBit = false;
1656 packet_->seqNum = seq_num_;
1657 packet_->timestamp = timestamp_;
1658
1659 bool retransmitted = false;
1660 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
1661 &retransmitted));
1662
1663 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
1664 EXPECT_TRUE(frame_out == NULL);
1665
1666 seq_num_++;
1667 packet_->isFirstPacket = false;
1668 packet_->markerBit = true;
1669 packet_->seqNum = seq_num_;
1670
1671 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
1672 &retransmitted));
1673
1674 frame_out = DecodeCompleteFrame();
1675 CheckOutFrame(frame_out, 2 * size_, false);
1676 jitter_buffer_->ReleaseFrame(frame_out);
1677
1678 seq_num_++;
1679 timestamp_ += 33*90;
1680 packet_->frameType = kVideoFrameDelta;
1681 packet_->isFirstPacket = true;
1682 packet_->markerBit = false;
1683 packet_->seqNum = seq_num_;
1684 packet_->timestamp = timestamp_;
1685
1686 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
1687 &retransmitted));
1688
1689 frame_out = DecodeCompleteFrame();
1690 EXPECT_TRUE(frame_out == NULL);
1691
1692 seq_num_++;
1693 packet_->isFirstPacket = false;
1694 packet_->markerBit = true;
1695 packet_->seqNum = seq_num_;
1696
1697 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
1698 &retransmitted));
1699
1700 frame_out = DecodeCompleteFrame();
1701 CheckOutFrame(frame_out, 2 * size_, false);
1702 EXPECT_EQ(kVideoFrameDelta, frame_out->FrameType());
1703 jitter_buffer_->ReleaseFrame(frame_out);
1704 }
1705
1706 TEST_F(TestBasicJitterBuffer, 2FrameWithTimestampWrap) {
1707 // ------- -------
1708 // | 1 | | 2 |
1709 // ------- -------
1710 // t = 0xffffff00 t = 2700
1711
1712 timestamp_ = 0xffffff00;
1713 packet_->frameType = kVideoFrameKey;
1714 packet_->isFirstPacket = true;
1715 packet_->markerBit = true;
1716 packet_->timestamp = timestamp_;
1717
1718 bool retransmitted = false;
1719 // Insert first frame (session will be complete).
1720 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
1721 &retransmitted));
1722
1723 // Insert next frame.
1724 seq_num_++;
1725 timestamp_ = 2700;
1726 packet_->frameType = kVideoFrameDelta;
1727 packet_->isFirstPacket = true;
1728 packet_->markerBit = true;
1729 packet_->seqNum = seq_num_;
1730 packet_->timestamp = timestamp_;
1731
1732 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
1733 &retransmitted));
1734
1735 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
1736 EXPECT_EQ(0xffffff00, frame_out->TimeStamp());
1737 CheckOutFrame(frame_out, size_, false);
1738 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
1739 jitter_buffer_->ReleaseFrame(frame_out);
1740
1741 VCMEncodedFrame* frame_out2 = DecodeCompleteFrame();
1742 EXPECT_EQ(2700u, frame_out2->TimeStamp());
1743 CheckOutFrame(frame_out2, size_, false);
1744 EXPECT_EQ(kVideoFrameDelta, frame_out2->FrameType());
1745 jitter_buffer_->ReleaseFrame(frame_out2);
1746 }
1747
1748 TEST_F(TestBasicJitterBuffer, Insert2FramesReOrderedWithTimestampWrap) {
1749 // ------- -------
1750 // | 2 | | 1 |
1751 // ------- -------
1752 // t = 2700 t = 0xffffff00
1753
1754 seq_num_ = 2;
1755 timestamp_ = 2700;
1756 packet_->frameType = kVideoFrameDelta;
1757 packet_->isFirstPacket = true;
1758 packet_->markerBit = true;
1759 packet_->seqNum = seq_num_;
1760 packet_->timestamp = timestamp_;
1761
1762 bool retransmitted = false;
1763 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
1764 &retransmitted));
1765
1766 // Insert second frame
1767 seq_num_--;
1768 timestamp_ = 0xffffff00;
1769 packet_->frameType = kVideoFrameKey;
1770 packet_->isFirstPacket = true;
1771 packet_->markerBit = true;
1772 packet_->seqNum = seq_num_;
1773 packet_->timestamp = timestamp_;
1774
1775 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
1776 &retransmitted));
1777
1778 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
1779 EXPECT_EQ(0xffffff00, frame_out->TimeStamp());
1780 CheckOutFrame(frame_out, size_, false);
1781 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
1782 jitter_buffer_->ReleaseFrame(frame_out);
1783
1784 VCMEncodedFrame* frame_out2 = DecodeCompleteFrame();
1785 EXPECT_EQ(2700u, frame_out2->TimeStamp());
1786 CheckOutFrame(frame_out2, size_, false);
1787 EXPECT_EQ(kVideoFrameDelta, frame_out2->FrameType());
1788 jitter_buffer_->ReleaseFrame(frame_out2);
1789 }
1790
1791 TEST_F(TestBasicJitterBuffer, DeltaFrameWithMoreThanMaxNumberOfPackets) {
1792 int loop = 0;
1793 bool firstPacket = true;
1794 bool retransmitted = false;
1795 // Insert kMaxPacketsInJitterBuffer into frame.
1796 do {
1797 seq_num_++;
1798 packet_->isFirstPacket = false;
1799 packet_->markerBit = false;
1800 packet_->seqNum = seq_num_;
1801
1802 if (firstPacket) {
1803 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
1804 &retransmitted));
1805 firstPacket = false;
1806 } else {
1807 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(*packet_,
1808 &retransmitted));
1809 }
1810
1811 loop++;
1812 } while (loop < kMaxPacketsInSession);
1813
1814 // Max number of packets inserted.
1815 // Insert one more packet.
1816 seq_num_++;
1817 packet_->isFirstPacket = false;
1818 packet_->markerBit = true;
1819 packet_->seqNum = seq_num_;
1820
1821 // Insert the packet -> frame recycled.
1822 EXPECT_EQ(kSizeError, jitter_buffer_->InsertPacket(*packet_,
1823 &retransmitted));
1824 EXPECT_TRUE(NULL == DecodeCompleteFrame());
1825
1826 }
1827
1828 TEST_F(TestBasicJitterBuffer, ExceedNumOfFrameWithSeqNumWrap) {
1829 // TEST fill JB with more than max number of frame (50 delta frames +
1830 // 51 key frames) with wrap in seq_num_
1831 //
1832 // --------------------------------------------------------------
1833 // | 65485 | 65486 | 65487 | .... | 65535 | 0 | 1 | 2 | .....| 50 |
1834 // --------------------------------------------------------------
1835 // |<-----------delta frames------------->|<------key frames----->|
1836
1837 int loop = 0;
1838 seq_num_ = 65485;
1839 uint32_t first_key_frame_timestamp = 0;
1840 bool retransmitted = false;
1841 // Insert MAX_NUMBER_OF_FRAMES frames.
1842 do {
1843 timestamp_ += 33*90;
1844 seq_num_++;
1845 packet_->isFirstPacket = true;
1846 packet_->markerBit = true;
1847 packet_->seqNum = seq_num_;
1848 packet_->timestamp = timestamp_;
1849
1850 if (loop == 50) {
1851 first_key_frame_timestamp = packet_->timestamp;
1852 packet_->frameType = kVideoFrameKey;
1853 }
1854
1855 // Insert frame.
1856 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
1857 &retransmitted));
1858
1859 loop++;
1860 } while (loop < kMaxNumberOfFrames);
1861
1862 // Max number of frames inserted.
1863
1864 // Insert one more frame.
1865 timestamp_ += 33*90;
1866 seq_num_++;
1867 packet_->isFirstPacket = true;
1868 packet_->markerBit = true;
1869 packet_->seqNum = seq_num_;
1870 packet_->timestamp = timestamp_;
1871
1872 // Now, no free frame - frames will be recycled until first key frame.
1873 EXPECT_EQ(kFlushIndicator,
1874 jitter_buffer_->InsertPacket(*packet_, &retransmitted));
1875
1876 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
1877 EXPECT_EQ(first_key_frame_timestamp, frame_out->TimeStamp());
1878 CheckOutFrame(frame_out, size_, false);
1879 EXPECT_EQ(kVideoFrameKey, frame_out->FrameType());
1880 jitter_buffer_->ReleaseFrame(frame_out);
1881 }
1882
1883 TEST_F(TestBasicJitterBuffer, EmptyLastFrame) {
1884 jitter_buffer_->SetDecodeErrorMode(kWithErrors);
1885 seq_num_ = 3;
1886 // Insert one empty packet per frame, should never return the last timestamp
1887 // inserted. Only return empty frames in the presence of subsequent frames.
1888 int maxSize = 1000;
1889 bool retransmitted = false;
1890 for (int i = 0; i < maxSize + 10; i++) {
1891 timestamp_ += 33 * 90;
1892 seq_num_++;
1893 packet_->isFirstPacket = false;
1894 packet_->markerBit = false;
1895 packet_->seqNum = seq_num_;
1896 packet_->timestamp = timestamp_;
1897 packet_->frameType = kEmptyFrame;
1898
1899 EXPECT_EQ(kNoError, jitter_buffer_->InsertPacket(*packet_,
1900 &retransmitted));
1901 VCMEncodedFrame* testFrame = DecodeIncompleteFrame();
1902 // Timestamp should never be the last TS inserted.
1903 if (testFrame != NULL) {
1904 EXPECT_TRUE(testFrame->TimeStamp() < timestamp_);
1905 jitter_buffer_->ReleaseFrame(testFrame);
1906 }
1907 }
1908 }
1909
1910 TEST_F(TestBasicJitterBuffer, H264IncompleteNalu) {
1911 jitter_buffer_->SetNackMode(kNoNack, -1, -1);
1912 jitter_buffer_->SetDecodeErrorMode(kWithErrors);
1913 ++seq_num_;
1914 timestamp_ += 33 * 90;
1915 int insertedLength = 0;
1916 packet_->seqNum = seq_num_;
1917 packet_->timestamp = timestamp_;
1918 packet_->frameType = kVideoFrameKey;
1919 packet_->isFirstPacket = true;
1920 packet_->completeNALU = kNaluStart;
1921 packet_->markerBit = false;
1922 bool retransmitted = false;
1923
1924 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
1925 &retransmitted));
1926
1927 seq_num_ += 2; // Skip one packet.
1928 packet_->seqNum = seq_num_;
1929 packet_->frameType = kVideoFrameKey;
1930 packet_->isFirstPacket = false;
1931 packet_->completeNALU = kNaluIncomplete;
1932 packet_->markerBit = false;
1933
1934 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
1935 &retransmitted));
1936
1937 seq_num_++;
1938 packet_->seqNum = seq_num_;
1939 packet_->frameType = kVideoFrameKey;
1940 packet_->isFirstPacket = false;
1941 packet_->completeNALU = kNaluEnd;
1942 packet_->markerBit = false;
1943
1944 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
1945 &retransmitted));
1946
1947 seq_num_++;
1948 packet_->seqNum = seq_num_;
1949 packet_->completeNALU = kNaluComplete;
1950 packet_->markerBit = true; // Last packet.
1951 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
1952 &retransmitted));
1953 // The JB will only output (incomplete) frames if a packet belonging to a
1954 // subsequent frame was already inserted. Insert one packet of a subsequent
1955 // frame. place high timestamp so the JB would always have a next frame
1956 // (otherwise, for every inserted frame we need to take care of the next
1957 // frame as well).
1958 packet_->seqNum = 1;
1959 packet_->timestamp = timestamp_ + 33 * 90 * 10;
1960 packet_->frameType = kVideoFrameDelta;
1961 packet_->isFirstPacket = false;
1962 packet_->completeNALU = kNaluStart;
1963 packet_->markerBit = false;
1964
1965 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
1966 &retransmitted));
1967
1968 VCMEncodedFrame* frame_out = DecodeIncompleteFrame();
1969
1970 // We can decode everything from a NALU until a packet has been lost.
1971 // Thus we can decode the first packet of the first NALU and the second NALU
1972 // which consists of one packet.
1973 CheckOutFrame(frame_out, packet_->sizeBytes * 2, false);
1974 jitter_buffer_->ReleaseFrame(frame_out);
1975
1976 // Test reordered start frame + 1 lost.
1977 seq_num_ += 2; // Re-order 1 frame.
1978 timestamp_ += 33*90;
1979 insertedLength = 0;
1980
1981 packet_->seqNum = seq_num_;
1982 packet_->timestamp = timestamp_;
1983 packet_->frameType = kVideoFrameKey;
1984 packet_->isFirstPacket = false;
1985 packet_->completeNALU = kNaluEnd;
1986 packet_->markerBit = false;
1987 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
1988 &retransmitted));
1989 insertedLength += packet_->sizeBytes; // This packet should be decoded.
1990 seq_num_--;
1991 packet_->seqNum = seq_num_;
1992 packet_->timestamp = timestamp_;
1993 packet_->frameType = kVideoFrameKey;
1994 packet_->isFirstPacket = true;
1995 packet_->completeNALU = kNaluStart;
1996 packet_->markerBit = false;
1997
1998 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
1999 &retransmitted));
2000 insertedLength += packet_->sizeBytes; // This packet should be decoded.
2001
2002 seq_num_ += 3; // One packet drop.
2003 packet_->seqNum = seq_num_;
2004 packet_->timestamp = timestamp_;
2005 packet_->frameType = kVideoFrameKey;
2006 packet_->isFirstPacket = false;
2007 packet_->completeNALU = kNaluComplete;
2008 packet_->markerBit = false;
2009 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
2010 &retransmitted));
2011 insertedLength += packet_->sizeBytes; // This packet should be decoded.
2012 seq_num_++;
2013 packet_->seqNum = seq_num_;
2014 packet_->timestamp = timestamp_;
2015 packet_->frameType = kVideoFrameKey;
2016 packet_->isFirstPacket = false;
2017 packet_->completeNALU = kNaluStart;
2018 packet_->markerBit = false;
2019 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
2020 &retransmitted));
2021 // This packet should be decoded since it's the beginning of a NAL.
2022 insertedLength += packet_->sizeBytes;
2023
2024 seq_num_ += 2;
2025 packet_->seqNum = seq_num_;
2026 packet_->timestamp = timestamp_;
2027 packet_->frameType = kVideoFrameKey;
2028 packet_->isFirstPacket = false;
2029 packet_->completeNALU = kNaluEnd;
2030 packet_->markerBit = true;
2031 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
2032 &retransmitted));
2033 // This packet should not be decoded because it is an incomplete NAL if it
2034 // is the last.
2035 frame_out = DecodeIncompleteFrame();
2036 // Only last NALU is complete.
2037 CheckOutFrame(frame_out, insertedLength, false);
2038 jitter_buffer_->ReleaseFrame(frame_out);
2039
2040 // Test to insert empty packet.
2041 seq_num_++;
2042 timestamp_ += 33 * 90;
2043 VCMPacket emptypacket(data_, 0, seq_num_, timestamp_, true);
2044 emptypacket.seqNum = seq_num_;
2045 emptypacket.timestamp = timestamp_;
2046 emptypacket.frameType = kVideoFrameKey;
2047 emptypacket.isFirstPacket = true;
2048 emptypacket.completeNALU = kNaluComplete;
2049 emptypacket.markerBit = true;
2050 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(emptypacket,
2051 &retransmitted));
2052 // This packet should not be decoded because it is an incomplete NAL if it
2053 // is the last.
2054
2055 // Will be sent to the decoder, as a packet belonging to a subsequent frame
2056 // has arrived.
2057 frame_out = DecodeIncompleteFrame();
2058 EXPECT_TRUE(frame_out != NULL);
2059 jitter_buffer_->ReleaseFrame(frame_out);
2060
2061 // Test that a frame can include an empty packet.
2062 seq_num_++;
2063 timestamp_ += 33 * 90;
2064
2065 packet_->seqNum = seq_num_;
2066 packet_->timestamp = timestamp_;
2067 packet_->frameType = kVideoFrameKey;
2068 packet_->isFirstPacket = true;
2069 packet_->completeNALU = kNaluComplete;
2070 packet_->markerBit = false;
2071
2072 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
2073 &retransmitted));
2074
2075 seq_num_++;
2076 emptypacket.seqNum = seq_num_;
2077 emptypacket.timestamp = timestamp_;
2078 emptypacket.frameType = kVideoFrameKey;
2079 emptypacket.isFirstPacket = true;
2080 emptypacket.completeNALU = kNaluComplete;
2081 emptypacket.markerBit = true;
2082 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(emptypacket,
2083 &retransmitted));
2084
2085 frame_out = DecodeCompleteFrame();
2086 // Only last NALU is complete
2087 CheckOutFrame(frame_out, packet_->sizeBytes, false);
2088 jitter_buffer_->ReleaseFrame(frame_out);
2089 }
2090
2091 TEST_F(TestBasicJitterBuffer, NextFrameWhenIncomplete) {
2092 // Test that a we cannot get incomplete frames from the JB if we haven't
2093 // received the marker bit, unless we have received a packet from a later
2094 // timestamp.
2095 jitter_buffer_->SetDecodeErrorMode(kWithErrors);
2096 // Start with a complete key frame - insert and decode.
2097 packet_->frameType = kVideoFrameKey;
2098 packet_->isFirstPacket = true;
2099 packet_->markerBit = true;
2100 bool retransmitted = false;
2101
2102 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(*packet_,
2103 &retransmitted));
2104 VCMEncodedFrame* frame_out = DecodeCompleteFrame();
2105 EXPECT_TRUE(frame_out != NULL);
2106 jitter_buffer_->ReleaseFrame(frame_out);
2107
2108 packet_->seqNum += 2;
2109 packet_->timestamp += 33 * 90;
2110 packet_->frameType = kVideoFrameDelta;
2111 packet_->isFirstPacket = false;
2112 packet_->markerBit = false;
2113
2114
2115 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
2116 &retransmitted));
2117
2118 frame_out = DecodeIncompleteFrame();
2119 EXPECT_TRUE(frame_out == NULL);
2120
2121 packet_->seqNum += 2;
2122 packet_->timestamp += 33 * 90;
2123 packet_->isFirstPacket = true;
2124
2125 EXPECT_EQ(kDecodableSession, jitter_buffer_->InsertPacket(*packet_,
2126 &retransmitted));
2127
2128 frame_out = DecodeIncompleteFrame();
2129 CheckOutFrame(frame_out, packet_->sizeBytes, false);
2130 jitter_buffer_->ReleaseFrame(frame_out);
2131 }
2132
2133 TEST_F(TestRunningJitterBuffer, Full) {
2134 // Insert a key frame and decode it.
2135 EXPECT_GE(InsertFrame(kVideoFrameKey), kNoError);
2136 EXPECT_TRUE(DecodeCompleteFrame());
2137 DropFrame(1);
2138 // Fill the jitter buffer.
2139 EXPECT_GE(InsertFrames(kMaxNumberOfFrames, kVideoFrameDelta), kNoError);
2140 // Make sure we can't decode these frames.
2141 EXPECT_FALSE(DecodeCompleteFrame());
2142 // This frame will make the jitter buffer recycle frames until a key frame.
2143 // Since none is found it will have to wait until the next key frame before
2144 // decoding.
2145 EXPECT_EQ(kFlushIndicator, InsertFrame(kVideoFrameDelta));
2146 EXPECT_FALSE(DecodeCompleteFrame());
2147 }
2148
2149 TEST_F(TestRunningJitterBuffer, EmptyPackets) {
2150 // Make sure a frame can get complete even though empty packets are missing.
2151 stream_generator_->GenerateFrame(kVideoFrameKey, 3, 3,
2152 clock_->TimeInMilliseconds());
2153 bool request_key_frame = false;
2154 // Insert empty packet.
2155 EXPECT_EQ(kNoError, InsertPacketAndPop(4));
2156 EXPECT_FALSE(request_key_frame);
2157 // Insert 3 media packets.
2158 EXPECT_EQ(kIncomplete, InsertPacketAndPop(0));
2159 EXPECT_FALSE(request_key_frame);
2160 EXPECT_EQ(kIncomplete, InsertPacketAndPop(0));
2161 EXPECT_FALSE(request_key_frame);
2162 EXPECT_EQ(kCompleteSession, InsertPacketAndPop(0));
2163 EXPECT_FALSE(request_key_frame);
2164 // Insert empty packet.
2165 EXPECT_EQ(kCompleteSession, InsertPacketAndPop(0));
2166 EXPECT_FALSE(request_key_frame);
2167 }
2168
2169 TEST_F(TestRunningJitterBuffer, StatisticsTest) {
2170 FrameCounts frame_stats(jitter_buffer_->FrameStatistics());
2171 EXPECT_EQ(0, frame_stats.delta_frames);
2172 EXPECT_EQ(0, frame_stats.key_frames);
2173
2174 uint32_t framerate = 0;
2175 uint32_t bitrate = 0;
2176 jitter_buffer_->IncomingRateStatistics(&framerate, &bitrate);
2177 EXPECT_EQ(0u, framerate);
2178 EXPECT_EQ(0u, bitrate);
2179
2180 // Insert a couple of key and delta frames.
2181 InsertFrame(kVideoFrameKey);
2182 InsertFrame(kVideoFrameDelta);
2183 InsertFrame(kVideoFrameDelta);
2184 InsertFrame(kVideoFrameKey);
2185 InsertFrame(kVideoFrameDelta);
2186 // Decode some of them to make sure the statistics doesn't depend on frames
2187 // being decoded.
2188 EXPECT_TRUE(DecodeCompleteFrame());
2189 EXPECT_TRUE(DecodeCompleteFrame());
2190 frame_stats = jitter_buffer_->FrameStatistics();
2191 EXPECT_EQ(3, frame_stats.delta_frames);
2192 EXPECT_EQ(2, frame_stats.key_frames);
2193
2194 // Insert 20 more frames to get estimates of bitrate and framerate over
2195 // 1 second.
2196 for (int i = 0; i < 20; ++i) {
2197 InsertFrame(kVideoFrameDelta);
2198 }
2199 jitter_buffer_->IncomingRateStatistics(&framerate, &bitrate);
2200 // TODO(holmer): The current implementation returns the average of the last
2201 // two framerate calculations, which is why it takes two calls to reach the
2202 // actual framerate. This should be fixed.
2203 EXPECT_EQ(kDefaultFrameRate / 2u, framerate);
2204 EXPECT_EQ(kDefaultBitrateKbps, bitrate);
2205 // Insert 25 more frames to get estimates of bitrate and framerate over
2206 // 2 seconds.
2207 for (int i = 0; i < 25; ++i) {
2208 InsertFrame(kVideoFrameDelta);
2209 }
2210 jitter_buffer_->IncomingRateStatistics(&framerate, &bitrate);
2211 EXPECT_EQ(kDefaultFrameRate, framerate);
2212 EXPECT_EQ(kDefaultBitrateKbps, bitrate);
2213 }
2214
2215 TEST_F(TestRunningJitterBuffer, SkipToKeyFrame) {
2216 // Insert delta frames.
2217 EXPECT_GE(InsertFrames(5, kVideoFrameDelta), kNoError);
2218 // Can't decode without a key frame.
2219 EXPECT_FALSE(DecodeCompleteFrame());
2220 InsertFrame(kVideoFrameKey);
2221 // Skip to the next key frame.
2222 EXPECT_TRUE(DecodeCompleteFrame());
2223 }
2224
2225 TEST_F(TestRunningJitterBuffer, DontSkipToKeyFrameIfDecodable) {
2226 InsertFrame(kVideoFrameKey);
2227 EXPECT_TRUE(DecodeCompleteFrame());
2228 const int kNumDeltaFrames = 5;
2229 EXPECT_GE(InsertFrames(kNumDeltaFrames, kVideoFrameDelta), kNoError);
2230 InsertFrame(kVideoFrameKey);
2231 for (int i = 0; i < kNumDeltaFrames + 1; ++i) {
2232 EXPECT_TRUE(DecodeCompleteFrame());
2233 }
2234 }
2235
2236 TEST_F(TestRunningJitterBuffer, KeyDeltaKeyDelta) {
2237 InsertFrame(kVideoFrameKey);
2238 EXPECT_TRUE(DecodeCompleteFrame());
2239 const int kNumDeltaFrames = 5;
2240 EXPECT_GE(InsertFrames(kNumDeltaFrames, kVideoFrameDelta), kNoError);
2241 InsertFrame(kVideoFrameKey);
2242 EXPECT_GE(InsertFrames(kNumDeltaFrames, kVideoFrameDelta), kNoError);
2243 InsertFrame(kVideoFrameKey);
2244 for (int i = 0; i < 2 * (kNumDeltaFrames + 1); ++i) {
2245 EXPECT_TRUE(DecodeCompleteFrame());
2246 }
2247 }
2248
2249 TEST_F(TestRunningJitterBuffer, TwoPacketsNonContinuous) {
2250 InsertFrame(kVideoFrameKey);
2251 EXPECT_TRUE(DecodeCompleteFrame());
2252 stream_generator_->GenerateFrame(kVideoFrameDelta, 1, 0,
2253 clock_->TimeInMilliseconds());
2254 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs);
2255 stream_generator_->GenerateFrame(kVideoFrameDelta, 2, 0,
2256 clock_->TimeInMilliseconds());
2257 EXPECT_EQ(kIncomplete, InsertPacketAndPop(1));
2258 EXPECT_EQ(kCompleteSession, InsertPacketAndPop(1));
2259 EXPECT_FALSE(DecodeCompleteFrame());
2260 EXPECT_EQ(kCompleteSession, InsertPacketAndPop(0));
2261 EXPECT_TRUE(DecodeCompleteFrame());
2262 EXPECT_TRUE(DecodeCompleteFrame());
2263 }
2264
2265 TEST_F(TestJitterBufferNack, EmptyPackets) {
2266 // Make sure empty packets doesn't clog the jitter buffer.
2267 jitter_buffer_->SetNackMode(kNack, media_optimization::kLowRttNackMs, -1);
2268 EXPECT_GE(InsertFrames(kMaxNumberOfFrames, kEmptyFrame), kNoError);
2269 InsertFrame(kVideoFrameKey);
2270 EXPECT_TRUE(DecodeCompleteFrame());
2271 }
2272
2273 TEST_F(TestJitterBufferNack, NackTooOldPackets) {
2274 // Insert a key frame and decode it.
2275 EXPECT_GE(InsertFrame(kVideoFrameKey), kNoError);
2276 EXPECT_TRUE(DecodeCompleteFrame());
2277
2278 // Drop one frame and insert |kNackHistoryLength| to trigger NACKing a too
2279 // old packet.
2280 DropFrame(1);
2281 // Insert a frame which should trigger a recycle until the next key frame.
2282 EXPECT_EQ(kFlushIndicator, InsertFrames(oldest_packet_to_nack_ + 1,
2283 kVideoFrameDelta));
2284 EXPECT_FALSE(DecodeCompleteFrame());
2285
2286 bool request_key_frame = false;
2287 std::vector<uint16_t> nack_list =
2288 jitter_buffer_->GetNackList(&request_key_frame);
2289 // No key frame will be requested since the jitter buffer is empty.
2290 EXPECT_FALSE(request_key_frame);
2291 EXPECT_EQ(0u, nack_list.size());
2292
2293 EXPECT_GE(InsertFrame(kVideoFrameDelta), kNoError);
2294 // Waiting for a key frame.
2295 EXPECT_FALSE(DecodeCompleteFrame());
2296 EXPECT_FALSE(DecodeIncompleteFrame());
2297
2298 // The next complete continuous frame isn't a key frame, but we're waiting
2299 // for one.
2300 EXPECT_FALSE(DecodeCompleteFrame());
2301 EXPECT_GE(InsertFrame(kVideoFrameKey), kNoError);
2302 // Skipping ahead to the key frame.
2303 EXPECT_TRUE(DecodeCompleteFrame());
2304 }
2305
2306 TEST_F(TestJitterBufferNack, NackLargeJitterBuffer) {
2307 // Insert a key frame and decode it.
2308 EXPECT_GE(InsertFrame(kVideoFrameKey), kNoError);
2309 EXPECT_TRUE(DecodeCompleteFrame());
2310
2311 // Insert a frame which should trigger a recycle until the next key frame.
2312 EXPECT_GE(InsertFrames(oldest_packet_to_nack_, kVideoFrameDelta), kNoError);
2313
2314 bool request_key_frame = false;
2315 std::vector<uint16_t> nack_list =
2316 jitter_buffer_->GetNackList(&request_key_frame);
2317 // Verify that the jitter buffer does not request a key frame.
2318 EXPECT_FALSE(request_key_frame);
2319 // Verify that no packets are NACKed.
2320 EXPECT_EQ(0u, nack_list.size());
2321 // Verify that we can decode the next frame.
2322 EXPECT_TRUE(DecodeCompleteFrame());
2323 }
2324
2325 TEST_F(TestJitterBufferNack, NackListFull) {
2326 // Insert a key frame and decode it.
2327 EXPECT_GE(InsertFrame(kVideoFrameKey), kNoError);
2328 EXPECT_TRUE(DecodeCompleteFrame());
2329
2330 // Generate and drop |kNackHistoryLength| packets to fill the NACK list.
2331 DropFrame(max_nack_list_size_ + 1);
2332 // Insert a frame which should trigger a recycle until the next key frame.
2333 EXPECT_EQ(kFlushIndicator, InsertFrame(kVideoFrameDelta));
2334 EXPECT_FALSE(DecodeCompleteFrame());
2335
2336 bool request_key_frame = false;
2337 jitter_buffer_->GetNackList(&request_key_frame);
2338 // The jitter buffer is empty, so we won't request key frames until we get a
2339 // packet.
2340 EXPECT_FALSE(request_key_frame);
2341
2342 EXPECT_GE(InsertFrame(kVideoFrameDelta), kNoError);
2343 // Now we have a packet in the jitter buffer, a key frame will be requested
2344 // since it's not a key frame.
2345 jitter_buffer_->GetNackList(&request_key_frame);
2346 // The jitter buffer is empty, so we won't request key frames until we get a
2347 // packet.
2348 EXPECT_TRUE(request_key_frame);
2349 // The next complete continuous frame isn't a key frame, but we're waiting
2350 // for one.
2351 EXPECT_FALSE(DecodeCompleteFrame());
2352 EXPECT_FALSE(DecodeIncompleteFrame());
2353 EXPECT_GE(InsertFrame(kVideoFrameKey), kNoError);
2354 // Skipping ahead to the key frame.
2355 EXPECT_TRUE(DecodeCompleteFrame());
2356 }
2357
2358 TEST_F(TestJitterBufferNack, NoNackListReturnedBeforeFirstDecode) {
2359 DropFrame(10);
2360 // Insert a frame and try to generate a NACK list. Shouldn't get one.
2361 EXPECT_GE(InsertFrame(kVideoFrameDelta), kNoError);
2362 bool request_key_frame = false;
2363 std::vector<uint16_t> nack_list =
2364 jitter_buffer_->GetNackList(&request_key_frame);
2365 // No list generated, and a key frame request is signaled.
2366 EXPECT_EQ(0u, nack_list.size());
2367 EXPECT_TRUE(request_key_frame);
2368 }
2369
2370 TEST_F(TestJitterBufferNack, NackListBuiltBeforeFirstDecode) {
2371 stream_generator_->Init(0, clock_->TimeInMilliseconds());
2372 InsertFrame(kVideoFrameKey);
2373 stream_generator_->GenerateFrame(kVideoFrameDelta, 2, 0,
2374 clock_->TimeInMilliseconds());
2375 stream_generator_->NextPacket(NULL); // Drop packet.
2376 EXPECT_EQ(kIncomplete, InsertPacketAndPop(0));
2377 EXPECT_TRUE(DecodeCompleteFrame());
2378 bool extended = false;
2379 std::vector<uint16_t> nack_list = jitter_buffer_->GetNackList(&extended);
2380 EXPECT_EQ(1u, nack_list.size());
2381 }
2382
2383 TEST_F(TestJitterBufferNack, VerifyRetransmittedFlag) {
2384 stream_generator_->Init(0, clock_->TimeInMilliseconds());
2385 stream_generator_->GenerateFrame(kVideoFrameKey, 3, 0,
2386 clock_->TimeInMilliseconds());
2387 VCMPacket packet;
2388 stream_generator_->PopPacket(&packet, 0);
2389 bool retransmitted = false;
2390 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(packet, &retransmitted));
2391 EXPECT_FALSE(retransmitted);
2392 // Drop second packet.
2393 stream_generator_->PopPacket(&packet, 1);
2394 EXPECT_EQ(kIncomplete, jitter_buffer_->InsertPacket(packet, &retransmitted));
2395 EXPECT_FALSE(retransmitted);
2396 EXPECT_FALSE(DecodeCompleteFrame());
2397 bool extended = false;
2398 std::vector<uint16_t> nack_list = jitter_buffer_->GetNackList(&extended);
2399 EXPECT_EQ(1u, nack_list.size());
2400 stream_generator_->PopPacket(&packet, 0);
2401 EXPECT_EQ(packet.seqNum, nack_list[0]);
2402 EXPECT_EQ(kCompleteSession, jitter_buffer_->InsertPacket(packet,
2403 &retransmitted));
2404 EXPECT_TRUE(retransmitted);
2405 EXPECT_TRUE(DecodeCompleteFrame());
2406 }
2407
2408 TEST_F(TestJitterBufferNack, UseNackToRecoverFirstKeyFrame) {
2409 stream_generator_->Init(0, clock_->TimeInMilliseconds());
2410 stream_generator_->GenerateFrame(kVideoFrameKey, 3, 0,
2411 clock_->TimeInMilliseconds());
2412 EXPECT_EQ(kIncomplete, InsertPacketAndPop(0));
2413 // Drop second packet.
2414 EXPECT_EQ(kIncomplete, InsertPacketAndPop(1));
2415 EXPECT_FALSE(DecodeCompleteFrame());
2416 bool extended = false;
2417 std::vector<uint16_t> nack_list = jitter_buffer_->GetNackList(&extended);
2418 EXPECT_EQ(1u, nack_list.size());
2419 VCMPacket packet;
2420 stream_generator_->GetPacket(&packet, 0);
2421 EXPECT_EQ(packet.seqNum, nack_list[0]);
2422 }
2423
2424 TEST_F(TestJitterBufferNack, UseNackToRecoverFirstKeyFrameSecondInQueue) {
2425 VCMPacket packet;
2426 stream_generator_->Init(0, clock_->TimeInMilliseconds());
2427 // First frame is delta.
2428 stream_generator_->GenerateFrame(kVideoFrameDelta, 3, 0,
2429 clock_->TimeInMilliseconds());
2430 EXPECT_EQ(kIncomplete, InsertPacketAndPop(0));
2431 // Drop second packet in frame.
2432 ASSERT_TRUE(stream_generator_->PopPacket(&packet, 0));
2433 EXPECT_EQ(kIncomplete, InsertPacketAndPop(0));
2434 // Second frame is key.
2435 stream_generator_->GenerateFrame(kVideoFrameKey, 3, 0,
2436 clock_->TimeInMilliseconds() + 10);
2437 EXPECT_EQ(kIncomplete, InsertPacketAndPop(0));
2438 // Drop second packet in frame.
2439 EXPECT_EQ(kIncomplete, InsertPacketAndPop(1));
2440 EXPECT_FALSE(DecodeCompleteFrame());
2441 bool extended = false;
2442 std::vector<uint16_t> nack_list = jitter_buffer_->GetNackList(&extended);
2443 EXPECT_EQ(1u, nack_list.size());
2444 stream_generator_->GetPacket(&packet, 0);
2445 EXPECT_EQ(packet.seqNum, nack_list[0]);
2446 }
2447
2448 TEST_F(TestJitterBufferNack, NormalOperation) {
2449 EXPECT_EQ(kNack, jitter_buffer_->nack_mode());
2450 jitter_buffer_->SetDecodeErrorMode(kWithErrors);
2451
2452 EXPECT_GE(InsertFrame(kVideoFrameKey), kNoError);
2453 EXPECT_TRUE(DecodeIncompleteFrame());
2454
2455 // ----------------------------------------------------------------
2456 // | 1 | 2 | .. | 8 | 9 | x | 11 | 12 | .. | 19 | x | 21 | .. | 100 |
2457 // ----------------------------------------------------------------
2458 stream_generator_->GenerateFrame(kVideoFrameKey, 100, 0,
2459 clock_->TimeInMilliseconds());
2460 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs);
2461 EXPECT_EQ(kDecodableSession, InsertPacketAndPop(0));
2462 // Verify that the frame is incomplete.
2463 EXPECT_FALSE(DecodeCompleteFrame());
2464 while (stream_generator_->PacketsRemaining() > 1) {
2465 if (stream_generator_->NextSequenceNumber() % 10 != 0) {
2466 EXPECT_EQ(kDecodableSession, InsertPacketAndPop(0));
2467 } else {
2468 stream_generator_->NextPacket(NULL); // Drop packet
2469 }
2470 }
2471 EXPECT_EQ(kDecodableSession, InsertPacketAndPop(0));
2472 EXPECT_EQ(0, stream_generator_->PacketsRemaining());
2473 EXPECT_FALSE(DecodeCompleteFrame());
2474 EXPECT_FALSE(DecodeIncompleteFrame());
2475 bool request_key_frame = false;
2476 std::vector<uint16_t> nack_list =
2477 jitter_buffer_->GetNackList(&request_key_frame);
2478 // Verify the NACK list.
2479 const size_t kExpectedNackSize = 9;
2480 ASSERT_EQ(kExpectedNackSize, nack_list.size());
2481 for (size_t i = 0; i < nack_list.size(); ++i)
2482 EXPECT_EQ((1 + i) * 10, nack_list[i]);
2483 }
2484
2485 TEST_F(TestJitterBufferNack, NormalOperationWrap) {
2486 bool request_key_frame = false;
2487 // ------- ------------------------------------------------------------
2488 // | 65532 | | 65533 | 65534 | 65535 | x | 1 | .. | 9 | x | 11 |.....| 96 |
2489 // ------- ------------------------------------------------------------
2490 stream_generator_->Init(65532, clock_->TimeInMilliseconds());
2491 InsertFrame(kVideoFrameKey);
2492 EXPECT_FALSE(request_key_frame);
2493 EXPECT_TRUE(DecodeCompleteFrame());
2494 stream_generator_->GenerateFrame(kVideoFrameDelta, 100, 0,
2495 clock_->TimeInMilliseconds());
2496 EXPECT_EQ(kIncomplete, InsertPacketAndPop(0));
2497 while (stream_generator_->PacketsRemaining() > 1) {
2498 if (stream_generator_->NextSequenceNumber() % 10 != 0) {
2499 EXPECT_EQ(kIncomplete, InsertPacketAndPop(0));
2500 EXPECT_FALSE(request_key_frame);
2501 } else {
2502 stream_generator_->NextPacket(NULL); // Drop packet
2503 }
2504 }
2505 EXPECT_EQ(kIncomplete, InsertPacketAndPop(0));
2506 EXPECT_FALSE(request_key_frame);
2507 EXPECT_EQ(0, stream_generator_->PacketsRemaining());
2508 EXPECT_FALSE(DecodeCompleteFrame());
2509 EXPECT_FALSE(DecodeCompleteFrame());
2510 bool extended = false;
2511 std::vector<uint16_t> nack_list = jitter_buffer_->GetNackList(&extended);
2512 // Verify the NACK list.
2513 const size_t kExpectedNackSize = 10;
2514 ASSERT_EQ(kExpectedNackSize, nack_list.size());
2515 for (size_t i = 0; i < nack_list.size(); ++i)
2516 EXPECT_EQ(i * 10, nack_list[i]);
2517 }
2518
2519 TEST_F(TestJitterBufferNack, NormalOperationWrap2) {
2520 bool request_key_frame = false;
2521 // -----------------------------------
2522 // | 65532 | 65533 | 65534 | x | 0 | 1 |
2523 // -----------------------------------
2524 stream_generator_->Init(65532, clock_->TimeInMilliseconds());
2525 InsertFrame(kVideoFrameKey);
2526 EXPECT_FALSE(request_key_frame);
2527 EXPECT_TRUE(DecodeCompleteFrame());
2528 stream_generator_->GenerateFrame(kVideoFrameDelta, 1, 0,
2529 clock_->TimeInMilliseconds());
2530 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs);
2531 for (int i = 0; i < 5; ++i) {
2532 if (stream_generator_->NextSequenceNumber() != 65535) {
2533 EXPECT_EQ(kCompleteSession, InsertPacketAndPop(0));
2534 EXPECT_FALSE(request_key_frame);
2535 } else {
2536 stream_generator_->NextPacket(NULL); // Drop packet
2537 }
2538 stream_generator_->GenerateFrame(kVideoFrameDelta, 1, 0,
2539 clock_->TimeInMilliseconds());
2540 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs);
2541 }
2542 EXPECT_EQ(kCompleteSession, InsertPacketAndPop(0));
2543 EXPECT_FALSE(request_key_frame);
2544 bool extended = false;
2545 std::vector<uint16_t> nack_list = jitter_buffer_->GetNackList(&extended);
2546 // Verify the NACK list.
2547 ASSERT_EQ(1u, nack_list.size());
2548 EXPECT_EQ(65535, nack_list[0]);
2549 }
2550
2551 TEST_F(TestJitterBufferNack, ResetByFutureKeyFrameDoesntError) {
2552 stream_generator_->Init(0, clock_->TimeInMilliseconds());
2553 InsertFrame(kVideoFrameKey);
2554 EXPECT_TRUE(DecodeCompleteFrame());
2555 bool extended = false;
2556 std::vector<uint16_t> nack_list = jitter_buffer_->GetNackList(&extended);
2557 EXPECT_EQ(0u, nack_list.size());
2558
2559 // Far-into-the-future video frame, could be caused by resetting the encoder
2560 // or otherwise restarting. This should not fail when error when the packet is
2561 // a keyframe, even if all of the nack list needs to be flushed.
2562 stream_generator_->Init(10000, clock_->TimeInMilliseconds());
2563 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs);
2564 InsertFrame(kVideoFrameKey);
2565 EXPECT_TRUE(DecodeCompleteFrame());
2566 nack_list = jitter_buffer_->GetNackList(&extended);
2567 EXPECT_EQ(0u, nack_list.size());
2568
2569 // Stream should be decodable from this point.
2570 clock_->AdvanceTimeMilliseconds(kDefaultFramePeriodMs);
2571 InsertFrame(kVideoFrameDelta);
2572 EXPECT_TRUE(DecodeCompleteFrame());
2573 nack_list = jitter_buffer_->GetNackList(&extended);
2574 EXPECT_EQ(0u, nack_list.size());
2575 }
2576
2577 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698