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-2015, 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 | #include "SEIEncoder.h" |
---|
57 | |
---|
58 | #include "TEncAnalyze.h" |
---|
59 | #include "TEncRateCtrl.h" |
---|
60 | #include <vector> |
---|
61 | |
---|
62 | //! \ingroup TLibEncoder |
---|
63 | //! \{ |
---|
64 | |
---|
65 | class TEncTop; |
---|
66 | |
---|
67 | // ==================================================================================================================== |
---|
68 | // Class definition |
---|
69 | // ==================================================================================================================== |
---|
70 | |
---|
71 | class TEncGOP |
---|
72 | { |
---|
73 | class DUData |
---|
74 | { |
---|
75 | public: |
---|
76 | DUData() |
---|
77 | :accumBitsDU(0) |
---|
78 | ,accumNalsDU(0) {}; |
---|
79 | |
---|
80 | Int accumBitsDU; |
---|
81 | Int accumNalsDU; |
---|
82 | }; |
---|
83 | |
---|
84 | private: |
---|
85 | |
---|
86 | TEncAnalyze m_gcAnalyzeAll; |
---|
87 | TEncAnalyze m_gcAnalyzeI; |
---|
88 | TEncAnalyze m_gcAnalyzeP; |
---|
89 | TEncAnalyze m_gcAnalyzeB; |
---|
90 | |
---|
91 | TEncAnalyze m_gcAnalyzeAll_in; |
---|
92 | // Data |
---|
93 | Bool m_bLongtermTestPictureHasBeenCoded; |
---|
94 | Bool m_bLongtermTestPictureHasBeenCoded2; |
---|
95 | UInt m_numLongTermRefPicSPS; |
---|
96 | UInt m_ltRefPicPocLsbSps[MAX_NUM_LONG_TERM_REF_PICS]; |
---|
97 | Bool m_ltRefPicUsedByCurrPicFlag[MAX_NUM_LONG_TERM_REF_PICS]; |
---|
98 | Int m_iLastIDR; |
---|
99 | Int m_iGopSize; |
---|
100 | Int m_iNumPicCoded; |
---|
101 | Bool m_bFirst; |
---|
102 | Int m_iLastRecoveryPicPOC; |
---|
103 | |
---|
104 | // Access channel |
---|
105 | TEncTop* m_pcEncTop; |
---|
106 | TEncCfg* m_pcCfg; |
---|
107 | TEncSlice* m_pcSliceEncoder; |
---|
108 | TComList<TComPic*>* m_pcListPic; |
---|
109 | |
---|
110 | TEncEntropy* m_pcEntropyCoder; |
---|
111 | TEncCavlc* m_pcCavlcCoder; |
---|
112 | TEncSbac* m_pcSbacCoder; |
---|
113 | TEncBinCABAC* m_pcBinCABAC; |
---|
114 | TComLoopFilter* m_pcLoopFilter; |
---|
115 | |
---|
116 | SEIWriter m_seiWriter; |
---|
117 | |
---|
118 | #if NH_MV |
---|
119 | TComPicLists* m_ivPicLists; |
---|
120 | std::vector<TComPic*> m_refPicSetInterLayer0; |
---|
121 | std::vector<TComPic*> m_refPicSetInterLayer1; |
---|
122 | |
---|
123 | Int m_pocLastCoded; |
---|
124 | Int m_layerId; |
---|
125 | Int m_viewId; |
---|
126 | #endif |
---|
127 | //--Adaptive Loop filter |
---|
128 | TEncSampleAdaptiveOffset* m_pcSAO; |
---|
129 | TEncRateCtrl* m_pcRateCtrl; |
---|
130 | // indicate sequence first |
---|
131 | Bool m_bSeqFirst; |
---|
132 | |
---|
133 | // clean decoding refresh |
---|
134 | Bool m_bRefreshPending; |
---|
135 | Int m_pocCRA; |
---|
136 | NalUnitType m_associatedIRAPType; |
---|
137 | Int m_associatedIRAPPOC; |
---|
138 | |
---|
139 | std::vector<Int> m_vRVM_RP; |
---|
140 | UInt m_lastBPSEI; |
---|
141 | UInt m_totalCoded; |
---|
142 | Bool m_bufferingPeriodSEIPresentInAU; |
---|
143 | SEIEncoder m_seiEncoder; |
---|
144 | |
---|
145 | public: |
---|
146 | TEncGOP(); |
---|
147 | virtual ~TEncGOP(); |
---|
148 | |
---|
149 | Void create (); |
---|
150 | Void destroy (); |
---|
151 | |
---|
152 | Void init ( TEncTop* pcTEncTop ); |
---|
153 | #if NH_MV |
---|
154 | Void initGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, std::list<AccessUnit>& accessUnitsInGOP); |
---|
155 | Void compressPicInGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, |
---|
156 | std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE, Int iGOPid ); |
---|
157 | #else |
---|
158 | Void compressGOP ( Int iPOCLast, Int iNumPicRcvd, TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRec, |
---|
159 | std::list<AccessUnit>& accessUnitsInGOP, Bool isField, Bool isTff, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
---|
160 | #endif |
---|
161 | Void xAttachSliceDataToNalUnit (OutputNALUnit& rNalu, TComOutputBitstream* pcBitstreamRedirect); |
---|
162 | |
---|
163 | #if NH_MV |
---|
164 | Int getPocLastCoded () { return m_pocLastCoded; } |
---|
165 | Int getLayerId () { return m_layerId; } |
---|
166 | Int getViewId () { return m_viewId; } |
---|
167 | #endif |
---|
168 | |
---|
169 | Int getGOPSize() { return m_iGopSize; } |
---|
170 | |
---|
171 | TComList<TComPic*>* getListPic() { return m_pcListPic; } |
---|
172 | Void printOutSummary ( UInt uiNumAllPicCoded, Bool isField, const Bool printMSEBasedSNR, const Bool printSequenceMSE, const BitDepths &bitDepths ); |
---|
173 | Void preLoopFilterPicAll ( TComPic* pcPic, UInt64& ruiDist ); |
---|
174 | |
---|
175 | |
---|
176 | TEncSlice* getSliceEncoder() { return m_pcSliceEncoder; } |
---|
177 | NalUnitType getNalUnitType( Int pocCurr, Int lastIdr, Bool isField ); |
---|
178 | Void arrangeLongtermPicturesInRPS(TComSlice *, TComList<TComPic*>& ); |
---|
179 | |
---|
180 | protected: |
---|
181 | TEncRateCtrl* getRateCtrl() { return m_pcRateCtrl; } |
---|
182 | |
---|
183 | protected: |
---|
184 | |
---|
185 | Void xInitGOP ( Int iPOCLast, Int iNumPicRcvd, Bool isField ); |
---|
186 | Void xGetBuffer ( TComList<TComPic*>& rcListPic, TComList<TComPicYuv*>& rcListPicYuvRecOut, Int iNumPicRcvd, Int iTimeOffset, TComPic*& rpcPic, TComPicYuv*& rpcPicYuvRecOut, Int pocCurr, Bool isField ); |
---|
187 | |
---|
188 | Void xCalculateAddPSNRs ( const Bool isField, const Bool isFieldTopFieldFirst, const Int iGOPid, TComPic* pcPic, const AccessUnit&accessUnit, TComList<TComPic*> &rcListPic, Double dEncTime, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
---|
189 | Void xCalculateAddPSNR ( TComPic* pcPic, TComPicYuv* pcPicD, const AccessUnit&, Double dEncTime, const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
---|
190 | Void xCalculateInterlacedAddPSNR( TComPic* pcPicOrgFirstField, TComPic* pcPicOrgSecondField, |
---|
191 | TComPicYuv* pcPicRecFirstField, TComPicYuv* pcPicRecSecondField, |
---|
192 | const InputColourSpaceConversion snr_conversion, const Bool printFrameMSE ); |
---|
193 | UInt64 xFindDistortionFrame (TComPicYuv* pcPic0, TComPicYuv* pcPic1, const BitDepths &bitDepths); |
---|
194 | Double xCalculateRVM(); |
---|
195 | |
---|
196 | Void xCreateIRAPLeadingSEIMessages (SEIMessages& seiMessages, const TComSPS *sps, const TComPPS *pps); |
---|
197 | Void xCreatePerPictureSEIMessages (Int picInGOP, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, TComSlice *slice); |
---|
198 | Void xCreatePictureTimingSEI (Int IRAPGOPid, SEIMessages& seiMessages, SEIMessages& nestedSeiMessages, SEIMessages& duInfoSeiMessages, TComSlice *slice, Bool isField, std::deque<DUData> &duData); |
---|
199 | Void xUpdateDuData(AccessUnit &testAU, std::deque<DUData> &duData); |
---|
200 | Void xUpdateTimingSEI(SEIPictureTiming *pictureTimingSEI, std::deque<DUData> &duData, const TComSPS *sps); |
---|
201 | Void xUpdateDuInfoSEI(SEIMessages &duInfoSeiMessages, SEIPictureTiming *pictureTimingSEI); |
---|
202 | |
---|
203 | Void xCreateScalableNestingSEI (SEIMessages& seiMessages, SEIMessages& nestedSeiMessages); |
---|
204 | Void xWriteSEI (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComSPS *sps); |
---|
205 | Void xWriteSEISeparately (NalUnitType naluType, SEIMessages& seiMessages, AccessUnit &accessUnit, AccessUnit::iterator &auPos, Int temporalId, const TComSPS *sps); |
---|
206 | Void xClearSEIs(SEIMessages& seiMessages, Bool deleteMessages); |
---|
207 | Void xWriteLeadingSEIOrdered (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, Bool testWrite); |
---|
208 | Void xWriteLeadingSEIMessages (SEIMessages& seiMessages, SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, std::deque<DUData> &duData); |
---|
209 | Void xWriteTrailingSEIMessages (SEIMessages& seiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps); |
---|
210 | Void xWriteDuSEIMessages (SEIMessages& duInfoSeiMessages, AccessUnit &accessUnit, Int temporalId, const TComSPS *sps, std::deque<DUData> &duData); |
---|
211 | |
---|
212 | Int xWriteVPS (AccessUnit &accessUnit, const TComVPS *vps); |
---|
213 | Int xWriteSPS (AccessUnit &accessUnit, const TComSPS *sps); |
---|
214 | Int xWritePPS (AccessUnit &accessUnit, const TComPPS *pps); |
---|
215 | Int xWriteParameterSets (AccessUnit &accessUnit, TComSlice *slice); |
---|
216 | |
---|
217 | #if NH_MV |
---|
218 | Void xSetRefPicListModificationsMv( std::vector<TComPic*> tempPicLists[2], TComSlice* pcSlice, UInt iGOPid ); |
---|
219 | #endif |
---|
220 | |
---|
221 | |
---|
222 | Void applyDeblockingFilterMetric( TComPic* pcPic, UInt uiNumSlices ); |
---|
223 | };// END CLASS DEFINITION TEncGOP |
---|
224 | |
---|
225 | //! \} |
---|
226 | |
---|
227 | #endif // __TENCGOP__ |
---|
228 | |
---|