| 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 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 : frame_cb_(frame_cb) {} | 68 : frame_cb_(frame_cb) {} |
| 69 | 69 |
| 70 // Client virtual methods for capturing using Device Buffers. | 70 // Client virtual methods for capturing using Device Buffers. |
| 71 void OnIncomingCapturedData(const uint8_t* data, | 71 void OnIncomingCapturedData(const uint8_t* data, |
| 72 int length, | 72 int length, |
| 73 const VideoCaptureFormat& format, | 73 const VideoCaptureFormat& format, |
| 74 int rotation, | 74 int rotation, |
| 75 const base::TimeTicks& timestamp) { | 75 const base::TimeTicks& timestamp) { |
| 76 frame_cb_.Run(format); | 76 frame_cb_.Run(format); |
| 77 } | 77 } |
| 78 void OnIncomingCapturedYuvData(const uint8_t* y_data, | |
| 79 const uint8_t* u_data, | |
| 80 const uint8_t* v_data, | |
| 81 size_t y_stride, | |
| 82 size_t u_stride, | |
| 83 size_t v_stride, | |
| 84 const VideoCaptureFormat& frame_format, | |
| 85 int clockwise_rotation, | |
| 86 const base::TimeTicks& timestamp) { | |
| 87 frame_cb_.Run(frame_format); | |
| 88 } | |
| 89 | |
| 90 // Virtual methods for capturing using Client's Buffers. | 78 // Virtual methods for capturing using Client's Buffers. |
| 91 scoped_ptr<Buffer> ReserveOutputBuffer(const gfx::Size& dimensions, | 79 scoped_ptr<Buffer> ReserveOutputBuffer(const gfx::Size& dimensions, |
| 92 media::VideoPixelFormat format, | 80 media::VideoPixelFormat format, |
| 93 media::VideoPixelStorage storage) { | 81 media::VideoPixelStorage storage) { |
| 94 EXPECT_TRUE((format == media::PIXEL_FORMAT_ARGB && | 82 EXPECT_TRUE((format == media::PIXEL_FORMAT_ARGB && |
| 95 storage == media::PIXEL_STORAGE_CPU) || | 83 storage == media::PIXEL_STORAGE_CPU) || |
| 96 (format == media::PIXEL_FORMAT_I420 && | 84 (format == media::PIXEL_FORMAT_I420 && |
| 97 storage == media::PIXEL_STORAGE_GPUMEMORYBUFFER)); | 85 storage == media::PIXEL_STORAGE_GPUMEMORYBUFFER)); |
| 98 EXPECT_GT(dimensions.GetArea(), 0); | 86 EXPECT_GT(dimensions.GetArea(), 0); |
| 99 const VideoCaptureFormat frame_format(dimensions, 0.0, format); | 87 const VideoCaptureFormat frame_format(dimensions, 0.0, format); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 scoped_ptr<base::RunLoop> run_loop_; | 168 scoped_ptr<base::RunLoop> run_loop_; |
| 181 scoped_ptr<MockClient> client_; | 169 scoped_ptr<MockClient> client_; |
| 182 scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_; | 170 scoped_refptr<DeviceEnumerationListener> device_enumeration_listener_; |
| 183 VideoCaptureFormat last_format_; | 171 VideoCaptureFormat last_format_; |
| 184 const scoped_ptr<VideoCaptureDeviceFactory> video_capture_device_factory_; | 172 const scoped_ptr<VideoCaptureDeviceFactory> video_capture_device_factory_; |
| 185 }; | 173 }; |
| 186 | 174 |
| 187 class FakeVideoCaptureDeviceTest | 175 class FakeVideoCaptureDeviceTest |
| 188 : public FakeVideoCaptureDeviceBase, | 176 : public FakeVideoCaptureDeviceBase, |
| 189 public ::testing::WithParamInterface< | 177 public ::testing::WithParamInterface< |
| 190 ::testing::tuple<FakeVideoCaptureDevice::BufferOwnership, | 178 ::testing::tuple<FakeVideoCaptureDevice::BufferOwnership, float>> {}; |
| 191 FakeVideoCaptureDevice::BufferPlanarity, | |
| 192 float>> {}; | |
| 193 | 179 |
| 194 struct CommandLineTestData { | 180 struct CommandLineTestData { |
| 195 // Command line argument | 181 // Command line argument |
| 196 std::string argument; | 182 std::string argument; |
| 197 // Expected values | 183 // Expected values |
| 198 float fps; | 184 float fps; |
| 199 }; | 185 }; |
| 200 | 186 |
| 201 class FakeVideoCaptureDeviceCommandLineTest | 187 class FakeVideoCaptureDeviceCommandLineTest |
| 202 : public FakeVideoCaptureDeviceBase, | 188 : public FakeVideoCaptureDeviceBase, |
| 203 public ::testing::WithParamInterface<CommandLineTestData> {}; | 189 public ::testing::WithParamInterface<CommandLineTestData> {}; |
| 204 | 190 |
| 205 TEST_P(FakeVideoCaptureDeviceTest, CaptureUsing) { | 191 TEST_P(FakeVideoCaptureDeviceTest, CaptureUsing) { |
| 206 const scoped_ptr<VideoCaptureDevice::Names> names(EnumerateDevices()); | 192 const scoped_ptr<VideoCaptureDevice::Names> names(EnumerateDevices()); |
| 207 ASSERT_FALSE(names->empty()); | 193 ASSERT_FALSE(names->empty()); |
| 208 | 194 |
| 209 scoped_ptr<VideoCaptureDevice> device(new FakeVideoCaptureDevice( | 195 scoped_ptr<VideoCaptureDevice> device(new FakeVideoCaptureDevice( |
| 210 testing::get<0>(GetParam()), testing::get<1>(GetParam()), | 196 testing::get<0>(GetParam()), testing::get<1>(GetParam()))); |
| 211 testing::get<2>(GetParam()))); | |
| 212 ASSERT_TRUE(device); | 197 ASSERT_TRUE(device); |
| 213 | 198 |
| 214 VideoCaptureParams capture_params; | 199 VideoCaptureParams capture_params; |
| 215 capture_params.requested_format.frame_size.SetSize(640, 480); | 200 capture_params.requested_format.frame_size.SetSize(640, 480); |
| 216 capture_params.requested_format.frame_rate = testing::get<2>(GetParam()); | 201 capture_params.requested_format.frame_rate = testing::get<1>(GetParam()); |
| 217 device->AllocateAndStart(capture_params, std::move(client_)); | 202 device->AllocateAndStart(capture_params, std::move(client_)); |
| 218 | 203 |
| 219 WaitForCapturedFrame(); | 204 WaitForCapturedFrame(); |
| 220 EXPECT_EQ(last_format().frame_size.width(), 640); | 205 EXPECT_EQ(last_format().frame_size.width(), 640); |
| 221 EXPECT_EQ(last_format().frame_size.height(), 480); | 206 EXPECT_EQ(last_format().frame_size.height(), 480); |
| 222 EXPECT_EQ(last_format().frame_rate, testing::get<2>(GetParam())); | 207 EXPECT_EQ(last_format().frame_rate, testing::get<1>(GetParam())); |
| 223 device->StopAndDeAllocate(); | 208 device->StopAndDeAllocate(); |
| 224 } | 209 } |
| 225 | 210 |
| 226 INSTANTIATE_TEST_CASE_P( | 211 INSTANTIATE_TEST_CASE_P( |
| 227 , | 212 , |
| 228 FakeVideoCaptureDeviceTest, | 213 FakeVideoCaptureDeviceTest, |
| 229 Combine(Values(FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS, | 214 Combine(Values(FakeVideoCaptureDevice::BufferOwnership::OWN_BUFFERS, |
| 230 FakeVideoCaptureDevice::BufferOwnership::CLIENT_BUFFERS), | 215 FakeVideoCaptureDevice::BufferOwnership::CLIENT_BUFFERS), |
| 231 Values(FakeVideoCaptureDevice::BufferPlanarity::PACKED, | |
| 232 FakeVideoCaptureDevice::BufferPlanarity::TRIPLANAR), | |
| 233 Values(20, 29.97, 30, 50, 60))); | 216 Values(20, 29.97, 30, 50, 60))); |
| 234 | 217 |
| 235 TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { | 218 TEST_F(FakeVideoCaptureDeviceTest, GetDeviceSupportedFormats) { |
| 236 scoped_ptr<VideoCaptureDevice::Names> names(EnumerateDevices()); | 219 scoped_ptr<VideoCaptureDevice::Names> names(EnumerateDevices()); |
| 237 | 220 |
| 238 VideoCaptureFormats supported_formats; | 221 VideoCaptureFormats supported_formats; |
| 239 | 222 |
| 240 for (const auto& names_iterator : *names) { | 223 for (const auto& names_iterator : *names) { |
| 241 video_capture_device_factory_->GetDeviceSupportedFormats( | 224 video_capture_device_factory_->GetDeviceSupportedFormats( |
| 242 names_iterator, &supported_formats); | 225 names_iterator, &supported_formats); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 } | 267 } |
| 285 } | 268 } |
| 286 | 269 |
| 287 INSTANTIATE_TEST_CASE_P(, | 270 INSTANTIATE_TEST_CASE_P(, |
| 288 FakeVideoCaptureDeviceCommandLineTest, | 271 FakeVideoCaptureDeviceCommandLineTest, |
| 289 Values(CommandLineTestData{"fps=-1", 5}, | 272 Values(CommandLineTestData{"fps=-1", 5}, |
| 290 CommandLineTestData{"fps=29.97", 29.97f}, | 273 CommandLineTestData{"fps=29.97", 29.97f}, |
| 291 CommandLineTestData{"fps=60", 60}, | 274 CommandLineTestData{"fps=60", 60}, |
| 292 CommandLineTestData{"fps=1000", 60})); | 275 CommandLineTestData{"fps=1000", 60})); |
| 293 }; // namespace media | 276 }; // namespace media |
| OLD | NEW |