OLD | NEW |
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "media/capture/content/video_capture_oracle.h" | 5 #include "media/capture/content/video_capture_oracle.h" |
6 | 6 |
7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 namespace media { | 10 namespace media { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 // delta between frame timestamps should never be more than 2X the | 191 // delta between frame timestamps should never be more than 2X the |
192 // |event_increment|. | 192 // |event_increment|. |
193 const base::TimeDelta max_acceptable_delta = | 193 const base::TimeDelta max_acceptable_delta = |
194 (i % 100) == 78 ? event_increment * 5 : event_increment * 2; | 194 (i % 100) == 78 ? event_increment * 5 : event_increment * 2; |
195 EXPECT_GE(max_acceptable_delta.InMicroseconds(), delta.InMicroseconds()); | 195 EXPECT_GE(max_acceptable_delta.InMicroseconds(), delta.InMicroseconds()); |
196 } | 196 } |
197 last_frame_timestamp = frame_timestamp; | 197 last_frame_timestamp = frame_timestamp; |
198 } | 198 } |
199 } | 199 } |
200 | 200 |
201 // Tests that VideoCaptureOracle prevents refresh request events from initiating | 201 // Tests that VideoCaptureOracle prevents timer polling from initiating |
202 // simultaneous captures. | 202 // simultaneous captures. |
203 TEST(VideoCaptureOracleTest, SamplesAtCorrectTimesAroundRefreshRequests) { | 203 TEST(VideoCaptureOracleTest, SamplesOnlyOneOverdueFrameAtATime) { |
204 const base::TimeDelta vsync_interval = base::TimeDelta::FromSeconds(1) / 60; | 204 const base::TimeDelta vsync_interval = base::TimeDelta::FromSeconds(1) / 60; |
205 const base::TimeDelta refresh_interval = | 205 const base::TimeDelta timer_interval = base::TimeDelta::FromMilliseconds( |
206 base::TimeDelta::FromMilliseconds(125); // 8 FPS | 206 VideoCaptureOracle::kMinTimerPollPeriodMillis); |
207 | 207 |
208 VideoCaptureOracle oracle(Get30HzPeriod(), Get720pSize(), | 208 VideoCaptureOracle oracle(Get30HzPeriod(), Get720pSize(), |
209 media::RESOLUTION_POLICY_FIXED_RESOLUTION, false); | 209 media::RESOLUTION_POLICY_FIXED_RESOLUTION, false); |
210 | 210 |
211 // Have the oracle observe some compositor events. Simulate that each capture | 211 // Have the oracle observe some compositor events. Simulate that each capture |
212 // completes successfully. | 212 // completes successfully. |
213 base::TimeTicks t = InitialTestTimeTicks(); | 213 base::TimeTicks t = InitialTestTimeTicks(); |
214 base::TimeTicks ignored; | 214 base::TimeTicks ignored; |
215 bool did_complete_a_capture = false; | 215 bool did_complete_a_capture = false; |
216 for (int i = 0; i < 10; ++i) { | 216 for (int i = 0; i < 10; ++i) { |
(...skipping 12 matching lines...) Expand all Loading... |
229 for (int i = 0; i <= 10; ++i) { | 229 for (int i = 0; i <= 10; ++i) { |
230 ASSERT_GT(10, i) << "BUG: Seems like it'll never happen!"; | 230 ASSERT_GT(10, i) << "BUG: Seems like it'll never happen!"; |
231 t += vsync_interval; | 231 t += vsync_interval; |
232 if (oracle.ObserveEventAndDecideCapture( | 232 if (oracle.ObserveEventAndDecideCapture( |
233 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(), t)) { | 233 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(), t)) { |
234 break; | 234 break; |
235 } | 235 } |
236 } | 236 } |
237 int frame_number = oracle.RecordCapture(0.0); | 237 int frame_number = oracle.RecordCapture(0.0); |
238 | 238 |
239 // Stop providing the compositor events and start providing refresh request | 239 // Stop providing the compositor events and start providing timer polling |
240 // events. No overdue samplings should be recommended because of the | 240 // events. No overdue samplings should be recommended because of the |
241 // not-yet-complete compositor-based capture. | 241 // not-yet-complete compositor-based capture. |
242 for (int i = 0; i < 10; ++i) { | 242 for (int i = 0; i < 10; ++i) { |
243 t += refresh_interval; | 243 t += timer_interval; |
244 ASSERT_FALSE(oracle.ObserveEventAndDecideCapture( | 244 ASSERT_FALSE(oracle.ObserveEventAndDecideCapture( |
245 VideoCaptureOracle::kPassiveRefreshRequest, gfx::Rect(), t)); | 245 VideoCaptureOracle::kTimerPoll, gfx::Rect(), t)); |
246 } | 246 } |
247 | 247 |
248 // Now, complete the oustanding compositor-based capture and continue | 248 // Now, complete the oustanding compositor-based capture and continue |
249 // providing refresh request events. The oracle should start recommending | 249 // providing timer polling events. The oracle should start recommending |
250 // sampling again. | 250 // sampling again. |
251 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored)); | 251 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored)); |
252 did_complete_a_capture = false; | 252 did_complete_a_capture = false; |
253 for (int i = 0; i < 10; ++i) { | 253 for (int i = 0; i < 10; ++i) { |
254 t += refresh_interval; | 254 t += timer_interval; |
255 if (oracle.ObserveEventAndDecideCapture( | 255 if (oracle.ObserveEventAndDecideCapture(VideoCaptureOracle::kTimerPoll, |
256 VideoCaptureOracle::kPassiveRefreshRequest, gfx::Rect(), t)) { | 256 gfx::Rect(), t)) { |
257 ASSERT_TRUE( | 257 ASSERT_TRUE( |
258 oracle.CompleteCapture(oracle.RecordCapture(0.0), true, &ignored)); | 258 oracle.CompleteCapture(oracle.RecordCapture(0.0), true, &ignored)); |
259 did_complete_a_capture = true; | 259 did_complete_a_capture = true; |
260 } | 260 } |
261 } | 261 } |
262 ASSERT_TRUE(did_complete_a_capture); | 262 ASSERT_TRUE(did_complete_a_capture); |
263 | 263 |
264 // Start one more "refresh" capture, but do not notify of completion yet. | 264 // Start one more timer-based capture, but do not notify of completion yet. |
265 for (int i = 0; i <= 10; ++i) { | 265 for (int i = 0; i <= 10; ++i) { |
266 ASSERT_GT(10, i) << "BUG: Seems like it'll never happen!"; | 266 ASSERT_GT(10, i) << "BUG: Seems like it'll never happen!"; |
267 t += refresh_interval; | 267 t += timer_interval; |
268 if (oracle.ObserveEventAndDecideCapture( | 268 if (oracle.ObserveEventAndDecideCapture(VideoCaptureOracle::kTimerPoll, |
269 VideoCaptureOracle::kPassiveRefreshRequest, gfx::Rect(), t)) { | 269 gfx::Rect(), t)) { |
270 break; | 270 break; |
271 } | 271 } |
272 } | 272 } |
273 frame_number = oracle.RecordCapture(0.0); | 273 frame_number = oracle.RecordCapture(0.0); |
274 | 274 |
275 // Confirm that the oracle does not recommend sampling until the outstanding | 275 // Confirm that the oracle does not recommend sampling until the outstanding |
276 // "refresh" capture completes. | 276 // timer-based capture completes. |
277 for (int i = 0; i < 10; ++i) { | 277 for (int i = 0; i < 10; ++i) { |
278 t += refresh_interval; | 278 t += timer_interval; |
279 ASSERT_FALSE(oracle.ObserveEventAndDecideCapture( | 279 ASSERT_FALSE(oracle.ObserveEventAndDecideCapture( |
280 VideoCaptureOracle::kPassiveRefreshRequest, gfx::Rect(), t)); | 280 VideoCaptureOracle::kTimerPoll, gfx::Rect(), t)); |
281 } | 281 } |
282 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored)); | 282 ASSERT_TRUE(oracle.CompleteCapture(frame_number, true, &ignored)); |
283 for (int i = 0; i <= 10; ++i) { | 283 for (int i = 0; i <= 10; ++i) { |
284 ASSERT_GT(10, i) << "BUG: Seems like it'll never happen!"; | 284 ASSERT_GT(10, i) << "BUG: Seems like it'll never happen!"; |
285 t += refresh_interval; | 285 t += timer_interval; |
286 if (oracle.ObserveEventAndDecideCapture( | 286 if (oracle.ObserveEventAndDecideCapture(VideoCaptureOracle::kTimerPoll, |
287 VideoCaptureOracle::kPassiveRefreshRequest, gfx::Rect(), t)) { | 287 gfx::Rect(), t)) { |
288 break; | 288 break; |
289 } | 289 } |
290 } | 290 } |
291 } | 291 } |
292 | 292 |
293 // Tests that VideoCaptureOracle does not rapidly change proposed capture sizes, | 293 // Tests that VideoCaptureOracle does not rapidly change proposed capture sizes, |
294 // to allow both the source content and the rest of the end-to-end system to | 294 // to allow both the source content and the rest of the end-to-end system to |
295 // stabilize. | 295 // stabilize. |
296 TEST(VideoCaptureOracleTest, DoesNotRapidlyChangeCaptureSize) { | 296 TEST(VideoCaptureOracleTest, DoesNotRapidlyChangeCaptureSize) { |
297 VideoCaptureOracle oracle(Get30HzPeriod(), Get720pSize(), | 297 VideoCaptureOracle oracle(Get30HzPeriod(), Get720pSize(), |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
610 ASSERT_TRUE(oracle.ObserveEventAndDecideCapture( | 610 ASSERT_TRUE(oracle.ObserveEventAndDecideCapture( |
611 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(), t)); | 611 VideoCaptureOracle::kCompositorUpdate, gfx::Rect(), t)); |
612 ASSERT_EQ(Get720pSize(), oracle.capture_size()); | 612 ASSERT_EQ(Get720pSize(), oracle.capture_size()); |
613 base::TimeTicks ignored; | 613 base::TimeTicks ignored; |
614 ASSERT_TRUE( | 614 ASSERT_TRUE( |
615 oracle.CompleteCapture(oracle.RecordCapture(2.0), true, &ignored)); | 615 oracle.CompleteCapture(oracle.RecordCapture(2.0), true, &ignored)); |
616 } | 616 } |
617 } | 617 } |
618 | 618 |
619 } // namespace media | 619 } // namespace media |
OLD | NEW |