Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(80)

Side by Side Diff: source/libvpx/vp9/decoder/vp9_decodeframe.c

Issue 478033002: libvpx: Pull from upstream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/deps/third_party/libvpx/
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 vp9_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 resize_context_buffers(VP9_COMMON *cm, int width, int height) { 623 static void resize_context_buffers(VP9_COMMON *cm, int width, int height) {
624 #if CONFIG_SIZE_LIMIT 624 #if CONFIG_SIZE_LIMIT
625 if (width > DECODE_WIDTH_LIMIT || height > DECODE_HEIGHT_LIMIT) 625 if (width > DECODE_WIDTH_LIMIT || height > DECODE_HEIGHT_LIMIT)
626 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, 626 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
627 "Width and height beyond allowed size."); 627 "Width and height beyond allowed size.");
628 #endif 628 #endif
629 if (cm->width != width || cm->height != height) { 629 if (cm->width != width || cm->height != height) {
630 // Change in frame size (assumption: color format does not change). 630 const int new_rows = ALIGN_POWER_OF_TWO(height,
631 if (cm->width == 0 || cm->height == 0 || 631 MI_SIZE_LOG2) >> MI_SIZE_LOG2;
632 width * height > cm->width * cm->height) { 632 const int new_cols = ALIGN_POWER_OF_TWO(width,
633 MI_SIZE_LOG2) >> MI_SIZE_LOG2;
634 if (calc_mi_size(new_rows) * calc_mi_size(new_cols) > cm->mi_alloc_size) {
633 if (vp9_alloc_context_buffers(cm, width, height)) 635 if (vp9_alloc_context_buffers(cm, width, height))
634 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, 636 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
635 "Failed to allocate frame buffers"); 637 "Failed to allocate context buffers");
636 } else { 638 } else {
637 vp9_set_mb_mi(cm, width, height); 639 vp9_set_mb_mi(cm, width, height);
638 } 640 }
639 vp9_init_context_buffers(cm); 641 vp9_init_context_buffers(cm);
640 cm->width = width; 642 cm->width = width;
641 cm->height = height; 643 cm->height = height;
642 } 644 }
643 } 645 }
644 646
645 static void setup_frame_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) { 647 static void setup_frame_size(VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) {
646 int width, height; 648 int width, height;
647 vp9_read_frame_size(rb, &width, &height); 649 vp9_read_frame_size(rb, &width, &height);
648 resize_context_buffers(cm, width, height); 650 resize_context_buffers(cm, width, height);
649 setup_display_size(cm, rb); 651 setup_display_size(cm, rb);
650 652
651 if (vp9_realloc_frame_buffer( 653 if (vp9_realloc_frame_buffer(
652 get_frame_new_buffer(cm), cm->width, cm->height, 654 get_frame_new_buffer(cm), cm->width, cm->height,
653 cm->subsampling_x, cm->subsampling_y, VP9_DEC_BORDER_IN_PIXELS, 655 cm->subsampling_x, cm->subsampling_y, VP9_DEC_BORDER_IN_PIXELS,
654 &cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer, cm->get_fb_cb, 656 &cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer, cm->get_fb_cb,
655 cm->cb_priv)) { 657 cm->cb_priv)) {
656 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, 658 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
657 "Failed to allocate frame buffer"); 659 "Failed to allocate frame buffer");
658 } 660 }
659 } 661 }
660 662
661 static void setup_frame_size_with_refs(VP9_COMMON *cm, 663 static void setup_frame_size_with_refs(VP9_COMMON *cm,
662 struct vp9_read_bit_buffer *rb) { 664 struct vp9_read_bit_buffer *rb) {
663 int width, height; 665 int width, height;
664 int found = 0, i; 666 int found = 0, i;
667 int has_valid_ref_frame = 0;
665 for (i = 0; i < REFS_PER_FRAME; ++i) { 668 for (i = 0; i < REFS_PER_FRAME; ++i) {
666 if (vp9_rb_read_bit(rb)) { 669 if (vp9_rb_read_bit(rb)) {
667 YV12_BUFFER_CONFIG *const buf = cm->frame_refs[i].buf; 670 YV12_BUFFER_CONFIG *const buf = cm->frame_refs[i].buf;
668 width = buf->y_crop_width; 671 width = buf->y_crop_width;
669 height = buf->y_crop_height; 672 height = buf->y_crop_height;
670 found = 1; 673 found = 1;
671 break; 674 break;
672 } 675 }
673 } 676 }
674 677
675 if (!found) 678 if (!found)
676 vp9_read_frame_size(rb, &width, &height); 679 vp9_read_frame_size(rb, &width, &height);
677 680
678 // Check that each of the frames that this frame references has valid 681 if (width <=0 || height <= 0)
679 // dimensions. 682 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
683 "Invalid frame size");
684
685 // Check to make sure at least one of frames that this frame references
686 // has valid dimensions.
680 for (i = 0; i < REFS_PER_FRAME; ++i) { 687 for (i = 0; i < REFS_PER_FRAME; ++i) {
681 RefBuffer *const ref_frame = &cm->frame_refs[i]; 688 RefBuffer *const ref_frame = &cm->frame_refs[i];
682 if (!valid_ref_frame_size(ref_frame->buf->y_width, ref_frame->buf->y_height, 689 has_valid_ref_frame |= valid_ref_frame_size(ref_frame->buf->y_crop_width,
683 width, height)) 690 ref_frame->buf->y_crop_height,
684 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, 691 width, height);
685 "Referenced frame has invalid size");
686 } 692 }
693 if (!has_valid_ref_frame)
694 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
695 "Referenced frame has invalid size");
687 696
688 resize_context_buffers(cm, width, height); 697 resize_context_buffers(cm, width, height);
689 setup_display_size(cm, rb); 698 setup_display_size(cm, rb);
690 699
691 if (vp9_realloc_frame_buffer( 700 if (vp9_realloc_frame_buffer(
692 get_frame_new_buffer(cm), cm->width, cm->height, 701 get_frame_new_buffer(cm), cm->width, cm->height,
693 cm->subsampling_x, cm->subsampling_y, VP9_DEC_BORDER_IN_PIXELS, 702 cm->subsampling_x, cm->subsampling_y, VP9_DEC_BORDER_IN_PIXELS,
694 &cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer, cm->get_fb_cb, 703 &cm->frame_bufs[cm->new_fb_idx].raw_frame_buffer, cm->get_fb_cb,
695 cm->cb_priv)) { 704 cm->cb_priv)) {
696 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR, 705 vpx_internal_error(&cm->error, VPX_CODEC_MEM_ERROR,
(...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after
1077 } 1086 }
1078 1087
1079 BITSTREAM_PROFILE vp9_read_profile(struct vp9_read_bit_buffer *rb) { 1088 BITSTREAM_PROFILE vp9_read_profile(struct vp9_read_bit_buffer *rb) {
1080 int profile = vp9_rb_read_bit(rb); 1089 int profile = vp9_rb_read_bit(rb);
1081 profile |= vp9_rb_read_bit(rb) << 1; 1090 profile |= vp9_rb_read_bit(rb) << 1;
1082 if (profile > 2) 1091 if (profile > 2)
1083 profile += vp9_rb_read_bit(rb); 1092 profile += vp9_rb_read_bit(rb);
1084 return (BITSTREAM_PROFILE) profile; 1093 return (BITSTREAM_PROFILE) profile;
1085 } 1094 }
1086 1095
1096 static void read_bitdepth_colorspace_sampling(
1097 VP9_COMMON *cm, struct vp9_read_bit_buffer *rb) {
1098 if (cm->profile >= PROFILE_2)
1099 cm->bit_depth = vp9_rb_read_bit(rb) ? BITS_12 : BITS_10;
1100 cm->color_space = (COLOR_SPACE)vp9_rb_read_literal(rb, 3);
1101 if (cm->color_space != SRGB) {
1102 vp9_rb_read_bit(rb); // [16,235] (including xvycc) vs [0,255] range
1103 if (cm->profile == PROFILE_1 || cm->profile == PROFILE_3) {
1104 cm->subsampling_x = vp9_rb_read_bit(rb);
1105 cm->subsampling_y = vp9_rb_read_bit(rb);
1106 if (cm->subsampling_x == 1 && cm->subsampling_y == 1)
1107 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
1108 "4:2:0 color not supported in profile 1 or 3");
1109 if (vp9_rb_read_bit(rb))
1110 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
1111 "Reserved bit set");
1112 } else {
1113 cm->subsampling_y = cm->subsampling_x = 1;
1114 }
1115 } else {
1116 if (cm->profile == PROFILE_1 || cm->profile == PROFILE_3) {
1117 // Note if colorspace is SRGB then 4:4:4 chroma sampling is assumed.
1118 // 4:2:2 or 4:4:0 chroma sampling is not allowed.
1119 cm->subsampling_y = cm->subsampling_x = 0;
1120 if (vp9_rb_read_bit(rb))
1121 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
1122 "Reserved bit set");
1123 } else {
1124 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
1125 "4:4:4 color not supported in profile 0 or 2");
1126 }
1127 }
1128 }
1129
1087 static size_t read_uncompressed_header(VP9Decoder *pbi, 1130 static size_t read_uncompressed_header(VP9Decoder *pbi,
1088 struct vp9_read_bit_buffer *rb) { 1131 struct vp9_read_bit_buffer *rb) {
1089 VP9_COMMON *const cm = &pbi->common; 1132 VP9_COMMON *const cm = &pbi->common;
1090 size_t sz; 1133 size_t sz;
1091 int i; 1134 int i;
1092 1135
1093 cm->last_frame_type = cm->frame_type; 1136 cm->last_frame_type = cm->frame_type;
1094 1137
1095 if (vp9_rb_read_literal(rb, 2) != VP9_FRAME_MARKER) 1138 if (vp9_rb_read_literal(rb, 2) != VP9_FRAME_MARKER)
1096 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, 1139 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
(...skipping 22 matching lines...) Expand all
1119 } 1162 }
1120 1163
1121 cm->frame_type = (FRAME_TYPE) vp9_rb_read_bit(rb); 1164 cm->frame_type = (FRAME_TYPE) vp9_rb_read_bit(rb);
1122 cm->show_frame = vp9_rb_read_bit(rb); 1165 cm->show_frame = vp9_rb_read_bit(rb);
1123 cm->error_resilient_mode = vp9_rb_read_bit(rb); 1166 cm->error_resilient_mode = vp9_rb_read_bit(rb);
1124 1167
1125 if (cm->frame_type == KEY_FRAME) { 1168 if (cm->frame_type == KEY_FRAME) {
1126 if (!vp9_read_sync_code(rb)) 1169 if (!vp9_read_sync_code(rb))
1127 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, 1170 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
1128 "Invalid frame sync code"); 1171 "Invalid frame sync code");
1129 if (cm->profile > PROFILE_1)
1130 cm->bit_depth = vp9_rb_read_bit(rb) ? BITS_12 : BITS_10;
1131 cm->color_space = (COLOR_SPACE)vp9_rb_read_literal(rb, 3);
1132 if (cm->color_space != SRGB) {
1133 vp9_rb_read_bit(rb); // [16,235] (including xvycc) vs [0,255] range
1134 if (cm->profile == PROFILE_1 || cm->profile == PROFILE_3) {
1135 cm->subsampling_x = vp9_rb_read_bit(rb);
1136 cm->subsampling_y = vp9_rb_read_bit(rb);
1137 if (vp9_rb_read_bit(rb))
1138 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
1139 "Reserved bit set");
1140 } else {
1141 cm->subsampling_y = cm->subsampling_x = 1;
1142 }
1143 } else {
1144 if (cm->profile == PROFILE_1 || cm->profile == PROFILE_3) {
1145 cm->subsampling_y = cm->subsampling_x = 0;
1146 if (vp9_rb_read_bit(rb))
1147 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
1148 "Reserved bit set");
1149 } else {
1150 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
1151 "4:4:4 color not supported in profile 0");
1152 }
1153 }
1154 1172
1173 read_bitdepth_colorspace_sampling(cm, rb);
1155 pbi->refresh_frame_flags = (1 << REF_FRAMES) - 1; 1174 pbi->refresh_frame_flags = (1 << REF_FRAMES) - 1;
1156 1175
1157 for (i = 0; i < REFS_PER_FRAME; ++i) { 1176 for (i = 0; i < REFS_PER_FRAME; ++i) {
1158 cm->frame_refs[i].idx = -1; 1177 cm->frame_refs[i].idx = -1;
1159 cm->frame_refs[i].buf = NULL; 1178 cm->frame_refs[i].buf = NULL;
1160 } 1179 }
1161 1180
1162 setup_frame_size(cm, rb); 1181 setup_frame_size(cm, rb);
1163 } else { 1182 } else {
1164 cm->intra_only = cm->show_frame ? 0 : vp9_rb_read_bit(rb); 1183 cm->intra_only = cm->show_frame ? 0 : vp9_rb_read_bit(rb);
1165 1184
1166 cm->reset_frame_context = cm->error_resilient_mode ? 1185 cm->reset_frame_context = cm->error_resilient_mode ?
1167 0 : vp9_rb_read_literal(rb, 2); 1186 0 : vp9_rb_read_literal(rb, 2);
1168 1187
1169 if (cm->intra_only) { 1188 if (cm->intra_only) {
1170 if (!vp9_read_sync_code(rb)) 1189 if (!vp9_read_sync_code(rb))
1171 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM, 1190 vpx_internal_error(&cm->error, VPX_CODEC_UNSUP_BITSTREAM,
1172 "Invalid frame sync code"); 1191 "Invalid frame sync code");
1192 if (cm->profile > PROFILE_0) {
1193 read_bitdepth_colorspace_sampling(cm, rb);
1194 } else {
1195 // NOTE: The intra-only frame header does not include the specification
1196 // of either the color format or color sub-sampling in profile 0. VP9
1197 // specifies that the default color space should be YUV 4:2:0 in this
1198 // case (normative).
1199 cm->color_space = BT_601;
1200 cm->subsampling_y = cm->subsampling_x = 1;
1201 }
1173 1202
1174 pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES); 1203 pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES);
1175
1176 // NOTE: The intra-only frame header does not include the specification of
1177 // either the color format or color sub-sampling. VP9 specifies that the
1178 // default color space should be YUV 4:2:0 in this case (normative).
1179 cm->color_space = BT_601;
1180 cm->subsampling_y = cm->subsampling_x = 1;
1181
1182 setup_frame_size(cm, rb); 1204 setup_frame_size(cm, rb);
1183 } else { 1205 } else {
1184 pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES); 1206 pbi->refresh_frame_flags = vp9_rb_read_literal(rb, REF_FRAMES);
1185 for (i = 0; i < REFS_PER_FRAME; ++i) { 1207 for (i = 0; i < REFS_PER_FRAME; ++i) {
1186 const int ref = vp9_rb_read_literal(rb, REF_FRAMES_LOG2); 1208 const int ref = vp9_rb_read_literal(rb, REF_FRAMES_LOG2);
1187 const int idx = cm->ref_frame_map[ref]; 1209 const int idx = cm->ref_frame_map[ref];
1188 RefBuffer *const ref_frame = &cm->frame_refs[i]; 1210 RefBuffer *const ref_frame = &cm->frame_refs[i];
1189 ref_frame->idx = idx; 1211 ref_frame->idx = idx;
1190 ref_frame->buf = &cm->frame_bufs[idx].buf; 1212 ref_frame->buf = &cm->frame_bufs[idx].buf;
1191 cm->ref_frame_sign_bias[LAST_FRAME + i] = vp9_rb_read_bit(rb); 1213 cm->ref_frame_sign_bias[LAST_FRAME + i] = vp9_rb_read_bit(rb);
(...skipping 10 matching lines...) Expand all
1202 ref_buf->buf->y_crop_width, 1224 ref_buf->buf->y_crop_width,
1203 ref_buf->buf->y_crop_height, 1225 ref_buf->buf->y_crop_height,
1204 cm->width, cm->height); 1226 cm->width, cm->height);
1205 if (vp9_is_scaled(&ref_buf->sf)) 1227 if (vp9_is_scaled(&ref_buf->sf))
1206 vp9_extend_frame_borders(ref_buf->buf); 1228 vp9_extend_frame_borders(ref_buf->buf);
1207 } 1229 }
1208 } 1230 }
1209 } 1231 }
1210 1232
1211 if (!cm->error_resilient_mode) { 1233 if (!cm->error_resilient_mode) {
1212 cm->coding_use_prev_mi = 1;
1213 cm->refresh_frame_context = vp9_rb_read_bit(rb); 1234 cm->refresh_frame_context = vp9_rb_read_bit(rb);
1214 cm->frame_parallel_decoding_mode = vp9_rb_read_bit(rb); 1235 cm->frame_parallel_decoding_mode = vp9_rb_read_bit(rb);
1215 } else { 1236 } else {
1216 cm->coding_use_prev_mi = 0;
1217 cm->refresh_frame_context = 0; 1237 cm->refresh_frame_context = 0;
1218 cm->frame_parallel_decoding_mode = 1; 1238 cm->frame_parallel_decoding_mode = 1;
1219 } 1239 }
1220 1240
1221 // This flag will be overridden by the call to vp9_setup_past_independence 1241 // This flag will be overridden by the call to vp9_setup_past_independence
1222 // below, forcing the use of context 0 for those frame types. 1242 // below, forcing the use of context 0 for those frame types.
1223 cm->frame_context_idx = vp9_rb_read_literal(rb, FRAME_CONTEXTS_LOG2); 1243 cm->frame_context_idx = vp9_rb_read_literal(rb, FRAME_CONTEXTS_LOG2);
1224 1244
1225 if (frame_is_intra_only(cm) || cm->error_resilient_mode) 1245 if (frame_is_intra_only(cm) || cm->error_resilient_mode)
1226 vp9_setup_past_independence(cm); 1246 vp9_setup_past_independence(cm);
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
1382 return; 1402 return;
1383 } 1403 }
1384 1404
1385 data += vp9_rb_bytes_read(&rb); 1405 data += vp9_rb_bytes_read(&rb);
1386 if (!read_is_valid(data, first_partition_size, data_end)) 1406 if (!read_is_valid(data, first_partition_size, data_end))
1387 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, 1407 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
1388 "Truncated packet or corrupt header length"); 1408 "Truncated packet or corrupt header length");
1389 1409
1390 init_macroblockd(cm, &pbi->mb); 1410 init_macroblockd(cm, &pbi->mb);
1391 1411
1392 if (cm->coding_use_prev_mi) 1412 if (!cm->error_resilient_mode)
1393 set_prev_mi(cm); 1413 set_prev_mi(cm);
1394 else 1414 else
1395 cm->prev_mi = NULL; 1415 cm->prev_mi = NULL;
1396 1416
1397 setup_plane_dequants(cm, xd, cm->base_qindex); 1417 setup_plane_dequants(cm, xd, cm->base_qindex);
1398 vp9_setup_block_planes(xd, cm->subsampling_x, cm->subsampling_y); 1418 vp9_setup_block_planes(xd, cm->subsampling_x, cm->subsampling_y);
1399 1419
1400 cm->fc = cm->frame_contexts[cm->frame_context_idx]; 1420 cm->fc = cm->frame_contexts[cm->frame_context_idx];
1401 vp9_zero(cm->counts); 1421 vp9_zero(cm->counts);
1402 vp9_zero(xd->dqcoeff); 1422 vp9_zero(xd->dqcoeff);
(...skipping 27 matching lines...) Expand all
1430 debug_check_frame_counts(cm); 1450 debug_check_frame_counts(cm);
1431 } 1451 }
1432 } else { 1452 } else {
1433 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME, 1453 vpx_internal_error(&cm->error, VPX_CODEC_CORRUPT_FRAME,
1434 "Decode failed. Frame data is corrupted."); 1454 "Decode failed. Frame data is corrupted.");
1435 } 1455 }
1436 1456
1437 if (cm->refresh_frame_context) 1457 if (cm->refresh_frame_context)
1438 cm->frame_contexts[cm->frame_context_idx] = cm->fc; 1458 cm->frame_contexts[cm->frame_context_idx] = cm->fc;
1439 } 1459 }
OLDNEW
« no previous file with comments | « source/libvpx/vp9/common/x86/vp9_postproc_x86.h ('k') | source/libvpx/vp9/decoder/vp9_decodemv.c » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698