Put some table size information in one place.

Motivated by fixing an unused variable warning in release mode.
Review URL: http://webrtc-codereview.appspot.com/132007

git-svn-id: http://webrtc.googlecode.com/svn/trunk@523 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
andrew@webrtc.org 2011-09-02 22:03:56 +00:00
parent d7a41774ce
commit 413b993166
3 changed files with 61 additions and 59 deletions

View File

@ -11,15 +11,29 @@
#ifndef WEBRTC_MODULES_VIDEO_CODING_SOURCE_ER_TABLES_XOR_H_
#define WEBRTC_MODULES_VIDEO_CODING_SOURCE_ER_TABLES_XOR_H_
namespace webrtc
{
// This is a private header for media_opt_util.cc.
// It should not be included by other files.
namespace webrtc {
// Table for average FEC recovery from packet loss, for XOR code.
// From RPL model of random loss.
// Input is the received packet loss (up to 50%), and FEC code parameters (up to 24x24):
// i.e., averageFECRecoveryRS[k] where k= code_i*129 + loss_j;
// code_i=1x1,2x1,2x2,..24x24, loss_j=0,1,..128.
const unsigned char VCMAvgFECRecoveryXOR[38700] = {
// Input is the received packet loss (up to 50%), and FEC code parameters
// (up to 24x24):
// i.e., kAvgFECRecoveryXOR[k] where k = code_i*129 + loss_j;
// code_i=1x1,2x1,2x2,..24x24, loss_j = 0,1,..128.
// Maximum number of source packets in off-line model
static const int kMaxNumPackets = 24;
// Max value of loss rates in off-line model
static const int kPacketLossMax = 129;
// Table size for model is: kPacketLossMax * numberOfFecCodes = 38700
// numberOfFecCodes is determined as:
// {(1,1), (2,1), (2,2),...(n,1),..(n,n-1), (n,n)} = n*(n+1)/2
// for n = kMaxNumPackets.
static const int kSizeAvgFECRecoveryXOR = 38700;
static const unsigned char kAvgFECRecoveryXOR[kSizeAvgFECRecoveryXOR] = {
0,
0,
1,

View File

@ -11,14 +11,17 @@
#ifndef WEBRTC_MODULES_VIDEO_CODING_SOURCE_FEC_TABLES_XOR_H_
#define WEBRTC_MODULES_VIDEO_CODING_SOURCE_FEC_TABLES_XOR_H_
namespace webrtc
{
// This is a private header for media_opt_util.cc.
// It should not be included by other files.
namespace webrtc {
// Table for Protection factor (code rate) of delta frames, for the XOR FEC.
// Input is the packet loss and an effective rate (bits/frame).
// Output is array codeRateXORTable[k], where k = rate_i*129 + loss_j;
// loss_j=0,1,..128, and rate_i varies over some range.
const unsigned char VCMCodeRateXORTable[6450] = {
// Output is array kCodeRateXORTable[k], where k = rate_i*129 + loss_j;
// loss_j = 0,1,..128, and rate_i varies over some range.
static const int kSizeCodeRateXORTable = 6450;
static const unsigned char kCodeRateXORTable[kSizeCodeRateXORTable] = {
0,
0,
0,

View File

@ -225,17 +225,6 @@ VCMFecMethod::AvgRecoveryFEC(const VCMProtectionParameters* parameters) const
(static_cast<float> (bitRatePerFrame * 1000.0) /
static_cast<float> (8.0 * _maxPayloadSize) + 0.5);
// Parameters for tables
// Maximum number of source packets in off-line model
const WebRtc_UWord8 maxNumPackets = 24;
// Max value of loss rates in off-line model
const WebRtc_UWord8 plossMax = 129;
// Table size for model is: plossMax * numberOfFecCodes = 38700
// numberOfFecCodes is determined as:
// {(1,1), (2,1), (2,2),...(n,1),..(n,n-1), (n,n)} = n*(n+1)/2; for n=24.
const WebRtc_UWord16 maxErTableSize = 38700;
const float protectionFactor = static_cast<float>(_protectionFactorD) /
255.0;
@ -250,26 +239,26 @@ VCMFecMethod::AvgRecoveryFEC(const VCMProtectionParameters* parameters) const
return 0.0;
}
// Table defined up to maxNumPackets
if (sourcePacketsPerFrame > maxNumPackets)
// Table defined up to kMaxNumPackets
if (sourcePacketsPerFrame > kMaxNumPackets)
{
sourcePacketsPerFrame = maxNumPackets;
sourcePacketsPerFrame = kMaxNumPackets;
}
// Table defined up to maxNumPackets
if (fecPacketsPerFrame > maxNumPackets)
// Table defined up to kMaxNumPackets
if (fecPacketsPerFrame > kMaxNumPackets)
{
fecPacketsPerFrame = maxNumPackets;
fecPacketsPerFrame = kMaxNumPackets;
}
// Code index for tables: up to (maxNumPackets * maxNumPackets)
WebRtc_UWord16 codeIndexTable[maxNumPackets * maxNumPackets];
// Code index for tables: up to (kMaxNumPackets * kMaxNumPackets)
WebRtc_UWord16 codeIndexTable[kMaxNumPackets * kMaxNumPackets];
WebRtc_UWord16 k = 0;
for (WebRtc_UWord8 i = 1; i <= maxNumPackets; i++)
for (WebRtc_UWord8 i = 1; i <= kMaxNumPackets; i++)
{
for (WebRtc_UWord8 j = 1; j <= i; j++)
{
codeIndexTable[(j - 1) * maxNumPackets + i - 1] = k;
codeIndexTable[(j - 1) * kMaxNumPackets + i - 1] = k;
k += 1;
}
}
@ -278,21 +267,20 @@ VCMFecMethod::AvgRecoveryFEC(const VCMProtectionParameters* parameters) const
parameters->lossPr + 0.5f);
// Constrain lossRate to 50%: tables defined up to 50%
if (lossRate >= plossMax)
if (lossRate >= kPacketLossMax)
{
lossRate = plossMax - 1;
lossRate = kPacketLossMax - 1;
}
const WebRtc_UWord16 codeIndex = (fecPacketsPerFrame - 1) * maxNumPackets +
const WebRtc_UWord16 codeIndex = (fecPacketsPerFrame - 1) * kMaxNumPackets +
(sourcePacketsPerFrame - 1);
const WebRtc_UWord16 indexTable = codeIndexTable[codeIndex] * plossMax +
const WebRtc_UWord16 indexTable = codeIndexTable[codeIndex] * kPacketLossMax +
lossRate;
// Check on table index
assert (indexTable < maxErTableSize);
float avgFecRecov = static_cast<float> (VCMAvgFECRecoveryXOR[indexTable]);
assert(indexTable < kSizeAvgFECRecoveryXOR);
float avgFecRecov = static_cast<float>(kAvgFECRecoveryXOR[indexTable]);
return avgFecRecov;
}
@ -322,12 +310,9 @@ VCMFecMethod::ProtectionFactor(const VCMProtectionParameters* parameters)
WebRtc_UWord8 lossThr = 0;
WebRtc_UWord8 packetNumThr = 1;
// Size of table
const WebRtc_UWord16 maxFecTableSize = 6450;
// Parameters for range of rate and packet loss for tables
// Parameters for range of rate index of table.
const WebRtc_UWord8 ratePar1 = 5;
const WebRtc_UWord8 ratePar2 = 49;
const WebRtc_UWord8 plossMax = 129;
// Spatial resolution size, relative to a reference size.
float spatialSizeToRef = static_cast<float>
@ -365,17 +350,17 @@ VCMFecMethod::ProtectionFactor(const VCMProtectionParameters* parameters)
// Restrict packet loss range to 50:
// current tables defined only up to 50%
if (packetLoss >= plossMax)
if (packetLoss >= kPacketLossMax)
{
packetLoss = plossMax - 1;
packetLoss = kPacketLossMax - 1;
}
WebRtc_UWord16 indexTable = rateIndexTable * plossMax + packetLoss;
WebRtc_UWord16 indexTable = rateIndexTable * kPacketLossMax + packetLoss;
// Check on table index
assert(indexTable < maxFecTableSize);
assert(indexTable < kSizeCodeRateXORTable);
// Protection factor for P frame
codeRateDelta = VCMCodeRateXORTable[indexTable];
codeRateDelta = kCodeRateXORTable[indexTable];
if (packetLoss > lossThr && avgTotPackets > packetNumThr)
{
@ -387,9 +372,9 @@ VCMFecMethod::ProtectionFactor(const VCMProtectionParameters* parameters)
}
// Check limit on amount of protection for P frame; 50% is max.
if (codeRateDelta >= plossMax)
if (codeRateDelta >= kPacketLossMax)
{
codeRateDelta = plossMax - 1;
codeRateDelta = kPacketLossMax - 1;
}
float adjustFec = _qmRobustness->AdjustFecFactor(codeRateDelta,
@ -414,21 +399,21 @@ VCMFecMethod::ProtectionFactor(const VCMProtectionParameters* parameters)
rateIndexTable = (WebRtc_UWord8) VCM_MAX(VCM_MIN(
1 + (boostKey * effRateFecTable - ratePar1) /
ratePar1,ratePar2),0);
WebRtc_UWord16 indexTableKey = rateIndexTable * plossMax + packetLoss;
WebRtc_UWord16 indexTableKey = rateIndexTable * kPacketLossMax + packetLoss;
indexTableKey = VCM_MIN(indexTableKey, maxFecTableSize);
indexTableKey = VCM_MIN(indexTableKey, kSizeCodeRateXORTable);
// Check on table index
assert(indexTableKey < maxFecTableSize);
assert(indexTableKey < kSizeCodeRateXORTable);
// Protection factor for I frame
codeRateKey = VCMCodeRateXORTable[indexTableKey];
codeRateKey = kCodeRateXORTable[indexTableKey];
// Boosting for Key frame.
WebRtc_UWord32 boostKeyProt = _scaleProtKey * codeRateDelta;
if ( boostKeyProt >= plossMax)
int boostKeyProt = _scaleProtKey * codeRateDelta;
if (boostKeyProt >= kPacketLossMax)
{
boostKeyProt = plossMax - 1;
boostKeyProt = kPacketLossMax - 1;
}
// Make sure I frame protection is at least larger than P frame protection,
@ -437,9 +422,9 @@ VCMFecMethod::ProtectionFactor(const VCMProtectionParameters* parameters)
VCM_MAX(boostKeyProt, codeRateKey)));
// Check limit on amount of protection for I frame: 50% is max.
if (codeRateKey >= plossMax)
if (codeRateKey >= kPacketLossMax)
{
codeRateKey = plossMax - 1;
codeRateKey = kPacketLossMax - 1;
}
_protectionFactorK = codeRateKey;