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/tmmbn.h" 12 13 #include "testing/gtest/include/gtest/gtest.h" 14 15 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" 16 #include "webrtc/test/rtcp_packet_parser.h" 17 18 using webrtc::rtcp::RawPacket; 19 using webrtc::rtcp::Tmmbn; 20 using webrtc::test::RtcpPacketParser; 21 22 namespace webrtc { 23 const uint32_t kSenderSsrc = 0x12345678; 24 const uint32_t kRemoteSsrc = 0x23456789; 25 26 TEST(RtcpPacketTest, TmmbnWithNoItem) { 27 Tmmbn tmmbn; 28 tmmbn.From(kSenderSsrc); 29 30 rtc::scoped_ptr<RawPacket> packet(tmmbn.Build()); 31 RtcpPacketParser parser; 32 parser.Parse(packet->Buffer(), packet->Length()); 33 EXPECT_EQ(1, parser.tmmbn()->num_packets()); 34 EXPECT_EQ(kSenderSsrc, parser.tmmbn()->Ssrc()); 35 EXPECT_EQ(0, parser.tmmbn_items()->num_packets()); 36 } 37 38 TEST(RtcpPacketTest, TmmbnWithOneItem) { 39 Tmmbn tmmbn; 40 tmmbn.From(kSenderSsrc); 41 EXPECT_TRUE(tmmbn.WithTmmbr(kRemoteSsrc, 312, 60)); 42 43 rtc::scoped_ptr<RawPacket> packet(tmmbn.Build()); 44 RtcpPacketParser parser; 45 parser.Parse(packet->Buffer(), packet->Length()); 46 EXPECT_EQ(1, parser.tmmbn()->num_packets()); 47 EXPECT_EQ(kSenderSsrc, parser.tmmbn()->Ssrc()); 48 EXPECT_EQ(1, parser.tmmbn_items()->num_packets()); 49 EXPECT_EQ(kRemoteSsrc, parser.tmmbn_items()->Ssrc(0)); 50 EXPECT_EQ(312U, parser.tmmbn_items()->BitrateKbps(0)); 51 EXPECT_EQ(60U, parser.tmmbn_items()->Overhead(0)); 52 } 53 54 TEST(RtcpPacketTest, TmmbnWithTwoItems) { 55 Tmmbn tmmbn; 56 tmmbn.From(kSenderSsrc); 57 EXPECT_TRUE(tmmbn.WithTmmbr(kRemoteSsrc, 312, 60)); 58 EXPECT_TRUE(tmmbn.WithTmmbr(kRemoteSsrc + 1, 1288, 40)); 59 60 rtc::scoped_ptr<RawPacket> packet(tmmbn.Build()); 61 RtcpPacketParser parser; 62 parser.Parse(packet->Buffer(), packet->Length()); 63 EXPECT_EQ(1, parser.tmmbn()->num_packets()); 64 EXPECT_EQ(kSenderSsrc, parser.tmmbn()->Ssrc()); 65 EXPECT_EQ(2, parser.tmmbn_items()->num_packets()); 66 EXPECT_EQ(kRemoteSsrc, parser.tmmbn_items()->Ssrc(0)); 67 EXPECT_EQ(312U, parser.tmmbn_items()->BitrateKbps(0)); 68 EXPECT_EQ(60U, parser.tmmbn_items()->Overhead(0)); 69 EXPECT_EQ(kRemoteSsrc + 1, parser.tmmbn_items()->Ssrc(1)); 70 EXPECT_EQ(1288U, parser.tmmbn_items()->BitrateKbps(1)); 71 EXPECT_EQ(40U, parser.tmmbn_items()->Overhead(1)); 72 } 73 74 TEST(RtcpPacketTest, TmmbnWithTooManyItems) { 75 Tmmbn tmmbn; 76 tmmbn.From(kSenderSsrc); 77 const int kMaxTmmbrItems = 50; 78 for (int i = 0; i < kMaxTmmbrItems; ++i) 79 EXPECT_TRUE(tmmbn.WithTmmbr(kRemoteSsrc + i, 312, 60)); 80 81 EXPECT_FALSE(tmmbn.WithTmmbr(kRemoteSsrc + kMaxTmmbrItems, 312, 60)); 82 } 83 84 } // namespace webrtc 85