/src/vvdec/source/Lib/DecoderLib/DecLibRecon.h
Line | Count | Source |
1 | | /* ----------------------------------------------------------------------------- |
2 | | The copyright in this software is being made available under the Clear BSD |
3 | | License, included below. No patent rights, trademark rights and/or |
4 | | other Intellectual Property Rights other than the copyrights concerning |
5 | | the Software are granted under this license. |
6 | | |
7 | | The Clear BSD License |
8 | | |
9 | | Copyright (c) 2018-2026, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V. & The VVdeC Authors. |
10 | | All rights reserved. |
11 | | |
12 | | Redistribution and use in source and binary forms, with or without modification, |
13 | | are permitted (subject to the limitations in the disclaimer below) provided that |
14 | | the following conditions are met: |
15 | | |
16 | | * Redistributions of source code must retain the above copyright notice, |
17 | | this list of conditions and the following disclaimer. |
18 | | |
19 | | * Redistributions in binary form must reproduce the above copyright |
20 | | notice, this list of conditions and the following disclaimer in the |
21 | | documentation and/or other materials provided with the distribution. |
22 | | |
23 | | * Neither the name of the copyright holder nor the names of its |
24 | | contributors may be used to endorse or promote products derived from this |
25 | | software without specific prior written permission. |
26 | | |
27 | | NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY |
28 | | THIS LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND |
29 | | CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
30 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
31 | | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR |
32 | | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
33 | | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
34 | | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
35 | | BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER |
36 | | IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
37 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
38 | | POSSIBILITY OF SUCH DAMAGE. |
39 | | |
40 | | |
41 | | ------------------------------------------------------------------------------------------- */ |
42 | | |
43 | | /** \file DecLibRecon.h |
44 | | \brief decoder class (header) |
45 | | */ |
46 | | |
47 | | #pragma once |
48 | | |
49 | | #include "CommonLib/CommonDef.h" |
50 | | #include "CommonLib/AdaptiveLoopFilter.h" |
51 | | #include "CommonLib/LoopFilter.h" |
52 | | #include "CommonLib/InterPrediction.h" |
53 | | #include "CommonLib/IntraPrediction.h" |
54 | | #include "CommonLib/Picture.h" |
55 | | #include "CommonLib/RdCost.h" |
56 | | #include "CommonLib/Reshape.h" |
57 | | #include "CommonLib/SampleAdaptiveOffset.h" |
58 | | #include "CommonLib/TrQuant.h" |
59 | | |
60 | | #include "DecCu.h" |
61 | | #include "Utilities/ThreadPool.h" |
62 | | |
63 | | |
64 | | namespace vvdec |
65 | | { |
66 | | |
67 | | class DecLibRecon; |
68 | | class InterPrediction; |
69 | | class TrQuant; |
70 | | |
71 | | //! \ingroup DecoderLib |
72 | | //! \{ |
73 | | // ==================================================================================================================== |
74 | | // Class definition |
75 | | // ==================================================================================================================== |
76 | | |
77 | | |
78 | | enum TaskType |
79 | | { |
80 | | /*TRAFO=-1,*/ MIDER, MIDER_cont, LF_INIT, INTER, INTRA, INTRA_cont, RSP, LF_V, LF_V_cont, LF_H, PRESAO, SAO, SAO_cont, ALF, DONE, DMVR |
81 | | }; |
82 | | using CtuState = std::atomic<TaskType>; |
83 | | |
84 | | struct CommonTaskParam |
85 | | { |
86 | | DecLibRecon& decLib; |
87 | | CodingStructure* cs = nullptr; |
88 | | std::vector<CtuState> ctuStates; |
89 | | std::vector<MotionHist> perLineMiHist; |
90 | | |
91 | | bool doALF = true; |
92 | | |
93 | 0 | explicit CommonTaskParam( DecLibRecon* dec ) : decLib( *dec ) {} |
94 | | void reset( CodingStructure& cs, TaskType ctuStartState, int tasksPerLine, bool doALF ); |
95 | | }; |
96 | | |
97 | | struct SubPicExtTask |
98 | | { |
99 | | Picture* picture = nullptr; |
100 | | PelStorage* subPicBuf = nullptr; |
101 | | Area subPicArea; |
102 | | }; |
103 | | |
104 | | struct LineTaskParam |
105 | | { |
106 | | CommonTaskParam& common; |
107 | | int line; |
108 | | }; |
109 | | |
110 | | struct CtuTaskParam |
111 | | { |
112 | | CommonTaskParam& common; |
113 | | int taskLine; |
114 | | int taskCol; |
115 | | int ctuStart; |
116 | | int ctuEnd; |
117 | | int numColPerTask; |
118 | | int numTasksPerLine; |
119 | | }; |
120 | | |
121 | | struct FinishPicTaskParam |
122 | | { |
123 | | DecLibRecon* decLib; |
124 | | Picture* pic; |
125 | | |
126 | 0 | FinishPicTaskParam() : decLib( nullptr ), pic( nullptr ) {} |
127 | 0 | FinishPicTaskParam( DecLibRecon* _dec, Picture* _pic ) : decLib( _dec ), pic( _pic ) {} |
128 | | }; |
129 | | |
130 | | struct PerThreadResource |
131 | | { |
132 | | IntraPrediction m_cIntraPred; |
133 | | InterPrediction m_cInterPred; |
134 | | TrQuant m_cTrQuant; |
135 | | Reshape m_cReshaper; |
136 | | DecCu m_cCuDecoder; |
137 | | |
138 | 0 | explicit PerThreadResource() : m_cTrQuant( &m_cInterPred ) {} |
139 | 0 | explicit PerThreadResource( TrQuant& trQuant0 ) : m_cTrQuant( &m_cInterPred, &trQuant0 ) {} |
140 | | }; |
141 | | |
142 | | /// decoder class |
143 | | class DecLibRecon |
144 | | { |
145 | | private: |
146 | | PerThreadResource **m_pcThreadResource; |
147 | | RdCost m_cRdCost; |
148 | | LoopFilter m_cLoopFilter; |
149 | | SampleAdaptiveOffset m_cSAO; |
150 | | AdaptiveLoopFilter m_cALF; |
151 | | |
152 | | int m_numDecThreads = 0; |
153 | | ThreadPool* m_decodeThreadPool; |
154 | | bool m_upscaleOutputEnabled = false; |
155 | | |
156 | | Picture* m_currDecompPic = nullptr; |
157 | | #if TRACE_ENABLE_ITT |
158 | | __itt_domain* m_itt_decInst = nullptr; |
159 | | #endif |
160 | | |
161 | | std::unique_ptr<Pel[], AlignedDeleter<Pel>> |
162 | | m_predBuf; |
163 | | ptrdiff_t m_predBufSize = 0; |
164 | | Mv* m_dmvrMvCache = nullptr; |
165 | | size_t m_dmvrMvCacheSize = 0; |
166 | | ptrdiff_t m_num4x4Elements = 0; |
167 | | LoopFilterParam* m_loopFilterParam = nullptr; |
168 | | MotionInfo* m_motionInfo = nullptr; |
169 | | |
170 | | PelStorage m_fltBuf; |
171 | | |
172 | | CommonTaskParam commonTaskParam{ this }; |
173 | | std::vector<SubPicExtTask> m_subPicExtTasks; |
174 | | std::vector<LineTaskParam> tasksFinishMotion; |
175 | | std::vector<CtuTaskParam> tasksCtu; |
176 | | FinishPicTaskParam taskFinishPic; |
177 | | CBarrierVec picBarriers; |
178 | | |
179 | | public: |
180 | | DecLibRecon(); |
181 | 0 | ~DecLibRecon() = default; |
182 | | CLASS_COPY_MOVE_DELETE( DecLibRecon ) |
183 | | |
184 | | void create( ThreadPool* threadPool, unsigned instanceId, bool upscaleOutputEnabled ); |
185 | | void destroy(); |
186 | | |
187 | | void decompressPicture( Picture* pcPic ); |
188 | | Picture* waitForPrevDecompressedPic(); |
189 | | void cleanupOnException( std::exception_ptr exception ); |
190 | 0 | Picture* getCurrPic() const { return m_currDecompPic; } |
191 | | void swapBufs( CodingStructure& cs ); |
192 | | |
193 | | |
194 | | private: |
195 | | void borderExtPic ( Picture* pic, const Picture* currPic ); |
196 | | void createSubPicRefBufs( Picture* pic, const Picture* currPic ); |
197 | | |
198 | | template<bool checkReadyState=false> |
199 | | static bool ctuTask( int tid, CtuTaskParam* param ); |
200 | | }; |
201 | | |
202 | | } |