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