| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2004 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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 cricket::FakeWebRtcVideoEncoderFactory encoder_factory; | 333 cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| 334 encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8"); | 334 encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8"); |
| 335 cricket::VideoSendParameters parameters; | 335 cricket::VideoSendParameters parameters; |
| 336 parameters.codecs.push_back(kVp8Codec); | 336 parameters.codecs.push_back(kVp8Codec); |
| 337 | 337 |
| 338 std::unique_ptr<VideoMediaChannel> channel( | 338 std::unique_ptr<VideoMediaChannel> channel( |
| 339 SetUpForExternalEncoderFactory(&encoder_factory, parameters.codecs)); | 339 SetUpForExternalEncoderFactory(&encoder_factory, parameters.codecs)); |
| 340 | 340 |
| 341 EXPECT_TRUE( | 341 EXPECT_TRUE( |
| 342 channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); | 342 channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| 343 ASSERT_TRUE(encoder_factory.WaitForCreatedVideoEncoders(1)); | |
| 344 ASSERT_EQ(1u, encoder_factory.encoders().size()); | 343 ASSERT_EQ(1u, encoder_factory.encoders().size()); |
| 345 EXPECT_TRUE(channel->SetSend(true)); | 344 EXPECT_TRUE(channel->SetSend(true)); |
| 346 | 345 |
| 347 cricket::FakeVideoCapturer capturer; | 346 cricket::FakeVideoCapturer capturer; |
| 348 EXPECT_TRUE(channel->SetCapturer(kSsrc, &capturer)); | 347 EXPECT_TRUE(channel->SetCapturer(kSsrc, &capturer)); |
| 349 EXPECT_EQ(cricket::CS_RUNNING, | 348 EXPECT_EQ(cricket::CS_RUNNING, |
| 350 capturer.Start(capturer.GetSupportedFormats()->front())); | 349 capturer.Start(capturer.GetSupportedFormats()->front())); |
| 351 EXPECT_TRUE(capturer.CaptureFrame()); | 350 EXPECT_TRUE(capturer.CaptureFrame()); |
| 352 // Sending one frame will have reallocated the encoder since input size | |
| 353 // changes from a small default to the actual frame width/height. Wait for | |
| 354 // that to happen then for the frame to be sent. | |
| 355 ASSERT_TRUE(encoder_factory.WaitForCreatedVideoEncoders(2)); | |
| 356 EXPECT_TRUE_WAIT(encoder_factory.encoders()[0]->GetNumEncodedFrames() > 0, | 351 EXPECT_TRUE_WAIT(encoder_factory.encoders()[0]->GetNumEncodedFrames() > 0, |
| 357 kTimeout); | 352 kTimeout); |
| 358 | 353 |
| 354 // Sending one frame will have reallocated the encoder since input size |
| 355 // changes from a small default to the actual frame width/height. |
| 359 int num_created_encoders = encoder_factory.GetNumCreatedEncoders(); | 356 int num_created_encoders = encoder_factory.GetNumCreatedEncoders(); |
| 360 EXPECT_EQ(num_created_encoders, 2); | 357 EXPECT_EQ(num_created_encoders, 2); |
| 361 | 358 |
| 362 // Setting codecs of the same type should not reallocate any encoders | 359 // Setting codecs of the same type should not reallocate any encoders |
| 363 // (expecting a no-op). | 360 // (expecting a no-op). |
| 364 EXPECT_TRUE(channel->SetSendParameters(parameters)); | 361 EXPECT_TRUE(channel->SetSendParameters(parameters)); |
| 365 EXPECT_EQ(num_created_encoders, encoder_factory.GetNumCreatedEncoders()); | 362 EXPECT_EQ(num_created_encoders, encoder_factory.GetNumCreatedEncoders()); |
| 366 | 363 |
| 367 // Remove stream previously added to free the external encoder instance. | 364 // Remove stream previously added to free the external encoder instance. |
| 368 EXPECT_TRUE(channel->RemoveSendStream(kSsrc)); | 365 EXPECT_TRUE(channel->RemoveSendStream(kSsrc)); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 EXPECT_TRUE( | 576 EXPECT_TRUE( |
| 580 channel->AddSendStream(CreateSimStreamParams("cname", ssrcs))); | 577 channel->AddSendStream(CreateSimStreamParams("cname", ssrcs))); |
| 581 EXPECT_TRUE(channel->SetSend(true)); | 578 EXPECT_TRUE(channel->SetSend(true)); |
| 582 | 579 |
| 583 cricket::FakeVideoCapturer capturer; | 580 cricket::FakeVideoCapturer capturer; |
| 584 EXPECT_TRUE(channel->SetCapturer(ssrcs.front(), &capturer)); | 581 EXPECT_TRUE(channel->SetCapturer(ssrcs.front(), &capturer)); |
| 585 EXPECT_EQ(cricket::CS_RUNNING, | 582 EXPECT_EQ(cricket::CS_RUNNING, |
| 586 capturer.Start(capturer.GetSupportedFormats()->front())); | 583 capturer.Start(capturer.GetSupportedFormats()->front())); |
| 587 EXPECT_TRUE(capturer.CaptureFrame()); | 584 EXPECT_TRUE(capturer.CaptureFrame()); |
| 588 | 585 |
| 589 ASSERT_TRUE(encoder_factory.WaitForCreatedVideoEncoders(2)); | 586 EXPECT_GT(encoder_factory.encoders().size(), 1u); |
| 590 | 587 |
| 591 // Verify that encoders are configured for simulcast through adapter | 588 // Verify that encoders are configured for simulcast through adapter |
| 592 // (increasing resolution and only configured to send one stream each). | 589 // (increasing resolution and only configured to send one stream each). |
| 593 int prev_width = -1; | 590 int prev_width = -1; |
| 594 for (size_t i = 0; i < encoder_factory.encoders().size(); ++i) { | 591 for (size_t i = 0; i < encoder_factory.encoders().size(); ++i) { |
| 595 ASSERT_TRUE(encoder_factory.encoders()[i]->WaitForInitEncode()); | |
| 596 webrtc::VideoCodec codec_settings = | 592 webrtc::VideoCodec codec_settings = |
| 597 encoder_factory.encoders()[i]->GetCodecSettings(); | 593 encoder_factory.encoders()[i]->GetCodecSettings(); |
| 598 EXPECT_EQ(0, codec_settings.numberOfSimulcastStreams); | 594 EXPECT_EQ(0, codec_settings.numberOfSimulcastStreams); |
| 599 EXPECT_GT(codec_settings.width, prev_width); | 595 EXPECT_GT(codec_settings.width, prev_width); |
| 600 prev_width = codec_settings.width; | 596 prev_width = codec_settings.width; |
| 601 } | 597 } |
| 602 | 598 |
| 603 EXPECT_TRUE(channel->SetCapturer(ssrcs.front(), NULL)); | 599 EXPECT_TRUE(channel->SetCapturer(ssrcs.front(), NULL)); |
| 604 | 600 |
| 605 channel.reset(); | 601 channel.reset(); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 | 657 |
| 662 // Send a fake frame, or else the media engine will configure the simulcast | 658 // Send a fake frame, or else the media engine will configure the simulcast |
| 663 // encoder adapter at a low-enough size that it'll only create a single | 659 // encoder adapter at a low-enough size that it'll only create a single |
| 664 // encoder layer. | 660 // encoder layer. |
| 665 cricket::FakeVideoCapturer capturer; | 661 cricket::FakeVideoCapturer capturer; |
| 666 EXPECT_TRUE(channel->SetCapturer(ssrcs.front(), &capturer)); | 662 EXPECT_TRUE(channel->SetCapturer(ssrcs.front(), &capturer)); |
| 667 EXPECT_EQ(cricket::CS_RUNNING, | 663 EXPECT_EQ(cricket::CS_RUNNING, |
| 668 capturer.Start(capturer.GetSupportedFormats()->front())); | 664 capturer.Start(capturer.GetSupportedFormats()->front())); |
| 669 EXPECT_TRUE(capturer.CaptureFrame()); | 665 EXPECT_TRUE(capturer.CaptureFrame()); |
| 670 | 666 |
| 671 ASSERT_TRUE(encoder_factory.WaitForCreatedVideoEncoders(2)); | 667 ASSERT_GT(encoder_factory.encoders().size(), 1u); |
| 672 ASSERT_TRUE(encoder_factory.encoders()[0]->WaitForInitEncode()); | |
| 673 EXPECT_EQ(webrtc::kVideoCodecVP8, | 668 EXPECT_EQ(webrtc::kVideoCodecVP8, |
| 674 encoder_factory.encoders()[0]->GetCodecSettings().codecType); | 669 encoder_factory.encoders()[0]->GetCodecSettings().codecType); |
| 675 | 670 |
| 676 channel.reset(); | 671 channel.reset(); |
| 677 // Make sure DestroyVideoEncoder was called on the factory. | 672 // Make sure DestroyVideoEncoder was called on the factory. |
| 678 EXPECT_EQ(0u, encoder_factory.encoders().size()); | 673 EXPECT_EQ(0u, encoder_factory.encoders().size()); |
| 679 } | 674 } |
| 680 | 675 |
| 681 TEST_F(WebRtcVideoEngine2Test, | 676 TEST_F(WebRtcVideoEngine2Test, |
| 682 DestroysNonSimulcastEncoderFromCombinedVP8AndH264Factory) { | 677 DestroysNonSimulcastEncoderFromCombinedVP8AndH264Factory) { |
| 683 cricket::FakeWebRtcVideoEncoderFactory encoder_factory; | 678 cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| 684 encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8"); | 679 encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8"); |
| 685 encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecH264, "H264"); | 680 encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecH264, "H264"); |
| 686 | 681 |
| 687 std::vector<cricket::VideoCodec> codecs; | 682 std::vector<cricket::VideoCodec> codecs; |
| 688 codecs.push_back(kH264Codec); | 683 codecs.push_back(kH264Codec); |
| 689 | 684 |
| 690 std::unique_ptr<VideoMediaChannel> channel( | 685 std::unique_ptr<VideoMediaChannel> channel( |
| 691 SetUpForExternalEncoderFactory(&encoder_factory, codecs)); | 686 SetUpForExternalEncoderFactory(&encoder_factory, codecs)); |
| 692 | 687 |
| 693 EXPECT_TRUE( | 688 EXPECT_TRUE( |
| 694 channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); | 689 channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| 695 ASSERT_EQ(1u, encoder_factory.encoders().size()); | 690 ASSERT_EQ(1u, encoder_factory.encoders().size()); |
| 696 ASSERT_TRUE(encoder_factory.encoders()[0]->WaitForInitEncode()); | |
| 697 EXPECT_EQ(webrtc::kVideoCodecH264, | 691 EXPECT_EQ(webrtc::kVideoCodecH264, |
| 698 encoder_factory.encoders()[0]->GetCodecSettings().codecType); | 692 encoder_factory.encoders()[0]->GetCodecSettings().codecType); |
| 699 | 693 |
| 700 channel.reset(); | 694 channel.reset(); |
| 701 // Make sure DestroyVideoEncoder was called on the factory. | 695 // Make sure DestroyVideoEncoder was called on the factory. |
| 702 ASSERT_EQ(0u, encoder_factory.encoders().size()); | 696 ASSERT_EQ(0u, encoder_factory.encoders().size()); |
| 703 } | 697 } |
| 704 | 698 |
| 705 TEST_F(WebRtcVideoEngine2Test, SimulcastDisabledForH264) { | 699 TEST_F(WebRtcVideoEngine2Test, SimulcastDisabledForH264) { |
| 706 cricket::FakeWebRtcVideoEncoderFactory encoder_factory; | 700 cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 718 // Send a frame of 720p. This should trigger a "real" encoder initialization. | 712 // Send a frame of 720p. This should trigger a "real" encoder initialization. |
| 719 cricket::VideoFormat format( | 713 cricket::VideoFormat format( |
| 720 1280, 720, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420); | 714 1280, 720, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420); |
| 721 cricket::FakeVideoCapturer capturer; | 715 cricket::FakeVideoCapturer capturer; |
| 722 EXPECT_TRUE(channel->SetCapturer(ssrcs[0], &capturer)); | 716 EXPECT_TRUE(channel->SetCapturer(ssrcs[0], &capturer)); |
| 723 EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(format)); | 717 EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(format)); |
| 724 EXPECT_TRUE(capturer.CaptureFrame()); | 718 EXPECT_TRUE(capturer.CaptureFrame()); |
| 725 | 719 |
| 726 ASSERT_EQ(1u, encoder_factory.encoders().size()); | 720 ASSERT_EQ(1u, encoder_factory.encoders().size()); |
| 727 FakeWebRtcVideoEncoder* encoder = encoder_factory.encoders()[0]; | 721 FakeWebRtcVideoEncoder* encoder = encoder_factory.encoders()[0]; |
| 728 ASSERT_TRUE(encoder_factory.encoders()[0]->WaitForInitEncode()); | |
| 729 EXPECT_EQ(webrtc::kVideoCodecH264, encoder->GetCodecSettings().codecType); | 722 EXPECT_EQ(webrtc::kVideoCodecH264, encoder->GetCodecSettings().codecType); |
| 730 EXPECT_EQ(1u, encoder->GetCodecSettings().numberOfSimulcastStreams); | 723 EXPECT_EQ(1u, encoder->GetCodecSettings().numberOfSimulcastStreams); |
| 731 EXPECT_TRUE(channel->SetCapturer(ssrcs[0], nullptr)); | 724 EXPECT_TRUE(channel->SetCapturer(ssrcs[0], nullptr)); |
| 732 } | 725 } |
| 733 | 726 |
| 734 // Test that external codecs are added to the end of the supported codec list. | 727 // Test that external codecs are added to the end of the supported codec list. |
| 735 TEST_F(WebRtcVideoEngine2Test, ReportSupportedExternalCodecs) { | 728 TEST_F(WebRtcVideoEngine2Test, ReportSupportedExternalCodecs) { |
| 736 cricket::FakeWebRtcVideoEncoderFactory encoder_factory; | 729 cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
| 737 encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecUnknown, | 730 encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecUnknown, |
| 738 "FakeExternalCodec"); | 731 "FakeExternalCodec"); |
| (...skipping 2554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3293 | 3286 |
| 3294 // Test that we normalize send codec format size in simulcast. | 3287 // Test that we normalize send codec format size in simulcast. |
| 3295 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsWithOddSizeInSimulcast) { | 3288 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsWithOddSizeInSimulcast) { |
| 3296 cricket::VideoCodec codec(kVp8Codec270p); | 3289 cricket::VideoCodec codec(kVp8Codec270p); |
| 3297 codec.width += 1; | 3290 codec.width += 1; |
| 3298 codec.height += 1; | 3291 codec.height += 1; |
| 3299 VerifySimulcastSettings(codec, 2, 2); | 3292 VerifySimulcastSettings(codec, 2, 2); |
| 3300 } | 3293 } |
| 3301 } // namespace cricket | 3294 } // namespace cricket |
| 3302 | 3295 |
| OLD | NEW |