Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(100)

Side by Side Diff: content/browser/media/capture/desktop_capture_device_unittest.cc

Issue 83793004: Implement IPCs and VideoCapture::Client interfaces for texture capture (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: e296ac98 Win32 bits. Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/media/capture/desktop_capture_device.h" 5 #include "content/browser/media/capture/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 26 matching lines...) Expand all
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_METHOD2(ReserveOutputBuffer, 43 MOCK_METHOD2(ReserveOutputBuffer,
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_METHOD1(OnError, void(const std::string& reason)); 46 MOCK_METHOD1(OnError, void(const std::string& reason));
47 MOCK_METHOD5(OnIncomingCapturedFrame, 47 MOCK_METHOD5(OnIncomingCapturedData,
48 void(const uint8* data, 48 void(const uint8* data,
49 int length, 49 int length,
50 base::TimeTicks timestamp, 50 const media::VideoCaptureFormat& frame_format,
51 int rotation, 51 int rotation,
52 const media::VideoCaptureFormat& frame_format)); 52 base::TimeTicks timestamp));
53 MOCK_METHOD5(OnIncomingCapturedBuffer, 53 MOCK_METHOD4(OnIncomingCapturedVideoFrame,
54 void(const scoped_refptr<Buffer>& buffer, 54 void(const scoped_refptr<Buffer>& buffer,
55 media::VideoFrame::Format format, 55 const media::VideoCaptureFormat& buffer_format,
56 const gfx::Size& dimensions, 56 const scoped_refptr<media::VideoFrame>& frame,
57 base::TimeTicks timestamp, 57 base::TimeTicks timestamp));
58 int frame_rate));
59 }; 58 };
60 59
61 // DesktopFrame wrapper that flips wrapped frame upside down by inverting 60 // DesktopFrame wrapper that flips wrapped frame upside down by inverting
62 // stride. 61 // stride.
63 class InvertedDesktopFrame : public webrtc::DesktopFrame { 62 class InvertedDesktopFrame : public webrtc::DesktopFrame {
64 public: 63 public:
65 // Takes ownership of |frame|. 64 // Takes ownership of |frame|.
66 InvertedDesktopFrame(webrtc::DesktopFrame* frame) 65 InvertedDesktopFrame(webrtc::DesktopFrame* frame)
67 : webrtc::DesktopFrame( 66 : webrtc::DesktopFrame(
68 frame->size(), -frame->stride(), 67 frame->size(), -frame->stride(),
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 webrtc::ScreenCapturer::Create()); 157 webrtc::ScreenCapturer::Create());
159 DesktopCaptureDevice capture_device( 158 DesktopCaptureDevice capture_device(
160 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()), 159 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()),
161 capturer.Pass()); 160 capturer.Pass());
162 media::VideoCaptureFormat format; 161 media::VideoCaptureFormat format;
163 base::WaitableEvent done_event(false, false); 162 base::WaitableEvent done_event(false, false);
164 int frame_size; 163 int frame_size;
165 164
166 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); 165 scoped_ptr<MockDeviceClient> client(new MockDeviceClient());
167 EXPECT_CALL(*client, OnError(_)).Times(0); 166 EXPECT_CALL(*client, OnError(_)).Times(0);
168 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _)) 167 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _)).WillRepeatedly(
169 .WillRepeatedly( 168 DoAll(SaveArg<1>(&frame_size),
170 DoAll(SaveArg<1>(&frame_size), 169 SaveArg<2>(&format),
171 SaveArg<4>(&format), 170 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
172 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
173 171
174 media::VideoCaptureParams capture_params; 172 media::VideoCaptureParams capture_params;
175 capture_params.requested_format.frame_size.SetSize(640, 480); 173 capture_params.requested_format.frame_size.SetSize(640, 480);
176 capture_params.requested_format.frame_rate = kFrameRate; 174 capture_params.requested_format.frame_rate = kFrameRate;
177 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 175 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
178 capture_params.allow_resolution_change = false; 176 capture_params.allow_resolution_change = false;
179 capture_device.AllocateAndStart( 177 capture_device.AllocateAndStart(
180 capture_params, client.PassAs<media::VideoCaptureDevice::Client>()); 178 capture_params, client.PassAs<media::VideoCaptureDevice::Client>());
181 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 179 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
182 capture_device.StopAndDeAllocate(); 180 capture_device.StopAndDeAllocate();
(...skipping 15 matching lines...) Expand all
198 DesktopCaptureDevice capture_device( 196 DesktopCaptureDevice capture_device(
199 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()), 197 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()),
200 scoped_ptr<webrtc::DesktopCapturer>(mock_capturer)); 198 scoped_ptr<webrtc::DesktopCapturer>(mock_capturer));
201 199
202 media::VideoCaptureFormat format; 200 media::VideoCaptureFormat format;
203 base::WaitableEvent done_event(false, false); 201 base::WaitableEvent done_event(false, false);
204 int frame_size; 202 int frame_size;
205 203
206 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); 204 scoped_ptr<MockDeviceClient> client(new MockDeviceClient());
207 EXPECT_CALL(*client, OnError(_)).Times(0); 205 EXPECT_CALL(*client, OnError(_)).Times(0);
208 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _)) 206 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _)).WillRepeatedly(
209 .WillRepeatedly( 207 DoAll(SaveArg<1>(&frame_size),
210 DoAll(SaveArg<1>(&frame_size), 208 SaveArg<2>(&format),
211 SaveArg<4>(&format), 209 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
212 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
213 210
214 media::VideoCaptureParams capture_params; 211 media::VideoCaptureParams capture_params;
215 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1, 212 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1,
216 kTestFrameHeight1); 213 kTestFrameHeight1);
217 capture_params.requested_format.frame_rate = kFrameRate; 214 capture_params.requested_format.frame_rate = kFrameRate;
218 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 215 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
219 capture_params.allow_resolution_change = false; 216 capture_params.allow_resolution_change = false;
220 217
221 capture_device.AllocateAndStart( 218 capture_device.AllocateAndStart(
222 capture_params, client.PassAs<media::VideoCaptureDevice::Client>()); 219 capture_params, client.PassAs<media::VideoCaptureDevice::Client>());
(...skipping 22 matching lines...) Expand all
245 242
246 DesktopCaptureDevice capture_device( 243 DesktopCaptureDevice capture_device(
247 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()), 244 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()),
248 scoped_ptr<webrtc::DesktopCapturer>(mock_capturer)); 245 scoped_ptr<webrtc::DesktopCapturer>(mock_capturer));
249 246
250 media::VideoCaptureFormat format; 247 media::VideoCaptureFormat format;
251 base::WaitableEvent done_event(false, false); 248 base::WaitableEvent done_event(false, false);
252 249
253 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); 250 scoped_ptr<MockDeviceClient> client(new MockDeviceClient());
254 EXPECT_CALL(*client, OnError(_)).Times(0); 251 EXPECT_CALL(*client, OnError(_)).Times(0);
255 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _)) 252 EXPECT_CALL(*client, OnIncomingCapturedData(_, _, _, _, _)).WillRepeatedly(
256 .WillRepeatedly( 253 DoAll(SaveArg<2>(&format),
257 DoAll(SaveArg<4>(&format), 254 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
258 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
259 255
260 media::VideoCaptureParams capture_params; 256 media::VideoCaptureParams capture_params;
261 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth2, 257 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth2,
262 kTestFrameHeight2); 258 kTestFrameHeight2);
263 capture_params.requested_format.frame_rate = kFrameRate; 259 capture_params.requested_format.frame_rate = kFrameRate;
264 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 260 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
265 capture_params.allow_resolution_change = false; 261 capture_params.allow_resolution_change = false;
266 262
267 capture_device.AllocateAndStart( 263 capture_device.AllocateAndStart(
268 capture_params, client.PassAs<media::VideoCaptureDevice::Client>()); 264 capture_params, client.PassAs<media::VideoCaptureDevice::Client>());
269 265
270 // Capture at least three frames, to ensure that the source frame size has 266 // Capture at least three frames, to ensure that the source frame size has
271 // changed at least twice while capturing. 267 // changed at least twice while capturing.
272 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 268 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
273 done_event.Reset(); 269 done_event.Reset();
274 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 270 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
275 done_event.Reset(); 271 done_event.Reset();
276 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 272 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
277 273
278 capture_device.StopAndDeAllocate(); 274 capture_device.StopAndDeAllocate();
279 275
280 EXPECT_EQ(kTestFrameWidth1, format.frame_size.width()); 276 EXPECT_EQ(kTestFrameWidth1, format.frame_size.width());
281 EXPECT_EQ(kTestFrameHeight1, format.frame_size.height()); 277 EXPECT_EQ(kTestFrameHeight1, format.frame_size.height());
282 EXPECT_EQ(kFrameRate, format.frame_rate); 278 EXPECT_EQ(kFrameRate, format.frame_rate);
283 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format); 279 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format);
284 worker_pool_->FlushForTesting(); 280 worker_pool_->FlushForTesting();
285 } 281 }
286 282
287 } // namespace content 283 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698