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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 mojo::ScopedSharedBufferHandle handle, | 63 mojo::ScopedSharedBufferHandle 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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 controller_->RemoveClient(client_b_route_2, client_b_.get())) | 232 controller_->RemoveClient(client_b_route_2, client_b_.get())) |
230 << "Removing client B/2 should return its session_id."; | 233 << "Removing client B/2 should return its session_id."; |
231 // Clients in controller: [] | 234 // Clients in controller: [] |
232 ASSERT_EQ(0, controller_->GetClientCount()) | 235 ASSERT_EQ(0, controller_->GetClientCount()) |
233 << "Client count should return to zero after all clients are gone."; | 236 << "Client count should return to zero after all clients are gone."; |
234 } | 237 } |
235 | 238 |
236 // This test will connect and disconnect several clients while simulating an | 239 // This test will connect and disconnect several clients while simulating an |
237 // active capture device being started and generating frames. It runs on one | 240 // active capture device being started and generating frames. It runs on one |
238 // thread and is intended to behave deterministically. | 241 // thread and is intended to behave deterministically. |
239 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { | 242 TEST_P(VideoCaptureControllerTest, NormalCaptureMultipleClients) { |
240 media::VideoCaptureParams session_100; | 243 media::VideoCaptureParams session_100; |
241 session_100.requested_format = media::VideoCaptureFormat( | 244 const media::VideoPixelFormat format = GetParam(); |
242 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 245 client_a_->expect_buffer_format_ = format; |
| 246 client_b_->expect_buffer_format_ = format; |
| 247 |
| 248 session_100.requested_format = |
| 249 media::VideoCaptureFormat(gfx::Size(320, 240), 30, format); |
243 | 250 |
244 media::VideoCaptureParams session_200 = session_100; | 251 media::VideoCaptureParams session_200 = session_100; |
245 | 252 |
246 media::VideoCaptureParams session_300 = session_100; | 253 media::VideoCaptureParams session_300 = session_100; |
247 | 254 |
248 media::VideoCaptureParams session_1 = session_100; | 255 media::VideoCaptureParams session_1 = session_100; |
249 | 256 |
250 const gfx::Size capture_resolution(444, 200); | 257 const gfx::Size capture_resolution(444, 200); |
251 | 258 |
252 // The device format needn't match the VideoCaptureParams (the camera can do | 259 // The device format needn't match the VideoCaptureParams (the camera can do |
(...skipping 19 matching lines...) Expand all Loading... |
272 client_a_.get(), | 279 client_a_.get(), |
273 200, | 280 200, |
274 session_200); | 281 session_200); |
275 ASSERT_EQ(3, controller_->GetClientCount()); | 282 ASSERT_EQ(3, controller_->GetClientCount()); |
276 | 283 |
277 // Now, simulate an incoming captured buffer from the capture device. As a | 284 // Now, simulate an incoming captured buffer from the capture device. As a |
278 // side effect this will cause the first buffer to be shared with clients. | 285 // side effect this will cause the first buffer to be shared with clients. |
279 uint8_t buffer_no = 1; | 286 uint8_t buffer_no = 1; |
280 ASSERT_EQ(0.0, device_->GetBufferPoolUtilization()); | 287 ASSERT_EQ(0.0, device_->GetBufferPoolUtilization()); |
281 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( | 288 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( |
282 device_->ReserveOutputBuffer(capture_resolution, media::PIXEL_FORMAT_I420, | 289 device_->ReserveOutputBuffer(capture_resolution, format, |
283 media::PIXEL_STORAGE_CPU)); | 290 media::PIXEL_STORAGE_CPU)); |
284 ASSERT_TRUE(buffer.get()); | 291 ASSERT_TRUE(buffer.get()); |
285 ASSERT_EQ(1.0 / kPoolSize, device_->GetBufferPoolUtilization()); | 292 ASSERT_EQ(1.0 / kPoolSize, device_->GetBufferPoolUtilization()); |
286 memset(buffer->data(), buffer_no++, buffer->mapped_size()); | 293 memset(buffer->data(), buffer_no++, buffer->mapped_size()); |
287 { | 294 { |
288 InSequence s; | 295 InSequence s; |
289 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); | 296 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); |
290 EXPECT_CALL(*client_a_, | 297 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution)) |
291 DoI420BufferReady(client_a_route_1, capture_resolution)) | |
292 .Times(1); | 298 .Times(1); |
293 } | 299 } |
294 { | 300 { |
295 InSequence s; | 301 InSequence s; |
296 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); | 302 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); |
297 EXPECT_CALL(*client_b_, | 303 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1, capture_resolution)) |
298 DoI420BufferReady(client_b_route_1, capture_resolution)) | |
299 .Times(1); | 304 .Times(1); |
300 } | 305 } |
301 { | 306 { |
302 InSequence s; | 307 InSequence s; |
303 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); | 308 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); |
304 EXPECT_CALL(*client_a_, | 309 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution)) |
305 DoI420BufferReady(client_a_route_2, capture_resolution)) | |
306 .Times(1); | 310 .Times(1); |
307 } | 311 } |
308 scoped_refptr<media::VideoFrame> video_frame = | 312 scoped_refptr<media::VideoFrame> video_frame = WrapBuffer( |
309 WrapI420Buffer(capture_resolution, static_cast<uint8_t*>(buffer->data())); | 313 capture_resolution, static_cast<uint8_t*>(buffer->data()), format); |
310 ASSERT_TRUE(video_frame); | 314 ASSERT_TRUE(video_frame); |
311 ASSERT_FALSE(video_frame->metadata()->HasKey( | 315 ASSERT_FALSE(video_frame->metadata()->HasKey( |
312 media::VideoFrameMetadata::RESOURCE_UTILIZATION)); | 316 media::VideoFrameMetadata::RESOURCE_UTILIZATION)); |
313 client_a_->resource_utilization_ = 0.5; | 317 client_a_->resource_utilization_ = 0.5; |
314 client_b_->resource_utilization_ = -1.0; | 318 client_b_->resource_utilization_ = -1.0; |
315 video_frame->metadata()->SetTimeTicks( | 319 video_frame->metadata()->SetTimeTicks( |
316 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 320 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
317 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); | 321 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); |
318 | 322 |
319 base::RunLoop().RunUntilIdle(); | 323 base::RunLoop().RunUntilIdle(); |
320 Mock::VerifyAndClearExpectations(client_a_.get()); | 324 Mock::VerifyAndClearExpectations(client_a_.get()); |
321 Mock::VerifyAndClearExpectations(client_b_.get()); | 325 Mock::VerifyAndClearExpectations(client_b_.get()); |
322 | 326 |
323 // Expect VideoCaptureController set the metadata in |video_frame| to hold a | 327 // Expect VideoCaptureController set the metadata in |video_frame| to hold a |
324 // resource utilization of 0.5 (the largest of all reported values). | 328 // resource utilization of 0.5 (the largest of all reported values). |
325 double resource_utilization_in_metadata = -1.0; | 329 double resource_utilization_in_metadata = -1.0; |
326 ASSERT_TRUE(video_frame->metadata()->GetDouble( | 330 ASSERT_TRUE(video_frame->metadata()->GetDouble( |
327 media::VideoFrameMetadata::RESOURCE_UTILIZATION, | 331 media::VideoFrameMetadata::RESOURCE_UTILIZATION, |
328 &resource_utilization_in_metadata)); | 332 &resource_utilization_in_metadata)); |
329 ASSERT_EQ(0.5, resource_utilization_in_metadata); | 333 ASSERT_EQ(0.5, resource_utilization_in_metadata); |
330 | 334 |
331 // Second buffer which ought to use the same shared memory buffer. In this | 335 // Second buffer which ought to use the same shared memory buffer. In this |
332 // case pretend that the Buffer pointer is held by the device for a long | 336 // case pretend that the Buffer pointer is held by the device for a long |
333 // delay. This shouldn't affect anything. | 337 // delay. This shouldn't affect anything. |
334 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 = | 338 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer2 = |
335 device_->ReserveOutputBuffer(capture_resolution, media::PIXEL_FORMAT_I420, | 339 device_->ReserveOutputBuffer(capture_resolution, format, |
336 media::PIXEL_STORAGE_CPU); | 340 media::PIXEL_STORAGE_CPU); |
337 ASSERT_TRUE(buffer2.get()); | 341 ASSERT_TRUE(buffer2.get()); |
338 memset(buffer2->data(), buffer_no++, buffer2->mapped_size()); | 342 memset(buffer2->data(), buffer_no++, buffer2->mapped_size()); |
339 video_frame = WrapI420Buffer(capture_resolution, | 343 video_frame = WrapBuffer(capture_resolution, |
340 static_cast<uint8_t*>(buffer2->data())); | 344 static_cast<uint8_t*>(buffer2->data()), format); |
341 ASSERT_TRUE(video_frame); | 345 ASSERT_TRUE(video_frame); |
342 ASSERT_FALSE(video_frame->metadata()->HasKey( | 346 ASSERT_FALSE(video_frame->metadata()->HasKey( |
343 media::VideoFrameMetadata::RESOURCE_UTILIZATION)); | 347 media::VideoFrameMetadata::RESOURCE_UTILIZATION)); |
344 client_a_->resource_utilization_ = 0.5; | 348 client_a_->resource_utilization_ = 0.5; |
345 client_b_->resource_utilization_ = 3.14; | 349 client_b_->resource_utilization_ = 3.14; |
346 video_frame->metadata()->SetTimeTicks( | 350 video_frame->metadata()->SetTimeTicks( |
347 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 351 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
348 device_->OnIncomingCapturedVideoFrame(std::move(buffer2), video_frame); | 352 device_->OnIncomingCapturedVideoFrame(std::move(buffer2), video_frame); |
349 | 353 |
350 // The buffer should be delivered to the clients in any order. | 354 // The buffer should be delivered to the clients in any order. |
351 { | 355 { |
352 InSequence s; | 356 InSequence s; |
353 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); | 357 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); |
354 EXPECT_CALL(*client_a_, | 358 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution)) |
355 DoI420BufferReady(client_a_route_1, capture_resolution)) | |
356 .Times(1); | 359 .Times(1); |
357 } | 360 } |
358 { | 361 { |
359 InSequence s; | 362 InSequence s; |
360 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); | 363 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); |
361 EXPECT_CALL(*client_b_, | 364 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1, capture_resolution)) |
362 DoI420BufferReady(client_b_route_1, capture_resolution)) | |
363 .Times(1); | 365 .Times(1); |
364 } | 366 } |
365 { | 367 { |
366 InSequence s; | 368 InSequence s; |
367 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); | 369 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); |
368 EXPECT_CALL(*client_a_, | 370 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution)) |
369 DoI420BufferReady(client_a_route_2, capture_resolution)) | |
370 .Times(1); | 371 .Times(1); |
371 } | 372 } |
372 base::RunLoop().RunUntilIdle(); | 373 base::RunLoop().RunUntilIdle(); |
373 Mock::VerifyAndClearExpectations(client_a_.get()); | 374 Mock::VerifyAndClearExpectations(client_a_.get()); |
374 Mock::VerifyAndClearExpectations(client_b_.get()); | 375 Mock::VerifyAndClearExpectations(client_b_.get()); |
375 // Expect VideoCaptureController set the metadata in |video_frame| to hold a | 376 // Expect VideoCaptureController set the metadata in |video_frame| to hold a |
376 // resource utilization of 3.14 (the largest of all reported values). | 377 // resource utilization of 3.14 (the largest of all reported values). |
377 resource_utilization_in_metadata = -1.0; | 378 resource_utilization_in_metadata = -1.0; |
378 ASSERT_TRUE(video_frame->metadata()->GetDouble( | 379 ASSERT_TRUE(video_frame->metadata()->GetDouble( |
379 media::VideoFrameMetadata::RESOURCE_UTILIZATION, | 380 media::VideoFrameMetadata::RESOURCE_UTILIZATION, |
380 &resource_utilization_in_metadata)); | 381 &resource_utilization_in_metadata)); |
381 ASSERT_EQ(3.14, resource_utilization_in_metadata); | 382 ASSERT_EQ(3.14, resource_utilization_in_metadata); |
382 | 383 |
383 // Add a fourth client now that some buffers have come through. | 384 // Add a fourth client now that some buffers have come through. |
384 controller_->AddClient(client_b_route_2, | 385 controller_->AddClient(client_b_route_2, |
385 client_b_.get(), | 386 client_b_.get(), |
386 1, | 387 1, |
387 session_1); | 388 session_1); |
388 Mock::VerifyAndClearExpectations(client_b_.get()); | 389 Mock::VerifyAndClearExpectations(client_b_.get()); |
389 | 390 |
390 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. | 391 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. |
391 for (int i = 0; i < kPoolSize; i++) { | 392 for (int i = 0; i < kPoolSize; i++) { |
392 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = | 393 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer = |
393 device_->ReserveOutputBuffer(capture_resolution, | 394 device_->ReserveOutputBuffer(capture_resolution, format, |
394 media::PIXEL_FORMAT_I420, | |
395 media::PIXEL_STORAGE_CPU); | 395 media::PIXEL_STORAGE_CPU); |
396 ASSERT_TRUE(buffer.get()); | 396 ASSERT_TRUE(buffer.get()); |
397 memset(buffer->data(), buffer_no++, buffer->mapped_size()); | 397 memset(buffer->data(), buffer_no++, buffer->mapped_size()); |
398 video_frame = WrapI420Buffer(capture_resolution, | 398 video_frame = WrapBuffer(capture_resolution, |
399 static_cast<uint8_t*>(buffer->data())); | 399 static_cast<uint8_t*>(buffer->data()), format); |
400 ASSERT_TRUE(video_frame); | 400 ASSERT_TRUE(video_frame); |
401 video_frame->metadata()->SetTimeTicks( | 401 video_frame->metadata()->SetTimeTicks( |
402 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 402 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
403 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); | 403 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); |
404 } | 404 } |
405 // ReserveOutputBuffer ought to fail now, because the pool is depleted. | 405 // ReserveOutputBuffer ought to fail now, because the pool is depleted. |
406 ASSERT_FALSE( | 406 ASSERT_FALSE(device_ |
407 device_->ReserveOutputBuffer(capture_resolution, | 407 ->ReserveOutputBuffer(capture_resolution, format, |
408 media::PIXEL_FORMAT_I420, | 408 media::PIXEL_STORAGE_CPU) |
409 media::PIXEL_STORAGE_CPU).get()); | 409 .get()); |
410 | 410 |
411 // The new client needs to be notified of the creation of |kPoolSize| buffers; | 411 // The new client needs to be notified of the creation of |kPoolSize| buffers; |
412 // the old clients only |kPoolSize - 2|. | 412 // the old clients only |kPoolSize - 2|. |
413 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); | 413 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); |
414 EXPECT_CALL(*client_b_, | 414 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2, capture_resolution)) |
415 DoI420BufferReady(client_b_route_2, capture_resolution)) | |
416 .Times(kPoolSize); | 415 .Times(kPoolSize); |
417 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) | 416 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) |
418 .Times(kPoolSize - 2); | 417 .Times(kPoolSize - 2); |
419 EXPECT_CALL(*client_a_, | 418 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1, capture_resolution)) |
420 DoI420BufferReady(client_a_route_1, capture_resolution)) | |
421 .Times(kPoolSize); | 419 .Times(kPoolSize); |
422 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)) | 420 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)) |
423 .Times(kPoolSize - 2); | 421 .Times(kPoolSize - 2); |
424 EXPECT_CALL(*client_a_, | 422 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2, capture_resolution)) |
425 DoI420BufferReady(client_a_route_2, capture_resolution)) | |
426 .Times(kPoolSize); | 423 .Times(kPoolSize); |
427 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)) | 424 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)) |
428 .Times(kPoolSize - 2); | 425 .Times(kPoolSize - 2); |
429 EXPECT_CALL(*client_b_, | 426 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1, capture_resolution)) |
430 DoI420BufferReady(client_b_route_1, capture_resolution)) | |
431 .Times(kPoolSize); | 427 .Times(kPoolSize); |
432 base::RunLoop().RunUntilIdle(); | 428 base::RunLoop().RunUntilIdle(); |
433 Mock::VerifyAndClearExpectations(client_a_.get()); | 429 Mock::VerifyAndClearExpectations(client_a_.get()); |
434 Mock::VerifyAndClearExpectations(client_b_.get()); | 430 Mock::VerifyAndClearExpectations(client_b_.get()); |
435 | 431 |
436 // Now test the interaction of client shutdown and buffer delivery. | 432 // Now test the interaction of client shutdown and buffer delivery. |
437 // Kill A1 via renderer disconnect (synchronous). | 433 // Kill A1 via renderer disconnect (synchronous). |
438 controller_->RemoveClient(client_a_route_1, client_a_.get()); | 434 controller_->RemoveClient(client_a_route_1, client_a_.get()); |
439 // Kill B1 via session close (posts a task to disconnect). | 435 // Kill B1 via session close (posts a task to disconnect). |
440 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); | 436 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); |
441 controller_->StopSession(300); | 437 controller_->StopSession(300); |
442 // Queue up another buffer. | 438 // Queue up another buffer. |
443 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer3 = | 439 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer3 = |
444 device_->ReserveOutputBuffer(capture_resolution, media::PIXEL_FORMAT_I420, | 440 device_->ReserveOutputBuffer(capture_resolution, format, |
445 media::PIXEL_STORAGE_CPU); | 441 media::PIXEL_STORAGE_CPU); |
446 ASSERT_TRUE(buffer3.get()); | 442 ASSERT_TRUE(buffer3.get()); |
447 memset(buffer3->data(), buffer_no++, buffer3->mapped_size()); | 443 memset(buffer3->data(), buffer_no++, buffer3->mapped_size()); |
448 video_frame = WrapI420Buffer(capture_resolution, | 444 video_frame = WrapBuffer(capture_resolution, |
449 static_cast<uint8_t*>(buffer3->data())); | 445 static_cast<uint8_t*>(buffer3->data()), format); |
450 ASSERT_TRUE(video_frame); | 446 ASSERT_TRUE(video_frame); |
451 video_frame->metadata()->SetTimeTicks( | 447 video_frame->metadata()->SetTimeTicks( |
452 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 448 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
453 device_->OnIncomingCapturedVideoFrame(std::move(buffer3), video_frame); | 449 device_->OnIncomingCapturedVideoFrame(std::move(buffer3), video_frame); |
454 | 450 |
455 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer4 = | 451 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer4 = |
456 device_->ReserveOutputBuffer(capture_resolution, media::PIXEL_FORMAT_I420, | 452 device_->ReserveOutputBuffer(capture_resolution, format, |
457 media::PIXEL_STORAGE_CPU); | 453 media::PIXEL_STORAGE_CPU); |
458 { | 454 { |
459 // Kill A2 via session close (posts a task to disconnect, but A2 must not | 455 // Kill A2 via session close (posts a task to disconnect, but A2 must not |
460 // be sent either of these two buffers). | 456 // be sent either of these two buffers). |
461 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); | 457 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); |
462 controller_->StopSession(200); | 458 controller_->StopSession(200); |
463 } | 459 } |
464 ASSERT_TRUE(buffer4.get()); | 460 ASSERT_TRUE(buffer4.get()); |
465 memset(buffer4->data(), buffer_no++, buffer4->mapped_size()); | 461 memset(buffer4->data(), buffer_no++, buffer4->mapped_size()); |
466 video_frame = WrapI420Buffer(capture_resolution, | 462 video_frame = WrapBuffer(capture_resolution, |
467 static_cast<uint8_t*>(buffer4->data())); | 463 static_cast<uint8_t*>(buffer4->data()), format); |
468 ASSERT_TRUE(video_frame); | 464 ASSERT_TRUE(video_frame); |
469 video_frame->metadata()->SetTimeTicks( | 465 video_frame->metadata()->SetTimeTicks( |
470 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 466 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
471 device_->OnIncomingCapturedVideoFrame(std::move(buffer4), video_frame); | 467 device_->OnIncomingCapturedVideoFrame(std::move(buffer4), video_frame); |
472 // B2 is the only client left, and is the only one that should | 468 // B2 is the only client left, and is the only one that should |
473 // get the buffer. | 469 // get the buffer. |
474 EXPECT_CALL(*client_b_, | 470 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2, capture_resolution)) |
475 DoI420BufferReady(client_b_route_2, capture_resolution)) | |
476 .Times(2); | 471 .Times(2); |
477 base::RunLoop().RunUntilIdle(); | 472 base::RunLoop().RunUntilIdle(); |
478 Mock::VerifyAndClearExpectations(client_a_.get()); | 473 Mock::VerifyAndClearExpectations(client_a_.get()); |
479 Mock::VerifyAndClearExpectations(client_b_.get()); | 474 Mock::VerifyAndClearExpectations(client_b_.get()); |
480 } | 475 } |
481 | 476 |
| 477 INSTANTIATE_TEST_CASE_P(, |
| 478 VideoCaptureControllerTest, |
| 479 ::testing::Values(media::PIXEL_FORMAT_I420, |
| 480 media::PIXEL_FORMAT_Y16)); |
| 481 |
482 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 482 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
483 // behavior of various operations after the error state has been signalled. | 483 // behavior of various operations after the error state has been signalled. |
484 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { | 484 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { |
485 media::VideoCaptureParams session_100; | 485 media::VideoCaptureParams session_100; |
486 session_100.requested_format = media::VideoCaptureFormat( | 486 session_100.requested_format = media::VideoCaptureFormat( |
487 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 487 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
488 | 488 |
489 media::VideoCaptureParams session_200 = session_100; | 489 media::VideoCaptureParams session_200 = session_100; |
490 | 490 |
491 const gfx::Size capture_resolution(320, 240); | 491 const gfx::Size capture_resolution(320, 240); |
(...skipping 12 matching lines...) Expand all Loading... |
504 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 504 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
505 controller_->AddClient(route_id, client_b_.get(), 200, session_200); | 505 controller_->AddClient(route_id, client_b_.get(), 200, session_200); |
506 base::RunLoop().RunUntilIdle(); | 506 base::RunLoop().RunUntilIdle(); |
507 Mock::VerifyAndClearExpectations(client_b_.get()); | 507 Mock::VerifyAndClearExpectations(client_b_.get()); |
508 | 508 |
509 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( | 509 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( |
510 device_->ReserveOutputBuffer(capture_resolution, media::PIXEL_FORMAT_I420, | 510 device_->ReserveOutputBuffer(capture_resolution, media::PIXEL_FORMAT_I420, |
511 media::PIXEL_STORAGE_CPU)); | 511 media::PIXEL_STORAGE_CPU)); |
512 ASSERT_TRUE(buffer.get()); | 512 ASSERT_TRUE(buffer.get()); |
513 scoped_refptr<media::VideoFrame> video_frame = | 513 scoped_refptr<media::VideoFrame> video_frame = |
514 WrapI420Buffer(capture_resolution, static_cast<uint8_t*>(buffer->data())); | 514 WrapBuffer(capture_resolution, static_cast<uint8_t*>(buffer->data())); |
515 ASSERT_TRUE(video_frame); | 515 ASSERT_TRUE(video_frame); |
516 video_frame->metadata()->SetTimeTicks( | 516 video_frame->metadata()->SetTimeTicks( |
517 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 517 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
518 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); | 518 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); |
519 | 519 |
520 base::RunLoop().RunUntilIdle(); | 520 base::RunLoop().RunUntilIdle(); |
521 } | 521 } |
522 | 522 |
523 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 523 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
524 // behavior of various operations after the error state has been signalled. | 524 // behavior of various operations after the error state has been signalled. |
(...skipping 17 matching lines...) Expand all Loading... |
542 base::RunLoop().RunUntilIdle(); | 542 base::RunLoop().RunUntilIdle(); |
543 Mock::VerifyAndClearExpectations(client_a_.get()); | 543 Mock::VerifyAndClearExpectations(client_a_.get()); |
544 | 544 |
545 const gfx::Size dims(320, 240); | 545 const gfx::Size dims(320, 240); |
546 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( | 546 std::unique_ptr<media::VideoCaptureDevice::Client::Buffer> buffer( |
547 device_->ReserveOutputBuffer(dims, media::PIXEL_FORMAT_I420, | 547 device_->ReserveOutputBuffer(dims, media::PIXEL_FORMAT_I420, |
548 media::PIXEL_STORAGE_CPU)); | 548 media::PIXEL_STORAGE_CPU)); |
549 ASSERT_TRUE(buffer.get()); | 549 ASSERT_TRUE(buffer.get()); |
550 | 550 |
551 scoped_refptr<media::VideoFrame> video_frame = | 551 scoped_refptr<media::VideoFrame> video_frame = |
552 WrapI420Buffer(dims, static_cast<uint8_t*>(buffer->data())); | 552 WrapBuffer(dims, static_cast<uint8_t*>(buffer->data())); |
553 ASSERT_TRUE(video_frame); | 553 ASSERT_TRUE(video_frame); |
554 device_->OnError(FROM_HERE, "Test Error"); | 554 device_->OnError(FROM_HERE, "Test Error"); |
555 video_frame->metadata()->SetTimeTicks( | 555 video_frame->metadata()->SetTimeTicks( |
556 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); | 556 media::VideoFrameMetadata::REFERENCE_TIME, base::TimeTicks()); |
557 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); | 557 device_->OnIncomingCapturedVideoFrame(std::move(buffer), video_frame); |
558 | 558 |
559 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); | 559 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); |
560 base::RunLoop().RunUntilIdle(); | 560 base::RunLoop().RunUntilIdle(); |
561 Mock::VerifyAndClearExpectations(client_a_.get()); | 561 Mock::VerifyAndClearExpectations(client_a_.get()); |
562 | 562 |
563 // Second client connects after the error state. It also should get told of | 563 // Second client connects after the error state. It also should get told of |
564 // the error. | 564 // the error. |
565 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 565 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
566 controller_->AddClient(route_id, client_b_.get(), 200, session_200); | 566 controller_->AddClient(route_id, client_b_.get(), 200, session_200); |
567 Mock::VerifyAndClearExpectations(client_b_.get()); | 567 Mock::VerifyAndClearExpectations(client_b_.get()); |
568 } | 568 } |
569 | 569 |
570 } // namespace content | 570 } // namespace content |
OLD | NEW |