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" |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 235 |
236 // Start with two clients. | 236 // Start with two clients. |
237 controller_->AddClient(client_a_route_1, client_a_.get(), | 237 controller_->AddClient(client_a_route_1, client_a_.get(), |
238 base::kNullProcessHandle, session_100); | 238 base::kNullProcessHandle, session_100); |
239 controller_->AddClient(client_b_route_1, client_b_.get(), | 239 controller_->AddClient(client_b_route_1, client_b_.get(), |
240 base::kNullProcessHandle, session_300); | 240 base::kNullProcessHandle, session_300); |
241 controller_->AddClient(client_a_route_2, client_a_.get(), | 241 controller_->AddClient(client_a_route_2, client_a_.get(), |
242 base::kNullProcessHandle, session_200); | 242 base::kNullProcessHandle, session_200); |
243 ASSERT_EQ(3, controller_->GetClientCount()); | 243 ASSERT_EQ(3, controller_->GetClientCount()); |
244 | 244 |
245 // Now, simulate an incoming captured frame from the capture device. As a side | 245 // Now, simulate an incoming captured buffer from the capture device. As a |
246 // effect this will cause the first buffer to be shared with clients. | 246 // side effect this will cause the first buffer to be shared with clients. |
247 uint8 frame_no = 1; | 247 uint8 buffer_no = 1; |
248 scoped_refptr<media::VideoFrame> frame; | 248 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer; |
249 frame = device_->ReserveOutputBuffer(capture_resolution); | 249 buffer = |
250 ASSERT_TRUE(frame); | 250 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
251 media::FillYUV(frame, frame_no++, 0x22, 0x44); | 251 ASSERT_TRUE(buffer); |
| 252 memset(buffer->data(), buffer_no++, buffer->size()); |
252 { | 253 { |
253 InSequence s; | 254 InSequence s; |
254 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); | 255 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)).Times(1); |
255 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1); | 256 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1); |
256 } | 257 } |
257 { | 258 { |
258 InSequence s; | 259 InSequence s; |
259 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); | 260 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)).Times(1); |
260 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); | 261 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); |
261 } | 262 } |
262 { | 263 { |
263 InSequence s; | 264 InSequence s; |
264 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); | 265 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)).Times(1); |
265 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); | 266 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); |
266 } | 267 } |
267 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); | 268 device_->OnIncomingCapturedBuffer( |
268 frame = NULL; | 269 buffer, media::VideoFrame::I420, capture_resolution, base::Time()); |
| 270 buffer = NULL; |
269 | 271 |
270 base::RunLoop().RunUntilIdle(); | 272 base::RunLoop().RunUntilIdle(); |
271 Mock::VerifyAndClearExpectations(client_a_.get()); | 273 Mock::VerifyAndClearExpectations(client_a_.get()); |
272 Mock::VerifyAndClearExpectations(client_b_.get()); | 274 Mock::VerifyAndClearExpectations(client_b_.get()); |
273 | 275 |
274 // Second frame which ought to use the same shared memory buffer. In this case | 276 // Second buffer which ought to use the same shared memory buffer. In this |
275 // pretend that the VideoFrame pointer is held by the device for a long delay. | 277 // case pretend that the Buffer pointer is held by the device for a long |
276 // This shouldn't affect anything. | 278 // delay. This shouldn't affect anything. |
277 frame = device_->ReserveOutputBuffer(capture_resolution); | 279 buffer = |
278 ASSERT_TRUE(frame); | 280 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
279 media::FillYUV(frame, frame_no++, 0x22, 0x44); | 281 ASSERT_TRUE(buffer); |
280 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); | 282 memset(buffer->data(), buffer_no++, buffer->size()); |
| 283 device_->OnIncomingCapturedBuffer( |
| 284 buffer, media::VideoFrame::I420, capture_resolution, base::Time()); |
| 285 buffer = NULL; |
281 | 286 |
282 // The buffer should be delivered to the clients in any order. | 287 // The buffer should be delivered to the clients in any order. |
283 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1); | 288 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(1); |
284 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); | 289 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(1); |
285 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); | 290 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(1); |
286 base::RunLoop().RunUntilIdle(); | 291 base::RunLoop().RunUntilIdle(); |
287 Mock::VerifyAndClearExpectations(client_a_.get()); | 292 Mock::VerifyAndClearExpectations(client_a_.get()); |
288 Mock::VerifyAndClearExpectations(client_b_.get()); | 293 Mock::VerifyAndClearExpectations(client_b_.get()); |
289 frame = NULL; | |
290 | 294 |
291 // Add a fourth client now that some frames have come through. | 295 // Add a fourth client now that some buffers have come through. |
292 controller_->AddClient(client_b_route_2, client_b_.get(), | 296 controller_->AddClient(client_b_route_2, client_b_.get(), |
293 base::kNullProcessHandle, session_1); | 297 base::kNullProcessHandle, session_1); |
294 Mock::VerifyAndClearExpectations(client_b_.get()); | 298 Mock::VerifyAndClearExpectations(client_b_.get()); |
295 | 299 |
296 // Third, fourth, and fifth frames. Pretend they all arrive at the same time. | 300 // Third, fourth, and fifth buffers. Pretend they all arrive at the same time. |
297 for (int i = 0; i < kPoolSize; i++) { | 301 for (int i = 0; i < kPoolSize; i++) { |
298 frame = device_->ReserveOutputBuffer(capture_resolution); | 302 buffer = device_->ReserveOutputBuffer(media::VideoFrame::I420, |
299 ASSERT_TRUE(frame); | 303 capture_resolution); |
300 ASSERT_EQ(media::VideoFrame::I420, frame->format()); | 304 ASSERT_TRUE(buffer); |
301 media::FillYUV(frame, frame_no++, 0x22, 0x44); | 305 memset(buffer->data(), buffer_no++, buffer->size()); |
302 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); | 306 device_->OnIncomingCapturedBuffer( |
303 | 307 buffer, media::VideoFrame::I420, capture_resolution, base::Time()); |
| 308 buffer = NULL; |
304 } | 309 } |
305 // ReserveOutputBuffer ought to fail now, because the pool is depleted. | 310 // ReserveOutputBuffer ought to fail now, because the pool is depleted. |
306 ASSERT_FALSE(device_->ReserveOutputBuffer(capture_resolution)); | 311 ASSERT_FALSE(device_->ReserveOutputBuffer(media::VideoFrame::I420, |
| 312 capture_resolution)); |
307 | 313 |
308 // The new client needs to be told of 3 buffers; the old clients only 2. | 314 // The new client needs to be told of 3 buffers; the old clients only 2. |
309 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); | 315 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_2)).Times(kPoolSize); |
310 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(kPoolSize); | 316 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(kPoolSize); |
311 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) | 317 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_1)) |
312 .Times(kPoolSize - 1); | 318 .Times(kPoolSize - 1); |
313 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(kPoolSize); | 319 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_1)).Times(kPoolSize); |
314 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)) | 320 EXPECT_CALL(*client_a_, DoBufferCreated(client_a_route_2)) |
315 .Times(kPoolSize - 1); | 321 .Times(kPoolSize - 1); |
316 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(kPoolSize); | 322 EXPECT_CALL(*client_a_, DoBufferReady(client_a_route_2)).Times(kPoolSize); |
317 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)) | 323 EXPECT_CALL(*client_b_, DoBufferCreated(client_b_route_1)) |
318 .Times(kPoolSize - 1); | 324 .Times(kPoolSize - 1); |
319 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(kPoolSize); | 325 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_1)).Times(kPoolSize); |
320 base::RunLoop().RunUntilIdle(); | 326 base::RunLoop().RunUntilIdle(); |
321 Mock::VerifyAndClearExpectations(client_a_.get()); | 327 Mock::VerifyAndClearExpectations(client_a_.get()); |
322 Mock::VerifyAndClearExpectations(client_b_.get()); | 328 Mock::VerifyAndClearExpectations(client_b_.get()); |
323 | 329 |
324 // Now test the interaction of client shutdown and frame delivery. | 330 // Now test the interaction of client shutdown and buffer delivery. |
325 // Kill A1 via renderer disconnect (synchronous). | 331 // Kill A1 via renderer disconnect (synchronous). |
326 controller_->RemoveClient(client_a_route_1, client_a_.get()); | 332 controller_->RemoveClient(client_a_route_1, client_a_.get()); |
327 // Kill B1 via session close (posts a task to disconnect). | 333 // Kill B1 via session close (posts a task to disconnect). |
328 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); | 334 EXPECT_CALL(*client_b_, DoEnded(client_b_route_1)).Times(1); |
329 controller_->StopSession(300); | 335 controller_->StopSession(300); |
330 // Queue up another frame. | 336 // Queue up another buffer. |
331 frame = device_->ReserveOutputBuffer(capture_resolution); | 337 buffer = |
332 ASSERT_TRUE(frame); | 338 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
333 media::FillYUV(frame, frame_no++, 0x22, 0x44); | 339 ASSERT_TRUE(buffer); |
334 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); | 340 memset(buffer->data(), buffer_no++, buffer->size()); |
335 frame = device_->ReserveOutputBuffer(capture_resolution); | 341 device_->OnIncomingCapturedBuffer( |
| 342 buffer, media::VideoFrame::I420, capture_resolution, base::Time()); |
| 343 buffer = NULL; |
| 344 buffer = |
| 345 device_->ReserveOutputBuffer(media::VideoFrame::I420, capture_resolution); |
336 { | 346 { |
337 // Kill A2 via session close (posts a task to disconnect, but A2 must not | 347 // Kill A2 via session close (posts a task to disconnect, but A2 must not |
338 // be sent either of these two frames).. | 348 // be sent either of these two buffers). |
339 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); | 349 EXPECT_CALL(*client_a_, DoEnded(client_a_route_2)).Times(1); |
340 controller_->StopSession(200); | 350 controller_->StopSession(200); |
341 } | 351 } |
342 ASSERT_TRUE(frame); | 352 ASSERT_TRUE(buffer); |
343 media::FillYUV(frame, frame_no++, 0x22, 0x44); | 353 memset(buffer->data(), buffer_no++, buffer->size()); |
344 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); | 354 device_->OnIncomingCapturedBuffer( |
| 355 buffer, media::VideoFrame::I420, capture_resolution, base::Time()); |
| 356 buffer = NULL; |
345 // B2 is the only client left, and is the only one that should | 357 // B2 is the only client left, and is the only one that should |
346 // get the frame. | 358 // get the buffer. |
347 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(2); | 359 EXPECT_CALL(*client_b_, DoBufferReady(client_b_route_2)).Times(2); |
348 base::RunLoop().RunUntilIdle(); | 360 base::RunLoop().RunUntilIdle(); |
349 Mock::VerifyAndClearExpectations(client_a_.get()); | 361 Mock::VerifyAndClearExpectations(client_a_.get()); |
350 Mock::VerifyAndClearExpectations(client_b_.get()); | 362 Mock::VerifyAndClearExpectations(client_b_.get()); |
351 } | 363 } |
352 | 364 |
353 // Exercises the OnError() codepath of VideoCaptureController, and tests the | 365 // Exercises the OnError() codepath of VideoCaptureController, and tests the |
354 // behavior of various operations after the error state has been signalled. | 366 // behavior of various operations after the error state has been signalled. |
355 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { | 367 TEST_F(VideoCaptureControllerTest, ErrorBeforeDeviceCreation) { |
356 media::VideoCaptureParams session_100; | 368 media::VideoCaptureParams session_100; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 const VideoCaptureControllerID route_id(0x99); | 414 const VideoCaptureControllerID route_id(0x99); |
403 | 415 |
404 // Start with one client. | 416 // Start with one client. |
405 controller_->AddClient(route_id, client_a_.get(), | 417 controller_->AddClient(route_id, client_a_.get(), |
406 base::kNullProcessHandle, session_100); | 418 base::kNullProcessHandle, session_100); |
407 // OnFrameInfo from the VCD should become a no-op after the error occurs. | 419 // OnFrameInfo from the VCD should become a no-op after the error occurs. |
408 media::VideoCaptureCapability device_format( | 420 media::VideoCaptureCapability device_format( |
409 10, 10, 25, media::PIXEL_FORMAT_ARGB, | 421 10, 10, 25, media::PIXEL_FORMAT_ARGB, |
410 media::ConstantResolutionVideoCaptureDevice); | 422 media::ConstantResolutionVideoCaptureDevice); |
411 | 423 |
412 // Start the device. Then, before the first frame, signal an error and deliver | 424 // Start the device. Then, before the first buffer, signal an error and |
413 // the frame. The error should be propagated to clients; the frame should not | 425 // deliver the buffer. The error should be propagated to clients; the buffer |
414 // be. | 426 // should not be. |
415 base::RunLoop().RunUntilIdle(); | 427 base::RunLoop().RunUntilIdle(); |
416 Mock::VerifyAndClearExpectations(client_a_.get()); | 428 Mock::VerifyAndClearExpectations(client_a_.get()); |
417 | 429 |
418 scoped_refptr<media::VideoFrame> frame = | 430 const gfx::Size dims(320, 240); |
419 device_->ReserveOutputBuffer(gfx::Size(320, 240)); | 431 scoped_refptr<media::VideoCaptureDevice::Client::Buffer> buffer = |
420 ASSERT_TRUE(frame); | 432 device_->ReserveOutputBuffer(media::VideoFrame::I420, dims); |
| 433 ASSERT_TRUE(buffer); |
421 | 434 |
422 device_->OnError(); | 435 device_->OnError(); |
423 device_->OnIncomingCapturedVideoFrame(frame, base::Time()); | 436 device_->OnIncomingCapturedBuffer( |
424 frame = NULL; | 437 buffer, media::VideoFrame::I420, dims, base::Time()); |
| 438 buffer = NULL; |
425 | 439 |
426 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); | 440 EXPECT_CALL(*client_a_, DoError(route_id)).Times(1); |
427 base::RunLoop().RunUntilIdle(); | 441 base::RunLoop().RunUntilIdle(); |
428 Mock::VerifyAndClearExpectations(client_a_.get()); | 442 Mock::VerifyAndClearExpectations(client_a_.get()); |
429 | 443 |
430 // Second client connects after the error state. It also should get told of | 444 // Second client connects after the error state. It also should get told of |
431 // the error. | 445 // the error. |
432 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); | 446 EXPECT_CALL(*client_b_, DoError(route_id)).Times(1); |
433 controller_->AddClient(route_id, client_b_.get(), | 447 controller_->AddClient(route_id, client_b_.get(), |
434 base::kNullProcessHandle, session_200); | 448 base::kNullProcessHandle, session_200); |
435 Mock::VerifyAndClearExpectations(client_b_.get()); | 449 Mock::VerifyAndClearExpectations(client_b_.get()); |
436 } | 450 } |
437 | 451 |
438 } // namespace content | 452 } // namespace content |
OLD | NEW |