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 |
11 #include <algorithm> | 11 #include <algorithm> |
12 #include <list> | 12 #include <list> |
13 #include <map> | 13 #include <map> |
14 #include <memory> | 14 #include <memory> |
15 #include <unordered_set> | |
15 #include <vector> | 16 #include <vector> |
16 | 17 |
17 #include "webrtc/base/arraysize.h" | 18 #include "webrtc/base/arraysize.h" |
18 #include "webrtc/base/gunit.h" | 19 #include "webrtc/base/gunit.h" |
19 #include "webrtc/base/stringutils.h" | 20 #include "webrtc/base/stringutils.h" |
20 #include "webrtc/common_video/h264/profile_level_id.h" | 21 #include "webrtc/common_video/h264/profile_level_id.h" |
21 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | 22 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
22 #include "webrtc/media/base/testutils.h" | 23 #include "webrtc/media/base/testutils.h" |
23 #include "webrtc/media/base/videoengine_unittest.h" | 24 #include "webrtc/media/base/videoengine_unittest.h" |
24 #include "webrtc/media/engine/fakewebrtccall.h" | 25 #include "webrtc/media/engine/fakewebrtccall.h" |
25 #include "webrtc/media/engine/fakewebrtcvideoengine.h" | 26 #include "webrtc/media/engine/fakewebrtcvideoengine.h" |
26 #include "webrtc/media/engine/simulcast.h" | 27 #include "webrtc/media/engine/simulcast.h" |
27 #include "webrtc/media/engine/webrtcvideoengine2.h" | 28 #include "webrtc/media/engine/webrtcvideoengine2.h" |
28 #include "webrtc/media/engine/webrtcvoiceengine.h" | 29 #include "webrtc/media/engine/webrtcvoiceengine.h" |
30 #include "webrtc/modules/video_coding/codecs/h264/include/h264.h" | |
31 #include "webrtc/modules/video_coding/codecs/vp9/include/vp9.h" | |
29 #include "webrtc/test/field_trial.h" | 32 #include "webrtc/test/field_trial.h" |
30 #include "webrtc/video_encoder.h" | 33 #include "webrtc/video_encoder.h" |
31 | 34 |
32 using webrtc::RtpExtension; | 35 using webrtc::RtpExtension; |
33 | 36 |
34 namespace { | 37 namespace { |
35 static const int kDefaultQpMax = 56; | 38 static const int kDefaultQpMax = 56; |
36 | 39 |
37 static const uint8_t kRedRtxPayloadType = 125; | 40 static const uint8_t kRedRtxPayloadType = 125; |
38 | 41 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 if (cricket::CodecNamesEq(codec.name.c_str(), "rtx") && | 74 if (cricket::CodecNamesEq(codec.name.c_str(), "rtx") && |
72 codec.GetParam(cricket::kCodecParamAssociatedPayloadType, | 75 codec.GetParam(cricket::kCodecParamAssociatedPayloadType, |
73 &associated_payload_type) && | 76 &associated_payload_type) && |
74 associated_payload_type == payload_type) { | 77 associated_payload_type == payload_type) { |
75 return true; | 78 return true; |
76 } | 79 } |
77 } | 80 } |
78 return false; | 81 return false; |
79 } | 82 } |
80 | 83 |
81 static rtc::scoped_refptr<webrtc::VideoFrameBuffer> CreateBlackFrameBuffer( | 84 static rtc::scoped_refptr<webrtc::VideoFrameBuffer> CreateBlackFrameBuffer( |
perkj_webrtc
2016/11/28 09:20:06
can we remove static here. (not your cl I know)
brandtr
2016/11/28 10:40:15
Done.
| |
82 int width, | 85 int width, |
83 int height) { | 86 int height) { |
84 rtc::scoped_refptr<webrtc::I420Buffer> buffer = | 87 rtc::scoped_refptr<webrtc::I420Buffer> buffer = |
85 webrtc::I420Buffer::Create(width, height); | 88 webrtc::I420Buffer::Create(width, height); |
86 buffer->SetToBlack(); | 89 buffer->SetToBlack(); |
87 return buffer; | 90 return buffer; |
88 } | 91 } |
89 | 92 |
90 void VerifySendStreamHasRtxTypes(const webrtc::VideoSendStream::Config& config, | 93 void VerifySendStreamHasRtxTypes(const webrtc::VideoSendStream::Config& config, |
91 const std::map<int, int>& rtx_types) { | 94 const std::map<int, int>& rtx_types) { |
92 std::map<int, int>::const_iterator it; | 95 std::map<int, int>::const_iterator it; |
93 it = rtx_types.find(config.encoder_settings.payload_type); | 96 it = rtx_types.find(config.encoder_settings.payload_type); |
94 EXPECT_TRUE(it != rtx_types.end() && | 97 EXPECT_TRUE(it != rtx_types.end() && |
95 it->second == config.rtp.rtx.payload_type); | 98 it->second == config.rtp.rtx.payload_type); |
96 | 99 |
97 if (config.rtp.ulpfec.red_rtx_payload_type != -1) { | 100 if (config.rtp.ulpfec.red_rtx_payload_type != -1) { |
98 it = rtx_types.find(config.rtp.ulpfec.red_payload_type); | 101 it = rtx_types.find(config.rtp.ulpfec.red_payload_type); |
99 EXPECT_TRUE(it != rtx_types.end() && | 102 EXPECT_TRUE(it != rtx_types.end() && |
100 it->second == config.rtp.ulpfec.red_rtx_payload_type); | 103 it->second == config.rtp.ulpfec.red_rtx_payload_type); |
101 } | 104 } |
102 } | 105 } |
106 | |
107 std::unordered_set<std::string> GetCodecNames( | |
108 const cricket::WebRtcVideoEngine2& engine) { | |
109 std::unordered_set<std::string> codec_names; | |
110 for (const auto& codec : engine.codecs()) | |
111 codec_names.insert(codec.name); | |
112 return codec_names; | |
113 } | |
103 } // namespace | 114 } // namespace |
104 | 115 |
105 namespace cricket { | 116 namespace cricket { |
106 class WebRtcVideoEngine2Test : public ::testing::Test { | 117 class WebRtcVideoEngine2Test : public ::testing::Test { |
107 public: | 118 public: |
108 WebRtcVideoEngine2Test() : WebRtcVideoEngine2Test("") {} | 119 WebRtcVideoEngine2Test() : WebRtcVideoEngine2Test("") {} |
109 explicit WebRtcVideoEngine2Test(const char* field_trials) | 120 explicit WebRtcVideoEngine2Test(const char* field_trials) |
110 : override_field_trials_(field_trials), | 121 : override_field_trials_(field_trials), |
111 call_(webrtc::Call::Create(webrtc::Call::Config(&event_log_))), | 122 call_(webrtc::Call::Create(webrtc::Call::Config(&event_log_))), |
112 engine_() { | 123 engine_() { |
(...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
742 EXPECT_TRUE(capturer.CaptureFrame()); | 753 EXPECT_TRUE(capturer.CaptureFrame()); |
743 | 754 |
744 ASSERT_EQ(1u, encoder_factory.encoders().size()); | 755 ASSERT_EQ(1u, encoder_factory.encoders().size()); |
745 FakeWebRtcVideoEncoder* encoder = encoder_factory.encoders()[0]; | 756 FakeWebRtcVideoEncoder* encoder = encoder_factory.encoders()[0]; |
746 ASSERT_TRUE(encoder_factory.encoders()[0]->WaitForInitEncode()); | 757 ASSERT_TRUE(encoder_factory.encoders()[0]->WaitForInitEncode()); |
747 EXPECT_EQ(webrtc::kVideoCodecH264, encoder->GetCodecSettings().codecType); | 758 EXPECT_EQ(webrtc::kVideoCodecH264, encoder->GetCodecSettings().codecType); |
748 EXPECT_EQ(1u, encoder->GetCodecSettings().numberOfSimulcastStreams); | 759 EXPECT_EQ(1u, encoder->GetCodecSettings().numberOfSimulcastStreams); |
749 EXPECT_TRUE(channel->SetVideoSend(ssrcs[0], true, nullptr, nullptr)); | 760 EXPECT_TRUE(channel->SetVideoSend(ssrcs[0], true, nullptr, nullptr)); |
750 } | 761 } |
751 | 762 |
763 // Test that internal codecs are added to the codec list. | |
764 // Update this test if the internal codecs are changed! | |
765 TEST_F(WebRtcVideoEngine2Test, ReportSupportedInternalCodecs) { | |
perkj_webrtc
2016/11/28 09:20:06
The fix is for different codecs when the engine h
brandtr
2016/11/28 10:40:15
Done. I did not reinitialize the engine in the tes
| |
766 engine_.Init(); | |
767 std::unordered_set<std::string> codec_names = GetCodecNames(engine_); | |
768 | |
769 size_t expected_num_codecs = 4; | |
770 EXPECT_NE(codec_names.find("VP8"), codec_names.end()); | |
magjed_webrtc
2016/11/28 10:31:31
nit: I think it would be slightly cleaner to write
brandtr
2016/11/28 10:47:40
Agree. I'm used to the find()/end() style after wo
| |
771 if (webrtc::VP9Encoder::IsSupported()) { | |
772 EXPECT_NE(codec_names.find("VP9"), codec_names.end()); | |
773 ++expected_num_codecs; | |
774 } | |
775 if (webrtc::H264Encoder::IsSupported()) { | |
776 EXPECT_NE(codec_names.find("H264"), codec_names.end()); | |
777 ++expected_num_codecs; | |
778 } | |
779 EXPECT_NE(codec_names.find("rtx"), codec_names.end()); | |
780 EXPECT_NE(codec_names.find("red"), codec_names.end()); | |
781 EXPECT_NE(codec_names.find("ulpfec"), codec_names.end()); | |
782 EXPECT_EQ(expected_num_codecs, codec_names.size()); | |
783 } | |
784 | |
785 class WebRtcVideoEngine2FlexfecTest : public WebRtcVideoEngine2Test { | |
786 public: | |
787 WebRtcVideoEngine2FlexfecTest() | |
788 : WebRtcVideoEngine2Test("WebRTC-FlexFEC-03/Enabled/") {} | |
789 }; | |
790 | |
791 // TODO(brandtr): Merge with test above, when the FlexFEC field trial is gone. | |
792 TEST_F(WebRtcVideoEngine2FlexfecTest, ReportSupportedInternalCodecs) { | |
793 engine_.Init(); | |
794 std::unordered_set<std::string> codec_names = GetCodecNames(engine_); | |
795 | |
796 EXPECT_NE(codec_names.find("flexfec-03"), codec_names.end()); | |
797 } | |
798 | |
752 // Test that external codecs are added to the end of the supported codec list. | 799 // Test that external codecs are added to the end of the supported codec list. |
753 TEST_F(WebRtcVideoEngine2Test, ReportSupportedExternalCodecs) { | 800 TEST_F(WebRtcVideoEngine2Test, ReportSupportedExternalCodecs) { |
754 cricket::FakeWebRtcVideoEncoderFactory encoder_factory; | 801 cricket::FakeWebRtcVideoEncoderFactory encoder_factory; |
755 encoder_factory.AddSupportedVideoCodecType("FakeExternalCodec"); | 802 encoder_factory.AddSupportedVideoCodecType("FakeExternalCodec"); |
756 engine_.SetExternalEncoderFactory(&encoder_factory); | 803 engine_.SetExternalEncoderFactory(&encoder_factory); |
757 engine_.Init(); | 804 engine_.Init(); |
758 | 805 |
759 std::vector<cricket::VideoCodec> codecs(engine_.codecs()); | 806 std::vector<cricket::VideoCodec> codecs(engine_.codecs()); |
760 ASSERT_GE(codecs.size(), 2u); | 807 ASSERT_GE(codecs.size(), 2u); |
761 cricket::VideoCodec internal_codec = codecs.front(); | 808 cricket::VideoCodec internal_codec = codecs.front(); |
762 cricket::VideoCodec external_codec = codecs.back(); | 809 cricket::VideoCodec external_codec = codecs.back(); |
763 | 810 |
764 // The external codec will appear at last. | 811 // The external codec will appear last in the vector. |
765 EXPECT_EQ("VP8", internal_codec.name); | 812 EXPECT_EQ("VP8", internal_codec.name); |
766 EXPECT_EQ("FakeExternalCodec", external_codec.name); | 813 EXPECT_EQ("FakeExternalCodec", external_codec.name); |
767 } | 814 } |
768 | 815 |
769 TEST_F(WebRtcVideoEngine2Test, RegisterExternalDecodersIfSupported) { | 816 TEST_F(WebRtcVideoEngine2Test, RegisterExternalDecodersIfSupported) { |
770 cricket::FakeWebRtcVideoDecoderFactory decoder_factory; | 817 cricket::FakeWebRtcVideoDecoderFactory decoder_factory; |
771 decoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8); | 818 decoder_factory.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8); |
772 cricket::VideoRecvParameters parameters; | 819 cricket::VideoRecvParameters parameters; |
773 parameters.codecs.push_back(GetEngineCodec("VP8")); | 820 parameters.codecs.push_back(GetEngineCodec("VP8")); |
774 | 821 |
(...skipping 3214 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3989 | 4036 |
3990 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsWith3SimulcastStreams) { | 4037 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsWith3SimulcastStreams) { |
3991 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 3); | 4038 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 3); |
3992 } | 4039 } |
3993 | 4040 |
3994 // Test that we normalize send codec format size in simulcast. | 4041 // Test that we normalize send codec format size in simulcast. |
3995 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsWithOddSizeInSimulcast) { | 4042 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsWithOddSizeInSimulcast) { |
3996 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 541, 271, 2, 2); | 4043 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 541, 271, 2, 2); |
3997 } | 4044 } |
3998 } // namespace cricket | 4045 } // namespace cricket |
OLD | NEW |