OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2014 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 #include "webrtc/video/video_capture_input.h" | 10 #include "webrtc/video/video_capture_input.h" |
11 | 11 |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
| 16 #include "webrtc/base/event.h" |
16 #include "webrtc/base/scoped_ptr.h" | 17 #include "webrtc/base/scoped_ptr.h" |
17 #include "webrtc/common.h" | 18 #include "webrtc/common.h" |
18 #include "webrtc/modules/utility/include/mock/mock_process_thread.h" | 19 #include "webrtc/modules/utility/include/mock/mock_process_thread.h" |
19 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | 20 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" |
20 #include "webrtc/system_wrappers/include/event_wrapper.h" | |
21 #include "webrtc/system_wrappers/include/ref_count.h" | 21 #include "webrtc/system_wrappers/include/ref_count.h" |
22 #include "webrtc/system_wrappers/include/scoped_vector.h" | 22 #include "webrtc/system_wrappers/include/scoped_vector.h" |
23 #include "webrtc/test/fake_texture_frame.h" | 23 #include "webrtc/test/fake_texture_frame.h" |
24 #include "webrtc/video/send_statistics_proxy.h" | 24 #include "webrtc/video/send_statistics_proxy.h" |
25 | 25 |
26 using ::testing::_; | 26 using ::testing::_; |
27 using ::testing::Invoke; | 27 using ::testing::Invoke; |
28 using ::testing::NiceMock; | 28 using ::testing::NiceMock; |
29 using ::testing::Return; | 29 using ::testing::Return; |
30 using ::testing::WithArg; | 30 using ::testing::WithArg; |
(...skipping 13 matching lines...) Expand all Loading... |
44 bool EqualBufferFrames(const VideoFrame& frame1, const VideoFrame& frame2); | 44 bool EqualBufferFrames(const VideoFrame& frame1, const VideoFrame& frame2); |
45 bool EqualFramesVector(const ScopedVector<VideoFrame>& frames1, | 45 bool EqualFramesVector(const ScopedVector<VideoFrame>& frames1, |
46 const ScopedVector<VideoFrame>& frames2); | 46 const ScopedVector<VideoFrame>& frames2); |
47 VideoFrame* CreateVideoFrame(uint8_t length); | 47 VideoFrame* CreateVideoFrame(uint8_t length); |
48 | 48 |
49 class VideoCaptureInputTest : public ::testing::Test { | 49 class VideoCaptureInputTest : public ::testing::Test { |
50 protected: | 50 protected: |
51 VideoCaptureInputTest() | 51 VideoCaptureInputTest() |
52 : mock_process_thread_(new NiceMock<MockProcessThread>), | 52 : mock_process_thread_(new NiceMock<MockProcessThread>), |
53 mock_frame_callback_(new NiceMock<MockVideoCaptureCallback>), | 53 mock_frame_callback_(new NiceMock<MockVideoCaptureCallback>), |
54 output_frame_event_(EventWrapper::Create()), | 54 output_frame_event_(false, false), |
55 stats_proxy_(Clock::GetRealTimeClock(), | 55 stats_proxy_(Clock::GetRealTimeClock(), |
56 webrtc::VideoSendStream::Config(nullptr), | 56 webrtc::VideoSendStream::Config(nullptr), |
57 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo) {} | 57 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo) {} |
58 | 58 |
59 virtual void SetUp() { | 59 virtual void SetUp() { |
60 EXPECT_CALL(*mock_frame_callback_, DeliverFrame(_)) | 60 EXPECT_CALL(*mock_frame_callback_, DeliverFrame(_)) |
61 .WillRepeatedly( | 61 .WillRepeatedly( |
62 WithArg<0>(Invoke(this, &VideoCaptureInputTest::AddOutputFrame))); | 62 WithArg<0>(Invoke(this, &VideoCaptureInputTest::AddOutputFrame))); |
63 | 63 |
64 Config config; | 64 Config config; |
(...skipping 10 matching lines...) Expand all Loading... |
75 } | 75 } |
76 | 76 |
77 void AddInputFrame(VideoFrame* frame) { | 77 void AddInputFrame(VideoFrame* frame) { |
78 input_->IncomingCapturedFrame(*frame); | 78 input_->IncomingCapturedFrame(*frame); |
79 } | 79 } |
80 | 80 |
81 void AddOutputFrame(const VideoFrame& frame) { | 81 void AddOutputFrame(const VideoFrame& frame) { |
82 if (frame.native_handle() == NULL) | 82 if (frame.native_handle() == NULL) |
83 output_frame_ybuffers_.push_back(frame.buffer(kYPlane)); | 83 output_frame_ybuffers_.push_back(frame.buffer(kYPlane)); |
84 output_frames_.push_back(new VideoFrame(frame)); | 84 output_frames_.push_back(new VideoFrame(frame)); |
85 output_frame_event_->Set(); | 85 output_frame_event_.Set(); |
86 } | 86 } |
87 | 87 |
88 void WaitOutputFrame() { | 88 void WaitOutputFrame() { |
89 EXPECT_EQ(kEventSignaled, output_frame_event_->Wait(FRAME_TIMEOUT_MS)); | 89 EXPECT_TRUE(output_frame_event_.Wait(FRAME_TIMEOUT_MS)); |
90 } | 90 } |
91 | 91 |
92 rtc::scoped_ptr<MockProcessThread> mock_process_thread_; | 92 rtc::scoped_ptr<MockProcessThread> mock_process_thread_; |
93 rtc::scoped_ptr<MockVideoCaptureCallback> mock_frame_callback_; | 93 rtc::scoped_ptr<MockVideoCaptureCallback> mock_frame_callback_; |
94 | 94 |
95 // Used to send input capture frames to VideoCaptureInput. | 95 // Used to send input capture frames to VideoCaptureInput. |
96 rtc::scoped_ptr<internal::VideoCaptureInput> input_; | 96 rtc::scoped_ptr<internal::VideoCaptureInput> input_; |
97 | 97 |
98 // Input capture frames of VideoCaptureInput. | 98 // Input capture frames of VideoCaptureInput. |
99 ScopedVector<VideoFrame> input_frames_; | 99 ScopedVector<VideoFrame> input_frames_; |
100 | 100 |
101 // Indicate an output frame has arrived. | 101 // Indicate an output frame has arrived. |
102 rtc::scoped_ptr<EventWrapper> output_frame_event_; | 102 rtc::Event output_frame_event_; |
103 | 103 |
104 // Output delivered frames of VideoCaptureInput. | 104 // Output delivered frames of VideoCaptureInput. |
105 ScopedVector<VideoFrame> output_frames_; | 105 ScopedVector<VideoFrame> output_frames_; |
106 | 106 |
107 // The pointers of Y plane buffers of output frames. This is used to verify | 107 // The pointers of Y plane buffers of output frames. This is used to verify |
108 // the frame are swapped and not copied. | 108 // the frame are swapped and not copied. |
109 std::vector<const uint8_t*> output_frame_ybuffers_; | 109 std::vector<const uint8_t*> output_frame_ybuffers_; |
110 SendStatisticsProxy stats_proxy_; | 110 SendStatisticsProxy stats_proxy_; |
111 }; | 111 }; |
112 | 112 |
113 TEST_F(VideoCaptureInputTest, DoesNotRetainHandleNorCopyBuffer) { | 113 TEST_F(VideoCaptureInputTest, DoesNotRetainHandleNorCopyBuffer) { |
114 // Indicate an output frame has arrived. | 114 // Indicate an output frame has arrived. |
115 rtc::scoped_ptr<EventWrapper> frame_destroyed_event(EventWrapper::Create()); | 115 rtc::Event frame_destroyed_event(false, false); |
116 class TestBuffer : public webrtc::I420Buffer { | 116 class TestBuffer : public webrtc::I420Buffer { |
117 public: | 117 public: |
118 explicit TestBuffer(EventWrapper* event) | 118 explicit TestBuffer(rtc::Event* event) : I420Buffer(5, 5), event_(event) {} |
119 : I420Buffer(5, 5), event_(event) {} | |
120 | 119 |
121 private: | 120 private: |
122 friend class rtc::RefCountedObject<TestBuffer>; | 121 friend class rtc::RefCountedObject<TestBuffer>; |
123 ~TestBuffer() override { event_->Set(); } | 122 ~TestBuffer() override { event_->Set(); } |
124 EventWrapper* event_; | 123 rtc::Event* const event_; |
125 }; | 124 }; |
126 | 125 |
127 VideoFrame frame( | 126 VideoFrame frame( |
128 new rtc::RefCountedObject<TestBuffer>(frame_destroyed_event.get()), 1, 1, | 127 new rtc::RefCountedObject<TestBuffer>(&frame_destroyed_event), 1, 1, |
129 kVideoRotation_0); | 128 kVideoRotation_0); |
130 | 129 |
131 AddInputFrame(&frame); | 130 AddInputFrame(&frame); |
132 WaitOutputFrame(); | 131 WaitOutputFrame(); |
133 | 132 |
134 EXPECT_EQ(output_frames_[0]->video_frame_buffer().get(), | 133 EXPECT_EQ(output_frames_[0]->video_frame_buffer().get(), |
135 frame.video_frame_buffer().get()); | 134 frame.video_frame_buffer().get()); |
136 output_frames_.clear(); | 135 output_frames_.clear(); |
137 frame.Reset(); | 136 frame.Reset(); |
138 EXPECT_EQ(kEventSignaled, frame_destroyed_event->Wait(FRAME_TIMEOUT_MS)); | 137 EXPECT_TRUE(frame_destroyed_event.Wait(FRAME_TIMEOUT_MS)); |
139 } | 138 } |
140 | 139 |
141 TEST_F(VideoCaptureInputTest, TestNtpTimeStampSetIfRenderTimeSet) { | 140 TEST_F(VideoCaptureInputTest, TestNtpTimeStampSetIfRenderTimeSet) { |
142 input_frames_.push_back(CreateVideoFrame(0)); | 141 input_frames_.push_back(CreateVideoFrame(0)); |
143 input_frames_[0]->set_render_time_ms(5); | 142 input_frames_[0]->set_render_time_ms(5); |
144 input_frames_[0]->set_ntp_time_ms(0); | 143 input_frames_[0]->set_ntp_time_ms(0); |
145 | 144 |
146 AddInputFrame(input_frames_[0]); | 145 AddInputFrame(input_frames_[0]); |
147 WaitOutputFrame(); | 146 WaitOutputFrame(); |
148 EXPECT_GT(output_frames_[0]->ntp_time_ms(), | 147 EXPECT_GT(output_frames_[0]->ntp_time_ms(), |
(...skipping 16 matching lines...) Expand all Loading... |
165 input_frames_.push_back(CreateVideoFrame(0)); | 164 input_frames_.push_back(CreateVideoFrame(0)); |
166 | 165 |
167 input_frames_[0]->set_ntp_time_ms(17); | 166 input_frames_[0]->set_ntp_time_ms(17); |
168 AddInputFrame(input_frames_[0]); | 167 AddInputFrame(input_frames_[0]); |
169 WaitOutputFrame(); | 168 WaitOutputFrame(); |
170 EXPECT_EQ(output_frames_[0]->timestamp(), | 169 EXPECT_EQ(output_frames_[0]->timestamp(), |
171 input_frames_[0]->ntp_time_ms() * 90); | 170 input_frames_[0]->ntp_time_ms() * 90); |
172 | 171 |
173 // Repeat frame with the same NTP timestamp should drop. | 172 // Repeat frame with the same NTP timestamp should drop. |
174 AddInputFrame(input_frames_[0]); | 173 AddInputFrame(input_frames_[0]); |
175 EXPECT_EQ(kEventTimeout, output_frame_event_->Wait(FRAME_TIMEOUT_MS)); | 174 EXPECT_FALSE(output_frame_event_.Wait(FRAME_TIMEOUT_MS)); |
176 | 175 |
177 // As should frames with a decreased NTP timestamp. | 176 // As should frames with a decreased NTP timestamp. |
178 input_frames_[0]->set_ntp_time_ms(input_frames_[0]->ntp_time_ms() - 1); | 177 input_frames_[0]->set_ntp_time_ms(input_frames_[0]->ntp_time_ms() - 1); |
179 AddInputFrame(input_frames_[0]); | 178 AddInputFrame(input_frames_[0]); |
180 EXPECT_EQ(kEventTimeout, output_frame_event_->Wait(FRAME_TIMEOUT_MS)); | 179 EXPECT_FALSE(output_frame_event_.Wait(FRAME_TIMEOUT_MS)); |
181 | 180 |
182 // But delivering with an increased NTP timestamp should succeed. | 181 // But delivering with an increased NTP timestamp should succeed. |
183 input_frames_[0]->set_ntp_time_ms(4711); | 182 input_frames_[0]->set_ntp_time_ms(4711); |
184 AddInputFrame(input_frames_[0]); | 183 AddInputFrame(input_frames_[0]); |
185 WaitOutputFrame(); | 184 WaitOutputFrame(); |
186 EXPECT_EQ(output_frames_[1]->timestamp(), | 185 EXPECT_EQ(output_frames_[1]->timestamp(), |
187 input_frames_[0]->ntp_time_ms() * 90); | 186 input_frames_[0]->ntp_time_ms() * 90); |
188 } | 187 } |
189 | 188 |
190 TEST_F(VideoCaptureInputTest, TestTextureFrames) { | 189 TEST_F(VideoCaptureInputTest, TestTextureFrames) { |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 const int kSizeY = width * height * 2; | 296 const int kSizeY = width * height * 2; |
298 uint8_t buffer[kSizeY]; | 297 uint8_t buffer[kSizeY]; |
299 memset(buffer, data, kSizeY); | 298 memset(buffer, data, kSizeY); |
300 frame->CreateFrame(buffer, buffer, buffer, width, height, width, width / 2, | 299 frame->CreateFrame(buffer, buffer, buffer, width, height, width, width / 2, |
301 width / 2); | 300 width / 2); |
302 frame->set_render_time_ms(data); | 301 frame->set_render_time_ms(data); |
303 return frame; | 302 return frame; |
304 } | 303 } |
305 | 304 |
306 } // namespace webrtc | 305 } // namespace webrtc |
OLD | NEW |