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 10 matching lines...) Expand all Loading... |
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_pred_common.h" | 26 #include "vp9/common/vp9_pred_common.h" |
27 #include "vp9/common/vp9_quant_common.h" | 27 #include "vp9/common/vp9_quant_common.h" |
28 #include "vp9/common/vp9_reconintra.h" | 28 #include "vp9/common/vp9_reconintra.h" |
29 #include "vp9/common/vp9_reconinter.h" | 29 #include "vp9/common/vp9_reconinter.h" |
30 #include "vp9/common/vp9_seg_common.h" | 30 #include "vp9/common/vp9_seg_common.h" |
| 31 #include "vp9/common/vp9_thread.h" |
31 #include "vp9/common/vp9_tile_common.h" | 32 #include "vp9/common/vp9_tile_common.h" |
32 | 33 |
33 #include "vp9/decoder/vp9_decodeframe.h" | 34 #include "vp9/decoder/vp9_decodeframe.h" |
34 #include "vp9/decoder/vp9_detokenize.h" | 35 #include "vp9/decoder/vp9_detokenize.h" |
35 #include "vp9/decoder/vp9_decodemv.h" | 36 #include "vp9/decoder/vp9_decodemv.h" |
36 #include "vp9/decoder/vp9_decoder.h" | 37 #include "vp9/decoder/vp9_decoder.h" |
37 #include "vp9/decoder/vp9_dsubexp.h" | 38 #include "vp9/decoder/vp9_dsubexp.h" |
38 #include "vp9/decoder/vp9_dthread.h" | 39 #include "vp9/decoder/vp9_dthread.h" |
39 #include "vp9/decoder/vp9_read_bit_buffer.h" | 40 #include "vp9/decoder/vp9_read_bit_buffer.h" |
40 #include "vp9/decoder/vp9_reader.h" | 41 #include "vp9/decoder/vp9_reader.h" |
41 #include "vp9/decoder/vp9_thread.h" | |
42 | 42 |
43 #define MAX_VP9_HEADER_SIZE 80 | 43 #define MAX_VP9_HEADER_SIZE 80 |
44 | 44 |
45 static int is_compound_reference_allowed(const VP9_COMMON *cm) { | 45 static int is_compound_reference_allowed(const VP9_COMMON *cm) { |
46 int i; | 46 int i; |
47 for (i = 1; i < REFS_PER_FRAME; ++i) | 47 for (i = 1; i < REFS_PER_FRAME; ++i) |
48 if (cm->ref_frame_sign_bias[i + 1] != cm->ref_frame_sign_bias[1]) | 48 if (cm->ref_frame_sign_bias[i + 1] != cm->ref_frame_sign_bias[1]) |
49 return 1; | 49 return 1; |
50 | 50 |
51 return 0; | 51 return 0; |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
598 | 598 |
599 static INTERP_FILTER read_interp_filter(struct vp9_read_bit_buffer *rb) { | 599 static INTERP_FILTER read_interp_filter(struct vp9_read_bit_buffer *rb) { |
600 const INTERP_FILTER literal_to_filter[] = { EIGHTTAP_SMOOTH, | 600 const INTERP_FILTER literal_to_filter[] = { EIGHTTAP_SMOOTH, |
601 EIGHTTAP, | 601 EIGHTTAP, |
602 EIGHTTAP_SHARP, | 602 EIGHTTAP_SHARP, |
603 BILINEAR }; | 603 BILINEAR }; |
604 return vp9_rb_read_bit(rb) ? SWITCHABLE | 604 return vp9_rb_read_bit(rb) ? SWITCHABLE |
605 : literal_to_filter[vp9_rb_read_literal(rb, 2)]; | 605 : literal_to_filter[vp9_rb_read_literal(rb, 2)]; |
606 } | 606 } |
607 | 607 |
608 static void read_frame_size(struct vp9_read_bit_buffer *rb, | 608 void vp9_read_frame_size(struct vp9_read_bit_buffer *rb, |
609 int *width, int *height) { | 609 int *width, int *height) { |
610 const int w = vp9_rb_read_literal(rb, 16) + 1; | 610 const int w = vp9_rb_read_literal(rb, 16) + 1; |
611 const int h = vp9_rb_read_literal(rb, 16) + 1; | 611 const int h = vp9_rb_read_literal(rb, 16) + 1; |
612 *width = w; | 612 *width = w; |
613 *height = h; | 613 *height = h; |
614 } | 614 } |
615 | 615 |
616 static void setup_display_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { | 616 static void setup_display_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { |
617 cm->display_width = cm->width; | 617 cm->display_width = cm->width; |
618 cm->display_height = cm->height; | 618 cm->display_height = cm->height; |
619 if (vp9_rb_read_bit(rb)) | 619 if (vp9_rb_read_bit(rb)) |
620 read_frame_size(rb, &cm->display_width, &cm->display_height); | 620 vp9_read_frame_size(rb, &cm->display_width, &cm->display_height); |
621 } | 621 } |
622 | 622 |
623 static void apply_frame_size(VP9_COMMON *cm, int width, int height) { | 623 static void apply_frame_size(VP9_COMMON *cm, int width, int height) { |
624 if (cm->width != width || cm->height != height) { | 624 if (cm->width != width || cm->height != height) { |
625 // Change in frame size. | 625 // Change in frame size. |
626 // TODO(agrange) Don't test width/height, check overall size. | 626 // TODO(agrange) Don't test width/height, check overall size. |
627 if (width > cm->width || height > cm->height) { | 627 if (width > cm->width || height > cm->height) { |
628 // Rescale frame buffers only if they're not big enough already. | 628 // Rescale frame buffers only if they're not big enough already. |
629 if (vp9_resize_frame_buffers(cm, width, height)) | 629 if (vp9_resize_frame_buffers(cm, width, height)) |
630 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 630 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
(...skipping 11 matching lines...) Expand all Loading... |
642 cm->subsampling_x, cm->subsampling_y, VP9_DEC_BORDER_IN_PIXELS, | 642 cm->subsampling_x, cm->subsampling_y, VP9_DEC_BORDER_IN_PIXELS, |
643 &cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer, cm->get_fb_cb, | 643 &cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer, cm->get_fb_cb, |
644 cm->cb_priv)) { | 644 cm->cb_priv)) { |
645 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, | 645 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, |
646 "Failed to allocate frame buffer"); | 646 "Failed to allocate frame buffer"); |
647 } | 647 } |
648 } | 648 } |
649 | 649 |
650 static void setup_frame_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { | 650 static void setup_frame_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { |
651 int width, height; | 651 int width, height; |
652 read_frame_size(rb, &width, &height); | 652 vp9_read_frame_size(rb, &width, &height); |
653 apply_frame_size(cm, width, height); | 653 apply_frame_size(cm, width, height); |
654 setup_display_size(cm, rb); | 654 setup_display_size(cm, rb); |
655 } | 655 } |
656 | 656 |
657 static void setup_frame_size_with_refs(VP9_COMMON *cm, | 657 static void setup_frame_size_with_refs(VP9_COMMON *cm, |
658 struct vp9_read_bit_buffer *rb) { | 658 struct vp9_read_bit_buffer *rb) { |
659 int width, height; | 659 int width, height; |
660 int found = 0, i; | 660 int found = 0, i; |
661 for (i = 0; i < REFS_PER_FRAME; ++i) { | 661 for (i = 0; i < REFS_PER_FRAME; ++i) { |
662 if (vp9_rb_read_bit(rb)) { | 662 if (vp9_rb_read_bit(rb)) { |
663 YV12_BUFFER_CONFIG *const buf = cm->frame_refs[i].buf; | 663 YV12_BUFFER_CONFIG *const buf = cm->frame_refs[i].buf; |
664 width = buf->y_crop_width; | 664 width = buf->y_crop_width; |
665 height = buf->y_crop_height; | 665 height = buf->y_crop_height; |
666 found = 1; | 666 found = 1; |
667 break; | 667 break; |
668 } | 668 } |
669 } | 669 } |
670 | 670 |
671 if (!found) | 671 if (!found) |
672 read_frame_size(rb, &width, &height); | 672 vp9_read_frame_size(rb, &width, &height); |
673 | 673 |
674 // Check that each of the frames that this frame references has valid | 674 // Check that each of the frames that this frame references has valid |
675 // dimensions. | 675 // dimensions. |
676 for (i = 0; i < REFS_PER_FRAME; ++i) { | 676 for (i = 0; i < REFS_PER_FRAME; ++i) { |
677 RefBuffer *const ref_frame = &cm->frame_refs[i]; | 677 RefBuffer *const ref_frame = &cm->frame_refs[i]; |
678 const int ref_width = ref_frame->buf->y_width; | 678 const int ref_width = ref_frame->buf->y_width; |
679 const int ref_height = ref_frame->buf->y_height; | 679 const int ref_height = ref_frame->buf->y_height; |
680 | 680 |
681 if (!valid_ref_frame_size(ref_width, ref_height, width, height)) | 681 if (!valid_ref_frame_size(ref_width, ref_height, width, height)) |
682 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, | 682 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
851 tile_cols - tile_col - 1 : tile_col; | 851 tile_cols - tile_col - 1 : tile_col; |
852 tile_data = pbi->tile_data + tile_cols * tile_row + col; | 852 tile_data = pbi->tile_data + tile_cols * tile_row + col; |
853 vp9_tile_set_col(&tile, tile_data->cm, col); | 853 vp9_tile_set_col(&tile, tile_data->cm, col); |
854 vp9_zero(tile_data->xd.left_context); | 854 vp9_zero(tile_data->xd.left_context); |
855 vp9_zero(tile_data->xd.left_seg_context); | 855 vp9_zero(tile_data->xd.left_seg_context); |
856 for (mi_col = tile.mi_col_start; mi_col < tile.mi_col_end; | 856 for (mi_col = tile.mi_col_start; mi_col < tile.mi_col_end; |
857 mi_col += MI_BLOCK_SIZE) { | 857 mi_col += MI_BLOCK_SIZE) { |
858 decode_partition(tile_data->cm, &tile_data->xd, &tile, mi_row, mi_col, | 858 decode_partition(tile_data->cm, &tile_data->xd, &tile, mi_row, mi_col, |
859 &tile_data->bit_reader, BLOCK_64X64); | 859 &tile_data->bit_reader, BLOCK_64X64); |
860 } | 860 } |
| 861 pbi->mb.corrupted |= tile_data->xd.corrupted; |
861 } | 862 } |
862 // Loopfilter one row. | 863 // Loopfilter one row. |
863 if (cm->lf.filter_level) { | 864 if (cm->lf.filter_level) { |
864 const int lf_start = mi_row - MI_BLOCK_SIZE; | 865 const int lf_start = mi_row - MI_BLOCK_SIZE; |
865 LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1; | 866 LFWorkerData *const lf_data = (LFWorkerData*)pbi->lf_worker.data1; |
866 | 867 |
867 // delay the loopfilter by 1 macroblock row. | 868 // delay the loopfilter by 1 macroblock row. |
868 if (lf_start < 0) continue; | 869 if (lf_start < 0) continue; |
869 | 870 |
870 // decoding has completed: finish up the loop filter in this thread. | 871 // decoding has completed: finish up the loop filter in this thread. |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1046 TileWorkerData *const tile_data = | 1047 TileWorkerData *const tile_data = |
1047 (TileWorkerData*)pbi->tile_workers[final_worker].data1; | 1048 (TileWorkerData*)pbi->tile_workers[final_worker].data1; |
1048 bit_reader_end = vp9_reader_find_end(&tile_data->bit_reader); | 1049 bit_reader_end = vp9_reader_find_end(&tile_data->bit_reader); |
1049 final_worker = -1; | 1050 final_worker = -1; |
1050 } | 1051 } |
1051 } | 1052 } |
1052 | 1053 |
1053 return bit_reader_end; | 1054 return bit_reader_end; |
1054 } | 1055 } |
1055 | 1056 |
1056 static void check_sync_code(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { | |
1057 if (vp9_rb_read_literal(rb, 8) != VP9_SYNC_CODE_0 || | |
1058 vp9_rb_read_literal(rb, 8) != VP9_SYNC_CODE_1 || | |
1059 vp9_rb_read_literal(rb, 8) != VP9_SYNC_CODE_2) { | |
1060 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, | |
1061 "Invalid frame sync code"); | |
1062 } | |
1063 } | |
1064 | |
1065 static void error_handler(void *data) { | 1057 static void error_handler(void *data) { |
1066 VP9_COMMON *const cm = (VP9_COMMON *)data; | 1058 VP9_COMMON *const cm = (VP9_COMMON *)data; |
1067 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, "Truncated packet"); | 1059 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, "Truncated packet"); |
1068 } | 1060 } |
1069 | 1061 |
| 1062 int vp9_read_sync_code(struct vp9_read_bit_buffer *const rb) { |
| 1063 return vp9_rb_read_literal(rb, 8) == VP9_SYNC_CODE_0 && |
| 1064 vp9_rb_read_literal(rb, 8) == VP9_SYNC_CODE_1 && |
| 1065 vp9_rb_read_literal(rb, 8) == VP9_SYNC_CODE_2; |
| 1066 } |
| 1067 |
1070 static BITSTREAM_PROFILE read_profile(struct vp9_read_bit_buffer *rb) { | 1068 static BITSTREAM_PROFILE read_profile(struct vp9_read_bit_buffer *rb) { |
1071 int profile = vp9_rb_read_bit(rb); | 1069 int profile = vp9_rb_read_bit(rb); |
1072 profile |= vp9_rb_read_bit(rb) << 1; | 1070 profile |= vp9_rb_read_bit(rb) << 1; |
1073 return (BITSTREAM_PROFILE) profile; | 1071 return (BITSTREAM_PROFILE) profile; |
1074 } | 1072 } |
1075 | 1073 |
1076 static size_t read_uncompressed_header(VP9Decoder *pbi, | 1074 static size_t read_uncompressed_header(VP9Decoder *pbi, |
1077 struct vp9_read_bit_buffer *rb) { | 1075 struct vp9_read_bit_buffer *rb) { |
1078 VP9_COMMON *const cm = &pbi->common; | 1076 VP9_COMMON *const cm = &pbi->common; |
1079 size_t sz; | 1077 size_t sz; |
(...skipping 25 matching lines...) Expand all Loading... |
1105 cm->lf.filter_level = 0; | 1103 cm->lf.filter_level = 0; |
1106 cm->show_frame = 1; | 1104 cm->show_frame = 1; |
1107 return 0; | 1105 return 0; |
1108 } | 1106 } |
1109 | 1107 |
1110 cm->frame_type = (FRAME_TYPE) vp9_rb_read_bit(rb); | 1108 cm->frame_type = (FRAME_TYPE) vp9_rb_read_bit(rb); |
1111 cm->show_frame = vp9_rb_read_bit(rb); | 1109 cm->show_frame = vp9_rb_read_bit(rb); |
1112 cm->error_resilient_mode = vp9_rb_read_bit(rb); | 1110 cm->error_resilient_mode = vp9_rb_read_bit(rb); |
1113 | 1111 |
1114 if (cm->frame_type == KEY_FRAME) { | 1112 if (cm->frame_type == KEY_FRAME) { |
1115 check_sync_code(cm, rb); | 1113 if (!vp9_read_sync_code(rb)) |
| 1114 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, |
| 1115 "Invalid frame sync code"); |
1116 if (cm->profile > PROFILE_1) | 1116 if (cm->profile > PROFILE_1) |
1117 cm->bit_depth = vp9_rb_read_bit(rb) ? BITS_12 : BITS_10; | 1117 cm->bit_depth = vp9_rb_read_bit(rb) ? BITS_12 : BITS_10; |
1118 cm->color_space = (COLOR_SPACE)vp9_rb_read_literal(rb, 3); | 1118 cm->color_space = (COLOR_SPACE)vp9_rb_read_literal(rb, 3); |
1119 if (cm->color_space != SRGB) { | 1119 if (cm->color_space != SRGB) { |
1120 vp9_rb_read_bit(rb); // [16,235] (including xvycc) vs [0,255] range | 1120 vp9_rb_read_bit(rb); // [16,235] (including xvycc) vs [0,255] range |
1121 if (cm->profile >= PROFILE_1) { | 1121 if (cm->profile >= PROFILE_1) { |
1122 cm->subsampling_x = vp9_rb_read_bit(rb); | 1122 cm->subsampling_x = vp9_rb_read_bit(rb); |
1123 cm->subsampling_y = vp9_rb_read_bit(rb); | 1123 cm->subsampling_y = vp9_rb_read_bit(rb); |
1124 vp9_rb_read_bit(rb); // has extra plane | 1124 vp9_rb_read_bit(rb); // has extra plane |
1125 } else { | 1125 } else { |
(...skipping 17 matching lines...) Expand all Loading... |
1143 } | 1143 } |
1144 | 1144 |
1145 setup_frame_size(cm, rb); | 1145 setup_frame_size(cm, rb); |
1146 } else { | 1146 } else { |
1147 cm->intra_only = cm->show_frame ? 0 : vp9_rb_read_bit(rb); | 1147 cm->intra_only = cm->show_frame ? 0 : vp9_rb_read_bit(rb); |
1148 | 1148 |
1149 cm->reset_frame_context = cm->error_resilient_mode ? | 1149 cm->reset_frame_context = cm->error_resilient_mode ? |
1150 0 : vp9_rb_read_literal(rb, 2); | 1150 0 : vp9_rb_read_literal(rb, 2); |
1151 | 1151 |
1152 if (cm->intra_only) { | 1152 if (cm->intra_only) { |
1153 check_sync_code(cm, rb); | 1153 if (!vp9_read_sync_code(rb)) |
| 1154 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, |
| 1155 "Invalid frame sync code"); |
1154 | 1156 |
1155 pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES); | 1157 pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES); |
| 1158 |
| 1159 // NOTE: The intra-only frame header does not include the specification of |
| 1160 // either the color format or color sub-sampling. VP9 specifies that the |
| 1161 // default color space should be YUV 4:2:0 in this case (normative). |
| 1162 cm->color_space = BT_601; |
| 1163 cm->subsampling_y = cm->subsampling_x = 1; |
| 1164 |
1156 setup_frame_size(cm, rb); | 1165 setup_frame_size(cm, rb); |
1157 } else { | 1166 } else { |
1158 pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES); | 1167 pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES); |
1159 for (i = 0; i < REFS_PER_FRAME; ++i) { | 1168 for (i = 0; i < REFS_PER_FRAME; ++i) { |
1160 const int ref = vp9_rb_read_literal(rb, REF_FRAMES_LOG2); | 1169 const int ref = vp9_rb_read_literal(rb, REF_FRAMES_LOG2); |
1161 const int idx = cm->ref_frame_map[ref]; | 1170 const int idx = cm->ref_frame_map[ref]; |
1162 RefBuffer *const ref_frame = &cm->frame_refs[i]; | 1171 RefBuffer *const ref_frame = &cm->frame_refs[i]; |
1163 ref_frame->idx = idx; | 1172 ref_frame->idx = idx; |
1164 ref_frame->buf = &cm->frame_bufs[idx].buf; | 1173 ref_frame->buf = &cm->frame_bufs[idx].buf; |
1165 cm->ref_frame_sign_bias[LAST_FRAME + i] = vp9_rb_read_bit(rb); | 1174 cm->ref_frame_sign_bias[LAST_FRAME + i] = vp9_rb_read_bit(rb); |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1396 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) { | 1405 if (!cm->error_resilient_mode && !cm->frame_parallel_decoding_mode) { |
1397 vp9_adapt_coef_probs(cm); | 1406 vp9_adapt_coef_probs(cm); |
1398 | 1407 |
1399 if (!frame_is_intra_only(cm)) { | 1408 if (!frame_is_intra_only(cm)) { |
1400 vp9_adapt_mode_probs(cm); | 1409 vp9_adapt_mode_probs(cm); |
1401 vp9_adapt_mv_probs(cm, cm->allow_high_precision_mv); | 1410 vp9_adapt_mv_probs(cm, cm->allow_high_precision_mv); |
1402 } | 1411 } |
1403 } else { | 1412 } else { |
1404 debug_check_frame_counts(cm); | 1413 debug_check_frame_counts(cm); |
1405 } | 1414 } |
| 1415 } else { |
| 1416 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, |
| 1417 "Decode failed. Frame data is corrupted."); |
1406 } | 1418 } |
1407 | 1419 |
1408 if (cm->refresh_frame_context) | 1420 if (cm->refresh_frame_context) |
1409 cm->frame_contexts[cm->frame_context_idx] = cm->fc; | 1421 cm->frame_contexts[cm->frame_context_idx] = cm->fc; |
1410 } | 1422 } |
OLD | NEW |