| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 scoped_refptr<Buffer>(media::VideoFrame::Format format, | 44 scoped_refptr<Buffer>(media::VideoFrame::Format format, |
| 45 const gfx::Size& dimensions)); | 45 const gfx::Size& dimensions)); |
| 46 MOCK_METHOD0(OnError, void()); | 46 MOCK_METHOD0(OnError, void()); |
| 47 MOCK_METHOD7(OnIncomingCapturedFrame, | 47 MOCK_METHOD7(OnIncomingCapturedFrame, |
| 48 void(const uint8* data, | 48 void(const uint8* data, |
| 49 int length, | 49 int length, |
| 50 base::Time timestamp, | 50 base::Time timestamp, |
| 51 int rotation, | 51 int rotation, |
| 52 bool flip_vert, | 52 bool flip_vert, |
| 53 bool flip_horiz, | 53 bool flip_horiz, |
| 54 const media::VideoCaptureFormat& frame_format)); | 54 const media::VideoCaptureCapability& frame_info)); |
| 55 MOCK_METHOD5(OnIncomingCapturedBuffer, | 55 MOCK_METHOD5(OnIncomingCapturedBuffer, |
| 56 void(const scoped_refptr<Buffer>& buffer, | 56 void(const scoped_refptr<Buffer>& buffer, |
| 57 media::VideoFrame::Format format, | 57 media::VideoFrame::Format format, |
| 58 const gfx::Size& dimensions, | 58 const gfx::Size& dimensions, |
| 59 base::Time timestamp, | 59 base::Time timestamp, |
| 60 int frame_rate)); | 60 int frame_rate)); |
| 61 }; | 61 }; |
| 62 | 62 |
| 63 // 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. |
| 64 class FakeScreenCapturer : public webrtc::ScreenCapturer { | 64 class FakeScreenCapturer : public webrtc::ScreenCapturer { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 #define MAYBE_Capture DISABLED_Capture | 113 #define MAYBE_Capture DISABLED_Capture |
| 114 #else | 114 #else |
| 115 #define MAYBE_Capture Capture | 115 #define MAYBE_Capture Capture |
| 116 #endif | 116 #endif |
| 117 TEST_F(DesktopCaptureDeviceTest, MAYBE_Capture) { | 117 TEST_F(DesktopCaptureDeviceTest, MAYBE_Capture) { |
| 118 scoped_ptr<webrtc::DesktopCapturer> capturer( | 118 scoped_ptr<webrtc::DesktopCapturer> capturer( |
| 119 webrtc::ScreenCapturer::Create()); | 119 webrtc::ScreenCapturer::Create()); |
| 120 DesktopCaptureDevice capture_device( | 120 DesktopCaptureDevice capture_device( |
| 121 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()), | 121 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()), |
| 122 capturer.Pass()); | 122 capturer.Pass()); |
| 123 media::VideoCaptureFormat format; | 123 media::VideoCaptureCapability caps; |
| 124 base::WaitableEvent done_event(false, false); | 124 base::WaitableEvent done_event(false, false); |
| 125 int frame_size; | 125 int frame_size; |
| 126 | 126 |
| 127 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); | 127 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); |
| 128 EXPECT_CALL(*client, OnError()).Times(0); | 128 EXPECT_CALL(*client, OnError()).Times(0); |
| 129 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _, _, _)) | 129 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _, _, _)) |
| 130 .WillRepeatedly( | 130 .WillRepeatedly( |
| 131 DoAll(SaveArg<1>(&frame_size), | 131 DoAll(SaveArg<1>(&frame_size), |
| 132 SaveArg<6>(&format), | 132 SaveArg<6>(&caps), |
| 133 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); | 133 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); |
| 134 | 134 |
| 135 media::VideoCaptureParams capture_params; | 135 media::VideoCaptureCapability capture_format( |
| 136 capture_params.requested_format.frame_size.SetSize(640, 480); | 136 640, 480, kFrameRate, media::PIXEL_FORMAT_I420, |
| 137 capture_params.requested_format.frame_rate = kFrameRate; | 137 media::ConstantResolutionVideoCaptureDevice); |
| 138 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | |
| 139 capture_params.allow_resolution_change = false; | |
| 140 capture_device.AllocateAndStart( | 138 capture_device.AllocateAndStart( |
| 141 capture_params, client.PassAs<media::VideoCaptureDevice::Client>()); | 139 capture_format, client.PassAs<media::VideoCaptureDevice::Client>()); |
| 142 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); | 140 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); |
| 143 capture_device.StopAndDeAllocate(); | 141 capture_device.StopAndDeAllocate(); |
| 144 | 142 |
| 145 EXPECT_GT(format.frame_size.width(), 0); | 143 EXPECT_GT(caps.width, 0); |
| 146 EXPECT_GT(format.frame_size.height(), 0); | 144 EXPECT_GT(caps.height, 0); |
| 147 EXPECT_EQ(kFrameRate, format.frame_rate); | 145 EXPECT_EQ(kFrameRate, caps.frame_rate); |
| 148 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format); | 146 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, caps.color); |
| 149 | 147 |
| 150 EXPECT_EQ(format.frame_size.GetArea() * 4, frame_size); | 148 EXPECT_EQ(caps.width * caps.height * 4, frame_size); |
| 151 worker_pool_->FlushForTesting(); | 149 worker_pool_->FlushForTesting(); |
| 152 } | 150 } |
| 153 | 151 |
| 154 // Test that screen capturer behaves correctly if the source frame size changes | 152 // Test that screen capturer behaves correctly if the source frame size changes |
| 155 // but the caller cannot cope with variable resolution output. | 153 // but the caller cannot cope with variable resolution output. |
| 156 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeConstantResolution) { | 154 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeConstantResolution) { |
| 157 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); | 155 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); |
| 158 | 156 |
| 159 DesktopCaptureDevice capture_device( | 157 DesktopCaptureDevice capture_device( |
| 160 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()), | 158 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()), |
| 161 scoped_ptr<webrtc::DesktopCapturer>(mock_capturer)); | 159 scoped_ptr<webrtc::DesktopCapturer>(mock_capturer)); |
| 162 | 160 |
| 163 media::VideoCaptureFormat format; | 161 media::VideoCaptureCapability caps; |
| 164 base::WaitableEvent done_event(false, false); | 162 base::WaitableEvent done_event(false, false); |
| 165 int frame_size; | 163 int frame_size; |
| 166 | 164 |
| 167 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); | 165 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); |
| 168 EXPECT_CALL(*client, OnError()).Times(0); | 166 EXPECT_CALL(*client, OnError()).Times(0); |
| 169 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _, _, _)) | 167 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _, _, _)) |
| 170 .WillRepeatedly( | 168 .WillRepeatedly( |
| 171 DoAll(SaveArg<1>(&frame_size), | 169 DoAll(SaveArg<1>(&frame_size), |
| 172 SaveArg<6>(&format), | 170 SaveArg<6>(&caps), |
| 173 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); | 171 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); |
| 174 | 172 |
| 175 media::VideoCaptureParams capture_params; | 173 media::VideoCaptureCapability capture_format( |
| 176 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1, | 174 kTestFrameWidth1, |
| 177 kTestFrameHeight1); | 175 kTestFrameHeight1, |
| 178 capture_params.requested_format.frame_rate = kFrameRate; | 176 kFrameRate, |
| 179 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | 177 media::PIXEL_FORMAT_I420, |
| 180 capture_params.allow_resolution_change = false; | 178 media::ConstantResolutionVideoCaptureDevice); |
| 181 | 179 |
| 182 capture_device.AllocateAndStart( | 180 capture_device.AllocateAndStart( |
| 183 capture_params, client.PassAs<media::VideoCaptureDevice::Client>()); | 181 capture_format, client.PassAs<media::VideoCaptureDevice::Client>()); |
| 184 | 182 |
| 185 // Capture at least two frames, to ensure that the source frame size has | 183 // Capture at least two frames, to ensure that the source frame size has |
| 186 // changed while capturing. | 184 // changed while capturing. |
| 187 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); | 185 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); |
| 188 done_event.Reset(); | 186 done_event.Reset(); |
| 189 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); | 187 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); |
| 190 | 188 |
| 191 capture_device.StopAndDeAllocate(); | 189 capture_device.StopAndDeAllocate(); |
| 192 | 190 |
| 193 EXPECT_EQ(kTestFrameWidth1, format.frame_size.width()); | 191 EXPECT_EQ(kTestFrameWidth1, caps.width); |
| 194 EXPECT_EQ(kTestFrameHeight1, format.frame_size.height()); | 192 EXPECT_EQ(kTestFrameHeight1, caps.height); |
| 195 EXPECT_EQ(kFrameRate, format.frame_rate); | 193 EXPECT_EQ(kFrameRate, caps.frame_rate); |
| 196 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format); | 194 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, caps.color); |
| 197 | 195 |
| 198 EXPECT_EQ(format.frame_size.GetArea() * 4, frame_size); | 196 EXPECT_EQ(caps.width * caps.height * 4, frame_size); |
| 199 worker_pool_->FlushForTesting(); | 197 worker_pool_->FlushForTesting(); |
| 200 } | 198 } |
| 201 | 199 |
| 202 // Test that screen capturer behaves correctly if the source frame size changes | 200 // Test that screen capturer behaves correctly if the source frame size changes |
| 203 // and the caller can cope with variable resolution output. | 201 // and the caller can cope with variable resolution output. |
| 204 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeVariableResolution) { | 202 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeVariableResolution) { |
| 205 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); | 203 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); |
| 206 | 204 |
| 207 DesktopCaptureDevice capture_device( | 205 DesktopCaptureDevice capture_device( |
| 208 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()), | 206 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()), |
| 209 scoped_ptr<webrtc::DesktopCapturer>(mock_capturer)); | 207 scoped_ptr<webrtc::DesktopCapturer>(mock_capturer)); |
| 210 | 208 |
| 211 media::VideoCaptureFormat format; | 209 media::VideoCaptureCapability caps; |
| 212 base::WaitableEvent done_event(false, false); | 210 base::WaitableEvent done_event(false, false); |
| 213 | 211 |
| 214 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); | 212 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); |
| 215 EXPECT_CALL(*client, OnError()).Times(0); | 213 EXPECT_CALL(*client, OnError()).Times(0); |
| 216 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _, _, _)) | 214 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _, _, _)) |
| 217 .WillRepeatedly( | 215 .WillRepeatedly( |
| 218 DoAll(SaveArg<6>(&format), | 216 DoAll(SaveArg<6>(&caps), |
| 219 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); | 217 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); |
| 220 | 218 |
| 221 media::VideoCaptureParams capture_params; | 219 media::VideoCaptureCapability capture_format( |
| 222 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth2, | 220 kTestFrameWidth2, |
| 223 kTestFrameHeight2); | 221 kTestFrameHeight2, |
| 224 capture_params.requested_format.frame_rate = kFrameRate; | 222 kFrameRate, |
| 225 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; | 223 media::PIXEL_FORMAT_I420, |
| 226 capture_params.allow_resolution_change = false; | 224 media::VariableResolutionVideoCaptureDevice); |
| 227 | 225 |
| 228 capture_device.AllocateAndStart( | 226 capture_device.AllocateAndStart( |
| 229 capture_params, client.PassAs<media::VideoCaptureDevice::Client>()); | 227 capture_format, client.PassAs<media::VideoCaptureDevice::Client>()); |
| 230 | 228 |
| 231 // 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 |
| 232 // changed at least twice while capturing. | 230 // changed at least twice while capturing. |
| 233 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); | 231 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); |
| 234 done_event.Reset(); | 232 done_event.Reset(); |
| 235 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); | 233 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); |
| 236 done_event.Reset(); | 234 done_event.Reset(); |
| 237 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); | 235 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); |
| 238 | 236 |
| 239 capture_device.StopAndDeAllocate(); | 237 capture_device.StopAndDeAllocate(); |
| 240 | 238 |
| 241 EXPECT_EQ(kTestFrameWidth1, format.frame_size.width()); | 239 EXPECT_EQ(kTestFrameWidth1, caps.width); |
| 242 EXPECT_EQ(kTestFrameHeight1, format.frame_size.height()); | 240 EXPECT_EQ(kTestFrameHeight1, caps.height); |
| 243 EXPECT_EQ(kFrameRate, format.frame_rate); | 241 EXPECT_EQ(kFrameRate, caps.frame_rate); |
| 244 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format); | 242 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, caps.color); |
| 245 worker_pool_->FlushForTesting(); | 243 worker_pool_->FlushForTesting(); |
| 246 } | 244 } |
| 247 | 245 |
| 248 } // namespace content | 246 } // namespace content |
| OLD | NEW |