~ubuntu-branches/debian/experimental/kopete/experimental

« back to all changes in this revision

Viewing changes to protocols/jabber/googletalk/libjingle/talk/session/phone/ssrcmuxfilter_unittest.cc

  • Committer: Package Import Robot
  • Author(s): Maximiliano Curia
  • Date: 2015-02-24 11:32:57 UTC
  • mfrom: (1.1.41 vivid)
  • Revision ID: package-import@ubuntu.com-20150224113257-gnupg4v7lzz18ij0
Tags: 4:14.12.2-1
* New upstream release (14.12.2).
* Bump Standards-Version to 3.9.6, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * libjingle
3
 
 * Copyright 2004--2005, Google Inc.
4
 
 *
5
 
 * Redistribution and use in source and binary forms, with or without
6
 
 * modification, are permitted provided that the following conditions are met:
7
 
 *
8
 
 *  1. Redistributions of source code must retain the above copyright notice,
9
 
 *     this list of conditions and the following disclaimer.
10
 
 *  2. Redistributions in binary form must reproduce the above copyright notice,
11
 
 *     this list of conditions and the following disclaimer in the documentation
12
 
 *     and/or other materials provided with the distribution.
13
 
 *  3. The name of the author may not be used to endorse or promote products
14
 
 *     derived from this software without specific prior written permission.
15
 
 *
16
 
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17
 
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18
 
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19
 
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20
 
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21
 
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22
 
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23
 
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24
 
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25
 
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 
 */
27
 
 
28
 
 
29
 
#include "talk/base/gunit.h"
30
 
#include "talk/session/phone/ssrcmuxfilter.h"
31
 
 
32
 
static const int kSsrc1 = 0x1111;
33
 
static const int kSsrc2 = 0x2222;
34
 
static const int kSsrc3 = 0x3333;
35
 
 
36
 
using cricket::StreamParams;
37
 
 
38
 
// SSRC = 0x1111
39
 
static const unsigned char kRtpPacketSsrc1[] = {
40
 
    0x80, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11,
41
 
};
42
 
 
43
 
// SSRC = 0x2222
44
 
static const unsigned char kRtpPacketSsrc2[] = {
45
 
    0x80, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22,
46
 
};
47
 
 
48
 
// SSRC = 0
49
 
static const unsigned char kRtpPacketInvalidSsrc[] = {
50
 
    0x80, 0x80, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
51
 
};
52
 
 
53
 
// invalid size
54
 
static const unsigned char kRtpPacketTooSmall[] = {
55
 
    0x80, 0x80, 0x00, 0x00,
56
 
};
57
 
 
58
 
// PT = 200 = SR, len = 28, SSRC of sender = 0x0001
59
 
// NTP TS = 0, RTP TS = 0, packet count = 0
60
 
static const unsigned char kRtcpPacketSrSsrc01[] = {
61
 
    0x80, 0xC8, 0x00, 0x1B, 0x00, 0x00, 0x00, 0x01,
62
 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
63
 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
64
 
    0x00, 0x00, 0x00, 0x00,
65
 
};
66
 
 
67
 
// PT = 200 = SR, len = 28, SSRC of sender = 0x2222
68
 
// NTP TS = 0, RTP TS = 0, packet count = 0
69
 
static const unsigned char kRtcpPacketSrSsrc2[] = {
70
 
    0x80, 0xC8, 0x00, 0x1B, 0x00, 0x00, 0x22, 0x22,
71
 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
72
 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
73
 
    0x00, 0x00, 0x00, 0x00,
74
 
};
75
 
 
76
 
// First packet - SR = PT = 200, len = 0, SSRC of sender = 0x1111
77
 
// NTP TS = 0, RTP TS = 0, packet count = 0
78
 
// second packet - SDES = PT =  202, count = 0, SSRC = 0x1111, cname len = 0
79
 
