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

Side by Side Diff: webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter_unittest.cc

Issue 1913073002: Extract common simulcast logic from VP8 wrapper and simulcast adapter (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Address comments, added tests Created 4 years, 7 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 10
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 } 125 }
126 126
127 int32_t RegisterEncodeCompleteCallback( 127 int32_t RegisterEncodeCompleteCallback(
128 EncodedImageCallback* callback) /* override */ { 128 EncodedImageCallback* callback) /* override */ {
129 callback_ = callback; 129 callback_ = callback;
130 return 0; 130 return 0;
131 } 131 }
132 132
133 int32_t Release() /* override */ { return 0; } 133 int32_t Release() /* override */ { return 0; }
134 134
135 int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) /* override */ { 135 MOCK_METHOD2(SetRates, int32_t(uint32_t newBitRate, uint32_t frameRate));
136 return 0;
137 }
138
139 MOCK_METHOD2(SetChannelParameters, int32_t(uint32_t packetLoss, int64_t rtt)); 136 MOCK_METHOD2(SetChannelParameters, int32_t(uint32_t packetLoss, int64_t rtt));
140 137
141 bool SupportsNativeHandle() const /* override */ { 138 bool SupportsNativeHandle() const /* override */ {
142 return supports_native_handle_; 139 return supports_native_handle_;
143 } 140 }
144 141
145 virtual ~MockVideoEncoder() {} 142 virtual ~MockVideoEncoder() {}
146 143
147 const VideoCodec& codec() const { return codec_; } 144 const VideoCodec& codec() const { return codec_; }
148 145
(...skipping 19 matching lines...) Expand all
168 EncodedImageCallback* callback_; 165 EncodedImageCallback* callback_;
169 }; 166 };
170 167
171 class MockVideoEncoderFactory : public VideoEncoderFactory { 168 class MockVideoEncoderFactory : public VideoEncoderFactory {
172 public: 169 public:
173 VideoEncoder* Create() override { 170 VideoEncoder* Create() override {
174 MockVideoEncoder* encoder = new MockVideoEncoder(); 171 MockVideoEncoder* encoder = new MockVideoEncoder();
175 const char* encoder_name = encoder_names_.empty() 172 const char* encoder_name = encoder_names_.empty()
176 ? "codec_implementation_name" 173 ? "codec_implementation_name"
177 : encoder_names_[encoders_.size()]; 174 : encoder_names_[encoders_.size()];
178 ON_CALL(*encoder, ImplementationName()).WillByDefault(Return(encoder_name)); 175 EXPECT_CALL(*encoder, ImplementationName())
176 .WillRepeatedly(Return(encoder_name));
179 encoders_.push_back(encoder); 177 encoders_.push_back(encoder);
180 return encoder; 178 return encoder;
181 } 179 }
182 180
183 void Destroy(VideoEncoder* encoder) override { 181 void Destroy(VideoEncoder* encoder) override {
184 for (size_t i = 0; i < encoders_.size(); ++i) { 182 for (size_t i = 0; i < encoders_.size(); ++i) {
185 if (encoders_[i] == encoder) { 183 if (encoders_[i] == encoder) {
186 encoders_.erase(encoders_.begin() + i); 184 encoders_.erase(encoders_.begin() + i);
187 break; 185 break;
188 } 186 }
189 } 187 }
190 delete encoder; 188 delete encoder;
191 } 189 }
192 190
191 void ExpectRates(const std::vector<int>& expected_bitrates_kbps,
192 int expected_framerate) {
193 ASSERT_EQ(encoders_.size(), expected_bitrates_kbps.size());
194 for (size_t i = 0; i < expected_bitrates_kbps.size(); ++i) {
195 EXPECT_CALL(*encoders_[i],
196 SetRates(expected_bitrates_kbps[i], expected_framerate))
197 .WillOnce(Return(0));
198 }
199 }
200
193 virtual ~MockVideoEncoderFactory() {} 201 virtual ~MockVideoEncoderFactory() {}
194 202
195 const std::vector<MockVideoEncoder*>& encoders() const { return encoders_; } 203 const std::vector<MockVideoEncoder*>& encoders() const { return encoders_; }
196 void SetEncoderNames(const std::vector<const char*>& encoder_names) { 204 void SetEncoderNames(const std::vector<const char*>& encoder_names) {
197 encoder_names_ = encoder_names; 205 encoder_names_ = encoder_names;
198 } 206 }
199 207
200 private: 208 private:
201 std::vector<MockVideoEncoder*> encoders_; 209 std::vector<MockVideoEncoder*> encoders_;
202 std::vector<const char*> encoder_names_; 210 std::vector<const char*> encoder_names_;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 const uint32_t packetLoss = 5; 381 const uint32_t packetLoss = 5;
374 const int64_t rtt = 30; 382 const int64_t rtt = 30;
375 helper_->ExpectCallSetChannelParameters(packetLoss, rtt); 383 helper_->ExpectCallSetChannelParameters(packetLoss, rtt);
376 adapter_->SetChannelParameters(packetLoss, rtt); 384 adapter_->SetChannelParameters(packetLoss, rtt);
377 } 385 }
378 386
379 TEST_F(TestSimulcastEncoderAdapterFake, EncodedCallbackForDifferentEncoders) { 387 TEST_F(TestSimulcastEncoderAdapterFake, EncodedCallbackForDifferentEncoders) {
380 SetupCodec(); 388 SetupCodec();
381 389
382 // Set bitrates so that we send all layers. 390 // Set bitrates so that we send all layers.
383 adapter_->SetRates(1200, 30); 391 int total_bitrate_kbps = 0;
392 std::vector<int> expected_rates_kbps;
393 for (int i = 0; i < codec_.numberOfSimulcastStreams; ++i) {
394 expected_rates_kbps.push_back(codec_.simulcastStream[i].targetBitrate);
395 total_bitrate_kbps += codec_.simulcastStream[i].targetBitrate;
396 }
397
398 int kFrameRate = 30;
399 helper_->factory()->ExpectRates(expected_rates_kbps, kFrameRate);
400 adapter_->SetRates(total_bitrate_kbps, kFrameRate);
384 401
385 // At this point, the simulcast encoder adapter should have 3 streams: HD, 402 // At this point, the simulcast encoder adapter should have 3 streams: HD,
386 // quarter HD, and quarter quarter HD. We're going to mostly ignore the exact 403 // quarter HD, and quarter quarter HD. We're going to mostly ignore the exact
387 // resolutions, to test that the adapter forwards on the correct resolution 404 // resolutions, to test that the adapter forwards on the correct resolution
388 // and simulcast index values, going only off the encoder that generates the 405 // and simulcast index values, going only off the encoder that generates the
389 // image. 406 // image.
390 EXPECT_EQ(3u, helper_->factory()->encoders().size()); 407 EXPECT_EQ(3u, helper_->factory()->encoders().size());
391 helper_->factory()->encoders()[0]->SendEncodedImage(1152, 704); 408 helper_->factory()->encoders()[0]->SendEncodedImage(1152, 704);
392 int width; 409 int width;
393 int height; 410 int height;
(...skipping 23 matching lines...) Expand all
417 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); 434 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
418 adapter_->RegisterEncodeCompleteCallback(this); 435 adapter_->RegisterEncodeCompleteCallback(this);
419 ASSERT_EQ(1u, helper_->factory()->encoders().size()); 436 ASSERT_EQ(1u, helper_->factory()->encoders().size());
420 helper_->factory()->encoders()[0]->set_supports_native_handle(true); 437 helper_->factory()->encoders()[0]->set_supports_native_handle(true);
421 EXPECT_TRUE(adapter_->SupportsNativeHandle()); 438 EXPECT_TRUE(adapter_->SupportsNativeHandle());
422 helper_->factory()->encoders()[0]->set_supports_native_handle(false); 439 helper_->factory()->encoders()[0]->set_supports_native_handle(false);
423 EXPECT_FALSE(adapter_->SupportsNativeHandle()); 440 EXPECT_FALSE(adapter_->SupportsNativeHandle());
424 } 441 }
425 442
426 TEST_F(TestSimulcastEncoderAdapterFake, SupportsImplementationName) { 443 TEST_F(TestSimulcastEncoderAdapterFake, SupportsImplementationName) {
427 EXPECT_STREQ("SimulcastEncoderAdapter", adapter_->ImplementationName()); 444 EXPECT_STREQ("SimulcastEncoderAdapter (uninitialized)",
445 adapter_->ImplementationName());
428 TestVp8Simulcast::DefaultSettings( 446 TestVp8Simulcast::DefaultSettings(
429 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); 447 &codec_, static_cast<const int*>(kTestTemporalLayerProfile));
430 std::vector<const char*> encoder_names; 448 std::vector<const char*> encoder_names;
431 encoder_names.push_back("codec1"); 449 encoder_names.push_back("codec1");
432 encoder_names.push_back("codec2"); 450 encoder_names.push_back("codec2");
433 encoder_names.push_back("codec3"); 451 encoder_names.push_back("codec3");
434 helper_->factory()->SetEncoderNames(encoder_names); 452 helper_->factory()->SetEncoderNames(encoder_names);
435 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); 453 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
436 EXPECT_STREQ("SimulcastEncoderAdapter (codec1, codec2, codec3)", 454 EXPECT_STREQ("SimulcastEncoderAdapter (codec1, codec2, codec3)",
437 adapter_->ImplementationName()); 455 adapter_->ImplementationName());
(...skipping 17 matching lines...) Expand all
455 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); 473 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200));
456 adapter_->RegisterEncodeCompleteCallback(this); 474 adapter_->RegisterEncodeCompleteCallback(this);
457 ASSERT_EQ(3u, helper_->factory()->encoders().size()); 475 ASSERT_EQ(3u, helper_->factory()->encoders().size());
458 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) 476 for (MockVideoEncoder* encoder : helper_->factory()->encoders())
459 encoder->set_supports_native_handle(true); 477 encoder->set_supports_native_handle(true);
460 EXPECT_FALSE(adapter_->SupportsNativeHandle()); 478 EXPECT_FALSE(adapter_->SupportsNativeHandle());
461 } 479 }
462 480
463 } // namespace testing 481 } // namespace testing
464 } // namespace webrtc 482 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698