OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Unit test for VideoCaptureController. | 5 // Unit test for VideoCaptureController. |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
14 #include "base/run_loop.h" | 14 #include "base/run_loop.h" |
15 #include "content/browser/renderer_host/media/media_stream_provider.h" | 15 #include "content/browser/renderer_host/media/media_stream_provider.h" |
16 #include "content/browser/renderer_host/media/video_capture_controller.h" | 16 #include "content/browser/renderer_host/media/video_capture_controller.h" |
17 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" | 17 #include "content/browser/renderer_host/media/video_capture_controller_event_han
dler.h" |
18 #include "content/browser/renderer_host/media/video_capture_manager.h" | 18 #include "content/browser/renderer_host/media/video_capture_manager.h" |
19 #include "content/common/media/media_stream_options.h" | 19 #include "content/common/media/media_stream_options.h" |
20 #include "content/public/test/test_browser_thread_bundle.h" | 20 #include "content/public/test/test_browser_thread_bundle.h" |
21 #include "media/base/video_frame.h" | 21 #include "gpu/command_buffer/common/mailbox_holder.h" |
22 #include "media/base/video_util.h" | 22 #include "media/base/video_util.h" |
23 #include "media/video/capture/video_capture_types.h" | 23 #include "media/video/capture/video_capture_types.h" |
24 #include "testing/gmock/include/gmock/gmock.h" | 24 #include "testing/gmock/include/gmock/gmock.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 | 26 |
27 using ::testing::InSequence; | 27 using ::testing::InSequence; |
28 using ::testing::Mock; | 28 using ::testing::Mock; |
29 | 29 |
30 namespace content { | 30 namespace content { |
31 | 31 |
32 class MockVideoCaptureControllerEventHandler | 32 class MockVideoCaptureControllerEventHandler |
33 : public VideoCaptureControllerEventHandler { | 33 : public VideoCaptureControllerEventHandler { |
34 public: | 34 public: |
35 explicit MockVideoCaptureControllerEventHandler( | 35 explicit MockVideoCaptureControllerEventHandler( |
36 VideoCaptureController* controller) | 36 VideoCaptureController* controller) |
37 : controller_(controller) {} | 37 : controller_(controller) {} |
38 virtual ~MockVideoCaptureControllerEventHandler() {} | 38 virtual ~MockVideoCaptureControllerEventHandler() {} |
39 | 39 |
40 // These mock methods are delegated to by our fake implementation of | 40 // These mock methods are delegated to by our fake implementation of |
41 // VideoCaptureControllerEventHandler, to be used in EXPECT_CALL(). | 41 // VideoCaptureControllerEventHandler, to be used in EXPECT_CALL(). |
42 MOCK_METHOD1(DoBufferCreated, void(const VideoCaptureControllerID&)); | 42 MOCK_METHOD1(DoBufferCreated, void(const VideoCaptureControllerID&)); |
43 MOCK_METHOD1(DoBufferDestroyed, void(const VideoCaptureControllerID&)); | 43 MOCK_METHOD1(DoBufferDestroyed, void(const VideoCaptureControllerID&)); |
44 MOCK_METHOD1(DoBufferReady, void(const VideoCaptureControllerID&)); | 44 MOCK_METHOD1(DoBufferReady, void(const VideoCaptureControllerID&)); |
| 45 MOCK_METHOD1(DoMailboxBufferReady, void(const VideoCaptureControllerID&)); |
45 MOCK_METHOD1(DoEnded, void(const VideoCaptureControllerID&)); | 46 MOCK_METHOD1(DoEnded, void(const VideoCaptureControllerID&)); |
46 MOCK_METHOD1(DoError, void(const VideoCaptureControllerID&)); | 47 MOCK_METHOD1(DoError, void(const VideoCaptureControllerID&)); |
47 | 48 |
48 virtual void OnError(const VideoCaptureControllerID& id) OVERRIDE { | 49 virtual void OnError(const VideoCaptureControllerID& id) OVERRIDE { |
49 DoError(id); | 50 DoError(id); |
50 } | 51 } |
51 virtual void OnBufferCreated(const VideoCaptureControllerID& id, | 52 virtual void OnBufferCreated(const VideoCaptureControllerID& id, |
52 base::SharedMemoryHandle handle, | 53 base::SharedMemoryHandle handle, |
53 int length, int buffer_id) OVERRIDE { | 54 int length, int buffer_id) OVERRIDE { |
54 DoBufferCreated(id); | 55 DoBufferCreated(id); |
55 } | 56 } |
56 virtual void OnBufferDestroyed(const VideoCaptureControllerID& id, | 57 virtual void OnBufferDestroyed(const VideoCaptureControllerID& id, |
57 int buffer_id) OVERRIDE { | 58 int buffer_id) OVERRIDE { |
58 DoBufferDestroyed(id); | 59 DoBufferDestroyed(id); |
59 } | 60 } |
60 virtual void OnBufferReady(const VideoCaptureControllerID& id, | 61 virtual void OnBufferReady(const VideoCaptureControllerID& id, |
61 int buffer_id, | 62 int buffer_id, |
62 base::TimeTicks timestamp, | 63 const media::VideoCaptureFormat& format, |
63 const media::VideoCaptureFormat& format) OVERRIDE { | 64 base::TimeTicks timestamp) OVERRIDE { |
64 DoBufferReady(id); | 65 DoBufferReady(id); |
65 base::MessageLoop::current()->PostTask(FROM_HERE, | 66 base::MessageLoop::current()->PostTask( |
| 67 FROM_HERE, |
66 base::Bind(&VideoCaptureController::ReturnBuffer, | 68 base::Bind(&VideoCaptureController::ReturnBuffer, |
67 base::Unretained(controller_), id, this, buffer_id)); | 69 base::Unretained(controller_), |
| 70 id, |
| 71 this, |
| 72 buffer_id, |
| 73 0)); |
| 74 } |
| 75 virtual void OnMailboxBufferReady(const VideoCaptureControllerID& id, |
| 76 int buffer_id, |
| 77 const gpu::MailboxHolder& mailbox_holder, |
| 78 const media::VideoCaptureFormat& format, |
| 79 base::TimeTicks timestamp) OVERRIDE { |
| 80 DoMailboxBufferReady(id); |
| 81 // Use a very different syncpoint value when returning a new syncpoint. |
| 82 const uint32 new_sync_point = ~mailbox_holder.sync_point; |
| 83 base::MessageLoop::current()->PostTask( |
| 84 FROM_HERE, |
| 85 base::Bind(&VideoCaptureController::ReturnBuffer, |
| 86 base::Unretained(controller_), |
| 87 id, |
| 88 this, |
| 89 buffer_id, |
| 90 new_sync_point)); |
68 } | 91 } |
69 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE { | 92 virtual void OnEnded(const VideoCaptureControllerID& id) OVERRIDE { |
70 DoEnded(id); | 93 DoEnded(id); |
71 // OnEnded() must respond by (eventually) unregistering the client. | 94 // OnEnded() must respond by (eventually) unregistering the client. |
72 base::MessageLoop::current()->PostTask(FROM_HERE, | 95 base::MessageLoop::current()->PostTask(FROM_HERE, |
73 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), | 96 base::Bind(base::IgnoreResult(&VideoCaptureController::RemoveClient), |
74 base::Unretained(controller_), id, this)); | 97 base::Unretained(controller_), id, this)); |
75 } | 98 } |
76 | 99 |
77 VideoCaptureController* controller_; | 100 VideoCaptureController* controller_; |
(...skipping 14 matching lines...) Expand all Loading... |
92 client_a_.reset(new MockVideoCaptureControllerEventHandler( | 115 client_a_.reset(new MockVideoCaptureControllerEventHandler( |
93 controller_.get())); | 116 controller_.get())); |
94 client_b_.reset(new MockVideoCaptureControllerEventHandler( | 117 client_b_.reset(new MockVideoCaptureControllerEventHandler( |
95 controller_.get())); | 118 controller_.get())); |
96 } | 119 } |
97 | 120 |
98 virtual void TearDown() OVERRIDE { | 121 virtual void TearDown() OVERRIDE { |
99 base::RunLoop().RunUntilIdle(); | 122 base::RunLoop().RunUntilIdle(); |
100 } | 123 } |
101 | 124 |
102 TestBrowserThreadBundle bindle_; | 125 scoped_refptr<media::VideoFrame> WrapI420Buffer( |
| 126 const scoped_refptr<media::VideoCaptureDevice::Client::Buffer>& buffer, |
| 127 gfx::Size dimensions) { |
| 128 return media::VideoFrame::WrapExternalPackedMemory( |
| 129 media::VideoFrame::I420, |
| 130 dimensions, |
| 131 gfx::Rect(dimensions), |
| 132 dimensions, |
| 133 reinterpret_cast<uint8*>(buffer->data()), |
| 134 media::VideoFrame::AllocationSize(media::VideoFrame::I420, dimensions), |
| 135 base::SharedMemory::NULLHandle(), |
| 136 base::TimeDelta(), |
| 137 base::Closure()); |
| 138 } |
| 139 |
| 140 scoped_refptr<media::VideoFrame> WrapMailboxBuffer( |
| 141 const scoped_refptr<media::VideoCaptureDevice::Client::Buffer>& buffer, |
| 142 scoped_ptr<gpu::MailboxHolder> holder, |
| 143 const media::VideoFrame::ReleaseMailboxCB& release_cb, |
| 144 gfx::Size dimensions) { |
| 145 return media::VideoFrame::WrapNativeTexture( |
| 146 holder.Pass(), |
| 147 release_cb, |
| 148 dimensions, |
| 149 gfx::Rect(dimensions), |
| 150 dimensions, |
| 151 base::TimeDelta(), |
| 152 media::VideoFrame::ReadPixelsCB()); |
| 153 } |
| 154 |
| 155 TestBrowserThreadBundle bundle_; |
103 scoped_ptr<MockVideoCaptureControllerEventHandler> client_a_; | 156 scoped_ptr<MockVideoCaptureControllerEventHandler> client_a_; |
104 scoped_ptr<MockVideoCaptureControllerEventHandler> client_b_; | 157 scoped_ptr<MockVideoCaptureControllerEventHandler> client_b_; |
105 scoped_ptr<VideoCaptureController> controller_; | 158 scoped_ptr<VideoCaptureController> controller_; |
106 scoped_ptr<media::VideoCaptureDevice::Client> device_; | 159 scoped_ptr<media::VideoCaptureDevice::Client> device_; |
107 | 160 |
108 private: | 161 private: |
109 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); | 162 DISALLOW_COPY_AND_ASSIGN(VideoCaptureControllerTest); |
110 }; | 163 }; |
111 | 164 |
112 // A simple test of VideoCaptureController's ability to add, remove, and keep | 165 // A simple test of VideoCaptureController's ability to add, remove, and keep |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 ASSERT_EQ(1, controller_->GetClientCount()) | 255 ASSERT_EQ(1, controller_->GetClientCount()) |
203 << "Removing non-existant session 200 should be a no-op."; | 256 << "Removing non-existant session 200 should be a no-op."; |
204 ASSERT_EQ(400, | 257 ASSERT_EQ(400, |
205 controller_->RemoveClient(client_b_route_2, client_b_.get())) | 258 controller_->RemoveClient(client_b_route_2, client_b_.get())) |
206 << "Removing client B/2 should return its session_id."; | 259 << "Removing client B/2 should return its session_id."; |
207 // Clients in controller: [] | 260 // Clients in controller: [] |
208 ASSERT_EQ(0, controller_->GetClientCount()) | 261 ASSERT_EQ(0, controller_->GetClientCount()) |
209 << "Client count should return to zero after all clients are gone."; | 262 << "Client count should return to zero after all clients are gone."; |
210 } | 263 } |
211 | 264 |
| 265 static void CacheSyncPoint(uint32* sync_value, |
| 266 scoped_ptr<gpu::MailboxHolder> mailbox_holder) { |
| 267 *sync_value = mailbox_holder->sync_point; |
| 268 } |
| 269 |
212 // This test will connect and disconnect several clients while simulating an | 270 // This test will connect and disconnect several clients while simulating an |
213 // active capture device being started and generating frames. It runs on one | 271 // active capture device being started and generating frames. It runs on one |
214 // thread and is intended to behave deterministically. | 272 // thread and is intended to behave deterministically. |
215 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { | 273 TEST_F(VideoCaptureControllerTest, NormalCaptureMultipleClients) { |
216 media::VideoCaptureParams session_100; | 274 media::VideoCaptureParams session_100; |
217 session_100.requested_format = media::VideoCaptureFormat( | 275 session_100.requested_format = media::VideoCaptureFormat( |
218 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 276 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
219 | 277 |
220 media::VideoCaptureParams session_200 = session_100; | 278 media::VideoCaptureParams session_200 = session_100; |
221 | 279 |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 { | 327 { |
270 InSequence s; | 328 InSequence s; |
271 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); | 329 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); |
272 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); | 330 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); |
273 } | 331 } |
274 { | 332 { |
275 InSequence s; | 333 InSequence s; |
276 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); | 334 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); |
277 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); | 335 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); |
278 } | 336 } |
279 device_->OnIncomingCapturedBuffer(buffer, | 337 device_->OnIncomingCapturedVideoFrame( |
280 media::VideoFrame::I420, | 338 buffer, |
281 capture_resolution, | 339 media::VideoCaptureFormat(capture_resolution, |
282 base::TimeTicks(), | 340 device_format.frame_rate, |
283 device_format.frame_rate); | 341 media::PIXEL_FORMAT_I420), |
| 342 WrapI420Buffer(buffer, capture_resolution), |
| 343 base::TimeTicks()); |
284 buffer = NULL; | 344 buffer = NULL; |
285 | 345 |
286 base::RunLoop().RunUntilIdle(); | 346 base::RunLoop().RunUntilIdle(); |
287 Mock::VerifyAndClearExpectations(client_a_.get()); | 347 Mock::VerifyAndClearExpectations(client_a_.get()); |
288 Mock::VerifyAndClearExpectations(client_b_.get()); | 348 Mock::VerifyAndClearExpectations(client_b_.get()); |
289 | 349 |
290 // 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 |
291 // 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 |
292 // delay. This shouldn't affect anything. | 352 // delay. This shouldn't affect anything. |
293 buffer = | 353 buffer = |
294 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); | 354 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
295 ASSERT_TRUE(buffer); | 355 ASSERT_TRUE(buffer); |
296 memset(buffer->data(), buffer_no++, buffer->size()); | 356 memset(buffer->data(), buffer_no++, buffer->size()); |
297 device_->OnIncomingCapturedBuffer(buffer, | 357 device_->OnIncomingCapturedVideoFrame( |
298 media::VideoFrame::I420, | 358 buffer, |
299 capture_resolution, | 359 media::VideoCaptureFormat(capture_resolution, |
300 base::TimeTicks(), | 360 device_format.frame_rate, |
301 device_format.frame_rate); | 361 media::PIXEL_FORMAT_I420), |
| 362 WrapI420Buffer(buffer, capture_resolution), |
| 363 base::TimeTicks()); |
302 buffer = NULL; | 364 buffer = NULL; |
303 | 365 |
304 // The buffer should be delivered to the clients in any order. | 366 // The buffer should be delivered to the clients in any order. |
305 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1); | 367 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1); |
306 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); | 368 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); |
307 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); | 369 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); |
308 base::RunLoop().RunUntilIdle(); | 370 base::RunLoop().RunUntilIdle(); |
309 Mock::VerifyAndClearExpectations(client_a_.get()); | 371 Mock::VerifyAndClearExpectations(client_a_.get()); |
310 Mock::VerifyAndClearExpectations(client_b_.get()); | 372 Mock::VerifyAndClearExpectations(client_b_.get()); |
311 | 373 |
312 // Add a fourth client now that some buffers have come through. | 374 // Add a fourth client now that some buffers have come through. |
313 controller_->AddClient(client_b_route_2, | 375 controller_->AddClient(client_b_route_2, |
314 client_b_.get(), | 376 client_b_.get(), |
315 base::kNullProcessHandle, | 377 base::kNullProcessHandle, |
316 1, | 378 1, |
317 session_1); | 379 session_1); |
318 Mock::VerifyAndClearExpectations(client_b_.get()); | 380 Mock::VerifyAndClearExpectations(client_b_.get()); |
319 | 381 |
320 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. | 382 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. |
321 for (int i = 0; i < kPoolSize; i++) { | 383 for (int i = 0; i < kPoolSize; i++) { |
322 buffer = device_->ReserveOutputBuffer(media::VideoFrame::I420, | 384 buffer = device_->ReserveOutputBuffer(media::VideoFrame::I420, |
323 capture_resolution); | 385 capture_resolution); |
324 ASSERT_TRUE(buffer); | 386 ASSERT_TRUE(buffer); |
325 memset(buffer->data(), buffer_no++, buffer->size()); | 387 memset(buffer->data(), buffer_no++, buffer->size()); |
326 device_->OnIncomingCapturedBuffer(buffer, | 388 device_->OnIncomingCapturedVideoFrame( |
327 media::VideoFrame::I420, | 389 buffer, |
328 capture_resolution, | 390 media::VideoCaptureFormat(capture_resolution, |
329 base::TimeTicks(), | 391 device_format.frame_rate, |
330 device_format.frame_rate); | 392 media::PIXEL_FORMAT_I420), |
| 393 WrapI420Buffer(buffer, capture_resolution), |
| 394 base::TimeTicks()); |
331 buffer = NULL; | 395 buffer = NULL; |
332 } | 396 } |
333 // ReserveOutputBuffer ought to fail now, because the pool is depleted. | 397 // ReserveOutputBuffer ought to fail now, because the pool is depleted. |
334 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, | 398 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, |
335 capture_resolution)); | 399 capture_resolution)); |
336 | 400 |
337 // The new client needs to be told of 3 buffers; the old clients only 2. | 401 // The new client needs to be told of 3 buffers; the old clients only 2. |
338 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); | 402 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); |
339 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(kPoolSize); | 403 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(kPoolSize); |
340 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) | 404 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) |
(...skipping 13 matching lines...) Expand all Loading... |
354 // Kill A1 via renderer disconnect (synchronous). | 418 // Kill A1 via renderer disconnect (synchronous). |
355 controller_->RemoveClient(client_a_route_1, client_a_.get()); | 419 controller_->RemoveClient(client_a_route_1, client_a_.get()); |
356 // Kill B1 via session close (posts a task to disconnect). | 420 // Kill B1 via session close (posts a task to disconnect). |
357 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); | 421 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); |
358 controller_->StopSession(300); | 422 controller_->StopSession(300); |
359 // Queue up another buffer. | 423 // Queue up another buffer. |
360 buffer = | 424 buffer = |
361 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); | 425 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
362 ASSERT_TRUE(buffer); | 426 ASSERT_TRUE(buffer); |
363 memset(buffer->data(), buffer_no++, buffer->size()); | 427 memset(buffer->data(), buffer_no++, buffer->size()); |
364 device_->OnIncomingCapturedBuffer(buffer, | 428 device_->OnIncomingCapturedVideoFrame( |
365 media::VideoFrame::I420, | 429 buffer, |
366 capture_resolution, | 430 media::VideoCaptureFormat(capture_resolution, |
367 base::TimeTicks(), | 431 device_format.frame_rate, |
368 device_format.frame_rate); | 432 media::PIXEL_FORMAT_I420), |
| 433 WrapI420Buffer(buffer, capture_resolution), |
| 434 base::TimeTicks()); |
369 buffer = NULL; | 435 buffer = NULL; |
370 buffer = | 436 buffer = |
371 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); | 437 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
372 { | 438 { |
373 // Kill A2 via session close (posts a task to disconnect, but A2 must not | 439 // Kill A2 via session close (posts a task to disconnect, but A2 must not |
374 // be sent either of these two buffers). | 440 // be sent either of these two buffers). |
375 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); | 441 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); |
376 controller_->StopSession(200); | 442 controller_->StopSession(200); |
377 } | 443 } |
378 ASSERT_TRUE(buffer); | 444 ASSERT_TRUE(buffer); |
379 memset(buffer->data(), buffer_no++, buffer->size()); | 445 memset(buffer->data(), buffer_no++, buffer->size()); |
380 device_->OnIncomingCapturedBuffer(buffer, | 446 device_->OnIncomingCapturedVideoFrame( |
381 media::VideoFrame::I420, | 447 buffer, |
382 capture_resolution, | 448 media::VideoCaptureFormat(capture_resolution, |
383 base::TimeTicks(), | 449 device_format.frame_rate, |
384 device_format.frame_rate); | 450 media::PIXEL_FORMAT_I420), |
| 451 WrapI420Buffer(buffer, capture_resolution), |
| 452 base::TimeTicks()); |
385 buffer = NULL; | 453 buffer = NULL; |
386 // B2 is the only client left, and is the only one that should | 454 // B2 is the only client left, and is the only one that should |
387 // get the buffer. | 455 // get the buffer. |
388 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(2); | 456 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(2); |
389 base::RunLoop().RunUntilIdle(); | 457 base::RunLoop().RunUntilIdle(); |
390 Mock::VerifyAndClearExpectations(client_a_.get()); | 458 Mock::VerifyAndClearExpectations(client_a_.get()); |
391 Mock::VerifyAndClearExpectations(client_b_.get()); | 459 Mock::VerifyAndClearExpectations(client_b_.get()); |
| 460 |
| 461 // Allocate all buffers from the buffer pool, half as SHM buffer and half as |
| 462 // mailbox buffers. Make sure of different counts though. |
| 463 int shm_buffers = kPoolSize / 2; |
| 464 int mailbox_buffers = kPoolSize - shm_buffers; |
| 465 if (shm_buffers == mailbox_buffers) { |
| 466 shm_buffers--; |
| 467 mailbox_buffers++; |
| 468 } |
| 469 |
| 470 for (int i = 0; i < shm_buffers; ++i) { |
| 471 buffer = device_->ReserveOutputBuffer(media::VideoFrame::I420, |
| 472 capture_resolution); |
| 473 ASSERT_TRUE(buffer); |
| 474 device_->OnIncomingCapturedVideoFrame( |
| 475 buffer, |
| 476 media::VideoCaptureFormat(capture_resolution, |
| 477 device_format.frame_rate, |
| 478 media::PIXEL_FORMAT_I420), |
| 479 WrapI420Buffer(buffer, capture_resolution), |
| 480 base::TimeTicks()); |
| 481 buffer = NULL; |
| 482 } |
| 483 std::vector<uint32> mailbox_syncpoints(mailbox_buffers); |
| 484 std::vector<uint32> mailbox_syncpoints_new(mailbox_buffers); |
| 485 for (int i = 0; i < mailbox_buffers; ++i) { |
| 486 buffer = device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, |
| 487 gfx::Size(0, 0)); |
| 488 ASSERT_TRUE(buffer); |
| 489 mailbox_syncpoints[i] = i; |
| 490 device_->OnIncomingCapturedVideoFrame( |
| 491 buffer, |
| 492 media::VideoCaptureFormat(capture_resolution, |
| 493 device_format.frame_rate, |
| 494 media::PIXEL_FORMAT_TEXTURE), |
| 495 WrapMailboxBuffer( |
| 496 buffer, |
| 497 make_scoped_ptr(new gpu::MailboxHolder( |
| 498 gpu::Mailbox(), 0, mailbox_syncpoints[i])), |
| 499 base::Bind(&CacheSyncPoint, &mailbox_syncpoints_new[i]), |
| 500 capture_resolution), |
| 501 base::TimeTicks()); |
| 502 buffer = NULL; |
| 503 } |
| 504 // ReserveOutputBuffers ought to fail now regardless of buffer format, because |
| 505 // the pool is depleted. |
| 506 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, |
| 507 capture_resolution)); |
| 508 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::NATIVE_TEXTURE, |
| 509 gfx::Size(0, 0))); |
| 510 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(shm_buffers); |
| 511 EXPECT_CALL(*client_b_, DoMailboxBufferReady(client_b_route_2)) |
| 512 .Times(mailbox_buffers); |
| 513 base::RunLoop().RunUntilIdle(); |
| 514 for (size_t i = 0; i < mailbox_syncpoints.size(); ++i) { |
| 515 // See: MockVideoCaptureControllerEventHandler::OnMailboxBufferReady() |
| 516 ASSERT_EQ(mailbox_syncpoints[i], ~mailbox_syncpoints_new[i]); |
| 517 } |
| 518 Mock::VerifyAndClearExpectations(client_b_.get()); |
392 } | 519 } |
393 | 520 |
394 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 521 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
395 // behavior of various operations after the error state has been signalled. | 522 // behavior of various operations after the error state has been signalled. |
396 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { | 523 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { |
397 media::VideoCaptureParams session_100; | 524 media::VideoCaptureParams session_100; |
398 session_100.requested_format = media::VideoCaptureFormat( | 525 session_100.requested_format = media::VideoCaptureFormat( |
399 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); | 526 gfx::Size(320, 240), 30, media::PIXEL_FORMAT_I420); |
400 | 527 |
401 media::VideoCaptureParams session_200 = session_100; | 528 media::VideoCaptureParams session_200 = session_100; |
(...skipping 15 matching lines...) Expand all Loading... |
417 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 544 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
418 controller_->AddClient( | 545 controller_->AddClient( |
419 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); | 546 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); |
420 base::RunLoop().RunUntilIdle(); | 547 base::RunLoop().RunUntilIdle(); |
421 Mock::VerifyAndClearExpectations(client_b_.get()); | 548 Mock::VerifyAndClearExpectations(client_b_.get()); |
422 | 549 |
423 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = | 550 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = |
424 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); | 551 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
425 ASSERT_TRUE(buffer); | 552 ASSERT_TRUE(buffer); |
426 | 553 |
427 device_->OnIncomingCapturedBuffer(buffer, | 554 device_->OnIncomingCapturedVideoFrame( |
428 media::VideoFrame::I420, | 555 buffer, |
429 capture_resolution, | 556 media::VideoCaptureFormat( |
430 base::TimeTicks(), | 557 capture_resolution, 30, media::PIXEL_FORMAT_I420), |
431 30); | 558 WrapI420Buffer(buffer, capture_resolution), |
| 559 base::TimeTicks()); |
432 buffer = NULL; | 560 buffer = NULL; |
433 | 561 |
434 base::RunLoop().RunUntilIdle(); | 562 base::RunLoop().RunUntilIdle(); |
435 } | 563 } |
436 | 564 |
437 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 565 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
438 // behavior of various operations after the error state has been signalled. | 566 // behavior of various operations after the error state has been signalled. |
439 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { | 567 TEST_F(VideoCaptureControllerTest, ErrorAfterDeviceCreation) { |
440 media::VideoCaptureParams session_100; | 568 media::VideoCaptureParams session_100; |
441 session_100.requested_format = media::VideoCaptureFormat( | 569 session_100.requested_format = media::VideoCaptureFormat( |
(...skipping 14 matching lines...) Expand all Loading... |
456 // should not be. | 584 // should not be. |
457 base::RunLoop().RunUntilIdle(); | 585 base::RunLoop().RunUntilIdle(); |
458 Mock::VerifyAndClearExpectations(client_a_.get()); | 586 Mock::VerifyAndClearExpectations(client_a_.get()); |
459 | 587 |
460 const gfx::Size dims(320, 240); | 588 const gfx::Size dims(320, 240); |
461 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = | 589 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = |
462 device_->ReserveOutputBuffer(media::VideoFrame::I420, dims); | 590 device_->ReserveOutputBuffer(media::VideoFrame::I420, dims); |
463 ASSERT_TRUE(buffer); | 591 ASSERT_TRUE(buffer); |
464 | 592 |
465 device_->OnError("Test error"); | 593 device_->OnError("Test error"); |
466 device_->OnIncomingCapturedBuffer(buffer, | 594 device_->OnIncomingCapturedVideoFrame( |
467 media::VideoFrame::I420, | 595 buffer, |
468 dims, | 596 media::VideoCaptureFormat( |
469 base::TimeTicks(), | 597 dims, device_format.frame_rate, media::PIXEL_FORMAT_I420), |
470 device_format.frame_rate); | 598 WrapI420Buffer(buffer, dims), |
| 599 base::TimeTicks()); |
471 buffer = NULL; | 600 buffer = NULL; |
472 | 601 |
473 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); | 602 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); |
474 base::RunLoop().RunUntilIdle(); | 603 base::RunLoop().RunUntilIdle(); |
475 Mock::VerifyAndClearExpectations(client_a_.get()); | 604 Mock::VerifyAndClearExpectations(client_a_.get()); |
476 | 605 |
477 // Second client connects after the error state. It also should get told of | 606 // Second client connects after the error state. It also should get told of |
478 // the error. | 607 // the error. |
479 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 608 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
480 controller_->AddClient( | 609 controller_->AddClient( |
481 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); | 610 route_id, client_b_.get(), base::kNullProcessHandle, 200, session_200); |
482 Mock::VerifyAndClearExpectations(client_b_.get()); | 611 Mock::VerifyAndClearExpectations(client_b_.get()); |
483 } | 612 } |
484 | 613 |
485 } // namespace content | 614 } // namespace content |
OLD | NEW |