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/modules/video_coding/codecs/test/videoprocessor_unittest.cc

Issue 2999113002: Run VideoProcessor on task queue in VideoProcessorIntegrationTest. (Closed)
Patch Set: Created 3 years, 4 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; 52 }
53 53
54 void CreateVideoProcessor() {
54 EXPECT_CALL(frame_reader_mock_, NumberOfFrames()) 55 EXPECT_CALL(frame_reader_mock_, NumberOfFrames())
55 .WillRepeatedly(Return(kNumFrames)); 56 .WillRepeatedly(Return(kNumFrames));
56 EXPECT_CALL(frame_reader_mock_, FrameLength()) 57 EXPECT_CALL(frame_reader_mock_, FrameLength())
57 .WillRepeatedly(Return(kFrameSize)); 58 .WillRepeatedly(Return(kFrameSize));
58 video_processor_ = rtc::MakeUnique<VideoProcessor>( 59 video_processor_ = rtc::MakeUnique<VideoProcessor>(
59 &encoder_mock_, &decoder_mock_, &frame_reader_mock_, 60 &encoder_mock_, &decoder_mock_, &frame_reader_mock_,
60 &frame_writer_mock_, &packet_manipulator_mock_, config_, &stats_, 61 &frame_writer_mock_, &packet_manipulator_mock_, config_, &stats_,
61 nullptr /* encoded_frame_writer */, nullptr /* decoded_frame_writer */); 62 nullptr /* encoded_frame_writer */, nullptr /* decoded_frame_writer */);
62 } 63 }
63 64
64 void ExpectInit() { 65 void ExpectInit() {
65 EXPECT_CALL(encoder_mock_, InitEncode(_, _, _)).Times(1); 66 EXPECT_CALL(encoder_mock_, InitEncode(_, _, _)).Times(1);
66 EXPECT_CALL(encoder_mock_, RegisterEncodeCompleteCallback(_)) 67 EXPECT_CALL(encoder_mock_, RegisterEncodeCompleteCallback(_)).Times(1);
67 .Times(AtLeast(1));
68 EXPECT_CALL(decoder_mock_, InitDecode(_, _)).Times(1); 68 EXPECT_CALL(decoder_mock_, InitDecode(_, _)).Times(1);
69 EXPECT_CALL(decoder_mock_, RegisterDecodeCompleteCallback(_)) 69 EXPECT_CALL(decoder_mock_, RegisterDecodeCompleteCallback(_)).Times(1);
70 .Times(AtLeast(1)); 70 }
71
72 void ExpectRelease() {
73 EXPECT_CALL(encoder_mock_, Release()).Times(1);
74 EXPECT_CALL(encoder_mock_, RegisterEncodeCompleteCallback(_)).Times(1);
75 EXPECT_CALL(decoder_mock_, Release()).Times(1);
76 EXPECT_CALL(decoder_mock_, RegisterDecodeCompleteCallback(_)).Times(1);
71 } 77 }
72 78
73 TestConfig config_; 79 TestConfig config_;
74 80
75 MockVideoEncoder encoder_mock_; 81 MockVideoEncoder encoder_mock_;
76 MockVideoDecoder decoder_mock_; 82 MockVideoDecoder decoder_mock_;
77 MockFrameReader frame_reader_mock_; 83 MockFrameReader frame_reader_mock_;
78 MockFrameWriter frame_writer_mock_; 84 MockFrameWriter frame_writer_mock_;
79 MockPacketManipulator packet_manipulator_mock_; 85 MockPacketManipulator packet_manipulator_mock_;
80 Stats stats_; 86 Stats stats_;
81 std::unique_ptr<VideoProcessor> video_processor_; 87 std::unique_ptr<VideoProcessor> video_processor_;
82 }; 88 };
83 89
84 TEST_F(VideoProcessorTest, Init) { 90 TEST_F(VideoProcessorTest, InitRelease) {
91 CreateVideoProcessor();
92
85 ExpectInit(); 93 ExpectInit();
86 video_processor_->Init(); 94 video_processor_->Init();
95
96 ExpectRelease();
97 video_processor_->Release();
87 } 98 }
88 99
89 TEST_F(VideoProcessorTest, ProcessFrames) { 100 TEST_F(VideoProcessorTest, ProcessFrames_30fps) {
101 const int kFramerateFps = 30;
102 config_.codec_settings.maxFramerate = kFramerateFps;
103 CreateVideoProcessor();
104
90 ExpectInit(); 105 ExpectInit();
91 video_processor_->Init(); 106 video_processor_->Init();
92 107
93 EXPECT_CALL(frame_reader_mock_, ReadFrame()) 108 EXPECT_CALL(frame_reader_mock_, ReadFrame())
94 .WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight))); 109 .WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight)));
95 EXPECT_CALL(encoder_mock_, Encode(testing::Property(&VideoFrame::timestamp, 110 EXPECT_CALL(encoder_mock_,
96 1 * 90000 / kFramerate), 111 Encode(testing::Property(&VideoFrame::timestamp,
97 _, _)) 112 1 * 90000 / kFramerateFps),
113 _, _))
98 .Times(1); 114 .Times(1);
99 video_processor_->ProcessFrame(0); 115 video_processor_->ProcessFrame(0);
100 116
101 EXPECT_CALL(encoder_mock_, Encode(testing::Property(&VideoFrame::timestamp, 117 EXPECT_CALL(encoder_mock_,
102 2 * 90000 / kFramerate), 118 Encode(testing::Property(&VideoFrame::timestamp,
103 _, _)) 119 2 * 90000 / kFramerateFps),
120 _, _))
104 .Times(1); 121 .Times(1);
105 video_processor_->ProcessFrame(1); 122 video_processor_->ProcessFrame(1);
123
124 ExpectRelease();
125 video_processor_->Release();
126 }
127
128 TEST_F(VideoProcessorTest, ProcessFrames_15fps) {
129 const int kFramerateFps = 15;
130 config_.codec_settings.maxFramerate = kFramerateFps;
131 CreateVideoProcessor();
132
133 ExpectInit();
134 video_processor_->Init();
135
136 EXPECT_CALL(frame_reader_mock_, ReadFrame())
137 .WillRepeatedly(Return(I420Buffer::Create(kWidth, kHeight)));
138 EXPECT_CALL(encoder_mock_,
139 Encode(testing::Property(&VideoFrame::timestamp,
140 1 * 90000 / kFramerateFps),
141 _, _))
142 .Times(1);
143 video_processor_->ProcessFrame(0);
144
145 EXPECT_CALL(encoder_mock_,
146 Encode(testing::Property(&VideoFrame::timestamp,
147 2 * 90000 / kFramerateFps),
148 _, _))
149 .Times(1);
150 video_processor_->ProcessFrame(1);
151
152 ExpectRelease();
153 video_processor_->Release();
154 }
155
156 TEST_F(VideoProcessorTest, SetRates) {
157 CreateVideoProcessor();
158 ExpectInit();
159 video_processor_->Init();
160
161 const int kBitrateKbps = 123;
162 const int kFramerateFps = 17;
163 EXPECT_CALL(
164 encoder_mock_,
165 SetRateAllocation(
166 testing::Property(&BitrateAllocation::get_sum_kbps, kBitrateKbps),
167 kFramerateFps))
168 .Times(1);
169 video_processor_->SetRates(kBitrateKbps, kFramerateFps);
170 ASSERT_EQ(1u, video_processor_->NumberDroppedFramesPerRateUpdate().size());
171 EXPECT_EQ(0, video_processor_->NumberDroppedFramesPerRateUpdate()[0]);
172 ASSERT_EQ(1u, video_processor_->NumberSpatialResizesPerRateUpdate().size());
173 EXPECT_EQ(0, video_processor_->NumberSpatialResizesPerRateUpdate()[0]);
174
175 const int kNewBitrateKbps = 456;
176 const int kNewFramerateFps = 34;
177 EXPECT_CALL(
178 encoder_mock_,
179 SetRateAllocation(
180 testing::Property(&BitrateAllocation::get_sum_kbps, kNewBitrateKbps),
181 kNewFramerateFps))
182 .Times(1);
183 video_processor_->SetRates(kNewBitrateKbps, kNewFramerateFps);
184 ASSERT_EQ(2u, video_processor_->NumberDroppedFramesPerRateUpdate().size());
185 EXPECT_EQ(0, video_processor_->NumberDroppedFramesPerRateUpdate()[0]);
186 ASSERT_EQ(2u, video_processor_->NumberSpatialResizesPerRateUpdate().size());
187 EXPECT_EQ(0, video_processor_->NumberSpatialResizesPerRateUpdate()[0]);
106 } 188 }
107 189
108 } // namespace test 190 } // namespace test
109 } // namespace webrtc 191 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698