| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/chunk_demuxer.h" | 5 #include "media/filters/chunk_demuxer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <list> | 9 #include <list> |
| 10 | 10 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 126 |
| 127 // Aborts the current append sequence and resets the parser. | 127 // Aborts the current append sequence and resets the parser. |
| 128 void Abort(TimeDelta append_window_start, | 128 void Abort(TimeDelta append_window_start, |
| 129 TimeDelta append_window_end, | 129 TimeDelta append_window_end, |
| 130 TimeDelta* timestamp_offset); | 130 TimeDelta* timestamp_offset); |
| 131 | 131 |
| 132 // Calls Remove(|start|, |end|, |duration|) on all | 132 // Calls Remove(|start|, |end|, |duration|) on all |
| 133 // ChunkDemuxerStreams managed by this object. | 133 // ChunkDemuxerStreams managed by this object. |
| 134 void Remove(TimeDelta start, TimeDelta end, TimeDelta duration); | 134 void Remove(TimeDelta start, TimeDelta end, TimeDelta duration); |
| 135 | 135 |
| 136 bool EvictFrames(DecodeTimestamp media_time); |
| 137 |
| 136 // Returns true if currently parsing a media segment, or false otherwise. | 138 // Returns true if currently parsing a media segment, or false otherwise. |
| 137 bool parsing_media_segment() const { return parsing_media_segment_; } | 139 bool parsing_media_segment() const { return parsing_media_segment_; } |
| 138 | 140 |
| 139 // Sets |frame_processor_|'s sequence mode to |sequence_mode|. | 141 // Sets |frame_processor_|'s sequence mode to |sequence_mode|. |
| 140 void SetSequenceMode(bool sequence_mode); | 142 void SetSequenceMode(bool sequence_mode); |
| 141 | 143 |
| 142 // Signals the coded frame processor to update its group start timestamp to be | 144 // Signals the coded frame processor to update its group start timestamp to be |
| 143 // |timestamp_offset| if it is in sequence append mode. | 145 // |timestamp_offset| if it is in sequence append mode. |
| 144 void SetGroupStartTimestampIfInSequenceMode(base::TimeDelta timestamp_offset); | 146 void SetGroupStartTimestampIfInSequenceMode(base::TimeDelta timestamp_offset); |
| 145 | 147 |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 | 370 |
| 369 if (video_) | 371 if (video_) |
| 370 video_->Remove(start, end, duration); | 372 video_->Remove(start, end, duration); |
| 371 | 373 |
| 372 for (TextStreamMap::iterator itr = text_stream_map_.begin(); | 374 for (TextStreamMap::iterator itr = text_stream_map_.begin(); |
| 373 itr != text_stream_map_.end(); ++itr) { | 375 itr != text_stream_map_.end(); ++itr) { |
| 374 itr->second->Remove(start, end, duration); | 376 itr->second->Remove(start, end, duration); |
| 375 } | 377 } |
| 376 } | 378 } |
| 377 | 379 |
| 380 bool SourceState::EvictFrames(DecodeTimestamp media_time) { |
| 381 bool success = true; |
| 382 |
| 383 if(audio_) |
| 384 success = audio_->EvictFrames(media_time) && success; |
| 385 |
| 386 if (video_) |
| 387 success = video_->EvictFrames(media_time) && success; |
| 388 |
| 389 for (TextStreamMap::iterator itr = text_stream_map_.begin(); |
| 390 itr != text_stream_map_.end(); ++itr) { |
| 391 success = itr->second->EvictFrames(media_time) && success; |
| 392 } |
| 393 |
| 394 return success; |
| 395 } |
| 396 |
| 378 Ranges<TimeDelta> SourceState::GetBufferedRanges(TimeDelta duration, | 397 Ranges<TimeDelta> SourceState::GetBufferedRanges(TimeDelta duration, |
| 379 bool ended) const { | 398 bool ended) const { |
| 380 // TODO(acolwell): When we start allowing disabled tracks we'll need to update | 399 // TODO(acolwell): When we start allowing disabled tracks we'll need to update |
| 381 // this code to only add ranges from active tracks. | 400 // this code to only add ranges from active tracks. |
| 382 RangesList ranges_list; | 401 RangesList ranges_list; |
| 383 if (audio_) | 402 if (audio_) |
| 384 ranges_list.push_back(audio_->GetBufferedRanges(duration)); | 403 ranges_list.push_back(audio_->GetBufferedRanges(duration)); |
| 385 | 404 |
| 386 if (video_) | 405 if (video_) |
| 387 ranges_list.push_back(video_->GetBufferedRanges(duration)); | 406 ranges_list.push_back(video_->GetBufferedRanges(duration)); |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 876 | 895 |
| 877 return true; | 896 return true; |
| 878 } | 897 } |
| 879 | 898 |
| 880 void ChunkDemuxerStream::Remove(TimeDelta start, TimeDelta end, | 899 void ChunkDemuxerStream::Remove(TimeDelta start, TimeDelta end, |
| 881 TimeDelta duration) { | 900 TimeDelta duration) { |
| 882 base::AutoLock auto_lock(lock_); | 901 base::AutoLock auto_lock(lock_); |
| 883 stream_->Remove(start, end, duration); | 902 stream_->Remove(start, end, duration); |
| 884 } | 903 } |
| 885 | 904 |
| 905 bool ChunkDemuxerStream::EvictFrames(DecodeTimestamp media_time) { |
| 906 base::AutoLock auto_lock(lock_); |
| 907 return stream_->GarbageCollectIfNeeded(media_time); |
| 908 } |
| 909 |
| 886 void ChunkDemuxerStream::OnSetDuration(TimeDelta duration) { | 910 void ChunkDemuxerStream::OnSetDuration(TimeDelta duration) { |
| 887 base::AutoLock auto_lock(lock_); | 911 base::AutoLock auto_lock(lock_); |
| 888 stream_->OnSetDuration(duration); | 912 stream_->OnSetDuration(duration); |
| 889 } | 913 } |
| 890 | 914 |
| 891 Ranges<TimeDelta> ChunkDemuxerStream::GetBufferedRanges( | 915 Ranges<TimeDelta> ChunkDemuxerStream::GetBufferedRanges( |
| 892 TimeDelta duration) const { | 916 TimeDelta duration) const { |
| 893 base::AutoLock auto_lock(lock_); | 917 base::AutoLock auto_lock(lock_); |
| 894 | 918 |
| 895 if (type_ == TEXT) { | 919 if (type_ == TEXT) { |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 log_cb_(log_cb), | 1141 log_cb_(log_cb), |
| 1118 media_log_(media_log), | 1142 media_log_(media_log), |
| 1119 duration_(kNoTimestamp()), | 1143 duration_(kNoTimestamp()), |
| 1120 user_specified_duration_(-1), | 1144 user_specified_duration_(-1), |
| 1121 liveness_(DemuxerStream::LIVENESS_UNKNOWN), | 1145 liveness_(DemuxerStream::LIVENESS_UNKNOWN), |
| 1122 splice_frames_enabled_(splice_frames_enabled) { | 1146 splice_frames_enabled_(splice_frames_enabled) { |
| 1123 DCHECK(!open_cb_.is_null()); | 1147 DCHECK(!open_cb_.is_null()); |
| 1124 DCHECK(!encrypted_media_init_data_cb_.is_null()); | 1148 DCHECK(!encrypted_media_init_data_cb_.is_null()); |
| 1125 } | 1149 } |
| 1126 | 1150 |
| 1151 void ChunkDemuxer::SetMediaTimeProvider( |
| 1152 const base::Callback<base::TimeDelta(void)>& get_media_time_cb) { |
| 1153 get_media_time_cb_ = get_media_time_cb; |
| 1154 } |
| 1155 |
| 1127 void ChunkDemuxer::Initialize( | 1156 void ChunkDemuxer::Initialize( |
| 1128 DemuxerHost* host, | 1157 DemuxerHost* host, |
| 1129 const PipelineStatusCB& cb, | 1158 const PipelineStatusCB& cb, |
| 1130 bool enable_text_tracks) { | 1159 bool enable_text_tracks) { |
| 1131 DVLOG(1) << "Init()"; | 1160 DVLOG(1) << "Init()"; |
| 1132 | 1161 |
| 1133 base::AutoLock auto_lock(lock_); | 1162 base::AutoLock auto_lock(lock_); |
| 1134 | 1163 |
| 1135 init_cb_ = BindToCurrentLoop(cb); | 1164 init_cb_ = BindToCurrentLoop(cb); |
| 1136 if (state_ == SHUTDOWN) { | 1165 if (state_ == SHUTDOWN) { |
| (...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1309 Ranges<TimeDelta> ChunkDemuxer::GetBufferedRanges(const std::string& id) const { | 1338 Ranges<TimeDelta> ChunkDemuxer::GetBufferedRanges(const std::string& id) const { |
| 1310 base::AutoLock auto_lock(lock_); | 1339 base::AutoLock auto_lock(lock_); |
| 1311 DCHECK(!id.empty()); | 1340 DCHECK(!id.empty()); |
| 1312 | 1341 |
| 1313 SourceStateMap::const_iterator itr = source_state_map_.find(id); | 1342 SourceStateMap::const_iterator itr = source_state_map_.find(id); |
| 1314 | 1343 |
| 1315 DCHECK(itr != source_state_map_.end()); | 1344 DCHECK(itr != source_state_map_.end()); |
| 1316 return itr->second->GetBufferedRanges(duration_, state_ == ENDED); | 1345 return itr->second->GetBufferedRanges(duration_, state_ == ENDED); |
| 1317 } | 1346 } |
| 1318 | 1347 |
| 1348 bool ChunkDemuxer::EvictFrames() { |
| 1349 DecodeTimestamp current_media_time; |
| 1350 if (!get_media_time_cb_.is_null()) { |
| 1351 current_media_time = |
| 1352 DecodeTimestamp::FromPresentationTime(get_media_time_cb_.Run()); |
| 1353 } else { |
| 1354 current_media_time = kNoDecodeTimestamp(); |
| 1355 } |
| 1356 |
| 1357 bool success = true; |
| 1358 for (SourceStateMap::iterator itr = source_state_map_.begin(); |
| 1359 itr != source_state_map_.end(); ++itr) { |
| 1360 success = itr->second->EvictFrames(current_media_time) && success; |
| 1361 } |
| 1362 return success; |
| 1363 } |
| 1364 |
| 1319 void ChunkDemuxer::AppendData( | 1365 void ChunkDemuxer::AppendData( |
| 1320 const std::string& id, | 1366 const std::string& id, |
| 1321 const uint8* data, | 1367 const uint8* data, |
| 1322 size_t length, | 1368 size_t length, |
| 1323 TimeDelta append_window_start, | 1369 TimeDelta append_window_start, |
| 1324 TimeDelta append_window_end, | 1370 TimeDelta append_window_end, |
| 1325 TimeDelta* timestamp_offset, | 1371 TimeDelta* timestamp_offset, |
| 1326 const InitSegmentReceivedCB& init_segment_received_cb) { | 1372 const InitSegmentReceivedCB& init_segment_received_cb) { |
| 1327 DVLOG(1) << "AppendData(" << id << ", " << length << ")"; | 1373 DVLOG(1) << "AppendData(" << id << ", " << length << ")"; |
| 1328 | 1374 |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1852 } | 1898 } |
| 1853 | 1899 |
| 1854 void ChunkDemuxer::ShutdownAllStreams() { | 1900 void ChunkDemuxer::ShutdownAllStreams() { |
| 1855 for (SourceStateMap::iterator itr = source_state_map_.begin(); | 1901 for (SourceStateMap::iterator itr = source_state_map_.begin(); |
| 1856 itr != source_state_map_.end(); ++itr) { | 1902 itr != source_state_map_.end(); ++itr) { |
| 1857 itr->second->Shutdown(); | 1903 itr->second->Shutdown(); |
| 1858 } | 1904 } |
| 1859 } | 1905 } |
| 1860 | 1906 |
| 1861 } // namespace media | 1907 } // namespace media |
| OLD | NEW |