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

Side by Side Diff: webrtc/modules/rtp_rtcp/source/rtcp_packet/sli_unittest.cc

Issue 2023803002: [rtcp] Fir/Sli/Rpsi updated not to use RTCPUtility (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 6 months 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
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2016 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 "webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.h" 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.h"
12 12
13 #include "testing/gmock/include/gmock/gmock.h" 13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "webrtc/test/rtcp_packet_parser.h"
15 16
16 using testing::ElementsAreArray; 17 using testing::ElementsAreArray;
17 using testing::make_tuple; 18 using testing::make_tuple;
18 using webrtc::rtcp::Sli; 19 using webrtc::rtcp::Sli;
19 using webrtc::RTCPUtility::RtcpCommonHeader;
20 using webrtc::RTCPUtility::RtcpParseCommonHeader;
21 20
22 namespace webrtc { 21 namespace webrtc {
23 namespace { 22 namespace {
23 constexpr uint32_t kSenderSsrc = 0x12345678;
24 constexpr uint32_t kRemoteSsrc = 0x23456789;
24 25
25 const uint32_t kSenderSsrc = 0x12345678; 26 constexpr uint8_t kPictureId = 0x3f;
26 const uint32_t kRemoteSsrc = 0x23456789; 27 constexpr uint16_t kFirstMb = 0x1e61;
27 28 constexpr uint16_t kNumberOfMb = 0x1a0a;
28 const uint8_t kPictureId = 0x3f; 29 constexpr uint32_t kSliItem = (static_cast<uint32_t>(kFirstMb) << 19) |
29 const uint16_t kFirstMb = 0x1e61; 30 (static_cast<uint32_t>(kNumberOfMb) << 6) |
30 const uint16_t kNumberOfMb = 0x1a0a; 31 static_cast<uint32_t>(kPictureId);
31 const uint32_t kSliItem = (static_cast<uint32_t>(kFirstMb) << 19) |
32 (static_cast<uint32_t>(kNumberOfMb) << 6) |
33 static_cast<uint32_t>(kPictureId);
34 32
35 // Manually created Sli packet matching constants above. 33 // Manually created Sli packet matching constants above.
36 const uint8_t kPacket[] = {0x82, 206, 0x00, 0x03, 34 constexpr uint8_t kPacket[] = {0x82, 206, 0x00, 0x03,
37 0x12, 0x34, 0x56, 0x78, 35 0x12, 0x34, 0x56, 0x78,
38 0x23, 0x45, 0x67, 0x89, 36 0x23, 0x45, 0x67, 0x89,
39 (kSliItem >> 24) & 0xff, 37 (kSliItem >> 24) & 0xff,
40 (kSliItem >> 16) & 0xff, 38 (kSliItem >> 16) & 0xff,
41 (kSliItem >> 8) & 0xff, 39 (kSliItem >> 8) & 0xff,
42 kSliItem & 0xff}; 40 kSliItem & 0xff};
43 const size_t kPacketLength = sizeof(kPacket); 41 } // namespace
44
45 bool ParseSli(const uint8_t* buffer, size_t length, Sli* sli) {
46 RtcpCommonHeader header;
47 EXPECT_TRUE(RtcpParseCommonHeader(buffer, length, &header));
48 EXPECT_EQ(length, header.BlockSize());
49 return sli->Parse(header, buffer + RtcpCommonHeader::kHeaderSizeBytes);
50 }
51 42
52 TEST(RtcpPacketSliTest, Create) { 43 TEST(RtcpPacketSliTest, Create) {
53 Sli sli; 44 Sli sli;
54 sli.From(kSenderSsrc); 45 sli.From(kSenderSsrc);
55 sli.To(kRemoteSsrc); 46 sli.To(kRemoteSsrc);
56 sli.WithPictureId(kPictureId, kFirstMb, kNumberOfMb); 47 sli.WithPictureId(kPictureId, kFirstMb, kNumberOfMb);
57 48
58 rtc::Buffer packet = sli.Build(); 49 rtc::Buffer packet = sli.Build();
59 50
60 EXPECT_THAT(make_tuple(packet.data(), packet.size()), 51 EXPECT_THAT(make_tuple(packet.data(), packet.size()),
61 ElementsAreArray(kPacket)); 52 ElementsAreArray(kPacket));
62 } 53 }
63 54
64 TEST(RtcpPacketSliTest, Parse) { 55 TEST(RtcpPacketSliTest, Parse) {
65 Sli mutable_parsed; 56 Sli mutable_parsed;
66 EXPECT_TRUE(ParseSli(kPacket, kPacketLength, &mutable_parsed)); 57 EXPECT_TRUE(test::ParseSinglePacket(kPacket, &mutable_parsed));
67 const Sli& parsed = mutable_parsed; // Read values from constant object. 58 const Sli& parsed = mutable_parsed; // Read values from constant object.
68 59
69 EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc()); 60 EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc());
70 EXPECT_EQ(kRemoteSsrc, parsed.media_ssrc()); 61 EXPECT_EQ(kRemoteSsrc, parsed.media_ssrc());
71 EXPECT_EQ(1u, parsed.macroblocks().size()); 62 EXPECT_EQ(1u, parsed.macroblocks().size());
72 EXPECT_EQ(kFirstMb, parsed.macroblocks()[0].first()); 63 EXPECT_EQ(kFirstMb, parsed.macroblocks()[0].first());
73 EXPECT_EQ(kNumberOfMb, parsed.macroblocks()[0].number()); 64 EXPECT_EQ(kNumberOfMb, parsed.macroblocks()[0].number());
74 EXPECT_EQ(kPictureId, parsed.macroblocks()[0].picture_id()); 65 EXPECT_EQ(kPictureId, parsed.macroblocks()[0].picture_id());
75 } 66 }
76 67
77 TEST(RtcpPacketSliTest, ParseFailsOnTooSmallPacket) { 68 TEST(RtcpPacketSliTest, ParseFailsOnTooSmallPacket) {
78 Sli sli; 69 Sli sli;
79 sli.From(kSenderSsrc); 70 sli.From(kSenderSsrc);
80 sli.To(kRemoteSsrc); 71 sli.To(kRemoteSsrc);
81 sli.WithPictureId(kPictureId, kFirstMb, kNumberOfMb); 72 sli.WithPictureId(kPictureId, kFirstMb, kNumberOfMb);
82 73
83 rtc::Buffer packet = sli.Build(); 74 rtc::Buffer packet = sli.Build();
84 packet.data()[3]--; // Decrease size by 1 word (4 bytes). 75 packet[3]--; // Decrease size by 1 word (4 bytes).
76 packet.SetSize(packet.size() - 4);
85 77
86 EXPECT_FALSE(ParseSli(packet.data(), packet.size() - 4, &sli)); 78 EXPECT_FALSE(test::ParseSinglePacket(packet, &sli));
87 } 79 }
88 80
89 } // namespace
90 } // namespace webrtc 81 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet/sli.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698