| 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 "content/browser/renderer_host/media/web_contents_video_capture_device.
h" | 5 #include "content/browser/renderer_host/media/web_contents_video_capture_device.
h" |
| 6 | 6 |
| 7 #include "base/bind_helpers.h" | 7 #include "base/bind_helpers.h" |
| 8 #include "base/debug/debugger.h" | 8 #include "base/debug/debugger.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| 11 #include "base/time.h" | 11 #include "base/time.h" |
| 12 #include "base/timer.h" | 12 #include "base/timer.h" |
| 13 #include "content/browser/browser_thread_impl.h" | 13 #include "content/browser/browser_thread_impl.h" |
| 14 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" | 14 #include "content/browser/renderer_host/media/video_capture_buffer_pool.h" |
| 15 #include "content/browser/renderer_host/media/video_capture_controller.h" | 15 #include "content/browser/renderer_host/media/video_capture_controller.h" |
| 16 #include "content/browser/renderer_host/media/video_capture_oracle.h" | 16 #include "content/browser/renderer_host/media/video_capture_oracle.h" |
| 17 #include "content/browser/renderer_host/media/web_contents_capture_util.h" | 17 #include "content/browser/renderer_host/media/web_contents_capture_util.h" |
| 18 #include "content/browser/renderer_host/render_view_host_factory.h" | 18 #include "content/browser/renderer_host/render_view_host_factory.h" |
| 19 #include "content/browser/renderer_host/render_widget_host_impl.h" | 19 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 20 #include "content/browser/renderer_host/test_render_view_host.h" | 20 #include "content/browser/renderer_host/test_render_view_host.h" |
| 21 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" | 21 #include "content/port/browser/render_widget_host_view_frame_subscriber.h" |
| 22 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 23 #include "content/public/browser/notification_types.h" | 23 #include "content/public/browser/notification_types.h" |
| 24 #include "content/public/test/mock_render_process_host.h" | 24 #include "content/public/test/mock_render_process_host.h" |
| 25 #include "content/public/test/test_browser_context.h" | 25 #include "content/public/test/test_browser_context.h" |
| 26 #include "content/public/test/test_browser_thread_bundle.h" | 26 #include "content/public/test/test_browser_thread_bundle.h" |
| 27 #include "content/public/test/test_utils.h" | 27 #include "content/public/test/test_utils.h" |
| 28 #include "content/test/test_web_contents.h" | 28 #include "content/test/test_web_contents.h" |
| 29 #include "media/base/encoded_bitstream_buffer.h" |
| 29 #include "media/base/video_util.h" | 30 #include "media/base/video_util.h" |
| 30 #include "media/base/yuv_convert.h" | 31 #include "media/base/yuv_convert.h" |
| 31 #include "media/video/capture/video_capture_types.h" | 32 #include "media/video/capture/video_capture_types.h" |
| 32 #include "skia/ext/platform_canvas.h" | 33 #include "skia/ext/platform_canvas.h" |
| 33 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 34 #include "third_party/skia/include/core/SkColor.h" | 35 #include "third_party/skia/include/core/SkColor.h" |
| 35 | 36 |
| 36 namespace content { | 37 namespace content { |
| 37 namespace { | 38 namespace { |
| 38 | 39 |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 349 base::AutoLock guard(lock_); | 350 base::AutoLock guard(lock_); |
| 350 ASSERT_TRUE(error_encountered_); | 351 ASSERT_TRUE(error_encountered_); |
| 351 } | 352 } |
| 352 } | 353 } |
| 353 | 354 |
| 354 bool HasError() { | 355 bool HasError() { |
| 355 base::AutoLock guard(lock_); | 356 base::AutoLock guard(lock_); |
| 356 return error_encountered_; | 357 return error_encountered_; |
| 357 } | 358 } |
| 358 | 359 |
| 359 virtual scoped_refptr<media::VideoFrame> ReserveOutputBuffer() OVERRIDE { | 360 virtual scoped_refptr<media::VideoFrame> ReserveOutputVideoFrame() OVERRIDE { |
| 360 return VideoCaptureController::ReserveI420VideoFrame( | 361 return VideoCaptureController::ReserveI420VideoFrame( |
| 361 buffer_pool_, | 362 buffer_pool_, |
| 362 gfx::Size(kTestWidth, kTestHeight)); | 363 gfx::Size(kTestWidth, kTestHeight)); |
| 363 } | 364 } |
| 364 | 365 |
| 366 virtual scoped_refptr<media::EncodedBitstreamBuffer> |
| 367 ReserveOutputEncodedBitstreamBuffer() OVERRIDE { |
| 368 return NULL; |
| 369 } |
| 370 |
| 365 virtual void OnIncomingCapturedFrame( | 371 virtual void OnIncomingCapturedFrame( |
| 366 const uint8* data, | 372 const uint8* data, |
| 367 int length, | 373 int length, |
| 368 base::Time timestamp, | 374 base::Time timestamp, |
| 369 int rotation, | 375 int rotation, |
| 370 bool flip_vert, | 376 bool flip_vert, |
| 371 bool flip_horiz) OVERRIDE { | 377 bool flip_horiz) OVERRIDE { |
| 372 FAIL(); | 378 FAIL(); |
| 373 } | 379 } |
| 374 | 380 |
| 375 virtual void OnIncomingCapturedVideoFrame( | 381 virtual void OnIncomingCapturedVideoFrame( |
| 376 const scoped_refptr<media::VideoFrame>& frame, | 382 const scoped_refptr<media::VideoFrame>& frame, |
| 377 base::Time timestamp) OVERRIDE { | 383 base::Time timestamp) OVERRIDE { |
| 378 EXPECT_EQ(gfx::Size(kTestWidth, kTestHeight), frame->coded_size()); | 384 EXPECT_EQ(gfx::Size(kTestWidth, kTestHeight), frame->coded_size()); |
| 379 EXPECT_EQ(media::VideoFrame::YV12, frame->format()); | 385 EXPECT_EQ(media::VideoFrame::YV12, frame->format()); |
| 380 EXPECT_LE( | 386 EXPECT_LE( |
| 381 0, | 387 0, |
| 382 buffer_pool_->RecognizeReservedBuffer(frame->shared_memory_handle())); | 388 buffer_pool_->RecognizeReservedBuffer(frame->shared_memory_handle())); |
| 383 uint8 yuv[3]; | 389 uint8 yuv[3]; |
| 384 for (int plane = 0; plane < 3; ++plane) { | 390 for (int plane = 0; plane < 3; ++plane) { |
| 385 yuv[plane] = frame->data(plane)[0]; | 391 yuv[plane] = frame->data(plane)[0]; |
| 386 } | 392 } |
| 387 // TODO(nick): We just look at the first pixel presently, because if | 393 // TODO(nick): We just look at the first pixel presently, because if |
| 388 // the analysis is too slow, the backlog of frames will grow without bound | 394 // the analysis is too slow, the backlog of frames will grow without bound |
| 389 // and trouble erupts. http://crbug.com/174519 | 395 // and trouble erupts. http://crbug.com/174519 |
| 390 PostColorOrError(SkColorSetRGB(yuv[0], yuv[1], yuv[2])); | 396 PostColorOrError(SkColorSetRGB(yuv[0], yuv[1], yuv[2])); |
| 391 } | 397 } |
| 392 | 398 |
| 399 virtual void OnIncomingCapturedEncodedBitstreamBuffer( |
| 400 const scoped_refptr<media::EncodedBitstreamBuffer>& buffer, |
| 401 size_t data_size, |
| 402 base::Time timestamp) OVERRIDE { |
| 403 } |
| 404 |
| 393 void PostColorOrError(SkColor new_color) { | 405 void PostColorOrError(SkColor new_color) { |
| 394 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( | 406 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, base::Bind( |
| 395 &StubConsumer::QuitIfConditionMet, base::Unretained(this), new_color)); | 407 &StubConsumer::QuitIfConditionMet, base::Unretained(this), new_color)); |
| 396 } | 408 } |
| 397 | 409 |
| 398 virtual void OnError() OVERRIDE { | 410 virtual void OnError() OVERRIDE { |
| 399 { | 411 { |
| 400 base::AutoLock guard(lock_); | 412 base::AutoLock guard(lock_); |
| 401 error_encountered_ = true; | 413 error_encountered_ = true; |
| 402 } | 414 } |
| 403 PostColorOrError(kNothingYet); | 415 PostColorOrError(kNothingYet); |
| 404 } | 416 } |
| 405 | 417 |
| 406 virtual void OnFrameInfo(const media::VideoCaptureCapability& info) OVERRIDE { | 418 virtual void OnFrameInfo(const media::VideoCaptureCapability& info) OVERRIDE { |
| 407 EXPECT_EQ(kTestWidth, info.width); | 419 EXPECT_EQ(kTestWidth, info.width); |
| 408 EXPECT_EQ(kTestHeight, info.height); | 420 EXPECT_EQ(kTestHeight, info.height); |
| 409 EXPECT_EQ(kTestFramesPerSecond, info.frame_rate); | 421 EXPECT_EQ(kTestFramesPerSecond, info.frame_rate); |
| 410 EXPECT_EQ(media::VideoCaptureCapability::kI420, info.color); | 422 EXPECT_EQ(media::VideoCaptureCapability::kI420, info.color); |
| 411 } | 423 } |
| 412 | 424 |
| 425 virtual void OnEncodedFrameInfo( |
| 426 const media::VideoEncodingParameters& params) OVERRIDE { |
| 427 } |
| 428 |
| 429 virtual void OnBitstreamConfigChanged( |
| 430 const media::RuntimeVideoEncodingParameters& params) OVERRIDE { |
| 431 } |
| 432 |
| 413 private: | 433 private: |
| 414 base::Lock lock_; | 434 base::Lock lock_; |
| 415 bool error_encountered_; | 435 bool error_encountered_; |
| 416 SkColor wait_color_yuv_; | 436 SkColor wait_color_yuv_; |
| 417 scoped_refptr<VideoCaptureBufferPool> buffer_pool_; | 437 scoped_refptr<VideoCaptureBufferPool> buffer_pool_; |
| 418 | 438 |
| 419 DISALLOW_COPY_AND_ASSIGN(StubConsumer); | 439 DISALLOW_COPY_AND_ASSIGN(StubConsumer); |
| 420 }; | 440 }; |
| 421 | 441 |
| 422 // Test harness that sets up a minimal environment with necessary stubs. | 442 // Test harness that sets up a minimal environment with necessary stubs. |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorGREEN)); | 743 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorGREEN)); |
| 724 source()->SetSolidColor(SK_ColorRED); | 744 source()->SetSolidColor(SK_ColorRED); |
| 725 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorRED)); | 745 ASSERT_NO_FATAL_FAILURE(consumer()->WaitForNextColor(SK_ColorRED)); |
| 726 | 746 |
| 727 device()->Stop(); | 747 device()->Stop(); |
| 728 device()->DeAllocate(); | 748 device()->DeAllocate(); |
| 729 } | 749 } |
| 730 | 750 |
| 731 } // namespace | 751 } // namespace |
| 732 } // namespace content | 752 } // namespace content |
| OLD | NEW |