buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 1 | /* |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 2 | * Copyright 2004 The WebRTC project authors. All Rights Reserved. |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 3 | * |
kjellander | 65c7f67 | 2016-02-12 00:05:01 -0800 | [diff] [blame] | 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. |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "pc/bundlefilter.h" |
| 12 | #include "rtc_base/gunit.h" |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 13 | |
| 14 | using cricket::StreamParams; |
| 15 | |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 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[] = { |
| 22 | 0x80, kPayloadType1, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, |
| 23 | 0x11, |
| 24 | }; |
| 25 | |
| 26 | // SSRC = 0x2222, Payload type = 0x22 |
| 27 | static const unsigned char kRtpPacketPt2Ssrc2[] = { |
| 28 | 0x80, 0x80 + kPayloadType2, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 29 | 0x22, 0x22, |
| 30 | }; |
| 31 | |
| 32 | // SSRC = 0x2222, Payload type = 0x33 |
| 33 | static const unsigned char kRtpPacketPt3Ssrc2[] = { |
| 34 | 0x80, kPayloadType3, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, |
| 35 | 0x22, |
| 36 | }; |
| 37 | |
buildbot@webrtc.org | 1ef789d | 2014-06-19 23:54:12 +0000 | [diff] [blame] | 38 | // An SCTP packet. |
| 39 | static const unsigned char kSctpPacket[] = { |
| 40 | 0x00, 0x01, 0x00, 0x01, |
| 41 | 0xff, 0xff, 0xff, 0xff, |
| 42 | 0x00, 0x00, 0x00, 0x00, |
| 43 | 0x03, 0x00, 0x00, 0x04, |
| 44 | 0x00, 0x00, 0x00, 0x00, |
| 45 | }; |
| 46 | |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 47 | TEST(BundleFilterTest, RtpPacketTest) { |
| 48 | cricket::BundleFilter bundle_filter; |
| 49 | bundle_filter.AddPayloadType(kPayloadType1); |
pbos | 482b12e | 2015-11-16 10:19:58 -0800 | [diff] [blame] | 50 | EXPECT_TRUE(bundle_filter.DemuxPacket(kRtpPacketPt1Ssrc1, |
| 51 | sizeof(kRtpPacketPt1Ssrc1))); |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 52 | bundle_filter.AddPayloadType(kPayloadType2); |
pbos | 482b12e | 2015-11-16 10:19:58 -0800 | [diff] [blame] | 53 | EXPECT_TRUE(bundle_filter.DemuxPacket(kRtpPacketPt2Ssrc2, |
| 54 | sizeof(kRtpPacketPt2Ssrc2))); |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 55 | |
| 56 | // Payload type 0x33 is not added. |
pbos | 482b12e | 2015-11-16 10:19:58 -0800 | [diff] [blame] | 57 | EXPECT_FALSE(bundle_filter.DemuxPacket(kRtpPacketPt3Ssrc2, |
| 58 | sizeof(kRtpPacketPt3Ssrc2))); |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 59 | // Size is too small. |
pbos | 482b12e | 2015-11-16 10:19:58 -0800 | [diff] [blame] | 60 | EXPECT_FALSE(bundle_filter.DemuxPacket(kRtpPacketPt1Ssrc1, 11)); |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 61 | |
| 62 | bundle_filter.ClearAllPayloadTypes(); |
pbos | 482b12e | 2015-11-16 10:19:58 -0800 | [diff] [blame] | 63 | EXPECT_FALSE(bundle_filter.DemuxPacket(kRtpPacketPt1Ssrc1, |
| 64 | sizeof(kRtpPacketPt1Ssrc1))); |
| 65 | EXPECT_FALSE(bundle_filter.DemuxPacket(kRtpPacketPt2Ssrc2, |
| 66 | sizeof(kRtpPacketPt2Ssrc2))); |
buildbot@webrtc.org | 5ee0f05 | 2014-05-05 20:18:08 +0000 | [diff] [blame] | 67 | } |
buildbot@webrtc.org | 1ef789d | 2014-06-19 23:54:12 +0000 | [diff] [blame] | 68 | |
| 69 | TEST(BundleFilterTest, InvalidRtpPacket) { |
| 70 | cricket::BundleFilter bundle_filter; |
pbos | 482b12e | 2015-11-16 10:19:58 -0800 | [diff] [blame] | 71 | EXPECT_FALSE(bundle_filter.DemuxPacket(kSctpPacket, sizeof(kSctpPacket))); |
buildbot@webrtc.org | 1ef789d | 2014-06-19 23:54:12 +0000 | [diff] [blame] | 72 | } |