henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2004 Google Inc. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #include "talk/base/fakecpumonitor.h" |
| 29 | #include "talk/base/gunit.h" |
| 30 | #include "talk/base/logging.h" |
| 31 | #include "talk/base/scoped_ptr.h" |
| 32 | #include "talk/base/stream.h" |
| 33 | #include "talk/media/base/constants.h" |
| 34 | #include "talk/media/base/fakemediaprocessor.h" |
| 35 | #include "talk/media/base/fakenetworkinterface.h" |
| 36 | #include "talk/media/base/fakevideorenderer.h" |
| 37 | #include "talk/media/base/mediachannel.h" |
| 38 | #include "talk/media/base/testutils.h" |
| 39 | #include "talk/media/base/videoengine_unittest.h" |
| 40 | #include "talk/media/webrtc/fakewebrtcvideocapturemodule.h" |
| 41 | #include "talk/media/webrtc/fakewebrtcvideoengine.h" |
| 42 | #include "talk/media/webrtc/fakewebrtcvoiceengine.h" |
| 43 | #include "talk/media/webrtc/webrtcvideocapturer.h" |
| 44 | #include "talk/media/webrtc/webrtcvideoengine.h" |
| 45 | #include "talk/media/webrtc/webrtcvideoframe.h" |
| 46 | #include "talk/media/webrtc/webrtcvoiceengine.h" |
| 47 | #include "talk/session/media/mediasession.h" |
| 48 | #include "webrtc/system_wrappers/interface/trace.h" |
| 49 | |
| 50 | // Tests for the WebRtcVideoEngine/VideoChannel code. |
| 51 | |
| 52 | static const cricket::VideoCodec kVP8Codec720p(100, "VP8", 1280, 720, 30, 0); |
| 53 | static const cricket::VideoCodec kVP8Codec360p(100, "VP8", 640, 360, 30, 0); |
| 54 | static const cricket::VideoCodec kVP8Codec270p(100, "VP8", 480, 270, 30, 0); |
| 55 | static const cricket::VideoCodec kVP8Codec180p(100, "VP8", 320, 180, 30, 0); |
| 56 | |
| 57 | static const cricket::VideoCodec kVP8Codec(100, "VP8", 640, 400, 30, 0); |
| 58 | static const cricket::VideoCodec kRedCodec(101, "red", 0, 0, 0, 0); |
| 59 | static const cricket::VideoCodec kUlpFecCodec(102, "ulpfec", 0, 0, 0, 0); |
| 60 | static const cricket::VideoCodec* const kVideoCodecs[] = { |
| 61 | &kVP8Codec, |
| 62 | &kRedCodec, |
| 63 | &kUlpFecCodec |
| 64 | }; |
| 65 | |
| 66 | static const unsigned int kMinBandwidthKbps = 50; |
| 67 | static const unsigned int kStartBandwidthKbps = 300; |
| 68 | static const unsigned int kMaxBandwidthKbps = 2000; |
| 69 | |
| 70 | static const unsigned int kNumberOfTemporalLayers = 1; |
| 71 | |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 72 | static const uint32 kSsrcs1[] = {1}; |
| 73 | static const uint32 kSsrcs2[] = {1, 2}; |
| 74 | static const uint32 kSsrcs3[] = {1, 2, 3}; |
| 75 | static const uint32 kRtxSsrc1[] = {4}; |
| 76 | static const uint32 kRtxSsrcs3[] = {4, 5, 6}; |
| 77 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 78 | |
| 79 | class FakeViEWrapper : public cricket::ViEWrapper { |
| 80 | public: |
| 81 | explicit FakeViEWrapper(cricket::FakeWebRtcVideoEngine* engine) |
| 82 | : cricket::ViEWrapper(engine, // base |
| 83 | engine, // codec |
| 84 | engine, // capture |
| 85 | engine, // network |
| 86 | engine, // render |
| 87 | engine, // rtp |
| 88 | engine, // image |
| 89 | engine) { // external decoder |
| 90 | } |
| 91 | }; |
| 92 | |
| 93 | // Test fixture to test WebRtcVideoEngine with a fake webrtc::VideoEngine. |
| 94 | // Useful for testing failure paths. |
wu@webrtc.org | cadf904 | 2013-08-30 21:24:16 +0000 | [diff] [blame] | 95 | class WebRtcVideoEngineTestFake : public testing::Test, |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 96 | public sigslot::has_slots<> { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 97 | public: |
| 98 | WebRtcVideoEngineTestFake() |
| 99 | : vie_(kVideoCodecs, ARRAY_SIZE(kVideoCodecs)), |
| 100 | cpu_monitor_(new talk_base::FakeCpuMonitor( |
| 101 | talk_base::Thread::Current())), |
| 102 | engine_(NULL, // cricket::WebRtcVoiceEngine |
| 103 | new FakeViEWrapper(&vie_), cpu_monitor_), |
| 104 | channel_(NULL), |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 105 | voice_channel_(NULL), |
| 106 | last_error_(cricket::VideoMediaChannel::ERROR_NONE) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 107 | } |
| 108 | bool SetupEngine() { |
| 109 | bool result = engine_.Init(talk_base::Thread::Current()); |
| 110 | if (result) { |
| 111 | channel_ = engine_.CreateChannel(voice_channel_); |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 112 | channel_->SignalMediaError.connect(this, |
| 113 | &WebRtcVideoEngineTestFake::OnMediaError); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 114 | result = (channel_ != NULL); |
| 115 | } |
| 116 | return result; |
| 117 | } |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 118 | void OnMediaError(uint32 ssrc, cricket::VideoMediaChannel::Error error) { |
| 119 | last_error_ = error; |
| 120 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 121 | bool SendI420Frame(int width, int height) { |
| 122 | if (NULL == channel_) { |
| 123 | return false; |
| 124 | } |
| 125 | cricket::WebRtcVideoFrame frame; |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 126 | if (!frame.InitToBlack(width, height, 1, 1, 0, 0)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 127 | return false; |
| 128 | } |
| 129 | cricket::FakeVideoCapturer capturer; |
| 130 | channel_->SendFrame(&capturer, &frame); |
| 131 | return true; |
| 132 | } |
| 133 | bool SendI420ScreencastFrame(int width, int height) { |
| 134 | return SendI420ScreencastFrameWithTimestamp(width, height, 0); |
| 135 | } |
| 136 | bool SendI420ScreencastFrameWithTimestamp( |
| 137 | int width, int height, int64 timestamp) { |
| 138 | if (NULL == channel_) { |
| 139 | return false; |
| 140 | } |
| 141 | cricket::WebRtcVideoFrame frame; |
wu@webrtc.org | 9caf276 | 2013-12-11 18:25:07 +0000 | [diff] [blame] | 142 | if (!frame.InitToBlack(width, height, 1, 1, 0, 0)) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 143 | return false; |
| 144 | } |
| 145 | cricket::FakeVideoCapturer capturer; |
| 146 | capturer.SetScreencast(true); |
| 147 | channel_->SendFrame(&capturer, &frame); |
| 148 | return true; |
| 149 | } |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 150 | void VerifyCodecFeedbackParams(const cricket::VideoCodec& codec) { |
| 151 | EXPECT_TRUE(codec.HasFeedbackParam( |
| 152 | cricket::FeedbackParam(cricket::kRtcpFbParamNack, |
| 153 | cricket::kParamValueEmpty))); |
| 154 | EXPECT_TRUE(codec.HasFeedbackParam( |
| 155 | cricket::FeedbackParam(cricket::kRtcpFbParamNack, |
| 156 | cricket::kRtcpFbNackParamPli))); |
| 157 | EXPECT_TRUE(codec.HasFeedbackParam( |
| 158 | cricket::FeedbackParam(cricket::kRtcpFbParamRemb, |
| 159 | cricket::kParamValueEmpty))); |
| 160 | EXPECT_TRUE(codec.HasFeedbackParam( |
| 161 | cricket::FeedbackParam(cricket::kRtcpFbParamCcm, |
| 162 | cricket::kRtcpFbCcmParamFir))); |
| 163 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 164 | void VerifyVP8SendCodec(int channel_num, |
| 165 | unsigned int width, |
| 166 | unsigned int height, |
| 167 | unsigned int layers = 0, |
| 168 | unsigned int max_bitrate = kMaxBandwidthKbps, |
| 169 | unsigned int min_bitrate = kMinBandwidthKbps, |
| 170 | unsigned int start_bitrate = kStartBandwidthKbps, |
| 171 | unsigned int fps = 30, |
| 172 | unsigned int max_quantization = 0 |
| 173 | ) { |
| 174 | webrtc::VideoCodec gcodec; |
| 175 | EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec)); |
| 176 | |
| 177 | // Video codec properties. |
| 178 | EXPECT_EQ(webrtc::kVideoCodecVP8, gcodec.codecType); |
| 179 | EXPECT_STREQ("VP8", gcodec.plName); |
| 180 | EXPECT_EQ(100, gcodec.plType); |
| 181 | EXPECT_EQ(width, gcodec.width); |
| 182 | EXPECT_EQ(height, gcodec.height); |
| 183 | EXPECT_EQ(talk_base::_min(start_bitrate, max_bitrate), gcodec.startBitrate); |
| 184 | EXPECT_EQ(max_bitrate, gcodec.maxBitrate); |
| 185 | EXPECT_EQ(min_bitrate, gcodec.minBitrate); |
| 186 | EXPECT_EQ(fps, gcodec.maxFramerate); |
| 187 | // VP8 specific. |
| 188 | EXPECT_FALSE(gcodec.codecSpecific.VP8.pictureLossIndicationOn); |
| 189 | EXPECT_FALSE(gcodec.codecSpecific.VP8.feedbackModeOn); |
| 190 | EXPECT_EQ(webrtc::kComplexityNormal, gcodec.codecSpecific.VP8.complexity); |
| 191 | EXPECT_EQ(webrtc::kResilienceOff, gcodec.codecSpecific.VP8.resilience); |
| 192 | EXPECT_EQ(max_quantization, gcodec.qpMax); |
| 193 | } |
| 194 | virtual void TearDown() { |
| 195 | delete channel_; |
| 196 | engine_.Terminate(); |
| 197 | } |
| 198 | |
| 199 | protected: |
| 200 | cricket::FakeWebRtcVideoEngine vie_; |
| 201 | cricket::FakeWebRtcVideoDecoderFactory decoder_factory_; |
| 202 | cricket::FakeWebRtcVideoEncoderFactory encoder_factory_; |
| 203 | talk_base::FakeCpuMonitor* cpu_monitor_; |
| 204 | cricket::WebRtcVideoEngine engine_; |
| 205 | cricket::WebRtcVideoMediaChannel* channel_; |
| 206 | cricket::WebRtcVoiceMediaChannel* voice_channel_; |
wu@webrtc.org | d64719d | 2013-08-01 00:00:07 +0000 | [diff] [blame] | 207 | cricket::VideoMediaChannel::Error last_error_; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 208 | }; |
| 209 | |
| 210 | // Test fixtures to test WebRtcVideoEngine with a real webrtc::VideoEngine. |
| 211 | class WebRtcVideoEngineTest |
| 212 | : public VideoEngineTest<cricket::WebRtcVideoEngine> { |
| 213 | protected: |
| 214 | typedef VideoEngineTest<cricket::WebRtcVideoEngine> Base; |
| 215 | }; |
| 216 | class WebRtcVideoMediaChannelTest |
| 217 | : public VideoMediaChannelTest< |
| 218 | cricket::WebRtcVideoEngine, cricket::WebRtcVideoMediaChannel> { |
| 219 | protected: |
| 220 | typedef VideoMediaChannelTest<cricket::WebRtcVideoEngine, |
| 221 | cricket::WebRtcVideoMediaChannel> Base; |
| 222 | virtual cricket::VideoCodec DefaultCodec() { return kVP8Codec; } |
| 223 | virtual void SetUp() { |
| 224 | Base::SetUp(); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 225 | } |
| 226 | virtual void TearDown() { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 227 | Base::TearDown(); |
| 228 | } |
| 229 | }; |
| 230 | |
| 231 | ///////////////////////// |
| 232 | // Tests with fake ViE // |
| 233 | ///////////////////////// |
| 234 | |
| 235 | // Tests that our stub library "works". |
| 236 | TEST_F(WebRtcVideoEngineTestFake, StartupShutdown) { |
| 237 | EXPECT_FALSE(vie_.IsInited()); |
| 238 | EXPECT_TRUE(engine_.Init(talk_base::Thread::Current())); |
| 239 | EXPECT_TRUE(vie_.IsInited()); |
| 240 | engine_.Terminate(); |
| 241 | } |
| 242 | |
| 243 | // Tests that webrtc logs are logged when they should be. |
| 244 | TEST_F(WebRtcVideoEngineTest, WebRtcShouldLog) { |
| 245 | const char webrtc_log[] = "WebRtcVideoEngineTest.WebRtcShouldLog"; |
| 246 | EXPECT_TRUE(engine_.Init(talk_base::Thread::Current())); |
| 247 | engine_.SetLogging(talk_base::LS_INFO, ""); |
| 248 | std::string str; |
| 249 | talk_base::StringStream stream(str); |
| 250 | talk_base::LogMessage::AddLogToStream(&stream, talk_base::LS_INFO); |
| 251 | EXPECT_EQ(talk_base::LS_INFO, talk_base::LogMessage::GetLogToStream(&stream)); |
| 252 | webrtc::Trace::Add(webrtc::kTraceStateInfo, webrtc::kTraceUndefined, 0, |
| 253 | webrtc_log); |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 254 | talk_base::Thread::Current()->ProcessMessages(100); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 255 | talk_base::LogMessage::RemoveLogToStream(&stream); |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 256 | // Access |str| after LogMessage is done with it to avoid data racing. |
| 257 | EXPECT_NE(std::string::npos, str.find(webrtc_log)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | // Tests that webrtc logs are not logged when they should't be. |
| 261 | TEST_F(WebRtcVideoEngineTest, WebRtcShouldNotLog) { |
| 262 | const char webrtc_log[] = "WebRtcVideoEngineTest.WebRtcShouldNotLog"; |
| 263 | EXPECT_TRUE(engine_.Init(talk_base::Thread::Current())); |
| 264 | // WebRTC should never be logged lower than LS_INFO. |
| 265 | engine_.SetLogging(talk_base::LS_WARNING, ""); |
| 266 | std::string str; |
| 267 | talk_base::StringStream stream(str); |
| 268 | // Make sure that WebRTC is not logged, even at lowest severity |
| 269 | talk_base::LogMessage::AddLogToStream(&stream, talk_base::LS_SENSITIVE); |
| 270 | EXPECT_EQ(talk_base::LS_SENSITIVE, |
| 271 | talk_base::LogMessage::GetLogToStream(&stream)); |
| 272 | webrtc::Trace::Add(webrtc::kTraceStateInfo, webrtc::kTraceUndefined, 0, |
| 273 | webrtc_log); |
| 274 | talk_base::Thread::Current()->ProcessMessages(10); |
| 275 | EXPECT_EQ(std::string::npos, str.find(webrtc_log)); |
| 276 | talk_base::LogMessage::RemoveLogToStream(&stream); |
| 277 | } |
| 278 | |
| 279 | // Tests that we can create and destroy a channel. |
| 280 | TEST_F(WebRtcVideoEngineTestFake, CreateChannel) { |
| 281 | EXPECT_TRUE(engine_.Init(talk_base::Thread::Current())); |
| 282 | channel_ = engine_.CreateChannel(voice_channel_); |
| 283 | EXPECT_TRUE(channel_ != NULL); |
| 284 | EXPECT_EQ(1, engine_.GetNumOfChannels()); |
| 285 | delete channel_; |
| 286 | channel_ = NULL; |
| 287 | EXPECT_EQ(0, engine_.GetNumOfChannels()); |
| 288 | } |
| 289 | |
| 290 | // Tests that we properly handle failures in CreateChannel. |
| 291 | TEST_F(WebRtcVideoEngineTestFake, CreateChannelFail) { |
| 292 | vie_.set_fail_create_channel(true); |
| 293 | EXPECT_TRUE(engine_.Init(talk_base::Thread::Current())); |
| 294 | channel_ = engine_.CreateChannel(voice_channel_); |
| 295 | EXPECT_TRUE(channel_ == NULL); |
| 296 | } |
| 297 | |
| 298 | // Tests that we properly handle failures in AllocateExternalCaptureDevice. |
| 299 | TEST_F(WebRtcVideoEngineTestFake, AllocateExternalCaptureDeviceFail) { |
| 300 | vie_.set_fail_alloc_capturer(true); |
| 301 | EXPECT_TRUE(engine_.Init(talk_base::Thread::Current())); |
| 302 | channel_ = engine_.CreateChannel(voice_channel_); |
| 303 | EXPECT_TRUE(channel_ == NULL); |
| 304 | } |
| 305 | |
| 306 | // Test that we apply our default codecs properly. |
| 307 | TEST_F(WebRtcVideoEngineTestFake, SetSendCodecs) { |
| 308 | EXPECT_TRUE(SetupEngine()); |
| 309 | int channel_num = vie_.GetLastChannel(); |
| 310 | std::vector<cricket::VideoCodec> codecs(engine_.codecs()); |
| 311 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 312 | VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height); |
| 313 | EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num)); |
| 314 | EXPECT_FALSE(vie_.GetNackStatus(channel_num)); |
| 315 | // TODO(juberti): Check RTCP, PLI, TMMBR. |
| 316 | } |
| 317 | |
| 318 | TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMinMaxBitrate) { |
| 319 | EXPECT_TRUE(SetupEngine()); |
| 320 | int channel_num = vie_.GetLastChannel(); |
| 321 | std::vector<cricket::VideoCodec> codecs(engine_.codecs()); |
| 322 | codecs[0].params[cricket::kCodecParamMinBitrate] = "10"; |
| 323 | codecs[0].params[cricket::kCodecParamMaxBitrate] = "20"; |
| 324 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 325 | |
| 326 | VerifyVP8SendCodec( |
| 327 | channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20); |
| 328 | |
| 329 | cricket::VideoCodec codec; |
| 330 | EXPECT_TRUE(channel_->GetSendCodec(&codec)); |
| 331 | EXPECT_EQ("10", codec.params[cricket::kCodecParamMinBitrate]); |
| 332 | EXPECT_EQ("20", codec.params[cricket::kCodecParamMaxBitrate]); |
| 333 | } |
| 334 | |
| 335 | TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMinMaxBitrateInvalid) { |
| 336 | EXPECT_TRUE(SetupEngine()); |
| 337 | std::vector<cricket::VideoCodec> codecs(engine_.codecs()); |
| 338 | codecs[0].params[cricket::kCodecParamMinBitrate] = "30"; |
| 339 | codecs[0].params[cricket::kCodecParamMaxBitrate] = "20"; |
| 340 | EXPECT_FALSE(channel_->SetSendCodecs(codecs)); |
| 341 | } |
| 342 | |
| 343 | TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithLargeMinMaxBitrate) { |
| 344 | EXPECT_TRUE(SetupEngine()); |
| 345 | int channel_num = vie_.GetLastChannel(); |
| 346 | std::vector<cricket::VideoCodec> codecs(engine_.codecs()); |
| 347 | codecs[0].params[cricket::kCodecParamMinBitrate] = "1000"; |
| 348 | codecs[0].params[cricket::kCodecParamMaxBitrate] = "2000"; |
| 349 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 350 | |
| 351 | VerifyVP8SendCodec( |
| 352 | channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 1000, |
| 353 | 1000); |
| 354 | } |
| 355 | |
| 356 | TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsWithMaxQuantization) { |
| 357 | EXPECT_TRUE(SetupEngine()); |
| 358 | int channel_num = vie_.GetLastChannel(); |
| 359 | std::vector<cricket::VideoCodec> codecs(engine_.codecs()); |
| 360 | codecs[0].params[cricket::kCodecParamMaxQuantization] = "21"; |
| 361 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 362 | |
| 363 | VerifyVP8SendCodec( |
| 364 | channel_num, kVP8Codec.width, kVP8Codec.height, 0, 2000, 50, 300, |
| 365 | 30, 21); |
| 366 | |
| 367 | cricket::VideoCodec codec; |
| 368 | EXPECT_TRUE(channel_->GetSendCodec(&codec)); |
| 369 | EXPECT_EQ("21", codec.params[cricket::kCodecParamMaxQuantization]); |
| 370 | } |
| 371 | |
| 372 | TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithMaxBitrate) { |
| 373 | EXPECT_TRUE(SetupEngine()); |
| 374 | int channel_num = vie_.GetLastChannel(); |
| 375 | std::vector<cricket::VideoCodec> codecs(engine_.codecs()); |
| 376 | codecs[0].params[cricket::kCodecParamMinBitrate] = "10"; |
| 377 | codecs[0].params[cricket::kCodecParamMaxBitrate] = "20"; |
| 378 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 379 | |
| 380 | VerifyVP8SendCodec( |
| 381 | channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20); |
| 382 | |
| 383 | // Verify that max bitrate doesn't change after SetOptions(). |
| 384 | cricket::VideoOptions options; |
| 385 | options.video_noise_reduction.Set(true); |
| 386 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 387 | VerifyVP8SendCodec( |
| 388 | channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20); |
| 389 | |
| 390 | options.video_noise_reduction.Set(false); |
| 391 | options.conference_mode.Set(false); |
| 392 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 393 | VerifyVP8SendCodec( |
| 394 | channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20); |
| 395 | } |
| 396 | |
wu@webrtc.org | cecfd18 | 2013-10-30 05:18:12 +0000 | [diff] [blame] | 397 | TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithLoweredBitrate) { |
| 398 | EXPECT_TRUE(SetupEngine()); |
| 399 | int channel_num = vie_.GetLastChannel(); |
| 400 | std::vector<cricket::VideoCodec> codecs(engine_.codecs()); |
| 401 | codecs[0].params[cricket::kCodecParamMinBitrate] = "50"; |
| 402 | codecs[0].params[cricket::kCodecParamMaxBitrate] = "100"; |
| 403 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 404 | |
| 405 | VerifyVP8SendCodec( |
| 406 | channel_num, kVP8Codec.width, kVP8Codec.height, 0, 100, 50, 100); |
| 407 | |
| 408 | // Verify that min bitrate changes after SetOptions(). |
| 409 | cricket::VideoOptions options; |
| 410 | options.lower_min_bitrate.Set(true); |
| 411 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 412 | VerifyVP8SendCodec( |
| 413 | channel_num, kVP8Codec.width, kVP8Codec.height, 0, 100, 30, 100); |
| 414 | } |
| 415 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 416 | TEST_F(WebRtcVideoEngineTestFake, MaxBitrateResetWithConferenceMode) { |
| 417 | EXPECT_TRUE(SetupEngine()); |
| 418 | int channel_num = vie_.GetLastChannel(); |
| 419 | std::vector<cricket::VideoCodec> codecs(engine_.codecs()); |
| 420 | codecs[0].params[cricket::kCodecParamMinBitrate] = "10"; |
| 421 | codecs[0].params[cricket::kCodecParamMaxBitrate] = "20"; |
| 422 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 423 | |
| 424 | VerifyVP8SendCodec( |
| 425 | channel_num, kVP8Codec.width, kVP8Codec.height, 0, 20, 10, 20); |
| 426 | |
| 427 | cricket::VideoOptions options; |
| 428 | options.conference_mode.Set(true); |
| 429 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 430 | options.conference_mode.Set(false); |
| 431 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 432 | VerifyVP8SendCodec( |
| 433 | channel_num, kVP8Codec.width, kVP8Codec.height, 0, |
| 434 | kMaxBandwidthKbps, 10, 20); |
| 435 | } |
| 436 | |
| 437 | // Verify the current send bitrate is used as start bitrate when reconfiguring |
| 438 | // the send codec. |
| 439 | TEST_F(WebRtcVideoEngineTestFake, StartSendBitrate) { |
| 440 | EXPECT_TRUE(SetupEngine()); |
| 441 | EXPECT_TRUE(channel_->AddSendStream( |
| 442 | cricket::StreamParams::CreateLegacy(1))); |
| 443 | int send_channel = vie_.GetLastChannel(); |
| 444 | cricket::VideoCodec codec(kVP8Codec); |
| 445 | std::vector<cricket::VideoCodec> codec_list; |
| 446 | codec_list.push_back(codec); |
| 447 | EXPECT_TRUE(channel_->SetSendCodecs(codec_list)); |
| 448 | const unsigned int kVideoMaxSendBitrateKbps = 2000; |
| 449 | const unsigned int kVideoMinSendBitrateKbps = 50; |
| 450 | const unsigned int kVideoDefaultStartSendBitrateKbps = 300; |
| 451 | VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0, |
| 452 | kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps, |
| 453 | kVideoDefaultStartSendBitrateKbps); |
| 454 | EXPECT_EQ(0, vie_.StartSend(send_channel)); |
| 455 | |
| 456 | // Increase the send bitrate and verify it is used as start bitrate. |
| 457 | const unsigned int kVideoSendBitrateBps = 768000; |
| 458 | vie_.SetSendBitrates(send_channel, kVideoSendBitrateBps, 0, 0); |
| 459 | EXPECT_TRUE(channel_->SetSendCodecs(codec_list)); |
| 460 | VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0, |
| 461 | kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps, |
| 462 | kVideoSendBitrateBps / 1000); |
| 463 | |
| 464 | // Never set a start bitrate higher than the max bitrate. |
| 465 | vie_.SetSendBitrates(send_channel, kVideoMaxSendBitrateKbps + 500, 0, 0); |
| 466 | EXPECT_TRUE(channel_->SetSendCodecs(codec_list)); |
| 467 | VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0, |
| 468 | kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps, |
| 469 | kVideoDefaultStartSendBitrateKbps); |
| 470 | |
| 471 | // Use the default start bitrate if the send bitrate is lower. |
| 472 | vie_.SetSendBitrates(send_channel, kVideoDefaultStartSendBitrateKbps - 50, 0, |
| 473 | 0); |
| 474 | EXPECT_TRUE(channel_->SetSendCodecs(codec_list)); |
| 475 | VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0, |
| 476 | kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps, |
| 477 | kVideoDefaultStartSendBitrateKbps); |
| 478 | } |
| 479 | |
| 480 | |
| 481 | // Test that we constrain send codecs properly. |
| 482 | TEST_F(WebRtcVideoEngineTestFake, ConstrainSendCodecs) { |
| 483 | EXPECT_TRUE(SetupEngine()); |
| 484 | int channel_num = vie_.GetLastChannel(); |
| 485 | |
| 486 | // Set max settings of 640x400x30. |
| 487 | EXPECT_TRUE(engine_.SetDefaultEncoderConfig( |
| 488 | cricket::VideoEncoderConfig(kVP8Codec))); |
| 489 | |
| 490 | // Send codec format bigger than max setting. |
| 491 | cricket::VideoCodec codec(kVP8Codec); |
| 492 | codec.width = 1280; |
| 493 | codec.height = 800; |
| 494 | codec.framerate = 60; |
| 495 | std::vector<cricket::VideoCodec> codec_list; |
| 496 | codec_list.push_back(codec); |
| 497 | |
| 498 | // Set send codec and verify codec has been constrained. |
| 499 | EXPECT_TRUE(channel_->SetSendCodecs(codec_list)); |
| 500 | VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height); |
| 501 | } |
| 502 | |
| 503 | // Test that SetSendCodecs rejects bad format. |
| 504 | TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsRejectBadFormat) { |
| 505 | EXPECT_TRUE(SetupEngine()); |
| 506 | int channel_num = vie_.GetLastChannel(); |
| 507 | |
| 508 | // Set w = 0. |
| 509 | cricket::VideoCodec codec(kVP8Codec); |
| 510 | codec.width = 0; |
| 511 | std::vector<cricket::VideoCodec> codec_list; |
| 512 | codec_list.push_back(codec); |
| 513 | |
| 514 | // Verify SetSendCodecs failed and send codec is not changed on engine. |
| 515 | EXPECT_FALSE(channel_->SetSendCodecs(codec_list)); |
| 516 | webrtc::VideoCodec gcodec; |
| 517 | // Set plType to something other than the value to test against ensuring |
| 518 | // that failure will happen if it is not changed. |
| 519 | gcodec.plType = 1; |
| 520 | EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec)); |
| 521 | EXPECT_EQ(0, gcodec.plType); |
| 522 | |
| 523 | // Set h = 0. |
| 524 | codec_list[0].width = 640; |
| 525 | codec_list[0].height = 0; |
| 526 | |
| 527 | // Verify SetSendCodecs failed and send codec is not changed on engine. |
| 528 | EXPECT_FALSE(channel_->SetSendCodecs(codec_list)); |
| 529 | // Set plType to something other than the value to test against ensuring |
| 530 | // that failure will happen if it is not changed. |
| 531 | gcodec.plType = 1; |
| 532 | EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec)); |
| 533 | EXPECT_EQ(0, gcodec.plType); |
| 534 | } |
| 535 | |
| 536 | // Test that SetSendCodecs rejects bad codec. |
| 537 | TEST_F(WebRtcVideoEngineTestFake, SetSendCodecsRejectBadCodec) { |
| 538 | EXPECT_TRUE(SetupEngine()); |
| 539 | int channel_num = vie_.GetLastChannel(); |
| 540 | |
| 541 | // Set bad codec name. |
| 542 | cricket::VideoCodec codec(kVP8Codec); |
| 543 | codec.name = "bad"; |
| 544 | std::vector<cricket::VideoCodec> codec_list; |
| 545 | codec_list.push_back(codec); |
| 546 | |
| 547 | // Verify SetSendCodecs failed and send codec is not changed on engine. |
| 548 | EXPECT_FALSE(channel_->SetSendCodecs(codec_list)); |
| 549 | webrtc::VideoCodec gcodec; |
| 550 | // Set plType to something other than the value to test against ensuring |
| 551 | // that failure will happen if it is not changed. |
| 552 | gcodec.plType = 1; |
| 553 | EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec)); |
| 554 | EXPECT_EQ(0, gcodec.plType); |
| 555 | } |
| 556 | |
| 557 | // Test that vie send codec is reset on new video frame size. |
| 558 | TEST_F(WebRtcVideoEngineTestFake, ResetVieSendCodecOnNewFrameSize) { |
| 559 | EXPECT_TRUE(SetupEngine()); |
| 560 | int channel_num = vie_.GetLastChannel(); |
| 561 | |
| 562 | // Set send codec. |
| 563 | std::vector<cricket::VideoCodec> codec_list; |
| 564 | codec_list.push_back(kVP8Codec); |
| 565 | EXPECT_TRUE(channel_->SetSendCodecs(codec_list)); |
| 566 | EXPECT_TRUE(channel_->AddSendStream( |
| 567 | cricket::StreamParams::CreateLegacy(123))); |
| 568 | EXPECT_TRUE(channel_->SetSend(true)); |
| 569 | |
| 570 | // Capture a smaller frame and verify vie send codec has been reset to |
| 571 | // the new size. |
| 572 | SendI420Frame(kVP8Codec.width / 2, kVP8Codec.height / 2); |
| 573 | VerifyVP8SendCodec(channel_num, kVP8Codec.width / 2, kVP8Codec.height / 2); |
| 574 | |
| 575 | // Capture a frame bigger than send_codec_ and verify vie send codec has been |
| 576 | // reset (and clipped) to send_codec_. |
| 577 | SendI420Frame(kVP8Codec.width * 2, kVP8Codec.height * 2); |
| 578 | VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height); |
| 579 | } |
| 580 | |
| 581 | // Test that we set our inbound codecs properly. |
| 582 | TEST_F(WebRtcVideoEngineTestFake, SetRecvCodecs) { |
| 583 | EXPECT_TRUE(SetupEngine()); |
| 584 | int channel_num = vie_.GetLastChannel(); |
| 585 | |
| 586 | std::vector<cricket::VideoCodec> codecs; |
| 587 | codecs.push_back(kVP8Codec); |
| 588 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 589 | |
| 590 | webrtc::VideoCodec wcodec; |
| 591 | EXPECT_TRUE(engine_.ConvertFromCricketVideoCodec(kVP8Codec, &wcodec)); |
| 592 | EXPECT_TRUE(vie_.ReceiveCodecRegistered(channel_num, wcodec)); |
| 593 | } |
| 594 | |
| 595 | // Test that channel connects and disconnects external capturer correctly. |
| 596 | TEST_F(WebRtcVideoEngineTestFake, HasExternalCapturer) { |
| 597 | EXPECT_TRUE(SetupEngine()); |
| 598 | int channel_num = vie_.GetLastChannel(); |
| 599 | |
| 600 | EXPECT_EQ(1, vie_.GetNumCapturers()); |
| 601 | int capture_id = vie_.GetCaptureId(channel_num); |
| 602 | EXPECT_EQ(channel_num, vie_.GetCaptureChannelId(capture_id)); |
| 603 | |
| 604 | // Delete the channel should disconnect the capturer. |
| 605 | delete channel_; |
| 606 | channel_ = NULL; |
| 607 | EXPECT_EQ(0, vie_.GetNumCapturers()); |
| 608 | } |
| 609 | |
| 610 | // Test that channel adds and removes renderer correctly. |
| 611 | TEST_F(WebRtcVideoEngineTestFake, HasRenderer) { |
| 612 | EXPECT_TRUE(SetupEngine()); |
| 613 | int channel_num = vie_.GetLastChannel(); |
| 614 | |
| 615 | EXPECT_TRUE(vie_.GetHasRenderer(channel_num)); |
| 616 | EXPECT_FALSE(vie_.GetRenderStarted(channel_num)); |
| 617 | } |
| 618 | |
| 619 | // Test that rtcp is enabled on the channel. |
| 620 | TEST_F(WebRtcVideoEngineTestFake, RtcpEnabled) { |
| 621 | EXPECT_TRUE(SetupEngine()); |
| 622 | int channel_num = vie_.GetLastChannel(); |
| 623 | EXPECT_EQ(webrtc::kRtcpCompound_RFC4585, vie_.GetRtcpStatus(channel_num)); |
| 624 | } |
| 625 | |
| 626 | // Test that key frame request method is set on the channel. |
| 627 | TEST_F(WebRtcVideoEngineTestFake, KeyFrameRequestEnabled) { |
| 628 | EXPECT_TRUE(SetupEngine()); |
| 629 | int channel_num = vie_.GetLastChannel(); |
| 630 | EXPECT_EQ(webrtc::kViEKeyFrameRequestPliRtcp, |
| 631 | vie_.GetKeyFrameRequestMethod(channel_num)); |
| 632 | } |
| 633 | |
| 634 | // Test that remb receive and send is enabled for the default channel in a 1:1 |
| 635 | // call. |
| 636 | TEST_F(WebRtcVideoEngineTestFake, RembEnabled) { |
| 637 | EXPECT_TRUE(SetupEngine()); |
| 638 | int channel_num = vie_.GetLastChannel(); |
| 639 | EXPECT_TRUE(channel_->AddSendStream( |
| 640 | cricket::StreamParams::CreateLegacy(1))); |
| 641 | EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
| 642 | EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num)); |
| 643 | EXPECT_TRUE(channel_->SetSend(true)); |
| 644 | EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num)); |
| 645 | EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num)); |
| 646 | } |
| 647 | |
| 648 | // When in conference mode, test that remb is enabled on a receive channel but |
| 649 | // not for the default channel and that it uses the default channel for sending |
| 650 | // remb packets. |
| 651 | TEST_F(WebRtcVideoEngineTestFake, RembEnabledOnReceiveChannels) { |
| 652 | EXPECT_TRUE(SetupEngine()); |
| 653 | int default_channel = vie_.GetLastChannel(); |
| 654 | cricket::VideoOptions options; |
| 655 | options.conference_mode.Set(true); |
| 656 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 657 | EXPECT_TRUE(channel_->AddSendStream( |
| 658 | cricket::StreamParams::CreateLegacy(1))); |
| 659 | EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
| 660 | EXPECT_TRUE(vie_.GetRembStatusBwPartition(default_channel)); |
| 661 | EXPECT_TRUE(vie_.GetRembStatusContribute(default_channel)); |
| 662 | EXPECT_TRUE(channel_->SetSend(true)); |
| 663 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
| 664 | int new_channel_num = vie_.GetLastChannel(); |
| 665 | EXPECT_NE(default_channel, new_channel_num); |
| 666 | |
| 667 | EXPECT_TRUE(vie_.GetRembStatusBwPartition(default_channel)); |
| 668 | EXPECT_TRUE(vie_.GetRembStatusContribute(default_channel)); |
| 669 | EXPECT_FALSE(vie_.GetRembStatusBwPartition(new_channel_num)); |
| 670 | EXPECT_TRUE(vie_.GetRembStatusContribute(new_channel_num)); |
| 671 | } |
| 672 | |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 673 | TEST_F(WebRtcVideoEngineTestFake, RecvStreamWithRtx) { |
| 674 | EXPECT_TRUE(SetupEngine()); |
| 675 | int default_channel = vie_.GetLastChannel(); |
| 676 | cricket::VideoOptions options; |
| 677 | options.conference_mode.Set(true); |
| 678 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 679 | EXPECT_TRUE(channel_->AddSendStream( |
| 680 | cricket::CreateSimWithRtxStreamParams("cname", |
| 681 | MAKE_VECTOR(kSsrcs3), |
| 682 | MAKE_VECTOR(kRtxSsrcs3)))); |
| 683 | EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
| 684 | EXPECT_TRUE(channel_->SetSend(true)); |
| 685 | EXPECT_TRUE(channel_->AddRecvStream( |
| 686 | cricket::CreateSimWithRtxStreamParams("cname", |
| 687 | MAKE_VECTOR(kSsrcs1), |
| 688 | MAKE_VECTOR(kRtxSsrc1)))); |
| 689 | int new_channel_num = vie_.GetLastChannel(); |
| 690 | EXPECT_NE(default_channel, new_channel_num); |
| 691 | EXPECT_EQ(4, vie_.GetRemoteRtxSsrc(new_channel_num)); |
| 692 | } |
| 693 | |
| 694 | TEST_F(WebRtcVideoEngineTestFake, RecvStreamNoRtx) { |
| 695 | EXPECT_TRUE(SetupEngine()); |
| 696 | int default_channel = vie_.GetLastChannel(); |
| 697 | cricket::VideoOptions options; |
| 698 | options.conference_mode.Set(true); |
| 699 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 700 | EXPECT_TRUE(channel_->AddSendStream( |
| 701 | cricket::CreateSimWithRtxStreamParams("cname", |
| 702 | MAKE_VECTOR(kSsrcs3), |
| 703 | MAKE_VECTOR(kRtxSsrcs3)))); |
| 704 | EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
| 705 | EXPECT_TRUE(channel_->SetSend(true)); |
| 706 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
| 707 | int new_channel_num = vie_.GetLastChannel(); |
| 708 | EXPECT_NE(default_channel, new_channel_num); |
| 709 | EXPECT_EQ(-1, vie_.GetRemoteRtxSsrc(new_channel_num)); |
| 710 | } |
| 711 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 712 | // Test support for RTP timestamp offset header extension. |
| 713 | TEST_F(WebRtcVideoEngineTestFake, RtpTimestampOffsetHeaderExtensions) { |
| 714 | EXPECT_TRUE(SetupEngine()); |
| 715 | int channel_num = vie_.GetLastChannel(); |
| 716 | cricket::VideoOptions options; |
| 717 | options.conference_mode.Set(true); |
| 718 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 719 | |
| 720 | // Verify extensions are off by default. |
| 721 | EXPECT_EQ(0, vie_.GetSendRtpTimestampOffsetExtensionId(channel_num)); |
| 722 | EXPECT_EQ(0, vie_.GetReceiveRtpTimestampOffsetExtensionId(channel_num)); |
| 723 | |
| 724 | // Enable RTP timestamp extension. |
| 725 | const int id = 14; |
| 726 | std::vector<cricket::RtpHeaderExtension> extensions; |
| 727 | extensions.push_back(cricket::RtpHeaderExtension( |
| 728 | "urn:ietf:params:rtp-hdrext:toffset", id)); |
| 729 | |
| 730 | // Verify the send extension id. |
| 731 | EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions)); |
| 732 | EXPECT_EQ(id, vie_.GetSendRtpTimestampOffsetExtensionId(channel_num)); |
| 733 | |
| 734 | // Remove the extension id. |
| 735 | std::vector<cricket::RtpHeaderExtension> empty_extensions; |
| 736 | EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(empty_extensions)); |
| 737 | EXPECT_EQ(0, vie_.GetSendRtpTimestampOffsetExtensionId(channel_num)); |
| 738 | |
| 739 | // Verify receive extension id. |
| 740 | EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions)); |
| 741 | EXPECT_EQ(id, vie_.GetReceiveRtpTimestampOffsetExtensionId(channel_num)); |
| 742 | |
| 743 | // Add a new receive stream and verify the extension is set. |
| 744 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
| 745 | int new_channel_num = vie_.GetLastChannel(); |
| 746 | EXPECT_NE(channel_num, new_channel_num); |
| 747 | EXPECT_EQ(id, vie_.GetReceiveRtpTimestampOffsetExtensionId(new_channel_num)); |
| 748 | |
| 749 | // Remove the extension id. |
| 750 | EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(empty_extensions)); |
| 751 | EXPECT_EQ(0, vie_.GetReceiveRtpTimestampOffsetExtensionId(channel_num)); |
| 752 | EXPECT_EQ(0, vie_.GetReceiveRtpTimestampOffsetExtensionId(new_channel_num)); |
| 753 | } |
| 754 | |
| 755 | // Test support for absolute send time header extension. |
| 756 | TEST_F(WebRtcVideoEngineTestFake, AbsoluteSendTimeHeaderExtensions) { |
| 757 | EXPECT_TRUE(SetupEngine()); |
| 758 | int channel_num = vie_.GetLastChannel(); |
| 759 | cricket::VideoOptions options; |
| 760 | options.conference_mode.Set(true); |
| 761 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 762 | |
| 763 | // Verify extensions are off by default. |
| 764 | EXPECT_EQ(0, vie_.GetSendAbsoluteSendTimeExtensionId(channel_num)); |
| 765 | EXPECT_EQ(0, vie_.GetReceiveAbsoluteSendTimeExtensionId(channel_num)); |
| 766 | |
| 767 | // Enable RTP timestamp extension. |
| 768 | const int id = 12; |
| 769 | std::vector<cricket::RtpHeaderExtension> extensions; |
| 770 | extensions.push_back(cricket::RtpHeaderExtension( |
| 771 | "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time", id)); |
| 772 | |
| 773 | // Verify the send extension id. |
| 774 | EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions)); |
| 775 | EXPECT_EQ(id, vie_.GetSendAbsoluteSendTimeExtensionId(channel_num)); |
| 776 | |
| 777 | // Remove the extension id. |
| 778 | std::vector<cricket::RtpHeaderExtension> empty_extensions; |
| 779 | EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(empty_extensions)); |
| 780 | EXPECT_EQ(0, vie_.GetSendAbsoluteSendTimeExtensionId(channel_num)); |
| 781 | |
| 782 | // Verify receive extension id. |
| 783 | EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions)); |
| 784 | EXPECT_EQ(id, vie_.GetReceiveAbsoluteSendTimeExtensionId(channel_num)); |
| 785 | |
| 786 | // Add a new receive stream and verify the extension is set. |
| 787 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
| 788 | int new_channel_num = vie_.GetLastChannel(); |
| 789 | EXPECT_NE(channel_num, new_channel_num); |
| 790 | EXPECT_EQ(id, vie_.GetReceiveAbsoluteSendTimeExtensionId(new_channel_num)); |
| 791 | |
| 792 | // Remove the extension id. |
| 793 | EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(empty_extensions)); |
| 794 | EXPECT_EQ(0, vie_.GetReceiveAbsoluteSendTimeExtensionId(channel_num)); |
| 795 | EXPECT_EQ(0, vie_.GetReceiveAbsoluteSendTimeExtensionId(new_channel_num)); |
| 796 | } |
| 797 | |
| 798 | TEST_F(WebRtcVideoEngineTestFake, LeakyBucketTest) { |
| 799 | EXPECT_TRUE(SetupEngine()); |
| 800 | |
| 801 | // Verify this is off by default. |
| 802 | EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1))); |
| 803 | int first_send_channel = vie_.GetLastChannel(); |
| 804 | EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(first_send_channel)); |
| 805 | |
| 806 | // Enable the experiment and verify. |
| 807 | cricket::VideoOptions options; |
| 808 | options.conference_mode.Set(true); |
| 809 | options.video_leaky_bucket.Set(true); |
| 810 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 811 | EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel)); |
| 812 | |
| 813 | // Add a receive channel and verify leaky bucket isn't enabled. |
| 814 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
| 815 | int recv_channel_num = vie_.GetLastChannel(); |
| 816 | EXPECT_NE(first_send_channel, recv_channel_num); |
| 817 | EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(recv_channel_num)); |
| 818 | |
| 819 | // Add a new send stream and verify leaky bucket is enabled from start. |
| 820 | EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3))); |
| 821 | int second_send_channel = vie_.GetLastChannel(); |
| 822 | EXPECT_NE(first_send_channel, second_send_channel); |
| 823 | EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(second_send_channel)); |
| 824 | } |
| 825 | |
| 826 | TEST_F(WebRtcVideoEngineTestFake, BufferedModeLatency) { |
| 827 | EXPECT_TRUE(SetupEngine()); |
| 828 | |
| 829 | // Verify this is off by default. |
| 830 | EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1))); |
| 831 | int first_send_channel = vie_.GetLastChannel(); |
| 832 | EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel)); |
| 833 | EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel)); |
| 834 | |
| 835 | // Enable the experiment and verify. The default channel will have both |
| 836 | // sender and receiver buffered mode enabled. |
| 837 | cricket::VideoOptions options; |
| 838 | options.conference_mode.Set(true); |
| 839 | options.buffered_mode_latency.Set(100); |
| 840 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 841 | EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel)); |
| 842 | EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel)); |
| 843 | |
| 844 | // Add a receive channel and verify sender buffered mode isn't enabled. |
| 845 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(2))); |
| 846 | int recv_channel_num = vie_.GetLastChannel(); |
| 847 | EXPECT_NE(first_send_channel, recv_channel_num); |
| 848 | EXPECT_EQ(0, vie_.GetSenderTargetDelay(recv_channel_num)); |
| 849 | EXPECT_EQ(100, vie_.GetReceiverTargetDelay(recv_channel_num)); |
| 850 | |
| 851 | // Add a new send stream and verify sender buffered mode is enabled. |
| 852 | EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(3))); |
| 853 | int second_send_channel = vie_.GetLastChannel(); |
| 854 | EXPECT_NE(first_send_channel, second_send_channel); |
| 855 | EXPECT_EQ(100, vie_.GetSenderTargetDelay(second_send_channel)); |
| 856 | EXPECT_EQ(0, vie_.GetReceiverTargetDelay(second_send_channel)); |
| 857 | |
| 858 | // Disable sender buffered mode and verify. |
| 859 | options.buffered_mode_latency.Set(cricket::kBufferedModeDisabled); |
| 860 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 861 | EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel)); |
| 862 | EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel)); |
| 863 | EXPECT_EQ(0, vie_.GetSenderTargetDelay(second_send_channel)); |
| 864 | EXPECT_EQ(0, vie_.GetReceiverTargetDelay(second_send_channel)); |
| 865 | EXPECT_EQ(0, vie_.GetSenderTargetDelay(recv_channel_num)); |
| 866 | EXPECT_EQ(0, vie_.GetReceiverTargetDelay(recv_channel_num)); |
| 867 | } |
| 868 | |
| 869 | TEST_F(WebRtcVideoEngineTestFake, AdditiveVideoOptions) { |
| 870 | EXPECT_TRUE(SetupEngine()); |
| 871 | |
| 872 | EXPECT_TRUE(channel_->AddSendStream(cricket::StreamParams::CreateLegacy(1))); |
| 873 | int first_send_channel = vie_.GetLastChannel(); |
| 874 | EXPECT_EQ(0, vie_.GetSenderTargetDelay(first_send_channel)); |
| 875 | EXPECT_EQ(0, vie_.GetReceiverTargetDelay(first_send_channel)); |
| 876 | |
| 877 | cricket::VideoOptions options1; |
| 878 | options1.buffered_mode_latency.Set(100); |
| 879 | EXPECT_TRUE(channel_->SetOptions(options1)); |
| 880 | EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel)); |
| 881 | EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel)); |
| 882 | EXPECT_FALSE(vie_.GetTransmissionSmoothingStatus(first_send_channel)); |
| 883 | |
| 884 | cricket::VideoOptions options2; |
| 885 | options2.video_leaky_bucket.Set(true); |
| 886 | EXPECT_TRUE(channel_->SetOptions(options2)); |
| 887 | EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel)); |
| 888 | // The buffered_mode_latency still takes effect. |
| 889 | EXPECT_EQ(100, vie_.GetSenderTargetDelay(first_send_channel)); |
| 890 | EXPECT_EQ(100, vie_.GetReceiverTargetDelay(first_send_channel)); |
| 891 | |
| 892 | options1.buffered_mode_latency.Set(50); |
| 893 | EXPECT_TRUE(channel_->SetOptions(options1)); |
| 894 | EXPECT_EQ(50, vie_.GetSenderTargetDelay(first_send_channel)); |
| 895 | EXPECT_EQ(50, vie_.GetReceiverTargetDelay(first_send_channel)); |
| 896 | // The video_leaky_bucket still takes effect. |
| 897 | EXPECT_TRUE(vie_.GetTransmissionSmoothingStatus(first_send_channel)); |
| 898 | } |
| 899 | |
| 900 | // Test that AddRecvStream doesn't create new channel for 1:1 call. |
| 901 | TEST_F(WebRtcVideoEngineTestFake, AddRecvStream1On1) { |
| 902 | EXPECT_TRUE(SetupEngine()); |
| 903 | int channel_num = vie_.GetLastChannel(); |
| 904 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
| 905 | EXPECT_EQ(channel_num, vie_.GetLastChannel()); |
| 906 | } |
| 907 | |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 908 | // Test that NACK, PLI and REMB are enabled for internal codec. |
| 909 | TEST_F(WebRtcVideoEngineTestFake, InternalCodecFeedbackParams) { |
| 910 | EXPECT_TRUE(SetupEngine()); |
| 911 | |
| 912 | std::vector<cricket::VideoCodec> codecs(engine_.codecs()); |
| 913 | // Vp8 will appear at the beginning. |
| 914 | size_t pos = 0; |
| 915 | EXPECT_EQ("VP8", codecs[pos].name); |
| 916 | VerifyCodecFeedbackParams(codecs[pos]); |
| 917 | } |
| 918 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 919 | // Test that AddRecvStream doesn't change remb for 1:1 call. |
| 920 | TEST_F(WebRtcVideoEngineTestFake, NoRembChangeAfterAddRecvStream) { |
| 921 | EXPECT_TRUE(SetupEngine()); |
| 922 | int channel_num = vie_.GetLastChannel(); |
| 923 | EXPECT_TRUE(channel_->AddSendStream( |
| 924 | cricket::StreamParams::CreateLegacy(1))); |
| 925 | EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
| 926 | EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num)); |
| 927 | EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num)); |
| 928 | EXPECT_TRUE(channel_->SetSend(true)); |
| 929 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
| 930 | EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num)); |
| 931 | EXPECT_TRUE(vie_.GetRembStatusContribute(channel_num)); |
| 932 | } |
| 933 | |
| 934 | // Verify default REMB setting and that it can be turned on and off. |
| 935 | TEST_F(WebRtcVideoEngineTestFake, RembOnOff) { |
| 936 | EXPECT_TRUE(SetupEngine()); |
| 937 | int channel_num = vie_.GetLastChannel(); |
| 938 | // Verify REMB sending is always off by default. |
| 939 | EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num)); |
| 940 | |
| 941 | // Verify that REMB is turned on when setting default codecs since the |
| 942 | // default codecs have REMB enabled. |
| 943 | EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
| 944 | EXPECT_TRUE(vie_.GetRembStatusBwPartition(channel_num)); |
| 945 | |
| 946 | // Verify that REMB is turned off when codecs without REMB are set. |
| 947 | std::vector<cricket::VideoCodec> codecs = engine_.codecs(); |
| 948 | // Clearing the codecs' FeedbackParams and setting send codecs should disable |
| 949 | // REMB. |
| 950 | for (std::vector<cricket::VideoCodec>::iterator iter = codecs.begin(); |
| 951 | iter != codecs.end(); ++iter) { |
| 952 | // Intersecting with empty will clear the FeedbackParams. |
| 953 | cricket::FeedbackParams empty_params; |
| 954 | iter->feedback_params.Intersect(empty_params); |
| 955 | EXPECT_TRUE(iter->feedback_params.params().empty()); |
| 956 | } |
| 957 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 958 | EXPECT_FALSE(vie_.GetRembStatusBwPartition(channel_num)); |
| 959 | } |
| 960 | |
| 961 | // Test that nack is enabled on the channel if we don't offer red/fec. |
| 962 | TEST_F(WebRtcVideoEngineTestFake, NackEnabled) { |
| 963 | EXPECT_TRUE(SetupEngine()); |
| 964 | int channel_num = vie_.GetLastChannel(); |
| 965 | std::vector<cricket::VideoCodec> codecs(engine_.codecs()); |
| 966 | codecs.resize(1); // toss out red and ulpfec |
| 967 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 968 | EXPECT_TRUE(vie_.GetNackStatus(channel_num)); |
| 969 | } |
| 970 | |
| 971 | // Test that we enable hybrid NACK FEC mode. |
| 972 | TEST_F(WebRtcVideoEngineTestFake, HybridNackFec) { |
| 973 | EXPECT_TRUE(SetupEngine()); |
| 974 | int channel_num = vie_.GetLastChannel(); |
| 975 | EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs())); |
| 976 | EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
| 977 | EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num)); |
| 978 | EXPECT_FALSE(vie_.GetNackStatus(channel_num)); |
| 979 | } |
| 980 | |
| 981 | // Test that we enable hybrid NACK FEC mode when calling SetSendCodecs and |
| 982 | // SetReceiveCodecs in reversed order. |
| 983 | TEST_F(WebRtcVideoEngineTestFake, HybridNackFecReversedOrder) { |
| 984 | EXPECT_TRUE(SetupEngine()); |
| 985 | int channel_num = vie_.GetLastChannel(); |
| 986 | EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
| 987 | EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs())); |
| 988 | EXPECT_TRUE(vie_.GetHybridNackFecStatus(channel_num)); |
| 989 | EXPECT_FALSE(vie_.GetNackStatus(channel_num)); |
| 990 | } |
| 991 | |
| 992 | // Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if |
| 993 | // red/fec is offered as receive codec. |
| 994 | TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInterop) { |
| 995 | EXPECT_TRUE(SetupEngine()); |
| 996 | int channel_num = vie_.GetLastChannel(); |
| 997 | std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs()); |
| 998 | std::vector<cricket::VideoCodec> send_codecs(engine_.codecs()); |
| 999 | // Only add VP8 as send codec. |
| 1000 | send_codecs.resize(1); |
| 1001 | EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs)); |
| 1002 | EXPECT_TRUE(channel_->SetSendCodecs(send_codecs)); |
| 1003 | EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num)); |
| 1004 | EXPECT_TRUE(vie_.GetNackStatus(channel_num)); |
| 1005 | } |
| 1006 | |
| 1007 | // Test NACK vs Hybrid NACK/FEC interop call setup, i.e. only use NACK even if |
| 1008 | // red/fec is offered as receive codec. Call order reversed compared to |
| 1009 | // VideoProtectionInterop. |
| 1010 | TEST_F(WebRtcVideoEngineTestFake, VideoProtectionInteropReversed) { |
| 1011 | EXPECT_TRUE(SetupEngine()); |
| 1012 | int channel_num = vie_.GetLastChannel(); |
| 1013 | std::vector<cricket::VideoCodec> recv_codecs(engine_.codecs()); |
| 1014 | std::vector<cricket::VideoCodec> send_codecs(engine_.codecs()); |
| 1015 | // Only add VP8 as send codec. |
| 1016 | send_codecs.resize(1); |
| 1017 | EXPECT_TRUE(channel_->SetSendCodecs(send_codecs)); |
| 1018 | EXPECT_TRUE(channel_->SetRecvCodecs(recv_codecs)); |
| 1019 | EXPECT_FALSE(vie_.GetHybridNackFecStatus(channel_num)); |
| 1020 | EXPECT_TRUE(vie_.GetNackStatus(channel_num)); |
| 1021 | } |
| 1022 | |
| 1023 | // Test that NACK, not hybrid mode, is enabled in conference mode. |
| 1024 | TEST_F(WebRtcVideoEngineTestFake, HybridNackFecConference) { |
| 1025 | EXPECT_TRUE(SetupEngine()); |
| 1026 | // Setup the send channel. |
| 1027 | int send_channel_num = vie_.GetLastChannel(); |
| 1028 | cricket::VideoOptions options; |
| 1029 | options.conference_mode.Set(true); |
| 1030 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 1031 | EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs())); |
| 1032 | EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
| 1033 | EXPECT_FALSE(vie_.GetHybridNackFecStatus(send_channel_num)); |
| 1034 | EXPECT_TRUE(vie_.GetNackStatus(send_channel_num)); |
| 1035 | // Add a receive stream. |
| 1036 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
| 1037 | int receive_channel_num = vie_.GetLastChannel(); |
| 1038 | EXPECT_FALSE(vie_.GetHybridNackFecStatus(receive_channel_num)); |
| 1039 | EXPECT_TRUE(vie_.GetNackStatus(receive_channel_num)); |
| 1040 | } |
| 1041 | |
| 1042 | // Test that when AddRecvStream in conference mode, a new channel is created |
| 1043 | // for receiving. And the new channel's "original channel" is the send channel. |
| 1044 | TEST_F(WebRtcVideoEngineTestFake, AddRemoveRecvStreamConference) { |
| 1045 | EXPECT_TRUE(SetupEngine()); |
| 1046 | // Setup the send channel. |
| 1047 | int send_channel_num = vie_.GetLastChannel(); |
| 1048 | cricket::VideoOptions options; |
| 1049 | options.conference_mode.Set(true); |
| 1050 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 1051 | // Add a receive stream. |
| 1052 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
| 1053 | int receive_channel_num = vie_.GetLastChannel(); |
| 1054 | EXPECT_EQ(send_channel_num, vie_.GetOriginalChannelId(receive_channel_num)); |
| 1055 | EXPECT_TRUE(channel_->RemoveRecvStream(1)); |
| 1056 | EXPECT_FALSE(vie_.IsChannel(receive_channel_num)); |
| 1057 | } |
| 1058 | |
| 1059 | // Test that we can create a channel and start/stop rendering out on it. |
| 1060 | TEST_F(WebRtcVideoEngineTestFake, SetRender) { |
| 1061 | EXPECT_TRUE(SetupEngine()); |
| 1062 | int channel_num = vie_.GetLastChannel(); |
| 1063 | |
| 1064 | // Verify we can start/stop/start/stop rendering. |
| 1065 | EXPECT_TRUE(channel_->SetRender(true)); |
| 1066 | EXPECT_TRUE(vie_.GetRenderStarted(channel_num)); |
| 1067 | EXPECT_TRUE(channel_->SetRender(false)); |
| 1068 | EXPECT_FALSE(vie_.GetRenderStarted(channel_num)); |
| 1069 | EXPECT_TRUE(channel_->SetRender(true)); |
| 1070 | EXPECT_TRUE(vie_.GetRenderStarted(channel_num)); |
| 1071 | EXPECT_TRUE(channel_->SetRender(false)); |
| 1072 | EXPECT_FALSE(vie_.GetRenderStarted(channel_num)); |
| 1073 | } |
| 1074 | |
| 1075 | // Test that we can create a channel and start/stop sending out on it. |
| 1076 | TEST_F(WebRtcVideoEngineTestFake, SetSend) { |
| 1077 | EXPECT_TRUE(SetupEngine()); |
| 1078 | int channel_num = vie_.GetLastChannel(); |
| 1079 | |
| 1080 | // Set send codecs on the channel. |
| 1081 | std::vector<cricket::VideoCodec> codecs; |
| 1082 | codecs.push_back(kVP8Codec); |
| 1083 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1084 | EXPECT_TRUE(channel_->AddSendStream( |
| 1085 | cricket::StreamParams::CreateLegacy(123))); |
| 1086 | |
| 1087 | // Verify we can start/stop/start/stop sending. |
| 1088 | EXPECT_TRUE(channel_->SetSend(true)); |
| 1089 | EXPECT_TRUE(vie_.GetSend(channel_num)); |
| 1090 | EXPECT_TRUE(channel_->SetSend(false)); |
| 1091 | EXPECT_FALSE(vie_.GetSend(channel_num)); |
| 1092 | EXPECT_TRUE(channel_->SetSend(true)); |
| 1093 | EXPECT_TRUE(vie_.GetSend(channel_num)); |
| 1094 | EXPECT_TRUE(channel_->SetSend(false)); |
| 1095 | EXPECT_FALSE(vie_.GetSend(channel_num)); |
| 1096 | } |
| 1097 | |
| 1098 | // Test that we set bandwidth properly when using full auto bandwidth mode. |
| 1099 | TEST_F(WebRtcVideoEngineTestFake, SetBandwidthAuto) { |
| 1100 | EXPECT_TRUE(SetupEngine()); |
| 1101 | int channel_num = vie_.GetLastChannel(); |
| 1102 | EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
| 1103 | EXPECT_TRUE(channel_->SetSendBandwidth(true, cricket::kAutoBandwidth)); |
| 1104 | VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height); |
| 1105 | } |
| 1106 | |
| 1107 | // Test that we set bandwidth properly when using auto with upper bound. |
| 1108 | TEST_F(WebRtcVideoEngineTestFake, SetBandwidthAutoCapped) { |
| 1109 | EXPECT_TRUE(SetupEngine()); |
| 1110 | int channel_num = vie_.GetLastChannel(); |
| 1111 | EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
| 1112 | EXPECT_TRUE(channel_->SetSendBandwidth(true, 768000)); |
| 1113 | VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, 768U); |
| 1114 | } |
| 1115 | |
| 1116 | // Test that we set bandwidth properly when using a fixed bandwidth. |
| 1117 | TEST_F(WebRtcVideoEngineTestFake, SetBandwidthFixed) { |
| 1118 | EXPECT_TRUE(SetupEngine()); |
| 1119 | int channel_num = vie_.GetLastChannel(); |
| 1120 | EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
| 1121 | EXPECT_TRUE(channel_->SetSendBandwidth(false, 768000)); |
| 1122 | VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, |
| 1123 | 768U, 768U, 768U); |
| 1124 | } |
| 1125 | |
| 1126 | // Test that SetSendBandwidth is ignored in conference mode. |
| 1127 | TEST_F(WebRtcVideoEngineTestFake, SetBandwidthInConference) { |
| 1128 | EXPECT_TRUE(SetupEngine()); |
| 1129 | int channel_num = vie_.GetLastChannel(); |
| 1130 | cricket::VideoOptions options; |
| 1131 | options.conference_mode.Set(true); |
| 1132 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 1133 | EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); |
| 1134 | VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height); |
| 1135 | |
| 1136 | // Set send bandwidth. |
| 1137 | EXPECT_TRUE(channel_->SetSendBandwidth(false, 768000)); |
| 1138 | |
| 1139 | // Verify bitrate not changed. |
| 1140 | webrtc::VideoCodec gcodec; |
| 1141 | EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec)); |
| 1142 | EXPECT_EQ(kMinBandwidthKbps, gcodec.minBitrate); |
| 1143 | EXPECT_EQ(kStartBandwidthKbps, gcodec.startBitrate); |
| 1144 | EXPECT_EQ(kMaxBandwidthKbps, gcodec.maxBitrate); |
| 1145 | EXPECT_NE(768U, gcodec.minBitrate); |
| 1146 | EXPECT_NE(768U, gcodec.startBitrate); |
| 1147 | EXPECT_NE(768U, gcodec.maxBitrate); |
| 1148 | } |
| 1149 | |
| 1150 | // Test that sending screencast frames doesn't change bitrate. |
| 1151 | TEST_F(WebRtcVideoEngineTestFake, SetBandwidthScreencast) { |
| 1152 | EXPECT_TRUE(SetupEngine()); |
| 1153 | int channel_num = vie_.GetLastChannel(); |
| 1154 | |
| 1155 | // Set send codec. |
| 1156 | cricket::VideoCodec codec(kVP8Codec); |
| 1157 | std::vector<cricket::VideoCodec> codec_list; |
| 1158 | codec_list.push_back(codec); |
| 1159 | EXPECT_TRUE(channel_->AddSendStream( |
| 1160 | cricket::StreamParams::CreateLegacy(123))); |
| 1161 | EXPECT_TRUE(channel_->SetSendCodecs(codec_list)); |
| 1162 | EXPECT_TRUE(channel_->SetSendBandwidth(false, 111000)); |
| 1163 | EXPECT_TRUE(channel_->SetSend(true)); |
| 1164 | |
| 1165 | SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height); |
| 1166 | VerifyVP8SendCodec(channel_num, kVP8Codec.width, kVP8Codec.height, 0, |
| 1167 | 111, 111, 111); |
| 1168 | } |
| 1169 | |
| 1170 | |
| 1171 | // Test SetSendSsrc. |
| 1172 | TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAndCname) { |
| 1173 | EXPECT_TRUE(SetupEngine()); |
| 1174 | int channel_num = vie_.GetLastChannel(); |
| 1175 | |
| 1176 | cricket::StreamParams stream; |
| 1177 | stream.ssrcs.push_back(1234); |
| 1178 | stream.cname = "cname"; |
| 1179 | channel_->AddSendStream(stream); |
| 1180 | |
| 1181 | unsigned int ssrc = 0; |
| 1182 | EXPECT_EQ(0, vie_.GetLocalSSRC(channel_num, ssrc)); |
| 1183 | EXPECT_EQ(1234U, ssrc); |
| 1184 | EXPECT_EQ(1, vie_.GetNumSsrcs(channel_num)); |
| 1185 | |
| 1186 | char rtcp_cname[256]; |
| 1187 | EXPECT_EQ(0, vie_.GetRTCPCName(channel_num, rtcp_cname)); |
| 1188 | EXPECT_STREQ("cname", rtcp_cname); |
| 1189 | } |
| 1190 | |
| 1191 | |
| 1192 | // Test that the local SSRC is the same on sending and receiving channels if the |
| 1193 | // receive channel is created before the send channel. |
| 1194 | TEST_F(WebRtcVideoEngineTestFake, SetSendSsrcAfterCreatingReceiveChannel) { |
| 1195 | EXPECT_TRUE(SetupEngine()); |
| 1196 | |
| 1197 | EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); |
| 1198 | int receive_channel_num = vie_.GetLastChannel(); |
| 1199 | cricket::StreamParams stream = cricket::StreamParams::CreateLegacy(1234); |
| 1200 | EXPECT_TRUE(channel_->AddSendStream(stream)); |
| 1201 | int send_channel_num = vie_.GetLastChannel(); |
| 1202 | unsigned int ssrc = 0; |
| 1203 | EXPECT_EQ(0, vie_.GetLocalSSRC(send_channel_num, ssrc)); |
| 1204 | EXPECT_EQ(1234U, ssrc); |
| 1205 | EXPECT_EQ(1, vie_.GetNumSsrcs(send_channel_num)); |
| 1206 | ssrc = 0; |
| 1207 | EXPECT_EQ(0, vie_.GetLocalSSRC(receive_channel_num, ssrc)); |
| 1208 | EXPECT_EQ(1234U, ssrc); |
| 1209 | EXPECT_EQ(1, vie_.GetNumSsrcs(receive_channel_num)); |
| 1210 | } |
| 1211 | |
| 1212 | |
| 1213 | // Test SetOptions with denoising flag. |
| 1214 | TEST_F(WebRtcVideoEngineTestFake, SetOptionsWithDenoising) { |
| 1215 | EXPECT_TRUE(SetupEngine()); |
| 1216 | EXPECT_EQ(1, vie_.GetNumCapturers()); |
| 1217 | int channel_num = vie_.GetLastChannel(); |
| 1218 | int capture_id = vie_.GetCaptureId(channel_num); |
| 1219 | // Set send codecs on the channel. |
| 1220 | std::vector<cricket::VideoCodec> codecs; |
| 1221 | codecs.push_back(kVP8Codec); |
| 1222 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1223 | |
| 1224 | // Set options with OPT_VIDEO_NOISE_REDUCTION flag. |
| 1225 | cricket::VideoOptions options; |
| 1226 | options.video_noise_reduction.Set(true); |
| 1227 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 1228 | |
| 1229 | // Verify capture has denoising turned on. |
| 1230 | webrtc::VideoCodec send_codec; |
| 1231 | memset(&send_codec, 0, sizeof(send_codec)); // avoid uninitialized warning |
| 1232 | EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec)); |
| 1233 | EXPECT_TRUE(send_codec.codecSpecific.VP8.denoisingOn); |
| 1234 | EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id)); |
| 1235 | |
| 1236 | // Set options back to zero. |
| 1237 | options.video_noise_reduction.Set(false); |
| 1238 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 1239 | |
| 1240 | // Verify capture has denoising turned off. |
| 1241 | EXPECT_EQ(0, vie_.GetSendCodec(channel_num, send_codec)); |
| 1242 | EXPECT_FALSE(send_codec.codecSpecific.VP8.denoisingOn); |
| 1243 | EXPECT_FALSE(vie_.GetCaptureDenoising(capture_id)); |
| 1244 | } |
| 1245 | |
wu@webrtc.org | 24301a6 | 2013-12-13 19:17:43 +0000 | [diff] [blame] | 1246 | TEST_F(WebRtcVideoEngineTestFake, MultipleSendStreamsWithOneCapturer) { |
| 1247 | EXPECT_TRUE(SetupEngine()); |
| 1248 | |
| 1249 | // Start the capturer |
| 1250 | cricket::FakeVideoCapturer capturer; |
| 1251 | cricket::VideoFormat capture_format_vga = cricket::VideoFormat(640, 480, |
| 1252 | cricket::VideoFormat::FpsToInterval(30), cricket::FOURCC_I420); |
| 1253 | EXPECT_EQ(cricket::CS_RUNNING, capturer.Start(capture_format_vga)); |
| 1254 | |
| 1255 | // Add send streams and connect the capturer |
| 1256 | for (unsigned int i = 0; i < sizeof(kSsrcs2)/sizeof(kSsrcs2[0]); ++i) { |
| 1257 | EXPECT_TRUE(channel_->AddSendStream( |
| 1258 | cricket::StreamParams::CreateLegacy(kSsrcs2[i]))); |
| 1259 | // Register the capturer to the ssrc. |
| 1260 | EXPECT_TRUE(channel_->SetCapturer(kSsrcs2[i], &capturer)); |
| 1261 | } |
| 1262 | |
| 1263 | const int channel0 = vie_.GetChannelFromLocalSsrc(kSsrcs2[0]); |
| 1264 | ASSERT_NE(-1, channel0); |
| 1265 | const int channel1 = vie_.GetChannelFromLocalSsrc(kSsrcs2[1]); |
| 1266 | ASSERT_NE(-1, channel1); |
| 1267 | ASSERT_NE(channel0, channel1); |
| 1268 | |
| 1269 | // Set send codec. |
| 1270 | std::vector<cricket::VideoCodec> codecs; |
| 1271 | cricket::VideoCodec send_codec(100, "VP8", 640, 480, 30, 0); |
| 1272 | codecs.push_back(send_codec); |
| 1273 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1274 | |
| 1275 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 1276 | EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0)); |
| 1277 | EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel1)); |
| 1278 | |
| 1279 | EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs2[0])); |
| 1280 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 1281 | // channel0 is the default channel, so it won't be deleted. |
| 1282 | // But it should be disconnected from the capturer. |
| 1283 | EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0)); |
| 1284 | EXPECT_EQ(2, vie_.GetIncomingFrameNum(channel1)); |
| 1285 | |
| 1286 | EXPECT_TRUE(channel_->RemoveSendStream(kSsrcs2[1])); |
| 1287 | EXPECT_TRUE(capturer.CaptureFrame()); |
| 1288 | EXPECT_EQ(1, vie_.GetIncomingFrameNum(channel0)); |
| 1289 | // channel1 has already been deleted. |
| 1290 | EXPECT_EQ(-1, vie_.GetIncomingFrameNum(channel1)); |
| 1291 | } |
| 1292 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1293 | |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 +0000 | [diff] [blame] | 1294 | // Disabled since its flaky: b/11288120 |
| 1295 | TEST_F(WebRtcVideoEngineTestFake, DISABLED_SendReceiveBitratesStats) { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1296 | EXPECT_TRUE(SetupEngine()); |
| 1297 | cricket::VideoOptions options; |
| 1298 | options.conference_mode.Set(true); |
| 1299 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 1300 | EXPECT_TRUE(channel_->AddSendStream( |
| 1301 | cricket::StreamParams::CreateLegacy(1))); |
| 1302 | int send_channel = vie_.GetLastChannel(); |
| 1303 | cricket::VideoCodec codec(kVP8Codec720p); |
| 1304 | std::vector<cricket::VideoCodec> codec_list; |
| 1305 | codec_list.push_back(codec); |
| 1306 | EXPECT_TRUE(channel_->SetSendCodecs(codec_list)); |
| 1307 | |
| 1308 | EXPECT_TRUE(channel_->AddRecvStream( |
| 1309 | cricket::StreamParams::CreateLegacy(2))); |
| 1310 | int first_receive_channel = vie_.GetLastChannel(); |
| 1311 | EXPECT_NE(send_channel, first_receive_channel); |
| 1312 | EXPECT_TRUE(channel_->AddRecvStream( |
| 1313 | cricket::StreamParams::CreateLegacy(3))); |
| 1314 | int second_receive_channel = vie_.GetLastChannel(); |
| 1315 | EXPECT_NE(first_receive_channel, second_receive_channel); |
| 1316 | |
| 1317 | cricket::VideoMediaInfo info; |
| 1318 | EXPECT_TRUE(channel_->GetStats(&info)); |
| 1319 | ASSERT_EQ(1U, info.bw_estimations.size()); |
| 1320 | ASSERT_EQ(0, info.bw_estimations[0].actual_enc_bitrate); |
| 1321 | ASSERT_EQ(0, info.bw_estimations[0].transmit_bitrate); |
| 1322 | ASSERT_EQ(0, info.bw_estimations[0].retransmit_bitrate); |
| 1323 | ASSERT_EQ(0, info.bw_estimations[0].available_send_bandwidth); |
| 1324 | ASSERT_EQ(0, info.bw_estimations[0].available_recv_bandwidth); |
| 1325 | ASSERT_EQ(0, info.bw_estimations[0].target_enc_bitrate); |
| 1326 | |
| 1327 | // Start sending and receiving on one of the channels and verify bitrates. |
| 1328 | EXPECT_EQ(0, vie_.StartSend(send_channel)); |
| 1329 | int send_video_bitrate = 800; |
| 1330 | int send_fec_bitrate = 100; |
| 1331 | int send_nack_bitrate = 20; |
| 1332 | int send_total_bitrate = send_video_bitrate + send_fec_bitrate + |
| 1333 | send_nack_bitrate; |
| 1334 | int send_bandwidth = 950; |
| 1335 | vie_.SetSendBitrates(send_channel, send_video_bitrate, send_fec_bitrate, |
| 1336 | send_nack_bitrate); |
| 1337 | vie_.SetSendBandwidthEstimate(send_channel, send_bandwidth); |
| 1338 | |
| 1339 | EXPECT_EQ(0, vie_.StartReceive(first_receive_channel)); |
| 1340 | int first_channel_receive_bandwidth = 600; |
| 1341 | vie_.SetReceiveBandwidthEstimate(first_receive_channel, |
| 1342 | first_channel_receive_bandwidth); |
| 1343 | |
| 1344 | info.Clear(); |
| 1345 | EXPECT_TRUE(channel_->GetStats(&info)); |
| 1346 | ASSERT_EQ(1U, info.bw_estimations.size()); |
| 1347 | ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate); |
| 1348 | ASSERT_EQ(send_total_bitrate, info.bw_estimations[0].transmit_bitrate); |
| 1349 | ASSERT_EQ(send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate); |
| 1350 | ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth); |
| 1351 | ASSERT_EQ(first_channel_receive_bandwidth, |
| 1352 | info.bw_estimations[0].available_recv_bandwidth); |
| 1353 | ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].target_enc_bitrate); |
| 1354 | |
| 1355 | // Start receiving on the second channel and verify received rate. |
| 1356 | EXPECT_EQ(0, vie_.StartReceive(second_receive_channel)); |
| 1357 | int second_channel_receive_bandwidth = 100; |
| 1358 | vie_.SetReceiveBandwidthEstimate(second_receive_channel, |
| 1359 | second_channel_receive_bandwidth); |
| 1360 | |
| 1361 | info.Clear(); |
| 1362 | EXPECT_TRUE(channel_->GetStats(&info)); |
| 1363 | ASSERT_EQ(1U, info.bw_estimations.size()); |
| 1364 | ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].actual_enc_bitrate); |
| 1365 | ASSERT_EQ(send_total_bitrate, info.bw_estimations[0].transmit_bitrate); |
| 1366 | ASSERT_EQ(send_nack_bitrate, info.bw_estimations[0].retransmit_bitrate); |
| 1367 | ASSERT_EQ(send_bandwidth, info.bw_estimations[0].available_send_bandwidth); |
| 1368 | ASSERT_EQ(first_channel_receive_bandwidth + second_channel_receive_bandwidth, |
| 1369 | info.bw_estimations[0].available_recv_bandwidth); |
| 1370 | ASSERT_EQ(send_video_bitrate, info.bw_estimations[0].target_enc_bitrate); |
| 1371 | } |
| 1372 | |
| 1373 | TEST_F(WebRtcVideoEngineTestFake, TestSetAdaptInputToCpuUsage) { |
| 1374 | EXPECT_TRUE(SetupEngine()); |
| 1375 | cricket::VideoOptions options_in, options_out; |
| 1376 | bool cpu_adapt = false; |
| 1377 | channel_->SetOptions(options_in); |
| 1378 | EXPECT_TRUE(channel_->GetOptions(&options_out)); |
| 1379 | EXPECT_FALSE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt)); |
| 1380 | // Set adapt input CPU usage option. |
| 1381 | options_in.adapt_input_to_cpu_usage.Set(true); |
| 1382 | EXPECT_TRUE(channel_->SetOptions(options_in)); |
| 1383 | EXPECT_TRUE(channel_->GetOptions(&options_out)); |
| 1384 | EXPECT_TRUE(options_out.adapt_input_to_cpu_usage.Get(&cpu_adapt)); |
| 1385 | EXPECT_TRUE(cpu_adapt); |
| 1386 | } |
| 1387 | |
| 1388 | TEST_F(WebRtcVideoEngineTestFake, TestSetCpuThreshold) { |
| 1389 | EXPECT_TRUE(SetupEngine()); |
| 1390 | float low, high; |
| 1391 | cricket::VideoOptions options_in, options_out; |
| 1392 | // Verify that initial values are set. |
| 1393 | EXPECT_TRUE(channel_->GetOptions(&options_out)); |
| 1394 | EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low)); |
| 1395 | EXPECT_EQ(low, 0.65f); |
| 1396 | EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high)); |
| 1397 | EXPECT_EQ(high, 0.85f); |
| 1398 | // Set new CPU threshold values. |
| 1399 | options_in.system_low_adaptation_threshhold.Set(0.45f); |
| 1400 | options_in.system_high_adaptation_threshhold.Set(0.95f); |
| 1401 | EXPECT_TRUE(channel_->SetOptions(options_in)); |
| 1402 | EXPECT_TRUE(channel_->GetOptions(&options_out)); |
| 1403 | EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low)); |
| 1404 | EXPECT_EQ(low, 0.45f); |
| 1405 | EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high)); |
| 1406 | EXPECT_EQ(high, 0.95f); |
| 1407 | } |
| 1408 | |
| 1409 | TEST_F(WebRtcVideoEngineTestFake, TestSetInvalidCpuThreshold) { |
| 1410 | EXPECT_TRUE(SetupEngine()); |
| 1411 | float low, high; |
| 1412 | cricket::VideoOptions options_in, options_out; |
| 1413 | // Valid range is [0, 1]. |
| 1414 | options_in.system_low_adaptation_threshhold.Set(-1.5f); |
| 1415 | options_in.system_high_adaptation_threshhold.Set(1.5f); |
| 1416 | EXPECT_TRUE(channel_->SetOptions(options_in)); |
| 1417 | EXPECT_TRUE(channel_->GetOptions(&options_out)); |
| 1418 | EXPECT_TRUE(options_out.system_low_adaptation_threshhold.Get(&low)); |
| 1419 | EXPECT_EQ(low, 0.0f); |
| 1420 | EXPECT_TRUE(options_out.system_high_adaptation_threshhold.Get(&high)); |
| 1421 | EXPECT_EQ(high, 1.0f); |
| 1422 | } |
| 1423 | |
| 1424 | |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 1425 | TEST_F(WebRtcVideoEngineTestFake, ResetCodecOnScreencast) { |
| 1426 | EXPECT_TRUE(SetupEngine()); |
| 1427 | cricket::VideoOptions options; |
| 1428 | options.video_noise_reduction.Set(true); |
| 1429 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 1430 | |
| 1431 | // Set send codec. |
| 1432 | cricket::VideoCodec codec(kVP8Codec); |
| 1433 | std::vector<cricket::VideoCodec> codec_list; |
| 1434 | codec_list.push_back(codec); |
| 1435 | EXPECT_TRUE(channel_->AddSendStream( |
| 1436 | cricket::StreamParams::CreateLegacy(123))); |
| 1437 | EXPECT_TRUE(channel_->SetSendCodecs(codec_list)); |
| 1438 | EXPECT_TRUE(channel_->SetSend(true)); |
| 1439 | EXPECT_EQ(1, vie_.num_set_send_codecs()); |
| 1440 | |
| 1441 | webrtc::VideoCodec gcodec; |
| 1442 | memset(&gcodec, 0, sizeof(gcodec)); |
| 1443 | int channel_num = vie_.GetLastChannel(); |
| 1444 | EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec)); |
| 1445 | EXPECT_TRUE(gcodec.codecSpecific.VP8.denoisingOn); |
| 1446 | |
| 1447 | // Send a screencast frame with the same size. |
| 1448 | // Verify that denoising is turned off. |
| 1449 | SendI420ScreencastFrame(kVP8Codec.width, kVP8Codec.height); |
| 1450 | EXPECT_EQ(2, vie_.num_set_send_codecs()); |
| 1451 | EXPECT_EQ(0, vie_.GetSendCodec(channel_num, gcodec)); |
| 1452 | EXPECT_FALSE(gcodec.codecSpecific.VP8.denoisingOn); |
| 1453 | } |
| 1454 | |
| 1455 | |
| 1456 | TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderIfFactoryIsNotGiven) { |
| 1457 | engine_.SetExternalDecoderFactory(NULL); |
| 1458 | EXPECT_TRUE(SetupEngine()); |
| 1459 | int channel_num = vie_.GetLastChannel(); |
| 1460 | |
| 1461 | std::vector<cricket::VideoCodec> codecs; |
| 1462 | codecs.push_back(kVP8Codec); |
| 1463 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 1464 | |
| 1465 | EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num)); |
| 1466 | } |
| 1467 | |
| 1468 | TEST_F(WebRtcVideoEngineTestFake, RegisterDecoderIfFactoryIsGiven) { |
| 1469 | decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8); |
| 1470 | engine_.SetExternalDecoderFactory(&decoder_factory_); |
| 1471 | EXPECT_TRUE(SetupEngine()); |
| 1472 | int channel_num = vie_.GetLastChannel(); |
| 1473 | |
| 1474 | std::vector<cricket::VideoCodec> codecs; |
| 1475 | codecs.push_back(kVP8Codec); |
| 1476 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 1477 | |
| 1478 | EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100)); |
| 1479 | EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num)); |
| 1480 | } |
| 1481 | |
| 1482 | TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderMultipleTimes) { |
| 1483 | decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8); |
| 1484 | engine_.SetExternalDecoderFactory(&decoder_factory_); |
| 1485 | EXPECT_TRUE(SetupEngine()); |
| 1486 | int channel_num = vie_.GetLastChannel(); |
| 1487 | |
| 1488 | std::vector<cricket::VideoCodec> codecs; |
| 1489 | codecs.push_back(kVP8Codec); |
| 1490 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 1491 | |
| 1492 | EXPECT_TRUE(vie_.ExternalDecoderRegistered(channel_num, 100)); |
| 1493 | EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num)); |
| 1494 | EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders()); |
| 1495 | |
| 1496 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 1497 | EXPECT_EQ(1, vie_.GetNumExternalDecoderRegistered(channel_num)); |
| 1498 | EXPECT_EQ(1, decoder_factory_.GetNumCreatedDecoders()); |
| 1499 | } |
| 1500 | |
| 1501 | TEST_F(WebRtcVideoEngineTestFake, DontRegisterDecoderForNonVP8) { |
| 1502 | decoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8); |
| 1503 | engine_.SetExternalDecoderFactory(&decoder_factory_); |
| 1504 | EXPECT_TRUE(SetupEngine()); |
| 1505 | int channel_num = vie_.GetLastChannel(); |
| 1506 | |
| 1507 | std::vector<cricket::VideoCodec> codecs; |
| 1508 | codecs.push_back(kRedCodec); |
| 1509 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 1510 | |
| 1511 | EXPECT_EQ(0, vie_.GetNumExternalDecoderRegistered(channel_num)); |
| 1512 | } |
| 1513 | |
| 1514 | TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderIfFactoryIsNotGiven) { |
| 1515 | engine_.SetExternalEncoderFactory(NULL); |
| 1516 | EXPECT_TRUE(SetupEngine()); |
| 1517 | int channel_num = vie_.GetLastChannel(); |
| 1518 | |
| 1519 | std::vector<cricket::VideoCodec> codecs; |
| 1520 | codecs.push_back(kVP8Codec); |
| 1521 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1522 | |
| 1523 | EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num)); |
| 1524 | } |
| 1525 | |
| 1526 | TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderIfFactoryIsGiven) { |
| 1527 | encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8"); |
| 1528 | engine_.SetExternalEncoderFactory(&encoder_factory_); |
| 1529 | EXPECT_TRUE(SetupEngine()); |
| 1530 | int channel_num = vie_.GetLastChannel(); |
| 1531 | |
| 1532 | std::vector<cricket::VideoCodec> codecs; |
| 1533 | codecs.push_back(kVP8Codec); |
| 1534 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1535 | |
| 1536 | EXPECT_TRUE(channel_->AddSendStream( |
| 1537 | cricket::StreamParams::CreateLegacy(kSsrc))); |
| 1538 | |
| 1539 | EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100)); |
| 1540 | EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num)); |
| 1541 | |
| 1542 | // Remove stream previously added to free the external encoder instance. |
| 1543 | EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); |
| 1544 | } |
| 1545 | |
| 1546 | TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderMultipleTimes) { |
| 1547 | encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8"); |
| 1548 | engine_.SetExternalEncoderFactory(&encoder_factory_); |
| 1549 | EXPECT_TRUE(SetupEngine()); |
| 1550 | int channel_num = vie_.GetLastChannel(); |
| 1551 | |
| 1552 | std::vector<cricket::VideoCodec> codecs; |
| 1553 | codecs.push_back(kVP8Codec); |
| 1554 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1555 | |
| 1556 | EXPECT_TRUE(channel_->AddSendStream( |
| 1557 | cricket::StreamParams::CreateLegacy(kSsrc))); |
| 1558 | |
| 1559 | EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100)); |
| 1560 | EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num)); |
| 1561 | EXPECT_EQ(1, encoder_factory_.GetNumCreatedEncoders()); |
| 1562 | |
| 1563 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1564 | EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num)); |
| 1565 | EXPECT_EQ(1, encoder_factory_.GetNumCreatedEncoders()); |
| 1566 | |
| 1567 | // Remove stream previously added to free the external encoder instance. |
| 1568 | EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); |
| 1569 | } |
| 1570 | |
| 1571 | TEST_F(WebRtcVideoEngineTestFake, RegisterEncoderWithMultipleSendStreams) { |
| 1572 | encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8"); |
| 1573 | engine_.SetExternalEncoderFactory(&encoder_factory_); |
| 1574 | EXPECT_TRUE(SetupEngine()); |
| 1575 | |
| 1576 | std::vector<cricket::VideoCodec> codecs; |
| 1577 | codecs.push_back(kVP8Codec); |
| 1578 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1579 | EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered()); |
| 1580 | |
| 1581 | // When we add the first stream (1234), it reuses the default send channel, |
| 1582 | // so it doesn't increase the registration count of external encoders. |
| 1583 | EXPECT_TRUE(channel_->AddSendStream( |
| 1584 | cricket::StreamParams::CreateLegacy(1234))); |
| 1585 | EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered()); |
| 1586 | |
| 1587 | // When we add the second stream (2345), it creates a new channel and |
| 1588 | // increments the registration count. |
| 1589 | EXPECT_TRUE(channel_->AddSendStream( |
| 1590 | cricket::StreamParams::CreateLegacy(2345))); |
| 1591 | EXPECT_EQ(2, vie_.GetTotalNumExternalEncoderRegistered()); |
| 1592 | |
| 1593 | // At this moment the total registration count is two, but only one encoder |
| 1594 | // is registered per channel. |
| 1595 | int channel_num = vie_.GetLastChannel(); |
| 1596 | EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num)); |
| 1597 | |
| 1598 | // Removing send streams decrements the registration count. |
| 1599 | EXPECT_TRUE(channel_->RemoveSendStream(1234)); |
| 1600 | EXPECT_EQ(1, vie_.GetTotalNumExternalEncoderRegistered()); |
| 1601 | |
| 1602 | // When we remove the last send stream, it also destroys the last send |
| 1603 | // channel and causes the registration count to drop to zero. It is a little |
| 1604 | // weird, but not a bug. |
| 1605 | EXPECT_TRUE(channel_->RemoveSendStream(2345)); |
| 1606 | EXPECT_EQ(0, vie_.GetTotalNumExternalEncoderRegistered()); |
| 1607 | } |
| 1608 | |
| 1609 | TEST_F(WebRtcVideoEngineTestFake, DontRegisterEncoderForNonVP8) { |
| 1610 | encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric, |
| 1611 | "GENERIC"); |
| 1612 | engine_.SetExternalEncoderFactory(&encoder_factory_); |
| 1613 | EXPECT_TRUE(SetupEngine()); |
| 1614 | int channel_num = vie_.GetLastChannel(); |
| 1615 | |
| 1616 | // Note: unlike the SetRecvCodecs, we must set a valid video codec for |
| 1617 | // channel_->SetSendCodecs() to succeed. |
| 1618 | std::vector<cricket::VideoCodec> codecs; |
| 1619 | codecs.push_back(kVP8Codec); |
| 1620 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1621 | |
| 1622 | EXPECT_EQ(0, vie_.GetNumExternalEncoderRegistered(channel_num)); |
| 1623 | } |
| 1624 | |
| 1625 | // Test that NACK, PLI and REMB are enabled for external codec. |
| 1626 | TEST_F(WebRtcVideoEngineTestFake, ExternalCodecFeedbackParams) { |
| 1627 | encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric, |
| 1628 | "GENERIC"); |
| 1629 | engine_.SetExternalEncoderFactory(&encoder_factory_); |
| 1630 | encoder_factory_.NotifyCodecsAvailable(); |
| 1631 | EXPECT_TRUE(SetupEngine()); |
| 1632 | |
| 1633 | std::vector<cricket::VideoCodec> codecs(engine_.codecs()); |
| 1634 | // The external codec will appear at last. |
| 1635 | size_t pos = codecs.size() - 1; |
| 1636 | EXPECT_EQ("GENERIC", codecs[pos].name); |
| 1637 | VerifyCodecFeedbackParams(codecs[pos]); |
| 1638 | } |
| 1639 | |
| 1640 | // Test external codec with be added to the end of the supported codec list. |
| 1641 | TEST_F(WebRtcVideoEngineTestFake, ExternalCodecAddedToTheEnd) { |
| 1642 | EXPECT_TRUE(SetupEngine()); |
| 1643 | |
| 1644 | std::vector<cricket::VideoCodec> codecs(engine_.codecs()); |
| 1645 | EXPECT_EQ("VP8", codecs[0].name); |
| 1646 | |
| 1647 | encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecGeneric, |
| 1648 | "GENERIC"); |
| 1649 | engine_.SetExternalEncoderFactory(&encoder_factory_); |
| 1650 | encoder_factory_.NotifyCodecsAvailable(); |
| 1651 | |
| 1652 | codecs = engine_.codecs(); |
| 1653 | cricket::VideoCodec internal_codec = codecs[0]; |
| 1654 | cricket::VideoCodec external_codec = codecs[codecs.size() - 1]; |
| 1655 | // The external codec will appear at last. |
| 1656 | EXPECT_EQ("GENERIC", external_codec.name); |
| 1657 | // The internal codec is preferred. |
| 1658 | EXPECT_GE(internal_codec.preference, external_codec.preference); |
| 1659 | } |
| 1660 | |
| 1661 | // Test that external codec with be ignored if it has the same name as one of |
| 1662 | // the internal codecs. |
| 1663 | TEST_F(WebRtcVideoEngineTestFake, ExternalCodecIgnored) { |
| 1664 | EXPECT_TRUE(SetupEngine()); |
| 1665 | |
| 1666 | std::vector<cricket::VideoCodec> internal_codecs(engine_.codecs()); |
| 1667 | EXPECT_EQ("VP8", internal_codecs[0].name); |
| 1668 | |
| 1669 | encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8"); |
| 1670 | engine_.SetExternalEncoderFactory(&encoder_factory_); |
| 1671 | encoder_factory_.NotifyCodecsAvailable(); |
| 1672 | |
| 1673 | std::vector<cricket::VideoCodec> codecs = engine_.codecs(); |
| 1674 | EXPECT_EQ("VP8", codecs[0].name); |
| 1675 | EXPECT_EQ(internal_codecs[0].height, codecs[0].height); |
| 1676 | EXPECT_EQ(internal_codecs[0].width, codecs[0].width); |
| 1677 | // Verify the last codec is not the external codec. |
| 1678 | EXPECT_NE("VP8", codecs[codecs.size() - 1].name); |
| 1679 | } |
| 1680 | |
| 1681 | TEST_F(WebRtcVideoEngineTestFake, UpdateEncoderCodecsAfterSetFactory) { |
| 1682 | engine_.SetExternalEncoderFactory(&encoder_factory_); |
| 1683 | EXPECT_TRUE(SetupEngine()); |
| 1684 | int channel_num = vie_.GetLastChannel(); |
| 1685 | |
| 1686 | encoder_factory_.AddSupportedVideoCodecType(webrtc::kVideoCodecVP8, "VP8"); |
| 1687 | encoder_factory_.NotifyCodecsAvailable(); |
| 1688 | std::vector<cricket::VideoCodec> codecs; |
| 1689 | codecs.push_back(kVP8Codec); |
| 1690 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1691 | |
| 1692 | EXPECT_TRUE(channel_->AddSendStream( |
| 1693 | cricket::StreamParams::CreateLegacy(kSsrc))); |
| 1694 | |
| 1695 | EXPECT_TRUE(vie_.ExternalEncoderRegistered(channel_num, 100)); |
| 1696 | EXPECT_EQ(1, vie_.GetNumExternalEncoderRegistered(channel_num)); |
| 1697 | EXPECT_EQ(1, encoder_factory_.GetNumCreatedEncoders()); |
| 1698 | |
| 1699 | // Remove stream previously added to free the external encoder instance. |
| 1700 | EXPECT_TRUE(channel_->RemoveSendStream(kSsrc)); |
| 1701 | } |
| 1702 | |
| 1703 | // Tests that OnReadyToSend will be propagated into ViE. |
| 1704 | TEST_F(WebRtcVideoEngineTestFake, OnReadyToSend) { |
| 1705 | EXPECT_TRUE(SetupEngine()); |
| 1706 | int channel_num = vie_.GetLastChannel(); |
| 1707 | EXPECT_TRUE(vie_.GetIsTransmitting(channel_num)); |
| 1708 | |
| 1709 | channel_->OnReadyToSend(false); |
| 1710 | EXPECT_FALSE(vie_.GetIsTransmitting(channel_num)); |
| 1711 | |
| 1712 | channel_->OnReadyToSend(true); |
| 1713 | EXPECT_TRUE(vie_.GetIsTransmitting(channel_num)); |
| 1714 | } |
| 1715 | |
| 1716 | #if 0 |
| 1717 | TEST_F(WebRtcVideoEngineTestFake, CaptureFrameTimestampToNtpTimestamp) { |
| 1718 | EXPECT_TRUE(SetupEngine()); |
| 1719 | int capture_id = vie_.GetCaptureId(vie_.GetLastChannel()); |
| 1720 | |
| 1721 | // Set send codec. |
| 1722 | cricket::VideoCodec codec(kVP8Codec); |
| 1723 | std::vector<cricket::VideoCodec> codec_list; |
| 1724 | codec_list.push_back(codec); |
| 1725 | EXPECT_TRUE(channel_->AddSendStream( |
| 1726 | cricket::StreamParams::CreateLegacy(123))); |
| 1727 | EXPECT_TRUE(channel_->SetSendCodecs(codec_list)); |
| 1728 | EXPECT_TRUE(channel_->SetSend(true)); |
| 1729 | |
| 1730 | int64 timestamp = time(NULL) * talk_base::kNumNanosecsPerSec; |
| 1731 | SendI420ScreencastFrameWithTimestamp( |
| 1732 | kVP8Codec.width, kVP8Codec.height, timestamp); |
| 1733 | EXPECT_EQ(talk_base::UnixTimestampNanosecsToNtpMillisecs(timestamp), |
| 1734 | vie_.GetCaptureLastTimestamp(capture_id)); |
| 1735 | |
| 1736 | SendI420ScreencastFrameWithTimestamp(kVP8Codec.width, kVP8Codec.height, 0); |
| 1737 | EXPECT_EQ(0, vie_.GetCaptureLastTimestamp(capture_id)); |
| 1738 | } |
| 1739 | #endif |
| 1740 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1741 | ///////////////////////// |
| 1742 | // Tests with real ViE // |
| 1743 | ///////////////////////// |
| 1744 | |
| 1745 | // Tests that we can find codecs by name or id. |
| 1746 | TEST_F(WebRtcVideoEngineTest, FindCodec) { |
| 1747 | // We should not need to init engine in order to get codecs. |
| 1748 | const std::vector<cricket::VideoCodec>& c = engine_.codecs(); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 1749 | EXPECT_EQ(4U, c.size()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1750 | |
| 1751 | cricket::VideoCodec vp8(104, "VP8", 320, 200, 30, 0); |
| 1752 | EXPECT_TRUE(engine_.FindCodec(vp8)); |
| 1753 | |
| 1754 | cricket::VideoCodec vp8_ci(104, "vp8", 320, 200, 30, 0); |
| 1755 | EXPECT_TRUE(engine_.FindCodec(vp8)); |
| 1756 | |
| 1757 | cricket::VideoCodec vp8_diff_fr_diff_pref(104, "VP8", 320, 200, 50, 50); |
| 1758 | EXPECT_TRUE(engine_.FindCodec(vp8_diff_fr_diff_pref)); |
| 1759 | |
| 1760 | cricket::VideoCodec vp8_diff_id(95, "VP8", 320, 200, 30, 0); |
| 1761 | EXPECT_FALSE(engine_.FindCodec(vp8_diff_id)); |
| 1762 | vp8_diff_id.id = 97; |
| 1763 | EXPECT_TRUE(engine_.FindCodec(vp8_diff_id)); |
| 1764 | |
| 1765 | cricket::VideoCodec vp8_diff_res(104, "VP8", 320, 111, 30, 0); |
| 1766 | EXPECT_FALSE(engine_.FindCodec(vp8_diff_res)); |
| 1767 | |
| 1768 | // PeerConnection doesn't negotiate the resolution at this point. |
| 1769 | // Test that FindCodec can handle the case when width/height is 0. |
| 1770 | cricket::VideoCodec vp8_zero_res(104, "VP8", 0, 0, 30, 0); |
| 1771 | EXPECT_TRUE(engine_.FindCodec(vp8_zero_res)); |
| 1772 | |
| 1773 | cricket::VideoCodec red(101, "RED", 0, 0, 30, 0); |
| 1774 | EXPECT_TRUE(engine_.FindCodec(red)); |
| 1775 | |
| 1776 | cricket::VideoCodec red_ci(101, "red", 0, 0, 30, 0); |
| 1777 | EXPECT_TRUE(engine_.FindCodec(red)); |
| 1778 | |
| 1779 | cricket::VideoCodec fec(102, "ULPFEC", 0, 0, 30, 0); |
| 1780 | EXPECT_TRUE(engine_.FindCodec(fec)); |
| 1781 | |
| 1782 | cricket::VideoCodec fec_ci(102, "ulpfec", 0, 0, 30, 0); |
| 1783 | EXPECT_TRUE(engine_.FindCodec(fec)); |
sergeyu@chromium.org | 5bc25c4 | 2013-12-05 00:24:06 +0000 | [diff] [blame] | 1784 | |
| 1785 | cricket::VideoCodec rtx(96, "rtx", 0, 0, 30, 0); |
| 1786 | EXPECT_TRUE(engine_.FindCodec(rtx)); |
| 1787 | } |
| 1788 | |
| 1789 | TEST_F(WebRtcVideoEngineTest, RtxCodecHasAptSet) { |
| 1790 | std::vector<cricket::VideoCodec>::const_iterator it; |
| 1791 | bool apt_checked = false; |
| 1792 | for (it = engine_.codecs().begin(); it != engine_.codecs().end(); ++it) { |
| 1793 | if (_stricmp(cricket::kRtxCodecName, it->name.c_str()) && it->id != 96) { |
| 1794 | continue; |
| 1795 | } |
| 1796 | int apt; |
| 1797 | EXPECT_TRUE(it->GetParam("apt", &apt)); |
| 1798 | EXPECT_EQ(100, apt); |
| 1799 | apt_checked = true; |
| 1800 | } |
| 1801 | EXPECT_TRUE(apt_checked); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1802 | } |
| 1803 | |
| 1804 | TEST_F(WebRtcVideoEngineTest, StartupShutdown) { |
| 1805 | EXPECT_TRUE(engine_.Init(talk_base::Thread::Current())); |
| 1806 | engine_.Terminate(); |
| 1807 | } |
| 1808 | |
| 1809 | TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec) |
| 1810 | TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainNewCodec) |
| 1811 | |
| 1812 | TEST_PRE_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec) |
| 1813 | TEST_POST_VIDEOENGINE_INIT(WebRtcVideoEngineTest, ConstrainRunningCodec) |
| 1814 | |
| 1815 | // TODO(juberti): Figure out why ViE is munging the COM refcount. |
| 1816 | #ifdef WIN32 |
| 1817 | TEST_F(WebRtcVideoEngineTest, DISABLED_CheckCoInitialize) { |
| 1818 | Base::CheckCoInitialize(); |
| 1819 | } |
| 1820 | #endif |
| 1821 | |
| 1822 | TEST_F(WebRtcVideoEngineTest, CreateChannel) { |
| 1823 | EXPECT_TRUE(engine_.Init(talk_base::Thread::Current())); |
| 1824 | cricket::VideoMediaChannel* channel = engine_.CreateChannel(NULL); |
| 1825 | EXPECT_TRUE(channel != NULL); |
| 1826 | delete channel; |
| 1827 | } |
| 1828 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1829 | TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecs) { |
| 1830 | std::vector<cricket::VideoCodec> codecs; |
| 1831 | codecs.push_back(kVP8Codec); |
| 1832 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 1833 | } |
| 1834 | TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsWrongPayloadType) { |
| 1835 | std::vector<cricket::VideoCodec> codecs; |
| 1836 | codecs.push_back(kVP8Codec); |
| 1837 | codecs[0].id = 99; |
| 1838 | EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); |
| 1839 | } |
| 1840 | TEST_F(WebRtcVideoMediaChannelTest, SetRecvCodecsUnsupportedCodec) { |
| 1841 | std::vector<cricket::VideoCodec> codecs; |
| 1842 | codecs.push_back(kVP8Codec); |
| 1843 | codecs.push_back(cricket::VideoCodec(101, "VP1", 640, 400, 30, 0)); |
| 1844 | EXPECT_FALSE(channel_->SetRecvCodecs(codecs)); |
| 1845 | } |
| 1846 | |
| 1847 | TEST_F(WebRtcVideoMediaChannelTest, SetSend) { |
| 1848 | Base::SetSend(); |
| 1849 | } |
| 1850 | TEST_F(WebRtcVideoMediaChannelTest, SetSendWithoutCodecs) { |
| 1851 | Base::SetSendWithoutCodecs(); |
| 1852 | } |
| 1853 | TEST_F(WebRtcVideoMediaChannelTest, SetSendSetsTransportBufferSizes) { |
| 1854 | Base::SetSendSetsTransportBufferSizes(); |
| 1855 | } |
| 1856 | |
| 1857 | TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Vga) { |
| 1858 | SendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30, 0)); |
| 1859 | } |
| 1860 | TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveVp8Qvga) { |
| 1861 | SendAndReceive(cricket::VideoCodec(100, "VP8", 320, 200, 30, 0)); |
| 1862 | } |
| 1863 | TEST_F(WebRtcVideoMediaChannelTest, SendAndReceiveH264SvcQqvga) { |
| 1864 | SendAndReceive(cricket::VideoCodec(100, "VP8", 160, 100, 30, 0)); |
| 1865 | } |
| 1866 | TEST_F(WebRtcVideoMediaChannelTest, SendManyResizeOnce) { |
| 1867 | SendManyResizeOnce(); |
| 1868 | } |
| 1869 | |
| 1870 | TEST_F(WebRtcVideoMediaChannelTest, SendVp8HdAndReceiveAdaptedVp8Vga) { |
henrike@webrtc.org | 28654cb | 2013-07-22 21:07:49 +0000 | [diff] [blame] | 1871 | EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1872 | channel_->UpdateAspectRatio(1280, 720); |
| 1873 | video_capturer_.reset(new cricket::FakeVideoCapturer); |
| 1874 | const std::vector<cricket::VideoFormat>* formats = |
| 1875 | video_capturer_->GetSupportedFormats(); |
| 1876 | cricket::VideoFormat capture_format_hd = (*formats)[0]; |
| 1877 | EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(capture_format_hd)); |
| 1878 | EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get())); |
| 1879 | |
| 1880 | // Capture format HD -> adapt (OnOutputFormatRequest VGA) -> VGA. |
| 1881 | cricket::VideoCodec codec(100, "VP8", 1280, 720, 30, 0); |
| 1882 | EXPECT_TRUE(SetOneCodec(codec)); |
| 1883 | codec.width /= 2; |
| 1884 | codec.height /= 2; |
| 1885 | EXPECT_TRUE(channel_->SetSendStreamFormat(kSsrc, cricket::VideoFormat( |
| 1886 | codec.width, codec.height, |
| 1887 | cricket::VideoFormat::FpsToInterval(codec.framerate), |
| 1888 | cricket::FOURCC_ANY))); |
| 1889 | EXPECT_TRUE(SetSend(true)); |
| 1890 | EXPECT_TRUE(channel_->SetRender(true)); |
| 1891 | EXPECT_EQ(0, renderer_.num_rendered_frames()); |
| 1892 | EXPECT_TRUE(SendFrame()); |
| 1893 | EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout); |
| 1894 | } |
| 1895 | |
| 1896 | // TODO(juberti): Fix this test to tolerate missing stats. |
| 1897 | TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStats) { |
| 1898 | Base::GetStats(); |
| 1899 | } |
| 1900 | |
| 1901 | // TODO(juberti): Fix this test to tolerate missing stats. |
| 1902 | TEST_F(WebRtcVideoMediaChannelTest, DISABLED_GetStatsMultipleRecvStreams) { |
| 1903 | Base::GetStatsMultipleRecvStreams(); |
| 1904 | } |
| 1905 | |
| 1906 | TEST_F(WebRtcVideoMediaChannelTest, GetStatsMultipleSendStreams) { |
| 1907 | Base::GetStatsMultipleSendStreams(); |
| 1908 | } |
| 1909 | |
| 1910 | TEST_F(WebRtcVideoMediaChannelTest, SetSendBandwidth) { |
| 1911 | Base::SetSendBandwidth(); |
| 1912 | } |
| 1913 | TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrc) { |
| 1914 | Base::SetSendSsrc(); |
| 1915 | } |
| 1916 | TEST_F(WebRtcVideoMediaChannelTest, SetSendSsrcAfterSetCodecs) { |
| 1917 | Base::SetSendSsrcAfterSetCodecs(); |
| 1918 | } |
| 1919 | |
| 1920 | TEST_F(WebRtcVideoMediaChannelTest, SetRenderer) { |
| 1921 | Base::SetRenderer(); |
| 1922 | } |
| 1923 | |
| 1924 | TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreams) { |
| 1925 | Base::AddRemoveRecvStreams(); |
| 1926 | } |
| 1927 | |
| 1928 | TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamAndRender) { |
| 1929 | Base::AddRemoveRecvStreamAndRender(); |
| 1930 | } |
| 1931 | |
| 1932 | TEST_F(WebRtcVideoMediaChannelTest, AddRemoveRecvStreamsNoConference) { |
| 1933 | Base::AddRemoveRecvStreamsNoConference(); |
| 1934 | } |
| 1935 | |
| 1936 | TEST_F(WebRtcVideoMediaChannelTest, AddRemoveSendStreams) { |
| 1937 | Base::AddRemoveSendStreams(); |
| 1938 | } |
| 1939 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1940 | TEST_F(WebRtcVideoMediaChannelTest, SimulateConference) { |
| 1941 | Base::SimulateConference(); |
| 1942 | } |
| 1943 | |
| 1944 | TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturer) { |
| 1945 | Base::AddRemoveCapturer(); |
| 1946 | } |
| 1947 | |
| 1948 | TEST_F(WebRtcVideoMediaChannelTest, RemoveCapturerWithoutAdd) { |
| 1949 | Base::RemoveCapturerWithoutAdd(); |
| 1950 | } |
| 1951 | |
| 1952 | TEST_F(WebRtcVideoMediaChannelTest, AddRemoveCapturerMultipleSources) { |
| 1953 | Base::AddRemoveCapturerMultipleSources(); |
| 1954 | } |
| 1955 | |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 1956 | // This test verifies DSCP settings are properly applied on video media channel. |
| 1957 | TEST_F(WebRtcVideoMediaChannelTest, TestSetDscpOptions) { |
| 1958 | talk_base::scoped_ptr<cricket::FakeNetworkInterface> network_interface( |
| 1959 | new cricket::FakeNetworkInterface); |
| 1960 | channel_->SetInterface(network_interface.get()); |
| 1961 | cricket::VideoOptions options; |
| 1962 | options.dscp.Set(true); |
| 1963 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 1964 | EXPECT_EQ(talk_base::DSCP_AF41, network_interface->dscp()); |
henrika@webrtc.org | aebb1ad | 2014-01-14 10:00:58 +0000 | [diff] [blame] | 1965 | // Verify previous value is not modified if dscp option is not set. |
| 1966 | cricket::VideoOptions options1; |
| 1967 | EXPECT_TRUE(channel_->SetOptions(options1)); |
| 1968 | EXPECT_EQ(talk_base::DSCP_AF41, network_interface->dscp()); |
wu@webrtc.org | de30501 | 2013-10-31 15:40:38 +0000 | [diff] [blame] | 1969 | options.dscp.Set(false); |
| 1970 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 1971 | EXPECT_EQ(talk_base::DSCP_DEFAULT, network_interface->dscp()); |
| 1972 | channel_->SetInterface(NULL); |
| 1973 | } |
| 1974 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1975 | |
| 1976 | TEST_F(WebRtcVideoMediaChannelTest, SetOptionsSucceedsWhenSending) { |
| 1977 | cricket::VideoOptions options; |
| 1978 | options.conference_mode.Set(true); |
| 1979 | EXPECT_TRUE(channel_->SetOptions(options)); |
| 1980 | |
| 1981 | // Verify SetOptions returns true on a different options. |
| 1982 | cricket::VideoOptions options2; |
| 1983 | options2.adapt_input_to_cpu_usage.Set(true); |
| 1984 | EXPECT_TRUE(channel_->SetOptions(options2)); |
| 1985 | |
| 1986 | // Set send codecs on the channel and start sending. |
| 1987 | std::vector<cricket::VideoCodec> codecs; |
| 1988 | codecs.push_back(kVP8Codec); |
| 1989 | EXPECT_TRUE(channel_->SetSendCodecs(codecs)); |
| 1990 | EXPECT_TRUE(channel_->SetSend(true)); |
| 1991 | |
| 1992 | // Verify SetOptions returns true if channel is already sending. |
| 1993 | cricket::VideoOptions options3; |
| 1994 | options3.conference_mode.Set(true); |
| 1995 | EXPECT_TRUE(channel_->SetOptions(options3)); |
| 1996 | } |
| 1997 | |
| 1998 | // Tests empty StreamParams is rejected. |
| 1999 | TEST_F(WebRtcVideoMediaChannelTest, RejectEmptyStreamParams) { |
| 2000 | Base::RejectEmptyStreamParams(); |
| 2001 | } |
| 2002 | |
| 2003 | |
| 2004 | TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution16x10) { |
| 2005 | Base::AdaptResolution16x10(); |
| 2006 | } |
| 2007 | |
| 2008 | TEST_F(WebRtcVideoMediaChannelTest, AdaptResolution4x3) { |
| 2009 | Base::AdaptResolution4x3(); |
| 2010 | } |
| 2011 | |
| 2012 | TEST_F(WebRtcVideoMediaChannelTest, MuteStream) { |
| 2013 | Base::MuteStream(); |
| 2014 | } |
| 2015 | |
| 2016 | TEST_F(WebRtcVideoMediaChannelTest, MultipleSendStreams) { |
| 2017 | Base::MultipleSendStreams(); |
| 2018 | } |
| 2019 | |
| 2020 | // TODO(juberti): Restore this test once we support sending 0 fps. |
| 2021 | TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptDropAllFrames) { |
| 2022 | Base::AdaptDropAllFrames(); |
| 2023 | } |
| 2024 | // TODO(juberti): Understand why we get decode errors on this test. |
| 2025 | TEST_F(WebRtcVideoMediaChannelTest, DISABLED_AdaptFramerate) { |
| 2026 | Base::AdaptFramerate(); |
| 2027 | } |
| 2028 | |
| 2029 | TEST_F(WebRtcVideoMediaChannelTest, SetSendStreamFormat0x0) { |
| 2030 | Base::SetSendStreamFormat0x0(); |
| 2031 | } |
| 2032 | |
| 2033 | // TODO(zhurunz): Fix the flakey test. |
| 2034 | TEST_F(WebRtcVideoMediaChannelTest, DISABLED_SetSendStreamFormat) { |
| 2035 | Base::SetSendStreamFormat(); |
| 2036 | } |
| 2037 | |
| 2038 | TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsSendAndReceive) { |
| 2039 | Base::TwoStreamsSendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30, |
| 2040 | 0)); |
| 2041 | } |
| 2042 | |
| 2043 | TEST_F(WebRtcVideoMediaChannelTest, TwoStreamsReUseFirstStream) { |
| 2044 | Base::TwoStreamsReUseFirstStream(cricket::VideoCodec(100, "VP8", 640, 400, 30, |
| 2045 | 0)); |
| 2046 | } |