Zhi Huang | 95e7dbb | 2018-03-29 00:08:03 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2004 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 "pc/bundlefilter.h" |
| 12 | #include "rtc_base/gunit.h" |
| 13 | |
| 14 | using cricket::StreamParams; |
| 15 | |
| 16 | static const int kPayloadType1 = 0x11; |
| 17 | static const int kPayloadType2 = 0x22; |
| 18 | static const int kPayloadType3 = 0x33; |
| 19 | |
| 20 | // SSRC = 0x1111, Payload type = 0x11 |
| 21 | static const unsigned char kRtpPacketPt1Ssrc1[] = { |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 22 | 0x80, kPayloadType1, 0x00, 0x01, 0x00, 0x00, |
| 23 | 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, |
Zhi Huang | 95e7dbb | 2018-03-29 00:08:03 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | // SSRC = 0x2222, Payload type = 0x22 |
| 27 | static const unsigned char kRtpPacketPt2Ssrc2[] = { |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 28 | 0x80, 0x80 + kPayloadType2, |
| 29 | 0x00, 0x01, |
| 30 | 0x00, 0x00, |
| 31 | 0x00, 0x00, |
| 32 | 0x00, 0x00, |
Zhi Huang | 95e7dbb | 2018-03-29 00:08:03 | [diff] [blame] | 33 | 0x22, 0x22, |
| 34 | }; |
| 35 | |
| 36 | // SSRC = 0x2222, Payload type = 0x33 |
| 37 | static const unsigned char kRtpPacketPt3Ssrc2[] = { |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 38 | 0x80, kPayloadType3, 0x00, 0x01, 0x00, 0x00, |
| 39 | 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, |
Zhi Huang | 95e7dbb | 2018-03-29 00:08:03 | [diff] [blame] | 40 | }; |
| 41 | |
| 42 | // An SCTP packet. |
| 43 | static const unsigned char kSctpPacket[] = { |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 44 | 0x00, 0x01, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, |
| 45 | 0x00, 0x00, 0x03, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, |
Zhi Huang | 95e7dbb | 2018-03-29 00:08:03 | [diff] [blame] | 46 | }; |
| 47 | |
| 48 | TEST(BundleFilterTest, RtpPacketTest) { |
| 49 | cricket::BundleFilter bundle_filter; |
| 50 | bundle_filter.AddPayloadType(kPayloadType1); |
| 51 | EXPECT_TRUE(bundle_filter.DemuxPacket(kRtpPacketPt1Ssrc1, |
| 52 | sizeof(kRtpPacketPt1Ssrc1))); |
| 53 | bundle_filter.AddPayloadType(kPayloadType2); |
| 54 | EXPECT_TRUE(bundle_filter.DemuxPacket(kRtpPacketPt2Ssrc2, |
| 55 | sizeof(kRtpPacketPt2Ssrc2))); |
| 56 | |
| 57 | // Payload type 0x33 is not added. |
| 58 | EXPECT_FALSE(bundle_filter.DemuxPacket(kRtpPacketPt3Ssrc2, |
| 59 | sizeof(kRtpPacketPt3Ssrc2))); |
| 60 | // Size is too small. |
| 61 | EXPECT_FALSE(bundle_filter.DemuxPacket(kRtpPacketPt1Ssrc1, 11)); |
| 62 | |
| 63 | bundle_filter.ClearAllPayloadTypes(); |
| 64 | EXPECT_FALSE(bundle_filter.DemuxPacket(kRtpPacketPt1Ssrc1, |
| 65 | sizeof(kRtpPacketPt1Ssrc1))); |
| 66 | EXPECT_FALSE(bundle_filter.DemuxPacket(kRtpPacketPt2Ssrc2, |
| 67 | sizeof(kRtpPacketPt2Ssrc2))); |
| 68 | } |
| 69 | |
| 70 | TEST(BundleFilterTest, InvalidRtpPacket) { |
| 71 | cricket::BundleFilter bundle_filter; |
| 72 | EXPECT_FALSE(bundle_filter.DemuxPacket(kSctpPacket, sizeof(kSctpPacket))); |
| 73 | } |