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" |
(...skipping 21 matching lines...) Expand all Loading... |
32 h264_parser_(new H264Parser()), | 32 h264_parser_(new H264Parser()), |
33 current_access_unit_pos_(0), | 33 current_access_unit_pos_(0), |
34 next_access_unit_pos_(0) { | 34 next_access_unit_pos_(0) { |
35 } | 35 } |
36 | 36 |
37 EsParserH264::~EsParserH264() { | 37 EsParserH264::~EsParserH264() { |
38 } | 38 } |
39 | 39 |
40 bool EsParserH264::Parse(const uint8* buf, int size, | 40 bool EsParserH264::Parse(const uint8* buf, int size, |
41 base::TimeDelta pts, | 41 base::TimeDelta pts, |
42 base::TimeDelta dts) { | 42 DecodeTimestamp dts) { |
43 // Note: Parse is invoked each time a PES packet has been reassembled. | 43 // Note: Parse is invoked each time a PES packet has been reassembled. |
44 // Unfortunately, a PES packet does not necessarily map | 44 // Unfortunately, a PES packet does not necessarily map |
45 // to an h264 access unit, although the HLS recommendation is to use one PES | 45 // to an h264 access unit, although the HLS recommendation is to use one PES |
46 // for each access unit (but this is just a recommendation and some streams | 46 // for each access unit (but this is just a recommendation and some streams |
47 // do not comply with this recommendation). | 47 // do not comply with this recommendation). |
48 | 48 |
49 // HLS recommendation: "In AVC video, you should have both a DTS and a | 49 // HLS recommendation: "In AVC video, you should have both a DTS and a |
50 // PTS in each PES header". | 50 // PTS in each PES header". |
51 // However, some streams do not comply with this recommendation. | 51 // However, some streams do not comply with this recommendation. |
52 DVLOG_IF(1, pts == kNoTimestamp()) << "Each video PES should have a PTS"; | 52 DVLOG_IF(1, pts == kNoTimestamp()) << "Each video PES should have a PTS"; |
53 if (pts != kNoTimestamp()) { | 53 if (pts != kNoTimestamp()) { |
54 TimingDesc timing_desc; | 54 TimingDesc timing_desc; |
55 timing_desc.pts = pts; | 55 timing_desc.pts = pts; |
56 timing_desc.dts = (dts != kNoTimestamp()) ? dts : pts; | 56 timing_desc.dts = (dts != kNoDecodeTimestamp()) ? dts : |
| 57 DecodeTimestamp::FromPresentationTime(pts); |
57 | 58 |
58 // Link the end of the byte queue with the incoming timing descriptor. | 59 // Link the end of the byte queue with the incoming timing descriptor. |
59 timing_desc_list_.push_back( | 60 timing_desc_list_.push_back( |
60 std::pair<int64, TimingDesc>(es_queue_->tail(), timing_desc)); | 61 std::pair<int64, TimingDesc>(es_queue_->tail(), timing_desc)); |
61 } | 62 } |
62 | 63 |
63 // Add the incoming bytes to the ES queue. | 64 // Add the incoming bytes to the ES queue. |
64 es_queue_->Push(buf, size); | 65 es_queue_->Push(buf, size); |
65 return ParseInternal(); | 66 return ParseInternal(); |
66 } | 67 } |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 is_key_frame, pps_id_for_access_unit)); | 225 is_key_frame, pps_id_for_access_unit)); |
225 current_access_unit_pos_ = next_access_unit_pos_; | 226 current_access_unit_pos_ = next_access_unit_pos_; |
226 es_queue_->Trim(current_access_unit_pos_); | 227 es_queue_->Trim(current_access_unit_pos_); |
227 | 228 |
228 return true; | 229 return true; |
229 } | 230 } |
230 | 231 |
231 bool EsParserH264::EmitFrame(int64 access_unit_pos, int access_unit_size, | 232 bool EsParserH264::EmitFrame(int64 access_unit_pos, int access_unit_size, |
232 bool is_key_frame, int pps_id) { | 233 bool is_key_frame, int pps_id) { |
233 // Get the access unit timing info. | 234 // Get the access unit timing info. |
234 TimingDesc current_timing_desc = {kNoTimestamp(), kNoTimestamp()}; | 235 TimingDesc current_timing_desc = {kNoDecodeTimestamp(), kNoTimestamp()}; |
235 while (!timing_desc_list_.empty() && | 236 while (!timing_desc_list_.empty() && |
236 timing_desc_list_.front().first <= access_unit_pos) { | 237 timing_desc_list_.front().first <= access_unit_pos) { |
237 current_timing_desc = timing_desc_list_.front().second; | 238 current_timing_desc = timing_desc_list_.front().second; |
238 timing_desc_list_.pop_front(); | 239 timing_desc_list_.pop_front(); |
239 } | 240 } |
240 if (current_timing_desc.pts == kNoTimestamp()) | 241 if (current_timing_desc.pts == kNoTimestamp()) |
241 return false; | 242 return false; |
242 | 243 |
243 // Update the video decoder configuration if needed. | 244 // Update the video decoder configuration if needed. |
244 const H264PPS* pps = h264_parser_->GetPPS(pps_id); | 245 const H264PPS* pps = h264_parser_->GetPPS(pps_id); |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
325 << " height=" << sps->sar_height; | 326 << " height=" << sps->sar_height; |
326 last_video_decoder_config_ = video_decoder_config; | 327 last_video_decoder_config_ = video_decoder_config; |
327 es_adapter_.OnConfigChanged(video_decoder_config); | 328 es_adapter_.OnConfigChanged(video_decoder_config); |
328 } | 329 } |
329 | 330 |
330 return true; | 331 return true; |
331 } | 332 } |
332 | 333 |
333 } // namespace mp2t | 334 } // namespace mp2t |
334 } // namespace media | 335 } // namespace media |
335 | |
OLD | NEW |