| 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/media/capture/web_contents_video_capture_device.h" | 5 #include "content/browser/media/capture/web_contents_video_capture_device.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 92 |
| 93 media::VideoCaptureParams DefaultCaptureParams() { | 93 media::VideoCaptureParams DefaultCaptureParams() { |
| 94 media::VideoCaptureParams capture_params; | 94 media::VideoCaptureParams capture_params; |
| 95 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); | 95 capture_params.requested_format.frame_size.SetSize(kTestWidth, kTestHeight); |
| 96 capture_params.requested_format.frame_rate = kTestFramesPerSecond; | 96 capture_params.requested_format.frame_rate = kTestFramesPerSecond; |
| 97 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | 97 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; |
| 98 return capture_params; | 98 return capture_params; |
| 99 } | 99 } |
| 100 | 100 |
| 101 // A stub implementation which fills solid-colors into VideoFrames in calls to | 101 // A stub implementation which fills solid-colors into VideoFrames in calls to |
| 102 // CopyFromCompositingSurfaceToVideoFrame(). The colors are changed by tests | 102 // CopyFromSurfaceToVideoFrame(). The colors are changed by tests in-between |
| 103 // in-between draw events to confirm that the right frames have the right | 103 // draw events to confirm that the right frames have the right content and in |
| 104 // content and in the right sequence. | 104 // the right sequence. |
| 105 class CaptureTestView : public TestRenderWidgetHostView { | 105 class CaptureTestView : public TestRenderWidgetHostView { |
| 106 public: | 106 public: |
| 107 explicit CaptureTestView(RenderWidgetHostImpl* rwh) | 107 explicit CaptureTestView(RenderWidgetHostImpl* rwh) |
| 108 : TestRenderWidgetHostView(rwh), | 108 : TestRenderWidgetHostView(rwh), |
| 109 fake_bounds_(100, 100, 100 + kTestWidth, 100 + kTestHeight), | 109 fake_bounds_(100, 100, 100 + kTestWidth, 100 + kTestHeight), |
| 110 yuv_color_(kDrawColorNotSet) {} | 110 yuv_color_(kDrawColorNotSet) {} |
| 111 | 111 |
| 112 ~CaptureTestView() override {} | 112 ~CaptureTestView() override {} |
| 113 | 113 |
| 114 // TestRenderWidgetHostView overrides. | 114 // TestRenderWidgetHostView overrides. |
| 115 gfx::Rect GetViewBounds() const override { | 115 gfx::Rect GetViewBounds() const override { |
| 116 return fake_bounds_; | 116 return fake_bounds_; |
| 117 } | 117 } |
| 118 | 118 |
| 119 void SetSize(const gfx::Size& size) override { | 119 void SetSize(const gfx::Size& size) override { |
| 120 SetBounds(gfx::Rect(fake_bounds_.origin(), size)); | 120 SetBounds(gfx::Rect(fake_bounds_.origin(), size)); |
| 121 } | 121 } |
| 122 | 122 |
| 123 void SetBounds(const gfx::Rect& rect) override { | 123 void SetBounds(const gfx::Rect& rect) override { |
| 124 fake_bounds_ = rect; | 124 fake_bounds_ = rect; |
| 125 } | 125 } |
| 126 | 126 |
| 127 bool CanCopyToVideoFrame() const override { return true; } | 127 bool IsSurfaceAvailableForCopy() const override { return true; } |
| 128 | 128 |
| 129 void CopyFromCompositingSurfaceToVideoFrame( | 129 void CopyFromSurface(const gfx::Rect& src_rect, |
| 130 const gfx::Size& output_size, |
| 131 const ReadbackRequestCallback& callback, |
| 132 const SkColorType color_type) override { |
| 133 // WebContentsVideoCaptureDevice implementation does not use this. |
| 134 NOTREACHED(); |
| 135 } |
| 136 |
| 137 void CopyFromSurfaceToVideoFrame( |
| 130 const gfx::Rect& src_subrect, | 138 const gfx::Rect& src_subrect, |
| 131 const scoped_refptr<media::VideoFrame>& target, | 139 scoped_refptr<media::VideoFrame> target, |
| 132 const base::Callback<void(const gfx::Rect&, bool)>& callback) override { | 140 const base::Callback<void(const gfx::Rect&, bool)>& callback) override { |
| 141 ASSERT_TRUE(src_subrect.IsEmpty()); |
| 133 media::FillYUV(target.get(), SkColorGetR(yuv_color_), | 142 media::FillYUV(target.get(), SkColorGetR(yuv_color_), |
| 134 SkColorGetG(yuv_color_), SkColorGetB(yuv_color_)); | 143 SkColorGetG(yuv_color_), SkColorGetB(yuv_color_)); |
| 135 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 144 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 136 base::Bind(callback, gfx::Rect(), true)); | 145 base::Bind(callback, gfx::Rect(), true)); |
| 137 } | 146 } |
| 138 | 147 |
| 139 void BeginFrameSubscription( | 148 void BeginFrameSubscription( |
| 140 std::unique_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) | 149 std::unique_ptr<RenderWidgetHostViewFrameSubscriber> subscriber) |
| 141 override { | 150 override { |
| 142 subscriber_ = std::move(subscriber); | 151 subscriber_ = std::move(subscriber); |
| 143 } | 152 } |
| 144 | 153 |
| 145 void EndFrameSubscription() override { subscriber_.reset(); } | 154 void EndFrameSubscription() override { subscriber_.reset(); } |
| 146 | 155 |
| 147 void SetSolidColor(SkColor rgb_color) { | 156 void SetSolidColor(SkColor rgb_color) { |
| 148 yuv_color_ = ConvertRgbToYuv(rgb_color); | 157 yuv_color_ = ConvertRgbToYuv(rgb_color); |
| 149 } | 158 } |
| 150 | 159 |
| 151 // Simulate a compositor paint event for our subscriber. | 160 // Simulate a compositor paint event for our subscriber. |
| 152 void SimulateUpdate() { | 161 void SimulateUpdate() { |
| 153 const base::TimeTicks present_time = base::TimeTicks::Now(); | 162 const base::TimeTicks present_time = base::TimeTicks::Now(); |
| 154 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; | 163 RenderWidgetHostViewFrameSubscriber::DeliverFrameCallback callback; |
| 155 scoped_refptr<media::VideoFrame> target; | 164 scoped_refptr<media::VideoFrame> target; |
| 156 if (subscriber_ && subscriber_->ShouldCaptureFrame( | 165 if (subscriber_ && subscriber_->ShouldCaptureFrame( |
| 157 gfx::Rect(), present_time, &target, &callback)) { | 166 gfx::Rect(), present_time, &target, &callback)) { |
| 158 CopyFromCompositingSurfaceToVideoFrame( | 167 CopyFromSurfaceToVideoFrame(gfx::Rect(), target, |
| 159 gfx::Rect(), target, base::Bind(callback, present_time)); | 168 base::Bind(callback, present_time)); |
| 160 } | 169 } |
| 161 } | 170 } |
| 162 | 171 |
| 163 private: | 172 private: |
| 164 std::unique_ptr<RenderWidgetHostViewFrameSubscriber> subscriber_; | 173 std::unique_ptr<RenderWidgetHostViewFrameSubscriber> subscriber_; |
| 165 gfx::Rect fake_bounds_; | 174 gfx::Rect fake_bounds_; |
| 166 SkColor yuv_color_; | 175 SkColor yuv_color_; |
| 167 | 176 |
| 168 DISALLOW_IMPLICIT_CONSTRUCTORS(CaptureTestView); | 177 DISALLOW_IMPLICIT_CONSTRUCTORS(CaptureTestView); |
| 169 }; | 178 }; |
| (...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 display.set_device_scale_factor(kTestDeviceScaleFactor); | 453 display.set_device_scale_factor(kTestDeviceScaleFactor); |
| 445 test_screen_.display_list().RemoveDisplay(test_display.id()); | 454 test_screen_.display_list().RemoveDisplay(test_display.id()); |
| 446 test_screen_.display_list().AddDisplay(display, | 455 test_screen_.display_list().AddDisplay(display, |
| 447 display::DisplayList::Type::PRIMARY); | 456 display::DisplayList::Type::PRIMARY); |
| 448 display::Screen::SetScreenInstance(&test_screen_); | 457 display::Screen::SetScreenInstance(&test_screen_); |
| 449 ASSERT_EQ(&test_screen_, display::Screen::GetScreen()); | 458 ASSERT_EQ(&test_screen_, display::Screen::GetScreen()); |
| 450 | 459 |
| 451 // TODO(nick): Sadness and woe! Much "mock-the-world" boilerplate could be | 460 // TODO(nick): Sadness and woe! Much "mock-the-world" boilerplate could be |
| 452 // eliminated here, if only we could use RenderViewHostTestHarness. The | 461 // eliminated here, if only we could use RenderViewHostTestHarness. The |
| 453 // catch is that we need to inject our CaptureTestView:: | 462 // catch is that we need to inject our CaptureTestView:: |
| 454 // CopyFromCompositingSurfaceToVideoFrame() mock. To accomplish that, | 463 // CopyFromSurfaceToVideoFrame() mock. To accomplish that, either |
| 455 // either RenderViewHostTestHarness would have to support installing a | 464 // RenderViewHostTestHarness would have to support installing a custom |
| 456 // custom RenderViewHostFactory, or else we implant some kind of delegated | 465 // RenderViewHostFactory, or else we implant some kind of delegated |
| 457 // CopyFromCompositingSurfaceToVideoFrame functionality into | 466 // CopyFromSurfaceToVideoFrame functionality into TestRenderWidgetHostView |
| 458 // TestRenderViewHostView itself. | 467 // itself. |
| 459 | 468 |
| 460 render_process_host_factory_.reset(new MockRenderProcessHostFactory()); | 469 render_process_host_factory_.reset(new MockRenderProcessHostFactory()); |
| 461 // Create our (self-registering) RVH factory, so that when we create a | 470 // Create our (self-registering) RVH factory, so that when we create a |
| 462 // WebContents, it in turn creates CaptureTestRenderViewHosts. | 471 // WebContents, it in turn creates CaptureTestRenderViewHosts. |
| 463 render_view_host_factory_.reset(new CaptureTestRenderViewHostFactory()); | 472 render_view_host_factory_.reset(new CaptureTestRenderViewHostFactory()); |
| 464 render_frame_host_factory_.reset(new TestRenderFrameHostFactory()); | 473 render_frame_host_factory_.reset(new TestRenderFrameHostFactory()); |
| 465 | 474 |
| 466 browser_context_.reset(new TestBrowserContext()); | 475 browser_context_.reset(new TestBrowserContext()); |
| 467 | 476 |
| 468 scoped_refptr<SiteInstance> site_instance = | 477 scoped_refptr<SiteInstance> site_instance = |
| (...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 for (int i = 0; i < 3; ++i) { | 1030 for (int i = 0; i < 3; ++i) { |
| 1022 SimulateRefreshFrameRequest(); | 1031 SimulateRefreshFrameRequest(); |
| 1023 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); | 1032 ASSERT_NO_FATAL_FAILURE(client_observer()->WaitForNextColor(SK_ColorGREEN)); |
| 1024 } | 1033 } |
| 1025 | 1034 |
| 1026 device()->StopAndDeAllocate(); | 1035 device()->StopAndDeAllocate(); |
| 1027 } | 1036 } |
| 1028 | 1037 |
| 1029 } // namespace | 1038 } // namespace |
| 1030 } // namespace content | 1039 } // namespace content |
| OLD | NEW |