Chromium Code Reviews| 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 <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 112 | 112 |
| 113 return true; | 113 return true; |
| 114 } | 114 } |
| 115 | 115 |
| 116 void ChunkDemuxerStream::Remove(TimeDelta start, TimeDelta end, | 116 void ChunkDemuxerStream::Remove(TimeDelta start, TimeDelta end, |
| 117 TimeDelta duration) { | 117 TimeDelta duration) { |
| 118 base::AutoLock auto_lock(lock_); | 118 base::AutoLock auto_lock(lock_); |
| 119 stream_->Remove(start, end, duration); | 119 stream_->Remove(start, end, duration); |
| 120 } | 120 } |
| 121 | 121 |
| 122 bool ChunkDemuxerStream::EvictCodedFrames(DecodeTimestamp media_time, | 122 bool ChunkDemuxerStream::EvictCodedFrames(base::TimeDelta media_time, |
| 123 size_t newDataSize) { | 123 size_t newDataSize) { |
| 124 base::AutoLock auto_lock(lock_); | 124 base::AutoLock auto_lock(lock_); |
| 125 return stream_->GarbageCollectIfNeeded(media_time, newDataSize); | 125 |
| 126 // If the stream is disabled, then the renderer is not reading from it and | |
| 127 // thus the read position might be stale. MSE GC algorithm uses the read | |
| 128 // position to determine when to stop removing data from the front of buffered | |
| 129 // ranges, so do a Seek in order to update the read position and allow the GC | |
| 130 // to collect unnecessary data that is earlier than the GOP containing | |
| 131 // |media_time|. | |
| 132 if (!is_enabled_) | |
| 133 stream_->Seek(media_time); | |
|
wolenetz
2017/04/20 18:30:18
Interesting. I think this will work. The comment d
wolenetz
2017/04/20 19:01:09
Hmm. Actually I like the way you did this better,
servolk
2017/04/20 20:12:32
Thanks for diving deep into this with me, Matt :)
| |
| 134 | |
| 135 // Note: The direct conversion from PTS to DTS is safe here, since we don't | |
| 136 // need to know currentTime precisely for GC. GC only needs to know which GOP | |
| 137 // currentTime points to. | |
| 138 DecodeTimestamp media_time_dts = | |
| 139 DecodeTimestamp::FromPresentationTime(media_time); | |
| 140 return stream_->GarbageCollectIfNeeded(media_time_dts, newDataSize); | |
| 126 } | 141 } |
| 127 | 142 |
| 128 void ChunkDemuxerStream::OnMemoryPressure( | 143 void ChunkDemuxerStream::OnMemoryPressure( |
| 129 DecodeTimestamp media_time, | 144 DecodeTimestamp media_time, |
| 130 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level, | 145 base::MemoryPressureListener::MemoryPressureLevel memory_pressure_level, |
| 131 bool force_instant_gc) { | 146 bool force_instant_gc) { |
| 132 base::AutoLock auto_lock(lock_); | 147 base::AutoLock auto_lock(lock_); |
| 133 return stream_->OnMemoryPressure(media_time, memory_pressure_level, | 148 return stream_->OnMemoryPressure(media_time, memory_pressure_level, |
| 134 force_instant_gc); | 149 force_instant_gc); |
| 135 } | 150 } |
| (...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 779 } | 794 } |
| 780 | 795 |
| 781 bool ChunkDemuxer::EvictCodedFrames(const std::string& id, | 796 bool ChunkDemuxer::EvictCodedFrames(const std::string& id, |
| 782 base::TimeDelta currentMediaTime, | 797 base::TimeDelta currentMediaTime, |
| 783 size_t newDataSize) { | 798 size_t newDataSize) { |
| 784 DVLOG(1) << __func__ << "(" << id << ")" | 799 DVLOG(1) << __func__ << "(" << id << ")" |
| 785 << " media_time=" << currentMediaTime.InSecondsF() | 800 << " media_time=" << currentMediaTime.InSecondsF() |
| 786 << " newDataSize=" << newDataSize; | 801 << " newDataSize=" << newDataSize; |
| 787 base::AutoLock auto_lock(lock_); | 802 base::AutoLock auto_lock(lock_); |
| 788 | 803 |
| 789 // Note: The direct conversion from PTS to DTS is safe here, since we don't | |
| 790 // need to know currentTime precisely for GC. GC only needs to know which GOP | |
| 791 // currentTime points to. | |
| 792 DecodeTimestamp media_time_dts = | |
| 793 DecodeTimestamp::FromPresentationTime(currentMediaTime); | |
| 794 | |
| 795 DCHECK(!id.empty()); | 804 DCHECK(!id.empty()); |
| 796 auto itr = source_state_map_.find(id); | 805 auto itr = source_state_map_.find(id); |
| 797 if (itr == source_state_map_.end()) { | 806 if (itr == source_state_map_.end()) { |
| 798 LOG(WARNING) << __func__ << " stream " << id << " not found"; | 807 LOG(WARNING) << __func__ << " stream " << id << " not found"; |
| 799 return false; | 808 return false; |
| 800 } | 809 } |
| 801 return itr->second->EvictCodedFrames(media_time_dts, newDataSize); | 810 return itr->second->EvictCodedFrames(currentMediaTime, newDataSize); |
| 802 } | 811 } |
| 803 | 812 |
| 804 bool ChunkDemuxer::AppendData(const std::string& id, | 813 bool ChunkDemuxer::AppendData(const std::string& id, |
| 805 const uint8_t* data, | 814 const uint8_t* data, |
| 806 size_t length, | 815 size_t length, |
| 807 TimeDelta append_window_start, | 816 TimeDelta append_window_start, |
| 808 TimeDelta append_window_end, | 817 TimeDelta append_window_end, |
| 809 TimeDelta* timestamp_offset) { | 818 TimeDelta* timestamp_offset) { |
| 810 DVLOG(1) << "AppendData(" << id << ", " << length << ")"; | 819 DVLOG(1) << "AppendData(" << id << ", " << length << ")"; |
| 811 | 820 |
| (...skipping 538 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1350 } | 1359 } |
| 1351 | 1360 |
| 1352 void ChunkDemuxer::ShutdownAllStreams() { | 1361 void ChunkDemuxer::ShutdownAllStreams() { |
| 1353 for (auto itr = source_state_map_.begin(); itr != source_state_map_.end(); | 1362 for (auto itr = source_state_map_.begin(); itr != source_state_map_.end(); |
| 1354 ++itr) { | 1363 ++itr) { |
| 1355 itr->second->Shutdown(); | 1364 itr->second->Shutdown(); |
| 1356 } | 1365 } |
| 1357 } | 1366 } |
| 1358 | 1367 |
| 1359 } // namespace media | 1368 } // namespace media |
| OLD | NEW |