1 /* ***** BEGIN LICENSE BLOCK *****
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
7 * The contents of this file are subject to the Mozilla Public License
8 * Version 1.1 (the "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 * http://www.mozilla.org/MPL/
12 * Software distributed under the License is distributed on an "AS IS" basis,
13 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
14 * the specific language governing rights and limitations under the License.
16 * The Original Code is BBC Research and Development code.
18 * The Initial Developer of the Original Code is the British Broadcasting
20 * Portions created by the Initial Developer are Copyright (C) 2004.
21 * All Rights Reserved.
23 * Contributor(s): Thomas Davies (Original Author),
26 * Alternatively, the contents of this file may be used under the terms of
27 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
28 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
29 * the GPL or the LGPL are applicable instead of those above. If you wish to
30 * allow use of your version of this file only under the terms of the either
31 * the GPL or LGPL and not to allow others to use your version of this file
32 * under the MPL, indicate your decision by deleting the provisions above
33 * and replace them with the notice and other provisions required by the GPL
34 * or LGPL. If you do not delete the provisions above, a recipient may use
35 * your version of this file under the terms of any one of the MPL, the GPL
37 * ***** END LICENSE BLOCK ***** */
44 #include <libdirac_encoder/enc_picture.h>
45 #include <libdirac_common/common.h>
49 //! Holds pictures both for reference and to overcome reordering delay
51 The buffer holds pictures in a stack to overcome both reordering due to
52 bi-directional prediction and use as references for subsequence motion
53 estimation. Pictures, and components of pictures, can be accessed by their
54 picture numbers. GOP parameters can be included in the constructors so
55 that pictures can be given types (I picture, L1 picture or L2 picture) on
56 being pushed onto the stack; alternatively, these parameters can be
61 //! Default Constructor
66 Creates a EncQueue using the chroma format. Suitable for
67 compressing when there are no L2 pictures, or when the temporal
68 prediction structure is to be determined on the fly.
70 \param cf the Chroma format of pictures in the buffer
71 \param xlen the luma width of pictures in the buffer
72 \param ylen the luma height of pictures in the buffer
73 \param luma_depth the video depth of the luma comp in the buffer
74 \param chroma_depth the video depth of the chroma comp in the buffer
75 \param using_ac True if using Arithmetic coding to code coefficient data
78 EncQueue(ChromaFormat cf
,
81 const unsigned int luma_depth
,
82 const unsigned int chroma_depth
,
87 Creates a EncQueue using the chroma format, the number of L1
88 pictures between I pictures and the separation in pictures between L1
89 pictures. Suitable for compressing when there is a full GOP structure
90 or when the temporal prediction structure is to be determined on
93 \param cf the Chroma format of pictures in the buffer
94 \param numL1 the number of Layer 1 pictures before the next I picture. 0 means that there is only one I picture.
95 \param L1sep the number of Layer 2 pictures between Layer 1 pictures
96 \param xlen the luma width of pictures in the buffer
97 \param ylen the luma height of pictures in the buffer
98 \param luma_depth the video depth of the luma comp in the buffer
99 \param chroma_depth the video depth of the chroma comp in the buffer
100 \param interlace Set true if material is being coded in interlaced mode
101 \param using_ac True if using Arithmetic coding to code coefficient data
103 EncQueue(ChromaFormat cf
,
108 const unsigned int luma_depth
,
109 const unsigned int chroma_depth
,
115 Copy constructor. Removes the current contents of the pictureture buffer
116 and copies in the contents of the initialising buffer.
118 EncQueue(const EncQueue
& cpy
);
122 Operator=. Assigns all elements of the rhs to the lhs.
124 EncQueue
& operator=(const EncQueue
& rhs
);
129 //! Get picture with a given picture number (NOT with a given position in the buffer)
130 EncPicture
& GetPicture(const unsigned int pnum
);
132 //! Get picture with a given picture number (NOT with a given position in the buffer)
133 const EncPicture
& GetPicture(const unsigned int pnum
) const;
135 //! Get picture with a given picture number, setting a flag to true if it's there
136 EncPicture
& GetPicture(const unsigned int pnum
, bool& is_present
);
138 //! Get picture with a given picture number, setting a flag to true if it's there
139 const EncPicture
& GetPicture(const unsigned int pnum
, bool& is_present
) const;
141 //! Return true if picture with the particular picture number is available else return false
142 bool IsPictureAvail(const unsigned int pnum
) const;
144 //! Returns a list of member pictures
145 std::vector
<int> Members() const;
147 //! Returns the size of the queue
148 int Size() const { return m_pic_data
.size(); }
150 //! Put a new picture into the top of the buffer
152 Put a new picture into the top of the buffer. EncPicture parameters
153 associated with the picture will be as given by the picture parameter
156 void PushPicture(const PictureParams
& pp
);
158 //! Put a copy of a new picture into the buffer
160 Put a copy of a new picture into the buffer.
162 void CopyPicture( const EncPicture
& picture
);
164 //! Sets the reference picture number that will be cleaned
166 Indicate which picture which has been output and which is no longer
167 required for reference. Expiry times are set in each picture's
169 \param show_pnum picture number in display order that can be output
170 \param current_coded_pnum picture number in display order of picture currently being coded
172 void SetRetiredPictureNum(const int show_pnum
, const int current_coded_pnum
);
174 //! Delete all expired pictures
176 Delete pictures which have been output and which are no longer
177 required for reference. Expiry times are set in each picture's
179 \param show_pnum picture number in display order that can be output
180 \param current_coded_pnum picture number in display order of picture currently being coded
182 void CleanAll(const int show_pnum
, const int current_coded_pnum
);
184 //! Delete retired reference pictures and expired non-ref pictures
186 Delete pictures which have been output and retired reference pictures.
187 Expiry times are set in each picture's picture parameters.
188 \param show_pnum picture number in display order that can be output
189 \param current_coded_pnum picture number in display order of picture currently being coded
191 void CleanRetired(const int show_pnum
, const int current_coded_pnum
);
196 \param pnum picture number in display order to be deleted from picture buffer
198 void Remove(int pnum
);
201 //! Clear internal data slot number pos
203 Clear internal data slot number pos
205 void ClearSlot(const unsigned int pos
);
209 // //! the count of the number of reference pictures in the buffer
212 //! the buffer storing all the values
213 std::vector
<EncPicture
*> m_pic_data
;
215 //!the map from picture numbers to position in the buffer
216 std::map
<unsigned int,unsigned int> m_pnum_map
;