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

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

Issue 10843044: Fix sourceAbort() for BMFF streams. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 ChangeState(kParsingBoxes); 51 ChangeState(kParsingBoxes);
52 init_cb_ = init_cb; 52 init_cb_ = init_cb;
53 config_cb_ = config_cb; 53 config_cb_ = config_cb;
54 audio_cb_ = audio_cb; 54 audio_cb_ = audio_cb;
55 video_cb_ = video_cb; 55 video_cb_ = video_cb;
56 need_key_cb_ = need_key_cb; 56 need_key_cb_ = need_key_cb;
57 new_segment_cb_ = new_segment_cb; 57 new_segment_cb_ = new_segment_cb;
58 end_of_segment_cb_ = end_of_segment_cb; 58 end_of_segment_cb_ = end_of_segment_cb;
59 } 59 }
60 60
61 void MP4StreamParser::Reset() {
62 queue_.Reset();
63 moov_.reset();
64 runs_.reset();
65 moof_head_ = 0;
66 mdat_tail_ = 0;
67 }
68
61 void MP4StreamParser::Flush() { 69 void MP4StreamParser::Flush() {
62 DCHECK_NE(state_, kWaitingForInit); 70 DCHECK_NE(state_, kWaitingForInit);
63 71 Reset();
64 queue_.Reset(); 72 ChangeState(kParsingBoxes);
65 moof_head_ = 0;
66 mdat_tail_ = 0;
67 } 73 }
68 74
69 bool MP4StreamParser::Parse(const uint8* buf, int size) { 75 bool MP4StreamParser::Parse(const uint8* buf, int size) {
70 DCHECK_NE(state_, kWaitingForInit); 76 DCHECK_NE(state_, kWaitingForInit);
71 77
72 if (state_ == kError) 78 if (state_ == kError)
73 return false; 79 return false;
74 80
75 queue_.Push(buf, size); 81 queue_.Push(buf, size);
76 82
(...skipping 13 matching lines...) Expand all
90 err = !ReadAndDiscardMDATsUntil(max_clear); 96 err = !ReadAndDiscardMDATsUntil(max_clear);
91 } 97 }
92 } 98 }
93 } while (result && !err); 99 } while (result && !err);
94 100
95 if (!err) 101 if (!err)
96 err = !SendAndFlushSamples(&audio_buffers, &video_buffers); 102 err = !SendAndFlushSamples(&audio_buffers, &video_buffers);
97 103
98 if (err) { 104 if (err) {
99 DLOG(ERROR) << "Error while parsing MP4"; 105 DLOG(ERROR) << "Error while parsing MP4";
100 queue_.Reset(); 106 Reset();
101 moov_.reset();
102 runs_.reset();
103 ChangeState(kError); 107 ChangeState(kError);
104 return false; 108 return false;
105 } 109 }
106 110
107 return true; 111 return true;
108 } 112 }
109 113
110 bool MP4StreamParser::ParseBox(bool* err) { 114 bool MP4StreamParser::ParseBox(bool* err) {
111 const uint8* buf; 115 const uint8* buf;
112 int size; 116 int size;
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
371 375
372 scoped_ptr<DecryptConfig> decrypt_config; 376 scoped_ptr<DecryptConfig> decrypt_config;
373 if (runs_->is_encrypted()) 377 if (runs_->is_encrypted())
374 decrypt_config = runs_->GetDecryptConfig(); 378 decrypt_config = runs_->GetDecryptConfig();
375 379
376 std::vector<uint8> frame_buf(buf, buf + runs_->sample_size()); 380 std::vector<uint8> frame_buf(buf, buf + runs_->sample_size());
377 if (video) { 381 if (video) {
378 std::vector<SubsampleEntry> subsamples; 382 std::vector<SubsampleEntry> subsamples;
379 if (decrypt_config.get()) 383 if (decrypt_config.get())
380 subsamples = decrypt_config->subsamples(); 384 subsamples = decrypt_config->subsamples();
381 RCHECK(PrepareAVCBuffer(runs_->video_description().avcc, 385 if (!PrepareAVCBuffer(runs_->video_description().avcc,
382 &frame_buf, &subsamples)); 386 &frame_buf, &subsamples)) {
387 DLOG(ERROR) << "Failed to prepare AVC sample for decode";
388 *err = true;
389 return false;
390 }
383 if (!subsamples.empty()) { 391 if (!subsamples.empty()) {
384 decrypt_config.reset(new DecryptConfig( 392 decrypt_config.reset(new DecryptConfig(
385 decrypt_config->key_id(), 393 decrypt_config->key_id(),
386 decrypt_config->iv(), 394 decrypt_config->iv(),
387 decrypt_config->checksum(), 395 decrypt_config->checksum(),
388 decrypt_config->data_offset(), 396 decrypt_config->data_offset(),
389 subsamples)); 397 subsamples));
390 } 398 }
391 } 399 }
392 400
393 if (audio) { 401 if (audio) {
394 const AAC& aac = runs_->audio_description().esds.aac; 402 const AAC& aac = runs_->audio_description().esds.aac;
395 RCHECK(aac.ConvertEsdsToADTS(&frame_buf)); 403 if (!aac.ConvertEsdsToADTS(&frame_buf)) {
404 DLOG(ERROR) << "Failed to convert ESDS to ADTS";
405 *err = true;
406 return false;
407 }
396 } 408 }
397 409
398 scoped_refptr<StreamParserBuffer> stream_buf = 410 scoped_refptr<StreamParserBuffer> stream_buf =
399 StreamParserBuffer::CopyFrom(&frame_buf[0], frame_buf.size(), 411 StreamParserBuffer::CopyFrom(&frame_buf[0], frame_buf.size(),
400 runs_->is_keyframe()); 412 runs_->is_keyframe());
401 413
402 if (runs_->is_encrypted()) 414 if (runs_->is_encrypted())
403 stream_buf->SetDecryptConfig(decrypt_config.Pass()); 415 stream_buf->SetDecryptConfig(decrypt_config.Pass());
404 416
405 stream_buf->SetDuration(runs_->duration()); 417 stream_buf->SetDuration(runs_->duration());
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 return !err; 471 return !err;
460 } 472 }
461 473
462 void MP4StreamParser::ChangeState(State new_state) { 474 void MP4StreamParser::ChangeState(State new_state) {
463 DVLOG(2) << "Changing state: " << new_state; 475 DVLOG(2) << "Changing state: " << new_state;
464 state_ = new_state; 476 state_ = new_state;
465 } 477 }
466 478
467 } // namespace mp4 479 } // namespace mp4
468 } // namespace media 480 } // 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