Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(106)

Side by Side Diff: webrtc/video/video_capture_input_unittest.cc

Issue 1763693002: Move encoder thread to VideoSendStream. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: feedback Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/video/video_capture_input.cc ('k') | webrtc/video/video_receive_stream.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <memory> 12 #include <memory>
13 #include <vector> 13 #include <vector>
14 14
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
17 #include "webrtc/base/event.h" 16 #include "webrtc/base/event.h"
18 #include "webrtc/system_wrappers/include/ref_count.h" 17 #include "webrtc/system_wrappers/include/ref_count.h"
19 #include "webrtc/system_wrappers/include/scoped_vector.h" 18 #include "webrtc/system_wrappers/include/scoped_vector.h"
20 #include "webrtc/test/fake_texture_frame.h" 19 #include "webrtc/test/fake_texture_frame.h"
21 #include "webrtc/video/send_statistics_proxy.h" 20 #include "webrtc/video/send_statistics_proxy.h"
22 21
23 using ::testing::_;
24 using ::testing::Invoke;
25 using ::testing::NiceMock;
26 using ::testing::Return;
27 using ::testing::WithArg;
28
29 // If an output frame does not arrive in 500ms, the test will fail. 22 // If an output frame does not arrive in 500ms, the test will fail.
30 #define FRAME_TIMEOUT_MS 500 23 #define FRAME_TIMEOUT_MS 500
31 24
32 namespace webrtc { 25 namespace webrtc {
33 26
34 class MockVideoCaptureCallback : public VideoCaptureCallback {
35 public:
36 MOCK_METHOD1(DeliverFrame, void(VideoFrame video_frame));
37 };
38
39 bool EqualFrames(const VideoFrame& frame1, const VideoFrame& frame2); 27 bool EqualFrames(const VideoFrame& frame1, const VideoFrame& frame2);
40 bool EqualTextureFrames(const VideoFrame& frame1, const VideoFrame& frame2); 28 bool EqualTextureFrames(const VideoFrame& frame1, const VideoFrame& frame2);
41 bool EqualBufferFrames(const VideoFrame& frame1, const VideoFrame& frame2); 29 bool EqualBufferFrames(const VideoFrame& frame1, const VideoFrame& frame2);
42 bool EqualFramesVector(const ScopedVector<VideoFrame>& frames1, 30 bool EqualFramesVector(const ScopedVector<VideoFrame>& frames1,
43 const ScopedVector<VideoFrame>& frames2); 31 const ScopedVector<VideoFrame>& frames2);
44 VideoFrame* CreateVideoFrame(uint8_t length); 32 VideoFrame* CreateVideoFrame(uint8_t length);
45 33
46 class VideoCaptureInputTest : public ::testing::Test { 34 class VideoCaptureInputTest : public ::testing::Test {
47 protected: 35 protected:
48 VideoCaptureInputTest() 36 VideoCaptureInputTest()
49 : stats_proxy_(Clock::GetRealTimeClock(), 37 : stats_proxy_(Clock::GetRealTimeClock(),
50 webrtc::VideoSendStream::Config(nullptr), 38 webrtc::VideoSendStream::Config(nullptr),
51 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo), 39 webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo),
52 mock_frame_callback_(new NiceMock<MockVideoCaptureCallback>), 40 capture_event_(false, false) {}
53 output_frame_event_(false, false) {}
54 41
55 virtual void SetUp() { 42 virtual void SetUp() {
56 EXPECT_CALL(*mock_frame_callback_, DeliverFrame(_))
57 .WillRepeatedly(
58 WithArg<0>(Invoke(this, &VideoCaptureInputTest::AddOutputFrame)));
59
60 overuse_detector_.reset( 43 overuse_detector_.reset(
61 new OveruseFrameDetector(Clock::GetRealTimeClock(), CpuOveruseOptions(), 44 new OveruseFrameDetector(Clock::GetRealTimeClock(), CpuOveruseOptions(),
62 nullptr, nullptr, &stats_proxy_)); 45 nullptr, nullptr, &stats_proxy_));
63 input_.reset(new internal::VideoCaptureInput(mock_frame_callback_.get(), 46 input_.reset(new internal::VideoCaptureInput(
64 nullptr, &stats_proxy_, 47 &capture_event_, nullptr, &stats_proxy_, overuse_detector_.get()));
65 overuse_detector_.get()));
66 } 48 }
67 49
68 void AddInputFrame(VideoFrame* frame) { 50 void AddInputFrame(VideoFrame* frame) {
69 input_->IncomingCapturedFrame(*frame); 51 input_->IncomingCapturedFrame(*frame);
70 } 52 }
71 53
72 void AddOutputFrame(const VideoFrame& frame) { 54 void WaitOutputFrame() {
73 if (frame.native_handle() == NULL) 55 EXPECT_TRUE(capture_event_.Wait(FRAME_TIMEOUT_MS));
74 output_frame_ybuffers_.push_back(frame.buffer(kYPlane)); 56 VideoFrame frame;
57 EXPECT_TRUE(input_->GetVideoFrame(&frame));
58 if (!frame.native_handle()) {
59 output_frame_ybuffers_.push_back(
60 static_cast<const VideoFrame*>(&frame)->buffer(kYPlane));
61 }
75 output_frames_.push_back(new VideoFrame(frame)); 62 output_frames_.push_back(new VideoFrame(frame));
76 output_frame_event_.Set();
77 }
78
79 void WaitOutputFrame() {
80 EXPECT_TRUE(output_frame_event_.Wait(FRAME_TIMEOUT_MS));
81 } 63 }
82 64
83 SendStatisticsProxy stats_proxy_; 65 SendStatisticsProxy stats_proxy_;
84 66
85 std::unique_ptr<MockVideoCaptureCallback> mock_frame_callback_; 67 rtc::Event capture_event_;
86 68
87 std::unique_ptr<OveruseFrameDetector> overuse_detector_; 69 std::unique_ptr<OveruseFrameDetector> overuse_detector_;
88 70
89 // Used to send input capture frames to VideoCaptureInput. 71 // Used to send input capture frames to VideoCaptureInput.
90 std::unique_ptr<internal::VideoCaptureInput> input_; 72 std::unique_ptr<internal::VideoCaptureInput> input_;
91 73
92 // Input capture frames of VideoCaptureInput. 74 // Input capture frames of VideoCaptureInput.
93 ScopedVector<VideoFrame> input_frames_; 75 ScopedVector<VideoFrame> input_frames_;
94 76
95 // Indicate an output frame has arrived.
96 rtc::Event output_frame_event_;
97
98 // Output delivered frames of VideoCaptureInput. 77 // Output delivered frames of VideoCaptureInput.
99 ScopedVector<VideoFrame> output_frames_; 78 ScopedVector<VideoFrame> output_frames_;
100 79
101 // The pointers of Y plane buffers of output frames. This is used to verify 80 // The pointers of Y plane buffers of output frames. This is used to verify
102 // the frame are swapped and not copied. 81 // the frame are swapped and not copied.
103 std::vector<const uint8_t*> output_frame_ybuffers_; 82 std::vector<const uint8_t*> output_frame_ybuffers_;
104 }; 83 };
105 84
106 TEST_F(VideoCaptureInputTest, DoesNotRetainHandleNorCopyBuffer) { 85 TEST_F(VideoCaptureInputTest, DoesNotRetainHandleNorCopyBuffer) {
107 // Indicate an output frame has arrived. 86 // Indicate an output frame has arrived.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
157 input_frames_.push_back(CreateVideoFrame(0)); 136 input_frames_.push_back(CreateVideoFrame(0));
158 137
159 input_frames_[0]->set_ntp_time_ms(17); 138 input_frames_[0]->set_ntp_time_ms(17);
160 AddInputFrame(input_frames_[0]); 139 AddInputFrame(input_frames_[0]);
161 WaitOutputFrame(); 140 WaitOutputFrame();
162 EXPECT_EQ(output_frames_[0]->timestamp(), 141 EXPECT_EQ(output_frames_[0]->timestamp(),
163 input_frames_[0]->ntp_time_ms() * 90); 142 input_frames_[0]->ntp_time_ms() * 90);
164 143
165 // Repeat frame with the same NTP timestamp should drop. 144 // Repeat frame with the same NTP timestamp should drop.
166 AddInputFrame(input_frames_[0]); 145 AddInputFrame(input_frames_[0]);
167 EXPECT_FALSE(output_frame_event_.Wait(FRAME_TIMEOUT_MS)); 146 EXPECT_FALSE(capture_event_.Wait(FRAME_TIMEOUT_MS));
168 147
169 // As should frames with a decreased NTP timestamp. 148 // As should frames with a decreased NTP timestamp.
170 input_frames_[0]->set_ntp_time_ms(input_frames_[0]->ntp_time_ms() - 1); 149 input_frames_[0]->set_ntp_time_ms(input_frames_[0]->ntp_time_ms() - 1);
171 AddInputFrame(input_frames_[0]); 150 AddInputFrame(input_frames_[0]);
172 EXPECT_FALSE(output_frame_event_.Wait(FRAME_TIMEOUT_MS)); 151 EXPECT_FALSE(capture_event_.Wait(FRAME_TIMEOUT_MS));
173 152
174 // But delivering with an increased NTP timestamp should succeed. 153 // But delivering with an increased NTP timestamp should succeed.
175 input_frames_[0]->set_ntp_time_ms(4711); 154 input_frames_[0]->set_ntp_time_ms(4711);
176 AddInputFrame(input_frames_[0]); 155 AddInputFrame(input_frames_[0]);
177 WaitOutputFrame(); 156 WaitOutputFrame();
178 EXPECT_EQ(output_frames_[1]->timestamp(), 157 EXPECT_EQ(output_frames_[1]->timestamp(),
179 input_frames_[0]->ntp_time_ms() * 90); 158 input_frames_[0]->ntp_time_ms() * 90);
180 } 159 }
181 160
182 TEST_F(VideoCaptureInputTest, TestTextureFrames) { 161 TEST_F(VideoCaptureInputTest, TestTextureFrames) {
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 const int kSizeY = width * height * 2; 266 const int kSizeY = width * height * 2;
288 uint8_t buffer[kSizeY]; 267 uint8_t buffer[kSizeY];
289 memset(buffer, data, kSizeY); 268 memset(buffer, data, kSizeY);
290 frame->CreateFrame(buffer, buffer, buffer, width, height, width, width / 2, 269 frame->CreateFrame(buffer, buffer, buffer, width, height, width, width / 2,
291 width / 2, kVideoRotation_0); 270 width / 2, kVideoRotation_0);
292 frame->set_render_time_ms(data); 271 frame->set_render_time_ms(data);
293 return frame; 272 return frame;
294 } 273 }
295 274
296 } // namespace webrtc 275 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/video_capture_input.cc ('k') | webrtc/video/video_receive_stream.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698