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 1582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1593 seek_timestamp); | 1593 seek_timestamp); |
| 1594 } | 1594 } |
| 1595 | 1595 |
| 1596 DecodeTimestamp SourceBufferStream::FindNewSelectedRangeSeekTimestamp( | 1596 DecodeTimestamp SourceBufferStream::FindNewSelectedRangeSeekTimestamp( |
| 1597 const DecodeTimestamp start_timestamp) { | 1597 const DecodeTimestamp start_timestamp) { |
| 1598 DCHECK(start_timestamp != kNoDecodeTimestamp()); | 1598 DCHECK(start_timestamp != kNoDecodeTimestamp()); |
| 1599 DCHECK(start_timestamp >= DecodeTimestamp()); | 1599 DCHECK(start_timestamp >= DecodeTimestamp()); |
| 1600 | 1600 |
| 1601 RangeList::iterator itr = ranges_.begin(); | 1601 RangeList::iterator itr = ranges_.begin(); |
| 1602 | 1602 |
| 1603 // When checking a range to see if it has or begins soon enough after | |
| 1604 // |start_timestamp|, use the fudge room to determine "soon enough". | |
| 1605 DecodeTimestamp start_timestamp_plus_fudge = | |
| 1606 start_timestamp + ComputeFudgeRoom(GetMaxInterbufferDistance()); | |
| 1607 | |
| 1608 // Multiple ranges could be within the fudge room, because the fudge room is | |
| 1609 // dynamic based on max inter-buffer distance seen so far. Optimistically | |
| 1610 // check the earliest ones first. | |
| 1603 for (; itr != ranges_.end(); ++itr) { | 1611 for (; itr != ranges_.end(); ++itr) { |
| 1604 if ((*itr)->GetEndTimestamp() >= start_timestamp) { | 1612 DecodeTimestamp range_start = (*itr)->GetStartTimestamp(); |
| 1613 if (range_start >= start_timestamp_plus_fudge) | |
|
chcunningham
2016/04/20 20:14:27
Do you want this comparison to be GE vs GT? IIUC G
wolenetz
2016/04/20 21:28:01
Hmm. I had based this on the previous logic in l16
| |
| 1605 break; | 1614 break; |
| 1615 if ((*itr)->GetEndTimestamp() < start_timestamp) | |
| 1616 continue; | |
| 1617 DecodeTimestamp search_timestamp = start_timestamp; | |
| 1618 if (start_timestamp < range_start && | |
| 1619 start_timestamp_plus_fudge >= range_start) { | |
| 1620 search_timestamp = range_start; | |
| 1606 } | 1621 } |
| 1622 DecodeTimestamp keyframe_timestamp = | |
| 1623 (*itr)->NextKeyframeTimestamp(search_timestamp); | |
| 1624 if (keyframe_timestamp != kNoDecodeTimestamp()) | |
| 1625 return keyframe_timestamp; | |
| 1607 } | 1626 } |
| 1608 | 1627 |
| 1609 if (itr == ranges_.end()) { | 1628 DVLOG(2) << __FUNCTION__ << " " << GetStreamTypeName() |
| 1610 DVLOG(2) << __FUNCTION__ << " " << GetStreamTypeName() | 1629 << " no buffered data for dts=" << start_timestamp.InSecondsF(); |
| 1611 << " no buffered data for dts=" << start_timestamp.InSecondsF(); | |
| 1612 return kNoDecodeTimestamp(); | |
| 1613 } | |
| 1614 | |
| 1615 // First check for a keyframe timestamp >= |start_timestamp| | |
| 1616 // in the current range. | |
| 1617 DecodeTimestamp keyframe_timestamp = | |
| 1618 (*itr)->NextKeyframeTimestamp(start_timestamp); | |
| 1619 | |
| 1620 if (keyframe_timestamp != kNoDecodeTimestamp()) | |
| 1621 return keyframe_timestamp; | |
| 1622 | |
| 1623 // If a keyframe was not found then look for a keyframe that is | |
| 1624 // "close enough" in the current or next range. | |
| 1625 DecodeTimestamp end_timestamp = | |
| 1626 start_timestamp + ComputeFudgeRoom(GetMaxInterbufferDistance()); | |
| 1627 DCHECK(start_timestamp < end_timestamp); | |
| 1628 | |
| 1629 // Make sure the current range doesn't start beyond |end_timestamp|. | |
| 1630 if ((*itr)->GetStartTimestamp() >= end_timestamp) | |
| 1631 return kNoDecodeTimestamp(); | |
| 1632 | |
| 1633 keyframe_timestamp = (*itr)->KeyframeBeforeTimestamp(end_timestamp); | |
| 1634 | |
| 1635 // Check to see if the keyframe is within the acceptable range | |
| 1636 // (|start_timestamp|, |end_timestamp|]. | |
| 1637 if (keyframe_timestamp != kNoDecodeTimestamp() && | |
| 1638 start_timestamp < keyframe_timestamp && | |
| 1639 keyframe_timestamp <= end_timestamp) { | |
| 1640 return keyframe_timestamp; | |
| 1641 } | |
| 1642 | |
| 1643 // If |end_timestamp| is within this range, then no other checks are | |
| 1644 // necessary. | |
| 1645 if (end_timestamp <= (*itr)->GetEndTimestamp()) | |
| 1646 return kNoDecodeTimestamp(); | |
| 1647 | |
| 1648 // Move on to the next range. | |
| 1649 ++itr; | |
| 1650 | |
| 1651 // Return early if the next range does not contain |end_timestamp|. | |
| 1652 if (itr == ranges_.end() || (*itr)->GetStartTimestamp() >= end_timestamp) | |
| 1653 return kNoDecodeTimestamp(); | |
| 1654 | |
| 1655 keyframe_timestamp = (*itr)->KeyframeBeforeTimestamp(end_timestamp); | |
| 1656 | |
| 1657 // Check to see if the keyframe is within the acceptable range | |
| 1658 // (|start_timestamp|, |end_timestamp|]. | |
| 1659 if (keyframe_timestamp != kNoDecodeTimestamp() && | |
| 1660 start_timestamp < keyframe_timestamp && | |
| 1661 keyframe_timestamp <= end_timestamp) { | |
| 1662 return keyframe_timestamp; | |
| 1663 } | |
| 1664 | |
| 1665 return kNoDecodeTimestamp(); | 1630 return kNoDecodeTimestamp(); |
| 1666 } | 1631 } |
| 1667 | 1632 |
| 1668 DecodeTimestamp SourceBufferStream::FindKeyframeAfterTimestamp( | 1633 DecodeTimestamp SourceBufferStream::FindKeyframeAfterTimestamp( |
| 1669 const DecodeTimestamp timestamp) { | 1634 const DecodeTimestamp timestamp) { |
| 1670 DCHECK(timestamp != kNoDecodeTimestamp()); | 1635 DCHECK(timestamp != kNoDecodeTimestamp()); |
| 1671 | 1636 |
| 1672 RangeList::iterator itr = FindExistingRangeFor(timestamp); | 1637 RangeList::iterator itr = FindExistingRangeFor(timestamp); |
| 1673 | 1638 |
| 1674 if (itr == ranges_.end()) | 1639 if (itr == ranges_.end()) |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1839 return false; | 1804 return false; |
| 1840 | 1805 |
| 1841 DCHECK_NE(have_splice_buffers, have_preroll_buffer); | 1806 DCHECK_NE(have_splice_buffers, have_preroll_buffer); |
| 1842 splice_buffers_index_ = 0; | 1807 splice_buffers_index_ = 0; |
| 1843 pending_buffer_.swap(*out_buffer); | 1808 pending_buffer_.swap(*out_buffer); |
| 1844 pending_buffers_complete_ = false; | 1809 pending_buffers_complete_ = false; |
| 1845 return true; | 1810 return true; |
| 1846 } | 1811 } |
| 1847 | 1812 |
| 1848 } // namespace media | 1813 } // namespace media |
| OLD | NEW |