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 640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
651 | 651 |
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 |
wolenetz
2015/09/15 23:19:22
w.r.t. my comment on l.775: maybe do something lik
| |
662 // Try removing data from the front of the SourceBuffer up to |media_time| | 662 // Try removing data from the front of the SourceBuffer up to |media_time| |
663 // position. | 663 // position. |
664 if (bytes_freed < bytes_to_free) { | 664 if (bytes_freed < bytes_to_free) { |
665 size_t front = FreeBuffers(bytes_to_free - bytes_freed, media_time, false); | 665 size_t front = FreeBuffers(bytes_to_free - bytes_freed, media_time, false); |
666 DVLOG(3) << __FUNCTION__ << " Removed " << front << " bytes from the front" | 666 DVLOG(3) << __FUNCTION__ << " Removed " << front << " bytes from the front" |
667 << " ranges_=" << RangesToString(ranges_); | 667 << " ranges_=" << RangesToString(ranges_); |
668 bytes_freed += front; | 668 bytes_freed += front; |
669 } | 669 } |
670 | 670 |
671 // Try removing data from the back of the SourceBuffer, until we reach the | 671 // Try removing data from the back of the SourceBuffer, until we reach the |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
752 "total bytes to free", total_bytes_to_free, | 752 "total bytes to free", total_bytes_to_free, |
753 "reverse direction", reverse_direction); | 753 "reverse direction", reverse_direction); |
754 | 754 |
755 DCHECK_GT(total_bytes_to_free, 0u); | 755 DCHECK_GT(total_bytes_to_free, 0u); |
756 size_t bytes_freed = 0; | 756 size_t bytes_freed = 0; |
757 | 757 |
758 // This range will save the last GOP appended to |range_for_next_append_| | 758 // This range will save the last GOP appended to |range_for_next_append_| |
759 // if the buffers surrounding it get deleted during garbage collection. | 759 // if the buffers surrounding it get deleted during garbage collection. |
760 SourceBufferRange* new_range_for_append = NULL; | 760 SourceBufferRange* new_range_for_append = NULL; |
761 | 761 |
762 // If media_time is before the first buffered range, that means we are in the | |
wolenetz
2015/09/15 22:36:13
nit:s/media_time/|media_time|/
servolk
2015/09/16 00:28:08
Done.
| |
763 // process of seeking back in the stream. HTMLMediaElement adjusts media_time | |
wolenetz
2015/09/15 22:36:13
nit: s/HTMLMediaElement/caller/
nit: s/media_time/
servolk
2015/09/16 00:28:08
Done.
| |
764 // as soon as seeking is started. In those cases we can allow garbage | |
765 // collection to delete data from the front, since the player will append new | |
766 // data at the seek target position. | |
767 if (!ranges_.empty() && | |
768 ranges_.front()->GetStartTimestamp() > media_time) { | |
769 DVLOG(5) << "media_time (" << media_time.InSecondsF() << ") is earlier than" | |
770 << " start of buffered data (" | |
771 << ranges_.front()->GetStartTimestamp().InSecondsF() | |
772 << "), using media_time=" | |
773 << ranges_.front()->GetEndTimestamp().InSecondsF(); | |
774 media_time = ranges_.front()->GetEndTimestamp(); | |
wolenetz
2015/09/15 22:36:12
nit: While this looks like it would work, could th
servolk
2015/09/16 00:28:08
Acknowledged. I've reworked this as we discussed o
| |
775 } | |
wolenetz
2015/09/15 23:04:51
As discussed further in chat, it seems we should a
servolk
2015/09/16 00:28:08
Done in the lastest patchset.
| |
776 | |
wolenetz
2015/09/15 22:36:12
Please add a unit test that verifies this works as
servolk
2015/09/16 00:28:08
I've added a ChunkDemuxer unit tests that verifies
| |
762 while (!ranges_.empty() && bytes_freed < total_bytes_to_free) { | 777 while (!ranges_.empty() && bytes_freed < total_bytes_to_free) { |
763 SourceBufferRange* current_range = NULL; | 778 SourceBufferRange* current_range = NULL; |
764 BufferQueue buffers; | 779 BufferQueue buffers; |
765 size_t bytes_deleted = 0; | 780 size_t bytes_deleted = 0; |
766 | 781 |
767 if (reverse_direction) { | 782 if (reverse_direction) { |
768 current_range = ranges_.back(); | 783 current_range = ranges_.back(); |
769 DVLOG(5) << "current_range=" << RangeToString(*current_range); | 784 DVLOG(5) << "current_range=" << RangeToString(*current_range); |
770 if (current_range->LastGOPContainsNextBufferPosition()) { | 785 if (current_range->LastGOPContainsNextBufferPosition()) { |
771 DCHECK_EQ(current_range, selected_range_); | 786 DCHECK_EQ(current_range, selected_range_); |
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1731 return false; | 1746 return false; |
1732 | 1747 |
1733 DCHECK_NE(have_splice_buffers, have_preroll_buffer); | 1748 DCHECK_NE(have_splice_buffers, have_preroll_buffer); |
1734 splice_buffers_index_ = 0; | 1749 splice_buffers_index_ = 0; |
1735 pending_buffer_.swap(*out_buffer); | 1750 pending_buffer_.swap(*out_buffer); |
1736 pending_buffers_complete_ = false; | 1751 pending_buffers_complete_ = false; |
1737 return true; | 1752 return true; |
1738 } | 1753 } |
1739 | 1754 |
1740 } // namespace media | 1755 } // namespace media |
OLD | NEW |