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

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
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) {
åsapersson 2016/05/12 11:06:05 will this test ParseFailsWhenSsrcCountMismatchLeng
danilchap 2016/05/12 11:36:35 Yes, it fails for the wrong reason. It should fail
80 uint8_t packet[kPacketLength]; 83 uint8_t packet[kPacketLength - 4];
81 memcpy(packet, kPacket, kPacketLength); 84 memcpy(packet, kPacket, kPacketLength - 4);
82 packet[3] = 3; // Make it too small. 85 packet[3]--; // Make it too small.
83 86
84 Remb remb; 87 Remb remb;
85 EXPECT_FALSE(ParseRemb(packet, (1 + 3) * 4, &remb)); 88 EXPECT_FALSE(test::ParseSinglePacket(packet, &remb));
86 } 89 }
87 90
88 TEST(RtcpPacketRembTest, ParseFailsWhenUniqueIdentifierIsNotRemb) { 91 TEST(RtcpPacketRembTest, ParseFailsWhenUniqueIdentifierIsNotRemb) {
89 uint8_t packet[kPacketLength]; 92 uint8_t packet[kPacketLength];
90 memcpy(packet, kPacket, kPacketLength); 93 memcpy(packet, kPacket, kPacketLength);
91 packet[12] = 'N'; // Swap 'R' -> 'N' in the 'REMB' unique identifier. 94 packet[12] = 'N'; // Swap 'R' -> 'N' in the 'REMB' unique identifier.
92 95
93 Remb remb; 96 Remb remb;
94 EXPECT_FALSE(ParseRemb(packet, kPacketLength, &remb)); 97 EXPECT_FALSE(test::ParseSinglePacket(packet, &remb));
98 }
99
100 TEST(RtcpPacketRembTest, ParseFailsWhenBitrateDoNotFitIn64bits) {
101 uint8_t packet[kPacketLength];
102 memcpy(packet, kPacket, kPacketLength);
103 packet[17] |= 0xfc; // Set exponenta component to maximum of 63.
104 packet[19] |= 0x02; // Ensure mantissa is at least 2.
105
106 Remb remb;
107 EXPECT_FALSE(test::ParseSinglePacket(packet, &remb));
95 } 108 }
96 109
97 TEST(RtcpPacketRembTest, ParseFailsWhenSsrcCountMismatchLength) { 110 TEST(RtcpPacketRembTest, ParseFailsWhenSsrcCountMismatchLength) {
98 uint8_t packet[kPacketLength]; 111 uint8_t packet[kPacketLength];
99 memcpy(packet, kPacket, kPacketLength); 112 memcpy(packet, kPacket, kPacketLength);
100 packet[16]++; // Swap 3 -> 4 in the ssrcs count. 113 packet[16]++; // Swap 3 -> 4 in the ssrcs count.
101 114
102 Remb remb; 115 Remb remb;
103 EXPECT_FALSE(ParseRemb(packet, kPacketLength, &remb)); 116 EXPECT_FALSE(test::ParseSinglePacket(packet, &remb));
104 } 117 }
105 118
106 TEST(RtcpPacketRembTest, TooManySsrcs) { 119 TEST(RtcpPacketRembTest, TooManySsrcs) {
107 const size_t kMax = 0xff; 120 const size_t kMax = 0xff;
108 Remb remb; 121 Remb remb;
109 for (size_t i = 1; i <= kMax; ++i) 122 for (size_t i = 1; i <= kMax; ++i)
110 EXPECT_TRUE(remb.AppliesTo(kRemoteSsrcs[0] + i)); 123 EXPECT_TRUE(remb.AppliesTo(kRemoteSsrcs[0] + i));
111 EXPECT_FALSE(remb.AppliesTo(kRemoteSsrcs[0])); 124 EXPECT_FALSE(remb.AppliesTo(kRemoteSsrcs[0]));
112 } 125 }
113 126
114 TEST(RtcpPacketRembTest, TooManySsrcsForBatchAssign) { 127 TEST(RtcpPacketRembTest, TooManySsrcsForBatchAssign) {
115 const uint32_t kRemoteSsrc = kRemoteSsrcs[0]; 128 const uint32_t kRemoteSsrc = kRemoteSsrcs[0];
116 const size_t kMax = 0xff; 129 const size_t kMax = 0xff;
117 const std::vector<uint32_t> kAllButOneSsrc(kMax - 1, kRemoteSsrc); 130 const std::vector<uint32_t> kAllButOneSsrc(kMax - 1, kRemoteSsrc);
118 const std::vector<uint32_t> kTwoSsrcs(2, kRemoteSsrc); 131 const std::vector<uint32_t> kTwoSsrcs(2, kRemoteSsrc);
119 132
120 Remb remb; 133 Remb remb;
121 EXPECT_TRUE(remb.AppliesToMany(kAllButOneSsrc)); 134 EXPECT_TRUE(remb.AppliesToMany(kAllButOneSsrc));
122 // Should be no place for 2 more. 135 // Should be no place for 2 more.
123 EXPECT_FALSE(remb.AppliesToMany(kTwoSsrcs)); 136 EXPECT_FALSE(remb.AppliesToMany(kTwoSsrcs));
124 // But enough place for 1 more. 137 // But enough place for 1 more.
125 EXPECT_TRUE(remb.AppliesTo(kRemoteSsrc)); 138 EXPECT_TRUE(remb.AppliesTo(kRemoteSsrc));
126 // But not for another one. 139 // But not for another one.
127 EXPECT_FALSE(remb.AppliesTo(kRemoteSsrc)); 140 EXPECT_FALSE(remb.AppliesTo(kRemoteSsrc));
128 } 141 }
129 } // namespace 142
130 } // namespace webrtc 143 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698