OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 InSequence sequence; // Verify that the order of delivery is unchanged. | 374 InSequence sequence; // Verify that the order of delivery is unchanged. |
375 | 375 |
376 constexpr uint32_t shared_ssrc = 100; | 376 constexpr uint32_t shared_ssrc = 100; |
377 | 377 |
378 // First a packet with |rsid_a| is received, and |sink_a| is associated with | 378 // First a packet with |rsid_a| is received, and |sink_a| is associated with |
379 // its SSRC. | 379 // its SSRC. |
380 auto packet_a = CreateRtpPacketReceivedWithRsid(rsid_a, shared_ssrc, 10); | 380 auto packet_a = CreateRtpPacketReceivedWithRsid(rsid_a, shared_ssrc, 10); |
381 EXPECT_CALL(sink_a, OnRtpPacket(SamePacketAs(*packet_a))).Times(1); | 381 EXPECT_CALL(sink_a, OnRtpPacket(SamePacketAs(*packet_a))).Times(1); |
382 EXPECT_TRUE(demuxer.OnRtpPacket(*packet_a)); | 382 EXPECT_TRUE(demuxer.OnRtpPacket(*packet_a)); |
383 | 383 |
384 // Second, a packet with |rsid_b| is received. Its RSID is ignored. | 384 // Second, a packet with |rsid_b| is received. We guarantee that |sink_a| |
| 385 // would receive it, and make no guarantees about |sink_b|. |
385 auto packet_b = CreateRtpPacketReceivedWithRsid(rsid_b, shared_ssrc, 20); | 386 auto packet_b = CreateRtpPacketReceivedWithRsid(rsid_b, shared_ssrc, 20); |
386 EXPECT_CALL(sink_a, OnRtpPacket(SamePacketAs(*packet_b))).Times(1); | 387 EXPECT_CALL(sink_a, OnRtpPacket(SamePacketAs(*packet_b))).Times(1); |
| 388 EXPECT_CALL(sink_b, OnRtpPacket(SamePacketAs(*packet_b))).Times(AtLeast(0)); |
387 EXPECT_TRUE(demuxer.OnRtpPacket(*packet_b)); | 389 EXPECT_TRUE(demuxer.OnRtpPacket(*packet_b)); |
388 | 390 |
389 // Known edge-case; adding a new RSID association makes us re-examine all | 391 // Known edge-case; adding a new RSID association makes us re-examine all |
390 // SSRCs. |sink_b| may or may not be associated with the SSRC now; we make | 392 // SSRCs. |sink_b| may or may not be associated with the SSRC now; we make |
391 // no promises on that. We do however still guarantee that |sink_a| still | 393 // no promises on that. We do however still guarantee that |sink_a| still |
392 // receives the new packets. | 394 // receives the new packets. |
393 MockRtpPacketSink sink_ignored; | 395 MockRtpPacketSink sink_c; |
394 demuxer.AddSink("ignored", &sink_ignored); | 396 const std::string rsid_c = "c"; |
395 auto packet_c = CreateRtpPacketReceivedWithRsid(rsid_b, shared_ssrc, 30); | 397 constexpr uint32_t some_other_ssrc = shared_ssrc + 1; |
| 398 demuxer.AddSink(some_other_ssrc, &sink_c); |
| 399 auto packet_c = CreateRtpPacketReceivedWithRsid(rsid_c, shared_ssrc, 30); |
396 EXPECT_CALL(sink_a, OnRtpPacket(SamePacketAs(*packet_c))).Times(1); | 400 EXPECT_CALL(sink_a, OnRtpPacket(SamePacketAs(*packet_c))).Times(1); |
397 EXPECT_CALL(sink_b, OnRtpPacket(SamePacketAs(*packet_c))).Times(AtLeast(0)); | 401 EXPECT_CALL(sink_b, OnRtpPacket(SamePacketAs(*packet_c))).Times(AtLeast(0)); |
398 EXPECT_TRUE(demuxer.OnRtpPacket(*packet_c)); | 402 EXPECT_TRUE(demuxer.OnRtpPacket(*packet_c)); |
399 | 403 |
400 // Test tear-down | 404 // Test tear-down |
401 demuxer.RemoveSink(&sink_a); | 405 demuxer.RemoveSink(&sink_a); |
402 demuxer.RemoveSink(&sink_b); | 406 demuxer.RemoveSink(&sink_b); |
403 demuxer.RemoveSink(&sink_ignored); | 407 demuxer.RemoveSink(&sink_c); |
404 } | 408 } |
405 | 409 |
406 TEST(RtpDemuxerTest, MultipleRsidsOnSameSink) { | 410 TEST(RtpDemuxerTest, MultipleRsidsOnSameSink) { |
407 RtpDemuxer demuxer; | 411 RtpDemuxer demuxer; |
408 | 412 |
409 MockRtpPacketSink sink; | 413 MockRtpPacketSink sink; |
410 const std::string rsids[] = {"a", "b", "c"}; | 414 const std::string rsids[] = {"a", "b", "c"}; |
411 | 415 |
412 for (const std::string& rsid : rsids) { | 416 for (const std::string& rsid : rsids) { |
413 demuxer.AddSink(rsid, &sink); | 417 demuxer.AddSink(rsid, &sink); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
511 | 515 |
512 // The expected calls to OnRsidResolved() will be triggered by this. | 516 // The expected calls to OnRsidResolved() will be triggered by this. |
513 demuxer.OnRtpPacket(*CreateRtpPacketReceivedWithRsid(rsid, ssrc)); | 517 demuxer.OnRtpPacket(*CreateRtpPacketReceivedWithRsid(rsid, ssrc)); |
514 | 518 |
515 // Test tear-down | 519 // Test tear-down |
516 for (auto& observer : rsid_resolution_observers) { | 520 for (auto& observer : rsid_resolution_observers) { |
517 demuxer.DeregisterRsidResolutionObserver(&observer); | 521 demuxer.DeregisterRsidResolutionObserver(&observer); |
518 } | 522 } |
519 } | 523 } |
520 | 524 |
521 // Normally, we only produce one notification per resolution (though no such | |
522 // guarantee is made), but when a new observer is added, we reset | |
523 // this suppression - we "re-resolve" associations for the benefit of the | |
524 // new observer.. | |
525 TEST(RtpDemuxerTest, NotificationSuppressionResetWhenNewObserverAdded) { | |
526 RtpDemuxer demuxer; | |
527 | |
528 constexpr uint32_t ssrc = 111; | |
529 const std::string rsid = "a"; | |
530 | |
531 // First observer registered, then gets a notification. | |
532 NiceMock<MockRsidResolutionObserver> first_observer; | |
533 demuxer.RegisterRsidResolutionObserver(&first_observer); | |
534 demuxer.OnRtpPacket(*CreateRtpPacketReceivedWithRsid(rsid, ssrc)); | |
535 | |
536 // Second observer registered, then gets a notification. No guarantee is made | |
537 // about whether the first observer would get an additional notification. | |
538 MockRsidResolutionObserver second_observer; | |
539 demuxer.RegisterRsidResolutionObserver(&second_observer); | |
540 EXPECT_CALL(first_observer, OnRsidResolved(rsid, ssrc)).Times(AtLeast(0)); | |
541 EXPECT_CALL(second_observer, OnRsidResolved(rsid, ssrc)).Times(1); | |
542 demuxer.OnRtpPacket(*CreateRtpPacketReceivedWithRsid(rsid, ssrc)); | |
543 | |
544 // Test tear-down | |
545 demuxer.DeregisterRsidResolutionObserver(&first_observer); | |
546 demuxer.DeregisterRsidResolutionObserver(&second_observer); | |
547 } | |
548 | |
549 TEST(RtpDemuxerTest, DeregisteredRsidObserversNotInformedOfResolutions) { | 525 TEST(RtpDemuxerTest, DeregisteredRsidObserversNotInformedOfResolutions) { |
550 RtpDemuxer demuxer; | 526 RtpDemuxer demuxer; |
551 | 527 |
552 constexpr uint32_t ssrc = 111; | 528 constexpr uint32_t ssrc = 111; |
553 const std::string rsid = "a"; | 529 const std::string rsid = "a"; |
554 NiceMock<MockRtpPacketSink> sink; | 530 NiceMock<MockRtpPacketSink> sink; |
555 demuxer.AddSink(rsid, &sink); | 531 demuxer.AddSink(rsid, &sink); |
556 | 532 |
557 // Register several, then deregister only one, to show that not all of the | 533 // Register several, then deregister only one, to show that not all of the |
558 // observers had been forgotten when one was removed. | 534 // observers had been forgotten when one was removed. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 DregisterationOfNeverRegisteredRsidResolutionObserverDisallowed) { | 596 DregisterationOfNeverRegisteredRsidResolutionObserverDisallowed) { |
621 RtpDemuxer demuxer; | 597 RtpDemuxer demuxer; |
622 MockRsidResolutionObserver observer; | 598 MockRsidResolutionObserver observer; |
623 EXPECT_DEATH(demuxer.DeregisterRsidResolutionObserver(&observer), ""); | 599 EXPECT_DEATH(demuxer.DeregisterRsidResolutionObserver(&observer), ""); |
624 } | 600 } |
625 | 601 |
626 #endif | 602 #endif |
627 | 603 |
628 } // namespace | 604 } // namespace |
629 } // namespace webrtc | 605 } // namespace webrtc |
OLD | NEW |