| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "webrtc/modules/video_capture/video_capture_factory.h" | 22 #include "webrtc/modules/video_capture/video_capture_factory.h" |
| 23 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 23 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
| 24 #include "webrtc/system_wrappers/include/sleep.h" | 24 #include "webrtc/system_wrappers/include/sleep.h" |
| 25 #include "webrtc/test/frame_utils.h" | 25 #include "webrtc/test/frame_utils.h" |
| 26 #include "webrtc/test/gtest.h" | 26 #include "webrtc/test/gtest.h" |
| 27 #include "webrtc/video_frame.h" | 27 #include "webrtc/video_frame.h" |
| 28 | 28 |
| 29 using webrtc::CriticalSectionWrapper; | 29 using webrtc::CriticalSectionWrapper; |
| 30 using webrtc::CriticalSectionScoped; | 30 using webrtc::CriticalSectionScoped; |
| 31 using webrtc::SleepMs; | 31 using webrtc::SleepMs; |
| 32 using webrtc::VideoCaptureAlarm; | |
| 33 using webrtc::VideoCaptureCapability; | 32 using webrtc::VideoCaptureCapability; |
| 34 using webrtc::VideoCaptureDataCallback; | |
| 35 using webrtc::VideoCaptureFactory; | 33 using webrtc::VideoCaptureFactory; |
| 36 using webrtc::VideoCaptureFeedBack; | |
| 37 using webrtc::VideoCaptureModule; | 34 using webrtc::VideoCaptureModule; |
| 38 | 35 |
| 39 | 36 |
| 40 #define WAIT_(ex, timeout, res) \ | 37 #define WAIT_(ex, timeout, res) \ |
| 41 do { \ | 38 do { \ |
| 42 res = (ex); \ | 39 res = (ex); \ |
| 43 int64_t start = rtc::TimeMillis(); \ | 40 int64_t start = rtc::TimeMillis(); \ |
| 44 while (!res && rtc::TimeMillis() < start + timeout) { \ | 41 while (!res && rtc::TimeMillis() < start + timeout) { \ |
| 45 SleepMs(5); \ | 42 SleepMs(5); \ |
| 46 res = (ex); \ | 43 res = (ex); \ |
| 47 } \ | 44 } \ |
| 48 } while (0) | 45 } while (0) |
| 49 | 46 |
| 50 #define EXPECT_TRUE_WAIT(ex, timeout) \ | 47 #define EXPECT_TRUE_WAIT(ex, timeout) \ |
| 51 do { \ | 48 do { \ |
| 52 bool res; \ | 49 bool res; \ |
| 53 WAIT_(ex, timeout, res); \ | 50 WAIT_(ex, timeout, res); \ |
| 54 if (!res) EXPECT_TRUE(ex); \ | 51 if (!res) EXPECT_TRUE(ex); \ |
| 55 } while (0) | 52 } while (0) |
| 56 | 53 |
| 57 | 54 |
| 58 static const int kTimeOut = 5000; | 55 static const int kTimeOut = 5000; |
| 59 static const int kTestHeight = 288; | 56 static const int kTestHeight = 288; |
| 60 static const int kTestWidth = 352; | 57 static const int kTestWidth = 352; |
| 61 static const int kTestFramerate = 30; | 58 static const int kTestFramerate = 30; |
| 62 | 59 |
| 63 class TestVideoCaptureCallback : public VideoCaptureDataCallback { | 60 class TestVideoCaptureCallback |
| 61 : public rtc::VideoSinkInterface<webrtc::VideoFrame> { |
| 64 public: | 62 public: |
| 65 TestVideoCaptureCallback() | 63 TestVideoCaptureCallback() |
| 66 : capture_cs_(CriticalSectionWrapper::CreateCriticalSection()), | 64 : capture_cs_(CriticalSectionWrapper::CreateCriticalSection()), |
| 67 capture_delay_(-1), | |
| 68 last_render_time_ms_(0), | 65 last_render_time_ms_(0), |
| 69 incoming_frames_(0), | 66 incoming_frames_(0), |
| 70 timing_warnings_(0), | 67 timing_warnings_(0), |
| 71 rotate_frame_(webrtc::kVideoRotation_0) {} | 68 rotate_frame_(webrtc::kVideoRotation_0) {} |
| 72 | 69 |
| 73 ~TestVideoCaptureCallback() { | 70 ~TestVideoCaptureCallback() { |
| 74 if (timing_warnings_ > 0) | 71 if (timing_warnings_ > 0) |
| 75 printf("No of timing warnings %d\n", timing_warnings_); | 72 printf("No of timing warnings %d\n", timing_warnings_); |
| 76 } | 73 } |
| 77 | 74 |
| 78 virtual void OnIncomingCapturedFrame(const int32_t id, | 75 void OnFrame(const webrtc::VideoFrame& videoFrame) override { |
| 79 const webrtc::VideoFrame& videoFrame) { | |
| 80 CriticalSectionScoped cs(capture_cs_.get()); | 76 CriticalSectionScoped cs(capture_cs_.get()); |
| 81 int height = videoFrame.height(); | 77 int height = videoFrame.height(); |
| 82 int width = videoFrame.width(); | 78 int width = videoFrame.width(); |
| 83 #if defined(ANDROID) && ANDROID | 79 #if defined(ANDROID) && ANDROID |
| 84 // Android camera frames may be rotated depending on test device | 80 // Android camera frames may be rotated depending on test device |
| 85 // orientation. | 81 // orientation. |
| 86 EXPECT_TRUE(height == capability_.height || height == capability_.width); | 82 EXPECT_TRUE(height == capability_.height || height == capability_.width); |
| 87 EXPECT_TRUE(width == capability_.width || width == capability_.height); | 83 EXPECT_TRUE(width == capability_.width || width == capability_.height); |
| 88 #else | 84 #else |
| 89 EXPECT_EQ(height, capability_.height); | 85 EXPECT_EQ(height, capability_.height); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 102 last_render_time_ms_ + (1000 * 0.9) / capability_.maxFPS && | 98 last_render_time_ms_ + (1000 * 0.9) / capability_.maxFPS && |
| 103 last_render_time_ms_ > 0)) { | 99 last_render_time_ms_ > 0)) { |
| 104 timing_warnings_++; | 100 timing_warnings_++; |
| 105 } | 101 } |
| 106 | 102 |
| 107 incoming_frames_++; | 103 incoming_frames_++; |
| 108 last_render_time_ms_ = videoFrame.render_time_ms(); | 104 last_render_time_ms_ = videoFrame.render_time_ms(); |
| 109 last_frame_ = videoFrame.video_frame_buffer(); | 105 last_frame_ = videoFrame.video_frame_buffer(); |
| 110 } | 106 } |
| 111 | 107 |
| 112 virtual void OnCaptureDelayChanged(const int32_t id, | |
| 113 const int32_t delay) { | |
| 114 CriticalSectionScoped cs(capture_cs_.get()); | |
| 115 capture_delay_ = delay; | |
| 116 } | |
| 117 | |
| 118 void SetExpectedCapability(VideoCaptureCapability capability) { | 108 void SetExpectedCapability(VideoCaptureCapability capability) { |
| 119 CriticalSectionScoped cs(capture_cs_.get()); | 109 CriticalSectionScoped cs(capture_cs_.get()); |
| 120 capability_= capability; | 110 capability_= capability; |
| 121 incoming_frames_ = 0; | 111 incoming_frames_ = 0; |
| 122 last_render_time_ms_ = 0; | 112 last_render_time_ms_ = 0; |
| 123 capture_delay_ = -1; | |
| 124 } | 113 } |
| 125 int incoming_frames() { | 114 int incoming_frames() { |
| 126 CriticalSectionScoped cs(capture_cs_.get()); | 115 CriticalSectionScoped cs(capture_cs_.get()); |
| 127 return incoming_frames_; | 116 return incoming_frames_; |
| 128 } | 117 } |
| 129 | 118 |
| 130 int capture_delay() { | |
| 131 CriticalSectionScoped cs(capture_cs_.get()); | |
| 132 return capture_delay_; | |
| 133 } | |
| 134 int timing_warnings() { | 119 int timing_warnings() { |
| 135 CriticalSectionScoped cs(capture_cs_.get()); | 120 CriticalSectionScoped cs(capture_cs_.get()); |
| 136 return timing_warnings_; | 121 return timing_warnings_; |
| 137 } | 122 } |
| 138 VideoCaptureCapability capability() { | 123 VideoCaptureCapability capability() { |
| 139 CriticalSectionScoped cs(capture_cs_.get()); | 124 CriticalSectionScoped cs(capture_cs_.get()); |
| 140 return capability_; | 125 return capability_; |
| 141 } | 126 } |
| 142 | 127 |
| 143 bool CompareLastFrame(const webrtc::VideoFrame& frame) { | 128 bool CompareLastFrame(const webrtc::VideoFrame& frame) { |
| 144 CriticalSectionScoped cs(capture_cs_.get()); | 129 CriticalSectionScoped cs(capture_cs_.get()); |
| 145 return webrtc::test::FrameBufsEqual(last_frame_, | 130 return webrtc::test::FrameBufsEqual(last_frame_, |
| 146 frame.video_frame_buffer()); | 131 frame.video_frame_buffer()); |
| 147 } | 132 } |
| 148 | 133 |
| 149 void SetExpectedCaptureRotation(webrtc::VideoRotation rotation) { | 134 void SetExpectedCaptureRotation(webrtc::VideoRotation rotation) { |
| 150 CriticalSectionScoped cs(capture_cs_.get()); | 135 CriticalSectionScoped cs(capture_cs_.get()); |
| 151 rotate_frame_ = rotation; | 136 rotate_frame_ = rotation; |
| 152 } | 137 } |
| 153 | 138 |
| 154 private: | 139 private: |
| 155 std::unique_ptr<CriticalSectionWrapper> capture_cs_; | 140 std::unique_ptr<CriticalSectionWrapper> capture_cs_; |
| 156 VideoCaptureCapability capability_; | 141 VideoCaptureCapability capability_; |
| 157 int capture_delay_; | |
| 158 int64_t last_render_time_ms_; | 142 int64_t last_render_time_ms_; |
| 159 int incoming_frames_; | 143 int incoming_frames_; |
| 160 int timing_warnings_; | 144 int timing_warnings_; |
| 161 rtc::scoped_refptr<webrtc::VideoFrameBuffer> last_frame_; | 145 rtc::scoped_refptr<webrtc::VideoFrameBuffer> last_frame_; |
| 162 webrtc::VideoRotation rotate_frame_; | 146 webrtc::VideoRotation rotate_frame_; |
| 163 }; | 147 }; |
| 164 | 148 |
| 165 class TestVideoCaptureFeedBack : public VideoCaptureFeedBack { | |
| 166 public: | |
| 167 TestVideoCaptureFeedBack() : | |
| 168 capture_cs_(CriticalSectionWrapper::CreateCriticalSection()), | |
| 169 frame_rate_(0), | |
| 170 alarm_(webrtc::Cleared) { | |
| 171 } | |
| 172 | |
| 173 virtual void OnCaptureFrameRate(const int32_t id, | |
| 174 const uint32_t frameRate) { | |
| 175 CriticalSectionScoped cs(capture_cs_.get()); | |
| 176 frame_rate_ = frameRate; | |
| 177 } | |
| 178 | |
| 179 virtual void OnNoPictureAlarm(const int32_t id, | |
| 180 const VideoCaptureAlarm reported_alarm) { | |
| 181 CriticalSectionScoped cs(capture_cs_.get()); | |
| 182 alarm_ = reported_alarm; | |
| 183 } | |
| 184 int frame_rate() { | |
| 185 CriticalSectionScoped cs(capture_cs_.get()); | |
| 186 return frame_rate_; | |
| 187 | |
| 188 } | |
| 189 VideoCaptureAlarm alarm() { | |
| 190 CriticalSectionScoped cs(capture_cs_.get()); | |
| 191 return alarm_; | |
| 192 } | |
| 193 | |
| 194 private: | |
| 195 std::unique_ptr<CriticalSectionWrapper> capture_cs_; | |
| 196 unsigned int frame_rate_; | |
| 197 VideoCaptureAlarm alarm_; | |
| 198 }; | |
| 199 | |
| 200 class VideoCaptureTest : public testing::Test { | 149 class VideoCaptureTest : public testing::Test { |
| 201 public: | 150 public: |
| 202 VideoCaptureTest() : number_of_devices_(0) {} | 151 VideoCaptureTest() : number_of_devices_(0) {} |
| 203 | 152 |
| 204 void SetUp() { | 153 void SetUp() { |
| 205 device_info_.reset(VideoCaptureFactory::CreateDeviceInfo(0)); | 154 device_info_.reset(VideoCaptureFactory::CreateDeviceInfo()); |
| 206 assert(device_info_.get()); | 155 assert(device_info_.get()); |
| 207 number_of_devices_ = device_info_->NumberOfDevices(); | 156 number_of_devices_ = device_info_->NumberOfDevices(); |
| 208 ASSERT_GT(number_of_devices_, 0u); | 157 ASSERT_GT(number_of_devices_, 0u); |
| 209 } | 158 } |
| 210 | 159 |
| 211 rtc::scoped_refptr<VideoCaptureModule> OpenVideoCaptureDevice( | 160 rtc::scoped_refptr<VideoCaptureModule> OpenVideoCaptureDevice( |
| 212 unsigned int device, | 161 unsigned int device, |
| 213 VideoCaptureDataCallback* callback) { | 162 rtc::VideoSinkInterface<webrtc::VideoFrame>* callback) { |
| 214 char device_name[256]; | 163 char device_name[256]; |
| 215 char unique_name[256]; | 164 char unique_name[256]; |
| 216 | 165 |
| 217 EXPECT_EQ(0, device_info_->GetDeviceName( | 166 EXPECT_EQ(0, device_info_->GetDeviceName( |
| 218 device, device_name, 256, unique_name, 256)); | 167 device, device_name, 256, unique_name, 256)); |
| 219 | 168 |
| 220 rtc::scoped_refptr<VideoCaptureModule> module( | 169 rtc::scoped_refptr<VideoCaptureModule> module( |
| 221 VideoCaptureFactory::Create(device, unique_name)); | 170 VideoCaptureFactory::Create(unique_name)); |
| 222 if (module.get() == NULL) | 171 if (module.get() == NULL) |
| 223 return NULL; | 172 return NULL; |
| 224 | 173 |
| 225 EXPECT_FALSE(module->CaptureStarted()); | 174 EXPECT_FALSE(module->CaptureStarted()); |
| 226 | 175 |
| 227 module->RegisterCaptureDataCallback(*callback); | 176 module->RegisterCaptureDataCallback(callback); |
| 228 return module; | 177 return module; |
| 229 } | 178 } |
| 230 | 179 |
| 231 void StartCapture(VideoCaptureModule* capture_module, | 180 void StartCapture(VideoCaptureModule* capture_module, |
| 232 VideoCaptureCapability capability) { | 181 VideoCaptureCapability capability) { |
| 233 ASSERT_EQ(0, capture_module->StartCapture(capability)); | 182 ASSERT_EQ(0, capture_module->StartCapture(capability)); |
| 234 EXPECT_TRUE(capture_module->CaptureStarted()); | 183 EXPECT_TRUE(capture_module->CaptureStarted()); |
| 235 | 184 |
| 236 VideoCaptureCapability resulting_capability; | 185 VideoCaptureCapability resulting_capability; |
| 237 EXPECT_EQ(0, capture_module->CaptureSettings(resulting_capability)); | 186 EXPECT_EQ(0, capture_module->CaptureSettings(resulting_capability)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 #endif | 218 #endif |
| 270 capture_observer.SetExpectedCapability(capability); | 219 capture_observer.SetExpectedCapability(capability); |
| 271 ASSERT_NO_FATAL_FAILURE(StartCapture(module.get(), capability)); | 220 ASSERT_NO_FATAL_FAILURE(StartCapture(module.get(), capability)); |
| 272 | 221 |
| 273 // Less than 4s to start the camera. | 222 // Less than 4s to start the camera. |
| 274 EXPECT_LE(rtc::TimeMillis() - start_time, 4000); | 223 EXPECT_LE(rtc::TimeMillis() - start_time, 4000); |
| 275 | 224 |
| 276 // Make sure 5 frames are captured. | 225 // Make sure 5 frames are captured. |
| 277 EXPECT_TRUE_WAIT(capture_observer.incoming_frames() >= 5, kTimeOut); | 226 EXPECT_TRUE_WAIT(capture_observer.incoming_frames() >= 5, kTimeOut); |
| 278 | 227 |
| 279 EXPECT_GE(capture_observer.capture_delay(), 0); | |
| 280 | |
| 281 int64_t stop_time = rtc::TimeMillis(); | 228 int64_t stop_time = rtc::TimeMillis(); |
| 282 EXPECT_EQ(0, module->StopCapture()); | 229 EXPECT_EQ(0, module->StopCapture()); |
| 283 EXPECT_FALSE(module->CaptureStarted()); | 230 EXPECT_FALSE(module->CaptureStarted()); |
| 284 | 231 |
| 285 // Less than 3s to stop the camera. | 232 // Less than 3s to stop the camera. |
| 286 EXPECT_LE(rtc::TimeMillis() - stop_time, 3000); | 233 EXPECT_LE(rtc::TimeMillis() - stop_time, 3000); |
| 287 } | 234 } |
| 288 } | 235 } |
| 289 | 236 |
| 290 #ifdef WEBRTC_MAC | 237 #ifdef WEBRTC_MAC |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 401 EXPECT_TRUE_WAIT(capture_observer2.incoming_frames() >= 5, kTimeOut); | 348 EXPECT_TRUE_WAIT(capture_observer2.incoming_frames() >= 5, kTimeOut); |
| 402 EXPECT_EQ(0, module2->StopCapture()); | 349 EXPECT_EQ(0, module2->StopCapture()); |
| 403 EXPECT_EQ(0, module1->StopCapture()); | 350 EXPECT_EQ(0, module1->StopCapture()); |
| 404 } | 351 } |
| 405 | 352 |
| 406 // Test class for testing external capture and capture feedback information | 353 // Test class for testing external capture and capture feedback information |
| 407 // such as frame rate and picture alarm. | 354 // such as frame rate and picture alarm. |
| 408 class VideoCaptureExternalTest : public testing::Test { | 355 class VideoCaptureExternalTest : public testing::Test { |
| 409 public: | 356 public: |
| 410 void SetUp() { | 357 void SetUp() { |
| 411 capture_module_ = VideoCaptureFactory::Create(0, capture_input_interface_); | 358 capture_module_ = VideoCaptureFactory::Create(capture_input_interface_); |
| 412 process_module_ = webrtc::ProcessThread::Create("ProcessThread"); | |
| 413 process_module_->Start(); | |
| 414 process_module_->RegisterModule(capture_module_); | |
| 415 | 359 |
| 416 VideoCaptureCapability capability; | 360 VideoCaptureCapability capability; |
| 417 capability.width = kTestWidth; | 361 capability.width = kTestWidth; |
| 418 capability.height = kTestHeight; | 362 capability.height = kTestHeight; |
| 419 capability.rawType = webrtc::kVideoYV12; | 363 capability.rawType = webrtc::kVideoYV12; |
| 420 capability.maxFPS = kTestFramerate; | 364 capability.maxFPS = kTestFramerate; |
| 421 capture_callback_.SetExpectedCapability(capability); | 365 capture_callback_.SetExpectedCapability(capability); |
| 422 | 366 |
| 423 rtc::scoped_refptr<webrtc::I420Buffer> buffer = webrtc::I420Buffer::Create( | 367 rtc::scoped_refptr<webrtc::I420Buffer> buffer = webrtc::I420Buffer::Create( |
| 424 kTestWidth, kTestHeight, | 368 kTestWidth, kTestHeight, |
| 425 kTestWidth, ((kTestWidth + 1) / 2), (kTestWidth + 1) / 2); | 369 kTestWidth, ((kTestWidth + 1) / 2), (kTestWidth + 1) / 2); |
| 426 | 370 |
| 427 memset(buffer->MutableDataY(), 127, kTestWidth * kTestHeight); | 371 memset(buffer->MutableDataY(), 127, kTestWidth * kTestHeight); |
| 428 memset(buffer->MutableDataU(), 127, | 372 memset(buffer->MutableDataU(), 127, |
| 429 ((kTestWidth + 1) / 2) * ((kTestHeight + 1) / 2)); | 373 ((kTestWidth + 1) / 2) * ((kTestHeight + 1) / 2)); |
| 430 memset(buffer->MutableDataV(), 127, | 374 memset(buffer->MutableDataV(), 127, |
| 431 ((kTestWidth + 1) / 2) * ((kTestHeight + 1) / 2)); | 375 ((kTestWidth + 1) / 2) * ((kTestHeight + 1) / 2)); |
| 432 test_frame_.reset( | 376 test_frame_.reset( |
| 433 new webrtc::VideoFrame(buffer, 0, 0, webrtc::kVideoRotation_0)); | 377 new webrtc::VideoFrame(buffer, 0, 0, webrtc::kVideoRotation_0)); |
| 434 | 378 |
| 435 SleepMs(1); // Wait 1ms so that two tests can't have the same timestamp. | 379 SleepMs(1); // Wait 1ms so that two tests can't have the same timestamp. |
| 436 | 380 |
| 437 capture_module_->RegisterCaptureDataCallback(capture_callback_); | 381 capture_module_->RegisterCaptureDataCallback(&capture_callback_); |
| 438 capture_module_->RegisterCaptureCallback(capture_feedback_); | |
| 439 capture_module_->EnableFrameRateCallback(true); | |
| 440 capture_module_->EnableNoPictureAlarm(true); | |
| 441 } | 382 } |
| 442 | 383 |
| 443 void TearDown() { | 384 void TearDown() { |
| 444 process_module_->Stop(); | |
| 445 } | 385 } |
| 446 | 386 |
| 447 webrtc::VideoCaptureExternal* capture_input_interface_; | 387 webrtc::VideoCaptureExternal* capture_input_interface_; |
| 448 rtc::scoped_refptr<VideoCaptureModule> capture_module_; | 388 rtc::scoped_refptr<VideoCaptureModule> capture_module_; |
| 449 std::unique_ptr<webrtc::ProcessThread> process_module_; | |
| 450 std::unique_ptr<webrtc::VideoFrame> test_frame_; | 389 std::unique_ptr<webrtc::VideoFrame> test_frame_; |
| 451 TestVideoCaptureCallback capture_callback_; | 390 TestVideoCaptureCallback capture_callback_; |
| 452 TestVideoCaptureFeedBack capture_feedback_; | |
| 453 }; | 391 }; |
| 454 | 392 |
| 455 // Test input of external video frames. | 393 // Test input of external video frames. |
| 456 TEST_F(VideoCaptureExternalTest, TestExternalCapture) { | 394 TEST_F(VideoCaptureExternalTest, TestExternalCapture) { |
| 457 size_t length = webrtc::CalcBufferSize(webrtc::kI420, | 395 size_t length = webrtc::CalcBufferSize(webrtc::kI420, |
| 458 test_frame_->width(), | 396 test_frame_->width(), |
| 459 test_frame_->height()); | 397 test_frame_->height()); |
| 460 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); | 398 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); |
| 461 webrtc::ExtractBuffer(*test_frame_, length, test_buffer.get()); | 399 webrtc::ExtractBuffer(*test_frame_, length, test_buffer.get()); |
| 462 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 400 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
| 463 length, capture_callback_.capability(), 0)); | 401 length, capture_callback_.capability(), 0)); |
| 464 EXPECT_TRUE(capture_callback_.CompareLastFrame(*test_frame_)); | 402 EXPECT_TRUE(capture_callback_.CompareLastFrame(*test_frame_)); |
| 465 } | 403 } |
| 466 | 404 |
| 467 // Test frame rate and no picture alarm. | |
| 468 // Flaky on Win32, see webrtc:3270. | |
| 469 #if defined(WEBRTC_WIN) || defined(WEBRTC_MAC) | |
| 470 #define MAYBE_FrameRate DISABLED_FrameRate | |
| 471 #else | |
| 472 #define MAYBE_FrameRate FrameRate | |
| 473 #endif | |
| 474 TEST_F(VideoCaptureExternalTest, MAYBE_FrameRate) { | |
| 475 int64_t testTime = 3 * rtc::kNumNanosecsPerSec; | |
| 476 int64_t startTime = rtc::TimeNanos(); | |
| 477 | |
| 478 while ((rtc::TimeNanos() - startTime) < testTime) { | |
| 479 size_t length = webrtc::CalcBufferSize(webrtc::kI420, | |
| 480 test_frame_->width(), | |
| 481 test_frame_->height()); | |
| 482 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); | |
| 483 webrtc::ExtractBuffer(*test_frame_, length, test_buffer.get()); | |
| 484 EXPECT_EQ( | |
| 485 0, capture_input_interface_->IncomingFrame( | |
| 486 test_buffer.get(), length, capture_callback_.capability(), 0)); | |
| 487 SleepMs(100); | |
| 488 } | |
| 489 EXPECT_TRUE(capture_feedback_.frame_rate() >= 8 && | |
| 490 capture_feedback_.frame_rate() <= 10); | |
| 491 SleepMs(500); | |
| 492 EXPECT_EQ(webrtc::Raised, capture_feedback_.alarm()); | |
| 493 | |
| 494 startTime = rtc::TimeNanos(); | |
| 495 while ((rtc::TimeNanos() - startTime) < testTime) { | |
| 496 size_t length = webrtc::CalcBufferSize(webrtc::kI420, | |
| 497 test_frame_->width(), | |
| 498 test_frame_->height()); | |
| 499 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); | |
| 500 webrtc::ExtractBuffer(*test_frame_, length, test_buffer.get()); | |
| 501 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | |
| 502 length, capture_callback_.capability(), 0)); | |
| 503 SleepMs(1000 / 30); | |
| 504 } | |
| 505 EXPECT_EQ(webrtc::Cleared, capture_feedback_.alarm()); | |
| 506 // Frame rate might be less than 33 since we have paused providing | |
| 507 // frames for a while. | |
| 508 EXPECT_TRUE(capture_feedback_.frame_rate() >= 25 && | |
| 509 capture_feedback_.frame_rate() <= 33); | |
| 510 } | |
| 511 | |
| 512 TEST_F(VideoCaptureExternalTest, Rotation) { | 405 TEST_F(VideoCaptureExternalTest, Rotation) { |
| 513 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_0)); | 406 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_0)); |
| 514 size_t length = webrtc::CalcBufferSize(webrtc::kI420, | 407 size_t length = webrtc::CalcBufferSize(webrtc::kI420, |
| 515 test_frame_->width(), | 408 test_frame_->width(), |
| 516 test_frame_->height()); | 409 test_frame_->height()); |
| 517 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); | 410 std::unique_ptr<uint8_t[]> test_buffer(new uint8_t[length]); |
| 518 webrtc::ExtractBuffer(*test_frame_, length, test_buffer.get()); | 411 webrtc::ExtractBuffer(*test_frame_, length, test_buffer.get()); |
| 519 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 412 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
| 520 length, capture_callback_.capability(), 0)); | 413 length, capture_callback_.capability(), 0)); |
| 521 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_90)); | 414 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_90)); |
| 522 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_90); | 415 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_90); |
| 523 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 416 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
| 524 length, capture_callback_.capability(), 0)); | 417 length, capture_callback_.capability(), 0)); |
| 525 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180)); | 418 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180)); |
| 526 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180); | 419 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180); |
| 527 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 420 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
| 528 length, capture_callback_.capability(), 0)); | 421 length, capture_callback_.capability(), 0)); |
| 529 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270)); | 422 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270)); |
| 530 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270); | 423 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270); |
| 531 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 424 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
| 532 length, capture_callback_.capability(), 0)); | 425 length, capture_callback_.capability(), 0)); |
| 533 } | 426 } |
| OLD | NEW |