Void TEncRCSeq::create( Int totalFrames, Int targetBitrate, Int frameRate, Int GOPSize, Int picWidth, Int picHeight, Int LCUWidth, Int LCUHeight, Int numberOfLevel, Bool useLCUSeparateModel, Int adaptiveBit )//Bool useLCUSeparateModel表示LCU的分割方式
{
destroy();
m_totalFrames = totalFrames;//m表示类的数据成员,等号左边的为上面的函数定义的,等号右边的为该函数定义的
m_targetRate = targetBitrate;
m_frameRate = frameRate;
m_GOPSize = GOPSize;
m_picWidth = picWidth;
m_picHeight = picHeight;
m_LCUWidth = LCUWidth;
m_LCUHeight = LCUHeight;
m_numberOfLevel = numberOfLevel;
m_useLCUSeparateModel = useLCUSeparateModel;
m_numberOfPixel = m_picWidth * m_picHeight;//像素数量
m_targetBits = (Int64)m_totalFrames * (Int64)m_targetRate / (Int64)m_frameRate;//总的目标比特????
m_seqTargetBpp = (Double)m_targetRate / (Double)m_frameRate / (Double)m_numberOfPixel;//每像素分配的比特
if ( m_seqTargetBpp < 0.03 )//根据目标分配比特数的等级不同分别给αβ赋予不同的值,用于更新λ来控制后面的码率控制
{
m_alphaUpdate = 0.01;//α为0.01
m_betaUpdate = 0.005;//β为0.005
}
else if ( m_seqTargetBpp < 0.08 )
{
m_alphaUpdate = 0.05;
m_betaUpdate = 0.025;
}
else if ( m_seqTargetBpp < 0.2 )
{
m_alphaUpdate = 0.1;
m_betaUpdate = 0.05;
}
else if ( m_seqTargetBpp < 0.5 )
{
m_alphaUpdate = 0.2;
m_betaUpdate = 0.1;
}
else
{
m_alphaUpdate = 0.4;
m_betaUpdate = 0.2;
}
m_averageBits = (Int)(m_targetBits / totalFrames);//每帧平均比特数
Int picWidthInBU = ( m_picWidth % m_LCUWidth ) == 0 ? m_picWidth / m_LCUWidth : m_picWidth / m_LCUWidth + 1;//
Int picHeightInBU = ( m_picHeight % m_LCUHeight ) == 0 ? m_picHeight / m_LCUHeight : m_picHeight / m_LCUHeight + 1;
m_numberOfLCU = picWidthInBU * picHeightInBU;//CU的数量
m_bitsRatio = new Int[m_GOPSize];
for ( Int i=0; i<m_GOPSize; i++ )
{
m_bitsRatio[i] = 1;//初始化整个GOP中的各帧的比特率都为1
}
m_GOPID2Level = new Int[m_GOPSize];
for ( Int i=0; i<m_GOPSize; i++ )
{
m_GOPID2Level[i] = 1;//初始化整个GOP的各帧的层次都相同啊
}
m_picPara = new TRCParameter[m_numberOfLevel];
for ( Int i=0; i<m_numberOfLevel; i++ )
{
m_picPara[i].m_alpha = 0.0;
m_picPara[i].m_beta = 0.0;
}
if ( m_useLCUSeparateModel )//
{
m_LCUPara = new TRCParameter*[m_numberOfLevel];
for ( Int i=0; i<m_numberOfLevel; i++ )
{
m_LCUPara[i] = new TRCParameter[m_numberOfLCU];
for ( Int j=0; j<m_numberOfLCU; j++)
{
m_LCUPara[i][j].m_alpha = 0.0;
m_LCUPara[i][j].m_beta = 0.0;
}
}
}
m_framesLeft = m_totalFrames;
m_bitsLeft = m_targetBits;
m_adaptiveBit = adaptiveBit;
m_lastLambda = 0.0;
}
这是HEVC中码率控制里面seq层的参数初始化(Void TEncRCSeq::create)的代码。在这段代码里面大量运用到了new这个表达式。
new:主要用来创建数组,也可以用来动态创建单个的对象。定义变量的时候需要指定其类型和名字,而动态创建对象时只需指定其数据类型,而不需要为该对象命名。取而代之的是,new表达式返回新的创建对象的指针,我们通过指针来访问对象。
int i;
int *pi=new int;
这个new表达式在自由存储区中分配创建了一个整型对象,并返回此对象的地址,并用该地址初始化指针pi。
m_bitsRatio = new Int[m_GOPSize];
for ( Int i=0; i<m_GOPSize; i++ )
{
m_bitsRatio[i] = 1;
}
这段代码中,m_bitsRatio的定义就是指针变量,所以这里是用新创建的整型数组(大小为GOPsize)的地址来初始化该指针。(这里需要补习下指向数组的指针这块的内容)
m_GOPID2Level = new Int[m_GOPSize];
for ( Int i=0; i<m_GOPSize; i++ )
{
m_GOPID2Level[i] = 1;
}
这段代码的目的是初始化整个GOP中的每一帧的级别,用指针取出每一帧,并且将他们的层次定义为相同的值1。
时间: 2024-10-12 18:52:04