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

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: Removed extra blank line as per review comment. 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
« media/mp2t/es_parser_h264.h ('K') | « 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 while (!timing_desc_list_.empty() && 237 while (!timing_desc_list_.empty() &&
238 timing_desc_list_.front().first <= current_access_unit_pos_) { 238 timing_desc_list_.front().first <= current_access_unit_pos_) {
239 current_timing_desc = timing_desc_list_.front().second; 239 current_timing_desc = timing_desc_list_.front().second;
240 timing_desc_list_.pop_front(); 240 timing_desc_list_.pop_front();
241 } 241 }
242 242
243 if (current_timing_desc.pts == kNoTimestamp())
244 return false;
245
243 // Emit a frame. 246 // Emit a frame.
244 int raw_es_size; 247 int raw_es_size;
245 const uint8* raw_es; 248 const uint8* raw_es;
246 es_byte_queue_.Peek(&raw_es, &raw_es_size); 249 es_byte_queue_.Peek(&raw_es, &raw_es_size);
247 int access_unit_size = next_aud_pos - current_access_unit_pos_; 250 int access_unit_size = next_aud_pos - current_access_unit_pos_;
248 scoped_refptr<StreamParserBuffer> stream_parser_buffer = 251 scoped_refptr<StreamParserBuffer> stream_parser_buffer =
249 StreamParserBuffer::CopyFrom( 252 StreamParserBuffer::CopyFrom(
250 &raw_es[current_access_unit_pos_], 253 &raw_es[current_access_unit_pos_],
251 access_unit_size, 254 access_unit_size,
252 is_key_frame_); 255 is_key_frame_);
253 stream_parser_buffer->SetDecodeTimestamp(current_timing_desc.dts); 256 stream_parser_buffer->SetDecodeTimestamp(current_timing_desc.dts);
254 stream_parser_buffer->set_timestamp(current_timing_desc.pts); 257 stream_parser_buffer->set_timestamp(current_timing_desc.pts);
255 emit_buffer_cb_.Run(stream_parser_buffer); 258 emit_buffer_cb_.Run(stream_parser_buffer);
256 259
257 // Set the current frame position to the next AUD position. 260 // Set the current frame position to the next AUD position.
258 StartFrame(next_aud_pos); 261 StartFrame(next_aud_pos);
262 return true;
259 } 263 }
260 264
261 void EsParserH264::StartFrame(int aud_pos) { 265 void EsParserH264::StartFrame(int aud_pos) {
262 // Two cases: 266 // Two cases:
263 // - if aud_pos < 0, clear the current frame and set |is_key_frame| to a 267 // - if aud_pos < 0, clear the current frame and set |is_key_frame| to a
264 // default value (false). 268 // default value (false).
265 // - if aud_pos >= 0, start a new frame and set |is_key_frame| to true 269 // - 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. 270 // |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. 271 // If any NAL is a non IDR NAL, it will be set to false.
268 current_access_unit_pos_ = aud_pos; 272 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; 526 last_video_decoder_config_ = video_decoder_config;
523 new_video_config_cb_.Run(video_decoder_config); 527 new_video_config_cb_.Run(video_decoder_config);
524 } 528 }
525 529
526 return true; 530 return true;
527 } 531 }
528 532
529 } // namespace mp2t 533 } // namespace mp2t
530 } // namespace media 534 } // namespace media
531 535
OLDNEW
« media/mp2t/es_parser_h264.h ('K') | « media/mp2t/es_parser_h264.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698