OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 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/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 758 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
769 kMaxMissingTrackInSegmentLogs) | 769 kMaxMissingTrackInSegmentLogs) |
770 << "Media segment did not contain any " | 770 << "Media segment did not contain any " |
771 << (missing_audio && missing_video ? "audio or video" | 771 << (missing_audio && missing_video ? "audio or video" |
772 : missing_audio ? "audio" : "video") | 772 : missing_audio ? "audio" : "video") |
773 << " coded frames, mismatching initialization segment. Therefore, MSE " | 773 << " coded frames, mismatching initialization segment. Therefore, MSE " |
774 "coded frame processing may not interoperably detect discontinuities " | 774 "coded frame processing may not interoperably detect discontinuities " |
775 "in appended media."; | 775 "in appended media."; |
776 } | 776 } |
777 | 777 |
778 bool MediaSourceState::OnNewBuffers( | 778 bool MediaSourceState::OnNewBuffers( |
779 const StreamParser::BufferQueue& audio_buffers, | 779 const StreamParser::BufferQueueMap& buffer_queue_map) { |
780 const StreamParser::BufferQueue& video_buffers, | |
781 const StreamParser::TextBufferQueueMap& text_map) { | |
782 DVLOG(2) << "OnNewBuffers()"; | 780 DVLOG(2) << "OnNewBuffers()"; |
783 DCHECK_EQ(state_, PARSER_INITIALIZED); | 781 DCHECK_EQ(state_, PARSER_INITIALIZED); |
784 DCHECK(timestamp_offset_during_append_); | 782 DCHECK(timestamp_offset_during_append_); |
785 DCHECK(parsing_media_segment_); | 783 DCHECK(parsing_media_segment_); |
786 | 784 |
787 media_segment_contained_audio_frame_ |= !audio_buffers.empty(); | 785 for (const auto& it : buffer_queue_map) { |
788 media_segment_contained_video_frame_ |= !video_buffers.empty(); | 786 const StreamParser::BufferQueue& bufq = it.second; |
787 DCHECK(!bufq.empty()); | |
788 if (bufq[0]->type() == DemuxerStream::AUDIO) { | |
789 media_segment_contained_audio_frame_ = true; | |
790 } else if (bufq[0]->type() == DemuxerStream::VIDEO) { | |
791 media_segment_contained_video_frame_ = true; | |
792 } | |
793 } | |
789 | 794 |
790 const TimeDelta timestamp_offset_before_processing = | 795 const TimeDelta timestamp_offset_before_processing = |
791 *timestamp_offset_during_append_; | 796 *timestamp_offset_during_append_; |
792 | 797 |
793 // Calculate the new timestamp offset for audio/video tracks if the stream | 798 // Calculate the new timestamp offset for audio/video tracks if the stream |
794 // parser has requested automatic updates. | 799 // parser has requested automatic updates. |
795 TimeDelta new_timestamp_offset = timestamp_offset_before_processing; | 800 TimeDelta new_timestamp_offset = timestamp_offset_before_processing; |
796 if (auto_update_timestamp_offset_) { | 801 if (auto_update_timestamp_offset_) { |
797 const bool have_audio_buffers = !audio_buffers.empty(); | 802 TimeDelta min_end_timestamp = kNoTimestamp; |
798 const bool have_video_buffers = !video_buffers.empty(); | 803 for (const auto& it : buffer_queue_map) { |
799 if (have_audio_buffers && have_video_buffers) { | 804 const StreamParser::BufferQueue& bufq = it.second; |
800 new_timestamp_offset += | 805 DCHECK(!bufq.empty()); |
801 std::min(EndTimestamp(audio_buffers), EndTimestamp(video_buffers)); | 806 if (min_end_timestamp == kNoTimestamp || |
802 } else if (have_audio_buffers) { | 807 EndTimestamp(bufq) < min_end_timestamp) { |
wolenetz
2016/08/23 21:31:21
aside: text track EndTimestamp minimums are now in
servolk
2016/08/23 23:56:32
Acknowledged. Yes, that's a good point. But would
wolenetz
2016/08/24 21:57:51
I'm not sure, though the right eventual fix will b
servolk
2016/08/24 23:17:44
Acknowledged.
| |
803 new_timestamp_offset += EndTimestamp(audio_buffers); | 808 min_end_timestamp = EndTimestamp(bufq); |
804 } else if (have_video_buffers) { | 809 DCHECK_NE(kNoTimestamp, min_end_timestamp); |
805 new_timestamp_offset += EndTimestamp(video_buffers); | 810 } |
806 } | 811 } |
812 if (min_end_timestamp != kNoTimestamp) | |
813 new_timestamp_offset += min_end_timestamp; | |
807 } | 814 } |
808 | 815 |
809 if (!frame_processor_->ProcessFrames(audio_buffers, video_buffers, text_map, | 816 if (!frame_processor_->ProcessFrames( |
810 append_window_start_during_append_, | 817 buffer_queue_map, append_window_start_during_append_, |
811 append_window_end_during_append_, | 818 append_window_end_during_append_, timestamp_offset_during_append_)) { |
812 timestamp_offset_during_append_)) { | |
813 return false; | 819 return false; |
814 } | 820 } |
815 | 821 |
816 // Only update the timestamp offset if the frame processor hasn't already. | 822 // Only update the timestamp offset if the frame processor hasn't already. |
817 if (auto_update_timestamp_offset_ && | 823 if (auto_update_timestamp_offset_ && |
818 timestamp_offset_before_processing == *timestamp_offset_during_append_) { | 824 timestamp_offset_before_processing == *timestamp_offset_during_append_) { |
819 *timestamp_offset_during_append_ = new_timestamp_offset; | 825 *timestamp_offset_during_append_ = new_timestamp_offset; |
820 } | 826 } |
821 | 827 |
822 return true; | 828 return true; |
823 } | 829 } |
824 | 830 |
825 void MediaSourceState::OnSourceInitDone( | 831 void MediaSourceState::OnSourceInitDone( |
826 const StreamParser::InitParameters& params) { | 832 const StreamParser::InitParameters& params) { |
827 DCHECK_EQ(state_, PENDING_PARSER_INIT); | 833 DCHECK_EQ(state_, PENDING_PARSER_INIT); |
828 state_ = PARSER_INITIALIZED; | 834 state_ = PARSER_INITIALIZED; |
829 auto_update_timestamp_offset_ = params.auto_update_timestamp_offset; | 835 auto_update_timestamp_offset_ = params.auto_update_timestamp_offset; |
830 base::ResetAndReturn(&init_cb_).Run(params); | 836 base::ResetAndReturn(&init_cb_).Run(params); |
831 } | 837 } |
832 | 838 |
833 } // namespace media | 839 } // namespace media |
OLD | NEW |