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/event.h" |
17 #include "webrtc/base/scoped_ptr.h" | 17 #include "webrtc/base/scoped_ptr.h" |
18 #include "webrtc/modules/utility/include/mock/mock_process_thread.h" | 18 #include "webrtc/modules/utility/include/mock/mock_process_thread.h" |
åsapersson
2016/02/04 11:17:55
remove?
pbos-webrtc
2016/02/04 12:38:04
Done.
| |
19 #include "webrtc/system_wrappers/include/ref_count.h" | 19 #include "webrtc/system_wrappers/include/ref_count.h" |
20 #include "webrtc/system_wrappers/include/scoped_vector.h" | 20 #include "webrtc/system_wrappers/include/scoped_vector.h" |
21 #include "webrtc/test/fake_texture_frame.h" | 21 #include "webrtc/test/fake_texture_frame.h" |
22 #include "webrtc/video/send_statistics_proxy.h" | 22 #include "webrtc/video/send_statistics_proxy.h" |
23 | 23 |
24 using ::testing::_; | 24 using ::testing::_; |
25 using ::testing::Invoke; | 25 using ::testing::Invoke; |
26 using ::testing::NiceMock; | 26 using ::testing::NiceMock; |
27 using ::testing::Return; | 27 using ::testing::Return; |
28 using ::testing::WithArg; | 28 using ::testing::WithArg; |
(...skipping 11 matching lines...) Expand all Loading... | |
40 bool EqualFrames(const VideoFrame& frame1, const VideoFrame& frame2); | 40 bool EqualFrames(const VideoFrame& frame1, const VideoFrame& frame2); |
41 bool EqualTextureFrames(const VideoFrame& frame1, const VideoFrame& frame2); | 41 bool EqualTextureFrames(const VideoFrame& frame1, const VideoFrame& frame2); |
42 bool EqualBufferFrames(const VideoFrame& frame1, const VideoFrame& frame2); | 42 bool EqualBufferFrames(const VideoFrame& frame1, const VideoFrame& frame2); |
43 bool EqualFramesVector(const ScopedVector<VideoFrame>& frames1, | 43 bool EqualFramesVector(const ScopedVector<VideoFrame>& frames1, |
44 const ScopedVector<VideoFrame>& frames2); | 44 const ScopedVector<VideoFrame>& frames2); |
45 VideoFrame* CreateVideoFrame(uint8_t length); | 45 VideoFrame* CreateVideoFrame(uint8_t length); |
46 | 46 |
47 class VideoCaptureInputTest : public ::testing::Test { | 47 class VideoCaptureInputTest : public ::testing::Test { |
48 protected: | 48 protected: |
49 VideoCaptureInputTest() | 49 VideoCaptureInputTest() |
50 : mock_process_thread_(new NiceMock<MockProcessThread>), | 50 : stats_proxy_(Clock::GetRealTimeClock(), |
51 webrtc::VideoSendStream::Config(nullptr), | |
52 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo), | |
51 mock_frame_callback_(new NiceMock<MockVideoCaptureCallback>), | 53 mock_frame_callback_(new NiceMock<MockVideoCaptureCallback>), |
52 output_frame_event_(false, false), | 54 output_frame_event_(false, false) {} |
53 stats_proxy_(Clock::GetRealTimeClock(), | |
54 webrtc::VideoSendStream::Config(nullptr), | |
55 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo) {} | |
56 | 55 |
57 virtual void SetUp() { | 56 virtual void SetUp() { |
58 EXPECT_CALL(*mock_frame_callback_, DeliverFrame(_)) | 57 EXPECT_CALL(*mock_frame_callback_, DeliverFrame(_)) |
59 .WillRepeatedly( | 58 .WillRepeatedly( |
60 WithArg<0>(Invoke(this, &VideoCaptureInputTest::AddOutputFrame))); | 59 WithArg<0>(Invoke(this, &VideoCaptureInputTest::AddOutputFrame))); |
61 | 60 |
62 input_.reset(new internal::VideoCaptureInput( | 61 overuse_detector_.reset( |
63 mock_process_thread_.get(), mock_frame_callback_.get(), nullptr, | 62 new OveruseFrameDetector(Clock::GetRealTimeClock(), CpuOveruseOptions(), |
64 &stats_proxy_, nullptr, nullptr)); | 63 nullptr, nullptr, &stats_proxy_)); |
65 } | 64 input_.reset(new internal::VideoCaptureInput(mock_frame_callback_.get(), |
66 | 65 nullptr, &stats_proxy_, |
67 virtual void TearDown() { | 66 overuse_detector_.get())); |
68 // VideoCaptureInput accesses |mock_process_thread_| in destructor and | |
69 // should | |
70 // be deleted first. | |
71 input_.reset(); | |
72 } | 67 } |
73 | 68 |
74 void AddInputFrame(VideoFrame* frame) { | 69 void AddInputFrame(VideoFrame* frame) { |
75 input_->IncomingCapturedFrame(*frame); | 70 input_->IncomingCapturedFrame(*frame); |
76 } | 71 } |
77 | 72 |
78 void AddOutputFrame(const VideoFrame& frame) { | 73 void AddOutputFrame(const VideoFrame& frame) { |
79 if (frame.native_handle() == NULL) | 74 if (frame.native_handle() == NULL) |
80 output_frame_ybuffers_.push_back(frame.buffer(kYPlane)); | 75 output_frame_ybuffers_.push_back(frame.buffer(kYPlane)); |
81 output_frames_.push_back(new VideoFrame(frame)); | 76 output_frames_.push_back(new VideoFrame(frame)); |
82 output_frame_event_.Set(); | 77 output_frame_event_.Set(); |
83 } | 78 } |
84 | 79 |
85 void WaitOutputFrame() { | 80 void WaitOutputFrame() { |
86 EXPECT_TRUE(output_frame_event_.Wait(FRAME_TIMEOUT_MS)); | 81 EXPECT_TRUE(output_frame_event_.Wait(FRAME_TIMEOUT_MS)); |
87 } | 82 } |
88 | 83 |
89 rtc::scoped_ptr<MockProcessThread> mock_process_thread_; | 84 SendStatisticsProxy stats_proxy_; |
85 | |
90 rtc::scoped_ptr<MockVideoCaptureCallback> mock_frame_callback_; | 86 rtc::scoped_ptr<MockVideoCaptureCallback> mock_frame_callback_; |
91 | 87 |
88 rtc::scoped_ptr<OveruseFrameDetector> overuse_detector_; | |
89 | |
92 // Used to send input capture frames to VideoCaptureInput. | 90 // Used to send input capture frames to VideoCaptureInput. |
93 rtc::scoped_ptr<internal::VideoCaptureInput> input_; | 91 rtc::scoped_ptr<internal::VideoCaptureInput> input_; |
94 | 92 |
95 // Input capture frames of VideoCaptureInput. | 93 // Input capture frames of VideoCaptureInput. |
96 ScopedVector<VideoFrame> input_frames_; | 94 ScopedVector<VideoFrame> input_frames_; |
97 | 95 |
98 // Indicate an output frame has arrived. | 96 // Indicate an output frame has arrived. |
99 rtc::Event output_frame_event_; | 97 rtc::Event output_frame_event_; |
100 | 98 |
101 // Output delivered frames of VideoCaptureInput. | 99 // Output delivered frames of VideoCaptureInput. |
102 ScopedVector<VideoFrame> output_frames_; | 100 ScopedVector<VideoFrame> output_frames_; |
103 | 101 |
104 // The pointers of Y plane buffers of output frames. This is used to verify | 102 // The pointers of Y plane buffers of output frames. This is used to verify |
105 // the frame are swapped and not copied. | 103 // the frame are swapped and not copied. |
106 std::vector<const uint8_t*> output_frame_ybuffers_; | 104 std::vector<const uint8_t*> output_frame_ybuffers_; |
107 SendStatisticsProxy stats_proxy_; | |
108 }; | 105 }; |
109 | 106 |
110 TEST_F(VideoCaptureInputTest, DoesNotRetainHandleNorCopyBuffer) { | 107 TEST_F(VideoCaptureInputTest, DoesNotRetainHandleNorCopyBuffer) { |
111 // Indicate an output frame has arrived. | 108 // Indicate an output frame has arrived. |
112 rtc::Event frame_destroyed_event(false, false); | 109 rtc::Event frame_destroyed_event(false, false); |
113 class TestBuffer : public webrtc::I420Buffer { | 110 class TestBuffer : public webrtc::I420Buffer { |
114 public: | 111 public: |
115 explicit TestBuffer(rtc::Event* event) : I420Buffer(5, 5), event_(event) {} | 112 explicit TestBuffer(rtc::Event* event) : I420Buffer(5, 5), event_(event) {} |
116 | 113 |
117 private: | 114 private: |
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 const int kSizeY = width * height * 2; | 290 const int kSizeY = width * height * 2; |
294 uint8_t buffer[kSizeY]; | 291 uint8_t buffer[kSizeY]; |
295 memset(buffer, data, kSizeY); | 292 memset(buffer, data, kSizeY); |
296 frame->CreateFrame(buffer, buffer, buffer, width, height, width, width / 2, | 293 frame->CreateFrame(buffer, buffer, buffer, width, height, width, width / 2, |
297 width / 2); | 294 width / 2); |
298 frame->set_render_time_ms(data); | 295 frame->set_render_time_ms(data); |
299 return frame; | 296 return frame; |
300 } | 297 } |
301 | 298 |
302 } // namespace webrtc | 299 } // namespace webrtc |
OLD | NEW |