• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "modules/rtp_rtcp/source/rtcp_packet/tmmbr.h"
12 
13 #include "test/gmock.h"
14 #include "test/gtest.h"
15 #include "test/rtcp_packet_parser.h"
16 
17 using ::testing::ElementsAreArray;
18 using ::testing::make_tuple;
19 using webrtc::rtcp::TmmbItem;
20 using webrtc::rtcp::Tmmbr;
21 
22 namespace webrtc {
23 namespace {
24 const uint32_t kSenderSsrc = 0x12345678;
25 const uint32_t kRemoteSsrc = 0x23456789;
26 const uint32_t kBitrateBps = 312000;
27 const uint16_t kOverhead = 0x1fe;
28 const uint8_t kPacket[] = {0x83, 205,  0x00, 0x04, 0x12, 0x34, 0x56,
29                            0x78, 0x00, 0x00, 0x00, 0x00, 0x23, 0x45,
30                            0x67, 0x89, 0x0a, 0x61, 0x61, 0xfe};
31 }  // namespace
32 
TEST(RtcpPacketTmmbrTest,Create)33 TEST(RtcpPacketTmmbrTest, Create) {
34   Tmmbr tmmbr;
35   tmmbr.SetSenderSsrc(kSenderSsrc);
36   tmmbr.AddTmmbr(TmmbItem(kRemoteSsrc, kBitrateBps, kOverhead));
37 
38   rtc::Buffer packet = tmmbr.Build();
39 
40   EXPECT_THAT(make_tuple(packet.data(), packet.size()),
41               ElementsAreArray(kPacket));
42 }
43 
TEST(RtcpPacketTmmbrTest,Parse)44 TEST(RtcpPacketTmmbrTest, Parse) {
45   Tmmbr tmmbr;
46   EXPECT_TRUE(test::ParseSinglePacket(kPacket, &tmmbr));
47   const Tmmbr& parsed = tmmbr;
48 
49   EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc());
50   ASSERT_EQ(1u, parsed.requests().size());
51   EXPECT_EQ(kRemoteSsrc, parsed.requests().front().ssrc());
52   EXPECT_EQ(kBitrateBps, parsed.requests().front().bitrate_bps());
53   EXPECT_EQ(kOverhead, parsed.requests().front().packet_overhead());
54 }
55 
TEST(RtcpPacketTmmbrTest,CreateAndParseWithTwoEntries)56 TEST(RtcpPacketTmmbrTest, CreateAndParseWithTwoEntries) {
57   Tmmbr tmmbr;
58   tmmbr.SetSenderSsrc(kSenderSsrc);
59   tmmbr.AddTmmbr(TmmbItem(kRemoteSsrc, kBitrateBps, kOverhead));
60   tmmbr.AddTmmbr(TmmbItem(kRemoteSsrc + 1, 4 * kBitrateBps, kOverhead + 1));
61 
62   rtc::Buffer packet = tmmbr.Build();
63 
64   Tmmbr parsed;
65   EXPECT_TRUE(test::ParseSinglePacket(packet, &parsed));
66 
67   EXPECT_EQ(kSenderSsrc, parsed.sender_ssrc());
68   EXPECT_EQ(2u, parsed.requests().size());
69   EXPECT_EQ(kRemoteSsrc, parsed.requests()[0].ssrc());
70   EXPECT_EQ(kRemoteSsrc + 1, parsed.requests()[1].ssrc());
71 }
72 
TEST(RtcpPacketTmmbrTest,ParseFailsWithoutItems)73 TEST(RtcpPacketTmmbrTest, ParseFailsWithoutItems) {
74   const uint8_t kZeroItemsPacket[] = {0x83, 205,  0x00, 0x02, 0x12, 0x34,
75                                       0x56, 0x78, 0x00, 0x00, 0x00, 0x00};
76 
77   Tmmbr tmmbr;
78   EXPECT_FALSE(test::ParseSinglePacket(kZeroItemsPacket, &tmmbr));
79 }
80 
TEST(RtcpPacketTmmbrTest,ParseFailsOnUnAlignedPacket)81 TEST(RtcpPacketTmmbrTest, ParseFailsOnUnAlignedPacket) {
82   const uint8_t kUnalignedPacket[] = {
83       0x83, 205,  0x00, 0x05, 0x12, 0x34, 0x56, 0x78, 0x00, 0x00, 0x00, 0x00,
84       0x23, 0x45, 0x67, 0x89, 0x0a, 0x61, 0x61, 0xfe, 0x34, 0x56, 0x78, 0x9a};
85 
86   Tmmbr tmmbr;
87   EXPECT_FALSE(test::ParseSinglePacket(kUnalignedPacket, &tmmbr));
88 }
89 }  // namespace webrtc
90