Newer
Older

Karsten Suehring
committed
/* The copyright in this software is being made available under the BSD
* License, included below. This software may be subject to other third party
* and contributor rights, including patent rights, and no such rights are
* granted under this license.
*
* Copyright (c) 2010-2022, ITU/ISO/IEC

Karsten Suehring
committed
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* * Neither the name of the ITU/ISO/IEC nor the names of its contributors may
* be used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/** \file Picture.cpp
* \brief Description of a coded picture
*/
#include "Picture.h"
#include "SEI.h"
#include "ChromaFormat.h"
Sagar Kotecha
committed
#include "CommonLib/InterpolationFilter.h"
#if JVET_X0071_CHROMA_BILATERAL_FILTER
ChromaBifParams Picture::m_ChromaBifParams;

Karsten Suehring
committed

Karsten Suehring
committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
int g_wppThreadId( 0 );
#pragma omp threadprivate(g_wppThreadId)
#if ENABLE_SPLIT_PARALLELISM
int g_splitThreadId( 0 );
#pragma omp threadprivate(g_splitThreadId)
int g_splitJobId( 0 );
#pragma omp threadprivate(g_splitJobId)
#endif
Scheduler::Scheduler() :
#if ENABLE_SPLIT_PARALLELISM
m_numSplitThreads( 1 )
#endif
{
}
Scheduler::~Scheduler()
{
}
#if ENABLE_SPLIT_PARALLELISM
unsigned Scheduler::getSplitDataId( int jobId ) const
{
if( m_numSplitThreads > 1 && m_hasParallelBuffer )
{
int splitJobId = jobId == CURR_THREAD_ID ? g_splitJobId : jobId;
return ( g_wppThreadId * NUM_RESERVERD_SPLIT_JOBS ) + splitJobId;
}
else
{
return 0;
}
}
unsigned Scheduler::getSplitPicId( int tId /*= CURR_THREAD_ID */ ) const
{
if( m_numSplitThreads > 1 && m_hasParallelBuffer )
{
int threadId = tId == CURR_THREAD_ID ? g_splitThreadId : tId;
return ( g_wppThreadId * m_numSplitThreads ) + threadId;
}
else
{
return 0;
}
}
unsigned Scheduler::getSplitJobId() const
{
if( m_numSplitThreads > 1 )
{
return g_splitJobId;
}
else
{
return 0;
}
}
void Scheduler::setSplitJobId( const int jobId )
{
CHECK( g_splitJobId != 0 && jobId != 0, "Need to reset the jobId after usage!" );
g_splitJobId = jobId;
}
void Scheduler::startParallel()
{
m_hasParallelBuffer = true;
}
void Scheduler::finishParallel()
{
m_hasParallelBuffer = false;
}
void Scheduler::setSplitThreadId( const int tId )
{
g_splitThreadId = tId == CURR_THREAD_ID ? omp_get_thread_num() : tId;
}
#endif
unsigned Scheduler::getDataId() const
{
#if ENABLE_SPLIT_PARALLELISM
if( m_numSplitThreads > 1 )
{
return getSplitDataId();
}
#endif
return 0;
}
bool Scheduler::init( const int ctuYsize, const int ctuXsize, const int numWppThreadsRunning, const int numWppExtraLines, const int numSplitThreads )
{
#if ENABLE_SPLIT_PARALLELISM
m_numSplitThreads = numSplitThreads;
#endif
return true;
}
int Scheduler::getNumPicInstances() const
{
#if !ENABLE_SPLIT_PARALLELISM
return 1;
#else
return ( m_numSplitThreads > 1 ? m_numSplitThreads : 1 );

Karsten Suehring
committed
#endif
}
#endif
// ---------------------------------------------------------------------------
// picture methods
// ---------------------------------------------------------------------------

Karsten Suehring
committed
Picture::Picture()
{
cs = nullptr;
Biao Wang
committed
m_isSubPicBorderSaved = false;

Karsten Suehring
committed
m_bIsBorderExtended = false;
m_wrapAroundValid = false;
m_wrapAroundOffset = 0;

Karsten Suehring
committed
usedByCurr = false;
longTerm = false;
reconstructed = false;
neededForOutput = false;
referenced = false;

Karsten Suehring
committed
temporalId = std::numeric_limits<uint32_t>::max();

Karsten Suehring
committed
fieldPic = false;
topField = false;
Vadim Seregin
committed
#if JVET_S0124_UNAVAILABLE_REFERENCE
nonReferencePictureFlag = false;
#endif

Karsten Suehring
committed
for( int i = 0; i < MAX_NUM_CHANNEL_TYPE; i++ )
{
m_prevQP[i] = -1;

Karsten Suehring
committed
}
m_spliceIdx = NULL;
m_ctuNums = 0;
numSubpics = 1;
#if JVET_Z0118_GDR
m_cleanDirtyFlag = false;
#endif

Karsten Suehring
committed
}
void Picture::create( const ChromaFormat &_chromaFormat, const Size &size, const unsigned _maxCUSize, const unsigned _margin, const bool _decoder, const int _layerId, const bool gopBasedTemporalFilterEnabled )

