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

Side by Side Diff: media/mp4/mp4_stream_parser.cc

Issue 10834101: Fix MP4StreamParser discard behavior when retaining 'moof'. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tgt_offset -> offset Created 8 years, 4 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 | Annotate | Revision Log
« no previous file with comments | « media/mp4/mp4_stream_parser.h ('k') | media/mp4/mp4_stream_parser_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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 offset) {
442 DCHECK(tgt_offset <= queue_.tail()); 441 bool err = false;
443 442 while (mdat_tail_ < offset) {
444 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_, offset));
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
OLDNEW
« no previous file with comments | « media/mp4/mp4_stream_parser.h ('k') | media/mp4/mp4_stream_parser_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698