Commit 85fbb00e authored by vrk@chromium.org's avatar vrk@chromium.org

Fix SplitRange() logic in SourceBufferRange to transfer next buffer position appropriately

Adds logic to transfer the waiting-for-next-keyframe state to the split range
if necessary.

BUG=NONE
TEST=media_unittests


Review URL: https://chromiumcodereview.appspot.com/10703125

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146274 0039d316-1c4b-4281-b951-d872f2087c98
parent 037116ed
...@@ -825,12 +825,18 @@ SourceBufferRange* SourceBufferRange::SplitRange(base::TimeDelta timestamp) { ...@@ -825,12 +825,18 @@ SourceBufferRange* SourceBufferRange::SplitRange(base::TimeDelta timestamp) {
new SourceBufferRange( new SourceBufferRange(
removed_buffers, kNoTimestamp(), interbuffer_distance_cb_); removed_buffers, kNoTimestamp(), interbuffer_distance_cb_);
// If |next_buffer_index_| points to a buffer in |split_range|, update the // If the next buffer position is now in |split_range|, update the state of
// |next_buffer_index_| of this range and |split_range| accordingly. // this range and |split_range| accordingly.
if (next_buffer_index_ >= static_cast<int>(buffers_.size())) { if (next_buffer_index_ >= static_cast<int>(buffers_.size())) {
DCHECK(!waiting_for_keyframe_);
split_range->next_buffer_index_ = next_buffer_index_ - keyframe_index; split_range->next_buffer_index_ = next_buffer_index_ - keyframe_index;
next_buffer_index_ = -1; ResetNextBufferPosition();
} else if (waiting_for_keyframe_) {
split_range->waiting_for_keyframe_ = true;
split_range->next_keyframe_timestamp_ = next_keyframe_timestamp_;
ResetNextBufferPosition();
} }
return split_range; return split_range;
} }
...@@ -885,7 +891,7 @@ bool SourceBufferRange::TruncateAt( ...@@ -885,7 +891,7 @@ bool SourceBufferRange::TruncateAt(
BufferQueue saved(starting_point + next_buffer_offset, buffers_.end()); BufferQueue saved(starting_point + next_buffer_offset, buffers_.end());
removed_buffers->swap(saved); removed_buffers->swap(saved);
} }
next_buffer_index_ = -1; ResetNextBufferPosition();
removed_next_buffer = true; removed_next_buffer = true;
} }
} }
......
...@@ -893,6 +893,55 @@ TEST_F(SourceBufferStreamTest, End_Overlap_Selected_NoKeyframeAfterNew) { ...@@ -893,6 +893,55 @@ TEST_F(SourceBufferStreamTest, End_Overlap_Selected_NoKeyframeAfterNew) {
CheckExpectedBuffers(10, 10, &kDataB); CheckExpectedBuffers(10, 10, &kDataB);
} }
// This test covers the case where new buffers end-overlap an existing, selected
// range, and there is no keyframe after the end of the new buffers, then the
// range gets split.
// index: 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
// old  : |A a a a a A*a*|
// new  : B b b b b B b b b b B
// after: |B b b b b B b b b b B|
// new  : A a a a a A
// after: |A a a a a A| |B b b b b B|
// track: |a|
TEST_F(SourceBufferStreamTest, End_Overlap_Selected_NoKeyframeAfterNew2) {
// Append 7 buffers at positions 10 through 16.
NewSegmentAppend(10, 7, &kDataA);
// Seek to position 15, then move to position 16.
Seek(15);
CheckExpectedBuffers(15, 15, &kDataA);
// Now append 11 buffers at positions 5 through 15.
NewSegmentAppend(5, 11, &kDataB);
CheckExpectedRanges("{ [5,15) }");
// Now do another end-overlap to split the range into two parts, where the
// 2nd range should have the next buffer position.
NewSegmentAppend(0, 6, &kDataA);
CheckExpectedRanges("{ [0,5) [10,15) }");
// Check for data in the track buffer.
CheckExpectedBuffers(16, 16, &kDataA);
// Now there's no data to fulfill the request.
CheckNoNextBuffer();
// Add data to the 2nd range, should not be able to fulfill the next read
// until we've added a keyframe.
NewSegmentAppend(15, 1, &kDataB);
CheckNoNextBuffer();
for (int i = 16; i <= 19; i++) {
AppendBuffers(i, 1, &kDataB);
CheckNoNextBuffer();
}
// Now append a keyframe.
AppendBuffers(20, 1, &kDataB);
// We should be able to get the next buffer.
CheckExpectedBuffers(20, 20, &kDataB, true);
}
// This test covers the case when new buffers overlap the middle of a selected // This test covers the case when new buffers overlap the middle of a selected
// range. This tests the case when there is no split and the next buffer is a // range. This tests the case when there is no split and the next buffer is a
// keyframe. // keyframe.
......
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