Skip to content

Commit 4426cde

Browse files
authored
Merge pull request #205 from adamjw24/develop_conformance_cleanup_3.0xx
Conformance fixes, HLS cleanups
2 parents 737bfb7 + 11c7970 commit 4426cde

26 files changed

+427
-514
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ endforeach()
425425
get_directory_property( ALL_TESTS TESTS )
426426
set_tests_properties( ${ALL_TESTS} PROPERTIES
427427
TIMEOUT 120
428-
FAIL_REGULAR_EXPRESSION "WARNING:" )
428+
FAIL_REGULAR_EXPRESSION "(WARNING:|runtime error)" )
429429

430430
add_custom_target( test-ok USES_TERMINAL COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIG> -R "\"^(Test|MISSING)\"" )
431431
add_custom_target( test-all USES_TERMINAL COMMAND ${CMAKE_CTEST_COMMAND} -C $<CONFIG> -R "\"^(Test|MISSING|Faulty)\"" )

source/Lib/CommonLib/AdaptiveLoopFilter.cpp

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ bool AdaptiveLoopFilter::isClipOrCrossedByVirtualBoundaries( const CodingStructu
199199
const CodingUnit* prevCtu = cs.getCU( prevCtuPos, CHANNEL_TYPE_LUMA );
200200
if( !CU::isAvailable( *currCtu,
201201
*prevCtu,
202-
!loopFilterAcrossTilesEnabledFlag,
202+
!loopFilterAcrossSlicesEnabledFlag,
203203
!loopFilterAcrossTilesEnabledFlag,
204204
!loopFilterAcrossSubPicEnabledFlag ) )
205205
{
@@ -214,8 +214,8 @@ bool AdaptiveLoopFilter::isClipOrCrossedByVirtualBoundaries( const CodingStructu
214214
const CodingUnit* nextCtu = cs.getCU( nextCtuPos, CHANNEL_TYPE_LUMA );
215215
if( !CU::isAvailable( *currCtu,
216216
*nextCtu,
217-
!pps->getLoopFilterAcrossSlicesEnabledFlag(),
218-
!pps->getLoopFilterAcrossTilesEnabledFlag(),
217+
!loopFilterAcrossSlicesEnabledFlag,
218+
!loopFilterAcrossTilesEnabledFlag,
219219
!loopFilterAcrossSubPicEnabledFlag ) )
220220
{
221221
clipBottom = true;
@@ -229,8 +229,8 @@ bool AdaptiveLoopFilter::isClipOrCrossedByVirtualBoundaries( const CodingStructu
229229
const CodingUnit* prevCtu = cs.getCU( prevCtuPos, CHANNEL_TYPE_LUMA );
230230
if( !CU::isAvailable( *currCtu,
231231
*prevCtu,
232-
!pps->getLoopFilterAcrossSlicesEnabledFlag(),
233-
!pps->getLoopFilterAcrossTilesEnabledFlag(),
232+
!loopFilterAcrossSlicesEnabledFlag,
233+
!loopFilterAcrossTilesEnabledFlag,
234234
!loopFilterAcrossSubPicEnabledFlag ) )
235235
{
236236
clipLeft = true;
@@ -245,8 +245,8 @@ bool AdaptiveLoopFilter::isClipOrCrossedByVirtualBoundaries( const CodingStructu
245245

246246
if( !CU::isAvailable( *currCtu,
247247
*nextCtu,
248-
!pps->getLoopFilterAcrossSlicesEnabledFlag(),
249-
!pps->getLoopFilterAcrossTilesEnabledFlag(),
248+
!loopFilterAcrossSlicesEnabledFlag,
249+
!loopFilterAcrossTilesEnabledFlag,
250250
!loopFilterAcrossSubPicEnabledFlag ) )
251251
{
252252
clipRight = true;
@@ -261,21 +261,21 @@ bool AdaptiveLoopFilter::isClipOrCrossedByVirtualBoundaries( const CodingStructu
261261
{
262262
const Position prevCtuPos( area.x - ctuSize, area.y - ctuSize );
263263
const CodingUnit *prevCtu = cs.getCU( prevCtuPos, CHANNEL_TYPE_LUMA );
264-
if ( !pps->getLoopFilterAcrossSlicesEnabledFlag() && !CU::isSameSlice( *currCtu, *prevCtu ) )
264+
if ( !loopFilterAcrossSlicesEnabledFlag && !CU::isSameSlice( *currCtu, *prevCtu ) )
265265
{
266266
rasterSliceAlfPad = 1;
267267
}
268268
}
269269
}
270270

271-
if ( !clipBottom && !clipRight && restrictSlices )
271+
if( !clipBottom && !clipRight && restrictSlices )
272272
{
273273
//bottom-right CTU
274274
if ( area.x + ctuSize < cs.pcv->lumaWidth && area.y + ctuSize < cs.pcv->lumaHeight )
275275
{
276276
const Position nextCtuPos( area.x + ctuSize, area.y + ctuSize );
277277
const CodingUnit *nextCtu = cs.getCU( nextCtuPos, CHANNEL_TYPE_LUMA );
278-
if ( !pps->getLoopFilterAcrossSlicesEnabledFlag() && !CU::isSameSlice( *currCtu, *nextCtu ) )
278+
if ( !loopFilterAcrossSlicesEnabledFlag && !CU::isSameSlice( *currCtu, *nextCtu ) )
279279
{
280280
rasterSliceAlfPad += 2;
281281
}
@@ -460,16 +460,17 @@ void AdaptiveLoopFilter::prepareCTU( CodingStructure &cs, unsigned col, unsigned
460460
void AdaptiveLoopFilter::processCTU( CodingStructure & cs, unsigned col, unsigned line, int tid, const ChannelType chType )
461461
{
462462
PROFILER_SCOPE_AND_STAGE_EXT( 1, g_timeProfiler, P_ALF, cs, CH_L );
463-
PelUnitBuf recYuv = cs.getRecoBuf();
464463

465464
const UnitArea ctuArea( getCtuArea( cs, col, line, true ) );
465+
CPelUnitBuf recYuv = cs.getRecoBuf().subBuf( ctuArea );
466+
PelUnitBuf dstYuv = m_alfBuf.subBuf( ctuArea );
466467

467468
const unsigned ctuIdx = line * cs.pcv->widthInCtus + col;
468469
CtuAlfData currAlfData = cs.getCtuData( col, line ).alfParam;
469470
currAlfData.alfCtuEnableFlag[1] += currAlfData.ccAlfFilterControl[0] > 0 ? 2 : 0;
470471
currAlfData.alfCtuEnableFlag[2] += currAlfData.ccAlfFilterControl[1] > 0 ? 2 : 0;
471472

472-
filterCTU( recYuv.subBuf( ctuArea ), m_alfBuf.subBuf( ctuArea ), currAlfData, cs.picture->slices[0]->getClpRngs(), chType, cs, ctuIdx, ctuArea.lumaPos(), tid );
473+
filterCTU( recYuv, dstYuv, currAlfData, cs.picture->slices[0]->getClpRngs(), chType, cs, ctuIdx, ctuArea.lumaPos(), tid );
473474
}
474475

475476
bool AdaptiveLoopFilter::getAlfSkipPic( const CodingStructure & cs )
@@ -489,7 +490,7 @@ bool AdaptiveLoopFilter::getAlfSkipPic( const CodingStructure & cs )
489490
}
490491

491492
void AdaptiveLoopFilter::filterAreaLuma( const CPelUnitBuf& srcBuf,
492-
const PelUnitBuf& dstBuf,
493+
PelUnitBuf& dstBuf,
493494
const Area& blk,
494495
const Slice* slice,
495496
const APS* const* aps,
@@ -535,7 +536,7 @@ void AdaptiveLoopFilter::filterAreaLuma( const CPelUnitBuf& srcBuf,
535536
}
536537

537538
void AdaptiveLoopFilter::filterAreaChroma( const CPelUnitBuf& srcBuf,
538-
const PelUnitBuf& dstBuf,
539+
PelUnitBuf& dstBuf,
539540
const Area& blkChroma,
540541
const ComponentID compID,
541542
const Slice* slice,
@@ -575,7 +576,7 @@ void AdaptiveLoopFilter::filterAreaChroma( const CPelUnitBuf& srcBuf,
575576
}
576577

577578
void AdaptiveLoopFilter::filterAreaChromaCc( const CPelUnitBuf& srcBuf,
578-
const PelUnitBuf& dstBuf,
579+
PelUnitBuf& dstBuf,
579580
const Area& blkLuma,
580581
const Area& blkChroma,
581582
const ComponentID compID,
@@ -601,7 +602,7 @@ void AdaptiveLoopFilter::filterAreaChromaCc( const CPelUnitBuf& srcBuf,
601602
}
602603

603604
void AdaptiveLoopFilter::filterAreaChromaBothCc( const CPelUnitBuf& srcBuf,
604-
const PelUnitBuf& dstBuf,
605+
PelUnitBuf& dstBuf,
605606
const Area& blkLuma,
606607
const Area& blkChroma,
607608
const Slice* slice,
@@ -653,7 +654,7 @@ void AdaptiveLoopFilter::filterAreaChromaBothCc( const CPelUnitBuf& srcBuf,
653654
}
654655

655656
void AdaptiveLoopFilter::filterCTU( const CPelUnitBuf& srcBuf,
656-
const PelUnitBuf& dstBuf,
657+
PelUnitBuf& dstBuf,
657658
const CtuAlfData& ctuAlfData,
658659
const ClpRngs& clpRngs,
659660
const ChannelType chType,

source/Lib/CommonLib/AdaptiveLoopFilter.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ class AdaptiveLoopFilter
121121
static void deriveClassificationBlk( AlfClassifier *classifier, const CPelBuf& srcLuma, const Area& blk, const int shift, int vbCTUHeight, int vbPos );
122122
void ( *m_deriveClassificationBlk )( AlfClassifier *classifier, const CPelBuf& srcLuma, const Area& blk, const int shift, int vbCTUHeight, int vbPos );
123123

124-
void filterCTU ( const CPelUnitBuf& srcBuf, const PelUnitBuf& dstBuf, const CtuAlfData& ctuAlfData, const ClpRngs& clpRngs, const ChannelType chType, const CodingStructure& cs, int ctuIdx, Position ctuPos, int tid );
125-
void filterAreaLuma ( const CPelUnitBuf& srcBuf, const PelUnitBuf& dstBuf, const Area& blk, const Slice* slice, const APS* const* aps, const short filterSetIndex, const ClpRngs& clpRngs, const int tId );
126-
void filterAreaChroma ( const CPelUnitBuf& srcBuf, const PelUnitBuf& dstBuf, const Area& blkChroma, const ComponentID compID, const Slice* slice, const APS* const* aps, const CtuAlfData& ctuAlfData, const ClpRngs& clpRngs );
127-
void filterAreaChromaCc ( const CPelUnitBuf& srcBuf, const PelUnitBuf& dstBuf, const Area& blkLuma, const Area& blkChroma, const ComponentID compID, const Slice* slice, const APS* const* aps, const CtuAlfData& ctuAlfData, const ClpRngs& clpRngs );
128-
void filterAreaChromaBothCc ( const CPelUnitBuf& srcBuf, const PelUnitBuf& dstBuf, const Area& blkLuma, const Area& blkChroma, const Slice* slice, const APS* const* aps, const CtuAlfData& ctuAlfData, const ClpRngs& clpRngs );
124+
void filterCTU ( const CPelUnitBuf& srcBuf, PelUnitBuf& dstBuf, const CtuAlfData& ctuAlfData, const ClpRngs& clpRngs, const ChannelType chType, const CodingStructure& cs, int ctuIdx, Position ctuPos, int tid );
125+
void filterAreaLuma ( const CPelUnitBuf& srcBuf, PelUnitBuf& dstBuf, const Area& blk, const Slice* slice, const APS* const* aps, const short filterSetIndex, const ClpRngs& clpRngs, const int tId );
126+
void filterAreaChroma ( const CPelUnitBuf& srcBuf, PelUnitBuf& dstBuf, const Area& blkChroma, const ComponentID compID, const Slice* slice, const APS* const* aps, const CtuAlfData& ctuAlfData, const ClpRngs& clpRngs );
127+
void filterAreaChromaCc ( const CPelUnitBuf& srcBuf, PelUnitBuf& dstBuf, const Area& blkLuma, const Area& blkChroma, const ComponentID compID, const Slice* slice, const APS* const* aps, const CtuAlfData& ctuAlfData, const ClpRngs& clpRngs );
128+
void filterAreaChromaBothCc ( const CPelUnitBuf& srcBuf, PelUnitBuf& dstBuf, const Area& blkLuma, const Area& blkChroma, const Slice* slice, const APS* const* aps, const CtuAlfData& ctuAlfData, const ClpRngs& clpRngs );
129129

130130
template<AlfFilterType filtType>
131131
static void filterBlk ( const AlfClassifier *classifier, const PelUnitBuf &recDst, const CPelUnitBuf& recSrc, const Area& blk, const ComponentID compId, const short* filterSet, const short* fClipSet, const ClpRng& clpRng, int vbCTUHeight, int vbPos );

source/Lib/CommonLib/BitStream.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ uint32_t InputBitstream::read (uint32_t uiNumberOfBits)
102102
m_numBitsRead += uiNumberOfBits;
103103
#endif
104104

105+
constexpr static uint64_t ONES = ~static_cast<uint64_t>( 0 ); // need to ensure 64 bits for the mask, because shift by 32 is UB for uin32_t
105106

106107
/* NB, bits are extracted from the MSB of each byte. */
107108
uint32_t retval = 0;
@@ -111,7 +112,7 @@ uint32_t InputBitstream::read (uint32_t uiNumberOfBits)
111112
* n=3, len(H)=7: -VVV HHHH, shift_down=4, mask=0xf8
112113
*/
113114
retval = static_cast<uint32_t>( m_held_bits >> ( m_num_held_bits - uiNumberOfBits ) );
114-
retval &= ~( ~0u << uiNumberOfBits );
115+
retval &= ~( ONES << uiNumberOfBits );
115116
m_num_held_bits -= uiNumberOfBits;
116117

117118
return retval;
@@ -127,7 +128,7 @@ uint32_t InputBitstream::read (uint32_t uiNumberOfBits)
127128
/* n=5, len(H)=3: ---- -VVV, mask=0x07, shift_up=5-3=2,
128129
* n=9, len(H)=3: ---- -VVV, mask=0x07, shift_up=9-3=6 */
129130
uiNumberOfBits -= m_num_held_bits;
130-
retval = static_cast<uint32_t>( m_held_bits ) & ~( ~0u << m_num_held_bits ); // we can cast to 32 bits, because the held bits are the rightmost bits
131+
retval = static_cast<uint32_t>( m_held_bits ) & ~( ONES << m_num_held_bits ); // we can cast to 32 bits, because the held bits are the rightmost bits
131132
retval <<= uiNumberOfBits;
132133
}
133134

@@ -170,7 +171,7 @@ std::unique_ptr<InputBitstream> InputBitstream::extractSubstream( uint32_t uiNum
170171
{
171172
std::unique_ptr<InputBitstream> substream( new InputBitstream );
172173

173-
std::vector<uint8_t>& buf = substream->getFifo();
174+
AlignedByteVec& buf = substream->getFifo();
174175
buf.reserve( ( uiNumBits + 7 ) / 8 + 1 ); // +1 because a zero byte might be added later
175176

176177
const uint32_t uiNumBytes = uiNumBits / 8; // don't round up here, because the remaing bits will be copied later

source/Lib/CommonLib/BitStream.h

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ namespace vvdec
7171
class InputBitstream
7272
{
7373
private:
74-
std::vector<uint8_t> m_fifo; /// FIFO for storage of complete bytes
74+
AlignedByteVec m_fifo; /// FIFO for storage of complete bytes
7575
std::vector<uint32_t> m_emulationPreventionByteLocation;
7676

7777
uint32_t m_fifo_idx = 0; /// Read index into m_fifo
@@ -178,15 +178,16 @@ class InputBitstream
178178
void setEmulationPreventionByteLocation( const std::vector<uint32_t>& vec ) { m_emulationPreventionByteLocation = vec; }
179179
void clearEmulationPreventionByteLocation() { m_emulationPreventionByteLocation.clear(); }
180180

181-
const std::vector<uint8_t>& getFifo() const { return m_fifo; }
182-
std::vector<uint8_t>& getFifo() { return m_fifo; }
183-
void clearFifo() { m_fifo.clear(); m_zeroByteAdded = false; }
181+
const AlignedByteVec& getFifo() const { return m_fifo; }
182+
AlignedByteVec& getFifo() { return m_fifo; }
183+
void clearFifo() { m_fifo.clear(); m_zeroByteAdded = false; }
184184

185185
private:
186186
inline void load_next_bits( int requiredBits )
187187
{
188188
uint32_t num_bytes_to_load = 8;
189-
if UNLIKELY( m_fifo_idx + num_bytes_to_load > m_fifo.size() )
189+
if UNLIKELY( m_fifo_idx + num_bytes_to_load > m_fifo.size() // end of bitstream
190+
|| ( m_fifo_idx & 0x7 ) != 0 ) // unaligned read position (m_fifo should be aligned)
190191
{
191192
const int required_bytes = ( requiredBits + 7 ) >> 3;
192193
CHECK( m_fifo_idx + required_bytes > m_fifo.size(), "Exceeded FIFO size" );
@@ -196,23 +197,24 @@ class InputBitstream
196197
m_held_bits = 0;
197198
switch( num_bytes_to_load )
198199
{
199-
case 8: m_held_bits = static_cast<uint64_t>( m_fifo[m_fifo_idx++] ) << ( 7 * 8 );
200-
case 7: m_held_bits |= static_cast<uint64_t>( m_fifo[m_fifo_idx++] ) << ( 6 * 8 );
201-
case 6: m_held_bits |= static_cast<uint64_t>( m_fifo[m_fifo_idx++] ) << ( 5 * 8 );
202-
case 5: m_held_bits |= static_cast<uint64_t>( m_fifo[m_fifo_idx++] ) << ( 4 * 8 );
203-
case 4: m_held_bits |= static_cast<uint64_t>( m_fifo[m_fifo_idx++] ) << ( 3 * 8 );
204-
case 3: m_held_bits |= static_cast<uint64_t>( m_fifo[m_fifo_idx++] ) << ( 2 * 8 );
205-
case 2: m_held_bits |= static_cast<uint64_t>( m_fifo[m_fifo_idx++] ) << ( 1 * 8 );
206-
case 1: m_held_bits |= static_cast<uint64_t>( m_fifo[m_fifo_idx++] );
200+
default: num_bytes_to_load = 8; // in the unaligned case num_bytes_to_load could be >8
201+
case 8: m_held_bits = static_cast<uint64_t>( m_fifo[m_fifo_idx++] ) << ( 7 * 8 );
202+
case 7: m_held_bits |= static_cast<uint64_t>( m_fifo[m_fifo_idx++] ) << ( 6 * 8 );
203+
case 6: m_held_bits |= static_cast<uint64_t>( m_fifo[m_fifo_idx++] ) << ( 5 * 8 );
204+
case 5: m_held_bits |= static_cast<uint64_t>( m_fifo[m_fifo_idx++] ) << ( 4 * 8 );
205+
case 4: m_held_bits |= static_cast<uint64_t>( m_fifo[m_fifo_idx++] ) << ( 3 * 8 );
206+
case 3: m_held_bits |= static_cast<uint64_t>( m_fifo[m_fifo_idx++] ) << ( 2 * 8 );
207+
case 2: m_held_bits |= static_cast<uint64_t>( m_fifo[m_fifo_idx++] ) << ( 1 * 8 );
208+
case 1: m_held_bits |= static_cast<uint64_t>( m_fifo[m_fifo_idx++] );
207209
}
208210
}
209211
else
210212
{
213+
CHECKD( reinterpret_cast<intptr_t>( &m_fifo[m_fifo_idx] ) & 0x7, "bistream read pos unaligned" );
211214
m_held_bits = simde_bswap64( *reinterpret_cast<uint64_t*>( &m_fifo[m_fifo_idx] ) );
212215
m_fifo_idx += num_bytes_to_load;
213216
}
214217

215-
/* resolve remainder bits */
216218
m_num_held_bits = num_bytes_to_load * 8;
217219
}
218220
};

source/Lib/CommonLib/Buffer.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ struct AreaBuf : public Size
150150
void fill ( const T &val );
151151
void memset ( const int val );
152152

153-
void copyFrom ( const AreaBuf<const T> &other ) const;
153+
void copyFrom ( const AreaBuf<const T> &other );
154154

155155
void reconstruct ( const AreaBuf<const T> &pred, const AreaBuf<const T> &resi, const ClpRng& clpRng);
156156

@@ -396,7 +396,7 @@ void AreaBuf<T>::memset( const int val )
396396

397397
#if ENABLE_SIMD_OPT_BUFFER
398398
template<typename T>
399-
void AreaBuf<T>::copyFrom( const AreaBuf<const T> &other ) const
399+
void AreaBuf<T>::copyFrom( const AreaBuf<const T> &other )
400400
{
401401
#if !defined(__GNUC__) || __GNUC__ > 5
402402
static_assert( std::is_trivially_copyable<T>::value, "Type T is not trivially_copyable" );
@@ -406,7 +406,7 @@ void AreaBuf<T>::copyFrom( const AreaBuf<const T> &other ) const
406406
}
407407
#else
408408
template<typename T>
409-
void AreaBuf<T>::copyFrom( const AreaBuf<const T> &other ) const
409+
void AreaBuf<T>::copyFrom( const AreaBuf<const T> &other )
410410
{
411411
#if !defined(__GNUC__) || __GNUC__ > 5
412412
static_assert( std::is_trivially_copyable<T>::value, "Type T is not trivially_copyable" );
@@ -711,7 +711,7 @@ struct UnitBuf
711711
const AreaBuf<T>& Cr() const { return bufs[2]; }
712712

713713
void fill ( const T &val );
714-
void copyFrom ( const UnitBuf<const T> &other ) const;
714+
void copyFrom ( const UnitBuf<const T> &other );
715715
void reconstruct ( const UnitBuf<const T> &pred, const UnitBuf<const T> &resi, const ClpRngs& clpRngs );
716716
void subtract ( const UnitBuf<const T> &other );
717717
void addWeightedAvg ( const UnitBuf< T> &other1, const UnitBuf< T> &other2, const ClpRngs& clpRngs, const uint8_t bcwIdx = BCW_DEFAULT, const bool chromaOnly = false, const bool lumaOnly = false);
@@ -751,7 +751,7 @@ void UnitBuf<T>::fill( const T &val )
751751
}
752752

753753
template<typename T>
754-
void UnitBuf<T>::copyFrom( const UnitBuf<const T> &other ) const
754+
void UnitBuf<T>::copyFrom( const UnitBuf<const T> &other )
755755
{
756756
CHECK( chromaFormat != other.chromaFormat, "Incompatible formats" );
757757

0 commit comments

Comments
 (0)