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 |
11 #include <assert.h> | 11 #include <assert.h> |
12 #include <stdlib.h> // qsort() | 12 #include <stdlib.h> // qsort() |
13 | 13 |
14 #include "./vp9_rtcd.h" | 14 #include "./vp9_rtcd.h" |
15 #include "./vpx_scale_rtcd.h" | 15 #include "./vpx_scale_rtcd.h" |
16 | 16 |
17 #include "vpx_mem/vpx_mem.h" | 17 #include "vpx_mem/vpx_mem.h" |
18 #include "vpx_ports/mem_ops.h" | 18 #include "vpx_ports/mem_ops.h" |
19 #include "vpx_scale/vpx_scale.h" | 19 #include "vpx_scale/vpx_scale.h" |
20 | 20 |
21 #include "vp9/common/vp9_alloccommon.h" | 21 #include "vp9/common/vp9_alloccommon.h" |
22 #include "vp9/common/vp9_common.h" | 22 #include "vp9/common/vp9_common.h" |
23 #include "vp9/common/vp9_entropy.h" | 23 #include "vp9/common/vp9_entropy.h" |
24 #include "vp9/common/vp9_entropymode.h" | 24 #include "vp9/common/vp9_entropymode.h" |
25 #include "vp9/common/vp9_idct.h" | 25 #include "vp9/common/vp9_idct.h" |
| 26 #include "vp9/common/vp9_loopfilter_thread.h" |
26 #include "vp9/common/vp9_pred_common.h" | 27 #include "vp9/common/vp9_pred_common.h" |
27 #include "vp9/common/vp9_quant_common.h" | 28 #include "vp9/common/vp9_quant_common.h" |
28 #include "vp9/common/vp9_reconintra.h" | 29 #include "vp9/common/vp9_reconintra.h" |
29 #include "vp9/common/vp9_reconinter.h" | 30 #include "vp9/common/vp9_reconinter.h" |
30 #include "vp9/common/vp9_seg_common.h" | 31 #include "vp9/common/vp9_seg_common.h" |
31 #include "vp9/common/vp9_thread.h" | 32 #include "vp9/common/vp9_thread.h" |
32 #include "vp9/common/vp9_tile_common.h" | 33 #include "vp9/common/vp9_tile_common.h" |
33 | 34 |
34 #include "vp9/decoder/vp9_decodeframe.h" | 35 #include "vp9/decoder/vp9_decodeframe.h" |
35 #include "vp9/decoder/vp9_detokenize.h" | 36 #include "vp9/decoder/vp9_detokenize.h" |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 vpx_memset(dqcoeff, 0, 256 * sizeof(dqcoeff[0])); | 292 vpx_memset(dqcoeff, 0, 256 * sizeof(dqcoeff[0])); |
292 else | 293 else |
293 vpx_memset(dqcoeff, 0, (16 << (tx_size << 1)) * sizeof(dqcoeff[0])); | 294 vpx_memset(dqcoeff, 0, (16 << (tx_size << 1)) * sizeof(dqcoeff[0])); |
294 } | 295 } |
295 } | 296 } |
296 } | 297 } |
297 | 298 |
298 struct intra_args { | 299 struct intra_args { |
299 VP9_COMMON *cm; | 300 VP9_COMMON *cm; |
300 MACROBLOCKD *xd; | 301 MACROBLOCKD *xd; |
| 302 FRAME_COUNTS *counts; |
301 vp9_reader *r; | 303 vp9_reader *r; |
302 }; | 304 }; |
303 | 305 |
304 static void predict_and_reconstruct_intra_block(int plane, int block, | 306 static void predict_and_reconstruct_intra_block(int plane, int block, |
305 BLOCK_SIZE plane_bsize, | 307 BLOCK_SIZE plane_bsize, |
306 TX_SIZE tx_size, void *arg) { | 308 TX_SIZE tx_size, void *arg) { |
307 struct intra_args *const args = (struct intra_args *)arg; | 309 struct intra_args *const args = (struct intra_args *)arg; |
308 VP9_COMMON *const cm = args->cm; | 310 VP9_COMMON *const cm = args->cm; |
309 MACROBLOCKD *const xd = args->xd; | 311 MACROBLOCKD *const xd = args->xd; |
310 struct macroblockd_plane *const pd = &xd->plane[plane]; | 312 struct macroblockd_plane *const pd = &xd->plane[plane]; |
311 MODE_INFO *const mi = xd->mi[0].src_mi; | 313 MODE_INFO *const mi = xd->mi[0].src_mi; |
312 const PREDICTION_MODE mode = (plane == 0) ? get_y_mode(mi, block) | 314 const PREDICTION_MODE mode = (plane == 0) ? get_y_mode(mi, block) |
313 : mi->mbmi.uv_mode; | 315 : mi->mbmi.uv_mode; |
314 int x, y; | 316 int x, y; |
315 uint8_t *dst; | 317 uint8_t *dst; |
316 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x, &y); | 318 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x, &y); |
317 dst = &pd->dst.buf[4 * y * pd->dst.stride + 4 * x]; | 319 dst = &pd->dst.buf[4 * y * pd->dst.stride + 4 * x]; |
318 | 320 |
319 vp9_predict_intra_block(xd, block >> (tx_size << 1), | 321 vp9_predict_intra_block(xd, block >> (tx_size << 1), |
320 b_width_log2_lookup[plane_bsize], tx_size, mode, | 322 b_width_log2_lookup[plane_bsize], tx_size, mode, |
321 dst, pd->dst.stride, dst, pd->dst.stride, | 323 dst, pd->dst.stride, dst, pd->dst.stride, |
322 x, y, plane); | 324 x, y, plane); |
323 | 325 |
324 if (!mi->mbmi.skip) { | 326 if (!mi->mbmi.skip) { |
325 const int eob = vp9_decode_block_tokens(cm, xd, plane, block, | 327 const int eob = vp9_decode_block_tokens(cm, xd, args->counts, plane, block, |
326 plane_bsize, x, y, tx_size, | 328 plane_bsize, x, y, tx_size, |
327 args->r); | 329 args->r); |
328 inverse_transform_block(xd, plane, block, tx_size, dst, pd->dst.stride, | 330 inverse_transform_block(xd, plane, block, tx_size, dst, pd->dst.stride, |
329 eob); | 331 eob); |
330 } | 332 } |
331 } | 333 } |
332 | 334 |
333 struct inter_args { | 335 struct inter_args { |
334 VP9_COMMON *cm; | 336 VP9_COMMON *cm; |
335 MACROBLOCKD *xd; | 337 MACROBLOCKD *xd; |
336 vp9_reader *r; | 338 vp9_reader *r; |
| 339 FRAME_COUNTS *counts; |
337 int *eobtotal; | 340 int *eobtotal; |
338 }; | 341 }; |
339 | 342 |
340 static void reconstruct_inter_block(int plane, int block, | 343 static void reconstruct_inter_block(int plane, int block, |
341 BLOCK_SIZE plane_bsize, | 344 BLOCK_SIZE plane_bsize, |
342 TX_SIZE tx_size, void *arg) { | 345 TX_SIZE tx_size, void *arg) { |
343 struct inter_args *args = (struct inter_args *)arg; | 346 struct inter_args *args = (struct inter_args *)arg; |
344 VP9_COMMON *const cm = args->cm; | 347 VP9_COMMON *const cm = args->cm; |
345 MACROBLOCKD *const xd = args->xd; | 348 MACROBLOCKD *const xd = args->xd; |
346 struct macroblockd_plane *const pd = &xd->plane[plane]; | 349 struct macroblockd_plane *const pd = &xd->plane[plane]; |
347 int x, y, eob; | 350 int x, y, eob; |
348 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x, &y); | 351 txfrm_block_to_raster_xy(plane_bsize, tx_size, block, &x, &y); |
349 eob = vp9_decode_block_tokens(cm, xd, plane, block, plane_bsize, x, y, | 352 eob = vp9_decode_block_tokens(cm, xd, args->counts, plane, block, plane_bsize, |
350 tx_size, args->r); | 353 x, y, tx_size, args->r); |
351 inverse_transform_block(xd, plane, block, tx_size, | 354 inverse_transform_block(xd, plane, block, tx_size, |
352 &pd->dst.buf[4 * y * pd->dst.stride + 4 * x], | 355 &pd->dst.buf[4 * y * pd->dst.stride + 4 * x], |
353 pd->dst.stride, eob); | 356 pd->dst.stride, eob); |
354 *args->eobtotal += eob; | 357 *args->eobtotal += eob; |
355 } | 358 } |
356 | 359 |
357 static MB_MODE_INFO *set_offsets(VP9_COMMON *const cm, MACROBLOCKD *const xd, | 360 static MB_MODE_INFO *set_offsets(VP9_COMMON *const cm, MACROBLOCKD *const xd, |
358 const TileInfo *const tile, | 361 const TileInfo *const tile, |
359 BLOCK_SIZE bsize, int mi_row, int mi_col) { | 362 BLOCK_SIZE bsize, int mi_row, int mi_col) { |
360 const int bw = num_8x8_blocks_wide_lookup[bsize]; | 363 const int bw = num_8x8_blocks_wide_lookup[bsize]; |
(...skipping 15 matching lines...) Expand all Loading... |
376 set_skip_context(xd, mi_row, mi_col); | 379 set_skip_context(xd, mi_row, mi_col); |
377 | 380 |
378 // Distance of Mb to the various image edges. These are specified to 8th pel | 381 // Distance of Mb to the various image edges. These are specified to 8th pel |
379 // as they are always compared to values that are in 1/8th pel units | 382 // as they are always compared to values that are in 1/8th pel units |
380 set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw, cm->mi_rows, cm->mi_cols); | 383 set_mi_row_col(xd, tile, mi_row, bh, mi_col, bw, cm->mi_rows, cm->mi_cols); |
381 | 384 |
382 vp9_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col); | 385 vp9_setup_dst_planes(xd->plane, get_frame_new_buffer(cm), mi_row, mi_col); |
383 return &xd->mi[0].mbmi; | 386 return &xd->mi[0].mbmi; |
384 } | 387 } |
385 | 388 |
386 static void decode_block(VP9_COMMON *const cm, MACROBLOCKD *const xd, | 389 static void decode_block(VP9Decoder *const pbi, MACROBLOCKD *const xd, |
| 390 FRAME_COUNTS *counts, |
387 const TileInfo *const tile, | 391 const TileInfo *const tile, |
388 int mi_row, int mi_col, | 392 int mi_row, int mi_col, |
389 vp9_reader *r, BLOCK_SIZE bsize) { | 393 vp9_reader *r, BLOCK_SIZE bsize) { |
| 394 VP9_COMMON *const cm = &pbi->common; |
390 const int less8x8 = bsize < BLOCK_8X8; | 395 const int less8x8 = bsize < BLOCK_8X8; |
391 MB_MODE_INFO *mbmi = set_offsets(cm, xd, tile, bsize, mi_row, mi_col); | 396 MB_MODE_INFO *mbmi = set_offsets(cm, xd, tile, bsize, mi_row, mi_col); |
392 vp9_read_mode_info(cm, xd, tile, mi_row, mi_col, r); | 397 vp9_read_mode_info(pbi, xd, counts, tile, mi_row, mi_col, r); |
393 | 398 |
394 if (less8x8) | 399 if (less8x8) |
395 bsize = BLOCK_8X8; | 400 bsize = BLOCK_8X8; |
396 | 401 |
397 if (mbmi->skip) { | 402 if (mbmi->skip) { |
398 reset_skip_context(xd, bsize); | 403 reset_skip_context(xd, bsize); |
399 } else { | 404 } else { |
400 if (cm->seg.enabled) | 405 if (cm->seg.enabled) |
401 setup_plane_dequants(cm, xd, vp9_get_qindex(&cm->seg, mbmi->segment_id, | 406 setup_plane_dequants(cm, xd, vp9_get_qindex(&cm->seg, mbmi->segment_id, |
402 cm->base_qindex)); | 407 cm->base_qindex)); |
403 } | 408 } |
404 | 409 |
405 if (!is_inter_block(mbmi)) { | 410 if (!is_inter_block(mbmi)) { |
406 struct intra_args arg = { cm, xd, r }; | 411 struct intra_args arg = { cm, xd, counts, r }; |
407 vp9_foreach_transformed_block(xd, bsize, | 412 vp9_foreach_transformed_block(xd, bsize, |
408 predict_and_reconstruct_intra_block, &arg); | 413 predict_and_reconstruct_intra_block, &arg); |
409 } else { | 414 } else { |
410 // Prediction | 415 // Prediction |
411 vp9_dec_build_inter_predictors_sb(xd, mi_row, mi_col, bsize); | 416 vp9_dec_build_inter_predictors_sb(pbi, xd, mi_row, mi_col, bsize); |
412 | 417 |
413 // Reconstruction | 418 // Reconstruction |
414 if (!mbmi->skip) { | 419 if (!mbmi->skip) { |
415 int eobtotal = 0; | 420 int eobtotal = 0; |
416 struct inter_args arg = { cm, xd, r, &eobtotal }; | 421 struct inter_args arg = { cm, xd, r, counts, &eobtotal }; |
417 vp9_foreach_transformed_block(xd, bsize, reconstruct_inter_block, &arg); | 422 vp9_foreach_transformed_block(xd, bsize, reconstruct_inter_block, &arg); |
418 if (!less8x8 && eobtotal == 0) | 423 if (!less8x8 && eobtotal == 0) |
419 mbmi->skip = 1; // skip loopfilter | 424 mbmi->skip = 1; // skip loopfilter |
420 } | 425 } |
421 } | 426 } |
422 | 427 |
423 xd->corrupted |= vp9_reader_has_error(r); | 428 xd->corrupted |= vp9_reader_has_error(r); |
424 } | 429 } |
425 | 430 |
426 static PARTITION_TYPE read_partition(VP9_COMMON *cm, MACROBLOCKD *xd, int hbs, | 431 static PARTITION_TYPE read_partition(VP9_COMMON *cm, MACROBLOCKD *xd, |
| 432 FRAME_COUNTS *counts, int hbs, |
427 int mi_row, int mi_col, BLOCK_SIZE bsize, | 433 int mi_row, int mi_col, BLOCK_SIZE bsize, |
428 vp9_reader *r) { | 434 vp9_reader *r) { |
429 const int ctx = partition_plane_context(xd, mi_row, mi_col, bsize); | 435 const int ctx = partition_plane_context(xd, mi_row, mi_col, bsize); |
430 const vp9_prob *const probs = get_partition_probs(cm, ctx); | 436 const vp9_prob *const probs = get_partition_probs(cm, ctx); |
431 const int has_rows = (mi_row + hbs) < cm->mi_rows; | 437 const int has_rows = (mi_row + hbs) < cm->mi_rows; |
432 const int has_cols = (mi_col + hbs) < cm->mi_cols; | 438 const int has_cols = (mi_col + hbs) < cm->mi_cols; |
433 PARTITION_TYPE p; | 439 PARTITION_TYPE p; |
434 | 440 |
435 if (has_rows && has_cols) | 441 if (has_rows && has_cols) |
436 p = (PARTITION_TYPE)vp9_read_tree(r, vp9_partition_tree, probs); | 442 p = (PARTITION_TYPE)vp9_read_tree(r, vp9_partition_tree, probs); |
437 else if (!has_rows && has_cols) | 443 else if (!has_rows && has_cols) |
438 p = vp9_read(r, probs[1]) ? PARTITION_SPLIT : PARTITION_HORZ; | 444 p = vp9_read(r, probs[1]) ? PARTITION_SPLIT : PARTITION_HORZ; |
439 else if (has_rows && !has_cols) | 445 else if (has_rows && !has_cols) |
440 p = vp9_read(r, probs[2]) ? PARTITION_SPLIT : PARTITION_VERT; | 446 p = vp9_read(r, probs[2]) ? PARTITION_SPLIT : PARTITION_VERT; |
441 else | 447 else |
442 p = PARTITION_SPLIT; | 448 p = PARTITION_SPLIT; |
443 | 449 |
444 if (!cm->frame_parallel_decoding_mode) | 450 if (!cm->frame_parallel_decoding_mode) |
445 ++cm->counts.partition[ctx][p]; | 451 ++counts->partition[ctx][p]; |
446 | 452 |
447 return p; | 453 return p; |
448 } | 454 } |
449 | 455 |
450 static void decode_partition(VP9_COMMON *const cm, MACROBLOCKD *const xd, | 456 static void decode_partition(VP9Decoder *const pbi, MACROBLOCKD *const xd, |
| 457 FRAME_COUNTS *counts, |
451 const TileInfo *const tile, | 458 const TileInfo *const tile, |
452 int mi_row, int mi_col, | 459 int mi_row, int mi_col, |
453 vp9_reader* r, BLOCK_SIZE bsize) { | 460 vp9_reader* r, BLOCK_SIZE bsize) { |
| 461 VP9_COMMON *const cm = &pbi->common; |
454 const int hbs = num_8x8_blocks_wide_lookup[bsize] / 2; | 462 const int hbs = num_8x8_blocks_wide_lookup[bsize] / 2; |
455 PARTITION_TYPE partition; | 463 PARTITION_TYPE partition; |
456 BLOCK_SIZE subsize, uv_subsize; | 464 BLOCK_SIZE subsize, uv_subsize; |
457 | 465 |
458 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) | 466 if (mi_row >= cm->mi_rows || mi_col >= cm->mi_cols) |
459 return; | 467 return; |
460 | 468 |
461 partition = read_partition(cm, xd, hbs, mi_row, mi_col, bsize, r); | 469 partition = read_partition(cm, xd, counts, hbs, mi_row, mi_col, bsize, r); |
462 subsize = get_subsize(bsize, partition); | 470 subsize = get_subsize(bsize, partition); |
463 uv_subsize = ss_size_lookup[subsize][cm->subsampling_x][cm->subsampling_y]; | 471 uv_subsize = ss_size_lookup[subsize][cm->subsampling_x][cm->subsampling_y]; |
464 if (subsize >= BLOCK_8X8 && uv_subsize == BLOCK_INVALID) | 472 if (subsize >= BLOCK_8X8 && uv_subsize == BLOCK_INVALID) |
465 vpx_internal_error(xd->error_info, | 473 vpx_internal_error(xd->error_info, |
466 VPX_CODEC_CORRUPT_FRAME, "Invalid block size."); | 474 VPX_CODEC_CORRUPT_FRAME, "Invalid block size."); |
467 if (subsize < BLOCK_8X8) { | 475 if (subsize < BLOCK_8X8) { |
468 decode_block(cm, xd, tile, mi_row, mi_col, r, subsize); | 476 decode_block(pbi, xd, counts, tile, mi_row, mi_col, r, subsize); |
469 } else { | 477 } else { |
470 switch (partition) { | 478 switch (partition) { |
471 case PARTITION_NONE: | 479 case PARTITION_NONE: |
472 decode_block(cm, xd, tile, mi_row, mi_col, r, subsize); | 480 decode_block(pbi, xd, counts, tile, mi_row, mi_col, r, subsize); |
473 break; | 481 break; |
474 case PARTITION_HORZ: | 482 case PARTITION_HORZ: |
475 decode_block(cm, xd, tile, mi_row, mi_col, r, subsize); | 483 decode_block(pbi, xd, counts, tile, mi_row, mi_col, r, subsize); |
476 if (mi_row + hbs < cm->mi_rows) | 484 if (mi_row + hbs < cm->mi_rows) |
477 decode_block(cm, xd, tile, mi_row + hbs, mi_col, r, subsize); | 485 decode_block(pbi, xd, counts, tile, mi_row + hbs, mi_col, r, subsize); |
478 break; | 486 break; |
479 case PARTITION_VERT: | 487 case PARTITION_VERT: |
480 decode_block(cm, xd, tile, mi_row, mi_col, r, subsize); | 488 decode_block(pbi, xd, counts, tile, mi_row, mi_col, r, subsize); |
481 if (mi_col + hbs < cm->mi_cols) | 489 if (mi_col + hbs < cm->mi_cols) |
482 decode_block(cm, xd, tile, mi_row, mi_col + hbs, r, subsize); | 490 decode_block(pbi, xd, counts, tile, mi_row, mi_col + hbs, r, subsize); |
483 break; | 491 break; |
484 case PARTITION_SPLIT: | 492 case PARTITION_SPLIT: |
485 decode_partition(cm, xd, tile, mi_row, mi_col, r, subsize); | 493 decode_partition(pbi, xd, counts, tile, mi_row, mi_col, r, subsize); |
486 decode_partition(cm, xd, tile, mi_row, mi_col + hbs, r, subsize); | 494 decode_partition(pbi, xd, counts, tile, mi_row, mi_col + hbs, r, |
487 decode_partition(cm, xd, tile, mi_row + hbs, mi_col, r, subsize); | 495 subsize); |
488 decode_partition(cm, xd, tile, mi_row + hbs, mi_col + hbs, r, subsize); | 496 decode_partition(pbi, xd, counts, tile, mi_row + hbs, mi_col, r, |
| 497 subsize); |
| 498 decode_partition(pbi, xd, counts, tile, mi_row + hbs, mi_col + hbs, r, |
| 499 subsize); |
489 break; | 500 break; |
490 default: | 501 default: |
491 assert(0 && "Invalid partition type"); | 502 assert(0 && "Invalid partition type"); |
492 } | 503 } |
493 } | 504 } |
494 | 505 |
495 // update partition context | 506 // update partition context |
496 if (bsize >= BLOCK_8X8 && | 507 if (bsize >= BLOCK_8X8 && |
497 (bsize == BLOCK_8X8 || partition != PARTITION_SPLIT)) | 508 (bsize == BLOCK_8X8 || partition != PARTITION_SPLIT)) |
498 update_partition_context(xd, mi_row, mi_col, subsize, bsize); | 509 update_partition_context(xd, mi_row, mi_col, subsize, bsize); |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
700 cm->height = height; | 711 cm->height = height; |
701 } | 712 } |
702 if (cm->cur_frame->mvs == NULL || cm->mi_rows > cm->cur_frame->mi_rows || | 713 if (cm->cur_frame->mvs == NULL || cm->mi_rows > cm->cur_frame->mi_rows || |
703 cm->mi_cols > cm->cur_frame->mi_cols) { | 714 cm->mi_cols > cm->cur_frame->mi_cols) { |
704 resize_mv_buffer(cm); | 715 resize_mv_buffer(cm); |
705 } | 716 } |
706 } | 717 } |
707 | 718 |
708 static void setup_frame_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { | 719 static void setup_frame_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { |
709 int width, height; | 720 int width, height; |
| 721 BufferPool *const pool = cm->buffer_pool; |
710 vp9_read_frame_size(rb, &width, &height); | 722 vp9_read_frame_size(rb, &width, &height); |
711 resize_context_buffers(cm, width, height); | 723 resize_context_buffers(cm, width, height); |
712 setup_display_size(cm, rb); | 724 setup_display_size(cm, rb); |
713 | 725 |
| 726 lock_buffer_pool(pool); |
714 if (vp9_realloc_frame_buffer( | 727 if (vp9_realloc_frame_buffer( |
715 get_frame_new_buffer(cm), cm->width, cm->height, | 728 get_frame_new_buffer(cm), cm->width, cm->height, |
716 cm->subsampling_x, cm->subsampling_y, | 729 cm->subsampling_x, cm->subsampling_y, |
717 #if CONFIG_VP9_HIGHBITDEPTH | 730 #if CONFIG_VP9_HIGHBITDEPTH |
718 cm->use_highbitdepth, | 731 cm->use_highbitdepth, |
719 #endif | 732 #endif |
720 VP9_DEC_BORDER_IN_PIXELS, | 733 VP9_DEC_BORDER_IN_PIXELS, |
721 cm->byte_alignment, | 734 cm->byte_alignment, |
722 &cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer, cm->get_fb_cb, | 735 &pool->frame_bufs[cm->new_fb_idx].raw_frame_buffer, pool->get_fb_cb, |
723 cm->cb_priv)) { | 736 pool->cb_priv)) { |
| 737 unlock_buffer_pool(pool); |
724 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 738 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
725 "Failed to allocate frame buffer"); | 739 "Failed to allocate frame buffer"); |
726 } | 740 } |
727 cm->frame_bufs[cm->new_fb_idx].buf.subsampling_x = cm->subsampling_x; | 741 unlock_buffer_pool(pool); |
728 cm->frame_bufs[cm->new_fb_idx].buf.subsampling_y = cm->subsampling_y; | 742 |
729 cm->frame_bufs[cm->new_fb_idx].buf.color_space = | 743 pool->frame_bufs[cm->new_fb_idx].buf.subsampling_x = cm->subsampling_x; |
730 (vpx_color_space_t)cm->color_space; | 744 pool->frame_bufs[cm->new_fb_idx].buf.subsampling_y = cm->subsampling_y; |
731 cm->frame_bufs[cm->new_fb_idx].buf.bit_depth = (unsigned int)cm->bit_depth; | 745 pool->frame_bufs[cm->new_fb_idx].buf.bit_depth = (unsigned int)cm->bit_depth; |
732 } | 746 } |
733 | 747 |
734 static INLINE int valid_ref_frame_img_fmt(vpx_bit_depth_t ref_bit_depth, | 748 static INLINE int valid_ref_frame_img_fmt(vpx_bit_depth_t ref_bit_depth, |
735 int ref_xss, int ref_yss, | 749 int ref_xss, int ref_yss, |
736 vpx_bit_depth_t this_bit_depth, | 750 vpx_bit_depth_t this_bit_depth, |
737 int this_xss, int this_yss) { | 751 int this_xss, int this_yss) { |
738 return ref_bit_depth == this_bit_depth && ref_xss == this_xss && | 752 return ref_bit_depth == this_bit_depth && ref_xss == this_xss && |
739 ref_yss == this_yss; | 753 ref_yss == this_yss; |
740 } | 754 } |
741 | 755 |
742 static void setup_frame_size_with_refs(VP9_COMMON *cm, | 756 static void setup_frame_size_with_refs(VP9_COMMON *cm, |
743 struct vp9_read_bit_buffer *rb) { | 757 struct vp9_read_bit_buffer *rb) { |
744 int width, height; | 758 int width, height; |
745 int found = 0, i; | 759 int found = 0, i; |
746 int has_valid_ref_frame = 0; | 760 int has_valid_ref_frame = 0; |
| 761 BufferPool *const pool = cm->buffer_pool; |
747 for (i = 0; i < REFS_PER_FRAME; ++i) { | 762 for (i = 0; i < REFS_PER_FRAME; ++i) { |
748 if (vp9_rb_read_bit(rb)) { | 763 if (vp9_rb_read_bit(rb)) { |
749 YV12_BUFFER_CONFIG *const buf = cm->frame_refs[i].buf; | 764 YV12_BUFFER_CONFIG *const buf = cm->frame_refs[i].buf; |
750 width = buf->y_crop_width; | 765 width = buf->y_crop_width; |
751 height = buf->y_crop_height; | 766 height = buf->y_crop_height; |
752 found = 1; | 767 found = 1; |
753 break; | 768 break; |
754 } | 769 } |
755 } | 770 } |
756 | 771 |
(...skipping 24 matching lines...) Expand all Loading... |
781 cm->bit_depth, | 796 cm->bit_depth, |
782 cm->subsampling_x, | 797 cm->subsampling_x, |
783 cm->subsampling_y)) | 798 cm->subsampling_y)) |
784 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, | 799 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, |
785 "Referenced frame has incompatible color format"); | 800 "Referenced frame has incompatible color format"); |
786 } | 801 } |
787 | 802 |
788 resize_context_buffers(cm, width, height); | 803 resize_context_buffers(cm, width, height); |
789 setup_display_size(cm, rb); | 804 setup_display_size(cm, rb); |
790 | 805 |
| 806 lock_buffer_pool(pool); |
791 if (vp9_realloc_frame_buffer( | 807 if (vp9_realloc_frame_buffer( |
792 get_frame_new_buffer(cm), cm->width, cm->height, | 808 get_frame_new_buffer(cm), cm->width, cm->height, |
793 cm->subsampling_x, cm->subsampling_y, | 809 cm->subsampling_x, cm->subsampling_y, |
794 #if CONFIG_VP9_HIGHBITDEPTH | 810 #if CONFIG_VP9_HIGHBITDEPTH |
795 cm->use_highbitdepth, | 811 cm->use_highbitdepth, |
796 #endif | 812 #endif |
797 VP9_DEC_BORDER_IN_PIXELS, | 813 VP9_DEC_BORDER_IN_PIXELS, |
798 cm->byte_alignment, | 814 cm->byte_alignment, |
799 &cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer, cm->get_fb_cb, | 815 &pool->frame_bufs[cm->new_fb_idx].raw_frame_buffer, pool->get_fb_cb, |
800 cm->cb_priv)) { | 816 pool->cb_priv)) { |
| 817 unlock_buffer_pool(pool); |
801 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 818 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
802 "Failed to allocate frame buffer"); | 819 "Failed to allocate frame buffer"); |
803 } | 820 } |
804 cm->frame_bufs[cm->new_fb_idx].buf.subsampling_x = cm->subsampling_x; | 821 unlock_buffer_pool(pool); |
805 cm->frame_bufs[cm->new_fb_idx].buf.subsampling_y = cm->subsampling_y; | 822 |
806 cm->frame_bufs[cm->new_fb_idx].buf.bit_depth = (unsigned int)cm->bit_depth; | 823 pool->frame_bufs[cm->new_fb_idx].buf.subsampling_x = cm->subsampling_x; |
| 824 pool->frame_bufs[cm->new_fb_idx].buf.subsampling_y = cm->subsampling_y; |
| 825 pool->frame_bufs[cm->new_fb_idx].buf.bit_depth = (unsigned int)cm->bit_depth; |
807 } | 826 } |
808 | 827 |
809 static void setup_tile_info(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { | 828 static void setup_tile_info(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { |
810 int min_log2_tile_cols, max_log2_tile_cols, max_ones; | 829 int min_log2_tile_cols, max_log2_tile_cols, max_ones; |
811 vp9_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols); | 830 vp9_get_tile_n_bits(cm->mi_cols, &min_log2_tile_cols, &max_log2_tile_cols); |
812 | 831 |
813 // columns | 832 // columns |
814 max_ones = max_log2_tile_cols - min_log2_tile_cols; | 833 max_ones = max_log2_tile_cols - min_log2_tile_cols; |
815 cm->log2_tile_cols = min_log2_tile_cols; | 834 cm->log2_tile_cols = min_log2_tile_cols; |
816 while (max_ones-- && vp9_rb_read_bit(rb)) | 835 while (max_ones-- && vp9_rb_read_bit(rb)) |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
965 mi_row += MI_BLOCK_SIZE) { | 984 mi_row += MI_BLOCK_SIZE) { |
966 for (tile_col = 0; tile_col < tile_cols; ++tile_col) { | 985 for (tile_col = 0; tile_col < tile_cols; ++tile_col) { |
967 const int col = pbi->inv_tile_order ? | 986 const int col = pbi->inv_tile_order ? |
968 tile_cols - tile_col - 1 : tile_col; | 987 tile_cols - tile_col - 1 : tile_col; |
969 tile_data = pbi->tile_data + tile_cols * tile_row + col; | 988 tile_data = pbi->tile_data + tile_cols * tile_row + col; |
970 vp9_tile_set_col(&tile, tile_data->cm, col); | 989 vp9_tile_set_col(&tile, tile_data->cm, col); |
971 vp9_zero(tile_data->xd.left_context); | 990 vp9_zero(tile_data->xd.left_context); |
972 vp9_zero(tile_data->xd.left_seg_context); | 991 vp9_zero(tile_data->xd.left_seg_context); |
973 for (mi_col = tile.mi_col_start; mi_col < tile.mi_col_end; | 992 for (mi_col = tile.mi_col_start; mi_col < tile.mi_col_end; |
974 mi_col += MI_BLOCK_SIZE) { | 993 mi_col += MI_BLOCK_SIZE) { |
975 decode_partition(tile_data->cm, &tile_data->xd, &tile, mi_row, mi_col, | 994 decode_partition(pbi, &tile_data->xd, &cm->counts, &tile, mi_row, |
976 &tile_data->bit_reader, BLOCK_64X64); | 995 mi_col, &tile_data->bit_reader, BLOCK_64X64); |
977 } | 996 } |
978 pbi->mb.corrupted |= tile_data->xd.corrupted; | 997 pbi->mb.corrupted |= tile_data->xd.corrupted; |
979 if (pbi->mb.corrupted) | 998 if (pbi->mb.corrupted) |
980 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, | 999 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, |
981 "Failed to decode tile data"); | 1000 "Failed to decode tile data"); |
982 } | 1001 } |
983 // Loopfilter one row. | 1002 // Loopfilter one row. |
984 if (cm->lf.filter_level) { | 1003 if (cm->lf.filter_level) { |
985 const int lf_start = mi_row - MI_BLOCK_SIZE; | 1004 const int lf_start = mi_row - MI_BLOCK_SIZE; |
986 LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1; | 1005 LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1; |
987 | 1006 |
988 // delay the loopfilter by 1 macroblock row. | 1007 // delay the loopfilter by 1 macroblock row. |
989 if (lf_start < 0) continue; | 1008 if (lf_start < 0) continue; |
990 | 1009 |
991 // decoding has completed: finish up the loop filter in this thread. | 1010 // decoding has completed: finish up the loop filter in this thread. |
992 if (mi_row + MI_BLOCK_SIZE >= cm->mi_rows) continue; | 1011 if (mi_row + MI_BLOCK_SIZE >= cm->mi_rows) continue; |
993 | 1012 |
994 winterface->sync(&pbi->lf_worker); | 1013 winterface->sync(&pbi->lf_worker); |
995 lf_data->start = lf_start; | 1014 lf_data->start = lf_start; |
996 lf_data->stop = mi_row; | 1015 lf_data->stop = mi_row; |
997 if (pbi->max_threads > 1) { | 1016 if (pbi->max_threads > 1) { |
998 winterface->launch(&pbi->lf_worker); | 1017 winterface->launch(&pbi->lf_worker); |
999 } else { | 1018 } else { |
1000 winterface->execute(&pbi->lf_worker); | 1019 winterface->execute(&pbi->lf_worker); |
1001 } | 1020 } |
1002 } | 1021 } |
| 1022 // After loopfiltering, the last 7 row pixels in each superblock row may |
| 1023 // still be changed by the longest loopfilter of the next superblock |
| 1024 // row. |
| 1025 if (pbi->frame_parallel_decode) |
| 1026 vp9_frameworker_broadcast(pbi->cur_buf, |
| 1027 mi_row << MI_BLOCK_SIZE_LOG2); |
1003 } | 1028 } |
1004 } | 1029 } |
1005 | 1030 |
1006 // Loopfilter remaining rows in the frame. | 1031 // Loopfilter remaining rows in the frame. |
1007 if (cm->lf.filter_level) { | 1032 if (cm->lf.filter_level) { |
1008 LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1; | 1033 LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1; |
1009 winterface->sync(&pbi->lf_worker); | 1034 winterface->sync(&pbi->lf_worker); |
1010 lf_data->start = lf_data->stop; | 1035 lf_data->start = lf_data->stop; |
1011 lf_data->stop = cm->mi_rows; | 1036 lf_data->stop = cm->mi_rows; |
1012 winterface->execute(&pbi->lf_worker); | 1037 winterface->execute(&pbi->lf_worker); |
1013 } | 1038 } |
1014 | 1039 |
1015 // Get last tile data. | 1040 // Get last tile data. |
1016 tile_data = pbi->tile_data + tile_cols * tile_rows - 1; | 1041 tile_data = pbi->tile_data + tile_cols * tile_rows - 1; |
1017 | 1042 |
| 1043 if (pbi->frame_parallel_decode) |
| 1044 vp9_frameworker_broadcast(pbi->cur_buf, INT_MAX); |
1018 return vp9_reader_find_end(&tile_data->bit_reader); | 1045 return vp9_reader_find_end(&tile_data->bit_reader); |
1019 } | 1046 } |
1020 | 1047 |
1021 static int tile_worker_hook(TileWorkerData *const tile_data, | 1048 static int tile_worker_hook(TileWorkerData *const tile_data, |
1022 const TileInfo *const tile) { | 1049 const TileInfo *const tile) { |
1023 int mi_row, mi_col; | 1050 int mi_row, mi_col; |
1024 | 1051 |
1025 if (setjmp(tile_data->error_info.jmp)) { | 1052 if (setjmp(tile_data->error_info.jmp)) { |
1026 tile_data->error_info.setjmp = 0; | 1053 tile_data->error_info.setjmp = 0; |
1027 tile_data->xd.corrupted = 1; | 1054 tile_data->xd.corrupted = 1; |
1028 return 0; | 1055 return 0; |
1029 } | 1056 } |
1030 | 1057 |
1031 tile_data->error_info.setjmp = 1; | 1058 tile_data->error_info.setjmp = 1; |
1032 tile_data->xd.error_info = &tile_data->error_info; | 1059 tile_data->xd.error_info = &tile_data->error_info; |
1033 | 1060 |
1034 for (mi_row = tile->mi_row_start; mi_row < tile->mi_row_end; | 1061 for (mi_row = tile->mi_row_start; mi_row < tile->mi_row_end; |
1035 mi_row += MI_BLOCK_SIZE) { | 1062 mi_row += MI_BLOCK_SIZE) { |
1036 vp9_zero(tile_data->xd.left_context); | 1063 vp9_zero(tile_data->xd.left_context); |
1037 vp9_zero(tile_data->xd.left_seg_context); | 1064 vp9_zero(tile_data->xd.left_seg_context); |
1038 for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end; | 1065 for (mi_col = tile->mi_col_start; mi_col < tile->mi_col_end; |
1039 mi_col += MI_BLOCK_SIZE) { | 1066 mi_col += MI_BLOCK_SIZE) { |
1040 decode_partition(tile_data->cm, &tile_data->xd, tile, | 1067 decode_partition(tile_data->pbi, &tile_data->xd, |
1041 mi_row, mi_col, &tile_data->bit_reader, BLOCK_64X64); | 1068 &tile_data->pbi->common.counts, |
| 1069 tile, mi_row, mi_col, &tile_data->bit_reader, |
| 1070 BLOCK_64X64); |
1042 } | 1071 } |
1043 } | 1072 } |
1044 return !tile_data->xd.corrupted; | 1073 return !tile_data->xd.corrupted; |
1045 } | 1074 } |
1046 | 1075 |
1047 // sorts in descending order | 1076 // sorts in descending order |
1048 static int compare_tile_buffers(const void *a, const void *b) { | 1077 static int compare_tile_buffers(const void *a, const void *b) { |
1049 const TileBuffer *const buf1 = (const TileBuffer*)a; | 1078 const TileBuffer *const buf1 = (const TileBuffer*)a; |
1050 const TileBuffer *const buf2 = (const TileBuffer*)b; | 1079 const TileBuffer *const buf2 = (const TileBuffer*)b; |
1051 if (buf1->size < buf2->size) { | 1080 if (buf1->size < buf2->size) { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 | 1174 |
1146 n = 0; | 1175 n = 0; |
1147 while (n < tile_cols) { | 1176 while (n < tile_cols) { |
1148 int i; | 1177 int i; |
1149 for (i = 0; i < num_workers && n < tile_cols; ++i) { | 1178 for (i = 0; i < num_workers && n < tile_cols; ++i) { |
1150 VP9Worker *const worker = &pbi->tile_workers[i]; | 1179 VP9Worker *const worker = &pbi->tile_workers[i]; |
1151 TileWorkerData *const tile_data = (TileWorkerData*)worker->data1; | 1180 TileWorkerData *const tile_data = (TileWorkerData*)worker->data1; |
1152 TileInfo *const tile = (TileInfo*)worker->data2; | 1181 TileInfo *const tile = (TileInfo*)worker->data2; |
1153 TileBuffer *const buf = &tile_buffers[0][n]; | 1182 TileBuffer *const buf = &tile_buffers[0][n]; |
1154 | 1183 |
1155 tile_data->cm = cm; | 1184 tile_data->pbi = pbi; |
1156 tile_data->xd = pbi->mb; | 1185 tile_data->xd = pbi->mb; |
1157 tile_data->xd.corrupted = 0; | 1186 tile_data->xd.corrupted = 0; |
1158 vp9_tile_init(tile, tile_data->cm, 0, buf->col); | 1187 vp9_tile_init(tile, &pbi->common, 0, buf->col); |
1159 setup_token_decoder(buf->data, data_end, buf->size, &cm->error, | 1188 setup_token_decoder(buf->data, data_end, buf->size, &cm->error, |
1160 &tile_data->bit_reader, pbi->decrypt_cb, | 1189 &tile_data->bit_reader, pbi->decrypt_cb, |
1161 pbi->decrypt_state); | 1190 pbi->decrypt_state); |
1162 init_macroblockd(cm, &tile_data->xd); | 1191 init_macroblockd(cm, &tile_data->xd); |
1163 | 1192 |
1164 worker->had_error = 0; | 1193 worker->had_error = 0; |
1165 if (i == num_workers - 1 || n == tile_cols - 1) { | 1194 if (i == num_workers - 1 || n == tile_cols - 1) { |
1166 winterface->execute(worker); | 1195 winterface->execute(worker); |
1167 } else { | 1196 } else { |
1168 winterface->launch(worker); | 1197 winterface->launch(worker); |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1252 } else { | 1281 } else { |
1253 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, | 1282 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, |
1254 "4:4:4 color not supported in profile 0 or 2"); | 1283 "4:4:4 color not supported in profile 0 or 2"); |
1255 } | 1284 } |
1256 } | 1285 } |
1257 } | 1286 } |
1258 | 1287 |
1259 static size_t read_uncompressed_header(VP9Decoder *pbi, | 1288 static size_t read_uncompressed_header(VP9Decoder *pbi, |
1260 struct vp9_read_bit_buffer *rb) { | 1289 struct vp9_read_bit_buffer *rb) { |
1261 VP9_COMMON *const cm = &pbi->common; | 1290 VP9_COMMON *const cm = &pbi->common; |
| 1291 RefCntBuffer *const frame_bufs = cm->buffer_pool->frame_bufs; |
| 1292 BufferPool *const pool = pbi->common.buffer_pool; |
| 1293 int i, mask, ref_index = 0; |
1262 size_t sz; | 1294 size_t sz; |
1263 int i; | |
1264 | 1295 |
1265 cm->last_frame_type = cm->frame_type; | 1296 cm->last_frame_type = cm->frame_type; |
1266 | 1297 |
1267 if (vp9_rb_read_literal(rb, 2) != VP9_FRAME_MARKER) | 1298 if (vp9_rb_read_literal(rb, 2) != VP9_FRAME_MARKER) |
1268 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, | 1299 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, |
1269 "Invalid frame marker"); | 1300 "Invalid frame marker"); |
1270 | 1301 |
1271 cm->profile = vp9_read_profile(rb); | 1302 cm->profile = vp9_read_profile(rb); |
1272 | 1303 |
1273 if (cm->profile >= MAX_PROFILES) | 1304 if (cm->profile >= MAX_PROFILES) |
1274 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, | 1305 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, |
1275 "Unsupported bitstream profile"); | 1306 "Unsupported bitstream profile"); |
1276 | 1307 |
1277 cm->show_existing_frame = vp9_rb_read_bit(rb); | 1308 cm->show_existing_frame = vp9_rb_read_bit(rb); |
1278 if (cm->show_existing_frame) { | 1309 if (cm->show_existing_frame) { |
1279 // Show an existing frame directly. | 1310 // Show an existing frame directly. |
1280 const int frame_to_show = cm->ref_frame_map[vp9_rb_read_literal(rb, 3)]; | 1311 const int frame_to_show = cm->ref_frame_map[vp9_rb_read_literal(rb, 3)]; |
1281 | 1312 lock_buffer_pool(pool); |
1282 if (frame_to_show < 0 || cm->frame_bufs[frame_to_show].ref_count < 1) | 1313 if (frame_to_show < 0 || frame_bufs[frame_to_show].ref_count < 1) { |
| 1314 unlock_buffer_pool(pool); |
1283 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, | 1315 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, |
1284 "Buffer %d does not contain a decoded frame", | 1316 "Buffer %d does not contain a decoded frame", |
1285 frame_to_show); | 1317 frame_to_show); |
| 1318 } |
1286 | 1319 |
1287 ref_cnt_fb(cm->frame_bufs, &cm->new_fb_idx, frame_to_show); | 1320 ref_cnt_fb(frame_bufs, &cm->new_fb_idx, frame_to_show); |
| 1321 unlock_buffer_pool(pool); |
1288 pbi->refresh_frame_flags = 0; | 1322 pbi->refresh_frame_flags = 0; |
1289 cm->lf.filter_level = 0; | 1323 cm->lf.filter_level = 0; |
1290 cm->show_frame = 1; | 1324 cm->show_frame = 1; |
| 1325 |
| 1326 if (pbi->frame_parallel_decode) { |
| 1327 for (i = 0; i < REF_FRAMES; ++i) |
| 1328 cm->next_ref_frame_map[i] = cm->ref_frame_map[i]; |
| 1329 } |
1291 return 0; | 1330 return 0; |
1292 } | 1331 } |
1293 | 1332 |
1294 cm->frame_type = (FRAME_TYPE) vp9_rb_read_bit(rb); | 1333 cm->frame_type = (FRAME_TYPE) vp9_rb_read_bit(rb); |
1295 cm->show_frame = vp9_rb_read_bit(rb); | 1334 cm->show_frame = vp9_rb_read_bit(rb); |
1296 cm->error_resilient_mode = vp9_rb_read_bit(rb); | 1335 cm->error_resilient_mode = vp9_rb_read_bit(rb); |
1297 | 1336 |
1298 if (cm->frame_type == KEY_FRAME) { | 1337 if (cm->frame_type == KEY_FRAME) { |
1299 if (!vp9_read_sync_code(rb)) | 1338 if (!vp9_read_sync_code(rb)) |
1300 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, | 1339 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, |
1301 "Invalid frame sync code"); | 1340 "Invalid frame sync code"); |
1302 | 1341 |
1303 read_bitdepth_colorspace_sampling(cm, rb); | 1342 read_bitdepth_colorspace_sampling(cm, rb); |
1304 pbi->refresh_frame_flags = (1 << REF_FRAMES) - 1; | 1343 pbi->refresh_frame_flags = (1 << REF_FRAMES) - 1; |
1305 | 1344 |
1306 for (i = 0; i < REFS_PER_FRAME; ++i) { | 1345 for (i = 0; i < REFS_PER_FRAME; ++i) { |
1307 cm->frame_refs[i].idx = -1; | 1346 cm->frame_refs[i].idx = -1; |
1308 cm->frame_refs[i].buf = NULL; | 1347 cm->frame_refs[i].buf = NULL; |
1309 } | 1348 } |
1310 | 1349 |
1311 setup_frame_size(cm, rb); | 1350 setup_frame_size(cm, rb); |
1312 pbi->need_resync = 0; | 1351 if (pbi->need_resync) { |
| 1352 vpx_memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map)); |
| 1353 pbi->need_resync = 0; |
| 1354 } |
1313 } else { | 1355 } else { |
1314 cm->intra_only = cm->show_frame ? 0 : vp9_rb_read_bit(rb); | 1356 cm->intra_only = cm->show_frame ? 0 : vp9_rb_read_bit(rb); |
1315 | 1357 |
1316 cm->reset_frame_context = cm->error_resilient_mode ? | 1358 cm->reset_frame_context = cm->error_resilient_mode ? |
1317 0 : vp9_rb_read_literal(rb, 2); | 1359 0 : vp9_rb_read_literal(rb, 2); |
1318 | 1360 |
1319 if (cm->intra_only) { | 1361 if (cm->intra_only) { |
1320 if (!vp9_read_sync_code(rb)) | 1362 if (!vp9_read_sync_code(rb)) |
1321 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, | 1363 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, |
1322 "Invalid frame sync code"); | 1364 "Invalid frame sync code"); |
1323 if (cm->profile > PROFILE_0) { | 1365 if (cm->profile > PROFILE_0) { |
1324 read_bitdepth_colorspace_sampling(cm, rb); | 1366 read_bitdepth_colorspace_sampling(cm, rb); |
1325 } else { | 1367 } else { |
1326 // NOTE: The intra-only frame header does not include the specification | 1368 // NOTE: The intra-only frame header does not include the specification |
1327 // of either the color format or color sub-sampling in profile 0. VP9 | 1369 // of either the color format or color sub-sampling in profile 0. VP9 |
1328 // specifies that the default color format should be YUV 4:2:0 in this | 1370 // specifies that the default color format should be YUV 4:2:0 in this |
1329 // case (normative). | 1371 // case (normative). |
1330 cm->color_space = VPX_CS_BT_601; | 1372 cm->color_space = VPX_CS_BT_601; |
1331 cm->subsampling_y = cm->subsampling_x = 1; | 1373 cm->subsampling_y = cm->subsampling_x = 1; |
1332 cm->bit_depth = VPX_BITS_8; | 1374 cm->bit_depth = VPX_BITS_8; |
1333 #if CONFIG_VP9_HIGHBITDEPTH | 1375 #if CONFIG_VP9_HIGHBITDEPTH |
1334 cm->use_highbitdepth = 0; | 1376 cm->use_highbitdepth = 0; |
1335 #endif | 1377 #endif |
1336 } | 1378 } |
1337 | 1379 |
1338 pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES); | 1380 pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES); |
1339 setup_frame_size(cm, rb); | 1381 setup_frame_size(cm, rb); |
1340 pbi->need_resync = 0; | 1382 if (pbi->need_resync) { |
1341 } else { | 1383 vpx_memset(&cm->ref_frame_map, -1, sizeof(cm->ref_frame_map)); |
| 1384 pbi->need_resync = 0; |
| 1385 } |
| 1386 } else if (pbi->need_resync != 1) { /* Skip if need resync */ |
1342 pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES); | 1387 pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES); |
1343 for (i = 0; i < REFS_PER_FRAME; ++i) { | 1388 for (i = 0; i < REFS_PER_FRAME; ++i) { |
1344 const int ref = vp9_rb_read_literal(rb, REF_FRAMES_LOG2); | 1389 const int ref = vp9_rb_read_literal(rb, REF_FRAMES_LOG2); |
1345 const int idx = cm->ref_frame_map[ref]; | 1390 const int idx = cm->ref_frame_map[ref]; |
1346 RefBuffer *const ref_frame = &cm->frame_refs[i]; | 1391 RefBuffer *const ref_frame = &cm->frame_refs[i]; |
1347 ref_frame->idx = idx; | 1392 ref_frame->idx = idx; |
1348 ref_frame->buf = &cm->frame_bufs[idx].buf; | 1393 ref_frame->buf = &frame_bufs[idx].buf; |
1349 cm->ref_frame_sign_bias[LAST_FRAME + i] = vp9_rb_read_bit(rb); | 1394 cm->ref_frame_sign_bias[LAST_FRAME + i] = vp9_rb_read_bit(rb); |
1350 } | 1395 } |
1351 | 1396 |
1352 setup_frame_size_with_refs(cm, rb); | 1397 setup_frame_size_with_refs(cm, rb); |
1353 | 1398 |
1354 cm->allow_high_precision_mv = vp9_rb_read_bit(rb); | 1399 cm->allow_high_precision_mv = vp9_rb_read_bit(rb); |
1355 cm->interp_filter = read_interp_filter(rb); | 1400 cm->interp_filter = read_interp_filter(rb); |
1356 | 1401 |
1357 for (i = 0; i < REFS_PER_FRAME; ++i) { | 1402 for (i = 0; i < REFS_PER_FRAME; ++i) { |
1358 RefBuffer *const ref_buf = &cm->frame_refs[i]; | 1403 RefBuffer *const ref_buf = &cm->frame_refs[i]; |
(...skipping 29 matching lines...) Expand all Loading... |
1388 cm->frame_parallel_decoding_mode = vp9_rb_read_bit(rb); | 1433 cm->frame_parallel_decoding_mode = vp9_rb_read_bit(rb); |
1389 } else { | 1434 } else { |
1390 cm->refresh_frame_context = 0; | 1435 cm->refresh_frame_context = 0; |
1391 cm->frame_parallel_decoding_mode = 1; | 1436 cm->frame_parallel_decoding_mode = 1; |
1392 } | 1437 } |
1393 | 1438 |
1394 // This flag will be overridden by the call to vp9_setup_past_independence | 1439 // This flag will be overridden by the call to vp9_setup_past_independence |
1395 // below, forcing the use of context 0 for those frame types. | 1440 // below, forcing the use of context 0 for those frame types. |
1396 cm->frame_context_idx = vp9_rb_read_literal(rb, FRAME_CONTEXTS_LOG2); | 1441 cm->frame_context_idx = vp9_rb_read_literal(rb, FRAME_CONTEXTS_LOG2); |
1397 | 1442 |
| 1443 // Generate next_ref_frame_map. |
| 1444 lock_buffer_pool(pool); |
| 1445 for (mask = pbi->refresh_frame_flags; mask; mask >>= 1) { |
| 1446 if (mask & 1) { |
| 1447 cm->next_ref_frame_map[ref_index] = cm->new_fb_idx; |
| 1448 ++frame_bufs[cm->new_fb_idx].ref_count; |
| 1449 } else { |
| 1450 cm->next_ref_frame_map[ref_index] = cm->ref_frame_map[ref_index]; |
| 1451 } |
| 1452 // Current thread holds the reference frame. |
| 1453 if (cm->ref_frame_map[ref_index] >= 0) |
| 1454 ++frame_bufs[cm->ref_frame_map[ref_index]].ref_count; |
| 1455 ++ref_index; |
| 1456 } |
| 1457 |
| 1458 for (; ref_index < REF_FRAMES; ++ref_index) { |
| 1459 cm->next_ref_frame_map[ref_index] = cm->ref_frame_map[ref_index]; |
| 1460 // Current thread holds the reference frame. |
| 1461 if (cm->ref_frame_map[ref_index] >= 0) |
| 1462 ++frame_bufs[cm->ref_frame_map[ref_index]].ref_count; |
| 1463 } |
| 1464 unlock_buffer_pool(pool); |
| 1465 pbi->hold_ref_buf = 1; |
| 1466 |
1398 if (frame_is_intra_only(cm) || cm->error_resilient_mode) | 1467 if (frame_is_intra_only(cm) || cm->error_resilient_mode) |
1399 vp9_setup_past_independence(cm); | 1468 vp9_setup_past_independence(cm); |
1400 | 1469 |
1401 setup_loopfilter(&cm->lf, rb); | 1470 setup_loopfilter(&cm->lf, rb); |
1402 setup_quantization(cm, &pbi->mb, rb); | 1471 setup_quantization(cm, &pbi->mb, rb); |
1403 setup_segmentation(&cm->seg, rb); | 1472 setup_segmentation(&cm->seg, rb); |
1404 | 1473 |
1405 setup_tile_info(cm, rb); | 1474 setup_tile_info(cm, rb); |
1406 sz = vp9_rb_read_literal(rb, 16); | 1475 sz = vp9_rb_read_literal(rb, 16); |
1407 | 1476 |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1533 } | 1602 } |
1534 return rb; | 1603 return rb; |
1535 } | 1604 } |
1536 | 1605 |
1537 void vp9_decode_frame(VP9Decoder *pbi, | 1606 void vp9_decode_frame(VP9Decoder *pbi, |
1538 const uint8_t *data, const uint8_t *data_end, | 1607 const uint8_t *data, const uint8_t *data_end, |
1539 const uint8_t **p_data_end) { | 1608 const uint8_t **p_data_end) { |
1540 VP9_COMMON *const cm = &pbi->common; | 1609 VP9_COMMON *const cm = &pbi->common; |
1541 MACROBLOCKD *const xd = &pbi->mb; | 1610 MACROBLOCKD *const xd = &pbi->mb; |
1542 struct vp9_read_bit_buffer rb = { NULL, NULL, 0, NULL, 0}; | 1611 struct vp9_read_bit_buffer rb = { NULL, NULL, 0, NULL, 0}; |
1543 | 1612 int context_updated = 0; |
1544 uint8_t clear_data[MAX_VP9_HEADER_SIZE]; | 1613 uint8_t clear_data[MAX_VP9_HEADER_SIZE]; |
1545 const size_t first_partition_size = read_uncompressed_header(pbi, | 1614 const size_t first_partition_size = read_uncompressed_header(pbi, |
1546 init_read_bit_buffer(pbi, &rb, data, data_end, clear_data)); | 1615 init_read_bit_buffer(pbi, &rb, data, data_end, clear_data)); |
1547 const int tile_rows = 1 << cm->log2_tile_rows; | 1616 const int tile_rows = 1 << cm->log2_tile_rows; |
1548 const int tile_cols = 1 << cm->log2_tile_cols; | 1617 const int tile_cols = 1 << cm->log2_tile_cols; |
1549 YV12_BUFFER_CONFIG *const new_fb = get_frame_new_buffer(cm); | 1618 YV12_BUFFER_CONFIG *const new_fb = get_frame_new_buffer(cm); |
1550 xd->cur_buf = new_fb; | 1619 xd->cur_buf = new_fb; |
1551 | 1620 |
1552 if (!first_partition_size) { | 1621 if (!first_partition_size) { |
1553 // showing a frame directly | 1622 // showing a frame directly |
(...skipping 21 matching lines...) Expand all Loading... |
1575 "Uninitialized entropy context."); | 1644 "Uninitialized entropy context."); |
1576 | 1645 |
1577 vp9_zero(cm->counts); | 1646 vp9_zero(cm->counts); |
1578 | 1647 |
1579 xd->corrupted = 0; | 1648 xd->corrupted = 0; |
1580 new_fb->corrupted = read_compressed_header(pbi, data, first_partition_size); | 1649 new_fb->corrupted = read_compressed_header(pbi, data, first_partition_size); |
1581 if (new_fb->corrupted) | 1650 if (new_fb->corrupted) |
1582 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, | 1651 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, |
1583 "Decode failed. Frame data header is corrupted."); | 1652 "Decode failed. Frame data header is corrupted."); |
1584 | 1653 |
| 1654 if (cm->lf.filter_level) { |
| 1655 vp9_loop_filter_frame_init(cm, cm->lf.filter_level); |
| 1656 } |
| 1657 |
| 1658 // If encoded in frame parallel mode, frame context is ready after decoding |
| 1659 // the frame header. |
| 1660 if (pbi->frame_parallel_decode && cm->frame_parallel_decoding_mode) { |
| 1661 VP9Worker *const worker = pbi->frame_worker_owner; |
| 1662 FrameWorkerData *const frame_worker_data = worker->data1; |
| 1663 if (cm->refresh_frame_context) { |
| 1664 context_updated = 1; |
| 1665 cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
| 1666 } |
| 1667 vp9_frameworker_lock_stats(worker); |
| 1668 pbi->cur_buf->row = -1; |
| 1669 pbi->cur_buf->col = -1; |
| 1670 frame_worker_data->frame_context_ready = 1; |
| 1671 // Signal the main thread that context is ready. |
| 1672 vp9_frameworker_signal_stats(worker); |
| 1673 vp9_frameworker_unlock_stats(worker); |
| 1674 } |
| 1675 |
1585 // TODO(jzern): remove frame_parallel_decoding_mode restriction for | 1676 // TODO(jzern): remove frame_parallel_decoding_mode restriction for |
1586 // single-frame tile decoding. | 1677 // single-frame tile decoding. |
1587 if (pbi->max_threads > 1 && tile_rows == 1 && tile_cols > 1 && | 1678 if (pbi->max_threads > 1 && tile_rows == 1 && tile_cols > 1 && |
1588 cm->frame_parallel_decoding_mode) { | 1679 cm->frame_parallel_decoding_mode) { |
1589 *p_data_end = decode_tiles_mt(pbi, data + first_partition_size, data_end); | 1680 *p_data_end = decode_tiles_mt(pbi, data + first_partition_size, data_end); |
1590 if (!xd->corrupted) { | 1681 if (!xd->corrupted) { |
1591 // If multiple threads are used to decode tiles, then we use those threads | 1682 // If multiple threads are used to decode tiles, then we use those threads |
1592 // to do parallel loopfiltering. | 1683 // to do parallel loopfiltering. |
1593 vp9_loop_filter_frame_mt(new_fb, cm, pbi->mb.plane, cm->lf.filter_level, | 1684 vp9_loop_filter_frame_mt(new_fb, cm, pbi->mb.plane, cm->lf.filter_level, |
1594 0, 0, pbi->tile_workers, pbi->num_tile_workers, | 1685 0, 0, pbi->tile_workers, pbi->num_tile_workers, |
1595 &pbi->lf_row_sync); | 1686 &pbi->lf_row_sync); |
1596 } else { | 1687 } else { |
1597 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, | 1688 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, |
1598 "Decode failed. Frame data is corrupted."); | 1689 "Decode failed. Frame data is corrupted."); |
1599 | 1690 |
1600 } | 1691 } |
1601 } else { | 1692 } else { |
1602 *p_data_end = decode_tiles(pbi, data + first_partition_size, data_end); | 1693 *p_data_end = decode_tiles(pbi, data + first_partition_size, data_end); |
1603 } | 1694 } |
1604 | 1695 |
1605 new_fb->corrupted |= xd->corrupted; | 1696 if (!xd->corrupted) { |
1606 | |
1607 if (!new_fb->corrupted) { | |
1608 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) { | 1697 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) { |
1609 vp9_adapt_coef_probs(cm); | 1698 vp9_adapt_coef_probs(cm); |
1610 | 1699 |
1611 if (!frame_is_intra_only(cm)) { | 1700 if (!frame_is_intra_only(cm)) { |
1612 vp9_adapt_mode_probs(cm); | 1701 vp9_adapt_mode_probs(cm); |
1613 vp9_adapt_mv_probs(cm, cm->allow_high_precision_mv); | 1702 vp9_adapt_mv_probs(cm, cm->allow_high_precision_mv); |
1614 } | 1703 } |
1615 } else { | 1704 } else { |
1616 debug_check_frame_counts(cm); | 1705 debug_check_frame_counts(cm); |
1617 } | 1706 } |
1618 } else { | 1707 } else { |
1619 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, | 1708 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, |
1620 "Decode failed. Frame data is corrupted."); | 1709 "Decode failed. Frame data is corrupted."); |
1621 } | 1710 } |
1622 | 1711 |
1623 if (cm->refresh_frame_context) | 1712 // Non frame parallel update frame context here. |
| 1713 if (cm->refresh_frame_context && !context_updated) |
1624 cm->frame_contexts[cm->frame_context_idx] = *cm->fc; | 1714 cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
1625 } | 1715 } |
| 1716 |
| 1717 static void build_mc_border(const uint8_t *src, int src_stride, |
| 1718 uint8_t *dst, int dst_stride, |
| 1719 int x, int y, int b_w, int b_h, int w, int h) { |
| 1720 // Get a pointer to the start of the real data for this row. |
| 1721 const uint8_t *ref_row = src - x - y * src_stride; |
| 1722 |
| 1723 if (y >= h) |
| 1724 ref_row += (h - 1) * src_stride; |
| 1725 else if (y > 0) |
| 1726 ref_row += y * src_stride; |
| 1727 |
| 1728 do { |
| 1729 int right = 0, copy; |
| 1730 int left = x < 0 ? -x : 0; |
| 1731 |
| 1732 if (left > b_w) |
| 1733 left = b_w; |
| 1734 |
| 1735 if (x + b_w > w) |
| 1736 right = x + b_w - w; |
| 1737 |
| 1738 if (right > b_w) |
| 1739 right = b_w; |
| 1740 |
| 1741 copy = b_w - left - right; |
| 1742 |
| 1743 if (left) |
| 1744 memset(dst, ref_row[0], left); |
| 1745 |
| 1746 if (copy) |
| 1747 memcpy(dst + left, ref_row + x + left, copy); |
| 1748 |
| 1749 if (right) |
| 1750 memset(dst + left + copy, ref_row[w - 1], right); |
| 1751 |
| 1752 dst += dst_stride; |
| 1753 ++y; |
| 1754 |
| 1755 if (y > 0 && y < h) |
| 1756 ref_row += src_stride; |
| 1757 } while (--b_h); |
| 1758 } |
| 1759 |
| 1760 #if CONFIG_VP9_HIGHBITDEPTH |
| 1761 static void high_build_mc_border(const uint8_t *src8, int src_stride, |
| 1762 uint16_t *dst, int dst_stride, |
| 1763 int x, int y, int b_w, int b_h, |
| 1764 int w, int h) { |
| 1765 // Get a pointer to the start of the real data for this row. |
| 1766 const uint16_t *src = CONVERT_TO_SHORTPTR(src8); |
| 1767 const uint16_t *ref_row = src - x - y * src_stride; |
| 1768 |
| 1769 if (y >= h) |
| 1770 ref_row += (h - 1) * src_stride; |
| 1771 else if (y > 0) |
| 1772 ref_row += y * src_stride; |
| 1773 |
| 1774 do { |
| 1775 int right = 0, copy; |
| 1776 int left = x < 0 ? -x : 0; |
| 1777 |
| 1778 if (left > b_w) |
| 1779 left = b_w; |
| 1780 |
| 1781 if (x + b_w > w) |
| 1782 right = x + b_w - w; |
| 1783 |
| 1784 if (right > b_w) |
| 1785 right = b_w; |
| 1786 |
| 1787 copy = b_w - left - right; |
| 1788 |
| 1789 if (left) |
| 1790 vpx_memset16(dst, ref_row[0], left); |
| 1791 |
| 1792 if (copy) |
| 1793 memcpy(dst + left, ref_row + x + left, copy * sizeof(uint16_t)); |
| 1794 |
| 1795 if (right) |
| 1796 vpx_memset16(dst + left + copy, ref_row[w - 1], right); |
| 1797 |
| 1798 dst += dst_stride; |
| 1799 ++y; |
| 1800 |
| 1801 if (y > 0 && y < h) |
| 1802 ref_row += src_stride; |
| 1803 } while (--b_h); |
| 1804 } |
| 1805 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 1806 |
| 1807 void dec_build_inter_predictors(VP9Decoder *const pbi, MACROBLOCKD *xd, |
| 1808 int plane, int block, int bw, int bh, int x, |
| 1809 int y, int w, int h, int mi_x, int mi_y) { |
| 1810 struct macroblockd_plane *const pd = &xd->plane[plane]; |
| 1811 const MODE_INFO *mi = xd->mi[0].src_mi; |
| 1812 const int is_compound = has_second_ref(&mi->mbmi); |
| 1813 const InterpKernel *kernel = vp9_get_interp_kernel(mi->mbmi.interp_filter); |
| 1814 int ref; |
| 1815 |
| 1816 for (ref = 0; ref < 1 + is_compound; ++ref) { |
| 1817 const struct scale_factors *const sf = &xd->block_refs[ref]->sf; |
| 1818 struct buf_2d *const pre_buf = &pd->pre[ref]; |
| 1819 struct buf_2d *const dst_buf = &pd->dst; |
| 1820 uint8_t *const dst = dst_buf->buf + dst_buf->stride * y + x; |
| 1821 const MV mv = mi->mbmi.sb_type < BLOCK_8X8 |
| 1822 ? average_split_mvs(pd, mi, ref, block) |
| 1823 : mi->mbmi.mv[ref].as_mv; |
| 1824 |
| 1825 const MV mv_q4 = clamp_mv_to_umv_border_sb(xd, &mv, bw, bh, |
| 1826 pd->subsampling_x, |
| 1827 pd->subsampling_y); |
| 1828 |
| 1829 MV32 scaled_mv; |
| 1830 int xs, ys, x0, y0, x0_16, y0_16, y1, frame_width, frame_height, |
| 1831 buf_stride, subpel_x, subpel_y; |
| 1832 uint8_t *ref_frame, *buf_ptr; |
| 1833 const int idx = xd->block_refs[ref]->idx; |
| 1834 BufferPool *const pool = pbi->common.buffer_pool; |
| 1835 RefCntBuffer *const ref_frame_buf = &pool->frame_bufs[idx]; |
| 1836 const int is_scaled = vp9_is_scaled(sf); |
| 1837 |
| 1838 // Get reference frame pointer, width and height. |
| 1839 if (plane == 0) { |
| 1840 frame_width = ref_frame_buf->buf.y_crop_width; |
| 1841 frame_height = ref_frame_buf->buf.y_crop_height; |
| 1842 ref_frame = ref_frame_buf->buf.y_buffer; |
| 1843 } else { |
| 1844 frame_width = ref_frame_buf->buf.uv_crop_width; |
| 1845 frame_height = ref_frame_buf->buf.uv_crop_height; |
| 1846 ref_frame = plane == 1 ? ref_frame_buf->buf.u_buffer |
| 1847 : ref_frame_buf->buf.v_buffer; |
| 1848 } |
| 1849 |
| 1850 if (is_scaled) { |
| 1851 // Co-ordinate of containing block to pixel precision. |
| 1852 int x_start = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x)); |
| 1853 int y_start = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y)); |
| 1854 |
| 1855 // Co-ordinate of the block to 1/16th pixel precision. |
| 1856 x0_16 = (x_start + x) << SUBPEL_BITS; |
| 1857 y0_16 = (y_start + y) << SUBPEL_BITS; |
| 1858 |
| 1859 // Co-ordinate of current block in reference frame |
| 1860 // to 1/16th pixel precision. |
| 1861 x0_16 = sf->scale_value_x(x0_16, sf); |
| 1862 y0_16 = sf->scale_value_y(y0_16, sf); |
| 1863 |
| 1864 // Map the top left corner of the block into the reference frame. |
| 1865 x0 = sf->scale_value_x(x_start + x, sf); |
| 1866 y0 = sf->scale_value_y(y_start + y, sf); |
| 1867 |
| 1868 // Scale the MV and incorporate the sub-pixel offset of the block |
| 1869 // in the reference frame. |
| 1870 scaled_mv = vp9_scale_mv(&mv_q4, mi_x + x, mi_y + y, sf); |
| 1871 xs = sf->x_step_q4; |
| 1872 ys = sf->y_step_q4; |
| 1873 } else { |
| 1874 // Co-ordinate of containing block to pixel precision. |
| 1875 x0 = (-xd->mb_to_left_edge >> (3 + pd->subsampling_x)) + x; |
| 1876 y0 = (-xd->mb_to_top_edge >> (3 + pd->subsampling_y)) + y; |
| 1877 |
| 1878 // Co-ordinate of the block to 1/16th pixel precision. |
| 1879 x0_16 = x0 << SUBPEL_BITS; |
| 1880 y0_16 = y0 << SUBPEL_BITS; |
| 1881 |
| 1882 scaled_mv.row = mv_q4.row; |
| 1883 scaled_mv.col = mv_q4.col; |
| 1884 xs = ys = 16; |
| 1885 } |
| 1886 subpel_x = scaled_mv.col & SUBPEL_MASK; |
| 1887 subpel_y = scaled_mv.row & SUBPEL_MASK; |
| 1888 |
| 1889 // Calculate the top left corner of the best matching block in the |
| 1890 // reference frame. |
| 1891 x0 += scaled_mv.col >> SUBPEL_BITS; |
| 1892 y0 += scaled_mv.row >> SUBPEL_BITS; |
| 1893 x0_16 += scaled_mv.col; |
| 1894 y0_16 += scaled_mv.row; |
| 1895 |
| 1896 // Get reference block pointer. |
| 1897 buf_ptr = ref_frame + y0 * pre_buf->stride + x0; |
| 1898 buf_stride = pre_buf->stride; |
| 1899 |
| 1900 // Get reference block bottom right vertical coordinate. |
| 1901 y1 = ((y0_16 + (h - 1) * ys) >> SUBPEL_BITS) + 1; |
| 1902 |
| 1903 // Do border extension if there is motion or the |
| 1904 // width/height is not a multiple of 8 pixels. |
| 1905 if (is_scaled || scaled_mv.col || scaled_mv.row || |
| 1906 (frame_width & 0x7) || (frame_height & 0x7)) { |
| 1907 // Get reference block bottom right horizontal coordinate. |
| 1908 int x1 = ((x0_16 + (w - 1) * xs) >> SUBPEL_BITS) + 1; |
| 1909 int x_pad = 0, y_pad = 0; |
| 1910 |
| 1911 if (subpel_x || (sf->x_step_q4 != SUBPEL_SHIFTS)) { |
| 1912 x0 -= VP9_INTERP_EXTEND - 1; |
| 1913 x1 += VP9_INTERP_EXTEND; |
| 1914 x_pad = 1; |
| 1915 } |
| 1916 |
| 1917 if (subpel_y || (sf->y_step_q4 != SUBPEL_SHIFTS)) { |
| 1918 y0 -= VP9_INTERP_EXTEND - 1; |
| 1919 y1 += VP9_INTERP_EXTEND; |
| 1920 y_pad = 1; |
| 1921 } |
| 1922 |
| 1923 // Wait until reference block is ready. Pad 7 more pixels as last 7 |
| 1924 // pixels of each superblock row can be changed by next superblock row. |
| 1925 if (pbi->frame_parallel_decode) |
| 1926 vp9_frameworker_wait(pbi->frame_worker_owner, ref_frame_buf, |
| 1927 (y1 + 7) << (plane == 0 ? 0 : 1)); |
| 1928 |
| 1929 // Skip border extension if block is inside the frame. |
| 1930 if (x0 < 0 || x0 > frame_width - 1 || x1 < 0 || x1 > frame_width - 1 || |
| 1931 y0 < 0 || y0 > frame_height - 1 || y1 < 0 || y1 > frame_height - 1) { |
| 1932 uint8_t *buf_ptr1 = ref_frame + y0 * pre_buf->stride + x0; |
| 1933 // Extend the border. |
| 1934 #if CONFIG_VP9_HIGHBITDEPTH |
| 1935 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 1936 high_build_mc_border(buf_ptr1, |
| 1937 pre_buf->stride, |
| 1938 xd->mc_buf_high, |
| 1939 x1 - x0 + 1, |
| 1940 x0, |
| 1941 y0, |
| 1942 x1 - x0 + 1, |
| 1943 y1 - y0 + 1, |
| 1944 frame_width, |
| 1945 frame_height); |
| 1946 buf_stride = x1 - x0 + 1; |
| 1947 buf_ptr = CONVERT_TO_BYTEPTR(xd->mc_buf_high) + |
| 1948 y_pad * 3 * buf_stride + x_pad * 3; |
| 1949 } else { |
| 1950 build_mc_border(buf_ptr1, |
| 1951 pre_buf->stride, |
| 1952 xd->mc_buf, |
| 1953 x1 - x0 + 1, |
| 1954 x0, |
| 1955 y0, |
| 1956 x1 - x0 + 1, |
| 1957 y1 - y0 + 1, |
| 1958 frame_width, |
| 1959 frame_height); |
| 1960 buf_stride = x1 - x0 + 1; |
| 1961 buf_ptr = xd->mc_buf + y_pad * 3 * buf_stride + x_pad * 3; |
| 1962 } |
| 1963 #else |
| 1964 build_mc_border(buf_ptr1, |
| 1965 pre_buf->stride, |
| 1966 xd->mc_buf, |
| 1967 x1 - x0 + 1, |
| 1968 x0, |
| 1969 y0, |
| 1970 x1 - x0 + 1, |
| 1971 y1 - y0 + 1, |
| 1972 frame_width, |
| 1973 frame_height); |
| 1974 buf_stride = x1 - x0 + 1; |
| 1975 buf_ptr = xd->mc_buf + y_pad * 3 * buf_stride + x_pad * 3; |
| 1976 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 1977 } |
| 1978 } else { |
| 1979 // Wait until reference block is ready. Pad 7 more pixels as last 7 |
| 1980 // pixels of each superblock row can be changed by next superblock row. |
| 1981 if (pbi->frame_parallel_decode) |
| 1982 vp9_frameworker_wait(pbi->frame_worker_owner, ref_frame_buf, |
| 1983 (y1 + 7) << (plane == 0 ? 0 : 1)); |
| 1984 } |
| 1985 #if CONFIG_VP9_HIGHBITDEPTH |
| 1986 if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) { |
| 1987 high_inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x, |
| 1988 subpel_y, sf, w, h, ref, kernel, xs, ys, xd->bd); |
| 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); |
| 1992 } |
| 1993 #else |
| 1994 inter_predictor(buf_ptr, buf_stride, dst, dst_buf->stride, subpel_x, |
| 1995 subpel_y, sf, w, h, ref, kernel, xs, ys); |
| 1996 #endif // CONFIG_VP9_HIGHBITDEPTH |
| 1997 } |
| 1998 } |
| 1999 |
| 2000 void vp9_dec_build_inter_predictors_sb(VP9Decoder *const pbi, MACROBLOCKD *xd, |
| 2001 int mi_row, int mi_col, |
| 2002 BLOCK_SIZE bsize) { |
| 2003 int plane; |
| 2004 const int mi_x = mi_col * MI_SIZE; |
| 2005 const int mi_y = mi_row * MI_SIZE; |
| 2006 for (plane = 0; plane < MAX_MB_PLANE; ++plane) { |
| 2007 const BLOCK_SIZE plane_bsize = get_plane_block_size(bsize, |
| 2008 &xd->plane[plane]); |
| 2009 const int num_4x4_w = num_4x4_blocks_wide_lookup[plane_bsize]; |
| 2010 const int num_4x4_h = num_4x4_blocks_high_lookup[plane_bsize]; |
| 2011 const int bw = 4 * num_4x4_w; |
| 2012 const int bh = 4 * num_4x4_h; |
| 2013 |
| 2014 if (xd->mi[0].src_mi->mbmi.sb_type < BLOCK_8X8) { |
| 2015 int i = 0, x, y; |
| 2016 assert(bsize == BLOCK_8X8); |
| 2017 for (y = 0; y < num_4x4_h; ++y) |
| 2018 for (x = 0; x < num_4x4_w; ++x) |
| 2019 dec_build_inter_predictors(pbi, xd, plane, i++, bw, bh, |
| 2020 4 * x, 4 * y, 4, 4, mi_x, mi_y); |
| 2021 } else { |
| 2022 dec_build_inter_predictors(pbi, xd, plane, 0, bw, bh, |
| 2023 0, 0, bw, bh, mi_x, mi_y); |
| 2024 } |
| 2025 } |
| 2026 } |
OLD | NEW |