| Index: webrtc/modules/rtp_rtcp/test/testFec/test_fec.cc
|
| diff --git a/webrtc/modules/rtp_rtcp/test/testFec/test_fec.cc b/webrtc/modules/rtp_rtcp/test/testFec/test_fec.cc
|
| index 0a1ae6272eda2cecf02a431418009ffde2930eb3..3e9a5989d608b151aff7fdeebc754a79ac438258 100644
|
| --- a/webrtc/modules/rtp_rtcp/test/testFec/test_fec.cc
|
| +++ b/webrtc/modules/rtp_rtcp/test/testFec/test_fec.cc
|
| @@ -13,9 +13,6 @@
|
| * functions in ForwardErrorCorrection directly.
|
| */
|
|
|
| -#include <assert.h>
|
| -#include <stdio.h>
|
| -#include <stdlib.h>
|
| #include <string.h>
|
| #include <time.h>
|
|
|
| @@ -38,46 +35,45 @@ namespace test {
|
| using fec_private_tables::kPacketMaskBurstyTbl;
|
|
|
| void ReceivePackets(
|
| - ForwardErrorCorrection::ReceivedPacketList* toDecodeList,
|
| - ForwardErrorCorrection::ReceivedPacketList* receivedPacketList,
|
| - size_t numPacketsToDecode,
|
| - float reorderRate,
|
| - float duplicateRate,
|
| + ForwardErrorCorrection::ReceivedPacketList* to_decode_list,
|
| + ForwardErrorCorrection::ReceivedPacketList* received_packet_list,
|
| + size_t num_packets_to_decode,
|
| + float reorder_rate,
|
| + float duplicate_rate,
|
| Random* random) {
|
| - assert(toDecodeList->empty());
|
| - assert(numPacketsToDecode <= receivedPacketList->size());
|
| + RTC_DCHECK(to_decode_list->empty());
|
| + RTC_DCHECK_LE(num_packets_to_decode, received_packet_list->size());
|
|
|
| - ForwardErrorCorrection::ReceivedPacketList::iterator it;
|
| - for (size_t i = 0; i < numPacketsToDecode; i++) {
|
| - it = receivedPacketList->begin();
|
| + for (size_t i = 0; i < num_packets_to_decode; i++) {
|
| + auto it = received_packet_list->begin();
|
| // Reorder packets.
|
| - float randomVariable = random->Rand<float>();
|
| - while (randomVariable < reorderRate) {
|
| + float random_variable = random->Rand<float>();
|
| + while (random_variable < reorder_rate) {
|
| ++it;
|
| - if (it == receivedPacketList->end()) {
|
| + if (it == received_packet_list->end()) {
|
| --it;
|
| break;
|
| }
|
| - randomVariable = random->Rand<float>();
|
| + random_variable = random->Rand<float>();
|
| }
|
| - ForwardErrorCorrection::ReceivedPacket* receivedPacket = *it;
|
| - toDecodeList->push_back(receivedPacket);
|
| + ForwardErrorCorrection::ReceivedPacket* received_packet = *it;
|
| + to_decode_list->push_back(received_packet);
|
|
|
| // Duplicate packets.
|
| - randomVariable = random->Rand<float>();
|
| - while (randomVariable < duplicateRate) {
|
| - ForwardErrorCorrection::ReceivedPacket* duplicatePacket =
|
| - new ForwardErrorCorrection::ReceivedPacket;
|
| - *duplicatePacket = *receivedPacket;
|
| - duplicatePacket->pkt = new ForwardErrorCorrection::Packet;
|
| - memcpy(duplicatePacket->pkt->data, receivedPacket->pkt->data,
|
| - receivedPacket->pkt->length);
|
| - duplicatePacket->pkt->length = receivedPacket->pkt->length;
|
| -
|
| - toDecodeList->push_back(duplicatePacket);
|
| - randomVariable = random->Rand<float>();
|
| + random_variable = random->Rand<float>();
|
| + while (random_variable < duplicate_rate) {
|
| + ForwardErrorCorrection::ReceivedPacket* duplicate_packet =
|
| + new ForwardErrorCorrection::ReceivedPacket();
|
| + *duplicate_packet = *received_packet;
|
| + duplicate_packet->pkt = new ForwardErrorCorrection::Packet();
|
| + memcpy(duplicate_packet->pkt->data, received_packet->pkt->data,
|
| + received_packet->pkt->length);
|
| + duplicate_packet->pkt->length = received_packet->pkt->length;
|
| +
|
| + to_decode_list->push_back(duplicate_packet);
|
| + random_variable = random->Rand<float>();
|
| }
|
| - receivedPacketList->erase(it);
|
| + received_packet_list->erase(it);
|
| }
|
| }
|
|
|
| @@ -111,94 +107,100 @@ TEST(FecTest, MAYBE_FecTest) {
|
| << "equal to 12.";
|
|
|
| ForwardErrorCorrection fec;
|
| - ForwardErrorCorrection::PacketList mediaPacketList;
|
| - ForwardErrorCorrection::PacketList fecPacketList;
|
| - ForwardErrorCorrection::ReceivedPacketList toDecodeList;
|
| - ForwardErrorCorrection::ReceivedPacketList receivedPacketList;
|
| - ForwardErrorCorrection::RecoveredPacketList recoveredPacketList;
|
| - std::list<uint8_t*> fecMaskList;
|
| -
|
| - ForwardErrorCorrection::Packet* mediaPacket = NULL;
|
| + ForwardErrorCorrection::PacketList media_packet_list;
|
| + ForwardErrorCorrection::PacketList fec_packet_list;
|
| + ForwardErrorCorrection::ReceivedPacketList to_decode_list;
|
| + ForwardErrorCorrection::ReceivedPacketList received_packet_list;
|
| + ForwardErrorCorrection::RecoveredPacketList recovered_packet_list;
|
| + std::list<uint8_t*> fec_mask_list;
|
| +
|
| + ForwardErrorCorrection::Packet* media_packet = nullptr;
|
| // Running over only one loss rate to limit execution time.
|
| - const float lossRate[] = {0.5f};
|
| - const uint32_t lossRateSize = sizeof(lossRate) / sizeof(*lossRate);
|
| - const float reorderRate = 0.1f;
|
| - const float duplicateRate = 0.1f;
|
| + const float loss_rate[] = {0.5f};
|
| + const uint32_t loss_rate_size = sizeof(loss_rate) / sizeof(*loss_rate);
|
| + const float reorder_rate = 0.1f;
|
| + const float duplicate_rate = 0.1f;
|
|
|
| - uint8_t mediaLossMask[kMaxNumberMediaPackets];
|
| - uint8_t fecLossMask[kMaxNumberFecPackets];
|
| - uint8_t fecPacketMasks[kMaxNumberFecPackets][kMaxNumberMediaPackets];
|
| + uint8_t media_loss_mask[kMaxNumberMediaPackets];
|
| + uint8_t fec_loss_mask[kMaxNumberFecPackets];
|
| + uint8_t fec_packet_masks[kMaxNumberFecPackets][kMaxNumberMediaPackets];
|
|
|
| // Seed the random number generator, storing the seed to file in order to
|
| // reproduce past results.
|
| - const unsigned int randomSeed = static_cast<unsigned int>(time(NULL));
|
| - Random random(randomSeed);
|
| + const unsigned int random_seed = static_cast<unsigned int>(time(nullptr));
|
| + Random random(random_seed);
|
| std::string filename = webrtc::test::OutputPath() + "randomSeedLog.txt";
|
| - FILE* randomSeedFile = fopen(filename.c_str(), "a");
|
| - fprintf(randomSeedFile, "%u\n", randomSeed);
|
| - fclose(randomSeedFile);
|
| - randomSeedFile = NULL;
|
| + FILE* random_seed_file = fopen(filename.c_str(), "a");
|
| + fprintf(random_seed_file, "%u\n", random_seed);
|
| + fclose(random_seed_file);
|
| + random_seed_file = nullptr;
|
|
|
| - uint16_t seqNum = 0;
|
| - uint32_t timeStamp = random.Rand<uint32_t>();
|
| + uint16_t seq_num = 0;
|
| + uint32_t timestamp = random.Rand<uint32_t>();
|
| const uint32_t ssrc = random.Rand(1u, 0xfffffffe);
|
|
|
| // Loop over the mask types: random and bursty.
|
| for (int mask_type_idx = 0; mask_type_idx < kNumFecMaskTypes;
|
| ++mask_type_idx) {
|
| - for (uint32_t lossRateIdx = 0; lossRateIdx < lossRateSize; ++lossRateIdx) {
|
| - printf("Loss rate: %.2f, Mask type %d \n", lossRate[lossRateIdx],
|
| + for (uint32_t loss_rate_idx = 0; loss_rate_idx < loss_rate_size;
|
| + ++loss_rate_idx) {
|
| + printf("Loss rate: %.2f, Mask type %d \n", loss_rate[loss_rate_idx],
|
| mask_type_idx);
|
|
|
| - const uint32_t packetMaskMax = kMaxMediaPackets[mask_type_idx];
|
| - uint8_t* packetMask = new uint8_t[packetMaskMax * kNumMaskBytesL1];
|
| + const uint32_t packet_mask_max = kMaxMediaPackets[mask_type_idx];
|
| + std::unique_ptr<uint8_t[]> packet_mask(
|
| + new uint8_t[packet_mask_max * kNumMaskBytesL1]);
|
|
|
| FecMaskType fec_mask_type = kMaskTypes[mask_type_idx];
|
|
|
| - for (uint32_t numMediaPackets = 1; numMediaPackets <= packetMaskMax;
|
| - numMediaPackets++) {
|
| - internal::PacketMaskTable mask_table(fec_mask_type, numMediaPackets);
|
| -
|
| - for (uint32_t numFecPackets = 1;
|
| - numFecPackets <= numMediaPackets && numFecPackets <= packetMaskMax;
|
| - numFecPackets++) {
|
| - // Loop over numImpPackets: usually <= (0.3*numMediaPackets).
|
| - // For this test we check up to ~ (numMediaPackets / 4).
|
| - uint32_t maxNumImpPackets = numMediaPackets / 4 + 1;
|
| - for (uint32_t numImpPackets = 0; numImpPackets <= maxNumImpPackets &&
|
| - numImpPackets <= packetMaskMax;
|
| - numImpPackets++) {
|
| - uint8_t protectionFactor =
|
| - static_cast<uint8_t>(numFecPackets * 255 / numMediaPackets);
|
| -
|
| - const uint32_t maskBytesPerFecPacket =
|
| - (numMediaPackets > 16) ? kNumMaskBytesL1 : kNumMaskBytesL0;
|
| -
|
| - memset(packetMask, 0, numMediaPackets * maskBytesPerFecPacket);
|
| + for (uint32_t num_media_packets = 1; num_media_packets <= packet_mask_max;
|
| + num_media_packets++) {
|
| + internal::PacketMaskTable mask_table(fec_mask_type, num_media_packets);
|
| +
|
| + for (uint32_t num_fec_packets = 1;
|
| + num_fec_packets <= num_media_packets &&
|
| + num_fec_packets <= packet_mask_max;
|
| + num_fec_packets++) {
|
| + // Loop over num_imp_packets: usually <= (0.3*num_media_packets).
|
| + // For this test we check up to ~ (num_media_packets / 4).
|
| + uint32_t max_num_imp_packets = num_media_packets / 4 + 1;
|
| + for (uint32_t num_imp_packets = 0;
|
| + num_imp_packets <= max_num_imp_packets &&
|
| + num_imp_packets <= packet_mask_max;
|
| + num_imp_packets++) {
|
| + uint8_t protection_factor =
|
| + static_cast<uint8_t>(num_fec_packets * 255 / num_media_packets);
|
| +
|
| + const uint32_t mask_bytes_per_fec_packet =
|
| + (num_media_packets > 16) ? kNumMaskBytesL1 : kNumMaskBytesL0;
|
| +
|
| + memset(packet_mask.get(), 0,
|
| + num_media_packets * mask_bytes_per_fec_packet);
|
|
|
| // Transfer packet masks from bit-mask to byte-mask.
|
| - internal::GeneratePacketMasks(numMediaPackets, numFecPackets,
|
| - numImpPackets, kUseUnequalProtection,
|
| - mask_table, packetMask);
|
| + internal::GeneratePacketMasks(num_media_packets, num_fec_packets,
|
| + num_imp_packets,
|
| + kUseUnequalProtection,
|
| + mask_table, packet_mask.get());
|
|
|
| #ifdef VERBOSE_OUTPUT
|
| printf(
|
| - "%u media packets, %u FEC packets, %u numImpPackets, "
|
| + "%u media packets, %u FEC packets, %u num_imp_packets, "
|
| "loss rate = %.2f \n",
|
| - numMediaPackets, numFecPackets, numImpPackets,
|
| - lossRate[lossRateIdx]);
|
| + num_media_packets, num_fec_packets, num_imp_packets,
|
| + loss_rate[loss_rate_idx]);
|
| printf("Packet mask matrix \n");
|
| #endif
|
|
|
| - for (uint32_t i = 0; i < numFecPackets; i++) {
|
| - for (uint32_t j = 0; j < numMediaPackets; j++) {
|
| - const uint8_t byteMask =
|
| - packetMask[i * maskBytesPerFecPacket + j / 8];
|
| - const uint32_t bitPosition = (7 - j % 8);
|
| - fecPacketMasks[i][j] =
|
| - (byteMask & (1 << bitPosition)) >> bitPosition;
|
| + for (uint32_t i = 0; i < num_fec_packets; i++) {
|
| + for (uint32_t j = 0; j < num_media_packets; j++) {
|
| + const uint8_t byte_mask =
|
| + packet_mask[i * mask_bytes_per_fec_packet + j / 8];
|
| + const uint32_t bit_position = (7 - j % 8);
|
| + fec_packet_masks[i][j] =
|
| + (byte_mask & (1 << bit_position)) >> bit_position;
|
| #ifdef VERBOSE_OUTPUT
|
| - printf("%u ", fecPacketMasks[i][j]);
|
| + printf("%u ", fec_packet_masks[i][j]);
|
| #endif
|
| }
|
| #ifdef VERBOSE_OUTPUT
|
| @@ -209,20 +211,20 @@ TEST(FecTest, MAYBE_FecTest) {
|
| printf("\n");
|
| #endif
|
| // Check for all zero rows or columns: indicates incorrect mask.
|
| - uint32_t rowLimit = numMediaPackets;
|
| - for (uint32_t i = 0; i < numFecPackets; ++i) {
|
| - uint32_t rowSum = 0;
|
| - for (uint32_t j = 0; j < rowLimit; ++j) {
|
| - rowSum += fecPacketMasks[i][j];
|
| + uint32_t row_limit = num_media_packets;
|
| + for (uint32_t i = 0; i < num_fec_packets; ++i) {
|
| + uint32_t row_sum = 0;
|
| + for (uint32_t j = 0; j < row_limit; ++j) {
|
| + row_sum += fec_packet_masks[i][j];
|
| }
|
| - ASSERT_NE(0u, rowSum) << "Row is all zero " << i;
|
| + ASSERT_NE(0u, row_sum) << "Row is all zero " << i;
|
| }
|
| - for (uint32_t j = 0; j < rowLimit; ++j) {
|
| - uint32_t columnSum = 0;
|
| - for (uint32_t i = 0; i < numFecPackets; ++i) {
|
| - columnSum += fecPacketMasks[i][j];
|
| + for (uint32_t j = 0; j < row_limit; ++j) {
|
| + uint32_t column_sum = 0;
|
| + for (uint32_t i = 0; i < num_fec_packets; ++i) {
|
| + column_sum += fec_packet_masks[i][j];
|
| }
|
| - ASSERT_NE(0u, columnSum) << "Column is all zero " << j;
|
| + ASSERT_NE(0u, column_sum) << "Column is all zero " << j;
|
| }
|
|
|
| // Construct media packets.
|
| @@ -230,19 +232,20 @@ TEST(FecTest, MAYBE_FecTest) {
|
| // below, to avoid sequence number wrap-around. In actual decoding,
|
| // old FEC packets in list are dropped if sequence number wrap
|
| // around is detected. This case is currently not handled below.
|
| - seqNum = 0;
|
| - for (uint32_t i = 0; i < numMediaPackets; ++i) {
|
| - mediaPacket = new ForwardErrorCorrection::Packet;
|
| - mediaPacketList.push_back(mediaPacket);
|
| + seq_num = 0;
|
| + for (uint32_t i = 0; i < num_media_packets; ++i) {
|
| + media_packet = new ForwardErrorCorrection::Packet();
|
| + media_packet_list.push_back(media_packet);
|
| const uint32_t kMinPacketSize = 12;
|
| const uint32_t kMaxPacketSize = static_cast<uint32_t>(
|
| IP_PACKET_SIZE - 12 - 28 -
|
| ForwardErrorCorrection::PacketOverhead());
|
| - mediaPacket->length = random.Rand(kMinPacketSize, kMaxPacketSize);
|
| + media_packet->length = random.Rand(kMinPacketSize,
|
| + kMaxPacketSize);
|
|
|
| // Generate random values for the first 2 bytes.
|
| - mediaPacket->data[0] = random.Rand<uint8_t>();
|
| - mediaPacket->data[1] = random.Rand<uint8_t>();
|
| + media_packet->data[0] = random.Rand<uint8_t>();
|
| + media_packet->data[1] = random.Rand<uint8_t>();
|
|
|
| // The first two bits are assumed to be 10 by the
|
| // FEC encoder. In fact the FEC decoder will set the
|
| @@ -250,237 +253,217 @@ TEST(FecTest, MAYBE_FecTest) {
|
| // actually were. Set the first two bits to 10
|
| // so that a memcmp can be performed for the
|
| // whole restored packet.
|
| - mediaPacket->data[0] |= 0x80;
|
| - mediaPacket->data[0] &= 0xbf;
|
| + media_packet->data[0] |= 0x80;
|
| + media_packet->data[0] &= 0xbf;
|
|
|
| // FEC is applied to a whole frame.
|
| // A frame is signaled by multiple packets without
|
| // the marker bit set followed by the last packet of
|
| // the frame for which the marker bit is set.
|
| // Only push one (fake) frame to the FEC.
|
| - mediaPacket->data[1] &= 0x7f;
|
| -
|
| - ByteWriter<uint16_t>::WriteBigEndian(&mediaPacket->data[2],
|
| - seqNum);
|
| - ByteWriter<uint32_t>::WriteBigEndian(&mediaPacket->data[4],
|
| - timeStamp);
|
| - ByteWriter<uint32_t>::WriteBigEndian(&mediaPacket->data[8], ssrc);
|
| + media_packet->data[1] &= 0x7f;
|
| +
|
| + ByteWriter<uint16_t>::WriteBigEndian(&media_packet->data[2],
|
| + seq_num);
|
| + ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[4],
|
| + timestamp);
|
| + ByteWriter<uint32_t>::WriteBigEndian(&media_packet->data[8],
|
| + ssrc);
|
| // Generate random values for payload
|
| - for (size_t j = 12; j < mediaPacket->length; ++j) {
|
| - mediaPacket->data[j] = random.Rand<uint8_t>();
|
| + for (size_t j = 12; j < media_packet->length; ++j) {
|
| + media_packet->data[j] = random.Rand<uint8_t>();
|
| }
|
| - seqNum++;
|
| + seq_num++;
|
| }
|
| - mediaPacket->data[1] |= 0x80;
|
| -
|
| - ASSERT_EQ(0, fec.GenerateFEC(mediaPacketList, protectionFactor,
|
| - numImpPackets, kUseUnequalProtection,
|
| - fec_mask_type, &fecPacketList))
|
| - << "GenerateFEC() failed";
|
| -
|
| - ASSERT_EQ(numFecPackets, fecPacketList.size())
|
| - << "We requested " << numFecPackets << " FEC packets, but "
|
| - << "GenerateFEC() produced " << fecPacketList.size();
|
| - memset(mediaLossMask, 0, sizeof(mediaLossMask));
|
| - ForwardErrorCorrection::PacketList::iterator mediaPacketListItem =
|
| - mediaPacketList.begin();
|
| - ForwardErrorCorrection::ReceivedPacket* receivedPacket;
|
| - uint32_t mediaPacketIdx = 0;
|
| -
|
| - while (mediaPacketListItem != mediaPacketList.end()) {
|
| - mediaPacket = *mediaPacketListItem;
|
| + media_packet->data[1] |= 0x80;
|
| +
|
| + ASSERT_EQ(0, fec.GenerateFec(media_packet_list, protection_factor,
|
| + num_imp_packets, kUseUnequalProtection,
|
| + fec_mask_type, &fec_packet_list))
|
| + << "GenerateFec() failed";
|
| +
|
| + ASSERT_EQ(num_fec_packets, fec_packet_list.size())
|
| + << "We requested " << num_fec_packets << " FEC packets, but "
|
| + << "GenerateFec() produced " << fec_packet_list.size();
|
| +
|
| + memset(media_loss_mask, 0, sizeof(media_loss_mask));
|
| + uint32_t media_packet_idx = 0;
|
| + for (auto* media_packet : media_packet_list) {
|
| // We want a value between 0 and 1.
|
| - const float lossRandomVariable = random.Rand<float>();
|
| -
|
| - if (lossRandomVariable >= lossRate[lossRateIdx]) {
|
| - mediaLossMask[mediaPacketIdx] = 1;
|
| - receivedPacket = new ForwardErrorCorrection::ReceivedPacket;
|
| - receivedPacket->pkt = new ForwardErrorCorrection::Packet;
|
| - receivedPacketList.push_back(receivedPacket);
|
| -
|
| - receivedPacket->pkt->length = mediaPacket->length;
|
| - memcpy(receivedPacket->pkt->data, mediaPacket->data,
|
| - mediaPacket->length);
|
| - receivedPacket->seq_num =
|
| - ByteReader<uint16_t>::ReadBigEndian(&mediaPacket->data[2]);
|
| - receivedPacket->is_fec = false;
|
| + const float loss_random_variable = random.Rand<float>();
|
| +
|
| + if (loss_random_variable >= loss_rate[loss_rate_idx]) {
|
| + media_loss_mask[media_packet_idx] = 1;
|
| + auto received_packet =
|
| + new ForwardErrorCorrection::ReceivedPacket();
|
| + received_packet->pkt = new ForwardErrorCorrection::Packet();
|
| + received_packet_list.push_back(received_packet);
|
| +
|
| + received_packet->pkt->length = media_packet->length;
|
| + memcpy(received_packet->pkt->data, media_packet->data,
|
| + media_packet->length);
|
| + received_packet->seq_num =
|
| + ByteReader<uint16_t>::ReadBigEndian(&media_packet->data[2]);
|
| + received_packet->is_fec = false;
|
| }
|
| - mediaPacketIdx++;
|
| - ++mediaPacketListItem;
|
| + media_packet_idx++;
|
| }
|
| - memset(fecLossMask, 0, sizeof(fecLossMask));
|
| - ForwardErrorCorrection::PacketList::iterator fecPacketListItem =
|
| - fecPacketList.begin();
|
| - ForwardErrorCorrection::Packet* fecPacket;
|
| - uint32_t fecPacketIdx = 0;
|
| - while (fecPacketListItem != fecPacketList.end()) {
|
| - fecPacket = *fecPacketListItem;
|
| - const float lossRandomVariable = random.Rand<float>();
|
| - if (lossRandomVariable >= lossRate[lossRateIdx]) {
|
| - fecLossMask[fecPacketIdx] = 1;
|
| - receivedPacket = new ForwardErrorCorrection::ReceivedPacket;
|
| - receivedPacket->pkt = new ForwardErrorCorrection::Packet;
|
| -
|
| - receivedPacketList.push_back(receivedPacket);
|
| -
|
| - receivedPacket->pkt->length = fecPacket->length;
|
| - memcpy(receivedPacket->pkt->data, fecPacket->data,
|
| - fecPacket->length);
|
| -
|
| - receivedPacket->seq_num = seqNum;
|
| - receivedPacket->is_fec = true;
|
| - receivedPacket->ssrc = ssrc;
|
| -
|
| - fecMaskList.push_back(fecPacketMasks[fecPacketIdx]);
|
| +
|
| + memset(fec_loss_mask, 0, sizeof(fec_loss_mask));
|
| + uint32_t fec_packet_idx = 0;
|
| + for (auto* fec_packet : fec_packet_list) {
|
| + const float loss_random_variable = random.Rand<float>();
|
| + if (loss_random_variable >= loss_rate[loss_rate_idx]) {
|
| + fec_loss_mask[fec_packet_idx] = 1;
|
| + auto received_packet =
|
| + new ForwardErrorCorrection::ReceivedPacket();
|
| + received_packet->pkt = new ForwardErrorCorrection::Packet();
|
| +
|
| + received_packet_list.push_back(received_packet);
|
| +
|
| + received_packet->pkt->length = fec_packet->length;
|
| + memcpy(received_packet->pkt->data, fec_packet->data,
|
| + fec_packet->length);
|
| +
|
| + received_packet->seq_num = seq_num;
|
| + received_packet->is_fec = true;
|
| + received_packet->ssrc = ssrc;
|
| +
|
| + fec_mask_list.push_back(fec_packet_masks[fec_packet_idx]);
|
| }
|
| - ++fecPacketIdx;
|
| - ++seqNum;
|
| - ++fecPacketListItem;
|
| + ++fec_packet_idx;
|
| + ++seq_num;
|
| }
|
|
|
| #ifdef VERBOSE_OUTPUT
|
| printf("Media loss mask:\n");
|
| - for (uint32_t i = 0; i < numMediaPackets; i++) {
|
| - printf("%u ", mediaLossMask[i]);
|
| + for (uint32_t i = 0; i < num_media_packets; i++) {
|
| + printf("%u ", media_loss_mask[i]);
|
| }
|
| printf("\n\n");
|
|
|
| printf("FEC loss mask:\n");
|
| - for (uint32_t i = 0; i < numFecPackets; i++) {
|
| - printf("%u ", fecLossMask[i]);
|
| + for (uint32_t i = 0; i < num_fec_packets; i++) {
|
| + printf("%u ", fec_loss_mask[i]);
|
| }
|
| printf("\n\n");
|
| #endif
|
|
|
| - std::list<uint8_t*>::iterator fecMaskIt = fecMaskList.begin();
|
| - uint8_t* fecMask;
|
| - while (fecMaskIt != fecMaskList.end()) {
|
| - fecMask = *fecMaskIt;
|
| - uint32_t hammingDist = 0;
|
| - uint32_t recoveryPosition = 0;
|
| - for (uint32_t i = 0; i < numMediaPackets; i++) {
|
| - if (mediaLossMask[i] == 0 && fecMask[i] == 1) {
|
| - recoveryPosition = i;
|
| - ++hammingDist;
|
| + auto fec_mask_it = fec_mask_list.begin();
|
| + while (fec_mask_it != fec_mask_list.end()) {
|
| + uint32_t hamming_dist = 0;
|
| + uint32_t recovery_position = 0;
|
| + for (uint32_t i = 0; i < num_media_packets; i++) {
|
| + if (media_loss_mask[i] == 0 && (*fec_mask_it)[i] == 1) {
|
| + recovery_position = i;
|
| + ++hamming_dist;
|
| }
|
| }
|
| - std::list<uint8_t*>::iterator itemToDelete = fecMaskIt;
|
| - ++fecMaskIt;
|
| + auto item_to_delete = fec_mask_it;
|
| + ++fec_mask_it;
|
|
|
| - if (hammingDist == 1) {
|
| + if (hamming_dist == 1) {
|
| // Recovery possible. Restart search.
|
| - mediaLossMask[recoveryPosition] = 1;
|
| - fecMaskIt = fecMaskList.begin();
|
| - } else if (hammingDist == 0) {
|
| + media_loss_mask[recovery_position] = 1;
|
| + fec_mask_it = fec_mask_list.begin();
|
| + } else if (hamming_dist == 0) {
|
| // FEC packet cannot provide further recovery.
|
| - fecMaskList.erase(itemToDelete);
|
| + fec_mask_list.erase(item_to_delete);
|
| }
|
| }
|
| #ifdef VERBOSE_OUTPUT
|
| printf("Recovery mask:\n");
|
| - for (uint32_t i = 0; i < numMediaPackets; ++i) {
|
| - printf("%u ", mediaLossMask[i]);
|
| + for (uint32_t i = 0; i < num_media_packets; ++i) {
|
| + printf("%u ", media_loss_mask[i]);
|
| }
|
| printf("\n\n");
|
| #endif
|
| // For error-checking frame completion.
|
| - bool fecPacketReceived = false;
|
| - while (!receivedPacketList.empty()) {
|
| - size_t numPacketsToDecode = random.Rand(
|
| - 1u, static_cast<uint32_t>(receivedPacketList.size()));
|
| - ReceivePackets(&toDecodeList, &receivedPacketList,
|
| - numPacketsToDecode, reorderRate, duplicateRate,
|
| - &random);
|
| -
|
| - if (fecPacketReceived == false) {
|
| - ForwardErrorCorrection::ReceivedPacketList::iterator
|
| - toDecodeIt = toDecodeList.begin();
|
| - while (toDecodeIt != toDecodeList.end()) {
|
| - receivedPacket = *toDecodeIt;
|
| - if (receivedPacket->is_fec) {
|
| - fecPacketReceived = true;
|
| + bool fec_packet_received = false;
|
| + while (!received_packet_list.empty()) {
|
| + size_t num_packets_to_decode = random.Rand(
|
| + 1u, static_cast<uint32_t>(received_packet_list.size()));
|
| + ReceivePackets(&to_decode_list, &received_packet_list,
|
| + num_packets_to_decode, reorder_rate,
|
| + duplicate_rate, &random);
|
| +
|
| + if (fec_packet_received == false) {
|
| + for (auto* received_packet : to_decode_list) {
|
| + if (received_packet->is_fec) {
|
| + fec_packet_received = true;
|
| }
|
| - ++toDecodeIt;
|
| }
|
| }
|
| - ASSERT_EQ(0, fec.DecodeFEC(&toDecodeList, &recoveredPacketList))
|
| - << "DecodeFEC() failed";
|
| - ASSERT_TRUE(toDecodeList.empty())
|
| + ASSERT_EQ(0, fec.DecodeFec(&to_decode_list,
|
| + &recovered_packet_list))
|
| + << "DecodeFec() failed";
|
| + ASSERT_TRUE(to_decode_list.empty())
|
| << "Received packet list is not empty.";
|
| }
|
| - mediaPacketListItem = mediaPacketList.begin();
|
| - mediaPacketIdx = 0;
|
| - while (mediaPacketListItem != mediaPacketList.end()) {
|
| - if (mediaLossMask[mediaPacketIdx] == 1) {
|
| + media_packet_idx = 0;
|
| + for (auto* media_packet : media_packet_list) {
|
| + if (media_loss_mask[media_packet_idx] == 1) {
|
| // Should have recovered this packet.
|
| - ForwardErrorCorrection::RecoveredPacketList::iterator
|
| - recoveredPacketListItem = recoveredPacketList.begin();
|
| + auto recovered_packet_list_it = recovered_packet_list.cbegin();
|
|
|
| - ASSERT_FALSE(recoveredPacketListItem ==
|
| - recoveredPacketList.end())
|
| + ASSERT_FALSE(recovered_packet_list_it ==
|
| + recovered_packet_list.end())
|
| << "Insufficient number of recovered packets.";
|
| - mediaPacket = *mediaPacketListItem;
|
| - ForwardErrorCorrection::RecoveredPacket* recoveredPacket =
|
| - *recoveredPacketListItem;
|
| + ForwardErrorCorrection::RecoveredPacket* recovered_packet =
|
| + *recovered_packet_list_it;
|
|
|
| - ASSERT_EQ(recoveredPacket->pkt->length, mediaPacket->length)
|
| + ASSERT_EQ(recovered_packet->pkt->length, media_packet->length)
|
| << "Recovered packet length not identical to original "
|
| << "media packet";
|
| - ASSERT_EQ(0, memcmp(recoveredPacket->pkt->data,
|
| - mediaPacket->data, mediaPacket->length))
|
| + ASSERT_EQ(0, memcmp(recovered_packet->pkt->data,
|
| + media_packet->data, media_packet->length))
|
| << "Recovered packet payload not identical to original "
|
| << "media packet";
|
| - delete recoveredPacket;
|
| - recoveredPacketList.pop_front();
|
| + delete recovered_packet;
|
| + recovered_packet_list.pop_front();
|
| }
|
| - ++mediaPacketIdx;
|
| - ++mediaPacketListItem;
|
| + ++media_packet_idx;
|
| }
|
| - fec.ResetState(&recoveredPacketList);
|
| - ASSERT_TRUE(recoveredPacketList.empty())
|
| + fec.ResetState(&recovered_packet_list);
|
| + ASSERT_TRUE(recovered_packet_list.empty())
|
| << "Excessive number of recovered packets.\t size is: "
|
| - << recoveredPacketList.size();
|
| + << recovered_packet_list.size();
|
| // -- Teardown --
|
| - mediaPacketListItem = mediaPacketList.begin();
|
| - while (mediaPacketListItem != mediaPacketList.end()) {
|
| - delete *mediaPacketListItem;
|
| - ++mediaPacketListItem;
|
| - mediaPacketList.pop_front();
|
| + auto media_packet_list_it = media_packet_list.begin();
|
| + while (media_packet_list_it != media_packet_list.end()) {
|
| + delete *media_packet_list_it;
|
| + ++media_packet_list_it;
|
| + media_packet_list.pop_front();
|
| }
|
| - assert(mediaPacketList.empty());
|
| + RTC_DCHECK(media_packet_list.empty());
|
|
|
| - fecPacketListItem = fecPacketList.begin();
|
| - while (fecPacketListItem != fecPacketList.end()) {
|
| - ++fecPacketListItem;
|
| - fecPacketList.pop_front();
|
| - }
|
| + // Clear FEC packet list, so we don't pass in a non-empty
|
| + // list in the next call to DecodeFec().
|
| + fec_packet_list.clear();
|
|
|
| - // Delete received packets we didn't pass to DecodeFEC(), due to
|
| + // Delete received packets we didn't pass to DecodeFec(), due to
|
| // early frame completion.
|
| - ForwardErrorCorrection::ReceivedPacketList::iterator
|
| - receivedPacketIt = receivedPacketList.begin();
|
| - while (receivedPacketIt != receivedPacketList.end()) {
|
| - receivedPacket = *receivedPacketIt;
|
| - delete receivedPacket;
|
| - ++receivedPacketIt;
|
| - receivedPacketList.pop_front();
|
| + auto received_packet_it = received_packet_list.cbegin();
|
| + while (received_packet_it != received_packet_list.end()) {
|
| + delete *received_packet_it;
|
| + ++received_packet_it;
|
| + received_packet_list.pop_front();
|
| }
|
| - assert(receivedPacketList.empty());
|
| + RTC_DCHECK(received_packet_list.empty());
|
|
|
| - while (!fecMaskList.empty()) {
|
| - fecMaskList.pop_front();
|
| + while (!fec_mask_list.empty()) {
|
| + fec_mask_list.pop_front();
|
| }
|
| - timeStamp += 90000 / 30;
|
| - } // loop over numImpPackets
|
| + timestamp += 90000 / 30;
|
| + } // loop over num_imp_packets
|
| } // loop over FecPackets
|
| - } // loop over numMediaPackets
|
| - delete[] packetMask;
|
| + } // loop over num_media_packets
|
| } // loop over loss rates
|
| } // loop over mask types
|
|
|
| - // Have DecodeFEC free allocated memory.
|
| - fec.ResetState(&recoveredPacketList);
|
| - ASSERT_TRUE(recoveredPacketList.empty())
|
| + // Have DecodeFec free allocated memory.
|
| + fec.ResetState(&recovered_packet_list);
|
| + ASSERT_TRUE(recovered_packet_list.empty())
|
| << "Recovered packet list is not empty";
|
| }
|
|
|
|
|