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