| OLD | NEW |
| 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 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 } | 88 } |
| 89 | 89 |
| 90 TEST_F(TestSimulcastEncoderAdapter, TestSaptioTemporalLayers333PatternEncoder) { | 90 TEST_F(TestSimulcastEncoderAdapter, TestSaptioTemporalLayers333PatternEncoder) { |
| 91 TestVp8Simulcast::TestSaptioTemporalLayers333PatternEncoder(); | 91 TestVp8Simulcast::TestSaptioTemporalLayers333PatternEncoder(); |
| 92 } | 92 } |
| 93 | 93 |
| 94 TEST_F(TestSimulcastEncoderAdapter, TestSpatioTemporalLayers321PatternEncoder) { | 94 TEST_F(TestSimulcastEncoderAdapter, TestSpatioTemporalLayers321PatternEncoder) { |
| 95 TestVp8Simulcast::TestSpatioTemporalLayers321PatternEncoder(); | 95 TestVp8Simulcast::TestSpatioTemporalLayers321PatternEncoder(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 // TODO(ronghuawu): Enable this test when SkipEncodingUnusedStreams option is | |
| 99 // implemented for SimulcastEncoderAdapter. | |
| 100 TEST_F(TestSimulcastEncoderAdapter, DISABLED_TestSkipEncodingUnusedStreams) { | |
| 101 TestVp8Simulcast::TestSkipEncodingUnusedStreams(); | |
| 102 } | |
| 103 | |
| 104 TEST_F(TestSimulcastEncoderAdapter, DISABLED_TestRPSIEncoder) { | 98 TEST_F(TestSimulcastEncoderAdapter, DISABLED_TestRPSIEncoder) { |
| 105 TestVp8Simulcast::TestRPSIEncoder(); | 99 TestVp8Simulcast::TestRPSIEncoder(); |
| 106 } | 100 } |
| 107 | 101 |
| 108 class MockVideoEncoder : public VideoEncoder { | 102 class MockVideoEncoder : public VideoEncoder { |
| 109 public: | 103 public: |
| 110 // TODO(nisse): Valid overrides commented out, because the gmock | 104 // TODO(nisse): Valid overrides commented out, because the gmock |
| 111 // methods don't use any override declarations, and we want to avoid | 105 // methods don't use any override declarations, and we want to avoid |
| 112 // warnings from -Winconsistent-missing-override. See | 106 // warnings from -Winconsistent-missing-override. See |
| 113 // http://crbug.com/428099. | 107 // http://crbug.com/428099. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 125 const std::vector<FrameType>* frame_types) /* override */); | 119 const std::vector<FrameType>* frame_types) /* override */); |
| 126 | 120 |
| 127 int32_t RegisterEncodeCompleteCallback( | 121 int32_t RegisterEncodeCompleteCallback( |
| 128 EncodedImageCallback* callback) /* override */ { | 122 EncodedImageCallback* callback) /* override */ { |
| 129 callback_ = callback; | 123 callback_ = callback; |
| 130 return 0; | 124 return 0; |
| 131 } | 125 } |
| 132 | 126 |
| 133 int32_t Release() /* override */ { return 0; } | 127 int32_t Release() /* override */ { return 0; } |
| 134 | 128 |
| 135 int32_t SetRates(uint32_t newBitRate, uint32_t frameRate) /* override */ { | 129 int32_t SetRateAllocation(const BitrateAllocation& bitrate_allocation, |
| 136 last_set_bitrate_ = static_cast<int32_t>(newBitRate); | 130 uint32_t framerate) { |
| 131 last_set_bitrate_ = bitrate_allocation; |
| 137 return 0; | 132 return 0; |
| 138 } | 133 } |
| 139 | 134 |
| 140 MOCK_METHOD2(SetChannelParameters, int32_t(uint32_t packetLoss, int64_t rtt)); | 135 MOCK_METHOD2(SetChannelParameters, int32_t(uint32_t packetLoss, int64_t rtt)); |
| 141 | 136 |
| 142 bool SupportsNativeHandle() const /* override */ { | 137 bool SupportsNativeHandle() const /* override */ { |
| 143 return supports_native_handle_; | 138 return supports_native_handle_; |
| 144 } | 139 } |
| 145 | 140 |
| 146 virtual ~MockVideoEncoder() {} | 141 virtual ~MockVideoEncoder() {} |
| 147 | 142 |
| 148 const VideoCodec& codec() const { return codec_; } | 143 const VideoCodec& codec() const { return codec_; } |
| 149 | 144 |
| 150 void SendEncodedImage(int width, int height) { | 145 void SendEncodedImage(int width, int height) { |
| 151 // Sends a fake image of the given width/height. | 146 // Sends a fake image of the given width/height. |
| 152 EncodedImage image; | 147 EncodedImage image; |
| 153 image._encodedWidth = width; | 148 image._encodedWidth = width; |
| 154 image._encodedHeight = height; | 149 image._encodedHeight = height; |
| 155 CodecSpecificInfo codecSpecificInfo; | 150 CodecSpecificInfo codecSpecificInfo; |
| 156 memset(&codecSpecificInfo, 0, sizeof(codecSpecificInfo)); | 151 memset(&codecSpecificInfo, 0, sizeof(codecSpecificInfo)); |
| 157 callback_->Encoded(image, &codecSpecificInfo, NULL); | 152 callback_->Encoded(image, &codecSpecificInfo, NULL); |
| 158 } | 153 } |
| 159 | 154 |
| 160 void set_supports_native_handle(bool enabled) { | 155 void set_supports_native_handle(bool enabled) { |
| 161 supports_native_handle_ = enabled; | 156 supports_native_handle_ = enabled; |
| 162 } | 157 } |
| 163 int32_t last_set_bitrate() const { return last_set_bitrate_; } | 158 BitrateAllocation last_set_bitrate() const { return last_set_bitrate_; } |
| 164 | 159 |
| 165 MOCK_CONST_METHOD0(ImplementationName, const char*()); | 160 MOCK_CONST_METHOD0(ImplementationName, const char*()); |
| 166 | 161 |
| 167 private: | 162 private: |
| 168 bool supports_native_handle_ = false; | 163 bool supports_native_handle_ = false; |
| 169 int32_t last_set_bitrate_ = -1; | 164 BitrateAllocation last_set_bitrate_; |
| 170 | 165 |
| 171 VideoCodec codec_; | 166 VideoCodec codec_; |
| 172 EncodedImageCallback* callback_; | 167 EncodedImageCallback* callback_; |
| 173 }; | 168 }; |
| 174 | 169 |
| 175 class MockVideoEncoderFactory : public VideoEncoderFactory { | 170 class MockVideoEncoderFactory : public VideoEncoderFactory { |
| 176 public: | 171 public: |
| 177 VideoEncoder* Create() override { | 172 VideoEncoder* Create() override { |
| 178 MockVideoEncoder* encoder = new | 173 MockVideoEncoder* encoder = new |
| 179 ::testing::NiceMock<MockVideoEncoder>(); | 174 ::testing::NiceMock<MockVideoEncoder>(); |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 } | 261 } |
| 267 *out_width = last_encoded_image_width_; | 262 *out_width = last_encoded_image_width_; |
| 268 *out_height = last_encoded_image_height_; | 263 *out_height = last_encoded_image_height_; |
| 269 *out_simulcast_index = last_encoded_image_simulcast_index_; | 264 *out_simulcast_index = last_encoded_image_simulcast_index_; |
| 270 return true; | 265 return true; |
| 271 } | 266 } |
| 272 | 267 |
| 273 void SetupCodec() { | 268 void SetupCodec() { |
| 274 TestVp8Simulcast::DefaultSettings( | 269 TestVp8Simulcast::DefaultSettings( |
| 275 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 270 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 271 rate_allocator_.reset(new SimulcastRateAllocator(codec_, nullptr)); |
| 272 tl_factory_.SetListener(rate_allocator_.get()); |
| 273 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
| 276 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 274 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
| 277 adapter_->RegisterEncodeCompleteCallback(this); | 275 adapter_->RegisterEncodeCompleteCallback(this); |
| 278 } | 276 } |
| 279 | 277 |
| 280 void VerifyCodec(const VideoCodec& ref, int stream_index) { | 278 void VerifyCodec(const VideoCodec& ref, int stream_index) { |
| 281 const VideoCodec& target = | 279 const VideoCodec& target = |
| 282 helper_->factory()->encoders()[stream_index]->codec(); | 280 helper_->factory()->encoders()[stream_index]->codec(); |
| 283 EXPECT_EQ(ref.codecType, target.codecType); | 281 EXPECT_EQ(ref.codecType, target.codecType); |
| 284 EXPECT_EQ(0, strcmp(ref.plName, target.plName)); | 282 EXPECT_EQ(0, strcmp(ref.plName, target.plName)); |
| 285 EXPECT_EQ(ref.plType, target.plType); | 283 EXPECT_EQ(ref.plType, target.plType); |
| 286 EXPECT_EQ(ref.width, target.width); | 284 EXPECT_EQ(ref.width, target.width); |
| 287 EXPECT_EQ(ref.height, target.height); | 285 EXPECT_EQ(ref.height, target.height); |
| 288 EXPECT_EQ(ref.startBitrate, target.startBitrate); | 286 EXPECT_EQ(ref.startBitrate, target.startBitrate); |
| 289 EXPECT_EQ(ref.maxBitrate, target.maxBitrate); | 287 EXPECT_EQ(ref.maxBitrate, target.maxBitrate); |
| 290 EXPECT_EQ(ref.minBitrate, target.minBitrate); | 288 EXPECT_EQ(ref.minBitrate, target.minBitrate); |
| 291 EXPECT_EQ(ref.maxFramerate, target.maxFramerate); | 289 EXPECT_EQ(ref.maxFramerate, target.maxFramerate); |
| 292 EXPECT_EQ(ref.VP8().pictureLossIndicationOn, | 290 EXPECT_EQ(ref.VP8().pictureLossIndicationOn, |
| 293 target.VP8().pictureLossIndicationOn); | 291 target.VP8().pictureLossIndicationOn); |
| 294 EXPECT_EQ(ref.VP8().feedbackModeOn, target.VP8().feedbackModeOn); | 292 EXPECT_EQ(ref.VP8().feedbackModeOn, target.VP8().feedbackModeOn); |
| 295 EXPECT_EQ(ref.VP8().complexity, target.VP8().complexity); | 293 EXPECT_EQ(ref.VP8().complexity, target.VP8().complexity); |
| 296 EXPECT_EQ(ref.VP8().resilience, target.VP8().resilience); | 294 EXPECT_EQ(ref.VP8().resilience, target.VP8().resilience); |
| 297 EXPECT_EQ(ref.VP8().numberOfTemporalLayers, | 295 EXPECT_EQ(ref.VP8().numberOfTemporalLayers, |
| 298 target.VP8().numberOfTemporalLayers); | 296 target.VP8().numberOfTemporalLayers); |
| 299 EXPECT_EQ(ref.VP8().denoisingOn, target.VP8().denoisingOn); | 297 EXPECT_EQ(ref.VP8().denoisingOn, target.VP8().denoisingOn); |
| 300 EXPECT_EQ(ref.VP8().errorConcealmentOn, target.VP8().errorConcealmentOn); | 298 EXPECT_EQ(ref.VP8().errorConcealmentOn, target.VP8().errorConcealmentOn); |
| 301 EXPECT_EQ(ref.VP8().automaticResizeOn, target.VP8().automaticResizeOn); | 299 EXPECT_EQ(ref.VP8().automaticResizeOn, target.VP8().automaticResizeOn); |
| 302 EXPECT_EQ(ref.VP8().frameDroppingOn, target.VP8().frameDroppingOn); | 300 EXPECT_EQ(ref.VP8().frameDroppingOn, target.VP8().frameDroppingOn); |
| 303 EXPECT_EQ(ref.VP8().keyFrameInterval, target.VP8().keyFrameInterval); | 301 EXPECT_EQ(ref.VP8().keyFrameInterval, target.VP8().keyFrameInterval); |
| 304 EXPECT_EQ(ref.VP8().tl_factory, target.VP8().tl_factory); | |
| 305 EXPECT_EQ(ref.qpMax, target.qpMax); | 302 EXPECT_EQ(ref.qpMax, target.qpMax); |
| 306 EXPECT_EQ(0, target.numberOfSimulcastStreams); | 303 EXPECT_EQ(0, target.numberOfSimulcastStreams); |
| 307 EXPECT_EQ(ref.mode, target.mode); | 304 EXPECT_EQ(ref.mode, target.mode); |
| 308 | 305 |
| 309 // No need to compare simulcastStream as numberOfSimulcastStreams should | 306 // No need to compare simulcastStream as numberOfSimulcastStreams should |
| 310 // always be 0. | 307 // always be 0. |
| 311 } | 308 } |
| 312 | 309 |
| 313 void InitRefCodec(int stream_index, VideoCodec* ref_codec) { | 310 void InitRefCodec(int stream_index, VideoCodec* ref_codec) { |
| 314 *ref_codec = codec_; | 311 *ref_codec = codec_; |
| 315 ref_codec->VP8()->numberOfTemporalLayers = | 312 ref_codec->VP8()->numberOfTemporalLayers = |
| 316 kTestTemporalLayerProfile[stream_index]; | 313 kTestTemporalLayerProfile[stream_index]; |
| 314 ref_codec->codecSpecific.VP8.tl_factory = &tl_factory_; |
| 317 ref_codec->width = codec_.simulcastStream[stream_index].width; | 315 ref_codec->width = codec_.simulcastStream[stream_index].width; |
| 318 ref_codec->height = codec_.simulcastStream[stream_index].height; | 316 ref_codec->height = codec_.simulcastStream[stream_index].height; |
| 319 ref_codec->maxBitrate = codec_.simulcastStream[stream_index].maxBitrate; | 317 ref_codec->maxBitrate = codec_.simulcastStream[stream_index].maxBitrate; |
| 320 ref_codec->minBitrate = codec_.simulcastStream[stream_index].minBitrate; | 318 ref_codec->minBitrate = codec_.simulcastStream[stream_index].minBitrate; |
| 321 ref_codec->qpMax = codec_.simulcastStream[stream_index].qpMax; | 319 ref_codec->qpMax = codec_.simulcastStream[stream_index].qpMax; |
| 322 } | 320 } |
| 323 | 321 |
| 324 void VerifyCodecSettings() { | 322 void VerifyCodecSettings() { |
| 325 EXPECT_EQ(3u, helper_->factory()->encoders().size()); | 323 EXPECT_EQ(3u, helper_->factory()->encoders().size()); |
| 326 VideoCodec ref_codec; | 324 VideoCodec ref_codec; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 350 VerifyCodec(ref_codec, 2); | 348 VerifyCodec(ref_codec, 2); |
| 351 } | 349 } |
| 352 | 350 |
| 353 protected: | 351 protected: |
| 354 std::unique_ptr<TestSimulcastEncoderAdapterFakeHelper> helper_; | 352 std::unique_ptr<TestSimulcastEncoderAdapterFakeHelper> helper_; |
| 355 std::unique_ptr<VP8Encoder> adapter_; | 353 std::unique_ptr<VP8Encoder> adapter_; |
| 356 VideoCodec codec_; | 354 VideoCodec codec_; |
| 357 int last_encoded_image_width_; | 355 int last_encoded_image_width_; |
| 358 int last_encoded_image_height_; | 356 int last_encoded_image_height_; |
| 359 int last_encoded_image_simulcast_index_; | 357 int last_encoded_image_simulcast_index_; |
| 358 TemporalLayersFactory tl_factory_; |
| 359 std::unique_ptr<SimulcastRateAllocator> rate_allocator_; |
| 360 }; | 360 }; |
| 361 | 361 |
| 362 TEST_F(TestSimulcastEncoderAdapterFake, InitEncode) { | 362 TEST_F(TestSimulcastEncoderAdapterFake, InitEncode) { |
| 363 SetupCodec(); | 363 SetupCodec(); |
| 364 VerifyCodecSettings(); | 364 VerifyCodecSettings(); |
| 365 } | 365 } |
| 366 | 366 |
| 367 TEST_F(TestSimulcastEncoderAdapterFake, SetChannelParameters) { | 367 TEST_F(TestSimulcastEncoderAdapterFake, SetChannelParameters) { |
| 368 SetupCodec(); | 368 SetupCodec(); |
| 369 const uint32_t packetLoss = 5; | 369 const uint32_t packetLoss = 5; |
| 370 const int64_t rtt = 30; | 370 const int64_t rtt = 30; |
| 371 helper_->ExpectCallSetChannelParameters(packetLoss, rtt); | 371 helper_->ExpectCallSetChannelParameters(packetLoss, rtt); |
| 372 adapter_->SetChannelParameters(packetLoss, rtt); | 372 adapter_->SetChannelParameters(packetLoss, rtt); |
| 373 } | 373 } |
| 374 | 374 |
| 375 TEST_F(TestSimulcastEncoderAdapterFake, EncodedCallbackForDifferentEncoders) { | 375 TEST_F(TestSimulcastEncoderAdapterFake, EncodedCallbackForDifferentEncoders) { |
| 376 SetupCodec(); | 376 SetupCodec(); |
| 377 | 377 |
| 378 // Set bitrates so that we send all layers. | 378 // Set bitrates so that we send all layers. |
| 379 adapter_->SetRates(1200, 30); | 379 adapter_->SetRateAllocation(rate_allocator_->GetAllocation(1200, 30), 30); |
| 380 | 380 |
| 381 // At this point, the simulcast encoder adapter should have 3 streams: HD, | 381 // At this point, the simulcast encoder adapter should have 3 streams: HD, |
| 382 // quarter HD, and quarter quarter HD. We're going to mostly ignore the exact | 382 // quarter HD, and quarter quarter HD. We're going to mostly ignore the exact |
| 383 // resolutions, to test that the adapter forwards on the correct resolution | 383 // resolutions, to test that the adapter forwards on the correct resolution |
| 384 // and simulcast index values, going only off the encoder that generates the | 384 // and simulcast index values, going only off the encoder that generates the |
| 385 // image. | 385 // image. |
| 386 EXPECT_EQ(3u, helper_->factory()->encoders().size()); | 386 EXPECT_EQ(3u, helper_->factory()->encoders().size()); |
| 387 helper_->factory()->encoders()[0]->SendEncodedImage(1152, 704); | 387 helper_->factory()->encoders()[0]->SendEncodedImage(1152, 704); |
| 388 int width; | 388 int width; |
| 389 int height; | 389 int height; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 402 helper_->factory()->encoders()[2]->SendEncodedImage(120, 240); | 402 helper_->factory()->encoders()[2]->SendEncodedImage(120, 240); |
| 403 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); | 403 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); |
| 404 EXPECT_EQ(120, width); | 404 EXPECT_EQ(120, width); |
| 405 EXPECT_EQ(240, height); | 405 EXPECT_EQ(240, height); |
| 406 EXPECT_EQ(2, simulcast_index); | 406 EXPECT_EQ(2, simulcast_index); |
| 407 } | 407 } |
| 408 | 408 |
| 409 TEST_F(TestSimulcastEncoderAdapterFake, SupportsNativeHandleForSingleStreams) { | 409 TEST_F(TestSimulcastEncoderAdapterFake, SupportsNativeHandleForSingleStreams) { |
| 410 TestVp8Simulcast::DefaultSettings( | 410 TestVp8Simulcast::DefaultSettings( |
| 411 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 411 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 412 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
| 412 codec_.numberOfSimulcastStreams = 1; | 413 codec_.numberOfSimulcastStreams = 1; |
| 413 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 414 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
| 414 adapter_->RegisterEncodeCompleteCallback(this); | 415 adapter_->RegisterEncodeCompleteCallback(this); |
| 415 ASSERT_EQ(1u, helper_->factory()->encoders().size()); | 416 ASSERT_EQ(1u, helper_->factory()->encoders().size()); |
| 416 helper_->factory()->encoders()[0]->set_supports_native_handle(true); | 417 helper_->factory()->encoders()[0]->set_supports_native_handle(true); |
| 417 EXPECT_TRUE(adapter_->SupportsNativeHandle()); | 418 EXPECT_TRUE(adapter_->SupportsNativeHandle()); |
| 418 helper_->factory()->encoders()[0]->set_supports_native_handle(false); | 419 helper_->factory()->encoders()[0]->set_supports_native_handle(false); |
| 419 EXPECT_FALSE(adapter_->SupportsNativeHandle()); | 420 EXPECT_FALSE(adapter_->SupportsNativeHandle()); |
| 420 } | 421 } |
| 421 | 422 |
| 422 TEST_F(TestSimulcastEncoderAdapterFake, SetRatesUnderMinBitrate) { | 423 TEST_F(TestSimulcastEncoderAdapterFake, SetRatesUnderMinBitrate) { |
| 423 TestVp8Simulcast::DefaultSettings( | 424 TestVp8Simulcast::DefaultSettings( |
| 424 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 425 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 426 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
| 425 codec_.minBitrate = 50; | 427 codec_.minBitrate = 50; |
| 426 codec_.numberOfSimulcastStreams = 1; | 428 codec_.numberOfSimulcastStreams = 1; |
| 427 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 429 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
| 430 rate_allocator_.reset(new SimulcastRateAllocator(codec_, nullptr)); |
| 428 | 431 |
| 429 // Above min should be respected. | 432 // Above min should be respected. |
| 430 adapter_->SetRates(100, 30); | 433 BitrateAllocation target_bitrate = |
| 431 EXPECT_EQ(100, helper_->factory()->encoders()[0]->last_set_bitrate()); | 434 rate_allocator_->GetAllocation(codec_.minBitrate * 1000, 30); |
| 435 adapter_->SetRateAllocation(target_bitrate, 30); |
| 436 EXPECT_EQ(target_bitrate, |
| 437 helper_->factory()->encoders()[0]->last_set_bitrate()); |
| 432 | 438 |
| 433 // Below min but non-zero should be replaced with the min bitrate. | 439 // Below min but non-zero should be replaced with the min bitrate. |
| 434 adapter_->SetRates(15, 30); | 440 BitrateAllocation too_low_bitrate = |
| 435 EXPECT_EQ(50, helper_->factory()->encoders()[0]->last_set_bitrate()); | 441 rate_allocator_->GetAllocation((codec_.minBitrate - 1) * 1000, 30); |
| 442 adapter_->SetRateAllocation(too_low_bitrate, 30); |
| 443 EXPECT_EQ(target_bitrate, |
| 444 helper_->factory()->encoders()[0]->last_set_bitrate()); |
| 436 | 445 |
| 437 // Zero should be passed on as is, since it means "pause". | 446 // Zero should be passed on as is, since it means "pause". |
| 438 adapter_->SetRates(0, 30); | 447 adapter_->SetRateAllocation(BitrateAllocation(), 30); |
| 439 EXPECT_EQ(0, helper_->factory()->encoders()[0]->last_set_bitrate()); | 448 EXPECT_EQ(BitrateAllocation(), |
| 449 helper_->factory()->encoders()[0]->last_set_bitrate()); |
| 440 } | 450 } |
| 441 | 451 |
| 442 TEST_F(TestSimulcastEncoderAdapterFake, SupportsImplementationName) { | 452 TEST_F(TestSimulcastEncoderAdapterFake, SupportsImplementationName) { |
| 443 EXPECT_STREQ("SimulcastEncoderAdapter", adapter_->ImplementationName()); | 453 EXPECT_STREQ("SimulcastEncoderAdapter", adapter_->ImplementationName()); |
| 444 TestVp8Simulcast::DefaultSettings( | 454 TestVp8Simulcast::DefaultSettings( |
| 445 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 455 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 456 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
| 446 std::vector<const char*> encoder_names; | 457 std::vector<const char*> encoder_names; |
| 447 encoder_names.push_back("codec1"); | 458 encoder_names.push_back("codec1"); |
| 448 encoder_names.push_back("codec2"); | 459 encoder_names.push_back("codec2"); |
| 449 encoder_names.push_back("codec3"); | 460 encoder_names.push_back("codec3"); |
| 450 helper_->factory()->SetEncoderNames(encoder_names); | 461 helper_->factory()->SetEncoderNames(encoder_names); |
| 451 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 462 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
| 452 EXPECT_STREQ("SimulcastEncoderAdapter (codec1, codec2, codec3)", | 463 EXPECT_STREQ("SimulcastEncoderAdapter (codec1, codec2, codec3)", |
| 453 adapter_->ImplementationName()); | 464 adapter_->ImplementationName()); |
| 454 | 465 |
| 455 // Single streams should not expose "SimulcastEncoderAdapter" in name. | 466 // Single streams should not expose "SimulcastEncoderAdapter" in name. |
| 456 adapter_->Release(); | 467 adapter_->Release(); |
| 457 codec_.numberOfSimulcastStreams = 1; | 468 codec_.numberOfSimulcastStreams = 1; |
| 458 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 469 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
| 459 adapter_->RegisterEncodeCompleteCallback(this); | 470 adapter_->RegisterEncodeCompleteCallback(this); |
| 460 ASSERT_EQ(1u, helper_->factory()->encoders().size()); | 471 ASSERT_EQ(1u, helper_->factory()->encoders().size()); |
| 461 EXPECT_STREQ("codec1", adapter_->ImplementationName()); | 472 EXPECT_STREQ("codec1", adapter_->ImplementationName()); |
| 462 } | 473 } |
| 463 | 474 |
| 464 TEST_F(TestSimulcastEncoderAdapterFake, | 475 TEST_F(TestSimulcastEncoderAdapterFake, |
| 465 SupportsNativeHandleForMultipleStreams) { | 476 SupportsNativeHandleForMultipleStreams) { |
| 466 TestVp8Simulcast::DefaultSettings( | 477 TestVp8Simulcast::DefaultSettings( |
| 467 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 478 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 479 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
| 468 codec_.numberOfSimulcastStreams = 3; | 480 codec_.numberOfSimulcastStreams = 3; |
| 469 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 481 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
| 470 adapter_->RegisterEncodeCompleteCallback(this); | 482 adapter_->RegisterEncodeCompleteCallback(this); |
| 471 ASSERT_EQ(3u, helper_->factory()->encoders().size()); | 483 ASSERT_EQ(3u, helper_->factory()->encoders().size()); |
| 472 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) | 484 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) |
| 473 encoder->set_supports_native_handle(true); | 485 encoder->set_supports_native_handle(true); |
| 474 // If one encoder doesn't support it, then overall support is disabled. | 486 // If one encoder doesn't support it, then overall support is disabled. |
| 475 helper_->factory()->encoders()[0]->set_supports_native_handle(false); | 487 helper_->factory()->encoders()[0]->set_supports_native_handle(false); |
| 476 EXPECT_FALSE(adapter_->SupportsNativeHandle()); | 488 EXPECT_FALSE(adapter_->SupportsNativeHandle()); |
| 477 // Once all do, then the adapter claims support. | 489 // Once all do, then the adapter claims support. |
| 478 helper_->factory()->encoders()[0]->set_supports_native_handle(true); | 490 helper_->factory()->encoders()[0]->set_supports_native_handle(true); |
| 479 EXPECT_TRUE(adapter_->SupportsNativeHandle()); | 491 EXPECT_TRUE(adapter_->SupportsNativeHandle()); |
| 480 } | 492 } |
| 481 | 493 |
| 482 class FakeNativeHandleBuffer : public NativeHandleBuffer { | 494 class FakeNativeHandleBuffer : public NativeHandleBuffer { |
| 483 public: | 495 public: |
| 484 FakeNativeHandleBuffer(void* native_handle, int width, int height) | 496 FakeNativeHandleBuffer(void* native_handle, int width, int height) |
| 485 : NativeHandleBuffer(native_handle, width, height) {} | 497 : NativeHandleBuffer(native_handle, width, height) {} |
| 486 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override { | 498 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override { |
| 487 RTC_NOTREACHED(); | 499 RTC_NOTREACHED(); |
| 488 return nullptr; | 500 return nullptr; |
| 489 } | 501 } |
| 490 }; | 502 }; |
| 491 | 503 |
| 492 TEST_F(TestSimulcastEncoderAdapterFake, | 504 TEST_F(TestSimulcastEncoderAdapterFake, |
| 493 NativeHandleForwardingForMultipleStreams) { | 505 NativeHandleForwardingForMultipleStreams) { |
| 494 TestVp8Simulcast::DefaultSettings( | 506 TestVp8Simulcast::DefaultSettings( |
| 495 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 507 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 508 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
| 496 codec_.numberOfSimulcastStreams = 3; | 509 codec_.numberOfSimulcastStreams = 3; |
| 497 // High start bitrate, so all streams are enabled. | 510 // High start bitrate, so all streams are enabled. |
| 498 codec_.startBitrate = 3000; | 511 codec_.startBitrate = 3000; |
| 499 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 512 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
| 500 adapter_->RegisterEncodeCompleteCallback(this); | 513 adapter_->RegisterEncodeCompleteCallback(this); |
| 501 ASSERT_EQ(3u, helper_->factory()->encoders().size()); | 514 ASSERT_EQ(3u, helper_->factory()->encoders().size()); |
| 502 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) | 515 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) |
| 503 encoder->set_supports_native_handle(true); | 516 encoder->set_supports_native_handle(true); |
| 504 EXPECT_TRUE(adapter_->SupportsNativeHandle()); | 517 EXPECT_TRUE(adapter_->SupportsNativeHandle()); |
| 505 | 518 |
| 506 rtc::scoped_refptr<VideoFrameBuffer> buffer( | 519 rtc::scoped_refptr<VideoFrameBuffer> buffer( |
| 507 new rtc::RefCountedObject<FakeNativeHandleBuffer>(this, 1280, 720)); | 520 new rtc::RefCountedObject<FakeNativeHandleBuffer>(this, 1280, 720)); |
| 508 VideoFrame input_frame(buffer, 100, 1000, kVideoRotation_180); | 521 VideoFrame input_frame(buffer, 100, 1000, kVideoRotation_180); |
| 509 // Expect calls with the given video frame verbatim, since it's a texture | 522 // Expect calls with the given video frame verbatim, since it's a texture |
| 510 // frame and can't otherwise be modified/resized. | 523 // frame and can't otherwise be modified/resized. |
| 511 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) | 524 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) |
| 512 EXPECT_CALL(*encoder, Encode(::testing::Ref(input_frame), _, _)).Times(1); | 525 EXPECT_CALL(*encoder, Encode(::testing::Ref(input_frame), _, _)).Times(1); |
| 513 std::vector<FrameType> frame_types(3, kVideoFrameKey); | 526 std::vector<FrameType> frame_types(3, kVideoFrameKey); |
| 514 EXPECT_EQ(0, adapter_->Encode(input_frame, NULL, &frame_types)); | 527 EXPECT_EQ(0, adapter_->Encode(input_frame, NULL, &frame_types)); |
| 515 } | 528 } |
| 516 | 529 |
| 517 TEST_F(TestSimulcastEncoderAdapterFake, TestFailureReturnCodesFromEncodeCalls) { | 530 TEST_F(TestSimulcastEncoderAdapterFake, TestFailureReturnCodesFromEncodeCalls) { |
| 518 TestVp8Simulcast::DefaultSettings( | 531 TestVp8Simulcast::DefaultSettings( |
| 519 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 532 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 533 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
| 520 codec_.numberOfSimulcastStreams = 3; | 534 codec_.numberOfSimulcastStreams = 3; |
| 521 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 535 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
| 522 adapter_->RegisterEncodeCompleteCallback(this); | 536 adapter_->RegisterEncodeCompleteCallback(this); |
| 523 ASSERT_EQ(3u, helper_->factory()->encoders().size()); | 537 ASSERT_EQ(3u, helper_->factory()->encoders().size()); |
| 524 // Tell the 2nd encoder to request software fallback. | 538 // Tell the 2nd encoder to request software fallback. |
| 525 EXPECT_CALL(*helper_->factory()->encoders()[1], Encode(_, _, _)) | 539 EXPECT_CALL(*helper_->factory()->encoders()[1], Encode(_, _, _)) |
| 526 .WillOnce(Return(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE)); | 540 .WillOnce(Return(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE)); |
| 527 | 541 |
| 528 // Send a fake frame and assert the return is software fallback. | 542 // Send a fake frame and assert the return is software fallback. |
| 529 int half_width = (kDefaultWidth + 1) / 2; | 543 int half_width = (kDefaultWidth + 1) / 2; |
| 530 rtc::scoped_refptr<I420Buffer> input_buffer = I420Buffer::Create( | 544 rtc::scoped_refptr<I420Buffer> input_buffer = I420Buffer::Create( |
| 531 kDefaultWidth, kDefaultHeight, kDefaultWidth, half_width, half_width); | 545 kDefaultWidth, kDefaultHeight, kDefaultWidth, half_width, half_width); |
| 532 input_buffer->InitializeData(); | 546 input_buffer->InitializeData(); |
| 533 VideoFrame input_frame(input_buffer, 0, 0, webrtc::kVideoRotation_0); | 547 VideoFrame input_frame(input_buffer, 0, 0, webrtc::kVideoRotation_0); |
| 534 std::vector<FrameType> frame_types(3, kVideoFrameKey); | 548 std::vector<FrameType> frame_types(3, kVideoFrameKey); |
| 535 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE, | 549 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE, |
| 536 adapter_->Encode(input_frame, nullptr, &frame_types)); | 550 adapter_->Encode(input_frame, nullptr, &frame_types)); |
| 537 } | 551 } |
| 538 | 552 |
| 539 } // namespace testing | 553 } // namespace testing |
| 540 } // namespace webrtc | 554 } // namespace webrtc |
| OLD | NEW |