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}
diff --git a/webrtc/modules/rtp_rtcp/source/forward_error_correction.cc b/webrtc/modules/rtp_rtcp/source/forward_error_correction.cc
index 6bc80e9..e666421 100644
--- a/webrtc/modules/rtp_rtcp/source/forward_error_correction.cc
+++ b/webrtc/modules/rtp_rtcp/source/forward_error_correction.cc
@@ -306,10 +306,10 @@
++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 @@
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 @@
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,
diff --git a/webrtc/modules/rtp_rtcp/source/forward_error_correction.h b/webrtc/modules/rtp_rtcp/source/forward_error_correction.h
index 57eec7a..ac2cfa7 100644
--- a/webrtc/modules/rtp_rtcp/source/forward_error_correction.h
+++ b/webrtc/modules/rtp_rtcp/source/forward_error_correction.h
@@ -229,26 +229,6 @@
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,
diff --git a/webrtc/modules/rtp_rtcp/source/forward_error_correction_internal.cc b/webrtc/modules/rtp_rtcp/source/forward_error_correction_internal.cc
index fae5907..790e705 100644
--- a/webrtc/modules/rtp_rtcp/source/forward_error_correction_internal.cc
+++ b/webrtc/modules/rtp_rtcp/source/forward_error_correction_internal.cc
@@ -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 @@
} // 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
diff --git a/webrtc/modules/rtp_rtcp/source/forward_error_correction_internal.h b/webrtc/modules/rtp_rtcp/source/forward_error_correction_internal.h
index 4811751..82f02c2 100644
--- a/webrtc/modules/rtp_rtcp/source/forward_error_correction_internal.h
+++ b/webrtc/modules/rtp_rtcp/source/forward_error_correction_internal.h
@@ -65,6 +65,33 @@
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_