blob: ddb151fbc11efd9d4741ca16244075a97f999759 [file] [log] [blame]
eladalon760a0762017-05-31 16:12:251/*
2 * Copyright (c) 2017 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
Mirko Bonadei92ea95e2017-09-15 04:47:3111#include "call/rtp_demuxer.h"
eladalon760a0762017-05-31 16:12:2512
13#include <memory>
Steve Anton9e0c7422017-08-18 01:59:4714#include <set>
eladalond0244c22017-06-08 11:19:1315#include <string>
eladalon760a0762017-05-31 16:12:2516
Mirko Bonadei92ea95e2017-09-15 04:47:3117#include "call/test/mock_rtp_packet_sink_interface.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3118#include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
19#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
20#include "modules/rtp_rtcp/source/rtp_packet_received.h"
21#include "rtc_base/arraysize.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3122#include "rtc_base/checks.h"
Karl Wiberge40468b2017-11-22 09:42:2623#include "rtc_base/numerics/safe_conversions.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3124#include "test/gmock.h"
25#include "test/gtest.h"
eladalon760a0762017-05-31 16:12:2526
27namespace webrtc {
28
29namespace {
30
31using ::testing::_;
eladalond0244c22017-06-08 11:19:1332using ::testing::AtLeast;
33using ::testing::InSequence;
34using ::testing::NiceMock;
eladalon760a0762017-05-31 16:12:2535
Mirko Bonadei6a489f22019-04-09 13:11:1236class RtpDemuxerTest : public ::testing::Test {
Steve Anton9e0c7422017-08-18 01:59:4737 protected:
38 ~RtpDemuxerTest() {
39 for (auto* sink : sinks_to_tear_down_) {
40 demuxer_.RemoveSink(sink);
41 }
Steve Anton9e0c7422017-08-18 01:59:4742 }
43
Steve Anton53c7ba62017-08-18 17:05:4744 // These are convenience methods for calling demuxer.AddSink with different
45 // parameters and will ensure that the sink is automatically removed when the
46 // test case finishes.
47
48 bool AddSink(const RtpDemuxerCriteria& criteria,
49 RtpPacketSinkInterface* sink) {
50 bool added = demuxer_.AddSink(criteria, sink);
Steve Anton9e0c7422017-08-18 01:59:4751 if (added) {
52 sinks_to_tear_down_.insert(sink);
53 }
54 return added;
55 }
56
Steve Anton53c7ba62017-08-18 17:05:4757 bool AddSinkOnlySsrc(uint32_t ssrc, RtpPacketSinkInterface* sink) {
58 RtpDemuxerCriteria criteria;
59 criteria.ssrcs = {ssrc};
60 return AddSink(criteria, sink);
61 }
62
63 bool AddSinkOnlyRsid(const std::string& rsid, RtpPacketSinkInterface* sink) {
Tomas Gunnarssonc3795ff2022-01-03 13:04:5164 RtpDemuxerCriteria criteria(absl::string_view(), rsid);
Steve Anton53c7ba62017-08-18 17:05:4765 return AddSink(criteria, sink);
66 }
67
68 bool AddSinkOnlyMid(const std::string& mid, RtpPacketSinkInterface* sink) {
Tomas Gunnarssonc3795ff2022-01-03 13:04:5169 RtpDemuxerCriteria criteria(mid);
Steve Anton53c7ba62017-08-18 17:05:4770 return AddSink(criteria, sink);
71 }
72
73 bool AddSinkBothMidRsid(const std::string& mid,
74 const std::string& rsid,
75 RtpPacketSinkInterface* sink) {
Tomas Gunnarssonc3795ff2022-01-03 13:04:5176 RtpDemuxerCriteria criteria(mid, rsid);
Steve Anton53c7ba62017-08-18 17:05:4777 return AddSink(criteria, sink);
Steve Anton9e0c7422017-08-18 01:59:4778 }
79
80 bool RemoveSink(RtpPacketSinkInterface* sink) {
81 sinks_to_tear_down_.erase(sink);
82 return demuxer_.RemoveSink(sink);
83 }
84
Steve Anton9e0c7422017-08-18 01:59:4785 // The CreatePacket* methods are helpers for creating new RTP packets with
86 // various attributes set. Tests should use the helper that provides the
87 // minimum information needed to exercise the behavior under test. Tests also
88 // should not rely on any behavior which is not clearly described in the
89 // helper name/arguments. Any additional settings that are not covered by the
90 // helper should be set manually on the packet once it has been returned.
91 // For example, most tests in this file do not care about the RTP sequence
92 // number, but to ensure that the returned packets are valid the helpers will
93 // auto-increment the sequence number starting with 1. Tests that rely on
94 // specific sequence number behavior should call SetSequenceNumber manually on
95 // the returned packet.
96
97 // Intended for use only by other CreatePacket* helpers.
98 std::unique_ptr<RtpPacketReceived> CreatePacket(
99 uint32_t ssrc,
100 RtpPacketReceived::ExtensionManager* extension_manager) {
Mirko Bonadei317a1f02019-09-17 15:06:18101 auto packet = std::make_unique<RtpPacketReceived>(extension_manager);
Steve Anton9e0c7422017-08-18 01:59:47102 packet->SetSsrc(ssrc);
103 packet->SetSequenceNumber(next_sequence_number_++);
104 return packet;
105 }
106
107 std::unique_ptr<RtpPacketReceived> CreatePacketWithSsrc(uint32_t ssrc) {
108 return CreatePacket(ssrc, nullptr);
109 }
110
Steve Anton53c7ba62017-08-18 17:05:47111 std::unique_ptr<RtpPacketReceived> CreatePacketWithSsrcMid(
112 uint32_t ssrc,
113 const std::string& mid) {
114 RtpPacketReceived::ExtensionManager extension_manager;
115 extension_manager.Register<RtpMid>(11);
116
117 auto packet = CreatePacket(ssrc, &extension_manager);
118 packet->SetExtension<RtpMid>(mid);
119 return packet;
120 }
121
Steve Anton9e0c7422017-08-18 01:59:47122 std::unique_ptr<RtpPacketReceived> CreatePacketWithSsrcRsid(
123 uint32_t ssrc,
124 const std::string& rsid) {
125 RtpPacketReceived::ExtensionManager extension_manager;
126 extension_manager.Register<RtpStreamId>(6);
127
128 auto packet = CreatePacket(ssrc, &extension_manager);
129 packet->SetExtension<RtpStreamId>(rsid);
130 return packet;
131 }
132
Steve Anton53c7ba62017-08-18 17:05:47133 std::unique_ptr<RtpPacketReceived> CreatePacketWithSsrcRrid(
134 uint32_t ssrc,
135 const std::string& rrid) {
136 RtpPacketReceived::ExtensionManager extension_manager;
137 extension_manager.Register<RepairedRtpStreamId>(7);
138
139 auto packet = CreatePacket(ssrc, &extension_manager);
140 packet->SetExtension<RepairedRtpStreamId>(rrid);
141 return packet;
142 }
143
144 std::unique_ptr<RtpPacketReceived> CreatePacketWithSsrcMidRsid(
145 uint32_t ssrc,
146 const std::string& mid,
147 const std::string& rsid) {
148 RtpPacketReceived::ExtensionManager extension_manager;
149 extension_manager.Register<RtpMid>(11);
150 extension_manager.Register<RtpStreamId>(6);
151
152 auto packet = CreatePacket(ssrc, &extension_manager);
153 packet->SetExtension<RtpMid>(mid);
154 packet->SetExtension<RtpStreamId>(rsid);
155 return packet;
156 }
157
158 std::unique_ptr<RtpPacketReceived> CreatePacketWithSsrcRsidRrid(
159 uint32_t ssrc,
160 const std::string& rsid,
161 const std::string& rrid) {
162 RtpPacketReceived::ExtensionManager extension_manager;
163 extension_manager.Register<RtpStreamId>(6);
164 extension_manager.Register<RepairedRtpStreamId>(7);
165
166 auto packet = CreatePacket(ssrc, &extension_manager);
167 packet->SetExtension<RtpStreamId>(rsid);
168 packet->SetExtension<RepairedRtpStreamId>(rrid);
169 return packet;
170 }
171
Steve Anton9e0c7422017-08-18 01:59:47172 RtpDemuxer demuxer_;
173 std::set<RtpPacketSinkInterface*> sinks_to_tear_down_;
Steve Anton9e0c7422017-08-18 01:59:47174 uint16_t next_sequence_number_ = 1;
175};
176
Tommi909f3a52020-05-18 14:47:56177class RtpDemuxerDeathTest : public RtpDemuxerTest {};
178
eladalond0244c22017-06-08 11:19:13179MATCHER_P(SamePacketAs, other, "") {
180 return arg.Ssrc() == other.Ssrc() &&
181 arg.SequenceNumber() == other.SequenceNumber();
eladalon760a0762017-05-31 16:12:25182}
183
Steve Anton9e0c7422017-08-18 01:59:47184TEST_F(RtpDemuxerTest, CanAddSinkBySsrc) {
eladalon5daecca2017-08-04 13:34:54185 MockRtpPacketSink sink;
186 constexpr uint32_t ssrc = 1;
187
Steve Anton9e0c7422017-08-18 01:59:47188 EXPECT_TRUE(AddSinkOnlySsrc(ssrc, &sink));
eladalon5daecca2017-08-04 13:34:54189}
190
Steve Anton53c7ba62017-08-18 17:05:47191TEST_F(RtpDemuxerTest, AllowAddSinkWithOverlappingPayloadTypesIfDifferentMid) {
192 const std::string mid1 = "v";
193 const std::string mid2 = "a";
194 constexpr uint8_t pt1 = 30;
195 constexpr uint8_t pt2 = 31;
196 constexpr uint8_t pt3 = 32;
197
198 RtpDemuxerCriteria pt1_pt2;
199 pt1_pt2.mid = mid1;
200 pt1_pt2.payload_types = {pt1, pt2};
201 MockRtpPacketSink sink1;
202 AddSink(pt1_pt2, &sink1);
203
204 RtpDemuxerCriteria pt1_pt3;
205 pt1_pt2.mid = mid2;
206 pt1_pt3.payload_types = {pt1, pt3};
207 MockRtpPacketSink sink2;
208 EXPECT_TRUE(AddSink(pt1_pt3, &sink2));
209}
210
211TEST_F(RtpDemuxerTest, RejectAddSinkForSameMidOnly) {
212 const std::string mid = "mid";
213
214 MockRtpPacketSink sink;
215 AddSinkOnlyMid(mid, &sink);
216 EXPECT_FALSE(AddSinkOnlyMid(mid, &sink));
217}
218
219TEST_F(RtpDemuxerTest, RejectAddSinkForSameMidRsid) {
220 const std::string mid = "v";
221 const std::string rsid = "1";
222
223 MockRtpPacketSink sink1;
224 AddSinkBothMidRsid(mid, rsid, &sink1);
225
226 MockRtpPacketSink sink2;
227 EXPECT_FALSE(AddSinkBothMidRsid(mid, rsid, &sink2));
228}
229
230TEST_F(RtpDemuxerTest, RejectAddSinkForConflictingMidAndMidRsid) {
231 const std::string mid = "v";
232 const std::string rsid = "1";
233
234 MockRtpPacketSink mid_sink;
235 AddSinkOnlyMid(mid, &mid_sink);
236
237 // This sink would never get any packets routed to it because the above sink
238 // would receive them all.
239 MockRtpPacketSink mid_rsid_sink;
240 EXPECT_FALSE(AddSinkBothMidRsid(mid, rsid, &mid_rsid_sink));
241}
242
243TEST_F(RtpDemuxerTest, RejectAddSinkForConflictingMidRsidAndMid) {
244 const std::string mid = "v";
245 const std::string rsid = "";
246
247 MockRtpPacketSink mid_rsid_sink;
248 AddSinkBothMidRsid(mid, rsid, &mid_rsid_sink);
249
250 // This sink would shadow the above sink.
251 MockRtpPacketSink mid_sink;
252 EXPECT_FALSE(AddSinkOnlyMid(mid, &mid_sink));
253}
254
255TEST_F(RtpDemuxerTest, AddSinkFailsIfCalledForTwoSinksWithSameSsrc) {
256 MockRtpPacketSink sink_a;
257 MockRtpPacketSink sink_b;
258 constexpr uint32_t ssrc = 1;
259 ASSERT_TRUE(AddSinkOnlySsrc(ssrc, &sink_a));
260
261 EXPECT_FALSE(AddSinkOnlySsrc(ssrc, &sink_b));
262}
263
264TEST_F(RtpDemuxerTest, AddSinkFailsIfCalledTwiceEvenIfSameSinkWithSameSsrc) {
265 MockRtpPacketSink sink;
266 constexpr uint32_t ssrc = 1;
267 ASSERT_TRUE(AddSinkOnlySsrc(ssrc, &sink));
268
269 EXPECT_FALSE(AddSinkOnlySsrc(ssrc, &sink));
270}
271
272// TODO(steveanton): Currently fails because payload type validation is not
273// complete in AddSink (see note in rtp_demuxer.cc).
274TEST_F(RtpDemuxerTest, DISABLED_RejectAddSinkForSamePayloadTypes) {
275 constexpr uint8_t pt1 = 30;
276 constexpr uint8_t pt2 = 31;
277
278 RtpDemuxerCriteria pt1_pt2;
279 pt1_pt2.payload_types = {pt1, pt2};
280 MockRtpPacketSink sink1;
281 AddSink(pt1_pt2, &sink1);
282
283 RtpDemuxerCriteria pt2_pt1;
284 pt2_pt1.payload_types = {pt2, pt1};
285 MockRtpPacketSink sink2;
286 EXPECT_FALSE(AddSink(pt2_pt1, &sink2));
287}
288
289// Routing Tests
290
Steve Anton9e0c7422017-08-18 01:59:47291TEST_F(RtpDemuxerTest, OnRtpPacketCalledOnCorrectSinkBySsrc) {
eladalond0244c22017-06-08 11:19:13292 constexpr uint32_t ssrcs[] = {101, 202, 303};
293 MockRtpPacketSink sinks[arraysize(ssrcs)];
294 for (size_t i = 0; i < arraysize(ssrcs); i++) {
Steve Anton9e0c7422017-08-18 01:59:47295 AddSinkOnlySsrc(ssrcs[i], &sinks[i]);
eladalond0244c22017-06-08 11:19:13296 }
297
298 for (size_t i = 0; i < arraysize(ssrcs); i++) {
Steve Anton9e0c7422017-08-18 01:59:47299 auto packet = CreatePacketWithSsrc(ssrcs[i]);
eladalond0244c22017-06-08 11:19:13300 EXPECT_CALL(sinks[i], OnRtpPacket(SamePacketAs(*packet))).Times(1);
Steve Anton9e0c7422017-08-18 01:59:47301 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet));
eladalon760a0762017-05-31 16:12:25302 }
303}
304
Steve Anton9e0c7422017-08-18 01:59:47305TEST_F(RtpDemuxerTest, OnRtpPacketCalledOnCorrectSinkByRsid) {
eladalond0244c22017-06-08 11:19:13306 const std::string rsids[] = {"a", "b", "c"};
307 MockRtpPacketSink sinks[arraysize(rsids)];
308 for (size_t i = 0; i < arraysize(rsids); i++) {
Steve Anton9e0c7422017-08-18 01:59:47309 AddSinkOnlyRsid(rsids[i], &sinks[i]);
eladalond0244c22017-06-08 11:19:13310 }
311
312 for (size_t i = 0; i < arraysize(rsids); i++) {
Yves Gerey665174f2018-06-19 13:03:05313 auto packet =
314 CreatePacketWithSsrcRsid(rtc::checked_cast<uint32_t>(i), rsids[i]);
eladalond0244c22017-06-08 11:19:13315 EXPECT_CALL(sinks[i], OnRtpPacket(SamePacketAs(*packet))).Times(1);
Steve Anton9e0c7422017-08-18 01:59:47316 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet));
eladalond0244c22017-06-08 11:19:13317 }
318}
319
Steve Anton53c7ba62017-08-18 17:05:47320TEST_F(RtpDemuxerTest, OnRtpPacketCalledOnCorrectSinkByMid) {
321 const std::string mids[] = {"a", "v", "s"};
322 MockRtpPacketSink sinks[arraysize(mids)];
323 for (size_t i = 0; i < arraysize(mids); i++) {
324 AddSinkOnlyMid(mids[i], &sinks[i]);
325 }
326
327 for (size_t i = 0; i < arraysize(mids); i++) {
Yves Gerey665174f2018-06-19 13:03:05328 auto packet =
329 CreatePacketWithSsrcMid(rtc::checked_cast<uint32_t>(i), mids[i]);
Steve Anton53c7ba62017-08-18 17:05:47330 EXPECT_CALL(sinks[i], OnRtpPacket(SamePacketAs(*packet))).Times(1);
331 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet));
332 }
333}
334
335TEST_F(RtpDemuxerTest, OnRtpPacketCalledOnCorrectSinkByMidAndRsid) {
336 const std::string mid = "v";
337 const std::string rsid = "1";
338 constexpr uint32_t ssrc = 10;
339
340 MockRtpPacketSink sink;
341 AddSinkBothMidRsid(mid, rsid, &sink);
342
343 auto packet = CreatePacketWithSsrcMidRsid(ssrc, mid, rsid);
344 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet))).Times(1);
345 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet));
346}
347
348TEST_F(RtpDemuxerTest, OnRtpPacketCalledOnCorrectSinkByRepairedRsid) {
349 const std::string rrid = "1";
350 constexpr uint32_t ssrc = 10;
351
352 MockRtpPacketSink sink;
353 AddSinkOnlyRsid(rrid, &sink);
354
355 auto packet_with_rrid = CreatePacketWithSsrcRrid(ssrc, rrid);
356 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet_with_rrid))).Times(1);
357 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet_with_rrid));
358}
359
360TEST_F(RtpDemuxerTest, OnRtpPacketCalledOnCorrectSinkByPayloadType) {
361 constexpr uint32_t ssrc = 10;
362 constexpr uint8_t payload_type = 30;
363
364 MockRtpPacketSink sink;
365 RtpDemuxerCriteria criteria;
366 criteria.payload_types = {payload_type};
367 AddSink(criteria, &sink);
368
369 auto packet = CreatePacketWithSsrc(ssrc);
370 packet->SetPayloadType(payload_type);
371 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet))).Times(1);
372 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet));
373}
374
Steve Anton9e0c7422017-08-18 01:59:47375TEST_F(RtpDemuxerTest, PacketsDeliveredInRightOrder) {
eladalona52722f2017-06-26 18:23:54376 constexpr uint32_t ssrc = 101;
377 MockRtpPacketSink sink;
Steve Anton9e0c7422017-08-18 01:59:47378 AddSinkOnlySsrc(ssrc, &sink);
eladalond0244c22017-06-08 11:19:13379
380 std::unique_ptr<RtpPacketReceived> packets[5];
381 for (size_t i = 0; i < arraysize(packets); i++) {
Steve Anton9e0c7422017-08-18 01:59:47382 packets[i] = CreatePacketWithSsrc(ssrc);
oprypin0826fb22017-08-22 20:57:48383 packets[i]->SetSequenceNumber(rtc::checked_cast<uint16_t>(i));
eladalond0244c22017-06-08 11:19:13384 }
385
386 InSequence sequence;
387 for (const auto& packet : packets) {
eladalona52722f2017-06-26 18:23:54388 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet))).Times(1);
eladalond0244c22017-06-08 11:19:13389 }
390
391 for (const auto& packet : packets) {
Steve Anton9e0c7422017-08-18 01:59:47392 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet));
eladalond0244c22017-06-08 11:19:13393 }
eladalond0244c22017-06-08 11:19:13394}
395
Steve Anton9e0c7422017-08-18 01:59:47396TEST_F(RtpDemuxerTest, SinkMappedToMultipleSsrcs) {
eladalond0244c22017-06-08 11:19:13397 constexpr uint32_t ssrcs[] = {404, 505, 606};
398 MockRtpPacketSink sink;
399 for (uint32_t ssrc : ssrcs) {
Steve Anton9e0c7422017-08-18 01:59:47400 AddSinkOnlySsrc(ssrc, &sink);
eladalon760a0762017-05-31 16:12:25401 }
402
403 // The sink which is associated with multiple SSRCs gets the callback
404 // triggered for each of those SSRCs.
eladalond0244c22017-06-08 11:19:13405 for (uint32_t ssrc : ssrcs) {
Steve Anton9e0c7422017-08-18 01:59:47406 auto packet = CreatePacketWithSsrc(ssrc);
Steve Anton53c7ba62017-08-18 17:05:47407 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet))).Times(1);
Steve Anton9e0c7422017-08-18 01:59:47408 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet));
eladalon760a0762017-05-31 16:12:25409 }
eladalon760a0762017-05-31 16:12:25410}
411
Steve Anton9e0c7422017-08-18 01:59:47412TEST_F(RtpDemuxerTest, NoCallbackOnSsrcSinkRemovedBeforeFirstPacket) {
eladalond0244c22017-06-08 11:19:13413 constexpr uint32_t ssrc = 404;
414 MockRtpPacketSink sink;
Steve Anton9e0c7422017-08-18 01:59:47415 AddSinkOnlySsrc(ssrc, &sink);
eladalond0244c22017-06-08 11:19:13416
Steve Anton9e0c7422017-08-18 01:59:47417 ASSERT_TRUE(RemoveSink(&sink));
eladalond0244c22017-06-08 11:19:13418
419 // The removed sink does not get callbacks.
Steve Anton9e0c7422017-08-18 01:59:47420 auto packet = CreatePacketWithSsrc(ssrc);
eladalond0244c22017-06-08 11:19:13421 EXPECT_CALL(sink, OnRtpPacket(_)).Times(0); // Not called.
Steve Anton9e0c7422017-08-18 01:59:47422 EXPECT_FALSE(demuxer_.OnRtpPacket(*packet));
eladalond0244c22017-06-08 11:19:13423}
424
Steve Anton9e0c7422017-08-18 01:59:47425TEST_F(RtpDemuxerTest, NoCallbackOnSsrcSinkRemovedAfterFirstPacket) {
eladalond0244c22017-06-08 11:19:13426 constexpr uint32_t ssrc = 404;
427 NiceMock<MockRtpPacketSink> sink;
Steve Anton9e0c7422017-08-18 01:59:47428 AddSinkOnlySsrc(ssrc, &sink);
eladalond0244c22017-06-08 11:19:13429
430 InSequence sequence;
Steve Anton9e0c7422017-08-18 01:59:47431 for (size_t i = 0; i < 10; i++) {
432 ASSERT_TRUE(demuxer_.OnRtpPacket(*CreatePacketWithSsrc(ssrc)));
eladalon760a0762017-05-31 16:12:25433 }
434
Steve Anton9e0c7422017-08-18 01:59:47435 ASSERT_TRUE(RemoveSink(&sink));
eladalon760a0762017-05-31 16:12:25436
eladalond0244c22017-06-08 11:19:13437 // The removed sink does not get callbacks.
Steve Anton9e0c7422017-08-18 01:59:47438 auto packet = CreatePacketWithSsrc(ssrc);
eladalond0244c22017-06-08 11:19:13439 EXPECT_CALL(sink, OnRtpPacket(_)).Times(0); // Not called.
Steve Anton9e0c7422017-08-18 01:59:47440 EXPECT_FALSE(demuxer_.OnRtpPacket(*packet));
eladalond0244c22017-06-08 11:19:13441}
442
eladalon5daecca2017-08-04 13:34:54443// An SSRC may only be mapped to a single sink. However, since configuration
444// of this associations might come from the network, we need to fail gracefully.
Steve Anton9e0c7422017-08-18 01:59:47445TEST_F(RtpDemuxerTest, OnlyOneSinkPerSsrcGetsOnRtpPacketTriggered) {
eladalon5daecca2017-08-04 13:34:54446 MockRtpPacketSink sinks[3];
447 constexpr uint32_t ssrc = 404;
Steve Anton9e0c7422017-08-18 01:59:47448 ASSERT_TRUE(AddSinkOnlySsrc(ssrc, &sinks[0]));
449 ASSERT_FALSE(AddSinkOnlySsrc(ssrc, &sinks[1]));
450 ASSERT_FALSE(AddSinkOnlySsrc(ssrc, &sinks[2]));
eladalon5daecca2017-08-04 13:34:54451
452 // The first sink associated with the SSRC remains active; other sinks
453 // were not really added, and so do not get OnRtpPacket() called.
Steve Anton9e0c7422017-08-18 01:59:47454 auto packet = CreatePacketWithSsrc(ssrc);
eladalon5daecca2017-08-04 13:34:54455 EXPECT_CALL(sinks[0], OnRtpPacket(SamePacketAs(*packet))).Times(1);
456 EXPECT_CALL(sinks[1], OnRtpPacket(_)).Times(0);
457 EXPECT_CALL(sinks[2], OnRtpPacket(_)).Times(0);
Steve Anton9e0c7422017-08-18 01:59:47458 ASSERT_TRUE(demuxer_.OnRtpPacket(*packet));
eladalon5daecca2017-08-04 13:34:54459}
460
Steve Anton9e0c7422017-08-18 01:59:47461TEST_F(RtpDemuxerTest, NoRepeatedCallbackOnRepeatedAddSinkForSameSink) {
eladalond0244c22017-06-08 11:19:13462 constexpr uint32_t ssrc = 111;
463 MockRtpPacketSink sink;
464
Steve Anton9e0c7422017-08-18 01:59:47465 ASSERT_TRUE(AddSinkOnlySsrc(ssrc, &sink));
466 ASSERT_FALSE(AddSinkOnlySsrc(ssrc, &sink));
eladalond0244c22017-06-08 11:19:13467
Steve Anton9e0c7422017-08-18 01:59:47468 auto packet = CreatePacketWithSsrc(ssrc);
eladalond0244c22017-06-08 11:19:13469 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet))).Times(1);
Steve Anton9e0c7422017-08-18 01:59:47470 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet));
eladalond0244c22017-06-08 11:19:13471}
472
Steve Anton9e0c7422017-08-18 01:59:47473TEST_F(RtpDemuxerTest, RemoveSinkReturnsFalseForNeverAddedSink) {
eladalond0244c22017-06-08 11:19:13474 MockRtpPacketSink sink;
Steve Anton9e0c7422017-08-18 01:59:47475 EXPECT_FALSE(RemoveSink(&sink));
eladalond0244c22017-06-08 11:19:13476}
477
Steve Anton9e0c7422017-08-18 01:59:47478TEST_F(RtpDemuxerTest, RemoveSinkReturnsTrueForPreviouslyAddedSsrcSink) {
eladalond0244c22017-06-08 11:19:13479 constexpr uint32_t ssrc = 101;
480 MockRtpPacketSink sink;
Steve Anton9e0c7422017-08-18 01:59:47481 AddSinkOnlySsrc(ssrc, &sink);
eladalond0244c22017-06-08 11:19:13482
Steve Anton9e0c7422017-08-18 01:59:47483 EXPECT_TRUE(RemoveSink(&sink));
eladalond0244c22017-06-08 11:19:13484}
485
Steve Anton9e0c7422017-08-18 01:59:47486TEST_F(RtpDemuxerTest,
487 RemoveSinkReturnsTrueForUnresolvedPreviouslyAddedRsidSink) {
eladalond0244c22017-06-08 11:19:13488 const std::string rsid = "a";
489 MockRtpPacketSink sink;
Steve Anton9e0c7422017-08-18 01:59:47490 AddSinkOnlyRsid(rsid, &sink);
eladalond0244c22017-06-08 11:19:13491
Steve Anton9e0c7422017-08-18 01:59:47492 EXPECT_TRUE(RemoveSink(&sink));
eladalond0244c22017-06-08 11:19:13493}
494
Steve Anton9e0c7422017-08-18 01:59:47495TEST_F(RtpDemuxerTest,
496 RemoveSinkReturnsTrueForResolvedPreviouslyAddedRsidSink) {
eladalond0244c22017-06-08 11:19:13497 const std::string rsid = "a";
498 constexpr uint32_t ssrc = 101;
499 NiceMock<MockRtpPacketSink> sink;
Steve Anton9e0c7422017-08-18 01:59:47500 AddSinkOnlyRsid(rsid, &sink);
501 ASSERT_TRUE(demuxer_.OnRtpPacket(*CreatePacketWithSsrcRsid(ssrc, rsid)));
eladalond0244c22017-06-08 11:19:13502
Steve Anton9e0c7422017-08-18 01:59:47503 EXPECT_TRUE(RemoveSink(&sink));
eladalond0244c22017-06-08 11:19:13504}
505
Steve Anton53c7ba62017-08-18 17:05:47506TEST_F(RtpDemuxerTest, RsidLearnedAndLaterPacketsDeliveredWithOnlySsrc) {
eladalond0244c22017-06-08 11:19:13507 MockRtpPacketSink sink;
508 const std::string rsid = "a";
Steve Anton9e0c7422017-08-18 01:59:47509 AddSinkOnlyRsid(rsid, &sink);
eladalond0244c22017-06-08 11:19:13510
511 // Create a sequence of RTP packets, where only the first one actually
512 // mentions the RSID.
513 std::unique_ptr<RtpPacketReceived> packets[5];
514 constexpr uint32_t rsid_ssrc = 111;
Steve Anton9e0c7422017-08-18 01:59:47515 packets[0] = CreatePacketWithSsrcRsid(rsid_ssrc, rsid);
eladalond0244c22017-06-08 11:19:13516 for (size_t i = 1; i < arraysize(packets); i++) {
Steve Anton9e0c7422017-08-18 01:59:47517 packets[i] = CreatePacketWithSsrc(rsid_ssrc);
eladalon760a0762017-05-31 16:12:25518 }
eladalond0244c22017-06-08 11:19:13519
520 // The first packet associates the RSID with the SSRC, thereby allowing the
521 // demuxer to correctly demux all of the packets.
522 InSequence sequence;
523 for (const auto& packet : packets) {
524 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet))).Times(1);
525 }
526 for (const auto& packet : packets) {
Steve Anton9e0c7422017-08-18 01:59:47527 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet));
eladalond0244c22017-06-08 11:19:13528 }
eladalond0244c22017-06-08 11:19:13529}
530
Steve Anton9e0c7422017-08-18 01:59:47531TEST_F(RtpDemuxerTest, NoCallbackOnRsidSinkRemovedBeforeFirstPacket) {
eladalond0244c22017-06-08 11:19:13532 MockRtpPacketSink sink;
533 const std::string rsid = "a";
Steve Anton9e0c7422017-08-18 01:59:47534 AddSinkOnlyRsid(rsid, &sink);
eladalond0244c22017-06-08 11:19:13535
536 // Sink removed - it won't get triggers even if packets with its RSID arrive.
Steve Anton9e0c7422017-08-18 01:59:47537 ASSERT_TRUE(RemoveSink(&sink));
eladalond0244c22017-06-08 11:19:13538
539 constexpr uint32_t ssrc = 111;
Steve Anton9e0c7422017-08-18 01:59:47540 auto packet = CreatePacketWithSsrcRsid(ssrc, rsid);
eladalond0244c22017-06-08 11:19:13541 EXPECT_CALL(sink, OnRtpPacket(_)).Times(0); // Not called.
Steve Anton9e0c7422017-08-18 01:59:47542 EXPECT_FALSE(demuxer_.OnRtpPacket(*packet));
eladalond0244c22017-06-08 11:19:13543}
544
Steve Anton9e0c7422017-08-18 01:59:47545TEST_F(RtpDemuxerTest, NoCallbackOnRsidSinkRemovedAfterFirstPacket) {
eladalond0244c22017-06-08 11:19:13546 NiceMock<MockRtpPacketSink> sink;
547 const std::string rsid = "a";
Steve Anton9e0c7422017-08-18 01:59:47548 AddSinkOnlyRsid(rsid, &sink);
eladalond0244c22017-06-08 11:19:13549
550 InSequence sequence;
551 constexpr uint32_t ssrc = 111;
Steve Anton9e0c7422017-08-18 01:59:47552 for (size_t i = 0; i < 10; i++) {
553 auto packet = CreatePacketWithSsrcRsid(ssrc, rsid);
554 ASSERT_TRUE(demuxer_.OnRtpPacket(*packet));
eladalond0244c22017-06-08 11:19:13555 }
556
557 // Sink removed - it won't get triggers even if packets with its RSID arrive.
Steve Anton9e0c7422017-08-18 01:59:47558 ASSERT_TRUE(RemoveSink(&sink));
eladalond0244c22017-06-08 11:19:13559
Steve Anton9e0c7422017-08-18 01:59:47560 auto packet = CreatePacketWithSsrcRsid(ssrc, rsid);
eladalond0244c22017-06-08 11:19:13561 EXPECT_CALL(sink, OnRtpPacket(_)).Times(0); // Not called.
Steve Anton9e0c7422017-08-18 01:59:47562 EXPECT_FALSE(demuxer_.OnRtpPacket(*packet));
eladalond0244c22017-06-08 11:19:13563}
564
Steve Anton53c7ba62017-08-18 17:05:47565TEST_F(RtpDemuxerTest, NoCallbackOnMidSinkRemovedBeforeFirstPacket) {
566 const std::string mid = "v";
567 constexpr uint32_t ssrc = 10;
568
569 MockRtpPacketSink sink;
570 AddSinkOnlyMid(mid, &sink);
571 RemoveSink(&sink);
572
573 auto packet = CreatePacketWithSsrcMid(ssrc, mid);
574 EXPECT_CALL(sink, OnRtpPacket(_)).Times(0);
575 EXPECT_FALSE(demuxer_.OnRtpPacket(*packet));
576}
577
578TEST_F(RtpDemuxerTest, NoCallbackOnMidSinkRemovedAfterFirstPacket) {
579 const std::string mid = "v";
580 constexpr uint32_t ssrc = 10;
581
582 NiceMock<MockRtpPacketSink> sink;
583 AddSinkOnlyMid(mid, &sink);
584
585 auto p1 = CreatePacketWithSsrcMid(ssrc, mid);
586 demuxer_.OnRtpPacket(*p1);
587
588 RemoveSink(&sink);
589
590 auto p2 = CreatePacketWithSsrcMid(ssrc, mid);
591 EXPECT_CALL(sink, OnRtpPacket(_)).Times(0);
592 EXPECT_FALSE(demuxer_.OnRtpPacket(*p2));
593}
594
595TEST_F(RtpDemuxerTest, NoCallbackOnMidRsidSinkRemovedAfterFirstPacket) {
596 const std::string mid = "v";
597 const std::string rsid = "1";
598 constexpr uint32_t ssrc = 10;
599
600 NiceMock<MockRtpPacketSink> sink;
601 AddSinkBothMidRsid(mid, rsid, &sink);
602
603 auto p1 = CreatePacketWithSsrcMidRsid(ssrc, mid, rsid);
604 demuxer_.OnRtpPacket(*p1);
605
606 RemoveSink(&sink);
607
608 auto p2 = CreatePacketWithSsrcMidRsid(ssrc, mid, rsid);
609 EXPECT_CALL(sink, OnRtpPacket(_)).Times(0);
610 EXPECT_FALSE(demuxer_.OnRtpPacket(*p2));
611}
612
eladalond0244c22017-06-08 11:19:13613// The RSID to SSRC mapping should be one-to-one. If we end up receiving
614// two (or more) packets with the same SSRC, but different RSIDs, we guarantee
Steve Anton53c7ba62017-08-18 17:05:47615// delivery to one of them but not both.
Steve Anton9e0c7422017-08-18 01:59:47616TEST_F(RtpDemuxerTest, FirstSsrcAssociatedWithAnRsidIsNotForgotten) {
eladalond0244c22017-06-08 11:19:13617 // Each sink has a distinct RSID.
618 MockRtpPacketSink sink_a;
619 const std::string rsid_a = "a";
Steve Anton9e0c7422017-08-18 01:59:47620 AddSinkOnlyRsid(rsid_a, &sink_a);
eladalond0244c22017-06-08 11:19:13621
622 MockRtpPacketSink sink_b;
623 const std::string rsid_b = "b";
Steve Anton9e0c7422017-08-18 01:59:47624 AddSinkOnlyRsid(rsid_b, &sink_b);
eladalond0244c22017-06-08 11:19:13625
626 InSequence sequence; // Verify that the order of delivery is unchanged.
627
628 constexpr uint32_t shared_ssrc = 100;
629
Artem Titovea240272021-07-26 10:40:21630 // First a packet with `rsid_a` is received, and `sink_a` is associated with
eladalond0244c22017-06-08 11:19:13631 // its SSRC.
Steve Anton9e0c7422017-08-18 01:59:47632 auto packet_a = CreatePacketWithSsrcRsid(shared_ssrc, rsid_a);
eladalond0244c22017-06-08 11:19:13633 EXPECT_CALL(sink_a, OnRtpPacket(SamePacketAs(*packet_a))).Times(1);
Steve Anton9e0c7422017-08-18 01:59:47634 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet_a));
eladalond0244c22017-06-08 11:19:13635
Artem Titovea240272021-07-26 10:40:21636 // Second, a packet with `rsid_b` is received. We guarantee that `sink_b`
Steve Anton53c7ba62017-08-18 17:05:47637 // receives it.
Steve Anton9e0c7422017-08-18 01:59:47638 auto packet_b = CreatePacketWithSsrcRsid(shared_ssrc, rsid_b);
Steve Anton53c7ba62017-08-18 17:05:47639 EXPECT_CALL(sink_a, OnRtpPacket(_)).Times(0);
640 EXPECT_CALL(sink_b, OnRtpPacket(SamePacketAs(*packet_b))).Times(1);
Steve Anton9e0c7422017-08-18 01:59:47641 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet_b));
eladalond0244c22017-06-08 11:19:13642
643 // Known edge-case; adding a new RSID association makes us re-examine all
Artem Titovea240272021-07-26 10:40:21644 // SSRCs. `sink_b` may or may not be associated with the SSRC now; we make
Steve Anton53c7ba62017-08-18 17:05:47645 // no promises on that. However, since the RSID is specified and it cannot be
646 // found the packet should be dropped.
eladalon9addbeb2017-06-30 13:26:54647 MockRtpPacketSink sink_c;
648 const std::string rsid_c = "c";
649 constexpr uint32_t some_other_ssrc = shared_ssrc + 1;
Steve Anton9e0c7422017-08-18 01:59:47650 AddSinkOnlySsrc(some_other_ssrc, &sink_c);
Steve Anton53c7ba62017-08-18 17:05:47651
652 auto packet_c = CreatePacketWithSsrcMid(shared_ssrc, rsid_c);
653 EXPECT_CALL(sink_a, OnRtpPacket(_)).Times(0);
654 EXPECT_CALL(sink_b, OnRtpPacket(_)).Times(0);
655 EXPECT_CALL(sink_c, OnRtpPacket(_)).Times(0);
656 EXPECT_FALSE(demuxer_.OnRtpPacket(*packet_c));
eladalond0244c22017-06-08 11:19:13657}
658
Steve Anton9e0c7422017-08-18 01:59:47659TEST_F(RtpDemuxerTest, MultipleRsidsOnSameSink) {
eladalond0244c22017-06-08 11:19:13660 MockRtpPacketSink sink;
661 const std::string rsids[] = {"a", "b", "c"};
662
663 for (const std::string& rsid : rsids) {
Steve Anton9e0c7422017-08-18 01:59:47664 AddSinkOnlyRsid(rsid, &sink);
eladalond0244c22017-06-08 11:19:13665 }
666
667 InSequence sequence;
668 for (size_t i = 0; i < arraysize(rsids); i++) {
669 // Assign different SSRCs and sequence numbers to all packets.
670 const uint32_t ssrc = 1000 + static_cast<uint32_t>(i);
Steve Anton53c7ba62017-08-18 17:05:47671 const uint16_t sequence_number = 50 + static_cast<uint16_t>(i);
Steve Anton9e0c7422017-08-18 01:59:47672 auto packet = CreatePacketWithSsrcRsid(ssrc, rsids[i]);
Steve Anton53c7ba62017-08-18 17:05:47673 packet->SetSequenceNumber(sequence_number);
eladalond0244c22017-06-08 11:19:13674 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet))).Times(1);
Steve Anton9e0c7422017-08-18 01:59:47675 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet));
eladalond0244c22017-06-08 11:19:13676 }
eladalond0244c22017-06-08 11:19:13677}
678
Steve Anton53c7ba62017-08-18 17:05:47679// RSIDs are given higher priority than SSRC because we believe senders are less
680// likely to mislabel packets with RSID than mislabel them with SSRCs.
Steve Anton9e0c7422017-08-18 01:59:47681TEST_F(RtpDemuxerTest, SinkWithBothRsidAndSsrcAssociations) {
Steve Anton53c7ba62017-08-18 17:05:47682 MockRtpPacketSink sink;
eladalond0244c22017-06-08 11:19:13683 constexpr uint32_t standalone_ssrc = 10101;
684 constexpr uint32_t rsid_ssrc = 20202;
Steve Anton53c7ba62017-08-18 17:05:47685 const std::string rsid = "1";
eladalond0244c22017-06-08 11:19:13686
Steve Anton9e0c7422017-08-18 01:59:47687 AddSinkOnlySsrc(standalone_ssrc, &sink);
688 AddSinkOnlyRsid(rsid, &sink);
eladalond0244c22017-06-08 11:19:13689
690 InSequence sequence;
691
Steve Anton9e0c7422017-08-18 01:59:47692 auto ssrc_packet = CreatePacketWithSsrc(standalone_ssrc);
eladalond0244c22017-06-08 11:19:13693 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*ssrc_packet))).Times(1);
Steve Anton9e0c7422017-08-18 01:59:47694 EXPECT_TRUE(demuxer_.OnRtpPacket(*ssrc_packet));
eladalond0244c22017-06-08 11:19:13695
Steve Anton9e0c7422017-08-18 01:59:47696 auto rsid_packet = CreatePacketWithSsrcRsid(rsid_ssrc, rsid);
eladalond0244c22017-06-08 11:19:13697 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*rsid_packet))).Times(1);
Steve Anton9e0c7422017-08-18 01:59:47698 EXPECT_TRUE(demuxer_.OnRtpPacket(*rsid_packet));
eladalond0244c22017-06-08 11:19:13699}
700
Steve Anton53c7ba62017-08-18 17:05:47701// Packets are always guaranteed to be routed to only one sink.
Steve Anton9e0c7422017-08-18 01:59:47702TEST_F(RtpDemuxerTest, AssociatingByRsidAndBySsrcCannotTriggerDoubleCall) {
eladalond0244c22017-06-08 11:19:13703 constexpr uint32_t ssrc = 10101;
eladalond0244c22017-06-08 11:19:13704 const std::string rsid = "a";
eladalond0244c22017-06-08 11:19:13705
Steve Anton9e0c7422017-08-18 01:59:47706 MockRtpPacketSink sink;
707 AddSinkOnlySsrc(ssrc, &sink);
708 AddSinkOnlyRsid(rsid, &sink);
709
710 auto packet = CreatePacketWithSsrcRsid(ssrc, rsid);
eladalond0244c22017-06-08 11:19:13711 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet))).Times(1);
Steve Anton9e0c7422017-08-18 01:59:47712 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet));
eladalon760a0762017-05-31 16:12:25713}
714
Steve Anton53c7ba62017-08-18 17:05:47715
716// If one sink is associated with SSRC x, and another sink with RSID y, then if
717// we receive a packet with both SSRC x and RSID y, route that to only the sink
718// for RSID y since we believe RSID tags to be more trustworthy than signaled
719// SSRCs.
Steve Anton9e0c7422017-08-18 01:59:47720TEST_F(RtpDemuxerTest,
Steve Anton53c7ba62017-08-18 17:05:47721 PacketFittingBothRsidSinkAndSsrcSinkGivenOnlyToRsidSink) {
eladalon5daecca2017-08-04 13:34:54722 constexpr uint32_t ssrc = 111;
723 MockRtpPacketSink ssrc_sink;
Steve Anton9e0c7422017-08-18 01:59:47724 AddSinkOnlySsrc(ssrc, &ssrc_sink);
eladalon5daecca2017-08-04 13:34:54725
726 const std::string rsid = "a";
727 MockRtpPacketSink rsid_sink;
Steve Anton9e0c7422017-08-18 01:59:47728 AddSinkOnlyRsid(rsid, &rsid_sink);
eladalon5daecca2017-08-04 13:34:54729
Steve Anton9e0c7422017-08-18 01:59:47730 auto packet = CreatePacketWithSsrcRsid(ssrc, rsid);
eladalon5daecca2017-08-04 13:34:54731
Steve Anton53c7ba62017-08-18 17:05:47732 EXPECT_CALL(ssrc_sink, OnRtpPacket(_)).Times(0);
733 EXPECT_CALL(rsid_sink, OnRtpPacket(SamePacketAs(*packet))).Times(1);
734 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet));
eladalon5daecca2017-08-04 13:34:54735}
736
737// We're not expecting RSIDs to be resolved to SSRCs which were previously
738// mapped to sinks, and make no guarantees except for graceful handling.
Steve Anton9e0c7422017-08-18 01:59:47739TEST_F(RtpDemuxerTest,
740 GracefullyHandleRsidBeingMappedToPrevouslyAssociatedSsrc) {
eladalon5daecca2017-08-04 13:34:54741 constexpr uint32_t ssrc = 111;
742 NiceMock<MockRtpPacketSink> ssrc_sink;
Steve Anton9e0c7422017-08-18 01:59:47743 AddSinkOnlySsrc(ssrc, &ssrc_sink);
eladalon5daecca2017-08-04 13:34:54744
745 const std::string rsid = "a";
Steve Anton53c7ba62017-08-18 17:05:47746 NiceMock<MockRtpPacketSink> rsid_sink;
Steve Anton9e0c7422017-08-18 01:59:47747 AddSinkOnlyRsid(rsid, &rsid_sink);
eladalon5daecca2017-08-04 13:34:54748
eladalon5daecca2017-08-04 13:34:54749 // The SSRC was mapped to an SSRC sink, but was even active (packets flowed
750 // over it).
Steve Anton9e0c7422017-08-18 01:59:47751 auto packet = CreatePacketWithSsrcRsid(ssrc, rsid);
752 demuxer_.OnRtpPacket(*packet);
eladalon5daecca2017-08-04 13:34:54753
754 // If the SSRC sink is ever removed, the RSID sink *might* receive indications
755 // of packets, and observers *might* be informed. Only graceful handling
756 // is guaranteed.
Steve Anton9e0c7422017-08-18 01:59:47757 RemoveSink(&ssrc_sink);
eladalon5daecca2017-08-04 13:34:54758 EXPECT_CALL(rsid_sink, OnRtpPacket(SamePacketAs(*packet))).Times(AtLeast(0));
Steve Anton53c7ba62017-08-18 17:05:47759 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet));
760}
761
762// Tests that when one MID sink is configured, packets that include the MID
763// extension will get routed to that sink and any packets that use the same
764// SSRC as one of those packets later will also get routed to the sink, even
765// if a new SSRC is introduced for the same MID.
766TEST_F(RtpDemuxerTest, RoutedByMidWhenSsrcAdded) {
767 const std::string mid = "v";
768 NiceMock<MockRtpPacketSink> sink;
769 AddSinkOnlyMid(mid, &sink);
770
771 constexpr uint32_t ssrc1 = 10;
772 constexpr uint32_t ssrc2 = 11;
773
774 auto packet_ssrc1_mid = CreatePacketWithSsrcMid(ssrc1, mid);
775 demuxer_.OnRtpPacket(*packet_ssrc1_mid);
776 auto packet_ssrc2_mid = CreatePacketWithSsrcMid(ssrc2, mid);
777 demuxer_.OnRtpPacket(*packet_ssrc2_mid);
778
779 auto packet_ssrc1_only = CreatePacketWithSsrc(ssrc1);
780 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet_ssrc1_only))).Times(1);
781 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet_ssrc1_only));
782
783 auto packet_ssrc2_only = CreatePacketWithSsrc(ssrc2);
784 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet_ssrc2_only))).Times(1);
785 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet_ssrc2_only));
786}
787
788TEST_F(RtpDemuxerTest, DontLearnMidSsrcBindingBeforeSinkAdded) {
789 const std::string mid = "v";
790 constexpr uint32_t ssrc = 10;
791
792 auto packet_ssrc_mid = CreatePacketWithSsrcMid(ssrc, mid);
793 ASSERT_FALSE(demuxer_.OnRtpPacket(*packet_ssrc_mid));
794
795 MockRtpPacketSink sink;
796 AddSinkOnlyMid(mid, &sink);
797
798 auto packet_ssrc_only = CreatePacketWithSsrc(ssrc);
799 EXPECT_CALL(sink, OnRtpPacket(_)).Times(0);
800 EXPECT_FALSE(demuxer_.OnRtpPacket(*packet_ssrc_only));
801}
802
803TEST_F(RtpDemuxerTest, DontForgetMidSsrcBindingWhenSinkRemoved) {
804 const std::string mid = "v";
805 constexpr uint32_t ssrc = 10;
806
807 NiceMock<MockRtpPacketSink> sink1;
808 AddSinkOnlyMid(mid, &sink1);
809
810 auto packet_with_mid = CreatePacketWithSsrcMid(ssrc, mid);
811 demuxer_.OnRtpPacket(*packet_with_mid);
812
813 RemoveSink(&sink1);
814
815 MockRtpPacketSink sink2;
816 AddSinkOnlyMid(mid, &sink2);
817
818 auto packet_with_ssrc = CreatePacketWithSsrc(ssrc);
819 EXPECT_CALL(sink2, OnRtpPacket(SamePacketAs(*packet_with_ssrc)));
820 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet_with_ssrc));
821}
822
823// If a sink is added with only a MID, then any packet with that MID no matter
824// the RSID should be routed to that sink.
825TEST_F(RtpDemuxerTest, RoutedByMidWithAnyRsid) {
826 const std::string mid = "v";
827 const std::string rsid1 = "1";
828 const std::string rsid2 = "2";
829 constexpr uint32_t ssrc1 = 10;
830 constexpr uint32_t ssrc2 = 11;
831
832 MockRtpPacketSink sink;
833 AddSinkOnlyMid(mid, &sink);
834
835 InSequence sequence;
836
837 auto packet_ssrc1_rsid1 = CreatePacketWithSsrcMidRsid(ssrc1, mid, rsid1);
838 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet_ssrc1_rsid1))).Times(1);
839 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet_ssrc1_rsid1));
840
841 auto packet_ssrc2_rsid2 = CreatePacketWithSsrcMidRsid(ssrc2, mid, rsid2);
842 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet_ssrc2_rsid2))).Times(1);
843 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet_ssrc2_rsid2));
844}
845
846// These two tests verify that for a sink added with a MID, RSID pair, if the
847// MID and RSID are learned in separate packets (e.g., because the header
848// extensions are sent separately), then a later packet with just SSRC will get
849// routed to that sink.
850// The first test checks that the functionality works when MID is learned first.
851// The second test checks that the functionality works when RSID is learned
852// first.
853TEST_F(RtpDemuxerTest, LearnMidThenRsidSeparatelyAndRouteBySsrc) {
854 const std::string mid = "v";
855 const std::string rsid = "1";
856 constexpr uint32_t ssrc = 10;
857
858 NiceMock<MockRtpPacketSink> sink;
859 AddSinkBothMidRsid(mid, rsid, &sink);
860
861 auto packet_with_mid = CreatePacketWithSsrcMid(ssrc, mid);
862 ASSERT_FALSE(demuxer_.OnRtpPacket(*packet_with_mid));
863
864 auto packet_with_rsid = CreatePacketWithSsrcRsid(ssrc, rsid);
865 ASSERT_TRUE(demuxer_.OnRtpPacket(*packet_with_rsid));
866
867 auto packet_with_ssrc = CreatePacketWithSsrc(ssrc);
868 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet_with_ssrc))).Times(1);
869 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet_with_ssrc));
870}
871
872TEST_F(RtpDemuxerTest, LearnRsidThenMidSeparatelyAndRouteBySsrc) {
873 const std::string mid = "v";
874 const std::string rsid = "1";
875 constexpr uint32_t ssrc = 10;
876
877 NiceMock<MockRtpPacketSink> sink;
878 AddSinkBothMidRsid(mid, rsid, &sink);
879
880 auto packet_with_rsid = CreatePacketWithSsrcRsid(ssrc, rsid);
881 ASSERT_FALSE(demuxer_.OnRtpPacket(*packet_with_rsid));
882
883 auto packet_with_mid = CreatePacketWithSsrcMid(ssrc, mid);
884 ASSERT_TRUE(demuxer_.OnRtpPacket(*packet_with_mid));
885
886 auto packet_with_ssrc = CreatePacketWithSsrc(ssrc);
887 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet_with_ssrc))).Times(1);
888 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet_with_ssrc));
889}
890
891TEST_F(RtpDemuxerTest, DontLearnMidRsidBindingBeforeSinkAdded) {
892 const std::string mid = "v";
893 const std::string rsid = "1";
894 constexpr uint32_t ssrc = 10;
895
896 auto packet_with_both = CreatePacketWithSsrcMidRsid(ssrc, mid, rsid);
897 ASSERT_FALSE(demuxer_.OnRtpPacket(*packet_with_both));
898
899 MockRtpPacketSink sink;
900 AddSinkBothMidRsid(mid, rsid, &sink);
901
902 auto packet_with_ssrc = CreatePacketWithSsrc(ssrc);
903 EXPECT_CALL(sink, OnRtpPacket(_)).Times(0);
904 EXPECT_FALSE(demuxer_.OnRtpPacket(*packet_with_ssrc));
905}
906
907TEST_F(RtpDemuxerTest, DontForgetMidRsidBindingWhenSinkRemoved) {
908 const std::string mid = "v";
909 const std::string rsid = "1";
910 constexpr uint32_t ssrc = 10;
911
912 NiceMock<MockRtpPacketSink> sink1;
913 AddSinkBothMidRsid(mid, rsid, &sink1);
914
915 auto packet_with_both = CreatePacketWithSsrcMidRsid(ssrc, mid, rsid);
916 demuxer_.OnRtpPacket(*packet_with_both);
917
918 RemoveSink(&sink1);
919
920 MockRtpPacketSink sink2;
921 AddSinkBothMidRsid(mid, rsid, &sink2);
922
923 auto packet_with_ssrc = CreatePacketWithSsrc(ssrc);
924 EXPECT_CALL(sink2, OnRtpPacket(SamePacketAs(*packet_with_ssrc)));
925 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet_with_ssrc));
926}
927
928TEST_F(RtpDemuxerTest, LearnMidRsidBindingAfterSinkAdded) {
929 const std::string mid = "v";
930 const std::string rsid = "1";
931 constexpr uint32_t ssrc = 10;
932
933 NiceMock<MockRtpPacketSink> sink;
934 AddSinkBothMidRsid(mid, rsid, &sink);
935
936 auto packet_with_both = CreatePacketWithSsrcMidRsid(ssrc, mid, rsid);
937 demuxer_.OnRtpPacket(*packet_with_both);
938
939 auto packet_with_ssrc = CreatePacketWithSsrc(ssrc);
940 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet_with_ssrc)));
941 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet_with_ssrc));
942}
943
944TEST_F(RtpDemuxerTest, DropByPayloadTypeIfNoSink) {
945 constexpr uint8_t payload_type = 30;
946 constexpr uint32_t ssrc = 10;
947
948 auto packet = CreatePacketWithSsrc(ssrc);
949 packet->SetPayloadType(payload_type);
950 EXPECT_FALSE(demuxer_.OnRtpPacket(*packet));
951}
952
953// For legacy applications, it's possible for us to demux if the payload type is
954// unique. But if multiple sinks are registered with different MIDs and the same
955// payload types, then we cannot route a packet with just payload type because
956// it is ambiguous which sink it should be sent to.
957TEST_F(RtpDemuxerTest, DropByPayloadTypeIfAddedInMultipleSinks) {
958 const std::string mid1 = "v";
959 const std::string mid2 = "a";
960 constexpr uint8_t payload_type = 30;
961 constexpr uint32_t ssrc = 10;
962
963 RtpDemuxerCriteria mid1_pt;
964 mid1_pt.mid = mid1;
965 mid1_pt.payload_types = {payload_type};
966 MockRtpPacketSink sink1;
967 AddSink(mid1_pt, &sink1);
968
969 RtpDemuxerCriteria mid2_pt;
970 mid2_pt.mid = mid2;
971 mid2_pt.payload_types = {payload_type};
972 MockRtpPacketSink sink2;
973 AddSink(mid2_pt, &sink2);
974
975 auto packet = CreatePacketWithSsrc(ssrc);
976 packet->SetPayloadType(payload_type);
977
978 EXPECT_CALL(sink1, OnRtpPacket(_)).Times(0);
979 EXPECT_CALL(sink2, OnRtpPacket(_)).Times(0);
980 EXPECT_FALSE(demuxer_.OnRtpPacket(*packet));
981}
982
983// If two sinks are added with different MIDs but the same payload types, then
984// we cannot demux on the payload type only unless one of the sinks is removed.
985TEST_F(RtpDemuxerTest, RoutedByPayloadTypeIfAmbiguousSinkRemoved) {
986 const std::string mid1 = "v";
987 const std::string mid2 = "a";
988 constexpr uint8_t payload_type = 30;
989 constexpr uint32_t ssrc = 10;
990
991 RtpDemuxerCriteria mid1_pt;
992 mid1_pt.mid = mid1;
993 mid1_pt.payload_types = {payload_type};
994 MockRtpPacketSink sink1;
995 AddSink(mid1_pt, &sink1);
996
997 RtpDemuxerCriteria mid2_pt;
998 mid2_pt.mid = mid2;
999 mid2_pt.payload_types = {payload_type};
1000 MockRtpPacketSink sink2;
1001 AddSink(mid2_pt, &sink2);
1002
1003 RemoveSink(&sink1);
1004
1005 auto packet = CreatePacketWithSsrc(ssrc);
1006 packet->SetPayloadType(payload_type);
1007
1008 EXPECT_CALL(sink1, OnRtpPacket(_)).Times(0);
1009 EXPECT_CALL(sink2, OnRtpPacket(SamePacketAs(*packet))).Times(1);
1010
1011 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet));
1012}
1013
1014TEST_F(RtpDemuxerTest, RoutedByPayloadTypeLatchesSsrc) {
1015 constexpr uint8_t payload_type = 30;
1016 constexpr uint32_t ssrc = 10;
1017
1018 RtpDemuxerCriteria pt;
1019 pt.payload_types = {payload_type};
1020 NiceMock<MockRtpPacketSink> sink;
1021 AddSink(pt, &sink);
1022
1023 auto packet_with_pt = CreatePacketWithSsrc(ssrc);
1024 packet_with_pt->SetPayloadType(payload_type);
1025 ASSERT_TRUE(demuxer_.OnRtpPacket(*packet_with_pt));
1026
1027 auto packet_with_ssrc = CreatePacketWithSsrc(ssrc);
1028 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet_with_ssrc))).Times(1);
1029 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet_with_ssrc));
1030}
1031
1032// RSIDs are scoped within MID, so if two sinks are registered with the same
1033// RSIDs but different MIDs, then packets containing both extensions should be
1034// routed to the correct one.
1035TEST_F(RtpDemuxerTest, PacketWithSameRsidDifferentMidRoutedToProperSink) {
1036 const std::string mid1 = "mid1";
1037 const std::string mid2 = "mid2";
1038 const std::string rsid = "rsid";
1039 constexpr uint32_t ssrc1 = 10;
1040 constexpr uint32_t ssrc2 = 11;
1041
1042 NiceMock<MockRtpPacketSink> mid1_sink;
1043 AddSinkBothMidRsid(mid1, rsid, &mid1_sink);
1044
1045 MockRtpPacketSink mid2_sink;
1046 AddSinkBothMidRsid(mid2, rsid, &mid2_sink);
1047
1048 auto packet_mid1 = CreatePacketWithSsrcMidRsid(ssrc1, mid1, rsid);
1049 ASSERT_TRUE(demuxer_.OnRtpPacket(*packet_mid1));
1050
1051 auto packet_mid2 = CreatePacketWithSsrcMidRsid(ssrc2, mid2, rsid);
1052 EXPECT_CALL(mid2_sink, OnRtpPacket(SamePacketAs(*packet_mid2))).Times(1);
1053 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet_mid2));
1054}
1055
1056// If a sink is first bound to a given SSRC by signaling but later a new sink is
1057// bound to a given MID by a later signaling, then when a packet arrives with
1058// both the SSRC and MID, then the signaled MID sink should take precedence.
1059TEST_F(RtpDemuxerTest, SignaledMidShouldOverwriteSignaledSsrc) {
1060 constexpr uint32_t ssrc = 11;
1061 const std::string mid = "mid";
1062
1063 MockRtpPacketSink ssrc_sink;
1064 AddSinkOnlySsrc(ssrc, &ssrc_sink);
1065
1066 MockRtpPacketSink mid_sink;
1067 AddSinkOnlyMid(mid, &mid_sink);
1068
1069 auto p = CreatePacketWithSsrcMid(ssrc, mid);
1070 EXPECT_CALL(ssrc_sink, OnRtpPacket(_)).Times(0);
1071 EXPECT_CALL(mid_sink, OnRtpPacket(SamePacketAs(*p))).Times(1);
1072 EXPECT_TRUE(demuxer_.OnRtpPacket(*p));
1073}
1074
1075// Extends the previous test to also ensure that later packets that do not
1076// specify MID are still routed to the MID sink rather than the overwritten SSRC
1077// sink.
1078TEST_F(RtpDemuxerTest, SignaledMidShouldOverwriteSignalledSsrcPersistent) {
1079 constexpr uint32_t ssrc = 11;
1080 const std::string mid = "mid";
1081
1082 MockRtpPacketSink ssrc_sink;
1083 AddSinkOnlySsrc(ssrc, &ssrc_sink);
1084
1085 NiceMock<MockRtpPacketSink> mid_sink;
1086 AddSinkOnlyMid(mid, &mid_sink);
1087
1088 EXPECT_CALL(ssrc_sink, OnRtpPacket(_)).Times(0);
1089
1090 auto packet_with_mid = CreatePacketWithSsrcMid(ssrc, mid);
1091 demuxer_.OnRtpPacket(*packet_with_mid);
1092
1093 auto packet_without_mid = CreatePacketWithSsrc(ssrc);
1094 EXPECT_CALL(mid_sink, OnRtpPacket(SamePacketAs(*packet_without_mid)))
1095 .Times(1);
1096 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet_without_mid));
1097}
1098
1099TEST_F(RtpDemuxerTest, RouteByPayloadTypeMultipleMatch) {
1100 constexpr uint32_t ssrc = 10;
1101 constexpr uint8_t pt1 = 30;
1102 constexpr uint8_t pt2 = 31;
1103
1104 MockRtpPacketSink sink;
1105 RtpDemuxerCriteria criteria;
1106 criteria.payload_types = {pt1, pt2};
1107 AddSink(criteria, &sink);
1108
1109 auto packet_with_pt1 = CreatePacketWithSsrc(ssrc);
1110 packet_with_pt1->SetPayloadType(pt1);
1111 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet_with_pt1)));
1112 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet_with_pt1));
1113
1114 auto packet_with_pt2 = CreatePacketWithSsrc(ssrc);
1115 packet_with_pt2->SetPayloadType(pt2);
1116 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet_with_pt2)));
1117 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet_with_pt2));
1118}
1119
1120TEST_F(RtpDemuxerTest, DontDemuxOnMidAloneIfAddedWithRsid) {
1121 const std::string mid = "v";
1122 const std::string rsid = "1";
1123 constexpr uint32_t ssrc = 10;
1124
1125 MockRtpPacketSink sink;
1126 AddSinkBothMidRsid(mid, rsid, &sink);
1127
1128 EXPECT_CALL(sink, OnRtpPacket(_)).Times(0);
1129
1130 auto packet = CreatePacketWithSsrcMid(ssrc, mid);
1131 EXPECT_FALSE(demuxer_.OnRtpPacket(*packet));
1132}
1133
1134TEST_F(RtpDemuxerTest, DemuxBySsrcEvenWithMidAndRsid) {
1135 const std::string mid = "v";
1136 const std::string rsid = "1";
1137 constexpr uint32_t ssrc = 10;
1138
1139 RtpDemuxerCriteria criteria;
1140 criteria.rsid = rsid;
1141 criteria.mid = mid;
1142 criteria.ssrcs = {ssrc};
1143 MockRtpPacketSink sink;
1144 AddSink(criteria, &sink);
1145
1146 auto packet = CreatePacketWithSsrc(ssrc);
1147 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet))).Times(1);
1148 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet));
1149}
1150
1151// In slight deviation from the BUNDLE spec, if we match a sink according to
1152// SSRC, then we do not verify payload type against the criteria and defer to
1153// the sink to check that it is correct.
1154TEST_F(RtpDemuxerTest, DoNotCheckPayloadTypeIfMatchedByOtherCriteria) {
1155 constexpr uint32_t ssrc = 10;
1156 constexpr uint8_t payload_type = 30;
1157 constexpr uint8_t different_payload_type = payload_type + 1;
1158
1159 RtpDemuxerCriteria criteria;
1160 criteria.ssrcs = {ssrc};
1161 criteria.payload_types = {payload_type};
1162 MockRtpPacketSink sink;
1163 AddSink(criteria, &sink);
1164
1165 auto packet = CreatePacketWithSsrc(ssrc);
1166 packet->SetPayloadType(different_payload_type);
1167 EXPECT_CALL(sink, OnRtpPacket(SamePacketAs(*packet))).Times(1);
1168 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet));
1169}
1170
1171// If a repair packet includes an RSID it should be ignored and the packet
1172// should be routed by its RRID.
1173TEST_F(RtpDemuxerTest, PacketWithRsidAndRridRoutedByRrid) {
1174 const std::string rsid = "1";
1175 const std::string rrid = "1r";
1176 constexpr uint32_t ssrc = 10;
1177
1178 MockRtpPacketSink sink_rsid;
1179 AddSinkOnlyRsid(rsid, &sink_rsid);
1180
1181 MockRtpPacketSink sink_rrid;
1182 AddSinkOnlyRsid(rrid, &sink_rrid);
1183
1184 auto packet = CreatePacketWithSsrcRsidRrid(ssrc, rsid, rrid);
1185 EXPECT_CALL(sink_rsid, OnRtpPacket(_)).Times(0);
1186 EXPECT_CALL(sink_rrid, OnRtpPacket(SamePacketAs(*packet))).Times(1);
1187 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet));
1188}
1189
1190// Same test as above but checks that the latched SSRC routes to the RRID sink.
1191TEST_F(RtpDemuxerTest, PacketWithRsidAndRridLatchesSsrcToRrid) {
1192 const std::string rsid = "1";
1193 const std::string rrid = "1r";
1194 constexpr uint32_t ssrc = 10;
1195
1196 MockRtpPacketSink sink_rsid;
1197 AddSinkOnlyRsid(rsid, &sink_rsid);
1198
1199 NiceMock<MockRtpPacketSink> sink_rrid;
1200 AddSinkOnlyRsid(rrid, &sink_rrid);
1201
1202 auto packet_rsid_rrid = CreatePacketWithSsrcRsidRrid(ssrc, rsid, rrid);
1203 demuxer_.OnRtpPacket(*packet_rsid_rrid);
1204
1205 auto packet_ssrc_only = CreatePacketWithSsrc(ssrc);
1206 EXPECT_CALL(sink_rsid, OnRtpPacket(_)).Times(0);
1207 EXPECT_CALL(sink_rrid, OnRtpPacket(SamePacketAs(*packet_ssrc_only))).Times(1);
1208 EXPECT_TRUE(demuxer_.OnRtpPacket(*packet_ssrc_only));
1209}
1210
1211// Tests that a packet which includes MID and RSID is dropped and not routed by
1212// SSRC if the MID and RSID do not match an added sink.
1213TEST_F(RtpDemuxerTest, PacketWithMidAndUnknownRsidIsNotRoutedBySsrc) {
1214 constexpr uint32_t ssrc = 10;
1215 const std::string mid = "v";
1216 const std::string rsid = "1";
1217 const std::string wrong_rsid = "2";
1218
1219 RtpDemuxerCriteria criteria;
1220 criteria.mid = mid;
1221 criteria.rsid = rsid;
1222 criteria.ssrcs = {ssrc};
1223 MockRtpPacketSink sink;
1224 AddSink(criteria, &sink);
1225
1226 auto packet = CreatePacketWithSsrcMidRsid(ssrc, mid, wrong_rsid);
1227 EXPECT_CALL(sink, OnRtpPacket(_)).Times(0);
1228 EXPECT_FALSE(demuxer_.OnRtpPacket(*packet));
1229}
1230
1231// Tests that a packet which includes MID and RSID is dropped and not routed by
1232// payload type if the MID and RSID do not match an added sink.
1233TEST_F(RtpDemuxerTest, PacketWithMidAndUnknownRsidIsNotRoutedByPayloadType) {
1234 constexpr uint32_t ssrc = 10;
1235 const std::string mid = "v";
1236 const std::string rsid = "1";
1237 const std::string wrong_rsid = "2";
1238 constexpr uint8_t payload_type = 30;
1239
1240 RtpDemuxerCriteria criteria;
1241 criteria.mid = mid;
1242 criteria.rsid = rsid;
1243 criteria.payload_types = {payload_type};
1244 MockRtpPacketSink sink;
1245 AddSink(criteria, &sink);
1246
1247 auto packet = CreatePacketWithSsrcMidRsid(ssrc, mid, wrong_rsid);
1248 packet->SetPayloadType(payload_type);
1249 EXPECT_CALL(sink, OnRtpPacket(_)).Times(0);
1250 EXPECT_FALSE(demuxer_.OnRtpPacket(*packet));
1251}
1252
eladalon760a0762017-05-31 16:12:251253#if RTC_DCHECK_IS_ON && GTEST_HAS_DEATH_TEST && !defined(WEBRTC_ANDROID)
Steve Anton53c7ba62017-08-18 17:05:471254
Tommi909f3a52020-05-18 14:47:561255TEST_F(RtpDemuxerDeathTest, CriteriaMustBeNonEmpty) {
eladalond0244c22017-06-08 11:19:131256 MockRtpPacketSink sink;
Steve Anton53c7ba62017-08-18 17:05:471257 RtpDemuxerCriteria criteria;
1258 EXPECT_DEATH(AddSink(criteria, &sink), "");
eladalond0244c22017-06-08 11:19:131259}
1260
Tommi909f3a52020-05-18 14:47:561261TEST_F(RtpDemuxerDeathTest, RsidMustBeAlphaNumeric) {
eladalond0244c22017-06-08 11:19:131262 MockRtpPacketSink sink;
Steve Anton9e0c7422017-08-18 01:59:471263 EXPECT_DEATH(AddSinkOnlyRsid("a_3", &sink), "");
eladalond0244c22017-06-08 11:19:131264}
1265
Tommi909f3a52020-05-18 14:47:561266TEST_F(RtpDemuxerDeathTest, MidMustBeToken) {
Steve Anton53c7ba62017-08-18 17:05:471267 MockRtpPacketSink sink;
Joachim Bauchd3b7ec22018-08-01 08:12:001268 EXPECT_DEATH(AddSinkOnlyMid("a(3)", &sink), "");
Steve Anton53c7ba62017-08-18 17:05:471269}
1270
Tommi909f3a52020-05-18 14:47:561271TEST_F(RtpDemuxerDeathTest, RsidMustNotExceedMaximumLength) {
eladalond0244c22017-06-08 11:19:131272 MockRtpPacketSink sink;
Niels Möllerd57efc12019-03-22 13:02:111273 std::string rsid(BaseRtpStringExtension::kMaxValueSizeBytes + 1, 'a');
Steve Anton9e0c7422017-08-18 01:59:471274 EXPECT_DEATH(AddSinkOnlyRsid(rsid, &sink), "");
eladalond0244c22017-06-08 11:19:131275}
1276
Tommi909f3a52020-05-18 14:47:561277TEST_F(RtpDemuxerDeathTest, MidMustNotExceedMaximumLength) {
Steve Anton9e0c7422017-08-18 01:59:471278 MockRtpPacketSink sink;
Niels Möllerd57efc12019-03-22 13:02:111279 std::string mid(BaseRtpStringExtension::kMaxValueSizeBytes + 1, 'a');
Steve Anton53c7ba62017-08-18 17:05:471280 EXPECT_DEATH(AddSinkOnlyMid(mid, &sink), "");
eladalon760a0762017-05-31 16:12:251281}
eladalona52722f2017-06-26 18:23:541282
eladalon760a0762017-05-31 16:12:251283#endif
1284
1285} // namespace
1286} // namespace webrtc