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

Side by Side Diff: media/capture/video/fake_video_capture_device_unittest.cc

Issue 2447233002: FakeVideoCaptureDevice: Y16 testing support. (Closed)
Patch Set: Nits. Created 4 years, 1 month 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
« no previous file with comments | « media/capture/video/fake_video_capture_device_factory.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 return std::unique_ptr<MockClient>(new MockClient(base::Bind(
189 &FakeVideoCaptureDeviceBase::OnFrameCaptured, base::Unretained(this))));
190 }
191
189 void OnFrameCaptured(const VideoCaptureFormat& format) { 192 void OnFrameCaptured(const VideoCaptureFormat& format) {
190 last_format_ = format; 193 last_format_ = format;
191 run_loop_->QuitClosure().Run(); 194 run_loop_->QuitClosure().Run();
192 } 195 }
193 196
194 void WaitForCapturedFrame() { 197 void WaitForCapturedFrame() {
195 run_loop_.reset(new base::RunLoop()); 198 run_loop_.reset(new base::RunLoop());
196 run_loop_->Run(); 199 run_loop_->Run();
197 } 200 }
198 201
(...skipping 26 matching lines...) Expand all
225 class FakeVideoCaptureDeviceTest 228 class FakeVideoCaptureDeviceTest
226 : public FakeVideoCaptureDeviceBase, 229 : public FakeVideoCaptureDeviceBase,
227 public ::testing::WithParamInterface< 230 public ::testing::WithParamInterface<
228 ::testing::tuple<FakeVideoCaptureDevice::BufferOwnership, float>> {}; 231 ::testing::tuple<FakeVideoCaptureDevice::BufferOwnership, float>> {};
229 232
230 struct CommandLineTestData { 233 struct CommandLineTestData {
231 // Command line argument 234 // Command line argument
232 std::string argument; 235 std::string argument;
233 // Expected values 236 // Expected values
234 float fps; 237 float fps;
238 size_t device_count;
235 }; 239 };
236 240
237 class FakeVideoCaptureDeviceCommandLineTest 241 class FakeVideoCaptureDeviceCommandLineTest
238 : public FakeVideoCaptureDeviceBase, 242 : public FakeVideoCaptureDeviceBase,
239 public ::testing::WithParamInterface<CommandLineTestData> {}; 243 public ::testing::WithParamInterface<CommandLineTestData> {};
240 244
241 TEST_P(FakeVideoCaptureDeviceTest, CaptureUsing) { 245 TEST_P(FakeVideoCaptureDeviceTest, CaptureUsing) {
242 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( 246 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors(
243 EnumerateDevices()); 247 EnumerateDevices());
244 ASSERT_FALSE(descriptors->empty()); 248 ASSERT_FALSE(descriptors->empty());
(...skipping 15 matching lines...) Expand all
260 } 264 }
261 265
262 INSTANTIATE_TEST_CASE_P( 266 INSTANTIATE_TEST_CASE_P(
263 , 267 ,
264 FakeVideoCaptureDeviceTest, 268 FakeVideoCaptureDeviceTest,
265 Combine(Values(FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS, 269 Combine(Values(FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS,
266 FakeVideoCaptureDevice::BufferOwnership::CLIENT_BUFFERS), 270 FakeVideoCaptureDevice::BufferOwnership::CLIENT_BUFFERS),
267 Values(20, 29.97, 30, 50, 60))); 271 Values(20, 29.97, 30, 50, 60)));
268 272
269 TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { 273 TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) {
274 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
275 switches::kUseFakeDeviceForMediaStream, "device-count=3");
270 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( 276 std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors(
271 EnumerateDevices()); 277 EnumerateDevices());
278 ASSERT_EQ(3u, descriptors->size());
272 279
273 for (const auto& descriptors_iterator : *descriptors) { 280 for (const auto& descriptors_iterator : *descriptors) {
274 VideoCaptureFormats supported_formats; 281 VideoCaptureFormats supported_formats;
275 video_capture_device_factory_->GetSupportedFormats(descriptors_iterator, 282 video_capture_device_factory_->GetSupportedFormats(descriptors_iterator,
276 &supported_formats); 283 &supported_formats);
277 ASSERT_EQ(supported_formats.size(), 4u); 284 ASSERT_EQ(5u, supported_formats.size());
278 EXPECT_EQ(supported_formats[0].frame_size.width(), 320); 285 const std::string device_id = descriptors_iterator.device_id;
279 EXPECT_EQ(supported_formats[0].frame_size.height(), 240); 286 VideoPixelFormat expected_format =
280 EXPECT_EQ(supported_formats[0].pixel_format, PIXEL_FORMAT_I420); 287 (device_id == "/dev/video1") ? PIXEL_FORMAT_Y16 : PIXEL_FORMAT_I420;
288 EXPECT_EQ(96, supported_formats[0].frame_size.width());
289 EXPECT_EQ(96, supported_formats[0].frame_size.height());
290 EXPECT_EQ(expected_format, supported_formats[0].pixel_format);
281 EXPECT_GE(supported_formats[0].frame_rate, 20.0); 291 EXPECT_GE(supported_formats[0].frame_rate, 20.0);
282 EXPECT_EQ(supported_formats[1].frame_size.width(), 640); 292 EXPECT_EQ(320, supported_formats[1].frame_size.width());
283 EXPECT_EQ(supported_formats[1].frame_size.height(), 480); 293 EXPECT_EQ(240, supported_formats[1].frame_size.height());
284 EXPECT_EQ(supported_formats[1].pixel_format, PIXEL_FORMAT_I420); 294 EXPECT_EQ(expected_format, supported_formats[1].pixel_format);
285 EXPECT_GE(supported_formats[1].frame_rate, 20.0); 295 EXPECT_GE(supported_formats[1].frame_rate, 20.0);
286 EXPECT_EQ(supported_formats[2].frame_size.width(), 1280); 296 EXPECT_EQ(640, supported_formats[2].frame_size.width());
287 EXPECT_EQ(supported_formats[2].frame_size.height(), 720); 297 EXPECT_EQ(480, supported_formats[2].frame_size.height());
288 EXPECT_EQ(supported_formats[2].pixel_format, PIXEL_FORMAT_I420); 298 EXPECT_EQ(expected_format, supported_formats[2].pixel_format);
289 EXPECT_GE(supported_formats[2].frame_rate, 20.0); 299 EXPECT_GE(supported_formats[2].frame_rate, 20.0);
290 EXPECT_EQ(supported_formats[3].frame_size.width(), 1920); 300 EXPECT_EQ(1280, supported_formats[3].frame_size.width());
291 EXPECT_EQ(supported_formats[3].frame_size.height(), 1080); 301 EXPECT_EQ(720, supported_formats[3].frame_size.height());
292 EXPECT_EQ(supported_formats[3].pixel_format, PIXEL_FORMAT_I420); 302 EXPECT_EQ(expected_format, supported_formats[3].pixel_format);
293 EXPECT_GE(supported_formats[3].frame_rate, 20.0); 303 EXPECT_GE(supported_formats[3].frame_rate, 20.0);
304 EXPECT_EQ(1920, supported_formats[4].frame_size.width());
305 EXPECT_EQ(1080, supported_formats[4].frame_size.height());
306 EXPECT_EQ(expected_format, supported_formats[4].pixel_format);
307 EXPECT_GE(supported_formats[4].frame_rate, 20.0);
294 } 308 }
295 } 309 }
296 310
297 TEST_F(FakeVideoCaptureDeviceTest, GetAndSetCapabilities) { 311 TEST_F(FakeVideoCaptureDeviceTest, GetAndSetCapabilities) {
298 std::unique_ptr<VideoCaptureDevice> device(new FakeVideoCaptureDevice( 312 std::unique_ptr<VideoCaptureDevice> device(new FakeVideoCaptureDevice(
299 FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS, 30.0)); 313 FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS, 30.0));
300 ASSERT_TRUE(device); 314 ASSERT_TRUE(device);
301 315
302 VideoCaptureParams capture_params; 316 VideoCaptureParams capture_params;
303 capture_params.requested_format.frame_size.SetSize(640, 480); 317 capture_params.requested_format.frame_size.SetSize(640, 480);
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
419 image_capture_client_)); 433 image_capture_client_));
420 434
421 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1); 435 EXPECT_CALL(*image_capture_client_.get(), OnCorrectPhotoTaken()).Times(1);
422 device->TakePhoto(std::move(scoped_callback)); 436 device->TakePhoto(std::move(scoped_callback));
423 437
424 run_loop_.reset(new base::RunLoop()); 438 run_loop_.reset(new base::RunLoop());
425 run_loop_->Run(); 439 run_loop_->Run();
426 device->StopAndDeAllocate(); 440 device->StopAndDeAllocate();
427 } 441 }
428 442
429 TEST_P(FakeVideoCaptureDeviceCommandLineTest, FrameRate) { 443 TEST_P(FakeVideoCaptureDeviceCommandLineTest, FrameRateAndDeviceCount) {
430 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 444 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
431 switches::kUseFakeDeviceForMediaStream, GetParam().argument); 445 switches::kUseFakeDeviceForMediaStream, GetParam().argument);
432 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors( 446 const std::unique_ptr<VideoCaptureDeviceDescriptors> descriptors(
433 EnumerateDevices()); 447 EnumerateDevices());
448 EXPECT_EQ(descriptors->size(), GetParam().device_count);
434 ASSERT_FALSE(descriptors->empty()); 449 ASSERT_FALSE(descriptors->empty());
435 450
436 for (const auto& descriptors_iterator : *descriptors) { 451 for (const auto& descriptors_iterator : *descriptors) {
437 std::unique_ptr<VideoCaptureDevice> device = 452 std::unique_ptr<VideoCaptureDevice> device =
438 video_capture_device_factory_->CreateDevice(descriptors_iterator); 453 video_capture_device_factory_->CreateDevice(descriptors_iterator);
439 ASSERT_TRUE(device); 454 ASSERT_TRUE(device);
440 455
441 VideoCaptureParams capture_params; 456 VideoCaptureParams capture_params;
442 capture_params.requested_format.frame_size.SetSize(1280, 720); 457 capture_params.requested_format.frame_size.SetSize(1280, 720);
443 capture_params.requested_format.frame_rate = GetParam().fps; 458 capture_params.requested_format.frame_rate = GetParam().fps;
444 device->AllocateAndStart(capture_params, std::move(client_)); 459 device->AllocateAndStart(capture_params, CreateClient());
445
446 WaitForCapturedFrame(); 460 WaitForCapturedFrame();
447 EXPECT_EQ(last_format().frame_size.width(), 1280); 461 EXPECT_EQ(last_format().frame_size.width(), 1280);
448 EXPECT_EQ(last_format().frame_size.height(), 720); 462 EXPECT_EQ(last_format().frame_size.height(), 720);
449 EXPECT_EQ(last_format().frame_rate, GetParam().fps); 463 EXPECT_EQ(last_format().frame_rate, GetParam().fps);
450 device->StopAndDeAllocate(); 464 device->StopAndDeAllocate();
451 } 465 }
452 } 466 }
453 467
454 INSTANTIATE_TEST_CASE_P(, 468 INSTANTIATE_TEST_CASE_P(
455 FakeVideoCaptureDeviceCommandLineTest, 469 ,
456 Values(CommandLineTestData{"fps=-1", 5}, 470 FakeVideoCaptureDeviceCommandLineTest,
457 CommandLineTestData{"fps=29.97", 29.97f}, 471 Values(CommandLineTestData{"fps=-1", 5, 1u},
458 CommandLineTestData{"fps=60", 60}, 472 CommandLineTestData{"fps=29.97, device-count=1", 29.97f, 1u},
459 CommandLineTestData{"fps=1000", 60})); 473 CommandLineTestData{"fps=60, device-count=2", 60, 2u},
474 CommandLineTestData{"fps=1000, device-count=-1", 60, 1u},
475 CommandLineTestData{"device-count=2", 20, 2u},
476 CommandLineTestData{"device-count=0", 20, 1u}));
460 }; // namespace media 477 }; // namespace media
OLDNEW
« no previous file with comments | « media/capture/video/fake_video_capture_device_factory.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698