Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(38)

Side by Side Diff: source/libvpx/vp8/encoder/ratectrl.c

Issue 11974002: libvpx: Pull from upstream (Closed) Base URL: svn://chrome-svn/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « source/libvpx/vp8/encoder/quantize.c ('k') | source/libvpx/vp8/encoder/rdopt.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 cc->filter_level = cpi->common.filter_level; 235 cc->filter_level = cpi->common.filter_level;
236 cc->frames_till_gf_update_due = cpi->frames_till_gf_update_due; 236 cc->frames_till_gf_update_due = cpi->frames_till_gf_update_due;
237 cc->frames_since_golden = cpi->common.frames_since_golden; 237 cc->frames_since_golden = cpi->common.frames_since_golden;
238 238
239 vp8_copy(cc->mvc, cpi->common.fc.mvc); 239 vp8_copy(cc->mvc, cpi->common.fc.mvc);
240 vp8_copy(cc->mvcosts, cpi->rd_costs.mvcosts); 240 vp8_copy(cc->mvcosts, cpi->rd_costs.mvcosts);
241 241
242 vp8_copy(cc->ymode_prob, cpi->common.fc.ymode_prob); 242 vp8_copy(cc->ymode_prob, cpi->common.fc.ymode_prob);
243 vp8_copy(cc->uv_mode_prob, cpi->common.fc.uv_mode_prob); 243 vp8_copy(cc->uv_mode_prob, cpi->common.fc.uv_mode_prob);
244 244
245 vp8_copy(cc->ymode_count, cpi->ymode_count); 245 vp8_copy(cc->ymode_count, cpi->mb.ymode_count);
246 vp8_copy(cc->uv_mode_count, cpi->uv_mode_count); 246 vp8_copy(cc->uv_mode_count, cpi->mb.uv_mode_count);
247 247
248 248
249 /* Stats */ 249 /* Stats */
250 #ifdef MODE_STATS 250 #ifdef MODE_STATS
251 vp8_copy(cc->y_modes, y_modes); 251 vp8_copy(cc->y_modes, y_modes);
252 vp8_copy(cc->uv_modes, uv_modes); 252 vp8_copy(cc->uv_modes, uv_modes);
253 vp8_copy(cc->b_modes, b_modes); 253 vp8_copy(cc->b_modes, b_modes);
254 vp8_copy(cc->inter_y_modes, inter_y_modes); 254 vp8_copy(cc->inter_y_modes, inter_y_modes);
255 vp8_copy(cc->inter_uv_modes, inter_uv_modes); 255 vp8_copy(cc->inter_uv_modes, inter_uv_modes);
256 vp8_copy(cc->inter_b_modes, inter_b_modes); 256 vp8_copy(cc->inter_b_modes, inter_b_modes);
(...skipping 16 matching lines...) Expand all
273 cpi->frames_till_gf_update_due = cc->frames_till_gf_update_due; 273 cpi->frames_till_gf_update_due = cc->frames_till_gf_update_due;
274 cpi->common.frames_since_golden = cc->frames_since_golden; 274 cpi->common.frames_since_golden = cc->frames_since_golden;
275 275
276 vp8_copy(cpi->common.fc.mvc, cc->mvc); 276 vp8_copy(cpi->common.fc.mvc, cc->mvc);
277 277
278 vp8_copy(cpi->rd_costs.mvcosts, cc->mvcosts); 278 vp8_copy(cpi->rd_costs.mvcosts, cc->mvcosts);
279 279
280 vp8_copy(cpi->common.fc.ymode_prob, cc->ymode_prob); 280 vp8_copy(cpi->common.fc.ymode_prob, cc->ymode_prob);
281 vp8_copy(cpi->common.fc.uv_mode_prob, cc->uv_mode_prob); 281 vp8_copy(cpi->common.fc.uv_mode_prob, cc->uv_mode_prob);
282 282
283 vp8_copy(cpi->ymode_count, cc->ymode_count); 283 vp8_copy(cpi->mb.ymode_count, cc->ymode_count);
284 vp8_copy(cpi->uv_mode_count, cc->uv_mode_count); 284 vp8_copy(cpi->mb.uv_mode_count, cc->uv_mode_count);
285 285
286 /* Stats */ 286 /* Stats */
287 #ifdef MODE_STATS 287 #ifdef MODE_STATS
288 vp8_copy(y_modes, cc->y_modes); 288 vp8_copy(y_modes, cc->y_modes);
289 vp8_copy(uv_modes, cc->uv_modes); 289 vp8_copy(uv_modes, cc->uv_modes);
290 vp8_copy(b_modes, cc->b_modes); 290 vp8_copy(b_modes, cc->b_modes);
291 vp8_copy(inter_y_modes, cc->inter_y_modes); 291 vp8_copy(inter_y_modes, cc->inter_y_modes);
292 vp8_copy(inter_uv_modes, cc->inter_uv_modes); 292 vp8_copy(inter_uv_modes, cc->inter_uv_modes);
293 vp8_copy(inter_b_modes, cc->inter_b_modes); 293 vp8_copy(inter_b_modes, cc->inter_b_modes);
294 #endif 294 #endif
(...skipping 807 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 1102
1103 /* Clear down mmx registers to allow floating point in what follows */ 1103 /* Clear down mmx registers to allow floating point in what follows */
1104 vp8_clear_system_state(); 1104 vp8_clear_system_state();
1105 1105
1106 if (cpi->common.frame_type == KEY_FRAME) 1106 if (cpi->common.frame_type == KEY_FRAME)
1107 { 1107 {
1108 rate_correction_factor = cpi->key_frame_rate_correction_factor; 1108 rate_correction_factor = cpi->key_frame_rate_correction_factor;
1109 } 1109 }
1110 else 1110 else
1111 { 1111 {
1112 if (cpi->common.refresh_alt_ref_frame || cpi->common.refresh_golden_fram e) 1112 if (cpi->oxcf.number_of_layers == 1 &&
1113 (cpi->common.refresh_alt_ref_frame ||
1114 cpi->common.refresh_golden_frame))
1113 rate_correction_factor = cpi->gf_rate_correction_factor; 1115 rate_correction_factor = cpi->gf_rate_correction_factor;
1114 else 1116 else
1115 rate_correction_factor = cpi->rate_correction_factor; 1117 rate_correction_factor = cpi->rate_correction_factor;
1116 } 1118 }
1117 1119
1118 /* Work out how big we would have expected the frame to be at this Q 1120 /* Work out how big we would have expected the frame to be at this Q
1119 * given the current correction factor. Stay in double to avoid int 1121 * given the current correction factor. Stay in double to avoid int
1120 * overflow when values are large 1122 * overflow when values are large
1121 */ 1123 */
1122 projected_size_based_on_q = (int)(((.5 + rate_correction_factor * vp8_bits_p er_mb[cpi->common.frame_type][Q]) * cpi->common.MBs) / (1 << BPER_MB_NORMBITS)); 1124 projected_size_based_on_q = (int)(((.5 + rate_correction_factor * vp8_bits_p er_mb[cpi->common.frame_type][Q]) * cpi->common.MBs) / (1 << BPER_MB_NORMBITS));
1123 1125
1124 /* Make some allowance for cpi->zbin_over_quant */ 1126 /* Make some allowance for cpi->zbin_over_quant */
1125 if (cpi->zbin_over_quant > 0) 1127 if (cpi->mb.zbin_over_quant > 0)
1126 { 1128 {
1127 int Z = cpi->zbin_over_quant; 1129 int Z = cpi->mb.zbin_over_quant;
1128 double Factor = 0.99; 1130 double Factor = 0.99;
1129 double factor_adjustment = 0.01 / 256.0; 1131 double factor_adjustment = 0.01 / 256.0;
1130 1132
1131 while (Z > 0) 1133 while (Z > 0)
1132 { 1134 {
1133 Z --; 1135 Z --;
1134 projected_size_based_on_q = 1136 projected_size_based_on_q =
1135 (int)(Factor * projected_size_based_on_q); 1137 (int)(Factor * projected_size_based_on_q);
1136 Factor += factor_adjustment; 1138 Factor += factor_adjustment;
1137 1139
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1179 1181
1180 /* Keep rate_correction_factor within limits */ 1182 /* Keep rate_correction_factor within limits */
1181 if (rate_correction_factor < MIN_BPB_FACTOR) 1183 if (rate_correction_factor < MIN_BPB_FACTOR)
1182 rate_correction_factor = MIN_BPB_FACTOR; 1184 rate_correction_factor = MIN_BPB_FACTOR;
1183 } 1185 }
1184 1186
1185 if (cpi->common.frame_type == KEY_FRAME) 1187 if (cpi->common.frame_type == KEY_FRAME)
1186 cpi->key_frame_rate_correction_factor = rate_correction_factor; 1188 cpi->key_frame_rate_correction_factor = rate_correction_factor;
1187 else 1189 else
1188 { 1190 {
1189 if (cpi->common.refresh_alt_ref_frame || cpi->common.refresh_golden_fram e) 1191 if (cpi->oxcf.number_of_layers == 1 &&
1192 (cpi->common.refresh_alt_ref_frame ||
1193 cpi->common.refresh_golden_frame))
1190 cpi->gf_rate_correction_factor = rate_correction_factor; 1194 cpi->gf_rate_correction_factor = rate_correction_factor;
1191 else 1195 else
1192 cpi->rate_correction_factor = rate_correction_factor; 1196 cpi->rate_correction_factor = rate_correction_factor;
1193 } 1197 }
1194 } 1198 }
1195 1199
1196 1200
1197 int vp8_regulate_q(VP8_COMP *cpi, int target_bits_per_frame) 1201 int vp8_regulate_q(VP8_COMP *cpi, int target_bits_per_frame)
1198 { 1202 {
1199 int Q = cpi->active_worst_quality; 1203 int Q = cpi->active_worst_quality;
1200 1204
1201 /* Reset Zbin OQ value */ 1205 /* Reset Zbin OQ value */
1202 cpi->zbin_over_quant = 0; 1206 cpi->mb.zbin_over_quant = 0;
1203 1207
1204 if (cpi->oxcf.fixed_q >= 0) 1208 if (cpi->oxcf.fixed_q >= 0)
1205 { 1209 {
1206 Q = cpi->oxcf.fixed_q; 1210 Q = cpi->oxcf.fixed_q;
1207 1211
1208 if (cpi->common.frame_type == KEY_FRAME) 1212 if (cpi->common.frame_type == KEY_FRAME)
1209 { 1213 {
1210 Q = cpi->oxcf.key_q; 1214 Q = cpi->oxcf.key_q;
1211 } 1215 }
1212 else if (cpi->common.refresh_alt_ref_frame) 1216 else if (cpi->oxcf.number_of_layers == 1 &&
1217 cpi->common.refresh_alt_ref_frame)
1213 { 1218 {
1214 Q = cpi->oxcf.alt_q; 1219 Q = cpi->oxcf.alt_q;
1215 } 1220 }
1216 else if (cpi->common.refresh_golden_frame) 1221 else if (cpi->oxcf.number_of_layers == 1 &&
1222 cpi->common.refresh_golden_frame)
1217 { 1223 {
1218 Q = cpi->oxcf.gold_q; 1224 Q = cpi->oxcf.gold_q;
1219 } 1225 }
1220 1226
1221 } 1227 }
1222 else 1228 else
1223 { 1229 {
1224 int i; 1230 int i;
1225 int last_error = INT_MAX; 1231 int last_error = INT_MAX;
1226 int target_bits_per_mb; 1232 int target_bits_per_mb;
1227 int bits_per_mb_at_this_q; 1233 int bits_per_mb_at_this_q;
1228 double correction_factor; 1234 double correction_factor;
1229 1235
1230 /* Select the appropriate correction factor based upon type of frame. */ 1236 /* Select the appropriate correction factor based upon type of frame. */
1231 if (cpi->common.frame_type == KEY_FRAME) 1237 if (cpi->common.frame_type == KEY_FRAME)
1232 correction_factor = cpi->key_frame_rate_correction_factor; 1238 correction_factor = cpi->key_frame_rate_correction_factor;
1233 else 1239 else
1234 { 1240 {
1235 if (cpi->common.refresh_alt_ref_frame || cpi->common.refresh_golden_ frame) 1241 if (cpi->oxcf.number_of_layers == 1 &&
1242 (cpi->common.refresh_alt_ref_frame ||
1243 cpi->common.refresh_golden_frame))
1236 correction_factor = cpi->gf_rate_correction_factor; 1244 correction_factor = cpi->gf_rate_correction_factor;
1237 else 1245 else
1238 correction_factor = cpi->rate_correction_factor; 1246 correction_factor = cpi->rate_correction_factor;
1239 } 1247 }
1240 1248
1241 /* Calculate required scaling factor based on target frame size and 1249 /* Calculate required scaling factor based on target frame size and
1242 * size of frame produced using previous Q 1250 * size of frame produced using previous Q
1243 */ 1251 */
1244 if (target_bits_per_frame >= (INT_MAX >> BPER_MB_NORMBITS)) 1252 if (target_bits_per_frame >= (INT_MAX >> BPER_MB_NORMBITS))
1245 /* Case where we would overflow int */ 1253 /* Case where we would overflow int */
(...skipping 28 matching lines...) Expand all
1274 */ 1282 */
1275 if (Q >= MAXQ) 1283 if (Q >= MAXQ)
1276 { 1284 {
1277 int zbin_oqmax; 1285 int zbin_oqmax;
1278 1286
1279 double Factor = 0.99; 1287 double Factor = 0.99;
1280 double factor_adjustment = 0.01 / 256.0; 1288 double factor_adjustment = 0.01 / 256.0;
1281 1289
1282 if (cpi->common.frame_type == KEY_FRAME) 1290 if (cpi->common.frame_type == KEY_FRAME)
1283 zbin_oqmax = 0; 1291 zbin_oqmax = 0;
1284 else if (cpi->common.refresh_alt_ref_frame || (cpi->common.refresh_g olden_frame && !cpi->source_alt_ref_active)) 1292 else if (cpi->oxcf.number_of_layers == 1 &&
1293 (cpi->common.refresh_alt_ref_frame ||
1294 (cpi->common.refresh_golden_frame &&
1295 !cpi->source_alt_ref_active)))
1285 zbin_oqmax = 16; 1296 zbin_oqmax = 16;
1286 else 1297 else
1287 zbin_oqmax = ZBIN_OQ_MAX; 1298 zbin_oqmax = ZBIN_OQ_MAX;
1288 1299
1289 /*{ 1300 /*{
1290 double Factor = (double)target_bits_per_mb/(double)bits_per_mb_a t_this_q; 1301 double Factor = (double)target_bits_per_mb/(double)bits_per_mb_a t_this_q;
1291 double Oq; 1302 double Oq;
1292 1303
1293 Factor = Factor/1.2683; 1304 Factor = Factor/1.2683;
1294 1305
1295 Oq = pow( Factor, (1.0/-0.165) ); 1306 Oq = pow( Factor, (1.0/-0.165) );
1296 1307
1297 if ( Oq > zbin_oqmax ) 1308 if ( Oq > zbin_oqmax )
1298 Oq = zbin_oqmax; 1309 Oq = zbin_oqmax;
1299 1310
1300 cpi->zbin_over_quant = (int)Oq; 1311 cpi->zbin_over_quant = (int)Oq;
1301 }*/ 1312 }*/
1302 1313
1303 /* Each incrment in the zbin is assumed to have a fixed effect 1314 /* Each incrment in the zbin is assumed to have a fixed effect
1304 * on bitrate. This is not of course true. The effect will be 1315 * on bitrate. This is not of course true. The effect will be
1305 * highly clip dependent and may well have sudden steps. The 1316 * highly clip dependent and may well have sudden steps. The
1306 * idea here is to acheive higher effective quantizers than the 1317 * idea here is to acheive higher effective quantizers than the
1307 * normal maximum by expanding the zero bin and hence 1318 * normal maximum by expanding the zero bin and hence
1308 * decreasing the number of low magnitude non zero coefficients. 1319 * decreasing the number of low magnitude non zero coefficients.
1309 */ 1320 */
1310 while (cpi->zbin_over_quant < zbin_oqmax) 1321 while (cpi->mb.zbin_over_quant < zbin_oqmax)
1311 { 1322 {
1312 cpi->zbin_over_quant ++; 1323 cpi->mb.zbin_over_quant ++;
1313 1324
1314 if (cpi->zbin_over_quant > zbin_oqmax) 1325 if (cpi->mb.zbin_over_quant > zbin_oqmax)
1315 cpi->zbin_over_quant = zbin_oqmax; 1326 cpi->mb.zbin_over_quant = zbin_oqmax;
1316 1327
1317 /* Adjust bits_per_mb_at_this_q estimate */ 1328 /* Adjust bits_per_mb_at_this_q estimate */
1318 bits_per_mb_at_this_q = (int)(Factor * bits_per_mb_at_this_q); 1329 bits_per_mb_at_this_q = (int)(Factor * bits_per_mb_at_this_q);
1319 Factor += factor_adjustment; 1330 Factor += factor_adjustment;
1320 1331
1321 if (Factor >= 0.999) 1332 if (Factor >= 0.999)
1322 Factor = 0.999; 1333 Factor = 0.999;
1323 1334
1324 /* Break out if we get down to the target rate */ 1335 /* Break out if we get down to the target rate */
1325 if (bits_per_mb_at_this_q <= target_bits_per_mb) 1336 if (bits_per_mb_at_this_q <= target_bits_per_mb)
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1525 1536
1526 /* Check if we're dropping the frame: */ 1537 /* Check if we're dropping the frame: */
1527 if (cpi->drop_frame) 1538 if (cpi->drop_frame)
1528 { 1539 {
1529 cpi->drop_frame = 0; 1540 cpi->drop_frame = 0;
1530 return 0; 1541 return 0;
1531 } 1542 }
1532 } 1543 }
1533 return 1; 1544 return 1;
1534 } 1545 }
OLDNEW
« no previous file with comments | « source/libvpx/vp8/encoder/quantize.c ('k') | source/libvpx/vp8/encoder/rdopt.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698