pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1 | /* |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 2 | * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3 | * |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 11 | #include <algorithm> |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 12 | #include <map> |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 13 | #include <memory> |
Steve Anton | e78bcb9 | 2017-10-31 09:53:08 -0700 | [diff] [blame] | 14 | #include <utility> |
pbos@webrtc.org | 86f613d | 2014-06-10 08:53:05 +0000 | [diff] [blame] | 15 | #include <vector> |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 16 | |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 17 | #include "api/rtpparameters.h" |
Emircan Uysaler | dbcac7f | 2017-10-30 23:10:12 -0700 | [diff] [blame] | 18 | #include "api/test/mock_video_decoder_factory.h" |
| 19 | #include "api/test/mock_video_encoder_factory.h" |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 20 | #include "api/video_codecs/builtin_video_decoder_factory.h" |
| 21 | #include "api/video_codecs/builtin_video_encoder_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 22 | #include "api/video_codecs/sdp_video_format.h" |
| 23 | #include "api/video_codecs/video_decoder_factory.h" |
| 24 | #include "api/video_codecs/video_encoder.h" |
| 25 | #include "api/video_codecs/video_encoder_factory.h" |
| 26 | #include "call/flexfec_receive_stream.h" |
| 27 | #include "common_video/h264/profile_level_id.h" |
| 28 | #include "logging/rtc_event_log/rtc_event_log.h" |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 29 | #include "media/base/fakenetworkinterface.h" |
| 30 | #include "media/base/fakevideocapturer.h" |
| 31 | #include "media/base/fakevideorenderer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 32 | #include "media/base/mediaconstants.h" |
| 33 | #include "media/base/rtputils.h" |
| 34 | #include "media/base/testutils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 35 | #include "media/engine/constants.h" |
| 36 | #include "media/engine/fakewebrtccall.h" |
| 37 | #include "media/engine/fakewebrtcvideoengine.h" |
| 38 | #include "media/engine/simulcast.h" |
| 39 | #include "media/engine/webrtcvideoengine.h" |
| 40 | #include "media/engine/webrtcvoiceengine.h" |
| 41 | #include "rtc_base/arraysize.h" |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 42 | #include "rtc_base/numerics/safe_conversions.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 43 | #include "rtc_base/gunit.h" |
| 44 | #include "rtc_base/stringutils.h" |
| 45 | #include "test/field_trial.h" |
| 46 | #include "test/gmock.h" |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 47 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 48 | using cricket::FakeVideoCapturerWithTaskQueue; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 49 | using webrtc::BitrateConstraints; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 50 | using webrtc::RtpExtension; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 51 | using testing::Field; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 52 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 53 | namespace { |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 54 | static const int kDefaultQpMax = 56; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 55 | |
noahric | d10a68e | 2015-07-10 11:27:55 -0700 | [diff] [blame] | 56 | static const uint8_t kRedRtxPayloadType = 125; |
| 57 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 58 | static const uint32_t kTimeout = 5000U; |
| 59 | static const uint32_t kDefaultReceiveSsrc = 0; |
| 60 | static const uint32_t kSsrc = 1234u; |
| 61 | static const uint32_t kSsrcs4[] = {1, 2, 3, 4}; |
| 62 | static const int kVideoWidth = 640; |
| 63 | static const int kVideoHeight = 360; |
| 64 | static const int kFramerate = 30; |
| 65 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 66 | static const uint32_t kSsrcs1[] = {1}; |
| 67 | static const uint32_t kSsrcs3[] = {1, 2, 3}; |
| 68 | static const uint32_t kRtxSsrcs1[] = {4}; |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 69 | static const uint32_t kFlexfecSsrc = 5; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 70 | static const uint32_t kIncomingUnsignalledSsrc = 0xC0FFEE; |
mzanaty | 8a855d6 | 2017-02-17 15:46:43 -0800 | [diff] [blame] | 71 | static const uint32_t kDefaultRecvSsrc = 0; |
| 72 | |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 73 | static const char kUnsupportedExtensionName[] = |
| 74 | "urn:ietf:params:rtp-hdrext:unsupported"; |
pbos@webrtc.org | f99c2f2 | 2014-06-13 12:27:38 +0000 | [diff] [blame] | 75 | |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 76 | cricket::VideoCodec RemoveFeedbackParams(cricket::VideoCodec&& codec) { |
| 77 | codec.feedback_params = cricket::FeedbackParams(); |
Mirko Bonadei | 29a8d10 | 2018-04-25 23:58:26 +0200 | [diff] [blame] | 78 | return std::move(codec); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 79 | } |
| 80 | |
pbos@webrtc.org | f99c2f2 | 2014-06-13 12:27:38 +0000 | [diff] [blame] | 81 | void VerifyCodecHasDefaultFeedbackParams(const cricket::VideoCodec& codec) { |
| 82 | EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( |
| 83 | cricket::kRtcpFbParamNack, cricket::kParamValueEmpty))); |
| 84 | EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( |
| 85 | cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli))); |
| 86 | EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( |
| 87 | cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty))); |
| 88 | EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( |
stefan | 43edf0f | 2015-11-20 18:05:48 -0800 | [diff] [blame] | 89 | cricket::kRtcpFbParamTransportCc, cricket::kParamValueEmpty))); |
| 90 | EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( |
pbos@webrtc.org | f99c2f2 | 2014-06-13 12:27:38 +0000 | [diff] [blame] | 91 | cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir))); |
| 92 | } |
| 93 | |
magjed | 725e484 | 2016-11-16 00:48:13 -0800 | [diff] [blame] | 94 | // Return true if any codec in |codecs| is an RTX codec with associated payload |
| 95 | // type |payload_type|. |
| 96 | bool HasRtxCodec(const std::vector<cricket::VideoCodec>& codecs, |
| 97 | int payload_type) { |
| 98 | for (const cricket::VideoCodec& codec : codecs) { |
| 99 | int associated_payload_type; |
| 100 | if (cricket::CodecNamesEq(codec.name.c_str(), "rtx") && |
| 101 | codec.GetParam(cricket::kCodecParamAssociatedPayloadType, |
| 102 | &associated_payload_type) && |
| 103 | associated_payload_type == payload_type) { |
| 104 | return true; |
| 105 | } |
| 106 | } |
| 107 | return false; |
| 108 | } |
| 109 | |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 110 | // TODO(nisse): Duplicated in call.cc. |
| 111 | const int* FindKeyByValue(const std::map<int, int>& m, int v) { |
| 112 | for (const auto& kv : m) { |
| 113 | if (kv.second == v) |
| 114 | return &kv.first; |
| 115 | } |
| 116 | return nullptr; |
| 117 | } |
| 118 | |
| 119 | bool HasRtxReceiveAssociation( |
| 120 | const webrtc::VideoReceiveStream::Config& config, |
| 121 | int payload_type) { |
| 122 | return FindKeyByValue(config.rtp.rtx_associated_payload_types, |
| 123 | payload_type) != nullptr; |
| 124 | } |
| 125 | |
| 126 | // Check that there's an Rtx payload type for each decoder. |
| 127 | bool VerifyRtxReceiveAssociations( |
| 128 | const webrtc::VideoReceiveStream::Config& config) { |
| 129 | for (const auto& decoder : config.decoders) { |
| 130 | if (!HasRtxReceiveAssociation(config, decoder.payload_type)) |
| 131 | return false; |
| 132 | } |
| 133 | return true; |
| 134 | } |
| 135 | |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 136 | rtc::scoped_refptr<webrtc::VideoFrameBuffer> CreateBlackFrameBuffer( |
nisse | 64ec8f8 | 2016-09-27 00:17:25 -0700 | [diff] [blame] | 137 | int width, |
| 138 | int height) { |
| 139 | rtc::scoped_refptr<webrtc::I420Buffer> buffer = |
| 140 | webrtc::I420Buffer::Create(width, height); |
nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 141 | webrtc::I420Buffer::SetBlack(buffer); |
nisse | 64ec8f8 | 2016-09-27 00:17:25 -0700 | [diff] [blame] | 142 | return buffer; |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 143 | } |
| 144 | |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 145 | void VerifySendStreamHasRtxTypes(const webrtc::VideoSendStream::Config& config, |
| 146 | const std::map<int, int>& rtx_types) { |
| 147 | std::map<int, int>::const_iterator it; |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 148 | it = rtx_types.find(config.rtp.payload_type); |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 149 | EXPECT_TRUE(it != rtx_types.end() && |
| 150 | it->second == config.rtp.rtx.payload_type); |
| 151 | |
brandtr | b5f2c3f | 2016-10-04 23:28:39 -0700 | [diff] [blame] | 152 | if (config.rtp.ulpfec.red_rtx_payload_type != -1) { |
| 153 | it = rtx_types.find(config.rtp.ulpfec.red_payload_type); |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 154 | EXPECT_TRUE(it != rtx_types.end() && |
brandtr | b5f2c3f | 2016-10-04 23:28:39 -0700 | [diff] [blame] | 155 | it->second == config.rtp.ulpfec.red_rtx_payload_type); |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 156 | } |
| 157 | } |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 158 | |
| 159 | cricket::MediaConfig GetMediaConfig() { |
| 160 | cricket::MediaConfig media_config; |
Niels Möller | 1d7ecd2 | 2018-01-18 15:25:12 +0100 | [diff] [blame] | 161 | media_config.video.enable_cpu_adaptation = false; |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 162 | return media_config; |
| 163 | } |
nisse | 26e3abb | 2017-08-25 04:44:25 -0700 | [diff] [blame] | 164 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 165 | } // namespace |
| 166 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 167 | #define EXPECT_FRAME_WAIT(c, w, h, t) \ |
| 168 | EXPECT_EQ_WAIT((c), renderer_.num_rendered_frames(), (t)); \ |
| 169 | EXPECT_EQ((w), renderer_.width()); \ |
| 170 | EXPECT_EQ((h), renderer_.height()); \ |
| 171 | EXPECT_EQ(0, renderer_.errors()); |
| 172 | |
| 173 | #define EXPECT_FRAME_ON_RENDERER_WAIT(r, c, w, h, t) \ |
| 174 | EXPECT_EQ_WAIT((c), (r).num_rendered_frames(), (t)); \ |
| 175 | EXPECT_EQ((w), (r).width()); \ |
| 176 | EXPECT_EQ((h), (r).height()); \ |
| 177 | EXPECT_EQ(0, (r).errors()); |
| 178 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 179 | namespace cricket { |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 180 | class WebRtcVideoEngineTest : public ::testing::Test { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 181 | public: |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 182 | WebRtcVideoEngineTest() : WebRtcVideoEngineTest("") {} |
| 183 | explicit WebRtcVideoEngineTest(const char* field_trials) |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 184 | : override_field_trials_(field_trials), |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 185 | call_(webrtc::Call::Create(webrtc::Call::Config(&event_log_))), |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 186 | encoder_factory_(new cricket::FakeWebRtcVideoEncoderFactory), |
| 187 | decoder_factory_(new cricket::FakeWebRtcVideoDecoderFactory), |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 188 | engine_(std::unique_ptr<cricket::FakeWebRtcVideoEncoderFactory>( |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 189 | encoder_factory_), |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 190 | std::unique_ptr<cricket::FakeWebRtcVideoDecoderFactory>( |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 191 | decoder_factory_)) {} |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 192 | |
| 193 | protected: |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 194 | void AssignDefaultAptRtxTypes(); |
| 195 | void AssignDefaultCodec(); |
| 196 | |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 197 | // Find the index of the codec in the engine with the given name. The codec |
| 198 | // must be present. |
Oleh Prypin | a40f824 | 2017-12-21 13:32:23 +0100 | [diff] [blame] | 199 | size_t GetEngineCodecIndex(const std::string& name) const; |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 200 | |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 201 | // Find the codec in the engine with the given name. The codec must be |
| 202 | // present. |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 203 | cricket::VideoCodec GetEngineCodec(const std::string& name) const; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 204 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 205 | VideoMediaChannel* SetSendParamsWithAllSupportedCodecs(); |
pbos@webrtc.org | fa553ef | 2014-10-20 11:07:07 +0000 | [diff] [blame] | 206 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 207 | VideoMediaChannel* SetRecvParamsWithSupportedCodecs( |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 208 | const std::vector<VideoCodec>& codecs); |
| 209 | |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 210 | void TestExtendedEncoderOveruse(bool use_external_encoder); |
| 211 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 212 | webrtc::test::ScopedFieldTrials override_field_trials_; |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 213 | webrtc::RtcEventLogNullImpl event_log_; |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 214 | // Used in WebRtcVideoEngineVoiceTest, but defined here so it's properly |
pbos@webrtc.org | f1f0d9a | 2015-03-02 13:30:15 +0000 | [diff] [blame] | 215 | // initialized when the constructor is called. |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 216 | std::unique_ptr<webrtc::Call> call_; |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 217 | cricket::FakeWebRtcVideoEncoderFactory* encoder_factory_; |
| 218 | cricket::FakeWebRtcVideoDecoderFactory* decoder_factory_; |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 219 | WebRtcVideoEngine engine_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 220 | VideoCodec default_codec_; |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 221 | std::map<int, int> default_apt_rtx_types_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 222 | }; |
| 223 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 224 | TEST_F(WebRtcVideoEngineTest, DefaultRtxCodecHasAssociatedPayloadTypeSet) { |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 225 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
| 226 | AssignDefaultCodec(); |
| 227 | |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 228 | std::vector<VideoCodec> engine_codecs = engine_.codecs(); |
| 229 | for (size_t i = 0; i < engine_codecs.size(); ++i) { |
| 230 | if (engine_codecs[i].name != kRtxCodecName) |
| 231 | continue; |
| 232 | int associated_payload_type; |
| 233 | EXPECT_TRUE(engine_codecs[i].GetParam(kCodecParamAssociatedPayloadType, |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 234 | &associated_payload_type)); |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 235 | EXPECT_EQ(default_codec_.id, associated_payload_type); |
| 236 | return; |
| 237 | } |
| 238 | FAIL() << "No RTX codec found among default codecs."; |
| 239 | } |
| 240 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 241 | TEST_F(WebRtcVideoEngineTest, SupportsTimestampOffsetHeaderExtension) { |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 242 | RtpCapabilities capabilities = engine_.GetCapabilities(); |
| 243 | ASSERT_FALSE(capabilities.header_extensions.empty()); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 244 | for (const RtpExtension& extension : capabilities.header_extensions) { |
| 245 | if (extension.uri == RtpExtension::kTimestampOffsetUri) { |
| 246 | EXPECT_EQ(RtpExtension::kTimestampOffsetDefaultId, extension.id); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 247 | return; |
| 248 | } |
| 249 | } |
| 250 | FAIL() << "Timestamp offset extension not in header-extension list."; |
| 251 | } |
| 252 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 253 | TEST_F(WebRtcVideoEngineTest, SupportsAbsoluteSenderTimeHeaderExtension) { |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 254 | RtpCapabilities capabilities = engine_.GetCapabilities(); |
| 255 | ASSERT_FALSE(capabilities.header_extensions.empty()); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 256 | for (const RtpExtension& extension : capabilities.header_extensions) { |
| 257 | if (extension.uri == RtpExtension::kAbsSendTimeUri) { |
| 258 | EXPECT_EQ(RtpExtension::kAbsSendTimeDefaultId, extension.id); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 259 | return; |
| 260 | } |
| 261 | } |
| 262 | FAIL() << "Absolute Sender Time extension not in header-extension list."; |
| 263 | } |
| 264 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 265 | TEST_F(WebRtcVideoEngineTest, SupportsTransportSequenceNumberHeaderExtension) { |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 266 | RtpCapabilities capabilities = engine_.GetCapabilities(); |
| 267 | ASSERT_FALSE(capabilities.header_extensions.empty()); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 268 | for (const RtpExtension& extension : capabilities.header_extensions) { |
| 269 | if (extension.uri == RtpExtension::kTransportSequenceNumberUri) { |
| 270 | EXPECT_EQ(RtpExtension::kTransportSequenceNumberDefaultId, extension.id); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 271 | return; |
| 272 | } |
| 273 | } |
| 274 | FAIL() << "Transport sequence number extension not in header-extension list."; |
| 275 | } |
| 276 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 277 | TEST_F(WebRtcVideoEngineTest, SupportsVideoRotationHeaderExtension) { |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 278 | RtpCapabilities capabilities = engine_.GetCapabilities(); |
| 279 | ASSERT_FALSE(capabilities.header_extensions.empty()); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 280 | for (const RtpExtension& extension : capabilities.header_extensions) { |
| 281 | if (extension.uri == RtpExtension::kVideoRotationUri) { |
| 282 | EXPECT_EQ(RtpExtension::kVideoRotationDefaultId, extension.id); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 283 | return; |
| 284 | } |
| 285 | } |
| 286 | FAIL() << "Video Rotation extension not in header-extension list."; |
| 287 | } |
| 288 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 289 | TEST_F(WebRtcVideoEngineTest, CVOSetHeaderExtensionBeforeCapturer) { |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 290 | // Allocate the capturer first to prevent early destruction before channel's |
| 291 | // dtor is called. |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 292 | FakeVideoCapturerWithTaskQueue capturer; |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 293 | |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 294 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 295 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 296 | std::unique_ptr<VideoMediaChannel> channel( |
| 297 | SetSendParamsWithAllSupportedCodecs()); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 298 | EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(kSsrc))); |
| 299 | |
| 300 | // Add CVO extension. |
| 301 | const int id = 1; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 302 | cricket::VideoSendParameters parameters; |
| 303 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 304 | parameters.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 305 | RtpExtension(RtpExtension::kVideoRotationUri, id)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 306 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 307 | |
| 308 | // Set capturer. |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 309 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, nullptr, &capturer)); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 310 | |
| 311 | // Verify capturer has turned off applying rotation. |
nisse | 47ac462 | 2016-05-25 08:47:01 -0700 | [diff] [blame] | 312 | EXPECT_FALSE(capturer.apply_rotation()); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 313 | |
| 314 | // Verify removing header extension turns on applying rotation. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 315 | parameters.extensions.clear(); |
| 316 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
nisse | 47ac462 | 2016-05-25 08:47:01 -0700 | [diff] [blame] | 317 | EXPECT_TRUE(capturer.apply_rotation()); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 318 | } |
| 319 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 320 | TEST_F(WebRtcVideoEngineTest, CVOSetHeaderExtensionBeforeAddSendStream) { |
perkj | 91e1c15 | 2016-03-02 05:34:00 -0800 | [diff] [blame] | 321 | // Allocate the capturer first to prevent early destruction before channel's |
| 322 | // dtor is called. |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 323 | FakeVideoCapturerWithTaskQueue capturer; |
perkj | 91e1c15 | 2016-03-02 05:34:00 -0800 | [diff] [blame] | 324 | |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 325 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
perkj | 91e1c15 | 2016-03-02 05:34:00 -0800 | [diff] [blame] | 326 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 327 | std::unique_ptr<VideoMediaChannel> channel( |
| 328 | SetSendParamsWithAllSupportedCodecs()); |
perkj | 91e1c15 | 2016-03-02 05:34:00 -0800 | [diff] [blame] | 329 | // Add CVO extension. |
| 330 | const int id = 1; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 331 | cricket::VideoSendParameters parameters; |
| 332 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
perkj | 91e1c15 | 2016-03-02 05:34:00 -0800 | [diff] [blame] | 333 | parameters.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 334 | RtpExtension(RtpExtension::kVideoRotationUri, id)); |
perkj | 91e1c15 | 2016-03-02 05:34:00 -0800 | [diff] [blame] | 335 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
| 336 | EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(kSsrc))); |
| 337 | |
| 338 | // Set capturer. |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 339 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, nullptr, &capturer)); |
perkj | 91e1c15 | 2016-03-02 05:34:00 -0800 | [diff] [blame] | 340 | |
| 341 | // Verify capturer has turned off applying rotation. |
nisse | 47ac462 | 2016-05-25 08:47:01 -0700 | [diff] [blame] | 342 | EXPECT_FALSE(capturer.apply_rotation()); |
perkj | 91e1c15 | 2016-03-02 05:34:00 -0800 | [diff] [blame] | 343 | } |
| 344 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 345 | TEST_F(WebRtcVideoEngineTest, CVOSetHeaderExtensionAfterCapturer) { |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 346 | FakeVideoCapturerWithTaskQueue capturer; |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 347 | |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 348 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
| 349 | encoder_factory_->AddSupportedVideoCodecType("VP9"); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 350 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 351 | std::unique_ptr<VideoMediaChannel> channel( |
| 352 | SetSendParamsWithAllSupportedCodecs()); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 353 | EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(kSsrc))); |
| 354 | |
| 355 | // Set capturer. |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 356 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, nullptr, &capturer)); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 357 | |
perkj | caafdba | 2016-03-20 07:34:29 -0700 | [diff] [blame] | 358 | // Verify capturer has turned on applying rotation. |
nisse | 47ac462 | 2016-05-25 08:47:01 -0700 | [diff] [blame] | 359 | EXPECT_TRUE(capturer.apply_rotation()); |
perkj | caafdba | 2016-03-20 07:34:29 -0700 | [diff] [blame] | 360 | |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 361 | // Add CVO extension. |
| 362 | const int id = 1; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 363 | cricket::VideoSendParameters parameters; |
| 364 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 365 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 366 | parameters.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 367 | RtpExtension(RtpExtension::kVideoRotationUri, id)); |
perkj | caafdba | 2016-03-20 07:34:29 -0700 | [diff] [blame] | 368 | // Also remove the first codec to trigger a codec change as well. |
| 369 | parameters.codecs.erase(parameters.codecs.begin()); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 370 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 371 | |
| 372 | // Verify capturer has turned off applying rotation. |
nisse | 47ac462 | 2016-05-25 08:47:01 -0700 | [diff] [blame] | 373 | EXPECT_FALSE(capturer.apply_rotation()); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 374 | |
| 375 | // Verify removing header extension turns on applying rotation. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 376 | parameters.extensions.clear(); |
| 377 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
nisse | 47ac462 | 2016-05-25 08:47:01 -0700 | [diff] [blame] | 378 | EXPECT_TRUE(capturer.apply_rotation()); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 379 | } |
| 380 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 381 | TEST_F(WebRtcVideoEngineTest, SetSendFailsBeforeSettingCodecs) { |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 382 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
| 383 | |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 384 | std::unique_ptr<VideoMediaChannel> channel( |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 385 | engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions())); |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 386 | |
| 387 | EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(123))); |
| 388 | |
| 389 | EXPECT_FALSE(channel->SetSend(true)) |
| 390 | << "Channel should not start without codecs."; |
| 391 | EXPECT_TRUE(channel->SetSend(false)) |
| 392 | << "Channel should be stoppable even without set codecs."; |
| 393 | } |
| 394 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 395 | TEST_F(WebRtcVideoEngineTest, GetStatsWithoutSendCodecsSetDoesNotCrash) { |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 396 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
| 397 | |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 398 | std::unique_ptr<VideoMediaChannel> channel( |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 399 | engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions())); |
pbos@webrtc.org | c3d2bd2 | 2014-08-12 20:55:10 +0000 | [diff] [blame] | 400 | EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(123))); |
| 401 | VideoMediaInfo info; |
| 402 | channel->GetStats(&info); |
| 403 | } |
| 404 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 405 | TEST_F(WebRtcVideoEngineTest, UseFactoryForVp8WhenSupported) { |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 406 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 407 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 408 | std::unique_ptr<VideoMediaChannel> channel( |
| 409 | SetSendParamsWithAllSupportedCodecs()); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 410 | channel->OnReadyToSend(true); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 411 | |
| 412 | EXPECT_TRUE( |
| 413 | channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 414 | EXPECT_EQ(0, encoder_factory_->GetNumCreatedEncoders()); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 415 | EXPECT_TRUE(channel->SetSend(true)); |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 416 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 417 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, nullptr, &capturer)); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 418 | EXPECT_EQ(cricket::CS_RUNNING, |
| 419 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 420 | EXPECT_TRUE(capturer.CaptureFrame()); |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 421 | // Sending one frame will have allocate the encoder. |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 422 | ASSERT_TRUE(encoder_factory_->WaitForCreatedVideoEncoders(1)); |
| 423 | EXPECT_TRUE_WAIT(encoder_factory_->encoders()[0]->GetNumEncodedFrames() > 0, |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 424 | kTimeout); |
| 425 | |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 426 | int num_created_encoders = encoder_factory_->GetNumCreatedEncoders(); |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 427 | EXPECT_EQ(num_created_encoders, 1); |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 428 | |
| 429 | // Setting codecs of the same type should not reallocate any encoders |
| 430 | // (expecting a no-op). |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 431 | cricket::VideoSendParameters parameters; |
| 432 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 433 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 434 | EXPECT_EQ(num_created_encoders, encoder_factory_->GetNumCreatedEncoders()); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 435 | |
| 436 | // Remove stream previously added to free the external encoder instance. |
| 437 | EXPECT_TRUE(channel->RemoveSendStream(kSsrc)); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 438 | EXPECT_EQ(0u, encoder_factory_->encoders().size()); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 439 | } |
| 440 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 441 | // Test that when an encoder factory supports H264, we add an RTX |
| 442 | // codec for it. |
| 443 | // TODO(deadbeef): This test should be updated if/when we start |
| 444 | // adding RTX codecs for unrecognized codec names. |
| 445 | TEST_F(WebRtcVideoEngineTest, RtxCodecAddedForH264Codec) { |
magjed | 725e484 | 2016-11-16 00:48:13 -0800 | [diff] [blame] | 446 | using webrtc::H264::ProfileLevelIdToString; |
| 447 | using webrtc::H264::ProfileLevelId; |
| 448 | using webrtc::H264::kLevel1; |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 449 | webrtc::SdpVideoFormat h264_constrained_baseline("H264"); |
| 450 | h264_constrained_baseline.parameters[kH264FmtpProfileLevelId] = |
magjed | 725e484 | 2016-11-16 00:48:13 -0800 | [diff] [blame] | 451 | *ProfileLevelIdToString( |
| 452 | ProfileLevelId(webrtc::H264::kProfileConstrainedBaseline, kLevel1)); |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 453 | webrtc::SdpVideoFormat h264_constrained_high("H264"); |
| 454 | h264_constrained_high.parameters[kH264FmtpProfileLevelId] = |
magjed | 725e484 | 2016-11-16 00:48:13 -0800 | [diff] [blame] | 455 | *ProfileLevelIdToString( |
| 456 | ProfileLevelId(webrtc::H264::kProfileConstrainedHigh, kLevel1)); |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 457 | webrtc::SdpVideoFormat h264_high("H264"); |
| 458 | h264_high.parameters[kH264FmtpProfileLevelId] = *ProfileLevelIdToString( |
magjed | 725e484 | 2016-11-16 00:48:13 -0800 | [diff] [blame] | 459 | ProfileLevelId(webrtc::H264::kProfileHigh, kLevel1)); |
| 460 | |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 461 | encoder_factory_->AddSupportedVideoCodec(h264_constrained_baseline); |
| 462 | encoder_factory_->AddSupportedVideoCodec(h264_constrained_high); |
| 463 | encoder_factory_->AddSupportedVideoCodec(h264_high); |
Taylor Brandstetter | 6c3e788 | 2016-06-29 11:14:19 -0700 | [diff] [blame] | 464 | |
magjed | 725e484 | 2016-11-16 00:48:13 -0800 | [diff] [blame] | 465 | // First figure out what payload types the test codecs got assigned. |
| 466 | const std::vector<cricket::VideoCodec> codecs = engine_.codecs(); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 467 | // Now search for RTX codecs for them. Expect that they all have associated |
| 468 | // RTX codecs. |
magjed | 725e484 | 2016-11-16 00:48:13 -0800 | [diff] [blame] | 469 | EXPECT_TRUE(HasRtxCodec( |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 470 | codecs, |
| 471 | FindMatchingCodec(codecs, cricket::VideoCodec(h264_constrained_baseline)) |
| 472 | ->id)); |
magjed | 725e484 | 2016-11-16 00:48:13 -0800 | [diff] [blame] | 473 | EXPECT_TRUE(HasRtxCodec( |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 474 | codecs, |
| 475 | FindMatchingCodec(codecs, cricket::VideoCodec(h264_constrained_high)) |
| 476 | ->id)); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 477 | EXPECT_TRUE(HasRtxCodec( |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 478 | codecs, FindMatchingCodec(codecs, cricket::VideoCodec(h264_high))->id)); |
Taylor Brandstetter | 6c3e788 | 2016-06-29 11:14:19 -0700 | [diff] [blame] | 479 | } |
| 480 | |
Peter Boström | 1299615 | 2016-05-14 02:03:18 +0200 | [diff] [blame] | 481 | #if !defined(RTC_DISABLE_VP9) |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 482 | TEST_F(WebRtcVideoEngineTest, CanConstructDecoderForVp9EncoderFactory) { |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 483 | encoder_factory_->AddSupportedVideoCodecType("VP9"); |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 484 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 485 | std::unique_ptr<VideoMediaChannel> channel( |
| 486 | SetSendParamsWithAllSupportedCodecs()); |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 487 | |
| 488 | EXPECT_TRUE( |
| 489 | channel->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| 490 | } |
Peter Boström | 1299615 | 2016-05-14 02:03:18 +0200 | [diff] [blame] | 491 | #endif // !defined(RTC_DISABLE_VP9) |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 492 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 493 | TEST_F(WebRtcVideoEngineTest, PropagatesInputFrameTimestamp) { |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 494 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 495 | FakeCall* fake_call = new FakeCall(); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 496 | call_.reset(fake_call); |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 497 | std::unique_ptr<VideoMediaChannel> channel( |
| 498 | SetSendParamsWithAllSupportedCodecs()); |
qiangchen | c27d89f | 2015-07-16 10:27:16 -0700 | [diff] [blame] | 499 | |
| 500 | EXPECT_TRUE( |
| 501 | channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| 502 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 503 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 504 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, nullptr, &capturer)); |
qiangchen | c27d89f | 2015-07-16 10:27:16 -0700 | [diff] [blame] | 505 | capturer.Start(cricket::VideoFormat(1280, 720, |
| 506 | cricket::VideoFormat::FpsToInterval(60), |
| 507 | cricket::FOURCC_I420)); |
| 508 | channel->SetSend(true); |
| 509 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 510 | FakeVideoSendStream* stream = fake_call->GetVideoSendStreams()[0]; |
qiangchen | c27d89f | 2015-07-16 10:27:16 -0700 | [diff] [blame] | 511 | |
| 512 | EXPECT_TRUE(capturer.CaptureFrame()); |
pbos | 1cb121d | 2015-09-14 11:38:38 -0700 | [diff] [blame] | 513 | int64_t last_timestamp = stream->GetLastTimestamp(); |
qiangchen | c27d89f | 2015-07-16 10:27:16 -0700 | [diff] [blame] | 514 | for (int i = 0; i < 10; i++) { |
| 515 | EXPECT_TRUE(capturer.CaptureFrame()); |
pbos | 1cb121d | 2015-09-14 11:38:38 -0700 | [diff] [blame] | 516 | int64_t timestamp = stream->GetLastTimestamp(); |
qiangchen | c27d89f | 2015-07-16 10:27:16 -0700 | [diff] [blame] | 517 | int64_t interval = timestamp - last_timestamp; |
| 518 | |
| 519 | // Precision changes from nanosecond to millisecond. |
| 520 | // Allow error to be no more than 1. |
| 521 | EXPECT_NEAR(cricket::VideoFormat::FpsToInterval(60) / 1E6, interval, 1); |
| 522 | |
| 523 | last_timestamp = timestamp; |
| 524 | } |
| 525 | |
| 526 | capturer.Start(cricket::VideoFormat(1280, 720, |
| 527 | cricket::VideoFormat::FpsToInterval(30), |
| 528 | cricket::FOURCC_I420)); |
| 529 | |
| 530 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 531 | last_timestamp = stream->GetLastTimestamp(); |
| 532 | for (int i = 0; i < 10; i++) { |
| 533 | EXPECT_TRUE(capturer.CaptureFrame()); |
pbos | 1cb121d | 2015-09-14 11:38:38 -0700 | [diff] [blame] | 534 | int64_t timestamp = stream->GetLastTimestamp(); |
qiangchen | c27d89f | 2015-07-16 10:27:16 -0700 | [diff] [blame] | 535 | int64_t interval = timestamp - last_timestamp; |
| 536 | |
| 537 | // Precision changes from nanosecond to millisecond. |
| 538 | // Allow error to be no more than 1. |
| 539 | EXPECT_NEAR(cricket::VideoFormat::FpsToInterval(30) / 1E6, interval, 1); |
| 540 | |
| 541 | last_timestamp = timestamp; |
| 542 | } |
| 543 | |
| 544 | // Remove stream previously added to free the external encoder instance. |
| 545 | EXPECT_TRUE(channel->RemoveSendStream(kSsrc)); |
| 546 | } |
| 547 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 548 | void WebRtcVideoEngineTest::AssignDefaultAptRtxTypes() { |
| 549 | std::vector<VideoCodec> engine_codecs = engine_.codecs(); |
| 550 | RTC_DCHECK(!engine_codecs.empty()); |
| 551 | for (const cricket::VideoCodec& codec : engine_codecs) { |
| 552 | if (codec.name == "rtx") { |
| 553 | int associated_payload_type; |
| 554 | if (codec.GetParam(kCodecParamAssociatedPayloadType, |
| 555 | &associated_payload_type)) { |
| 556 | default_apt_rtx_types_[associated_payload_type] = codec.id; |
| 557 | } |
| 558 | } |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | void WebRtcVideoEngineTest::AssignDefaultCodec() { |
| 563 | std::vector<VideoCodec> engine_codecs = engine_.codecs(); |
| 564 | RTC_DCHECK(!engine_codecs.empty()); |
| 565 | bool codec_set = false; |
| 566 | for (const cricket::VideoCodec& codec : engine_codecs) { |
| 567 | if (!codec_set && codec.name != "rtx" && codec.name != "red" && |
| 568 | codec.name != "ulpfec") { |
| 569 | default_codec_ = codec; |
| 570 | codec_set = true; |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | RTC_DCHECK(codec_set); |
| 575 | } |
| 576 | |
Oleh Prypin | a40f824 | 2017-12-21 13:32:23 +0100 | [diff] [blame] | 577 | size_t WebRtcVideoEngineTest::GetEngineCodecIndex( |
| 578 | const std::string& name) const { |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 579 | const std::vector<cricket::VideoCodec> codecs = engine_.codecs(); |
| 580 | for (size_t i = 0; i < codecs.size(); ++i) { |
| 581 | const cricket::VideoCodec engine_codec = codecs[i]; |
Magnus Jedvert | 8deb818 | 2017-10-05 13:13:32 +0200 | [diff] [blame] | 582 | if (!CodecNamesEq(name, engine_codec.name)) |
| 583 | continue; |
| 584 | // The tests only use H264 Constrained Baseline. Make sure we don't return |
| 585 | // an internal H264 codec from the engine with a different H264 profile. |
| 586 | if (CodecNamesEq(name.c_str(), kH264CodecName)) { |
| 587 | const rtc::Optional<webrtc::H264::ProfileLevelId> profile_level_id = |
| 588 | webrtc::H264::ParseSdpProfileLevelId(engine_codec.params); |
| 589 | if (profile_level_id->profile != |
| 590 | webrtc::H264::kProfileConstrainedBaseline) { |
| 591 | continue; |
| 592 | } |
| 593 | } |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 594 | return i; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 595 | } |
| 596 | // This point should never be reached. |
| 597 | ADD_FAILURE() << "Unrecognized codec name: " << name; |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 598 | return -1; |
| 599 | } |
| 600 | |
| 601 | cricket::VideoCodec WebRtcVideoEngineTest::GetEngineCodec( |
| 602 | const std::string& name) const { |
| 603 | return engine_.codecs()[GetEngineCodecIndex(name)]; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 604 | } |
| 605 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 606 | VideoMediaChannel* |
| 607 | WebRtcVideoEngineTest::SetSendParamsWithAllSupportedCodecs() { |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 608 | VideoMediaChannel* channel = |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 609 | engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions()); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 610 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 611 | // We need to look up the codec in the engine to get the correct payload type. |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 612 | for (const webrtc::SdpVideoFormat& format : |
| 613 | encoder_factory_->GetSupportedFormats()) { |
| 614 | cricket::VideoCodec engine_codec = GetEngineCodec(format.name); |
| 615 | if (std::find(parameters.codecs.begin(), parameters.codecs.end(), |
| 616 | engine_codec) == parameters.codecs.end()) { |
| 617 | parameters.codecs.push_back(engine_codec); |
| 618 | } |
| 619 | } |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 620 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 621 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 622 | |
| 623 | return channel; |
| 624 | } |
| 625 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 626 | VideoMediaChannel* WebRtcVideoEngineTest::SetRecvParamsWithSupportedCodecs( |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 627 | const std::vector<VideoCodec>& codecs) { |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 628 | VideoMediaChannel* channel = |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 629 | engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions()); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 630 | cricket::VideoRecvParameters parameters; |
| 631 | parameters.codecs = codecs; |
| 632 | EXPECT_TRUE(channel->SetRecvParameters(parameters)); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 633 | |
| 634 | return channel; |
| 635 | } |
| 636 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 637 | TEST_F(WebRtcVideoEngineTest, UsesSimulcastAdapterForVp8Factories) { |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 638 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
pbos@webrtc.org | f18fba2 | 2015-01-14 16:26:23 +0000 | [diff] [blame] | 639 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 640 | std::unique_ptr<VideoMediaChannel> channel( |
| 641 | SetSendParamsWithAllSupportedCodecs()); |
pbos@webrtc.org | f18fba2 | 2015-01-14 16:26:23 +0000 | [diff] [blame] | 642 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 643 | std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); |
pbos@webrtc.org | f18fba2 | 2015-01-14 16:26:23 +0000 | [diff] [blame] | 644 | |
| 645 | EXPECT_TRUE( |
| 646 | channel->AddSendStream(CreateSimStreamParams("cname", ssrcs))); |
| 647 | EXPECT_TRUE(channel->SetSend(true)); |
| 648 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 649 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 650 | EXPECT_TRUE(channel->SetVideoSend(ssrcs.front(), nullptr, &capturer)); |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 651 | EXPECT_EQ(cricket::CS_RUNNING, |
| 652 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 653 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 654 | |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 655 | ASSERT_TRUE(encoder_factory_->WaitForCreatedVideoEncoders(2)); |
pbos@webrtc.org | f18fba2 | 2015-01-14 16:26:23 +0000 | [diff] [blame] | 656 | |
| 657 | // Verify that encoders are configured for simulcast through adapter |
| 658 | // (increasing resolution and only configured to send one stream each). |
| 659 | int prev_width = -1; |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 660 | for (size_t i = 0; i < encoder_factory_->encoders().size(); ++i) { |
| 661 | ASSERT_TRUE(encoder_factory_->encoders()[i]->WaitForInitEncode()); |
pbos@webrtc.org | f18fba2 | 2015-01-14 16:26:23 +0000 | [diff] [blame] | 662 | webrtc::VideoCodec codec_settings = |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 663 | encoder_factory_->encoders()[i]->GetCodecSettings(); |
pbos@webrtc.org | f18fba2 | 2015-01-14 16:26:23 +0000 | [diff] [blame] | 664 | EXPECT_EQ(0, codec_settings.numberOfSimulcastStreams); |
| 665 | EXPECT_GT(codec_settings.width, prev_width); |
| 666 | prev_width = codec_settings.width; |
| 667 | } |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 668 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 669 | EXPECT_TRUE(channel->SetVideoSend(ssrcs.front(), nullptr, nullptr)); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 670 | |
| 671 | channel.reset(); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 672 | ASSERT_EQ(0u, encoder_factory_->encoders().size()); |
pbos@webrtc.org | f18fba2 | 2015-01-14 16:26:23 +0000 | [diff] [blame] | 673 | } |
| 674 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 675 | TEST_F(WebRtcVideoEngineTest, ChannelWithH264CanChangeToVp8) { |
| 676 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 677 | encoder_factory_->AddSupportedVideoCodecType("H264"); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 678 | |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 679 | // Set capturer. |
| 680 | FakeVideoCapturerWithTaskQueue capturer; |
| 681 | EXPECT_EQ(cricket::CS_RUNNING, |
| 682 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 683 | |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 684 | std::unique_ptr<VideoMediaChannel> channel( |
| 685 | engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions())); |
| 686 | cricket::VideoSendParameters parameters; |
| 687 | parameters.codecs.push_back(GetEngineCodec("H264")); |
| 688 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 689 | |
| 690 | EXPECT_TRUE( |
| 691 | channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 692 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, nullptr, &capturer)); |
| 693 | // Sending one frame will have allocate the encoder. |
| 694 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 695 | |
| 696 | ASSERT_EQ_WAIT(1u, encoder_factory_->encoders().size(), kTimeout); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 697 | |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 698 | cricket::VideoSendParameters new_parameters; |
| 699 | new_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 700 | EXPECT_TRUE(channel->SetSendParameters(new_parameters)); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 701 | |
| 702 | // Sending one frame will switch encoder. |
| 703 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 704 | |
Anders Carlsson | 8a150d9 | 2018-05-14 12:40:04 +0200 | [diff] [blame] | 705 | EXPECT_EQ_WAIT(1u, encoder_factory_->encoders().size(), kTimeout); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 706 | } |
| 707 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 708 | TEST_F(WebRtcVideoEngineTest, |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 709 | UsesSimulcastAdapterForVp8WithCombinedVP8AndH264Factory) { |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 710 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
| 711 | encoder_factory_->AddSupportedVideoCodecType("H264"); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 712 | |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 713 | std::unique_ptr<VideoMediaChannel> channel( |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 714 | engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions())); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 715 | cricket::VideoSendParameters parameters; |
| 716 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 717 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 718 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 719 | std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 720 | |
| 721 | EXPECT_TRUE( |
| 722 | channel->AddSendStream(CreateSimStreamParams("cname", ssrcs))); |
| 723 | EXPECT_TRUE(channel->SetSend(true)); |
| 724 | |
| 725 | // Send a fake frame, or else the media engine will configure the simulcast |
| 726 | // encoder adapter at a low-enough size that it'll only create a single |
| 727 | // encoder layer. |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 728 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 729 | EXPECT_TRUE(channel->SetVideoSend(ssrcs.front(), nullptr, &capturer)); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 730 | EXPECT_EQ(cricket::CS_RUNNING, |
| 731 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 732 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 733 | |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 734 | ASSERT_TRUE(encoder_factory_->WaitForCreatedVideoEncoders(2)); |
| 735 | ASSERT_TRUE(encoder_factory_->encoders()[0]->WaitForInitEncode()); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 736 | EXPECT_EQ(webrtc::kVideoCodecVP8, |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 737 | encoder_factory_->encoders()[0]->GetCodecSettings().codecType); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 738 | |
| 739 | channel.reset(); |
| 740 | // Make sure DestroyVideoEncoder was called on the factory. |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 741 | EXPECT_EQ(0u, encoder_factory_->encoders().size()); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 742 | } |
| 743 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 744 | TEST_F(WebRtcVideoEngineTest, |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 745 | DestroysNonSimulcastEncoderFromCombinedVP8AndH264Factory) { |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 746 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
| 747 | encoder_factory_->AddSupportedVideoCodecType("H264"); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 748 | |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 749 | std::unique_ptr<VideoMediaChannel> channel( |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 750 | engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions())); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 751 | cricket::VideoSendParameters parameters; |
| 752 | parameters.codecs.push_back(GetEngineCodec("H264")); |
| 753 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 754 | |
| 755 | EXPECT_TRUE( |
| 756 | channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 757 | |
| 758 | // Send a frame of 720p. This should trigger a "real" encoder initialization. |
| 759 | cricket::VideoFormat format( |
| 760 | 1280, 720, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420); |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 761 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 762 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, nullptr, &capturer)); |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 763 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(format)); |
| 764 | EXPECT_TRUE(capturer.CaptureFrame()); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 765 | ASSERT_TRUE(encoder_factory_->WaitForCreatedVideoEncoders(1)); |
| 766 | ASSERT_EQ(1u, encoder_factory_->encoders().size()); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 767 | ASSERT_TRUE(encoder_factory_->encoders()[0]->WaitForInitEncode()); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 768 | EXPECT_EQ(webrtc::kVideoCodecH264, |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 769 | encoder_factory_->encoders()[0]->GetCodecSettings().codecType); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 770 | |
| 771 | channel.reset(); |
| 772 | // Make sure DestroyVideoEncoder was called on the factory. |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 773 | ASSERT_EQ(0u, encoder_factory_->encoders().size()); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 774 | } |
| 775 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 776 | TEST_F(WebRtcVideoEngineTest, SimulcastDisabledForH264) { |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 777 | encoder_factory_->AddSupportedVideoCodecType("H264"); |
noahric | fdac516 | 2015-08-27 01:59:29 -0700 | [diff] [blame] | 778 | |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 779 | std::unique_ptr<VideoMediaChannel> channel( |
| 780 | engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions())); |
| 781 | cricket::VideoSendParameters parameters; |
| 782 | parameters.codecs.push_back(GetEngineCodec("H264")); |
| 783 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
noahric | fdac516 | 2015-08-27 01:59:29 -0700 | [diff] [blame] | 784 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 785 | const std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); |
noahric | fdac516 | 2015-08-27 01:59:29 -0700 | [diff] [blame] | 786 | EXPECT_TRUE( |
| 787 | channel->AddSendStream(cricket::CreateSimStreamParams("cname", ssrcs))); |
Peter Boström | ce23bee | 2016-02-02 14:14:30 +0100 | [diff] [blame] | 788 | |
| 789 | // Send a frame of 720p. This should trigger a "real" encoder initialization. |
noahric | fdac516 | 2015-08-27 01:59:29 -0700 | [diff] [blame] | 790 | cricket::VideoFormat format( |
| 791 | 1280, 720, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420); |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 792 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 793 | EXPECT_TRUE(channel->SetVideoSend(ssrcs[0], nullptr, &capturer)); |
Peter Boström | ce23bee | 2016-02-02 14:14:30 +0100 | [diff] [blame] | 794 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(format)); |
| 795 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 796 | |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 797 | ASSERT_TRUE(encoder_factory_->WaitForCreatedVideoEncoders(1)); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 798 | ASSERT_EQ(1u, encoder_factory_->encoders().size()); |
| 799 | FakeWebRtcVideoEncoder* encoder = encoder_factory_->encoders()[0]; |
| 800 | ASSERT_TRUE(encoder_factory_->encoders()[0]->WaitForInitEncode()); |
noahric | fdac516 | 2015-08-27 01:59:29 -0700 | [diff] [blame] | 801 | EXPECT_EQ(webrtc::kVideoCodecH264, encoder->GetCodecSettings().codecType); |
| 802 | EXPECT_EQ(1u, encoder->GetCodecSettings().numberOfSimulcastStreams); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 803 | EXPECT_TRUE(channel->SetVideoSend(ssrcs[0], nullptr, nullptr)); |
noahric | fdac516 | 2015-08-27 01:59:29 -0700 | [diff] [blame] | 804 | } |
| 805 | |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 806 | // Test that the FlexFEC field trial properly alters the output of |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 807 | // WebRtcVideoEngine::codecs(), for an existing |engine_| object. |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 808 | // |
| 809 | // TODO(brandtr): Remove this test, when the FlexFEC field trial is gone. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 810 | TEST_F(WebRtcVideoEngineTest, |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 811 | Flexfec03SupportedAsInternalCodecBehindFieldTrial) { |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 812 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
| 813 | |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 814 | auto is_flexfec = [](const VideoCodec& codec) { |
| 815 | if (codec.name == "flexfec-03") |
| 816 | return true; |
| 817 | return false; |
| 818 | }; |
| 819 | |
| 820 | // FlexFEC is not active without field trial. |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 821 | const std::vector<VideoCodec> codecs_before = engine_.codecs(); |
| 822 | EXPECT_EQ(codecs_before.end(), std::find_if(codecs_before.begin(), |
| 823 | codecs_before.end(), is_flexfec)); |
| 824 | |
| 825 | // FlexFEC is active with field trial. |
| 826 | webrtc::test::ScopedFieldTrials override_field_trials_( |
brandtr | 340e3fd | 2017-02-28 15:43:10 -0800 | [diff] [blame] | 827 | "WebRTC-FlexFEC-03-Advertised/Enabled/"); |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 828 | const std::vector<VideoCodec> codecs_after = engine_.codecs(); |
| 829 | EXPECT_NE(codecs_after.end(), |
| 830 | std::find_if(codecs_after.begin(), codecs_after.end(), is_flexfec)); |
| 831 | } |
| 832 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 833 | // Test that codecs are added in the order they are reported from the factory. |
| 834 | TEST_F(WebRtcVideoEngineTest, ReportSupportedCodecs) { |
| 835 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
| 836 | const char* kFakeCodecName = "FakeCodec"; |
| 837 | encoder_factory_->AddSupportedVideoCodecType(kFakeCodecName); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 838 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 839 | // The last reported codec should appear after the first codec in the vector. |
Oleh Prypin | a40f824 | 2017-12-21 13:32:23 +0100 | [diff] [blame] | 840 | const size_t vp8_index = GetEngineCodecIndex("VP8"); |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 841 | const size_t fake_codec_index = GetEngineCodecIndex(kFakeCodecName); |
| 842 | EXPECT_LT(vp8_index, fake_codec_index); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 843 | } |
| 844 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 845 | // Test that a codec that was added after the engine was initialized |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 846 | // does show up in the codec list after it was added. |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 847 | TEST_F(WebRtcVideoEngineTest, ReportSupportedAddedCodec) { |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 848 | const char* kFakeExternalCodecName1 = "FakeExternalCodec1"; |
| 849 | const char* kFakeExternalCodecName2 = "FakeExternalCodec2"; |
Magnus Jedvert | 154ee1f | 2017-11-15 19:27:11 +0100 | [diff] [blame] | 850 | |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 851 | // Set up external encoder factory with first codec, and initialize engine. |
| 852 | encoder_factory_->AddSupportedVideoCodecType(kFakeExternalCodecName1); |
| 853 | |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 854 | std::vector<cricket::VideoCodec> codecs_before(engine_.codecs()); |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 855 | |
| 856 | // Add second codec. |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 857 | encoder_factory_->AddSupportedVideoCodecType(kFakeExternalCodecName2); |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 858 | std::vector<cricket::VideoCodec> codecs_after(engine_.codecs()); |
| 859 | EXPECT_EQ(codecs_before.size() + 1, codecs_after.size()); |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 860 | |
| 861 | // Check that both fake codecs are present and that the second fake codec |
| 862 | // appears after the first fake codec. |
Oleh Prypin | a40f824 | 2017-12-21 13:32:23 +0100 | [diff] [blame] | 863 | const size_t fake_codec_index1 = GetEngineCodecIndex(kFakeExternalCodecName1); |
| 864 | const size_t fake_codec_index2 = GetEngineCodecIndex(kFakeExternalCodecName2); |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 865 | EXPECT_LT(fake_codec_index1, fake_codec_index2); |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 866 | } |
| 867 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 868 | TEST_F(WebRtcVideoEngineTest, RegisterDecodersIfSupported) { |
| 869 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 870 | decoder_factory_->AddSupportedVideoCodecType(webrtc::SdpVideoFormat("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 871 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 872 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 873 | |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 874 | std::unique_ptr<VideoMediaChannel> channel( |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 875 | SetRecvParamsWithSupportedCodecs(parameters.codecs)); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 876 | |
| 877 | EXPECT_TRUE( |
| 878 | channel->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 879 | ASSERT_EQ(1u, decoder_factory_->decoders().size()); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 880 | |
| 881 | // Setting codecs of the same type should not reallocate the decoder. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 882 | EXPECT_TRUE(channel->SetRecvParameters(parameters)); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 883 | EXPECT_EQ(1, decoder_factory_->GetNumCreatedDecoders()); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 884 | |
| 885 | // Remove stream previously added to free the external decoder instance. |
| 886 | EXPECT_TRUE(channel->RemoveRecvStream(kSsrc)); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 887 | EXPECT_EQ(0u, decoder_factory_->decoders().size()); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 888 | } |
| 889 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 890 | // Verifies that we can set up decoders. |
| 891 | TEST_F(WebRtcVideoEngineTest, RegisterH264DecoderIfSupported) { |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 892 | // TODO(pbos): Do not assume that encoder/decoder support is symmetric. We |
| 893 | // can't even query the WebRtcVideoDecoderFactory for supported codecs. |
| 894 | // For now we add a FakeWebRtcVideoEncoderFactory to add H264 to supported |
| 895 | // codecs. |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 896 | encoder_factory_->AddSupportedVideoCodecType("H264"); |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 897 | decoder_factory_->AddSupportedVideoCodecType(webrtc::SdpVideoFormat("H264")); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 898 | std::vector<cricket::VideoCodec> codecs; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 899 | codecs.push_back(GetEngineCodec("H264")); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 900 | |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 901 | std::unique_ptr<VideoMediaChannel> channel( |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 902 | SetRecvParamsWithSupportedCodecs(codecs)); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 903 | |
| 904 | EXPECT_TRUE( |
| 905 | channel->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 906 | ASSERT_EQ(1u, decoder_factory_->decoders().size()); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 907 | } |
| 908 | |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 909 | TEST(WebRtcVideoEngineNewVideoCodecFactoryTest, NullFactories) { |
| 910 | std::unique_ptr<webrtc::VideoEncoderFactory> encoder_factory; |
| 911 | std::unique_ptr<webrtc::VideoDecoderFactory> decoder_factory; |
| 912 | WebRtcVideoEngine engine(std::move(encoder_factory), |
| 913 | std::move(decoder_factory)); |
| 914 | EXPECT_EQ(0u, engine.codecs().size()); |
| 915 | } |
| 916 | |
| 917 | TEST(WebRtcVideoEngineNewVideoCodecFactoryTest, EmptyFactories) { |
| 918 | // |engine| take ownership of the factories. |
Emircan Uysaler | dbcac7f | 2017-10-30 23:10:12 -0700 | [diff] [blame] | 919 | webrtc::MockVideoEncoderFactory* encoder_factory = |
| 920 | new webrtc::MockVideoEncoderFactory(); |
| 921 | webrtc::MockVideoDecoderFactory* decoder_factory = |
| 922 | new webrtc::MockVideoDecoderFactory(); |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 923 | WebRtcVideoEngine engine( |
| 924 | (std::unique_ptr<webrtc::VideoEncoderFactory>(encoder_factory)), |
| 925 | (std::unique_ptr<webrtc::VideoDecoderFactory>(decoder_factory))); |
| 926 | EXPECT_CALL(*encoder_factory, GetSupportedFormats()); |
| 927 | EXPECT_EQ(0u, engine.codecs().size()); |
| 928 | EXPECT_CALL(*encoder_factory, Die()); |
| 929 | EXPECT_CALL(*decoder_factory, Die()); |
| 930 | } |
| 931 | |
| 932 | // Test full behavior in the video engine when video codec factories of the new |
| 933 | // type are injected supporting the single codec Vp8. Check the returned codecs |
| 934 | // from the engine and that we will create a Vp8 encoder and decoder using the |
| 935 | // new factories. |
| 936 | TEST(WebRtcVideoEngineNewVideoCodecFactoryTest, Vp8) { |
| 937 | // |engine| take ownership of the factories. |
Emircan Uysaler | dbcac7f | 2017-10-30 23:10:12 -0700 | [diff] [blame] | 938 | webrtc::MockVideoEncoderFactory* encoder_factory = |
| 939 | new webrtc::MockVideoEncoderFactory(); |
| 940 | webrtc::MockVideoDecoderFactory* decoder_factory = |
| 941 | new webrtc::MockVideoDecoderFactory(); |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 942 | WebRtcVideoEngine engine( |
| 943 | (std::unique_ptr<webrtc::VideoEncoderFactory>(encoder_factory)), |
| 944 | (std::unique_ptr<webrtc::VideoDecoderFactory>(decoder_factory))); |
| 945 | const webrtc::SdpVideoFormat vp8_format("VP8"); |
| 946 | const std::vector<webrtc::SdpVideoFormat> supported_formats = {vp8_format}; |
| 947 | EXPECT_CALL(*encoder_factory, GetSupportedFormats()) |
| 948 | .WillRepeatedly(testing::Return(supported_formats)); |
| 949 | |
| 950 | // Verify the codecs from the engine. |
| 951 | const std::vector<VideoCodec> engine_codecs = engine.codecs(); |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 952 | // Verify default codecs has been added correctly. |
| 953 | EXPECT_EQ(5u, engine_codecs.size()); |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 954 | EXPECT_EQ("VP8", engine_codecs.at(0).name); |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 955 | |
| 956 | // RTX codec for VP8. |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 957 | EXPECT_EQ("rtx", engine_codecs.at(1).name); |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 958 | int vp8_associated_payload; |
| 959 | EXPECT_TRUE(engine_codecs.at(1).GetParam(kCodecParamAssociatedPayloadType, |
| 960 | &vp8_associated_payload)); |
| 961 | EXPECT_EQ(vp8_associated_payload, engine_codecs.at(0).id); |
| 962 | |
| 963 | EXPECT_EQ(kRedCodecName, engine_codecs.at(2).name); |
| 964 | |
| 965 | // RTX codec for RED. |
| 966 | EXPECT_EQ("rtx", engine_codecs.at(3).name); |
| 967 | int red_associated_payload; |
| 968 | EXPECT_TRUE(engine_codecs.at(3).GetParam(kCodecParamAssociatedPayloadType, |
| 969 | &red_associated_payload)); |
| 970 | EXPECT_EQ(red_associated_payload, engine_codecs.at(2).id); |
| 971 | |
| 972 | EXPECT_EQ(kUlpfecCodecName, engine_codecs.at(4).name); |
| 973 | |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 974 | int associated_payload_type; |
| 975 | EXPECT_TRUE(engine_codecs.at(1).GetParam( |
| 976 | cricket::kCodecParamAssociatedPayloadType, &associated_payload_type)); |
| 977 | EXPECT_EQ(engine_codecs.at(0).id, associated_payload_type); |
| 978 | // Verify default parameters has been added to the VP8 codec. |
| 979 | VerifyCodecHasDefaultFeedbackParams(engine_codecs.at(0)); |
| 980 | |
| 981 | // Mock encoder creation. |engine| take ownership of the encoder. |
| 982 | webrtc::VideoEncoderFactory::CodecInfo codec_info; |
| 983 | codec_info.is_hardware_accelerated = false; |
| 984 | codec_info.has_internal_source = false; |
| 985 | const webrtc::SdpVideoFormat format("VP8"); |
| 986 | EXPECT_CALL(*encoder_factory, QueryVideoEncoder(format)) |
| 987 | .WillRepeatedly(testing::Return(codec_info)); |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 988 | FakeWebRtcVideoEncoder* const encoder = new FakeWebRtcVideoEncoder(nullptr); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 989 | rtc::Event encoder_created(false, false); |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 990 | EXPECT_CALL(*encoder_factory, CreateVideoEncoderProxy(format)) |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 991 | .WillOnce( |
| 992 | ::testing::DoAll(::testing::InvokeWithoutArgs( |
| 993 | [&encoder_created]() { encoder_created.Set(); }), |
| 994 | ::testing::Return(encoder))); |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 995 | |
| 996 | // Mock decoder creation. |engine| take ownership of the decoder. |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 997 | FakeWebRtcVideoDecoder* const decoder = new FakeWebRtcVideoDecoder(nullptr); |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 998 | EXPECT_CALL(*decoder_factory, CreateVideoDecoderProxy(format)) |
| 999 | .WillOnce(testing::Return(decoder)); |
| 1000 | |
| 1001 | // Create a call. |
| 1002 | webrtc::RtcEventLogNullImpl event_log; |
| 1003 | std::unique_ptr<webrtc::Call> call( |
| 1004 | webrtc::Call::Create(webrtc::Call::Config(&event_log))); |
| 1005 | |
| 1006 | // Create send channel. |
| 1007 | const int send_ssrc = 123; |
| 1008 | std::unique_ptr<VideoMediaChannel> send_channel( |
| 1009 | engine.CreateChannel(call.get(), GetMediaConfig(), VideoOptions())); |
| 1010 | cricket::VideoSendParameters send_parameters; |
| 1011 | send_parameters.codecs.push_back(engine_codecs.at(0)); |
| 1012 | EXPECT_TRUE(send_channel->SetSendParameters(send_parameters)); |
| 1013 | send_channel->OnReadyToSend(true); |
| 1014 | EXPECT_TRUE( |
| 1015 | send_channel->AddSendStream(StreamParams::CreateLegacy(send_ssrc))); |
| 1016 | EXPECT_TRUE(send_channel->SetSend(true)); |
| 1017 | |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 1018 | // Set capturer. |
| 1019 | FakeVideoCapturerWithTaskQueue capturer; |
| 1020 | EXPECT_EQ(cricket::CS_RUNNING, |
| 1021 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 1022 | EXPECT_TRUE(send_channel->SetVideoSend(send_ssrc, nullptr, &capturer)); |
| 1023 | // Sending one frame will allocate the encoder. |
| 1024 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 1025 | encoder_created.Wait(kTimeout); |
| 1026 | |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 1027 | // Create recv channel. |
| 1028 | const int recv_ssrc = 321; |
| 1029 | std::unique_ptr<VideoMediaChannel> recv_channel( |
| 1030 | engine.CreateChannel(call.get(), GetMediaConfig(), VideoOptions())); |
| 1031 | cricket::VideoRecvParameters recv_parameters; |
| 1032 | recv_parameters.codecs.push_back(engine_codecs.at(0)); |
| 1033 | EXPECT_TRUE(recv_channel->SetRecvParameters(recv_parameters)); |
| 1034 | EXPECT_TRUE(recv_channel->AddRecvStream( |
| 1035 | cricket::StreamParams::CreateLegacy(recv_ssrc))); |
| 1036 | |
| 1037 | // Remove streams previously added to free the encoder and decoder instance. |
| 1038 | EXPECT_CALL(*encoder_factory, Die()); |
| 1039 | EXPECT_CALL(*decoder_factory, Die()); |
| 1040 | EXPECT_TRUE(send_channel->RemoveSendStream(send_ssrc)); |
| 1041 | EXPECT_TRUE(recv_channel->RemoveRecvStream(recv_ssrc)); |
| 1042 | } |
| 1043 | |
Magnus Jedvert | 7501b1c | 2017-11-09 13:43:42 +0100 | [diff] [blame] | 1044 | // Test behavior when decoder factory fails to create a decoder (returns null). |
| 1045 | TEST(WebRtcVideoEngineNewVideoCodecFactoryTest, NullDecoder) { |
| 1046 | // |engine| take ownership of the factories. |
| 1047 | webrtc::MockVideoEncoderFactory* encoder_factory = |
| 1048 | new testing::StrictMock<webrtc::MockVideoEncoderFactory>(); |
| 1049 | webrtc::MockVideoDecoderFactory* decoder_factory = |
| 1050 | new testing::StrictMock<webrtc::MockVideoDecoderFactory>(); |
| 1051 | WebRtcVideoEngine engine( |
| 1052 | (std::unique_ptr<webrtc::VideoEncoderFactory>(encoder_factory)), |
| 1053 | (std::unique_ptr<webrtc::VideoDecoderFactory>(decoder_factory))); |
| 1054 | const webrtc::SdpVideoFormat vp8_format("VP8"); |
| 1055 | const std::vector<webrtc::SdpVideoFormat> supported_formats = {vp8_format}; |
| 1056 | EXPECT_CALL(*encoder_factory, GetSupportedFormats()) |
| 1057 | .WillRepeatedly(testing::Return(supported_formats)); |
| 1058 | |
| 1059 | // Decoder creation fails. |
| 1060 | EXPECT_CALL(*decoder_factory, CreateVideoDecoderProxy(testing::_)) |
| 1061 | .WillOnce(testing::Return(nullptr)); |
| 1062 | |
| 1063 | // Create a call. |
| 1064 | webrtc::RtcEventLogNullImpl event_log; |
| 1065 | std::unique_ptr<webrtc::Call> call( |
| 1066 | webrtc::Call::Create(webrtc::Call::Config(&event_log))); |
| 1067 | |
| 1068 | // Create recv channel. |
| 1069 | const int recv_ssrc = 321; |
| 1070 | std::unique_ptr<VideoMediaChannel> recv_channel( |
| 1071 | engine.CreateChannel(call.get(), GetMediaConfig(), VideoOptions())); |
| 1072 | cricket::VideoRecvParameters recv_parameters; |
| 1073 | recv_parameters.codecs.push_back(engine.codecs().front()); |
| 1074 | EXPECT_TRUE(recv_channel->SetRecvParameters(recv_parameters)); |
| 1075 | EXPECT_TRUE(recv_channel->AddRecvStream( |
| 1076 | cricket::StreamParams::CreateLegacy(recv_ssrc))); |
| 1077 | |
| 1078 | // Remove streams previously added to free the encoder and decoder instance. |
| 1079 | EXPECT_TRUE(recv_channel->RemoveRecvStream(recv_ssrc)); |
| 1080 | } |
| 1081 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 1082 | TEST_F(WebRtcVideoEngineTest, DISABLED_RecreatesEncoderOnContentTypeChange) { |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 1083 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 1084 | std::unique_ptr<FakeCall> fake_call(new FakeCall()); |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 1085 | std::unique_ptr<VideoMediaChannel> channel( |
| 1086 | SetSendParamsWithAllSupportedCodecs()); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1087 | ASSERT_TRUE( |
| 1088 | channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| 1089 | cricket::VideoCodec codec = GetEngineCodec("VP8"); |
| 1090 | cricket::VideoSendParameters parameters; |
| 1091 | parameters.codecs.push_back(codec); |
| 1092 | channel->OnReadyToSend(true); |
| 1093 | channel->SetSend(true); |
| 1094 | ASSERT_TRUE(channel->SetSendParameters(parameters)); |
| 1095 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 1096 | FakeVideoCapturerWithTaskQueue capturer; |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1097 | VideoOptions options; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 1098 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, &options, &capturer)); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1099 | |
| 1100 | EXPECT_EQ(cricket::CS_RUNNING, |
| 1101 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 1102 | EXPECT_TRUE(capturer.CaptureFrame()); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 1103 | ASSERT_TRUE(encoder_factory_->WaitForCreatedVideoEncoders(1)); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1104 | EXPECT_EQ(webrtc::kRealtimeVideo, |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 1105 | encoder_factory_->encoders().back()->GetCodecSettings().mode); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1106 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 1107 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, &options, &capturer)); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1108 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 1109 | // No change in content type, keep current encoder. |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 1110 | EXPECT_EQ(1, encoder_factory_->GetNumCreatedEncoders()); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1111 | |
| 1112 | options.is_screencast.emplace(true); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 1113 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, &options, &capturer)); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1114 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 1115 | // Change to screen content, recreate encoder. For the simulcast encoder |
| 1116 | // adapter case, this will result in two calls since InitEncode triggers a |
| 1117 | // a new instance. |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 1118 | ASSERT_TRUE(encoder_factory_->WaitForCreatedVideoEncoders(2)); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1119 | EXPECT_EQ(webrtc::kScreensharing, |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 1120 | encoder_factory_->encoders().back()->GetCodecSettings().mode); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1121 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 1122 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, &options, &capturer)); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1123 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 1124 | // Still screen content, no need to update encoder. |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 1125 | EXPECT_EQ(2, encoder_factory_->GetNumCreatedEncoders()); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1126 | |
| 1127 | options.is_screencast.emplace(false); |
| 1128 | options.video_noise_reduction.emplace(false); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 1129 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, &options, &capturer)); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1130 | // Change back to regular video content, update encoder. Also change |
| 1131 | // a non |is_screencast| option just to verify it doesn't affect recreation. |
| 1132 | EXPECT_TRUE(capturer.CaptureFrame()); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 1133 | ASSERT_TRUE(encoder_factory_->WaitForCreatedVideoEncoders(3)); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1134 | EXPECT_EQ(webrtc::kRealtimeVideo, |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 1135 | encoder_factory_->encoders().back()->GetCodecSettings().mode); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1136 | |
| 1137 | // Remove stream previously added to free the external encoder instance. |
| 1138 | EXPECT_TRUE(channel->RemoveSendStream(kSsrc)); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 1139 | EXPECT_EQ(0u, encoder_factory_->encoders().size()); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1140 | } |
| 1141 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1142 | class WebRtcVideoChannelBaseTest : public testing::Test { |
| 1143 | protected: |
| 1144 | WebRtcVideoChannelBaseTest() |
| 1145 | : call_(webrtc::Call::Create(webrtc::Call::Config(&event_log_))), |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 1146 | engine_(webrtc::CreateBuiltinVideoEncoderFactory(), |
| 1147 | webrtc::CreateBuiltinVideoDecoderFactory()) {} |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1148 | |
| 1149 | virtual void SetUp() { |
| 1150 | cricket::MediaConfig media_config; |
| 1151 | // Disabling cpu overuse detection actually disables quality scaling too; it |
| 1152 | // implies DegradationPreference kMaintainResolution. Automatic scaling |
| 1153 | // needs to be disabled, otherwise, tests which check the size of received |
| 1154 | // frames become flaky. |
| 1155 | media_config.video.enable_cpu_adaptation = false; |
| 1156 | channel_.reset(engine_.CreateChannel(call_.get(), media_config, |
| 1157 | cricket::VideoOptions())); |
| 1158 | channel_->OnReadyToSend(true); |
| 1159 | EXPECT_TRUE(channel_.get() != NULL); |
| 1160 | network_interface_.SetDestination(channel_.get()); |
| 1161 | channel_->SetInterface(&network_interface_); |
| 1162 | cricket::VideoRecvParameters parameters; |
| 1163 | parameters.codecs = engine_.codecs(); |
| 1164 | channel_->SetRecvParameters(parameters); |
| 1165 | EXPECT_TRUE(channel_->AddSendStream(DefaultSendStreamParams())); |
| 1166 | video_capturer_.reset(CreateFakeVideoCapturer()); |
| 1167 | cricket::VideoFormat format(640, 480, |
| 1168 | cricket::VideoFormat::FpsToInterval(kFramerate), |
| 1169 | cricket::FOURCC_I420); |
| 1170 | EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(format)); |
| 1171 | EXPECT_TRUE( |
| 1172 | channel_->SetVideoSend(kSsrc, nullptr, video_capturer_.get())); |
| 1173 | } |
| 1174 | |
| 1175 | virtual cricket::FakeVideoCapturerWithTaskQueue* CreateFakeVideoCapturer() { |
| 1176 | return new cricket::FakeVideoCapturerWithTaskQueue(); |
| 1177 | } |
| 1178 | |
| 1179 | // Utility method to setup an additional stream to send and receive video. |
| 1180 | // Used to test send and recv between two streams. |
| 1181 | void SetUpSecondStream() { |
| 1182 | SetUpSecondStreamWithNoRecv(); |
| 1183 | // Setup recv for second stream. |
| 1184 | EXPECT_TRUE(channel_->AddRecvStream( |
| 1185 | cricket::StreamParams::CreateLegacy(kSsrc + 2))); |
| 1186 | // Make the second renderer available for use by a new stream. |
| 1187 | EXPECT_TRUE(channel_->SetSink(kSsrc + 2, &renderer2_)); |
| 1188 | } |
| 1189 | // Setup an additional stream just to send video. Defer add recv stream. |
| 1190 | // This is required if you want to test unsignalled recv of video rtp packets. |
| 1191 | void SetUpSecondStreamWithNoRecv() { |
| 1192 | // SetUp() already added kSsrc make sure duplicate SSRCs cant be added. |
| 1193 | EXPECT_TRUE(channel_->AddRecvStream( |
| 1194 | cricket::StreamParams::CreateLegacy(kSsrc))); |
| 1195 | EXPECT_TRUE(channel_->SetSink(kSsrc, &renderer_)); |
| 1196 | EXPECT_FALSE(channel_->AddSendStream( |
| 1197 | cricket::StreamParams::CreateLegacy(kSsrc))); |
| 1198 | EXPECT_TRUE(channel_->AddSendStream( |
| 1199 | cricket::StreamParams::CreateLegacy(kSsrc + 2))); |
| 1200 | // We dont add recv for the second stream. |
| 1201 | |
| 1202 | // Setup the receive and renderer for second stream after send. |
| 1203 | video_capturer_2_.reset(CreateFakeVideoCapturer()); |
| 1204 | cricket::VideoFormat format(640, 480, |
| 1205 | cricket::VideoFormat::FpsToInterval(kFramerate), |
| 1206 | cricket::FOURCC_I420); |
| 1207 | EXPECT_EQ(cricket::CS_RUNNING, video_capturer_2_->Start(format)); |
| 1208 | |
| 1209 | EXPECT_TRUE(channel_->SetVideoSend(kSsrc + 2, nullptr, |
| 1210 | video_capturer_2_.get())); |
| 1211 | } |
| 1212 | virtual void TearDown() { |
| 1213 | channel_.reset(); |
| 1214 | } |
| 1215 | bool SetDefaultCodec() { |
| 1216 | return SetOneCodec(DefaultCodec()); |
| 1217 | } |
| 1218 | |
| 1219 | bool SetOneCodec(const cricket::VideoCodec& codec) { |
| 1220 | cricket::VideoFormat capture_format( |
| 1221 | kVideoWidth, kVideoHeight, |
| 1222 | cricket::VideoFormat::FpsToInterval(kFramerate), cricket::FOURCC_I420); |
| 1223 | |
| 1224 | if (video_capturer_) { |
| 1225 | EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(capture_format)); |
| 1226 | } |
| 1227 | if (video_capturer_2_) { |
| 1228 | EXPECT_EQ(cricket::CS_RUNNING, video_capturer_2_->Start(capture_format)); |
| 1229 | } |
| 1230 | |
| 1231 | bool sending = channel_->sending(); |
| 1232 | bool success = SetSend(false); |
| 1233 | if (success) { |
| 1234 | cricket::VideoSendParameters parameters; |
| 1235 | parameters.codecs.push_back(codec); |
| 1236 | success = channel_->SetSendParameters(parameters); |
| 1237 | } |
| 1238 | if (success) { |
| 1239 | success = SetSend(sending); |
| 1240 | } |
| 1241 | return success; |
| 1242 | } |
| 1243 | bool SetSend(bool send) { |
| 1244 | return channel_->SetSend(send); |
| 1245 | } |
| 1246 | bool SendFrame() { |
| 1247 | if (video_capturer_2_) { |
| 1248 | video_capturer_2_->CaptureFrame(); |
| 1249 | } |
| 1250 | return video_capturer_.get() && video_capturer_->CaptureFrame(); |
| 1251 | } |
| 1252 | bool WaitAndSendFrame(int wait_ms) { |
| 1253 | bool ret = rtc::Thread::Current()->ProcessMessages(wait_ms); |
| 1254 | ret &= SendFrame(); |
| 1255 | return ret; |
| 1256 | } |
| 1257 | int NumRtpBytes() { |
| 1258 | return network_interface_.NumRtpBytes(); |
| 1259 | } |
| 1260 | int NumRtpBytes(uint32_t ssrc) { |
| 1261 | return network_interface_.NumRtpBytes(ssrc); |
| 1262 | } |
| 1263 | int NumRtpPackets() { |
| 1264 | return network_interface_.NumRtpPackets(); |
| 1265 | } |
| 1266 | int NumRtpPackets(uint32_t ssrc) { |
| 1267 | return network_interface_.NumRtpPackets(ssrc); |
| 1268 | } |
| 1269 | int NumSentSsrcs() { |
| 1270 | return network_interface_.NumSentSsrcs(); |
| 1271 | } |
| 1272 | const rtc::CopyOnWriteBuffer* GetRtpPacket(int index) { |
| 1273 | return network_interface_.GetRtpPacket(index); |
| 1274 | } |
| 1275 | static int GetPayloadType(const rtc::CopyOnWriteBuffer* p) { |
| 1276 | int pt = -1; |
| 1277 | ParseRtpPacket(p, NULL, &pt, NULL, NULL, NULL, NULL); |
| 1278 | return pt; |
| 1279 | } |
| 1280 | static bool ParseRtpPacket(const rtc::CopyOnWriteBuffer* p, |
| 1281 | bool* x, |
| 1282 | int* pt, |
| 1283 | int* seqnum, |
| 1284 | uint32_t* tstamp, |
| 1285 | uint32_t* ssrc, |
| 1286 | std::string* payload) { |
| 1287 | rtc::ByteBufferReader buf(p->data<char>(), p->size()); |
| 1288 | uint8_t u08 = 0; |
| 1289 | uint16_t u16 = 0; |
| 1290 | uint32_t u32 = 0; |
| 1291 | |
| 1292 | // Read X and CC fields. |
| 1293 | if (!buf.ReadUInt8(&u08)) return false; |
| 1294 | bool extension = ((u08 & 0x10) != 0); |
| 1295 | uint8_t cc = (u08 & 0x0F); |
| 1296 | if (x) *x = extension; |
| 1297 | |
| 1298 | // Read PT field. |
| 1299 | if (!buf.ReadUInt8(&u08)) return false; |
| 1300 | if (pt) *pt = (u08 & 0x7F); |
| 1301 | |
| 1302 | // Read Sequence Number field. |
| 1303 | if (!buf.ReadUInt16(&u16)) return false; |
| 1304 | if (seqnum) *seqnum = u16; |
| 1305 | |
| 1306 | // Read Timestamp field. |
| 1307 | if (!buf.ReadUInt32(&u32)) return false; |
| 1308 | if (tstamp) *tstamp = u32; |
| 1309 | |
| 1310 | // Read SSRC field. |
| 1311 | if (!buf.ReadUInt32(&u32)) return false; |
| 1312 | if (ssrc) *ssrc = u32; |
| 1313 | |
| 1314 | // Skip CSRCs. |
| 1315 | for (uint8_t i = 0; i < cc; ++i) { |
| 1316 | if (!buf.ReadUInt32(&u32)) return false; |
| 1317 | } |
| 1318 | |
| 1319 | // Skip extension header. |
| 1320 | if (extension) { |
| 1321 | // Read Profile-specific extension header ID |
| 1322 | if (!buf.ReadUInt16(&u16)) return false; |
| 1323 | |
| 1324 | // Read Extension header length |
| 1325 | if (!buf.ReadUInt16(&u16)) return false; |
| 1326 | uint16_t ext_header_len = u16; |
| 1327 | |
| 1328 | // Read Extension header |
| 1329 | for (uint16_t i = 0; i < ext_header_len; ++i) { |
| 1330 | if (!buf.ReadUInt32(&u32)) return false; |
| 1331 | } |
| 1332 | } |
| 1333 | |
| 1334 | if (payload) { |
| 1335 | return buf.ReadString(payload, buf.Length()); |
| 1336 | } |
| 1337 | return true; |
| 1338 | } |
| 1339 | |
| 1340 | // Tests that we can send and receive frames. |
| 1341 | void SendAndReceive(const cricket::VideoCodec& codec) { |
| 1342 | EXPECT_TRUE(SetOneCodec(codec)); |
| 1343 | EXPECT_TRUE(SetSend(true)); |
| 1344 | EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); |
| 1345 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 1346 | EXPECT_TRUE(SendFrame()); |
| 1347 | EXPECT_FRAME_WAIT(1, kVideoWidth, kVideoHeight, kTimeout); |
| 1348 | std::unique_ptr<const rtc::CopyOnWriteBuffer> p(GetRtpPacket(0)); |
| 1349 | EXPECT_EQ(codec.id, GetPayloadType(p.get())); |
| 1350 | } |
| 1351 | |
| 1352 | void SendReceiveManyAndGetStats(const cricket::VideoCodec& codec, |
| 1353 | int duration_sec, int fps) { |
| 1354 | EXPECT_TRUE(SetOneCodec(codec)); |
| 1355 | EXPECT_TRUE(SetSend(true)); |
| 1356 | EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); |
| 1357 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 1358 | for (int i = 0; i < duration_sec; ++i) { |
| 1359 | for (int frame = 1; frame <= fps; ++frame) { |
| 1360 | EXPECT_TRUE(WaitAndSendFrame(1000 / fps)); |
| 1361 | EXPECT_FRAME_WAIT(frame + i * fps, kVideoWidth, kVideoHeight, kTimeout); |
| 1362 | } |
| 1363 | } |
| 1364 | std::unique_ptr<const rtc::CopyOnWriteBuffer> p(GetRtpPacket(0)); |
| 1365 | EXPECT_EQ(codec.id, GetPayloadType(p.get())); |
| 1366 | } |
| 1367 | |
| 1368 | |
| 1369 | cricket::VideoSenderInfo GetSenderStats(size_t i) { |
| 1370 | cricket::VideoMediaInfo info; |
| 1371 | EXPECT_TRUE(channel_->GetStats(&info)); |
| 1372 | return info.senders[i]; |
| 1373 | } |
| 1374 | |
| 1375 | cricket::VideoReceiverInfo GetReceiverStats(size_t i) { |
| 1376 | cricket::VideoMediaInfo info; |
| 1377 | EXPECT_TRUE(channel_->GetStats(&info)); |
| 1378 | return info.receivers[i]; |
| 1379 | } |
| 1380 | |
| 1381 | // Two streams one channel tests. |
| 1382 | |
| 1383 | // Tests that we can send and receive frames. |
| 1384 | void TwoStreamsSendAndReceive(const cricket::VideoCodec& codec) { |
| 1385 | SetUpSecondStream(); |
| 1386 | // Test sending and receiving on first stream. |
| 1387 | SendAndReceive(codec); |
| 1388 | // Test sending and receiving on second stream. |
| 1389 | EXPECT_EQ_WAIT(1, renderer2_.num_rendered_frames(), kTimeout); |
| 1390 | EXPECT_GT(NumRtpPackets(), 0); |
| 1391 | EXPECT_EQ(1, renderer2_.num_rendered_frames()); |
| 1392 | } |
| 1393 | |
| 1394 | cricket::VideoCodec GetEngineCodec(const std::string& name) { |
| 1395 | for (const cricket::VideoCodec& engine_codec : engine_.codecs()) { |
| 1396 | if (CodecNamesEq(name, engine_codec.name)) |
| 1397 | return engine_codec; |
| 1398 | } |
| 1399 | // This point should never be reached. |
| 1400 | ADD_FAILURE() << "Unrecognized codec name: " << name; |
| 1401 | return cricket::VideoCodec(); |
| 1402 | } |
| 1403 | |
| 1404 | cricket::VideoCodec DefaultCodec() { return GetEngineCodec("VP8"); } |
| 1405 | |
| 1406 | cricket::StreamParams DefaultSendStreamParams() { |
| 1407 | return cricket::StreamParams::CreateLegacy(kSsrc); |
| 1408 | } |
| 1409 | |
| 1410 | webrtc::RtcEventLogNullImpl event_log_; |
| 1411 | const std::unique_ptr<webrtc::Call> call_; |
| 1412 | WebRtcVideoEngine engine_; |
| 1413 | std::unique_ptr<cricket::FakeVideoCapturerWithTaskQueue> video_capturer_; |
| 1414 | std::unique_ptr<cricket::FakeVideoCapturerWithTaskQueue> video_capturer_2_; |
| 1415 | std::unique_ptr<WebRtcVideoChannel> channel_; |
| 1416 | cricket::FakeNetworkInterface network_interface_; |
| 1417 | cricket::FakeVideoRenderer renderer_; |
| 1418 | |
| 1419 | // Used by test cases where 2 streams are run on the same channel. |
| 1420 | cricket::FakeVideoRenderer renderer2_; |
| 1421 | }; |
| 1422 | |
| 1423 | // Test that SetSend works. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1424 | TEST_F(WebRtcVideoChannelBaseTest, SetSend) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1425 | EXPECT_FALSE(channel_->sending()); |
| 1426 | EXPECT_TRUE( |
| 1427 | channel_->SetVideoSend(kSsrc, nullptr, video_capturer_.get())); |
| 1428 | EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
| 1429 | EXPECT_FALSE(channel_->sending()); |
| 1430 | EXPECT_TRUE(SetSend(true)); |
| 1431 | EXPECT_TRUE(channel_->sending()); |
| 1432 | EXPECT_TRUE(SendFrame()); |
| 1433 | EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); |
| 1434 | EXPECT_TRUE(SetSend(false)); |
| 1435 | EXPECT_FALSE(channel_->sending()); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1436 | } |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1437 | |
| 1438 | // Test that SetSend fails without codecs being set. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1439 | TEST_F(WebRtcVideoChannelBaseTest, SetSendWithoutCodecs) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1440 | EXPECT_FALSE(channel_->sending()); |
| 1441 | EXPECT_FALSE(SetSend(true)); |
| 1442 | EXPECT_FALSE(channel_->sending()); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1443 | } |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1444 | |
| 1445 | // Test that we properly set the send and recv buffer sizes by the time |
| 1446 | // SetSend is called. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1447 | TEST_F(WebRtcVideoChannelBaseTest, SetSendSetsTransportBufferSizes) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1448 | EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
| 1449 | EXPECT_TRUE(SetSend(true)); |
| 1450 | EXPECT_EQ(64 * 1024, network_interface_.sendbuf_size()); |
| 1451 | EXPECT_EQ(64 * 1024, network_interface_.recvbuf_size()); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1452 | } |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 1453 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1454 | // Test that stats work properly for a 1-1 call. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1455 | TEST_F(WebRtcVideoChannelBaseTest, GetStats) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1456 | const int kDurationSec = 3; |
| 1457 | const int kFps = 10; |
| 1458 | SendReceiveManyAndGetStats(DefaultCodec(), kDurationSec, kFps); |
| 1459 | |
| 1460 | cricket::VideoMediaInfo info; |
| 1461 | EXPECT_TRUE(channel_->GetStats(&info)); |
| 1462 | |
| 1463 | ASSERT_EQ(1U, info.senders.size()); |
| 1464 | // TODO(whyuan): bytes_sent and bytes_rcvd are different. Are both payload? |
| 1465 | // For webrtc, bytes_sent does not include the RTP header length. |
| 1466 | EXPECT_GT(info.senders[0].bytes_sent, 0); |
| 1467 | EXPECT_EQ(NumRtpPackets(), info.senders[0].packets_sent); |
| 1468 | EXPECT_EQ(0.0, info.senders[0].fraction_lost); |
| 1469 | ASSERT_TRUE(info.senders[0].codec_payload_type); |
| 1470 | EXPECT_EQ(DefaultCodec().id, *info.senders[0].codec_payload_type); |
| 1471 | EXPECT_EQ(0, info.senders[0].firs_rcvd); |
| 1472 | EXPECT_EQ(0, info.senders[0].plis_rcvd); |
| 1473 | EXPECT_EQ(0, info.senders[0].nacks_rcvd); |
| 1474 | EXPECT_EQ(kVideoWidth, info.senders[0].send_frame_width); |
| 1475 | EXPECT_EQ(kVideoHeight, info.senders[0].send_frame_height); |
| 1476 | EXPECT_GT(info.senders[0].framerate_input, 0); |
| 1477 | EXPECT_GT(info.senders[0].framerate_sent, 0); |
| 1478 | |
| 1479 | EXPECT_EQ(1U, info.send_codecs.count(DefaultCodec().id)); |
| 1480 | EXPECT_EQ(DefaultCodec().ToCodecParameters(), |
| 1481 | info.send_codecs[DefaultCodec().id]); |
| 1482 | |
| 1483 | ASSERT_EQ(1U, info.receivers.size()); |
| 1484 | EXPECT_EQ(1U, info.senders[0].ssrcs().size()); |
| 1485 | EXPECT_EQ(1U, info.receivers[0].ssrcs().size()); |
| 1486 | EXPECT_EQ(info.senders[0].ssrcs()[0], info.receivers[0].ssrcs()[0]); |
| 1487 | ASSERT_TRUE(info.receivers[0].codec_payload_type); |
| 1488 | EXPECT_EQ(DefaultCodec().id, *info.receivers[0].codec_payload_type); |
| 1489 | EXPECT_EQ(NumRtpBytes(), info.receivers[0].bytes_rcvd); |
| 1490 | EXPECT_EQ(NumRtpPackets(), info.receivers[0].packets_rcvd); |
| 1491 | EXPECT_EQ(0.0, info.receivers[0].fraction_lost); |
| 1492 | EXPECT_EQ(0, info.receivers[0].packets_lost); |
| 1493 | // TODO(asapersson): Not set for webrtc. Handle missing stats. |
| 1494 | // EXPECT_EQ(0, info.receivers[0].packets_concealed); |
| 1495 | EXPECT_EQ(0, info.receivers[0].firs_sent); |
| 1496 | EXPECT_EQ(0, info.receivers[0].plis_sent); |
| 1497 | EXPECT_EQ(0, info.receivers[0].nacks_sent); |
| 1498 | EXPECT_EQ(kVideoWidth, info.receivers[0].frame_width); |
| 1499 | EXPECT_EQ(kVideoHeight, info.receivers[0].frame_height); |
| 1500 | EXPECT_GT(info.receivers[0].framerate_rcvd, 0); |
| 1501 | EXPECT_GT(info.receivers[0].framerate_decoded, 0); |
| 1502 | EXPECT_GT(info.receivers[0].framerate_output, 0); |
| 1503 | |
| 1504 | EXPECT_EQ(1U, info.receive_codecs.count(DefaultCodec().id)); |
| 1505 | EXPECT_EQ(DefaultCodec().ToCodecParameters(), |
| 1506 | info.receive_codecs[DefaultCodec().id]); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1507 | } |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1508 | |
| 1509 | // Test that stats work properly for a conf call with multiple recv streams. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1510 | TEST_F(WebRtcVideoChannelBaseTest, GetStatsMultipleRecvStreams) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1511 | cricket::FakeVideoRenderer renderer1, renderer2; |
| 1512 | EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
| 1513 | cricket::VideoSendParameters parameters; |
| 1514 | parameters.codecs.push_back(DefaultCodec()); |
| 1515 | parameters.conference_mode = true; |
| 1516 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 1517 | EXPECT_TRUE(SetSend(true)); |
| 1518 | EXPECT_TRUE(channel_->AddRecvStream( |
| 1519 | cricket::StreamParams::CreateLegacy(1))); |
| 1520 | EXPECT_TRUE(channel_->AddRecvStream( |
| 1521 | cricket::StreamParams::CreateLegacy(2))); |
| 1522 | EXPECT_TRUE(channel_->SetSink(1, &renderer1)); |
| 1523 | EXPECT_TRUE(channel_->SetSink(2, &renderer2)); |
| 1524 | EXPECT_EQ(0, renderer1.num_rendered_frames()); |
| 1525 | EXPECT_EQ(0, renderer2.num_rendered_frames()); |
| 1526 | std::vector<uint32_t> ssrcs; |
| 1527 | ssrcs.push_back(1); |
| 1528 | ssrcs.push_back(2); |
| 1529 | network_interface_.SetConferenceMode(true, ssrcs); |
| 1530 | EXPECT_TRUE(SendFrame()); |
| 1531 | EXPECT_FRAME_ON_RENDERER_WAIT(renderer1, 1, kVideoWidth, kVideoHeight, |
| 1532 | kTimeout); |
| 1533 | EXPECT_FRAME_ON_RENDERER_WAIT(renderer2, 1, kVideoWidth, kVideoHeight, |
| 1534 | kTimeout); |
| 1535 | |
| 1536 | EXPECT_TRUE(channel_->SetSend(false)); |
| 1537 | |
| 1538 | cricket::VideoMediaInfo info; |
| 1539 | EXPECT_TRUE(channel_->GetStats(&info)); |
| 1540 | ASSERT_EQ(1U, info.senders.size()); |
| 1541 | // TODO(whyuan): bytes_sent and bytes_rcvd are different. Are both payload? |
| 1542 | // For webrtc, bytes_sent does not include the RTP header length. |
| 1543 | EXPECT_GT(GetSenderStats(0).bytes_sent, 0); |
| 1544 | EXPECT_EQ_WAIT(NumRtpPackets(), GetSenderStats(0).packets_sent, kTimeout); |
| 1545 | EXPECT_EQ(kVideoWidth, GetSenderStats(0).send_frame_width); |
| 1546 | EXPECT_EQ(kVideoHeight, GetSenderStats(0).send_frame_height); |
| 1547 | |
| 1548 | ASSERT_EQ(2U, info.receivers.size()); |
| 1549 | for (size_t i = 0; i < info.receivers.size(); ++i) { |
| 1550 | EXPECT_EQ(1U, GetReceiverStats(i).ssrcs().size()); |
| 1551 | EXPECT_EQ(i + 1, GetReceiverStats(i).ssrcs()[0]); |
| 1552 | EXPECT_EQ_WAIT(NumRtpBytes(), GetReceiverStats(i).bytes_rcvd, kTimeout); |
| 1553 | EXPECT_EQ_WAIT(NumRtpPackets(), GetReceiverStats(i).packets_rcvd, |
| 1554 | kTimeout); |
| 1555 | EXPECT_EQ_WAIT(kVideoWidth, GetReceiverStats(i).frame_width, kTimeout); |
| 1556 | EXPECT_EQ_WAIT(kVideoHeight, GetReceiverStats(i).frame_height, kTimeout); |
| 1557 | } |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1558 | } |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1559 | |
| 1560 | // Test that stats work properly for a conf call with multiple send streams. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1561 | TEST_F(WebRtcVideoChannelBaseTest, GetStatsMultipleSendStreams) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1562 | // Normal setup; note that we set the SSRC explicitly to ensure that |
| 1563 | // it will come first in the senders map. |
| 1564 | EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
| 1565 | cricket::VideoSendParameters parameters; |
| 1566 | parameters.codecs.push_back(DefaultCodec()); |
| 1567 | parameters.conference_mode = true; |
| 1568 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 1569 | EXPECT_TRUE(channel_->AddRecvStream( |
| 1570 | cricket::StreamParams::CreateLegacy(kSsrc))); |
| 1571 | EXPECT_TRUE(channel_->SetSink(kSsrc, &renderer_)); |
| 1572 | EXPECT_TRUE(SetSend(true)); |
| 1573 | EXPECT_TRUE(SendFrame()); |
| 1574 | EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); |
| 1575 | EXPECT_FRAME_WAIT(1, kVideoWidth, kVideoHeight, kTimeout); |
| 1576 | |
| 1577 | // Add an additional capturer, and hook up a renderer to receive it. |
| 1578 | cricket::FakeVideoRenderer renderer2; |
| 1579 | std::unique_ptr<cricket::FakeVideoCapturerWithTaskQueue> capturer( |
| 1580 | CreateFakeVideoCapturer()); |
| 1581 | const int kTestWidth = 160; |
| 1582 | const int kTestHeight = 120; |
| 1583 | cricket::VideoFormat format(kTestWidth, kTestHeight, |
| 1584 | cricket::VideoFormat::FpsToInterval(5), |
| 1585 | cricket::FOURCC_I420); |
| 1586 | EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format)); |
| 1587 | EXPECT_TRUE(channel_->AddSendStream( |
| 1588 | cricket::StreamParams::CreateLegacy(5678))); |
| 1589 | EXPECT_TRUE(channel_->SetVideoSend(5678, nullptr, capturer.get())); |
| 1590 | EXPECT_TRUE(channel_->AddRecvStream( |
| 1591 | cricket::StreamParams::CreateLegacy(5678))); |
| 1592 | EXPECT_TRUE(channel_->SetSink(5678, &renderer2)); |
| 1593 | EXPECT_TRUE(capturer->CaptureCustomFrame(kTestWidth, kTestHeight)); |
| 1594 | EXPECT_FRAME_ON_RENDERER_WAIT( |
| 1595 | renderer2, 1, kTestWidth, kTestHeight, kTimeout); |
| 1596 | |
| 1597 | // Get stats, and make sure they are correct for two senders. We wait until |
| 1598 | // the number of expected packets have been sent to avoid races where we |
| 1599 | // check stats before it has been updated. |
| 1600 | cricket::VideoMediaInfo info; |
| 1601 | for (uint32_t i = 0; i < kTimeout; ++i) { |
| 1602 | rtc::Thread::Current()->ProcessMessages(1); |
| 1603 | EXPECT_TRUE(channel_->GetStats(&info)); |
| 1604 | ASSERT_EQ(2U, info.senders.size()); |
| 1605 | if (info.senders[0].packets_sent + info.senders[1].packets_sent == |
| 1606 | NumRtpPackets()) { |
| 1607 | // Stats have been updated for both sent frames, expectations can be |
| 1608 | // checked now. |
| 1609 | break; |
| 1610 | } |
| 1611 | } |
| 1612 | EXPECT_EQ(NumRtpPackets(), |
| 1613 | info.senders[0].packets_sent + info.senders[1].packets_sent) |
| 1614 | << "Timed out while waiting for packet counts for all sent packets."; |
| 1615 | EXPECT_EQ(1U, info.senders[0].ssrcs().size()); |
| 1616 | EXPECT_EQ(1234U, info.senders[0].ssrcs()[0]); |
| 1617 | EXPECT_EQ(kVideoWidth, info.senders[0].send_frame_width); |
| 1618 | EXPECT_EQ(kVideoHeight, info.senders[0].send_frame_height); |
| 1619 | EXPECT_EQ(1U, info.senders[1].ssrcs().size()); |
| 1620 | EXPECT_EQ(5678U, info.senders[1].ssrcs()[0]); |
| 1621 | EXPECT_EQ(kTestWidth, info.senders[1].send_frame_width); |
| 1622 | EXPECT_EQ(kTestHeight, info.senders[1].send_frame_height); |
| 1623 | // The capturer must be unregistered here as it runs out of it's scope next. |
| 1624 | channel_->SetVideoSend(5678, nullptr, nullptr); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1625 | } |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 1626 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1627 | // Test that we can set the bandwidth. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1628 | TEST_F(WebRtcVideoChannelBaseTest, SetSendBandwidth) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1629 | cricket::VideoSendParameters parameters; |
| 1630 | parameters.codecs.push_back(DefaultCodec()); |
| 1631 | parameters.max_bandwidth_bps = -1; // <= 0 means unlimited. |
| 1632 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 1633 | parameters.max_bandwidth_bps = 128 * 1024; |
| 1634 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1635 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1636 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1637 | // Test that we can set the SSRC for the default send source. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1638 | TEST_F(WebRtcVideoChannelBaseTest, SetSendSsrc) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1639 | EXPECT_TRUE(SetDefaultCodec()); |
| 1640 | EXPECT_TRUE(SetSend(true)); |
| 1641 | EXPECT_TRUE(SendFrame()); |
| 1642 | EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); |
| 1643 | uint32_t ssrc = 0; |
| 1644 | std::unique_ptr<const rtc::CopyOnWriteBuffer> p(GetRtpPacket(0)); |
| 1645 | ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); |
| 1646 | EXPECT_EQ(kSsrc, ssrc); |
| 1647 | // Packets are being paced out, so these can mismatch between the first and |
| 1648 | // second call to NumRtpPackets until pending packets are paced out. |
| 1649 | EXPECT_EQ_WAIT(NumRtpPackets(), NumRtpPackets(ssrc), kTimeout); |
| 1650 | EXPECT_EQ_WAIT(NumRtpBytes(), NumRtpBytes(ssrc), kTimeout); |
| 1651 | EXPECT_EQ(1, NumSentSsrcs()); |
| 1652 | EXPECT_EQ(0, NumRtpPackets(kSsrc - 1)); |
| 1653 | EXPECT_EQ(0, NumRtpBytes(kSsrc - 1)); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1654 | } |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1655 | |
| 1656 | // Test that we can set the SSRC even after codecs are set. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1657 | TEST_F(WebRtcVideoChannelBaseTest, SetSendSsrcAfterSetCodecs) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1658 | // Remove stream added in Setup. |
| 1659 | EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); |
| 1660 | EXPECT_TRUE(SetDefaultCodec()); |
| 1661 | EXPECT_TRUE(channel_->AddSendStream( |
| 1662 | cricket::StreamParams::CreateLegacy(999))); |
| 1663 | EXPECT_TRUE( |
| 1664 | channel_->SetVideoSend(999u, nullptr, video_capturer_.get())); |
| 1665 | EXPECT_TRUE(SetSend(true)); |
| 1666 | EXPECT_TRUE(WaitAndSendFrame(0)); |
| 1667 | EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); |
| 1668 | uint32_t ssrc = 0; |
| 1669 | std::unique_ptr<const rtc::CopyOnWriteBuffer> p(GetRtpPacket(0)); |
| 1670 | ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); |
| 1671 | EXPECT_EQ(999u, ssrc); |
| 1672 | // Packets are being paced out, so these can mismatch between the first and |
| 1673 | // second call to NumRtpPackets until pending packets are paced out. |
| 1674 | EXPECT_EQ_WAIT(NumRtpPackets(), NumRtpPackets(ssrc), kTimeout); |
| 1675 | EXPECT_EQ_WAIT(NumRtpBytes(), NumRtpBytes(ssrc), kTimeout); |
| 1676 | EXPECT_EQ(1, NumSentSsrcs()); |
| 1677 | EXPECT_EQ(0, NumRtpPackets(kSsrc)); |
| 1678 | EXPECT_EQ(0, NumRtpBytes(kSsrc)); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1679 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1680 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1681 | // Test that we can set the default video renderer before and after |
| 1682 | // media is received. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1683 | TEST_F(WebRtcVideoChannelBaseTest, SetSink) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1684 | uint8_t data1[] = { |
| 1685 | 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 1686 | |
| 1687 | rtc::CopyOnWriteBuffer packet1(data1, sizeof(data1)); |
| 1688 | rtc::SetBE32(packet1.data() + 8, kSsrc); |
| 1689 | channel_->SetSink(kDefaultReceiveSsrc, NULL); |
| 1690 | EXPECT_TRUE(SetDefaultCodec()); |
| 1691 | EXPECT_TRUE(SetSend(true)); |
| 1692 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 1693 | channel_->OnPacketReceived(&packet1, rtc::PacketTime()); |
| 1694 | EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); |
| 1695 | EXPECT_TRUE(SendFrame()); |
| 1696 | EXPECT_FRAME_WAIT(1, kVideoWidth, kVideoHeight, kTimeout); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1697 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1698 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1699 | // Tests setting up and configuring a send stream. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1700 | TEST_F(WebRtcVideoChannelBaseTest, AddRemoveSendStreams) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1701 | EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
| 1702 | EXPECT_TRUE(SetSend(true)); |
| 1703 | EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); |
| 1704 | EXPECT_TRUE(SendFrame()); |
| 1705 | EXPECT_FRAME_WAIT(1, kVideoWidth, kVideoHeight, kTimeout); |
| 1706 | EXPECT_GT(NumRtpPackets(), 0); |
| 1707 | uint32_t ssrc = 0; |
| 1708 | size_t last_packet = NumRtpPackets() - 1; |
| 1709 | std::unique_ptr<const rtc::CopyOnWriteBuffer> |
| 1710 | p(GetRtpPacket(static_cast<int>(last_packet))); |
| 1711 | ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); |
| 1712 | EXPECT_EQ(kSsrc, ssrc); |
| 1713 | |
| 1714 | // Remove the send stream that was added during Setup. |
| 1715 | EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); |
| 1716 | int rtp_packets = NumRtpPackets(); |
| 1717 | |
| 1718 | EXPECT_TRUE(channel_->AddSendStream( |
| 1719 | cricket::StreamParams::CreateLegacy(789u))); |
| 1720 | EXPECT_TRUE( |
| 1721 | channel_->SetVideoSend(789u, nullptr, video_capturer_.get())); |
| 1722 | EXPECT_EQ(rtp_packets, NumRtpPackets()); |
| 1723 | // Wait 30ms to guarantee the engine does not drop the frame. |
| 1724 | EXPECT_TRUE(WaitAndSendFrame(30)); |
| 1725 | EXPECT_TRUE_WAIT(NumRtpPackets() > rtp_packets, kTimeout); |
| 1726 | |
| 1727 | last_packet = NumRtpPackets() - 1; |
| 1728 | p.reset(GetRtpPacket(static_cast<int>(last_packet))); |
| 1729 | ParseRtpPacket(p.get(), NULL, NULL, NULL, NULL, &ssrc, NULL); |
| 1730 | EXPECT_EQ(789u, ssrc); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1731 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1732 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1733 | // Tests the behavior of incoming streams in a conference scenario. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1734 | TEST_F(WebRtcVideoChannelBaseTest, SimulateConference) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1735 | cricket::FakeVideoRenderer renderer1, renderer2; |
| 1736 | EXPECT_TRUE(SetDefaultCodec()); |
| 1737 | cricket::VideoSendParameters parameters; |
| 1738 | parameters.codecs.push_back(DefaultCodec()); |
| 1739 | parameters.conference_mode = true; |
| 1740 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 1741 | EXPECT_TRUE(SetSend(true)); |
| 1742 | EXPECT_TRUE(channel_->AddRecvStream( |
| 1743 | cricket::StreamParams::CreateLegacy(1))); |
| 1744 | EXPECT_TRUE(channel_->AddRecvStream( |
| 1745 | cricket::StreamParams::CreateLegacy(2))); |
| 1746 | EXPECT_TRUE(channel_->SetSink(1, &renderer1)); |
| 1747 | EXPECT_TRUE(channel_->SetSink(2, &renderer2)); |
| 1748 | EXPECT_EQ(0, renderer1.num_rendered_frames()); |
| 1749 | EXPECT_EQ(0, renderer2.num_rendered_frames()); |
| 1750 | std::vector<uint32_t> ssrcs; |
| 1751 | ssrcs.push_back(1); |
| 1752 | ssrcs.push_back(2); |
| 1753 | network_interface_.SetConferenceMode(true, ssrcs); |
| 1754 | EXPECT_TRUE(SendFrame()); |
| 1755 | EXPECT_FRAME_ON_RENDERER_WAIT(renderer1, 1, kVideoWidth, kVideoHeight, |
| 1756 | kTimeout); |
| 1757 | EXPECT_FRAME_ON_RENDERER_WAIT(renderer2, 1, kVideoWidth, kVideoHeight, |
| 1758 | kTimeout); |
| 1759 | |
| 1760 | std::unique_ptr<const rtc::CopyOnWriteBuffer> p(GetRtpPacket(0)); |
| 1761 | EXPECT_EQ(DefaultCodec().id, GetPayloadType(p.get())); |
| 1762 | EXPECT_EQ(kVideoWidth, renderer1.width()); |
| 1763 | EXPECT_EQ(kVideoHeight, renderer1.height()); |
| 1764 | EXPECT_EQ(kVideoWidth, renderer2.width()); |
| 1765 | EXPECT_EQ(kVideoHeight, renderer2.height()); |
| 1766 | EXPECT_TRUE(channel_->RemoveRecvStream(2)); |
| 1767 | EXPECT_TRUE(channel_->RemoveRecvStream(1)); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1768 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1769 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1770 | // Tests that we can add and remove capturers and frames are sent out properly |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1771 | TEST_F(WebRtcVideoChannelBaseTest, DISABLED_AddRemoveCapturer) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1772 | using cricket::VideoCodec; |
| 1773 | using cricket::VideoOptions; |
| 1774 | using cricket::VideoFormat; |
| 1775 | using cricket::FOURCC_I420; |
| 1776 | |
| 1777 | VideoCodec codec = DefaultCodec(); |
| 1778 | const int time_between_send_ms = VideoFormat::FpsToInterval(kFramerate); |
| 1779 | EXPECT_TRUE(SetOneCodec(codec)); |
| 1780 | EXPECT_TRUE(SetSend(true)); |
| 1781 | EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); |
| 1782 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 1783 | EXPECT_TRUE(SendFrame()); |
| 1784 | EXPECT_FRAME_WAIT(1, kVideoWidth, kVideoHeight, kTimeout); |
| 1785 | std::unique_ptr<cricket::FakeVideoCapturerWithTaskQueue> capturer( |
| 1786 | CreateFakeVideoCapturer()); |
| 1787 | |
| 1788 | // TODO(nisse): This testcase fails if we don't configure |
| 1789 | // screencast. It's unclear why, I see nothing obvious in this |
| 1790 | // test which is related to screencast logic. |
| 1791 | VideoOptions video_options; |
| 1792 | video_options.is_screencast = true; |
| 1793 | channel_->SetVideoSend(kSsrc, &video_options, nullptr); |
| 1794 | |
| 1795 | VideoFormat format(480, 360, VideoFormat::FpsToInterval(30), FOURCC_I420); |
| 1796 | EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format)); |
| 1797 | // All capturers start generating frames with the same timestamp. ViE does |
| 1798 | // not allow the same timestamp to be used. Capture one frame before |
| 1799 | // associating the capturer with the channel. |
| 1800 | EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height)); |
| 1801 | |
| 1802 | int captured_frames = 1; |
| 1803 | for (int iterations = 0; iterations < 2; ++iterations) { |
| 1804 | EXPECT_TRUE(channel_->SetVideoSend(kSsrc, nullptr, capturer.get())); |
| 1805 | rtc::Thread::Current()->ProcessMessages(time_between_send_ms); |
| 1806 | EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height)); |
| 1807 | ++captured_frames; |
| 1808 | // Wait until frame of right size is captured. |
| 1809 | EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames && |
| 1810 | format.width == renderer_.width() && |
| 1811 | format.height == renderer_.height() && |
| 1812 | !renderer_.black_frame(), kTimeout); |
| 1813 | EXPECT_GE(renderer_.num_rendered_frames(), captured_frames); |
| 1814 | EXPECT_EQ(format.width, renderer_.width()); |
| 1815 | EXPECT_EQ(format.height, renderer_.height()); |
| 1816 | captured_frames = renderer_.num_rendered_frames() + 1; |
| 1817 | EXPECT_FALSE(renderer_.black_frame()); |
| 1818 | EXPECT_TRUE(channel_->SetVideoSend(kSsrc, nullptr, nullptr)); |
| 1819 | // Make sure a black frame is generated within the specified timeout. |
| 1820 | // The black frame should be the resolution of the previous frame to |
| 1821 | // prevent expensive encoder reconfigurations. |
| 1822 | EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames && |
| 1823 | format.width == renderer_.width() && |
| 1824 | format.height == renderer_.height() && |
| 1825 | renderer_.black_frame(), kTimeout); |
| 1826 | EXPECT_GE(renderer_.num_rendered_frames(), captured_frames); |
| 1827 | EXPECT_EQ(format.width, renderer_.width()); |
| 1828 | EXPECT_EQ(format.height, renderer_.height()); |
| 1829 | EXPECT_TRUE(renderer_.black_frame()); |
| 1830 | |
| 1831 | // The black frame has the same timestamp as the next frame since it's |
| 1832 | // timestamp is set to the last frame's timestamp + interval. WebRTC will |
| 1833 | // not render a frame with the same timestamp so capture another frame |
| 1834 | // with the frame capturer to increment the next frame's timestamp. |
| 1835 | EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height)); |
| 1836 | } |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1837 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1838 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1839 | // Tests that if SetVideoSend is called with a NULL capturer after the |
| 1840 | // capturer was already removed, the application doesn't crash (and no black |
| 1841 | // frame is sent). |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1842 | TEST_F(WebRtcVideoChannelBaseTest, RemoveCapturerWithoutAdd) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1843 | EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
| 1844 | EXPECT_TRUE(SetSend(true)); |
| 1845 | EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); |
| 1846 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 1847 | EXPECT_TRUE(SendFrame()); |
| 1848 | EXPECT_FRAME_WAIT(1, kVideoWidth, kVideoHeight, kTimeout); |
| 1849 | // Wait for one frame so they don't get dropped because we send frames too |
| 1850 | // tightly. |
| 1851 | rtc::Thread::Current()->ProcessMessages(30); |
| 1852 | // Remove the capturer. |
| 1853 | EXPECT_TRUE(channel_->SetVideoSend(kSsrc, nullptr, nullptr)); |
| 1854 | |
| 1855 | // No capturer was added, so this SetVideoSend shouldn't do anything. |
| 1856 | EXPECT_TRUE(channel_->SetVideoSend(kSsrc, nullptr, nullptr)); |
| 1857 | rtc::Thread::Current()->ProcessMessages(300); |
| 1858 | // Verify no more frames were sent. |
| 1859 | EXPECT_EQ(1, renderer_.num_rendered_frames()); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1860 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1861 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1862 | // Tests that we can add and remove capturer as unique sources. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1863 | TEST_F(WebRtcVideoChannelBaseTest, AddRemoveCapturerMultipleSources) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1864 | // WebRTC implementation will drop frames if pushed to quickly. Wait the |
| 1865 | // interval time to avoid that. |
| 1866 | // WebRTC implementation will drop frames if pushed to quickly. Wait the |
| 1867 | // interval time to avoid that. |
| 1868 | // Set up the stream associated with the engine. |
| 1869 | EXPECT_TRUE(channel_->AddRecvStream( |
| 1870 | cricket::StreamParams::CreateLegacy(kSsrc))); |
| 1871 | EXPECT_TRUE(channel_->SetSink(kSsrc, &renderer_)); |
| 1872 | cricket::VideoFormat capture_format( |
| 1873 | kVideoWidth, kVideoHeight, |
| 1874 | cricket::VideoFormat::FpsToInterval(kFramerate), cricket::FOURCC_I420); |
| 1875 | // Set up additional stream 1. |
| 1876 | cricket::FakeVideoRenderer renderer1; |
| 1877 | EXPECT_FALSE(channel_->SetSink(1, &renderer1)); |
| 1878 | EXPECT_TRUE(channel_->AddRecvStream( |
| 1879 | cricket::StreamParams::CreateLegacy(1))); |
| 1880 | EXPECT_TRUE(channel_->SetSink(1, &renderer1)); |
| 1881 | EXPECT_TRUE(channel_->AddSendStream( |
| 1882 | cricket::StreamParams::CreateLegacy(1))); |
| 1883 | std::unique_ptr<cricket::FakeVideoCapturerWithTaskQueue> capturer1( |
| 1884 | CreateFakeVideoCapturer()); |
| 1885 | EXPECT_EQ(cricket::CS_RUNNING, capturer1->Start(capture_format)); |
| 1886 | // Set up additional stream 2. |
| 1887 | cricket::FakeVideoRenderer renderer2; |
| 1888 | EXPECT_FALSE(channel_->SetSink(2, &renderer2)); |
| 1889 | EXPECT_TRUE(channel_->AddRecvStream( |
| 1890 | cricket::StreamParams::CreateLegacy(2))); |
| 1891 | EXPECT_TRUE(channel_->SetSink(2, &renderer2)); |
| 1892 | EXPECT_TRUE(channel_->AddSendStream( |
| 1893 | cricket::StreamParams::CreateLegacy(2))); |
| 1894 | std::unique_ptr<cricket::FakeVideoCapturerWithTaskQueue> capturer2( |
| 1895 | CreateFakeVideoCapturer()); |
| 1896 | EXPECT_EQ(cricket::CS_RUNNING, capturer2->Start(capture_format)); |
| 1897 | // State for all the streams. |
| 1898 | EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
| 1899 | // A limitation in the lmi implementation requires that SetVideoSend() is |
| 1900 | // called after SetOneCodec(). |
| 1901 | // TODO(hellner): this seems like an unnecessary constraint, fix it. |
| 1902 | EXPECT_TRUE(channel_->SetVideoSend(1, nullptr, capturer1.get())); |
| 1903 | EXPECT_TRUE(channel_->SetVideoSend(2, nullptr, capturer2.get())); |
| 1904 | EXPECT_TRUE(SetSend(true)); |
| 1905 | // Test capturer associated with engine. |
| 1906 | const int kTestWidth = 160; |
| 1907 | const int kTestHeight = 120; |
| 1908 | EXPECT_TRUE(capturer1->CaptureCustomFrame(kTestWidth, kTestHeight)); |
| 1909 | EXPECT_FRAME_ON_RENDERER_WAIT( |
| 1910 | renderer1, 1, kTestWidth, kTestHeight, kTimeout); |
| 1911 | // Capture a frame with additional capturer2, frames should be received |
| 1912 | EXPECT_TRUE(capturer2->CaptureCustomFrame(kTestWidth, kTestHeight)); |
| 1913 | EXPECT_FRAME_ON_RENDERER_WAIT( |
| 1914 | renderer2, 1, kTestWidth, kTestHeight, kTimeout); |
| 1915 | // Successfully remove the capturer. |
| 1916 | EXPECT_TRUE(channel_->SetVideoSend(kSsrc, nullptr, nullptr)); |
| 1917 | // The capturers must be unregistered here as it runs out of it's scope |
| 1918 | // next. |
| 1919 | EXPECT_TRUE(channel_->SetVideoSend(1, nullptr, nullptr)); |
| 1920 | EXPECT_TRUE(channel_->SetVideoSend(2, nullptr, nullptr)); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1921 | } |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1922 | |
| 1923 | // Tests empty StreamParams is rejected. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1924 | TEST_F(WebRtcVideoChannelBaseTest, RejectEmptyStreamParams) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1925 | // Remove the send stream that was added during Setup. |
| 1926 | EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); |
| 1927 | |
| 1928 | cricket::StreamParams empty; |
| 1929 | EXPECT_FALSE(channel_->AddSendStream(empty)); |
| 1930 | EXPECT_TRUE(channel_->AddSendStream( |
| 1931 | cricket::StreamParams::CreateLegacy(789u))); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1932 | } |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1933 | |
| 1934 | // Test that multiple send streams can be created and deleted properly. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1935 | TEST_F(WebRtcVideoChannelBaseTest, MultipleSendStreams) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1936 | // Remove stream added in Setup. I.e. remove stream corresponding to default |
| 1937 | // channel. |
| 1938 | EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); |
| 1939 | const unsigned int kSsrcsSize = sizeof(kSsrcs4)/sizeof(kSsrcs4[0]); |
| 1940 | for (unsigned int i = 0; i < kSsrcsSize; ++i) { |
| 1941 | EXPECT_TRUE(channel_->AddSendStream( |
| 1942 | cricket::StreamParams::CreateLegacy(kSsrcs4[i]))); |
| 1943 | } |
| 1944 | // Delete one of the non default channel streams, let the destructor delete |
| 1945 | // the remaining ones. |
| 1946 | EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[kSsrcsSize - 1])); |
| 1947 | // Stream should already be deleted. |
| 1948 | EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[kSsrcsSize - 1])); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1949 | } |
pbos@webrtc.org | c4175b9 | 2014-09-03 15:25:49 +0000 | [diff] [blame] | 1950 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 1951 | TEST_F(WebRtcVideoChannelBaseTest, SendAndReceiveVp8Vga) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 1952 | SendAndReceive(GetEngineCodec("VP8")); |
pbos@webrtc.org | 9359cb3 | 2014-07-23 15:44:48 +0000 | [diff] [blame] | 1953 | } |
| 1954 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 1955 | TEST_F(WebRtcVideoChannelBaseTest, SendAndReceiveVp8Qvga) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 1956 | SendAndReceive(GetEngineCodec("VP8")); |
pbos@webrtc.org | 9359cb3 | 2014-07-23 15:44:48 +0000 | [diff] [blame] | 1957 | } |
| 1958 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 1959 | TEST_F(WebRtcVideoChannelBaseTest, SendAndReceiveVp8SvcQqvga) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 1960 | SendAndReceive(GetEngineCodec("VP8")); |
pbos@webrtc.org | 9359cb3 | 2014-07-23 15:44:48 +0000 | [diff] [blame] | 1961 | } |
| 1962 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 1963 | TEST_F(WebRtcVideoChannelBaseTest, TwoStreamsSendAndReceive) { |
Peter Boström | d1f584b | 2016-04-20 16:31:53 +0200 | [diff] [blame] | 1964 | // Set a high bitrate to not be downscaled by VP8 due to low initial start |
| 1965 | // bitrates. This currently happens at <250k, and two streams sharing 300k |
| 1966 | // initially will use QVGA instead of VGA. |
| 1967 | // TODO(pbos): Set up the quality scaler so that both senders reliably start |
| 1968 | // at QVGA, then verify that instead. |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 1969 | cricket::VideoCodec codec = GetEngineCodec("VP8"); |
Peter Boström | d1f584b | 2016-04-20 16:31:53 +0200 | [diff] [blame] | 1970 | codec.params[kCodecParamStartBitrate] = "1000000"; |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1971 | TwoStreamsSendAndReceive(codec); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1972 | } |
| 1973 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 1974 | class WebRtcVideoChannelTest : public WebRtcVideoEngineTest { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1975 | public: |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 1976 | WebRtcVideoChannelTest() : WebRtcVideoChannelTest("") {} |
| 1977 | explicit WebRtcVideoChannelTest(const char* field_trials) |
| 1978 | : WebRtcVideoEngineTest(field_trials), last_ssrc_(0) {} |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 1979 | void SetUp() override { |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 1980 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
| 1981 | encoder_factory_->AddSupportedVideoCodecType("VP9"); |
| 1982 | #if defined(WEBRTC_USE_H264) |
| 1983 | encoder_factory_->AddSupportedVideoCodecType("H264"); |
| 1984 | #endif |
| 1985 | |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 1986 | fake_call_.reset(new FakeCall()); |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 1987 | channel_.reset(engine_.CreateChannel(fake_call_.get(), GetMediaConfig(), |
| 1988 | VideoOptions())); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 1989 | channel_->OnReadyToSend(true); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1990 | last_ssrc_ = 123; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 1991 | send_parameters_.codecs = engine_.codecs(); |
| 1992 | recv_parameters_.codecs = engine_.codecs(); |
| 1993 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1994 | } |
| 1995 | |
| 1996 | protected: |
| 1997 | FakeVideoSendStream* AddSendStream() { |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1998 | return AddSendStream(StreamParams::CreateLegacy(++last_ssrc_)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | FakeVideoSendStream* AddSendStream(const StreamParams& sp) { |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2002 | size_t num_streams = fake_call_->GetVideoSendStreams().size(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2003 | EXPECT_TRUE(channel_->AddSendStream(sp)); |
| 2004 | std::vector<FakeVideoSendStream*> streams = |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2005 | fake_call_->GetVideoSendStreams(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2006 | EXPECT_EQ(num_streams + 1, streams.size()); |
| 2007 | return streams[streams.size() - 1]; |
| 2008 | } |
| 2009 | |
| 2010 | std::vector<FakeVideoSendStream*> GetFakeSendStreams() { |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2011 | return fake_call_->GetVideoSendStreams(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2012 | } |
| 2013 | |
| 2014 | FakeVideoReceiveStream* AddRecvStream() { |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2015 | return AddRecvStream(StreamParams::CreateLegacy(++last_ssrc_)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
| 2018 | FakeVideoReceiveStream* AddRecvStream(const StreamParams& sp) { |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2019 | size_t num_streams = fake_call_->GetVideoReceiveStreams().size(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2020 | EXPECT_TRUE(channel_->AddRecvStream(sp)); |
| 2021 | std::vector<FakeVideoReceiveStream*> streams = |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2022 | fake_call_->GetVideoReceiveStreams(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2023 | EXPECT_EQ(num_streams + 1, streams.size()); |
| 2024 | return streams[streams.size() - 1]; |
| 2025 | } |
| 2026 | |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2027 | void SetSendCodecsShouldWorkForBitrates(const char* min_bitrate_kbps, |
| 2028 | int expected_min_bitrate_bps, |
| 2029 | const char* start_bitrate_kbps, |
| 2030 | int expected_start_bitrate_bps, |
| 2031 | const char* max_bitrate_kbps, |
| 2032 | int expected_max_bitrate_bps) { |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 2033 | ExpectSetBitrateParameters(expected_min_bitrate_bps, |
| 2034 | expected_start_bitrate_bps, |
| 2035 | expected_max_bitrate_bps); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2036 | auto& codecs = send_parameters_.codecs; |
| 2037 | codecs.clear(); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2038 | codecs.push_back(GetEngineCodec("VP8")); |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2039 | codecs[0].params[kCodecParamMinBitrate] = min_bitrate_kbps; |
| 2040 | codecs[0].params[kCodecParamStartBitrate] = start_bitrate_kbps; |
| 2041 | codecs[0].params[kCodecParamMaxBitrate] = max_bitrate_kbps; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2042 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 2043 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2044 | |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 2045 | void ExpectSetBitrateParameters(int min_bitrate_bps, |
| 2046 | int start_bitrate_bps, |
| 2047 | int max_bitrate_bps) { |
| 2048 | EXPECT_CALL( |
| 2049 | *fake_call_->GetMockTransportControllerSend(), |
| 2050 | SetSdpBitrateParameters(AllOf( |
| 2051 | Field(&BitrateConstraints::min_bitrate_bps, min_bitrate_bps), |
| 2052 | Field(&BitrateConstraints::start_bitrate_bps, start_bitrate_bps), |
| 2053 | Field(&BitrateConstraints::max_bitrate_bps, max_bitrate_bps)))); |
| 2054 | } |
| 2055 | |
| 2056 | void ExpectSetMaxBitrate(int max_bitrate_bps) { |
| 2057 | EXPECT_CALL(*fake_call_->GetMockTransportControllerSend(), |
| 2058 | SetSdpBitrateParameters(Field( |
| 2059 | &BitrateConstraints::max_bitrate_bps, max_bitrate_bps))); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2060 | } |
| 2061 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2062 | void TestSetSendRtpHeaderExtensions(const std::string& ext_uri) { |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2063 | // Enable extension. |
| 2064 | const int id = 1; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2065 | cricket::VideoSendParameters parameters = send_parameters_; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2066 | parameters.extensions.push_back(RtpExtension(ext_uri, id)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2067 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2068 | FakeVideoSendStream* send_stream = |
| 2069 | AddSendStream(cricket::StreamParams::CreateLegacy(123)); |
| 2070 | |
| 2071 | // Verify the send extension id. |
| 2072 | ASSERT_EQ(1u, send_stream->GetConfig().rtp.extensions.size()); |
| 2073 | EXPECT_EQ(id, send_stream->GetConfig().rtp.extensions[0].id); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2074 | EXPECT_EQ(ext_uri, send_stream->GetConfig().rtp.extensions[0].uri); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2075 | // Verify call with same set of extensions returns true. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2076 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2077 | // Verify that SetSendRtpHeaderExtensions doesn't implicitly add them for |
| 2078 | // receivers. |
| 2079 | EXPECT_TRUE(AddRecvStream(cricket::StreamParams::CreateLegacy(123)) |
| 2080 | ->GetConfig() |
| 2081 | .rtp.extensions.empty()); |
| 2082 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2083 | // Verify that existing RTP header extensions can be removed. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2084 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 2085 | ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| 2086 | send_stream = fake_call_->GetVideoSendStreams()[0]; |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2087 | EXPECT_TRUE(send_stream->GetConfig().rtp.extensions.empty()); |
| 2088 | |
| 2089 | // Verify that adding receive RTP header extensions adds them for existing |
| 2090 | // streams. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2091 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 2092 | send_stream = fake_call_->GetVideoSendStreams()[0]; |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2093 | ASSERT_EQ(1u, send_stream->GetConfig().rtp.extensions.size()); |
| 2094 | EXPECT_EQ(id, send_stream->GetConfig().rtp.extensions[0].id); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2095 | EXPECT_EQ(ext_uri, send_stream->GetConfig().rtp.extensions[0].uri); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2096 | } |
| 2097 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2098 | void TestSetRecvRtpHeaderExtensions(const std::string& ext_uri) { |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2099 | // Enable extension. |
| 2100 | const int id = 1; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2101 | cricket::VideoRecvParameters parameters = recv_parameters_; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2102 | parameters.extensions.push_back(RtpExtension(ext_uri, id)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2103 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2104 | |
| 2105 | FakeVideoReceiveStream* recv_stream = |
| 2106 | AddRecvStream(cricket::StreamParams::CreateLegacy(123)); |
| 2107 | |
| 2108 | // Verify the recv extension id. |
| 2109 | ASSERT_EQ(1u, recv_stream->GetConfig().rtp.extensions.size()); |
| 2110 | EXPECT_EQ(id, recv_stream->GetConfig().rtp.extensions[0].id); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2111 | EXPECT_EQ(ext_uri, recv_stream->GetConfig().rtp.extensions[0].uri); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2112 | // Verify call with same set of extensions returns true. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2113 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2114 | |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2115 | // Verify that SetRecvRtpHeaderExtensions doesn't implicitly add them for |
| 2116 | // senders. |
| 2117 | EXPECT_TRUE(AddSendStream(cricket::StreamParams::CreateLegacy(123)) |
| 2118 | ->GetConfig() |
| 2119 | .rtp.extensions.empty()); |
| 2120 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2121 | // Verify that existing RTP header extensions can be removed. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2122 | EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 2123 | ASSERT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
| 2124 | recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2125 | EXPECT_TRUE(recv_stream->GetConfig().rtp.extensions.empty()); |
| 2126 | |
| 2127 | // Verify that adding receive RTP header extensions adds them for existing |
| 2128 | // streams. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2129 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 2130 | recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2131 | ASSERT_EQ(1u, recv_stream->GetConfig().rtp.extensions.size()); |
| 2132 | EXPECT_EQ(id, recv_stream->GetConfig().rtp.extensions[0].id); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2133 | EXPECT_EQ(ext_uri, recv_stream->GetConfig().rtp.extensions[0].uri); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2134 | } |
| 2135 | |
Stefan Holmer | bbaf363 | 2015-10-29 18:53:23 +0100 | [diff] [blame] | 2136 | void TestExtensionFilter(const std::vector<std::string>& extensions, |
| 2137 | const std::string& expected_extension) { |
| 2138 | cricket::VideoSendParameters parameters = send_parameters_; |
| 2139 | int expected_id = -1; |
| 2140 | int id = 1; |
| 2141 | for (const std::string& extension : extensions) { |
| 2142 | if (extension == expected_extension) |
| 2143 | expected_id = id; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2144 | parameters.extensions.push_back(RtpExtension(extension, id++)); |
Stefan Holmer | bbaf363 | 2015-10-29 18:53:23 +0100 | [diff] [blame] | 2145 | } |
| 2146 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 2147 | FakeVideoSendStream* send_stream = |
| 2148 | AddSendStream(cricket::StreamParams::CreateLegacy(123)); |
| 2149 | |
| 2150 | // Verify that only one of them has been set, and that it is the one with |
| 2151 | // highest priority (transport sequence number). |
| 2152 | ASSERT_EQ(1u, send_stream->GetConfig().rtp.extensions.size()); |
| 2153 | EXPECT_EQ(expected_id, send_stream->GetConfig().rtp.extensions[0].id); |
| 2154 | EXPECT_EQ(expected_extension, |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2155 | send_stream->GetConfig().rtp.extensions[0].uri); |
Stefan Holmer | bbaf363 | 2015-10-29 18:53:23 +0100 | [diff] [blame] | 2156 | } |
| 2157 | |
asapersson | 3c81a1a | 2017-06-14 05:52:21 -0700 | [diff] [blame] | 2158 | void TestDegradationPreference(bool resolution_scaling_enabled, |
| 2159 | bool fps_scaling_enabled); |
| 2160 | |
Erik Språng | efbde37 | 2015-04-29 16:21:28 +0200 | [diff] [blame] | 2161 | void TestCpuAdaptation(bool enable_overuse, bool is_screenshare); |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 2162 | void TestReceiverLocalSsrcConfiguration(bool receiver_first); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2163 | void TestReceiveUnsignaledSsrcPacket(uint8_t payload_type, |
| 2164 | bool expect_created_receive_stream); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2165 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2166 | FakeVideoSendStream* SetDenoisingOption( |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2167 | uint32_t ssrc, |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 2168 | FakeVideoCapturerWithTaskQueue* capturer, |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 2169 | bool enabled) { |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2170 | cricket::VideoOptions options; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 2171 | options.video_noise_reduction = enabled; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2172 | EXPECT_TRUE(channel_->SetVideoSend(ssrc, &options, capturer)); |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 2173 | // Options only take effect on the next frame. |
| 2174 | EXPECT_TRUE(capturer->CaptureFrame()); |
| 2175 | |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2176 | return fake_call_->GetVideoSendStreams().back(); |
| 2177 | } |
| 2178 | |
Peter Boström | 2feafdb | 2015-09-09 14:32:14 +0200 | [diff] [blame] | 2179 | FakeVideoSendStream* SetUpSimulcast(bool enabled, bool with_rtx) { |
| 2180 | const int kRtxSsrcOffset = 0xDEADBEEF; |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2181 | last_ssrc_ += 3; |
Peter Boström | 2feafdb | 2015-09-09 14:32:14 +0200 | [diff] [blame] | 2182 | std::vector<uint32_t> ssrcs; |
| 2183 | std::vector<uint32_t> rtx_ssrcs; |
| 2184 | uint32_t num_streams = enabled ? 3 : 1; |
| 2185 | for (uint32_t i = 0; i < num_streams; ++i) { |
| 2186 | uint32_t ssrc = last_ssrc_ + i; |
| 2187 | ssrcs.push_back(ssrc); |
| 2188 | if (with_rtx) { |
| 2189 | rtx_ssrcs.push_back(ssrc + kRtxSsrcOffset); |
| 2190 | } |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2191 | } |
Peter Boström | 2feafdb | 2015-09-09 14:32:14 +0200 | [diff] [blame] | 2192 | if (with_rtx) { |
| 2193 | return AddSendStream( |
| 2194 | cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); |
| 2195 | } |
| 2196 | return AddSendStream(CreateSimStreamParams("cname", ssrcs)); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2197 | } |
| 2198 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2199 | int GetMaxEncoderBitrate() { |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 2200 | std::vector<FakeVideoSendStream*> streams = |
| 2201 | fake_call_->GetVideoSendStreams(); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2202 | EXPECT_EQ(1u, streams.size()); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 2203 | FakeVideoSendStream* stream = streams[streams.size() - 1]; |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 2204 | EXPECT_EQ(1u, stream->GetEncoderConfig().number_of_streams); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2205 | return stream->GetVideoStreams()[0].max_bitrate_bps; |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 2206 | } |
| 2207 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2208 | void SetAndExpectMaxBitrate(int global_max, |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 2209 | int stream_max, |
| 2210 | int expected_encoder_bitrate) { |
| 2211 | VideoSendParameters limited_send_params = send_parameters_; |
| 2212 | limited_send_params.max_bandwidth_bps = global_max; |
| 2213 | EXPECT_TRUE(channel_->SetSendParameters(limited_send_params)); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 2214 | webrtc::RtpParameters parameters = |
| 2215 | channel_->GetRtpSendParameters(last_ssrc_); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 2216 | EXPECT_EQ(1UL, parameters.encodings.size()); |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 2217 | parameters.encodings[0].max_bitrate_bps = stream_max; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 2218 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 2219 | // Read back the parameteres and verify they have the correct value |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 2220 | parameters = channel_->GetRtpSendParameters(last_ssrc_); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 2221 | EXPECT_EQ(1UL, parameters.encodings.size()); |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 2222 | EXPECT_EQ(stream_max, parameters.encodings[0].max_bitrate_bps); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 2223 | // Verify that the new value propagated down to the encoder |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2224 | EXPECT_EQ(expected_encoder_bitrate, GetMaxEncoderBitrate()); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 2225 | } |
| 2226 | |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 2227 | std::unique_ptr<FakeCall> fake_call_; |
| 2228 | std::unique_ptr<VideoMediaChannel> channel_; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2229 | cricket::VideoSendParameters send_parameters_; |
| 2230 | cricket::VideoRecvParameters recv_parameters_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 2231 | uint32_t last_ssrc_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2232 | }; |
| 2233 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2234 | TEST_F(WebRtcVideoChannelTest, SetsSyncGroupFromSyncLabel) { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 2235 | const uint32_t kVideoSsrc = 123; |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 2236 | const std::string kSyncLabel = "AvSyncLabel"; |
| 2237 | |
| 2238 | cricket::StreamParams sp = cricket::StreamParams::CreateLegacy(kVideoSsrc); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 2239 | sp.set_stream_ids({kSyncLabel}); |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 2240 | EXPECT_TRUE(channel_->AddRecvStream(sp)); |
| 2241 | |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 2242 | EXPECT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 2243 | EXPECT_EQ(kSyncLabel, |
| 2244 | fake_call_->GetVideoReceiveStreams()[0]->GetConfig().sync_group) |
| 2245 | << "SyncGroup should be set based on sync_label"; |
| 2246 | } |
| 2247 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2248 | TEST_F(WebRtcVideoChannelTest, RecvStreamWithSimAndRtx) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2249 | cricket::VideoSendParameters parameters; |
| 2250 | parameters.codecs = engine_.codecs(); |
| 2251 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2252 | EXPECT_TRUE(channel_->SetSend(true)); |
nisse | 4b4dc86 | 2016-02-17 05:25:36 -0800 | [diff] [blame] | 2253 | parameters.conference_mode = true; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2254 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2255 | |
| 2256 | // Send side. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 2257 | const std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs1); |
| 2258 | const std::vector<uint32_t> rtx_ssrcs = MAKE_VECTOR(kRtxSsrcs1); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2259 | FakeVideoSendStream* send_stream = AddSendStream( |
| 2260 | cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); |
| 2261 | |
| 2262 | ASSERT_EQ(rtx_ssrcs.size(), send_stream->GetConfig().rtp.rtx.ssrcs.size()); |
| 2263 | for (size_t i = 0; i < rtx_ssrcs.size(); ++i) |
| 2264 | EXPECT_EQ(rtx_ssrcs[i], send_stream->GetConfig().rtp.rtx.ssrcs[i]); |
| 2265 | |
| 2266 | // Receiver side. |
| 2267 | FakeVideoReceiveStream* recv_stream = AddRecvStream( |
| 2268 | cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); |
nisse | 26e3abb | 2017-08-25 04:44:25 -0700 | [diff] [blame] | 2269 | EXPECT_FALSE( |
| 2270 | recv_stream->GetConfig().rtp.rtx_associated_payload_types.empty()); |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 2271 | EXPECT_TRUE(VerifyRtxReceiveAssociations(recv_stream->GetConfig())) |
Peter Boström | d8b0109 | 2016-05-12 16:44:36 +0200 | [diff] [blame] | 2272 | << "RTX should be mapped for all decoders/payload types."; |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 2273 | EXPECT_TRUE(HasRtxReceiveAssociation(recv_stream->GetConfig(), |
| 2274 | GetEngineCodec("red").id)) |
| 2275 | << "RTX should be mapped for the RED payload type"; |
| 2276 | |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 2277 | EXPECT_EQ(rtx_ssrcs[0], recv_stream->GetConfig().rtp.rtx_ssrc); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2278 | } |
| 2279 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2280 | TEST_F(WebRtcVideoChannelTest, RecvStreamWithRtx) { |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 2281 | // Setup one channel with an associated RTX stream. |
| 2282 | cricket::StreamParams params = |
| 2283 | cricket::StreamParams::CreateLegacy(kSsrcs1[0]); |
| 2284 | params.AddFidSsrc(kSsrcs1[0], kRtxSsrcs1[0]); |
| 2285 | FakeVideoReceiveStream* recv_stream = AddRecvStream(params); |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 2286 | EXPECT_EQ(kRtxSsrcs1[0], recv_stream->GetConfig().rtp.rtx_ssrc); |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 2287 | |
| 2288 | EXPECT_TRUE(VerifyRtxReceiveAssociations(recv_stream->GetConfig())) |
| 2289 | << "RTX should be mapped for all decoders/payload types."; |
| 2290 | EXPECT_TRUE(HasRtxReceiveAssociation(recv_stream->GetConfig(), |
| 2291 | GetEngineCodec("red").id)) |
| 2292 | << "RTX should be mapped for the RED payload type"; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2293 | } |
| 2294 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2295 | TEST_F(WebRtcVideoChannelTest, RecvStreamNoRtx) { |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 2296 | // Setup one channel without an associated RTX stream. |
| 2297 | cricket::StreamParams params = |
| 2298 | cricket::StreamParams::CreateLegacy(kSsrcs1[0]); |
| 2299 | FakeVideoReceiveStream* recv_stream = AddRecvStream(params); |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 2300 | ASSERT_EQ(0U, recv_stream->GetConfig().rtp.rtx_ssrc); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2301 | } |
| 2302 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2303 | TEST_F(WebRtcVideoChannelTest, NoHeaderExtesionsByDefault) { |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2304 | FakeVideoSendStream* send_stream = |
| 2305 | AddSendStream(cricket::StreamParams::CreateLegacy(kSsrcs1[0])); |
| 2306 | ASSERT_TRUE(send_stream->GetConfig().rtp.extensions.empty()); |
| 2307 | |
| 2308 | FakeVideoReceiveStream* recv_stream = |
| 2309 | AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrcs1[0])); |
| 2310 | ASSERT_TRUE(recv_stream->GetConfig().rtp.extensions.empty()); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2311 | } |
| 2312 | |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2313 | // Test support for RTP timestamp offset header extension. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2314 | TEST_F(WebRtcVideoChannelTest, SendRtpTimestampOffsetHeaderExtensions) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2315 | TestSetSendRtpHeaderExtensions(RtpExtension::kTimestampOffsetUri); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2316 | } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2317 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2318 | TEST_F(WebRtcVideoChannelTest, RecvRtpTimestampOffsetHeaderExtensions) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2319 | TestSetRecvRtpHeaderExtensions(RtpExtension::kTimestampOffsetUri); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2320 | } |
| 2321 | |
| 2322 | // Test support for absolute send time header extension. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2323 | TEST_F(WebRtcVideoChannelTest, SendAbsoluteSendTimeHeaderExtensions) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2324 | TestSetSendRtpHeaderExtensions(RtpExtension::kAbsSendTimeUri); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2325 | } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2326 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2327 | TEST_F(WebRtcVideoChannelTest, RecvAbsoluteSendTimeHeaderExtensions) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2328 | TestSetRecvRtpHeaderExtensions(RtpExtension::kAbsSendTimeUri); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2329 | } |
| 2330 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2331 | TEST_F(WebRtcVideoChannelTest, FiltersExtensionsPicksTransportSeqNum) { |
Stefan Holmer | bbaf363 | 2015-10-29 18:53:23 +0100 | [diff] [blame] | 2332 | // Enable three redundant extensions. |
| 2333 | std::vector<std::string> extensions; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2334 | extensions.push_back(RtpExtension::kAbsSendTimeUri); |
| 2335 | extensions.push_back(RtpExtension::kTimestampOffsetUri); |
| 2336 | extensions.push_back(RtpExtension::kTransportSequenceNumberUri); |
| 2337 | TestExtensionFilter(extensions, RtpExtension::kTransportSequenceNumberUri); |
Stefan Holmer | bbaf363 | 2015-10-29 18:53:23 +0100 | [diff] [blame] | 2338 | } |
| 2339 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2340 | TEST_F(WebRtcVideoChannelTest, FiltersExtensionsPicksAbsSendTime) { |
Stefan Holmer | bbaf363 | 2015-10-29 18:53:23 +0100 | [diff] [blame] | 2341 | // Enable two redundant extensions. |
| 2342 | std::vector<std::string> extensions; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2343 | extensions.push_back(RtpExtension::kAbsSendTimeUri); |
| 2344 | extensions.push_back(RtpExtension::kTimestampOffsetUri); |
| 2345 | TestExtensionFilter(extensions, RtpExtension::kAbsSendTimeUri); |
Stefan Holmer | bbaf363 | 2015-10-29 18:53:23 +0100 | [diff] [blame] | 2346 | } |
| 2347 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 2348 | // Test support for transport sequence number header extension. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2349 | TEST_F(WebRtcVideoChannelTest, SendTransportSequenceNumberHeaderExtensions) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2350 | TestSetSendRtpHeaderExtensions(RtpExtension::kTransportSequenceNumberUri); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 2351 | } |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2352 | TEST_F(WebRtcVideoChannelTest, RecvTransportSequenceNumberHeaderExtensions) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2353 | TestSetRecvRtpHeaderExtensions(RtpExtension::kTransportSequenceNumberUri); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 2354 | } |
| 2355 | |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 2356 | // Test support for video rotation header extension. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2357 | TEST_F(WebRtcVideoChannelTest, SendVideoRotationHeaderExtensions) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2358 | TestSetSendRtpHeaderExtensions(RtpExtension::kVideoRotationUri); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 2359 | } |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2360 | TEST_F(WebRtcVideoChannelTest, RecvVideoRotationHeaderExtensions) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2361 | TestSetRecvRtpHeaderExtensions(RtpExtension::kVideoRotationUri); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 2362 | } |
| 2363 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2364 | TEST_F(WebRtcVideoChannelTest, IdenticalSendExtensionsDoesntRecreateStream) { |
Stefan Holmer | bbaf363 | 2015-10-29 18:53:23 +0100 | [diff] [blame] | 2365 | const int kAbsSendTimeId = 1; |
| 2366 | const int kVideoRotationId = 2; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2367 | send_parameters_.extensions.push_back( |
| 2368 | RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeId)); |
| 2369 | send_parameters_.extensions.push_back( |
| 2370 | RtpExtension(RtpExtension::kVideoRotationUri, kVideoRotationId)); |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2371 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2372 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2373 | FakeVideoSendStream* send_stream = |
| 2374 | AddSendStream(cricket::StreamParams::CreateLegacy(123)); |
| 2375 | |
| 2376 | EXPECT_EQ(1, fake_call_->GetNumCreatedSendStreams()); |
Stefan Holmer | bbaf363 | 2015-10-29 18:53:23 +0100 | [diff] [blame] | 2377 | ASSERT_EQ(2u, send_stream->GetConfig().rtp.extensions.size()); |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2378 | |
| 2379 | // Setting the same extensions (even if in different order) shouldn't |
| 2380 | // reallocate the stream. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2381 | std::reverse(send_parameters_.extensions.begin(), |
| 2382 | send_parameters_.extensions.end()); |
| 2383 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2384 | |
| 2385 | EXPECT_EQ(1, fake_call_->GetNumCreatedSendStreams()); |
| 2386 | |
| 2387 | // Setting different extensions should recreate the stream. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2388 | send_parameters_.extensions.resize(1); |
| 2389 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2390 | |
| 2391 | EXPECT_EQ(2, fake_call_->GetNumCreatedSendStreams()); |
| 2392 | } |
| 2393 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2394 | TEST_F(WebRtcVideoChannelTest, IdenticalRecvExtensionsDoesntRecreateStream) { |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2395 | const int kTOffsetId = 1; |
| 2396 | const int kAbsSendTimeId = 2; |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 2397 | const int kVideoRotationId = 3; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2398 | recv_parameters_.extensions.push_back( |
| 2399 | RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeId)); |
| 2400 | recv_parameters_.extensions.push_back( |
| 2401 | RtpExtension(RtpExtension::kTimestampOffsetUri, kTOffsetId)); |
| 2402 | recv_parameters_.extensions.push_back( |
| 2403 | RtpExtension(RtpExtension::kVideoRotationUri, kVideoRotationId)); |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2404 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2405 | EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
Peter Boström | 54be3e0 | 2015-05-25 15:04:24 +0200 | [diff] [blame] | 2406 | FakeVideoReceiveStream* recv_stream = |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2407 | AddRecvStream(cricket::StreamParams::CreateLegacy(123)); |
| 2408 | |
| 2409 | EXPECT_EQ(1, fake_call_->GetNumCreatedReceiveStreams()); |
Peter Boström | 54be3e0 | 2015-05-25 15:04:24 +0200 | [diff] [blame] | 2410 | ASSERT_EQ(3u, recv_stream->GetConfig().rtp.extensions.size()); |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2411 | |
| 2412 | // Setting the same extensions (even if in different order) shouldn't |
| 2413 | // reallocate the stream. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2414 | std::reverse(recv_parameters_.extensions.begin(), |
| 2415 | recv_parameters_.extensions.end()); |
| 2416 | EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2417 | |
| 2418 | EXPECT_EQ(1, fake_call_->GetNumCreatedReceiveStreams()); |
| 2419 | |
| 2420 | // Setting different extensions should recreate the stream. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2421 | recv_parameters_.extensions.resize(1); |
| 2422 | EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2423 | |
| 2424 | EXPECT_EQ(2, fake_call_->GetNumCreatedReceiveStreams()); |
| 2425 | } |
| 2426 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2427 | TEST_F(WebRtcVideoChannelTest, |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2428 | SetSendRtpHeaderExtensionsExcludeUnsupportedExtensions) { |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2429 | const int kUnsupportedId = 1; |
| 2430 | const int kTOffsetId = 2; |
| 2431 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2432 | send_parameters_.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2433 | RtpExtension(kUnsupportedExtensionName, kUnsupportedId)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2434 | send_parameters_.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2435 | RtpExtension(RtpExtension::kTimestampOffsetUri, kTOffsetId)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2436 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2437 | FakeVideoSendStream* send_stream = |
| 2438 | AddSendStream(cricket::StreamParams::CreateLegacy(123)); |
| 2439 | |
| 2440 | // Only timestamp offset extension is set to send stream, |
| 2441 | // unsupported rtp extension is ignored. |
| 2442 | ASSERT_EQ(1u, send_stream->GetConfig().rtp.extensions.size()); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2443 | EXPECT_STREQ(RtpExtension::kTimestampOffsetUri, |
| 2444 | send_stream->GetConfig().rtp.extensions[0].uri.c_str()); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2445 | } |
| 2446 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2447 | TEST_F(WebRtcVideoChannelTest, |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2448 | SetRecvRtpHeaderExtensionsExcludeUnsupportedExtensions) { |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2449 | const int kUnsupportedId = 1; |
| 2450 | const int kTOffsetId = 2; |
| 2451 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2452 | recv_parameters_.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2453 | RtpExtension(kUnsupportedExtensionName, kUnsupportedId)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2454 | recv_parameters_.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2455 | RtpExtension(RtpExtension::kTimestampOffsetUri, kTOffsetId)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2456 | EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2457 | FakeVideoReceiveStream* recv_stream = |
| 2458 | AddRecvStream(cricket::StreamParams::CreateLegacy(123)); |
| 2459 | |
| 2460 | // Only timestamp offset extension is set to receive stream, |
| 2461 | // unsupported rtp extension is ignored. |
| 2462 | ASSERT_EQ(1u, recv_stream->GetConfig().rtp.extensions.size()); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2463 | EXPECT_STREQ(RtpExtension::kTimestampOffsetUri, |
| 2464 | recv_stream->GetConfig().rtp.extensions[0].uri.c_str()); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2465 | } |
| 2466 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2467 | TEST_F(WebRtcVideoChannelTest, SetSendRtpHeaderExtensionsRejectsIncorrectIds) { |
Peter Boström | 23914fe | 2015-03-31 15:08:04 +0200 | [diff] [blame] | 2468 | const int kIncorrectIds[] = {-2, -1, 0, 15, 16}; |
pkasting@chromium.org | e7a4a12 | 2015-01-28 21:36:55 +0000 | [diff] [blame] | 2469 | for (size_t i = 0; i < arraysize(kIncorrectIds); ++i) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2470 | send_parameters_.extensions.push_back( |
| 2471 | RtpExtension(RtpExtension::kTimestampOffsetUri, kIncorrectIds[i])); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2472 | EXPECT_FALSE(channel_->SetSendParameters(send_parameters_)) |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2473 | << "Bad extension id '" << kIncorrectIds[i] << "' accepted."; |
| 2474 | } |
| 2475 | } |
| 2476 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2477 | TEST_F(WebRtcVideoChannelTest, SetRecvRtpHeaderExtensionsRejectsIncorrectIds) { |
Peter Boström | 23914fe | 2015-03-31 15:08:04 +0200 | [diff] [blame] | 2478 | const int kIncorrectIds[] = {-2, -1, 0, 15, 16}; |
pkasting@chromium.org | e7a4a12 | 2015-01-28 21:36:55 +0000 | [diff] [blame] | 2479 | for (size_t i = 0; i < arraysize(kIncorrectIds); ++i) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2480 | recv_parameters_.extensions.push_back( |
| 2481 | RtpExtension(RtpExtension::kTimestampOffsetUri, kIncorrectIds[i])); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2482 | EXPECT_FALSE(channel_->SetRecvParameters(recv_parameters_)) |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2483 | << "Bad extension id '" << kIncorrectIds[i] << "' accepted."; |
| 2484 | } |
| 2485 | } |
| 2486 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2487 | TEST_F(WebRtcVideoChannelTest, SetSendRtpHeaderExtensionsRejectsDuplicateIds) { |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2488 | const int id = 1; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2489 | send_parameters_.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2490 | RtpExtension(RtpExtension::kTimestampOffsetUri, id)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2491 | send_parameters_.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2492 | RtpExtension(RtpExtension::kAbsSendTimeUri, id)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2493 | EXPECT_FALSE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2494 | |
| 2495 | // Duplicate entries are also not supported. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2496 | send_parameters_.extensions.clear(); |
| 2497 | send_parameters_.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2498 | RtpExtension(RtpExtension::kTimestampOffsetUri, id)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2499 | send_parameters_.extensions.push_back(send_parameters_.extensions.back()); |
| 2500 | EXPECT_FALSE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2501 | } |
| 2502 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2503 | TEST_F(WebRtcVideoChannelTest, SetRecvRtpHeaderExtensionsRejectsDuplicateIds) { |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2504 | const int id = 1; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2505 | recv_parameters_.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2506 | RtpExtension(RtpExtension::kTimestampOffsetUri, id)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2507 | recv_parameters_.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2508 | RtpExtension(RtpExtension::kAbsSendTimeUri, id)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2509 | EXPECT_FALSE(channel_->SetRecvParameters(recv_parameters_)); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2510 | |
| 2511 | // Duplicate entries are also not supported. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2512 | recv_parameters_.extensions.clear(); |
| 2513 | recv_parameters_.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2514 | RtpExtension(RtpExtension::kTimestampOffsetUri, id)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2515 | recv_parameters_.extensions.push_back(recv_parameters_.extensions.back()); |
| 2516 | EXPECT_FALSE(channel_->SetRecvParameters(recv_parameters_)); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2517 | } |
| 2518 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2519 | TEST_F(WebRtcVideoChannelTest, AddRecvStreamOnlyUsesOneReceiveStream) { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2520 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2521 | EXPECT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2522 | } |
| 2523 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2524 | TEST_F(WebRtcVideoChannelTest, RtcpIsCompoundByDefault) { |
Peter Boström | d7da120 | 2015-06-05 14:09:38 +0200 | [diff] [blame] | 2525 | FakeVideoReceiveStream* stream = AddRecvStream(); |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 2526 | EXPECT_EQ(webrtc::RtcpMode::kCompound, stream->GetConfig().rtp.rtcp_mode); |
Peter Boström | d7da120 | 2015-06-05 14:09:38 +0200 | [diff] [blame] | 2527 | } |
| 2528 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2529 | TEST_F(WebRtcVideoChannelTest, RembIsEnabledByDefault) { |
pbos@webrtc.org | 257e130 | 2014-07-25 19:01:32 +0000 | [diff] [blame] | 2530 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 2531 | EXPECT_TRUE(stream->GetConfig().rtp.remb); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2532 | } |
| 2533 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2534 | TEST_F(WebRtcVideoChannelTest, TransportCcIsEnabledByDefault) { |
stefan | 43edf0f | 2015-11-20 18:05:48 -0800 | [diff] [blame] | 2535 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 2536 | EXPECT_TRUE(stream->GetConfig().rtp.transport_cc); |
| 2537 | } |
| 2538 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2539 | TEST_F(WebRtcVideoChannelTest, RembCanBeEnabledAndDisabled) { |
pbos@webrtc.org | 257e130 | 2014-07-25 19:01:32 +0000 | [diff] [blame] | 2540 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 2541 | EXPECT_TRUE(stream->GetConfig().rtp.remb); |
| 2542 | |
Peter Boström | 126c03e | 2015-05-11 12:48:12 +0200 | [diff] [blame] | 2543 | // Verify that REMB is turned off when send(!) codecs without REMB are set. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2544 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2545 | parameters.codecs.push_back(RemoveFeedbackParams(GetEngineCodec("VP8"))); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2546 | EXPECT_TRUE(parameters.codecs[0].feedback_params.params().empty()); |
| 2547 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2548 | stream = fake_call_->GetVideoReceiveStreams()[0]; |
pbos@webrtc.org | 257e130 | 2014-07-25 19:01:32 +0000 | [diff] [blame] | 2549 | EXPECT_FALSE(stream->GetConfig().rtp.remb); |
| 2550 | |
| 2551 | // Verify that REMB is turned on when setting default codecs since the |
| 2552 | // default codecs have REMB enabled. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2553 | parameters.codecs = engine_.codecs(); |
| 2554 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2555 | stream = fake_call_->GetVideoReceiveStreams()[0]; |
pbos@webrtc.org | 257e130 | 2014-07-25 19:01:32 +0000 | [diff] [blame] | 2556 | EXPECT_TRUE(stream->GetConfig().rtp.remb); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2557 | } |
| 2558 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2559 | TEST_F(WebRtcVideoChannelTest, TransportCcCanBeEnabledAndDisabled) { |
stefan | 43edf0f | 2015-11-20 18:05:48 -0800 | [diff] [blame] | 2560 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 2561 | EXPECT_TRUE(stream->GetConfig().rtp.transport_cc); |
| 2562 | |
| 2563 | // Verify that transport cc feedback is turned off when send(!) codecs without |
| 2564 | // transport cc feedback are set. |
| 2565 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2566 | parameters.codecs.push_back(RemoveFeedbackParams(GetEngineCodec("VP8"))); |
stefan | 43edf0f | 2015-11-20 18:05:48 -0800 | [diff] [blame] | 2567 | EXPECT_TRUE(parameters.codecs[0].feedback_params.params().empty()); |
| 2568 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 2569 | stream = fake_call_->GetVideoReceiveStreams()[0]; |
| 2570 | EXPECT_FALSE(stream->GetConfig().rtp.transport_cc); |
| 2571 | |
| 2572 | // Verify that transport cc feedback is turned on when setting default codecs |
| 2573 | // since the default codecs have transport cc feedback enabled. |
| 2574 | parameters.codecs = engine_.codecs(); |
| 2575 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 2576 | stream = fake_call_->GetVideoReceiveStreams()[0]; |
| 2577 | EXPECT_TRUE(stream->GetConfig().rtp.transport_cc); |
| 2578 | } |
| 2579 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2580 | TEST_F(WebRtcVideoChannelTest, NackIsEnabledByDefault) { |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 2581 | AssignDefaultCodec(); |
pbos@webrtc.org | f99c2f2 | 2014-06-13 12:27:38 +0000 | [diff] [blame] | 2582 | VerifyCodecHasDefaultFeedbackParams(default_codec_); |
| 2583 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2584 | cricket::VideoSendParameters parameters; |
| 2585 | parameters.codecs = engine_.codecs(); |
| 2586 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 1986474 | 2014-05-30 07:35:47 +0000 | [diff] [blame] | 2587 | EXPECT_TRUE(channel_->SetSend(true)); |
| 2588 | |
| 2589 | // Send side. |
| 2590 | FakeVideoSendStream* send_stream = |
| 2591 | AddSendStream(cricket::StreamParams::CreateLegacy(1)); |
| 2592 | EXPECT_GT(send_stream->GetConfig().rtp.nack.rtp_history_ms, 0); |
| 2593 | |
| 2594 | // Receiver side. |
| 2595 | FakeVideoReceiveStream* recv_stream = |
| 2596 | AddRecvStream(cricket::StreamParams::CreateLegacy(1)); |
| 2597 | EXPECT_GT(recv_stream->GetConfig().rtp.nack.rtp_history_ms, 0); |
| 2598 | |
| 2599 | // Nack history size should match between sender and receiver. |
| 2600 | EXPECT_EQ(send_stream->GetConfig().rtp.nack.rtp_history_ms, |
| 2601 | recv_stream->GetConfig().rtp.nack.rtp_history_ms); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2602 | } |
| 2603 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2604 | TEST_F(WebRtcVideoChannelTest, NackCanBeEnabledAndDisabled) { |
Peter Boström | 67c9df7 | 2015-05-11 14:34:58 +0200 | [diff] [blame] | 2605 | FakeVideoSendStream* send_stream = AddSendStream(); |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 2606 | FakeVideoReceiveStream* recv_stream = AddRecvStream(); |
Peter Boström | 67c9df7 | 2015-05-11 14:34:58 +0200 | [diff] [blame] | 2607 | |
| 2608 | EXPECT_GT(recv_stream->GetConfig().rtp.nack.rtp_history_ms, 0); |
| 2609 | EXPECT_GT(send_stream->GetConfig().rtp.nack.rtp_history_ms, 0); |
| 2610 | |
| 2611 | // Verify that NACK is turned off when send(!) codecs without NACK are set. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2612 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2613 | parameters.codecs.push_back(RemoveFeedbackParams(GetEngineCodec("VP8"))); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2614 | EXPECT_TRUE(parameters.codecs[0].feedback_params.params().empty()); |
| 2615 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
Peter Boström | 67c9df7 | 2015-05-11 14:34:58 +0200 | [diff] [blame] | 2616 | recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
| 2617 | EXPECT_EQ(0, recv_stream->GetConfig().rtp.nack.rtp_history_ms); |
| 2618 | send_stream = fake_call_->GetVideoSendStreams()[0]; |
pbos@webrtc.org | f99c2f2 | 2014-06-13 12:27:38 +0000 | [diff] [blame] | 2619 | EXPECT_EQ(0, send_stream->GetConfig().rtp.nack.rtp_history_ms); |
| 2620 | |
Peter Boström | 67c9df7 | 2015-05-11 14:34:58 +0200 | [diff] [blame] | 2621 | // Verify that NACK is turned on when setting default codecs since the |
| 2622 | // default codecs have NACK enabled. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2623 | parameters.codecs = engine_.codecs(); |
| 2624 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
Peter Boström | 67c9df7 | 2015-05-11 14:34:58 +0200 | [diff] [blame] | 2625 | recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
| 2626 | EXPECT_GT(recv_stream->GetConfig().rtp.nack.rtp_history_ms, 0); |
| 2627 | send_stream = fake_call_->GetVideoSendStreams()[0]; |
| 2628 | EXPECT_GT(send_stream->GetConfig().rtp.nack.rtp_history_ms, 0); |
pbos@webrtc.org | f99c2f2 | 2014-06-13 12:27:38 +0000 | [diff] [blame] | 2629 | } |
| 2630 | |
Peter Boström | e7ba086 | 2016-03-12 00:02:28 +0100 | [diff] [blame] | 2631 | // This test verifies that new frame sizes reconfigures encoders even though not |
| 2632 | // (yet) sending. The purpose of this is to permit encoding as quickly as |
| 2633 | // possible once we start sending. Likely the frames being input are from the |
| 2634 | // same source that will be sent later, which just means that we're ready |
| 2635 | // earlier. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2636 | TEST_F(WebRtcVideoChannelTest, ReconfiguresEncodersWhenNotSending) { |
Peter Boström | e7ba086 | 2016-03-12 00:02:28 +0100 | [diff] [blame] | 2637 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2638 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Peter Boström | e7ba086 | 2016-03-12 00:02:28 +0100 | [diff] [blame] | 2639 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 2640 | channel_->SetSend(false); |
| 2641 | |
| 2642 | FakeVideoSendStream* stream = AddSendStream(); |
| 2643 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2644 | // No frames entered. |
Peter Boström | e7ba086 | 2016-03-12 00:02:28 +0100 | [diff] [blame] | 2645 | std::vector<webrtc::VideoStream> streams = stream->GetVideoStreams(); |
Danil Chapovalov | 350531e | 2018-06-08 11:04:04 +0000 | [diff] [blame] | 2646 | EXPECT_EQ(0u, streams[0].width); |
| 2647 | EXPECT_EQ(0u, streams[0].height); |
Peter Boström | e7ba086 | 2016-03-12 00:02:28 +0100 | [diff] [blame] | 2648 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 2649 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2650 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, &capturer)); |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 2651 | VideoFormat capture_format = capturer.GetSupportedFormats()->front(); |
| 2652 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format)); |
Peter Boström | e7ba086 | 2016-03-12 00:02:28 +0100 | [diff] [blame] | 2653 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 2654 | |
| 2655 | // Frame entered, should be reconfigured to new dimensions. |
| 2656 | streams = stream->GetVideoStreams(); |
Danil Chapovalov | 350531e | 2018-06-08 11:04:04 +0000 | [diff] [blame] | 2657 | EXPECT_EQ(rtc::checked_cast<size_t>(capture_format.width), streams[0].width); |
| 2658 | EXPECT_EQ(rtc::checked_cast<size_t>(capture_format.height), |
| 2659 | streams[0].height); |
Peter Boström | e7ba086 | 2016-03-12 00:02:28 +0100 | [diff] [blame] | 2660 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2661 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
Peter Boström | e7ba086 | 2016-03-12 00:02:28 +0100 | [diff] [blame] | 2662 | } |
| 2663 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2664 | TEST_F(WebRtcVideoChannelTest, UsesCorrectSettingsForScreencast) { |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 2665 | static const int kScreenshareMinBitrateKbps = 800; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2666 | cricket::VideoCodec codec = GetEngineCodec("VP8"); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2667 | cricket::VideoSendParameters parameters; |
| 2668 | parameters.codecs.push_back(codec); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2669 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 2670 | AddSendStream(); |
| 2671 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 2672 | FakeVideoCapturerWithTaskQueue capturer; |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2673 | VideoOptions min_bitrate_options; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 2674 | min_bitrate_options.screencast_min_bitrate_kbps = kScreenshareMinBitrateKbps; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2675 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &min_bitrate_options, |
deadbeef | 5a4a75a | 2016-06-02 16:23:38 -0700 | [diff] [blame] | 2676 | &capturer)); |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 2677 | cricket::VideoFormat capture_format_hd = |
| 2678 | capturer.GetSupportedFormats()->front(); |
| 2679 | EXPECT_EQ(1280, capture_format_hd.width); |
| 2680 | EXPECT_EQ(720, capture_format_hd.height); |
| 2681 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format_hd)); |
| 2682 | |
| 2683 | EXPECT_TRUE(channel_->SetSend(true)); |
| 2684 | |
| 2685 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 2686 | ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| 2687 | FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
| 2688 | |
| 2689 | EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
| 2690 | |
| 2691 | // Verify non-screencast settings. |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2692 | webrtc::VideoEncoderConfig encoder_config = |
| 2693 | send_stream->GetEncoderConfig().Copy(); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2694 | EXPECT_EQ(webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo, |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 2695 | encoder_config.content_type); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2696 | std::vector<webrtc::VideoStream> streams = send_stream->GetVideoStreams(); |
Danil Chapovalov | 350531e | 2018-06-08 11:04:04 +0000 | [diff] [blame] | 2697 | EXPECT_EQ(rtc::checked_cast<size_t>(capture_format_hd.width), |
| 2698 | streams.front().width); |
| 2699 | EXPECT_EQ(rtc::checked_cast<size_t>(capture_format_hd.height), |
| 2700 | streams.front().height); |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 2701 | EXPECT_EQ(0, encoder_config.min_transmit_bitrate_bps) |
| 2702 | << "Non-screenshare shouldn't use min-transmit bitrate."; |
| 2703 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2704 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
perkj | d533aec | 2017-01-13 05:57:25 -0800 | [diff] [blame] | 2705 | EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2706 | VideoOptions screencast_options; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 2707 | screencast_options.is_screencast = true; |
deadbeef | 5a4a75a | 2016-06-02 16:23:38 -0700 | [diff] [blame] | 2708 | EXPECT_TRUE( |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2709 | channel_->SetVideoSend(last_ssrc_, &screencast_options, &capturer)); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 2710 | EXPECT_TRUE(capturer.CaptureFrame()); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 2711 | // Send stream recreated after option change. |
| 2712 | ASSERT_EQ(2, fake_call_->GetNumCreatedSendStreams()); |
| 2713 | send_stream = fake_call_->GetVideoSendStreams().front(); |
| 2714 | EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 2715 | |
| 2716 | // Verify screencast settings. |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2717 | encoder_config = send_stream->GetEncoderConfig().Copy(); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2718 | EXPECT_EQ(webrtc::VideoEncoderConfig::ContentType::kScreen, |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 2719 | encoder_config.content_type); |
| 2720 | EXPECT_EQ(kScreenshareMinBitrateKbps * 1000, |
| 2721 | encoder_config.min_transmit_bitrate_bps); |
| 2722 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2723 | streams = send_stream->GetVideoStreams(); |
Danil Chapovalov | 350531e | 2018-06-08 11:04:04 +0000 | [diff] [blame] | 2724 | EXPECT_EQ(rtc::checked_cast<size_t>(capture_format_hd.width), |
| 2725 | streams.front().width); |
| 2726 | EXPECT_EQ(rtc::checked_cast<size_t>(capture_format_hd.height), |
| 2727 | streams.front().height); |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 2728 | EXPECT_FALSE(streams[0].num_temporal_layers.has_value()); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2729 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2730 | } |
| 2731 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2732 | TEST_F(WebRtcVideoChannelTest, |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2733 | ConferenceModeScreencastConfiguresTemporalLayer) { |
Rasmus Brandt | 195d1d7 | 2018-05-09 11:28:01 +0200 | [diff] [blame] | 2734 | static const int kConferenceScreencastTemporalBitrateBps = 200 * 1000; |
nisse | 4b4dc86 | 2016-02-17 05:25:36 -0800 | [diff] [blame] | 2735 | send_parameters_.conference_mode = true; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2736 | channel_->SetSendParameters(send_parameters_); |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2737 | |
| 2738 | AddSendStream(); |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2739 | VideoOptions options; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 2740 | options.is_screencast = true; |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 2741 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2742 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2743 | cricket::VideoFormat capture_format_hd = |
| 2744 | capturer.GetSupportedFormats()->front(); |
| 2745 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format_hd)); |
| 2746 | |
| 2747 | EXPECT_TRUE(channel_->SetSend(true)); |
| 2748 | |
| 2749 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 2750 | ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| 2751 | FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
| 2752 | |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2753 | webrtc::VideoEncoderConfig encoder_config = |
| 2754 | send_stream->GetEncoderConfig().Copy(); |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2755 | |
| 2756 | // Verify screencast settings. |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2757 | encoder_config = send_stream->GetEncoderConfig().Copy(); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2758 | EXPECT_EQ(webrtc::VideoEncoderConfig::ContentType::kScreen, |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2759 | encoder_config.content_type); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2760 | |
| 2761 | std::vector<webrtc::VideoStream> streams = send_stream->GetVideoStreams(); |
| 2762 | ASSERT_EQ(1u, streams.size()); |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 2763 | ASSERT_EQ(2u, streams[0].num_temporal_layers); |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2764 | EXPECT_EQ(kConferenceScreencastTemporalBitrateBps, |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 2765 | streams[0].target_bitrate_bps); |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 2766 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2767 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2768 | } |
| 2769 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2770 | TEST_F(WebRtcVideoChannelTest, SuspendBelowMinBitrateDisabledByDefault) { |
pbos@webrtc.org | 5ff71ab | 2014-07-23 07:28:56 +0000 | [diff] [blame] | 2771 | FakeVideoSendStream* stream = AddSendStream(); |
| 2772 | EXPECT_FALSE(stream->GetConfig().suspend_below_min_bitrate); |
| 2773 | } |
| 2774 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2775 | TEST_F(WebRtcVideoChannelTest, SetMediaConfigSuspendBelowMinBitrate) { |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 2776 | MediaConfig media_config = GetMediaConfig(); |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 2777 | media_config.video.suspend_below_min_bitrate = true; |
| 2778 | |
| 2779 | channel_.reset( |
| 2780 | engine_.CreateChannel(fake_call_.get(), media_config, VideoOptions())); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 2781 | channel_->OnReadyToSend(true); |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 2782 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2783 | channel_->SetSendParameters(send_parameters_); |
pbos@webrtc.org | 5ff71ab | 2014-07-23 07:28:56 +0000 | [diff] [blame] | 2784 | |
| 2785 | FakeVideoSendStream* stream = AddSendStream(); |
| 2786 | EXPECT_TRUE(stream->GetConfig().suspend_below_min_bitrate); |
| 2787 | |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 2788 | media_config.video.suspend_below_min_bitrate = false; |
| 2789 | channel_.reset( |
| 2790 | engine_.CreateChannel(fake_call_.get(), media_config, VideoOptions())); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 2791 | channel_->OnReadyToSend(true); |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 2792 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2793 | channel_->SetSendParameters(send_parameters_); |
pbos@webrtc.org | 5ff71ab | 2014-07-23 07:28:56 +0000 | [diff] [blame] | 2794 | |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 2795 | stream = AddSendStream(); |
pbos@webrtc.org | 5ff71ab | 2014-07-23 07:28:56 +0000 | [diff] [blame] | 2796 | EXPECT_FALSE(stream->GetConfig().suspend_below_min_bitrate); |
| 2797 | } |
| 2798 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2799 | TEST_F(WebRtcVideoChannelTest, Vp8DenoisingEnabledByDefault) { |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 2800 | FakeVideoSendStream* stream = AddSendStream(); |
| 2801 | webrtc::VideoCodecVP8 vp8_settings; |
| 2802 | ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| 2803 | EXPECT_TRUE(vp8_settings.denoisingOn); |
| 2804 | } |
| 2805 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2806 | TEST_F(WebRtcVideoChannelTest, VerifyVp8SpecificSettings) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2807 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2808 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2809 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 2810 | |
Peter Boström | 2feafdb | 2015-09-09 14:32:14 +0200 | [diff] [blame] | 2811 | // Single-stream settings should apply with RTX as well (verifies that we |
| 2812 | // check number of regular SSRCs and not StreamParams::ssrcs which contains |
| 2813 | // both RTX and regular SSRCs). |
| 2814 | FakeVideoSendStream* stream = SetUpSimulcast(false, true); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2815 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 2816 | FakeVideoCapturerWithTaskQueue capturer; |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2817 | EXPECT_EQ(cricket::CS_RUNNING, |
| 2818 | capturer.Start(capturer.GetSupportedFormats()->front())); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2819 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, &capturer)); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2820 | channel_->SetSend(true); |
| 2821 | |
| 2822 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 2823 | |
pbos | 4cba4eb | 2015-10-26 11:18:18 -0700 | [diff] [blame] | 2824 | webrtc::VideoCodecVP8 vp8_settings; |
| 2825 | ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| 2826 | EXPECT_TRUE(vp8_settings.denoisingOn) |
| 2827 | << "VP8 denoising should be on by default."; |
| 2828 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2829 | stream = SetDenoisingOption(last_ssrc_, &capturer, false); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2830 | |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 2831 | ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| 2832 | EXPECT_FALSE(vp8_settings.denoisingOn); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2833 | EXPECT_TRUE(vp8_settings.automaticResizeOn); |
| 2834 | EXPECT_TRUE(vp8_settings.frameDroppingOn); |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 2835 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2836 | stream = SetDenoisingOption(last_ssrc_, &capturer, true); |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 2837 | |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 2838 | ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| 2839 | EXPECT_TRUE(vp8_settings.denoisingOn); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2840 | EXPECT_TRUE(vp8_settings.automaticResizeOn); |
| 2841 | EXPECT_TRUE(vp8_settings.frameDroppingOn); |
| 2842 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2843 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
Peter Boström | 2feafdb | 2015-09-09 14:32:14 +0200 | [diff] [blame] | 2844 | stream = SetUpSimulcast(true, false); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2845 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, &capturer)); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2846 | channel_->SetSend(true); |
| 2847 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 2848 | |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 2849 | EXPECT_EQ(3u, stream->GetVideoStreams().size()); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2850 | ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| 2851 | // Autmatic resize off when using simulcast. |
| 2852 | EXPECT_FALSE(vp8_settings.automaticResizeOn); |
| 2853 | EXPECT_TRUE(vp8_settings.frameDroppingOn); |
| 2854 | |
| 2855 | // In screen-share mode, denoising is forced off and simulcast disabled. |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2856 | VideoOptions options; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 2857 | options.is_screencast = true; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2858 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
Niels Möller | 60653ba | 2016-03-02 11:41:36 +0100 | [diff] [blame] | 2859 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2860 | stream = SetDenoisingOption(last_ssrc_, &capturer, false); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2861 | |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 2862 | EXPECT_EQ(1u, stream->GetVideoStreams().size()); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2863 | ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| 2864 | EXPECT_FALSE(vp8_settings.denoisingOn); |
| 2865 | // Resizing and frame dropping always off for screen sharing. |
| 2866 | EXPECT_FALSE(vp8_settings.automaticResizeOn); |
| 2867 | EXPECT_FALSE(vp8_settings.frameDroppingOn); |
| 2868 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2869 | stream = SetDenoisingOption(last_ssrc_, &capturer, true); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2870 | |
| 2871 | ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| 2872 | EXPECT_FALSE(vp8_settings.denoisingOn); |
| 2873 | EXPECT_FALSE(vp8_settings.automaticResizeOn); |
| 2874 | EXPECT_FALSE(vp8_settings.frameDroppingOn); |
| 2875 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2876 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2877 | } |
| 2878 | |
deadbeef | 119760a | 2016-04-04 11:43:27 -0700 | [diff] [blame] | 2879 | // Test that setting the same options doesn't result in the encoder being |
| 2880 | // reconfigured. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2881 | TEST_F(WebRtcVideoChannelTest, SetIdenticalOptionsDoesntReconfigureEncoder) { |
deadbeef | 119760a | 2016-04-04 11:43:27 -0700 | [diff] [blame] | 2882 | VideoOptions options; |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 2883 | FakeVideoCapturerWithTaskQueue capturer; |
deadbeef | 119760a | 2016-04-04 11:43:27 -0700 | [diff] [blame] | 2884 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2885 | AddSendStream(); |
deadbeef | 119760a | 2016-04-04 11:43:27 -0700 | [diff] [blame] | 2886 | EXPECT_EQ(cricket::CS_RUNNING, |
| 2887 | capturer.Start(capturer.GetSupportedFormats()->front())); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2888 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2889 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2890 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 2891 | FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
| 2892 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2893 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
| 2894 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
deadbeef | 119760a | 2016-04-04 11:43:27 -0700 | [diff] [blame] | 2895 | EXPECT_TRUE(capturer.CaptureFrame()); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2896 | // Expect 1 reconfigurations at this point from the initial configuration. |
| 2897 | EXPECT_EQ(1, send_stream->num_encoder_reconfigurations()); |
deadbeef | 119760a | 2016-04-04 11:43:27 -0700 | [diff] [blame] | 2898 | |
| 2899 | // Set the options one more time and expect no additional reconfigurations. |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2900 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2901 | EXPECT_EQ(1, send_stream->num_encoder_reconfigurations()); |
| 2902 | |
| 2903 | // Change |options| and expect 2 reconfigurations. |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 2904 | options.video_noise_reduction = true; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2905 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
deadbeef | 119760a | 2016-04-04 11:43:27 -0700 | [diff] [blame] | 2906 | EXPECT_EQ(2, send_stream->num_encoder_reconfigurations()); |
| 2907 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2908 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
deadbeef | 119760a | 2016-04-04 11:43:27 -0700 | [diff] [blame] | 2909 | } |
| 2910 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2911 | class Vp9SettingsTest : public WebRtcVideoChannelTest { |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2912 | public: |
asapersson | c5dabdd | 2016-03-21 04:15:50 -0700 | [diff] [blame] | 2913 | Vp9SettingsTest() : Vp9SettingsTest("") {} |
| 2914 | explicit Vp9SettingsTest(const char* field_trials) |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2915 | : WebRtcVideoChannelTest(field_trials) { |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 2916 | encoder_factory_->AddSupportedVideoCodecType("VP9"); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2917 | } |
| 2918 | virtual ~Vp9SettingsTest() {} |
| 2919 | |
| 2920 | protected: |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2921 | void TearDown() override { |
| 2922 | // Remove references to encoder_factory_ since this will be destroyed |
| 2923 | // before channel_ and engine_. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2924 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2925 | } |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2926 | }; |
| 2927 | |
| 2928 | TEST_F(Vp9SettingsTest, VerifyVp9SpecificSettings) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2929 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2930 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2931 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2932 | |
Peter Boström | 2feafdb | 2015-09-09 14:32:14 +0200 | [diff] [blame] | 2933 | FakeVideoSendStream* stream = SetUpSimulcast(false, false); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2934 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 2935 | FakeVideoCapturerWithTaskQueue capturer; |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2936 | EXPECT_EQ(cricket::CS_RUNNING, |
| 2937 | capturer.Start(capturer.GetSupportedFormats()->front())); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2938 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, &capturer)); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2939 | channel_->SetSend(true); |
| 2940 | |
| 2941 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 2942 | |
pbos | 4cba4eb | 2015-10-26 11:18:18 -0700 | [diff] [blame] | 2943 | webrtc::VideoCodecVP9 vp9_settings; |
| 2944 | ASSERT_TRUE(stream->GetVp9Settings(&vp9_settings)) << "No VP9 config set."; |
jianj | a5e8aa6 | 2017-03-27 10:09:00 -0700 | [diff] [blame] | 2945 | EXPECT_TRUE(vp9_settings.denoisingOn) |
| 2946 | << "VP9 denoising should be on by default."; |
pbos | 4cba4eb | 2015-10-26 11:18:18 -0700 | [diff] [blame] | 2947 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2948 | stream = SetDenoisingOption(last_ssrc_, &capturer, false); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2949 | |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2950 | ASSERT_TRUE(stream->GetVp9Settings(&vp9_settings)) << "No VP9 config set."; |
| 2951 | EXPECT_FALSE(vp9_settings.denoisingOn); |
| 2952 | // Frame dropping always on for real time video. |
| 2953 | EXPECT_TRUE(vp9_settings.frameDroppingOn); |
| 2954 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2955 | stream = SetDenoisingOption(last_ssrc_, &capturer, true); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2956 | |
| 2957 | ASSERT_TRUE(stream->GetVp9Settings(&vp9_settings)) << "No VP9 config set."; |
| 2958 | EXPECT_TRUE(vp9_settings.denoisingOn); |
| 2959 | EXPECT_TRUE(vp9_settings.frameDroppingOn); |
| 2960 | |
| 2961 | // In screen-share mode, denoising is forced off. |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2962 | VideoOptions options; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 2963 | options.is_screencast = true; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2964 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 2965 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2966 | stream = SetDenoisingOption(last_ssrc_, &capturer, false); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2967 | |
| 2968 | ASSERT_TRUE(stream->GetVp9Settings(&vp9_settings)) << "No VP9 config set."; |
| 2969 | EXPECT_FALSE(vp9_settings.denoisingOn); |
Sergey Silkin | be71a1e | 2018-05-17 16:46:43 +0200 | [diff] [blame] | 2970 | // Frame dropping always on for screen sharing. |
| 2971 | EXPECT_TRUE(vp9_settings.frameDroppingOn); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2972 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2973 | stream = SetDenoisingOption(last_ssrc_, &capturer, false); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2974 | |
| 2975 | ASSERT_TRUE(stream->GetVp9Settings(&vp9_settings)) << "No VP9 config set."; |
| 2976 | EXPECT_FALSE(vp9_settings.denoisingOn); |
Sergey Silkin | be71a1e | 2018-05-17 16:46:43 +0200 | [diff] [blame] | 2977 | EXPECT_TRUE(vp9_settings.frameDroppingOn); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2978 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2979 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2980 | } |
| 2981 | |
Sergey Silkin | f18072e | 2018-03-14 10:35:35 +0100 | [diff] [blame] | 2982 | TEST_F(Vp9SettingsTest, MultipleSsrcsEnablesSvc) { |
| 2983 | cricket::VideoSendParameters parameters; |
| 2984 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
| 2985 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 2986 | |
| 2987 | std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); |
| 2988 | |
| 2989 | FakeVideoSendStream* stream = |
| 2990 | AddSendStream(CreateSimStreamParams("cname", ssrcs)); |
| 2991 | |
| 2992 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| 2993 | EXPECT_EQ(ssrcs.size(), config.rtp.ssrcs.size()); |
| 2994 | |
| 2995 | FakeVideoCapturerWithTaskQueue capturer; |
| 2996 | EXPECT_EQ(cricket::CS_RUNNING, |
| 2997 | capturer.Start(capturer.GetSupportedFormats()->front())); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2998 | EXPECT_TRUE(channel_->SetVideoSend(ssrcs[0], nullptr, &capturer)); |
Sergey Silkin | f18072e | 2018-03-14 10:35:35 +0100 | [diff] [blame] | 2999 | channel_->SetSend(true); |
| 3000 | |
| 3001 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 3002 | |
| 3003 | webrtc::VideoCodecVP9 vp9_settings; |
| 3004 | ASSERT_TRUE(stream->GetVp9Settings(&vp9_settings)) << "No VP9 config set."; |
| 3005 | |
| 3006 | const size_t kNumSpatialLayers = ssrcs.size(); |
| 3007 | const size_t kNumTemporalLayers = 3; |
| 3008 | EXPECT_EQ(vp9_settings.numberOfSpatialLayers, kNumSpatialLayers); |
| 3009 | EXPECT_EQ(vp9_settings.numberOfTemporalLayers, kNumTemporalLayers); |
| 3010 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3011 | EXPECT_TRUE(channel_->SetVideoSend(ssrcs[0], nullptr, nullptr)); |
Sergey Silkin | f18072e | 2018-03-14 10:35:35 +0100 | [diff] [blame] | 3012 | } |
| 3013 | |
asapersson | c5dabdd | 2016-03-21 04:15:50 -0700 | [diff] [blame] | 3014 | class Vp9SettingsTestWithFieldTrial : public Vp9SettingsTest { |
| 3015 | public: |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3016 | explicit Vp9SettingsTestWithFieldTrial(const char* field_trials) |
asapersson | c5dabdd | 2016-03-21 04:15:50 -0700 | [diff] [blame] | 3017 | : Vp9SettingsTest(field_trials) {} |
| 3018 | |
| 3019 | protected: |
| 3020 | void VerifySettings(int num_spatial_layers, int num_temporal_layers) { |
| 3021 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3022 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
asapersson | c5dabdd | 2016-03-21 04:15:50 -0700 | [diff] [blame] | 3023 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 3024 | |
| 3025 | FakeVideoSendStream* stream = SetUpSimulcast(false, false); |
| 3026 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 3027 | FakeVideoCapturerWithTaskQueue capturer; |
asapersson | c5dabdd | 2016-03-21 04:15:50 -0700 | [diff] [blame] | 3028 | EXPECT_EQ(cricket::CS_RUNNING, |
| 3029 | capturer.Start(capturer.GetSupportedFormats()->front())); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3030 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, &capturer)); |
asapersson | c5dabdd | 2016-03-21 04:15:50 -0700 | [diff] [blame] | 3031 | channel_->SetSend(true); |
| 3032 | |
| 3033 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 3034 | |
| 3035 | webrtc::VideoCodecVP9 vp9_settings; |
| 3036 | ASSERT_TRUE(stream->GetVp9Settings(&vp9_settings)) << "No VP9 config set."; |
| 3037 | EXPECT_EQ(num_spatial_layers, vp9_settings.numberOfSpatialLayers); |
| 3038 | EXPECT_EQ(num_temporal_layers, vp9_settings.numberOfTemporalLayers); |
| 3039 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3040 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
asapersson | c5dabdd | 2016-03-21 04:15:50 -0700 | [diff] [blame] | 3041 | } |
| 3042 | }; |
| 3043 | |
| 3044 | class Vp9SettingsTestWithNoFlag : public Vp9SettingsTestWithFieldTrial { |
| 3045 | public: |
| 3046 | Vp9SettingsTestWithNoFlag() : Vp9SettingsTestWithFieldTrial("") {} |
| 3047 | }; |
| 3048 | |
| 3049 | TEST_F(Vp9SettingsTestWithNoFlag, VerifySettings) { |
| 3050 | const int kNumSpatialLayers = 1; |
| 3051 | const int kNumTemporalLayers = 1; |
| 3052 | VerifySettings(kNumSpatialLayers, kNumTemporalLayers); |
| 3053 | } |
| 3054 | |
| 3055 | class Vp9SettingsTestWithInvalidFlag : public Vp9SettingsTestWithFieldTrial { |
| 3056 | public: |
| 3057 | Vp9SettingsTestWithInvalidFlag() |
| 3058 | : Vp9SettingsTestWithFieldTrial("WebRTC-SupportVP9SVC/Default/") {} |
| 3059 | }; |
| 3060 | |
| 3061 | TEST_F(Vp9SettingsTestWithInvalidFlag, VerifySettings) { |
| 3062 | const int kNumSpatialLayers = 1; |
| 3063 | const int kNumTemporalLayers = 1; |
| 3064 | VerifySettings(kNumSpatialLayers, kNumTemporalLayers); |
| 3065 | } |
| 3066 | |
| 3067 | class Vp9SettingsTestWith2SL3TLFlag : public Vp9SettingsTestWithFieldTrial { |
| 3068 | public: |
| 3069 | Vp9SettingsTestWith2SL3TLFlag() |
| 3070 | : Vp9SettingsTestWithFieldTrial( |
| 3071 | "WebRTC-SupportVP9SVC/EnabledByFlag_2SL3TL/") {} |
| 3072 | }; |
| 3073 | |
| 3074 | TEST_F(Vp9SettingsTestWith2SL3TLFlag, VerifySettings) { |
| 3075 | const int kNumSpatialLayers = 2; |
| 3076 | const int kNumTemporalLayers = 3; |
| 3077 | VerifySettings(kNumSpatialLayers, kNumTemporalLayers); |
| 3078 | } |
| 3079 | |
Åsa Persson | 45bbc8a | 2017-11-13 10:16:47 +0100 | [diff] [blame] | 3080 | TEST_F(WebRtcVideoChannelTest, VerifyMinBitrate) { |
| 3081 | std::vector<webrtc::VideoStream> streams = AddSendStream()->GetVideoStreams(); |
| 3082 | ASSERT_EQ(1u, streams.size()); |
| 3083 | EXPECT_EQ(cricket::kMinVideoBitrateBps, streams[0].min_bitrate_bps); |
| 3084 | } |
| 3085 | |
| 3086 | TEST_F(WebRtcVideoChannelTest, VerifyMinBitrateWithForcedFallbackFieldTrial) { |
| 3087 | webrtc::test::ScopedFieldTrials override_field_trials_( |
| 3088 | "WebRTC-VP8-Forced-Fallback-Encoder-v2/Enabled-1,2,34567/"); |
| 3089 | std::vector<webrtc::VideoStream> streams = AddSendStream()->GetVideoStreams(); |
| 3090 | ASSERT_EQ(1u, streams.size()); |
| 3091 | EXPECT_EQ(34567, streams[0].min_bitrate_bps); |
| 3092 | } |
| 3093 | |
asapersson | 3c81a1a | 2017-06-14 05:52:21 -0700 | [diff] [blame] | 3094 | TEST_F(WebRtcVideoChannelTest, |
| 3095 | BalancedDegradationPreferenceNotSupportedWithoutFieldtrial) { |
| 3096 | webrtc::test::ScopedFieldTrials override_field_trials_( |
| 3097 | "WebRTC-Video-BalancedDegradation/Disabled/"); |
| 3098 | const bool kResolutionScalingEnabled = true; |
| 3099 | const bool kFpsScalingEnabled = false; |
| 3100 | TestDegradationPreference(kResolutionScalingEnabled, kFpsScalingEnabled); |
| 3101 | } |
| 3102 | |
| 3103 | TEST_F(WebRtcVideoChannelTest, |
| 3104 | BalancedDegradationPreferenceSupportedBehindFieldtrial) { |
| 3105 | webrtc::test::ScopedFieldTrials override_field_trials_( |
| 3106 | "WebRTC-Video-BalancedDegradation/Enabled/"); |
| 3107 | const bool kResolutionScalingEnabled = true; |
| 3108 | const bool kFpsScalingEnabled = true; |
| 3109 | TestDegradationPreference(kResolutionScalingEnabled, kFpsScalingEnabled); |
| 3110 | } |
| 3111 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3112 | TEST_F(WebRtcVideoChannelTest, AdaptsOnOveruse) { |
Erik Språng | efbde37 | 2015-04-29 16:21:28 +0200 | [diff] [blame] | 3113 | TestCpuAdaptation(true, false); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3114 | } |
| 3115 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3116 | TEST_F(WebRtcVideoChannelTest, DoesNotAdaptOnOveruseWhenDisabled) { |
Erik Språng | efbde37 | 2015-04-29 16:21:28 +0200 | [diff] [blame] | 3117 | TestCpuAdaptation(false, false); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3118 | } |
| 3119 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3120 | TEST_F(WebRtcVideoChannelTest, DoesNotAdaptOnOveruseWhenScreensharing) { |
Erik Språng | efbde37 | 2015-04-29 16:21:28 +0200 | [diff] [blame] | 3121 | TestCpuAdaptation(true, true); |
| 3122 | } |
| 3123 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3124 | TEST_F(WebRtcVideoChannelTest, AdaptsOnOveruseAndChangeResolution) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3125 | cricket::VideoCodec codec = GetEngineCodec("VP8"); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3126 | cricket::VideoSendParameters parameters; |
| 3127 | parameters.codecs.push_back(codec); |
| 3128 | |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 3129 | MediaConfig media_config = GetMediaConfig(); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3130 | channel_.reset( |
| 3131 | engine_.CreateChannel(fake_call_.get(), media_config, VideoOptions())); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 3132 | channel_->OnReadyToSend(true); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3133 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 3134 | |
| 3135 | AddSendStream(); |
| 3136 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 3137 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3138 | ASSERT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, &capturer)); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3139 | ASSERT_EQ(cricket::CS_RUNNING, |
| 3140 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 3141 | ASSERT_TRUE(channel_->SetSend(true)); |
| 3142 | |
| 3143 | ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| 3144 | FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3145 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 3146 | EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720)); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3147 | EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
| 3148 | EXPECT_EQ(1280, send_stream->GetLastWidth()); |
| 3149 | EXPECT_EQ(720, send_stream->GetLastHeight()); |
| 3150 | |
| 3151 | // Trigger overuse. |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3152 | rtc::VideoSinkWants wants; |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3153 | wants.max_pixel_count = |
| 3154 | send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1; |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3155 | send_stream->InjectVideoSinkWants(wants); |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 3156 | EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720)); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3157 | EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); |
| 3158 | EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth()); |
| 3159 | EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight()); |
| 3160 | |
| 3161 | // Trigger overuse again. |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3162 | wants.max_pixel_count = |
| 3163 | send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1; |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3164 | send_stream->InjectVideoSinkWants(wants); |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 3165 | EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720)); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3166 | EXPECT_EQ(3, send_stream->GetNumberOfSwappedFrames()); |
| 3167 | EXPECT_EQ(1280 * 2 / 4, send_stream->GetLastWidth()); |
| 3168 | EXPECT_EQ(720 * 2 / 4, send_stream->GetLastHeight()); |
| 3169 | |
| 3170 | // Change input resolution. |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 3171 | EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724)); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3172 | EXPECT_EQ(4, send_stream->GetNumberOfSwappedFrames()); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3173 | EXPECT_EQ(1284 / 2, send_stream->GetLastWidth()); |
| 3174 | EXPECT_EQ(724 / 2, send_stream->GetLastHeight()); |
| 3175 | |
| 3176 | // Trigger underuse which should go back up in resolution. |
sprang | 84a3759 | 2017-02-10 07:04:27 -0800 | [diff] [blame] | 3177 | int current_pixel_count = |
| 3178 | send_stream->GetLastWidth() * send_stream->GetLastHeight(); |
| 3179 | // Cap the max to 4x the pixel count (assuming max 1/2 x 1/2 scale downs) |
| 3180 | // of the current stream, so we don't take too large steps. |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3181 | wants.max_pixel_count = current_pixel_count * 4; |
sprang | 84a3759 | 2017-02-10 07:04:27 -0800 | [diff] [blame] | 3182 | // Default step down is 3/5 pixel count, so go up by 5/3. |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 3183 | wants.target_pixel_count = (current_pixel_count * 5 / 3); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3184 | send_stream->InjectVideoSinkWants(wants); |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 3185 | EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724)); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3186 | EXPECT_EQ(5, send_stream->GetNumberOfSwappedFrames()); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3187 | EXPECT_EQ(1284 * 3 / 4, send_stream->GetLastWidth()); |
| 3188 | EXPECT_EQ(724 * 3 / 4, send_stream->GetLastHeight()); |
| 3189 | |
sprang | 84a3759 | 2017-02-10 07:04:27 -0800 | [diff] [blame] | 3190 | // Trigger underuse again, should go back up to full resolution. |
| 3191 | current_pixel_count = |
| 3192 | send_stream->GetLastWidth() * send_stream->GetLastHeight(); |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3193 | wants.max_pixel_count = current_pixel_count * 4; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 3194 | wants.target_pixel_count = (current_pixel_count * 5 / 3); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3195 | send_stream->InjectVideoSinkWants(wants); |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 3196 | EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724)); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3197 | EXPECT_EQ(6, send_stream->GetNumberOfSwappedFrames()); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3198 | EXPECT_EQ(1284, send_stream->GetLastWidth()); |
| 3199 | EXPECT_EQ(724, send_stream->GetLastHeight()); |
| 3200 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3201 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3202 | } |
| 3203 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3204 | TEST_F(WebRtcVideoChannelTest, PreviousAdaptationDoesNotApplyToScreenshare) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3205 | cricket::VideoCodec codec = GetEngineCodec("VP8"); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3206 | cricket::VideoSendParameters parameters; |
| 3207 | parameters.codecs.push_back(codec); |
| 3208 | |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 3209 | MediaConfig media_config = GetMediaConfig(); |
Niels Möller | 1d7ecd2 | 2018-01-18 15:25:12 +0100 | [diff] [blame] | 3210 | media_config.video.enable_cpu_adaptation = true; |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3211 | channel_.reset( |
| 3212 | engine_.CreateChannel(fake_call_.get(), media_config, VideoOptions())); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 3213 | channel_->OnReadyToSend(true); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3214 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 3215 | |
| 3216 | AddSendStream(); |
| 3217 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 3218 | FakeVideoCapturerWithTaskQueue capturer; |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3219 | ASSERT_EQ(cricket::CS_RUNNING, |
| 3220 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 3221 | ASSERT_TRUE(channel_->SetSend(true)); |
| 3222 | cricket::VideoOptions camera_options; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 3223 | camera_options.is_screencast = false; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3224 | channel_->SetVideoSend(last_ssrc_, &camera_options, |
deadbeef | 5a4a75a | 2016-06-02 16:23:38 -0700 | [diff] [blame] | 3225 | &capturer); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3226 | |
| 3227 | ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| 3228 | FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3229 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 3230 | EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720)); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3231 | EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
| 3232 | EXPECT_EQ(1280, send_stream->GetLastWidth()); |
| 3233 | EXPECT_EQ(720, send_stream->GetLastHeight()); |
| 3234 | |
| 3235 | // Trigger overuse. |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3236 | rtc::VideoSinkWants wants; |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3237 | wants.max_pixel_count = |
| 3238 | send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1; |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3239 | send_stream->InjectVideoSinkWants(wants); |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 3240 | EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720)); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3241 | EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); |
| 3242 | EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth()); |
| 3243 | EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight()); |
| 3244 | |
| 3245 | // Switch to screen share. Expect no CPU adaptation. |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 3246 | FakeVideoCapturerWithTaskQueue screen_share(true); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3247 | ASSERT_EQ(cricket::CS_RUNNING, |
| 3248 | screen_share.Start(screen_share.GetSupportedFormats()->front())); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3249 | cricket::VideoOptions screenshare_options; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 3250 | screenshare_options.is_screencast = true; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3251 | channel_->SetVideoSend(last_ssrc_, &screenshare_options, |
deadbeef | 5a4a75a | 2016-06-02 16:23:38 -0700 | [diff] [blame] | 3252 | &screen_share); |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 3253 | EXPECT_TRUE(screen_share.CaptureCustomFrame(1284, 724)); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 3254 | ASSERT_EQ(2, fake_call_->GetNumCreatedSendStreams()); |
| 3255 | send_stream = fake_call_->GetVideoSendStreams().front(); |
| 3256 | EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3257 | EXPECT_EQ(1284, send_stream->GetLastWidth()); |
| 3258 | EXPECT_EQ(724, send_stream->GetLastHeight()); |
| 3259 | |
| 3260 | // Switch back to the normal capturer. Expect the frame to be CPU adapted. |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3261 | channel_->SetVideoSend(last_ssrc_, &camera_options, |
deadbeef | 5a4a75a | 2016-06-02 16:23:38 -0700 | [diff] [blame] | 3262 | &capturer); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 3263 | send_stream = fake_call_->GetVideoSendStreams().front(); |
| 3264 | // We have a new fake send stream, so it doesn't remember the old sink wants. |
| 3265 | // In practice, it will be populated from |
mflodman | cc3d442 | 2017-08-03 08:27:51 -0700 | [diff] [blame] | 3266 | // VideoStreamEncoder::VideoSourceProxy::SetSource(), so simulate that here. |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 3267 | send_stream->InjectVideoSinkWants(wants); |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 3268 | EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720)); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 3269 | ASSERT_EQ(3, fake_call_->GetNumCreatedSendStreams()); |
| 3270 | send_stream = fake_call_->GetVideoSendStreams().front(); |
| 3271 | EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3272 | EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth()); |
| 3273 | EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight()); |
| 3274 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3275 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3276 | } |
| 3277 | |
asapersson | 3c81a1a | 2017-06-14 05:52:21 -0700 | [diff] [blame] | 3278 | // TODO(asapersson): Remove this test when the balanced field trial is removed. |
| 3279 | void WebRtcVideoChannelTest::TestDegradationPreference( |
| 3280 | bool resolution_scaling_enabled, |
| 3281 | bool fps_scaling_enabled) { |
| 3282 | cricket::VideoCodec codec = GetEngineCodec("VP8"); |
| 3283 | cricket::VideoSendParameters parameters; |
| 3284 | parameters.codecs.push_back(codec); |
| 3285 | |
| 3286 | MediaConfig media_config = GetMediaConfig(); |
Niels Möller | 1d7ecd2 | 2018-01-18 15:25:12 +0100 | [diff] [blame] | 3287 | media_config.video.enable_cpu_adaptation = true; |
asapersson | 3c81a1a | 2017-06-14 05:52:21 -0700 | [diff] [blame] | 3288 | channel_.reset( |
| 3289 | engine_.CreateChannel(fake_call_.get(), media_config, VideoOptions())); |
| 3290 | channel_->OnReadyToSend(true); |
| 3291 | |
| 3292 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 3293 | |
| 3294 | AddSendStream(); |
| 3295 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 3296 | FakeVideoCapturerWithTaskQueue capturer; |
asapersson | 3c81a1a | 2017-06-14 05:52:21 -0700 | [diff] [blame] | 3297 | VideoOptions options; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3298 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
asapersson | 3c81a1a | 2017-06-14 05:52:21 -0700 | [diff] [blame] | 3299 | cricket::VideoFormat capture_format = capturer.GetSupportedFormats()->front(); |
| 3300 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format)); |
| 3301 | |
| 3302 | EXPECT_TRUE(channel_->SetSend(true)); |
| 3303 | |
| 3304 | FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
| 3305 | EXPECT_EQ(resolution_scaling_enabled, |
| 3306 | send_stream->resolution_scaling_enabled()); |
| 3307 | EXPECT_EQ(fps_scaling_enabled, send_stream->framerate_scaling_enabled()); |
| 3308 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3309 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
asapersson | 3c81a1a | 2017-06-14 05:52:21 -0700 | [diff] [blame] | 3310 | } |
| 3311 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3312 | void WebRtcVideoChannelTest::TestCpuAdaptation(bool enable_overuse, |
| 3313 | bool is_screenshare) { |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3314 | const int kDefaultFps = 30; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3315 | cricket::VideoCodec codec = GetEngineCodec("VP8"); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3316 | cricket::VideoSendParameters parameters; |
| 3317 | parameters.codecs.push_back(codec); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3318 | |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 3319 | MediaConfig media_config = GetMediaConfig(); |
| 3320 | if (enable_overuse) { |
Niels Möller | 1d7ecd2 | 2018-01-18 15:25:12 +0100 | [diff] [blame] | 3321 | media_config.video.enable_cpu_adaptation = true; |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 3322 | } |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3323 | channel_.reset( |
| 3324 | engine_.CreateChannel(fake_call_.get(), media_config, VideoOptions())); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 3325 | channel_->OnReadyToSend(true); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3326 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3327 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 3328 | |
| 3329 | AddSendStream(); |
| 3330 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 3331 | FakeVideoCapturerWithTaskQueue capturer; |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 3332 | VideoOptions options; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 3333 | options.is_screencast = is_screenshare; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3334 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 3335 | cricket::VideoFormat capture_format = capturer.GetSupportedFormats()->front(); |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3336 | capture_format.interval = rtc::kNumNanosecsPerSec / kDefaultFps; |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 3337 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format)); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 3338 | |
| 3339 | EXPECT_TRUE(channel_->SetSend(true)); |
| 3340 | |
solenberg | e526974 | 2015-09-08 05:13:22 -0700 | [diff] [blame] | 3341 | FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3342 | |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3343 | if (!enable_overuse) { |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3344 | EXPECT_FALSE(send_stream->resolution_scaling_enabled()); |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3345 | EXPECT_FALSE(send_stream->framerate_scaling_enabled()); |
| 3346 | EXPECT_EQ(is_screenshare, send_stream->framerate_scaling_enabled()); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3347 | |
| 3348 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 3349 | EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
| 3350 | |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 3351 | EXPECT_EQ(capture_format.width, send_stream->GetLastWidth()); |
| 3352 | EXPECT_EQ(capture_format.height, send_stream->GetLastHeight()); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3353 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3354 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3355 | return; |
| 3356 | } |
| 3357 | |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3358 | if (is_screenshare) { |
| 3359 | EXPECT_FALSE(send_stream->resolution_scaling_enabled()); |
| 3360 | EXPECT_TRUE(send_stream->framerate_scaling_enabled()); |
| 3361 | } else { |
| 3362 | EXPECT_TRUE(send_stream->resolution_scaling_enabled()); |
| 3363 | EXPECT_FALSE(send_stream->framerate_scaling_enabled()); |
| 3364 | } |
| 3365 | |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3366 | // Trigger overuse. |
| 3367 | ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| 3368 | |
| 3369 | rtc::VideoSinkWants wants; |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3370 | if (is_screenshare) { |
| 3371 | wants.max_framerate_fps = (kDefaultFps * 2) / 3; |
| 3372 | } else { |
| 3373 | wants.max_pixel_count = capture_format.width * capture_format.height - 1; |
| 3374 | } |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3375 | send_stream->InjectVideoSinkWants(wants); |
| 3376 | |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3377 | for (int i = 0; i < kDefaultFps; ++i) |
| 3378 | EXPECT_TRUE(capturer.CaptureFrame()); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 3379 | |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3380 | if (is_screenshare) { |
| 3381 | // Drops every third frame. |
| 3382 | EXPECT_EQ(kDefaultFps * 2 / 3, send_stream->GetNumberOfSwappedFrames()); |
| 3383 | EXPECT_EQ(send_stream->GetLastWidth(), capture_format.width); |
| 3384 | EXPECT_EQ(send_stream->GetLastHeight(), capture_format.height); |
| 3385 | } else { |
| 3386 | EXPECT_EQ(kDefaultFps, send_stream->GetNumberOfSwappedFrames()); |
| 3387 | EXPECT_LT(send_stream->GetLastWidth(), capture_format.width); |
| 3388 | EXPECT_LT(send_stream->GetLastHeight(), capture_format.height); |
| 3389 | } |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 3390 | |
| 3391 | // Trigger underuse which should go back to normal resolution. |
sprang | 84a3759 | 2017-02-10 07:04:27 -0800 | [diff] [blame] | 3392 | int last_pixel_count = |
| 3393 | send_stream->GetLastWidth() * send_stream->GetLastHeight(); |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3394 | if (is_screenshare) { |
| 3395 | wants.max_framerate_fps = kDefaultFps; |
| 3396 | } else { |
| 3397 | wants.max_pixel_count = last_pixel_count * 4; |
| 3398 | wants.target_pixel_count.emplace((last_pixel_count * 5) / 3); |
| 3399 | } |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3400 | send_stream->InjectVideoSinkWants(wants); |
| 3401 | |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3402 | for (int i = 0; i < kDefaultFps; ++i) |
| 3403 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 3404 | |
| 3405 | if (is_screenshare) { |
| 3406 | EXPECT_EQ(kDefaultFps + (kDefaultFps * 2 / 3), |
| 3407 | send_stream->GetNumberOfSwappedFrames()); |
| 3408 | } else { |
| 3409 | EXPECT_EQ(kDefaultFps * 2, send_stream->GetNumberOfSwappedFrames()); |
| 3410 | } |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 3411 | |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 3412 | EXPECT_EQ(capture_format.width, send_stream->GetLastWidth()); |
| 3413 | EXPECT_EQ(capture_format.height, send_stream->GetLastHeight()); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 3414 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3415 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3416 | } |
| 3417 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3418 | TEST_F(WebRtcVideoChannelTest, EstimatesNtpStartTimeCorrectly) { |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 3419 | // Start at last timestamp to verify that wraparounds are estimated correctly. |
| 3420 | static const uint32_t kInitialTimestamp = 0xFFFFFFFFu; |
| 3421 | static const int64_t kInitialNtpTimeMs = 1247891230; |
| 3422 | static const int kFrameOffsetMs = 20; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3423 | EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3424 | |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 3425 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 3426 | cricket::FakeVideoRenderer renderer; |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 3427 | EXPECT_TRUE(channel_->SetSink(last_ssrc_, &renderer)); |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 3428 | |
nisse | 64ec8f8 | 2016-09-27 00:17:25 -0700 | [diff] [blame] | 3429 | webrtc::VideoFrame video_frame(CreateBlackFrameBuffer(4, 4), |
| 3430 | kInitialTimestamp, 0, |
| 3431 | webrtc::kVideoRotation_0); |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 3432 | // Initial NTP time is not available on the first frame, but should still be |
| 3433 | // able to be estimated. |
nisse | eb83a1a | 2016-03-21 01:27:56 -0700 | [diff] [blame] | 3434 | stream->InjectFrame(video_frame); |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 3435 | |
| 3436 | EXPECT_EQ(1, renderer.num_rendered_frames()); |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 3437 | |
| 3438 | // This timestamp is kInitialTimestamp (-1) + kFrameOffsetMs * 90, which |
| 3439 | // triggers a constant-overflow warning, hence we're calculating it explicitly |
| 3440 | // here. |
| 3441 | video_frame.set_timestamp(kFrameOffsetMs * 90 - 1); |
| 3442 | video_frame.set_ntp_time_ms(kInitialNtpTimeMs + kFrameOffsetMs); |
nisse | eb83a1a | 2016-03-21 01:27:56 -0700 | [diff] [blame] | 3443 | stream->InjectFrame(video_frame); |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 3444 | |
| 3445 | EXPECT_EQ(2, renderer.num_rendered_frames()); |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 3446 | |
| 3447 | // Verify that NTP time has been correctly deduced. |
| 3448 | cricket::VideoMediaInfo info; |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 3449 | ASSERT_TRUE(channel_->GetStats(&info)); |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 3450 | ASSERT_EQ(1u, info.receivers.size()); |
| 3451 | EXPECT_EQ(kInitialNtpTimeMs, info.receivers[0].capture_start_ntp_time_ms); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3452 | } |
| 3453 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3454 | TEST_F(WebRtcVideoChannelTest, SetDefaultSendCodecs) { |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 3455 | AssignDefaultAptRtxTypes(); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3456 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3457 | |
| 3458 | VideoCodec codec; |
| 3459 | EXPECT_TRUE(channel_->GetSendCodec(&codec)); |
pbos@webrtc.org | 9fbb717 | 2014-06-13 09:34:13 +0000 | [diff] [blame] | 3460 | EXPECT_TRUE(codec.Matches(engine_.codecs()[0])); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3461 | |
| 3462 | // Using a RTX setup to verify that the default RTX payload type is good. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 3463 | const std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs1); |
| 3464 | const std::vector<uint32_t> rtx_ssrcs = MAKE_VECTOR(kRtxSsrcs1); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3465 | FakeVideoSendStream* stream = AddSendStream( |
| 3466 | cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 3467 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3468 | |
| 3469 | // Make sure NACK and FEC are enabled on the correct payload types. |
| 3470 | EXPECT_EQ(1000, config.rtp.nack.rtp_history_ms); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3471 | EXPECT_EQ(GetEngineCodec("ulpfec").id, config.rtp.ulpfec.ulpfec_payload_type); |
| 3472 | EXPECT_EQ(GetEngineCodec("red").id, config.rtp.ulpfec.red_payload_type); |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 3473 | |
| 3474 | EXPECT_EQ(1u, config.rtp.rtx.ssrcs.size()); |
| 3475 | EXPECT_EQ(kRtxSsrcs1[0], config.rtp.rtx.ssrcs[0]); |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 3476 | VerifySendStreamHasRtxTypes(config, default_apt_rtx_types_); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3477 | // TODO(juberti): Check RTCP, PLI, TMMBR. |
| 3478 | } |
| 3479 | |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3480 | // The following four tests ensures that FlexFEC is not activated by default |
| 3481 | // when the field trials are not enabled. |
| 3482 | // TODO(brandtr): Remove or update these tests when FlexFEC _is_ enabled by |
| 3483 | // default. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3484 | TEST_F(WebRtcVideoChannelTest, |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3485 | FlexfecSendCodecWithoutSsrcNotExposedByDefault) { |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3486 | FakeVideoSendStream* stream = AddSendStream(); |
| 3487 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| 3488 | |
brandtr | 3d200bd | 2017-01-16 06:59:19 -0800 | [diff] [blame] | 3489 | EXPECT_EQ(-1, config.rtp.flexfec.payload_type); |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3490 | EXPECT_EQ(0U, config.rtp.flexfec.ssrc); |
| 3491 | EXPECT_TRUE(config.rtp.flexfec.protected_media_ssrcs.empty()); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3492 | } |
| 3493 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3494 | TEST_F(WebRtcVideoChannelTest, FlexfecSendCodecWithSsrcNotExposedByDefault) { |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3495 | FakeVideoSendStream* stream = AddSendStream( |
| 3496 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| 3497 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| 3498 | |
brandtr | 3d200bd | 2017-01-16 06:59:19 -0800 | [diff] [blame] | 3499 | EXPECT_EQ(-1, config.rtp.flexfec.payload_type); |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3500 | EXPECT_EQ(0U, config.rtp.flexfec.ssrc); |
| 3501 | EXPECT_TRUE(config.rtp.flexfec.protected_media_ssrcs.empty()); |
| 3502 | } |
| 3503 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3504 | TEST_F(WebRtcVideoChannelTest, |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3505 | FlexfecRecvCodecWithoutSsrcNotExposedByDefault) { |
| 3506 | AddRecvStream(); |
| 3507 | |
| 3508 | const std::vector<FakeFlexfecReceiveStream*>& streams = |
| 3509 | fake_call_->GetFlexfecReceiveStreams(); |
| 3510 | EXPECT_TRUE(streams.empty()); |
| 3511 | } |
| 3512 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3513 | TEST_F(WebRtcVideoChannelTest, FlexfecRecvCodecWithSsrcNotExposedByDefault) { |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3514 | AddRecvStream( |
| 3515 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| 3516 | |
| 3517 | const std::vector<FakeFlexfecReceiveStream*>& streams = |
| 3518 | fake_call_->GetFlexfecReceiveStreams(); |
| 3519 | EXPECT_TRUE(streams.empty()); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3520 | } |
| 3521 | |
| 3522 | // TODO(brandtr): When FlexFEC is no longer behind a field trial, merge all |
| 3523 | // tests that use this test fixture into the corresponding "non-field trial" |
| 3524 | // tests. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3525 | class WebRtcVideoChannelFlexfecRecvTest : public WebRtcVideoChannelTest { |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3526 | public: |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3527 | WebRtcVideoChannelFlexfecRecvTest() |
| 3528 | : WebRtcVideoChannelTest("WebRTC-FlexFEC-03-Advertised/Enabled/") {} |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3529 | }; |
| 3530 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3531 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, |
brandtr | 36e7d70 | 2017-01-13 07:15:54 -0800 | [diff] [blame] | 3532 | DefaultFlexfecCodecHasTransportCcAndRembFeedbackParam) { |
| 3533 | EXPECT_TRUE(cricket::HasTransportCc(GetEngineCodec("flexfec-03"))); |
| 3534 | EXPECT_TRUE(cricket::HasRemb(GetEngineCodec("flexfec-03"))); |
| 3535 | } |
| 3536 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3537 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, SetDefaultRecvCodecsWithoutSsrc) { |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3538 | AddRecvStream(); |
| 3539 | |
| 3540 | const std::vector<FakeFlexfecReceiveStream*>& streams = |
| 3541 | fake_call_->GetFlexfecReceiveStreams(); |
| 3542 | EXPECT_TRUE(streams.empty()); |
Rasmus Brandt | 60bb6fe | 2018-02-05 09:51:47 +0100 | [diff] [blame] | 3543 | |
| 3544 | const std::vector<FakeVideoReceiveStream*>& video_streams = |
| 3545 | fake_call_->GetVideoReceiveStreams(); |
| 3546 | ASSERT_EQ(1U, video_streams.size()); |
| 3547 | const FakeVideoReceiveStream& video_stream = *video_streams.front(); |
| 3548 | EXPECT_EQ(0, video_stream.GetNumAddedSecondarySinks()); |
| 3549 | EXPECT_EQ(0, video_stream.GetNumRemovedSecondarySinks()); |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3550 | } |
| 3551 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3552 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, SetDefaultRecvCodecsWithSsrc) { |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3553 | AddRecvStream( |
| 3554 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| 3555 | |
| 3556 | const std::vector<FakeFlexfecReceiveStream*>& streams = |
| 3557 | fake_call_->GetFlexfecReceiveStreams(); |
| 3558 | ASSERT_EQ(1U, streams.size()); |
| 3559 | const FakeFlexfecReceiveStream* stream = streams.front(); |
| 3560 | const webrtc::FlexfecReceiveStream::Config& config = stream->GetConfig(); |
| 3561 | EXPECT_EQ(GetEngineCodec("flexfec-03").id, config.payload_type); |
| 3562 | EXPECT_EQ(kFlexfecSsrc, config.remote_ssrc); |
| 3563 | ASSERT_EQ(1U, config.protected_media_ssrcs.size()); |
| 3564 | EXPECT_EQ(kSsrcs1[0], config.protected_media_ssrcs[0]); |
brandtr | 7cd28b9 | 2017-09-22 00:26:25 -0700 | [diff] [blame] | 3565 | |
| 3566 | const std::vector<FakeVideoReceiveStream*>& video_streams = |
| 3567 | fake_call_->GetVideoReceiveStreams(); |
| 3568 | ASSERT_EQ(1U, video_streams.size()); |
Rasmus Brandt | 60bb6fe | 2018-02-05 09:51:47 +0100 | [diff] [blame] | 3569 | const FakeVideoReceiveStream& video_stream = *video_streams.front(); |
| 3570 | EXPECT_EQ(1, video_stream.GetNumAddedSecondarySinks()); |
brandtr | 7cd28b9 | 2017-09-22 00:26:25 -0700 | [diff] [blame] | 3571 | const webrtc::VideoReceiveStream::Config& video_config = |
Rasmus Brandt | 60bb6fe | 2018-02-05 09:51:47 +0100 | [diff] [blame] | 3572 | video_stream.GetConfig(); |
brandtr | 7cd28b9 | 2017-09-22 00:26:25 -0700 | [diff] [blame] | 3573 | EXPECT_TRUE(video_config.rtp.protected_by_flexfec); |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3574 | } |
| 3575 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3576 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, |
brandtr | 11fb472 | 2017-05-30 01:31:37 -0700 | [diff] [blame] | 3577 | EnablingFlexfecDoesNotRecreateVideoReceiveStream) { |
| 3578 | cricket::VideoRecvParameters recv_parameters; |
| 3579 | recv_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3580 | ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
| 3581 | |
| 3582 | AddRecvStream( |
| 3583 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| 3584 | EXPECT_EQ(1, fake_call_->GetNumCreatedReceiveStreams()); |
Rasmus Brandt | 60bb6fe | 2018-02-05 09:51:47 +0100 | [diff] [blame] | 3585 | const std::vector<FakeVideoReceiveStream*>& video_streams = |
| 3586 | fake_call_->GetVideoReceiveStreams(); |
| 3587 | ASSERT_EQ(1U, video_streams.size()); |
| 3588 | const FakeVideoReceiveStream& video_stream = *video_streams.front(); |
| 3589 | EXPECT_EQ(0, video_stream.GetNumAddedSecondarySinks()); |
| 3590 | EXPECT_EQ(0, video_stream.GetNumRemovedSecondarySinks()); |
brandtr | 11fb472 | 2017-05-30 01:31:37 -0700 | [diff] [blame] | 3591 | |
| 3592 | // Enable FlexFEC. |
| 3593 | recv_parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| 3594 | ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
| 3595 | EXPECT_EQ(2, fake_call_->GetNumCreatedReceiveStreams()) |
| 3596 | << "Enabling FlexFEC should create FlexfecReceiveStream."; |
| 3597 | EXPECT_EQ(1U, fake_call_->GetVideoReceiveStreams().size()) |
| 3598 | << "Enabling FlexFEC should not create VideoReceiveStream."; |
| 3599 | EXPECT_EQ(1U, fake_call_->GetFlexfecReceiveStreams().size()) |
| 3600 | << "Enabling FlexFEC should create a single FlexfecReceiveStream."; |
Rasmus Brandt | 60bb6fe | 2018-02-05 09:51:47 +0100 | [diff] [blame] | 3601 | EXPECT_EQ(1, video_stream.GetNumAddedSecondarySinks()); |
| 3602 | EXPECT_EQ(0, video_stream.GetNumRemovedSecondarySinks()); |
brandtr | 11fb472 | 2017-05-30 01:31:37 -0700 | [diff] [blame] | 3603 | } |
| 3604 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3605 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, |
brandtr | 11fb472 | 2017-05-30 01:31:37 -0700 | [diff] [blame] | 3606 | DisablingFlexfecDoesNotRecreateVideoReceiveStream) { |
| 3607 | cricket::VideoRecvParameters recv_parameters; |
| 3608 | recv_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3609 | recv_parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| 3610 | ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
| 3611 | |
| 3612 | AddRecvStream( |
| 3613 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| 3614 | EXPECT_EQ(2, fake_call_->GetNumCreatedReceiveStreams()); |
brandtr | 11fb472 | 2017-05-30 01:31:37 -0700 | [diff] [blame] | 3615 | EXPECT_EQ(1U, fake_call_->GetFlexfecReceiveStreams().size()); |
Rasmus Brandt | 60bb6fe | 2018-02-05 09:51:47 +0100 | [diff] [blame] | 3616 | const std::vector<FakeVideoReceiveStream*>& video_streams = |
| 3617 | fake_call_->GetVideoReceiveStreams(); |
| 3618 | ASSERT_EQ(1U, video_streams.size()); |
| 3619 | const FakeVideoReceiveStream& video_stream = *video_streams.front(); |
| 3620 | EXPECT_EQ(1, video_stream.GetNumAddedSecondarySinks()); |
| 3621 | EXPECT_EQ(0, video_stream.GetNumRemovedSecondarySinks()); |
brandtr | 11fb472 | 2017-05-30 01:31:37 -0700 | [diff] [blame] | 3622 | |
| 3623 | // Disable FlexFEC. |
| 3624 | recv_parameters.codecs.clear(); |
| 3625 | recv_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3626 | ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
| 3627 | EXPECT_EQ(2, fake_call_->GetNumCreatedReceiveStreams()) |
| 3628 | << "Disabling FlexFEC should not recreate VideoReceiveStream."; |
| 3629 | EXPECT_EQ(1U, fake_call_->GetVideoReceiveStreams().size()) |
| 3630 | << "Disabling FlexFEC should not destroy VideoReceiveStream."; |
| 3631 | EXPECT_TRUE(fake_call_->GetFlexfecReceiveStreams().empty()) |
| 3632 | << "Disabling FlexFEC should destroy FlexfecReceiveStream."; |
Rasmus Brandt | 60bb6fe | 2018-02-05 09:51:47 +0100 | [diff] [blame] | 3633 | EXPECT_EQ(1, video_stream.GetNumAddedSecondarySinks()); |
| 3634 | EXPECT_EQ(1, video_stream.GetNumRemovedSecondarySinks()); |
brandtr | 11fb472 | 2017-05-30 01:31:37 -0700 | [diff] [blame] | 3635 | } |
| 3636 | |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3637 | // TODO(brandtr): When FlexFEC is no longer behind a field trial, merge all |
| 3638 | // tests that use this test fixture into the corresponding "non-field trial" |
| 3639 | // tests. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3640 | class WebRtcVideoChannelFlexfecSendRecvTest : public WebRtcVideoChannelTest { |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3641 | public: |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3642 | WebRtcVideoChannelFlexfecSendRecvTest() |
| 3643 | : WebRtcVideoChannelTest( |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3644 | "WebRTC-FlexFEC-03-Advertised/Enabled/WebRTC-FlexFEC-03/Enabled/") { |
| 3645 | } |
| 3646 | }; |
| 3647 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3648 | TEST_F(WebRtcVideoChannelFlexfecSendRecvTest, |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3649 | SetDefaultSendCodecsWithoutSsrc) { |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3650 | FakeVideoSendStream* stream = AddSendStream(); |
| 3651 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| 3652 | |
brandtr | 3d200bd | 2017-01-16 06:59:19 -0800 | [diff] [blame] | 3653 | EXPECT_EQ(GetEngineCodec("flexfec-03").id, config.rtp.flexfec.payload_type); |
| 3654 | EXPECT_EQ(0U, config.rtp.flexfec.ssrc); |
| 3655 | EXPECT_TRUE(config.rtp.flexfec.protected_media_ssrcs.empty()); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3656 | } |
| 3657 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3658 | TEST_F(WebRtcVideoChannelFlexfecSendRecvTest, SetDefaultSendCodecsWithSsrc) { |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3659 | FakeVideoSendStream* stream = AddSendStream( |
| 3660 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| 3661 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| 3662 | |
brandtr | 3d200bd | 2017-01-16 06:59:19 -0800 | [diff] [blame] | 3663 | EXPECT_EQ(GetEngineCodec("flexfec-03").id, config.rtp.flexfec.payload_type); |
| 3664 | EXPECT_EQ(kFlexfecSsrc, config.rtp.flexfec.ssrc); |
| 3665 | ASSERT_EQ(1U, config.rtp.flexfec.protected_media_ssrcs.size()); |
| 3666 | EXPECT_EQ(kSsrcs1[0], config.rtp.flexfec.protected_media_ssrcs[0]); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3667 | } |
| 3668 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3669 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsWithoutFec) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3670 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3671 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3672 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3673 | |
| 3674 | FakeVideoSendStream* stream = AddSendStream(); |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 3675 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3676 | |
brandtr | b5f2c3f | 2016-10-04 23:28:39 -0700 | [diff] [blame] | 3677 | EXPECT_EQ(-1, config.rtp.ulpfec.ulpfec_payload_type); |
| 3678 | EXPECT_EQ(-1, config.rtp.ulpfec.red_payload_type); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3679 | } |
| 3680 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3681 | TEST_F(WebRtcVideoChannelFlexfecSendRecvTest, SetSendCodecsWithoutFec) { |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3682 | cricket::VideoSendParameters parameters; |
| 3683 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3684 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 3685 | |
| 3686 | FakeVideoSendStream* stream = AddSendStream(); |
| 3687 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| 3688 | |
brandtr | 3d200bd | 2017-01-16 06:59:19 -0800 | [diff] [blame] | 3689 | EXPECT_EQ(-1, config.rtp.flexfec.payload_type); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3690 | } |
| 3691 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3692 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, SetRecvCodecsWithFec) { |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 3693 | AddRecvStream( |
| 3694 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 3695 | |
| 3696 | cricket::VideoRecvParameters recv_parameters; |
| 3697 | recv_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3698 | recv_parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| 3699 | ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
brandtr | 9d58d94 | 2017-02-03 04:43:41 -0800 | [diff] [blame] | 3700 | |
| 3701 | const std::vector<FakeFlexfecReceiveStream*>& flexfec_streams = |
| 3702 | fake_call_->GetFlexfecReceiveStreams(); |
| 3703 | ASSERT_EQ(1U, flexfec_streams.size()); |
| 3704 | const FakeFlexfecReceiveStream* flexfec_stream = flexfec_streams.front(); |
| 3705 | const webrtc::FlexfecReceiveStream::Config& flexfec_stream_config = |
| 3706 | flexfec_stream->GetConfig(); |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 3707 | EXPECT_EQ(GetEngineCodec("flexfec-03").id, |
brandtr | 9d58d94 | 2017-02-03 04:43:41 -0800 | [diff] [blame] | 3708 | flexfec_stream_config.payload_type); |
| 3709 | EXPECT_EQ(kFlexfecSsrc, flexfec_stream_config.remote_ssrc); |
| 3710 | ASSERT_EQ(1U, flexfec_stream_config.protected_media_ssrcs.size()); |
| 3711 | EXPECT_EQ(kSsrcs1[0], flexfec_stream_config.protected_media_ssrcs[0]); |
| 3712 | const std::vector<FakeVideoReceiveStream*>& video_streams = |
| 3713 | fake_call_->GetVideoReceiveStreams(); |
| 3714 | const FakeVideoReceiveStream* video_stream = video_streams.front(); |
| 3715 | const webrtc::VideoReceiveStream::Config& video_stream_config = |
| 3716 | video_stream->GetConfig(); |
| 3717 | EXPECT_EQ(video_stream_config.rtp.local_ssrc, |
| 3718 | flexfec_stream_config.local_ssrc); |
| 3719 | EXPECT_EQ(video_stream_config.rtp.rtcp_mode, flexfec_stream_config.rtcp_mode); |
| 3720 | EXPECT_EQ(video_stream_config.rtcp_send_transport, |
| 3721 | flexfec_stream_config.rtcp_send_transport); |
| 3722 | // TODO(brandtr): Update this EXPECT when we set |transport_cc| in a |
| 3723 | // spec-compliant way. |
| 3724 | EXPECT_EQ(video_stream_config.rtp.transport_cc, |
| 3725 | flexfec_stream_config.transport_cc); |
| 3726 | EXPECT_EQ(video_stream_config.rtp.rtcp_mode, flexfec_stream_config.rtcp_mode); |
| 3727 | EXPECT_EQ(video_stream_config.rtp.extensions, |
| 3728 | flexfec_stream_config.rtp_header_extensions); |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 3729 | } |
| 3730 | |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3731 | // We should not send FlexFEC, even if we advertise it, unless the right |
| 3732 | // field trial is set. |
| 3733 | // TODO(brandtr): Remove when FlexFEC is enabled by default. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3734 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3735 | SetSendCodecsWithoutSsrcWithFecDoesNotEnableFec) { |
| 3736 | cricket::VideoSendParameters parameters; |
| 3737 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3738 | parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| 3739 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 3740 | |
| 3741 | FakeVideoSendStream* stream = AddSendStream(); |
| 3742 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| 3743 | |
| 3744 | EXPECT_EQ(-1, config.rtp.flexfec.payload_type); |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 3745 | EXPECT_EQ(0u, config.rtp.flexfec.ssrc); |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3746 | EXPECT_TRUE(config.rtp.flexfec.protected_media_ssrcs.empty()); |
| 3747 | } |
| 3748 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3749 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3750 | SetSendCodecsWithSsrcWithFecDoesNotEnableFec) { |
| 3751 | cricket::VideoSendParameters parameters; |
| 3752 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3753 | parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| 3754 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 3755 | |
| 3756 | FakeVideoSendStream* stream = AddSendStream( |
| 3757 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| 3758 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| 3759 | |
| 3760 | EXPECT_EQ(-1, config.rtp.flexfec.payload_type); |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 3761 | EXPECT_EQ(0u, config.rtp.flexfec.ssrc); |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3762 | EXPECT_TRUE(config.rtp.flexfec.protected_media_ssrcs.empty()); |
| 3763 | } |
| 3764 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3765 | TEST_F(WebRtcVideoChannelTest, |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 3766 | SetSendCodecRejectsRtxWithoutAssociatedPayloadType) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3767 | const int kUnusedPayloadType = 127; |
| 3768 | EXPECT_FALSE(FindCodecById(engine_.codecs(), kUnusedPayloadType)); |
| 3769 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3770 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3771 | cricket::VideoCodec rtx_codec(kUnusedPayloadType, "rtx"); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3772 | parameters.codecs.push_back(rtx_codec); |
| 3773 | EXPECT_FALSE(channel_->SetSendParameters(parameters)) |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 3774 | << "RTX codec without associated payload type should be rejected."; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3775 | } |
| 3776 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3777 | TEST_F(WebRtcVideoChannelTest, |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 3778 | SetSendCodecRejectsRtxWithoutMatchingVideoCodec) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3779 | const int kUnusedPayloadType1 = 126; |
| 3780 | const int kUnusedPayloadType2 = 127; |
| 3781 | EXPECT_FALSE(FindCodecById(engine_.codecs(), kUnusedPayloadType1)); |
| 3782 | EXPECT_FALSE(FindCodecById(engine_.codecs(), kUnusedPayloadType2)); |
| 3783 | { |
| 3784 | cricket::VideoCodec rtx_codec = cricket::VideoCodec::CreateRtxCodec( |
| 3785 | kUnusedPayloadType1, GetEngineCodec("VP8").id); |
| 3786 | cricket::VideoSendParameters parameters; |
| 3787 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3788 | parameters.codecs.push_back(rtx_codec); |
| 3789 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 3790 | } |
| 3791 | { |
| 3792 | cricket::VideoCodec rtx_codec = cricket::VideoCodec::CreateRtxCodec( |
| 3793 | kUnusedPayloadType1, kUnusedPayloadType2); |
| 3794 | cricket::VideoSendParameters parameters; |
| 3795 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3796 | parameters.codecs.push_back(rtx_codec); |
| 3797 | EXPECT_FALSE(channel_->SetSendParameters(parameters)) |
| 3798 | << "RTX without matching video codec should be rejected."; |
| 3799 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3800 | } |
| 3801 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3802 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsWithChangedRtxPayloadType) { |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 3803 | const int kUnusedPayloadType1 = 126; |
| 3804 | const int kUnusedPayloadType2 = 127; |
| 3805 | EXPECT_FALSE(FindCodecById(engine_.codecs(), kUnusedPayloadType1)); |
| 3806 | EXPECT_FALSE(FindCodecById(engine_.codecs(), kUnusedPayloadType2)); |
| 3807 | |
| 3808 | // SSRCs for RTX. |
| 3809 | cricket::StreamParams params = |
| 3810 | cricket::StreamParams::CreateLegacy(kSsrcs1[0]); |
| 3811 | params.AddFidSsrc(kSsrcs1[0], kRtxSsrcs1[0]); |
| 3812 | AddSendStream(params); |
| 3813 | |
| 3814 | // Original payload type for RTX. |
| 3815 | cricket::VideoSendParameters parameters; |
| 3816 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3817 | cricket::VideoCodec rtx_codec(kUnusedPayloadType1, "rtx"); |
| 3818 | rtx_codec.SetParam("apt", GetEngineCodec("VP8").id); |
| 3819 | parameters.codecs.push_back(rtx_codec); |
| 3820 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 3821 | ASSERT_EQ(1U, fake_call_->GetVideoSendStreams().size()); |
| 3822 | const webrtc::VideoSendStream::Config& config_before = |
| 3823 | fake_call_->GetVideoSendStreams()[0]->GetConfig(); |
| 3824 | EXPECT_EQ(kUnusedPayloadType1, config_before.rtp.rtx.payload_type); |
| 3825 | ASSERT_EQ(1U, config_before.rtp.rtx.ssrcs.size()); |
| 3826 | EXPECT_EQ(kRtxSsrcs1[0], config_before.rtp.rtx.ssrcs[0]); |
| 3827 | |
| 3828 | // Change payload type for RTX. |
| 3829 | parameters.codecs[1].id = kUnusedPayloadType2; |
| 3830 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 3831 | ASSERT_EQ(1U, fake_call_->GetVideoSendStreams().size()); |
| 3832 | const webrtc::VideoSendStream::Config& config_after = |
| 3833 | fake_call_->GetVideoSendStreams()[0]->GetConfig(); |
| 3834 | EXPECT_EQ(kUnusedPayloadType2, config_after.rtp.rtx.payload_type); |
| 3835 | ASSERT_EQ(1U, config_after.rtp.rtx.ssrcs.size()); |
| 3836 | EXPECT_EQ(kRtxSsrcs1[0], config_after.rtp.rtx.ssrcs[0]); |
| 3837 | } |
| 3838 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3839 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsWithoutFecDisablesFec) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3840 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3841 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3842 | parameters.codecs.push_back(GetEngineCodec("ulpfec")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3843 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 3844 | |
| 3845 | FakeVideoSendStream* stream = AddSendStream(); |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 3846 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 3847 | |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3848 | EXPECT_EQ(GetEngineCodec("ulpfec").id, config.rtp.ulpfec.ulpfec_payload_type); |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 3849 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3850 | parameters.codecs.pop_back(); |
| 3851 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 3852 | stream = fake_call_->GetVideoSendStreams()[0]; |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3853 | ASSERT_TRUE(stream != nullptr); |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 3854 | config = stream->GetConfig().Copy(); |
brandtr | b5f2c3f | 2016-10-04 23:28:39 -0700 | [diff] [blame] | 3855 | EXPECT_EQ(-1, config.rtp.ulpfec.ulpfec_payload_type) |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3856 | << "SetSendCodec without ULPFEC should disable current ULPFEC."; |
| 3857 | } |
| 3858 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3859 | TEST_F(WebRtcVideoChannelFlexfecSendRecvTest, |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3860 | SetSendCodecsWithoutFecDisablesFec) { |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3861 | cricket::VideoSendParameters parameters; |
| 3862 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3863 | parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| 3864 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 3865 | |
| 3866 | FakeVideoSendStream* stream = AddSendStream( |
| 3867 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| 3868 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| 3869 | |
brandtr | 3d200bd | 2017-01-16 06:59:19 -0800 | [diff] [blame] | 3870 | EXPECT_EQ(GetEngineCodec("flexfec-03").id, config.rtp.flexfec.payload_type); |
| 3871 | EXPECT_EQ(kFlexfecSsrc, config.rtp.flexfec.ssrc); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3872 | ASSERT_EQ(1U, config.rtp.flexfec.protected_media_ssrcs.size()); |
| 3873 | EXPECT_EQ(kSsrcs1[0], config.rtp.flexfec.protected_media_ssrcs[0]); |
| 3874 | |
| 3875 | parameters.codecs.pop_back(); |
| 3876 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 3877 | stream = fake_call_->GetVideoSendStreams()[0]; |
| 3878 | ASSERT_TRUE(stream != nullptr); |
| 3879 | config = stream->GetConfig().Copy(); |
brandtr | 3d200bd | 2017-01-16 06:59:19 -0800 | [diff] [blame] | 3880 | EXPECT_EQ(-1, config.rtp.flexfec.payload_type) |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3881 | << "SetSendCodec without FlexFEC should disable current FlexFEC."; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3882 | } |
| 3883 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3884 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsChangesExistingStreams) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3885 | cricket::VideoSendParameters parameters; |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 3886 | cricket::VideoCodec codec(100, "VP8"); |
| 3887 | codec.SetParam(kCodecParamMaxQuantization, kDefaultQpMax); |
| 3888 | parameters.codecs.push_back(codec); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3889 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3890 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 3891 | channel_->SetSend(true); |
pbos@webrtc.org | 38ce7d0 | 2014-07-16 08:01:38 +0000 | [diff] [blame] | 3892 | |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 3893 | FakeVideoSendStream* stream = AddSendStream(); |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 3894 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3895 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, &capturer)); |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 3896 | |
| 3897 | std::vector<webrtc::VideoStream> streams = stream->GetVideoStreams(); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3898 | EXPECT_EQ(kDefaultQpMax, streams[0].max_qp); |
pbos@webrtc.org | 38ce7d0 | 2014-07-16 08:01:38 +0000 | [diff] [blame] | 3899 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3900 | parameters.codecs.clear(); |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 3901 | codec.SetParam(kCodecParamMaxQuantization, kDefaultQpMax + 1); |
| 3902 | parameters.codecs.push_back(codec); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3903 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 3904 | streams = fake_call_->GetVideoSendStreams()[0]->GetVideoStreams(); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3905 | EXPECT_EQ(kDefaultQpMax + 1, streams[0].max_qp); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3906 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3907 | } |
| 3908 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3909 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsWithBitrates) { |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 3910 | SetSendCodecsShouldWorkForBitrates("100", 100000, "150", 150000, "200", |
| 3911 | 200000); |
| 3912 | } |
| 3913 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3914 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsWithHighMaxBitrate) { |
pbos@webrtc.org | a5f6fb5 | 2015-03-23 22:29:39 +0000 | [diff] [blame] | 3915 | SetSendCodecsShouldWorkForBitrates("", 0, "", -1, "10000", 10000000); |
| 3916 | std::vector<webrtc::VideoStream> streams = AddSendStream()->GetVideoStreams(); |
| 3917 | ASSERT_EQ(1u, streams.size()); |
| 3918 | EXPECT_EQ(10000000, streams[0].max_bitrate_bps); |
| 3919 | } |
| 3920 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3921 | TEST_F(WebRtcVideoChannelTest, |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 3922 | SetSendCodecsWithoutBitratesUsesCorrectDefaults) { |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 3923 | SetSendCodecsShouldWorkForBitrates("", 0, "", -1, "", -1); |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 3924 | } |
| 3925 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3926 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsCapsMinAndStartBitrate) { |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 3927 | SetSendCodecsShouldWorkForBitrates("-1", 0, "-100", -1, "", -1); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3928 | } |
| 3929 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3930 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsRejectsMaxLessThanMinBitrate) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3931 | send_parameters_.codecs[0].params[kCodecParamMinBitrate] = "300"; |
| 3932 | send_parameters_.codecs[0].params[kCodecParamMaxBitrate] = "200"; |
| 3933 | EXPECT_FALSE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3934 | } |
| 3935 | |
Taylor Brandstetter | 58f2bd9 | 2016-04-26 17:15:23 -0700 | [diff] [blame] | 3936 | // Test that when both the codec-specific bitrate params and max_bandwidth_bps |
| 3937 | // are present in the same send parameters, the settings are combined correctly. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3938 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsWithBitratesAndMaxSendBandwidth) { |
Taylor Brandstetter | 58f2bd9 | 2016-04-26 17:15:23 -0700 | [diff] [blame] | 3939 | send_parameters_.codecs[0].params[kCodecParamMinBitrate] = "100"; |
| 3940 | send_parameters_.codecs[0].params[kCodecParamStartBitrate] = "200"; |
| 3941 | send_parameters_.codecs[0].params[kCodecParamMaxBitrate] = "300"; |
| 3942 | send_parameters_.max_bandwidth_bps = 400000; |
Taylor Brandstetter | 58f2bd9 | 2016-04-26 17:15:23 -0700 | [diff] [blame] | 3943 | // We expect max_bandwidth_bps to take priority, if set. |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 3944 | ExpectSetBitrateParameters(100000, 200000, 400000); |
| 3945 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| 3946 | // Since the codec isn't changing, start_bitrate_bps should be -1. |
| 3947 | ExpectSetBitrateParameters(100000, -1, 350000); |
Taylor Brandstetter | 58f2bd9 | 2016-04-26 17:15:23 -0700 | [diff] [blame] | 3948 | |
| 3949 | // Decrease max_bandwidth_bps. |
| 3950 | send_parameters_.max_bandwidth_bps = 350000; |
| 3951 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Taylor Brandstetter | 58f2bd9 | 2016-04-26 17:15:23 -0700 | [diff] [blame] | 3952 | |
| 3953 | // Now try again with the values flipped around. |
| 3954 | send_parameters_.codecs[0].params[kCodecParamMaxBitrate] = "400"; |
| 3955 | send_parameters_.max_bandwidth_bps = 300000; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 3956 | ExpectSetBitrateParameters(100000, 200000, 300000); |
Taylor Brandstetter | 58f2bd9 | 2016-04-26 17:15:23 -0700 | [diff] [blame] | 3957 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Taylor Brandstetter | 58f2bd9 | 2016-04-26 17:15:23 -0700 | [diff] [blame] | 3958 | |
| 3959 | // If we change the codec max, max_bandwidth_bps should still apply. |
| 3960 | send_parameters_.codecs[0].params[kCodecParamMaxBitrate] = "350"; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 3961 | ExpectSetBitrateParameters(100000, 200000, 300000); |
Taylor Brandstetter | 58f2bd9 | 2016-04-26 17:15:23 -0700 | [diff] [blame] | 3962 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Taylor Brandstetter | 58f2bd9 | 2016-04-26 17:15:23 -0700 | [diff] [blame] | 3963 | } |
| 3964 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3965 | TEST_F(WebRtcVideoChannelTest, |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 3966 | SetMaxSendBandwidthShouldPreserveOtherBitrates) { |
| 3967 | SetSendCodecsShouldWorkForBitrates("100", 100000, "150", 150000, "200", |
| 3968 | 200000); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3969 | send_parameters_.max_bandwidth_bps = 300000; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 3970 | // Setting max bitrate should keep previous min bitrate. |
| 3971 | // Setting max bitrate should not reset start bitrate. |
| 3972 | ExpectSetBitrateParameters(100000, -1, 300000); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3973 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 3974 | } |
| 3975 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3976 | TEST_F(WebRtcVideoChannelTest, SetMaxSendBandwidthShouldBeRemovable) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3977 | send_parameters_.max_bandwidth_bps = 300000; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 3978 | ExpectSetMaxBitrate(300000); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3979 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
pbos | 5c7760a | 2017-03-10 11:23:12 -0800 | [diff] [blame] | 3980 | // -1 means to disable max bitrate (set infinite). |
| 3981 | send_parameters_.max_bandwidth_bps = -1; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 3982 | ExpectSetMaxBitrate(-1); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3983 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3984 | } |
| 3985 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3986 | TEST_F(WebRtcVideoChannelTest, SetMaxSendBandwidthAndAddSendStream) { |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3987 | send_parameters_.max_bandwidth_bps = 99999; |
| 3988 | FakeVideoSendStream* stream = AddSendStream(); |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 3989 | ExpectSetMaxBitrate(send_parameters_.max_bandwidth_bps); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3990 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3991 | ASSERT_EQ(1u, stream->GetVideoStreams().size()); |
| 3992 | EXPECT_EQ(send_parameters_.max_bandwidth_bps, |
| 3993 | stream->GetVideoStreams()[0].max_bitrate_bps); |
| 3994 | |
| 3995 | send_parameters_.max_bandwidth_bps = 77777; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 3996 | ExpectSetMaxBitrate(send_parameters_.max_bandwidth_bps); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3997 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| 3998 | EXPECT_EQ(send_parameters_.max_bandwidth_bps, |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3999 | stream->GetVideoStreams()[0].max_bitrate_bps); |
| 4000 | } |
| 4001 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4002 | TEST_F(WebRtcVideoChannelTest, SetMaxSendBitrateCanIncreaseSenderBitrate) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4003 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4004 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4005 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4006 | channel_->SetSend(true); |
| 4007 | |
| 4008 | FakeVideoSendStream* stream = AddSendStream(); |
| 4009 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 4010 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 4011 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, &capturer)); |
Peter Boström | 3afc8c4 | 2016-01-27 16:45:21 +0100 | [diff] [blame] | 4012 | EXPECT_EQ(cricket::CS_RUNNING, |
| 4013 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 4014 | |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4015 | std::vector<webrtc::VideoStream> streams = stream->GetVideoStreams(); |
| 4016 | int initial_max_bitrate_bps = streams[0].max_bitrate_bps; |
| 4017 | EXPECT_GT(initial_max_bitrate_bps, 0); |
| 4018 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4019 | parameters.max_bandwidth_bps = initial_max_bitrate_bps * 2; |
| 4020 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
Peter Boström | 3afc8c4 | 2016-01-27 16:45:21 +0100 | [diff] [blame] | 4021 | // Insert a frame to update the encoder config. |
| 4022 | EXPECT_TRUE(capturer.CaptureFrame()); |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4023 | streams = stream->GetVideoStreams(); |
| 4024 | EXPECT_EQ(initial_max_bitrate_bps * 2, streams[0].max_bitrate_bps); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 4025 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4026 | } |
| 4027 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4028 | TEST_F(WebRtcVideoChannelTest, |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4029 | SetMaxSendBitrateCanIncreaseSimulcastSenderBitrate) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4030 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4031 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4032 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4033 | channel_->SetSend(true); |
| 4034 | |
| 4035 | FakeVideoSendStream* stream = AddSendStream( |
| 4036 | cricket::CreateSimStreamParams("cname", MAKE_VECTOR(kSsrcs3))); |
| 4037 | |
| 4038 | // Send a frame to make sure this scales up to >1 stream (simulcast). |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 4039 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 4040 | EXPECT_TRUE(channel_->SetVideoSend(kSsrcs3[0], nullptr, &capturer)); |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4041 | EXPECT_EQ(cricket::CS_RUNNING, |
| 4042 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 4043 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 4044 | |
| 4045 | std::vector<webrtc::VideoStream> streams = stream->GetVideoStreams(); |
| 4046 | ASSERT_GT(streams.size(), 1u) |
| 4047 | << "Without simulcast this test doesn't make sense."; |
pbos | be16f79 | 2015-10-16 12:49:39 -0700 | [diff] [blame] | 4048 | int initial_max_bitrate_bps = GetTotalMaxBitrateBps(streams); |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4049 | EXPECT_GT(initial_max_bitrate_bps, 0); |
| 4050 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4051 | parameters.max_bandwidth_bps = initial_max_bitrate_bps * 2; |
| 4052 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
Peter Boström | 3afc8c4 | 2016-01-27 16:45:21 +0100 | [diff] [blame] | 4053 | // Insert a frame to update the encoder config. |
| 4054 | EXPECT_TRUE(capturer.CaptureFrame()); |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4055 | streams = stream->GetVideoStreams(); |
pbos | be16f79 | 2015-10-16 12:49:39 -0700 | [diff] [blame] | 4056 | int increased_max_bitrate_bps = GetTotalMaxBitrateBps(streams); |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4057 | EXPECT_EQ(initial_max_bitrate_bps * 2, increased_max_bitrate_bps); |
| 4058 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 4059 | EXPECT_TRUE(channel_->SetVideoSend(kSsrcs3[0], nullptr, nullptr)); |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4060 | } |
| 4061 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4062 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsWithMaxQuantization) { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4063 | static const char* kMaxQuantization = "21"; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4064 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4065 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4066 | parameters.codecs[0].params[kCodecParamMaxQuantization] = kMaxQuantization; |
| 4067 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 4068 | EXPECT_EQ(atoi(kMaxQuantization), |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 4069 | AddSendStream()->GetVideoStreams().back().max_qp); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4070 | |
| 4071 | VideoCodec codec; |
| 4072 | EXPECT_TRUE(channel_->GetSendCodec(&codec)); |
| 4073 | EXPECT_EQ(kMaxQuantization, codec.params[kCodecParamMaxQuantization]); |
| 4074 | } |
| 4075 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4076 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsRejectBadPayloadTypes) { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4077 | // TODO(pbos): Should we only allow the dynamic range? |
pkasting@chromium.org | e7a4a12 | 2015-01-28 21:36:55 +0000 | [diff] [blame] | 4078 | static const int kIncorrectPayloads[] = {-2, -1, 128, 129}; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4079 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4080 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
pkasting@chromium.org | e7a4a12 | 2015-01-28 21:36:55 +0000 | [diff] [blame] | 4081 | for (size_t i = 0; i < arraysize(kIncorrectPayloads); ++i) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4082 | parameters.codecs[0].id = kIncorrectPayloads[i]; |
| 4083 | EXPECT_FALSE(channel_->SetSendParameters(parameters)) |
pkasting@chromium.org | d324546 | 2015-02-23 21:28:22 +0000 | [diff] [blame] | 4084 | << "Bad payload type '" << kIncorrectPayloads[i] << "' accepted."; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4085 | } |
| 4086 | } |
| 4087 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4088 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsAcceptAllValidPayloadTypes) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4089 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4090 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
magjed | f823ede | 2016-11-12 09:53:04 -0800 | [diff] [blame] | 4091 | for (int payload_type = 96; payload_type <= 127; ++payload_type) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4092 | parameters.codecs[0].id = payload_type; |
| 4093 | EXPECT_TRUE(channel_->SetSendParameters(parameters)) |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4094 | << "Payload type '" << payload_type << "' rejected."; |
| 4095 | } |
| 4096 | } |
| 4097 | |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 4098 | // Test that setting the a different set of codecs but with an identical front |
| 4099 | // codec doesn't result in the stream being recreated. |
| 4100 | // This may happen when a subsequent negotiation includes fewer codecs, as a |
| 4101 | // result of one of the codecs being rejected. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4102 | TEST_F(WebRtcVideoChannelTest, |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 4103 | SetSendCodecsIdenticalFirstCodecDoesntRecreateStream) { |
| 4104 | cricket::VideoSendParameters parameters1; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4105 | parameters1.codecs.push_back(GetEngineCodec("VP8")); |
| 4106 | parameters1.codecs.push_back(GetEngineCodec("VP9")); |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 4107 | EXPECT_TRUE(channel_->SetSendParameters(parameters1)); |
| 4108 | |
| 4109 | AddSendStream(); |
| 4110 | EXPECT_EQ(1, fake_call_->GetNumCreatedSendStreams()); |
| 4111 | |
| 4112 | cricket::VideoSendParameters parameters2; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4113 | parameters2.codecs.push_back(GetEngineCodec("VP8")); |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 4114 | EXPECT_TRUE(channel_->SetSendParameters(parameters2)); |
| 4115 | EXPECT_EQ(1, fake_call_->GetNumCreatedSendStreams()); |
| 4116 | } |
| 4117 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4118 | TEST_F(WebRtcVideoChannelTest, SetRecvCodecsWithOnlyVp8) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4119 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4120 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4121 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4122 | } |
| 4123 | |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 4124 | // Test that we set our inbound RTX codecs properly. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4125 | TEST_F(WebRtcVideoChannelTest, SetRecvCodecsWithRtx) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4126 | const int kUnusedPayloadType1 = 126; |
| 4127 | const int kUnusedPayloadType2 = 127; |
| 4128 | EXPECT_FALSE(FindCodecById(engine_.codecs(), kUnusedPayloadType1)); |
| 4129 | EXPECT_FALSE(FindCodecById(engine_.codecs(), kUnusedPayloadType2)); |
| 4130 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4131 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4132 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4133 | cricket::VideoCodec rtx_codec(kUnusedPayloadType1, "rtx"); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4134 | parameters.codecs.push_back(rtx_codec); |
| 4135 | EXPECT_FALSE(channel_->SetRecvParameters(parameters)) |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 4136 | << "RTX codec without associated payload should be rejected."; |
| 4137 | |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4138 | parameters.codecs[1].SetParam("apt", kUnusedPayloadType2); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4139 | EXPECT_FALSE(channel_->SetRecvParameters(parameters)) |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 4140 | << "RTX codec with invalid associated payload type should be rejected."; |
| 4141 | |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4142 | parameters.codecs[1].SetParam("apt", GetEngineCodec("VP8").id); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4143 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 4144 | |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4145 | cricket::VideoCodec rtx_codec2(kUnusedPayloadType2, "rtx"); |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 4146 | rtx_codec2.SetParam("apt", rtx_codec.id); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4147 | parameters.codecs.push_back(rtx_codec2); |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 4148 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4149 | EXPECT_FALSE(channel_->SetRecvParameters(parameters)) << |
| 4150 | "RTX codec with another RTX as associated payload type should be " |
| 4151 | "rejected."; |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 4152 | } |
| 4153 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4154 | TEST_F(WebRtcVideoChannelTest, SetRecvCodecsWithChangedRtxPayloadType) { |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 4155 | const int kUnusedPayloadType1 = 126; |
| 4156 | const int kUnusedPayloadType2 = 127; |
| 4157 | EXPECT_FALSE(FindCodecById(engine_.codecs(), kUnusedPayloadType1)); |
| 4158 | EXPECT_FALSE(FindCodecById(engine_.codecs(), kUnusedPayloadType2)); |
| 4159 | |
| 4160 | // SSRCs for RTX. |
| 4161 | cricket::StreamParams params = |
| 4162 | cricket::StreamParams::CreateLegacy(kSsrcs1[0]); |
| 4163 | params.AddFidSsrc(kSsrcs1[0], kRtxSsrcs1[0]); |
| 4164 | AddRecvStream(params); |
| 4165 | |
| 4166 | // Original payload type for RTX. |
| 4167 | cricket::VideoRecvParameters parameters; |
| 4168 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4169 | cricket::VideoCodec rtx_codec(kUnusedPayloadType1, "rtx"); |
| 4170 | rtx_codec.SetParam("apt", GetEngineCodec("VP8").id); |
| 4171 | parameters.codecs.push_back(rtx_codec); |
| 4172 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
| 4173 | ASSERT_EQ(1U, fake_call_->GetVideoReceiveStreams().size()); |
| 4174 | const webrtc::VideoReceiveStream::Config& config_before = |
| 4175 | fake_call_->GetVideoReceiveStreams()[0]->GetConfig(); |
nisse | 26e3abb | 2017-08-25 04:44:25 -0700 | [diff] [blame] | 4176 | EXPECT_EQ(1U, config_before.rtp.rtx_associated_payload_types.size()); |
| 4177 | const int* payload_type_before = FindKeyByValue( |
| 4178 | config_before.rtp.rtx_associated_payload_types, GetEngineCodec("VP8").id); |
| 4179 | ASSERT_NE(payload_type_before, nullptr); |
| 4180 | EXPECT_EQ(kUnusedPayloadType1, *payload_type_before); |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 4181 | EXPECT_EQ(kRtxSsrcs1[0], config_before.rtp.rtx_ssrc); |
| 4182 | |
| 4183 | // Change payload type for RTX. |
| 4184 | parameters.codecs[1].id = kUnusedPayloadType2; |
| 4185 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
| 4186 | ASSERT_EQ(1U, fake_call_->GetVideoReceiveStreams().size()); |
| 4187 | const webrtc::VideoReceiveStream::Config& config_after = |
| 4188 | fake_call_->GetVideoReceiveStreams()[0]->GetConfig(); |
nisse | 26e3abb | 2017-08-25 04:44:25 -0700 | [diff] [blame] | 4189 | EXPECT_EQ(1U, config_after.rtp.rtx_associated_payload_types.size()); |
| 4190 | const int* payload_type_after = FindKeyByValue( |
| 4191 | config_after.rtp.rtx_associated_payload_types, GetEngineCodec("VP8").id); |
| 4192 | ASSERT_NE(payload_type_after, nullptr); |
| 4193 | EXPECT_EQ(kUnusedPayloadType2, *payload_type_after); |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 4194 | EXPECT_EQ(kRtxSsrcs1[0], config_after.rtp.rtx_ssrc); |
| 4195 | } |
| 4196 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4197 | TEST_F(WebRtcVideoChannelTest, SetRecvCodecsDifferentPayloadType) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4198 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4199 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4200 | parameters.codecs[0].id = 99; |
| 4201 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4202 | } |
| 4203 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4204 | TEST_F(WebRtcVideoChannelTest, SetRecvCodecsAcceptDefaultCodecs) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4205 | cricket::VideoRecvParameters parameters; |
| 4206 | parameters.codecs = engine_.codecs(); |
| 4207 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | ccbed3b | 2014-07-11 13:02:54 +0000 | [diff] [blame] | 4208 | |
| 4209 | FakeVideoReceiveStream* stream = AddRecvStream(); |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 4210 | const webrtc::VideoReceiveStream::Config& config = stream->GetConfig(); |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 4211 | EXPECT_EQ(engine_.codecs()[0].name, config.decoders[0].payload_name); |
| 4212 | EXPECT_EQ(engine_.codecs()[0].id, config.decoders[0].payload_type); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4213 | } |
| 4214 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4215 | TEST_F(WebRtcVideoChannelTest, SetRecvCodecsRejectUnsupportedCodec) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4216 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4217 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 4218 | parameters.codecs.push_back(VideoCodec(101, "WTF3")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4219 | EXPECT_FALSE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4220 | } |
| 4221 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4222 | TEST_F(WebRtcVideoChannelTest, SetRecvCodecsAcceptsMultipleVideoCodecs) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4223 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4224 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4225 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4226 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4227 | } |
| 4228 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4229 | TEST_F(WebRtcVideoChannelTest, SetRecvCodecsWithoutFecDisablesFec) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4230 | cricket::VideoSendParameters send_parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4231 | send_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4232 | send_parameters.codecs.push_back(GetEngineCodec("red")); |
| 4233 | send_parameters.codecs.push_back(GetEngineCodec("ulpfec")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4234 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters)); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 4235 | |
| 4236 | FakeVideoReceiveStream* stream = AddRecvStream(); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 4237 | |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4238 | EXPECT_EQ(GetEngineCodec("ulpfec").id, |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 4239 | stream->GetConfig().rtp.ulpfec_payload_type); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 4240 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4241 | cricket::VideoRecvParameters recv_parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4242 | recv_parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4243 | ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 4244 | stream = fake_call_->GetVideoReceiveStreams()[0]; |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4245 | ASSERT_TRUE(stream != nullptr); |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 4246 | EXPECT_EQ(-1, stream->GetConfig().rtp.ulpfec_payload_type) |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4247 | << "SetSendCodec without ULPFEC should disable current ULPFEC."; |
| 4248 | } |
| 4249 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4250 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, SetRecvParamsWithoutFecDisablesFec) { |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4251 | AddRecvStream( |
| 4252 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4253 | const std::vector<FakeFlexfecReceiveStream*>& streams = |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4254 | fake_call_->GetFlexfecReceiveStreams(); |
| 4255 | |
| 4256 | ASSERT_EQ(1U, streams.size()); |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4257 | const FakeFlexfecReceiveStream* stream = streams.front(); |
| 4258 | EXPECT_EQ(GetEngineCodec("flexfec-03").id, stream->GetConfig().payload_type); |
| 4259 | EXPECT_EQ(kFlexfecSsrc, stream->GetConfig().remote_ssrc); |
| 4260 | ASSERT_EQ(1U, stream->GetConfig().protected_media_ssrcs.size()); |
| 4261 | EXPECT_EQ(kSsrcs1[0], stream->GetConfig().protected_media_ssrcs[0]); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4262 | |
| 4263 | cricket::VideoRecvParameters recv_parameters; |
| 4264 | recv_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4265 | ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
| 4266 | EXPECT_TRUE(streams.empty()) |
| 4267 | << "SetSendCodec without FlexFEC should disable current FlexFEC."; |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 4268 | } |
| 4269 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4270 | TEST_F(WebRtcVideoChannelTest, SetSendParamsWithFecEnablesFec) { |
Stefan Holmer | 2b1f651 | 2016-05-17 16:33:30 +0200 | [diff] [blame] | 4271 | FakeVideoReceiveStream* stream = AddRecvStream(); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4272 | EXPECT_EQ(GetEngineCodec("ulpfec").id, |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 4273 | stream->GetConfig().rtp.ulpfec_payload_type); |
Stefan Holmer | 2b1f651 | 2016-05-17 16:33:30 +0200 | [diff] [blame] | 4274 | |
| 4275 | cricket::VideoRecvParameters recv_parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4276 | recv_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4277 | recv_parameters.codecs.push_back(GetEngineCodec("red")); |
| 4278 | recv_parameters.codecs.push_back(GetEngineCodec("ulpfec")); |
Stefan Holmer | 2b1f651 | 2016-05-17 16:33:30 +0200 | [diff] [blame] | 4279 | ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
| 4280 | stream = fake_call_->GetVideoReceiveStreams()[0]; |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4281 | ASSERT_TRUE(stream != nullptr); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4282 | EXPECT_EQ(GetEngineCodec("ulpfec").id, |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 4283 | stream->GetConfig().rtp.ulpfec_payload_type) |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4284 | << "ULPFEC should be enabled on the receive stream."; |
Stefan Holmer | 2b1f651 | 2016-05-17 16:33:30 +0200 | [diff] [blame] | 4285 | |
| 4286 | cricket::VideoSendParameters send_parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4287 | send_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4288 | send_parameters.codecs.push_back(GetEngineCodec("red")); |
| 4289 | send_parameters.codecs.push_back(GetEngineCodec("ulpfec")); |
Stefan Holmer | 2b1f651 | 2016-05-17 16:33:30 +0200 | [diff] [blame] | 4290 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters)); |
| 4291 | stream = fake_call_->GetVideoReceiveStreams()[0]; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4292 | EXPECT_EQ(GetEngineCodec("ulpfec").id, |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 4293 | stream->GetConfig().rtp.ulpfec_payload_type) |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4294 | << "ULPFEC should be enabled on the receive stream."; |
| 4295 | } |
| 4296 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4297 | TEST_F(WebRtcVideoChannelFlexfecSendRecvTest, |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 4298 | SetSendRecvParamsWithFecEnablesFec) { |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4299 | AddRecvStream( |
| 4300 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4301 | const std::vector<FakeFlexfecReceiveStream*>& streams = |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4302 | fake_call_->GetFlexfecReceiveStreams(); |
| 4303 | |
| 4304 | cricket::VideoRecvParameters recv_parameters; |
| 4305 | recv_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4306 | recv_parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| 4307 | ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
| 4308 | ASSERT_EQ(1U, streams.size()); |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4309 | const FakeFlexfecReceiveStream* stream_with_recv_params = streams.front(); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4310 | EXPECT_EQ(GetEngineCodec("flexfec-03").id, |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4311 | stream_with_recv_params->GetConfig().payload_type); |
| 4312 | EXPECT_EQ(kFlexfecSsrc, stream_with_recv_params->GetConfig().remote_ssrc); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4313 | EXPECT_EQ(1U, |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4314 | stream_with_recv_params->GetConfig().protected_media_ssrcs.size()); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4315 | EXPECT_EQ(kSsrcs1[0], |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4316 | stream_with_recv_params->GetConfig().protected_media_ssrcs[0]); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4317 | |
| 4318 | cricket::VideoSendParameters send_parameters; |
| 4319 | send_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4320 | send_parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| 4321 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters)); |
| 4322 | ASSERT_EQ(1U, streams.size()); |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4323 | const FakeFlexfecReceiveStream* stream_with_send_params = streams.front(); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4324 | EXPECT_EQ(GetEngineCodec("flexfec-03").id, |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4325 | stream_with_send_params->GetConfig().payload_type); |
| 4326 | EXPECT_EQ(kFlexfecSsrc, stream_with_send_params->GetConfig().remote_ssrc); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4327 | EXPECT_EQ(1U, |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4328 | stream_with_send_params->GetConfig().protected_media_ssrcs.size()); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4329 | EXPECT_EQ(kSsrcs1[0], |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4330 | stream_with_send_params->GetConfig().protected_media_ssrcs[0]); |
Stefan Holmer | 2b1f651 | 2016-05-17 16:33:30 +0200 | [diff] [blame] | 4331 | } |
| 4332 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4333 | TEST_F(WebRtcVideoChannelTest, SetRecvCodecsRejectDuplicateFecPayloads) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4334 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4335 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4336 | parameters.codecs.push_back(GetEngineCodec("red")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4337 | parameters.codecs[1].id = parameters.codecs[0].id; |
| 4338 | EXPECT_FALSE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4339 | } |
| 4340 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4341 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 4342 | SetRecvCodecsRejectDuplicateFecPayloads) { |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4343 | cricket::VideoRecvParameters parameters; |
| 4344 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4345 | parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| 4346 | parameters.codecs[1].id = parameters.codecs[0].id; |
| 4347 | EXPECT_FALSE(channel_->SetRecvParameters(parameters)); |
| 4348 | } |
| 4349 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4350 | TEST_F(WebRtcVideoChannelTest, SetRecvCodecsRejectDuplicateCodecPayloads) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4351 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4352 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4353 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4354 | parameters.codecs[1].id = parameters.codecs[0].id; |
| 4355 | EXPECT_FALSE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4356 | } |
| 4357 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4358 | TEST_F(WebRtcVideoChannelTest, |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4359 | SetRecvCodecsAcceptSameCodecOnMultiplePayloadTypes) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4360 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4361 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4362 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4363 | parameters.codecs[1].id += 1; |
| 4364 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4365 | } |
| 4366 | |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 4367 | // Test that setting the same codecs but with a different order |
deadbeef | 874ca3a | 2015-08-20 17:19:20 -0700 | [diff] [blame] | 4368 | // doesn't result in the stream being recreated. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4369 | TEST_F(WebRtcVideoChannelTest, |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 4370 | SetRecvCodecsDifferentOrderDoesntRecreateStream) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4371 | cricket::VideoRecvParameters parameters1; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4372 | parameters1.codecs.push_back(GetEngineCodec("VP8")); |
| 4373 | parameters1.codecs.push_back(GetEngineCodec("red")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4374 | EXPECT_TRUE(channel_->SetRecvParameters(parameters1)); |
deadbeef | 874ca3a | 2015-08-20 17:19:20 -0700 | [diff] [blame] | 4375 | |
| 4376 | AddRecvStream(cricket::StreamParams::CreateLegacy(123)); |
| 4377 | EXPECT_EQ(1, fake_call_->GetNumCreatedReceiveStreams()); |
| 4378 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4379 | cricket::VideoRecvParameters parameters2; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4380 | parameters2.codecs.push_back(GetEngineCodec("red")); |
| 4381 | parameters2.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4382 | EXPECT_TRUE(channel_->SetRecvParameters(parameters2)); |
deadbeef | 874ca3a | 2015-08-20 17:19:20 -0700 | [diff] [blame] | 4383 | EXPECT_EQ(1, fake_call_->GetNumCreatedReceiveStreams()); |
| 4384 | } |
| 4385 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4386 | TEST_F(WebRtcVideoChannelTest, SendStreamNotSendingByDefault) { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4387 | EXPECT_FALSE(AddSendStream()->IsSending()); |
| 4388 | } |
| 4389 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4390 | TEST_F(WebRtcVideoChannelTest, ReceiveStreamReceivingByDefault) { |
pbos@webrtc.org | 85f4294 | 2014-07-22 09:14:58 +0000 | [diff] [blame] | 4391 | EXPECT_TRUE(AddRecvStream()->IsReceiving()); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4392 | } |
| 4393 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4394 | TEST_F(WebRtcVideoChannelTest, SetSend) { |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 4395 | FakeVideoSendStream* stream = AddSendStream(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4396 | EXPECT_FALSE(stream->IsSending()); |
| 4397 | |
| 4398 | // false->true |
| 4399 | EXPECT_TRUE(channel_->SetSend(true)); |
| 4400 | EXPECT_TRUE(stream->IsSending()); |
| 4401 | // true->true |
| 4402 | EXPECT_TRUE(channel_->SetSend(true)); |
| 4403 | EXPECT_TRUE(stream->IsSending()); |
| 4404 | // true->false |
| 4405 | EXPECT_TRUE(channel_->SetSend(false)); |
| 4406 | EXPECT_FALSE(stream->IsSending()); |
| 4407 | // false->false |
| 4408 | EXPECT_TRUE(channel_->SetSend(false)); |
| 4409 | EXPECT_FALSE(stream->IsSending()); |
| 4410 | |
| 4411 | EXPECT_TRUE(channel_->SetSend(true)); |
| 4412 | FakeVideoSendStream* new_stream = AddSendStream(); |
| 4413 | EXPECT_TRUE(new_stream->IsSending()) |
| 4414 | << "Send stream created after SetSend(true) not sending initially."; |
| 4415 | } |
| 4416 | |
pbos@webrtc.org | d819803 | 2014-11-10 14:41:43 +0000 | [diff] [blame] | 4417 | // This test verifies DSCP settings are properly applied on video media channel. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4418 | TEST_F(WebRtcVideoChannelTest, TestSetDscpOptions) { |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 4419 | std::unique_ptr<cricket::FakeNetworkInterface> network_interface( |
pbos@webrtc.org | d819803 | 2014-11-10 14:41:43 +0000 | [diff] [blame] | 4420 | new cricket::FakeNetworkInterface); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 4421 | MediaConfig config; |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 4422 | std::unique_ptr<VideoMediaChannel> channel; |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 4423 | |
| 4424 | channel.reset(engine_.CreateChannel(call_.get(), config, VideoOptions())); |
| 4425 | channel->SetInterface(network_interface.get()); |
| 4426 | // Default value when DSCP is disabled should be DSCP_DEFAULT. |
pbos@webrtc.org | d819803 | 2014-11-10 14:41:43 +0000 | [diff] [blame] | 4427 | EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp()); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 4428 | |
| 4429 | config.enable_dscp = true; |
| 4430 | channel.reset(engine_.CreateChannel(call_.get(), config, VideoOptions())); |
| 4431 | channel->SetInterface(network_interface.get()); |
| 4432 | EXPECT_EQ(rtc::DSCP_AF41, network_interface->dscp()); |
| 4433 | |
| 4434 | // Verify that setting the option to false resets the |
| 4435 | // DiffServCodePoint. |
| 4436 | config.enable_dscp = false; |
| 4437 | channel.reset(engine_.CreateChannel(call_.get(), config, VideoOptions())); |
| 4438 | channel->SetInterface(network_interface.get()); |
| 4439 | EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp()); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4440 | } |
| 4441 | |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 4442 | // This test verifies that the RTCP reduced size mode is properly applied to |
| 4443 | // send video streams. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4444 | TEST_F(WebRtcVideoChannelTest, TestSetSendRtcpReducedSize) { |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 4445 | // Create stream, expecting that default mode is "compound". |
| 4446 | FakeVideoSendStream* stream1 = AddSendStream(); |
| 4447 | EXPECT_EQ(webrtc::RtcpMode::kCompound, stream1->GetConfig().rtp.rtcp_mode); |
Florent Castelli | dacec71 | 2018-05-24 16:24:21 +0200 | [diff] [blame] | 4448 | webrtc::RtpParameters rtp_parameters = |
| 4449 | channel_->GetRtpSendParameters(last_ssrc_); |
| 4450 | EXPECT_FALSE(rtp_parameters.rtcp.reduced_size); |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 4451 | |
| 4452 | // Now enable reduced size mode. |
| 4453 | send_parameters_.rtcp.reduced_size = true; |
| 4454 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| 4455 | stream1 = fake_call_->GetVideoSendStreams()[0]; |
| 4456 | EXPECT_EQ(webrtc::RtcpMode::kReducedSize, stream1->GetConfig().rtp.rtcp_mode); |
Florent Castelli | dacec71 | 2018-05-24 16:24:21 +0200 | [diff] [blame] | 4457 | rtp_parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 4458 | EXPECT_TRUE(rtp_parameters.rtcp.reduced_size); |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 4459 | |
| 4460 | // Create a new stream and ensure it picks up the reduced size mode. |
| 4461 | FakeVideoSendStream* stream2 = AddSendStream(); |
| 4462 | EXPECT_EQ(webrtc::RtcpMode::kReducedSize, stream2->GetConfig().rtp.rtcp_mode); |
| 4463 | } |
| 4464 | |
| 4465 | // This test verifies that the RTCP reduced size mode is properly applied to |
| 4466 | // receive video streams. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4467 | TEST_F(WebRtcVideoChannelTest, TestSetRecvRtcpReducedSize) { |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 4468 | // Create stream, expecting that default mode is "compound". |
| 4469 | FakeVideoReceiveStream* stream1 = AddRecvStream(); |
| 4470 | EXPECT_EQ(webrtc::RtcpMode::kCompound, stream1->GetConfig().rtp.rtcp_mode); |
| 4471 | |
| 4472 | // Now enable reduced size mode. |
Taylor Brandstetter | 5f0b83b | 2016-03-18 15:02:07 -0700 | [diff] [blame] | 4473 | // TODO(deadbeef): Once "recv_parameters" becomes "receiver_parameters", |
| 4474 | // the reduced_size flag should come from that. |
| 4475 | send_parameters_.rtcp.reduced_size = true; |
| 4476 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 4477 | stream1 = fake_call_->GetVideoReceiveStreams()[0]; |
| 4478 | EXPECT_EQ(webrtc::RtcpMode::kReducedSize, stream1->GetConfig().rtp.rtcp_mode); |
| 4479 | |
| 4480 | // Create a new stream and ensure it picks up the reduced size mode. |
| 4481 | FakeVideoReceiveStream* stream2 = AddRecvStream(); |
| 4482 | EXPECT_EQ(webrtc::RtcpMode::kReducedSize, stream2->GetConfig().rtp.rtcp_mode); |
| 4483 | } |
| 4484 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4485 | TEST_F(WebRtcVideoChannelTest, OnReadyToSendSignalsNetworkState) { |
skvlad | 7a43d25 | 2016-03-22 15:32:27 -0700 | [diff] [blame] | 4486 | EXPECT_EQ(webrtc::kNetworkUp, |
| 4487 | fake_call_->GetNetworkState(webrtc::MediaType::VIDEO)); |
| 4488 | EXPECT_EQ(webrtc::kNetworkUp, |
| 4489 | fake_call_->GetNetworkState(webrtc::MediaType::AUDIO)); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 4490 | |
| 4491 | channel_->OnReadyToSend(false); |
skvlad | 7a43d25 | 2016-03-22 15:32:27 -0700 | [diff] [blame] | 4492 | EXPECT_EQ(webrtc::kNetworkDown, |
| 4493 | fake_call_->GetNetworkState(webrtc::MediaType::VIDEO)); |
| 4494 | EXPECT_EQ(webrtc::kNetworkUp, |
| 4495 | fake_call_->GetNetworkState(webrtc::MediaType::AUDIO)); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 4496 | |
| 4497 | channel_->OnReadyToSend(true); |
skvlad | 7a43d25 | 2016-03-22 15:32:27 -0700 | [diff] [blame] | 4498 | EXPECT_EQ(webrtc::kNetworkUp, |
| 4499 | fake_call_->GetNetworkState(webrtc::MediaType::VIDEO)); |
| 4500 | EXPECT_EQ(webrtc::kNetworkUp, |
| 4501 | fake_call_->GetNetworkState(webrtc::MediaType::AUDIO)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4502 | } |
| 4503 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4504 | TEST_F(WebRtcVideoChannelTest, GetStatsReportsSentCodecName) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4505 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4506 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4507 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
Peter Boström | 74d9ed7 | 2015-03-26 16:28:31 +0100 | [diff] [blame] | 4508 | |
| 4509 | AddSendStream(); |
| 4510 | |
| 4511 | cricket::VideoMediaInfo info; |
| 4512 | ASSERT_TRUE(channel_->GetStats(&info)); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4513 | EXPECT_EQ("VP8", info.senders[0].codec_name); |
Peter Boström | 74d9ed7 | 2015-03-26 16:28:31 +0100 | [diff] [blame] | 4514 | } |
| 4515 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4516 | TEST_F(WebRtcVideoChannelTest, GetStatsReportsEncoderImplementationName) { |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 4517 | FakeVideoSendStream* stream = AddSendStream(); |
| 4518 | webrtc::VideoSendStream::Stats stats; |
| 4519 | stats.encoder_implementation_name = "encoder_implementation_name"; |
| 4520 | stream->SetStats(stats); |
| 4521 | |
| 4522 | cricket::VideoMediaInfo info; |
| 4523 | ASSERT_TRUE(channel_->GetStats(&info)); |
| 4524 | EXPECT_EQ(stats.encoder_implementation_name, |
| 4525 | info.senders[0].encoder_implementation_name); |
| 4526 | } |
| 4527 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4528 | TEST_F(WebRtcVideoChannelTest, GetStatsReportsCpuOveruseMetrics) { |
pbos@webrtc.org | 3e6e271 | 2015-02-26 12:19:31 +0000 | [diff] [blame] | 4529 | FakeVideoSendStream* stream = AddSendStream(); |
| 4530 | webrtc::VideoSendStream::Stats stats; |
| 4531 | stats.avg_encode_time_ms = 13; |
| 4532 | stats.encode_usage_percent = 42; |
| 4533 | stream->SetStats(stats); |
| 4534 | |
| 4535 | cricket::VideoMediaInfo info; |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 4536 | ASSERT_TRUE(channel_->GetStats(&info)); |
pbos@webrtc.org | 3e6e271 | 2015-02-26 12:19:31 +0000 | [diff] [blame] | 4537 | EXPECT_EQ(stats.avg_encode_time_ms, info.senders[0].avg_encode_ms); |
| 4538 | EXPECT_EQ(stats.encode_usage_percent, info.senders[0].encode_usage_percent); |
| 4539 | } |
| 4540 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4541 | TEST_F(WebRtcVideoChannelTest, GetStatsReportsFramesEncoded) { |
sakal | 43536c3 | 2016-10-24 01:46:43 -0700 | [diff] [blame] | 4542 | FakeVideoSendStream* stream = AddSendStream(); |
| 4543 | webrtc::VideoSendStream::Stats stats; |
| 4544 | stats.frames_encoded = 13; |
| 4545 | stream->SetStats(stats); |
| 4546 | |
| 4547 | cricket::VideoMediaInfo info; |
| 4548 | ASSERT_TRUE(channel_->GetStats(&info)); |
| 4549 | EXPECT_EQ(stats.frames_encoded, info.senders[0].frames_encoded); |
| 4550 | } |
| 4551 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4552 | TEST_F(WebRtcVideoChannelTest, GetStatsReportsQpSum) { |
sakal | 87da404 | 2016-10-31 06:53:47 -0700 | [diff] [blame] | 4553 | FakeVideoSendStream* stream = AddSendStream(); |
| 4554 | webrtc::VideoSendStream::Stats stats; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 4555 | stats.qp_sum = 13; |
sakal | 87da404 | 2016-10-31 06:53:47 -0700 | [diff] [blame] | 4556 | stream->SetStats(stats); |
| 4557 | |
| 4558 | cricket::VideoMediaInfo info; |
| 4559 | ASSERT_TRUE(channel_->GetStats(&info)); |
| 4560 | EXPECT_EQ(stats.qp_sum, info.senders[0].qp_sum); |
| 4561 | } |
| 4562 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4563 | TEST_F(WebRtcVideoChannelTest, GetStatsReportsUpperResolution) { |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 4564 | FakeVideoSendStream* stream = AddSendStream(); |
| 4565 | webrtc::VideoSendStream::Stats stats; |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 4566 | stats.substreams[17].width = 123; |
| 4567 | stats.substreams[17].height = 40; |
| 4568 | stats.substreams[42].width = 80; |
| 4569 | stats.substreams[42].height = 31; |
| 4570 | stats.substreams[11].width = 20; |
| 4571 | stats.substreams[11].height = 90; |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 4572 | stream->SetStats(stats); |
| 4573 | |
| 4574 | cricket::VideoMediaInfo info; |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 4575 | ASSERT_TRUE(channel_->GetStats(&info)); |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 4576 | ASSERT_EQ(1u, info.senders.size()); |
| 4577 | EXPECT_EQ(123, info.senders[0].send_frame_width); |
| 4578 | EXPECT_EQ(90, info.senders[0].send_frame_height); |
| 4579 | } |
| 4580 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4581 | TEST_F(WebRtcVideoChannelTest, GetStatsReportsCpuAdaptationStats) { |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 4582 | FakeVideoSendStream* stream = AddSendStream(); |
| 4583 | webrtc::VideoSendStream::Stats stats; |
| 4584 | stats.number_of_cpu_adapt_changes = 2; |
| 4585 | stats.cpu_limited_resolution = true; |
| 4586 | stream->SetStats(stats); |
pbos@webrtc.org | 9a4410e | 2015-02-26 10:03:39 +0000 | [diff] [blame] | 4587 | |
pbos@webrtc.org | 9a4410e | 2015-02-26 10:03:39 +0000 | [diff] [blame] | 4588 | cricket::VideoMediaInfo info; |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 4589 | EXPECT_TRUE(channel_->GetStats(&info)); |
pbos@webrtc.org | 9a4410e | 2015-02-26 10:03:39 +0000 | [diff] [blame] | 4590 | ASSERT_EQ(1U, info.senders.size()); |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4591 | EXPECT_EQ(WebRtcVideoChannel::ADAPTREASON_CPU, info.senders[0].adapt_reason); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 4592 | EXPECT_EQ(stats.number_of_cpu_adapt_changes, info.senders[0].adapt_changes); |
pbos@webrtc.org | 9a4410e | 2015-02-26 10:03:39 +0000 | [diff] [blame] | 4593 | } |
| 4594 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4595 | TEST_F(WebRtcVideoChannelTest, GetStatsReportsAdaptationAndBandwidthStats) { |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 4596 | FakeVideoSendStream* stream = AddSendStream(); |
asapersson | 17821db | 2015-12-14 02:08:12 -0800 | [diff] [blame] | 4597 | webrtc::VideoSendStream::Stats stats; |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 4598 | stats.number_of_cpu_adapt_changes = 2; |
| 4599 | stats.cpu_limited_resolution = true; |
asapersson | 17821db | 2015-12-14 02:08:12 -0800 | [diff] [blame] | 4600 | stats.bw_limited_resolution = true; |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 4601 | stream->SetStats(stats); |
| 4602 | |
| 4603 | cricket::VideoMediaInfo info; |
asapersson | 17821db | 2015-12-14 02:08:12 -0800 | [diff] [blame] | 4604 | EXPECT_TRUE(channel_->GetStats(&info)); |
| 4605 | ASSERT_EQ(1U, info.senders.size()); |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4606 | EXPECT_EQ(WebRtcVideoChannel::ADAPTREASON_CPU | |
| 4607 | WebRtcVideoChannel::ADAPTREASON_BANDWIDTH, |
asapersson | 17821db | 2015-12-14 02:08:12 -0800 | [diff] [blame] | 4608 | info.senders[0].adapt_reason); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 4609 | EXPECT_EQ(stats.number_of_cpu_adapt_changes, info.senders[0].adapt_changes); |
asapersson | 17821db | 2015-12-14 02:08:12 -0800 | [diff] [blame] | 4610 | } |
| 4611 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4612 | TEST_F(WebRtcVideoChannelTest, |
asapersson | 17821db | 2015-12-14 02:08:12 -0800 | [diff] [blame] | 4613 | GetStatsTranslatesBandwidthLimitedResolutionCorrectly) { |
| 4614 | FakeVideoSendStream* stream = AddSendStream(); |
| 4615 | webrtc::VideoSendStream::Stats stats; |
| 4616 | stats.bw_limited_resolution = true; |
| 4617 | stream->SetStats(stats); |
| 4618 | |
| 4619 | cricket::VideoMediaInfo info; |
| 4620 | EXPECT_TRUE(channel_->GetStats(&info)); |
| 4621 | ASSERT_EQ(1U, info.senders.size()); |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4622 | EXPECT_EQ(WebRtcVideoChannel::ADAPTREASON_BANDWIDTH, |
asapersson | 17821db | 2015-12-14 02:08:12 -0800 | [diff] [blame] | 4623 | info.senders[0].adapt_reason); |
| 4624 | } |
| 4625 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4626 | TEST_F(WebRtcVideoChannelTest, |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 4627 | GetStatsTranslatesSendRtcpPacketTypesCorrectly) { |
| 4628 | FakeVideoSendStream* stream = AddSendStream(); |
| 4629 | webrtc::VideoSendStream::Stats stats; |
| 4630 | stats.substreams[17].rtcp_packet_type_counts.fir_packets = 2; |
| 4631 | stats.substreams[17].rtcp_packet_type_counts.nack_packets = 3; |
| 4632 | stats.substreams[17].rtcp_packet_type_counts.pli_packets = 4; |
| 4633 | |
| 4634 | stats.substreams[42].rtcp_packet_type_counts.fir_packets = 5; |
| 4635 | stats.substreams[42].rtcp_packet_type_counts.nack_packets = 7; |
| 4636 | stats.substreams[42].rtcp_packet_type_counts.pli_packets = 9; |
| 4637 | |
| 4638 | stream->SetStats(stats); |
| 4639 | |
| 4640 | cricket::VideoMediaInfo info; |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 4641 | ASSERT_TRUE(channel_->GetStats(&info)); |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 4642 | EXPECT_EQ(7, info.senders[0].firs_rcvd); |
| 4643 | EXPECT_EQ(10, info.senders[0].nacks_rcvd); |
| 4644 | EXPECT_EQ(13, info.senders[0].plis_rcvd); |
| 4645 | } |
| 4646 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4647 | TEST_F(WebRtcVideoChannelTest, |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 4648 | GetStatsTranslatesReceiveRtcpPacketTypesCorrectly) { |
| 4649 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 4650 | webrtc::VideoReceiveStream::Stats stats; |
| 4651 | stats.rtcp_packet_type_counts.fir_packets = 2; |
| 4652 | stats.rtcp_packet_type_counts.nack_packets = 3; |
| 4653 | stats.rtcp_packet_type_counts.pli_packets = 4; |
| 4654 | stream->SetStats(stats); |
| 4655 | |
| 4656 | cricket::VideoMediaInfo info; |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 4657 | ASSERT_TRUE(channel_->GetStats(&info)); |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 4658 | EXPECT_EQ(stats.rtcp_packet_type_counts.fir_packets, |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 4659 | rtc::checked_cast<unsigned int>(info.receivers[0].firs_sent)); |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 4660 | EXPECT_EQ(stats.rtcp_packet_type_counts.nack_packets, |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 4661 | rtc::checked_cast<unsigned int>(info.receivers[0].nacks_sent)); |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 4662 | EXPECT_EQ(stats.rtcp_packet_type_counts.pli_packets, |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 4663 | rtc::checked_cast<unsigned int>(info.receivers[0].plis_sent)); |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 4664 | } |
| 4665 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4666 | TEST_F(WebRtcVideoChannelTest, GetStatsTranslatesDecodeStatsCorrectly) { |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 4667 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 4668 | webrtc::VideoReceiveStream::Stats stats; |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 4669 | stats.decoder_implementation_name = "decoder_implementation_name"; |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 4670 | stats.decode_ms = 2; |
| 4671 | stats.max_decode_ms = 3; |
| 4672 | stats.current_delay_ms = 4; |
| 4673 | stats.target_delay_ms = 5; |
| 4674 | stats.jitter_buffer_ms = 6; |
| 4675 | stats.min_playout_delay_ms = 7; |
| 4676 | stats.render_delay_ms = 8; |
asapersson | 26dd92b | 2016-08-30 00:45:45 -0700 | [diff] [blame] | 4677 | stats.width = 9; |
| 4678 | stats.height = 10; |
hbos | 42f6d2f | 2017-01-20 03:56:50 -0800 | [diff] [blame] | 4679 | stats.frame_counts.key_frames = 11; |
| 4680 | stats.frame_counts.delta_frames = 12; |
hbos | 50cfe1f | 2017-01-23 07:21:55 -0800 | [diff] [blame] | 4681 | stats.frames_rendered = 13; |
| 4682 | stats.frames_decoded = 14; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 4683 | stats.qp_sum = 15; |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 4684 | stream->SetStats(stats); |
| 4685 | |
| 4686 | cricket::VideoMediaInfo info; |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 4687 | ASSERT_TRUE(channel_->GetStats(&info)); |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 4688 | EXPECT_EQ(stats.decoder_implementation_name, |
| 4689 | info.receivers[0].decoder_implementation_name); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 4690 | EXPECT_EQ(stats.decode_ms, info.receivers[0].decode_ms); |
| 4691 | EXPECT_EQ(stats.max_decode_ms, info.receivers[0].max_decode_ms); |
| 4692 | EXPECT_EQ(stats.current_delay_ms, info.receivers[0].current_delay_ms); |
| 4693 | EXPECT_EQ(stats.target_delay_ms, info.receivers[0].target_delay_ms); |
| 4694 | EXPECT_EQ(stats.jitter_buffer_ms, info.receivers[0].jitter_buffer_ms); |
| 4695 | EXPECT_EQ(stats.min_playout_delay_ms, info.receivers[0].min_playout_delay_ms); |
| 4696 | EXPECT_EQ(stats.render_delay_ms, info.receivers[0].render_delay_ms); |
asapersson | 26dd92b | 2016-08-30 00:45:45 -0700 | [diff] [blame] | 4697 | EXPECT_EQ(stats.width, info.receivers[0].frame_width); |
| 4698 | EXPECT_EQ(stats.height, info.receivers[0].frame_height); |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 4699 | EXPECT_EQ(rtc::checked_cast<unsigned int>(stats.frame_counts.key_frames + |
| 4700 | stats.frame_counts.delta_frames), |
hbos | 42f6d2f | 2017-01-20 03:56:50 -0800 | [diff] [blame] | 4701 | info.receivers[0].frames_received); |
hbos | 50cfe1f | 2017-01-23 07:21:55 -0800 | [diff] [blame] | 4702 | EXPECT_EQ(stats.frames_rendered, info.receivers[0].frames_rendered); |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 4703 | EXPECT_EQ(stats.frames_decoded, info.receivers[0].frames_decoded); |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 4704 | EXPECT_EQ(stats.qp_sum, info.receivers[0].qp_sum); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 4705 | } |
| 4706 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4707 | TEST_F(WebRtcVideoChannelTest, GetStatsTranslatesReceivePacketStatsCorrectly) { |
Peter Boström | 393347f | 2015-04-22 14:52:45 +0200 | [diff] [blame] | 4708 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 4709 | webrtc::VideoReceiveStream::Stats stats; |
| 4710 | stats.rtp_stats.transmitted.payload_bytes = 2; |
| 4711 | stats.rtp_stats.transmitted.header_bytes = 3; |
| 4712 | stats.rtp_stats.transmitted.padding_bytes = 4; |
| 4713 | stats.rtp_stats.transmitted.packets = 5; |
srte | 186d9c3 | 2017-08-04 05:03:53 -0700 | [diff] [blame] | 4714 | stats.rtcp_stats.packets_lost = 6; |
Peter Boström | 393347f | 2015-04-22 14:52:45 +0200 | [diff] [blame] | 4715 | stats.rtcp_stats.fraction_lost = 7; |
| 4716 | stream->SetStats(stats); |
| 4717 | |
| 4718 | cricket::VideoMediaInfo info; |
| 4719 | ASSERT_TRUE(channel_->GetStats(&info)); |
| 4720 | EXPECT_EQ(stats.rtp_stats.transmitted.payload_bytes + |
| 4721 | stats.rtp_stats.transmitted.header_bytes + |
| 4722 | stats.rtp_stats.transmitted.padding_bytes, |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 4723 | rtc::checked_cast<size_t>(info.receivers[0].bytes_rcvd)); |
Peter Boström | 393347f | 2015-04-22 14:52:45 +0200 | [diff] [blame] | 4724 | EXPECT_EQ(stats.rtp_stats.transmitted.packets, |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 4725 | rtc::checked_cast<unsigned int>(info.receivers[0].packets_rcvd)); |
srte | 186d9c3 | 2017-08-04 05:03:53 -0700 | [diff] [blame] | 4726 | EXPECT_EQ(stats.rtcp_stats.packets_lost, info.receivers[0].packets_lost); |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 4727 | EXPECT_EQ(rtc::checked_cast<float>(stats.rtcp_stats.fraction_lost) / (1 << 8), |
Peter Boström | 393347f | 2015-04-22 14:52:45 +0200 | [diff] [blame] | 4728 | info.receivers[0].fraction_lost); |
| 4729 | } |
| 4730 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4731 | TEST_F(WebRtcVideoChannelTest, TranslatesCallStatsCorrectly) { |
pbos@webrtc.org | 2b19f06 | 2014-12-11 13:26:09 +0000 | [diff] [blame] | 4732 | AddSendStream(); |
| 4733 | AddSendStream(); |
| 4734 | webrtc::Call::Stats stats; |
| 4735 | stats.rtt_ms = 123; |
| 4736 | fake_call_->SetStats(stats); |
| 4737 | |
| 4738 | cricket::VideoMediaInfo info; |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 4739 | ASSERT_TRUE(channel_->GetStats(&info)); |
pbos@webrtc.org | 2b19f06 | 2014-12-11 13:26:09 +0000 | [diff] [blame] | 4740 | ASSERT_EQ(2u, info.senders.size()); |
| 4741 | EXPECT_EQ(stats.rtt_ms, info.senders[0].rtt_ms); |
| 4742 | EXPECT_EQ(stats.rtt_ms, info.senders[1].rtt_ms); |
| 4743 | } |
| 4744 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4745 | TEST_F(WebRtcVideoChannelTest, TranslatesSenderBitrateStatsCorrectly) { |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 4746 | FakeVideoSendStream* stream = AddSendStream(); |
| 4747 | webrtc::VideoSendStream::Stats stats; |
pbos@webrtc.org | 891d483 | 2015-02-26 13:15:22 +0000 | [diff] [blame] | 4748 | stats.target_media_bitrate_bps = 156; |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 4749 | stats.media_bitrate_bps = 123; |
| 4750 | stats.substreams[17].total_bitrate_bps = 1; |
| 4751 | stats.substreams[17].retransmit_bitrate_bps = 2; |
| 4752 | stats.substreams[42].total_bitrate_bps = 3; |
| 4753 | stats.substreams[42].retransmit_bitrate_bps = 4; |
| 4754 | stream->SetStats(stats); |
| 4755 | |
| 4756 | FakeVideoSendStream* stream2 = AddSendStream(); |
| 4757 | webrtc::VideoSendStream::Stats stats2; |
pbos@webrtc.org | 891d483 | 2015-02-26 13:15:22 +0000 | [diff] [blame] | 4758 | stats2.target_media_bitrate_bps = 200; |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 4759 | stats2.media_bitrate_bps = 321; |
| 4760 | stats2.substreams[13].total_bitrate_bps = 5; |
| 4761 | stats2.substreams[13].retransmit_bitrate_bps = 6; |
| 4762 | stats2.substreams[21].total_bitrate_bps = 7; |
| 4763 | stats2.substreams[21].retransmit_bitrate_bps = 8; |
| 4764 | stream2->SetStats(stats2); |
| 4765 | |
| 4766 | cricket::VideoMediaInfo info; |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 4767 | ASSERT_TRUE(channel_->GetStats(&info)); |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 4768 | ASSERT_EQ(2u, info.senders.size()); |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 4769 | BandwidthEstimationInfo bwe_info; |
| 4770 | channel_->FillBitrateInfo(&bwe_info); |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 4771 | // Assuming stream and stream2 corresponds to senders[0] and [1] respectively |
| 4772 | // is OK as std::maps are sorted and AddSendStream() gives increasing SSRCs. |
| 4773 | EXPECT_EQ(stats.media_bitrate_bps, info.senders[0].nominal_bitrate); |
| 4774 | EXPECT_EQ(stats2.media_bitrate_bps, info.senders[1].nominal_bitrate); |
pbos@webrtc.org | 891d483 | 2015-02-26 13:15:22 +0000 | [diff] [blame] | 4775 | EXPECT_EQ(stats.target_media_bitrate_bps + stats2.target_media_bitrate_bps, |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 4776 | bwe_info.target_enc_bitrate); |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 4777 | EXPECT_EQ(stats.media_bitrate_bps + stats2.media_bitrate_bps, |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 4778 | bwe_info.actual_enc_bitrate); |
| 4779 | EXPECT_EQ(1 + 3 + 5 + 7, bwe_info.transmit_bitrate) |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 4780 | << "Bandwidth stats should take all streams into account."; |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 4781 | EXPECT_EQ(2 + 4 + 6 + 8, bwe_info.retransmit_bitrate) |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 4782 | << "Bandwidth stats should take all streams into account."; |
| 4783 | } |
| 4784 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4785 | TEST_F(WebRtcVideoChannelTest, DefaultReceiveStreamReconfiguresToUseRtx) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4786 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | a2a6fe6 | 2015-03-06 15:35:19 +0000 | [diff] [blame] | 4787 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 4788 | const std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs1); |
| 4789 | const std::vector<uint32_t> rtx_ssrcs = MAKE_VECTOR(kRtxSsrcs1); |
pbos@webrtc.org | a2a6fe6 | 2015-03-06 15:35:19 +0000 | [diff] [blame] | 4790 | |
| 4791 | ASSERT_EQ(0u, fake_call_->GetVideoReceiveStreams().size()); |
| 4792 | const size_t kDataLength = 12; |
| 4793 | uint8_t data[kDataLength]; |
| 4794 | memset(data, 0, sizeof(data)); |
| 4795 | rtc::SetBE32(&data[8], ssrcs[0]); |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 4796 | rtc::CopyOnWriteBuffer packet(data, kDataLength); |
pbos@webrtc.org | a2a6fe6 | 2015-03-06 15:35:19 +0000 | [diff] [blame] | 4797 | rtc::PacketTime packet_time; |
| 4798 | channel_->OnPacketReceived(&packet, packet_time); |
| 4799 | |
| 4800 | ASSERT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()) |
| 4801 | << "No default receive stream created."; |
| 4802 | FakeVideoReceiveStream* recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 4803 | EXPECT_EQ(0u, recv_stream->GetConfig().rtp.rtx_ssrc) |
pbos@webrtc.org | a2a6fe6 | 2015-03-06 15:35:19 +0000 | [diff] [blame] | 4804 | << "Default receive stream should not have configured RTX"; |
| 4805 | |
| 4806 | EXPECT_TRUE(channel_->AddRecvStream( |
| 4807 | cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs))); |
| 4808 | ASSERT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()) |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 4809 | << "AddRecvStream should have reconfigured, not added a new receiver."; |
pbos@webrtc.org | a2a6fe6 | 2015-03-06 15:35:19 +0000 | [diff] [blame] | 4810 | recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
nisse | 26e3abb | 2017-08-25 04:44:25 -0700 | [diff] [blame] | 4811 | EXPECT_FALSE( |
| 4812 | recv_stream->GetConfig().rtp.rtx_associated_payload_types.empty()); |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 4813 | EXPECT_TRUE(VerifyRtxReceiveAssociations(recv_stream->GetConfig())) |
Peter Boström | d8b0109 | 2016-05-12 16:44:36 +0200 | [diff] [blame] | 4814 | << "RTX should be mapped for all decoders/payload types."; |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 4815 | EXPECT_TRUE(HasRtxReceiveAssociation(recv_stream->GetConfig(), |
| 4816 | GetEngineCodec("red").id)) |
| 4817 | << "RTX should be mapped also for the RED payload type"; |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 4818 | EXPECT_EQ(rtx_ssrcs[0], recv_stream->GetConfig().rtp.rtx_ssrc); |
pbos@webrtc.org | a2a6fe6 | 2015-03-06 15:35:19 +0000 | [diff] [blame] | 4819 | } |
| 4820 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4821 | TEST_F(WebRtcVideoChannelTest, RejectsAddingStreamsWithMissingSsrcsForRtx) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4822 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Peter Boström | d4362cd | 2015-03-25 14:17:23 +0100 | [diff] [blame] | 4823 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 4824 | const std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs1); |
| 4825 | const std::vector<uint32_t> rtx_ssrcs = MAKE_VECTOR(kRtxSsrcs1); |
Peter Boström | d4362cd | 2015-03-25 14:17:23 +0100 | [diff] [blame] | 4826 | |
| 4827 | StreamParams sp = |
| 4828 | cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs); |
| 4829 | sp.ssrcs = ssrcs; // Without RTXs, this is the important part. |
| 4830 | |
| 4831 | EXPECT_FALSE(channel_->AddSendStream(sp)); |
| 4832 | EXPECT_FALSE(channel_->AddRecvStream(sp)); |
| 4833 | } |
| 4834 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4835 | TEST_F(WebRtcVideoChannelTest, RejectsAddingStreamsWithOverlappingRtxSsrcs) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4836 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 4837 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 4838 | const std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs1); |
| 4839 | const std::vector<uint32_t> rtx_ssrcs = MAKE_VECTOR(kRtxSsrcs1); |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 4840 | |
| 4841 | StreamParams sp = |
| 4842 | cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs); |
| 4843 | |
| 4844 | EXPECT_TRUE(channel_->AddSendStream(sp)); |
| 4845 | EXPECT_TRUE(channel_->AddRecvStream(sp)); |
| 4846 | |
| 4847 | // The RTX SSRC is already used in previous streams, using it should fail. |
| 4848 | sp = cricket::StreamParams::CreateLegacy(rtx_ssrcs[0]); |
| 4849 | EXPECT_FALSE(channel_->AddSendStream(sp)); |
| 4850 | EXPECT_FALSE(channel_->AddRecvStream(sp)); |
| 4851 | |
| 4852 | // After removing the original stream this should be fine to add (makes sure |
| 4853 | // that RTX ssrcs are not forever taken). |
| 4854 | EXPECT_TRUE(channel_->RemoveSendStream(ssrcs[0])); |
| 4855 | EXPECT_TRUE(channel_->RemoveRecvStream(ssrcs[0])); |
| 4856 | EXPECT_TRUE(channel_->AddSendStream(sp)); |
| 4857 | EXPECT_TRUE(channel_->AddRecvStream(sp)); |
| 4858 | } |
| 4859 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4860 | TEST_F(WebRtcVideoChannelTest, |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 4861 | RejectsAddingStreamsWithOverlappingSimulcastSsrcs) { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 4862 | static const uint32_t kFirstStreamSsrcs[] = {1, 2, 3}; |
| 4863 | static const uint32_t kOverlappingStreamSsrcs[] = {4, 3, 5}; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4864 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 4865 | |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 4866 | StreamParams sp = |
| 4867 | cricket::CreateSimStreamParams("cname", MAKE_VECTOR(kFirstStreamSsrcs)); |
| 4868 | |
| 4869 | EXPECT_TRUE(channel_->AddSendStream(sp)); |
| 4870 | EXPECT_TRUE(channel_->AddRecvStream(sp)); |
| 4871 | |
| 4872 | // One of the SSRCs is already used in previous streams, using it should fail. |
| 4873 | sp = cricket::CreateSimStreamParams("cname", |
| 4874 | MAKE_VECTOR(kOverlappingStreamSsrcs)); |
| 4875 | EXPECT_FALSE(channel_->AddSendStream(sp)); |
| 4876 | EXPECT_FALSE(channel_->AddRecvStream(sp)); |
| 4877 | |
| 4878 | // After removing the original stream this should be fine to add (makes sure |
| 4879 | // that RTX ssrcs are not forever taken). |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 4880 | EXPECT_TRUE(channel_->RemoveSendStream(kFirstStreamSsrcs[0])); |
| 4881 | EXPECT_TRUE(channel_->RemoveRecvStream(kFirstStreamSsrcs[0])); |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 4882 | EXPECT_TRUE(channel_->AddSendStream(sp)); |
| 4883 | EXPECT_TRUE(channel_->AddRecvStream(sp)); |
| 4884 | } |
| 4885 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4886 | TEST_F(WebRtcVideoChannelTest, ReportsSsrcGroupsInStats) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4887 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Peter Boström | 259bd20 | 2015-05-28 13:39:50 +0200 | [diff] [blame] | 4888 | |
| 4889 | static const uint32_t kSenderSsrcs[] = {4, 7, 10}; |
| 4890 | static const uint32_t kSenderRtxSsrcs[] = {5, 8, 11}; |
| 4891 | |
| 4892 | StreamParams sender_sp = cricket::CreateSimWithRtxStreamParams( |
| 4893 | "cname", MAKE_VECTOR(kSenderSsrcs), MAKE_VECTOR(kSenderRtxSsrcs)); |
| 4894 | |
| 4895 | EXPECT_TRUE(channel_->AddSendStream(sender_sp)); |
| 4896 | |
| 4897 | static const uint32_t kReceiverSsrcs[] = {3}; |
| 4898 | static const uint32_t kReceiverRtxSsrcs[] = {2}; |
| 4899 | |
| 4900 | StreamParams receiver_sp = cricket::CreateSimWithRtxStreamParams( |
| 4901 | "cname", MAKE_VECTOR(kReceiverSsrcs), MAKE_VECTOR(kReceiverRtxSsrcs)); |
| 4902 | EXPECT_TRUE(channel_->AddRecvStream(receiver_sp)); |
| 4903 | |
| 4904 | cricket::VideoMediaInfo info; |
| 4905 | ASSERT_TRUE(channel_->GetStats(&info)); |
| 4906 | |
| 4907 | ASSERT_EQ(1u, info.senders.size()); |
| 4908 | ASSERT_EQ(1u, info.receivers.size()); |
| 4909 | |
| 4910 | EXPECT_NE(sender_sp.ssrc_groups, receiver_sp.ssrc_groups); |
| 4911 | EXPECT_EQ(sender_sp.ssrc_groups, info.senders[0].ssrc_groups); |
| 4912 | EXPECT_EQ(receiver_sp.ssrc_groups, info.receivers[0].ssrc_groups); |
| 4913 | } |
| 4914 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4915 | TEST_F(WebRtcVideoChannelTest, MapsReceivedPayloadTypeToCodecName) { |
pbos | f42376c | 2015-08-28 07:35:32 -0700 | [diff] [blame] | 4916 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 4917 | webrtc::VideoReceiveStream::Stats stats; |
| 4918 | cricket::VideoMediaInfo info; |
| 4919 | |
| 4920 | // Report no codec name before receiving. |
| 4921 | stream->SetStats(stats); |
| 4922 | ASSERT_TRUE(channel_->GetStats(&info)); |
| 4923 | EXPECT_STREQ("", info.receivers[0].codec_name.c_str()); |
| 4924 | |
| 4925 | // Report VP8 if we're receiving it. |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4926 | stats.current_payload_type = GetEngineCodec("VP8").id; |
pbos | f42376c | 2015-08-28 07:35:32 -0700 | [diff] [blame] | 4927 | stream->SetStats(stats); |
| 4928 | ASSERT_TRUE(channel_->GetStats(&info)); |
| 4929 | EXPECT_STREQ(kVp8CodecName, info.receivers[0].codec_name.c_str()); |
| 4930 | |
| 4931 | // Report no codec name for unknown playload types. |
| 4932 | stats.current_payload_type = 3; |
| 4933 | stream->SetStats(stats); |
| 4934 | ASSERT_TRUE(channel_->GetStats(&info)); |
| 4935 | EXPECT_STREQ("", info.receivers[0].codec_name.c_str()); |
| 4936 | } |
| 4937 | |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 4938 | // Tests that when we add a stream without SSRCs, but contains a stream_id |
| 4939 | // that it is stored and its stream id is later used when the first packet |
| 4940 | // arrives to properly create a receive stream with a sync label. |
| 4941 | TEST_F(WebRtcVideoChannelTest, RecvUnsignaledSsrcWithSignaledStreamId) { |
| 4942 | const char kSyncLabel[] = "sync_label"; |
| 4943 | cricket::StreamParams unsignaled_stream; |
| 4944 | unsignaled_stream.set_stream_ids({kSyncLabel}); |
| 4945 | ASSERT_TRUE(channel_->AddRecvStream(unsignaled_stream)); |
| 4946 | // The stream shouldn't have been created at this point because it doesn't |
| 4947 | // have any SSRCs. |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 4948 | EXPECT_EQ(0u, fake_call_->GetVideoReceiveStreams().size()); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 4949 | |
| 4950 | // Create and deliver packet. |
| 4951 | const size_t kDataLength = 12; |
| 4952 | uint8_t data[kDataLength]; |
| 4953 | memset(data, 0, sizeof(data)); |
| 4954 | rtc::SetBE32(&data[8], kIncomingUnsignalledSsrc); |
| 4955 | rtc::CopyOnWriteBuffer packet(data, kDataLength); |
| 4956 | rtc::PacketTime packet_time; |
| 4957 | channel_->OnPacketReceived(&packet, packet_time); |
| 4958 | |
| 4959 | // The stream should now be created with the appropriate sync label. |
| 4960 | EXPECT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
| 4961 | EXPECT_EQ(kSyncLabel, |
| 4962 | fake_call_->GetVideoReceiveStreams()[0]->GetConfig().sync_group); |
| 4963 | |
| 4964 | // Removing the unsignaled stream should clear the cache. This time when |
| 4965 | // a default video receive stream is created it won't have a sync_group. |
| 4966 | ASSERT_TRUE(channel_->RemoveRecvStream(0)); |
| 4967 | ASSERT_TRUE(channel_->RemoveRecvStream(kIncomingUnsignalledSsrc)); |
| 4968 | EXPECT_EQ(0u, fake_call_->GetVideoReceiveStreams().size()); |
| 4969 | |
| 4970 | channel_->OnPacketReceived(&packet, packet_time); |
| 4971 | EXPECT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
| 4972 | EXPECT_TRUE( |
| 4973 | fake_call_->GetVideoReceiveStreams()[0]->GetConfig().sync_group.empty()); |
| 4974 | } |
| 4975 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4976 | void WebRtcVideoChannelTest::TestReceiveUnsignaledSsrcPacket( |
noahric | d10a68e | 2015-07-10 11:27:55 -0700 | [diff] [blame] | 4977 | uint8_t payload_type, |
| 4978 | bool expect_created_receive_stream) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4979 | // kRedRtxPayloadType must currently be unused. |
| 4980 | EXPECT_FALSE(FindCodecById(engine_.codecs(), kRedRtxPayloadType)); |
| 4981 | |
noahric | d10a68e | 2015-07-10 11:27:55 -0700 | [diff] [blame] | 4982 | // Add a RED RTX codec. |
| 4983 | VideoCodec red_rtx_codec = |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4984 | VideoCodec::CreateRtxCodec(kRedRtxPayloadType, GetEngineCodec("red").id); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4985 | recv_parameters_.codecs.push_back(red_rtx_codec); |
| 4986 | EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
noahric | d10a68e | 2015-07-10 11:27:55 -0700 | [diff] [blame] | 4987 | |
| 4988 | ASSERT_EQ(0u, fake_call_->GetVideoReceiveStreams().size()); |
| 4989 | const size_t kDataLength = 12; |
| 4990 | uint8_t data[kDataLength]; |
| 4991 | memset(data, 0, sizeof(data)); |
| 4992 | |
| 4993 | rtc::Set8(data, 1, payload_type); |
| 4994 | rtc::SetBE32(&data[8], kIncomingUnsignalledSsrc); |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 4995 | rtc::CopyOnWriteBuffer packet(data, kDataLength); |
noahric | d10a68e | 2015-07-10 11:27:55 -0700 | [diff] [blame] | 4996 | rtc::PacketTime packet_time; |
| 4997 | channel_->OnPacketReceived(&packet, packet_time); |
| 4998 | |
| 4999 | if (expect_created_receive_stream) { |
| 5000 | EXPECT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()) |
| 5001 | << "Should have created a receive stream for payload type: " |
| 5002 | << payload_type; |
| 5003 | } else { |
| 5004 | EXPECT_EQ(0u, fake_call_->GetVideoReceiveStreams().size()) |
| 5005 | << "Shouldn't have created a receive stream for payload type: " |
| 5006 | << payload_type; |
| 5007 | } |
| 5008 | } |
| 5009 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5010 | TEST_F(WebRtcVideoChannelTest, Vp8PacketCreatesUnsignalledStream) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5011 | TestReceiveUnsignaledSsrcPacket(GetEngineCodec("VP8").id, |
| 5012 | true /* expect_created_receive_stream */); |
noahric | d10a68e | 2015-07-10 11:27:55 -0700 | [diff] [blame] | 5013 | } |
| 5014 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5015 | TEST_F(WebRtcVideoChannelTest, Vp9PacketCreatesUnsignalledStream) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5016 | TestReceiveUnsignaledSsrcPacket(GetEngineCodec("VP9").id, |
| 5017 | true /* expect_created_receive_stream */); |
noahric | d10a68e | 2015-07-10 11:27:55 -0700 | [diff] [blame] | 5018 | } |
| 5019 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5020 | TEST_F(WebRtcVideoChannelTest, RtxPacketDoesntCreateUnsignalledStream) { |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 5021 | AssignDefaultAptRtxTypes(); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5022 | const cricket::VideoCodec vp8 = GetEngineCodec("VP8"); |
| 5023 | const int rtx_vp8_payload_type = default_apt_rtx_types_[vp8.id]; |
| 5024 | TestReceiveUnsignaledSsrcPacket(rtx_vp8_payload_type, |
| 5025 | false /* expect_created_receive_stream */); |
noahric | d10a68e | 2015-07-10 11:27:55 -0700 | [diff] [blame] | 5026 | } |
| 5027 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5028 | TEST_F(WebRtcVideoChannelTest, UlpfecPacketDoesntCreateUnsignalledStream) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5029 | TestReceiveUnsignaledSsrcPacket(GetEngineCodec("ulpfec").id, |
| 5030 | false /* expect_created_receive_stream */); |
noahric | d10a68e | 2015-07-10 11:27:55 -0700 | [diff] [blame] | 5031 | } |
| 5032 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5033 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 5034 | FlexfecPacketDoesntCreateUnsignalledStream) { |
| 5035 | TestReceiveUnsignaledSsrcPacket(GetEngineCodec("flexfec-03").id, |
| 5036 | false /* expect_created_receive_stream */); |
| 5037 | } |
| 5038 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5039 | TEST_F(WebRtcVideoChannelTest, RedRtxPacketDoesntCreateUnsignalledStream) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5040 | TestReceiveUnsignaledSsrcPacket(kRedRtxPayloadType, |
| 5041 | false /* expect_created_receive_stream */); |
noahric | d10a68e | 2015-07-10 11:27:55 -0700 | [diff] [blame] | 5042 | } |
| 5043 | |
mzanaty | 8a855d6 | 2017-02-17 15:46:43 -0800 | [diff] [blame] | 5044 | // Test that receiving any unsignalled SSRC works even if it changes. |
| 5045 | // The first unsignalled SSRC received will create a default receive stream. |
| 5046 | // Any different unsignalled SSRC received will replace the default. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5047 | TEST_F(WebRtcVideoChannelTest, ReceiveDifferentUnsignaledSsrc) { |
mzanaty | 8a855d6 | 2017-02-17 15:46:43 -0800 | [diff] [blame] | 5048 | // Allow receiving VP8, VP9, H264 (if enabled). |
| 5049 | cricket::VideoRecvParameters parameters; |
| 5050 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 5051 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
| 5052 | |
| 5053 | #if defined(WEBRTC_USE_H264) |
| 5054 | cricket::VideoCodec H264codec(126, "H264"); |
| 5055 | parameters.codecs.push_back(H264codec); |
| 5056 | #endif |
| 5057 | |
| 5058 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
| 5059 | // No receive streams yet. |
| 5060 | ASSERT_EQ(0u, fake_call_->GetVideoReceiveStreams().size()); |
| 5061 | cricket::FakeVideoRenderer renderer; |
| 5062 | EXPECT_TRUE(channel_->SetSink(kDefaultRecvSsrc, &renderer)); |
| 5063 | |
| 5064 | // Receive VP8 packet on first SSRC. |
| 5065 | uint8_t data[kMinRtpPacketLen]; |
| 5066 | cricket::RtpHeader rtpHeader; |
| 5067 | rtpHeader.payload_type = GetEngineCodec("VP8").id; |
| 5068 | rtpHeader.seq_num = rtpHeader.timestamp = 0; |
| 5069 | rtpHeader.ssrc = kIncomingUnsignalledSsrc+1; |
| 5070 | cricket::SetRtpHeader(data, sizeof(data), rtpHeader); |
| 5071 | rtc::CopyOnWriteBuffer packet(data, sizeof(data)); |
| 5072 | rtc::PacketTime packet_time; |
| 5073 | channel_->OnPacketReceived(&packet, packet_time); |
| 5074 | // VP8 packet should create default receive stream. |
| 5075 | ASSERT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
| 5076 | FakeVideoReceiveStream* recv_stream = |
| 5077 | fake_call_->GetVideoReceiveStreams()[0]; |
| 5078 | EXPECT_EQ(rtpHeader.ssrc, recv_stream->GetConfig().rtp.remote_ssrc); |
| 5079 | // Verify that the receive stream sinks to a renderer. |
| 5080 | webrtc::VideoFrame video_frame(CreateBlackFrameBuffer(4, 4), 100, 0, |
| 5081 | webrtc::kVideoRotation_0); |
| 5082 | recv_stream->InjectFrame(video_frame); |
| 5083 | EXPECT_EQ(1, renderer.num_rendered_frames()); |
| 5084 | |
| 5085 | // Receive VP9 packet on second SSRC. |
| 5086 | rtpHeader.payload_type = GetEngineCodec("VP9").id; |
| 5087 | rtpHeader.ssrc = kIncomingUnsignalledSsrc+2; |
| 5088 | cricket::SetRtpHeader(data, sizeof(data), rtpHeader); |
| 5089 | rtc::CopyOnWriteBuffer packet2(data, sizeof(data)); |
| 5090 | channel_->OnPacketReceived(&packet2, packet_time); |
| 5091 | // VP9 packet should replace the default receive SSRC. |
| 5092 | ASSERT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
| 5093 | recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
| 5094 | EXPECT_EQ(rtpHeader.ssrc, recv_stream->GetConfig().rtp.remote_ssrc); |
| 5095 | // Verify that the receive stream sinks to a renderer. |
| 5096 | webrtc::VideoFrame video_frame2(CreateBlackFrameBuffer(4, 4), 200, 0, |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 5097 | webrtc::kVideoRotation_0); |
mzanaty | 8a855d6 | 2017-02-17 15:46:43 -0800 | [diff] [blame] | 5098 | recv_stream->InjectFrame(video_frame2); |
| 5099 | EXPECT_EQ(2, renderer.num_rendered_frames()); |
| 5100 | |
| 5101 | #if defined(WEBRTC_USE_H264) |
| 5102 | // Receive H264 packet on third SSRC. |
| 5103 | rtpHeader.payload_type = 126; |
| 5104 | rtpHeader.ssrc = kIncomingUnsignalledSsrc+3; |
| 5105 | cricket::SetRtpHeader(data, sizeof(data), rtpHeader); |
| 5106 | rtc::CopyOnWriteBuffer packet3(data, sizeof(data)); |
| 5107 | channel_->OnPacketReceived(&packet3, packet_time); |
| 5108 | // H264 packet should replace the default receive SSRC. |
| 5109 | ASSERT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
| 5110 | recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
| 5111 | EXPECT_EQ(rtpHeader.ssrc, recv_stream->GetConfig().rtp.remote_ssrc); |
| 5112 | // Verify that the receive stream sinks to a renderer. |
| 5113 | webrtc::VideoFrame video_frame3(CreateBlackFrameBuffer(4, 4), 300, 0, |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 5114 | webrtc::kVideoRotation_0); |
mzanaty | 8a855d6 | 2017-02-17 15:46:43 -0800 | [diff] [blame] | 5115 | recv_stream->InjectFrame(video_frame3); |
| 5116 | EXPECT_EQ(3, renderer.num_rendered_frames()); |
| 5117 | #endif |
| 5118 | } |
| 5119 | |
brandtr | 0dc57ea | 2017-05-29 23:33:31 -0700 | [diff] [blame] | 5120 | // This test verifies that when a new default stream is created for a new |
| 5121 | // unsignaled SSRC, the new stream does not overwrite any old stream that had |
| 5122 | // been the default receive stream before being properly signaled. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5123 | TEST_F(WebRtcVideoChannelTest, |
brandtr | 0dc57ea | 2017-05-29 23:33:31 -0700 | [diff] [blame] | 5124 | NewUnsignaledStreamDoesNotDestroyPreviouslyUnsignaledStream) { |
| 5125 | cricket::VideoRecvParameters parameters; |
| 5126 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 5127 | ASSERT_TRUE(channel_->SetRecvParameters(parameters)); |
| 5128 | |
| 5129 | // No streams signaled and no packets received, so we should not have any |
| 5130 | // stream objects created yet. |
| 5131 | EXPECT_EQ(0u, fake_call_->GetVideoReceiveStreams().size()); |
| 5132 | |
| 5133 | // Receive packet on an unsignaled SSRC. |
| 5134 | uint8_t data[kMinRtpPacketLen]; |
| 5135 | cricket::RtpHeader rtp_header; |
| 5136 | rtp_header.payload_type = GetEngineCodec("VP8").id; |
| 5137 | rtp_header.seq_num = rtp_header.timestamp = 0; |
| 5138 | rtp_header.ssrc = kSsrcs3[0]; |
| 5139 | cricket::SetRtpHeader(data, sizeof(data), rtp_header); |
| 5140 | rtc::CopyOnWriteBuffer packet(data, sizeof(data)); |
| 5141 | rtc::PacketTime packet_time; |
| 5142 | channel_->OnPacketReceived(&packet, packet_time); |
| 5143 | // Default receive stream should be created. |
| 5144 | ASSERT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
| 5145 | FakeVideoReceiveStream* recv_stream0 = |
| 5146 | fake_call_->GetVideoReceiveStreams()[0]; |
| 5147 | EXPECT_EQ(kSsrcs3[0], recv_stream0->GetConfig().rtp.remote_ssrc); |
| 5148 | |
| 5149 | // Signal the SSRC. |
| 5150 | EXPECT_TRUE( |
| 5151 | channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrcs3[0]))); |
| 5152 | ASSERT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
| 5153 | recv_stream0 = fake_call_->GetVideoReceiveStreams()[0]; |
| 5154 | EXPECT_EQ(kSsrcs3[0], recv_stream0->GetConfig().rtp.remote_ssrc); |
| 5155 | |
| 5156 | // Receive packet on a different unsignaled SSRC. |
| 5157 | rtp_header.ssrc = kSsrcs3[1]; |
| 5158 | cricket::SetRtpHeader(data, sizeof(data), rtp_header); |
| 5159 | packet.SetData(data, sizeof(data)); |
| 5160 | channel_->OnPacketReceived(&packet, packet_time); |
| 5161 | // New default receive stream should be created, but old stream should remain. |
| 5162 | ASSERT_EQ(2u, fake_call_->GetVideoReceiveStreams().size()); |
| 5163 | EXPECT_EQ(recv_stream0, fake_call_->GetVideoReceiveStreams()[0]); |
| 5164 | FakeVideoReceiveStream* recv_stream1 = |
| 5165 | fake_call_->GetVideoReceiveStreams()[1]; |
| 5166 | EXPECT_EQ(kSsrcs3[1], recv_stream1->GetConfig().rtp.remote_ssrc); |
| 5167 | } |
| 5168 | |
Seth Hampson | 7c682e0 | 2018-05-04 16:28:15 -0700 | [diff] [blame] | 5169 | TEST_F(WebRtcVideoChannelTest, CanSetMaxBitrateForExistingStream) { |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5170 | AddSendStream(); |
| 5171 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 5172 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 5173 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, &capturer)); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5174 | cricket::VideoFormat capture_format_hd = |
| 5175 | capturer.GetSupportedFormats()->front(); |
| 5176 | EXPECT_EQ(1280, capture_format_hd.width); |
| 5177 | EXPECT_EQ(720, capture_format_hd.height); |
| 5178 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format_hd)); |
| 5179 | EXPECT_TRUE(channel_->SetSend(true)); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 5180 | capturer.CaptureFrame(); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5181 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 5182 | int default_encoder_bitrate = GetMaxEncoderBitrate(); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 5183 | EXPECT_GT(default_encoder_bitrate, 1000); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5184 | |
| 5185 | // TODO(skvlad): Resolve the inconsistency between the interpretation |
| 5186 | // of the global bitrate limit for audio and video: |
| 5187 | // - Audio: max_bandwidth_bps = 0 - fail the operation, |
| 5188 | // max_bandwidth_bps = -1 - remove the bandwidth limit |
| 5189 | // - Video: max_bandwidth_bps = 0 - remove the bandwidth limit, |
pbos | 5c7760a | 2017-03-10 11:23:12 -0800 | [diff] [blame] | 5190 | // max_bandwidth_bps = -1 - remove the bandwidth limit |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5191 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 5192 | SetAndExpectMaxBitrate(1000, 0, 1000); |
| 5193 | SetAndExpectMaxBitrate(1000, 800, 800); |
| 5194 | SetAndExpectMaxBitrate(600, 800, 600); |
| 5195 | SetAndExpectMaxBitrate(0, 800, 800); |
| 5196 | SetAndExpectMaxBitrate(0, 0, default_encoder_bitrate); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5197 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 5198 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5199 | } |
| 5200 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5201 | TEST_F(WebRtcVideoChannelTest, CannotSetMaxBitrateForNonexistentStream) { |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5202 | webrtc::RtpParameters nonexistent_parameters = |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 5203 | channel_->GetRtpSendParameters(last_ssrc_); |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 5204 | EXPECT_EQ(0u, nonexistent_parameters.encodings.size()); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5205 | |
| 5206 | nonexistent_parameters.encodings.push_back(webrtc::RtpEncodingParameters()); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 5207 | EXPECT_FALSE( |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5208 | channel_->SetRtpSendParameters(last_ssrc_, nonexistent_parameters).ok()); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5209 | } |
| 5210 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5211 | TEST_F(WebRtcVideoChannelTest, |
Seth Hampson | 7c682e0 | 2018-05-04 16:28:15 -0700 | [diff] [blame] | 5212 | SetLowMaxBitrateOverwritesVideoStreamMinBitrate) { |
| 5213 | AddSendStream(); |
| 5214 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5215 | EXPECT_EQ(1UL, parameters.encodings.size()); |
| 5216 | EXPECT_FALSE(parameters.encodings[0].max_bitrate_bps.has_value()); |
| 5217 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 5218 | |
| 5219 | // Note that this is testing the behavior of the FakeVideoSendStream, which |
| 5220 | // also calls to CreateEncoderStreams to get the VideoStreams, so essentially |
| 5221 | // we are just testing the behavior of |
| 5222 | // EncoderStreamFactory::CreateEncoderStreams. |
| 5223 | std::vector<webrtc::VideoStream> video_streams = |
| 5224 | fake_call_->GetVideoSendStreams().front()->GetVideoStreams(); |
| 5225 | ASSERT_EQ(1UL, video_streams.size()); |
| 5226 | EXPECT_EQ(kMinVideoBitrateBps, video_streams[0].min_bitrate_bps); |
| 5227 | |
| 5228 | // Set a low max bitrate & check that VideoStream.min_bitrate_bps is limited |
| 5229 | // by this amount. |
| 5230 | parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5231 | int low_max_bitrate_bps = kMinVideoBitrateBps - 1000; |
| 5232 | parameters.encodings[0].max_bitrate_bps = low_max_bitrate_bps; |
| 5233 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 5234 | |
| 5235 | video_streams = fake_call_->GetVideoSendStreams().front()->GetVideoStreams(); |
| 5236 | ASSERT_EQ(1UL, video_streams.size()); |
| 5237 | EXPECT_GE(low_max_bitrate_bps, video_streams[0].min_bitrate_bps); |
| 5238 | } |
| 5239 | |
| 5240 | TEST_F(WebRtcVideoChannelTest, |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 5241 | CannotSetRtpSendParametersWithIncorrectNumberOfEncodings) { |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5242 | AddSendStream(); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 5243 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5244 | // Two or more encodings should result in failure. |
| 5245 | parameters.encodings.push_back(webrtc::RtpEncodingParameters()); |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5246 | EXPECT_FALSE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
deadbeef | fb2aced | 2017-01-06 23:05:37 -0800 | [diff] [blame] | 5247 | // Zero encodings should also fail. |
| 5248 | parameters.encodings.clear(); |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5249 | EXPECT_FALSE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
deadbeef | fb2aced | 2017-01-06 23:05:37 -0800 | [diff] [blame] | 5250 | } |
| 5251 | |
Zach Stein | 3ca452b | 2018-01-18 10:01:24 -0800 | [diff] [blame] | 5252 | TEST_F(WebRtcVideoChannelTest, |
| 5253 | CannotSetSimulcastRtpSendParametersWithIncorrectNumberOfEncodings) { |
| 5254 | std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); |
| 5255 | StreamParams sp = CreateSimStreamParams("cname", ssrcs); |
| 5256 | AddSendStream(sp); |
| 5257 | |
| 5258 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5259 | |
| 5260 | // Additional encodings should result in failure. |
| 5261 | parameters.encodings.push_back(webrtc::RtpEncodingParameters()); |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5262 | EXPECT_FALSE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
Zach Stein | 3ca452b | 2018-01-18 10:01:24 -0800 | [diff] [blame] | 5263 | // Zero encodings should also fail. |
| 5264 | parameters.encodings.clear(); |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5265 | EXPECT_FALSE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
Zach Stein | 3ca452b | 2018-01-18 10:01:24 -0800 | [diff] [blame] | 5266 | } |
| 5267 | |
deadbeef | fb2aced | 2017-01-06 23:05:37 -0800 | [diff] [blame] | 5268 | // Changing the SSRC through RtpParameters is not allowed. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5269 | TEST_F(WebRtcVideoChannelTest, CannotSetSsrcInRtpSendParameters) { |
deadbeef | fb2aced | 2017-01-06 23:05:37 -0800 | [diff] [blame] | 5270 | AddSendStream(); |
| 5271 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 5272 | parameters.encodings[0].ssrc = 0xdeadbeef; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5273 | EXPECT_FALSE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5274 | } |
| 5275 | |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5276 | // Tests that when RTCRtpEncodingParameters.bitrate_priority gets set to |
| 5277 | // a value <= 0, setting the parameters returns false. |
| 5278 | TEST_F(WebRtcVideoChannelTest, SetRtpSendParametersInvalidBitratePriority) { |
| 5279 | AddSendStream(); |
| 5280 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5281 | EXPECT_EQ(1UL, parameters.encodings.size()); |
| 5282 | EXPECT_EQ(webrtc::kDefaultBitratePriority, |
| 5283 | parameters.encodings[0].bitrate_priority); |
| 5284 | |
| 5285 | parameters.encodings[0].bitrate_priority = 0; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5286 | EXPECT_FALSE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5287 | parameters.encodings[0].bitrate_priority = -2; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5288 | EXPECT_FALSE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5289 | } |
| 5290 | |
| 5291 | // Tests when the the RTCRtpEncodingParameters.bitrate_priority gets set |
| 5292 | // properly on the VideoChannel and propogates down to the video encoder. |
| 5293 | TEST_F(WebRtcVideoChannelTest, SetRtpSendParametersPriorityOneStream) { |
| 5294 | AddSendStream(); |
| 5295 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5296 | EXPECT_EQ(1UL, parameters.encodings.size()); |
| 5297 | EXPECT_EQ(webrtc::kDefaultBitratePriority, |
| 5298 | parameters.encodings[0].bitrate_priority); |
| 5299 | |
| 5300 | // Change the value and set it on the VideoChannel. |
| 5301 | double new_bitrate_priority = 2.0; |
| 5302 | parameters.encodings[0].bitrate_priority = new_bitrate_priority; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5303 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5304 | |
| 5305 | // Verify that the encoding parameters bitrate_priority is set for the |
| 5306 | // VideoChannel. |
| 5307 | parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5308 | EXPECT_EQ(1UL, parameters.encodings.size()); |
| 5309 | EXPECT_EQ(new_bitrate_priority, parameters.encodings[0].bitrate_priority); |
| 5310 | |
| 5311 | // Verify that the new value propagated down to the encoder. |
| 5312 | std::vector<FakeVideoSendStream*> video_send_streams = |
| 5313 | fake_call_->GetVideoSendStreams(); |
| 5314 | EXPECT_EQ(1UL, video_send_streams.size()); |
| 5315 | FakeVideoSendStream* video_send_stream = video_send_streams.front(); |
| 5316 | // Check that the WebRtcVideoSendStream updated the VideoEncoderConfig |
| 5317 | // appropriately. |
| 5318 | EXPECT_EQ(new_bitrate_priority, |
| 5319 | video_send_stream->GetEncoderConfig().bitrate_priority); |
| 5320 | // Check that the vector of VideoStreams also was propagated correctly. Note |
| 5321 | // that this is testing the behavior of the FakeVideoSendStream, which mimics |
| 5322 | // the calls to CreateEncoderStreams to get the VideoStreams. |
| 5323 | EXPECT_EQ(rtc::Optional<double>(new_bitrate_priority), |
| 5324 | video_send_stream->GetVideoStreams()[0].bitrate_priority); |
| 5325 | } |
| 5326 | |
| 5327 | // Tests that the RTCRtpEncodingParameters.bitrate_priority is set for the |
| 5328 | // VideoChannel and the value propogates to the video encoder with all simulcast |
| 5329 | // streams. |
| 5330 | TEST_F(WebRtcVideoChannelTest, SetRtpSendParametersPrioritySimulcastStreams) { |
| 5331 | // Create the stream params with multiple ssrcs for simulcast. |
| 5332 | const int kNumSimulcastStreams = 3; |
| 5333 | std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); |
| 5334 | StreamParams stream_params = CreateSimStreamParams("cname", ssrcs); |
| 5335 | AddSendStream(stream_params); |
| 5336 | uint32_t primary_ssrc = stream_params.first_ssrc(); |
| 5337 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 5338 | // Using the FakeVideoCapturerWithTaskQueue, we manually send a full size |
| 5339 | // frame. This creates multiple VideoStreams for all simulcast layers when |
| 5340 | // reconfiguring, and allows us to test this behavior. |
| 5341 | FakeVideoCapturerWithTaskQueue capturer; |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5342 | VideoOptions options; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 5343 | EXPECT_TRUE(channel_->SetVideoSend(primary_ssrc, &options, &capturer)); |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5344 | EXPECT_EQ(cricket::CS_RUNNING, |
| 5345 | capturer.Start(cricket::VideoFormat( |
| 5346 | 1920, 1080, cricket::VideoFormat::FpsToInterval(30), |
| 5347 | cricket::FOURCC_I420))); |
| 5348 | channel_->SetSend(true); |
| 5349 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 5350 | // Get and set the rtp encoding parameters. |
| 5351 | webrtc::RtpParameters parameters = |
| 5352 | channel_->GetRtpSendParameters(primary_ssrc); |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 5353 | EXPECT_EQ(rtc::checked_cast<size_t>(kNumSimulcastStreams), |
| 5354 | parameters.encodings.size()); |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5355 | EXPECT_EQ(webrtc::kDefaultBitratePriority, |
| 5356 | parameters.encodings[0].bitrate_priority); |
| 5357 | // Change the value and set it on the VideoChannel. |
| 5358 | double new_bitrate_priority = 2.0; |
| 5359 | parameters.encodings[0].bitrate_priority = new_bitrate_priority; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5360 | EXPECT_TRUE(channel_->SetRtpSendParameters(primary_ssrc, parameters).ok()); |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5361 | |
| 5362 | // Verify that the encoding parameters priority is set on the VideoChannel. |
| 5363 | parameters = channel_->GetRtpSendParameters(primary_ssrc); |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 5364 | EXPECT_EQ(rtc::checked_cast<size_t>(kNumSimulcastStreams), |
| 5365 | parameters.encodings.size()); |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5366 | EXPECT_EQ(new_bitrate_priority, parameters.encodings[0].bitrate_priority); |
| 5367 | |
| 5368 | // Verify that the new value propagated down to the encoder. |
| 5369 | std::vector<FakeVideoSendStream*> video_send_streams = |
| 5370 | fake_call_->GetVideoSendStreams(); |
| 5371 | EXPECT_EQ(1UL, video_send_streams.size()); |
| 5372 | FakeVideoSendStream* video_send_stream = video_send_streams.front(); |
| 5373 | // Check that the WebRtcVideoSendStream updated the VideoEncoderConfig |
| 5374 | // appropriately. |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 5375 | EXPECT_EQ(rtc::checked_cast<size_t>(kNumSimulcastStreams), |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5376 | video_send_stream->GetEncoderConfig().number_of_streams); |
| 5377 | EXPECT_EQ(new_bitrate_priority, |
| 5378 | video_send_stream->GetEncoderConfig().bitrate_priority); |
| 5379 | // Check that the vector of VideoStreams also propagated correctly. The |
| 5380 | // FakeVideoSendStream calls CreateEncoderStreams, and we are testing that |
| 5381 | // these are created appropriately for the simulcast case. |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 5382 | EXPECT_EQ(rtc::checked_cast<size_t>(kNumSimulcastStreams), |
| 5383 | video_send_stream->GetVideoStreams().size()); |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5384 | EXPECT_EQ(rtc::Optional<double>(new_bitrate_priority), |
| 5385 | video_send_stream->GetVideoStreams()[0].bitrate_priority); |
| 5386 | // Since we are only setting bitrate priority per-sender, the other |
| 5387 | // VideoStreams should have a bitrate priority of 0. |
| 5388 | EXPECT_EQ(rtc::nullopt, |
| 5389 | video_send_stream->GetVideoStreams()[1].bitrate_priority); |
| 5390 | EXPECT_EQ(rtc::nullopt, |
| 5391 | video_send_stream->GetVideoStreams()[2].bitrate_priority); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 5392 | EXPECT_TRUE(channel_->SetVideoSend(primary_ssrc, nullptr, nullptr)); |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5393 | } |
| 5394 | |
Taylor Brandstetter | 14b9d79 | 2016-09-07 17:16:54 -0700 | [diff] [blame] | 5395 | // Test that a stream will not be sending if its encoding is made inactive |
| 5396 | // through SetRtpSendParameters. |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 5397 | TEST_F(WebRtcVideoChannelTest, SetRtpSendParametersOneEncodingActive) { |
deadbeef | dbe2b87 | 2016-03-22 15:42:00 -0700 | [diff] [blame] | 5398 | FakeVideoSendStream* stream = AddSendStream(); |
| 5399 | EXPECT_TRUE(channel_->SetSend(true)); |
| 5400 | EXPECT_TRUE(stream->IsSending()); |
| 5401 | |
| 5402 | // Get current parameters and change "active" to false. |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 5403 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
deadbeef | dbe2b87 | 2016-03-22 15:42:00 -0700 | [diff] [blame] | 5404 | ASSERT_EQ(1u, parameters.encodings.size()); |
| 5405 | ASSERT_TRUE(parameters.encodings[0].active); |
| 5406 | parameters.encodings[0].active = false; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5407 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
deadbeef | dbe2b87 | 2016-03-22 15:42:00 -0700 | [diff] [blame] | 5408 | EXPECT_FALSE(stream->IsSending()); |
| 5409 | |
| 5410 | // Now change it back to active and verify we resume sending. |
| 5411 | parameters.encodings[0].active = true; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5412 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
deadbeef | dbe2b87 | 2016-03-22 15:42:00 -0700 | [diff] [blame] | 5413 | EXPECT_TRUE(stream->IsSending()); |
| 5414 | } |
| 5415 | |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 5416 | // Tests that when active is updated for any simulcast layer then the send |
| 5417 | // stream's sending state will be updated and it will be reconfigured with the |
| 5418 | // new appropriate active simulcast streams. |
| 5419 | TEST_F(WebRtcVideoChannelTest, SetRtpSendParametersMultipleEncodingsActive) { |
| 5420 | // Create the stream params with multiple ssrcs for simulcast. |
| 5421 | const int kNumSimulcastStreams = 3; |
| 5422 | std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); |
| 5423 | StreamParams stream_params = CreateSimStreamParams("cname", ssrcs); |
| 5424 | FakeVideoSendStream* fake_video_send_stream = AddSendStream(stream_params); |
| 5425 | uint32_t primary_ssrc = stream_params.first_ssrc(); |
| 5426 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 5427 | // Using the FakeVideoCapturerWithTaskQueue, we manually send a full size |
| 5428 | // frame. This allows us to test that ReconfigureEncoder is called |
| 5429 | // appropriately. |
| 5430 | cricket::FakeVideoCapturerWithTaskQueue capturer; |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 5431 | VideoOptions options; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 5432 | EXPECT_TRUE(channel_->SetVideoSend(primary_ssrc, &options, &capturer)); |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 5433 | EXPECT_EQ(cricket::CS_RUNNING, |
| 5434 | capturer.Start(cricket::VideoFormat( |
| 5435 | 1920, 1080, cricket::VideoFormat::FpsToInterval(30), |
| 5436 | cricket::FOURCC_I420))); |
| 5437 | channel_->SetSend(true); |
| 5438 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 5439 | |
| 5440 | // Check that all encodings are initially active. |
| 5441 | webrtc::RtpParameters parameters = |
| 5442 | channel_->GetRtpSendParameters(primary_ssrc); |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 5443 | EXPECT_EQ(rtc::checked_cast<size_t>(kNumSimulcastStreams), |
| 5444 | parameters.encodings.size()); |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 5445 | EXPECT_TRUE(parameters.encodings[0].active); |
| 5446 | EXPECT_TRUE(parameters.encodings[1].active); |
| 5447 | EXPECT_TRUE(parameters.encodings[2].active); |
| 5448 | EXPECT_TRUE(fake_video_send_stream->IsSending()); |
| 5449 | |
| 5450 | // Only turn on only the middle stream. |
| 5451 | parameters.encodings[0].active = false; |
| 5452 | parameters.encodings[1].active = true; |
| 5453 | parameters.encodings[2].active = false; |
| 5454 | EXPECT_TRUE(channel_->SetRtpSendParameters(primary_ssrc, parameters).ok()); |
| 5455 | // Verify that the active fields are set on the VideoChannel. |
| 5456 | parameters = channel_->GetRtpSendParameters(primary_ssrc); |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 5457 | EXPECT_EQ(rtc::checked_cast<size_t>(kNumSimulcastStreams), |
| 5458 | parameters.encodings.size()); |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 5459 | EXPECT_FALSE(parameters.encodings[0].active); |
| 5460 | EXPECT_TRUE(parameters.encodings[1].active); |
| 5461 | EXPECT_FALSE(parameters.encodings[2].active); |
| 5462 | // Check that the VideoSendStream is updated appropriately. This means its |
| 5463 | // send state was updated and it was reconfigured. |
| 5464 | EXPECT_TRUE(fake_video_send_stream->IsSending()); |
| 5465 | std::vector<webrtc::VideoStream> simulcast_streams = |
| 5466 | fake_video_send_stream->GetVideoStreams(); |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 5467 | EXPECT_EQ(rtc::checked_cast<size_t>(kNumSimulcastStreams), |
| 5468 | simulcast_streams.size()); |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 5469 | EXPECT_FALSE(simulcast_streams[0].active); |
| 5470 | EXPECT_TRUE(simulcast_streams[1].active); |
| 5471 | EXPECT_FALSE(simulcast_streams[2].active); |
| 5472 | |
| 5473 | // Turn off all streams. |
| 5474 | parameters.encodings[0].active = false; |
| 5475 | parameters.encodings[1].active = false; |
| 5476 | parameters.encodings[2].active = false; |
| 5477 | EXPECT_TRUE(channel_->SetRtpSendParameters(primary_ssrc, parameters).ok()); |
| 5478 | // Verify that the active fields are set on the VideoChannel. |
| 5479 | parameters = channel_->GetRtpSendParameters(primary_ssrc); |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 5480 | EXPECT_EQ(rtc::checked_cast<size_t>(kNumSimulcastStreams), |
| 5481 | parameters.encodings.size()); |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 5482 | EXPECT_FALSE(parameters.encodings[0].active); |
| 5483 | EXPECT_FALSE(parameters.encodings[1].active); |
| 5484 | EXPECT_FALSE(parameters.encodings[2].active); |
| 5485 | // Check that the VideoSendStream is off. |
| 5486 | EXPECT_FALSE(fake_video_send_stream->IsSending()); |
| 5487 | simulcast_streams = fake_video_send_stream->GetVideoStreams(); |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 5488 | EXPECT_EQ(rtc::checked_cast<size_t>(kNumSimulcastStreams), |
| 5489 | simulcast_streams.size()); |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 5490 | EXPECT_FALSE(simulcast_streams[0].active); |
| 5491 | EXPECT_FALSE(simulcast_streams[1].active); |
| 5492 | EXPECT_FALSE(simulcast_streams[2].active); |
| 5493 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 5494 | EXPECT_TRUE(channel_->SetVideoSend(primary_ssrc, nullptr, nullptr)); |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 5495 | } |
| 5496 | |
Taylor Brandstetter | 14b9d79 | 2016-09-07 17:16:54 -0700 | [diff] [blame] | 5497 | // Test that if a stream is reconfigured (due to a codec change or other |
| 5498 | // change) while its encoding is still inactive, it doesn't start sending. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5499 | TEST_F(WebRtcVideoChannelTest, |
Taylor Brandstetter | 14b9d79 | 2016-09-07 17:16:54 -0700 | [diff] [blame] | 5500 | InactiveStreamDoesntStartSendingWhenReconfigured) { |
| 5501 | // Set an initial codec list, which will be modified later. |
| 5502 | cricket::VideoSendParameters parameters1; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5503 | parameters1.codecs.push_back(GetEngineCodec("VP8")); |
| 5504 | parameters1.codecs.push_back(GetEngineCodec("VP9")); |
Taylor Brandstetter | 14b9d79 | 2016-09-07 17:16:54 -0700 | [diff] [blame] | 5505 | EXPECT_TRUE(channel_->SetSendParameters(parameters1)); |
| 5506 | |
| 5507 | FakeVideoSendStream* stream = AddSendStream(); |
| 5508 | EXPECT_TRUE(channel_->SetSend(true)); |
| 5509 | EXPECT_TRUE(stream->IsSending()); |
| 5510 | |
| 5511 | // Get current parameters and change "active" to false. |
| 5512 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5513 | ASSERT_EQ(1u, parameters.encodings.size()); |
| 5514 | ASSERT_TRUE(parameters.encodings[0].active); |
| 5515 | parameters.encodings[0].active = false; |
| 5516 | EXPECT_EQ(1u, GetFakeSendStreams().size()); |
| 5517 | EXPECT_EQ(1, fake_call_->GetNumCreatedSendStreams()); |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5518 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
Taylor Brandstetter | 14b9d79 | 2016-09-07 17:16:54 -0700 | [diff] [blame] | 5519 | EXPECT_FALSE(stream->IsSending()); |
| 5520 | |
| 5521 | // Reorder the codec list, causing the stream to be reconfigured. |
| 5522 | cricket::VideoSendParameters parameters2; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5523 | parameters2.codecs.push_back(GetEngineCodec("VP9")); |
| 5524 | parameters2.codecs.push_back(GetEngineCodec("VP8")); |
Taylor Brandstetter | 14b9d79 | 2016-09-07 17:16:54 -0700 | [diff] [blame] | 5525 | EXPECT_TRUE(channel_->SetSendParameters(parameters2)); |
| 5526 | auto new_streams = GetFakeSendStreams(); |
| 5527 | // Assert that a new underlying stream was created due to the codec change. |
| 5528 | // Otherwise, this test isn't testing what it set out to test. |
| 5529 | EXPECT_EQ(1u, GetFakeSendStreams().size()); |
| 5530 | EXPECT_EQ(2, fake_call_->GetNumCreatedSendStreams()); |
| 5531 | |
| 5532 | // Verify that we still are not sending anything, due to the inactive |
| 5533 | // encoding. |
| 5534 | EXPECT_FALSE(new_streams[0]->IsSending()); |
| 5535 | } |
| 5536 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 5537 | // Test that GetRtpSendParameters returns the currently configured codecs. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5538 | TEST_F(WebRtcVideoChannelTest, GetRtpSendParametersCodecs) { |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 5539 | AddSendStream(); |
| 5540 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5541 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 5542 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 5543 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 5544 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 5545 | webrtc::RtpParameters rtp_parameters = |
| 5546 | channel_->GetRtpSendParameters(last_ssrc_); |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 5547 | ASSERT_EQ(2u, rtp_parameters.codecs.size()); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5548 | EXPECT_EQ(GetEngineCodec("VP8").ToCodecParameters(), |
| 5549 | rtp_parameters.codecs[0]); |
| 5550 | EXPECT_EQ(GetEngineCodec("VP9").ToCodecParameters(), |
| 5551 | rtp_parameters.codecs[1]); |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 5552 | } |
| 5553 | |
Florent Castelli | dacec71 | 2018-05-24 16:24:21 +0200 | [diff] [blame] | 5554 | // Test that GetRtpSendParameters returns the currently configured RTCP CNAME. |
| 5555 | TEST_F(WebRtcVideoChannelTest, GetRtpSendParametersRtcpCname) { |
| 5556 | StreamParams params = StreamParams::CreateLegacy(kSsrc); |
| 5557 | params.cname = "rtcpcname"; |
| 5558 | AddSendStream(params); |
| 5559 | |
| 5560 | webrtc::RtpParameters rtp_parameters = channel_->GetRtpSendParameters(kSsrc); |
| 5561 | EXPECT_STREQ("rtcpcname", rtp_parameters.rtcp.cname.c_str()); |
| 5562 | } |
| 5563 | |
deadbeef | fb2aced | 2017-01-06 23:05:37 -0800 | [diff] [blame] | 5564 | // Test that RtpParameters for send stream has one encoding and it has |
| 5565 | // the correct SSRC. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5566 | TEST_F(WebRtcVideoChannelTest, GetRtpSendParametersSsrc) { |
deadbeef | fb2aced | 2017-01-06 23:05:37 -0800 | [diff] [blame] | 5567 | AddSendStream(); |
| 5568 | |
| 5569 | webrtc::RtpParameters rtp_parameters = |
| 5570 | channel_->GetRtpSendParameters(last_ssrc_); |
| 5571 | ASSERT_EQ(1u, rtp_parameters.encodings.size()); |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 5572 | EXPECT_EQ(last_ssrc_, rtp_parameters.encodings[0].ssrc); |
deadbeef | fb2aced | 2017-01-06 23:05:37 -0800 | [diff] [blame] | 5573 | } |
| 5574 | |
Florent Castelli | abe301f | 2018-06-12 18:33:49 +0200 | [diff] [blame^] | 5575 | TEST_F(WebRtcVideoChannelTest, DetectRtpSendParameterHeaderExtensionsChange) { |
| 5576 | AddSendStream(); |
| 5577 | |
| 5578 | webrtc::RtpParameters rtp_parameters = |
| 5579 | channel_->GetRtpSendParameters(last_ssrc_); |
| 5580 | rtp_parameters.header_extensions.emplace_back(); |
| 5581 | |
| 5582 | EXPECT_NE(0u, rtp_parameters.header_extensions.size()); |
| 5583 | |
| 5584 | webrtc::RTCError result = |
| 5585 | channel_->SetRtpSendParameters(last_ssrc_, rtp_parameters); |
| 5586 | EXPECT_EQ(webrtc::RTCErrorType::INVALID_MODIFICATION, result.type()); |
| 5587 | } |
| 5588 | |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 5589 | // Test that if we set/get parameters multiple times, we get the same results. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5590 | TEST_F(WebRtcVideoChannelTest, SetAndGetRtpSendParameters) { |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 5591 | AddSendStream(); |
| 5592 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5593 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 5594 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 5595 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 5596 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 5597 | webrtc::RtpParameters initial_params = |
| 5598 | channel_->GetRtpSendParameters(last_ssrc_); |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 5599 | |
| 5600 | // We should be able to set the params we just got. |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5601 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, initial_params).ok()); |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 5602 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 5603 | // ... And this shouldn't change the params returned by GetRtpSendParameters. |
| 5604 | EXPECT_EQ(initial_params, channel_->GetRtpSendParameters(last_ssrc_)); |
| 5605 | } |
| 5606 | |
| 5607 | // Test that GetRtpReceiveParameters returns the currently configured codecs. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5608 | TEST_F(WebRtcVideoChannelTest, GetRtpReceiveParametersCodecs) { |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 5609 | AddRecvStream(); |
| 5610 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5611 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 5612 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 5613 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
| 5614 | |
| 5615 | webrtc::RtpParameters rtp_parameters = |
| 5616 | channel_->GetRtpReceiveParameters(last_ssrc_); |
| 5617 | ASSERT_EQ(2u, rtp_parameters.codecs.size()); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5618 | EXPECT_EQ(GetEngineCodec("VP8").ToCodecParameters(), |
| 5619 | rtp_parameters.codecs[0]); |
| 5620 | EXPECT_EQ(GetEngineCodec("VP9").ToCodecParameters(), |
| 5621 | rtp_parameters.codecs[1]); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 5622 | } |
| 5623 | |
johan | 073ece4 | 2016-08-26 02:59:47 -0700 | [diff] [blame] | 5624 | #if defined(WEBRTC_USE_H264) |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5625 | TEST_F(WebRtcVideoChannelTest, GetRtpReceiveFmtpSprop) { |
johan | 073ece4 | 2016-08-26 02:59:47 -0700 | [diff] [blame] | 5626 | #else |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5627 | TEST_F(WebRtcVideoChannelTest, DISABLED_GetRtpReceiveFmtpSprop) { |
johan | 073ece4 | 2016-08-26 02:59:47 -0700 | [diff] [blame] | 5628 | #endif |
johan | 3859c89 | 2016-08-05 09:19:25 -0700 | [diff] [blame] | 5629 | cricket::VideoRecvParameters parameters; |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 5630 | cricket::VideoCodec kH264sprop1(101, "H264"); |
magjed | 5dfac56 | 2016-11-25 03:56:37 -0800 | [diff] [blame] | 5631 | kH264sprop1.SetParam(kH264FmtpSpropParameterSets, "uvw"); |
johan | 3859c89 | 2016-08-05 09:19:25 -0700 | [diff] [blame] | 5632 | parameters.codecs.push_back(kH264sprop1); |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 5633 | cricket::VideoCodec kH264sprop2(102, "H264"); |
magjed | 5dfac56 | 2016-11-25 03:56:37 -0800 | [diff] [blame] | 5634 | kH264sprop2.SetParam(kH264FmtpSpropParameterSets, "xyz"); |
johan | 3859c89 | 2016-08-05 09:19:25 -0700 | [diff] [blame] | 5635 | parameters.codecs.push_back(kH264sprop2); |
| 5636 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
| 5637 | |
| 5638 | FakeVideoReceiveStream* recv_stream = AddRecvStream(); |
| 5639 | const webrtc::VideoReceiveStream::Config& cfg = recv_stream->GetConfig(); |
| 5640 | webrtc::RtpParameters rtp_parameters = |
| 5641 | channel_->GetRtpReceiveParameters(last_ssrc_); |
| 5642 | ASSERT_EQ(2u, rtp_parameters.codecs.size()); |
| 5643 | EXPECT_EQ(kH264sprop1.ToCodecParameters(), rtp_parameters.codecs[0]); |
| 5644 | ASSERT_EQ(2u, cfg.decoders.size()); |
| 5645 | EXPECT_EQ(101, cfg.decoders[0].payload_type); |
| 5646 | EXPECT_EQ("H264", cfg.decoders[0].payload_name); |
magjed | 5dfac56 | 2016-11-25 03:56:37 -0800 | [diff] [blame] | 5647 | const auto it0 = |
| 5648 | cfg.decoders[0].codec_params.find(kH264FmtpSpropParameterSets); |
| 5649 | ASSERT_TRUE(it0 != cfg.decoders[0].codec_params.end()); |
| 5650 | EXPECT_EQ("uvw", it0->second); |
johan | 3859c89 | 2016-08-05 09:19:25 -0700 | [diff] [blame] | 5651 | |
| 5652 | EXPECT_EQ(102, cfg.decoders[1].payload_type); |
| 5653 | EXPECT_EQ("H264", cfg.decoders[1].payload_name); |
magjed | 5dfac56 | 2016-11-25 03:56:37 -0800 | [diff] [blame] | 5654 | const auto it1 = |
| 5655 | cfg.decoders[1].codec_params.find(kH264FmtpSpropParameterSets); |
| 5656 | ASSERT_TRUE(it1 != cfg.decoders[1].codec_params.end()); |
| 5657 | EXPECT_EQ("xyz", it1->second); |
johan | 3859c89 | 2016-08-05 09:19:25 -0700 | [diff] [blame] | 5658 | } |
| 5659 | |
sakal | 1fd9595 | 2016-06-22 00:46:15 -0700 | [diff] [blame] | 5660 | // Test that RtpParameters for receive stream has one encoding and it has |
| 5661 | // the correct SSRC. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5662 | TEST_F(WebRtcVideoChannelTest, GetRtpReceiveParametersSsrc) { |
sakal | 1fd9595 | 2016-06-22 00:46:15 -0700 | [diff] [blame] | 5663 | AddRecvStream(); |
| 5664 | |
| 5665 | webrtc::RtpParameters rtp_parameters = |
| 5666 | channel_->GetRtpReceiveParameters(last_ssrc_); |
| 5667 | ASSERT_EQ(1u, rtp_parameters.encodings.size()); |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 5668 | EXPECT_EQ(last_ssrc_, rtp_parameters.encodings[0].ssrc); |
sakal | 1fd9595 | 2016-06-22 00:46:15 -0700 | [diff] [blame] | 5669 | } |
| 5670 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 5671 | // Test that if we set/get parameters multiple times, we get the same results. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5672 | TEST_F(WebRtcVideoChannelTest, SetAndGetRtpReceiveParameters) { |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 5673 | AddRecvStream(); |
| 5674 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5675 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 5676 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 5677 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
| 5678 | |
| 5679 | webrtc::RtpParameters initial_params = |
| 5680 | channel_->GetRtpReceiveParameters(last_ssrc_); |
| 5681 | |
| 5682 | // We should be able to set the params we just got. |
| 5683 | EXPECT_TRUE(channel_->SetRtpReceiveParameters(last_ssrc_, initial_params)); |
| 5684 | |
| 5685 | // ... And this shouldn't change the params returned by |
| 5686 | // GetRtpReceiveParameters. |
| 5687 | EXPECT_EQ(initial_params, channel_->GetRtpReceiveParameters(last_ssrc_)); |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 5688 | } |
| 5689 | |
deadbeef | 3bc1510 | 2017-04-20 19:25:07 -0700 | [diff] [blame] | 5690 | // Test that GetRtpReceiveParameters returns parameters correctly when SSRCs |
| 5691 | // aren't signaled. It should always return an empty "RtpEncodingParameters", |
| 5692 | // even after a packet is received and the unsignaled SSRC is known. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5693 | TEST_F(WebRtcVideoChannelTest, GetRtpReceiveParametersWithUnsignaledSsrc) { |
deadbeef | 3bc1510 | 2017-04-20 19:25:07 -0700 | [diff] [blame] | 5694 | // Call necessary methods to configure receiving a default stream as |
| 5695 | // soon as it arrives. |
| 5696 | cricket::VideoRecvParameters parameters; |
| 5697 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 5698 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
| 5699 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
| 5700 | |
| 5701 | // Call GetRtpReceiveParameters before configured to receive an unsignaled |
| 5702 | // stream. Should return nothing. |
| 5703 | EXPECT_EQ(webrtc::RtpParameters(), channel_->GetRtpReceiveParameters(0)); |
| 5704 | |
| 5705 | // Set a sink for an unsignaled stream. |
| 5706 | cricket::FakeVideoRenderer renderer; |
| 5707 | // Value of "0" means "unsignaled stream". |
| 5708 | EXPECT_TRUE(channel_->SetSink(0, &renderer)); |
| 5709 | |
| 5710 | // Call GetRtpReceiveParameters before the SSRC is known. Value of "0" |
| 5711 | // in this method means "unsignaled stream". |
| 5712 | webrtc::RtpParameters rtp_parameters = channel_->GetRtpReceiveParameters(0); |
| 5713 | ASSERT_EQ(1u, rtp_parameters.encodings.size()); |
| 5714 | EXPECT_FALSE(rtp_parameters.encodings[0].ssrc); |
| 5715 | |
| 5716 | // Receive VP8 packet. |
| 5717 | uint8_t data[kMinRtpPacketLen]; |
| 5718 | cricket::RtpHeader rtpHeader; |
| 5719 | rtpHeader.payload_type = GetEngineCodec("VP8").id; |
| 5720 | rtpHeader.seq_num = rtpHeader.timestamp = 0; |
| 5721 | rtpHeader.ssrc = kIncomingUnsignalledSsrc; |
| 5722 | cricket::SetRtpHeader(data, sizeof(data), rtpHeader); |
| 5723 | rtc::CopyOnWriteBuffer packet(data, sizeof(data)); |
| 5724 | rtc::PacketTime packet_time; |
| 5725 | channel_->OnPacketReceived(&packet, packet_time); |
| 5726 | |
| 5727 | // The |ssrc| member should still be unset. |
| 5728 | rtp_parameters = channel_->GetRtpReceiveParameters(0); |
| 5729 | ASSERT_EQ(1u, rtp_parameters.encodings.size()); |
| 5730 | EXPECT_FALSE(rtp_parameters.encodings[0].ssrc); |
| 5731 | } |
| 5732 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5733 | void WebRtcVideoChannelTest::TestReceiverLocalSsrcConfiguration( |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 5734 | bool receiver_first) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 5735 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 5736 | |
| 5737 | const uint32_t kSenderSsrc = 0xC0FFEE; |
Peter Boström | dfa2815 | 2015-10-21 17:21:10 +0200 | [diff] [blame] | 5738 | const uint32_t kSecondSenderSsrc = 0xBADCAFE; |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 5739 | const uint32_t kReceiverSsrc = 0x4711; |
Peter Boström | dfa2815 | 2015-10-21 17:21:10 +0200 | [diff] [blame] | 5740 | const uint32_t kExpectedDefaultReceiverSsrc = 1; |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 5741 | |
| 5742 | if (receiver_first) { |
| 5743 | AddRecvStream(StreamParams::CreateLegacy(kReceiverSsrc)); |
| 5744 | std::vector<FakeVideoReceiveStream*> receive_streams = |
| 5745 | fake_call_->GetVideoReceiveStreams(); |
| 5746 | ASSERT_EQ(1u, receive_streams.size()); |
Peter Boström | dfa2815 | 2015-10-21 17:21:10 +0200 | [diff] [blame] | 5747 | // Default local SSRC when we have no sender. |
| 5748 | EXPECT_EQ(kExpectedDefaultReceiverSsrc, |
| 5749 | receive_streams[0]->GetConfig().rtp.local_ssrc); |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 5750 | } |
| 5751 | AddSendStream(StreamParams::CreateLegacy(kSenderSsrc)); |
| 5752 | if (!receiver_first) |
| 5753 | AddRecvStream(StreamParams::CreateLegacy(kReceiverSsrc)); |
| 5754 | std::vector<FakeVideoReceiveStream*> receive_streams = |
| 5755 | fake_call_->GetVideoReceiveStreams(); |
| 5756 | ASSERT_EQ(1u, receive_streams.size()); |
| 5757 | EXPECT_EQ(kSenderSsrc, receive_streams[0]->GetConfig().rtp.local_ssrc); |
Peter Boström | dfa2815 | 2015-10-21 17:21:10 +0200 | [diff] [blame] | 5758 | |
| 5759 | // Removing first sender should fall back to another (in this case the second) |
| 5760 | // local send stream's SSRC. |
| 5761 | AddSendStream(StreamParams::CreateLegacy(kSecondSenderSsrc)); |
| 5762 | ASSERT_TRUE(channel_->RemoveSendStream(kSenderSsrc)); |
| 5763 | receive_streams = |
| 5764 | fake_call_->GetVideoReceiveStreams(); |
| 5765 | ASSERT_EQ(1u, receive_streams.size()); |
| 5766 | EXPECT_EQ(kSecondSenderSsrc, receive_streams[0]->GetConfig().rtp.local_ssrc); |
| 5767 | |
| 5768 | // Removing the last sender should fall back to default local SSRC. |
| 5769 | ASSERT_TRUE(channel_->RemoveSendStream(kSecondSenderSsrc)); |
| 5770 | receive_streams = |
| 5771 | fake_call_->GetVideoReceiveStreams(); |
| 5772 | ASSERT_EQ(1u, receive_streams.size()); |
| 5773 | EXPECT_EQ(kExpectedDefaultReceiverSsrc, |
| 5774 | receive_streams[0]->GetConfig().rtp.local_ssrc); |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 5775 | } |
| 5776 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5777 | TEST_F(WebRtcVideoChannelTest, ConfiguresLocalSsrc) { |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 5778 | TestReceiverLocalSsrcConfiguration(false); |
| 5779 | } |
| 5780 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5781 | TEST_F(WebRtcVideoChannelTest, ConfiguresLocalSsrcOnExistingReceivers) { |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 5782 | TestReceiverLocalSsrcConfiguration(true); |
| 5783 | } |
| 5784 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5785 | class WebRtcVideoChannelSimulcastTest : public testing::Test { |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5786 | public: |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5787 | WebRtcVideoChannelSimulcastTest() |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 5788 | : fake_call_(), |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 5789 | encoder_factory_(new cricket::FakeWebRtcVideoEncoderFactory), |
| 5790 | decoder_factory_(new cricket::FakeWebRtcVideoDecoderFactory), |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 5791 | engine_(std::unique_ptr<cricket::FakeWebRtcVideoEncoderFactory>( |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 5792 | encoder_factory_), |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 5793 | std::unique_ptr<cricket::FakeWebRtcVideoDecoderFactory>( |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 5794 | decoder_factory_)), |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 5795 | last_ssrc_(0) {} |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5796 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 5797 | void SetUp() override { |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 5798 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 5799 | channel_.reset( |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 5800 | engine_.CreateChannel(&fake_call_, GetMediaConfig(), VideoOptions())); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 5801 | channel_->OnReadyToSend(true); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5802 | last_ssrc_ = 123; |
| 5803 | } |
| 5804 | |
| 5805 | protected: |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5806 | void VerifySimulcastSettings(const VideoCodec& codec, |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 5807 | int capture_width, |
| 5808 | int capture_height, |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5809 | size_t num_configured_streams, |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 5810 | size_t expected_num_streams, |
| 5811 | bool screenshare, |
| 5812 | bool conference_mode) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 5813 | cricket::VideoSendParameters parameters; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 5814 | parameters.codecs.push_back(codec); |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 5815 | parameters.conference_mode = conference_mode; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 5816 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5817 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 5818 | std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 5819 | RTC_DCHECK(num_configured_streams <= ssrcs.size()); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5820 | ssrcs.resize(num_configured_streams); |
| 5821 | |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 5822 | AddSendStream(CreateSimStreamParams("cname", ssrcs)); |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 5823 | // Send a full-size frame to trigger a stream reconfiguration to use all |
| 5824 | // expected simulcast layers. |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 5825 | FakeVideoCapturerWithTaskQueue capturer; |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 5826 | VideoOptions options; |
| 5827 | if (screenshare) |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 5828 | options.is_screencast = screenshare; |
deadbeef | 5a4a75a | 2016-06-02 16:23:38 -0700 | [diff] [blame] | 5829 | EXPECT_TRUE( |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 5830 | channel_->SetVideoSend(ssrcs.front(), &options, &capturer)); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 5831 | // Fetch the latest stream since SetVideoSend() may recreate it if the |
| 5832 | // screen content setting is changed. |
| 5833 | FakeVideoSendStream* stream = fake_call_.GetVideoSendStreams().front(); |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 5834 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(cricket::VideoFormat( |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 5835 | capture_width, capture_height, |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 5836 | cricket::VideoFormat::FpsToInterval(30), |
| 5837 | cricket::FOURCC_I420))); |
| 5838 | channel_->SetSend(true); |
| 5839 | EXPECT_TRUE(capturer.CaptureFrame()); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5840 | |
Zach Stein | 3ca452b | 2018-01-18 10:01:24 -0800 | [diff] [blame] | 5841 | auto rtp_parameters = channel_->GetRtpSendParameters(kSsrcs3[0]); |
| 5842 | EXPECT_EQ(num_configured_streams, rtp_parameters.encodings.size()); |
| 5843 | |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5844 | std::vector<webrtc::VideoStream> video_streams = stream->GetVideoStreams(); |
| 5845 | ASSERT_EQ(expected_num_streams, video_streams.size()); |
| 5846 | |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 5847 | std::vector<webrtc::VideoStream> expected_streams; |
| 5848 | if (conference_mode) { |
| 5849 | expected_streams = GetSimulcastConfig( |
| 5850 | num_configured_streams, capture_width, capture_height, 0, |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5851 | webrtc::kDefaultBitratePriority, kDefaultQpMax, |
| 5852 | kDefaultVideoMaxFramerate, screenshare); |
sprang | 3ebabf1 | 2017-02-16 07:35:22 -0800 | [diff] [blame] | 5853 | if (screenshare) { |
| 5854 | for (const webrtc::VideoStream& stream : expected_streams) { |
| 5855 | // Never scale screen content. |
Danil Chapovalov | 350531e | 2018-06-08 11:04:04 +0000 | [diff] [blame] | 5856 | EXPECT_EQ(stream.width, rtc::checked_cast<size_t>(capture_width)); |
| 5857 | EXPECT_EQ(stream.height, rtc::checked_cast<size_t>(capture_height)); |
sprang | 3ebabf1 | 2017-02-16 07:35:22 -0800 | [diff] [blame] | 5858 | } |
| 5859 | } |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 5860 | } else { |
| 5861 | webrtc::VideoStream stream; |
| 5862 | stream.width = capture_width; |
| 5863 | stream.height = capture_height; |
| 5864 | stream.max_framerate = kDefaultVideoMaxFramerate; |
Åsa Persson | 45bbc8a | 2017-11-13 10:16:47 +0100 | [diff] [blame] | 5865 | stream.min_bitrate_bps = cricket::kMinVideoBitrateBps; |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 5866 | int max_bitrate_kbps; |
| 5867 | if (capture_width * capture_height <= 320 * 240) { |
| 5868 | max_bitrate_kbps = 600; |
| 5869 | } else if (capture_width * capture_height <= 640 * 480) { |
| 5870 | max_bitrate_kbps = 1700; |
| 5871 | } else if (capture_width * capture_height <= 960 * 540) { |
| 5872 | max_bitrate_kbps = 2000; |
| 5873 | } else { |
| 5874 | max_bitrate_kbps = 2500; |
| 5875 | } |
| 5876 | stream.target_bitrate_bps = stream.max_bitrate_bps = |
| 5877 | max_bitrate_kbps * 1000; |
| 5878 | stream.max_qp = kDefaultQpMax; |
| 5879 | expected_streams.push_back(stream); |
| 5880 | } |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5881 | |
| 5882 | ASSERT_EQ(expected_streams.size(), video_streams.size()); |
| 5883 | |
| 5884 | size_t num_streams = video_streams.size(); |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 5885 | int total_max_bitrate_bps = 0; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5886 | for (size_t i = 0; i < num_streams; ++i) { |
| 5887 | EXPECT_EQ(expected_streams[i].width, video_streams[i].width); |
| 5888 | EXPECT_EQ(expected_streams[i].height, video_streams[i].height); |
| 5889 | |
| 5890 | EXPECT_GT(video_streams[i].max_framerate, 0); |
| 5891 | EXPECT_EQ(expected_streams[i].max_framerate, |
| 5892 | video_streams[i].max_framerate); |
| 5893 | |
| 5894 | EXPECT_GT(video_streams[i].min_bitrate_bps, 0); |
| 5895 | EXPECT_EQ(expected_streams[i].min_bitrate_bps, |
| 5896 | video_streams[i].min_bitrate_bps); |
| 5897 | |
| 5898 | EXPECT_GT(video_streams[i].target_bitrate_bps, 0); |
| 5899 | EXPECT_EQ(expected_streams[i].target_bitrate_bps, |
| 5900 | video_streams[i].target_bitrate_bps); |
| 5901 | |
| 5902 | EXPECT_GT(video_streams[i].max_bitrate_bps, 0); |
| 5903 | EXPECT_EQ(expected_streams[i].max_bitrate_bps, |
| 5904 | video_streams[i].max_bitrate_bps); |
| 5905 | |
| 5906 | EXPECT_GT(video_streams[i].max_qp, 0); |
| 5907 | EXPECT_EQ(expected_streams[i].max_qp, video_streams[i].max_qp); |
| 5908 | |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 5909 | EXPECT_EQ(conference_mode, |
| 5910 | expected_streams[i].num_temporal_layers.has_value()); |
| 5911 | |
| 5912 | if (conference_mode) { |
| 5913 | EXPECT_EQ(expected_streams[i].num_temporal_layers, |
| 5914 | video_streams[i].num_temporal_layers); |
| 5915 | } |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 5916 | |
| 5917 | if (i == num_streams - 1) { |
| 5918 | total_max_bitrate_bps += video_streams[i].max_bitrate_bps; |
| 5919 | } else { |
| 5920 | total_max_bitrate_bps += video_streams[i].target_bitrate_bps; |
| 5921 | } |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5922 | } |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 5923 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 5924 | EXPECT_TRUE(channel_->SetVideoSend(ssrcs.front(), nullptr, nullptr)); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5925 | } |
| 5926 | |
| 5927 | FakeVideoSendStream* AddSendStream() { |
| 5928 | return AddSendStream(StreamParams::CreateLegacy(last_ssrc_++)); |
| 5929 | } |
| 5930 | |
| 5931 | FakeVideoSendStream* AddSendStream(const StreamParams& sp) { |
| 5932 | size_t num_streams = |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 5933 | fake_call_.GetVideoSendStreams().size(); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5934 | EXPECT_TRUE(channel_->AddSendStream(sp)); |
| 5935 | std::vector<FakeVideoSendStream*> streams = |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 5936 | fake_call_.GetVideoSendStreams(); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5937 | EXPECT_EQ(num_streams + 1, streams.size()); |
| 5938 | return streams[streams.size() - 1]; |
| 5939 | } |
| 5940 | |
| 5941 | std::vector<FakeVideoSendStream*> GetFakeSendStreams() { |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 5942 | return fake_call_.GetVideoSendStreams(); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5943 | } |
| 5944 | |
| 5945 | FakeVideoReceiveStream* AddRecvStream() { |
| 5946 | return AddRecvStream(StreamParams::CreateLegacy(last_ssrc_++)); |
| 5947 | } |
| 5948 | |
| 5949 | FakeVideoReceiveStream* AddRecvStream(const StreamParams& sp) { |
| 5950 | size_t num_streams = |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 5951 | fake_call_.GetVideoReceiveStreams().size(); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5952 | EXPECT_TRUE(channel_->AddRecvStream(sp)); |
| 5953 | std::vector<FakeVideoReceiveStream*> streams = |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 5954 | fake_call_.GetVideoReceiveStreams(); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5955 | EXPECT_EQ(num_streams + 1, streams.size()); |
| 5956 | return streams[streams.size() - 1]; |
| 5957 | } |
| 5958 | |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 5959 | webrtc::RtcEventLogNullImpl event_log_; |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 5960 | FakeCall fake_call_; |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 5961 | cricket::FakeWebRtcVideoEncoderFactory* encoder_factory_; |
| 5962 | cricket::FakeWebRtcVideoDecoderFactory* decoder_factory_; |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5963 | WebRtcVideoEngine engine_; |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 5964 | std::unique_ptr<VideoMediaChannel> channel_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 5965 | uint32_t last_ssrc_; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5966 | }; |
| 5967 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5968 | TEST_F(WebRtcVideoChannelSimulcastTest, SetSendCodecsWith2SimulcastStreams) { |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 5969 | VerifySimulcastSettings(cricket::VideoCodec("VP8"), 640, 360, 2, 2, false, |
| 5970 | true); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5971 | } |
| 5972 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5973 | TEST_F(WebRtcVideoChannelSimulcastTest, SetSendCodecsWith3SimulcastStreams) { |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 5974 | VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 3, false, |
| 5975 | true); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5976 | } |
| 5977 | |
| 5978 | // Test that we normalize send codec format size in simulcast. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5979 | TEST_F(WebRtcVideoChannelSimulcastTest, SetSendCodecsWithOddSizeInSimulcast) { |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 5980 | VerifySimulcastSettings(cricket::VideoCodec("VP8"), 541, 271, 2, 2, false, |
| 5981 | true); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 5982 | } |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 5983 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5984 | TEST_F(WebRtcVideoChannelSimulcastTest, SetSendCodecsForScreenshare) { |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 5985 | VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 1, true, |
| 5986 | false); |
| 5987 | } |
| 5988 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5989 | TEST_F(WebRtcVideoChannelSimulcastTest, |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 5990 | SetSendCodecsForConferenceModeScreenshare) { |
| 5991 | VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 1, true, |
| 5992 | true); |
| 5993 | } |
| 5994 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5995 | TEST_F(WebRtcVideoChannelSimulcastTest, SetSendCodecsForSimulcastScreenshare) { |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 5996 | webrtc::test::ScopedFieldTrials override_field_trials_( |
| 5997 | "WebRTC-SimulcastScreenshare/Enabled/"); |
| 5998 | VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 2, true, |
| 5999 | true); |
| 6000 | } |
| 6001 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 6002 | TEST_F(WebRtcVideoChannelSimulcastTest, |
sprang | fe627f3 | 2017-03-29 08:24:59 -0700 | [diff] [blame] | 6003 | NoSimulcastScreenshareWithoutConference) { |
| 6004 | webrtc::test::ScopedFieldTrials override_field_trials_( |
| 6005 | "WebRTC-SimulcastScreenshare/Enabled/"); |
| 6006 | VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 1, true, |
| 6007 | false); |
| 6008 | } |
| 6009 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 6010 | } // namespace cricket |