blob: 2b1af5c3a398bf58ed887de342885a6f48a87aa0 [file] [log] [blame]
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00001/*
kjellander65c7f672016-02-12 00:05:01 -08002 * Copyright 2004 The WebRTC project authors. All Rights Reserved.
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +00003 *
kjellander65c7f672016-02-12 00:05:01 -08004 * 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.org5ee0f052014-05-05 20:18:08 +00009 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "pc/bundlefilter.h"
12#include "rtc_base/gunit.h"
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +000013
14using cricket::StreamParams;
15
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +000016static const int kPayloadType1 = 0x11;
17static const int kPayloadType2 = 0x22;
18static const int kPayloadType3 = 0x33;
19
20// SSRC = 0x1111, Payload type = 0x11
21static 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
27static 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
33static const unsigned char kRtpPacketPt3Ssrc2[] = {
34 0x80, kPayloadType3, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22,
35 0x22,
36};
37
buildbot@webrtc.org1ef789d2014-06-19 23:54:12 +000038// An SCTP packet.
39static 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.org5ee0f052014-05-05 20:18:08 +000047TEST(BundleFilterTest, RtpPacketTest) {
48 cricket::BundleFilter bundle_filter;
49 bundle_filter.AddPayloadType(kPayloadType1);
pbos482b12e2015-11-16 10:19:58 -080050 EXPECT_TRUE(bundle_filter.DemuxPacket(kRtpPacketPt1Ssrc1,
51 sizeof(kRtpPacketPt1Ssrc1)));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +000052 bundle_filter.AddPayloadType(kPayloadType2);
pbos482b12e2015-11-16 10:19:58 -080053 EXPECT_TRUE(bundle_filter.DemuxPacket(kRtpPacketPt2Ssrc2,
54 sizeof(kRtpPacketPt2Ssrc2)));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +000055
56 // Payload type 0x33 is not added.
pbos482b12e2015-11-16 10:19:58 -080057 EXPECT_FALSE(bundle_filter.DemuxPacket(kRtpPacketPt3Ssrc2,
58 sizeof(kRtpPacketPt3Ssrc2)));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +000059 // Size is too small.
pbos482b12e2015-11-16 10:19:58 -080060 EXPECT_FALSE(bundle_filter.DemuxPacket(kRtpPacketPt1Ssrc1, 11));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +000061
62 bundle_filter.ClearAllPayloadTypes();
pbos482b12e2015-11-16 10:19:58 -080063 EXPECT_FALSE(bundle_filter.DemuxPacket(kRtpPacketPt1Ssrc1,
64 sizeof(kRtpPacketPt1Ssrc1)));
65 EXPECT_FALSE(bundle_filter.DemuxPacket(kRtpPacketPt2Ssrc2,
66 sizeof(kRtpPacketPt2Ssrc2)));
buildbot@webrtc.org5ee0f052014-05-05 20:18:08 +000067}
buildbot@webrtc.org1ef789d2014-06-19 23:54:12 +000068
69TEST(BundleFilterTest, InvalidRtpPacket) {
70 cricket::BundleFilter bundle_filter;
pbos482b12e2015-11-16 10:19:58 -080071 EXPECT_FALSE(bundle_filter.DemuxPacket(kSctpPacket, sizeof(kSctpPacket)));
buildbot@webrtc.org1ef789d2014-06-19 23:54:12 +000072}