OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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 |
| 11 #include "webrtc/call/flexfec_receive_stream_impl.h" |
| 12 |
11 #include <stdint.h> | 13 #include <stdint.h> |
| 14 #include <memory> |
12 | 15 |
13 #include "webrtc/base/array_view.h" | 16 #include "webrtc/base/array_view.h" |
14 #include "webrtc/call/flexfec_receive_stream_impl.h" | |
15 #include "webrtc/call/rtp_stream_receiver_controller.h" | 17 #include "webrtc/call/rtp_stream_receiver_controller.h" |
16 #include "webrtc/modules/pacing/packet_router.h" | 18 #include "webrtc/modules/pacing/packet_router.h" |
17 #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" | 19 #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" |
18 #include "webrtc/modules/rtp_rtcp/mocks/mock_recovered_packet_receiver.h" | 20 #include "webrtc/modules/rtp_rtcp/mocks/mock_recovered_packet_receiver.h" |
19 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtcp_rtt_stats.h" | 21 #include "webrtc/modules/rtp_rtcp/mocks/mock_rtcp_rtt_stats.h" |
20 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" | 22 #include "webrtc/modules/rtp_rtcp/source/byte_io.h" |
21 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" | 23 #include "webrtc/modules/rtp_rtcp/source/rtp_header_extensions.h" |
22 #include "webrtc/modules/utility/include/mock/mock_process_thread.h" | 24 #include "webrtc/modules/utility/include/mock/mock_process_thread.h" |
| 25 #include "webrtc/rtc_base/ptr_util.h" |
23 #include "webrtc/test/gmock.h" | 26 #include "webrtc/test/gmock.h" |
24 #include "webrtc/test/gtest.h" | 27 #include "webrtc/test/gtest.h" |
25 #include "webrtc/test/mock_transport.h" | 28 #include "webrtc/test/mock_transport.h" |
26 | 29 |
27 namespace webrtc { | 30 namespace webrtc { |
28 | 31 |
29 namespace { | 32 namespace { |
30 | 33 |
| 34 using ::testing::_; |
| 35 |
31 constexpr uint8_t kFlexfecPlType = 118; | 36 constexpr uint8_t kFlexfecPlType = 118; |
32 constexpr uint8_t kFlexfecSsrc[] = {0x00, 0x00, 0x00, 0x01}; | 37 constexpr uint8_t kFlexfecSsrc[] = {0x00, 0x00, 0x00, 0x01}; |
33 constexpr uint8_t kMediaSsrc[] = {0x00, 0x00, 0x00, 0x02}; | 38 constexpr uint8_t kMediaSsrc[] = {0x00, 0x00, 0x00, 0x02}; |
34 | 39 |
35 FlexfecReceiveStream::Config CreateDefaultConfig( | 40 FlexfecReceiveStream::Config CreateDefaultConfig( |
36 Transport* rtcp_send_transport) { | 41 Transport* rtcp_send_transport) { |
37 FlexfecReceiveStream::Config config(rtcp_send_transport); | 42 FlexfecReceiveStream::Config config(rtcp_send_transport); |
38 config.payload_type = kFlexfecPlType; | 43 config.payload_type = kFlexfecPlType; |
39 config.remote_ssrc = ByteReader<uint32_t>::ReadBigEndian(kFlexfecSsrc); | 44 config.remote_ssrc = ByteReader<uint32_t>::ReadBigEndian(kFlexfecSsrc); |
40 config.protected_media_ssrcs = { | 45 config.protected_media_ssrcs = { |
(...skipping 29 matching lines...) Expand all Loading... |
70 config.protected_media_ssrcs.push_back(138989393); | 75 config.protected_media_ssrcs.push_back(138989393); |
71 EXPECT_TRUE(config.IsCompleteAndEnabled()); | 76 EXPECT_TRUE(config.IsCompleteAndEnabled()); |
72 | 77 |
73 config.protected_media_ssrcs.push_back(33423423); | 78 config.protected_media_ssrcs.push_back(33423423); |
74 EXPECT_FALSE(config.IsCompleteAndEnabled()); | 79 EXPECT_FALSE(config.IsCompleteAndEnabled()); |
75 } | 80 } |
76 | 81 |
77 class FlexfecReceiveStreamTest : public ::testing::Test { | 82 class FlexfecReceiveStreamTest : public ::testing::Test { |
78 protected: | 83 protected: |
79 FlexfecReceiveStreamTest() | 84 FlexfecReceiveStreamTest() |
80 : config_(CreateDefaultConfig(&rtcp_send_transport_)), | 85 : config_(CreateDefaultConfig(&rtcp_send_transport_)) { |
81 receive_stream_(&rtp_stream_receiver_controller_, | 86 EXPECT_CALL(process_thread_, RegisterModule(_, _)).Times(1); |
82 config_, | 87 receive_stream_ = rtc::MakeUnique<FlexfecReceiveStreamImpl>( |
83 &recovered_packet_receiver_, | 88 &rtp_stream_receiver_controller_, config_, &recovered_packet_receiver_, |
84 &rtt_stats_, | 89 &rtt_stats_, &process_thread_); |
85 &process_thread_) {} | 90 } |
| 91 |
| 92 ~FlexfecReceiveStreamTest() { |
| 93 EXPECT_CALL(process_thread_, DeRegisterModule(_)).Times(1); |
| 94 } |
86 | 95 |
87 MockTransport rtcp_send_transport_; | 96 MockTransport rtcp_send_transport_; |
88 FlexfecReceiveStream::Config config_; | 97 FlexfecReceiveStream::Config config_; |
89 MockRecoveredPacketReceiver recovered_packet_receiver_; | 98 MockRecoveredPacketReceiver recovered_packet_receiver_; |
90 MockRtcpRttStats rtt_stats_; | 99 MockRtcpRttStats rtt_stats_; |
91 MockProcessThread process_thread_; | 100 MockProcessThread process_thread_; |
92 RtpStreamReceiverController rtp_stream_receiver_controller_; | 101 RtpStreamReceiverController rtp_stream_receiver_controller_; |
93 FlexfecReceiveStreamImpl receive_stream_; | 102 std::unique_ptr<FlexfecReceiveStreamImpl> receive_stream_; |
94 }; | 103 }; |
95 | 104 |
96 TEST_F(FlexfecReceiveStreamTest, ConstructDestruct) {} | 105 TEST_F(FlexfecReceiveStreamTest, ConstructDestruct) {} |
97 | 106 |
98 TEST_F(FlexfecReceiveStreamTest, StartStop) { | 107 TEST_F(FlexfecReceiveStreamTest, StartStop) { |
99 receive_stream_.Start(); | 108 receive_stream_->Start(); |
100 receive_stream_.Stop(); | 109 receive_stream_->Stop(); |
101 } | 110 } |
102 | 111 |
103 // Create a FlexFEC packet that protects a single media packet and ensure | 112 // Create a FlexFEC packet that protects a single media packet and ensure |
104 // that the callback is called. Correctness of recovery is checked in the | 113 // that the callback is called. Correctness of recovery is checked in the |
105 // FlexfecReceiver unit tests. | 114 // FlexfecReceiver unit tests. |
106 TEST_F(FlexfecReceiveStreamTest, RecoversPacketWhenStarted) { | 115 TEST_F(FlexfecReceiveStreamTest, RecoversPacketWhenStarted) { |
107 constexpr uint8_t kFlexfecSeqNum[] = {0x00, 0x01}; | 116 constexpr uint8_t kFlexfecSeqNum[] = {0x00, 0x01}; |
108 constexpr uint8_t kFlexfecTs[] = {0x00, 0x11, 0x22, 0x33}; | 117 constexpr uint8_t kFlexfecTs[] = {0x00, 0x11, 0x22, 0x33}; |
109 constexpr uint8_t kMediaPlType = 107; | 118 constexpr uint8_t kMediaPlType = 107; |
110 constexpr uint8_t kMediaSeqNum[] = {0x00, 0x02}; | 119 constexpr uint8_t kMediaSeqNum[] = {0x00, 0x02}; |
(...skipping 18 matching lines...) Expand all Loading... |
129 0x00, kMediaPlType, kPayloadLength[0], kPayloadLength[1], | 138 0x00, kMediaPlType, kPayloadLength[0], kPayloadLength[1], |
130 kMediaTs[0], kMediaTs[1], kMediaTs[2], kMediaTs[3], | 139 kMediaTs[0], kMediaTs[1], kMediaTs[2], kMediaTs[3], |
131 kSsrcCount, kReservedBits, kReservedBits, kReservedBits, | 140 kSsrcCount, kReservedBits, kReservedBits, kReservedBits, |
132 kMediaSsrc[0], kMediaSsrc[1], kMediaSsrc[2], kMediaSsrc[3], | 141 kMediaSsrc[0], kMediaSsrc[1], kMediaSsrc[2], kMediaSsrc[3], |
133 kMediaSeqNum[0], kMediaSeqNum[1], kFlexfecPktMask[0], kFlexfecPktMask[1], | 142 kMediaSeqNum[0], kMediaSeqNum[1], kFlexfecPktMask[0], kFlexfecPktMask[1], |
134 // FEC payload. | 143 // FEC payload. |
135 kPayloadBits, kPayloadBits, kPayloadBits, kPayloadBits}; | 144 kPayloadBits, kPayloadBits, kPayloadBits, kPayloadBits}; |
136 // clang-format on | 145 // clang-format on |
137 | 146 |
138 testing::StrictMock<MockRecoveredPacketReceiver> recovered_packet_receiver; | 147 testing::StrictMock<MockRecoveredPacketReceiver> recovered_packet_receiver; |
| 148 EXPECT_CALL(process_thread_, RegisterModule(_, _)).Times(1); |
139 FlexfecReceiveStreamImpl receive_stream(&rtp_stream_receiver_controller_, | 149 FlexfecReceiveStreamImpl receive_stream(&rtp_stream_receiver_controller_, |
140 config_, &recovered_packet_receiver, | 150 config_, &recovered_packet_receiver, |
141 &rtt_stats_, &process_thread_); | 151 &rtt_stats_, &process_thread_); |
142 | 152 |
143 // Do not call back before being started. | 153 // Do not call back before being started. |
144 receive_stream.OnRtpPacket(ParsePacket(kFlexfecPacket)); | 154 receive_stream.OnRtpPacket(ParsePacket(kFlexfecPacket)); |
145 | 155 |
146 // Call back after being started. | 156 // Call back after being started. |
147 receive_stream.Start(); | 157 receive_stream.Start(); |
148 EXPECT_CALL( | 158 EXPECT_CALL(recovered_packet_receiver, |
149 recovered_packet_receiver, | 159 OnRecoveredPacket(_, kRtpHeaderSize + kPayloadLength[1])); |
150 OnRecoveredPacket(::testing::_, kRtpHeaderSize + kPayloadLength[1])); | |
151 receive_stream.OnRtpPacket(ParsePacket(kFlexfecPacket)); | 160 receive_stream.OnRtpPacket(ParsePacket(kFlexfecPacket)); |
| 161 |
| 162 // Tear-down |
| 163 EXPECT_CALL(process_thread_, DeRegisterModule(_)).Times(1); |
152 } | 164 } |
153 | 165 |
154 } // namespace webrtc | 166 } // namespace webrtc |
OLD | NEW |