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