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