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

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

Issue 2121043002: 16 bpp video stream capture, render and WebGL usage - Realsense R200 & SR300 support. Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 2 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 "content/browser/renderer_host/media/video_capture_controller.h" 7 #include "content/browser/renderer_host/media/video_capture_controller.h"
8 8
9 #include <stdint.h> 9 #include <stdint.h>
10 #include <string.h> 10 #include <string.h>
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(DoBufferDestroyed, void(VideoCaptureControllerID)); 54 MOCK_METHOD1(DoBufferDestroyed, void(VideoCaptureControllerID));
55 MOCK_METHOD2(DoI420BufferReady, 55 MOCK_METHOD2(DoBufferReady, void(VideoCaptureControllerID, const gfx::Size&));
56 void(VideoCaptureControllerID, const gfx::Size&));
57 MOCK_METHOD1(DoEnded, void(VideoCaptureControllerID)); 56 MOCK_METHOD1(DoEnded, void(VideoCaptureControllerID));
58 MOCK_METHOD1(DoError, void(VideoCaptureControllerID)); 57 MOCK_METHOD1(DoError, void(VideoCaptureControllerID));
59 58
60 void OnError(VideoCaptureControllerID id) override { 59 void OnError(VideoCaptureControllerID id) override {
61 DoError(id); 60 DoError(id);
62 } 61 }
63 void OnBufferCreated(VideoCaptureControllerID id, 62 void OnBufferCreated(VideoCaptureControllerID id,
64 base::SharedMemoryHandle handle, 63 base::SharedMemoryHandle handle,
65 int length, int buffer_id) override { 64 int length, int buffer_id) override {
66 DoBufferCreated(id); 65 DoBufferCreated(id);
67 } 66 }
68 void OnBufferDestroyed(VideoCaptureControllerID id, int buffer_id) override { 67 void OnBufferDestroyed(VideoCaptureControllerID id, int buffer_id) override {
69 DoBufferDestroyed(id); 68 DoBufferDestroyed(id);
70 } 69 }
71 void OnBufferReady(VideoCaptureControllerID id, 70 void OnBufferReady(VideoCaptureControllerID id,
72 int buffer_id, 71 int buffer_id,
73 const scoped_refptr<media::VideoFrame>& frame) override { 72 const scoped_refptr<media::VideoFrame>& frame) override {
74 EXPECT_EQ(frame->format(), media::PIXEL_FORMAT_I420); 73 EXPECT_EQ(frame->format(), expect_buffer_format_);
75 base::TimeTicks reference_time; 74 base::TimeTicks reference_time;
76 EXPECT_TRUE(frame->metadata()->GetTimeTicks( 75 EXPECT_TRUE(frame->metadata()->GetTimeTicks(
77 media::VideoFrameMetadata::REFERENCE_TIME, &reference_time)); 76 media::VideoFrameMetadata::REFERENCE_TIME, &reference_time));
78 DoI420BufferReady(id, frame->coded_size()); 77 DoBufferReady(id, frame->coded_size());
79 base::ThreadTaskRunnerHandle::Get()->PostTask( 78 base::ThreadTaskRunnerHandle::Get()->PostTask(
80 FROM_HERE, 79 FROM_HERE,
81 base::Bind(&VideoCaptureController::ReturnBuffer, 80 base::Bind(&VideoCaptureController::ReturnBuffer,
82 base::Unretained(controller_), id, this, buffer_id, 81 base::Unretained(controller_), id, this, buffer_id,
83 gpu::SyncToken(), resource_utilization_)); 82 gpu::SyncToken(), resource_utilization_));
84 } 83 }
85 void OnEnded(VideoCaptureControllerID id) override { 84 void OnEnded(VideoCaptureControllerID id) override {
86 DoEnded(id); 85 DoEnded(id);
87 // OnEnded() must respond by (eventually) unregistering the client. 86 // OnEnded() must respond by (eventually) unregistering the client.
88 base::ThreadTaskRunnerHandle::Get()->PostTask( 87 base::ThreadTaskRunnerHandle::Get()->PostTask(
89 FROM_HERE, 88 FROM_HERE,
90 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), 89 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient),
91 base::Unretained(controller_), id, this)); 90 base::Unretained(controller_), id, this));
92 } 91 }
93 92
94 VideoCaptureController* controller_; 93 VideoCaptureController* controller_;
94 media::VideoPixelFormat expect_buffer_format_ = media::PIXEL_FORMAT_I420;
95 double resource_utilization_; 95 double resource_utilization_;
96 }; 96 };
97 97
98 // Test class. 98 // Test class.
99 class VideoCaptureControllerTest : public testing::Test { 99 class VideoCaptureControllerTest
100 : public testing::Test,
101 public testing::WithParamInterface<media::VideoPixelFormat> {
100 public: 102 public:
101 VideoCaptureControllerTest() {} 103 VideoCaptureControllerTest() {}
102 ~VideoCaptureControllerTest() override {} 104 ~VideoCaptureControllerTest() override {}
103 105
104 protected: 106 protected:
105 static const int kPoolSize = 3; 107 static const int kPoolSize = 3;
106 108
107 void SetUp() override { 109 void SetUp() override {
108 controller_.reset(new VideoCaptureController(kPoolSize)); 110 controller_.reset(new VideoCaptureController(kPoolSize));
109 device_ = controller_->NewDeviceClient(); 111 device_ = controller_->NewDeviceClient();
110 client_a_.reset(new MockVideoCaptureControllerEventHandler( 112 client_a_.reset(new MockVideoCaptureControllerEventHandler(
111 controller_.get())); 113 controller_.get()));
112 client_b_.reset(new MockVideoCaptureControllerEventHandler( 114 client_b_.reset(new MockVideoCaptureControllerEventHandler(
113 controller_.get())); 115 controller_.get()));
114 } 116 }
115 117
116 void TearDown() override { base::RunLoop().RunUntilIdle(); } 118 void TearDown() override { base::RunLoop().RunUntilIdle(); }
117 119
118 scoped_refptr<media::VideoFrame> WrapI420Buffer(gfx::Size dimensions, 120 scoped_refptr<media::VideoFrame> WrapBuffer(
119 uint8_t* data) { 121 gfx::Size dimensions,
122 uint8_t* data,
123 media::VideoPixelFormat format = media::PIXEL_FORMAT_I420) {
120 scoped_refptr<media::VideoFrame> video_frame = 124 scoped_refptr<media::VideoFrame> video_frame =
121 media::VideoFrame::WrapExternalSharedMemory( 125 media::VideoFrame::WrapExternalSharedMemory(
122 media::PIXEL_FORMAT_I420, dimensions, gfx::Rect(dimensions), 126 format, dimensions, gfx::Rect(dimensions), dimensions, data,
123 dimensions, data, media::VideoFrame::AllocationSize( 127 media::VideoFrame::AllocationSize(format, dimensions),
124 media::PIXEL_FORMAT_I420, dimensions),
125 base::SharedMemory::NULLHandle(), 0u, base::TimeDelta()); 128 base::SharedMemory::NULLHandle(), 0u, base::TimeDelta());
126 EXPECT_TRUE(video_frame); 129 EXPECT_TRUE(video_frame);
127 return video_frame; 130 return video_frame;
128 } 131 }
129 132
130 TestBrowserThreadBundle bundle_; 133 TestBrowserThreadBundle bundle_;
131 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_; 134 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_a_;
132 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_; 135 std::unique_ptr<MockVideoCaptureControllerEventHandler> client_b_;
133 std::unique_ptr<VideoCaptureController> controller_; 136 std::unique_ptr<VideoCaptureController> controller_;
134 std::unique_ptr<media::VideoCaptureDevice::Client> device_; 137 std::unique_ptr<media::VideoCaptureDevice::Client> device_;
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 controller_->RemoveClient(client_b_route_2, client_b_.get())) 236 controller_->RemoveClient(client_b_route_2, client_b_.get()))
234 << "Removing client B/2 should return its session_id."; 237 << "Removing client B/2 should return its session_id.";
235 // Clients in controller: [] 238 // Clients in controller: []
236 ASSERT_EQ(0, controller_->GetClientCount()) 239 ASSERT_EQ(0, controller_->GetClientCount())
237 << "Client count should return to zero after all clients are gone."; 240 << "Client count should return to zero after all clients are gone.";
238 } 241 }
239 242
240 // This test will connect and disconnect several clients while simulating an 243 // This test will connect and disconnect several clients while simulating an
241 // active capture device being started and generating frames. It runs on one 244 // active capture device being started and generating frames. It runs on one
242 // thread and is intended to behave deterministically. 245 // thread and is intended to behave deterministically.
243 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { 246 TEST_P(VideoCaptureControllerTest, NormalCaptureMultipleClients) {
244 media::VideoCaptureParams session_100; 247 media::VideoCaptureParams session_100;
245 session_100.requested_format = media::VideoCaptureFormat( 248 const media::VideoPixelFormat format = GetParam();
246 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); 249 client_a_->expect_buffer_format_ = format;
250 client_b_->expect_buffer_format_ = format;
251
252 session_100.requested_format =
253 media::VideoCaptureFormat(gfx::Size(320, 240), 30, format);
247 254
248 media::VideoCaptureParams session_200 = session_100; 255 media::VideoCaptureParams session_200 = session_100;
249 256
250 media::VideoCaptureParams session_300 = session_100; 257 media::VideoCaptureParams session_300 = session_100;
251 258
252 media::VideoCaptureParams session_1 = session_100; 259 media::VideoCaptureParams session_1 = session_100;
253 260
254 const gfx::Size capture_resolution(444, 200); 261 const gfx::Size capture_resolution(444, 200);
255 262
256 // The device format needn't match the VideoCaptureParams (the camera can do 263 // The device format needn't match the VideoCaptureParams (the camera can do
(...skipping 22 matching lines...) Expand all
279 base::kNullProcessHandle, 286 base::kNullProcessHandle,
280 200, 287 200,
281 session_200); 288 session_200);
282 ASSERT_EQ(3, controller_->GetClientCount()); 289 ASSERT_EQ(3, controller_->GetClientCount());
283 290
284 // Now, simulate an incoming captured buffer from the capture device. As a 291 // Now, simulate an incoming captured buffer from the capture device. As a
285 // side effect this will cause the first buffer to be shared with clients. 292 // side effect this will cause the first buffer to be shared with clients.
286 uint8_t buffer_no = 1; 293 uint8_t buffer_no = 1;
287 ASSERT_EQ(0.0, device_->GetBufferPoolUtilization()); 294 ASSERT_EQ(0.0, device_->GetBufferPoolUtilization());
288 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( 295 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer(
289 device_->ReserveOutputBuffer(capture_resolution, media::PIXEL_FORMAT_I420, 296 device_->ReserveOutputBuffer(capture_resolution, format,
290 media::PIXEL_STORAGE_CPU)); 297 media::PIXEL_STORAGE_CPU));
291 ASSERT_TRUE(buffer.get()); 298 ASSERT_TRUE(buffer.get());
292 ASSERT_EQ(1.0 / kPoolSize, device_->GetBufferPoolUtilization()); 299 ASSERT_EQ(1.0 / kPoolSize, device_->GetBufferPoolUtilization());
293 memset(buffer->data(), buffer_no++, buffer->mapped_size()); 300 memset(buffer->data(), buffer_no++, buffer->mapped_size());
294 { 301 {
295 InSequence s; 302 InSequence s;
296 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); 303 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1);
297 EXPECT_CALL(*client_a_, 304 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution))
298 DoI420BufferReady(client_a_route_1, capture_resolution))
299 .Times(1); 305 .Times(1);
300 } 306 }
301 { 307 {
302 InSequence s; 308 InSequence s;
303 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); 309 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1);
304 EXPECT_CALL(*client_b_, 310 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1, capture_resolution))
305 DoI420BufferReady(client_b_route_1, capture_resolution))
306 .Times(1); 311 .Times(1);
307 } 312 }
308 { 313 {
309 InSequence s; 314 InSequence s;
310 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); 315 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1);
311 EXPECT_CALL(*client_a_, 316 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution))
312 DoI420BufferReady(client_a_route_2, capture_resolution))
313 .Times(1); 317 .Times(1);
314 } 318 }
315 scoped_refptr<media::VideoFrame> video_frame = 319 scoped_refptr<media::VideoFrame> video_frame = WrapBuffer(
316 WrapI420Buffer(capture_resolution, static_cast<uint8_t*>(buffer->data())); 320 capture_resolution, static_cast<uint8_t*>(buffer->data()), format);
317 ASSERT_TRUE(video_frame); 321 ASSERT_TRUE(video_frame);
318 ASSERT_FALSE(video_frame->metadata()->HasKey( 322 ASSERT_FALSE(video_frame->metadata()->HasKey(
319 media::VideoFrameMetadata::RESOURCE_UTILIZATION)); 323 media::VideoFrameMetadata::RESOURCE_UTILIZATION));
320 client_a_->resource_utilization_ = 0.5; 324 client_a_->resource_utilization_ = 0.5;
321 client_b_->resource_utilization_ = -1.0; 325 client_b_->resource_utilization_ = -1.0;
322 video_frame->metadata()->SetTimeTicks( 326 video_frame->metadata()->SetTimeTicks(
323 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); 327 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks());
324 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); 328 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame);
325 329
326 base::RunLoop().RunUntilIdle(); 330 base::RunLoop().RunUntilIdle();
327 Mock::VerifyAndClearExpectations(client_a_.get()); 331 Mock::VerifyAndClearExpectations(client_a_.get());
328 Mock::VerifyAndClearExpectations(client_b_.get()); 332 Mock::VerifyAndClearExpectations(client_b_.get());
329 333
330 // Expect VideoCaptureController set the metadata in |video_frame| to hold a 334 // Expect VideoCaptureController set the metadata in |video_frame| to hold a
331 // resource utilization of 0.5 (the largest of all reported values). 335 // resource utilization of 0.5 (the largest of all reported values).
332 double resource_utilization_in_metadata = -1.0; 336 double resource_utilization_in_metadata = -1.0;
333 ASSERT_TRUE(video_frame->metadata()->GetDouble( 337 ASSERT_TRUE(video_frame->metadata()->GetDouble(
334 media::VideoFrameMetadata::RESOURCE_UTILIZATION, 338 media::VideoFrameMetadata::RESOURCE_UTILIZATION,
335 &resource_utilization_in_metadata)); 339 &resource_utilization_in_metadata));
336 ASSERT_EQ(0.5, resource_utilization_in_metadata); 340 ASSERT_EQ(0.5, resource_utilization_in_metadata);
337 341
338 // Second buffer which ought to use the same shared memory buffer. In this 342 // Second buffer which ought to use the same shared memory buffer. In this
339 // case pretend that the Buffer pointer is held by the device for a long 343 // case pretend that the Buffer pointer is held by the device for a long
340 // delay. This shouldn't affect anything. 344 // delay. This shouldn't affect anything.
341 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 = 345 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 =
342 device_->ReserveOutputBuffer(capture_resolution, media::PIXEL_FORMAT_I420, 346 device_->ReserveOutputBuffer(capture_resolution, format,
343 media::PIXEL_STORAGE_CPU); 347 media::PIXEL_STORAGE_CPU);
344 ASSERT_TRUE(buffer2.get()); 348 ASSERT_TRUE(buffer2.get());
345 memset(buffer2->data(), buffer_no++, buffer2->mapped_size()); 349 memset(buffer2->data(), buffer_no++, buffer2->mapped_size());
346 video_frame = WrapI420Buffer(capture_resolution, 350 video_frame = WrapBuffer(capture_resolution,
347 static_cast<uint8_t*>(buffer2->data())); 351 static_cast<uint8_t*>(buffer2->data()), format);
348 ASSERT_TRUE(video_frame); 352 ASSERT_TRUE(video_frame);
349 ASSERT_FALSE(video_frame->metadata()->HasKey( 353 ASSERT_FALSE(video_frame->metadata()->HasKey(
350 media::VideoFrameMetadata::RESOURCE_UTILIZATION)); 354 media::VideoFrameMetadata::RESOURCE_UTILIZATION));
351 client_a_->resource_utilization_ = 0.5; 355 client_a_->resource_utilization_ = 0.5;
352 client_b_->resource_utilization_ = 3.14; 356 client_b_->resource_utilization_ = 3.14;
353 video_frame->metadata()->SetTimeTicks( 357 video_frame->metadata()->SetTimeTicks(
354 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); 358 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks());
355 device_->OnIncomingCapturedVideoFrame(std::move(buffer2), video_frame); 359 device_->OnIncomingCapturedVideoFrame(std::move(buffer2), video_frame);
356 360
357 // The buffer should be delivered to the clients in any order. 361 // The buffer should be delivered to the clients in any order.
358 { 362 {
359 InSequence s; 363 InSequence s;
360 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); 364 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1);
361 EXPECT_CALL(*client_a_, 365 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution))
362 DoI420BufferReady(client_a_route_1, capture_resolution))
363 .Times(1); 366 .Times(1);
364 } 367 }
365 { 368 {
366 InSequence s; 369 InSequence s;
367 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); 370 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1);
368 EXPECT_CALL(*client_b_, 371 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1, capture_resolution))
369 DoI420BufferReady(client_b_route_1, capture_resolution))
370 .Times(1); 372 .Times(1);
371 } 373 }
372 { 374 {
373 InSequence s; 375 InSequence s;
374 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); 376 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1);
375 EXPECT_CALL(*client_a_, 377 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution))
376 DoI420BufferReady(client_a_route_2, capture_resolution))
377 .Times(1); 378 .Times(1);
378 } 379 }
379 base::RunLoop().RunUntilIdle(); 380 base::RunLoop().RunUntilIdle();
380 Mock::VerifyAndClearExpectations(client_a_.get()); 381 Mock::VerifyAndClearExpectations(client_a_.get());
381 Mock::VerifyAndClearExpectations(client_b_.get()); 382 Mock::VerifyAndClearExpectations(client_b_.get());
382 // Expect VideoCaptureController set the metadata in |video_frame| to hold a 383 // Expect VideoCaptureController set the metadata in |video_frame| to hold a
383 // resource utilization of 3.14 (the largest of all reported values). 384 // resource utilization of 3.14 (the largest of all reported values).
384 resource_utilization_in_metadata = -1.0; 385 resource_utilization_in_metadata = -1.0;
385 ASSERT_TRUE(video_frame->metadata()->GetDouble( 386 ASSERT_TRUE(video_frame->metadata()->GetDouble(
386 media::VideoFrameMetadata::RESOURCE_UTILIZATION, 387 media::VideoFrameMetadata::RESOURCE_UTILIZATION,
387 &resource_utilization_in_metadata)); 388 &resource_utilization_in_metadata));
388 ASSERT_EQ(3.14, resource_utilization_in_metadata); 389 ASSERT_EQ(3.14, resource_utilization_in_metadata);
389 390
390 // Add a fourth client now that some buffers have come through. 391 // Add a fourth client now that some buffers have come through.
391 controller_->AddClient(client_b_route_2, 392 controller_->AddClient(client_b_route_2,
392 client_b_.get(), 393 client_b_.get(),
393 base::kNullProcessHandle, 394 base::kNullProcessHandle,
394 1, 395 1,
395 session_1); 396 session_1);
396 Mock::VerifyAndClearExpectations(client_b_.get()); 397 Mock::VerifyAndClearExpectations(client_b_.get());
397 398
398 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. 399 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time.
399 for (int i = 0; i < kPoolSize; i++) { 400 for (int i = 0; i < kPoolSize; i++) {
400 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = 401 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer =
401 device_->ReserveOutputBuffer(capture_resolution, 402 device_->ReserveOutputBuffer(capture_resolution, format,
402 media::PIXEL_FORMAT_I420,
403 media::PIXEL_STORAGE_CPU); 403 media::PIXEL_STORAGE_CPU);
404 ASSERT_TRUE(buffer.get()); 404 ASSERT_TRUE(buffer.get());
405 memset(buffer->data(), buffer_no++, buffer->mapped_size()); 405 memset(buffer->data(), buffer_no++, buffer->mapped_size());
406 video_frame = WrapI420Buffer(capture_resolution, 406 video_frame = WrapBuffer(capture_resolution,
407 static_cast<uint8_t*>(buffer->data())); 407 static_cast<uint8_t*>(buffer->data()), format);
408 ASSERT_TRUE(video_frame); 408 ASSERT_TRUE(video_frame);
409 video_frame->metadata()->SetTimeTicks( 409 video_frame->metadata()->SetTimeTicks(
410 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); 410 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks());
411 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); 411 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame);
412 } 412 }
413 // ReserveOutputBuffer ought to fail now, because the pool is depleted. 413 // ReserveOutputBuffer ought to fail now, because the pool is depleted.
414 ASSERT_FALSE( 414 ASSERT_FALSE(device_
415 device_->ReserveOutputBuffer(capture_resolution, 415 ->ReserveOutputBuffer(capture_resolution, format,
416 media::PIXEL_FORMAT_I420, 416 media::PIXEL_STORAGE_CPU)
417 media::PIXEL_STORAGE_CPU).get()); 417 .get());
418 418
419 // The new client needs to be notified of the creation of |kPoolSize| buffers; 419 // The new client needs to be notified of the creation of |kPoolSize| buffers;
420 // the old clients only |kPoolSize - 2|. 420 // the old clients only |kPoolSize - 2|.
421 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); 421 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize);
422 EXPECT_CALL(*client_b_, 422 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2, capture_resolution))
423 DoI420BufferReady(client_b_route_2, capture_resolution))
424 .Times(kPoolSize); 423 .Times(kPoolSize);
425 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) 424 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1))
426 .Times(kPoolSize - 2); 425 .Times(kPoolSize - 2);
427 EXPECT_CALL(*client_a_, 426 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution))
428 DoI420BufferReady(client_a_route_1, capture_resolution))
429 .Times(kPoolSize); 427 .Times(kPoolSize);
430 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)) 428 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2))
431 .Times(kPoolSize - 2); 429 .Times(kPoolSize - 2);
432 EXPECT_CALL(*client_a_, 430 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution))
433 DoI420BufferReady(client_a_route_2, capture_resolution))
434 .Times(kPoolSize); 431 .Times(kPoolSize);
435 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)) 432 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1))
436 .Times(kPoolSize - 2); 433 .Times(kPoolSize - 2);
437 EXPECT_CALL(*client_b_, 434 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1, capture_resolution))
438 DoI420BufferReady(client_b_route_1, capture_resolution))
439 .Times(kPoolSize); 435 .Times(kPoolSize);
440 base::RunLoop().RunUntilIdle(); 436 base::RunLoop().RunUntilIdle();
441 Mock::VerifyAndClearExpectations(client_a_.get()); 437 Mock::VerifyAndClearExpectations(client_a_.get());
442 Mock::VerifyAndClearExpectations(client_b_.get()); 438 Mock::VerifyAndClearExpectations(client_b_.get());
443 439
444 // Now test the interaction of client shutdown and buffer delivery. 440 // Now test the interaction of client shutdown and buffer delivery.
445 // Kill A1 via renderer disconnect (synchronous). 441 // Kill A1 via renderer disconnect (synchronous).
446 controller_->RemoveClient(client_a_route_1, client_a_.get()); 442 controller_->RemoveClient(client_a_route_1, client_a_.get());
447 // Kill B1 via session close (posts a task to disconnect). 443 // Kill B1 via session close (posts a task to disconnect).
448 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); 444 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1);
449 controller_->StopSession(300); 445 controller_->StopSession(300);
450 // Queue up another buffer. 446 // Queue up another buffer.
451 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer3 = 447 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer3 =
452 device_->ReserveOutputBuffer(capture_resolution, media::PIXEL_FORMAT_I420, 448 device_->ReserveOutputBuffer(capture_resolution, format,
453 media::PIXEL_STORAGE_CPU); 449 media::PIXEL_STORAGE_CPU);
454 ASSERT_TRUE(buffer3.get()); 450 ASSERT_TRUE(buffer3.get());
455 memset(buffer3->data(), buffer_no++, buffer3->mapped_size()); 451 memset(buffer3->data(), buffer_no++, buffer3->mapped_size());
456 video_frame = WrapI420Buffer(capture_resolution, 452 video_frame = WrapBuffer(capture_resolution,
457 static_cast<uint8_t*>(buffer3->data())); 453 static_cast<uint8_t*>(buffer3->data()), format);
458 ASSERT_TRUE(video_frame); 454 ASSERT_TRUE(video_frame);
459 video_frame->metadata()->SetTimeTicks( 455 video_frame->metadata()->SetTimeTicks(
460 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); 456 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks());
461 device_->OnIncomingCapturedVideoFrame(std::move(buffer3), video_frame); 457 device_->OnIncomingCapturedVideoFrame(std::move(buffer3), video_frame);
462 458
463 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer4 = 459 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer4 =
464 device_->ReserveOutputBuffer(capture_resolution, media::PIXEL_FORMAT_I420, 460 device_->ReserveOutputBuffer(capture_resolution, format,
465 media::PIXEL_STORAGE_CPU); 461 media::PIXEL_STORAGE_CPU);
466 { 462 {
467 // 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
468 // be sent either of these two buffers). 464 // be sent either of these two buffers).
469 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); 465 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1);
470 controller_->StopSession(200); 466 controller_->StopSession(200);
471 } 467 }
472 ASSERT_TRUE(buffer4.get()); 468 ASSERT_TRUE(buffer4.get());
473 memset(buffer4->data(), buffer_no++, buffer4->mapped_size()); 469 memset(buffer4->data(), buffer_no++, buffer4->mapped_size());
474 video_frame = WrapI420Buffer(capture_resolution, 470 video_frame = WrapBuffer(capture_resolution,
475 static_cast<uint8_t*>(buffer4->data())); 471 static_cast<uint8_t*>(buffer4->data()), format);
476 ASSERT_TRUE(video_frame); 472 ASSERT_TRUE(video_frame);
477 video_frame->metadata()->SetTimeTicks( 473 video_frame->metadata()->SetTimeTicks(
478 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); 474 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks());
479 device_->OnIncomingCapturedVideoFrame(std::move(buffer4), video_frame); 475 device_->OnIncomingCapturedVideoFrame(std::move(buffer4), video_frame);
480 // B2 is the only client left, and is the only one that should 476 // B2 is the only client left, and is the only one that should
481 // get the buffer. 477 // get the buffer.
482 EXPECT_CALL(*client_b_, 478 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2, capture_resolution))
483 DoI420BufferReady(client_b_route_2, capture_resolution))
484 .Times(2); 479 .Times(2);
485 base::RunLoop().RunUntilIdle(); 480 base::RunLoop().RunUntilIdle();
486 Mock::VerifyAndClearExpectations(client_a_.get()); 481 Mock::VerifyAndClearExpectations(client_a_.get());
487 Mock::VerifyAndClearExpectations(client_b_.get()); 482 Mock::VerifyAndClearExpectations(client_b_.get());
488 } 483 }
489 484
485 INSTANTIATE_TEST_CASE_P(,
486 VideoCaptureControllerTest,
487 ::testing::Values(media::PIXEL_FORMAT_I420,
488 media::PIXEL_FORMAT_Y16));
489
490 // Exercises the OnError() codepath of VideoCaptureController, and tests the 490 // Exercises the OnError() codepath of VideoCaptureController, and tests the
491 // behavior of various operations after the error state has been signalled. 491 // behavior of various operations after the error state has been signalled.
492 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { 492 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) {
493 media::VideoCaptureParams session_100; 493 media::VideoCaptureParams session_100;
494 session_100.requested_format = media::VideoCaptureFormat( 494 session_100.requested_format = media::VideoCaptureFormat(
495 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); 495 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420);
496 496
497 media::VideoCaptureParams session_200 = session_100; 497 media::VideoCaptureParams session_200 = session_100;
498 498
499 const gfx::Size capture_resolution(320, 240); 499 const gfx::Size capture_resolution(320, 240);
(...skipping 14 matching lines...) Expand all
514 controller_->AddClient( 514 controller_->AddClient(
515 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); 515 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200);
516 base::RunLoop().RunUntilIdle(); 516 base::RunLoop().RunUntilIdle();
517 Mock::VerifyAndClearExpectations(client_b_.get()); 517 Mock::VerifyAndClearExpectations(client_b_.get());
518 518
519 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( 519 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer(
520 device_->ReserveOutputBuffer(capture_resolution, media::PIXEL_FORMAT_I420, 520 device_->ReserveOutputBuffer(capture_resolution, media::PIXEL_FORMAT_I420,
521 media::PIXEL_STORAGE_CPU)); 521 media::PIXEL_STORAGE_CPU));
522 ASSERT_TRUE(buffer.get()); 522 ASSERT_TRUE(buffer.get());
523 scoped_refptr<media::VideoFrame> video_frame = 523 scoped_refptr<media::VideoFrame> video_frame =
524 WrapI420Buffer(capture_resolution, static_cast<uint8_t*>(buffer->data())); 524 WrapBuffer(capture_resolution, static_cast<uint8_t*>(buffer->data()));
525 ASSERT_TRUE(video_frame); 525 ASSERT_TRUE(video_frame);
526 video_frame->metadata()->SetTimeTicks( 526 video_frame->metadata()->SetTimeTicks(
527 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); 527 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks());
528 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); 528 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame);
529 529
530 base::RunLoop().RunUntilIdle(); 530 base::RunLoop().RunUntilIdle();
531 } 531 }
532 532
533 // Exercises the OnError() codepath of VideoCaptureController, and tests the 533 // Exercises the OnError() codepath of VideoCaptureController, and tests the
534 // behavior of various operations after the error state has been signalled. 534 // behavior of various operations after the error state has been signalled.
(...skipping 18 matching lines...) Expand all
553 base::RunLoop().RunUntilIdle(); 553 base::RunLoop().RunUntilIdle();
554 Mock::VerifyAndClearExpectations(client_a_.get()); 554 Mock::VerifyAndClearExpectations(client_a_.get());
555 555
556 const gfx::Size dims(320, 240); 556 const gfx::Size dims(320, 240);
557 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( 557 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer(
558 device_->ReserveOutputBuffer(dims, media::PIXEL_FORMAT_I420, 558 device_->ReserveOutputBuffer(dims, media::PIXEL_FORMAT_I420,
559 media::PIXEL_STORAGE_CPU)); 559 media::PIXEL_STORAGE_CPU));
560 ASSERT_TRUE(buffer.get()); 560 ASSERT_TRUE(buffer.get());
561 561
562 scoped_refptr<media::VideoFrame> video_frame = 562 scoped_refptr<media::VideoFrame> video_frame =
563 WrapI420Buffer(dims, static_cast<uint8_t*>(buffer->data())); 563 WrapBuffer(dims, static_cast<uint8_t*>(buffer->data()));
564 ASSERT_TRUE(video_frame); 564 ASSERT_TRUE(video_frame);
565 device_->OnError(FROM_HERE, "Test Error"); 565 device_->OnError(FROM_HERE, "Test Error");
566 video_frame->metadata()->SetTimeTicks( 566 video_frame->metadata()->SetTimeTicks(
567 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); 567 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks());
568 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); 568 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame);
569 569
570 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); 570 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1);
571 base::RunLoop().RunUntilIdle(); 571 base::RunLoop().RunUntilIdle();
572 Mock::VerifyAndClearExpectations(client_a_.get()); 572 Mock::VerifyAndClearExpectations(client_a_.get());
573 573
574 // Second client connects after the error state. It also should get told of 574 // Second client connects after the error state. It also should get told of
575 // the error. 575 // the error.
576 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); 576 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1);
577 controller_->AddClient( 577 controller_->AddClient(
578 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); 578 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200);
579 Mock::VerifyAndClearExpectations(client_b_.get()); 579 Mock::VerifyAndClearExpectations(client_b_.get());
580 } 580 }
581 581
582 } // namespace content 582 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698