1 | |
---|
2 | |
---|
3 | #include "TEncSeqStructure.h" |
---|
4 | #include "TEncFormattedStringParser.h" |
---|
5 | #include <algorithm> |
---|
6 | |
---|
7 | ErrVal FrameDescriptor::initFrameDescriptor( const std::string& rcString, UInt &ruiIncrement, std::map<UInt, UInt>& rcColDirTracker) |
---|
8 | { |
---|
9 | std::string::size_type uiPos = 0; |
---|
10 | |
---|
11 | while( 1 ) |
---|
12 | { |
---|
13 | SliceType eSliceType; |
---|
14 | Bool bStoreForRef; |
---|
15 | Bool bIsIDR; |
---|
16 | UInt uiLayer; |
---|
17 | |
---|
18 | RNOK( TEncFormattedStringParser::extractFrameType( rcString, eSliceType, bStoreForRef, bIsIDR, uiPos ) ); |
---|
19 | RNOK( TEncFormattedStringParser::extractFrameLayer( rcString, uiLayer, uiPos ) ); |
---|
20 | |
---|
21 | m_aeSliceType.push_back( eSliceType ); |
---|
22 | m_abStoreForRef.push_back( bStoreForRef ); |
---|
23 | m_abIsIDR.push_back( bIsIDR ); |
---|
24 | m_auiLayer.push_back( uiLayer ); |
---|
25 | m_aaiAllowedRelativeRefPocsL0.push_back( std::vector<int>() ); |
---|
26 | m_aaiAllowedRelativeRefPocsL1.push_back( std::vector<int>() ); |
---|
27 | m_aaiAllowedReferenceViewIdxL0.push_back( std::vector<int>() ); |
---|
28 | m_aaiAllowedReferenceViewIdxL1.push_back( std::vector<int>() ); |
---|
29 | |
---|
30 | if( eSliceType == P_SLICE ) |
---|
31 | { |
---|
32 | RNOK( TEncFormattedStringParser::extractAllowedRelativeRefPocs( rcString, m_aaiAllowedRelativeRefPocsL0.back(), m_aaiAllowedReferenceViewIdxL0.back(), uiPos ) ); |
---|
33 | } |
---|
34 | else if( eSliceType == B_SLICE ) |
---|
35 | { |
---|
36 | RNOK( TEncFormattedStringParser::extractAllowedRelativeRefPocs( rcString, m_aaiAllowedRelativeRefPocsL0.back(), m_aaiAllowedRelativeRefPocsL1.back(), |
---|
37 | m_aaiAllowedReferenceViewIdxL0.back(), m_aaiAllowedReferenceViewIdxL1.back(), uiPos ) ); |
---|
38 | } |
---|
39 | |
---|
40 | // check that only available views are referenced |
---|
41 | { |
---|
42 | const Int iCurrViewIdx = Int( m_aeSliceType.size() - 1 ); |
---|
43 | for( UInt ui = 0; ui < m_aaiAllowedReferenceViewIdxL0.back().size(); ui++ ) |
---|
44 | { |
---|
45 | const Int iRefViewIdx = m_aaiAllowedReferenceViewIdxL0.back()[ui]; |
---|
46 | ROF( iRefViewIdx == -1 || ( 0 <= iRefViewIdx && iRefViewIdx < iCurrViewIdx ) ); |
---|
47 | } |
---|
48 | for( UInt ui = 0; ui < m_aaiAllowedReferenceViewIdxL1.back().size(); ui++ ) |
---|
49 | { |
---|
50 | const Int iRefViewIdx = m_aaiAllowedReferenceViewIdxL1.back()[ui]; |
---|
51 | ROF( iRefViewIdx == -1 || ( 0 <= iRefViewIdx && iRefViewIdx < iCurrViewIdx ) ); |
---|
52 | } |
---|
53 | } |
---|
54 | |
---|
55 | ROT( eSliceType == I_SLICE && ! m_aaiAllowedRelativeRefPocsL0.back().empty() && ! m_aaiAllowedRelativeRefPocsL1.back().empty() ); |
---|
56 | ROT( eSliceType == P_SLICE && ! m_aaiAllowedRelativeRefPocsL1.back().empty() ); |
---|
57 | if( rcString[uiPos] == '_' ) |
---|
58 | { |
---|
59 | uiPos++; |
---|
60 | break; |
---|
61 | } |
---|
62 | } |
---|
63 | |
---|
64 | RNOK( TEncFormattedStringParser::extractFrameIncrement( rcString, ruiIncrement, uiPos ) ); |
---|
65 | |
---|
66 | if(rcColDirTracker.find( m_auiLayer[0] )==rcColDirTracker.end()) |
---|
67 | rcColDirTracker.insert( std::make_pair(m_auiLayer[0],1) ); |
---|
68 | |
---|
69 | m_uiColDir = rcColDirTracker[ m_auiLayer[0] ]; |
---|
70 | rcColDirTracker[ m_auiLayer[0] ] = 1 - rcColDirTracker[ m_auiLayer[0] ]; |
---|
71 | |
---|
72 | ROF( std::string::npos == uiPos || rcString.length() == uiPos ); |
---|
73 | |
---|
74 | return Err::m_nOK; |
---|
75 | } |
---|
76 | |
---|
77 | |
---|
78 | UInt64 TEncSeqStructure::FrameSequencePart::findIncrement( UInt64 uiIncrement, bool &rbSuccess ) const |
---|
79 | { |
---|
80 | TOF( isInfinitelyLong() || uiIncrement < getSize() ); |
---|
81 | rbSuccess = false; |
---|
82 | const UInt64 uiOffset = uiIncrement % xGetSize(); |
---|
83 | for( UInt ui = 0; ui < UInt( m_auiIncrements.size() ); ui++ ) |
---|
84 | { |
---|
85 | if( uiOffset == m_auiIncrements[ui] ) |
---|
86 | { |
---|
87 | rbSuccess = true; |
---|
88 | return uiIncrement - uiOffset + ui; |
---|
89 | } |
---|
90 | } |
---|
91 | return 0; |
---|
92 | } |
---|
93 | |
---|
94 | |
---|
95 | TEncSeqStructure::FrameSequencePart::FrameSequencePart( const std::string& rcString ) |
---|
96 | { |
---|
97 | std::string cNoRepString; |
---|
98 | |
---|
99 | //----- get number of repetitions and number of frames ----- |
---|
100 | UInt uiNumRep = 0; |
---|
101 | TNOK( TEncFormattedStringParser::extractRepetitions( rcString, cNoRepString, uiNumRep ) ); |
---|
102 | xSetNumRep( uiNumRep ); |
---|
103 | UInt uiNumberOfFrames = 0; |
---|
104 | TNOK( TEncFormattedStringParser::getNumberOfFrames( cNoRepString, uiNumberOfFrames ) ); |
---|
105 | TOF( uiNumberOfFrames ); |
---|
106 | //----- create array ----- |
---|
107 | m_acFrameDescriptors.resize( uiNumberOfFrames ); |
---|
108 | TOF( m_acFrameDescriptors.size() == uiNumberOfFrames ); |
---|
109 | m_auiIncrements.resize( uiNumberOfFrames ); |
---|
110 | |
---|
111 | //----- initialize array ----- |
---|
112 | UInt uiIndex; |
---|
113 | size_t uiPos; |
---|
114 | for( uiPos = 0, uiIndex = 0; uiIndex < uiNumberOfFrames; uiIndex++ ) |
---|
115 | { |
---|
116 | std::string cFDString; |
---|
117 | TNOK( TEncFormattedStringParser::extractNextFrameDescription( cNoRepString, cFDString, uiPos ) ); |
---|
118 | UInt uiIncrement = 0; |
---|
119 | TNOK( m_acFrameDescriptors[uiIndex].initFrameDescriptor( cFDString, uiIncrement, m_cColDirTracker ) ); |
---|
120 | m_auiIncrements[uiIndex] = uiIncrement; |
---|
121 | } |
---|
122 | TNOK( xCheck() ); |
---|
123 | } |
---|
124 | |
---|
125 | |
---|
126 | ErrVal TEncSeqStructure::FrameSequencePart::xCheck() |
---|
127 | { |
---|
128 | ROTS( m_acFrameDescriptors.empty() ); |
---|
129 | |
---|
130 | std::vector<bool> abCovered( m_acFrameDescriptors.size(), false ); |
---|
131 | for( UInt uiIndex = 0; uiIndex < m_acFrameDescriptors.size(); uiIndex++ ) |
---|
132 | { |
---|
133 | const UInt uiInc = m_auiIncrements[uiIndex]; |
---|
134 | ROT( uiInc >= m_acFrameDescriptors.size() ); // error in config file parameter GOPFormatString |
---|
135 | ROT( abCovered[ uiInc ] ); |
---|
136 | abCovered[uiInc] = true; |
---|
137 | } |
---|
138 | |
---|
139 | return Err::m_nOK; |
---|
140 | } |
---|
141 | |
---|
142 | |
---|
143 | TEncSeqStructure::GeneralSequencePart::GeneralSequencePart( const std::string& rcString ) |
---|
144 | { |
---|
145 | std::string cNoRepString; |
---|
146 | |
---|
147 | UInt uiNumRep = 0; |
---|
148 | TNOK( TEncFormattedStringParser::extractRepetitions( rcString, cNoRepString, uiNumRep ) ); |
---|
149 | xSetNumRep( uiNumRep ); |
---|
150 | UInt uiNumberOfParts = 0; |
---|
151 | TNOK( TEncFormattedStringParser::getNumberOfParts( cNoRepString, uiNumberOfParts ) ); |
---|
152 | TOF( uiNumberOfParts ); |
---|
153 | |
---|
154 | //----- create array ----- |
---|
155 | m_apcSequenceParts.resize( uiNumberOfParts ); |
---|
156 | |
---|
157 | //----- initialize array ----- |
---|
158 | UInt uiIndex; |
---|
159 | size_t uiPos; |
---|
160 | for( uiPos = 0, uiIndex = 0; uiIndex < uiNumberOfParts; uiIndex++ ) |
---|
161 | { |
---|
162 | std::string cPartString; |
---|
163 | |
---|
164 | TNOK( TEncFormattedStringParser::extractPart( cNoRepString, cPartString, uiPos ) ); |
---|
165 | |
---|
166 | if( TEncFormattedStringParser::isFrameSequencePart( cPartString ) ) |
---|
167 | { |
---|
168 | m_apcSequenceParts[uiIndex] = new FrameSequencePart( cPartString ); |
---|
169 | } |
---|
170 | else |
---|
171 | { |
---|
172 | m_apcSequenceParts[uiIndex] = new GeneralSequencePart( cPartString ); |
---|
173 | } |
---|
174 | } |
---|
175 | } |
---|
176 | |
---|
177 | |
---|
178 | TEncSeqStructure::TEncSeqStructure() |
---|
179 | : m_pcSequencePart( NULL ) |
---|
180 | { |
---|
181 | } |
---|
182 | |
---|
183 | TEncSeqStructure::~TEncSeqStructure() |
---|
184 | { |
---|
185 | delete m_pcSequencePart; m_pcSequencePart = NULL ; |
---|
186 | } |
---|
187 | |
---|
188 | ErrVal TEncSeqStructure::init( const std::string& rcString ) |
---|
189 | { |
---|
190 | std::string cStringWithoutWhitespace; |
---|
191 | for( UInt ui = 0; ui < rcString.length(); ui++ ) |
---|
192 | { |
---|
193 | if( rcString[ui] != ' ' && rcString[ui] != '\t' ) |
---|
194 | { |
---|
195 | cStringWithoutWhitespace += rcString[ui]; |
---|
196 | } |
---|
197 | } |
---|
198 | |
---|
199 | if( cStringWithoutWhitespace.find( "*n{" ) == std::string::npos ) |
---|
200 | { |
---|
201 | cStringWithoutWhitespace = "*n{" + cStringWithoutWhitespace + "}"; |
---|
202 | } |
---|
203 | m_pcSequencePart = new GeneralSequencePart( cStringWithoutWhitespace ); |
---|
204 | |
---|
205 | return Err::m_nOK; |
---|
206 | } |
---|
207 | |
---|
208 | |
---|
209 | UInt TEncSeqStructure::getMaxAbsPocDiff( const UInt uiNumberOfFrames ) |
---|
210 | { |
---|
211 | TEncSeqStructure::Iterator cSeqIter = TEncSeqStructure::Iterator( *this, PicOrderCnt( 0 ), 0 ); |
---|
212 | |
---|
213 | UInt uiMaxAbsPocDiff = 0; |
---|
214 | Int64 iLastPoc = cSeqIter.getPoc(); |
---|
215 | int iNumFramesLeft = uiNumberOfFrames; |
---|
216 | |
---|
217 | for( int iIndex = 0; 0 != iNumFramesLeft; ++cSeqIter, iIndex++ ) |
---|
218 | { |
---|
219 | Int64 iPoc = cSeqIter.getPoc(); |
---|
220 | if( iPoc >= uiNumberOfFrames ) |
---|
221 | { |
---|
222 | // skiped due to frame behind end of sequence |
---|
223 | continue; |
---|
224 | } |
---|
225 | iNumFramesLeft--; |
---|
226 | //----- check POC differences ----- |
---|
227 | UInt uiAbsFrameDiffRef = (UInt) gAbs( iPoc - iLastPoc ); |
---|
228 | if( uiMaxAbsPocDiff < uiAbsFrameDiffRef ) |
---|
229 | { |
---|
230 | uiMaxAbsPocDiff = uiAbsFrameDiffRef; |
---|
231 | } |
---|
232 | iLastPoc = iPoc; |
---|
233 | } |
---|
234 | |
---|
235 | return uiMaxAbsPocDiff; |
---|
236 | } |
---|
237 | |
---|
238 | TEncSeqStructure::Iterator::Iterator( const TEncSeqStructure &r, PicOrderCnt cLayerChangeStartPoc, int iLayerOffset ) |
---|
239 | : m_cBasePoc( 0 ) |
---|
240 | , m_cLayerChangeStartPoc( cLayerChangeStartPoc ) |
---|
241 | , m_iLayerOffset( iLayerOffset ) |
---|
242 | { |
---|
243 | m_acSeqPartPath.resize( 1 ); |
---|
244 | xGetCurr().m_pcSeqPart = r.m_pcSequencePart; |
---|
245 | xGetCurr().m_uiCurrPos = 0; |
---|
246 | xGoToLeaf( false ); |
---|
247 | } |
---|
248 | |
---|
249 | void TEncSeqStructure::Iterator::xGoToLeaf( bool bGoToRightmostLeaf ) |
---|
250 | { |
---|
251 | while( !xGetCurr().m_pcSeqPart->isLeafNode() ) |
---|
252 | { |
---|
253 | SequencePartWithPos cPartWithPos; |
---|
254 | cPartWithPos.m_pcSeqPart = xGetCurr().m_pcSeqPart->getChildNode( xGetCurr().m_uiCurrPos ); |
---|
255 | cPartWithPos.m_uiCurrPos = 0; |
---|
256 | if( bGoToRightmostLeaf ) |
---|
257 | { |
---|
258 | TOT( cPartWithPos.m_pcSeqPart->isInfinitelyLong() ); |
---|
259 | cPartWithPos.m_uiCurrPos = cPartWithPos.m_pcSeqPart->getSize() - 1; |
---|
260 | } |
---|
261 | m_acSeqPartPath.push_back( cPartWithPos ); |
---|
262 | } |
---|
263 | } |
---|
264 | |
---|
265 | |
---|
266 | TEncSeqStructure::Iterator& TEncSeqStructure::Iterator::operator++() |
---|
267 | { |
---|
268 | ++xGetCurr().m_uiCurrPos; |
---|
269 | if( !xGetCurr().m_pcSeqPart->isInfinitelyLong() && xGetCurr().m_uiCurrPos == xGetCurr().m_pcSeqPart->getSize() ) |
---|
270 | { |
---|
271 | xGoToNextFrameSequencePart(); |
---|
272 | xGetCurr().m_uiCurrPos = 0; |
---|
273 | } |
---|
274 | return *this; |
---|
275 | } |
---|
276 | |
---|
277 | |
---|
278 | TEncSeqStructure::Iterator& TEncSeqStructure::Iterator::traverseByPocDiff( Int64 iPocDiff ) |
---|
279 | { |
---|
280 | const PicOrderCnt cTargetPoc = getPoc() + iPocDiff; |
---|
281 | const Int64 iIncrement = Int64( xGetCurr().m_pcSeqPart->getIncrement( xGetCurr().m_uiCurrPos ) ); |
---|
282 | if( iIncrement + iPocDiff < 0 ) |
---|
283 | { |
---|
284 | xGoToPreviousFrameSequencePart(); |
---|
285 | const Int64 iNewIncrement = Int64( xGetCurr().m_pcSeqPart->getIncrement( xGetCurr().m_uiCurrPos ) ); |
---|
286 | const Int64 iNewSize = Int64( xGetCurr().m_pcSeqPart->getSize() ); |
---|
287 | traverseByPocDiff( iPocDiff + iIncrement + iNewSize - iNewIncrement ); |
---|
288 | TOF( cTargetPoc == getPoc() ); |
---|
289 | return *this; |
---|
290 | } |
---|
291 | |
---|
292 | if( !xGetCurr().m_pcSeqPart->isInfinitelyLong() ) |
---|
293 | { |
---|
294 | const Int64 iSize = Int64( xGetCurr().m_pcSeqPart->getSize() ); |
---|
295 | if( iIncrement + iPocDiff >= iSize ) |
---|
296 | { |
---|
297 | xGoToNextFrameSequencePart(); |
---|
298 | traverseByPocDiff( iPocDiff - ( iSize - iIncrement ) ); |
---|
299 | TOF( cTargetPoc == getPoc() ); |
---|
300 | return *this; |
---|
301 | } |
---|
302 | } |
---|
303 | |
---|
304 | UInt64 uiPocDiffToFind = UInt64( iIncrement + iPocDiff ); |
---|
305 | bool bFound = false; |
---|
306 | xGetCurr().m_uiCurrPos = xGetCurr().m_pcSeqPart->findIncrement( uiPocDiffToFind, bFound ); |
---|
307 | TOF( bFound ); |
---|
308 | TOF( cTargetPoc == getPoc() ); |
---|
309 | return *this; |
---|
310 | } |
---|
311 | |
---|
312 | |
---|
313 | TEncSeqStructure::Iterator TEncSeqStructure::Iterator::getIterByPocDiff( Int64 iPocDiff ) const |
---|
314 | { |
---|
315 | Iterator cCopy = *this; |
---|
316 | cCopy.traverseByPocDiff( iPocDiff ); |
---|
317 | return cCopy; |
---|
318 | } |
---|
319 | |
---|
320 | |
---|
321 | void TEncSeqStructure::Iterator::xGoToPreviousFrameSequencePart() |
---|
322 | { |
---|
323 | TOF( xGetCurr().m_pcSeqPart->isLeafNode() ); |
---|
324 | TOF( m_acSeqPartPath.size() > 1 ); |
---|
325 | m_acSeqPartPath.pop_back(); |
---|
326 | while( xGetCurr().m_uiCurrPos == 0 ) |
---|
327 | { |
---|
328 | TOF( m_acSeqPartPath.size() > 1 ); |
---|
329 | m_acSeqPartPath.pop_back(); |
---|
330 | } |
---|
331 | xGetCurr().m_uiCurrPos--; |
---|
332 | xGoToLeaf( true ); |
---|
333 | m_cBasePoc -= xGetCurr().m_pcSeqPart->getSize(); |
---|
334 | } |
---|
335 | |
---|
336 | |
---|
337 | void TEncSeqStructure::Iterator::xGoToNextFrameSequencePart() |
---|
338 | { |
---|
339 | TOF( xGetCurr().m_pcSeqPart->isLeafNode() ); |
---|
340 | TOT( xGetCurr().m_pcSeqPart->isInfinitelyLong() ); |
---|
341 | m_cBasePoc += xGetCurr().m_pcSeqPart->getSize(); |
---|
342 | m_acSeqPartPath.pop_back(); |
---|
343 | while( !xGetCurr().m_pcSeqPart->isInfinitelyLong() && xGetCurr().m_uiCurrPos == xGetCurr().m_pcSeqPart->getSize() - 1 ) |
---|
344 | { |
---|
345 | TOF( m_acSeqPartPath.size() > 1 ); |
---|
346 | m_acSeqPartPath.pop_back(); |
---|
347 | } |
---|
348 | xGetCurr().m_uiCurrPos++; |
---|
349 | xGoToLeaf( false ); |
---|
350 | } |
---|
351 | |
---|
352 | |
---|
353 | |
---|