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

Unified Diff: media/filters/source_buffer_range.cc

Issue 1018373003: Improving WebM video duration estimation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Adding limited media log (10 times max) for WebM duration estimates. Created 5 years, 9 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
Index: media/filters/source_buffer_range.cc
diff --git a/media/filters/source_buffer_range.cc b/media/filters/source_buffer_range.cc
index a80d629fe8a620d18177e5ecd33aac34811894c9..e57efec75bbe452ce0fab968d09e707c0ea4445c 100644
--- a/media/filters/source_buffer_range.cc
+++ b/media/filters/source_buffer_range.cc
@@ -48,6 +48,9 @@ void SourceBufferRange::AppendBuffersToEnd(const BufferQueue& new_buffers) {
DCHECK(media_segment_start_time_ == kNoDecodeTimestamp() ||
media_segment_start_time_ <=
new_buffers.front()->GetDecodeTimestamp());
+
+ AdjustEstimatedDurationForNewAppend(new_buffers);
+
for (BufferQueue::const_iterator itr = new_buffers.begin();
itr != new_buffers.end();
++itr) {
@@ -63,11 +66,36 @@ void SourceBufferRange::AppendBuffersToEnd(const BufferQueue& new_buffers) {
}
}
+void SourceBufferRange::AdjustEstimatedDurationForNewAppend(
wolenetz 2015/03/28 00:26:06 Does adjustment to duration correctly include when
chcunningham 2015/04/13 23:25:17 This is a great question and I've given it a lot o
wolenetz 2015/04/15 02:55:23 I agree.
+ const BufferQueue& new_buffers) {
+ if (buffers_.empty() || new_buffers.empty()) {
wolenetz 2015/03/28 00:26:06 nit: Change call to only occur when buffers_ is no
chcunningham 2015/04/13 23:25:18 Let me push back a little here (or at least argue
wolenetz 2015/04/15 02:55:23 That's fine. If this method really needed to requi
+ return;
+ }
+
+ // Only adjust the last of the previously appended buffers. The last buffer
wolenetz 2015/03/28 00:26:05 nit: s/buffers./buffers if its duration was previo
chcunningham 2015/04/13 23:25:17 Done.
+ // in a given append is an edge case where the parsers (upstream) cannot know
+ // the implicit PTS-delta duration because the do not know the PTS of the
wolenetz 2015/03/28 00:26:05 nit: s/because the/because they/.. Actually, is th
chcunningham 2015/04/13 23:25:17 Done. Changed a little from what you wrote, but di
+ // frame that may follow the last for that append. The PTS of this new append
+ // supplies the missing information for a better duration estimate.
+ scoped_refptr<StreamParserBuffer> last_appended_buffer = buffers_.back();
wolenetz 2015/03/28 00:26:05 nit: const& the smart pointer to reduce unnecessar
chcunningham 2015/04/13 23:25:18 Done. Made auto too.
+ if (last_appended_buffer->is_duration_estimated()) {
+ base::TimeDelta timestamp_delta =
+ new_buffers.front()->timestamp() - last_appended_buffer->timestamp();
+ if (last_appended_buffer->duration() != timestamp_delta) {
+ DVLOG(1) << "Replacing estimated duration ("
+ << last_appended_buffer->duration()
+ << ") from last append with derived duration ("
wolenetz 2015/03/28 00:26:06 nit: may not have been from "last" append.
chcunningham 2015/04/13 23:25:17 Done. Now reads "Replacing estimated duration (X)
+ << timestamp_delta << ").";
+ last_appended_buffer->set_duration(timestamp_delta);
+ }
+ }
+}
+
void SourceBufferRange::Seek(DecodeTimestamp timestamp) {
DCHECK(CanSeekTo(timestamp));
DCHECK(!keyframe_map_.empty());
- KeyframeMap::iterator result = GetFirstKeyframeBefore(timestamp);
+ KeyframeMap::iterator result = GetFirstKeyframeAtOrBefore(timestamp);
next_buffer_index_ = result->second - keyframe_map_index_base_;
DCHECK_LT(next_buffer_index_, static_cast<int>(buffers_.size()));
}
@@ -175,7 +203,7 @@ SourceBufferRange::GetFirstKeyframeAt(DecodeTimestamp timestamp,
}
SourceBufferRange::KeyframeMap::iterator
-SourceBufferRange::GetFirstKeyframeBefore(DecodeTimestamp timestamp) {
+SourceBufferRange::GetFirstKeyframeAtOrBefore(DecodeTimestamp timestamp) {
KeyframeMap::iterator result = keyframe_map_.lower_bound(timestamp);
// lower_bound() returns the first element >= |timestamp|, so we want the
// previous element if it did not return the element exactly equal to
@@ -288,7 +316,7 @@ int SourceBufferRange::GetRemovalGOP(
BufferQueue::iterator buffer_itr = buffers_.begin() + keyframe_index;
KeyframeMap::iterator gop_end = keyframe_map_.end();
if (end_timestamp < GetBufferedEndTimestamp())
- gop_end = GetFirstKeyframeBefore(end_timestamp);
+ gop_end = GetFirstKeyframeAtOrBefore(end_timestamp);
// Check if the removal range is within a GOP and skip the loop if so.
// [keyframe]...[start_timestamp]...[end_timestamp]...[keyframe]
@@ -528,7 +556,7 @@ DecodeTimestamp SourceBufferRange::KeyframeBeforeTimestamp(
if (timestamp < GetStartTimestamp() || timestamp >= GetBufferedEndTimestamp())
return kNoDecodeTimestamp();
- return GetFirstKeyframeBefore(timestamp)->first;
+ return GetFirstKeyframeAtOrBefore(timestamp)->first;
}
bool SourceBufferRange::IsNextInSequence(

Powered by Google App Engine
This is Rietveld 408576698