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