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 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
266 } | 266 } |
267 *out_width = last_encoded_image_width_; | 267 *out_width = last_encoded_image_width_; |
268 *out_height = last_encoded_image_height_; | 268 *out_height = last_encoded_image_height_; |
269 *out_simulcast_index = last_encoded_image_simulcast_index_; | 269 *out_simulcast_index = last_encoded_image_simulcast_index_; |
270 return true; | 270 return true; |
271 } | 271 } |
272 | 272 |
273 void SetupCodec() { | 273 void SetupCodec() { |
274 TestVp8Simulcast::DefaultSettings( | 274 TestVp8Simulcast::DefaultSettings( |
275 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 275 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 276 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
276 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 277 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
277 adapter_->RegisterEncodeCompleteCallback(this); | 278 adapter_->RegisterEncodeCompleteCallback(this); |
278 } | 279 } |
279 | 280 |
280 void VerifyCodec(const VideoCodec& ref, int stream_index) { | 281 void VerifyCodec(const VideoCodec& ref, int stream_index) { |
281 const VideoCodec& target = | 282 const VideoCodec& target = |
282 helper_->factory()->encoders()[stream_index]->codec(); | 283 helper_->factory()->encoders()[stream_index]->codec(); |
283 EXPECT_EQ(ref.codecType, target.codecType); | 284 EXPECT_EQ(ref.codecType, target.codecType); |
284 EXPECT_EQ(0, strcmp(ref.plName, target.plName)); | 285 EXPECT_EQ(0, strcmp(ref.plName, target.plName)); |
285 EXPECT_EQ(ref.plType, target.plType); | 286 EXPECT_EQ(ref.plType, target.plType); |
(...skipping 30 matching lines...) Expand all Loading... |
316 EXPECT_EQ(ref.mode, target.mode); | 317 EXPECT_EQ(ref.mode, target.mode); |
317 | 318 |
318 // No need to compare simulcastStream as numberOfSimulcastStreams should | 319 // No need to compare simulcastStream as numberOfSimulcastStreams should |
319 // always be 0. | 320 // always be 0. |
320 } | 321 } |
321 | 322 |
322 void InitRefCodec(int stream_index, VideoCodec* ref_codec) { | 323 void InitRefCodec(int stream_index, VideoCodec* ref_codec) { |
323 *ref_codec = codec_; | 324 *ref_codec = codec_; |
324 ref_codec->codecSpecific.VP8.numberOfTemporalLayers = | 325 ref_codec->codecSpecific.VP8.numberOfTemporalLayers = |
325 kTestTemporalLayerProfile[stream_index]; | 326 kTestTemporalLayerProfile[stream_index]; |
| 327 ref_codec->codecSpecific.VP8.tl_factory = &tl_factory_; |
326 ref_codec->width = codec_.simulcastStream[stream_index].width; | 328 ref_codec->width = codec_.simulcastStream[stream_index].width; |
327 ref_codec->height = codec_.simulcastStream[stream_index].height; | 329 ref_codec->height = codec_.simulcastStream[stream_index].height; |
328 ref_codec->maxBitrate = codec_.simulcastStream[stream_index].maxBitrate; | 330 ref_codec->maxBitrate = codec_.simulcastStream[stream_index].maxBitrate; |
329 ref_codec->minBitrate = codec_.simulcastStream[stream_index].minBitrate; | 331 ref_codec->minBitrate = codec_.simulcastStream[stream_index].minBitrate; |
330 ref_codec->qpMax = codec_.simulcastStream[stream_index].qpMax; | 332 ref_codec->qpMax = codec_.simulcastStream[stream_index].qpMax; |
331 } | 333 } |
332 | 334 |
333 void VerifyCodecSettings() { | 335 void VerifyCodecSettings() { |
334 EXPECT_EQ(3u, helper_->factory()->encoders().size()); | 336 EXPECT_EQ(3u, helper_->factory()->encoders().size()); |
335 VideoCodec ref_codec; | 337 VideoCodec ref_codec; |
(...skipping 23 matching lines...) Expand all Loading... |
359 VerifyCodec(ref_codec, 2); | 361 VerifyCodec(ref_codec, 2); |
360 } | 362 } |
361 | 363 |
362 protected: | 364 protected: |
363 std::unique_ptr<TestSimulcastEncoderAdapterFakeHelper> helper_; | 365 std::unique_ptr<TestSimulcastEncoderAdapterFakeHelper> helper_; |
364 std::unique_ptr<VP8Encoder> adapter_; | 366 std::unique_ptr<VP8Encoder> adapter_; |
365 VideoCodec codec_; | 367 VideoCodec codec_; |
366 int last_encoded_image_width_; | 368 int last_encoded_image_width_; |
367 int last_encoded_image_height_; | 369 int last_encoded_image_height_; |
368 int last_encoded_image_simulcast_index_; | 370 int last_encoded_image_simulcast_index_; |
| 371 TemporalLayersFactory tl_factory_; |
369 }; | 372 }; |
370 | 373 |
371 TEST_F(TestSimulcastEncoderAdapterFake, InitEncode) { | 374 TEST_F(TestSimulcastEncoderAdapterFake, InitEncode) { |
372 SetupCodec(); | 375 SetupCodec(); |
373 VerifyCodecSettings(); | 376 VerifyCodecSettings(); |
374 } | 377 } |
375 | 378 |
376 TEST_F(TestSimulcastEncoderAdapterFake, SetChannelParameters) { | 379 TEST_F(TestSimulcastEncoderAdapterFake, SetChannelParameters) { |
377 SetupCodec(); | 380 SetupCodec(); |
378 const uint32_t packetLoss = 5; | 381 const uint32_t packetLoss = 5; |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 helper_->factory()->encoders()[2]->SendEncodedImage(120, 240); | 414 helper_->factory()->encoders()[2]->SendEncodedImage(120, 240); |
412 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); | 415 EXPECT_TRUE(GetLastEncodedImageInfo(&width, &height, &simulcast_index)); |
413 EXPECT_EQ(120, width); | 416 EXPECT_EQ(120, width); |
414 EXPECT_EQ(240, height); | 417 EXPECT_EQ(240, height); |
415 EXPECT_EQ(2, simulcast_index); | 418 EXPECT_EQ(2, simulcast_index); |
416 } | 419 } |
417 | 420 |
418 TEST_F(TestSimulcastEncoderAdapterFake, SupportsNativeHandleForSingleStreams) { | 421 TEST_F(TestSimulcastEncoderAdapterFake, SupportsNativeHandleForSingleStreams) { |
419 TestVp8Simulcast::DefaultSettings( | 422 TestVp8Simulcast::DefaultSettings( |
420 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 423 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 424 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
421 codec_.numberOfSimulcastStreams = 1; | 425 codec_.numberOfSimulcastStreams = 1; |
422 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 426 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
423 adapter_->RegisterEncodeCompleteCallback(this); | 427 adapter_->RegisterEncodeCompleteCallback(this); |
424 ASSERT_EQ(1u, helper_->factory()->encoders().size()); | 428 ASSERT_EQ(1u, helper_->factory()->encoders().size()); |
425 helper_->factory()->encoders()[0]->set_supports_native_handle(true); | 429 helper_->factory()->encoders()[0]->set_supports_native_handle(true); |
426 EXPECT_TRUE(adapter_->SupportsNativeHandle()); | 430 EXPECT_TRUE(adapter_->SupportsNativeHandle()); |
427 helper_->factory()->encoders()[0]->set_supports_native_handle(false); | 431 helper_->factory()->encoders()[0]->set_supports_native_handle(false); |
428 EXPECT_FALSE(adapter_->SupportsNativeHandle()); | 432 EXPECT_FALSE(adapter_->SupportsNativeHandle()); |
429 } | 433 } |
430 | 434 |
431 TEST_F(TestSimulcastEncoderAdapterFake, SetRatesUnderMinBitrate) { | 435 TEST_F(TestSimulcastEncoderAdapterFake, SetRatesUnderMinBitrate) { |
432 TestVp8Simulcast::DefaultSettings( | 436 TestVp8Simulcast::DefaultSettings( |
433 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 437 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 438 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
434 codec_.minBitrate = 50; | 439 codec_.minBitrate = 50; |
435 codec_.numberOfSimulcastStreams = 1; | 440 codec_.numberOfSimulcastStreams = 1; |
436 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 441 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
437 | 442 |
438 // Above min should be respected. | 443 // Above min should be respected. |
439 adapter_->SetRates(100, 30); | 444 adapter_->SetRates(100, 30); |
440 EXPECT_EQ(100, helper_->factory()->encoders()[0]->last_set_bitrate()); | 445 EXPECT_EQ(100, 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 adapter_->SetRates(15, 30); |
444 EXPECT_EQ(50, helper_->factory()->encoders()[0]->last_set_bitrate()); | 449 EXPECT_EQ(50, helper_->factory()->encoders()[0]->last_set_bitrate()); |
445 | 450 |
446 // Zero should be passed on as is, since it means "pause". | 451 // Zero should be passed on as is, since it means "pause". |
447 adapter_->SetRates(0, 30); | 452 adapter_->SetRates(0, 30); |
448 EXPECT_EQ(0, helper_->factory()->encoders()[0]->last_set_bitrate()); | 453 EXPECT_EQ(0, helper_->factory()->encoders()[0]->last_set_bitrate()); |
449 } | 454 } |
450 | 455 |
451 TEST_F(TestSimulcastEncoderAdapterFake, SupportsImplementationName) { | 456 TEST_F(TestSimulcastEncoderAdapterFake, SupportsImplementationName) { |
452 EXPECT_STREQ("SimulcastEncoderAdapter", adapter_->ImplementationName()); | 457 EXPECT_STREQ("SimulcastEncoderAdapter", adapter_->ImplementationName()); |
453 TestVp8Simulcast::DefaultSettings( | 458 TestVp8Simulcast::DefaultSettings( |
454 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 459 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 460 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
455 std::vector<const char*> encoder_names; | 461 std::vector<const char*> encoder_names; |
456 encoder_names.push_back("codec1"); | 462 encoder_names.push_back("codec1"); |
457 encoder_names.push_back("codec2"); | 463 encoder_names.push_back("codec2"); |
458 encoder_names.push_back("codec3"); | 464 encoder_names.push_back("codec3"); |
459 helper_->factory()->SetEncoderNames(encoder_names); | 465 helper_->factory()->SetEncoderNames(encoder_names); |
460 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 466 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
461 EXPECT_STREQ("SimulcastEncoderAdapter (codec1, codec2, codec3)", | 467 EXPECT_STREQ("SimulcastEncoderAdapter (codec1, codec2, codec3)", |
462 adapter_->ImplementationName()); | 468 adapter_->ImplementationName()); |
463 | 469 |
464 // Single streams should not expose "SimulcastEncoderAdapter" in name. | 470 // Single streams should not expose "SimulcastEncoderAdapter" in name. |
465 adapter_->Release(); | 471 adapter_->Release(); |
466 codec_.numberOfSimulcastStreams = 1; | 472 codec_.numberOfSimulcastStreams = 1; |
467 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 473 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
468 adapter_->RegisterEncodeCompleteCallback(this); | 474 adapter_->RegisterEncodeCompleteCallback(this); |
469 ASSERT_EQ(1u, helper_->factory()->encoders().size()); | 475 ASSERT_EQ(1u, helper_->factory()->encoders().size()); |
470 EXPECT_STREQ("codec1", adapter_->ImplementationName()); | 476 EXPECT_STREQ("codec1", adapter_->ImplementationName()); |
471 } | 477 } |
472 | 478 |
473 TEST_F(TestSimulcastEncoderAdapterFake, | 479 TEST_F(TestSimulcastEncoderAdapterFake, |
474 SupportsNativeHandleForMultipleStreams) { | 480 SupportsNativeHandleForMultipleStreams) { |
475 TestVp8Simulcast::DefaultSettings( | 481 TestVp8Simulcast::DefaultSettings( |
476 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 482 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 483 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
477 codec_.numberOfSimulcastStreams = 3; | 484 codec_.numberOfSimulcastStreams = 3; |
478 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 485 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
479 adapter_->RegisterEncodeCompleteCallback(this); | 486 adapter_->RegisterEncodeCompleteCallback(this); |
480 ASSERT_EQ(3u, helper_->factory()->encoders().size()); | 487 ASSERT_EQ(3u, helper_->factory()->encoders().size()); |
481 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) | 488 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) |
482 encoder->set_supports_native_handle(true); | 489 encoder->set_supports_native_handle(true); |
483 // If one encoder doesn't support it, then overall support is disabled. | 490 // If one encoder doesn't support it, then overall support is disabled. |
484 helper_->factory()->encoders()[0]->set_supports_native_handle(false); | 491 helper_->factory()->encoders()[0]->set_supports_native_handle(false); |
485 EXPECT_FALSE(adapter_->SupportsNativeHandle()); | 492 EXPECT_FALSE(adapter_->SupportsNativeHandle()); |
486 // Once all do, then the adapter claims support. | 493 // Once all do, then the adapter claims support. |
487 helper_->factory()->encoders()[0]->set_supports_native_handle(true); | 494 helper_->factory()->encoders()[0]->set_supports_native_handle(true); |
488 EXPECT_TRUE(adapter_->SupportsNativeHandle()); | 495 EXPECT_TRUE(adapter_->SupportsNativeHandle()); |
489 } | 496 } |
490 | 497 |
491 class FakeNativeHandleBuffer : public NativeHandleBuffer { | 498 class FakeNativeHandleBuffer : public NativeHandleBuffer { |
492 public: | 499 public: |
493 FakeNativeHandleBuffer(void* native_handle, int width, int height) | 500 FakeNativeHandleBuffer(void* native_handle, int width, int height) |
494 : NativeHandleBuffer(native_handle, width, height) {} | 501 : NativeHandleBuffer(native_handle, width, height) {} |
495 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override { | 502 rtc::scoped_refptr<VideoFrameBuffer> NativeToI420Buffer() override { |
496 RTC_NOTREACHED(); | 503 RTC_NOTREACHED(); |
497 return nullptr; | 504 return nullptr; |
498 } | 505 } |
499 }; | 506 }; |
500 | 507 |
501 TEST_F(TestSimulcastEncoderAdapterFake, | 508 TEST_F(TestSimulcastEncoderAdapterFake, |
502 NativeHandleForwardingForMultipleStreams) { | 509 NativeHandleForwardingForMultipleStreams) { |
503 TestVp8Simulcast::DefaultSettings( | 510 TestVp8Simulcast::DefaultSettings( |
504 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 511 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 512 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
505 codec_.numberOfSimulcastStreams = 3; | 513 codec_.numberOfSimulcastStreams = 3; |
506 // High start bitrate, so all streams are enabled. | 514 // High start bitrate, so all streams are enabled. |
507 codec_.startBitrate = 3000; | 515 codec_.startBitrate = 3000; |
508 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 516 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
509 adapter_->RegisterEncodeCompleteCallback(this); | 517 adapter_->RegisterEncodeCompleteCallback(this); |
510 ASSERT_EQ(3u, helper_->factory()->encoders().size()); | 518 ASSERT_EQ(3u, helper_->factory()->encoders().size()); |
511 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) | 519 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) |
512 encoder->set_supports_native_handle(true); | 520 encoder->set_supports_native_handle(true); |
513 EXPECT_TRUE(adapter_->SupportsNativeHandle()); | 521 EXPECT_TRUE(adapter_->SupportsNativeHandle()); |
514 | 522 |
515 rtc::scoped_refptr<VideoFrameBuffer> buffer( | 523 rtc::scoped_refptr<VideoFrameBuffer> buffer( |
516 new rtc::RefCountedObject<FakeNativeHandleBuffer>(this, 1280, 720)); | 524 new rtc::RefCountedObject<FakeNativeHandleBuffer>(this, 1280, 720)); |
517 VideoFrame input_frame(buffer, 100, 1000, kVideoRotation_180); | 525 VideoFrame input_frame(buffer, 100, 1000, kVideoRotation_180); |
518 // Expect calls with the given video frame verbatim, since it's a texture | 526 // Expect calls with the given video frame verbatim, since it's a texture |
519 // frame and can't otherwise be modified/resized. | 527 // frame and can't otherwise be modified/resized. |
520 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) | 528 for (MockVideoEncoder* encoder : helper_->factory()->encoders()) |
521 EXPECT_CALL(*encoder, Encode(::testing::Ref(input_frame), _, _)).Times(1); | 529 EXPECT_CALL(*encoder, Encode(::testing::Ref(input_frame), _, _)).Times(1); |
522 std::vector<FrameType> frame_types(3, kVideoFrameKey); | 530 std::vector<FrameType> frame_types(3, kVideoFrameKey); |
523 EXPECT_EQ(0, adapter_->Encode(input_frame, NULL, &frame_types)); | 531 EXPECT_EQ(0, adapter_->Encode(input_frame, NULL, &frame_types)); |
524 } | 532 } |
525 | 533 |
526 TEST_F(TestSimulcastEncoderAdapterFake, TestFailureReturnCodesFromEncodeCalls) { | 534 TEST_F(TestSimulcastEncoderAdapterFake, TestFailureReturnCodesFromEncodeCalls) { |
527 TestVp8Simulcast::DefaultSettings( | 535 TestVp8Simulcast::DefaultSettings( |
528 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); | 536 &codec_, static_cast<const int*>(kTestTemporalLayerProfile)); |
| 537 codec_.codecSpecific.VP8.tl_factory = &tl_factory_; |
529 codec_.numberOfSimulcastStreams = 3; | 538 codec_.numberOfSimulcastStreams = 3; |
530 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); | 539 EXPECT_EQ(0, adapter_->InitEncode(&codec_, 1, 1200)); |
531 adapter_->RegisterEncodeCompleteCallback(this); | 540 adapter_->RegisterEncodeCompleteCallback(this); |
532 ASSERT_EQ(3u, helper_->factory()->encoders().size()); | 541 ASSERT_EQ(3u, helper_->factory()->encoders().size()); |
533 // Tell the 2nd encoder to request software fallback. | 542 // Tell the 2nd encoder to request software fallback. |
534 EXPECT_CALL(*helper_->factory()->encoders()[1], Encode(_, _, _)) | 543 EXPECT_CALL(*helper_->factory()->encoders()[1], Encode(_, _, _)) |
535 .WillOnce(Return(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE)); | 544 .WillOnce(Return(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE)); |
536 | 545 |
537 // Send a fake frame and assert the return is software fallback. | 546 // Send a fake frame and assert the return is software fallback. |
538 int half_width = (kDefaultWidth + 1) / 2; | 547 int half_width = (kDefaultWidth + 1) / 2; |
539 rtc::scoped_refptr<I420Buffer> input_buffer = I420Buffer::Create( | 548 rtc::scoped_refptr<I420Buffer> input_buffer = I420Buffer::Create( |
540 kDefaultWidth, kDefaultHeight, kDefaultWidth, half_width, half_width); | 549 kDefaultWidth, kDefaultHeight, kDefaultWidth, half_width, half_width); |
541 input_buffer->InitializeData(); | 550 input_buffer->InitializeData(); |
542 VideoFrame input_frame(input_buffer, 0, 0, webrtc::kVideoRotation_0); | 551 VideoFrame input_frame(input_buffer, 0, 0, webrtc::kVideoRotation_0); |
543 std::vector<FrameType> frame_types(3, kVideoFrameKey); | 552 std::vector<FrameType> frame_types(3, kVideoFrameKey); |
544 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE, | 553 EXPECT_EQ(WEBRTC_VIDEO_CODEC_FALLBACK_SOFTWARE, |
545 adapter_->Encode(input_frame, nullptr, &frame_types)); | 554 adapter_->Encode(input_frame, nullptr, &frame_types)); |
546 } | 555 } |
547 | 556 |
548 } // namespace testing | 557 } // namespace testing |
549 } // namespace webrtc | 558 } // namespace webrtc |
OLD | NEW |