| OLD | NEW |
| 1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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/filters/media_source_state.h" | 5 #include "media/filters/media_source_state.h" |
| 6 | 6 |
| 7 #include "base/callback_helpers.h" | 7 #include "base/callback_helpers.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "media/filters/chunk_demuxer.h" | 9 #include "media/filters/chunk_demuxer.h" |
| 10 #include "media/filters/frame_processor.h" | 10 #include "media/filters/frame_processor.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 return intersection_ranges; | 83 return intersection_ranges; |
| 84 } | 84 } |
| 85 | 85 |
| 86 MediaSourceState::MediaSourceState( | 86 MediaSourceState::MediaSourceState( |
| 87 scoped_ptr<StreamParser> stream_parser, | 87 scoped_ptr<StreamParser> stream_parser, |
| 88 scoped_ptr<FrameProcessor> frame_processor, | 88 scoped_ptr<FrameProcessor> frame_processor, |
| 89 const CreateDemuxerStreamCB& create_demuxer_stream_cb, | 89 const CreateDemuxerStreamCB& create_demuxer_stream_cb, |
| 90 const scoped_refptr<MediaLog>& media_log) | 90 const scoped_refptr<MediaLog>& media_log) |
| 91 : create_demuxer_stream_cb_(create_demuxer_stream_cb), | 91 : create_demuxer_stream_cb_(create_demuxer_stream_cb), |
| 92 timestamp_offset_during_append_(NULL), | 92 timestamp_offset_during_append_(NULL), |
| 93 new_media_segment_(false), |
| 93 parsing_media_segment_(false), | 94 parsing_media_segment_(false), |
| 94 media_segment_contained_audio_frame_(false), | 95 media_segment_contained_audio_frame_(false), |
| 95 media_segment_contained_video_frame_(false), | 96 media_segment_contained_video_frame_(false), |
| 96 stream_parser_(stream_parser.release()), | 97 stream_parser_(stream_parser.release()), |
| 97 audio_(NULL), | 98 audio_(NULL), |
| 98 video_(NULL), | 99 video_(NULL), |
| 99 frame_processor_(frame_processor.release()), | 100 frame_processor_(frame_processor.release()), |
| 100 media_log_(media_log), | 101 media_log_(media_log), |
| 101 auto_update_timestamp_offset_(false) { | 102 auto_update_timestamp_offset_(false) { |
| 102 DCHECK(!create_demuxer_stream_cb_.is_null()); | 103 DCHECK(!create_demuxer_stream_cb_.is_null()); |
| (...skipping 536 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 639 DVLOG(1) << "OnNewConfigs() : " << (success ? "success" : "failed"); | 640 DVLOG(1) << "OnNewConfigs() : " << (success ? "success" : "failed"); |
| 640 if (success) | 641 if (success) |
| 641 init_segment_received_cb_.Run(); | 642 init_segment_received_cb_.Run(); |
| 642 | 643 |
| 643 return success; | 644 return success; |
| 644 } | 645 } |
| 645 | 646 |
| 646 void MediaSourceState::OnNewMediaSegment() { | 647 void MediaSourceState::OnNewMediaSegment() { |
| 647 DVLOG(2) << "OnNewMediaSegment()"; | 648 DVLOG(2) << "OnNewMediaSegment()"; |
| 648 parsing_media_segment_ = true; | 649 parsing_media_segment_ = true; |
| 650 new_media_segment_ = true; |
| 649 media_segment_contained_audio_frame_ = false; | 651 media_segment_contained_audio_frame_ = false; |
| 650 media_segment_contained_video_frame_ = false; | 652 media_segment_contained_video_frame_ = false; |
| 651 } | 653 } |
| 652 | 654 |
| 653 void MediaSourceState::OnEndOfMediaSegment() { | 655 void MediaSourceState::OnEndOfMediaSegment() { |
| 654 DVLOG(2) << "OnEndOfMediaSegment()"; | 656 DVLOG(2) << "OnEndOfMediaSegment()"; |
| 655 parsing_media_segment_ = false; | 657 parsing_media_segment_ = false; |
| 658 new_media_segment_ = false; |
| 656 | 659 |
| 657 const bool missing_audio = audio_ && !media_segment_contained_audio_frame_; | 660 const bool missing_audio = audio_ && !media_segment_contained_audio_frame_; |
| 658 const bool missing_video = video_ && !media_segment_contained_video_frame_; | 661 const bool missing_video = video_ && !media_segment_contained_video_frame_; |
| 659 if (!missing_audio && !missing_video) | 662 if (!missing_audio && !missing_video) |
| 660 return; | 663 return; |
| 661 | 664 |
| 662 LIMITED_MEDIA_LOG(DEBUG, media_log_, num_missing_track_logs_, | 665 LIMITED_MEDIA_LOG(DEBUG, media_log_, num_missing_track_logs_, |
| 663 kMaxMissingTrackInSegmentLogs) | 666 kMaxMissingTrackInSegmentLogs) |
| 664 << "Media segment did not contain any " | 667 << "Media segment did not contain any " |
| 665 << (missing_audio && missing_video ? "audio or video" | 668 << (missing_audio && missing_video ? "audio or video" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 692 if (have_audio_buffers && have_video_buffers) { | 695 if (have_audio_buffers && have_video_buffers) { |
| 693 new_timestamp_offset += | 696 new_timestamp_offset += |
| 694 std::min(EndTimestamp(audio_buffers), EndTimestamp(video_buffers)); | 697 std::min(EndTimestamp(audio_buffers), EndTimestamp(video_buffers)); |
| 695 } else if (have_audio_buffers) { | 698 } else if (have_audio_buffers) { |
| 696 new_timestamp_offset += EndTimestamp(audio_buffers); | 699 new_timestamp_offset += EndTimestamp(audio_buffers); |
| 697 } else if (have_video_buffers) { | 700 } else if (have_video_buffers) { |
| 698 new_timestamp_offset += EndTimestamp(video_buffers); | 701 new_timestamp_offset += EndTimestamp(video_buffers); |
| 699 } | 702 } |
| 700 } | 703 } |
| 701 | 704 |
| 702 if (!frame_processor_->ProcessFrames(audio_buffers, video_buffers, text_map, | 705 if (!frame_processor_->ProcessFrames( |
| 703 append_window_start_during_append_, | 706 audio_buffers, video_buffers, text_map, |
| 704 append_window_end_during_append_, | 707 append_window_start_during_append_, append_window_end_during_append_, |
| 705 timestamp_offset_during_append_)) { | 708 &new_media_segment_, timestamp_offset_during_append_)) { |
| 706 return false; | 709 return false; |
| 707 } | 710 } |
| 708 | 711 |
| 709 // Only update the timestamp offset if the frame processor hasn't already. | 712 // Only update the timestamp offset if the frame processor hasn't already. |
| 710 if (auto_update_timestamp_offset_ && | 713 if (auto_update_timestamp_offset_ && |
| 711 timestamp_offset_before_processing == *timestamp_offset_during_append_) { | 714 timestamp_offset_before_processing == *timestamp_offset_during_append_) { |
| 712 *timestamp_offset_during_append_ = new_timestamp_offset; | 715 *timestamp_offset_during_append_ = new_timestamp_offset; |
| 713 } | 716 } |
| 714 | 717 |
| 715 return true; | 718 return true; |
| 716 } | 719 } |
| 717 | 720 |
| 718 void MediaSourceState::OnSourceInitDone( | 721 void MediaSourceState::OnSourceInitDone( |
| 719 const StreamParser::InitParameters& params) { | 722 const StreamParser::InitParameters& params) { |
| 720 auto_update_timestamp_offset_ = params.auto_update_timestamp_offset; | 723 auto_update_timestamp_offset_ = params.auto_update_timestamp_offset; |
| 721 base::ResetAndReturn(&init_cb_).Run(params); | 724 base::ResetAndReturn(&init_cb_).Run(params); |
| 722 } | 725 } |
| 723 | 726 |
| 724 } // namespace media | 727 } // namespace media |
| OLD | NEW |