source: 3DVCSoftware/branches/0.2-poznan-univ/source/Lib/TLibEncoder/TEncSeqStructure.h @ 192

Last change on this file since 192 was 5, checked in by hhi, 13 years ago

Clean version with cfg-files

  • Property svn:eol-style set to native
File size: 9.2 KB
Line 
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-2011, 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 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
35
36#if !defined(AFX_TEncSeqStructure_H__268768B8_4D1D_484A_904E_586985833BAC__INCLUDED_)
37#define AFX_TEncSeqStructure_H__268768B8_4D1D_484A_904E_586985833BAC__INCLUDED_
38
39#include <cctype>
40#include "../TLibCommon/CommonDef.h"
41#include <vector>
42
43#include <map>
44
45
46class FrameDescriptor
47{
48public:
49  ErrVal initFrameDescriptor( const std::string&  rcString, UInt &ruiIncrement, std::map<UInt, UInt>& cColDirTracker);
50
51  const std::vector<int>& getAllowedRelativeRefPocs( RefPicList eRefPicList, UInt uiViewIdx ) const {
52    assert( eRefPicList == REF_PIC_LIST_0 || eRefPicList == REF_PIC_LIST_1 );
53    assert( m_aaiAllowedRelativeRefPocsL0.size() == m_aaiAllowedRelativeRefPocsL1.size() );
54    if( m_aaiAllowedRelativeRefPocsL0.size() <= uiViewIdx )
55    {
56      return eRefPicList == REF_PIC_LIST_0 ? m_aaiAllowedRelativeRefPocsL0.back() : m_aaiAllowedRelativeRefPocsL1.back();
57    }
58    return eRefPicList == REF_PIC_LIST_0 ? m_aaiAllowedRelativeRefPocsL0[uiViewIdx]: m_aaiAllowedRelativeRefPocsL1[uiViewIdx];
59  }
60
61  const std::vector<int>& getAllowedReferenceViewIdx( RefPicList eRefPicList, UInt uiViewIdx  ) const {
62    assert( eRefPicList == REF_PIC_LIST_0 || eRefPicList == REF_PIC_LIST_1 );
63    assert( m_aaiAllowedReferenceViewIdxL0.size() == m_aaiAllowedReferenceViewIdxL1.size() );
64    if( m_aaiAllowedReferenceViewIdxL0.size() <= uiViewIdx )
65    {
66      return eRefPicList == REF_PIC_LIST_0 ? m_aaiAllowedReferenceViewIdxL0.back() : m_aaiAllowedReferenceViewIdxL1.back();
67    }
68    return eRefPicList == REF_PIC_LIST_0 ? m_aaiAllowedReferenceViewIdxL0[uiViewIdx]: m_aaiAllowedReferenceViewIdxL1[uiViewIdx];
69  }
70
71  UInt getTEncSeqStructureLayer(UInt uiViewIdx)  const {
72    if (m_auiLayer.size() <= uiViewIdx)
73    {
74      return m_auiLayer.back();
75    }
76    return m_auiLayer[uiViewIdx];
77  }
78
79  bool getStoreForRef(UInt uiViewIdx)            const {
80    if (m_abStoreForRef.size() <= uiViewIdx)
81    {
82      return m_abStoreForRef.back();
83    }
84    return m_abStoreForRef[uiViewIdx];
85  }
86  bool isIdr(UInt uiViewIdx)                     const {
87    if (m_abIsIDR.size() <= uiViewIdx)
88    {
89      return m_abIsIDR.back();
90    }
91    return m_abIsIDR[uiViewIdx];
92  }
93  SliceType getSliceType(UInt uiViewIdx)        const {
94    if (m_aeSliceType.size() <= uiViewIdx)
95    {
96      return m_aeSliceType.back();
97    }
98    return m_aeSliceType[uiViewIdx];
99  }
100
101  UInt getColDir()  const { return m_uiColDir ; }
102
103  void addLayerOffset( Int iLayerOffset ) {
104     for(Int i = 0; i<m_auiLayer.size(); i++)
105     {
106       m_auiLayer[i] += iLayerOffset ;
107     }
108  }
109
110private:
111  std::vector<bool> m_abStoreForRef;
112  std::vector<bool> m_abIsIDR;
113  std::vector<UInt> m_auiLayer;
114  std::vector<SliceType>  m_aeSliceType;
115  std::vector< std::vector<int> > m_aaiAllowedRelativeRefPocsL0;
116  std::vector< std::vector<int> > m_aaiAllowedRelativeRefPocsL1;
117  std::vector< std::vector<int> > m_aaiAllowedReferenceViewIdxL0;
118  std::vector< std::vector<int> > m_aaiAllowedReferenceViewIdxL1;
119  UInt m_uiColDir ;
120
121};
122class TEncSeqStructure
123{
124private:
125  class SequencePart
126  {
127    DISABLE_DEFAULT_CPYCTOR_AND_ASOP( SequencePart );
128  protected:
129    SequencePart() : m_uiNumberOfRepetitions( 0 ) {}
130
131  public:
132    virtual ~SequencePart() {}
133
134    virtual bool isLeafNode() const = 0;
135    virtual SequencePart* getChildNode( UInt64 ui ) const { TOT( 1 ); return NULL; }
136    virtual const FrameDescriptor* getFrameDescriptor( UInt64 ui ) const { TOT( 1 ); return NULL; }
137
138    UInt64 getSize() const { TOT( isInfinitelyLong() ); return UInt64( m_uiNumberOfRepetitions ) * xGetSize(); }
139    UInt64 getIncrement( UInt64 ui ) const { return ui - UInt64( xGetIdx( ui ) ) + UInt64( xGetIncrement( ui ) ); }
140//    bool isInfinitelyLong() const { return m_uiNumberOfRepetitions == TypeLimits<UInt>::m_iMax; }
141    bool isInfinitelyLong() const { return m_uiNumberOfRepetitions == MAX_UINT; }
142
143    virtual UInt64 findIncrement( UInt64 uiIncrement, bool &rbSuccess ) const { TOT( 1 ); return 0; }
144
145  protected:
146    UInt xGetIdx( UInt64 ui ) const { return UInt( ui % xGetSize() ); }
147    void xSetNumRep( UInt ui )
148    {
149      TOT( m_uiNumberOfRepetitions );
150      TOF( ui );
151      m_uiNumberOfRepetitions = ui;
152    }
153
154  private:
155    virtual UInt   xGetIncrement( UInt64 ui ) const { TOT( 1 ); return 0; }
156    virtual UInt64 xGetSize() const = 0;
157
158    UInt m_uiNumberOfRepetitions; //GT: *n5{...}
159  };
160
161
162  class FrameSequencePart : public SequencePart //GT: Sequence of Frames without repetitions
163  {
164  public:
165    FrameSequencePart( const std::string& rcString );
166    virtual ~FrameSequencePart() {}
167
168    UInt64 xGetSize() const { return UInt64( m_acFrameDescriptors.size() ); }
169    bool isLeafNode() const { return true; }
170    const FrameDescriptor* getFrameDescriptor( UInt64 ui ) const { return &m_acFrameDescriptors[xGetIdx( ui )]; }
171    UInt xGetIncrement( UInt64 ui ) const { return m_auiIncrements[xGetIdx( ui )]; }
172    virtual UInt64 findIncrement( UInt64 uiIncrement, bool &rbSuccess ) const;
173
174  private:
175    ErrVal xCheck();
176
177    std::vector<FrameDescriptor> m_acFrameDescriptors; //GT: one descriptor for each frame B3L2(-4,+3)
178    std::vector<UInt> m_auiIncrements;                 //GT: same size as frame descriptor, stores increments  P7L1(-8)B3L2(-4,+3)b0L4(-2,+2,+6) -> 1 3 0
179
180    std::map<UInt,UInt> m_cColDirTracker ;
181  };
182
183
184  class GeneralSequencePart : public SequencePart  //GT: Sequence of FrameSequences
185  {
186  public:
187    GeneralSequencePart( const std::string& rcString );
188    virtual ~GeneralSequencePart() {}
189
190    UInt64 xGetSize() const { return UInt64( m_apcSequenceParts.size() ); }
191    bool isLeafNode() const { return false; }
192    SequencePart* getChildNode( UInt64 ui ) const { return m_apcSequenceParts[xGetIdx( ui )]; }
193
194  private:
195    AutoDeletePtrVector<SequencePart> m_apcSequenceParts;
196  };
197
198public:
199  TEncSeqStructure();
200  virtual ~TEncSeqStructure();
201
202  ErrVal init( const std::string& rcString );
203  UInt getMaxAbsPocDiff( const UInt uiNumberOfFrames );
204  UInt getDecodedPictureBufferSize( const UInt uiNumberOfFrames );
205  class Iterator
206  {
207  private:
208    class SequencePartWithPos
209    {
210    public:
211      const SequencePart *m_pcSeqPart;
212      UInt64 m_uiCurrPos;
213    };
214
215  public:
216    Iterator() : m_cBasePoc( 0 ) {}
217    virtual ~Iterator() {}
218
219    Iterator( const TEncSeqStructure &r, PicOrderCnt cLayerChangeStartPoc, int iLayerOffset );
220
221    FrameDescriptor getFrameDescriptor() const
222    {
223      if( m_iLayerOffset != 0 && getPoc() >= m_cLayerChangeStartPoc )
224      {
225        FrameDescriptor cModified = *xGetCurr().m_pcSeqPart->getFrameDescriptor( xGetCurr().m_uiCurrPos );
226        cModified.addLayerOffset ( m_iLayerOffset );
227        return cModified;
228      }
229      return *xGetCurr().m_pcSeqPart->getFrameDescriptor( xGetCurr().m_uiCurrPos );
230    }
231
232    PicOrderCnt getPoc() const { return m_cBasePoc + xGetCurr().m_pcSeqPart->getIncrement( xGetCurr().m_uiCurrPos ); }
233
234    Iterator& operator++();
235    Iterator& traverseByPocDiff( Int64 iPocDiff );
236    Iterator getIterByPocDiff( Int64 iPocDiff ) const;
237
238  private:
239    SequencePartWithPos&       xGetCurr()       { return m_acSeqPartPath.back(); }
240    const SequencePartWithPos& xGetCurr() const { return m_acSeqPartPath.back(); }
241
242    void xGoToPreviousFrameSequencePart();
243    void xGoToNextFrameSequencePart();
244
245    void xGoToLeaf( bool bGoToRightmostLeaf );
246
247    std::vector<SequencePartWithPos> m_acSeqPartPath;
248    PicOrderCnt m_cBasePoc;
249    PicOrderCnt m_cLayerChangeStartPoc;
250    int m_iLayerOffset;
251  };
252
253private:
254  SequencePart *m_pcSequencePart;
255};
256
257
258
259
260#endif // !defined(AFX_TEncSeqStructure_H__268768B8_4D1D_484A_904E_586985833BAC__INCLUDED_)
Note: See TracBrowser for help on using the repository browser.