1 /******************************************************************************
5 * Copyright (C) 2002 Edouard Gomez <ed.gomez@wanadoo.fr>
7 * The curve treatment algorithm is based on work done by Foxer <email?> and
8 * Dirk Knop <dknop@gwdg.de> for the XviD vfw dynamic library.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 *****************************************************************************/
26 #ifndef __XVID_VBR_H__
27 #define __XVID_VBR_H__
31 /******************************************************************************
32 * Function types used in the vbr controler
33 *****************************************************************************/
35 typedef int (vbr_init_function
)(void *state
);
36 typedef vbr_init_function
*vbr_init_function_ptr
;
38 typedef int (vbr_get_quant_function
)(void *state
);
39 typedef vbr_get_quant_function
*vbr_get_quant_function_ptr
;
41 typedef int (vbr_get_intra_function
)(void *state
);
42 typedef vbr_get_intra_function
*vbr_get_intra_function_ptr
;
44 typedef int (vbr_update_function
)(void *state
,
52 typedef vbr_update_function
*vbr_update_function_ptr
;
54 typedef int (vbr_finish_function
)(void *state
);
55 typedef vbr_finish_function
*vbr_finish_function_ptr
;
57 /******************************************************************************
58 * The VBR CONTROLER structure - the spin of the library
59 *****************************************************************************/
61 typedef struct _vbr_control_t
64 /* All modes - specifies what VBR algorithm has to be used */
67 /* All modes - specifies what fps the movie uses */
74 * For VBR_MODE_2PASS_1/2 - specifies from/to what file the vbr
75 * controller has to write/read stats
79 /* For VBR_MODE_2PASS_2 - Target size */
82 /* For VBR_MODE_2PASS_2 - Credits parameters */
85 int credits_start_begin
;
86 int credits_start_end
;
88 int credits_end_begin
;
90 int credits_quant_ratio
;
91 int credits_fixed_quant
;
94 int credits_start_size
;
97 /* For VBR_MODE_2PASS_2 - keyframe parameters */
101 int min_key_interval
;
102 int max_key_interval
;
104 /* For VBR_MODE_2PASS_2 - Normal curve */
105 int curve_compression_high
;
106 int curve_compression_low
;
108 /* For VBR_MODE_2PASS_2 - Alternate curve parameters */
111 int alt_curve_low_dist
;
112 int alt_curve_high_dist
;
113 int alt_curve_min_rel_qual
;
114 int alt_curve_use_auto
;
115 int alt_curve_auto_str
;
116 int alt_curve_use_auto_bonus_bias
;
117 int alt_curve_bonus_bias
;
118 int bitrate_payback_method
;
119 int bitrate_payback_delay
;
124 int twopass_max_bitrate
;
125 int twopass_max_overflow_improvement
;
126 int twopass_max_overflow_degradation
;
129 * For VBR_MODE_FIXED_QUANT - the quantizer that has to be used for all
134 /* ----------- Internal data - Do not modify ----------- */
138 long long desired_size
;
144 int *keyframe_locations
;
147 double credits_start_curve
;
148 double credits_end_curve
;
150 double average_frame
;
151 double alt_curve_low
;
152 double alt_curve_low_diff
;
153 double alt_curve_high
;
154 double alt_curve_high_diff
;
155 double alt_curve_mid_qual
;
156 double alt_curve_qual_dev
;
157 double curve_bias_bonus
;
158 double curve_comp_scale
;
159 double curve_comp_error
;
171 double quant_error
[32];
175 int KFoverflow_partial
;
178 int debug_quant_count
[32];
180 /* ----------- Internal data - do not modify ----------- */
181 vbr_init_function_ptr init
;
182 vbr_get_quant_function_ptr getquant
;
183 vbr_get_intra_function_ptr getintra
;
184 vbr_update_function_ptr update
;
185 vbr_finish_function_ptr finish
;
189 /******************************************************************************
191 *****************************************************************************/
193 /* Constants for the mode member */
194 #define VBR_MODE_1PASS 0x01
195 #define VBR_MODE_2PASS_1 0x02
196 #define VBR_MODE_2PASS_2 0x04
197 #define VBR_MODE_FIXED_QUANT 0x08
199 /* Constants for the credits mode */
200 #define VBR_CREDITS_MODE_RATE 0x01
201 #define VBR_CREDITS_MODE_QUANT 0x02
202 #define VBR_CREDITS_MODE_SIZE 0x04
204 /* Alternate curve treatment types */
205 #define VBR_ALT_CURVE_SOFT 0x01
206 #define VBR_ALT_CURVE_LINEAR 0x02
207 #define VBR_ALT_CURVE_AGGRESIVE 0x04
210 #define VBR_PAYBACK_BIAS 0x01
211 #define VBR_PAYBACK_PROPORTIONAL 0x02
213 /******************************************************************************
215 *****************************************************************************/
217 extern int vbrSetDefaults(vbr_control_t
*state
);
218 extern int vbrInit(vbr_control_t
*state
);
219 extern int vbrGetQuant(vbr_control_t
*state
);
220 extern int vbrGetIntra(vbr_control_t
*state
);
221 extern int vbrUpdate(vbr_control_t
*state
,
229 extern int vbrFinish(vbr_control_t
*state
);