Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(297)

Side by Side Diff: media/mp2t/es_parser_h264.cc

Issue 136703005: Return an error on Multiple AUs in a PES. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/mp2t/es_parser_h264.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/mp2t/es_parser_h264.h" 5 #include "media/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 "media/base/bit_reader.h" 9 #include "media/base/bit_reader.h"
10 #include "media/base/buffers.h" 10 #include "media/base/buffers.h"
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 // Retrieve the NAL type. 209 // Retrieve the NAL type.
210 int nal_header = raw_es[current_nal_pos_]; 210 int nal_header = raw_es[current_nal_pos_];
211 int forbidden_zero_bit = (nal_header >> 7) & 0x1; 211 int forbidden_zero_bit = (nal_header >> 7) & 0x1;
212 RCHECK(forbidden_zero_bit == 0); 212 RCHECK(forbidden_zero_bit == 0);
213 NalUnitType nal_unit_type = static_cast<NalUnitType>(nal_header & 0x1f); 213 NalUnitType nal_unit_type = static_cast<NalUnitType>(nal_header & 0x1f);
214 DVLOG(LOG_LEVEL_ES) << "nal: offset=" << es_pos_ 214 DVLOG(LOG_LEVEL_ES) << "nal: offset=" << es_pos_
215 << " type=" << nal_unit_type; 215 << " type=" << nal_unit_type;
216 216
217 // Emit a frame if needed. 217 // Emit a frame if needed.
218 if (nal_unit_type == kNalUnitTypeAUD) 218 if (nal_unit_type == kNalUnitTypeAUD)
219 EmitFrameIfNeeded(es_pos_); 219 RCHECK(EmitFrameIfNeeded(es_pos_));
220 220
221 // Skip the syncword. 221 // Skip the syncword.
222 es_pos_ += syncword_length; 222 es_pos_ += syncword_length;
223 } 223 }
224 224
225 return true; 225 return true;
226 } 226 }
227 227
228 void EsParserH264::EmitFrameIfNeeded(int next_aud_pos) { 228 bool EsParserH264::EmitFrameIfNeeded(int next_aud_pos) {
229 // There is no current frame: start a new frame. 229 // There is no current frame: start a new frame.
230 if (current_access_unit_pos_ < 0) { 230 if (current_access_unit_pos_ < 0) {
231 StartFrame(next_aud_pos); 231 StartFrame(next_aud_pos);
232 return; 232 return true;
233 } 233 }
234 234
235 // Get the access unit timing info. 235 // Get the access unit timing info.
236 TimingDesc current_timing_desc; 236 TimingDesc current_timing_desc = {kNoTimestamp(), kNoTimestamp()};
237
damienv1 2014/01/16 01:05:54 nit: blank line not needed (otherwise the previous
237 while (!timing_desc_list_.empty() && 238 while (!timing_desc_list_.empty() &&
238 timing_desc_list_.front().first <= current_access_unit_pos_) { 239 timing_desc_list_.front().first <= current_access_unit_pos_) {
239 current_timing_desc = timing_desc_list_.front().second; 240 current_timing_desc = timing_desc_list_.front().second;
240 timing_desc_list_.pop_front(); 241 timing_desc_list_.pop_front();
241 } 242 }
242 243
244 if (current_timing_desc.pts == kNoTimestamp())
245 return false;
246
243 // Emit a frame. 247 // Emit a frame.
244 int raw_es_size; 248 int raw_es_size;
245 const uint8* raw_es; 249 const uint8* raw_es;
246 es_byte_queue_.Peek(&raw_es, &raw_es_size); 250 es_byte_queue_.Peek(&raw_es, &raw_es_size);
247 int access_unit_size = next_aud_pos - current_access_unit_pos_; 251 int access_unit_size = next_aud_pos - current_access_unit_pos_;
248 scoped_refptr<StreamParserBuffer> stream_parser_buffer = 252 scoped_refptr<StreamParserBuffer> stream_parser_buffer =
249 StreamParserBuffer::CopyFrom( 253 StreamParserBuffer::CopyFrom(
250 &raw_es[current_access_unit_pos_], 254 &raw_es[current_access_unit_pos_],
251 access_unit_size, 255 access_unit_size,
252 is_key_frame_); 256 is_key_frame_);
253 stream_parser_buffer->SetDecodeTimestamp(current_timing_desc.dts); 257 stream_parser_buffer->SetDecodeTimestamp(current_timing_desc.dts);
254 stream_parser_buffer->set_timestamp(current_timing_desc.pts); 258 stream_parser_buffer->set_timestamp(current_timing_desc.pts);
255 emit_buffer_cb_.Run(stream_parser_buffer); 259 emit_buffer_cb_.Run(stream_parser_buffer);
256 260
257 // Set the current frame position to the next AUD position. 261 // Set the current frame position to the next AUD position.
258 StartFrame(next_aud_pos); 262 StartFrame(next_aud_pos);
263 return true;
259 } 264 }
260 265
261 void EsParserH264::StartFrame(int aud_pos) { 266 void EsParserH264::StartFrame(int aud_pos) {
262 // Two cases: 267 // Two cases:
263 // - if aud_pos < 0, clear the current frame and set |is_key_frame| to a 268 // - if aud_pos < 0, clear the current frame and set |is_key_frame| to a
264 // default value (false). 269 // default value (false).
265 // - if aud_pos >= 0, start a new frame and set |is_key_frame| to true 270 // - if aud_pos >= 0, start a new frame and set |is_key_frame| to true
266 // |is_key_frame_| will be updated while parsing the NALs of that frame. 271 // |is_key_frame_| will be updated while parsing the NALs of that frame.
267 // If any NAL is a non IDR NAL, it will be set to false. 272 // If any NAL is a non IDR NAL, it will be set to false.
268 current_access_unit_pos_ = aud_pos; 273 current_access_unit_pos_ = aud_pos;
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 last_video_decoder_config_ = video_decoder_config; 527 last_video_decoder_config_ = video_decoder_config;
523 new_video_config_cb_.Run(video_decoder_config); 528 new_video_config_cb_.Run(video_decoder_config);
524 } 529 }
525 530
526 return true; 531 return true;
527 } 532 }
528 533
529 } // namespace mp2t 534 } // namespace mp2t
530 } // namespace media 535 } // namespace media
531 536
OLDNEW
« no previous file with comments | « media/mp2t/es_parser_h264.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698