Karsten Suehring
committed
{

Karsten Suehring
committed
UnitArea::operator=( UnitArea( _chromaFormat, Area( Position{ 0, 0 }, size ) ) );

Karsten Suehring
committed
const Area a = Area( Position(), size );
#if JVET_Z0118_GDR
M_BUFS( 0, PIC_RECONSTRUCTION_0 ).create( _chromaFormat, a, _maxCUSize, margin, MEMORY_ALIGN_DEF_SIZE );
M_BUFS( 0, PIC_RECONSTRUCTION_1 ).create( _chromaFormat, a, _maxCUSize, margin, MEMORY_ALIGN_DEF_SIZE );
#else
M_BUFS( 0, PIC_RECONSTRUCTION ).create( _chromaFormat, a, _maxCUSize, margin, MEMORY_ALIGN_DEF_SIZE );
M_BUFS( 0, PIC_RECON_WRAP ).create( _chromaFormat, a, _maxCUSize, margin, MEMORY_ALIGN_DEF_SIZE );

Karsten Suehring
committed
if( !_decoder )
{
M_BUFS( 0, PIC_ORIGINAL ). create( _chromaFormat, a );
M_BUFS( 0, PIC_TRUE_ORIGINAL ). create( _chromaFormat, a );
if( gopBasedTemporalFilterEnabled )
{
M_BUFS( 0, PIC_FILTERED_ORIGINAL ).create( _chromaFormat, a );
}

Karsten Suehring
committed
}
#if !KEEP_PRED_AND_RESI_SIGNALS
m_ctuArea = UnitArea( _chromaFormat, Area( Position{ 0, 0 }, Size( _maxCUSize, _maxCUSize ) ) );
#endif

Karsten Suehring
committed
}
void Picture::destroy()
{
#if ENABLE_SPLIT_PARALLELISM
for( int jId = 0; jId < PARL_SPLIT_MAX_NUM_THREADS; jId++ )
#endif
{
for (uint32_t t = 0; t < NUM_PIC_TYPES; t++)
{
M_BUFS(jId, t).destroy();
}
m_hashMap.clearAll();
if (cs)
{
#if JVET_Z0118_GDR
if (cs->picHeader)
{
delete cs->picHeader;
}
cs->picHeader = nullptr;
#endif
cs->destroy();
delete cs;
cs = nullptr;
}

Karsten Suehring
committed
for (auto &ps: slices)
{
delete ps;
}
slices.clear();

Karsten Suehring
committed
for (auto &psei: SEIs)
{
delete psei;
}
SEIs.clear();

Karsten Suehring
committed
if (m_spliceIdx)
{
delete[] m_spliceIdx;
m_spliceIdx = NULL;
}

Karsten Suehring
committed
}
void Picture::createTempBuffers( const unsigned _maxCUSize )
{
#if KEEP_PRED_AND_RESI_SIGNALS
const Area a( Position{ 0, 0 }, lumaSize() );
#else
const Area a = m_ctuArea.Y();
#endif
#if ENABLE_SPLIT_PARALLELISM
scheduler.startParallel();
for( int jId = 0; jId < scheduler.getNumPicInstances(); jId++ )
#endif
{
M_BUFS( jId, PIC_PREDICTION ).create( chromaFormat, a, _maxCUSize );
M_BUFS( jId, PIC_RESIDUAL ).create( chromaFormat, a, _maxCUSize );
#if ENABLE_SPLIT_PARALLELISM
if (jId > 0)
{
M_BUFS(jId, PIC_RECONSTRUCTION).create(chromaFormat, Y(), _maxCUSize, margin, MEMORY_ALIGN_DEF_SIZE);
}

Karsten Suehring
committed
#endif
}
if (cs)
{
cs->rebindPicBufs();
}

Karsten Suehring
committed
}
void Picture::destroyTempBuffers()
{
#if ENABLE_SPLIT_PARALLELISM
scheduler.finishParallel();
for( int jId = 0; jId < scheduler.getNumPicInstances(); jId++ )
#endif
{
for (uint32_t t = 0; t < NUM_PIC_TYPES; t++)
{
if (t == PIC_RESIDUAL || t == PIC_PREDICTION)

Karsten Suehring
committed
#if ENABLE_SPLIT_PARALLELISM
if (t == PIC_RECONSTRUCTION && jId > 0)

Karsten Suehring
committed
#endif

Karsten Suehring
committed
}
if (cs)
{
cs->rebindPicBufs();
}

Karsten Suehring
committed
}
PelBuf Picture::getOrigBuf(const CompArea &blk) { return getBuf(blk, PIC_ORIGINAL); }
const CPelBuf Picture::getOrigBuf(const CompArea &blk) const { return getBuf(blk, PIC_ORIGINAL); }
PelUnitBuf Picture::getOrigBuf(const UnitArea &unit) { return getBuf(unit, PIC_ORIGINAL); }
const CPelUnitBuf Picture::getOrigBuf(const UnitArea &unit) const { return getBuf(unit, PIC_ORIGINAL); }
PelUnitBuf Picture::getOrigBuf() { return M_BUFS(0, PIC_ORIGINAL); }
const CPelUnitBuf Picture::getOrigBuf() const { return M_BUFS(0, PIC_ORIGINAL); }
PelBuf Picture::getOrigBuf(const ComponentID compID) { return getBuf(compID, PIC_ORIGINAL); }
const CPelBuf Picture::getOrigBuf(const ComponentID compID) const { return getBuf(compID, PIC_ORIGINAL); }
PelUnitBuf Picture::getTrueOrigBuf() { return M_BUFS(0, PIC_TRUE_ORIGINAL); }
const CPelUnitBuf Picture::getTrueOrigBuf() const { return M_BUFS(0, PIC_TRUE_ORIGINAL); }
PelBuf Picture::getTrueOrigBuf(const CompArea &blk) { return getBuf(blk, PIC_TRUE_ORIGINAL); }
const CPelBuf Picture::getTrueOrigBuf(const CompArea &blk) const { return getBuf(blk, PIC_TRUE_ORIGINAL); }
PelUnitBuf Picture::getFilteredOrigBuf() { return M_BUFS(0, PIC_FILTERED_ORIGINAL); }
const CPelUnitBuf Picture::getFilteredOrigBuf() const { return M_BUFS(0, PIC_FILTERED_ORIGINAL); }
PelBuf Picture::getFilteredOrigBuf(const CompArea &blk) { return getBuf(blk, PIC_FILTERED_ORIGINAL); }
const CPelBuf Picture::getFilteredOrigBuf(const CompArea &blk) const { return getBuf(blk, PIC_FILTERED_ORIGINAL); }

Karsten Suehring
committed
PelBuf Picture::getPredBuf(const CompArea &blk) { return getBuf(blk, PIC_PREDICTION); }
const CPelBuf Picture::getPredBuf(const CompArea &blk) const { return getBuf(blk, PIC_PREDICTION); }
PelUnitBuf Picture::getPredBuf(const UnitArea &unit) { return getBuf(unit, PIC_PREDICTION); }
const CPelUnitBuf Picture::getPredBuf(const UnitArea &unit) const { return getBuf(unit, PIC_PREDICTION); }
PelBuf Picture::getResiBuf(const CompArea &blk) { return getBuf(blk, PIC_RESIDUAL); }
const CPelBuf Picture::getResiBuf(const CompArea &blk) const { return getBuf(blk, PIC_RESIDUAL); }
PelUnitBuf Picture::getResiBuf(const UnitArea &unit) { return getBuf(unit, PIC_RESIDUAL); }
const CPelUnitBuf Picture::getResiBuf(const UnitArea &unit) const { return getBuf(unit, PIC_RESIDUAL); }
#if JVET_Z0118_GDR
PelBuf Picture::getRecoBuf(const ComponentID compID, bool wrap) { return getBuf(compID, (PictureType) wrap ? PIC_RECON_WRAP : (m_cleanDirtyFlag ? PIC_RECONSTRUCTION_1 : PIC_RECONSTRUCTION_0)); }
const CPelBuf Picture::getRecoBuf(const ComponentID compID, bool wrap) const { return getBuf(compID, (PictureType) wrap ? PIC_RECON_WRAP : (m_cleanDirtyFlag ? PIC_RECONSTRUCTION_1 : PIC_RECONSTRUCTION_0)); }
PelBuf Picture::getRecoBuf(const CompArea &blk, bool wrap) { return getBuf(blk, (PictureType) wrap ? PIC_RECON_WRAP : (m_cleanDirtyFlag ? PIC_RECONSTRUCTION_1 : PIC_RECONSTRUCTION_0)); }
const CPelBuf Picture::getRecoBuf(const CompArea &blk, bool wrap) const { return getBuf(blk, (PictureType) wrap ? PIC_RECON_WRAP : (m_cleanDirtyFlag ? PIC_RECONSTRUCTION_1 : PIC_RECONSTRUCTION_0)); }
PelUnitBuf Picture::getRecoBuf(const UnitArea &unit, bool wrap) { return getBuf(unit, (PictureType) wrap ? PIC_RECON_WRAP : (m_cleanDirtyFlag ? PIC_RECONSTRUCTION_1 : PIC_RECONSTRUCTION_0)); }
const CPelUnitBuf Picture::getRecoBuf(const UnitArea &unit, bool wrap) const { return getBuf(unit, (PictureType) wrap ? PIC_RECON_WRAP : (m_cleanDirtyFlag ? PIC_RECONSTRUCTION_1 : PIC_RECONSTRUCTION_0)); }
PelUnitBuf Picture::getRecoBuf(bool wrap) { return M_BUFS(scheduler.getSplitPicId(), wrap ? PIC_RECON_WRAP : (PictureType) (m_cleanDirtyFlag ? PIC_RECONSTRUCTION_1 : PIC_RECONSTRUCTION_0)); }
const CPelUnitBuf Picture::getRecoBuf(bool wrap) const { return M_BUFS(scheduler.getSplitPicId(), wrap ? PIC_RECON_WRAP : (PictureType) (m_cleanDirtyFlag ? PIC_RECONSTRUCTION_1 : PIC_RECONSTRUCTION_0)); }
#else
PelBuf Picture::getRecoBuf(const ComponentID compID, bool wrap) { return getBuf(compID, wrap ? PIC_RECON_WRAP : PIC_RECONSTRUCTION); }
const CPelBuf Picture::getRecoBuf(const ComponentID compID, bool wrap) const { return getBuf(compID, wrap ? PIC_RECON_WRAP : PIC_RECONSTRUCTION); }
PelBuf Picture::getRecoBuf(const CompArea &blk, bool wrap) { return getBuf(blk, wrap ? PIC_RECON_WRAP : PIC_RECONSTRUCTION); }
const CPelBuf Picture::getRecoBuf(const CompArea &blk, bool wrap) const { return getBuf(blk, wrap ? PIC_RECON_WRAP : PIC_RECONSTRUCTION); }
PelUnitBuf Picture::getRecoBuf(const UnitArea &unit, bool wrap) { return getBuf(unit, wrap ? PIC_RECON_WRAP : PIC_RECONSTRUCTION); }
const CPelUnitBuf Picture::getRecoBuf(const UnitArea &unit, bool wrap) const { return getBuf(unit, wrap ? PIC_RECON_WRAP : PIC_RECONSTRUCTION); }
PelUnitBuf Picture::getRecoBuf(bool wrap) { return M_BUFS(scheduler.getSplitPicId(), wrap ? PIC_RECON_WRAP : PIC_RECONSTRUCTION); }
const CPelUnitBuf Picture::getRecoBuf(bool wrap) const { return M_BUFS(scheduler.getSplitPicId(), wrap ? PIC_RECON_WRAP : PIC_RECONSTRUCTION); }

Karsten Suehring
committed
void Picture::finalInit( const VPS* vps, const SPS& sps, const PPS& pps, PicHeader *picHeader, APS** alfApss, APS* lmcsAps, APS* scalingListAps )

Karsten Suehring
committed
{
for( auto &sei : SEIs )
{
delete sei;
}
SEIs.clear();
clearSliceBuffer();
const ChromaFormat chromaFormatIDC = sps.getChromaFormatIdc();
const int iWidth = pps.getPicWidthInLumaSamples();
const int iHeight = pps.getPicHeightInLumaSamples();

Karsten Suehring
committed
if( cs )
{
cs->initStructData();
}
else
{
cs = new CodingStructure( g_globalUnitCache.cuCache, g_globalUnitCache.puCache, g_globalUnitCache.tuCache );
cs->sps = &sps;
cs->create(chromaFormatIDC, Area(0, 0, iWidth, iHeight), true, (bool)sps.getPLTMode());

Karsten Suehring
committed
}

Karsten Suehring
committed
cs->picture = this;
cs->slice = nullptr; // the slices for this picture have not been set at this point. update cs->slice after swapSliceObject()
cs->pps = &pps;
#if JVET_Z0118_GDR
setCleanDirty(false);
#endif
picHeader->setSPSId( sps.getSPSId() );
picHeader->setPPSId( pps.getPPSId() );
#if JVET_Z0118_GDR
picHeader->setPic(this);
#endif
memcpy(cs->alfApss, alfApss, sizeof(cs->alfApss));
cs->lmcsAps = lmcsAps;
cs->scalinglistAps = scalingListAps;

Karsten Suehring
committed
cs->pcv = pps.pcv;
Loading
Loading full blame...