OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/filters/h264_parser.h" | 5 #include "media/filters/h264_parser.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "base/numerics/safe_math.h" |
12 #include "base/stl_util.h" | 13 #include "base/stl_util.h" |
13 #include "media/base/decrypt_config.h" | 14 #include "media/base/decrypt_config.h" |
14 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
15 #include "ui/gfx/geometry/size.h" | 16 #include "ui/gfx/geometry/size.h" |
16 | 17 |
17 namespace media { | 18 namespace media { |
18 | 19 |
19 bool H264SliceHeader::IsPSlice() const { | 20 bool H264SliceHeader::IsPSlice() const { |
20 return (slice_type % 5 == kPSlice); | 21 return (slice_type % 5 == kPSlice); |
21 } | 22 } |
(...skipping 918 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 sps->chroma_array_type = 0; | 941 sps->chroma_array_type = 0; |
941 else | 942 else |
942 sps->chroma_array_type = sps->chroma_format_idc; | 943 sps->chroma_array_type = sps->chroma_format_idc; |
943 | 944 |
944 READ_UE_OR_RETURN(&sps->log2_max_frame_num_minus4); | 945 READ_UE_OR_RETURN(&sps->log2_max_frame_num_minus4); |
945 TRUE_OR_RETURN(sps->log2_max_frame_num_minus4 < 13); | 946 TRUE_OR_RETURN(sps->log2_max_frame_num_minus4 < 13); |
946 | 947 |
947 READ_UE_OR_RETURN(&sps->pic_order_cnt_type); | 948 READ_UE_OR_RETURN(&sps->pic_order_cnt_type); |
948 TRUE_OR_RETURN(sps->pic_order_cnt_type < 3); | 949 TRUE_OR_RETURN(sps->pic_order_cnt_type < 3); |
949 | 950 |
950 sps->expected_delta_per_pic_order_cnt_cycle = 0; | |
951 if (sps->pic_order_cnt_type == 0) { | 951 if (sps->pic_order_cnt_type == 0) { |
952 READ_UE_OR_RETURN(&sps->log2_max_pic_order_cnt_lsb_minus4); | 952 READ_UE_OR_RETURN(&sps->log2_max_pic_order_cnt_lsb_minus4); |
953 TRUE_OR_RETURN(sps->log2_max_pic_order_cnt_lsb_minus4 < 13); | 953 TRUE_OR_RETURN(sps->log2_max_pic_order_cnt_lsb_minus4 < 13); |
| 954 sps->expected_delta_per_pic_order_cnt_cycle = 0; |
954 } else if (sps->pic_order_cnt_type == 1) { | 955 } else if (sps->pic_order_cnt_type == 1) { |
955 READ_BOOL_OR_RETURN(&sps->delta_pic_order_always_zero_flag); | 956 READ_BOOL_OR_RETURN(&sps->delta_pic_order_always_zero_flag); |
956 READ_SE_OR_RETURN(&sps->offset_for_non_ref_pic); | 957 READ_SE_OR_RETURN(&sps->offset_for_non_ref_pic); |
957 READ_SE_OR_RETURN(&sps->offset_for_top_to_bottom_field); | 958 READ_SE_OR_RETURN(&sps->offset_for_top_to_bottom_field); |
958 READ_UE_OR_RETURN(&sps->num_ref_frames_in_pic_order_cnt_cycle); | 959 READ_UE_OR_RETURN(&sps->num_ref_frames_in_pic_order_cnt_cycle); |
959 TRUE_OR_RETURN(sps->num_ref_frames_in_pic_order_cnt_cycle < 255); | 960 TRUE_OR_RETURN(sps->num_ref_frames_in_pic_order_cnt_cycle < 255); |
960 | 961 |
| 962 base::CheckedNumeric<int> offset_acc = 0; |
961 for (int i = 0; i < sps->num_ref_frames_in_pic_order_cnt_cycle; ++i) { | 963 for (int i = 0; i < sps->num_ref_frames_in_pic_order_cnt_cycle; ++i) { |
962 READ_SE_OR_RETURN(&sps->offset_for_ref_frame[i]); | 964 READ_SE_OR_RETURN(&sps->offset_for_ref_frame[i]); |
963 sps->expected_delta_per_pic_order_cnt_cycle += | 965 offset_acc += sps->offset_for_ref_frame[i]; |
964 sps->offset_for_ref_frame[i]; | |
965 } | 966 } |
| 967 if (!offset_acc.IsValid()) |
| 968 return kInvalidStream; |
| 969 sps->expected_delta_per_pic_order_cnt_cycle = offset_acc.ValueOrDefault(0); |
966 } | 970 } |
967 | 971 |
968 READ_UE_OR_RETURN(&sps->max_num_ref_frames); | 972 READ_UE_OR_RETURN(&sps->max_num_ref_frames); |
969 READ_BOOL_OR_RETURN(&sps->gaps_in_frame_num_value_allowed_flag); | 973 READ_BOOL_OR_RETURN(&sps->gaps_in_frame_num_value_allowed_flag); |
970 | 974 |
971 READ_UE_OR_RETURN(&sps->pic_width_in_mbs_minus1); | 975 READ_UE_OR_RETURN(&sps->pic_width_in_mbs_minus1); |
972 READ_UE_OR_RETURN(&sps->pic_height_in_map_units_minus1); | 976 READ_UE_OR_RETURN(&sps->pic_height_in_map_units_minus1); |
973 | 977 |
974 READ_BOOL_OR_RETURN(&sps->frame_mbs_only_flag); | 978 READ_BOOL_OR_RETURN(&sps->frame_mbs_only_flag); |
975 if (!sps->frame_mbs_only_flag) | 979 if (!sps->frame_mbs_only_flag) |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1454 | 1458 |
1455 default: | 1459 default: |
1456 DVLOG(4) << "Unsupported SEI message"; | 1460 DVLOG(4) << "Unsupported SEI message"; |
1457 break; | 1461 break; |
1458 } | 1462 } |
1459 | 1463 |
1460 return kOk; | 1464 return kOk; |
1461 } | 1465 } |
1462 | 1466 |
1463 } // namespace media | 1467 } // namespace media |
OLD | NEW |