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/formats/mp2t/es_parser_h264.h" | 5 #include "media/formats/mp2t/es_parser_h264.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/numerics/safe_conversions.h" | 10 #include "base/numerics/safe_conversions.h" |
| 11 #include "base/optional.h" |
11 #include "media/base/encryption_scheme.h" | 12 #include "media/base/encryption_scheme.h" |
12 #include "media/base/media_util.h" | 13 #include "media/base/media_util.h" |
13 #include "media/base/stream_parser_buffer.h" | 14 #include "media/base/stream_parser_buffer.h" |
14 #include "media/base/timestamp_constants.h" | 15 #include "media/base/timestamp_constants.h" |
15 #include "media/base/video_frame.h" | 16 #include "media/base/video_frame.h" |
16 #include "media/filters/h264_parser.h" | 17 #include "media/filters/h264_parser.h" |
17 #include "media/formats/common/offset_byte_queue.h" | 18 #include "media/formats/common/offset_byte_queue.h" |
18 #include "media/formats/mp2t/mp2t_common.h" | 19 #include "media/formats/mp2t/mp2t_common.h" |
19 #include "ui/gfx/geometry/rect.h" | 20 #include "ui/gfx/geometry/rect.h" |
20 #include "ui/gfx/geometry/size.h" | 21 #include "ui/gfx/geometry/size.h" |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 stream_parser_buffer->set_timestamp(current_timing_desc.pts); | 255 stream_parser_buffer->set_timestamp(current_timing_desc.pts); |
255 return es_adapter_.OnNewBuffer(stream_parser_buffer); | 256 return es_adapter_.OnNewBuffer(stream_parser_buffer); |
256 } | 257 } |
257 | 258 |
258 bool EsParserH264::UpdateVideoDecoderConfig(const H264SPS* sps, | 259 bool EsParserH264::UpdateVideoDecoderConfig(const H264SPS* sps, |
259 const EncryptionScheme& scheme) { | 260 const EncryptionScheme& scheme) { |
260 // Set the SAR to 1 when not specified in the H264 stream. | 261 // Set the SAR to 1 when not specified in the H264 stream. |
261 int sar_width = (sps->sar_width == 0) ? 1 : sps->sar_width; | 262 int sar_width = (sps->sar_width == 0) ? 1 : sps->sar_width; |
262 int sar_height = (sps->sar_height == 0) ? 1 : sps->sar_height; | 263 int sar_height = (sps->sar_height == 0) ? 1 : sps->sar_height; |
263 | 264 |
264 // TODO(damienv): a MAP unit can be either 16 or 32 pixels. | 265 base::Optional<gfx::Size> coded_size = sps->GetCodedSize(); |
265 // although it's 16 pixels for progressive non MBAFF frames. | 266 if (!coded_size) |
266 int width_mb = sps->pic_width_in_mbs_minus1 + 1; | 267 return false; |
267 int height_mb = sps->pic_height_in_map_units_minus1 + 1; | 268 |
268 if (width_mb > std::numeric_limits<int>::max() / 16 || | 269 base::Optional<gfx::Rect> visible_rect = sps->GetVisibleRect(); |
269 height_mb > std::numeric_limits<int>::max() / 16) { | 270 if (!visible_rect) |
270 DVLOG(1) << "Picture size is too big: width_mb=" << width_mb | 271 return false; |
271 << " height_mb=" << height_mb; | 272 |
| 273 if (visible_rect->width() > std::numeric_limits<int>::max() / sar_width) { |
| 274 DVLOG(1) << "Integer overflow detected: visible_rect.width()=" |
| 275 << visible_rect->width() << " sar_width=" << sar_width; |
272 return false; | 276 return false; |
273 } | 277 } |
274 | 278 gfx::Size natural_size((visible_rect->width() * sar_width) / sar_height, |
275 gfx::Size coded_size(16 * width_mb, 16 * height_mb); | 279 visible_rect->height()); |
276 gfx::Rect visible_rect( | |
277 sps->frame_crop_left_offset, | |
278 sps->frame_crop_top_offset, | |
279 (coded_size.width() - sps->frame_crop_right_offset) - | |
280 sps->frame_crop_left_offset, | |
281 (coded_size.height() - sps->frame_crop_bottom_offset) - | |
282 sps->frame_crop_top_offset); | |
283 if (visible_rect.width() <= 0 || visible_rect.height() <= 0) | |
284 return false; | |
285 if (visible_rect.width() > std::numeric_limits<int>::max() / sar_width) { | |
286 DVLOG(1) << "Integer overflow detected: visible_rect.width()=" | |
287 << visible_rect.width() << " sar_width=" << sar_width; | |
288 return false; | |
289 } | |
290 gfx::Size natural_size( | |
291 (visible_rect.width() * sar_width) / sar_height, | |
292 visible_rect.height()); | |
293 if (natural_size.width() == 0) | 280 if (natural_size.width() == 0) |
294 return false; | 281 return false; |
295 | 282 |
296 VideoDecoderConfig video_decoder_config( | 283 VideoDecoderConfig video_decoder_config( |
297 kCodecH264, H264Parser::ProfileIDCToVideoCodecProfile(sps->profile_idc), | 284 kCodecH264, H264Parser::ProfileIDCToVideoCodecProfile(sps->profile_idc), |
298 PIXEL_FORMAT_YV12, COLOR_SPACE_HD_REC709, coded_size, visible_rect, | 285 PIXEL_FORMAT_YV12, COLOR_SPACE_HD_REC709, coded_size.value(), |
299 natural_size, EmptyExtraData(), scheme); | 286 visible_rect.value(), natural_size, EmptyExtraData(), scheme); |
300 | 287 |
301 if (!video_decoder_config.Matches(last_video_decoder_config_)) { | 288 if (!video_decoder_config.Matches(last_video_decoder_config_)) { |
302 DVLOG(1) << "Profile IDC: " << sps->profile_idc; | 289 DVLOG(1) << "Profile IDC: " << sps->profile_idc; |
303 DVLOG(1) << "Level IDC: " << sps->level_idc; | 290 DVLOG(1) << "Level IDC: " << sps->level_idc; |
304 DVLOG(1) << "Pic width: " << coded_size.width(); | 291 DVLOG(1) << "Pic width: " << coded_size->width(); |
305 DVLOG(1) << "Pic height: " << coded_size.height(); | 292 DVLOG(1) << "Pic height: " << coded_size->height(); |
306 DVLOG(1) << "log2_max_frame_num_minus4: " | 293 DVLOG(1) << "log2_max_frame_num_minus4: " |
307 << sps->log2_max_frame_num_minus4; | 294 << sps->log2_max_frame_num_minus4; |
308 DVLOG(1) << "SAR: width=" << sps->sar_width | 295 DVLOG(1) << "SAR: width=" << sps->sar_width |
309 << " height=" << sps->sar_height; | 296 << " height=" << sps->sar_height; |
310 last_video_decoder_config_ = video_decoder_config; | 297 last_video_decoder_config_ = video_decoder_config; |
311 es_adapter_.OnConfigChanged(video_decoder_config); | 298 es_adapter_.OnConfigChanged(video_decoder_config); |
312 } | 299 } |
313 | 300 |
314 return true; | 301 return true; |
315 } | 302 } |
316 | 303 |
317 } // namespace mp2t | 304 } // namespace mp2t |
318 } // namespace media | 305 } // namespace media |
OLD | NEW |