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

Side by Side Diff: content/browser/renderer_host/media/video_capture_controller_unittest.cc

Issue 1267883002: Pass GpuMemoryBuffer backed VideoFrame from browser to renderer processes (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gmbtracker-multiple
Patch Set: reveman@ comment: remove multiple textures. Created 5 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 unified diff | Download patch
OLDNEW
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 public: 44 public:
45 explicit MockVideoCaptureControllerEventHandler( 45 explicit MockVideoCaptureControllerEventHandler(
46 VideoCaptureController* controller) 46 VideoCaptureController* controller)
47 : controller_(controller), 47 : controller_(controller),
48 resource_utilization_(-1.0) {} 48 resource_utilization_(-1.0) {}
49 ~MockVideoCaptureControllerEventHandler() override {} 49 ~MockVideoCaptureControllerEventHandler() override {}
50 50
51 // These mock methods are delegated to by our fake implementation of 51 // These mock methods are delegated to by our fake implementation of
52 // VideoCaptureControllerEventHandler, to be used in EXPECT_CALL(). 52 // VideoCaptureControllerEventHandler, to be used in EXPECT_CALL().
53 MOCK_METHOD1(DoBufferCreated, void(VideoCaptureControllerID)); 53 MOCK_METHOD1(DoBufferCreated, void(VideoCaptureControllerID));
54 MOCK_METHOD1(DoGpuMemoryBufferCreated, void(VideoCaptureControllerID));
reveman 2015/08/26 11:54:04 DoBufferCreated2?
emircan 2015/08/26 21:23:11 Done.
54 MOCK_METHOD1(DoBufferDestroyed, void(VideoCaptureControllerID)); 55 MOCK_METHOD1(DoBufferDestroyed, void(VideoCaptureControllerID));
55 MOCK_METHOD2(DoI420BufferReady, 56 MOCK_METHOD2(DoI420BufferReady,
56 void(VideoCaptureControllerID, const gfx::Size&)); 57 void(VideoCaptureControllerID, const gfx::Size&));
57 MOCK_METHOD2(DoTextureBufferReady, 58 MOCK_METHOD2(DoTextureBufferReady,
58 void(VideoCaptureControllerID, const gfx::Size&)); 59 void(VideoCaptureControllerID, const gfx::Size&));
59 MOCK_METHOD1(DoEnded, void(VideoCaptureControllerID)); 60 MOCK_METHOD1(DoEnded, void(VideoCaptureControllerID));
60 MOCK_METHOD1(DoError, void(VideoCaptureControllerID)); 61 MOCK_METHOD1(DoError, void(VideoCaptureControllerID));
61 62
62 void OnError(VideoCaptureControllerID id) override { 63 void OnError(VideoCaptureControllerID id) override {
63 DoError(id); 64 DoError(id);
64 } 65 }
65 void OnBufferCreated(VideoCaptureControllerID id, 66 void OnBufferCreated(VideoCaptureControllerID id,
66 base::SharedMemoryHandle handle, 67 base::SharedMemoryHandle handle,
67 int length, int buffer_id) override { 68 int length, int buffer_id) override {
68 DoBufferCreated(id); 69 DoBufferCreated(id);
69 } 70 }
71 void OnBufferCreated2(
72 VideoCaptureControllerID id,
73 const std::vector<gfx::GpuMemoryBufferHandle>& gmb_handles,
reveman 2015/08/26 11:54:04 nit: s/gmb_handles/handles/
emircan 2015/08/26 21:23:11 Done.
74 const gfx::Size& size,
75 int buffer_id) override {
76 DoGpuMemoryBufferCreated(id);
77 }
70 void OnBufferDestroyed(VideoCaptureControllerID id, int buffer_id) override { 78 void OnBufferDestroyed(VideoCaptureControllerID id, int buffer_id) override {
71 DoBufferDestroyed(id); 79 DoBufferDestroyed(id);
72 } 80 }
73 void OnBufferReady(VideoCaptureControllerID id, 81 void OnBufferReady(VideoCaptureControllerID id,
74 int buffer_id, 82 int buffer_id,
75 const scoped_refptr<media::VideoFrame>& frame, 83 const scoped_refptr<media::VideoFrame>& frame,
76 const base::TimeTicks& timestamp) override { 84 const base::TimeTicks& timestamp) override {
77 if (!frame->HasTextures()) { 85 if (!frame->HasTextures()) {
78 EXPECT_EQ(frame->format(), media::PIXEL_FORMAT_I420); 86 EXPECT_EQ(frame->format(), media::PIXEL_FORMAT_I420);
79 DoI420BufferReady(id, frame->coded_size()); 87 DoI420BufferReady(id, frame->coded_size());
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 // Now, simulate an incoming captured buffer from the capture device. As a 319 // Now, simulate an incoming captured buffer from the capture device. As a
312 // side effect this will cause the first buffer to be shared with clients. 320 // side effect this will cause the first buffer to be shared with clients.
313 uint8 buffer_no = 1; 321 uint8 buffer_no = 1;
314 ASSERT_EQ(0.0, device_->GetBufferPoolUtilization()); 322 ASSERT_EQ(0.0, device_->GetBufferPoolUtilization());
315 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( 323 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer(
316 device_->ReserveOutputBuffer(capture_resolution, 324 device_->ReserveOutputBuffer(capture_resolution,
317 media::VIDEO_CAPTURE_PIXEL_FORMAT_I420, 325 media::VIDEO_CAPTURE_PIXEL_FORMAT_I420,
318 media::PIXEL_STORAGE_CPU)); 326 media::PIXEL_STORAGE_CPU));
319 ASSERT_TRUE(buffer.get()); 327 ASSERT_TRUE(buffer.get());
320 ASSERT_EQ(1.0 / kPoolSize, device_->GetBufferPoolUtilization()); 328 ASSERT_EQ(1.0 / kPoolSize, device_->GetBufferPoolUtilization());
321 memset(buffer->data(), buffer_no++, buffer->size()); 329 memset(buffer->data(), buffer_no++, buffer->mapped_size());
322 { 330 {
323 InSequence s; 331 InSequence s;
324 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); 332 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1);
325 EXPECT_CALL(*client_a_, 333 EXPECT_CALL(*client_a_,
326 DoI420BufferReady(client_a_route_1, capture_resolution)) 334 DoI420BufferReady(client_a_route_1, capture_resolution))
327 .Times(1); 335 .Times(1);
328 } 336 }
329 { 337 {
330 InSequence s; 338 InSequence s;
331 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); 339 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1);
(...skipping 29 matching lines...) Expand all
361 ASSERT_EQ(0.5, resource_utilization_in_metadata); 369 ASSERT_EQ(0.5, resource_utilization_in_metadata);
362 370
363 // Second buffer which ought to use the same shared memory buffer. In this 371 // Second buffer which ought to use the same shared memory buffer. In this
364 // case pretend that the Buffer pointer is held by the device for a long 372 // case pretend that the Buffer pointer is held by the device for a long
365 // delay. This shouldn't affect anything. 373 // delay. This shouldn't affect anything.
366 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 = 374 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 =
367 device_->ReserveOutputBuffer(capture_resolution, 375 device_->ReserveOutputBuffer(capture_resolution,
368 media::VIDEO_CAPTURE_PIXEL_FORMAT_I420, 376 media::VIDEO_CAPTURE_PIXEL_FORMAT_I420,
369 media::PIXEL_STORAGE_CPU); 377 media::PIXEL_STORAGE_CPU);
370 ASSERT_TRUE(buffer2.get()); 378 ASSERT_TRUE(buffer2.get());
371 memset(buffer2->data(), buffer_no++, buffer2->size()); 379 memset(buffer2->data(), buffer_no++, buffer2->mapped_size());
372 video_frame = 380 video_frame =
373 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer2->data())); 381 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer2->data()));
374 ASSERT_FALSE(video_frame->metadata()->HasKey( 382 ASSERT_FALSE(video_frame->metadata()->HasKey(
375 media::VideoFrameMetadata::RESOURCE_UTILIZATION)); 383 media::VideoFrameMetadata::RESOURCE_UTILIZATION));
376 client_a_->resource_utilization_ = 0.5; 384 client_a_->resource_utilization_ = 0.5;
377 client_b_->resource_utilization_ = 3.14; 385 client_b_->resource_utilization_ = 3.14;
378 device_->OnIncomingCapturedVideoFrame(buffer2.Pass(), video_frame, 386 device_->OnIncomingCapturedVideoFrame(buffer2.Pass(), video_frame,
379 base::TimeTicks()); 387 base::TimeTicks());
380 388
381 // The buffer should be delivered to the clients in any order. 389 // The buffer should be delivered to the clients in any order.
(...skipping 25 matching lines...) Expand all
407 session_1); 415 session_1);
408 Mock::VerifyAndClearExpectations(client_b_.get()); 416 Mock::VerifyAndClearExpectations(client_b_.get());
409 417
410 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. 418 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time.
411 for (int i = 0; i < kPoolSize; i++) { 419 for (int i = 0; i < kPoolSize; i++) {
412 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = 420 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer =
413 device_->ReserveOutputBuffer(capture_resolution, 421 device_->ReserveOutputBuffer(capture_resolution,
414 media::VIDEO_CAPTURE_PIXEL_FORMAT_I420, 422 media::VIDEO_CAPTURE_PIXEL_FORMAT_I420,
415 media::PIXEL_STORAGE_CPU); 423 media::PIXEL_STORAGE_CPU);
416 ASSERT_TRUE(buffer.get()); 424 ASSERT_TRUE(buffer.get());
417 memset(buffer->data(), buffer_no++, buffer->size()); 425 memset(buffer->data(), buffer_no++, buffer->mapped_size());
418 video_frame = 426 video_frame =
419 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer->data())); 427 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer->data()));
420 device_->OnIncomingCapturedVideoFrame(buffer.Pass(), video_frame, 428 device_->OnIncomingCapturedVideoFrame(buffer.Pass(), video_frame,
421 base::TimeTicks()); 429 base::TimeTicks());
422 } 430 }
423 // ReserveOutputBuffer ought to fail now, because the pool is depleted. 431 // ReserveOutputBuffer ought to fail now, because the pool is depleted.
424 ASSERT_FALSE( 432 ASSERT_FALSE(
425 device_->ReserveOutputBuffer(capture_resolution, 433 device_->ReserveOutputBuffer(capture_resolution,
426 media::VIDEO_CAPTURE_PIXEL_FORMAT_I420, 434 media::VIDEO_CAPTURE_PIXEL_FORMAT_I420,
427 media::PIXEL_STORAGE_CPU).get()); 435 media::PIXEL_STORAGE_CPU).get());
(...skipping 27 matching lines...) Expand all
455 controller_->RemoveClient(client_a_route_1, client_a_.get()); 463 controller_->RemoveClient(client_a_route_1, client_a_.get());
456 // Kill B1 via session close (posts a task to disconnect). 464 // Kill B1 via session close (posts a task to disconnect).
457 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); 465 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1);
458 controller_->StopSession(300); 466 controller_->StopSession(300);
459 // Queue up another buffer. 467 // Queue up another buffer.
460 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer3 = 468 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer3 =
461 device_->ReserveOutputBuffer(capture_resolution, 469 device_->ReserveOutputBuffer(capture_resolution,
462 media::VIDEO_CAPTURE_PIXEL_FORMAT_I420, 470 media::VIDEO_CAPTURE_PIXEL_FORMAT_I420,
463 media::PIXEL_STORAGE_CPU); 471 media::PIXEL_STORAGE_CPU);
464 ASSERT_TRUE(buffer3.get()); 472 ASSERT_TRUE(buffer3.get());
465 memset(buffer3->data(), buffer_no++, buffer3->size()); 473 memset(buffer3->data(), buffer_no++, buffer3->mapped_size());
466 video_frame = 474 video_frame =
467 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer3->data())); 475 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer3->data()));
468 device_->OnIncomingCapturedVideoFrame(buffer3.Pass(), video_frame, 476 device_->OnIncomingCapturedVideoFrame(buffer3.Pass(), video_frame,
469 base::TimeTicks()); 477 base::TimeTicks());
470 478
471 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer4 = 479 scoped_ptr<media::VideoCaptureDevice::Client::Buffer> buffer4 =
472 device_->ReserveOutputBuffer(capture_resolution, 480 device_->ReserveOutputBuffer(capture_resolution,
473 media::VIDEO_CAPTURE_PIXEL_FORMAT_I420, 481 media::VIDEO_CAPTURE_PIXEL_FORMAT_I420,
474 media::PIXEL_STORAGE_CPU); 482 media::PIXEL_STORAGE_CPU);
475 { 483 {
476 // Kill A2 via session close (posts a task to disconnect, but A2 must not 484 // Kill A2 via session close (posts a task to disconnect, but A2 must not
477 // be sent either of these two buffers). 485 // be sent either of these two buffers).
478 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); 486 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1);
479 controller_->StopSession(200); 487 controller_->StopSession(200);
480 } 488 }
481 ASSERT_TRUE(buffer4.get()); 489 ASSERT_TRUE(buffer4.get());
482 memset(buffer4->data(), buffer_no++, buffer4->size()); 490 memset(buffer4->data(), buffer_no++, buffer4->mapped_size());
483 video_frame = 491 video_frame =
484 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer4->data())); 492 WrapI420Buffer(capture_resolution, static_cast<uint8*>(buffer4->data()));
485 device_->OnIncomingCapturedVideoFrame(buffer4.Pass(), video_frame, 493 device_->OnIncomingCapturedVideoFrame(buffer4.Pass(), video_frame,
486 base::TimeTicks()); 494 base::TimeTicks());
487 // B2 is the only client left, and is the only one that should 495 // B2 is the only client left, and is the only one that should
488 // get the buffer. 496 // get the buffer.
489 EXPECT_CALL(*client_b_, 497 EXPECT_CALL(*client_b_,
490 DoI420BufferReady(client_b_route_2, capture_resolution)) 498 DoI420BufferReady(client_b_route_2, capture_resolution))
491 .Times(2); 499 .Times(2);
492 base::RunLoop().RunUntilIdle(); 500 base::RunLoop().RunUntilIdle();
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 662
655 // Second client connects after the error state. It also should get told of 663 // Second client connects after the error state. It also should get told of
656 // the error. 664 // the error.
657 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); 665 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1);
658 controller_->AddClient( 666 controller_->AddClient(
659 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); 667 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200);
660 Mock::VerifyAndClearExpectations(client_b_.get()); 668 Mock::VerifyAndClearExpectations(client_b_.get());
661 } 669 }
662 670
663 } // namespace content 671 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698