Chromium Code Reviews| Index: media/filters/source_buffer_stream_unittest.cc |
| diff --git a/media/filters/source_buffer_stream_unittest.cc b/media/filters/source_buffer_stream_unittest.cc |
| index 9e7373a16ad37d6bf172642fe2388185599b935a..18e43677d3710859d0bc8e8c2f735ea0dee9701b 100644 |
| --- a/media/filters/source_buffer_stream_unittest.cc |
| +++ b/media/filters/source_buffer_stream_unittest.cc |
| @@ -6,6 +6,8 @@ |
| #include <string> |
| +#include "base/bind.h" |
| +#include "base/bind_helpers.h" |
| #include "base/logging.h" |
| #include "base/strings/string_number_conversions.h" |
| #include "base/strings/string_split.h" |
| @@ -27,8 +29,8 @@ class SourceBufferStreamTest : public testing::Test { |
| protected: |
| SourceBufferStreamTest() { |
| config_ = TestVideoConfig::Normal(); |
| - stream_.reset(new SourceBufferStream(config_, LogCB())); |
| SetStreamInfo(kDefaultFramesPerSecond, kDefaultKeyframesPerSecond); |
| + stream_.reset(new SourceBufferStream(config_, log_cb())); |
| } |
| void SetMemoryLimit(int buffers_of_data) { |
| @@ -248,6 +250,11 @@ class SourceBufferStreamTest : public testing::Test { |
| << "\nActual: " << actual.AsHumanReadableString(); |
| } |
| + const LogCB log_cb() { |
| + return base::Bind(&SourceBufferStreamTest::DebugMediaLog, |
| + base::Unretained(this)); |
| + } |
| + |
| base::TimeDelta frame_duration() const { return frame_duration_; } |
| scoped_ptr<SourceBufferStream> stream_; |
| @@ -304,6 +311,21 @@ class SourceBufferStreamTest : public testing::Test { |
| EXPECT_EQ(expect_success, stream_->Append(queue)); |
| } |
| + // AppendBuffers() allows for the generation of StreamParserBuffers from coded |
| + // strings of timestamps separated by spaces. Supported syntax: |
| + // |
| + // ##: |
| + // Generates a StreamParserBuffer with decode timestamp ##. E.g., "0 1 2 3". |
| + // |
| + // ##K: |
| + // Indicates the buffer with timestamp ## reflects a keyframe. E.g., "0K 1". |
| + // |
| + // S(a# b#C ... z#) |
| + // Indicates a splice frame buffer should be created with timestamp a#. |
| + // Subsequent timestamps b# ... z# will be treated as the fade out preroll for |
| + // the splice frame. If a timestamp within the preroll ends with C the config |
| + // id to use for that and subsequent preroll appends is incremented by one. |
| + // The config id for non-splice frame appends will not be affected. |
| void AppendBuffers(const std::string& buffers_to_append, |
| bool start_new_segment, bool one_by_one, |
| bool expect_success) { |
| @@ -312,14 +334,42 @@ class SourceBufferStreamTest : public testing::Test { |
| CHECK_GT(timestamps.size(), 0u); |
| + bool splice_frame = false; |
| + scoped_refptr<StreamParserBuffer> splice_buffer; |
| + size_t splice_config_id = stream_->append_config_index_; |
| + std::vector<scoped_refptr<StreamParserBuffer> > fade_out_preroll; |
| SourceBufferStream::BufferQueue buffers; |
| for (size_t i = 0; i < timestamps.size(); i++) { |
| bool is_keyframe = false; |
| + bool last_splice_frame = false; |
| if (EndsWith(timestamps[i], "K", true)) { |
|
acolwell GONE FROM CHROMIUM
2014/01/14 02:01:26
I think you probably need to move this down below
DaleCurtis
2014/01/14 22:44:35
I'll switch it to S(1K 2 3) since that seems most
|
| is_keyframe = true; |
| // Remove the "K" off of the token. |
| timestamps[i] = timestamps[i].substr(0, timestamps[i].length() - 1); |
| } |
| + // Handle splice frame starts. |
| + if (StartsWithASCII(timestamps[i], "S(", true)) { |
| + splice_frame = true; |
| + // Remove the "S(" off of the token. |
| + timestamps[i] = timestamps[i].substr(2, timestamps[i].length()); |
| + } |
| + if (splice_frame && EndsWith(timestamps[i], ")", true)) { |
| + // Forbid single entry splice frames. |
| + CHECK(splice_buffer); |
| + splice_frame = false; |
| + last_splice_frame = true; |
| + // Remove the ")" off of the token. |
| + timestamps[i] = timestamps[i].substr(0, timestamps[i].length() - 1); |
| + } |
| + // Handle config changes within the splice frame. |
| + if (splice_frame && EndsWith(timestamps[i], "C", true)) { |
| + splice_config_id++; |
| + CHECK(splice_config_id < stream_->audio_configs_.size() || |
| + splice_config_id < stream_->video_configs_.size()); |
| + // Remove the "C" off of the token. |
| + timestamps[i] = timestamps[i].substr(0, timestamps[i].length() - 1); |
| + } |
| + |
| int time_in_ms; |
| CHECK(base::StringToInt(timestamps[i], &time_in_ms)); |
| @@ -330,6 +380,20 @@ class SourceBufferStreamTest : public testing::Test { |
| base::TimeDelta::FromMilliseconds(time_in_ms); |
| buffer->SetDecodeTimestamp(timestamp); |
| + if ((splice_frame || last_splice_frame) && splice_buffer) { |
| + CHECK(timestamp < splice_buffer->GetDecodeTimestamp()); |
| + buffer->SetConfigId(splice_config_id); |
| + fade_out_preroll.push_back(buffer); |
| + if (last_splice_frame) { |
| + splice_buffer->SetFadeOutPreroll(fade_out_preroll); |
| + splice_buffer = NULL; |
| + fade_out_preroll.clear(); |
| + } |
| + continue; |
| + } else if (splice_frame) { |
| + splice_buffer = buffer; |
| + } |
| + |
| if (i == 0u && start_new_segment) |
| stream_->OnNewMediaSegment(timestamp); |
| @@ -349,6 +413,11 @@ class SourceBufferStreamTest : public testing::Test { |
| } |
| } |
| + |
| + void DebugMediaLog(const std::string& log) { |
| + DVLOG(1) << log; |
| + } |
| + |
| int frames_per_second_; |
| int keyframes_per_second_; |
| base::TimeDelta frame_duration_; |
| @@ -3000,7 +3069,7 @@ TEST_F(SourceBufferStreamTest, SameTimestamp_Video_Overlap_3) { |
| TEST_F(SourceBufferStreamTest, SameTimestamp_Audio) { |
| AudioDecoderConfig config(kCodecMP3, kSampleFormatF32, CHANNEL_LAYOUT_STEREO, |
| 44100, NULL, 0, false); |
| - stream_.reset(new SourceBufferStream(config, LogCB())); |
| + stream_.reset(new SourceBufferStream(config, log_cb())); |
| Seek(0); |
| NewSegmentAppend("0K 0K 30K 30 60 60"); |
| CheckExpectedBuffers("0K 0K 30K 30 60 60"); |
| @@ -3009,7 +3078,7 @@ TEST_F(SourceBufferStreamTest, SameTimestamp_Audio) { |
| TEST_F(SourceBufferStreamTest, SameTimestamp_Audio_Invalid_1) { |
| AudioDecoderConfig config(kCodecMP3, kSampleFormatF32, CHANNEL_LAYOUT_STEREO, |
| 44100, NULL, 0, false); |
| - stream_.reset(new SourceBufferStream(config, LogCB())); |
| + stream_.reset(new SourceBufferStream(config, log_cb())); |
| Seek(0); |
| NewSegmentAppend_ExpectFailure("0K 30 30K 60"); |
| } |
| @@ -3250,7 +3319,6 @@ TEST_F(SourceBufferStreamTest, Remove_GOPBeingAppended) { |
| CheckExpectedBuffers("240K 270 300"); |
| } |
| - |
| TEST_F(SourceBufferStreamTest, |
| Remove_PreviousAppendDestroyedAndOverwriteExistingRange) { |
| SeekToTimestamp(base::TimeDelta::FromMilliseconds(90)); |
| @@ -3275,6 +3343,49 @@ TEST_F(SourceBufferStreamTest, |
| CheckExpectedBuffers("90K 121 151"); |
| } |
| +TEST_F(SourceBufferStreamTest, SpliceFrame_Basic) { |
| + Seek(0); |
| + NewSegmentAppend("0K S(10 3 6 9) 15 20 S(35 25 30) 40"); |
|
acolwell GONE FROM CHROMIUM
2014/01/14 02:01:26
This is why I think changing the format would be a
DaleCurtis
2014/01/14 22:44:35
Are all audio frames keyframes? The mp3 parser ta
|
| + CheckExpectedBuffers("0K 3 6 9"); |
| + |
| + scoped_refptr<StreamParserBuffer> buffer; |
| + EXPECT_EQ(stream_->GetNextBuffer(&buffer), SourceBufferStream::kConfigChange); |
| + stream_->GetCurrentVideoDecoderConfig(); |
| + |
| + CheckExpectedBuffers("10 15 20 25 30"); |
| + |
| + EXPECT_EQ(stream_->GetNextBuffer(&buffer), SourceBufferStream::kConfigChange); |
| + stream_->GetCurrentVideoDecoderConfig(); |
| + |
| + CheckExpectedBuffers("35 40"); |
| + CheckNoNextBuffer(); |
| +} |
| + |
| +TEST_F(SourceBufferStreamTest, SpliceFrame_BasicConfigChange) { |
| + VideoDecoderConfig new_config = TestVideoConfig::Large(); |
| + ASSERT_FALSE(new_config.Matches(config_)); |
| + CheckConfig(config_); |
| + |
| + // Add a new video config, then reset the config index back to the original. |
| + stream_->UpdateVideoConfig(new_config); |
| + stream_->UpdateVideoConfig(config_); |
| + |
| + Seek(0); |
| + CheckConfig(config_); |
| + NewSegmentAppend("0K S(10 3 6C 9) 15"); |
| + CheckExpectedBuffers("0K 3"); |
| + |
| + scoped_refptr<StreamParserBuffer> buffer; |
| + EXPECT_EQ(stream_->GetNextBuffer(&buffer), SourceBufferStream::kConfigChange); |
| + CheckConfig(new_config); |
| + CheckExpectedBuffers("6 9"); |
| + |
| + EXPECT_EQ(stream_->GetNextBuffer(&buffer), SourceBufferStream::kConfigChange); |
| + CheckConfig(config_); |
| + CheckExpectedBuffers("10 15"); |
| + CheckNoNextBuffer(); |
| +} |
| + |
| // TODO(vrk): Add unit tests where keyframes are unaligned between streams. |
| // (crbug.com/133557) |