| 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 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 } | 181 } |
| 182 vp9_init_plane_quantizers(cpi, x); | 182 vp9_init_plane_quantizers(cpi, x); |
| 183 | 183 |
| 184 x->encode_breakout = cpi->segment_encode_breakout[mbmi->segment_id]; | 184 x->encode_breakout = cpi->segment_encode_breakout[mbmi->segment_id]; |
| 185 } else { | 185 } else { |
| 186 mbmi->segment_id = 0; | 186 mbmi->segment_id = 0; |
| 187 x->encode_breakout = cpi->encode_breakout; | 187 x->encode_breakout = cpi->encode_breakout; |
| 188 } | 188 } |
| 189 } | 189 } |
| 190 | 190 |
| 191 static void duplicate_mode_info_in_sb(VP9_COMMON * const cm, | 191 static void duplicate_mode_info_in_sb(VP9_COMMON *cm, MACROBLOCKD *xd, |
| 192 MACROBLOCKD *const xd, | 192 int mi_row, int mi_col, |
| 193 int mi_row, | 193 BLOCK_SIZE bsize) { |
| 194 int mi_col, | |
| 195 BLOCK_SIZE bsize) { | |
| 196 const int block_width = num_8x8_blocks_wide_lookup[bsize]; | 194 const int block_width = num_8x8_blocks_wide_lookup[bsize]; |
| 197 const int block_height = num_8x8_blocks_high_lookup[bsize]; | 195 const int block_height = num_8x8_blocks_high_lookup[bsize]; |
| 198 int i, j; | 196 int i, j; |
| 199 for (j = 0; j < block_height; ++j) | 197 for (j = 0; j < block_height; ++j) |
| 200 for (i = 0; i < block_width; ++i) { | 198 for (i = 0; i < block_width; ++i) { |
| 201 if (mi_row + j < cm->mi_rows && mi_col + i < cm->mi_cols) | 199 if (mi_row + j < cm->mi_rows && mi_col + i < cm->mi_cols) |
| 202 xd->mi[j * xd->mi_stride + i] = xd->mi[0]; | 200 xd->mi[j * xd->mi_stride + i] = xd->mi[0]; |
| 203 } | 201 } |
| 204 } | 202 } |
| 205 | 203 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 } | 284 } |
| 287 case BLOCK_8X8: { | 285 case BLOCK_8X8: { |
| 288 v8x8 *vt = (v8x8 *) data; | 286 v8x8 *vt = (v8x8 *) data; |
| 289 node->part_variances = &vt->part_variances; | 287 node->part_variances = &vt->part_variances; |
| 290 for (i = 0; i < 4; i++) | 288 for (i = 0; i < 4; i++) |
| 291 node->split[i] = &vt->split[i]; | 289 node->split[i] = &vt->split[i]; |
| 292 break; | 290 break; |
| 293 } | 291 } |
| 294 default: { | 292 default: { |
| 295 assert(0); | 293 assert(0); |
| 294 break; |
| 296 } | 295 } |
| 297 } | 296 } |
| 298 } | 297 } |
| 299 | 298 |
| 300 // Set variance values given sum square error, sum error, count. | 299 // Set variance values given sum square error, sum error, count. |
| 301 static void fill_variance(int64_t s2, int64_t s, int c, var *v) { | 300 static void fill_variance(int64_t s2, int64_t s, int c, var *v) { |
| 302 v->sum_square_error = s2; | 301 v->sum_square_error = s2; |
| 303 v->sum_error = s; | 302 v->sum_error = s; |
| 304 v->count = c; | 303 v->count = c; |
| 305 if (c > 0) | 304 if (c > 0) |
| (...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 if (seg->enabled && output_enabled) { | 532 if (seg->enabled && output_enabled) { |
| 534 // For in frame complexity AQ copy the segment id from the segment map. | 533 // For in frame complexity AQ copy the segment id from the segment map. |
| 535 if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { | 534 if (cpi->oxcf.aq_mode == COMPLEXITY_AQ) { |
| 536 const uint8_t *const map = seg->update_map ? cpi->segmentation_map | 535 const uint8_t *const map = seg->update_map ? cpi->segmentation_map |
| 537 : cm->last_frame_seg_map; | 536 : cm->last_frame_seg_map; |
| 538 mi_addr->mbmi.segment_id = | 537 mi_addr->mbmi.segment_id = |
| 539 vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); | 538 vp9_get_segment_id(cm, map, bsize, mi_row, mi_col); |
| 540 } | 539 } |
| 541 // Else for cyclic refresh mode update the segment map, set the segment id | 540 // Else for cyclic refresh mode update the segment map, set the segment id |
| 542 // and then update the quantizer. | 541 // and then update the quantizer. |
| 543 else if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { | 542 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) { |
| 544 vp9_cyclic_refresh_update_segment(cpi, &xd->mi[0]->mbmi, | 543 vp9_cyclic_refresh_update_segment(cpi, &xd->mi[0]->mbmi, |
| 545 mi_row, mi_col, bsize, 1); | 544 mi_row, mi_col, bsize, 1); |
| 546 vp9_init_plane_quantizers(cpi, x); | |
| 547 } | 545 } |
| 548 } | 546 } |
| 549 | 547 |
| 550 max_plane = is_inter_block(mbmi) ? MAX_MB_PLANE : 1; | 548 max_plane = is_inter_block(mbmi) ? MAX_MB_PLANE : 1; |
| 551 for (i = 0; i < max_plane; ++i) { | 549 for (i = 0; i < max_plane; ++i) { |
| 552 p[i].coeff = ctx->coeff_pbuf[i][1]; | 550 p[i].coeff = ctx->coeff_pbuf[i][1]; |
| 553 p[i].qcoeff = ctx->qcoeff_pbuf[i][1]; | 551 p[i].qcoeff = ctx->qcoeff_pbuf[i][1]; |
| 554 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][1]; | 552 pd[i].dqcoeff = ctx->dqcoeff_pbuf[i][1]; |
| 555 p[i].eobs = ctx->eobs_pbuf[i][1]; | 553 p[i].eobs = ctx->eobs_pbuf[i][1]; |
| 556 } | 554 } |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 791 } | 789 } |
| 792 | 790 |
| 793 x->rdmult = orig_rdmult; | 791 x->rdmult = orig_rdmult; |
| 794 | 792 |
| 795 if (aq_mode == VARIANCE_AQ && *totalrate != INT_MAX) { | 793 if (aq_mode == VARIANCE_AQ && *totalrate != INT_MAX) { |
| 796 vp9_clear_system_state(); | 794 vp9_clear_system_state(); |
| 797 *totalrate = (int)round(*totalrate * rdmult_ratio); | 795 *totalrate = (int)round(*totalrate * rdmult_ratio); |
| 798 } | 796 } |
| 799 } | 797 } |
| 800 | 798 |
| 801 static void update_stats(VP9_COMP *cpi) { | 799 static void update_stats(VP9_COMMON *cm, const MACROBLOCK *x) { |
| 802 VP9_COMMON *const cm = &cpi->common; | |
| 803 const MACROBLOCK *const x = &cpi->mb; | |
| 804 const MACROBLOCKD *const xd = &x->e_mbd; | 800 const MACROBLOCKD *const xd = &x->e_mbd; |
| 805 const MODE_INFO *const mi = xd->mi[0]; | 801 const MODE_INFO *const mi = xd->mi[0]; |
| 806 const MB_MODE_INFO *const mbmi = &mi->mbmi; | 802 const MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 807 | 803 |
| 808 if (!frame_is_intra_only(cm)) { | 804 if (!frame_is_intra_only(cm)) { |
| 809 const int seg_ref_active = vp9_segfeature_active(&cm->seg, mbmi->segment_id, | 805 const int seg_ref_active = vp9_segfeature_active(&cm->seg, mbmi->segment_id, |
| 810 SEG_LVL_REF_FRAME); | 806 SEG_LVL_REF_FRAME); |
| 811 if (!seg_ref_active) { | 807 if (!seg_ref_active) { |
| 812 FRAME_COUNTS *const counts = &cm->counts; | 808 FRAME_COUNTS *const counts = &cm->counts; |
| 813 const int inter_block = is_inter_block(mbmi); | 809 const int inter_block = is_inter_block(mbmi); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 905 | 901 |
| 906 static void encode_b(VP9_COMP *cpi, const TileInfo *const tile, | 902 static void encode_b(VP9_COMP *cpi, const TileInfo *const tile, |
| 907 TOKENEXTRA **tp, int mi_row, int mi_col, | 903 TOKENEXTRA **tp, int mi_row, int mi_col, |
| 908 int output_enabled, BLOCK_SIZE bsize, | 904 int output_enabled, BLOCK_SIZE bsize, |
| 909 PICK_MODE_CONTEXT *ctx) { | 905 PICK_MODE_CONTEXT *ctx) { |
| 910 set_offsets(cpi, tile, mi_row, mi_col, bsize); | 906 set_offsets(cpi, tile, mi_row, mi_col, bsize); |
| 911 update_state(cpi, ctx, mi_row, mi_col, bsize, output_enabled); | 907 update_state(cpi, ctx, mi_row, mi_col, bsize, output_enabled); |
| 912 encode_superblock(cpi, tp, output_enabled, mi_row, mi_col, bsize, ctx); | 908 encode_superblock(cpi, tp, output_enabled, mi_row, mi_col, bsize, ctx); |
| 913 | 909 |
| 914 if (output_enabled) { | 910 if (output_enabled) { |
| 915 update_stats(cpi); | 911 update_stats(&cpi->common, &cpi->mb); |
| 916 | 912 |
| 917 (*tp)->token = EOSB_TOKEN; | 913 (*tp)->token = EOSB_TOKEN; |
| 918 (*tp)++; | 914 (*tp)++; |
| 919 } | 915 } |
| 920 } | 916 } |
| 921 | 917 |
| 922 static void encode_sb(VP9_COMP *cpi, const TileInfo *const tile, | 918 static void encode_sb(VP9_COMP *cpi, const TileInfo *const tile, |
| 923 TOKENEXTRA **tp, int mi_row, int mi_col, | 919 TOKENEXTRA **tp, int mi_row, int mi_col, |
| 924 int output_enabled, BLOCK_SIZE bsize, | 920 int output_enabled, BLOCK_SIZE bsize, |
| 925 PC_TREE *pc_tree) { | 921 PC_TREE *pc_tree) { |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 encode_sb(cpi, tile, tp, mi_row, mi_col + hbs, output_enabled, subsize, | 974 encode_sb(cpi, tile, tp, mi_row, mi_col + hbs, output_enabled, subsize, |
| 979 pc_tree->split[1]); | 975 pc_tree->split[1]); |
| 980 encode_sb(cpi, tile, tp, mi_row + hbs, mi_col, output_enabled, subsize, | 976 encode_sb(cpi, tile, tp, mi_row + hbs, mi_col, output_enabled, subsize, |
| 981 pc_tree->split[2]); | 977 pc_tree->split[2]); |
| 982 encode_sb(cpi, tile, tp, mi_row + hbs, mi_col + hbs, output_enabled, | 978 encode_sb(cpi, tile, tp, mi_row + hbs, mi_col + hbs, output_enabled, |
| 983 subsize, pc_tree->split[3]); | 979 subsize, pc_tree->split[3]); |
| 984 } | 980 } |
| 985 break; | 981 break; |
| 986 default: | 982 default: |
| 987 assert("Invalid partition type."); | 983 assert("Invalid partition type."); |
| 984 break; |
| 988 } | 985 } |
| 989 | 986 |
| 990 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) | 987 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) |
| 991 update_partition_context(xd, mi_row, mi_col, subsize, bsize); | 988 update_partition_context(xd, mi_row, mi_col, subsize, bsize); |
| 992 } | 989 } |
| 993 | 990 |
| 994 // Check to see if the given partition size is allowed for a specified number | 991 // Check to see if the given partition size is allowed for a specified number |
| 995 // of 8x8 block rows and columns remaining in the image. | 992 // of 8x8 block rows and columns remaining in the image. |
| 996 // If not then return the largest allowed partition size | 993 // If not then return the largest allowed partition size |
| 997 static BLOCK_SIZE find_partition_size(BLOCK_SIZE bsize, | 994 static BLOCK_SIZE find_partition_size(BLOCK_SIZE bsize, |
| (...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1314 if (is_inter_block(mbmi)) { | 1311 if (is_inter_block(mbmi)) { |
| 1315 vp9_update_mv_count(cm, xd); | 1312 vp9_update_mv_count(cm, xd); |
| 1316 | 1313 |
| 1317 if (cm->interp_filter == SWITCHABLE) { | 1314 if (cm->interp_filter == SWITCHABLE) { |
| 1318 const int pred_ctx = vp9_get_pred_context_switchable_interp(xd); | 1315 const int pred_ctx = vp9_get_pred_context_switchable_interp(xd); |
| 1319 ++cm->counts.switchable_interp[pred_ctx][mbmi->interp_filter]; | 1316 ++cm->counts.switchable_interp[pred_ctx][mbmi->interp_filter]; |
| 1320 } | 1317 } |
| 1321 } | 1318 } |
| 1322 | 1319 |
| 1323 x->skip = ctx->skip; | 1320 x->skip = ctx->skip; |
| 1324 x->skip_txfm = mbmi->segment_id ? 0 : ctx->skip_txfm; | 1321 x->skip_txfm[0] = mbmi->segment_id ? 0 : ctx->skip_txfm[0]; |
| 1325 } | 1322 } |
| 1326 | 1323 |
| 1327 static void encode_b_rt(VP9_COMP *cpi, const TileInfo *const tile, | 1324 static void encode_b_rt(VP9_COMP *cpi, const TileInfo *const tile, |
| 1328 TOKENEXTRA **tp, int mi_row, int mi_col, | 1325 TOKENEXTRA **tp, int mi_row, int mi_col, |
| 1329 int output_enabled, BLOCK_SIZE bsize, | 1326 int output_enabled, BLOCK_SIZE bsize, |
| 1330 PICK_MODE_CONTEXT *ctx) { | 1327 PICK_MODE_CONTEXT *ctx) { |
| 1331 | |
| 1332 | |
| 1333 set_offsets(cpi, tile, mi_row, mi_col, bsize); | 1328 set_offsets(cpi, tile, mi_row, mi_col, bsize); |
| 1334 update_state_rt(cpi, ctx, mi_row, mi_col, bsize); | 1329 update_state_rt(cpi, ctx, mi_row, mi_col, bsize); |
| 1335 | 1330 |
| 1336 #if CONFIG_DENOISING | 1331 #if CONFIG_VP9_TEMPORAL_DENOISING |
| 1337 if (cpi->oxcf.noise_sensitivity > 0 && output_enabled) { | 1332 if (cpi->oxcf.noise_sensitivity > 0 && output_enabled) { |
| 1338 vp9_denoiser_denoise(&cpi->denoiser, &cpi->mb, mi_row, mi_col, | 1333 vp9_denoiser_denoise(&cpi->denoiser, &cpi->mb, mi_row, mi_col, |
| 1339 MAX(BLOCK_8X8, bsize), ctx); | 1334 MAX(BLOCK_8X8, bsize), ctx); |
| 1340 } | 1335 } |
| 1341 #endif | 1336 #endif |
| 1342 | 1337 |
| 1343 encode_superblock(cpi, tp, output_enabled, mi_row, mi_col, bsize, ctx); | 1338 encode_superblock(cpi, tp, output_enabled, mi_row, mi_col, bsize, ctx); |
| 1344 update_stats(cpi); | 1339 update_stats(&cpi->common, &cpi->mb); |
| 1345 | 1340 |
| 1346 (*tp)->token = EOSB_TOKEN; | 1341 (*tp)->token = EOSB_TOKEN; |
| 1347 (*tp)++; | 1342 (*tp)++; |
| 1348 } | 1343 } |
| 1349 | 1344 |
| 1350 static void encode_sb_rt(VP9_COMP *cpi, const TileInfo *const tile, | 1345 static void encode_sb_rt(VP9_COMP *cpi, const TileInfo *const tile, |
| 1351 TOKENEXTRA **tp, int mi_row, int mi_col, | 1346 TOKENEXTRA **tp, int mi_row, int mi_col, |
| 1352 int output_enabled, BLOCK_SIZE bsize, | 1347 int output_enabled, BLOCK_SIZE bsize, |
| 1353 PC_TREE *pc_tree) { | 1348 PC_TREE *pc_tree) { |
| 1354 VP9_COMMON *const cm = &cpi->common; | 1349 VP9_COMMON *const cm = &cpi->common; |
| 1355 MACROBLOCK *const x = &cpi->mb; | 1350 MACROBLOCK *const x = &cpi->mb; |
| 1356 MACROBLOCKD *const xd = &x->e_mbd; | 1351 MACROBLOCKD *const xd = &x->e_mbd; |
| 1357 | 1352 |
| 1358 const int bsl = b_width_log2(bsize), hbs = (1 << bsl) / 4; | 1353 const int bsl = b_width_log2(bsize), hbs = (1 << bsl) / 4; |
| 1359 int ctx; | 1354 int ctx; |
| 1360 PARTITION_TYPE partition; | 1355 PARTITION_TYPE partition; |
| 1361 BLOCK_SIZE subsize; | 1356 BLOCK_SIZE subsize; |
| 1362 | 1357 |
| 1363 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 1358 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
| 1364 return; | 1359 return; |
| 1365 | 1360 |
| 1366 if (bsize >= BLOCK_8X8) { | 1361 if (bsize >= BLOCK_8X8) { |
| 1367 MACROBLOCKD *const xd = &cpi->mb.e_mbd; | |
| 1368 const int idx_str = xd->mi_stride * mi_row + mi_col; | 1362 const int idx_str = xd->mi_stride * mi_row + mi_col; |
| 1369 MODE_INFO ** mi_8x8 = cm->mi_grid_visible + idx_str; | 1363 MODE_INFO ** mi_8x8 = cm->mi_grid_visible + idx_str; |
| 1370 ctx = partition_plane_context(xd, mi_row, mi_col, bsize); | 1364 ctx = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 1371 subsize = mi_8x8[0]->mbmi.sb_type; | 1365 subsize = mi_8x8[0]->mbmi.sb_type; |
| 1372 } else { | 1366 } else { |
| 1373 ctx = 0; | 1367 ctx = 0; |
| 1374 subsize = BLOCK_4X4; | 1368 subsize = BLOCK_4X4; |
| 1375 } | 1369 } |
| 1376 | 1370 |
| 1377 partition = partition_lookup[bsl][subsize]; | 1371 partition = partition_lookup[bsl][subsize]; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1405 pc_tree->split[0]); | 1399 pc_tree->split[0]); |
| 1406 encode_sb_rt(cpi, tile, tp, mi_row, mi_col + hbs, output_enabled, | 1400 encode_sb_rt(cpi, tile, tp, mi_row, mi_col + hbs, output_enabled, |
| 1407 subsize, pc_tree->split[1]); | 1401 subsize, pc_tree->split[1]); |
| 1408 encode_sb_rt(cpi, tile, tp, mi_row + hbs, mi_col, output_enabled, | 1402 encode_sb_rt(cpi, tile, tp, mi_row + hbs, mi_col, output_enabled, |
| 1409 subsize, pc_tree->split[2]); | 1403 subsize, pc_tree->split[2]); |
| 1410 encode_sb_rt(cpi, tile, tp, mi_row + hbs, mi_col + hbs, output_enabled, | 1404 encode_sb_rt(cpi, tile, tp, mi_row + hbs, mi_col + hbs, output_enabled, |
| 1411 subsize, pc_tree->split[3]); | 1405 subsize, pc_tree->split[3]); |
| 1412 break; | 1406 break; |
| 1413 default: | 1407 default: |
| 1414 assert("Invalid partition type."); | 1408 assert("Invalid partition type."); |
| 1409 break; |
| 1415 } | 1410 } |
| 1416 | 1411 |
| 1417 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) | 1412 if (partition != PARTITION_SPLIT || bsize == BLOCK_8X8) |
| 1418 update_partition_context(xd, mi_row, mi_col, subsize, bsize); | 1413 update_partition_context(xd, mi_row, mi_col, subsize, bsize); |
| 1419 } | 1414 } |
| 1420 | 1415 |
| 1421 static void rd_use_partition(VP9_COMP *cpi, | 1416 static void rd_use_partition(VP9_COMP *cpi, |
| 1422 const TileInfo *const tile, | 1417 const TileInfo *const tile, |
| 1423 MODE_INFO **mi_8x8, | 1418 MODE_INFO **mi_8x8, |
| 1424 TOKENEXTRA **tp, int mi_row, int mi_col, | 1419 TOKENEXTRA **tp, int mi_row, int mi_col, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1456 | 1451 |
| 1457 assert(num_4x4_blocks_wide_lookup[bsize] == | 1452 assert(num_4x4_blocks_wide_lookup[bsize] == |
| 1458 num_4x4_blocks_high_lookup[bsize]); | 1453 num_4x4_blocks_high_lookup[bsize]); |
| 1459 | 1454 |
| 1460 partition = partition_lookup[bsl][bs_type]; | 1455 partition = partition_lookup[bsl][bs_type]; |
| 1461 subsize = get_subsize(bsize, partition); | 1456 subsize = get_subsize(bsize, partition); |
| 1462 | 1457 |
| 1463 pc_tree->partitioning = partition; | 1458 pc_tree->partitioning = partition; |
| 1464 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 1459 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
| 1465 | 1460 |
| 1466 if (bsize == BLOCK_16X16) { | 1461 if (bsize == BLOCK_16X16 && cpi->oxcf.aq_mode) { |
| 1467 set_offsets(cpi, tile, mi_row, mi_col, bsize); | 1462 set_offsets(cpi, tile, mi_row, mi_col, bsize); |
| 1468 x->mb_energy = vp9_block_energy(cpi, x, bsize); | 1463 x->mb_energy = vp9_block_energy(cpi, x, bsize); |
| 1469 } | 1464 } |
| 1470 | 1465 |
| 1471 if (do_partition_search && | 1466 if (do_partition_search && |
| 1472 cpi->sf.partition_search_type == SEARCH_PARTITION && | 1467 cpi->sf.partition_search_type == SEARCH_PARTITION && |
| 1473 cpi->sf.adjust_partitioning_from_last_frame) { | 1468 cpi->sf.adjust_partitioning_from_last_frame) { |
| 1474 // Check if any of the sub blocks are further split. | 1469 // Check if any of the sub blocks are further split. |
| 1475 if (partition == PARTITION_SPLIT && subsize > BLOCK_8X8) { | 1470 if (partition == PARTITION_SPLIT && subsize > BLOCK_8X8) { |
| 1476 sub_subsize = get_subsize(subsize, PARTITION_SPLIT); | 1471 sub_subsize = get_subsize(subsize, PARTITION_SPLIT); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1583 last_part_rate = INT_MAX; | 1578 last_part_rate = INT_MAX; |
| 1584 last_part_dist = INT64_MAX; | 1579 last_part_dist = INT64_MAX; |
| 1585 break; | 1580 break; |
| 1586 } | 1581 } |
| 1587 last_part_rate += rt; | 1582 last_part_rate += rt; |
| 1588 last_part_dist += dt; | 1583 last_part_dist += dt; |
| 1589 } | 1584 } |
| 1590 break; | 1585 break; |
| 1591 default: | 1586 default: |
| 1592 assert(0); | 1587 assert(0); |
| 1588 break; |
| 1593 } | 1589 } |
| 1594 | 1590 |
| 1595 pl = partition_plane_context(xd, mi_row, mi_col, bsize); | 1591 pl = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 1596 if (last_part_rate < INT_MAX) { | 1592 if (last_part_rate < INT_MAX) { |
| 1597 last_part_rate += cpi->partition_cost[pl][partition]; | 1593 last_part_rate += cpi->partition_cost[pl][partition]; |
| 1598 last_part_rd = RDCOST(x->rdmult, x->rddiv, last_part_rate, last_part_dist); | 1594 last_part_rd = RDCOST(x->rdmult, x->rddiv, last_part_rate, last_part_dist); |
| 1599 } | 1595 } |
| 1600 | 1596 |
| 1601 if (do_partition_search | 1597 if (do_partition_search |
| 1602 && cpi->sf.adjust_partitioning_from_last_frame | 1598 && cpi->sf.adjust_partitioning_from_last_frame |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1718 BLOCK_64X64 | 1714 BLOCK_64X64 |
| 1719 }; | 1715 }; |
| 1720 | 1716 |
| 1721 // Look at all the mode_info entries for blocks that are part of this | 1717 // Look at all the mode_info entries for blocks that are part of this |
| 1722 // partition and find the min and max values for sb_type. | 1718 // partition and find the min and max values for sb_type. |
| 1723 // At the moment this is designed to work on a 64x64 SB but could be | 1719 // At the moment this is designed to work on a 64x64 SB but could be |
| 1724 // adjusted to use a size parameter. | 1720 // adjusted to use a size parameter. |
| 1725 // | 1721 // |
| 1726 // The min and max are assumed to have been initialized prior to calling this | 1722 // The min and max are assumed to have been initialized prior to calling this |
| 1727 // function so repeat calls can accumulate a min and max of more than one sb64. | 1723 // function so repeat calls can accumulate a min and max of more than one sb64. |
| 1728 static void get_sb_partition_size_range(VP9_COMP *cpi, MODE_INFO ** mi_8x8, | 1724 static void get_sb_partition_size_range(MACROBLOCKD *xd, MODE_INFO **mi_8x8, |
| 1729 BLOCK_SIZE * min_block_size, | 1725 BLOCK_SIZE *min_block_size, |
| 1730 BLOCK_SIZE * max_block_size ) { | 1726 BLOCK_SIZE *max_block_size ) { |
| 1731 MACROBLOCKD *const xd = &cpi->mb.e_mbd; | |
| 1732 int sb_width_in_blocks = MI_BLOCK_SIZE; | 1727 int sb_width_in_blocks = MI_BLOCK_SIZE; |
| 1733 int sb_height_in_blocks = MI_BLOCK_SIZE; | 1728 int sb_height_in_blocks = MI_BLOCK_SIZE; |
| 1734 int i, j; | 1729 int i, j; |
| 1735 int index = 0; | 1730 int index = 0; |
| 1736 | 1731 |
| 1737 // Check the sb_type for each block that belongs to this region. | 1732 // Check the sb_type for each block that belongs to this region. |
| 1738 for (i = 0; i < sb_height_in_blocks; ++i) { | 1733 for (i = 0; i < sb_height_in_blocks; ++i) { |
| 1739 for (j = 0; j < sb_width_in_blocks; ++j) { | 1734 for (j = 0; j < sb_width_in_blocks; ++j) { |
| 1740 MODE_INFO * mi = mi_8x8[index+j]; | 1735 MODE_INFO * mi = mi_8x8[index+j]; |
| 1741 BLOCK_SIZE sb_type = mi ? mi->mbmi.sb_type : 0; | 1736 BLOCK_SIZE sb_type = mi ? mi->mbmi.sb_type : 0; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1776 // Default "min to max" and "max to min" | 1771 // Default "min to max" and "max to min" |
| 1777 min_size = BLOCK_64X64; | 1772 min_size = BLOCK_64X64; |
| 1778 max_size = BLOCK_4X4; | 1773 max_size = BLOCK_4X4; |
| 1779 | 1774 |
| 1780 // NOTE: each call to get_sb_partition_size_range() uses the previous | 1775 // NOTE: each call to get_sb_partition_size_range() uses the previous |
| 1781 // passed in values for min and max as a starting point. | 1776 // passed in values for min and max as a starting point. |
| 1782 // Find the min and max partition used in previous frame at this location | 1777 // Find the min and max partition used in previous frame at this location |
| 1783 if (cm->frame_type != KEY_FRAME) { | 1778 if (cm->frame_type != KEY_FRAME) { |
| 1784 MODE_INFO **const prev_mi = | 1779 MODE_INFO **const prev_mi = |
| 1785 &cm->prev_mi_grid_visible[mi_row * xd->mi_stride + mi_col]; | 1780 &cm->prev_mi_grid_visible[mi_row * xd->mi_stride + mi_col]; |
| 1786 get_sb_partition_size_range(cpi, prev_mi, &min_size, &max_size); | 1781 get_sb_partition_size_range(xd, prev_mi, &min_size, &max_size); |
| 1787 } | 1782 } |
| 1788 // Find the min and max partition sizes used in the left SB64 | 1783 // Find the min and max partition sizes used in the left SB64 |
| 1789 if (left_in_image) { | 1784 if (left_in_image) { |
| 1790 MODE_INFO **left_sb64_mi = &mi[-MI_BLOCK_SIZE]; | 1785 MODE_INFO **left_sb64_mi = &mi[-MI_BLOCK_SIZE]; |
| 1791 get_sb_partition_size_range(cpi, left_sb64_mi, &min_size, &max_size); | 1786 get_sb_partition_size_range(xd, left_sb64_mi, &min_size, &max_size); |
| 1792 } | 1787 } |
| 1793 // Find the min and max partition sizes used in the above SB64. | 1788 // Find the min and max partition sizes used in the above SB64. |
| 1794 if (above_in_image) { | 1789 if (above_in_image) { |
| 1795 MODE_INFO **above_sb64_mi = &mi[-xd->mi_stride * MI_BLOCK_SIZE]; | 1790 MODE_INFO **above_sb64_mi = &mi[-xd->mi_stride * MI_BLOCK_SIZE]; |
| 1796 get_sb_partition_size_range(cpi, above_sb64_mi, &min_size, &max_size); | 1791 get_sb_partition_size_range(xd, above_sb64_mi, &min_size, &max_size); |
| 1797 } | 1792 } |
| 1798 // adjust observed min and max | 1793 // adjust observed min and max |
| 1799 if (cpi->sf.auto_min_max_partition_size == RELAXED_NEIGHBORING_MIN_MAX) { | 1794 if (cpi->sf.auto_min_max_partition_size == RELAXED_NEIGHBORING_MIN_MAX) { |
| 1800 min_size = min_partition_size[min_size]; | 1795 min_size = min_partition_size[min_size]; |
| 1801 max_size = max_partition_size[max_size]; | 1796 max_size = max_partition_size[max_size]; |
| 1802 } | 1797 } |
| 1803 } | 1798 } |
| 1804 | 1799 |
| 1805 // Check border cases where max and min from neighbors may not be legal. | 1800 // Check border cases where max and min from neighbors may not be legal. |
| 1806 max_size = find_partition_size(max_size, | 1801 max_size = find_partition_size(max_size, |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1829 const int left_in_image = xd->left_available && mi_8x8[-1]; | 1824 const int left_in_image = xd->left_available && mi_8x8[-1]; |
| 1830 const int above_in_image = xd->up_available && | 1825 const int above_in_image = xd->up_available && |
| 1831 mi_8x8[-xd->mi_stride]; | 1826 mi_8x8[-xd->mi_stride]; |
| 1832 int row8x8_remaining = tile->mi_row_end - mi_row; | 1827 int row8x8_remaining = tile->mi_row_end - mi_row; |
| 1833 int col8x8_remaining = tile->mi_col_end - mi_col; | 1828 int col8x8_remaining = tile->mi_col_end - mi_col; |
| 1834 int bh, bw; | 1829 int bh, bw; |
| 1835 BLOCK_SIZE min_size = BLOCK_32X32; | 1830 BLOCK_SIZE min_size = BLOCK_32X32; |
| 1836 BLOCK_SIZE max_size = BLOCK_8X8; | 1831 BLOCK_SIZE max_size = BLOCK_8X8; |
| 1837 int bsl = mi_width_log2(BLOCK_64X64); | 1832 int bsl = mi_width_log2(BLOCK_64X64); |
| 1838 const int search_range_ctrl = (((mi_row + mi_col) >> bsl) + | 1833 const int search_range_ctrl = (((mi_row + mi_col) >> bsl) + |
| 1839 get_chessboard_index(cm)) % 2; | 1834 get_chessboard_index(cm->current_video_frame)) & 0x1; |
| 1840 // Trap case where we do not have a prediction. | 1835 // Trap case where we do not have a prediction. |
| 1841 if (search_range_ctrl && | 1836 if (search_range_ctrl && |
| 1842 (left_in_image || above_in_image || cm->frame_type != KEY_FRAME)) { | 1837 (left_in_image || above_in_image || cm->frame_type != KEY_FRAME)) { |
| 1843 int block; | 1838 int block; |
| 1844 MODE_INFO **mi; | 1839 MODE_INFO **mi; |
| 1845 BLOCK_SIZE sb_type; | 1840 BLOCK_SIZE sb_type; |
| 1846 | 1841 |
| 1847 // Find the min and max partition sizes used in the left SB64. | 1842 // Find the min and max partition sizes used in the left SB64. |
| 1848 if (left_in_image) { | 1843 if (left_in_image) { |
| 1849 MODE_INFO *cur_mi; | 1844 MODE_INFO *cur_mi; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1873 max_size = MIN(max_size, BLOCK_32X32); | 1868 max_size = MIN(max_size, BLOCK_32X32); |
| 1874 } else { | 1869 } else { |
| 1875 min_size = BLOCK_8X8; | 1870 min_size = BLOCK_8X8; |
| 1876 max_size = BLOCK_32X32; | 1871 max_size = BLOCK_32X32; |
| 1877 } | 1872 } |
| 1878 | 1873 |
| 1879 *min_block_size = min_size; | 1874 *min_block_size = min_size; |
| 1880 *max_block_size = max_size; | 1875 *max_block_size = max_size; |
| 1881 } | 1876 } |
| 1882 | 1877 |
| 1878 // TODO(jingning) refactor functions setting partition search range |
| 1879 static void set_partition_range(VP9_COMMON *cm, MACROBLOCKD *xd, |
| 1880 int mi_row, int mi_col, BLOCK_SIZE bsize, |
| 1881 BLOCK_SIZE *min_bs, BLOCK_SIZE *max_bs) { |
| 1882 int mi_width = num_8x8_blocks_wide_lookup[bsize]; |
| 1883 int mi_height = num_8x8_blocks_high_lookup[bsize]; |
| 1884 int idx, idy; |
| 1885 |
| 1886 MODE_INFO *mi; |
| 1887 MODE_INFO **prev_mi = |
| 1888 &cm->prev_mi_grid_visible[mi_row * cm->mi_stride + mi_col]; |
| 1889 BLOCK_SIZE bs, min_size, max_size; |
| 1890 |
| 1891 min_size = BLOCK_64X64; |
| 1892 max_size = BLOCK_4X4; |
| 1893 |
| 1894 if (prev_mi) { |
| 1895 for (idy = 0; idy < mi_height; ++idy) { |
| 1896 for (idx = 0; idx < mi_width; ++idx) { |
| 1897 mi = prev_mi[idy * cm->mi_stride + idx]; |
| 1898 bs = mi ? mi->mbmi.sb_type : bsize; |
| 1899 min_size = MIN(min_size, bs); |
| 1900 max_size = MAX(max_size, bs); |
| 1901 } |
| 1902 } |
| 1903 } |
| 1904 |
| 1905 if (xd->left_available) { |
| 1906 for (idy = 0; idy < mi_height; ++idy) { |
| 1907 mi = xd->mi[idy * cm->mi_stride - 1]; |
| 1908 bs = mi ? mi->mbmi.sb_type : bsize; |
| 1909 min_size = MIN(min_size, bs); |
| 1910 max_size = MAX(max_size, bs); |
| 1911 } |
| 1912 } |
| 1913 |
| 1914 if (xd->up_available) { |
| 1915 for (idx = 0; idx < mi_width; ++idx) { |
| 1916 mi = xd->mi[idx - cm->mi_stride]; |
| 1917 bs = mi ? mi->mbmi.sb_type : bsize; |
| 1918 min_size = MIN(min_size, bs); |
| 1919 max_size = MAX(max_size, bs); |
| 1920 } |
| 1921 } |
| 1922 |
| 1923 if (min_size == max_size) { |
| 1924 min_size = min_partition_size[min_size]; |
| 1925 max_size = max_partition_size[max_size]; |
| 1926 } |
| 1927 |
| 1928 *min_bs = min_size; |
| 1929 *max_bs = max_size; |
| 1930 } |
| 1931 |
| 1883 static INLINE void store_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) { | 1932 static INLINE void store_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) { |
| 1884 vpx_memcpy(ctx->pred_mv, x->pred_mv, sizeof(x->pred_mv)); | 1933 vpx_memcpy(ctx->pred_mv, x->pred_mv, sizeof(x->pred_mv)); |
| 1885 } | 1934 } |
| 1886 | 1935 |
| 1887 static INLINE void load_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) { | 1936 static INLINE void load_pred_mv(MACROBLOCK *x, PICK_MODE_CONTEXT *ctx) { |
| 1888 vpx_memcpy(x->pred_mv, ctx->pred_mv, sizeof(x->pred_mv)); | 1937 vpx_memcpy(x->pred_mv, ctx->pred_mv, sizeof(x->pred_mv)); |
| 1889 } | 1938 } |
| 1890 | 1939 |
| 1940 #if CONFIG_FP_MB_STATS |
| 1941 const int num_16x16_blocks_wide_lookup[BLOCK_SIZES] = |
| 1942 {1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 4, 4}; |
| 1943 const int num_16x16_blocks_high_lookup[BLOCK_SIZES] = |
| 1944 {1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 4, 2, 4}; |
| 1945 const int qindex_skip_threshold_lookup[BLOCK_SIZES] = |
| 1946 {0, 10, 10, 30, 40, 40, 60, 80, 80, 90, 100, 100, 120}; |
| 1947 const int qindex_split_threshold_lookup[BLOCK_SIZES] = |
| 1948 {0, 3, 3, 7, 15, 15, 30, 40, 40, 60, 80, 80, 120}; |
| 1949 const int complexity_16x16_blocks_threshold[BLOCK_SIZES] = |
| 1950 {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 4, 6}; |
| 1951 |
| 1952 typedef enum { |
| 1953 MV_ZERO = 0, |
| 1954 MV_LEFT = 1, |
| 1955 MV_UP = 2, |
| 1956 MV_RIGHT = 3, |
| 1957 MV_DOWN = 4, |
| 1958 MV_INVALID |
| 1959 } MOTION_DIRECTION; |
| 1960 |
| 1961 static INLINE MOTION_DIRECTION get_motion_direction_fp(uint8_t fp_byte) { |
| 1962 if (fp_byte & FPMB_MOTION_ZERO_MASK) { |
| 1963 return MV_ZERO; |
| 1964 } else if (fp_byte & FPMB_MOTION_LEFT_MASK) { |
| 1965 return MV_LEFT; |
| 1966 } else if (fp_byte & FPMB_MOTION_RIGHT_MASK) { |
| 1967 return MV_RIGHT; |
| 1968 } else if (fp_byte & FPMB_MOTION_UP_MASK) { |
| 1969 return MV_UP; |
| 1970 } else { |
| 1971 return MV_DOWN; |
| 1972 } |
| 1973 } |
| 1974 |
| 1975 static INLINE int get_motion_inconsistency(MOTION_DIRECTION this_mv, |
| 1976 MOTION_DIRECTION that_mv) { |
| 1977 if (this_mv == that_mv) { |
| 1978 return 0; |
| 1979 } else { |
| 1980 return abs(this_mv - that_mv) == 2 ? 2 : 1; |
| 1981 } |
| 1982 } |
| 1983 #endif |
| 1984 |
| 1891 // TODO(jingning,jimbankoski,rbultje): properly skip partition types that are | 1985 // TODO(jingning,jimbankoski,rbultje): properly skip partition types that are |
| 1892 // unlikely to be selected depending on previous rate-distortion optimization | 1986 // unlikely to be selected depending on previous rate-distortion optimization |
| 1893 // results, for encoding speed-up. | 1987 // results, for encoding speed-up. |
| 1894 static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, | 1988 static void rd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, |
| 1895 TOKENEXTRA **tp, int mi_row, | 1989 TOKENEXTRA **tp, int mi_row, |
| 1896 int mi_col, BLOCK_SIZE bsize, int *rate, | 1990 int mi_col, BLOCK_SIZE bsize, int *rate, |
| 1897 int64_t *dist, int do_recon, int64_t best_rd, | 1991 int64_t *dist, int64_t best_rd, |
| 1898 PC_TREE *pc_tree) { | 1992 PC_TREE *pc_tree) { |
| 1899 VP9_COMMON *const cm = &cpi->common; | 1993 VP9_COMMON *const cm = &cpi->common; |
| 1900 MACROBLOCK *const x = &cpi->mb; | 1994 MACROBLOCK *const x = &cpi->mb; |
| 1901 MACROBLOCKD *const xd = &x->e_mbd; | 1995 MACROBLOCKD *const xd = &x->e_mbd; |
| 1902 const int mi_step = num_8x8_blocks_wide_lookup[bsize] / 2; | 1996 const int mi_step = num_8x8_blocks_wide_lookup[bsize] / 2; |
| 1903 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; | 1997 ENTROPY_CONTEXT l[16 * MAX_MB_PLANE], a[16 * MAX_MB_PLANE]; |
| 1904 PARTITION_CONTEXT sl[8], sa[8]; | 1998 PARTITION_CONTEXT sl[8], sa[8]; |
| 1905 TOKENEXTRA *tp_orig = *tp; | 1999 TOKENEXTRA *tp_orig = *tp; |
| 1906 PICK_MODE_CONTEXT *ctx = &pc_tree->none; | 2000 PICK_MODE_CONTEXT *ctx = &pc_tree->none; |
| 1907 int i, pl; | 2001 int i, pl; |
| 1908 BLOCK_SIZE subsize; | 2002 BLOCK_SIZE subsize; |
| 1909 int this_rate, sum_rate = 0, best_rate = INT_MAX; | 2003 int this_rate, sum_rate = 0, best_rate = INT_MAX; |
| 1910 int64_t this_dist, sum_dist = 0, best_dist = INT64_MAX; | 2004 int64_t this_dist, sum_dist = 0, best_dist = INT64_MAX; |
| 1911 int64_t sum_rd = 0; | 2005 int64_t sum_rd = 0; |
| 1912 int do_split = bsize >= BLOCK_8X8; | 2006 int do_split = bsize >= BLOCK_8X8; |
| 1913 int do_rect = 1; | 2007 int do_rect = 1; |
| 2008 |
| 1914 // Override skipping rectangular partition operations for edge blocks | 2009 // Override skipping rectangular partition operations for edge blocks |
| 1915 const int force_horz_split = (mi_row + mi_step >= cm->mi_rows); | 2010 const int force_horz_split = (mi_row + mi_step >= cm->mi_rows); |
| 1916 const int force_vert_split = (mi_col + mi_step >= cm->mi_cols); | 2011 const int force_vert_split = (mi_col + mi_step >= cm->mi_cols); |
| 1917 const int xss = x->e_mbd.plane[1].subsampling_x; | 2012 const int xss = x->e_mbd.plane[1].subsampling_x; |
| 1918 const int yss = x->e_mbd.plane[1].subsampling_y; | 2013 const int yss = x->e_mbd.plane[1].subsampling_y; |
| 1919 | 2014 |
| 2015 BLOCK_SIZE min_size = cpi->sf.min_partition_size; |
| 2016 BLOCK_SIZE max_size = cpi->sf.max_partition_size; |
| 2017 |
| 2018 #if CONFIG_FP_MB_STATS |
| 2019 unsigned int src_diff_var = UINT_MAX; |
| 2020 int none_complexity = 0; |
| 2021 #endif |
| 2022 |
| 1920 int partition_none_allowed = !force_horz_split && !force_vert_split; | 2023 int partition_none_allowed = !force_horz_split && !force_vert_split; |
| 1921 int partition_horz_allowed = !force_vert_split && yss <= xss && | 2024 int partition_horz_allowed = !force_vert_split && yss <= xss && |
| 1922 bsize >= BLOCK_8X8; | 2025 bsize >= BLOCK_8X8; |
| 1923 int partition_vert_allowed = !force_horz_split && xss <= yss && | 2026 int partition_vert_allowed = !force_horz_split && xss <= yss && |
| 1924 bsize >= BLOCK_8X8; | 2027 bsize >= BLOCK_8X8; |
| 1925 (void) *tp_orig; | 2028 (void) *tp_orig; |
| 1926 | 2029 |
| 1927 assert(num_8x8_blocks_wide_lookup[bsize] == | 2030 assert(num_8x8_blocks_wide_lookup[bsize] == |
| 1928 num_8x8_blocks_high_lookup[bsize]); | 2031 num_8x8_blocks_high_lookup[bsize]); |
| 1929 | 2032 |
| 1930 if (bsize == BLOCK_16X16) { | 2033 set_offsets(cpi, tile, mi_row, mi_col, bsize); |
| 1931 set_offsets(cpi, tile, mi_row, mi_col, bsize); | 2034 |
| 2035 if (bsize == BLOCK_16X16 && cpi->oxcf.aq_mode) |
| 1932 x->mb_energy = vp9_block_energy(cpi, x, bsize); | 2036 x->mb_energy = vp9_block_energy(cpi, x, bsize); |
| 2037 |
| 2038 if (cpi->sf.cb_partition_search && bsize == BLOCK_16X16) { |
| 2039 int cb_partition_search_ctrl = ((pc_tree->index == 0 || pc_tree->index == 3) |
| 2040 + get_chessboard_index(cm->current_video_frame)) & 0x1; |
| 2041 |
| 2042 if (cb_partition_search_ctrl && bsize > min_size && bsize < max_size) |
| 2043 set_partition_range(cm, xd, mi_row, mi_col, bsize, &min_size, &max_size); |
| 1933 } | 2044 } |
| 2045 |
| 1934 // Determine partition types in search according to the speed features. | 2046 // Determine partition types in search according to the speed features. |
| 1935 // The threshold set here has to be of square block size. | 2047 // The threshold set here has to be of square block size. |
| 1936 if (cpi->sf.auto_min_max_partition_size) { | 2048 if (cpi->sf.auto_min_max_partition_size) { |
| 1937 partition_none_allowed &= (bsize <= cpi->sf.max_partition_size && | 2049 partition_none_allowed &= (bsize <= max_size && bsize >= min_size); |
| 1938 bsize >= cpi->sf.min_partition_size); | 2050 partition_horz_allowed &= ((bsize <= max_size && bsize > min_size) || |
| 1939 partition_horz_allowed &= ((bsize <= cpi->sf.max_partition_size && | |
| 1940 bsize > cpi->sf.min_partition_size) || | |
| 1941 force_horz_split); | 2051 force_horz_split); |
| 1942 partition_vert_allowed &= ((bsize <= cpi->sf.max_partition_size && | 2052 partition_vert_allowed &= ((bsize <= max_size && bsize > min_size) || |
| 1943 bsize > cpi->sf.min_partition_size) || | |
| 1944 force_vert_split); | 2053 force_vert_split); |
| 1945 do_split &= bsize > cpi->sf.min_partition_size; | 2054 do_split &= bsize > min_size; |
| 1946 } | 2055 } |
| 1947 if (cpi->sf.use_square_partition_only) { | 2056 if (cpi->sf.use_square_partition_only) { |
| 1948 partition_horz_allowed &= force_horz_split; | 2057 partition_horz_allowed &= force_horz_split; |
| 1949 partition_vert_allowed &= force_vert_split; | 2058 partition_vert_allowed &= force_vert_split; |
| 1950 } | 2059 } |
| 1951 | 2060 |
| 1952 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 2061 save_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
| 1953 | 2062 |
| 1954 if (cpi->sf.disable_split_var_thresh && partition_none_allowed) { | 2063 #if CONFIG_FP_MB_STATS |
| 1955 unsigned int source_variancey; | 2064 if (cpi->use_fp_mb_stats) { |
| 1956 vp9_setup_src_planes(x, cpi->Source, mi_row, mi_col); | 2065 set_offsets(cpi, tile, mi_row, mi_col, bsize); |
| 1957 source_variancey = get_sby_perpixel_variance(cpi, &x->plane[0].src, bsize); | 2066 src_diff_var = get_sby_perpixel_diff_variance(cpi, &cpi->mb.plane[0].src, |
| 1958 if (source_variancey < cpi->sf.disable_split_var_thresh) { | 2067 mi_row, mi_col, bsize); |
| 1959 do_split = 0; | 2068 } |
| 1960 if (source_variancey < cpi->sf.disable_split_var_thresh / 2) | 2069 #endif |
| 1961 do_rect = 0; | 2070 |
| 2071 #if CONFIG_FP_MB_STATS |
| 2072 // Decide whether we shall split directly and skip searching NONE by using |
| 2073 // the first pass block statistics |
| 2074 if (cpi->use_fp_mb_stats && bsize >= BLOCK_32X32 && do_split && |
| 2075 partition_none_allowed && src_diff_var > 4 && |
| 2076 cm->base_qindex < qindex_split_threshold_lookup[bsize]) { |
| 2077 int mb_row = mi_row >> 1; |
| 2078 int mb_col = mi_col >> 1; |
| 2079 int mb_row_end = |
| 2080 MIN(mb_row + num_16x16_blocks_high_lookup[bsize], cm->mb_rows); |
| 2081 int mb_col_end = |
| 2082 MIN(mb_col + num_16x16_blocks_wide_lookup[bsize], cm->mb_cols); |
| 2083 int r, c; |
| 2084 |
| 2085 // compute a complexity measure, basically measure inconsistency of motion |
| 2086 // vectors obtained from the first pass in the current block |
| 2087 for (r = mb_row; r < mb_row_end ; r++) { |
| 2088 for (c = mb_col; c < mb_col_end; c++) { |
| 2089 const int mb_index = r * cm->mb_cols + c; |
| 2090 |
| 2091 MOTION_DIRECTION this_mv; |
| 2092 MOTION_DIRECTION right_mv; |
| 2093 MOTION_DIRECTION bottom_mv; |
| 2094 |
| 2095 this_mv = |
| 2096 get_motion_direction_fp(cpi->twopass.this_frame_mb_stats[mb_index]); |
| 2097 |
| 2098 // to its right |
| 2099 if (c != mb_col_end - 1) { |
| 2100 right_mv = get_motion_direction_fp( |
| 2101 cpi->twopass.this_frame_mb_stats[mb_index + 1]); |
| 2102 none_complexity += get_motion_inconsistency(this_mv, right_mv); |
| 2103 } |
| 2104 |
| 2105 // to its bottom |
| 2106 if (r != mb_row_end - 1) { |
| 2107 bottom_mv = get_motion_direction_fp( |
| 2108 cpi->twopass.this_frame_mb_stats[mb_index + cm->mb_cols]); |
| 2109 none_complexity += get_motion_inconsistency(this_mv, bottom_mv); |
| 2110 } |
| 2111 |
| 2112 // do not count its left and top neighbors to avoid double counting |
| 2113 } |
| 2114 } |
| 2115 |
| 2116 if (none_complexity > complexity_16x16_blocks_threshold[bsize]) { |
| 2117 partition_none_allowed = 0; |
| 1962 } | 2118 } |
| 1963 } | 2119 } |
| 2120 #endif |
| 1964 | 2121 |
| 1965 // PARTITION_NONE | 2122 // PARTITION_NONE |
| 1966 if (partition_none_allowed) { | 2123 if (partition_none_allowed) { |
| 1967 rd_pick_sb_modes(cpi, tile, mi_row, mi_col, &this_rate, &this_dist, bsize, | 2124 rd_pick_sb_modes(cpi, tile, mi_row, mi_col, &this_rate, &this_dist, bsize, |
| 1968 ctx, best_rd, 0); | 2125 ctx, best_rd, 0); |
| 1969 if (this_rate != INT_MAX) { | 2126 if (this_rate != INT_MAX) { |
| 1970 if (bsize >= BLOCK_8X8) { | 2127 if (bsize >= BLOCK_8X8) { |
| 1971 pl = partition_plane_context(xd, mi_row, mi_col, bsize); | 2128 pl = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 1972 this_rate += cpi->partition_cost[pl][PARTITION_NONE]; | 2129 this_rate += cpi->partition_cost[pl][PARTITION_NONE]; |
| 1973 } | 2130 } |
| 1974 sum_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_dist); | 2131 sum_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_dist); |
| 2132 |
| 1975 if (sum_rd < best_rd) { | 2133 if (sum_rd < best_rd) { |
| 1976 int64_t stop_thresh = 4096; | 2134 int64_t stop_thresh = 4096; |
| 1977 int64_t stop_thresh_rd; | 2135 int64_t stop_thresh_rd; |
| 1978 | 2136 |
| 1979 best_rate = this_rate; | 2137 best_rate = this_rate; |
| 1980 best_dist = this_dist; | 2138 best_dist = this_dist; |
| 1981 best_rd = sum_rd; | 2139 best_rd = sum_rd; |
| 1982 if (bsize >= BLOCK_8X8) | 2140 if (bsize >= BLOCK_8X8) |
| 1983 pc_tree->partitioning = PARTITION_NONE; | 2141 pc_tree->partitioning = PARTITION_NONE; |
| 1984 | 2142 |
| 1985 // Adjust threshold according to partition size. | 2143 // Adjust threshold according to partition size. |
| 1986 stop_thresh >>= 8 - (b_width_log2(bsize) + | 2144 stop_thresh >>= 8 - (b_width_log2(bsize) + |
| 1987 b_height_log2(bsize)); | 2145 b_height_log2(bsize)); |
| 1988 | 2146 |
| 1989 stop_thresh_rd = RDCOST(x->rdmult, x->rddiv, 0, stop_thresh); | 2147 stop_thresh_rd = RDCOST(x->rdmult, x->rddiv, 0, stop_thresh); |
| 1990 // If obtained distortion is very small, choose current partition | 2148 // If obtained distortion is very small, choose current partition |
| 1991 // and stop splitting. | 2149 // and stop splitting. |
| 1992 if (!x->e_mbd.lossless && best_rd < stop_thresh_rd) { | 2150 if (!x->e_mbd.lossless && best_rd < stop_thresh_rd) { |
| 1993 do_split = 0; | 2151 do_split = 0; |
| 1994 do_rect = 0; | 2152 do_rect = 0; |
| 1995 } | 2153 } |
| 2154 |
| 2155 #if CONFIG_FP_MB_STATS |
| 2156 // Check if every 16x16 first pass block statistics has zero |
| 2157 // motion and the corresponding first pass residue is small enough. |
| 2158 // If that is the case, check the difference variance between the |
| 2159 // current frame and the last frame. If the variance is small enough, |
| 2160 // stop further splitting in RD optimization |
| 2161 if (cpi->use_fp_mb_stats && do_split != 0 && |
| 2162 cm->base_qindex > qindex_skip_threshold_lookup[bsize]) { |
| 2163 int mb_row = mi_row >> 1; |
| 2164 int mb_col = mi_col >> 1; |
| 2165 int mb_row_end = |
| 2166 MIN(mb_row + num_16x16_blocks_high_lookup[bsize], cm->mb_rows); |
| 2167 int mb_col_end = |
| 2168 MIN(mb_col + num_16x16_blocks_wide_lookup[bsize], cm->mb_cols); |
| 2169 int r, c; |
| 2170 |
| 2171 int skip = 1; |
| 2172 for (r = mb_row; r < mb_row_end; r++) { |
| 2173 for (c = mb_col; c < mb_col_end; c++) { |
| 2174 const int mb_index = r * cm->mb_cols + c; |
| 2175 if (!(cpi->twopass.this_frame_mb_stats[mb_index] & |
| 2176 FPMB_MOTION_ZERO_MASK) || |
| 2177 !(cpi->twopass.this_frame_mb_stats[mb_index] & |
| 2178 FPMB_ERROR_SMALL_MASK)) { |
| 2179 skip = 0; |
| 2180 break; |
| 2181 } |
| 2182 } |
| 2183 if (skip == 0) { |
| 2184 break; |
| 2185 } |
| 2186 } |
| 2187 if (skip) { |
| 2188 if (src_diff_var == UINT_MAX) { |
| 2189 set_offsets(cpi, tile, mi_row, mi_col, bsize); |
| 2190 src_diff_var = get_sby_perpixel_diff_variance( |
| 2191 cpi, &cpi->mb.plane[0].src, mi_row, mi_col, bsize); |
| 2192 } |
| 2193 if (src_diff_var < 8) { |
| 2194 do_split = 0; |
| 2195 do_rect = 0; |
| 2196 } |
| 2197 } |
| 2198 } |
| 2199 #endif |
| 1996 } | 2200 } |
| 1997 } | 2201 } |
| 1998 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 2202 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
| 1999 } | 2203 } |
| 2000 | 2204 |
| 2001 // store estimated motion vector | 2205 // store estimated motion vector |
| 2002 if (cpi->sf.adaptive_motion_search) | 2206 if (cpi->sf.adaptive_motion_search) |
| 2003 store_pred_mv(x, ctx); | 2207 store_pred_mv(x, ctx); |
| 2004 | 2208 |
| 2005 // PARTITION_SPLIT | 2209 // PARTITION_SPLIT |
| 2006 sum_rd = 0; | 2210 sum_rd = 0; |
| 2007 // TODO(jingning): use the motion vectors given by the above search as | 2211 // TODO(jingning): use the motion vectors given by the above search as |
| 2008 // the starting point of motion search in the following partition type check. | 2212 // the starting point of motion search in the following partition type check. |
| 2009 if (do_split) { | 2213 if (do_split) { |
| 2010 subsize = get_subsize(bsize, PARTITION_SPLIT); | 2214 subsize = get_subsize(bsize, PARTITION_SPLIT); |
| 2011 if (bsize == BLOCK_8X8) { | 2215 if (bsize == BLOCK_8X8) { |
| 2012 i = 4; | 2216 i = 4; |
| 2013 if (cpi->sf.adaptive_pred_interp_filter && partition_none_allowed) | 2217 if (cpi->sf.adaptive_pred_interp_filter && partition_none_allowed) |
| 2014 pc_tree->leaf_split[0]->pred_interp_filter = | 2218 pc_tree->leaf_split[0]->pred_interp_filter = |
| 2015 ctx->mic.mbmi.interp_filter; | 2219 ctx->mic.mbmi.interp_filter; |
| 2016 rd_pick_sb_modes(cpi, tile, mi_row, mi_col, &sum_rate, &sum_dist, subsize, | 2220 rd_pick_sb_modes(cpi, tile, mi_row, mi_col, &sum_rate, &sum_dist, subsize, |
| 2017 pc_tree->leaf_split[0], best_rd, 0); | 2221 pc_tree->leaf_split[0], best_rd, 0); |
| 2018 if (sum_rate == INT_MAX) { | 2222 if (sum_rate == INT_MAX) |
| 2019 sum_rd = INT64_MAX; | 2223 sum_rd = INT64_MAX; |
| 2020 } else { | 2224 else |
| 2021 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 2225 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
| 2022 if (sum_rd < best_rd) { | |
| 2023 update_state(cpi, pc_tree->leaf_split[0], mi_row, mi_col, subsize, 0); | |
| 2024 encode_superblock(cpi, tp, 0, mi_row, mi_col, subsize, | |
| 2025 pc_tree->leaf_split[0]); | |
| 2026 update_partition_context(xd, mi_row, mi_col, subsize, bsize); | |
| 2027 } | |
| 2028 } | |
| 2029 } else { | 2226 } else { |
| 2030 for (i = 0; i < 4 && sum_rd < best_rd; ++i) { | 2227 for (i = 0; i < 4 && sum_rd < best_rd; ++i) { |
| 2031 const int x_idx = (i & 1) * mi_step; | 2228 const int x_idx = (i & 1) * mi_step; |
| 2032 const int y_idx = (i >> 1) * mi_step; | 2229 const int y_idx = (i >> 1) * mi_step; |
| 2033 | 2230 |
| 2034 if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) | 2231 if (mi_row + y_idx >= cm->mi_rows || mi_col + x_idx >= cm->mi_cols) |
| 2035 continue; | 2232 continue; |
| 2036 | 2233 |
| 2037 if (cpi->sf.adaptive_motion_search) | 2234 if (cpi->sf.adaptive_motion_search) |
| 2038 load_pred_mv(x, ctx); | 2235 load_pred_mv(x, ctx); |
| 2039 | 2236 |
| 2237 pc_tree->split[i]->index = i; |
| 2040 rd_pick_partition(cpi, tile, tp, mi_row + y_idx, mi_col + x_idx, | 2238 rd_pick_partition(cpi, tile, tp, mi_row + y_idx, mi_col + x_idx, |
| 2041 subsize, &this_rate, &this_dist, i != 3, | 2239 subsize, &this_rate, &this_dist, |
| 2042 best_rd - sum_rd, pc_tree->split[i]); | 2240 best_rd - sum_rd, pc_tree->split[i]); |
| 2043 | 2241 |
| 2044 if (this_rate == INT_MAX) { | 2242 if (this_rate == INT_MAX) { |
| 2045 sum_rd = INT64_MAX; | 2243 sum_rd = INT64_MAX; |
| 2046 } else { | 2244 } else { |
| 2047 sum_rate += this_rate; | 2245 sum_rate += this_rate; |
| 2048 sum_dist += this_dist; | 2246 sum_dist += this_dist; |
| 2049 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 2247 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
| 2050 } | 2248 } |
| 2051 } | 2249 } |
| 2052 } | 2250 } |
| 2053 | 2251 |
| 2054 if (sum_rd < best_rd && i == 4) { | 2252 if (sum_rd < best_rd && i == 4) { |
| 2055 pl = partition_plane_context(xd, mi_row, mi_col, bsize); | 2253 pl = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 2056 sum_rate += cpi->partition_cost[pl][PARTITION_SPLIT]; | 2254 sum_rate += cpi->partition_cost[pl][PARTITION_SPLIT]; |
| 2057 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 2255 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
| 2256 |
| 2058 if (sum_rd < best_rd) { | 2257 if (sum_rd < best_rd) { |
| 2059 best_rate = sum_rate; | 2258 best_rate = sum_rate; |
| 2060 best_dist = sum_dist; | 2259 best_dist = sum_dist; |
| 2061 best_rd = sum_rd; | 2260 best_rd = sum_rd; |
| 2062 pc_tree->partitioning = PARTITION_SPLIT; | 2261 pc_tree->partitioning = PARTITION_SPLIT; |
| 2063 } | 2262 } |
| 2064 } else { | 2263 } else { |
| 2065 // skip rectangular partition test when larger block size | 2264 // skip rectangular partition test when larger block size |
| 2066 // gives better rd cost | 2265 // gives better rd cost |
| 2067 if (cpi->sf.less_rectangular_check) | 2266 if (cpi->sf.less_rectangular_check) |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2160 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 2359 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
| 2161 if (sum_rd < best_rd) { | 2360 if (sum_rd < best_rd) { |
| 2162 best_rate = sum_rate; | 2361 best_rate = sum_rate; |
| 2163 best_dist = sum_dist; | 2362 best_dist = sum_dist; |
| 2164 best_rd = sum_rd; | 2363 best_rd = sum_rd; |
| 2165 pc_tree->partitioning = PARTITION_VERT; | 2364 pc_tree->partitioning = PARTITION_VERT; |
| 2166 } | 2365 } |
| 2167 } | 2366 } |
| 2168 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); | 2367 restore_context(cpi, mi_row, mi_col, a, l, sa, sl, bsize); |
| 2169 } | 2368 } |
| 2369 |
| 2170 // TODO(jbb): This code added so that we avoid static analysis | 2370 // TODO(jbb): This code added so that we avoid static analysis |
| 2171 // warning related to the fact that best_rd isn't used after this | 2371 // warning related to the fact that best_rd isn't used after this |
| 2172 // point. This code should be refactored so that the duplicate | 2372 // point. This code should be refactored so that the duplicate |
| 2173 // checks occur in some sub function and thus are used... | 2373 // checks occur in some sub function and thus are used... |
| 2174 (void) best_rd; | 2374 (void) best_rd; |
| 2175 *rate = best_rate; | 2375 *rate = best_rate; |
| 2176 *dist = best_dist; | 2376 *dist = best_dist; |
| 2177 | 2377 |
| 2178 if (best_rate < INT_MAX && best_dist < INT64_MAX && do_recon) { | 2378 if (best_rate < INT_MAX && best_dist < INT64_MAX && pc_tree->index != 3) { |
| 2179 int output_enabled = (bsize == BLOCK_64X64); | 2379 int output_enabled = (bsize == BLOCK_64X64); |
| 2180 | 2380 |
| 2181 // Check the projected output rate for this SB against it's target | 2381 // Check the projected output rate for this SB against it's target |
| 2182 // and and if necessary apply a Q delta using segmentation to get | 2382 // and and if necessary apply a Q delta using segmentation to get |
| 2183 // closer to the target. | 2383 // closer to the target. |
| 2184 if ((cpi->oxcf.aq_mode == COMPLEXITY_AQ) && cm->seg.update_map) | 2384 if ((cpi->oxcf.aq_mode == COMPLEXITY_AQ) && cm->seg.update_map) |
| 2185 vp9_select_in_frame_q_segment(cpi, mi_row, mi_col, output_enabled, | 2385 vp9_select_in_frame_q_segment(cpi, mi_row, mi_col, output_enabled, |
| 2186 best_rate); | 2386 best_rate); |
| 2187 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) | 2387 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) |
| 2188 vp9_cyclic_refresh_set_rate_and_dist_sb(cpi->cyclic_refresh, | 2388 vp9_cyclic_refresh_set_rate_and_dist_sb(cpi->cyclic_refresh, |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2225 | 2425 |
| 2226 for (i = 0; i < 64; ++i) { | 2426 for (i = 0; i < 64; ++i) { |
| 2227 cpi->pc_tree[i].vertical[0].pred_interp_filter = SWITCHABLE; | 2427 cpi->pc_tree[i].vertical[0].pred_interp_filter = SWITCHABLE; |
| 2228 cpi->pc_tree[i].vertical[1].pred_interp_filter = SWITCHABLE; | 2428 cpi->pc_tree[i].vertical[1].pred_interp_filter = SWITCHABLE; |
| 2229 cpi->pc_tree[i].horizontal[0].pred_interp_filter = SWITCHABLE; | 2429 cpi->pc_tree[i].horizontal[0].pred_interp_filter = SWITCHABLE; |
| 2230 cpi->pc_tree[i].horizontal[1].pred_interp_filter = SWITCHABLE; | 2430 cpi->pc_tree[i].horizontal[1].pred_interp_filter = SWITCHABLE; |
| 2231 } | 2431 } |
| 2232 } | 2432 } |
| 2233 | 2433 |
| 2234 vp9_zero(cpi->mb.pred_mv); | 2434 vp9_zero(cpi->mb.pred_mv); |
| 2435 cpi->pc_root->index = 0; |
| 2235 | 2436 |
| 2236 if ((sf->partition_search_type == SEARCH_PARTITION && | 2437 if ((sf->partition_search_type == SEARCH_PARTITION && |
| 2237 sf->use_lastframe_partitioning) || | 2438 sf->use_lastframe_partitioning) || |
| 2238 sf->partition_search_type == FIXED_PARTITION || | 2439 sf->partition_search_type == FIXED_PARTITION || |
| 2239 sf->partition_search_type == VAR_BASED_PARTITION || | 2440 sf->partition_search_type == VAR_BASED_PARTITION || |
| 2240 sf->partition_search_type == VAR_BASED_FIXED_PARTITION) { | 2441 sf->partition_search_type == VAR_BASED_FIXED_PARTITION) { |
| 2241 const int idx_str = cm->mi_stride * mi_row + mi_col; | 2442 const int idx_str = cm->mi_stride * mi_row + mi_col; |
| 2242 MODE_INFO **mi = cm->mi_grid_visible + idx_str; | 2443 MODE_INFO **mi = cm->mi_grid_visible + idx_str; |
| 2243 MODE_INFO **prev_mi = cm->prev_mi_grid_visible + idx_str; | 2444 MODE_INFO **prev_mi = cm->prev_mi_grid_visible + idx_str; |
| 2244 cpi->mb.source_variance = UINT_MAX; | 2445 cpi->mb.source_variance = UINT_MAX; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2256 set_fixed_partitioning(cpi, tile, mi, mi_row, mi_col, bsize); | 2457 set_fixed_partitioning(cpi, tile, mi, mi_row, mi_col, bsize); |
| 2257 rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, | 2458 rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, |
| 2258 &dummy_rate, &dummy_dist, 1, cpi->pc_root); | 2459 &dummy_rate, &dummy_dist, 1, cpi->pc_root); |
| 2259 } else if (sf->partition_search_type == VAR_BASED_PARTITION) { | 2460 } else if (sf->partition_search_type == VAR_BASED_PARTITION) { |
| 2260 choose_partitioning(cpi, tile, mi_row, mi_col); | 2461 choose_partitioning(cpi, tile, mi_row, mi_col); |
| 2261 rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, | 2462 rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, |
| 2262 &dummy_rate, &dummy_dist, 1, cpi->pc_root); | 2463 &dummy_rate, &dummy_dist, 1, cpi->pc_root); |
| 2263 } else { | 2464 } else { |
| 2264 GF_GROUP * gf_grp = &cpi->twopass.gf_group; | 2465 GF_GROUP * gf_grp = &cpi->twopass.gf_group; |
| 2265 int last_was_mid_sequence_overlay = 0; | 2466 int last_was_mid_sequence_overlay = 0; |
| 2266 if ((cpi->pass == 2) && (gf_grp->index)) { | 2467 if ((cpi->oxcf.pass == 2) && (gf_grp->index)) { |
| 2267 if (gf_grp->update_type[gf_grp->index - 1] == OVERLAY_UPDATE) | 2468 if (gf_grp->update_type[gf_grp->index - 1] == OVERLAY_UPDATE) |
| 2268 last_was_mid_sequence_overlay = 1; | 2469 last_was_mid_sequence_overlay = 1; |
| 2269 } | 2470 } |
| 2270 if ((cm->current_video_frame | 2471 if ((cpi->rc.frames_since_key |
| 2271 % sf->last_partitioning_redo_frequency) == 0 | 2472 % sf->last_partitioning_redo_frequency) == 0 |
| 2272 || last_was_mid_sequence_overlay | 2473 || last_was_mid_sequence_overlay |
| 2273 || cm->prev_mi == 0 | 2474 || cm->prev_mi == 0 |
| 2274 || cm->show_frame == 0 | 2475 || cm->show_frame == 0 |
| 2275 || cm->frame_type == KEY_FRAME | 2476 || cm->frame_type == KEY_FRAME |
| 2276 || cpi->rc.is_src_frame_alt_ref | 2477 || cpi->rc.is_src_frame_alt_ref |
| 2277 || ((sf->use_lastframe_partitioning == | 2478 || ((sf->use_lastframe_partitioning == |
| 2278 LAST_FRAME_PARTITION_LOW_MOTION) && | 2479 LAST_FRAME_PARTITION_LOW_MOTION) && |
| 2279 sb_has_motion(cm, prev_mi, sf->lf_motion_threshold))) { | 2480 sb_has_motion(cm, prev_mi, sf->lf_motion_threshold))) { |
| 2280 // If required set upper and lower partition size limits | 2481 // If required set upper and lower partition size limits |
| 2281 if (sf->auto_min_max_partition_size) { | 2482 if (sf->auto_min_max_partition_size) { |
| 2282 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); | 2483 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); |
| 2283 rd_auto_partition_range(cpi, tile, mi_row, mi_col, | 2484 rd_auto_partition_range(cpi, tile, mi_row, mi_col, |
| 2284 &sf->min_partition_size, | 2485 &sf->min_partition_size, |
| 2285 &sf->max_partition_size); | 2486 &sf->max_partition_size); |
| 2286 } | 2487 } |
| 2287 rd_pick_partition(cpi, tile, tp, mi_row, mi_col, BLOCK_64X64, | 2488 rd_pick_partition(cpi, tile, tp, mi_row, mi_col, BLOCK_64X64, |
| 2288 &dummy_rate, &dummy_dist, 1, INT64_MAX, | 2489 &dummy_rate, &dummy_dist, INT64_MAX, |
| 2289 cpi->pc_root); | 2490 cpi->pc_root); |
| 2290 } else { | 2491 } else { |
| 2291 if (sf->constrain_copy_partition && | 2492 if (sf->constrain_copy_partition && |
| 2292 sb_has_motion(cm, prev_mi, sf->lf_motion_threshold)) | 2493 sb_has_motion(cm, prev_mi, sf->lf_motion_threshold)) |
| 2293 constrain_copy_partitioning(cpi, tile, mi, prev_mi, | 2494 constrain_copy_partitioning(cpi, tile, mi, prev_mi, |
| 2294 mi_row, mi_col, BLOCK_16X16); | 2495 mi_row, mi_col, BLOCK_16X16); |
| 2295 else | 2496 else |
| 2296 copy_partitioning(cm, mi, prev_mi); | 2497 copy_partitioning(cm, mi, prev_mi); |
| 2297 rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, | 2498 rd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, |
| 2298 &dummy_rate, &dummy_dist, 1, cpi->pc_root); | 2499 &dummy_rate, &dummy_dist, 1, cpi->pc_root); |
| 2299 } | 2500 } |
| 2300 } | 2501 } |
| 2301 } else { | 2502 } else { |
| 2302 // If required set upper and lower partition size limits | 2503 // If required set upper and lower partition size limits |
| 2303 if (sf->auto_min_max_partition_size) { | 2504 if (sf->auto_min_max_partition_size) { |
| 2304 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); | 2505 set_offsets(cpi, tile, mi_row, mi_col, BLOCK_64X64); |
| 2305 rd_auto_partition_range(cpi, tile, mi_row, mi_col, | 2506 rd_auto_partition_range(cpi, tile, mi_row, mi_col, |
| 2306 &sf->min_partition_size, | 2507 &sf->min_partition_size, |
| 2307 &sf->max_partition_size); | 2508 &sf->max_partition_size); |
| 2308 } | 2509 } |
| 2309 rd_pick_partition(cpi, tile, tp, mi_row, mi_col, BLOCK_64X64, | 2510 rd_pick_partition(cpi, tile, tp, mi_row, mi_col, BLOCK_64X64, |
| 2310 &dummy_rate, &dummy_dist, 1, INT64_MAX, cpi->pc_root); | 2511 &dummy_rate, &dummy_dist, INT64_MAX, cpi->pc_root); |
| 2311 } | 2512 } |
| 2312 } | 2513 } |
| 2313 } | 2514 } |
| 2314 | 2515 |
| 2315 static void init_encode_frame_mb_context(VP9_COMP *cpi) { | 2516 static void init_encode_frame_mb_context(VP9_COMP *cpi) { |
| 2316 MACROBLOCK *const x = &cpi->mb; | 2517 MACROBLOCK *const x = &cpi->mb; |
| 2317 VP9_COMMON *const cm = &cpi->common; | 2518 VP9_COMMON *const cm = &cpi->common; |
| 2318 MACROBLOCKD *const xd = &x->e_mbd; | 2519 MACROBLOCKD *const xd = &x->e_mbd; |
| 2319 const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); | 2520 const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); |
| 2320 | 2521 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2361 return INTRA_FRAME; | 2562 return INTRA_FRAME; |
| 2362 else if (cpi->rc.is_src_frame_alt_ref && cpi->refresh_golden_frame) | 2563 else if (cpi->rc.is_src_frame_alt_ref && cpi->refresh_golden_frame) |
| 2363 return ALTREF_FRAME; | 2564 return ALTREF_FRAME; |
| 2364 else if (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) | 2565 else if (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) |
| 2365 return GOLDEN_FRAME; | 2566 return GOLDEN_FRAME; |
| 2366 else | 2567 else |
| 2367 return LAST_FRAME; | 2568 return LAST_FRAME; |
| 2368 } | 2569 } |
| 2369 | 2570 |
| 2370 static TX_MODE select_tx_mode(const VP9_COMP *cpi) { | 2571 static TX_MODE select_tx_mode(const VP9_COMP *cpi) { |
| 2371 if (cpi->mb.e_mbd.lossless) { | 2572 if (cpi->mb.e_mbd.lossless) |
| 2372 return ONLY_4X4; | 2573 return ONLY_4X4; |
| 2373 } else if (cpi->common.current_video_frame == 0) { | 2574 if (cpi->common.frame_type == KEY_FRAME) |
| 2374 return TX_MODE_SELECT; | 2575 return TX_MODE_SELECT; |
| 2375 } else { | 2576 if (cpi->sf.tx_size_search_method == USE_LARGESTALL) |
| 2376 if (cpi->sf.tx_size_search_method == USE_LARGESTALL) { | 2577 return ALLOW_32X32; |
| 2377 return ALLOW_32X32; | 2578 else if (cpi->sf.tx_size_search_method == USE_FULL_RD|| |
| 2378 } else if (cpi->sf.tx_size_search_method == USE_FULL_RD) { | 2579 cpi->sf.tx_size_search_method == USE_TX_8X8) |
| 2379 const RD_OPT *const rd_opt = &cpi->rd; | 2580 return TX_MODE_SELECT; |
| 2380 const MV_REFERENCE_FRAME frame_type = get_frame_type(cpi); | 2581 else |
| 2381 return rd_opt->tx_select_threshes[frame_type][ALLOW_32X32] > | 2582 return cpi->common.tx_mode; |
| 2382 rd_opt->tx_select_threshes[frame_type][TX_MODE_SELECT] ? | |
| 2383 ALLOW_32X32 : TX_MODE_SELECT; | |
| 2384 } else if (cpi->sf.tx_size_search_method == USE_TX_8X8) { | |
| 2385 return TX_MODE_SELECT; | |
| 2386 } else { | |
| 2387 unsigned int total = 0; | |
| 2388 int i; | |
| 2389 for (i = 0; i < TX_SIZES; ++i) | |
| 2390 total += cpi->tx_stepdown_count[i]; | |
| 2391 | |
| 2392 if (total) { | |
| 2393 const double fraction = (double)cpi->tx_stepdown_count[0] / total; | |
| 2394 return fraction > 0.90 ? ALLOW_32X32 : TX_MODE_SELECT; | |
| 2395 } else { | |
| 2396 return cpi->common.tx_mode; | |
| 2397 } | |
| 2398 } | |
| 2399 } | |
| 2400 } | 2583 } |
| 2401 | 2584 |
| 2402 static void nonrd_pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, | 2585 static void nonrd_pick_sb_modes(VP9_COMP *cpi, const TileInfo *const tile, |
| 2403 int mi_row, int mi_col, | 2586 int mi_row, int mi_col, |
| 2404 int *rate, int64_t *dist, | 2587 int *rate, int64_t *dist, |
| 2405 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) { | 2588 BLOCK_SIZE bsize, PICK_MODE_CONTEXT *ctx) { |
| 2406 VP9_COMMON *const cm = &cpi->common; | 2589 VP9_COMMON *const cm = &cpi->common; |
| 2407 MACROBLOCK *const x = &cpi->mb; | 2590 MACROBLOCK *const x = &cpi->mb; |
| 2408 MACROBLOCKD *const xd = &x->e_mbd; | 2591 MACROBLOCKD *const xd = &x->e_mbd; |
| 2409 MB_MODE_INFO *mbmi; | 2592 MB_MODE_INFO *mbmi; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2478 default: | 2661 default: |
| 2479 break; | 2662 break; |
| 2480 } | 2663 } |
| 2481 } | 2664 } |
| 2482 | 2665 |
| 2483 static void nonrd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, | 2666 static void nonrd_pick_partition(VP9_COMP *cpi, const TileInfo *const tile, |
| 2484 TOKENEXTRA **tp, int mi_row, | 2667 TOKENEXTRA **tp, int mi_row, |
| 2485 int mi_col, BLOCK_SIZE bsize, int *rate, | 2668 int mi_col, BLOCK_SIZE bsize, int *rate, |
| 2486 int64_t *dist, int do_recon, int64_t best_rd, | 2669 int64_t *dist, int do_recon, int64_t best_rd, |
| 2487 PC_TREE *pc_tree) { | 2670 PC_TREE *pc_tree) { |
| 2671 const SPEED_FEATURES *const sf = &cpi->sf; |
| 2672 const VP9EncoderConfig *const oxcf = &cpi->oxcf; |
| 2488 VP9_COMMON *const cm = &cpi->common; | 2673 VP9_COMMON *const cm = &cpi->common; |
| 2489 MACROBLOCK *const x = &cpi->mb; | 2674 MACROBLOCK *const x = &cpi->mb; |
| 2490 MACROBLOCKD *const xd = &x->e_mbd; | 2675 MACROBLOCKD *const xd = &x->e_mbd; |
| 2491 const int ms = num_8x8_blocks_wide_lookup[bsize] / 2; | 2676 const int ms = num_8x8_blocks_wide_lookup[bsize] / 2; |
| 2492 TOKENEXTRA *tp_orig = *tp; | 2677 TOKENEXTRA *tp_orig = *tp; |
| 2493 PICK_MODE_CONTEXT *ctx = &pc_tree->none; | 2678 PICK_MODE_CONTEXT *ctx = &pc_tree->none; |
| 2494 int i; | 2679 int i; |
| 2495 BLOCK_SIZE subsize = bsize; | 2680 BLOCK_SIZE subsize = bsize; |
| 2496 int this_rate, sum_rate = 0, best_rate = INT_MAX; | 2681 int this_rate, sum_rate = 0, best_rate = INT_MAX; |
| 2497 int64_t this_dist, sum_dist = 0, best_dist = INT64_MAX; | 2682 int64_t this_dist, sum_dist = 0, best_dist = INT64_MAX; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2509 bsize >= BLOCK_8X8; | 2694 bsize >= BLOCK_8X8; |
| 2510 int partition_vert_allowed = !force_horz_split && xss <= yss && | 2695 int partition_vert_allowed = !force_horz_split && xss <= yss && |
| 2511 bsize >= BLOCK_8X8; | 2696 bsize >= BLOCK_8X8; |
| 2512 (void) *tp_orig; | 2697 (void) *tp_orig; |
| 2513 | 2698 |
| 2514 assert(num_8x8_blocks_wide_lookup[bsize] == | 2699 assert(num_8x8_blocks_wide_lookup[bsize] == |
| 2515 num_8x8_blocks_high_lookup[bsize]); | 2700 num_8x8_blocks_high_lookup[bsize]); |
| 2516 | 2701 |
| 2517 // Determine partition types in search according to the speed features. | 2702 // Determine partition types in search according to the speed features. |
| 2518 // The threshold set here has to be of square block size. | 2703 // The threshold set here has to be of square block size. |
| 2519 if (cpi->sf.auto_min_max_partition_size) { | 2704 if (sf->auto_min_max_partition_size) { |
| 2520 partition_none_allowed &= (bsize <= cpi->sf.max_partition_size && | 2705 partition_none_allowed &= (bsize <= sf->max_partition_size && |
| 2521 bsize >= cpi->sf.min_partition_size); | 2706 bsize >= sf->min_partition_size); |
| 2522 partition_horz_allowed &= ((bsize <= cpi->sf.max_partition_size && | 2707 partition_horz_allowed &= ((bsize <= sf->max_partition_size && |
| 2523 bsize > cpi->sf.min_partition_size) || | 2708 bsize > sf->min_partition_size) || |
| 2524 force_horz_split); | 2709 force_horz_split); |
| 2525 partition_vert_allowed &= ((bsize <= cpi->sf.max_partition_size && | 2710 partition_vert_allowed &= ((bsize <= sf->max_partition_size && |
| 2526 bsize > cpi->sf.min_partition_size) || | 2711 bsize > sf->min_partition_size) || |
| 2527 force_vert_split); | 2712 force_vert_split); |
| 2528 do_split &= bsize > cpi->sf.min_partition_size; | 2713 do_split &= bsize > sf->min_partition_size; |
| 2529 } | 2714 } |
| 2530 if (cpi->sf.use_square_partition_only) { | 2715 if (sf->use_square_partition_only) { |
| 2531 partition_horz_allowed &= force_horz_split; | 2716 partition_horz_allowed &= force_horz_split; |
| 2532 partition_vert_allowed &= force_vert_split; | 2717 partition_vert_allowed &= force_vert_split; |
| 2533 } | 2718 } |
| 2534 | 2719 |
| 2535 // PARTITION_NONE | 2720 // PARTITION_NONE |
| 2536 if (partition_none_allowed) { | 2721 if (partition_none_allowed) { |
| 2537 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, | 2722 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, |
| 2538 &this_rate, &this_dist, bsize, ctx); | 2723 &this_rate, &this_dist, bsize, ctx); |
| 2539 ctx->mic.mbmi = xd->mi[0]->mbmi; | 2724 ctx->mic.mbmi = xd->mi[0]->mbmi; |
| 2540 ctx->skip_txfm = x->skip_txfm; | 2725 ctx->skip_txfm[0] = x->skip_txfm[0]; |
| 2541 ctx->skip = x->skip; | 2726 ctx->skip = x->skip; |
| 2542 | 2727 |
| 2543 if (this_rate != INT_MAX) { | 2728 if (this_rate != INT_MAX) { |
| 2544 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); | 2729 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 2545 this_rate += cpi->partition_cost[pl][PARTITION_NONE]; | 2730 this_rate += cpi->partition_cost[pl][PARTITION_NONE]; |
| 2546 sum_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_dist); | 2731 sum_rd = RDCOST(x->rdmult, x->rddiv, this_rate, this_dist); |
| 2547 if (sum_rd < best_rd) { | 2732 if (sum_rd < best_rd) { |
| 2548 int64_t stop_thresh = 4096; | 2733 int64_t stop_thresh = 4096; |
| 2549 int64_t stop_thresh_rd; | 2734 int64_t stop_thresh_rd; |
| 2550 | 2735 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2599 } | 2784 } |
| 2600 | 2785 |
| 2601 if (sum_rd < best_rd) { | 2786 if (sum_rd < best_rd) { |
| 2602 best_rate = sum_rate; | 2787 best_rate = sum_rate; |
| 2603 best_dist = sum_dist; | 2788 best_dist = sum_dist; |
| 2604 best_rd = sum_rd; | 2789 best_rd = sum_rd; |
| 2605 pc_tree->partitioning = PARTITION_SPLIT; | 2790 pc_tree->partitioning = PARTITION_SPLIT; |
| 2606 } else { | 2791 } else { |
| 2607 // skip rectangular partition test when larger block size | 2792 // skip rectangular partition test when larger block size |
| 2608 // gives better rd cost | 2793 // gives better rd cost |
| 2609 if (cpi->sf.less_rectangular_check) | 2794 if (sf->less_rectangular_check) |
| 2610 do_rect &= !partition_none_allowed; | 2795 do_rect &= !partition_none_allowed; |
| 2611 } | 2796 } |
| 2612 } | 2797 } |
| 2613 | 2798 |
| 2614 // PARTITION_HORZ | 2799 // PARTITION_HORZ |
| 2615 if (partition_horz_allowed && do_rect) { | 2800 if (partition_horz_allowed && do_rect) { |
| 2616 subsize = get_subsize(bsize, PARTITION_HORZ); | 2801 subsize = get_subsize(bsize, PARTITION_HORZ); |
| 2617 if (cpi->sf.adaptive_motion_search) | 2802 if (sf->adaptive_motion_search) |
| 2618 load_pred_mv(x, ctx); | 2803 load_pred_mv(x, ctx); |
| 2619 | 2804 |
| 2620 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, | 2805 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, |
| 2621 &this_rate, &this_dist, subsize, | 2806 &this_rate, &this_dist, subsize, |
| 2622 &pc_tree->horizontal[0]); | 2807 &pc_tree->horizontal[0]); |
| 2623 | 2808 |
| 2624 pc_tree->horizontal[0].mic.mbmi = xd->mi[0]->mbmi; | 2809 pc_tree->horizontal[0].mic.mbmi = xd->mi[0]->mbmi; |
| 2625 pc_tree->horizontal[0].skip_txfm = x->skip_txfm; | 2810 pc_tree->horizontal[0].skip_txfm[0] = x->skip_txfm[0]; |
| 2626 pc_tree->horizontal[0].skip = x->skip; | 2811 pc_tree->horizontal[0].skip = x->skip; |
| 2627 | 2812 |
| 2628 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 2813 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
| 2629 | 2814 |
| 2630 if (sum_rd < best_rd && mi_row + ms < cm->mi_rows) { | 2815 if (sum_rd < best_rd && mi_row + ms < cm->mi_rows) { |
| 2631 load_pred_mv(x, ctx); | 2816 load_pred_mv(x, ctx); |
| 2632 nonrd_pick_sb_modes(cpi, tile, mi_row + ms, mi_col, | 2817 nonrd_pick_sb_modes(cpi, tile, mi_row + ms, mi_col, |
| 2633 &this_rate, &this_dist, subsize, | 2818 &this_rate, &this_dist, subsize, |
| 2634 &pc_tree->horizontal[1]); | 2819 &pc_tree->horizontal[1]); |
| 2635 | 2820 |
| 2636 pc_tree->horizontal[1].mic.mbmi = xd->mi[0]->mbmi; | 2821 pc_tree->horizontal[1].mic.mbmi = xd->mi[0]->mbmi; |
| 2637 pc_tree->horizontal[1].skip_txfm = x->skip_txfm; | 2822 pc_tree->horizontal[1].skip_txfm[0] = x->skip_txfm[0]; |
| 2638 pc_tree->horizontal[1].skip = x->skip; | 2823 pc_tree->horizontal[1].skip = x->skip; |
| 2639 | 2824 |
| 2640 if (this_rate == INT_MAX) { | 2825 if (this_rate == INT_MAX) { |
| 2641 sum_rd = INT64_MAX; | 2826 sum_rd = INT64_MAX; |
| 2642 } else { | 2827 } else { |
| 2643 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); | 2828 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 2644 this_rate += cpi->partition_cost[pl][PARTITION_HORZ]; | 2829 this_rate += cpi->partition_cost[pl][PARTITION_HORZ]; |
| 2645 sum_rate += this_rate; | 2830 sum_rate += this_rate; |
| 2646 sum_dist += this_dist; | 2831 sum_dist += this_dist; |
| 2647 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 2832 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
| 2648 } | 2833 } |
| 2649 } | 2834 } |
| 2650 if (sum_rd < best_rd) { | 2835 if (sum_rd < best_rd) { |
| 2651 best_rd = sum_rd; | 2836 best_rd = sum_rd; |
| 2652 best_rate = sum_rate; | 2837 best_rate = sum_rate; |
| 2653 best_dist = sum_dist; | 2838 best_dist = sum_dist; |
| 2654 pc_tree->partitioning = PARTITION_HORZ; | 2839 pc_tree->partitioning = PARTITION_HORZ; |
| 2655 } | 2840 } |
| 2656 } | 2841 } |
| 2657 | 2842 |
| 2658 // PARTITION_VERT | 2843 // PARTITION_VERT |
| 2659 if (partition_vert_allowed && do_rect) { | 2844 if (partition_vert_allowed && do_rect) { |
| 2660 subsize = get_subsize(bsize, PARTITION_VERT); | 2845 subsize = get_subsize(bsize, PARTITION_VERT); |
| 2661 | 2846 |
| 2662 if (cpi->sf.adaptive_motion_search) | 2847 if (sf->adaptive_motion_search) |
| 2663 load_pred_mv(x, ctx); | 2848 load_pred_mv(x, ctx); |
| 2664 | 2849 |
| 2665 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, | 2850 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, |
| 2666 &this_rate, &this_dist, subsize, | 2851 &this_rate, &this_dist, subsize, |
| 2667 &pc_tree->vertical[0]); | 2852 &pc_tree->vertical[0]); |
| 2668 pc_tree->vertical[0].mic.mbmi = xd->mi[0]->mbmi; | 2853 pc_tree->vertical[0].mic.mbmi = xd->mi[0]->mbmi; |
| 2669 pc_tree->vertical[0].skip_txfm = x->skip_txfm; | 2854 pc_tree->vertical[0].skip_txfm[0] = x->skip_txfm[0]; |
| 2670 pc_tree->vertical[0].skip = x->skip; | 2855 pc_tree->vertical[0].skip = x->skip; |
| 2671 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 2856 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
| 2672 if (sum_rd < best_rd && mi_col + ms < cm->mi_cols) { | 2857 if (sum_rd < best_rd && mi_col + ms < cm->mi_cols) { |
| 2673 load_pred_mv(x, ctx); | 2858 load_pred_mv(x, ctx); |
| 2674 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col + ms, | 2859 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col + ms, |
| 2675 &this_rate, &this_dist, subsize, | 2860 &this_rate, &this_dist, subsize, |
| 2676 &pc_tree->vertical[1]); | 2861 &pc_tree->vertical[1]); |
| 2677 pc_tree->vertical[1].mic.mbmi = xd->mi[0]->mbmi; | 2862 pc_tree->vertical[1].mic.mbmi = xd->mi[0]->mbmi; |
| 2678 pc_tree->vertical[1].skip_txfm = x->skip_txfm; | 2863 pc_tree->vertical[1].skip_txfm[0] = x->skip_txfm[0]; |
| 2679 pc_tree->vertical[1].skip = x->skip; | 2864 pc_tree->vertical[1].skip = x->skip; |
| 2680 if (this_rate == INT_MAX) { | 2865 if (this_rate == INT_MAX) { |
| 2681 sum_rd = INT64_MAX; | 2866 sum_rd = INT64_MAX; |
| 2682 } else { | 2867 } else { |
| 2683 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); | 2868 int pl = partition_plane_context(xd, mi_row, mi_col, bsize); |
| 2684 this_rate += cpi->partition_cost[pl][PARTITION_VERT]; | 2869 this_rate += cpi->partition_cost[pl][PARTITION_VERT]; |
| 2685 sum_rate += this_rate; | 2870 sum_rate += this_rate; |
| 2686 sum_dist += this_dist; | 2871 sum_dist += this_dist; |
| 2687 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); | 2872 sum_rd = RDCOST(x->rdmult, x->rddiv, sum_rate, sum_dist); |
| 2688 } | 2873 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2709 subsize = get_subsize(bsize, pc_tree->partitioning); | 2894 subsize = get_subsize(bsize, pc_tree->partitioning); |
| 2710 fill_mode_info_sb(cm, x, mi_row, mi_col, bsize, subsize, | 2895 fill_mode_info_sb(cm, x, mi_row, mi_col, bsize, subsize, |
| 2711 pc_tree); | 2896 pc_tree); |
| 2712 | 2897 |
| 2713 if (best_rate < INT_MAX && best_dist < INT64_MAX && do_recon) { | 2898 if (best_rate < INT_MAX && best_dist < INT64_MAX && do_recon) { |
| 2714 int output_enabled = (bsize == BLOCK_64X64); | 2899 int output_enabled = (bsize == BLOCK_64X64); |
| 2715 | 2900 |
| 2716 // Check the projected output rate for this SB against it's target | 2901 // Check the projected output rate for this SB against it's target |
| 2717 // and and if necessary apply a Q delta using segmentation to get | 2902 // and and if necessary apply a Q delta using segmentation to get |
| 2718 // closer to the target. | 2903 // closer to the target. |
| 2719 if ((cpi->oxcf.aq_mode == COMPLEXITY_AQ) && cm->seg.update_map) { | 2904 if ((oxcf->aq_mode == COMPLEXITY_AQ) && cm->seg.update_map) { |
| 2720 vp9_select_in_frame_q_segment(cpi, mi_row, mi_col, output_enabled, | 2905 vp9_select_in_frame_q_segment(cpi, mi_row, mi_col, output_enabled, |
| 2721 best_rate); | 2906 best_rate); |
| 2722 } | 2907 } |
| 2723 | 2908 |
| 2724 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) | 2909 if (oxcf->aq_mode == CYCLIC_REFRESH_AQ) |
| 2725 vp9_cyclic_refresh_set_rate_and_dist_sb(cpi->cyclic_refresh, | 2910 vp9_cyclic_refresh_set_rate_and_dist_sb(cpi->cyclic_refresh, |
| 2726 best_rate, best_dist); | 2911 best_rate, best_dist); |
| 2727 | 2912 |
| 2728 encode_sb_rt(cpi, tile, tp, mi_row, mi_col, output_enabled, bsize, pc_tree); | 2913 encode_sb_rt(cpi, tile, tp, mi_row, mi_col, output_enabled, bsize, pc_tree); |
| 2729 } | 2914 } |
| 2730 | 2915 |
| 2731 if (bsize == BLOCK_64X64) { | 2916 if (bsize == BLOCK_64X64) { |
| 2732 assert(tp_orig < *tp); | 2917 assert(tp_orig < *tp); |
| 2733 assert(best_rate < INT_MAX); | 2918 assert(best_rate < INT_MAX); |
| 2734 assert(best_dist < INT64_MAX); | 2919 assert(best_dist < INT64_MAX); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2759 return; | 2944 return; |
| 2760 | 2945 |
| 2761 subsize = (bsize >= BLOCK_8X8) ? mi[0]->mbmi.sb_type : BLOCK_4X4; | 2946 subsize = (bsize >= BLOCK_8X8) ? mi[0]->mbmi.sb_type : BLOCK_4X4; |
| 2762 partition = partition_lookup[bsl][subsize]; | 2947 partition = partition_lookup[bsl][subsize]; |
| 2763 | 2948 |
| 2764 switch (partition) { | 2949 switch (partition) { |
| 2765 case PARTITION_NONE: | 2950 case PARTITION_NONE: |
| 2766 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, | 2951 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, |
| 2767 subsize, &pc_tree->none); | 2952 subsize, &pc_tree->none); |
| 2768 pc_tree->none.mic.mbmi = xd->mi[0]->mbmi; | 2953 pc_tree->none.mic.mbmi = xd->mi[0]->mbmi; |
| 2769 pc_tree->none.skip_txfm = x->skip_txfm; | 2954 pc_tree->none.skip_txfm[0] = x->skip_txfm[0]; |
| 2770 pc_tree->none.skip = x->skip; | 2955 pc_tree->none.skip = x->skip; |
| 2771 break; | 2956 break; |
| 2772 case PARTITION_VERT: | 2957 case PARTITION_VERT: |
| 2773 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, | 2958 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, |
| 2774 subsize, &pc_tree->vertical[0]); | 2959 subsize, &pc_tree->vertical[0]); |
| 2775 pc_tree->vertical[0].mic.mbmi = xd->mi[0]->mbmi; | 2960 pc_tree->vertical[0].mic.mbmi = xd->mi[0]->mbmi; |
| 2776 pc_tree->vertical[0].skip_txfm = x->skip_txfm; | 2961 pc_tree->vertical[0].skip_txfm[0] = x->skip_txfm[0]; |
| 2777 pc_tree->vertical[0].skip = x->skip; | 2962 pc_tree->vertical[0].skip = x->skip; |
| 2778 if (mi_col + hbs < cm->mi_cols) { | 2963 if (mi_col + hbs < cm->mi_cols) { |
| 2779 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col + hbs, | 2964 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col + hbs, |
| 2780 &rate, &dist, subsize, &pc_tree->vertical[1]); | 2965 &rate, &dist, subsize, &pc_tree->vertical[1]); |
| 2781 pc_tree->vertical[1].mic.mbmi = xd->mi[0]->mbmi; | 2966 pc_tree->vertical[1].mic.mbmi = xd->mi[0]->mbmi; |
| 2782 pc_tree->vertical[1].skip_txfm = x->skip_txfm; | 2967 pc_tree->vertical[1].skip_txfm[0] = x->skip_txfm[0]; |
| 2783 pc_tree->vertical[1].skip = x->skip; | 2968 pc_tree->vertical[1].skip = x->skip; |
| 2784 if (rate != INT_MAX && dist != INT64_MAX && | 2969 if (rate != INT_MAX && dist != INT64_MAX && |
| 2785 *totrate != INT_MAX && *totdist != INT64_MAX) { | 2970 *totrate != INT_MAX && *totdist != INT64_MAX) { |
| 2786 *totrate += rate; | 2971 *totrate += rate; |
| 2787 *totdist += dist; | 2972 *totdist += dist; |
| 2788 } | 2973 } |
| 2789 } | 2974 } |
| 2790 break; | 2975 break; |
| 2791 case PARTITION_HORZ: | 2976 case PARTITION_HORZ: |
| 2792 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, | 2977 nonrd_pick_sb_modes(cpi, tile, mi_row, mi_col, totrate, totdist, |
| 2793 subsize, &pc_tree->horizontal[0]); | 2978 subsize, &pc_tree->horizontal[0]); |
| 2794 pc_tree->horizontal[0].mic.mbmi = xd->mi[0]->mbmi; | 2979 pc_tree->horizontal[0].mic.mbmi = xd->mi[0]->mbmi; |
| 2795 pc_tree->horizontal[0].skip_txfm = x->skip_txfm; | 2980 pc_tree->horizontal[0].skip_txfm[0] = x->skip_txfm[0]; |
| 2796 pc_tree->horizontal[0].skip = x->skip; | 2981 pc_tree->horizontal[0].skip = x->skip; |
| 2797 if (mi_row + hbs < cm->mi_rows) { | 2982 if (mi_row + hbs < cm->mi_rows) { |
| 2798 nonrd_pick_sb_modes(cpi, tile, mi_row + hbs, mi_col, | 2983 nonrd_pick_sb_modes(cpi, tile, mi_row + hbs, mi_col, |
| 2799 &rate, &dist, subsize, &pc_tree->horizontal[0]); | 2984 &rate, &dist, subsize, &pc_tree->horizontal[0]); |
| 2800 pc_tree->horizontal[1].mic.mbmi = xd->mi[0]->mbmi; | 2985 pc_tree->horizontal[1].mic.mbmi = xd->mi[0]->mbmi; |
| 2801 pc_tree->horizontal[1].skip_txfm = x->skip_txfm; | 2986 pc_tree->horizontal[1].skip_txfm[0] = x->skip_txfm[0]; |
| 2802 pc_tree->horizontal[1].skip = x->skip; | 2987 pc_tree->horizontal[1].skip = x->skip; |
| 2803 if (rate != INT_MAX && dist != INT64_MAX && | 2988 if (rate != INT_MAX && dist != INT64_MAX && |
| 2804 *totrate != INT_MAX && *totdist != INT64_MAX) { | 2989 *totrate != INT_MAX && *totdist != INT64_MAX) { |
| 2805 *totrate += rate; | 2990 *totrate += rate; |
| 2806 *totdist += dist; | 2991 *totdist += dist; |
| 2807 } | 2992 } |
| 2808 } | 2993 } |
| 2809 break; | 2994 break; |
| 2810 case PARTITION_SPLIT: | 2995 case PARTITION_SPLIT: |
| 2811 subsize = get_subsize(bsize, PARTITION_SPLIT); | 2996 subsize = get_subsize(bsize, PARTITION_SPLIT); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2832 mi_row + hbs, mi_col + hbs, subsize, output_enabled, | 3017 mi_row + hbs, mi_col + hbs, subsize, output_enabled, |
| 2833 &rate, &dist, pc_tree->split[3]); | 3018 &rate, &dist, pc_tree->split[3]); |
| 2834 if (rate != INT_MAX && dist != INT64_MAX && | 3019 if (rate != INT_MAX && dist != INT64_MAX && |
| 2835 *totrate != INT_MAX && *totdist != INT64_MAX) { | 3020 *totrate != INT_MAX && *totdist != INT64_MAX) { |
| 2836 *totrate += rate; | 3021 *totrate += rate; |
| 2837 *totdist += dist; | 3022 *totdist += dist; |
| 2838 } | 3023 } |
| 2839 break; | 3024 break; |
| 2840 default: | 3025 default: |
| 2841 assert("Invalid partition type."); | 3026 assert("Invalid partition type."); |
| 3027 break; |
| 2842 } | 3028 } |
| 2843 | 3029 |
| 2844 if (bsize == BLOCK_64X64 && output_enabled) { | 3030 if (bsize == BLOCK_64X64 && output_enabled) { |
| 2845 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) | 3031 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ) |
| 2846 vp9_cyclic_refresh_set_rate_and_dist_sb(cpi->cyclic_refresh, | 3032 vp9_cyclic_refresh_set_rate_and_dist_sb(cpi->cyclic_refresh, |
| 2847 *totrate, *totdist); | 3033 *totrate, *totdist); |
| 2848 encode_sb_rt(cpi, tile, tp, mi_row, mi_col, 1, bsize, pc_tree); | 3034 encode_sb_rt(cpi, tile, tp, mi_row, mi_col, 1, bsize, pc_tree); |
| 2849 } | 3035 } |
| 2850 } | 3036 } |
| 2851 | 3037 |
| 2852 static void encode_nonrd_sb_row(VP9_COMP *cpi, const TileInfo *const tile, | 3038 static void encode_nonrd_sb_row(VP9_COMP *cpi, const TileInfo *const tile, |
| 2853 int mi_row, TOKENEXTRA **tp) { | 3039 int mi_row, TOKENEXTRA **tp) { |
| 2854 VP9_COMMON *cm = &cpi->common; | 3040 SPEED_FEATURES *const sf = &cpi->sf; |
| 2855 MACROBLOCK *x = &cpi->mb; | 3041 VP9_COMMON *const cm = &cpi->common; |
| 2856 MACROBLOCKD *xd = &x->e_mbd; | 3042 MACROBLOCK *const x = &cpi->mb; |
| 3043 MACROBLOCKD *const xd = &x->e_mbd; |
| 2857 int mi_col; | 3044 int mi_col; |
| 2858 | 3045 |
| 2859 // Initialize the left context for the new SB row | 3046 // Initialize the left context for the new SB row |
| 2860 vpx_memset(&xd->left_context, 0, sizeof(xd->left_context)); | 3047 vpx_memset(&xd->left_context, 0, sizeof(xd->left_context)); |
| 2861 vpx_memset(xd->left_seg_context, 0, sizeof(xd->left_seg_context)); | 3048 vpx_memset(xd->left_seg_context, 0, sizeof(xd->left_seg_context)); |
| 2862 | 3049 |
| 2863 // Code each SB in the row | 3050 // Code each SB in the row |
| 2864 for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end; | 3051 for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end; |
| 2865 mi_col += MI_BLOCK_SIZE) { | 3052 mi_col += MI_BLOCK_SIZE) { |
| 2866 MACROBLOCK *x = &cpi->mb; | |
| 2867 int dummy_rate = 0; | 3053 int dummy_rate = 0; |
| 2868 int64_t dummy_dist = 0; | 3054 int64_t dummy_dist = 0; |
| 2869 const int idx_str = cm->mi_stride * mi_row + mi_col; | 3055 const int idx_str = cm->mi_stride * mi_row + mi_col; |
| 2870 MODE_INFO **mi = cm->mi_grid_visible + idx_str; | 3056 MODE_INFO **mi = cm->mi_grid_visible + idx_str; |
| 2871 MODE_INFO **prev_mi = cm->prev_mi_grid_visible + idx_str; | 3057 MODE_INFO **prev_mi = cm->prev_mi_grid_visible + idx_str; |
| 2872 BLOCK_SIZE bsize; | 3058 BLOCK_SIZE bsize; |
| 2873 | 3059 |
| 2874 x->in_static_area = 0; | 3060 x->in_static_area = 0; |
| 2875 x->source_variance = UINT_MAX; | 3061 x->source_variance = UINT_MAX; |
| 2876 vp9_zero(x->pred_mv); | 3062 vp9_zero(x->pred_mv); |
| 2877 | 3063 |
| 2878 // Set the partition type of the 64X64 block | 3064 // Set the partition type of the 64X64 block |
| 2879 switch (cpi->sf.partition_search_type) { | 3065 switch (sf->partition_search_type) { |
| 2880 case VAR_BASED_PARTITION: | 3066 case VAR_BASED_PARTITION: |
| 2881 choose_partitioning(cpi, tile, mi_row, mi_col); | 3067 choose_partitioning(cpi, tile, mi_row, mi_col); |
| 2882 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, | 3068 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, |
| 2883 1, &dummy_rate, &dummy_dist, cpi->pc_root); | 3069 1, &dummy_rate, &dummy_dist, cpi->pc_root); |
| 2884 break; | 3070 break; |
| 2885 case SOURCE_VAR_BASED_PARTITION: | 3071 case SOURCE_VAR_BASED_PARTITION: |
| 2886 set_source_var_based_partition(cpi, tile, mi, mi_row, mi_col); | 3072 set_source_var_based_partition(cpi, tile, mi, mi_row, mi_col); |
| 2887 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, | 3073 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, |
| 2888 1, &dummy_rate, &dummy_dist, cpi->pc_root); | 3074 1, &dummy_rate, &dummy_dist, cpi->pc_root); |
| 2889 break; | 3075 break; |
| 2890 case VAR_BASED_FIXED_PARTITION: | 3076 case VAR_BASED_FIXED_PARTITION: |
| 2891 case FIXED_PARTITION: | 3077 case FIXED_PARTITION: |
| 2892 bsize = cpi->sf.partition_search_type == FIXED_PARTITION ? | 3078 bsize = sf->partition_search_type == FIXED_PARTITION ? |
| 2893 cpi->sf.always_this_block_size : | 3079 sf->always_this_block_size : |
| 2894 get_nonrd_var_based_fixed_partition(cpi, mi_row, mi_col); | 3080 get_nonrd_var_based_fixed_partition(cpi, mi_row, mi_col); |
| 2895 set_fixed_partitioning(cpi, tile, mi, mi_row, mi_col, bsize); | 3081 set_fixed_partitioning(cpi, tile, mi, mi_row, mi_col, bsize); |
| 2896 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, | 3082 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, BLOCK_64X64, |
| 2897 1, &dummy_rate, &dummy_dist, cpi->pc_root); | 3083 1, &dummy_rate, &dummy_dist, cpi->pc_root); |
| 2898 break; | 3084 break; |
| 2899 case REFERENCE_PARTITION: | 3085 case REFERENCE_PARTITION: |
| 2900 if (cpi->sf.partition_check || | 3086 if (sf->partition_check || |
| 2901 !is_background(cpi, tile, mi_row, mi_col)) { | 3087 !is_background(cpi, tile, mi_row, mi_col)) { |
| 2902 set_modeinfo_offsets(cm, xd, mi_row, mi_col); | 3088 set_modeinfo_offsets(cm, xd, mi_row, mi_col); |
| 2903 auto_partition_range(cpi, tile, mi_row, mi_col, | 3089 auto_partition_range(cpi, tile, mi_row, mi_col, |
| 2904 &cpi->sf.min_partition_size, | 3090 &sf->min_partition_size, |
| 2905 &cpi->sf.max_partition_size); | 3091 &sf->max_partition_size); |
| 2906 nonrd_pick_partition(cpi, tile, tp, mi_row, mi_col, BLOCK_64X64, | 3092 nonrd_pick_partition(cpi, tile, tp, mi_row, mi_col, BLOCK_64X64, |
| 2907 &dummy_rate, &dummy_dist, 1, INT64_MAX, | 3093 &dummy_rate, &dummy_dist, 1, INT64_MAX, |
| 2908 cpi->pc_root); | 3094 cpi->pc_root); |
| 2909 } else { | 3095 } else { |
| 2910 copy_partitioning(cm, mi, prev_mi); | 3096 copy_partitioning(cm, mi, prev_mi); |
| 2911 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, | 3097 nonrd_use_partition(cpi, tile, mi, tp, mi_row, mi_col, |
| 2912 BLOCK_64X64, 1, &dummy_rate, &dummy_dist, | 3098 BLOCK_64X64, 1, &dummy_rate, &dummy_dist, |
| 2913 cpi->pc_root); | 3099 cpi->pc_root); |
| 2914 } | 3100 } |
| 2915 break; | 3101 break; |
| 2916 default: | 3102 default: |
| 2917 assert(0); | 3103 assert(0); |
| 3104 break; |
| 2918 } | 3105 } |
| 2919 } | 3106 } |
| 2920 } | 3107 } |
| 2921 // end RTC play code | 3108 // end RTC play code |
| 2922 | 3109 |
| 2923 static int set_var_thresh_from_histogram(VP9_COMP *cpi) { | 3110 static int set_var_thresh_from_histogram(VP9_COMP *cpi) { |
| 2924 SPEED_FEATURES *const sf = &cpi->sf; | 3111 const SPEED_FEATURES *const sf = &cpi->sf; |
| 2925 VP9_COMMON *const cm = &cpi->common; | 3112 const VP9_COMMON *const cm = &cpi->common; |
| 2926 | 3113 |
| 2927 const uint8_t *src = cpi->Source->y_buffer; | 3114 const uint8_t *src = cpi->Source->y_buffer; |
| 2928 const uint8_t *last_src = cpi->Last_Source->y_buffer; | 3115 const uint8_t *last_src = cpi->Last_Source->y_buffer; |
| 2929 const int src_stride = cpi->Source->y_stride; | 3116 const int src_stride = cpi->Source->y_stride; |
| 2930 const int last_stride = cpi->Last_Source->y_stride; | 3117 const int last_stride = cpi->Last_Source->y_stride; |
| 2931 | 3118 |
| 2932 // Pick cutoff threshold | 3119 // Pick cutoff threshold |
| 2933 const int cutoff = (MIN(cm->width, cm->height) >= 720) ? | 3120 const int cutoff = (MIN(cm->width, cm->height) >= 720) ? |
| 2934 (cm->MBs * VAR_HIST_LARGE_CUT_OFF / 100) : | 3121 (cm->MBs * VAR_HIST_LARGE_CUT_OFF / 100) : |
| 2935 (cm->MBs * VAR_HIST_SMALL_CUT_OFF / 100); | 3122 (cm->MBs * VAR_HIST_SMALL_CUT_OFF / 100); |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3074 xd->mi[0] = cm->mi; | 3261 xd->mi[0] = cm->mi; |
| 3075 | 3262 |
| 3076 vp9_zero(cm->counts); | 3263 vp9_zero(cm->counts); |
| 3077 vp9_zero(cpi->coef_counts); | 3264 vp9_zero(cpi->coef_counts); |
| 3078 vp9_zero(cpi->tx_stepdown_count); | 3265 vp9_zero(cpi->tx_stepdown_count); |
| 3079 vp9_zero(rd_opt->comp_pred_diff); | 3266 vp9_zero(rd_opt->comp_pred_diff); |
| 3080 vp9_zero(rd_opt->filter_diff); | 3267 vp9_zero(rd_opt->filter_diff); |
| 3081 vp9_zero(rd_opt->tx_select_diff); | 3268 vp9_zero(rd_opt->tx_select_diff); |
| 3082 vp9_zero(rd_opt->tx_select_threshes); | 3269 vp9_zero(rd_opt->tx_select_threshes); |
| 3083 | 3270 |
| 3084 cpi->mb.e_mbd.lossless = cm->base_qindex == 0 && | 3271 xd->lossless = cm->base_qindex == 0 && |
| 3085 cm->y_dc_delta_q == 0 && | 3272 cm->y_dc_delta_q == 0 && |
| 3086 cm->uv_dc_delta_q == 0 && | 3273 cm->uv_dc_delta_q == 0 && |
| 3087 cm->uv_ac_delta_q == 0; | 3274 cm->uv_ac_delta_q == 0; |
| 3088 | 3275 |
| 3089 cm->tx_mode = select_tx_mode(cpi); | 3276 cm->tx_mode = select_tx_mode(cpi); |
| 3090 | 3277 |
| 3091 cpi->mb.fwd_txm4x4 = cpi->mb.e_mbd.lossless ? vp9_fwht4x4 : vp9_fdct4x4; | 3278 x->fwd_txm4x4 = xd->lossless ? vp9_fwht4x4 : vp9_fdct4x4; |
| 3092 cpi->mb.itxm_add = cpi->mb.e_mbd.lossless ? vp9_iwht4x4_add : vp9_idct4x4_add; | 3279 x->itxm_add = xd->lossless ? vp9_iwht4x4_add : vp9_idct4x4_add; |
| 3093 | 3280 |
| 3094 if (cpi->mb.e_mbd.lossless) { | 3281 if (xd->lossless) { |
| 3095 cpi->mb.optimize = 0; | 3282 x->optimize = 0; |
| 3096 cpi->common.lf.filter_level = 0; | 3283 cm->lf.filter_level = 0; |
| 3097 cpi->zbin_mode_boost_enabled = 0; | 3284 cpi->zbin_mode_boost_enabled = 0; |
| 3098 } | 3285 } |
| 3099 | 3286 |
| 3100 vp9_frame_init_quantizer(cpi); | 3287 vp9_frame_init_quantizer(cpi); |
| 3101 | 3288 |
| 3102 vp9_initialize_rd_consts(cpi); | 3289 vp9_initialize_rd_consts(cpi); |
| 3103 vp9_initialize_me_consts(cpi, cm->base_qindex); | 3290 vp9_initialize_me_consts(cpi, cm->base_qindex); |
| 3104 init_encode_frame_mb_context(cpi); | 3291 init_encode_frame_mb_context(cpi); |
| 3105 set_prev_mi(cm); | 3292 set_prev_mi(cm); |
| 3106 | 3293 |
| 3107 x->quant_fp = cpi->sf.use_quant_fp; | 3294 x->quant_fp = cpi->sf.use_quant_fp; |
| 3108 x->skip_txfm = 0; | 3295 vp9_zero(x->skip_txfm); |
| 3109 if (sf->use_nonrd_pick_mode) { | 3296 if (sf->use_nonrd_pick_mode) { |
| 3110 // Initialize internal buffer pointers for rtc coding, where non-RD | 3297 // Initialize internal buffer pointers for rtc coding, where non-RD |
| 3111 // mode decision is used and hence no buffer pointer swap needed. | 3298 // mode decision is used and hence no buffer pointer swap needed. |
| 3112 int i; | 3299 int i; |
| 3113 struct macroblock_plane *const p = x->plane; | 3300 struct macroblock_plane *const p = x->plane; |
| 3114 struct macroblockd_plane *const pd = xd->plane; | 3301 struct macroblockd_plane *const pd = xd->plane; |
| 3115 PICK_MODE_CONTEXT *ctx = &cpi->pc_root->none; | 3302 PICK_MODE_CONTEXT *ctx = &cpi->pc_root->none; |
| 3116 | 3303 |
| 3117 for (i = 0; i < MAX_MB_PLANE; ++i) { | 3304 for (i = 0; i < MAX_MB_PLANE; ++i) { |
| 3118 p[i].coeff = ctx->coeff_pbuf[i][0]; | 3305 p[i].coeff = ctx->coeff_pbuf[i][0]; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3338 | 3525 |
| 3339 static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, | 3526 static void encode_superblock(VP9_COMP *cpi, TOKENEXTRA **t, int output_enabled, |
| 3340 int mi_row, int mi_col, BLOCK_SIZE bsize, | 3527 int mi_row, int mi_col, BLOCK_SIZE bsize, |
| 3341 PICK_MODE_CONTEXT *ctx) { | 3528 PICK_MODE_CONTEXT *ctx) { |
| 3342 VP9_COMMON *const cm = &cpi->common; | 3529 VP9_COMMON *const cm = &cpi->common; |
| 3343 MACROBLOCK *const x = &cpi->mb; | 3530 MACROBLOCK *const x = &cpi->mb; |
| 3344 MACROBLOCKD *const xd = &x->e_mbd; | 3531 MACROBLOCKD *const xd = &x->e_mbd; |
| 3345 MODE_INFO **mi_8x8 = xd->mi; | 3532 MODE_INFO **mi_8x8 = xd->mi; |
| 3346 MODE_INFO *mi = mi_8x8[0]; | 3533 MODE_INFO *mi = mi_8x8[0]; |
| 3347 MB_MODE_INFO *mbmi = &mi->mbmi; | 3534 MB_MODE_INFO *mbmi = &mi->mbmi; |
| 3348 unsigned int segment_id = mbmi->segment_id; | 3535 const int seg_skip = vp9_segfeature_active(&cm->seg, mbmi->segment_id, |
| 3536 SEG_LVL_SKIP); |
| 3349 const int mis = cm->mi_stride; | 3537 const int mis = cm->mi_stride; |
| 3350 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; | 3538 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; |
| 3351 const int mi_height = num_8x8_blocks_high_lookup[bsize]; | 3539 const int mi_height = num_8x8_blocks_high_lookup[bsize]; |
| 3352 | 3540 |
| 3353 x->skip_recode = !x->select_tx_size && mbmi->sb_type >= BLOCK_8X8 && | 3541 x->skip_recode = !x->select_tx_size && mbmi->sb_type >= BLOCK_8X8 && |
| 3354 cpi->oxcf.aq_mode != COMPLEXITY_AQ && | 3542 cpi->oxcf.aq_mode != COMPLEXITY_AQ && |
| 3355 cpi->oxcf.aq_mode != CYCLIC_REFRESH_AQ && | 3543 cpi->oxcf.aq_mode != CYCLIC_REFRESH_AQ && |
| 3356 cpi->sf.allow_skip_recode; | 3544 cpi->sf.allow_skip_recode; |
| 3357 | 3545 |
| 3546 if (!x->skip_recode && !cpi->sf.use_nonrd_pick_mode) |
| 3547 vpx_memset(x->skip_txfm, 0, sizeof(x->skip_txfm)); |
| 3548 |
| 3358 x->skip_optimize = ctx->is_coded; | 3549 x->skip_optimize = ctx->is_coded; |
| 3359 ctx->is_coded = 1; | 3550 ctx->is_coded = 1; |
| 3360 x->use_lp32x32fdct = cpi->sf.use_lp32x32fdct; | 3551 x->use_lp32x32fdct = cpi->sf.use_lp32x32fdct; |
| 3361 x->skip_encode = (!output_enabled && cpi->sf.skip_encode_frame && | 3552 x->skip_encode = (!output_enabled && cpi->sf.skip_encode_frame && |
| 3362 x->q_index < QIDX_SKIP_THRESH); | 3553 x->q_index < QIDX_SKIP_THRESH); |
| 3363 | 3554 |
| 3364 if (x->skip_encode) | 3555 if (x->skip_encode) |
| 3365 return; | 3556 return; |
| 3366 | 3557 |
| 3367 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); | 3558 set_ref_ptrs(cm, xd, mbmi->ref_frame[0], mbmi->ref_frame[1]); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 3382 vp9_tokenize_sb(cpi, t, !output_enabled, MAX(bsize, BLOCK_8X8)); | 3573 vp9_tokenize_sb(cpi, t, !output_enabled, MAX(bsize, BLOCK_8X8)); |
| 3383 } else { | 3574 } else { |
| 3384 int ref; | 3575 int ref; |
| 3385 const int is_compound = has_second_ref(mbmi); | 3576 const int is_compound = has_second_ref(mbmi); |
| 3386 for (ref = 0; ref < 1 + is_compound; ++ref) { | 3577 for (ref = 0; ref < 1 + is_compound; ++ref) { |
| 3387 YV12_BUFFER_CONFIG *cfg = get_ref_frame_buffer(cpi, | 3578 YV12_BUFFER_CONFIG *cfg = get_ref_frame_buffer(cpi, |
| 3388 mbmi->ref_frame[ref]); | 3579 mbmi->ref_frame[ref]); |
| 3389 vp9_setup_pre_planes(xd, ref, cfg, mi_row, mi_col, | 3580 vp9_setup_pre_planes(xd, ref, cfg, mi_row, mi_col, |
| 3390 &xd->block_refs[ref]->sf); | 3581 &xd->block_refs[ref]->sf); |
| 3391 } | 3582 } |
| 3392 if (!cpi->sf.reuse_inter_pred_sby) | 3583 if (!cpi->sf.reuse_inter_pred_sby || seg_skip) |
| 3393 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, MAX(bsize, BLOCK_8X8)); | 3584 vp9_build_inter_predictors_sby(xd, mi_row, mi_col, MAX(bsize, BLOCK_8X8)); |
| 3394 | 3585 |
| 3395 vp9_build_inter_predictors_sbuv(xd, mi_row, mi_col, MAX(bsize, BLOCK_8X8)); | 3586 vp9_build_inter_predictors_sbuv(xd, mi_row, mi_col, MAX(bsize, BLOCK_8X8)); |
| 3396 | 3587 |
| 3397 if (!x->skip) { | 3588 if (!x->skip) { |
| 3398 mbmi->skip = 1; | 3589 mbmi->skip = 1; |
| 3399 vp9_encode_sb(x, MAX(bsize, BLOCK_8X8)); | 3590 vp9_encode_sb(x, MAX(bsize, BLOCK_8X8)); |
| 3400 vp9_tokenize_sb(cpi, t, !output_enabled, MAX(bsize, BLOCK_8X8)); | 3591 vp9_tokenize_sb(cpi, t, !output_enabled, MAX(bsize, BLOCK_8X8)); |
| 3401 } else { | 3592 } else { |
| 3402 mbmi->skip = 1; | 3593 mbmi->skip = 1; |
| 3403 if (output_enabled && | 3594 if (output_enabled && !seg_skip) |
| 3404 !vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) | |
| 3405 cm->counts.skip[vp9_get_skip_context(xd)][1]++; | 3595 cm->counts.skip[vp9_get_skip_context(xd)][1]++; |
| 3406 reset_skip_context(xd, MAX(bsize, BLOCK_8X8)); | 3596 reset_skip_context(xd, MAX(bsize, BLOCK_8X8)); |
| 3407 } | 3597 } |
| 3408 } | 3598 } |
| 3409 | 3599 |
| 3410 if (output_enabled) { | 3600 if (output_enabled) { |
| 3411 if (cm->tx_mode == TX_MODE_SELECT && | 3601 if (cm->tx_mode == TX_MODE_SELECT && |
| 3412 mbmi->sb_type >= BLOCK_8X8 && | 3602 mbmi->sb_type >= BLOCK_8X8 && |
| 3413 !(is_inter_block(mbmi) && | 3603 !(is_inter_block(mbmi) && (mbmi->skip || seg_skip))) { |
| 3414 (mbmi->skip || | |
| 3415 vp9_segfeature_active(&cm->seg, segment_id, SEG_LVL_SKIP)))) { | |
| 3416 ++get_tx_counts(max_txsize_lookup[bsize], vp9_get_tx_size_context(xd), | 3604 ++get_tx_counts(max_txsize_lookup[bsize], vp9_get_tx_size_context(xd), |
| 3417 &cm->counts.tx)[mbmi->tx_size]; | 3605 &cm->counts.tx)[mbmi->tx_size]; |
| 3418 } else { | 3606 } else { |
| 3419 int x, y; | 3607 int x, y; |
| 3420 TX_SIZE tx_size; | 3608 TX_SIZE tx_size; |
| 3421 // The new intra coding scheme requires no change of transform size | 3609 // The new intra coding scheme requires no change of transform size |
| 3422 if (is_inter_block(&mi->mbmi)) { | 3610 if (is_inter_block(&mi->mbmi)) { |
| 3423 tx_size = MIN(tx_mode_to_biggest_tx_size[cm->tx_mode], | 3611 tx_size = MIN(tx_mode_to_biggest_tx_size[cm->tx_mode], |
| 3424 max_txsize_lookup[bsize]); | 3612 max_txsize_lookup[bsize]); |
| 3425 } else { | 3613 } else { |
| 3426 tx_size = (bsize >= BLOCK_8X8) ? mbmi->tx_size : TX_4X4; | 3614 tx_size = (bsize >= BLOCK_8X8) ? mbmi->tx_size : TX_4X4; |
| 3427 } | 3615 } |
| 3428 | 3616 |
| 3429 for (y = 0; y < mi_height; y++) | 3617 for (y = 0; y < mi_height; y++) |
| 3430 for (x = 0; x < mi_width; x++) | 3618 for (x = 0; x < mi_width; x++) |
| 3431 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) | 3619 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) |
| 3432 mi_8x8[mis * y + x]->mbmi.tx_size = tx_size; | 3620 mi_8x8[mis * y + x]->mbmi.tx_size = tx_size; |
| 3433 } | 3621 } |
| 3434 } | 3622 } |
| 3435 } | 3623 } |
| OLD | NEW |