OLD | NEW |
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 378 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 } else { | 389 } else { |
390 if ((cpi->refresh_alt_ref_frame || cpi->refresh_golden_frame) && | 390 if ((cpi->refresh_alt_ref_frame || cpi->refresh_golden_frame) && |
391 !rc->is_src_frame_alt_ref && !cpi->use_svc && | 391 !rc->is_src_frame_alt_ref && !cpi->use_svc && |
392 (cpi->oxcf.rc_mode != VPX_CBR || cpi->oxcf.gf_cbr_boost_pct > 20)) | 392 (cpi->oxcf.rc_mode != VPX_CBR || cpi->oxcf.gf_cbr_boost_pct > 20)) |
393 rc->rate_correction_factors[GF_ARF_STD] = factor; | 393 rc->rate_correction_factors[GF_ARF_STD] = factor; |
394 else | 394 else |
395 rc->rate_correction_factors[INTER_NORMAL] = factor; | 395 rc->rate_correction_factors[INTER_NORMAL] = factor; |
396 } | 396 } |
397 } | 397 } |
398 | 398 |
399 void vp9_rc_update_rate_correction_factors(VP9_COMP *cpi) { | 399 void vp9_rc_update_rate_correction_factors(VP9_COMP *cpi, int damp_var) { |
400 const VP9_COMMON *const cm = &cpi->common; | 400 const VP9_COMMON *const cm = &cpi->common; |
401 int correction_factor = 100; | 401 int correction_factor = 100; |
402 double rate_correction_factor = get_rate_correction_factor(cpi); | 402 double rate_correction_factor = get_rate_correction_factor(cpi); |
403 double adjustment_limit; | 403 double adjustment_limit; |
404 | 404 |
405 int projected_size_based_on_q = 0; | 405 int projected_size_based_on_q = 0; |
406 | 406 |
407 // Do not update the rate factors for arf overlay frames. | 407 // Do not update the rate factors for arf overlay frames. |
408 if (cpi->rc.is_src_frame_alt_ref) | 408 if (cpi->rc.is_src_frame_alt_ref) |
409 return; | 409 return; |
(...skipping 14 matching lines...) Expand all Loading... |
424 rate_correction_factor, | 424 rate_correction_factor, |
425 cm->bit_depth); | 425 cm->bit_depth); |
426 } | 426 } |
427 // Work out a size correction factor. | 427 // Work out a size correction factor. |
428 if (projected_size_based_on_q > FRAME_OVERHEAD_BITS) | 428 if (projected_size_based_on_q > FRAME_OVERHEAD_BITS) |
429 correction_factor = (int)((100 * (int64_t)cpi->rc.projected_frame_size) / | 429 correction_factor = (int)((100 * (int64_t)cpi->rc.projected_frame_size) / |
430 projected_size_based_on_q); | 430 projected_size_based_on_q); |
431 | 431 |
432 // More heavily damped adjustment used if we have been oscillating either side | 432 // More heavily damped adjustment used if we have been oscillating either side |
433 // of target. | 433 // of target. |
434 adjustment_limit = 0.25 + | 434 switch (damp_var) { |
435 0.5 * MIN(1, fabs(log10(0.01 * correction_factor))); | 435 case 0: |
| 436 adjustment_limit = 0.75; |
| 437 break; |
| 438 case 1: |
| 439 adjustment_limit = 0.25 + |
| 440 0.5 * MIN(1, fabs(log10(0.01 * correction_factor))); |
| 441 break; |
| 442 case 2: |
| 443 default: |
| 444 adjustment_limit = 0.25; |
| 445 break; |
| 446 } |
436 | 447 |
437 cpi->rc.q_2_frame = cpi->rc.q_1_frame; | 448 cpi->rc.q_2_frame = cpi->rc.q_1_frame; |
438 cpi->rc.q_1_frame = cm->base_qindex; | 449 cpi->rc.q_1_frame = cm->base_qindex; |
439 cpi->rc.rc_2_frame = cpi->rc.rc_1_frame; | 450 cpi->rc.rc_2_frame = cpi->rc.rc_1_frame; |
440 if (correction_factor > 110) | 451 if (correction_factor > 110) |
441 cpi->rc.rc_1_frame = -1; | 452 cpi->rc.rc_1_frame = -1; |
442 else if (correction_factor < 90) | 453 else if (correction_factor < 90) |
443 cpi->rc.rc_1_frame = 1; | 454 cpi->rc.rc_1_frame = 1; |
444 else | 455 else |
445 cpi->rc.rc_1_frame = 0; | 456 cpi->rc.rc_1_frame = 0; |
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 const int qindex = cm->base_qindex; | 1215 const int qindex = cm->base_qindex; |
1205 | 1216 |
1206 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled) { | 1217 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled) { |
1207 vp9_cyclic_refresh_update_actual_count(cpi); | 1218 vp9_cyclic_refresh_update_actual_count(cpi); |
1208 } | 1219 } |
1209 | 1220 |
1210 // Update rate control heuristics | 1221 // Update rate control heuristics |
1211 rc->projected_frame_size = (int)(bytes_used << 3); | 1222 rc->projected_frame_size = (int)(bytes_used << 3); |
1212 | 1223 |
1213 // Post encode loop adjustment of Q prediction. | 1224 // Post encode loop adjustment of Q prediction. |
1214 vp9_rc_update_rate_correction_factors(cpi); | 1225 vp9_rc_update_rate_correction_factors( |
| 1226 cpi, (cpi->sf.recode_loop >= ALLOW_RECODE_KFARFGF) ? 2 : |
| 1227 ((oxcf->rc_mode == VPX_CBR) ? 1 : 0)); |
1215 | 1228 |
1216 // Keep a record of last Q and ambient average Q. | 1229 // Keep a record of last Q and ambient average Q. |
1217 if (cm->frame_type == KEY_FRAME) { | 1230 if (cm->frame_type == KEY_FRAME) { |
1218 rc->last_q[KEY_FRAME] = qindex; | 1231 rc->last_q[KEY_FRAME] = qindex; |
1219 rc->avg_frame_qindex[KEY_FRAME] = | 1232 rc->avg_frame_qindex[KEY_FRAME] = |
1220 ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[KEY_FRAME] + qindex, 2); | 1233 ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[KEY_FRAME] + qindex, 2); |
1221 } else { | 1234 } else { |
1222 if (rc->is_src_frame_alt_ref || | 1235 if (rc->is_src_frame_alt_ref || |
1223 !(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) || | 1236 !(cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) || |
1224 (cpi->use_svc && oxcf->rc_mode == VPX_CBR)) { | 1237 (cpi->use_svc && oxcf->rc_mode == VPX_CBR)) { |
1225 rc->last_q[INTER_FRAME] = qindex; | 1238 rc->last_q[INTER_FRAME] = qindex; |
1226 rc->avg_frame_qindex[INTER_FRAME] = | 1239 rc->avg_frame_qindex[INTER_FRAME] = |
1227 ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[INTER_FRAME] + qindex, 2); | 1240 ROUND_POWER_OF_TWO(3 * rc->avg_frame_qindex[INTER_FRAME] + qindex, 2); |
1228 rc->ni_frames++; | 1241 rc->ni_frames++; |
1229 rc->tot_q += vp9_convert_qindex_to_q(qindex, cm->bit_depth); | 1242 rc->tot_q += vp9_convert_qindex_to_q(qindex, cm->bit_depth); |
1230 rc->avg_q = rc->tot_q / rc->ni_frames; | 1243 rc->avg_q = rc->tot_q / rc->ni_frames; |
1231 // Calculate the average Q for normal inter frames (not key or GFU | 1244 // Calculate the average Q for normal inter frames (not key or GFU |
1232 // frames). | 1245 // frames). |
1233 rc->ni_tot_qi += qindex; | 1246 rc->ni_tot_qi += qindex; |
1234 rc->ni_av_qi = rc->ni_tot_qi / rc->ni_frames; | 1247 rc->ni_av_qi = rc->ni_tot_qi / rc->ni_frames; |
1235 } | 1248 } |
1236 } | 1249 } |
1237 | 1250 |
1238 // Keep record of last boosted (KF/KF/ARF) Q value. | 1251 // Keep record of last boosted (KF/KF/ARF) Q value. |
1239 // If the current frame is coded at a lower Q then we also update it. | 1252 // If the current frame is coded at a lower Q then we also update it. |
1240 // If all mbs in this group are skipped only update if the Q value is | 1253 // If all mbs in this group are skipped only update if the Q value is |
1241 // better than that already stored. | 1254 // better than that already stored. |
1242 // This is used to help set quality in forced key frames to reduce popping | 1255 // This is used to help set quality in forced key frames to reduce popping |
1243 if ((qindex < rc->last_boosted_qindex) || | 1256 if ((qindex < rc->last_boosted_qindex) || |
1244 (cm->frame_type == KEY_FRAME) || | 1257 (((cm->frame_type == KEY_FRAME) || cpi->refresh_alt_ref_frame || |
1245 (!rc->constrained_gf_group && | |
1246 (cpi->refresh_alt_ref_frame || | |
1247 (cpi->refresh_golden_frame && !rc->is_src_frame_alt_ref)))) { | 1258 (cpi->refresh_golden_frame && !rc->is_src_frame_alt_ref)))) { |
1248 rc->last_boosted_qindex = qindex; | 1259 rc->last_boosted_qindex = qindex; |
1249 } | 1260 } |
1250 if (cm->frame_type == KEY_FRAME) | 1261 if (cm->frame_type == KEY_FRAME) |
1251 rc->last_kf_qindex = qindex; | 1262 rc->last_kf_qindex = qindex; |
1252 | 1263 |
1253 update_buffer_level(cpi, rc->projected_frame_size); | 1264 update_buffer_level(cpi, rc->projected_frame_size); |
1254 | 1265 |
1255 // Rolling monitors of whether we are over or underspending used to help | 1266 // Rolling monitors of whether we are over or underspending used to help |
1256 // regulate min and Max Q in two pass. | 1267 // regulate min and Max Q in two pass. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1340 rc->frames_to_key = cpi->oxcf.key_freq; | 1351 rc->frames_to_key = cpi->oxcf.key_freq; |
1341 rc->kf_boost = DEFAULT_KF_BOOST; | 1352 rc->kf_boost = DEFAULT_KF_BOOST; |
1342 rc->source_alt_ref_active = 0; | 1353 rc->source_alt_ref_active = 0; |
1343 } else { | 1354 } else { |
1344 cm->frame_type = INTER_FRAME; | 1355 cm->frame_type = INTER_FRAME; |
1345 } | 1356 } |
1346 if (rc->frames_till_gf_update_due == 0) { | 1357 if (rc->frames_till_gf_update_due == 0) { |
1347 rc->baseline_gf_interval = DEFAULT_GF_INTERVAL; | 1358 rc->baseline_gf_interval = DEFAULT_GF_INTERVAL; |
1348 rc->frames_till_gf_update_due = rc->baseline_gf_interval; | 1359 rc->frames_till_gf_update_due = rc->baseline_gf_interval; |
1349 // NOTE: frames_till_gf_update_due must be <= frames_to_key. | 1360 // NOTE: frames_till_gf_update_due must be <= frames_to_key. |
1350 if (rc->frames_till_gf_update_due > rc->frames_to_key) { | 1361 if (rc->frames_till_gf_update_due > rc->frames_to_key) |
1351 rc->frames_till_gf_update_due = rc->frames_to_key; | 1362 rc->frames_till_gf_update_due = rc->frames_to_key; |
1352 rc->constrained_gf_group = 1; | |
1353 } else { | |
1354 rc->constrained_gf_group = 0; | |
1355 } | |
1356 cpi->refresh_golden_frame = 1; | 1363 cpi->refresh_golden_frame = 1; |
1357 rc->source_alt_ref_pending = USE_ALTREF_FOR_ONE_PASS; | 1364 rc->source_alt_ref_pending = USE_ALTREF_FOR_ONE_PASS; |
1358 rc->gfu_boost = DEFAULT_GF_BOOST; | 1365 rc->gfu_boost = DEFAULT_GF_BOOST; |
1359 } | 1366 } |
1360 if (cm->frame_type == KEY_FRAME) | 1367 if (cm->frame_type == KEY_FRAME) |
1361 target = calc_iframe_target_size_one_pass_vbr(cpi); | 1368 target = calc_iframe_target_size_one_pass_vbr(cpi); |
1362 else | 1369 else |
1363 target = calc_pframe_target_size_one_pass_vbr(cpi); | 1370 target = calc_pframe_target_size_one_pass_vbr(cpi); |
1364 vp9_rc_set_frame_target(cpi, target); | 1371 vp9_rc_set_frame_target(cpi, target); |
1365 } | 1372 } |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1651 | 1658 |
1652 void vp9_set_target_rate(VP9_COMP *cpi) { | 1659 void vp9_set_target_rate(VP9_COMP *cpi) { |
1653 RATE_CONTROL *const rc = &cpi->rc; | 1660 RATE_CONTROL *const rc = &cpi->rc; |
1654 int target_rate = rc->base_frame_target; | 1661 int target_rate = rc->base_frame_target; |
1655 | 1662 |
1656 // Correction to rate target based on prior over or under shoot. | 1663 // Correction to rate target based on prior over or under shoot. |
1657 if (cpi->oxcf.rc_mode == VPX_VBR) | 1664 if (cpi->oxcf.rc_mode == VPX_VBR) |
1658 vbr_rate_correction(cpi, &target_rate, rc->vbr_bits_off_target); | 1665 vbr_rate_correction(cpi, &target_rate, rc->vbr_bits_off_target); |
1659 vp9_rc_set_frame_target(cpi, target_rate); | 1666 vp9_rc_set_frame_target(cpi, target_rate); |
1660 } | 1667 } |
OLD | NEW |