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/stl_util.h" | 12 #include "base/stl_util.h" |
13 #include "media/base/decrypt_config.h" | 13 #include "media/base/decrypt_config.h" |
14 #include "ui/gfx/geometry/rect.h" | |
15 #include "ui/gfx/geometry/size.h" | |
14 | 16 |
15 namespace media { | 17 namespace media { |
16 | 18 |
17 bool H264SliceHeader::IsPSlice() const { | 19 bool H264SliceHeader::IsPSlice() const { |
18 return (slice_type % 5 == kPSlice); | 20 return (slice_type % 5 == kPSlice); |
19 } | 21 } |
20 | 22 |
21 bool H264SliceHeader::IsBSlice() const { | 23 bool H264SliceHeader::IsBSlice() const { |
22 return (slice_type % 5 == kBSlice); | 24 return (slice_type % 5 == kBSlice); |
23 } | 25 } |
(...skipping 11 matching lines...) Expand all Loading... | |
35 } | 37 } |
36 | 38 |
37 H264NALU::H264NALU() { | 39 H264NALU::H264NALU() { |
38 memset(this, 0, sizeof(*this)); | 40 memset(this, 0, sizeof(*this)); |
39 } | 41 } |
40 | 42 |
41 H264SPS::H264SPS() { | 43 H264SPS::H264SPS() { |
42 memset(this, 0, sizeof(*this)); | 44 memset(this, 0, sizeof(*this)); |
43 } | 45 } |
44 | 46 |
47 // Spec section 7.4.2.1.1. | |
servolk
2016/08/26 16:43:05
Nit: I think we could be a bit more explicit about
sandersd (OOO until July 31)
2016/08/27 01:11:01
Done.
| |
48 base::Optional<gfx::Size> H264SPS::GetCodedSize() { | |
49 // Interlaced frames are twice the height of each field. | |
50 const int mb_unit = 16; | |
51 int map_unit = frame_mbs_only_flag ? 16 : 32; | |
52 | |
53 // Verify that the values are not too large before multiplying them. | |
54 // TODO(sandersd): These limits could be much smaller. The currently-largest | |
55 // specified limit (excluding SVC, multiview, etc., which I didn't bother to | |
56 // read) is 543 macroblocks (section A.3.1). | |
57 int max_mb_minus1 = std::numeric_limits<int>::max() / mb_unit - 1; | |
58 int max_map_units_minus1 = std::numeric_limits<int>::max() / map_unit - 1; | |
59 if (pic_width_in_mbs_minus1 > max_mb_minus1 || | |
60 pic_height_in_map_units_minus1 > max_map_units_minus1) { | |
61 DVLOG(1) << "Coded size is too large."; | |
62 return base::Optional<gfx::Size>(); | |
63 } | |
64 | |
65 return gfx::Size(mb_unit * (pic_width_in_mbs_minus1 + 1), | |
66 map_unit * (pic_height_in_map_units_minus1 + 1)); | |
67 } | |
68 | |
69 // Also spec section 7.4.2.1.1. | |
70 base::Optional<gfx::Rect> H264SPS::GetVisibleRect() { | |
71 base::Optional<gfx::Size> coded_size = GetCodedSize(); | |
72 if (!coded_size) | |
73 return base::Optional<gfx::Rect>(); | |
74 | |
75 if (!frame_cropping_flag) | |
76 return gfx::Rect(coded_size.value()); | |
77 | |
78 int crop_unit_x; | |
79 int crop_unit_y; | |
80 if (chroma_array_type == 0) { | |
81 crop_unit_x = 1; | |
82 crop_unit_y = frame_mbs_only_flag ? 1 : 2; | |
83 } else { | |
84 // Section 6.2. | |
85 // |chroma_format_idc| may be: | |
86 // 1 => 4:2:0 | |
87 // 2 => 4:2:2 | |
88 // 3 => 4:4:4 | |
89 // Everything else has |chroma_array_type| == 0. | |
90 int sub_width_c = chroma_format_idc > 2 ? 1 : 2; | |
91 int sub_height_c = chroma_format_idc > 1 ? 1 : 2; | |
92 crop_unit_x = sub_width_c; | |
93 crop_unit_y = sub_height_c * (frame_mbs_only_flag ? 1 : 2); | |
94 } | |
95 | |
96 // Verify that the values are not too large before multiplying. | |
97 if (coded_size->width() / crop_unit_x < frame_crop_left_offset || | |
98 coded_size->width() / crop_unit_x < frame_crop_right_offset || | |
99 coded_size->height() / crop_unit_y < frame_crop_top_offset || | |
100 coded_size->height() / crop_unit_y < frame_crop_bottom_offset) { | |
101 DVLOG(1) << "Frame cropping exceeds coded size."; | |
102 return base::Optional<gfx::Rect>(); | |
103 } | |
104 int crop_left = crop_unit_x * frame_crop_left_offset; | |
105 int crop_right = crop_unit_x * frame_crop_right_offset; | |
106 int crop_top = crop_unit_y * frame_crop_top_offset; | |
107 int crop_bottom = crop_unit_y * frame_crop_bottom_offset; | |
108 | |
109 // Verify that the values are sane. Note that some decoders also require that | |
110 // crops are smaller than a macroblock and/or that crops must be adjacent to | |
111 // at least one corner of the coded frame. | |
112 if (coded_size->width() - crop_left <= crop_right || | |
113 coded_size->height() - crop_top <= crop_bottom) { | |
114 DVLOG(1) << "Frame cropping excludes entire frame."; | |
115 return base::Optional<gfx::Rect>(); | |
116 } | |
117 | |
118 return gfx::Rect(crop_left, crop_top, | |
119 coded_size->width() - crop_left - crop_right, | |
120 coded_size->height() - crop_top - crop_bottom); | |
121 } | |
122 | |
45 H264PPS::H264PPS() { | 123 H264PPS::H264PPS() { |
46 memset(this, 0, sizeof(*this)); | 124 memset(this, 0, sizeof(*this)); |
47 } | 125 } |
48 | 126 |
49 H264SliceHeader::H264SliceHeader() { | 127 H264SliceHeader::H264SliceHeader() { |
50 memset(this, 0, sizeof(*this)); | 128 memset(this, 0, sizeof(*this)); |
51 } | 129 } |
52 | 130 |
53 H264SEIMessage::H264SEIMessage() { | 131 H264SEIMessage::H264SEIMessage() { |
54 memset(this, 0, sizeof(*this)); | 132 memset(this, 0, sizeof(*this)); |
(...skipping 1320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1375 | 1453 |
1376 default: | 1454 default: |
1377 DVLOG(4) << "Unsupported SEI message"; | 1455 DVLOG(4) << "Unsupported SEI message"; |
1378 break; | 1456 break; |
1379 } | 1457 } |
1380 | 1458 |
1381 return kOk; | 1459 return kOk; |
1382 } | 1460 } |
1383 | 1461 |
1384 } // namespace media | 1462 } // namespace media |
OLD | NEW |