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 741 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
752 } | 752 } |
753 yv12_extend_frame_left_right_c(yv12_fb_new, | 753 yv12_extend_frame_left_right_c(yv12_fb_new, |
754 eb_dst[0], | 754 eb_dst[0], |
755 eb_dst[1], | 755 eb_dst[1], |
756 eb_dst[2]); | 756 eb_dst[2]); |
757 | 757 |
758 yv12_extend_frame_bottom_c(yv12_fb_new); | 758 yv12_extend_frame_bottom_c(yv12_fb_new); |
759 | 759 |
760 } | 760 } |
761 | 761 |
762 static unsigned int read_partition_size(const unsigned char *cx_size) | 762 static unsigned int read_partition_size(VP8D_COMP *pbi, |
| 763 const unsigned char *cx_size) |
763 { | 764 { |
764 const unsigned int size = | 765 unsigned char temp[3]; |
765 cx_size[0] + (cx_size[1] << 8) + (cx_size[2] << 16); | 766 if (pbi->decrypt_cb) |
766 return size; | 767 { |
| 768 pbi->decrypt_cb(pbi->decrypt_state, cx_size, temp, 3); |
| 769 cx_size = temp; |
| 770 } |
| 771 return cx_size[0] + (cx_size[1] << 8) + (cx_size[2] << 16); |
767 } | 772 } |
768 | 773 |
769 static int read_is_valid(const unsigned char *start, | 774 static int read_is_valid(const unsigned char *start, |
770 size_t len, | 775 size_t len, |
771 const unsigned char *end) | 776 const unsigned char *end) |
772 { | 777 { |
773 return (start + len > start && start + len <= end); | 778 return (start + len > start && start + len <= end); |
774 } | 779 } |
775 | 780 |
776 static unsigned int read_available_partition_size( | 781 static unsigned int read_available_partition_size( |
(...skipping 10 matching lines...) Expand all Loading... |
787 unsigned int partition_size = 0; | 792 unsigned int partition_size = 0; |
788 ptrdiff_t bytes_left = fragment_end - fragment_start; | 793 ptrdiff_t bytes_left = fragment_end - fragment_start; |
789 /* Calculate the length of this partition. The last partition | 794 /* Calculate the length of this partition. The last partition |
790 * size is implicit. If the partition size can't be read, then | 795 * size is implicit. If the partition size can't be read, then |
791 * either use the remaining data in the buffer (for EC mode) | 796 * either use the remaining data in the buffer (for EC mode) |
792 * or throw an error. | 797 * or throw an error. |
793 */ | 798 */ |
794 if (i < num_part - 1) | 799 if (i < num_part - 1) |
795 { | 800 { |
796 if (read_is_valid(partition_size_ptr, 3, first_fragment_end)) | 801 if (read_is_valid(partition_size_ptr, 3, first_fragment_end)) |
797 partition_size = read_partition_size(partition_size_ptr); | 802 partition_size = read_partition_size(pbi, partition_size_ptr); |
798 else if (pbi->ec_active) | 803 else if (pbi->ec_active) |
799 partition_size = (unsigned int)bytes_left; | 804 partition_size = (unsigned int)bytes_left; |
800 else | 805 else |
801 vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, | 806 vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, |
802 "Truncated partition size data"); | 807 "Truncated partition size data"); |
803 } | 808 } |
804 else | 809 else |
805 partition_size = (unsigned int)bytes_left; | 810 partition_size = (unsigned int)bytes_left; |
806 | 811 |
807 /* Validate the calculated partition length. If the buffer | 812 /* Validate the calculated partition length. If the buffer |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 } | 892 } |
888 } | 893 } |
889 | 894 |
890 pbi->fragments.count = num_token_partitions + 1; | 895 pbi->fragments.count = num_token_partitions + 1; |
891 | 896 |
892 for (partition_idx = 1; partition_idx < pbi->fragments.count; ++partition_id
x) | 897 for (partition_idx = 1; partition_idx < pbi->fragments.count; ++partition_id
x) |
893 { | 898 { |
894 if (vp8dx_start_decode(bool_decoder, | 899 if (vp8dx_start_decode(bool_decoder, |
895 pbi->fragments.ptrs[partition_idx], | 900 pbi->fragments.ptrs[partition_idx], |
896 pbi->fragments.sizes[partition_idx], | 901 pbi->fragments.sizes[partition_idx], |
897 pbi->fragments.ptrs[0], | 902 pbi->decrypt_cb, pbi->decrypt_state)) |
898 pbi->decrypt_key)) | |
899 vpx_internal_error(&pbi->common.error, VPX_CODEC_MEM_ERROR, | 903 vpx_internal_error(&pbi->common.error, VPX_CODEC_MEM_ERROR, |
900 "Failed to allocate bool decoder %d", | 904 "Failed to allocate bool decoder %d", |
901 partition_idx); | 905 partition_idx); |
902 | 906 |
903 bool_decoder++; | 907 bool_decoder++; |
904 } | 908 } |
905 | 909 |
906 #if CONFIG_MULTITHREAD | 910 #if CONFIG_MULTITHREAD |
907 /* Clamp number of decoder threads */ | 911 /* Clamp number of decoder threads */ |
908 if (pbi->decoding_thread_count > num_token_partitions - 1) | 912 if (pbi->decoding_thread_count > num_token_partitions - 1) |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 xd->fullpixel_mask = 0xfffffff8; | 983 xd->fullpixel_mask = 0xfffffff8; |
980 | 984 |
981 } | 985 } |
982 | 986 |
983 int vp8_decode_frame(VP8D_COMP *pbi) | 987 int vp8_decode_frame(VP8D_COMP *pbi) |
984 { | 988 { |
985 vp8_reader *const bc = &pbi->mbc[8]; | 989 vp8_reader *const bc = &pbi->mbc[8]; |
986 VP8_COMMON *const pc = &pbi->common; | 990 VP8_COMMON *const pc = &pbi->common; |
987 MACROBLOCKD *const xd = &pbi->mb; | 991 MACROBLOCKD *const xd = &pbi->mb; |
988 const unsigned char *data = pbi->fragments.ptrs[0]; | 992 const unsigned char *data = pbi->fragments.ptrs[0]; |
989 const unsigned char *const origin = data; | |
990 const unsigned char *data_end = data + pbi->fragments.sizes[0]; | 993 const unsigned char *data_end = data + pbi->fragments.sizes[0]; |
991 ptrdiff_t first_partition_length_in_bytes; | 994 ptrdiff_t first_partition_length_in_bytes; |
992 | 995 |
993 int i, j, k, l; | 996 int i, j, k, l; |
994 const int *const mb_feature_data_bits = vp8_mb_feature_data_bits; | 997 const int *const mb_feature_data_bits = vp8_mb_feature_data_bits; |
995 int corrupt_tokens = 0; | 998 int corrupt_tokens = 0; |
996 int prev_independent_partitions = pbi->independent_partitions; | 999 int prev_independent_partitions = pbi->independent_partitions; |
997 | 1000 |
998 YV12_BUFFER_CONFIG *yv12_fb_new = pbi->dec_fb_ref[INTRA_FRAME]; | 1001 YV12_BUFFER_CONFIG *yv12_fb_new = pbi->dec_fb_ref[INTRA_FRAME]; |
999 | 1002 |
(...skipping 12 matching lines...) Expand all Loading... |
1012 /* Declare the missing frame as an inter frame since it will | 1015 /* Declare the missing frame as an inter frame since it will |
1013 be handled as an inter frame when we have estimated its | 1016 be handled as an inter frame when we have estimated its |
1014 motion vectors. */ | 1017 motion vectors. */ |
1015 pc->frame_type = INTER_FRAME; | 1018 pc->frame_type = INTER_FRAME; |
1016 pc->version = 0; | 1019 pc->version = 0; |
1017 pc->show_frame = 1; | 1020 pc->show_frame = 1; |
1018 first_partition_length_in_bytes = 0; | 1021 first_partition_length_in_bytes = 0; |
1019 } | 1022 } |
1020 else | 1023 else |
1021 { | 1024 { |
1022 const unsigned char data0 = decrypt_byte(data + 0, origin, | 1025 unsigned char clear_buffer[10]; |
1023 pbi->decrypt_key); | 1026 const unsigned char *clear = data; |
1024 const unsigned char data1 = decrypt_byte(data + 1, origin, | 1027 if (pbi->decrypt_cb) |
1025 pbi->decrypt_key); | 1028 { |
1026 const unsigned char data2 = decrypt_byte(data + 2, origin, | 1029 int n = data_end - data; |
1027 pbi->decrypt_key); | 1030 if (n > 10) n = 10; |
| 1031 pbi->decrypt_cb(pbi->decrypt_state, data, clear_buffer, n); |
| 1032 clear = clear_buffer; |
| 1033 } |
1028 | 1034 |
1029 pc->frame_type = (FRAME_TYPE)(data0 & 1); | 1035 pc->frame_type = (FRAME_TYPE)(clear[0] & 1); |
1030 pc->version = (data0 >> 1) & 7; | 1036 pc->version = (clear[0] >> 1) & 7; |
1031 pc->show_frame = (data0 >> 4) & 1; | 1037 pc->show_frame = (clear[0] >> 4) & 1; |
1032 first_partition_length_in_bytes = | 1038 first_partition_length_in_bytes = |
1033 (data0 | (data1 << 8) | (data2 << 16)) >> 5; | 1039 (clear[0] | (clear[1] << 8) | (clear[2] << 16)) >> 5; |
1034 | 1040 |
1035 if (!pbi->ec_active && | 1041 if (!pbi->ec_active && |
1036 (data + first_partition_length_in_bytes > data_end | 1042 (data + first_partition_length_in_bytes > data_end |
1037 || data + first_partition_length_in_bytes < data)) | 1043 || data + first_partition_length_in_bytes < data)) |
1038 vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, | 1044 vpx_internal_error(&pc->error, VPX_CODEC_CORRUPT_FRAME, |
1039 "Truncated packet or corrupt partition 0 length")
; | 1045 "Truncated packet or corrupt partition 0 length")
; |
1040 | 1046 |
1041 data += 3; | 1047 data += 3; |
| 1048 clear += 3; |
1042 | 1049 |
1043 vp8_setup_version(pc); | 1050 vp8_setup_version(pc); |
1044 | 1051 |
1045 | 1052 |
1046 if (pc->frame_type == KEY_FRAME) | 1053 if (pc->frame_type == KEY_FRAME) |
1047 { | 1054 { |
1048 /* vet via sync code */ | 1055 /* vet via sync code */ |
1049 /* When error concealment is enabled we should only check the sync | 1056 /* When error concealment is enabled we should only check the sync |
1050 * code if we have enough bits available | 1057 * code if we have enough bits available |
1051 */ | 1058 */ |
1052 if (!pbi->ec_active || data + 3 < data_end) | 1059 if (!pbi->ec_active || data + 3 < data_end) |
1053 { | 1060 { |
1054 const unsigned char data0 = decrypt_byte(data + 0, origin, | 1061 if (clear[0] != 0x9d || clear[1] != 0x01 || clear[2] != 0x2a) |
1055 pbi->decrypt_key); | |
1056 const unsigned char data1 = decrypt_byte(data + 1, origin, | |
1057 pbi->decrypt_key); | |
1058 const unsigned char data2 = decrypt_byte(data + 2, origin, | |
1059 pbi->decrypt_key); | |
1060 if (data0 != 0x9d || data1 != 0x01 || data2 != 0x2a) | |
1061 vpx_internal_error(&pc->error, VPX_CODEC_UNSUP_BITSTREAM, | 1062 vpx_internal_error(&pc->error, VPX_CODEC_UNSUP_BITSTREAM, |
1062 "Invalid frame sync code"); | 1063 "Invalid frame sync code"); |
1063 } | 1064 } |
1064 | 1065 |
1065 /* If error concealment is enabled we should only parse the new size | 1066 /* If error concealment is enabled we should only parse the new size |
1066 * if we have enough data. Otherwise we will end up with the wrong | 1067 * if we have enough data. Otherwise we will end up with the wrong |
1067 * size. | 1068 * size. |
1068 */ | 1069 */ |
1069 if (!pbi->ec_active || data + 6 < data_end) | 1070 if (!pbi->ec_active || data + 6 < data_end) |
1070 { | 1071 { |
1071 const unsigned char data3 = decrypt_byte(data + 3, origin, | 1072 pc->Width = (clear[3] | (clear[4] << 8)) & 0x3fff; |
1072 pbi->decrypt_key); | 1073 pc->horiz_scale = clear[4] >> 6; |
1073 const unsigned char data4 = decrypt_byte(data + 4, origin, | 1074 pc->Height = (clear[5] | (clear[6] << 8)) & 0x3fff; |
1074 pbi->decrypt_key); | 1075 pc->vert_scale = clear[6] >> 6; |
1075 const unsigned char data5 = decrypt_byte(data + 5, origin, | |
1076 pbi->decrypt_key); | |
1077 const unsigned char data6 = decrypt_byte(data + 6, origin, | |
1078 pbi->decrypt_key); | |
1079 | |
1080 pc->Width = (data3 | (data4 << 8)) & 0x3fff; | |
1081 pc->horiz_scale = data4 >> 6; | |
1082 pc->Height = (data5 | (data6 << 8)) & 0x3fff; | |
1083 pc->vert_scale = data6 >> 6; | |
1084 } | 1076 } |
1085 data += 7; | 1077 data += 7; |
1086 | 1078 clear += 7; |
1087 } | 1079 } |
1088 else | 1080 else |
1089 { | 1081 { |
1090 vpx_memcpy(&xd->pre, yv12_fb_new, sizeof(YV12_BUFFER_CONFIG)); | 1082 vpx_memcpy(&xd->pre, yv12_fb_new, sizeof(YV12_BUFFER_CONFIG)); |
1091 vpx_memcpy(&xd->dst, yv12_fb_new, sizeof(YV12_BUFFER_CONFIG)); | 1083 vpx_memcpy(&xd->dst, yv12_fb_new, sizeof(YV12_BUFFER_CONFIG)); |
1092 } | 1084 } |
1093 } | 1085 } |
1094 if ((!pbi->decoded_key_frame && pc->frame_type != KEY_FRAME)) | 1086 if ((!pbi->decoded_key_frame && pc->frame_type != KEY_FRAME)) |
1095 { | 1087 { |
1096 return -1; | 1088 return -1; |
1097 } | 1089 } |
1098 | 1090 |
1099 init_frame(pbi); | 1091 init_frame(pbi); |
1100 | 1092 |
1101 if (vp8dx_start_decode(bc, | 1093 if (vp8dx_start_decode(bc, data, (unsigned int)(data_end - data), |
1102 data, | 1094 pbi->decrypt_cb, pbi->decrypt_state)) |
1103 (unsigned int)(data_end - data), | |
1104 pbi->fragments.ptrs[0], | |
1105 pbi->decrypt_key)) | |
1106 vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR, | 1095 vpx_internal_error(&pc->error, VPX_CODEC_MEM_ERROR, |
1107 "Failed to allocate bool decoder 0"); | 1096 "Failed to allocate bool decoder 0"); |
1108 if (pc->frame_type == KEY_FRAME) { | 1097 if (pc->frame_type == KEY_FRAME) { |
1109 pc->clr_type = (YUV_TYPE)vp8_read_bit(bc); | 1098 pc->clr_type = (YUV_TYPE)vp8_read_bit(bc); |
1110 pc->clamp_type = (CLAMP_TYPE)vp8_read_bit(bc); | 1099 pc->clamp_type = (CLAMP_TYPE)vp8_read_bit(bc); |
1111 } | 1100 } |
1112 | 1101 |
1113 /* Is segmentation enabled */ | 1102 /* Is segmentation enabled */ |
1114 xd->segmentation_enabled = (unsigned char)vp8_read_bit(bc); | 1103 xd->segmentation_enabled = (unsigned char)vp8_read_bit(bc); |
1115 | 1104 |
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1407 FILE *f = fopen("decompressor.VP8", "ab"); | 1396 FILE *f = fopen("decompressor.VP8", "ab"); |
1408 unsigned int size = pbi->bc2.pos + pbi->bc.pos + 8; | 1397 unsigned int size = pbi->bc2.pos + pbi->bc.pos + 8; |
1409 fwrite((void *) &size, 4, 1, f); | 1398 fwrite((void *) &size, 4, 1, f); |
1410 fwrite((void *) pbi->Source, size, 1, f); | 1399 fwrite((void *) pbi->Source, size, 1, f); |
1411 fclose(f); | 1400 fclose(f); |
1412 } | 1401 } |
1413 #endif | 1402 #endif |
1414 | 1403 |
1415 return 0; | 1404 return 0; |
1416 } | 1405 } |
OLD | NEW |