| 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 <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "webrtc/base/arraysize.h" | 17 #include "webrtc/base/arraysize.h" |
| 18 #include "webrtc/base/gunit.h" | 18 #include "webrtc/base/gunit.h" |
| 19 #include "webrtc/base/stringutils.h" | 19 #include "webrtc/base/stringutils.h" |
| 20 #include "webrtc/common_video/h264/profile_level_id.h" | 20 #include "webrtc/common_video/h264/profile_level_id.h" |
| 21 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" | 21 #include "webrtc/logging/rtc_event_log/rtc_event_log.h" |
| 22 #include "webrtc/media/base/mediaconstants.h" | 22 #include "webrtc/media/base/mediaconstants.h" |
| 23 #include "webrtc/media/base/testutils.h" | 23 #include "webrtc/media/base/testutils.h" |
| 24 #include "webrtc/media/base/videoengine_unittest.h" | 24 #include "webrtc/media/base/videoengine_unittest.h" |
| 25 #include "webrtc/media/engine/constants.h" |
| 25 #include "webrtc/media/engine/fakewebrtccall.h" | 26 #include "webrtc/media/engine/fakewebrtccall.h" |
| 26 #include "webrtc/media/engine/fakewebrtcvideoengine.h" | 27 #include "webrtc/media/engine/fakewebrtcvideoengine.h" |
| 27 #include "webrtc/media/engine/simulcast.h" | 28 #include "webrtc/media/engine/simulcast.h" |
| 28 #include "webrtc/media/engine/webrtcvideoengine2.h" | 29 #include "webrtc/media/engine/webrtcvideoengine2.h" |
| 29 #include "webrtc/media/engine/webrtcvoiceengine.h" | 30 #include "webrtc/media/engine/webrtcvoiceengine.h" |
| 30 #include "webrtc/test/field_trial.h" | 31 #include "webrtc/test/field_trial.h" |
| 31 #include "webrtc/video_encoder.h" | 32 #include "webrtc/video_encoder.h" |
| 32 | 33 |
| 33 using webrtc::RtpExtension; | 34 using webrtc::RtpExtension; |
| 34 | 35 |
| (...skipping 3892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3927 TestReceiverLocalSsrcConfiguration(false); | 3928 TestReceiverLocalSsrcConfiguration(false); |
| 3928 } | 3929 } |
| 3929 | 3930 |
| 3930 TEST_F(WebRtcVideoChannel2Test, ConfiguresLocalSsrcOnExistingReceivers) { | 3931 TEST_F(WebRtcVideoChannel2Test, ConfiguresLocalSsrcOnExistingReceivers) { |
| 3931 TestReceiverLocalSsrcConfiguration(true); | 3932 TestReceiverLocalSsrcConfiguration(true); |
| 3932 } | 3933 } |
| 3933 | 3934 |
| 3934 class WebRtcVideoChannel2SimulcastTest : public testing::Test { | 3935 class WebRtcVideoChannel2SimulcastTest : public testing::Test { |
| 3935 public: | 3936 public: |
| 3936 WebRtcVideoChannel2SimulcastTest() | 3937 WebRtcVideoChannel2SimulcastTest() |
| 3937 : fake_call_(webrtc::Call::Config(&event_log_)) {} | 3938 : fake_call_(webrtc::Call::Config(&event_log_)), last_ssrc_(0) {} |
| 3938 | 3939 |
| 3939 void SetUp() override { | 3940 void SetUp() override { |
| 3940 engine_.Init(); | 3941 engine_.Init(); |
| 3941 channel_.reset( | 3942 channel_.reset( |
| 3942 engine_.CreateChannel(&fake_call_, MediaConfig(), VideoOptions())); | 3943 engine_.CreateChannel(&fake_call_, MediaConfig(), VideoOptions())); |
| 3943 channel_->OnReadyToSend(true); | 3944 channel_->OnReadyToSend(true); |
| 3944 last_ssrc_ = 123; | 3945 last_ssrc_ = 123; |
| 3945 } | 3946 } |
| 3946 | 3947 |
| 3947 protected: | 3948 protected: |
| 3948 void VerifySimulcastSettings(const VideoCodec& codec, | 3949 void VerifySimulcastSettings(const VideoCodec& codec, |
| 3949 int capture_width, | 3950 int capture_width, |
| 3950 int capture_height, | 3951 int capture_height, |
| 3951 size_t num_configured_streams, | 3952 size_t num_configured_streams, |
| 3952 size_t expected_num_streams) { | 3953 size_t expected_num_streams, |
| 3954 bool screenshare, |
| 3955 bool conference_mode) { |
| 3953 cricket::VideoSendParameters parameters; | 3956 cricket::VideoSendParameters parameters; |
| 3957 VideoOptions options; |
| 3954 parameters.codecs.push_back(codec); | 3958 parameters.codecs.push_back(codec); |
| 3959 parameters.conference_mode = conference_mode; |
| 3960 if (screenshare) { |
| 3961 options.is_screencast = rtc::Optional<bool>(screenshare); |
| 3962 } |
| 3955 ASSERT_TRUE(channel_->SetSendParameters(parameters)); | 3963 ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 3956 | 3964 |
| 3957 std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); | 3965 std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); |
| 3958 RTC_DCHECK(num_configured_streams <= ssrcs.size()); | 3966 RTC_DCHECK(num_configured_streams <= ssrcs.size()); |
| 3959 ssrcs.resize(num_configured_streams); | 3967 ssrcs.resize(num_configured_streams); |
| 3960 | 3968 |
| 3961 FakeVideoSendStream* stream = | 3969 FakeVideoSendStream* stream = |
| 3962 AddSendStream(CreateSimStreamParams("cname", ssrcs)); | 3970 AddSendStream(CreateSimStreamParams("cname", ssrcs)); |
| 3963 // Send a full-size frame to trigger a stream reconfiguration to use all | 3971 // Send a full-size frame to trigger a stream reconfiguration to use all |
| 3964 // expected simulcast layers. | 3972 // expected simulcast layers. |
| 3965 cricket::FakeVideoCapturer capturer; | 3973 cricket::FakeVideoCapturer capturer; |
| 3966 EXPECT_TRUE( | 3974 EXPECT_TRUE( |
| 3967 channel_->SetVideoSend(ssrcs.front(), true, nullptr, &capturer)); | 3975 channel_->SetVideoSend(ssrcs.front(), true, &options, &capturer)); |
| 3968 EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(cricket::VideoFormat( | 3976 EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(cricket::VideoFormat( |
| 3969 capture_width, capture_height, | 3977 capture_width, capture_height, |
| 3970 cricket::VideoFormat::FpsToInterval(30), | 3978 cricket::VideoFormat::FpsToInterval(30), |
| 3971 cricket::FOURCC_I420))); | 3979 cricket::FOURCC_I420))); |
| 3972 channel_->SetSend(true); | 3980 channel_->SetSend(true); |
| 3973 EXPECT_TRUE(capturer.CaptureFrame()); | 3981 EXPECT_TRUE(capturer.CaptureFrame()); |
| 3974 | 3982 |
| 3975 std::vector<webrtc::VideoStream> video_streams = stream->GetVideoStreams(); | 3983 std::vector<webrtc::VideoStream> video_streams = stream->GetVideoStreams(); |
| 3976 ASSERT_EQ(expected_num_streams, video_streams.size()); | 3984 ASSERT_EQ(expected_num_streams, video_streams.size()); |
| 3977 | 3985 |
| 3978 std::vector<webrtc::VideoStream> expected_streams = GetSimulcastConfig( | 3986 std::vector<webrtc::VideoStream> expected_streams; |
| 3979 num_configured_streams, capture_width, capture_height, 0, kDefaultQpMax, | 3987 if (conference_mode) { |
| 3980 kDefaultVideoMaxFramerate); | 3988 expected_streams = GetSimulcastConfig( |
| 3989 num_configured_streams, capture_width, capture_height, 0, |
| 3990 kDefaultQpMax, kDefaultVideoMaxFramerate, screenshare); |
| 3991 } else { |
| 3992 webrtc::VideoStream stream; |
| 3993 stream.width = capture_width; |
| 3994 stream.height = capture_height; |
| 3995 stream.max_framerate = kDefaultVideoMaxFramerate; |
| 3996 stream.min_bitrate_bps = cricket::kMinVideoBitrateKbps * 1000; |
| 3997 int max_bitrate_kbps; |
| 3998 if (capture_width * capture_height <= 320 * 240) { |
| 3999 max_bitrate_kbps = 600; |
| 4000 } else if (capture_width * capture_height <= 640 * 480) { |
| 4001 max_bitrate_kbps = 1700; |
| 4002 } else if (capture_width * capture_height <= 960 * 540) { |
| 4003 max_bitrate_kbps = 2000; |
| 4004 } else { |
| 4005 max_bitrate_kbps = 2500; |
| 4006 } |
| 4007 stream.target_bitrate_bps = stream.max_bitrate_bps = |
| 4008 max_bitrate_kbps * 1000; |
| 4009 stream.max_qp = kDefaultQpMax; |
| 4010 expected_streams.push_back(stream); |
| 4011 } |
| 3981 | 4012 |
| 3982 ASSERT_EQ(expected_streams.size(), video_streams.size()); | 4013 ASSERT_EQ(expected_streams.size(), video_streams.size()); |
| 3983 | 4014 |
| 3984 size_t num_streams = video_streams.size(); | 4015 size_t num_streams = video_streams.size(); |
| 3985 int total_max_bitrate_bps = 0; | 4016 int total_max_bitrate_bps = 0; |
| 3986 for (size_t i = 0; i < num_streams; ++i) { | 4017 for (size_t i = 0; i < num_streams; ++i) { |
| 3987 EXPECT_EQ(expected_streams[i].width, video_streams[i].width); | 4018 EXPECT_EQ(expected_streams[i].width, video_streams[i].width); |
| 3988 EXPECT_EQ(expected_streams[i].height, video_streams[i].height); | 4019 EXPECT_EQ(expected_streams[i].height, video_streams[i].height); |
| 3989 | 4020 |
| 3990 EXPECT_GT(video_streams[i].max_framerate, 0); | 4021 EXPECT_GT(video_streams[i].max_framerate, 0); |
| 3991 EXPECT_EQ(expected_streams[i].max_framerate, | 4022 EXPECT_EQ(expected_streams[i].max_framerate, |
| 3992 video_streams[i].max_framerate); | 4023 video_streams[i].max_framerate); |
| 3993 | 4024 |
| 3994 EXPECT_GT(video_streams[i].min_bitrate_bps, 0); | 4025 EXPECT_GT(video_streams[i].min_bitrate_bps, 0); |
| 3995 EXPECT_EQ(expected_streams[i].min_bitrate_bps, | 4026 EXPECT_EQ(expected_streams[i].min_bitrate_bps, |
| 3996 video_streams[i].min_bitrate_bps); | 4027 video_streams[i].min_bitrate_bps); |
| 3997 | 4028 |
| 3998 EXPECT_GT(video_streams[i].target_bitrate_bps, 0); | 4029 EXPECT_GT(video_streams[i].target_bitrate_bps, 0); |
| 3999 EXPECT_EQ(expected_streams[i].target_bitrate_bps, | 4030 EXPECT_EQ(expected_streams[i].target_bitrate_bps, |
| 4000 video_streams[i].target_bitrate_bps); | 4031 video_streams[i].target_bitrate_bps); |
| 4001 | 4032 |
| 4002 EXPECT_GT(video_streams[i].max_bitrate_bps, 0); | 4033 EXPECT_GT(video_streams[i].max_bitrate_bps, 0); |
| 4003 EXPECT_EQ(expected_streams[i].max_bitrate_bps, | 4034 EXPECT_EQ(expected_streams[i].max_bitrate_bps, |
| 4004 video_streams[i].max_bitrate_bps); | 4035 video_streams[i].max_bitrate_bps); |
| 4005 | 4036 |
| 4006 EXPECT_GT(video_streams[i].max_qp, 0); | 4037 EXPECT_GT(video_streams[i].max_qp, 0); |
| 4007 EXPECT_EQ(expected_streams[i].max_qp, video_streams[i].max_qp); | 4038 EXPECT_EQ(expected_streams[i].max_qp, video_streams[i].max_qp); |
| 4008 | 4039 |
| 4009 EXPECT_FALSE(expected_streams[i].temporal_layer_thresholds_bps.empty()); | 4040 EXPECT_EQ(!conference_mode, |
| 4041 expected_streams[i].temporal_layer_thresholds_bps.empty()); |
| 4010 EXPECT_EQ(expected_streams[i].temporal_layer_thresholds_bps, | 4042 EXPECT_EQ(expected_streams[i].temporal_layer_thresholds_bps, |
| 4011 video_streams[i].temporal_layer_thresholds_bps); | 4043 video_streams[i].temporal_layer_thresholds_bps); |
| 4012 | 4044 |
| 4013 if (i == num_streams - 1) { | 4045 if (i == num_streams - 1) { |
| 4014 total_max_bitrate_bps += video_streams[i].max_bitrate_bps; | 4046 total_max_bitrate_bps += video_streams[i].max_bitrate_bps; |
| 4015 } else { | 4047 } else { |
| 4016 total_max_bitrate_bps += video_streams[i].target_bitrate_bps; | 4048 total_max_bitrate_bps += video_streams[i].target_bitrate_bps; |
| 4017 } | 4049 } |
| 4018 } | 4050 } |
| 4019 | 4051 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4053 } | 4085 } |
| 4054 | 4086 |
| 4055 webrtc::RtcEventLogNullImpl event_log_; | 4087 webrtc::RtcEventLogNullImpl event_log_; |
| 4056 FakeCall fake_call_; | 4088 FakeCall fake_call_; |
| 4057 WebRtcVideoEngine2 engine_; | 4089 WebRtcVideoEngine2 engine_; |
| 4058 std::unique_ptr<VideoMediaChannel> channel_; | 4090 std::unique_ptr<VideoMediaChannel> channel_; |
| 4059 uint32_t last_ssrc_; | 4091 uint32_t last_ssrc_; |
| 4060 }; | 4092 }; |
| 4061 | 4093 |
| 4062 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsWith2SimulcastStreams) { | 4094 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsWith2SimulcastStreams) { |
| 4063 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 640, 360, 2, 2); | 4095 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 640, 360, 2, 2, false, |
| 4096 true); |
| 4064 } | 4097 } |
| 4065 | 4098 |
| 4066 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsWith3SimulcastStreams) { | 4099 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsWith3SimulcastStreams) { |
| 4067 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 3); | 4100 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 3, false, |
| 4101 true); |
| 4068 } | 4102 } |
| 4069 | 4103 |
| 4070 // Test that we normalize send codec format size in simulcast. | 4104 // Test that we normalize send codec format size in simulcast. |
| 4071 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsWithOddSizeInSimulcast) { | 4105 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsWithOddSizeInSimulcast) { |
| 4072 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 541, 271, 2, 2); | 4106 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 541, 271, 2, 2, false, |
| 4107 true); |
| 4073 } | 4108 } |
| 4109 |
| 4110 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsForScreenshare) { |
| 4111 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 1, true, |
| 4112 false); |
| 4113 } |
| 4114 |
| 4115 TEST_F(WebRtcVideoChannel2SimulcastTest, |
| 4116 SetSendCodecsForConferenceModeScreenshare) { |
| 4117 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 1, true, |
| 4118 true); |
| 4119 } |
| 4120 |
| 4121 TEST_F(WebRtcVideoChannel2SimulcastTest, SetSendCodecsForSimulcastScreenshare) { |
| 4122 webrtc::test::ScopedFieldTrials override_field_trials_( |
| 4123 "WebRTC-SimulcastScreenshare/Enabled/"); |
| 4124 VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 2, true, |
| 4125 true); |
| 4126 } |
| 4127 |
| 4074 } // namespace cricket | 4128 } // namespace cricket |
| OLD | NEW |