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.WaitForCreatedVideoEncoder()); | |
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.WaitForCreatedVideoEncoder()); | |
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 while (encoder_factory.encoders().size() <= 1) |
590 ASSERT_TRUE(encoder_factory.WaitForCreatedVideoEncoder()); | |
stefan-webrtc
2016/03/14 13:14:03
Maybe we should make WaitForCreatedVideoEncoder ta
pbos-webrtc
2016/03/14 15:12:58
Done.
| |
587 | 591 |
588 // Verify that encoders are configured for simulcast through adapter | 592 // Verify that encoders are configured for simulcast through adapter |
589 // (increasing resolution and only configured to send one stream each). | 593 // (increasing resolution and only configured to send one stream each). |
590 int prev_width = -1; | 594 int prev_width = -1; |
591 for (size_t i = 0; i < encoder_factory.encoders().size(); ++i) { | 595 for (size_t i = 0; i < encoder_factory.encoders().size(); ++i) { |
596 ASSERT_TRUE(encoder_factory.encoders()[i]->WaitForInitEncode()); | |
592 webrtc::VideoCodec codec_settings = | 597 webrtc::VideoCodec codec_settings = |
593 encoder_factory.encoders()[i]->GetCodecSettings(); | 598 encoder_factory.encoders()[i]->GetCodecSettings(); |
594 EXPECT_EQ(0, codec_settings.numberOfSimulcastStreams); | 599 EXPECT_EQ(0, codec_settings.numberOfSimulcastStreams); |
595 EXPECT_GT(codec_settings.width, prev_width); | 600 EXPECT_GT(codec_settings.width, prev_width); |
596 prev_width = codec_settings.width; | 601 prev_width = codec_settings.width; |
597 } | 602 } |
598 | 603 |
599 EXPECT_TRUE(channel->SetCapturer(ssrcs.front(), NULL)); | 604 EXPECT_TRUE(channel->SetCapturer(ssrcs.front(), NULL)); |
600 | 605 |
601 channel.reset(); | 606 channel.reset(); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
657 | 662 |
658 // Send a fake frame, or else the media engine will configure the simulcast | 663 // 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 | 664 // encoder adapter at a low-enough size that it'll only create a single |
660 // encoder layer. | 665 // encoder layer. |
661 cricket::FakeVideoCapturer capturer; | 666 cricket::FakeVideoCapturer capturer; |
662 EXPECT_TRUE(channel->SetCapturer(ssrcs.front(), &capturer)); | 667 EXPECT_TRUE(channel->SetCapturer(ssrcs.front(), &capturer)); |
663 EXPECT_EQ(cricket::CS_RUNNING, | 668 EXPECT_EQ(cricket::CS_RUNNING, |
664 capturer.Start(capturer.GetSupportedFormats()->front())); | 669 capturer.Start(capturer.GetSupportedFormats()->front())); |
665 EXPECT_TRUE(capturer.CaptureFrame()); | 670 EXPECT_TRUE(capturer.CaptureFrame()); |
666 | 671 |
667 ASSERT_GT(encoder_factory.encoders().size(), 1u); | 672 while (encoder_factory.encoders().size() <= 1) |
673 ASSERT_TRUE(encoder_factory.WaitForCreatedVideoEncoder()); | |
674 ASSERT_TRUE(encoder_factory.encoders()[0]->WaitForInitEncode()); | |
668 EXPECT_EQ(webrtc::kVideoCodecVP8, | 675 EXPECT_EQ(webrtc::kVideoCodecVP8, |
669 encoder_factory.encoders()[0]->GetCodecSettings().codecType); | 676 encoder_factory.encoders()[0]->GetCodecSettings().codecType); |
670 | 677 |
671 channel.reset(); | 678 channel.reset(); |
672 // Make sure DestroyVideoEncoder was called on the factory. | 679 // Make sure DestroyVideoEncoder was called on the factory. |
673 EXPECT_EQ(0u, encoder_factory.encoders().size()); | 680 EXPECT_EQ(0u, encoder_factory.encoders().size()); |
674 } | 681 } |
675 | 682 |
676 TEST_F(WebRtcVideoEngine2Test, | 683 TEST_F(WebRtcVideoEngine2Test, |
677 DestroysNonSimulcastEncoderFromCombinedVP8AndH264Factory) { | 684 DestroysNonSimulcastEncoderFromCombinedVP8AndH264Factory) { |
678 cricket::FakeWebRtcVideoEncoderFactory encoder_factory; | 685 cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
679 encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8"); | 686 encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8"); |
680 encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecH264, "H264"); | 687 encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecH264, "H264"); |
681 | 688 |
682 std::vector<cricket::VideoCodec> codecs; | 689 std::vector<cricket::VideoCodec> codecs; |
683 codecs.push_back(kH264Codec); | 690 codecs.push_back(kH264Codec); |
684 | 691 |
685 std::unique_ptr<VideoMediaChannel> channel( | 692 std::unique_ptr<VideoMediaChannel> channel( |
686 SetUpForExternalEncoderFactory(&encoder_factory, codecs)); | 693 SetUpForExternalEncoderFactory(&encoder_factory, codecs)); |
687 | 694 |
688 EXPECT_TRUE( | 695 EXPECT_TRUE( |
689 channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); | 696 channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
690 ASSERT_EQ(1u, encoder_factory.encoders().size()); | 697 ASSERT_EQ(1u, encoder_factory.encoders().size()); |
698 ASSERT_TRUE(encoder_factory.encoders()[0]->WaitForInitEncode()); | |
691 EXPECT_EQ(webrtc::kVideoCodecH264, | 699 EXPECT_EQ(webrtc::kVideoCodecH264, |
692 encoder_factory.encoders()[0]->GetCodecSettings().codecType); | 700 encoder_factory.encoders()[0]->GetCodecSettings().codecType); |
693 | 701 |
694 channel.reset(); | 702 channel.reset(); |
695 // Make sure DestroyVideoEncoder was called on the factory. | 703 // Make sure DestroyVideoEncoder was called on the factory. |
696 ASSERT_EQ(0u, encoder_factory.encoders().size()); | 704 ASSERT_EQ(0u, encoder_factory.encoders().size()); |
697 } | 705 } |
698 | 706 |
699 TEST_F(WebRtcVideoEngine2Test, SimulcastDisabledForH264) { | 707 TEST_F(WebRtcVideoEngine2Test, SimulcastDisabledForH264) { |
700 cricket::FakeWebRtcVideoEncoderFactory encoder_factory; | 708 cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
(...skipping 11 matching lines...) Expand all Loading... | |
712 // Send a frame of 720p. This should trigger a "real" encoder initialization. | 720 // Send a frame of 720p. This should trigger a "real" encoder initialization. |
713 cricket::VideoFormat format( | 721 cricket::VideoFormat format( |
714 1280, 720, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420); | 722 1280, 720, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420); |
715 cricket::FakeVideoCapturer capturer; | 723 cricket::FakeVideoCapturer capturer; |
716 EXPECT_TRUE(channel->SetCapturer(ssrcs[0], &capturer)); | 724 EXPECT_TRUE(channel->SetCapturer(ssrcs[0], &capturer)); |
717 EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(format)); | 725 EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(format)); |
718 EXPECT_TRUE(capturer.CaptureFrame()); | 726 EXPECT_TRUE(capturer.CaptureFrame()); |
719 | 727 |
720 ASSERT_EQ(1u, encoder_factory.encoders().size()); | 728 ASSERT_EQ(1u, encoder_factory.encoders().size()); |
721 FakeWebRtcVideoEncoder* encoder = encoder_factory.encoders()[0]; | 729 FakeWebRtcVideoEncoder* encoder = encoder_factory.encoders()[0]; |
730 ASSERT_TRUE(encoder_factory.encoders()[0]->WaitForInitEncode()); | |
722 EXPECT_EQ(webrtc::kVideoCodecH264, encoder->GetCodecSettings().codecType); | 731 EXPECT_EQ(webrtc::kVideoCodecH264, encoder->GetCodecSettings().codecType); |
723 EXPECT_EQ(1u, encoder->GetCodecSettings().numberOfSimulcastStreams); | 732 EXPECT_EQ(1u, encoder->GetCodecSettings().numberOfSimulcastStreams); |
724 EXPECT_TRUE(channel->SetCapturer(ssrcs[0], nullptr)); | 733 EXPECT_TRUE(channel->SetCapturer(ssrcs[0], nullptr)); |
725 } | 734 } |
726 | 735 |
727 // Test that external codecs are added to the end of the supported codec list. | 736 // Test that external codecs are added to the end of the supported codec list. |
728 TEST_F(WebRtcVideoEngine2Test, ReportSupportedExternalCodecs) { | 737 TEST_F(WebRtcVideoEngine2Test, ReportSupportedExternalCodecs) { |
729 cricket::FakeWebRtcVideoEncoderFactory encoder_factory; | 738 cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
730 encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecUnknown, | 739 encoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecUnknown, |
731 "FakeExternalCodec"); | 740 "FakeExternalCodec"); |
(...skipping 2520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3252 | 3261 |
3253 // Test that we normalize send codec format size in simulcast. | 3262 // Test that we normalize send codec format size in simulcast. |
3254 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsWithOddSizeInSimulcast) { | 3263 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsWithOddSizeInSimulcast) { |
3255 cricket::VideoCodec codec(kVp8Codec270p); | 3264 cricket::VideoCodec codec(kVp8Codec270p); |
3256 codec.width += 1; | 3265 codec.width += 1; |
3257 codec.height += 1; | 3266 codec.height += 1; |
3258 VerifySimulcastSettings(codec, 2, 2); | 3267 VerifySimulcastSettings(codec, 2, 2); |
3259 } | 3268 } |
3260 } // namespace cricket | 3269 } // namespace cricket |
3261 | 3270 |
OLD | NEW |