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/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
192 } | 192 } |
193 | 193 |
194 void OnBufferFilledDispatch(int device_id, | 194 void OnBufferFilledDispatch(int device_id, |
195 int buffer_id, | 195 int buffer_id, |
196 base::Time timestamp, | 196 base::Time timestamp, |
197 const media::VideoCaptureFormat& frame_format) { | 197 const media::VideoCaptureFormat& frame_format) { |
198 base::SharedMemory* dib = filled_dib_[buffer_id]; | 198 base::SharedMemory* dib = filled_dib_[buffer_id]; |
199 ASSERT_TRUE(dib != NULL); | 199 ASSERT_TRUE(dib != NULL); |
200 if (dump_video_) { | 200 if (dump_video_) { |
201 if (!format_.IsValid()) { | 201 if (!format_.IsValid()) { |
202 dumper_.StartDump(frame_format.frame_size.width(), | 202 dumper_.StartDump(frame_format.width, frame_format.height); |
203 frame_format.frame_size.height()); | |
204 format_ = frame_format; | 203 format_ = frame_format; |
205 } | 204 } |
206 ASSERT_EQ(format_.frame_size.width(), frame_format.frame_size.width()) | 205 ASSERT_EQ(format_.width, frame_format.width) |
207 << "Dump format does not handle variable resolution."; | 206 << "Dump format does not handle variable resolution."; |
208 ASSERT_EQ(format_.frame_size.height(), frame_format.frame_size.height()) | 207 ASSERT_EQ(format_.height, frame_format.height) |
209 << "Dump format does not handle variable resolution."; | 208 << "Dump format does not handle variable resolution.";; |
210 dumper_.NewVideoFrame(dib->memory()); | 209 dumper_.NewVideoFrame(dib->memory()); |
211 } | 210 } |
212 | 211 |
213 OnBufferFilled(device_id, buffer_id, timestamp, frame_format); | 212 OnBufferFilled(device_id, buffer_id, timestamp, frame_format); |
214 if (return_buffers_) { | 213 if (return_buffers_) { |
215 VideoCaptureHost::OnReceiveEmptyBuffer(device_id, buffer_id); | 214 VideoCaptureHost::OnReceiveEmptyBuffer(device_id, buffer_id); |
216 } | 215 } |
217 } | 216 } |
218 | 217 |
219 void OnStateChangedDispatch(int device_id, VideoCaptureState state) { | 218 void OnStateChangedDispatch(int device_id, VideoCaptureState state) { |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 EXPECT_CALL(*host_, OnNewBufferCreated(kDeviceId, _, _, _)) | 340 EXPECT_CALL(*host_, OnNewBufferCreated(kDeviceId, _, _, _)) |
342 .Times(AnyNumber()).WillRepeatedly(Return()); | 341 .Times(AnyNumber()).WillRepeatedly(Return()); |
343 | 342 |
344 base::RunLoop run_loop; | 343 base::RunLoop run_loop; |
345 EXPECT_CALL(*host_, OnBufferFilled(kDeviceId, _, _, _)) | 344 EXPECT_CALL(*host_, OnBufferFilled(kDeviceId, _, _, _)) |
346 .Times(AnyNumber()).WillOnce(ExitMessageLoop( | 345 .Times(AnyNumber()).WillOnce(ExitMessageLoop( |
347 message_loop_, run_loop.QuitClosure())); | 346 message_loop_, run_loop.QuitClosure())); |
348 | 347 |
349 media::VideoCaptureParams params; | 348 media::VideoCaptureParams params; |
350 params.requested_format = media::VideoCaptureFormat( | 349 params.requested_format = media::VideoCaptureFormat( |
351 gfx::Size(352, 288), 30, media::PIXEL_FORMAT_I420); | 350 352, 288, 30, media::ConstantResolutionVideoCaptureDevice); |
352 host_->OnStartCapture(kDeviceId, opened_session_id_, params); | 351 params.session_id = opened_session_id_; |
| 352 host_->OnStartCapture(kDeviceId, params); |
353 run_loop.Run(); | 353 run_loop.Run(); |
354 } | 354 } |
355 | 355 |
356 void StartStopCapture() { | 356 void StartStopCapture() { |
357 // Quickly start and then stop capture, without giving much chance for | 357 // Quickly start and then stop capture, without giving much chance for |
358 // asynchronous start operations to complete. | 358 // asynchronous start operations to complete. |
359 InSequence s; | 359 InSequence s; |
360 base::RunLoop run_loop; | 360 base::RunLoop run_loop; |
361 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_STOPPED)); | 361 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_STOPPED)); |
362 media::VideoCaptureParams params; | 362 media::VideoCaptureParams params; |
363 params.requested_format = media::VideoCaptureFormat( | 363 params.requested_format = media::VideoCaptureFormat( |
364 gfx::Size(352, 288), 30, media::PIXEL_FORMAT_I420); | 364 352, 288, 30, media::ConstantResolutionVideoCaptureDevice); |
365 host_->OnStartCapture(kDeviceId, opened_session_id_, params); | 365 params.session_id = opened_session_id_; |
| 366 host_->OnStartCapture(kDeviceId, params); |
366 host_->OnStopCapture(kDeviceId); | 367 host_->OnStopCapture(kDeviceId); |
367 run_loop.RunUntilIdle(); | 368 run_loop.RunUntilIdle(); |
368 } | 369 } |
369 | 370 |
370 #ifdef DUMP_VIDEO | 371 #ifdef DUMP_VIDEO |
371 void CaptureAndDumpVideo(int width, int height, int frame_rate) { | 372 void CaptureAndDumpVideo(int width, int height, int frame_rate) { |
372 InSequence s; | 373 InSequence s; |
373 EXPECT_CALL(*host_.get(), OnNewBufferCreated(kDeviceId, _, _, _)) | 374 EXPECT_CALL(*host_.get(), OnNewBufferCreated(kDeviceId, _, _, _)) |
374 .Times(AnyNumber()).WillRepeatedly(Return()); | 375 .Times(AnyNumber()).WillRepeatedly(Return()); |
375 | 376 |
376 base::RunLoop run_loop; | 377 base::RunLoop run_loop; |
377 EXPECT_CALL(*host_, OnBufferFilled(kDeviceId, _, _, _)) | 378 EXPECT_CALL(*host_, OnBufferFilled(kDeviceId, _, _, _)) |
378 .Times(AnyNumber()) | 379 .Times(AnyNumber()) |
379 .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure())); | 380 .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure())); |
380 | 381 |
381 media::VideoCaptureParams params; | 382 media::VideoCaptureParams params; |
382 params.requested_format = | 383 params.requested_format = media::VideoCaptureFormat( |
383 media::VideoCaptureFormat(gfx::Size(width, height), frame_rate); | 384 width, height, frame_rate, media::ConstantResolutionVideoCaptureDevice); |
| 385 params.session_id = opened_session_id_; |
384 host_->SetDumpVideo(true); | 386 host_->SetDumpVideo(true); |
385 host_->OnStartCapture(kDeviceId, opened_session_id_, params); | 387 host_->OnStartCapture(kDeviceId, params); |
386 run_loop.Run(); | 388 run_loop.Run(); |
387 } | 389 } |
388 #endif | 390 #endif |
389 | 391 |
390 void StopCapture() { | 392 void StopCapture() { |
391 base::RunLoop run_loop; | 393 base::RunLoop run_loop; |
392 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_STOPPED)) | 394 EXPECT_CALL(*host_, OnStateChanged(kDeviceId, VIDEO_CAPTURE_STATE_STOPPED)) |
393 .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure())); | 395 .WillOnce(ExitMessageLoop(message_loop_, run_loop.QuitClosure())); |
394 | 396 |
395 host_->OnStopCapture(kDeviceId); | 397 host_->OnStopCapture(kDeviceId); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
481 #ifdef DUMP_VIDEO | 483 #ifdef DUMP_VIDEO |
482 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { | 484 TEST_F(VideoCaptureHostTest, CaptureAndDumpVideoVga) { |
483 CaptureAndDumpVideo(640, 480, 30); | 485 CaptureAndDumpVideo(640, 480, 30); |
484 } | 486 } |
485 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { | 487 TEST_F(VideoCaptureHostTest, CaptureAndDump720P) { |
486 CaptureAndDumpVideo(1280, 720, 30); | 488 CaptureAndDumpVideo(1280, 720, 30); |
487 } | 489 } |
488 #endif | 490 #endif |
489 | 491 |
490 } // namespace content | 492 } // namespace content |
OLD | NEW |