1 /*
2 * Copyright (c) 2019 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 #include "modules/congestion_controller/rtp/transport_feedback_demuxer.h"
11
12 #include "modules/rtp_rtcp/source/rtcp_packet/transport_feedback.h"
13 #include "test/gmock.h"
14 #include "test/gtest.h"
15
16 namespace webrtc {
17 namespace {
18
19 using ::testing::_;
20 static constexpr uint32_t kSsrc = 8492;
21
22 class MockStreamFeedbackObserver : public webrtc::StreamFeedbackObserver {
23 public:
24 MOCK_METHOD(void,
25 OnPacketFeedbackVector,
26 (std::vector<StreamPacketInfo> packet_feedback_vector),
27 (override));
28 };
29
CreatePacket(uint32_t ssrc,int16_t rtp_sequence_number,int64_t transport_sequence_number)30 RtpPacketSendInfo CreatePacket(uint32_t ssrc,
31 int16_t rtp_sequence_number,
32 int64_t transport_sequence_number) {
33 RtpPacketSendInfo res;
34 res.ssrc = ssrc;
35 res.transport_sequence_number = transport_sequence_number;
36 res.rtp_sequence_number = rtp_sequence_number;
37 return res;
38 }
39 } // namespace
TEST(TransportFeedbackDemuxerTest,ObserverSanity)40 TEST(TransportFeedbackDemuxerTest, ObserverSanity) {
41 TransportFeedbackDemuxer demuxer;
42 MockStreamFeedbackObserver mock;
43 demuxer.RegisterStreamFeedbackObserver({kSsrc}, &mock);
44
45 demuxer.AddPacket(CreatePacket(kSsrc, 55, 1));
46 demuxer.AddPacket(CreatePacket(kSsrc, 56, 2));
47 demuxer.AddPacket(CreatePacket(kSsrc, 57, 3));
48
49 rtcp::TransportFeedback feedback;
50 feedback.SetBase(1, 1000);
51 ASSERT_TRUE(feedback.AddReceivedPacket(1, 1000));
52 ASSERT_TRUE(feedback.AddReceivedPacket(2, 2000));
53 ASSERT_TRUE(feedback.AddReceivedPacket(3, 3000));
54
55 EXPECT_CALL(mock, OnPacketFeedbackVector(_)).Times(1);
56 demuxer.OnTransportFeedback(feedback);
57
58 demuxer.DeRegisterStreamFeedbackObserver(&mock);
59
60 demuxer.AddPacket(CreatePacket(kSsrc, 58, 4));
61 rtcp::TransportFeedback second_feedback;
62 second_feedback.SetBase(4, 4000);
63 ASSERT_TRUE(second_feedback.AddReceivedPacket(4, 4000));
64
65 EXPECT_CALL(mock, OnPacketFeedbackVector(_)).Times(0);
66 demuxer.OnTransportFeedback(second_feedback);
67 }
68 } // namespace webrtc
69