转载:http://blog.csdn.net/Villa_7/article/details/70139266
Void TEncTop::encode(Bool flush, TComPicYuv* pcPicYuvOrg, TComPicYuv* pcPicYuvTrueOrg, const InputColourSpaceConversion snrCSC, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsOut, Int& iNumEncoded, Bool isTff)
{
iNumEncoded = 0;//编码帧数为0
for (Int fieldNum=0; fieldNum<2; fieldNum++)//当场数量小于2时
{
if (pcPicYuvOrg)
{
/* -- field initialization场帧初始化 -- */
const Bool isTopField=isTff==(fieldNum==0);//顶场和底场的部分,忽略不看
TComPic *pcField;
xGetNewPicBuffer( pcField );
pcField->setReconMark (false); // where is this normally?
if (fieldNum==1) // where is this normally?
{
TComPicYuv* rpcPicYuvRec;
// org. buffer
if ( rcListPicYuvRecOut.size() >= (UInt)m_iGOPSize+1 ) // need to maintain field 0 in list of RecOuts while processing field 1. Hence +1 on m_iGOPSize.
{
rpcPicYuvRec = rcListPicYuvRecOut.popFront();
}
else
{
rpcPicYuvRec = new TComPicYuv;
rpcPicYuvRec->create( m_iSourceWidth, m_iSourceHeight, m_chromaFormatIDC, m_maxCUWidth, m_maxCUHeight, m_maxTotalCUDepth, true);
}//创建一幅图像的数组表示(源图像宽、高、最大cu高度、宽度、深度)
rcListPicYuvRecOut.pushBack( rpcPicYuvRec );
}
pcField->getSlice(0)->setPOC( m_iPOCLast ); // superfluous?
pcField->getPicYuvRec()->setBorderExtension(false);// where is this normally?
pcField->setTopField(isTopField); //交错 interlaced requirement
for (UInt componentIndex = 0; componentIndex < pcPicYuvOrg->getNumberValidComponents(); componentIndex++)
{
const ComponentID component = ComponentID(componentIndex);
const UInt stride = pcPicYuvOrg->getStride(component);
separateFields((pcPicYuvOrg->getBuf(component) + pcPicYuvOrg->getMarginX(component) + (pcPicYuvOrg->getMarginY(component) * stride)),
pcField->getPicYuvOrg()->getAddr(component),
pcPicYuvOrg->getStride(component),
pcPicYuvOrg->getWidth(component),
pcPicYuvOrg->getHeight(component),
isTopField);
separateFields((pcPicYuvTrueOrg->getBuf(component) + pcPicYuvTrueOrg->getMarginX(component) + (pcPicYuvTrueOrg->getMarginY(component) * stride)),
pcField->getPicYuvTrueOrg()->getAddr(component),
pcPicYuvTrueOrg->getStride(component),
pcPicYuvTrueOrg->getWidth(component),
pcPicYuvTrueOrg->getHeight(component),
isTopField);
}
// 计算图像特性
if ( getUseAdaptiveQP() )
{
m_cPreanalyzer.xPreanalyze( dynamic_cast<TEncPic*>( pcField ) );
}
}
if ( m_iNumPicRcvd && ((flush&&fieldNum==1) || (m_iPOCLast/2)==0 || m_iNumPicRcvd==m_iGOPSize ) )
{
// 压缩gop
m_cGOPEncoder.compressGOP(m_iPOCLast, m_iNumPicRcvd, m_cListPic, rcListPicYuvRecOut, accessUnitsOut, true, isTff, snrCSC, m_printFrameMSE);
iNumEncoded += m_iNumPicRcvd;
m_uiNumAllPicCoded += m_iNumPicRcvd;
m_iNumPicRcvd = 0;
}
}
}