Index: webrtc/test/frame_generator_unittest.cc |
diff --git a/webrtc/test/frame_generator_unittest.cc b/webrtc/test/frame_generator_unittest.cc |
index 1ead69806223efd15b64db93d23dd2071993ceca..79e7b63abf6490380e3cd8db7dd18b54ce04fbeb 100644 |
--- a/webrtc/test/frame_generator_unittest.cc |
+++ b/webrtc/test/frame_generator_unittest.cc |
@@ -81,6 +81,26 @@ class FrameGeneratorTest : public ::testing::Test { |
frame->set_timestamp(13); |
} |
+ uint64_t Hash(VideoFrame* frame) { |
+ // Generate a 64-bit hash from the frame's buffer. |
+ uint64_t hash = 19; |
+ rtc::scoped_refptr<I420BufferInterface> i420_buffer = |
+ frame->video_frame_buffer()->ToI420(); |
+ const uint8_t* buffer = i420_buffer->DataY(); |
+ for (int i = 0; i < y_size; ++i) { |
+ hash = (37 * hash) + buffer[i]; |
+ } |
+ buffer = i420_buffer->DataU(); |
+ for (int i = 0; i < uv_size; ++i) { |
+ hash = (37 * hash) + buffer[i]; |
+ } |
+ buffer = i420_buffer->DataV(); |
+ for (int i = 0; i < uv_size; ++i) { |
+ hash = (37 * hash) + buffer[i]; |
+ } |
+ return hash; |
+ } |
+ |
std::string two_frame_filename_; |
std::string one_frame_filename_; |
const int y_size = kFrameWidth * kFrameHeight; |
@@ -145,5 +165,25 @@ TEST_F(FrameGeneratorTest, MultipleFrameFilesWithRepeat) { |
CheckFrameAndMutate(generator->NextFrame(), 0, 0, 0); |
} |
+TEST_F(FrameGeneratorTest, SlideGenerator) { |
+ const int kGenCount = 9; |
+ const int kRepeatCount = 3; |
+ std::unique_ptr<FrameGenerator> generator( |
+ FrameGenerator::CreateSlideGenerator( |
+ kFrameWidth, kFrameHeight, kRepeatCount)); |
+ uint64_t hashes[kGenCount]; |
+ for (int i = 0; i < kGenCount; ++i) { |
+ hashes[i] = Hash(generator->NextFrame()); |
+ } |
+ // Check that the buffer changes only every |kRepeatCount| frames. |
+ for (int i = 1; i < kGenCount; ++i) { |
+ if (i % kRepeatCount == 0) { |
+ EXPECT_NE(hashes[i-1], hashes[i]); |
+ } else { |
+ EXPECT_EQ(hashes[i-1], hashes[i]); |
+ } |
+ } |
+} |
+ |
} // namespace test |
} // namespace webrtc |