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-2017, 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 TAppEncTop.h |
---|
35 | \brief Encoder application class (header) |
---|
36 | */ |
---|
37 | |
---|
38 | #ifndef __TAPPENCTOP__ |
---|
39 | #define __TAPPENCTOP__ |
---|
40 | |
---|
41 | #include <list> |
---|
42 | #include <ostream> |
---|
43 | |
---|
44 | #include "TLibEncoder/TEncTop.h" |
---|
45 | #include "TLibVideoIO/TVideoIOYuv.h" |
---|
46 | #include "TLibCommon/AccessUnit.h" |
---|
47 | #include "TAppEncCfg.h" |
---|
48 | #if NH_3D_VSO |
---|
49 | #include "../../Lib/TLibRenderer/TRenTop.h" |
---|
50 | #endif |
---|
51 | |
---|
52 | #if KWU_RC_MADPRED_E0227 |
---|
53 | class TEncTop; |
---|
54 | #endif |
---|
55 | //! \ingroup TAppEncoder |
---|
56 | //! \{ |
---|
57 | |
---|
58 | // ==================================================================================================================== |
---|
59 | // Class definition |
---|
60 | // ==================================================================================================================== |
---|
61 | |
---|
62 | /// encoder application class |
---|
63 | class TAppEncTop : public TAppEncCfg |
---|
64 | { |
---|
65 | private: |
---|
66 | // class interface |
---|
67 | #if NH_MV |
---|
68 | std::vector<TEncTop*> m_acTEncTopList ; ///< encoder class per layer |
---|
69 | std::vector<TVideoIOYuv*> m_acTVideoIOYuvInputFileList; ///< input YUV file |
---|
70 | std::vector<TVideoIOYuv*> m_acTVideoIOYuvReconFileList; ///< output reconstruction file |
---|
71 | |
---|
72 | std::vector<TComList<TComPicYuv*>*> m_cListPicYuvRec; ///< list of reconstruction YUV files |
---|
73 | |
---|
74 | std::vector<Int> m_frameRcvd; ///< number of received frames |
---|
75 | TComPicLists m_ivPicLists; ///< picture buffers of encoder instances |
---|
76 | |
---|
77 | ParameterSetMap<TComSPS> m_spsMap; |
---|
78 | ParameterSetMap<TComPPS> m_ppsMap; |
---|
79 | |
---|
80 | IntAry1d m_parameterSetId; |
---|
81 | BoolAry1d m_sendParameterSets; |
---|
82 | |
---|
83 | |
---|
84 | #if NH_MV |
---|
85 | TComVPS* m_vps; ///< vps |
---|
86 | #else |
---|
87 | TComVPS m_vps; ///< vps |
---|
88 | #endif |
---|
89 | #else |
---|
90 | TEncTop m_cTEncTop; ///< encoder class |
---|
91 | TVideoIOYuv m_cTVideoIOYuvInputFile; ///< input YUV file |
---|
92 | TVideoIOYuv m_cTVideoIOYuvReconFile; ///< output reconstruction file |
---|
93 | |
---|
94 | TComList<TComPicYuv*> m_cListPicYuvRec; ///< list of reconstruction YUV files |
---|
95 | |
---|
96 | Int m_iFrameRcvd; ///< number of received frames |
---|
97 | #endif |
---|
98 | |
---|
99 | #if NH_3D |
---|
100 | TComSps3dExtension m_sps3dExtension; ///< Currently all layers share the same sps 3D Extension |
---|
101 | #endif |
---|
102 | |
---|
103 | UInt m_essentialBytes; |
---|
104 | UInt m_totalBytes; |
---|
105 | #if NH_3D_VSO |
---|
106 | TRenTop m_cRendererTop; |
---|
107 | TRenModel m_cRendererModel; |
---|
108 | #endif |
---|
109 | protected: |
---|
110 | // initialization |
---|
111 | Void xCreateLib (); ///< create files & encoder class |
---|
112 | Void xInitLibCfg (); ///< initialize internal variables |
---|
113 | Void xInitLib (Bool isFieldCoding); ///< initialize encoder class |
---|
114 | Void xDestroyLib (); ///< destroy encoder class |
---|
115 | |
---|
116 | /// obtain required buffers |
---|
117 | #if NH_MV |
---|
118 | Void xGetBuffer(TComPicYuv*& rpcPicYuvRec, UInt layer); |
---|
119 | #else |
---|
120 | Void xGetBuffer(TComPicYuv*& rpcPicYuvRec); |
---|
121 | #endif |
---|
122 | |
---|
123 | /// delete allocated buffers |
---|
124 | Void xDeleteBuffer (); |
---|
125 | |
---|
126 | // file I/O |
---|
127 | #if NH_MV |
---|
128 | Void xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, std::list<AccessUnit>& accessUnits, UInt layerId); ///< write bitstream to file |
---|
129 | #else |
---|
130 | Void xWriteOutput(std::ostream& bitstreamFile, Int iNumEncoded, const std::list<AccessUnit>& accessUnits); ///< write bitstream to file |
---|
131 | #endif |
---|
132 | Void rateStatsAccum(const AccessUnit& au, const std::vector<UInt>& stats); |
---|
133 | Void printRateSummary(); |
---|
134 | Void printChromaFormat(); |
---|
135 | |
---|
136 | #if NH_MV |
---|
137 | Void xSetTimingInfo ( TComVPS& vps ); |
---|
138 | Void xSetHrdParameters ( TComVPS& vps ); |
---|
139 | Void xSetLayerIds ( TComVPS& vps ); |
---|
140 | Void xSetDimensionIdAndLength ( TComVPS& vps ); |
---|
141 | Void xSetDependencies ( TComVPS& vps ); |
---|
142 | Void xSetLayerSets ( TComVPS& vps ); |
---|
143 | Void xSetProfileTierLevel ( TComVPS& vps ); |
---|
144 | |
---|
145 | Void xSetProfileTierLevel ( TComVPS& vps, Int profileTierLevelIdx, Int subLayer, |
---|
146 | Profile::Name profile, Level::Name level, Level::Tier tier, |
---|
147 | Bool progressiveSourceFlag, Bool interlacedSourceFlag, |
---|
148 | Bool nonPackedConstraintFlag, Bool frameOnlyConstraintFlag, |
---|
149 | Bool inbldFlag ); |
---|
150 | Void xSetRepFormat ( TComVPS& vps ); |
---|
151 | Void xSetDpbSize ( TComVPS& vps ); |
---|
152 | Void xSetVPSVUI ( TComVPS& vps ); |
---|
153 | #if NH_3D |
---|
154 | Void xSetCamPara ( TComVPS& vps ); |
---|
155 | #endif |
---|
156 | |
---|
157 | Void xDeriveParameterSetIds( TComVPS& vps ) |
---|
158 | { |
---|
159 | |
---|
160 | m_parameterSetId .clear(); |
---|
161 | m_sendParameterSets.clear(); |
---|
162 | |
---|
163 | m_parameterSetId .resize( m_numberOfLayers, -1 ); |
---|
164 | m_sendParameterSets.resize( m_numberOfLayers, false ); |
---|
165 | if ( !m_shareParameterSets ) |
---|
166 | { |
---|
167 | AOT( m_numberOfLayers > 16 ); |
---|
168 | for (Int curVpsLayerId = 0; curVpsLayerId < m_numberOfLayers; curVpsLayerId++ ) |
---|
169 | { |
---|
170 | m_parameterSetId [curVpsLayerId] = curVpsLayerId; |
---|
171 | m_sendParameterSets[curVpsLayerId] = true ; |
---|
172 | } |
---|
173 | } |
---|
174 | else |
---|
175 | { |
---|
176 | // The spec requires e.g.: |
---|
177 | // - It is a requirement of bitstream conformance that, when present, the value of chroma_format_idc shall be less than or equal to chroma_format_vps_idc |
---|
178 | // of the vps_rep_format_idx[ j ]-th rep_format( ) syntax structure in the active VPS, where j is equal to LayerIdxInVps[ layerIdCurr ]. |
---|
179 | |
---|
180 | // Consequently, a depth layer with chorma format 4:0:0 cannot refer to a base layer SPS with chroma format 4:2:0 |
---|
181 | |
---|
182 | // Furthermore, it is required that |
---|
183 | // - the SPS RBSP shall have nuh_layer_id equal to 0, nuhLayerId, or IdRefLayer[ nuhLayerId ][ i ] with any value of i in the range of 0 to NumRefLayers[ nuhLayerId ] - 1, inclusive. |
---|
184 | |
---|
185 | // Because of these requirements and when parameter set sharing is enabled, HTM sends the parameter sets for a current layer in its smallest reference layer having the same representation format. |
---|
186 | |
---|
187 | |
---|
188 | Int curPsId = 0; |
---|
189 | |
---|
190 | // Loop all layers |
---|
191 | for (Int curVpsLayerId = 0; curVpsLayerId < m_numberOfLayers; curVpsLayerId++ ) |
---|
192 | { |
---|
193 | // Get smallest reference layer with same rep format idx |
---|
194 | Int curNuhLayerId = vps.getLayerIdInNuh(curVpsLayerId); |
---|
195 | Int smallestRefNuhLIdSameRepFmt = curNuhLayerId; |
---|
196 | |
---|
197 | Int curRepFormatIdx = m_layerIdxInVpsToRepFormatIdx[ curVpsLayerId ]; |
---|
198 | |
---|
199 | for (Int j = 0; j < vps.getNumRefLayers( curNuhLayerId ); j++ ) |
---|
200 | { |
---|
201 | Int refNuhLayerId = vps.getIdRefLayer( curNuhLayerId, j ); |
---|
202 | Int refVpsLayerId = vps.getLayerIdInVps( refNuhLayerId ); |
---|
203 | |
---|
204 | if ( smallestRefNuhLIdSameRepFmt > refNuhLayerId && m_layerIdxInVpsToRepFormatIdx[refVpsLayerId] == curRepFormatIdx ) |
---|
205 | { |
---|
206 | smallestRefNuhLIdSameRepFmt = refNuhLayerId; |
---|
207 | } |
---|
208 | } |
---|
209 | |
---|
210 | Int smallestRefVpsLIdSameRepFmt = vps.getLayerIdInVps( smallestRefNuhLIdSameRepFmt ); |
---|
211 | |
---|
212 | if (smallestRefVpsLIdSameRepFmt == curVpsLayerId ) |
---|
213 | { |
---|
214 | m_sendParameterSets[ curVpsLayerId ] = true; |
---|
215 | m_parameterSetId [ curVpsLayerId ] = curPsId; |
---|
216 | curPsId++; |
---|
217 | AOT( curPsId > 15 ); |
---|
218 | } |
---|
219 | else |
---|
220 | { |
---|
221 | AOT( m_parameterSetId [ smallestRefVpsLIdSameRepFmt ] == -1 ); |
---|
222 | m_parameterSetId [ curVpsLayerId ] = m_parameterSetId [ smallestRefVpsLIdSameRepFmt ]; |
---|
223 | } |
---|
224 | |
---|
225 | |
---|
226 | } |
---|
227 | } |
---|
228 | } |
---|
229 | |
---|
230 | Int xGetMax( std::vector<Int>& vec); |
---|
231 | Bool xLayerIdInTargetEncLayerIdList( Int nuhLayerId ); |
---|
232 | #endif |
---|
233 | #if NH_3D |
---|
234 | Void xDeriveDltArray( TComVPS& vps, TComDLT* dlt ); |
---|
235 | Void xAnalyzeInputBaseDepth(UInt layer, UInt uiNumFrames, TComVPS* vps, TComDLT* dlt); |
---|
236 | #endif |
---|
237 | |
---|
238 | public: |
---|
239 | TAppEncTop(); |
---|
240 | virtual ~TAppEncTop(); |
---|
241 | |
---|
242 | Void encode (); ///< main encoding function |
---|
243 | #if NH_MV |
---|
244 | TEncTop* getTEncTop( UInt layer ) { return m_acTEncTopList[layer]; } ///< return pointer to encoder class for specific layer |
---|
245 | #else |
---|
246 | TEncTop& getTEncTop () { return m_cTEncTop; } ///< return encoder class pointer reference |
---|
247 | |
---|
248 | #endif |
---|
249 | private: |
---|
250 | |
---|
251 | };// END CLASS DEFINITION TAppEncTop |
---|
252 | |
---|
253 | //! \} |
---|
254 | |
---|
255 | #endif // __TAPPENCTOP__ |
---|
256 | |
---|