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

Unified Diff: webrtc/test/frame_generator_unittest.cc

Issue 3003193002: Add a new frame generator that cycles through randomly generated slides. (Closed)
Patch Set: Patchset 3C. Created 3 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
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

Powered by Google App Engine
This is Rietveld 408576698