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): Myo Tun (Original Author, myo.tun@brunel.ac.uk)
24 * Jonathan Loo (Jonathan.Loo@brunel.ac.uk)
25 * School of Engineering and Design, Brunel University, UK
27 * Alternatively, the contents of this file may be used under the terms of
28 * the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
29 * Public License Version 2.1 (the "LGPL"), in which case the provisions of
30 * the GPL or the LGPL are applicable instead of those above. If you wish to
31 * allow use of your version of this file only under the terms of the either
32 * the GPL or LGPL and not to allow others to use your version of this file
33 * under the MPL, indicate your decision by deleting the provisions above
34 * and replace them with the notice and other provisions required by the GPL
35 * or LGPL. If you do not delete the provisions above, a recipient may use
36 * your version of this file under the terms of any one of the MPL, the GPL
38 * ***** END LICENSE BLOCK ***** */
41 //Compression of an individual component,
42 //after motion compensation if appropriate
43 //////////////////////////////////////////
45 #ifndef _RATE_CONTROL_H_
46 #define _RATE_CONTROL_H_
48 #include <libdirac_common/common.h>
55 //! Default constructor
58 //! Return the complexity of I frame
59 int IComplexity() {return m_XI
;}
61 //! Return the complexity of L1 frame
62 int L1Complexity() {return m_XL1
;}
64 //! Return the complexity of L2 frame
65 int L2Complexity() {return m_XL2
;}
67 //! Set the complexity of I frame
68 void SetIComplexity(int cpx
) {m_XI
= cpx
;}
70 //! Set the complexity of L1 frame
71 void SetL1Complexity(int cpx
) {m_XL1
= cpx
;}
73 //! Set the complexity of L2 frame
74 void SetL2Complexity(int cpx
) {m_XL2
= cpx
;}
79 //! Complexity of I frame
82 //! Complexity of L1 frame
85 //! Complexity of L2 frame
90 //! A clas for allocation the bits to each and every types of frames in a GOP
95 //! Default constructor
96 RateController(int trate
, SourceParams
& srcp
, EncoderParams
& encp
);
99 //! Calculate the Quality factor of the next frame to encode
100 void CalcNextQualFactor(const PictureParams
& fparams
, int num_bits
);
102 //! Calculate the Quality factor of the next I frame to encode
103 void CalcNextIntraQualFactor();
105 //! Use the long-term average intra quality factor
106 void SetCutPictureQualFactor();
108 //! Return I frame qf
109 double IntraQualFactor() {return m_I_qf
;}
112 double QualFactor() {return m_qf
;}
114 //! Report the allocation to picture types
120 double TargetSubgroupRate();
122 double ProjectedSubgroupRate();
124 //! Allocate the bits to each type of frame in a GOP
125 void Allocate(const int fnum
);
127 //! Calculate the total number of bits in a GOP
128 void CalcTotalBits(const SourceParams
& sourceparams
);
130 //! Set the value of Current IQF
131 void SetIntraQualFactor(double value
){m_I_qf
= value
;}
133 //! Set the number of I, L1 and L2 frames in the GOP
134 void SetFrameDistribution();
136 //! Review the quality factor to make sure it's being set sensibly
137 float ReviewQualityFactor( const float qfac
, const long int num_bits
);
139 //! Clip the quality factor to something sensible
140 float ClipQualityFactor( const float qfac
);
142 //! Update the internal decoder buffer model
143 void UpdateBuffer( const long int num_bits
);
148 //! Current Quality Factor
151 //! I frame Quality Factor
154 //! Long-term average of I frame Quality Factor
155 double m_I_qf_long_term
;
157 //! Target bit rate in kbps
158 const int m_target_rate
;
160 //! Number of bits for I frame
161 long int m_Iframe_bits
;
163 //! Number of bits for L1 frame
164 long int m_L1frame_bits
;
166 //! Number of bits for L2 frame
167 long int m_L2frame_bits
;
169 //! Number of I frames
172 //! Number of L1 frames
175 //! Number of L2 frames
178 //! Total Number of bits in a GOP
179 long int m_total_GOP_bits
;
181 //! Mean number of bits in a picture
182 long int m_picture_bits
;
184 //! Size of the decoded bit buffer
185 const long int m_buffer_size
;
187 //! Number of bits in the buffer
188 long int m_buffer_bits
;
190 //! The old buffer occupancy
191 long int m_old_buffer_bits
;
193 //! The rate of change of buffer occupancy
194 double m_buffer_rate_of_change
;
196 //! The target number of bits for the current GOP
197 long int m_GOP_target
;
199 //! The duration of a GOP
200 double m_GOP_duration
;
202 //! A reference to the encoder parameters
203 EncoderParams
& m_encparams
;
205 //! A class to hold the frame complexity object
206 FrameComplexity m_frame_complexity
;
208 //! A frame counter, giving the position within a subgroup
211 // Indicated whether a sequence is being coded intra only or not
214 // Sum of complexity of L2 frames
215 int m_L2_complexity_sum
;