Index: webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter_unittest.cc |
diff --git a/webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter_unittest.cc b/webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter_unittest.cc |
index 9a06c0ac5f69c7530086cc741623c6d791b42491..b3fe8e053de7fc27f929044f06729e03c8bb6da4 100644 |
--- a/webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter_unittest.cc |
+++ b/webrtc/modules/video_coding/codecs/vp8/simulcast_encoder_adapter_unittest.cc |
@@ -95,12 +95,6 @@ TEST_F(TestSimulcastEncoderAdapter, TestSpatioTemporalLayers321PatternEncoder) { |
TestVp8Simulcast::TestSpatioTemporalLayers321PatternEncoder(); |
} |
-// TODO(ronghuawu): Enable this test when SkipEncodingUnusedStreams option is |
-// implemented for SimulcastEncoderAdapter. |
-TEST_F(TestSimulcastEncoderAdapter, DISABLED_TestSkipEncodingUnusedStreams) { |
- TestVp8Simulcast::TestSkipEncodingUnusedStreams(); |
-} |
- |
TEST_F(TestSimulcastEncoderAdapter, DISABLED_TestRPSIEncoder) { |
TestVp8Simulcast::TestRPSIEncoder(); |
} |
@@ -132,8 +126,9 @@ class MockVideoEncoder : public VideoEncoder { |
int32_t Release() /* override */ { return 0; } |
- int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) /* override */ { |
- last_set_bitrate_ = static_cast<int32_t>(newBitRate); |
+ int32_t SetRateAllocation(const BitrateAllocation& bitrate_allocation, |
+ uint32_t framerate) { |
+ last_set_bitrate_ = bitrate_allocation; |
return 0; |
} |
@@ -160,13 +155,13 @@ class MockVideoEncoder : public VideoEncoder { |
void set_supports_native_handle(bool enabled) { |
supports_native_handle_ = enabled; |
} |
- int32_t last_set_bitrate() const { return last_set_bitrate_; } |
+ BitrateAllocation last_set_bitrate() const { return last_set_bitrate_; } |
MOCK_CONST_METHOD0(ImplementationName, const char*()); |
private: |
bool supports_native_handle_ = false; |
- int32_t last_set_bitrate_ = -1; |
+ BitrateAllocation last_set_bitrate_; |
VideoCodec codec_; |
EncodedImageCallback* callback_; |
@@ -273,6 +268,9 @@ class TestSimulcastEncoderAdapterFake : public ::testing::Test, |
void SetupCodec() { |
TestVp8Simulcast::DefaultSettings( |
&codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
+ rate_allocator_.reset(new SimulcastRateAllocator(codec_, nullptr)); |
+ tl_factory_.SetListener(rate_allocator_.get()); |
+ codec_.VP8()->tl_factory = &tl_factory_; |
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
adapter_->RegisterEncodeCompleteCallback(this); |
} |
@@ -301,7 +299,6 @@ class TestSimulcastEncoderAdapterFake : public ::testing::Test, |
EXPECT_EQ(ref.VP8().automaticResizeOn, target.VP8().automaticResizeOn); |
EXPECT_EQ(ref.VP8().frameDroppingOn, target.VP8().frameDroppingOn); |
EXPECT_EQ(ref.VP8().keyFrameInterval, target.VP8().keyFrameInterval); |
- EXPECT_EQ(ref.VP8().tl_factory, target.VP8().tl_factory); |
EXPECT_EQ(ref.qpMax, target.qpMax); |
EXPECT_EQ(0, target.numberOfSimulcastStreams); |
EXPECT_EQ(ref.mode, target.mode); |
@@ -314,6 +311,7 @@ class TestSimulcastEncoderAdapterFake : public ::testing::Test, |
*ref_codec = codec_; |
ref_codec->VP8()->numberOfTemporalLayers = |
kTestTemporalLayerProfile[stream_index]; |
+ ref_codec->VP8()->tl_factory = &tl_factory_; |
ref_codec->width = codec_.simulcastStream[stream_index].width; |
ref_codec->height = codec_.simulcastStream[stream_index].height; |
ref_codec->maxBitrate = codec_.simulcastStream[stream_index].maxBitrate; |
@@ -357,6 +355,8 @@ class TestSimulcastEncoderAdapterFake : public ::testing::Test, |
int last_encoded_image_width_; |
int last_encoded_image_height_; |
int last_encoded_image_simulcast_index_; |
+ TemporalLayersFactory tl_factory_; |
+ std::unique_ptr<SimulcastRateAllocator> rate_allocator_; |
}; |
TEST_F(TestSimulcastEncoderAdapterFake, InitEncode) { |
@@ -376,7 +376,7 @@ TEST_F(TestSimulcastEncoderAdapterFake, EncodedCallbackForDifferentEncoders) { |
SetupCodec(); |
// Set bitrates so that we send all layers. |
- adapter_->SetRates(1200, 30); |
+ adapter_->SetRateAllocation(rate_allocator_->GetAllocation(1200, 30), 30); |
// At this point, the simulcast encoder adapter should have 3 streams: HD, |
// quarter HD, and quarter quarter HD. We're going to mostly ignore the exact |
@@ -409,6 +409,7 @@ TEST_F(TestSimulcastEncoderAdapterFake, EncodedCallbackForDifferentEncoders) { |
TEST_F(TestSimulcastEncoderAdapterFake, SupportsNativeHandleForSingleStreams) { |
TestVp8Simulcast::DefaultSettings( |
&codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
+ codec_.VP8()->tl_factory = &tl_factory_; |
codec_.numberOfSimulcastStreams = 1; |
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
adapter_->RegisterEncodeCompleteCallback(this); |
@@ -422,27 +423,37 @@ TEST_F(TestSimulcastEncoderAdapterFake, SupportsNativeHandleForSingleStreams) { |
TEST_F(TestSimulcastEncoderAdapterFake, SetRatesUnderMinBitrate) { |
TestVp8Simulcast::DefaultSettings( |
&codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
+ codec_.VP8()->tl_factory = &tl_factory_; |
codec_.minBitrate = 50; |
codec_.numberOfSimulcastStreams = 1; |
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
+ rate_allocator_.reset(new SimulcastRateAllocator(codec_, nullptr)); |
// Above min should be respected. |
- adapter_->SetRates(100, 30); |
- EXPECT_EQ(100, helper_->factory()->encoders()[0]->last_set_bitrate()); |
+ BitrateAllocation target_bitrate = |
+ rate_allocator_->GetAllocation(codec_.minBitrate * 1000, 30); |
+ adapter_->SetRateAllocation(target_bitrate, 30); |
+ EXPECT_EQ(target_bitrate, |
+ helper_->factory()->encoders()[0]->last_set_bitrate()); |
// Below min but non-zero should be replaced with the min bitrate. |
- adapter_->SetRates(15, 30); |
- EXPECT_EQ(50, helper_->factory()->encoders()[0]->last_set_bitrate()); |
+ BitrateAllocation too_low_bitrate = |
+ rate_allocator_->GetAllocation((codec_.minBitrate - 1) * 1000, 30); |
+ adapter_->SetRateAllocation(too_low_bitrate, 30); |
+ EXPECT_EQ(target_bitrate, |
+ helper_->factory()->encoders()[0]->last_set_bitrate()); |
// Zero should be passed on as is, since it means "pause". |
- adapter_->SetRates(0, 30); |
- EXPECT_EQ(0, helper_->factory()->encoders()[0]->last_set_bitrate()); |
+ adapter_->SetRateAllocation(BitrateAllocation(), 30); |
+ EXPECT_EQ(BitrateAllocation(), |
+ helper_->factory()->encoders()[0]->last_set_bitrate()); |
} |
TEST_F(TestSimulcastEncoderAdapterFake, SupportsImplementationName) { |
EXPECT_STREQ("SimulcastEncoderAdapter", adapter_->ImplementationName()); |
TestVp8Simulcast::DefaultSettings( |
&codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
+ codec_.VP8()->tl_factory = &tl_factory_; |
std::vector<const char*> encoder_names; |
encoder_names.push_back("codec1"); |
encoder_names.push_back("codec2"); |
@@ -465,6 +476,7 @@ TEST_F(TestSimulcastEncoderAdapterFake, |
SupportsNativeHandleForMultipleStreams) { |
TestVp8Simulcast::DefaultSettings( |
&codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
+ codec_.VP8()->tl_factory = &tl_factory_; |
codec_.numberOfSimulcastStreams = 3; |
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
adapter_->RegisterEncodeCompleteCallback(this); |
@@ -493,6 +505,7 @@ TEST_F(TestSimulcastEncoderAdapterFake, |
NativeHandleForwardingForMultipleStreams) { |
TestVp8Simulcast::DefaultSettings( |
&codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
+ codec_.VP8()->tl_factory = &tl_factory_; |
codec_.numberOfSimulcastStreams = 3; |
// High start bitrate, so all streams are enabled. |
codec_.startBitrate = 3000; |
@@ -517,6 +530,7 @@ TEST_F(TestSimulcastEncoderAdapterFake, |
TEST_F(TestSimulcastEncoderAdapterFake, TestFailureReturnCodesFromEncodeCalls) { |
TestVp8Simulcast::DefaultSettings( |
&codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
+ codec_.VP8()->tl_factory = &tl_factory_; |
codec_.numberOfSimulcastStreams = 3; |
EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
adapter_->RegisterEncodeCompleteCallback(this); |