blob: e7cadbfbac613c6429a8be277e21f375cfc4bd71 [file] [log] [blame]
Zhi Huang95e7dbb2018-03-29 00:08:031/*
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
14using cricket::StreamParams;
15
16static 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[] = {
Yves Gerey665174f2018-06-19 13:03:0522 0x80, kPayloadType1, 0x00, 0x01, 0x00, 0x00,
23 0x00, 0x00, 0x00, 0x00, 0x11, 0x11,
Zhi Huang95e7dbb2018-03-29 00:08:0324};
25
26// SSRC = 0x2222, Payload type = 0x22
27static const unsigned char kRtpPacketPt2Ssrc2[] = {
Yves Gerey665174f2018-06-19 13:03:0528 0x80, 0x80 + kPayloadType2,
29 0x00, 0x01,
30 0x00, 0x00,
31 0x00, 0x00,
32 0x00, 0x00,
Zhi Huang95e7dbb2018-03-29 00:08:0333 0x22, 0x22,
34};
35
36// SSRC = 0x2222, Payload type = 0x33
37static const unsigned char kRtpPacketPt3Ssrc2[] = {
Yves Gerey665174f2018-06-19 13:03:0538 0x80, kPayloadType3, 0x00, 0x01, 0x00, 0x00,
39 0x00, 0x00, 0x00, 0x00, 0x22, 0x22,
Zhi Huang95e7dbb2018-03-29 00:08:0340};
41
42// An SCTP packet.
43static const unsigned char kSctpPacket[] = {
Yves Gerey665174f2018-06-19 13:03:0544 0x00, 0x01, 0x00, 0x01, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00,
45 0x00, 0x00, 0x03, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00,
Zhi Huang95e7dbb2018-03-29 00:08:0346};
47
48TEST(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
70TEST(BundleFilterTest, InvalidRtpPacket) {
71 cricket::BundleFilter bundle_filter;
72 EXPECT_FALSE(bundle_filter.DemuxPacket(kSctpPacket, sizeof(kSctpPacket)));
73}