OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "media/capture/video/fake_video_capture_device.h" | 5 #include "media/capture/video/fake_video_capture_device.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 | 170 |
171 mojom::PhotoCapabilitiesPtr capabilities_; | 171 mojom::PhotoCapabilitiesPtr capabilities_; |
172 }; | 172 }; |
173 | 173 |
174 } // namespace | 174 } // namespace |
175 | 175 |
176 class FakeVideoCaptureDeviceBase : public ::testing::Test { | 176 class FakeVideoCaptureDeviceBase : public ::testing::Test { |
177 protected: | 177 protected: |
178 FakeVideoCaptureDeviceBase() | 178 FakeVideoCaptureDeviceBase() |
179 : loop_(new base::MessageLoop()), | 179 : loop_(new base::MessageLoop()), |
180 client_(new MockClient( | 180 client_(CreateClient()), |
181 base::Bind(&FakeVideoCaptureDeviceBase::OnFrameCaptured, | |
182 base::Unretained(this)))), | |
183 device_enumeration_listener_(new DeviceEnumerationListener()), | 181 device_enumeration_listener_(new DeviceEnumerationListener()), |
184 image_capture_client_(new ImageCaptureClient()), | 182 image_capture_client_(new ImageCaptureClient()), |
185 video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) {} | 183 video_capture_device_factory_(new FakeVideoCaptureDeviceFactory()) {} |
186 | 184 |
187 void SetUp() override { EXPECT_CALL(*client_, OnError(_, _)).Times(0); } | 185 void SetUp() override { EXPECT_CALL(*client_, OnError(_, _)).Times(0); } |
188 | 186 |
187 std::unique_ptr<MockClient> CreateClient() { | |
188 std::unique_ptr<MockClient> client = std::unique_ptr<MockClient>( | |
189 new MockClient(base::Bind(&FakeVideoCaptureDeviceBase::OnFrameCaptured, | |
190 base::Unretained(this)))); | |
191 return client; | |
mcasas
2016/10/25 22:13:13
Suggestion:
return base::MakeUnique<MockClien
aleksandar.stojiljkovic
2016/10/25 23:20:40
Done.
| |
192 } | |
193 | |
189 void OnFrameCaptured(const VideoCaptureFormat& format) { | 194 void OnFrameCaptured(const VideoCaptureFormat& format) { |
190 last_format_ = format; | 195 last_format_ = format; |
191 run_loop_->QuitClosure().Run(); | 196 run_loop_->QuitClosure().Run(); |
192 } | 197 } |
193 | 198 |
194 void WaitForCapturedFrame() { | 199 void WaitForCapturedFrame() { |
195 run_loop_.reset(new base::RunLoop()); | 200 run_loop_.reset(new base::RunLoop()); |
196 run_loop_->Run(); | 201 run_loop_->Run(); |
197 } | 202 } |
198 | 203 |
(...skipping 26 matching lines...) Expand all Loading... | |
225 class FakeVideoCaptureDeviceTest | 230 class FakeVideoCaptureDeviceTest |
226 : public FakeVideoCaptureDeviceBase, | 231 : public FakeVideoCaptureDeviceBase, |
227 public ::testing::WithParamInterface< | 232 public ::testing::WithParamInterface< |
228 ::testing::tuple<FakeVideoCaptureDevice::BufferOwnership, float>> {}; | 233 ::testing::tuple<FakeVideoCaptureDevice::BufferOwnership, float>> {}; |
229 | 234 |
230 struct CommandLineTestData { | 235 struct CommandLineTestData { |
231 // Command line argument | 236 // Command line argument |
232 std::string argument; | 237 std::string argument; |
233 // Expected values | 238 // Expected values |
234 float fps; | 239 float fps; |
240 size_t device_count; | |
235 }; | 241 }; |
236 | 242 |
237 class FakeVideoCaptureDeviceCommandLineTest | 243 class FakeVideoCaptureDeviceCommandLineTest |
238 : public FakeVideoCaptureDeviceBase, | 244 : public FakeVideoCaptureDeviceBase, |
239 public ::testing::WithParamInterface<CommandLineTestData> {}; | 245 public ::testing::WithParamInterface<CommandLineTestData> {}; |
240 | 246 |
241 TEST_P(FakeVideoCaptureDeviceTest, CaptureUsing) { | 247 TEST_P(FakeVideoCaptureDeviceTest, CaptureUsing) { |
242 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( | 248 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
243 EnumerateDevices()); | 249 EnumerateDevices()); |
244 ASSERT_FALSE(descriptors->empty()); | 250 ASSERT_FALSE(descriptors->empty()); |
(...skipping 15 matching lines...) Expand all Loading... | |
260 } | 266 } |
261 | 267 |
262 INSTANTIATE_TEST_CASE_P( | 268 INSTANTIATE_TEST_CASE_P( |
263 , | 269 , |
264 FakeVideoCaptureDeviceTest, | 270 FakeVideoCaptureDeviceTest, |
265 Combine(Values(FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS, | 271 Combine(Values(FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS, |
266 FakeVideoCaptureDevice::BufferOwnership::CLIENT_BUFFERS), | 272 FakeVideoCaptureDevice::BufferOwnership::CLIENT_BUFFERS), |
267 Values(20, 29.97, 30, 50, 60))); | 273 Values(20, 29.97, 30, 50, 60))); |
268 | 274 |
269 TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { | 275 TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
276 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | |
277 switches::kUseFakeDeviceForMediaStream, "device-count=3"); | |
270 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( | 278 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
271 EnumerateDevices()); | 279 EnumerateDevices()); |
280 ASSERT_EQ(descriptors->size(), 3u); | |
mcasas
2016/10/25 22:13:12
ASSERT_EQ(expected, actual), so here:
ASSERT_EQ(3u
aleksandar.stojiljkovic
2016/10/25 23:20:40
Done.
I did it only in this method - will do the r
| |
272 | 281 |
273 for (const auto& descriptors_iterator : *descriptors) { | 282 for (const auto& descriptors_iterator : *descriptors) { |
274 VideoCaptureFormats supported_formats; | 283 VideoCaptureFormats supported_formats; |
275 video_capture_device_factory_->GetSupportedFormats(descriptors_iterator, | 284 video_capture_device_factory_->GetSupportedFormats(descriptors_iterator, |
276 &supported_formats); | 285 &supported_formats); |
277 ASSERT_EQ(supported_formats.size(), 4u); | 286 ASSERT_EQ(supported_formats.size(), 5u); |
278 EXPECT_EQ(supported_formats[0].frame_size.width(), 320); | 287 const std::string device_id = descriptors_iterator.device_id; |
279 EXPECT_EQ(supported_formats[0].frame_size.height(), 240); | 288 VideoPixelFormat expected_format = |
280 EXPECT_EQ(supported_formats[0].pixel_format, PIXEL_FORMAT_I420); | 289 (device_id == "/dev/video1") ? PIXEL_FORMAT_Y16 : PIXEL_FORMAT_I420; |
290 EXPECT_EQ(supported_formats[0].frame_size.width(), 96); | |
291 EXPECT_EQ(supported_formats[0].frame_size.height(), 96); | |
292 EXPECT_EQ(supported_formats[0].pixel_format, expected_format); | |
281 EXPECT_GE(supported_formats[0].frame_rate, 20.0); | 293 EXPECT_GE(supported_formats[0].frame_rate, 20.0); |
282 EXPECT_EQ(supported_formats[1].frame_size.width(), 640); | 294 EXPECT_EQ(supported_formats[1].frame_size.width(), 320); |
283 EXPECT_EQ(supported_formats[1].frame_size.height(), 480); | 295 EXPECT_EQ(supported_formats[1].frame_size.height(), 240); |
284 EXPECT_EQ(supported_formats[1].pixel_format, PIXEL_FORMAT_I420); | 296 EXPECT_EQ(supported_formats[1].pixel_format, expected_format); |
285 EXPECT_GE(supported_formats[1].frame_rate, 20.0); | 297 EXPECT_GE(supported_formats[1].frame_rate, 20.0); |
286 EXPECT_EQ(supported_formats[2].frame_size.width(), 1280); | 298 EXPECT_EQ(supported_formats[2].frame_size.width(), 640); |
287 EXPECT_EQ(supported_formats[2].frame_size.height(), 720); | 299 EXPECT_EQ(supported_formats[2].frame_size.height(), 480); |
288 EXPECT_EQ(supported_formats[2].pixel_format, PIXEL_FORMAT_I420); | 300 EXPECT_EQ(supported_formats[2].pixel_format, expected_format); |
289 EXPECT_GE(supported_formats[2].frame_rate, 20.0); | 301 EXPECT_GE(supported_formats[2].frame_rate, 20.0); |
290 EXPECT_EQ(supported_formats[3].frame_size.width(), 1920); | 302 EXPECT_EQ(supported_formats[3].frame_size.width(), 1280); |
291 EXPECT_EQ(supported_formats[3].frame_size.height(), 1080); | 303 EXPECT_EQ(supported_formats[3].frame_size.height(), 720); |
292 EXPECT_EQ(supported_formats[3].pixel_format, PIXEL_FORMAT_I420); | 304 EXPECT_EQ(supported_formats[3].pixel_format, expected_format); |
293 EXPECT_GE(supported_formats[3].frame_rate, 20.0); | 305 EXPECT_GE(supported_formats[3].frame_rate, 20.0); |
306 EXPECT_EQ(supported_formats[4].frame_size.width(), 1920); | |
307 EXPECT_EQ(supported_formats[4].frame_size.height(), 1080); | |
308 EXPECT_EQ(supported_formats[4].pixel_format, expected_format); | |
309 EXPECT_GE(supported_formats[4].frame_rate, 20.0); | |
294 } | 310 } |
295 } | 311 } |
296 | 312 |
297 TEST_F(FakeVideoCaptureDeviceTest, GetAndSetCapabilities) { | 313 TEST_F(FakeVideoCaptureDeviceTest, GetAndSetCapabilities) { |
298 std::unique_ptr<VideoCaptureDevice> device(new FakeVideoCaptureDevice( | 314 std::unique_ptr<VideoCaptureDevice> device(new FakeVideoCaptureDevice( |
299 FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS, 30.0)); | 315 FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS, 30.0)); |
300 ASSERT_TRUE(device); | 316 ASSERT_TRUE(device); |
301 | 317 |
302 VideoCaptureParams capture_params; | 318 VideoCaptureParams capture_params; |
303 capture_params.requested_format.frame_size.SetSize(640, 480); | 319 capture_params.requested_format.frame_size.SetSize(640, 480); |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
419 image_capture_client_)); | 435 image_capture_client_)); |
420 | 436 |
421 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); | 437 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); |
422 device->TakePhoto(std::move(scoped_callback)); | 438 device->TakePhoto(std::move(scoped_callback)); |
423 | 439 |
424 run_loop_.reset(new base::RunLoop()); | 440 run_loop_.reset(new base::RunLoop()); |
425 run_loop_->Run(); | 441 run_loop_->Run(); |
426 device->StopAndDeAllocate(); | 442 device->StopAndDeAllocate(); |
427 } | 443 } |
428 | 444 |
429 TEST_P(FakeVideoCaptureDeviceCommandLineTest, FrameRate) { | 445 TEST_P(FakeVideoCaptureDeviceCommandLineTest, FrameRateAndDeviceCount) { |
430 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 446 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
431 switches::kUseFakeDeviceForMediaStream, GetParam().argument); | 447 switches::kUseFakeDeviceForMediaStream, GetParam().argument); |
432 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( | 448 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( |
433 EnumerateDevices()); | 449 EnumerateDevices()); |
450 EXPECT_EQ(descriptors->size(), GetParam().device_count); | |
434 ASSERT_FALSE(descriptors->empty()); | 451 ASSERT_FALSE(descriptors->empty()); |
435 | 452 |
436 for (const auto& descriptors_iterator : *descriptors) { | 453 for (const auto& descriptors_iterator : *descriptors) { |
437 std::unique_ptr<VideoCaptureDevice> device = | 454 std::unique_ptr<VideoCaptureDevice> device = |
438 video_capture_device_factory_->CreateDevice(descriptors_iterator); | 455 video_capture_device_factory_->CreateDevice(descriptors_iterator); |
439 ASSERT_TRUE(device); | 456 ASSERT_TRUE(device); |
440 | 457 |
441 VideoCaptureParams capture_params; | 458 VideoCaptureParams capture_params; |
442 capture_params.requested_format.frame_size.SetSize(1280, 720); | 459 capture_params.requested_format.frame_size.SetSize(1280, 720); |
443 capture_params.requested_format.frame_rate = GetParam().fps; | 460 capture_params.requested_format.frame_rate = GetParam().fps; |
444 device->AllocateAndStart(capture_params, std::move(client_)); | 461 device->AllocateAndStart(capture_params, CreateClient()); |
445 | |
446 WaitForCapturedFrame(); | 462 WaitForCapturedFrame(); |
447 EXPECT_EQ(last_format().frame_size.width(), 1280); | 463 EXPECT_EQ(last_format().frame_size.width(), 1280); |
448 EXPECT_EQ(last_format().frame_size.height(), 720); | 464 EXPECT_EQ(last_format().frame_size.height(), 720); |
449 EXPECT_EQ(last_format().frame_rate, GetParam().fps); | 465 EXPECT_EQ(last_format().frame_rate, GetParam().fps); |
450 device->StopAndDeAllocate(); | 466 device->StopAndDeAllocate(); |
451 } | 467 } |
452 } | 468 } |
453 | 469 |
454 INSTANTIATE_TEST_CASE_P(, | 470 INSTANTIATE_TEST_CASE_P( |
455 FakeVideoCaptureDeviceCommandLineTest, | 471 , |
456 Values(CommandLineTestData{"fps=-1", 5}, | 472 FakeVideoCaptureDeviceCommandLineTest, |
457 CommandLineTestData{"fps=29.97", 29.97f}, | 473 Values(CommandLineTestData{"fps=-1", 5, 1u}, |
458 CommandLineTestData{"fps=60", 60}, | 474 CommandLineTestData{"fps=29.97, device-count=1", 29.97f, 1u}, |
459 CommandLineTestData{"fps=1000", 60})); | 475 CommandLineTestData{"fps=60, device-count=2", 60, 2u}, |
476 CommandLineTestData{"fps=1000, device-count=-1", 60, 1u}, | |
477 CommandLineTestData{"device-count=2", 20, 2u}, | |
478 CommandLineTestData{"device-count=0", 20, 1u})); | |
460 }; // namespace media | 479 }; // namespace media |
OLD | NEW |