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

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

Issue 1552773002: [rtp_rtcp] rtcp::Remb cleaned and got Parse function (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Created 4 years, 11 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"
16 15
16 using testing::ElementsAreArray;
17 using testing::IsEmpty;
18 using testing::make_tuple;
17 using webrtc::rtcp::RawPacket; 19 using webrtc::rtcp::RawPacket;
18 using webrtc::rtcp::Remb; 20 using webrtc::rtcp::Remb;
19 using webrtc::test::RtcpPacketParser; 21 using webrtc::RTCPUtility::RtcpCommonHeader;
22 using webrtc::RTCPUtility::RtcpParseCommonHeader;
20 23
21 namespace webrtc { 24 namespace webrtc {
25 namespace {
22 26
23 const uint32_t kSenderSsrc = 0x12345678; 27 const uint32_t kSenderSsrc = 0x12345678;
24 const uint32_t kRemoteSsrc = 0x23456789; 28 const uint32_t kRemoteSsrcs[] = {0x23456789, 0x2345678a, 0x2345678b};
29 const uint32_t kBitrateBps = 0x3fb93 * 2; // 522022;
30 const uint8_t kPacket[] = {0x8f, 206, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78,
31 0x00, 0x00, 0x00, 0x00, 'R', 'E', 'M', 'B',
32 0x03, 0x07, 0xfb, 0x93, 0x23, 0x45, 0x67, 0x89,
33 0x23, 0x45, 0x67, 0x8a, 0x23, 0x45, 0x67, 0x8b};
34 const size_t kPacketLength = sizeof(kPacket);
25 35
26 TEST(RtcpPacketRembTest, Remb) { 36 bool ParseRemb(const uint8_t* buffer, size_t length, Remb* remb) {
37 RtcpCommonHeader header;
38 EXPECT_TRUE(RtcpParseCommonHeader(buffer, length, &header));
39 EXPECT_EQ(length, header.BlockSize());
40 return remb->Parse(header, buffer + RtcpCommonHeader::kHeaderSizeBytes);
41 }
42
43 TEST(RtcpPacketRembTest, Create) {
27 Remb remb; 44 Remb remb;
28 remb.From(kSenderSsrc); 45 remb.From(kSenderSsrc);
29 remb.AppliesTo(kRemoteSsrc); 46 remb.AppliesTo(kRemoteSsrcs[0]);
30 remb.AppliesTo(kRemoteSsrc + 1); 47 remb.AppliesTo(kRemoteSsrcs[1]);
31 remb.AppliesTo(kRemoteSsrc + 2); 48 remb.AppliesTo(kRemoteSsrcs[2]);
32 remb.WithBitrateBps(261011); 49 remb.WithBitrateBps(kBitrateBps);
33 50
34 rtc::scoped_ptr<RawPacket> packet(remb.Build()); 51 rtc::scoped_ptr<RawPacket> packet(remb.Build());
35 RtcpPacketParser parser; 52
36 parser.Parse(packet->Buffer(), packet->Length()); 53 EXPECT_THAT(make_tuple(packet->Buffer(), packet->Length()),
37 EXPECT_EQ(1, parser.psfb_app()->num_packets()); 54 ElementsAreArray(kPacket));
38 EXPECT_EQ(kSenderSsrc, parser.psfb_app()->Ssrc());
39 EXPECT_EQ(1, parser.remb_item()->num_packets());
40 EXPECT_EQ(261011, parser.remb_item()->last_bitrate_bps());
41 std::vector<uint32_t> ssrcs = parser.remb_item()->last_ssrc_list();
42 EXPECT_EQ(kRemoteSsrc, ssrcs[0]);
43 EXPECT_EQ(kRemoteSsrc + 1, ssrcs[1]);
44 EXPECT_EQ(kRemoteSsrc + 2, ssrcs[2]);
45 } 55 }
56
57 TEST(RtcpPacketRembTest, Parse) {
58 Remb remb;
59 EXPECT_TRUE(ParseRemb(kPacket, kPacketLength, &remb));
60 const Remb& parsed = remb;
61
62 EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc());
63 EXPECT_EQ(kBitrateBps, parsed.bitrate_bps());
64 EXPECT_THAT(parsed.ssrcs(), ElementsAreArray(kRemoteSsrcs));
65 }
66
67 TEST(RtcpPacketRembTest, CreateAndParseWithoutSsrcs) {
68 Remb remb;
69 remb.From(kSenderSsrc);
70 remb.WithBitrateBps(kBitrateBps);
71 rtc::scoped_ptr<RawPacket> packet(remb.Build());
72
73 Remb parsed;
74 EXPECT_TRUE(ParseRemb(packet->Buffer(), packet->Length(), &parsed));
75 EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc());
76 EXPECT_EQ(kBitrateBps, parsed.bitrate_bps());
77 EXPECT_THAT(parsed.ssrcs(), IsEmpty());
78 }
79
80 TEST(RtcpPacketRembTest, ParseFailsOnTooSmallPacketToBeRemb) {
81 uint8_t packet[kPacketLength];
82 memcpy(packet, kPacket, kPacketLength);
83 packet[3] = 3; // Make it too small.
84
85 Remb remb;
86 EXPECT_FALSE(ParseRemb(packet, (1 + 3) * 4, &remb));
87 }
88
89 TEST(RtcpPacketRembTest, ParseFailsWhenUniqueIdentifierIsNotRemb) {
90 uint8_t packet[kPacketLength];
91 memcpy(packet, kPacket, kPacketLength);
92 packet[12] = 'N'; // Swap 'R' -> 'N' in the 'REMB' unique identifier.
93
94 Remb remb;
95 EXPECT_FALSE(ParseRemb(packet, kPacketLength, &remb));
96 }
97
98 TEST(RtcpPacketRembTest, ParseFailsWhenSsrcCountMismatchLength) {
99 uint8_t packet[kPacketLength];
100 memcpy(packet, kPacket, kPacketLength);
101 packet[16]++; // Swap 3 -> 4 in the ssrcs count.
102
103 Remb remb;
104 EXPECT_FALSE(ParseRemb(packet, kPacketLength, &remb));
105 }
106
107 TEST(RtcpPacketRembTest, TooManySsrcs) {
108 const size_t kMax = 0xff;
109 Remb remb;
110 for (size_t i = 1; i <= kMax; ++i)
111 EXPECT_TRUE(remb.AppliesTo(kRemoteSsrcs[0] + i));
112 EXPECT_FALSE(remb.AppliesTo(kRemoteSsrcs[0]));
113 }
114
115 TEST(RtcpPacketRembTest, TooManySsrcsForBatchAssign) {
116 const uint32_t kRemoteSsrc = kRemoteSsrcs[0];
117 const size_t kMax = 0xff;
118 const std::vector<uint32_t> kAllButOneSsrc(kMax - 1, kRemoteSsrc);
119 const std::vector<uint32_t> kTwoSsrcs(2, kRemoteSsrc);
120
121 Remb remb;
122 EXPECT_TRUE(remb.AppliesToMany(kAllButOneSsrc));
123 // Should be no place for 2 more.
124 EXPECT_FALSE(remb.AppliesToMany(kTwoSsrcs));
125 // But enough place for 1 more.
126 EXPECT_TRUE(remb.AppliesTo(kRemoteSsrc));
127 // But not for another one.
128 EXPECT_FALSE(remb.AppliesTo(kRemoteSsrc));
129 }
130 } // namespace
46 } // namespace webrtc 131 } // 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