📄 mbdataaccess.cpp
字号:
SParIdx4x4 eSubMbPartIdx = ( eParIdx <= PART_8x8_1 ? ( eParIdx == PART_8x8_0 ? SPART_4x4_0 : SPART_4x4_1 )
: ( eParIdx == PART_8x8_2 ? SPART_4x4_2 : SPART_4x4_3 ) );
xGetColocatedMvRefIdx( acMvCol[0], scRefIdxCol, B4x4Idx( eParIdx + eSubMbPartIdx ) );
}
else
{
//===== THIS SHALL NEVER BE CALLED FOR INTERLACED SEQUENCES =====
xGetColocatedMvsRefIdxNonInterlaced( acMvCol, scRefIdxCol, eParIdx );
}
bAllColNonZero = ( scRefIdxCol != 1 );
}
if( ! bAllColNonZero )
{
bColZeroFlagBlk0 = ( acMvCol[0].getAbsHor() <= 1 && acMvCol[0].getAbsVer() <= 1 );
if( ! b8x8 )
{
bColZeroFlagBlk1 = ( acMvCol[1].getAbsHor() <= 1 && acMvCol[1].getAbsVer() <= 1 );
bColZeroFlagBlk2 = ( acMvCol[2].getAbsHor() <= 1 && acMvCol[2].getAbsVer() <= 1 );
bColZeroFlagBlk3 = ( acMvCol[3].getAbsHor() <= 1 && acMvCol[3].getAbsVer() <= 1 );
}
}
}
//===== set motion vectors and reference frames =====
for( uiLstIdx = 0; uiLstIdx < 2; uiLstIdx++ )
{
ListIdx eListIdx = ListIdx( uiLstIdx );
MbMotionData& rcMbMotionDataLX = getMbMotionData( eListIdx );
SChar scRefIdx = ascRefIdx[ eListIdx ];
Bool bZeroMv;
Bool bMvValid = true;
//----- set motion vectors -----
if( b8x8 || bAllColNonZero || scRefIdx < 1 )
{
bZeroMv = ( bDirectZeroPred || scRefIdx < 1 || ( scRefIdx == 1 && bColZeroFlagBlk0 ) );
const Mv& rcMv = ( bZeroMv ? Mv::ZeroMv() : acMvPred [ eListIdx ] );
rcMbMotionDataLX.setAllMv( rcMv, eParIdx );
bMvValid = xCheckMv( rcMv );
}
else
{
bZeroMv = ( scRefIdx == 1 && bColZeroFlagBlk0 );
const Mv& rcMv0 = ( bZeroMv ? Mv::ZeroMv() : acMvPred [ eListIdx ] );
rcMbMotionDataLX.setAllMv( rcMv0, eParIdx, SPART_4x4_0 );
bMvValid &= xCheckMv( rcMv0 );
bZeroMv = ( scRefIdx == 1 && bColZeroFlagBlk1 );
const Mv& rcMv1 = ( bZeroMv ? Mv::ZeroMv() : acMvPred [ eListIdx ] );
rcMbMotionDataLX.setAllMv( rcMv1, eParIdx, SPART_4x4_1 );
bMvValid &= xCheckMv( rcMv1 );
bZeroMv = ( scRefIdx == 1 && bColZeroFlagBlk2 );
const Mv& rcMv2 = ( bZeroMv ? Mv::ZeroMv() : acMvPred [ eListIdx ] );
rcMbMotionDataLX.setAllMv( rcMv2, eParIdx, SPART_4x4_2 );
bMvValid &= xCheckMv( rcMv2 );
bZeroMv = ( scRefIdx == 1 && bColZeroFlagBlk3 );
const Mv& rcMv3 = ( bZeroMv ? Mv::ZeroMv() : acMvPred [ eListIdx ] );
rcMbMotionDataLX.setAllMv( rcMv3, eParIdx, SPART_4x4_3 );
bMvValid &= xCheckMv( rcMv3 );
}
//----- set reference indices and reference pictures -----
rcMbMotionDataLX.setRefIdx ( scRefIdx, eParIdx );
if( m_rcSliceHeader.getRefPicList( getMbPicType(), eListIdx ).size() )
{
const Frame* pcFrame = ( scRefIdx < 1 ? 0 : m_rcSliceHeader.getRefPic ( scRefIdx, getMbPicType(), eListIdx ).getFrame() );
rcMbMotionDataLX.setRefPic ( pcFrame, eParIdx );
}
if ( !bMvValid )
{
return false;
}
}
return true;
}
Bool MbDataAccess::xTemporalDirectModeMvRef( Mv acMv[], SChar ascRefIdx[], LumaIdx cIdx, Bool bFaultTolerant )
{
SChar scRefIdxCol;
Mv cMvCol;
const RefPic& rcRefPicCol = xGetColocatedMvRefPic( cMvCol, scRefIdxCol, cIdx );
//----- get reference index for list 0 -----
if( scRefIdxCol > 0 )
{
if( rcRefPicCol.isAvailable() )
{
const RefPic cRefPic = ( ( getMbPicType() != FRAME && rcRefPicCol.getFrame()->getPicType() != FRAME ) ? rcRefPicCol :
rcRefPicCol.getFrame()->getFrameUnit()->getRefPic( getMbPicType(), rcRefPicCol ) );
ascRefIdx[LIST_0] = getSH().getRefPicList( getMbPicType(), LIST_0 ).find( cRefPic );
SChar sMaxRefIdx = (getSH().isMbAff() && getMbPicType() != FRAME ) ? getSH().getNumRefIdxActive(LIST_0) *2 :
getSH().getNumRefIdxActive(LIST_0);
if(ascRefIdx[LIST_0] < 1 || ascRefIdx[LIST_0] > sMaxRefIdx)
{
ROFRS( bFaultTolerant, false ); // not allowed
ascRefIdx[LIST_0] = 1;
}
}
else
{
ROFRS( bFaultTolerant, false ); // not allowed
}
}
Int iScale = getSH().getDistScaleFactor( getMbPicType(), ascRefIdx[LIST_0], ascRefIdx[LIST_1] );
if( iScale == 1024 )
{
acMv[LIST_0] = cMvCol;
acMv[LIST_1] = Mv::ZeroMv();
}
else
{
acMv[LIST_0] = cMvCol.scaleMv( iScale );
acMv[LIST_1] = acMv[LIST_0] - cMvCol;
}
const Bool bMvValid = xCheckMv( acMv[LIST_0]);
return bMvValid;
}
// TMM_EC {{
Bool MbDataAccess::xTemporalDirectModeMvRefVirtual( Mv acMv[], SChar ascRefIdx[], LumaIdx cIdx, Bool bFaultTolerant, RefFrameList& rcRefFrameListL0, RefFrameList& rcRefFrameListL1 )
{
SChar scRefIdxCol;
Mv cMvCol;
const RefPic& rcRefPicCol = xGetColocatedMvRefPic( cMvCol, scRefIdxCol, cIdx );
//----- get reference index for list 0 -----
if( scRefIdxCol > 0 )
{
if( rcRefPicCol.isAvailable() )
{
const RefPic cRefPic = ( ( getMbPicType() != FRAME && rcRefPicCol.getFrame()->getPicType() != FRAME ) ? rcRefPicCol :
rcRefPicCol.getFrame()->getFrameUnit()->getRefPic( getMbPicType(), rcRefPicCol ) );
ascRefIdx[LIST_0] = getSH().getRefPicList( getMbPicType(), LIST_0 ).find( cRefPic );
SChar sMaxRefIdx = (getSH().isMbAff() && getMbPicType() != FRAME ) ? getSH().getNumRefIdxActive(LIST_0) *2 :
getSH().getNumRefIdxActive(LIST_0);
if(ascRefIdx[LIST_0] < 1 || ascRefIdx[LIST_0] > sMaxRefIdx)
{
ROFRS( bFaultTolerant, false ); // not allowed
ascRefIdx[LIST_0] = 1;
}
}
else
{
ROFRS( bFaultTolerant, false ); // not allowed
}
}
Int iScale = getSH().getDistScaleFactorVirtual(getMbPicType(), ascRefIdx[LIST_0], ascRefIdx[LIST_1], rcRefFrameListL0, rcRefFrameListL1 );// TMM_INTERLACE
if( iScale == 1024 )
{
acMv[LIST_0] = cMvCol;
acMv[LIST_1] = Mv::ZeroMv();
}
else
{
acMv[LIST_0] = cMvCol.scaleMv( iScale );
acMv[LIST_1] = acMv[LIST_0] - cMvCol;
}
const Bool bMvValid = xCheckMv( acMv[LIST_0]);
return bMvValid;
}
// TMM_EC }}
Bool MbDataAccess::xTemporalDirectModeMvsRefNonInterlaced( Mv aacMv[][4], SChar ascRefIdx[], ParIdx8x8 eParIdx, Bool bFaultTolerant )
{
SChar scRefIdxCol;
Mv acMvCol[4];
const RefPic& rcRefPicCol = xGetColocatedMvsRefPicNonInterlaced( acMvCol, scRefIdxCol, eParIdx );
//----- get reference index for list 0 -----
if( scRefIdxCol > 0 )
{
if( rcRefPicCol.isAvailable() )
{
const RefPic cRefPic = rcRefPicCol.getFrame()->getFrameUnit()->getRefPic( getMbPicType(), rcRefPicCol );
ascRefIdx[LIST_0] = getSH().getRefPicList( getMbPicType(), LIST_0 ).find( cRefPic );
if(ascRefIdx[LIST_0] < 1 || ascRefIdx[LIST_0] > (SChar)getSH().getNumRefIdxActive(LIST_0))
{
ROFRS( bFaultTolerant, false ); // not allowed
ascRefIdx[LIST_0] = 1;
}
}
else
{
ROFRS( bFaultTolerant, false ); // not allowed
}
}
bool bMvValid = true;
Int iScale = 1024;
if( m_rcSliceHeader.getRefPicList( getMbPicType(), LIST_1 ).size() )
{
iScale = m_rcSliceHeader.getDistScaleFactor ( getMbPicType(), ascRefIdx[LIST_0], ascRefIdx[LIST_1] );
}
else
{
iScale = m_rcSliceHeader.getDistScaleFactorScal ( getMbPicType(), ascRefIdx[LIST_0], ascRefIdx[LIST_1] );
}
if( iScale == 1024 )
{
for( UInt uiIndex = 0; uiIndex < 4; uiIndex++ )
{
aacMv[LIST_0][uiIndex] = acMvCol[uiIndex];
aacMv[LIST_1][uiIndex] = Mv::ZeroMv();
}
}
else
{
for( UInt uiIndex = 0; uiIndex < 4; uiIndex++ )
{
aacMv[LIST_0][uiIndex] = acMvCol[uiIndex].scaleMv( iScale );
aacMv[LIST_1][uiIndex] = aacMv[LIST_0][uiIndex] - acMvCol[uiIndex];
bMvValid &= xCheckMv( aacMv[LIST_0][uiIndex] );
}
}
return bMvValid;
}
Bool MbDataAccess::xTemporalDirectMode( ParIdx8x8 eParIdx, Bool b8x8, Bool bFaultTolerant )
{
Bool bModeAllowed;
SChar ascRefIdx[2] = { 1, 1 };
if( b8x8 )
{
Mv acMv[2];
SParIdx4x4 eSubMbPartIdx = ( eParIdx <= PART_8x8_1 ? ( eParIdx == PART_8x8_0 ? SPART_4x4_0 : SPART_4x4_1 )
: ( eParIdx == PART_8x8_2 ? SPART_4x4_2 : SPART_4x4_3 ) );
B4x4Idx cIdx = B4x4Idx( eParIdx + eSubMbPartIdx );
bModeAllowed = xTemporalDirectModeMvRef( acMv, ascRefIdx, cIdx, bFaultTolerant );
ROFRS( bModeAllowed, bModeAllowed );
for( UInt uiLstIdx = 0; uiLstIdx < 2; uiLstIdx++ )
{
ListIdx eListIdx = ListIdx( uiLstIdx );
MbMotionData& rcMbMotionDataLX = getMbMotionData( eListIdx );
if( m_rcSliceHeader.getRefPicList( getMbPicType(), eListIdx ).size() )
{
const Frame* pcFrame = ( ascRefIdx[eListIdx] < 1 ? 0 : m_rcSliceHeader.getRefPic ( ascRefIdx[eListIdx], getMbPicType(), eListIdx ).getFrame() );
rcMbMotionDataLX.setRefPic( pcFrame, eParIdx );
}
rcMbMotionDataLX.setAllMv ( acMv [eListIdx], eParIdx );
rcMbMotionDataLX.setRefIdx( ascRefIdx[eListIdx], eParIdx );
}
}
else // do not do this for interlaced stuff
{
Mv aacMv[2][4];
bModeAllowed = xTemporalDirectModeMvsRefNonInterlaced( aacMv, ascRefIdx, eParIdx, bFaultTolerant );
ROFRS( bModeAllowed, bModeAllowed );
for( UInt uiLstIdx = 0; uiLstIdx < 2; uiLstIdx++ )
{
ListIdx eListIdx = ListIdx( uiLstIdx );
MbMotionData& rcMbMotionDataLX = getMbMotionData( eListIdx );
if( m_rcSliceHeader.getRefPicList( getMbPicType(), eListIdx ).size() )
{
const Frame* pcFrame = ( ascRefIdx[eListIdx] < 1 ? 0 : m_rcSliceHeader.getRefPic ( ascRefIdx[eListIdx], getMbPicType(), eListIdx ).getFrame() );
rcMbMotionDataLX.setRefPic( pcFrame, eParIdx );
}
rcMbMotionDataLX.setRefIdx( ascRefIdx[eListIdx], eParIdx );
rcMbMotionDataLX.setAllMv ( aacMv[eListIdx][0], eParIdx, SPART_4x4_0 );
rcMbMotionDataLX.setAllMv ( aacMv[eListIdx][1], eParIdx, SPART_4x4_1 );
rcMbMotionDataLX.setAllMv ( aacMv[eListIdx][2], eParIdx, SPART_4x4_2 );
rcMbMotionDataLX.setAllMv ( aacMv[eListIdx][3], eParIdx, SPART_4x4_3 );
}
}
return bModeAllowed;
}
//TMM_EC {{
Bool MbDataAccess::xTemporalDirectModeVirtual( ParIdx8x8 eParIdx, Bool b8x8, Bool bFaultTolerant, RefFrameList& rcRefFrameListL0, RefFrameList& rcRefFrameListL1 )
{
Bool bModeAllowed;
SChar ascRefIdx[2] = { 1, 1 };
if( b8x8 )
{
Mv acMv[2];
SParIdx4x4 eSubMbPartIdx = ( eParIdx <= PART_8x8_1 ? ( eParIdx == PART_8x8_0 ? SPART_4x4_0 : SPART_4x4_1 )
: ( eParIdx == PART_8x8_2 ? SPART_4x4_2 : SPART_4x4_3 ) );
B4x4Idx cIdx = B4x4Idx( eParIdx + eSubMbPartIdx );
bModeAllowed = xTemporalDirectModeMvRefVirtual( acMv, ascRefIdx, cIdx, bFaultTolerant, rcRefFrameListL0, rcRefFrameListL1 );
ROFRS( bModeAllowed, bModeAllowed );
for( UInt uiLstIdx = 0; uiLstIdx < 2; uiLstIdx++ )
{
ListIdx eListIdx = ListIdx( uiLstIdx );
MbMotionData& rcMbMotionDataLX = getMbMotionData( eListIdx );
if( m_rcSliceHeader.getNumRefIdxActive( LIST_1) != 0)
{
RefFrameList *pcRefFrameList;
if ( eListIdx == LIST_0)
pcRefFrameList = &rcRefFrameListL0;
else
pcRefFrameList = &rcRefFrameListL1;
}
rcMbMotionDataLX.setAllMv ( acMv [eListIdx], eParIdx );
rcMbMotionDataLX.setRefIdx( ascRefIdx[eListIdx], eParIdx );
}
}
else // do not do this for interlaced stuff
{
Mv aacMv[2][4];
bModeAllowed = xTemporalDirectModeMvsRefNonInterlaced( aacMv, ascRefIdx, eParIdx, bFaultTolerant );
ROFRS( bModeAllowed, bModeAllowed );
for( UInt uiLstIdx = 0; uiLstIdx < 2; uiLstIdx++ )
{
ListIdx eListIdx = ListIdx( uiLstIdx );
MbMotionData& rcMbMotionDataLX = getMbMotionData( eListIdx );
if( m_rcSliceHeader.getRefPicList( getMbPicType(), LIST_1).size() )// TMM_INTERLACE
{
const Frame* pcFrame = ( ascRefIdx[eListIdx] < 1 ? 0 : m_rcSliceHeader.getRefPic ( ascRefIdx[eListIdx], getMbPicType(), eListIdx ).getFrame() );// TMM_INTERLACE
rcMbMotionDataLX.setRefPic( pcFrame, eParIdx );
}
rcMbMotionDataLX.setRefIdx( ascRefIdx[eListIdx], eParIdx );
rcMbMotionDataLX.setAllMv ( aacMv[eListIdx][0], eParIdx, SPART_4x4_0 );
rcMbMotionDataLX.setAllMv ( aacMv[eListIdx][1], eParIdx, SPART_4x4_1 );
rcMbMotionDataLX.setAllMv ( aacMv[eListIdx][2], eParIdx, SPART_4x4_2 );
rcMbMotionDataLX.setAllMv ( aacMv[eListIdx][3], eParIdx, SPART_4x4_3 );
}
}
return bModeAllowed; // OK
}
//TMM_EC }}
H264AVC_NAMESPACE_END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -