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