| 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 "media/base/encryption_scheme.h" | 11 #include "media/base/encryption_scheme.h" |
| 12 #include "media/base/media_util.h" | 12 #include "media/base/media_util.h" |
| 13 #include "media/base/stream_parser_buffer.h" | 13 #include "media/base/stream_parser_buffer.h" |
| 14 #include "media/base/timestamp_constants.h" | 14 #include "media/base/timestamp_constants.h" |
| 15 #include "media/base/video_frame.h" | 15 #include "media/base/video_frame.h" |
| 16 #include "media/filters/h264_parser.h" | 16 #include "media/filters/h264_parser.h" |
| 17 #include "media/formats/common/offset_byte_queue.h" | 17 #include "media/formats/common/offset_byte_queue.h" |
| 18 #include "media/formats/mp2t/mp2t_common.h" | 18 #include "media/formats/mp2t/mp2t_common.h" |
| 19 #include "ui/gfx/geometry/rect.h" | 19 #include "ui/gfx/geometry/rect.h" |
| 20 #include "ui/gfx/geometry/size.h" | 20 #include "ui/gfx/geometry/size.h" |
| 21 | 21 |
| 22 namespace media { | 22 namespace media { |
| 23 namespace mp2t { | 23 namespace mp2t { |
| 24 | 24 |
| 25 namespace { | |
| 26 | |
| 27 VideoCodecProfile ProfileIDCToVideoCodecProfile(int profile_idc) { | |
| 28 switch (profile_idc) { | |
| 29 case H264SPS::kProfileIDCBaseline: | |
| 30 return H264PROFILE_BASELINE; | |
| 31 case H264SPS::kProfileIDCMain: | |
| 32 return H264PROFILE_MAIN; | |
| 33 case H264SPS::kProfileIDCHigh: | |
| 34 return H264PROFILE_HIGH; | |
| 35 case H264SPS::kProfileIDHigh10: | |
| 36 return H264PROFILE_HIGH10PROFILE; | |
| 37 case H264SPS::kProfileIDHigh422: | |
| 38 return H264PROFILE_HIGH422PROFILE; | |
| 39 case H264SPS::kProfileIDHigh444Predictive: | |
| 40 return H264PROFILE_HIGH444PREDICTIVEPROFILE; | |
| 41 case H264SPS::kProfileIDScalableBaseline: | |
| 42 return H264PROFILE_SCALABLEBASELINE; | |
| 43 case H264SPS::kProfileIDScalableHigh: | |
| 44 return H264PROFILE_SCALABLEHIGH; | |
| 45 case H264SPS::kProfileIDStereoHigh: | |
| 46 return H264PROFILE_STEREOHIGH; | |
| 47 case H264SPS::kProfileIDSMultiviewHigh: | |
| 48 return H264PROFILE_MULTIVIEWHIGH; | |
| 49 } | |
| 50 NOTREACHED() << "unknown video profile: " << profile_idc; | |
| 51 return VIDEO_CODEC_PROFILE_UNKNOWN; | |
| 52 } | |
| 53 | |
| 54 } // namespace | |
| 55 | |
| 56 // An AUD NALU is at least 4 bytes: | 25 // An AUD NALU is at least 4 bytes: |
| 57 // 3 bytes for the start code + 1 byte for the NALU type. | 26 // 3 bytes for the start code + 1 byte for the NALU type. |
| 58 const int kMinAUDSize = 4; | 27 const int kMinAUDSize = 4; |
| 59 | 28 |
| 60 EsParserH264::EsParserH264( | 29 EsParserH264::EsParserH264( |
| 61 const NewVideoConfigCB& new_video_config_cb, | 30 const NewVideoConfigCB& new_video_config_cb, |
| 62 const EmitBufferCB& emit_buffer_cb) | 31 const EmitBufferCB& emit_buffer_cb) |
| 63 : es_adapter_(new_video_config_cb, emit_buffer_cb), | 32 : es_adapter_(new_video_config_cb, emit_buffer_cb), |
| 64 h264_parser_(new H264Parser()), | 33 h264_parser_(new H264Parser()), |
| 65 current_access_unit_pos_(0), | 34 current_access_unit_pos_(0), |
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 << visible_rect.width() << " sar_width=" << sar_width; | 287 << visible_rect.width() << " sar_width=" << sar_width; |
| 319 return false; | 288 return false; |
| 320 } | 289 } |
| 321 gfx::Size natural_size( | 290 gfx::Size natural_size( |
| 322 (visible_rect.width() * sar_width) / sar_height, | 291 (visible_rect.width() * sar_width) / sar_height, |
| 323 visible_rect.height()); | 292 visible_rect.height()); |
| 324 if (natural_size.width() == 0) | 293 if (natural_size.width() == 0) |
| 325 return false; | 294 return false; |
| 326 | 295 |
| 327 VideoDecoderConfig video_decoder_config( | 296 VideoDecoderConfig video_decoder_config( |
| 328 kCodecH264, ProfileIDCToVideoCodecProfile(sps->profile_idc), | 297 kCodecH264, H264Parser::ProfileIDCToVideoCodecProfile(sps->profile_idc), |
| 329 PIXEL_FORMAT_YV12, COLOR_SPACE_HD_REC709, coded_size, visible_rect, | 298 PIXEL_FORMAT_YV12, COLOR_SPACE_HD_REC709, coded_size, visible_rect, |
| 330 natural_size, EmptyExtraData(), scheme); | 299 natural_size, EmptyExtraData(), scheme); |
| 331 | 300 |
| 332 if (!video_decoder_config.Matches(last_video_decoder_config_)) { | 301 if (!video_decoder_config.Matches(last_video_decoder_config_)) { |
| 333 DVLOG(1) << "Profile IDC: " << sps->profile_idc; | 302 DVLOG(1) << "Profile IDC: " << sps->profile_idc; |
| 334 DVLOG(1) << "Level IDC: " << sps->level_idc; | 303 DVLOG(1) << "Level IDC: " << sps->level_idc; |
| 335 DVLOG(1) << "Pic width: " << coded_size.width(); | 304 DVLOG(1) << "Pic width: " << coded_size.width(); |
| 336 DVLOG(1) << "Pic height: " << coded_size.height(); | 305 DVLOG(1) << "Pic height: " << coded_size.height(); |
| 337 DVLOG(1) << "log2_max_frame_num_minus4: " | 306 DVLOG(1) << "log2_max_frame_num_minus4: " |
| 338 << sps->log2_max_frame_num_minus4; | 307 << sps->log2_max_frame_num_minus4; |
| 339 DVLOG(1) << "SAR: width=" << sps->sar_width | 308 DVLOG(1) << "SAR: width=" << sps->sar_width |
| 340 << " height=" << sps->sar_height; | 309 << " height=" << sps->sar_height; |
| 341 last_video_decoder_config_ = video_decoder_config; | 310 last_video_decoder_config_ = video_decoder_config; |
| 342 es_adapter_.OnConfigChanged(video_decoder_config); | 311 es_adapter_.OnConfigChanged(video_decoder_config); |
| 343 } | 312 } |
| 344 | 313 |
| 345 return true; | 314 return true; |
| 346 } | 315 } |
| 347 | 316 |
| 348 } // namespace mp2t | 317 } // namespace mp2t |
| 349 } // namespace media | 318 } // namespace media |
| OLD | NEW |