Remove WebRtc_ types.

Allows us to avoid the "cast to UWord32" Coverity coverup.

BUG=
TEST=test_fec

Review URL: https://webrtc-codereview.appspot.com/379002

git-svn-id: http://webrtc.googlecode.com/svn/trunk@1647 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
andrew@webrtc.org 2012-02-08 22:24:14 +00:00
parent 454a27c13d
commit 68da6adafe
3 changed files with 72 additions and 76 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
* *
* Use of this source code is governed by a BSD-style license * Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source * that can be found in the LICENSE file in the root of the source

View File

@ -38,25 +38,23 @@ enum ProtectionMode
* \param[out] packetMask A pointer to hold the output mask, of size * \param[out] packetMask A pointer to hold the output mask, of size
* [0, x * numMaskBytes], where x >= numRows. * [0, x * numMaskBytes], where x >= numRows.
*/ */
void FitSubMask(WebRtc_UWord16 numMaskBytes, void FitSubMask(int numMaskBytes,
WebRtc_UWord16 numSubMaskBytes, int numSubMaskBytes,
WebRtc_UWord16 numRows, int numRows,
const WebRtc_UWord8* subMask, const uint8_t* subMask,
WebRtc_UWord8* packetMask) uint8_t* packetMask)
{ {
if (numMaskBytes == numSubMaskBytes) if (numMaskBytes == numSubMaskBytes)
{ {
memcpy(packetMask,subMask, memcpy(packetMask, subMask, numRows * numSubMaskBytes);
static_cast<WebRtc_UWord32>(numRows) *
static_cast<WebRtc_UWord32>(numSubMaskBytes));
} }
else else
{ {
for (WebRtc_UWord32 i = 0; i < numRows; i++) for (int i = 0; i < numRows; i++)
{ {
WebRtc_UWord32 pktMaskIdx = i * numMaskBytes; int pktMaskIdx = i * numMaskBytes;
WebRtc_UWord32 pktMaskIdx2 = i * numSubMaskBytes; int pktMaskIdx2 = i * numSubMaskBytes;
for (WebRtc_UWord32 j = 0; j < numSubMaskBytes; j++) for (int j = 0; j < numSubMaskBytes; j++)
{ {
packetMask[pktMaskIdx] = subMask[pktMaskIdx2]; packetMask[pktMaskIdx] = subMask[pktMaskIdx2];
pktMaskIdx++; pktMaskIdx++;
@ -85,34 +83,33 @@ void FitSubMask(WebRtc_UWord16 numMaskBytes,
// TODO (marpan): This function is doing three things at the same time: // TODO (marpan): This function is doing three things at the same time:
// shift within a byte, byte shift and resizing. // shift within a byte, byte shift and resizing.
// Split up into subroutines. // Split up into subroutines.
void ShiftFitSubMask(WebRtc_UWord16 numMaskBytes, void ShiftFitSubMask(int numMaskBytes,
WebRtc_UWord16 resMaskBytes, int resMaskBytes,
WebRtc_UWord16 numColumnShift, int numColumnShift,
WebRtc_UWord16 endRow, int endRow,
const WebRtc_UWord8* subMask, const uint8_t* subMask,
WebRtc_UWord8* packetMask) uint8_t* packetMask)
{ {
// Number of bit shifts within a byte // Number of bit shifts within a byte
const WebRtc_UWord8 numBitShifts = (numColumnShift % 8); const int numBitShifts = (numColumnShift % 8);
const WebRtc_UWord8 numByteShifts = numColumnShift >> 3; const int numByteShifts = numColumnShift >> 3;
// Modify new mask with sub-mask21. // Modify new mask with sub-mask21.
// Loop over the remaining FEC packets. // Loop over the remaining FEC packets.
for (WebRtc_UWord32 i = numColumnShift; i < endRow; i++) for (int i = numColumnShift; i < endRow; i++)
{ {
// Byte index of new mask, for row i and column resMaskBytes, // Byte index of new mask, for row i and column resMaskBytes,
// offset by the number of bytes shifts // offset by the number of bytes shifts
WebRtc_UWord32 pktMaskIdx = i * numMaskBytes + resMaskBytes - 1 int pktMaskIdx = i * numMaskBytes + resMaskBytes - 1 + numByteShifts;
+ numByteShifts;
// Byte index of subMask, for row i and column resMaskBytes // Byte index of subMask, for row i and column resMaskBytes
WebRtc_UWord32 pktMaskIdx2 = int pktMaskIdx2 =
(i - numColumnShift) * resMaskBytes + resMaskBytes - 1; (i - numColumnShift) * resMaskBytes + resMaskBytes - 1;
WebRtc_UWord8 shiftRightCurrByte = 0; uint8_t shiftRightCurrByte = 0;
WebRtc_UWord8 shiftLeftPrevByte = 0; uint8_t shiftLeftPrevByte = 0;
WebRtc_UWord8 combNewByte = 0; uint8_t combNewByte = 0;
// Handle case of numMaskBytes > resMaskBytes: // Handle case of numMaskBytes > resMaskBytes:
// For a given row, copy the rightmost "numBitShifts" bits // For a given row, copy the rightmost "numBitShifts" bits
@ -127,7 +124,7 @@ void ShiftFitSubMask(WebRtc_UWord16 numMaskBytes,
// For each row i (FEC packet), shift the bit-mask of the subMask. // For each row i (FEC packet), shift the bit-mask of the subMask.
// Each row of the mask contains "resMaskBytes" of bytes. // Each row of the mask contains "resMaskBytes" of bytes.
// We start from the last byte of the subMask and move to first one. // We start from the last byte of the subMask and move to first one.
for (WebRtc_Word32 j = resMaskBytes - 1; j > 0; j--) for (int j = resMaskBytes - 1; j > 0; j--)
{ {
// Shift current byte of sub21 to the right by "numBitShifts". // Shift current byte of sub21 to the right by "numBitShifts".
shiftRightCurrByte = shiftRightCurrByte =
@ -159,24 +156,24 @@ namespace webrtc {
namespace internal { namespace internal {
// Remaining protection after important (first partition) packet protection // Remaining protection after important (first partition) packet protection
void RemainingPacketProtection(WebRtc_UWord16 numMediaPackets, void RemainingPacketProtection(int numMediaPackets,
WebRtc_UWord16 numFecRemaining, int numFecRemaining,
WebRtc_UWord16 numFecForImpPackets, int numFecForImpPackets,
WebRtc_UWord16 numMaskBytes, int numMaskBytes,
ProtectionMode mode, ProtectionMode mode,
WebRtc_UWord8* packetMask) uint8_t* packetMask)
{ {
if (mode == kModeNoOverlap) if (mode == kModeNoOverlap)
{ {
// subMask21 // subMask21
const WebRtc_UWord8 lBit = const int lBit =
(numMediaPackets - numFecForImpPackets) > 16 ? 1 : 0; (numMediaPackets - numFecForImpPackets) > 16 ? 1 : 0;
const WebRtc_UWord16 resMaskBytes = const int resMaskBytes =
(lBit == 1)? kMaskSizeLBitSet : kMaskSizeLBitClear; (lBit == 1) ? kMaskSizeLBitSet : kMaskSizeLBitClear;
const WebRtc_UWord8* packetMaskSub21 = const uint8_t* packetMaskSub21 =
packetMaskTbl[numMediaPackets - numFecForImpPackets - 1] packetMaskTbl[numMediaPackets - numFecForImpPackets - 1]
[numFecRemaining - 1]; [numFecRemaining - 1];
@ -189,7 +186,7 @@ void RemainingPacketProtection(WebRtc_UWord16 numMediaPackets,
{ {
// subMask22 // subMask22
const WebRtc_UWord8* packetMaskSub22 = const uint8_t* packetMaskSub22 =
packetMaskTbl[numMediaPackets - 1][numFecRemaining - 1]; packetMaskTbl[numMediaPackets - 1][numFecRemaining - 1];
FitSubMask(numMaskBytes, numMaskBytes, numFecRemaining, packetMaskSub22, FitSubMask(numMaskBytes, numMaskBytes, numFecRemaining, packetMaskSub22,
@ -197,9 +194,9 @@ void RemainingPacketProtection(WebRtc_UWord16 numMediaPackets,
if (mode == kModeBiasFirstPacket) if (mode == kModeBiasFirstPacket)
{ {
for (WebRtc_UWord32 i = 0; i < numFecRemaining; i++) for (int i = 0; i < numFecRemaining; i++)
{ {
WebRtc_UWord32 pktMaskIdx = i * numMaskBytes; int pktMaskIdx = i * numMaskBytes;
packetMask[pktMaskIdx] = packetMask[pktMaskIdx] | (1 << 7); packetMask[pktMaskIdx] = packetMask[pktMaskIdx] | (1 << 7);
} }
} }
@ -212,19 +209,18 @@ void RemainingPacketProtection(WebRtc_UWord16 numMediaPackets,
} }
// Protection for important (first partition) packets // Protection for important (first partition) packets
void ImportantPacketProtection(WebRtc_UWord16 numFecForImpPackets, void ImportantPacketProtection(int numFecForImpPackets,
WebRtc_UWord16 numImpPackets, int numImpPackets,
WebRtc_UWord16 numMaskBytes, int numMaskBytes,
WebRtc_UWord8* packetMask) uint8_t* packetMask)
{ {
const WebRtc_UWord8 lBit = numImpPackets > 16 ? 1 : 0; const int lBit = numImpPackets > 16 ? 1 : 0;
const WebRtc_UWord16 numImpMaskBytes = const int numImpMaskBytes =
(lBit == 1)? kMaskSizeLBitSet : kMaskSizeLBitClear; (lBit == 1) ? kMaskSizeLBitSet : kMaskSizeLBitClear;
// Get subMask1 from table // Get subMask1 from table
const WebRtc_UWord8* packetMaskSub1 = const uint8_t* packetMaskSub1 =
packetMaskTbl[numImpPackets - 1][numFecForImpPackets - 1]; packetMaskTbl[numImpPackets - 1][numFecForImpPackets - 1];
FitSubMask(numMaskBytes, numImpMaskBytes, FitSubMask(numMaskBytes, numImpMaskBytes,
numFecForImpPackets, packetMaskSub1, packetMask); numFecForImpPackets, packetMaskSub1, packetMask);
@ -234,20 +230,19 @@ void ImportantPacketProtection(WebRtc_UWord16 numFecForImpPackets,
// This function sets the protection allocation: i.e., how many FEC packets // This function sets the protection allocation: i.e., how many FEC packets
// to use for numImp (1st partition) packets, given the: number of media // to use for numImp (1st partition) packets, given the: number of media
// packets, number of FEC packets, and number of 1st partition packets. // packets, number of FEC packets, and number of 1st partition packets.
WebRtc_UWord32 SetProtectionAllocation(const WebRtc_UWord16 numMediaPackets, int SetProtectionAllocation(int numMediaPackets,
const WebRtc_UWord16 numFecPackets, int numFecPackets,
const WebRtc_UWord16 numImpPackets) int numImpPackets)
{ {
// TODO (marpan): test different cases for protection allocation: // TODO (marpan): test different cases for protection allocation:
// Use at most (allocPar * numFecPackets) for important packets. // Use at most (allocPar * numFecPackets) for important packets.
float allocPar = 0.5; float allocPar = 0.5;
WebRtc_UWord16 maxNumFecForImp = static_cast<WebRtc_UWord16> int maxNumFecForImp = allocPar * numFecPackets;
(allocPar * numFecPackets);
WebRtc_UWord16 numFecForImpPackets = (numImpPackets < maxNumFecForImp) ? int numFecForImpPackets = (numImpPackets < maxNumFecForImp) ?
numImpPackets : maxNumFecForImp; numImpPackets : maxNumFecForImp;
// Fall back to equal protection in this case // Fall back to equal protection in this case
if (numFecPackets == 1 && (numMediaPackets > 2 * numImpPackets)) if (numFecPackets == 1 && (numMediaPackets > 2 * numImpPackets))
@ -303,18 +298,18 @@ WebRtc_UWord32 SetProtectionAllocation(const WebRtc_UWord16 numMediaPackets,
// Protection Mode 2 may be extended for a sort of sliding protection // Protection Mode 2 may be extended for a sort of sliding protection
// (i.e., vary the number/density of "1s" across columns) across packets. // (i.e., vary the number/density of "1s" across columns) across packets.
void UnequalProtectionMask(const WebRtc_UWord16 numMediaPackets, void UnequalProtectionMask(int numMediaPackets,
const WebRtc_UWord16 numFecPackets, int numFecPackets,
const WebRtc_UWord16 numImpPackets, int numImpPackets,
const WebRtc_UWord16 numMaskBytes, int numMaskBytes,
WebRtc_UWord8* packetMask) uint8_t* packetMask)
{ {
// Set Protection type and allocation // Set Protection type and allocation
// TODO (marpan): test/update for best mode and some combinations thereof. // TODO (marpan): test/update for best mode and some combinations thereof.
ProtectionMode mode = kModeOverlap; ProtectionMode mode = kModeOverlap;
WebRtc_UWord16 numFecForImpPackets = 0; int numFecForImpPackets = 0;
if (mode != kModeBiasFirstPacket) if (mode != kModeBiasFirstPacket)
{ {
@ -323,7 +318,7 @@ void UnequalProtectionMask(const WebRtc_UWord16 numMediaPackets,
numImpPackets); numImpPackets);
} }
WebRtc_UWord16 numFecRemaining = numFecPackets - numFecForImpPackets; int numFecRemaining = numFecPackets - numFecForImpPackets;
// Done with setting protection type and allocation // Done with setting protection type and allocation
// //
@ -351,7 +346,7 @@ void GeneratePacketMasks(int numMediaPackets,
int numFecPackets, int numFecPackets,
int numImpPackets, int numImpPackets,
bool useUnequalProtection, bool useUnequalProtection,
WebRtc_UWord8* packetMask) uint8_t* packetMask)
{ {
assert(numMediaPackets <= static_cast<int>(sizeof(packetMaskTbl) / assert(numMediaPackets <= static_cast<int>(sizeof(packetMaskTbl) /
sizeof(*packetMaskTbl))); sizeof(*packetMaskTbl)));
@ -359,9 +354,9 @@ void GeneratePacketMasks(int numMediaPackets,
assert(numFecPackets <= numMediaPackets && numFecPackets > 0); assert(numFecPackets <= numMediaPackets && numFecPackets > 0);
assert(numImpPackets <= numMediaPackets && numImpPackets >= 0); assert(numImpPackets <= numMediaPackets && numImpPackets >= 0);
WebRtc_UWord8 lBit = numMediaPackets > 16 ? 1 : 0; int lBit = numMediaPackets > 16 ? 1 : 0;
const WebRtc_UWord16 numMaskBytes = const int numMaskBytes =
(lBit == 1)? kMaskSizeLBitSet : kMaskSizeLBitClear; (lBit == 1) ? kMaskSizeLBitSet : kMaskSizeLBitClear;
// Equal-protection for these cases // Equal-protection for these cases
if (!useUnequalProtection || numImpPackets == 0) if (!useUnequalProtection || numImpPackets == 0)
@ -369,9 +364,9 @@ void GeneratePacketMasks(int numMediaPackets,
// Retrieve corresponding mask table directly:for equal-protection case. // Retrieve corresponding mask table directly:for equal-protection case.
// Mask = (k,n-k), with protection factor = (n-k)/k, // Mask = (k,n-k), with protection factor = (n-k)/k,
// where k = numMediaPackets, n=total#packets, (n-k)=numFecPackets. // where k = numMediaPackets, n=total#packets, (n-k)=numFecPackets.
memcpy(packetMask, packetMaskTbl[numMediaPackets - 1][numFecPackets - 1], memcpy(packetMask,
static_cast<WebRtc_UWord32>(numFecPackets) * packetMaskTbl[numMediaPackets - 1][numFecPackets - 1],
static_cast<WebRtc_UWord32>(numMaskBytes)); numFecPackets * numMaskBytes);
} }
else //UEP case else //UEP case
{ {

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
* *
* Use of this source code is governed by a BSD-style license * Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source * that can be found in the LICENSE file in the root of the source
@ -13,9 +13,9 @@
namespace webrtc { namespace webrtc {
// Packet mask size in bytes (L bit is set). // Packet mask size in bytes (L bit is set).
const WebRtc_UWord8 kMaskSizeLBitSet = 6; static const int kMaskSizeLBitSet = 6;
// Packet mask size in bytes (L bit is cleared). // Packet mask size in bytes (L bit is cleared).
const WebRtc_UWord8 kMaskSizeLBitClear = 2; static const int kMaskSizeLBitClear = 2;
namespace internal { namespace internal {
@ -42,6 +42,7 @@ void GeneratePacketMasks(int numMediaPackets,
int numFecPackets, int numFecPackets,
int numImpPackets, int numImpPackets,
bool useUnequalProtection, bool useUnequalProtection,
WebRtc_UWord8* packetMask); uint8_t* packetMask);
} // namespace internal } // namespace internal
} // namespace webrtc } // namespace webrtc