OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/mp4/mp4_stream_parser.h" | 5 #include "media/mp4/mp4_stream_parser.h" |
6 | 6 |
7 #include "base/callback.h" | 7 #include "base/callback.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
79 bool result, err = false; | 79 bool result, err = false; |
80 | 80 |
81 do { | 81 do { |
82 if (state_ == kParsingBoxes) { | 82 if (state_ == kParsingBoxes) { |
83 result = ParseBox(&err); | 83 result = ParseBox(&err); |
84 } else { | 84 } else { |
85 DCHECK_EQ(kEmittingSamples, state_); | 85 DCHECK_EQ(kEmittingSamples, state_); |
86 result = EnqueueSample(&audio_buffers, &video_buffers, &err); | 86 result = EnqueueSample(&audio_buffers, &video_buffers, &err); |
87 if (result) { | 87 if (result) { |
88 int64 max_clear = runs_->GetMaxClearOffset() + moof_head_; | 88 int64 max_clear = runs_->GetMaxClearOffset() + moof_head_; |
89 DCHECK(max_clear <= queue_.tail()); | 89 err = !ReadAndDiscardMDATsUntil(max_clear); |
90 err = !(ReadMDATsUntil(max_clear) && queue_.Trim(max_clear)); | |
91 } | 90 } |
92 } | 91 } |
93 } while (result && !err); | 92 } while (result && !err); |
94 | 93 |
95 if (!err) | 94 if (!err) |
96 err = !SendAndFlushSamples(&audio_buffers, &video_buffers); | 95 err = !SendAndFlushSamples(&audio_buffers, &video_buffers); |
97 | 96 |
98 if (err) { | 97 if (err) { |
99 DLOG(ERROR) << "Error while parsing MP4"; | 98 DLOG(ERROR) << "Error while parsing MP4"; |
100 queue_.Reset(); | 99 queue_.Reset(); |
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
431 err |= (audio_cb_.is_null() || !audio_cb_.Run(*audio_buffers)); | 430 err |= (audio_cb_.is_null() || !audio_cb_.Run(*audio_buffers)); |
432 audio_buffers->clear(); | 431 audio_buffers->clear(); |
433 } | 432 } |
434 if (!video_buffers->empty()) { | 433 if (!video_buffers->empty()) { |
435 err |= (video_cb_.is_null() || !video_cb_.Run(*video_buffers)); | 434 err |= (video_cb_.is_null() || !video_cb_.Run(*video_buffers)); |
436 video_buffers->clear(); | 435 video_buffers->clear(); |
437 } | 436 } |
438 return !err; | 437 return !err; |
439 } | 438 } |
440 | 439 |
441 bool MP4StreamParser::ReadMDATsUntil(const int64 tgt_offset) { | 440 bool MP4StreamParser::ReadAndDiscardMDATsUntil(const int64 tgt_offset) { |
442 DCHECK(tgt_offset <= queue_.tail()); | 441 bool err = false; |
acolwell GONE FROM CHROMIUM
2012/08/01 16:39:02
Why remove this DCHECK?
strobe_
2012/08/01 19:01:33
It was in fact always too narrow. It worked before
| |
443 | |
444 while (mdat_tail_ < tgt_offset) { | 442 while (mdat_tail_ < tgt_offset) { |
445 const uint8* buf; | 443 const uint8* buf; |
446 int size; | 444 int size; |
447 queue_.PeekAt(mdat_tail_, &buf, &size); | 445 queue_.PeekAt(mdat_tail_, &buf, &size); |
448 | 446 |
449 FourCC type; | 447 FourCC type; |
450 int box_sz; | 448 int box_sz; |
451 bool err; | |
452 if (!BoxReader::StartTopLevelBox(buf, size, &type, &box_sz, &err)) | 449 if (!BoxReader::StartTopLevelBox(buf, size, &type, &box_sz, &err)) |
453 return false; | 450 break; |
454 | 451 |
455 if (type != FOURCC_MDAT) { | 452 if (type != FOURCC_MDAT) { |
456 DLOG(WARNING) << "Unexpected type while parsing MDATs: " | 453 DLOG(WARNING) << "Unexpected type while parsing MDATs: " |
457 << FourCCToString(type); | 454 << FourCCToString(type); |
458 } | 455 } |
459 | |
460 mdat_tail_ += box_sz; | 456 mdat_tail_ += box_sz; |
461 } | 457 } |
462 | 458 queue_.Trim(std::min(mdat_tail_, tgt_offset)); |
acolwell GONE FROM CHROMIUM
2012/08/01 16:39:02
Why do you unconditionally trim now?
strobe_
2012/08/01 19:01:33
If multiple boxes are consumed in this loop, but t
| |
463 return true; | 459 return !err; |
464 } | 460 } |
465 | 461 |
466 void MP4StreamParser::ChangeState(State new_state) { | 462 void MP4StreamParser::ChangeState(State new_state) { |
467 DVLOG(2) << "Changing state: " << new_state; | 463 DVLOG(2) << "Changing state: " << new_state; |
468 state_ = new_state; | 464 state_ = new_state; |
469 } | 465 } |
470 | 466 |
471 } // namespace mp4 | 467 } // namespace mp4 |
472 } // namespace media | 468 } // namespace media |
OLD | NEW |