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