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