| 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 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 } | 363 } |
| 364 | 364 |
| 365 static void sum_2_variances(const var *a, const var *b, var *r) { | 365 static void sum_2_variances(const var *a, const var *b, var *r) { |
| 366 assert(a->log2_count == b->log2_count); | 366 assert(a->log2_count == b->log2_count); |
| 367 fill_variance(a->sum_square_error + b->sum_square_error, | 367 fill_variance(a->sum_square_error + b->sum_square_error, |
| 368 a->sum_error + b->sum_error, a->log2_count + 1, r); | 368 a->sum_error + b->sum_error, a->log2_count + 1, r); |
| 369 } | 369 } |
| 370 | 370 |
| 371 static void fill_variance_tree(void *data, BLOCK_SIZE bsize) { | 371 static void fill_variance_tree(void *data, BLOCK_SIZE bsize) { |
| 372 variance_node node; | 372 variance_node node; |
| 373 memset(&node, 0, sizeof(node)); |
| 373 tree_to_node(data, bsize, &node); | 374 tree_to_node(data, bsize, &node); |
| 374 sum_2_variances(node.split[0], node.split[1], &node.part_variances->horz[0]); | 375 sum_2_variances(node.split[0], node.split[1], &node.part_variances->horz[0]); |
| 375 sum_2_variances(node.split[2], node.split[3], &node.part_variances->horz[1]); | 376 sum_2_variances(node.split[2], node.split[3], &node.part_variances->horz[1]); |
| 376 sum_2_variances(node.split[0], node.split[2], &node.part_variances->vert[0]); | 377 sum_2_variances(node.split[0], node.split[2], &node.part_variances->vert[0]); |
| 377 sum_2_variances(node.split[1], node.split[3], &node.part_variances->vert[1]); | 378 sum_2_variances(node.split[1], node.split[3], &node.part_variances->vert[1]); |
| 378 sum_2_variances(&node.part_variances->vert[0], &node.part_variances->vert[1], | 379 sum_2_variances(&node.part_variances->vert[0], &node.part_variances->vert[1], |
| 379 &node.part_variances->none); | 380 &node.part_variances->none); |
| 380 } | 381 } |
| 381 | 382 |
| 382 static int set_vt_partitioning(VP9_COMP *cpi, | 383 static int set_vt_partitioning(VP9_COMP *cpi, |
| (...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1043 mbmi->mv[1].as_int = mi->bmi[3].as_mv[1].as_int; | 1044 mbmi->mv[1].as_int = mi->bmi[3].as_mv[1].as_int; |
| 1044 } | 1045 } |
| 1045 | 1046 |
| 1046 x->skip = ctx->skip; | 1047 x->skip = ctx->skip; |
| 1047 memcpy(x->zcoeff_blk[mbmi->tx_size], ctx->zcoeff_blk, | 1048 memcpy(x->zcoeff_blk[mbmi->tx_size], ctx->zcoeff_blk, |
| 1048 sizeof(uint8_t) * ctx->num_4x4_blk); | 1049 sizeof(uint8_t) * ctx->num_4x4_blk); |
| 1049 | 1050 |
| 1050 if (!output_enabled) | 1051 if (!output_enabled) |
| 1051 return; | 1052 return; |
| 1052 | 1053 |
| 1053 if (!vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { | 1054 if (!segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
| 1054 for (i = 0; i < TX_MODES; i++) | 1055 for (i = 0; i < TX_MODES; i++) |
| 1055 rdc->tx_select_diff[i] += ctx->tx_rd_diff[i]; | 1056 rdc->tx_select_diff[i] += ctx->tx_rd_diff[i]; |
| 1056 } | 1057 } |
| 1057 | 1058 |
| 1058 #if CONFIG_INTERNAL_STATS | 1059 #if CONFIG_INTERNAL_STATS |
| 1059 if (frame_is_intra_only(cm)) { | 1060 if (frame_is_intra_only(cm)) { |
| 1060 static const int kf_mode_index[] = { | 1061 static const int kf_mode_index[] = { |
| 1061 THR_DC /*DC_PRED*/, | 1062 THR_DC /*DC_PRED*/, |
| 1062 THR_V_PRED /*V_PRED*/, | 1063 THR_V_PRED /*V_PRED*/, |
| 1063 THR_H_PRED /*H_PRED*/, | 1064 THR_H_PRED /*H_PRED*/, |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1240 vp9_get_segment_id(cm, map, bsize, mi_row, mi_col))) | 1241 vp9_get_segment_id(cm, map, bsize, mi_row, mi_col))) |
| 1241 x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); | 1242 x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); |
| 1242 } | 1243 } |
| 1243 | 1244 |
| 1244 // Find best coding mode & reconstruct the MB so it is available | 1245 // Find best coding mode & reconstruct the MB so it is available |
| 1245 // as a predictor for MBs that follow in the SB | 1246 // as a predictor for MBs that follow in the SB |
| 1246 if (frame_is_intra_only(cm)) { | 1247 if (frame_is_intra_only(cm)) { |
| 1247 vp9_rd_pick_intra_mode_sb(cpi, x, rd_cost, bsize, ctx, best_rd); | 1248 vp9_rd_pick_intra_mode_sb(cpi, x, rd_cost, bsize, ctx, best_rd); |
| 1248 } else { | 1249 } else { |
| 1249 if (bsize >= BLOCK_8X8) { | 1250 if (bsize >= BLOCK_8X8) { |
| 1250 if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) | 1251 if (segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) |
| 1251 vp9_rd_pick_inter_mode_sb_seg_skip(cpi, tile_data, x, rd_cost, bsize, | 1252 vp9_rd_pick_inter_mode_sb_seg_skip(cpi, tile_data, x, rd_cost, bsize, |
| 1252 ctx, best_rd); | 1253 ctx, best_rd); |
| 1253 else | 1254 else |
| 1254 vp9_rd_pick_inter_mode_sb(cpi, tile_data, x, mi_row, mi_col, | 1255 vp9_rd_pick_inter_mode_sb(cpi, tile_data, x, mi_row, mi_col, |
| 1255 rd_cost, bsize, ctx, best_rd); | 1256 rd_cost, bsize, ctx, best_rd); |
| 1256 } else { | 1257 } else { |
| 1257 vp9_rd_pick_inter_mode_sub8x8(cpi, tile_data, x, mi_row, mi_col, | 1258 vp9_rd_pick_inter_mode_sub8x8(cpi, tile_data, x, mi_row, mi_col, |
| 1258 rd_cost, bsize, ctx, best_rd); | 1259 rd_cost, bsize, ctx, best_rd); |
| 1259 } | 1260 } |
| 1260 } | 1261 } |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1283 static void update_stats(VP9_COMMON *cm, ThreadData *td) { | 1284 static void update_stats(VP9_COMMON *cm, ThreadData *td) { |
| 1284 const MACROBLOCK *x = &td->mb; | 1285 const MACROBLOCK *x = &td->mb; |
| 1285 const MACROBLOCKD *const xd = &x->e_mbd; | 1286 const MACROBLOCKD *const xd = &x->e_mbd; |
| 1286 const MODE_INFO *const mi = xd->mi[0]; | 1287 const MODE_INFO *const mi = xd->mi[0]; |
| 1287 const MB_MODE_INFO *const mbmi = &mi->mbmi; | 1288 const MB_MODE_INFO *const mbmi = &mi->mbmi; |
| 1288 const BLOCK_SIZE bsize = mbmi->sb_type; | 1289 const BLOCK_SIZE bsize = mbmi->sb_type; |
| 1289 | 1290 |
| 1290 if (!frame_is_intra_only(cm)) { | 1291 if (!frame_is_intra_only(cm)) { |
| 1291 FRAME_COUNTS *const counts = td->counts; | 1292 FRAME_COUNTS *const counts = td->counts; |
| 1292 const int inter_block = is_inter_block(mbmi); | 1293 const int inter_block = is_inter_block(mbmi); |
| 1293 const int seg_ref_active = vp9_segfeature_active(&cm->seg, mbmi->segment_id, | 1294 const int seg_ref_active = segfeature_active(&cm->seg, mbmi->segment_id, |
| 1294 SEG_LVL_REF_FRAME); | 1295 SEG_LVL_REF_FRAME); |
| 1295 if (!seg_ref_active) { | 1296 if (!seg_ref_active) { |
| 1296 counts->intra_inter[vp9_get_intra_inter_context(xd)][inter_block]++; | 1297 counts->intra_inter[vp9_get_intra_inter_context(xd)][inter_block]++; |
| 1297 // If the segment reference feature is enabled we have only a single | 1298 // If the segment reference feature is enabled we have only a single |
| 1298 // reference frame allowed for the segment so exclude it from | 1299 // reference frame allowed for the segment so exclude it from |
| 1299 // the reference frame counts used to work out probabilities. | 1300 // the reference frame counts used to work out probabilities. |
| 1300 if (inter_block) { | 1301 if (inter_block) { |
| 1301 const MV_REFERENCE_FRAME ref0 = mbmi->ref_frame[0]; | 1302 const MV_REFERENCE_FRAME ref0 = mbmi->ref_frame[0]; |
| 1302 if (cm->reference_mode == REFERENCE_MODE_SELECT) | 1303 if (cm->reference_mode == REFERENCE_MODE_SELECT) |
| 1303 counts->comp_inter[vp9_get_reference_mode_context(cm, xd)] | 1304 counts->comp_inter[vp9_get_reference_mode_context(cm, xd)] |
| 1304 [has_second_ref(mbmi)]++; | 1305 [has_second_ref(mbmi)]++; |
| 1305 | 1306 |
| 1306 if (has_second_ref(mbmi)) { | 1307 if (has_second_ref(mbmi)) { |
| 1307 counts->comp_ref[vp9_get_pred_context_comp_ref_p(cm, xd)] | 1308 counts->comp_ref[vp9_get_pred_context_comp_ref_p(cm, xd)] |
| 1308 [ref0 == GOLDEN_FRAME]++; | 1309 [ref0 == GOLDEN_FRAME]++; |
| 1309 } else { | 1310 } else { |
| 1310 counts->single_ref[vp9_get_pred_context_single_ref_p1(xd)][0] | 1311 counts->single_ref[vp9_get_pred_context_single_ref_p1(xd)][0] |
| 1311 [ref0 != LAST_FRAME]++; | 1312 [ref0 != LAST_FRAME]++; |
| 1312 if (ref0 != LAST_FRAME) | 1313 if (ref0 != LAST_FRAME) |
| 1313 counts->single_ref[vp9_get_pred_context_single_ref_p2(xd)][1] | 1314 counts->single_ref[vp9_get_pred_context_single_ref_p2(xd)][1] |
| 1314 [ref0 != GOLDEN_FRAME]++; | 1315 [ref0 != GOLDEN_FRAME]++; |
| 1315 } | 1316 } |
| 1316 } | 1317 } |
| 1317 } | 1318 } |
| 1318 if (inter_block && | 1319 if (inter_block && |
| 1319 !vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { | 1320 !segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) { |
| 1320 const int mode_ctx = mbmi->mode_context[mbmi->ref_frame[0]]; | 1321 const int mode_ctx = mbmi->mode_context[mbmi->ref_frame[0]]; |
| 1321 if (bsize >= BLOCK_8X8) { | 1322 if (bsize >= BLOCK_8X8) { |
| 1322 const PREDICTION_MODE mode = mbmi->mode; | 1323 const PREDICTION_MODE mode = mbmi->mode; |
| 1323 ++counts->inter_mode[mode_ctx][INTER_OFFSET(mode)]; | 1324 ++counts->inter_mode[mode_ctx][INTER_OFFSET(mode)]; |
| 1324 } else { | 1325 } else { |
| 1325 const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize]; | 1326 const int num_4x4_w = num_4x4_blocks_wide_lookup[bsize]; |
| 1326 const int num_4x4_h = num_4x4_blocks_high_lookup[bsize]; | 1327 const int num_4x4_h = num_4x4_blocks_high_lookup[bsize]; |
| 1327 int idx, idy; | 1328 int idx, idy; |
| 1328 for (idy = 0; idy < 2; idy += num_4x4_h) { | 1329 for (idy = 0; idy < 2; idy += num_4x4_h) { |
| 1329 for (idx = 0; idx < 2; idx += num_4x4_w) { | 1330 for (idx = 0; idx < 2; idx += num_4x4_w) { |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1556 mi_8x8[index]->mbmi.sb_type = bsize; | 1557 mi_8x8[index]->mbmi.sb_type = bsize; |
| 1557 } | 1558 } |
| 1558 } | 1559 } |
| 1559 } else { | 1560 } else { |
| 1560 // Else this is a partial SB64. | 1561 // Else this is a partial SB64. |
| 1561 set_partial_b64x64_partition(mi_upper_left, mis, bh, bw, row8x8_remaining, | 1562 set_partial_b64x64_partition(mi_upper_left, mis, bh, bw, row8x8_remaining, |
| 1562 col8x8_remaining, bsize, mi_8x8); | 1563 col8x8_remaining, bsize, mi_8x8); |
| 1563 } | 1564 } |
| 1564 } | 1565 } |
| 1565 | 1566 |
| 1566 const struct { | 1567 static const struct { |
| 1567 int row; | 1568 int row; |
| 1568 int col; | 1569 int col; |
| 1569 } coord_lookup[16] = { | 1570 } coord_lookup[16] = { |
| 1570 // 32x32 index = 0 | 1571 // 32x32 index = 0 |
| 1571 {0, 0}, {0, 2}, {2, 0}, {2, 2}, | 1572 {0, 0}, {0, 2}, {2, 0}, {2, 2}, |
| 1572 // 32x32 index = 1 | 1573 // 32x32 index = 1 |
| 1573 {0, 4}, {0, 6}, {2, 4}, {2, 6}, | 1574 {0, 4}, {0, 6}, {2, 4}, {2, 6}, |
| 1574 // 32x32 index = 2 | 1575 // 32x32 index = 2 |
| 1575 {4, 0}, {4, 2}, {6, 0}, {6, 2}, | 1576 {4, 0}, {4, 2}, {6, 0}, {6, 2}, |
| 1576 // 32x32 index = 3 | 1577 // 32x32 index = 3 |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2212 // *min_block_size. | 2213 // *min_block_size. |
| 2213 if (cpi->sf.use_square_partition_only && | 2214 if (cpi->sf.use_square_partition_only && |
| 2214 next_square_size[max_size] < min_size) { | 2215 next_square_size[max_size] < min_size) { |
| 2215 min_size = next_square_size[max_size]; | 2216 min_size = next_square_size[max_size]; |
| 2216 } | 2217 } |
| 2217 | 2218 |
| 2218 *min_block_size = min_size; | 2219 *min_block_size = min_size; |
| 2219 *max_block_size = max_size; | 2220 *max_block_size = max_size; |
| 2220 } | 2221 } |
| 2221 | 2222 |
| 2222 static void auto_partition_range(VP9_COMP *cpi, const TileInfo *const tile, | |
| 2223 MACROBLOCKD *const xd, | |
| 2224 int mi_row, int mi_col, | |
| 2225 BLOCK_SIZE *min_block_size, | |
| 2226 BLOCK_SIZE *max_block_size) { | |
| 2227 VP9_COMMON *const cm = &cpi->common; | |
| 2228 MODE_INFO **mi_8x8 = xd->mi; | |
| 2229 const int left_in_image = xd->left_available && mi_8x8[-1]; | |
| 2230 const int above_in_image = xd->up_available && mi_8x8[-xd->mi_stride]; | |
| 2231 int row8x8_remaining = tile->mi_row_end - mi_row; | |
| 2232 int col8x8_remaining = tile->mi_col_end - mi_col; | |
| 2233 int bh, bw; | |
| 2234 BLOCK_SIZE min_size = BLOCK_32X32; | |
| 2235 BLOCK_SIZE max_size = BLOCK_8X8; | |
| 2236 int bsl = mi_width_log2_lookup[BLOCK_64X64]; | |
| 2237 const int search_range_ctrl = (((mi_row + mi_col) >> bsl) + | |
| 2238 get_chessboard_index(cm->current_video_frame)) & 0x1; | |
| 2239 // Trap case where we do not have a prediction. | |
| 2240 if (search_range_ctrl && | |
| 2241 (left_in_image || above_in_image || cm->frame_type != KEY_FRAME)) { | |
| 2242 int block; | |
| 2243 MODE_INFO **mi; | |
| 2244 BLOCK_SIZE sb_type; | |
| 2245 | |
| 2246 // Find the min and max partition sizes used in the left SB64. | |
| 2247 if (left_in_image) { | |
| 2248 MODE_INFO *cur_mi; | |
| 2249 mi = &mi_8x8[-1]; | |
| 2250 for (block = 0; block < MI_BLOCK_SIZE; ++block) { | |
| 2251 cur_mi = mi[block * xd->mi_stride]; | |
| 2252 sb_type = cur_mi ? cur_mi->mbmi.sb_type : 0; | |
| 2253 min_size = MIN(min_size, sb_type); | |
| 2254 max_size = MAX(max_size, sb_type); | |
| 2255 } | |
| 2256 } | |
| 2257 // Find the min and max partition sizes used in the above SB64. | |
| 2258 if (above_in_image) { | |
| 2259 mi = &mi_8x8[-xd->mi_stride * MI_BLOCK_SIZE]; | |
| 2260 for (block = 0; block < MI_BLOCK_SIZE; ++block) { | |
| 2261 sb_type = mi[block] ? mi[block]->mbmi.sb_type : 0; | |
| 2262 min_size = MIN(min_size, sb_type); | |
| 2263 max_size = MAX(max_size, sb_type); | |
| 2264 } | |
| 2265 } | |
| 2266 | |
| 2267 min_size = min_partition_size[min_size]; | |
| 2268 max_size = find_partition_size(max_size, row8x8_remaining, col8x8_remaining, | |
| 2269 &bh, &bw); | |
| 2270 min_size = MIN(min_size, max_size); | |
| 2271 min_size = MAX(min_size, BLOCK_8X8); | |
| 2272 max_size = MIN(max_size, BLOCK_32X32); | |
| 2273 } else { | |
| 2274 min_size = BLOCK_8X8; | |
| 2275 max_size = BLOCK_32X32; | |
| 2276 } | |
| 2277 | |
| 2278 *min_block_size = min_size; | |
| 2279 *max_block_size = max_size; | |
| 2280 } | |
| 2281 | |
| 2282 // TODO(jingning) refactor functions setting partition search range | 2223 // TODO(jingning) refactor functions setting partition search range |
| 2283 static void set_partition_range(VP9_COMMON *cm, MACROBLOCKD *xd, | 2224 static void set_partition_range(VP9_COMMON *cm, MACROBLOCKD *xd, |
| 2284 int mi_row, int mi_col, BLOCK_SIZE bsize, | 2225 int mi_row, int mi_col, BLOCK_SIZE bsize, |
| 2285 BLOCK_SIZE *min_bs, BLOCK_SIZE *max_bs) { | 2226 BLOCK_SIZE *min_bs, BLOCK_SIZE *max_bs) { |
| 2286 int mi_width = num_8x8_blocks_wide_lookup[bsize]; | 2227 int mi_width = num_8x8_blocks_wide_lookup[bsize]; |
| 2287 int mi_height = num_8x8_blocks_high_lookup[bsize]; | 2228 int mi_height = num_8x8_blocks_high_lookup[bsize]; |
| 2288 int idx, idy; | 2229 int idx, idy; |
| 2289 | 2230 |
| 2290 MODE_INFO *mi; | 2231 MODE_INFO *mi; |
| 2291 const int idx_str = cm->mi_stride * mi_row + mi_col; | 2232 const int idx_str = cm->mi_stride * mi_row + mi_col; |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2841 } | 2782 } |
| 2842 } | 2783 } |
| 2843 | 2784 |
| 2844 vp9_zero(x->pred_mv); | 2785 vp9_zero(x->pred_mv); |
| 2845 td->pc_root->index = 0; | 2786 td->pc_root->index = 0; |
| 2846 | 2787 |
| 2847 if (seg->enabled) { | 2788 if (seg->enabled) { |
| 2848 const uint8_t *const map = seg->update_map ? cpi->segmentation_map | 2789 const uint8_t *const map = seg->update_map ? cpi->segmentation_map |
| 2849 : cm->last_frame_seg_map; | 2790 : cm->last_frame_seg_map; |
| 2850 int segment_id = vp9_get_segment_id(cm, map, BLOCK_64X64, mi_row, mi_col); | 2791 int segment_id = vp9_get_segment_id(cm, map, BLOCK_64X64, mi_row, mi_col); |
| 2851 seg_skip = vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP); | 2792 seg_skip = segfeature_active(seg, segment_id, SEG_LVL_SKIP); |
| 2852 } | 2793 } |
| 2853 | 2794 |
| 2854 x->source_variance = UINT_MAX; | 2795 x->source_variance = UINT_MAX; |
| 2855 if (sf->partition_search_type == FIXED_PARTITION || seg_skip) { | 2796 if (sf->partition_search_type == FIXED_PARTITION || seg_skip) { |
| 2856 const BLOCK_SIZE bsize = | 2797 const BLOCK_SIZE bsize = |
| 2857 seg_skip ? BLOCK_64X64 : sf->always_this_block_size; | 2798 seg_skip ? BLOCK_64X64 : sf->always_this_block_size; |
| 2858 set_offsets(cpi, tile_info, x, mi_row, mi_col, BLOCK_64X64); | 2799 set_offsets(cpi, tile_info, x, mi_row, mi_col, BLOCK_64X64); |
| 2859 set_fixed_partitioning(cpi, tile_info, mi, mi_row, mi_col, bsize); | 2800 set_fixed_partitioning(cpi, tile_info, mi, mi_row, mi_col, bsize); |
| 2860 rd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, | 2801 rd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, |
| 2861 BLOCK_64X64, &dummy_rate, &dummy_dist, 1, td->pc_root); | 2802 BLOCK_64X64, &dummy_rate, &dummy_dist, 1, td->pc_root); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2901 memset(xd->above_context[0], 0, | 2842 memset(xd->above_context[0], 0, |
| 2902 sizeof(*xd->above_context[0]) * | 2843 sizeof(*xd->above_context[0]) * |
| 2903 2 * aligned_mi_cols * MAX_MB_PLANE); | 2844 2 * aligned_mi_cols * MAX_MB_PLANE); |
| 2904 memset(xd->above_seg_context, 0, | 2845 memset(xd->above_seg_context, 0, |
| 2905 sizeof(*xd->above_seg_context) * aligned_mi_cols); | 2846 sizeof(*xd->above_seg_context) * aligned_mi_cols); |
| 2906 } | 2847 } |
| 2907 | 2848 |
| 2908 static int check_dual_ref_flags(VP9_COMP *cpi) { | 2849 static int check_dual_ref_flags(VP9_COMP *cpi) { |
| 2909 const int ref_flags = cpi->ref_frame_flags; | 2850 const int ref_flags = cpi->ref_frame_flags; |
| 2910 | 2851 |
| 2911 if (vp9_segfeature_active(&cpi->common.seg, 1, SEG_LVL_REF_FRAME)) { | 2852 if (segfeature_active(&cpi->common.seg, 1, SEG_LVL_REF_FRAME)) { |
| 2912 return 0; | 2853 return 0; |
| 2913 } else { | 2854 } else { |
| 2914 return (!!(ref_flags & VP9_GOLD_FLAG) + !!(ref_flags & VP9_LAST_FLAG) | 2855 return (!!(ref_flags & VP9_GOLD_FLAG) + !!(ref_flags & VP9_LAST_FLAG) |
| 2915 + !!(ref_flags & VP9_ALT_FLAG)) >= 2; | 2856 + !!(ref_flags & VP9_ALT_FLAG)) >= 2; |
| 2916 } | 2857 } |
| 2917 } | 2858 } |
| 2918 | 2859 |
| 2919 static void reset_skip_tx_size(VP9_COMMON *cm, TX_SIZE max_tx_size) { | 2860 static void reset_skip_tx_size(VP9_COMMON *cm, TX_SIZE max_tx_size) { |
| 2920 int mi_row, mi_col; | 2861 int mi_row, mi_col; |
| 2921 const int mis = cm->mi_stride; | 2862 const int mis = cm->mi_stride; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2937 else if (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) | 2878 else if (cpi->refresh_golden_frame || cpi->refresh_alt_ref_frame) |
| 2938 return GOLDEN_FRAME; | 2879 return GOLDEN_FRAME; |
| 2939 else | 2880 else |
| 2940 return LAST_FRAME; | 2881 return LAST_FRAME; |
| 2941 } | 2882 } |
| 2942 | 2883 |
| 2943 static TX_MODE select_tx_mode(const VP9_COMP *cpi, MACROBLOCKD *const xd) { | 2884 static TX_MODE select_tx_mode(const VP9_COMP *cpi, MACROBLOCKD *const xd) { |
| 2944 if (xd->lossless) | 2885 if (xd->lossless) |
| 2945 return ONLY_4X4; | 2886 return ONLY_4X4; |
| 2946 if (cpi->common.frame_type == KEY_FRAME && | 2887 if (cpi->common.frame_type == KEY_FRAME && |
| 2947 cpi->sf.use_nonrd_pick_mode && | 2888 cpi->sf.use_nonrd_pick_mode) |
| 2948 cpi->sf.partition_search_type == VAR_BASED_PARTITION) | |
| 2949 return ALLOW_16X16; | 2889 return ALLOW_16X16; |
| 2950 if (cpi->sf.tx_size_search_method == USE_LARGESTALL) | 2890 if (cpi->sf.tx_size_search_method == USE_LARGESTALL) |
| 2951 return ALLOW_32X32; | 2891 return ALLOW_32X32; |
| 2952 else if (cpi->sf.tx_size_search_method == USE_FULL_RD|| | 2892 else if (cpi->sf.tx_size_search_method == USE_FULL_RD|| |
| 2953 cpi->sf.tx_size_search_method == USE_TX_8X8) | 2893 cpi->sf.tx_size_search_method == USE_TX_8X8) |
| 2954 return TX_MODE_SELECT; | 2894 return TX_MODE_SELECT; |
| 2955 else | 2895 else |
| 2956 return cpi->common.tx_mode; | 2896 return cpi->common.tx_mode; |
| 2957 } | 2897 } |
| 2958 | 2898 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2976 set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize); | 2916 set_offsets(cpi, tile_info, x, mi_row, mi_col, bsize); |
| 2977 mbmi = &xd->mi[0]->mbmi; | 2917 mbmi = &xd->mi[0]->mbmi; |
| 2978 mbmi->sb_type = bsize; | 2918 mbmi->sb_type = bsize; |
| 2979 | 2919 |
| 2980 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled) | 2920 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled) |
| 2981 if (cyclic_refresh_segment_id_boosted(mbmi->segment_id)) | 2921 if (cyclic_refresh_segment_id_boosted(mbmi->segment_id)) |
| 2982 x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); | 2922 x->rdmult = vp9_cyclic_refresh_get_rdmult(cpi->cyclic_refresh); |
| 2983 | 2923 |
| 2984 if (cm->frame_type == KEY_FRAME) | 2924 if (cm->frame_type == KEY_FRAME) |
| 2985 hybrid_intra_mode_search(cpi, x, rd_cost, bsize, ctx); | 2925 hybrid_intra_mode_search(cpi, x, rd_cost, bsize, ctx); |
| 2986 else if (vp9_segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) | 2926 else if (segfeature_active(&cm->seg, mbmi->segment_id, SEG_LVL_SKIP)) |
| 2987 set_mode_info_seg_skip(x, cm->tx_mode, rd_cost, bsize); | 2927 set_mode_info_seg_skip(x, cm->tx_mode, rd_cost, bsize); |
| 2988 else if (bsize >= BLOCK_8X8) | 2928 else if (bsize >= BLOCK_8X8) |
| 2989 vp9_pick_inter_mode(cpi, x, tile_data, mi_row, mi_col, | 2929 vp9_pick_inter_mode(cpi, x, tile_data, mi_row, mi_col, |
| 2990 rd_cost, bsize, ctx); | 2930 rd_cost, bsize, ctx); |
| 2991 else | 2931 else |
| 2992 vp9_pick_inter_mode_sub8x8(cpi, x, tile_data, mi_row, mi_col, | 2932 vp9_pick_inter_mode_sub8x8(cpi, x, tile_data, mi_row, mi_col, |
| 2993 rd_cost, bsize, ctx); | 2933 rd_cost, bsize, ctx); |
| 2994 | 2934 |
| 2995 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, bsize); | 2935 duplicate_mode_info_in_sb(cm, xd, mi_row, mi_col, bsize); |
| 2996 | 2936 |
| (...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3591 x->source_variance = UINT_MAX; | 3531 x->source_variance = UINT_MAX; |
| 3592 vp9_zero(x->pred_mv); | 3532 vp9_zero(x->pred_mv); |
| 3593 vp9_rd_cost_init(&dummy_rdc); | 3533 vp9_rd_cost_init(&dummy_rdc); |
| 3594 x->color_sensitivity[0] = 0; | 3534 x->color_sensitivity[0] = 0; |
| 3595 x->color_sensitivity[1] = 0; | 3535 x->color_sensitivity[1] = 0; |
| 3596 | 3536 |
| 3597 if (seg->enabled) { | 3537 if (seg->enabled) { |
| 3598 const uint8_t *const map = seg->update_map ? cpi->segmentation_map | 3538 const uint8_t *const map = seg->update_map ? cpi->segmentation_map |
| 3599 : cm->last_frame_seg_map; | 3539 : cm->last_frame_seg_map; |
| 3600 int segment_id = vp9_get_segment_id(cm, map, BLOCK_64X64, mi_row, mi_col); | 3540 int segment_id = vp9_get_segment_id(cm, map, BLOCK_64X64, mi_row, mi_col); |
| 3601 seg_skip = vp9_segfeature_active(seg, segment_id, SEG_LVL_SKIP); | 3541 seg_skip = segfeature_active(seg, segment_id, SEG_LVL_SKIP); |
| 3602 if (seg_skip) { | 3542 if (seg_skip) { |
| 3603 partition_search_type = FIXED_PARTITION; | 3543 partition_search_type = FIXED_PARTITION; |
| 3604 } | 3544 } |
| 3605 } | 3545 } |
| 3606 | 3546 |
| 3607 // Set the partition type of the 64X64 block | 3547 // Set the partition type of the 64X64 block |
| 3608 switch (partition_search_type) { | 3548 switch (partition_search_type) { |
| 3609 case VAR_BASED_PARTITION: | 3549 case VAR_BASED_PARTITION: |
| 3610 // TODO(jingning, marpan): The mode decision and encoding process | 3550 // TODO(jingning, marpan): The mode decision and encoding process |
| 3611 // support both intra and inter sub8x8 block coding for RTC mode. | 3551 // support both intra and inter sub8x8 block coding for RTC mode. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3624 if (!seg_skip) | 3564 if (!seg_skip) |
| 3625 bsize = sf->always_this_block_size; | 3565 bsize = sf->always_this_block_size; |
| 3626 set_fixed_partitioning(cpi, tile_info, mi, mi_row, mi_col, bsize); | 3566 set_fixed_partitioning(cpi, tile_info, mi, mi_row, mi_col, bsize); |
| 3627 nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, | 3567 nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, |
| 3628 BLOCK_64X64, 1, &dummy_rdc, td->pc_root); | 3568 BLOCK_64X64, 1, &dummy_rdc, td->pc_root); |
| 3629 break; | 3569 break; |
| 3630 case REFERENCE_PARTITION: | 3570 case REFERENCE_PARTITION: |
| 3631 set_offsets(cpi, tile_info, x, mi_row, mi_col, BLOCK_64X64); | 3571 set_offsets(cpi, tile_info, x, mi_row, mi_col, BLOCK_64X64); |
| 3632 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled && | 3572 if (cpi->oxcf.aq_mode == CYCLIC_REFRESH_AQ && cm->seg.enabled && |
| 3633 xd->mi[0]->mbmi.segment_id) { | 3573 xd->mi[0]->mbmi.segment_id) { |
| 3634 x->max_partition_size = BLOCK_64X64; | 3574 // Use lower max_partition_size for low resoultions. |
| 3575 if (cm->width <= 352 && cm->height <= 288) |
| 3576 x->max_partition_size = BLOCK_32X32; |
| 3577 else |
| 3578 x->max_partition_size = BLOCK_64X64; |
| 3635 x->min_partition_size = BLOCK_8X8; | 3579 x->min_partition_size = BLOCK_8X8; |
| 3636 nonrd_pick_partition(cpi, td, tile_data, tp, mi_row, mi_col, | 3580 nonrd_pick_partition(cpi, td, tile_data, tp, mi_row, mi_col, |
| 3637 BLOCK_64X64, &dummy_rdc, 1, | 3581 BLOCK_64X64, &dummy_rdc, 1, |
| 3638 INT64_MAX, td->pc_root); | 3582 INT64_MAX, td->pc_root); |
| 3639 } else { | 3583 } else { |
| 3640 choose_partitioning(cpi, tile_info, x, mi_row, mi_col); | 3584 choose_partitioning(cpi, tile_info, x, mi_row, mi_col); |
| 3641 nonrd_select_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, | 3585 // TODO(marpan): Seems like nonrd_select_partition does not support |
| 3642 BLOCK_64X64, 1, &dummy_rdc, td->pc_root); | 3586 // 4x4 partition. Since 4x4 is used on key frame, use this switch |
| 3587 // for now. |
| 3588 if (cm->frame_type == KEY_FRAME) |
| 3589 nonrd_use_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, |
| 3590 BLOCK_64X64, 1, &dummy_rdc, td->pc_root); |
| 3591 else |
| 3592 nonrd_select_partition(cpi, td, tile_data, mi, tp, mi_row, mi_col, |
| 3593 BLOCK_64X64, 1, &dummy_rdc, td->pc_root); |
| 3643 } | 3594 } |
| 3644 | 3595 |
| 3645 break; | 3596 break; |
| 3646 default: | 3597 default: |
| 3647 assert(0); | 3598 assert(0); |
| 3648 break; | 3599 break; |
| 3649 } | 3600 } |
| 3650 } | 3601 } |
| 3651 } | 3602 } |
| 3652 // end RTC play code | 3603 // end RTC play code |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3778 } | 3729 } |
| 3779 | 3730 |
| 3780 void vp9_init_tile_data(VP9_COMP *cpi) { | 3731 void vp9_init_tile_data(VP9_COMP *cpi) { |
| 3781 VP9_COMMON *const cm = &cpi->common; | 3732 VP9_COMMON *const cm = &cpi->common; |
| 3782 const int tile_cols = 1 << cm->log2_tile_cols; | 3733 const int tile_cols = 1 << cm->log2_tile_cols; |
| 3783 const int tile_rows = 1 << cm->log2_tile_rows; | 3734 const int tile_rows = 1 << cm->log2_tile_rows; |
| 3784 int tile_col, tile_row; | 3735 int tile_col, tile_row; |
| 3785 TOKENEXTRA *pre_tok = cpi->tile_tok[0][0]; | 3736 TOKENEXTRA *pre_tok = cpi->tile_tok[0][0]; |
| 3786 int tile_tok = 0; | 3737 int tile_tok = 0; |
| 3787 | 3738 |
| 3788 if (cpi->tile_data == NULL) { | 3739 if (cpi->tile_data == NULL || cpi->allocated_tiles < tile_cols * tile_rows) { |
| 3740 if (cpi->tile_data != NULL) |
| 3741 vpx_free(cpi->tile_data); |
| 3789 CHECK_MEM_ERROR(cm, cpi->tile_data, | 3742 CHECK_MEM_ERROR(cm, cpi->tile_data, |
| 3790 vpx_malloc(tile_cols * tile_rows * sizeof(*cpi->tile_data))); | 3743 vpx_malloc(tile_cols * tile_rows * sizeof(*cpi->tile_data))); |
| 3744 cpi->allocated_tiles = tile_cols * tile_rows; |
| 3745 |
| 3791 for (tile_row = 0; tile_row < tile_rows; ++tile_row) | 3746 for (tile_row = 0; tile_row < tile_rows; ++tile_row) |
| 3792 for (tile_col = 0; tile_col < tile_cols; ++tile_col) { | 3747 for (tile_col = 0; tile_col < tile_cols; ++tile_col) { |
| 3793 TileDataEnc *tile_data = | 3748 TileDataEnc *tile_data = |
| 3794 &cpi->tile_data[tile_row * tile_cols + tile_col]; | 3749 &cpi->tile_data[tile_row * tile_cols + tile_col]; |
| 3795 int i, j; | 3750 int i, j; |
| 3796 for (i = 0; i < BLOCK_SIZES; ++i) { | 3751 for (i = 0; i < BLOCK_SIZES; ++i) { |
| 3797 for (j = 0; j < MAX_MODES; ++j) { | 3752 for (j = 0; j < MAX_MODES; ++j) { |
| 3798 tile_data->thresh_freq_fact[i][j] = 32; | 3753 tile_data->thresh_freq_fact[i][j] = 32; |
| 3799 tile_data->mode_map[i][j] = j; | 3754 tile_data->mode_map[i][j] = j; |
| 3800 } | 3755 } |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4149 static void encode_superblock(VP9_COMP *cpi, ThreadData *td, | 4104 static void encode_superblock(VP9_COMP *cpi, ThreadData *td, |
| 4150 TOKENEXTRA **t, int output_enabled, | 4105 TOKENEXTRA **t, int output_enabled, |
| 4151 int mi_row, int mi_col, BLOCK_SIZE bsize, | 4106 int mi_row, int mi_col, BLOCK_SIZE bsize, |
| 4152 PICK_MODE_CONTEXT *ctx) { | 4107 PICK_MODE_CONTEXT *ctx) { |
| 4153 VP9_COMMON *const cm = &cpi->common; | 4108 VP9_COMMON *const cm = &cpi->common; |
| 4154 MACROBLOCK *const x = &td->mb; | 4109 MACROBLOCK *const x = &td->mb; |
| 4155 MACROBLOCKD *const xd = &x->e_mbd; | 4110 MACROBLOCKD *const xd = &x->e_mbd; |
| 4156 MODE_INFO **mi_8x8 = xd->mi; | 4111 MODE_INFO **mi_8x8 = xd->mi; |
| 4157 MODE_INFO *mi = mi_8x8[0]; | 4112 MODE_INFO *mi = mi_8x8[0]; |
| 4158 MB_MODE_INFO *mbmi = &mi->mbmi; | 4113 MB_MODE_INFO *mbmi = &mi->mbmi; |
| 4159 const int seg_skip = vp9_segfeature_active(&cm->seg, mbmi->segment_id, | 4114 const int seg_skip = segfeature_active(&cm->seg, mbmi->segment_id, |
| 4160 SEG_LVL_SKIP); | 4115 SEG_LVL_SKIP); |
| 4161 const int mis = cm->mi_stride; | 4116 const int mis = cm->mi_stride; |
| 4162 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; | 4117 const int mi_width = num_8x8_blocks_wide_lookup[bsize]; |
| 4163 const int mi_height = num_8x8_blocks_high_lookup[bsize]; | 4118 const int mi_height = num_8x8_blocks_high_lookup[bsize]; |
| 4164 | 4119 |
| 4165 x->skip_recode = !x->select_tx_size && mbmi->sb_type >= BLOCK_8X8 && | 4120 x->skip_recode = !x->select_tx_size && mbmi->sb_type >= BLOCK_8X8 && |
| 4166 cpi->oxcf.aq_mode != COMPLEXITY_AQ && | 4121 cpi->oxcf.aq_mode != COMPLEXITY_AQ && |
| 4167 cpi->oxcf.aq_mode != CYCLIC_REFRESH_AQ && | 4122 cpi->oxcf.aq_mode != CYCLIC_REFRESH_AQ && |
| 4168 cpi->sf.allow_skip_recode; | 4123 cpi->sf.allow_skip_recode; |
| 4169 | 4124 |
| 4170 if (!x->skip_recode && !cpi->sf.use_nonrd_pick_mode) | 4125 if (!x->skip_recode && !cpi->sf.use_nonrd_pick_mode) |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4227 | 4182 |
| 4228 for (y = 0; y < mi_height; y++) | 4183 for (y = 0; y < mi_height; y++) |
| 4229 for (x = 0; x < mi_width; x++) | 4184 for (x = 0; x < mi_width; x++) |
| 4230 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) | 4185 if (mi_col + x < cm->mi_cols && mi_row + y < cm->mi_rows) |
| 4231 mi_8x8[mis * y + x]->mbmi.tx_size = tx_size; | 4186 mi_8x8[mis * y + x]->mbmi.tx_size = tx_size; |
| 4232 } | 4187 } |
| 4233 ++td->counts->tx.tx_totals[mbmi->tx_size]; | 4188 ++td->counts->tx.tx_totals[mbmi->tx_size]; |
| 4234 ++td->counts->tx.tx_totals[get_uv_tx_size(mbmi, &xd->plane[1])]; | 4189 ++td->counts->tx.tx_totals[get_uv_tx_size(mbmi, &xd->plane[1])]; |
| 4235 } | 4190 } |
| 4236 } | 4191 } |
| OLD | NEW |