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