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

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

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

Powered by Google App Engine
This is Rietveld 408576698