Newer
Older

Karsten Suehring
committed
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
reco.copyFrom( *m_pcDeblockingTempPicYuv );
const uint64_t dist = preLoopFilterPicAndCalcDist( pcPic );
if(dist < distMin)
{
distMin = dist;
bDBFilterDisabledBest = false;
betaOffsetDiv2Best = betaOffsetDiv2;
tcOffsetDiv2Best = tcOffsetDiv2;
}
if(dist < distTcMin)
{
distTcMin = dist;
}
else if(tcOffsetDiv2 <-2)
{
break;
}
}
if(betaOffsetDiv2<-1 && distTcMin >= distBetaPrevious)
{
break;
}
distBetaPrevious = distTcMin;
}
//update:
m_DBParam[currQualityLayer][DBFLT_PARAM_AVAILABLE] = 1;
m_DBParam[currQualityLayer][DBFLT_DISABLE_FLAG] = bDBFilterDisabledBest;
m_DBParam[currQualityLayer][DBFLT_BETA_OFFSETD2] = betaOffsetDiv2Best;
m_DBParam[currQualityLayer][DBFLT_TC_OFFSETD2] = tcOffsetDiv2Best;
// restore reconstruction
reco.copyFrom( *m_pcDeblockingTempPicYuv );
const PPS* pcPPS = pcPic->slices[0]->getPPS();
if(bDBFilterDisabledBest)
{
for (int i=0; i<numSlices; i++)
{
Slice* pcSlice = pcPic->slices[i];
pcSlice->setDeblockingFilterOverrideFlag( true);
pcSlice->setDeblockingFilterDisable ( true);
}
}
else if(betaOffsetDiv2Best == pcPPS->getDeblockingFilterBetaOffsetDiv2() && tcOffsetDiv2Best == pcPPS->getDeblockingFilterTcOffsetDiv2())
{
for (int i=0; i<numSlices; i++)
{
Slice* pcSlice = pcPic->slices[i];
pcSlice->setDeblockingFilterOverrideFlag ( false);
pcSlice->setDeblockingFilterDisable ( pcPPS->getPPSDeblockingFilterDisabledFlag() );
pcSlice->setDeblockingFilterBetaOffsetDiv2 ( pcPPS->getDeblockingFilterBetaOffsetDiv2() );
pcSlice->setDeblockingFilterTcOffsetDiv2 ( pcPPS->getDeblockingFilterTcOffsetDiv2() );
pcSlice->setDeblockingFilterCbBetaOffsetDiv2 ( pcPPS->getDeblockingFilterBetaOffsetDiv2() );
pcSlice->setDeblockingFilterCbTcOffsetDiv2 ( pcPPS->getDeblockingFilterTcOffsetDiv2() );
pcSlice->setDeblockingFilterCrBetaOffsetDiv2 ( pcPPS->getDeblockingFilterBetaOffsetDiv2() );
pcSlice->setDeblockingFilterCrTcOffsetDiv2 ( pcPPS->getDeblockingFilterTcOffsetDiv2() );

Karsten Suehring
committed
}
}
else
{
for (int i=0; i<numSlices; i++)
{
Slice* pcSlice = pcPic->slices[i];
pcSlice->setDeblockingFilterOverrideFlag ( true);
pcSlice->setDeblockingFilterDisable ( false );
pcSlice->setDeblockingFilterBetaOffsetDiv2 ( betaOffsetDiv2Best);
pcSlice->setDeblockingFilterTcOffsetDiv2 ( tcOffsetDiv2Best);
pcSlice->setDeblockingFilterCbBetaOffsetDiv2 ( betaOffsetDiv2Best);
pcSlice->setDeblockingFilterCbTcOffsetDiv2 ( tcOffsetDiv2Best);
pcSlice->setDeblockingFilterCrBetaOffsetDiv2 ( betaOffsetDiv2Best);
pcSlice->setDeblockingFilterCrTcOffsetDiv2 ( tcOffsetDiv2Best);

Karsten Suehring
committed
}
}
}
#endif
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
void EncGOP::xCreateExplicitReferencePictureSetFromReference( Slice* slice, PicList& rcListPic, const ReferencePictureList *rpl0, const ReferencePictureList *rpl1 )
{
Picture* rpcPic;
int pocCycle = 0;
Picture* pic = slice->getPic();
const VPS* vps = slice->getPic()->cs->vps;
int layerIdx = vps == nullptr ? 0 : vps->getGeneralLayerIdx( pic->layerId );
ReferencePictureList* pLocalRPL0 = slice->getLocalRPL0();
*pLocalRPL0 = ReferencePictureList( slice->getSPS()->getInterLayerPresentFlag() );
uint32_t numOfSTRPL0 = 0;
uint32_t numOfLTRPL0 = 0;
uint32_t numOfILRPL0 = 0;
uint32_t numOfRefPic = rpl0->getNumberOfShorttermPictures() + rpl0->getNumberOfLongtermPictures();
uint32_t refPicIdxL0 = 0;
for( int ii = 0; ii < numOfRefPic; ii++ )
{
// loop through all pictures in the reference picture buffer
PicList::iterator iterPic = rcListPic.begin();
bool isAvailable = false;
pocCycle = 1 << ( slice->getSPS()->getBitsForPOC() );
while( iterPic != rcListPic.end() )
{
rpcPic = *( iterPic++ );
if( rpcPic->layerId == pic->layerId )
{
if( !rpl0->isRefPicLongterm( ii ) && rpcPic->referenced && rpcPic->getPOC() == slice->getPOC() - rpl0->getRefPicIdentifier( ii ) && !slice->isPocRestrictedByDRAP( rpcPic->getPOC(), rpcPic->precedingDRAP ) )
{
isAvailable = true;
break;
}
else if( rpl0->isRefPicLongterm( ii ) && rpcPic->referenced && ( rpcPic->getPOC() & ( pocCycle - 1 ) ) == rpl0->getRefPicIdentifier( ii ) && !slice->isPocRestrictedByDRAP( rpcPic->getPOC(), rpcPic->precedingDRAP ) )
{
isAvailable = true;
break;
}
}
}
if( isAvailable )
{
pLocalRPL0->setRefPicIdentifier( refPicIdxL0, rpl0->getRefPicIdentifier( ii ), rpl0->isRefPicLongterm( ii ), false, NOT_VALID );
refPicIdxL0++;
numOfSTRPL0 = numOfSTRPL0 + ( ( rpl0->isRefPicLongterm( ii ) ) ? 0 : 1 );
numOfLTRPL0 += ( rpl0->isRefPicLongterm( ii ) && !rpl0->isInterLayerRefPic( ii ) ) ? 1 : 0;
isAvailable = false;
}
}
// inter-layer reference pictures are added to the end of the reference picture list
if( layerIdx && vps && !vps->getAllIndependentLayersFlag() )
{
numOfRefPic = rpl0->getNumberOfInterLayerPictures() ? rpl0->getNumberOfInterLayerPictures() : m_pcEncLib->getNumRefLayers( layerIdx );
for( int ii = 0; ii < numOfRefPic; ii++ )
{
// loop through all pictures in the reference picture buffer
PicList::iterator iterPic = rcListPic.begin();
Vadim Seregin
committed
while( iterPic != rcListPic.end() && ii < numOfRefPic )
{
rpcPic = *( iterPic++ );
int refLayerIdx = vps->getGeneralLayerIdx( rpcPic->layerId );
if( rpcPic->referenced && rpcPic->getPOC() == pic->getPOC() && vps->getDirectRefLayerFlag( layerIdx, refLayerIdx ) )
pLocalRPL0->setRefPicIdentifier( refPicIdxL0, 0, true, true, vps->getInterLayerRefIdc( layerIdx, refLayerIdx ) );
refPicIdxL0++;
numOfILRPL0++;
Vadim Seregin
committed
ii++;
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
}
}
}
}
if( slice->getEnableDRAPSEI() )
{
pLocalRPL0->setNumberOfShorttermPictures( numOfSTRPL0 );
pLocalRPL0->setNumberOfLongtermPictures( numOfLTRPL0 );
pLocalRPL0->setNumberOfInterLayerPictures( numOfILRPL0 );
if( !slice->isIRAP() && !slice->isPOCInRefPicList( pLocalRPL0, slice->getAssociatedIRAPPOC() ) )
{
if( slice->getUseLTforDRAP() && !slice->isPOCInRefPicList( rpl1, slice->getAssociatedIRAPPOC() ) )
{
// Adding associated IRAP as longterm picture
pLocalRPL0->setRefPicIdentifier( refPicIdxL0, slice->getAssociatedIRAPPOC(), true, false, 0 );
refPicIdxL0++;
numOfLTRPL0++;
}
else
{
// Adding associated IRAP as shortterm picture
pLocalRPL0->setRefPicIdentifier( refPicIdxL0, slice->getPOC() - slice->getAssociatedIRAPPOC(), false, false, 0 );
refPicIdxL0++;
numOfSTRPL0++;
}
}
}
ReferencePictureList* pLocalRPL1 = slice->getLocalRPL1();
*pLocalRPL1 = ReferencePictureList( slice->getSPS()->getInterLayerPresentFlag() );
uint32_t numOfSTRPL1 = 0;
uint32_t numOfLTRPL1 = 0;
uint32_t numOfILRPL1 = 0;
numOfRefPic = rpl1->getNumberOfShorttermPictures() + rpl1->getNumberOfLongtermPictures();
uint32_t refPicIdxL1 = 0;
for( int ii = 0; ii < numOfRefPic; ii++ )
{
// loop through all pictures in the reference picture buffer
PicList::iterator iterPic = rcListPic.begin();
bool isAvailable = false;
pocCycle = 1 << ( slice->getSPS()->getBitsForPOC() );
while( iterPic != rcListPic.end() )
{
rpcPic = *( iterPic++ );
if( rpcPic->layerId == pic->layerId )
{
if( !rpl1->isRefPicLongterm( ii ) && rpcPic->referenced && rpcPic->getPOC() == slice->getPOC() - rpl1->getRefPicIdentifier( ii ) && !slice->isPocRestrictedByDRAP( rpcPic->getPOC(), rpcPic->precedingDRAP ) )
{
isAvailable = true;
break;
}
else if( rpl1->isRefPicLongterm( ii ) && rpcPic->referenced && ( rpcPic->getPOC() & ( pocCycle - 1 ) ) == rpl1->getRefPicIdentifier( ii ) && !slice->isPocRestrictedByDRAP( rpcPic->getPOC(), rpcPic->precedingDRAP ) )
{
isAvailable = true;
break;
}
}
if( isAvailable )
{
pLocalRPL1->setRefPicIdentifier( refPicIdxL1, rpl1->getRefPicIdentifier( ii ), rpl1->isRefPicLongterm( ii ), false, NOT_VALID );
refPicIdxL1++;
numOfSTRPL1 = numOfSTRPL1 + ( ( rpl1->isRefPicLongterm( ii ) ) ? 0 : 1 );
numOfLTRPL1 += ( rpl1->isRefPicLongterm( ii ) && !rpl1->isInterLayerRefPic( ii ) ) ? 1 : 0;
isAvailable = false;
}
}
// inter-layer reference pictures are added to the end of the reference picture list
if( layerIdx && vps && !vps->getAllIndependentLayersFlag() )
{
numOfRefPic = rpl1->getNumberOfInterLayerPictures() ? rpl1->getNumberOfInterLayerPictures() : m_pcEncLib->getNumRefLayers( layerIdx );
for( int ii = 0; ii < numOfRefPic; ii++ )
{
// loop through all pictures in the reference picture buffer
PicList::iterator iterPic = rcListPic.begin();
Vadim Seregin
committed
while( iterPic != rcListPic.end() && ii < numOfRefPic )
{
rpcPic = *( iterPic++ );
int refLayerIdx = vps->getGeneralLayerIdx( rpcPic->layerId );
if( rpcPic->referenced && rpcPic->getPOC() == pic->getPOC() && vps->getDirectRefLayerFlag( layerIdx, refLayerIdx ) )
{
pLocalRPL1->setRefPicIdentifier( refPicIdxL1, 0, true, true, vps->getInterLayerRefIdc( layerIdx, refLayerIdx ) );
refPicIdxL1++;
numOfILRPL1++;
Vadim Seregin
committed
ii++;
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
}
}
}
}
//Copy from L1 if we have less than active ref pic
int numOfNeedToFill = rpl0->getNumberOfActivePictures() - (numOfLTRPL0 + numOfSTRPL0);
bool isDisallowMixedRefPic = ( slice->getSPS()->getAllActiveRplEntriesHasSameSignFlag() ) ? true : false;
int originalL0StrpNum = numOfSTRPL0;
int originalL0LtrpNum = numOfLTRPL0;
int originalL0IlrpNum = numOfILRPL0;
for( int ii = 0; numOfNeedToFill > 0 && ii < ( pLocalRPL1->getNumberOfLongtermPictures() + pLocalRPL1->getNumberOfShorttermPictures() + pLocalRPL1->getNumberOfInterLayerPictures() ); ii++ )
{
if( ii <= ( numOfLTRPL1 + numOfSTRPL1 + numOfILRPL1 - 1 ) )
{
//Make sure this copy is not already in L0
bool canIncludeThis = true;
for( int jj = 0; jj < refPicIdxL0; jj++ )
{
if( ( pLocalRPL1->getRefPicIdentifier( ii ) == pLocalRPL0->getRefPicIdentifier( jj ) ) && ( pLocalRPL1->isRefPicLongterm( ii ) == pLocalRPL0->isRefPicLongterm( jj ) ) && pLocalRPL1->getInterLayerRefPicIdx( ii ) == pLocalRPL0->getInterLayerRefPicIdx( jj ) )
{
canIncludeThis = false;
}
bool sameSign = ( pLocalRPL1->getRefPicIdentifier( ii ) > 0 ) == ( pLocalRPL0->getRefPicIdentifier( 0 ) > 0 );
if( isDisallowMixedRefPic && canIncludeThis && !pLocalRPL1->isRefPicLongterm( ii ) && !sameSign )
{
canIncludeThis = false;
}
}
if( canIncludeThis )
{
pLocalRPL0->setRefPicIdentifier( refPicIdxL0, pLocalRPL1->getRefPicIdentifier( ii ), pLocalRPL1->isRefPicLongterm( ii ), pLocalRPL1->isInterLayerRefPic( ii ), pLocalRPL1->getInterLayerRefPicIdx( ii ) );
refPicIdxL0++;
numOfSTRPL0 = numOfSTRPL0 + ( ( pLocalRPL1->isRefPicLongterm( ii ) ) ? 0 : 1 );
numOfLTRPL0 += ( pLocalRPL1->isRefPicLongterm( ii ) && !pLocalRPL1->isInterLayerRefPic( ii ) ) ? 1 : 0;
numOfILRPL0 += pLocalRPL1->isInterLayerRefPic( ii ) ? 1 : 0;
numOfNeedToFill--;
}
}
}
pLocalRPL0->setNumberOfLongtermPictures( numOfLTRPL0 );
pLocalRPL0->setNumberOfShorttermPictures( numOfSTRPL0 );
pLocalRPL0->setNumberOfInterLayerPictures( numOfILRPL0 );
int numPics = numOfLTRPL0 + numOfSTRPL0;
pLocalRPL0->setNumberOfActivePictures( ( numPics < rpl0->getNumberOfActivePictures() ? numPics : rpl0->getNumberOfActivePictures() ) + numOfILRPL0 );
Zhipin Deng
committed
#if JVET_R0059_RPL_CLEANUP
pLocalRPL0->setLtrpInSliceHeaderFlag( 1 );
#else
pLocalRPL0->setLtrpInSliceHeaderFlag( rpl0->getLtrpInSliceHeaderFlag() );
Zhipin Deng
committed
#endif
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
slice->setRPL0idx( -1 );
slice->setRPL0( pLocalRPL0 );
//Copy from L0 if we have less than active ref pic
numOfNeedToFill = pLocalRPL0->getNumberOfActivePictures() - ( numOfLTRPL1 + numOfSTRPL1 );
for( int ii = 0; numOfNeedToFill > 0 && ii < ( pLocalRPL0->getNumberOfLongtermPictures() + pLocalRPL0->getNumberOfShorttermPictures() + pLocalRPL0->getNumberOfInterLayerPictures() ); ii++ )
{
if( ii <= ( originalL0StrpNum + originalL0LtrpNum + originalL0IlrpNum - 1 ) )
{
//Make sure this copy is not already in L0
bool canIncludeThis = true;
for( int jj = 0; jj < refPicIdxL1; jj++ )
{
if( ( pLocalRPL0->getRefPicIdentifier( ii ) == pLocalRPL1->getRefPicIdentifier( jj ) ) && ( pLocalRPL0->isRefPicLongterm( ii ) == pLocalRPL1->isRefPicLongterm( jj ) ) && pLocalRPL0->getInterLayerRefPicIdx( ii ) == pLocalRPL1->getInterLayerRefPicIdx( jj ) )
{
canIncludeThis = false;
}
bool sameSign = ( pLocalRPL0->getRefPicIdentifier( ii ) > 0 ) == ( pLocalRPL1->getRefPicIdentifier( 0 ) > 0 );
if( isDisallowMixedRefPic && canIncludeThis && !pLocalRPL0->isRefPicLongterm( ii ) && !sameSign )
{
canIncludeThis = false;
}
}
if( canIncludeThis )
{
pLocalRPL1->setRefPicIdentifier( refPicIdxL1, pLocalRPL0->getRefPicIdentifier( ii ), pLocalRPL0->isRefPicLongterm( ii ), pLocalRPL0->isInterLayerRefPic( ii ), pLocalRPL0->getInterLayerRefPicIdx( ii ) );
refPicIdxL1++;
numOfSTRPL1 = numOfSTRPL1 + ( ( pLocalRPL0->isRefPicLongterm( ii ) ) ? 0 : 1 );
numOfLTRPL1 += ( pLocalRPL0->isRefPicLongterm( ii ) && !pLocalRPL0->isInterLayerRefPic( ii ) ) ? 1 : 0;
numOfLTRPL1 += pLocalRPL0->isInterLayerRefPic( ii ) ? 1 : 0;
numOfNeedToFill--;
}
}
}
pLocalRPL1->setNumberOfLongtermPictures( numOfLTRPL1 );
pLocalRPL1->setNumberOfShorttermPictures( numOfSTRPL1 );
pLocalRPL1->setNumberOfInterLayerPictures( numOfILRPL1 );
numPics = numOfLTRPL1 + numOfSTRPL1;
pLocalRPL1->setNumberOfActivePictures( ( isDisallowMixedRefPic ? numPics : ( numPics < rpl1->getNumberOfActivePictures() ? numPics : rpl1->getNumberOfActivePictures() ) ) + numOfILRPL1 );
Zhipin Deng
committed
#if JVET_R0059_RPL_CLEANUP
pLocalRPL1->setLtrpInSliceHeaderFlag( 1 );
#else
pLocalRPL1->setLtrpInSliceHeaderFlag( rpl1->getLtrpInSliceHeaderFlag() );
Zhipin Deng
committed
#endif
slice->setRPL1idx( -1 );
slice->setRPL1( pLocalRPL1 );
}