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

Side by Side Diff: webrtc/modules/video_coding/main/source/session_info_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) 2012 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 "testing/gtest/include/gtest/gtest.h"
14 #include "webrtc/modules/include/module_common_types.h"
15 #include "webrtc/modules/video_coding/main/source/packet.h"
16 #include "webrtc/modules/video_coding/main/source/session_info.h"
17
18 namespace webrtc {
19
20 class TestSessionInfo : public ::testing::Test {
21 protected:
22 virtual void SetUp() {
23 memset(packet_buffer_, 0, sizeof(packet_buffer_));
24 memset(frame_buffer_, 0, sizeof(frame_buffer_));
25 session_.Reset();
26 packet_.Reset();
27 packet_.frameType = kVideoFrameDelta;
28 packet_.sizeBytes = packet_buffer_size();
29 packet_.dataPtr = packet_buffer_;
30 packet_.seqNum = 0;
31 packet_.timestamp = 0;
32 frame_data.rtt_ms = 0;
33 frame_data.rolling_average_packets_per_frame = -1;
34 }
35
36 void FillPacket(uint8_t start_value) {
37 for (size_t i = 0; i < packet_buffer_size(); ++i)
38 packet_buffer_[i] = start_value + i;
39 }
40
41 void VerifyPacket(uint8_t* start_ptr, uint8_t start_value) {
42 for (size_t j = 0; j < packet_buffer_size(); ++j) {
43 ASSERT_EQ(start_value + j, start_ptr[j]);
44 }
45 }
46
47 size_t packet_buffer_size() const {
48 return sizeof(packet_buffer_) / sizeof(packet_buffer_[0]);
49 }
50 size_t frame_buffer_size() const {
51 return sizeof(frame_buffer_) / sizeof(frame_buffer_[0]);
52 }
53
54 enum { kPacketBufferSize = 10 };
55
56 uint8_t packet_buffer_[kPacketBufferSize];
57 uint8_t frame_buffer_[10 * kPacketBufferSize];
58
59 VCMSessionInfo session_;
60 VCMPacket packet_;
61 FrameData frame_data;
62 };
63
64 class TestVP8Partitions : public TestSessionInfo {
65 protected:
66 enum { kMaxVP8Partitions = 9 };
67
68 virtual void SetUp() {
69 TestSessionInfo::SetUp();
70 vp8_header_ = &packet_header_.type.Video.codecHeader.VP8;
71 packet_header_.frameType = kVideoFrameDelta;
72 packet_header_.type.Video.codec = kRtpVideoVp8;
73 vp8_header_->InitRTPVideoHeaderVP8();
74 fragmentation_.VerifyAndAllocateFragmentationHeader(kMaxVP8Partitions);
75 }
76
77 bool VerifyPartition(int partition_id,
78 int packets_expected,
79 int start_value) {
80 EXPECT_EQ(packets_expected * packet_buffer_size(),
81 fragmentation_.fragmentationLength[partition_id]);
82 for (int i = 0; i < packets_expected; ++i) {
83 size_t packet_index = fragmentation_.fragmentationOffset[partition_id] +
84 i * packet_buffer_size();
85 if (packet_index + packet_buffer_size() > frame_buffer_size())
86 return false;
87 VerifyPacket(frame_buffer_ + packet_index, start_value + i);
88 }
89 return true;
90 }
91
92 WebRtcRTPHeader packet_header_;
93 RTPVideoHeaderVP8* vp8_header_;
94 RTPFragmentationHeader fragmentation_;
95 };
96
97 class TestNalUnits : public TestSessionInfo {
98 protected:
99 virtual void SetUp() {
100 TestSessionInfo::SetUp();
101 packet_.codec = kVideoCodecVP8;
102 }
103
104 bool VerifyNalu(int offset, int packets_expected, int start_value) {
105 EXPECT_GE(session_.SessionLength(),
106 packets_expected * packet_buffer_size());
107 for (int i = 0; i < packets_expected; ++i) {
108 int packet_index = (offset + i) * packet_buffer_size();
109 VerifyPacket(frame_buffer_ + packet_index, start_value + i);
110 }
111 return true;
112 }
113 };
114
115 class TestNackList : public TestSessionInfo {
116 protected:
117 static const size_t kMaxSeqNumListLength = 30;
118
119 virtual void SetUp() {
120 TestSessionInfo::SetUp();
121 seq_num_list_length_ = 0;
122 memset(seq_num_list_, 0, sizeof(seq_num_list_));
123 }
124
125 void BuildSeqNumList(uint16_t low,
126 uint16_t high) {
127 size_t i = 0;
128 while (low != high + 1) {
129 EXPECT_LT(i, kMaxSeqNumListLength);
130 if (i >= kMaxSeqNumListLength) {
131 seq_num_list_length_ = kMaxSeqNumListLength;
132 return;
133 }
134 seq_num_list_[i] = low;
135 low++;
136 i++;
137 }
138 seq_num_list_length_ = i;
139 }
140
141 void VerifyAll(int value) {
142 for (int i = 0; i < seq_num_list_length_; ++i)
143 EXPECT_EQ(seq_num_list_[i], value);
144 }
145
146 int seq_num_list_[kMaxSeqNumListLength];
147 int seq_num_list_length_;
148 };
149
150 TEST_F(TestSessionInfo, TestSimpleAPIs) {
151 packet_.isFirstPacket = true;
152 packet_.seqNum = 0xFFFE;
153 packet_.sizeBytes = packet_buffer_size();
154 packet_.frameType = kVideoFrameKey;
155 FillPacket(0);
156 EXPECT_EQ(packet_buffer_size(),
157 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
158 kNoErrors, frame_data)));
159 EXPECT_FALSE(session_.HaveLastPacket());
160 EXPECT_EQ(kVideoFrameKey, session_.FrameType());
161
162 packet_.isFirstPacket = false;
163 packet_.markerBit = true;
164 packet_.seqNum += 1;
165 EXPECT_EQ(packet_buffer_size(),
166 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
167 kNoErrors, frame_data)));
168 EXPECT_TRUE(session_.HaveLastPacket());
169 EXPECT_EQ(packet_.seqNum, session_.HighSequenceNumber());
170 EXPECT_EQ(0xFFFE, session_.LowSequenceNumber());
171
172 // Insert empty packet which will be the new high sequence number.
173 // To make things more difficult we will make sure to have a wrap here.
174 packet_.isFirstPacket = false;
175 packet_.markerBit = true;
176 packet_.seqNum = 2;
177 packet_.sizeBytes = 0;
178 packet_.frameType = kEmptyFrame;
179 EXPECT_EQ(0,
180 session_.InsertPacket(packet_,
181 frame_buffer_,
182 kNoErrors,
183 frame_data));
184 EXPECT_EQ(packet_.seqNum, session_.HighSequenceNumber());
185 }
186
187 TEST_F(TestSessionInfo, NormalOperation) {
188 packet_.seqNum = 0xFFFF;
189 packet_.isFirstPacket = true;
190 packet_.markerBit = false;
191 FillPacket(0);
192 EXPECT_EQ(packet_buffer_size(),
193 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
194 kNoErrors, frame_data)));
195
196 packet_.isFirstPacket = false;
197 for (int i = 1; i < 9; ++i) {
198 packet_.seqNum += 1;
199 FillPacket(i);
200 ASSERT_EQ(packet_buffer_size(),
201 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
202 kNoErrors,
203 frame_data)));
204 }
205
206 packet_.seqNum += 1;
207 packet_.markerBit = true;
208 FillPacket(9);
209 EXPECT_EQ(packet_buffer_size(),
210 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
211 kNoErrors, frame_data)));
212
213 EXPECT_EQ(10 * packet_buffer_size(), session_.SessionLength());
214 for (int i = 0; i < 10; ++i) {
215 SCOPED_TRACE("Calling VerifyPacket");
216 VerifyPacket(frame_buffer_ + i * packet_buffer_size(), i);
217 }
218 }
219
220 TEST_F(TestSessionInfo, ErrorsEqualDecodableState) {
221 packet_.seqNum = 0xFFFF;
222 packet_.isFirstPacket = false;
223 packet_.markerBit = false;
224 FillPacket(3);
225 EXPECT_EQ(packet_buffer_size(),
226 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
227 kWithErrors,
228 frame_data)));
229 EXPECT_TRUE(session_.decodable());
230 }
231
232 TEST_F(TestSessionInfo, SelectiveDecodableState) {
233 packet_.seqNum = 0xFFFF;
234 packet_.isFirstPacket = false;
235 packet_.markerBit = false;
236 FillPacket(1);
237 frame_data.rolling_average_packets_per_frame = 11;
238 frame_data.rtt_ms = 150;
239 EXPECT_EQ(packet_buffer_size(),
240 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
241 kSelectiveErrors,
242 frame_data)));
243 EXPECT_FALSE(session_.decodable());
244
245 packet_.seqNum -= 1;
246 FillPacket(0);
247 packet_.isFirstPacket = true;
248 EXPECT_EQ(packet_buffer_size(),
249 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
250 kSelectiveErrors,
251 frame_data)));
252 EXPECT_TRUE(session_.decodable());
253
254 packet_.isFirstPacket = false;
255 packet_.seqNum += 1;
256 for (int i = 2; i < 8; ++i) {
257 packet_.seqNum += 1;
258 FillPacket(i);
259 EXPECT_EQ(packet_buffer_size(),
260 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
261 kSelectiveErrors,
262 frame_data)));
263 EXPECT_TRUE(session_.decodable());
264 }
265
266 packet_.seqNum += 1;
267 FillPacket(8);
268 EXPECT_EQ(packet_buffer_size(),
269 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
270 kSelectiveErrors,
271 frame_data)));
272 EXPECT_TRUE(session_.decodable());
273 }
274
275 TEST_F(TestSessionInfo, OutOfBoundsPackets1PacketFrame) {
276 packet_.seqNum = 0x0001;
277 packet_.isFirstPacket = true;
278 packet_.markerBit = true;
279 FillPacket(1);
280 EXPECT_EQ(packet_buffer_size(),
281 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
282 kNoErrors, frame_data)));
283
284 packet_.seqNum = 0x0004;
285 packet_.isFirstPacket = true;
286 packet_.markerBit = true;
287 FillPacket(1);
288 EXPECT_EQ(-3, session_.InsertPacket(packet_,
289 frame_buffer_,
290 kNoErrors,
291 frame_data));
292 packet_.seqNum = 0x0000;
293 packet_.isFirstPacket = false;
294 packet_.markerBit = false;
295 FillPacket(1);
296 EXPECT_EQ(-3, session_.InsertPacket(packet_,
297 frame_buffer_,
298 kNoErrors,
299 frame_data));
300 }
301
302 TEST_F(TestSessionInfo, SetMarkerBitOnce) {
303 packet_.seqNum = 0x0005;
304 packet_.isFirstPacket = false;
305 packet_.markerBit = true;
306 FillPacket(1);
307 EXPECT_EQ(packet_buffer_size(),
308 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
309 kNoErrors, frame_data)));
310 ++packet_.seqNum;
311 packet_.isFirstPacket = true;
312 packet_.markerBit = true;
313 FillPacket(1);
314 EXPECT_EQ(-3, session_.InsertPacket(packet_,
315 frame_buffer_,
316 kNoErrors,
317 frame_data));
318 }
319
320 TEST_F(TestSessionInfo, OutOfBoundsPacketsBase) {
321 // Allow packets in the range 5-6.
322 packet_.seqNum = 0x0005;
323 packet_.isFirstPacket = true;
324 packet_.markerBit = false;
325 FillPacket(1);
326 EXPECT_EQ(packet_buffer_size(),
327 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
328 kNoErrors, frame_data)));
329 // Insert an older packet with a first packet set.
330 packet_.seqNum = 0x0004;
331 packet_.isFirstPacket = true;
332 packet_.markerBit = true;
333 FillPacket(1);
334 EXPECT_EQ(-3, session_.InsertPacket(packet_,
335 frame_buffer_,
336 kNoErrors,
337 frame_data));
338 packet_.seqNum = 0x0006;
339 packet_.isFirstPacket = true;
340 packet_.markerBit = true;
341 FillPacket(1);
342 EXPECT_EQ(packet_buffer_size(),
343 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
344 kNoErrors, frame_data)));
345 packet_.seqNum = 0x0008;
346 packet_.isFirstPacket = false;
347 packet_.markerBit = true;
348 FillPacket(1);
349 EXPECT_EQ(-3, session_.InsertPacket(packet_,
350 frame_buffer_,
351 kNoErrors,
352 frame_data));
353 }
354
355 TEST_F(TestSessionInfo, OutOfBoundsPacketsWrap) {
356 packet_.seqNum = 0xFFFE;
357 packet_.isFirstPacket = true;
358 packet_.markerBit = false;
359 FillPacket(1);
360 EXPECT_EQ(packet_buffer_size(),
361 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
362 kNoErrors, frame_data)));
363
364 packet_.seqNum = 0x0004;
365 packet_.isFirstPacket = false;
366 packet_.markerBit = true;
367 FillPacket(1);
368 EXPECT_EQ(packet_buffer_size(),
369 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
370 kNoErrors, frame_data)));
371 packet_.seqNum = 0x0002;
372 packet_.isFirstPacket = false;
373 packet_.markerBit = false;
374 FillPacket(1);
375 ASSERT_EQ(packet_buffer_size(),
376 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
377 kNoErrors, frame_data)));
378 packet_.seqNum = 0xFFF0;
379 packet_.isFirstPacket = false;
380 packet_.markerBit = false;
381 FillPacket(1);
382 EXPECT_EQ(-3,
383 session_.InsertPacket(packet_,
384 frame_buffer_,
385 kNoErrors,
386 frame_data));
387 packet_.seqNum = 0x0006;
388 packet_.isFirstPacket = false;
389 packet_.markerBit = false;
390 FillPacket(1);
391 EXPECT_EQ(-3,
392 session_.InsertPacket(packet_,
393 frame_buffer_,
394 kNoErrors,
395 frame_data));
396 }
397
398 TEST_F(TestSessionInfo, OutOfBoundsOutOfOrder) {
399 // Insert out of bound regular packets, and then the first and last packet.
400 // Verify that correct bounds are maintained.
401 packet_.seqNum = 0x0003;
402 packet_.isFirstPacket = false;
403 packet_.markerBit = false;
404 FillPacket(1);
405 EXPECT_EQ(packet_buffer_size(),
406 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
407 kNoErrors, frame_data)));
408 // Insert an older packet with a first packet set.
409 packet_.seqNum = 0x0005;
410 packet_.isFirstPacket = true;
411 packet_.markerBit = false;
412 FillPacket(1);
413 EXPECT_EQ(packet_buffer_size(),
414 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
415 kNoErrors, frame_data)));
416 packet_.seqNum = 0x0004;
417 packet_.isFirstPacket = false;
418 packet_.markerBit = false;
419 FillPacket(1);
420 EXPECT_EQ(-3, session_.InsertPacket(packet_,
421 frame_buffer_,
422 kNoErrors,
423 frame_data));
424 packet_.seqNum = 0x0010;
425 packet_.isFirstPacket = false;
426 packet_.markerBit = false;
427 FillPacket(1);
428 EXPECT_EQ(packet_buffer_size(),
429 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
430 kNoErrors, frame_data)));
431 packet_.seqNum = 0x0008;
432 packet_.isFirstPacket = false;
433 packet_.markerBit = true;
434 FillPacket(1);
435 EXPECT_EQ(packet_buffer_size(),
436 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
437 kNoErrors, frame_data)));
438
439 packet_.seqNum = 0x0009;
440 packet_.isFirstPacket = false;
441 packet_.markerBit = false;
442 FillPacket(1);
443 EXPECT_EQ(-3, session_.InsertPacket(packet_,
444 frame_buffer_,
445 kNoErrors,
446 frame_data));
447 }
448
449 TEST_F(TestVP8Partitions, TwoPartitionsOneLoss) {
450 // Partition 0 | Partition 1
451 // [ 0 ] [ 2 ] | [ 3 ]
452 packet_header_.type.Video.isFirstPacket = true;
453 vp8_header_->beginningOfPartition = true;
454 vp8_header_->partitionId = 0;
455 packet_header_.header.markerBit = false;
456 packet_header_.header.sequenceNumber = 0;
457 FillPacket(0);
458 VCMPacket* packet = new VCMPacket(packet_buffer_, packet_buffer_size(),
459 packet_header_);
460 EXPECT_EQ(packet_buffer_size(),
461 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
462 kNoErrors, frame_data)));
463 delete packet;
464
465 packet_header_.type.Video.isFirstPacket = false;
466 vp8_header_->partitionId = 0;
467 vp8_header_->beginningOfPartition = false;
468 packet_header_.header.markerBit = false;
469 packet_header_.header.sequenceNumber += 2;
470 FillPacket(2);
471 packet = new VCMPacket(packet_buffer_, packet_buffer_size(), packet_header_);
472 EXPECT_EQ(packet_buffer_size(),
473 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
474 kNoErrors, frame_data)));
475 delete packet;
476
477 packet_header_.type.Video.isFirstPacket = false;
478 vp8_header_->partitionId = 1;
479 vp8_header_->beginningOfPartition = true;
480 packet_header_.header.markerBit = true;
481 packet_header_.header.sequenceNumber += 1;
482 FillPacket(3);
483 packet = new VCMPacket(packet_buffer_, packet_buffer_size(), packet_header_);
484 EXPECT_EQ(packet_buffer_size(),
485 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
486 kNoErrors, frame_data)));
487 delete packet;
488
489 // One packet should be removed (end of partition 0).
490 EXPECT_EQ(2 * packet_buffer_size(),
491 session_.BuildVP8FragmentationHeader(
492 frame_buffer_, frame_buffer_size(), &fragmentation_));
493 SCOPED_TRACE("Calling VerifyPartition");
494 EXPECT_TRUE(VerifyPartition(0, 1, 0));
495 SCOPED_TRACE("Calling VerifyPartition");
496 EXPECT_TRUE(VerifyPartition(1, 1, 3));
497 }
498
499 TEST_F(TestVP8Partitions, TwoPartitionsOneLoss2) {
500 // Partition 0 | Partition 1
501 // [ 1 ] [ 2 ] | [ 3 ] [ 5 ]
502 packet_header_.type.Video.isFirstPacket = true;
503 vp8_header_->beginningOfPartition = true;
504 vp8_header_->partitionId = 0;
505 packet_header_.header.markerBit = false;
506 packet_header_.header.sequenceNumber = 1;
507 FillPacket(1);
508 VCMPacket* packet = new VCMPacket(packet_buffer_, packet_buffer_size(),
509 packet_header_);
510 EXPECT_EQ(packet_buffer_size(),
511 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
512 kNoErrors, frame_data)));
513 delete packet;
514
515 packet_header_.type.Video.isFirstPacket = false;
516 vp8_header_->partitionId = 0;
517 vp8_header_->beginningOfPartition = false;
518 packet_header_.header.markerBit = false;
519 packet_header_.header.sequenceNumber += 1;
520 FillPacket(2);
521 packet = new VCMPacket(packet_buffer_, packet_buffer_size(), packet_header_);
522 EXPECT_EQ(packet_buffer_size(),
523 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
524 kNoErrors, frame_data)));
525 delete packet;
526
527 packet_header_.type.Video.isFirstPacket = false;
528 vp8_header_->partitionId = 1;
529 vp8_header_->beginningOfPartition = true;
530 packet_header_.header.markerBit = false;
531 packet_header_.header.sequenceNumber += 1;
532 FillPacket(3);
533 packet = new VCMPacket(packet_buffer_, packet_buffer_size(), packet_header_);
534 EXPECT_EQ(packet_buffer_size(),
535 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
536 kNoErrors, frame_data)));
537 delete packet;
538
539 packet_header_.type.Video.isFirstPacket = false;
540 vp8_header_->partitionId = 1;
541 vp8_header_->beginningOfPartition = false;
542 packet_header_.header.markerBit = true;
543 packet_header_.header.sequenceNumber += 2;
544 FillPacket(5);
545 packet = new VCMPacket(packet_buffer_, packet_buffer_size(), packet_header_);
546 EXPECT_EQ(packet_buffer_size(),
547 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
548 kNoErrors, frame_data)));
549 delete packet;
550
551 // One packet should be removed (end of partition 2), 3 left.
552 EXPECT_EQ(3 * packet_buffer_size(),
553 session_.BuildVP8FragmentationHeader(
554 frame_buffer_, frame_buffer_size(), &fragmentation_));
555 SCOPED_TRACE("Calling VerifyPartition");
556 EXPECT_TRUE(VerifyPartition(0, 2, 1));
557 SCOPED_TRACE("Calling VerifyPartition");
558 EXPECT_TRUE(VerifyPartition(1, 1, 3));
559 }
560
561 TEST_F(TestVP8Partitions, TwoPartitionsNoLossWrap) {
562 // Partition 0 | Partition 1
563 // [ fffd ] [ fffe ] | [ ffff ] [ 0 ]
564 packet_header_.type.Video.isFirstPacket = true;
565 vp8_header_->beginningOfPartition = true;
566 vp8_header_->partitionId = 0;
567 packet_header_.header.markerBit = false;
568 packet_header_.header.sequenceNumber = 0xfffd;
569 FillPacket(0);
570 VCMPacket* packet = new VCMPacket(packet_buffer_, packet_buffer_size(),
571 packet_header_);
572 EXPECT_EQ(packet_buffer_size(),
573 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
574 kNoErrors, frame_data)));
575 delete packet;
576
577 packet_header_.type.Video.isFirstPacket = false;
578 vp8_header_->partitionId = 0;
579 vp8_header_->beginningOfPartition = false;
580 packet_header_.header.markerBit = false;
581 packet_header_.header.sequenceNumber += 1;
582 FillPacket(1);
583 packet = new VCMPacket(packet_buffer_, packet_buffer_size(), packet_header_);
584 EXPECT_EQ(packet_buffer_size(),
585 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
586 kNoErrors, frame_data)));
587 delete packet;
588
589 packet_header_.type.Video.isFirstPacket = false;
590 vp8_header_->partitionId = 1;
591 vp8_header_->beginningOfPartition = true;
592 packet_header_.header.markerBit = false;
593 packet_header_.header.sequenceNumber += 1;
594 FillPacket(2);
595 packet = new VCMPacket(packet_buffer_, packet_buffer_size(), packet_header_);
596 EXPECT_EQ(packet_buffer_size(),
597 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
598 kNoErrors, frame_data)));
599 delete packet;
600
601 packet_header_.type.Video.isFirstPacket = false;
602 vp8_header_->partitionId = 1;
603 vp8_header_->beginningOfPartition = false;
604 packet_header_.header.markerBit = true;
605 packet_header_.header.sequenceNumber += 1;
606 FillPacket(3);
607 packet = new VCMPacket(packet_buffer_, packet_buffer_size(), packet_header_);
608 EXPECT_EQ(packet_buffer_size(),
609 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
610 kNoErrors, frame_data)));
611 delete packet;
612
613 // No packet should be removed.
614 EXPECT_EQ(4 * packet_buffer_size(),
615 session_.BuildVP8FragmentationHeader(
616 frame_buffer_, frame_buffer_size(), &fragmentation_));
617 SCOPED_TRACE("Calling VerifyPartition");
618 EXPECT_TRUE(VerifyPartition(0, 2, 0));
619 SCOPED_TRACE("Calling VerifyPartition");
620 EXPECT_TRUE(VerifyPartition(1, 2, 2));
621 }
622
623 TEST_F(TestVP8Partitions, TwoPartitionsLossWrap) {
624 // Partition 0 | Partition 1
625 // [ fffd ] [ fffe ] | [ ffff ] [ 1 ]
626 packet_header_.type.Video.isFirstPacket = true;
627 vp8_header_->beginningOfPartition = true;
628 vp8_header_->partitionId = 0;
629 packet_header_.header.markerBit = false;
630 packet_header_.header.sequenceNumber = 0xfffd;
631 FillPacket(0);
632 VCMPacket* packet = new VCMPacket(packet_buffer_, packet_buffer_size(),
633 packet_header_);
634 EXPECT_EQ(packet_buffer_size(),
635 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
636 kNoErrors, frame_data)));
637 delete packet;
638
639 packet_header_.type.Video.isFirstPacket = false;
640 vp8_header_->partitionId = 0;
641 vp8_header_->beginningOfPartition = false;
642 packet_header_.header.markerBit = false;
643 packet_header_.header.sequenceNumber += 1;
644 FillPacket(1);
645 packet = new VCMPacket(packet_buffer_, packet_buffer_size(), packet_header_);
646 EXPECT_EQ(packet_buffer_size(),
647 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
648 kNoErrors, frame_data)));
649 delete packet;
650
651 packet_header_.type.Video.isFirstPacket = false;
652 vp8_header_->partitionId = 1;
653 vp8_header_->beginningOfPartition = true;
654 packet_header_.header.markerBit = false;
655 packet_header_.header.sequenceNumber += 1;
656 FillPacket(2);
657 packet = new VCMPacket(packet_buffer_, packet_buffer_size(), packet_header_);
658 EXPECT_EQ(packet_buffer_size(),
659 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
660 kNoErrors, frame_data)));
661 delete packet;
662
663 packet_header_.type.Video.isFirstPacket = false;
664 vp8_header_->partitionId = 1;
665 vp8_header_->beginningOfPartition = false;
666 packet_header_.header.markerBit = true;
667 packet_header_.header.sequenceNumber += 2;
668 FillPacket(3);
669 packet = new VCMPacket(packet_buffer_, packet_buffer_size(), packet_header_);
670 EXPECT_EQ(packet_buffer_size(),
671 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
672 kNoErrors, frame_data)));
673 delete packet;
674
675 // One packet should be removed from the last partition
676 EXPECT_EQ(3 * packet_buffer_size(),
677 session_.BuildVP8FragmentationHeader(
678 frame_buffer_, frame_buffer_size(), &fragmentation_));
679 SCOPED_TRACE("Calling VerifyPartition");
680 EXPECT_TRUE(VerifyPartition(0, 2, 0));
681 SCOPED_TRACE("Calling VerifyPartition");
682 EXPECT_TRUE(VerifyPartition(1, 1, 2));
683 }
684
685
686 TEST_F(TestVP8Partitions, ThreePartitionsOneMissing) {
687 // Partition 1 |Partition 2 | Partition 3
688 // [ 1 ] [ 2 ] | | [ 5 ] | [ 6 ]
689 packet_header_.type.Video.isFirstPacket = true;
690 vp8_header_->beginningOfPartition = true;
691 vp8_header_->partitionId = 0;
692 packet_header_.header.markerBit = false;
693 packet_header_.header.sequenceNumber = 1;
694 FillPacket(1);
695 VCMPacket* packet = new VCMPacket(packet_buffer_, packet_buffer_size(),
696 packet_header_);
697 EXPECT_EQ(packet_buffer_size(),
698 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
699 kNoErrors, frame_data)));
700 delete packet;
701
702 packet_header_.type.Video.isFirstPacket = false;
703 vp8_header_->partitionId = 0;
704 vp8_header_->beginningOfPartition = false;
705 packet_header_.header.markerBit = false;
706 packet_header_.header.sequenceNumber += 1;
707 FillPacket(2);
708 packet = new VCMPacket(packet_buffer_, packet_buffer_size(), packet_header_);
709 EXPECT_EQ(packet_buffer_size(),
710 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
711 kNoErrors, frame_data)));
712 delete packet;
713
714 packet_header_.type.Video.isFirstPacket = false;
715 vp8_header_->partitionId = 2;
716 vp8_header_->beginningOfPartition = true;
717 packet_header_.header.markerBit = false;
718 packet_header_.header.sequenceNumber += 3;
719 FillPacket(5);
720 packet = new VCMPacket(packet_buffer_, packet_buffer_size(), packet_header_);
721 EXPECT_EQ(packet_buffer_size(),
722 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
723 kNoErrors, frame_data)));
724 delete packet;
725
726 packet_header_.type.Video.isFirstPacket = false;
727 vp8_header_->partitionId = 2;
728 vp8_header_->beginningOfPartition = false;
729 packet_header_.header.markerBit = true;
730 packet_header_.header.sequenceNumber += 1;
731 FillPacket(6);
732 packet = new VCMPacket(packet_buffer_, packet_buffer_size(), packet_header_);
733 EXPECT_EQ(packet_buffer_size(),
734 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
735 kNoErrors, frame_data)));
736 delete packet;
737
738 // No packet should be removed.
739 EXPECT_EQ(4 * packet_buffer_size(),
740 session_.BuildVP8FragmentationHeader(
741 frame_buffer_, frame_buffer_size(), &fragmentation_));
742 SCOPED_TRACE("Calling VerifyPartition");
743 EXPECT_TRUE(VerifyPartition(0, 2, 1));
744 SCOPED_TRACE("Calling VerifyPartition");
745 EXPECT_TRUE(VerifyPartition(2, 2, 5));
746 }
747
748 TEST_F(TestVP8Partitions, ThreePartitionsLossInSecond) {
749 // Partition 0 |Partition 1 | Partition 2
750 // [ 1 ] [ 2 ] | [ 4 ] [ 5 ] | [ 6 ] [ 7 ]
751 packet_header_.type.Video.isFirstPacket = true;
752 vp8_header_->beginningOfPartition = true;
753 vp8_header_->partitionId = 0;
754 packet_header_.header.markerBit = false;
755 packet_header_.header.sequenceNumber = 1;
756 FillPacket(1);
757 VCMPacket* packet = new VCMPacket(packet_buffer_, packet_buffer_size(),
758 packet_header_);
759 EXPECT_EQ(packet_buffer_size(),
760 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
761 kNoErrors, frame_data)));
762 delete packet;
763
764 packet_header_.type.Video.isFirstPacket = false;
765 vp8_header_->partitionId = 0;
766 vp8_header_->beginningOfPartition = false;
767 packet_header_.header.markerBit = false;
768 packet_header_.header.sequenceNumber += 1;
769 FillPacket(2);
770 packet = new VCMPacket(packet_buffer_, packet_buffer_size(),
771 packet_header_);
772 EXPECT_EQ(packet_buffer_size(),
773 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
774 kNoErrors, frame_data)));
775 delete packet;
776
777 packet_header_.type.Video.isFirstPacket = false;
778 vp8_header_->partitionId = 1;
779 vp8_header_->beginningOfPartition = false;
780 packet_header_.header.markerBit = false;
781 packet_header_.header.sequenceNumber += 2;
782 FillPacket(4);
783 packet = new VCMPacket(packet_buffer_, packet_buffer_size(), packet_header_);
784 EXPECT_EQ(packet_buffer_size(),
785 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
786 kNoErrors, frame_data)));
787 delete packet;
788
789 packet_header_.type.Video.isFirstPacket = false;
790 vp8_header_->partitionId = 1;
791 vp8_header_->beginningOfPartition = false;
792 packet_header_.header.markerBit = false;
793 packet_header_.header.sequenceNumber += 1;
794 FillPacket(5);
795 packet = new VCMPacket(packet_buffer_, packet_buffer_size(), packet_header_);
796 EXPECT_EQ(packet_buffer_size(),
797 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
798 kNoErrors, frame_data)));
799 delete packet;
800
801 packet_header_.type.Video.isFirstPacket = false;
802 vp8_header_->partitionId = 2;
803 vp8_header_->beginningOfPartition = true;
804 packet_header_.header.markerBit = false;
805 packet_header_.header.sequenceNumber += 1;
806 FillPacket(6);
807 packet = new VCMPacket(packet_buffer_, packet_buffer_size(), packet_header_);
808 EXPECT_EQ(packet_buffer_size(),
809 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
810 kNoErrors, frame_data)));
811 delete packet;
812
813 packet_header_.type.Video.isFirstPacket = false;
814 vp8_header_->partitionId = 2;
815 vp8_header_->beginningOfPartition = false;
816 packet_header_.header.markerBit = true;
817 packet_header_.header.sequenceNumber += 1;
818 FillPacket(7);
819 packet = new VCMPacket(packet_buffer_, packet_buffer_size(), packet_header_);
820 EXPECT_EQ(packet_buffer_size(),
821 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
822 kNoErrors, frame_data)));
823 delete packet;
824
825 // 2 partitions left. 2 packets removed from second partition
826 EXPECT_EQ(4 * packet_buffer_size(),
827 session_.BuildVP8FragmentationHeader(
828 frame_buffer_, frame_buffer_size(), &fragmentation_));
829 SCOPED_TRACE("Calling VerifyPartition");
830 EXPECT_TRUE(VerifyPartition(0, 2, 1));
831 SCOPED_TRACE("Calling VerifyPartition");
832 EXPECT_TRUE(VerifyPartition(2, 2, 6));
833 }
834
835 TEST_F(TestVP8Partitions, AggregationOverTwoPackets) {
836 // Partition 0 | Partition 1 | Partition 2
837 // [ 0 | ] [ 1 ] | [ 2 ]
838 packet_header_.type.Video.isFirstPacket = true;
839 vp8_header_->beginningOfPartition = true;
840 vp8_header_->partitionId = 0;
841 packet_header_.header.markerBit = false;
842 packet_header_.header.sequenceNumber = 0;
843 FillPacket(0);
844 VCMPacket* packet = new VCMPacket(packet_buffer_, packet_buffer_size(),
845 packet_header_);
846 EXPECT_EQ(packet_buffer_size(),
847 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
848 kNoErrors, frame_data)));
849 delete packet;
850
851 packet_header_.type.Video.isFirstPacket = false;
852 vp8_header_->partitionId = 1;
853 vp8_header_->beginningOfPartition = false;
854 packet_header_.header.markerBit = false;
855 packet_header_.header.sequenceNumber += 1;
856 FillPacket(1);
857 packet = new VCMPacket(packet_buffer_, packet_buffer_size(), packet_header_);
858 EXPECT_EQ(packet_buffer_size(),
859 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
860 kNoErrors, frame_data)));
861 delete packet;
862
863 packet_header_.type.Video.isFirstPacket = false;
864 vp8_header_->partitionId = 2;
865 vp8_header_->beginningOfPartition = true;
866 packet_header_.header.markerBit = true;
867 packet_header_.header.sequenceNumber += 1;
868 FillPacket(2);
869 packet = new VCMPacket(packet_buffer_, packet_buffer_size(), packet_header_);
870 EXPECT_EQ(packet_buffer_size(),
871 static_cast<size_t>(session_.InsertPacket(*packet, frame_buffer_,
872 kNoErrors, frame_data)));
873 delete packet;
874
875 // No packets removed.
876 EXPECT_EQ(3 * packet_buffer_size(),
877 session_.BuildVP8FragmentationHeader(
878 frame_buffer_, frame_buffer_size(), &fragmentation_));
879 SCOPED_TRACE("Calling VerifyPartition");
880 EXPECT_TRUE(VerifyPartition(0, 2, 0));
881 // This partition is aggregated in partition 0
882 SCOPED_TRACE("Calling VerifyPartition");
883 EXPECT_TRUE(VerifyPartition(1, 0, 0));
884 SCOPED_TRACE("Calling VerifyPartition");
885 EXPECT_TRUE(VerifyPartition(2, 1, 2));
886 }
887
888 TEST_F(TestNalUnits, OnlyReceivedEmptyPacket) {
889 packet_.isFirstPacket = false;
890 packet_.completeNALU = kNaluComplete;
891 packet_.frameType = kEmptyFrame;
892 packet_.sizeBytes = 0;
893 packet_.seqNum = 0;
894 packet_.markerBit = false;
895 EXPECT_EQ(0, session_.InsertPacket(packet_,
896 frame_buffer_,
897 kNoErrors,
898 frame_data));
899
900 EXPECT_EQ(0U, session_.MakeDecodable());
901 EXPECT_EQ(0U, session_.SessionLength());
902 }
903
904 TEST_F(TestNalUnits, OneIsolatedNaluLoss) {
905 packet_.isFirstPacket = true;
906 packet_.completeNALU = kNaluComplete;
907 packet_.seqNum = 0;
908 packet_.markerBit = false;
909 FillPacket(0);
910 EXPECT_EQ(packet_buffer_size(),
911 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
912 kNoErrors, frame_data)));
913
914 packet_.isFirstPacket = false;
915 packet_.completeNALU = kNaluComplete;
916 packet_.seqNum += 2;
917 packet_.markerBit = true;
918 FillPacket(2);
919 EXPECT_EQ(packet_buffer_size(),
920 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
921 kNoErrors, frame_data)));
922
923 EXPECT_EQ(0U, session_.MakeDecodable());
924 EXPECT_EQ(2 * packet_buffer_size(), session_.SessionLength());
925 SCOPED_TRACE("Calling VerifyNalu");
926 EXPECT_TRUE(VerifyNalu(0, 1, 0));
927 SCOPED_TRACE("Calling VerifyNalu");
928 EXPECT_TRUE(VerifyNalu(1, 1, 2));
929 }
930
931 TEST_F(TestNalUnits, LossInMiddleOfNalu) {
932 packet_.isFirstPacket = true;
933 packet_.completeNALU = kNaluComplete;
934 packet_.seqNum = 0;
935 packet_.markerBit = false;
936 FillPacket(0);
937 EXPECT_EQ(packet_buffer_size(),
938 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
939 kNoErrors, frame_data)));
940
941 packet_.isFirstPacket = false;
942 packet_.completeNALU = kNaluEnd;
943 packet_.seqNum += 2;
944 packet_.markerBit = true;
945 FillPacket(2);
946 EXPECT_EQ(packet_buffer_size(),
947 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
948 kNoErrors, frame_data)));
949
950 EXPECT_EQ(packet_buffer_size(), session_.MakeDecodable());
951 EXPECT_EQ(packet_buffer_size(), session_.SessionLength());
952 SCOPED_TRACE("Calling VerifyNalu");
953 EXPECT_TRUE(VerifyNalu(0, 1, 0));
954 }
955
956 TEST_F(TestNalUnits, StartAndEndOfLastNalUnitLost) {
957 packet_.isFirstPacket = true;
958 packet_.completeNALU = kNaluComplete;
959 packet_.seqNum = 0;
960 packet_.markerBit = false;
961 FillPacket(0);
962 EXPECT_EQ(packet_buffer_size(),
963 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
964 kNoErrors, frame_data)));
965
966 packet_.isFirstPacket = false;
967 packet_.completeNALU = kNaluIncomplete;
968 packet_.seqNum += 2;
969 packet_.markerBit = false;
970 FillPacket(1);
971 EXPECT_EQ(packet_buffer_size(),
972 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
973 kNoErrors, frame_data)));
974
975 EXPECT_EQ(packet_buffer_size(), session_.MakeDecodable());
976 EXPECT_EQ(packet_buffer_size(), session_.SessionLength());
977 SCOPED_TRACE("Calling VerifyNalu");
978 EXPECT_TRUE(VerifyNalu(0, 1, 0));
979 }
980
981 TEST_F(TestNalUnits, ReorderWrapNoLoss) {
982 packet_.seqNum = 0xFFFF;
983 packet_.isFirstPacket = false;
984 packet_.completeNALU = kNaluIncomplete;
985 packet_.seqNum += 1;
986 packet_.markerBit = false;
987 FillPacket(1);
988 EXPECT_EQ(packet_buffer_size(),
989 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
990 kNoErrors, frame_data)));
991
992 packet_.isFirstPacket = true;
993 packet_.completeNALU = kNaluComplete;
994 packet_.seqNum -= 1;
995 packet_.markerBit = false;
996 FillPacket(0);
997 EXPECT_EQ(packet_buffer_size(),
998 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
999 kNoErrors, frame_data)));
1000
1001 packet_.isFirstPacket = false;
1002 packet_.completeNALU = kNaluEnd;
1003 packet_.seqNum += 2;
1004 packet_.markerBit = true;
1005 FillPacket(2);
1006 EXPECT_EQ(packet_buffer_size(),
1007 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
1008 kNoErrors, frame_data)));
1009
1010 EXPECT_EQ(0U, session_.MakeDecodable());
1011 EXPECT_EQ(3 * packet_buffer_size(), session_.SessionLength());
1012 SCOPED_TRACE("Calling VerifyNalu");
1013 EXPECT_TRUE(VerifyNalu(0, 1, 0));
1014 }
1015
1016 TEST_F(TestNalUnits, WrapLosses) {
1017 packet_.seqNum = 0xFFFF;
1018 packet_.isFirstPacket = false;
1019 packet_.completeNALU = kNaluIncomplete;
1020 packet_.markerBit = false;
1021 FillPacket(1);
1022 EXPECT_EQ(packet_buffer_size(),
1023 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
1024 kNoErrors, frame_data)));
1025
1026 packet_.isFirstPacket = false;
1027 packet_.completeNALU = kNaluEnd;
1028 packet_.seqNum += 2;
1029 packet_.markerBit = true;
1030 FillPacket(2);
1031 EXPECT_EQ(packet_buffer_size(),
1032 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
1033 kNoErrors, frame_data)));
1034
1035 EXPECT_EQ(2 * packet_buffer_size(), session_.MakeDecodable());
1036 EXPECT_EQ(0U, session_.SessionLength());
1037 }
1038
1039 TEST_F(TestNalUnits, ReorderWrapLosses) {
1040 packet_.seqNum = 0xFFFF;
1041
1042 packet_.isFirstPacket = false;
1043 packet_.completeNALU = kNaluEnd;
1044 packet_.seqNum += 2;
1045 packet_.markerBit = true;
1046 FillPacket(2);
1047 EXPECT_EQ(packet_buffer_size(),
1048 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
1049 kNoErrors, frame_data)));
1050
1051 packet_.seqNum -= 2;
1052 packet_.isFirstPacket = false;
1053 packet_.completeNALU = kNaluIncomplete;
1054 packet_.markerBit = false;
1055 FillPacket(1);
1056 EXPECT_EQ(packet_buffer_size(),
1057 static_cast<size_t>(session_.InsertPacket(packet_, frame_buffer_,
1058 kNoErrors, frame_data)));
1059
1060 EXPECT_EQ(2 * packet_buffer_size(), session_.MakeDecodable());
1061 EXPECT_EQ(0U, session_.SessionLength());
1062 }
1063
1064 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698