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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 | 124 |
125 // Aborts the current append sequence and resets the parser. | 125 // Aborts the current append sequence and resets the parser. |
126 void Abort(TimeDelta append_window_start, | 126 void Abort(TimeDelta append_window_start, |
127 TimeDelta append_window_end, | 127 TimeDelta append_window_end, |
128 TimeDelta* timestamp_offset); | 128 TimeDelta* timestamp_offset); |
129 | 129 |
130 // Calls Remove(|start|, |end|, |duration|) on all | 130 // Calls Remove(|start|, |end|, |duration|) on all |
131 // ChunkDemuxerStreams managed by this object. | 131 // ChunkDemuxerStreams managed by this object. |
132 void Remove(TimeDelta start, TimeDelta end, TimeDelta duration); | 132 void Remove(TimeDelta start, TimeDelta end, TimeDelta duration); |
133 | 133 |
134 // Attempts to perform garbage collection in SourceBuffers associated with | |
wolenetz
2015/08/12 21:09:57
This comment seems ChunkDemuxer-focused. Move it t
servolk
2015/08/13 00:31:42
Will do
servolk
2015/08/20 02:45:27
Done.
| |
135 // this ChunkDemuxer. Returns true if garbage collection was successful. | |
136 // |media_time| parameter should indicate the current playback position. | |
137 // If it's a valid time value, the garbage collection algorithm will make sure | |
138 // to preserve unconsumed data buffers in the range between last read position | |
139 // and the current playback position. | |
140 bool EvictCodedFrames(DecodeTimestamp media_time); | |
141 | |
134 // Returns true if currently parsing a media segment, or false otherwise. | 142 // Returns true if currently parsing a media segment, or false otherwise. |
135 bool parsing_media_segment() const { return parsing_media_segment_; } | 143 bool parsing_media_segment() const { return parsing_media_segment_; } |
136 | 144 |
137 // Sets |frame_processor_|'s sequence mode to |sequence_mode|. | 145 // Sets |frame_processor_|'s sequence mode to |sequence_mode|. |
138 void SetSequenceMode(bool sequence_mode); | 146 void SetSequenceMode(bool sequence_mode); |
139 | 147 |
140 // Signals the coded frame processor to update its group start timestamp to be | 148 // Signals the coded frame processor to update its group start timestamp to be |
141 // |timestamp_offset| if it is in sequence append mode. | 149 // |timestamp_offset| if it is in sequence append mode. |
142 void SetGroupStartTimestampIfInSequenceMode(base::TimeDelta timestamp_offset); | 150 void SetGroupStartTimestampIfInSequenceMode(base::TimeDelta timestamp_offset); |
143 | 151 |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
362 | 370 |
363 if (video_) | 371 if (video_) |
364 video_->Remove(start, end, duration); | 372 video_->Remove(start, end, duration); |
365 | 373 |
366 for (TextStreamMap::iterator itr = text_stream_map_.begin(); | 374 for (TextStreamMap::iterator itr = text_stream_map_.begin(); |
367 itr != text_stream_map_.end(); ++itr) { | 375 itr != text_stream_map_.end(); ++itr) { |
368 itr->second->Remove(start, end, duration); | 376 itr->second->Remove(start, end, duration); |
369 } | 377 } |
370 } | 378 } |
371 | 379 |
380 bool SourceState::EvictCodedFrames(DecodeTimestamp media_time) { | |
381 bool success = true; | |
382 | |
383 if (audio_) | |
384 success = audio_->EvictCodedFrames(media_time) && success; | |
385 | |
386 if (video_) | |
387 success = video_->EvictCodedFrames(media_time) && success; | |
388 | |
389 for (TextStreamMap::iterator itr = text_stream_map_.begin(); | |
390 itr != text_stream_map_.end(); ++itr) { | |
391 success = itr->second->EvictCodedFrames(media_time) && success; | |
392 } | |
393 | |
394 return success; | |
395 } | |
396 | |
372 Ranges<TimeDelta> SourceState::GetBufferedRanges(TimeDelta duration, | 397 Ranges<TimeDelta> SourceState::GetBufferedRanges(TimeDelta duration, |
373 bool ended) const { | 398 bool ended) const { |
374 // 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 |
375 // this code to only add ranges from active tracks. | 400 // this code to only add ranges from active tracks. |
376 RangesList ranges_list; | 401 RangesList ranges_list; |
377 if (audio_) | 402 if (audio_) |
378 ranges_list.push_back(audio_->GetBufferedRanges(duration)); | 403 ranges_list.push_back(audio_->GetBufferedRanges(duration)); |
379 | 404 |
380 if (video_) | 405 if (video_) |
381 ranges_list.push_back(video_->GetBufferedRanges(duration)); | 406 ranges_list.push_back(video_->GetBufferedRanges(duration)); |
(...skipping 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
872 | 897 |
873 return true; | 898 return true; |
874 } | 899 } |
875 | 900 |
876 void ChunkDemuxerStream::Remove(TimeDelta start, TimeDelta end, | 901 void ChunkDemuxerStream::Remove(TimeDelta start, TimeDelta end, |
877 TimeDelta duration) { | 902 TimeDelta duration) { |
878 base::AutoLock auto_lock(lock_); | 903 base::AutoLock auto_lock(lock_); |
879 stream_->Remove(start, end, duration); | 904 stream_->Remove(start, end, duration); |
880 } | 905 } |
881 | 906 |
907 bool ChunkDemuxerStream::EvictCodedFrames(DecodeTimestamp media_time) { | |
908 base::AutoLock auto_lock(lock_); | |
909 return stream_->GarbageCollectIfNeeded(media_time); | |
910 } | |
911 | |
882 void ChunkDemuxerStream::OnSetDuration(TimeDelta duration) { | 912 void ChunkDemuxerStream::OnSetDuration(TimeDelta duration) { |
883 base::AutoLock auto_lock(lock_); | 913 base::AutoLock auto_lock(lock_); |
884 stream_->OnSetDuration(duration); | 914 stream_->OnSetDuration(duration); |
885 } | 915 } |
886 | 916 |
887 Ranges<TimeDelta> ChunkDemuxerStream::GetBufferedRanges( | 917 Ranges<TimeDelta> ChunkDemuxerStream::GetBufferedRanges( |
888 TimeDelta duration) const { | 918 TimeDelta duration) const { |
889 base::AutoLock auto_lock(lock_); | 919 base::AutoLock auto_lock(lock_); |
890 | 920 |
891 if (type_ == TEXT) { | 921 if (type_ == TEXT) { |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1314 Ranges<TimeDelta> ChunkDemuxer::GetBufferedRanges(const std::string& id) const { | 1344 Ranges<TimeDelta> ChunkDemuxer::GetBufferedRanges(const std::string& id) const { |
1315 base::AutoLock auto_lock(lock_); | 1345 base::AutoLock auto_lock(lock_); |
1316 DCHECK(!id.empty()); | 1346 DCHECK(!id.empty()); |
1317 | 1347 |
1318 SourceStateMap::const_iterator itr = source_state_map_.find(id); | 1348 SourceStateMap::const_iterator itr = source_state_map_.find(id); |
1319 | 1349 |
1320 DCHECK(itr != source_state_map_.end()); | 1350 DCHECK(itr != source_state_map_.end()); |
1321 return itr->second->GetBufferedRanges(duration_, state_ == ENDED); | 1351 return itr->second->GetBufferedRanges(duration_, state_ == ENDED); |
1322 } | 1352 } |
1323 | 1353 |
1354 bool ChunkDemuxer::EvictCodedFrames(base::TimeDelta currentMediaTime) { | |
1355 DVLOG(1) << __FUNCTION__ << " media_time=" << currentMediaTime.InSecondsF(); | |
1356 base::AutoLock auto_lock(lock_); | |
1357 | |
1358 // Note: The direct conversion from PTS to DTS is safe here, since we don't | |
1359 // need to know currentTime precisely for GC. GC only needs to know which GOP | |
1360 // currentTime points to. | |
1361 DecodeTimestamp media_time_dts = | |
1362 DecodeTimestamp::FromPresentationTime(currentMediaTime); | |
1363 | |
1364 bool success = true; | |
1365 for (SourceStateMap::iterator itr = source_state_map_.begin(); | |
1366 itr != source_state_map_.end(); ++itr) { | |
1367 success = itr->second->EvictCodedFrames(media_time_dts) && success; | |
1368 } | |
1369 return success; | |
1370 } | |
1371 | |
1324 void ChunkDemuxer::AppendData( | 1372 void ChunkDemuxer::AppendData( |
1325 const std::string& id, | 1373 const std::string& id, |
1326 const uint8* data, | 1374 const uint8* data, |
1327 size_t length, | 1375 size_t length, |
1328 TimeDelta append_window_start, | 1376 TimeDelta append_window_start, |
1329 TimeDelta append_window_end, | 1377 TimeDelta append_window_end, |
1330 TimeDelta* timestamp_offset, | 1378 TimeDelta* timestamp_offset, |
1331 const InitSegmentReceivedCB& init_segment_received_cb) { | 1379 const InitSegmentReceivedCB& init_segment_received_cb) { |
1332 DVLOG(1) << "AppendData(" << id << ", " << length << ")"; | 1380 DVLOG(1) << "AppendData(" << id << ", " << length << ")"; |
1333 | 1381 |
(...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1834 } | 1882 } |
1835 | 1883 |
1836 void ChunkDemuxer::ShutdownAllStreams() { | 1884 void ChunkDemuxer::ShutdownAllStreams() { |
1837 for (SourceStateMap::iterator itr = source_state_map_.begin(); | 1885 for (SourceStateMap::iterator itr = source_state_map_.begin(); |
1838 itr != source_state_map_.end(); ++itr) { | 1886 itr != source_state_map_.end(); ++itr) { |
1839 itr->second->Shutdown(); | 1887 itr->second->Shutdown(); |
1840 } | 1888 } |
1841 } | 1889 } |
1842 | 1890 |
1843 } // namespace media | 1891 } // namespace media |
OLD | NEW |