| 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 | 10 |
| 11 // This file includes unit tests for ViECapturer. | 11 // This file includes unit tests for ViECapturer. |
| 12 | 12 |
| 13 #include "webrtc/video_engine/vie_capturer.h" | 13 #include "webrtc/video_engine/vie_capturer.h" |
| 14 | 14 |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 17 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "webrtc/base/scoped_ptr.h" | 19 #include "webrtc/base/scoped_ptr.h" |
| 20 #include "webrtc/common.h" | 20 #include "webrtc/common.h" |
| 21 #include "webrtc/modules/utility/interface/mock/mock_process_thread.h" | 21 #include "webrtc/modules/utility/interface/mock/mock_process_thread.h" |
| 22 #include "webrtc/modules/video_capture/include/mock/mock_video_capture.h" | 22 #include "webrtc/modules/video_capture/include/mock/mock_video_capture.h" |
| 23 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" | 23 #include "webrtc/system_wrappers/interface/critical_section_wrapper.h" |
| 24 #include "webrtc/system_wrappers/interface/event_wrapper.h" | 24 #include "webrtc/system_wrappers/interface/event_wrapper.h" |
| 25 #include "webrtc/system_wrappers/interface/ref_count.h" | 25 #include "webrtc/system_wrappers/interface/ref_count.h" |
| 26 #include "webrtc/system_wrappers/interface/scoped_vector.h" | 26 #include "webrtc/system_wrappers/interface/scoped_vector.h" |
| 27 #include "webrtc/test/fake_texture_frame.h" |
| 27 | 28 |
| 28 using ::testing::_; | 29 using ::testing::_; |
| 29 using ::testing::Invoke; | 30 using ::testing::Invoke; |
| 30 using ::testing::NiceMock; | 31 using ::testing::NiceMock; |
| 31 using ::testing::Return; | 32 using ::testing::Return; |
| 32 using ::testing::WithArg; | 33 using ::testing::WithArg; |
| 33 | 34 |
| 34 // If an output frame does not arrive in 500ms, the test will fail. | 35 // If an output frame does not arrive in 500ms, the test will fail. |
| 35 #define FRAME_TIMEOUT_MS 500 | 36 #define FRAME_TIMEOUT_MS 500 |
| 36 | 37 |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 | 153 |
| 153 AddInputFrame(input_frames_[0]); | 154 AddInputFrame(input_frames_[0]); |
| 154 WaitOutputFrame(); | 155 WaitOutputFrame(); |
| 155 EXPECT_EQ(output_frames_[0]->timestamp(), | 156 EXPECT_EQ(output_frames_[0]->timestamp(), |
| 156 input_frames_[0]->ntp_time_ms() * 90); | 157 input_frames_[0]->ntp_time_ms() * 90); |
| 157 } | 158 } |
| 158 | 159 |
| 159 TEST_F(ViECapturerTest, TestTextureFrames) { | 160 TEST_F(ViECapturerTest, TestTextureFrames) { |
| 160 const int kNumFrame = 3; | 161 const int kNumFrame = 3; |
| 161 for (int i = 0 ; i < kNumFrame; ++i) { | 162 for (int i = 0 ; i < kNumFrame; ++i) { |
| 162 void* dummy_handle = reinterpret_cast<void*>(i+1); | 163 test::FakeNativeHandle* dummy_handle = new test::FakeNativeHandle(); |
| 163 // Add one to |i| so that width/height > 0. | 164 // Add one to |i| so that width/height > 0. |
| 164 input_frames_.push_back(new VideoFrame(dummy_handle, i + 1, i + 1, i + 1, | 165 input_frames_.push_back(new VideoFrame(test::CreateFakeNativeHandleFrame( |
| 165 i + 1, webrtc::kVideoRotation_0, | 166 dummy_handle, i + 1, i + 1, i + 1, i + 1, webrtc::kVideoRotation_0))); |
| 166 rtc::Callback0<void>())); | |
| 167 AddInputFrame(input_frames_[i]); | 167 AddInputFrame(input_frames_[i]); |
| 168 WaitOutputFrame(); | 168 WaitOutputFrame(); |
| 169 EXPECT_EQ(dummy_handle, output_frames_[i]->native_handle()); | 169 EXPECT_EQ(dummy_handle, output_frames_[i]->native_handle()); |
| 170 } | 170 } |
| 171 | 171 |
| 172 EXPECT_TRUE(EqualFramesVector(input_frames_, output_frames_)); | 172 EXPECT_TRUE(EqualFramesVector(input_frames_, output_frames_)); |
| 173 } | 173 } |
| 174 | 174 |
| 175 TEST_F(ViECapturerTest, TestI420Frames) { | 175 TEST_F(ViECapturerTest, TestI420Frames) { |
| 176 const int kNumFrame = 4; | 176 const int kNumFrame = 4; |
| 177 std::vector<const uint8_t*> ybuffer_pointers; | 177 std::vector<const uint8_t*> ybuffer_pointers; |
| 178 for (int i = 0; i < kNumFrame; ++i) { | 178 for (int i = 0; i < kNumFrame; ++i) { |
| 179 input_frames_.push_back(CreateVideoFrame(static_cast<uint8_t>(i + 1))); | 179 input_frames_.push_back(CreateVideoFrame(static_cast<uint8_t>(i + 1))); |
| 180 const VideoFrame* const_input_frame = input_frames_[i]; | 180 const VideoFrame* const_input_frame = input_frames_[i]; |
| 181 ybuffer_pointers.push_back(const_input_frame->buffer(kYPlane)); | 181 ybuffer_pointers.push_back(const_input_frame->buffer(kYPlane)); |
| 182 AddInputFrame(input_frames_[i]); | 182 AddInputFrame(input_frames_[i]); |
| 183 WaitOutputFrame(); | 183 WaitOutputFrame(); |
| 184 } | 184 } |
| 185 | 185 |
| 186 EXPECT_TRUE(EqualFramesVector(input_frames_, output_frames_)); | 186 EXPECT_TRUE(EqualFramesVector(input_frames_, output_frames_)); |
| 187 // Make sure the buffer is not copied. | 187 // Make sure the buffer is not copied. |
| 188 for (int i = 0; i < kNumFrame; ++i) | 188 for (int i = 0; i < kNumFrame; ++i) |
| 189 EXPECT_EQ(ybuffer_pointers[i], output_frame_ybuffers_[i]); | 189 EXPECT_EQ(ybuffer_pointers[i], output_frame_ybuffers_[i]); |
| 190 } | 190 } |
| 191 | 191 |
| 192 TEST_F(ViECapturerTest, TestI420FrameAfterTextureFrame) { | 192 TEST_F(ViECapturerTest, TestI420FrameAfterTextureFrame) { |
| 193 void* dummy_handle = &input_frames_; | 193 test::FakeNativeHandle* dummy_handle = new test::FakeNativeHandle(); |
| 194 input_frames_.push_back(new VideoFrame(dummy_handle, 1, 1, 1, 1, | 194 input_frames_.push_back(new VideoFrame(test::CreateFakeNativeHandleFrame( |
| 195 webrtc::kVideoRotation_0, | 195 dummy_handle, 1, 1, 1, 1, webrtc::kVideoRotation_0))); |
| 196 rtc::Callback0<void>())); | |
| 197 AddInputFrame(input_frames_[0]); | 196 AddInputFrame(input_frames_[0]); |
| 198 WaitOutputFrame(); | 197 WaitOutputFrame(); |
| 199 EXPECT_EQ(dummy_handle, output_frames_[0]->native_handle()); | 198 EXPECT_EQ(dummy_handle, output_frames_[0]->native_handle()); |
| 200 | 199 |
| 201 input_frames_.push_back(CreateVideoFrame(2)); | 200 input_frames_.push_back(CreateVideoFrame(2)); |
| 202 AddInputFrame(input_frames_[1]); | 201 AddInputFrame(input_frames_[1]); |
| 203 WaitOutputFrame(); | 202 WaitOutputFrame(); |
| 204 | 203 |
| 205 EXPECT_TRUE(EqualFramesVector(input_frames_, output_frames_)); | 204 EXPECT_TRUE(EqualFramesVector(input_frames_, output_frames_)); |
| 206 } | 205 } |
| 207 | 206 |
| 208 TEST_F(ViECapturerTest, TestTextureFrameAfterI420Frame) { | 207 TEST_F(ViECapturerTest, TestTextureFrameAfterI420Frame) { |
| 209 input_frames_.push_back(CreateVideoFrame(1)); | 208 input_frames_.push_back(CreateVideoFrame(1)); |
| 210 AddInputFrame(input_frames_[0]); | 209 AddInputFrame(input_frames_[0]); |
| 211 WaitOutputFrame(); | 210 WaitOutputFrame(); |
| 212 | 211 |
| 213 void* dummy_handle = &input_frames_; | 212 test::FakeNativeHandle* dummy_handle = new test::FakeNativeHandle(); |
| 214 input_frames_.push_back(new VideoFrame(dummy_handle, 1, 1, 2, 2, | 213 input_frames_.push_back(new VideoFrame(test::CreateFakeNativeHandleFrame( |
| 215 webrtc::kVideoRotation_0, | 214 dummy_handle, 1, 1, 2, 2, webrtc::kVideoRotation_0))); |
| 216 rtc::Callback0<void>())); | |
| 217 AddInputFrame(input_frames_[1]); | 215 AddInputFrame(input_frames_[1]); |
| 218 WaitOutputFrame(); | 216 WaitOutputFrame(); |
| 219 | 217 |
| 220 EXPECT_TRUE(EqualFramesVector(input_frames_, output_frames_)); | 218 EXPECT_TRUE(EqualFramesVector(input_frames_, output_frames_)); |
| 221 } | 219 } |
| 222 | 220 |
| 223 bool EqualFrames(const VideoFrame& frame1, const VideoFrame& frame2) { | 221 bool EqualFrames(const VideoFrame& frame1, const VideoFrame& frame2) { |
| 224 if (frame1.native_handle() != NULL || frame2.native_handle() != NULL) | 222 if (frame1.native_handle() != NULL || frame2.native_handle() != NULL) |
| 225 return EqualTextureFrames(frame1, frame2); | 223 return EqualTextureFrames(frame1, frame2); |
| 226 return EqualBufferFrames(frame1, frame2); | 224 return EqualBufferFrames(frame1, frame2); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 uint8_t buffer[kSizeY]; | 268 uint8_t buffer[kSizeY]; |
| 271 memset(buffer, data, kSizeY); | 269 memset(buffer, data, kSizeY); |
| 272 frame->CreateFrame( | 270 frame->CreateFrame( |
| 273 buffer, buffer, buffer, width, height, width, | 271 buffer, buffer, buffer, width, height, width, |
| 274 width / 2, width / 2); | 272 width / 2, width / 2); |
| 275 frame->set_render_time_ms(data); | 273 frame->set_render_time_ms(data); |
| 276 return frame; | 274 return frame; |
| 277 } | 275 } |
| 278 | 276 |
| 279 } // namespace webrtc | 277 } // namespace webrtc |
| OLD | NEW |