Commit d5ae8f1f authored by Matt Wolenetz's avatar Matt Wolenetz Committed by Commit Bot

MSE: Merge SourceBufferRangeByPts into SourceBufferRange

With recent removal of LegacyByDts buffering logic, there is no longer a
need to split the internals of SourceBufferRange into ByDts and ByPts
implementations. This change merges the ByPts implementation into
SourceBufferRange (SBR), makes SBR a concrete type, and updates a
multitude of references to SBRByPts to be to SBR.

BUG=771349

Change-Id: I0f96ea98733c8f124d616433c2f3e3324f06e9ef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1594277Reviewed-by: default avatarDan Sanders <sandersd@chromium.org>
Commit-Queue: Matthew Wolenetz <wolenetz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658851}
parent 786fbf1f
......@@ -55,8 +55,6 @@ jumbo_source_set("filters") {
"source_buffer_parse_warnings.h",
"source_buffer_range.cc",
"source_buffer_range.h",
"source_buffer_range_by_pts.cc",
"source_buffer_range_by_pts.h",
"source_buffer_state.cc",
"source_buffer_state.h",
"source_buffer_stream.cc",
......
......@@ -95,10 +95,9 @@ class MseTrackBuffer {
// monotonically increasing.
void SetHighestPresentationTimestampIfIncreased(base::TimeDelta timestamp);
// Adds |frame| to the end of |processed_frames_|. In some BufferingByPts
// SAP-Type-2 conditions, may also flush any previously enqueued frames, which
// can fail. Returns the result of such flushing, or true if no flushing was
// done.
// Adds |frame| to the end of |processed_frames_|. In some SAP-Type-2
// conditions, may also flush any previously enqueued frames, which can fail.
// Returns the result of such flushing, or true if no flushing was done.
bool EnqueueProcessedFrame(scoped_refptr<StreamParserBuffer> frame);
// Appends |processed_frames_|, if not empty, to |stream_| and clears
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
......@@ -85,7 +85,7 @@ std::string StatusToString(const SourceBufferStreamStatus& status) {
}
// Helper method for logging, converts a range into a readable string.
std::string RangeToString(const SourceBufferRangeByPts& range) {
std::string RangeToString(const SourceBufferRange& range) {
if (range.size_in_bytes() == 0) {
return "[]";
}
......@@ -566,14 +566,13 @@ void SourceBufferStream::RemoveInternal(DecodeTimestamp start,
auto itr = ranges_.begin();
while (itr != ranges_.end()) {
SourceBufferRangeByPts* range = itr->get();
SourceBufferRange* range = itr->get();
if (RangeGetStartTimestamp(range) >= end)
break;
// Split off any remaining GOPs starting at or after |end| and add it to
// |ranges_|.
std::unique_ptr<SourceBufferRangeByPts> new_range =
RangeSplitRange(range, end);
std::unique_ptr<SourceBufferRange> new_range = RangeSplitRange(range, end);
if (new_range) {
itr = ranges_.insert(++itr, std::move(new_range));
......@@ -1005,7 +1004,7 @@ size_t SourceBufferStream::GetRemovalRange(
for (auto itr = ranges_.begin();
itr != ranges_.end() && bytes_freed < total_bytes_to_free; ++itr) {
SourceBufferRangeByPts* range = itr->get();
SourceBufferRange* range = itr->get();
if (RangeGetStartTimestamp(range) >= end_timestamp)
break;
if (RangeGetEndTimestamp(range) < start_timestamp)
......@@ -1032,10 +1031,10 @@ size_t SourceBufferStream::FreeBuffers(size_t total_bytes_to_free,
// This range will save the last GOP appended to |range_for_next_append_|
// if the buffers surrounding it get deleted during garbage collection.
std::unique_ptr<SourceBufferRangeByPts> new_range_for_append;
std::unique_ptr<SourceBufferRange> new_range_for_append;
while (!ranges_.empty() && bytes_freed < total_bytes_to_free) {
SourceBufferRangeByPts* current_range = NULL;
SourceBufferRange* current_range = NULL;
BufferQueue buffers;
size_t bytes_deleted = 0;
......@@ -1297,7 +1296,7 @@ void SourceBufferStream::PrepareRangesForNextAppend(
// Split the range at |buffers_start_timestamp|, if necessary, then return
// early.
std::unique_ptr<SourceBufferRangeByPts> new_range =
std::unique_ptr<SourceBufferRange> new_range =
RangeSplitRange(range_for_next_append_->get(), buffers_start_timestamp);
if (!new_range)
return;
......@@ -1408,8 +1407,7 @@ void SourceBufferStream::MergeWithNextRangeIfNecessary(
const RangeList::iterator& range_with_new_buffers_itr) {
DCHECK(range_with_new_buffers_itr != ranges_.end());
SourceBufferRangeByPts* range_with_new_buffers =
range_with_new_buffers_itr->get();
SourceBufferRange* range_with_new_buffers = range_with_new_buffers_itr->get();
RangeList::iterator next_range_itr = range_with_new_buffers_itr;
++next_range_itr;
......@@ -1672,7 +1670,7 @@ SourceBufferStream::FindExistingRangeFor(DecodeTimestamp start_timestamp) {
}
SourceBufferStream::RangeList::iterator SourceBufferStream::AddToRanges(
std::unique_ptr<SourceBufferRangeByPts> new_range) {
std::unique_ptr<SourceBufferRange> new_range) {
DecodeTimestamp start_timestamp = RangeGetStartTimestamp(new_range.get());
auto itr = ranges_.end();
for (itr = ranges_.begin(); itr != ranges_.end(); ++itr) {
......@@ -1695,14 +1693,14 @@ SourceBufferStream::GetSelectedRangeItr() {
}
void SourceBufferStream::SeekAndSetSelectedRange(
SourceBufferRangeByPts* range,
SourceBufferRange* range,
DecodeTimestamp seek_timestamp) {
if (range)
RangeSeek(range, seek_timestamp);
SetSelectedRange(range);
}
void SourceBufferStream::SetSelectedRange(SourceBufferRangeByPts* range) {
void SourceBufferStream::SetSelectedRange(SourceBufferRange* range) {
DVLOG(1) << __func__ << " " << GetStreamTypeName() << ": " << selected_range_
<< " " << (selected_range_ ? RangeToString(*selected_range_) : "")
<< " -> " << range << " " << (range ? RangeToString(*range) : "");
......@@ -2036,39 +2034,39 @@ DecodeTimestamp SourceBufferStream::BufferGetTimestamp(
}
void SourceBufferStream::RangeAppendBuffersToEnd(
SourceBufferRangeByPts* range,
SourceBufferRange* range,
const BufferQueue& buffers,
DecodeTimestamp group_start_time) {
range->AppendBuffersToEnd(buffers, group_start_time.ToPresentationTime());
}
DecodeTimestamp SourceBufferStream::RangeGetBufferedEndTimestamp(
SourceBufferRangeByPts* range) const {
SourceBufferRange* range) const {
return DecodeTimestamp::FromPresentationTime(
range->GetBufferedEndTimestamp());
}
DecodeTimestamp SourceBufferStream::RangeGetEndTimestamp(
SourceBufferRangeByPts* range) const {
SourceBufferRange* range) const {
return DecodeTimestamp::FromPresentationTime(range->GetEndTimestamp());
}
DecodeTimestamp SourceBufferStream::RangeGetStartTimestamp(
SourceBufferRangeByPts* range) const {
SourceBufferRange* range) const {
return DecodeTimestamp::FromPresentationTime(range->GetStartTimestamp());
}
bool SourceBufferStream::RangeCanSeekTo(SourceBufferRangeByPts* range,
bool SourceBufferStream::RangeCanSeekTo(SourceBufferRange* range,
DecodeTimestamp seek_time) const {
return range->CanSeekTo(seek_time.ToPresentationTime());
}
int SourceBufferStream::RangeGetConfigIdAtTime(SourceBufferRangeByPts* range,
int SourceBufferStream::RangeGetConfigIdAtTime(SourceBufferRange* range,
DecodeTimestamp config_time) {
return range->GetConfigIdAtTime(config_time.ToPresentationTime());
}
bool SourceBufferStream::RangeSameConfigThruRange(SourceBufferRangeByPts* range,
bool SourceBufferStream::RangeSameConfigThruRange(SourceBufferRange* range,
DecodeTimestamp start,
DecodeTimestamp end) {
return range->SameConfigThruRange(start.ToPresentationTime(),
......@@ -2076,13 +2074,13 @@ bool SourceBufferStream::RangeSameConfigThruRange(SourceBufferRangeByPts* range,
}
bool SourceBufferStream::RangeFirstGOPEarlierThanMediaTime(
SourceBufferRangeByPts* range,
SourceBufferRange* range,
DecodeTimestamp media_time) const {
return range->FirstGOPEarlierThanMediaTime(media_time.ToPresentationTime());
}
size_t SourceBufferStream::RangeGetRemovalGOP(
SourceBufferRangeByPts* range,
SourceBufferRange* range,
DecodeTimestamp start_timestamp,
DecodeTimestamp end_timestamp,
size_t bytes_to_free,
......@@ -2096,32 +2094,32 @@ size_t SourceBufferStream::RangeGetRemovalGOP(
return result;
}
bool SourceBufferStream::RangeBelongsToRange(SourceBufferRangeByPts* range,
bool SourceBufferStream::RangeBelongsToRange(SourceBufferRange* range,
DecodeTimestamp timestamp) const {
return range->BelongsToRange(timestamp.ToPresentationTime());
}
DecodeTimestamp SourceBufferStream::RangeFindHighestBufferedTimestampAtOrBefore(
SourceBufferRangeByPts* range,
SourceBufferRange* range,
DecodeTimestamp timestamp) const {
return DecodeTimestamp::FromPresentationTime(
range->FindHighestBufferedTimestampAtOrBefore(
timestamp.ToPresentationTime()));
}
void SourceBufferStream::RangeSeek(SourceBufferRangeByPts* range,
void SourceBufferStream::RangeSeek(SourceBufferRange* range,
DecodeTimestamp timestamp) {
range->Seek(timestamp.ToPresentationTime());
}
DecodeTimestamp SourceBufferStream::RangeNextKeyframeTimestamp(
SourceBufferRangeByPts* range,
SourceBufferRange* range,
DecodeTimestamp timestamp) {
return DecodeTimestamp::FromPresentationTime(
range->NextKeyframeTimestamp(timestamp.ToPresentationTime()));
}
bool SourceBufferStream::RangeGetBuffersInRange(SourceBufferRangeByPts* range,
bool SourceBufferStream::RangeGetBuffersInRange(SourceBufferRange* range,
DecodeTimestamp start,
DecodeTimestamp end,
BufferQueue* buffers) {
......@@ -2129,13 +2127,13 @@ bool SourceBufferStream::RangeGetBuffersInRange(SourceBufferRangeByPts* range,
end.ToPresentationTime(), buffers);
}
std::unique_ptr<SourceBufferRangeByPts> SourceBufferStream::RangeSplitRange(
SourceBufferRangeByPts* range,
std::unique_ptr<SourceBufferRange> SourceBufferStream::RangeSplitRange(
SourceBufferRange* range,
DecodeTimestamp timestamp) {
return range->SplitRange(timestamp.ToPresentationTime());
}
bool SourceBufferStream::RangeTruncateAt(SourceBufferRangeByPts* range,
bool SourceBufferStream::RangeTruncateAt(SourceBufferRange* range,
DecodeTimestamp timestamp,
BufferQueue* deleted_buffers,
bool is_exclusive) {
......@@ -2144,16 +2142,16 @@ bool SourceBufferStream::RangeTruncateAt(SourceBufferRangeByPts* range,
}
DecodeTimestamp SourceBufferStream::RangeKeyframeBeforeTimestamp(
SourceBufferRangeByPts* range,
SourceBufferRange* range,
DecodeTimestamp timestamp) {
return DecodeTimestamp::FromPresentationTime(
range->KeyframeBeforeTimestamp(timestamp.ToPresentationTime()));
}
std::unique_ptr<SourceBufferRangeByPts> SourceBufferStream::RangeNew(
std::unique_ptr<SourceBufferRange> SourceBufferStream::RangeNew(
const BufferQueue& new_buffers,
DecodeTimestamp range_start_time) {
return std::make_unique<SourceBufferRangeByPts>(
return std::make_unique<SourceBufferRange>(
TypeToGapPolicy(GetType()), new_buffers,
range_start_time.ToPresentationTime(),
base::BindRepeating(&SourceBufferStream::GetMaxInterbufferDistance,
......
......@@ -32,7 +32,6 @@
#include "media/base/text_track_config.h"
#include "media/base/video_decoder_config.h"
#include "media/filters/source_buffer_range.h"
#include "media/filters/source_buffer_range_by_pts.h"
namespace media {
......@@ -54,7 +53,7 @@ enum class SourceBufferStreamType { kAudio, kVideo, kText };
class MEDIA_EXPORT SourceBufferStream {
public:
using BufferQueue = StreamParser::BufferQueue;
using RangeList = std::list<std::unique_ptr<SourceBufferRangeByPts>>;
using RangeList = std::list<std::unique_ptr<SourceBufferRange>>;
// Helper for PrepareRangesForNextAppend and BufferQueueToLogString that
// populates |start| and |end| with the presentation interval of |buffers|.
......@@ -255,7 +254,7 @@ class MEDIA_EXPORT SourceBufferStream {
// iterator in |ranges_| that points to |new_range|. |new_range| becomes owned
// by |ranges_|.
typename RangeList::iterator AddToRanges(
std::unique_ptr<SourceBufferRangeByPts> new_range);
std::unique_ptr<SourceBufferRange> new_range);
// Returns an iterator that points to the place in |ranges_| where
// |selected_range_| lives.
......@@ -263,11 +262,11 @@ class MEDIA_EXPORT SourceBufferStream {
// Sets the |selected_range_| to |range| and resets the next buffer position
// for the previous |selected_range_|.
void SetSelectedRange(SourceBufferRangeByPts* range);
void SetSelectedRange(SourceBufferRange* range);
// Seeks |range| to |seek_timestamp| and then calls SetSelectedRange() with
// |range|.
void SeekAndSetSelectedRange(SourceBufferRangeByPts* range,
void SeekAndSetSelectedRange(SourceBufferRange* range,
DecodeTimestamp seek_timestamp);
// Resets this stream back to an unseeked state.
......@@ -398,57 +397,54 @@ class MEDIA_EXPORT SourceBufferStream {
// returns true. Otherwise returns false.
bool SetPendingBuffer(scoped_refptr<StreamParserBuffer>* out_buffer);
// Helpers that adapt StreamParserBuffer and SBRByPts to a common internal
// interface until legacy calculations of time unit are converted internally
// in SourceBufferStream usage of these.
// Helpers that adapt StreamParserBuffer and SourceBufferRange to a common
// internal interface until legacy calculations of time unit are converted
// internally in SourceBufferStream usage of these.
// TODO(wolenetz): Convert callers to use base::TimeDelta for timestamps
// except when actually considering DTS. See https://crbug.com/771349.
DecodeTimestamp BufferGetTimestamp(scoped_refptr<StreamParserBuffer> buffer);
void RangeAppendBuffersToEnd(SourceBufferRangeByPts* range,
void RangeAppendBuffersToEnd(SourceBufferRange* range,
const BufferQueue& buffers,
DecodeTimestamp group_start_time);
DecodeTimestamp RangeGetBufferedEndTimestamp(
SourceBufferRangeByPts* range) const;
DecodeTimestamp RangeGetEndTimestamp(SourceBufferRangeByPts* range) const;
DecodeTimestamp RangeGetStartTimestamp(SourceBufferRangeByPts* range) const;
bool RangeCanSeekTo(SourceBufferRangeByPts* range,
DecodeTimestamp RangeGetBufferedEndTimestamp(SourceBufferRange* range) const;
DecodeTimestamp RangeGetEndTimestamp(SourceBufferRange* range) const;
DecodeTimestamp RangeGetStartTimestamp(SourceBufferRange* range) const;
bool RangeCanSeekTo(SourceBufferRange* range,
DecodeTimestamp seek_time) const;
int RangeGetConfigIdAtTime(SourceBufferRangeByPts* range,
int RangeGetConfigIdAtTime(SourceBufferRange* range,
DecodeTimestamp config_time);
bool RangeSameConfigThruRange(SourceBufferRangeByPts* range,
bool RangeSameConfigThruRange(SourceBufferRange* range,
DecodeTimestamp start,
DecodeTimestamp end);
bool RangeFirstGOPEarlierThanMediaTime(SourceBufferRangeByPts* range,
bool RangeFirstGOPEarlierThanMediaTime(SourceBufferRange* range,
DecodeTimestamp media_time) const;
size_t RangeGetRemovalGOP(SourceBufferRangeByPts* range,
size_t RangeGetRemovalGOP(SourceBufferRange* range,
DecodeTimestamp start_timestamp,
DecodeTimestamp end_timestamp,
size_t bytes_to_free,
DecodeTimestamp* end_removal_timestamp);
bool RangeBelongsToRange(SourceBufferRangeByPts* range,
bool RangeBelongsToRange(SourceBufferRange* range,
DecodeTimestamp timestamp) const;
DecodeTimestamp RangeFindHighestBufferedTimestampAtOrBefore(
SourceBufferRangeByPts* range,
SourceBufferRange* range,
DecodeTimestamp timestamp) const;
void RangeSeek(SourceBufferRangeByPts* range, DecodeTimestamp timestamp);
DecodeTimestamp RangeNextKeyframeTimestamp(SourceBufferRangeByPts* range,
void RangeSeek(SourceBufferRange* range, DecodeTimestamp timestamp);
DecodeTimestamp RangeNextKeyframeTimestamp(SourceBufferRange* range,
DecodeTimestamp timestamp);
bool RangeGetBuffersInRange(SourceBufferRangeByPts* range,
bool RangeGetBuffersInRange(SourceBufferRange* range,
DecodeTimestamp start,
DecodeTimestamp end,
BufferQueue* buffers);
std::unique_ptr<SourceBufferRangeByPts> RangeSplitRange(
SourceBufferRangeByPts* range,
DecodeTimestamp timestamp);
bool RangeTruncateAt(SourceBufferRangeByPts* range,
std::unique_ptr<SourceBufferRange> RangeSplitRange(SourceBufferRange* range,
DecodeTimestamp timestamp);
bool RangeTruncateAt(SourceBufferRange* range,
DecodeTimestamp timestamp,
BufferQueue* deleted_buffers,
bool is_exclusive);
DecodeTimestamp RangeKeyframeBeforeTimestamp(SourceBufferRangeByPts* range,
DecodeTimestamp RangeKeyframeBeforeTimestamp(SourceBufferRange* range,
DecodeTimestamp timestamp);
std::unique_ptr<SourceBufferRangeByPts> RangeNew(
const BufferQueue& new_buffers,
DecodeTimestamp range_start_time);
std::unique_ptr<SourceBufferRange> RangeNew(const BufferQueue& new_buffers,
DecodeTimestamp range_start_time);
// Used to report log messages that can help the web developer figure out what
// is wrong with the content.
......@@ -489,7 +485,7 @@ class MEDIA_EXPORT SourceBufferStream {
// Pointer to the seeked-to Range. This is the range from which
// GetNextBuffer() calls are fulfilled after the |track_buffer_| has been
// emptied.
SourceBufferRangeByPts* selected_range_ = nullptr;
SourceBufferRange* selected_range_ = nullptr;
// Queue of the next buffers to be returned from calls to GetNextBuffer(). If
// |track_buffer_| is empty, return buffers from |selected_range_|.
......@@ -518,22 +514,24 @@ class MEDIA_EXPORT SourceBufferStream {
base::TimeDelta last_appended_buffer_duration_ = kNoTimestamp;
bool last_appended_buffer_is_keyframe_ = false;
// When buffering ByPts, yet needing still to verify coded frame group is
// monotically increasing in DTS sequence and to update max interbuffer
// distance also by DTS deltas within a coded frame group, the following is
// needed.
// When buffering GOPs by keyframe PTS and intra-gop by nonkeyframe DTS, to
// verify monotonically increasing intra-GOP DTS sequence and to update max
// interbuffer distance also by DTS deltas within a coded frame group, the
// following is needed.
DecodeTimestamp last_appended_buffer_decode_timestamp_ = kNoDecodeTimestamp();
// The following is the highest timestamp appended so far in this coded frame
// group. In ByPts buffering, this is a PTS in DTS type, and isn't necessarily
// the most recently appended frame. This is used as the lower bound of
// removing previously buffered media when processing new appends.
// TODO(wolenetz): Use TimeDelta for PTS. See https://crbug.com/771349.
DecodeTimestamp highest_timestamp_in_append_sequence_ = kNoDecodeTimestamp();
// The following is used in determining if FreeBuffersAfterLastAppended() is
// allowed during garbage collection. In ByPts buffering, this is a PTS in DTS
// type, and isn't necessarily the end time of the most recently appended
// frame.
// TODO(wolenetz): Use TimeDelta for PTS. See https://crbug.com/771349.
DecodeTimestamp highest_buffered_end_time_in_append_sequence_ =
kNoDecodeTimestamp();
......
......@@ -28,7 +28,6 @@
#include "media/base/timestamp_constants.h"
#include "media/base/webvtt_util.h"
#include "media/filters/source_buffer_range.h"
#include "media/filters/source_buffer_range_by_pts.h"
#include "testing/gtest/include/gtest/gtest.h"
using ::testing::HasSubstr;
......@@ -5179,7 +5178,7 @@ TEST_F(SourceBufferStreamTest, InstantGarbageCollectionUnderMemoryPressure) {
}
TEST_F(SourceBufferStreamTest, GCFromFrontThenExplicitRemoveFromMiddleToEnd) {
// Attempts to exercise SBRByPts::GetBufferIndexAt() after its
// Attempts to exercise SourceBufferRange::GetBufferIndexAt() after its
// |keyframe_map_index_base_| has been increased, and when there is a GOP
// following the search timestamp. GC followed by an explicit remove may
// trigger that code path.
......@@ -5194,7 +5193,7 @@ TEST_F(SourceBufferStreamTest, GCFromFrontThenExplicitRemoveFromMiddleToEnd) {
CheckExpectedRangesByTimestamp("{ [0,150) }");
// Seek to the second GOP's keyframe to allow GC to collect all of the first
// GOP (ostensibly increasing SBR's |keyframe_map_index_base_|).
// GOP (ostensibly increasing SourceBufferRange's |keyframe_map_index_base_|).
SeekToTimestampMs(50);
GarbageCollect(base::TimeDelta::FromMilliseconds(50), 0);
CheckExpectedRangesByTimestamp("{ [50,150) }");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment