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

Side by Side Diff: webrtc/modules/video_coding/codecs/test/videoprocessor_unittest.cc

Issue 2997283002: VideoProcessorIntegrationTest: make it runnable on a task queue. (Closed)
Patch Set: Rebase. Created 3 years, 3 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) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 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 #include <memory> 11 #include <memory>
12 12
13 #include "webrtc/api/video/i420_buffer.h" 13 #include "webrtc/api/video/i420_buffer.h"
14 #include "webrtc/common_types.h"
14 #include "webrtc/modules/video_coding/codecs/test/mock/mock_packet_manipulator.h " 15 #include "webrtc/modules/video_coding/codecs/test/mock/mock_packet_manipulator.h "
15 #include "webrtc/modules/video_coding/codecs/test/videoprocessor.h" 16 #include "webrtc/modules/video_coding/codecs/test/videoprocessor.h"
16 #include "webrtc/modules/video_coding/include/mock/mock_video_codec_interface.h" 17 #include "webrtc/modules/video_coding/include/mock/mock_video_codec_interface.h"
17 #include "webrtc/modules/video_coding/include/video_coding.h" 18 #include "webrtc/modules/video_coding/include/video_coding.h"
18 #include "webrtc/rtc_base/ptr_util.h" 19 #include "webrtc/rtc_base/ptr_util.h"
19 #include "webrtc/test/gmock.h" 20 #include "webrtc/test/gmock.h"
20 #include "webrtc/test/gtest.h" 21 #include "webrtc/test/gtest.h"
21 #include "webrtc/test/testsupport/mock/mock_frame_reader.h" 22 #include "webrtc/test/testsupport/mock/mock_frame_reader.h"
22 #include "webrtc/test/testsupport/mock/mock_frame_writer.h" 23 #include "webrtc/test/testsupport/mock/mock_frame_writer.h"
23 #include "webrtc/test/testsupport/packet_reader.h" 24 #include "webrtc/test/testsupport/packet_reader.h"
24 #include "webrtc/test/testsupport/unittest_utils.h" 25 #include "webrtc/test/testsupport/unittest_utils.h"
25 #include "webrtc/test/video_codec_settings.h" 26 #include "webrtc/test/video_codec_settings.h"
26 #include "webrtc/typedefs.h" 27 #include "webrtc/typedefs.h"
27 28
28 using ::testing::_; 29 using ::testing::_;
29 using ::testing::AtLeast; 30 using ::testing::AtLeast;
30 using ::testing::Return; 31 using ::testing::Return;
31 32
32 namespace webrtc { 33 namespace webrtc {
33 namespace test { 34 namespace test {
34 35
35 namespace { 36 namespace {
36 37
37 const int kWidth = 352; 38 const int kWidth = 352;
38 const int kHeight = 288; 39 const int kHeight = 288;
39 const int kFrameSize = kWidth * kHeight * 3 / 2; // I420. 40 const int kFrameSize = kWidth * kHeight * 3 / 2; // I420.
40 const int kFramerate = 30;
41 const int kNumFrames = 2; 41 const int kNumFrames = 2;
42 42
43 } // namespace 43 } // namespace
44 44
45 class VideoProcessorTest : public testing::Test { 45 class VideoProcessorTest : public testing::Test {
46 protected: 46 protected:
47 VideoProcessorTest() { 47 VideoProcessorTest() {
48 // Get a codec configuration struct and configure it. 48 // Get a codec configuration struct and configure it.
49 webrtc::test::CodecSettings(kVideoCodecVP8, &config_.codec_settings); 49 webrtc::test::CodecSettings(kVideoCodecVP8, &config_.codec_settings);
50 config_.codec_settings.width = kWidth; 50 config_.codec_settings.width = kWidth;
51 config_.codec_settings.height = kHeight; 51 config_.codec_settings.height = kHeight;
52 config_.codec_settings.maxFramerate = kFramerate;
53 52
54 EXPECT_CALL(frame_reader_mock_, NumberOfFrames()) 53 EXPECT_CALL(frame_reader_mock_, NumberOfFrames())
55 .WillRepeatedly(Return(kNumFrames)); 54 .WillRepeatedly(Return(kNumFrames));
56 EXPECT_CALL(frame_reader_mock_, FrameLength()) 55 EXPECT_CALL(frame_reader_mock_, FrameLength())
57 .WillRepeatedly(Return(kFrameSize)); 56 .WillRepeatedly(Return(kFrameSize));
58 video_processor_ = rtc::MakeUnique<VideoProcessor>( 57 video_processor_ = rtc::MakeUnique<VideoProcessor>(
59 &encoder_mock_, &decoder_mock_, &frame_reader_mock_, 58 &encoder_mock_, &decoder_mock_, &frame_reader_mock_,
60 &frame_writer_mock_, &packet_manipulator_mock_, config_, &stats_, 59 &frame_writer_mock_, &packet_manipulator_mock_, config_, &stats_,
61 nullptr /* encoded_frame_writer */, nullptr /* decoded_frame_writer */); 60 nullptr /* encoded_frame_writer */, nullptr /* decoded_frame_writer */);
62 } 61 }
63 62
64 void ExpectInit() { 63 void ExpectInit() {
65 EXPECT_CALL(encoder_mock_, InitEncode(_, _, _)).Times(1); 64 EXPECT_CALL(encoder_mock_, InitEncode(_, _, _)).Times(1);
66 EXPECT_CALL(encoder_mock_, RegisterEncodeCompleteCallback(_)) 65 EXPECT_CALL(encoder_mock_, RegisterEncodeCompleteCallback(_)).Times(1);
67 .Times(AtLeast(1));
68 EXPECT_CALL(decoder_mock_, InitDecode(_, _)).Times(1); 66 EXPECT_CALL(decoder_mock_, InitDecode(_, _)).Times(1);
69 EXPECT_CALL(decoder_mock_, RegisterDecodeCompleteCallback(_)) 67 EXPECT_CALL(decoder_mock_, RegisterDecodeCompleteCallback(_)).Times(1);
70 .Times(AtLeast(1)); 68 }
69
70 void ExpectRelease() {
71 EXPECT_CALL(encoder_mock_, Release()).Times(1);
72 EXPECT_CALL(encoder_mock_, RegisterEncodeCompleteCallback(_)).Times(1);
73 EXPECT_CALL(decoder_mock_, Release()).Times(1);
74 EXPECT_CALL(decoder_mock_, RegisterDecodeCompleteCallback(_)).Times(1);
71 } 75 }
72 76
73 TestConfig config_; 77 TestConfig config_;
74 78
75 MockVideoEncoder encoder_mock_; 79 MockVideoEncoder encoder_mock_;
76 MockVideoDecoder decoder_mock_; 80 MockVideoDecoder decoder_mock_;
77 MockFrameReader frame_reader_mock_; 81 MockFrameReader frame_reader_mock_;
78 MockFrameWriter frame_writer_mock_; 82 MockFrameWriter frame_writer_mock_;
79 MockPacketManipulator packet_manipulator_mock_; 83 MockPacketManipulator packet_manipulator_mock_;
80 Stats stats_; 84 Stats stats_;
81 std::unique_ptr<VideoProcessor> video_processor_; 85 std::unique_ptr<VideoProcessor> video_processor_;
82 }; 86 };
83 87
84 TEST_F(VideoProcessorTest, Init) { 88 TEST_F(VideoProcessorTest, InitRelease) {
85 ExpectInit();
86 video_processor_->Init();
87 }
88
89 TEST_F(VideoProcessorTest, ProcessFrames) {
90 ExpectInit(); 89 ExpectInit();
91 video_processor_->Init(); 90 video_processor_->Init();
92 91
92 ExpectRelease();
93 video_processor_->Release();
94 }
95
96 TEST_F(VideoProcessorTest, ProcessFrames_FixedFramerate) {
97 ExpectInit();
98 video_processor_->Init();
99
100 const int kBitrateKbps = 456;
101 const int kFramerateFps = 31;
102 video_processor_->SetRates(kBitrateKbps, kFramerateFps);
103
93 EXPECT_CALL(frame_reader_mock_, ReadFrame()) 104 EXPECT_CALL(frame_reader_mock_, ReadFrame())
94 .WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight))); 105 .WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight)));
95 EXPECT_CALL(encoder_mock_, Encode(testing::Property(&VideoFrame::timestamp, 106 EXPECT_CALL(encoder_mock_,
96 1 * 90000 / kFramerate), 107 Encode(testing::Property(&VideoFrame::timestamp,
97 _, _)) 108 1 * 90000 / kFramerateFps),
109 _, _))
98 .Times(1); 110 .Times(1);
99 video_processor_->ProcessFrame(0); 111 video_processor_->ProcessFrame(0);
100 112
101 EXPECT_CALL(encoder_mock_, Encode(testing::Property(&VideoFrame::timestamp, 113 EXPECT_CALL(encoder_mock_,
102 2 * 90000 / kFramerate), 114 Encode(testing::Property(&VideoFrame::timestamp,
103 _, _)) 115 2 * 90000 / kFramerateFps),
116 _, _))
104 .Times(1); 117 .Times(1);
105 video_processor_->ProcessFrame(1); 118 video_processor_->ProcessFrame(1);
119
120 ExpectRelease();
121 video_processor_->Release();
122 }
123
124 TEST_F(VideoProcessorTest, ProcessFrames_VariableFramerate) {
125 ExpectInit();
126 video_processor_->Init();
127
128 const int kBitrateKbps = 456;
129 const int kStartFramerateFps = 27;
130 video_processor_->SetRates(kBitrateKbps, kStartFramerateFps);
131
132 EXPECT_CALL(frame_reader_mock_, ReadFrame())
133 .WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight)));
134 EXPECT_CALL(encoder_mock_,
135 Encode(testing::Property(&VideoFrame::timestamp,
136 1 * 90000 / kStartFramerateFps),
137 _, _))
138 .Times(1);
139 video_processor_->ProcessFrame(0);
140
141 const int kNewFramerateFps = 13;
142 video_processor_->SetRates(kBitrateKbps, kNewFramerateFps);
143
144 EXPECT_CALL(encoder_mock_,
145 Encode(testing::Property(&VideoFrame::timestamp,
146 2 * 90000 / kNewFramerateFps),
147 _, _))
148 .Times(1);
149 video_processor_->ProcessFrame(1);
150
151 ExpectRelease();
152 video_processor_->Release();
153 }
154
155 TEST_F(VideoProcessorTest, SetRates) {
156 ExpectInit();
157 video_processor_->Init();
158
159 const int kBitrateKbps = 123;
160 const int kFramerateFps = 17;
161 EXPECT_CALL(
162 encoder_mock_,
163 SetRateAllocation(
164 testing::Property(&BitrateAllocation::get_sum_kbps, kBitrateKbps),
165 kFramerateFps))
166 .Times(1);
167 video_processor_->SetRates(kBitrateKbps, kFramerateFps);
168 ASSERT_EQ(1u, video_processor_->NumberDroppedFramesPerRateUpdate().size());
169 EXPECT_EQ(0, video_processor_->NumberDroppedFramesPerRateUpdate()[0]);
åsapersson 2017/08/29 13:42:33 maybe EXPECT_THAT(video_processor_->NumberDroppedF
brandtr 2017/08/30 11:44:26 Done.
170 ASSERT_EQ(1u, video_processor_->NumberSpatialResizesPerRateUpdate().size());
171 EXPECT_EQ(0, video_processor_->NumberSpatialResizesPerRateUpdate()[0]);
172
173 const int kNewBitrateKbps = 456;
174 const int kNewFramerateFps = 34;
175 EXPECT_CALL(
176 encoder_mock_,
177 SetRateAllocation(
178 testing::Property(&BitrateAllocation::get_sum_kbps, kNewBitrateKbps),
179 kNewFramerateFps))
180 .Times(1);
181 video_processor_->SetRates(kNewBitrateKbps, kNewFramerateFps);
182 ASSERT_EQ(2u, video_processor_->NumberDroppedFramesPerRateUpdate().size());
183 EXPECT_EQ(0, video_processor_->NumberDroppedFramesPerRateUpdate()[1]);
184 ASSERT_EQ(2u, video_processor_->NumberSpatialResizesPerRateUpdate().size());
185 EXPECT_EQ(0, video_processor_->NumberSpatialResizesPerRateUpdate()[1]);
186
187 ExpectRelease();
188 video_processor_->Release();
106 } 189 }
107 190
108 } // namespace test 191 } // namespace test
109 } // namespace webrtc 192 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698