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