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 #include <map> | 5 #include <map> |
6 #include <string> | 6 #include <string> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 dump_video_(false) {} | 119 dump_video_(false) {} |
120 | 120 |
121 // A list of mock methods. | 121 // A list of mock methods. |
122 MOCK_METHOD4(OnNewBufferCreated, | 122 MOCK_METHOD4(OnNewBufferCreated, |
123 void(int device_id, | 123 void(int device_id, |
124 base::SharedMemoryHandle handle, | 124 base::SharedMemoryHandle handle, |
125 int length, | 125 int length, |
126 int buffer_id)); | 126 int buffer_id)); |
127 MOCK_METHOD2(OnBufferFreed, | 127 MOCK_METHOD2(OnBufferFreed, |
128 void(int device_id, int buffer_id)); | 128 void(int device_id, int buffer_id)); |
129 MOCK_METHOD4(OnBufferFilled, | 129 MOCK_METHOD5(OnBufferFilled, |
130 void(int device_id, | 130 void(int device_id, |
131 int buffer_id, | 131 int buffer_id, |
132 const media::VideoCaptureFormat& format, | 132 const media::VideoCaptureFormat& format, |
| 133 const gfx::Rect& visible_rect, |
133 base::TimeTicks timestamp)); | 134 base::TimeTicks timestamp)); |
134 MOCK_METHOD5(OnMailboxBufferFilled, | 135 MOCK_METHOD5(OnMailboxBufferFilled, |
135 void(int device_id, | 136 void(int device_id, |
136 int buffer_id, | 137 int buffer_id, |
137 const gpu::MailboxHolder& mailbox_holder, | 138 const gpu::MailboxHolder& mailbox_holder, |
138 const media::VideoCaptureFormat& format, | 139 const media::VideoCaptureFormat& format, |
139 base::TimeTicks timestamp)); | 140 base::TimeTicks timestamp)); |
140 MOCK_METHOD2(OnStateChanged, void(int device_id, VideoCaptureState state)); | 141 MOCK_METHOD2(OnStateChanged, void(int device_id, VideoCaptureState state)); |
141 | 142 |
142 // Use class DumpVideo to write I420 video to file. | 143 // Use class DumpVideo to write I420 video to file. |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 std::map<int, base::SharedMemory*>::iterator it = | 216 std::map<int, base::SharedMemory*>::iterator it = |
216 filled_dib_.find(buffer_id); | 217 filled_dib_.find(buffer_id); |
217 ASSERT_TRUE(it != filled_dib_.end()); | 218 ASSERT_TRUE(it != filled_dib_.end()); |
218 delete it->second; | 219 delete it->second; |
219 filled_dib_.erase(it); | 220 filled_dib_.erase(it); |
220 } | 221 } |
221 | 222 |
222 void OnBufferFilledDispatch(int device_id, | 223 void OnBufferFilledDispatch(int device_id, |
223 int buffer_id, | 224 int buffer_id, |
224 const media::VideoCaptureFormat& frame_format, | 225 const media::VideoCaptureFormat& frame_format, |
| 226 const gfx::Rect& visible_rect, |
225 base::TimeTicks timestamp) { | 227 base::TimeTicks timestamp) { |
226 base::SharedMemory* dib = filled_dib_[buffer_id]; | 228 base::SharedMemory* dib = filled_dib_[buffer_id]; |
227 ASSERT_TRUE(dib != NULL); | 229 ASSERT_TRUE(dib != NULL); |
228 if (dump_video_) { | 230 if (dump_video_) { |
229 if (!format_.IsValid()) { | 231 if (!format_.IsValid()) { |
230 dumper_.StartDump(frame_format.frame_size.width(), | 232 dumper_.StartDump(frame_format.frame_size.width(), |
231 frame_format.frame_size.height()); | 233 frame_format.frame_size.height()); |
232 format_ = frame_format; | 234 format_ = frame_format; |
233 } | 235 } |
234 ASSERT_EQ(format_.frame_size.width(), frame_format.frame_size.width()) | 236 ASSERT_EQ(format_.frame_size.width(), frame_format.frame_size.width()) |
235 << "Dump format does not handle variable resolution."; | 237 << "Dump format does not handle variable resolution."; |
236 ASSERT_EQ(format_.frame_size.height(), frame_format.frame_size.height()) | 238 ASSERT_EQ(format_.frame_size.height(), frame_format.frame_size.height()) |
237 << "Dump format does not handle variable resolution."; | 239 << "Dump format does not handle variable resolution."; |
238 dumper_.NewVideoFrame(dib->memory()); | 240 dumper_.NewVideoFrame(dib->memory()); |
239 } | 241 } |
240 | 242 |
241 OnBufferFilled(device_id, buffer_id, frame_format, timestamp); | 243 OnBufferFilled(device_id, buffer_id, frame_format, visible_rect, timestamp); |
242 if (return_buffers_) { | 244 if (return_buffers_) { |
243 VideoCaptureHost::OnReceiveEmptyBuffer(device_id, buffer_id, 0); | 245 VideoCaptureHost::OnReceiveEmptyBuffer(device_id, buffer_id, 0); |
244 } | 246 } |
245 } | 247 } |
246 | 248 |
247 void OnMailboxBufferFilledDispatch(int device_id, | 249 void OnMailboxBufferFilledDispatch(int device_id, |
248 int buffer_id, | 250 int buffer_id, |
249 const gpu::MailboxHolder& mailbox_holder, | 251 const gpu::MailboxHolder& mailbox_holder, |
250 const media::VideoCaptureFormat& format, | 252 const media::VideoCaptureFormat& format, |
251 base::TimeTicks timestamp) { | 253 base::TimeTicks timestamp) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 opened_session_id_ = kInvalidMediaCaptureSessionId; | 388 opened_session_id_ = kInvalidMediaCaptureSessionId; |
387 } | 389 } |
388 | 390 |
389 protected: | 391 protected: |
390 void StartCapture() { | 392 void StartCapture() { |
391 EXPECT_CALL(*host_.get(), OnNewBufferCreated(kDeviceId, _, _, _)) | 393 EXPECT_CALL(*host_.get(), OnNewBufferCreated(kDeviceId, _, _, _)) |
392 .Times(AnyNumber()) | 394 .Times(AnyNumber()) |
393 .WillRepeatedly(Return()); | 395 .WillRepeatedly(Return()); |
394 | 396 |
395 base::RunLoop run_loop; | 397 base::RunLoop run_loop; |
396 EXPECT_CALL(*host_.get(), OnBufferFilled(kDeviceId, _, _, _)) | 398 EXPECT_CALL(*host_.get(), OnBufferFilled(kDeviceId, _, _, _, _)) |
397 .Times(AnyNumber()) | 399 .Times(AnyNumber()) |
398 .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure())); | 400 .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure())); |
399 | 401 |
400 media::VideoCaptureParams params; | 402 media::VideoCaptureParams params; |
401 params.requested_format = media::VideoCaptureFormat( | 403 params.requested_format = media::VideoCaptureFormat( |
402 gfx::Size(352, 288), 30, media::PIXEL_FORMAT_I420); | 404 gfx::Size(352, 288), 30, media::PIXEL_FORMAT_I420); |
403 host_->OnStartCapture(kDeviceId, opened_session_id_, params); | 405 host_->OnStartCapture(kDeviceId, opened_session_id_, params); |
404 run_loop.Run(); | 406 run_loop.Run(); |
405 } | 407 } |
406 | 408 |
(...skipping 12 matching lines...) Expand all Loading... |
419 run_loop.RunUntilIdle(); | 421 run_loop.RunUntilIdle(); |
420 } | 422 } |
421 | 423 |
422 #ifdef DUMP_VIDEO | 424 #ifdef DUMP_VIDEO |
423 void CaptureAndDumpVideo(int width, int height, int frame_rate) { | 425 void CaptureAndDumpVideo(int width, int height, int frame_rate) { |
424 InSequence s; | 426 InSequence s; |
425 EXPECT_CALL(*host_.get(), OnNewBufferCreated(kDeviceId, _, _, _)) | 427 EXPECT_CALL(*host_.get(), OnNewBufferCreated(kDeviceId, _, _, _)) |
426 .Times(AnyNumber()).WillRepeatedly(Return()); | 428 .Times(AnyNumber()).WillRepeatedly(Return()); |
427 | 429 |
428 base::RunLoop run_loop; | 430 base::RunLoop run_loop; |
429 EXPECT_CALL(*host_, OnBufferFilled(kDeviceId, _, _, _)) | 431 EXPECT_CALL(*host_, OnBufferFilled(kDeviceId, _, _, _, _)) |
430 .Times(AnyNumber()) | 432 .Times(AnyNumber()) |
431 .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure())); | 433 .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure())); |
432 | 434 |
433 media::VideoCaptureParams params; | 435 media::VideoCaptureParams params; |
434 params.requested_format = | 436 params.requested_format = |
435 media::VideoCaptureFormat(gfx::Size(width, height), frame_rate); | 437 media::VideoCaptureFormat(gfx::Size(width, height), frame_rate); |
436 host_->SetDumpVideo(true); | 438 host_->SetDumpVideo(true); |
437 host_->OnStartCapture(kDeviceId, opened_session_id_, params); | 439 host_->OnStartCapture(kDeviceId, opened_session_id_, params); |
438 run_loop.Run(); | 440 run_loop.Run(); |
439 } | 441 } |
(...skipping 11 matching lines...) Expand all Loading... |
451 | 453 |
452 run_loop.Run(); | 454 run_loop.Run(); |
453 | 455 |
454 host_->SetReturnReceivedDibs(false); | 456 host_->SetReturnReceivedDibs(false); |
455 // Expect the VideoCaptureDevice has been stopped | 457 // Expect the VideoCaptureDevice has been stopped |
456 EXPECT_EQ(0u, host_->entries_.size()); | 458 EXPECT_EQ(0u, host_->entries_.size()); |
457 } | 459 } |
458 | 460 |
459 void NotifyPacketReady() { | 461 void NotifyPacketReady() { |
460 base::RunLoop run_loop; | 462 base::RunLoop run_loop; |
461 EXPECT_CALL(*host_.get(), OnBufferFilled(kDeviceId, _, _, _)) | 463 EXPECT_CALL(*host_.get(), OnBufferFilled(kDeviceId, _, _, _, _)) |
462 .Times(AnyNumber()) | 464 .Times(AnyNumber()) |
463 .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure())) | 465 .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure())) |
464 .RetiresOnSaturation(); | 466 .RetiresOnSaturation(); |
465 run_loop.Run(); | 467 run_loop.Run(); |
466 } | 468 } |
467 | 469 |
468 void ReturnReceivedPackets() { | 470 void ReturnReceivedPackets() { |
469 host_->ReturnReceivedDibs(kDeviceId); | 471 host_->ReturnReceivedDibs(kDeviceId); |
470 } | 472 } |
471 | 473 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 #ifdef DUMP_VIDEO | 538 #ifdef DUMP_VIDEO |
537 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { | 539 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { |
538 CaptureAndDumpVideo(640, 480, 30); | 540 CaptureAndDumpVideo(640, 480, 30); |
539 } | 541 } |
540 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { | 542 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { |
541 CaptureAndDumpVideo(1280, 720, 30); | 543 CaptureAndDumpVideo(1280, 720, 30); |
542 } | 544 } |
543 #endif | 545 #endif |
544 | 546 |
545 } // namespace content | 547 } // namespace content |
OLD | NEW |