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