| 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 "webrtc/api/video/i420_buffer.h" | 17 #include "webrtc/api/video/i420_buffer.h" |
| 18 #include "webrtc/api/video/video_frame.h" | 18 #include "webrtc/api/video/video_frame.h" |
| 19 #include "webrtc/base/criticalsection.h" |
| 19 #include "webrtc/base/scoped_ref_ptr.h" | 20 #include "webrtc/base/scoped_ref_ptr.h" |
| 20 #include "webrtc/base/timeutils.h" | 21 #include "webrtc/base/timeutils.h" |
| 21 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 22 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
| 22 #include "webrtc/modules/utility/include/process_thread.h" | 23 #include "webrtc/modules/utility/include/process_thread.h" |
| 23 #include "webrtc/modules/video_capture/video_capture.h" | 24 #include "webrtc/modules/video_capture/video_capture.h" |
| 24 #include "webrtc/modules/video_capture/video_capture_factory.h" | 25 #include "webrtc/modules/video_capture/video_capture_factory.h" |
| 25 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | |
| 26 #include "webrtc/system_wrappers/include/sleep.h" | 26 #include "webrtc/system_wrappers/include/sleep.h" |
| 27 #include "webrtc/test/frame_utils.h" | 27 #include "webrtc/test/frame_utils.h" |
| 28 #include "webrtc/test/gtest.h" | 28 #include "webrtc/test/gtest.h" |
| 29 | 29 |
| 30 using webrtc::CriticalSectionWrapper; | |
| 31 using webrtc::CriticalSectionScoped; | |
| 32 using webrtc::SleepMs; | 30 using webrtc::SleepMs; |
| 33 using webrtc::VideoCaptureCapability; | 31 using webrtc::VideoCaptureCapability; |
| 34 using webrtc::VideoCaptureFactory; | 32 using webrtc::VideoCaptureFactory; |
| 35 using webrtc::VideoCaptureModule; | 33 using webrtc::VideoCaptureModule; |
| 36 | 34 |
| 37 | 35 |
| 38 #define WAIT_(ex, timeout, res) \ | 36 #define WAIT_(ex, timeout, res) \ |
| 39 do { \ | 37 do { \ |
| 40 res = (ex); \ | 38 res = (ex); \ |
| 41 int64_t start = rtc::TimeMillis(); \ | 39 int64_t start = rtc::TimeMillis(); \ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 54 | 52 |
| 55 | 53 |
| 56 static const int kTimeOut = 5000; | 54 static const int kTimeOut = 5000; |
| 57 static const int kTestHeight = 288; | 55 static const int kTestHeight = 288; |
| 58 static const int kTestWidth = 352; | 56 static const int kTestWidth = 352; |
| 59 static const int kTestFramerate = 30; | 57 static const int kTestFramerate = 30; |
| 60 | 58 |
| 61 class TestVideoCaptureCallback | 59 class TestVideoCaptureCallback |
| 62 : public rtc::VideoSinkInterface<webrtc::VideoFrame> { | 60 : public rtc::VideoSinkInterface<webrtc::VideoFrame> { |
| 63 public: | 61 public: |
| 64 TestVideoCaptureCallback() | 62 TestVideoCaptureCallback() : |
| 65 : capture_cs_(CriticalSectionWrapper::CreateCriticalSection()), | |
| 66 last_render_time_ms_(0), | 63 last_render_time_ms_(0), |
| 67 incoming_frames_(0), | 64 incoming_frames_(0), |
| 68 timing_warnings_(0), | 65 timing_warnings_(0), |
| 69 rotate_frame_(webrtc::kVideoRotation_0) {} | 66 rotate_frame_(webrtc::kVideoRotation_0) {} |
| 70 | 67 |
| 71 ~TestVideoCaptureCallback() { | 68 ~TestVideoCaptureCallback() { |
| 72 if (timing_warnings_ > 0) | 69 if (timing_warnings_ > 0) |
| 73 printf("No of timing warnings %d\n", timing_warnings_); | 70 printf("No of timing warnings %d\n", timing_warnings_); |
| 74 } | 71 } |
| 75 | 72 |
| 76 void OnFrame(const webrtc::VideoFrame& videoFrame) override { | 73 void OnFrame(const webrtc::VideoFrame& videoFrame) override { |
| 77 CriticalSectionScoped cs(capture_cs_.get()); | 74 rtc::CritScope cs(&capture_cs_); |
| 78 int height = videoFrame.height(); | 75 int height = videoFrame.height(); |
| 79 int width = videoFrame.width(); | 76 int width = videoFrame.width(); |
| 80 #if defined(ANDROID) && ANDROID | 77 #if defined(ANDROID) && ANDROID |
| 81 // Android camera frames may be rotated depending on test device | 78 // Android camera frames may be rotated depending on test device |
| 82 // orientation. | 79 // orientation. |
| 83 EXPECT_TRUE(height == capability_.height || height == capability_.width); | 80 EXPECT_TRUE(height == capability_.height || height == capability_.width); |
| 84 EXPECT_TRUE(width == capability_.width || width == capability_.height); | 81 EXPECT_TRUE(width == capability_.width || width == capability_.height); |
| 85 #else | 82 #else |
| 86 EXPECT_EQ(height, capability_.height); | 83 EXPECT_EQ(height, capability_.height); |
| 87 EXPECT_EQ(width, capability_.width); | 84 EXPECT_EQ(width, capability_.width); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 100 last_render_time_ms_ > 0)) { | 97 last_render_time_ms_ > 0)) { |
| 101 timing_warnings_++; | 98 timing_warnings_++; |
| 102 } | 99 } |
| 103 | 100 |
| 104 incoming_frames_++; | 101 incoming_frames_++; |
| 105 last_render_time_ms_ = videoFrame.render_time_ms(); | 102 last_render_time_ms_ = videoFrame.render_time_ms(); |
| 106 last_frame_ = videoFrame.video_frame_buffer(); | 103 last_frame_ = videoFrame.video_frame_buffer(); |
| 107 } | 104 } |
| 108 | 105 |
| 109 void SetExpectedCapability(VideoCaptureCapability capability) { | 106 void SetExpectedCapability(VideoCaptureCapability capability) { |
| 110 CriticalSectionScoped cs(capture_cs_.get()); | 107 rtc::CritScope cs(&capture_cs_); |
| 111 capability_= capability; | 108 capability_= capability; |
| 112 incoming_frames_ = 0; | 109 incoming_frames_ = 0; |
| 113 last_render_time_ms_ = 0; | 110 last_render_time_ms_ = 0; |
| 114 } | 111 } |
| 115 int incoming_frames() { | 112 int incoming_frames() { |
| 116 CriticalSectionScoped cs(capture_cs_.get()); | 113 rtc::CritScope cs(&capture_cs_); |
| 117 return incoming_frames_; | 114 return incoming_frames_; |
| 118 } | 115 } |
| 119 | 116 |
| 120 int timing_warnings() { | 117 int timing_warnings() { |
| 121 CriticalSectionScoped cs(capture_cs_.get()); | 118 rtc::CritScope cs(&capture_cs_); |
| 122 return timing_warnings_; | 119 return timing_warnings_; |
| 123 } | 120 } |
| 124 VideoCaptureCapability capability() { | 121 VideoCaptureCapability capability() { |
| 125 CriticalSectionScoped cs(capture_cs_.get()); | 122 rtc::CritScope cs(&capture_cs_); |
| 126 return capability_; | 123 return capability_; |
| 127 } | 124 } |
| 128 | 125 |
| 129 bool CompareLastFrame(const webrtc::VideoFrame& frame) { | 126 bool CompareLastFrame(const webrtc::VideoFrame& frame) { |
| 130 CriticalSectionScoped cs(capture_cs_.get()); | 127 rtc::CritScope cs(&capture_cs_); |
| 131 return webrtc::test::FrameBufsEqual(last_frame_, | 128 return webrtc::test::FrameBufsEqual(last_frame_, |
| 132 frame.video_frame_buffer()); | 129 frame.video_frame_buffer()); |
| 133 } | 130 } |
| 134 | 131 |
| 135 void SetExpectedCaptureRotation(webrtc::VideoRotation rotation) { | 132 void SetExpectedCaptureRotation(webrtc::VideoRotation rotation) { |
| 136 CriticalSectionScoped cs(capture_cs_.get()); | 133 rtc::CritScope cs(&capture_cs_); |
| 137 rotate_frame_ = rotation; | 134 rotate_frame_ = rotation; |
| 138 } | 135 } |
| 139 | 136 |
| 140 private: | 137 private: |
| 141 std::unique_ptr<CriticalSectionWrapper> capture_cs_; | 138 rtc::CriticalSection capture_cs_; |
| 142 VideoCaptureCapability capability_; | 139 VideoCaptureCapability capability_; |
| 143 int64_t last_render_time_ms_; | 140 int64_t last_render_time_ms_; |
| 144 int incoming_frames_; | 141 int incoming_frames_; |
| 145 int timing_warnings_; | 142 int timing_warnings_; |
| 146 rtc::scoped_refptr<webrtc::VideoFrameBuffer> last_frame_; | 143 rtc::scoped_refptr<webrtc::VideoFrameBuffer> last_frame_; |
| 147 webrtc::VideoRotation rotate_frame_; | 144 webrtc::VideoRotation rotate_frame_; |
| 148 }; | 145 }; |
| 149 | 146 |
| 150 class VideoCaptureTest : public testing::Test { | 147 class VideoCaptureTest : public testing::Test { |
| 151 public: | 148 public: |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 418 length, capture_callback_.capability(), 0)); | 415 length, capture_callback_.capability(), 0)); |
| 419 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180)); | 416 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_180)); |
| 420 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180); | 417 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_180); |
| 421 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 418 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
| 422 length, capture_callback_.capability(), 0)); | 419 length, capture_callback_.capability(), 0)); |
| 423 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270)); | 420 EXPECT_EQ(0, capture_module_->SetCaptureRotation(webrtc::kVideoRotation_270)); |
| 424 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270); | 421 capture_callback_.SetExpectedCaptureRotation(webrtc::kVideoRotation_270); |
| 425 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), | 422 EXPECT_EQ(0, capture_input_interface_->IncomingFrame(test_buffer.get(), |
| 426 length, capture_callback_.capability(), 0)); | 423 length, capture_callback_.capability(), 0)); |
| 427 } | 424 } |
| OLD | NEW |