Index: media/capture/webm_muxer_unittest.cc |
diff --git a/media/capture/webm_muxer_unittest.cc b/media/capture/webm_muxer_unittest.cc |
index bde9b4fb49a6d398240d17bb34f220f09bd84b48..431b807e37cd3b65f812696331680ddaa6fcf73a 100644 |
--- a/media/capture/webm_muxer_unittest.cc |
+++ b/media/capture/webm_muxer_unittest.cc |
@@ -54,6 +54,11 @@ class WebmMuxerTest : public testing::Test, public EventHandlerInterface { |
return webm_muxer_.segment_.mode(); |
} |
+ bool HasTrack(int track_index) const { |
+ return webm_muxer_.segment_.GetTrackByNumber( |
+ webm_muxer_.muxer_args[track_index].track_number) != NULL; |
+ } |
+ |
mkvmuxer::int32 WebmMuxerWrite(const void* buf, mkvmuxer::uint32 len) { |
return webm_muxer_.Write(buf, len); |
} |
@@ -85,12 +90,59 @@ TEST_F(WebmMuxerTest, OnEncodedVideoTwoFrames) { |
const scoped_refptr<VideoFrame> video_frame = |
VideoFrame::CreateBlackFrame(frame_size); |
const base::StringPiece encoded_data("abcdefghijklmnopqrstuvwxyz"); |
+ int track_index = webm_muxer_.GetNextTrackIndex(); |
+ |
+ EXPECT_CALL(*this, WriteCallback(_)) |
+ .Times(AtLeast(1)) |
+ .WillRepeatedly(WithArgs<0>( |
+ Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); |
+ webm_muxer_.OnEncodedVideo(track_index, |
+ video_frame, |
+ encoded_data, |
+ base::TimeTicks::Now(), |
+ false /* keyframe */); |
+ |
+ // First time around WriteCallback() is pinged a number of times to write the |
+ // Matroska header, but at the end it dumps |encoded_data|. |
+ EXPECT_EQ(last_encoded_length_, encoded_data.size()); |
+ EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); |
+ EXPECT_GE(GetWebmMuxerPosition(), static_cast<int64_t>(last_encoded_length_)); |
+ EXPECT_EQ(GetWebmSegmentMode(), mkvmuxer::Segment::kLive); |
+ |
+ const int64_t begin_of_second_block = accumulated_position_; |
+ EXPECT_CALL(*this, WriteCallback(_)) |
+ .Times(AtLeast(1)) |
+ .WillRepeatedly(WithArgs<0>( |
+ Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); |
+ webm_muxer_.OnEncodedVideo(track_index, |
+ video_frame, |
+ encoded_data, |
+ base::TimeTicks::Now(), |
+ false /* keyframe */); |
+ |
+ // The second time around the callbacks should include a SimpleBlock header, |
+ // namely the track index, a timestamp and a flags byte, for a total of 6B. |
+ EXPECT_EQ(last_encoded_length_, encoded_data.size()); |
+ EXPECT_EQ(GetWebmMuxerPosition(), accumulated_position_); |
+ const uint32_t kSimpleBlockSize = 6u; |
+ EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize + |
+ encoded_data.size()), |
+ accumulated_position_); |
+} |
+ |
+TEST_F(WebmMuxerTest, OnEncodedVideoTwoTracks) { |
+ const gfx::Size frame_size(160, 80); |
+ const scoped_refptr<VideoFrame> video_frame = |
+ VideoFrame::CreateBlackFrame(frame_size); |
+ const base::StringPiece encoded_data("abcdefghijklmnopqrstuvwxyz"); |
+ int track_index_1 = webm_muxer_.GetNextTrackIndex(); |
EXPECT_CALL(*this, WriteCallback(_)) |
.Times(AtLeast(1)) |
.WillRepeatedly(WithArgs<0>( |
Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); |
- webm_muxer_.OnEncodedVideo(video_frame, |
+ webm_muxer_.OnEncodedVideo(track_index_1, |
+ video_frame, |
encoded_data, |
base::TimeTicks::Now(), |
false /* keyframe */); |
@@ -102,12 +154,15 @@ TEST_F(WebmMuxerTest, OnEncodedVideoTwoFrames) { |
EXPECT_GE(GetWebmMuxerPosition(), static_cast<int64_t>(last_encoded_length_)); |
EXPECT_EQ(GetWebmSegmentMode(), mkvmuxer::Segment::kLive); |
+ int track_index_2 = webm_muxer_.GetNextTrackIndex(); |
+ |
const int64_t begin_of_second_block = accumulated_position_; |
EXPECT_CALL(*this, WriteCallback(_)) |
.Times(AtLeast(1)) |
.WillRepeatedly(WithArgs<0>( |
Invoke(this, &WebmMuxerTest::SaveEncodedDataLen))); |
- webm_muxer_.OnEncodedVideo(video_frame, |
+ webm_muxer_.OnEncodedVideo(track_index_2, |
+ video_frame, |
encoded_data, |
base::TimeTicks::Now(), |
false /* keyframe */); |
@@ -120,6 +175,8 @@ TEST_F(WebmMuxerTest, OnEncodedVideoTwoFrames) { |
EXPECT_EQ(static_cast<int64_t>(begin_of_second_block + kSimpleBlockSize + |
encoded_data.size()), |
accumulated_position_); |
+ EXPECT_TRUE(HasTrack(track_index_1)); |
+ EXPECT_TRUE(HasTrack(track_index_2)); |
} |
} // namespace media |