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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 if (is_compound_reference_allowed(cm)) { | 120 if (is_compound_reference_allowed(cm)) { |
121 return vp9_read_bit(r) ? (vp9_read_bit(r) ? REFERENCE_MODE_SELECT | 121 return vp9_read_bit(r) ? (vp9_read_bit(r) ? REFERENCE_MODE_SELECT |
122 : COMPOUND_REFERENCE) | 122 : COMPOUND_REFERENCE) |
123 : SINGLE_REFERENCE; | 123 : SINGLE_REFERENCE; |
124 } else { | 124 } else { |
125 return SINGLE_REFERENCE; | 125 return SINGLE_REFERENCE; |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
129 static void read_frame_reference_mode_probs(VP9_COMMON *cm, vp9_reader *r) { | 129 static void read_frame_reference_mode_probs(VP9_COMMON *cm, vp9_reader *r) { |
130 FRAME_CONTEXT *const fc = &cm->fc; | 130 FRAME_CONTEXT *const fc = cm->fc; |
131 int i; | 131 int i; |
132 | 132 |
133 if (cm->reference_mode == REFERENCE_MODE_SELECT) | 133 if (cm->reference_mode == REFERENCE_MODE_SELECT) |
134 for (i = 0; i < COMP_INTER_CONTEXTS; ++i) | 134 for (i = 0; i < COMP_INTER_CONTEXTS; ++i) |
135 vp9_diff_update_prob(r, &fc->comp_inter_prob[i]); | 135 vp9_diff_update_prob(r, &fc->comp_inter_prob[i]); |
136 | 136 |
137 if (cm->reference_mode != COMPOUND_REFERENCE) | 137 if (cm->reference_mode != COMPOUND_REFERENCE) |
138 for (i = 0; i < REF_CONTEXTS; ++i) { | 138 for (i = 0; i < REF_CONTEXTS; ++i) { |
139 vp9_diff_update_prob(r, &fc->single_ref_prob[i][0]); | 139 vp9_diff_update_prob(r, &fc->single_ref_prob[i][0]); |
140 vp9_diff_update_prob(r, &fc->single_ref_prob[i][1]); | 140 vp9_diff_update_prob(r, &fc->single_ref_prob[i][1]); |
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 *height = vp9_rb_read_literal(rb, 16) + 1; | 660 *height = vp9_rb_read_literal(rb, 16) + 1; |
661 } | 661 } |
662 | 662 |
663 static void setup_display_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { | 663 static void setup_display_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { |
664 cm->display_width = cm->width; | 664 cm->display_width = cm->width; |
665 cm->display_height = cm->height; | 665 cm->display_height = cm->height; |
666 if (vp9_rb_read_bit(rb)) | 666 if (vp9_rb_read_bit(rb)) |
667 vp9_read_frame_size(rb, &cm->display_width, &cm->display_height); | 667 vp9_read_frame_size(rb, &cm->display_width, &cm->display_height); |
668 } | 668 } |
669 | 669 |
| 670 static void resize_mv_buffer(VP9_COMMON *cm) { |
| 671 vpx_free(cm->cur_frame->mvs); |
| 672 cm->cur_frame->mi_rows = cm->mi_rows; |
| 673 cm->cur_frame->mi_cols = cm->mi_cols; |
| 674 cm->cur_frame->mvs = (MV_REF *)vpx_calloc(cm->mi_rows * cm->mi_cols, |
| 675 sizeof(*cm->cur_frame->mvs)); |
| 676 } |
| 677 |
670 static void resize_context_buffers(VP9_COMMON *cm, int width, int height) { | 678 static void resize_context_buffers(VP9_COMMON *cm, int width, int height) { |
671 #if CONFIG_SIZE_LIMIT | 679 #if CONFIG_SIZE_LIMIT |
672 if (width > DECODE_WIDTH_LIMIT || height > DECODE_HEIGHT_LIMIT) | 680 if (width > DECODE_WIDTH_LIMIT || height > DECODE_HEIGHT_LIMIT) |
673 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, | 681 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, |
674 "Width and height beyond allowed size."); | 682 "Width and height beyond allowed size."); |
675 #endif | 683 #endif |
676 if (cm->width != width || cm->height != height) { | 684 if (cm->width != width || cm->height != height) { |
677 const int new_mi_rows = | 685 const int new_mi_rows = |
678 ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2) >> MI_SIZE_LOG2; | 686 ALIGN_POWER_OF_TWO(height, MI_SIZE_LOG2) >> MI_SIZE_LOG2; |
679 const int new_mi_cols = | 687 const int new_mi_cols = |
680 ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2) >> MI_SIZE_LOG2; | 688 ALIGN_POWER_OF_TWO(width, MI_SIZE_LOG2) >> MI_SIZE_LOG2; |
681 | 689 |
682 // Allocations in vp9_alloc_context_buffers() depend on individual | 690 // Allocations in vp9_alloc_context_buffers() depend on individual |
683 // dimensions as well as the overall size. | 691 // dimensions as well as the overall size. |
684 if (new_mi_cols > cm->mi_cols || new_mi_rows > cm->mi_rows) { | 692 if (new_mi_cols > cm->mi_cols || new_mi_rows > cm->mi_rows) { |
685 if (vp9_alloc_context_buffers(cm, width, height)) | 693 if (vp9_alloc_context_buffers(cm, width, height)) |
686 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 694 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
687 "Failed to allocate context buffers"); | 695 "Failed to allocate context buffers"); |
688 } else { | 696 } else { |
689 vp9_set_mb_mi(cm, width, height); | 697 vp9_set_mb_mi(cm, width, height); |
690 } | 698 } |
691 vp9_init_context_buffers(cm); | 699 vp9_init_context_buffers(cm); |
692 cm->width = width; | 700 cm->width = width; |
693 cm->height = height; | 701 cm->height = height; |
694 } | 702 } |
| 703 if (cm->cur_frame->mvs == NULL || cm->mi_rows > cm->cur_frame->mi_rows || |
| 704 cm->mi_cols > cm->cur_frame->mi_cols) { |
| 705 resize_mv_buffer(cm); |
| 706 } |
695 } | 707 } |
696 | 708 |
697 static void setup_frame_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { | 709 static void setup_frame_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { |
698 int width, height; | 710 int width, height; |
699 vp9_read_frame_size(rb, &width, &height); | 711 vp9_read_frame_size(rb, &width, &height); |
700 resize_context_buffers(cm, width, height); | 712 resize_context_buffers(cm, width, height); |
701 setup_display_size(cm, rb); | 713 setup_display_size(cm, rb); |
702 | 714 |
703 if (vp9_realloc_frame_buffer( | 715 if (vp9_realloc_frame_buffer( |
704 get_frame_new_buffer(cm), cm->width, cm->height, | 716 get_frame_new_buffer(cm), cm->width, cm->height, |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
895 if (pbi->max_threads > 1 && !winterface->reset(&pbi->lf_worker)) { | 907 if (pbi->max_threads > 1 && !winterface->reset(&pbi->lf_worker)) { |
896 vpx_internal_error(&cm->error, VPX_CODEC_ERROR, | 908 vpx_internal_error(&cm->error, VPX_CODEC_ERROR, |
897 "Loop filter thread creation failed"); | 909 "Loop filter thread creation failed"); |
898 } | 910 } |
899 } | 911 } |
900 | 912 |
901 if (cm->lf.filter_level) { | 913 if (cm->lf.filter_level) { |
902 LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1; | 914 LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1; |
903 // Be sure to sync as we might be resuming after a failed frame decode. | 915 // Be sure to sync as we might be resuming after a failed frame decode. |
904 winterface->sync(&pbi->lf_worker); | 916 winterface->sync(&pbi->lf_worker); |
905 lf_data->frame_buffer = get_frame_new_buffer(cm); | 917 vp9_loop_filter_data_reset(lf_data, get_frame_new_buffer(cm), cm, |
906 lf_data->cm = cm; | 918 pbi->mb.plane); |
907 vp9_copy(lf_data->planes, pbi->mb.plane); | |
908 lf_data->stop = 0; | |
909 lf_data->y_only = 0; | |
910 vp9_loop_filter_frame_init(cm, cm->lf.filter_level); | 919 vp9_loop_filter_frame_init(cm, cm->lf.filter_level); |
911 } | 920 } |
912 | 921 |
913 assert(tile_rows <= 4); | 922 assert(tile_rows <= 4); |
914 assert(tile_cols <= (1 << 6)); | 923 assert(tile_cols <= (1 << 6)); |
915 | 924 |
916 // Note: this memset assumes above_context[0], [1] and [2] | 925 // Note: this memset assumes above_context[0], [1] and [2] |
917 // are allocated as part of the same buffer. | 926 // are allocated as part of the same buffer. |
918 vpx_memset(cm->above_context, 0, | 927 vpx_memset(cm->above_context, 0, |
919 sizeof(*cm->above_context) * MAX_MB_PLANE * 2 * aligned_cols); | 928 sizeof(*cm->above_context) * MAX_MB_PLANE * 2 * aligned_cols); |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1058 | 1067 |
1059 // TODO(jzern): See if we can remove the restriction of passing in max | 1068 // TODO(jzern): See if we can remove the restriction of passing in max |
1060 // threads to the decoder. | 1069 // threads to the decoder. |
1061 if (pbi->num_tile_workers == 0) { | 1070 if (pbi->num_tile_workers == 0) { |
1062 const int num_threads = pbi->max_threads & ~1; | 1071 const int num_threads = pbi->max_threads & ~1; |
1063 int i; | 1072 int i; |
1064 // TODO(jzern): Allocate one less worker, as in the current code we only | 1073 // TODO(jzern): Allocate one less worker, as in the current code we only |
1065 // use num_threads - 1 workers. | 1074 // use num_threads - 1 workers. |
1066 CHECK_MEM_ERROR(cm, pbi->tile_workers, | 1075 CHECK_MEM_ERROR(cm, pbi->tile_workers, |
1067 vpx_malloc(num_threads * sizeof(*pbi->tile_workers))); | 1076 vpx_malloc(num_threads * sizeof(*pbi->tile_workers))); |
| 1077 // Ensure tile data offsets will be properly aligned. This may fail on |
| 1078 // platforms without DECLARE_ALIGNED(). |
| 1079 assert((sizeof(*pbi->tile_worker_data) % 16) == 0); |
| 1080 CHECK_MEM_ERROR(cm, pbi->tile_worker_data, |
| 1081 vpx_memalign(32, num_threads * |
| 1082 sizeof(*pbi->tile_worker_data))); |
| 1083 CHECK_MEM_ERROR(cm, pbi->tile_worker_info, |
| 1084 vpx_malloc(num_threads * sizeof(*pbi->tile_worker_info))); |
1068 for (i = 0; i < num_threads; ++i) { | 1085 for (i = 0; i < num_threads; ++i) { |
1069 VP9Worker *const worker = &pbi->tile_workers[i]; | 1086 VP9Worker *const worker = &pbi->tile_workers[i]; |
1070 ++pbi->num_tile_workers; | 1087 ++pbi->num_tile_workers; |
1071 | 1088 |
1072 winterface->init(worker); | 1089 winterface->init(worker); |
1073 CHECK_MEM_ERROR(cm, worker->data1, | |
1074 vpx_memalign(32, sizeof(TileWorkerData))); | |
1075 CHECK_MEM_ERROR(cm, worker->data2, vpx_malloc(sizeof(TileInfo))); | |
1076 if (i < num_threads - 1 && !winterface->reset(worker)) { | 1090 if (i < num_threads - 1 && !winterface->reset(worker)) { |
1077 vpx_internal_error(&cm->error, VPX_CODEC_ERROR, | 1091 vpx_internal_error(&cm->error, VPX_CODEC_ERROR, |
1078 "Tile decoder thread creation failed"); | 1092 "Tile decoder thread creation failed"); |
1079 } | 1093 } |
1080 } | 1094 } |
1081 } | 1095 } |
1082 | 1096 |
1083 // Reset tile decoding hook | 1097 // Reset tile decoding hook |
1084 for (n = 0; n < num_workers; ++n) { | 1098 for (n = 0; n < num_workers; ++n) { |
1085 winterface->sync(&pbi->tile_workers[n]); | 1099 VP9Worker *const worker = &pbi->tile_workers[n]; |
1086 pbi->tile_workers[n].hook = (VP9WorkerHook)tile_worker_hook; | 1100 winterface->sync(worker); |
| 1101 worker->hook = (VP9WorkerHook)tile_worker_hook; |
| 1102 worker->data1 = &pbi->tile_worker_data[n]; |
| 1103 worker->data2 = &pbi->tile_worker_info[n]; |
1087 } | 1104 } |
1088 | 1105 |
1089 // Note: this memset assumes above_context[0], [1] and [2] | 1106 // Note: this memset assumes above_context[0], [1] and [2] |
1090 // are allocated as part of the same buffer. | 1107 // are allocated as part of the same buffer. |
1091 vpx_memset(cm->above_context, 0, | 1108 vpx_memset(cm->above_context, 0, |
1092 sizeof(*cm->above_context) * MAX_MB_PLANE * 2 * aligned_mi_cols); | 1109 sizeof(*cm->above_context) * MAX_MB_PLANE * 2 * aligned_mi_cols); |
1093 vpx_memset(cm->above_seg_context, 0, | 1110 vpx_memset(cm->above_seg_context, 0, |
1094 sizeof(*cm->above_seg_context) * aligned_mi_cols); | 1111 sizeof(*cm->above_seg_context) * aligned_mi_cols); |
1095 | 1112 |
1096 // Load tile data into tile_buffers | 1113 // Load tile data into tile_buffers |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1379 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, | 1396 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, |
1380 "Invalid header size"); | 1397 "Invalid header size"); |
1381 | 1398 |
1382 return sz; | 1399 return sz; |
1383 } | 1400 } |
1384 | 1401 |
1385 static int read_compressed_header(VP9Decoder *pbi, const uint8_t *data, | 1402 static int read_compressed_header(VP9Decoder *pbi, const uint8_t *data, |
1386 size_t partition_size) { | 1403 size_t partition_size) { |
1387 VP9_COMMON *const cm = &pbi->common; | 1404 VP9_COMMON *const cm = &pbi->common; |
1388 MACROBLOCKD *const xd = &pbi->mb; | 1405 MACROBLOCKD *const xd = &pbi->mb; |
1389 FRAME_CONTEXT *const fc = &cm->fc; | 1406 FRAME_CONTEXT *const fc = cm->fc; |
1390 vp9_reader r; | 1407 vp9_reader r; |
1391 int k; | 1408 int k; |
1392 | 1409 |
1393 if (vp9_reader_init(&r, data, partition_size, pbi->decrypt_cb, | 1410 if (vp9_reader_init(&r, data, partition_size, pbi->decrypt_cb, |
1394 pbi->decrypt_state)) | 1411 pbi->decrypt_state)) |
1395 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 1412 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
1396 "Failed to allocate bool decoder 0"); | 1413 "Failed to allocate bool decoder 0"); |
1397 | 1414 |
1398 cm->tx_mode = xd->lossless ? ONLY_4X4 : read_tx_mode(&r); | 1415 cm->tx_mode = xd->lossless ? ONLY_4X4 : read_tx_mode(&r); |
1399 if (cm->tx_mode == TX_MODE_SELECT) | 1416 if (cm->tx_mode == TX_MODE_SELECT) |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1525 return; | 1542 return; |
1526 } | 1543 } |
1527 | 1544 |
1528 data += vp9_rb_bytes_read(&rb); | 1545 data += vp9_rb_bytes_read(&rb); |
1529 if (!read_is_valid(data, first_partition_size, data_end)) | 1546 if (!read_is_valid(data, first_partition_size, data_end)) |
1530 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, | 1547 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, |
1531 "Truncated packet or corrupt header length"); | 1548 "Truncated packet or corrupt header length"); |
1532 | 1549 |
1533 init_macroblockd(cm, &pbi->mb); | 1550 init_macroblockd(cm, &pbi->mb); |
1534 | 1551 |
1535 if (!cm->error_resilient_mode) | 1552 cm->use_prev_frame_mvs = !cm->error_resilient_mode && |
1536 set_prev_mi(cm); | 1553 cm->width == cm->last_width && |
1537 else | 1554 cm->height == cm->last_height && |
1538 cm->prev_mi = NULL; | 1555 !cm->intra_only && |
| 1556 cm->last_show_frame; |
1539 | 1557 |
1540 setup_plane_dequants(cm, xd, cm->base_qindex); | 1558 setup_plane_dequants(cm, xd, cm->base_qindex); |
1541 vp9_setup_block_planes(xd, cm->subsampling_x, cm->subsampling_y); | 1559 vp9_setup_block_planes(xd, cm->subsampling_x, cm->subsampling_y); |
1542 | 1560 |
1543 cm->fc = cm->frame_contexts[cm->frame_context_idx]; | 1561 *cm->fc = cm->frame_contexts[cm->frame_context_idx]; |
1544 vp9_zero(cm->counts); | 1562 vp9_zero(cm->counts); |
1545 vp9_zero(xd->dqcoeff); | 1563 vp9_zero(xd->dqcoeff); |
1546 | 1564 |
1547 xd->corrupted = 0; | 1565 xd->corrupted = 0; |
1548 new_fb->corrupted = read_compressed_header(pbi, data, first_partition_size); | 1566 new_fb->corrupted = read_compressed_header(pbi, data, first_partition_size); |
1549 | 1567 |
1550 // TODO(jzern): remove frame_parallel_decoding_mode restriction for | 1568 // TODO(jzern): remove frame_parallel_decoding_mode restriction for |
1551 // single-frame tile decoding. | 1569 // single-frame tile decoding. |
1552 if (pbi->max_threads > 1 && tile_rows == 1 && tile_cols > 1 && | 1570 if (pbi->max_threads > 1 && tile_rows == 1 && tile_cols > 1 && |
1553 cm->frame_parallel_decoding_mode) { | 1571 cm->frame_parallel_decoding_mode) { |
1554 *p_data_end = decode_tiles_mt(pbi, data + first_partition_size, data_end); | 1572 *p_data_end = decode_tiles_mt(pbi, data + first_partition_size, data_end); |
1555 if (!xd->corrupted) { | 1573 if (!xd->corrupted) { |
1556 // If multiple threads are used to decode tiles, then we use those threads | 1574 // If multiple threads are used to decode tiles, then we use those threads |
1557 // to do parallel loopfiltering. | 1575 // to do parallel loopfiltering. |
1558 vp9_loop_filter_frame_mt(new_fb, pbi, cm, cm->lf.filter_level, 0); | 1576 vp9_loop_filter_frame_mt(&pbi->lf_row_sync, new_fb, pbi->mb.plane, cm, |
| 1577 pbi->tile_workers, pbi->num_tile_workers, |
| 1578 cm->lf.filter_level, 0); |
1559 } | 1579 } |
1560 } else { | 1580 } else { |
1561 *p_data_end = decode_tiles(pbi, data + first_partition_size, data_end); | 1581 *p_data_end = decode_tiles(pbi, data + first_partition_size, data_end); |
1562 } | 1582 } |
1563 | 1583 |
1564 new_fb->corrupted |= xd->corrupted; | 1584 new_fb->corrupted |= xd->corrupted; |
1565 | 1585 |
1566 if (!new_fb->corrupted) { | 1586 if (!new_fb->corrupted) { |
1567 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) { | 1587 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) { |
1568 vp9_adapt_coef_probs(cm); | 1588 vp9_adapt_coef_probs(cm); |
1569 | 1589 |
1570 if (!frame_is_intra_only(cm)) { | 1590 if (!frame_is_intra_only(cm)) { |
1571 vp9_adapt_mode_probs(cm); | 1591 vp9_adapt_mode_probs(cm); |
1572 vp9_adapt_mv_probs(cm, cm->allow_high_precision_mv); | 1592 vp9_adapt_mv_probs(cm, cm->allow_high_precision_mv); |
1573 } | 1593 } |
1574 } else { | 1594 } else { |
1575 debug_check_frame_counts(cm); | 1595 debug_check_frame_counts(cm); |
1576 } | 1596 } |
1577 } else { | 1597 } else { |
1578 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, | 1598 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, |
1579 "Decode failed. Frame data is corrupted."); | 1599 "Decode failed. Frame data is corrupted."); |
1580 } | 1600 } |
1581 | 1601 |
1582 if (cm->refresh_frame_context) | 1602 if (cm->refresh_frame_context) |
1583 cm->frame_contexts[cm->frame_context_idx] = cm->fc; | 1603 cm->frame_contexts[cm->frame_context_idx] = *cm->fc; |
1584 } | 1604 } |
OLD | NEW |