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 <algorithm> | 11 #include <algorithm> |
12 #include <memory> | 12 #include <memory> |
13 | 13 |
14 #include "webrtc/base/basictypes.h" | 14 #include "webrtc/base/basictypes.h" |
15 #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" | 15 #include "webrtc/modules/rtp_rtcp/include/flexfec_receiver.h" |
16 #include "webrtc/modules/rtp_rtcp/mocks/mock_recovered_packet_receiver.h" | 16 #include "webrtc/modules/rtp_rtcp/mocks/mock_recovered_packet_receiver.h" |
17 #include "webrtc/modules/rtp_rtcp/source/fec_test_helper.h" | 17 #include "webrtc/modules/rtp_rtcp/source/fec_test_helper.h" |
18 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" | 18 #include "webrtc/modules/rtp_rtcp/source/forward_error_correction.h" |
19 #include "webrtc/modules/rtp_rtcp/source/rtp_packet_received.h" | |
20 #include "webrtc/test/gmock.h" | 19 #include "webrtc/test/gmock.h" |
21 #include "webrtc/test/gtest.h" | 20 #include "webrtc/test/gtest.h" |
22 | 21 |
23 namespace webrtc { | 22 namespace webrtc { |
24 | 23 |
25 namespace { | 24 namespace { |
26 | 25 |
27 using ::testing::_; | 26 using ::testing::_; |
28 using ::testing::Args; | 27 using ::testing::Args; |
29 using ::testing::ElementsAreArray; | 28 using ::testing::ElementsAreArray; |
30 using ::testing::Return; | 29 using ::testing::Return; |
31 | 30 |
32 using test::fec::FlexfecPacketGenerator; | 31 using test::fec::FlexfecPacketGenerator; |
33 using Packet = ForwardErrorCorrection::Packet; | 32 using Packet = ForwardErrorCorrection::Packet; |
34 using PacketList = ForwardErrorCorrection::PacketList; | 33 using PacketList = ForwardErrorCorrection::PacketList; |
35 | 34 |
36 constexpr size_t kPayloadLength = 500; | 35 constexpr size_t kPayloadLength = 500; |
37 constexpr uint32_t kFlexfecSsrc = 42984; | 36 constexpr uint32_t kFlexfecSsrc = 42984; |
38 constexpr uint32_t kMediaSsrc = 8353; | 37 constexpr uint32_t kMediaSsrc = 8353; |
39 | 38 |
40 RtpPacketReceived ParsePacket(const Packet& packet) { | |
41 RtpPacketReceived parsed_packet; | |
42 EXPECT_TRUE(parsed_packet.Parse(packet.data, packet.length)); | |
43 return parsed_packet; | |
44 } | |
45 | |
46 } // namespace | 39 } // namespace |
47 | 40 |
48 class FlexfecReceiverTest : public ::testing::Test { | 41 class FlexfecReceiverTest : public ::testing::Test { |
49 protected: | 42 protected: |
50 FlexfecReceiverTest() | 43 FlexfecReceiverTest() |
51 : receiver_(kFlexfecSsrc, kMediaSsrc, &recovered_packet_receiver_), | 44 : receiver_(kFlexfecSsrc, kMediaSsrc, &recovered_packet_receiver_), |
52 erasure_code_(ForwardErrorCorrection::CreateFlexfec()), | 45 erasure_code_(ForwardErrorCorrection::CreateFlexfec()), |
53 packet_generator_(kMediaSsrc, kFlexfecSsrc) {} | 46 packet_generator_(kMediaSsrc, kFlexfecSsrc) {} |
54 | 47 |
55 // Generates |num_media_packets| corresponding to a single frame. | 48 // Generates |num_media_packets| corresponding to a single frame. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 kUseUnequalProtection, kFecMaskType, &fec_packets)); | 86 kUseUnequalProtection, kFecMaskType, &fec_packets)); |
94 EXPECT_EQ(num_fec_packets, fec_packets.size()); | 87 EXPECT_EQ(num_fec_packets, fec_packets.size()); |
95 return fec_packets; | 88 return fec_packets; |
96 } | 89 } |
97 | 90 |
98 TEST_F(FlexfecReceiverTest, ReceivesMediaPacket) { | 91 TEST_F(FlexfecReceiverTest, ReceivesMediaPacket) { |
99 packet_generator_.NewFrame(1); | 92 packet_generator_.NewFrame(1); |
100 std::unique_ptr<Packet> media_packet( | 93 std::unique_ptr<Packet> media_packet( |
101 packet_generator_.NextPacket(0, kPayloadLength)); | 94 packet_generator_.NextPacket(0, kPayloadLength)); |
102 | 95 |
103 EXPECT_TRUE( | 96 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(media_packet->data, |
104 receiver_.AddAndProcessReceivedPacket(ParsePacket(*media_packet))); | 97 media_packet->length)); |
| 98 } |
| 99 |
| 100 TEST_F(FlexfecReceiverTest, FailsOnTruncatedMediaPacket) { |
| 101 const size_t kNoPayload = 0; |
| 102 |
| 103 packet_generator_.NewFrame(1); |
| 104 std::unique_ptr<Packet> media_packet( |
| 105 packet_generator_.NextPacket(0, kNoPayload)); |
| 106 // Simulate truncated media packet. |
| 107 media_packet->length = kRtpHeaderSize - 1; |
| 108 |
| 109 EXPECT_FALSE(receiver_.AddAndProcessReceivedPacket(media_packet->data, |
| 110 media_packet->length)); |
105 } | 111 } |
106 | 112 |
107 TEST_F(FlexfecReceiverTest, ReceivesMediaAndFecPackets) { | 113 TEST_F(FlexfecReceiverTest, ReceivesMediaAndFecPackets) { |
108 const size_t kNumMediaPackets = 1; | 114 const size_t kNumMediaPackets = 1; |
109 const size_t kNumFecPackets = 1; | 115 const size_t kNumFecPackets = 1; |
110 | 116 |
111 PacketList media_packets; | 117 PacketList media_packets; |
112 PacketizeFrame(kNumMediaPackets, 0, &media_packets); | 118 PacketizeFrame(kNumMediaPackets, 0, &media_packets); |
113 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); | 119 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); |
114 const auto& media_packet = media_packets.front(); | 120 auto media_packet = media_packets.front().get(); |
115 auto fec_packet = packet_generator_.BuildFlexfecPacket(*fec_packets.front()); | 121 auto fec_packet = packet_generator_.BuildFlexfecPacket(*fec_packets.front()); |
116 | 122 |
117 EXPECT_TRUE( | 123 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(media_packet->data, |
118 receiver_.AddAndProcessReceivedPacket(ParsePacket(*media_packet))); | 124 media_packet->length)); |
119 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(*fec_packet))); | 125 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(fec_packet->data, |
| 126 fec_packet->length)); |
120 } | 127 } |
121 | 128 |
122 TEST_F(FlexfecReceiverTest, FailsOnTruncatedFecPacket) { | 129 TEST_F(FlexfecReceiverTest, FailsOnTruncatedFecPacket) { |
123 const size_t kNumMediaPackets = 1; | 130 const size_t kNumMediaPackets = 1; |
124 const size_t kNumFecPackets = 1; | 131 const size_t kNumFecPackets = 1; |
125 | 132 |
126 PacketList media_packets; | 133 PacketList media_packets; |
127 PacketizeFrame(kNumMediaPackets, 0, &media_packets); | 134 PacketizeFrame(kNumMediaPackets, 0, &media_packets); |
128 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); | 135 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); |
129 const auto& media_packet = media_packets.front(); | 136 auto media_packet = media_packets.front().get(); |
130 // Simulate truncated FlexFEC payload. | 137 // Simulate truncated FlexFEC payload. |
131 fec_packets.front()->length = 1; | 138 fec_packets.front()->length = 1; |
132 auto fec_packet = packet_generator_.BuildFlexfecPacket(*fec_packets.front()); | 139 auto fec_packet = packet_generator_.BuildFlexfecPacket(*fec_packets.front()); |
133 | 140 |
134 EXPECT_TRUE( | 141 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(media_packet->data, |
135 receiver_.AddAndProcessReceivedPacket(ParsePacket(*media_packet))); | 142 media_packet->length)); |
136 EXPECT_FALSE(receiver_.AddAndProcessReceivedPacket(ParsePacket(*fec_packet))); | 143 EXPECT_FALSE(receiver_.AddAndProcessReceivedPacket(fec_packet->data, |
| 144 fec_packet->length)); |
137 } | 145 } |
138 | 146 |
139 TEST_F(FlexfecReceiverTest, FailsOnUnknownMediaSsrc) { | 147 TEST_F(FlexfecReceiverTest, FailsOnUnknownMediaSsrc) { |
140 const size_t kNumMediaPackets = 1; | 148 const size_t kNumMediaPackets = 1; |
141 | 149 |
142 PacketList media_packets; | 150 PacketList media_packets; |
143 PacketizeFrame(kNumMediaPackets, 0, &media_packets); | 151 PacketizeFrame(kNumMediaPackets, 0, &media_packets); |
144 auto& media_packet = media_packets.front(); | 152 auto media_packet = media_packets.front().get(); |
145 // Corrupt the SSRC. | 153 // Corrupt the SSRC. |
146 media_packet->data[8] = 0; | 154 media_packet->data[8] = 0; |
147 media_packet->data[9] = 1; | 155 media_packet->data[9] = 1; |
148 media_packet->data[10] = 2; | 156 media_packet->data[10] = 2; |
149 media_packet->data[11] = 3; | 157 media_packet->data[11] = 3; |
150 | 158 |
151 EXPECT_FALSE( | 159 EXPECT_FALSE(receiver_.AddAndProcessReceivedPacket(media_packet->data, |
152 receiver_.AddAndProcessReceivedPacket(ParsePacket(*media_packet))); | 160 media_packet->length)); |
153 } | 161 } |
154 | 162 |
155 TEST_F(FlexfecReceiverTest, FailsOnUnknownFecSsrc) { | 163 TEST_F(FlexfecReceiverTest, FailsOnUnknownFecSsrc) { |
156 const size_t kNumMediaPackets = 1; | 164 const size_t kNumMediaPackets = 1; |
157 const size_t kNumFecPackets = 1; | 165 const size_t kNumFecPackets = 1; |
158 | 166 |
159 PacketList media_packets; | 167 PacketList media_packets; |
160 PacketizeFrame(kNumMediaPackets, 0, &media_packets); | 168 PacketizeFrame(kNumMediaPackets, 0, &media_packets); |
161 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); | 169 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); |
162 const auto& media_packet = media_packets.front(); | 170 auto media_packet = media_packets.front().get(); |
163 auto fec_packet = packet_generator_.BuildFlexfecPacket(*fec_packets.front()); | 171 auto fec_packet = packet_generator_.BuildFlexfecPacket(*fec_packets.front()); |
164 // Corrupt the SSRC. | 172 // Corrupt the SSRC. |
165 fec_packet->data[8] = 4; | 173 fec_packet->data[8] = 4; |
166 fec_packet->data[9] = 5; | 174 fec_packet->data[9] = 5; |
167 fec_packet->data[10] = 6; | 175 fec_packet->data[10] = 6; |
168 fec_packet->data[11] = 7; | 176 fec_packet->data[11] = 7; |
169 | 177 |
170 EXPECT_TRUE( | 178 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(media_packet->data, |
171 receiver_.AddAndProcessReceivedPacket(ParsePacket(*media_packet))); | 179 media_packet->length)); |
172 EXPECT_FALSE(receiver_.AddAndProcessReceivedPacket(ParsePacket(*fec_packet))); | 180 EXPECT_FALSE(receiver_.AddAndProcessReceivedPacket(fec_packet->data, |
| 181 fec_packet->length)); |
173 } | 182 } |
174 | 183 |
175 TEST_F(FlexfecReceiverTest, ReceivesMultiplePackets) { | 184 TEST_F(FlexfecReceiverTest, ReceivesMultiplePackets) { |
176 const size_t kNumMediaPackets = 2; | 185 const size_t kNumMediaPackets = 2; |
177 const size_t kNumFecPackets = 1; | 186 const size_t kNumFecPackets = 1; |
178 | 187 |
179 PacketList media_packets; | 188 PacketList media_packets; |
180 PacketizeFrame(kNumMediaPackets, 0, &media_packets); | 189 PacketizeFrame(kNumMediaPackets, 0, &media_packets); |
181 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); | 190 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); |
182 | 191 |
183 // Receive all media packets. | 192 // Receive all media packets. |
184 for (const auto& media_packet : media_packets) { | 193 for (const auto& media_packet : media_packets) { |
185 EXPECT_TRUE( | 194 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(media_packet->data, |
186 receiver_.AddAndProcessReceivedPacket(ParsePacket(*media_packet))); | 195 media_packet->length)); |
187 } | 196 } |
188 | 197 |
189 // Receive FEC packet. | 198 // Receive FEC packet. |
190 auto fec_packet = fec_packets.front(); | 199 auto fec_packet = fec_packets.front(); |
191 std::unique_ptr<Packet> packet_with_rtp_header = | 200 std::unique_ptr<Packet> packet_with_rtp_header = |
192 packet_generator_.BuildFlexfecPacket(*fec_packet); | 201 packet_generator_.BuildFlexfecPacket(*fec_packet); |
193 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( | 202 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
194 ParsePacket(*packet_with_rtp_header))); | 203 packet_with_rtp_header->data, packet_with_rtp_header->length)); |
195 } | 204 } |
196 | 205 |
197 TEST_F(FlexfecReceiverTest, RecoversFromSingleMediaLoss) { | 206 TEST_F(FlexfecReceiverTest, RecoversFromSingleMediaLoss) { |
198 const size_t kNumMediaPackets = 2; | 207 const size_t kNumMediaPackets = 2; |
199 const size_t kNumFecPackets = 1; | 208 const size_t kNumFecPackets = 1; |
200 | 209 |
201 PacketList media_packets; | 210 PacketList media_packets; |
202 PacketizeFrame(kNumMediaPackets, 0, &media_packets); | 211 PacketizeFrame(kNumMediaPackets, 0, &media_packets); |
203 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); | 212 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); |
204 | 213 |
205 // Receive first media packet but drop second. | 214 // Receive first media packet but drop second. |
206 auto media_it = media_packets.begin(); | 215 auto media_it = media_packets.begin(); |
207 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_it))); | 216 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
| 217 (*media_it)->length)); |
208 | 218 |
209 // Receive FEC packet and ensure recovery of lost media packet. | 219 // Receive FEC packet and ensure recovery of lost media packet. |
210 auto fec_it = fec_packets.begin(); | 220 auto fec_it = fec_packets.begin(); |
211 std::unique_ptr<Packet> packet_with_rtp_header = | 221 std::unique_ptr<Packet> packet_with_rtp_header = |
212 packet_generator_.BuildFlexfecPacket(**fec_it); | 222 packet_generator_.BuildFlexfecPacket(**fec_it); |
213 media_it++; | 223 media_it++; |
214 EXPECT_CALL(recovered_packet_receiver_, | 224 EXPECT_CALL(recovered_packet_receiver_, |
215 OnRecoveredPacket(_, (*media_it)->length)) | 225 OnRecoveredPacket(_, (*media_it)->length)) |
216 .With( | 226 .With( |
217 Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) | 227 Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) |
218 .WillOnce(Return(true)); | 228 .WillOnce(Return(true)); |
219 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( | 229 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
220 ParsePacket(*packet_with_rtp_header))); | 230 packet_with_rtp_header->data, packet_with_rtp_header->length)); |
221 } | 231 } |
222 | 232 |
223 TEST_F(FlexfecReceiverTest, RecoversFromDoubleMediaLoss) { | 233 TEST_F(FlexfecReceiverTest, RecoversFromDoubleMediaLoss) { |
224 const size_t kNumMediaPackets = 2; | 234 const size_t kNumMediaPackets = 2; |
225 const size_t kNumFecPackets = 2; | 235 const size_t kNumFecPackets = 2; |
226 | 236 |
227 PacketList media_packets; | 237 PacketList media_packets; |
228 PacketizeFrame(kNumMediaPackets, 0, &media_packets); | 238 PacketizeFrame(kNumMediaPackets, 0, &media_packets); |
229 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); | 239 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); |
230 | 240 |
231 // Drop both media packets. | 241 // Drop both media packets. |
232 | 242 |
233 // Receive first FEC packet and recover first lost media packet. | 243 // Receive first FEC packet and recover first lost media packet. |
234 auto fec_it = fec_packets.begin(); | 244 auto fec_it = fec_packets.begin(); |
235 std::unique_ptr<Packet> packet_with_rtp_header = | 245 std::unique_ptr<Packet> packet_with_rtp_header = |
236 packet_generator_.BuildFlexfecPacket(**fec_it); | 246 packet_generator_.BuildFlexfecPacket(**fec_it); |
237 auto media_it = media_packets.begin(); | 247 auto media_it = media_packets.begin(); |
238 EXPECT_CALL(recovered_packet_receiver_, | 248 EXPECT_CALL(recovered_packet_receiver_, |
239 OnRecoveredPacket(_, (*media_it)->length)) | 249 OnRecoveredPacket(_, (*media_it)->length)) |
240 .With( | 250 .With( |
241 Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) | 251 Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) |
242 .WillOnce(Return(true)); | 252 .WillOnce(Return(true)); |
243 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( | 253 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
244 ParsePacket(*packet_with_rtp_header))); | 254 packet_with_rtp_header->data, packet_with_rtp_header->length)); |
245 | 255 |
246 // Receive second FEC packet and recover second lost media packet. | 256 // Receive second FEC packet and recover second lost media packet. |
247 fec_it++; | 257 fec_it++; |
248 packet_with_rtp_header = packet_generator_.BuildFlexfecPacket(**fec_it); | 258 packet_with_rtp_header = packet_generator_.BuildFlexfecPacket(**fec_it); |
249 media_it++; | 259 media_it++; |
250 EXPECT_CALL(recovered_packet_receiver_, | 260 EXPECT_CALL(recovered_packet_receiver_, |
251 OnRecoveredPacket(_, (*media_it)->length)) | 261 OnRecoveredPacket(_, (*media_it)->length)) |
252 .With( | 262 .With( |
253 Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) | 263 Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) |
254 .WillOnce(Return(true)); | 264 .WillOnce(Return(true)); |
255 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( | 265 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
256 ParsePacket(*packet_with_rtp_header))); | 266 packet_with_rtp_header->data, packet_with_rtp_header->length)); |
257 } | 267 } |
258 | 268 |
259 TEST_F(FlexfecReceiverTest, DoesNotRecoverFromMediaAndFecLoss) { | 269 TEST_F(FlexfecReceiverTest, DoesNotRecoverFromMediaAndFecLoss) { |
260 const size_t kNumMediaPackets = 2; | 270 const size_t kNumMediaPackets = 2; |
261 const size_t kNumFecPackets = 1; | 271 const size_t kNumFecPackets = 1; |
262 | 272 |
263 PacketList media_packets; | 273 PacketList media_packets; |
264 PacketizeFrame(kNumMediaPackets, 0, &media_packets); | 274 PacketizeFrame(kNumMediaPackets, 0, &media_packets); |
265 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); | 275 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); |
266 | 276 |
267 // Receive first media packet. | 277 // Receive first media packet. |
268 auto media_it = media_packets.begin(); | 278 auto media_it = media_packets.begin(); |
269 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_it))); | 279 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
| 280 (*media_it)->length)); |
270 | 281 |
271 // Drop second media packet and FEC packet. Do not expect call back. | 282 // Drop second media packet and FEC packet. Do not expect call back. |
272 } | 283 } |
273 | 284 |
274 TEST_F(FlexfecReceiverTest, DoesNotCallbackTwice) { | 285 TEST_F(FlexfecReceiverTest, DoesNotCallbackTwice) { |
275 const size_t kNumMediaPackets = 2; | 286 const size_t kNumMediaPackets = 2; |
276 const size_t kNumFecPackets = 1; | 287 const size_t kNumFecPackets = 1; |
277 | 288 |
278 PacketList media_packets; | 289 PacketList media_packets; |
279 PacketizeFrame(kNumMediaPackets, 0, &media_packets); | 290 PacketizeFrame(kNumMediaPackets, 0, &media_packets); |
280 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); | 291 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); |
281 | 292 |
282 // Receive first media packet but drop second. | 293 // Receive first media packet but drop second. |
283 auto media_it = media_packets.begin(); | 294 auto media_it = media_packets.begin(); |
284 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_it))); | 295 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
| 296 (*media_it)->length)); |
285 | 297 |
286 // Receive FEC packet and ensure recovery of lost media packet. | 298 // Receive FEC packet and ensure recovery of lost media packet. |
287 auto fec_it = fec_packets.begin(); | 299 auto fec_it = fec_packets.begin(); |
288 std::unique_ptr<Packet> packet_with_rtp_header = | 300 std::unique_ptr<Packet> packet_with_rtp_header = |
289 packet_generator_.BuildFlexfecPacket(**fec_it); | 301 packet_generator_.BuildFlexfecPacket(**fec_it); |
290 media_it++; | 302 media_it++; |
291 EXPECT_CALL(recovered_packet_receiver_, | 303 EXPECT_CALL(recovered_packet_receiver_, |
292 OnRecoveredPacket(_, (*media_it)->length)) | 304 OnRecoveredPacket(_, (*media_it)->length)) |
293 .With( | 305 .With( |
294 Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) | 306 Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) |
295 .WillOnce(Return(true)); | 307 .WillOnce(Return(true)); |
296 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( | 308 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
297 ParsePacket(*packet_with_rtp_header))); | 309 packet_with_rtp_header->data, packet_with_rtp_header->length)); |
298 | 310 |
299 // Receive FEC packet again. | 311 // Receive FEC packet again. |
300 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( | 312 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
301 ParsePacket(*packet_with_rtp_header))); | 313 packet_with_rtp_header->data, packet_with_rtp_header->length)); |
302 | 314 |
303 // Do not call back again. | 315 // Do not call back again. |
304 } | 316 } |
305 | 317 |
306 // Here we are implicitly assuming packet masks that are suitable for | 318 // Here we are implicitly assuming packet masks that are suitable for |
307 // this type of 50% correlated loss. If we are changing our precomputed | 319 // this type of 50% correlated loss. If we are changing our precomputed |
308 // packet masks, this test might need to be updated. | 320 // packet masks, this test might need to be updated. |
309 TEST_F(FlexfecReceiverTest, RecoversFrom50PercentLoss) { | 321 TEST_F(FlexfecReceiverTest, RecoversFrom50PercentLoss) { |
310 const size_t kNumFecPackets = 5; | 322 const size_t kNumFecPackets = 5; |
311 const size_t kNumFrames = 2 * kNumFecPackets; | 323 const size_t kNumFrames = 2 * kNumFecPackets; |
312 const size_t kNumMediaPacketsPerFrame = 1; | 324 const size_t kNumMediaPacketsPerFrame = 1; |
313 | 325 |
314 PacketList media_packets; | 326 PacketList media_packets; |
315 for (size_t i = 0; i < kNumFrames; ++i) { | 327 for (size_t i = 0; i < kNumFrames; ++i) { |
316 PacketizeFrame(kNumMediaPacketsPerFrame, i, &media_packets); | 328 PacketizeFrame(kNumMediaPacketsPerFrame, i, &media_packets); |
317 } | 329 } |
318 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); | 330 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); |
319 | 331 |
320 // Drop every second media packet. | 332 // Drop every second media packet. |
321 auto media_it = media_packets.begin(); | 333 auto media_it = media_packets.begin(); |
322 while (media_it != media_packets.end()) { | 334 while (media_it != media_packets.end()) { |
323 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_it))); | 335 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
| 336 (*media_it)->length)); |
324 ++media_it; | 337 ++media_it; |
325 if (media_it == media_packets.end()) { | 338 if (media_it == media_packets.end()) { |
326 break; | 339 break; |
327 } | 340 } |
328 ++media_it; | 341 ++media_it; |
329 } | 342 } |
330 | 343 |
331 // Receive all FEC packets. | 344 // Receive all FEC packets. |
332 media_it = media_packets.begin(); | 345 media_it = media_packets.begin(); |
333 for (const auto& fec_packet : fec_packets) { | 346 for (const auto& fec_packet : fec_packets) { |
334 std::unique_ptr<Packet> fec_packet_with_rtp_header = | 347 std::unique_ptr<Packet> fec_packet_with_rtp_header = |
335 packet_generator_.BuildFlexfecPacket(*fec_packet); | 348 packet_generator_.BuildFlexfecPacket(*fec_packet); |
336 ++media_it; | 349 ++media_it; |
337 if (media_it == media_packets.end()) { | 350 if (media_it == media_packets.end()) { |
338 break; | 351 break; |
339 } | 352 } |
340 EXPECT_CALL(recovered_packet_receiver_, | 353 EXPECT_CALL(recovered_packet_receiver_, |
341 OnRecoveredPacket(_, (*media_it)->length)) | 354 OnRecoveredPacket(_, (*media_it)->length)) |
342 .With(Args<0, 1>( | 355 .With(Args<0, 1>( |
343 ElementsAreArray((*media_it)->data, (*media_it)->length))) | 356 ElementsAreArray((*media_it)->data, (*media_it)->length))) |
344 .WillOnce(Return(true)); | 357 .WillOnce(Return(true)); |
345 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( | 358 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
346 ParsePacket(*fec_packet_with_rtp_header))); | 359 fec_packet_with_rtp_header->data, fec_packet_with_rtp_header->length)); |
347 ++media_it; | 360 ++media_it; |
348 } | 361 } |
349 } | 362 } |
350 | 363 |
351 TEST_F(FlexfecReceiverTest, DelayedFecPacketDoesHelp) { | 364 TEST_F(FlexfecReceiverTest, DelayedFecPacketDoesHelp) { |
352 // These values need to be updated if the underlying erasure code | 365 // These values need to be updated if the underlying erasure code |
353 // implementation changes. | 366 // implementation changes. |
354 const size_t kNumFrames = 48; | 367 const size_t kNumFrames = 48; |
355 const size_t kNumMediaPacketsPerFrame = 1; | 368 const size_t kNumMediaPacketsPerFrame = 1; |
356 const size_t kNumFecPackets = 1; | 369 const size_t kNumFecPackets = 1; |
357 | 370 |
358 PacketList media_packets; | 371 PacketList media_packets; |
359 PacketizeFrame(kNumMediaPacketsPerFrame, 0, &media_packets); | 372 PacketizeFrame(kNumMediaPacketsPerFrame, 0, &media_packets); |
360 PacketizeFrame(kNumMediaPacketsPerFrame, 1, &media_packets); | 373 PacketizeFrame(kNumMediaPacketsPerFrame, 1, &media_packets); |
361 // Protect two first frames. | 374 // Protect two first frames. |
362 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); | 375 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); |
363 for (size_t i = 2; i < kNumFrames; ++i) { | 376 for (size_t i = 2; i < kNumFrames; ++i) { |
364 PacketizeFrame(kNumMediaPacketsPerFrame, i, &media_packets); | 377 PacketizeFrame(kNumMediaPacketsPerFrame, i, &media_packets); |
365 } | 378 } |
366 | 379 |
367 // Drop first media packet and delay FEC packet. | 380 // Drop first media packet and delay FEC packet. |
368 auto media_it = media_packets.begin(); | 381 auto media_it = media_packets.begin(); |
369 ++media_it; | 382 ++media_it; |
370 | 383 |
371 // Receive all other media packets. | 384 // Receive all other media packets. |
372 while (media_it != media_packets.end()) { | 385 while (media_it != media_packets.end()) { |
373 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_it))); | 386 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
| 387 (*media_it)->length)); |
374 ++media_it; | 388 ++media_it; |
375 } | 389 } |
376 | 390 |
377 // Receive FEC packet and recover first media packet. | 391 // Receive FEC packet and recover first media packet. |
378 auto fec_it = fec_packets.begin(); | 392 auto fec_it = fec_packets.begin(); |
379 std::unique_ptr<Packet> packet_with_rtp_header = | 393 std::unique_ptr<Packet> packet_with_rtp_header = |
380 packet_generator_.BuildFlexfecPacket(**fec_it); | 394 packet_generator_.BuildFlexfecPacket(**fec_it); |
381 media_it = media_packets.begin(); | 395 media_it = media_packets.begin(); |
382 EXPECT_CALL(recovered_packet_receiver_, | 396 EXPECT_CALL(recovered_packet_receiver_, |
383 OnRecoveredPacket(_, (*media_it)->length)) | 397 OnRecoveredPacket(_, (*media_it)->length)) |
384 .With( | 398 .With( |
385 Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) | 399 Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) |
386 .WillOnce(Return(true)); | 400 .WillOnce(Return(true)); |
387 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( | 401 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
388 ParsePacket(*packet_with_rtp_header))); | 402 packet_with_rtp_header->data, packet_with_rtp_header->length)); |
389 } | 403 } |
390 | 404 |
391 TEST_F(FlexfecReceiverTest, TooDelayedFecPacketDoesNotHelp) { | 405 TEST_F(FlexfecReceiverTest, TooDelayedFecPacketDoesNotHelp) { |
392 // These values need to be updated if the underlying erasure code | 406 // These values need to be updated if the underlying erasure code |
393 // implementation changes. | 407 // implementation changes. |
394 const size_t kNumFrames = 49; | 408 const size_t kNumFrames = 49; |
395 const size_t kNumMediaPacketsPerFrame = 1; | 409 const size_t kNumMediaPacketsPerFrame = 1; |
396 const size_t kNumFecPackets = 1; | 410 const size_t kNumFecPackets = 1; |
397 | 411 |
398 PacketList media_packets; | 412 PacketList media_packets; |
399 PacketizeFrame(kNumMediaPacketsPerFrame, 0, &media_packets); | 413 PacketizeFrame(kNumMediaPacketsPerFrame, 0, &media_packets); |
400 PacketizeFrame(kNumMediaPacketsPerFrame, 1, &media_packets); | 414 PacketizeFrame(kNumMediaPacketsPerFrame, 1, &media_packets); |
401 // Protect two first frames. | 415 // Protect two first frames. |
402 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); | 416 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); |
403 for (size_t i = 2; i < kNumFrames; ++i) { | 417 for (size_t i = 2; i < kNumFrames; ++i) { |
404 PacketizeFrame(kNumMediaPacketsPerFrame, i, &media_packets); | 418 PacketizeFrame(kNumMediaPacketsPerFrame, i, &media_packets); |
405 } | 419 } |
406 | 420 |
407 // Drop first media packet and delay FEC packet. | 421 // Drop first media packet and delay FEC packet. |
408 auto media_it = media_packets.begin(); | 422 auto media_it = media_packets.begin(); |
409 ++media_it; | 423 ++media_it; |
410 | 424 |
411 // Receive all other media packets. | 425 // Receive all other media packets. |
412 while (media_it != media_packets.end()) { | 426 while (media_it != media_packets.end()) { |
413 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_it))); | 427 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
| 428 (*media_it)->length)); |
414 ++media_it; | 429 ++media_it; |
415 } | 430 } |
416 | 431 |
417 // Receive FEC packet. | 432 // Receive FEC packet. |
418 auto fec_it = fec_packets.begin(); | 433 auto fec_it = fec_packets.begin(); |
419 std::unique_ptr<Packet> packet_with_rtp_header = | 434 std::unique_ptr<Packet> packet_with_rtp_header = |
420 packet_generator_.BuildFlexfecPacket(**fec_it); | 435 packet_generator_.BuildFlexfecPacket(**fec_it); |
421 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( | 436 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
422 ParsePacket(*packet_with_rtp_header))); | 437 packet_with_rtp_header->data, packet_with_rtp_header->length)); |
423 | 438 |
424 // Do not expect a call back. | 439 // Do not expect a call back. |
425 } | 440 } |
426 | 441 |
427 TEST_F(FlexfecReceiverTest, RecoversWithMediaPacketsOutOfOrder) { | 442 TEST_F(FlexfecReceiverTest, RecoversWithMediaPacketsOutOfOrder) { |
428 const size_t kNumMediaPackets = 6; | 443 const size_t kNumMediaPackets = 6; |
429 const size_t kNumFecPackets = 2; | 444 const size_t kNumFecPackets = 2; |
430 | 445 |
431 PacketList media_packets; | 446 PacketList media_packets; |
432 PacketizeFrame(kNumMediaPackets, 0, &media_packets); | 447 PacketizeFrame(kNumMediaPackets, 0, &media_packets); |
433 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); | 448 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); |
434 | 449 |
435 // Lose two media packets, and receive the others out of order. | 450 // Lose two media packets, and receive the others out of order. |
436 auto media_it = media_packets.begin(); | 451 auto media_it = media_packets.begin(); |
437 auto media_packet0 = media_it++; | 452 auto media_packet0 = media_it++; |
438 auto media_packet1 = media_it++; | 453 auto media_packet1 = media_it++; |
439 auto media_packet2 = media_it++; | 454 auto media_packet2 = media_it++; |
440 auto media_packet3 = media_it++; | 455 auto media_packet3 = media_it++; |
441 auto media_packet4 = media_it++; | 456 auto media_packet4 = media_it++; |
442 auto media_packet5 = media_it++; | 457 auto media_packet5 = media_it++; |
443 EXPECT_TRUE( | 458 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_packet5)->data, |
444 receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_packet5))); | 459 (*media_packet5)->length)); |
445 EXPECT_TRUE( | 460 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_packet2)->data, |
446 receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_packet2))); | 461 (*media_packet2)->length)); |
447 EXPECT_TRUE( | 462 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_packet3)->data, |
448 receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_packet3))); | 463 (*media_packet3)->length)); |
449 EXPECT_TRUE( | 464 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_packet0)->data, |
450 receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_packet0))); | 465 (*media_packet0)->length)); |
451 | 466 |
452 // Expect to recover lost media packets. | 467 // Expect to recover lost media packets. |
453 EXPECT_CALL(recovered_packet_receiver_, | 468 EXPECT_CALL(recovered_packet_receiver_, |
454 OnRecoveredPacket(_, (*media_packet1)->length)) | 469 OnRecoveredPacket(_, (*media_packet1)->length)) |
455 .With(Args<0, 1>( | 470 .With(Args<0, 1>( |
456 ElementsAreArray((*media_packet1)->data, (*media_packet1)->length))) | 471 ElementsAreArray((*media_packet1)->data, (*media_packet1)->length))) |
457 .WillOnce(Return(true)); | 472 .WillOnce(Return(true)); |
458 EXPECT_CALL(recovered_packet_receiver_, | 473 EXPECT_CALL(recovered_packet_receiver_, |
459 OnRecoveredPacket(_, (*media_packet4)->length)) | 474 OnRecoveredPacket(_, (*media_packet4)->length)) |
460 .With(Args<0, 1>( | 475 .With(Args<0, 1>( |
461 ElementsAreArray((*media_packet4)->data, (*media_packet4)->length))) | 476 ElementsAreArray((*media_packet4)->data, (*media_packet4)->length))) |
462 .WillOnce(Return(true)); | 477 .WillOnce(Return(true)); |
463 | 478 |
464 // Add FEC packets. | 479 // Add FEC packets. |
465 auto fec_it = fec_packets.begin(); | 480 auto fec_it = fec_packets.begin(); |
466 std::unique_ptr<Packet> packet_with_rtp_header; | 481 std::unique_ptr<Packet> packet_with_rtp_header; |
467 while (fec_it != fec_packets.end()) { | 482 while (fec_it != fec_packets.end()) { |
468 packet_with_rtp_header = packet_generator_.BuildFlexfecPacket(**fec_it); | 483 packet_with_rtp_header = packet_generator_.BuildFlexfecPacket(**fec_it); |
469 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( | 484 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
470 ParsePacket(*packet_with_rtp_header))); | 485 packet_with_rtp_header->data, packet_with_rtp_header->length)); |
471 ++fec_it; | 486 ++fec_it; |
472 } | 487 } |
473 } | 488 } |
474 | 489 |
475 TEST_F(FlexfecReceiverTest, CalculatesNumberOfPackets) { | 490 TEST_F(FlexfecReceiverTest, CalculatesNumberOfPackets) { |
476 const size_t kNumMediaPackets = 2; | 491 const size_t kNumMediaPackets = 2; |
477 const size_t kNumFecPackets = 1; | 492 const size_t kNumFecPackets = 1; |
478 | 493 |
479 PacketList media_packets; | 494 PacketList media_packets; |
480 PacketizeFrame(kNumMediaPackets, 0, &media_packets); | 495 PacketizeFrame(kNumMediaPackets, 0, &media_packets); |
481 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); | 496 std::list<Packet*> fec_packets = EncodeFec(media_packets, kNumFecPackets); |
482 | 497 |
483 // Receive first media packet but drop second. | 498 // Receive first media packet but drop second. |
484 auto media_it = media_packets.begin(); | 499 auto media_it = media_packets.begin(); |
485 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket(ParsePacket(**media_it))); | 500 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket((*media_it)->data, |
| 501 (*media_it)->length)); |
486 | 502 |
487 // Receive FEC packet and ensure recovery of lost media packet. | 503 // Receive FEC packet and ensure recovery of lost media packet. |
488 auto fec_it = fec_packets.begin(); | 504 auto fec_it = fec_packets.begin(); |
489 std::unique_ptr<Packet> packet_with_rtp_header = | 505 std::unique_ptr<Packet> packet_with_rtp_header = |
490 packet_generator_.BuildFlexfecPacket(**fec_it); | 506 packet_generator_.BuildFlexfecPacket(**fec_it); |
491 media_it++; | 507 media_it++; |
492 EXPECT_CALL(recovered_packet_receiver_, | 508 EXPECT_CALL(recovered_packet_receiver_, |
493 OnRecoveredPacket(_, (*media_it)->length)) | 509 OnRecoveredPacket(_, (*media_it)->length)) |
494 .With( | 510 .With( |
495 Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) | 511 Args<0, 1>(ElementsAreArray((*media_it)->data, (*media_it)->length))) |
496 .WillOnce(Return(true)); | 512 .WillOnce(Return(true)); |
497 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( | 513 EXPECT_TRUE(receiver_.AddAndProcessReceivedPacket( |
498 ParsePacket(*packet_with_rtp_header))); | 514 packet_with_rtp_header->data, packet_with_rtp_header->length)); |
499 | 515 |
500 // Check stats calculations. | 516 // Check stats calculations. |
501 FecPacketCounter packet_counter = receiver_.GetPacketCounter(); | 517 FecPacketCounter packet_counter = receiver_.GetPacketCounter(); |
502 EXPECT_EQ(2U, packet_counter.num_packets); | 518 EXPECT_EQ(2U, packet_counter.num_packets); |
503 EXPECT_EQ(1U, packet_counter.num_fec_packets); | 519 EXPECT_EQ(1U, packet_counter.num_fec_packets); |
504 EXPECT_EQ(1U, packet_counter.num_recovered_packets); | 520 EXPECT_EQ(1U, packet_counter.num_recovered_packets); |
505 } | 521 } |
506 | 522 |
507 } // namespace webrtc | 523 } // namespace webrtc |
OLD | NEW |