| 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 |
| 11 #include <stdio.h> | 11 #include <stdio.h> |
| 12 | 12 |
| 13 #include <map> | 13 #include <map> |
| 14 #include <memory> | 14 #include <memory> |
| 15 #include <sstream> | 15 #include <sstream> |
| 16 | 16 |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "webrtc/base/scoped_ref_ptr.h" | 18 #include "webrtc/base/scoped_ref_ptr.h" |
| 19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 19 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
| 20 #include "webrtc/modules/utility/include/process_thread.h" | 20 #include "webrtc/modules/utility/include/process_thread.h" |
| 21 #include "webrtc/modules/video_capture/video_capture.h" | 21 #include "webrtc/modules/video_capture/video_capture.h" |
| 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/system_wrappers/include/tick_util.h" | 25 #include "webrtc/system_wrappers/include/tick_util.h" |
| 26 #include "webrtc/test/frame_utils.h" |
| 26 #include "webrtc/video_frame.h" | 27 #include "webrtc/video_frame.h" |
| 27 | 28 |
| 28 using webrtc::CriticalSectionWrapper; | 29 using webrtc::CriticalSectionWrapper; |
| 29 using webrtc::CriticalSectionScoped; | 30 using webrtc::CriticalSectionScoped; |
| 30 using webrtc::SleepMs; | 31 using webrtc::SleepMs; |
| 31 using webrtc::TickTime; | 32 using webrtc::TickTime; |
| 32 using webrtc::VideoCaptureAlarm; | 33 using webrtc::VideoCaptureAlarm; |
| 33 using webrtc::VideoCaptureCapability; | 34 using webrtc::VideoCaptureCapability; |
| 34 using webrtc::VideoCaptureDataCallback; | 35 using webrtc::VideoCaptureDataCallback; |
| 35 using webrtc::VideoCaptureFactory; | 36 using webrtc::VideoCaptureFactory; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 53 WAIT_(ex, timeout, res); \ | 54 WAIT_(ex, timeout, res); \ |
| 54 if (!res) EXPECT_TRUE(ex); \ | 55 if (!res) EXPECT_TRUE(ex); \ |
| 55 } while (0) | 56 } while (0) |
| 56 | 57 |
| 57 | 58 |
| 58 static const int kTimeOut = 5000; | 59 static const int kTimeOut = 5000; |
| 59 static const int kTestHeight = 288; | 60 static const int kTestHeight = 288; |
| 60 static const int kTestWidth = 352; | 61 static const int kTestWidth = 352; |
| 61 static const int kTestFramerate = 30; | 62 static const int kTestFramerate = 30; |
| 62 | 63 |
| 63 // Compares the content of two video frames. | |
| 64 static bool CompareFrames(const webrtc::VideoFrame& frame1, | |
| 65 const webrtc::VideoFrame& frame2) { | |
| 66 bool result = | |
| 67 (frame1.stride(webrtc::kYPlane) == frame2.stride(webrtc::kYPlane)) && | |
| 68 (frame1.stride(webrtc::kUPlane) == frame2.stride(webrtc::kUPlane)) && | |
| 69 (frame1.stride(webrtc::kVPlane) == frame2.stride(webrtc::kVPlane)) && | |
| 70 (frame1.width() == frame2.width()) && | |
| 71 (frame1.height() == frame2.height()); | |
| 72 | |
| 73 if (!result) | |
| 74 return false; | |
| 75 for (int plane = 0; plane < webrtc::kNumOfPlanes; plane ++) { | |
| 76 webrtc::PlaneType plane_type = static_cast<webrtc::PlaneType>(plane); | |
| 77 int allocated_size1 = frame1.allocated_size(plane_type); | |
| 78 int allocated_size2 = frame2.allocated_size(plane_type); | |
| 79 if (allocated_size1 != allocated_size2) | |
| 80 return false; | |
| 81 const uint8_t* plane_buffer1 = frame1.buffer(plane_type); | |
| 82 const uint8_t* plane_buffer2 = frame2.buffer(plane_type); | |
| 83 if (memcmp(plane_buffer1, plane_buffer2, allocated_size1)) | |
| 84 return false; | |
| 85 } | |
| 86 return true; | |
| 87 } | |
| 88 | |
| 89 class TestVideoCaptureCallback : public VideoCaptureDataCallback { | 64 class TestVideoCaptureCallback : public VideoCaptureDataCallback { |
| 90 public: | 65 public: |
| 91 TestVideoCaptureCallback() | 66 TestVideoCaptureCallback() |
| 92 : capture_cs_(CriticalSectionWrapper::CreateCriticalSection()), | 67 : capture_cs_(CriticalSectionWrapper::CreateCriticalSection()), |
| 93 capture_delay_(-1), | 68 capture_delay_(-1), |
| 94 last_render_time_ms_(0), | 69 last_render_time_ms_(0), |
| 95 incoming_frames_(0), | 70 incoming_frames_(0), |
| 96 timing_warnings_(0), | 71 timing_warnings_(0), |
| 97 rotate_frame_(webrtc::kVideoRotation_0) {} | 72 rotate_frame_(webrtc::kVideoRotation_0) {} |
| 98 | 73 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 125 last_render_time_ms_ + (1000 * 1.1) / capability_.maxFPS && | 100 last_render_time_ms_ + (1000 * 1.1) / capability_.maxFPS && |
| 126 last_render_time_ms_ > 0) || | 101 last_render_time_ms_ > 0) || |
| 127 (videoFrame.render_time_ms() < | 102 (videoFrame.render_time_ms() < |
| 128 last_render_time_ms_ + (1000 * 0.9) / capability_.maxFPS && | 103 last_render_time_ms_ + (1000 * 0.9) / capability_.maxFPS && |
| 129 last_render_time_ms_ > 0)) { | 104 last_render_time_ms_ > 0)) { |
| 130 timing_warnings_++; | 105 timing_warnings_++; |
| 131 } | 106 } |
| 132 | 107 |
| 133 incoming_frames_++; | 108 incoming_frames_++; |
| 134 last_render_time_ms_ = videoFrame.render_time_ms(); | 109 last_render_time_ms_ = videoFrame.render_time_ms(); |
| 135 last_frame_.CopyFrame(videoFrame); | 110 last_frame_ = videoFrame.video_frame_buffer(); |
| 136 } | 111 } |
| 137 | 112 |
| 138 virtual void OnCaptureDelayChanged(const int32_t id, | 113 virtual void OnCaptureDelayChanged(const int32_t id, |
| 139 const int32_t delay) { | 114 const int32_t delay) { |
| 140 CriticalSectionScoped cs(capture_cs_.get()); | 115 CriticalSectionScoped cs(capture_cs_.get()); |
| 141 capture_delay_ = delay; | 116 capture_delay_ = delay; |
| 142 } | 117 } |
| 143 | 118 |
| 144 void SetExpectedCapability(VideoCaptureCapability capability) { | 119 void SetExpectedCapability(VideoCaptureCapability capability) { |
| 145 CriticalSectionScoped cs(capture_cs_.get()); | 120 CriticalSectionScoped cs(capture_cs_.get()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 161 CriticalSectionScoped cs(capture_cs_.get()); | 136 CriticalSectionScoped cs(capture_cs_.get()); |
| 162 return timing_warnings_; | 137 return timing_warnings_; |
| 163 } | 138 } |
| 164 VideoCaptureCapability capability() { | 139 VideoCaptureCapability capability() { |
| 165 CriticalSectionScoped cs(capture_cs_.get()); | 140 CriticalSectionScoped cs(capture_cs_.get()); |
| 166 return capability_; | 141 return capability_; |
| 167 } | 142 } |
| 168 | 143 |
| 169 bool CompareLastFrame(const webrtc::VideoFrame& frame) { | 144 bool CompareLastFrame(const webrtc::VideoFrame& frame) { |
| 170 CriticalSectionScoped cs(capture_cs_.get()); | 145 CriticalSectionScoped cs(capture_cs_.get()); |
| 171 return CompareFrames(last_frame_, frame); | 146 return webrtc::test::FrameBufsEqual(last_frame_, |
| 147 frame.video_frame_buffer()); |
| 172 } | 148 } |
| 173 | 149 |
| 174 void SetExpectedCaptureRotation(webrtc::VideoRotation rotation) { | 150 void SetExpectedCaptureRotation(webrtc::VideoRotation rotation) { |
| 175 CriticalSectionScoped cs(capture_cs_.get()); | 151 CriticalSectionScoped cs(capture_cs_.get()); |
| 176 rotate_frame_ = rotation; | 152 rotate_frame_ = rotation; |
| 177 } | 153 } |
| 178 | 154 |
| 179 private: | 155 private: |
| 180 std::unique_ptr<CriticalSectionWrapper> capture_cs_; | 156 std::unique_ptr<CriticalSectionWrapper> capture_cs_; |
| 181 VideoCaptureCapability capability_; | 157 VideoCaptureCapability capability_; |
| 182 int capture_delay_; | 158 int capture_delay_; |
| 183 int64_t last_render_time_ms_; | 159 int64_t last_render_time_ms_; |
| 184 int incoming_frames_; | 160 int incoming_frames_; |
| 185 int timing_warnings_; | 161 int timing_warnings_; |
| 186 webrtc::VideoFrame last_frame_; | 162 rtc::scoped_refptr<webrtc::VideoFrameBuffer> last_frame_; |
| 187 webrtc::VideoRotation rotate_frame_; | 163 webrtc::VideoRotation rotate_frame_; |
| 188 }; | 164 }; |
| 189 | 165 |
| 190 class TestVideoCaptureFeedBack : public VideoCaptureFeedBack { | 166 class TestVideoCaptureFeedBack : public VideoCaptureFeedBack { |
| 191 public: | 167 public: |
| 192 TestVideoCaptureFeedBack() : | 168 TestVideoCaptureFeedBack() : |
| 193 capture_cs_(CriticalSectionWrapper::CreateCriticalSection()), | 169 capture_cs_(CriticalSectionWrapper::CreateCriticalSection()), |
| 194 frame_rate_(0), | 170 frame_rate_(0), |
| 195 alarm_(webrtc::Cleared) { | 171 alarm_(webrtc::Cleared) { |
| 196 } | 172 } |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 441 VideoCaptureCapability capability; | 417 VideoCaptureCapability capability; |
| 442 capability.width = kTestWidth; | 418 capability.width = kTestWidth; |
| 443 capability.height = kTestHeight; | 419 capability.height = kTestHeight; |
| 444 capability.rawType = webrtc::kVideoYV12; | 420 capability.rawType = webrtc::kVideoYV12; |
| 445 capability.maxFPS = kTestFramerate; | 421 capability.maxFPS = kTestFramerate; |
| 446 capture_callback_.SetExpectedCapability(capability); | 422 capture_callback_.SetExpectedCapability(capability); |
| 447 | 423 |
| 448 test_frame_.CreateEmptyFrame(kTestWidth, kTestHeight, kTestWidth, | 424 test_frame_.CreateEmptyFrame(kTestWidth, kTestHeight, kTestWidth, |
| 449 ((kTestWidth + 1) / 2), (kTestWidth + 1) / 2); | 425 ((kTestWidth + 1) / 2), (kTestWidth + 1) / 2); |
| 450 SleepMs(1); // Wait 1ms so that two tests can't have the same timestamp. | 426 SleepMs(1); // Wait 1ms so that two tests can't have the same timestamp. |
| 451 memset(test_frame_.buffer(webrtc::kYPlane), 127, kTestWidth * kTestHeight); | 427 memset(test_frame_.video_frame_buffer()->MutableDataY(), 127, |
| 452 memset(test_frame_.buffer(webrtc::kUPlane), 127, | 428 kTestWidth * kTestHeight); |
| 429 memset(test_frame_.video_frame_buffer()->MutableDataU(), 127, |
| 453 ((kTestWidth + 1) / 2) * ((kTestHeight + 1) / 2)); | 430 ((kTestWidth + 1) / 2) * ((kTestHeight + 1) / 2)); |
| 454 memset(test_frame_.buffer(webrtc::kVPlane), 127, | 431 memset(test_frame_.video_frame_buffer()->MutableDataV(), 127, |
| 455 ((kTestWidth + 1) / 2) * ((kTestHeight + 1) / 2)); | 432 ((kTestWidth + 1) / 2) * ((kTestHeight + 1) / 2)); |
| 456 | 433 |
| 457 capture_module_->RegisterCaptureDataCallback(capture_callback_); | 434 capture_module_->RegisterCaptureDataCallback(capture_callback_); |
| 458 capture_module_->RegisterCaptureCallback(capture_feedback_); | 435 capture_module_->RegisterCaptureCallback(capture_feedback_); |
| 459 capture_module_->EnableFrameRateCallback(true); | 436 capture_module_->EnableFrameRateCallback(true); |
| 460 capture_module_->EnableNoPictureAlarm(true); | 437 capture_module_->EnableNoPictureAlarm(true); |
| 461 } | 438 } |
| 462 | 439 |
| 463 void TearDown() { | 440 void TearDown() { |
| 464 process_module_->Stop(); | 441 process_module_->Stop(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 length, capture_callback_.capability(), 0)); | 520 length, capture_callback_.capability(), 0)); |
| 544 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180)); | 521 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180)); |
| 545 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180); | 522 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180); |
| 546 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 523 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
| 547 length, capture_callback_.capability(), 0)); | 524 length, capture_callback_.capability(), 0)); |
| 548 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270)); | 525 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270)); |
| 549 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270); | 526 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270); |
| 550 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 527 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
| 551 length, capture_callback_.capability(), 0)); | 528 length, capture_callback_.capability(), 0)); |
| 552 } | 529 } |
| OLD | NEW |