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