static const unsigned char kRtcpPacketCompoundSrSdesSsrc1[] = {
80
 
    0x80, 0xC8, 0x00, 0x01, 0x00, 0x00, 0x11, 0x11,
81
 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
82
 
    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
83
 
    0x00, 0x00, 0x00, 0x00,
84
 
    0x81, 0xCA, 0x00, 0x00, 0x00, 0x00, 0x11, 0x11, 0x01, 0x00,
85
 
};
86
 
 
87
 
// SDES = PT =  202, count = 0, SSRC = 0x2222, cname len = 0
88
 
static const unsigned char kRtcpPacketSdesSsrc2[] = {
89
 
    0x81, 0xCA, 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x01, 0x00,
90
 
};
91
 
 
92
 
// Packet has only mandatory fixed RTCP header
93
 
static const unsigned char kRtcpPacketFixedHeaderOnly[] = {
94
 
    0x80, 0xC8, 0x00, 0x00,
95
 
};
96
 
 
97
 
// Small packet for SSRC demux.
98
 
static const unsigned char kRtcpPacketTooSmall[] = {
99
 
    0x80, 0xC8, 0x00, 0x00, 0x00, 0x00,
100
 
};
101
 
 
102
 
// PT = 206, FMT = 1, Sender SSRC  = 0x1111, Media SSRC = 0x1111
103
 
// No FCI information is needed for PLI.
104
 
static const unsigned char kRtcpPacketNonCompoundRtcpPliFeedback[] = {
105
 
    0x81, 0xCE, 0x00, 0x0C, 0x00, 0x00, 0x11, 0x11, 0x00, 0x00, 0x11, 0x11,
106
 
};
107
 
 
108
 
TEST(SsrcMuxFilterTest, AddRemoveStreamTest) {
109
 
  cricket::SsrcMuxFilter ssrc_filter;
110
 
  EXPECT_FALSE(ssrc_filter.IsActive());
111
 
  EXPECT_TRUE(ssrc_filter.AddStream(StreamParams::CreateLegacy(kSsrc1)));
112
 
  StreamParams stream2;
113
 
  stream2.ssrcs.push_back(kSsrc2);
114
 
  stream2.ssrcs.push_back(kSsrc3);
115
 
  EXPECT_TRUE(ssrc_filter.AddStream(stream2));
116
 
 
117
 
  EXPECT_TRUE(ssrc_filter.IsActive());
118
 
  EXPECT_TRUE(ssrc_filter.FindStream(kSsrc1));
119
 
  EXPECT_TRUE(ssrc_filter.FindStream(kSsrc2));
120
 
  EXPECT_TRUE(ssrc_filter.FindStream(kSsrc3));
121
 
  EXPECT_TRUE(ssrc_filter.RemoveStream(kSsrc1));
122
 
  EXPECT_FALSE(ssrc_filter.FindStream(kSsrc1));
123
 
  EXPECT_TRUE(ssrc_filter.RemoveStream(kSsrc3));
124
 
  EXPECT_FALSE(ssrc_filter.RemoveStream(kSsrc2));  // Already removed.
125
 
  EXPECT_FALSE(ssrc_filter.IsActive());
126
 
}
127
 
 
128
 
