Commit 9dc004f9 authored by Yan Zhang's avatar Yan Zhang

1/16-pel motion vector storage

Motion vecotrs are always stored with 1/16-pel precision and the High
precision motion vector SPS flags are removed.

The following strategies are followed:

1. Motion vector data in the buffer are always stored in high precision.
2. Motion vector used for motion compensation are always in high
precision.
3. Motion vector difference data are always in low precision.
4. Encoder side motion estimation always use low precision.
5. Motion vector bits calculation are always performed in low precision.
6. Candidates of motion vector prediction list are always in low
precision.
parent 6178ac75
......@@ -110,7 +110,7 @@ RCForceIntraQP : 0 # Rate control: force int
#============ JEM settings ======================
LoopFilterTcOffset_div2 : 0
SEIDecodedPictureHash : 0
SEIDecodedPictureHash : 1
CbQpOffset : 0
CrQpOffset : 0
......@@ -135,7 +135,7 @@ MTT : 1
EMT : 3
EMTFast : 3
Affine : 1
HighPrecMv : 1
#HighPrecMv : 1
SubPuMvp : 1
MaxNumMergeCand : 6
LMChroma : 1
......@@ -158,3 +158,4 @@ AMaxBT : 1
### DO NOT ADD ANYTHING BELOW THIS LINE ###
### DO NOT DELETE THE EMPTY LINE BELOW ###
......@@ -241,7 +241,9 @@ void EncApp::xInitLibCfg()
#endif
#endif
#if JEM_TOOLS
#if !REMOVE_MV_ADAPT_PREC
m_cEncLib.setHighPrecisionMv ( m_highPrecisionMv );
#endif
m_cEncLib.setAffine ( m_Affine );
#if JVET_K0337_AFFINE_6PARA
m_cEncLib.setAffineType ( m_AffineType );
......
......@@ -833,10 +833,14 @@ bool EncAppCfg::parseCfg( int argc, char* argv[] )
("SubPuMvp", m_SubPuMvpMode, 0, "Enable Sub-PU temporal motion vector prediction (0:off, 1:on) [default: off]")
#endif
("SubPuMvpLog2Size", m_SubPuMvpLog2Size, 2u, "Sub-PU TMVP size index: 2^n")
#if !REMOVE_MV_ADAPT_PREC
("HighPrecMv", m_highPrecisionMv, false, "High precision motion vectors for temporal merging (0:off, 1:on) [default: off]")
#endif
#endif
#if JEM_TOOLS || JVET_K_AFFINE
#if !REMOVE_MV_ADAPT_PREC
("HighPrecMv", m_highPrecisionMv, false, "High precision motion vectors for temporal merging (0:off, 1:on) [default: off]")
#endif
("Affine", m_Affine, false, "Enable affine prediction (0:off, 1:on) [default: off]")
#if JVET_K0337_AFFINE_6PARA
( "AffineType", m_AffineType, true, "Enable affine type prediction (0:off, 1:on) [default: on]" )
......@@ -2122,8 +2126,10 @@ bool EncAppCfg::xCheckParameter()
xConfirmPara( !( m_OBMCBlkSize == 4 || m_OBMCBlkSize == 8 ), "OBMC Block Size must be set to 4 or 8 samples" );
#endif
#if JVET_K_AFFINE
#if !REMOVE_MV_ADAPT_PREC
xConfirmPara( m_Affine && !m_highPrecisionMv, "Affine is not yet implemented for HighPrecMv off." );
#endif
#endif
#if JEM_TOOLS
xConfirmPara( m_DMVR && !m_QTBT, "DMVR without QTBT results in encoder-decoder mismatch!" );
#endif
......@@ -3403,11 +3409,15 @@ void EncAppCfg::xPrintParameter()
#endif
#endif
#if JEM_TOOLS
#if !REMOVE_MV_ADAPT_PREC
msg( VERBOSE, "HighPrecMv:%d ", m_highPrecisionMv );
#endif
msg( VERBOSE, "BIO:%d ", m_BIO );
#endif
#if !JEM_TOOLS && (JVET_K0346 || JVET_K_AFFINE)
#if !REMOVE_MV_ADAPT_PREC
msg(VERBOSE, "HighPrecMv:%d ", m_highPrecisionMv);
#endif
#endif
msg( VERBOSE, "DisMDC:%d ", m_DisableMotionCompression );
#if JEM_TOOLS
......
......@@ -769,7 +769,7 @@ void MergeCtx::setMergeInfo( PredictionUnit& pu, int candIdx )
{
pu.cu->ibc = true;
pu.bv = pu.mv[REF_PIC_LIST_0];
#if REMOVE_MV_ADAPT_PREC
#if REMOVE_MV_ADAPT_PREC
pu.bv >>= (2 + VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE);
#else
pu.bv >>= 2; // used for only integer resolution
......
This diff is collapsed.
......@@ -324,8 +324,11 @@ protected:
#endif
void xFrucUpdateTemplate (PredictionUnit& pu, int nWidth, int nHeight, RefPicList eCurRefPicList, const MvField& rCurMvField );
#if REMOVE_MV_ADAPT_PREC
void xFrucInsertMv2StartList (const MvField & rMvField, std::list<MvField> & rList);
#else
void xFrucInsertMv2StartList (const MvField & rMvField, std::list<MvField> & rList,bool setHighPrec);
#endif
bool xFrucIsInList (const MvField & rMvField, std::list<MvField> & rList);
bool xFrucGetCurBlkTemplate (PredictionUnit& pu, int nCurBlkWidth , int nCurBlkHeight);
......
......@@ -506,16 +506,18 @@ unsigned LoopFilter::xGetBoundaryStrengthSingle ( const CodingUnit& cu, const De
int nThreshold = 4;
#if JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE
#if !REMOVE_MV_ADAPT_PREC
if( cu.cs->sps->getSpsNext().getUseHighPrecMv() )
{
#if !REMOVE_MV_ADAPT_PREC
mvP0.setHighPrec();
mvP1.setHighPrec();
mvQ0.setHighPrec();
mvQ1.setHighPrec();
#endif
nThreshold = 4 << VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
#if !REMOVE_MV_ADAPT_PREC
}
#endif
#endif
unsigned uiBs = 0;
......@@ -571,14 +573,16 @@ unsigned LoopFilter::xGetBoundaryStrengthSingle ( const CodingUnit& cu, const De
int nThreshold = 4;
#if JEM_TOOLS || JVET_K0346 || JVET_K_AFFINE
#if !REMOVE_MV_ADAPT_PREC
if( cu.cs->sps->getSpsNext().getUseHighPrecMv() )
{
#if !REMOVE_MV_ADAPT_PREC
mvP0.setHighPrec();
mvQ0.setHighPrec();
#endif
nThreshold = 4 << VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
#if !REMOVE_MV_ADAPT_PREC
}
#endif
#endif
return ( ( abs( mvQ0.getHor() - mvP0.getHor() ) >= nThreshold ) || ( abs( mvQ0.getVer() - mvP0.getVer() ) >= nThreshold ) ) ? 1 : 0;
}
......
......@@ -71,10 +71,7 @@ void clipMv( Mv& rcMv, const Position& pos, const SPS& sps )
int iMvShift = 2;
#endif
#if REMOVE_MV_ADAPT_PREC
if (sps.getSpsNext().getUseHighPrecMv())
{
iMvShift += VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
}
#endif
int iOffset = 8;
int iHorMax = ( sps.getPicWidthInLumaSamples() + iOffset - ( int ) pos.x - 1 ) << iMvShift;
......
......@@ -1836,11 +1836,15 @@ SPSNext::SPSNext( SPS& sps )
#endif
#endif
#if JEM_TOOLS
#if !REMOVE_MV_ADAPT_PREC
, m_highPrecMv ( false )
#endif
, m_BIO ( false )
#endif
#if !JEM_TOOLS && (JVET_K0346 || JVET_K_AFFINE)
#if !REMOVE_MV_ADAPT_PREC
, m_highPrecMv ( false )
#endif
#endif
, m_DisableMotionCompression ( false )
#if JEM_TOOLS
......
......@@ -829,11 +829,15 @@ private:
#endif
#endif
#if JEM_TOOLS
#if !REMOVE_MV_ADAPT_PREC
bool m_highPrecMv; // 11
#endif
bool m_BIO; // 12
#endif
#if !JEM_TOOLS && (JVET_K0346 || JVET_K_AFFINE)
#if !REMOVE_MV_ADAPT_PREC
bool m_highPrecMv;
#endif
#endif
bool m_DisableMotionCompression; // 13
#if JEM_TOOLS
......@@ -1016,14 +1020,18 @@ public:
#endif
#endif
#if JEM_TOOLS
#if !REMOVE_MV_ADAPT_PREC
void setUseHighPrecMv ( bool b ) { m_highPrecMv = b; }
bool getUseHighPrecMv () const { return m_highPrecMv; }
#endif
void setUseBIO ( bool b ) { m_BIO = b; }
bool getUseBIO () const { return m_BIO; }
#endif
#if !JEM_TOOLS && (JVET_K0346 || JVET_K_AFFINE)
#if !REMOVE_MV_ADAPT_PREC
void setUseHighPrecMv(bool b) { m_highPrecMv = b; }
bool getUseHighPrecMv() const { return m_highPrecMv; }
#endif
#endif
void setDisableMotCompress ( bool b ) { m_DisableMotionCompression = b; }
bool getDisableMotCompress () const { return m_DisableMotionCompression; }
......
......@@ -92,11 +92,12 @@ static void xInitFrucMvpEl( CodingStructure& cs, int x, int y, int nCurPOC, int
int nColRefPOC = pColPic->cs->slice->getRefPOC( eRefPicList, frucMi.refIdx[eRefPicList] );
Mv mvColPic = frucMi.mv[eRefPicList];
#if !REMOVE_MV_ADAPT_PREC
if( cs.sps->getSpsNext().getUseHighPrecMv() )
{
mvColPic.setHighPrec();
}
#endif
#if JVET_K0157
Mv mv2CurRefPic;
if (cs.slice->getRefPic(eRefPicList, frucMi.refIdx[eRefPicList])->longTerm)
......@@ -109,19 +110,22 @@ static void xInitFrucMvpEl( CodingStructure& cs, int x, int y, int nCurPOC, int
int xCurPic = 0;
int yCurPic = 0;
#if !REMOVE_MV_ADAPT_PREC
if( cs.sps->getSpsNext().getUseHighPrecMv() )
{
#endif
int nOffset = 1 << ( VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE + 1 );
xCurPic = x + ( MIN_PU_SIZE >> 1 ) - ( ( mv2CurRefPic.getHor() + nOffset ) >> ( 2 + VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE ) );
yCurPic = y + ( MIN_PU_SIZE >> 1 ) - ( ( mv2CurRefPic.getVer() + nOffset ) >> ( 2 + VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE ) );
#if !REMOVE_MV_ADAPT_PREC
}
else
{
xCurPic = x - ( ( mv2CurRefPic.getHor() + 2 ) >> 2 ) + ( MIN_PU_SIZE >> 1 );
yCurPic = y - ( ( mv2CurRefPic.getVer() + 2 ) >> 2 ) + ( MIN_PU_SIZE >> 1 );
}
#endif
if( 0 <= xCurPic && xCurPic < cs.picture->Y().width && 0 <= yCurPic && yCurPic < cs.picture->Y().height )
{
MotionInfo &curMiFRUC = cs.getMotionInfoFRUC( Position{ xCurPic, yCurPic } );
......@@ -2239,10 +2243,7 @@ void PU::fillMvpCand(PredictionUnit &pu, const RefPicList &eRefPicList, const in
{
unsigned imvShift = pu.cu->imv << 1;
#if REMOVE_MV_ADAPT_PREC
if (pu.cs->sps->getSpsNext().getUseHighPrecMv())
{
imvShift += VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
}
#endif
for( int i = 0; i < pInfo->numCand; i++ )
{
......@@ -2344,9 +2345,10 @@ void PU::fillMvpCand(PredictionUnit &pu, const RefPicList &eRefPicList, const in
#endif
pInfo->numCand++;
}
#if !REMOVE_MV_ADAPT_PREC
if( pu.cs->sps->getSpsNext().getUseHighPrecMv() )
{
#endif
for( Mv &mv : pInfo->mvCand )
{
#if REMOVE_MV_ADAPT_PREC
......@@ -2355,7 +2357,9 @@ void PU::fillMvpCand(PredictionUnit &pu, const RefPicList &eRefPicList, const in
if (mv.highPrec) mv.setLowPrec();
#endif
}
#if !REMOVE_MV_ADAPT_PREC
}
#endif
#if JVET_K0357_AMVR
if (pu.cu->imv != 0)
{
......@@ -3311,13 +3315,15 @@ bool PU::getInterMergeSubPuMvpCand( const PredictionUnit &pu, MergeCtx& mrgCtx,
//////// GET Initial Temporal Vector ////////
///////////////////////////////////////////////////////////////////////
int mvPrec = 2;
#if !REMOVE_MV_ADAPT_PREC
if( pu.cs->sps->getSpsNext().getUseHighPrecMv() )
{
#if !REMOVE_MV_ADAPT_PREC
cTMv.setHighPrec();
#endif
mvPrec += VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
#if !REMOVE_MV_ADAPT_PREC
}
#endif
int mvRndOffs = ( 1 << mvPrec ) >> 1;
Mv cTempVector = cTMv;
......@@ -4465,13 +4471,15 @@ bool PU::getInterMergeSubPuMvpCand(const PredictionUnit &pu, MergeCtx& mrgCtx, b
//////// GET Initial Temporal Vector ////////
///////////////////////////////////////////////////////////////////////
int mvPrec = 2;
#if !REMOVE_MV_ADAPT_PREC
if (pu.cs->sps->getSpsNext().getUseHighPrecMv())
{
#if !REMOVE_MV_ADAPT_PREC
cTMv.setHighPrec();
#endif
mvPrec += VCEG_AZ07_MV_ADD_PRECISION_BIT_FOR_STORE;
#if !REMOVE_MV_ADAPT_PREC
}
#endif
int mvRndOffs = (1 << mvPrec) >> 1;
Mv cTempVector = cTMv;
......@@ -4883,11 +4891,7 @@ void PU::applyImv( PredictionUnit& pu, MergeCtx &mrgCtx, InterPrediction *interP
pu.mvpIdx[0] = mvp_idx;
pu.mv [0] = amvpInfo.mvCand[mvp_idx] + pu.mvd[0];
#if REMOVE_MV_ADAPT_PREC
if (pu.cs->sps->getSpsNext().getUseAffine()
|| pu.cs->sps->getSpsNext().getUseHighPrecMv())
{
pu.mv[0].setHighPrec();
}
#endif
#if JVET_K0076_CPR
if (pu.interDir == 1 && pu.cs->slice->getRefPic(REF_PIC_LIST_0, pu.refIdx[REF_PIC_LIST_0])->getPOC() == pu.cs->slice->getPOC())
......@@ -4917,11 +4921,7 @@ void PU::applyImv( PredictionUnit& pu, MergeCtx &mrgCtx, InterPrediction *interP
pu.mvpIdx[1] = mvp_idx;
pu.mv [1] = amvpInfo.mvCand[mvp_idx] + pu.mvd[1];
#if REMOVE_MV_ADAPT_PREC
if (pu.cs->sps->getSpsNext().getUseAffine()
|| pu.cs->sps->getSpsNext().getUseHighPrecMv())
{
pu.mv[1].setHighPrec();
}
pu.mv[1].setHighPrec();
#endif
}
}
......
......@@ -677,13 +677,8 @@ void DecCu::xDeriveCUMV( CodingUnit &cu )
#else
pu.mv [eRefList] = amvpInfo.mvCand[pu.mvpIdx [eRefList]] + pu.mvd[eRefList];
#endif
#if JEM_TOOLS || JVET_K_AFFINE
if( pu.cs->sps->getSpsNext().getUseAffine()
#if REMOVE_MV_ADAPT_PREC
|| pu.cs->sps->getSpsNext().getUseHighPrecMv()
#endif
)
if( pu.cs->sps->getSpsNext().getUseAffine())
{
pu.mv[eRefList].setHighPrec();
}
......
......@@ -828,11 +828,15 @@ void HLSyntaxReader::parseSPSNext( SPSNext& spsNext, const bool usePCM )
#endif
#endif
#if JEM_TOOLS
#if !REMOVE_MV_ADAPT_PREC
READ_FLAG( symbol, "high_precision_motion_vectors" ); spsNext.setUseHighPrecMv ( symbol != 0 );
#endif
READ_FLAG( symbol, "bio_enable_flag" ); spsNext.setUseBIO ( symbol != 0 );
#endif
#if !JEM_TOOLS && (JVET_K0346 || JVET_K_AFFINE)
#if !REMOVE_MV_ADAPT_PREC
READ_FLAG( symbol, "high_precision_motion_vectors" ); spsNext.setUseHighPrecMv(symbol != 0);
#endif
#endif
READ_FLAG( symbol, "disable_motion_compression_flag" ); spsNext.setDisableMotCompress ( symbol != 0 );
#if JEM_TOOLS
......
......@@ -228,7 +228,9 @@ protected:
#endif
#endif
#if JEM_TOOLS
#if !REMOVE_MV_ADAPT_PREC
bool m_highPrecMv;
#endif
bool m_Affine;
#if JVET_K0337_AFFINE_6PARA
bool m_AffineType;
......@@ -242,7 +244,9 @@ protected:
#endif
#endif
#if !JEM_TOOLS && (JVET_K0346 || JVET_K_AFFINE)
#if !REMOVE_MV_ADAPT_PREC
bool m_highPrecMv;
#endif
#endif
bool m_DisableMotionCompression;
#if JEM_TOOLS
......@@ -738,8 +742,10 @@ public:
#endif
#endif
#if JEM_TOOLS
#if !REMOVE_MV_ADAPT_PREC
void setHighPrecisionMv ( bool b ) { m_highPrecMv = b; }
bool getHighPrecisionMv () { return m_highPrecMv; }
#endif
void setBIO ( bool b ) { m_BIO = b; }
bool getBIO () const { return m_BIO; }
......@@ -760,8 +766,10 @@ public:
#endif
#endif
#if !JEM_TOOLS && (JVET_K0346 || JVET_K_AFFINE)
#if !REMOVE_MV_ADAPT_PREC
void setHighPrecisionMv(bool b) { m_highPrecMv = b; }
bool getHighPrecisionMv() { return m_highPrecMv; }
#endif
#endif
void setDisableMotionCompression ( bool b ) { m_DisableMotionCompression = b; }
bool getDisableMotionCompression () const { return m_DisableMotionCompression; }
......
......@@ -965,7 +965,9 @@ void EncLib::xInitSPS(SPS &sps)
#endif
#endif
#if JEM_TOOLS || JVET_K_AFFINE
#if !REMOVE_MV_ADAPT_PREC
sps.getSpsNext().setUseHighPrecMv ( m_highPrecMv );
#endif
sps.getSpsNext().setUseAffine ( m_Affine );
#if JVET_K0337_AFFINE_6PARA
sps.getSpsNext().setUseAffineType ( m_AffineType );
......@@ -975,7 +977,9 @@ void EncLib::xInitSPS(SPS &sps)
sps.getSpsNext().setUseBIO ( m_BIO );
#endif
#if !JEM_TOOLS && JVET_K0346 && !JVET_K_AFFINE
#if !REMOVE_MV_ADAPT_PREC
sps.getSpsNext().setUseHighPrecMv(m_highPrecMv);
#endif
#endif
sps.getSpsNext().setDisableMotCompress ( m_DisableMotionCompression );
#if JEM_TOOLS
......
......@@ -2955,7 +2955,11 @@ void InterSearch::xMotionEstimation(PredictionUnit& pu, PelUnitBuf& origBuf, Ref
{
xPatternSearchIntRefine( pu, cStruct, rcMv, rcMvPred, riMVPIdx, ruiBits, ruiCost, amvpInfo, fWeight);
}
DTRACE( g_trace_ctx, D_ME, " MECost<L%d,%d>: %6d (%d) MV:%d,%d\n", ( int ) eRefPicList, ( int ) bBi, ruiCost, ruiBits, rcMv.getHor() << ( pu.cs->sps->getSpsNext().getUseHighPrecMv() ? 2 : 0 ), rcMv.getVer() << ( pu.cs->sps->getSpsNext().getUseHighPrecMv() ? 2 : 0 ) );
#if REMOVE_MV_ADAPT_PREC
DTRACE( g_trace_ctx, D_ME, " MECost<L%d,%d>: %6d (%d) MV:%d,%d\n", ( int ) eRefPicList, ( int ) bBi, ruiCost, ruiBits, rcMv.getHor() << 2, rcMv.getVer() << 2);
#else
DTRACE(g_trace_ctx, D_ME, " MECost<L%d,%d>: %6d (%d) MV:%d,%d\n", (int)eRefPicList, (int)bBi, ruiCost, ruiBits, rcMv.getHor() << (pu.cs->sps->getSpsNext().getUseHighPrecMv() ? 2 : 0), rcMv.getVer() << (pu.cs->sps->getSpsNext().getUseHighPrecMv() ? 2 : 0));
#endif
#else
DTRACE( g_trace_ctx, D_ME, " MECost<L%d,%d>: %6d (%d) MV:%d,%d\n", ( int ) eRefPicList, ( int ) bBi, ruiCost, ruiBits, rcMv.getHor(), rcMv.getVer() );
#endif
......
......@@ -565,11 +565,15 @@ void HLSWriter::codeSPSNext( const SPSNext& spsNext, const bool usePCM )
#endif
#endif
#if JEM_TOOLS
#if !REMOVE_MV_ADAPT_PREC
WRITE_FLAG( spsNext.getUseHighPrecMv() ? 1 : 0, "high_precision_motion_vectors" );
#endif
WRITE_FLAG( spsNext.getUseBIO() ? 1 : 0, "bio_enable_flag" );
#endif
#if !JEM_TOOLS && (JVET_K0346 || JVET_K_AFFINE)
#if !REMOVE_MV_ADAPT_PREC
WRITE_FLAG(spsNext.getUseHighPrecMv() ? 1 : 0, "high_precision_motion_vectors");
#endif
#endif
WRITE_FLAG( spsNext.getDisableMotCompress() ? 1 : 0, "disable_motion_compression_flag" );
#if JEM_TOOLS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment