| 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 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 vp9_idct32x32_add(dqcoeff, dst, stride, eob); | 269 vp9_idct32x32_add(dqcoeff, dst, stride, eob); |
| 270 break; | 270 break; |
| 271 default: | 271 default: |
| 272 assert(0 && "Invalid transform size"); | 272 assert(0 && "Invalid transform size"); |
| 273 return; | 273 return; |
| 274 } | 274 } |
| 275 } | 275 } |
| 276 #endif // CONFIG_VP9_HIGHBITDEPTH | 276 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 277 | 277 |
| 278 if (eob == 1) { | 278 if (eob == 1) { |
| 279 vpx_memset(dqcoeff, 0, 2 * sizeof(dqcoeff[0])); | 279 memset(dqcoeff, 0, 2 * sizeof(dqcoeff[0])); |
| 280 } else { | 280 } else { |
| 281 if (tx_type == DCT_DCT && tx_size <= TX_16X16 && eob <= 10) | 281 if (tx_type == DCT_DCT && tx_size <= TX_16X16 && eob <= 10) |
| 282 vpx_memset(dqcoeff, 0, 4 * (4 << tx_size) * sizeof(dqcoeff[0])); | 282 memset(dqcoeff, 0, 4 * (4 << tx_size) * sizeof(dqcoeff[0])); |
| 283 else if (tx_size == TX_32X32 && eob <= 34) | 283 else if (tx_size == TX_32X32 && eob <= 34) |
| 284 vpx_memset(dqcoeff, 0, 256 * sizeof(dqcoeff[0])); | 284 memset(dqcoeff, 0, 256 * sizeof(dqcoeff[0])); |
| 285 else | 285 else |
| 286 vpx_memset(dqcoeff, 0, (16 << (tx_size << 1)) * sizeof(dqcoeff[0])); | 286 memset(dqcoeff, 0, (16 << (tx_size << 1)) * sizeof(dqcoeff[0])); |
| 287 } | 287 } |
| 288 } | 288 } |
| 289 } | 289 } |
| 290 | 290 |
| 291 struct intra_args { | 291 struct intra_args { |
| 292 VP9_COMMON *cm; | 292 VP9_COMMON *cm; |
| 293 MACROBLOCKD *xd; | 293 MACROBLOCKD *xd; |
| 294 FRAME_COUNTS *counts; | 294 FRAME_COUNTS *counts; |
| 295 vp9_reader *r; | 295 vp9_reader *r; |
| 296 const int16_t *const y_dequant; | 296 int seg_id; |
| 297 const int16_t *const uv_dequant; | |
| 298 }; | 297 }; |
| 299 | 298 |
| 300 static void predict_and_reconstruct_intra_block(int plane, int block, | 299 static void predict_and_reconstruct_intra_block(int plane, int block, |
| 301 BLOCK_SIZE plane_bsize, | 300 BLOCK_SIZE plane_bsize, |
| 302 TX_SIZE tx_size, void *arg) { | 301 TX_SIZE tx_size, void *arg) { |
| 303 struct intra_args *const args = (struct intra_args *)arg; | 302 struct intra_args *const args = (struct intra_args *)arg; |
| 304 VP9_COMMON *const cm = args->cm; | 303 VP9_COMMON *const cm = args->cm; |
| 305 MACROBLOCKD *const xd = args->xd; | 304 MACROBLOCKD *const xd = args->xd; |
| 306 struct macroblockd_plane *const pd = &xd->plane[plane]; | 305 struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 307 MODE_INFO *const mi = xd->mi[0].src_mi; | 306 MODE_INFO *const mi = xd->mi[0]; |
| 308 const PREDICTION_MODE mode = (plane == 0) ? get_y_mode(mi, block) | 307 const PREDICTION_MODE mode = (plane == 0) ? get_y_mode(mi, block) |
| 309 : mi->mbmi.uv_mode; | 308 : mi->mbmi.uv_mode; |
| 310 const int16_t *const dequant = (plane == 0) ? args->y_dequant | |
| 311 : args->uv_dequant; | |
| 312 int x, y; | 309 int x, y; |
| 313 uint8_t *dst; | 310 uint8_t *dst; |
| 314 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x, &y); | 311 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x, &y); |
| 315 dst = &pd->dst.buf[4 * y * pd->dst.stride + 4 * x]; | 312 dst = &pd->dst.buf[4 * y * pd->dst.stride + 4 * x]; |
| 316 | 313 |
| 317 vp9_predict_intra_block(xd, block >> (tx_size << 1), | 314 vp9_predict_intra_block(xd, block >> (tx_size << 1), |
| 318 b_width_log2_lookup[plane_bsize], tx_size, mode, | 315 b_width_log2_lookup[plane_bsize], tx_size, mode, |
| 319 dst, pd->dst.stride, dst, pd->dst.stride, | 316 dst, pd->dst.stride, dst, pd->dst.stride, |
| 320 x, y, plane); | 317 x, y, plane); |
| 321 | 318 |
| 322 if (!mi->mbmi.skip) { | 319 if (!mi->mbmi.skip) { |
| 323 const int eob = vp9_decode_block_tokens(cm, xd, args->counts, plane, block, | 320 const int eob = vp9_decode_block_tokens(cm, xd, args->counts, plane, block, |
| 324 plane_bsize, x, y, tx_size, | 321 plane_bsize, x, y, tx_size, |
| 325 args->r, dequant); | 322 args->r, args->seg_id); |
| 326 inverse_transform_block(xd, plane, block, tx_size, dst, pd->dst.stride, | 323 inverse_transform_block(xd, plane, block, tx_size, dst, pd->dst.stride, |
| 327 eob); | 324 eob); |
| 328 } | 325 } |
| 329 } | 326 } |
| 330 | 327 |
| 331 struct inter_args { | 328 struct inter_args { |
| 332 VP9_COMMON *cm; | 329 VP9_COMMON *cm; |
| 333 MACROBLOCKD *xd; | 330 MACROBLOCKD *xd; |
| 334 vp9_reader *r; | 331 vp9_reader *r; |
| 335 FRAME_COUNTS *counts; | 332 FRAME_COUNTS *counts; |
| 336 int *eobtotal; | 333 int *eobtotal; |
| 337 const int16_t *const y_dequant; | 334 int seg_id; |
| 338 const int16_t *const uv_dequant; | |
| 339 }; | 335 }; |
| 340 | 336 |
| 341 static void reconstruct_inter_block(int plane, int block, | 337 static void reconstruct_inter_block(int plane, int block, |
| 342 BLOCK_SIZE plane_bsize, | 338 BLOCK_SIZE plane_bsize, |
| 343 TX_SIZE tx_size, void *arg) { | 339 TX_SIZE tx_size, void *arg) { |
| 344 struct inter_args *args = (struct inter_args *)arg; | 340 struct inter_args *args = (struct inter_args *)arg; |
| 345 VP9_COMMON *const cm = args->cm; | 341 VP9_COMMON *const cm = args->cm; |
| 346 MACROBLOCKD *const xd = args->xd; | 342 MACROBLOCKD *const xd = args->xd; |
| 347 struct macroblockd_plane *const pd = &xd->plane[plane]; | 343 struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 348 const int16_t *const dequant = (plane == 0) ? args->y_dequant | |
| 349 : args->uv_dequant; | |
| 350 int x, y, eob; | 344 int x, y, eob; |
| 351 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x, &y); | 345 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x, &y); |
| 352 eob = vp9_decode_block_tokens(cm, xd, args->counts, plane, block, plane_bsize, | 346 eob = vp9_decode_block_tokens(cm, xd, args->counts, plane, block, plane_bsize, |
| 353 x, y, tx_size, args->r, dequant); | 347 x, y, tx_size, args->r, args->seg_id); |
| 354 inverse_transform_block(xd, plane, block, tx_size, | 348 inverse_transform_block(xd, plane, block, tx_size, |
| 355 &pd->dst.buf[4 * y * pd->dst.stride + 4 * x], | 349 &pd->dst.buf[4 * y * pd->dst.stride + 4 * x], |
| 356 pd->dst.stride, eob); | 350 pd->dst.stride, eob); |
| 357 *args->eobtotal += eob; | 351 *args->eobtotal += eob; |
| 358 } | 352 } |
| 359 | 353 |
| 360 static MB_MODE_INFO *set_offsets(VP9_COMMON *const cm, MACROBLOCKD *const xd, | 354 static MB_MODE_INFO *set_offsets(VP9_COMMON *const cm, MACROBLOCKD *const xd, |
| 361 const TileInfo *const tile, | 355 const TileInfo *const tile, |
| 362 BLOCK_SIZE bsize, int mi_row, int mi_col) { | 356 BLOCK_SIZE bsize, int mi_row, int mi_col) { |
| 363 const int bw = num_8x8_blocks_wide_lookup[bsize]; | 357 const int bw = num_8x8_blocks_wide_lookup[bsize]; |
| 364 const int bh = num_8x8_blocks_high_lookup[bsize]; | 358 const int bh = num_8x8_blocks_high_lookup[bsize]; |
| 365 const int x_mis = MIN(bw, cm->mi_cols - mi_col); | 359 const int x_mis = MIN(bw, cm->mi_cols - mi_col); |
| 366 const int y_mis = MIN(bh, cm->mi_rows - mi_row); | 360 const int y_mis = MIN(bh, cm->mi_rows - mi_row); |
| 367 const int offset = mi_row * cm->mi_stride + mi_col; | 361 const int offset = mi_row * cm->mi_stride + mi_col; |
| 368 int x, y; | 362 int x, y; |
| 369 | 363 |
| 370 xd->mi = cm->mi + offset; | 364 xd->mi = cm->mi_grid_visible + offset; |
| 371 xd->mi[0].src_mi = &xd->mi[0]; // Point to self. | 365 xd->mi[0] = &cm->mi[offset]; |
| 372 xd->mi[0].mbmi.sb_type = bsize; | 366 xd->mi[0]->mbmi.sb_type = bsize; |
| 373 | |
| 374 for (y = 0; y < y_mis; ++y) | 367 for (y = 0; y < y_mis; ++y) |
| 375 for (x = !y; x < x_mis; ++x) { | 368 for (x = !y; x < x_mis; ++x) { |
| 376 xd->mi[y * cm->mi_stride + x].src_mi = &xd->mi[0]; | 369 xd->mi[y * cm->mi_stride + x] = xd->mi[0]; |
| 377 } | 370 } |
| 378 | 371 |
| 379 set_skip_context(xd, mi_row, mi_col); | 372 set_skip_context(xd, mi_row, mi_col); |
| 380 | 373 |
| 381 // Distance of Mb to the various image edges. These are specified to 8th pel | 374 // Distance of Mb to the various image edges. These are specified to 8th pel |
| 382 // as they are always compared to values that are in 1/8th pel units | 375 // as they are always compared to values that are in 1/8th pel units |
| 383 set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw, cm->mi_rows, cm->mi_cols); | 376 set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw, cm->mi_rows, cm->mi_cols); |
| 384 | 377 |
| 385 vp9_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col); | 378 vp9_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col); |
| 386 return &xd->mi[0].mbmi; | 379 return &xd->mi[0]->mbmi; |
| 387 } | 380 } |
| 388 | 381 |
| 389 static void decode_block(VP9Decoder *const pbi, MACROBLOCKD *const xd, | 382 static void decode_block(VP9Decoder *const pbi, MACROBLOCKD *const xd, |
| 390 FRAME_COUNTS *counts, | 383 FRAME_COUNTS *counts, |
| 391 const TileInfo *const tile, | 384 const TileInfo *const tile, |
| 392 int mi_row, int mi_col, | 385 int mi_row, int mi_col, |
| 393 vp9_reader *r, BLOCK_SIZE bsize) { | 386 vp9_reader *r, BLOCK_SIZE bsize) { |
| 394 VP9_COMMON *const cm = &pbi->common; | 387 VP9_COMMON *const cm = &pbi->common; |
| 395 const int less8x8 = bsize < BLOCK_8X8; | 388 const int less8x8 = bsize < BLOCK_8X8; |
| 396 int16_t y_dequant[2], uv_dequant[2]; | |
| 397 int qindex = cm->base_qindex; | |
| 398 MB_MODE_INFO *mbmi = set_offsets(cm, xd, tile, bsize, mi_row, mi_col); | 389 MB_MODE_INFO *mbmi = set_offsets(cm, xd, tile, bsize, mi_row, mi_col); |
| 399 vp9_read_mode_info(pbi, xd, counts, tile, mi_row, mi_col, r); | 390 vp9_read_mode_info(pbi, xd, counts, tile, mi_row, mi_col, r); |
| 400 | 391 |
| 401 if (less8x8) | 392 if (less8x8) |
| 402 bsize = BLOCK_8X8; | 393 bsize = BLOCK_8X8; |
| 403 | 394 |
| 404 if (mbmi->skip) { | 395 if (mbmi->skip) { |
| 405 reset_skip_context(xd, bsize); | 396 reset_skip_context(xd, bsize); |
| 406 } else if (cm->seg.enabled) { | |
| 407 qindex = vp9_get_qindex(&cm->seg, mbmi->segment_id, cm->base_qindex); | |
| 408 } | 397 } |
| 409 | 398 |
| 410 y_dequant[0] = vp9_dc_quant(qindex, cm->y_dc_delta_q, cm->bit_depth); | |
| 411 y_dequant[1] = vp9_ac_quant(qindex, 0, cm->bit_depth); | |
| 412 uv_dequant[0] = vp9_dc_quant(qindex, cm->uv_dc_delta_q, cm->bit_depth); | |
| 413 uv_dequant[1] = vp9_ac_quant(qindex, cm->uv_ac_delta_q, cm->bit_depth); | |
| 414 | |
| 415 if (!is_inter_block(mbmi)) { | 399 if (!is_inter_block(mbmi)) { |
| 416 struct intra_args arg = {cm, xd, counts, r , y_dequant, uv_dequant}; | 400 struct intra_args arg = {cm, xd, counts, r, mbmi->segment_id}; |
| 417 vp9_foreach_transformed_block(xd, bsize, | 401 vp9_foreach_transformed_block(xd, bsize, |
| 418 predict_and_reconstruct_intra_block, &arg); | 402 predict_and_reconstruct_intra_block, &arg); |
| 419 } else { | 403 } else { |
| 420 // Prediction | 404 // Prediction |
| 421 vp9_dec_build_inter_predictors_sb(pbi, xd, mi_row, mi_col, bsize); | 405 vp9_dec_build_inter_predictors_sb(pbi, xd, mi_row, mi_col, bsize); |
| 422 | 406 |
| 423 // Reconstruction | 407 // Reconstruction |
| 424 if (!mbmi->skip) { | 408 if (!mbmi->skip) { |
| 425 int eobtotal = 0; | 409 int eobtotal = 0; |
| 426 struct inter_args arg = {cm, xd, r, counts, &eobtotal, y_dequant, | 410 struct inter_args arg = {cm, xd, r, counts, &eobtotal, mbmi->segment_id}; |
| 427 uv_dequant}; | |
| 428 vp9_foreach_transformed_block(xd, bsize, reconstruct_inter_block, &arg); | 411 vp9_foreach_transformed_block(xd, bsize, reconstruct_inter_block, &arg); |
| 429 if (!less8x8 && eobtotal == 0) | 412 if (!less8x8 && eobtotal == 0) |
| 430 mbmi->skip = 1; // skip loopfilter | 413 mbmi->skip = 1; // skip loopfilter |
| 431 } | 414 } |
| 432 } | 415 } |
| 433 | 416 |
| 434 xd->corrupted |= vp9_reader_has_error(r); | 417 xd->corrupted |= vp9_reader_has_error(r); |
| 435 } | 418 } |
| 436 | 419 |
| 437 static PARTITION_TYPE read_partition(VP9_COMMON *cm, MACROBLOCKD *xd, | 420 static PARTITION_TYPE read_partition(VP9_COMMON *cm, MACROBLOCKD *xd, |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 struct vp9_read_bit_buffer *rb) { | 624 struct vp9_read_bit_buffer *rb) { |
| 642 cm->base_qindex = vp9_rb_read_literal(rb, QINDEX_BITS); | 625 cm->base_qindex = vp9_rb_read_literal(rb, QINDEX_BITS); |
| 643 cm->y_dc_delta_q = read_delta_q(rb); | 626 cm->y_dc_delta_q = read_delta_q(rb); |
| 644 cm->uv_dc_delta_q = read_delta_q(rb); | 627 cm->uv_dc_delta_q = read_delta_q(rb); |
| 645 cm->uv_ac_delta_q = read_delta_q(rb); | 628 cm->uv_ac_delta_q = read_delta_q(rb); |
| 646 cm->dequant_bit_depth = cm->bit_depth; | 629 cm->dequant_bit_depth = cm->bit_depth; |
| 647 xd->lossless = cm->base_qindex == 0 && | 630 xd->lossless = cm->base_qindex == 0 && |
| 648 cm->y_dc_delta_q == 0 && | 631 cm->y_dc_delta_q == 0 && |
| 649 cm->uv_dc_delta_q == 0 && | 632 cm->uv_dc_delta_q == 0 && |
| 650 cm->uv_ac_delta_q == 0; | 633 cm->uv_ac_delta_q == 0; |
| 634 |
| 651 #if CONFIG_VP9_HIGHBITDEPTH | 635 #if CONFIG_VP9_HIGHBITDEPTH |
| 652 xd->bd = (int)cm->bit_depth; | 636 xd->bd = (int)cm->bit_depth; |
| 653 #endif | 637 #endif |
| 654 } | 638 } |
| 655 | 639 |
| 640 static void setup_segmentation_dequant(VP9_COMMON *const cm) { |
| 641 // Build y/uv dequant values based on segmentation. |
| 642 if (cm->seg.enabled) { |
| 643 int i; |
| 644 for (i = 0; i < MAX_SEGMENTS; ++i) { |
| 645 const int qindex = vp9_get_qindex(&cm->seg, i, cm->base_qindex); |
| 646 cm->y_dequant[i][0] = vp9_dc_quant(qindex, cm->y_dc_delta_q, |
| 647 cm->bit_depth); |
| 648 cm->y_dequant[i][1] = vp9_ac_quant(qindex, 0, cm->bit_depth); |
| 649 cm->uv_dequant[i][0] = vp9_dc_quant(qindex, cm->uv_dc_delta_q, |
| 650 cm->bit_depth); |
| 651 cm->uv_dequant[i][1] = vp9_ac_quant(qindex, cm->uv_ac_delta_q, |
| 652 cm->bit_depth); |
| 653 } |
| 654 } else { |
| 655 const int qindex = cm->base_qindex; |
| 656 // When segmentation is disabled, only the first value is used. The |
| 657 // remaining are don't cares. |
| 658 cm->y_dequant[0][0] = vp9_dc_quant(qindex, cm->y_dc_delta_q, cm->bit_depth); |
| 659 cm->y_dequant[0][1] = vp9_ac_quant(qindex, 0, cm->bit_depth); |
| 660 cm->uv_dequant[0][0] = vp9_dc_quant(qindex, cm->uv_dc_delta_q, |
| 661 cm->bit_depth); |
| 662 cm->uv_dequant[0][1] = vp9_ac_quant(qindex, cm->uv_ac_delta_q, |
| 663 cm->bit_depth); |
| 664 } |
| 665 } |
| 666 |
| 656 static INTERP_FILTER read_interp_filter(struct vp9_read_bit_buffer *rb) { | 667 static INTERP_FILTER read_interp_filter(struct vp9_read_bit_buffer *rb) { |
| 657 const INTERP_FILTER literal_to_filter[] = { EIGHTTAP_SMOOTH, | 668 const INTERP_FILTER literal_to_filter[] = { EIGHTTAP_SMOOTH, |
| 658 EIGHTTAP, | 669 EIGHTTAP, |
| 659 EIGHTTAP_SHARP, | 670 EIGHTTAP_SHARP, |
| 660 BILINEAR }; | 671 BILINEAR }; |
| 661 return vp9_rb_read_bit(rb) ? SWITCHABLE | 672 return vp9_rb_read_bit(rb) ? SWITCHABLE |
| 662 : literal_to_filter[vp9_rb_read_literal(rb, 2)]; | 673 : literal_to_filter[vp9_rb_read_literal(rb, 2)]; |
| 663 } | 674 } |
| 664 | 675 |
| 665 void vp9_read_frame_size(struct vp9_read_bit_buffer *rb, | 676 void vp9_read_frame_size(struct vp9_read_bit_buffer *rb, |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 934 winterface->sync(&pbi->lf_worker); | 945 winterface->sync(&pbi->lf_worker); |
| 935 vp9_loop_filter_data_reset(lf_data, get_frame_new_buffer(cm), cm, | 946 vp9_loop_filter_data_reset(lf_data, get_frame_new_buffer(cm), cm, |
| 936 pbi->mb.plane); | 947 pbi->mb.plane); |
| 937 } | 948 } |
| 938 | 949 |
| 939 assert(tile_rows <= 4); | 950 assert(tile_rows <= 4); |
| 940 assert(tile_cols <= (1 << 6)); | 951 assert(tile_cols <= (1 << 6)); |
| 941 | 952 |
| 942 // Note: this memset assumes above_context[0], [1] and [2] | 953 // Note: this memset assumes above_context[0], [1] and [2] |
| 943 // are allocated as part of the same buffer. | 954 // are allocated as part of the same buffer. |
| 944 vpx_memset(cm->above_context, 0, | 955 memset(cm->above_context, 0, |
| 945 sizeof(*cm->above_context) * MAX_MB_PLANE * 2 * aligned_cols); | 956 sizeof(*cm->above_context) * MAX_MB_PLANE * 2 * aligned_cols); |
| 946 | 957 |
| 947 vpx_memset(cm->above_seg_context, 0, | 958 memset(cm->above_seg_context, 0, |
| 948 sizeof(*cm->above_seg_context) * aligned_cols); | 959 sizeof(*cm->above_seg_context) * aligned_cols); |
| 949 | 960 |
| 950 get_tile_buffers(pbi, data, data_end, tile_cols, tile_rows, tile_buffers); | 961 get_tile_buffers(pbi, data, data_end, tile_cols, tile_rows, tile_buffers); |
| 951 | 962 |
| 952 if (pbi->tile_data == NULL || | 963 if (pbi->tile_data == NULL || |
| 953 (tile_cols * tile_rows) != pbi->total_tiles) { | 964 (tile_cols * tile_rows) != pbi->total_tiles) { |
| 954 vpx_free(pbi->tile_data); | 965 vpx_free(pbi->tile_data); |
| 955 CHECK_MEM_ERROR( | 966 CHECK_MEM_ERROR( |
| 956 cm, | 967 cm, |
| 957 pbi->tile_data, | 968 pbi->tile_data, |
| 958 vpx_memalign(32, tile_cols * tile_rows * (sizeof(*pbi->tile_data)))); | 969 vpx_memalign(32, tile_cols * tile_rows * (sizeof(*pbi->tile_data)))); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1068 BLOCK_64X64); | 1079 BLOCK_64X64); |
| 1069 } | 1080 } |
| 1070 } | 1081 } |
| 1071 return !tile_data->xd.corrupted; | 1082 return !tile_data->xd.corrupted; |
| 1072 } | 1083 } |
| 1073 | 1084 |
| 1074 // sorts in descending order | 1085 // sorts in descending order |
| 1075 static int compare_tile_buffers(const void *a, const void *b) { | 1086 static int compare_tile_buffers(const void *a, const void *b) { |
| 1076 const TileBuffer *const buf1 = (const TileBuffer*)a; | 1087 const TileBuffer *const buf1 = (const TileBuffer*)a; |
| 1077 const TileBuffer *const buf2 = (const TileBuffer*)b; | 1088 const TileBuffer *const buf2 = (const TileBuffer*)b; |
| 1078 if (buf1->size < buf2->size) { | 1089 return (int)(buf2->size - buf1->size); |
| 1079 return 1; | |
| 1080 } else if (buf1->size == buf2->size) { | |
| 1081 return 0; | |
| 1082 } else { | |
| 1083 return -1; | |
| 1084 } | |
| 1085 } | 1090 } |
| 1086 | 1091 |
| 1087 static const uint8_t *decode_tiles_mt(VP9Decoder *pbi, | 1092 static const uint8_t *decode_tiles_mt(VP9Decoder *pbi, |
| 1088 const uint8_t *data, | 1093 const uint8_t *data, |
| 1089 const uint8_t *data_end) { | 1094 const uint8_t *data_end) { |
| 1090 VP9_COMMON *const cm = &pbi->common; | 1095 VP9_COMMON *const cm = &pbi->common; |
| 1091 const VP9WorkerInterface *const winterface = vp9_get_worker_interface(); | 1096 const VP9WorkerInterface *const winterface = vp9_get_worker_interface(); |
| 1092 const uint8_t *bit_reader_end = NULL; | 1097 const uint8_t *bit_reader_end = NULL; |
| 1093 const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); | 1098 const int aligned_mi_cols = mi_cols_aligned_to_sb(cm->mi_cols); |
| 1094 const int tile_cols = 1 << cm->log2_tile_cols; | 1099 const int tile_cols = 1 << cm->log2_tile_cols; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1135 for (n = 0; n < num_workers; ++n) { | 1140 for (n = 0; n < num_workers; ++n) { |
| 1136 VP9Worker *const worker = &pbi->tile_workers[n]; | 1141 VP9Worker *const worker = &pbi->tile_workers[n]; |
| 1137 winterface->sync(worker); | 1142 winterface->sync(worker); |
| 1138 worker->hook = (VP9WorkerHook)tile_worker_hook; | 1143 worker->hook = (VP9WorkerHook)tile_worker_hook; |
| 1139 worker->data1 = &pbi->tile_worker_data[n]; | 1144 worker->data1 = &pbi->tile_worker_data[n]; |
| 1140 worker->data2 = &pbi->tile_worker_info[n]; | 1145 worker->data2 = &pbi->tile_worker_info[n]; |
| 1141 } | 1146 } |
| 1142 | 1147 |
| 1143 // Note: this memset assumes above_context[0], [1] and [2] | 1148 // Note: this memset assumes above_context[0], [1] and [2] |
| 1144 // are allocated as part of the same buffer. | 1149 // are allocated as part of the same buffer. |
| 1145 vpx_memset(cm->above_context, 0, | 1150 memset(cm->above_context, 0, |
| 1146 sizeof(*cm->above_context) * MAX_MB_PLANE * 2 * aligned_mi_cols); | 1151 sizeof(*cm->above_context) * MAX_MB_PLANE * 2 * aligned_mi_cols); |
| 1147 vpx_memset(cm->above_seg_context, 0, | 1152 memset(cm->above_seg_context, 0, |
| 1148 sizeof(*cm->above_seg_context) * aligned_mi_cols); | 1153 sizeof(*cm->above_seg_context) * aligned_mi_cols); |
| 1149 | 1154 |
| 1150 // Load tile data into tile_buffers | 1155 // Load tile data into tile_buffers |
| 1151 get_tile_buffers(pbi, data, data_end, tile_cols, tile_rows, tile_buffers); | 1156 get_tile_buffers(pbi, data, data_end, tile_cols, tile_rows, tile_buffers); |
| 1152 | 1157 |
| 1153 // Sort the buffers based on size in descending order. | 1158 // Sort the buffers based on size in descending order. |
| 1154 qsort(tile_buffers[0], tile_cols, sizeof(tile_buffers[0][0]), | 1159 qsort(tile_buffers[0], tile_cols, sizeof(tile_buffers[0][0]), |
| 1155 compare_tile_buffers); | 1160 compare_tile_buffers); |
| 1156 | 1161 |
| 1157 // Rearrange the tile buffers such that per-tile group the largest, and | 1162 // Rearrange the tile buffers such that per-tile group the largest, and |
| 1158 // presumably the most difficult, tile will be decoded in the main thread. | 1163 // presumably the most difficult, tile will be decoded in the main thread. |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 read_bitdepth_colorspace_sampling(cm, rb); | 1365 read_bitdepth_colorspace_sampling(cm, rb); |
| 1361 pbi->refresh_frame_flags = (1 << REF_FRAMES) - 1; | 1366 pbi->refresh_frame_flags = (1 << REF_FRAMES) - 1; |
| 1362 | 1367 |
| 1363 for (i = 0; i < REFS_PER_FRAME; ++i) { | 1368 for (i = 0; i < REFS_PER_FRAME; ++i) { |
| 1364 cm->frame_refs[i].idx = INVALID_IDX; | 1369 cm->frame_refs[i].idx = INVALID_IDX; |
| 1365 cm->frame_refs[i].buf = NULL; | 1370 cm->frame_refs[i].buf = NULL; |
| 1366 } | 1371 } |
| 1367 | 1372 |
| 1368 setup_frame_size(cm, rb); | 1373 setup_frame_size(cm, rb); |
| 1369 if (pbi->need_resync) { | 1374 if (pbi->need_resync) { |
| 1370 vpx_memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map)); | 1375 memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map)); |
| 1371 pbi->need_resync = 0; | 1376 pbi->need_resync = 0; |
| 1372 } | 1377 } |
| 1373 } else { | 1378 } else { |
| 1374 cm->intra_only = cm->show_frame ? 0 : vp9_rb_read_bit(rb); | 1379 cm->intra_only = cm->show_frame ? 0 : vp9_rb_read_bit(rb); |
| 1375 | 1380 |
| 1376 cm->reset_frame_context = cm->error_resilient_mode ? | 1381 cm->reset_frame_context = cm->error_resilient_mode ? |
| 1377 0 : vp9_rb_read_literal(rb, 2); | 1382 0 : vp9_rb_read_literal(rb, 2); |
| 1378 | 1383 |
| 1379 if (cm->intra_only) { | 1384 if (cm->intra_only) { |
| 1380 if (!vp9_read_sync_code(rb)) | 1385 if (!vp9_read_sync_code(rb)) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1391 cm->subsampling_y = cm->subsampling_x = 1; | 1396 cm->subsampling_y = cm->subsampling_x = 1; |
| 1392 cm->bit_depth = VPX_BITS_8; | 1397 cm->bit_depth = VPX_BITS_8; |
| 1393 #if CONFIG_VP9_HIGHBITDEPTH | 1398 #if CONFIG_VP9_HIGHBITDEPTH |
| 1394 cm->use_highbitdepth = 0; | 1399 cm->use_highbitdepth = 0; |
| 1395 #endif | 1400 #endif |
| 1396 } | 1401 } |
| 1397 | 1402 |
| 1398 pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES); | 1403 pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES); |
| 1399 setup_frame_size(cm, rb); | 1404 setup_frame_size(cm, rb); |
| 1400 if (pbi->need_resync) { | 1405 if (pbi->need_resync) { |
| 1401 vpx_memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map)); | 1406 memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map)); |
| 1402 pbi->need_resync = 0; | 1407 pbi->need_resync = 0; |
| 1403 } | 1408 } |
| 1404 } else if (pbi->need_resync != 1) { /* Skip if need resync */ | 1409 } else if (pbi->need_resync != 1) { /* Skip if need resync */ |
| 1405 pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES); | 1410 pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES); |
| 1406 for (i = 0; i < REFS_PER_FRAME; ++i) { | 1411 for (i = 0; i < REFS_PER_FRAME; ++i) { |
| 1407 const int ref = vp9_rb_read_literal(rb, REF_FRAMES_LOG2); | 1412 const int ref = vp9_rb_read_literal(rb, REF_FRAMES_LOG2); |
| 1408 const int idx = cm->ref_frame_map[ref]; | 1413 const int idx = cm->ref_frame_map[ref]; |
| 1409 RefBuffer *const ref_frame = &cm->frame_refs[i]; | 1414 RefBuffer *const ref_frame = &cm->frame_refs[i]; |
| 1410 ref_frame->idx = idx; | 1415 ref_frame->idx = idx; |
| 1411 ref_frame->buf = &frame_bufs[idx].buf; | 1416 ref_frame->buf = &frame_bufs[idx].buf; |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1480 } | 1485 } |
| 1481 unlock_buffer_pool(pool); | 1486 unlock_buffer_pool(pool); |
| 1482 pbi->hold_ref_buf = 1; | 1487 pbi->hold_ref_buf = 1; |
| 1483 | 1488 |
| 1484 if (frame_is_intra_only(cm) || cm->error_resilient_mode) | 1489 if (frame_is_intra_only(cm) || cm->error_resilient_mode) |
| 1485 vp9_setup_past_independence(cm); | 1490 vp9_setup_past_independence(cm); |
| 1486 | 1491 |
| 1487 setup_loopfilter(&cm->lf, rb); | 1492 setup_loopfilter(&cm->lf, rb); |
| 1488 setup_quantization(cm, &pbi->mb, rb); | 1493 setup_quantization(cm, &pbi->mb, rb); |
| 1489 setup_segmentation(&cm->seg, rb); | 1494 setup_segmentation(&cm->seg, rb); |
| 1495 setup_segmentation_dequant(cm); |
| 1490 | 1496 |
| 1491 setup_tile_info(cm, rb); | 1497 setup_tile_info(cm, rb); |
| 1492 sz = vp9_rb_read_literal(rb, 16); | 1498 sz = vp9_rb_read_literal(rb, 16); |
| 1493 | 1499 |
| 1494 if (sz == 0) | 1500 if (sz == 0) |
| 1495 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, | 1501 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, |
| 1496 "Invalid header size"); | 1502 "Invalid header size"); |
| 1497 | 1503 |
| 1498 return sz; | 1504 return sz; |
| 1499 } | 1505 } |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1800 dst += dst_stride; | 1806 dst += dst_stride; |
| 1801 ++y; | 1807 ++y; |
| 1802 | 1808 |
| 1803 if (y > 0 && y < h) | 1809 if (y > 0 && y < h) |
| 1804 ref_row += src_stride; | 1810 ref_row += src_stride; |
| 1805 } while (--b_h); | 1811 } while (--b_h); |
| 1806 } | 1812 } |
| 1807 #endif // CONFIG_VP9_HIGHBITDEPTH | 1813 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 1808 | 1814 |
| 1809 void dec_build_inter_predictors(VP9Decoder *const pbi, MACROBLOCKD *xd, | 1815 void dec_build_inter_predictors(VP9Decoder *const pbi, MACROBLOCKD *xd, |
| 1810 int plane, int block, int bw, int bh, int x, | 1816 int plane, int bw, int bh, int x, |
| 1811 int y, int w, int h, int mi_x, int mi_y) { | 1817 int y, int w, int h, int mi_x, int mi_y, |
| 1818 const InterpKernel *kernel, |
| 1819 const struct scale_factors *sf, |
| 1820 struct buf_2d *pre_buf, struct buf_2d *dst_buf, |
| 1821 const MV* mv, RefCntBuffer *ref_frame_buf, |
| 1822 int is_scaled, int ref) { |
| 1812 struct macroblockd_plane *const pd = &xd->plane[plane]; | 1823 struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 1813 const MODE_INFO *mi = xd->mi[0].src_mi; | 1824 uint8_t *const dst = dst_buf->buf + dst_buf->stride * y + x; |
| 1814 const int is_compound = has_second_ref(&mi->mbmi); | 1825 MV32 scaled_mv; |
| 1815 const InterpKernel *kernel = vp9_get_interp_kernel(mi->mbmi.interp_filter); | 1826 int xs, ys, x0, y0, x0_16, y0_16, frame_width, frame_height, |
| 1816 int ref; | 1827 buf_stride, subpel_x, subpel_y; |
| 1828 uint8_t *ref_frame, *buf_ptr; |
| 1817 | 1829 |
| 1818 for (ref = 0; ref < 1 + is_compound; ++ref) { | 1830 // Get reference frame pointer, width and height. |
| 1819 const struct scale_factors *const sf = &xd->block_refs[ref]->sf; | 1831 if (plane == 0) { |
| 1820 struct buf_2d *const pre_buf = &pd->pre[ref]; | 1832 frame_width = ref_frame_buf->buf.y_crop_width; |
| 1821 struct buf_2d *const dst_buf = &pd->dst; | 1833 frame_height = ref_frame_buf->buf.y_crop_height; |
| 1822 uint8_t *const dst = dst_buf->buf + dst_buf->stride * y + x; | 1834 ref_frame = ref_frame_buf->buf.y_buffer; |
| 1823 const MV mv = mi->mbmi.sb_type < BLOCK_8X8 | 1835 } else { |
| 1824 ? average_split_mvs(pd, mi, ref, block) | 1836 frame_width = ref_frame_buf->buf.uv_crop_width; |
| 1825 : mi->mbmi.mv[ref].as_mv; | 1837 frame_height = ref_frame_buf->buf.uv_crop_height; |
| 1838 ref_frame = plane == 1 ? ref_frame_buf->buf.u_buffer |
| 1839 : ref_frame_buf->buf.v_buffer; |
| 1840 } |
| 1826 | 1841 |
| 1827 const MV mv_q4 = clamp_mv_to_umv_border_sb(xd, &mv, bw, bh, | 1842 if (is_scaled) { |
| 1843 const MV mv_q4 = clamp_mv_to_umv_border_sb(xd, mv, bw, bh, |
| 1828 pd->subsampling_x, | 1844 pd->subsampling_x, |
| 1829 pd->subsampling_y); | 1845 pd->subsampling_y); |
| 1846 // Co-ordinate of containing block to pixel precision. |
| 1847 int x_start = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x)); |
| 1848 int y_start = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y)); |
| 1830 | 1849 |
| 1831 MV32 scaled_mv; | 1850 // Co-ordinate of the block to 1/16th pixel precision. |
| 1832 int xs, ys, x0, y0, x0_16, y0_16, y1, frame_width, frame_height, | 1851 x0_16 = (x_start + x) << SUBPEL_BITS; |
| 1833 buf_stride, subpel_x, subpel_y; | 1852 y0_16 = (y_start + y) << SUBPEL_BITS; |
| 1834 uint8_t *ref_frame, *buf_ptr; | |
| 1835 const int idx = xd->block_refs[ref]->idx; | |
| 1836 BufferPool *const pool = pbi->common.buffer_pool; | |
| 1837 RefCntBuffer *const ref_frame_buf = &pool->frame_bufs[idx]; | |
| 1838 const int is_scaled = vp9_is_scaled(sf); | |
| 1839 | 1853 |
| 1840 // Get reference frame pointer, width and height. | 1854 // Co-ordinate of current block in reference frame |
| 1841 if (plane == 0) { | 1855 // to 1/16th pixel precision. |
| 1842 frame_width = ref_frame_buf->buf.y_crop_width; | 1856 x0_16 = sf->scale_value_x(x0_16, sf); |
| 1843 frame_height = ref_frame_buf->buf.y_crop_height; | 1857 y0_16 = sf->scale_value_y(y0_16, sf); |
| 1844 ref_frame = ref_frame_buf->buf.y_buffer; | 1858 |
| 1845 } else { | 1859 // Map the top left corner of the block into the reference frame. |
| 1846 frame_width = ref_frame_buf->buf.uv_crop_width; | 1860 x0 = sf->scale_value_x(x_start + x, sf); |
| 1847 frame_height = ref_frame_buf->buf.uv_crop_height; | 1861 y0 = sf->scale_value_y(y_start + y, sf); |
| 1848 ref_frame = plane == 1 ? ref_frame_buf->buf.u_buffer | 1862 |
| 1849 : ref_frame_buf->buf.v_buffer; | 1863 // Scale the MV and incorporate the sub-pixel offset of the block |
| 1864 // in the reference frame. |
| 1865 scaled_mv = vp9_scale_mv(&mv_q4, mi_x + x, mi_y + y, sf); |
| 1866 xs = sf->x_step_q4; |
| 1867 ys = sf->y_step_q4; |
| 1868 } else { |
| 1869 // Co-ordinate of containing block to pixel precision. |
| 1870 x0 = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x)) + x; |
| 1871 y0 = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y)) + y; |
| 1872 |
| 1873 // Co-ordinate of the block to 1/16th pixel precision. |
| 1874 x0_16 = x0 << SUBPEL_BITS; |
| 1875 y0_16 = y0 << SUBPEL_BITS; |
| 1876 |
| 1877 scaled_mv.row = mv->row * (1 << (1 - pd->subsampling_y)); |
| 1878 scaled_mv.col = mv->col * (1 << (1 - pd->subsampling_x)); |
| 1879 xs = ys = 16; |
| 1880 } |
| 1881 subpel_x = scaled_mv.col & SUBPEL_MASK; |
| 1882 subpel_y = scaled_mv.row & SUBPEL_MASK; |
| 1883 |
| 1884 // Calculate the top left corner of the best matching block in the |
| 1885 // reference frame. |
| 1886 x0 += scaled_mv.col >> SUBPEL_BITS; |
| 1887 y0 += scaled_mv.row >> SUBPEL_BITS; |
| 1888 x0_16 += scaled_mv.col; |
| 1889 y0_16 += scaled_mv.row; |
| 1890 |
| 1891 // Get reference block pointer. |
| 1892 buf_ptr = ref_frame + y0 * pre_buf->stride + x0; |
| 1893 buf_stride = pre_buf->stride; |
| 1894 |
| 1895 // Do border extension if there is motion or the |
| 1896 // width/height is not a multiple of 8 pixels. |
| 1897 if (is_scaled || scaled_mv.col || scaled_mv.row || |
| 1898 (frame_width & 0x7) || (frame_height & 0x7)) { |
| 1899 int y1 = (y0_16 + (h - 1) * ys) >> SUBPEL_BITS; |
| 1900 |
| 1901 // Get reference block bottom right horizontal coordinate. |
| 1902 int x1 = (x0_16 + (w - 1) * xs) >> SUBPEL_BITS; |
| 1903 int x_pad = 0, y_pad = 0; |
| 1904 |
| 1905 if (subpel_x || (sf->x_step_q4 != SUBPEL_SHIFTS)) { |
| 1906 x0 -= VP9_INTERP_EXTEND - 1; |
| 1907 x1 += VP9_INTERP_EXTEND; |
| 1908 x_pad = 1; |
| 1850 } | 1909 } |
| 1851 | 1910 |
| 1852 if (is_scaled) { | 1911 if (subpel_y || (sf->y_step_q4 != SUBPEL_SHIFTS)) { |
| 1853 // Co-ordinate of containing block to pixel precision. | 1912 y0 -= VP9_INTERP_EXTEND - 1; |
| 1854 int x_start = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x)); | 1913 y1 += VP9_INTERP_EXTEND; |
| 1855 int y_start = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y)); | 1914 y_pad = 1; |
| 1915 } |
| 1856 | 1916 |
| 1857 // Co-ordinate of the block to 1/16th pixel precision. | 1917 // Wait until reference block is ready. Pad 7 more pixels as last 7 |
| 1858 x0_16 = (x_start + x) << SUBPEL_BITS; | 1918 // pixels of each superblock row can be changed by next superblock row. |
| 1859 y0_16 = (y_start + y) << SUBPEL_BITS; | 1919 if (pbi->frame_parallel_decode) |
| 1920 vp9_frameworker_wait(pbi->frame_worker_owner, ref_frame_buf, |
| 1921 MAX(0, (y1 + 7)) << (plane == 0 ? 0 : 1)); |
| 1860 | 1922 |
| 1861 // Co-ordinate of current block in reference frame | 1923 // Skip border extension if block is inside the frame. |
| 1862 // to 1/16th pixel precision. | 1924 if (x0 < 0 || x0 > frame_width - 1 || x1 < 0 || x1 > frame_width - 1 || |
| 1863 x0_16 = sf->scale_value_x(x0_16, sf); | 1925 y0 < 0 || y0 > frame_height - 1 || y1 < 0 || y1 > frame_height - 1) { |
| 1864 y0_16 = sf->scale_value_y(y0_16, sf); | 1926 uint8_t *buf_ptr1 = ref_frame + y0 * pre_buf->stride + x0; |
| 1865 | 1927 // Extend the border. |
| 1866 // Map the top left corner of the block into the reference frame. | |
| 1867 x0 = sf->scale_value_x(x_start + x, sf); | |
| 1868 y0 = sf->scale_value_y(y_start + y, sf); | |
| 1869 | |
| 1870 // Scale the MV and incorporate the sub-pixel offset of the block | |
| 1871 // in the reference frame. | |
| 1872 scaled_mv = vp9_scale_mv(&mv_q4, mi_x + x, mi_y + y, sf); | |
| 1873 xs = sf->x_step_q4; | |
| 1874 ys = sf->y_step_q4; | |
| 1875 } else { | |
| 1876 // Co-ordinate of containing block to pixel precision. | |
| 1877 x0 = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x)) + x; | |
| 1878 y0 = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y)) + y; | |
| 1879 | |
| 1880 // Co-ordinate of the block to 1/16th pixel precision. | |
| 1881 x0_16 = x0 << SUBPEL_BITS; | |
| 1882 y0_16 = y0 << SUBPEL_BITS; | |
| 1883 | |
| 1884 scaled_mv.row = mv_q4.row; | |
| 1885 scaled_mv.col = mv_q4.col; | |
| 1886 xs = ys = 16; | |
| 1887 } | |
| 1888 subpel_x = scaled_mv.col & SUBPEL_MASK; | |
| 1889 subpel_y = scaled_mv.row & SUBPEL_MASK; | |
| 1890 | |
| 1891 // Calculate the top left corner of the best matching block in the | |
| 1892 // reference frame. | |
| 1893 x0 += scaled_mv.col >> SUBPEL_BITS; | |
| 1894 y0 += scaled_mv.row >> SUBPEL_BITS; | |
| 1895 x0_16 += scaled_mv.col; | |
| 1896 y0_16 += scaled_mv.row; | |
| 1897 | |
| 1898 // Get reference block pointer. | |
| 1899 buf_ptr = ref_frame + y0 * pre_buf->stride + x0; | |
| 1900 buf_stride = pre_buf->stride; | |
| 1901 | |
| 1902 // Get reference block bottom right vertical coordinate. | |
| 1903 y1 = ((y0_16 + (h - 1) * ys) >> SUBPEL_BITS) + 1; | |
| 1904 | |
| 1905 // Do border extension if there is motion or the | |
| 1906 // width/height is not a multiple of 8 pixels. | |
| 1907 if (is_scaled || scaled_mv.col || scaled_mv.row || | |
| 1908 (frame_width & 0x7) || (frame_height & 0x7)) { | |
| 1909 // Get reference block bottom right horizontal coordinate. | |
| 1910 int x1 = ((x0_16 + (w - 1) * xs) >> SUBPEL_BITS) + 1; | |
| 1911 int x_pad = 0, y_pad = 0; | |
| 1912 | |
| 1913 if (subpel_x || (sf->x_step_q4 != SUBPEL_SHIFTS)) { | |
| 1914 x0 -= VP9_INTERP_EXTEND - 1; | |
| 1915 x1 += VP9_INTERP_EXTEND; | |
| 1916 x_pad = 1; | |
| 1917 } | |
| 1918 | |
| 1919 if (subpel_y || (sf->y_step_q4 != SUBPEL_SHIFTS)) { | |
| 1920 y0 -= VP9_INTERP_EXTEND - 1; | |
| 1921 y1 += VP9_INTERP_EXTEND; | |
| 1922 y_pad = 1; | |
| 1923 } | |
| 1924 | |
| 1925 // Wait until reference block is ready. Pad 7 more pixels as last 7 | |
| 1926 // pixels of each superblock row can be changed by next superblock row. | |
| 1927 if (pbi->frame_parallel_decode) | |
| 1928 vp9_frameworker_wait(pbi->frame_worker_owner, ref_frame_buf, | |
| 1929 MAX(0, (y1 + 7) << (plane == 0 ? 0 : 1))); | |
| 1930 | |
| 1931 // Skip border extension if block is inside the frame. | |
| 1932 if (x0 < 0 || x0 > frame_width - 1 || x1 < 0 || x1 > frame_width - 1 || | |
| 1933 y0 < 0 || y0 > frame_height - 1 || y1 < 0 || y1 > frame_height - 1) { | |
| 1934 uint8_t *buf_ptr1 = ref_frame + y0 * pre_buf->stride + x0; | |
| 1935 // Extend the border. | |
| 1936 #if CONFIG_VP9_HIGHBITDEPTH | 1928 #if CONFIG_VP9_HIGHBITDEPTH |
| 1937 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | 1929 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 1938 high_build_mc_border(buf_ptr1, | 1930 high_build_mc_border(buf_ptr1, |
| 1939 pre_buf->stride, | 1931 pre_buf->stride, |
| 1940 xd->mc_buf_high, | 1932 xd->mc_buf_high, |
| 1941 x1 - x0 + 1, | 1933 x1 - x0 + 1, |
| 1942 x0, | 1934 x0, |
| 1943 y0, | 1935 y0, |
| 1944 x1 - x0 + 1, | 1936 x1 - x0 + 1, |
| 1945 y1 - y0 + 1, | 1937 y1 - y0 + 1, |
| 1946 frame_width, | 1938 frame_width, |
| 1947 frame_height); | 1939 frame_height); |
| 1948 buf_stride = x1 - x0 + 1; | 1940 buf_stride = x1 - x0 + 1; |
| 1949 buf_ptr = CONVERT_TO_BYTEPTR(xd->mc_buf_high) + | 1941 buf_ptr = CONVERT_TO_BYTEPTR(xd->mc_buf_high) + |
| 1950 y_pad * 3 * buf_stride + x_pad * 3; | 1942 y_pad * 3 * buf_stride + x_pad * 3; |
| 1951 } else { | 1943 } else { |
| 1952 build_mc_border(buf_ptr1, | |
| 1953 pre_buf->stride, | |
| 1954 xd->mc_buf, | |
| 1955 x1 - x0 + 1, | |
| 1956 x0, | |
| 1957 y0, | |
| 1958 x1 - x0 + 1, | |
| 1959 y1 - y0 + 1, | |
| 1960 frame_width, | |
| 1961 frame_height); | |
| 1962 buf_stride = x1 - x0 + 1; | |
| 1963 buf_ptr = xd->mc_buf + y_pad * 3 * buf_stride + x_pad * 3; | |
| 1964 } | |
| 1965 #else | |
| 1966 build_mc_border(buf_ptr1, | 1944 build_mc_border(buf_ptr1, |
| 1967 pre_buf->stride, | 1945 pre_buf->stride, |
| 1968 xd->mc_buf, | 1946 xd->mc_buf, |
| 1969 x1 - x0 + 1, | 1947 x1 - x0 + 1, |
| 1970 x0, | 1948 x0, |
| 1971 y0, | 1949 y0, |
| 1972 x1 - x0 + 1, | 1950 x1 - x0 + 1, |
| 1973 y1 - y0 + 1, | 1951 y1 - y0 + 1, |
| 1974 frame_width, | 1952 frame_width, |
| 1975 frame_height); | 1953 frame_height); |
| 1976 buf_stride = x1 - x0 + 1; | 1954 buf_stride = x1 - x0 + 1; |
| 1977 buf_ptr = xd->mc_buf + y_pad * 3 * buf_stride + x_pad * 3; | 1955 buf_ptr = xd->mc_buf + y_pad * 3 * buf_stride + x_pad * 3; |
| 1956 } |
| 1957 #else |
| 1958 build_mc_border(buf_ptr1, |
| 1959 pre_buf->stride, |
| 1960 xd->mc_buf, |
| 1961 x1 - x0 + 1, |
| 1962 x0, |
| 1963 y0, |
| 1964 x1 - x0 + 1, |
| 1965 y1 - y0 + 1, |
| 1966 frame_width, |
| 1967 frame_height); |
| 1968 buf_stride = x1 - x0 + 1; |
| 1969 buf_ptr = xd->mc_buf + y_pad * 3 * buf_stride + x_pad * 3; |
| 1978 #endif // CONFIG_VP9_HIGHBITDEPTH | 1970 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 1979 } | |
| 1980 } else { | |
| 1981 // Wait until reference block is ready. Pad 7 more pixels as last 7 | |
| 1982 // pixels of each superblock row can be changed by next superblock row. | |
| 1983 if (pbi->frame_parallel_decode) | |
| 1984 vp9_frameworker_wait(pbi->frame_worker_owner, ref_frame_buf, | |
| 1985 MAX(0, (y1 + 7) << (plane == 0 ? 0 : 1))); | |
| 1986 } | 1971 } |
| 1972 } else { |
| 1973 // Wait until reference block is ready. Pad 7 more pixels as last 7 |
| 1974 // pixels of each superblock row can be changed by next superblock row. |
| 1975 if (pbi->frame_parallel_decode) { |
| 1976 const int y1 = ((y0_16 + (h - 1) * ys) >> SUBPEL_BITS) + 1; |
| 1977 vp9_frameworker_wait(pbi->frame_worker_owner, ref_frame_buf, |
| 1978 MAX(0, (y1 + 7)) << (plane == 0 ? 0 : 1)); |
| 1979 } |
| 1980 } |
| 1987 #if CONFIG_VP9_HIGHBITDEPTH | 1981 #if CONFIG_VP9_HIGHBITDEPTH |
| 1988 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { | 1982 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 1989 high_inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x, | 1983 high_inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x, |
| 1990 subpel_y, sf, w, h, ref, kernel, xs, ys, xd->bd); | 1984 subpel_y, sf, w, h, ref, kernel, xs, ys, xd->bd); |
| 1991 } else { | 1985 } else { |
| 1992 inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x, | |
| 1993 subpel_y, sf, w, h, ref, kernel, xs, ys); | |
| 1994 } | |
| 1995 #else | |
| 1996 inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x, | 1986 inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x, |
| 1997 subpel_y, sf, w, h, ref, kernel, xs, ys); | 1987 subpel_y, sf, w, h, ref, kernel, xs, ys); |
| 1988 } |
| 1989 #else |
| 1990 inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x, |
| 1991 subpel_y, sf, w, h, ref, kernel, xs, ys); |
| 1998 #endif // CONFIG_VP9_HIGHBITDEPTH | 1992 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 1999 } | |
| 2000 } | 1993 } |
| 2001 | 1994 |
| 2002 void vp9_dec_build_inter_predictors_sb(VP9Decoder *const pbi, MACROBLOCKD *xd, | 1995 void vp9_dec_build_inter_predictors_sb(VP9Decoder *const pbi, MACROBLOCKD *xd, |
| 2003 int mi_row, int mi_col, | 1996 int mi_row, int mi_col, |
| 2004 BLOCK_SIZE bsize) { | 1997 BLOCK_SIZE bsize) { |
| 2005 int plane; | 1998 int plane; |
| 2006 const int mi_x = mi_col * MI_SIZE; | 1999 const int mi_x = mi_col * MI_SIZE; |
| 2007 const int mi_y = mi_row * MI_SIZE; | 2000 const int mi_y = mi_row * MI_SIZE; |
| 2001 const MODE_INFO *mi = xd->mi[0]; |
| 2002 const InterpKernel *kernel = vp9_get_interp_kernel(mi->mbmi.interp_filter); |
| 2003 const BLOCK_SIZE sb_type = mi->mbmi.sb_type; |
| 2004 const int is_compound = has_second_ref(&mi->mbmi); |
| 2005 |
| 2008 for (plane = 0; plane < MAX_MB_PLANE; ++plane) { | 2006 for (plane = 0; plane < MAX_MB_PLANE; ++plane) { |
| 2009 const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, | 2007 const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, |
| 2010 &xd->plane[plane]); | 2008 &xd->plane[plane]); |
| 2009 struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 2010 struct buf_2d *const dst_buf = &pd->dst; |
| 2011 const int num_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize]; | 2011 const int num_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize]; |
| 2012 const int num_4x4_h = num_4x4_blocks_high_lookup[plane_bsize]; | 2012 const int num_4x4_h = num_4x4_blocks_high_lookup[plane_bsize]; |
| 2013 |
| 2013 const int bw = 4 * num_4x4_w; | 2014 const int bw = 4 * num_4x4_w; |
| 2014 const int bh = 4 * num_4x4_h; | 2015 const int bh = 4 * num_4x4_h; |
| 2016 int ref; |
| 2015 | 2017 |
| 2016 if (xd->mi[0].src_mi->mbmi.sb_type < BLOCK_8X8) { | 2018 for (ref = 0; ref < 1 + is_compound; ++ref) { |
| 2017 int i = 0, x, y; | 2019 const struct scale_factors *const sf = &xd->block_refs[ref]->sf; |
| 2018 assert(bsize == BLOCK_8X8); | 2020 struct buf_2d *const pre_buf = &pd->pre[ref]; |
| 2019 for (y = 0; y < num_4x4_h; ++y) | 2021 const int idx = xd->block_refs[ref]->idx; |
| 2020 for (x = 0; x < num_4x4_w; ++x) | 2022 BufferPool *const pool = pbi->common.buffer_pool; |
| 2021 dec_build_inter_predictors(pbi, xd, plane, i++, bw, bh, | 2023 RefCntBuffer *const ref_frame_buf = &pool->frame_bufs[idx]; |
| 2022 4 * x, 4 * y, 4, 4, mi_x, mi_y); | 2024 const int is_scaled = vp9_is_scaled(sf); |
| 2023 } else { | 2025 |
| 2024 dec_build_inter_predictors(pbi, xd, plane, 0, bw, bh, | 2026 if (sb_type < BLOCK_8X8) { |
| 2025 0, 0, bw, bh, mi_x, mi_y); | 2027 int i = 0, x, y; |
| 2028 assert(bsize == BLOCK_8X8); |
| 2029 for (y = 0; y < num_4x4_h; ++y) { |
| 2030 for (x = 0; x < num_4x4_w; ++x) { |
| 2031 const MV mv = average_split_mvs(pd, mi, ref, i++); |
| 2032 dec_build_inter_predictors(pbi, xd, plane, bw, bh, |
| 2033 4 * x, 4 * y, 4, 4, mi_x, mi_y, kernel, |
| 2034 sf, pre_buf, dst_buf, &mv, |
| 2035 ref_frame_buf, is_scaled, ref); |
| 2036 } |
| 2037 } |
| 2038 } else { |
| 2039 const MV mv = mi->mbmi.mv[ref].as_mv; |
| 2040 dec_build_inter_predictors(pbi, xd, plane, bw, bh, |
| 2041 0, 0, bw, bh, mi_x, mi_y, kernel, |
| 2042 sf, pre_buf, dst_buf, &mv, ref_frame_buf, |
| 2043 is_scaled, ref); |
| 2044 } |
| 2026 } | 2045 } |
| 2027 } | 2046 } |
| 2028 } | 2047 } |
| OLD | NEW |