OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
516 for (uint16_t byte_idx = 0; byte_idx < mask_size_bytes; ++byte_idx) { | 516 for (uint16_t byte_idx = 0; byte_idx < mask_size_bytes; ++byte_idx) { |
517 uint8_t packet_mask = fec_packet->pkt->data[12 + byte_idx]; | 517 uint8_t packet_mask = fec_packet->pkt->data[12 + byte_idx]; |
518 for (uint16_t bit_idx = 0; bit_idx < 8; ++bit_idx) { | 518 for (uint16_t bit_idx = 0; bit_idx < 8; ++bit_idx) { |
519 if (packet_mask & (1 << (7 - bit_idx))) { | 519 if (packet_mask & (1 << (7 - bit_idx))) { |
520 std::unique_ptr<ProtectedPacket> protected_packet( | 520 std::unique_ptr<ProtectedPacket> protected_packet( |
521 new ProtectedPacket()); | 521 new ProtectedPacket()); |
522 // This wraps naturally with the sequence number. | 522 // This wraps naturally with the sequence number. |
523 protected_packet->seq_num = | 523 protected_packet->seq_num = |
524 static_cast<uint16_t>(seq_num_base + (byte_idx << 3) + bit_idx); | 524 static_cast<uint16_t>(seq_num_base + (byte_idx << 3) + bit_idx); |
525 protected_packet->pkt = nullptr; | 525 protected_packet->pkt = nullptr; |
| 526 // Note that |protected_pkt_list| is sorted (according to sequence |
| 527 // number) by construction. |
526 fec_packet->protected_packets.push_back(std::move(protected_packet)); | 528 fec_packet->protected_packets.push_back(std::move(protected_packet)); |
527 } | 529 } |
528 } | 530 } |
529 } | 531 } |
530 if (fec_packet->protected_packets.empty()) { | 532 if (fec_packet->protected_packets.empty()) { |
531 // All-zero packet mask; we can discard this FEC packet. | 533 // All-zero packet mask; we can discard this FEC packet. |
532 LOG(LS_WARNING) << "Received FEC packet has an all-zero packet mask."; | 534 LOG(LS_WARNING) << "Received FEC packet has an all-zero packet mask."; |
533 } else { | 535 } else { |
534 AssignRecoveredPackets(fec_packet.get(), recovered_packets); | 536 AssignRecoveredPackets(fec_packet.get(), recovered_packets); |
535 // TODO(holmer): Consider replacing this with a binary search for the right | 537 // TODO(holmer): Consider replacing this with a binary search for the right |
536 // position, and then just insert the new packet. Would get rid of the sort. | 538 // position, and then just insert the new packet. Would get rid of the sort. |
| 539 // |
| 540 // For correct decoding, |fec_packet_list_| does not necessarily |
| 541 // need to be sorted by sequence number (see decoding algorithm in |
| 542 // AttemptRecover()), but by keeping it sorted we try to recover the |
| 543 // oldest lost packets first. |
537 received_fec_packets_.push_back(std::move(fec_packet)); | 544 received_fec_packets_.push_back(std::move(fec_packet)); |
538 received_fec_packets_.sort(SortablePacket::LessThan()); | 545 received_fec_packets_.sort(SortablePacket::LessThan()); |
539 if (received_fec_packets_.size() > kMaxFecPackets) { | 546 if (received_fec_packets_.size() > kMaxFecPackets) { |
540 received_fec_packets_.pop_front(); | 547 received_fec_packets_.pop_front(); |
541 } | 548 } |
542 RTC_DCHECK_LE(received_fec_packets_.size(), kMaxFecPackets); | 549 RTC_DCHECK_LE(received_fec_packets_.size(), kMaxFecPackets); |
543 } | 550 } |
544 } | 551 } |
545 | 552 |
546 void ForwardErrorCorrection::AssignRecoveredPackets( | 553 void ForwardErrorCorrection::AssignRecoveredPackets( |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
796 } | 803 } |
797 InsertPackets(received_packets, recovered_packets); | 804 InsertPackets(received_packets, recovered_packets); |
798 AttemptRecover(recovered_packets); | 805 AttemptRecover(recovered_packets); |
799 return 0; | 806 return 0; |
800 } | 807 } |
801 | 808 |
802 size_t ForwardErrorCorrection::PacketOverhead() { | 809 size_t ForwardErrorCorrection::PacketOverhead() { |
803 return kFecHeaderSize + kUlpHeaderSizeLBitSet; | 810 return kFecHeaderSize + kUlpHeaderSizeLBitSet; |
804 } | 811 } |
805 } // namespace webrtc | 812 } // namespace webrtc |
OLD | NEW |