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

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

Issue 83633008: Reland: Reorganize media::VideoCapture* types (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
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::VideoCaptureCapability& frame_info)); 54 const media::VideoCaptureFormat& frame_format));
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
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::VideoCaptureCapability caps; 123 media::VideoCaptureFormat format;
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>(&caps), 132 SaveArg<6>(&format),
133 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 133 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
134 134
135 media::VideoCaptureCapability capture_format( 135 media::VideoCaptureParams capture_params;
136 640, 480, kFrameRate, media::PIXEL_FORMAT_I420, 136 capture_params.requested_format.frame_size.SetSize(640, 480);
137 media::ConstantResolutionVideoCaptureDevice); 137 capture_params.requested_format.frame_rate = kFrameRate;
138 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
139 capture_params.allow_resolution_change = false;
138 capture_device.AllocateAndStart( 140 capture_device.AllocateAndStart(
139 capture_format, client.PassAs<media::VideoCaptureDevice::Client>()); 141 capture_params, client.PassAs<media::VideoCaptureDevice::Client>());
140 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 142 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
141 capture_device.StopAndDeAllocate(); 143 capture_device.StopAndDeAllocate();
142 144
143 EXPECT_GT(caps.width, 0); 145 EXPECT_GT(format.frame_size.width(), 0);
144 EXPECT_GT(caps.height, 0); 146 EXPECT_GT(format.frame_size.height(), 0);
145 EXPECT_EQ(kFrameRate, caps.frame_rate); 147 EXPECT_EQ(kFrameRate, format.frame_rate);
146 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, caps.color); 148 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format);
147 149
148 EXPECT_EQ(caps.width * caps.height * 4, frame_size); 150 EXPECT_EQ(format.frame_size.GetArea() * 4, frame_size);
149 worker_pool_->FlushForTesting(); 151 worker_pool_->FlushForTesting();
150 } 152 }
151 153
152 // Test that screen capturer behaves correctly if the source frame size changes 154 // Test that screen capturer behaves correctly if the source frame size changes
153 // but the caller cannot cope with variable resolution output. 155 // but the caller cannot cope with variable resolution output.
154 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeConstantResolution) { 156 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeConstantResolution) {
155 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); 157 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer();
156 158
157 DesktopCaptureDevice capture_device( 159 DesktopCaptureDevice capture_device(
158 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()), 160 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()),
159 scoped_ptr<webrtc::DesktopCapturer>(mock_capturer)); 161 scoped_ptr<webrtc::DesktopCapturer>(mock_capturer));
160 162
161 media::VideoCaptureCapability caps; 163 media::VideoCaptureFormat format;
162 base::WaitableEvent done_event(false, false); 164 base::WaitableEvent done_event(false, false);
163 int frame_size; 165 int frame_size;
164 166
165 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); 167 scoped_ptr<MockDeviceClient> client(new MockDeviceClient());
166 EXPECT_CALL(*client, OnError()).Times(0); 168 EXPECT_CALL(*client, OnError()).Times(0);
167 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _, _, _)) 169 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _, _, _))
168 .WillRepeatedly( 170 .WillRepeatedly(
169 DoAll(SaveArg<1>(&frame_size), 171 DoAll(SaveArg<1>(&frame_size),
170 SaveArg<6>(&caps), 172 SaveArg<6>(&format),
171 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 173 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
172 174
173 media::VideoCaptureCapability capture_format( 175 media::VideoCaptureParams capture_params;
174 kTestFrameWidth1, 176 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth1,
175 kTestFrameHeight1, 177 kTestFrameHeight1);
176 kFrameRate, 178 capture_params.requested_format.frame_rate = kFrameRate;
177 media::PIXEL_FORMAT_I420, 179 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
178 media::ConstantResolutionVideoCaptureDevice); 180 capture_params.allow_resolution_change = false;
179 181
180 capture_device.AllocateAndStart( 182 capture_device.AllocateAndStart(
181 capture_format, client.PassAs<media::VideoCaptureDevice::Client>()); 183 capture_params, client.PassAs<media::VideoCaptureDevice::Client>());
182 184
183 // Capture at least two frames, to ensure that the source frame size has 185 // Capture at least two frames, to ensure that the source frame size has
184 // changed while capturing. 186 // changed while capturing.
185 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 187 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
186 done_event.Reset(); 188 done_event.Reset();
187 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 189 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
188 190
189 capture_device.StopAndDeAllocate(); 191 capture_device.StopAndDeAllocate();
190 192
191 EXPECT_EQ(kTestFrameWidth1, caps.width); 193 EXPECT_EQ(kTestFrameWidth1, format.frame_size.width());
192 EXPECT_EQ(kTestFrameHeight1, caps.height); 194 EXPECT_EQ(kTestFrameHeight1, format.frame_size.height());
193 EXPECT_EQ(kFrameRate, caps.frame_rate); 195 EXPECT_EQ(kFrameRate, format.frame_rate);
194 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, caps.color); 196 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format);
195 197
196 EXPECT_EQ(caps.width * caps.height * 4, frame_size); 198 EXPECT_EQ(format.frame_size.GetArea() * 4, frame_size);
197 worker_pool_->FlushForTesting(); 199 worker_pool_->FlushForTesting();
198 } 200 }
199 201
200 // Test that screen capturer behaves correctly if the source frame size changes 202 // Test that screen capturer behaves correctly if the source frame size changes
201 // and the caller can cope with variable resolution output. 203 // and the caller can cope with variable resolution output.
202 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeVariableResolution) { 204 TEST_F(DesktopCaptureDeviceTest, ScreenResolutionChangeVariableResolution) {
203 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer(); 205 FakeScreenCapturer* mock_capturer = new FakeScreenCapturer();
204 206
205 DesktopCaptureDevice capture_device( 207 DesktopCaptureDevice capture_device(
206 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()), 208 worker_pool_->GetSequencedTaskRunner(worker_pool_->GetSequenceToken()),
207 scoped_ptr<webrtc::DesktopCapturer>(mock_capturer)); 209 scoped_ptr<webrtc::DesktopCapturer>(mock_capturer));
208 210
209 media::VideoCaptureCapability caps; 211 media::VideoCaptureFormat format;
210 base::WaitableEvent done_event(false, false); 212 base::WaitableEvent done_event(false, false);
211 213
212 scoped_ptr<MockDeviceClient> client(new MockDeviceClient()); 214 scoped_ptr<MockDeviceClient> client(new MockDeviceClient());
213 EXPECT_CALL(*client, OnError()).Times(0); 215 EXPECT_CALL(*client, OnError()).Times(0);
214 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _, _, _)) 216 EXPECT_CALL(*client, OnIncomingCapturedFrame(_, _, _, _, _, _, _))
215 .WillRepeatedly( 217 .WillRepeatedly(
216 DoAll(SaveArg<6>(&caps), 218 DoAll(SaveArg<6>(&format),
217 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal))); 219 InvokeWithoutArgs(&done_event, &base::WaitableEvent::Signal)));
218 220
219 media::VideoCaptureCapability capture_format( 221 media::VideoCaptureParams capture_params;
220 kTestFrameWidth2, 222 capture_params.requested_format.frame_size.SetSize(kTestFrameWidth2,
221 kTestFrameHeight2, 223 kTestFrameHeight2);
222 kFrameRate, 224 capture_params.requested_format.frame_rate = kFrameRate;
223 media::PIXEL_FORMAT_I420, 225 capture_params.requested_format.pixel_format = media::PIXEL_FORMAT_I420;
224 media::VariableResolutionVideoCaptureDevice); 226 capture_params.allow_resolution_change = false;
225 227
226 capture_device.AllocateAndStart( 228 capture_device.AllocateAndStart(
227 capture_format, client.PassAs<media::VideoCaptureDevice::Client>()); 229 capture_params, client.PassAs<media::VideoCaptureDevice::Client>());
228 230
229 // Capture at least three frames, to ensure that the source frame size has 231 // Capture at least three frames, to ensure that the source frame size has
230 // changed at least twice while capturing. 232 // changed at least twice while capturing.
231 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 233 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
232 done_event.Reset(); 234 done_event.Reset();
233 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 235 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
234 done_event.Reset(); 236 done_event.Reset();
235 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout())); 237 EXPECT_TRUE(done_event.TimedWait(TestTimeouts::action_max_timeout()));
236 238
237 capture_device.StopAndDeAllocate(); 239 capture_device.StopAndDeAllocate();
238 240
239 EXPECT_EQ(kTestFrameWidth1, caps.width); 241 EXPECT_EQ(kTestFrameWidth1, format.frame_size.width());
240 EXPECT_EQ(kTestFrameHeight1, caps.height); 242 EXPECT_EQ(kTestFrameHeight1, format.frame_size.height());
241 EXPECT_EQ(kFrameRate, caps.frame_rate); 243 EXPECT_EQ(kFrameRate, format.frame_rate);
242 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, caps.color); 244 EXPECT_EQ(media::PIXEL_FORMAT_ARGB, format.pixel_format);
243 worker_pool_->FlushForTesting(); 245 worker_pool_->FlushForTesting();
244 } 246 }
245 247
246 } // namespace content 248 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698