| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/message_loop.h" | 6 #include "base/message_loop.h" |
| 7 #include "base/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
| 8 #include "base/test/test_timeouts.h" | 8 #include "base/test/test_timeouts.h" |
| 9 #include "base/threading/thread.h" | 9 #include "base/threading/thread.h" |
| 10 #include "media/video/capture/fake_video_capture_device.h" | 10 #include "media/video/capture/fake_video_capture_device.h" |
| 11 #include "media/video/capture/video_capture_device.h" | 11 #include "media/video/capture/video_capture_device.h" |
| 12 #include "media/video/capture/video_capture_types.h" | 12 #include "media/video/capture/video_capture_types.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 | 15 |
| 16 #if defined(OS_WIN) | 16 #if defined(OS_WIN) |
| 17 #include "base/win/scoped_com_initializer.h" | 17 #include "base/win/scoped_com_initializer.h" |
| 18 #include "base/win/windows_version.h" |
| 18 #endif | 19 #endif |
| 19 | 20 |
| 20 #if defined(OS_ANDROID) | 21 #if defined(OS_ANDROID) |
| 21 #include "base/android/jni_android.h" | 22 #include "base/android/jni_android.h" |
| 22 #include "media/video/capture/android/video_capture_device_android.h" | 23 #include "media/video/capture/android/video_capture_device_android.h" |
| 23 #endif | 24 #endif |
| 24 | 25 |
| 25 #if defined(OS_MACOSX) | 26 #if defined(OS_MACOSX) |
| 26 // Mac/QTKit will always give you the size you ask for and this case will fail. | 27 // Mac/QTKit will always give you the size you ask for and this case will fail. |
| 27 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize | 28 #define MAYBE_AllocateBadSize DISABLED_AllocateBadSize |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 #if defined(OS_WIN) | 121 #if defined(OS_WIN) |
| 121 base::win::ScopedCOMInitializer initialize_com_; | 122 base::win::ScopedCOMInitializer initialize_com_; |
| 122 #endif | 123 #endif |
| 123 base::WaitableEvent wait_event_; | 124 base::WaitableEvent wait_event_; |
| 124 scoped_ptr<MockFrameObserver> frame_observer_; | 125 scoped_ptr<MockFrameObserver> frame_observer_; |
| 125 VideoCaptureDevice::Names names_; | 126 VideoCaptureDevice::Names names_; |
| 126 scoped_ptr<base::MessageLoop> loop_; | 127 scoped_ptr<base::MessageLoop> loop_; |
| 127 }; | 128 }; |
| 128 | 129 |
| 129 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { | 130 TEST_F(VideoCaptureDeviceTest, OpenInvalidDevice) { |
| 131 #if defined(OS_WIN) |
| 132 VideoCaptureDevice::Name::CaptureApiType api_type = |
| 133 (base::win::GetVersion() < base::win::VERSION_WIN7) |
| 134 ? VideoCaptureDevice::Name::DIRECT_SHOW |
| 135 : VideoCaptureDevice::Name::MEDIA_FOUNDATION; |
| 136 VideoCaptureDevice::Name device_name("jibberish", "jibberish", api_type); |
| 137 #else |
| 130 VideoCaptureDevice::Name device_name("jibberish", "jibberish"); | 138 VideoCaptureDevice::Name device_name("jibberish", "jibberish"); |
| 139 #endif |
| 131 VideoCaptureDevice* device = VideoCaptureDevice::Create(device_name); | 140 VideoCaptureDevice* device = VideoCaptureDevice::Create(device_name); |
| 132 EXPECT_TRUE(device == NULL); | 141 EXPECT_TRUE(device == NULL); |
| 133 } | 142 } |
| 134 | 143 |
| 135 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { | 144 TEST_F(VideoCaptureDeviceTest, CaptureVGA) { |
| 136 VideoCaptureDevice::GetDeviceNames(&names_); | 145 VideoCaptureDevice::GetDeviceNames(&names_); |
| 137 if (!names_.size()) { | 146 if (!names_.size()) { |
| 138 DVLOG(1) << "No camera available. Exiting test."; | 147 DVLOG(1) << "No camera available. Exiting test."; |
| 139 return; | 148 return; |
| 140 } | 149 } |
| 141 | 150 |
| 142 scoped_ptr<VideoCaptureDevice> device( | 151 scoped_ptr<VideoCaptureDevice> device( |
| 143 VideoCaptureDevice::Create(names_.front())); | 152 VideoCaptureDevice::Create(names_.front())); |
| 144 ASSERT_FALSE(device.get() == NULL); | 153 ASSERT_FALSE(device.get() == NULL); |
| 145 | 154 |
| 146 // Get info about the new resolution. | 155 // Get info about the new resolution. |
| 147 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30, _)) | 156 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, _, _)) |
| 148 .Times(1); | 157 .Times(1); |
| 149 | 158 |
| 150 EXPECT_CALL(*frame_observer_, OnErr()) | 159 EXPECT_CALL(*frame_observer_, OnErr()) |
| 151 .Times(0); | 160 .Times(0); |
| 152 | 161 |
| 153 device->Allocate(640, 480, 30, frame_observer_.get()); | 162 device->Allocate(640, 480, 30, frame_observer_.get()); |
| 154 device->Start(); | 163 device->Start(); |
| 155 // Get captured video frames. | 164 // Get captured video frames. |
| 156 PostQuitTask(); | 165 PostQuitTask(); |
| 157 EXPECT_TRUE(wait_event_.TimedWait(TestTimeouts::action_max_timeout())); | 166 EXPECT_TRUE(wait_event_.TimedWait(TestTimeouts::action_max_timeout())); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 DVLOG(1) << "No camera available. Exiting test."; | 256 DVLOG(1) << "No camera available. Exiting test."; |
| 248 return; | 257 return; |
| 249 } | 258 } |
| 250 scoped_ptr<VideoCaptureDevice> device( | 259 scoped_ptr<VideoCaptureDevice> device( |
| 251 VideoCaptureDevice::Create(names_.front())); | 260 VideoCaptureDevice::Create(names_.front())); |
| 252 ASSERT_TRUE(device.get() != NULL); | 261 ASSERT_TRUE(device.get() != NULL); |
| 253 | 262 |
| 254 EXPECT_CALL(*frame_observer_, OnErr()) | 263 EXPECT_CALL(*frame_observer_, OnErr()) |
| 255 .Times(0); | 264 .Times(0); |
| 256 // Get info about the new resolution. | 265 // Get info about the new resolution. |
| 257 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 30, _)); | 266 EXPECT_CALL(*frame_observer_, OnFrameInfo(640, 480, 15, _)); |
| 258 | 267 |
| 259 device->Allocate(640, 480, 30, frame_observer_.get()); | 268 device->Allocate(640, 480, 30, frame_observer_.get()); |
| 260 | 269 |
| 261 device->Start(); | 270 device->Start(); |
| 262 // Get captured video frames. | 271 // Get captured video frames. |
| 263 PostQuitTask(); | 272 PostQuitTask(); |
| 264 EXPECT_TRUE(wait_event_.TimedWait(TestTimeouts::action_max_timeout())); | 273 EXPECT_TRUE(wait_event_.TimedWait(TestTimeouts::action_max_timeout())); |
| 265 device->DeAllocate(); | 274 device->DeAllocate(); |
| 266 } | 275 } |
| 267 | 276 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 device->Allocate(1280, 720, 30, frame_observer_.get()); | 321 device->Allocate(1280, 720, 30, frame_observer_.get()); |
| 313 | 322 |
| 314 device->Start(); | 323 device->Start(); |
| 315 // Get captured video frames. | 324 // Get captured video frames. |
| 316 PostQuitTask(); | 325 PostQuitTask(); |
| 317 EXPECT_TRUE(wait_event_.TimedWait(TestTimeouts::action_max_timeout())); | 326 EXPECT_TRUE(wait_event_.TimedWait(TestTimeouts::action_max_timeout())); |
| 318 device->DeAllocate(); | 327 device->DeAllocate(); |
| 319 } | 328 } |
| 320 | 329 |
| 321 }; // namespace media | 330 }; // namespace media |
| OLD | NEW |