Chromium Code Reviews| 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 586 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 597 const bool kUseUnequalProtection = false; | 597 const bool kUseUnequalProtection = false; |
| 598 const int kNumMediaPackets = 5; | 598 const int kNumMediaPackets = 5; |
| 599 uint8_t kProtectionFactor = 60; | 599 uint8_t kProtectionFactor = 60; |
| 600 | 600 |
| 601 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); | 601 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); |
| 602 | 602 |
| 603 // Create a new temporary packet list for generating FEC packets. | 603 // Create a new temporary packet list for generating FEC packets. |
| 604 // This list should have every other packet removed. | 604 // This list should have every other packet removed. |
| 605 PacketList protected_media_packets; | 605 PacketList protected_media_packets; |
| 606 int i = 0; | 606 int i = 0; |
| 607 for (PacketList::iterator it = media_packet_list_.begin(); | 607 for (auto it = media_packet_list_.begin(); it != media_packet_list_.end(); |
|
stefan-webrtc
2016/06/29 16:14:03
Should be able to change this to a range-based loo
brandtr
2016/06/30 13:37:43
See "1b" CL.
| |
| 608 it != media_packet_list_.end(); ++it, ++i) { | 608 ++it, ++i) { |
| 609 if (i % 2 == 0) protected_media_packets.push_back(*it); | 609 if (i % 2 == 0) protected_media_packets.push_back(*it); |
| 610 } | 610 } |
| 611 | 611 |
| 612 EXPECT_EQ(0, fec_->GenerateFEC(protected_media_packets, kProtectionFactor, | 612 EXPECT_EQ(0, fec_->GenerateFEC(protected_media_packets, kProtectionFactor, |
| 613 kNumImportantPackets, kUseUnequalProtection, | 613 kNumImportantPackets, kUseUnequalProtection, |
| 614 webrtc::kFecMaskBursty, &fec_packet_list_)); | 614 webrtc::kFecMaskBursty, &fec_packet_list_)); |
| 615 | 615 |
| 616 // Expect 1 FEC packet. | 616 // Expect 1 FEC packet. |
| 617 EXPECT_EQ(1, static_cast<int>(fec_packet_list_.size())); | 617 EXPECT_EQ(1, static_cast<int>(fec_packet_list_.size())); |
| 618 | 618 |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 661 const bool kUseUnequalProtection = false; | 661 const bool kUseUnequalProtection = false; |
| 662 const int kNumMediaPackets = 21; | 662 const int kNumMediaPackets = 21; |
| 663 uint8_t kProtectionFactor = 127; | 663 uint8_t kProtectionFactor = 127; |
| 664 | 664 |
| 665 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); | 665 fec_seq_num_ = ConstructMediaPackets(kNumMediaPackets); |
| 666 | 666 |
| 667 // Create a new temporary packet list for generating FEC packets. | 667 // Create a new temporary packet list for generating FEC packets. |
| 668 // This list should have every other packet removed. | 668 // This list should have every other packet removed. |
| 669 PacketList protected_media_packets; | 669 PacketList protected_media_packets; |
| 670 int i = 0; | 670 int i = 0; |
| 671 for (PacketList::iterator it = media_packet_list_.begin(); | 671 for (auto it = media_packet_list_.begin(); it != media_packet_list_.end(); |
| 672 it != media_packet_list_.end(); ++it, ++i) { | 672 ++it, ++i) { |
|
stefan-webrtc
2016/06/29 16:14:03
Same here
brandtr
2016/06/30 13:37:43
See "1b" CL.
| |
| 673 if (i % 2 == 0) protected_media_packets.push_back(*it); | 673 if (i % 2 == 0) protected_media_packets.push_back(*it); |
| 674 } | 674 } |
| 675 | 675 |
| 676 // Zero column insertion will have to extend the size of the packet | 676 // Zero column insertion will have to extend the size of the packet |
| 677 // mask since the number of actual packets are 21, while the number | 677 // mask since the number of actual packets are 21, while the number |
| 678 // of protected packets are 11. | 678 // of protected packets are 11. |
| 679 EXPECT_EQ(0, fec_->GenerateFEC(protected_media_packets, kProtectionFactor, | 679 EXPECT_EQ(0, fec_->GenerateFEC(protected_media_packets, kProtectionFactor, |
| 680 kNumImportantPackets, kUseUnequalProtection, | 680 kNumImportantPackets, kUseUnequalProtection, |
| 681 webrtc::kFecMaskBursty, &fec_packet_list_)); | 681 webrtc::kFecMaskBursty, &fec_packet_list_)); |
| 682 | 682 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 732 const bool kUseUnequalProtection = false; | 732 const bool kUseUnequalProtection = false; |
| 733 const int kNumMediaPackets = 21; | 733 const int kNumMediaPackets = 21; |
| 734 uint8_t kProtectionFactor = 127; | 734 uint8_t kProtectionFactor = 127; |
| 735 | 735 |
| 736 fec_seq_num_ = ConstructMediaPacketsSeqNum(kNumMediaPackets, 0xFFFF - 5); | 736 fec_seq_num_ = ConstructMediaPacketsSeqNum(kNumMediaPackets, 0xFFFF - 5); |
| 737 | 737 |
| 738 // Create a new temporary packet list for generating FEC packets. | 738 // Create a new temporary packet list for generating FEC packets. |
| 739 // This list should have every other packet removed. | 739 // This list should have every other packet removed. |
| 740 PacketList protected_media_packets; | 740 PacketList protected_media_packets; |
| 741 int i = 0; | 741 int i = 0; |
| 742 for (PacketList::iterator it = media_packet_list_.begin(); | 742 for (auto it = media_packet_list_.begin(); it != media_packet_list_.end(); |
| 743 it != media_packet_list_.end(); ++it, ++i) { | 743 ++it, ++i) { |
|
stefan-webrtc
2016/06/29 16:14:03
And here
brandtr
2016/06/30 13:37:43
See "1b" CL.
| |
| 744 if (i % 2 == 0) protected_media_packets.push_back(*it); | 744 if (i % 2 == 0) protected_media_packets.push_back(*it); |
| 745 } | 745 } |
| 746 | 746 |
| 747 // Zero column insertion will have to extend the size of the packet | 747 // Zero column insertion will have to extend the size of the packet |
| 748 // mask since the number of actual packets are 21, while the number | 748 // mask since the number of actual packets are 21, while the number |
| 749 // of protected packets are 11. | 749 // of protected packets are 11. |
| 750 EXPECT_EQ(0, fec_->GenerateFEC(protected_media_packets, kProtectionFactor, | 750 EXPECT_EQ(0, fec_->GenerateFEC(protected_media_packets, kProtectionFactor, |
| 751 kNumImportantPackets, kUseUnequalProtection, | 751 kNumImportantPackets, kUseUnequalProtection, |
| 752 webrtc::kFecMaskBursty, &fec_packet_list_)); | 752 webrtc::kFecMaskBursty, &fec_packet_list_)); |
| 753 | 753 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 814 // Check that the number of media and recovered packets are equal. | 814 // Check that the number of media and recovered packets are equal. |
| 815 if (media_packet_list_.size() != recovered_packet_list_.size()) { | 815 if (media_packet_list_.size() != recovered_packet_list_.size()) { |
| 816 return false; | 816 return false; |
| 817 } | 817 } |
| 818 | 818 |
| 819 ForwardErrorCorrection::Packet* media_packet; | 819 ForwardErrorCorrection::Packet* media_packet; |
| 820 ForwardErrorCorrection::RecoveredPacket* recovered_packet; | 820 ForwardErrorCorrection::RecoveredPacket* recovered_packet; |
| 821 | 821 |
| 822 bool recovery = true; | 822 bool recovery = true; |
| 823 | 823 |
| 824 PacketList::iterator media_packet_list_item = media_packet_list_.begin(); | 824 auto media_packet_list_it = media_packet_list_.cbegin(); |
| 825 RecoveredPacketList::iterator recovered_packet_list_item = | 825 auto recovered_packet_list_it = recovered_packet_list_.cbegin(); |
| 826 recovered_packet_list_.begin(); | 826 while (media_packet_list_it != media_packet_list_.end()) { |
|
stefan-webrtc
2016/06/29 16:14:03
Make this a range-based loop
brandtr
2016/06/30 13:37:43
Rewrote using std::equal and custom predicate inst
| |
| 827 while (media_packet_list_item != media_packet_list_.end()) { | 827 if (recovered_packet_list_it == recovered_packet_list_.end()) { |
| 828 if (recovered_packet_list_item == recovered_packet_list_.end()) { | |
| 829 return false; | 828 return false; |
| 830 } | 829 } |
| 831 media_packet = *media_packet_list_item; | 830 media_packet = *media_packet_list_it; |
| 832 recovered_packet = *recovered_packet_list_item; | 831 recovered_packet = *recovered_packet_list_it; |
| 833 if (recovered_packet->pkt->length != media_packet->length) { | 832 if (recovered_packet->pkt->length != media_packet->length) { |
| 834 return false; | 833 return false; |
| 835 } | 834 } |
| 836 if (memcmp(recovered_packet->pkt->data, media_packet->data, | 835 if (memcmp(recovered_packet->pkt->data, media_packet->data, |
| 837 media_packet->length) != 0) { | 836 media_packet->length) != 0) { |
| 838 return false; | 837 return false; |
| 839 } | 838 } |
| 840 media_packet_list_item++; | 839 media_packet_list_it++; |
| 841 recovered_packet_list_item++; | 840 recovered_packet_list_it++; |
| 842 } | 841 } |
| 843 return recovery; | 842 return recovery; |
| 844 } | 843 } |
| 845 | 844 |
| 846 void RtpFecTest::NetworkReceivedPackets() { | 845 void RtpFecTest::NetworkReceivedPackets() { |
| 847 const bool kFecPacket = true; | 846 const bool kFecPacket = true; |
| 848 ReceivedPackets(media_packet_list_, media_loss_mask_, !kFecPacket); | 847 ReceivedPackets(media_packet_list_, media_loss_mask_, !kFecPacket); |
| 849 ReceivedPackets(fec_packet_list_, fec_loss_mask_, kFecPacket); | 848 ReceivedPackets(fec_packet_list_, fec_loss_mask_, kFecPacket); |
| 850 } | 849 } |
| 851 | 850 |
| 852 void RtpFecTest::ReceivedPackets(const PacketList& packet_list, int* loss_mask, | 851 void RtpFecTest::ReceivedPackets(const PacketList& packet_list, int* loss_mask, |
| 853 bool is_fec) { | 852 bool is_fec) { |
| 854 ForwardErrorCorrection::Packet* packet; | 853 ForwardErrorCorrection::Packet* packet; |
| 855 ForwardErrorCorrection::ReceivedPacket* received_packet; | 854 ForwardErrorCorrection::ReceivedPacket* received_packet; |
| 856 int seq_num = fec_seq_num_; | 855 int seq_num = fec_seq_num_; |
| 857 int packet_idx = 0; | 856 int packet_idx = 0; |
| 858 | 857 |
| 859 PacketList::const_iterator packet_list_item = packet_list.begin(); | 858 auto packet_list_it = packet_list.cbegin(); |
| 860 | 859 while (packet_list_it != packet_list.end()) { |
|
stefan-webrtc
2016/06/29 16:14:03
and this, I think?
brandtr
2016/06/30 13:37:43
Done.
| |
| 861 while (packet_list_item != packet_list.end()) { | 860 packet = *packet_list_it; |
| 862 packet = *packet_list_item; | |
| 863 if (loss_mask[packet_idx] == 0) { | 861 if (loss_mask[packet_idx] == 0) { |
| 864 received_packet = new ForwardErrorCorrection::ReceivedPacket; | 862 received_packet = new ForwardErrorCorrection::ReceivedPacket; |
| 865 received_packet->pkt = new ForwardErrorCorrection::Packet; | 863 received_packet->pkt = new ForwardErrorCorrection::Packet; |
| 866 received_packet_list_.push_back(received_packet); | 864 received_packet_list_.push_back(received_packet); |
| 867 received_packet->pkt->length = packet->length; | 865 received_packet->pkt->length = packet->length; |
| 868 memcpy(received_packet->pkt->data, packet->data, packet->length); | 866 memcpy(received_packet->pkt->data, packet->data, packet->length); |
| 869 received_packet->is_fec = is_fec; | 867 received_packet->is_fec = is_fec; |
| 870 if (!is_fec) { | 868 if (!is_fec) { |
| 871 // For media packets, the sequence number and marker bit is | 869 // For media packets, the sequence number and marker bit is |
| 872 // obtained from RTP header. These were set in ConstructMediaPackets(). | 870 // obtained from RTP header. These were set in ConstructMediaPackets(). |
| 873 received_packet->seq_num = | 871 received_packet->seq_num = |
| 874 webrtc::ByteReader<uint16_t>::ReadBigEndian(&packet->data[2]); | 872 webrtc::ByteReader<uint16_t>::ReadBigEndian(&packet->data[2]); |
| 875 } else { | 873 } else { |
| 876 // The sequence number, marker bit, and ssrc number are defined in the | 874 // The sequence number, marker bit, and ssrc number are defined in the |
| 877 // RTP header of the FEC packet, which is not constructed in this test. | 875 // RTP header of the FEC packet, which is not constructed in this test. |
| 878 // So we set these values below based on the values generated in | 876 // So we set these values below based on the values generated in |
| 879 // ConstructMediaPackets(). | 877 // ConstructMediaPackets(). |
| 880 received_packet->seq_num = seq_num; | 878 received_packet->seq_num = seq_num; |
| 881 // The ssrc value for FEC packets is set to the one used for the | 879 // The ssrc value for FEC packets is set to the one used for the |
| 882 // media packets in ConstructMediaPackets(). | 880 // media packets in ConstructMediaPackets(). |
| 883 received_packet->ssrc = ssrc_; | 881 received_packet->ssrc = ssrc_; |
| 884 } | 882 } |
| 885 } | 883 } |
| 886 packet_idx++; | 884 packet_idx++; |
| 887 packet_list_item++; | 885 packet_list_it++; |
| 888 // Sequence number of FEC packets are defined as increment by 1 from | 886 // Sequence number of FEC packets are defined as increment by 1 from |
| 889 // last media packet in frame. | 887 // last media packet in frame. |
| 890 if (is_fec) seq_num++; | 888 if (is_fec) seq_num++; |
| 891 } | 889 } |
| 892 } | 890 } |
| 893 | 891 |
| 894 int RtpFecTest::ConstructMediaPacketsSeqNum(int num_media_packets, | 892 int RtpFecTest::ConstructMediaPacketsSeqNum(int num_media_packets, |
| 895 int start_seq_num) { | 893 int start_seq_num) { |
| 896 assert(num_media_packets > 0); | 894 RTC_DCHECK_GT(num_media_packets, 0); |
| 897 ForwardErrorCorrection::Packet* media_packet = NULL; | 895 ForwardErrorCorrection::Packet* media_packet = NULL; |
| 898 int sequence_number = start_seq_num; | 896 int sequence_number = start_seq_num; |
| 899 int time_stamp = random_.Rand<int>(); | 897 int time_stamp = random_.Rand<int>(); |
| 900 | 898 |
| 901 for (int i = 0; i < num_media_packets; ++i) { | 899 for (int i = 0; i < num_media_packets; ++i) { |
| 902 media_packet = new ForwardErrorCorrection::Packet; | 900 media_packet = new ForwardErrorCorrection::Packet; |
| 903 media_packet_list_.push_back(media_packet); | 901 media_packet_list_.push_back(media_packet); |
| 904 const uint32_t kMinPacketSize = kRtpHeaderSize; | 902 const uint32_t kMinPacketSize = kRtpHeaderSize; |
| 905 const uint32_t kMaxPacketSize = IP_PACKET_SIZE - kRtpHeaderSize - | 903 const uint32_t kMaxPacketSize = IP_PACKET_SIZE - kRtpHeaderSize - |
| 906 kTransportOverhead - | 904 kTransportOverhead - |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 930 time_stamp); | 928 time_stamp); |
| 931 webrtc::ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[8], ssrc_); | 929 webrtc::ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[8], ssrc_); |
| 932 | 930 |
| 933 // Generate random values for payload. | 931 // Generate random values for payload. |
| 934 for (size_t j = 12; j < media_packet->length; ++j) { | 932 for (size_t j = 12; j < media_packet->length; ++j) { |
| 935 media_packet->data[j] = random_.Rand<uint8_t>(); | 933 media_packet->data[j] = random_.Rand<uint8_t>(); |
| 936 } | 934 } |
| 937 sequence_number++; | 935 sequence_number++; |
| 938 } | 936 } |
| 939 // Last packet, set marker bit. | 937 // Last packet, set marker bit. |
| 940 assert(media_packet != NULL); | 938 RTC_DCHECK(media_packet); |
| 941 media_packet->data[1] |= 0x80; | 939 media_packet->data[1] |= 0x80; |
| 942 return sequence_number; | 940 return sequence_number; |
| 943 } | 941 } |
| 944 | 942 |
| 945 int RtpFecTest::ConstructMediaPackets(int num_media_packets) { | 943 int RtpFecTest::ConstructMediaPackets(int num_media_packets) { |
| 946 return ConstructMediaPacketsSeqNum(num_media_packets, random_.Rand<int>()); | 944 return ConstructMediaPacketsSeqNum(num_media_packets, random_.Rand<int>()); |
| 947 } | 945 } |
| OLD | NEW |