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/base/media_track.h" | 9 #include "media/base/media_track.h" |
10 #include "media/base/media_tracks.h" | 10 #include "media/base/media_tracks.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 frame_processor_->SetSequenceMode(sequence_mode); | 138 frame_processor_->SetSequenceMode(sequence_mode); |
139 } | 139 } |
140 | 140 |
141 void MediaSourceState::SetGroupStartTimestampIfInSequenceMode( | 141 void MediaSourceState::SetGroupStartTimestampIfInSequenceMode( |
142 base::TimeDelta timestamp_offset) { | 142 base::TimeDelta timestamp_offset) { |
143 DCHECK(!parsing_media_segment_); | 143 DCHECK(!parsing_media_segment_); |
144 | 144 |
145 frame_processor_->SetGroupStartTimestampIfInSequenceMode(timestamp_offset); | 145 frame_processor_->SetGroupStartTimestampIfInSequenceMode(timestamp_offset); |
146 } | 146 } |
147 | 147 |
148 bool MediaSourceState::Append( | 148 void MediaSourceState::SetTracksWatcher( |
149 const uint8_t* data, | 149 const Demuxer::MediaTracksUpdatedCB& tracks_updated_cb) { |
150 size_t length, | 150 DCHECK(init_segment_received_cb_.is_null()); |
151 TimeDelta append_window_start, | 151 init_segment_received_cb_ = tracks_updated_cb; |
152 TimeDelta append_window_end, | 152 DCHECK(!init_segment_received_cb_.is_null()); |
153 TimeDelta* timestamp_offset, | 153 } |
154 const InitSegmentReceivedCB& init_segment_received_cb) { | 154 |
155 bool MediaSourceState::Append(const uint8_t* data, | |
156 size_t length, | |
157 TimeDelta append_window_start, | |
158 TimeDelta append_window_end, | |
159 TimeDelta* timestamp_offset) { | |
160 append_in_progress_ = true; | |
155 DCHECK(timestamp_offset); | 161 DCHECK(timestamp_offset); |
156 DCHECK(!timestamp_offset_during_append_); | 162 DCHECK(!timestamp_offset_during_append_); |
157 DCHECK(!init_segment_received_cb.is_null()); | |
158 DCHECK(init_segment_received_cb_.is_null()); | |
159 append_window_start_during_append_ = append_window_start; | 163 append_window_start_during_append_ = append_window_start; |
160 append_window_end_during_append_ = append_window_end; | 164 append_window_end_during_append_ = append_window_end; |
161 timestamp_offset_during_append_ = timestamp_offset; | 165 timestamp_offset_during_append_ = timestamp_offset; |
162 init_segment_received_cb_ = init_segment_received_cb; | |
163 | 166 |
164 // TODO(wolenetz/acolwell): Curry and pass a NewBuffersCB here bound with | 167 // TODO(wolenetz/acolwell): Curry and pass a NewBuffersCB here bound with |
165 // append window and timestamp offset pointer. See http://crbug.com/351454. | 168 // append window and timestamp offset pointer. See http://crbug.com/351454. |
166 bool result = stream_parser_->Parse(data, length); | 169 bool result = stream_parser_->Parse(data, length); |
167 if (!result) { | 170 if (!result) { |
168 MEDIA_LOG(ERROR, media_log_) | 171 MEDIA_LOG(ERROR, media_log_) |
169 << __FUNCTION__ << ": stream parsing failed." | 172 << __FUNCTION__ << ": stream parsing failed." |
170 << " Data size=" << length | 173 << " Data size=" << length |
171 << " append_window_start=" << append_window_start.InSecondsF() | 174 << " append_window_start=" << append_window_start.InSecondsF() |
172 << " append_window_end=" << append_window_end.InSecondsF(); | 175 << " append_window_end=" << append_window_end.InSecondsF(); |
173 } | 176 } |
174 timestamp_offset_during_append_ = NULL; | 177 timestamp_offset_during_append_ = NULL; |
175 init_segment_received_cb_.Reset(); | 178 append_in_progress_ = false; |
176 return result; | 179 return result; |
177 } | 180 } |
178 | 181 |
179 void MediaSourceState::ResetParserState(TimeDelta append_window_start, | 182 void MediaSourceState::ResetParserState(TimeDelta append_window_start, |
180 TimeDelta append_window_end, | 183 TimeDelta append_window_end, |
181 base::TimeDelta* timestamp_offset) { | 184 base::TimeDelta* timestamp_offset) { |
182 DCHECK(timestamp_offset); | 185 DCHECK(timestamp_offset); |
183 DCHECK(!timestamp_offset_during_append_); | 186 DCHECK(!timestamp_offset_during_append_); |
184 timestamp_offset_during_append_ = timestamp_offset; | 187 timestamp_offset_during_append_ = timestamp_offset; |
185 append_window_start_during_append_ = append_window_start; | 188 append_window_start_during_append_ = append_window_start; |
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 scoped_ptr<MediaTracks> tracks, | 476 scoped_ptr<MediaTracks> tracks, |
474 const StreamParser::TextTrackConfigMap& text_configs) { | 477 const StreamParser::TextTrackConfigMap& text_configs) { |
475 DCHECK(tracks.get()); | 478 DCHECK(tracks.get()); |
476 media_tracks_ = std::move(tracks); | 479 media_tracks_ = std::move(tracks); |
477 const AudioDecoderConfig& audio_config = media_tracks_->getFirstAudioConfig(); | 480 const AudioDecoderConfig& audio_config = media_tracks_->getFirstAudioConfig(); |
478 const VideoDecoderConfig& video_config = media_tracks_->getFirstVideoConfig(); | 481 const VideoDecoderConfig& video_config = media_tracks_->getFirstVideoConfig(); |
479 | 482 |
480 DVLOG(1) << "OnNewConfigs(" << allow_audio << ", " << allow_video << ", " | 483 DVLOG(1) << "OnNewConfigs(" << allow_audio << ", " << allow_video << ", " |
481 << audio_config.IsValidConfig() << ", " | 484 << audio_config.IsValidConfig() << ", " |
482 << video_config.IsValidConfig() << ")"; | 485 << video_config.IsValidConfig() << ")"; |
483 DCHECK(!init_segment_received_cb_.is_null()); | 486 // MSE spec allows new configs to be emitted only during Append, but not |
487 // during Flush or parser reset operations. | |
488 CHECK(append_in_progress_); | |
wolenetz
2016/03/05 01:47:43
ok. I see why you have this flag now. I'm fine wit
servolk
2016/03/05 01:56:19
Acknowledged.
| |
484 | 489 |
485 if (!audio_config.IsValidConfig() && !video_config.IsValidConfig()) { | 490 if (!audio_config.IsValidConfig() && !video_config.IsValidConfig()) { |
486 DVLOG(1) << "OnNewConfigs() : Audio & video config are not valid!"; | 491 DVLOG(1) << "OnNewConfigs() : Audio & video config are not valid!"; |
487 return false; | 492 return false; |
488 } | 493 } |
489 | 494 |
490 // Signal an error if we get configuration info for stream types that weren't | 495 // Signal an error if we get configuration info for stream types that weren't |
491 // specified in AddId() or more configs after a stream is initialized. | 496 // specified in AddId() or more configs after a stream is initialized. |
492 if (allow_audio != audio_config.IsValidConfig()) { | 497 if (allow_audio != audio_config.IsValidConfig()) { |
493 MEDIA_LOG(ERROR, media_log_) | 498 MEDIA_LOG(ERROR, media_log_) |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
636 << " does not match old one."; | 641 << " does not match old one."; |
637 break; | 642 break; |
638 } | 643 } |
639 } | 644 } |
640 } | 645 } |
641 } | 646 } |
642 | 647 |
643 frame_processor_->SetAllTrackBuffersNeedRandomAccessPoint(); | 648 frame_processor_->SetAllTrackBuffersNeedRandomAccessPoint(); |
644 | 649 |
645 DVLOG(1) << "OnNewConfigs() : " << (success ? "success" : "failed"); | 650 DVLOG(1) << "OnNewConfigs() : " << (success ? "success" : "failed"); |
646 if (success) | 651 if (success) { |
647 init_segment_received_cb_.Run(*media_tracks_); | 652 DCHECK(!init_segment_received_cb_.is_null()); |
653 init_segment_received_cb_.Run(std::move(media_tracks_)); | |
654 } | |
648 | 655 |
649 return success; | 656 return success; |
650 } | 657 } |
651 | 658 |
652 void MediaSourceState::OnNewMediaSegment() { | 659 void MediaSourceState::OnNewMediaSegment() { |
653 DVLOG(2) << "OnNewMediaSegment()"; | 660 DVLOG(2) << "OnNewMediaSegment()"; |
654 parsing_media_segment_ = true; | 661 parsing_media_segment_ = true; |
655 media_segment_contained_audio_frame_ = false; | 662 media_segment_contained_audio_frame_ = false; |
656 media_segment_contained_video_frame_ = false; | 663 media_segment_contained_video_frame_ = false; |
657 } | 664 } |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
721 return true; | 728 return true; |
722 } | 729 } |
723 | 730 |
724 void MediaSourceState::OnSourceInitDone( | 731 void MediaSourceState::OnSourceInitDone( |
725 const StreamParser::InitParameters& params) { | 732 const StreamParser::InitParameters& params) { |
726 auto_update_timestamp_offset_ = params.auto_update_timestamp_offset; | 733 auto_update_timestamp_offset_ = params.auto_update_timestamp_offset; |
727 base::ResetAndReturn(&init_cb_).Run(params); | 734 base::ResetAndReturn(&init_cb_).Run(params); |
728 } | 735 } |
729 | 736 |
730 } // namespace media | 737 } // namespace media |
OLD | NEW |