# 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
common.h
dirac
Definition of class SequenceHeaderByteIO.
Definition: accessunit_byteio.h:52
dirac::SourceParams
Parameters relating to the source material being encoded/decoded.
Definition: common.h:289
dirac::PictureParams
Parameters for initialising picture class objects.
Definition: common.h:533
dirac::EncoderParams
Parameters for the encoding process.
Definition: common.h:1280
dirac::FrameComplexity
Definition: rate_control.h:53
dirac::FrameComplexity::SetL2Complexity
void SetL2Complexity(int cpx)
Set the complexity of L2 frame.
Definition: rate_control.h:74
dirac::FrameComplexity::m_XL1
int m_XL1
Complexity of L1 frame.
Definition: rate_control.h:83
dirac::FrameComplexity::SetIComplexity
void SetIComplexity(int cpx)
Set the complexity of I frame.
Definition: rate_control.h:68
dirac::FrameComplexity::SetL1Complexity
void SetL1Complexity(int cpx)
Set the complexity of L1 frame.
Definition: rate_control.h:71
dirac::FrameComplexity::m_XL2
int m_XL2
Complexity of L2 frame.
Definition: rate_control.h:86
dirac::FrameComplexity::L2Complexity
int L2Complexity()
Return the complexity of L2 frame.
Definition: rate_control.h:65
dirac::FrameComplexity::L1Complexity
int L1Complexity()
Return the complexity of L1 frame.
Definition: rate_control.h:62
dirac::FrameComplexity::m_XI
int m_XI
Complexity of I frame.
Definition: rate_control.h:80
dirac::FrameComplexity::IComplexity
int IComplexity()
Return the complexity of I frame.
Definition: rate_control.h:59
dirac::FrameComplexity::FrameComplexity
FrameComplexity()
Default constructor.
dirac::RateController
A clas for allocation the bits to each and every types of frames in a GOP.
Definition: rate_control.h:92
dirac::RateController::m_qf
double m_qf
Current Quality Factor.
Definition: rate_control.h:149
dirac::RateController::m_target_rate
const int m_target_rate
Target bit rate in kbps.
Definition: rate_control.h:158
dirac::RateController::m_intra_only
bool m_intra_only
Definition: rate_control.h:212
dirac::RateController::ProjectedSubgroupRate
double ProjectedSubgroupRate()
dirac::RateController::m_buffer_bits
long int m_buffer_bits
Number of bits in the buffer.
Definition: rate_control.h:188
dirac::RateController::QualFactor
double QualFactor()
Return qf.
Definition: rate_control.h:112
dirac::RateController::m_I_qf
double m_I_qf
I frame Quality Factor.
Definition: rate_control.h:152
dirac::RateController::CalcNextQualFactor
void CalcNextQualFactor(const PictureParams &fparams, int num_bits)
Calculate the Quality factor of the next frame to encode.
dirac::RateController::CalcTotalBits
void CalcTotalBits(const SourceParams &sourceparams)
Calculate the total number of bits in a GOP.
dirac::RateController::UpdateBuffer
void UpdateBuffer(const long int num_bits)
Update the internal decoder buffer model.
dirac::RateController::ReviewQualityFactor
float ReviewQualityFactor(const float qfac, const long int num_bits)
Review the quality factor to make sure it's being set sensibly.
dirac::RateController::IntraQualFactor
double IntraQualFactor()
Return I frame qf.
Definition: rate_control.h:109
dirac::RateController::SetFrameDistribution
void SetFrameDistribution()
Set the number of I, L1 and L2 frames in the GOP.
dirac::RateController::m_num_L1frame
int m_num_L1frame
Number of L1 frames.
Definition: rate_control.h:173
dirac::RateController::m_buffer_rate_of_change
double m_buffer_rate_of_change
The rate of change of buffer occupancy.
Definition: rate_control.h:194
dirac::RateController::SetCutPictureQualFactor
void SetCutPictureQualFactor()
Use the long-term average intra quality factor.
dirac::RateController::m_L1frame_bits
long int m_L1frame_bits
Number of bits for L1 frame.
Definition: rate_control.h:164
dirac::RateController::ClipQualityFactor
float ClipQualityFactor(const float qfac)
Clip the quality factor to something sensible.
dirac::RateController::TargetSubgroupRate
double TargetSubgroupRate()
dirac::RateController::m_num_Iframe
int m_num_Iframe
Number of I frames.
Definition: rate_control.h:170
dirac::RateController::m_L2_complexity_sum
int m_L2_complexity_sum
Definition: rate_control.h:215
dirac::RateController::Allocate
void Allocate(const int fnum)
Allocate the bits to each type of frame in a GOP.
dirac::RateController::Report
void Report()
Report the allocation to picture types.
dirac::RateController::m_GOP_target
long int m_GOP_target
The target number of bits for the current GOP.
Definition: rate_control.h:197
dirac::RateController::m_buffer_size
const long int m_buffer_size
Size of the decoded bit buffer.
Definition: rate_control.h:185
dirac::RateController::RateController
RateController(int trate, SourceParams &srcp, EncoderParams &encp)
Default constructor.
dirac::RateController::m_total_GOP_bits
long int m_total_GOP_bits
Total Number of bits in a GOP.
Definition: rate_control.h:179
dirac::RateController::m_frame_complexity
FrameComplexity m_frame_complexity
A class to hold the frame complexity object.
Definition: rate_control.h:206
dirac::RateController::CalcNextIntraQualFactor
void CalcNextIntraQualFactor()
Calculate the Quality factor of the next I frame to encode.
dirac::RateController::m_old_buffer_bits
long int m_old_buffer_bits
The old buffer occupancy.
Definition: rate_control.h:191
dirac::RateController::m_picture_bits
long int m_picture_bits
Mean number of bits in a picture.
Definition: rate_control.h:182
dirac::RateController::m_encparams
EncoderParams & m_encparams
A reference to the encoder parameters.
Definition: rate_control.h:203
dirac::RateController::SetIntraQualFactor
void SetIntraQualFactor(double value)
Set the value of Current IQF.
Definition: rate_control.h:131
dirac::RateController::m_I_qf_long_term
double m_I_qf_long_term
Long-term average of I frame Quality Factor.
Definition: rate_control.h:155
dirac::RateController::m_num_L2frame
int m_num_L2frame
Number of L2 frames.
Definition: rate_control.h:176
dirac::RateController::m_GOP_duration
double m_GOP_duration
The duration of a GOP.
Definition: rate_control.h:200
dirac::RateController::m_L2frame_bits
long int m_L2frame_bits
Number of bits for L2 frame.
Definition: rate_control.h:167
dirac::RateController::m_Iframe_bits
long int m_Iframe_bits
Number of bits for I frame.
Definition: rate_control.h:161
dirac::RateController::m_fcount
int m_fcount
A frame counter, giving the position within a subgroup.
Definition: rate_control.h:209

© 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.