OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // Unit test for VideoCaptureController. | 5 // Unit test for VideoCaptureController. |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 base::SharedMemoryHandle handle, | 52 base::SharedMemoryHandle handle, |
53 int length, int buffer_id) OVERRIDE { | 53 int length, int buffer_id) OVERRIDE { |
54 DoBufferCreated(id); | 54 DoBufferCreated(id); |
55 } | 55 } |
56 virtual void OnBufferDestroyed(const VideoCaptureControllerID& id, | 56 virtual void OnBufferDestroyed(const VideoCaptureControllerID& id, |
57 int buffer_id) OVERRIDE { | 57 int buffer_id) OVERRIDE { |
58 DoBufferDestroyed(id); | 58 DoBufferDestroyed(id); |
59 } | 59 } |
60 virtual void OnBufferReady(const VideoCaptureControllerID& id, | 60 virtual void OnBufferReady(const VideoCaptureControllerID& id, |
61 int buffer_id, | 61 int buffer_id, |
62 base::Time timestamp, | 62 base::TimeTicks timestamp, |
63 const media::VideoCaptureFormat& format) OVERRIDE { | 63 const media::VideoCaptureFormat& format) OVERRIDE { |
64 DoBufferReady(id); | 64 DoBufferReady(id); |
65 base::MessageLoop::current()->PostTask(FROM_HERE, | 65 base::MessageLoop::current()->PostTask(FROM_HERE, |
66 base::Bind(&VideoCaptureController::ReturnBuffer, | 66 base::Bind(&VideoCaptureController::ReturnBuffer, |
67 base::Unretained(controller_), id, this, buffer_id)); | 67 base::Unretained(controller_), id, this, buffer_id)); |
68 } | 68 } |
69 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE { | 69 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE { |
70 DoEnded(id); | 70 DoEnded(id); |
71 // OnEnded() must respond by (eventually) unregistering the client. | 71 // OnEnded() must respond by (eventually) unregistering the client. |
72 base::MessageLoop::current()->PostTask(FROM_HERE, | 72 base::MessageLoop::current()->PostTask(FROM_HERE, |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); | 272 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); |
273 } | 273 } |
274 { | 274 { |
275 InSequence s; | 275 InSequence s; |
276 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); | 276 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); |
277 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); | 277 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); |
278 } | 278 } |
279 device_->OnIncomingCapturedBuffer(buffer, | 279 device_->OnIncomingCapturedBuffer(buffer, |
280 media::VideoFrame::I420, | 280 media::VideoFrame::I420, |
281 capture_resolution, | 281 capture_resolution, |
282 base::Time(), | 282 base::TimeTicks(), |
283 device_format.frame_rate); | 283 device_format.frame_rate); |
284 buffer = NULL; | 284 buffer = NULL; |
285 | 285 |
286 base::RunLoop().RunUntilIdle(); | 286 base::RunLoop().RunUntilIdle(); |
287 Mock::VerifyAndClearExpectations(client_a_.get()); | 287 Mock::VerifyAndClearExpectations(client_a_.get()); |
288 Mock::VerifyAndClearExpectations(client_b_.get()); | 288 Mock::VerifyAndClearExpectations(client_b_.get()); |
289 | 289 |
290 // Second buffer which ought to use the same shared memory buffer. In this | 290 // Second buffer which ought to use the same shared memory buffer. In this |
291 // case pretend that the Buffer pointer is held by the device for a long | 291 // case pretend that the Buffer pointer is held by the device for a long |
292 // delay. This shouldn't affect anything. | 292 // delay. This shouldn't affect anything. |
293 buffer = | 293 buffer = |
294 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); | 294 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
295 ASSERT_TRUE(buffer); | 295 ASSERT_TRUE(buffer); |
296 memset(buffer->data(), buffer_no++, buffer->size()); | 296 memset(buffer->data(), buffer_no++, buffer->size()); |
297 device_->OnIncomingCapturedBuffer(buffer, | 297 device_->OnIncomingCapturedBuffer(buffer, |
298 media::VideoFrame::I420, | 298 media::VideoFrame::I420, |
299 capture_resolution, | 299 capture_resolution, |
300 base::Time(), | 300 base::TimeTicks(), |
301 device_format.frame_rate); | 301 device_format.frame_rate); |
302 buffer = NULL; | 302 buffer = NULL; |
303 | 303 |
304 // The buffer should be delivered to the clients in any order. | 304 // The buffer should be delivered to the clients in any order. |
305 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1); | 305 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1); |
306 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); | 306 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); |
307 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); | 307 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); |
308 base::RunLoop().RunUntilIdle(); | 308 base::RunLoop().RunUntilIdle(); |
309 Mock::VerifyAndClearExpectations(client_a_.get()); | 309 Mock::VerifyAndClearExpectations(client_a_.get()); |
310 Mock::VerifyAndClearExpectations(client_b_.get()); | 310 Mock::VerifyAndClearExpectations(client_b_.get()); |
311 | 311 |
312 // Add a fourth client now that some buffers have come through. | 312 // Add a fourth client now that some buffers have come through. |
313 controller_->AddClient(client_b_route_2, | 313 controller_->AddClient(client_b_route_2, |
314 client_b_.get(), | 314 client_b_.get(), |
315 base::kNullProcessHandle, | 315 base::kNullProcessHandle, |
316 1, | 316 1, |
317 session_1); | 317 session_1); |
318 Mock::VerifyAndClearExpectations(client_b_.get()); | 318 Mock::VerifyAndClearExpectations(client_b_.get()); |
319 | 319 |
320 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. | 320 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. |
321 for (int i = 0; i < kPoolSize; i++) { | 321 for (int i = 0; i < kPoolSize; i++) { |
322 buffer = device_->ReserveOutputBuffer(media::VideoFrame::I420, | 322 buffer = device_->ReserveOutputBuffer(media::VideoFrame::I420, |
323 capture_resolution); | 323 capture_resolution); |
324 ASSERT_TRUE(buffer); | 324 ASSERT_TRUE(buffer); |
325 memset(buffer->data(), buffer_no++, buffer->size()); | 325 memset(buffer->data(), buffer_no++, buffer->size()); |
326 device_->OnIncomingCapturedBuffer(buffer, | 326 device_->OnIncomingCapturedBuffer(buffer, |
327 media::VideoFrame::I420, | 327 media::VideoFrame::I420, |
328 capture_resolution, | 328 capture_resolution, |
329 base::Time(), | 329 base::TimeTicks(), |
330 device_format.frame_rate); | 330 device_format.frame_rate); |
331 buffer = NULL; | 331 buffer = NULL; |
332 } | 332 } |
333 // ReserveOutputBuffer ought to fail now, because the pool is depleted. | 333 // ReserveOutputBuffer ought to fail now, because the pool is depleted. |
334 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, | 334 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, |
335 capture_resolution)); | 335 capture_resolution)); |
336 | 336 |
337 // The new client needs to be told of 3 buffers; the old clients only 2. | 337 // The new client needs to be told of 3 buffers; the old clients only 2. |
338 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); | 338 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); |
339 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(kPoolSize); | 339 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(kPoolSize); |
(...skipping 17 matching lines...) Expand all Loading... |
357 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); | 357 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); |
358 controller_->StopSession(300); | 358 controller_->StopSession(300); |
359 // Queue up another buffer. | 359 // Queue up another buffer. |
360 buffer = | 360 buffer = |
361 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); | 361 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
362 ASSERT_TRUE(buffer); | 362 ASSERT_TRUE(buffer); |
363 memset(buffer->data(), buffer_no++, buffer->size()); | 363 memset(buffer->data(), buffer_no++, buffer->size()); |
364 device_->OnIncomingCapturedBuffer(buffer, | 364 device_->OnIncomingCapturedBuffer(buffer, |
365 media::VideoFrame::I420, | 365 media::VideoFrame::I420, |
366 capture_resolution, | 366 capture_resolution, |
367 base::Time(), | 367 base::TimeTicks(), |
368 device_format.frame_rate); | 368 device_format.frame_rate); |
369 buffer = NULL; | 369 buffer = NULL; |
370 buffer = | 370 buffer = |
371 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); | 371 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
372 { | 372 { |
373 // Kill A2 via session close (posts a task to disconnect, but A2 must not | 373 // Kill A2 via session close (posts a task to disconnect, but A2 must not |
374 // be sent either of these two buffers). | 374 // be sent either of these two buffers). |
375 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); | 375 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); |
376 controller_->StopSession(200); | 376 controller_->StopSession(200); |
377 } | 377 } |
378 ASSERT_TRUE(buffer); | 378 ASSERT_TRUE(buffer); |
379 memset(buffer->data(), buffer_no++, buffer->size()); | 379 memset(buffer->data(), buffer_no++, buffer->size()); |
380 device_->OnIncomingCapturedBuffer(buffer, | 380 device_->OnIncomingCapturedBuffer(buffer, |
381 media::VideoFrame::I420, | 381 media::VideoFrame::I420, |
382 capture_resolution, | 382 capture_resolution, |
383 base::Time(), | 383 base::TimeTicks(), |
384 device_format.frame_rate); | 384 device_format.frame_rate); |
385 buffer = NULL; | 385 buffer = NULL; |
386 // B2 is the only client left, and is the only one that should | 386 // B2 is the only client left, and is the only one that should |
387 // get the buffer. | 387 // get the buffer. |
388 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(2); | 388 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(2); |
389 base::RunLoop().RunUntilIdle(); | 389 base::RunLoop().RunUntilIdle(); |
390 Mock::VerifyAndClearExpectations(client_a_.get()); | 390 Mock::VerifyAndClearExpectations(client_a_.get()); |
391 Mock::VerifyAndClearExpectations(client_b_.get()); | 391 Mock::VerifyAndClearExpectations(client_b_.get()); |
392 } | 392 } |
393 | 393 |
(...skipping 23 matching lines...) Expand all Loading... |
417 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 417 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
418 controller_->AddClient( | 418 controller_->AddClient( |
419 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); | 419 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); |
420 base::RunLoop().RunUntilIdle(); | 420 base::RunLoop().RunUntilIdle(); |
421 Mock::VerifyAndClearExpectations(client_b_.get()); | 421 Mock::VerifyAndClearExpectations(client_b_.get()); |
422 | 422 |
423 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = | 423 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = |
424 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); | 424 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
425 ASSERT_TRUE(buffer); | 425 ASSERT_TRUE(buffer); |
426 | 426 |
427 device_->OnIncomingCapturedBuffer( | 427 device_->OnIncomingCapturedBuffer(buffer, |
428 buffer, media::VideoFrame::I420, capture_resolution, base::Time(), 30); | 428 media::VideoFrame::I420, |
| 429 capture_resolution, |
| 430 base::TimeTicks(), |
| 431 30); |
429 buffer = NULL; | 432 buffer = NULL; |
430 | 433 |
431 base::RunLoop().RunUntilIdle(); | 434 base::RunLoop().RunUntilIdle(); |
432 } | 435 } |
433 | 436 |
434 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 437 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
435 // behavior of various operations after the error state has been signalled. | 438 // behavior of various operations after the error state has been signalled. |
436 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { | 439 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { |
437 media::VideoCaptureParams session_100; | 440 media::VideoCaptureParams session_100; |
438 session_100.requested_format = media::VideoCaptureFormat( | 441 session_100.requested_format = media::VideoCaptureFormat( |
(...skipping 17 matching lines...) Expand all Loading... |
456 | 459 |
457 const gfx::Size dims(320, 240); | 460 const gfx::Size dims(320, 240); |
458 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = | 461 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = |
459 device_->ReserveOutputBuffer(media::VideoFrame::I420, dims); | 462 device_->ReserveOutputBuffer(media::VideoFrame::I420, dims); |
460 ASSERT_TRUE(buffer); | 463 ASSERT_TRUE(buffer); |
461 | 464 |
462 device_->OnError(); | 465 device_->OnError(); |
463 device_->OnIncomingCapturedBuffer(buffer, | 466 device_->OnIncomingCapturedBuffer(buffer, |
464 media::VideoFrame::I420, | 467 media::VideoFrame::I420, |
465 dims, | 468 dims, |
466 base::Time(), | 469 base::TimeTicks(), |
467 device_format.frame_rate); | 470 device_format.frame_rate); |
468 buffer = NULL; | 471 buffer = NULL; |
469 | 472 |
470 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); | 473 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); |
471 base::RunLoop().RunUntilIdle(); | 474 base::RunLoop().RunUntilIdle(); |
472 Mock::VerifyAndClearExpectations(client_a_.get()); | 475 Mock::VerifyAndClearExpectations(client_a_.get()); |
473 | 476 |
474 // Second client connects after the error state. It also should get told of | 477 // Second client connects after the error state. It also should get told of |
475 // the error. | 478 // the error. |
476 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 479 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
477 controller_->AddClient( | 480 controller_->AddClient( |
478 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); | 481 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); |
479 Mock::VerifyAndClearExpectations(client_b_.get()); | 482 Mock::VerifyAndClearExpectations(client_b_.get()); |
480 } | 483 } |
481 | 484 |
482 } // namespace content | 485 } // namespace content |
OLD | NEW |