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

Side by Side Diff: content/browser/renderer_host/media/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: 5744a8bbb Nits. Created 6 years, 11 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/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 29 matching lines...) Expand all
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_METHOD0(OnError, void()); 46 MOCK_METHOD0(OnError, void());
47 MOCK_METHOD5(OnIncomingCapturedFrame, 47 MOCK_METHOD5(OnIncomingCapturedFrame,
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 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
150 webrtc::ScreenCapturer::Create()); 149 webrtc::ScreenCapturer::Create());
151 DesktopCaptureDevice capture_device( 150 DesktopCaptureDevice capture_device(
152 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()), 151 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()),
153 capturer.Pass()); 152 capturer.Pass());
154 media::VideoCaptureFormat format; 153 media::VideoCaptureFormat format;
155 base::WaitableEvent done_event(false, false); 154 base::WaitableEvent done_event(false, false);
156 int frame_size; 155 int frame_size;
157 156
158 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); 157 scoped_ptr<MockDeviceClient> client(new MockDeviceClient());
159 EXPECT_CALL(*client, OnError()).Times(0); 158 EXPECT_CALL(*client, OnError()).Times(0);
160 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _)) 159 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _)).WillRepeatedly(
161 .WillRepeatedly( 160 DoAll(SaveArg<1>(&frame_size),
162 DoAll(SaveArg<1>(&frame_size), 161 SaveArg<2>(&format),
163 SaveArg<4>(&format), 162 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
164 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
165 163
166 media::VideoCaptureParams capture_params; 164 media::VideoCaptureParams capture_params;
167 capture_params.requested_format.frame_size.SetSize(640, 480); 165 capture_params.requested_format.frame_size.SetSize(640, 480);
168 capture_params.requested_format.frame_rate = kFrameRate; 166 capture_params.requested_format.frame_rate = kFrameRate;
169 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 167 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
170 capture_params.allow_resolution_change = false; 168 capture_params.allow_resolution_change = false;
171 capture_device.AllocateAndStart( 169 capture_device.AllocateAndStart(
172 capture_params, client.PassAs<media::VideoCaptureDevice::Client>()); 170 capture_params, client.PassAs<media::VideoCaptureDevice::Client>());
173 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 171 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
174 capture_device.StopAndDeAllocate(); 172 capture_device.StopAndDeAllocate();
(...skipping 15 matching lines...) Expand all
190 DesktopCaptureDevice capture_device( 188 DesktopCaptureDevice capture_device(
191 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()), 189 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()),
192 scoped_ptr<webrtc::DesktopCapturer>(mock_capturer)); 190 scoped_ptr<webrtc::DesktopCapturer>(mock_capturer));
193 191
194 media::VideoCaptureFormat format; 192 media::VideoCaptureFormat format;
195 base::WaitableEvent done_event(false, false); 193 base::WaitableEvent done_event(false, false);
196 int frame_size; 194 int frame_size;
197 195
198 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); 196 scoped_ptr<MockDeviceClient> client(new MockDeviceClient());
199 EXPECT_CALL(*client, OnError()).Times(0); 197 EXPECT_CALL(*client, OnError()).Times(0);
200 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _)) 198 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _)).WillRepeatedly(
201 .WillRepeatedly( 199 DoAll(SaveArg<1>(&frame_size),
202 DoAll(SaveArg<1>(&frame_size), 200 SaveArg<2>(&format),
203 SaveArg<4>(&format), 201 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
204 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
205 202
206 media::VideoCaptureParams capture_params; 203 media::VideoCaptureParams capture_params;
207 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1, 204 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1,
208 kTestFrameHeight1); 205 kTestFrameHeight1);
209 capture_params.requested_format.frame_rate = kFrameRate; 206 capture_params.requested_format.frame_rate = kFrameRate;
210 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 207 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
211 capture_params.allow_resolution_change = false; 208 capture_params.allow_resolution_change = false;
212 209
213 capture_device.AllocateAndStart( 210 capture_device.AllocateAndStart(
214 capture_params, client.PassAs<media::VideoCaptureDevice::Client>()); 211 capture_params, client.PassAs<media::VideoCaptureDevice::Client>());
(...skipping 22 matching lines...) Expand all
237 234
238 DesktopCaptureDevice capture_device( 235 DesktopCaptureDevice capture_device(
239 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()), 236 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()),
240 scoped_ptr<webrtc::DesktopCapturer>(mock_capturer)); 237 scoped_ptr<webrtc::DesktopCapturer>(mock_capturer));
241 238
242 media::VideoCaptureFormat format; 239 media::VideoCaptureFormat format;
243 base::WaitableEvent done_event(false, false); 240 base::WaitableEvent done_event(false, false);
244 241
245 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); 242 scoped_ptr<MockDeviceClient> client(new MockDeviceClient());
246 EXPECT_CALL(*client, OnError()).Times(0); 243 EXPECT_CALL(*client, OnError()).Times(0);
247 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _)) 244 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _)).WillRepeatedly(
248 .WillRepeatedly( 245 DoAll(SaveArg<2>(&format),
249 DoAll(SaveArg<4>(&format), 246 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
250 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
251 247
252 media::VideoCaptureParams capture_params; 248 media::VideoCaptureParams capture_params;
253 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth2, 249 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth2,
254 kTestFrameHeight2); 250 kTestFrameHeight2);
255 capture_params.requested_format.frame_rate = kFrameRate; 251 capture_params.requested_format.frame_rate = kFrameRate;
256 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420; 252 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
257 capture_params.allow_resolution_change = false; 253 capture_params.allow_resolution_change = false;
258 254
259 capture_device.AllocateAndStart( 255 capture_device.AllocateAndStart(
260 capture_params, client.PassAs<media::VideoCaptureDevice::Client>()); 256 capture_params, client.PassAs<media::VideoCaptureDevice::Client>());
261 257
262 // Capture at least three frames, to ensure that the source frame size has 258 // Capture at least three frames, to ensure that the source frame size has
263 // changed at least twice while capturing. 259 // changed at least twice while capturing.
264 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 260 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
265 done_event.Reset(); 261 done_event.Reset();
266 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 262 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
267 done_event.Reset(); 263 done_event.Reset();
268 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 264 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
269 265
270 capture_device.StopAndDeAllocate(); 266 capture_device.StopAndDeAllocate();
271 267
272 EXPECT_EQ(kTestFrameWidth1, format.frame_size.width()); 268 EXPECT_EQ(kTestFrameWidth1, format.frame_size.width());
273 EXPECT_EQ(kTestFrameHeight1, format.frame_size.height()); 269 EXPECT_EQ(kTestFrameHeight1, format.frame_size.height());
274 EXPECT_EQ(kFrameRate, format.frame_rate); 270 EXPECT_EQ(kFrameRate, format.frame_rate);
275 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format); 271 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format);
276 worker_pool_->FlushForTesting(); 272 worker_pool_->FlushForTesting();
277 } 273 }
278 274
279 } // namespace content 275 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698