1 | /* The copyright in this software is being made available under the BSD |
---|
2 | * License, included below. This software may be subject to other third party |
---|
3 | * and contributor rights, including patent rights, and no such rights are |
---|
4 | * granted under this license. |
---|
5 | * |
---|
6 | * Copyright (c) 2010-2014, ITU/ISO/IEC |
---|
7 | * All rights reserved. |
---|
8 | * |
---|
9 | * Redistribution and use in source and binary forms, with or without |
---|
10 | * modification, are permitted provided that the following conditions are met: |
---|
11 | * |
---|
12 | * * Redistributions of source code must retain the above copyright notice, |
---|
13 | * this list of conditions and the following disclaimer. |
---|
14 | * * Redistributions in binary form must reproduce the above copyright notice, |
---|
15 | * this list of conditions and the following disclaimer in the documentation |
---|
16 | * and/or other materials provided with the distribution. |
---|
17 | * * Neither the name of the ITU/ISO/IEC nor the names of its contributors may |
---|
18 | * be used to endorse or promote products derived from this software without |
---|
19 | * specific prior written permission. |
---|
20 | * |
---|
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
---|
22 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
---|
23 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
---|
24 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS |
---|
25 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
26 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
27 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
28 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
29 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
---|
31 | * THE POSSIBILITY OF SUCH DAMAGE. |
---|
32 | */ |
---|
33 | |
---|
34 | /** \file TEncGOP.h |
---|
35 | \brief GOP encoder class (header) |
---|
36 | */ |
---|
37 | |
---|
38 | #ifndef __TENCGOP__ |
---|
39 | #define __TENCGOP__ |
---|
40 | |
---|
41 | #include <list> |
---|
42 | |
---|
43 | #include <stdlib.h> |
---|
44 | |
---|
45 | #include "TLibCommon/TComList.h" |
---|
46 | #include "TLibCommon/TComPic.h" |
---|
47 | #include "TLibCommon/TComBitCounter.h" |
---|
48 | #include "TLibCommon/TComLoopFilter.h" |
---|
49 | #include "TLibCommon/AccessUnit.h" |
---|
50 | #include "TEncSampleAdaptiveOffset.h" |
---|
51 | #include "TEncSlice.h" |
---|
52 | #include "TEncEntropy.h" |
---|
53 | #include "TEncCavlc.h" |
---|
54 | #include "TEncSbac.h" |
---|
55 | #include "SEIwrite.h" |
---|
56 | |
---|
57 | #include "TEncAnalyze.h" |
---|
58 | #include "TEncRateCtrl.h" |
---|
59 | #if KWU_RC_MADPRED_E0227 |
---|
60 | #include "../App/TAppEncoder/TAppEncTop.h" |
---|
61 | #endif |
---|
62 | #include <vector> |
---|
63 | |
---|
64 | //! \ingroup TLibEncoder |
---|
65 | //! \{ |
---|
66 | |
---|
67 | class TEncTop; |
---|
68 | |
---|
69 | // ==================================================================================================================== |
---|
70 | // Class definition |
---|
71 | // ==================================================================================================================== |
---|
72 | |
---|
73 | /// GOP encoder class |
---|
74 | class TEncGOP |
---|
75 | { |
---|
76 | private: |
---|
77 | // Data |
---|
78 | Bool m_bLongtermTestPictureHasBeenCoded; |
---|
79 | Bool m_bLongtermTestPictureHasBeenCoded2; |
---|
80 | UInt m_numLongTermRefPicSPS; |
---|
81 | UInt m_ltRefPicPocLsbSps[33]; |
---|
82 | Bool m_ltRefPicUsedByCurrPicFlag[33]; |
---|
83 | Int m_iLastIDR; |
---|
84 | Int m_iGopSize; |
---|
85 | Int m_iNumPicCoded; |
---|
86 | Bool m_bFirst; |
---|
87 | #if ALLOW_RECOVERY_POINT_AS_RAP |
---|
88 | Int m_iLastRecoveryPicPOC; |
---|
89 | #endif |
---|
90 | |
---|
91 | // Access channel |
---|
92 | TEncTop* m_pcEncTop; |
---|
93 | TEncCfg* m_pcCfg; |
---|
94 | TEncSlice* m_pcSliceEncoder; |
---|
95 | TComList<TComPic*>* m_pcListPic; |
---|
96 | |
---|
97 | TEncEntropy* m_pcEntropyCoder; |
---|
98 | TEncCavlc* m_pcCavlcCoder; |
---|
99 | TEncSbac* m_pcSbacCoder; |
---|
100 | TEncBinCABAC* m_pcBinCABAC; |
---|
101 | TComLoopFilter* m_pcLoopFilter; |
---|
102 | |
---|
103 | SEIWriter m_seiWriter; |
---|
104 | |
---|
105 | #if H_MV |
---|
106 | TComPicLists* m_ivPicLists; |
---|
107 | std::vector<TComPic*> m_refPicSetInterLayer0; |
---|
108 | std::vector<TComPic*> m_refPicSetInterLayer1; |
---|
109 | |
---|
110 | Int m_pocLastCoded; |
---|
111 | Int m_layerId; |
---|
112 | Int m_viewId; |
---|
113 | #if H_3D |
---|
114 | Int m_viewIndex; |
---|
115 | Bool m_isDepth; |
---|
116 | #endif |
---|
117 | #endif |
---|
118 | //--Adaptive Loop filter |
---|
119 | TEncSampleAdaptiveOffset* m_pcSAO; |
---|
120 | TComBitCounter* m_pcBitCounter; |
---|
121 | TEncRateCtrl* m_pcRateCtrl; |
---|
122 | // indicate sequence first |
---|
123 | Bool m_bSeqFirst; |
---|
124 | |
---|
125 | // clean decoding refresh |
---|
126 | Bool m_bRefreshPending; |
---|
127 | Int m_pocCRA; |
---|
128 | std::vector<Int> m_storedStartCUAddrForEncodingSlice; |
---|
129 | std::vector<Int> m_storedStartCUAddrForEncodingSliceSegment; |
---|
130 | #if FIX1172 |
---|
131 | NalUnitType m_associatedIRAPType; |
---|
132 | Int m_associatedIRAPPOC; |
---|
133 | #endif |
---|
134 | |
---|
135 | std::vector<Int> m_vRVM_RP; |
---|
136 | UInt m_lastBPSEI; |
---|
137 | UInt m_totalCoded; |
---|
138 | UInt m_cpbRemovalDelay; |
---|
139 | UInt m_tl0Idx; |
---|
140 | UInt m_rapIdx; |
---|
141 | Bool m_activeParameterSetSEIPresentInAU; |
---|
142 | Bool m_bufferingPeriodSEIPresentInAU; |
---|
143 | Bool m_pictureTimingSEIPresentInAU; |
---|
144 | Bool m_nestedBufferingPeriodSEIPresentInAU; |
---|
145 | Bool m_nestedPictureTimingSEIPresentInAU; |
---|
146 | public: |
---|
147 | TEncGOP(); |
---|
148 | virtual ~TEncGOP(); |
---|
149 | |
---|
150 | Void create (); |
---|
151 | Void destroy (); |
---|
152 | |
---|
153 | Void init ( TEncTop* pcTEncTop ); |
---|
154 | #if H_MV |
---|
155 | Void initGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP); |
---|
156 | Void compressPicInGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP, Int iGOPid, Bool isField, Bool isTff ); |
---|
157 | #else |
---|
158 | Void compressGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff ); |
---|
159 | #endif |
---|
160 | Void xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream*& rpcBitstreamRedirect); |
---|
161 | |
---|
162 | #if H_MV |
---|
163 | Int getPocLastCoded () { return m_pocLastCoded; } |
---|
164 | Int getLayerId () { return m_layerId; } |
---|
165 | Int getViewId () { return m_viewId; } |
---|
166 | #if H_3D |
---|
167 | Int getViewIndex () { return m_viewIndex; } |
---|
168 | Bool getIsDepth () { return m_isDepth; } |
---|
169 | #endif |
---|
170 | #endif |
---|
171 | |
---|
172 | Int getGOPSize() { return m_iGopSize; } |
---|
173 | |
---|
174 | TComList<TComPic*>* getListPic() { return m_pcListPic; } |
---|
175 | |
---|
176 | #if !H_MV |
---|
177 | Void printOutSummary ( UInt uiNumAllPicCoded , bool isField); |
---|
178 | #endif |
---|
179 | #if H_3D_VSO |
---|
180 | Void preLoopFilterPicAll ( TComPic* pcPic, Dist64& ruiDist, UInt64& ruiBits ); |
---|
181 | #else |
---|
182 | Void preLoopFilterPicAll ( TComPic* pcPic, UInt64& ruiDist, UInt64& ruiBits ); |
---|
183 | #endif |
---|
184 | |
---|
185 | #if KWU_RC_MADPRED_E0227 |
---|
186 | TEncTop* getEncTop() { return m_pcEncTop; } |
---|
187 | #endif |
---|
188 | |
---|
189 | TEncSlice* getSliceEncoder() { return m_pcSliceEncoder; } |
---|
190 | NalUnitType getNalUnitType( Int pocCurr, Int lastIdr, Bool isField ); |
---|
191 | Void arrangeLongtermPicturesInRPS(TComSlice *, TComList<TComPic*>& ); |
---|
192 | protected: |
---|
193 | TEncRateCtrl* getRateCtrl() { return m_pcRateCtrl; } |
---|
194 | |
---|
195 | protected: |
---|
196 | |
---|
197 | Void xInitGOP( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, bool isField ); |
---|
198 | Void xInitGOP ( Int iPOC, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut ); |
---|
199 | Void xGetBuffer ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, bool isField ); |
---|
200 | |
---|
201 | Void xCalculateAddPSNR ( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit&, Double dEncTime ); |
---|
202 | Void xCalculateInterlacedAddPSNR( TComPic* pcPicOrgTop, TComPic* pcPicOrgBottom, TComPicYuv* pcPicRecTop, TComPicYuv* pcPicRecBottom, const AccessUnit& accessUnit, Double dEncTime ); |
---|
203 | |
---|
204 | #if H_3D_VSO |
---|
205 | Dist64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1); |
---|
206 | #else |
---|
207 | UInt64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1); |
---|
208 | #endif |
---|
209 | |
---|
210 | Double xCalculateRVM(); |
---|
211 | |
---|
212 | SEIActiveParameterSets* xCreateSEIActiveParameterSets (TComSPS *sps); |
---|
213 | SEIFramePacking* xCreateSEIFramePacking(); |
---|
214 | SEIDisplayOrientation* xCreateSEIDisplayOrientation(); |
---|
215 | |
---|
216 | SEIToneMappingInfo* xCreateSEIToneMappingInfo(); |
---|
217 | #if H_MV |
---|
218 | SEISubBitstreamProperty *xCreateSEISubBitstreamProperty( TComSPS *sps); |
---|
219 | #endif |
---|
220 | |
---|
221 | Void xCreateLeadingSEIMessages (/*SEIMessages seiMessages,*/ AccessUnit &accessUnit, TComSPS *sps); |
---|
222 | Int xGetFirstSeiLocation (AccessUnit &accessUnit); |
---|
223 | Void xResetNonNestedSEIPresentFlags() |
---|
224 | { |
---|
225 | m_activeParameterSetSEIPresentInAU = false; |
---|
226 | m_bufferingPeriodSEIPresentInAU = false; |
---|
227 | m_pictureTimingSEIPresentInAU = false; |
---|
228 | } |
---|
229 | Void xResetNestedSEIPresentFlags() |
---|
230 | { |
---|
231 | m_nestedBufferingPeriodSEIPresentInAU = false; |
---|
232 | m_nestedPictureTimingSEIPresentInAU = false; |
---|
233 | } |
---|
234 | #if H_MV |
---|
235 | Void xSetRefPicListModificationsMv( std::vector<TComPic*> tempPicLists[2], TComSlice* pcSlice, UInt iGOPid ); |
---|
236 | #endif |
---|
237 | Void dblMetric( TComPic* pcPic, UInt uiNumSlices ); |
---|
238 | };// END CLASS DEFINITION TEncGOP |
---|
239 | |
---|
240 | // ==================================================================================================================== |
---|
241 | // Enumeration |
---|
242 | // ==================================================================================================================== |
---|
243 | enum PROCESSING_STATE |
---|
244 | { |
---|
245 | EXECUTE_INLOOPFILTER, |
---|
246 | ENCODE_SLICE |
---|
247 | }; |
---|
248 | |
---|
249 | enum SCALING_LIST_PARAMETER |
---|
250 | { |
---|
251 | SCALING_LIST_OFF, |
---|
252 | SCALING_LIST_DEFAULT, |
---|
253 | SCALING_LIST_FILE_READ |
---|
254 | }; |
---|
255 | |
---|
256 | //! \} |
---|
257 | |
---|
258 | #endif // __TENCGOP__ |
---|
259 | |
---|