| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/desktop_capture_device.h" | 5 #include "content/browser/renderer_host/media/desktop_capture_device.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/sequenced_task_runner.h" | 8 #include "base/sequenced_task_runner.h" |
| 9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
| 10 #include "base/test/test_timeouts.h" | 10 #include "base/test/test_timeouts.h" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 const int kTestFrameWidth1 = 100; | 34 const int kTestFrameWidth1 = 100; |
| 35 const int kTestFrameHeight1 = 100; | 35 const int kTestFrameHeight1 = 100; |
| 36 const int kTestFrameWidth2 = 200; | 36 const int kTestFrameWidth2 = 200; |
| 37 const int kTestFrameHeight2 = 150; | 37 const int kTestFrameHeight2 = 150; |
| 38 | 38 |
| 39 const int kFrameRate = 30; | 39 const int kFrameRate = 30; |
| 40 | 40 |
| 41 class MockDeviceClient : public media::VideoCaptureDevice::Client { | 41 class MockDeviceClient : public media::VideoCaptureDevice::Client { |
| 42 public: | 42 public: |
| 43 MOCK_METHOD1(ReserveOutputBuffer, | 43 MOCK_METHOD2(ReserveOutputBuffer, |
| 44 scoped_refptr<media::VideoFrame>(const gfx::Size& size)); | 44 scoped_refptr<Buffer>(media::VideoFrame::Format format, |
| 45 const gfx::Size& dimensions)); |
| 45 MOCK_METHOD0(OnError, void()); | 46 MOCK_METHOD0(OnError, void()); |
| 46 MOCK_METHOD7(OnIncomingCapturedFrame, | 47 MOCK_METHOD7(OnIncomingCapturedFrame, |
| 47 void(const uint8* data, | 48 void(const uint8* data, |
| 48 int length, | 49 int length, |
| 49 base::Time timestamp, | 50 base::Time timestamp, |
| 50 int rotation, | 51 int rotation, |
| 51 bool flip_vert, | 52 bool flip_vert, |
| 52 bool flip_horiz, | 53 bool flip_horiz, |
| 53 const media::VideoCaptureCapability& frame_info)); | 54 const media::VideoCaptureCapability& frame_info)); |
| 54 MOCK_METHOD3(OnIncomingCapturedVideoFrame, | 55 MOCK_METHOD5(OnIncomingCapturedBuffer, |
| 55 void(const scoped_refptr<media::VideoFrame>& frame, | 56 void(const scoped_refptr<Buffer>& buffer, |
| 56 base::Time timestamp, | 57 media::VideoFrame::Format format, |
| 57 int frame_rate)); | 58 const gfx::Size& dimensions, |
| 59 base::Time timestamp, |
| 60 int frame_rate)); |
| 58 }; | 61 }; |
| 59 | 62 |
| 60 // TODO(sergeyu): Move this to a separate file where it can be reused. | 63 // TODO(sergeyu): Move this to a separate file where it can be reused. |
| 61 class FakeScreenCapturer : public webrtc::ScreenCapturer { | 64 class FakeScreenCapturer : public webrtc::ScreenCapturer { |
| 62 public: | 65 public: |
| 63 FakeScreenCapturer() | 66 FakeScreenCapturer() |
| 64 : callback_(NULL), | 67 : callback_(NULL), |
| 65 frame_index_(0) { | 68 frame_index_(0) { |
| 66 } | 69 } |
| 67 virtual ~FakeScreenCapturer() {} | 70 virtual ~FakeScreenCapturer() {} |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 DesktopCaptureDevice capture_device( | 205 DesktopCaptureDevice capture_device( |
| 203 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()), | 206 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()), |
| 204 scoped_ptr<webrtc::DesktopCapturer>(mock_capturer)); | 207 scoped_ptr<webrtc::DesktopCapturer>(mock_capturer)); |
| 205 | 208 |
| 206 media::VideoCaptureCapability caps; | 209 media::VideoCaptureCapability caps; |
| 207 base::WaitableEvent done_event(false, false); | 210 base::WaitableEvent done_event(false, false); |
| 208 | 211 |
| 209 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); | 212 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); |
| 210 EXPECT_CALL(*client, OnError()).Times(0); | 213 EXPECT_CALL(*client, OnError()).Times(0); |
| 211 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _, _, _)) | 214 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _, _, _)) |
| 212 .WillRepeatedly(DoAll( | 215 .WillRepeatedly( |
| 213 SaveArg<6>(&caps), | 216 DoAll(SaveArg<6>(&caps), |
| 214 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); | 217 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); |
| 215 | 218 |
| 216 media::VideoCaptureCapability capture_format( | 219 media::VideoCaptureCapability capture_format( |
| 217 kTestFrameWidth2, | 220 kTestFrameWidth2, |
| 218 kTestFrameHeight2, | 221 kTestFrameHeight2, |
| 219 kFrameRate, | 222 kFrameRate, |
| 220 media::PIXEL_FORMAT_I420, | 223 media::PIXEL_FORMAT_I420, |
| 221 media::VariableResolutionVideoCaptureDevice); | 224 media::VariableResolutionVideoCaptureDevice); |
| 222 | 225 |
| 223 capture_device.AllocateAndStart( | 226 capture_device.AllocateAndStart( |
| 224 capture_format, client.PassAs<media::VideoCaptureDevice::Client>()); | 227 capture_format, client.PassAs<media::VideoCaptureDevice::Client>()); |
| 225 | 228 |
| 226 // Capture at least three frames, to ensure that the source frame size has | 229 // Capture at least three frames, to ensure that the source frame size has |
| 227 // changed at least twice while capturing. | 230 // changed at least twice while capturing. |
| 228 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); | 231 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); |
| 229 done_event.Reset(); | 232 done_event.Reset(); |
| 230 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); | 233 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); |
| 231 done_event.Reset(); | 234 done_event.Reset(); |
| 232 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); | 235 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); |
| 233 | 236 |
| 234 capture_device.StopAndDeAllocate(); | 237 capture_device.StopAndDeAllocate(); |
| 235 | 238 |
| 236 EXPECT_EQ(kTestFrameWidth1, caps.width); | 239 EXPECT_EQ(kTestFrameWidth1, caps.width); |
| 237 EXPECT_EQ(kTestFrameHeight1, caps.height); | 240 EXPECT_EQ(kTestFrameHeight1, caps.height); |
| 238 EXPECT_EQ(kFrameRate, caps.frame_rate); | 241 EXPECT_EQ(kFrameRate, caps.frame_rate); |
| 239 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, caps.color); | 242 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, caps.color); |
| 240 worker_pool_->FlushForTesting(); | 243 worker_pool_->FlushForTesting(); |
| 241 } | 244 } |
| 242 | 245 |
| 243 } // namespace content | 246 } // namespace content |
| OLD | NEW |