| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/media/devices/devicemanager.h" | 11 #include "webrtc/media/devices/devicemanager.h" |
| 12 | 12 |
| 13 #ifdef WIN32 | 13 #ifdef WIN32 |
| 14 #include <objbase.h> | 14 #include <objbase.h> |
| 15 #include "webrtc/base/win32.h" | 15 #include "webrtc/base/win32.h" |
| 16 #endif | 16 #endif |
| 17 |
| 18 #include <memory> |
| 17 #include <string> | 19 #include <string> |
| 18 | 20 |
| 19 #include "webrtc/base/arraysize.h" | 21 #include "webrtc/base/arraysize.h" |
| 20 #include "webrtc/base/fileutils.h" | 22 #include "webrtc/base/fileutils.h" |
| 21 #include "webrtc/base/gunit.h" | 23 #include "webrtc/base/gunit.h" |
| 22 #include "webrtc/base/logging.h" | 24 #include "webrtc/base/logging.h" |
| 23 #include "webrtc/base/pathutils.h" | 25 #include "webrtc/base/pathutils.h" |
| 24 #include "webrtc/base/scoped_ptr.h" | |
| 25 #include "webrtc/base/stream.h" | 26 #include "webrtc/base/stream.h" |
| 26 #include "webrtc/base/windowpickerfactory.h" | 27 #include "webrtc/base/windowpickerfactory.h" |
| 27 #include "webrtc/media/base/fakevideocapturer.h" | 28 #include "webrtc/media/base/fakevideocapturer.h" |
| 28 #include "webrtc/media/base/screencastid.h" | 29 #include "webrtc/media/base/screencastid.h" |
| 29 #include "webrtc/media/base/testutils.h" | 30 #include "webrtc/media/base/testutils.h" |
| 30 #include "webrtc/media/base/videocapturerfactory.h" | 31 #include "webrtc/media/base/videocapturerfactory.h" |
| 31 #include "webrtc/media/devices/v4llookup.h" | 32 #include "webrtc/media/devices/v4llookup.h" |
| 32 | 33 |
| 33 #ifdef WEBRTC_LINUX | 34 #ifdef WEBRTC_LINUX |
| 34 // TODO(juberti): Figure out why this doesn't compile on Windows. | 35 // TODO(juberti): Figure out why this doesn't compile on Windows. |
| 35 #include "webrtc/base/fileutils_mock.h" | 36 #include "webrtc/base/fileutils_mock.h" |
| 36 #endif // WEBRTC_LINUX | 37 #endif // WEBRTC_LINUX |
| 37 | 38 |
| 38 using rtc::Pathname; | 39 using rtc::Pathname; |
| 39 using rtc::FileTimeType; | 40 using rtc::FileTimeType; |
| 40 using rtc::scoped_ptr; | |
| 41 using cricket::Device; | 41 using cricket::Device; |
| 42 using cricket::DeviceManager; | 42 using cricket::DeviceManager; |
| 43 using cricket::DeviceManagerFactory; | 43 using cricket::DeviceManagerFactory; |
| 44 using cricket::DeviceManagerInterface; | 44 using cricket::DeviceManagerInterface; |
| 45 | 45 |
| 46 const cricket::VideoFormat kVgaFormat(640, 480, | 46 const cricket::VideoFormat kVgaFormat(640, 480, |
| 47 cricket::VideoFormat::FpsToInterval(30), | 47 cricket::VideoFormat::FpsToInterval(30), |
| 48 cricket::FOURCC_I420); | 48 cricket::FOURCC_I420); |
| 49 const cricket::VideoFormat kHdFormat(1280, 720, | 49 const cricket::VideoFormat kHdFormat(1280, 720, |
| 50 cricket::VideoFormat::FpsToInterval(30), | 50 cricket::VideoFormat::FpsToInterval(30), |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 new FakeVideoDeviceCapturerFactory()); | 82 new FakeVideoDeviceCapturerFactory()); |
| 83 device_manager->SetScreenCapturerFactory( | 83 device_manager->SetScreenCapturerFactory( |
| 84 new FakeScreenCapturerFactory()); | 84 new FakeScreenCapturerFactory()); |
| 85 } | 85 } |
| 86 | 86 |
| 87 virtual void TearDown() { | 87 virtual void TearDown() { |
| 88 dm_->Terminate(); | 88 dm_->Terminate(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 protected: | 91 protected: |
| 92 scoped_ptr<DeviceManagerInterface> dm_; | 92 std::unique_ptr<DeviceManagerInterface> dm_; |
| 93 }; | 93 }; |
| 94 | 94 |
| 95 | 95 |
| 96 // Test that we startup/shutdown properly. | 96 // Test that we startup/shutdown properly. |
| 97 TEST(DeviceManagerTest, StartupShutdown) { | 97 TEST(DeviceManagerTest, StartupShutdown) { |
| 98 scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); | 98 std::unique_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); |
| 99 EXPECT_TRUE(dm->Init()); | 99 EXPECT_TRUE(dm->Init()); |
| 100 dm->Terminate(); | 100 dm->Terminate(); |
| 101 } | 101 } |
| 102 | 102 |
| 103 // Test CoInitEx behavior | 103 // Test CoInitEx behavior |
| 104 #ifdef WIN32 | 104 #ifdef WIN32 |
| 105 TEST(DeviceManagerTest, CoInitialize) { | 105 TEST(DeviceManagerTest, CoInitialize) { |
| 106 scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); | 106 std::unique_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); |
| 107 std::vector<Device> devices; | 107 std::vector<Device> devices; |
| 108 // Ensure that calls to video device work if COM is not yet initialized. | 108 // Ensure that calls to video device work if COM is not yet initialized. |
| 109 EXPECT_TRUE(dm->Init()); | 109 EXPECT_TRUE(dm->Init()); |
| 110 EXPECT_TRUE(dm->GetVideoCaptureDevices(&devices)); | 110 EXPECT_TRUE(dm->GetVideoCaptureDevices(&devices)); |
| 111 dm->Terminate(); | 111 dm->Terminate(); |
| 112 // Ensure that the ref count is correct. | 112 // Ensure that the ref count is correct. |
| 113 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED)); | 113 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED)); |
| 114 CoUninitialize(); | 114 CoUninitialize(); |
| 115 // Ensure that Init works in COINIT_APARTMENTTHREADED setting. | 115 // Ensure that Init works in COINIT_APARTMENTTHREADED setting. |
| 116 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)); | 116 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)); |
| 117 EXPECT_TRUE(dm->Init()); | 117 EXPECT_TRUE(dm->Init()); |
| 118 dm->Terminate(); | 118 dm->Terminate(); |
| 119 CoUninitialize(); | 119 CoUninitialize(); |
| 120 // Ensure that the ref count is correct. | 120 // Ensure that the ref count is correct. |
| 121 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)); | 121 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_APARTMENTTHREADED)); |
| 122 CoUninitialize(); | 122 CoUninitialize(); |
| 123 // Ensure that Init works in COINIT_MULTITHREADED setting. | 123 // Ensure that Init works in COINIT_MULTITHREADED setting. |
| 124 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED)); | 124 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED)); |
| 125 EXPECT_TRUE(dm->Init()); | 125 EXPECT_TRUE(dm->Init()); |
| 126 dm->Terminate(); | 126 dm->Terminate(); |
| 127 CoUninitialize(); | 127 CoUninitialize(); |
| 128 // Ensure that the ref count is correct. | 128 // Ensure that the ref count is correct. |
| 129 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED)); | 129 EXPECT_EQ(S_OK, CoInitializeEx(NULL, COINIT_MULTITHREADED)); |
| 130 CoUninitialize(); | 130 CoUninitialize(); |
| 131 } | 131 } |
| 132 #endif | 132 #endif |
| 133 | 133 |
| 134 // Test enumerating devices (although we may not find any). | 134 // Test enumerating devices (although we may not find any). |
| 135 TEST(DeviceManagerTest, GetDevices) { | 135 TEST(DeviceManagerTest, GetDevices) { |
| 136 scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); | 136 std::unique_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); |
| 137 std::vector<Device> audio_ins, audio_outs, video_ins; | 137 std::vector<Device> audio_ins, audio_outs, video_ins; |
| 138 std::vector<cricket::Device> video_in_devs; | 138 std::vector<cricket::Device> video_in_devs; |
| 139 cricket::Device def_video; | 139 cricket::Device def_video; |
| 140 EXPECT_TRUE(dm->Init()); | 140 EXPECT_TRUE(dm->Init()); |
| 141 EXPECT_TRUE(dm->GetAudioInputDevices(&audio_ins)); | 141 EXPECT_TRUE(dm->GetAudioInputDevices(&audio_ins)); |
| 142 EXPECT_TRUE(dm->GetAudioOutputDevices(&audio_outs)); | 142 EXPECT_TRUE(dm->GetAudioOutputDevices(&audio_outs)); |
| 143 EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_ins)); | 143 EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_ins)); |
| 144 EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_in_devs)); | 144 EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_in_devs)); |
| 145 EXPECT_EQ(video_ins.size(), video_in_devs.size()); | 145 EXPECT_EQ(video_ins.size(), video_in_devs.size()); |
| 146 // If we have any video devices, we should be able to pick a default. | 146 // If we have any video devices, we should be able to pick a default. |
| 147 EXPECT_TRUE(dm->GetVideoCaptureDevice( | 147 EXPECT_TRUE(dm->GetVideoCaptureDevice( |
| 148 cricket::DeviceManagerInterface::kDefaultDeviceName, &def_video) | 148 cricket::DeviceManagerInterface::kDefaultDeviceName, &def_video) |
| 149 != video_ins.empty()); | 149 != video_ins.empty()); |
| 150 } | 150 } |
| 151 | 151 |
| 152 // Test that we return correct ids for default and bogus devices. | 152 // Test that we return correct ids for default and bogus devices. |
| 153 TEST(DeviceManagerTest, GetAudioDeviceIds) { | 153 TEST(DeviceManagerTest, GetAudioDeviceIds) { |
| 154 scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); | 154 std::unique_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); |
| 155 Device device; | 155 Device device; |
| 156 EXPECT_TRUE(dm->Init()); | 156 EXPECT_TRUE(dm->Init()); |
| 157 EXPECT_TRUE(dm->GetAudioInputDevice( | 157 EXPECT_TRUE(dm->GetAudioInputDevice( |
| 158 cricket::DeviceManagerInterface::kDefaultDeviceName, &device)); | 158 cricket::DeviceManagerInterface::kDefaultDeviceName, &device)); |
| 159 EXPECT_EQ("-1", device.id); | 159 EXPECT_EQ("-1", device.id); |
| 160 EXPECT_TRUE(dm->GetAudioOutputDevice( | 160 EXPECT_TRUE(dm->GetAudioOutputDevice( |
| 161 cricket::DeviceManagerInterface::kDefaultDeviceName, &device)); | 161 cricket::DeviceManagerInterface::kDefaultDeviceName, &device)); |
| 162 EXPECT_EQ("-1", device.id); | 162 EXPECT_EQ("-1", device.id); |
| 163 EXPECT_FALSE(dm->GetAudioInputDevice("_NOT A REAL DEVICE_", &device)); | 163 EXPECT_FALSE(dm->GetAudioInputDevice("_NOT A REAL DEVICE_", &device)); |
| 164 EXPECT_FALSE(dm->GetAudioOutputDevice("_NOT A REAL DEVICE_", &device)); | 164 EXPECT_FALSE(dm->GetAudioOutputDevice("_NOT A REAL DEVICE_", &device)); |
| 165 } | 165 } |
| 166 | 166 |
| 167 // Test that we get the video capture device by name properly. | 167 // Test that we get the video capture device by name properly. |
| 168 TEST(DeviceManagerTest, GetVideoDeviceIds) { | 168 TEST(DeviceManagerTest, GetVideoDeviceIds) { |
| 169 scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); | 169 std::unique_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); |
| 170 Device device; | 170 Device device; |
| 171 EXPECT_TRUE(dm->Init()); | 171 EXPECT_TRUE(dm->Init()); |
| 172 EXPECT_FALSE(dm->GetVideoCaptureDevice("_NOT A REAL DEVICE_", &device)); | 172 EXPECT_FALSE(dm->GetVideoCaptureDevice("_NOT A REAL DEVICE_", &device)); |
| 173 std::vector<Device> video_ins; | 173 std::vector<Device> video_ins; |
| 174 EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_ins)); | 174 EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_ins)); |
| 175 if (!video_ins.empty()) { | 175 if (!video_ins.empty()) { |
| 176 // Get the default device with the parameter kDefaultDeviceName. | 176 // Get the default device with the parameter kDefaultDeviceName. |
| 177 EXPECT_TRUE(dm->GetVideoCaptureDevice( | 177 EXPECT_TRUE(dm->GetVideoCaptureDevice( |
| 178 cricket::DeviceManagerInterface::kDefaultDeviceName, &device)); | 178 cricket::DeviceManagerInterface::kDefaultDeviceName, &device)); |
| 179 | 179 |
| 180 // Get the first device with the parameter video_ins[0].name. | 180 // Get the first device with the parameter video_ins[0].name. |
| 181 EXPECT_TRUE(dm->GetVideoCaptureDevice(video_ins[0].name, &device)); | 181 EXPECT_TRUE(dm->GetVideoCaptureDevice(video_ins[0].name, &device)); |
| 182 EXPECT_EQ(device.name, video_ins[0].name); | 182 EXPECT_EQ(device.name, video_ins[0].name); |
| 183 EXPECT_EQ(device.id, video_ins[0].id); | 183 EXPECT_EQ(device.id, video_ins[0].id); |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 | 186 |
| 187 TEST(DeviceManagerTest, VerifyDevicesListsAreCleared) { | 187 TEST(DeviceManagerTest, VerifyDevicesListsAreCleared) { |
| 188 const std::string imaginary("_NOT A REAL DEVICE_"); | 188 const std::string imaginary("_NOT A REAL DEVICE_"); |
| 189 scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); | 189 std::unique_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); |
| 190 std::vector<Device> audio_ins, audio_outs, video_ins; | 190 std::vector<Device> audio_ins, audio_outs, video_ins; |
| 191 audio_ins.push_back(Device(imaginary, imaginary)); | 191 audio_ins.push_back(Device(imaginary, imaginary)); |
| 192 audio_outs.push_back(Device(imaginary, imaginary)); | 192 audio_outs.push_back(Device(imaginary, imaginary)); |
| 193 video_ins.push_back(Device(imaginary, imaginary)); | 193 video_ins.push_back(Device(imaginary, imaginary)); |
| 194 EXPECT_TRUE(dm->Init()); | 194 EXPECT_TRUE(dm->Init()); |
| 195 EXPECT_TRUE(dm->GetAudioInputDevices(&audio_ins)); | 195 EXPECT_TRUE(dm->GetAudioInputDevices(&audio_ins)); |
| 196 EXPECT_TRUE(dm->GetAudioOutputDevices(&audio_outs)); | 196 EXPECT_TRUE(dm->GetAudioOutputDevices(&audio_outs)); |
| 197 EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_ins)); | 197 EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_ins)); |
| 198 for (size_t i = 0; i < audio_ins.size(); ++i) { | 198 for (size_t i = 0; i < audio_ins.size(); ++i) { |
| 199 EXPECT_NE(imaginary, audio_ins[i].name); | 199 EXPECT_NE(imaginary, audio_ins[i].name); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 files.push_back(rtc::FakeFileSystem::File("/dev/video5", "")); | 284 files.push_back(rtc::FakeFileSystem::File("/dev/video5", "")); |
| 285 files.push_back(rtc::FakeFileSystem::File( | 285 files.push_back(rtc::FakeFileSystem::File( |
| 286 "/sys/class/video4linux/video0/name", "Video Device 1")); | 286 "/sys/class/video4linux/video0/name", "Video Device 1")); |
| 287 files.push_back(rtc::FakeFileSystem::File( | 287 files.push_back(rtc::FakeFileSystem::File( |
| 288 "/sys/class/video4linux/video1/model", "Bad Device")); | 288 "/sys/class/video4linux/video1/model", "Bad Device")); |
| 289 files.push_back( | 289 files.push_back( |
| 290 rtc::FakeFileSystem::File("/sys/class/video4linux/video5/model", | 290 rtc::FakeFileSystem::File("/sys/class/video4linux/video5/model", |
| 291 "Video Device 2")); | 291 "Video Device 2")); |
| 292 rtc::FilesystemScope fs(new rtc::FakeFileSystem(files)); | 292 rtc::FilesystemScope fs(new rtc::FakeFileSystem(files)); |
| 293 | 293 |
| 294 scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); | 294 std::unique_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); |
| 295 std::vector<Device> video_ins; | 295 std::vector<Device> video_ins; |
| 296 EXPECT_TRUE(dm->Init()); | 296 EXPECT_TRUE(dm->Init()); |
| 297 EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_ins)); | 297 EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_ins)); |
| 298 EXPECT_EQ(2u, video_ins.size()); | 298 EXPECT_EQ(2u, video_ins.size()); |
| 299 EXPECT_EQ("Video Device 1", video_ins.at(0).name); | 299 EXPECT_EQ("Video Device 1", video_ins.at(0).name); |
| 300 EXPECT_EQ("Video Device 2", video_ins.at(1).name); | 300 EXPECT_EQ("Video Device 2", video_ins.at(1).name); |
| 301 } | 301 } |
| 302 | 302 |
| 303 TEST(DeviceManagerTest, GetVideoCaptureDevices_K2_4) { | 303 TEST(DeviceManagerTest, GetVideoCaptureDevices_K2_4) { |
| 304 std::vector<std::string> devices; | 304 std::vector<std::string> devices; |
| 305 devices.push_back("/dev/video0"); | 305 devices.push_back("/dev/video0"); |
| 306 devices.push_back("/dev/video5"); | 306 devices.push_back("/dev/video5"); |
| 307 cricket::V4LLookup::SetV4LLookup(new FakeV4LLookup(devices)); | 307 cricket::V4LLookup::SetV4LLookup(new FakeV4LLookup(devices)); |
| 308 | 308 |
| 309 std::vector<rtc::FakeFileSystem::File> files; | 309 std::vector<rtc::FakeFileSystem::File> files; |
| 310 files.push_back(rtc::FakeFileSystem::File("/dev/video0", "")); | 310 files.push_back(rtc::FakeFileSystem::File("/dev/video0", "")); |
| 311 files.push_back(rtc::FakeFileSystem::File("/dev/video5", "")); | 311 files.push_back(rtc::FakeFileSystem::File("/dev/video5", "")); |
| 312 files.push_back(rtc::FakeFileSystem::File( | 312 files.push_back(rtc::FakeFileSystem::File( |
| 313 "/proc/video/dev/video0", | 313 "/proc/video/dev/video0", |
| 314 "param1: value1\nname: Video Device 1\n param2: value2\n")); | 314 "param1: value1\nname: Video Device 1\n param2: value2\n")); |
| 315 files.push_back(rtc::FakeFileSystem::File( | 315 files.push_back(rtc::FakeFileSystem::File( |
| 316 "/proc/video/dev/video1", | 316 "/proc/video/dev/video1", |
| 317 "param1: value1\nname: Bad Device\n param2: value2\n")); | 317 "param1: value1\nname: Bad Device\n param2: value2\n")); |
| 318 files.push_back(rtc::FakeFileSystem::File( | 318 files.push_back(rtc::FakeFileSystem::File( |
| 319 "/proc/video/dev/video5", | 319 "/proc/video/dev/video5", |
| 320 "param1: value1\nname: Video Device 2\n param2: value2\n")); | 320 "param1: value1\nname: Video Device 2\n param2: value2\n")); |
| 321 rtc::FilesystemScope fs(new rtc::FakeFileSystem(files)); | 321 rtc::FilesystemScope fs(new rtc::FakeFileSystem(files)); |
| 322 | 322 |
| 323 scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); | 323 std::unique_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); |
| 324 std::vector<Device> video_ins; | 324 std::vector<Device> video_ins; |
| 325 EXPECT_TRUE(dm->Init()); | 325 EXPECT_TRUE(dm->Init()); |
| 326 EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_ins)); | 326 EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_ins)); |
| 327 EXPECT_EQ(2u, video_ins.size()); | 327 EXPECT_EQ(2u, video_ins.size()); |
| 328 EXPECT_EQ("Video Device 1", video_ins.at(0).name); | 328 EXPECT_EQ("Video Device 1", video_ins.at(0).name); |
| 329 EXPECT_EQ("Video Device 2", video_ins.at(1).name); | 329 EXPECT_EQ("Video Device 2", video_ins.at(1).name); |
| 330 } | 330 } |
| 331 | 331 |
| 332 TEST(DeviceManagerTest, GetVideoCaptureDevices_KUnknown) { | 332 TEST(DeviceManagerTest, GetVideoCaptureDevices_KUnknown) { |
| 333 std::vector<std::string> devices; | 333 std::vector<std::string> devices; |
| 334 devices.push_back("/dev/video0"); | 334 devices.push_back("/dev/video0"); |
| 335 devices.push_back("/dev/video5"); | 335 devices.push_back("/dev/video5"); |
| 336 cricket::V4LLookup::SetV4LLookup(new FakeV4LLookup(devices)); | 336 cricket::V4LLookup::SetV4LLookup(new FakeV4LLookup(devices)); |
| 337 | 337 |
| 338 std::vector<rtc::FakeFileSystem::File> files; | 338 std::vector<rtc::FakeFileSystem::File> files; |
| 339 files.push_back(rtc::FakeFileSystem::File("/dev/video0", "")); | 339 files.push_back(rtc::FakeFileSystem::File("/dev/video0", "")); |
| 340 files.push_back(rtc::FakeFileSystem::File("/dev/video1", "")); | 340 files.push_back(rtc::FakeFileSystem::File("/dev/video1", "")); |
| 341 files.push_back(rtc::FakeFileSystem::File("/dev/video5", "")); | 341 files.push_back(rtc::FakeFileSystem::File("/dev/video5", "")); |
| 342 rtc::FilesystemScope fs(new rtc::FakeFileSystem(files)); | 342 rtc::FilesystemScope fs(new rtc::FakeFileSystem(files)); |
| 343 | 343 |
| 344 scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); | 344 std::unique_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); |
| 345 std::vector<Device> video_ins; | 345 std::vector<Device> video_ins; |
| 346 EXPECT_TRUE(dm->Init()); | 346 EXPECT_TRUE(dm->Init()); |
| 347 EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_ins)); | 347 EXPECT_TRUE(dm->GetVideoCaptureDevices(&video_ins)); |
| 348 EXPECT_EQ(2u, video_ins.size()); | 348 EXPECT_EQ(2u, video_ins.size()); |
| 349 EXPECT_EQ("/dev/video0", video_ins.at(0).name); | 349 EXPECT_EQ("/dev/video0", video_ins.at(0).name); |
| 350 EXPECT_EQ("/dev/video5", video_ins.at(1).name); | 350 EXPECT_EQ("/dev/video5", video_ins.at(1).name); |
| 351 } | 351 } |
| 352 #endif // WEBRTC_LINUX | 352 #endif // WEBRTC_LINUX |
| 353 | 353 |
| 354 // TODO(noahric): These are flaky on windows on headless machines. | 354 // TODO(noahric): These are flaky on windows on headless machines. |
| 355 #ifndef WIN32 | 355 #ifndef WIN32 |
| 356 TEST(DeviceManagerTest, GetWindows) { | 356 TEST(DeviceManagerTest, GetWindows) { |
| 357 if (!rtc::WindowPickerFactory::IsSupported()) { | 357 if (!rtc::WindowPickerFactory::IsSupported()) { |
| 358 LOG(LS_INFO) << "skipping test: window capturing is not supported with " | 358 LOG(LS_INFO) << "skipping test: window capturing is not supported with " |
| 359 << "current configuration."; | 359 << "current configuration."; |
| 360 return; | 360 return; |
| 361 } | 361 } |
| 362 scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); | 362 std::unique_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); |
| 363 dm->SetScreenCapturerFactory(new FakeScreenCapturerFactory()); | 363 dm->SetScreenCapturerFactory(new FakeScreenCapturerFactory()); |
| 364 std::vector<rtc::WindowDescription> descriptions; | 364 std::vector<rtc::WindowDescription> descriptions; |
| 365 EXPECT_TRUE(dm->Init()); | 365 EXPECT_TRUE(dm->Init()); |
| 366 if (!dm->GetWindows(&descriptions) || descriptions.empty()) { | 366 if (!dm->GetWindows(&descriptions) || descriptions.empty()) { |
| 367 LOG(LS_INFO) << "skipping test: window capturing. Does not have any " | 367 LOG(LS_INFO) << "skipping test: window capturing. Does not have any " |
| 368 << "windows to capture."; | 368 << "windows to capture."; |
| 369 return; | 369 return; |
| 370 } | 370 } |
| 371 scoped_ptr<cricket::VideoCapturer> capturer(dm->CreateScreenCapturer( | 371 std::unique_ptr<cricket::VideoCapturer> capturer(dm->CreateScreenCapturer( |
| 372 cricket::ScreencastId(descriptions.front().id()))); | 372 cricket::ScreencastId(descriptions.front().id()))); |
| 373 EXPECT_FALSE(capturer.get() == NULL); | 373 EXPECT_FALSE(capturer.get() == NULL); |
| 374 // TODO(hellner): creating a window capturer and immediately deleting it | 374 // TODO(hellner): creating a window capturer and immediately deleting it |
| 375 // results in "Continuous Build and Test Mainline - Mac opt" failure (crash). | 375 // results in "Continuous Build and Test Mainline - Mac opt" failure (crash). |
| 376 // Remove the following line as soon as this has been resolved. | 376 // Remove the following line as soon as this has been resolved. |
| 377 rtc::Thread::Current()->ProcessMessages(1); | 377 rtc::Thread::Current()->ProcessMessages(1); |
| 378 } | 378 } |
| 379 | 379 |
| 380 TEST(DeviceManagerTest, GetDesktops) { | 380 TEST(DeviceManagerTest, GetDesktops) { |
| 381 if (!rtc::WindowPickerFactory::IsSupported()) { | 381 if (!rtc::WindowPickerFactory::IsSupported()) { |
| 382 LOG(LS_INFO) << "skipping test: desktop capturing is not supported with " | 382 LOG(LS_INFO) << "skipping test: desktop capturing is not supported with " |
| 383 << "current configuration."; | 383 << "current configuration."; |
| 384 return; | 384 return; |
| 385 } | 385 } |
| 386 scoped_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); | 386 std::unique_ptr<DeviceManagerInterface> dm(DeviceManagerFactory::Create()); |
| 387 dm->SetScreenCapturerFactory(new FakeScreenCapturerFactory()); | 387 dm->SetScreenCapturerFactory(new FakeScreenCapturerFactory()); |
| 388 std::vector<rtc::DesktopDescription> descriptions; | 388 std::vector<rtc::DesktopDescription> descriptions; |
| 389 EXPECT_TRUE(dm->Init()); | 389 EXPECT_TRUE(dm->Init()); |
| 390 if (!dm->GetDesktops(&descriptions) || descriptions.empty()) { | 390 if (!dm->GetDesktops(&descriptions) || descriptions.empty()) { |
| 391 LOG(LS_INFO) << "skipping test: desktop capturing. Does not have any " | 391 LOG(LS_INFO) << "skipping test: desktop capturing. Does not have any " |
| 392 << "desktops to capture."; | 392 << "desktops to capture."; |
| 393 return; | 393 return; |
| 394 } | 394 } |
| 395 scoped_ptr<cricket::VideoCapturer> capturer(dm->CreateScreenCapturer( | 395 std::unique_ptr<cricket::VideoCapturer> capturer(dm->CreateScreenCapturer( |
| 396 cricket::ScreencastId(descriptions.front().id()))); | 396 cricket::ScreencastId(descriptions.front().id()))); |
| 397 EXPECT_FALSE(capturer.get() == NULL); | 397 EXPECT_FALSE(capturer.get() == NULL); |
| 398 } | 398 } |
| 399 #endif // !WIN32 | 399 #endif // !WIN32 |
| 400 | 400 |
| 401 TEST_F(DeviceManagerTestFake, CaptureConstraintsWhitelisted) { | 401 TEST_F(DeviceManagerTestFake, CaptureConstraintsWhitelisted) { |
| 402 const Device device("white", "white_id"); | 402 const Device device("white", "white_id"); |
| 403 dm_->SetVideoCaptureDeviceMaxFormat(device.name, kHdFormat); | 403 dm_->SetVideoCaptureDeviceMaxFormat(device.name, kHdFormat); |
| 404 scoped_ptr<cricket::VideoCapturer> capturer( | 404 std::unique_ptr<cricket::VideoCapturer> capturer( |
| 405 dm_->CreateVideoCapturer(device)); | 405 dm_->CreateVideoCapturer(device)); |
| 406 cricket::VideoFormat best_format; | 406 cricket::VideoFormat best_format; |
| 407 capturer->set_enable_camera_list(true); | 407 capturer->set_enable_camera_list(true); |
| 408 EXPECT_TRUE(capturer->GetBestCaptureFormat(kHdFormat, &best_format)); | 408 EXPECT_TRUE(capturer->GetBestCaptureFormat(kHdFormat, &best_format)); |
| 409 EXPECT_EQ(kHdFormat, best_format); | 409 EXPECT_EQ(kHdFormat, best_format); |
| 410 } | 410 } |
| 411 | 411 |
| 412 TEST_F(DeviceManagerTestFake, CaptureConstraintsNotWhitelisted) { | 412 TEST_F(DeviceManagerTestFake, CaptureConstraintsNotWhitelisted) { |
| 413 const Device device("regular", "regular_id"); | 413 const Device device("regular", "regular_id"); |
| 414 scoped_ptr<cricket::VideoCapturer> capturer( | 414 std::unique_ptr<cricket::VideoCapturer> capturer( |
| 415 dm_->CreateVideoCapturer(device)); | 415 dm_->CreateVideoCapturer(device)); |
| 416 cricket::VideoFormat best_format; | 416 cricket::VideoFormat best_format; |
| 417 capturer->set_enable_camera_list(true); | 417 capturer->set_enable_camera_list(true); |
| 418 EXPECT_TRUE(capturer->GetBestCaptureFormat(kHdFormat, &best_format)); | 418 EXPECT_TRUE(capturer->GetBestCaptureFormat(kHdFormat, &best_format)); |
| 419 EXPECT_EQ(kHdFormat, best_format); | 419 EXPECT_EQ(kHdFormat, best_format); |
| 420 } | 420 } |
| 421 | 421 |
| 422 TEST_F(DeviceManagerTestFake, CaptureConstraintsUnWhitelisted) { | 422 TEST_F(DeviceManagerTestFake, CaptureConstraintsUnWhitelisted) { |
| 423 const Device device("un_white", "un_white_id"); | 423 const Device device("un_white", "un_white_id"); |
| 424 dm_->SetVideoCaptureDeviceMaxFormat(device.name, kHdFormat); | 424 dm_->SetVideoCaptureDeviceMaxFormat(device.name, kHdFormat); |
| 425 dm_->ClearVideoCaptureDeviceMaxFormat(device.name); | 425 dm_->ClearVideoCaptureDeviceMaxFormat(device.name); |
| 426 scoped_ptr<cricket::VideoCapturer> capturer( | 426 std::unique_ptr<cricket::VideoCapturer> capturer( |
| 427 dm_->CreateVideoCapturer(device)); | 427 dm_->CreateVideoCapturer(device)); |
| 428 cricket::VideoFormat best_format; | 428 cricket::VideoFormat best_format; |
| 429 capturer->set_enable_camera_list(true); | 429 capturer->set_enable_camera_list(true); |
| 430 EXPECT_TRUE(capturer->GetBestCaptureFormat(kHdFormat, &best_format)); | 430 EXPECT_TRUE(capturer->GetBestCaptureFormat(kHdFormat, &best_format)); |
| 431 EXPECT_EQ(kHdFormat, best_format); | 431 EXPECT_EQ(kHdFormat, best_format); |
| 432 } | 432 } |
| 433 | 433 |
| 434 TEST_F(DeviceManagerTestFake, CaptureConstraintsWildcard) { | 434 TEST_F(DeviceManagerTestFake, CaptureConstraintsWildcard) { |
| 435 const Device device("any_device", "any_device"); | 435 const Device device("any_device", "any_device"); |
| 436 dm_->SetVideoCaptureDeviceMaxFormat("*", kHdFormat); | 436 dm_->SetVideoCaptureDeviceMaxFormat("*", kHdFormat); |
| 437 scoped_ptr<cricket::VideoCapturer> capturer( | 437 std::unique_ptr<cricket::VideoCapturer> capturer( |
| 438 dm_->CreateVideoCapturer(device)); | 438 dm_->CreateVideoCapturer(device)); |
| 439 cricket::VideoFormat best_format; | 439 cricket::VideoFormat best_format; |
| 440 capturer->set_enable_camera_list(true); | 440 capturer->set_enable_camera_list(true); |
| 441 EXPECT_TRUE(capturer->GetBestCaptureFormat(kHdFormat, &best_format)); | 441 EXPECT_TRUE(capturer->GetBestCaptureFormat(kHdFormat, &best_format)); |
| 442 EXPECT_EQ(kHdFormat, best_format); | 442 EXPECT_EQ(kHdFormat, best_format); |
| 443 } | 443 } |
| OLD | NEW |