Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Unified Diff: media/filters/source_buffer_stream.cc

Issue 341083004: Introduce the playback time into the MSE garbage collection. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: New flow to pass the media time to SourceBufferStream. Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/filters/source_buffer_stream.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/source_buffer_stream.cc
diff --git a/media/filters/source_buffer_stream.cc b/media/filters/source_buffer_stream.cc
index fe22b4a795eaf0f0ed102cdc93c748ce005ffc8e..f24d73415cd5db17e7ae0ba2811802bce688cf6a 100644
--- a/media/filters/source_buffer_stream.cc
+++ b/media/filters/source_buffer_stream.cc
@@ -126,6 +126,10 @@ class SourceBufferRange {
base::TimeDelta start_timestamp, base::TimeDelta end_timestamp,
int bytes_to_free, base::TimeDelta* end_removal_timestamp);
+ // Indicates whether the GOP at the beginning of the range
+ // has timestamps all lower than |media_time|.
+ bool FirstGOPEarlierThanMediaTime(base::TimeDelta media_time) const;
+
// Indicates whether the GOP at the beginning or end of the range contains the
// next buffer position.
bool FirstGOPContainsNextBufferPosition() const;
@@ -351,6 +355,7 @@ SourceBufferStream::SourceBufferStream(const AudioDecoderConfig& audio_config,
end_of_stream_(false),
seek_buffer_timestamp_(kNoTimestamp()),
selected_range_(NULL),
+ current_media_time_(kNoTimestamp()),
media_segment_start_time_(kNoTimestamp()),
range_for_next_append_(ranges_.end()),
new_media_segment_(false),
@@ -377,6 +382,7 @@ SourceBufferStream::SourceBufferStream(const VideoDecoderConfig& video_config,
end_of_stream_(false),
seek_buffer_timestamp_(kNoTimestamp()),
selected_range_(NULL),
+ current_media_time_(kNoTimestamp()),
media_segment_start_time_(kNoTimestamp()),
range_for_next_append_(ranges_.end()),
new_media_segment_(false),
@@ -404,6 +410,7 @@ SourceBufferStream::SourceBufferStream(const TextTrackConfig& text_config,
end_of_stream_(false),
seek_buffer_timestamp_(kNoTimestamp()),
selected_range_(NULL),
+ current_media_time_(kNoTimestamp()),
media_segment_start_time_(kNoTimestamp()),
range_for_next_append_(ranges_.end()),
new_media_segment_(false),
@@ -445,7 +452,8 @@ void SourceBufferStream::OnNewMediaSegment(
}
}
-bool SourceBufferStream::Append(const BufferQueue& buffers) {
+bool SourceBufferStream::Append(const BufferQueue& buffers,
+ base::TimeDelta media_time) {
TRACE_EVENT2("media", "SourceBufferStream::Append",
"stream type", GetStreamTypeName(),
"buffers to append", buffers.size());
@@ -577,7 +585,7 @@ bool SourceBufferStream::Append(const BufferQueue& buffers) {
SetSelectedRangeIfNeeded(next_buffer_timestamp);
- GarbageCollectIfNeeded();
+ GarbageCollectIfNeeded(media_time);
DCHECK(IsRangeListSorted(ranges_));
DCHECK(OnlySelectedRangeIsSeeked());
@@ -791,7 +799,7 @@ void SourceBufferStream::SetConfigIds(const BufferQueue& buffers) {
}
}
-void SourceBufferStream::GarbageCollectIfNeeded() {
+void SourceBufferStream::GarbageCollectIfNeeded(base::TimeDelta media_time) {
// Compute size of |ranges_|.
int ranges_size = 0;
for (RangeList::iterator itr = ranges_.begin(); itr != ranges_.end(); ++itr)
@@ -808,11 +816,11 @@ void SourceBufferStream::GarbageCollectIfNeeded() {
// Begin deleting from the front.
if (bytes_to_free - bytes_freed > 0)
- bytes_freed += FreeBuffers(bytes_to_free - bytes_freed, false);
+ bytes_freed += FreeBuffers(bytes_to_free - bytes_freed, false, media_time);
// Begin deleting from the back.
if (bytes_to_free - bytes_freed > 0)
- FreeBuffers(bytes_to_free - bytes_freed, true);
+ FreeBuffers(bytes_to_free - bytes_freed, true, media_time);
}
int SourceBufferStream::FreeBuffersAfterLastAppended(int total_bytes_to_free) {
@@ -871,7 +879,8 @@ int SourceBufferStream::GetRemovalRange(
}
int SourceBufferStream::FreeBuffers(int total_bytes_to_free,
- bool reverse_direction) {
+ bool reverse_direction,
+ base::TimeDelta media_time) {
TRACE_EVENT2("media", "SourceBufferStream::FreeBuffers",
"total bytes to free", total_bytes_to_free,
"reverse direction", reverse_direction);
@@ -902,6 +911,10 @@ int SourceBufferStream::FreeBuffers(int total_bytes_to_free,
DCHECK_EQ(current_range, selected_range_);
break;
}
+ if (current_media_time_ != kNoTimestamp() &&
+ !current_range->FirstGOPEarlierThanMediaTime(media_time)) {
+ break;
+ }
bytes_deleted = current_range->DeleteGOPFromFront(&buffers);
}
@@ -1074,10 +1087,23 @@ void SourceBufferStream::MergeWithAdjacentRangeIfNecessary(
DeleteAndRemoveRange(&next_range_itr);
}
+void SourceBufferStream::NotifyMediaTimeUpdate(base::TimeDelta media_time) {
+ if (current_media_time_ != kNoTimestamp() &&
+ media_time < current_media_time_) {
+ LOG(WARNING) << "Time should be monotonically increasing: "
+ << media_time.InMilliseconds()
+ << " " << current_media_time_.InMilliseconds();
+ return;
+ }
+ current_media_time_ = media_time;
+}
+
void SourceBufferStream::Seek(base::TimeDelta timestamp) {
DCHECK(timestamp >= base::TimeDelta());
ResetSeekState();
+ current_media_time_ = kNoTimestamp();
+
if (ShouldSeekToStartOfBuffered(timestamp)) {
ranges_.front()->SeekToStart();
SetSelectedRange(ranges_.front());
@@ -1988,6 +2014,16 @@ int SourceBufferRange::GetRemovalGOP(
return bytes_removed;
}
+bool SourceBufferRange::FirstGOPEarlierThanMediaTime(
+ base::TimeDelta media_time) const {
+ if (keyframe_map_.size() == 1u)
+ return (GetEndTimestamp() < media_time);
+
+ KeyframeMap::const_iterator second_gop = keyframe_map_.begin();
+ ++second_gop;
+ return second_gop->first <= media_time;
+}
+
bool SourceBufferRange::FirstGOPContainsNextBufferPosition() const {
if (!HasNextBufferPosition())
return false;
« no previous file with comments | « media/filters/source_buffer_stream.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698