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/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 641 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 652 // If the last append happened before the current playback position | 652 // If the last append happened before the current playback position |
| 653 // |media_time|, then JS player is probably preparing to seek back and we | 653 // |media_time|, then JS player is probably preparing to seek back and we |
| 654 // should try to preserve all most recently appended data (which is in | 654 // should try to preserve all most recently appended data (which is in |
| 655 // range_for_next_append_) from being removed by GC (see crbug.com/440173) | 655 // range_for_next_append_) from being removed by GC (see crbug.com/440173) |
| 656 if (range_for_next_append_ != ranges_.end()) { | 656 if (range_for_next_append_ != ranges_.end()) { |
| 657 DCHECK((*range_for_next_append_)->GetStartTimestamp() <= media_time); | 657 DCHECK((*range_for_next_append_)->GetStartTimestamp() <= media_time); |
| 658 media_time = (*range_for_next_append_)->GetStartTimestamp(); | 658 media_time = (*range_for_next_append_)->GetStartTimestamp(); |
| 659 } | 659 } |
| 660 } | 660 } |
| 661 | 661 |
| 662 // Try removing data from the front of the SourceBuffer up to |media_time| | 662 // If |media_time| is earlier than any of the buffered data, that means we are |
|
wolenetz
2015/09/16 19:25:27
I wonder if we should make this even more aggressi
| |
| 663 // position. | 663 // seeking back in the stream. In that case we should delete as much data as |
| 664 if (bytes_freed < bytes_to_free) { | 664 // possible from the back of the buffered range without evicting the most |
| 665 size_t front = FreeBuffers(bytes_to_free - bytes_freed, media_time, false); | 665 // recently appended chunks, and then, if that's not enough, we can delete |
| 666 DVLOG(3) << __FUNCTION__ << " Removed " << front << " bytes from the front" | 666 // from the front of the buffered ranges greedily, i.e. without trying to save |
| 667 << " ranges_=" << RangesToString(ranges_); | 667 // the previous media playback position, since the player is going to append |
| 668 bytes_freed += front; | 668 // new data to the new seek target next. |
| 669 } | 669 if (!ranges_.empty() && |
| 670 media_time < ranges_.front()->GetStartTimestamp()) { | |
| 671 DVLOG(3) << __FUNCTION__ << " Detected seeking backwards (media_time=" | |
| 672 << media_time.InSecondsF() << "; buffered_start=" | |
| 673 << ranges_.front()->GetStartTimestamp().InSecondsF() | |
| 674 << "), removing data from the back of buffered ranges first"; | |
| 675 if (bytes_freed < bytes_to_free) { | |
| 676 // Remove data from the back, until we reach most recently appended GOP. | |
| 677 size_t back = FreeBuffers(bytes_to_free - bytes_freed, media_time, true); | |
| 678 DVLOG(3) << __FUNCTION__ << " Removed " << back << " bytes from the back" | |
| 679 << " ranges_=" << RangesToString(ranges_); | |
| 680 bytes_freed += back; | |
| 681 } | |
| 670 | 682 |
| 671 // Try removing data from the back of the SourceBuffer, until we reach the | 683 if (bytes_freed < bytes_to_free) { |
| 672 // most recent append position. | 684 // Remove data from the front, removing as much as necessary. |
| 673 if (bytes_freed < bytes_to_free) { | 685 size_t back = FreeBuffers(bytes_to_free - bytes_freed, |
| 674 size_t back = FreeBuffers(bytes_to_free - bytes_freed, media_time, true); | 686 ranges_.back()->GetEndTimestamp(), false); |
| 675 DVLOG(3) << __FUNCTION__ << " Removed " << back << " bytes from the back" | 687 DVLOG(3) << __FUNCTION__ << " Removed " << back << " bytes from the back" |
| 676 << " ranges_=" << RangesToString(ranges_); | 688 << " ranges_=" << RangesToString(ranges_); |
| 677 bytes_freed += back; | 689 bytes_freed += back; |
| 690 } | |
| 691 } else { | |
| 692 // Try removing data from the front of the SourceBuffer up to |media_time| | |
| 693 // position. | |
| 694 if (bytes_freed < bytes_to_free) { | |
| 695 size_t front = | |
| 696 FreeBuffers(bytes_to_free - bytes_freed, media_time, false); | |
| 697 DVLOG(3) << __FUNCTION__ << " Removed " << front << " bytes from the" | |
| 698 << " front. ranges_=" << RangesToString(ranges_); | |
| 699 bytes_freed += front; | |
| 700 } | |
| 701 | |
| 702 // Try removing data from the back of the SourceBuffer, until we reach the | |
| 703 // most recent append position. | |
| 704 if (bytes_freed < bytes_to_free) { | |
| 705 size_t back = FreeBuffers(bytes_to_free - bytes_freed, media_time, true); | |
| 706 DVLOG(3) << __FUNCTION__ << " Removed " << back << " bytes from the back." | |
| 707 << " ranges_=" << RangesToString(ranges_); | |
| 708 bytes_freed += back; | |
| 709 } | |
| 678 } | 710 } |
| 679 | 711 |
| 680 DVLOG(2) << __FUNCTION__ << " " << GetStreamTypeName() << ": After GC" | 712 DVLOG(2) << __FUNCTION__ << " " << GetStreamTypeName() << ": After GC" |
| 681 << " bytes_to_free=" << bytes_to_free | 713 << " bytes_to_free=" << bytes_to_free |
| 682 << " bytes_freed=" << bytes_freed | 714 << " bytes_freed=" << bytes_freed |
| 683 << " ranges_=" << RangesToString(ranges_); | 715 << " ranges_=" << RangesToString(ranges_); |
| 684 | 716 |
| 685 return bytes_freed >= bytes_to_free; | 717 return bytes_freed >= bytes_to_free; |
| 686 } | 718 } |
| 687 | 719 |
| (...skipping 1043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1731 return false; | 1763 return false; |
| 1732 | 1764 |
| 1733 DCHECK_NE(have_splice_buffers, have_preroll_buffer); | 1765 DCHECK_NE(have_splice_buffers, have_preroll_buffer); |
| 1734 splice_buffers_index_ = 0; | 1766 splice_buffers_index_ = 0; |
| 1735 pending_buffer_.swap(*out_buffer); | 1767 pending_buffer_.swap(*out_buffer); |
| 1736 pending_buffers_complete_ = false; | 1768 pending_buffers_complete_ = false; |
| 1737 return true; | 1769 return true; |
| 1738 } | 1770 } |
| 1739 | 1771 |
| 1740 } // namespace media | 1772 } // namespace media |
| OLD | NEW |