| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/formats/mp4/mp4_stream_parser.h" | 5 #include "media/formats/mp4/mp4_stream_parser.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
| 10 #include "media/base/audio_decoder_config.h" | 10 #include "media/base/audio_decoder_config.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 } | 40 } |
| 41 | 41 |
| 42 MP4StreamParser::~MP4StreamParser() {} | 42 MP4StreamParser::~MP4StreamParser() {} |
| 43 | 43 |
| 44 void MP4StreamParser::Init( | 44 void MP4StreamParser::Init( |
| 45 const InitCB& init_cb, | 45 const InitCB& init_cb, |
| 46 const NewConfigCB& config_cb, | 46 const NewConfigCB& config_cb, |
| 47 const NewBuffersCB& new_buffers_cb, | 47 const NewBuffersCB& new_buffers_cb, |
| 48 bool /* ignore_text_tracks */, | 48 bool /* ignore_text_tracks */, |
| 49 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, | 49 const EncryptedMediaInitDataCB& encrypted_media_init_data_cb, |
| 50 const NewMediaSegmentCB& new_segment_cb, | 50 const base::Closure& start_of_segment_cb, |
| 51 const base::Closure& end_of_segment_cb, | 51 const base::Closure& end_of_segment_cb, |
| 52 const scoped_refptr<MediaLog>& media_log) { | 52 const scoped_refptr<MediaLog>& media_log) { |
| 53 DCHECK_EQ(state_, kWaitingForInit); | 53 DCHECK_EQ(state_, kWaitingForInit); |
| 54 DCHECK(init_cb_.is_null()); | 54 DCHECK(init_cb_.is_null()); |
| 55 DCHECK(!init_cb.is_null()); | 55 DCHECK(!init_cb.is_null()); |
| 56 DCHECK(!config_cb.is_null()); | 56 DCHECK(!config_cb.is_null()); |
| 57 DCHECK(!new_buffers_cb.is_null()); | 57 DCHECK(!new_buffers_cb.is_null()); |
| 58 DCHECK(!encrypted_media_init_data_cb.is_null()); | 58 DCHECK(!encrypted_media_init_data_cb.is_null()); |
| 59 DCHECK(!end_of_segment_cb.is_null()); | 59 DCHECK(!end_of_segment_cb.is_null()); |
| 60 | 60 |
| 61 ChangeState(kParsingBoxes); | 61 ChangeState(kParsingBoxes); |
| 62 init_cb_ = init_cb; | 62 init_cb_ = init_cb; |
| 63 config_cb_ = config_cb; | 63 config_cb_ = config_cb; |
| 64 new_buffers_cb_ = new_buffers_cb; | 64 new_buffers_cb_ = new_buffers_cb; |
| 65 encrypted_media_init_data_cb_ = encrypted_media_init_data_cb; | 65 encrypted_media_init_data_cb_ = encrypted_media_init_data_cb; |
| 66 new_segment_cb_ = new_segment_cb; | 66 start_of_segment_cb_ = start_of_segment_cb; |
| 67 end_of_segment_cb_ = end_of_segment_cb; | 67 end_of_segment_cb_ = end_of_segment_cb; |
| 68 media_log_ = media_log; | 68 media_log_ = media_log; |
| 69 } | 69 } |
| 70 | 70 |
| 71 void MP4StreamParser::Reset() { | 71 void MP4StreamParser::Reset() { |
| 72 queue_.Reset(); | 72 queue_.Reset(); |
| 73 runs_.reset(); | 73 runs_.reset(); |
| 74 moof_head_ = 0; | 74 moof_head_ = 0; |
| 75 mdat_tail_ = 0; | 75 mdat_tail_ = 0; |
| 76 } | 76 } |
| (...skipping 277 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 MovieFragment moof; | 354 MovieFragment moof; |
| 355 RCHECK(moof.Parse(reader)); | 355 RCHECK(moof.Parse(reader)); |
| 356 if (!runs_) | 356 if (!runs_) |
| 357 runs_.reset(new TrackRunIterator(moov_.get(), media_log_)); | 357 runs_.reset(new TrackRunIterator(moov_.get(), media_log_)); |
| 358 RCHECK(runs_->Init(moof)); | 358 RCHECK(runs_->Init(moof)); |
| 359 RCHECK(ComputeHighestEndOffset(moof)); | 359 RCHECK(ComputeHighestEndOffset(moof)); |
| 360 | 360 |
| 361 if (!moof.pssh.empty()) | 361 if (!moof.pssh.empty()) |
| 362 OnEncryptedMediaInitData(moof.pssh); | 362 OnEncryptedMediaInitData(moof.pssh); |
| 363 | 363 |
| 364 new_segment_cb_.Run(); | 364 start_of_segment_cb_.Run(); |
| 365 ChangeState(kWaitingForSampleData); | 365 ChangeState(kWaitingForSampleData); |
| 366 return true; | 366 return true; |
| 367 } | 367 } |
| 368 | 368 |
| 369 void MP4StreamParser::OnEncryptedMediaInitData( | 369 void MP4StreamParser::OnEncryptedMediaInitData( |
| 370 const std::vector<ProtectionSystemSpecificHeader>& headers) { | 370 const std::vector<ProtectionSystemSpecificHeader>& headers) { |
| 371 // TODO(strobe): ensure that the value of init_data (all PSSH headers | 371 // TODO(strobe): ensure that the value of init_data (all PSSH headers |
| 372 // concatenated in arbitrary order) matches the EME spec. | 372 // concatenated in arbitrary order) matches the EME spec. |
| 373 // See https://www.w3.org/Bugs/Public/show_bug.cgi?id=17673. | 373 // See https://www.w3.org/Bugs/Public/show_bug.cgi?id=17673. |
| 374 size_t total_size = 0; | 374 size_t total_size = 0; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 402 return true; | 402 return true; |
| 403 } | 403 } |
| 404 | 404 |
| 405 bool MP4StreamParser::EnqueueSample(BufferQueue* audio_buffers, | 405 bool MP4StreamParser::EnqueueSample(BufferQueue* audio_buffers, |
| 406 BufferQueue* video_buffers, | 406 BufferQueue* video_buffers, |
| 407 bool* err) { | 407 bool* err) { |
| 408 DCHECK_EQ(state_, kEmittingSamples); | 408 DCHECK_EQ(state_, kEmittingSamples); |
| 409 | 409 |
| 410 if (!runs_->IsRunValid()) { | 410 if (!runs_->IsRunValid()) { |
| 411 // Flush any buffers we've gotten in this chunk so that buffers don't | 411 // Flush any buffers we've gotten in this chunk so that buffers don't |
| 412 // cross NewSegment() calls | 412 // cross |start_of_segment_cb_| calls |
| 413 *err = !SendAndFlushSamples(audio_buffers, video_buffers); | 413 *err = !SendAndFlushSamples(audio_buffers, video_buffers); |
| 414 if (*err) | 414 if (*err) |
| 415 return false; | 415 return false; |
| 416 | 416 |
| 417 // Remain in kEmittingSamples state, discarding data, until the end of | 417 // Remain in kEmittingSamples state, discarding data, until the end of |
| 418 // the current 'mdat' box has been appended to the queue. | 418 // the current 'mdat' box has been appended to the queue. |
| 419 if (!queue_.Trim(mdat_tail_)) | 419 if (!queue_.Trim(mdat_tail_)) |
| 420 return false; | 420 return false; |
| 421 | 421 |
| 422 ChangeState(kParsingBoxes); | 422 ChangeState(kParsingBoxes); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 runs.AdvanceSample(); | 621 runs.AdvanceSample(); |
| 622 } | 622 } |
| 623 runs.AdvanceRun(); | 623 runs.AdvanceRun(); |
| 624 } | 624 } |
| 625 | 625 |
| 626 return true; | 626 return true; |
| 627 } | 627 } |
| 628 | 628 |
| 629 } // namespace mp4 | 629 } // namespace mp4 |
| 630 } // namespace media | 630 } // namespace media |
| OLD | NEW |