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 <map> 29 #include <vector> 30 31 #include "talk/media/base/testutils.h" 32 #include "talk/media/base/videoengine_unittest.h" 33 #include "talk/media/webrtc/webrtcvideochannelfactory.h" 34 #include "talk/media/webrtc/webrtcvideoengine2.h" 35 #include "talk/media/webrtc/webrtcvideoengine2_unittest.h" 36 #include "webrtc/base/gunit.h" 37 #include "webrtc/base/stringutils.h" 38 39 namespace { 40 static const cricket::VideoCodec kVp8Codec720p(100, "VP8", 1280, 720, 30, 0); 41 static const cricket::VideoCodec kVp8Codec360p(100, "VP8", 640, 360, 30, 0); 42 static const cricket::VideoCodec kVp8Codec270p(100, "VP8", 480, 270, 30, 0); 43 static const cricket::VideoCodec kVp8Codec180p(100, "VP8", 320, 180, 30, 0); 44 45 static const cricket::VideoCodec kVp8Codec(100, "VP8", 640, 400, 30, 0); 46 static const cricket::VideoCodec kVp9Codec(101, "VP9", 640, 400, 30, 0); 47 static const cricket::VideoCodec kRedCodec(116, "red", 0, 0, 0, 0); 48 static const cricket::VideoCodec kUlpfecCodec(117, "ulpfec", 0, 0, 0, 0); 49 50 static const uint32 kSsrcs1[] = {1}; 51 static const uint32 kRtxSsrcs1[] = {4}; 52 static const char kUnsupportedExtensionName[] = 53 "urn:ietf:params:rtp-hdrext:unsupported"; 54 55 void VerifyCodecHasDefaultFeedbackParams(const cricket::VideoCodec& codec) { 56 EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( 57 cricket::kRtcpFbParamNack, cricket::kParamValueEmpty))); 58 EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( 59 cricket::kRtcpFbParamNack, cricket::kRtcpFbNackParamPli))); 60 EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( 61 cricket::kRtcpFbParamRemb, cricket::kParamValueEmpty))); 62 EXPECT_TRUE(codec.HasFeedbackParam(cricket::FeedbackParam( 63 cricket::kRtcpFbParamCcm, cricket::kRtcpFbCcmParamFir))); 64 } 65 66 } // namespace 67 68 namespace cricket { 69 FakeVideoSendStream::FakeVideoSendStream( 70 const webrtc::VideoSendStream::Config& config, 71 const webrtc::VideoEncoderConfig& encoder_config) 72 : sending_(false), config_(config), codec_settings_set_(false) { 73 assert(config.encoder_settings.encoder != NULL); 74 ReconfigureVideoEncoder(encoder_config); 75 } 76 77 webrtc::VideoSendStream::Config FakeVideoSendStream::GetConfig() { 78 return config_; 79 } 80 81 std::vector<webrtc::VideoStream> FakeVideoSendStream::GetVideoStreams() { 82 return encoder_config_.streams; 83 } 84 85 bool FakeVideoSendStream::IsSending() const { 86 return sending_; 87 } 88 89 bool FakeVideoSendStream::GetVp8Settings( 90 webrtc::VideoCodecVP8* settings) const { 91 if (!codec_settings_set_) { 92 return false; 93 } 94 95 *settings = vp8_settings_; 96 return true; 97 } 98 99 webrtc::VideoSendStream::Stats FakeVideoSendStream::GetStats() const { 100 return webrtc::VideoSendStream::Stats(); 101 } 102 103 bool FakeVideoSendStream::ReconfigureVideoEncoder( 104 const webrtc::VideoEncoderConfig& config) { 105 encoder_config_ = config; 106 if (config.encoder_specific_settings != NULL) { 107 assert(config_.encoder_settings.payload_name == "VP8"); 108 vp8_settings_ = *reinterpret_cast<const webrtc::VideoCodecVP8*>( 109 config.encoder_specific_settings); 110 } 111 codec_settings_set_ = config.encoder_specific_settings != NULL; 112 return true; 113 } 114 115 webrtc::VideoSendStreamInput* FakeVideoSendStream::Input() { 116 // TODO(pbos): Fix. 117 return NULL; 118 } 119 120 void FakeVideoSendStream::Start() { 121 sending_ = true; 122 } 123 124 void FakeVideoSendStream::Stop() { 125 sending_ = false; 126 } 127 128 FakeVideoReceiveStream::FakeVideoReceiveStream( 129 const webrtc::VideoReceiveStream::Config& config) 130 : config_(config), receiving_(false) { 131 } 132 133 webrtc::VideoReceiveStream::Config FakeVideoReceiveStream::GetConfig() { 134 return config_; 135 } 136 137 bool FakeVideoReceiveStream::IsReceiving() const { 138 return receiving_; 139 } 140 141 webrtc::VideoReceiveStream::Stats FakeVideoReceiveStream::GetStats() const { 142 return webrtc::VideoReceiveStream::Stats(); 143 } 144 145 void FakeVideoReceiveStream::Start() { 146 receiving_ = true; 147 } 148 149 void FakeVideoReceiveStream::Stop() { 150 receiving_ = false; 151 } 152 153 void FakeVideoReceiveStream::GetCurrentReceiveCodec(webrtc::VideoCodec* codec) { 154 } 155 156 FakeCall::FakeCall() : network_state_(kNetworkUp) { 157 SetVideoCodecs(GetDefaultVideoCodecs()); 158 } 159 160 FakeCall::~FakeCall() { 161 EXPECT_EQ(0u, video_send_streams_.size()); 162 EXPECT_EQ(0u, video_receive_streams_.size()); 163 } 164 165 void FakeCall::SetVideoCodecs(const std::vector<webrtc::VideoCodec> codecs) { 166 codecs_ = codecs; 167 } 168 169 std::vector<FakeVideoSendStream*> FakeCall::GetVideoSendStreams() { 170 return video_send_streams_; 171 } 172 173 std::vector<FakeVideoReceiveStream*> FakeCall::GetVideoReceiveStreams() { 174 return video_receive_streams_; 175 } 176 177 webrtc::VideoCodec FakeCall::GetEmptyVideoCodec() { 178 webrtc::VideoCodec codec; 179 codec.minBitrate = 300; 180 codec.startBitrate = 800; 181 codec.maxBitrate = 1500; 182 codec.maxFramerate = 10; 183 codec.width = 640; 184 codec.height = 480; 185 codec.qpMax = 56; 186 187 return codec; 188 } 189 190 webrtc::VideoCodec FakeCall::GetVideoCodecVp8() { 191 webrtc::VideoCodec vp8_codec = GetEmptyVideoCodec(); 192 vp8_codec.codecType = webrtc::kVideoCodecVP8; 193 rtc::strcpyn(vp8_codec.plName, ARRAY_SIZE(vp8_codec.plName), 194 kVp8Codec.name.c_str()); 195 vp8_codec.plType = kVp8Codec.id; 196 197 return vp8_codec; 198 } 199 200 webrtc::VideoCodec FakeCall::GetVideoCodecVp9() { 201 webrtc::VideoCodec vp9_codec = GetEmptyVideoCodec(); 202 // TODO(pbos): Add a correct codecType when webrtc has one. 203 vp9_codec.codecType = webrtc::kVideoCodecVP8; 204 rtc::strcpyn(vp9_codec.plName, ARRAY_SIZE(vp9_codec.plName), 205 kVp9Codec.name.c_str()); 206 vp9_codec.plType = kVp9Codec.id; 207 208 return vp9_codec; 209 } 210 211 std::vector<webrtc::VideoCodec> FakeCall::GetDefaultVideoCodecs() { 212 std::vector<webrtc::VideoCodec> codecs; 213 codecs.push_back(GetVideoCodecVp8()); 214 // codecs.push_back(GetVideoCodecVp9()); 215 216 return codecs; 217 } 218 219 webrtc::Call::NetworkState FakeCall::GetNetworkState() const { 220 return network_state_; 221 } 222 223 webrtc::VideoSendStream* FakeCall::CreateVideoSendStream( 224 const webrtc::VideoSendStream::Config& config, 225 const webrtc::VideoEncoderConfig& encoder_config) { 226 FakeVideoSendStream* fake_stream = 227 new FakeVideoSendStream(config, encoder_config); 228 video_send_streams_.push_back(fake_stream); 229 return fake_stream; 230 } 231 232 void FakeCall::DestroyVideoSendStream(webrtc::VideoSendStream* send_stream) { 233 FakeVideoSendStream* fake_stream = 234 static_cast<FakeVideoSendStream*>(send_stream); 235 for (size_t i = 0; i < video_send_streams_.size(); ++i) { 236 if (video_send_streams_[i] == fake_stream) { 237 delete video_send_streams_[i]; 238 video_send_streams_.erase(video_send_streams_.begin() + i); 239 return; 240 } 241 } 242 ADD_FAILURE() << "DestroyVideoSendStream called with unknown paramter."; 243 } 244 245 webrtc::VideoReceiveStream* FakeCall::CreateVideoReceiveStream( 246 const webrtc::VideoReceiveStream::Config& config) { 247 video_receive_streams_.push_back(new FakeVideoReceiveStream(config)); 248 return video_receive_streams_[video_receive_streams_.size() - 1]; 249 } 250 251 void FakeCall::DestroyVideoReceiveStream( 252 webrtc::VideoReceiveStream* receive_stream) { 253 FakeVideoReceiveStream* fake_stream = 254 static_cast<FakeVideoReceiveStream*>(receive_stream); 255 for (size_t i = 0; i < video_receive_streams_.size(); ++i) { 256 if (video_receive_streams_[i] == fake_stream) { 257 delete video_receive_streams_[i]; 258 video_receive_streams_.erase(video_receive_streams_.begin() + i); 259 return; 260 } 261 } 262 ADD_FAILURE() << "DestroyVideoReceiveStream called with unknown paramter."; 263 } 264 265 webrtc::PacketReceiver* FakeCall::Receiver() { 266 // TODO(pbos): Fix this. 267 return NULL; 268 } 269 270 uint32_t FakeCall::SendBitrateEstimate() { 271 return 0; 272 } 273 274 uint32_t FakeCall::ReceiveBitrateEstimate() { 275 return 0; 276 } 277 278 void FakeCall::SignalNetworkState(webrtc::Call::NetworkState state) { 279 network_state_ = state; 280 } 281 282 FakeWebRtcVideoChannel2::FakeWebRtcVideoChannel2( 283 FakeCall* call, 284 WebRtcVideoEngine2* engine, 285 VoiceMediaChannel* voice_channel) 286 : WebRtcVideoChannel2(call, engine, engine->GetVideoEncoderFactory()), 287 fake_call_(call), 288 voice_channel_(voice_channel) { 289 } 290 291 FakeWebRtcVideoChannel2::~FakeWebRtcVideoChannel2() { 292 } 293 294 VoiceMediaChannel* FakeWebRtcVideoChannel2::GetVoiceChannel() { 295 return voice_channel_; 296 } 297 298 FakeCall* FakeWebRtcVideoChannel2::GetFakeCall() { 299 return fake_call_; 300 } 301 302 FakeWebRtcVideoChannel2* FakeWebRtcVideoMediaChannelFactory::GetFakeChannel( 303 VideoMediaChannel* channel) { 304 return channel_map_[channel]; 305 } 306 307 WebRtcVideoChannel2* FakeWebRtcVideoMediaChannelFactory::Create( 308 WebRtcVideoEngine2* engine, 309 VoiceMediaChannel* voice_channel) { 310 FakeWebRtcVideoChannel2* channel = 311 new FakeWebRtcVideoChannel2(new FakeCall(), engine, voice_channel); 312 channel_map_[channel] = channel; 313 return channel; 314 } 315 316 class WebRtcVideoEngine2Test : public testing::Test { 317 public: 318 WebRtcVideoEngine2Test() { 319 engine_.SetChannelFactory(&factory_); 320 std::vector<VideoCodec> engine_codecs = engine_.codecs(); 321 assert(!engine_codecs.empty()); 322 bool codec_set = false; 323 for (size_t i = 0; i < engine_codecs.size(); ++i) { 324 if (engine_codecs[i].name == "red") { 325 default_red_codec_ = engine_codecs[i]; 326 } else if (engine_codecs[i].name == "ulpfec") { 327 default_ulpfec_codec_ = engine_codecs[i]; 328 } else if (engine_codecs[i].name == "rtx") { 329 default_rtx_codec_ = engine_codecs[i]; 330 } else if (!codec_set) { 331 default_codec_ = engine_codecs[i]; 332 codec_set = true; 333 } 334 } 335 336 assert(codec_set); 337 } 338 339 protected: 340 FakeWebRtcVideoMediaChannelFactory factory_; 341 WebRtcVideoEngine2 engine_; 342 VideoCodec default_codec_; 343 VideoCodec default_red_codec_; 344 VideoCodec default_ulpfec_codec_; 345 VideoCodec default_rtx_codec_; 346 }; 347 348 TEST_F(WebRtcVideoEngine2Test, CreateChannel) { 349 rtc::scoped_ptr<VideoMediaChannel> channel(engine_.CreateChannel(NULL)); 350 ASSERT_TRUE(channel.get() != NULL) << "Could not create channel."; 351 EXPECT_TRUE(factory_.GetFakeChannel(channel.get()) != NULL) 352 << "Channel not created through factory."; 353 } 354 355 TEST_F(WebRtcVideoEngine2Test, CreateChannelWithVoiceEngine) { 356 VoiceMediaChannel* voice_channel = reinterpret_cast<VoiceMediaChannel*>(0x42); 357 rtc::scoped_ptr<VideoMediaChannel> channel( 358 engine_.CreateChannel(voice_channel)); 359 ASSERT_TRUE(channel.get() != NULL) << "Could not create channel."; 360 361 FakeWebRtcVideoChannel2* fake_channel = 362 factory_.GetFakeChannel(channel.get()); 363 ASSERT_TRUE(fake_channel != NULL) << "Channel not created through factory."; 364 365 EXPECT_TRUE(fake_channel->GetVoiceChannel() != NULL) 366 << "VoiceChannel not set."; 367 EXPECT_EQ(voice_channel, fake_channel->GetVoiceChannel()) 368 << "Different VoiceChannel set than the provided one."; 369 } 370 371 TEST_F(WebRtcVideoEngine2Test, FindCodec) { 372 const std::vector<cricket::VideoCodec>& c = engine_.codecs(); 373 EXPECT_EQ(4U, c.size()); 374 375 cricket::VideoCodec vp8(104, "VP8", 320, 200, 30, 0); 376 EXPECT_TRUE(engine_.FindCodec(vp8)); 377 378 cricket::VideoCodec vp8_ci(104, "vp8", 320, 200, 30, 0); 379 EXPECT_TRUE(engine_.FindCodec(vp8)); 380 381 cricket::VideoCodec vp8_diff_fr_diff_pref(104, "VP8", 320, 200, 50, 50); 382 EXPECT_TRUE(engine_.FindCodec(vp8_diff_fr_diff_pref)); 383 384 cricket::VideoCodec vp8_diff_id(95, "VP8", 320, 200, 30, 0); 385 EXPECT_FALSE(engine_.FindCodec(vp8_diff_id)); 386 vp8_diff_id.id = 97; 387 EXPECT_TRUE(engine_.FindCodec(vp8_diff_id)); 388 389 // FindCodec ignores the codec size. 390 // Test that FindCodec can accept uncommon codec size. 391 cricket::VideoCodec vp8_diff_res(104, "VP8", 320, 111, 30, 0); 392 EXPECT_TRUE(engine_.FindCodec(vp8_diff_res)); 393 394 // PeerConnection doesn't negotiate the resolution at this point. 395 // Test that FindCodec can handle the case when width/height is 0. 396 cricket::VideoCodec vp8_zero_res(104, "VP8", 0, 0, 30, 0); 397 EXPECT_TRUE(engine_.FindCodec(vp8_zero_res)); 398 399 cricket::VideoCodec red(101, "RED", 0, 0, 30, 0); 400 EXPECT_TRUE(engine_.FindCodec(red)); 401 402 cricket::VideoCodec red_ci(101, "red", 0, 0, 30, 0); 403 EXPECT_TRUE(engine_.FindCodec(red)); 404 405 cricket::VideoCodec fec(102, "ULPFEC", 0, 0, 30, 0); 406 EXPECT_TRUE(engine_.FindCodec(fec)); 407 408 cricket::VideoCodec fec_ci(102, "ulpfec", 0, 0, 30, 0); 409 EXPECT_TRUE(engine_.FindCodec(fec)); 410 411 cricket::VideoCodec rtx(96, "rtx", 0, 0, 30, 0); 412 EXPECT_TRUE(engine_.FindCodec(rtx)); 413 } 414 415 TEST_F(WebRtcVideoEngine2Test, DefaultRtxCodecHasAssociatedPayloadTypeSet) { 416 std::vector<VideoCodec> engine_codecs = engine_.codecs(); 417 for (size_t i = 0; i < engine_codecs.size(); ++i) { 418 if (engine_codecs[i].name != kRtxCodecName) 419 continue; 420 int associated_payload_type; 421 EXPECT_TRUE(engine_codecs[i].GetParam(kCodecParamAssociatedPayloadType, 422 &associated_payload_type)); 423 EXPECT_EQ(default_codec_.id, associated_payload_type); 424 return; 425 } 426 FAIL() << "No RTX codec found among default codecs."; 427 } 428 429 TEST_F(WebRtcVideoEngine2Test, SupportsTimestampOffsetHeaderExtension) { 430 std::vector<RtpHeaderExtension> extensions = engine_.rtp_header_extensions(); 431 ASSERT_FALSE(extensions.empty()); 432 for (size_t i = 0; i < extensions.size(); ++i) { 433 if (extensions[i].uri == kRtpTimestampOffsetHeaderExtension) { 434 EXPECT_EQ(kRtpTimestampOffsetHeaderExtensionDefaultId, extensions[i].id); 435 return; 436 } 437 } 438 FAIL() << "Timestamp offset extension not in header-extension list."; 439 } 440 441 TEST_F(WebRtcVideoEngine2Test, SupportsAbsoluteSenderTimeHeaderExtension) { 442 std::vector<RtpHeaderExtension> extensions = engine_.rtp_header_extensions(); 443 ASSERT_FALSE(extensions.empty()); 444 for (size_t i = 0; i < extensions.size(); ++i) { 445 if (extensions[i].uri == kRtpAbsoluteSenderTimeHeaderExtension) { 446 EXPECT_EQ(kRtpAbsoluteSenderTimeHeaderExtensionDefaultId, 447 extensions[i].id); 448 return; 449 } 450 } 451 FAIL() << "Absolute Sender Time extension not in header-extension list."; 452 } 453 454 TEST_F(WebRtcVideoEngine2Test, SetSendFailsBeforeSettingCodecs) { 455 rtc::scoped_ptr<VideoMediaChannel> channel(engine_.CreateChannel(NULL)); 456 457 EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(123))); 458 459 EXPECT_FALSE(channel->SetSend(true)) 460 << "Channel should not start without codecs."; 461 EXPECT_TRUE(channel->SetSend(false)) 462 << "Channel should be stoppable even without set codecs."; 463 } 464 465 TEST_F(WebRtcVideoEngine2Test, GetStatsWithoutSendCodecsSetDoesNotCrash) { 466 rtc::scoped_ptr<VideoMediaChannel> channel(engine_.CreateChannel(NULL)); 467 EXPECT_TRUE(channel->AddSendStream(StreamParams::CreateLegacy(123))); 468 VideoMediaInfo info; 469 channel->GetStats(&info); 470 } 471 472 class WebRtcVideoEngine2BaseTest 473 : public VideoEngineTest<cricket::WebRtcVideoEngine2> { 474 protected: 475 typedef VideoEngineTest<cricket::WebRtcVideoEngine2> Base; 476 }; 477 478 #define WEBRTC_ENGINE_BASE_TEST(test) \ 479 TEST_F(WebRtcVideoEngine2BaseTest, test) { Base::test##Body(); } 480 481 WEBRTC_ENGINE_BASE_TEST(ConstrainNewCodec2); 482 483 class WebRtcVideoChannel2BaseTest 484 : public VideoMediaChannelTest<WebRtcVideoEngine2, WebRtcVideoChannel2> { 485 protected: 486 virtual cricket::VideoCodec DefaultCodec() OVERRIDE { return kVp8Codec; } 487 typedef VideoMediaChannelTest<WebRtcVideoEngine2, WebRtcVideoChannel2> Base; 488 }; 489 490 #define WEBRTC_BASE_TEST(test) \ 491 TEST_F(WebRtcVideoChannel2BaseTest, test) { Base::test(); } 492 493 #define WEBRTC_DISABLED_BASE_TEST(test) \ 494 TEST_F(WebRtcVideoChannel2BaseTest, DISABLED_ ## test) { Base::test(); } 495 496 // TODO(pbos): Fix WebRtcVideoEngine2BaseTest, where we want CheckCoInitialize. 497 #if 0 498 // TODO(juberti): Figure out why ViE is munging the COM refcount. 499 #ifdef WIN32 500 WEBRTC_DISABLED_BASE_TEST(CheckCoInitialize) { 501 Base::CheckCoInitialize(); 502 } 503 #endif 504 #endif 505 506 WEBRTC_BASE_TEST(SetSend); 507 WEBRTC_BASE_TEST(SetSendWithoutCodecs); 508 WEBRTC_BASE_TEST(SetSendSetsTransportBufferSizes); 509 510 WEBRTC_BASE_TEST(GetStats); 511 WEBRTC_BASE_TEST(GetStatsMultipleRecvStreams); 512 WEBRTC_BASE_TEST(GetStatsMultipleSendStreams); 513 514 WEBRTC_BASE_TEST(SetSendBandwidth); 515 516 WEBRTC_BASE_TEST(SetSendSsrc); 517 WEBRTC_BASE_TEST(SetSendSsrcAfterSetCodecs); 518 519 WEBRTC_BASE_TEST(SetRenderer); 520 WEBRTC_BASE_TEST(AddRemoveRecvStreams); 521 522 WEBRTC_DISABLED_BASE_TEST(AddRemoveRecvStreamAndRender); 523 524 WEBRTC_BASE_TEST(AddRemoveRecvStreamsNoConference); 525 526 WEBRTC_BASE_TEST(AddRemoveSendStreams); 527 528 WEBRTC_BASE_TEST(SimulateConference); 529 530 WEBRTC_BASE_TEST(AddRemoveCapturer); 531 532 WEBRTC_BASE_TEST(RemoveCapturerWithoutAdd); 533 534 WEBRTC_BASE_TEST(AddRemoveCapturerMultipleSources); 535 536 // TODO(pbos): Figure out why this fails so often. 537 WEBRTC_DISABLED_BASE_TEST(HighAspectHighHeightCapturer); 538 539 WEBRTC_BASE_TEST(RejectEmptyStreamParams); 540 541 WEBRTC_BASE_TEST(AdaptResolution16x10); 542 543 WEBRTC_BASE_TEST(AdaptResolution4x3); 544 545 // TODO(juberti): Restore this test once we support sending 0 fps. 546 WEBRTC_DISABLED_BASE_TEST(AdaptDropAllFrames); 547 // TODO(juberti): Understand why we get decode errors on this test. 548 WEBRTC_DISABLED_BASE_TEST(AdaptFramerate); 549 550 WEBRTC_BASE_TEST(SendsLowerResolutionOnSmallerFrames); 551 552 WEBRTC_BASE_TEST(MuteStream); 553 554 WEBRTC_BASE_TEST(MultipleSendStreams); 555 556 WEBRTC_BASE_TEST(SetSendStreamFormat0x0); 557 558 // TODO(zhurunz): Fix the flakey test. 559 WEBRTC_DISABLED_BASE_TEST(SetSendStreamFormat); 560 561 TEST_F(WebRtcVideoChannel2BaseTest, SendAndReceiveVp8Vga) { 562 SendAndReceive(cricket::VideoCodec(100, "VP8", 640, 400, 30, 0)); 563 } 564 565 TEST_F(WebRtcVideoChannel2BaseTest, SendAndReceiveVp8Qvga) { 566 SendAndReceive(cricket::VideoCodec(100, "VP8", 320, 200, 30, 0)); 567 } 568 569 TEST_F(WebRtcVideoChannel2BaseTest, SendAndReceiveVp8SvcQqvga) { 570 SendAndReceive(cricket::VideoCodec(100, "VP8", 160, 100, 30, 0)); 571 } 572 573 TEST_F(WebRtcVideoChannel2BaseTest, TwoStreamsSendAndReceive) { 574 Base::TwoStreamsSendAndReceive(kVp8Codec); 575 } 576 577 TEST_F(WebRtcVideoChannel2BaseTest, TwoStreamsReUseFirstStream) { 578 Base::TwoStreamsReUseFirstStream(kVp8Codec); 579 } 580 581 WEBRTC_BASE_TEST(SendManyResizeOnce); 582 583 // TODO(pbos): Enable and figure out why this fails (or should work). 584 TEST_F(WebRtcVideoChannel2BaseTest, DISABLED_SendVp8HdAndReceiveAdaptedVp8Vga) { 585 EXPECT_TRUE(channel_->SetCapturer(kSsrc, NULL)); 586 EXPECT_TRUE(channel_->SetRenderer(kDefaultReceiveSsrc, &renderer_)); 587 channel_->UpdateAspectRatio(1280, 720); 588 video_capturer_.reset(new cricket::FakeVideoCapturer); 589 const std::vector<cricket::VideoFormat>* formats = 590 video_capturer_->GetSupportedFormats(); 591 cricket::VideoFormat capture_format_hd = (*formats)[0]; 592 EXPECT_EQ(cricket::CS_RUNNING, video_capturer_->Start(capture_format_hd)); 593 EXPECT_TRUE(channel_->SetCapturer(kSsrc, video_capturer_.get())); 594 595 // Capture format HD -> adapt (OnOutputFormatRequest VGA) -> VGA. 596 cricket::VideoCodec codec(100, "VP8", 1280, 720, 30, 0); 597 EXPECT_TRUE(SetOneCodec(codec)); 598 codec.width /= 2; 599 codec.height /= 2; 600 EXPECT_TRUE(SetSend(true)); 601 EXPECT_TRUE(channel_->SetRender(true)); 602 EXPECT_EQ(0, renderer_.num_rendered_frames()); 603 EXPECT_TRUE(SendFrame()); 604 EXPECT_FRAME_WAIT(1, codec.width, codec.height, kTimeout); 605 } 606 607 class WebRtcVideoChannel2Test : public WebRtcVideoEngine2Test { 608 public: 609 virtual void SetUp() OVERRIDE { 610 channel_.reset(engine_.CreateChannel(NULL)); 611 fake_channel_ = factory_.GetFakeChannel(channel_.get()); 612 last_ssrc_ = 123; 613 ASSERT_TRUE(fake_channel_ != NULL) 614 << "Channel not created through factory."; 615 EXPECT_TRUE(fake_channel_->SetSendCodecs(engine_.codecs())); 616 } 617 618 protected: 619 FakeVideoSendStream* AddSendStream() { 620 return AddSendStream(StreamParams::CreateLegacy(last_ssrc_++)); 621 } 622 623 FakeVideoSendStream* AddSendStream(const StreamParams& sp) { 624 size_t num_streams = 625 fake_channel_->GetFakeCall()->GetVideoSendStreams().size(); 626 EXPECT_TRUE(channel_->AddSendStream(sp)); 627 std::vector<FakeVideoSendStream*> streams = 628 fake_channel_->GetFakeCall()->GetVideoSendStreams(); 629 EXPECT_EQ(num_streams + 1, streams.size()); 630 return streams[streams.size() - 1]; 631 } 632 633 std::vector<FakeVideoSendStream*> GetFakeSendStreams() { 634 return fake_channel_->GetFakeCall()->GetVideoSendStreams(); 635 } 636 637 FakeVideoReceiveStream* AddRecvStream() { 638 return AddRecvStream(StreamParams::CreateLegacy(last_ssrc_++)); 639 } 640 641 FakeVideoReceiveStream* AddRecvStream(const StreamParams& sp) { 642 size_t num_streams = 643 fake_channel_->GetFakeCall()->GetVideoReceiveStreams().size(); 644 EXPECT_TRUE(channel_->AddRecvStream(sp)); 645 std::vector<FakeVideoReceiveStream*> streams = 646 fake_channel_->GetFakeCall()->GetVideoReceiveStreams(); 647 EXPECT_EQ(num_streams + 1, streams.size()); 648 return streams[streams.size() - 1]; 649 } 650 651 void SetSendCodecsShouldWorkForBitrates(const char* min_bitrate, 652 const char* max_bitrate) { 653 std::vector<VideoCodec> codecs; 654 codecs.push_back(kVp8Codec); 655 codecs[0].params[kCodecParamMinBitrate] = min_bitrate; 656 codecs[0].params[kCodecParamMaxBitrate] = max_bitrate; 657 EXPECT_TRUE(channel_->SetSendCodecs(codecs)); 658 659 FakeVideoSendStream* stream = AddSendStream(); 660 661 std::vector<webrtc::VideoStream> video_streams = stream->GetVideoStreams(); 662 ASSERT_EQ(1u, video_streams.size()); 663 EXPECT_EQ(atoi(min_bitrate), video_streams.back().min_bitrate_bps / 1000); 664 EXPECT_EQ(atoi(max_bitrate), video_streams.back().max_bitrate_bps / 1000); 665 666 VideoCodec codec; 667 EXPECT_TRUE(channel_->GetSendCodec(&codec)); 668 EXPECT_EQ(min_bitrate, codec.params[kCodecParamMinBitrate]); 669 EXPECT_EQ(max_bitrate, codec.params[kCodecParamMaxBitrate]); 670 } 671 672 void TestSetSendRtpHeaderExtensions(const std::string& cricket_ext, 673 const std::string& webrtc_ext) { 674 FakeCall* call = fake_channel_->GetFakeCall(); 675 // Enable extension. 676 const int id = 1; 677 std::vector<cricket::RtpHeaderExtension> extensions; 678 extensions.push_back(cricket::RtpHeaderExtension(cricket_ext, id)); 679 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions)); 680 681 FakeVideoSendStream* send_stream = 682 AddSendStream(cricket::StreamParams::CreateLegacy(123)); 683 684 // Verify the send extension id. 685 ASSERT_EQ(1u, send_stream->GetConfig().rtp.extensions.size()); 686 EXPECT_EQ(id, send_stream->GetConfig().rtp.extensions[0].id); 687 EXPECT_EQ(webrtc_ext, send_stream->GetConfig().rtp.extensions[0].name); 688 // Verify call with same set of extensions returns true. 689 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions)); 690 // Verify that SetSendRtpHeaderExtensions doesn't implicitly add them for 691 // receivers. 692 EXPECT_TRUE(AddRecvStream(cricket::StreamParams::CreateLegacy(123)) 693 ->GetConfig() 694 .rtp.extensions.empty()); 695 696 // Verify that existing RTP header extensions can be removed. 697 std::vector<cricket::RtpHeaderExtension> empty_extensions; 698 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(empty_extensions)); 699 ASSERT_EQ(1u, call->GetVideoSendStreams().size()); 700 send_stream = call->GetVideoSendStreams()[0]; 701 EXPECT_TRUE(send_stream->GetConfig().rtp.extensions.empty()); 702 703 // Verify that adding receive RTP header extensions adds them for existing 704 // streams. 705 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions)); 706 send_stream = call->GetVideoSendStreams()[0]; 707 ASSERT_EQ(1u, send_stream->GetConfig().rtp.extensions.size()); 708 EXPECT_EQ(id, send_stream->GetConfig().rtp.extensions[0].id); 709 EXPECT_EQ(webrtc_ext, send_stream->GetConfig().rtp.extensions[0].name); 710 } 711 712 void TestSetRecvRtpHeaderExtensions(const std::string& cricket_ext, 713 const std::string& webrtc_ext) { 714 FakeCall* call = fake_channel_->GetFakeCall(); 715 // Enable extension. 716 const int id = 1; 717 std::vector<cricket::RtpHeaderExtension> extensions; 718 extensions.push_back(cricket::RtpHeaderExtension(cricket_ext, id)); 719 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions)); 720 721 FakeVideoReceiveStream* recv_stream = 722 AddRecvStream(cricket::StreamParams::CreateLegacy(123)); 723 724 // Verify the recv extension id. 725 ASSERT_EQ(1u, recv_stream->GetConfig().rtp.extensions.size()); 726 EXPECT_EQ(id, recv_stream->GetConfig().rtp.extensions[0].id); 727 EXPECT_EQ(webrtc_ext, recv_stream->GetConfig().rtp.extensions[0].name); 728 // Verify call with same set of extensions returns true. 729 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions)); 730 731 // Verify that SetRecvRtpHeaderExtensions doesn't implicitly add them for 732 // senders. 733 EXPECT_TRUE(AddSendStream(cricket::StreamParams::CreateLegacy(123)) 734 ->GetConfig() 735 .rtp.extensions.empty()); 736 737 // Verify that existing RTP header extensions can be removed. 738 std::vector<cricket::RtpHeaderExtension> empty_extensions; 739 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(empty_extensions)); 740 ASSERT_EQ(1u, call->GetVideoReceiveStreams().size()); 741 recv_stream = call->GetVideoReceiveStreams()[0]; 742 EXPECT_TRUE(recv_stream->GetConfig().rtp.extensions.empty()); 743 744 // Verify that adding receive RTP header extensions adds them for existing 745 // streams. 746 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions)); 747 recv_stream = call->GetVideoReceiveStreams()[0]; 748 ASSERT_EQ(1u, recv_stream->GetConfig().rtp.extensions.size()); 749 EXPECT_EQ(id, recv_stream->GetConfig().rtp.extensions[0].id); 750 EXPECT_EQ(webrtc_ext, recv_stream->GetConfig().rtp.extensions[0].name); 751 } 752 753 rtc::scoped_ptr<VideoMediaChannel> channel_; 754 FakeWebRtcVideoChannel2* fake_channel_; 755 uint32 last_ssrc_; 756 }; 757 758 TEST_F(WebRtcVideoChannel2Test, DISABLED_MaxBitrateResetsWithConferenceMode) { 759 FAIL() << "Not implemented."; // TODO(pbos): Implement. 760 } 761 762 TEST_F(WebRtcVideoChannel2Test, DISABLED_StartSendBitrate) { 763 // TODO(pbos): Is this test testing vie_ ? this is confusing. No API to set 764 // start send bitrate from outside? Add defaults here that should be kept? 765 std::vector<cricket::VideoCodec> codec_list; 766 codec_list.push_back(kVp8Codec); 767 EXPECT_TRUE(channel_->SetSendCodecs(codec_list)); 768 const unsigned int kVideoMinSendBitrateKbps = 50; 769 const unsigned int kVideoTargetSendBitrateKbps = 300; 770 const unsigned int kVideoMaxSendBitrateKbps = 2000; 771 FakeVideoSendStream* stream = AddSendStream(); 772 std::vector<webrtc::VideoStream> video_streams = stream->GetVideoStreams(); 773 ASSERT_EQ(1u, video_streams.size()); 774 EXPECT_EQ(kVideoMinSendBitrateKbps, 775 video_streams.back().min_bitrate_bps / 1000); 776 EXPECT_EQ(kVideoTargetSendBitrateKbps, 777 video_streams.back().target_bitrate_bps / 1000); 778 EXPECT_EQ(kVideoMaxSendBitrateKbps, 779 video_streams.back().max_bitrate_bps / 1000); 780 #if 0 781 // TODO(pbos): un-#if 782 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0, 783 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps, 784 kVideoDefaultStartSendBitrateKbps); 785 EXPECT_EQ(0, vie_.StartSend(send_channel)); 786 787 // Increase the send bitrate and verify it is used as start bitrate. 788 const unsigned int kVideoSendBitrateBps = 768000; 789 vie_.SetSendBitrates(send_channel, kVideoSendBitrateBps, 0, 0); 790 EXPECT_TRUE(channel_->SetSendCodecs(codec_list)); 791 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0, 792 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps, 793 kVideoSendBitrateBps / 1000); 794 795 // Never set a start bitrate higher than the max bitrate. 796 vie_.SetSendBitrates(send_channel, kVideoMaxSendBitrateKbps + 500, 0, 0); 797 EXPECT_TRUE(channel_->SetSendCodecs(codec_list)); 798 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0, 799 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps, 800 kVideoDefaultStartSendBitrateKbps); 801 802 // Use the default start bitrate if the send bitrate is lower. 803 vie_.SetSendBitrates(send_channel, kVideoDefaultStartSendBitrateKbps - 50, 0, 804 0); 805 EXPECT_TRUE(channel_->SetSendCodecs(codec_list)); 806 VerifyVP8SendCodec(send_channel, kVP8Codec.width, kVP8Codec.height, 0, 807 kVideoMaxSendBitrateKbps, kVideoMinSendBitrateKbps, 808 kVideoDefaultStartSendBitrateKbps); 809 #endif 810 } 811 812 TEST_F(WebRtcVideoChannel2Test, RecvStreamWithSimAndRtx) { 813 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); 814 EXPECT_TRUE(channel_->SetSend(true)); 815 cricket::VideoOptions options; 816 options.conference_mode.Set(true); 817 EXPECT_TRUE(channel_->SetOptions(options)); 818 819 // Send side. 820 const std::vector<uint32> ssrcs = MAKE_VECTOR(kSsrcs1); 821 const std::vector<uint32> rtx_ssrcs = MAKE_VECTOR(kRtxSsrcs1); 822 FakeVideoSendStream* send_stream = AddSendStream( 823 cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); 824 825 ASSERT_EQ(rtx_ssrcs.size(), send_stream->GetConfig().rtp.rtx.ssrcs.size()); 826 for (size_t i = 0; i < rtx_ssrcs.size(); ++i) 827 EXPECT_EQ(rtx_ssrcs[i], send_stream->GetConfig().rtp.rtx.ssrcs[i]); 828 829 // Receiver side. 830 FakeVideoReceiveStream* recv_stream = AddRecvStream( 831 cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); 832 ASSERT_GT(recv_stream->GetConfig().rtp.rtx.size(), 0u) 833 << "No SSRCs for RTX configured by AddRecvStream."; 834 ASSERT_EQ(1u, recv_stream->GetConfig().rtp.rtx.size()) 835 << "This test only works with one receive codec. Please update the test."; 836 EXPECT_EQ(rtx_ssrcs[0], 837 recv_stream->GetConfig().rtp.rtx.begin()->second.ssrc); 838 // TODO(pbos): Make sure we set the RTX for correct payloads etc. 839 } 840 841 TEST_F(WebRtcVideoChannel2Test, RecvStreamWithRtx) { 842 // Setup one channel with an associated RTX stream. 843 cricket::StreamParams params = 844 cricket::StreamParams::CreateLegacy(kSsrcs1[0]); 845 params.AddFidSsrc(kSsrcs1[0], kRtxSsrcs1[0]); 846 FakeVideoReceiveStream* recv_stream = AddRecvStream(params); 847 ASSERT_EQ(1u, recv_stream->GetConfig().rtp.rtx.size()); 848 EXPECT_EQ(kRtxSsrcs1[0], 849 recv_stream->GetConfig().rtp.rtx.begin()->second.ssrc); 850 } 851 852 TEST_F(WebRtcVideoChannel2Test, RecvStreamNoRtx) { 853 // Setup one channel without an associated RTX stream. 854 cricket::StreamParams params = 855 cricket::StreamParams::CreateLegacy(kSsrcs1[0]); 856 FakeVideoReceiveStream* recv_stream = AddRecvStream(params); 857 ASSERT_TRUE(recv_stream->GetConfig().rtp.rtx.empty()); 858 } 859 860 TEST_F(WebRtcVideoChannel2Test, NoHeaderExtesionsByDefault) { 861 FakeVideoSendStream* send_stream = 862 AddSendStream(cricket::StreamParams::CreateLegacy(kSsrcs1[0])); 863 ASSERT_TRUE(send_stream->GetConfig().rtp.extensions.empty()); 864 865 FakeVideoReceiveStream* recv_stream = 866 AddRecvStream(cricket::StreamParams::CreateLegacy(kSsrcs1[0])); 867 ASSERT_TRUE(recv_stream->GetConfig().rtp.extensions.empty()); 868 } 869 870 // Test support for RTP timestamp offset header extension. 871 TEST_F(WebRtcVideoChannel2Test, SendRtpTimestampOffsetHeaderExtensions) { 872 TestSetSendRtpHeaderExtensions(kRtpTimestampOffsetHeaderExtension, 873 webrtc::RtpExtension::kTOffset); 874 } 875 TEST_F(WebRtcVideoChannel2Test, RecvRtpTimestampOffsetHeaderExtensions) { 876 TestSetRecvRtpHeaderExtensions(kRtpTimestampOffsetHeaderExtension, 877 webrtc::RtpExtension::kTOffset); 878 } 879 880 // Test support for absolute send time header extension. 881 TEST_F(WebRtcVideoChannel2Test, SendAbsoluteSendTimeHeaderExtensions) { 882 TestSetSendRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension, 883 webrtc::RtpExtension::kAbsSendTime); 884 } 885 TEST_F(WebRtcVideoChannel2Test, RecvAbsoluteSendTimeHeaderExtensions) { 886 TestSetRecvRtpHeaderExtensions(kRtpAbsoluteSenderTimeHeaderExtension, 887 webrtc::RtpExtension::kAbsSendTime); 888 } 889 890 TEST_F(WebRtcVideoChannel2Test, 891 SetSendRtpHeaderExtensionsExcludeUnsupportedExtensions) { 892 const int kUnsupportedId = 1; 893 const int kTOffsetId = 2; 894 895 std::vector<cricket::RtpHeaderExtension> extensions; 896 extensions.push_back(cricket::RtpHeaderExtension( 897 kUnsupportedExtensionName, kUnsupportedId)); 898 extensions.push_back(cricket::RtpHeaderExtension( 899 webrtc::RtpExtension::kTOffset, kTOffsetId)); 900 EXPECT_TRUE(channel_->SetSendRtpHeaderExtensions(extensions)); 901 FakeVideoSendStream* send_stream = 902 AddSendStream(cricket::StreamParams::CreateLegacy(123)); 903 904 // Only timestamp offset extension is set to send stream, 905 // unsupported rtp extension is ignored. 906 ASSERT_EQ(1u, send_stream->GetConfig().rtp.extensions.size()); 907 EXPECT_STREQ(webrtc::RtpExtension::kTOffset, 908 send_stream->GetConfig().rtp.extensions[0].name.c_str()); 909 } 910 911 TEST_F(WebRtcVideoChannel2Test, 912 SetRecvRtpHeaderExtensionsExcludeUnsupportedExtensions) { 913 const int kUnsupportedId = 1; 914 const int kTOffsetId = 2; 915 916 std::vector<cricket::RtpHeaderExtension> extensions; 917 extensions.push_back(cricket::RtpHeaderExtension( 918 kUnsupportedExtensionName, kUnsupportedId)); 919 extensions.push_back(cricket::RtpHeaderExtension( 920 webrtc::RtpExtension::kTOffset, kTOffsetId)); 921 EXPECT_TRUE(channel_->SetRecvRtpHeaderExtensions(extensions)); 922 FakeVideoReceiveStream* recv_stream = 923 AddRecvStream(cricket::StreamParams::CreateLegacy(123)); 924 925 // Only timestamp offset extension is set to receive stream, 926 // unsupported rtp extension is ignored. 927 ASSERT_EQ(1u, recv_stream->GetConfig().rtp.extensions.size()); 928 EXPECT_STREQ(webrtc::RtpExtension::kTOffset, 929 recv_stream->GetConfig().rtp.extensions[0].name.c_str()); 930 } 931 932 TEST_F(WebRtcVideoChannel2Test, 933 SetSendRtpHeaderExtensionsRejectsIncorrectIds) { 934 const size_t kNumIncorrectIds = 4; 935 const int kIncorrectIds[kNumIncorrectIds] = {-2, -1, 15, 16}; 936 for (size_t i = 0; i < kNumIncorrectIds; ++i) { 937 std::vector<cricket::RtpHeaderExtension> extensions; 938 extensions.push_back(cricket::RtpHeaderExtension( 939 webrtc::RtpExtension::kTOffset, kIncorrectIds[i])); 940 EXPECT_FALSE(channel_->SetSendRtpHeaderExtensions(extensions)) 941 << "Bad extension id '" << kIncorrectIds[i] << "' accepted."; 942 } 943 } 944 945 TEST_F(WebRtcVideoChannel2Test, 946 SetRecvRtpHeaderExtensionsRejectsIncorrectIds) { 947 const size_t kNumIncorrectIds = 4; 948 const int kIncorrectIds[kNumIncorrectIds] = {-2, -1, 15, 16}; 949 for (size_t i = 0; i < kNumIncorrectIds; ++i) { 950 std::vector<cricket::RtpHeaderExtension> extensions; 951 extensions.push_back(cricket::RtpHeaderExtension( 952 webrtc::RtpExtension::kTOffset, kIncorrectIds[i])); 953 EXPECT_FALSE(channel_->SetRecvRtpHeaderExtensions(extensions)) 954 << "Bad extension id '" << kIncorrectIds[i] << "' accepted."; 955 } 956 } 957 958 TEST_F(WebRtcVideoChannel2Test, 959 SetSendRtpHeaderExtensionsRejectsDuplicateIds) { 960 const int id = 1; 961 std::vector<cricket::RtpHeaderExtension> extensions; 962 extensions.push_back(cricket::RtpHeaderExtension( 963 webrtc::RtpExtension::kTOffset, id)); 964 extensions.push_back(cricket::RtpHeaderExtension( 965 kRtpAbsoluteSenderTimeHeaderExtension, id)); 966 EXPECT_FALSE(channel_->SetSendRtpHeaderExtensions(extensions)); 967 968 // Duplicate entries are also not supported. 969 extensions.clear(); 970 extensions.push_back(cricket::RtpHeaderExtension( 971 webrtc::RtpExtension::kTOffset, id)); 972 extensions.push_back(extensions.back()); 973 EXPECT_FALSE(channel_->SetSendRtpHeaderExtensions(extensions)); 974 } 975 976 TEST_F(WebRtcVideoChannel2Test, 977 SetRecvRtpHeaderExtensionsRejectsDuplicateIds) { 978 const int id = 1; 979 std::vector<cricket::RtpHeaderExtension> extensions; 980 extensions.push_back(cricket::RtpHeaderExtension( 981 webrtc::RtpExtension::kTOffset, id)); 982 extensions.push_back(cricket::RtpHeaderExtension( 983 kRtpAbsoluteSenderTimeHeaderExtension, id)); 984 EXPECT_FALSE(channel_->SetRecvRtpHeaderExtensions(extensions)); 985 986 // Duplicate entries are also not supported. 987 extensions.clear(); 988 extensions.push_back(cricket::RtpHeaderExtension( 989 webrtc::RtpExtension::kTOffset, id)); 990 extensions.push_back(extensions.back()); 991 EXPECT_FALSE(channel_->SetRecvRtpHeaderExtensions(extensions)); 992 } 993 994 TEST_F(WebRtcVideoChannel2Test, DISABLED_LeakyBucketTest) { 995 FAIL() << "Not implemented."; // TODO(pbos): Implement. 996 } 997 998 TEST_F(WebRtcVideoChannel2Test, DISABLED_BufferedModeLatency) { 999 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1000 } 1001 1002 TEST_F(WebRtcVideoChannel2Test, DISABLED_AdditiveVideoOptions) { 1003 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1004 } 1005 1006 TEST_F(WebRtcVideoChannel2Test, AddRecvStreamOnlyUsesOneReceiveStream) { 1007 EXPECT_TRUE(channel_->AddRecvStream(cricket::StreamParams::CreateLegacy(1))); 1008 EXPECT_EQ(1u, fake_channel_->GetFakeCall()->GetVideoReceiveStreams().size()); 1009 } 1010 1011 TEST_F(WebRtcVideoChannel2Test, RembIsEnabledByDefault) { 1012 FakeVideoReceiveStream* stream = AddRecvStream(); 1013 EXPECT_TRUE(stream->GetConfig().rtp.remb); 1014 } 1015 1016 TEST_F(WebRtcVideoChannel2Test, RembCanBeEnabledAndDisabled) { 1017 FakeVideoReceiveStream* stream = AddRecvStream(); 1018 EXPECT_TRUE(stream->GetConfig().rtp.remb); 1019 1020 // Verify that REMB is turned off when codecs without REMB are set. 1021 std::vector<VideoCodec> codecs; 1022 codecs.push_back(kVp8Codec); 1023 EXPECT_TRUE(codecs[0].feedback_params.params().empty()); 1024 EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); 1025 stream = fake_channel_->GetFakeCall()->GetVideoReceiveStreams()[0]; 1026 EXPECT_FALSE(stream->GetConfig().rtp.remb); 1027 1028 // Verify that REMB is turned on when setting default codecs since the 1029 // default codecs have REMB enabled. 1030 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs())); 1031 stream = fake_channel_->GetFakeCall()->GetVideoReceiveStreams()[0]; 1032 EXPECT_TRUE(stream->GetConfig().rtp.remb); 1033 } 1034 1035 TEST_F(WebRtcVideoChannel2Test, NackIsEnabledByDefault) { 1036 VerifyCodecHasDefaultFeedbackParams(default_codec_); 1037 1038 EXPECT_TRUE(channel_->SetSendCodecs(engine_.codecs())); 1039 EXPECT_TRUE(channel_->SetSend(true)); 1040 1041 // Send side. 1042 FakeVideoSendStream* send_stream = 1043 AddSendStream(cricket::StreamParams::CreateLegacy(1)); 1044 EXPECT_GT(send_stream->GetConfig().rtp.nack.rtp_history_ms, 0); 1045 1046 // Receiver side. 1047 FakeVideoReceiveStream* recv_stream = 1048 AddRecvStream(cricket::StreamParams::CreateLegacy(1)); 1049 EXPECT_GT(recv_stream->GetConfig().rtp.nack.rtp_history_ms, 0); 1050 1051 // Nack history size should match between sender and receiver. 1052 EXPECT_EQ(send_stream->GetConfig().rtp.nack.rtp_history_ms, 1053 recv_stream->GetConfig().rtp.nack.rtp_history_ms); 1054 } 1055 1056 TEST_F(WebRtcVideoChannel2Test, NackCanBeDisabled) { 1057 std::vector<VideoCodec> codecs; 1058 codecs.push_back(kVp8Codec); 1059 1060 // Send side. 1061 ASSERT_TRUE(channel_->SetSendCodecs(codecs)); 1062 FakeVideoSendStream* send_stream = 1063 AddSendStream(cricket::StreamParams::CreateLegacy(1)); 1064 EXPECT_EQ(0, send_stream->GetConfig().rtp.nack.rtp_history_ms); 1065 1066 // Receiver side. 1067 ASSERT_TRUE(channel_->SetRecvCodecs(codecs)); 1068 FakeVideoReceiveStream* recv_stream = 1069 AddRecvStream(cricket::StreamParams::CreateLegacy(1)); 1070 EXPECT_EQ(0, recv_stream->GetConfig().rtp.nack.rtp_history_ms); 1071 } 1072 1073 TEST_F(WebRtcVideoChannel2Test, DISABLED_VideoProtectionInterop) { 1074 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1075 } 1076 1077 TEST_F(WebRtcVideoChannel2Test, DISABLED_VideoProtectionInteropReversed) { 1078 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1079 } 1080 1081 TEST_F(WebRtcVideoChannel2Test, DISABLED_HybridNackFecConference) { 1082 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1083 } 1084 1085 TEST_F(WebRtcVideoChannel2Test, DISABLED_AddRemoveRecvStreamConference) { 1086 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1087 } 1088 1089 TEST_F(WebRtcVideoChannel2Test, DISABLED_SetRender) { 1090 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1091 } 1092 1093 TEST_F(WebRtcVideoChannel2Test, DISABLED_SetBandwidthAuto) { 1094 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1095 } 1096 1097 TEST_F(WebRtcVideoChannel2Test, DISABLED_SetBandwidthAutoCapped) { 1098 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1099 } 1100 1101 TEST_F(WebRtcVideoChannel2Test, DISABLED_SetBandwidthFixed) { 1102 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1103 } 1104 1105 TEST_F(WebRtcVideoChannel2Test, DISABLED_SetBandwidthInConference) { 1106 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1107 } 1108 1109 TEST_F(WebRtcVideoChannel2Test, DISABLED_SetBandwidthScreencast) { 1110 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1111 } 1112 1113 TEST_F(WebRtcVideoChannel2Test, DISABLED_SetSendSsrcAndCname) { 1114 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1115 } 1116 1117 TEST_F(WebRtcVideoChannel2Test, 1118 DISABLED_SetSendSsrcAfterCreatingReceiveChannel) { 1119 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1120 } 1121 1122 TEST_F(WebRtcVideoChannel2Test, SuspendBelowMinBitrateDisabledByDefault) { 1123 FakeVideoSendStream* stream = AddSendStream(); 1124 EXPECT_FALSE(stream->GetConfig().suspend_below_min_bitrate); 1125 } 1126 1127 TEST_F(WebRtcVideoChannel2Test, SetOptionsWithSuspendBelowMinBitrate) { 1128 VideoOptions options; 1129 options.suspend_below_min_bitrate.Set(true); 1130 channel_->SetOptions(options); 1131 1132 FakeVideoSendStream* stream = AddSendStream(); 1133 EXPECT_TRUE(stream->GetConfig().suspend_below_min_bitrate); 1134 1135 options.suspend_below_min_bitrate.Set(false); 1136 channel_->SetOptions(options); 1137 1138 stream = fake_channel_->GetFakeCall()->GetVideoSendStreams()[0]; 1139 EXPECT_FALSE(stream->GetConfig().suspend_below_min_bitrate); 1140 } 1141 1142 TEST_F(WebRtcVideoChannel2Test, RedundantPayloadsDisabledByDefault) { 1143 const std::vector<uint32> ssrcs = MAKE_VECTOR(kSsrcs1); 1144 const std::vector<uint32> rtx_ssrcs = MAKE_VECTOR(kRtxSsrcs1); 1145 FakeVideoSendStream* stream = AddSendStream( 1146 cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); 1147 EXPECT_FALSE(stream->GetConfig().rtp.rtx.pad_with_redundant_payloads); 1148 } 1149 1150 TEST_F(WebRtcVideoChannel2Test, SetOptionsWithPayloadPadding) { 1151 VideoOptions options; 1152 options.use_payload_padding.Set(true); 1153 channel_->SetOptions(options); 1154 1155 const std::vector<uint32> ssrcs = MAKE_VECTOR(kSsrcs1); 1156 const std::vector<uint32> rtx_ssrcs = MAKE_VECTOR(kRtxSsrcs1); 1157 FakeVideoSendStream* stream = AddSendStream( 1158 cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); 1159 EXPECT_TRUE(stream->GetConfig().rtp.rtx.pad_with_redundant_payloads); 1160 1161 options.use_payload_padding.Set(false); 1162 channel_->SetOptions(options); 1163 1164 stream = fake_channel_->GetFakeCall()->GetVideoSendStreams()[0]; 1165 EXPECT_FALSE(stream->GetConfig().rtp.rtx.pad_with_redundant_payloads); 1166 } 1167 1168 TEST_F(WebRtcVideoChannel2Test, Vp8DenoisingEnabledByDefault) { 1169 FakeVideoSendStream* stream = AddSendStream(); 1170 webrtc::VideoCodecVP8 vp8_settings; 1171 ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; 1172 EXPECT_TRUE(vp8_settings.denoisingOn); 1173 } 1174 1175 TEST_F(WebRtcVideoChannel2Test, SetOptionsWithDenoising) { 1176 VideoOptions options; 1177 options.video_noise_reduction.Set(false); 1178 channel_->SetOptions(options); 1179 1180 FakeVideoSendStream* stream = AddSendStream(); 1181 webrtc::VideoCodecVP8 vp8_settings; 1182 ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; 1183 EXPECT_FALSE(vp8_settings.denoisingOn); 1184 1185 options.video_noise_reduction.Set(true); 1186 channel_->SetOptions(options); 1187 1188 stream = fake_channel_->GetFakeCall()->GetVideoSendStreams()[0]; 1189 ASSERT_TRUE(stream->GetVp8Settings(&vp8_settings)) << "No VP8 config set."; 1190 EXPECT_TRUE(vp8_settings.denoisingOn); 1191 } 1192 1193 TEST_F(WebRtcVideoChannel2Test, DISABLED_MultipleSendStreamsWithOneCapturer) { 1194 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1195 } 1196 1197 TEST_F(WebRtcVideoChannel2Test, DISABLED_SendReceiveBitratesStats) { 1198 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1199 } 1200 1201 TEST_F(WebRtcVideoChannel2Test, DISABLED_TestSetAdaptInputToCpuUsage) { 1202 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1203 } 1204 1205 TEST_F(WebRtcVideoChannel2Test, DISABLED_TestSetCpuThreshold) { 1206 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1207 } 1208 1209 TEST_F(WebRtcVideoChannel2Test, DISABLED_TestSetInvalidCpuThreshold) { 1210 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1211 } 1212 1213 TEST_F(WebRtcVideoChannel2Test, DISABLED_WebRtcShouldLog) { 1214 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1215 } 1216 1217 TEST_F(WebRtcVideoChannel2Test, DISABLED_WebRtcShouldNotLog) { 1218 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1219 } 1220 1221 TEST_F(WebRtcVideoChannel2Test, SetDefaultSendCodecs) { 1222 ASSERT_TRUE(channel_->SetSendCodecs(engine_.codecs())); 1223 1224 VideoCodec codec; 1225 EXPECT_TRUE(channel_->GetSendCodec(&codec)); 1226 EXPECT_TRUE(codec.Matches(engine_.codecs()[0])); 1227 1228 // Using a RTX setup to verify that the default RTX payload type is good. 1229 const std::vector<uint32> ssrcs = MAKE_VECTOR(kSsrcs1); 1230 const std::vector<uint32> rtx_ssrcs = MAKE_VECTOR(kRtxSsrcs1); 1231 FakeVideoSendStream* stream = AddSendStream( 1232 cricket::CreateSimWithRtxStreamParams("cname", ssrcs, rtx_ssrcs)); 1233 webrtc::VideoSendStream::Config config = stream->GetConfig(); 1234 1235 // Make sure NACK and FEC are enabled on the correct payload types. 1236 EXPECT_EQ(1000, config.rtp.nack.rtp_history_ms); 1237 EXPECT_EQ(default_ulpfec_codec_.id, config.rtp.fec.ulpfec_payload_type); 1238 EXPECT_EQ(default_red_codec_.id, config.rtp.fec.red_payload_type); 1239 1240 EXPECT_EQ(1u, config.rtp.rtx.ssrcs.size()); 1241 EXPECT_EQ(kRtxSsrcs1[0], config.rtp.rtx.ssrcs[0]); 1242 EXPECT_EQ(static_cast<int>(default_rtx_codec_.id), 1243 config.rtp.rtx.payload_type); 1244 // TODO(juberti): Check RTCP, PLI, TMMBR. 1245 } 1246 1247 TEST_F(WebRtcVideoChannel2Test, SetSendCodecsWithoutFec) { 1248 std::vector<VideoCodec> codecs; 1249 codecs.push_back(kVp8Codec); 1250 ASSERT_TRUE(channel_->SetSendCodecs(codecs)); 1251 1252 FakeVideoSendStream* stream = AddSendStream(); 1253 webrtc::VideoSendStream::Config config = stream->GetConfig(); 1254 1255 EXPECT_EQ(-1, config.rtp.fec.ulpfec_payload_type); 1256 EXPECT_EQ(-1, config.rtp.fec.red_payload_type); 1257 } 1258 1259 TEST_F(WebRtcVideoChannel2Test, 1260 SetSendCodecRejectsRtxWithoutAssociatedPayloadType) { 1261 std::vector<VideoCodec> codecs; 1262 cricket::VideoCodec rtx_codec(96, "rtx", 0, 0, 0, 0); 1263 codecs.push_back(rtx_codec); 1264 EXPECT_FALSE(channel_->SetSendCodecs(codecs)) 1265 << "RTX codec without associated payload type should be rejected."; 1266 } 1267 1268 TEST_F(WebRtcVideoChannel2Test, 1269 SetSendCodecRejectsRtxWithoutMatchingVideoCodec) { 1270 std::vector<VideoCodec> codecs; 1271 cricket::VideoCodec rtx_codec = 1272 cricket::VideoCodec::CreateRtxCodec(96, kVp8Codec.id); 1273 codecs.push_back(kVp8Codec); 1274 codecs.push_back(rtx_codec); 1275 ASSERT_TRUE(channel_->SetSendCodecs(codecs)); 1276 1277 cricket::VideoCodec rtx_codec2 = 1278 cricket::VideoCodec::CreateRtxCodec(96, kVp8Codec.id + 1); 1279 codecs.pop_back(); 1280 codecs.push_back(rtx_codec2); 1281 EXPECT_FALSE(channel_->SetSendCodecs(codecs)) 1282 << "RTX without matching video codec should be rejected."; 1283 } 1284 1285 TEST_F(WebRtcVideoChannel2Test, SetSendCodecsWithoutFecDisablesFec) { 1286 std::vector<VideoCodec> codecs; 1287 codecs.push_back(kVp8Codec); 1288 codecs.push_back(kUlpfecCodec); 1289 ASSERT_TRUE(channel_->SetSendCodecs(codecs)); 1290 1291 FakeVideoSendStream* stream = AddSendStream(); 1292 webrtc::VideoSendStream::Config config = stream->GetConfig(); 1293 1294 EXPECT_EQ(kUlpfecCodec.id, config.rtp.fec.ulpfec_payload_type); 1295 1296 codecs.pop_back(); 1297 ASSERT_TRUE(channel_->SetSendCodecs(codecs)); 1298 stream = fake_channel_->GetFakeCall()->GetVideoSendStreams()[0]; 1299 ASSERT_TRUE(stream != NULL); 1300 config = stream->GetConfig(); 1301 EXPECT_EQ(-1, config.rtp.fec.ulpfec_payload_type) 1302 << "SetSendCodec without FEC should disable current FEC."; 1303 } 1304 1305 TEST_F(WebRtcVideoChannel2Test, SetSendCodecsChangesExistingStreams) { 1306 std::vector<VideoCodec> codecs; 1307 codecs.push_back(kVp8Codec720p); 1308 ASSERT_TRUE(channel_->SetSendCodecs(codecs)); 1309 1310 std::vector<webrtc::VideoStream> streams = 1311 AddSendStream()->GetVideoStreams(); 1312 EXPECT_EQ(kVp8Codec720p.width, streams[0].width); 1313 EXPECT_EQ(kVp8Codec720p.height, streams[0].height); 1314 1315 codecs.clear(); 1316 codecs.push_back(kVp8Codec360p); 1317 ASSERT_TRUE(channel_->SetSendCodecs(codecs)); 1318 streams = fake_channel_->GetFakeCall()->GetVideoSendStreams()[0] 1319 ->GetVideoStreams(); 1320 EXPECT_EQ(kVp8Codec360p.width, streams[0].width); 1321 EXPECT_EQ(kVp8Codec360p.height, streams[0].height); 1322 } 1323 1324 TEST_F(WebRtcVideoChannel2Test, SetSendCodecsWithMinMaxBitrate) { 1325 SetSendCodecsShouldWorkForBitrates("10", "20"); 1326 } 1327 1328 TEST_F(WebRtcVideoChannel2Test, SetSendCodecsRejectsMaxLessThanMinBitrate) { 1329 std::vector<VideoCodec> video_codecs = engine_.codecs(); 1330 video_codecs[0].params[kCodecParamMinBitrate] = "30"; 1331 video_codecs[0].params[kCodecParamMaxBitrate] = "20"; 1332 EXPECT_FALSE(channel_->SetSendCodecs(video_codecs)); 1333 } 1334 1335 TEST_F(WebRtcVideoChannel2Test, SetSendCodecsAcceptLargeMinMaxBitrate) { 1336 SetSendCodecsShouldWorkForBitrates("1000", "2000"); 1337 } 1338 1339 TEST_F(WebRtcVideoChannel2Test, SetSendCodecsWithMaxQuantization) { 1340 static const char* kMaxQuantization = "21"; 1341 std::vector<VideoCodec> codecs; 1342 codecs.push_back(kVp8Codec); 1343 codecs[0].params[kCodecParamMaxQuantization] = kMaxQuantization; 1344 EXPECT_TRUE(channel_->SetSendCodecs(codecs)); 1345 EXPECT_EQ(static_cast<unsigned int>(atoi(kMaxQuantization)), 1346 AddSendStream()->GetVideoStreams().back().max_qp); 1347 1348 VideoCodec codec; 1349 EXPECT_TRUE(channel_->GetSendCodec(&codec)); 1350 EXPECT_EQ(kMaxQuantization, codec.params[kCodecParamMaxQuantization]); 1351 } 1352 1353 TEST_F(WebRtcVideoChannel2Test, SetSendCodecsRejectBadDimensions) { 1354 std::vector<cricket::VideoCodec> codecs; 1355 codecs.push_back(kVp8Codec); 1356 1357 codecs[0].width = 0; 1358 EXPECT_FALSE(channel_->SetSendCodecs(codecs)) 1359 << "Codec set though codec width is zero."; 1360 1361 codecs[0].width = kVp8Codec.width; 1362 codecs[0].height = 0; 1363 EXPECT_FALSE(channel_->SetSendCodecs(codecs)) 1364 << "Codec set though codec height is zero."; 1365 } 1366 1367 TEST_F(WebRtcVideoChannel2Test, SetSendCodecsRejectBadPayloadTypes) { 1368 // TODO(pbos): Should we only allow the dynamic range? 1369 static const size_t kNumIncorrectPayloads = 4; 1370 static const int kIncorrectPayloads[kNumIncorrectPayloads] = {-2, -1, 128, 1371 129}; 1372 std::vector<cricket::VideoCodec> codecs; 1373 codecs.push_back(kVp8Codec); 1374 for (size_t i = 0; i < kNumIncorrectPayloads; ++i) { 1375 int payload_type = kIncorrectPayloads[i]; 1376 codecs[0].id = payload_type; 1377 EXPECT_FALSE(channel_->SetSendCodecs(codecs)) 1378 << "Bad payload type '" << payload_type << "' accepted."; 1379 } 1380 } 1381 1382 TEST_F(WebRtcVideoChannel2Test, SetSendCodecsAcceptAllValidPayloadTypes) { 1383 std::vector<cricket::VideoCodec> codecs; 1384 codecs.push_back(kVp8Codec); 1385 for (int payload_type = 0; payload_type <= 127; ++payload_type) { 1386 codecs[0].id = payload_type; 1387 EXPECT_TRUE(channel_->SetSendCodecs(codecs)) 1388 << "Payload type '" << payload_type << "' rejected."; 1389 } 1390 } 1391 1392 TEST_F(WebRtcVideoChannel2Test, DISABLED_ResetVieSendCodecOnNewFrameSize) { 1393 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1394 } 1395 1396 TEST_F(WebRtcVideoChannel2Test, SetRecvCodecsWithOnlyVp8) { 1397 std::vector<cricket::VideoCodec> codecs; 1398 codecs.push_back(kVp8Codec); 1399 EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); 1400 } 1401 1402 // Test that we set our inbound RTX codecs properly. 1403 TEST_F(WebRtcVideoChannel2Test, SetRecvCodecsWithRtx) { 1404 std::vector<cricket::VideoCodec> codecs; 1405 codecs.push_back(kVp8Codec); 1406 cricket::VideoCodec rtx_codec(96, "rtx", 0, 0, 0, 0); 1407 codecs.push_back(rtx_codec); 1408 EXPECT_FALSE(channel_->SetRecvCodecs(codecs)) 1409 << "RTX codec without associated payload should be rejected."; 1410 1411 codecs[1].SetParam("apt", kVp8Codec.id + 1); 1412 EXPECT_FALSE(channel_->SetRecvCodecs(codecs)) 1413 << "RTX codec with invalid associated payload type should be rejected."; 1414 1415 codecs[1].SetParam("apt", kVp8Codec.id); 1416 EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); 1417 1418 cricket::VideoCodec rtx_codec2(97, "rtx", 0, 0, 0, 0); 1419 rtx_codec2.SetParam("apt", rtx_codec.id); 1420 codecs.push_back(rtx_codec2); 1421 1422 EXPECT_FALSE(channel_->SetRecvCodecs(codecs)) << "RTX codec with another RTX " 1423 "as associated payload type " 1424 "should be rejected."; 1425 } 1426 1427 TEST_F(WebRtcVideoChannel2Test, SetRecvCodecsDifferentPayloadType) { 1428 std::vector<cricket::VideoCodec> codecs; 1429 codecs.push_back(kVp8Codec); 1430 codecs[0].id = 99; 1431 EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); 1432 } 1433 1434 TEST_F(WebRtcVideoChannel2Test, SetRecvCodecsAcceptDefaultCodecs) { 1435 EXPECT_TRUE(channel_->SetRecvCodecs(engine_.codecs())); 1436 1437 FakeVideoReceiveStream* stream = AddRecvStream(); 1438 webrtc::VideoReceiveStream::Config config = stream->GetConfig(); 1439 EXPECT_STREQ(engine_.codecs()[0].name.c_str(), config.codecs[0].plName); 1440 EXPECT_EQ(engine_.codecs()[0].id, config.codecs[0].plType); 1441 } 1442 1443 TEST_F(WebRtcVideoChannel2Test, SetRecvCodecsRejectUnsupportedCodec) { 1444 std::vector<VideoCodec> codecs; 1445 codecs.push_back(kVp8Codec); 1446 codecs.push_back(VideoCodec(101, "WTF3", 640, 400, 30, 0)); 1447 EXPECT_FALSE(channel_->SetRecvCodecs(codecs)); 1448 } 1449 1450 // TODO(pbos): Enable VP9 through external codec support 1451 TEST_F(WebRtcVideoChannel2Test, 1452 DISABLED_SetRecvCodecsAcceptsMultipleVideoCodecs) { 1453 std::vector<VideoCodec> codecs; 1454 codecs.push_back(kVp8Codec); 1455 codecs.push_back(kVp9Codec); 1456 EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); 1457 } 1458 1459 TEST_F(WebRtcVideoChannel2Test, 1460 DISABLED_SetRecvCodecsSetsFecForAllVideoCodecs) { 1461 std::vector<VideoCodec> codecs; 1462 codecs.push_back(kVp8Codec); 1463 codecs.push_back(kVp9Codec); 1464 EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); 1465 FAIL(); // TODO(pbos): Verify that the FEC parameters are set for all codecs. 1466 } 1467 1468 TEST_F(WebRtcVideoChannel2Test, SetRecvCodecsWithoutFecDisablesFec) { 1469 std::vector<VideoCodec> codecs; 1470 codecs.push_back(kVp8Codec); 1471 codecs.push_back(kUlpfecCodec); 1472 ASSERT_TRUE(channel_->SetSendCodecs(codecs)); 1473 1474 FakeVideoReceiveStream* stream = AddRecvStream(); 1475 webrtc::VideoReceiveStream::Config config = stream->GetConfig(); 1476 1477 EXPECT_EQ(kUlpfecCodec.id, config.rtp.fec.ulpfec_payload_type); 1478 1479 codecs.pop_back(); 1480 ASSERT_TRUE(channel_->SetRecvCodecs(codecs)); 1481 stream = fake_channel_->GetFakeCall()->GetVideoReceiveStreams()[0]; 1482 ASSERT_TRUE(stream != NULL); 1483 config = stream->GetConfig(); 1484 EXPECT_EQ(-1, config.rtp.fec.ulpfec_payload_type) 1485 << "SetSendCodec without FEC should disable current FEC."; 1486 } 1487 1488 TEST_F(WebRtcVideoChannel2Test, SetSendCodecsRejectDuplicateFecPayloads) { 1489 std::vector<VideoCodec> codecs; 1490 codecs.push_back(kVp8Codec); 1491 codecs.push_back(kRedCodec); 1492 codecs[1].id = codecs[0].id; 1493 EXPECT_FALSE(channel_->SetRecvCodecs(codecs)); 1494 } 1495 1496 TEST_F(WebRtcVideoChannel2Test, SetRecvCodecsRejectDuplicateCodecPayloads) { 1497 std::vector<VideoCodec> codecs; 1498 codecs.push_back(kVp8Codec); 1499 codecs.push_back(kVp9Codec); 1500 codecs[1].id = codecs[0].id; 1501 EXPECT_FALSE(channel_->SetRecvCodecs(codecs)); 1502 } 1503 1504 TEST_F(WebRtcVideoChannel2Test, 1505 SetRecvCodecsAcceptSameCodecOnMultiplePayloadTypes) { 1506 std::vector<VideoCodec> codecs; 1507 codecs.push_back(kVp8Codec); 1508 codecs.push_back(kVp8Codec); 1509 codecs[1].id += 1; 1510 EXPECT_TRUE(channel_->SetRecvCodecs(codecs)); 1511 } 1512 1513 TEST_F(WebRtcVideoChannel2Test, SendStreamNotSendingByDefault) { 1514 EXPECT_FALSE(AddSendStream()->IsSending()); 1515 } 1516 1517 TEST_F(WebRtcVideoChannel2Test, ReceiveStreamReceivingByDefault) { 1518 EXPECT_TRUE(AddRecvStream()->IsReceiving()); 1519 } 1520 1521 TEST_F(WebRtcVideoChannel2Test, SetSend) { 1522 FakeVideoSendStream* stream = AddSendStream(); 1523 EXPECT_FALSE(stream->IsSending()); 1524 1525 // false->true 1526 EXPECT_TRUE(channel_->SetSend(true)); 1527 EXPECT_TRUE(stream->IsSending()); 1528 // true->true 1529 EXPECT_TRUE(channel_->SetSend(true)); 1530 EXPECT_TRUE(stream->IsSending()); 1531 // true->false 1532 EXPECT_TRUE(channel_->SetSend(false)); 1533 EXPECT_FALSE(stream->IsSending()); 1534 // false->false 1535 EXPECT_TRUE(channel_->SetSend(false)); 1536 EXPECT_FALSE(stream->IsSending()); 1537 1538 EXPECT_TRUE(channel_->SetSend(true)); 1539 FakeVideoSendStream* new_stream = AddSendStream(); 1540 EXPECT_TRUE(new_stream->IsSending()) 1541 << "Send stream created after SetSend(true) not sending initially."; 1542 } 1543 1544 TEST_F(WebRtcVideoChannel2Test, DISABLED_TestSetDscpOptions) { 1545 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1546 } 1547 1548 TEST_F(WebRtcVideoChannel2Test, DISABLED_SetOptionsWithMaxBitrate) { 1549 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1550 } 1551 1552 TEST_F(WebRtcVideoChannel2Test, DISABLED_SetOptionsWithLoweredBitrate) { 1553 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1554 } 1555 1556 TEST_F(WebRtcVideoChannel2Test, DISABLED_SetOptionsSucceedsWhenSending) { 1557 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1558 } 1559 1560 TEST_F(WebRtcVideoChannel2Test, DISABLED_ResetCodecOnScreencast) { 1561 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1562 } 1563 1564 TEST_F(WebRtcVideoChannel2Test, DISABLED_DontResetCodecOnSendFrame) { 1565 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1566 } 1567 1568 TEST_F(WebRtcVideoChannel2Test, 1569 DISABLED_DontRegisterDecoderIfFactoryIsNotGiven) { 1570 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1571 } 1572 1573 TEST_F(WebRtcVideoChannel2Test, DISABLED_RegisterDecoderIfFactoryIsGiven) { 1574 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1575 } 1576 1577 TEST_F(WebRtcVideoChannel2Test, DISABLED_DontRegisterDecoderMultipleTimes) { 1578 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1579 } 1580 1581 TEST_F(WebRtcVideoChannel2Test, DISABLED_DontRegisterDecoderForNonVP8) { 1582 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1583 } 1584 1585 TEST_F(WebRtcVideoChannel2Test, 1586 DISABLED_DontRegisterEncoderIfFactoryIsNotGiven) { 1587 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1588 } 1589 1590 TEST_F(WebRtcVideoChannel2Test, DISABLED_RegisterEncoderIfFactoryIsGiven) { 1591 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1592 } 1593 1594 TEST_F(WebRtcVideoChannel2Test, DISABLED_DontRegisterEncoderMultipleTimes) { 1595 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1596 } 1597 1598 TEST_F(WebRtcVideoChannel2Test, 1599 DISABLED_RegisterEncoderWithMultipleSendStreams) { 1600 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1601 } 1602 1603 TEST_F(WebRtcVideoChannel2Test, DISABLED_DontRegisterEncoderForNonVP8) { 1604 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1605 } 1606 1607 TEST_F(WebRtcVideoChannel2Test, DISABLED_FeedbackParamsForNonVP8) { 1608 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1609 } 1610 1611 TEST_F(WebRtcVideoChannel2Test, DISABLED_ExternalCodecAddedToTheEnd) { 1612 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1613 } 1614 1615 TEST_F(WebRtcVideoChannel2Test, DISABLED_ExternalCodecIgnored) { 1616 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1617 } 1618 1619 TEST_F(WebRtcVideoChannel2Test, DISABLED_UpdateEncoderCodecsAfterSetFactory) { 1620 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1621 } 1622 1623 TEST_F(WebRtcVideoChannel2Test, OnReadyToSendSignalsNetworkState) { 1624 EXPECT_EQ(webrtc::Call::kNetworkUp, 1625 fake_channel_->GetFakeCall()->GetNetworkState()); 1626 1627 channel_->OnReadyToSend(false); 1628 EXPECT_EQ(webrtc::Call::kNetworkDown, 1629 fake_channel_->GetFakeCall()->GetNetworkState()); 1630 1631 channel_->OnReadyToSend(true); 1632 EXPECT_EQ(webrtc::Call::kNetworkUp, 1633 fake_channel_->GetFakeCall()->GetNetworkState()); 1634 } 1635 1636 TEST_F(WebRtcVideoChannel2Test, DISABLED_CaptureFrameTimestampToNtpTimestamp) { 1637 FAIL() << "Not implemented."; // TODO(pbos): Implement. 1638 } 1639 } // namespace cricket 1640