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" |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame^] | 20 | #include "api/units/time_delta.h" |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 21 | #include "api/video_codecs/builtin_video_decoder_factory.h" |
| 22 | #include "api/video_codecs/builtin_video_encoder_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 23 | #include "api/video_codecs/sdp_video_format.h" |
| 24 | #include "api/video_codecs/video_decoder_factory.h" |
| 25 | #include "api/video_codecs/video_encoder.h" |
| 26 | #include "api/video_codecs/video_encoder_factory.h" |
| 27 | #include "call/flexfec_receive_stream.h" |
| 28 | #include "common_video/h264/profile_level_id.h" |
| 29 | #include "logging/rtc_event_log/rtc_event_log.h" |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 30 | #include "media/base/fakenetworkinterface.h" |
| 31 | #include "media/base/fakevideocapturer.h" |
| 32 | #include "media/base/fakevideorenderer.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 33 | #include "media/base/mediaconstants.h" |
| 34 | #include "media/base/rtputils.h" |
| 35 | #include "media/base/testutils.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 36 | #include "media/engine/constants.h" |
| 37 | #include "media/engine/fakewebrtccall.h" |
| 38 | #include "media/engine/fakewebrtcvideoengine.h" |
| 39 | #include "media/engine/simulcast.h" |
| 40 | #include "media/engine/webrtcvideoengine.h" |
| 41 | #include "media/engine/webrtcvoiceengine.h" |
Åsa Persson | 23cd45a | 2018-07-03 10:40:40 +0200 | [diff] [blame] | 42 | #include "modules/rtp_rtcp/include/rtp_header_parser.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 43 | #include "rtc_base/arraysize.h" |
Ilya Nikolaevskiy | 9c38c47 | 2018-09-03 16:11:42 +0200 | [diff] [blame] | 44 | #include "rtc_base/fakeclock.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 45 | #include "rtc_base/gunit.h" |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 46 | #include "rtc_base/numerics/safe_conversions.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 47 | #include "rtc_base/stringutils.h" |
| 48 | #include "test/field_trial.h" |
| 49 | #include "test/gmock.h" |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 50 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 51 | using cricket::FakeVideoCapturerWithTaskQueue; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 52 | using webrtc::BitrateConstraints; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 53 | using webrtc::RtpExtension; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 54 | using testing::Field; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 55 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 56 | namespace { |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 57 | static const int kDefaultQpMax = 56; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 58 | |
noahric | d10a68e | 2015-07-10 11:27:55 -0700 | [diff] [blame] | 59 | static const uint8_t kRedRtxPayloadType = 125; |
| 60 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 61 | static const uint32_t kTimeout = 5000U; |
| 62 | static const uint32_t kDefaultReceiveSsrc = 0; |
| 63 | static const uint32_t kSsrc = 1234u; |
| 64 | static const uint32_t kSsrcs4[] = {1, 2, 3, 4}; |
| 65 | static const int kVideoWidth = 640; |
| 66 | static const int kVideoHeight = 360; |
| 67 | static const int kFramerate = 30; |
| 68 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 69 | static const uint32_t kSsrcs1[] = {1}; |
| 70 | static const uint32_t kSsrcs3[] = {1, 2, 3}; |
| 71 | static const uint32_t kRtxSsrcs1[] = {4}; |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 72 | static const uint32_t kFlexfecSsrc = 5; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 73 | static const uint32_t kIncomingUnsignalledSsrc = 0xC0FFEE; |
mzanaty | 8a855d6 | 2017-02-17 15:46:43 -0800 | [diff] [blame] | 74 | static const uint32_t kDefaultRecvSsrc = 0; |
| 75 | |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 76 | static const char kUnsupportedExtensionName[] = |
| 77 | "urn:ietf:params:rtp-hdrext:unsupported"; |
pbos@webrtc.org | f99c2f2 | 2014-06-13 12:27:38 +0000 | [diff] [blame] | 78 | |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 79 | cricket::VideoCodec RemoveFeedbackParams(cricket::VideoCodec&& codec) { |
| 80 | codec.feedback_params = cricket::FeedbackParams(); |
Mirko Bonadei | 29a8d10 | 2018-04-25 23:58:26 +0200 | [diff] [blame] | 81 | return std::move(codec); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 82 | } |
| 83 | |
pbos@webrtc.org | f99c2f2 | 2014-06-13 12:27:38 +0000 | [diff] [blame] | 84 | void VerifyCodecHasDefaultFeedbackParams(const cricket::VideoCodec& codec) { |
| 85 | EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( |
| 86 | cricket::kRtcpFbParamNack, cricket::kParamValueEmpty))); |
| 87 | EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( |
| 88 | cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli))); |
| 89 | EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( |
| 90 | cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty))); |
| 91 | EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( |
stefan | 43edf0f | 2015-11-20 18:05:48 -0800 | [diff] [blame] | 92 | cricket::kRtcpFbParamTransportCc, cricket::kParamValueEmpty))); |
| 93 | EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( |
pbos@webrtc.org | f99c2f2 | 2014-06-13 12:27:38 +0000 | [diff] [blame] | 94 | cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir))); |
| 95 | } |
| 96 | |
magjed | 725e484 | 2016-11-16 00:48:13 -0800 | [diff] [blame] | 97 | // Return true if any codec in |codecs| is an RTX codec with associated payload |
| 98 | // type |payload_type|. |
| 99 | bool HasRtxCodec(const std::vector<cricket::VideoCodec>& codecs, |
| 100 | int payload_type) { |
| 101 | for (const cricket::VideoCodec& codec : codecs) { |
| 102 | int associated_payload_type; |
| 103 | if (cricket::CodecNamesEq(codec.name.c_str(), "rtx") && |
| 104 | codec.GetParam(cricket::kCodecParamAssociatedPayloadType, |
| 105 | &associated_payload_type) && |
| 106 | associated_payload_type == payload_type) { |
| 107 | return true; |
| 108 | } |
| 109 | } |
| 110 | return false; |
| 111 | } |
| 112 | |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 113 | // TODO(nisse): Duplicated in call.cc. |
| 114 | const int* FindKeyByValue(const std::map<int, int>& m, int v) { |
| 115 | for (const auto& kv : m) { |
| 116 | if (kv.second == v) |
| 117 | return &kv.first; |
| 118 | } |
| 119 | return nullptr; |
| 120 | } |
| 121 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 122 | bool HasRtxReceiveAssociation(const webrtc::VideoReceiveStream::Config& config, |
| 123 | int payload_type) { |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 124 | return FindKeyByValue(config.rtp.rtx_associated_payload_types, |
| 125 | payload_type) != nullptr; |
| 126 | } |
| 127 | |
| 128 | // Check that there's an Rtx payload type for each decoder. |
| 129 | bool VerifyRtxReceiveAssociations( |
| 130 | const webrtc::VideoReceiveStream::Config& config) { |
| 131 | for (const auto& decoder : config.decoders) { |
| 132 | if (!HasRtxReceiveAssociation(config, decoder.payload_type)) |
| 133 | return false; |
| 134 | } |
| 135 | return true; |
| 136 | } |
| 137 | |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 138 | rtc::scoped_refptr<webrtc::VideoFrameBuffer> CreateBlackFrameBuffer( |
nisse | 64ec8f8 | 2016-09-27 00:17:25 -0700 | [diff] [blame] | 139 | int width, |
| 140 | int height) { |
| 141 | rtc::scoped_refptr<webrtc::I420Buffer> buffer = |
| 142 | webrtc::I420Buffer::Create(width, height); |
nisse | af91689 | 2017-01-10 07:44:26 -0800 | [diff] [blame] | 143 | webrtc::I420Buffer::SetBlack(buffer); |
nisse | 64ec8f8 | 2016-09-27 00:17:25 -0700 | [diff] [blame] | 144 | return buffer; |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 147 | void VerifySendStreamHasRtxTypes(const webrtc::VideoSendStream::Config& config, |
| 148 | const std::map<int, int>& rtx_types) { |
| 149 | std::map<int, int>::const_iterator it; |
Niels Möller | 259a497 | 2018-04-05 15:36:51 +0200 | [diff] [blame] | 150 | it = rtx_types.find(config.rtp.payload_type); |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 151 | EXPECT_TRUE(it != rtx_types.end() && |
| 152 | it->second == config.rtp.rtx.payload_type); |
| 153 | |
brandtr | b5f2c3f | 2016-10-04 23:28:39 -0700 | [diff] [blame] | 154 | if (config.rtp.ulpfec.red_rtx_payload_type != -1) { |
| 155 | it = rtx_types.find(config.rtp.ulpfec.red_payload_type); |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 156 | EXPECT_TRUE(it != rtx_types.end() && |
brandtr | b5f2c3f | 2016-10-04 23:28:39 -0700 | [diff] [blame] | 157 | it->second == config.rtp.ulpfec.red_rtx_payload_type); |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 158 | } |
| 159 | } |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 160 | |
| 161 | cricket::MediaConfig GetMediaConfig() { |
| 162 | cricket::MediaConfig media_config; |
Niels Möller | 1d7ecd2 | 2018-01-18 15:25:12 +0100 | [diff] [blame] | 163 | media_config.video.enable_cpu_adaptation = false; |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 164 | return media_config; |
| 165 | } |
nisse | 26e3abb | 2017-08-25 04:44:25 -0700 | [diff] [blame] | 166 | |
Åsa Persson | bdee46d | 2018-06-25 11:28:06 +0200 | [diff] [blame] | 167 | // Values from GetMaxDefaultVideoBitrateKbps in webrtcvideoengine.cc. |
| 168 | int GetMaxDefaultBitrateBps(size_t width, size_t height) { |
| 169 | if (width * height <= 320 * 240) { |
| 170 | return 600000; |
| 171 | } else if (width * height <= 640 * 480) { |
| 172 | return 1700000; |
| 173 | } else if (width * height <= 960 * 540) { |
| 174 | return 2000000; |
| 175 | } else { |
| 176 | return 2500000; |
| 177 | } |
| 178 | } |
| 179 | |
Niels Möller | 731a2c2 | 2018-07-30 15:08:07 +0200 | [diff] [blame] | 180 | class MockVideoSource : public rtc::VideoSourceInterface<webrtc::VideoFrame> { |
| 181 | public: |
| 182 | MOCK_METHOD2(AddOrUpdateSink, |
| 183 | void(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink, |
| 184 | const rtc::VideoSinkWants& wants)); |
| 185 | MOCK_METHOD1(RemoveSink, |
| 186 | void(rtc::VideoSinkInterface<webrtc::VideoFrame>* sink)); |
| 187 | }; |
| 188 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 189 | } // namespace |
| 190 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 191 | #define EXPECT_FRAME_WAIT(c, w, h, t) \ |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 192 | EXPECT_EQ_WAIT((c), renderer_.num_rendered_frames(), (t)); \ |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 193 | EXPECT_EQ((w), renderer_.width()); \ |
| 194 | EXPECT_EQ((h), renderer_.height()); \ |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 195 | EXPECT_EQ(0, renderer_.errors()); |
| 196 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 197 | #define EXPECT_FRAME_ON_RENDERER_WAIT(r, c, w, h, t) \ |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 198 | EXPECT_EQ_WAIT((c), (r).num_rendered_frames(), (t)); \ |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 199 | EXPECT_EQ((w), (r).width()); \ |
| 200 | EXPECT_EQ((h), (r).height()); \ |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 201 | EXPECT_EQ(0, (r).errors()); |
| 202 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 203 | namespace cricket { |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 204 | class WebRtcVideoEngineTest : public ::testing::Test { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 205 | public: |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 206 | WebRtcVideoEngineTest() : WebRtcVideoEngineTest("") {} |
| 207 | explicit WebRtcVideoEngineTest(const char* field_trials) |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 208 | : override_field_trials_(field_trials), |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 209 | call_(webrtc::Call::Create(webrtc::Call::Config(&event_log_))), |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 210 | encoder_factory_(new cricket::FakeWebRtcVideoEncoderFactory), |
| 211 | decoder_factory_(new cricket::FakeWebRtcVideoDecoderFactory), |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 212 | engine_(std::unique_ptr<cricket::FakeWebRtcVideoEncoderFactory>( |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 213 | encoder_factory_), |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 214 | std::unique_ptr<cricket::FakeWebRtcVideoDecoderFactory>( |
Ilya Nikolaevskiy | 9c38c47 | 2018-09-03 16:11:42 +0200 | [diff] [blame] | 215 | decoder_factory_)) { |
| 216 | // Ensure fake clock doesn't return 0, which will cause some initializations |
| 217 | // fail inside RTP senders. |
| 218 | fake_clock_.AdvanceTimeMicros(1); |
| 219 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 220 | |
| 221 | protected: |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 222 | void AssignDefaultAptRtxTypes(); |
| 223 | void AssignDefaultCodec(); |
| 224 | |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 225 | // Find the index of the codec in the engine with the given name. The codec |
| 226 | // must be present. |
Oleh Prypin | a40f824 | 2017-12-21 13:32:23 +0100 | [diff] [blame] | 227 | size_t GetEngineCodecIndex(const std::string& name) const; |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 228 | |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 229 | // Find the codec in the engine with the given name. The codec must be |
| 230 | // present. |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 231 | cricket::VideoCodec GetEngineCodec(const std::string& name) const; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 232 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 233 | VideoMediaChannel* SetSendParamsWithAllSupportedCodecs(); |
pbos@webrtc.org | fa553ef | 2014-10-20 11:07:07 +0000 | [diff] [blame] | 234 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 235 | VideoMediaChannel* SetRecvParamsWithSupportedCodecs( |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 236 | const std::vector<VideoCodec>& codecs); |
| 237 | |
Peter Boström | e449915 | 2016-02-05 11:13:28 +0100 | [diff] [blame] | 238 | void TestExtendedEncoderOveruse(bool use_external_encoder); |
| 239 | |
Ilya Nikolaevskiy | 9c38c47 | 2018-09-03 16:11:42 +0200 | [diff] [blame] | 240 | // Has to be the first one, so it is initialized before the call or there is a |
| 241 | // race condition in the clock access. |
| 242 | rtc::ScopedFakeClock fake_clock_; |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 243 | webrtc::test::ScopedFieldTrials override_field_trials_; |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 244 | webrtc::RtcEventLogNullImpl event_log_; |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 245 | // Used in WebRtcVideoEngineVoiceTest, but defined here so it's properly |
pbos@webrtc.org | f1f0d9a | 2015-03-02 13:30:15 +0000 | [diff] [blame] | 246 | // initialized when the constructor is called. |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 247 | std::unique_ptr<webrtc::Call> call_; |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 248 | cricket::FakeWebRtcVideoEncoderFactory* encoder_factory_; |
| 249 | cricket::FakeWebRtcVideoDecoderFactory* decoder_factory_; |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 250 | WebRtcVideoEngine engine_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 251 | VideoCodec default_codec_; |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 252 | std::map<int, int> default_apt_rtx_types_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 253 | }; |
| 254 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 255 | TEST_F(WebRtcVideoEngineTest, DefaultRtxCodecHasAssociatedPayloadTypeSet) { |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 256 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
| 257 | AssignDefaultCodec(); |
| 258 | |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 259 | std::vector<VideoCodec> engine_codecs = engine_.codecs(); |
| 260 | for (size_t i = 0; i < engine_codecs.size(); ++i) { |
| 261 | if (engine_codecs[i].name != kRtxCodecName) |
| 262 | continue; |
| 263 | int associated_payload_type; |
| 264 | EXPECT_TRUE(engine_codecs[i].GetParam(kCodecParamAssociatedPayloadType, |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 265 | &associated_payload_type)); |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 266 | EXPECT_EQ(default_codec_.id, associated_payload_type); |
| 267 | return; |
| 268 | } |
| 269 | FAIL() << "No RTX codec found among default codecs."; |
| 270 | } |
| 271 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 272 | TEST_F(WebRtcVideoEngineTest, SupportsTimestampOffsetHeaderExtension) { |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 273 | RtpCapabilities capabilities = engine_.GetCapabilities(); |
| 274 | ASSERT_FALSE(capabilities.header_extensions.empty()); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 275 | for (const RtpExtension& extension : capabilities.header_extensions) { |
| 276 | if (extension.uri == RtpExtension::kTimestampOffsetUri) { |
| 277 | EXPECT_EQ(RtpExtension::kTimestampOffsetDefaultId, extension.id); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 278 | return; |
| 279 | } |
| 280 | } |
| 281 | FAIL() << "Timestamp offset extension not in header-extension list."; |
| 282 | } |
| 283 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 284 | TEST_F(WebRtcVideoEngineTest, SupportsAbsoluteSenderTimeHeaderExtension) { |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 285 | RtpCapabilities capabilities = engine_.GetCapabilities(); |
| 286 | ASSERT_FALSE(capabilities.header_extensions.empty()); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 287 | for (const RtpExtension& extension : capabilities.header_extensions) { |
| 288 | if (extension.uri == RtpExtension::kAbsSendTimeUri) { |
| 289 | EXPECT_EQ(RtpExtension::kAbsSendTimeDefaultId, extension.id); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 290 | return; |
| 291 | } |
| 292 | } |
| 293 | FAIL() << "Absolute Sender Time extension not in header-extension list."; |
| 294 | } |
| 295 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 296 | TEST_F(WebRtcVideoEngineTest, SupportsTransportSequenceNumberHeaderExtension) { |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 297 | RtpCapabilities capabilities = engine_.GetCapabilities(); |
| 298 | ASSERT_FALSE(capabilities.header_extensions.empty()); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 299 | for (const RtpExtension& extension : capabilities.header_extensions) { |
| 300 | if (extension.uri == RtpExtension::kTransportSequenceNumberUri) { |
| 301 | EXPECT_EQ(RtpExtension::kTransportSequenceNumberDefaultId, extension.id); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 302 | return; |
| 303 | } |
| 304 | } |
| 305 | FAIL() << "Transport sequence number extension not in header-extension list."; |
| 306 | } |
| 307 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 308 | TEST_F(WebRtcVideoEngineTest, SupportsVideoRotationHeaderExtension) { |
Stefan Holmer | 9d69c3f | 2015-12-07 10:45:43 +0100 | [diff] [blame] | 309 | RtpCapabilities capabilities = engine_.GetCapabilities(); |
| 310 | ASSERT_FALSE(capabilities.header_extensions.empty()); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 311 | for (const RtpExtension& extension : capabilities.header_extensions) { |
| 312 | if (extension.uri == RtpExtension::kVideoRotationUri) { |
| 313 | EXPECT_EQ(RtpExtension::kVideoRotationDefaultId, extension.id); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 314 | return; |
| 315 | } |
| 316 | } |
| 317 | FAIL() << "Video Rotation extension not in header-extension list."; |
| 318 | } |
| 319 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 320 | TEST_F(WebRtcVideoEngineTest, CVOSetHeaderExtensionBeforeCapturer) { |
Niels Möller | 731a2c2 | 2018-07-30 15:08:07 +0200 | [diff] [blame] | 321 | // Allocate the source first to prevent early destruction before channel's |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 322 | // dtor is called. |
Niels Möller | 731a2c2 | 2018-07-30 15:08:07 +0200 | [diff] [blame] | 323 | testing::NiceMock<MockVideoSource> video_source; |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 324 | |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 325 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 326 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 327 | std::unique_ptr<VideoMediaChannel> channel( |
| 328 | SetSendParamsWithAllSupportedCodecs()); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 329 | EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(kSsrc))); |
| 330 | |
| 331 | // Add CVO extension. |
| 332 | const int id = 1; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 333 | cricket::VideoSendParameters parameters; |
| 334 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 335 | parameters.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 336 | RtpExtension(RtpExtension::kVideoRotationUri, id)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 337 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 338 | |
Niels Möller | 731a2c2 | 2018-07-30 15:08:07 +0200 | [diff] [blame] | 339 | EXPECT_CALL( |
| 340 | video_source, |
| 341 | AddOrUpdateSink(testing::_, |
| 342 | Field(&rtc::VideoSinkWants::rotation_applied, false))); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 343 | // Set capturer. |
Niels Möller | 731a2c2 | 2018-07-30 15:08:07 +0200 | [diff] [blame] | 344 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, nullptr, &video_source)); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 345 | |
| 346 | // Verify capturer has turned off applying rotation. |
Niels Möller | 731a2c2 | 2018-07-30 15:08:07 +0200 | [diff] [blame] | 347 | testing::Mock::VerifyAndClear(&video_source); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 348 | |
| 349 | // Verify removing header extension turns on applying rotation. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 350 | parameters.extensions.clear(); |
Niels Möller | 731a2c2 | 2018-07-30 15:08:07 +0200 | [diff] [blame] | 351 | EXPECT_CALL( |
| 352 | video_source, |
| 353 | AddOrUpdateSink(testing::_, |
| 354 | Field(&rtc::VideoSinkWants::rotation_applied, true))); |
| 355 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 356 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 357 | } |
| 358 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 359 | TEST_F(WebRtcVideoEngineTest, CVOSetHeaderExtensionBeforeAddSendStream) { |
Niels Möller | 731a2c2 | 2018-07-30 15:08:07 +0200 | [diff] [blame] | 360 | // Allocate the source first to prevent early destruction before channel's |
perkj | 91e1c15 | 2016-03-02 05:34:00 -0800 | [diff] [blame] | 361 | // dtor is called. |
Niels Möller | 731a2c2 | 2018-07-30 15:08:07 +0200 | [diff] [blame] | 362 | testing::NiceMock<MockVideoSource> video_source; |
perkj | 91e1c15 | 2016-03-02 05:34:00 -0800 | [diff] [blame] | 363 | |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 364 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
perkj | 91e1c15 | 2016-03-02 05:34:00 -0800 | [diff] [blame] | 365 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 366 | std::unique_ptr<VideoMediaChannel> channel( |
| 367 | SetSendParamsWithAllSupportedCodecs()); |
perkj | 91e1c15 | 2016-03-02 05:34:00 -0800 | [diff] [blame] | 368 | // Add CVO extension. |
| 369 | const int id = 1; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 370 | cricket::VideoSendParameters parameters; |
| 371 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
perkj | 91e1c15 | 2016-03-02 05:34:00 -0800 | [diff] [blame] | 372 | parameters.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 373 | RtpExtension(RtpExtension::kVideoRotationUri, id)); |
perkj | 91e1c15 | 2016-03-02 05:34:00 -0800 | [diff] [blame] | 374 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
| 375 | EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(kSsrc))); |
| 376 | |
Niels Möller | 731a2c2 | 2018-07-30 15:08:07 +0200 | [diff] [blame] | 377 | // Set source. |
| 378 | EXPECT_CALL( |
| 379 | video_source, |
| 380 | AddOrUpdateSink(testing::_, |
| 381 | Field(&rtc::VideoSinkWants::rotation_applied, false))); |
| 382 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, nullptr, &video_source)); |
perkj | 91e1c15 | 2016-03-02 05:34:00 -0800 | [diff] [blame] | 383 | } |
| 384 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 385 | TEST_F(WebRtcVideoEngineTest, CVOSetHeaderExtensionAfterCapturer) { |
Niels Möller | 731a2c2 | 2018-07-30 15:08:07 +0200 | [diff] [blame] | 386 | testing::NiceMock<MockVideoSource> video_source; |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 387 | |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 388 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
| 389 | encoder_factory_->AddSupportedVideoCodecType("VP9"); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 390 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 391 | std::unique_ptr<VideoMediaChannel> channel( |
| 392 | SetSendParamsWithAllSupportedCodecs()); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 393 | EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(kSsrc))); |
| 394 | |
| 395 | // Set capturer. |
Niels Möller | 731a2c2 | 2018-07-30 15:08:07 +0200 | [diff] [blame] | 396 | EXPECT_CALL( |
| 397 | video_source, |
| 398 | AddOrUpdateSink(testing::_, |
| 399 | Field(&rtc::VideoSinkWants::rotation_applied, true))); |
| 400 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, nullptr, &video_source)); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 401 | |
perkj | caafdba | 2016-03-20 07:34:29 -0700 | [diff] [blame] | 402 | // Verify capturer has turned on applying rotation. |
Niels Möller | 731a2c2 | 2018-07-30 15:08:07 +0200 | [diff] [blame] | 403 | testing::Mock::VerifyAndClear(&video_source); |
perkj | caafdba | 2016-03-20 07:34:29 -0700 | [diff] [blame] | 404 | |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 405 | // Add CVO extension. |
| 406 | const int id = 1; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 407 | cricket::VideoSendParameters parameters; |
| 408 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 409 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 410 | parameters.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 411 | RtpExtension(RtpExtension::kVideoRotationUri, id)); |
perkj | caafdba | 2016-03-20 07:34:29 -0700 | [diff] [blame] | 412 | // Also remove the first codec to trigger a codec change as well. |
| 413 | parameters.codecs.erase(parameters.codecs.begin()); |
Niels Möller | 731a2c2 | 2018-07-30 15:08:07 +0200 | [diff] [blame] | 414 | EXPECT_CALL( |
| 415 | video_source, |
| 416 | AddOrUpdateSink(testing::_, |
| 417 | Field(&rtc::VideoSinkWants::rotation_applied, false))); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 418 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 419 | |
| 420 | // Verify capturer has turned off applying rotation. |
Niels Möller | 731a2c2 | 2018-07-30 15:08:07 +0200 | [diff] [blame] | 421 | testing::Mock::VerifyAndClear(&video_source); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 422 | |
| 423 | // Verify removing header extension turns on applying rotation. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 424 | parameters.extensions.clear(); |
Niels Möller | 731a2c2 | 2018-07-30 15:08:07 +0200 | [diff] [blame] | 425 | EXPECT_CALL( |
| 426 | video_source, |
| 427 | AddOrUpdateSink(testing::_, |
| 428 | Field(&rtc::VideoSinkWants::rotation_applied, true))); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 429 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 430 | } |
| 431 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 432 | TEST_F(WebRtcVideoEngineTest, SetSendFailsBeforeSettingCodecs) { |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 433 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
| 434 | |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 435 | std::unique_ptr<VideoMediaChannel> channel( |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 436 | engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions())); |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 437 | |
| 438 | EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(123))); |
| 439 | |
| 440 | EXPECT_FALSE(channel->SetSend(true)) |
| 441 | << "Channel should not start without codecs."; |
| 442 | EXPECT_TRUE(channel->SetSend(false)) |
| 443 | << "Channel should be stoppable even without set codecs."; |
| 444 | } |
| 445 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 446 | TEST_F(WebRtcVideoEngineTest, GetStatsWithoutSendCodecsSetDoesNotCrash) { |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 447 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
| 448 | |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 449 | std::unique_ptr<VideoMediaChannel> channel( |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 450 | engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions())); |
pbos@webrtc.org | c3d2bd2 | 2014-08-12 20:55:10 +0000 | [diff] [blame] | 451 | EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(123))); |
| 452 | VideoMediaInfo info; |
| 453 | channel->GetStats(&info); |
| 454 | } |
| 455 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 456 | TEST_F(WebRtcVideoEngineTest, UseFactoryForVp8WhenSupported) { |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 457 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 458 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 459 | std::unique_ptr<VideoMediaChannel> channel( |
| 460 | SetSendParamsWithAllSupportedCodecs()); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 461 | channel->OnReadyToSend(true); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 462 | |
| 463 | EXPECT_TRUE( |
| 464 | channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 465 | EXPECT_EQ(0, encoder_factory_->GetNumCreatedEncoders()); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 466 | EXPECT_TRUE(channel->SetSend(true)); |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 467 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 468 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, nullptr, &capturer)); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 469 | EXPECT_EQ(cricket::CS_RUNNING, |
| 470 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 471 | EXPECT_TRUE(capturer.CaptureFrame()); |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 472 | // Sending one frame will have allocate the encoder. |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 473 | ASSERT_TRUE(encoder_factory_->WaitForCreatedVideoEncoders(1)); |
| 474 | EXPECT_TRUE_WAIT(encoder_factory_->encoders()[0]->GetNumEncodedFrames() > 0, |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 475 | kTimeout); |
| 476 | |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 477 | int num_created_encoders = encoder_factory_->GetNumCreatedEncoders(); |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 478 | EXPECT_EQ(num_created_encoders, 1); |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 479 | |
| 480 | // Setting codecs of the same type should not reallocate any encoders |
| 481 | // (expecting a no-op). |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 482 | cricket::VideoSendParameters parameters; |
| 483 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 484 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 485 | EXPECT_EQ(num_created_encoders, encoder_factory_->GetNumCreatedEncoders()); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 486 | |
| 487 | // Remove stream previously added to free the external encoder instance. |
| 488 | EXPECT_TRUE(channel->RemoveSendStream(kSsrc)); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 489 | EXPECT_EQ(0u, encoder_factory_->encoders().size()); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 490 | } |
| 491 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 492 | // Test that when an encoder factory supports H264, we add an RTX |
| 493 | // codec for it. |
| 494 | // TODO(deadbeef): This test should be updated if/when we start |
| 495 | // adding RTX codecs for unrecognized codec names. |
| 496 | TEST_F(WebRtcVideoEngineTest, RtxCodecAddedForH264Codec) { |
magjed | 725e484 | 2016-11-16 00:48:13 -0800 | [diff] [blame] | 497 | using webrtc::H264::ProfileLevelIdToString; |
| 498 | using webrtc::H264::ProfileLevelId; |
| 499 | using webrtc::H264::kLevel1; |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 500 | webrtc::SdpVideoFormat h264_constrained_baseline("H264"); |
| 501 | h264_constrained_baseline.parameters[kH264FmtpProfileLevelId] = |
magjed | 725e484 | 2016-11-16 00:48:13 -0800 | [diff] [blame] | 502 | *ProfileLevelIdToString( |
| 503 | ProfileLevelId(webrtc::H264::kProfileConstrainedBaseline, kLevel1)); |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 504 | webrtc::SdpVideoFormat h264_constrained_high("H264"); |
| 505 | h264_constrained_high.parameters[kH264FmtpProfileLevelId] = |
magjed | 725e484 | 2016-11-16 00:48:13 -0800 | [diff] [blame] | 506 | *ProfileLevelIdToString( |
| 507 | ProfileLevelId(webrtc::H264::kProfileConstrainedHigh, kLevel1)); |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 508 | webrtc::SdpVideoFormat h264_high("H264"); |
| 509 | h264_high.parameters[kH264FmtpProfileLevelId] = *ProfileLevelIdToString( |
magjed | 725e484 | 2016-11-16 00:48:13 -0800 | [diff] [blame] | 510 | ProfileLevelId(webrtc::H264::kProfileHigh, kLevel1)); |
| 511 | |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 512 | encoder_factory_->AddSupportedVideoCodec(h264_constrained_baseline); |
| 513 | encoder_factory_->AddSupportedVideoCodec(h264_constrained_high); |
| 514 | encoder_factory_->AddSupportedVideoCodec(h264_high); |
Taylor Brandstetter | 6c3e788 | 2016-06-29 11:14:19 -0700 | [diff] [blame] | 515 | |
magjed | 725e484 | 2016-11-16 00:48:13 -0800 | [diff] [blame] | 516 | // First figure out what payload types the test codecs got assigned. |
| 517 | const std::vector<cricket::VideoCodec> codecs = engine_.codecs(); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 518 | // Now search for RTX codecs for them. Expect that they all have associated |
| 519 | // RTX codecs. |
magjed | 725e484 | 2016-11-16 00:48:13 -0800 | [diff] [blame] | 520 | EXPECT_TRUE(HasRtxCodec( |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 521 | codecs, |
| 522 | FindMatchingCodec(codecs, cricket::VideoCodec(h264_constrained_baseline)) |
| 523 | ->id)); |
magjed | 725e484 | 2016-11-16 00:48:13 -0800 | [diff] [blame] | 524 | EXPECT_TRUE(HasRtxCodec( |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 525 | codecs, |
| 526 | FindMatchingCodec(codecs, cricket::VideoCodec(h264_constrained_high)) |
| 527 | ->id)); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 528 | EXPECT_TRUE(HasRtxCodec( |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 529 | codecs, FindMatchingCodec(codecs, cricket::VideoCodec(h264_high))->id)); |
Taylor Brandstetter | 6c3e788 | 2016-06-29 11:14:19 -0700 | [diff] [blame] | 530 | } |
| 531 | |
Peter Boström | 1299615 | 2016-05-14 02:03:18 +0200 | [diff] [blame] | 532 | #if !defined(RTC_DISABLE_VP9) |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 533 | TEST_F(WebRtcVideoEngineTest, CanConstructDecoderForVp9EncoderFactory) { |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 534 | encoder_factory_->AddSupportedVideoCodecType("VP9"); |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 535 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 536 | std::unique_ptr<VideoMediaChannel> channel( |
| 537 | SetSendParamsWithAllSupportedCodecs()); |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 538 | |
| 539 | EXPECT_TRUE( |
| 540 | channel->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| 541 | } |
Peter Boström | 1299615 | 2016-05-14 02:03:18 +0200 | [diff] [blame] | 542 | #endif // !defined(RTC_DISABLE_VP9) |
Peter Boström | 53eda3d | 2015-03-27 15:53:18 +0100 | [diff] [blame] | 543 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 544 | TEST_F(WebRtcVideoEngineTest, PropagatesInputFrameTimestamp) { |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 545 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 546 | FakeCall* fake_call = new FakeCall(); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 547 | call_.reset(fake_call); |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 548 | std::unique_ptr<VideoMediaChannel> channel( |
| 549 | SetSendParamsWithAllSupportedCodecs()); |
qiangchen | c27d89f | 2015-07-16 10:27:16 -0700 | [diff] [blame] | 550 | |
| 551 | EXPECT_TRUE( |
| 552 | channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| 553 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 554 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 555 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, nullptr, &capturer)); |
qiangchen | c27d89f | 2015-07-16 10:27:16 -0700 | [diff] [blame] | 556 | capturer.Start(cricket::VideoFormat(1280, 720, |
| 557 | cricket::VideoFormat::FpsToInterval(60), |
| 558 | cricket::FOURCC_I420)); |
| 559 | channel->SetSend(true); |
| 560 | |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 561 | FakeVideoSendStream* stream = fake_call->GetVideoSendStreams()[0]; |
qiangchen | c27d89f | 2015-07-16 10:27:16 -0700 | [diff] [blame] | 562 | |
| 563 | EXPECT_TRUE(capturer.CaptureFrame()); |
pbos | 1cb121d | 2015-09-14 11:38:38 -0700 | [diff] [blame] | 564 | int64_t last_timestamp = stream->GetLastTimestamp(); |
qiangchen | c27d89f | 2015-07-16 10:27:16 -0700 | [diff] [blame] | 565 | for (int i = 0; i < 10; i++) { |
| 566 | EXPECT_TRUE(capturer.CaptureFrame()); |
pbos | 1cb121d | 2015-09-14 11:38:38 -0700 | [diff] [blame] | 567 | int64_t timestamp = stream->GetLastTimestamp(); |
qiangchen | c27d89f | 2015-07-16 10:27:16 -0700 | [diff] [blame] | 568 | int64_t interval = timestamp - last_timestamp; |
| 569 | |
| 570 | // Precision changes from nanosecond to millisecond. |
| 571 | // Allow error to be no more than 1. |
| 572 | EXPECT_NEAR(cricket::VideoFormat::FpsToInterval(60) / 1E6, interval, 1); |
| 573 | |
| 574 | last_timestamp = timestamp; |
| 575 | } |
| 576 | |
| 577 | capturer.Start(cricket::VideoFormat(1280, 720, |
| 578 | cricket::VideoFormat::FpsToInterval(30), |
| 579 | cricket::FOURCC_I420)); |
| 580 | |
| 581 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 582 | last_timestamp = stream->GetLastTimestamp(); |
| 583 | for (int i = 0; i < 10; i++) { |
| 584 | EXPECT_TRUE(capturer.CaptureFrame()); |
pbos | 1cb121d | 2015-09-14 11:38:38 -0700 | [diff] [blame] | 585 | int64_t timestamp = stream->GetLastTimestamp(); |
qiangchen | c27d89f | 2015-07-16 10:27:16 -0700 | [diff] [blame] | 586 | int64_t interval = timestamp - last_timestamp; |
| 587 | |
| 588 | // Precision changes from nanosecond to millisecond. |
| 589 | // Allow error to be no more than 1. |
| 590 | EXPECT_NEAR(cricket::VideoFormat::FpsToInterval(30) / 1E6, interval, 1); |
| 591 | |
| 592 | last_timestamp = timestamp; |
| 593 | } |
| 594 | |
| 595 | // Remove stream previously added to free the external encoder instance. |
| 596 | EXPECT_TRUE(channel->RemoveSendStream(kSsrc)); |
| 597 | } |
| 598 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 599 | void WebRtcVideoEngineTest::AssignDefaultAptRtxTypes() { |
| 600 | std::vector<VideoCodec> engine_codecs = engine_.codecs(); |
| 601 | RTC_DCHECK(!engine_codecs.empty()); |
| 602 | for (const cricket::VideoCodec& codec : engine_codecs) { |
| 603 | if (codec.name == "rtx") { |
| 604 | int associated_payload_type; |
| 605 | if (codec.GetParam(kCodecParamAssociatedPayloadType, |
| 606 | &associated_payload_type)) { |
| 607 | default_apt_rtx_types_[associated_payload_type] = codec.id; |
| 608 | } |
| 609 | } |
| 610 | } |
| 611 | } |
| 612 | |
| 613 | void WebRtcVideoEngineTest::AssignDefaultCodec() { |
| 614 | std::vector<VideoCodec> engine_codecs = engine_.codecs(); |
| 615 | RTC_DCHECK(!engine_codecs.empty()); |
| 616 | bool codec_set = false; |
| 617 | for (const cricket::VideoCodec& codec : engine_codecs) { |
| 618 | if (!codec_set && codec.name != "rtx" && codec.name != "red" && |
| 619 | codec.name != "ulpfec") { |
| 620 | default_codec_ = codec; |
| 621 | codec_set = true; |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | RTC_DCHECK(codec_set); |
| 626 | } |
| 627 | |
Oleh Prypin | a40f824 | 2017-12-21 13:32:23 +0100 | [diff] [blame] | 628 | size_t WebRtcVideoEngineTest::GetEngineCodecIndex( |
| 629 | const std::string& name) const { |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 630 | const std::vector<cricket::VideoCodec> codecs = engine_.codecs(); |
| 631 | for (size_t i = 0; i < codecs.size(); ++i) { |
| 632 | const cricket::VideoCodec engine_codec = codecs[i]; |
Magnus Jedvert | 8deb818 | 2017-10-05 13:13:32 +0200 | [diff] [blame] | 633 | if (!CodecNamesEq(name, engine_codec.name)) |
| 634 | continue; |
| 635 | // The tests only use H264 Constrained Baseline. Make sure we don't return |
| 636 | // an internal H264 codec from the engine with a different H264 profile. |
| 637 | if (CodecNamesEq(name.c_str(), kH264CodecName)) { |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 638 | const absl::optional<webrtc::H264::ProfileLevelId> profile_level_id = |
Magnus Jedvert | 8deb818 | 2017-10-05 13:13:32 +0200 | [diff] [blame] | 639 | webrtc::H264::ParseSdpProfileLevelId(engine_codec.params); |
| 640 | if (profile_level_id->profile != |
| 641 | webrtc::H264::kProfileConstrainedBaseline) { |
| 642 | continue; |
| 643 | } |
| 644 | } |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 645 | return i; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 646 | } |
| 647 | // This point should never be reached. |
| 648 | ADD_FAILURE() << "Unrecognized codec name: " << name; |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 649 | return -1; |
| 650 | } |
| 651 | |
| 652 | cricket::VideoCodec WebRtcVideoEngineTest::GetEngineCodec( |
| 653 | const std::string& name) const { |
| 654 | return engine_.codecs()[GetEngineCodecIndex(name)]; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 655 | } |
| 656 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 657 | VideoMediaChannel* |
| 658 | WebRtcVideoEngineTest::SetSendParamsWithAllSupportedCodecs() { |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 659 | VideoMediaChannel* channel = |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 660 | engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions()); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 661 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 662 | // 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] | 663 | for (const webrtc::SdpVideoFormat& format : |
| 664 | encoder_factory_->GetSupportedFormats()) { |
| 665 | cricket::VideoCodec engine_codec = GetEngineCodec(format.name); |
| 666 | if (std::find(parameters.codecs.begin(), parameters.codecs.end(), |
| 667 | engine_codec) == parameters.codecs.end()) { |
| 668 | parameters.codecs.push_back(engine_codec); |
| 669 | } |
| 670 | } |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 671 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 672 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 673 | |
| 674 | return channel; |
| 675 | } |
| 676 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 677 | VideoMediaChannel* WebRtcVideoEngineTest::SetRecvParamsWithSupportedCodecs( |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 678 | const std::vector<VideoCodec>& codecs) { |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 679 | VideoMediaChannel* channel = |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 680 | engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions()); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 681 | cricket::VideoRecvParameters parameters; |
| 682 | parameters.codecs = codecs; |
| 683 | EXPECT_TRUE(channel->SetRecvParameters(parameters)); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 684 | |
| 685 | return channel; |
| 686 | } |
| 687 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 688 | TEST_F(WebRtcVideoEngineTest, UsesSimulcastAdapterForVp8Factories) { |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 689 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
pbos@webrtc.org | f18fba2 | 2015-01-14 16:26:23 +0000 | [diff] [blame] | 690 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 691 | std::unique_ptr<VideoMediaChannel> channel( |
| 692 | SetSendParamsWithAllSupportedCodecs()); |
pbos@webrtc.org | f18fba2 | 2015-01-14 16:26:23 +0000 | [diff] [blame] | 693 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 694 | std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); |
pbos@webrtc.org | f18fba2 | 2015-01-14 16:26:23 +0000 | [diff] [blame] | 695 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 696 | EXPECT_TRUE(channel->AddSendStream(CreateSimStreamParams("cname", ssrcs))); |
pbos@webrtc.org | f18fba2 | 2015-01-14 16:26:23 +0000 | [diff] [blame] | 697 | EXPECT_TRUE(channel->SetSend(true)); |
| 698 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 699 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 700 | EXPECT_TRUE(channel->SetVideoSend(ssrcs.front(), nullptr, &capturer)); |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 701 | EXPECT_EQ(cricket::CS_RUNNING, |
| 702 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 703 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 704 | |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 705 | ASSERT_TRUE(encoder_factory_->WaitForCreatedVideoEncoders(2)); |
pbos@webrtc.org | f18fba2 | 2015-01-14 16:26:23 +0000 | [diff] [blame] | 706 | |
| 707 | // Verify that encoders are configured for simulcast through adapter |
| 708 | // (increasing resolution and only configured to send one stream each). |
| 709 | int prev_width = -1; |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 710 | for (size_t i = 0; i < encoder_factory_->encoders().size(); ++i) { |
| 711 | ASSERT_TRUE(encoder_factory_->encoders()[i]->WaitForInitEncode()); |
pbos@webrtc.org | f18fba2 | 2015-01-14 16:26:23 +0000 | [diff] [blame] | 712 | webrtc::VideoCodec codec_settings = |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 713 | encoder_factory_->encoders()[i]->GetCodecSettings(); |
pbos@webrtc.org | f18fba2 | 2015-01-14 16:26:23 +0000 | [diff] [blame] | 714 | EXPECT_EQ(0, codec_settings.numberOfSimulcastStreams); |
| 715 | EXPECT_GT(codec_settings.width, prev_width); |
| 716 | prev_width = codec_settings.width; |
| 717 | } |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 718 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 719 | EXPECT_TRUE(channel->SetVideoSend(ssrcs.front(), nullptr, nullptr)); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 720 | |
| 721 | channel.reset(); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 722 | ASSERT_EQ(0u, encoder_factory_->encoders().size()); |
pbos@webrtc.org | f18fba2 | 2015-01-14 16:26:23 +0000 | [diff] [blame] | 723 | } |
| 724 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 725 | TEST_F(WebRtcVideoEngineTest, ChannelWithH264CanChangeToVp8) { |
| 726 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 727 | encoder_factory_->AddSupportedVideoCodecType("H264"); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 728 | |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 729 | // Set capturer. |
| 730 | FakeVideoCapturerWithTaskQueue capturer; |
| 731 | EXPECT_EQ(cricket::CS_RUNNING, |
| 732 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 733 | |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 734 | std::unique_ptr<VideoMediaChannel> channel( |
| 735 | engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions())); |
| 736 | cricket::VideoSendParameters parameters; |
| 737 | parameters.codecs.push_back(GetEngineCodec("H264")); |
| 738 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 739 | |
| 740 | EXPECT_TRUE( |
| 741 | channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 742 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, nullptr, &capturer)); |
| 743 | // Sending one frame will have allocate the encoder. |
| 744 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 745 | |
| 746 | ASSERT_EQ_WAIT(1u, encoder_factory_->encoders().size(), kTimeout); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 747 | |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 748 | cricket::VideoSendParameters new_parameters; |
| 749 | new_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 750 | EXPECT_TRUE(channel->SetSendParameters(new_parameters)); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 751 | |
| 752 | // Sending one frame will switch encoder. |
| 753 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 754 | |
Anders Carlsson | 8a150d9 | 2018-05-14 12:40:04 +0200 | [diff] [blame] | 755 | EXPECT_EQ_WAIT(1u, encoder_factory_->encoders().size(), kTimeout); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 756 | } |
| 757 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 758 | TEST_F(WebRtcVideoEngineTest, |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 759 | UsesSimulcastAdapterForVp8WithCombinedVP8AndH264Factory) { |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 760 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
| 761 | encoder_factory_->AddSupportedVideoCodecType("H264"); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 762 | |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 763 | std::unique_ptr<VideoMediaChannel> channel( |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 764 | engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions())); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 765 | cricket::VideoSendParameters parameters; |
| 766 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 767 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 768 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 769 | std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 770 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 771 | EXPECT_TRUE(channel->AddSendStream(CreateSimStreamParams("cname", ssrcs))); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 772 | EXPECT_TRUE(channel->SetSend(true)); |
| 773 | |
| 774 | // Send a fake frame, or else the media engine will configure the simulcast |
| 775 | // encoder adapter at a low-enough size that it'll only create a single |
| 776 | // encoder layer. |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 777 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 778 | EXPECT_TRUE(channel->SetVideoSend(ssrcs.front(), nullptr, &capturer)); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 779 | EXPECT_EQ(cricket::CS_RUNNING, |
| 780 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 781 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 782 | |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 783 | ASSERT_TRUE(encoder_factory_->WaitForCreatedVideoEncoders(2)); |
| 784 | ASSERT_TRUE(encoder_factory_->encoders()[0]->WaitForInitEncode()); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 785 | EXPECT_EQ(webrtc::kVideoCodecVP8, |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 786 | encoder_factory_->encoders()[0]->GetCodecSettings().codecType); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 787 | |
| 788 | channel.reset(); |
| 789 | // Make sure DestroyVideoEncoder was called on the factory. |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 790 | EXPECT_EQ(0u, encoder_factory_->encoders().size()); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 791 | } |
| 792 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 793 | TEST_F(WebRtcVideoEngineTest, |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 794 | DestroysNonSimulcastEncoderFromCombinedVP8AndH264Factory) { |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 795 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
| 796 | encoder_factory_->AddSupportedVideoCodecType("H264"); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 797 | |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 798 | std::unique_ptr<VideoMediaChannel> channel( |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 799 | engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions())); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 800 | cricket::VideoSendParameters parameters; |
| 801 | parameters.codecs.push_back(GetEngineCodec("H264")); |
| 802 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 803 | |
| 804 | EXPECT_TRUE( |
| 805 | channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 806 | |
| 807 | // Send a frame of 720p. This should trigger a "real" encoder initialization. |
| 808 | cricket::VideoFormat format( |
| 809 | 1280, 720, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420); |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 810 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 811 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, nullptr, &capturer)); |
Per | 21d45d2 | 2016-10-30 21:37:57 +0100 | [diff] [blame] | 812 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(format)); |
| 813 | EXPECT_TRUE(capturer.CaptureFrame()); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 814 | ASSERT_TRUE(encoder_factory_->WaitForCreatedVideoEncoders(1)); |
| 815 | ASSERT_EQ(1u, encoder_factory_->encoders().size()); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 816 | ASSERT_TRUE(encoder_factory_->encoders()[0]->WaitForInitEncode()); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 817 | EXPECT_EQ(webrtc::kVideoCodecH264, |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 818 | encoder_factory_->encoders()[0]->GetCodecSettings().codecType); |
pthatcher@webrtc.org | 818c498 | 2015-03-06 02:20:58 +0000 | [diff] [blame] | 819 | |
| 820 | channel.reset(); |
| 821 | // Make sure DestroyVideoEncoder was called on the factory. |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 822 | ASSERT_EQ(0u, encoder_factory_->encoders().size()); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 823 | } |
| 824 | |
Sergio Garcia Murillo | 43800f9 | 2018-06-21 16:16:38 +0200 | [diff] [blame] | 825 | TEST_F(WebRtcVideoEngineTest, SimulcastEnabledForH264BehindFieldTrial) { |
| 826 | webrtc::test::ScopedFieldTrials override_field_trials_( |
| 827 | "WebRTC-H264Simulcast/Enabled/"); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 828 | encoder_factory_->AddSupportedVideoCodecType("H264"); |
noahric | fdac516 | 2015-08-27 01:59:29 -0700 | [diff] [blame] | 829 | |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 830 | std::unique_ptr<VideoMediaChannel> channel( |
| 831 | engine_.CreateChannel(call_.get(), GetMediaConfig(), VideoOptions())); |
| 832 | cricket::VideoSendParameters parameters; |
| 833 | parameters.codecs.push_back(GetEngineCodec("H264")); |
| 834 | EXPECT_TRUE(channel->SetSendParameters(parameters)); |
noahric | fdac516 | 2015-08-27 01:59:29 -0700 | [diff] [blame] | 835 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 836 | const std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); |
noahric | fdac516 | 2015-08-27 01:59:29 -0700 | [diff] [blame] | 837 | EXPECT_TRUE( |
| 838 | channel->AddSendStream(cricket::CreateSimStreamParams("cname", ssrcs))); |
Peter Boström | ce23bee | 2016-02-02 14:14:30 +0100 | [diff] [blame] | 839 | |
| 840 | // Send a frame of 720p. This should trigger a "real" encoder initialization. |
noahric | fdac516 | 2015-08-27 01:59:29 -0700 | [diff] [blame] | 841 | cricket::VideoFormat format( |
| 842 | 1280, 720, cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420); |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 843 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 844 | EXPECT_TRUE(channel->SetVideoSend(ssrcs[0], nullptr, &capturer)); |
Peter Boström | ce23bee | 2016-02-02 14:14:30 +0100 | [diff] [blame] | 845 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(format)); |
| 846 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 847 | |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 848 | ASSERT_TRUE(encoder_factory_->WaitForCreatedVideoEncoders(1)); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 849 | ASSERT_EQ(1u, encoder_factory_->encoders().size()); |
| 850 | FakeWebRtcVideoEncoder* encoder = encoder_factory_->encoders()[0]; |
| 851 | ASSERT_TRUE(encoder_factory_->encoders()[0]->WaitForInitEncode()); |
noahric | fdac516 | 2015-08-27 01:59:29 -0700 | [diff] [blame] | 852 | EXPECT_EQ(webrtc::kVideoCodecH264, encoder->GetCodecSettings().codecType); |
Sergio Garcia Murillo | 43800f9 | 2018-06-21 16:16:38 +0200 | [diff] [blame] | 853 | EXPECT_LT(1u, encoder->GetCodecSettings().numberOfSimulcastStreams); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 854 | EXPECT_TRUE(channel->SetVideoSend(ssrcs[0], nullptr, nullptr)); |
noahric | fdac516 | 2015-08-27 01:59:29 -0700 | [diff] [blame] | 855 | } |
| 856 | |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 857 | // Test that the FlexFEC field trial properly alters the output of |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 858 | // WebRtcVideoEngine::codecs(), for an existing |engine_| object. |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 859 | // |
| 860 | // TODO(brandtr): Remove this test, when the FlexFEC field trial is gone. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 861 | TEST_F(WebRtcVideoEngineTest, |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 862 | Flexfec03SupportedAsInternalCodecBehindFieldTrial) { |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 863 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
| 864 | |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 865 | auto is_flexfec = [](const VideoCodec& codec) { |
| 866 | if (codec.name == "flexfec-03") |
| 867 | return true; |
| 868 | return false; |
| 869 | }; |
| 870 | |
| 871 | // FlexFEC is not active without field trial. |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 872 | const std::vector<VideoCodec> codecs_before = engine_.codecs(); |
| 873 | EXPECT_EQ(codecs_before.end(), std::find_if(codecs_before.begin(), |
| 874 | codecs_before.end(), is_flexfec)); |
| 875 | |
| 876 | // FlexFEC is active with field trial. |
| 877 | webrtc::test::ScopedFieldTrials override_field_trials_( |
brandtr | 340e3fd | 2017-02-28 15:43:10 -0800 | [diff] [blame] | 878 | "WebRTC-FlexFEC-03-Advertised/Enabled/"); |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 879 | const std::vector<VideoCodec> codecs_after = engine_.codecs(); |
| 880 | EXPECT_NE(codecs_after.end(), |
| 881 | std::find_if(codecs_after.begin(), codecs_after.end(), is_flexfec)); |
| 882 | } |
| 883 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 884 | // Test that codecs are added in the order they are reported from the factory. |
| 885 | TEST_F(WebRtcVideoEngineTest, ReportSupportedCodecs) { |
| 886 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
| 887 | const char* kFakeCodecName = "FakeCodec"; |
| 888 | encoder_factory_->AddSupportedVideoCodecType(kFakeCodecName); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 889 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 890 | // 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] | 891 | const size_t vp8_index = GetEngineCodecIndex("VP8"); |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 892 | const size_t fake_codec_index = GetEngineCodecIndex(kFakeCodecName); |
| 893 | EXPECT_LT(vp8_index, fake_codec_index); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 894 | } |
| 895 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 896 | // Test that a codec that was added after the engine was initialized |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 897 | // does show up in the codec list after it was added. |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 898 | TEST_F(WebRtcVideoEngineTest, ReportSupportedAddedCodec) { |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 899 | const char* kFakeExternalCodecName1 = "FakeExternalCodec1"; |
| 900 | const char* kFakeExternalCodecName2 = "FakeExternalCodec2"; |
Magnus Jedvert | 154ee1f | 2017-11-15 19:27:11 +0100 | [diff] [blame] | 901 | |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 902 | // Set up external encoder factory with first codec, and initialize engine. |
| 903 | encoder_factory_->AddSupportedVideoCodecType(kFakeExternalCodecName1); |
| 904 | |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 905 | std::vector<cricket::VideoCodec> codecs_before(engine_.codecs()); |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 906 | |
| 907 | // Add second codec. |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 908 | encoder_factory_->AddSupportedVideoCodecType(kFakeExternalCodecName2); |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 909 | std::vector<cricket::VideoCodec> codecs_after(engine_.codecs()); |
Sami Kalliomäki | e9a18b2 | 2018-07-13 10:28:21 +0200 | [diff] [blame] | 910 | // The codec itself and RTX should have been added. |
| 911 | EXPECT_EQ(codecs_before.size() + 2, codecs_after.size()); |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 912 | |
| 913 | // Check that both fake codecs are present and that the second fake codec |
| 914 | // appears after the first fake codec. |
Oleh Prypin | a40f824 | 2017-12-21 13:32:23 +0100 | [diff] [blame] | 915 | const size_t fake_codec_index1 = GetEngineCodecIndex(kFakeExternalCodecName1); |
| 916 | const size_t fake_codec_index2 = GetEngineCodecIndex(kFakeExternalCodecName2); |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 917 | EXPECT_LT(fake_codec_index1, fake_codec_index2); |
brandtr | ffc6118 | 2016-11-28 06:02:22 -0800 | [diff] [blame] | 918 | } |
| 919 | |
Sami Kalliomäki | e9a18b2 | 2018-07-13 10:28:21 +0200 | [diff] [blame] | 920 | TEST_F(WebRtcVideoEngineTest, ReportRtxForExternalCodec) { |
| 921 | const char* kFakeCodecName = "FakeCodec"; |
| 922 | encoder_factory_->AddSupportedVideoCodecType(kFakeCodecName); |
| 923 | |
| 924 | const size_t fake_codec_index = GetEngineCodecIndex(kFakeCodecName); |
| 925 | EXPECT_EQ("rtx", engine_.codecs().at(fake_codec_index + 1).name); |
| 926 | } |
| 927 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 928 | TEST_F(WebRtcVideoEngineTest, RegisterDecodersIfSupported) { |
| 929 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 930 | decoder_factory_->AddSupportedVideoCodecType(webrtc::SdpVideoFormat("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 931 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 932 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 933 | |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 934 | std::unique_ptr<VideoMediaChannel> channel( |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 935 | SetRecvParamsWithSupportedCodecs(parameters.codecs)); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 936 | |
| 937 | EXPECT_TRUE( |
| 938 | channel->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 939 | ASSERT_EQ(1u, decoder_factory_->decoders().size()); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 940 | |
| 941 | // Setting codecs of the same type should not reallocate the decoder. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 942 | EXPECT_TRUE(channel->SetRecvParameters(parameters)); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 943 | EXPECT_EQ(1, decoder_factory_->GetNumCreatedDecoders()); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 944 | |
| 945 | // Remove stream previously added to free the external decoder instance. |
| 946 | EXPECT_TRUE(channel->RemoveRecvStream(kSsrc)); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 947 | EXPECT_EQ(0u, decoder_factory_->decoders().size()); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 948 | } |
| 949 | |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 950 | // Verifies that we can set up decoders. |
| 951 | TEST_F(WebRtcVideoEngineTest, RegisterH264DecoderIfSupported) { |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 952 | // TODO(pbos): Do not assume that encoder/decoder support is symmetric. We |
| 953 | // can't even query the WebRtcVideoDecoderFactory for supported codecs. |
| 954 | // For now we add a FakeWebRtcVideoEncoderFactory to add H264 to supported |
| 955 | // codecs. |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 956 | encoder_factory_->AddSupportedVideoCodecType("H264"); |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 957 | decoder_factory_->AddSupportedVideoCodecType(webrtc::SdpVideoFormat("H264")); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 958 | std::vector<cricket::VideoCodec> codecs; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 959 | codecs.push_back(GetEngineCodec("H264")); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 960 | |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 961 | std::unique_ptr<VideoMediaChannel> channel( |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 962 | SetRecvParamsWithSupportedCodecs(codecs)); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 963 | |
| 964 | EXPECT_TRUE( |
| 965 | channel->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 966 | ASSERT_EQ(1u, decoder_factory_->decoders().size()); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 967 | } |
| 968 | |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame^] | 969 | // Tests when GetSources is called with non-existing ssrc, it will return an |
| 970 | // empty list of RtpSource without crashing. |
| 971 | TEST_F(WebRtcVideoEngineTest, GetSourcesWithNonExistingSsrc) { |
| 972 | // Setup an recv stream with |kSsrc|. |
| 973 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
| 974 | decoder_factory_->AddSupportedVideoCodecType(webrtc::SdpVideoFormat("VP8")); |
| 975 | cricket::VideoRecvParameters parameters; |
| 976 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 977 | std::unique_ptr<VideoMediaChannel> channel( |
| 978 | SetRecvParamsWithSupportedCodecs(parameters.codecs)); |
| 979 | |
| 980 | EXPECT_TRUE( |
| 981 | channel->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| 982 | |
| 983 | // Call GetSources with |kSsrc + 1| which doesn't exist. |
| 984 | std::vector<webrtc::RtpSource> sources = channel->GetSources(kSsrc + 1); |
| 985 | EXPECT_EQ(0u, sources.size()); |
| 986 | } |
| 987 | |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 988 | TEST(WebRtcVideoEngineNewVideoCodecFactoryTest, NullFactories) { |
| 989 | std::unique_ptr<webrtc::VideoEncoderFactory> encoder_factory; |
| 990 | std::unique_ptr<webrtc::VideoDecoderFactory> decoder_factory; |
| 991 | WebRtcVideoEngine engine(std::move(encoder_factory), |
| 992 | std::move(decoder_factory)); |
| 993 | EXPECT_EQ(0u, engine.codecs().size()); |
| 994 | } |
| 995 | |
| 996 | TEST(WebRtcVideoEngineNewVideoCodecFactoryTest, EmptyFactories) { |
| 997 | // |engine| take ownership of the factories. |
Emircan Uysaler | dbcac7f | 2017-10-30 23:10:12 -0700 | [diff] [blame] | 998 | webrtc::MockVideoEncoderFactory* encoder_factory = |
| 999 | new webrtc::MockVideoEncoderFactory(); |
| 1000 | webrtc::MockVideoDecoderFactory* decoder_factory = |
| 1001 | new webrtc::MockVideoDecoderFactory(); |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 1002 | WebRtcVideoEngine engine( |
| 1003 | (std::unique_ptr<webrtc::VideoEncoderFactory>(encoder_factory)), |
| 1004 | (std::unique_ptr<webrtc::VideoDecoderFactory>(decoder_factory))); |
| 1005 | EXPECT_CALL(*encoder_factory, GetSupportedFormats()); |
| 1006 | EXPECT_EQ(0u, engine.codecs().size()); |
| 1007 | EXPECT_CALL(*encoder_factory, Die()); |
| 1008 | EXPECT_CALL(*decoder_factory, Die()); |
| 1009 | } |
| 1010 | |
| 1011 | // Test full behavior in the video engine when video codec factories of the new |
| 1012 | // type are injected supporting the single codec Vp8. Check the returned codecs |
| 1013 | // from the engine and that we will create a Vp8 encoder and decoder using the |
| 1014 | // new factories. |
| 1015 | TEST(WebRtcVideoEngineNewVideoCodecFactoryTest, Vp8) { |
| 1016 | // |engine| take ownership of the factories. |
Emircan Uysaler | dbcac7f | 2017-10-30 23:10:12 -0700 | [diff] [blame] | 1017 | webrtc::MockVideoEncoderFactory* encoder_factory = |
| 1018 | new webrtc::MockVideoEncoderFactory(); |
| 1019 | webrtc::MockVideoDecoderFactory* decoder_factory = |
| 1020 | new webrtc::MockVideoDecoderFactory(); |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 1021 | WebRtcVideoEngine engine( |
| 1022 | (std::unique_ptr<webrtc::VideoEncoderFactory>(encoder_factory)), |
| 1023 | (std::unique_ptr<webrtc::VideoDecoderFactory>(decoder_factory))); |
| 1024 | const webrtc::SdpVideoFormat vp8_format("VP8"); |
| 1025 | const std::vector<webrtc::SdpVideoFormat> supported_formats = {vp8_format}; |
| 1026 | EXPECT_CALL(*encoder_factory, GetSupportedFormats()) |
| 1027 | .WillRepeatedly(testing::Return(supported_formats)); |
| 1028 | |
| 1029 | // Verify the codecs from the engine. |
| 1030 | const std::vector<VideoCodec> engine_codecs = engine.codecs(); |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 1031 | // Verify default codecs has been added correctly. |
| 1032 | EXPECT_EQ(5u, engine_codecs.size()); |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 1033 | EXPECT_EQ("VP8", engine_codecs.at(0).name); |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 1034 | |
| 1035 | // RTX codec for VP8. |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 1036 | EXPECT_EQ("rtx", engine_codecs.at(1).name); |
Magnus Jedvert | 9b16e2d | 2017-11-18 12:08:55 +0100 | [diff] [blame] | 1037 | int vp8_associated_payload; |
| 1038 | EXPECT_TRUE(engine_codecs.at(1).GetParam(kCodecParamAssociatedPayloadType, |
| 1039 | &vp8_associated_payload)); |
| 1040 | EXPECT_EQ(vp8_associated_payload, engine_codecs.at(0).id); |
| 1041 | |
| 1042 | EXPECT_EQ(kRedCodecName, engine_codecs.at(2).name); |
| 1043 | |
| 1044 | // RTX codec for RED. |
| 1045 | EXPECT_EQ("rtx", engine_codecs.at(3).name); |
| 1046 | int red_associated_payload; |
| 1047 | EXPECT_TRUE(engine_codecs.at(3).GetParam(kCodecParamAssociatedPayloadType, |
| 1048 | &red_associated_payload)); |
| 1049 | EXPECT_EQ(red_associated_payload, engine_codecs.at(2).id); |
| 1050 | |
| 1051 | EXPECT_EQ(kUlpfecCodecName, engine_codecs.at(4).name); |
| 1052 | |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 1053 | int associated_payload_type; |
| 1054 | EXPECT_TRUE(engine_codecs.at(1).GetParam( |
| 1055 | cricket::kCodecParamAssociatedPayloadType, &associated_payload_type)); |
| 1056 | EXPECT_EQ(engine_codecs.at(0).id, associated_payload_type); |
| 1057 | // Verify default parameters has been added to the VP8 codec. |
| 1058 | VerifyCodecHasDefaultFeedbackParams(engine_codecs.at(0)); |
| 1059 | |
| 1060 | // Mock encoder creation. |engine| take ownership of the encoder. |
| 1061 | webrtc::VideoEncoderFactory::CodecInfo codec_info; |
| 1062 | codec_info.is_hardware_accelerated = false; |
| 1063 | codec_info.has_internal_source = false; |
| 1064 | const webrtc::SdpVideoFormat format("VP8"); |
| 1065 | EXPECT_CALL(*encoder_factory, QueryVideoEncoder(format)) |
| 1066 | .WillRepeatedly(testing::Return(codec_info)); |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 1067 | FakeWebRtcVideoEncoder* const encoder = new FakeWebRtcVideoEncoder(nullptr); |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 1068 | rtc::Event encoder_created(false, false); |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 1069 | EXPECT_CALL(*encoder_factory, CreateVideoEncoderProxy(format)) |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 1070 | .WillOnce( |
| 1071 | ::testing::DoAll(::testing::InvokeWithoutArgs( |
| 1072 | [&encoder_created]() { encoder_created.Set(); }), |
| 1073 | ::testing::Return(encoder))); |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 1074 | |
| 1075 | // Mock decoder creation. |engine| take ownership of the decoder. |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 1076 | FakeWebRtcVideoDecoder* const decoder = new FakeWebRtcVideoDecoder(nullptr); |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 1077 | EXPECT_CALL(*decoder_factory, CreateVideoDecoderProxy(format)) |
| 1078 | .WillOnce(testing::Return(decoder)); |
| 1079 | |
| 1080 | // Create a call. |
| 1081 | webrtc::RtcEventLogNullImpl event_log; |
| 1082 | std::unique_ptr<webrtc::Call> call( |
| 1083 | webrtc::Call::Create(webrtc::Call::Config(&event_log))); |
| 1084 | |
| 1085 | // Create send channel. |
| 1086 | const int send_ssrc = 123; |
| 1087 | std::unique_ptr<VideoMediaChannel> send_channel( |
| 1088 | engine.CreateChannel(call.get(), GetMediaConfig(), VideoOptions())); |
| 1089 | cricket::VideoSendParameters send_parameters; |
| 1090 | send_parameters.codecs.push_back(engine_codecs.at(0)); |
| 1091 | EXPECT_TRUE(send_channel->SetSendParameters(send_parameters)); |
| 1092 | send_channel->OnReadyToSend(true); |
| 1093 | EXPECT_TRUE( |
| 1094 | send_channel->AddSendStream(StreamParams::CreateLegacy(send_ssrc))); |
| 1095 | EXPECT_TRUE(send_channel->SetSend(true)); |
| 1096 | |
Niels Möller | 4db138e | 2018-04-19 09:04:13 +0200 | [diff] [blame] | 1097 | // Set capturer. |
| 1098 | FakeVideoCapturerWithTaskQueue capturer; |
| 1099 | EXPECT_EQ(cricket::CS_RUNNING, |
| 1100 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 1101 | EXPECT_TRUE(send_channel->SetVideoSend(send_ssrc, nullptr, &capturer)); |
| 1102 | // Sending one frame will allocate the encoder. |
| 1103 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 1104 | encoder_created.Wait(kTimeout); |
| 1105 | |
Magnus Jedvert | d4b0c05 | 2017-09-14 10:24:54 +0200 | [diff] [blame] | 1106 | // Create recv channel. |
| 1107 | const int recv_ssrc = 321; |
| 1108 | std::unique_ptr<VideoMediaChannel> recv_channel( |
| 1109 | engine.CreateChannel(call.get(), GetMediaConfig(), VideoOptions())); |
| 1110 | cricket::VideoRecvParameters recv_parameters; |
| 1111 | recv_parameters.codecs.push_back(engine_codecs.at(0)); |
| 1112 | EXPECT_TRUE(recv_channel->SetRecvParameters(recv_parameters)); |
| 1113 | EXPECT_TRUE(recv_channel->AddRecvStream( |
| 1114 | cricket::StreamParams::CreateLegacy(recv_ssrc))); |
| 1115 | |
| 1116 | // Remove streams previously added to free the encoder and decoder instance. |
| 1117 | EXPECT_CALL(*encoder_factory, Die()); |
| 1118 | EXPECT_CALL(*decoder_factory, Die()); |
| 1119 | EXPECT_TRUE(send_channel->RemoveSendStream(send_ssrc)); |
| 1120 | EXPECT_TRUE(recv_channel->RemoveRecvStream(recv_ssrc)); |
| 1121 | } |
| 1122 | |
Magnus Jedvert | 7501b1c | 2017-11-09 13:43:42 +0100 | [diff] [blame] | 1123 | // Test behavior when decoder factory fails to create a decoder (returns null). |
| 1124 | TEST(WebRtcVideoEngineNewVideoCodecFactoryTest, NullDecoder) { |
| 1125 | // |engine| take ownership of the factories. |
| 1126 | webrtc::MockVideoEncoderFactory* encoder_factory = |
| 1127 | new testing::StrictMock<webrtc::MockVideoEncoderFactory>(); |
| 1128 | webrtc::MockVideoDecoderFactory* decoder_factory = |
| 1129 | new testing::StrictMock<webrtc::MockVideoDecoderFactory>(); |
| 1130 | WebRtcVideoEngine engine( |
| 1131 | (std::unique_ptr<webrtc::VideoEncoderFactory>(encoder_factory)), |
| 1132 | (std::unique_ptr<webrtc::VideoDecoderFactory>(decoder_factory))); |
| 1133 | const webrtc::SdpVideoFormat vp8_format("VP8"); |
| 1134 | const std::vector<webrtc::SdpVideoFormat> supported_formats = {vp8_format}; |
| 1135 | EXPECT_CALL(*encoder_factory, GetSupportedFormats()) |
| 1136 | .WillRepeatedly(testing::Return(supported_formats)); |
| 1137 | |
| 1138 | // Decoder creation fails. |
| 1139 | EXPECT_CALL(*decoder_factory, CreateVideoDecoderProxy(testing::_)) |
| 1140 | .WillOnce(testing::Return(nullptr)); |
| 1141 | |
| 1142 | // Create a call. |
| 1143 | webrtc::RtcEventLogNullImpl event_log; |
| 1144 | std::unique_ptr<webrtc::Call> call( |
| 1145 | webrtc::Call::Create(webrtc::Call::Config(&event_log))); |
| 1146 | |
| 1147 | // Create recv channel. |
| 1148 | const int recv_ssrc = 321; |
| 1149 | std::unique_ptr<VideoMediaChannel> recv_channel( |
| 1150 | engine.CreateChannel(call.get(), GetMediaConfig(), VideoOptions())); |
| 1151 | cricket::VideoRecvParameters recv_parameters; |
| 1152 | recv_parameters.codecs.push_back(engine.codecs().front()); |
| 1153 | EXPECT_TRUE(recv_channel->SetRecvParameters(recv_parameters)); |
| 1154 | EXPECT_TRUE(recv_channel->AddRecvStream( |
| 1155 | cricket::StreamParams::CreateLegacy(recv_ssrc))); |
| 1156 | |
| 1157 | // Remove streams previously added to free the encoder and decoder instance. |
| 1158 | EXPECT_TRUE(recv_channel->RemoveRecvStream(recv_ssrc)); |
| 1159 | } |
| 1160 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 1161 | TEST_F(WebRtcVideoEngineTest, DISABLED_RecreatesEncoderOnContentTypeChange) { |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 1162 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 1163 | std::unique_ptr<FakeCall> fake_call(new FakeCall()); |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 1164 | std::unique_ptr<VideoMediaChannel> channel( |
| 1165 | SetSendParamsWithAllSupportedCodecs()); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1166 | ASSERT_TRUE( |
| 1167 | channel->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
| 1168 | cricket::VideoCodec codec = GetEngineCodec("VP8"); |
| 1169 | cricket::VideoSendParameters parameters; |
| 1170 | parameters.codecs.push_back(codec); |
| 1171 | channel->OnReadyToSend(true); |
| 1172 | channel->SetSend(true); |
| 1173 | ASSERT_TRUE(channel->SetSendParameters(parameters)); |
| 1174 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 1175 | FakeVideoCapturerWithTaskQueue capturer; |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1176 | VideoOptions options; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 1177 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, &options, &capturer)); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1178 | |
| 1179 | EXPECT_EQ(cricket::CS_RUNNING, |
| 1180 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 1181 | EXPECT_TRUE(capturer.CaptureFrame()); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 1182 | ASSERT_TRUE(encoder_factory_->WaitForCreatedVideoEncoders(1)); |
Niels Möller | e3cf3d0 | 2018-06-13 11:52:16 +0200 | [diff] [blame] | 1183 | EXPECT_EQ(webrtc::VideoCodecMode::kRealtimeVideo, |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 1184 | encoder_factory_->encoders().back()->GetCodecSettings().mode); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1185 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 1186 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, &options, &capturer)); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1187 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 1188 | // No change in content type, keep current encoder. |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 1189 | EXPECT_EQ(1, encoder_factory_->GetNumCreatedEncoders()); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1190 | |
| 1191 | options.is_screencast.emplace(true); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 1192 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, &options, &capturer)); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1193 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 1194 | // Change to screen content, recreate encoder. For the simulcast encoder |
| 1195 | // adapter case, this will result in two calls since InitEncode triggers a |
| 1196 | // a new instance. |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 1197 | ASSERT_TRUE(encoder_factory_->WaitForCreatedVideoEncoders(2)); |
Niels Möller | e3cf3d0 | 2018-06-13 11:52:16 +0200 | [diff] [blame] | 1198 | EXPECT_EQ(webrtc::VideoCodecMode::kScreensharing, |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 1199 | encoder_factory_->encoders().back()->GetCodecSettings().mode); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1200 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 1201 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, &options, &capturer)); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1202 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 1203 | // Still screen content, no need to update encoder. |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 1204 | EXPECT_EQ(2, encoder_factory_->GetNumCreatedEncoders()); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1205 | |
| 1206 | options.is_screencast.emplace(false); |
| 1207 | options.video_noise_reduction.emplace(false); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 1208 | EXPECT_TRUE(channel->SetVideoSend(kSsrc, &options, &capturer)); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1209 | // Change back to regular video content, update encoder. Also change |
| 1210 | // a non |is_screencast| option just to verify it doesn't affect recreation. |
| 1211 | EXPECT_TRUE(capturer.CaptureFrame()); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 1212 | ASSERT_TRUE(encoder_factory_->WaitForCreatedVideoEncoders(3)); |
Niels Möller | e3cf3d0 | 2018-06-13 11:52:16 +0200 | [diff] [blame] | 1213 | EXPECT_EQ(webrtc::VideoCodecMode::kRealtimeVideo, |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 1214 | encoder_factory_->encoders().back()->GetCodecSettings().mode); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1215 | |
| 1216 | // Remove stream previously added to free the external encoder instance. |
| 1217 | EXPECT_TRUE(channel->RemoveSendStream(kSsrc)); |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 1218 | EXPECT_EQ(0u, encoder_factory_->encoders().size()); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 1219 | } |
| 1220 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1221 | class WebRtcVideoChannelBaseTest : public testing::Test { |
| 1222 | protected: |
| 1223 | WebRtcVideoChannelBaseTest() |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame^] | 1224 | : engine_(webrtc::CreateBuiltinVideoEncoderFactory(), |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 1225 | webrtc::CreateBuiltinVideoDecoderFactory()) {} |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1226 | |
| 1227 | virtual void SetUp() { |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame^] | 1228 | // One testcase calls SetUp in a loop, only create call_ once. |
| 1229 | if (!call_) { |
| 1230 | call_.reset(webrtc::Call::Create(webrtc::Call::Config(&event_log_))); |
| 1231 | } |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1232 | cricket::MediaConfig media_config; |
| 1233 | // Disabling cpu overuse detection actually disables quality scaling too; it |
| 1234 | // implies DegradationPreference kMaintainResolution. Automatic scaling |
| 1235 | // needs to be disabled, otherwise, tests which check the size of received |
| 1236 | // frames become flaky. |
| 1237 | media_config.video.enable_cpu_adaptation = false; |
| 1238 | channel_.reset(engine_.CreateChannel(call_.get(), media_config, |
| 1239 | cricket::VideoOptions())); |
| 1240 | channel_->OnReadyToSend(true); |
| 1241 | EXPECT_TRUE(channel_.get() != NULL); |
| 1242 | network_interface_.SetDestination(channel_.get()); |
| 1243 | channel_->SetInterface(&network_interface_); |
| 1244 | cricket::VideoRecvParameters parameters; |
| 1245 | parameters.codecs = engine_.codecs(); |
| 1246 | channel_->SetRecvParameters(parameters); |
| 1247 | EXPECT_TRUE(channel_->AddSendStream(DefaultSendStreamParams())); |
| 1248 | video_capturer_.reset(CreateFakeVideoCapturer()); |
| 1249 | cricket::VideoFormat format(640, 480, |
| 1250 | cricket::VideoFormat::FpsToInterval(kFramerate), |
| 1251 | cricket::FOURCC_I420); |
| 1252 | EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(format)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1253 | EXPECT_TRUE(channel_->SetVideoSend(kSsrc, nullptr, video_capturer_.get())); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | virtual cricket::FakeVideoCapturerWithTaskQueue* CreateFakeVideoCapturer() { |
| 1257 | return new cricket::FakeVideoCapturerWithTaskQueue(); |
| 1258 | } |
| 1259 | |
| 1260 | // Utility method to setup an additional stream to send and receive video. |
| 1261 | // Used to test send and recv between two streams. |
| 1262 | void SetUpSecondStream() { |
| 1263 | SetUpSecondStreamWithNoRecv(); |
| 1264 | // Setup recv for second stream. |
| 1265 | EXPECT_TRUE(channel_->AddRecvStream( |
| 1266 | cricket::StreamParams::CreateLegacy(kSsrc + 2))); |
| 1267 | // Make the second renderer available for use by a new stream. |
| 1268 | EXPECT_TRUE(channel_->SetSink(kSsrc + 2, &renderer2_)); |
| 1269 | } |
| 1270 | // Setup an additional stream just to send video. Defer add recv stream. |
| 1271 | // This is required if you want to test unsignalled recv of video rtp packets. |
| 1272 | void SetUpSecondStreamWithNoRecv() { |
| 1273 | // SetUp() already added kSsrc make sure duplicate SSRCs cant be added. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1274 | EXPECT_TRUE( |
| 1275 | channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1276 | EXPECT_TRUE(channel_->SetSink(kSsrc, &renderer_)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1277 | EXPECT_FALSE( |
| 1278 | channel_->AddSendStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1279 | EXPECT_TRUE(channel_->AddSendStream( |
| 1280 | cricket::StreamParams::CreateLegacy(kSsrc + 2))); |
| 1281 | // We dont add recv for the second stream. |
| 1282 | |
| 1283 | // Setup the receive and renderer for second stream after send. |
| 1284 | video_capturer_2_.reset(CreateFakeVideoCapturer()); |
| 1285 | cricket::VideoFormat format(640, 480, |
| 1286 | cricket::VideoFormat::FpsToInterval(kFramerate), |
| 1287 | cricket::FOURCC_I420); |
| 1288 | EXPECT_EQ(cricket::CS_RUNNING, video_capturer_2_->Start(format)); |
| 1289 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1290 | EXPECT_TRUE( |
| 1291 | channel_->SetVideoSend(kSsrc + 2, nullptr, video_capturer_2_.get())); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1292 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1293 | virtual void TearDown() { channel_.reset(); } |
| 1294 | bool SetDefaultCodec() { return SetOneCodec(DefaultCodec()); } |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1295 | |
| 1296 | bool SetOneCodec(const cricket::VideoCodec& codec) { |
| 1297 | cricket::VideoFormat capture_format( |
| 1298 | kVideoWidth, kVideoHeight, |
| 1299 | cricket::VideoFormat::FpsToInterval(kFramerate), cricket::FOURCC_I420); |
| 1300 | |
| 1301 | if (video_capturer_) { |
| 1302 | EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(capture_format)); |
| 1303 | } |
| 1304 | if (video_capturer_2_) { |
| 1305 | EXPECT_EQ(cricket::CS_RUNNING, video_capturer_2_->Start(capture_format)); |
| 1306 | } |
| 1307 | |
| 1308 | bool sending = channel_->sending(); |
| 1309 | bool success = SetSend(false); |
| 1310 | if (success) { |
| 1311 | cricket::VideoSendParameters parameters; |
| 1312 | parameters.codecs.push_back(codec); |
| 1313 | success = channel_->SetSendParameters(parameters); |
| 1314 | } |
| 1315 | if (success) { |
| 1316 | success = SetSend(sending); |
| 1317 | } |
| 1318 | return success; |
| 1319 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1320 | bool SetSend(bool send) { return channel_->SetSend(send); } |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1321 | bool SendFrame() { |
| 1322 | if (video_capturer_2_) { |
| 1323 | video_capturer_2_->CaptureFrame(); |
| 1324 | } |
| 1325 | return video_capturer_.get() && video_capturer_->CaptureFrame(); |
| 1326 | } |
| 1327 | bool WaitAndSendFrame(int wait_ms) { |
| 1328 | bool ret = rtc::Thread::Current()->ProcessMessages(wait_ms); |
| 1329 | ret &= SendFrame(); |
| 1330 | return ret; |
| 1331 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1332 | int NumRtpBytes() { return network_interface_.NumRtpBytes(); } |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1333 | int NumRtpBytes(uint32_t ssrc) { |
| 1334 | return network_interface_.NumRtpBytes(ssrc); |
| 1335 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1336 | int NumRtpPackets() { return network_interface_.NumRtpPackets(); } |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1337 | int NumRtpPackets(uint32_t ssrc) { |
| 1338 | return network_interface_.NumRtpPackets(ssrc); |
| 1339 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1340 | int NumSentSsrcs() { return network_interface_.NumSentSsrcs(); } |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1341 | const rtc::CopyOnWriteBuffer* GetRtpPacket(int index) { |
| 1342 | return network_interface_.GetRtpPacket(index); |
| 1343 | } |
| 1344 | static int GetPayloadType(const rtc::CopyOnWriteBuffer* p) { |
Åsa Persson | 23cd45a | 2018-07-03 10:40:40 +0200 | [diff] [blame] | 1345 | webrtc::RTPHeader header; |
| 1346 | EXPECT_TRUE(ParseRtpPacket(p, &header)); |
| 1347 | return header.payloadType; |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1348 | } |
Åsa Persson | 23cd45a | 2018-07-03 10:40:40 +0200 | [diff] [blame] | 1349 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1350 | static bool ParseRtpPacket(const rtc::CopyOnWriteBuffer* p, |
Åsa Persson | 23cd45a | 2018-07-03 10:40:40 +0200 | [diff] [blame] | 1351 | webrtc::RTPHeader* header) { |
| 1352 | std::unique_ptr<webrtc::RtpHeaderParser> parser( |
| 1353 | webrtc::RtpHeaderParser::Create()); |
| 1354 | return parser->Parse(p->cdata(), p->size(), header); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1355 | } |
| 1356 | |
| 1357 | // Tests that we can send and receive frames. |
| 1358 | void SendAndReceive(const cricket::VideoCodec& codec) { |
| 1359 | EXPECT_TRUE(SetOneCodec(codec)); |
| 1360 | EXPECT_TRUE(SetSend(true)); |
| 1361 | EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); |
| 1362 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 1363 | EXPECT_TRUE(SendFrame()); |
| 1364 | EXPECT_FRAME_WAIT(1, kVideoWidth, kVideoHeight, kTimeout); |
| 1365 | std::unique_ptr<const rtc::CopyOnWriteBuffer> p(GetRtpPacket(0)); |
| 1366 | EXPECT_EQ(codec.id, GetPayloadType(p.get())); |
| 1367 | } |
| 1368 | |
| 1369 | void SendReceiveManyAndGetStats(const cricket::VideoCodec& codec, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1370 | int duration_sec, |
| 1371 | int fps) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1372 | EXPECT_TRUE(SetOneCodec(codec)); |
| 1373 | EXPECT_TRUE(SetSend(true)); |
| 1374 | EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); |
| 1375 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 1376 | for (int i = 0; i < duration_sec; ++i) { |
| 1377 | for (int frame = 1; frame <= fps; ++frame) { |
| 1378 | EXPECT_TRUE(WaitAndSendFrame(1000 / fps)); |
| 1379 | EXPECT_FRAME_WAIT(frame + i * fps, kVideoWidth, kVideoHeight, kTimeout); |
| 1380 | } |
| 1381 | } |
| 1382 | std::unique_ptr<const rtc::CopyOnWriteBuffer> p(GetRtpPacket(0)); |
| 1383 | EXPECT_EQ(codec.id, GetPayloadType(p.get())); |
| 1384 | } |
| 1385 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1386 | cricket::VideoSenderInfo GetSenderStats(size_t i) { |
| 1387 | cricket::VideoMediaInfo info; |
| 1388 | EXPECT_TRUE(channel_->GetStats(&info)); |
| 1389 | return info.senders[i]; |
| 1390 | } |
| 1391 | |
| 1392 | cricket::VideoReceiverInfo GetReceiverStats(size_t i) { |
| 1393 | cricket::VideoMediaInfo info; |
| 1394 | EXPECT_TRUE(channel_->GetStats(&info)); |
| 1395 | return info.receivers[i]; |
| 1396 | } |
| 1397 | |
| 1398 | // Two streams one channel tests. |
| 1399 | |
| 1400 | // Tests that we can send and receive frames. |
| 1401 | void TwoStreamsSendAndReceive(const cricket::VideoCodec& codec) { |
| 1402 | SetUpSecondStream(); |
| 1403 | // Test sending and receiving on first stream. |
| 1404 | SendAndReceive(codec); |
| 1405 | // Test sending and receiving on second stream. |
| 1406 | EXPECT_EQ_WAIT(1, renderer2_.num_rendered_frames(), kTimeout); |
| 1407 | EXPECT_GT(NumRtpPackets(), 0); |
| 1408 | EXPECT_EQ(1, renderer2_.num_rendered_frames()); |
| 1409 | } |
| 1410 | |
| 1411 | cricket::VideoCodec GetEngineCodec(const std::string& name) { |
| 1412 | for (const cricket::VideoCodec& engine_codec : engine_.codecs()) { |
| 1413 | if (CodecNamesEq(name, engine_codec.name)) |
| 1414 | return engine_codec; |
| 1415 | } |
| 1416 | // This point should never be reached. |
| 1417 | ADD_FAILURE() << "Unrecognized codec name: " << name; |
| 1418 | return cricket::VideoCodec(); |
| 1419 | } |
| 1420 | |
| 1421 | cricket::VideoCodec DefaultCodec() { return GetEngineCodec("VP8"); } |
| 1422 | |
| 1423 | cricket::StreamParams DefaultSendStreamParams() { |
| 1424 | return cricket::StreamParams::CreateLegacy(kSsrc); |
| 1425 | } |
| 1426 | |
| 1427 | webrtc::RtcEventLogNullImpl event_log_; |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame^] | 1428 | std::unique_ptr<webrtc::Call> call_; |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1429 | WebRtcVideoEngine engine_; |
| 1430 | std::unique_ptr<cricket::FakeVideoCapturerWithTaskQueue> video_capturer_; |
| 1431 | std::unique_ptr<cricket::FakeVideoCapturerWithTaskQueue> video_capturer_2_; |
| 1432 | std::unique_ptr<WebRtcVideoChannel> channel_; |
| 1433 | cricket::FakeNetworkInterface network_interface_; |
| 1434 | cricket::FakeVideoRenderer renderer_; |
| 1435 | |
| 1436 | // Used by test cases where 2 streams are run on the same channel. |
| 1437 | cricket::FakeVideoRenderer renderer2_; |
| 1438 | }; |
| 1439 | |
| 1440 | // Test that SetSend works. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1441 | TEST_F(WebRtcVideoChannelBaseTest, SetSend) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1442 | EXPECT_FALSE(channel_->sending()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1443 | EXPECT_TRUE(channel_->SetVideoSend(kSsrc, nullptr, video_capturer_.get())); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1444 | EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
| 1445 | EXPECT_FALSE(channel_->sending()); |
| 1446 | EXPECT_TRUE(SetSend(true)); |
| 1447 | EXPECT_TRUE(channel_->sending()); |
| 1448 | EXPECT_TRUE(SendFrame()); |
| 1449 | EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); |
| 1450 | EXPECT_TRUE(SetSend(false)); |
| 1451 | EXPECT_FALSE(channel_->sending()); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1452 | } |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1453 | |
| 1454 | // Test that SetSend fails without codecs being set. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1455 | TEST_F(WebRtcVideoChannelBaseTest, SetSendWithoutCodecs) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1456 | EXPECT_FALSE(channel_->sending()); |
| 1457 | EXPECT_FALSE(SetSend(true)); |
| 1458 | EXPECT_FALSE(channel_->sending()); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1459 | } |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1460 | |
| 1461 | // Test that we properly set the send and recv buffer sizes by the time |
| 1462 | // SetSend is called. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1463 | TEST_F(WebRtcVideoChannelBaseTest, SetSendSetsTransportBufferSizes) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1464 | EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
| 1465 | EXPECT_TRUE(SetSend(true)); |
| 1466 | EXPECT_EQ(64 * 1024, network_interface_.sendbuf_size()); |
| 1467 | EXPECT_EQ(64 * 1024, network_interface_.recvbuf_size()); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1468 | } |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 1469 | |
Erik Språng | 820ebd0 | 2018-08-20 17:14:25 +0200 | [diff] [blame] | 1470 | // Test that we properly set the send and recv buffer sizes when overriding |
| 1471 | // via field trials. |
| 1472 | TEST_F(WebRtcVideoChannelBaseTest, OverridesRecvBufferSize) { |
| 1473 | // Set field trial to override the default recv buffer size, and then re-run |
| 1474 | // setup where the interface is created and configured. |
| 1475 | const int kCustomRecvBufferSize = 123456; |
| 1476 | webrtc::test::ScopedFieldTrials field_trial( |
| 1477 | "WebRTC-IncreasedReceivebuffers/123456/"); |
| 1478 | SetUp(); |
| 1479 | |
| 1480 | EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
| 1481 | EXPECT_TRUE(SetSend(true)); |
| 1482 | EXPECT_EQ(64 * 1024, network_interface_.sendbuf_size()); |
| 1483 | EXPECT_EQ(kCustomRecvBufferSize, network_interface_.recvbuf_size()); |
| 1484 | } |
| 1485 | |
| 1486 | // Test that we properly set the send and recv buffer sizes when overriding |
| 1487 | // via field trials with suffix. |
| 1488 | TEST_F(WebRtcVideoChannelBaseTest, OverridesRecvBufferSizeWithSuffix) { |
| 1489 | // Set field trial to override the default recv buffer size, and then re-run |
| 1490 | // setup where the interface is created and configured. |
| 1491 | const int kCustomRecvBufferSize = 123456; |
| 1492 | webrtc::test::ScopedFieldTrials field_trial( |
| 1493 | "WebRTC-IncreasedReceivebuffers/123456_Dogfood/"); |
| 1494 | SetUp(); |
| 1495 | |
| 1496 | EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
| 1497 | EXPECT_TRUE(SetSend(true)); |
| 1498 | EXPECT_EQ(64 * 1024, network_interface_.sendbuf_size()); |
| 1499 | EXPECT_EQ(kCustomRecvBufferSize, network_interface_.recvbuf_size()); |
| 1500 | } |
| 1501 | |
| 1502 | // Test that we properly set the send and recv buffer sizes when overriding |
| 1503 | // via field trials that don't make any sense. |
| 1504 | TEST_F(WebRtcVideoChannelBaseTest, InvalidRecvBufferSize) { |
| 1505 | // Set bogus field trial values to override the default recv buffer size, and |
| 1506 | // then re-run setup where the interface is created and configured. The |
| 1507 | // default value should still be used. |
| 1508 | |
| 1509 | for (std::string group : {" ", "NotANumber", "-1", "0"}) { |
| 1510 | std::string field_trial_string = "WebRTC-IncreasedReceivebuffers/"; |
| 1511 | field_trial_string += group; |
| 1512 | field_trial_string += "/"; |
| 1513 | webrtc::test::ScopedFieldTrials field_trial(field_trial_string); |
| 1514 | SetUp(); |
| 1515 | |
| 1516 | EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
| 1517 | EXPECT_TRUE(SetSend(true)); |
| 1518 | EXPECT_EQ(64 * 1024, network_interface_.sendbuf_size()); |
| 1519 | EXPECT_EQ(64 * 1024, network_interface_.recvbuf_size()); |
| 1520 | } |
| 1521 | } |
| 1522 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1523 | // Test that stats work properly for a 1-1 call. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1524 | TEST_F(WebRtcVideoChannelBaseTest, GetStats) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1525 | const int kDurationSec = 3; |
| 1526 | const int kFps = 10; |
| 1527 | SendReceiveManyAndGetStats(DefaultCodec(), kDurationSec, kFps); |
| 1528 | |
| 1529 | cricket::VideoMediaInfo info; |
| 1530 | EXPECT_TRUE(channel_->GetStats(&info)); |
| 1531 | |
| 1532 | ASSERT_EQ(1U, info.senders.size()); |
| 1533 | // TODO(whyuan): bytes_sent and bytes_rcvd are different. Are both payload? |
| 1534 | // For webrtc, bytes_sent does not include the RTP header length. |
| 1535 | EXPECT_GT(info.senders[0].bytes_sent, 0); |
| 1536 | EXPECT_EQ(NumRtpPackets(), info.senders[0].packets_sent); |
| 1537 | EXPECT_EQ(0.0, info.senders[0].fraction_lost); |
| 1538 | ASSERT_TRUE(info.senders[0].codec_payload_type); |
| 1539 | EXPECT_EQ(DefaultCodec().id, *info.senders[0].codec_payload_type); |
| 1540 | EXPECT_EQ(0, info.senders[0].firs_rcvd); |
| 1541 | EXPECT_EQ(0, info.senders[0].plis_rcvd); |
| 1542 | EXPECT_EQ(0, info.senders[0].nacks_rcvd); |
| 1543 | EXPECT_EQ(kVideoWidth, info.senders[0].send_frame_width); |
| 1544 | EXPECT_EQ(kVideoHeight, info.senders[0].send_frame_height); |
| 1545 | EXPECT_GT(info.senders[0].framerate_input, 0); |
| 1546 | EXPECT_GT(info.senders[0].framerate_sent, 0); |
| 1547 | |
| 1548 | EXPECT_EQ(1U, info.send_codecs.count(DefaultCodec().id)); |
| 1549 | EXPECT_EQ(DefaultCodec().ToCodecParameters(), |
| 1550 | info.send_codecs[DefaultCodec().id]); |
| 1551 | |
| 1552 | ASSERT_EQ(1U, info.receivers.size()); |
| 1553 | EXPECT_EQ(1U, info.senders[0].ssrcs().size()); |
| 1554 | EXPECT_EQ(1U, info.receivers[0].ssrcs().size()); |
| 1555 | EXPECT_EQ(info.senders[0].ssrcs()[0], info.receivers[0].ssrcs()[0]); |
| 1556 | ASSERT_TRUE(info.receivers[0].codec_payload_type); |
| 1557 | EXPECT_EQ(DefaultCodec().id, *info.receivers[0].codec_payload_type); |
| 1558 | EXPECT_EQ(NumRtpBytes(), info.receivers[0].bytes_rcvd); |
| 1559 | EXPECT_EQ(NumRtpPackets(), info.receivers[0].packets_rcvd); |
| 1560 | EXPECT_EQ(0.0, info.receivers[0].fraction_lost); |
| 1561 | EXPECT_EQ(0, info.receivers[0].packets_lost); |
| 1562 | // TODO(asapersson): Not set for webrtc. Handle missing stats. |
| 1563 | // EXPECT_EQ(0, info.receivers[0].packets_concealed); |
| 1564 | EXPECT_EQ(0, info.receivers[0].firs_sent); |
| 1565 | EXPECT_EQ(0, info.receivers[0].plis_sent); |
| 1566 | EXPECT_EQ(0, info.receivers[0].nacks_sent); |
| 1567 | EXPECT_EQ(kVideoWidth, info.receivers[0].frame_width); |
| 1568 | EXPECT_EQ(kVideoHeight, info.receivers[0].frame_height); |
| 1569 | EXPECT_GT(info.receivers[0].framerate_rcvd, 0); |
| 1570 | EXPECT_GT(info.receivers[0].framerate_decoded, 0); |
| 1571 | EXPECT_GT(info.receivers[0].framerate_output, 0); |
| 1572 | |
| 1573 | EXPECT_EQ(1U, info.receive_codecs.count(DefaultCodec().id)); |
| 1574 | EXPECT_EQ(DefaultCodec().ToCodecParameters(), |
| 1575 | info.receive_codecs[DefaultCodec().id]); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1576 | } |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1577 | |
| 1578 | // Test that stats work properly for a conf call with multiple recv streams. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1579 | TEST_F(WebRtcVideoChannelBaseTest, GetStatsMultipleRecvStreams) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1580 | cricket::FakeVideoRenderer renderer1, renderer2; |
| 1581 | EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
| 1582 | cricket::VideoSendParameters parameters; |
| 1583 | parameters.codecs.push_back(DefaultCodec()); |
| 1584 | parameters.conference_mode = true; |
| 1585 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 1586 | EXPECT_TRUE(SetSend(true)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1587 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
| 1588 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1589 | EXPECT_TRUE(channel_->SetSink(1, &renderer1)); |
| 1590 | EXPECT_TRUE(channel_->SetSink(2, &renderer2)); |
| 1591 | EXPECT_EQ(0, renderer1.num_rendered_frames()); |
| 1592 | EXPECT_EQ(0, renderer2.num_rendered_frames()); |
| 1593 | std::vector<uint32_t> ssrcs; |
| 1594 | ssrcs.push_back(1); |
| 1595 | ssrcs.push_back(2); |
| 1596 | network_interface_.SetConferenceMode(true, ssrcs); |
| 1597 | EXPECT_TRUE(SendFrame()); |
| 1598 | EXPECT_FRAME_ON_RENDERER_WAIT(renderer1, 1, kVideoWidth, kVideoHeight, |
| 1599 | kTimeout); |
| 1600 | EXPECT_FRAME_ON_RENDERER_WAIT(renderer2, 1, kVideoWidth, kVideoHeight, |
| 1601 | kTimeout); |
| 1602 | |
| 1603 | EXPECT_TRUE(channel_->SetSend(false)); |
| 1604 | |
| 1605 | cricket::VideoMediaInfo info; |
| 1606 | EXPECT_TRUE(channel_->GetStats(&info)); |
| 1607 | ASSERT_EQ(1U, info.senders.size()); |
| 1608 | // TODO(whyuan): bytes_sent and bytes_rcvd are different. Are both payload? |
| 1609 | // For webrtc, bytes_sent does not include the RTP header length. |
| 1610 | EXPECT_GT(GetSenderStats(0).bytes_sent, 0); |
| 1611 | EXPECT_EQ_WAIT(NumRtpPackets(), GetSenderStats(0).packets_sent, kTimeout); |
| 1612 | EXPECT_EQ(kVideoWidth, GetSenderStats(0).send_frame_width); |
| 1613 | EXPECT_EQ(kVideoHeight, GetSenderStats(0).send_frame_height); |
| 1614 | |
| 1615 | ASSERT_EQ(2U, info.receivers.size()); |
| 1616 | for (size_t i = 0; i < info.receivers.size(); ++i) { |
| 1617 | EXPECT_EQ(1U, GetReceiverStats(i).ssrcs().size()); |
| 1618 | EXPECT_EQ(i + 1, GetReceiverStats(i).ssrcs()[0]); |
| 1619 | EXPECT_EQ_WAIT(NumRtpBytes(), GetReceiverStats(i).bytes_rcvd, kTimeout); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1620 | EXPECT_EQ_WAIT(NumRtpPackets(), GetReceiverStats(i).packets_rcvd, kTimeout); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1621 | EXPECT_EQ_WAIT(kVideoWidth, GetReceiverStats(i).frame_width, kTimeout); |
| 1622 | EXPECT_EQ_WAIT(kVideoHeight, GetReceiverStats(i).frame_height, kTimeout); |
| 1623 | } |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1624 | } |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1625 | |
| 1626 | // Test that stats work properly for a conf call with multiple send streams. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1627 | TEST_F(WebRtcVideoChannelBaseTest, GetStatsMultipleSendStreams) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1628 | // Normal setup; note that we set the SSRC explicitly to ensure that |
| 1629 | // it will come first in the senders map. |
| 1630 | EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
| 1631 | cricket::VideoSendParameters parameters; |
| 1632 | parameters.codecs.push_back(DefaultCodec()); |
| 1633 | parameters.conference_mode = true; |
| 1634 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1635 | EXPECT_TRUE( |
| 1636 | channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1637 | EXPECT_TRUE(channel_->SetSink(kSsrc, &renderer_)); |
| 1638 | EXPECT_TRUE(SetSend(true)); |
| 1639 | EXPECT_TRUE(SendFrame()); |
| 1640 | EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); |
| 1641 | EXPECT_FRAME_WAIT(1, kVideoWidth, kVideoHeight, kTimeout); |
| 1642 | |
| 1643 | // Add an additional capturer, and hook up a renderer to receive it. |
| 1644 | cricket::FakeVideoRenderer renderer2; |
| 1645 | std::unique_ptr<cricket::FakeVideoCapturerWithTaskQueue> capturer( |
| 1646 | CreateFakeVideoCapturer()); |
| 1647 | const int kTestWidth = 160; |
| 1648 | const int kTestHeight = 120; |
| 1649 | cricket::VideoFormat format(kTestWidth, kTestHeight, |
| 1650 | cricket::VideoFormat::FpsToInterval(5), |
| 1651 | cricket::FOURCC_I420); |
| 1652 | EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1653 | EXPECT_TRUE( |
| 1654 | channel_->AddSendStream(cricket::StreamParams::CreateLegacy(5678))); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1655 | EXPECT_TRUE(channel_->SetVideoSend(5678, nullptr, capturer.get())); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1656 | EXPECT_TRUE( |
| 1657 | channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(5678))); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1658 | EXPECT_TRUE(channel_->SetSink(5678, &renderer2)); |
| 1659 | EXPECT_TRUE(capturer->CaptureCustomFrame(kTestWidth, kTestHeight)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1660 | EXPECT_FRAME_ON_RENDERER_WAIT(renderer2, 1, kTestWidth, kTestHeight, |
| 1661 | kTimeout); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1662 | |
| 1663 | // Get stats, and make sure they are correct for two senders. We wait until |
| 1664 | // the number of expected packets have been sent to avoid races where we |
| 1665 | // check stats before it has been updated. |
| 1666 | cricket::VideoMediaInfo info; |
| 1667 | for (uint32_t i = 0; i < kTimeout; ++i) { |
| 1668 | rtc::Thread::Current()->ProcessMessages(1); |
| 1669 | EXPECT_TRUE(channel_->GetStats(&info)); |
| 1670 | ASSERT_EQ(2U, info.senders.size()); |
| 1671 | if (info.senders[0].packets_sent + info.senders[1].packets_sent == |
| 1672 | NumRtpPackets()) { |
| 1673 | // Stats have been updated for both sent frames, expectations can be |
| 1674 | // checked now. |
| 1675 | break; |
| 1676 | } |
| 1677 | } |
| 1678 | EXPECT_EQ(NumRtpPackets(), |
| 1679 | info.senders[0].packets_sent + info.senders[1].packets_sent) |
| 1680 | << "Timed out while waiting for packet counts for all sent packets."; |
| 1681 | EXPECT_EQ(1U, info.senders[0].ssrcs().size()); |
| 1682 | EXPECT_EQ(1234U, info.senders[0].ssrcs()[0]); |
| 1683 | EXPECT_EQ(kVideoWidth, info.senders[0].send_frame_width); |
| 1684 | EXPECT_EQ(kVideoHeight, info.senders[0].send_frame_height); |
| 1685 | EXPECT_EQ(1U, info.senders[1].ssrcs().size()); |
| 1686 | EXPECT_EQ(5678U, info.senders[1].ssrcs()[0]); |
| 1687 | EXPECT_EQ(kTestWidth, info.senders[1].send_frame_width); |
| 1688 | EXPECT_EQ(kTestHeight, info.senders[1].send_frame_height); |
| 1689 | // The capturer must be unregistered here as it runs out of it's scope next. |
| 1690 | channel_->SetVideoSend(5678, nullptr, nullptr); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1691 | } |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 1692 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1693 | // Test that we can set the bandwidth. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1694 | TEST_F(WebRtcVideoChannelBaseTest, SetSendBandwidth) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1695 | cricket::VideoSendParameters parameters; |
| 1696 | parameters.codecs.push_back(DefaultCodec()); |
| 1697 | parameters.max_bandwidth_bps = -1; // <= 0 means unlimited. |
| 1698 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 1699 | parameters.max_bandwidth_bps = 128 * 1024; |
| 1700 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1701 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1702 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1703 | // Test that we can set the SSRC for the default send source. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1704 | TEST_F(WebRtcVideoChannelBaseTest, SetSendSsrc) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1705 | EXPECT_TRUE(SetDefaultCodec()); |
| 1706 | EXPECT_TRUE(SetSend(true)); |
| 1707 | EXPECT_TRUE(SendFrame()); |
| 1708 | EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); |
Åsa Persson | 23cd45a | 2018-07-03 10:40:40 +0200 | [diff] [blame] | 1709 | webrtc::RTPHeader header; |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1710 | std::unique_ptr<const rtc::CopyOnWriteBuffer> p(GetRtpPacket(0)); |
Åsa Persson | 23cd45a | 2018-07-03 10:40:40 +0200 | [diff] [blame] | 1711 | EXPECT_TRUE(ParseRtpPacket(p.get(), &header)); |
| 1712 | EXPECT_EQ(kSsrc, header.ssrc); |
| 1713 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1714 | // Packets are being paced out, so these can mismatch between the first and |
| 1715 | // second call to NumRtpPackets until pending packets are paced out. |
Åsa Persson | 23cd45a | 2018-07-03 10:40:40 +0200 | [diff] [blame] | 1716 | EXPECT_EQ_WAIT(NumRtpPackets(), NumRtpPackets(header.ssrc), kTimeout); |
| 1717 | EXPECT_EQ_WAIT(NumRtpBytes(), NumRtpBytes(header.ssrc), kTimeout); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1718 | EXPECT_EQ(1, NumSentSsrcs()); |
| 1719 | EXPECT_EQ(0, NumRtpPackets(kSsrc - 1)); |
| 1720 | EXPECT_EQ(0, NumRtpBytes(kSsrc - 1)); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1721 | } |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1722 | |
| 1723 | // Test that we can set the SSRC even after codecs are set. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1724 | TEST_F(WebRtcVideoChannelBaseTest, SetSendSsrcAfterSetCodecs) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1725 | // Remove stream added in Setup. |
| 1726 | EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); |
| 1727 | EXPECT_TRUE(SetDefaultCodec()); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1728 | EXPECT_TRUE( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1729 | channel_->AddSendStream(cricket::StreamParams::CreateLegacy(999))); |
| 1730 | EXPECT_TRUE(channel_->SetVideoSend(999u, nullptr, video_capturer_.get())); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1731 | EXPECT_TRUE(SetSend(true)); |
| 1732 | EXPECT_TRUE(WaitAndSendFrame(0)); |
| 1733 | EXPECT_TRUE_WAIT(NumRtpPackets() > 0, kTimeout); |
Åsa Persson | 23cd45a | 2018-07-03 10:40:40 +0200 | [diff] [blame] | 1734 | webrtc::RTPHeader header; |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1735 | std::unique_ptr<const rtc::CopyOnWriteBuffer> p(GetRtpPacket(0)); |
Åsa Persson | 23cd45a | 2018-07-03 10:40:40 +0200 | [diff] [blame] | 1736 | EXPECT_TRUE(ParseRtpPacket(p.get(), &header)); |
| 1737 | EXPECT_EQ(999u, header.ssrc); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1738 | // Packets are being paced out, so these can mismatch between the first and |
| 1739 | // second call to NumRtpPackets until pending packets are paced out. |
Åsa Persson | 23cd45a | 2018-07-03 10:40:40 +0200 | [diff] [blame] | 1740 | EXPECT_EQ_WAIT(NumRtpPackets(), NumRtpPackets(header.ssrc), kTimeout); |
| 1741 | EXPECT_EQ_WAIT(NumRtpBytes(), NumRtpBytes(header.ssrc), kTimeout); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1742 | EXPECT_EQ(1, NumSentSsrcs()); |
| 1743 | EXPECT_EQ(0, NumRtpPackets(kSsrc)); |
| 1744 | EXPECT_EQ(0, NumRtpBytes(kSsrc)); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1745 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1746 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1747 | // Test that we can set the default video renderer before and after |
| 1748 | // media is received. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1749 | TEST_F(WebRtcVideoChannelBaseTest, SetSink) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1750 | uint8_t data1[] = {0x80, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 1751 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1752 | |
| 1753 | rtc::CopyOnWriteBuffer packet1(data1, sizeof(data1)); |
| 1754 | rtc::SetBE32(packet1.data() + 8, kSsrc); |
| 1755 | channel_->SetSink(kDefaultReceiveSsrc, NULL); |
| 1756 | EXPECT_TRUE(SetDefaultCodec()); |
| 1757 | EXPECT_TRUE(SetSend(true)); |
| 1758 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 1759 | channel_->OnPacketReceived(&packet1, rtc::PacketTime()); |
| 1760 | EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); |
| 1761 | EXPECT_TRUE(SendFrame()); |
| 1762 | EXPECT_FRAME_WAIT(1, kVideoWidth, kVideoHeight, kTimeout); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1763 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1764 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1765 | // Tests setting up and configuring a send stream. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1766 | TEST_F(WebRtcVideoChannelBaseTest, AddRemoveSendStreams) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1767 | EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
| 1768 | EXPECT_TRUE(SetSend(true)); |
| 1769 | EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); |
| 1770 | EXPECT_TRUE(SendFrame()); |
| 1771 | EXPECT_FRAME_WAIT(1, kVideoWidth, kVideoHeight, kTimeout); |
| 1772 | EXPECT_GT(NumRtpPackets(), 0); |
Åsa Persson | 23cd45a | 2018-07-03 10:40:40 +0200 | [diff] [blame] | 1773 | webrtc::RTPHeader header; |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1774 | size_t last_packet = NumRtpPackets() - 1; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1775 | std::unique_ptr<const rtc::CopyOnWriteBuffer> p( |
| 1776 | GetRtpPacket(static_cast<int>(last_packet))); |
Åsa Persson | 23cd45a | 2018-07-03 10:40:40 +0200 | [diff] [blame] | 1777 | EXPECT_TRUE(ParseRtpPacket(p.get(), &header)); |
| 1778 | EXPECT_EQ(kSsrc, header.ssrc); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1779 | |
| 1780 | // Remove the send stream that was added during Setup. |
| 1781 | EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); |
| 1782 | int rtp_packets = NumRtpPackets(); |
| 1783 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1784 | EXPECT_TRUE( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1785 | channel_->AddSendStream(cricket::StreamParams::CreateLegacy(789u))); |
| 1786 | EXPECT_TRUE(channel_->SetVideoSend(789u, nullptr, video_capturer_.get())); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1787 | EXPECT_EQ(rtp_packets, NumRtpPackets()); |
| 1788 | // Wait 30ms to guarantee the engine does not drop the frame. |
| 1789 | EXPECT_TRUE(WaitAndSendFrame(30)); |
| 1790 | EXPECT_TRUE_WAIT(NumRtpPackets() > rtp_packets, kTimeout); |
| 1791 | |
| 1792 | last_packet = NumRtpPackets() - 1; |
| 1793 | p.reset(GetRtpPacket(static_cast<int>(last_packet))); |
Åsa Persson | 23cd45a | 2018-07-03 10:40:40 +0200 | [diff] [blame] | 1794 | EXPECT_TRUE(ParseRtpPacket(p.get(), &header)); |
| 1795 | EXPECT_EQ(789u, header.ssrc); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1796 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1797 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1798 | // Tests the behavior of incoming streams in a conference scenario. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1799 | TEST_F(WebRtcVideoChannelBaseTest, SimulateConference) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1800 | cricket::FakeVideoRenderer renderer1, renderer2; |
| 1801 | EXPECT_TRUE(SetDefaultCodec()); |
| 1802 | cricket::VideoSendParameters parameters; |
| 1803 | parameters.codecs.push_back(DefaultCodec()); |
| 1804 | parameters.conference_mode = true; |
| 1805 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 1806 | EXPECT_TRUE(SetSend(true)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1807 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
| 1808 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1809 | EXPECT_TRUE(channel_->SetSink(1, &renderer1)); |
| 1810 | EXPECT_TRUE(channel_->SetSink(2, &renderer2)); |
| 1811 | EXPECT_EQ(0, renderer1.num_rendered_frames()); |
| 1812 | EXPECT_EQ(0, renderer2.num_rendered_frames()); |
| 1813 | std::vector<uint32_t> ssrcs; |
| 1814 | ssrcs.push_back(1); |
| 1815 | ssrcs.push_back(2); |
| 1816 | network_interface_.SetConferenceMode(true, ssrcs); |
| 1817 | EXPECT_TRUE(SendFrame()); |
| 1818 | EXPECT_FRAME_ON_RENDERER_WAIT(renderer1, 1, kVideoWidth, kVideoHeight, |
| 1819 | kTimeout); |
| 1820 | EXPECT_FRAME_ON_RENDERER_WAIT(renderer2, 1, kVideoWidth, kVideoHeight, |
| 1821 | kTimeout); |
| 1822 | |
| 1823 | std::unique_ptr<const rtc::CopyOnWriteBuffer> p(GetRtpPacket(0)); |
| 1824 | EXPECT_EQ(DefaultCodec().id, GetPayloadType(p.get())); |
| 1825 | EXPECT_EQ(kVideoWidth, renderer1.width()); |
| 1826 | EXPECT_EQ(kVideoHeight, renderer1.height()); |
| 1827 | EXPECT_EQ(kVideoWidth, renderer2.width()); |
| 1828 | EXPECT_EQ(kVideoHeight, renderer2.height()); |
| 1829 | EXPECT_TRUE(channel_->RemoveRecvStream(2)); |
| 1830 | EXPECT_TRUE(channel_->RemoveRecvStream(1)); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1831 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1832 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1833 | // 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] | 1834 | TEST_F(WebRtcVideoChannelBaseTest, DISABLED_AddRemoveCapturer) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1835 | using cricket::VideoCodec; |
| 1836 | using cricket::VideoOptions; |
| 1837 | using cricket::VideoFormat; |
| 1838 | using cricket::FOURCC_I420; |
| 1839 | |
| 1840 | VideoCodec codec = DefaultCodec(); |
| 1841 | const int time_between_send_ms = VideoFormat::FpsToInterval(kFramerate); |
| 1842 | EXPECT_TRUE(SetOneCodec(codec)); |
| 1843 | EXPECT_TRUE(SetSend(true)); |
| 1844 | EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); |
| 1845 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 1846 | EXPECT_TRUE(SendFrame()); |
| 1847 | EXPECT_FRAME_WAIT(1, kVideoWidth, kVideoHeight, kTimeout); |
| 1848 | std::unique_ptr<cricket::FakeVideoCapturerWithTaskQueue> capturer( |
| 1849 | CreateFakeVideoCapturer()); |
| 1850 | |
| 1851 | // TODO(nisse): This testcase fails if we don't configure |
| 1852 | // screencast. It's unclear why, I see nothing obvious in this |
| 1853 | // test which is related to screencast logic. |
| 1854 | VideoOptions video_options; |
| 1855 | video_options.is_screencast = true; |
| 1856 | channel_->SetVideoSend(kSsrc, &video_options, nullptr); |
| 1857 | |
| 1858 | VideoFormat format(480, 360, VideoFormat::FpsToInterval(30), FOURCC_I420); |
| 1859 | EXPECT_EQ(cricket::CS_RUNNING, capturer->Start(format)); |
| 1860 | // All capturers start generating frames with the same timestamp. ViE does |
| 1861 | // not allow the same timestamp to be used. Capture one frame before |
| 1862 | // associating the capturer with the channel. |
| 1863 | EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height)); |
| 1864 | |
| 1865 | int captured_frames = 1; |
| 1866 | for (int iterations = 0; iterations < 2; ++iterations) { |
| 1867 | EXPECT_TRUE(channel_->SetVideoSend(kSsrc, nullptr, capturer.get())); |
| 1868 | rtc::Thread::Current()->ProcessMessages(time_between_send_ms); |
| 1869 | EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height)); |
| 1870 | ++captured_frames; |
| 1871 | // Wait until frame of right size is captured. |
| 1872 | EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames && |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1873 | format.width == renderer_.width() && |
| 1874 | format.height == renderer_.height() && |
| 1875 | !renderer_.black_frame(), |
| 1876 | kTimeout); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1877 | EXPECT_GE(renderer_.num_rendered_frames(), captured_frames); |
| 1878 | EXPECT_EQ(format.width, renderer_.width()); |
| 1879 | EXPECT_EQ(format.height, renderer_.height()); |
| 1880 | captured_frames = renderer_.num_rendered_frames() + 1; |
| 1881 | EXPECT_FALSE(renderer_.black_frame()); |
| 1882 | EXPECT_TRUE(channel_->SetVideoSend(kSsrc, nullptr, nullptr)); |
| 1883 | // Make sure a black frame is generated within the specified timeout. |
| 1884 | // The black frame should be the resolution of the previous frame to |
| 1885 | // prevent expensive encoder reconfigurations. |
| 1886 | EXPECT_TRUE_WAIT(renderer_.num_rendered_frames() >= captured_frames && |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1887 | format.width == renderer_.width() && |
| 1888 | format.height == renderer_.height() && |
| 1889 | renderer_.black_frame(), |
| 1890 | kTimeout); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1891 | EXPECT_GE(renderer_.num_rendered_frames(), captured_frames); |
| 1892 | EXPECT_EQ(format.width, renderer_.width()); |
| 1893 | EXPECT_EQ(format.height, renderer_.height()); |
| 1894 | EXPECT_TRUE(renderer_.black_frame()); |
| 1895 | |
| 1896 | // The black frame has the same timestamp as the next frame since it's |
| 1897 | // timestamp is set to the last frame's timestamp + interval. WebRTC will |
| 1898 | // not render a frame with the same timestamp so capture another frame |
| 1899 | // with the frame capturer to increment the next frame's timestamp. |
| 1900 | EXPECT_TRUE(capturer->CaptureCustomFrame(format.width, format.height)); |
| 1901 | } |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1902 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1903 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1904 | // Tests that if SetVideoSend is called with a NULL capturer after the |
| 1905 | // capturer was already removed, the application doesn't crash (and no black |
| 1906 | // frame is sent). |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1907 | TEST_F(WebRtcVideoChannelBaseTest, RemoveCapturerWithoutAdd) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1908 | EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
| 1909 | EXPECT_TRUE(SetSend(true)); |
| 1910 | EXPECT_TRUE(channel_->SetSink(kDefaultReceiveSsrc, &renderer_)); |
| 1911 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 1912 | EXPECT_TRUE(SendFrame()); |
| 1913 | EXPECT_FRAME_WAIT(1, kVideoWidth, kVideoHeight, kTimeout); |
| 1914 | // Wait for one frame so they don't get dropped because we send frames too |
| 1915 | // tightly. |
| 1916 | rtc::Thread::Current()->ProcessMessages(30); |
| 1917 | // Remove the capturer. |
| 1918 | EXPECT_TRUE(channel_->SetVideoSend(kSsrc, nullptr, nullptr)); |
| 1919 | |
| 1920 | // No capturer was added, so this SetVideoSend shouldn't do anything. |
| 1921 | EXPECT_TRUE(channel_->SetVideoSend(kSsrc, nullptr, nullptr)); |
| 1922 | rtc::Thread::Current()->ProcessMessages(300); |
| 1923 | // Verify no more frames were sent. |
| 1924 | EXPECT_EQ(1, renderer_.num_rendered_frames()); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1925 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1926 | |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1927 | // Tests that we can add and remove capturer as unique sources. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1928 | TEST_F(WebRtcVideoChannelBaseTest, AddRemoveCapturerMultipleSources) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1929 | // WebRTC implementation will drop frames if pushed to quickly. Wait the |
| 1930 | // interval time to avoid that. |
| 1931 | // WebRTC implementation will drop frames if pushed to quickly. Wait the |
| 1932 | // interval time to avoid that. |
| 1933 | // Set up the stream associated with the engine. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1934 | EXPECT_TRUE( |
| 1935 | channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrc))); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1936 | EXPECT_TRUE(channel_->SetSink(kSsrc, &renderer_)); |
| 1937 | cricket::VideoFormat capture_format( |
| 1938 | kVideoWidth, kVideoHeight, |
| 1939 | cricket::VideoFormat::FpsToInterval(kFramerate), cricket::FOURCC_I420); |
| 1940 | // Set up additional stream 1. |
| 1941 | cricket::FakeVideoRenderer renderer1; |
| 1942 | EXPECT_FALSE(channel_->SetSink(1, &renderer1)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1943 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1944 | EXPECT_TRUE(channel_->SetSink(1, &renderer1)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1945 | EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1))); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1946 | std::unique_ptr<cricket::FakeVideoCapturerWithTaskQueue> capturer1( |
| 1947 | CreateFakeVideoCapturer()); |
| 1948 | EXPECT_EQ(cricket::CS_RUNNING, capturer1->Start(capture_format)); |
| 1949 | // Set up additional stream 2. |
| 1950 | cricket::FakeVideoRenderer renderer2; |
| 1951 | EXPECT_FALSE(channel_->SetSink(2, &renderer2)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1952 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1953 | EXPECT_TRUE(channel_->SetSink(2, &renderer2)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1954 | EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(2))); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1955 | std::unique_ptr<cricket::FakeVideoCapturerWithTaskQueue> capturer2( |
| 1956 | CreateFakeVideoCapturer()); |
| 1957 | EXPECT_EQ(cricket::CS_RUNNING, capturer2->Start(capture_format)); |
| 1958 | // State for all the streams. |
| 1959 | EXPECT_TRUE(SetOneCodec(DefaultCodec())); |
| 1960 | // A limitation in the lmi implementation requires that SetVideoSend() is |
| 1961 | // called after SetOneCodec(). |
| 1962 | // TODO(hellner): this seems like an unnecessary constraint, fix it. |
| 1963 | EXPECT_TRUE(channel_->SetVideoSend(1, nullptr, capturer1.get())); |
| 1964 | EXPECT_TRUE(channel_->SetVideoSend(2, nullptr, capturer2.get())); |
| 1965 | EXPECT_TRUE(SetSend(true)); |
| 1966 | // Test capturer associated with engine. |
| 1967 | const int kTestWidth = 160; |
| 1968 | const int kTestHeight = 120; |
| 1969 | EXPECT_TRUE(capturer1->CaptureCustomFrame(kTestWidth, kTestHeight)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1970 | EXPECT_FRAME_ON_RENDERER_WAIT(renderer1, 1, kTestWidth, kTestHeight, |
| 1971 | kTimeout); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1972 | // Capture a frame with additional capturer2, frames should be received |
| 1973 | EXPECT_TRUE(capturer2->CaptureCustomFrame(kTestWidth, kTestHeight)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1974 | EXPECT_FRAME_ON_RENDERER_WAIT(renderer2, 1, kTestWidth, kTestHeight, |
| 1975 | kTimeout); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1976 | // Successfully remove the capturer. |
| 1977 | EXPECT_TRUE(channel_->SetVideoSend(kSsrc, nullptr, nullptr)); |
| 1978 | // The capturers must be unregistered here as it runs out of it's scope |
| 1979 | // next. |
| 1980 | EXPECT_TRUE(channel_->SetVideoSend(1, nullptr, nullptr)); |
| 1981 | EXPECT_TRUE(channel_->SetVideoSend(2, nullptr, nullptr)); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1982 | } |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1983 | |
| 1984 | // Tests empty StreamParams is rejected. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1985 | TEST_F(WebRtcVideoChannelBaseTest, RejectEmptyStreamParams) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1986 | // Remove the send stream that was added during Setup. |
| 1987 | EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); |
| 1988 | |
| 1989 | cricket::StreamParams empty; |
| 1990 | EXPECT_FALSE(channel_->AddSendStream(empty)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 1991 | EXPECT_TRUE( |
| 1992 | channel_->AddSendStream(cricket::StreamParams::CreateLegacy(789u))); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1993 | } |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1994 | |
| 1995 | // Test that multiple send streams can be created and deleted properly. |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 1996 | TEST_F(WebRtcVideoChannelBaseTest, MultipleSendStreams) { |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 1997 | // Remove stream added in Setup. I.e. remove stream corresponding to default |
| 1998 | // channel. |
| 1999 | EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2000 | const unsigned int kSsrcsSize = sizeof(kSsrcs4) / sizeof(kSsrcs4[0]); |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 2001 | for (unsigned int i = 0; i < kSsrcsSize; ++i) { |
| 2002 | EXPECT_TRUE(channel_->AddSendStream( |
| 2003 | cricket::StreamParams::CreateLegacy(kSsrcs4[i]))); |
| 2004 | } |
| 2005 | // Delete one of the non default channel streams, let the destructor delete |
| 2006 | // the remaining ones. |
| 2007 | EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs4[kSsrcsSize - 1])); |
| 2008 | // Stream should already be deleted. |
| 2009 | EXPECT_FALSE(channel_->RemoveSendStream(kSsrcs4[kSsrcsSize - 1])); |
srte | e0c2eea | 2017-12-15 17:44:33 +0100 | [diff] [blame] | 2010 | } |
pbos@webrtc.org | c4175b9 | 2014-09-03 15:25:49 +0000 | [diff] [blame] | 2011 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2012 | TEST_F(WebRtcVideoChannelBaseTest, SendAndReceiveVp8Vga) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2013 | SendAndReceive(GetEngineCodec("VP8")); |
pbos@webrtc.org | 9359cb3 | 2014-07-23 15:44:48 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2016 | TEST_F(WebRtcVideoChannelBaseTest, SendAndReceiveVp8Qvga) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2017 | SendAndReceive(GetEngineCodec("VP8")); |
pbos@webrtc.org | 9359cb3 | 2014-07-23 15:44:48 +0000 | [diff] [blame] | 2018 | } |
| 2019 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2020 | TEST_F(WebRtcVideoChannelBaseTest, SendAndReceiveVp8SvcQqvga) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2021 | SendAndReceive(GetEngineCodec("VP8")); |
pbos@webrtc.org | 9359cb3 | 2014-07-23 15:44:48 +0000 | [diff] [blame] | 2022 | } |
| 2023 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2024 | TEST_F(WebRtcVideoChannelBaseTest, TwoStreamsSendAndReceive) { |
Peter Boström | d1f584b | 2016-04-20 16:31:53 +0200 | [diff] [blame] | 2025 | // Set a high bitrate to not be downscaled by VP8 due to low initial start |
| 2026 | // bitrates. This currently happens at <250k, and two streams sharing 300k |
| 2027 | // initially will use QVGA instead of VGA. |
| 2028 | // TODO(pbos): Set up the quality scaler so that both senders reliably start |
| 2029 | // at QVGA, then verify that instead. |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2030 | cricket::VideoCodec codec = GetEngineCodec("VP8"); |
Peter Boström | d1f584b | 2016-04-20 16:31:53 +0200 | [diff] [blame] | 2031 | codec.params[kCodecParamStartBitrate] = "1000000"; |
Niels Möller | 6557d0c | 2018-04-11 15:18:34 +0200 | [diff] [blame] | 2032 | TwoStreamsSendAndReceive(codec); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2033 | } |
| 2034 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2035 | class WebRtcVideoChannelTest : public WebRtcVideoEngineTest { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2036 | public: |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2037 | WebRtcVideoChannelTest() : WebRtcVideoChannelTest("") {} |
| 2038 | explicit WebRtcVideoChannelTest(const char* field_trials) |
| 2039 | : WebRtcVideoEngineTest(field_trials), last_ssrc_(0) {} |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 2040 | void SetUp() override { |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 2041 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
| 2042 | encoder_factory_->AddSupportedVideoCodecType("VP9"); |
| 2043 | #if defined(WEBRTC_USE_H264) |
| 2044 | encoder_factory_->AddSupportedVideoCodecType("H264"); |
| 2045 | #endif |
| 2046 | |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 2047 | fake_call_.reset(new FakeCall()); |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 2048 | channel_.reset(engine_.CreateChannel(fake_call_.get(), GetMediaConfig(), |
| 2049 | VideoOptions())); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 2050 | channel_->OnReadyToSend(true); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2051 | last_ssrc_ = 123; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2052 | send_parameters_.codecs = engine_.codecs(); |
| 2053 | recv_parameters_.codecs = engine_.codecs(); |
| 2054 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2055 | } |
| 2056 | |
| 2057 | protected: |
| 2058 | FakeVideoSendStream* AddSendStream() { |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2059 | return AddSendStream(StreamParams::CreateLegacy(++last_ssrc_)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2060 | } |
| 2061 | |
| 2062 | FakeVideoSendStream* AddSendStream(const StreamParams& sp) { |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2063 | size_t num_streams = fake_call_->GetVideoSendStreams().size(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2064 | EXPECT_TRUE(channel_->AddSendStream(sp)); |
| 2065 | std::vector<FakeVideoSendStream*> streams = |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2066 | fake_call_->GetVideoSendStreams(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2067 | EXPECT_EQ(num_streams + 1, streams.size()); |
| 2068 | return streams[streams.size() - 1]; |
| 2069 | } |
| 2070 | |
| 2071 | std::vector<FakeVideoSendStream*> GetFakeSendStreams() { |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2072 | return fake_call_->GetVideoSendStreams(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2073 | } |
| 2074 | |
| 2075 | FakeVideoReceiveStream* AddRecvStream() { |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2076 | return AddRecvStream(StreamParams::CreateLegacy(++last_ssrc_)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | FakeVideoReceiveStream* AddRecvStream(const StreamParams& sp) { |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2080 | size_t num_streams = fake_call_->GetVideoReceiveStreams().size(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2081 | EXPECT_TRUE(channel_->AddRecvStream(sp)); |
| 2082 | std::vector<FakeVideoReceiveStream*> streams = |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2083 | fake_call_->GetVideoReceiveStreams(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2084 | EXPECT_EQ(num_streams + 1, streams.size()); |
| 2085 | return streams[streams.size() - 1]; |
| 2086 | } |
| 2087 | |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2088 | void SetSendCodecsShouldWorkForBitrates(const char* min_bitrate_kbps, |
| 2089 | int expected_min_bitrate_bps, |
| 2090 | const char* start_bitrate_kbps, |
| 2091 | int expected_start_bitrate_bps, |
| 2092 | const char* max_bitrate_kbps, |
| 2093 | int expected_max_bitrate_bps) { |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 2094 | ExpectSetBitrateParameters(expected_min_bitrate_bps, |
| 2095 | expected_start_bitrate_bps, |
| 2096 | expected_max_bitrate_bps); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2097 | auto& codecs = send_parameters_.codecs; |
| 2098 | codecs.clear(); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2099 | codecs.push_back(GetEngineCodec("VP8")); |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 2100 | codecs[0].params[kCodecParamMinBitrate] = min_bitrate_kbps; |
| 2101 | codecs[0].params[kCodecParamStartBitrate] = start_bitrate_kbps; |
| 2102 | codecs[0].params[kCodecParamMaxBitrate] = max_bitrate_kbps; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2103 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 2104 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2105 | |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 2106 | void ExpectSetBitrateParameters(int min_bitrate_bps, |
| 2107 | int start_bitrate_bps, |
| 2108 | int max_bitrate_bps) { |
| 2109 | EXPECT_CALL( |
| 2110 | *fake_call_->GetMockTransportControllerSend(), |
| 2111 | SetSdpBitrateParameters(AllOf( |
| 2112 | Field(&BitrateConstraints::min_bitrate_bps, min_bitrate_bps), |
| 2113 | Field(&BitrateConstraints::start_bitrate_bps, start_bitrate_bps), |
| 2114 | Field(&BitrateConstraints::max_bitrate_bps, max_bitrate_bps)))); |
| 2115 | } |
| 2116 | |
| 2117 | void ExpectSetMaxBitrate(int max_bitrate_bps) { |
| 2118 | EXPECT_CALL(*fake_call_->GetMockTransportControllerSend(), |
| 2119 | SetSdpBitrateParameters(Field( |
| 2120 | &BitrateConstraints::max_bitrate_bps, max_bitrate_bps))); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2121 | } |
| 2122 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2123 | void TestSetSendRtpHeaderExtensions(const std::string& ext_uri) { |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2124 | // Enable extension. |
| 2125 | const int id = 1; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2126 | cricket::VideoSendParameters parameters = send_parameters_; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2127 | parameters.extensions.push_back(RtpExtension(ext_uri, id)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2128 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2129 | FakeVideoSendStream* send_stream = |
| 2130 | AddSendStream(cricket::StreamParams::CreateLegacy(123)); |
| 2131 | |
| 2132 | // Verify the send extension id. |
| 2133 | ASSERT_EQ(1u, send_stream->GetConfig().rtp.extensions.size()); |
| 2134 | EXPECT_EQ(id, send_stream->GetConfig().rtp.extensions[0].id); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2135 | EXPECT_EQ(ext_uri, send_stream->GetConfig().rtp.extensions[0].uri); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2136 | // Verify call with same set of extensions returns true. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2137 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2138 | // Verify that SetSendRtpHeaderExtensions doesn't implicitly add them for |
| 2139 | // receivers. |
| 2140 | EXPECT_TRUE(AddRecvStream(cricket::StreamParams::CreateLegacy(123)) |
| 2141 | ->GetConfig() |
| 2142 | .rtp.extensions.empty()); |
| 2143 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2144 | // Verify that existing RTP header extensions can be removed. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2145 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 2146 | ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| 2147 | send_stream = fake_call_->GetVideoSendStreams()[0]; |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2148 | EXPECT_TRUE(send_stream->GetConfig().rtp.extensions.empty()); |
| 2149 | |
| 2150 | // Verify that adding receive RTP header extensions adds them for existing |
| 2151 | // streams. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2152 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 2153 | send_stream = fake_call_->GetVideoSendStreams()[0]; |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2154 | ASSERT_EQ(1u, send_stream->GetConfig().rtp.extensions.size()); |
| 2155 | EXPECT_EQ(id, send_stream->GetConfig().rtp.extensions[0].id); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2156 | EXPECT_EQ(ext_uri, send_stream->GetConfig().rtp.extensions[0].uri); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2157 | } |
| 2158 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2159 | void TestSetRecvRtpHeaderExtensions(const std::string& ext_uri) { |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2160 | // Enable extension. |
| 2161 | const int id = 1; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2162 | cricket::VideoRecvParameters parameters = recv_parameters_; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2163 | parameters.extensions.push_back(RtpExtension(ext_uri, id)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2164 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2165 | |
| 2166 | FakeVideoReceiveStream* recv_stream = |
| 2167 | AddRecvStream(cricket::StreamParams::CreateLegacy(123)); |
| 2168 | |
| 2169 | // Verify the recv extension id. |
| 2170 | ASSERT_EQ(1u, recv_stream->GetConfig().rtp.extensions.size()); |
| 2171 | EXPECT_EQ(id, recv_stream->GetConfig().rtp.extensions[0].id); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2172 | EXPECT_EQ(ext_uri, recv_stream->GetConfig().rtp.extensions[0].uri); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2173 | // Verify call with same set of extensions returns true. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2174 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2175 | |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2176 | // Verify that SetRecvRtpHeaderExtensions doesn't implicitly add them for |
| 2177 | // senders. |
| 2178 | EXPECT_TRUE(AddSendStream(cricket::StreamParams::CreateLegacy(123)) |
| 2179 | ->GetConfig() |
| 2180 | .rtp.extensions.empty()); |
| 2181 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2182 | // Verify that existing RTP header extensions can be removed. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2183 | EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 2184 | ASSERT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
| 2185 | recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2186 | EXPECT_TRUE(recv_stream->GetConfig().rtp.extensions.empty()); |
| 2187 | |
| 2188 | // Verify that adding receive RTP header extensions adds them for existing |
| 2189 | // streams. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2190 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 2191 | recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2192 | ASSERT_EQ(1u, recv_stream->GetConfig().rtp.extensions.size()); |
| 2193 | EXPECT_EQ(id, recv_stream->GetConfig().rtp.extensions[0].id); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2194 | EXPECT_EQ(ext_uri, recv_stream->GetConfig().rtp.extensions[0].uri); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2195 | } |
| 2196 | |
Stefan Holmer | bbaf363 | 2015-10-29 18:53:23 +0100 | [diff] [blame] | 2197 | void TestExtensionFilter(const std::vector<std::string>& extensions, |
| 2198 | const std::string& expected_extension) { |
| 2199 | cricket::VideoSendParameters parameters = send_parameters_; |
| 2200 | int expected_id = -1; |
| 2201 | int id = 1; |
| 2202 | for (const std::string& extension : extensions) { |
| 2203 | if (extension == expected_extension) |
| 2204 | expected_id = id; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2205 | parameters.extensions.push_back(RtpExtension(extension, id++)); |
Stefan Holmer | bbaf363 | 2015-10-29 18:53:23 +0100 | [diff] [blame] | 2206 | } |
| 2207 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 2208 | FakeVideoSendStream* send_stream = |
| 2209 | AddSendStream(cricket::StreamParams::CreateLegacy(123)); |
| 2210 | |
| 2211 | // Verify that only one of them has been set, and that it is the one with |
| 2212 | // highest priority (transport sequence number). |
| 2213 | ASSERT_EQ(1u, send_stream->GetConfig().rtp.extensions.size()); |
| 2214 | EXPECT_EQ(expected_id, send_stream->GetConfig().rtp.extensions[0].id); |
| 2215 | EXPECT_EQ(expected_extension, |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2216 | send_stream->GetConfig().rtp.extensions[0].uri); |
Stefan Holmer | bbaf363 | 2015-10-29 18:53:23 +0100 | [diff] [blame] | 2217 | } |
| 2218 | |
asapersson | 3c81a1a | 2017-06-14 05:52:21 -0700 | [diff] [blame] | 2219 | void TestDegradationPreference(bool resolution_scaling_enabled, |
| 2220 | bool fps_scaling_enabled); |
| 2221 | |
Erik Språng | efbde37 | 2015-04-29 16:21:28 +0200 | [diff] [blame] | 2222 | void TestCpuAdaptation(bool enable_overuse, bool is_screenshare); |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 2223 | void TestReceiverLocalSsrcConfiguration(bool receiver_first); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2224 | void TestReceiveUnsignaledSsrcPacket(uint8_t payload_type, |
| 2225 | bool expect_created_receive_stream); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2226 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2227 | FakeVideoSendStream* SetDenoisingOption( |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2228 | uint32_t ssrc, |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 2229 | FakeVideoCapturerWithTaskQueue* capturer, |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 2230 | bool enabled) { |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2231 | cricket::VideoOptions options; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 2232 | options.video_noise_reduction = enabled; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2233 | EXPECT_TRUE(channel_->SetVideoSend(ssrc, &options, capturer)); |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 2234 | // Options only take effect on the next frame. |
| 2235 | EXPECT_TRUE(capturer->CaptureFrame()); |
| 2236 | |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2237 | return fake_call_->GetVideoSendStreams().back(); |
| 2238 | } |
| 2239 | |
Peter Boström | 2feafdb | 2015-09-09 14:32:14 +0200 | [diff] [blame] | 2240 | FakeVideoSendStream* SetUpSimulcast(bool enabled, bool with_rtx) { |
| 2241 | const int kRtxSsrcOffset = 0xDEADBEEF; |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2242 | last_ssrc_ += 3; |
Peter Boström | 2feafdb | 2015-09-09 14:32:14 +0200 | [diff] [blame] | 2243 | std::vector<uint32_t> ssrcs; |
| 2244 | std::vector<uint32_t> rtx_ssrcs; |
| 2245 | uint32_t num_streams = enabled ? 3 : 1; |
| 2246 | for (uint32_t i = 0; i < num_streams; ++i) { |
| 2247 | uint32_t ssrc = last_ssrc_ + i; |
| 2248 | ssrcs.push_back(ssrc); |
| 2249 | if (with_rtx) { |
| 2250 | rtx_ssrcs.push_back(ssrc + kRtxSsrcOffset); |
| 2251 | } |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2252 | } |
Peter Boström | 2feafdb | 2015-09-09 14:32:14 +0200 | [diff] [blame] | 2253 | if (with_rtx) { |
| 2254 | return AddSendStream( |
| 2255 | cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); |
| 2256 | } |
| 2257 | return AddSendStream(CreateSimStreamParams("cname", ssrcs)); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2258 | } |
| 2259 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2260 | int GetMaxEncoderBitrate() { |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 2261 | std::vector<FakeVideoSendStream*> streams = |
| 2262 | fake_call_->GetVideoSendStreams(); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2263 | EXPECT_EQ(1u, streams.size()); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 2264 | FakeVideoSendStream* stream = streams[streams.size() - 1]; |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 2265 | EXPECT_EQ(1u, stream->GetEncoderConfig().number_of_streams); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2266 | return stream->GetVideoStreams()[0].max_bitrate_bps; |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 2267 | } |
| 2268 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2269 | void SetAndExpectMaxBitrate(int global_max, |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 2270 | int stream_max, |
| 2271 | int expected_encoder_bitrate) { |
| 2272 | VideoSendParameters limited_send_params = send_parameters_; |
| 2273 | limited_send_params.max_bandwidth_bps = global_max; |
| 2274 | EXPECT_TRUE(channel_->SetSendParameters(limited_send_params)); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 2275 | webrtc::RtpParameters parameters = |
| 2276 | channel_->GetRtpSendParameters(last_ssrc_); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 2277 | EXPECT_EQ(1UL, parameters.encodings.size()); |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 2278 | parameters.encodings[0].max_bitrate_bps = stream_max; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 2279 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 2280 | // Read back the parameteres and verify they have the correct value |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 2281 | parameters = channel_->GetRtpSendParameters(last_ssrc_); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 2282 | EXPECT_EQ(1UL, parameters.encodings.size()); |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 2283 | EXPECT_EQ(stream_max, parameters.encodings[0].max_bitrate_bps); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 2284 | // Verify that the new value propagated down to the encoder |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2285 | EXPECT_EQ(expected_encoder_bitrate, GetMaxEncoderBitrate()); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 2286 | } |
| 2287 | |
Åsa Persson | 5565981 | 2018-06-18 17:51:32 +0200 | [diff] [blame] | 2288 | // Values from kSimulcastConfigs in simulcast.cc. |
| 2289 | const std::vector<webrtc::VideoStream> GetSimulcastBitrates720p() const { |
| 2290 | std::vector<webrtc::VideoStream> layers(3); |
| 2291 | layers[0].min_bitrate_bps = 30000; |
| 2292 | layers[0].target_bitrate_bps = 150000; |
| 2293 | layers[0].max_bitrate_bps = 200000; |
| 2294 | layers[1].min_bitrate_bps = 150000; |
| 2295 | layers[1].target_bitrate_bps = 500000; |
| 2296 | layers[1].max_bitrate_bps = 700000; |
| 2297 | layers[2].min_bitrate_bps = 600000; |
| 2298 | layers[2].target_bitrate_bps = 2500000; |
| 2299 | layers[2].max_bitrate_bps = 2500000; |
| 2300 | return layers; |
| 2301 | } |
| 2302 | |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 2303 | std::unique_ptr<FakeCall> fake_call_; |
| 2304 | std::unique_ptr<VideoMediaChannel> channel_; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2305 | cricket::VideoSendParameters send_parameters_; |
| 2306 | cricket::VideoRecvParameters recv_parameters_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 2307 | uint32_t last_ssrc_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2308 | }; |
| 2309 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2310 | TEST_F(WebRtcVideoChannelTest, SetsSyncGroupFromSyncLabel) { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 2311 | const uint32_t kVideoSsrc = 123; |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 2312 | const std::string kSyncLabel = "AvSyncLabel"; |
| 2313 | |
| 2314 | cricket::StreamParams sp = cricket::StreamParams::CreateLegacy(kVideoSsrc); |
Seth Hampson | 845e878 | 2018-03-02 11:34:10 -0800 | [diff] [blame] | 2315 | sp.set_stream_ids({kSyncLabel}); |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 2316 | EXPECT_TRUE(channel_->AddRecvStream(sp)); |
| 2317 | |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 2318 | EXPECT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
pbos | 8fc7fa7 | 2015-07-15 08:02:58 -0700 | [diff] [blame] | 2319 | EXPECT_EQ(kSyncLabel, |
| 2320 | fake_call_->GetVideoReceiveStreams()[0]->GetConfig().sync_group) |
| 2321 | << "SyncGroup should be set based on sync_label"; |
| 2322 | } |
| 2323 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2324 | TEST_F(WebRtcVideoChannelTest, RecvStreamWithSimAndRtx) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2325 | cricket::VideoSendParameters parameters; |
| 2326 | parameters.codecs = engine_.codecs(); |
| 2327 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2328 | EXPECT_TRUE(channel_->SetSend(true)); |
nisse | 4b4dc86 | 2016-02-17 05:25:36 -0800 | [diff] [blame] | 2329 | parameters.conference_mode = true; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2330 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2331 | |
| 2332 | // Send side. |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 2333 | const std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs1); |
| 2334 | const std::vector<uint32_t> rtx_ssrcs = MAKE_VECTOR(kRtxSsrcs1); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2335 | FakeVideoSendStream* send_stream = AddSendStream( |
| 2336 | cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); |
| 2337 | |
| 2338 | ASSERT_EQ(rtx_ssrcs.size(), send_stream->GetConfig().rtp.rtx.ssrcs.size()); |
| 2339 | for (size_t i = 0; i < rtx_ssrcs.size(); ++i) |
| 2340 | EXPECT_EQ(rtx_ssrcs[i], send_stream->GetConfig().rtp.rtx.ssrcs[i]); |
| 2341 | |
| 2342 | // Receiver side. |
| 2343 | FakeVideoReceiveStream* recv_stream = AddRecvStream( |
| 2344 | cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); |
nisse | 26e3abb | 2017-08-25 04:44:25 -0700 | [diff] [blame] | 2345 | EXPECT_FALSE( |
| 2346 | recv_stream->GetConfig().rtp.rtx_associated_payload_types.empty()); |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 2347 | EXPECT_TRUE(VerifyRtxReceiveAssociations(recv_stream->GetConfig())) |
Peter Boström | d8b0109 | 2016-05-12 16:44:36 +0200 | [diff] [blame] | 2348 | << "RTX should be mapped for all decoders/payload types."; |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 2349 | EXPECT_TRUE(HasRtxReceiveAssociation(recv_stream->GetConfig(), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2350 | GetEngineCodec("red").id)) |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 2351 | << "RTX should be mapped for the RED payload type"; |
| 2352 | |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 2353 | EXPECT_EQ(rtx_ssrcs[0], recv_stream->GetConfig().rtp.rtx_ssrc); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2354 | } |
| 2355 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2356 | TEST_F(WebRtcVideoChannelTest, RecvStreamWithRtx) { |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 2357 | // Setup one channel with an associated RTX stream. |
| 2358 | cricket::StreamParams params = |
| 2359 | cricket::StreamParams::CreateLegacy(kSsrcs1[0]); |
| 2360 | params.AddFidSsrc(kSsrcs1[0], kRtxSsrcs1[0]); |
| 2361 | FakeVideoReceiveStream* recv_stream = AddRecvStream(params); |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 2362 | EXPECT_EQ(kRtxSsrcs1[0], recv_stream->GetConfig().rtp.rtx_ssrc); |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 2363 | |
| 2364 | EXPECT_TRUE(VerifyRtxReceiveAssociations(recv_stream->GetConfig())) |
| 2365 | << "RTX should be mapped for all decoders/payload types."; |
| 2366 | EXPECT_TRUE(HasRtxReceiveAssociation(recv_stream->GetConfig(), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2367 | GetEngineCodec("red").id)) |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 2368 | << "RTX should be mapped for the RED payload type"; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2369 | } |
| 2370 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2371 | TEST_F(WebRtcVideoChannelTest, RecvStreamNoRtx) { |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 2372 | // Setup one channel without an associated RTX stream. |
| 2373 | cricket::StreamParams params = |
| 2374 | cricket::StreamParams::CreateLegacy(kSsrcs1[0]); |
| 2375 | FakeVideoReceiveStream* recv_stream = AddRecvStream(params); |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 2376 | ASSERT_EQ(0U, recv_stream->GetConfig().rtp.rtx_ssrc); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2377 | } |
| 2378 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2379 | TEST_F(WebRtcVideoChannelTest, NoHeaderExtesionsByDefault) { |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2380 | FakeVideoSendStream* send_stream = |
| 2381 | AddSendStream(cricket::StreamParams::CreateLegacy(kSsrcs1[0])); |
| 2382 | ASSERT_TRUE(send_stream->GetConfig().rtp.extensions.empty()); |
| 2383 | |
| 2384 | FakeVideoReceiveStream* recv_stream = |
| 2385 | AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrcs1[0])); |
| 2386 | ASSERT_TRUE(recv_stream->GetConfig().rtp.extensions.empty()); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2387 | } |
| 2388 | |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2389 | // Test support for RTP timestamp offset header extension. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2390 | TEST_F(WebRtcVideoChannelTest, SendRtpTimestampOffsetHeaderExtensions) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2391 | TestSetSendRtpHeaderExtensions(RtpExtension::kTimestampOffsetUri); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2392 | } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2393 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2394 | TEST_F(WebRtcVideoChannelTest, RecvRtpTimestampOffsetHeaderExtensions) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2395 | TestSetRecvRtpHeaderExtensions(RtpExtension::kTimestampOffsetUri); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2396 | } |
| 2397 | |
| 2398 | // Test support for absolute send time header extension. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2399 | TEST_F(WebRtcVideoChannelTest, SendAbsoluteSendTimeHeaderExtensions) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2400 | TestSetSendRtpHeaderExtensions(RtpExtension::kAbsSendTimeUri); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 2401 | } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2402 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2403 | TEST_F(WebRtcVideoChannelTest, RecvAbsoluteSendTimeHeaderExtensions) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2404 | TestSetRecvRtpHeaderExtensions(RtpExtension::kAbsSendTimeUri); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2405 | } |
| 2406 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2407 | TEST_F(WebRtcVideoChannelTest, FiltersExtensionsPicksTransportSeqNum) { |
Stefan Holmer | bbaf363 | 2015-10-29 18:53:23 +0100 | [diff] [blame] | 2408 | // Enable three redundant extensions. |
| 2409 | std::vector<std::string> extensions; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2410 | extensions.push_back(RtpExtension::kAbsSendTimeUri); |
| 2411 | extensions.push_back(RtpExtension::kTimestampOffsetUri); |
| 2412 | extensions.push_back(RtpExtension::kTransportSequenceNumberUri); |
| 2413 | TestExtensionFilter(extensions, RtpExtension::kTransportSequenceNumberUri); |
Stefan Holmer | bbaf363 | 2015-10-29 18:53:23 +0100 | [diff] [blame] | 2414 | } |
| 2415 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2416 | TEST_F(WebRtcVideoChannelTest, FiltersExtensionsPicksAbsSendTime) { |
Stefan Holmer | bbaf363 | 2015-10-29 18:53:23 +0100 | [diff] [blame] | 2417 | // Enable two redundant extensions. |
| 2418 | std::vector<std::string> extensions; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2419 | extensions.push_back(RtpExtension::kAbsSendTimeUri); |
| 2420 | extensions.push_back(RtpExtension::kTimestampOffsetUri); |
| 2421 | TestExtensionFilter(extensions, RtpExtension::kAbsSendTimeUri); |
Stefan Holmer | bbaf363 | 2015-10-29 18:53:23 +0100 | [diff] [blame] | 2422 | } |
| 2423 | |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 2424 | // Test support for transport sequence number header extension. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2425 | TEST_F(WebRtcVideoChannelTest, SendTransportSequenceNumberHeaderExtensions) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2426 | TestSetSendRtpHeaderExtensions(RtpExtension::kTransportSequenceNumberUri); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 2427 | } |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2428 | TEST_F(WebRtcVideoChannelTest, RecvTransportSequenceNumberHeaderExtensions) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2429 | TestSetRecvRtpHeaderExtensions(RtpExtension::kTransportSequenceNumberUri); |
stefan | c1aeaf0 | 2015-10-15 07:26:07 -0700 | [diff] [blame] | 2430 | } |
| 2431 | |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 2432 | // Test support for video rotation header extension. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2433 | TEST_F(WebRtcVideoChannelTest, SendVideoRotationHeaderExtensions) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2434 | TestSetSendRtpHeaderExtensions(RtpExtension::kVideoRotationUri); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 2435 | } |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2436 | TEST_F(WebRtcVideoChannelTest, RecvVideoRotationHeaderExtensions) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2437 | TestSetRecvRtpHeaderExtensions(RtpExtension::kVideoRotationUri); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 2438 | } |
| 2439 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2440 | TEST_F(WebRtcVideoChannelTest, IdenticalSendExtensionsDoesntRecreateStream) { |
Stefan Holmer | bbaf363 | 2015-10-29 18:53:23 +0100 | [diff] [blame] | 2441 | const int kAbsSendTimeId = 1; |
| 2442 | const int kVideoRotationId = 2; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2443 | send_parameters_.extensions.push_back( |
| 2444 | RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeId)); |
| 2445 | send_parameters_.extensions.push_back( |
| 2446 | RtpExtension(RtpExtension::kVideoRotationUri, kVideoRotationId)); |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2447 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2448 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2449 | FakeVideoSendStream* send_stream = |
| 2450 | AddSendStream(cricket::StreamParams::CreateLegacy(123)); |
| 2451 | |
| 2452 | EXPECT_EQ(1, fake_call_->GetNumCreatedSendStreams()); |
Stefan Holmer | bbaf363 | 2015-10-29 18:53:23 +0100 | [diff] [blame] | 2453 | ASSERT_EQ(2u, send_stream->GetConfig().rtp.extensions.size()); |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2454 | |
| 2455 | // Setting the same extensions (even if in different order) shouldn't |
| 2456 | // reallocate the stream. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2457 | std::reverse(send_parameters_.extensions.begin(), |
| 2458 | send_parameters_.extensions.end()); |
| 2459 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2460 | |
| 2461 | EXPECT_EQ(1, fake_call_->GetNumCreatedSendStreams()); |
| 2462 | |
| 2463 | // Setting different extensions should recreate the stream. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2464 | send_parameters_.extensions.resize(1); |
| 2465 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2466 | |
| 2467 | EXPECT_EQ(2, fake_call_->GetNumCreatedSendStreams()); |
| 2468 | } |
| 2469 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2470 | TEST_F(WebRtcVideoChannelTest, IdenticalRecvExtensionsDoesntRecreateStream) { |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2471 | const int kTOffsetId = 1; |
| 2472 | const int kAbsSendTimeId = 2; |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 2473 | const int kVideoRotationId = 3; |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2474 | recv_parameters_.extensions.push_back( |
| 2475 | RtpExtension(RtpExtension::kAbsSendTimeUri, kAbsSendTimeId)); |
| 2476 | recv_parameters_.extensions.push_back( |
| 2477 | RtpExtension(RtpExtension::kTimestampOffsetUri, kTOffsetId)); |
| 2478 | recv_parameters_.extensions.push_back( |
| 2479 | RtpExtension(RtpExtension::kVideoRotationUri, kVideoRotationId)); |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2480 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2481 | EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
Peter Boström | 54be3e0 | 2015-05-25 15:04:24 +0200 | [diff] [blame] | 2482 | FakeVideoReceiveStream* recv_stream = |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2483 | AddRecvStream(cricket::StreamParams::CreateLegacy(123)); |
| 2484 | |
| 2485 | EXPECT_EQ(1, fake_call_->GetNumCreatedReceiveStreams()); |
Peter Boström | 54be3e0 | 2015-05-25 15:04:24 +0200 | [diff] [blame] | 2486 | ASSERT_EQ(3u, recv_stream->GetConfig().rtp.extensions.size()); |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2487 | |
| 2488 | // Setting the same extensions (even if in different order) shouldn't |
| 2489 | // reallocate the stream. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2490 | std::reverse(recv_parameters_.extensions.begin(), |
| 2491 | recv_parameters_.extensions.end()); |
| 2492 | EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2493 | |
| 2494 | EXPECT_EQ(1, fake_call_->GetNumCreatedReceiveStreams()); |
| 2495 | |
| 2496 | // Setting different extensions should recreate the stream. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2497 | recv_parameters_.extensions.resize(1); |
| 2498 | EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 2499 | |
| 2500 | EXPECT_EQ(2, fake_call_->GetNumCreatedReceiveStreams()); |
| 2501 | } |
| 2502 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2503 | TEST_F(WebRtcVideoChannelTest, |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2504 | SetSendRtpHeaderExtensionsExcludeUnsupportedExtensions) { |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2505 | const int kUnsupportedId = 1; |
| 2506 | const int kTOffsetId = 2; |
| 2507 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2508 | send_parameters_.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2509 | RtpExtension(kUnsupportedExtensionName, kUnsupportedId)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2510 | send_parameters_.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2511 | RtpExtension(RtpExtension::kTimestampOffsetUri, kTOffsetId)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2512 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2513 | FakeVideoSendStream* send_stream = |
| 2514 | AddSendStream(cricket::StreamParams::CreateLegacy(123)); |
| 2515 | |
| 2516 | // Only timestamp offset extension is set to send stream, |
| 2517 | // unsupported rtp extension is ignored. |
| 2518 | ASSERT_EQ(1u, send_stream->GetConfig().rtp.extensions.size()); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2519 | EXPECT_STREQ(RtpExtension::kTimestampOffsetUri, |
| 2520 | send_stream->GetConfig().rtp.extensions[0].uri.c_str()); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2521 | } |
| 2522 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2523 | TEST_F(WebRtcVideoChannelTest, |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2524 | SetRecvRtpHeaderExtensionsExcludeUnsupportedExtensions) { |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2525 | const int kUnsupportedId = 1; |
| 2526 | const int kTOffsetId = 2; |
| 2527 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2528 | recv_parameters_.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2529 | RtpExtension(kUnsupportedExtensionName, kUnsupportedId)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2530 | recv_parameters_.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2531 | RtpExtension(RtpExtension::kTimestampOffsetUri, kTOffsetId)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2532 | EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2533 | FakeVideoReceiveStream* recv_stream = |
| 2534 | AddRecvStream(cricket::StreamParams::CreateLegacy(123)); |
| 2535 | |
| 2536 | // Only timestamp offset extension is set to receive stream, |
| 2537 | // unsupported rtp extension is ignored. |
| 2538 | ASSERT_EQ(1u, recv_stream->GetConfig().rtp.extensions.size()); |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2539 | EXPECT_STREQ(RtpExtension::kTimestampOffsetUri, |
| 2540 | recv_stream->GetConfig().rtp.extensions[0].uri.c_str()); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2541 | } |
| 2542 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2543 | TEST_F(WebRtcVideoChannelTest, SetSendRtpHeaderExtensionsRejectsIncorrectIds) { |
Peter Boström | 23914fe | 2015-03-31 15:08:04 +0200 | [diff] [blame] | 2544 | const int kIncorrectIds[] = {-2, -1, 0, 15, 16}; |
pkasting@chromium.org | e7a4a12 | 2015-01-28 21:36:55 +0000 | [diff] [blame] | 2545 | for (size_t i = 0; i < arraysize(kIncorrectIds); ++i) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2546 | send_parameters_.extensions.push_back( |
| 2547 | RtpExtension(RtpExtension::kTimestampOffsetUri, kIncorrectIds[i])); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2548 | EXPECT_FALSE(channel_->SetSendParameters(send_parameters_)) |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2549 | << "Bad extension id '" << kIncorrectIds[i] << "' accepted."; |
| 2550 | } |
| 2551 | } |
| 2552 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2553 | TEST_F(WebRtcVideoChannelTest, SetRecvRtpHeaderExtensionsRejectsIncorrectIds) { |
Peter Boström | 23914fe | 2015-03-31 15:08:04 +0200 | [diff] [blame] | 2554 | const int kIncorrectIds[] = {-2, -1, 0, 15, 16}; |
pkasting@chromium.org | e7a4a12 | 2015-01-28 21:36:55 +0000 | [diff] [blame] | 2555 | for (size_t i = 0; i < arraysize(kIncorrectIds); ++i) { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2556 | recv_parameters_.extensions.push_back( |
| 2557 | RtpExtension(RtpExtension::kTimestampOffsetUri, kIncorrectIds[i])); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2558 | EXPECT_FALSE(channel_->SetRecvParameters(recv_parameters_)) |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2559 | << "Bad extension id '" << kIncorrectIds[i] << "' accepted."; |
| 2560 | } |
| 2561 | } |
| 2562 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2563 | TEST_F(WebRtcVideoChannelTest, SetSendRtpHeaderExtensionsRejectsDuplicateIds) { |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2564 | const int id = 1; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2565 | send_parameters_.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2566 | RtpExtension(RtpExtension::kTimestampOffsetUri, id)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2567 | send_parameters_.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2568 | RtpExtension(RtpExtension::kAbsSendTimeUri, id)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2569 | EXPECT_FALSE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2570 | |
| 2571 | // Duplicate entries are also not supported. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2572 | send_parameters_.extensions.clear(); |
| 2573 | send_parameters_.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2574 | RtpExtension(RtpExtension::kTimestampOffsetUri, id)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2575 | send_parameters_.extensions.push_back(send_parameters_.extensions.back()); |
| 2576 | EXPECT_FALSE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2577 | } |
| 2578 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2579 | TEST_F(WebRtcVideoChannelTest, SetRecvRtpHeaderExtensionsRejectsDuplicateIds) { |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2580 | const int id = 1; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2581 | recv_parameters_.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2582 | RtpExtension(RtpExtension::kTimestampOffsetUri, id)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2583 | recv_parameters_.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2584 | RtpExtension(RtpExtension::kAbsSendTimeUri, id)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2585 | EXPECT_FALSE(channel_->SetRecvParameters(recv_parameters_)); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2586 | |
| 2587 | // Duplicate entries are also not supported. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2588 | recv_parameters_.extensions.clear(); |
| 2589 | recv_parameters_.extensions.push_back( |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 2590 | RtpExtension(RtpExtension::kTimestampOffsetUri, id)); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2591 | recv_parameters_.extensions.push_back(recv_parameters_.extensions.back()); |
| 2592 | EXPECT_FALSE(channel_->SetRecvParameters(recv_parameters_)); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 2593 | } |
| 2594 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2595 | TEST_F(WebRtcVideoChannelTest, AddRecvStreamOnlyUsesOneReceiveStream) { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2596 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2597 | EXPECT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2598 | } |
| 2599 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2600 | TEST_F(WebRtcVideoChannelTest, RtcpIsCompoundByDefault) { |
Peter Boström | d7da120 | 2015-06-05 14:09:38 +0200 | [diff] [blame] | 2601 | FakeVideoReceiveStream* stream = AddRecvStream(); |
pbos | da903ea | 2015-10-02 02:36:56 -0700 | [diff] [blame] | 2602 | EXPECT_EQ(webrtc::RtcpMode::kCompound, stream->GetConfig().rtp.rtcp_mode); |
Peter Boström | d7da120 | 2015-06-05 14:09:38 +0200 | [diff] [blame] | 2603 | } |
| 2604 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2605 | TEST_F(WebRtcVideoChannelTest, RembIsEnabledByDefault) { |
pbos@webrtc.org | 257e130 | 2014-07-25 19:01:32 +0000 | [diff] [blame] | 2606 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 2607 | EXPECT_TRUE(stream->GetConfig().rtp.remb); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2608 | } |
| 2609 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2610 | TEST_F(WebRtcVideoChannelTest, TransportCcIsEnabledByDefault) { |
stefan | 43edf0f | 2015-11-20 18:05:48 -0800 | [diff] [blame] | 2611 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 2612 | EXPECT_TRUE(stream->GetConfig().rtp.transport_cc); |
| 2613 | } |
| 2614 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2615 | TEST_F(WebRtcVideoChannelTest, RembCanBeEnabledAndDisabled) { |
pbos@webrtc.org | 257e130 | 2014-07-25 19:01:32 +0000 | [diff] [blame] | 2616 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 2617 | EXPECT_TRUE(stream->GetConfig().rtp.remb); |
| 2618 | |
Peter Boström | 126c03e | 2015-05-11 12:48:12 +0200 | [diff] [blame] | 2619 | // 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] | 2620 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2621 | parameters.codecs.push_back(RemoveFeedbackParams(GetEngineCodec("VP8"))); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2622 | EXPECT_TRUE(parameters.codecs[0].feedback_params.params().empty()); |
| 2623 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2624 | stream = fake_call_->GetVideoReceiveStreams()[0]; |
pbos@webrtc.org | 257e130 | 2014-07-25 19:01:32 +0000 | [diff] [blame] | 2625 | EXPECT_FALSE(stream->GetConfig().rtp.remb); |
| 2626 | |
| 2627 | // Verify that REMB is turned on when setting default codecs since the |
| 2628 | // default codecs have REMB enabled. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2629 | parameters.codecs = engine_.codecs(); |
| 2630 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2631 | stream = fake_call_->GetVideoReceiveStreams()[0]; |
pbos@webrtc.org | 257e130 | 2014-07-25 19:01:32 +0000 | [diff] [blame] | 2632 | EXPECT_TRUE(stream->GetConfig().rtp.remb); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2633 | } |
| 2634 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2635 | TEST_F(WebRtcVideoChannelTest, TransportCcCanBeEnabledAndDisabled) { |
stefan | 43edf0f | 2015-11-20 18:05:48 -0800 | [diff] [blame] | 2636 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 2637 | EXPECT_TRUE(stream->GetConfig().rtp.transport_cc); |
| 2638 | |
| 2639 | // Verify that transport cc feedback is turned off when send(!) codecs without |
| 2640 | // transport cc feedback are set. |
| 2641 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2642 | parameters.codecs.push_back(RemoveFeedbackParams(GetEngineCodec("VP8"))); |
stefan | 43edf0f | 2015-11-20 18:05:48 -0800 | [diff] [blame] | 2643 | EXPECT_TRUE(parameters.codecs[0].feedback_params.params().empty()); |
| 2644 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 2645 | stream = fake_call_->GetVideoReceiveStreams()[0]; |
| 2646 | EXPECT_FALSE(stream->GetConfig().rtp.transport_cc); |
| 2647 | |
| 2648 | // Verify that transport cc feedback is turned on when setting default codecs |
| 2649 | // since the default codecs have transport cc feedback enabled. |
| 2650 | parameters.codecs = engine_.codecs(); |
| 2651 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 2652 | stream = fake_call_->GetVideoReceiveStreams()[0]; |
| 2653 | EXPECT_TRUE(stream->GetConfig().rtp.transport_cc); |
| 2654 | } |
| 2655 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2656 | TEST_F(WebRtcVideoChannelTest, NackIsEnabledByDefault) { |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 2657 | AssignDefaultCodec(); |
pbos@webrtc.org | f99c2f2 | 2014-06-13 12:27:38 +0000 | [diff] [blame] | 2658 | VerifyCodecHasDefaultFeedbackParams(default_codec_); |
| 2659 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2660 | cricket::VideoSendParameters parameters; |
| 2661 | parameters.codecs = engine_.codecs(); |
| 2662 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 1986474 | 2014-05-30 07:35:47 +0000 | [diff] [blame] | 2663 | EXPECT_TRUE(channel_->SetSend(true)); |
| 2664 | |
| 2665 | // Send side. |
| 2666 | FakeVideoSendStream* send_stream = |
| 2667 | AddSendStream(cricket::StreamParams::CreateLegacy(1)); |
| 2668 | EXPECT_GT(send_stream->GetConfig().rtp.nack.rtp_history_ms, 0); |
| 2669 | |
| 2670 | // Receiver side. |
| 2671 | FakeVideoReceiveStream* recv_stream = |
| 2672 | AddRecvStream(cricket::StreamParams::CreateLegacy(1)); |
| 2673 | EXPECT_GT(recv_stream->GetConfig().rtp.nack.rtp_history_ms, 0); |
| 2674 | |
| 2675 | // Nack history size should match between sender and receiver. |
| 2676 | EXPECT_EQ(send_stream->GetConfig().rtp.nack.rtp_history_ms, |
| 2677 | recv_stream->GetConfig().rtp.nack.rtp_history_ms); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2678 | } |
| 2679 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2680 | TEST_F(WebRtcVideoChannelTest, NackCanBeEnabledAndDisabled) { |
Peter Boström | 67c9df7 | 2015-05-11 14:34:58 +0200 | [diff] [blame] | 2681 | FakeVideoSendStream* send_stream = AddSendStream(); |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 2682 | FakeVideoReceiveStream* recv_stream = AddRecvStream(); |
Peter Boström | 67c9df7 | 2015-05-11 14:34:58 +0200 | [diff] [blame] | 2683 | |
| 2684 | EXPECT_GT(recv_stream->GetConfig().rtp.nack.rtp_history_ms, 0); |
| 2685 | EXPECT_GT(send_stream->GetConfig().rtp.nack.rtp_history_ms, 0); |
| 2686 | |
| 2687 | // 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] | 2688 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2689 | parameters.codecs.push_back(RemoveFeedbackParams(GetEngineCodec("VP8"))); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2690 | EXPECT_TRUE(parameters.codecs[0].feedback_params.params().empty()); |
| 2691 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
Peter Boström | 67c9df7 | 2015-05-11 14:34:58 +0200 | [diff] [blame] | 2692 | recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
| 2693 | EXPECT_EQ(0, recv_stream->GetConfig().rtp.nack.rtp_history_ms); |
| 2694 | send_stream = fake_call_->GetVideoSendStreams()[0]; |
pbos@webrtc.org | f99c2f2 | 2014-06-13 12:27:38 +0000 | [diff] [blame] | 2695 | EXPECT_EQ(0, send_stream->GetConfig().rtp.nack.rtp_history_ms); |
| 2696 | |
Peter Boström | 67c9df7 | 2015-05-11 14:34:58 +0200 | [diff] [blame] | 2697 | // Verify that NACK is turned on when setting default codecs since the |
| 2698 | // default codecs have NACK enabled. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2699 | parameters.codecs = engine_.codecs(); |
| 2700 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
Peter Boström | 67c9df7 | 2015-05-11 14:34:58 +0200 | [diff] [blame] | 2701 | recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
| 2702 | EXPECT_GT(recv_stream->GetConfig().rtp.nack.rtp_history_ms, 0); |
| 2703 | send_stream = fake_call_->GetVideoSendStreams()[0]; |
| 2704 | EXPECT_GT(send_stream->GetConfig().rtp.nack.rtp_history_ms, 0); |
pbos@webrtc.org | f99c2f2 | 2014-06-13 12:27:38 +0000 | [diff] [blame] | 2705 | } |
| 2706 | |
Peter Boström | e7ba086 | 2016-03-12 00:02:28 +0100 | [diff] [blame] | 2707 | // This test verifies that new frame sizes reconfigures encoders even though not |
| 2708 | // (yet) sending. The purpose of this is to permit encoding as quickly as |
| 2709 | // possible once we start sending. Likely the frames being input are from the |
| 2710 | // same source that will be sent later, which just means that we're ready |
| 2711 | // earlier. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2712 | TEST_F(WebRtcVideoChannelTest, ReconfiguresEncodersWhenNotSending) { |
Peter Boström | e7ba086 | 2016-03-12 00:02:28 +0100 | [diff] [blame] | 2713 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2714 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Peter Boström | e7ba086 | 2016-03-12 00:02:28 +0100 | [diff] [blame] | 2715 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 2716 | channel_->SetSend(false); |
| 2717 | |
| 2718 | FakeVideoSendStream* stream = AddSendStream(); |
| 2719 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2720 | // No frames entered. |
Peter Boström | e7ba086 | 2016-03-12 00:02:28 +0100 | [diff] [blame] | 2721 | std::vector<webrtc::VideoStream> streams = stream->GetVideoStreams(); |
Danil Chapovalov | 350531e | 2018-06-08 11:04:04 +0000 | [diff] [blame] | 2722 | EXPECT_EQ(0u, streams[0].width); |
| 2723 | EXPECT_EQ(0u, streams[0].height); |
Peter Boström | e7ba086 | 2016-03-12 00:02:28 +0100 | [diff] [blame] | 2724 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 2725 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2726 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, &capturer)); |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 2727 | VideoFormat capture_format = capturer.GetSupportedFormats()->front(); |
| 2728 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format)); |
Peter Boström | e7ba086 | 2016-03-12 00:02:28 +0100 | [diff] [blame] | 2729 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 2730 | |
| 2731 | // Frame entered, should be reconfigured to new dimensions. |
| 2732 | streams = stream->GetVideoStreams(); |
Danil Chapovalov | 350531e | 2018-06-08 11:04:04 +0000 | [diff] [blame] | 2733 | EXPECT_EQ(rtc::checked_cast<size_t>(capture_format.width), streams[0].width); |
| 2734 | EXPECT_EQ(rtc::checked_cast<size_t>(capture_format.height), |
| 2735 | streams[0].height); |
Peter Boström | e7ba086 | 2016-03-12 00:02:28 +0100 | [diff] [blame] | 2736 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2737 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
Peter Boström | e7ba086 | 2016-03-12 00:02:28 +0100 | [diff] [blame] | 2738 | } |
| 2739 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2740 | TEST_F(WebRtcVideoChannelTest, UsesCorrectSettingsForScreencast) { |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 2741 | static const int kScreenshareMinBitrateKbps = 800; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2742 | cricket::VideoCodec codec = GetEngineCodec("VP8"); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2743 | cricket::VideoSendParameters parameters; |
| 2744 | parameters.codecs.push_back(codec); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2745 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 2746 | AddSendStream(); |
| 2747 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 2748 | FakeVideoCapturerWithTaskQueue capturer; |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2749 | VideoOptions min_bitrate_options; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 2750 | min_bitrate_options.screencast_min_bitrate_kbps = kScreenshareMinBitrateKbps; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 2751 | EXPECT_TRUE( |
| 2752 | channel_->SetVideoSend(last_ssrc_, &min_bitrate_options, &capturer)); |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 2753 | cricket::VideoFormat capture_format_hd = |
| 2754 | capturer.GetSupportedFormats()->front(); |
| 2755 | EXPECT_EQ(1280, capture_format_hd.width); |
| 2756 | EXPECT_EQ(720, capture_format_hd.height); |
| 2757 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format_hd)); |
| 2758 | |
| 2759 | EXPECT_TRUE(channel_->SetSend(true)); |
| 2760 | |
| 2761 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 2762 | ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| 2763 | FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
| 2764 | |
| 2765 | EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
| 2766 | |
| 2767 | // Verify non-screencast settings. |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2768 | webrtc::VideoEncoderConfig encoder_config = |
| 2769 | send_stream->GetEncoderConfig().Copy(); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2770 | EXPECT_EQ(webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo, |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 2771 | encoder_config.content_type); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2772 | std::vector<webrtc::VideoStream> streams = send_stream->GetVideoStreams(); |
Danil Chapovalov | 350531e | 2018-06-08 11:04:04 +0000 | [diff] [blame] | 2773 | EXPECT_EQ(rtc::checked_cast<size_t>(capture_format_hd.width), |
| 2774 | streams.front().width); |
| 2775 | EXPECT_EQ(rtc::checked_cast<size_t>(capture_format_hd.height), |
| 2776 | streams.front().height); |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 2777 | EXPECT_EQ(0, encoder_config.min_transmit_bitrate_bps) |
| 2778 | << "Non-screenshare shouldn't use min-transmit bitrate."; |
| 2779 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2780 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
perkj | d533aec | 2017-01-13 05:57:25 -0800 | [diff] [blame] | 2781 | EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2782 | VideoOptions screencast_options; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 2783 | screencast_options.is_screencast = true; |
deadbeef | 5a4a75a | 2016-06-02 16:23:38 -0700 | [diff] [blame] | 2784 | EXPECT_TRUE( |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2785 | channel_->SetVideoSend(last_ssrc_, &screencast_options, &capturer)); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 2786 | EXPECT_TRUE(capturer.CaptureFrame()); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 2787 | // Send stream recreated after option change. |
| 2788 | ASSERT_EQ(2, fake_call_->GetNumCreatedSendStreams()); |
| 2789 | send_stream = fake_call_->GetVideoSendStreams().front(); |
| 2790 | EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 2791 | |
| 2792 | // Verify screencast settings. |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2793 | encoder_config = send_stream->GetEncoderConfig().Copy(); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2794 | EXPECT_EQ(webrtc::VideoEncoderConfig::ContentType::kScreen, |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 2795 | encoder_config.content_type); |
| 2796 | EXPECT_EQ(kScreenshareMinBitrateKbps * 1000, |
| 2797 | encoder_config.min_transmit_bitrate_bps); |
| 2798 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2799 | streams = send_stream->GetVideoStreams(); |
Danil Chapovalov | 350531e | 2018-06-08 11:04:04 +0000 | [diff] [blame] | 2800 | EXPECT_EQ(rtc::checked_cast<size_t>(capture_format_hd.width), |
| 2801 | streams.front().width); |
| 2802 | EXPECT_EQ(rtc::checked_cast<size_t>(capture_format_hd.height), |
| 2803 | streams.front().height); |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 2804 | EXPECT_FALSE(streams[0].num_temporal_layers.has_value()); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2805 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2806 | } |
| 2807 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2808 | TEST_F(WebRtcVideoChannelTest, |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2809 | ConferenceModeScreencastConfiguresTemporalLayer) { |
Rasmus Brandt | 195d1d7 | 2018-05-09 11:28:01 +0200 | [diff] [blame] | 2810 | static const int kConferenceScreencastTemporalBitrateBps = 200 * 1000; |
nisse | 4b4dc86 | 2016-02-17 05:25:36 -0800 | [diff] [blame] | 2811 | send_parameters_.conference_mode = true; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2812 | channel_->SetSendParameters(send_parameters_); |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2813 | |
| 2814 | AddSendStream(); |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2815 | VideoOptions options; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 2816 | options.is_screencast = true; |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 2817 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2818 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2819 | cricket::VideoFormat capture_format_hd = |
| 2820 | capturer.GetSupportedFormats()->front(); |
| 2821 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format_hd)); |
| 2822 | |
| 2823 | EXPECT_TRUE(channel_->SetSend(true)); |
| 2824 | |
| 2825 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 2826 | ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| 2827 | FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
| 2828 | |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2829 | webrtc::VideoEncoderConfig encoder_config = |
| 2830 | send_stream->GetEncoderConfig().Copy(); |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2831 | |
| 2832 | // Verify screencast settings. |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 2833 | encoder_config = send_stream->GetEncoderConfig().Copy(); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2834 | EXPECT_EQ(webrtc::VideoEncoderConfig::ContentType::kScreen, |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2835 | encoder_config.content_type); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2836 | |
| 2837 | std::vector<webrtc::VideoStream> streams = send_stream->GetVideoStreams(); |
| 2838 | ASSERT_EQ(1u, streams.size()); |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 2839 | ASSERT_EQ(2u, streams[0].num_temporal_layers); |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 2840 | EXPECT_EQ(kConferenceScreencastTemporalBitrateBps, |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 2841 | streams[0].target_bitrate_bps); |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 2842 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2843 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2844 | } |
| 2845 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2846 | TEST_F(WebRtcVideoChannelTest, SuspendBelowMinBitrateDisabledByDefault) { |
pbos@webrtc.org | 5ff71ab | 2014-07-23 07:28:56 +0000 | [diff] [blame] | 2847 | FakeVideoSendStream* stream = AddSendStream(); |
| 2848 | EXPECT_FALSE(stream->GetConfig().suspend_below_min_bitrate); |
| 2849 | } |
| 2850 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2851 | TEST_F(WebRtcVideoChannelTest, SetMediaConfigSuspendBelowMinBitrate) { |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 2852 | MediaConfig media_config = GetMediaConfig(); |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 2853 | media_config.video.suspend_below_min_bitrate = true; |
| 2854 | |
| 2855 | channel_.reset( |
| 2856 | engine_.CreateChannel(fake_call_.get(), media_config, VideoOptions())); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 2857 | channel_->OnReadyToSend(true); |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 2858 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2859 | channel_->SetSendParameters(send_parameters_); |
pbos@webrtc.org | 5ff71ab | 2014-07-23 07:28:56 +0000 | [diff] [blame] | 2860 | |
| 2861 | FakeVideoSendStream* stream = AddSendStream(); |
| 2862 | EXPECT_TRUE(stream->GetConfig().suspend_below_min_bitrate); |
| 2863 | |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 2864 | media_config.video.suspend_below_min_bitrate = false; |
| 2865 | channel_.reset( |
| 2866 | engine_.CreateChannel(fake_call_.get(), media_config, VideoOptions())); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 2867 | channel_->OnReadyToSend(true); |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 2868 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2869 | channel_->SetSendParameters(send_parameters_); |
pbos@webrtc.org | 5ff71ab | 2014-07-23 07:28:56 +0000 | [diff] [blame] | 2870 | |
nisse | 0db023a | 2016-03-01 04:29:59 -0800 | [diff] [blame] | 2871 | stream = AddSendStream(); |
pbos@webrtc.org | 5ff71ab | 2014-07-23 07:28:56 +0000 | [diff] [blame] | 2872 | EXPECT_FALSE(stream->GetConfig().suspend_below_min_bitrate); |
| 2873 | } |
| 2874 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2875 | TEST_F(WebRtcVideoChannelTest, Vp8DenoisingEnabledByDefault) { |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 2876 | FakeVideoSendStream* stream = AddSendStream(); |
| 2877 | webrtc::VideoCodecVP8 vp8_settings; |
| 2878 | ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| 2879 | EXPECT_TRUE(vp8_settings.denoisingOn); |
| 2880 | } |
| 2881 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2882 | TEST_F(WebRtcVideoChannelTest, VerifyVp8SpecificSettings) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2883 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2884 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 2885 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 2886 | |
Peter Boström | 2feafdb | 2015-09-09 14:32:14 +0200 | [diff] [blame] | 2887 | // Single-stream settings should apply with RTX as well (verifies that we |
| 2888 | // check number of regular SSRCs and not StreamParams::ssrcs which contains |
| 2889 | // both RTX and regular SSRCs). |
| 2890 | FakeVideoSendStream* stream = SetUpSimulcast(false, true); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2891 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 2892 | FakeVideoCapturerWithTaskQueue capturer; |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2893 | EXPECT_EQ(cricket::CS_RUNNING, |
| 2894 | capturer.Start(capturer.GetSupportedFormats()->front())); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2895 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, &capturer)); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2896 | channel_->SetSend(true); |
| 2897 | |
| 2898 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 2899 | |
pbos | 4cba4eb | 2015-10-26 11:18:18 -0700 | [diff] [blame] | 2900 | webrtc::VideoCodecVP8 vp8_settings; |
| 2901 | ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| 2902 | EXPECT_TRUE(vp8_settings.denoisingOn) |
| 2903 | << "VP8 denoising should be on by default."; |
| 2904 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2905 | stream = SetDenoisingOption(last_ssrc_, &capturer, false); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2906 | |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 2907 | ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| 2908 | EXPECT_FALSE(vp8_settings.denoisingOn); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2909 | EXPECT_TRUE(vp8_settings.automaticResizeOn); |
| 2910 | EXPECT_TRUE(vp8_settings.frameDroppingOn); |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 2911 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2912 | stream = SetDenoisingOption(last_ssrc_, &capturer, true); |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 2913 | |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 2914 | ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| 2915 | EXPECT_TRUE(vp8_settings.denoisingOn); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2916 | EXPECT_TRUE(vp8_settings.automaticResizeOn); |
| 2917 | EXPECT_TRUE(vp8_settings.frameDroppingOn); |
| 2918 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2919 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
Peter Boström | 2feafdb | 2015-09-09 14:32:14 +0200 | [diff] [blame] | 2920 | stream = SetUpSimulcast(true, false); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2921 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, &capturer)); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2922 | channel_->SetSend(true); |
| 2923 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 2924 | |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 2925 | EXPECT_EQ(3u, stream->GetVideoStreams().size()); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2926 | ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| 2927 | // Autmatic resize off when using simulcast. |
| 2928 | EXPECT_FALSE(vp8_settings.automaticResizeOn); |
| 2929 | EXPECT_TRUE(vp8_settings.frameDroppingOn); |
| 2930 | |
| 2931 | // In screen-share mode, denoising is forced off and simulcast disabled. |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2932 | VideoOptions options; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 2933 | options.is_screencast = true; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2934 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
Niels Möller | 60653ba | 2016-03-02 11:41:36 +0100 | [diff] [blame] | 2935 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2936 | stream = SetDenoisingOption(last_ssrc_, &capturer, false); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2937 | |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 2938 | EXPECT_EQ(1u, stream->GetVideoStreams().size()); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2939 | ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| 2940 | EXPECT_FALSE(vp8_settings.denoisingOn); |
| 2941 | // Resizing and frame dropping always off for screen sharing. |
| 2942 | EXPECT_FALSE(vp8_settings.automaticResizeOn); |
| 2943 | EXPECT_FALSE(vp8_settings.frameDroppingOn); |
| 2944 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 2945 | stream = SetDenoisingOption(last_ssrc_, &capturer, true); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2946 | |
| 2947 | ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; |
| 2948 | EXPECT_FALSE(vp8_settings.denoisingOn); |
| 2949 | EXPECT_FALSE(vp8_settings.automaticResizeOn); |
| 2950 | EXPECT_FALSE(vp8_settings.frameDroppingOn); |
| 2951 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2952 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2953 | } |
| 2954 | |
deadbeef | 119760a | 2016-04-04 11:43:27 -0700 | [diff] [blame] | 2955 | // Test that setting the same options doesn't result in the encoder being |
| 2956 | // reconfigured. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2957 | TEST_F(WebRtcVideoChannelTest, SetIdenticalOptionsDoesntReconfigureEncoder) { |
deadbeef | 119760a | 2016-04-04 11:43:27 -0700 | [diff] [blame] | 2958 | VideoOptions options; |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 2959 | FakeVideoCapturerWithTaskQueue capturer; |
deadbeef | 119760a | 2016-04-04 11:43:27 -0700 | [diff] [blame] | 2960 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2961 | AddSendStream(); |
deadbeef | 119760a | 2016-04-04 11:43:27 -0700 | [diff] [blame] | 2962 | EXPECT_EQ(cricket::CS_RUNNING, |
| 2963 | capturer.Start(capturer.GetSupportedFormats()->front())); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2964 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 2965 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2966 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 2967 | FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
| 2968 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2969 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
| 2970 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
deadbeef | 119760a | 2016-04-04 11:43:27 -0700 | [diff] [blame] | 2971 | EXPECT_TRUE(capturer.CaptureFrame()); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2972 | // Expect 1 reconfigurations at this point from the initial configuration. |
| 2973 | EXPECT_EQ(1, send_stream->num_encoder_reconfigurations()); |
deadbeef | 119760a | 2016-04-04 11:43:27 -0700 | [diff] [blame] | 2974 | |
| 2975 | // Set the options one more time and expect no additional reconfigurations. |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2976 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 2977 | EXPECT_EQ(1, send_stream->num_encoder_reconfigurations()); |
| 2978 | |
| 2979 | // Change |options| and expect 2 reconfigurations. |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 2980 | options.video_noise_reduction = true; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2981 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
deadbeef | 119760a | 2016-04-04 11:43:27 -0700 | [diff] [blame] | 2982 | EXPECT_EQ(2, send_stream->num_encoder_reconfigurations()); |
| 2983 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 2984 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
deadbeef | 119760a | 2016-04-04 11:43:27 -0700 | [diff] [blame] | 2985 | } |
| 2986 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2987 | class Vp9SettingsTest : public WebRtcVideoChannelTest { |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2988 | public: |
asapersson | c5dabdd | 2016-03-21 04:15:50 -0700 | [diff] [blame] | 2989 | Vp9SettingsTest() : Vp9SettingsTest("") {} |
| 2990 | explicit Vp9SettingsTest(const char* field_trials) |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 2991 | : WebRtcVideoChannelTest(field_trials) { |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 2992 | encoder_factory_->AddSupportedVideoCodecType("VP9"); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2993 | } |
| 2994 | virtual ~Vp9SettingsTest() {} |
| 2995 | |
| 2996 | protected: |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2997 | void TearDown() override { |
| 2998 | // Remove references to encoder_factory_ since this will be destroyed |
| 2999 | // before channel_ and engine_. |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3000 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 3001 | } |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 3002 | }; |
| 3003 | |
| 3004 | TEST_F(Vp9SettingsTest, VerifyVp9SpecificSettings) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3005 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3006 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3007 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 3008 | |
Peter Boström | 2feafdb | 2015-09-09 14:32:14 +0200 | [diff] [blame] | 3009 | FakeVideoSendStream* stream = SetUpSimulcast(false, false); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 3010 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 3011 | FakeVideoCapturerWithTaskQueue capturer; |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 3012 | EXPECT_EQ(cricket::CS_RUNNING, |
| 3013 | capturer.Start(capturer.GetSupportedFormats()->front())); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3014 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, &capturer)); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 3015 | channel_->SetSend(true); |
| 3016 | |
| 3017 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 3018 | |
pbos | 4cba4eb | 2015-10-26 11:18:18 -0700 | [diff] [blame] | 3019 | webrtc::VideoCodecVP9 vp9_settings; |
| 3020 | ASSERT_TRUE(stream->GetVp9Settings(&vp9_settings)) << "No VP9 config set."; |
jianj | a5e8aa6 | 2017-03-27 10:09:00 -0700 | [diff] [blame] | 3021 | EXPECT_TRUE(vp9_settings.denoisingOn) |
| 3022 | << "VP9 denoising should be on by default."; |
pbos | 4cba4eb | 2015-10-26 11:18:18 -0700 | [diff] [blame] | 3023 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 3024 | stream = SetDenoisingOption(last_ssrc_, &capturer, false); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 3025 | |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 3026 | ASSERT_TRUE(stream->GetVp9Settings(&vp9_settings)) << "No VP9 config set."; |
| 3027 | EXPECT_FALSE(vp9_settings.denoisingOn); |
| 3028 | // Frame dropping always on for real time video. |
| 3029 | EXPECT_TRUE(vp9_settings.frameDroppingOn); |
| 3030 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 3031 | stream = SetDenoisingOption(last_ssrc_, &capturer, true); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 3032 | |
| 3033 | ASSERT_TRUE(stream->GetVp9Settings(&vp9_settings)) << "No VP9 config set."; |
| 3034 | EXPECT_TRUE(vp9_settings.denoisingOn); |
| 3035 | EXPECT_TRUE(vp9_settings.frameDroppingOn); |
| 3036 | |
| 3037 | // In screen-share mode, denoising is forced off. |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 3038 | VideoOptions options; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 3039 | options.is_screencast = true; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3040 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3041 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 3042 | stream = SetDenoisingOption(last_ssrc_, &capturer, false); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 3043 | |
| 3044 | ASSERT_TRUE(stream->GetVp9Settings(&vp9_settings)) << "No VP9 config set."; |
| 3045 | EXPECT_FALSE(vp9_settings.denoisingOn); |
Sergey Silkin | be71a1e | 2018-05-17 16:46:43 +0200 | [diff] [blame] | 3046 | // Frame dropping always on for screen sharing. |
| 3047 | EXPECT_TRUE(vp9_settings.frameDroppingOn); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 3048 | |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 3049 | stream = SetDenoisingOption(last_ssrc_, &capturer, false); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 3050 | |
| 3051 | ASSERT_TRUE(stream->GetVp9Settings(&vp9_settings)) << "No VP9 config set."; |
| 3052 | EXPECT_FALSE(vp9_settings.denoisingOn); |
Sergey Silkin | be71a1e | 2018-05-17 16:46:43 +0200 | [diff] [blame] | 3053 | EXPECT_TRUE(vp9_settings.frameDroppingOn); |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 3054 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3055 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3056 | } |
| 3057 | |
Sergey Silkin | f18072e | 2018-03-14 10:35:35 +0100 | [diff] [blame] | 3058 | TEST_F(Vp9SettingsTest, MultipleSsrcsEnablesSvc) { |
| 3059 | cricket::VideoSendParameters parameters; |
| 3060 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
| 3061 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 3062 | |
| 3063 | std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); |
| 3064 | |
| 3065 | FakeVideoSendStream* stream = |
| 3066 | AddSendStream(CreateSimStreamParams("cname", ssrcs)); |
| 3067 | |
| 3068 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| 3069 | EXPECT_EQ(ssrcs.size(), config.rtp.ssrcs.size()); |
| 3070 | |
| 3071 | FakeVideoCapturerWithTaskQueue capturer; |
| 3072 | EXPECT_EQ(cricket::CS_RUNNING, |
| 3073 | capturer.Start(capturer.GetSupportedFormats()->front())); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3074 | EXPECT_TRUE(channel_->SetVideoSend(ssrcs[0], nullptr, &capturer)); |
Sergey Silkin | f18072e | 2018-03-14 10:35:35 +0100 | [diff] [blame] | 3075 | channel_->SetSend(true); |
| 3076 | |
| 3077 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 3078 | |
| 3079 | webrtc::VideoCodecVP9 vp9_settings; |
| 3080 | ASSERT_TRUE(stream->GetVp9Settings(&vp9_settings)) << "No VP9 config set."; |
| 3081 | |
| 3082 | const size_t kNumSpatialLayers = ssrcs.size(); |
| 3083 | const size_t kNumTemporalLayers = 3; |
| 3084 | EXPECT_EQ(vp9_settings.numberOfSpatialLayers, kNumSpatialLayers); |
| 3085 | EXPECT_EQ(vp9_settings.numberOfTemporalLayers, kNumTemporalLayers); |
| 3086 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3087 | EXPECT_TRUE(channel_->SetVideoSend(ssrcs[0], nullptr, nullptr)); |
Sergey Silkin | f18072e | 2018-03-14 10:35:35 +0100 | [diff] [blame] | 3088 | } |
| 3089 | |
asapersson | c5dabdd | 2016-03-21 04:15:50 -0700 | [diff] [blame] | 3090 | class Vp9SettingsTestWithFieldTrial : public Vp9SettingsTest { |
| 3091 | public: |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3092 | explicit Vp9SettingsTestWithFieldTrial(const char* field_trials) |
asapersson | c5dabdd | 2016-03-21 04:15:50 -0700 | [diff] [blame] | 3093 | : Vp9SettingsTest(field_trials) {} |
| 3094 | |
| 3095 | protected: |
| 3096 | void VerifySettings(int num_spatial_layers, int num_temporal_layers) { |
| 3097 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3098 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
asapersson | c5dabdd | 2016-03-21 04:15:50 -0700 | [diff] [blame] | 3099 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 3100 | |
| 3101 | FakeVideoSendStream* stream = SetUpSimulcast(false, false); |
| 3102 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 3103 | FakeVideoCapturerWithTaskQueue capturer; |
asapersson | c5dabdd | 2016-03-21 04:15:50 -0700 | [diff] [blame] | 3104 | EXPECT_EQ(cricket::CS_RUNNING, |
| 3105 | capturer.Start(capturer.GetSupportedFormats()->front())); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3106 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, &capturer)); |
asapersson | c5dabdd | 2016-03-21 04:15:50 -0700 | [diff] [blame] | 3107 | channel_->SetSend(true); |
| 3108 | |
| 3109 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 3110 | |
| 3111 | webrtc::VideoCodecVP9 vp9_settings; |
| 3112 | ASSERT_TRUE(stream->GetVp9Settings(&vp9_settings)) << "No VP9 config set."; |
| 3113 | EXPECT_EQ(num_spatial_layers, vp9_settings.numberOfSpatialLayers); |
| 3114 | EXPECT_EQ(num_temporal_layers, vp9_settings.numberOfTemporalLayers); |
| 3115 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3116 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
asapersson | c5dabdd | 2016-03-21 04:15:50 -0700 | [diff] [blame] | 3117 | } |
| 3118 | }; |
| 3119 | |
| 3120 | class Vp9SettingsTestWithNoFlag : public Vp9SettingsTestWithFieldTrial { |
| 3121 | public: |
| 3122 | Vp9SettingsTestWithNoFlag() : Vp9SettingsTestWithFieldTrial("") {} |
| 3123 | }; |
| 3124 | |
| 3125 | TEST_F(Vp9SettingsTestWithNoFlag, VerifySettings) { |
| 3126 | const int kNumSpatialLayers = 1; |
| 3127 | const int kNumTemporalLayers = 1; |
| 3128 | VerifySettings(kNumSpatialLayers, kNumTemporalLayers); |
| 3129 | } |
| 3130 | |
| 3131 | class Vp9SettingsTestWithInvalidFlag : public Vp9SettingsTestWithFieldTrial { |
| 3132 | public: |
| 3133 | Vp9SettingsTestWithInvalidFlag() |
| 3134 | : Vp9SettingsTestWithFieldTrial("WebRTC-SupportVP9SVC/Default/") {} |
| 3135 | }; |
| 3136 | |
| 3137 | TEST_F(Vp9SettingsTestWithInvalidFlag, VerifySettings) { |
| 3138 | const int kNumSpatialLayers = 1; |
| 3139 | const int kNumTemporalLayers = 1; |
| 3140 | VerifySettings(kNumSpatialLayers, kNumTemporalLayers); |
| 3141 | } |
| 3142 | |
| 3143 | class Vp9SettingsTestWith2SL3TLFlag : public Vp9SettingsTestWithFieldTrial { |
| 3144 | public: |
| 3145 | Vp9SettingsTestWith2SL3TLFlag() |
| 3146 | : Vp9SettingsTestWithFieldTrial( |
| 3147 | "WebRTC-SupportVP9SVC/EnabledByFlag_2SL3TL/") {} |
| 3148 | }; |
| 3149 | |
| 3150 | TEST_F(Vp9SettingsTestWith2SL3TLFlag, VerifySettings) { |
| 3151 | const int kNumSpatialLayers = 2; |
| 3152 | const int kNumTemporalLayers = 3; |
| 3153 | VerifySettings(kNumSpatialLayers, kNumTemporalLayers); |
| 3154 | } |
| 3155 | |
Åsa Persson | 45bbc8a | 2017-11-13 10:16:47 +0100 | [diff] [blame] | 3156 | TEST_F(WebRtcVideoChannelTest, VerifyMinBitrate) { |
| 3157 | std::vector<webrtc::VideoStream> streams = AddSendStream()->GetVideoStreams(); |
| 3158 | ASSERT_EQ(1u, streams.size()); |
| 3159 | EXPECT_EQ(cricket::kMinVideoBitrateBps, streams[0].min_bitrate_bps); |
| 3160 | } |
| 3161 | |
| 3162 | TEST_F(WebRtcVideoChannelTest, VerifyMinBitrateWithForcedFallbackFieldTrial) { |
| 3163 | webrtc::test::ScopedFieldTrials override_field_trials_( |
| 3164 | "WebRTC-VP8-Forced-Fallback-Encoder-v2/Enabled-1,2,34567/"); |
| 3165 | std::vector<webrtc::VideoStream> streams = AddSendStream()->GetVideoStreams(); |
| 3166 | ASSERT_EQ(1u, streams.size()); |
| 3167 | EXPECT_EQ(34567, streams[0].min_bitrate_bps); |
| 3168 | } |
| 3169 | |
asapersson | 3c81a1a | 2017-06-14 05:52:21 -0700 | [diff] [blame] | 3170 | TEST_F(WebRtcVideoChannelTest, |
| 3171 | BalancedDegradationPreferenceNotSupportedWithoutFieldtrial) { |
| 3172 | webrtc::test::ScopedFieldTrials override_field_trials_( |
| 3173 | "WebRTC-Video-BalancedDegradation/Disabled/"); |
| 3174 | const bool kResolutionScalingEnabled = true; |
| 3175 | const bool kFpsScalingEnabled = false; |
| 3176 | TestDegradationPreference(kResolutionScalingEnabled, kFpsScalingEnabled); |
| 3177 | } |
| 3178 | |
| 3179 | TEST_F(WebRtcVideoChannelTest, |
| 3180 | BalancedDegradationPreferenceSupportedBehindFieldtrial) { |
| 3181 | webrtc::test::ScopedFieldTrials override_field_trials_( |
| 3182 | "WebRTC-Video-BalancedDegradation/Enabled/"); |
| 3183 | const bool kResolutionScalingEnabled = true; |
| 3184 | const bool kFpsScalingEnabled = true; |
| 3185 | TestDegradationPreference(kResolutionScalingEnabled, kFpsScalingEnabled); |
| 3186 | } |
| 3187 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3188 | TEST_F(WebRtcVideoChannelTest, AdaptsOnOveruse) { |
Erik Språng | efbde37 | 2015-04-29 16:21:28 +0200 | [diff] [blame] | 3189 | TestCpuAdaptation(true, false); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3190 | } |
| 3191 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3192 | TEST_F(WebRtcVideoChannelTest, DoesNotAdaptOnOveruseWhenDisabled) { |
Erik Språng | efbde37 | 2015-04-29 16:21:28 +0200 | [diff] [blame] | 3193 | TestCpuAdaptation(false, false); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3194 | } |
| 3195 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3196 | TEST_F(WebRtcVideoChannelTest, DoesNotAdaptOnOveruseWhenScreensharing) { |
Erik Språng | efbde37 | 2015-04-29 16:21:28 +0200 | [diff] [blame] | 3197 | TestCpuAdaptation(true, true); |
| 3198 | } |
| 3199 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3200 | TEST_F(WebRtcVideoChannelTest, AdaptsOnOveruseAndChangeResolution) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3201 | cricket::VideoCodec codec = GetEngineCodec("VP8"); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3202 | cricket::VideoSendParameters parameters; |
| 3203 | parameters.codecs.push_back(codec); |
| 3204 | |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 3205 | MediaConfig media_config = GetMediaConfig(); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3206 | channel_.reset( |
| 3207 | engine_.CreateChannel(fake_call_.get(), media_config, VideoOptions())); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 3208 | channel_->OnReadyToSend(true); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3209 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 3210 | |
| 3211 | AddSendStream(); |
| 3212 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 3213 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3214 | ASSERT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, &capturer)); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3215 | ASSERT_EQ(cricket::CS_RUNNING, |
| 3216 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 3217 | ASSERT_TRUE(channel_->SetSend(true)); |
| 3218 | |
| 3219 | ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| 3220 | FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3221 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 3222 | EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720)); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3223 | EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
| 3224 | EXPECT_EQ(1280, send_stream->GetLastWidth()); |
| 3225 | EXPECT_EQ(720, send_stream->GetLastHeight()); |
| 3226 | |
| 3227 | // Trigger overuse. |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3228 | rtc::VideoSinkWants wants; |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3229 | wants.max_pixel_count = |
| 3230 | send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1; |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3231 | send_stream->InjectVideoSinkWants(wants); |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 3232 | EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720)); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3233 | EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); |
| 3234 | EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth()); |
| 3235 | EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight()); |
| 3236 | |
| 3237 | // Trigger overuse again. |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3238 | wants.max_pixel_count = |
| 3239 | send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1; |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3240 | send_stream->InjectVideoSinkWants(wants); |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 3241 | EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720)); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3242 | EXPECT_EQ(3, send_stream->GetNumberOfSwappedFrames()); |
| 3243 | EXPECT_EQ(1280 * 2 / 4, send_stream->GetLastWidth()); |
| 3244 | EXPECT_EQ(720 * 2 / 4, send_stream->GetLastHeight()); |
| 3245 | |
| 3246 | // Change input resolution. |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 3247 | EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724)); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3248 | EXPECT_EQ(4, send_stream->GetNumberOfSwappedFrames()); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3249 | EXPECT_EQ(1284 / 2, send_stream->GetLastWidth()); |
| 3250 | EXPECT_EQ(724 / 2, send_stream->GetLastHeight()); |
| 3251 | |
| 3252 | // Trigger underuse which should go back up in resolution. |
sprang | 84a3759 | 2017-02-10 07:04:27 -0800 | [diff] [blame] | 3253 | int current_pixel_count = |
| 3254 | send_stream->GetLastWidth() * send_stream->GetLastHeight(); |
| 3255 | // Cap the max to 4x the pixel count (assuming max 1/2 x 1/2 scale downs) |
| 3256 | // of the current stream, so we don't take too large steps. |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3257 | wants.max_pixel_count = current_pixel_count * 4; |
sprang | 84a3759 | 2017-02-10 07:04:27 -0800 | [diff] [blame] | 3258 | // 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] | 3259 | wants.target_pixel_count = (current_pixel_count * 5 / 3); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3260 | send_stream->InjectVideoSinkWants(wants); |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 3261 | EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724)); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3262 | EXPECT_EQ(5, send_stream->GetNumberOfSwappedFrames()); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3263 | EXPECT_EQ(1284 * 3 / 4, send_stream->GetLastWidth()); |
| 3264 | EXPECT_EQ(724 * 3 / 4, send_stream->GetLastHeight()); |
| 3265 | |
sprang | 84a3759 | 2017-02-10 07:04:27 -0800 | [diff] [blame] | 3266 | // Trigger underuse again, should go back up to full resolution. |
| 3267 | current_pixel_count = |
| 3268 | send_stream->GetLastWidth() * send_stream->GetLastHeight(); |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3269 | wants.max_pixel_count = current_pixel_count * 4; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 3270 | wants.target_pixel_count = (current_pixel_count * 5 / 3); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3271 | send_stream->InjectVideoSinkWants(wants); |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 3272 | EXPECT_TRUE(capturer.CaptureCustomFrame(1284, 724)); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3273 | EXPECT_EQ(6, send_stream->GetNumberOfSwappedFrames()); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3274 | EXPECT_EQ(1284, send_stream->GetLastWidth()); |
| 3275 | EXPECT_EQ(724, send_stream->GetLastHeight()); |
| 3276 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3277 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3278 | } |
| 3279 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3280 | TEST_F(WebRtcVideoChannelTest, PreviousAdaptationDoesNotApplyToScreenshare) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3281 | cricket::VideoCodec codec = GetEngineCodec("VP8"); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3282 | cricket::VideoSendParameters parameters; |
| 3283 | parameters.codecs.push_back(codec); |
| 3284 | |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 3285 | MediaConfig media_config = GetMediaConfig(); |
Niels Möller | 1d7ecd2 | 2018-01-18 15:25:12 +0100 | [diff] [blame] | 3286 | media_config.video.enable_cpu_adaptation = true; |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3287 | channel_.reset( |
| 3288 | engine_.CreateChannel(fake_call_.get(), media_config, VideoOptions())); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 3289 | channel_->OnReadyToSend(true); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3290 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 3291 | |
| 3292 | AddSendStream(); |
| 3293 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 3294 | FakeVideoCapturerWithTaskQueue capturer; |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3295 | ASSERT_EQ(cricket::CS_RUNNING, |
| 3296 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 3297 | ASSERT_TRUE(channel_->SetSend(true)); |
| 3298 | cricket::VideoOptions camera_options; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 3299 | camera_options.is_screencast = false; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3300 | channel_->SetVideoSend(last_ssrc_, &camera_options, &capturer); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3301 | |
| 3302 | ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| 3303 | FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3304 | |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 3305 | EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720)); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3306 | EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
| 3307 | EXPECT_EQ(1280, send_stream->GetLastWidth()); |
| 3308 | EXPECT_EQ(720, send_stream->GetLastHeight()); |
| 3309 | |
| 3310 | // Trigger overuse. |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3311 | rtc::VideoSinkWants wants; |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3312 | wants.max_pixel_count = |
| 3313 | send_stream->GetLastWidth() * send_stream->GetLastHeight() - 1; |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3314 | send_stream->InjectVideoSinkWants(wants); |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 3315 | EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720)); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3316 | EXPECT_EQ(2, send_stream->GetNumberOfSwappedFrames()); |
| 3317 | EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth()); |
| 3318 | EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight()); |
| 3319 | |
| 3320 | // Switch to screen share. Expect no CPU adaptation. |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 3321 | FakeVideoCapturerWithTaskQueue screen_share(true); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3322 | ASSERT_EQ(cricket::CS_RUNNING, |
| 3323 | screen_share.Start(screen_share.GetSupportedFormats()->front())); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3324 | cricket::VideoOptions screenshare_options; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 3325 | screenshare_options.is_screencast = true; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3326 | channel_->SetVideoSend(last_ssrc_, &screenshare_options, &screen_share); |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 3327 | EXPECT_TRUE(screen_share.CaptureCustomFrame(1284, 724)); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 3328 | ASSERT_EQ(2, fake_call_->GetNumCreatedSendStreams()); |
| 3329 | send_stream = fake_call_->GetVideoSendStreams().front(); |
| 3330 | EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3331 | EXPECT_EQ(1284, send_stream->GetLastWidth()); |
| 3332 | EXPECT_EQ(724, send_stream->GetLastHeight()); |
| 3333 | |
| 3334 | // Switch back to the normal capturer. Expect the frame to be CPU adapted. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3335 | channel_->SetVideoSend(last_ssrc_, &camera_options, &capturer); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 3336 | send_stream = fake_call_->GetVideoSendStreams().front(); |
| 3337 | // We have a new fake send stream, so it doesn't remember the old sink wants. |
| 3338 | // In practice, it will be populated from |
mflodman | cc3d442 | 2017-08-03 08:27:51 -0700 | [diff] [blame] | 3339 | // VideoStreamEncoder::VideoSourceProxy::SetSource(), so simulate that here. |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 3340 | send_stream->InjectVideoSinkWants(wants); |
Niels Möller | a6cc0f9 | 2018-02-12 17:14:55 +0100 | [diff] [blame] | 3341 | EXPECT_TRUE(capturer.CaptureCustomFrame(1280, 720)); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 3342 | ASSERT_EQ(3, fake_call_->GetNumCreatedSendStreams()); |
| 3343 | send_stream = fake_call_->GetVideoSendStreams().front(); |
| 3344 | EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3345 | EXPECT_EQ(1280 * 3 / 4, send_stream->GetLastWidth()); |
| 3346 | EXPECT_EQ(720 * 3 / 4, send_stream->GetLastHeight()); |
| 3347 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3348 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
Per | 766ad3b | 2016-04-05 15:23:49 +0200 | [diff] [blame] | 3349 | } |
| 3350 | |
asapersson | 3c81a1a | 2017-06-14 05:52:21 -0700 | [diff] [blame] | 3351 | // TODO(asapersson): Remove this test when the balanced field trial is removed. |
| 3352 | void WebRtcVideoChannelTest::TestDegradationPreference( |
| 3353 | bool resolution_scaling_enabled, |
| 3354 | bool fps_scaling_enabled) { |
| 3355 | cricket::VideoCodec codec = GetEngineCodec("VP8"); |
| 3356 | cricket::VideoSendParameters parameters; |
| 3357 | parameters.codecs.push_back(codec); |
| 3358 | |
| 3359 | MediaConfig media_config = GetMediaConfig(); |
Niels Möller | 1d7ecd2 | 2018-01-18 15:25:12 +0100 | [diff] [blame] | 3360 | media_config.video.enable_cpu_adaptation = true; |
asapersson | 3c81a1a | 2017-06-14 05:52:21 -0700 | [diff] [blame] | 3361 | channel_.reset( |
| 3362 | engine_.CreateChannel(fake_call_.get(), media_config, VideoOptions())); |
| 3363 | channel_->OnReadyToSend(true); |
| 3364 | |
| 3365 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 3366 | |
| 3367 | AddSendStream(); |
| 3368 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 3369 | FakeVideoCapturerWithTaskQueue capturer; |
asapersson | 3c81a1a | 2017-06-14 05:52:21 -0700 | [diff] [blame] | 3370 | VideoOptions options; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3371 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
asapersson | 3c81a1a | 2017-06-14 05:52:21 -0700 | [diff] [blame] | 3372 | cricket::VideoFormat capture_format = capturer.GetSupportedFormats()->front(); |
| 3373 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format)); |
| 3374 | |
| 3375 | EXPECT_TRUE(channel_->SetSend(true)); |
| 3376 | |
| 3377 | FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
| 3378 | EXPECT_EQ(resolution_scaling_enabled, |
| 3379 | send_stream->resolution_scaling_enabled()); |
| 3380 | EXPECT_EQ(fps_scaling_enabled, send_stream->framerate_scaling_enabled()); |
| 3381 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3382 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
asapersson | 3c81a1a | 2017-06-14 05:52:21 -0700 | [diff] [blame] | 3383 | } |
| 3384 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3385 | void WebRtcVideoChannelTest::TestCpuAdaptation(bool enable_overuse, |
| 3386 | bool is_screenshare) { |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3387 | const int kDefaultFps = 30; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3388 | cricket::VideoCodec codec = GetEngineCodec("VP8"); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3389 | cricket::VideoSendParameters parameters; |
| 3390 | parameters.codecs.push_back(codec); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3391 | |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 3392 | MediaConfig media_config = GetMediaConfig(); |
| 3393 | if (enable_overuse) { |
Niels Möller | 1d7ecd2 | 2018-01-18 15:25:12 +0100 | [diff] [blame] | 3394 | media_config.video.enable_cpu_adaptation = true; |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 3395 | } |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3396 | channel_.reset( |
| 3397 | engine_.CreateChannel(fake_call_.get(), media_config, VideoOptions())); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 3398 | channel_->OnReadyToSend(true); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 3399 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3400 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 3401 | |
| 3402 | AddSendStream(); |
| 3403 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 3404 | FakeVideoCapturerWithTaskQueue capturer; |
nisse | 0510331 | 2016-03-16 02:22:50 -0700 | [diff] [blame] | 3405 | VideoOptions options; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 3406 | options.is_screencast = is_screenshare; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3407 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 3408 | cricket::VideoFormat capture_format = capturer.GetSupportedFormats()->front(); |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3409 | capture_format.interval = rtc::kNumNanosecsPerSec / kDefaultFps; |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 3410 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format)); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 3411 | |
| 3412 | EXPECT_TRUE(channel_->SetSend(true)); |
| 3413 | |
solenberg | e526974 | 2015-09-08 05:13:22 -0700 | [diff] [blame] | 3414 | FakeVideoSendStream* send_stream = fake_call_->GetVideoSendStreams().front(); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3415 | |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3416 | if (!enable_overuse) { |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3417 | EXPECT_FALSE(send_stream->resolution_scaling_enabled()); |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3418 | EXPECT_FALSE(send_stream->framerate_scaling_enabled()); |
| 3419 | EXPECT_EQ(is_screenshare, send_stream->framerate_scaling_enabled()); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3420 | |
| 3421 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 3422 | EXPECT_EQ(1, send_stream->GetNumberOfSwappedFrames()); |
| 3423 | |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 3424 | EXPECT_EQ(capture_format.width, send_stream->GetLastWidth()); |
| 3425 | EXPECT_EQ(capture_format.height, send_stream->GetLastHeight()); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3426 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3427 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
perkj | 2d5f091 | 2016-02-29 00:04:41 -0800 | [diff] [blame] | 3428 | return; |
| 3429 | } |
| 3430 | |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3431 | if (is_screenshare) { |
| 3432 | EXPECT_FALSE(send_stream->resolution_scaling_enabled()); |
| 3433 | EXPECT_TRUE(send_stream->framerate_scaling_enabled()); |
| 3434 | } else { |
| 3435 | EXPECT_TRUE(send_stream->resolution_scaling_enabled()); |
| 3436 | EXPECT_FALSE(send_stream->framerate_scaling_enabled()); |
| 3437 | } |
| 3438 | |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3439 | // Trigger overuse. |
| 3440 | ASSERT_EQ(1u, fake_call_->GetVideoSendStreams().size()); |
| 3441 | |
| 3442 | rtc::VideoSinkWants wants; |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3443 | if (is_screenshare) { |
| 3444 | wants.max_framerate_fps = (kDefaultFps * 2) / 3; |
| 3445 | } else { |
| 3446 | wants.max_pixel_count = capture_format.width * capture_format.height - 1; |
| 3447 | } |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3448 | send_stream->InjectVideoSinkWants(wants); |
| 3449 | |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3450 | for (int i = 0; i < kDefaultFps; ++i) |
| 3451 | EXPECT_TRUE(capturer.CaptureFrame()); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 3452 | |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3453 | if (is_screenshare) { |
| 3454 | // Drops every third frame. |
| 3455 | EXPECT_EQ(kDefaultFps * 2 / 3, send_stream->GetNumberOfSwappedFrames()); |
| 3456 | EXPECT_EQ(send_stream->GetLastWidth(), capture_format.width); |
| 3457 | EXPECT_EQ(send_stream->GetLastHeight(), capture_format.height); |
| 3458 | } else { |
| 3459 | EXPECT_EQ(kDefaultFps, send_stream->GetNumberOfSwappedFrames()); |
| 3460 | EXPECT_LT(send_stream->GetLastWidth(), capture_format.width); |
| 3461 | EXPECT_LT(send_stream->GetLastHeight(), capture_format.height); |
| 3462 | } |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 3463 | |
| 3464 | // Trigger underuse which should go back to normal resolution. |
sprang | 84a3759 | 2017-02-10 07:04:27 -0800 | [diff] [blame] | 3465 | int last_pixel_count = |
| 3466 | send_stream->GetLastWidth() * send_stream->GetLastHeight(); |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3467 | if (is_screenshare) { |
| 3468 | wants.max_framerate_fps = kDefaultFps; |
| 3469 | } else { |
| 3470 | wants.max_pixel_count = last_pixel_count * 4; |
| 3471 | wants.target_pixel_count.emplace((last_pixel_count * 5) / 3); |
| 3472 | } |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 3473 | send_stream->InjectVideoSinkWants(wants); |
| 3474 | |
sprang | c5d62e2 | 2017-04-02 23:53:04 -0700 | [diff] [blame] | 3475 | for (int i = 0; i < kDefaultFps; ++i) |
| 3476 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 3477 | |
| 3478 | if (is_screenshare) { |
| 3479 | EXPECT_EQ(kDefaultFps + (kDefaultFps * 2 / 3), |
| 3480 | send_stream->GetNumberOfSwappedFrames()); |
| 3481 | } else { |
| 3482 | EXPECT_EQ(kDefaultFps * 2, send_stream->GetNumberOfSwappedFrames()); |
| 3483 | } |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 3484 | |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 3485 | EXPECT_EQ(capture_format.width, send_stream->GetLastWidth()); |
| 3486 | EXPECT_EQ(capture_format.height, send_stream->GetLastHeight()); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 3487 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3488 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3489 | } |
| 3490 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3491 | TEST_F(WebRtcVideoChannelTest, EstimatesNtpStartTimeCorrectly) { |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 3492 | // Start at last timestamp to verify that wraparounds are estimated correctly. |
| 3493 | static const uint32_t kInitialTimestamp = 0xFFFFFFFFu; |
| 3494 | static const int64_t kInitialNtpTimeMs = 1247891230; |
| 3495 | static const int kFrameOffsetMs = 20; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3496 | EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3497 | |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 3498 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 3499 | cricket::FakeVideoRenderer renderer; |
nisse | 08582ff | 2016-02-04 01:24:52 -0800 | [diff] [blame] | 3500 | EXPECT_TRUE(channel_->SetSink(last_ssrc_, &renderer)); |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 3501 | |
nisse | 64ec8f8 | 2016-09-27 00:17:25 -0700 | [diff] [blame] | 3502 | webrtc::VideoFrame video_frame(CreateBlackFrameBuffer(4, 4), |
| 3503 | kInitialTimestamp, 0, |
| 3504 | webrtc::kVideoRotation_0); |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 3505 | // Initial NTP time is not available on the first frame, but should still be |
| 3506 | // able to be estimated. |
nisse | eb83a1a | 2016-03-21 01:27:56 -0700 | [diff] [blame] | 3507 | stream->InjectFrame(video_frame); |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 3508 | |
| 3509 | EXPECT_EQ(1, renderer.num_rendered_frames()); |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 3510 | |
| 3511 | // This timestamp is kInitialTimestamp (-1) + kFrameOffsetMs * 90, which |
| 3512 | // triggers a constant-overflow warning, hence we're calculating it explicitly |
| 3513 | // here. |
Ilya Nikolaevskiy | 9c38c47 | 2018-09-03 16:11:42 +0200 | [diff] [blame] | 3514 | fake_clock_.AdvanceTimeMicros(kFrameOffsetMs * rtc::kNumMicrosecsPerMillisec); |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 3515 | video_frame.set_timestamp(kFrameOffsetMs * 90 - 1); |
| 3516 | video_frame.set_ntp_time_ms(kInitialNtpTimeMs + kFrameOffsetMs); |
nisse | eb83a1a | 2016-03-21 01:27:56 -0700 | [diff] [blame] | 3517 | stream->InjectFrame(video_frame); |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 3518 | |
| 3519 | EXPECT_EQ(2, renderer.num_rendered_frames()); |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 3520 | |
| 3521 | // Verify that NTP time has been correctly deduced. |
| 3522 | cricket::VideoMediaInfo info; |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 3523 | ASSERT_TRUE(channel_->GetStats(&info)); |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 3524 | ASSERT_EQ(1u, info.receivers.size()); |
| 3525 | EXPECT_EQ(kInitialNtpTimeMs, info.receivers[0].capture_start_ntp_time_ms); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3526 | } |
| 3527 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3528 | TEST_F(WebRtcVideoChannelTest, SetDefaultSendCodecs) { |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 3529 | AssignDefaultAptRtxTypes(); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3530 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3531 | |
| 3532 | VideoCodec codec; |
| 3533 | EXPECT_TRUE(channel_->GetSendCodec(&codec)); |
pbos@webrtc.org | 9fbb717 | 2014-06-13 09:34:13 +0000 | [diff] [blame] | 3534 | EXPECT_TRUE(codec.Matches(engine_.codecs()[0])); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3535 | |
| 3536 | // 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] | 3537 | const std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs1); |
| 3538 | const std::vector<uint32_t> rtx_ssrcs = MAKE_VECTOR(kRtxSsrcs1); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3539 | FakeVideoSendStream* stream = AddSendStream( |
| 3540 | cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 3541 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3542 | |
| 3543 | // Make sure NACK and FEC are enabled on the correct payload types. |
| 3544 | EXPECT_EQ(1000, config.rtp.nack.rtp_history_ms); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3545 | EXPECT_EQ(GetEngineCodec("ulpfec").id, config.rtp.ulpfec.ulpfec_payload_type); |
| 3546 | EXPECT_EQ(GetEngineCodec("red").id, config.rtp.ulpfec.red_payload_type); |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 3547 | |
| 3548 | EXPECT_EQ(1u, config.rtp.rtx.ssrcs.size()); |
| 3549 | EXPECT_EQ(kRtxSsrcs1[0], config.rtp.rtx.ssrcs[0]); |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 3550 | VerifySendStreamHasRtxTypes(config, default_apt_rtx_types_); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3551 | // TODO(juberti): Check RTCP, PLI, TMMBR. |
| 3552 | } |
| 3553 | |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3554 | // The following four tests ensures that FlexFEC is not activated by default |
| 3555 | // when the field trials are not enabled. |
| 3556 | // TODO(brandtr): Remove or update these tests when FlexFEC _is_ enabled by |
| 3557 | // default. |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3558 | TEST_F(WebRtcVideoChannelTest, FlexfecSendCodecWithoutSsrcNotExposedByDefault) { |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3559 | FakeVideoSendStream* stream = AddSendStream(); |
| 3560 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| 3561 | |
brandtr | 3d200bd | 2017-01-16 06:59:19 -0800 | [diff] [blame] | 3562 | EXPECT_EQ(-1, config.rtp.flexfec.payload_type); |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3563 | EXPECT_EQ(0U, config.rtp.flexfec.ssrc); |
| 3564 | EXPECT_TRUE(config.rtp.flexfec.protected_media_ssrcs.empty()); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3565 | } |
| 3566 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3567 | TEST_F(WebRtcVideoChannelTest, FlexfecSendCodecWithSsrcNotExposedByDefault) { |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3568 | FakeVideoSendStream* stream = AddSendStream( |
| 3569 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| 3570 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| 3571 | |
brandtr | 3d200bd | 2017-01-16 06:59:19 -0800 | [diff] [blame] | 3572 | EXPECT_EQ(-1, config.rtp.flexfec.payload_type); |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3573 | EXPECT_EQ(0U, config.rtp.flexfec.ssrc); |
| 3574 | EXPECT_TRUE(config.rtp.flexfec.protected_media_ssrcs.empty()); |
| 3575 | } |
| 3576 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3577 | TEST_F(WebRtcVideoChannelTest, FlexfecRecvCodecWithoutSsrcNotExposedByDefault) { |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3578 | AddRecvStream(); |
| 3579 | |
| 3580 | const std::vector<FakeFlexfecReceiveStream*>& streams = |
| 3581 | fake_call_->GetFlexfecReceiveStreams(); |
| 3582 | EXPECT_TRUE(streams.empty()); |
| 3583 | } |
| 3584 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3585 | TEST_F(WebRtcVideoChannelTest, FlexfecRecvCodecWithSsrcNotExposedByDefault) { |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3586 | AddRecvStream( |
| 3587 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| 3588 | |
| 3589 | const std::vector<FakeFlexfecReceiveStream*>& streams = |
| 3590 | fake_call_->GetFlexfecReceiveStreams(); |
| 3591 | EXPECT_TRUE(streams.empty()); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3592 | } |
| 3593 | |
| 3594 | // TODO(brandtr): When FlexFEC is no longer behind a field trial, merge all |
| 3595 | // tests that use this test fixture into the corresponding "non-field trial" |
| 3596 | // tests. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3597 | class WebRtcVideoChannelFlexfecRecvTest : public WebRtcVideoChannelTest { |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3598 | public: |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3599 | WebRtcVideoChannelFlexfecRecvTest() |
| 3600 | : WebRtcVideoChannelTest("WebRTC-FlexFEC-03-Advertised/Enabled/") {} |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3601 | }; |
| 3602 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3603 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, |
brandtr | 36e7d70 | 2017-01-13 07:15:54 -0800 | [diff] [blame] | 3604 | DefaultFlexfecCodecHasTransportCcAndRembFeedbackParam) { |
| 3605 | EXPECT_TRUE(cricket::HasTransportCc(GetEngineCodec("flexfec-03"))); |
| 3606 | EXPECT_TRUE(cricket::HasRemb(GetEngineCodec("flexfec-03"))); |
| 3607 | } |
| 3608 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3609 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, SetDefaultRecvCodecsWithoutSsrc) { |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3610 | AddRecvStream(); |
| 3611 | |
| 3612 | const std::vector<FakeFlexfecReceiveStream*>& streams = |
| 3613 | fake_call_->GetFlexfecReceiveStreams(); |
| 3614 | EXPECT_TRUE(streams.empty()); |
Rasmus Brandt | 60bb6fe | 2018-02-05 09:51:47 +0100 | [diff] [blame] | 3615 | |
| 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(0, video_stream.GetNumAddedSecondarySinks()); |
| 3621 | EXPECT_EQ(0, video_stream.GetNumRemovedSecondarySinks()); |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3622 | } |
| 3623 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3624 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, SetDefaultRecvCodecsWithSsrc) { |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3625 | AddRecvStream( |
| 3626 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| 3627 | |
| 3628 | const std::vector<FakeFlexfecReceiveStream*>& streams = |
| 3629 | fake_call_->GetFlexfecReceiveStreams(); |
| 3630 | ASSERT_EQ(1U, streams.size()); |
| 3631 | const FakeFlexfecReceiveStream* stream = streams.front(); |
| 3632 | const webrtc::FlexfecReceiveStream::Config& config = stream->GetConfig(); |
| 3633 | EXPECT_EQ(GetEngineCodec("flexfec-03").id, config.payload_type); |
| 3634 | EXPECT_EQ(kFlexfecSsrc, config.remote_ssrc); |
| 3635 | ASSERT_EQ(1U, config.protected_media_ssrcs.size()); |
| 3636 | EXPECT_EQ(kSsrcs1[0], config.protected_media_ssrcs[0]); |
brandtr | 7cd28b9 | 2017-09-22 00:26:25 -0700 | [diff] [blame] | 3637 | |
| 3638 | const std::vector<FakeVideoReceiveStream*>& video_streams = |
| 3639 | fake_call_->GetVideoReceiveStreams(); |
| 3640 | ASSERT_EQ(1U, video_streams.size()); |
Rasmus Brandt | 60bb6fe | 2018-02-05 09:51:47 +0100 | [diff] [blame] | 3641 | const FakeVideoReceiveStream& video_stream = *video_streams.front(); |
| 3642 | EXPECT_EQ(1, video_stream.GetNumAddedSecondarySinks()); |
brandtr | 7cd28b9 | 2017-09-22 00:26:25 -0700 | [diff] [blame] | 3643 | const webrtc::VideoReceiveStream::Config& video_config = |
Rasmus Brandt | 60bb6fe | 2018-02-05 09:51:47 +0100 | [diff] [blame] | 3644 | video_stream.GetConfig(); |
brandtr | 7cd28b9 | 2017-09-22 00:26:25 -0700 | [diff] [blame] | 3645 | EXPECT_TRUE(video_config.rtp.protected_by_flexfec); |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3646 | } |
| 3647 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3648 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, |
brandtr | 11fb472 | 2017-05-30 01:31:37 -0700 | [diff] [blame] | 3649 | EnablingFlexfecDoesNotRecreateVideoReceiveStream) { |
| 3650 | cricket::VideoRecvParameters recv_parameters; |
| 3651 | recv_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3652 | ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
| 3653 | |
| 3654 | AddRecvStream( |
| 3655 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| 3656 | EXPECT_EQ(1, fake_call_->GetNumCreatedReceiveStreams()); |
Rasmus Brandt | 60bb6fe | 2018-02-05 09:51:47 +0100 | [diff] [blame] | 3657 | const std::vector<FakeVideoReceiveStream*>& video_streams = |
| 3658 | fake_call_->GetVideoReceiveStreams(); |
| 3659 | ASSERT_EQ(1U, video_streams.size()); |
| 3660 | const FakeVideoReceiveStream& video_stream = *video_streams.front(); |
| 3661 | EXPECT_EQ(0, video_stream.GetNumAddedSecondarySinks()); |
| 3662 | EXPECT_EQ(0, video_stream.GetNumRemovedSecondarySinks()); |
brandtr | 11fb472 | 2017-05-30 01:31:37 -0700 | [diff] [blame] | 3663 | |
| 3664 | // Enable FlexFEC. |
| 3665 | recv_parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| 3666 | ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
| 3667 | EXPECT_EQ(2, fake_call_->GetNumCreatedReceiveStreams()) |
| 3668 | << "Enabling FlexFEC should create FlexfecReceiveStream."; |
| 3669 | EXPECT_EQ(1U, fake_call_->GetVideoReceiveStreams().size()) |
| 3670 | << "Enabling FlexFEC should not create VideoReceiveStream."; |
| 3671 | EXPECT_EQ(1U, fake_call_->GetFlexfecReceiveStreams().size()) |
| 3672 | << "Enabling FlexFEC should create a single FlexfecReceiveStream."; |
Rasmus Brandt | 60bb6fe | 2018-02-05 09:51:47 +0100 | [diff] [blame] | 3673 | EXPECT_EQ(1, video_stream.GetNumAddedSecondarySinks()); |
| 3674 | EXPECT_EQ(0, video_stream.GetNumRemovedSecondarySinks()); |
brandtr | 11fb472 | 2017-05-30 01:31:37 -0700 | [diff] [blame] | 3675 | } |
| 3676 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3677 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, |
brandtr | 11fb472 | 2017-05-30 01:31:37 -0700 | [diff] [blame] | 3678 | DisablingFlexfecDoesNotRecreateVideoReceiveStream) { |
| 3679 | cricket::VideoRecvParameters recv_parameters; |
| 3680 | recv_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3681 | recv_parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| 3682 | ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
| 3683 | |
| 3684 | AddRecvStream( |
| 3685 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| 3686 | EXPECT_EQ(2, fake_call_->GetNumCreatedReceiveStreams()); |
brandtr | 11fb472 | 2017-05-30 01:31:37 -0700 | [diff] [blame] | 3687 | EXPECT_EQ(1U, fake_call_->GetFlexfecReceiveStreams().size()); |
Rasmus Brandt | 60bb6fe | 2018-02-05 09:51:47 +0100 | [diff] [blame] | 3688 | const std::vector<FakeVideoReceiveStream*>& video_streams = |
| 3689 | fake_call_->GetVideoReceiveStreams(); |
| 3690 | ASSERT_EQ(1U, video_streams.size()); |
| 3691 | const FakeVideoReceiveStream& video_stream = *video_streams.front(); |
| 3692 | EXPECT_EQ(1, video_stream.GetNumAddedSecondarySinks()); |
| 3693 | EXPECT_EQ(0, video_stream.GetNumRemovedSecondarySinks()); |
brandtr | 11fb472 | 2017-05-30 01:31:37 -0700 | [diff] [blame] | 3694 | |
| 3695 | // Disable FlexFEC. |
| 3696 | recv_parameters.codecs.clear(); |
| 3697 | recv_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3698 | ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
| 3699 | EXPECT_EQ(2, fake_call_->GetNumCreatedReceiveStreams()) |
| 3700 | << "Disabling FlexFEC should not recreate VideoReceiveStream."; |
| 3701 | EXPECT_EQ(1U, fake_call_->GetVideoReceiveStreams().size()) |
| 3702 | << "Disabling FlexFEC should not destroy VideoReceiveStream."; |
| 3703 | EXPECT_TRUE(fake_call_->GetFlexfecReceiveStreams().empty()) |
| 3704 | << "Disabling FlexFEC should destroy FlexfecReceiveStream."; |
Rasmus Brandt | 60bb6fe | 2018-02-05 09:51:47 +0100 | [diff] [blame] | 3705 | EXPECT_EQ(1, video_stream.GetNumAddedSecondarySinks()); |
| 3706 | EXPECT_EQ(1, video_stream.GetNumRemovedSecondarySinks()); |
brandtr | 11fb472 | 2017-05-30 01:31:37 -0700 | [diff] [blame] | 3707 | } |
| 3708 | |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3709 | // TODO(brandtr): When FlexFEC is no longer behind a field trial, merge all |
| 3710 | // tests that use this test fixture into the corresponding "non-field trial" |
| 3711 | // tests. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3712 | class WebRtcVideoChannelFlexfecSendRecvTest : public WebRtcVideoChannelTest { |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3713 | public: |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3714 | WebRtcVideoChannelFlexfecSendRecvTest() |
| 3715 | : WebRtcVideoChannelTest( |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3716 | "WebRTC-FlexFEC-03-Advertised/Enabled/WebRTC-FlexFEC-03/Enabled/") { |
| 3717 | } |
| 3718 | }; |
| 3719 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 3720 | TEST_F(WebRtcVideoChannelFlexfecSendRecvTest, SetDefaultSendCodecsWithoutSsrc) { |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3721 | FakeVideoSendStream* stream = AddSendStream(); |
| 3722 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| 3723 | |
brandtr | 3d200bd | 2017-01-16 06:59:19 -0800 | [diff] [blame] | 3724 | EXPECT_EQ(GetEngineCodec("flexfec-03").id, config.rtp.flexfec.payload_type); |
| 3725 | EXPECT_EQ(0U, config.rtp.flexfec.ssrc); |
| 3726 | EXPECT_TRUE(config.rtp.flexfec.protected_media_ssrcs.empty()); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3727 | } |
| 3728 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3729 | TEST_F(WebRtcVideoChannelFlexfecSendRecvTest, SetDefaultSendCodecsWithSsrc) { |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3730 | FakeVideoSendStream* stream = AddSendStream( |
| 3731 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| 3732 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| 3733 | |
brandtr | 3d200bd | 2017-01-16 06:59:19 -0800 | [diff] [blame] | 3734 | EXPECT_EQ(GetEngineCodec("flexfec-03").id, config.rtp.flexfec.payload_type); |
| 3735 | EXPECT_EQ(kFlexfecSsrc, config.rtp.flexfec.ssrc); |
| 3736 | ASSERT_EQ(1U, config.rtp.flexfec.protected_media_ssrcs.size()); |
| 3737 | EXPECT_EQ(kSsrcs1[0], config.rtp.flexfec.protected_media_ssrcs[0]); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3738 | } |
| 3739 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3740 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsWithoutFec) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3741 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3742 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3743 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3744 | |
| 3745 | FakeVideoSendStream* stream = AddSendStream(); |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 3746 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3747 | |
brandtr | b5f2c3f | 2016-10-04 23:28:39 -0700 | [diff] [blame] | 3748 | EXPECT_EQ(-1, config.rtp.ulpfec.ulpfec_payload_type); |
| 3749 | EXPECT_EQ(-1, config.rtp.ulpfec.red_payload_type); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3750 | } |
| 3751 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3752 | TEST_F(WebRtcVideoChannelFlexfecSendRecvTest, SetSendCodecsWithoutFec) { |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3753 | cricket::VideoSendParameters parameters; |
| 3754 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3755 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 3756 | |
| 3757 | FakeVideoSendStream* stream = AddSendStream(); |
| 3758 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| 3759 | |
brandtr | 3d200bd | 2017-01-16 06:59:19 -0800 | [diff] [blame] | 3760 | EXPECT_EQ(-1, config.rtp.flexfec.payload_type); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3761 | } |
| 3762 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3763 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, SetRecvCodecsWithFec) { |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 3764 | AddRecvStream( |
| 3765 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 3766 | |
| 3767 | cricket::VideoRecvParameters recv_parameters; |
| 3768 | recv_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3769 | recv_parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| 3770 | ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
brandtr | 9d58d94 | 2017-02-03 04:43:41 -0800 | [diff] [blame] | 3771 | |
| 3772 | const std::vector<FakeFlexfecReceiveStream*>& flexfec_streams = |
| 3773 | fake_call_->GetFlexfecReceiveStreams(); |
| 3774 | ASSERT_EQ(1U, flexfec_streams.size()); |
| 3775 | const FakeFlexfecReceiveStream* flexfec_stream = flexfec_streams.front(); |
| 3776 | const webrtc::FlexfecReceiveStream::Config& flexfec_stream_config = |
| 3777 | flexfec_stream->GetConfig(); |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 3778 | EXPECT_EQ(GetEngineCodec("flexfec-03").id, |
brandtr | 9d58d94 | 2017-02-03 04:43:41 -0800 | [diff] [blame] | 3779 | flexfec_stream_config.payload_type); |
| 3780 | EXPECT_EQ(kFlexfecSsrc, flexfec_stream_config.remote_ssrc); |
| 3781 | ASSERT_EQ(1U, flexfec_stream_config.protected_media_ssrcs.size()); |
| 3782 | EXPECT_EQ(kSsrcs1[0], flexfec_stream_config.protected_media_ssrcs[0]); |
| 3783 | const std::vector<FakeVideoReceiveStream*>& video_streams = |
| 3784 | fake_call_->GetVideoReceiveStreams(); |
| 3785 | const FakeVideoReceiveStream* video_stream = video_streams.front(); |
| 3786 | const webrtc::VideoReceiveStream::Config& video_stream_config = |
| 3787 | video_stream->GetConfig(); |
| 3788 | EXPECT_EQ(video_stream_config.rtp.local_ssrc, |
| 3789 | flexfec_stream_config.local_ssrc); |
| 3790 | EXPECT_EQ(video_stream_config.rtp.rtcp_mode, flexfec_stream_config.rtcp_mode); |
| 3791 | EXPECT_EQ(video_stream_config.rtcp_send_transport, |
| 3792 | flexfec_stream_config.rtcp_send_transport); |
| 3793 | // TODO(brandtr): Update this EXPECT when we set |transport_cc| in a |
| 3794 | // spec-compliant way. |
| 3795 | EXPECT_EQ(video_stream_config.rtp.transport_cc, |
| 3796 | flexfec_stream_config.transport_cc); |
| 3797 | EXPECT_EQ(video_stream_config.rtp.rtcp_mode, flexfec_stream_config.rtcp_mode); |
| 3798 | EXPECT_EQ(video_stream_config.rtp.extensions, |
| 3799 | flexfec_stream_config.rtp_header_extensions); |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 3800 | } |
| 3801 | |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3802 | // We should not send FlexFEC, even if we advertise it, unless the right |
| 3803 | // field trial is set. |
| 3804 | // TODO(brandtr): Remove when FlexFEC is enabled by default. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3805 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3806 | SetSendCodecsWithoutSsrcWithFecDoesNotEnableFec) { |
| 3807 | cricket::VideoSendParameters parameters; |
| 3808 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3809 | parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| 3810 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 3811 | |
| 3812 | FakeVideoSendStream* stream = AddSendStream(); |
| 3813 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| 3814 | |
| 3815 | EXPECT_EQ(-1, config.rtp.flexfec.payload_type); |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 3816 | EXPECT_EQ(0u, config.rtp.flexfec.ssrc); |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3817 | EXPECT_TRUE(config.rtp.flexfec.protected_media_ssrcs.empty()); |
| 3818 | } |
| 3819 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3820 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3821 | SetSendCodecsWithSsrcWithFecDoesNotEnableFec) { |
| 3822 | cricket::VideoSendParameters parameters; |
| 3823 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3824 | parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| 3825 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 3826 | |
| 3827 | FakeVideoSendStream* stream = AddSendStream( |
| 3828 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| 3829 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| 3830 | |
| 3831 | EXPECT_EQ(-1, config.rtp.flexfec.payload_type); |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 3832 | EXPECT_EQ(0u, config.rtp.flexfec.ssrc); |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3833 | EXPECT_TRUE(config.rtp.flexfec.protected_media_ssrcs.empty()); |
| 3834 | } |
| 3835 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3836 | TEST_F(WebRtcVideoChannelTest, |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 3837 | SetSendCodecRejectsRtxWithoutAssociatedPayloadType) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3838 | const int kUnusedPayloadType = 127; |
| 3839 | EXPECT_FALSE(FindCodecById(engine_.codecs(), kUnusedPayloadType)); |
| 3840 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3841 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3842 | cricket::VideoCodec rtx_codec(kUnusedPayloadType, "rtx"); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3843 | parameters.codecs.push_back(rtx_codec); |
| 3844 | EXPECT_FALSE(channel_->SetSendParameters(parameters)) |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 3845 | << "RTX codec without associated payload type should be rejected."; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3846 | } |
| 3847 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3848 | TEST_F(WebRtcVideoChannelTest, |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 3849 | SetSendCodecRejectsRtxWithoutMatchingVideoCodec) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3850 | const int kUnusedPayloadType1 = 126; |
| 3851 | const int kUnusedPayloadType2 = 127; |
| 3852 | EXPECT_FALSE(FindCodecById(engine_.codecs(), kUnusedPayloadType1)); |
| 3853 | EXPECT_FALSE(FindCodecById(engine_.codecs(), kUnusedPayloadType2)); |
| 3854 | { |
| 3855 | cricket::VideoCodec rtx_codec = cricket::VideoCodec::CreateRtxCodec( |
| 3856 | kUnusedPayloadType1, GetEngineCodec("VP8").id); |
| 3857 | cricket::VideoSendParameters parameters; |
| 3858 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3859 | parameters.codecs.push_back(rtx_codec); |
| 3860 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 3861 | } |
| 3862 | { |
| 3863 | cricket::VideoCodec rtx_codec = cricket::VideoCodec::CreateRtxCodec( |
| 3864 | kUnusedPayloadType1, kUnusedPayloadType2); |
| 3865 | cricket::VideoSendParameters parameters; |
| 3866 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3867 | parameters.codecs.push_back(rtx_codec); |
| 3868 | EXPECT_FALSE(channel_->SetSendParameters(parameters)) |
| 3869 | << "RTX without matching video codec should be rejected."; |
| 3870 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3871 | } |
| 3872 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3873 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsWithChangedRtxPayloadType) { |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 3874 | const int kUnusedPayloadType1 = 126; |
| 3875 | const int kUnusedPayloadType2 = 127; |
| 3876 | EXPECT_FALSE(FindCodecById(engine_.codecs(), kUnusedPayloadType1)); |
| 3877 | EXPECT_FALSE(FindCodecById(engine_.codecs(), kUnusedPayloadType2)); |
| 3878 | |
| 3879 | // SSRCs for RTX. |
| 3880 | cricket::StreamParams params = |
| 3881 | cricket::StreamParams::CreateLegacy(kSsrcs1[0]); |
| 3882 | params.AddFidSsrc(kSsrcs1[0], kRtxSsrcs1[0]); |
| 3883 | AddSendStream(params); |
| 3884 | |
| 3885 | // Original payload type for RTX. |
| 3886 | cricket::VideoSendParameters parameters; |
| 3887 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3888 | cricket::VideoCodec rtx_codec(kUnusedPayloadType1, "rtx"); |
| 3889 | rtx_codec.SetParam("apt", GetEngineCodec("VP8").id); |
| 3890 | parameters.codecs.push_back(rtx_codec); |
| 3891 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 3892 | ASSERT_EQ(1U, fake_call_->GetVideoSendStreams().size()); |
| 3893 | const webrtc::VideoSendStream::Config& config_before = |
| 3894 | fake_call_->GetVideoSendStreams()[0]->GetConfig(); |
| 3895 | EXPECT_EQ(kUnusedPayloadType1, config_before.rtp.rtx.payload_type); |
| 3896 | ASSERT_EQ(1U, config_before.rtp.rtx.ssrcs.size()); |
| 3897 | EXPECT_EQ(kRtxSsrcs1[0], config_before.rtp.rtx.ssrcs[0]); |
| 3898 | |
| 3899 | // Change payload type for RTX. |
| 3900 | parameters.codecs[1].id = kUnusedPayloadType2; |
| 3901 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 3902 | ASSERT_EQ(1U, fake_call_->GetVideoSendStreams().size()); |
| 3903 | const webrtc::VideoSendStream::Config& config_after = |
| 3904 | fake_call_->GetVideoSendStreams()[0]->GetConfig(); |
| 3905 | EXPECT_EQ(kUnusedPayloadType2, config_after.rtp.rtx.payload_type); |
| 3906 | ASSERT_EQ(1U, config_after.rtp.rtx.ssrcs.size()); |
| 3907 | EXPECT_EQ(kRtxSsrcs1[0], config_after.rtp.rtx.ssrcs[0]); |
| 3908 | } |
| 3909 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3910 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsWithoutFecDisablesFec) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3911 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3912 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3913 | parameters.codecs.push_back(GetEngineCodec("ulpfec")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3914 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 3915 | |
| 3916 | FakeVideoSendStream* stream = AddSendStream(); |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 3917 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 3918 | |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 3919 | EXPECT_EQ(GetEngineCodec("ulpfec").id, config.rtp.ulpfec.ulpfec_payload_type); |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 3920 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3921 | parameters.codecs.pop_back(); |
| 3922 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 3923 | stream = fake_call_->GetVideoSendStreams()[0]; |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3924 | ASSERT_TRUE(stream != nullptr); |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 3925 | config = stream->GetConfig().Copy(); |
brandtr | b5f2c3f | 2016-10-04 23:28:39 -0700 | [diff] [blame] | 3926 | EXPECT_EQ(-1, config.rtp.ulpfec.ulpfec_payload_type) |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3927 | << "SetSendCodec without ULPFEC should disable current ULPFEC."; |
| 3928 | } |
| 3929 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3930 | TEST_F(WebRtcVideoChannelFlexfecSendRecvTest, |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 3931 | SetSendCodecsWithoutFecDisablesFec) { |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3932 | cricket::VideoSendParameters parameters; |
| 3933 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 3934 | parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| 3935 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 3936 | |
| 3937 | FakeVideoSendStream* stream = AddSendStream( |
| 3938 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
| 3939 | webrtc::VideoSendStream::Config config = stream->GetConfig().Copy(); |
| 3940 | |
brandtr | 3d200bd | 2017-01-16 06:59:19 -0800 | [diff] [blame] | 3941 | EXPECT_EQ(GetEngineCodec("flexfec-03").id, config.rtp.flexfec.payload_type); |
| 3942 | EXPECT_EQ(kFlexfecSsrc, config.rtp.flexfec.ssrc); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3943 | ASSERT_EQ(1U, config.rtp.flexfec.protected_media_ssrcs.size()); |
| 3944 | EXPECT_EQ(kSsrcs1[0], config.rtp.flexfec.protected_media_ssrcs[0]); |
| 3945 | |
| 3946 | parameters.codecs.pop_back(); |
| 3947 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
| 3948 | stream = fake_call_->GetVideoSendStreams()[0]; |
| 3949 | ASSERT_TRUE(stream != nullptr); |
| 3950 | config = stream->GetConfig().Copy(); |
brandtr | 3d200bd | 2017-01-16 06:59:19 -0800 | [diff] [blame] | 3951 | EXPECT_EQ(-1, config.rtp.flexfec.payload_type) |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 3952 | << "SetSendCodec without FlexFEC should disable current FlexFEC."; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3953 | } |
| 3954 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3955 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsChangesExistingStreams) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3956 | cricket::VideoSendParameters parameters; |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 3957 | cricket::VideoCodec codec(100, "VP8"); |
| 3958 | codec.SetParam(kCodecParamMaxQuantization, kDefaultQpMax); |
| 3959 | parameters.codecs.push_back(codec); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3960 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3961 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 3962 | channel_->SetSend(true); |
pbos@webrtc.org | 38ce7d0 | 2014-07-16 08:01:38 +0000 | [diff] [blame] | 3963 | |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 3964 | FakeVideoSendStream* stream = AddSendStream(); |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 3965 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3966 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, &capturer)); |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 3967 | |
| 3968 | std::vector<webrtc::VideoStream> streams = stream->GetVideoStreams(); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3969 | EXPECT_EQ(kDefaultQpMax, streams[0].max_qp); |
pbos@webrtc.org | 38ce7d0 | 2014-07-16 08:01:38 +0000 | [diff] [blame] | 3970 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3971 | parameters.codecs.clear(); |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 3972 | codec.SetParam(kCodecParamMaxQuantization, kDefaultQpMax + 1); |
| 3973 | parameters.codecs.push_back(codec); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 3974 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 3975 | streams = fake_call_->GetVideoSendStreams()[0]->GetVideoStreams(); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 3976 | EXPECT_EQ(kDefaultQpMax + 1, streams[0].max_qp); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 3977 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3978 | } |
| 3979 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3980 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsWithBitrates) { |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 3981 | SetSendCodecsShouldWorkForBitrates("100", 100000, "150", 150000, "200", |
| 3982 | 200000); |
| 3983 | } |
| 3984 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3985 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsWithHighMaxBitrate) { |
pbos@webrtc.org | a5f6fb5 | 2015-03-23 22:29:39 +0000 | [diff] [blame] | 3986 | SetSendCodecsShouldWorkForBitrates("", 0, "", -1, "10000", 10000000); |
| 3987 | std::vector<webrtc::VideoStream> streams = AddSendStream()->GetVideoStreams(); |
| 3988 | ASSERT_EQ(1u, streams.size()); |
| 3989 | EXPECT_EQ(10000000, streams[0].max_bitrate_bps); |
| 3990 | } |
| 3991 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3992 | TEST_F(WebRtcVideoChannelTest, |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 3993 | SetSendCodecsWithoutBitratesUsesCorrectDefaults) { |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 3994 | SetSendCodecsShouldWorkForBitrates("", 0, "", -1, "", -1); |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 3995 | } |
| 3996 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 3997 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsCapsMinAndStartBitrate) { |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 3998 | SetSendCodecsShouldWorkForBitrates("-1", 0, "-100", -1, "", -1); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 3999 | } |
| 4000 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4001 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsRejectsMaxLessThanMinBitrate) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4002 | send_parameters_.codecs[0].params[kCodecParamMinBitrate] = "300"; |
| 4003 | send_parameters_.codecs[0].params[kCodecParamMaxBitrate] = "200"; |
| 4004 | EXPECT_FALSE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4005 | } |
| 4006 | |
Taylor Brandstetter | 58f2bd9 | 2016-04-26 17:15:23 -0700 | [diff] [blame] | 4007 | // Test that when both the codec-specific bitrate params and max_bandwidth_bps |
| 4008 | // are present in the same send parameters, the settings are combined correctly. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4009 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsWithBitratesAndMaxSendBandwidth) { |
Taylor Brandstetter | 58f2bd9 | 2016-04-26 17:15:23 -0700 | [diff] [blame] | 4010 | send_parameters_.codecs[0].params[kCodecParamMinBitrate] = "100"; |
| 4011 | send_parameters_.codecs[0].params[kCodecParamStartBitrate] = "200"; |
| 4012 | send_parameters_.codecs[0].params[kCodecParamMaxBitrate] = "300"; |
| 4013 | send_parameters_.max_bandwidth_bps = 400000; |
Taylor Brandstetter | 58f2bd9 | 2016-04-26 17:15:23 -0700 | [diff] [blame] | 4014 | // We expect max_bandwidth_bps to take priority, if set. |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 4015 | ExpectSetBitrateParameters(100000, 200000, 400000); |
| 4016 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| 4017 | // Since the codec isn't changing, start_bitrate_bps should be -1. |
| 4018 | ExpectSetBitrateParameters(100000, -1, 350000); |
Taylor Brandstetter | 58f2bd9 | 2016-04-26 17:15:23 -0700 | [diff] [blame] | 4019 | |
| 4020 | // Decrease max_bandwidth_bps. |
| 4021 | send_parameters_.max_bandwidth_bps = 350000; |
| 4022 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Taylor Brandstetter | 58f2bd9 | 2016-04-26 17:15:23 -0700 | [diff] [blame] | 4023 | |
| 4024 | // Now try again with the values flipped around. |
| 4025 | send_parameters_.codecs[0].params[kCodecParamMaxBitrate] = "400"; |
| 4026 | send_parameters_.max_bandwidth_bps = 300000; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 4027 | ExpectSetBitrateParameters(100000, 200000, 300000); |
Taylor Brandstetter | 58f2bd9 | 2016-04-26 17:15:23 -0700 | [diff] [blame] | 4028 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Taylor Brandstetter | 58f2bd9 | 2016-04-26 17:15:23 -0700 | [diff] [blame] | 4029 | |
| 4030 | // If we change the codec max, max_bandwidth_bps should still apply. |
| 4031 | send_parameters_.codecs[0].params[kCodecParamMaxBitrate] = "350"; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 4032 | ExpectSetBitrateParameters(100000, 200000, 300000); |
Taylor Brandstetter | 58f2bd9 | 2016-04-26 17:15:23 -0700 | [diff] [blame] | 4033 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Taylor Brandstetter | 58f2bd9 | 2016-04-26 17:15:23 -0700 | [diff] [blame] | 4034 | } |
| 4035 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 4036 | TEST_F(WebRtcVideoChannelTest, SetMaxSendBandwidthShouldPreserveOtherBitrates) { |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 4037 | SetSendCodecsShouldWorkForBitrates("100", 100000, "150", 150000, "200", |
| 4038 | 200000); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4039 | send_parameters_.max_bandwidth_bps = 300000; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 4040 | // Setting max bitrate should keep previous min bitrate. |
| 4041 | // Setting max bitrate should not reset start bitrate. |
| 4042 | ExpectSetBitrateParameters(100000, -1, 300000); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4043 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 4044 | } |
| 4045 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4046 | TEST_F(WebRtcVideoChannelTest, SetMaxSendBandwidthShouldBeRemovable) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4047 | send_parameters_.max_bandwidth_bps = 300000; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 4048 | ExpectSetMaxBitrate(300000); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4049 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
pbos | 5c7760a | 2017-03-10 11:23:12 -0800 | [diff] [blame] | 4050 | // -1 means to disable max bitrate (set infinite). |
| 4051 | send_parameters_.max_bandwidth_bps = -1; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 4052 | ExpectSetMaxBitrate(-1); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4053 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4054 | } |
| 4055 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4056 | TEST_F(WebRtcVideoChannelTest, SetMaxSendBandwidthAndAddSendStream) { |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 4057 | send_parameters_.max_bandwidth_bps = 99999; |
| 4058 | FakeVideoSendStream* stream = AddSendStream(); |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 4059 | ExpectSetMaxBitrate(send_parameters_.max_bandwidth_bps); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 4060 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 4061 | ASSERT_EQ(1u, stream->GetVideoStreams().size()); |
| 4062 | EXPECT_EQ(send_parameters_.max_bandwidth_bps, |
| 4063 | stream->GetVideoStreams()[0].max_bitrate_bps); |
| 4064 | |
| 4065 | send_parameters_.max_bandwidth_bps = 77777; |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 4066 | ExpectSetMaxBitrate(send_parameters_.max_bandwidth_bps); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 4067 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| 4068 | EXPECT_EQ(send_parameters_.max_bandwidth_bps, |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 4069 | stream->GetVideoStreams()[0].max_bitrate_bps); |
| 4070 | } |
| 4071 | |
Seth Hampson | feec91e | 2018-07-13 10:41:10 -0700 | [diff] [blame] | 4072 | // Tests that when the codec specific max bitrate and VideoSendParameters |
| 4073 | // max_bandwidth_bps are used, that it sets the VideoStream's max bitrate |
| 4074 | // appropriately. |
| 4075 | TEST_F(WebRtcVideoChannelTest, |
| 4076 | MaxBitratePrioritizesVideoSendParametersOverCodecMaxBitrate) { |
| 4077 | send_parameters_.codecs[0].params[kCodecParamMinBitrate] = "100"; |
| 4078 | send_parameters_.codecs[0].params[kCodecParamStartBitrate] = "200"; |
| 4079 | send_parameters_.codecs[0].params[kCodecParamMaxBitrate] = "300"; |
| 4080 | send_parameters_.max_bandwidth_bps = -1; |
| 4081 | AddSendStream(); |
| 4082 | ExpectSetMaxBitrate(300000); |
| 4083 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| 4084 | |
| 4085 | std::vector<FakeVideoSendStream*> video_send_streams = GetFakeSendStreams(); |
| 4086 | ASSERT_EQ(1u, video_send_streams.size()); |
| 4087 | FakeVideoSendStream* video_send_stream = video_send_streams[0]; |
| 4088 | ASSERT_EQ(1u, video_send_streams[0]->GetVideoStreams().size()); |
| 4089 | // First the max bitrate is set based upon the codec param. |
| 4090 | EXPECT_EQ(300000, |
| 4091 | video_send_streams[0]->GetVideoStreams()[0].max_bitrate_bps); |
| 4092 | |
| 4093 | // The VideoSendParameters max bitrate overrides the codec's. |
| 4094 | send_parameters_.max_bandwidth_bps = 500000; |
| 4095 | ExpectSetMaxBitrate(send_parameters_.max_bandwidth_bps); |
| 4096 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| 4097 | ASSERT_EQ(1u, video_send_stream->GetVideoStreams().size()); |
| 4098 | EXPECT_EQ(500000, video_send_stream->GetVideoStreams()[0].max_bitrate_bps); |
| 4099 | } |
| 4100 | |
| 4101 | // Tests that when the codec specific max bitrate and RtpParameters |
| 4102 | // max_bitrate_bps are used, that it sets the VideoStream's max bitrate |
| 4103 | // appropriately. |
| 4104 | TEST_F(WebRtcVideoChannelTest, |
| 4105 | MaxBitratePrioritizesRtpParametersOverCodecMaxBitrate) { |
| 4106 | send_parameters_.codecs[0].params[kCodecParamMinBitrate] = "100"; |
| 4107 | send_parameters_.codecs[0].params[kCodecParamStartBitrate] = "200"; |
| 4108 | send_parameters_.codecs[0].params[kCodecParamMaxBitrate] = "300"; |
| 4109 | send_parameters_.max_bandwidth_bps = -1; |
| 4110 | AddSendStream(); |
| 4111 | ExpectSetMaxBitrate(300000); |
| 4112 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| 4113 | |
| 4114 | std::vector<FakeVideoSendStream*> video_send_streams = GetFakeSendStreams(); |
| 4115 | ASSERT_EQ(1u, video_send_streams.size()); |
| 4116 | FakeVideoSendStream* video_send_stream = video_send_streams[0]; |
| 4117 | ASSERT_EQ(1u, video_send_stream->GetVideoStreams().size()); |
| 4118 | // First the max bitrate is set based upon the codec param. |
| 4119 | EXPECT_EQ(300000, video_send_stream->GetVideoStreams()[0].max_bitrate_bps); |
| 4120 | |
| 4121 | // The RtpParameter max bitrate overrides the codec's. |
| 4122 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 4123 | ASSERT_EQ(1u, parameters.encodings.size()); |
| 4124 | parameters.encodings[0].max_bitrate_bps = 500000; |
| 4125 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 4126 | ASSERT_EQ(1u, video_send_stream->GetVideoStreams().size()); |
| 4127 | EXPECT_EQ(parameters.encodings[0].max_bitrate_bps, |
| 4128 | video_send_stream->GetVideoStreams()[0].max_bitrate_bps); |
| 4129 | } |
| 4130 | |
Åsa Persson | 5565981 | 2018-06-18 17:51:32 +0200 | [diff] [blame] | 4131 | TEST_F(WebRtcVideoChannelTest, |
| 4132 | MaxBitrateIsMinimumOfMaxSendBandwidthAndMaxEncodingBitrate) { |
| 4133 | send_parameters_.max_bandwidth_bps = 99999; |
| 4134 | FakeVideoSendStream* stream = AddSendStream(); |
| 4135 | ExpectSetMaxBitrate(send_parameters_.max_bandwidth_bps); |
| 4136 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| 4137 | ASSERT_EQ(1u, stream->GetVideoStreams().size()); |
| 4138 | EXPECT_EQ(send_parameters_.max_bandwidth_bps, |
| 4139 | stream->GetVideoStreams()[0].max_bitrate_bps); |
| 4140 | |
| 4141 | // Get and set the rtp encoding parameters. |
| 4142 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 4143 | EXPECT_EQ(1u, parameters.encodings.size()); |
| 4144 | |
| 4145 | parameters.encodings[0].max_bitrate_bps = 99999 - 1; |
| 4146 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 4147 | EXPECT_EQ(parameters.encodings[0].max_bitrate_bps, |
| 4148 | stream->GetVideoStreams()[0].max_bitrate_bps); |
| 4149 | |
| 4150 | parameters.encodings[0].max_bitrate_bps = 99999 + 1; |
| 4151 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 4152 | EXPECT_EQ(send_parameters_.max_bandwidth_bps, |
| 4153 | stream->GetVideoStreams()[0].max_bitrate_bps); |
| 4154 | } |
| 4155 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4156 | TEST_F(WebRtcVideoChannelTest, SetMaxSendBitrateCanIncreaseSenderBitrate) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4157 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4158 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4159 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4160 | channel_->SetSend(true); |
| 4161 | |
| 4162 | FakeVideoSendStream* stream = AddSendStream(); |
| 4163 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 4164 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 4165 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, &capturer)); |
Peter Boström | 3afc8c4 | 2016-01-27 16:45:21 +0100 | [diff] [blame] | 4166 | EXPECT_EQ(cricket::CS_RUNNING, |
| 4167 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 4168 | |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4169 | std::vector<webrtc::VideoStream> streams = stream->GetVideoStreams(); |
| 4170 | int initial_max_bitrate_bps = streams[0].max_bitrate_bps; |
| 4171 | EXPECT_GT(initial_max_bitrate_bps, 0); |
| 4172 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4173 | parameters.max_bandwidth_bps = initial_max_bitrate_bps * 2; |
| 4174 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
Peter Boström | 3afc8c4 | 2016-01-27 16:45:21 +0100 | [diff] [blame] | 4175 | // Insert a frame to update the encoder config. |
| 4176 | EXPECT_TRUE(capturer.CaptureFrame()); |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4177 | streams = stream->GetVideoStreams(); |
| 4178 | 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] | 4179 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4180 | } |
| 4181 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4182 | TEST_F(WebRtcVideoChannelTest, |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4183 | SetMaxSendBitrateCanIncreaseSimulcastSenderBitrate) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4184 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4185 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4186 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4187 | channel_->SetSend(true); |
| 4188 | |
| 4189 | FakeVideoSendStream* stream = AddSendStream( |
| 4190 | cricket::CreateSimStreamParams("cname", MAKE_VECTOR(kSsrcs3))); |
| 4191 | |
| 4192 | // Send a frame to make sure this scales up to >1 stream (simulcast). |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 4193 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 4194 | EXPECT_TRUE(channel_->SetVideoSend(kSsrcs3[0], nullptr, &capturer)); |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4195 | EXPECT_EQ(cricket::CS_RUNNING, |
| 4196 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 4197 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 4198 | |
| 4199 | std::vector<webrtc::VideoStream> streams = stream->GetVideoStreams(); |
| 4200 | ASSERT_GT(streams.size(), 1u) |
| 4201 | << "Without simulcast this test doesn't make sense."; |
pbos | be16f79 | 2015-10-16 12:49:39 -0700 | [diff] [blame] | 4202 | int initial_max_bitrate_bps = GetTotalMaxBitrateBps(streams); |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4203 | EXPECT_GT(initial_max_bitrate_bps, 0); |
| 4204 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4205 | parameters.max_bandwidth_bps = initial_max_bitrate_bps * 2; |
| 4206 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
Peter Boström | 3afc8c4 | 2016-01-27 16:45:21 +0100 | [diff] [blame] | 4207 | // Insert a frame to update the encoder config. |
| 4208 | EXPECT_TRUE(capturer.CaptureFrame()); |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4209 | streams = stream->GetVideoStreams(); |
pbos | be16f79 | 2015-10-16 12:49:39 -0700 | [diff] [blame] | 4210 | int increased_max_bitrate_bps = GetTotalMaxBitrateBps(streams); |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4211 | EXPECT_EQ(initial_max_bitrate_bps * 2, increased_max_bitrate_bps); |
| 4212 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 4213 | EXPECT_TRUE(channel_->SetVideoSend(kSsrcs3[0], nullptr, nullptr)); |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 4214 | } |
| 4215 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4216 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsWithMaxQuantization) { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4217 | static const char* kMaxQuantization = "21"; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4218 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4219 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4220 | parameters.codecs[0].params[kCodecParamMaxQuantization] = kMaxQuantization; |
| 4221 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 4222 | EXPECT_EQ(atoi(kMaxQuantization), |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 4223 | AddSendStream()->GetVideoStreams().back().max_qp); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4224 | |
| 4225 | VideoCodec codec; |
| 4226 | EXPECT_TRUE(channel_->GetSendCodec(&codec)); |
| 4227 | EXPECT_EQ(kMaxQuantization, codec.params[kCodecParamMaxQuantization]); |
| 4228 | } |
| 4229 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4230 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsRejectBadPayloadTypes) { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4231 | // TODO(pbos): Should we only allow the dynamic range? |
pkasting@chromium.org | e7a4a12 | 2015-01-28 21:36:55 +0000 | [diff] [blame] | 4232 | static const int kIncorrectPayloads[] = {-2, -1, 128, 129}; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4233 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4234 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
pkasting@chromium.org | e7a4a12 | 2015-01-28 21:36:55 +0000 | [diff] [blame] | 4235 | for (size_t i = 0; i < arraysize(kIncorrectPayloads); ++i) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4236 | parameters.codecs[0].id = kIncorrectPayloads[i]; |
| 4237 | EXPECT_FALSE(channel_->SetSendParameters(parameters)) |
pkasting@chromium.org | d324546 | 2015-02-23 21:28:22 +0000 | [diff] [blame] | 4238 | << "Bad payload type '" << kIncorrectPayloads[i] << "' accepted."; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4239 | } |
| 4240 | } |
| 4241 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4242 | TEST_F(WebRtcVideoChannelTest, SetSendCodecsAcceptAllValidPayloadTypes) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4243 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4244 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
magjed | f823ede | 2016-11-12 09:53:04 -0800 | [diff] [blame] | 4245 | for (int payload_type = 96; payload_type <= 127; ++payload_type) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4246 | parameters.codecs[0].id = payload_type; |
| 4247 | EXPECT_TRUE(channel_->SetSendParameters(parameters)) |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4248 | << "Payload type '" << payload_type << "' rejected."; |
| 4249 | } |
| 4250 | } |
| 4251 | |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 4252 | // Test that setting the a different set of codecs but with an identical front |
| 4253 | // codec doesn't result in the stream being recreated. |
| 4254 | // This may happen when a subsequent negotiation includes fewer codecs, as a |
| 4255 | // result of one of the codecs being rejected. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4256 | TEST_F(WebRtcVideoChannelTest, |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 4257 | SetSendCodecsIdenticalFirstCodecDoesntRecreateStream) { |
| 4258 | cricket::VideoSendParameters parameters1; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4259 | parameters1.codecs.push_back(GetEngineCodec("VP8")); |
| 4260 | parameters1.codecs.push_back(GetEngineCodec("VP9")); |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 4261 | EXPECT_TRUE(channel_->SetSendParameters(parameters1)); |
| 4262 | |
| 4263 | AddSendStream(); |
| 4264 | EXPECT_EQ(1, fake_call_->GetNumCreatedSendStreams()); |
| 4265 | |
| 4266 | cricket::VideoSendParameters parameters2; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4267 | parameters2.codecs.push_back(GetEngineCodec("VP8")); |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 4268 | EXPECT_TRUE(channel_->SetSendParameters(parameters2)); |
| 4269 | EXPECT_EQ(1, fake_call_->GetNumCreatedSendStreams()); |
| 4270 | } |
| 4271 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4272 | TEST_F(WebRtcVideoChannelTest, SetRecvCodecsWithOnlyVp8) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4273 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4274 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4275 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4276 | } |
| 4277 | |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 4278 | // Test that we set our inbound RTX codecs properly. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4279 | TEST_F(WebRtcVideoChannelTest, SetRecvCodecsWithRtx) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4280 | const int kUnusedPayloadType1 = 126; |
| 4281 | const int kUnusedPayloadType2 = 127; |
| 4282 | EXPECT_FALSE(FindCodecById(engine_.codecs(), kUnusedPayloadType1)); |
| 4283 | EXPECT_FALSE(FindCodecById(engine_.codecs(), kUnusedPayloadType2)); |
| 4284 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4285 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4286 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4287 | cricket::VideoCodec rtx_codec(kUnusedPayloadType1, "rtx"); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4288 | parameters.codecs.push_back(rtx_codec); |
| 4289 | EXPECT_FALSE(channel_->SetRecvParameters(parameters)) |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 4290 | << "RTX codec without associated payload should be rejected."; |
| 4291 | |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4292 | parameters.codecs[1].SetParam("apt", kUnusedPayloadType2); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4293 | EXPECT_FALSE(channel_->SetRecvParameters(parameters)) |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 4294 | << "RTX codec with invalid associated payload type should be rejected."; |
| 4295 | |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4296 | parameters.codecs[1].SetParam("apt", GetEngineCodec("VP8").id); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4297 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 4298 | |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4299 | cricket::VideoCodec rtx_codec2(kUnusedPayloadType2, "rtx"); |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 4300 | rtx_codec2.SetParam("apt", rtx_codec.id); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4301 | parameters.codecs.push_back(rtx_codec2); |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 4302 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 4303 | EXPECT_FALSE(channel_->SetRecvParameters(parameters)) |
| 4304 | << "RTX codec with another RTX as associated payload type should be " |
| 4305 | "rejected."; |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 4306 | } |
| 4307 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4308 | TEST_F(WebRtcVideoChannelTest, SetRecvCodecsWithChangedRtxPayloadType) { |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 4309 | const int kUnusedPayloadType1 = 126; |
| 4310 | const int kUnusedPayloadType2 = 127; |
| 4311 | EXPECT_FALSE(FindCodecById(engine_.codecs(), kUnusedPayloadType1)); |
| 4312 | EXPECT_FALSE(FindCodecById(engine_.codecs(), kUnusedPayloadType2)); |
| 4313 | |
| 4314 | // SSRCs for RTX. |
| 4315 | cricket::StreamParams params = |
| 4316 | cricket::StreamParams::CreateLegacy(kSsrcs1[0]); |
| 4317 | params.AddFidSsrc(kSsrcs1[0], kRtxSsrcs1[0]); |
| 4318 | AddRecvStream(params); |
| 4319 | |
| 4320 | // Original payload type for RTX. |
| 4321 | cricket::VideoRecvParameters parameters; |
| 4322 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4323 | cricket::VideoCodec rtx_codec(kUnusedPayloadType1, "rtx"); |
| 4324 | rtx_codec.SetParam("apt", GetEngineCodec("VP8").id); |
| 4325 | parameters.codecs.push_back(rtx_codec); |
| 4326 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
| 4327 | ASSERT_EQ(1U, fake_call_->GetVideoReceiveStreams().size()); |
| 4328 | const webrtc::VideoReceiveStream::Config& config_before = |
| 4329 | fake_call_->GetVideoReceiveStreams()[0]->GetConfig(); |
nisse | 26e3abb | 2017-08-25 04:44:25 -0700 | [diff] [blame] | 4330 | EXPECT_EQ(1U, config_before.rtp.rtx_associated_payload_types.size()); |
| 4331 | const int* payload_type_before = FindKeyByValue( |
| 4332 | config_before.rtp.rtx_associated_payload_types, GetEngineCodec("VP8").id); |
| 4333 | ASSERT_NE(payload_type_before, nullptr); |
| 4334 | EXPECT_EQ(kUnusedPayloadType1, *payload_type_before); |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 4335 | EXPECT_EQ(kRtxSsrcs1[0], config_before.rtp.rtx_ssrc); |
| 4336 | |
| 4337 | // Change payload type for RTX. |
| 4338 | parameters.codecs[1].id = kUnusedPayloadType2; |
| 4339 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
| 4340 | ASSERT_EQ(1U, fake_call_->GetVideoReceiveStreams().size()); |
| 4341 | const webrtc::VideoReceiveStream::Config& config_after = |
| 4342 | fake_call_->GetVideoReceiveStreams()[0]->GetConfig(); |
nisse | 26e3abb | 2017-08-25 04:44:25 -0700 | [diff] [blame] | 4343 | EXPECT_EQ(1U, config_after.rtp.rtx_associated_payload_types.size()); |
| 4344 | const int* payload_type_after = FindKeyByValue( |
| 4345 | config_after.rtp.rtx_associated_payload_types, GetEngineCodec("VP8").id); |
| 4346 | ASSERT_NE(payload_type_after, nullptr); |
| 4347 | EXPECT_EQ(kUnusedPayloadType2, *payload_type_after); |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 4348 | EXPECT_EQ(kRtxSsrcs1[0], config_after.rtp.rtx_ssrc); |
| 4349 | } |
| 4350 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4351 | TEST_F(WebRtcVideoChannelTest, SetRecvCodecsDifferentPayloadType) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4352 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4353 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4354 | parameters.codecs[0].id = 99; |
| 4355 | EXPECT_TRUE(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, SetRecvCodecsAcceptDefaultCodecs) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4359 | cricket::VideoRecvParameters parameters; |
| 4360 | parameters.codecs = engine_.codecs(); |
| 4361 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | ccbed3b | 2014-07-11 13:02:54 +0000 | [diff] [blame] | 4362 | |
| 4363 | FakeVideoReceiveStream* stream = AddRecvStream(); |
Tommi | 733b547 | 2016-06-10 17:58:01 +0200 | [diff] [blame] | 4364 | const webrtc::VideoReceiveStream::Config& config = stream->GetConfig(); |
Niels Möller | cb7e1d2 | 2018-09-11 15:56:04 +0200 | [diff] [blame] | 4365 | EXPECT_EQ(engine_.codecs()[0].name, config.decoders[0].video_format.name); |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 4366 | EXPECT_EQ(engine_.codecs()[0].id, config.decoders[0].payload_type); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4367 | } |
| 4368 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4369 | TEST_F(WebRtcVideoChannelTest, SetRecvCodecsRejectUnsupportedCodec) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4370 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4371 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 4372 | parameters.codecs.push_back(VideoCodec(101, "WTF3")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4373 | EXPECT_FALSE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4374 | } |
| 4375 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4376 | TEST_F(WebRtcVideoChannelTest, SetRecvCodecsAcceptsMultipleVideoCodecs) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4377 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4378 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4379 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4380 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4381 | } |
| 4382 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4383 | TEST_F(WebRtcVideoChannelTest, SetRecvCodecsWithoutFecDisablesFec) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4384 | cricket::VideoSendParameters send_parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4385 | send_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4386 | send_parameters.codecs.push_back(GetEngineCodec("red")); |
| 4387 | send_parameters.codecs.push_back(GetEngineCodec("ulpfec")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4388 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters)); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 4389 | |
| 4390 | FakeVideoReceiveStream* stream = AddRecvStream(); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 4391 | |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4392 | EXPECT_EQ(GetEngineCodec("ulpfec").id, |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 4393 | stream->GetConfig().rtp.ulpfec_payload_type); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 4394 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4395 | cricket::VideoRecvParameters recv_parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4396 | recv_parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4397 | ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 4398 | stream = fake_call_->GetVideoReceiveStreams()[0]; |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4399 | ASSERT_TRUE(stream != nullptr); |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 4400 | EXPECT_EQ(-1, stream->GetConfig().rtp.ulpfec_payload_type) |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4401 | << "SetSendCodec without ULPFEC should disable current ULPFEC."; |
| 4402 | } |
| 4403 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4404 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, SetRecvParamsWithoutFecDisablesFec) { |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4405 | AddRecvStream( |
| 4406 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4407 | const std::vector<FakeFlexfecReceiveStream*>& streams = |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4408 | fake_call_->GetFlexfecReceiveStreams(); |
| 4409 | |
| 4410 | ASSERT_EQ(1U, streams.size()); |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4411 | const FakeFlexfecReceiveStream* stream = streams.front(); |
| 4412 | EXPECT_EQ(GetEngineCodec("flexfec-03").id, stream->GetConfig().payload_type); |
| 4413 | EXPECT_EQ(kFlexfecSsrc, stream->GetConfig().remote_ssrc); |
| 4414 | ASSERT_EQ(1U, stream->GetConfig().protected_media_ssrcs.size()); |
| 4415 | EXPECT_EQ(kSsrcs1[0], stream->GetConfig().protected_media_ssrcs[0]); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4416 | |
| 4417 | cricket::VideoRecvParameters recv_parameters; |
| 4418 | recv_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4419 | ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
| 4420 | EXPECT_TRUE(streams.empty()) |
| 4421 | << "SetSendCodec without FlexFEC should disable current FlexFEC."; |
pbos@webrtc.org | 269605c | 2014-06-26 08:49:03 +0000 | [diff] [blame] | 4422 | } |
| 4423 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4424 | TEST_F(WebRtcVideoChannelTest, SetSendParamsWithFecEnablesFec) { |
Stefan Holmer | 2b1f651 | 2016-05-17 16:33:30 +0200 | [diff] [blame] | 4425 | FakeVideoReceiveStream* stream = AddRecvStream(); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4426 | EXPECT_EQ(GetEngineCodec("ulpfec").id, |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 4427 | stream->GetConfig().rtp.ulpfec_payload_type); |
Stefan Holmer | 2b1f651 | 2016-05-17 16:33:30 +0200 | [diff] [blame] | 4428 | |
| 4429 | cricket::VideoRecvParameters recv_parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4430 | recv_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4431 | recv_parameters.codecs.push_back(GetEngineCodec("red")); |
| 4432 | recv_parameters.codecs.push_back(GetEngineCodec("ulpfec")); |
Stefan Holmer | 2b1f651 | 2016-05-17 16:33:30 +0200 | [diff] [blame] | 4433 | ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
| 4434 | stream = fake_call_->GetVideoReceiveStreams()[0]; |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4435 | ASSERT_TRUE(stream != nullptr); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4436 | EXPECT_EQ(GetEngineCodec("ulpfec").id, |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 4437 | stream->GetConfig().rtp.ulpfec_payload_type) |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4438 | << "ULPFEC should be enabled on the receive stream."; |
Stefan Holmer | 2b1f651 | 2016-05-17 16:33:30 +0200 | [diff] [blame] | 4439 | |
| 4440 | cricket::VideoSendParameters send_parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4441 | send_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4442 | send_parameters.codecs.push_back(GetEngineCodec("red")); |
| 4443 | send_parameters.codecs.push_back(GetEngineCodec("ulpfec")); |
Stefan Holmer | 2b1f651 | 2016-05-17 16:33:30 +0200 | [diff] [blame] | 4444 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters)); |
| 4445 | stream = fake_call_->GetVideoReceiveStreams()[0]; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4446 | EXPECT_EQ(GetEngineCodec("ulpfec").id, |
nisse | 3b3622f | 2017-09-26 02:49:21 -0700 | [diff] [blame] | 4447 | stream->GetConfig().rtp.ulpfec_payload_type) |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4448 | << "ULPFEC should be enabled on the receive stream."; |
| 4449 | } |
| 4450 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4451 | TEST_F(WebRtcVideoChannelFlexfecSendRecvTest, |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 4452 | SetSendRecvParamsWithFecEnablesFec) { |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4453 | AddRecvStream( |
| 4454 | CreatePrimaryWithFecFrStreamParams("cname", kSsrcs1[0], kFlexfecSsrc)); |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4455 | const std::vector<FakeFlexfecReceiveStream*>& streams = |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4456 | fake_call_->GetFlexfecReceiveStreams(); |
| 4457 | |
| 4458 | cricket::VideoRecvParameters recv_parameters; |
| 4459 | recv_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4460 | recv_parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| 4461 | ASSERT_TRUE(channel_->SetRecvParameters(recv_parameters)); |
| 4462 | ASSERT_EQ(1U, streams.size()); |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4463 | const FakeFlexfecReceiveStream* stream_with_recv_params = streams.front(); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4464 | EXPECT_EQ(GetEngineCodec("flexfec-03").id, |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4465 | stream_with_recv_params->GetConfig().payload_type); |
| 4466 | EXPECT_EQ(kFlexfecSsrc, stream_with_recv_params->GetConfig().remote_ssrc); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4467 | EXPECT_EQ(1U, |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4468 | stream_with_recv_params->GetConfig().protected_media_ssrcs.size()); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4469 | EXPECT_EQ(kSsrcs1[0], |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4470 | stream_with_recv_params->GetConfig().protected_media_ssrcs[0]); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4471 | |
| 4472 | cricket::VideoSendParameters send_parameters; |
| 4473 | send_parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4474 | send_parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| 4475 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters)); |
| 4476 | ASSERT_EQ(1U, streams.size()); |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4477 | const FakeFlexfecReceiveStream* stream_with_send_params = streams.front(); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4478 | EXPECT_EQ(GetEngineCodec("flexfec-03").id, |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4479 | stream_with_send_params->GetConfig().payload_type); |
| 4480 | EXPECT_EQ(kFlexfecSsrc, stream_with_send_params->GetConfig().remote_ssrc); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4481 | EXPECT_EQ(1U, |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4482 | stream_with_send_params->GetConfig().protected_media_ssrcs.size()); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4483 | EXPECT_EQ(kSsrcs1[0], |
brandtr | 9c3d4c4 | 2017-01-23 06:59:13 -0800 | [diff] [blame] | 4484 | stream_with_send_params->GetConfig().protected_media_ssrcs[0]); |
Stefan Holmer | 2b1f651 | 2016-05-17 16:33:30 +0200 | [diff] [blame] | 4485 | } |
| 4486 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4487 | TEST_F(WebRtcVideoChannelTest, SetRecvCodecsRejectDuplicateFecPayloads) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4488 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4489 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4490 | parameters.codecs.push_back(GetEngineCodec("red")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4491 | parameters.codecs[1].id = parameters.codecs[0].id; |
| 4492 | EXPECT_FALSE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4493 | } |
| 4494 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4495 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, |
brandtr | 31bd224 | 2017-05-19 05:47:46 -0700 | [diff] [blame] | 4496 | SetRecvCodecsRejectDuplicateFecPayloads) { |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 4497 | cricket::VideoRecvParameters parameters; |
| 4498 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4499 | parameters.codecs.push_back(GetEngineCodec("flexfec-03")); |
| 4500 | parameters.codecs[1].id = parameters.codecs[0].id; |
| 4501 | EXPECT_FALSE(channel_->SetRecvParameters(parameters)); |
| 4502 | } |
| 4503 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4504 | TEST_F(WebRtcVideoChannelTest, SetRecvCodecsRejectDuplicateCodecPayloads) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4505 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4506 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4507 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4508 | parameters.codecs[1].id = parameters.codecs[0].id; |
| 4509 | EXPECT_FALSE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4510 | } |
| 4511 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4512 | TEST_F(WebRtcVideoChannelTest, |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4513 | SetRecvCodecsAcceptSameCodecOnMultiplePayloadTypes) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4514 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4515 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 4516 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4517 | parameters.codecs[1].id += 1; |
| 4518 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4519 | } |
| 4520 | |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 4521 | // Test that setting the same codecs but with a different order |
deadbeef | 874ca3a | 2015-08-20 17:19:20 -0700 | [diff] [blame] | 4522 | // doesn't result in the stream being recreated. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4523 | TEST_F(WebRtcVideoChannelTest, |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 4524 | SetRecvCodecsDifferentOrderDoesntRecreateStream) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4525 | cricket::VideoRecvParameters parameters1; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4526 | parameters1.codecs.push_back(GetEngineCodec("VP8")); |
| 4527 | parameters1.codecs.push_back(GetEngineCodec("red")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4528 | EXPECT_TRUE(channel_->SetRecvParameters(parameters1)); |
deadbeef | 874ca3a | 2015-08-20 17:19:20 -0700 | [diff] [blame] | 4529 | |
| 4530 | AddRecvStream(cricket::StreamParams::CreateLegacy(123)); |
| 4531 | EXPECT_EQ(1, fake_call_->GetNumCreatedReceiveStreams()); |
| 4532 | |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4533 | cricket::VideoRecvParameters parameters2; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4534 | parameters2.codecs.push_back(GetEngineCodec("red")); |
| 4535 | parameters2.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4536 | EXPECT_TRUE(channel_->SetRecvParameters(parameters2)); |
deadbeef | 874ca3a | 2015-08-20 17:19:20 -0700 | [diff] [blame] | 4537 | EXPECT_EQ(1, fake_call_->GetNumCreatedReceiveStreams()); |
| 4538 | } |
| 4539 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4540 | TEST_F(WebRtcVideoChannelTest, SendStreamNotSendingByDefault) { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4541 | EXPECT_FALSE(AddSendStream()->IsSending()); |
| 4542 | } |
| 4543 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4544 | TEST_F(WebRtcVideoChannelTest, ReceiveStreamReceivingByDefault) { |
pbos@webrtc.org | 85f4294 | 2014-07-22 09:14:58 +0000 | [diff] [blame] | 4545 | EXPECT_TRUE(AddRecvStream()->IsReceiving()); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4546 | } |
| 4547 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4548 | TEST_F(WebRtcVideoChannelTest, SetSend) { |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 4549 | FakeVideoSendStream* stream = AddSendStream(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4550 | EXPECT_FALSE(stream->IsSending()); |
| 4551 | |
| 4552 | // false->true |
| 4553 | EXPECT_TRUE(channel_->SetSend(true)); |
| 4554 | EXPECT_TRUE(stream->IsSending()); |
| 4555 | // true->true |
| 4556 | EXPECT_TRUE(channel_->SetSend(true)); |
| 4557 | EXPECT_TRUE(stream->IsSending()); |
| 4558 | // true->false |
| 4559 | EXPECT_TRUE(channel_->SetSend(false)); |
| 4560 | EXPECT_FALSE(stream->IsSending()); |
| 4561 | // false->false |
| 4562 | EXPECT_TRUE(channel_->SetSend(false)); |
| 4563 | EXPECT_FALSE(stream->IsSending()); |
| 4564 | |
| 4565 | EXPECT_TRUE(channel_->SetSend(true)); |
| 4566 | FakeVideoSendStream* new_stream = AddSendStream(); |
| 4567 | EXPECT_TRUE(new_stream->IsSending()) |
| 4568 | << "Send stream created after SetSend(true) not sending initially."; |
| 4569 | } |
| 4570 | |
pbos@webrtc.org | d819803 | 2014-11-10 14:41:43 +0000 | [diff] [blame] | 4571 | // This test verifies DSCP settings are properly applied on video media channel. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4572 | TEST_F(WebRtcVideoChannelTest, TestSetDscpOptions) { |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 4573 | std::unique_ptr<cricket::FakeNetworkInterface> network_interface( |
pbos@webrtc.org | d819803 | 2014-11-10 14:41:43 +0000 | [diff] [blame] | 4574 | new cricket::FakeNetworkInterface); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 4575 | MediaConfig config; |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 4576 | std::unique_ptr<VideoMediaChannel> channel; |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 4577 | |
| 4578 | channel.reset(engine_.CreateChannel(call_.get(), config, VideoOptions())); |
| 4579 | channel->SetInterface(network_interface.get()); |
| 4580 | // Default value when DSCP is disabled should be DSCP_DEFAULT. |
pbos@webrtc.org | d819803 | 2014-11-10 14:41:43 +0000 | [diff] [blame] | 4581 | EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp()); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 4582 | |
| 4583 | config.enable_dscp = true; |
| 4584 | channel.reset(engine_.CreateChannel(call_.get(), config, VideoOptions())); |
| 4585 | channel->SetInterface(network_interface.get()); |
| 4586 | EXPECT_EQ(rtc::DSCP_AF41, network_interface->dscp()); |
| 4587 | |
| 4588 | // Verify that setting the option to false resets the |
| 4589 | // DiffServCodePoint. |
| 4590 | config.enable_dscp = false; |
| 4591 | channel.reset(engine_.CreateChannel(call_.get(), config, VideoOptions())); |
| 4592 | channel->SetInterface(network_interface.get()); |
| 4593 | EXPECT_EQ(rtc::DSCP_DEFAULT, network_interface->dscp()); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4594 | } |
| 4595 | |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 4596 | // This test verifies that the RTCP reduced size mode is properly applied to |
| 4597 | // send video streams. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4598 | TEST_F(WebRtcVideoChannelTest, TestSetSendRtcpReducedSize) { |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 4599 | // Create stream, expecting that default mode is "compound". |
| 4600 | FakeVideoSendStream* stream1 = AddSendStream(); |
| 4601 | EXPECT_EQ(webrtc::RtcpMode::kCompound, stream1->GetConfig().rtp.rtcp_mode); |
Florent Castelli | dacec71 | 2018-05-24 16:24:21 +0200 | [diff] [blame] | 4602 | webrtc::RtpParameters rtp_parameters = |
| 4603 | channel_->GetRtpSendParameters(last_ssrc_); |
| 4604 | EXPECT_FALSE(rtp_parameters.rtcp.reduced_size); |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 4605 | |
| 4606 | // Now enable reduced size mode. |
| 4607 | send_parameters_.rtcp.reduced_size = true; |
| 4608 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| 4609 | stream1 = fake_call_->GetVideoSendStreams()[0]; |
| 4610 | EXPECT_EQ(webrtc::RtcpMode::kReducedSize, stream1->GetConfig().rtp.rtcp_mode); |
Florent Castelli | dacec71 | 2018-05-24 16:24:21 +0200 | [diff] [blame] | 4611 | rtp_parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 4612 | EXPECT_TRUE(rtp_parameters.rtcp.reduced_size); |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 4613 | |
| 4614 | // Create a new stream and ensure it picks up the reduced size mode. |
| 4615 | FakeVideoSendStream* stream2 = AddSendStream(); |
| 4616 | EXPECT_EQ(webrtc::RtcpMode::kReducedSize, stream2->GetConfig().rtp.rtcp_mode); |
| 4617 | } |
| 4618 | |
| 4619 | // This test verifies that the RTCP reduced size mode is properly applied to |
| 4620 | // receive video streams. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4621 | TEST_F(WebRtcVideoChannelTest, TestSetRecvRtcpReducedSize) { |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 4622 | // Create stream, expecting that default mode is "compound". |
| 4623 | FakeVideoReceiveStream* stream1 = AddRecvStream(); |
| 4624 | EXPECT_EQ(webrtc::RtcpMode::kCompound, stream1->GetConfig().rtp.rtcp_mode); |
| 4625 | |
| 4626 | // Now enable reduced size mode. |
Taylor Brandstetter | 5f0b83b | 2016-03-18 15:02:07 -0700 | [diff] [blame] | 4627 | // TODO(deadbeef): Once "recv_parameters" becomes "receiver_parameters", |
| 4628 | // the reduced_size flag should come from that. |
| 4629 | send_parameters_.rtcp.reduced_size = true; |
| 4630 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
deadbeef | 1387149 | 2015-12-09 12:37:51 -0800 | [diff] [blame] | 4631 | stream1 = fake_call_->GetVideoReceiveStreams()[0]; |
| 4632 | EXPECT_EQ(webrtc::RtcpMode::kReducedSize, stream1->GetConfig().rtp.rtcp_mode); |
| 4633 | |
| 4634 | // Create a new stream and ensure it picks up the reduced size mode. |
| 4635 | FakeVideoReceiveStream* stream2 = AddRecvStream(); |
| 4636 | EXPECT_EQ(webrtc::RtcpMode::kReducedSize, stream2->GetConfig().rtp.rtcp_mode); |
| 4637 | } |
| 4638 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4639 | TEST_F(WebRtcVideoChannelTest, OnReadyToSendSignalsNetworkState) { |
skvlad | 7a43d25 | 2016-03-22 15:32:27 -0700 | [diff] [blame] | 4640 | EXPECT_EQ(webrtc::kNetworkUp, |
| 4641 | fake_call_->GetNetworkState(webrtc::MediaType::VIDEO)); |
| 4642 | EXPECT_EQ(webrtc::kNetworkUp, |
| 4643 | fake_call_->GetNetworkState(webrtc::MediaType::AUDIO)); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 4644 | |
| 4645 | channel_->OnReadyToSend(false); |
skvlad | 7a43d25 | 2016-03-22 15:32:27 -0700 | [diff] [blame] | 4646 | EXPECT_EQ(webrtc::kNetworkDown, |
| 4647 | fake_call_->GetNetworkState(webrtc::MediaType::VIDEO)); |
| 4648 | EXPECT_EQ(webrtc::kNetworkUp, |
| 4649 | fake_call_->GetNetworkState(webrtc::MediaType::AUDIO)); |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 4650 | |
| 4651 | channel_->OnReadyToSend(true); |
skvlad | 7a43d25 | 2016-03-22 15:32:27 -0700 | [diff] [blame] | 4652 | EXPECT_EQ(webrtc::kNetworkUp, |
| 4653 | fake_call_->GetNetworkState(webrtc::MediaType::VIDEO)); |
| 4654 | EXPECT_EQ(webrtc::kNetworkUp, |
| 4655 | fake_call_->GetNetworkState(webrtc::MediaType::AUDIO)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 4656 | } |
| 4657 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4658 | TEST_F(WebRtcVideoChannelTest, GetStatsReportsSentCodecName) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4659 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4660 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4661 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
Peter Boström | 74d9ed7 | 2015-03-26 16:28:31 +0100 | [diff] [blame] | 4662 | |
| 4663 | AddSendStream(); |
| 4664 | |
| 4665 | cricket::VideoMediaInfo info; |
| 4666 | ASSERT_TRUE(channel_->GetStats(&info)); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 4667 | EXPECT_EQ("VP8", info.senders[0].codec_name); |
Peter Boström | 74d9ed7 | 2015-03-26 16:28:31 +0100 | [diff] [blame] | 4668 | } |
| 4669 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4670 | TEST_F(WebRtcVideoChannelTest, GetStatsReportsEncoderImplementationName) { |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 4671 | FakeVideoSendStream* stream = AddSendStream(); |
| 4672 | webrtc::VideoSendStream::Stats stats; |
| 4673 | stats.encoder_implementation_name = "encoder_implementation_name"; |
| 4674 | stream->SetStats(stats); |
| 4675 | |
| 4676 | cricket::VideoMediaInfo info; |
| 4677 | ASSERT_TRUE(channel_->GetStats(&info)); |
| 4678 | EXPECT_EQ(stats.encoder_implementation_name, |
| 4679 | info.senders[0].encoder_implementation_name); |
| 4680 | } |
| 4681 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4682 | TEST_F(WebRtcVideoChannelTest, GetStatsReportsCpuOveruseMetrics) { |
pbos@webrtc.org | 3e6e271 | 2015-02-26 12:19:31 +0000 | [diff] [blame] | 4683 | FakeVideoSendStream* stream = AddSendStream(); |
| 4684 | webrtc::VideoSendStream::Stats stats; |
| 4685 | stats.avg_encode_time_ms = 13; |
| 4686 | stats.encode_usage_percent = 42; |
| 4687 | stream->SetStats(stats); |
| 4688 | |
| 4689 | cricket::VideoMediaInfo info; |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 4690 | ASSERT_TRUE(channel_->GetStats(&info)); |
pbos@webrtc.org | 3e6e271 | 2015-02-26 12:19:31 +0000 | [diff] [blame] | 4691 | EXPECT_EQ(stats.avg_encode_time_ms, info.senders[0].avg_encode_ms); |
| 4692 | EXPECT_EQ(stats.encode_usage_percent, info.senders[0].encode_usage_percent); |
| 4693 | } |
| 4694 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4695 | TEST_F(WebRtcVideoChannelTest, GetStatsReportsFramesEncoded) { |
sakal | 43536c3 | 2016-10-24 01:46:43 -0700 | [diff] [blame] | 4696 | FakeVideoSendStream* stream = AddSendStream(); |
| 4697 | webrtc::VideoSendStream::Stats stats; |
| 4698 | stats.frames_encoded = 13; |
| 4699 | stream->SetStats(stats); |
| 4700 | |
| 4701 | cricket::VideoMediaInfo info; |
| 4702 | ASSERT_TRUE(channel_->GetStats(&info)); |
| 4703 | EXPECT_EQ(stats.frames_encoded, info.senders[0].frames_encoded); |
| 4704 | } |
| 4705 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4706 | TEST_F(WebRtcVideoChannelTest, GetStatsReportsQpSum) { |
sakal | 87da404 | 2016-10-31 06:53:47 -0700 | [diff] [blame] | 4707 | FakeVideoSendStream* stream = AddSendStream(); |
| 4708 | webrtc::VideoSendStream::Stats stats; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 4709 | stats.qp_sum = 13; |
sakal | 87da404 | 2016-10-31 06:53:47 -0700 | [diff] [blame] | 4710 | stream->SetStats(stats); |
| 4711 | |
| 4712 | cricket::VideoMediaInfo info; |
| 4713 | ASSERT_TRUE(channel_->GetStats(&info)); |
| 4714 | EXPECT_EQ(stats.qp_sum, info.senders[0].qp_sum); |
| 4715 | } |
| 4716 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4717 | TEST_F(WebRtcVideoChannelTest, GetStatsReportsUpperResolution) { |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 4718 | FakeVideoSendStream* stream = AddSendStream(); |
| 4719 | webrtc::VideoSendStream::Stats stats; |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 4720 | stats.substreams[17].width = 123; |
| 4721 | stats.substreams[17].height = 40; |
| 4722 | stats.substreams[42].width = 80; |
| 4723 | stats.substreams[42].height = 31; |
| 4724 | stats.substreams[11].width = 20; |
| 4725 | stats.substreams[11].height = 90; |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 4726 | stream->SetStats(stats); |
| 4727 | |
| 4728 | cricket::VideoMediaInfo info; |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 4729 | ASSERT_TRUE(channel_->GetStats(&info)); |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 4730 | ASSERT_EQ(1u, info.senders.size()); |
| 4731 | EXPECT_EQ(123, info.senders[0].send_frame_width); |
| 4732 | EXPECT_EQ(90, info.senders[0].send_frame_height); |
| 4733 | } |
| 4734 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4735 | TEST_F(WebRtcVideoChannelTest, GetStatsReportsCpuAdaptationStats) { |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 4736 | FakeVideoSendStream* stream = AddSendStream(); |
| 4737 | webrtc::VideoSendStream::Stats stats; |
| 4738 | stats.number_of_cpu_adapt_changes = 2; |
| 4739 | stats.cpu_limited_resolution = true; |
| 4740 | stream->SetStats(stats); |
pbos@webrtc.org | 9a4410e | 2015-02-26 10:03:39 +0000 | [diff] [blame] | 4741 | |
pbos@webrtc.org | 9a4410e | 2015-02-26 10:03:39 +0000 | [diff] [blame] | 4742 | cricket::VideoMediaInfo info; |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 4743 | EXPECT_TRUE(channel_->GetStats(&info)); |
pbos@webrtc.org | 9a4410e | 2015-02-26 10:03:39 +0000 | [diff] [blame] | 4744 | ASSERT_EQ(1U, info.senders.size()); |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4745 | EXPECT_EQ(WebRtcVideoChannel::ADAPTREASON_CPU, info.senders[0].adapt_reason); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 4746 | 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] | 4747 | } |
| 4748 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4749 | TEST_F(WebRtcVideoChannelTest, GetStatsReportsAdaptationAndBandwidthStats) { |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 4750 | FakeVideoSendStream* stream = AddSendStream(); |
asapersson | 17821db | 2015-12-14 02:08:12 -0800 | [diff] [blame] | 4751 | webrtc::VideoSendStream::Stats stats; |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 4752 | stats.number_of_cpu_adapt_changes = 2; |
| 4753 | stats.cpu_limited_resolution = true; |
asapersson | 17821db | 2015-12-14 02:08:12 -0800 | [diff] [blame] | 4754 | stats.bw_limited_resolution = true; |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 4755 | stream->SetStats(stats); |
| 4756 | |
| 4757 | cricket::VideoMediaInfo info; |
asapersson | 17821db | 2015-12-14 02:08:12 -0800 | [diff] [blame] | 4758 | EXPECT_TRUE(channel_->GetStats(&info)); |
| 4759 | ASSERT_EQ(1U, info.senders.size()); |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4760 | EXPECT_EQ(WebRtcVideoChannel::ADAPTREASON_CPU | |
| 4761 | WebRtcVideoChannel::ADAPTREASON_BANDWIDTH, |
asapersson | 17821db | 2015-12-14 02:08:12 -0800 | [diff] [blame] | 4762 | info.senders[0].adapt_reason); |
perkj | 803d97f | 2016-11-01 11:45:46 -0700 | [diff] [blame] | 4763 | EXPECT_EQ(stats.number_of_cpu_adapt_changes, info.senders[0].adapt_changes); |
asapersson | 17821db | 2015-12-14 02:08:12 -0800 | [diff] [blame] | 4764 | } |
| 4765 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4766 | TEST_F(WebRtcVideoChannelTest, |
asapersson | 17821db | 2015-12-14 02:08:12 -0800 | [diff] [blame] | 4767 | GetStatsTranslatesBandwidthLimitedResolutionCorrectly) { |
| 4768 | FakeVideoSendStream* stream = AddSendStream(); |
| 4769 | webrtc::VideoSendStream::Stats stats; |
| 4770 | stats.bw_limited_resolution = true; |
| 4771 | stream->SetStats(stats); |
| 4772 | |
| 4773 | cricket::VideoMediaInfo info; |
| 4774 | EXPECT_TRUE(channel_->GetStats(&info)); |
| 4775 | ASSERT_EQ(1U, info.senders.size()); |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4776 | EXPECT_EQ(WebRtcVideoChannel::ADAPTREASON_BANDWIDTH, |
asapersson | 17821db | 2015-12-14 02:08:12 -0800 | [diff] [blame] | 4777 | info.senders[0].adapt_reason); |
| 4778 | } |
| 4779 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 4780 | TEST_F(WebRtcVideoChannelTest, GetStatsTranslatesSendRtcpPacketTypesCorrectly) { |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 4781 | FakeVideoSendStream* stream = AddSendStream(); |
| 4782 | webrtc::VideoSendStream::Stats stats; |
| 4783 | stats.substreams[17].rtcp_packet_type_counts.fir_packets = 2; |
| 4784 | stats.substreams[17].rtcp_packet_type_counts.nack_packets = 3; |
| 4785 | stats.substreams[17].rtcp_packet_type_counts.pli_packets = 4; |
| 4786 | |
| 4787 | stats.substreams[42].rtcp_packet_type_counts.fir_packets = 5; |
| 4788 | stats.substreams[42].rtcp_packet_type_counts.nack_packets = 7; |
| 4789 | stats.substreams[42].rtcp_packet_type_counts.pli_packets = 9; |
| 4790 | |
| 4791 | stream->SetStats(stats); |
| 4792 | |
| 4793 | cricket::VideoMediaInfo info; |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 4794 | ASSERT_TRUE(channel_->GetStats(&info)); |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 4795 | EXPECT_EQ(7, info.senders[0].firs_rcvd); |
| 4796 | EXPECT_EQ(10, info.senders[0].nacks_rcvd); |
| 4797 | EXPECT_EQ(13, info.senders[0].plis_rcvd); |
| 4798 | } |
| 4799 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4800 | TEST_F(WebRtcVideoChannelTest, |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 4801 | GetStatsTranslatesReceiveRtcpPacketTypesCorrectly) { |
| 4802 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 4803 | webrtc::VideoReceiveStream::Stats stats; |
| 4804 | stats.rtcp_packet_type_counts.fir_packets = 2; |
| 4805 | stats.rtcp_packet_type_counts.nack_packets = 3; |
| 4806 | stats.rtcp_packet_type_counts.pli_packets = 4; |
| 4807 | stream->SetStats(stats); |
| 4808 | |
| 4809 | cricket::VideoMediaInfo info; |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 4810 | ASSERT_TRUE(channel_->GetStats(&info)); |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 4811 | EXPECT_EQ(stats.rtcp_packet_type_counts.fir_packets, |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 4812 | rtc::checked_cast<unsigned int>(info.receivers[0].firs_sent)); |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 4813 | EXPECT_EQ(stats.rtcp_packet_type_counts.nack_packets, |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 4814 | rtc::checked_cast<unsigned int>(info.receivers[0].nacks_sent)); |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 4815 | EXPECT_EQ(stats.rtcp_packet_type_counts.pli_packets, |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 4816 | rtc::checked_cast<unsigned int>(info.receivers[0].plis_sent)); |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 4817 | } |
| 4818 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4819 | TEST_F(WebRtcVideoChannelTest, GetStatsTranslatesDecodeStatsCorrectly) { |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 4820 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 4821 | webrtc::VideoReceiveStream::Stats stats; |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 4822 | stats.decoder_implementation_name = "decoder_implementation_name"; |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 4823 | stats.decode_ms = 2; |
| 4824 | stats.max_decode_ms = 3; |
| 4825 | stats.current_delay_ms = 4; |
| 4826 | stats.target_delay_ms = 5; |
| 4827 | stats.jitter_buffer_ms = 6; |
| 4828 | stats.min_playout_delay_ms = 7; |
| 4829 | stats.render_delay_ms = 8; |
asapersson | 26dd92b | 2016-08-30 00:45:45 -0700 | [diff] [blame] | 4830 | stats.width = 9; |
| 4831 | stats.height = 10; |
hbos | 42f6d2f | 2017-01-20 03:56:50 -0800 | [diff] [blame] | 4832 | stats.frame_counts.key_frames = 11; |
| 4833 | stats.frame_counts.delta_frames = 12; |
hbos | 50cfe1f | 2017-01-23 07:21:55 -0800 | [diff] [blame] | 4834 | stats.frames_rendered = 13; |
| 4835 | stats.frames_decoded = 14; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 4836 | stats.qp_sum = 15; |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 4837 | stream->SetStats(stats); |
| 4838 | |
| 4839 | cricket::VideoMediaInfo info; |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 4840 | ASSERT_TRUE(channel_->GetStats(&info)); |
Peter Boström | b7d9a97 | 2015-12-18 16:01:11 +0100 | [diff] [blame] | 4841 | EXPECT_EQ(stats.decoder_implementation_name, |
| 4842 | info.receivers[0].decoder_implementation_name); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 4843 | EXPECT_EQ(stats.decode_ms, info.receivers[0].decode_ms); |
| 4844 | EXPECT_EQ(stats.max_decode_ms, info.receivers[0].max_decode_ms); |
| 4845 | EXPECT_EQ(stats.current_delay_ms, info.receivers[0].current_delay_ms); |
| 4846 | EXPECT_EQ(stats.target_delay_ms, info.receivers[0].target_delay_ms); |
| 4847 | EXPECT_EQ(stats.jitter_buffer_ms, info.receivers[0].jitter_buffer_ms); |
| 4848 | EXPECT_EQ(stats.min_playout_delay_ms, info.receivers[0].min_playout_delay_ms); |
| 4849 | EXPECT_EQ(stats.render_delay_ms, info.receivers[0].render_delay_ms); |
asapersson | 26dd92b | 2016-08-30 00:45:45 -0700 | [diff] [blame] | 4850 | EXPECT_EQ(stats.width, info.receivers[0].frame_width); |
| 4851 | EXPECT_EQ(stats.height, info.receivers[0].frame_height); |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 4852 | EXPECT_EQ(rtc::checked_cast<unsigned int>(stats.frame_counts.key_frames + |
| 4853 | stats.frame_counts.delta_frames), |
hbos | 42f6d2f | 2017-01-20 03:56:50 -0800 | [diff] [blame] | 4854 | info.receivers[0].frames_received); |
hbos | 50cfe1f | 2017-01-23 07:21:55 -0800 | [diff] [blame] | 4855 | EXPECT_EQ(stats.frames_rendered, info.receivers[0].frames_rendered); |
sakal | e5ba44e | 2016-10-26 07:09:24 -0700 | [diff] [blame] | 4856 | EXPECT_EQ(stats.frames_decoded, info.receivers[0].frames_decoded); |
sakal | cc452e1 | 2017-02-09 04:53:45 -0800 | [diff] [blame] | 4857 | EXPECT_EQ(stats.qp_sum, info.receivers[0].qp_sum); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 4858 | } |
| 4859 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4860 | TEST_F(WebRtcVideoChannelTest, GetStatsTranslatesReceivePacketStatsCorrectly) { |
Peter Boström | 393347f | 2015-04-22 14:52:45 +0200 | [diff] [blame] | 4861 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 4862 | webrtc::VideoReceiveStream::Stats stats; |
| 4863 | stats.rtp_stats.transmitted.payload_bytes = 2; |
| 4864 | stats.rtp_stats.transmitted.header_bytes = 3; |
| 4865 | stats.rtp_stats.transmitted.padding_bytes = 4; |
| 4866 | stats.rtp_stats.transmitted.packets = 5; |
srte | 186d9c3 | 2017-08-04 05:03:53 -0700 | [diff] [blame] | 4867 | stats.rtcp_stats.packets_lost = 6; |
Peter Boström | 393347f | 2015-04-22 14:52:45 +0200 | [diff] [blame] | 4868 | stats.rtcp_stats.fraction_lost = 7; |
| 4869 | stream->SetStats(stats); |
| 4870 | |
| 4871 | cricket::VideoMediaInfo info; |
| 4872 | ASSERT_TRUE(channel_->GetStats(&info)); |
| 4873 | EXPECT_EQ(stats.rtp_stats.transmitted.payload_bytes + |
| 4874 | stats.rtp_stats.transmitted.header_bytes + |
| 4875 | stats.rtp_stats.transmitted.padding_bytes, |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 4876 | rtc::checked_cast<size_t>(info.receivers[0].bytes_rcvd)); |
Peter Boström | 393347f | 2015-04-22 14:52:45 +0200 | [diff] [blame] | 4877 | EXPECT_EQ(stats.rtp_stats.transmitted.packets, |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 4878 | rtc::checked_cast<unsigned int>(info.receivers[0].packets_rcvd)); |
srte | 186d9c3 | 2017-08-04 05:03:53 -0700 | [diff] [blame] | 4879 | EXPECT_EQ(stats.rtcp_stats.packets_lost, info.receivers[0].packets_lost); |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 4880 | 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] | 4881 | info.receivers[0].fraction_lost); |
| 4882 | } |
| 4883 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4884 | TEST_F(WebRtcVideoChannelTest, TranslatesCallStatsCorrectly) { |
pbos@webrtc.org | 2b19f06 | 2014-12-11 13:26:09 +0000 | [diff] [blame] | 4885 | AddSendStream(); |
| 4886 | AddSendStream(); |
| 4887 | webrtc::Call::Stats stats; |
| 4888 | stats.rtt_ms = 123; |
| 4889 | fake_call_->SetStats(stats); |
| 4890 | |
| 4891 | cricket::VideoMediaInfo info; |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 4892 | ASSERT_TRUE(channel_->GetStats(&info)); |
pbos@webrtc.org | 2b19f06 | 2014-12-11 13:26:09 +0000 | [diff] [blame] | 4893 | ASSERT_EQ(2u, info.senders.size()); |
| 4894 | EXPECT_EQ(stats.rtt_ms, info.senders[0].rtt_ms); |
| 4895 | EXPECT_EQ(stats.rtt_ms, info.senders[1].rtt_ms); |
| 4896 | } |
| 4897 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4898 | TEST_F(WebRtcVideoChannelTest, TranslatesSenderBitrateStatsCorrectly) { |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 4899 | FakeVideoSendStream* stream = AddSendStream(); |
| 4900 | webrtc::VideoSendStream::Stats stats; |
pbos@webrtc.org | 891d483 | 2015-02-26 13:15:22 +0000 | [diff] [blame] | 4901 | stats.target_media_bitrate_bps = 156; |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 4902 | stats.media_bitrate_bps = 123; |
| 4903 | stats.substreams[17].total_bitrate_bps = 1; |
| 4904 | stats.substreams[17].retransmit_bitrate_bps = 2; |
| 4905 | stats.substreams[42].total_bitrate_bps = 3; |
| 4906 | stats.substreams[42].retransmit_bitrate_bps = 4; |
| 4907 | stream->SetStats(stats); |
| 4908 | |
| 4909 | FakeVideoSendStream* stream2 = AddSendStream(); |
| 4910 | webrtc::VideoSendStream::Stats stats2; |
pbos@webrtc.org | 891d483 | 2015-02-26 13:15:22 +0000 | [diff] [blame] | 4911 | stats2.target_media_bitrate_bps = 200; |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 4912 | stats2.media_bitrate_bps = 321; |
| 4913 | stats2.substreams[13].total_bitrate_bps = 5; |
| 4914 | stats2.substreams[13].retransmit_bitrate_bps = 6; |
| 4915 | stats2.substreams[21].total_bitrate_bps = 7; |
| 4916 | stats2.substreams[21].retransmit_bitrate_bps = 8; |
| 4917 | stream2->SetStats(stats2); |
| 4918 | |
| 4919 | cricket::VideoMediaInfo info; |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 4920 | ASSERT_TRUE(channel_->GetStats(&info)); |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 4921 | ASSERT_EQ(2u, info.senders.size()); |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 4922 | BandwidthEstimationInfo bwe_info; |
| 4923 | channel_->FillBitrateInfo(&bwe_info); |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 4924 | // Assuming stream and stream2 corresponds to senders[0] and [1] respectively |
| 4925 | // is OK as std::maps are sorted and AddSendStream() gives increasing SSRCs. |
| 4926 | EXPECT_EQ(stats.media_bitrate_bps, info.senders[0].nominal_bitrate); |
| 4927 | EXPECT_EQ(stats2.media_bitrate_bps, info.senders[1].nominal_bitrate); |
pbos@webrtc.org | 891d483 | 2015-02-26 13:15:22 +0000 | [diff] [blame] | 4928 | EXPECT_EQ(stats.target_media_bitrate_bps + stats2.target_media_bitrate_bps, |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 4929 | bwe_info.target_enc_bitrate); |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 4930 | EXPECT_EQ(stats.media_bitrate_bps + stats2.media_bitrate_bps, |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 4931 | bwe_info.actual_enc_bitrate); |
| 4932 | EXPECT_EQ(1 + 3 + 5 + 7, bwe_info.transmit_bitrate) |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 4933 | << "Bandwidth stats should take all streams into account."; |
stefan | f79ade1 | 2017-06-02 06:44:03 -0700 | [diff] [blame] | 4934 | EXPECT_EQ(2 + 4 + 6 + 8, bwe_info.retransmit_bitrate) |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 4935 | << "Bandwidth stats should take all streams into account."; |
| 4936 | } |
| 4937 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4938 | TEST_F(WebRtcVideoChannelTest, DefaultReceiveStreamReconfiguresToUseRtx) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4939 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
pbos@webrtc.org | a2a6fe6 | 2015-03-06 15:35:19 +0000 | [diff] [blame] | 4940 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 4941 | const std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs1); |
| 4942 | const std::vector<uint32_t> rtx_ssrcs = MAKE_VECTOR(kRtxSsrcs1); |
pbos@webrtc.org | a2a6fe6 | 2015-03-06 15:35:19 +0000 | [diff] [blame] | 4943 | |
| 4944 | ASSERT_EQ(0u, fake_call_->GetVideoReceiveStreams().size()); |
| 4945 | const size_t kDataLength = 12; |
| 4946 | uint8_t data[kDataLength]; |
| 4947 | memset(data, 0, sizeof(data)); |
| 4948 | rtc::SetBE32(&data[8], ssrcs[0]); |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 4949 | rtc::CopyOnWriteBuffer packet(data, kDataLength); |
pbos@webrtc.org | a2a6fe6 | 2015-03-06 15:35:19 +0000 | [diff] [blame] | 4950 | rtc::PacketTime packet_time; |
| 4951 | channel_->OnPacketReceived(&packet, packet_time); |
| 4952 | |
| 4953 | ASSERT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()) |
| 4954 | << "No default receive stream created."; |
| 4955 | FakeVideoReceiveStream* recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 4956 | EXPECT_EQ(0u, recv_stream->GetConfig().rtp.rtx_ssrc) |
pbos@webrtc.org | a2a6fe6 | 2015-03-06 15:35:19 +0000 | [diff] [blame] | 4957 | << "Default receive stream should not have configured RTX"; |
| 4958 | |
| 4959 | EXPECT_TRUE(channel_->AddRecvStream( |
| 4960 | cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs))); |
| 4961 | ASSERT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()) |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 4962 | << "AddRecvStream should have reconfigured, not added a new receiver."; |
pbos@webrtc.org | a2a6fe6 | 2015-03-06 15:35:19 +0000 | [diff] [blame] | 4963 | recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
nisse | 26e3abb | 2017-08-25 04:44:25 -0700 | [diff] [blame] | 4964 | EXPECT_FALSE( |
| 4965 | recv_stream->GetConfig().rtp.rtx_associated_payload_types.empty()); |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 4966 | EXPECT_TRUE(VerifyRtxReceiveAssociations(recv_stream->GetConfig())) |
Peter Boström | d8b0109 | 2016-05-12 16:44:36 +0200 | [diff] [blame] | 4967 | << "RTX should be mapped for all decoders/payload types."; |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 4968 | EXPECT_TRUE(HasRtxReceiveAssociation(recv_stream->GetConfig(), |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 4969 | GetEngineCodec("red").id)) |
nisse | ca5706d | 2017-09-11 02:32:16 -0700 | [diff] [blame] | 4970 | << "RTX should be mapped also for the RED payload type"; |
brandtr | 1474212 | 2017-01-27 04:53:07 -0800 | [diff] [blame] | 4971 | EXPECT_EQ(rtx_ssrcs[0], recv_stream->GetConfig().rtp.rtx_ssrc); |
pbos@webrtc.org | a2a6fe6 | 2015-03-06 15:35:19 +0000 | [diff] [blame] | 4972 | } |
| 4973 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4974 | TEST_F(WebRtcVideoChannelTest, RejectsAddingStreamsWithMissingSsrcsForRtx) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4975 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Peter Boström | d4362cd | 2015-03-25 14:17:23 +0100 | [diff] [blame] | 4976 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 4977 | const std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs1); |
| 4978 | const std::vector<uint32_t> rtx_ssrcs = MAKE_VECTOR(kRtxSsrcs1); |
Peter Boström | d4362cd | 2015-03-25 14:17:23 +0100 | [diff] [blame] | 4979 | |
| 4980 | StreamParams sp = |
| 4981 | cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs); |
| 4982 | sp.ssrcs = ssrcs; // Without RTXs, this is the important part. |
| 4983 | |
| 4984 | EXPECT_FALSE(channel_->AddSendStream(sp)); |
| 4985 | EXPECT_FALSE(channel_->AddRecvStream(sp)); |
| 4986 | } |
| 4987 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 4988 | TEST_F(WebRtcVideoChannelTest, RejectsAddingStreamsWithOverlappingRtxSsrcs) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 4989 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 4990 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 4991 | const std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs1); |
| 4992 | const std::vector<uint32_t> rtx_ssrcs = MAKE_VECTOR(kRtxSsrcs1); |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 4993 | |
| 4994 | StreamParams sp = |
| 4995 | cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs); |
| 4996 | |
| 4997 | EXPECT_TRUE(channel_->AddSendStream(sp)); |
| 4998 | EXPECT_TRUE(channel_->AddRecvStream(sp)); |
| 4999 | |
| 5000 | // The RTX SSRC is already used in previous streams, using it should fail. |
| 5001 | sp = cricket::StreamParams::CreateLegacy(rtx_ssrcs[0]); |
| 5002 | EXPECT_FALSE(channel_->AddSendStream(sp)); |
| 5003 | EXPECT_FALSE(channel_->AddRecvStream(sp)); |
| 5004 | |
| 5005 | // After removing the original stream this should be fine to add (makes sure |
| 5006 | // that RTX ssrcs are not forever taken). |
| 5007 | EXPECT_TRUE(channel_->RemoveSendStream(ssrcs[0])); |
| 5008 | EXPECT_TRUE(channel_->RemoveRecvStream(ssrcs[0])); |
| 5009 | EXPECT_TRUE(channel_->AddSendStream(sp)); |
| 5010 | EXPECT_TRUE(channel_->AddRecvStream(sp)); |
| 5011 | } |
| 5012 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5013 | TEST_F(WebRtcVideoChannelTest, |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 5014 | RejectsAddingStreamsWithOverlappingSimulcastSsrcs) { |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 5015 | static const uint32_t kFirstStreamSsrcs[] = {1, 2, 3}; |
| 5016 | static const uint32_t kOverlappingStreamSsrcs[] = {4, 3, 5}; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 5017 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 5018 | |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 5019 | StreamParams sp = |
| 5020 | cricket::CreateSimStreamParams("cname", MAKE_VECTOR(kFirstStreamSsrcs)); |
| 5021 | |
| 5022 | EXPECT_TRUE(channel_->AddSendStream(sp)); |
| 5023 | EXPECT_TRUE(channel_->AddRecvStream(sp)); |
| 5024 | |
| 5025 | // One of the SSRCs is already used in previous streams, using it should fail. |
| 5026 | sp = cricket::CreateSimStreamParams("cname", |
| 5027 | MAKE_VECTOR(kOverlappingStreamSsrcs)); |
| 5028 | EXPECT_FALSE(channel_->AddSendStream(sp)); |
| 5029 | EXPECT_FALSE(channel_->AddRecvStream(sp)); |
| 5030 | |
| 5031 | // After removing the original stream this should be fine to add (makes sure |
| 5032 | // that RTX ssrcs are not forever taken). |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 5033 | EXPECT_TRUE(channel_->RemoveSendStream(kFirstStreamSsrcs[0])); |
| 5034 | EXPECT_TRUE(channel_->RemoveRecvStream(kFirstStreamSsrcs[0])); |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 5035 | EXPECT_TRUE(channel_->AddSendStream(sp)); |
| 5036 | EXPECT_TRUE(channel_->AddRecvStream(sp)); |
| 5037 | } |
| 5038 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5039 | TEST_F(WebRtcVideoChannelTest, ReportsSsrcGroupsInStats) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 5040 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Peter Boström | 259bd20 | 2015-05-28 13:39:50 +0200 | [diff] [blame] | 5041 | |
| 5042 | static const uint32_t kSenderSsrcs[] = {4, 7, 10}; |
| 5043 | static const uint32_t kSenderRtxSsrcs[] = {5, 8, 11}; |
| 5044 | |
| 5045 | StreamParams sender_sp = cricket::CreateSimWithRtxStreamParams( |
| 5046 | "cname", MAKE_VECTOR(kSenderSsrcs), MAKE_VECTOR(kSenderRtxSsrcs)); |
| 5047 | |
| 5048 | EXPECT_TRUE(channel_->AddSendStream(sender_sp)); |
| 5049 | |
| 5050 | static const uint32_t kReceiverSsrcs[] = {3}; |
| 5051 | static const uint32_t kReceiverRtxSsrcs[] = {2}; |
| 5052 | |
| 5053 | StreamParams receiver_sp = cricket::CreateSimWithRtxStreamParams( |
| 5054 | "cname", MAKE_VECTOR(kReceiverSsrcs), MAKE_VECTOR(kReceiverRtxSsrcs)); |
| 5055 | EXPECT_TRUE(channel_->AddRecvStream(receiver_sp)); |
| 5056 | |
| 5057 | cricket::VideoMediaInfo info; |
| 5058 | ASSERT_TRUE(channel_->GetStats(&info)); |
| 5059 | |
| 5060 | ASSERT_EQ(1u, info.senders.size()); |
| 5061 | ASSERT_EQ(1u, info.receivers.size()); |
| 5062 | |
| 5063 | EXPECT_NE(sender_sp.ssrc_groups, receiver_sp.ssrc_groups); |
| 5064 | EXPECT_EQ(sender_sp.ssrc_groups, info.senders[0].ssrc_groups); |
| 5065 | EXPECT_EQ(receiver_sp.ssrc_groups, info.receivers[0].ssrc_groups); |
| 5066 | } |
| 5067 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5068 | TEST_F(WebRtcVideoChannelTest, MapsReceivedPayloadTypeToCodecName) { |
pbos | f42376c | 2015-08-28 07:35:32 -0700 | [diff] [blame] | 5069 | FakeVideoReceiveStream* stream = AddRecvStream(); |
| 5070 | webrtc::VideoReceiveStream::Stats stats; |
| 5071 | cricket::VideoMediaInfo info; |
| 5072 | |
| 5073 | // Report no codec name before receiving. |
| 5074 | stream->SetStats(stats); |
| 5075 | ASSERT_TRUE(channel_->GetStats(&info)); |
| 5076 | EXPECT_STREQ("", info.receivers[0].codec_name.c_str()); |
| 5077 | |
| 5078 | // Report VP8 if we're receiving it. |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5079 | stats.current_payload_type = GetEngineCodec("VP8").id; |
pbos | f42376c | 2015-08-28 07:35:32 -0700 | [diff] [blame] | 5080 | stream->SetStats(stats); |
| 5081 | ASSERT_TRUE(channel_->GetStats(&info)); |
| 5082 | EXPECT_STREQ(kVp8CodecName, info.receivers[0].codec_name.c_str()); |
| 5083 | |
| 5084 | // Report no codec name for unknown playload types. |
| 5085 | stats.current_payload_type = 3; |
| 5086 | stream->SetStats(stats); |
| 5087 | ASSERT_TRUE(channel_->GetStats(&info)); |
| 5088 | EXPECT_STREQ("", info.receivers[0].codec_name.c_str()); |
| 5089 | } |
| 5090 | |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 5091 | // Tests that when we add a stream without SSRCs, but contains a stream_id |
| 5092 | // that it is stored and its stream id is later used when the first packet |
| 5093 | // arrives to properly create a receive stream with a sync label. |
| 5094 | TEST_F(WebRtcVideoChannelTest, RecvUnsignaledSsrcWithSignaledStreamId) { |
| 5095 | const char kSyncLabel[] = "sync_label"; |
| 5096 | cricket::StreamParams unsignaled_stream; |
| 5097 | unsignaled_stream.set_stream_ids({kSyncLabel}); |
| 5098 | ASSERT_TRUE(channel_->AddRecvStream(unsignaled_stream)); |
| 5099 | // The stream shouldn't have been created at this point because it doesn't |
| 5100 | // have any SSRCs. |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 5101 | EXPECT_EQ(0u, fake_call_->GetVideoReceiveStreams().size()); |
Seth Hampson | 5897a6e | 2018-04-03 11:16:33 -0700 | [diff] [blame] | 5102 | |
| 5103 | // Create and deliver packet. |
| 5104 | const size_t kDataLength = 12; |
| 5105 | uint8_t data[kDataLength]; |
| 5106 | memset(data, 0, sizeof(data)); |
| 5107 | rtc::SetBE32(&data[8], kIncomingUnsignalledSsrc); |
| 5108 | rtc::CopyOnWriteBuffer packet(data, kDataLength); |
| 5109 | rtc::PacketTime packet_time; |
| 5110 | channel_->OnPacketReceived(&packet, packet_time); |
| 5111 | |
| 5112 | // The stream should now be created with the appropriate sync label. |
| 5113 | EXPECT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
| 5114 | EXPECT_EQ(kSyncLabel, |
| 5115 | fake_call_->GetVideoReceiveStreams()[0]->GetConfig().sync_group); |
| 5116 | |
| 5117 | // Removing the unsignaled stream should clear the cache. This time when |
| 5118 | // a default video receive stream is created it won't have a sync_group. |
| 5119 | ASSERT_TRUE(channel_->RemoveRecvStream(0)); |
| 5120 | ASSERT_TRUE(channel_->RemoveRecvStream(kIncomingUnsignalledSsrc)); |
| 5121 | EXPECT_EQ(0u, fake_call_->GetVideoReceiveStreams().size()); |
| 5122 | |
| 5123 | channel_->OnPacketReceived(&packet, packet_time); |
| 5124 | EXPECT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
| 5125 | EXPECT_TRUE( |
| 5126 | fake_call_->GetVideoReceiveStreams()[0]->GetConfig().sync_group.empty()); |
| 5127 | } |
| 5128 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5129 | void WebRtcVideoChannelTest::TestReceiveUnsignaledSsrcPacket( |
noahric | d10a68e | 2015-07-10 11:27:55 -0700 | [diff] [blame] | 5130 | uint8_t payload_type, |
| 5131 | bool expect_created_receive_stream) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5132 | // kRedRtxPayloadType must currently be unused. |
| 5133 | EXPECT_FALSE(FindCodecById(engine_.codecs(), kRedRtxPayloadType)); |
| 5134 | |
noahric | d10a68e | 2015-07-10 11:27:55 -0700 | [diff] [blame] | 5135 | // Add a RED RTX codec. |
| 5136 | VideoCodec red_rtx_codec = |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5137 | VideoCodec::CreateRtxCodec(kRedRtxPayloadType, GetEngineCodec("red").id); |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 5138 | recv_parameters_.codecs.push_back(red_rtx_codec); |
| 5139 | EXPECT_TRUE(channel_->SetRecvParameters(recv_parameters_)); |
noahric | d10a68e | 2015-07-10 11:27:55 -0700 | [diff] [blame] | 5140 | |
| 5141 | ASSERT_EQ(0u, fake_call_->GetVideoReceiveStreams().size()); |
| 5142 | const size_t kDataLength = 12; |
| 5143 | uint8_t data[kDataLength]; |
| 5144 | memset(data, 0, sizeof(data)); |
| 5145 | |
| 5146 | rtc::Set8(data, 1, payload_type); |
| 5147 | rtc::SetBE32(&data[8], kIncomingUnsignalledSsrc); |
jbauch | eec21bd | 2016-03-20 06:15:43 -0700 | [diff] [blame] | 5148 | rtc::CopyOnWriteBuffer packet(data, kDataLength); |
noahric | d10a68e | 2015-07-10 11:27:55 -0700 | [diff] [blame] | 5149 | rtc::PacketTime packet_time; |
| 5150 | channel_->OnPacketReceived(&packet, packet_time); |
| 5151 | |
| 5152 | if (expect_created_receive_stream) { |
| 5153 | EXPECT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()) |
| 5154 | << "Should have created a receive stream for payload type: " |
| 5155 | << payload_type; |
| 5156 | } else { |
| 5157 | EXPECT_EQ(0u, fake_call_->GetVideoReceiveStreams().size()) |
| 5158 | << "Shouldn't have created a receive stream for payload type: " |
| 5159 | << payload_type; |
| 5160 | } |
| 5161 | } |
| 5162 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5163 | TEST_F(WebRtcVideoChannelTest, Vp8PacketCreatesUnsignalledStream) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5164 | TestReceiveUnsignaledSsrcPacket(GetEngineCodec("VP8").id, |
| 5165 | true /* expect_created_receive_stream */); |
noahric | d10a68e | 2015-07-10 11:27:55 -0700 | [diff] [blame] | 5166 | } |
| 5167 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5168 | TEST_F(WebRtcVideoChannelTest, Vp9PacketCreatesUnsignalledStream) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5169 | TestReceiveUnsignaledSsrcPacket(GetEngineCodec("VP9").id, |
| 5170 | true /* expect_created_receive_stream */); |
noahric | d10a68e | 2015-07-10 11:27:55 -0700 | [diff] [blame] | 5171 | } |
| 5172 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5173 | TEST_F(WebRtcVideoChannelTest, RtxPacketDoesntCreateUnsignalledStream) { |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 5174 | AssignDefaultAptRtxTypes(); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5175 | const cricket::VideoCodec vp8 = GetEngineCodec("VP8"); |
| 5176 | const int rtx_vp8_payload_type = default_apt_rtx_types_[vp8.id]; |
| 5177 | TestReceiveUnsignaledSsrcPacket(rtx_vp8_payload_type, |
| 5178 | false /* expect_created_receive_stream */); |
noahric | d10a68e | 2015-07-10 11:27:55 -0700 | [diff] [blame] | 5179 | } |
| 5180 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5181 | TEST_F(WebRtcVideoChannelTest, UlpfecPacketDoesntCreateUnsignalledStream) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5182 | TestReceiveUnsignaledSsrcPacket(GetEngineCodec("ulpfec").id, |
| 5183 | false /* expect_created_receive_stream */); |
noahric | d10a68e | 2015-07-10 11:27:55 -0700 | [diff] [blame] | 5184 | } |
| 5185 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5186 | TEST_F(WebRtcVideoChannelFlexfecRecvTest, |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 5187 | FlexfecPacketDoesntCreateUnsignalledStream) { |
| 5188 | TestReceiveUnsignaledSsrcPacket(GetEngineCodec("flexfec-03").id, |
| 5189 | false /* expect_created_receive_stream */); |
| 5190 | } |
| 5191 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5192 | TEST_F(WebRtcVideoChannelTest, RedRtxPacketDoesntCreateUnsignalledStream) { |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 5193 | TestReceiveUnsignaledSsrcPacket(kRedRtxPayloadType, |
| 5194 | false /* expect_created_receive_stream */); |
noahric | d10a68e | 2015-07-10 11:27:55 -0700 | [diff] [blame] | 5195 | } |
| 5196 | |
mzanaty | 8a855d6 | 2017-02-17 15:46:43 -0800 | [diff] [blame] | 5197 | // Test that receiving any unsignalled SSRC works even if it changes. |
| 5198 | // The first unsignalled SSRC received will create a default receive stream. |
| 5199 | // Any different unsignalled SSRC received will replace the default. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5200 | TEST_F(WebRtcVideoChannelTest, ReceiveDifferentUnsignaledSsrc) { |
mzanaty | 8a855d6 | 2017-02-17 15:46:43 -0800 | [diff] [blame] | 5201 | // Allow receiving VP8, VP9, H264 (if enabled). |
| 5202 | cricket::VideoRecvParameters parameters; |
| 5203 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 5204 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
| 5205 | |
| 5206 | #if defined(WEBRTC_USE_H264) |
| 5207 | cricket::VideoCodec H264codec(126, "H264"); |
| 5208 | parameters.codecs.push_back(H264codec); |
| 5209 | #endif |
| 5210 | |
| 5211 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
| 5212 | // No receive streams yet. |
| 5213 | ASSERT_EQ(0u, fake_call_->GetVideoReceiveStreams().size()); |
| 5214 | cricket::FakeVideoRenderer renderer; |
| 5215 | EXPECT_TRUE(channel_->SetSink(kDefaultRecvSsrc, &renderer)); |
| 5216 | |
| 5217 | // Receive VP8 packet on first SSRC. |
| 5218 | uint8_t data[kMinRtpPacketLen]; |
| 5219 | cricket::RtpHeader rtpHeader; |
| 5220 | rtpHeader.payload_type = GetEngineCodec("VP8").id; |
| 5221 | rtpHeader.seq_num = rtpHeader.timestamp = 0; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 5222 | rtpHeader.ssrc = kIncomingUnsignalledSsrc + 1; |
mzanaty | 8a855d6 | 2017-02-17 15:46:43 -0800 | [diff] [blame] | 5223 | cricket::SetRtpHeader(data, sizeof(data), rtpHeader); |
| 5224 | rtc::CopyOnWriteBuffer packet(data, sizeof(data)); |
| 5225 | rtc::PacketTime packet_time; |
| 5226 | channel_->OnPacketReceived(&packet, packet_time); |
| 5227 | // VP8 packet should create default receive stream. |
| 5228 | ASSERT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 5229 | FakeVideoReceiveStream* recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
mzanaty | 8a855d6 | 2017-02-17 15:46:43 -0800 | [diff] [blame] | 5230 | EXPECT_EQ(rtpHeader.ssrc, recv_stream->GetConfig().rtp.remote_ssrc); |
| 5231 | // Verify that the receive stream sinks to a renderer. |
| 5232 | webrtc::VideoFrame video_frame(CreateBlackFrameBuffer(4, 4), 100, 0, |
| 5233 | webrtc::kVideoRotation_0); |
| 5234 | recv_stream->InjectFrame(video_frame); |
| 5235 | EXPECT_EQ(1, renderer.num_rendered_frames()); |
| 5236 | |
| 5237 | // Receive VP9 packet on second SSRC. |
| 5238 | rtpHeader.payload_type = GetEngineCodec("VP9").id; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 5239 | rtpHeader.ssrc = kIncomingUnsignalledSsrc + 2; |
mzanaty | 8a855d6 | 2017-02-17 15:46:43 -0800 | [diff] [blame] | 5240 | cricket::SetRtpHeader(data, sizeof(data), rtpHeader); |
| 5241 | rtc::CopyOnWriteBuffer packet2(data, sizeof(data)); |
| 5242 | channel_->OnPacketReceived(&packet2, packet_time); |
| 5243 | // VP9 packet should replace the default receive SSRC. |
| 5244 | ASSERT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
| 5245 | recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
| 5246 | EXPECT_EQ(rtpHeader.ssrc, recv_stream->GetConfig().rtp.remote_ssrc); |
| 5247 | // Verify that the receive stream sinks to a renderer. |
| 5248 | webrtc::VideoFrame video_frame2(CreateBlackFrameBuffer(4, 4), 200, 0, |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 5249 | webrtc::kVideoRotation_0); |
mzanaty | 8a855d6 | 2017-02-17 15:46:43 -0800 | [diff] [blame] | 5250 | recv_stream->InjectFrame(video_frame2); |
| 5251 | EXPECT_EQ(2, renderer.num_rendered_frames()); |
| 5252 | |
| 5253 | #if defined(WEBRTC_USE_H264) |
| 5254 | // Receive H264 packet on third SSRC. |
| 5255 | rtpHeader.payload_type = 126; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 5256 | rtpHeader.ssrc = kIncomingUnsignalledSsrc + 3; |
mzanaty | 8a855d6 | 2017-02-17 15:46:43 -0800 | [diff] [blame] | 5257 | cricket::SetRtpHeader(data, sizeof(data), rtpHeader); |
| 5258 | rtc::CopyOnWriteBuffer packet3(data, sizeof(data)); |
| 5259 | channel_->OnPacketReceived(&packet3, packet_time); |
| 5260 | // H264 packet should replace the default receive SSRC. |
| 5261 | ASSERT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
| 5262 | recv_stream = fake_call_->GetVideoReceiveStreams()[0]; |
| 5263 | EXPECT_EQ(rtpHeader.ssrc, recv_stream->GetConfig().rtp.remote_ssrc); |
| 5264 | // Verify that the receive stream sinks to a renderer. |
| 5265 | webrtc::VideoFrame video_frame3(CreateBlackFrameBuffer(4, 4), 300, 0, |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 5266 | webrtc::kVideoRotation_0); |
mzanaty | 8a855d6 | 2017-02-17 15:46:43 -0800 | [diff] [blame] | 5267 | recv_stream->InjectFrame(video_frame3); |
| 5268 | EXPECT_EQ(3, renderer.num_rendered_frames()); |
| 5269 | #endif |
| 5270 | } |
| 5271 | |
brandtr | 0dc57ea | 2017-05-29 23:33:31 -0700 | [diff] [blame] | 5272 | // This test verifies that when a new default stream is created for a new |
| 5273 | // unsignaled SSRC, the new stream does not overwrite any old stream that had |
| 5274 | // been the default receive stream before being properly signaled. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5275 | TEST_F(WebRtcVideoChannelTest, |
brandtr | 0dc57ea | 2017-05-29 23:33:31 -0700 | [diff] [blame] | 5276 | NewUnsignaledStreamDoesNotDestroyPreviouslyUnsignaledStream) { |
| 5277 | cricket::VideoRecvParameters parameters; |
| 5278 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 5279 | ASSERT_TRUE(channel_->SetRecvParameters(parameters)); |
| 5280 | |
| 5281 | // No streams signaled and no packets received, so we should not have any |
| 5282 | // stream objects created yet. |
| 5283 | EXPECT_EQ(0u, fake_call_->GetVideoReceiveStreams().size()); |
| 5284 | |
| 5285 | // Receive packet on an unsignaled SSRC. |
| 5286 | uint8_t data[kMinRtpPacketLen]; |
| 5287 | cricket::RtpHeader rtp_header; |
| 5288 | rtp_header.payload_type = GetEngineCodec("VP8").id; |
| 5289 | rtp_header.seq_num = rtp_header.timestamp = 0; |
| 5290 | rtp_header.ssrc = kSsrcs3[0]; |
| 5291 | cricket::SetRtpHeader(data, sizeof(data), rtp_header); |
| 5292 | rtc::CopyOnWriteBuffer packet(data, sizeof(data)); |
| 5293 | rtc::PacketTime packet_time; |
| 5294 | channel_->OnPacketReceived(&packet, packet_time); |
| 5295 | // Default receive stream should be created. |
| 5296 | ASSERT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
| 5297 | FakeVideoReceiveStream* recv_stream0 = |
| 5298 | fake_call_->GetVideoReceiveStreams()[0]; |
| 5299 | EXPECT_EQ(kSsrcs3[0], recv_stream0->GetConfig().rtp.remote_ssrc); |
| 5300 | |
| 5301 | // Signal the SSRC. |
| 5302 | EXPECT_TRUE( |
| 5303 | channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrcs3[0]))); |
| 5304 | ASSERT_EQ(1u, fake_call_->GetVideoReceiveStreams().size()); |
| 5305 | recv_stream0 = fake_call_->GetVideoReceiveStreams()[0]; |
| 5306 | EXPECT_EQ(kSsrcs3[0], recv_stream0->GetConfig().rtp.remote_ssrc); |
| 5307 | |
| 5308 | // Receive packet on a different unsignaled SSRC. |
| 5309 | rtp_header.ssrc = kSsrcs3[1]; |
| 5310 | cricket::SetRtpHeader(data, sizeof(data), rtp_header); |
| 5311 | packet.SetData(data, sizeof(data)); |
| 5312 | channel_->OnPacketReceived(&packet, packet_time); |
| 5313 | // New default receive stream should be created, but old stream should remain. |
| 5314 | ASSERT_EQ(2u, fake_call_->GetVideoReceiveStreams().size()); |
| 5315 | EXPECT_EQ(recv_stream0, fake_call_->GetVideoReceiveStreams()[0]); |
| 5316 | FakeVideoReceiveStream* recv_stream1 = |
| 5317 | fake_call_->GetVideoReceiveStreams()[1]; |
| 5318 | EXPECT_EQ(kSsrcs3[1], recv_stream1->GetConfig().rtp.remote_ssrc); |
| 5319 | } |
| 5320 | |
Seth Hampson | 7c682e0 | 2018-05-04 16:28:15 -0700 | [diff] [blame] | 5321 | TEST_F(WebRtcVideoChannelTest, CanSetMaxBitrateForExistingStream) { |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5322 | AddSendStream(); |
| 5323 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 5324 | FakeVideoCapturerWithTaskQueue capturer; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 5325 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, &capturer)); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5326 | cricket::VideoFormat capture_format_hd = |
| 5327 | capturer.GetSupportedFormats()->front(); |
| 5328 | EXPECT_EQ(1280, capture_format_hd.width); |
| 5329 | EXPECT_EQ(720, capture_format_hd.height); |
| 5330 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format_hd)); |
| 5331 | EXPECT_TRUE(channel_->SetSend(true)); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 5332 | capturer.CaptureFrame(); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5333 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 5334 | int default_encoder_bitrate = GetMaxEncoderBitrate(); |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 5335 | EXPECT_GT(default_encoder_bitrate, 1000); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5336 | |
| 5337 | // TODO(skvlad): Resolve the inconsistency between the interpretation |
| 5338 | // of the global bitrate limit for audio and video: |
| 5339 | // - Audio: max_bandwidth_bps = 0 - fail the operation, |
| 5340 | // max_bandwidth_bps = -1 - remove the bandwidth limit |
| 5341 | // - Video: max_bandwidth_bps = 0 - remove the bandwidth limit, |
pbos | 5c7760a | 2017-03-10 11:23:12 -0800 | [diff] [blame] | 5342 | // max_bandwidth_bps = -1 - remove the bandwidth limit |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5343 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 5344 | SetAndExpectMaxBitrate(1000, 0, 1000); |
| 5345 | SetAndExpectMaxBitrate(1000, 800, 800); |
| 5346 | SetAndExpectMaxBitrate(600, 800, 600); |
| 5347 | SetAndExpectMaxBitrate(0, 800, 800); |
| 5348 | SetAndExpectMaxBitrate(0, 0, default_encoder_bitrate); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5349 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 5350 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5351 | } |
| 5352 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5353 | TEST_F(WebRtcVideoChannelTest, CannotSetMaxBitrateForNonexistentStream) { |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5354 | webrtc::RtpParameters nonexistent_parameters = |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 5355 | channel_->GetRtpSendParameters(last_ssrc_); |
Mirko Bonadei | f859e55 | 2018-05-30 15:31:29 +0200 | [diff] [blame] | 5356 | EXPECT_EQ(0u, nonexistent_parameters.encodings.size()); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5357 | |
| 5358 | nonexistent_parameters.encodings.push_back(webrtc::RtpEncodingParameters()); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 5359 | EXPECT_FALSE( |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5360 | channel_->SetRtpSendParameters(last_ssrc_, nonexistent_parameters).ok()); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5361 | } |
| 5362 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5363 | TEST_F(WebRtcVideoChannelTest, |
Seth Hampson | 7c682e0 | 2018-05-04 16:28:15 -0700 | [diff] [blame] | 5364 | SetLowMaxBitrateOverwritesVideoStreamMinBitrate) { |
Åsa Persson | bdee46d | 2018-06-25 11:28:06 +0200 | [diff] [blame] | 5365 | FakeVideoSendStream* stream = AddSendStream(); |
| 5366 | |
Seth Hampson | 7c682e0 | 2018-05-04 16:28:15 -0700 | [diff] [blame] | 5367 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5368 | EXPECT_EQ(1UL, parameters.encodings.size()); |
| 5369 | EXPECT_FALSE(parameters.encodings[0].max_bitrate_bps.has_value()); |
| 5370 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 5371 | |
| 5372 | // Note that this is testing the behavior of the FakeVideoSendStream, which |
| 5373 | // also calls to CreateEncoderStreams to get the VideoStreams, so essentially |
| 5374 | // we are just testing the behavior of |
| 5375 | // EncoderStreamFactory::CreateEncoderStreams. |
Åsa Persson | bdee46d | 2018-06-25 11:28:06 +0200 | [diff] [blame] | 5376 | ASSERT_EQ(1UL, stream->GetVideoStreams().size()); |
| 5377 | EXPECT_EQ(kMinVideoBitrateBps, stream->GetVideoStreams()[0].min_bitrate_bps); |
Seth Hampson | 7c682e0 | 2018-05-04 16:28:15 -0700 | [diff] [blame] | 5378 | |
| 5379 | // Set a low max bitrate & check that VideoStream.min_bitrate_bps is limited |
| 5380 | // by this amount. |
| 5381 | parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5382 | int low_max_bitrate_bps = kMinVideoBitrateBps - 1000; |
| 5383 | parameters.encodings[0].max_bitrate_bps = low_max_bitrate_bps; |
| 5384 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 5385 | |
Åsa Persson | bdee46d | 2018-06-25 11:28:06 +0200 | [diff] [blame] | 5386 | ASSERT_EQ(1UL, stream->GetVideoStreams().size()); |
| 5387 | EXPECT_EQ(low_max_bitrate_bps, stream->GetVideoStreams()[0].min_bitrate_bps); |
| 5388 | EXPECT_EQ(low_max_bitrate_bps, stream->GetVideoStreams()[0].max_bitrate_bps); |
| 5389 | } |
| 5390 | |
| 5391 | TEST_F(WebRtcVideoChannelTest, |
| 5392 | SetHighMinBitrateOverwritesVideoStreamMaxBitrate) { |
| 5393 | FakeVideoSendStream* stream = AddSendStream(); |
| 5394 | |
| 5395 | // Note that this is testing the behavior of the FakeVideoSendStream, which |
| 5396 | // also calls to CreateEncoderStreams to get the VideoStreams, so essentially |
| 5397 | // we are just testing the behavior of |
| 5398 | // EncoderStreamFactory::CreateEncoderStreams. |
| 5399 | ASSERT_EQ(1UL, stream->GetVideoStreams().size()); |
| 5400 | int high_min_bitrate_bps = stream->GetVideoStreams()[0].max_bitrate_bps + 1; |
| 5401 | |
| 5402 | // Set a high min bitrate and check that max_bitrate_bps is adjusted up. |
| 5403 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5404 | EXPECT_EQ(1UL, parameters.encodings.size()); |
| 5405 | parameters.encodings[0].min_bitrate_bps = high_min_bitrate_bps; |
| 5406 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 5407 | |
| 5408 | ASSERT_EQ(1UL, stream->GetVideoStreams().size()); |
| 5409 | EXPECT_EQ(high_min_bitrate_bps, stream->GetVideoStreams()[0].min_bitrate_bps); |
| 5410 | EXPECT_EQ(high_min_bitrate_bps, stream->GetVideoStreams()[0].max_bitrate_bps); |
| 5411 | } |
| 5412 | |
| 5413 | TEST_F(WebRtcVideoChannelTest, |
| 5414 | SetMinBitrateAboveMaxBitrateLimitAdjustsMinBitrateDown) { |
| 5415 | send_parameters_.max_bandwidth_bps = 99999; |
| 5416 | FakeVideoSendStream* stream = AddSendStream(); |
| 5417 | ExpectSetMaxBitrate(send_parameters_.max_bandwidth_bps); |
| 5418 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| 5419 | ASSERT_EQ(1UL, stream->GetVideoStreams().size()); |
| 5420 | EXPECT_EQ(kMinVideoBitrateBps, stream->GetVideoStreams()[0].min_bitrate_bps); |
| 5421 | EXPECT_EQ(send_parameters_.max_bandwidth_bps, |
| 5422 | stream->GetVideoStreams()[0].max_bitrate_bps); |
| 5423 | |
| 5424 | // Set min bitrate above global max bitrate and check that min_bitrate_bps is |
| 5425 | // adjusted down. |
| 5426 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5427 | EXPECT_EQ(1UL, parameters.encodings.size()); |
| 5428 | parameters.encodings[0].min_bitrate_bps = 99999 + 1; |
| 5429 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 5430 | ASSERT_EQ(1UL, stream->GetVideoStreams().size()); |
| 5431 | EXPECT_EQ(send_parameters_.max_bandwidth_bps, |
| 5432 | stream->GetVideoStreams()[0].min_bitrate_bps); |
| 5433 | EXPECT_EQ(send_parameters_.max_bandwidth_bps, |
| 5434 | stream->GetVideoStreams()[0].max_bitrate_bps); |
Seth Hampson | 7c682e0 | 2018-05-04 16:28:15 -0700 | [diff] [blame] | 5435 | } |
| 5436 | |
Åsa Persson | 8c1bf95 | 2018-09-13 10:42:19 +0200 | [diff] [blame] | 5437 | TEST_F(WebRtcVideoChannelTest, SetMaxFramerateOneStream) { |
| 5438 | FakeVideoSendStream* stream = AddSendStream(); |
| 5439 | |
| 5440 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5441 | EXPECT_EQ(1UL, parameters.encodings.size()); |
| 5442 | EXPECT_FALSE(parameters.encodings[0].max_framerate.has_value()); |
| 5443 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 5444 | |
| 5445 | // Note that this is testing the behavior of the FakeVideoSendStream, which |
| 5446 | // also calls to CreateEncoderStreams to get the VideoStreams, so essentially |
| 5447 | // we are just testing the behavior of |
| 5448 | // EncoderStreamFactory::CreateEncoderStreams. |
| 5449 | ASSERT_EQ(1UL, stream->GetVideoStreams().size()); |
| 5450 | EXPECT_EQ(kDefaultVideoMaxFramerate, |
| 5451 | stream->GetVideoStreams()[0].max_framerate); |
| 5452 | |
| 5453 | // Set max framerate and check that VideoStream.max_framerate is set. |
| 5454 | const int kNewMaxFramerate = kDefaultVideoMaxFramerate - 1; |
| 5455 | parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5456 | parameters.encodings[0].max_framerate = kNewMaxFramerate; |
| 5457 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 5458 | |
| 5459 | ASSERT_EQ(1UL, stream->GetVideoStreams().size()); |
| 5460 | EXPECT_EQ(kNewMaxFramerate, stream->GetVideoStreams()[0].max_framerate); |
| 5461 | } |
| 5462 | |
Seth Hampson | 7c682e0 | 2018-05-04 16:28:15 -0700 | [diff] [blame] | 5463 | TEST_F(WebRtcVideoChannelTest, |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 5464 | CannotSetRtpSendParametersWithIncorrectNumberOfEncodings) { |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5465 | AddSendStream(); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 5466 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5467 | // Two or more encodings should result in failure. |
| 5468 | parameters.encodings.push_back(webrtc::RtpEncodingParameters()); |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5469 | EXPECT_FALSE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
deadbeef | fb2aced | 2017-01-06 23:05:37 -0800 | [diff] [blame] | 5470 | // Zero encodings should also fail. |
| 5471 | parameters.encodings.clear(); |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5472 | EXPECT_FALSE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
deadbeef | fb2aced | 2017-01-06 23:05:37 -0800 | [diff] [blame] | 5473 | } |
| 5474 | |
Zach Stein | 3ca452b | 2018-01-18 10:01:24 -0800 | [diff] [blame] | 5475 | TEST_F(WebRtcVideoChannelTest, |
| 5476 | CannotSetSimulcastRtpSendParametersWithIncorrectNumberOfEncodings) { |
| 5477 | std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); |
| 5478 | StreamParams sp = CreateSimStreamParams("cname", ssrcs); |
| 5479 | AddSendStream(sp); |
| 5480 | |
| 5481 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5482 | |
| 5483 | // Additional encodings should result in failure. |
| 5484 | parameters.encodings.push_back(webrtc::RtpEncodingParameters()); |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5485 | EXPECT_FALSE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
Zach Stein | 3ca452b | 2018-01-18 10:01:24 -0800 | [diff] [blame] | 5486 | // Zero encodings should also fail. |
| 5487 | parameters.encodings.clear(); |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5488 | EXPECT_FALSE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
Zach Stein | 3ca452b | 2018-01-18 10:01:24 -0800 | [diff] [blame] | 5489 | } |
| 5490 | |
deadbeef | fb2aced | 2017-01-06 23:05:37 -0800 | [diff] [blame] | 5491 | // Changing the SSRC through RtpParameters is not allowed. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 5492 | TEST_F(WebRtcVideoChannelTest, CannotSetSsrcInRtpSendParameters) { |
deadbeef | fb2aced | 2017-01-06 23:05:37 -0800 | [diff] [blame] | 5493 | AddSendStream(); |
| 5494 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 5495 | parameters.encodings[0].ssrc = 0xdeadbeef; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5496 | EXPECT_FALSE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
skvlad | dc1c62c | 2016-03-16 19:07:43 -0700 | [diff] [blame] | 5497 | } |
| 5498 | |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5499 | // Tests that when RTCRtpEncodingParameters.bitrate_priority gets set to |
| 5500 | // a value <= 0, setting the parameters returns false. |
| 5501 | TEST_F(WebRtcVideoChannelTest, SetRtpSendParametersInvalidBitratePriority) { |
| 5502 | AddSendStream(); |
| 5503 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5504 | EXPECT_EQ(1UL, parameters.encodings.size()); |
| 5505 | EXPECT_EQ(webrtc::kDefaultBitratePriority, |
| 5506 | parameters.encodings[0].bitrate_priority); |
| 5507 | |
| 5508 | parameters.encodings[0].bitrate_priority = 0; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5509 | EXPECT_FALSE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5510 | parameters.encodings[0].bitrate_priority = -2; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5511 | EXPECT_FALSE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5512 | } |
| 5513 | |
| 5514 | // Tests when the the RTCRtpEncodingParameters.bitrate_priority gets set |
| 5515 | // properly on the VideoChannel and propogates down to the video encoder. |
| 5516 | TEST_F(WebRtcVideoChannelTest, SetRtpSendParametersPriorityOneStream) { |
| 5517 | AddSendStream(); |
| 5518 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5519 | EXPECT_EQ(1UL, parameters.encodings.size()); |
| 5520 | EXPECT_EQ(webrtc::kDefaultBitratePriority, |
| 5521 | parameters.encodings[0].bitrate_priority); |
| 5522 | |
| 5523 | // Change the value and set it on the VideoChannel. |
| 5524 | double new_bitrate_priority = 2.0; |
| 5525 | parameters.encodings[0].bitrate_priority = new_bitrate_priority; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5526 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5527 | |
| 5528 | // Verify that the encoding parameters bitrate_priority is set for the |
| 5529 | // VideoChannel. |
| 5530 | parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5531 | EXPECT_EQ(1UL, parameters.encodings.size()); |
| 5532 | EXPECT_EQ(new_bitrate_priority, parameters.encodings[0].bitrate_priority); |
| 5533 | |
| 5534 | // Verify that the new value propagated down to the encoder. |
| 5535 | std::vector<FakeVideoSendStream*> video_send_streams = |
| 5536 | fake_call_->GetVideoSendStreams(); |
| 5537 | EXPECT_EQ(1UL, video_send_streams.size()); |
| 5538 | FakeVideoSendStream* video_send_stream = video_send_streams.front(); |
| 5539 | // Check that the WebRtcVideoSendStream updated the VideoEncoderConfig |
| 5540 | // appropriately. |
| 5541 | EXPECT_EQ(new_bitrate_priority, |
| 5542 | video_send_stream->GetEncoderConfig().bitrate_priority); |
| 5543 | // Check that the vector of VideoStreams also was propagated correctly. Note |
| 5544 | // that this is testing the behavior of the FakeVideoSendStream, which mimics |
| 5545 | // the calls to CreateEncoderStreams to get the VideoStreams. |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 5546 | EXPECT_EQ(absl::optional<double>(new_bitrate_priority), |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5547 | video_send_stream->GetVideoStreams()[0].bitrate_priority); |
| 5548 | } |
| 5549 | |
| 5550 | // Tests that the RTCRtpEncodingParameters.bitrate_priority is set for the |
| 5551 | // VideoChannel and the value propogates to the video encoder with all simulcast |
| 5552 | // streams. |
| 5553 | TEST_F(WebRtcVideoChannelTest, SetRtpSendParametersPrioritySimulcastStreams) { |
| 5554 | // Create the stream params with multiple ssrcs for simulcast. |
Åsa Persson | 31cb8f9 | 2018-06-27 10:44:56 +0200 | [diff] [blame] | 5555 | const size_t kNumSimulcastStreams = 3; |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5556 | std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); |
| 5557 | StreamParams stream_params = CreateSimStreamParams("cname", ssrcs); |
| 5558 | AddSendStream(stream_params); |
| 5559 | uint32_t primary_ssrc = stream_params.first_ssrc(); |
| 5560 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 5561 | // Using the FakeVideoCapturerWithTaskQueue, we manually send a full size |
| 5562 | // frame. This creates multiple VideoStreams for all simulcast layers when |
| 5563 | // reconfiguring, and allows us to test this behavior. |
| 5564 | FakeVideoCapturerWithTaskQueue capturer; |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5565 | VideoOptions options; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 5566 | EXPECT_TRUE(channel_->SetVideoSend(primary_ssrc, &options, &capturer)); |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5567 | EXPECT_EQ(cricket::CS_RUNNING, |
| 5568 | capturer.Start(cricket::VideoFormat( |
| 5569 | 1920, 1080, cricket::VideoFormat::FpsToInterval(30), |
| 5570 | cricket::FOURCC_I420))); |
| 5571 | channel_->SetSend(true); |
| 5572 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 5573 | // Get and set the rtp encoding parameters. |
| 5574 | webrtc::RtpParameters parameters = |
| 5575 | channel_->GetRtpSendParameters(primary_ssrc); |
Åsa Persson | 31cb8f9 | 2018-06-27 10:44:56 +0200 | [diff] [blame] | 5576 | EXPECT_EQ(kNumSimulcastStreams, parameters.encodings.size()); |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5577 | EXPECT_EQ(webrtc::kDefaultBitratePriority, |
| 5578 | parameters.encodings[0].bitrate_priority); |
| 5579 | // Change the value and set it on the VideoChannel. |
| 5580 | double new_bitrate_priority = 2.0; |
| 5581 | parameters.encodings[0].bitrate_priority = new_bitrate_priority; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 5582 | EXPECT_TRUE(channel_->SetRtpSendParameters(primary_ssrc, parameters).ok()); |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5583 | |
| 5584 | // Verify that the encoding parameters priority is set on the VideoChannel. |
| 5585 | parameters = channel_->GetRtpSendParameters(primary_ssrc); |
Åsa Persson | 31cb8f9 | 2018-06-27 10:44:56 +0200 | [diff] [blame] | 5586 | EXPECT_EQ(kNumSimulcastStreams, parameters.encodings.size()); |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5587 | EXPECT_EQ(new_bitrate_priority, parameters.encodings[0].bitrate_priority); |
| 5588 | |
| 5589 | // Verify that the new value propagated down to the encoder. |
| 5590 | std::vector<FakeVideoSendStream*> video_send_streams = |
| 5591 | fake_call_->GetVideoSendStreams(); |
| 5592 | EXPECT_EQ(1UL, video_send_streams.size()); |
| 5593 | FakeVideoSendStream* video_send_stream = video_send_streams.front(); |
| 5594 | // Check that the WebRtcVideoSendStream updated the VideoEncoderConfig |
| 5595 | // appropriately. |
Åsa Persson | 31cb8f9 | 2018-06-27 10:44:56 +0200 | [diff] [blame] | 5596 | EXPECT_EQ(kNumSimulcastStreams, |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5597 | video_send_stream->GetEncoderConfig().number_of_streams); |
| 5598 | EXPECT_EQ(new_bitrate_priority, |
| 5599 | video_send_stream->GetEncoderConfig().bitrate_priority); |
| 5600 | // Check that the vector of VideoStreams also propagated correctly. The |
| 5601 | // FakeVideoSendStream calls CreateEncoderStreams, and we are testing that |
| 5602 | // these are created appropriately for the simulcast case. |
Åsa Persson | 31cb8f9 | 2018-06-27 10:44:56 +0200 | [diff] [blame] | 5603 | EXPECT_EQ(kNumSimulcastStreams, video_send_stream->GetVideoStreams().size()); |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 5604 | EXPECT_EQ(absl::optional<double>(new_bitrate_priority), |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5605 | video_send_stream->GetVideoStreams()[0].bitrate_priority); |
| 5606 | // Since we are only setting bitrate priority per-sender, the other |
| 5607 | // VideoStreams should have a bitrate priority of 0. |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 5608 | EXPECT_EQ(absl::nullopt, |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5609 | video_send_stream->GetVideoStreams()[1].bitrate_priority); |
Danil Chapovalov | 00c7183 | 2018-06-15 15:58:38 +0200 | [diff] [blame] | 5610 | EXPECT_EQ(absl::nullopt, |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5611 | video_send_stream->GetVideoStreams()[2].bitrate_priority); |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 5612 | EXPECT_TRUE(channel_->SetVideoSend(primary_ssrc, nullptr, nullptr)); |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 5613 | } |
| 5614 | |
Åsa Persson | 8c1bf95 | 2018-09-13 10:42:19 +0200 | [diff] [blame] | 5615 | TEST_F(WebRtcVideoChannelTest, GetAndSetRtpSendParametersMaxFramerate) { |
| 5616 | const size_t kNumSimulcastStreams = 3; |
| 5617 | SetUpSimulcast(true, false); |
| 5618 | |
| 5619 | // Get and set the rtp encoding parameters. |
| 5620 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5621 | EXPECT_EQ(kNumSimulcastStreams, parameters.encodings.size()); |
| 5622 | for (const auto& encoding : parameters.encodings) { |
| 5623 | EXPECT_FALSE(encoding.max_framerate); |
| 5624 | } |
| 5625 | |
| 5626 | // Change the value and set it on the VideoChannel. |
| 5627 | parameters.encodings[0].max_framerate = 10; |
| 5628 | parameters.encodings[1].max_framerate = 20; |
| 5629 | parameters.encodings[2].max_framerate = 25; |
| 5630 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 5631 | |
| 5632 | // Verify that the bitrates are set on the VideoChannel. |
| 5633 | parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5634 | EXPECT_EQ(kNumSimulcastStreams, parameters.encodings.size()); |
| 5635 | EXPECT_EQ(10, parameters.encodings[0].max_framerate); |
| 5636 | EXPECT_EQ(20, parameters.encodings[1].max_framerate); |
| 5637 | EXPECT_EQ(25, parameters.encodings[2].max_framerate); |
| 5638 | } |
| 5639 | |
| 5640 | TEST_F(WebRtcVideoChannelTest, MaxSimulcastFrameratePropagatedToEncoder) { |
| 5641 | const size_t kNumSimulcastStreams = 3; |
| 5642 | FakeVideoSendStream* stream = SetUpSimulcast(true, false); |
| 5643 | |
| 5644 | // Send a full size frame so all simulcast layers are used when reconfiguring. |
| 5645 | FakeVideoCapturerWithTaskQueue capturer; |
| 5646 | VideoOptions options; |
| 5647 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
| 5648 | EXPECT_EQ(cricket::CS_RUNNING, |
| 5649 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 5650 | channel_->SetSend(true); |
| 5651 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 5652 | |
| 5653 | // Get and set the rtp encoding parameters. |
| 5654 | // Change the value and set it on the VideoChannel. |
| 5655 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5656 | EXPECT_EQ(kNumSimulcastStreams, parameters.encodings.size()); |
| 5657 | parameters.encodings[0].max_framerate = 15; |
| 5658 | parameters.encodings[1].max_framerate = 25; |
| 5659 | parameters.encodings[2].max_framerate = 20; |
| 5660 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 5661 | |
| 5662 | // Verify that the new value propagated down to the encoder. |
| 5663 | // Check that WebRtcVideoSendStream updates VideoEncoderConfig correctly. |
| 5664 | EXPECT_EQ(2, stream->num_encoder_reconfigurations()); |
| 5665 | webrtc::VideoEncoderConfig encoder_config = stream->GetEncoderConfig().Copy(); |
| 5666 | EXPECT_EQ(kNumSimulcastStreams, encoder_config.number_of_streams); |
| 5667 | EXPECT_EQ(kNumSimulcastStreams, encoder_config.simulcast_layers.size()); |
| 5668 | EXPECT_EQ(15, encoder_config.simulcast_layers[0].max_framerate); |
| 5669 | EXPECT_EQ(25, encoder_config.simulcast_layers[1].max_framerate); |
| 5670 | EXPECT_EQ(20, encoder_config.simulcast_layers[2].max_framerate); |
| 5671 | |
| 5672 | // FakeVideoSendStream calls CreateEncoderStreams, test that the vector of |
| 5673 | // VideoStreams are created appropriately for the simulcast case. |
| 5674 | // Currently the maximum |max_framerate| is used. |
| 5675 | EXPECT_EQ(kNumSimulcastStreams, stream->GetVideoStreams().size()); |
| 5676 | EXPECT_EQ(25, stream->GetVideoStreams()[0].max_framerate); |
| 5677 | EXPECT_EQ(25, stream->GetVideoStreams()[1].max_framerate); |
| 5678 | EXPECT_EQ(25, stream->GetVideoStreams()[2].max_framerate); |
| 5679 | |
| 5680 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
| 5681 | } |
| 5682 | |
| 5683 | TEST_F(WebRtcVideoChannelTest, |
| 5684 | DefaultValuePropagatedToEncoderForUnsetFramerate) { |
| 5685 | const size_t kNumSimulcastStreams = 3; |
| 5686 | const std::vector<webrtc::VideoStream> kDefault = GetSimulcastBitrates720p(); |
| 5687 | FakeVideoSendStream* stream = SetUpSimulcast(true, false); |
| 5688 | |
| 5689 | // Send a full size frame so all simulcast layers are used when reconfiguring. |
| 5690 | FakeVideoCapturerWithTaskQueue capturer; |
| 5691 | VideoOptions options; |
| 5692 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
| 5693 | EXPECT_EQ(cricket::CS_RUNNING, |
| 5694 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 5695 | channel_->SetSend(true); |
| 5696 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 5697 | |
| 5698 | // Get and set the rtp encoding parameters. |
| 5699 | // Change the value and set it on the VideoChannel. |
| 5700 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5701 | EXPECT_EQ(kNumSimulcastStreams, parameters.encodings.size()); |
| 5702 | parameters.encodings[0].max_framerate = 15; |
| 5703 | parameters.encodings[2].max_framerate = 20; |
| 5704 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 5705 | |
| 5706 | // Verify that the new value propagated down to the encoder. |
| 5707 | // Check that WebRtcVideoSendStream updates VideoEncoderConfig correctly. |
| 5708 | webrtc::VideoEncoderConfig encoder_config = stream->GetEncoderConfig().Copy(); |
| 5709 | EXPECT_EQ(kNumSimulcastStreams, encoder_config.number_of_streams); |
| 5710 | EXPECT_EQ(kNumSimulcastStreams, encoder_config.simulcast_layers.size()); |
| 5711 | EXPECT_EQ(15, encoder_config.simulcast_layers[0].max_framerate); |
| 5712 | EXPECT_EQ(-1, encoder_config.simulcast_layers[1].max_framerate); |
| 5713 | EXPECT_EQ(20, encoder_config.simulcast_layers[2].max_framerate); |
| 5714 | |
| 5715 | // FakeVideoSendStream calls CreateEncoderStreams, test that the vector of |
| 5716 | // VideoStreams are created appropriately for the simulcast case. |
| 5717 | // The maximum |max_framerate| is used, kDefaultVideoMaxFramerate: 60. |
| 5718 | EXPECT_EQ(kNumSimulcastStreams, stream->GetVideoStreams().size()); |
| 5719 | EXPECT_EQ(kDefaultVideoMaxFramerate, |
| 5720 | stream->GetVideoStreams()[0].max_framerate); |
| 5721 | EXPECT_EQ(kDefaultVideoMaxFramerate, |
| 5722 | stream->GetVideoStreams()[1].max_framerate); |
| 5723 | EXPECT_EQ(kDefaultVideoMaxFramerate, |
| 5724 | stream->GetVideoStreams()[2].max_framerate); |
| 5725 | |
| 5726 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
| 5727 | } |
| 5728 | |
Åsa Persson | 5565981 | 2018-06-18 17:51:32 +0200 | [diff] [blame] | 5729 | TEST_F(WebRtcVideoChannelTest, GetAndSetRtpSendParametersMinAndMaxBitrate) { |
| 5730 | const size_t kNumSimulcastStreams = 3; |
| 5731 | SetUpSimulcast(true, false); |
| 5732 | |
| 5733 | // Get and set the rtp encoding parameters. |
| 5734 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5735 | EXPECT_EQ(kNumSimulcastStreams, parameters.encodings.size()); |
| 5736 | for (const auto& encoding : parameters.encodings) { |
| 5737 | EXPECT_FALSE(encoding.min_bitrate_bps); |
| 5738 | EXPECT_FALSE(encoding.max_bitrate_bps); |
| 5739 | } |
| 5740 | |
| 5741 | // Change the value and set it on the VideoChannel. |
| 5742 | parameters.encodings[0].min_bitrate_bps = 100000; |
| 5743 | parameters.encodings[0].max_bitrate_bps = 200000; |
| 5744 | parameters.encodings[1].min_bitrate_bps = 300000; |
| 5745 | parameters.encodings[1].max_bitrate_bps = 400000; |
| 5746 | parameters.encodings[2].min_bitrate_bps = 500000; |
| 5747 | parameters.encodings[2].max_bitrate_bps = 600000; |
| 5748 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 5749 | |
| 5750 | // Verify that the bitrates are set on the VideoChannel. |
| 5751 | parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5752 | EXPECT_EQ(kNumSimulcastStreams, parameters.encodings.size()); |
| 5753 | EXPECT_EQ(100000, parameters.encodings[0].min_bitrate_bps); |
| 5754 | EXPECT_EQ(200000, parameters.encodings[0].max_bitrate_bps); |
| 5755 | EXPECT_EQ(300000, parameters.encodings[1].min_bitrate_bps); |
| 5756 | EXPECT_EQ(400000, parameters.encodings[1].max_bitrate_bps); |
| 5757 | EXPECT_EQ(500000, parameters.encodings[2].min_bitrate_bps); |
| 5758 | EXPECT_EQ(600000, parameters.encodings[2].max_bitrate_bps); |
| 5759 | } |
| 5760 | |
| 5761 | TEST_F(WebRtcVideoChannelTest, SetRtpSendParametersFailsWithIncorrectBitrate) { |
| 5762 | const size_t kNumSimulcastStreams = 3; |
| 5763 | SetUpSimulcast(true, false); |
| 5764 | |
| 5765 | // Get and set the rtp encoding parameters. |
| 5766 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5767 | EXPECT_EQ(kNumSimulcastStreams, parameters.encodings.size()); |
| 5768 | |
| 5769 | // Max bitrate lower than min bitrate should fail. |
| 5770 | parameters.encodings[2].min_bitrate_bps = 100000; |
| 5771 | parameters.encodings[2].max_bitrate_bps = 100000 - 1; |
| 5772 | EXPECT_EQ(webrtc::RTCErrorType::INVALID_RANGE, |
| 5773 | channel_->SetRtpSendParameters(last_ssrc_, parameters).type()); |
| 5774 | } |
| 5775 | |
| 5776 | // Test that min and max bitrate values set via RtpParameters are correctly |
| 5777 | // propagated to the underlying encoder, and that the target is set to 3/4 of |
| 5778 | // the maximum (3/4 was chosen because it's similar to the simulcast defaults |
| 5779 | // that are used if no min/max are specified). |
| 5780 | TEST_F(WebRtcVideoChannelTest, MinAndMaxSimulcastBitratePropagatedToEncoder) { |
| 5781 | const size_t kNumSimulcastStreams = 3; |
| 5782 | FakeVideoSendStream* stream = SetUpSimulcast(true, false); |
| 5783 | |
| 5784 | // Send a full size frame so all simulcast layers are used when reconfiguring. |
| 5785 | FakeVideoCapturerWithTaskQueue capturer; |
| 5786 | VideoOptions options; |
| 5787 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
| 5788 | EXPECT_EQ(cricket::CS_RUNNING, |
| 5789 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 5790 | channel_->SetSend(true); |
| 5791 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 5792 | |
| 5793 | // Get and set the rtp encoding parameters. |
| 5794 | // Change the value and set it on the VideoChannel. |
| 5795 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5796 | EXPECT_EQ(kNumSimulcastStreams, parameters.encodings.size()); |
| 5797 | parameters.encodings[0].min_bitrate_bps = 100000; |
| 5798 | parameters.encodings[0].max_bitrate_bps = 200000; |
| 5799 | parameters.encodings[1].min_bitrate_bps = 300000; |
| 5800 | parameters.encodings[1].max_bitrate_bps = 400000; |
| 5801 | parameters.encodings[2].min_bitrate_bps = 500000; |
| 5802 | parameters.encodings[2].max_bitrate_bps = 600000; |
| 5803 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 5804 | |
| 5805 | // Verify that the new value propagated down to the encoder. |
| 5806 | // Check that WebRtcVideoSendStream updates VideoEncoderConfig correctly. |
| 5807 | EXPECT_EQ(2, stream->num_encoder_reconfigurations()); |
| 5808 | webrtc::VideoEncoderConfig encoder_config = stream->GetEncoderConfig().Copy(); |
| 5809 | EXPECT_EQ(kNumSimulcastStreams, encoder_config.number_of_streams); |
| 5810 | EXPECT_EQ(kNumSimulcastStreams, encoder_config.simulcast_layers.size()); |
| 5811 | EXPECT_EQ(100000, encoder_config.simulcast_layers[0].min_bitrate_bps); |
| 5812 | EXPECT_EQ(200000, encoder_config.simulcast_layers[0].max_bitrate_bps); |
| 5813 | EXPECT_EQ(300000, encoder_config.simulcast_layers[1].min_bitrate_bps); |
| 5814 | EXPECT_EQ(400000, encoder_config.simulcast_layers[1].max_bitrate_bps); |
| 5815 | EXPECT_EQ(500000, encoder_config.simulcast_layers[2].min_bitrate_bps); |
| 5816 | EXPECT_EQ(600000, encoder_config.simulcast_layers[2].max_bitrate_bps); |
| 5817 | |
| 5818 | // FakeVideoSendStream calls CreateEncoderStreams, test that the vector of |
| 5819 | // VideoStreams are created appropriately for the simulcast case. |
| 5820 | EXPECT_EQ(kNumSimulcastStreams, stream->GetVideoStreams().size()); |
| 5821 | // Target bitrate: 200000 * 3 / 4 = 150000. |
| 5822 | EXPECT_EQ(100000, stream->GetVideoStreams()[0].min_bitrate_bps); |
| 5823 | EXPECT_EQ(150000, stream->GetVideoStreams()[0].target_bitrate_bps); |
| 5824 | EXPECT_EQ(200000, stream->GetVideoStreams()[0].max_bitrate_bps); |
| 5825 | // Target bitrate: 400000 * 3 / 4 = 300000. |
| 5826 | EXPECT_EQ(300000, stream->GetVideoStreams()[1].min_bitrate_bps); |
| 5827 | EXPECT_EQ(300000, stream->GetVideoStreams()[1].target_bitrate_bps); |
| 5828 | EXPECT_EQ(400000, stream->GetVideoStreams()[1].max_bitrate_bps); |
| 5829 | // Target bitrate: 600000 * 3 / 4 = 450000, less than min -> max. |
| 5830 | EXPECT_EQ(500000, stream->GetVideoStreams()[2].min_bitrate_bps); |
| 5831 | EXPECT_EQ(600000, stream->GetVideoStreams()[2].target_bitrate_bps); |
| 5832 | EXPECT_EQ(600000, stream->GetVideoStreams()[2].max_bitrate_bps); |
| 5833 | |
| 5834 | // No parameter changed, encoder should not be reconfigured. |
| 5835 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 5836 | EXPECT_EQ(2, stream->num_encoder_reconfigurations()); |
| 5837 | |
| 5838 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
| 5839 | } |
| 5840 | |
| 5841 | // Test to only specify the min or max bitrate value for a layer via |
| 5842 | // RtpParameters. The unspecified min/max and target value should be set to the |
| 5843 | // simulcast default that is used if no min/max are specified. |
| 5844 | TEST_F(WebRtcVideoChannelTest, MinOrMaxSimulcastBitratePropagatedToEncoder) { |
| 5845 | const size_t kNumSimulcastStreams = 3; |
| 5846 | const std::vector<webrtc::VideoStream> kDefault = GetSimulcastBitrates720p(); |
| 5847 | FakeVideoSendStream* stream = SetUpSimulcast(true, false); |
| 5848 | |
| 5849 | // Send a full size frame so all simulcast layers are used when reconfiguring. |
| 5850 | FakeVideoCapturerWithTaskQueue capturer; |
| 5851 | VideoOptions options; |
| 5852 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
| 5853 | EXPECT_EQ(cricket::CS_RUNNING, |
| 5854 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 5855 | channel_->SetSend(true); |
| 5856 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 5857 | |
| 5858 | // Get and set the rtp encoding parameters. |
| 5859 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5860 | EXPECT_EQ(kNumSimulcastStreams, parameters.encodings.size()); |
| 5861 | |
| 5862 | // Change the value and set it on the VideoChannel. |
| 5863 | // Layer 0: only configure min bitrate. |
| 5864 | const int kMinBpsLayer0 = kDefault[0].min_bitrate_bps + 1; |
| 5865 | parameters.encodings[0].min_bitrate_bps = kMinBpsLayer0; |
| 5866 | // Layer 1: only configure max bitrate. |
| 5867 | const int kMaxBpsLayer1 = kDefault[1].max_bitrate_bps - 1; |
| 5868 | parameters.encodings[1].max_bitrate_bps = kMaxBpsLayer1; |
| 5869 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 5870 | |
| 5871 | // Verify that the new value propagated down to the encoder. |
| 5872 | // Check that WebRtcVideoSendStream updates VideoEncoderConfig correctly. |
| 5873 | webrtc::VideoEncoderConfig encoder_config = stream->GetEncoderConfig().Copy(); |
| 5874 | EXPECT_EQ(kNumSimulcastStreams, encoder_config.number_of_streams); |
| 5875 | EXPECT_EQ(kNumSimulcastStreams, encoder_config.simulcast_layers.size()); |
| 5876 | EXPECT_EQ(kMinBpsLayer0, encoder_config.simulcast_layers[0].min_bitrate_bps); |
| 5877 | EXPECT_EQ(-1, encoder_config.simulcast_layers[0].max_bitrate_bps); |
| 5878 | EXPECT_EQ(-1, encoder_config.simulcast_layers[1].min_bitrate_bps); |
| 5879 | EXPECT_EQ(kMaxBpsLayer1, encoder_config.simulcast_layers[1].max_bitrate_bps); |
| 5880 | EXPECT_EQ(-1, encoder_config.simulcast_layers[2].min_bitrate_bps); |
| 5881 | EXPECT_EQ(-1, encoder_config.simulcast_layers[2].max_bitrate_bps); |
| 5882 | |
| 5883 | // FakeVideoSendStream calls CreateEncoderStreams, test that the vector of |
| 5884 | // VideoStreams are created appropriately for the simulcast case. |
| 5885 | EXPECT_EQ(kNumSimulcastStreams, stream->GetVideoStreams().size()); |
| 5886 | // Layer 0: min configured bitrate should overwrite min default. |
| 5887 | EXPECT_EQ(kMinBpsLayer0, stream->GetVideoStreams()[0].min_bitrate_bps); |
| 5888 | EXPECT_EQ(kDefault[0].target_bitrate_bps, |
| 5889 | stream->GetVideoStreams()[0].target_bitrate_bps); |
| 5890 | EXPECT_EQ(kDefault[0].max_bitrate_bps, |
| 5891 | stream->GetVideoStreams()[0].max_bitrate_bps); |
| 5892 | // Layer 1: max configured bitrate should overwrite max default. |
| 5893 | EXPECT_EQ(kDefault[1].min_bitrate_bps, |
| 5894 | stream->GetVideoStreams()[1].min_bitrate_bps); |
| 5895 | EXPECT_EQ(kDefault[1].target_bitrate_bps, |
| 5896 | stream->GetVideoStreams()[1].target_bitrate_bps); |
| 5897 | EXPECT_EQ(kMaxBpsLayer1, stream->GetVideoStreams()[1].max_bitrate_bps); |
| 5898 | // Layer 2: min and max bitrate not configured, default expected. |
| 5899 | EXPECT_EQ(kDefault[2].min_bitrate_bps, |
| 5900 | stream->GetVideoStreams()[2].min_bitrate_bps); |
| 5901 | EXPECT_EQ(kDefault[2].target_bitrate_bps, |
| 5902 | stream->GetVideoStreams()[2].target_bitrate_bps); |
| 5903 | EXPECT_EQ(kDefault[2].max_bitrate_bps, |
| 5904 | stream->GetVideoStreams()[2].max_bitrate_bps); |
| 5905 | |
| 5906 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
| 5907 | } |
| 5908 | |
| 5909 | // Test that specifying the min (or max) bitrate value for a layer via |
| 5910 | // RtpParameters above (or below) the simulcast default max (or min) adjusts the |
| 5911 | // unspecified values accordingly. |
| 5912 | TEST_F(WebRtcVideoChannelTest, SetMinAndMaxSimulcastBitrateAboveBelowDefault) { |
| 5913 | const size_t kNumSimulcastStreams = 3; |
| 5914 | const std::vector<webrtc::VideoStream> kDefault = GetSimulcastBitrates720p(); |
| 5915 | FakeVideoSendStream* stream = SetUpSimulcast(true, false); |
| 5916 | |
| 5917 | // Send a full size frame so all simulcast layers are used when reconfiguring. |
| 5918 | FakeVideoCapturerWithTaskQueue capturer; |
| 5919 | VideoOptions options; |
| 5920 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
| 5921 | EXPECT_EQ(cricket::CS_RUNNING, |
| 5922 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 5923 | channel_->SetSend(true); |
| 5924 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 5925 | |
| 5926 | // Get and set the rtp encoding parameters. |
| 5927 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5928 | EXPECT_EQ(kNumSimulcastStreams, parameters.encodings.size()); |
| 5929 | |
| 5930 | // Change the value and set it on the VideoChannel. |
| 5931 | // For layer 0, set the min bitrate above the default max. |
| 5932 | const int kMinBpsLayer0 = kDefault[0].max_bitrate_bps + 1; |
| 5933 | parameters.encodings[0].min_bitrate_bps = kMinBpsLayer0; |
| 5934 | // For layer 1, set the max bitrate below the default min. |
| 5935 | const int kMaxBpsLayer1 = kDefault[1].min_bitrate_bps - 1; |
| 5936 | parameters.encodings[1].max_bitrate_bps = kMaxBpsLayer1; |
| 5937 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 5938 | |
| 5939 | // Verify that the new value propagated down to the encoder. |
| 5940 | // FakeVideoSendStream calls CreateEncoderStreams, test that the vector of |
| 5941 | // VideoStreams are created appropriately for the simulcast case. |
| 5942 | EXPECT_EQ(kNumSimulcastStreams, stream->GetVideoStreams().size()); |
| 5943 | // Layer 0: Min bitrate above default max (target/max should be adjusted). |
| 5944 | EXPECT_EQ(kMinBpsLayer0, stream->GetVideoStreams()[0].min_bitrate_bps); |
| 5945 | EXPECT_EQ(kMinBpsLayer0, stream->GetVideoStreams()[0].target_bitrate_bps); |
| 5946 | EXPECT_EQ(kMinBpsLayer0, stream->GetVideoStreams()[0].max_bitrate_bps); |
| 5947 | // Layer 1: Max bitrate below default min (min/target should be adjusted). |
| 5948 | EXPECT_EQ(kMaxBpsLayer1, stream->GetVideoStreams()[1].min_bitrate_bps); |
| 5949 | EXPECT_EQ(kMaxBpsLayer1, stream->GetVideoStreams()[1].target_bitrate_bps); |
| 5950 | EXPECT_EQ(kMaxBpsLayer1, stream->GetVideoStreams()[1].max_bitrate_bps); |
| 5951 | // Layer 2: min and max bitrate not configured, default expected. |
| 5952 | EXPECT_EQ(kDefault[2].min_bitrate_bps, |
| 5953 | stream->GetVideoStreams()[2].min_bitrate_bps); |
| 5954 | EXPECT_EQ(kDefault[2].target_bitrate_bps, |
| 5955 | stream->GetVideoStreams()[2].target_bitrate_bps); |
| 5956 | EXPECT_EQ(kDefault[2].max_bitrate_bps, |
| 5957 | stream->GetVideoStreams()[2].max_bitrate_bps); |
| 5958 | |
| 5959 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
| 5960 | } |
| 5961 | |
| 5962 | TEST_F(WebRtcVideoChannelTest, BandwidthAboveTotalMaxBitrateGivenToMaxLayer) { |
| 5963 | const size_t kNumSimulcastStreams = 3; |
| 5964 | const std::vector<webrtc::VideoStream> kDefault = GetSimulcastBitrates720p(); |
| 5965 | FakeVideoSendStream* stream = SetUpSimulcast(true, false); |
| 5966 | |
| 5967 | // Send a full size frame so all simulcast layers are used when reconfiguring. |
| 5968 | FakeVideoCapturerWithTaskQueue capturer; |
| 5969 | VideoOptions options; |
| 5970 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
| 5971 | EXPECT_EQ(cricket::CS_RUNNING, |
| 5972 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 5973 | channel_->SetSend(true); |
| 5974 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 5975 | |
| 5976 | // Set max bitrate for all but the highest layer. |
| 5977 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 5978 | EXPECT_EQ(kNumSimulcastStreams, parameters.encodings.size()); |
| 5979 | parameters.encodings[0].max_bitrate_bps = kDefault[0].max_bitrate_bps; |
| 5980 | parameters.encodings[1].max_bitrate_bps = kDefault[1].max_bitrate_bps; |
| 5981 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 5982 | |
| 5983 | // Set max bandwidth equal to total max bitrate. |
| 5984 | send_parameters_.max_bandwidth_bps = |
| 5985 | GetTotalMaxBitrateBps(stream->GetVideoStreams()); |
| 5986 | ExpectSetMaxBitrate(send_parameters_.max_bandwidth_bps); |
| 5987 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| 5988 | |
| 5989 | // No bitrate above the total max to give to the highest layer. |
| 5990 | EXPECT_EQ(kNumSimulcastStreams, stream->GetVideoStreams().size()); |
| 5991 | EXPECT_EQ(kDefault[2].max_bitrate_bps, |
| 5992 | stream->GetVideoStreams()[2].max_bitrate_bps); |
| 5993 | |
| 5994 | // Set max bandwidth above the total max bitrate. |
| 5995 | send_parameters_.max_bandwidth_bps = |
| 5996 | GetTotalMaxBitrateBps(stream->GetVideoStreams()) + 1; |
| 5997 | ExpectSetMaxBitrate(send_parameters_.max_bandwidth_bps); |
| 5998 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| 5999 | |
| 6000 | // The highest layer has no max bitrate set -> the bitrate above the total |
| 6001 | // max should be given to the highest layer. |
| 6002 | EXPECT_EQ(kNumSimulcastStreams, stream->GetVideoStreams().size()); |
| 6003 | EXPECT_EQ(send_parameters_.max_bandwidth_bps, |
| 6004 | GetTotalMaxBitrateBps(stream->GetVideoStreams())); |
| 6005 | EXPECT_EQ(kDefault[2].max_bitrate_bps + 1, |
| 6006 | stream->GetVideoStreams()[2].max_bitrate_bps); |
| 6007 | |
| 6008 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
| 6009 | } |
| 6010 | |
| 6011 | TEST_F(WebRtcVideoChannelTest, |
| 6012 | BandwidthAboveTotalMaxBitrateNotGivenToMaxLayerIfMaxBitrateSet) { |
| 6013 | const size_t kNumSimulcastStreams = 3; |
| 6014 | const std::vector<webrtc::VideoStream> kDefault = GetSimulcastBitrates720p(); |
| 6015 | EXPECT_EQ(kNumSimulcastStreams, kDefault.size()); |
| 6016 | FakeVideoSendStream* stream = SetUpSimulcast(true, false); |
| 6017 | |
| 6018 | // Send a full size frame so all simulcast layers are used when reconfiguring. |
| 6019 | FakeVideoCapturerWithTaskQueue capturer; |
| 6020 | VideoOptions options; |
| 6021 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, &options, &capturer)); |
| 6022 | EXPECT_EQ(cricket::CS_RUNNING, |
| 6023 | capturer.Start(capturer.GetSupportedFormats()->front())); |
| 6024 | channel_->SetSend(true); |
| 6025 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 6026 | |
| 6027 | // Set max bitrate for the highest layer. |
| 6028 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 6029 | EXPECT_EQ(kNumSimulcastStreams, parameters.encodings.size()); |
| 6030 | parameters.encodings[2].max_bitrate_bps = kDefault[2].max_bitrate_bps; |
| 6031 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 6032 | |
| 6033 | // Set max bandwidth above the total max bitrate. |
| 6034 | send_parameters_.max_bandwidth_bps = |
| 6035 | GetTotalMaxBitrateBps(stream->GetVideoStreams()) + 1; |
| 6036 | ExpectSetMaxBitrate(send_parameters_.max_bandwidth_bps); |
| 6037 | ASSERT_TRUE(channel_->SetSendParameters(send_parameters_)); |
| 6038 | |
| 6039 | // The highest layer has the max bitrate set -> the bitrate above the total |
| 6040 | // max should not be given to the highest layer. |
| 6041 | EXPECT_EQ(kNumSimulcastStreams, stream->GetVideoStreams().size()); |
| 6042 | EXPECT_EQ(*parameters.encodings[2].max_bitrate_bps, |
| 6043 | stream->GetVideoStreams()[2].max_bitrate_bps); |
| 6044 | |
| 6045 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
| 6046 | } |
| 6047 | |
Åsa Persson | bdee46d | 2018-06-25 11:28:06 +0200 | [diff] [blame] | 6048 | // Test that min and max bitrate values set via RtpParameters are correctly |
| 6049 | // propagated to the underlying encoder for a single stream. |
| 6050 | TEST_F(WebRtcVideoChannelTest, MinAndMaxBitratePropagatedToEncoder) { |
| 6051 | FakeVideoSendStream* stream = AddSendStream(); |
| 6052 | EXPECT_TRUE(channel_->SetSend(true)); |
| 6053 | EXPECT_TRUE(stream->IsSending()); |
| 6054 | |
| 6055 | // Set min and max bitrate. |
| 6056 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 6057 | EXPECT_EQ(1u, parameters.encodings.size()); |
| 6058 | parameters.encodings[0].min_bitrate_bps = 80000; |
| 6059 | parameters.encodings[0].max_bitrate_bps = 150000; |
| 6060 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
| 6061 | |
| 6062 | // Check that WebRtcVideoSendStream updates VideoEncoderConfig correctly. |
| 6063 | webrtc::VideoEncoderConfig encoder_config = stream->GetEncoderConfig().Copy(); |
| 6064 | EXPECT_EQ(1u, encoder_config.number_of_streams); |
| 6065 | EXPECT_EQ(1u, encoder_config.simulcast_layers.size()); |
| 6066 | EXPECT_EQ(80000, encoder_config.simulcast_layers[0].min_bitrate_bps); |
| 6067 | EXPECT_EQ(150000, encoder_config.simulcast_layers[0].max_bitrate_bps); |
| 6068 | |
| 6069 | // FakeVideoSendStream calls CreateEncoderStreams, test that the vector of |
| 6070 | // VideoStreams are created appropriately. |
| 6071 | EXPECT_EQ(1u, stream->GetVideoStreams().size()); |
| 6072 | EXPECT_EQ(80000, stream->GetVideoStreams()[0].min_bitrate_bps); |
| 6073 | EXPECT_EQ(150000, stream->GetVideoStreams()[0].target_bitrate_bps); |
| 6074 | EXPECT_EQ(150000, stream->GetVideoStreams()[0].max_bitrate_bps); |
| 6075 | } |
| 6076 | |
| 6077 | // Test the default min and max bitrate value are correctly propagated to the |
| 6078 | // underlying encoder for a single stream (when the values are not set via |
| 6079 | // RtpParameters). |
| 6080 | TEST_F(WebRtcVideoChannelTest, DefaultMinAndMaxBitratePropagatedToEncoder) { |
| 6081 | FakeVideoSendStream* stream = AddSendStream(); |
| 6082 | EXPECT_TRUE(channel_->SetSend(true)); |
| 6083 | EXPECT_TRUE(stream->IsSending()); |
| 6084 | |
| 6085 | // Check that WebRtcVideoSendStream updates VideoEncoderConfig correctly. |
| 6086 | webrtc::VideoEncoderConfig encoder_config = stream->GetEncoderConfig().Copy(); |
| 6087 | EXPECT_EQ(1u, encoder_config.number_of_streams); |
| 6088 | EXPECT_EQ(1u, encoder_config.simulcast_layers.size()); |
| 6089 | EXPECT_EQ(-1, encoder_config.simulcast_layers[0].min_bitrate_bps); |
| 6090 | EXPECT_EQ(-1, encoder_config.simulcast_layers[0].max_bitrate_bps); |
| 6091 | |
| 6092 | // FakeVideoSendStream calls CreateEncoderStreams, test that the vector of |
| 6093 | // VideoStreams are created appropriately. |
| 6094 | EXPECT_EQ(1u, stream->GetVideoStreams().size()); |
| 6095 | EXPECT_EQ(cricket::kMinVideoBitrateBps, |
| 6096 | stream->GetVideoStreams()[0].min_bitrate_bps); |
| 6097 | EXPECT_GT(stream->GetVideoStreams()[0].max_bitrate_bps, |
| 6098 | stream->GetVideoStreams()[0].min_bitrate_bps); |
| 6099 | EXPECT_EQ(stream->GetVideoStreams()[0].max_bitrate_bps, |
| 6100 | stream->GetVideoStreams()[0].target_bitrate_bps); |
| 6101 | } |
| 6102 | |
Taylor Brandstetter | 14b9d79 | 2016-09-07 17:16:54 -0700 | [diff] [blame] | 6103 | // Test that a stream will not be sending if its encoding is made inactive |
| 6104 | // through SetRtpSendParameters. |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 6105 | TEST_F(WebRtcVideoChannelTest, SetRtpSendParametersOneEncodingActive) { |
deadbeef | dbe2b87 | 2016-03-22 15:42:00 -0700 | [diff] [blame] | 6106 | FakeVideoSendStream* stream = AddSendStream(); |
| 6107 | EXPECT_TRUE(channel_->SetSend(true)); |
| 6108 | EXPECT_TRUE(stream->IsSending()); |
| 6109 | |
| 6110 | // Get current parameters and change "active" to false. |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 6111 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
deadbeef | dbe2b87 | 2016-03-22 15:42:00 -0700 | [diff] [blame] | 6112 | ASSERT_EQ(1u, parameters.encodings.size()); |
| 6113 | ASSERT_TRUE(parameters.encodings[0].active); |
| 6114 | parameters.encodings[0].active = false; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 6115 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
deadbeef | dbe2b87 | 2016-03-22 15:42:00 -0700 | [diff] [blame] | 6116 | EXPECT_FALSE(stream->IsSending()); |
| 6117 | |
| 6118 | // Now change it back to active and verify we resume sending. |
| 6119 | parameters.encodings[0].active = true; |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 6120 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
deadbeef | dbe2b87 | 2016-03-22 15:42:00 -0700 | [diff] [blame] | 6121 | EXPECT_TRUE(stream->IsSending()); |
| 6122 | } |
| 6123 | |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 6124 | // Tests that when active is updated for any simulcast layer then the send |
| 6125 | // stream's sending state will be updated and it will be reconfigured with the |
| 6126 | // new appropriate active simulcast streams. |
| 6127 | TEST_F(WebRtcVideoChannelTest, SetRtpSendParametersMultipleEncodingsActive) { |
| 6128 | // Create the stream params with multiple ssrcs for simulcast. |
Åsa Persson | 31cb8f9 | 2018-06-27 10:44:56 +0200 | [diff] [blame] | 6129 | const size_t kNumSimulcastStreams = 3; |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 6130 | std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); |
| 6131 | StreamParams stream_params = CreateSimStreamParams("cname", ssrcs); |
| 6132 | FakeVideoSendStream* fake_video_send_stream = AddSendStream(stream_params); |
| 6133 | uint32_t primary_ssrc = stream_params.first_ssrc(); |
| 6134 | |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 6135 | // Using the FakeVideoCapturerWithTaskQueue, we manually send a full size |
| 6136 | // frame. This allows us to test that ReconfigureEncoder is called |
| 6137 | // appropriately. |
| 6138 | cricket::FakeVideoCapturerWithTaskQueue capturer; |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 6139 | VideoOptions options; |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 6140 | EXPECT_TRUE(channel_->SetVideoSend(primary_ssrc, &options, &capturer)); |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 6141 | EXPECT_EQ(cricket::CS_RUNNING, |
| 6142 | capturer.Start(cricket::VideoFormat( |
| 6143 | 1920, 1080, cricket::VideoFormat::FpsToInterval(30), |
| 6144 | cricket::FOURCC_I420))); |
| 6145 | channel_->SetSend(true); |
| 6146 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 6147 | |
| 6148 | // Check that all encodings are initially active. |
| 6149 | webrtc::RtpParameters parameters = |
| 6150 | channel_->GetRtpSendParameters(primary_ssrc); |
Åsa Persson | 31cb8f9 | 2018-06-27 10:44:56 +0200 | [diff] [blame] | 6151 | EXPECT_EQ(kNumSimulcastStreams, parameters.encodings.size()); |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 6152 | EXPECT_TRUE(parameters.encodings[0].active); |
| 6153 | EXPECT_TRUE(parameters.encodings[1].active); |
| 6154 | EXPECT_TRUE(parameters.encodings[2].active); |
| 6155 | EXPECT_TRUE(fake_video_send_stream->IsSending()); |
| 6156 | |
| 6157 | // Only turn on only the middle stream. |
| 6158 | parameters.encodings[0].active = false; |
| 6159 | parameters.encodings[1].active = true; |
| 6160 | parameters.encodings[2].active = false; |
| 6161 | EXPECT_TRUE(channel_->SetRtpSendParameters(primary_ssrc, parameters).ok()); |
| 6162 | // Verify that the active fields are set on the VideoChannel. |
| 6163 | parameters = channel_->GetRtpSendParameters(primary_ssrc); |
Åsa Persson | 31cb8f9 | 2018-06-27 10:44:56 +0200 | [diff] [blame] | 6164 | EXPECT_EQ(kNumSimulcastStreams, parameters.encodings.size()); |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 6165 | EXPECT_FALSE(parameters.encodings[0].active); |
| 6166 | EXPECT_TRUE(parameters.encodings[1].active); |
| 6167 | EXPECT_FALSE(parameters.encodings[2].active); |
| 6168 | // Check that the VideoSendStream is updated appropriately. This means its |
| 6169 | // send state was updated and it was reconfigured. |
| 6170 | EXPECT_TRUE(fake_video_send_stream->IsSending()); |
| 6171 | std::vector<webrtc::VideoStream> simulcast_streams = |
| 6172 | fake_video_send_stream->GetVideoStreams(); |
Åsa Persson | 31cb8f9 | 2018-06-27 10:44:56 +0200 | [diff] [blame] | 6173 | EXPECT_EQ(kNumSimulcastStreams, simulcast_streams.size()); |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 6174 | EXPECT_FALSE(simulcast_streams[0].active); |
| 6175 | EXPECT_TRUE(simulcast_streams[1].active); |
| 6176 | EXPECT_FALSE(simulcast_streams[2].active); |
| 6177 | |
| 6178 | // Turn off all streams. |
| 6179 | parameters.encodings[0].active = false; |
| 6180 | parameters.encodings[1].active = false; |
| 6181 | parameters.encodings[2].active = false; |
| 6182 | EXPECT_TRUE(channel_->SetRtpSendParameters(primary_ssrc, parameters).ok()); |
| 6183 | // Verify that the active fields are set on the VideoChannel. |
| 6184 | parameters = channel_->GetRtpSendParameters(primary_ssrc); |
Åsa Persson | 31cb8f9 | 2018-06-27 10:44:56 +0200 | [diff] [blame] | 6185 | EXPECT_EQ(kNumSimulcastStreams, parameters.encodings.size()); |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 6186 | EXPECT_FALSE(parameters.encodings[0].active); |
| 6187 | EXPECT_FALSE(parameters.encodings[1].active); |
| 6188 | EXPECT_FALSE(parameters.encodings[2].active); |
| 6189 | // Check that the VideoSendStream is off. |
| 6190 | EXPECT_FALSE(fake_video_send_stream->IsSending()); |
| 6191 | simulcast_streams = fake_video_send_stream->GetVideoStreams(); |
Åsa Persson | 31cb8f9 | 2018-06-27 10:44:56 +0200 | [diff] [blame] | 6192 | EXPECT_EQ(kNumSimulcastStreams, simulcast_streams.size()); |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 6193 | EXPECT_FALSE(simulcast_streams[0].active); |
| 6194 | EXPECT_FALSE(simulcast_streams[1].active); |
| 6195 | EXPECT_FALSE(simulcast_streams[2].active); |
| 6196 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 6197 | EXPECT_TRUE(channel_->SetVideoSend(primary_ssrc, nullptr, nullptr)); |
Seth Hampson | 8234ead | 2018-02-02 15:16:24 -0800 | [diff] [blame] | 6198 | } |
| 6199 | |
Taylor Brandstetter | 14b9d79 | 2016-09-07 17:16:54 -0700 | [diff] [blame] | 6200 | // Test that if a stream is reconfigured (due to a codec change or other |
| 6201 | // change) while its encoding is still inactive, it doesn't start sending. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 6202 | TEST_F(WebRtcVideoChannelTest, |
Taylor Brandstetter | 14b9d79 | 2016-09-07 17:16:54 -0700 | [diff] [blame] | 6203 | InactiveStreamDoesntStartSendingWhenReconfigured) { |
| 6204 | // Set an initial codec list, which will be modified later. |
| 6205 | cricket::VideoSendParameters parameters1; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 6206 | parameters1.codecs.push_back(GetEngineCodec("VP8")); |
| 6207 | parameters1.codecs.push_back(GetEngineCodec("VP9")); |
Taylor Brandstetter | 14b9d79 | 2016-09-07 17:16:54 -0700 | [diff] [blame] | 6208 | EXPECT_TRUE(channel_->SetSendParameters(parameters1)); |
| 6209 | |
| 6210 | FakeVideoSendStream* stream = AddSendStream(); |
| 6211 | EXPECT_TRUE(channel_->SetSend(true)); |
| 6212 | EXPECT_TRUE(stream->IsSending()); |
| 6213 | |
| 6214 | // Get current parameters and change "active" to false. |
| 6215 | webrtc::RtpParameters parameters = channel_->GetRtpSendParameters(last_ssrc_); |
| 6216 | ASSERT_EQ(1u, parameters.encodings.size()); |
| 6217 | ASSERT_TRUE(parameters.encodings[0].active); |
| 6218 | parameters.encodings[0].active = false; |
| 6219 | EXPECT_EQ(1u, GetFakeSendStreams().size()); |
| 6220 | EXPECT_EQ(1, fake_call_->GetNumCreatedSendStreams()); |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 6221 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, parameters).ok()); |
Taylor Brandstetter | 14b9d79 | 2016-09-07 17:16:54 -0700 | [diff] [blame] | 6222 | EXPECT_FALSE(stream->IsSending()); |
| 6223 | |
| 6224 | // Reorder the codec list, causing the stream to be reconfigured. |
| 6225 | cricket::VideoSendParameters parameters2; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 6226 | parameters2.codecs.push_back(GetEngineCodec("VP9")); |
| 6227 | parameters2.codecs.push_back(GetEngineCodec("VP8")); |
Taylor Brandstetter | 14b9d79 | 2016-09-07 17:16:54 -0700 | [diff] [blame] | 6228 | EXPECT_TRUE(channel_->SetSendParameters(parameters2)); |
| 6229 | auto new_streams = GetFakeSendStreams(); |
| 6230 | // Assert that a new underlying stream was created due to the codec change. |
| 6231 | // Otherwise, this test isn't testing what it set out to test. |
| 6232 | EXPECT_EQ(1u, GetFakeSendStreams().size()); |
| 6233 | EXPECT_EQ(2, fake_call_->GetNumCreatedSendStreams()); |
| 6234 | |
| 6235 | // Verify that we still are not sending anything, due to the inactive |
| 6236 | // encoding. |
| 6237 | EXPECT_FALSE(new_streams[0]->IsSending()); |
| 6238 | } |
| 6239 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 6240 | // Test that GetRtpSendParameters returns the currently configured codecs. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 6241 | TEST_F(WebRtcVideoChannelTest, GetRtpSendParametersCodecs) { |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 6242 | AddSendStream(); |
| 6243 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 6244 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 6245 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 6246 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 6247 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 6248 | webrtc::RtpParameters rtp_parameters = |
| 6249 | channel_->GetRtpSendParameters(last_ssrc_); |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 6250 | ASSERT_EQ(2u, rtp_parameters.codecs.size()); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 6251 | EXPECT_EQ(GetEngineCodec("VP8").ToCodecParameters(), |
| 6252 | rtp_parameters.codecs[0]); |
| 6253 | EXPECT_EQ(GetEngineCodec("VP9").ToCodecParameters(), |
| 6254 | rtp_parameters.codecs[1]); |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 6255 | } |
| 6256 | |
Florent Castelli | dacec71 | 2018-05-24 16:24:21 +0200 | [diff] [blame] | 6257 | // Test that GetRtpSendParameters returns the currently configured RTCP CNAME. |
| 6258 | TEST_F(WebRtcVideoChannelTest, GetRtpSendParametersRtcpCname) { |
| 6259 | StreamParams params = StreamParams::CreateLegacy(kSsrc); |
| 6260 | params.cname = "rtcpcname"; |
| 6261 | AddSendStream(params); |
| 6262 | |
| 6263 | webrtc::RtpParameters rtp_parameters = channel_->GetRtpSendParameters(kSsrc); |
| 6264 | EXPECT_STREQ("rtcpcname", rtp_parameters.rtcp.cname.c_str()); |
| 6265 | } |
| 6266 | |
deadbeef | fb2aced | 2017-01-06 23:05:37 -0800 | [diff] [blame] | 6267 | // Test that RtpParameters for send stream has one encoding and it has |
| 6268 | // the correct SSRC. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 6269 | TEST_F(WebRtcVideoChannelTest, GetRtpSendParametersSsrc) { |
deadbeef | fb2aced | 2017-01-06 23:05:37 -0800 | [diff] [blame] | 6270 | AddSendStream(); |
| 6271 | |
| 6272 | webrtc::RtpParameters rtp_parameters = |
| 6273 | channel_->GetRtpSendParameters(last_ssrc_); |
| 6274 | ASSERT_EQ(1u, rtp_parameters.encodings.size()); |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 6275 | EXPECT_EQ(last_ssrc_, rtp_parameters.encodings[0].ssrc); |
deadbeef | fb2aced | 2017-01-06 23:05:37 -0800 | [diff] [blame] | 6276 | } |
| 6277 | |
Florent Castelli | abe301f | 2018-06-12 18:33:49 +0200 | [diff] [blame] | 6278 | TEST_F(WebRtcVideoChannelTest, DetectRtpSendParameterHeaderExtensionsChange) { |
| 6279 | AddSendStream(); |
| 6280 | |
| 6281 | webrtc::RtpParameters rtp_parameters = |
| 6282 | channel_->GetRtpSendParameters(last_ssrc_); |
| 6283 | rtp_parameters.header_extensions.emplace_back(); |
| 6284 | |
| 6285 | EXPECT_NE(0u, rtp_parameters.header_extensions.size()); |
| 6286 | |
| 6287 | webrtc::RTCError result = |
| 6288 | channel_->SetRtpSendParameters(last_ssrc_, rtp_parameters); |
| 6289 | EXPECT_EQ(webrtc::RTCErrorType::INVALID_MODIFICATION, result.type()); |
| 6290 | } |
| 6291 | |
Florent Castelli | 87b3c51 | 2018-07-18 16:00:28 +0200 | [diff] [blame] | 6292 | TEST_F(WebRtcVideoChannelTest, GetRtpSendParametersDegradationPreference) { |
| 6293 | AddSendStream(); |
| 6294 | |
| 6295 | FakeVideoCapturerWithTaskQueue capturer; |
| 6296 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, &capturer)); |
| 6297 | |
| 6298 | webrtc::RtpParameters rtp_parameters = |
| 6299 | channel_->GetRtpSendParameters(last_ssrc_); |
| 6300 | EXPECT_EQ(rtp_parameters.degradation_preference, |
| 6301 | webrtc::DegradationPreference::BALANCED); |
| 6302 | rtp_parameters.degradation_preference = |
| 6303 | webrtc::DegradationPreference::MAINTAIN_FRAMERATE; |
| 6304 | |
| 6305 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, rtp_parameters).ok()); |
| 6306 | |
| 6307 | webrtc::RtpParameters updated_rtp_parameters = |
| 6308 | channel_->GetRtpSendParameters(last_ssrc_); |
| 6309 | EXPECT_EQ(updated_rtp_parameters.degradation_preference, |
| 6310 | webrtc::DegradationPreference::MAINTAIN_FRAMERATE); |
| 6311 | |
| 6312 | // Remove the source since it will be destroyed before the channel |
| 6313 | EXPECT_TRUE(channel_->SetVideoSend(last_ssrc_, nullptr, nullptr)); |
| 6314 | } |
| 6315 | |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 6316 | // 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] | 6317 | TEST_F(WebRtcVideoChannelTest, SetAndGetRtpSendParameters) { |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 6318 | AddSendStream(); |
| 6319 | cricket::VideoSendParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 6320 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 6321 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 6322 | EXPECT_TRUE(channel_->SetSendParameters(parameters)); |
| 6323 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 6324 | webrtc::RtpParameters initial_params = |
| 6325 | channel_->GetRtpSendParameters(last_ssrc_); |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 6326 | |
| 6327 | // We should be able to set the params we just got. |
Zach Stein | ba37b4b | 2018-01-23 15:02:36 -0800 | [diff] [blame] | 6328 | EXPECT_TRUE(channel_->SetRtpSendParameters(last_ssrc_, initial_params).ok()); |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 6329 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 6330 | // ... And this shouldn't change the params returned by GetRtpSendParameters. |
| 6331 | EXPECT_EQ(initial_params, channel_->GetRtpSendParameters(last_ssrc_)); |
| 6332 | } |
| 6333 | |
| 6334 | // Test that GetRtpReceiveParameters returns the currently configured codecs. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 6335 | TEST_F(WebRtcVideoChannelTest, GetRtpReceiveParametersCodecs) { |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 6336 | AddRecvStream(); |
| 6337 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 6338 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 6339 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 6340 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
| 6341 | |
| 6342 | webrtc::RtpParameters rtp_parameters = |
| 6343 | channel_->GetRtpReceiveParameters(last_ssrc_); |
| 6344 | ASSERT_EQ(2u, rtp_parameters.codecs.size()); |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 6345 | EXPECT_EQ(GetEngineCodec("VP8").ToCodecParameters(), |
| 6346 | rtp_parameters.codecs[0]); |
| 6347 | EXPECT_EQ(GetEngineCodec("VP9").ToCodecParameters(), |
| 6348 | rtp_parameters.codecs[1]); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 6349 | } |
| 6350 | |
johan | 073ece4 | 2016-08-26 02:59:47 -0700 | [diff] [blame] | 6351 | #if defined(WEBRTC_USE_H264) |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 6352 | TEST_F(WebRtcVideoChannelTest, GetRtpReceiveFmtpSprop) { |
johan | 073ece4 | 2016-08-26 02:59:47 -0700 | [diff] [blame] | 6353 | #else |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 6354 | TEST_F(WebRtcVideoChannelTest, DISABLED_GetRtpReceiveFmtpSprop) { |
johan | 073ece4 | 2016-08-26 02:59:47 -0700 | [diff] [blame] | 6355 | #endif |
johan | 3859c89 | 2016-08-05 09:19:25 -0700 | [diff] [blame] | 6356 | cricket::VideoRecvParameters parameters; |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 6357 | cricket::VideoCodec kH264sprop1(101, "H264"); |
magjed | 5dfac56 | 2016-11-25 03:56:37 -0800 | [diff] [blame] | 6358 | kH264sprop1.SetParam(kH264FmtpSpropParameterSets, "uvw"); |
johan | 3859c89 | 2016-08-05 09:19:25 -0700 | [diff] [blame] | 6359 | parameters.codecs.push_back(kH264sprop1); |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 6360 | cricket::VideoCodec kH264sprop2(102, "H264"); |
magjed | 5dfac56 | 2016-11-25 03:56:37 -0800 | [diff] [blame] | 6361 | kH264sprop2.SetParam(kH264FmtpSpropParameterSets, "xyz"); |
johan | 3859c89 | 2016-08-05 09:19:25 -0700 | [diff] [blame] | 6362 | parameters.codecs.push_back(kH264sprop2); |
| 6363 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
| 6364 | |
| 6365 | FakeVideoReceiveStream* recv_stream = AddRecvStream(); |
| 6366 | const webrtc::VideoReceiveStream::Config& cfg = recv_stream->GetConfig(); |
| 6367 | webrtc::RtpParameters rtp_parameters = |
| 6368 | channel_->GetRtpReceiveParameters(last_ssrc_); |
| 6369 | ASSERT_EQ(2u, rtp_parameters.codecs.size()); |
| 6370 | EXPECT_EQ(kH264sprop1.ToCodecParameters(), rtp_parameters.codecs[0]); |
| 6371 | ASSERT_EQ(2u, cfg.decoders.size()); |
| 6372 | EXPECT_EQ(101, cfg.decoders[0].payload_type); |
Niels Möller | cb7e1d2 | 2018-09-11 15:56:04 +0200 | [diff] [blame] | 6373 | EXPECT_EQ("H264", cfg.decoders[0].video_format.name); |
magjed | 5dfac56 | 2016-11-25 03:56:37 -0800 | [diff] [blame] | 6374 | const auto it0 = |
Niels Möller | cb7e1d2 | 2018-09-11 15:56:04 +0200 | [diff] [blame] | 6375 | cfg.decoders[0].video_format.parameters.find(kH264FmtpSpropParameterSets); |
| 6376 | ASSERT_TRUE(it0 != cfg.decoders[0].video_format.parameters.end()); |
magjed | 5dfac56 | 2016-11-25 03:56:37 -0800 | [diff] [blame] | 6377 | EXPECT_EQ("uvw", it0->second); |
johan | 3859c89 | 2016-08-05 09:19:25 -0700 | [diff] [blame] | 6378 | |
| 6379 | EXPECT_EQ(102, cfg.decoders[1].payload_type); |
Niels Möller | cb7e1d2 | 2018-09-11 15:56:04 +0200 | [diff] [blame] | 6380 | EXPECT_EQ("H264", cfg.decoders[1].video_format.name); |
magjed | 5dfac56 | 2016-11-25 03:56:37 -0800 | [diff] [blame] | 6381 | const auto it1 = |
Niels Möller | cb7e1d2 | 2018-09-11 15:56:04 +0200 | [diff] [blame] | 6382 | cfg.decoders[1].video_format.parameters.find(kH264FmtpSpropParameterSets); |
| 6383 | ASSERT_TRUE(it1 != cfg.decoders[1].video_format.parameters.end()); |
magjed | 5dfac56 | 2016-11-25 03:56:37 -0800 | [diff] [blame] | 6384 | EXPECT_EQ("xyz", it1->second); |
johan | 3859c89 | 2016-08-05 09:19:25 -0700 | [diff] [blame] | 6385 | } |
| 6386 | |
sakal | 1fd9595 | 2016-06-22 00:46:15 -0700 | [diff] [blame] | 6387 | // Test that RtpParameters for receive stream has one encoding and it has |
| 6388 | // the correct SSRC. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 6389 | TEST_F(WebRtcVideoChannelTest, GetRtpReceiveParametersSsrc) { |
sakal | 1fd9595 | 2016-06-22 00:46:15 -0700 | [diff] [blame] | 6390 | AddRecvStream(); |
| 6391 | |
| 6392 | webrtc::RtpParameters rtp_parameters = |
| 6393 | channel_->GetRtpReceiveParameters(last_ssrc_); |
| 6394 | ASSERT_EQ(1u, rtp_parameters.encodings.size()); |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 6395 | EXPECT_EQ(last_ssrc_, rtp_parameters.encodings[0].ssrc); |
sakal | 1fd9595 | 2016-06-22 00:46:15 -0700 | [diff] [blame] | 6396 | } |
| 6397 | |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 6398 | // 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] | 6399 | TEST_F(WebRtcVideoChannelTest, SetAndGetRtpReceiveParameters) { |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 6400 | AddRecvStream(); |
| 6401 | cricket::VideoRecvParameters parameters; |
magjed | 509e4fe | 2016-11-18 01:34:11 -0800 | [diff] [blame] | 6402 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 6403 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
Taylor Brandstetter | db0cd9e | 2016-05-16 11:40:30 -0700 | [diff] [blame] | 6404 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
| 6405 | |
| 6406 | webrtc::RtpParameters initial_params = |
| 6407 | channel_->GetRtpReceiveParameters(last_ssrc_); |
| 6408 | |
| 6409 | // We should be able to set the params we just got. |
| 6410 | EXPECT_TRUE(channel_->SetRtpReceiveParameters(last_ssrc_, initial_params)); |
| 6411 | |
| 6412 | // ... And this shouldn't change the params returned by |
| 6413 | // GetRtpReceiveParameters. |
| 6414 | EXPECT_EQ(initial_params, channel_->GetRtpReceiveParameters(last_ssrc_)); |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 6415 | } |
| 6416 | |
deadbeef | 3bc1510 | 2017-04-20 19:25:07 -0700 | [diff] [blame] | 6417 | // Test that GetRtpReceiveParameters returns parameters correctly when SSRCs |
| 6418 | // aren't signaled. It should always return an empty "RtpEncodingParameters", |
| 6419 | // even after a packet is received and the unsignaled SSRC is known. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 6420 | TEST_F(WebRtcVideoChannelTest, GetRtpReceiveParametersWithUnsignaledSsrc) { |
deadbeef | 3bc1510 | 2017-04-20 19:25:07 -0700 | [diff] [blame] | 6421 | // Call necessary methods to configure receiving a default stream as |
| 6422 | // soon as it arrives. |
| 6423 | cricket::VideoRecvParameters parameters; |
| 6424 | parameters.codecs.push_back(GetEngineCodec("VP8")); |
| 6425 | parameters.codecs.push_back(GetEngineCodec("VP9")); |
| 6426 | EXPECT_TRUE(channel_->SetRecvParameters(parameters)); |
| 6427 | |
| 6428 | // Call GetRtpReceiveParameters before configured to receive an unsignaled |
| 6429 | // stream. Should return nothing. |
| 6430 | EXPECT_EQ(webrtc::RtpParameters(), channel_->GetRtpReceiveParameters(0)); |
| 6431 | |
| 6432 | // Set a sink for an unsignaled stream. |
| 6433 | cricket::FakeVideoRenderer renderer; |
| 6434 | // Value of "0" means "unsignaled stream". |
| 6435 | EXPECT_TRUE(channel_->SetSink(0, &renderer)); |
| 6436 | |
| 6437 | // Call GetRtpReceiveParameters before the SSRC is known. Value of "0" |
| 6438 | // in this method means "unsignaled stream". |
| 6439 | webrtc::RtpParameters rtp_parameters = channel_->GetRtpReceiveParameters(0); |
| 6440 | ASSERT_EQ(1u, rtp_parameters.encodings.size()); |
| 6441 | EXPECT_FALSE(rtp_parameters.encodings[0].ssrc); |
| 6442 | |
| 6443 | // Receive VP8 packet. |
| 6444 | uint8_t data[kMinRtpPacketLen]; |
| 6445 | cricket::RtpHeader rtpHeader; |
| 6446 | rtpHeader.payload_type = GetEngineCodec("VP8").id; |
| 6447 | rtpHeader.seq_num = rtpHeader.timestamp = 0; |
| 6448 | rtpHeader.ssrc = kIncomingUnsignalledSsrc; |
| 6449 | cricket::SetRtpHeader(data, sizeof(data), rtpHeader); |
| 6450 | rtc::CopyOnWriteBuffer packet(data, sizeof(data)); |
| 6451 | rtc::PacketTime packet_time; |
| 6452 | channel_->OnPacketReceived(&packet, packet_time); |
| 6453 | |
| 6454 | // The |ssrc| member should still be unset. |
| 6455 | rtp_parameters = channel_->GetRtpReceiveParameters(0); |
| 6456 | ASSERT_EQ(1u, rtp_parameters.encodings.size()); |
| 6457 | EXPECT_FALSE(rtp_parameters.encodings[0].ssrc); |
| 6458 | } |
| 6459 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 6460 | void WebRtcVideoChannelTest::TestReceiverLocalSsrcConfiguration( |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 6461 | bool receiver_first) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 6462 | EXPECT_TRUE(channel_->SetSendParameters(send_parameters_)); |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 6463 | |
| 6464 | const uint32_t kSenderSsrc = 0xC0FFEE; |
Peter Boström | dfa2815 | 2015-10-21 17:21:10 +0200 | [diff] [blame] | 6465 | const uint32_t kSecondSenderSsrc = 0xBADCAFE; |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 6466 | const uint32_t kReceiverSsrc = 0x4711; |
Peter Boström | dfa2815 | 2015-10-21 17:21:10 +0200 | [diff] [blame] | 6467 | const uint32_t kExpectedDefaultReceiverSsrc = 1; |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 6468 | |
| 6469 | if (receiver_first) { |
| 6470 | AddRecvStream(StreamParams::CreateLegacy(kReceiverSsrc)); |
| 6471 | std::vector<FakeVideoReceiveStream*> receive_streams = |
| 6472 | fake_call_->GetVideoReceiveStreams(); |
| 6473 | ASSERT_EQ(1u, receive_streams.size()); |
Peter Boström | dfa2815 | 2015-10-21 17:21:10 +0200 | [diff] [blame] | 6474 | // Default local SSRC when we have no sender. |
| 6475 | EXPECT_EQ(kExpectedDefaultReceiverSsrc, |
| 6476 | receive_streams[0]->GetConfig().rtp.local_ssrc); |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 6477 | } |
| 6478 | AddSendStream(StreamParams::CreateLegacy(kSenderSsrc)); |
| 6479 | if (!receiver_first) |
| 6480 | AddRecvStream(StreamParams::CreateLegacy(kReceiverSsrc)); |
| 6481 | std::vector<FakeVideoReceiveStream*> receive_streams = |
| 6482 | fake_call_->GetVideoReceiveStreams(); |
| 6483 | ASSERT_EQ(1u, receive_streams.size()); |
| 6484 | EXPECT_EQ(kSenderSsrc, receive_streams[0]->GetConfig().rtp.local_ssrc); |
Peter Boström | dfa2815 | 2015-10-21 17:21:10 +0200 | [diff] [blame] | 6485 | |
| 6486 | // Removing first sender should fall back to another (in this case the second) |
| 6487 | // local send stream's SSRC. |
| 6488 | AddSendStream(StreamParams::CreateLegacy(kSecondSenderSsrc)); |
| 6489 | ASSERT_TRUE(channel_->RemoveSendStream(kSenderSsrc)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 6490 | receive_streams = fake_call_->GetVideoReceiveStreams(); |
Peter Boström | dfa2815 | 2015-10-21 17:21:10 +0200 | [diff] [blame] | 6491 | ASSERT_EQ(1u, receive_streams.size()); |
| 6492 | EXPECT_EQ(kSecondSenderSsrc, receive_streams[0]->GetConfig().rtp.local_ssrc); |
| 6493 | |
| 6494 | // Removing the last sender should fall back to default local SSRC. |
| 6495 | ASSERT_TRUE(channel_->RemoveSendStream(kSecondSenderSsrc)); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 6496 | receive_streams = fake_call_->GetVideoReceiveStreams(); |
Peter Boström | dfa2815 | 2015-10-21 17:21:10 +0200 | [diff] [blame] | 6497 | ASSERT_EQ(1u, receive_streams.size()); |
| 6498 | EXPECT_EQ(kExpectedDefaultReceiverSsrc, |
| 6499 | receive_streams[0]->GetConfig().rtp.local_ssrc); |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 6500 | } |
| 6501 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 6502 | TEST_F(WebRtcVideoChannelTest, ConfiguresLocalSsrc) { |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 6503 | TestReceiverLocalSsrcConfiguration(false); |
| 6504 | } |
| 6505 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 6506 | TEST_F(WebRtcVideoChannelTest, ConfiguresLocalSsrcOnExistingReceivers) { |
Peter Boström | 3548dd2 | 2015-05-22 18:48:36 +0200 | [diff] [blame] | 6507 | TestReceiverLocalSsrcConfiguration(true); |
| 6508 | } |
| 6509 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 6510 | class WebRtcVideoChannelSimulcastTest : public testing::Test { |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6511 | public: |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 6512 | WebRtcVideoChannelSimulcastTest() |
Sebastian Jansson | 8f83b42 | 2018-02-21 13:07:13 +0100 | [diff] [blame] | 6513 | : fake_call_(), |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 6514 | encoder_factory_(new cricket::FakeWebRtcVideoEncoderFactory), |
| 6515 | decoder_factory_(new cricket::FakeWebRtcVideoDecoderFactory), |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 6516 | engine_(std::unique_ptr<cricket::FakeWebRtcVideoEncoderFactory>( |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 6517 | encoder_factory_), |
Anders Carlsson | 6753795 | 2018-05-03 11:28:29 +0200 | [diff] [blame] | 6518 | std::unique_ptr<cricket::FakeWebRtcVideoDecoderFactory>( |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 6519 | decoder_factory_)), |
magjed | 2475ae2 | 2017-09-12 04:42:15 -0700 | [diff] [blame] | 6520 | last_ssrc_(0) {} |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6521 | |
kjellander@webrtc.org | 14665ff | 2015-03-04 12:58:35 +0000 | [diff] [blame] | 6522 | void SetUp() override { |
Anders Carlsson | 5f2bb62 | 2018-05-14 09:48:06 +0200 | [diff] [blame] | 6523 | encoder_factory_->AddSupportedVideoCodecType("VP8"); |
nisse | 51542be | 2016-02-12 02:27:06 -0800 | [diff] [blame] | 6524 | channel_.reset( |
kthelgason | 2bc6864 | 2017-02-07 07:02:22 -0800 | [diff] [blame] | 6525 | engine_.CreateChannel(&fake_call_, GetMediaConfig(), VideoOptions())); |
Sergey Ulanov | e2b1501 | 2016-11-22 16:08:30 -0800 | [diff] [blame] | 6526 | channel_->OnReadyToSend(true); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6527 | last_ssrc_ = 123; |
| 6528 | } |
| 6529 | |
| 6530 | protected: |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6531 | void VerifySimulcastSettings(const VideoCodec& codec, |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 6532 | int capture_width, |
| 6533 | int capture_height, |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6534 | size_t num_configured_streams, |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 6535 | size_t expected_num_streams, |
| 6536 | bool screenshare, |
| 6537 | bool conference_mode) { |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 6538 | cricket::VideoSendParameters parameters; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 6539 | parameters.codecs.push_back(codec); |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 6540 | parameters.conference_mode = conference_mode; |
Fredrik Solenberg | b071a19 | 2015-09-17 16:42:56 +0200 | [diff] [blame] | 6541 | ASSERT_TRUE(channel_->SetSendParameters(parameters)); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6542 | |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 6543 | std::vector<uint32_t> ssrcs = MAKE_VECTOR(kSsrcs3); |
henrikg | 91d6ede | 2015-09-17 00:24:34 -0700 | [diff] [blame] | 6544 | RTC_DCHECK(num_configured_streams <= ssrcs.size()); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6545 | ssrcs.resize(num_configured_streams); |
| 6546 | |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 6547 | AddSendStream(CreateSimStreamParams("cname", ssrcs)); |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 6548 | // Send a full-size frame to trigger a stream reconfiguration to use all |
| 6549 | // expected simulcast layers. |
Tommi | 8595993 | 2018-02-07 19:26:06 +0100 | [diff] [blame] | 6550 | FakeVideoCapturerWithTaskQueue capturer; |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 6551 | VideoOptions options; |
| 6552 | if (screenshare) |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 6553 | options.is_screencast = screenshare; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 6554 | EXPECT_TRUE(channel_->SetVideoSend(ssrcs.front(), &options, &capturer)); |
sprang | f24a064 | 2017-02-28 13:23:26 -0800 | [diff] [blame] | 6555 | // Fetch the latest stream since SetVideoSend() may recreate it if the |
| 6556 | // screen content setting is changed. |
| 6557 | FakeVideoSendStream* stream = fake_call_.GetVideoSendStreams().front(); |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 6558 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(cricket::VideoFormat( |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 6559 | capture_width, capture_height, |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 6560 | cricket::VideoFormat::FpsToInterval(30), |
| 6561 | cricket::FOURCC_I420))); |
| 6562 | channel_->SetSend(true); |
| 6563 | EXPECT_TRUE(capturer.CaptureFrame()); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6564 | |
Zach Stein | 3ca452b | 2018-01-18 10:01:24 -0800 | [diff] [blame] | 6565 | auto rtp_parameters = channel_->GetRtpSendParameters(kSsrcs3[0]); |
| 6566 | EXPECT_EQ(num_configured_streams, rtp_parameters.encodings.size()); |
| 6567 | |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6568 | std::vector<webrtc::VideoStream> video_streams = stream->GetVideoStreams(); |
| 6569 | ASSERT_EQ(expected_num_streams, video_streams.size()); |
| 6570 | |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 6571 | std::vector<webrtc::VideoStream> expected_streams; |
| 6572 | if (conference_mode) { |
| 6573 | expected_streams = GetSimulcastConfig( |
| 6574 | num_configured_streams, capture_width, capture_height, 0, |
Seth Hampson | 24722b3 | 2017-12-22 09:36:42 -0800 | [diff] [blame] | 6575 | webrtc::kDefaultBitratePriority, kDefaultQpMax, |
Sergio Garcia Murillo | 43800f9 | 2018-06-21 16:16:38 +0200 | [diff] [blame] | 6576 | kDefaultVideoMaxFramerate, screenshare, true); |
sprang | 3ebabf1 | 2017-02-16 07:35:22 -0800 | [diff] [blame] | 6577 | if (screenshare) { |
| 6578 | for (const webrtc::VideoStream& stream : expected_streams) { |
| 6579 | // Never scale screen content. |
Danil Chapovalov | 350531e | 2018-06-08 11:04:04 +0000 | [diff] [blame] | 6580 | EXPECT_EQ(stream.width, rtc::checked_cast<size_t>(capture_width)); |
| 6581 | EXPECT_EQ(stream.height, rtc::checked_cast<size_t>(capture_height)); |
sprang | 3ebabf1 | 2017-02-16 07:35:22 -0800 | [diff] [blame] | 6582 | } |
| 6583 | } |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 6584 | } else { |
| 6585 | webrtc::VideoStream stream; |
| 6586 | stream.width = capture_width; |
| 6587 | stream.height = capture_height; |
| 6588 | stream.max_framerate = kDefaultVideoMaxFramerate; |
Åsa Persson | 45bbc8a | 2017-11-13 10:16:47 +0100 | [diff] [blame] | 6589 | stream.min_bitrate_bps = cricket::kMinVideoBitrateBps; |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 6590 | stream.target_bitrate_bps = stream.max_bitrate_bps = |
Åsa Persson | bdee46d | 2018-06-25 11:28:06 +0200 | [diff] [blame] | 6591 | GetMaxDefaultBitrateBps(capture_width, capture_height); |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 6592 | stream.max_qp = kDefaultQpMax; |
| 6593 | expected_streams.push_back(stream); |
| 6594 | } |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6595 | |
| 6596 | ASSERT_EQ(expected_streams.size(), video_streams.size()); |
| 6597 | |
| 6598 | size_t num_streams = video_streams.size(); |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 6599 | int total_max_bitrate_bps = 0; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6600 | for (size_t i = 0; i < num_streams; ++i) { |
| 6601 | EXPECT_EQ(expected_streams[i].width, video_streams[i].width); |
| 6602 | EXPECT_EQ(expected_streams[i].height, video_streams[i].height); |
| 6603 | |
| 6604 | EXPECT_GT(video_streams[i].max_framerate, 0); |
| 6605 | EXPECT_EQ(expected_streams[i].max_framerate, |
| 6606 | video_streams[i].max_framerate); |
| 6607 | |
| 6608 | EXPECT_GT(video_streams[i].min_bitrate_bps, 0); |
| 6609 | EXPECT_EQ(expected_streams[i].min_bitrate_bps, |
| 6610 | video_streams[i].min_bitrate_bps); |
| 6611 | |
| 6612 | EXPECT_GT(video_streams[i].target_bitrate_bps, 0); |
| 6613 | EXPECT_EQ(expected_streams[i].target_bitrate_bps, |
| 6614 | video_streams[i].target_bitrate_bps); |
| 6615 | |
| 6616 | EXPECT_GT(video_streams[i].max_bitrate_bps, 0); |
| 6617 | EXPECT_EQ(expected_streams[i].max_bitrate_bps, |
| 6618 | video_streams[i].max_bitrate_bps); |
| 6619 | |
| 6620 | EXPECT_GT(video_streams[i].max_qp, 0); |
| 6621 | EXPECT_EQ(expected_streams[i].max_qp, video_streams[i].max_qp); |
| 6622 | |
Sergey Silkin | a796a7e | 2018-03-01 15:11:29 +0100 | [diff] [blame] | 6623 | EXPECT_EQ(conference_mode, |
| 6624 | expected_streams[i].num_temporal_layers.has_value()); |
| 6625 | |
| 6626 | if (conference_mode) { |
| 6627 | EXPECT_EQ(expected_streams[i].num_temporal_layers, |
| 6628 | video_streams[i].num_temporal_layers); |
| 6629 | } |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 6630 | |
| 6631 | if (i == num_streams - 1) { |
| 6632 | total_max_bitrate_bps += video_streams[i].max_bitrate_bps; |
| 6633 | } else { |
| 6634 | total_max_bitrate_bps += video_streams[i].target_bitrate_bps; |
| 6635 | } |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6636 | } |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 6637 | |
Niels Möller | ff40b14 | 2018-04-09 08:49:14 +0200 | [diff] [blame] | 6638 | EXPECT_TRUE(channel_->SetVideoSend(ssrcs.front(), nullptr, nullptr)); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6639 | } |
| 6640 | |
| 6641 | FakeVideoSendStream* AddSendStream() { |
| 6642 | return AddSendStream(StreamParams::CreateLegacy(last_ssrc_++)); |
| 6643 | } |
| 6644 | |
| 6645 | FakeVideoSendStream* AddSendStream(const StreamParams& sp) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 6646 | size_t num_streams = fake_call_.GetVideoSendStreams().size(); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6647 | EXPECT_TRUE(channel_->AddSendStream(sp)); |
| 6648 | std::vector<FakeVideoSendStream*> streams = |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 6649 | fake_call_.GetVideoSendStreams(); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6650 | EXPECT_EQ(num_streams + 1, streams.size()); |
| 6651 | return streams[streams.size() - 1]; |
| 6652 | } |
| 6653 | |
| 6654 | std::vector<FakeVideoSendStream*> GetFakeSendStreams() { |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 6655 | return fake_call_.GetVideoSendStreams(); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6656 | } |
| 6657 | |
| 6658 | FakeVideoReceiveStream* AddRecvStream() { |
| 6659 | return AddRecvStream(StreamParams::CreateLegacy(last_ssrc_++)); |
| 6660 | } |
| 6661 | |
| 6662 | FakeVideoReceiveStream* AddRecvStream(const StreamParams& sp) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 6663 | size_t num_streams = fake_call_.GetVideoReceiveStreams().size(); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6664 | EXPECT_TRUE(channel_->AddRecvStream(sp)); |
| 6665 | std::vector<FakeVideoReceiveStream*> streams = |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 6666 | fake_call_.GetVideoReceiveStreams(); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6667 | EXPECT_EQ(num_streams + 1, streams.size()); |
| 6668 | return streams[streams.size() - 1]; |
| 6669 | } |
| 6670 | |
skvlad | 11a9cbf | 2016-10-07 11:53:05 -0700 | [diff] [blame] | 6671 | webrtc::RtcEventLogNullImpl event_log_; |
Fredrik Solenberg | 709ed67 | 2015-09-15 12:26:33 +0200 | [diff] [blame] | 6672 | FakeCall fake_call_; |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame] | 6673 | cricket::FakeWebRtcVideoEncoderFactory* encoder_factory_; |
| 6674 | cricket::FakeWebRtcVideoDecoderFactory* decoder_factory_; |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 6675 | WebRtcVideoEngine engine_; |
kwiberg | 686a8ef | 2016-02-26 03:00:35 -0800 | [diff] [blame] | 6676 | std::unique_ptr<VideoMediaChannel> channel_; |
Peter Boström | 0c4e06b | 2015-10-07 12:23:21 +0200 | [diff] [blame] | 6677 | uint32_t last_ssrc_; |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6678 | }; |
| 6679 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 6680 | TEST_F(WebRtcVideoChannelSimulcastTest, SetSendCodecsWith2SimulcastStreams) { |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 6681 | VerifySimulcastSettings(cricket::VideoCodec("VP8"), 640, 360, 2, 2, false, |
| 6682 | true); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6683 | } |
| 6684 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 6685 | TEST_F(WebRtcVideoChannelSimulcastTest, SetSendCodecsWith3SimulcastStreams) { |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 6686 | VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 3, false, |
| 6687 | true); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6688 | } |
| 6689 | |
| 6690 | // Test that we normalize send codec format size in simulcast. |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 6691 | TEST_F(WebRtcVideoChannelSimulcastTest, SetSendCodecsWithOddSizeInSimulcast) { |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 6692 | VerifySimulcastSettings(cricket::VideoCodec("VP8"), 541, 271, 2, 2, false, |
| 6693 | true); |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 6694 | } |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 6695 | |
Ilya Nikolaevskiy | 3df1d5d | 2018-08-22 09:26:51 +0200 | [diff] [blame] | 6696 | TEST_F(WebRtcVideoChannelSimulcastTest, SetSendCodecsForScreenshare) { |
Ilya Nikolaevskiy | 3df1d5d | 2018-08-22 09:26:51 +0200 | [diff] [blame] | 6697 | VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 1, true, |
| 6698 | false); |
| 6699 | } |
| 6700 | |
Ilya Nikolaevskiy | 3df1d5d | 2018-08-22 09:26:51 +0200 | [diff] [blame] | 6701 | TEST_F(WebRtcVideoChannelSimulcastTest, |
| 6702 | SetSendCodecsForConferenceModeScreenshare) { |
Ilya Nikolaevskiy | 3df1d5d | 2018-08-22 09:26:51 +0200 | [diff] [blame] | 6703 | VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 1, true, |
| 6704 | true); |
| 6705 | } |
| 6706 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 6707 | TEST_F(WebRtcVideoChannelSimulcastTest, SetSendCodecsForSimulcastScreenshare) { |
Erik Språng | b65aa01 | 2018-09-24 11:35:19 +0200 | [diff] [blame] | 6708 | webrtc::test::ScopedFieldTrials override_field_trials_( |
| 6709 | "WebRTC-SimulcastScreenshare/Enabled/"); |
sprang | 429600d | 2017-01-26 06:12:26 -0800 | [diff] [blame] | 6710 | VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 2, true, |
| 6711 | true); |
| 6712 | } |
| 6713 | |
eladalon | f184138 | 2017-06-12 01:16:46 -0700 | [diff] [blame] | 6714 | TEST_F(WebRtcVideoChannelSimulcastTest, |
sprang | fe627f3 | 2017-03-29 08:24:59 -0700 | [diff] [blame] | 6715 | NoSimulcastScreenshareWithoutConference) { |
Erik Språng | b65aa01 | 2018-09-24 11:35:19 +0200 | [diff] [blame] | 6716 | webrtc::test::ScopedFieldTrials override_field_trials_( |
| 6717 | "WebRTC-SimulcastScreenshare/Enabled/"); |
sprang | fe627f3 | 2017-03-29 08:24:59 -0700 | [diff] [blame] | 6718 | VerifySimulcastSettings(cricket::VideoCodec("VP8"), 1280, 720, 3, 1, true, |
| 6719 | false); |
| 6720 | } |
| 6721 | |
Jonas Oreland | 49ac595 | 2018-09-26 16:04:32 +0200 | [diff] [blame^] | 6722 | // The fake clock needs to be initialize before the call. |
| 6723 | // So defer creating call in base class. |
| 6724 | class WebRtcVideoChannelTestWithClock : public WebRtcVideoChannelBaseTest { |
| 6725 | public: |
| 6726 | WebRtcVideoChannelTestWithClock() { |
| 6727 | fake_clock_.AdvanceTime(webrtc::TimeDelta::ms(1)); // avoid time=0 |
| 6728 | } |
| 6729 | rtc::ScopedFakeClock fake_clock_; |
| 6730 | }; |
| 6731 | |
| 6732 | TEST_F(WebRtcVideoChannelTestWithClock, GetSources) { |
| 6733 | uint8_t data1[] = {0x80, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 6734 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 6735 | |
| 6736 | EXPECT_EQ(0u, channel_->GetSources(kSsrc).size()); |
| 6737 | |
| 6738 | rtc::CopyOnWriteBuffer packet1(data1, sizeof(data1)); |
| 6739 | rtc::SetBE32(packet1.data() + 8, kSsrc); |
| 6740 | channel_->SetSink(kDefaultReceiveSsrc, NULL); |
| 6741 | EXPECT_TRUE(SetDefaultCodec()); |
| 6742 | EXPECT_TRUE(SetSend(true)); |
| 6743 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 6744 | channel_->OnPacketReceived(&packet1, rtc::PacketTime()); |
| 6745 | |
| 6746 | std::vector<webrtc::RtpSource> sources = channel_->GetSources(kSsrc); |
| 6747 | EXPECT_EQ(1u, sources.size()); |
| 6748 | EXPECT_EQ(webrtc::RtpSourceType::SSRC, sources[0].source_type()); |
| 6749 | int64_t timestamp1 = sources[0].timestamp_ms(); |
| 6750 | |
| 6751 | // a new packet. |
| 6752 | int64_t timeDeltaMs = 1; |
| 6753 | fake_clock_.AdvanceTime(webrtc::TimeDelta::ms(timeDeltaMs)); |
| 6754 | channel_->OnPacketReceived(&packet1, rtc::PacketTime()); |
| 6755 | int64_t timestamp2 = channel_->GetSources(kSsrc)[0].timestamp_ms(); |
| 6756 | EXPECT_EQ(timestamp2, timestamp1 + timeDeltaMs); |
| 6757 | |
| 6758 | // It only keeps 10s of history. |
| 6759 | fake_clock_.AdvanceTime(webrtc::TimeDelta::seconds(10)); |
| 6760 | fake_clock_.AdvanceTime(webrtc::TimeDelta::ms(1)); |
| 6761 | EXPECT_EQ(0u, channel_->GetSources(kSsrc).size()); |
| 6762 | } |
| 6763 | |
| 6764 | TEST_F(WebRtcVideoChannelTestWithClock, GetContributingSources) { |
| 6765 | uint8_t data1[] = {0x81, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 6766 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 6767 | |
| 6768 | uint32_t kCsrc = 4321u; |
| 6769 | EXPECT_EQ(0u, channel_->GetSources(kSsrc).size()); |
| 6770 | EXPECT_EQ(0u, channel_->GetSources(kCsrc).size()); |
| 6771 | |
| 6772 | rtc::CopyOnWriteBuffer packet1(data1, sizeof(data1)); |
| 6773 | rtc::SetBE32(packet1.data() + 8, kSsrc); |
| 6774 | rtc::SetBE32(packet1.data() + 12, kCsrc); |
| 6775 | channel_->SetSink(kDefaultReceiveSsrc, NULL); |
| 6776 | EXPECT_TRUE(SetDefaultCodec()); |
| 6777 | EXPECT_TRUE(SetSend(true)); |
| 6778 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 6779 | channel_->OnPacketReceived(&packet1, rtc::PacketTime()); |
| 6780 | |
| 6781 | { |
| 6782 | ASSERT_EQ(2u, channel_->GetSources(kSsrc).size()); |
| 6783 | EXPECT_EQ(0u, channel_->GetSources(kCsrc).size()); |
| 6784 | std::vector<webrtc::RtpSource> sources = channel_->GetSources(kSsrc); |
| 6785 | EXPECT_EQ(sources[0].timestamp_ms(), sources[1].timestamp_ms()); |
| 6786 | // 1 SSRC and 1 CSRC. |
| 6787 | EXPECT_EQ(1, std::count_if(sources.begin(), sources.end(), |
| 6788 | [](const webrtc::RtpSource& source) { |
| 6789 | return source.source_type() == |
| 6790 | webrtc::RtpSourceType::SSRC; |
| 6791 | })); |
| 6792 | EXPECT_EQ(1, std::count_if(sources.begin(), sources.end(), |
| 6793 | [](const webrtc::RtpSource& source) { |
| 6794 | return source.source_type() == |
| 6795 | webrtc::RtpSourceType::CSRC; |
| 6796 | })); |
| 6797 | } |
| 6798 | int64_t timestamp1 = channel_->GetSources(kSsrc)[0].timestamp_ms(); |
| 6799 | |
| 6800 | // a new packet with only ssrc (i.e no csrc). |
| 6801 | uint8_t data2[] = {0x80, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 6802 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 6803 | rtc::CopyOnWriteBuffer packet2(data2, sizeof(data2)); |
| 6804 | rtc::SetBE32(packet2.data() + 8, kSsrc); |
| 6805 | |
| 6806 | int64_t timeDeltaMs = 1; |
| 6807 | fake_clock_.AdvanceTime(webrtc::TimeDelta::ms(timeDeltaMs)); |
| 6808 | channel_->OnPacketReceived(&packet2, rtc::PacketTime()); |
| 6809 | |
| 6810 | { |
| 6811 | ASSERT_EQ(2u, channel_->GetSources(kSsrc).size()); |
| 6812 | EXPECT_EQ(0u, channel_->GetSources(kCsrc).size()); |
| 6813 | std::vector<webrtc::RtpSource> sources = channel_->GetSources(kSsrc); |
| 6814 | EXPECT_NE(sources[0].timestamp_ms(), sources[1].timestamp_ms()); |
| 6815 | // 1 SSRC and 1 CSRC. |
| 6816 | EXPECT_EQ(1, std::count_if(sources.begin(), sources.end(), |
| 6817 | [](const webrtc::RtpSource& source) { |
| 6818 | return source.source_type() == |
| 6819 | webrtc::RtpSourceType::SSRC; |
| 6820 | })); |
| 6821 | EXPECT_EQ(1, std::count_if(sources.begin(), sources.end(), |
| 6822 | [](const webrtc::RtpSource& source) { |
| 6823 | return source.source_type() == |
| 6824 | webrtc::RtpSourceType::CSRC; |
| 6825 | })); |
| 6826 | auto ssrcSource = std::find_if( |
| 6827 | sources.begin(), sources.end(), [](const webrtc::RtpSource& source) { |
| 6828 | return source.source_type() == webrtc::RtpSourceType::SSRC; |
| 6829 | }); |
| 6830 | auto csrcSource = std::find_if( |
| 6831 | sources.begin(), sources.end(), [](const webrtc::RtpSource& source) { |
| 6832 | return source.source_type() == webrtc::RtpSourceType::CSRC; |
| 6833 | }); |
| 6834 | |
| 6835 | EXPECT_EQ(ssrcSource->timestamp_ms(), timestamp1 + timeDeltaMs); |
| 6836 | EXPECT_EQ(csrcSource->timestamp_ms(), timestamp1); |
| 6837 | } |
| 6838 | |
| 6839 | // It only keeps 10s of history. |
| 6840 | fake_clock_.AdvanceTime(webrtc::TimeDelta::seconds(10)); |
| 6841 | |
| 6842 | { |
| 6843 | ASSERT_EQ(1u, channel_->GetSources(kSsrc).size()); |
| 6844 | EXPECT_EQ(0u, channel_->GetSources(kCsrc).size()); |
| 6845 | std::vector<webrtc::RtpSource> sources = channel_->GetSources(kSsrc); |
| 6846 | EXPECT_EQ(1, std::count_if(sources.begin(), sources.end(), |
| 6847 | [](const webrtc::RtpSource& source) { |
| 6848 | return source.source_type() == |
| 6849 | webrtc::RtpSourceType::SSRC; |
| 6850 | })); |
| 6851 | EXPECT_EQ(0, std::count_if(sources.begin(), sources.end(), |
| 6852 | [](const webrtc::RtpSource& source) { |
| 6853 | return source.source_type() == |
| 6854 | webrtc::RtpSourceType::CSRC; |
| 6855 | })); |
| 6856 | } |
| 6857 | |
| 6858 | fake_clock_.AdvanceTime(webrtc::TimeDelta::ms(1)); |
| 6859 | EXPECT_EQ(0u, channel_->GetSources(kSsrc).size()); |
| 6860 | EXPECT_EQ(0u, channel_->GetSources(kCsrc).size()); |
| 6861 | } |
| 6862 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 6863 | } // namespace cricket |