Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(207)

Side by Side Diff: media/filters/source_buffer_stream.cc

Issue 2605993002: Experiment with more aggressive MSE GC on memory pressure (Closed)
Patch Set: Allow MSE GC to happen in EOS state now Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/source_buffer_stream.h" 5 #include "media/filters/source_buffer_stream.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <sstream> 9 #include <sstream>
10 #include <string> 10 #include <string>
(...skipping 675 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 } 686 }
687 687
688 void SourceBufferStream::SetConfigIds(const BufferQueue& buffers) { 688 void SourceBufferStream::SetConfigIds(const BufferQueue& buffers) {
689 for (BufferQueue::const_iterator itr = buffers.begin(); 689 for (BufferQueue::const_iterator itr = buffers.begin();
690 itr != buffers.end(); ++itr) { 690 itr != buffers.end(); ++itr) {
691 (*itr)->SetConfigId(append_config_index_); 691 (*itr)->SetConfigId(append_config_index_);
692 } 692 }
693 } 693 }
694 694
695 bool SourceBufferStream::GarbageCollectIfNeeded(DecodeTimestamp media_time, 695 bool SourceBufferStream::GarbageCollectIfNeeded(DecodeTimestamp media_time,
696 size_t newDataSize) { 696 size_t eviction_size,
697 size_t* bytes_released) {
697 DCHECK(media_time != kNoDecodeTimestamp()); 698 DCHECK(media_time != kNoDecodeTimestamp());
698 // Garbage collection should only happen before/during appending new data, 699
699 // which should not happen in end-of-stream state. 700 if (bytes_released)
700 DCHECK(!end_of_stream_); 701 *bytes_released = 0;
702
701 // Compute size of |ranges_|. 703 // Compute size of |ranges_|.
702 size_t ranges_size = GetBufferedSize(); 704 size_t ranges_size = GetBufferedSize();
703 705
704 // Sanity and overflow checks 706 // Sanity and overflow checks
705 if ((newDataSize > memory_limit_) || 707 if ((eviction_size > memory_limit_) ||
706 (ranges_size + newDataSize < ranges_size)) { 708 (ranges_size + eviction_size < ranges_size)) {
707 LIMITED_MEDIA_LOG(DEBUG, media_log_, num_garbage_collect_algorithm_logs_, 709 LIMITED_MEDIA_LOG(DEBUG, media_log_, num_garbage_collect_algorithm_logs_,
708 kMaxGarbageCollectAlgorithmWarningLogs) 710 kMaxGarbageCollectAlgorithmWarningLogs)
709 << GetStreamTypeName() << " stream: " 711 << GetStreamTypeName() << " stream: " << __func__
710 << "new append of newDataSize=" << newDataSize 712 << " eviction_size=" << eviction_size
711 << " bytes exceeds memory_limit_=" << memory_limit_ 713 << " bytes exceeds memory_limit_=" << memory_limit_
712 << ", currently buffered ranges_size=" << ranges_size; 714 << ", currently buffered ranges_size=" << ranges_size;
713 return false; 715 return false;
714 } 716 }
715 717
716 // Return if we're under or at the memory limit. 718 // Return if we're under or at the memory limit.
717 if (ranges_size + newDataSize <= memory_limit_) 719 if (ranges_size + eviction_size <= memory_limit_)
718 return true; 720 return true;
719 721
720 size_t bytes_to_free = ranges_size + newDataSize - memory_limit_; 722 size_t bytes_to_free = ranges_size + eviction_size - memory_limit_;
721 723
722 DVLOG(2) << __func__ << " " << GetStreamTypeName() 724 DVLOG(2) << __func__ << " " << GetStreamTypeName()
723 << ": Before GC media_time=" << media_time.InSecondsF() 725 << ": Before GC media_time=" << media_time.InSecondsF()
724 << " ranges_=" << RangesToString(ranges_) 726 << " ranges_=" << RangesToString(ranges_)
725 << " seek_pending_=" << seek_pending_ 727 << " seek_pending_=" << seek_pending_
726 << " ranges_size=" << ranges_size << " newDataSize=" << newDataSize 728 << " ranges_size=" << ranges_size
729 << " eviction_size=" << eviction_size
727 << " memory_limit_=" << memory_limit_ 730 << " memory_limit_=" << memory_limit_
728 << " last_appended_buffer_timestamp_=" 731 << " last_appended_buffer_timestamp_="
729 << last_appended_buffer_timestamp_.InSecondsF(); 732 << last_appended_buffer_timestamp_.InSecondsF();
730 733
731 if (selected_range_ && !seek_pending_ && 734 if (selected_range_ && !seek_pending_ &&
732 media_time > selected_range_->GetBufferedEndTimestamp()) { 735 media_time > selected_range_->GetBufferedEndTimestamp()) {
733 // Strictly speaking |media_time| (taken from HTMLMediaElement::currentTime) 736 // Strictly speaking |media_time| (taken from HTMLMediaElement::currentTime)
734 // should always be in the buffered ranges, but media::Pipeline uses audio 737 // should always be in the buffered ranges, but media::Pipeline uses audio
735 // stream as the main time source, when audio is present. 738 // stream as the main time source, when audio is present.
736 // In cases when audio and video streams have different buffered ranges, the 739 // In cases when audio and video streams have different buffered ranges, the
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
815 818
816 // Try removing data from the front of the SourceBuffer up to |media_time| 819 // Try removing data from the front of the SourceBuffer up to |media_time|
817 // position. 820 // position.
818 if (bytes_freed < bytes_to_free) { 821 if (bytes_freed < bytes_to_free) {
819 size_t front = FreeBuffers(bytes_to_free - bytes_freed, media_time, false); 822 size_t front = FreeBuffers(bytes_to_free - bytes_freed, media_time, false);
820 DVLOG(3) << __func__ << " Removed " << front 823 DVLOG(3) << __func__ << " Removed " << front
821 << " bytes from the front. ranges_=" << RangesToString(ranges_); 824 << " bytes from the front. ranges_=" << RangesToString(ranges_);
822 bytes_freed += front; 825 bytes_freed += front;
823 } 826 }
824 827
825 // Try removing data from the back of the SourceBuffer, until we reach the 828 // Try removing data from the back of the SourceBuffer, until we reach the
chcunningham 2017/01/12 22:31:25 We may want to avoid removing data from the back i
826 // most recent append position. 829 // most recent append position.
827 if (bytes_freed < bytes_to_free) { 830 if (bytes_freed < bytes_to_free) {
828 size_t back = FreeBuffers(bytes_to_free - bytes_freed, media_time, true); 831 size_t back = FreeBuffers(bytes_to_free - bytes_freed, media_time, true);
829 DVLOG(3) << __func__ << " Removed " << back 832 DVLOG(3) << __func__ << " Removed " << back
830 << " bytes from the back. ranges_=" << RangesToString(ranges_); 833 << " bytes from the back. ranges_=" << RangesToString(ranges_);
831 bytes_freed += back; 834 bytes_freed += back;
832 } 835 }
833 836
834 DVLOG(2) << __func__ << " " << GetStreamTypeName() 837 DVLOG(2) << __func__ << " " << GetStreamTypeName()
835 << ": After GC bytes_to_free=" << bytes_to_free 838 << ": After GC bytes_to_free=" << bytes_to_free
836 << " bytes_freed=" << bytes_freed 839 << " bytes_freed=" << bytes_freed
837 << " ranges_=" << RangesToString(ranges_); 840 << " ranges_=" << RangesToString(ranges_);
838 841
842 if (bytes_released)
843 *bytes_released = bytes_freed;
844
839 return bytes_freed >= bytes_to_free; 845 return bytes_freed >= bytes_to_free;
840 } 846 }
841 847
842 size_t SourceBufferStream::FreeBuffersAfterLastAppended( 848 size_t SourceBufferStream::FreeBuffersAfterLastAppended(
843 size_t total_bytes_to_free, DecodeTimestamp media_time) { 849 size_t total_bytes_to_free, DecodeTimestamp media_time) {
844 DVLOG(4) << __func__ << " last_appended_buffer_timestamp_=" 850 DVLOG(4) << __func__ << " last_appended_buffer_timestamp_="
845 << last_appended_buffer_timestamp_.InSecondsF() 851 << last_appended_buffer_timestamp_.InSecondsF()
846 << " media_time=" << media_time.InSecondsF(); 852 << " media_time=" << media_time.InSecondsF();
847 853
848 DecodeTimestamp remove_range_start = last_appended_buffer_timestamp_; 854 DecodeTimestamp remove_range_start = last_appended_buffer_timestamp_;
(...skipping 908 matching lines...) Expand 10 before | Expand all | Expand 10 after
1757 1763
1758 if (!have_preroll_buffer) 1764 if (!have_preroll_buffer)
1759 return false; 1765 return false;
1760 1766
1761 pending_buffer_.swap(*out_buffer); 1767 pending_buffer_.swap(*out_buffer);
1762 pending_buffers_complete_ = false; 1768 pending_buffers_complete_ = false;
1763 return true; 1769 return true;
1764 } 1770 }
1765 1771
1766 } // namespace media 1772 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698