TEST(SsrcMuxFilterTest, RtpPacketTest) {
129
 
  cricket::SsrcMuxFilter ssrc_filter;
130
 
  EXPECT_TRUE(ssrc_filter.AddStream(StreamParams::CreateLegacy(kSsrc1)));
131
 
  EXPECT_TRUE(ssrc_filter.DemuxPacket(
132
 
      reinterpret_cast<const char*>(kRtpPacketSsrc1),
133
 
      sizeof(kRtpPacketSsrc1), false));
134
 
  EXPECT_TRUE(ssrc_filter.AddStream(StreamParams::CreateLegacy(kSsrc2)));
135
 
  EXPECT_TRUE(ssrc_filter.DemuxPacket(
136
 
      reinterpret_cast<const char*>(kRtpPacketSsrc2),
137
 
      sizeof(kRtpPacketSsrc2), false));
138
 
  EXPECT_TRUE(ssrc_filter.RemoveStream(kSsrc2));
139
 
  EXPECT_FALSE(ssrc_filter.DemuxPacket(
140
 
      reinterpret_cast<const char*>(kRtpPacketSsrc2),
141
 
      sizeof(kRtpPacketSsrc2), false));
142
 
  EXPECT_FALSE(ssrc_filter.DemuxPacket(
143
 
      reinterpret_cast<const char*>(kRtpPacketInvalidSsrc),
144
 
      sizeof(kRtpPacketInvalidSsrc), false));
145
 
  EXPECT_FALSE(ssrc_filter.DemuxPacket(
146
 
      reinterpret_cast<const char*>(kRtpPacketTooSmall),
147
 
      sizeof(kRtpPacketTooSmall), false));
148
 
}
149
 
 
150
 
TEST(SsrcMuxFilterTest, RtcpPacketTest) {
151
 
  cricket::SsrcMuxFilter ssrc_filter;
152
 
  EXPECT_TRUE(ssrc_filter.AddStream(StreamParams::CreateLegacy(kSsrc1)));
153
 
  EXPECT_TRUE(ssrc_filter.DemuxPacket(
154
 
      reinterpret_cast<const char*>(kRtcpPacketCompoundSrSdesSsrc1),
155
 
      sizeof(kRtcpPacketCompoundSrSdesSsrc1), true));
156
 
  EXPECT_TRUE(ssrc_filter.AddStream(StreamParams::CreateLegacy(kSsrc2)));
157
 
  EXPECT_TRUE(ssrc_filter.DemuxPacket(
158
 
      reinterpret_cast<const char*>(kRtcpPacketSrSsrc2),
159
 
      sizeof(kRtcpPacketSrSsrc2), true));
160
 
  EXPECT_TRUE(ssrc_filter.DemuxPacket(
161
 
      reinterpret_cast<const char*>(kRtcpPacketSdesSsrc2),
162
 
      sizeof(kRtcpPacketSdesSsrc2), true));
163
 
  EXPECT_TRUE(ssrc_filter.RemoveStream(kSsrc2));
164
 
  // RTCP Packets other than SR and RR are demuxed regardless of SSRC.
165
 
  EXPECT_TRUE(ssrc_filter.DemuxPacket(
166
 
      reinterpret_cast<const char*>(kRtcpPacketSdesSsrc2),
167
 
      sizeof(kRtcpPacketSdesSsrc2), true));
168
 
  // RTCP Packets with 'special' SSRC 0x01 are demuxed also
169
 
  EXPECT_TRUE(ssrc_filter.DemuxPacket(
170
 
      reinterpret_cast<const char*>(kRtcpPacketSrSsrc01),
171
 
      sizeof(kRtcpPacketSrSsrc01), true));
172
 
  EXPECT_FALSE(ssrc_filter.DemuxPacket(
173
 
      reinterpret_cast<const char*>(kRtcpPacketSrSsrc2),
174
 
      sizeof(kRtcpPacketSrSsrc2), true));
175
 
  EXPECT_FALSE(ssrc_filter.DemuxPacket(
176
 
      reinterpret_cast<const char*>(kRtcpPacketFixedHeaderOnly),
177
 
      sizeof(kRtcpPacketFixedHeaderOnly), true));
178
 
  EXPECT_FALSE(ssrc_filter.DemuxPacket(
179
 
      reinterpret_cast<const char*>(kRtcpPacketTooSmall),
180
 
      sizeof(kRtcpPacketTooSmall), true));
181
 
  EXPECT_TRUE(ssrc_filter.DemuxPacket(
182
 
      reinterpret_cast<const char*>(kRtcpPacketNonCompoundRtcpPliFeedback),
183
 
      sizeof(kRtcpPacketNonCompoundRtcpPliFeedback), true));
184
 
}