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); |
(...skipping 16 matching lines...) Expand all Loading... |
302 EXPECT_EQ(ref.codecSpecific.VP8.denoisingOn, | 300 EXPECT_EQ(ref.codecSpecific.VP8.denoisingOn, |
303 target.codecSpecific.VP8.denoisingOn); | 301 target.codecSpecific.VP8.denoisingOn); |
304 EXPECT_EQ(ref.codecSpecific.VP8.errorConcealmentOn, | 302 EXPECT_EQ(ref.codecSpecific.VP8.errorConcealmentOn, |
305 target.codecSpecific.VP8.errorConcealmentOn); | 303 target.codecSpecific.VP8.errorConcealmentOn); |
306 EXPECT_EQ(ref.codecSpecific.VP8.automaticResizeOn, | 304 EXPECT_EQ(ref.codecSpecific.VP8.automaticResizeOn, |
307 target.codecSpecific.VP8.automaticResizeOn); | 305 target.codecSpecific.VP8.automaticResizeOn); |
308 EXPECT_EQ(ref.codecSpecific.VP8.frameDroppingOn, | 306 EXPECT_EQ(ref.codecSpecific.VP8.frameDroppingOn, |
309 target.codecSpecific.VP8.frameDroppingOn); | 307 target.codecSpecific.VP8.frameDroppingOn); |
310 EXPECT_EQ(ref.codecSpecific.VP8.keyFrameInterval, | 308 EXPECT_EQ(ref.codecSpecific.VP8.keyFrameInterval, |
311 target.codecSpecific.VP8.keyFrameInterval); | 309 target.codecSpecific.VP8.keyFrameInterval); |
312 EXPECT_EQ(ref.codecSpecific.VP8.tl_factory, | |
313 target.codecSpecific.VP8.tl_factory); | |
314 EXPECT_EQ(ref.qpMax, target.qpMax); | 310 EXPECT_EQ(ref.qpMax, target.qpMax); |
315 EXPECT_EQ(0, target.numberOfSimulcastStreams); | 311 EXPECT_EQ(0, target.numberOfSimulcastStreams); |
316 EXPECT_EQ(ref.mode, target.mode); | 312 EXPECT_EQ(ref.mode, target.mode); |
317 | 313 |
318 // No need to compare simulcastStream as numberOfSimulcastStreams should | 314 // No need to compare simulcastStream as numberOfSimulcastStreams should |
319 // always be 0. | 315 // always be 0. |
320 } | 316 } |
321 | 317 |
322 void InitRefCodec(int stream_index, VideoCodec* ref_codec) { | 318 void InitRefCodec(int stream_index, VideoCodec* ref_codec) { |
323 *ref_codec = codec_; | 319 *ref_codec = codec_; |
324 ref_codec->codecSpecific.VP8.numberOfTemporalLayers = | 320 ref_codec->codecSpecific.VP8.numberOfTemporalLayers = |
325 kTestTemporalLayerProfile[stream_index]; | 321 kTestTemporalLayerProfile[stream_index]; |
| 322 ref_codec->codecSpecific.VP8.tl_factory = &tl_factory_; |
326 ref_codec->width = codec_.simulcastStream[stream_index].width; | 323 ref_codec->width = codec_.simulcastStream[stream_index].width; |
327 ref_codec->height = codec_.simulcastStream[stream_index].height; | 324 ref_codec->height = codec_.simulcastStream[stream_index].height; |
328 ref_codec->maxBitrate = codec_.simulcastStream[stream_index].maxBitrate; | 325 ref_codec->maxBitrate = codec_.simulcastStream[stream_index].maxBitrate; |
329 ref_codec->minBitrate = codec_.simulcastStream[stream_index].minBitrate; | 326 ref_codec->minBitrate = codec_.simulcastStream[stream_index].minBitrate; |
330 ref_codec->qpMax = codec_.simulcastStream[stream_index].qpMax; | 327 ref_codec->qpMax = codec_.simulcastStream[stream_index].qpMax; |
331 } | 328 } |
332 | 329 |
333 void VerifyCodecSettings() { | 330 void VerifyCodecSettings() { |
334 EXPECT_EQ(3u, helper_->factory()->encoders().size()); | 331 EXPECT_EQ(3u, helper_->factory()->encoders().size()); |
335 VideoCodec ref_codec; | 332 VideoCodec ref_codec; |
(...skipping 23 matching lines...) Expand all Loading... |
359 VerifyCodec(ref_codec, 2); | 356 VerifyCodec(ref_codec, 2); |
360 } | 357 } |
361 | 358 |
362 protected: | 359 protected: |
363 std::unique_ptr<TestSimulcastEncoderAdapterFakeHelper> helper_; | 360 std::unique_ptr<TestSimulcastEncoderAdapterFakeHelper> helper_; |
364 std::unique_ptr<VP8Encoder> adapter_; | 361 std::unique_ptr<VP8Encoder> adapter_; |
365 VideoCodec codec_; | 362 VideoCodec codec_; |
366 int last_encoded_image_width_; | 363 int last_encoded_image_width_; |
367 int last_encoded_image_height_; | 364 int last_encoded_image_height_; |
368 int last_encoded_image_simulcast_index_; | 365 int last_encoded_image_simulcast_index_; |
| 366 TemporalLayersFactory tl_factory_; |
| 367 std::unique_ptr<SimulcastRateAllocator> rate_allocator_; |
369 }; | 368 }; |
370 | 369 |
371 TEST_F(TestSimulcastEncoderAdapterFake, InitEncode) { | 370 TEST_F(TestSimulcastEncoderAdapterFake, InitEncode) { |
372 SetupCodec(); | 371 SetupCodec(); |
373 VerifyCodecSettings(); | 372 VerifyCodecSettings(); |
374 } | 373 } |
375 | 374 |
376 TEST_F(TestSimulcastEncoderAdapterFake, SetChannelParameters) { | 375 TEST_F(TestSimulcastEncoderAdapterFake, SetChannelParameters) { |
377 SetupCodec(); | 376 SetupCodec(); |
378 const uint32_t packetLoss = 5; | 377 const uint32_t packetLoss = 5; |
379 const int64_t rtt = 30; | 378 const int64_t rtt = 30; |
380 helper_->ExpectCallSetChannelParameters(packetLoss, rtt); | 379 helper_->ExpectCallSetChannelParameters(packetLoss, rtt); |
381 adapter_->SetChannelParameters(packetLoss, rtt); | 380 adapter_->SetChannelParameters(packetLoss, rtt); |
382 } | 381 } |
383 | 382 |
384 TEST_F(TestSimulcastEncoderAdapterFake, EncodedCallbackForDifferentEncoders) { | 383 TEST_F(TestSimulcastEncoderAdapterFake, EncodedCallbackForDifferentEncoders) { |
385 SetupCodec(); | 384 SetupCodec(); |
386 | 385 |
387 // Set bitrates so that we send all layers. | 386 // Set bitrates so that we send all layers. |
388 adapter_->SetRates(1200, 30); | 387 adapter_->SetRateAllocation(rate_allocator_->GetAllocation(1200, 30), 30); |
389 | 388 |
390 // At this point, the simulcast encoder adapter should have 3 streams: HD, | 389 // At this point, the simulcast encoder adapter should have 3 streams: HD, |
391 // quarter HD, and quarter quarter HD. We're going to mostly ignore the exact | 390 // quarter HD, and quarter quarter HD. We're going to mostly ignore the exact |
392 // resolutions, to test that the adapter forwards on the correct resolution | 391 // resolutions, to test that the adapter forwards on the correct resolution |
393 // and simulcast index values, going only off the encoder that generates the | 392 // and simulcast index values, going only off the encoder that generates the |
394 // image. | 393 // image. |
395 EXPECT_EQ(3u, helper_->factory()->encoders().size()); | 394 EXPECT_EQ(3u, helper_->factory()->encoders().size()); |
396 helper_->factory()->encoders()[0]->SendEncodedImage(1152, 704); | 395 helper_->factory()->encoders()[0]->SendEncodedImage(1152, 704); |
397 int width; | 396 int width; |
398 int height; | 397 int height; |
(...skipping 12 matching lines...) Expand all Loading... |
411 helper_->factory()->encoders()[2]->SendEncodedImage(120, 240); | 410 helper_->factory()->encoders()[2]->SendEncodedImage(120, 240); |
412 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); | 411 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); |
413 EXPECT_EQ(120, width); | 412 EXPECT_EQ(120, width); |
414 EXPECT_EQ(240, height); | 413 EXPECT_EQ(240, height); |
415 EXPECT_EQ(2, simulcast_index); | 414 EXPECT_EQ(2, simulcast_index); |
416 } | 415 } |
417 | 416 |
418 TEST_F(TestSimulcastEncoderAdapterFake, SupportsNativeHandleForSingleStreams) { | 417 TEST_F(TestSimulcastEncoderAdapterFake, SupportsNativeHandleForSingleStreams) { |
419 TestVp8Simulcast::DefaultSettings( | 418 TestVp8Simulcast::DefaultSettings( |
420 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 419 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 420 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
421 codec_.numberOfSimulcastStreams = 1; | 421 codec_.numberOfSimulcastStreams = 1; |
422 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 422 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
423 adapter_->RegisterEncodeCompleteCallback(this); | 423 adapter_->RegisterEncodeCompleteCallback(this); |
424 ASSERT_EQ(1u, helper_->factory()->encoders().size()); | 424 ASSERT_EQ(1u, helper_->factory()->encoders().size()); |
425 helper_->factory()->encoders()[0]->set_supports_native_handle(true); | 425 helper_->factory()->encoders()[0]->set_supports_native_handle(true); |
426 EXPECT_TRUE(adapter_->SupportsNativeHandle()); | 426 EXPECT_TRUE(adapter_->SupportsNativeHandle()); |
427 helper_->factory()->encoders()[0]->set_supports_native_handle(false); | 427 helper_->factory()->encoders()[0]->set_supports_native_handle(false); |
428 EXPECT_FALSE(adapter_->SupportsNativeHandle()); | 428 EXPECT_FALSE(adapter_->SupportsNativeHandle()); |
429 } | 429 } |
430 | 430 |
431 TEST_F(TestSimulcastEncoderAdapterFake, SetRatesUnderMinBitrate) { | 431 TEST_F(TestSimulcastEncoderAdapterFake, SetRatesUnderMinBitrate) { |
432 TestVp8Simulcast::DefaultSettings( | 432 TestVp8Simulcast::DefaultSettings( |
433 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 433 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 434 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
434 codec_.minBitrate = 50; | 435 codec_.minBitrate = 50; |
435 codec_.numberOfSimulcastStreams = 1; | 436 codec_.numberOfSimulcastStreams = 1; |
436 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 437 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
| 438 rate_allocator_.reset(new SimulcastRateAllocator(codec_, nullptr)); |
437 | 439 |
438 // Above min should be respected. | 440 // Above min should be respected. |
439 adapter_->SetRates(100, 30); | 441 BitrateAllocation target_bitrate = |
440 EXPECT_EQ(100, helper_->factory()->encoders()[0]->last_set_bitrate()); | 442 rate_allocator_->GetAllocation(codec_.minBitrate * 1000, 30); |
| 443 adapter_->SetRateAllocation(target_bitrate, 30); |
| 444 EXPECT_EQ(target_bitrate, |
| 445 helper_->factory()->encoders()[0]->last_set_bitrate()); |
441 | 446 |
442 // Below min but non-zero should be replaced with the min bitrate. | 447 // Below min but non-zero should be replaced with the min bitrate. |
443 adapter_->SetRates(15, 30); | 448 BitrateAllocation too_low_bitrate = |
444 EXPECT_EQ(50, helper_->factory()->encoders()[0]->last_set_bitrate()); | 449 rate_allocator_->GetAllocation((codec_.minBitrate - 1) * 1000, 30); |
| 450 adapter_->SetRateAllocation(too_low_bitrate, 30); |
| 451 EXPECT_EQ(target_bitrate, |
| 452 helper_->factory()->encoders()[0]->last_set_bitrate()); |
445 | 453 |
446 // Zero should be passed on as is, since it means "pause". | 454 // Zero should be passed on as is, since it means "pause". |
447 adapter_->SetRates(0, 30); | 455 adapter_->SetRateAllocation(BitrateAllocation(), 30); |
448 EXPECT_EQ(0, helper_->factory()->encoders()[0]->last_set_bitrate()); | 456 EXPECT_EQ(BitrateAllocation(), |
| 457 helper_->factory()->encoders()[0]->last_set_bitrate()); |
449 } | 458 } |
450 | 459 |
451 TEST_F(TestSimulcastEncoderAdapterFake, SupportsImplementationName) { | 460 TEST_F(TestSimulcastEncoderAdapterFake, SupportsImplementationName) { |
452 EXPECT_STREQ("SimulcastEncoderAdapter", adapter_->ImplementationName()); | 461 EXPECT_STREQ("SimulcastEncoderAdapter", adapter_->ImplementationName()); |
453 TestVp8Simulcast::DefaultSettings( | 462 TestVp8Simulcast::DefaultSettings( |
454 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 463 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 464 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
455 std::vector<const char*> encoder_names; | 465 std::vector<const char*> encoder_names; |
456 encoder_names.push_back("codec1"); | 466 encoder_names.push_back("codec1"); |
457 encoder_names.push_back("codec2"); | 467 encoder_names.push_back("codec2"); |
458 encoder_names.push_back("codec3"); | 468 encoder_names.push_back("codec3"); |
459 helper_->factory()->SetEncoderNames(encoder_names); | 469 helper_->factory()->SetEncoderNames(encoder_names); |
460 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 470 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
461 EXPECT_STREQ("SimulcastEncoderAdapter (codec1, codec2, codec3)", | 471 EXPECT_STREQ("SimulcastEncoderAdapter (codec1, codec2, codec3)", |
462 adapter_->ImplementationName()); | 472 adapter_->ImplementationName()); |
463 | 473 |
464 // Single streams should not expose "SimulcastEncoderAdapter" in name. | 474 // Single streams should not expose "SimulcastEncoderAdapter" in name. |
465 adapter_->Release(); | 475 adapter_->Release(); |
466 codec_.numberOfSimulcastStreams = 1; | 476 codec_.numberOfSimulcastStreams = 1; |
467 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 477 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
468 adapter_->RegisterEncodeCompleteCallback(this); | 478 adapter_->RegisterEncodeCompleteCallback(this); |
469 ASSERT_EQ(1u, helper_->factory()->encoders().size()); | 479 ASSERT_EQ(1u, helper_->factory()->encoders().size()); |
470 EXPECT_STREQ("codec1", adapter_->ImplementationName()); | 480 EXPECT_STREQ("codec1", adapter_->ImplementationName()); |
471 } | 481 } |
472 | 482 |
473 TEST_F(TestSimulcastEncoderAdapterFake, | 483 TEST_F(TestSimulcastEncoderAdapterFake, |
474 SupportsNativeHandleForMultipleStreams) { | 484 SupportsNativeHandleForMultipleStreams) { |
475 TestVp8Simulcast::DefaultSettings( | 485 TestVp8Simulcast::DefaultSettings( |
476 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 486 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 487 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
477 codec_.numberOfSimulcastStreams = 3; | 488 codec_.numberOfSimulcastStreams = 3; |
478 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 489 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
479 adapter_->RegisterEncodeCompleteCallback(this); | 490 adapter_->RegisterEncodeCompleteCallback(this); |
480 ASSERT_EQ(3u, helper_->factory()->encoders().size()); | 491 ASSERT_EQ(3u, helper_->factory()->encoders().size()); |
481 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) | 492 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) |
482 encoder->set_supports_native_handle(true); | 493 encoder->set_supports_native_handle(true); |
483 // If one encoder doesn't support it, then overall support is disabled. | 494 // If one encoder doesn't support it, then overall support is disabled. |
484 helper_->factory()->encoders()[0]->set_supports_native_handle(false); | 495 helper_->factory()->encoders()[0]->set_supports_native_handle(false); |
485 EXPECT_FALSE(adapter_->SupportsNativeHandle()); | 496 EXPECT_FALSE(adapter_->SupportsNativeHandle()); |
486 // Once all do, then the adapter claims support. | 497 // Once all do, then the adapter claims support. |
487 helper_->factory()->encoders()[0]->set_supports_native_handle(true); | 498 helper_->factory()->encoders()[0]->set_supports_native_handle(true); |
488 EXPECT_TRUE(adapter_->SupportsNativeHandle()); | 499 EXPECT_TRUE(adapter_->SupportsNativeHandle()); |
489 } | 500 } |
490 | 501 |
491 class FakeNativeHandleBuffer : public NativeHandleBuffer { | 502 class FakeNativeHandleBuffer : public NativeHandleBuffer { |
492 public: | 503 public: |
493 FakeNativeHandleBuffer(void* native_handle, int width, int height) | 504 FakeNativeHandleBuffer(void* native_handle, int width, int height) |
494 : NativeHandleBuffer(native_handle, width, height) {} | 505 : NativeHandleBuffer(native_handle, width, height) {} |
495 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override { | 506 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override { |
496 RTC_NOTREACHED(); | 507 RTC_NOTREACHED(); |
497 return nullptr; | 508 return nullptr; |
498 } | 509 } |
499 }; | 510 }; |
500 | 511 |
501 TEST_F(TestSimulcastEncoderAdapterFake, | 512 TEST_F(TestSimulcastEncoderAdapterFake, |
502 NativeHandleForwardingForMultipleStreams) { | 513 NativeHandleForwardingForMultipleStreams) { |
503 TestVp8Simulcast::DefaultSettings( | 514 TestVp8Simulcast::DefaultSettings( |
504 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 515 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 516 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
505 codec_.numberOfSimulcastStreams = 3; | 517 codec_.numberOfSimulcastStreams = 3; |
506 // High start bitrate, so all streams are enabled. | 518 // High start bitrate, so all streams are enabled. |
507 codec_.startBitrate = 3000; | 519 codec_.startBitrate = 3000; |
508 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 520 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
509 adapter_->RegisterEncodeCompleteCallback(this); | 521 adapter_->RegisterEncodeCompleteCallback(this); |
510 ASSERT_EQ(3u, helper_->factory()->encoders().size()); | 522 ASSERT_EQ(3u, helper_->factory()->encoders().size()); |
511 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) | 523 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) |
512 encoder->set_supports_native_handle(true); | 524 encoder->set_supports_native_handle(true); |
513 EXPECT_TRUE(adapter_->SupportsNativeHandle()); | 525 EXPECT_TRUE(adapter_->SupportsNativeHandle()); |
514 | 526 |
515 rtc::scoped_refptr<VideoFrameBuffer> buffer( | 527 rtc::scoped_refptr<VideoFrameBuffer> buffer( |
516 new rtc::RefCountedObject<FakeNativeHandleBuffer>(this, 1280, 720)); | 528 new rtc::RefCountedObject<FakeNativeHandleBuffer>(this, 1280, 720)); |
517 VideoFrame input_frame(buffer, 100, 1000, kVideoRotation_180); | 529 VideoFrame input_frame(buffer, 100, 1000, kVideoRotation_180); |
518 // Expect calls with the given video frame verbatim, since it's a texture | 530 // Expect calls with the given video frame verbatim, since it's a texture |
519 // frame and can't otherwise be modified/resized. | 531 // frame and can't otherwise be modified/resized. |
520 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) | 532 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) |
521 EXPECT_CALL(*encoder, Encode(::testing::Ref(input_frame), _, _)).Times(1); | 533 EXPECT_CALL(*encoder, Encode(::testing::Ref(input_frame), _, _)).Times(1); |
522 std::vector<FrameType> frame_types(3, kVideoFrameKey); | 534 std::vector<FrameType> frame_types(3, kVideoFrameKey); |
523 EXPECT_EQ(0, adapter_->Encode(input_frame, NULL, &frame_types)); | 535 EXPECT_EQ(0, adapter_->Encode(input_frame, NULL, &frame_types)); |
524 } | 536 } |
525 | 537 |
526 TEST_F(TestSimulcastEncoderAdapterFake, TestFailureReturnCodesFromEncodeCalls) { | 538 TEST_F(TestSimulcastEncoderAdapterFake, TestFailureReturnCodesFromEncodeCalls) { |
527 TestVp8Simulcast::DefaultSettings( | 539 TestVp8Simulcast::DefaultSettings( |
528 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 540 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 541 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
529 codec_.numberOfSimulcastStreams = 3; | 542 codec_.numberOfSimulcastStreams = 3; |
530 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 543 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
531 adapter_->RegisterEncodeCompleteCallback(this); | 544 adapter_->RegisterEncodeCompleteCallback(this); |
532 ASSERT_EQ(3u, helper_->factory()->encoders().size()); | 545 ASSERT_EQ(3u, helper_->factory()->encoders().size()); |
533 // Tell the 2nd encoder to request software fallback. | 546 // Tell the 2nd encoder to request software fallback. |
534 EXPECT_CALL(*helper_->factory()->encoders()[1], Encode(_, _, _)) | 547 EXPECT_CALL(*helper_->factory()->encoders()[1], Encode(_, _, _)) |
535 .WillOnce(Return(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE)); | 548 .WillOnce(Return(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE)); |
536 | 549 |
537 // Send a fake frame and assert the return is software fallback. | 550 // Send a fake frame and assert the return is software fallback. |
538 int half_width = (kDefaultWidth + 1) / 2; | 551 int half_width = (kDefaultWidth + 1) / 2; |
539 rtc::scoped_refptr<I420Buffer> input_buffer = I420Buffer::Create( | 552 rtc::scoped_refptr<I420Buffer> input_buffer = I420Buffer::Create( |
540 kDefaultWidth, kDefaultHeight, kDefaultWidth, half_width, half_width); | 553 kDefaultWidth, kDefaultHeight, kDefaultWidth, half_width, half_width); |
541 input_buffer->InitializeData(); | 554 input_buffer->InitializeData(); |
542 VideoFrame input_frame(input_buffer, 0, 0, webrtc::kVideoRotation_0); | 555 VideoFrame input_frame(input_buffer, 0, 0, webrtc::kVideoRotation_0); |
543 std::vector<FrameType> frame_types(3, kVideoFrameKey); | 556 std::vector<FrameType> frame_types(3, kVideoFrameKey); |
544 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE, | 557 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE, |
545 adapter_->Encode(input_frame, nullptr, &frame_types)); | 558 adapter_->Encode(input_frame, nullptr, &frame_types)); |
546 } | 559 } |
547 | 560 |
548 } // namespace testing | 561 } // namespace testing |
549 } // namespace webrtc | 562 } // namespace webrtc |
OLD | NEW |