Move InsertZeroColumns and CopyColumn to ::internal.
These functions operate directly on the packet masks, and are thus not directly involved in the FEC encoding/decoding operation. The ::internal namespace is used for packet mask-related functions, and will be renamed later on. This CL should have no impact on functionality or performance. BUG=webrtc:5654 Review-Url: https://codereview.webrtc.org/2269893002 Cr-Commit-Position: refs/heads/master@{#13914}
This commit is contained in:
parent
7a770e0a61
commit
00e45bb09d
@ -306,10 +306,10 @@ int ForwardErrorCorrection::InsertZerosInBitMasks(
|
||||
++media_packets_it;
|
||||
|
||||
// Insert the first column.
|
||||
CopyColumn(tmp_packet_mask_, new_mask_bytes, packet_mask, num_mask_bytes,
|
||||
num_fec_packets, 0, 0);
|
||||
int new_bit_index = 1;
|
||||
int old_bit_index = 1;
|
||||
internal::CopyColumn(tmp_packet_mask_, new_mask_bytes, packet_mask_,
|
||||
num_mask_bytes, num_fec_packets, 0, 0);
|
||||
size_t new_bit_index = 1;
|
||||
size_t old_bit_index = 1;
|
||||
// Insert zeros in the bit mask for every hole in the sequence.
|
||||
while (media_packets_it != media_packets.end()) {
|
||||
if (new_bit_index == 8 * kMaskSizeLBitSet) {
|
||||
@ -317,15 +317,17 @@ int ForwardErrorCorrection::InsertZerosInBitMasks(
|
||||
break;
|
||||
}
|
||||
uint16_t seq_num = ParseSequenceNumber((*media_packets_it)->data);
|
||||
const int zeros_to_insert =
|
||||
const int num_zeros_to_insert =
|
||||
static_cast<uint16_t>(seq_num - prev_seq_num - 1);
|
||||
if (zeros_to_insert > 0) {
|
||||
InsertZeroColumns(zeros_to_insert, tmp_packet_mask_, new_mask_bytes,
|
||||
num_fec_packets, new_bit_index);
|
||||
if (num_zeros_to_insert > 0) {
|
||||
internal::InsertZeroColumns(num_zeros_to_insert, tmp_packet_mask_,
|
||||
new_mask_bytes, num_fec_packets,
|
||||
new_bit_index);
|
||||
}
|
||||
new_bit_index += zeros_to_insert;
|
||||
CopyColumn(tmp_packet_mask_, new_mask_bytes, packet_mask, num_mask_bytes,
|
||||
num_fec_packets, new_bit_index, old_bit_index);
|
||||
new_bit_index += num_zeros_to_insert;
|
||||
internal::CopyColumn(tmp_packet_mask_, new_mask_bytes, packet_mask_,
|
||||
num_mask_bytes, num_fec_packets, new_bit_index,
|
||||
old_bit_index);
|
||||
++new_bit_index;
|
||||
++old_bit_index;
|
||||
prev_seq_num = seq_num;
|
||||
@ -343,38 +345,6 @@ int ForwardErrorCorrection::InsertZerosInBitMasks(
|
||||
return new_bit_index;
|
||||
}
|
||||
|
||||
void ForwardErrorCorrection::InsertZeroColumns(int num_zeros,
|
||||
uint8_t* new_mask,
|
||||
int new_mask_bytes,
|
||||
int num_fec_packets,
|
||||
int new_bit_index) {
|
||||
for (uint16_t row = 0; row < num_fec_packets; ++row) {
|
||||
const int new_byte_index = row * new_mask_bytes + new_bit_index / 8;
|
||||
const int max_shifts = (7 - (new_bit_index % 8));
|
||||
new_mask[new_byte_index] <<= std::min(num_zeros, max_shifts);
|
||||
}
|
||||
}
|
||||
|
||||
void ForwardErrorCorrection::CopyColumn(uint8_t* new_mask,
|
||||
int new_mask_bytes,
|
||||
uint8_t* old_mask,
|
||||
int old_mask_bytes,
|
||||
int num_fec_packets,
|
||||
int new_bit_index,
|
||||
int old_bit_index) {
|
||||
// Copy column from the old mask to the beginning of the new mask and shift it
|
||||
// out from the old mask.
|
||||
for (uint16_t row = 0; row < num_fec_packets; ++row) {
|
||||
int new_byte_index = row * new_mask_bytes + new_bit_index / 8;
|
||||
int old_byte_index = row * old_mask_bytes + old_bit_index / 8;
|
||||
new_mask[new_byte_index] |= ((old_mask[old_byte_index] & 0x80) >> 7);
|
||||
if (new_bit_index % 8 != 7) {
|
||||
new_mask[new_byte_index] <<= 1;
|
||||
}
|
||||
old_mask[old_byte_index] <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
void ForwardErrorCorrection::GenerateFecUlpHeaders(
|
||||
const PacketList& media_packets,
|
||||
uint8_t* packet_mask,
|
||||
|
||||
@ -229,26 +229,6 @@ class ForwardErrorCorrection {
|
||||
uint8_t* packet_mask, int num_mask_bytes,
|
||||
int num_fec_packets);
|
||||
|
||||
// Inserts |num_zeros| zero columns into |new_mask| at position
|
||||
// |new_bit_index|. If the current byte of |new_mask| can't fit all zeros, the
|
||||
// byte will be filled with zeros from |new_bit_index|, but the next byte will
|
||||
// be untouched.
|
||||
static void InsertZeroColumns(int num_zeros, uint8_t* new_mask,
|
||||
int new_mask_bytes, int num_fec_packets,
|
||||
int new_bit_index);
|
||||
|
||||
// Copies the left most bit column from the byte pointed to by
|
||||
// |old_bit_index| in |old_mask| to the right most column of the byte pointed
|
||||
// to by |new_bit_index| in |new_mask|. |old_mask_bytes| and |new_mask_bytes|
|
||||
// represent the number of bytes used per row for each mask. |num_fec_packets|
|
||||
// represent the number of rows of the masks.
|
||||
// The copied bit is shifted out from |old_mask| and is shifted one step to
|
||||
// the left in |new_mask|. |new_mask| will contain "xxxx xxn0" after this
|
||||
// operation, where x are previously inserted bits and n is the new bit.
|
||||
static void CopyColumn(uint8_t* new_mask, int new_mask_bytes,
|
||||
uint8_t* old_mask, int old_mask_bytes,
|
||||
int num_fec_packets, int new_bit_index,
|
||||
int old_bit_index);
|
||||
|
||||
void GenerateFecUlpHeaders(const PacketList& media_packets,
|
||||
uint8_t* packet_mask, int num_fec_packets,
|
||||
|
||||
@ -13,6 +13,8 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "webrtc/modules/rtp_rtcp/source/fec_private_tables_bursty.h"
|
||||
#include "webrtc/modules/rtp_rtcp/source/fec_private_tables_random.h"
|
||||
|
||||
@ -392,5 +394,37 @@ void GeneratePacketMasks(int num_media_packets,
|
||||
} // End of UEP modification
|
||||
} // End of GetPacketMasks
|
||||
|
||||
void InsertZeroColumns(int num_zeros,
|
||||
uint8_t* new_mask,
|
||||
int new_mask_bytes,
|
||||
int num_fec_packets,
|
||||
int new_bit_index) {
|
||||
for (uint16_t row = 0; row < num_fec_packets; ++row) {
|
||||
const int new_byte_index = row * new_mask_bytes + new_bit_index / 8;
|
||||
const int max_shifts = (7 - (new_bit_index % 8));
|
||||
new_mask[new_byte_index] <<= std::min(num_zeros, max_shifts);
|
||||
}
|
||||
}
|
||||
|
||||
void CopyColumn(uint8_t* new_mask,
|
||||
int new_mask_bytes,
|
||||
uint8_t* old_mask,
|
||||
int old_mask_bytes,
|
||||
int num_fec_packets,
|
||||
int new_bit_index,
|
||||
int old_bit_index) {
|
||||
// Copy column from the old mask to the beginning of the new mask and shift it
|
||||
// out from the old mask.
|
||||
for (uint16_t row = 0; row < num_fec_packets; ++row) {
|
||||
int new_byte_index = row * new_mask_bytes + new_bit_index / 8;
|
||||
int old_byte_index = row * old_mask_bytes + old_bit_index / 8;
|
||||
new_mask[new_byte_index] |= ((old_mask[old_byte_index] & 0x80) >> 7);
|
||||
if (new_bit_index % 8 != 7) {
|
||||
new_mask[new_byte_index] <<= 1;
|
||||
}
|
||||
old_mask[old_byte_index] <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace webrtc
|
||||
|
||||
@ -65,6 +65,33 @@ void GeneratePacketMasks(int num_media_packets, int num_fec_packets,
|
||||
const PacketMaskTable& mask_table,
|
||||
uint8_t* packet_mask);
|
||||
|
||||
// Inserts |num_zeros| zero columns into |new_mask| at position
|
||||
// |new_bit_index|. If the current byte of |new_mask| can't fit all zeros, the
|
||||
// byte will be filled with zeros from |new_bit_index|, but the next byte will
|
||||
// be untouched.
|
||||
void InsertZeroColumns(int num_zeros,
|
||||
uint8_t* new_mask,
|
||||
int new_mask_bytes,
|
||||
int num_fec_packets,
|
||||
int new_bit_index);
|
||||
|
||||
// Copies the left most bit column from the byte pointed to by
|
||||
// |old_bit_index| in |old_mask| to the right most column of the byte pointed
|
||||
// to by |new_bit_index| in |new_mask|. |old_mask_bytes| and |new_mask_bytes|
|
||||
// represent the number of bytes used per row for each mask. |num_fec_packets|
|
||||
// represent the number of rows of the masks.
|
||||
// The copied bit is shifted out from |old_mask| and is shifted one step to
|
||||
// the left in |new_mask|. |new_mask| will contain "xxxx xxn0" after this
|
||||
// operation, where x are previously inserted bits and n is the new bit.
|
||||
void CopyColumn(uint8_t* new_mask,
|
||||
int new_mask_bytes,
|
||||
uint8_t* old_mask,
|
||||
int old_mask_bytes,
|
||||
int num_fec_packets,
|
||||
int new_bit_index,
|
||||
int old_bit_index);
|
||||
|
||||
} // namespace internal
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // WEBRTC_MODULES_RTP_RTCP_SOURCE_FORWARD_ERROR_CORRECTION_INTERNAL_H_
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user