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

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

Issue 1544983002: [rtp_rtcp] rtcp::SenderReport moved into own file and got Parse function (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Added SenderReport::ClearReportBlocks to make SenderReport reusable 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
OLDNEW
(Empty)
1 /*
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
11 #include "webrtc/modules/rtp_rtcp/source/rtcp_packet/remb.h"
12
åsapersson 2016/01/13 14:11:32 Should this file be part of this CL?
danilchap 2016/01/13 15:54:44 oops, removed.
13 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 using ::testing::ElementsAreArray;
17 using ::testing::Eq;
18 using ::testing::make_tuple;
19
20 using webrtc::rtcp::RawPacket;
21 using webrtc::rtcp::Remb;
22
23 namespace webrtc {
24 namespace {
25
26 const uint32_t kSenderSsrc = 0x12345678;
27
28 const uint32_t kRemoteSsrc[] = {0x23456789, 0x2345678a, 0x2345678b};
29 const uint32_t kBitrate = 0x3fb93 * 2; // 522022;
30
31 const uint8_t kPacket[] = {0x8f, 206, 0x00, 0x07, 0x12, 0x34, 0x56, 0x78,
32 0x00, 0x00, 0x00, 0x00, 'R', 'E', 'M', 'B',
33 0x03, 0x07, 0xfb, 0x93, 0x23, 0x45, 0x67, 0x89,
34 0x23, 0x45, 0x67, 0x8a, 0x23, 0x45, 0x67, 0x8b};
35 const size_t kPacketLength = sizeof(kPacket);
36
37 bool ParseRemb(const uint8_t* buffer, size_t length, Remb* remb) {
38 using RTCPUtility::RtcpCommonHeader;
39 using RTCPUtility::RtcpParseCommonHeader;
40 RtcpCommonHeader header;
41 EXPECT_TRUE(RtcpParseCommonHeader(buffer, length, &header));
42 EXPECT_THAT(header.BlockSize(), Eq(length));
43 return remb->Parse(header, buffer + RtcpCommonHeader::kHeaderSizeBytes);
44 }
45
46 TEST(RtcpPacketRembTest, Create) {
47 Remb remb;
48 remb.From(kSenderSsrc);
49 remb.AppliesTo(kRemoteSsrc[0]);
50 remb.AppliesTo(kRemoteSsrc[1]);
51 remb.AppliesTo(kRemoteSsrc[2]);
52 remb.WithBitrateBps(kBitrate);
53
54 rtc::scoped_ptr<RawPacket> packet = remb.Build();
55
56 EXPECT_THAT(make_tuple(packet->Buffer(), packet->Length()),
57 ElementsAreArray(kPacket));
58 }
59
60 TEST(RtcpPacketRembTest, Parse) {
61 Remb remb;
62 EXPECT_TRUE(ParseRemb(kPacket, kPacketLength, &remb));
63 const Remb& parsed = remb;
64
65 EXPECT_THAT(parsed.sender_ssrc(), Eq(kSenderSsrc));
66 EXPECT_THAT(parsed.bitrate_bps(), Eq(kBitrate));
67 EXPECT_THAT(parsed.ssrcs(), ElementsAreArray(kRemoteSsrc));
68 }
69
70 TEST(RtcpPacketRembTest, CreateAndParseEmpty) {
71 const uint32_t kBitrate = 500000;
72 Remb remb;
73 remb.From(kSenderSsrc);
74 remb.WithBitrateBps(kBitrate);
75 rtc::scoped_ptr<RawPacket> packet = remb.Build();
76
77 Remb parsed;
78 EXPECT_TRUE(ParseRemb(packet->Buffer(), packet->Length(), &parsed));
79 EXPECT_THAT(parsed.sender_ssrc(), Eq(kSenderSsrc));
80 EXPECT_THAT(parsed.bitrate_bps(), Eq(kBitrate));
81 }
82
83 TEST(RtcpPacketRembTest, ParseFailsOnNonRembTooSmall) {
84 uint8_t packet[kPacketLength];
85 memcpy(packet, kPacket, kPacketLength);
86 packet[3] = 3; // Make it too small.
87
88 Remb remb;
89 EXPECT_FALSE(ParseRemb(packet, (1 + 3) * 4, &remb));
90 }
91
92 TEST(RtcpPacketRembTest, ParseFailsOnNonRembSignature) {
93 uint8_t packet[kPacketLength];
94 memcpy(packet, kPacket, kPacketLength);
95 packet[12] = 'N'; // Swap 'R' -> 'N' in the 'REMB' signature.
96
97 Remb remb;
98 EXPECT_FALSE(ParseRemb(packet, kPacketLength, &remb));
99 }
100
101 TEST(RtcpPacketRembTest, ParseFailsWhenSsrcCountMismatchLength) {
102 uint8_t packet[kPacketLength];
103 memcpy(packet, kPacket, kPacketLength);
104 packet[16]++; // Swap 3 -> 4 in the ssrcs count.
105
106 Remb remb;
107 EXPECT_FALSE(ParseRemb(packet, kPacketLength, &remb));
108 }
109
110 TEST(RtcpPacketRembTest, TooManySsrcs) {
111 const size_t kMax = 0xff;
112 Remb remb;
113 for (size_t i = 1; i <= kMax; ++i)
114 EXPECT_TRUE(remb.AppliesTo(kRemoteSsrc[0] + i));
115 EXPECT_FALSE(remb.AppliesTo(kRemoteSsrc[0]));
116 }
117
118 TEST(RtcpPacketRembTest, TooManyForBatchAssign) {
119 const size_t kMax = 0xff;
120 Remb remb;
121
122 std::vector<uint32_t> AlmostAll(kMax - 1, kRemoteSsrc[0]);
123 EXPECT_TRUE(remb.AppliesToMany(AlmostAll));
124 // Should be no place for 2 more.
125 std::vector<uint32_t> TwoMoreSsrcs(2, kRemoteSsrc[1]);
126 EXPECT_FALSE(remb.AppliesToMany(TwoMoreSsrcs));
127 // But enough place for 1 more.
128 EXPECT_TRUE(remb.AppliesTo(kRemoteSsrc[2]));
129 // But not for another one.
130 EXPECT_FALSE(remb.AppliesTo(kRemoteSsrc[2] + 1));
131 }
132
133 } // namespace
134 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698