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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtp_format_vp8_unittest.cc

Issue 2522553002: RtpPacketizer::NextPacket fills RtpPacket instead of payload. (Closed)
Patch Set: nit Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include <memory> 11 #include <memory>
12 12
13 #include "webrtc/modules/rtp_rtcp/source/rtp_format_vp8.h" 13 #include "webrtc/modules/rtp_rtcp/source/rtp_format_vp8.h"
14 #include "webrtc/modules/rtp_rtcp/source/rtp_format_vp8_test_helper.h" 14 #include "webrtc/modules/rtp_rtcp/source/rtp_format_vp8_test_helper.h"
15 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_to_send.h"
15 #include "webrtc/test/gmock.h" 16 #include "webrtc/test/gmock.h"
16 #include "webrtc/test/gtest.h" 17 #include "webrtc/test/gtest.h"
17 #include "webrtc/typedefs.h" 18 #include "webrtc/typedefs.h"
18 19
19 #define CHECK_ARRAY_SIZE(expected_size, array) \ 20 #define CHECK_ARRAY_SIZE(expected_size, array) \
20 static_assert(expected_size == sizeof(array) / sizeof(array[0]), \ 21 static_assert(expected_size == sizeof(array) / sizeof(array[0]), \
21 "check array size"); 22 "check array size");
22 23
23 namespace webrtc { 24 namespace webrtc {
24 namespace { 25 namespace {
26
27 using ::testing::ElementsAreArray;
28 using ::testing::make_tuple;
29
30 constexpr RtpPacketToSend::ExtensionManager* kNoExtensions = nullptr;
25 // Payload descriptor 31 // Payload descriptor
26 // 0 1 2 3 4 5 6 7 32 // 0 1 2 3 4 5 6 7
27 // +-+-+-+-+-+-+-+-+ 33 // +-+-+-+-+-+-+-+-+
28 // |X|R|N|S|PartID | (REQUIRED) 34 // |X|R|N|S|PartID | (REQUIRED)
29 // +-+-+-+-+-+-+-+-+ 35 // +-+-+-+-+-+-+-+-+
30 // X: |I|L|T|K| RSV | (OPTIONAL) 36 // X: |I|L|T|K| RSV | (OPTIONAL)
31 // +-+-+-+-+-+-+-+-+ 37 // +-+-+-+-+-+-+-+-+
32 // I: | PictureID | (OPTIONAL) 38 // I: | PictureID | (OPTIONAL)
33 // +-+-+-+-+-+-+-+-+ 39 // +-+-+-+-+-+-+-+-+
34 // L: | TL0PICIDX | (OPTIONAL) 40 // L: | TL0PICIDX | (OPTIONAL)
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 TEST_F(RtpDepacketizerVp8Test, BasicHeader) { 431 TEST_F(RtpDepacketizerVp8Test, BasicHeader) {
426 const uint8_t kHeaderLength = 1; 432 const uint8_t kHeaderLength = 1;
427 uint8_t packet[4] = {0}; 433 uint8_t packet[4] = {0};
428 packet[0] = 0x14; // Binary 0001 0100; S = 1, PartID = 4. 434 packet[0] = 0x14; // Binary 0001 0100; S = 1, PartID = 4.
429 packet[1] = 0x01; // P frame. 435 packet[1] = 0x01; // P frame.
430 RtpDepacketizer::ParsedPayload payload; 436 RtpDepacketizer::ParsedPayload payload;
431 437
432 ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); 438 ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet)));
433 ExpectPacket( 439 ExpectPacket(
434 &payload, packet + kHeaderLength, sizeof(packet) - kHeaderLength); 440 &payload, packet + kHeaderLength, sizeof(packet) - kHeaderLength);
441
435 EXPECT_EQ(kVideoFrameDelta, payload.frame_type); 442 EXPECT_EQ(kVideoFrameDelta, payload.frame_type);
436 EXPECT_EQ(kRtpVideoVp8, payload.type.Video.codec); 443 EXPECT_EQ(kRtpVideoVp8, payload.type.Video.codec);
437 VerifyBasicHeader(&payload.type, 0, 1, 4); 444 VerifyBasicHeader(&payload.type, 0, 1, 4);
438 VerifyExtensions( 445 VerifyExtensions(
439 &payload.type, kNoPictureId, kNoTl0PicIdx, kNoTemporalIdx, kNoKeyIdx); 446 &payload.type, kNoPictureId, kNoTl0PicIdx, kNoTemporalIdx, kNoKeyIdx);
440 } 447 }
441 448
442 TEST_F(RtpDepacketizerVp8Test, PictureID) { 449 TEST_F(RtpDepacketizerVp8Test, PictureID) {
443 const uint8_t kHeaderLength1 = 3; 450 const uint8_t kHeaderLength1 = 3;
444 const uint8_t kHeaderLength2 = 4; 451 const uint8_t kHeaderLength2 = 4;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
557 packet[2] = 0x80 | 17; // ... but only 2 bytes PictureID is provided. 564 packet[2] = 0x80 | 17; // ... but only 2 bytes PictureID is provided.
558 packet[3] = 17; // PictureID, low 8 bits. 565 packet[3] = 17; // PictureID, low 8 bits.
559 RtpDepacketizer::ParsedPayload payload; 566 RtpDepacketizer::ParsedPayload payload;
560 567
561 EXPECT_FALSE(depacketizer_->Parse(&payload, packet, sizeof(packet))); 568 EXPECT_FALSE(depacketizer_->Parse(&payload, packet, sizeof(packet)));
562 } 569 }
563 570
564 TEST_F(RtpDepacketizerVp8Test, TestWithPacketizer) { 571 TEST_F(RtpDepacketizerVp8Test, TestWithPacketizer) {
565 const uint8_t kHeaderLength = 5; 572 const uint8_t kHeaderLength = 5;
566 uint8_t data[10] = {0}; 573 uint8_t data[10] = {0};
567 uint8_t packet[20] = {0}; 574 RtpPacketToSend packet(kNoExtensions);
568 RTPVideoHeaderVP8 input_header; 575 RTPVideoHeaderVP8 input_header;
569 input_header.nonReference = true; 576 input_header.nonReference = true;
570 input_header.pictureId = 300; 577 input_header.pictureId = 300;
571 input_header.temporalIdx = 1; 578 input_header.temporalIdx = 1;
572 input_header.layerSync = false; 579 input_header.layerSync = false;
573 input_header.tl0PicIdx = kNoTl0PicIdx; // Disable. 580 input_header.tl0PicIdx = kNoTl0PicIdx; // Disable.
574 input_header.keyIdx = 31; 581 input_header.keyIdx = 31;
575 RtpPacketizerVp8 packetizer(input_header, 20); 582 RtpPacketizerVp8 packetizer(input_header, 20);
576 packetizer.SetPayloadData(data, 10, NULL); 583 packetizer.SetPayloadData(data, 10, NULL);
577 bool last; 584 bool last;
578 size_t send_bytes; 585 ASSERT_TRUE(packetizer.NextPacket(&packet, &last));
579 ASSERT_TRUE(packetizer.NextPacket(packet, &send_bytes, &last)); 586 EXPECT_TRUE(last);
580 ASSERT_TRUE(last); 587 EXPECT_TRUE(packet.Marker());
588
589 auto rtp_payload = packet.payload();
581 RtpDepacketizer::ParsedPayload payload; 590 RtpDepacketizer::ParsedPayload payload;
582 591 ASSERT_TRUE(
583 ASSERT_TRUE(depacketizer_->Parse(&payload, packet, sizeof(packet))); 592 depacketizer_->Parse(&payload, rtp_payload.data(), rtp_payload.size()));
584 ExpectPacket( 593 auto vp8_payload = rtp_payload.subview(kHeaderLength);
585 &payload, packet + kHeaderLength, sizeof(packet) - kHeaderLength); 594 ExpectPacket(&payload, vp8_payload.data(), vp8_payload.size());
586 EXPECT_EQ(kVideoFrameKey, payload.frame_type); 595 EXPECT_EQ(kVideoFrameKey, payload.frame_type);
587 EXPECT_EQ(kRtpVideoVp8, payload.type.Video.codec); 596 EXPECT_EQ(kRtpVideoVp8, payload.type.Video.codec);
588 VerifyBasicHeader(&payload.type, 1, 1, 0); 597 VerifyBasicHeader(&payload.type, 1, 1, 0);
589 VerifyExtensions(&payload.type, 598 VerifyExtensions(&payload.type,
590 input_header.pictureId, 599 input_header.pictureId,
591 input_header.tl0PicIdx, 600 input_header.tl0PicIdx,
592 input_header.temporalIdx, 601 input_header.temporalIdx,
593 input_header.keyIdx); 602 input_header.keyIdx);
594 EXPECT_EQ(payload.type.Video.codecHeader.VP8.layerSync, 603 EXPECT_EQ(payload.type.Video.codecHeader.VP8.layerSync,
595 input_header.layerSync); 604 input_header.layerSync);
596 } 605 }
597 606
598 TEST_F(RtpDepacketizerVp8Test, TestEmptyPayload) { 607 TEST_F(RtpDepacketizerVp8Test, TestEmptyPayload) {
599 // Using a wild pointer to crash on accesses from inside the depacketizer. 608 // Using a wild pointer to crash on accesses from inside the depacketizer.
600 uint8_t* garbage_ptr = reinterpret_cast<uint8_t*>(0x4711); 609 uint8_t* garbage_ptr = reinterpret_cast<uint8_t*>(0x4711);
601 RtpDepacketizer::ParsedPayload payload; 610 RtpDepacketizer::ParsedPayload payload;
602 EXPECT_FALSE(depacketizer_->Parse(&payload, garbage_ptr, 0)); 611 EXPECT_FALSE(depacketizer_->Parse(&payload, garbage_ptr, 0));
603 } 612 }
604 } // namespace webrtc 613 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698