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/basictypes.h" | 7 #include "base/basictypes.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/numerics/safe_conversions.h" | 9 #include "base/numerics/safe_conversions.h" |
10 #include "media/base/buffers.h" | 10 #include "media/base/buffers.h" |
11 #include "media/base/stream_parser_buffer.h" | 11 #include "media/base/stream_parser_buffer.h" |
12 #include "media/base/video_frame.h" | 12 #include "media/base/video_frame.h" |
13 #include "media/filters/h264_parser.h" | 13 #include "media/filters/h264_parser.h" |
14 #include "media/formats/common/offset_byte_queue.h" | 14 #include "media/formats/common/offset_byte_queue.h" |
15 #include "media/formats/mp2t/es_adapter_video.h" | |
15 #include "media/formats/mp2t/mp2t_common.h" | 16 #include "media/formats/mp2t/mp2t_common.h" |
16 #include "ui/gfx/rect.h" | 17 #include "ui/gfx/rect.h" |
17 #include "ui/gfx/size.h" | 18 #include "ui/gfx/size.h" |
18 | 19 |
19 namespace media { | 20 namespace media { |
20 namespace mp2t { | 21 namespace mp2t { |
21 | 22 |
22 // An AUD NALU is at least 4 bytes: | 23 // An AUD NALU is at least 4 bytes: |
23 // 3 bytes for the start code + 1 byte for the NALU type. | 24 // 3 bytes for the start code + 1 byte for the NALU type. |
24 const int kMinAUDSize = 4; | 25 const int kMinAUDSize = 4; |
25 | 26 |
26 EsParserH264::EsParserH264( | 27 EsParserH264::EsParserH264( |
27 const NewVideoConfigCB& new_video_config_cb, | 28 const NewVideoConfigCB& new_video_config_cb, |
28 const EmitBufferCB& emit_buffer_cb) | 29 const EmitBufferCB& emit_buffer_cb) |
29 : new_video_config_cb_(new_video_config_cb), | 30 : new_video_config_cb_(new_video_config_cb), |
30 emit_buffer_cb_(emit_buffer_cb), | 31 emit_buffer_cb_(emit_buffer_cb), |
acolwell GONE FROM CHROMIUM
2014/07/09 20:01:11
remove this and new_video_config_cb_ ?
damienv1
2014/07/10 16:00:54
Done.
| |
32 es_adapter_(new EsAdapterVideo( | |
33 new_video_config_cb_, emit_buffer_cb_)), | |
31 es_queue_(new media::OffsetByteQueue()), | 34 es_queue_(new media::OffsetByteQueue()), |
32 h264_parser_(new H264Parser()), | 35 h264_parser_(new H264Parser()), |
33 current_access_unit_pos_(0), | 36 current_access_unit_pos_(0), |
34 next_access_unit_pos_(0) { | 37 next_access_unit_pos_(0) { |
35 } | 38 } |
36 | 39 |
37 EsParserH264::~EsParserH264() { | 40 EsParserH264::~EsParserH264() { |
38 } | 41 } |
39 | 42 |
40 bool EsParserH264::Parse(const uint8* buf, int size, | 43 bool EsParserH264::Parse(const uint8* buf, int size, |
(...skipping 27 matching lines...) Expand all Loading... | |
68 void EsParserH264::Flush() { | 71 void EsParserH264::Flush() { |
69 DVLOG(1) << "EsParserH264::Flush"; | 72 DVLOG(1) << "EsParserH264::Flush"; |
70 if (!FindAUD(¤t_access_unit_pos_)) | 73 if (!FindAUD(¤t_access_unit_pos_)) |
71 return; | 74 return; |
72 | 75 |
73 // Simulate an additional AUD to force emitting the last access unit | 76 // Simulate an additional AUD to force emitting the last access unit |
74 // which is assumed to be complete at this point. | 77 // which is assumed to be complete at this point. |
75 uint8 aud[] = { 0x00, 0x00, 0x01, 0x09 }; | 78 uint8 aud[] = { 0x00, 0x00, 0x01, 0x09 }; |
76 es_queue_->Push(aud, sizeof(aud)); | 79 es_queue_->Push(aud, sizeof(aud)); |
77 ParseInternal(); | 80 ParseInternal(); |
81 | |
82 es_adapter_->Flush(); | |
78 } | 83 } |
79 | 84 |
80 void EsParserH264::Reset() { | 85 void EsParserH264::Reset() { |
81 DVLOG(1) << "EsParserH264::Reset"; | 86 DVLOG(1) << "EsParserH264::Reset"; |
82 es_queue_.reset(new media::OffsetByteQueue()); | 87 es_queue_.reset(new media::OffsetByteQueue()); |
83 h264_parser_.reset(new H264Parser()); | 88 h264_parser_.reset(new H264Parser()); |
84 current_access_unit_pos_ = 0; | 89 current_access_unit_pos_ = 0; |
85 next_access_unit_pos_ = 0; | 90 next_access_unit_pos_ = 0; |
86 timing_desc_list_.clear(); | 91 timing_desc_list_.clear(); |
87 last_video_decoder_config_ = VideoDecoderConfig(); | 92 last_video_decoder_config_ = VideoDecoderConfig(); |
93 es_adapter_.reset( | |
acolwell GONE FROM CHROMIUM
2014/07/09 20:01:11
Add a Reset/Clear method on the adapter so you don
damienv1
2014/07/10 16:00:54
Done.
| |
94 new EsAdapterVideo(new_video_config_cb_, emit_buffer_cb_)); | |
88 } | 95 } |
89 | 96 |
90 bool EsParserH264::FindAUD(int64* stream_pos) { | 97 bool EsParserH264::FindAUD(int64* stream_pos) { |
91 while (true) { | 98 while (true) { |
92 const uint8* es; | 99 const uint8* es; |
93 int size; | 100 int size; |
94 es_queue_->PeekAt(*stream_pos, &es, &size); | 101 es_queue_->PeekAt(*stream_pos, &es, &size); |
95 | 102 |
96 // Find a start code and move the stream to the start code parser position. | 103 // Find a start code and move the stream to the start code parser position. |
97 off_t start_code_offset; | 104 off_t start_code_offset; |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 // type and allow multiple video tracks. See https://crbug.com/341581. | 273 // type and allow multiple video tracks. See https://crbug.com/341581. |
267 scoped_refptr<StreamParserBuffer> stream_parser_buffer = | 274 scoped_refptr<StreamParserBuffer> stream_parser_buffer = |
268 StreamParserBuffer::CopyFrom( | 275 StreamParserBuffer::CopyFrom( |
269 es, | 276 es, |
270 access_unit_size, | 277 access_unit_size, |
271 is_key_frame, | 278 is_key_frame, |
272 DemuxerStream::VIDEO, | 279 DemuxerStream::VIDEO, |
273 0); | 280 0); |
274 stream_parser_buffer->SetDecodeTimestamp(current_timing_desc.dts); | 281 stream_parser_buffer->SetDecodeTimestamp(current_timing_desc.dts); |
275 stream_parser_buffer->set_timestamp(current_timing_desc.pts); | 282 stream_parser_buffer->set_timestamp(current_timing_desc.pts); |
276 emit_buffer_cb_.Run(stream_parser_buffer); | 283 es_adapter_->OnNewBuffer(stream_parser_buffer); |
277 return true; | 284 return true; |
278 } | 285 } |
279 | 286 |
280 bool EsParserH264::UpdateVideoDecoderConfig(const H264SPS* sps) { | 287 bool EsParserH264::UpdateVideoDecoderConfig(const H264SPS* sps) { |
281 // Set the SAR to 1 when not specified in the H264 stream. | 288 // Set the SAR to 1 when not specified in the H264 stream. |
282 int sar_width = (sps->sar_width == 0) ? 1 : sps->sar_width; | 289 int sar_width = (sps->sar_width == 0) ? 1 : sps->sar_width; |
283 int sar_height = (sps->sar_height == 0) ? 1 : sps->sar_height; | 290 int sar_height = (sps->sar_height == 0) ? 1 : sps->sar_height; |
284 | 291 |
285 // TODO(damienv): a MAP unit can be either 16 or 32 pixels. | 292 // TODO(damienv): a MAP unit can be either 16 or 32 pixels. |
286 // although it's 16 pixels for progressive non MBAFF frames. | 293 // although it's 16 pixels for progressive non MBAFF frames. |
(...skipping 27 matching lines...) Expand all Loading... | |
314 if (!video_decoder_config.Matches(last_video_decoder_config_)) { | 321 if (!video_decoder_config.Matches(last_video_decoder_config_)) { |
315 DVLOG(1) << "Profile IDC: " << sps->profile_idc; | 322 DVLOG(1) << "Profile IDC: " << sps->profile_idc; |
316 DVLOG(1) << "Level IDC: " << sps->level_idc; | 323 DVLOG(1) << "Level IDC: " << sps->level_idc; |
317 DVLOG(1) << "Pic width: " << coded_size.width(); | 324 DVLOG(1) << "Pic width: " << coded_size.width(); |
318 DVLOG(1) << "Pic height: " << coded_size.height(); | 325 DVLOG(1) << "Pic height: " << coded_size.height(); |
319 DVLOG(1) << "log2_max_frame_num_minus4: " | 326 DVLOG(1) << "log2_max_frame_num_minus4: " |
320 << sps->log2_max_frame_num_minus4; | 327 << sps->log2_max_frame_num_minus4; |
321 DVLOG(1) << "SAR: width=" << sps->sar_width | 328 DVLOG(1) << "SAR: width=" << sps->sar_width |
322 << " height=" << sps->sar_height; | 329 << " height=" << sps->sar_height; |
323 last_video_decoder_config_ = video_decoder_config; | 330 last_video_decoder_config_ = video_decoder_config; |
324 new_video_config_cb_.Run(video_decoder_config); | 331 es_adapter_->OnConfigChanged(video_decoder_config); |
325 } | 332 } |
326 | 333 |
327 return true; | 334 return true; |
328 } | 335 } |
329 | 336 |
330 } // namespace mp2t | 337 } // namespace mp2t |
331 } // namespace media | 338 } // namespace media |
332 | 339 |
OLD | NEW |