1 /* -----------------------------------------------------------------------------
2 The copyright in this software is being made available under the 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 For any license concerning other Intellectual Property rights than the software,
8 especially patent licenses, a separate Agreement needs to be closed.
9 For more information please contact:
10 
11 Fraunhofer Heinrich Hertz Institute
12 Einsteinufer 37
13 10587 Berlin, Germany
14 www.hhi.fraunhofer.de/vvc
15 vvc@hhi.fraunhofer.de
16 
17 Copyright (c) 2018-2021, Fraunhofer-Gesellschaft zur Förderung der angewandten Forschung e.V.
18 All rights reserved.
19 
20 Redistribution and use in source and binary forms, with or without
21 modification, are permitted provided that the following conditions are met:
22 
23  * Redistributions of source code must retain the above copyright notice,
24    this list of conditions and the following disclaimer.
25  * Redistributions in binary form must reproduce the above copyright notice,
26    this list of conditions and the following disclaimer in the documentation
27    and/or other materials provided with the distribution.
28  * Neither the name of Fraunhofer nor the names of its contributors may
29    be used to endorse or promote products derived from this software without
30    specific prior written permission.
31 
32 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
33 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
36 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
37 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
38 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
39 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
40 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
41 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
42 THE POSSIBILITY OF SUCH DAMAGE.
43 
44 
45 ------------------------------------------------------------------------------------------- */
46 
47 /** \file     DecLibRecon.h
48     \brief    decoder class (header)
49 */
50 
51 #pragma once
52 
53 #include "CommonLib/CommonDef.h"
54 #include "CommonLib/Picture.h"
55 #include "CommonLib/RdCost.h"
56 #include "CommonLib/Reshape.h"
57 #include "CommonLib/LoopFilter.h"
58 #include "CommonLib/AdaptiveLoopFilter.h"
59 #include "CommonLib/SampleAdaptiveOffset.h"
60 
61 #include "Utilities/ThreadPool.h"
62 
63 namespace vvdec
64 {
65 
66 class DecLibRecon;
67 class IntraPrediction;
68 class InterPrediction;
69 class TrQuant;
70 class DecCu;
71 
72 //! \ingroup DecoderLib
73 //! \{
74 // ====================================================================================================================
75 // Class definition
76 // ====================================================================================================================
77 
78 
79 enum TaskType
80 {
81   /*TRAFO=-1,*/ MIDER, LF_INIT, INTER, INTRA, RSP, LF_V, LF_H, PRESAO, SAO, ALF, DONE, DMVR
82 };
83 using CtuState = std::atomic<TaskType>;
84 
85 struct CommonTaskParam
86 {
87   DecLibRecon&             decLib;
88   CodingStructure*         cs           = nullptr;
89   std::vector<CtuState>    ctuStates;
90   std::vector<MotionHist>  perLineMiHist;
91   std::vector<Barrier>     dmvrTriggers;
92 
93   bool                     doALF        = true;
94   Barrier                  alfPrepared;
95 
CommonTaskParamCommonTaskParam96   explicit CommonTaskParam( DecLibRecon* dec ) : decLib( *dec ) {}
97   void reset( CodingStructure& cs, TaskType ctuStartState, int tasksPerLine, bool doALF );
98 };
99 
100 struct SubPicExtTask
101 {
102   Picture*    picture   = nullptr;
103   PelStorage* subPicBuf = nullptr;
104   Area        subPicArea;
105 };
106 
107 struct LineTaskParam
108 {
109   CommonTaskParam& common;
110   int              line;
111 };
112 
113 struct CtuTaskParam
114 {
115   CommonTaskParam& common;
116   int              line;
117   int              col;
118   int              numColPerTask;
119   int              numTasksPerLine;
120 };
121 
122 /// decoder class
123 class DecLibRecon
124 {
125 private:
126   // functional classes
127   IntraPrediction*     m_cIntraPred = nullptr;
128   InterPrediction*     m_cInterPred = nullptr;
129   TrQuant*             m_cTrQuant   = nullptr;
130   DecCu*               m_cCuDecoder = nullptr;
131   RdCost               m_cRdCost;
132   Reshape*             m_cReshaper  = nullptr;   ///< reshaper class
133   LoopFilter           m_cLoopFilter;
134   SampleAdaptiveOffset m_cSAO;
135   AdaptiveLoopFilter   m_cALF;
136 
137   int                  m_numDecThreads = 0;
138   ThreadPool*          m_decodeThreadPool;
139 
140   Picture*             m_currDecompPic = nullptr;
141 #if TRACE_ENABLE_ITT
142   __itt_domain*        m_itt_decInst = nullptr;
143 #endif
144 
145   CommonTaskParam            commonTaskParam{ this };
146   std::vector<SubPicExtTask> m_subPicExtTasks;
147   std::vector<LineTaskParam> tasksDMVR;
148   std::vector<CtuTaskParam>  tasksCtu;
149   CBarrierVec                picBarriers;
150 
151 public:
152   DecLibRecon();
153   ~DecLibRecon() = default;
154   DecLibRecon( const DecLibRecon& )  = delete;
155   DecLibRecon( const DecLibRecon&& ) = delete;
156 
157   void create( ThreadPool* threadPool, unsigned instanceId );
158   void destroy();
159 
160   void     decompressPicture( Picture* pcPic );
161   Picture* waitForPrevDecompressedPic();
getCurrPic()162   Picture* getCurrPic() const { return m_currDecompPic; }
163 
164 
165 private:
166   void borderExtPic ( Picture* pic );
167   void createSubPicRefBufs( Picture* pic );
168 
169   template<bool checkReadyState=false>
170   static bool ctuTask( int tid, CtuTaskParam* param );
171 };
172 
173 }
174