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

Side by Side Diff: source/libvpx/vp9/encoder/vp9_firstpass.c

Issue 484923003: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 4 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/vp9/encoder/vp9_encoder.c ('k') | source/libvpx/vp9/encoder/vp9_pickmode.c » ('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 414 matching lines...) Expand 10 before | Expand all | Expand 10 after
425 int intercount = 0; 425 int intercount = 0;
426 int second_ref_count = 0; 426 int second_ref_count = 0;
427 int intrapenalty = 256; 427 int intrapenalty = 256;
428 int neutral_count = 0; 428 int neutral_count = 0;
429 int new_mv_count = 0; 429 int new_mv_count = 0;
430 int sum_in_vectors = 0; 430 int sum_in_vectors = 0;
431 uint32_t lastmv_as_int = 0; 431 uint32_t lastmv_as_int = 0;
432 TWO_PASS *twopass = &cpi->twopass; 432 TWO_PASS *twopass = &cpi->twopass;
433 const MV zero_mv = {0, 0}; 433 const MV zero_mv = {0, 0};
434 const YV12_BUFFER_CONFIG *first_ref_buf = lst_yv12; 434 const YV12_BUFFER_CONFIG *first_ref_buf = lst_yv12;
435 LAYER_CONTEXT *const lc = is_spatial_svc(cpi) ?
436 &cpi->svc.layer_context[cpi->svc.spatial_layer_id] : 0;
435 437
436 #if CONFIG_FP_MB_STATS 438 #if CONFIG_FP_MB_STATS
437 if (cpi->use_fp_mb_stats) { 439 if (cpi->use_fp_mb_stats) {
438 vp9_zero_array(cpi->twopass.frame_mb_stats_buf, cm->MBs); 440 vp9_zero_array(cpi->twopass.frame_mb_stats_buf, cm->MBs);
439 } 441 }
440 #endif 442 #endif
441 443
442 vp9_clear_system_state(); 444 vp9_clear_system_state();
443 445
444 set_first_pass_params(cpi); 446 set_first_pass_params(cpi);
445 vp9_set_quantizer(cm, find_fp_qindex()); 447 vp9_set_quantizer(cm, find_fp_qindex());
446 448
447 if (is_spatial_svc(cpi)) { 449 if (lc != NULL) {
448 MV_REFERENCE_FRAME ref_frame = LAST_FRAME; 450 MV_REFERENCE_FRAME ref_frame = LAST_FRAME;
449 const YV12_BUFFER_CONFIG *scaled_ref_buf = NULL; 451 const YV12_BUFFER_CONFIG *scaled_ref_buf = NULL;
450 twopass = &cpi->svc.layer_context[cpi->svc.spatial_layer_id].twopass; 452 twopass = &lc->twopass;
451 453
452 if (cpi->common.current_video_frame == 0) { 454 if (cpi->common.current_video_frame == 0) {
453 cpi->ref_frame_flags = 0; 455 cpi->ref_frame_flags = 0;
454 } else { 456 } else {
455 LAYER_CONTEXT *lc = &cpi->svc.layer_context[cpi->svc.spatial_layer_id];
456 if (lc->current_video_frame_in_layer == 0) 457 if (lc->current_video_frame_in_layer == 0)
457 cpi->ref_frame_flags = VP9_GOLD_FLAG; 458 cpi->ref_frame_flags = VP9_GOLD_FLAG;
458 else 459 else
459 cpi->ref_frame_flags = VP9_LAST_FLAG | VP9_GOLD_FLAG; 460 cpi->ref_frame_flags = VP9_LAST_FLAG | VP9_GOLD_FLAG;
460 } 461 }
461 462
462 vp9_scale_references(cpi); 463 vp9_scale_references(cpi);
463 464
464 // Use either last frame or alt frame for motion search. 465 // Use either last frame or alt frame for motion search.
465 if (cpi->ref_frame_flags & VP9_LAST_FLAG) { 466 if (cpi->ref_frame_flags & VP9_LAST_FLAG) {
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
606 // frame as the reference. Skip the further motion search on 607 // frame as the reference. Skip the further motion search on
607 // reconstructed frame if this error is small. 608 // reconstructed frame if this error is small.
608 unscaled_last_source_buf_2d.buf = 609 unscaled_last_source_buf_2d.buf =
609 cpi->unscaled_last_source->y_buffer + recon_yoffset; 610 cpi->unscaled_last_source->y_buffer + recon_yoffset;
610 unscaled_last_source_buf_2d.stride = 611 unscaled_last_source_buf_2d.stride =
611 cpi->unscaled_last_source->y_stride; 612 cpi->unscaled_last_source->y_stride;
612 raw_motion_error = get_prediction_error(bsize, &x->plane[0].src, 613 raw_motion_error = get_prediction_error(bsize, &x->plane[0].src,
613 &unscaled_last_source_buf_2d); 614 &unscaled_last_source_buf_2d);
614 615
615 // TODO(pengchong): Replace the hard-coded threshold 616 // TODO(pengchong): Replace the hard-coded threshold
616 if (raw_motion_error > 25 || is_spatial_svc(cpi)) { 617 if (raw_motion_error > 25 || lc != NULL) {
617 // Test last reference frame using the previous best mv as the 618 // Test last reference frame using the previous best mv as the
618 // starting point (best reference) for the search. 619 // starting point (best reference) for the search.
619 first_pass_motion_search(cpi, x, &best_ref_mv.as_mv, &mv.as_mv, 620 first_pass_motion_search(cpi, x, &best_ref_mv.as_mv, &mv.as_mv,
620 &motion_error); 621 &motion_error);
621 if (cpi->oxcf.aq_mode == VARIANCE_AQ) { 622 if (cpi->oxcf.aq_mode == VARIANCE_AQ) {
622 vp9_clear_system_state(); 623 vp9_clear_system_state();
623 motion_error = (int)(motion_error * error_weight); 624 motion_error = (int)(motion_error * error_weight);
624 } 625 }
625 626
626 // If the current best reference mv is not centered on 0,0 then do a 627 // If the current best reference mv is not centered on 0,0 then do a
(...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 if (gld_yv12 != NULL) { 889 if (gld_yv12 != NULL) {
889 vp8_yv12_copy_frame(lst_yv12, gld_yv12); 890 vp8_yv12_copy_frame(lst_yv12, gld_yv12);
890 } 891 }
891 twopass->sr_update_lag = 1; 892 twopass->sr_update_lag = 1;
892 } else { 893 } else {
893 ++twopass->sr_update_lag; 894 ++twopass->sr_update_lag;
894 } 895 }
895 896
896 vp9_extend_frame_borders(new_yv12); 897 vp9_extend_frame_borders(new_yv12);
897 898
898 if (is_spatial_svc(cpi)) { 899 if (lc != NULL) {
899 vp9_update_reference_frames(cpi); 900 vp9_update_reference_frames(cpi);
900 } else { 901 } else {
901 // Swap frame pointers so last frame refers to the frame we just compressed. 902 // Swap frame pointers so last frame refers to the frame we just compressed.
902 swap_yv12(lst_yv12, new_yv12); 903 swap_yv12(lst_yv12, new_yv12);
903 } 904 }
904 905
905 // Special case for the first frame. Copy into the GF buffer as a second 906 // Special case for the first frame. Copy into the GF buffer as a second
906 // reference. 907 // reference.
907 if (cm->current_video_frame == 0 && gld_yv12 != NULL) { 908 if (cm->current_video_frame == 0 && gld_yv12 != NULL) {
908 vp8_yv12_copy_frame(lst_yv12, gld_yv12); 909 vp8_yv12_copy_frame(lst_yv12, gld_yv12);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
1074 next_frame->coded_error) / cm->MBs; 1075 next_frame->coded_error) / cm->MBs;
1075 const double second_ref_decay = mb_sr_err_diff <= 512.0 1076 const double second_ref_decay = mb_sr_err_diff <= 512.0
1076 ? fclamp(pow(1.0 - (mb_sr_err_diff / 512.0), 0.5), 0.85, 1.0) 1077 ? fclamp(pow(1.0 - (mb_sr_err_diff / 512.0), 0.5), 0.85, 1.0)
1077 : 0.85; 1078 : 0.85;
1078 1079
1079 return MIN(second_ref_decay, next_frame->pcnt_inter); 1080 return MIN(second_ref_decay, next_frame->pcnt_inter);
1080 } 1081 }
1081 1082
1082 // This function gives an estimate of how badly we believe the prediction 1083 // This function gives an estimate of how badly we believe the prediction
1083 // quality is decaying from frame to frame. 1084 // quality is decaying from frame to frame.
1084 static double get_zero_motion_factor(const VP9_COMMON *cm, 1085 static double get_zero_motion_factor(const FIRSTPASS_STATS *frame) {
1085 const FIRSTPASS_STATS *frame) {
1086 const double sr_ratio = frame->coded_error / 1086 const double sr_ratio = frame->coded_error /
1087 DOUBLE_DIVIDE_CHECK(frame->sr_coded_error); 1087 DOUBLE_DIVIDE_CHECK(frame->sr_coded_error);
1088 const double zero_motion_pct = frame->pcnt_inter - 1088 const double zero_motion_pct = frame->pcnt_inter -
1089 frame->pcnt_motion; 1089 frame->pcnt_motion;
1090 1090
1091 return MIN(sr_ratio, zero_motion_pct); 1091 return MIN(sr_ratio, zero_motion_pct);
1092 } 1092 }
1093 1093
1094 1094
1095 // Function to test for a condition where a complex transition is followed 1095 // Function to test for a condition where a complex transition is followed
1096 // by a static section. For example in slide shows where there is a fade 1096 // by a static section. For example in slide shows where there is a fade
1097 // between slides. This is to help with more optimal kf and gf positioning. 1097 // between slides. This is to help with more optimal kf and gf positioning.
1098 static int detect_transition_to_still(TWO_PASS *twopass, 1098 static int detect_transition_to_still(const TWO_PASS *twopass,
1099 int frame_interval, int still_interval, 1099 int frame_interval, int still_interval,
1100 double loop_decay_rate, 1100 double loop_decay_rate,
1101 double last_decay_rate) { 1101 double last_decay_rate) {
1102 int trans_to_still = 0;
1103
1104 // Break clause to detect very still sections after motion 1102 // Break clause to detect very still sections after motion
1105 // For example a static image after a fade or other transition 1103 // For example a static image after a fade or other transition
1106 // instead of a clean scene cut. 1104 // instead of a clean scene cut.
1107 if (frame_interval > MIN_GF_INTERVAL && 1105 if (frame_interval > MIN_GF_INTERVAL &&
1108 loop_decay_rate >= 0.999 && 1106 loop_decay_rate >= 0.999 &&
1109 last_decay_rate < 0.9) { 1107 last_decay_rate < 0.9) {
1110 int j; 1108 int j;
1111 const FIRSTPASS_STATS *position = twopass->stats_in;
1112 FIRSTPASS_STATS tmp_next_frame;
1113 1109
1114 // Look ahead a few frames to see if static condition persists... 1110 // Look ahead a few frames to see if static condition persists...
1115 for (j = 0; j < still_interval; ++j) { 1111 for (j = 0; j < still_interval; ++j) {
1116 if (EOF == input_stats(twopass, &tmp_next_frame)) 1112 const FIRSTPASS_STATS *stats = &twopass->stats_in[j];
1113 if (stats >= twopass->stats_in_end)
1117 break; 1114 break;
1118 1115
1119 if (tmp_next_frame.pcnt_inter - tmp_next_frame.pcnt_motion < 0.999) 1116 if (stats->pcnt_inter - stats->pcnt_motion < 0.999)
1120 break; 1117 break;
1121 } 1118 }
1122 1119
1123 reset_fpf_position(twopass, position);
1124
1125 // Only if it does do we signal a transition to still. 1120 // Only if it does do we signal a transition to still.
1126 if (j == still_interval) 1121 return j == still_interval;
1127 trans_to_still = 1;
1128 } 1122 }
1129 1123
1130 return trans_to_still; 1124 return 0;
1131 } 1125 }
1132 1126
1133 // This function detects a flash through the high relative pcnt_second_ref 1127 // This function detects a flash through the high relative pcnt_second_ref
1134 // score in the frame following a flash frame. The offset passed in should 1128 // score in the frame following a flash frame. The offset passed in should
1135 // reflect this. 1129 // reflect this.
1136 static int detect_flash(const TWO_PASS *twopass, int offset) { 1130 static int detect_flash(const TWO_PASS *twopass, int offset) {
1137 const FIRSTPASS_STATS *const next_frame = read_frame_stats(twopass, offset); 1131 const FIRSTPASS_STATS *const next_frame = read_frame_stats(twopass, offset);
1138 1132
1139 // What we are looking for here is a situation where there is a 1133 // What we are looking for here is a situation where there is a
1140 // brief break in prediction (such as a flash) but subsequent frames 1134 // brief break in prediction (such as a flash) but subsequent frames
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1366 // the integration process with other codec features that swap buffers around. 1360 // the integration process with other codec features that swap buffers around.
1367 static void get_arf_buffer_indices(unsigned char *arf_buffer_indices) { 1361 static void get_arf_buffer_indices(unsigned char *arf_buffer_indices) {
1368 arf_buffer_indices[0] = ARF_SLOT1; 1362 arf_buffer_indices[0] = ARF_SLOT1;
1369 arf_buffer_indices[1] = ARF_SLOT2; 1363 arf_buffer_indices[1] = ARF_SLOT2;
1370 } 1364 }
1371 1365
1372 static void allocate_gf_group_bits(VP9_COMP *cpi, int64_t gf_group_bits, 1366 static void allocate_gf_group_bits(VP9_COMP *cpi, int64_t gf_group_bits,
1373 double group_error, int gf_arf_bits) { 1367 double group_error, int gf_arf_bits) {
1374 RATE_CONTROL *const rc = &cpi->rc; 1368 RATE_CONTROL *const rc = &cpi->rc;
1375 const VP9EncoderConfig *const oxcf = &cpi->oxcf; 1369 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
1376 TWO_PASS *twopass = &cpi->twopass; 1370 TWO_PASS *const twopass = &cpi->twopass;
1371 GF_GROUP *const gf_group = &twopass->gf_group;
1377 FIRSTPASS_STATS frame_stats; 1372 FIRSTPASS_STATS frame_stats;
1378 int i; 1373 int i;
1379 int frame_index = 1; 1374 int frame_index = 1;
1380 int target_frame_size; 1375 int target_frame_size;
1381 int key_frame; 1376 int key_frame;
1382 const int max_bits = frame_max_bits(&cpi->rc, &cpi->oxcf); 1377 const int max_bits = frame_max_bits(&cpi->rc, &cpi->oxcf);
1383 int64_t total_group_bits = gf_group_bits; 1378 int64_t total_group_bits = gf_group_bits;
1384 double modified_err = 0.0; 1379 double modified_err = 0.0;
1385 double err_fraction; 1380 double err_fraction;
1386 int mid_boost_bits = 0; 1381 int mid_boost_bits = 0;
1387 int mid_frame_idx; 1382 int mid_frame_idx;
1388 unsigned char arf_buffer_indices[MAX_ACTIVE_ARFS]; 1383 unsigned char arf_buffer_indices[MAX_ACTIVE_ARFS];
1389 1384
1390 key_frame = cpi->common.frame_type == KEY_FRAME || 1385 key_frame = cpi->common.frame_type == KEY_FRAME ||
1391 vp9_is_upper_layer_key_frame(cpi); 1386 vp9_is_upper_layer_key_frame(cpi);
1392 1387
1393 get_arf_buffer_indices(arf_buffer_indices); 1388 get_arf_buffer_indices(arf_buffer_indices);
1394 1389
1395 // For key frames the frame target rate is already set and it 1390 // For key frames the frame target rate is already set and it
1396 // is also the golden frame. 1391 // is also the golden frame.
1397 if (!key_frame) { 1392 if (!key_frame) {
1398 if (rc->source_alt_ref_active) { 1393 if (rc->source_alt_ref_active) {
1399 twopass->gf_group.update_type[0] = OVERLAY_UPDATE; 1394 gf_group->update_type[0] = OVERLAY_UPDATE;
1400 twopass->gf_group.rf_level[0] = INTER_NORMAL; 1395 gf_group->rf_level[0] = INTER_NORMAL;
1401 twopass->gf_group.bit_allocation[0] = 0; 1396 gf_group->bit_allocation[0] = 0;
1402 twopass->gf_group.arf_update_idx[0] = arf_buffer_indices[0]; 1397 gf_group->arf_update_idx[0] = arf_buffer_indices[0];
1403 twopass->gf_group.arf_ref_idx[0] = arf_buffer_indices[0]; 1398 gf_group->arf_ref_idx[0] = arf_buffer_indices[0];
1404 } else { 1399 } else {
1405 twopass->gf_group.update_type[0] = GF_UPDATE; 1400 gf_group->update_type[0] = GF_UPDATE;
1406 twopass->gf_group.rf_level[0] = GF_ARF_STD; 1401 gf_group->rf_level[0] = GF_ARF_STD;
1407 twopass->gf_group.bit_allocation[0] = gf_arf_bits; 1402 gf_group->bit_allocation[0] = gf_arf_bits;
1408 twopass->gf_group.arf_update_idx[0] = arf_buffer_indices[0]; 1403 gf_group->arf_update_idx[0] = arf_buffer_indices[0];
1409 twopass->gf_group.arf_ref_idx[0] = arf_buffer_indices[0]; 1404 gf_group->arf_ref_idx[0] = arf_buffer_indices[0];
1410 } 1405 }
1411 1406
1412 // Step over the golden frame / overlay frame 1407 // Step over the golden frame / overlay frame
1413 if (EOF == input_stats(twopass, &frame_stats)) 1408 if (EOF == input_stats(twopass, &frame_stats))
1414 return; 1409 return;
1415 } 1410 }
1416 1411
1417 // Deduct the boost bits for arf (or gf if it is not a key frame) 1412 // Deduct the boost bits for arf (or gf if it is not a key frame)
1418 // from the group total. 1413 // from the group total.
1419 if (rc->source_alt_ref_pending || !key_frame) 1414 if (rc->source_alt_ref_pending || !key_frame)
1420 total_group_bits -= gf_arf_bits; 1415 total_group_bits -= gf_arf_bits;
1421 1416
1422 // Store the bits to spend on the ARF if there is one. 1417 // Store the bits to spend on the ARF if there is one.
1423 if (rc->source_alt_ref_pending) { 1418 if (rc->source_alt_ref_pending) {
1424 twopass->gf_group.update_type[frame_index] = ARF_UPDATE; 1419 gf_group->update_type[frame_index] = ARF_UPDATE;
1425 twopass->gf_group.rf_level[frame_index] = GF_ARF_STD; 1420 gf_group->rf_level[frame_index] = GF_ARF_STD;
1426 twopass->gf_group.bit_allocation[frame_index] = gf_arf_bits; 1421 gf_group->bit_allocation[frame_index] = gf_arf_bits;
1427 twopass->gf_group.arf_src_offset[frame_index] = 1422 gf_group->arf_src_offset[frame_index] =
1428 (unsigned char)(rc->baseline_gf_interval - 1); 1423 (unsigned char)(rc->baseline_gf_interval - 1);
1429 twopass->gf_group.arf_update_idx[frame_index] = arf_buffer_indices[0]; 1424 gf_group->arf_update_idx[frame_index] = arf_buffer_indices[0];
1430 twopass->gf_group.arf_ref_idx[frame_index] = 1425 gf_group->arf_ref_idx[frame_index] =
1431 arf_buffer_indices[cpi->multi_arf_last_grp_enabled && 1426 arf_buffer_indices[cpi->multi_arf_last_grp_enabled &&
1432 rc->source_alt_ref_active]; 1427 rc->source_alt_ref_active];
1433 ++frame_index; 1428 ++frame_index;
1434 1429
1435 if (cpi->multi_arf_enabled) { 1430 if (cpi->multi_arf_enabled) {
1436 // Set aside a slot for a level 1 arf. 1431 // Set aside a slot for a level 1 arf.
1437 twopass->gf_group.update_type[frame_index] = ARF_UPDATE; 1432 gf_group->update_type[frame_index] = ARF_UPDATE;
1438 twopass->gf_group.rf_level[frame_index] = GF_ARF_LOW; 1433 gf_group->rf_level[frame_index] = GF_ARF_LOW;
1439 twopass->gf_group.arf_src_offset[frame_index] = 1434 gf_group->arf_src_offset[frame_index] =
1440 (unsigned char)((rc->baseline_gf_interval >> 1) - 1); 1435 (unsigned char)((rc->baseline_gf_interval >> 1) - 1);
1441 twopass->gf_group.arf_update_idx[frame_index] = arf_buffer_indices[1]; 1436 gf_group->arf_update_idx[frame_index] = arf_buffer_indices[1];
1442 twopass->gf_group.arf_ref_idx[frame_index] = arf_buffer_indices[0]; 1437 gf_group->arf_ref_idx[frame_index] = arf_buffer_indices[0];
1443 ++frame_index; 1438 ++frame_index;
1444 } 1439 }
1445 } 1440 }
1446 1441
1447 // Define middle frame 1442 // Define middle frame
1448 mid_frame_idx = frame_index + (rc->baseline_gf_interval >> 1) - 1; 1443 mid_frame_idx = frame_index + (rc->baseline_gf_interval >> 1) - 1;
1449 1444
1450 // Allocate bits to the other frames in the group. 1445 // Allocate bits to the other frames in the group.
1451 for (i = 0; i < rc->baseline_gf_interval - 1; ++i) { 1446 for (i = 0; i < rc->baseline_gf_interval - 1; ++i) {
1452 int arf_idx = 0; 1447 int arf_idx = 0;
1453 if (EOF == input_stats(twopass, &frame_stats)) 1448 if (EOF == input_stats(twopass, &frame_stats))
1454 break; 1449 break;
1455 1450
1456 modified_err = calculate_modified_err(twopass, oxcf, &frame_stats); 1451 modified_err = calculate_modified_err(twopass, oxcf, &frame_stats);
1457 1452
1458 if (group_error > 0) 1453 if (group_error > 0)
1459 err_fraction = modified_err / DOUBLE_DIVIDE_CHECK(group_error); 1454 err_fraction = modified_err / DOUBLE_DIVIDE_CHECK(group_error);
1460 else 1455 else
1461 err_fraction = 0.0; 1456 err_fraction = 0.0;
1462 1457
1463 target_frame_size = (int)((double)total_group_bits * err_fraction); 1458 target_frame_size = (int)((double)total_group_bits * err_fraction);
1464 1459
1465 if (rc->source_alt_ref_pending && cpi->multi_arf_enabled) { 1460 if (rc->source_alt_ref_pending && cpi->multi_arf_enabled) {
1466 mid_boost_bits += (target_frame_size >> 4); 1461 mid_boost_bits += (target_frame_size >> 4);
1467 target_frame_size -= (target_frame_size >> 4); 1462 target_frame_size -= (target_frame_size >> 4);
1468 1463
1469 if (frame_index <= mid_frame_idx) 1464 if (frame_index <= mid_frame_idx)
1470 arf_idx = 1; 1465 arf_idx = 1;
1471 } 1466 }
1472 twopass->gf_group.arf_update_idx[frame_index] = arf_buffer_indices[arf_idx]; 1467 gf_group->arf_update_idx[frame_index] = arf_buffer_indices[arf_idx];
1473 twopass->gf_group.arf_ref_idx[frame_index] = arf_buffer_indices[arf_idx]; 1468 gf_group->arf_ref_idx[frame_index] = arf_buffer_indices[arf_idx];
1474 1469
1475 target_frame_size = clamp(target_frame_size, 0, 1470 target_frame_size = clamp(target_frame_size, 0,
1476 MIN(max_bits, (int)total_group_bits)); 1471 MIN(max_bits, (int)total_group_bits));
1477 1472
1478 twopass->gf_group.update_type[frame_index] = LF_UPDATE; 1473 gf_group->update_type[frame_index] = LF_UPDATE;
1479 twopass->gf_group.rf_level[frame_index] = INTER_NORMAL; 1474 gf_group->rf_level[frame_index] = INTER_NORMAL;
1480 1475
1481 twopass->gf_group.bit_allocation[frame_index] = target_frame_size; 1476 gf_group->bit_allocation[frame_index] = target_frame_size;
1482 ++frame_index; 1477 ++frame_index;
1483 } 1478 }
1484 1479
1485 // Note: 1480 // Note:
1486 // We need to configure the frame at the end of the sequence + 1 that will be 1481 // We need to configure the frame at the end of the sequence + 1 that will be
1487 // the start frame for the next group. Otherwise prior to the call to 1482 // the start frame for the next group. Otherwise prior to the call to
1488 // vp9_rc_get_second_pass_params() the data will be undefined. 1483 // vp9_rc_get_second_pass_params() the data will be undefined.
1489 twopass->gf_group.arf_update_idx[frame_index] = arf_buffer_indices[0]; 1484 gf_group->arf_update_idx[frame_index] = arf_buffer_indices[0];
1490 twopass->gf_group.arf_ref_idx[frame_index] = arf_buffer_indices[0]; 1485 gf_group->arf_ref_idx[frame_index] = arf_buffer_indices[0];
1491 1486
1492 if (rc->source_alt_ref_pending) { 1487 if (rc->source_alt_ref_pending) {
1493 twopass->gf_group.update_type[frame_index] = OVERLAY_UPDATE; 1488 gf_group->update_type[frame_index] = OVERLAY_UPDATE;
1494 twopass->gf_group.rf_level[frame_index] = INTER_NORMAL; 1489 gf_group->rf_level[frame_index] = INTER_NORMAL;
1495 1490
1496 // Final setup for second arf and its overlay. 1491 // Final setup for second arf and its overlay.
1497 if (cpi->multi_arf_enabled) { 1492 if (cpi->multi_arf_enabled) {
1498 twopass->gf_group.bit_allocation[2] = 1493 gf_group->bit_allocation[2] =
1499 twopass->gf_group.bit_allocation[mid_frame_idx] + mid_boost_bits; 1494 gf_group->bit_allocation[mid_frame_idx] + mid_boost_bits;
1500 twopass->gf_group.update_type[mid_frame_idx] = OVERLAY_UPDATE; 1495 gf_group->update_type[mid_frame_idx] = OVERLAY_UPDATE;
1501 twopass->gf_group.bit_allocation[mid_frame_idx] = 0; 1496 gf_group->bit_allocation[mid_frame_idx] = 0;
1502 } 1497 }
1503 } else { 1498 } else {
1504 twopass->gf_group.update_type[frame_index] = GF_UPDATE; 1499 gf_group->update_type[frame_index] = GF_UPDATE;
1505 twopass->gf_group.rf_level[frame_index] = GF_ARF_STD; 1500 gf_group->rf_level[frame_index] = GF_ARF_STD;
1506 } 1501 }
1507 1502
1508 // Note whether multi-arf was enabled this group for next time. 1503 // Note whether multi-arf was enabled this group for next time.
1509 cpi->multi_arf_last_grp_enabled = cpi->multi_arf_enabled; 1504 cpi->multi_arf_last_grp_enabled = cpi->multi_arf_enabled;
1510 } 1505 }
1511 1506
1512 // Analyse and define a gf/arf group. 1507 // Analyse and define a gf/arf group.
1513 static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { 1508 static void define_gf_group(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
1514 RATE_CONTROL *const rc = &cpi->rc; 1509 RATE_CONTROL *const rc = &cpi->rc;
1515 const VP9EncoderConfig *const oxcf = &cpi->oxcf; 1510 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
1547 1542
1548 // Reset the GF group data structures unless this is a key 1543 // Reset the GF group data structures unless this is a key
1549 // frame in which case it will already have been done. 1544 // frame in which case it will already have been done.
1550 if (cpi->common.frame_type != KEY_FRAME) { 1545 if (cpi->common.frame_type != KEY_FRAME) {
1551 vp9_zero(twopass->gf_group); 1546 vp9_zero(twopass->gf_group);
1552 } 1547 }
1553 1548
1554 vp9_clear_system_state(); 1549 vp9_clear_system_state();
1555 vp9_zero(next_frame); 1550 vp9_zero(next_frame);
1556 1551
1557 gf_group_bits = 0;
1558
1559 // Load stats for the current frame. 1552 // Load stats for the current frame.
1560 mod_frame_err = calculate_modified_err(twopass, oxcf, this_frame); 1553 mod_frame_err = calculate_modified_err(twopass, oxcf, this_frame);
1561 1554
1562 // Note the error of the frame at the start of the group. This will be 1555 // Note the error of the frame at the start of the group. This will be
1563 // the GF frame error if we code a normal gf. 1556 // the GF frame error if we code a normal gf.
1564 gf_first_frame_err = mod_frame_err; 1557 gf_first_frame_err = mod_frame_err;
1565 1558
1566 // If this is a key frame or the overlay from a previous arf then 1559 // If this is a key frame or the overlay from a previous arf then
1567 // the error score / cost of this frame has already been accounted for. 1560 // the error score / cost of this frame has already been accounted for.
1568 if (cpi->common.frame_type == KEY_FRAME || rc->source_alt_ref_active) 1561 if (cpi->common.frame_type == KEY_FRAME || rc->source_alt_ref_active)
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
1608 &abs_mv_in_out_accumulator, 1601 &abs_mv_in_out_accumulator,
1609 &mv_ratio_accumulator); 1602 &mv_ratio_accumulator);
1610 1603
1611 // Accumulate the effect of prediction quality decay. 1604 // Accumulate the effect of prediction quality decay.
1612 if (!flash_detected) { 1605 if (!flash_detected) {
1613 last_loop_decay_rate = loop_decay_rate; 1606 last_loop_decay_rate = loop_decay_rate;
1614 loop_decay_rate = get_prediction_decay_rate(&cpi->common, &next_frame); 1607 loop_decay_rate = get_prediction_decay_rate(&cpi->common, &next_frame);
1615 decay_accumulator = decay_accumulator * loop_decay_rate; 1608 decay_accumulator = decay_accumulator * loop_decay_rate;
1616 1609
1617 // Monitor for static sections. 1610 // Monitor for static sections.
1618 zero_motion_accumulator = 1611 zero_motion_accumulator = MIN(zero_motion_accumulator,
1619 MIN(zero_motion_accumulator, 1612 get_zero_motion_factor(&next_frame));
1620 get_zero_motion_factor(&cpi->common, &next_frame));
1621 1613
1622 // Break clause to detect very still sections after motion. For example, 1614 // Break clause to detect very still sections after motion. For example,
1623 // a static image after a fade or other transition. 1615 // a static image after a fade or other transition.
1624 if (detect_transition_to_still(twopass, i, 5, loop_decay_rate, 1616 if (detect_transition_to_still(twopass, i, 5, loop_decay_rate,
1625 last_loop_decay_rate)) { 1617 last_loop_decay_rate)) {
1626 allow_alt_ref = 0; 1618 allow_alt_ref = 0;
1627 break; 1619 break;
1628 } 1620 }
1629 } 1621 }
1630 1622
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1824 } 1816 }
1825 } 1817 }
1826 1818
1827 return is_viable_kf; 1819 return is_viable_kf;
1828 } 1820 }
1829 1821
1830 static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) { 1822 static void find_next_key_frame(VP9_COMP *cpi, FIRSTPASS_STATS *this_frame) {
1831 int i, j; 1823 int i, j;
1832 RATE_CONTROL *const rc = &cpi->rc; 1824 RATE_CONTROL *const rc = &cpi->rc;
1833 TWO_PASS *const twopass = &cpi->twopass; 1825 TWO_PASS *const twopass = &cpi->twopass;
1826 GF_GROUP *const gf_group = &twopass->gf_group;
1834 const VP9EncoderConfig *const oxcf = &cpi->oxcf; 1827 const VP9EncoderConfig *const oxcf = &cpi->oxcf;
1835 const FIRSTPASS_STATS first_frame = *this_frame; 1828 const FIRSTPASS_STATS first_frame = *this_frame;
1836 const FIRSTPASS_STATS *const start_position = twopass->stats_in; 1829 const FIRSTPASS_STATS *const start_position = twopass->stats_in;
1837 FIRSTPASS_STATS next_frame; 1830 FIRSTPASS_STATS next_frame;
1838 FIRSTPASS_STATS last_frame; 1831 FIRSTPASS_STATS last_frame;
1839 int kf_bits = 0; 1832 int kf_bits = 0;
1840 double decay_accumulator = 1.0; 1833 double decay_accumulator = 1.0;
1841 double zero_motion_accumulator = 1.0; 1834 double zero_motion_accumulator = 1.0;
1842 double boost_score = 0.0; 1835 double boost_score = 0.0;
1843 double kf_mod_err = 0.0; 1836 double kf_mod_err = 0.0;
1844 double kf_group_err = 0.0; 1837 double kf_group_err = 0.0;
1845 double recent_loop_decay[8] = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0}; 1838 double recent_loop_decay[8] = {1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0};
1846 1839
1847 vp9_zero(next_frame); 1840 vp9_zero(next_frame);
1848 1841
1849 cpi->common.frame_type = KEY_FRAME; 1842 cpi->common.frame_type = KEY_FRAME;
1850 1843
1851 // Reset the GF group data structures. 1844 // Reset the GF group data structures.
1852 vp9_zero(twopass->gf_group); 1845 vp9_zero(*gf_group);
1853 1846
1854 // Is this a forced key frame by interval. 1847 // Is this a forced key frame by interval.
1855 rc->this_key_frame_forced = rc->next_key_frame_forced; 1848 rc->this_key_frame_forced = rc->next_key_frame_forced;
1856 1849
1857 // Clear the alt ref active flag and last group multi arf flags as they 1850 // Clear the alt ref active flag and last group multi arf flags as they
1858 // can never be set for a key frame. 1851 // can never be set for a key frame.
1859 rc->source_alt_ref_active = 0; 1852 rc->source_alt_ref_active = 0;
1860 cpi->multi_arf_last_grp_enabled = 0; 1853 cpi->multi_arf_last_grp_enabled = 0;
1861 1854
1862 // KF is always a GF so clear frames till next gf counter. 1855 // KF is always a GF so clear frames till next gf counter.
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1980 1973
1981 // Scan through the kf group collating various stats used to deteermine 1974 // Scan through the kf group collating various stats used to deteermine
1982 // how many bits to spend on it. 1975 // how many bits to spend on it.
1983 decay_accumulator = 1.0; 1976 decay_accumulator = 1.0;
1984 boost_score = 0.0; 1977 boost_score = 0.0;
1985 for (i = 0; i < rc->frames_to_key; ++i) { 1978 for (i = 0; i < rc->frames_to_key; ++i) {
1986 if (EOF == input_stats(twopass, &next_frame)) 1979 if (EOF == input_stats(twopass, &next_frame))
1987 break; 1980 break;
1988 1981
1989 // Monitor for static sections. 1982 // Monitor for static sections.
1990 zero_motion_accumulator = 1983 zero_motion_accumulator =MIN(zero_motion_accumulator,
1991 MIN(zero_motion_accumulator, 1984 get_zero_motion_factor(&next_frame));
1992 get_zero_motion_factor(&cpi->common, &next_frame));
1993 1985
1994 // For the first few frames collect data to decide kf boost. 1986 // For the first few frames collect data to decide kf boost.
1995 if (i <= (rc->max_gf_interval * 2)) { 1987 if (i <= (rc->max_gf_interval * 2)) {
1996 double r; 1988 double r;
1997 if (next_frame.intra_error > twopass->kf_intra_err_min) 1989 if (next_frame.intra_error > twopass->kf_intra_err_min)
1998 r = (IIKFACTOR2 * next_frame.intra_error / 1990 r = (IIKFACTOR2 * next_frame.intra_error /
1999 DOUBLE_DIVIDE_CHECK(next_frame.coded_error)); 1991 DOUBLE_DIVIDE_CHECK(next_frame.coded_error));
2000 else 1992 else
2001 r = (IIKFACTOR2 * twopass->kf_intra_err_min / 1993 r = (IIKFACTOR2 * twopass->kf_intra_err_min /
2002 DOUBLE_DIVIDE_CHECK(next_frame.coded_error)); 1994 DOUBLE_DIVIDE_CHECK(next_frame.coded_error));
(...skipping 30 matching lines...) Expand all
2033 rc->kf_boost = (rc->frames_to_key * 3); 2025 rc->kf_boost = (rc->frames_to_key * 3);
2034 if (rc->kf_boost < MIN_KF_BOOST) 2026 if (rc->kf_boost < MIN_KF_BOOST)
2035 rc->kf_boost = MIN_KF_BOOST; 2027 rc->kf_boost = MIN_KF_BOOST;
2036 2028
2037 kf_bits = calculate_boost_bits((rc->frames_to_key - 1), 2029 kf_bits = calculate_boost_bits((rc->frames_to_key - 1),
2038 rc->kf_boost, twopass->kf_group_bits); 2030 rc->kf_boost, twopass->kf_group_bits);
2039 2031
2040 twopass->kf_group_bits -= kf_bits; 2032 twopass->kf_group_bits -= kf_bits;
2041 2033
2042 // Save the bits to spend on the key frame. 2034 // Save the bits to spend on the key frame.
2043 twopass->gf_group.bit_allocation[0] = kf_bits; 2035 gf_group->bit_allocation[0] = kf_bits;
2044 twopass->gf_group.update_type[0] = KF_UPDATE; 2036 gf_group->update_type[0] = KF_UPDATE;
2045 twopass->gf_group.rf_level[0] = KF_STD; 2037 gf_group->rf_level[0] = KF_STD;
2046 2038
2047 // Note the total error score of the kf group minus the key frame itself. 2039 // Note the total error score of the kf group minus the key frame itself.
2048 twopass->kf_group_error_left = (int)(kf_group_err - kf_mod_err); 2040 twopass->kf_group_error_left = (int)(kf_group_err - kf_mod_err);
2049 2041
2050 // Adjust the count of total modified error left. 2042 // Adjust the count of total modified error left.
2051 // The count of bits left is adjusted elsewhere based on real coded frame 2043 // The count of bits left is adjusted elsewhere based on real coded frame
2052 // sizes. 2044 // sizes.
2053 twopass->modified_error_left -= kf_group_err; 2045 twopass->modified_error_left -= kf_group_err;
2054 } 2046 }
2055 2047
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
2112 if (cpi->alt_ref_source == NULL) 2104 if (cpi->alt_ref_source == NULL)
2113 cpi->refresh_alt_ref_frame = 0; 2105 cpi->refresh_alt_ref_frame = 0;
2114 } 2106 }
2115 } 2107 }
2116 2108
2117 2109
2118 void vp9_rc_get_second_pass_params(VP9_COMP *cpi) { 2110 void vp9_rc_get_second_pass_params(VP9_COMP *cpi) {
2119 VP9_COMMON *const cm = &cpi->common; 2111 VP9_COMMON *const cm = &cpi->common;
2120 RATE_CONTROL *const rc = &cpi->rc; 2112 RATE_CONTROL *const rc = &cpi->rc;
2121 TWO_PASS *const twopass = &cpi->twopass; 2113 TWO_PASS *const twopass = &cpi->twopass;
2114 GF_GROUP *const gf_group = &twopass->gf_group;
2122 int frames_left; 2115 int frames_left;
2123 FIRSTPASS_STATS this_frame; 2116 FIRSTPASS_STATS this_frame;
2124 FIRSTPASS_STATS this_frame_copy; 2117 FIRSTPASS_STATS this_frame_copy;
2125 2118
2126 int target_rate; 2119 int target_rate;
2127 LAYER_CONTEXT *lc = NULL; 2120 LAYER_CONTEXT *const lc = is_spatial_svc(cpi) ?
2121 &cpi->svc.layer_context[cpi->svc.spatial_layer_id] : 0;
2128 2122
2129 if (is_spatial_svc(cpi)) { 2123 if (lc != NULL) {
2130 lc = &cpi->svc.layer_context[cpi->svc.spatial_layer_id];
2131 frames_left = (int)(twopass->total_stats.count - 2124 frames_left = (int)(twopass->total_stats.count -
2132 lc->current_video_frame_in_layer); 2125 lc->current_video_frame_in_layer);
2133 } else { 2126 } else {
2134 frames_left = (int)(twopass->total_stats.count - 2127 frames_left = (int)(twopass->total_stats.count -
2135 cm->current_video_frame); 2128 cm->current_video_frame);
2136 } 2129 }
2137 2130
2138 if (!twopass->stats_in) 2131 if (!twopass->stats_in)
2139 return; 2132 return;
2140 2133
2141 // If this is an arf frame then we dont want to read the stats file or 2134 // If this is an arf frame then we dont want to read the stats file or
2142 // advance the input pointer as we already have what we need. 2135 // advance the input pointer as we already have what we need.
2143 if (twopass->gf_group.update_type[twopass->gf_group.index] == ARF_UPDATE) { 2136 if (gf_group->update_type[gf_group->index] == ARF_UPDATE) {
2144 int target_rate; 2137 int target_rate;
2145 configure_buffer_updates(cpi); 2138 configure_buffer_updates(cpi);
2146 target_rate = twopass->gf_group.bit_allocation[twopass->gf_group.index]; 2139 target_rate = gf_group->bit_allocation[gf_group->index];
2147 target_rate = vp9_rc_clamp_pframe_target_size(cpi, target_rate); 2140 target_rate = vp9_rc_clamp_pframe_target_size(cpi, target_rate);
2148 rc->base_frame_target = target_rate; 2141 rc->base_frame_target = target_rate;
2149 2142
2150 // Correction to rate target based on prior over or under shoot. 2143 // Correction to rate target based on prior over or under shoot.
2151 if (cpi->oxcf.rc_mode == VPX_VBR) 2144 if (cpi->oxcf.rc_mode == VPX_VBR)
2152 vbr_rate_correction(&target_rate, rc->vbr_bits_off_target); 2145 vbr_rate_correction(&target_rate, rc->vbr_bits_off_target);
2153 2146
2154 vp9_rc_set_frame_target(cpi, target_rate); 2147 vp9_rc_set_frame_target(cpi, target_rate);
2155 cm->frame_type = INTER_FRAME; 2148 cm->frame_type = INTER_FRAME;
2156 2149
2157 if (is_spatial_svc(cpi)) { 2150 if (lc != NULL) {
2158 if (cpi->svc.spatial_layer_id == 0) { 2151 if (cpi->svc.spatial_layer_id == 0) {
2159 lc->is_key_frame = 0; 2152 lc->is_key_frame = 0;
2160 } else { 2153 } else {
2161 lc->is_key_frame = cpi->svc.layer_context[0].is_key_frame; 2154 lc->is_key_frame = cpi->svc.layer_context[0].is_key_frame;
2162 2155
2163 if (lc->is_key_frame) 2156 if (lc->is_key_frame)
2164 cpi->ref_frame_flags &= (~VP9_LAST_FLAG); 2157 cpi->ref_frame_flags &= (~VP9_LAST_FLAG);
2165 } 2158 }
2166 } 2159 }
2167 2160
2168 return; 2161 return;
2169 } 2162 }
2170 2163
2171 vp9_clear_system_state(); 2164 vp9_clear_system_state();
2172 2165
2173 if (is_spatial_svc(cpi) && twopass->kf_intra_err_min == 0) { 2166 if (lc != NULL && twopass->kf_intra_err_min == 0) {
2174 twopass->kf_intra_err_min = KF_MB_INTRA_MIN * cpi->common.MBs; 2167 twopass->kf_intra_err_min = KF_MB_INTRA_MIN * cpi->common.MBs;
2175 twopass->gf_intra_err_min = GF_MB_INTRA_MIN * cpi->common.MBs; 2168 twopass->gf_intra_err_min = GF_MB_INTRA_MIN * cpi->common.MBs;
2176 } 2169 }
2177 2170
2178 if (cpi->oxcf.rc_mode == VPX_Q) { 2171 if (cpi->oxcf.rc_mode == VPX_Q) {
2179 twopass->active_worst_quality = cpi->oxcf.cq_level; 2172 twopass->active_worst_quality = cpi->oxcf.cq_level;
2180 } else if (cm->current_video_frame == 0 || 2173 } else if (cm->current_video_frame == 0 ||
2181 (is_spatial_svc(cpi) && 2174 (lc != NULL && lc->current_video_frame_in_layer == 0)) {
2182 lc->current_video_frame_in_layer == 0)) {
2183 // Special case code for first frame. 2175 // Special case code for first frame.
2184 const int section_target_bandwidth = (int)(twopass->bits_left / 2176 const int section_target_bandwidth = (int)(twopass->bits_left /
2185 frames_left); 2177 frames_left);
2186 const int tmp_q = get_twopass_worst_quality(cpi, &twopass->total_left_stats, 2178 const int tmp_q = get_twopass_worst_quality(cpi, &twopass->total_left_stats,
2187 section_target_bandwidth); 2179 section_target_bandwidth);
2188 twopass->active_worst_quality = tmp_q; 2180 twopass->active_worst_quality = tmp_q;
2189 rc->ni_av_qi = tmp_q; 2181 rc->ni_av_qi = tmp_q;
2190 rc->avg_q = vp9_convert_qindex_to_q(tmp_q); 2182 rc->avg_q = vp9_convert_qindex_to_q(tmp_q);
2191 } 2183 }
2192 vp9_zero(this_frame); 2184 vp9_zero(this_frame);
2193 if (EOF == input_stats(twopass, &this_frame)) 2185 if (EOF == input_stats(twopass, &this_frame))
2194 return; 2186 return;
2195 2187
2196 // Local copy of the current frame's first pass stats. 2188 // Local copy of the current frame's first pass stats.
2197 this_frame_copy = this_frame; 2189 this_frame_copy = this_frame;
2198 2190
2199 // Keyframe and section processing. 2191 // Keyframe and section processing.
2200 if (rc->frames_to_key == 0 || 2192 if (rc->frames_to_key == 0 ||
2201 (cpi->frame_flags & FRAMEFLAGS_KEY)) { 2193 (cpi->frame_flags & FRAMEFLAGS_KEY)) {
2202 // Define next KF group and assign bits to it. 2194 // Define next KF group and assign bits to it.
2203 find_next_key_frame(cpi, &this_frame_copy); 2195 find_next_key_frame(cpi, &this_frame_copy);
2204 } else { 2196 } else {
2205 cm->frame_type = INTER_FRAME; 2197 cm->frame_type = INTER_FRAME;
2206 } 2198 }
2207 2199
2208 if (is_spatial_svc(cpi)) { 2200 if (lc != NULL) {
2209 if (cpi->svc.spatial_layer_id == 0) { 2201 if (cpi->svc.spatial_layer_id == 0) {
2210 lc->is_key_frame = (cm->frame_type == KEY_FRAME); 2202 lc->is_key_frame = (cm->frame_type == KEY_FRAME);
2211 if (lc->is_key_frame) 2203 if (lc->is_key_frame)
2212 cpi->ref_frame_flags &= 2204 cpi->ref_frame_flags &=
2213 (~VP9_LAST_FLAG & ~VP9_GOLD_FLAG & ~VP9_ALT_FLAG); 2205 (~VP9_LAST_FLAG & ~VP9_GOLD_FLAG & ~VP9_ALT_FLAG);
2214 } else { 2206 } else {
2215 cm->frame_type = INTER_FRAME; 2207 cm->frame_type = INTER_FRAME;
2216 lc->is_key_frame = cpi->svc.layer_context[0].is_key_frame; 2208 lc->is_key_frame = cpi->svc.layer_context[0].is_key_frame;
2217 2209
2218 if (lc->is_key_frame) { 2210 if (lc->is_key_frame) {
(...skipping 10 matching lines...) Expand all
2229 // As long as max_thresh for encode breakout is small enough, it is ok 2221 // As long as max_thresh for encode breakout is small enough, it is ok
2230 // to enable it for show frame, i.e. set allow_encode_breakout to 2222 // to enable it for show frame, i.e. set allow_encode_breakout to
2231 // ENCODE_BREAKOUT_LIMITED. 2223 // ENCODE_BREAKOUT_LIMITED.
2232 if (!cm->show_frame) 2224 if (!cm->show_frame)
2233 cpi->allow_encode_breakout = ENCODE_BREAKOUT_DISABLED; 2225 cpi->allow_encode_breakout = ENCODE_BREAKOUT_DISABLED;
2234 else 2226 else
2235 cpi->allow_encode_breakout = ENCODE_BREAKOUT_LIMITED; 2227 cpi->allow_encode_breakout = ENCODE_BREAKOUT_LIMITED;
2236 } 2228 }
2237 2229
2238 rc->frames_till_gf_update_due = rc->baseline_gf_interval; 2230 rc->frames_till_gf_update_due = rc->baseline_gf_interval;
2239 if (!is_spatial_svc(cpi)) 2231 if (lc != NULL)
2240 cpi->refresh_golden_frame = 1; 2232 cpi->refresh_golden_frame = 1;
2241 } 2233 }
2242 2234
2243 configure_buffer_updates(cpi); 2235 configure_buffer_updates(cpi);
2244 2236
2245 target_rate = twopass->gf_group.bit_allocation[twopass->gf_group.index]; 2237 target_rate = gf_group->bit_allocation[gf_group->index];
2246 if (cpi->common.frame_type == KEY_FRAME) 2238 if (cpi->common.frame_type == KEY_FRAME)
2247 target_rate = vp9_rc_clamp_iframe_target_size(cpi, target_rate); 2239 target_rate = vp9_rc_clamp_iframe_target_size(cpi, target_rate);
2248 else 2240 else
2249 target_rate = vp9_rc_clamp_pframe_target_size(cpi, target_rate); 2241 target_rate = vp9_rc_clamp_pframe_target_size(cpi, target_rate);
2250 2242
2251 rc->base_frame_target = target_rate; 2243 rc->base_frame_target = target_rate;
2252 2244
2253 // Correction to rate target based on prior over or under shoot. 2245 // Correction to rate target based on prior over or under shoot.
2254 if (cpi->oxcf.rc_mode == VPX_VBR) 2246 if (cpi->oxcf.rc_mode == VPX_VBR)
2255 vbr_rate_correction(&target_rate, rc->vbr_bits_off_target); 2247 vbr_rate_correction(&target_rate, rc->vbr_bits_off_target);
(...skipping 20 matching lines...) Expand all
2276 2268
2277 if (cpi->common.frame_type != KEY_FRAME && 2269 if (cpi->common.frame_type != KEY_FRAME &&
2278 !vp9_is_upper_layer_key_frame(cpi)) { 2270 !vp9_is_upper_layer_key_frame(cpi)) {
2279 twopass->kf_group_bits -= bits_used; 2271 twopass->kf_group_bits -= bits_used;
2280 } 2272 }
2281 twopass->kf_group_bits = MAX(twopass->kf_group_bits, 0); 2273 twopass->kf_group_bits = MAX(twopass->kf_group_bits, 0);
2282 2274
2283 // Increment the gf group index ready for the next frame. 2275 // Increment the gf group index ready for the next frame.
2284 ++twopass->gf_group.index; 2276 ++twopass->gf_group.index;
2285 } 2277 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/encoder/vp9_encoder.c ('k') | source/libvpx/vp9/encoder/vp9_pickmode.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698