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

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

Issue 1959023002: [rtcp] Remb::Parse updated not to use RTCPUtility (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 7 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/remb.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/remb.h" 11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.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::IsEmpty; 18 using testing::IsEmpty;
18 using testing::make_tuple; 19 using testing::make_tuple;
19 using webrtc::rtcp::Remb; 20 using webrtc::rtcp::Remb;
20 using webrtc::RTCPUtility::RtcpCommonHeader;
21 using webrtc::RTCPUtility::RtcpParseCommonHeader;
22 21
23 namespace webrtc { 22 namespace webrtc {
24 namespace { 23 namespace {
25
26 const uint32_t kSenderSsrc = 0x12345678; 24 const uint32_t kSenderSsrc = 0x12345678;
27 const uint32_t kRemoteSsrcs[] = {0x23456789, 0x2345678a, 0x2345678b}; 25 const uint32_t kRemoteSsrcs[] = {0x23456789, 0x2345678a, 0x2345678b};
28 const uint32_t kBitrateBps = 0x3fb93 * 2; // 522022; 26 const uint32_t kBitrateBps = 0x3fb93 * 2; // 522022;
27 const uint64_t kBitrateBps64bit = 0x3fb93ULL << 30;
29 const uint8_t kPacket[] = {0x8f, 206, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78, 28 const uint8_t kPacket[] = {0x8f, 206, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78,
30 0x00, 0x00, 0x00, 0x00, 'R', 'E', 'M', 'B', 29 0x00, 0x00, 0x00, 0x00, 'R', 'E', 'M', 'B',
31 0x03, 0x07, 0xfb, 0x93, 0x23, 0x45, 0x67, 0x89, 30 0x03, 0x07, 0xfb, 0x93, 0x23, 0x45, 0x67, 0x89,
32 0x23, 0x45, 0x67, 0x8a, 0x23, 0x45, 0x67, 0x8b}; 31 0x23, 0x45, 0x67, 0x8a, 0x23, 0x45, 0x67, 0x8b};
33 const size_t kPacketLength = sizeof(kPacket); 32 const size_t kPacketLength = sizeof(kPacket);
34 33 } // namespace
35 bool ParseRemb(const uint8_t* buffer, size_t length, Remb* remb) {
36 RtcpCommonHeader header;
37 EXPECT_TRUE(RtcpParseCommonHeader(buffer, length, &header));
38 EXPECT_EQ(length, header.BlockSize());
39 return remb->Parse(header, buffer + RtcpCommonHeader::kHeaderSizeBytes);
40 }
41 34
42 TEST(RtcpPacketRembTest, Create) { 35 TEST(RtcpPacketRembTest, Create) {
43 Remb remb; 36 Remb remb;
44 remb.From(kSenderSsrc); 37 remb.From(kSenderSsrc);
45 remb.AppliesTo(kRemoteSsrcs[0]); 38 remb.AppliesTo(kRemoteSsrcs[0]);
46 remb.AppliesTo(kRemoteSsrcs[1]); 39 remb.AppliesTo(kRemoteSsrcs[1]);
47 remb.AppliesTo(kRemoteSsrcs[2]); 40 remb.AppliesTo(kRemoteSsrcs[2]);
48 remb.WithBitrateBps(kBitrateBps); 41 remb.WithBitrateBps(kBitrateBps);
49 42
50 rtc::Buffer packet = remb.Build(); 43 rtc::Buffer packet = remb.Build();
51 44
52 EXPECT_THAT(make_tuple(packet.data(), packet.size()), 45 EXPECT_THAT(make_tuple(packet.data(), packet.size()),
53 ElementsAreArray(kPacket)); 46 ElementsAreArray(kPacket));
54 } 47 }
55 48
56 TEST(RtcpPacketRembTest, Parse) { 49 TEST(RtcpPacketRembTest, Parse) {
57 Remb remb; 50 Remb remb;
58 EXPECT_TRUE(ParseRemb(kPacket, kPacketLength, &remb)); 51 EXPECT_TRUE(test::ParseSinglePacket(kPacket, &remb));
59 const Remb& parsed = remb; 52 const Remb& parsed = remb;
60 53
61 EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc()); 54 EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc());
62 EXPECT_EQ(kBitrateBps, parsed.bitrate_bps()); 55 EXPECT_EQ(kBitrateBps, parsed.bitrate_bps());
63 EXPECT_THAT(parsed.ssrcs(), ElementsAreArray(kRemoteSsrcs)); 56 EXPECT_THAT(parsed.ssrcs(), ElementsAreArray(kRemoteSsrcs));
64 } 57 }
65 58
66 TEST(RtcpPacketRembTest, CreateAndParseWithoutSsrcs) { 59 TEST(RtcpPacketRembTest, CreateAndParseWithoutSsrcs) {
67 Remb remb; 60 Remb remb;
68 remb.From(kSenderSsrc); 61 remb.From(kSenderSsrc);
69 remb.WithBitrateBps(kBitrateBps); 62 remb.WithBitrateBps(kBitrateBps);
70 rtc::Buffer packet = remb.Build(); 63 rtc::Buffer packet = remb.Build();
71 64
72 Remb parsed; 65 Remb parsed;
73 EXPECT_TRUE(ParseRemb(packet.data(), packet.size(), &parsed)); 66 EXPECT_TRUE(test::ParseSinglePacket(packet, &parsed));
74 EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc()); 67 EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc());
75 EXPECT_EQ(kBitrateBps, parsed.bitrate_bps()); 68 EXPECT_EQ(kBitrateBps, parsed.bitrate_bps());
76 EXPECT_THAT(parsed.ssrcs(), IsEmpty()); 69 EXPECT_THAT(parsed.ssrcs(), IsEmpty());
77 } 70 }
78 71
72 TEST(RtcpPacketRembTest, CreateAndParse64bitBitrate) {
73 Remb remb;
74 remb.WithBitrateBps(kBitrateBps64bit);
75 rtc::Buffer packet = remb.Build();
76
77 Remb parsed;
78 EXPECT_TRUE(test::ParseSinglePacket(packet, &parsed));
79 EXPECT_EQ(kBitrateBps64bit, parsed.bitrate_bps());
80 }
81
79 TEST(RtcpPacketRembTest, ParseFailsOnTooSmallPacketToBeRemb) { 82 TEST(RtcpPacketRembTest, ParseFailsOnTooSmallPacketToBeRemb) {
80 uint8_t packet[kPacketLength]; 83 // Make it too small.
81 memcpy(packet, kPacket, kPacketLength); 84 constexpr size_t kTooSmallSize = (1 + 3) * 4;
82 packet[3] = 3; // Make it too small. 85 uint8_t packet[kTooSmallSize];
86 memcpy(packet, kPacket, kTooSmallSize);
87 packet[3] = 3;
83 88
84 Remb remb; 89 Remb remb;
85 EXPECT_FALSE(ParseRemb(packet, (1 + 3) * 4, &remb)); 90 EXPECT_FALSE(test::ParseSinglePacket(packet, &remb));
86 } 91 }
87 92
88 TEST(RtcpPacketRembTest, ParseFailsWhenUniqueIdentifierIsNotRemb) { 93 TEST(RtcpPacketRembTest, ParseFailsWhenUniqueIdentifierIsNotRemb) {
89 uint8_t packet[kPacketLength]; 94 uint8_t packet[kPacketLength];
90 memcpy(packet, kPacket, kPacketLength); 95 memcpy(packet, kPacket, kPacketLength);
91 packet[12] = 'N'; // Swap 'R' -> 'N' in the 'REMB' unique identifier. 96 packet[12] = 'N'; // Swap 'R' -> 'N' in the 'REMB' unique identifier.
92 97
93 Remb remb; 98 Remb remb;
94 EXPECT_FALSE(ParseRemb(packet, kPacketLength, &remb)); 99 EXPECT_FALSE(test::ParseSinglePacket(packet, &remb));
100 }
101
102 TEST(RtcpPacketRembTest, ParseFailsWhenBitrateDoNotFitIn64bits) {
103 uint8_t packet[kPacketLength];
104 memcpy(packet, kPacket, kPacketLength);
105 packet[17] |= 0xfc; // Set exponenta component to maximum of 63.
106 packet[19] |= 0x02; // Ensure mantissa is at least 2.
107
108 Remb remb;
109 EXPECT_FALSE(test::ParseSinglePacket(packet, &remb));
95 } 110 }
96 111
97 TEST(RtcpPacketRembTest, ParseFailsWhenSsrcCountMismatchLength) { 112 TEST(RtcpPacketRembTest, ParseFailsWhenSsrcCountMismatchLength) {
98 uint8_t packet[kPacketLength]; 113 uint8_t packet[kPacketLength];
99 memcpy(packet, kPacket, kPacketLength); 114 memcpy(packet, kPacket, kPacketLength);
100 packet[16]++; // Swap 3 -> 4 in the ssrcs count. 115 packet[16]++; // Swap 3 -> 4 in the ssrcs count.
101 116
102 Remb remb; 117 Remb remb;
103 EXPECT_FALSE(ParseRemb(packet, kPacketLength, &remb)); 118 EXPECT_FALSE(test::ParseSinglePacket(packet, &remb));
104 } 119 }
105 120
106 TEST(RtcpPacketRembTest, TooManySsrcs) { 121 TEST(RtcpPacketRembTest, TooManySsrcs) {
107 const size_t kMax = 0xff; 122 const size_t kMax = 0xff;
108 Remb remb; 123 Remb remb;
109 for (size_t i = 1; i <= kMax; ++i) 124 for (size_t i = 1; i <= kMax; ++i)
110 EXPECT_TRUE(remb.AppliesTo(kRemoteSsrcs[0] + i)); 125 EXPECT_TRUE(remb.AppliesTo(kRemoteSsrcs[0] + i));
111 EXPECT_FALSE(remb.AppliesTo(kRemoteSsrcs[0])); 126 EXPECT_FALSE(remb.AppliesTo(kRemoteSsrcs[0]));
112 } 127 }
113 128
114 TEST(RtcpPacketRembTest, TooManySsrcsForBatchAssign) { 129 TEST(RtcpPacketRembTest, TooManySsrcsForBatchAssign) {
115 const uint32_t kRemoteSsrc = kRemoteSsrcs[0]; 130 const uint32_t kRemoteSsrc = kRemoteSsrcs[0];
116 const size_t kMax = 0xff; 131 const size_t kMax = 0xff;
117 const std::vector<uint32_t> kAllButOneSsrc(kMax - 1, kRemoteSsrc); 132 const std::vector<uint32_t> kAllButOneSsrc(kMax - 1, kRemoteSsrc);
118 const std::vector<uint32_t> kTwoSsrcs(2, kRemoteSsrc); 133 const std::vector<uint32_t> kTwoSsrcs(2, kRemoteSsrc);
119 134
120 Remb remb; 135 Remb remb;
121 EXPECT_TRUE(remb.AppliesToMany(kAllButOneSsrc)); 136 EXPECT_TRUE(remb.AppliesToMany(kAllButOneSsrc));
122 // Should be no place for 2 more. 137 // Should be no place for 2 more.
123 EXPECT_FALSE(remb.AppliesToMany(kTwoSsrcs)); 138 EXPECT_FALSE(remb.AppliesToMany(kTwoSsrcs));
124 // But enough place for 1 more. 139 // But enough place for 1 more.
125 EXPECT_TRUE(remb.AppliesTo(kRemoteSsrc)); 140 EXPECT_TRUE(remb.AppliesTo(kRemoteSsrc));
126 // But not for another one. 141 // But not for another one.
127 EXPECT_FALSE(remb.AppliesTo(kRemoteSsrc)); 142 EXPECT_FALSE(remb.AppliesTo(kRemoteSsrc));
128 } 143 }
129 } // namespace 144
130 } // namespace webrtc 145 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698