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/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 | 10 |
(...skipping 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 DVLOG(3) << __FUNCTION__ << " Removed " << back << " bytes from the back" | 723 DVLOG(3) << __FUNCTION__ << " Removed " << back << " bytes from the back" |
724 << " ranges_=" << RangesToString(ranges_); | 724 << " ranges_=" << RangesToString(ranges_); |
725 bytes_freed += back; | 725 bytes_freed += back; |
726 } | 726 } |
727 | 727 |
728 // If even that wasn't enough, then try greedily deleting from the front, | 728 // If even that wasn't enough, then try greedily deleting from the front, |
729 // that should allow us to remove as much data as necessary to succeed. | 729 // that should allow us to remove as much data as necessary to succeed. |
730 if (bytes_freed < bytes_to_free) { | 730 if (bytes_freed < bytes_to_free) { |
731 size_t front2 = FreeBuffers(bytes_to_free - bytes_freed, | 731 size_t front2 = FreeBuffers(bytes_to_free - bytes_freed, |
732 ranges_.back()->GetEndTimestamp(), false); | 732 ranges_.back()->GetEndTimestamp(), false); |
733 DVLOG(3) << __FUNCTION__ << " Removed " << front << " bytes from the" | 733 DVLOG(3) << __FUNCTION__ << " Removed " << front2 << " bytes from the" |
734 << " front. ranges_=" << RangesToString(ranges_); | 734 << " front. ranges_=" << RangesToString(ranges_); |
735 bytes_freed += front2; | 735 bytes_freed += front2; |
736 } | 736 } |
737 DCHECK(bytes_freed >= bytes_to_free); | 737 DCHECK(bytes_freed >= bytes_to_free); |
738 } | 738 } |
739 | 739 |
740 // Try removing data from the front of the SourceBuffer up to |media_time| | 740 // Try removing data from the front of the SourceBuffer up to |media_time| |
741 // position. | 741 // position. |
742 if (bytes_freed < bytes_to_free) { | 742 if (bytes_freed < bytes_to_free) { |
743 size_t front = FreeBuffers(bytes_to_free - bytes_freed, media_time, false); | 743 size_t front = FreeBuffers(bytes_to_free - bytes_freed, media_time, false); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
848 if (current_range->LastGOPContainsNextBufferPosition()) { | 848 if (current_range->LastGOPContainsNextBufferPosition()) { |
849 DCHECK_EQ(current_range, selected_range_); | 849 DCHECK_EQ(current_range, selected_range_); |
850 DVLOG(5) << "current_range contains next read position, stopping GC"; | 850 DVLOG(5) << "current_range contains next read position, stopping GC"; |
851 break; | 851 break; |
852 } | 852 } |
853 DVLOG(5) << "Deleting GOP from back: " << RangeToString(*current_range); | 853 DVLOG(5) << "Deleting GOP from back: " << RangeToString(*current_range); |
854 bytes_deleted = current_range->DeleteGOPFromBack(&buffers); | 854 bytes_deleted = current_range->DeleteGOPFromBack(&buffers); |
855 } else { | 855 } else { |
856 current_range = ranges_.front(); | 856 current_range = ranges_.front(); |
857 DVLOG(5) << "current_range=" << RangeToString(*current_range); | 857 DVLOG(5) << "current_range=" << RangeToString(*current_range); |
858 if (!current_range->FirstGOPEarlierThanMediaTime(media_time)) { | 858 |
| 859 // FirstGOPEarlierThanMediaTime() is useful here especially if |
| 860 // |seek_pending_| (such that no range contains next buffer |
| 861 // position). |
| 862 // FirstGOPContainsNextBufferPosition() is useful here especially if |
| 863 // |!seek_pending_| to protect against DeleteGOPFromFront() if |
| 864 // FirstGOPEarlierThanMediaTime() was insufficient alone. |
| 865 if (!current_range->FirstGOPEarlierThanMediaTime(media_time) || |
| 866 current_range->FirstGOPContainsNextBufferPosition()) { |
859 // We have removed all data up to the GOP that contains current playback | 867 // We have removed all data up to the GOP that contains current playback |
860 // position, we can't delete any further. | 868 // position, we can't delete any further. |
861 DVLOG(5) << "current_range contains playback position, stopping GC"; | 869 DVLOG(5) << "current_range contains playback position, stopping GC"; |
862 break; | 870 break; |
863 } | 871 } |
864 DVLOG(4) << "Deleting GOP from front: " << RangeToString(*current_range); | 872 DVLOG(4) << "Deleting GOP from front: " << RangeToString(*current_range) |
| 873 << ", media_time: " << media_time.InMicroseconds() |
| 874 << ", current_range->HasNextBufferPosition(): " |
| 875 << current_range->HasNextBufferPosition(); |
865 bytes_deleted = current_range->DeleteGOPFromFront(&buffers); | 876 bytes_deleted = current_range->DeleteGOPFromFront(&buffers); |
866 } | 877 } |
867 | 878 |
868 // Check to see if we've just deleted the GOP that was last appended. | 879 // Check to see if we've just deleted the GOP that was last appended. |
869 DecodeTimestamp end_timestamp = buffers.back()->GetDecodeTimestamp(); | 880 DecodeTimestamp end_timestamp = buffers.back()->GetDecodeTimestamp(); |
870 if (end_timestamp == last_appended_buffer_timestamp_) { | 881 if (end_timestamp == last_appended_buffer_timestamp_) { |
871 DCHECK(last_appended_buffer_timestamp_ != kNoDecodeTimestamp()); | 882 DCHECK(last_appended_buffer_timestamp_ != kNoDecodeTimestamp()); |
872 DCHECK(!new_range_for_append); | 883 DCHECK(!new_range_for_append); |
873 | 884 |
874 // Create a new range containing these buffers. | 885 // Create a new range containing these buffers. |
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1782 return false; | 1793 return false; |
1783 | 1794 |
1784 DCHECK_NE(have_splice_buffers, have_preroll_buffer); | 1795 DCHECK_NE(have_splice_buffers, have_preroll_buffer); |
1785 splice_buffers_index_ = 0; | 1796 splice_buffers_index_ = 0; |
1786 pending_buffer_.swap(*out_buffer); | 1797 pending_buffer_.swap(*out_buffer); |
1787 pending_buffers_complete_ = false; | 1798 pending_buffers_complete_ = false; |
1788 return true; | 1799 return true; |
1789 } | 1800 } |
1790 | 1801 |
1791 } // namespace media | 1802 } // namespace media |
OLD | NEW |