| 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 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 289 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
| 290 | 290 |
| 291 media::VideoCaptureParams session_200 = session_100; | 291 media::VideoCaptureParams session_200 = session_100; |
| 292 | 292 |
| 293 media::VideoCaptureParams session_300 = session_100; | 293 media::VideoCaptureParams session_300 = session_100; |
| 294 | 294 |
| 295 media::VideoCaptureParams session_1 = session_100; | 295 media::VideoCaptureParams session_1 = session_100; |
| 296 | 296 |
| 297 const gfx::Size capture_resolution(444, 200); | 297 const gfx::Size capture_resolution(444, 200); |
| 298 | 298 |
| 299 const media::VideoCaptureFormat capture_format(capture_resolution, 0.0f, |
| 300 media::PIXEL_FORMAT_I420); |
| 301 const media::VideoCaptureFormat capture_format_texture( |
| 302 capture_resolution, 0.0f, media::PIXEL_FORMAT_ARGB, |
| 303 media::PIXEL_STORAGE_TEXTURE); |
| 304 |
| 299 // The device format needn't match the VideoCaptureParams (the camera can do | 305 // The device format needn't match the VideoCaptureParams (the camera can do |
| 300 // what it wants). Pick something random. | 306 // what it wants). Pick something random. |
| 301 media::VideoCaptureFormat device_format( | 307 media::VideoCaptureFormat device_format( |
| 302 gfx::Size(10, 10), 25, media::PIXEL_FORMAT_RGB24); | 308 gfx::Size(10, 10), 25, media::PIXEL_FORMAT_RGB24); |
| 303 | 309 |
| 304 const VideoCaptureControllerID client_a_route_1(0xa1a1a1a1); | 310 const VideoCaptureControllerID client_a_route_1(0xa1a1a1a1); |
| 305 const VideoCaptureControllerID client_a_route_2(0xa2a2a2a2); | 311 const VideoCaptureControllerID client_a_route_2(0xa2a2a2a2); |
| 306 const VideoCaptureControllerID client_b_route_1(0xb1b1b1b1); | 312 const VideoCaptureControllerID client_b_route_1(0xb1b1b1b1); |
| 307 const VideoCaptureControllerID client_b_route_2(0xb2b2b2b2); | 313 const VideoCaptureControllerID client_b_route_2(0xb2b2b2b2); |
| 308 | 314 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 321 client_a_.get(), | 327 client_a_.get(), |
| 322 base::kNullProcessHandle, | 328 base::kNullProcessHandle, |
| 323 200, | 329 200, |
| 324 session_200); | 330 session_200); |
| 325 ASSERT_EQ(3, controller_->GetClientCount()); | 331 ASSERT_EQ(3, controller_->GetClientCount()); |
| 326 | 332 |
| 327 // Now, simulate an incoming captured buffer from the capture device. As a | 333 // Now, simulate an incoming captured buffer from the capture device. As a |
| 328 // side effect this will cause the first buffer to be shared with clients. | 334 // side effect this will cause the first buffer to be shared with clients. |
| 329 uint8 buffer_no = 1; | 335 uint8 buffer_no = 1; |
| 330 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( | 336 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( |
| 331 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, | 337 device_->ReserveOutputBuffer(capture_format)); |
| 332 capture_resolution)); | |
| 333 ASSERT_TRUE(buffer.get()); | 338 ASSERT_TRUE(buffer.get()); |
| 334 memset(buffer->data(), buffer_no++, buffer->size()); | 339 memset(buffer->data(), buffer_no++, buffer->size()); |
| 335 { | 340 { |
| 336 InSequence s; | 341 InSequence s; |
| 337 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); | 342 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); |
| 338 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1,_)).Times(1); | 343 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1,_)).Times(1); |
| 339 } | 344 } |
| 340 { | 345 { |
| 341 InSequence s; | 346 InSequence s; |
| 342 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); | 347 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 364 double resource_utilization_in_metadata = -1.0; | 369 double resource_utilization_in_metadata = -1.0; |
| 365 ASSERT_TRUE(video_frame->metadata()->GetDouble( | 370 ASSERT_TRUE(video_frame->metadata()->GetDouble( |
| 366 media::VideoFrameMetadata::RESOURCE_UTILIZATION, | 371 media::VideoFrameMetadata::RESOURCE_UTILIZATION, |
| 367 &resource_utilization_in_metadata)); | 372 &resource_utilization_in_metadata)); |
| 368 ASSERT_EQ(0.5, resource_utilization_in_metadata); | 373 ASSERT_EQ(0.5, resource_utilization_in_metadata); |
| 369 | 374 |
| 370 // Second buffer which ought to use the same shared memory buffer. In this | 375 // Second buffer which ought to use the same shared memory buffer. In this |
| 371 // case pretend that the Buffer pointer is held by the device for a long | 376 // case pretend that the Buffer pointer is held by the device for a long |
| 372 // delay. This shouldn't affect anything. | 377 // delay. This shouldn't affect anything. |
| 373 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 = | 378 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 = |
| 374 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, | 379 device_->ReserveOutputBuffer(capture_format); |
| 375 capture_resolution); | |
| 376 ASSERT_TRUE(buffer2.get()); | 380 ASSERT_TRUE(buffer2.get()); |
| 377 memset(buffer2->data(), buffer_no++, buffer2->size()); | 381 memset(buffer2->data(), buffer_no++, buffer2->size()); |
| 378 video_frame = | 382 video_frame = |
| 379 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer2->data())); | 383 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer2->data())); |
| 380 ASSERT_FALSE(video_frame->metadata()->HasKey( | 384 ASSERT_FALSE(video_frame->metadata()->HasKey( |
| 381 media::VideoFrameMetadata::RESOURCE_UTILIZATION)); | 385 media::VideoFrameMetadata::RESOURCE_UTILIZATION)); |
| 382 client_a_->resource_utilization_ = 0.5; | 386 client_a_->resource_utilization_ = 0.5; |
| 383 client_b_->resource_utilization_ = 3.14; | 387 client_b_->resource_utilization_ = 3.14; |
| 384 device_->OnIncomingCapturedVideoFrame(buffer2.Pass(), video_frame, | 388 device_->OnIncomingCapturedVideoFrame(buffer2.Pass(), video_frame, |
| 385 base::TimeTicks()); | 389 base::TimeTicks()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 403 controller_->AddClient(client_b_route_2, | 407 controller_->AddClient(client_b_route_2, |
| 404 client_b_.get(), | 408 client_b_.get(), |
| 405 base::kNullProcessHandle, | 409 base::kNullProcessHandle, |
| 406 1, | 410 1, |
| 407 session_1); | 411 session_1); |
| 408 Mock::VerifyAndClearExpectations(client_b_.get()); | 412 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 409 | 413 |
| 410 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. | 414 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. |
| 411 for (int i = 0; i < kPoolSize; i++) { | 415 for (int i = 0; i < kPoolSize; i++) { |
| 412 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = | 416 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = |
| 413 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, | 417 device_->ReserveOutputBuffer(capture_format); |
| 414 capture_resolution); | |
| 415 ASSERT_TRUE(buffer.get()); | 418 ASSERT_TRUE(buffer.get()); |
| 416 memset(buffer->data(), buffer_no++, buffer->size()); | 419 memset(buffer->data(), buffer_no++, buffer->size()); |
| 417 video_frame = | 420 video_frame = |
| 418 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer->data())); | 421 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer->data())); |
| 419 device_->OnIncomingCapturedVideoFrame(buffer.Pass(), video_frame, | 422 device_->OnIncomingCapturedVideoFrame(buffer.Pass(), video_frame, |
| 420 base::TimeTicks()); | 423 base::TimeTicks()); |
| 421 } | 424 } |
| 422 // ReserveOutputBuffer ought to fail now, because the pool is depleted. | 425 // ReserveOutputBuffer ought to fail now, because the pool is depleted. |
| 423 ASSERT_FALSE(device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, | 426 ASSERT_FALSE(device_->ReserveOutputBuffer(capture_format).get()); |
| 424 capture_resolution).get()); | |
| 425 | 427 |
| 426 // The new client needs to be told of 3 buffers; the old clients only 2. | 428 // The new client needs to be told of 3 buffers; the old clients only 2. |
| 427 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); | 429 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); |
| 428 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2,_)).Times(kPoolSize); | 430 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2,_)).Times(kPoolSize); |
| 429 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) | 431 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) |
| 430 .Times(kPoolSize - 1); | 432 .Times(kPoolSize - 1); |
| 431 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1,_)).Times(kPoolSize); | 433 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1,_)).Times(kPoolSize); |
| 432 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)) | 434 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)) |
| 433 .Times(kPoolSize - 1); | 435 .Times(kPoolSize - 1); |
| 434 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2,_)).Times(kPoolSize); | 436 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2,_)).Times(kPoolSize); |
| 435 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)) | 437 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)) |
| 436 .Times(kPoolSize - 1); | 438 .Times(kPoolSize - 1); |
| 437 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1,_)).Times(kPoolSize); | 439 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1,_)).Times(kPoolSize); |
| 438 base::RunLoop().RunUntilIdle(); | 440 base::RunLoop().RunUntilIdle(); |
| 439 Mock::VerifyAndClearExpectations(client_a_.get()); | 441 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 440 Mock::VerifyAndClearExpectations(client_b_.get()); | 442 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 441 | 443 |
| 442 // Now test the interaction of client shutdown and buffer delivery. | 444 // Now test the interaction of client shutdown and buffer delivery. |
| 443 // Kill A1 via renderer disconnect (synchronous). | 445 // Kill A1 via renderer disconnect (synchronous). |
| 444 controller_->RemoveClient(client_a_route_1, client_a_.get()); | 446 controller_->RemoveClient(client_a_route_1, client_a_.get()); |
| 445 // Kill B1 via session close (posts a task to disconnect). | 447 // Kill B1 via session close (posts a task to disconnect). |
| 446 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); | 448 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); |
| 447 controller_->StopSession(300); | 449 controller_->StopSession(300); |
| 448 // Queue up another buffer. | 450 // Queue up another buffer. |
| 449 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer3 = | 451 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer3 = |
| 450 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, | 452 device_->ReserveOutputBuffer(capture_format); |
| 451 capture_resolution); | |
| 452 ASSERT_TRUE(buffer3.get()); | 453 ASSERT_TRUE(buffer3.get()); |
| 453 memset(buffer3->data(), buffer_no++, buffer3->size()); | 454 memset(buffer3->data(), buffer_no++, buffer3->size()); |
| 454 video_frame = | 455 video_frame = |
| 455 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer3->data())); | 456 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer3->data())); |
| 456 device_->OnIncomingCapturedVideoFrame(buffer3.Pass(), video_frame, | 457 device_->OnIncomingCapturedVideoFrame(buffer3.Pass(), video_frame, |
| 457 base::TimeTicks()); | 458 base::TimeTicks()); |
| 458 | 459 |
| 459 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer4 = | 460 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer4 = |
| 460 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, | 461 device_->ReserveOutputBuffer(capture_format); |
| 461 capture_resolution); | |
| 462 { | 462 { |
| 463 // Kill A2 via session close (posts a task to disconnect, but A2 must not | 463 // Kill A2 via session close (posts a task to disconnect, but A2 must not |
| 464 // be sent either of these two buffers). | 464 // be sent either of these two buffers). |
| 465 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); | 465 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); |
| 466 controller_->StopSession(200); | 466 controller_->StopSession(200); |
| 467 } | 467 } |
| 468 ASSERT_TRUE(buffer4.get()); | 468 ASSERT_TRUE(buffer4.get()); |
| 469 memset(buffer4->data(), buffer_no++, buffer4->size()); | 469 memset(buffer4->data(), buffer_no++, buffer4->size()); |
| 470 video_frame = | 470 video_frame = |
| 471 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer4->data())); | 471 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer4->data())); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 486 int mailbox_buffers = kPoolSize / 2; | 486 int mailbox_buffers = kPoolSize / 2; |
| 487 #endif | 487 #endif |
| 488 int shm_buffers = kPoolSize - mailbox_buffers; | 488 int shm_buffers = kPoolSize - mailbox_buffers; |
| 489 if (shm_buffers == mailbox_buffers) { | 489 if (shm_buffers == mailbox_buffers) { |
| 490 shm_buffers--; | 490 shm_buffers--; |
| 491 mailbox_buffers++; | 491 mailbox_buffers++; |
| 492 } | 492 } |
| 493 | 493 |
| 494 for (int i = 0; i < shm_buffers; ++i) { | 494 for (int i = 0; i < shm_buffers; ++i) { |
| 495 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = | 495 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = |
| 496 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, | 496 device_->ReserveOutputBuffer(capture_format); |
| 497 capture_resolution); | |
| 498 ASSERT_TRUE(buffer.get()); | 497 ASSERT_TRUE(buffer.get()); |
| 499 video_frame = | 498 video_frame = |
| 500 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer->data())); | 499 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer->data())); |
| 501 device_->OnIncomingCapturedVideoFrame(buffer.Pass(), video_frame, | 500 device_->OnIncomingCapturedVideoFrame(buffer.Pass(), video_frame, |
| 502 base::TimeTicks()); | 501 base::TimeTicks()); |
| 503 } | 502 } |
| 504 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); | 503 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); |
| 505 std::vector<uint32> release_syncpoints(mailbox_buffers); | 504 std::vector<uint32> release_syncpoints(mailbox_buffers); |
| 506 for (int i = 0; i < mailbox_buffers; ++i) { | 505 for (int i = 0; i < mailbox_buffers; ++i) { |
| 507 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = | 506 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = |
| 508 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_TEXTURE, | 507 device_->ReserveOutputBuffer(capture_format_texture); |
| 509 capture_resolution); | |
| 510 ASSERT_TRUE(buffer.get()); | 508 ASSERT_TRUE(buffer.get()); |
| 511 #if !defined(OS_ANDROID) | 509 #if !defined(OS_ANDROID) |
| 512 mailbox_syncpoints[i] = | 510 mailbox_syncpoints[i] = |
| 513 ImageTransportFactory::GetInstance()->GetGLHelper()->InsertSyncPoint(); | 511 ImageTransportFactory::GetInstance()->GetGLHelper()->InsertSyncPoint(); |
| 514 #endif | 512 #endif |
| 515 device_->OnIncomingCapturedVideoFrame( | 513 device_->OnIncomingCapturedVideoFrame( |
| 516 buffer.Pass(), | 514 buffer.Pass(), |
| 517 WrapMailboxBuffer(gpu::MailboxHolder(gpu::Mailbox::Generate(), 0, | 515 WrapMailboxBuffer(gpu::MailboxHolder(gpu::Mailbox::Generate(), 0, |
| 518 mailbox_syncpoints[i]), | 516 mailbox_syncpoints[i]), |
| 519 base::Bind(&CacheSyncPoint, &release_syncpoints[i]), | 517 base::Bind(&CacheSyncPoint, &release_syncpoints[i]), |
| 520 capture_resolution), | 518 capture_resolution), |
| 521 base::TimeTicks()); | 519 base::TimeTicks()); |
| 522 } | 520 } |
| 523 // ReserveOutputBuffers ought to fail now regardless of buffer format, because | 521 // ReserveOutputBuffers ought to fail now regardless of buffer format, because |
| 524 // the pool is depleted. | 522 // the pool is depleted. |
| 525 ASSERT_FALSE(device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, | 523 ASSERT_FALSE(device_->ReserveOutputBuffer(capture_format).get()); |
| 526 capture_resolution).get()); | 524 ASSERT_FALSE(device_->ReserveOutputBuffer(capture_format_texture).get()); |
| 527 ASSERT_FALSE(device_->ReserveOutputBuffer(media::PIXEL_FORMAT_TEXTURE, | |
| 528 capture_resolution).get()); | |
| 529 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2,_)).Times(shm_buffers); | 525 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2,_)).Times(shm_buffers); |
| 530 EXPECT_CALL(*client_b_, DoMailboxBufferReady(client_b_route_2)) | 526 EXPECT_CALL(*client_b_, DoMailboxBufferReady(client_b_route_2)) |
| 531 .Times(mailbox_buffers); | 527 .Times(mailbox_buffers); |
| 532 #if !defined(OS_ANDROID) | 528 #if !defined(OS_ANDROID) |
| 533 EXPECT_CALL(*client_b_, DoBufferDestroyed(client_b_route_2)); | 529 EXPECT_CALL(*client_b_, DoBufferDestroyed(client_b_route_2)); |
| 534 #endif | 530 #endif |
| 535 base::RunLoop().RunUntilIdle(); | 531 base::RunLoop().RunUntilIdle(); |
| 536 for (size_t i = 0; i < mailbox_syncpoints.size(); ++i) { | 532 for (size_t i = 0; i < mailbox_syncpoints.size(); ++i) { |
| 537 // A new release sync point must be inserted when the video frame is | 533 // A new release sync point must be inserted when the video frame is |
| 538 // returned to the Browser process. | 534 // returned to the Browser process. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 550 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 546 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
| 551 // behavior of various operations after the error state has been signalled. | 547 // behavior of various operations after the error state has been signalled. |
| 552 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { | 548 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { |
| 553 media::VideoCaptureParams session_100; | 549 media::VideoCaptureParams session_100; |
| 554 session_100.requested_format = media::VideoCaptureFormat( | 550 session_100.requested_format = media::VideoCaptureFormat( |
| 555 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 551 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
| 556 | 552 |
| 557 media::VideoCaptureParams session_200 = session_100; | 553 media::VideoCaptureParams session_200 = session_100; |
| 558 | 554 |
| 559 const gfx::Size capture_resolution(320, 240); | 555 const gfx::Size capture_resolution(320, 240); |
| 556 const media::VideoCaptureFormat capture_format(capture_resolution, 0.0f, |
| 557 media::PIXEL_FORMAT_I420); |
| 560 | 558 |
| 561 const VideoCaptureControllerID route_id(0x99); | 559 const VideoCaptureControllerID route_id(0x99); |
| 562 | 560 |
| 563 // Start with one client. | 561 // Start with one client. |
| 564 controller_->AddClient( | 562 controller_->AddClient( |
| 565 route_id, client_a_.get(), base::kNullProcessHandle, 100, session_100); | 563 route_id, client_a_.get(), base::kNullProcessHandle, 100, session_100); |
| 566 device_->OnError("Test Error"); | 564 device_->OnError("Test Error"); |
| 567 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); | 565 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); |
| 568 base::RunLoop().RunUntilIdle(); | 566 base::RunLoop().RunUntilIdle(); |
| 569 Mock::VerifyAndClearExpectations(client_a_.get()); | 567 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 570 | 568 |
| 571 // Second client connects after the error state. It also should get told of | 569 // Second client connects after the error state. It also should get told of |
| 572 // the error. | 570 // the error. |
| 573 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 571 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
| 574 controller_->AddClient( | 572 controller_->AddClient( |
| 575 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); | 573 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); |
| 576 base::RunLoop().RunUntilIdle(); | 574 base::RunLoop().RunUntilIdle(); |
| 577 Mock::VerifyAndClearExpectations(client_b_.get()); | 575 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 578 | 576 |
| 579 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( | 577 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( |
| 580 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, | 578 device_->ReserveOutputBuffer(capture_format)); |
| 581 capture_resolution)); | |
| 582 ASSERT_TRUE(buffer.get()); | 579 ASSERT_TRUE(buffer.get()); |
| 583 scoped_refptr<media::VideoFrame> video_frame = | 580 scoped_refptr<media::VideoFrame> video_frame = |
| 584 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer->data())); | 581 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer->data())); |
| 585 device_->OnIncomingCapturedVideoFrame(buffer.Pass(), video_frame, | 582 device_->OnIncomingCapturedVideoFrame(buffer.Pass(), video_frame, |
| 586 base::TimeTicks()); | 583 base::TimeTicks()); |
| 587 | 584 |
| 588 base::RunLoop().RunUntilIdle(); | 585 base::RunLoop().RunUntilIdle(); |
| 589 } | 586 } |
| 590 | 587 |
| 591 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 588 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
| (...skipping 13 matching lines...) Expand all Loading... |
| 605 media::VideoCaptureFormat device_format( | 602 media::VideoCaptureFormat device_format( |
| 606 gfx::Size(10, 10), 25, media::PIXEL_FORMAT_ARGB); | 603 gfx::Size(10, 10), 25, media::PIXEL_FORMAT_ARGB); |
| 607 | 604 |
| 608 // Start the device. Then, before the first buffer, signal an error and | 605 // Start the device. Then, before the first buffer, signal an error and |
| 609 // deliver the buffer. The error should be propagated to clients; the buffer | 606 // deliver the buffer. The error should be propagated to clients; the buffer |
| 610 // should not be. | 607 // should not be. |
| 611 base::RunLoop().RunUntilIdle(); | 608 base::RunLoop().RunUntilIdle(); |
| 612 Mock::VerifyAndClearExpectations(client_a_.get()); | 609 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 613 | 610 |
| 614 const gfx::Size dims(320, 240); | 611 const gfx::Size dims(320, 240); |
| 612 const media::VideoCaptureFormat capture_format(dims, 0.0f, |
| 613 media::PIXEL_FORMAT_I420); |
| 615 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( | 614 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( |
| 616 device_->ReserveOutputBuffer(media::PIXEL_FORMAT_I420, dims)); | 615 device_->ReserveOutputBuffer(capture_format)); |
| 617 ASSERT_TRUE(buffer.get()); | 616 ASSERT_TRUE(buffer.get()); |
| 618 | 617 |
| 619 scoped_refptr<media::VideoFrame> video_frame = | 618 scoped_refptr<media::VideoFrame> video_frame = |
| 620 WrapI420Buffer(dims, static_cast<uint8*>(buffer->data())); | 619 WrapI420Buffer(dims, static_cast<uint8*>(buffer->data())); |
| 621 device_->OnError("Test Error"); | 620 device_->OnError("Test Error"); |
| 622 device_->OnIncomingCapturedVideoFrame(buffer.Pass(), video_frame, | 621 device_->OnIncomingCapturedVideoFrame(buffer.Pass(), video_frame, |
| 623 base::TimeTicks()); | 622 base::TimeTicks()); |
| 624 | 623 |
| 625 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); | 624 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); |
| 626 base::RunLoop().RunUntilIdle(); | 625 base::RunLoop().RunUntilIdle(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 642 // buffer. | 641 // buffer. |
| 643 const size_t kScratchpadSizeInBytes = 400; | 642 const size_t kScratchpadSizeInBytes = 400; |
| 644 unsigned char data[kScratchpadSizeInBytes]; | 643 unsigned char data[kScratchpadSizeInBytes]; |
| 645 // Initialize memory to satisfy DrMemory tests. | 644 // Initialize memory to satisfy DrMemory tests. |
| 646 memset(data, 0, kScratchpadSizeInBytes); | 645 memset(data, 0, kScratchpadSizeInBytes); |
| 647 const gfx::Size capture_resolution(10, 10); | 646 const gfx::Size capture_resolution(10, 10); |
| 648 ASSERT_GE(kScratchpadSizeInBytes, capture_resolution.GetArea() * 4u) | 647 ASSERT_GE(kScratchpadSizeInBytes, capture_resolution.GetArea() * 4u) |
| 649 << "Scratchpad is too small to hold the largest pixel format (ARGB)."; | 648 << "Scratchpad is too small to hold the largest pixel format (ARGB)."; |
| 650 | 649 |
| 651 const int kSessionId = 100; | 650 const int kSessionId = 100; |
| 652 // This Test skips PIXEL_FORMAT_TEXTURE and PIXEL_FORMAT_UNKNOWN. | 651 // This Test skips PIXEL_FORMAT_UNKNOWN. |
| 653 for (int format = 0; format < media::PIXEL_FORMAT_TEXTURE; ++format) { | 652 for (int format = 0; format < media::PIXEL_FORMAT_UNKNOWN; ++format) { |
| 654 media::VideoCaptureParams params; | 653 media::VideoCaptureParams params; |
| 655 params.requested_format = media::VideoCaptureFormat( | 654 params.requested_format = media::VideoCaptureFormat( |
| 656 capture_resolution, 30, media::VideoPixelFormat(format)); | 655 capture_resolution, 30, media::VideoPixelFormat(format)); |
| 657 | 656 |
| 658 // Start with one client. | 657 // Start with one client. |
| 659 const VideoCaptureControllerID route_id(0x99); | 658 const VideoCaptureControllerID route_id(0x99); |
| 660 controller_->AddClient(route_id, | 659 controller_->AddClient(route_id, |
| 661 client_a_.get(), | 660 client_a_.get(), |
| 662 base::kNullProcessHandle, | 661 base::kNullProcessHandle, |
| 663 kSessionId, | 662 kSessionId, |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 730 EXPECT_EQ(coded_size.width(), size_and_rotation.output_resolution.width()); | 729 EXPECT_EQ(coded_size.width(), size_and_rotation.output_resolution.width()); |
| 731 EXPECT_EQ(coded_size.height(), | 730 EXPECT_EQ(coded_size.height(), |
| 732 size_and_rotation.output_resolution.height()); | 731 size_and_rotation.output_resolution.height()); |
| 733 | 732 |
| 734 EXPECT_EQ(kSessionId, controller_->RemoveClient(route_id, client_a_.get())); | 733 EXPECT_EQ(kSessionId, controller_->RemoveClient(route_id, client_a_.get())); |
| 735 Mock::VerifyAndClearExpectations(client_a_.get()); | 734 Mock::VerifyAndClearExpectations(client_a_.get()); |
| 736 } | 735 } |
| 737 } | 736 } |
| 738 | 737 |
| 739 } // namespace content | 738 } // namespace content |
| OLD | NEW |