# Dirac - A Video Codec

Created by the British Broadcasting Corporation.

rate_control.h
Go to the documentation of this file.
1 /* ***** BEGIN LICENSE BLOCK *****
2 *
3 * $Id: rate_control.h,v 1.7 2008/01/31 11:25:18 tjdwave Exp $ $Name: Dirac_1_0_2 $
4 *
5 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 *
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/
11 *
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.
15 *
16 * The Original Code is BBC Research and Development code.
17 *
18 * The Initial Developer of the Original Code is the British Broadcasting
19 * Corporation.
20 * Portions created by the Initial Developer are Copyright (C) 2004.
21 * All Rights Reserved.
22 *
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
26 *
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
37 * or the LGPL.
38 * ***** END LICENSE BLOCK ***** */
39
40
41 //Compression of an individual component,
42 //after motion compensation if appropriate
44
45 #ifndef _RATE_CONTROL_H_
46 #define _RATE_CONTROL_H_
47
48 #include <libdirac_common/common.h>
49
50 namespace dirac
51 {
52 class FrameComplexity
53 {
54 public:
56 FrameComplexity();
57
59 int IComplexity() {return m_XI;}
60
62 int L1Complexity() {return m_XL1;}
63
65 int L2Complexity() {return m_XL2;}
66
68 void SetIComplexity(int cpx) {m_XI = cpx;}
69
71 void SetL1Complexity(int cpx) {m_XL1 = cpx;}
72
74 void SetL2Complexity(int cpx) {m_XL2 = cpx;}
75
76
77 private:
78
80 int m_XI;
81
83 int m_XL1;
84
86 int m_XL2;
87 };
88
89
91 class RateController
92 {
93 public:
94
96 RateController(int trate, SourceParams& srcp, EncoderParams& encp);
97
98
100 void CalcNextQualFactor(const PictureParams& fparams, int num_bits);
101
103 void CalcNextIntraQualFactor();
104
106 void SetCutPictureQualFactor();
107
109 double IntraQualFactor() {return m_I_qf;}
110
112 double QualFactor() {return m_qf;}
113
115 void Report();
116
117
118 private:
119
120 double TargetSubgroupRate();
121
122 double ProjectedSubgroupRate();
123
125 void Allocate(const int fnum);
126
128 void CalcTotalBits(const SourceParams& sourceparams);
129
131 void SetIntraQualFactor(double value){m_I_qf = value;}
132
134 void SetFrameDistribution();
135
137 float ReviewQualityFactor( const float qfac, const long int num_bits );
138
140 float ClipQualityFactor( const float qfac );
141
143 void UpdateBuffer( const long int num_bits );
144
145
146 private:
147
149 double m_qf;
150
152 double m_I_qf;
153
155 double m_I_qf_long_term;
156
158 const int m_target_rate;
159
161 long int m_Iframe_bits;
162
164 long int m_L1frame_bits;
165
167 long int m_L2frame_bits;
168
170 int m_num_Iframe;
171
173 int m_num_L1frame;
174
176 int m_num_L2frame;
177
179 long int m_total_GOP_bits;
180
182 long int m_picture_bits;
183
185 const long int m_buffer_size;
186
188 long int m_buffer_bits;
189
191 long int m_old_buffer_bits;
192
194 double m_buffer_rate_of_change;
195
197 long int m_GOP_target;
198
200 double m_GOP_duration;
201
203 EncoderParams& m_encparams;
204
206 FrameComplexity m_frame_complexity;
207
209 int m_fcount;
210
211 // Indicated whether a sequence is being coded intra only or not
212 bool m_intra_only;
213
214 // Sum of complexity of L2 frames
215 int m_L2_complexity_sum;
216
217 };
218
219
220 }// namespace dirac
221 #endif

© 2004 British Broadcasting Corporation. Dirac code licensed under the Mozilla Public License (MPL) Version 1.1.
HTML documentation generated by Dimitri van Heesch's excellent Doxygen tool.