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

Side by Side 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, 3 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 EXPECT_EQ(0, frame->ntp_time_ms()); 74 EXPECT_EQ(0, frame->ntp_time_ms());
75 EXPECT_EQ(0, frame->render_time_ms()); 75 EXPECT_EQ(0, frame->render_time_ms());
76 EXPECT_EQ(0u, frame->timestamp()); 76 EXPECT_EQ(0u, frame->timestamp());
77 77
78 // Mutate to something arbitrary non-zero. 78 // Mutate to something arbitrary non-zero.
79 frame->set_ntp_time_ms(11); 79 frame->set_ntp_time_ms(11);
80 frame->set_timestamp_us(12); 80 frame->set_timestamp_us(12);
81 frame->set_timestamp(13); 81 frame->set_timestamp(13);
82 } 82 }
83 83
84 uint64_t Hash(VideoFrame* frame) {
85 // Generate a 64-bit hash from the frame's buffer.
86 uint64_t hash = 19;
87 rtc::scoped_refptr<I420BufferInterface> i420_buffer =
88 frame->video_frame_buffer()->ToI420();
89 const uint8_t* buffer = i420_buffer->DataY();
90 for (int i = 0; i < y_size; ++i) {
91 hash = (37 * hash) + buffer[i];
92 }
93 buffer = i420_buffer->DataU();
94 for (int i = 0; i < uv_size; ++i) {
95 hash = (37 * hash) + buffer[i];
96 }
97 buffer = i420_buffer->DataV();
98 for (int i = 0; i < uv_size; ++i) {
99 hash = (37 * hash) + buffer[i];
100 }
101 return hash;
102 }
103
84 std::string two_frame_filename_; 104 std::string two_frame_filename_;
85 std::string one_frame_filename_; 105 std::string one_frame_filename_;
86 const int y_size = kFrameWidth * kFrameHeight; 106 const int y_size = kFrameWidth * kFrameHeight;
87 const int uv_size = ((kFrameHeight + 1) / 2) * ((kFrameWidth + 1) / 2); 107 const int uv_size = ((kFrameHeight + 1) / 2) * ((kFrameWidth + 1) / 2);
88 }; 108 };
89 109
90 TEST_F(FrameGeneratorTest, SingleFrameFile) { 110 TEST_F(FrameGeneratorTest, SingleFrameFile) {
91 std::unique_ptr<FrameGenerator> generator(FrameGenerator::CreateFromYuvFile( 111 std::unique_ptr<FrameGenerator> generator(FrameGenerator::CreateFromYuvFile(
92 std::vector<std::string>(1, one_frame_filename_), kFrameWidth, 112 std::vector<std::string>(1, one_frame_filename_), kFrameWidth,
93 kFrameHeight, 1)); 113 kFrameHeight, 1));
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 files, kFrameWidth, kFrameHeight, kRepeatCount)); 158 files, kFrameWidth, kFrameHeight, kRepeatCount));
139 for (int i = 0; i < kRepeatCount; ++i) 159 for (int i = 0; i < kRepeatCount; ++i)
140 CheckFrameAndMutate(generator->NextFrame(), 0, 0, 0); 160 CheckFrameAndMutate(generator->NextFrame(), 0, 0, 0);
141 for (int i = 0; i < kRepeatCount; ++i) 161 for (int i = 0; i < kRepeatCount; ++i)
142 CheckFrameAndMutate(generator->NextFrame(), 127, 127, 127); 162 CheckFrameAndMutate(generator->NextFrame(), 127, 127, 127);
143 for (int i = 0; i < kRepeatCount; ++i) 163 for (int i = 0; i < kRepeatCount; ++i)
144 CheckFrameAndMutate(generator->NextFrame(), 255, 255, 255); 164 CheckFrameAndMutate(generator->NextFrame(), 255, 255, 255);
145 CheckFrameAndMutate(generator->NextFrame(), 0, 0, 0); 165 CheckFrameAndMutate(generator->NextFrame(), 0, 0, 0);
146 } 166 }
147 167
168 TEST_F(FrameGeneratorTest, SlideGenerator) {
169 const int kGenCount = 9;
170 const int kRepeatCount = 3;
171 std::unique_ptr<FrameGenerator> generator(
172 FrameGenerator::CreateSlideGenerator(
173 kFrameWidth, kFrameHeight, kRepeatCount));
174 uint64_t hashes[kGenCount];
175 for (int i = 0; i < kGenCount; ++i) {
176 hashes[i] = Hash(generator->NextFrame());
177 }
178 // Check that the buffer changes only every |kRepeatCount| frames.
179 for (int i = 1; i < kGenCount; ++i) {
180 if (i % kRepeatCount == 0) {
181 EXPECT_NE(hashes[i-1], hashes[i]);
182 } else {
183 EXPECT_EQ(hashes[i-1], hashes[i]);
184 }
185 }
186 }
187
148 } // namespace test 188 } // namespace test
149 } // namespace webrtc 189 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698