blob: a87daf574bff52f0a5411af9baf8fc015282ee6c [file] [log] [blame]
pbos@webrtc.org9115cde2014-12-09 10:36:40 +00001/*
2 * Copyright (c) 2014 The WebRTC project authors. All Rights Reserved.
3 *
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
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
10
brandtr5e171752017-05-23 03:32:16 -070011#include <array>
kwiberg3f55dea2016-02-29 05:51:59 -080012#include <memory>
pbos@webrtc.org9115cde2014-12-09 10:36:40 +000013#include <vector>
14
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "common_video/include/video_frame_buffer.h"
Magnus Jedvert46a27652017-11-13 14:10:02 +010016#include "media/engine/internalencoderfactory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "media/engine/simulcast_encoder_adapter.h"
18#include "modules/video_coding/codecs/vp8/simulcast_test_utility.h"
19#include "modules/video_coding/include/video_codec_interface.h"
Magnus Jedvert46a27652017-11-13 14:10:02 +010020#include "rtc_base/ptr_util.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "test/gmock.h"
pbos@webrtc.org9115cde2014-12-09 10:36:40 +000022
23namespace webrtc {
24namespace testing {
25
pbos@webrtc.org9115cde2014-12-09 10:36:40 +000026class TestSimulcastEncoderAdapter : public TestVp8Simulcast {
27 public:
Zhi Huangaea84f52017-11-16 18:46:27 +000028 TestSimulcastEncoderAdapter()
29 : factory_(new cricket::InternalEncoderFactory()) {}
philipelcce46fc2015-12-21 03:04:49 -080030
pbos@webrtc.org9115cde2014-12-09 10:36:40 +000031 protected:
Magnus Jedvert46a27652017-11-13 14:10:02 +010032 std::unique_ptr<VP8Encoder> CreateEncoder() override {
33 return rtc::MakeUnique<SimulcastEncoderAdapter>(factory_.get());
magjed6cc25612017-07-10 03:26:36 -070034 }
Magnus Jedvert46a27652017-11-13 14:10:02 +010035 std::unique_ptr<VP8Decoder> CreateDecoder() override {
36 return VP8Decoder::Create();
37 }
magjed6cc25612017-07-10 03:26:36 -070038
39 private:
Zhi Huangaea84f52017-11-16 18:46:27 +000040 std::unique_ptr<cricket::WebRtcVideoEncoderFactory> factory_;
pbos@webrtc.org9115cde2014-12-09 10:36:40 +000041};
42
43TEST_F(TestSimulcastEncoderAdapter, TestKeyFrameRequestsOnAllStreams) {
44 TestVp8Simulcast::TestKeyFrameRequestsOnAllStreams();
45}
46
47TEST_F(TestSimulcastEncoderAdapter, TestPaddingAllStreams) {
48 TestVp8Simulcast::TestPaddingAllStreams();
49}
50
51TEST_F(TestSimulcastEncoderAdapter, TestPaddingTwoStreams) {
52 TestVp8Simulcast::TestPaddingTwoStreams();
53}
54
55TEST_F(TestSimulcastEncoderAdapter, TestPaddingTwoStreamsOneMaxedOut) {
56 TestVp8Simulcast::TestPaddingTwoStreamsOneMaxedOut();
57}
58
59TEST_F(TestSimulcastEncoderAdapter, TestPaddingOneStream) {
60 TestVp8Simulcast::TestPaddingOneStream();
61}
62
63TEST_F(TestSimulcastEncoderAdapter, TestPaddingOneStreamTwoMaxedOut) {
64 TestVp8Simulcast::TestPaddingOneStreamTwoMaxedOut();
65}
66
67TEST_F(TestSimulcastEncoderAdapter, TestSendAllStreams) {
68 TestVp8Simulcast::TestSendAllStreams();
69}
70
71TEST_F(TestSimulcastEncoderAdapter, TestDisablingStreams) {
72 TestVp8Simulcast::TestDisablingStreams();
73}
74
75TEST_F(TestSimulcastEncoderAdapter, TestSwitchingToOneStream) {
76 TestVp8Simulcast::TestSwitchingToOneStream();
77}
78
79TEST_F(TestSimulcastEncoderAdapter, TestSwitchingToOneOddStream) {
80 TestVp8Simulcast::TestSwitchingToOneOddStream();
81}
82
pbos@webrtc.org9115cde2014-12-09 10:36:40 +000083TEST_F(TestSimulcastEncoderAdapter, TestStrideEncodeDecode) {
84 TestVp8Simulcast::TestStrideEncodeDecode();
85}
86
87TEST_F(TestSimulcastEncoderAdapter, TestSaptioTemporalLayers333PatternEncoder) {
88 TestVp8Simulcast::TestSaptioTemporalLayers333PatternEncoder();
89}
90
91TEST_F(TestSimulcastEncoderAdapter, TestSpatioTemporalLayers321PatternEncoder) {
92 TestVp8Simulcast::TestSpatioTemporalLayers321PatternEncoder();
93}
94
pbos@webrtc.org9115cde2014-12-09 10:36:40 +000095class MockVideoEncoder : public VideoEncoder {
96 public:
nisseef8b61e2016-04-29 06:09:15 -070097 // TODO(nisse): Valid overrides commented out, because the gmock
98 // methods don't use any override declarations, and we want to avoid
99 // warnings from -Winconsistent-missing-override. See
100 // http://crbug.com/428099.
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000101 int32_t InitEncode(const VideoCodec* codecSettings,
102 int32_t numberOfCores,
nisseef8b61e2016-04-29 06:09:15 -0700103 size_t maxPayloadSize) /* override */ {
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000104 codec_ = *codecSettings;
noahrice5ba75a2016-12-12 13:08:27 -0800105 return init_encode_return_value_;
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000106 }
107
noahricfe3654d2016-07-01 09:05:54 -0700108 MOCK_METHOD3(
109 Encode,
110 int32_t(const VideoFrame& inputImage,
111 const CodecSpecificInfo* codecSpecificInfo,
112 const std::vector<FrameType>* frame_types) /* override */);
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000113
pbos65e15ba2015-10-15 10:52:15 -0700114 int32_t RegisterEncodeCompleteCallback(
nisseef8b61e2016-04-29 06:09:15 -0700115 EncodedImageCallback* callback) /* override */ {
Noah Richards41ee1ea2015-04-15 09:24:26 -0700116 callback_ = callback;
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000117 return 0;
118 }
119
brandtr5e171752017-05-23 03:32:16 -0700120 MOCK_METHOD0(Release, int32_t());
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000121
Erik Språng08127a92016-11-16 16:41:30 +0100122 int32_t SetRateAllocation(const BitrateAllocation& bitrate_allocation,
123 uint32_t framerate) {
124 last_set_bitrate_ = bitrate_allocation;
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000125 return 0;
126 }
127
philipelcce46fc2015-12-21 03:04:49 -0800128 MOCK_METHOD2(SetChannelParameters, int32_t(uint32_t packetLoss, int64_t rtt));
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000129
nisseef8b61e2016-04-29 06:09:15 -0700130 bool SupportsNativeHandle() const /* override */ {
131 return supports_native_handle_;
132 }
pbos65e15ba2015-10-15 10:52:15 -0700133
Zhi Huangaea84f52017-11-16 18:46:27 +0000134 virtual ~MockVideoEncoder() {}
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000135
136 const VideoCodec& codec() const { return codec_; }
137
Noah Richards41ee1ea2015-04-15 09:24:26 -0700138 void SendEncodedImage(int width, int height) {
139 // Sends a fake image of the given width/height.
140 EncodedImage image;
141 image._encodedWidth = width;
142 image._encodedHeight = height;
sergeyu2cb155a2016-11-04 11:39:29 -0700143 CodecSpecificInfo codec_specific_info;
144 memset(&codec_specific_info, 0, sizeof(codec_specific_info));
brandtr5e171752017-05-23 03:32:16 -0700145 callback_->OnEncodedImage(image, &codec_specific_info, nullptr);
Noah Richards41ee1ea2015-04-15 09:24:26 -0700146 }
147
pbos65e15ba2015-10-15 10:52:15 -0700148 void set_supports_native_handle(bool enabled) {
149 supports_native_handle_ = enabled;
150 }
noahrice5ba75a2016-12-12 13:08:27 -0800151
152 void set_init_encode_return_value(int32_t value) {
153 init_encode_return_value_ = value;
154 }
155
Erik Språng08127a92016-11-16 16:41:30 +0100156 BitrateAllocation last_set_bitrate() const { return last_set_bitrate_; }
pbos65e15ba2015-10-15 10:52:15 -0700157
Peter Boströma5dec162016-01-20 15:53:55 +0100158 MOCK_CONST_METHOD0(ImplementationName, const char*());
159
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000160 private:
pbos65e15ba2015-10-15 10:52:15 -0700161 bool supports_native_handle_ = false;
noahrice5ba75a2016-12-12 13:08:27 -0800162 int32_t init_encode_return_value_ = 0;
Erik Språng08127a92016-11-16 16:41:30 +0100163 BitrateAllocation last_set_bitrate_;
noahricfac0ff02016-09-09 10:27:15 -0700164
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000165 VideoCodec codec_;
Noah Richards41ee1ea2015-04-15 09:24:26 -0700166 EncodedImageCallback* callback_;
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000167};
168
Zhi Huangaea84f52017-11-16 18:46:27 +0000169class MockVideoEncoderFactory : public cricket::WebRtcVideoEncoderFactory {
170 public:
171 MockVideoEncoderFactory() {
172 supported_codecs_.push_back(cricket::VideoCodec("VP8"));
Peter Boströmd53c3892016-03-30 17:03:52 +0200173 }
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000174
Zhi Huangaea84f52017-11-16 18:46:27 +0000175 const std::vector<cricket::VideoCodec>& supported_codecs() const override {
176 return supported_codecs_;
177 }
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000178
Zhi Huangaea84f52017-11-16 18:46:27 +0000179 VideoEncoder* CreateVideoEncoder(const cricket::VideoCodec& codec) override {
180 MockVideoEncoder* encoder = new ::testing::NiceMock<MockVideoEncoder>();
181 encoder->set_init_encode_return_value(init_encode_return_value_);
182 const char* encoder_name = encoder_names_.empty()
183 ? "codec_implementation_name"
184 : encoder_names_[encoders_.size()];
185 ON_CALL(*encoder, ImplementationName()).WillByDefault(Return(encoder_name));
186 encoders_.push_back(encoder);
187 return encoder;
188 }
189
190 void DestroyVideoEncoder(VideoEncoder* encoder) override {
191 for (size_t i = 0; i < encoders_.size(); ++i) {
192 if (encoders_[i] == encoder) {
193 encoders_.erase(encoders_.begin() + i);
194 break;
195 }
196 }
197 delete encoder;
198 }
199
200 virtual ~MockVideoEncoderFactory() {}
201
202 const std::vector<MockVideoEncoder*>& encoders() const { return encoders_; }
203 void SetEncoderNames(const std::vector<const char*>& encoder_names) {
204 encoder_names_ = encoder_names;
205 }
206 void set_init_encode_return_value(int32_t value) {
207 init_encode_return_value_ = value;
208 }
209
210 private:
211 std::vector<cricket::VideoCodec> supported_codecs_;
212 int32_t init_encode_return_value_ = 0;
213 std::vector<MockVideoEncoder*> encoders_;
214 std::vector<const char*> encoder_names_;
215};
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000216
217class TestSimulcastEncoderAdapterFakeHelper {
218 public:
219 TestSimulcastEncoderAdapterFakeHelper()
220 : factory_(new MockVideoEncoderFactory()) {}
221
222 // Can only be called once as the SimulcastEncoderAdapter will take the
223 // ownership of |factory_|.
224 VP8Encoder* CreateMockEncoderAdapter() {
magjed6cc25612017-07-10 03:26:36 -0700225 return new SimulcastEncoderAdapter(factory_.get());
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000226 }
227
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000228 void ExpectCallSetChannelParameters(uint32_t packetLoss, int64_t rtt) {
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000229 EXPECT_TRUE(!factory_->encoders().empty());
230 for (size_t i = 0; i < factory_->encoders().size(); ++i) {
231 EXPECT_CALL(*factory_->encoders()[i],
philipelcce46fc2015-12-21 03:04:49 -0800232 SetChannelParameters(packetLoss, rtt))
233 .Times(1);
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000234 }
235 }
236
magjed6cc25612017-07-10 03:26:36 -0700237 MockVideoEncoderFactory* factory() { return factory_.get(); }
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000238
239 private:
magjed6cc25612017-07-10 03:26:36 -0700240 std::unique_ptr<MockVideoEncoderFactory> factory_;
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000241};
242
243static const int kTestTemporalLayerProfile[3] = {3, 2, 1};
244
Noah Richards41ee1ea2015-04-15 09:24:26 -0700245class TestSimulcastEncoderAdapterFake : public ::testing::Test,
246 public EncodedImageCallback {
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000247 public:
248 TestSimulcastEncoderAdapterFake()
Noah Richards41ee1ea2015-04-15 09:24:26 -0700249 : helper_(new TestSimulcastEncoderAdapterFakeHelper()),
250 adapter_(helper_->CreateMockEncoderAdapter()),
251 last_encoded_image_width_(-1),
252 last_encoded_image_height_(-1),
253 last_encoded_image_simulcast_index_(-1) {}
brandtr5e171752017-05-23 03:32:16 -0700254 virtual ~TestSimulcastEncoderAdapterFake() {
255 if (adapter_) {
256 adapter_->Release();
257 }
258 }
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000259
Sergey Ulanov525df3f2016-08-02 17:46:41 -0700260 Result OnEncodedImage(const EncodedImage& encoded_image,
261 const CodecSpecificInfo* codec_specific_info,
262 const RTPFragmentationHeader* fragmentation) override {
263 last_encoded_image_width_ = encoded_image._encodedWidth;
264 last_encoded_image_height_ = encoded_image._encodedHeight;
265 if (codec_specific_info) {
Noah Richards41ee1ea2015-04-15 09:24:26 -0700266 last_encoded_image_simulcast_index_ =
Sergey Ulanov525df3f2016-08-02 17:46:41 -0700267 codec_specific_info->codecSpecific.VP8.simulcastIdx;
Noah Richards41ee1ea2015-04-15 09:24:26 -0700268 }
Sergey Ulanov525df3f2016-08-02 17:46:41 -0700269 return Result(Result::OK, encoded_image._timeStamp);
Noah Richards41ee1ea2015-04-15 09:24:26 -0700270 }
271
272 bool GetLastEncodedImageInfo(int* out_width,
273 int* out_height,
274 int* out_simulcast_index) {
275 if (last_encoded_image_width_ == -1) {
276 return false;
277 }
278 *out_width = last_encoded_image_width_;
279 *out_height = last_encoded_image_height_;
280 *out_simulcast_index = last_encoded_image_simulcast_index_;
281 return true;
282 }
283
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000284 void SetupCodec() {
285 TestVp8Simulcast::DefaultSettings(
philipelcce46fc2015-12-21 03:04:49 -0800286 &codec_, static_cast<const int*>(kTestTemporalLayerProfile));
Erik Språng08127a92016-11-16 16:41:30 +0100287 rate_allocator_.reset(new SimulcastRateAllocator(codec_, nullptr));
288 tl_factory_.SetListener(rate_allocator_.get());
289 codec_.VP8()->tl_factory = &tl_factory_;
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000290 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
Noah Richards41ee1ea2015-04-15 09:24:26 -0700291 adapter_->RegisterEncodeCompleteCallback(this);
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000292 }
293
294 void VerifyCodec(const VideoCodec& ref, int stream_index) {
295 const VideoCodec& target =
296 helper_->factory()->encoders()[stream_index]->codec();
297 EXPECT_EQ(ref.codecType, target.codecType);
298 EXPECT_EQ(0, strcmp(ref.plName, target.plName));
299 EXPECT_EQ(ref.plType, target.plType);
300 EXPECT_EQ(ref.width, target.width);
301 EXPECT_EQ(ref.height, target.height);
302 EXPECT_EQ(ref.startBitrate, target.startBitrate);
303 EXPECT_EQ(ref.maxBitrate, target.maxBitrate);
304 EXPECT_EQ(ref.minBitrate, target.minBitrate);
305 EXPECT_EQ(ref.maxFramerate, target.maxFramerate);
hta257dc392016-10-25 09:05:06 -0700306 EXPECT_EQ(ref.VP8().pictureLossIndicationOn,
307 target.VP8().pictureLossIndicationOn);
hta257dc392016-10-25 09:05:06 -0700308 EXPECT_EQ(ref.VP8().complexity, target.VP8().complexity);
309 EXPECT_EQ(ref.VP8().resilience, target.VP8().resilience);
310 EXPECT_EQ(ref.VP8().numberOfTemporalLayers,
311 target.VP8().numberOfTemporalLayers);
312 EXPECT_EQ(ref.VP8().denoisingOn, target.VP8().denoisingOn);
313 EXPECT_EQ(ref.VP8().errorConcealmentOn, target.VP8().errorConcealmentOn);
314 EXPECT_EQ(ref.VP8().automaticResizeOn, target.VP8().automaticResizeOn);
315 EXPECT_EQ(ref.VP8().frameDroppingOn, target.VP8().frameDroppingOn);
316 EXPECT_EQ(ref.VP8().keyFrameInterval, target.VP8().keyFrameInterval);
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000317 EXPECT_EQ(ref.qpMax, target.qpMax);
318 EXPECT_EQ(0, target.numberOfSimulcastStreams);
319 EXPECT_EQ(ref.mode, target.mode);
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000320
321 // No need to compare simulcastStream as numberOfSimulcastStreams should
322 // always be 0.
323 }
324
325 void InitRefCodec(int stream_index, VideoCodec* ref_codec) {
326 *ref_codec = codec_;
hta257dc392016-10-25 09:05:06 -0700327 ref_codec->VP8()->numberOfTemporalLayers =
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000328 kTestTemporalLayerProfile[stream_index];
Erik Språng08127a92016-11-16 16:41:30 +0100329 ref_codec->VP8()->tl_factory = &tl_factory_;
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000330 ref_codec->width = codec_.simulcastStream[stream_index].width;
331 ref_codec->height = codec_.simulcastStream[stream_index].height;
332 ref_codec->maxBitrate = codec_.simulcastStream[stream_index].maxBitrate;
333 ref_codec->minBitrate = codec_.simulcastStream[stream_index].minBitrate;
334 ref_codec->qpMax = codec_.simulcastStream[stream_index].qpMax;
335 }
336
337 void VerifyCodecSettings() {
338 EXPECT_EQ(3u, helper_->factory()->encoders().size());
339 VideoCodec ref_codec;
340
341 // stream 0, the lowest resolution stream.
342 InitRefCodec(0, &ref_codec);
343 ref_codec.qpMax = 45;
hta257dc392016-10-25 09:05:06 -0700344 ref_codec.VP8()->complexity = webrtc::kComplexityHigher;
345 ref_codec.VP8()->denoisingOn = false;
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000346 ref_codec.startBitrate = 100; // Should equal to the target bitrate.
347 VerifyCodec(ref_codec, 0);
348
349 // stream 1
350 InitRefCodec(1, &ref_codec);
hta257dc392016-10-25 09:05:06 -0700351 ref_codec.VP8()->denoisingOn = false;
Noah Richards67b635a2015-05-22 14:12:10 -0700352 // The start bitrate (300kbit) minus what we have for the lower layers
353 // (100kbit).
354 ref_codec.startBitrate = 200;
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000355 VerifyCodec(ref_codec, 1);
356
357 // stream 2, the biggest resolution stream.
358 InitRefCodec(2, &ref_codec);
Noah Richards67b635a2015-05-22 14:12:10 -0700359 // We don't have enough bits to send this, so the adapter should have
360 // configured it to use the min bitrate for this layer (600kbit) but turn
361 // off sending.
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000362 ref_codec.startBitrate = 600;
363 VerifyCodec(ref_codec, 2);
364 }
365
366 protected:
kwiberg3f55dea2016-02-29 05:51:59 -0800367 std::unique_ptr<TestSimulcastEncoderAdapterFakeHelper> helper_;
368 std::unique_ptr<VP8Encoder> adapter_;
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000369 VideoCodec codec_;
Noah Richards41ee1ea2015-04-15 09:24:26 -0700370 int last_encoded_image_width_;
371 int last_encoded_image_height_;
372 int last_encoded_image_simulcast_index_;
Erik Språng08127a92016-11-16 16:41:30 +0100373 TemporalLayersFactory tl_factory_;
374 std::unique_ptr<SimulcastRateAllocator> rate_allocator_;
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000375};
376
377TEST_F(TestSimulcastEncoderAdapterFake, InitEncode) {
378 SetupCodec();
379 VerifyCodecSettings();
380}
381
brandtr5e171752017-05-23 03:32:16 -0700382TEST_F(TestSimulcastEncoderAdapterFake, ReleaseWithoutInitEncode) {
383 EXPECT_EQ(0, adapter_->Release());
384}
385
386TEST_F(TestSimulcastEncoderAdapterFake, Reinit) {
387 SetupCodec();
388 EXPECT_EQ(0, adapter_->Release());
389
390 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
391}
392
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000393TEST_F(TestSimulcastEncoderAdapterFake, SetChannelParameters) {
394 SetupCodec();
395 const uint32_t packetLoss = 5;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000396 const int64_t rtt = 30;
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000397 helper_->ExpectCallSetChannelParameters(packetLoss, rtt);
398 adapter_->SetChannelParameters(packetLoss, rtt);
399}
400
Noah Richards41ee1ea2015-04-15 09:24:26 -0700401TEST_F(TestSimulcastEncoderAdapterFake, EncodedCallbackForDifferentEncoders) {
402 SetupCodec();
403
Peter Boström5d0379d2015-10-06 14:04:51 +0200404 // Set bitrates so that we send all layers.
Erik Språng08127a92016-11-16 16:41:30 +0100405 adapter_->SetRateAllocation(rate_allocator_->GetAllocation(1200, 30), 30);
Peter Boström5d0379d2015-10-06 14:04:51 +0200406
Noah Richards41ee1ea2015-04-15 09:24:26 -0700407 // At this point, the simulcast encoder adapter should have 3 streams: HD,
408 // quarter HD, and quarter quarter HD. We're going to mostly ignore the exact
409 // resolutions, to test that the adapter forwards on the correct resolution
410 // and simulcast index values, going only off the encoder that generates the
411 // image.
brandtr5e171752017-05-23 03:32:16 -0700412 std::vector<MockVideoEncoder*> encoders = helper_->factory()->encoders();
413 ASSERT_EQ(3u, encoders.size());
414 encoders[0]->SendEncodedImage(1152, 704);
Noah Richards41ee1ea2015-04-15 09:24:26 -0700415 int width;
416 int height;
417 int simulcast_index;
418 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
419 EXPECT_EQ(1152, width);
420 EXPECT_EQ(704, height);
421 EXPECT_EQ(0, simulcast_index);
422
brandtr5e171752017-05-23 03:32:16 -0700423 encoders[1]->SendEncodedImage(300, 620);
Noah Richards41ee1ea2015-04-15 09:24:26 -0700424 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
425 EXPECT_EQ(300, width);
426 EXPECT_EQ(620, height);
427 EXPECT_EQ(1, simulcast_index);
428
brandtr5e171752017-05-23 03:32:16 -0700429 encoders[2]->SendEncodedImage(120, 240);
Noah Richards41ee1ea2015-04-15 09:24:26 -0700430 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
431 EXPECT_EQ(120, width);
432 EXPECT_EQ(240, height);
433 EXPECT_EQ(2, simulcast_index);
434}
435
brandtr5e171752017-05-23 03:32:16 -0700436// This test verifies that the underlying encoders are reused, when the adapter
437// is reinited with different number of simulcast streams. It further checks
438// that the allocated encoders are reused in the same order as before, starting
439// with the lowest stream.
440TEST_F(TestSimulcastEncoderAdapterFake, ReusesEncodersInOrder) {
441 // Set up common settings for three streams.
442 TestVp8Simulcast::DefaultSettings(
443 &codec_, static_cast<const int*>(kTestTemporalLayerProfile));
444 rate_allocator_.reset(new SimulcastRateAllocator(codec_, nullptr));
445 tl_factory_.SetListener(rate_allocator_.get());
446 codec_.VP8()->tl_factory = &tl_factory_;
447 adapter_->RegisterEncodeCompleteCallback(this);
448
449 // Input data.
450 rtc::scoped_refptr<VideoFrameBuffer> buffer(I420Buffer::Create(1280, 720));
451 VideoFrame input_frame(buffer, 100, 1000, kVideoRotation_180);
452 std::vector<FrameType> frame_types;
453
454 // Encode with three streams.
455 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
456 VerifyCodecSettings();
457 std::vector<MockVideoEncoder*> original_encoders =
458 helper_->factory()->encoders();
459 ASSERT_EQ(3u, original_encoders.size());
460 EXPECT_CALL(*original_encoders[0], Encode(_, _, _))
461 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
462 EXPECT_CALL(*original_encoders[1], Encode(_, _, _))
463 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
464 EXPECT_CALL(*original_encoders[2], Encode(_, _, _))
465 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
466 frame_types.resize(3, kVideoFrameKey);
467 EXPECT_EQ(0, adapter_->Encode(input_frame, nullptr, &frame_types));
468 EXPECT_CALL(*original_encoders[0], Release())
469 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
470 EXPECT_CALL(*original_encoders[1], Release())
471 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
472 EXPECT_CALL(*original_encoders[2], Release())
473 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
474 EXPECT_EQ(0, adapter_->Release());
475
476 // Encode with two streams.
477 codec_.width /= 2;
478 codec_.height /= 2;
479 codec_.numberOfSimulcastStreams = 2;
480 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
481 std::vector<MockVideoEncoder*> new_encoders = helper_->factory()->encoders();
482 ASSERT_EQ(2u, new_encoders.size());
483 ASSERT_EQ(original_encoders[0], new_encoders[0]);
484 EXPECT_CALL(*original_encoders[0], Encode(_, _, _))
485 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
486 ASSERT_EQ(original_encoders[1], new_encoders[1]);
487 EXPECT_CALL(*original_encoders[1], Encode(_, _, _))
488 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
489 frame_types.resize(2, kVideoFrameKey);
490 EXPECT_EQ(0, adapter_->Encode(input_frame, nullptr, &frame_types));
491 EXPECT_CALL(*original_encoders[0], Release())
492 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
493 EXPECT_CALL(*original_encoders[1], Release())
494 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
495 EXPECT_EQ(0, adapter_->Release());
496
497 // Encode with single stream.
498 codec_.width /= 2;
499 codec_.height /= 2;
500 codec_.numberOfSimulcastStreams = 1;
501 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
502 new_encoders = helper_->factory()->encoders();
503 ASSERT_EQ(1u, new_encoders.size());
504 ASSERT_EQ(original_encoders[0], new_encoders[0]);
505 EXPECT_CALL(*original_encoders[0], Encode(_, _, _))
506 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
507 frame_types.resize(1, kVideoFrameKey);
508 EXPECT_EQ(0, adapter_->Encode(input_frame, nullptr, &frame_types));
509 EXPECT_CALL(*original_encoders[0], Release())
510 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
511 EXPECT_EQ(0, adapter_->Release());
512
513 // Encode with three streams, again.
514 codec_.width *= 4;
515 codec_.height *= 4;
516 codec_.numberOfSimulcastStreams = 3;
517 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
518 new_encoders = helper_->factory()->encoders();
519 ASSERT_EQ(3u, new_encoders.size());
520 // The first encoder is reused.
521 ASSERT_EQ(original_encoders[0], new_encoders[0]);
522 EXPECT_CALL(*original_encoders[0], Encode(_, _, _))
523 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
524 // The second and third encoders are new.
525 EXPECT_CALL(*new_encoders[1], Encode(_, _, _))
526 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
527 EXPECT_CALL(*new_encoders[2], Encode(_, _, _))
528 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
529 frame_types.resize(3, kVideoFrameKey);
530 EXPECT_EQ(0, adapter_->Encode(input_frame, nullptr, &frame_types));
531 EXPECT_CALL(*original_encoders[0], Release())
532 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
533 EXPECT_CALL(*new_encoders[1], Release())
534 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
535 EXPECT_CALL(*new_encoders[2], Release())
536 .WillOnce(Return(WEBRTC_VIDEO_CODEC_OK));
537 EXPECT_EQ(0, adapter_->Release());
538}
539
540TEST_F(TestSimulcastEncoderAdapterFake, DoesNotLeakEncoders) {
541 SetupCodec();
542 VerifyCodecSettings();
543
544 EXPECT_EQ(3u, helper_->factory()->encoders().size());
545
546 // The adapter should destroy all encoders it has allocated. Since
547 // |helper_->factory()| is owned by |adapter_|, however, we need to rely on
548 // lsan to find leaks here.
549 EXPECT_EQ(0, adapter_->Release());
550 adapter_.reset();
551}
552
553// This test verifies that an adapter reinit with the same codec settings as
554// before does not change the underlying encoder codec settings.
555TEST_F(TestSimulcastEncoderAdapterFake, ReinitDoesNotReorderEncoderSettings) {
556 SetupCodec();
557 VerifyCodecSettings();
558
559 // Capture current codec settings.
560 std::vector<MockVideoEncoder*> encoders = helper_->factory()->encoders();
561 ASSERT_EQ(3u, encoders.size());
562 std::array<VideoCodec, 3> codecs_before;
563 for (int i = 0; i < 3; ++i) {
564 codecs_before[i] = encoders[i]->codec();
565 }
566
567 // Reinitialize and verify that the new codec settings are the same.
568 EXPECT_EQ(0, adapter_->Release());
569 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
570 for (int i = 0; i < 3; ++i) {
571 const VideoCodec& codec_before = codecs_before[i];
572 const VideoCodec& codec_after = encoders[i]->codec();
573
574 // webrtc::VideoCodec does not implement operator==.
575 EXPECT_EQ(codec_before.codecType, codec_after.codecType);
576 EXPECT_EQ(codec_before.plType, codec_after.plType);
577 EXPECT_EQ(codec_before.width, codec_after.width);
578 EXPECT_EQ(codec_before.height, codec_after.height);
579 EXPECT_EQ(codec_before.startBitrate, codec_after.startBitrate);
580 EXPECT_EQ(codec_before.maxBitrate, codec_after.maxBitrate);
581 EXPECT_EQ(codec_before.minBitrate, codec_after.minBitrate);
582 EXPECT_EQ(codec_before.targetBitrate, codec_after.targetBitrate);
583 EXPECT_EQ(codec_before.maxFramerate, codec_after.maxFramerate);
584 EXPECT_EQ(codec_before.qpMax, codec_after.qpMax);
585 EXPECT_EQ(codec_before.numberOfSimulcastStreams,
586 codec_after.numberOfSimulcastStreams);
587 EXPECT_EQ(codec_before.mode, codec_after.mode);
588 EXPECT_EQ(codec_before.expect_encode_from_texture,
589 codec_after.expect_encode_from_texture);
590 }
591}
592
593// This test is similar to the one above, except that it tests the simulcastIdx
594// from the CodecSpecificInfo that is connected to an encoded frame. The
595// PayloadRouter demuxes the incoming encoded frames on different RTP modules
596// using the simulcastIdx, so it's important that there is no corresponding
597// encoder reordering in between adapter reinits as this would lead to PictureID
598// discontinuities.
599TEST_F(TestSimulcastEncoderAdapterFake, ReinitDoesNotReorderFrameSimulcastIdx) {
600 SetupCodec();
601 adapter_->SetRateAllocation(rate_allocator_->GetAllocation(1200, 30), 30);
602 VerifyCodecSettings();
603
604 // Send frames on all streams.
605 std::vector<MockVideoEncoder*> encoders = helper_->factory()->encoders();
606 ASSERT_EQ(3u, encoders.size());
607 encoders[0]->SendEncodedImage(1152, 704);
608 int width;
609 int height;
610 int simulcast_index;
611 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
612 EXPECT_EQ(0, simulcast_index);
613
614 encoders[1]->SendEncodedImage(300, 620);
615 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
616 EXPECT_EQ(1, simulcast_index);
617
618 encoders[2]->SendEncodedImage(120, 240);
619 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
620 EXPECT_EQ(2, simulcast_index);
621
622 // Reinitialize.
623 EXPECT_EQ(0, adapter_->Release());
624 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
625 adapter_->SetRateAllocation(rate_allocator_->GetAllocation(1200, 30), 30);
626
627 // Verify that the same encoder sends out frames on the same simulcast index.
628 encoders[0]->SendEncodedImage(1152, 704);
629 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
630 EXPECT_EQ(0, simulcast_index);
631
632 encoders[1]->SendEncodedImage(300, 620);
633 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
634 EXPECT_EQ(1, simulcast_index);
635
636 encoders[2]->SendEncodedImage(120, 240);
637 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index));
638 EXPECT_EQ(2, simulcast_index);
639}
640
pbos65e15ba2015-10-15 10:52:15 -0700641TEST_F(TestSimulcastEncoderAdapterFake, SupportsNativeHandleForSingleStreams) {
642 TestVp8Simulcast::DefaultSettings(
643 &codec_, static_cast<const int*>(kTestTemporalLayerProfile));
Erik Språng08127a92016-11-16 16:41:30 +0100644 codec_.VP8()->tl_factory = &tl_factory_;
pbos65e15ba2015-10-15 10:52:15 -0700645 codec_.numberOfSimulcastStreams = 1;
646 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
647 adapter_->RegisterEncodeCompleteCallback(this);
648 ASSERT_EQ(1u, helper_->factory()->encoders().size());
649 helper_->factory()->encoders()[0]->set_supports_native_handle(true);
650 EXPECT_TRUE(adapter_->SupportsNativeHandle());
651 helper_->factory()->encoders()[0]->set_supports_native_handle(false);
652 EXPECT_FALSE(adapter_->SupportsNativeHandle());
653}
654
noahricfac0ff02016-09-09 10:27:15 -0700655TEST_F(TestSimulcastEncoderAdapterFake, SetRatesUnderMinBitrate) {
656 TestVp8Simulcast::DefaultSettings(
657 &codec_, static_cast<const int*>(kTestTemporalLayerProfile));
Erik Språng08127a92016-11-16 16:41:30 +0100658 codec_.VP8()->tl_factory = &tl_factory_;
noahricfac0ff02016-09-09 10:27:15 -0700659 codec_.minBitrate = 50;
660 codec_.numberOfSimulcastStreams = 1;
661 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
Erik Språng08127a92016-11-16 16:41:30 +0100662 rate_allocator_.reset(new SimulcastRateAllocator(codec_, nullptr));
noahricfac0ff02016-09-09 10:27:15 -0700663
664 // Above min should be respected.
Erik Språng08127a92016-11-16 16:41:30 +0100665 BitrateAllocation target_bitrate =
666 rate_allocator_->GetAllocation(codec_.minBitrate * 1000, 30);
667 adapter_->SetRateAllocation(target_bitrate, 30);
668 EXPECT_EQ(target_bitrate,
669 helper_->factory()->encoders()[0]->last_set_bitrate());
noahricfac0ff02016-09-09 10:27:15 -0700670
671 // Below min but non-zero should be replaced with the min bitrate.
Erik Språng08127a92016-11-16 16:41:30 +0100672 BitrateAllocation too_low_bitrate =
673 rate_allocator_->GetAllocation((codec_.minBitrate - 1) * 1000, 30);
674 adapter_->SetRateAllocation(too_low_bitrate, 30);
675 EXPECT_EQ(target_bitrate,
676 helper_->factory()->encoders()[0]->last_set_bitrate());
noahricfac0ff02016-09-09 10:27:15 -0700677
678 // Zero should be passed on as is, since it means "pause".
Erik Språng08127a92016-11-16 16:41:30 +0100679 adapter_->SetRateAllocation(BitrateAllocation(), 30);
680 EXPECT_EQ(BitrateAllocation(),
681 helper_->factory()->encoders()[0]->last_set_bitrate());
noahricfac0ff02016-09-09 10:27:15 -0700682}
683
Peter Boströma5dec162016-01-20 15:53:55 +0100684TEST_F(TestSimulcastEncoderAdapterFake, SupportsImplementationName) {
685 EXPECT_STREQ("SimulcastEncoderAdapter", adapter_->ImplementationName());
686 TestVp8Simulcast::DefaultSettings(
687 &codec_, static_cast<const int*>(kTestTemporalLayerProfile));
Erik Språng08127a92016-11-16 16:41:30 +0100688 codec_.VP8()->tl_factory = &tl_factory_;
Peter Boströma5dec162016-01-20 15:53:55 +0100689 std::vector<const char*> encoder_names;
690 encoder_names.push_back("codec1");
691 encoder_names.push_back("codec2");
692 encoder_names.push_back("codec3");
693 helper_->factory()->SetEncoderNames(encoder_names);
694 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
695 EXPECT_STREQ("SimulcastEncoderAdapter (codec1, codec2, codec3)",
696 adapter_->ImplementationName());
Peter Boströmd53c3892016-03-30 17:03:52 +0200697
698 // Single streams should not expose "SimulcastEncoderAdapter" in name.
brandtr5e171752017-05-23 03:32:16 -0700699 EXPECT_EQ(0, adapter_->Release());
Peter Boströmd53c3892016-03-30 17:03:52 +0200700 codec_.numberOfSimulcastStreams = 1;
701 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
702 adapter_->RegisterEncodeCompleteCallback(this);
703 ASSERT_EQ(1u, helper_->factory()->encoders().size());
704 EXPECT_STREQ("codec1", adapter_->ImplementationName());
Peter Boströma5dec162016-01-20 15:53:55 +0100705}
706
pbos65e15ba2015-10-15 10:52:15 -0700707TEST_F(TestSimulcastEncoderAdapterFake,
noahricfe3654d2016-07-01 09:05:54 -0700708 SupportsNativeHandleForMultipleStreams) {
pbos65e15ba2015-10-15 10:52:15 -0700709 TestVp8Simulcast::DefaultSettings(
710 &codec_, static_cast<const int*>(kTestTemporalLayerProfile));
Erik Språng08127a92016-11-16 16:41:30 +0100711 codec_.VP8()->tl_factory = &tl_factory_;
pbos65e15ba2015-10-15 10:52:15 -0700712 codec_.numberOfSimulcastStreams = 3;
713 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
714 adapter_->RegisterEncodeCompleteCallback(this);
715 ASSERT_EQ(3u, helper_->factory()->encoders().size());
716 for (MockVideoEncoder* encoder : helper_->factory()->encoders())
717 encoder->set_supports_native_handle(true);
noahricfe3654d2016-07-01 09:05:54 -0700718 // If one encoder doesn't support it, then overall support is disabled.
719 helper_->factory()->encoders()[0]->set_supports_native_handle(false);
pbos65e15ba2015-10-15 10:52:15 -0700720 EXPECT_FALSE(adapter_->SupportsNativeHandle());
noahricfe3654d2016-07-01 09:05:54 -0700721 // Once all do, then the adapter claims support.
722 helper_->factory()->encoders()[0]->set_supports_native_handle(true);
723 EXPECT_TRUE(adapter_->SupportsNativeHandle());
724}
725
nisseaf916892017-01-10 07:44:26 -0800726// TODO(nisse): Reuse definition in webrtc/test/fake_texture_handle.h.
Magnus Jedvert72dbe2a2017-06-10 17:03:37 +0000727class FakeNativeBuffer : public VideoFrameBuffer {
noahricfe3654d2016-07-01 09:05:54 -0700728 public:
Magnus Jedvert72dbe2a2017-06-10 17:03:37 +0000729 FakeNativeBuffer(int width, int height) : width_(width), height_(height) {}
730
731 Type type() const override { return Type::kNative; }
732 int width() const override { return width_; }
733 int height() const override { return height_; }
734
735 rtc::scoped_refptr<I420BufferInterface> ToI420() override {
noahricfe3654d2016-07-01 09:05:54 -0700736 RTC_NOTREACHED();
737 return nullptr;
738 }
Magnus Jedvert72dbe2a2017-06-10 17:03:37 +0000739
740 private:
741 const int width_;
742 const int height_;
noahricfe3654d2016-07-01 09:05:54 -0700743};
744
745TEST_F(TestSimulcastEncoderAdapterFake,
746 NativeHandleForwardingForMultipleStreams) {
747 TestVp8Simulcast::DefaultSettings(
748 &codec_, static_cast<const int*>(kTestTemporalLayerProfile));
Erik Språng08127a92016-11-16 16:41:30 +0100749 codec_.VP8()->tl_factory = &tl_factory_;
noahricfe3654d2016-07-01 09:05:54 -0700750 codec_.numberOfSimulcastStreams = 3;
751 // High start bitrate, so all streams are enabled.
752 codec_.startBitrate = 3000;
753 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
754 adapter_->RegisterEncodeCompleteCallback(this);
755 ASSERT_EQ(3u, helper_->factory()->encoders().size());
756 for (MockVideoEncoder* encoder : helper_->factory()->encoders())
757 encoder->set_supports_native_handle(true);
758 EXPECT_TRUE(adapter_->SupportsNativeHandle());
759
760 rtc::scoped_refptr<VideoFrameBuffer> buffer(
Magnus Jedvert72dbe2a2017-06-10 17:03:37 +0000761 new rtc::RefCountedObject<FakeNativeBuffer>(1280, 720));
noahricfe3654d2016-07-01 09:05:54 -0700762 VideoFrame input_frame(buffer, 100, 1000, kVideoRotation_180);
763 // Expect calls with the given video frame verbatim, since it's a texture
764 // frame and can't otherwise be modified/resized.
765 for (MockVideoEncoder* encoder : helper_->factory()->encoders())
766 EXPECT_CALL(*encoder, Encode(::testing::Ref(input_frame), _, _)).Times(1);
767 std::vector<FrameType> frame_types(3, kVideoFrameKey);
brandtr5e171752017-05-23 03:32:16 -0700768 EXPECT_EQ(0, adapter_->Encode(input_frame, nullptr, &frame_types));
pbos65e15ba2015-10-15 10:52:15 -0700769}
770
noahric57779102016-05-25 06:48:46 -0700771TEST_F(TestSimulcastEncoderAdapterFake, TestFailureReturnCodesFromEncodeCalls) {
772 TestVp8Simulcast::DefaultSettings(
773 &codec_, static_cast<const int*>(kTestTemporalLayerProfile));
Erik Språng08127a92016-11-16 16:41:30 +0100774 codec_.VP8()->tl_factory = &tl_factory_;
noahric57779102016-05-25 06:48:46 -0700775 codec_.numberOfSimulcastStreams = 3;
776 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
777 adapter_->RegisterEncodeCompleteCallback(this);
778 ASSERT_EQ(3u, helper_->factory()->encoders().size());
779 // Tell the 2nd encoder to request software fallback.
noahricfe3654d2016-07-01 09:05:54 -0700780 EXPECT_CALL(*helper_->factory()->encoders()[1], Encode(_, _, _))
781 .WillOnce(Return(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE));
noahric57779102016-05-25 06:48:46 -0700782
783 // Send a fake frame and assert the return is software fallback.
Magnus Jedvert72dbe2a2017-06-10 17:03:37 +0000784 rtc::scoped_refptr<I420Buffer> input_buffer =
785 I420Buffer::Create(kDefaultWidth, kDefaultHeight);
nisse64ec8f82016-09-27 00:17:25 -0700786 input_buffer->InitializeData();
787 VideoFrame input_frame(input_buffer, 0, 0, webrtc::kVideoRotation_0);
noahric57779102016-05-25 06:48:46 -0700788 std::vector<FrameType> frame_types(3, kVideoFrameKey);
789 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE,
790 adapter_->Encode(input_frame, nullptr, &frame_types));
791}
792
noahrice5ba75a2016-12-12 13:08:27 -0800793TEST_F(TestSimulcastEncoderAdapterFake, TestInitFailureCleansUpEncoders) {
794 TestVp8Simulcast::DefaultSettings(
795 &codec_, static_cast<const int*>(kTestTemporalLayerProfile));
796 codec_.VP8()->tl_factory = &tl_factory_;
797 codec_.numberOfSimulcastStreams = 3;
798 helper_->factory()->set_init_encode_return_value(
799 WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE);
800 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE,
801 adapter_->InitEncode(&codec_, 1, 1200));
802 EXPECT_TRUE(helper_->factory()->encoders().empty());
803}
804
pbos@webrtc.org9115cde2014-12-09 10:36:40 +0000805} // namespace testing
806} // namespace webrtc