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

Unified Diff: media/base/audio_splicer_unittest.cc

Issue 440803002: Don't crash when splices are in the past due to bad media. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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
« media/base/audio_splicer.cc ('K') | « media/base/audio_splicer.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/audio_splicer_unittest.cc
diff --git a/media/base/audio_splicer_unittest.cc b/media/base/audio_splicer_unittest.cc
index e6de2c62ed330ad9433993bd62b5dfbd0ce80ac5..86131bf48747448a2a806eecdb15e1d70808e774 100644
--- a/media/base/audio_splicer_unittest.cc
+++ b/media/base/audio_splicer_unittest.cc
@@ -720,4 +720,48 @@ TEST_F(AudioSplicerTest, IncorrectlyMarkedSpliceWithBadGap) {
EXPECT_FALSE(AddInput(second_buffer));
}
+// Ensure we don't crash when a splice frame is incorrectly marked such that the
+// splice timestamp has already passed when SetSpliceTimestamp() is called.
+// This can happen if the encoded timestamps are too far behind the decoded
+// timestamps.
+TEST_F(AudioSplicerTest, IncorrectlyMarkedPastSplice) {
+ const int kBufferSize = 200;
+
+ scoped_refptr<AudioBuffer> first_buffer =
+ GetNextInputBuffer(1.0f, kBufferSize);
+ EXPECT_TRUE(AddInput(first_buffer));
+ VerifyNextBuffer(first_buffer);
+
+ // Start the splice at a timestamp which has already occurred.
+ splicer_.SetSpliceTimestamp(base::TimeDelta());
+
+ scoped_refptr<AudioBuffer> second_buffer =
+ GetNextInputBuffer(0.5f, kBufferSize);
+ EXPECT_TRUE(AddInput(second_buffer));
+ EXPECT_FALSE(splicer_.HasNextBuffer());
+
+ // |third_buffer| will complete the supposed splice. The buffer size is set
+ // such that unchecked the splicer would try to trim off a negative number of
+ // frames.
+ splicer_.SetSpliceTimestamp(kNoTimestamp());
+ scoped_refptr<AudioBuffer> third_buffer =
+ GetNextInputBuffer(0.0f, kBufferSize * 10);
+ third_buffer->set_timestamp(base::TimeDelta());
+ EXPECT_TRUE(AddInput(third_buffer));
+
+ // The second buffer should come through unmodified.
+ VerifyNextBuffer(second_buffer);
+
+ // The third buffer should be partially dropped since it overlaps the second.
+ ASSERT_TRUE(splicer_.HasNextBuffer());
+ const base::TimeDelta second_buffer_end_ts =
+ second_buffer->timestamp() + second_buffer->duration();
+ scoped_refptr<AudioBuffer> output = splicer_.GetNextBuffer();
+ EXPECT_EQ(second_buffer_end_ts, output->timestamp());
+ EXPECT_EQ(third_buffer->duration() -
+ (second_buffer_end_ts - third_buffer->timestamp()),
+ output->duration());
+ EXPECT_TRUE(VerifyData(output, GetValue(third_buffer)));
+}
+
} // namespace media
« media/base/audio_splicer.cc ('K') | « media/base/audio_splicer.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698