1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724
|
/*
* Copyright 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include <memory>
#include <string>
#include <utility>
#include "webrtc/api/audiotrack.h"
#include "webrtc/api/fakemediacontroller.h"
#include "webrtc/api/localaudiosource.h"
#include "webrtc/api/mediastream.h"
#include "webrtc/api/remoteaudiosource.h"
#include "webrtc/api/rtpreceiver.h"
#include "webrtc/api/rtpsender.h"
#include "webrtc/api/streamcollection.h"
#include "webrtc/api/test/fakevideotracksource.h"
#include "webrtc/api/videotrack.h"
#include "webrtc/api/videotracksource.h"
#include "webrtc/base/gunit.h"
#include "webrtc/logging/rtc_event_log/rtc_event_log.h"
#include "webrtc/media/base/fakemediaengine.h"
#include "webrtc/media/base/mediachannel.h"
#include "webrtc/media/engine/fakewebrtccall.h"
#include "webrtc/p2p/base/faketransportcontroller.h"
#include "webrtc/pc/channelmanager.h"
#include "webrtc/test/gmock.h"
#include "webrtc/test/gtest.h"
using ::testing::_;
using ::testing::Exactly;
using ::testing::InvokeWithoutArgs;
using ::testing::Return;
static const char kStreamLabel1[] = "local_stream_1";
static const char kVideoTrackId[] = "video_1";
static const char kAudioTrackId[] = "audio_1";
static const uint32_t kVideoSsrc = 98;
static const uint32_t kVideoSsrc2 = 100;
static const uint32_t kAudioSsrc = 99;
static const uint32_t kAudioSsrc2 = 101;
namespace webrtc {
class RtpSenderReceiverTest : public testing::Test {
public:
RtpSenderReceiverTest()
: // Create fake media engine/etc. so we can create channels to use to
// test RtpSenders/RtpReceivers.
media_engine_(new cricket::FakeMediaEngine()),
channel_manager_(media_engine_,
rtc::Thread::Current(),
rtc::Thread::Current()),
fake_call_(Call::Config(&event_log_)),
fake_media_controller_(&channel_manager_, &fake_call_),
stream_(MediaStream::Create(kStreamLabel1)) {
// Create channels to be used by the RtpSenders and RtpReceivers.
channel_manager_.Init();
bool rtcp_mux_required = true;
bool srtp_required = true;
cricket::TransportChannel* rtp_transport =
fake_transport_controller_.CreateTransportChannel(
cricket::CN_AUDIO, cricket::ICE_CANDIDATE_COMPONENT_RTP);
voice_channel_ = channel_manager_.CreateVoiceChannel(
&fake_media_controller_, rtp_transport, nullptr, rtc::Thread::Current(),
cricket::CN_AUDIO, nullptr, rtcp_mux_required, srtp_required,
cricket::AudioOptions());
video_channel_ = channel_manager_.CreateVideoChannel(
&fake_media_controller_, rtp_transport, nullptr, rtc::Thread::Current(),
cricket::CN_VIDEO, nullptr, rtcp_mux_required, srtp_required,
cricket::VideoOptions());
voice_media_channel_ = media_engine_->GetVoiceChannel(0);
video_media_channel_ = media_engine_->GetVideoChannel(0);
RTC_CHECK(voice_channel_);
RTC_CHECK(video_channel_);
RTC_CHECK(voice_media_channel_);
RTC_CHECK(video_media_channel_);
// Create streams for predefined SSRCs. Streams need to exist in order
// for the senders and receievers to apply parameters to them.
// Normally these would be created by SetLocalDescription and
// SetRemoteDescription.
voice_media_channel_->AddSendStream(
cricket::StreamParams::CreateLegacy(kAudioSsrc));
voice_media_channel_->AddRecvStream(
cricket::StreamParams::CreateLegacy(kAudioSsrc));
voice_media_channel_->AddSendStream(
cricket::StreamParams::CreateLegacy(kAudioSsrc2));
voice_media_channel_->AddRecvStream(
cricket::StreamParams::CreateLegacy(kAudioSsrc2));
video_media_channel_->AddSendStream(
cricket::StreamParams::CreateLegacy(kVideoSsrc));
video_media_channel_->AddRecvStream(
cricket::StreamParams::CreateLegacy(kVideoSsrc));
video_media_channel_->AddSendStream(
cricket::StreamParams::CreateLegacy(kVideoSsrc2));
video_media_channel_->AddRecvStream(
cricket::StreamParams::CreateLegacy(kVideoSsrc2));
}
void TearDown() override { channel_manager_.Terminate(); }
void AddVideoTrack() { AddVideoTrack(false); }
void AddVideoTrack(bool is_screencast) {
rtc::scoped_refptr<VideoTrackSourceInterface> source(
FakeVideoTrackSource::Create(is_screencast));
video_track_ = VideoTrack::Create(kVideoTrackId, source);
EXPECT_TRUE(stream_->AddTrack(video_track_));
}
void CreateAudioRtpSender() { CreateAudioRtpSender(nullptr); }
void CreateAudioRtpSender(rtc::scoped_refptr<LocalAudioSource> source) {
audio_track_ = AudioTrack::Create(kAudioTrackId, source);
EXPECT_TRUE(stream_->AddTrack(audio_track_));
audio_rtp_sender_ =
new AudioRtpSender(stream_->GetAudioTracks()[0], stream_->label(),
voice_channel_, nullptr);
audio_rtp_sender_->SetSsrc(kAudioSsrc);
VerifyVoiceChannelInput();
}
void CreateVideoRtpSender() { CreateVideoRtpSender(false); }
void CreateVideoRtpSender(bool is_screencast) {
AddVideoTrack(is_screencast);
video_rtp_sender_ = new VideoRtpSender(stream_->GetVideoTracks()[0],
stream_->label(), video_channel_);
video_rtp_sender_->SetSsrc(kVideoSsrc);
VerifyVideoChannelInput();
}
void DestroyAudioRtpSender() {
audio_rtp_sender_ = nullptr;
VerifyVoiceChannelNoInput();
}
void DestroyVideoRtpSender() {
video_rtp_sender_ = nullptr;
VerifyVideoChannelNoInput();
}
void CreateAudioRtpReceiver() {
audio_track_ = AudioTrack::Create(
kAudioTrackId, RemoteAudioSource::Create(kAudioSsrc, NULL));
EXPECT_TRUE(stream_->AddTrack(audio_track_));
audio_rtp_receiver_ = new AudioRtpReceiver(stream_, kAudioTrackId,
kAudioSsrc, voice_channel_);
audio_track_ = audio_rtp_receiver_->audio_track();
VerifyVoiceChannelOutput();
}
void CreateVideoRtpReceiver() {
video_rtp_receiver_ =
new VideoRtpReceiver(stream_, kVideoTrackId, rtc::Thread::Current(),
kVideoSsrc, video_channel_);
video_track_ = video_rtp_receiver_->video_track();
VerifyVideoChannelOutput();
}
void DestroyAudioRtpReceiver() {
audio_rtp_receiver_ = nullptr;
VerifyVoiceChannelNoOutput();
}
void DestroyVideoRtpReceiver() {
video_rtp_receiver_ = nullptr;
VerifyVideoChannelNoOutput();
}
void VerifyVoiceChannelInput() { VerifyVoiceChannelInput(kAudioSsrc); }
void VerifyVoiceChannelInput(uint32_t ssrc) {
// Verify that the media channel has an audio source, and the stream isn't
// muted.
EXPECT_TRUE(voice_media_channel_->HasSource(ssrc));
EXPECT_FALSE(voice_media_channel_->IsStreamMuted(ssrc));
}
void VerifyVideoChannelInput() { VerifyVideoChannelInput(kVideoSsrc); }
void VerifyVideoChannelInput(uint32_t ssrc) {
// Verify that the media channel has a video source,
EXPECT_TRUE(video_media_channel_->HasSource(ssrc));
}
void VerifyVoiceChannelNoInput() { VerifyVoiceChannelNoInput(kAudioSsrc); }
void VerifyVoiceChannelNoInput(uint32_t ssrc) {
// Verify that the media channel's source is reset.
EXPECT_FALSE(voice_media_channel_->HasSource(ssrc));
}
void VerifyVideoChannelNoInput() { VerifyVideoChannelNoInput(kVideoSsrc); }
void VerifyVideoChannelNoInput(uint32_t ssrc) {
// Verify that the media channel's source is reset.
EXPECT_FALSE(video_media_channel_->HasSource(ssrc));
}
void VerifyVoiceChannelOutput() {
// Verify that the volume is initialized to 1.
double volume;
EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
EXPECT_EQ(1, volume);
}
void VerifyVideoChannelOutput() {
// Verify that the media channel has a sink.
EXPECT_TRUE(video_media_channel_->HasSink(kVideoSsrc));
}
void VerifyVoiceChannelNoOutput() {
// Verify that the volume is reset to 0.
double volume;
EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
EXPECT_EQ(0, volume);
}
void VerifyVideoChannelNoOutput() {
// Verify that the media channel's sink is reset.
EXPECT_FALSE(video_media_channel_->HasSink(kVideoSsrc));
}
protected:
webrtc::RtcEventLogNullImpl event_log_;
cricket::FakeMediaEngine* media_engine_;
cricket::FakeTransportController fake_transport_controller_;
cricket::ChannelManager channel_manager_;
cricket::FakeCall fake_call_;
cricket::FakeMediaController fake_media_controller_;
cricket::VoiceChannel* voice_channel_;
cricket::VideoChannel* video_channel_;
cricket::FakeVoiceMediaChannel* voice_media_channel_;
cricket::FakeVideoMediaChannel* video_media_channel_;
rtc::scoped_refptr<AudioRtpSender> audio_rtp_sender_;
rtc::scoped_refptr<VideoRtpSender> video_rtp_sender_;
rtc::scoped_refptr<AudioRtpReceiver> audio_rtp_receiver_;
rtc::scoped_refptr<VideoRtpReceiver> video_rtp_receiver_;
rtc::scoped_refptr<MediaStreamInterface> stream_;
rtc::scoped_refptr<VideoTrackInterface> video_track_;
rtc::scoped_refptr<AudioTrackInterface> audio_track_;
};
// Test that |voice_channel_| is updated when an audio track is associated
// and disassociated with an AudioRtpSender.
TEST_F(RtpSenderReceiverTest, AddAndDestroyAudioRtpSender) {
CreateAudioRtpSender();
DestroyAudioRtpSender();
}
// Test that |video_channel_| is updated when a video track is associated and
// disassociated with a VideoRtpSender.
TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpSender) {
CreateVideoRtpSender();
DestroyVideoRtpSender();
}
// Test that |voice_channel_| is updated when a remote audio track is
// associated and disassociated with an AudioRtpReceiver.
TEST_F(RtpSenderReceiverTest, AddAndDestroyAudioRtpReceiver) {
CreateAudioRtpReceiver();
DestroyAudioRtpReceiver();
}
// Test that |video_channel_| is updated when a remote video track is
// associated and disassociated with a VideoRtpReceiver.
TEST_F(RtpSenderReceiverTest, AddAndDestroyVideoRtpReceiver) {
CreateVideoRtpReceiver();
DestroyVideoRtpReceiver();
}
// Test that the AudioRtpSender applies options from the local audio source.
TEST_F(RtpSenderReceiverTest, LocalAudioSourceOptionsApplied) {
cricket::AudioOptions options;
options.echo_cancellation = rtc::Optional<bool>(true);
auto source = LocalAudioSource::Create(
PeerConnectionFactoryInterface::Options(), &options);
CreateAudioRtpSender(source.get());
EXPECT_EQ(rtc::Optional<bool>(true),
voice_media_channel_->options().echo_cancellation);
DestroyAudioRtpSender();
}
// Test that the stream is muted when the track is disabled, and unmuted when
// the track is enabled.
TEST_F(RtpSenderReceiverTest, LocalAudioTrackDisable) {
CreateAudioRtpSender();
audio_track_->set_enabled(false);
EXPECT_TRUE(voice_media_channel_->IsStreamMuted(kAudioSsrc));
audio_track_->set_enabled(true);
EXPECT_FALSE(voice_media_channel_->IsStreamMuted(kAudioSsrc));
DestroyAudioRtpSender();
}
// Test that the volume is set to 0 when the track is disabled, and back to
// 1 when the track is enabled.
TEST_F(RtpSenderReceiverTest, RemoteAudioTrackDisable) {
CreateAudioRtpReceiver();
double volume;
EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
EXPECT_EQ(1, volume);
audio_track_->set_enabled(false);
EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
EXPECT_EQ(0, volume);
audio_track_->set_enabled(true);
EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
EXPECT_EQ(1, volume);
DestroyAudioRtpReceiver();
}
// Currently no action is taken when a remote video track is disabled or
// enabled, so there's nothing to test here, other than what is normally
// verified in DestroyVideoRtpSender.
TEST_F(RtpSenderReceiverTest, LocalVideoTrackDisable) {
CreateVideoRtpSender();
video_track_->set_enabled(false);
video_track_->set_enabled(true);
DestroyVideoRtpSender();
}
// Test that the state of the video track created by the VideoRtpReceiver is
// updated when the receiver is destroyed.
TEST_F(RtpSenderReceiverTest, RemoteVideoTrackState) {
CreateVideoRtpReceiver();
EXPECT_EQ(webrtc::MediaStreamTrackInterface::kLive, video_track_->state());
EXPECT_EQ(webrtc::MediaSourceInterface::kLive,
video_track_->GetSource()->state());
DestroyVideoRtpReceiver();
EXPECT_EQ(webrtc::MediaStreamTrackInterface::kEnded, video_track_->state());
EXPECT_EQ(webrtc::MediaSourceInterface::kEnded,
video_track_->GetSource()->state());
}
// Currently no action is taken when a remote video track is disabled or
// enabled, so there's nothing to test here, other than what is normally
// verified in DestroyVideoRtpReceiver.
TEST_F(RtpSenderReceiverTest, RemoteVideoTrackDisable) {
CreateVideoRtpReceiver();
video_track_->set_enabled(false);
video_track_->set_enabled(true);
DestroyVideoRtpReceiver();
}
// Test that the AudioRtpReceiver applies volume changes from the track source
// to the media channel.
TEST_F(RtpSenderReceiverTest, RemoteAudioTrackSetVolume) {
CreateAudioRtpReceiver();
double volume;
audio_track_->GetSource()->SetVolume(0.5);
EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
EXPECT_EQ(0.5, volume);
// Disable the audio track, this should prevent setting the volume.
audio_track_->set_enabled(false);
audio_track_->GetSource()->SetVolume(0.8);
EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
EXPECT_EQ(0, volume);
// When the track is enabled, the previously set volume should take effect.
audio_track_->set_enabled(true);
EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
EXPECT_EQ(0.8, volume);
// Try changing volume one more time.
audio_track_->GetSource()->SetVolume(0.9);
EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
EXPECT_EQ(0.9, volume);
DestroyAudioRtpReceiver();
}
// Test that the media channel isn't enabled for sending if the audio sender
// doesn't have both a track and SSRC.
TEST_F(RtpSenderReceiverTest, AudioSenderWithoutTrackAndSsrc) {
audio_rtp_sender_ = new AudioRtpSender(voice_channel_, nullptr);
rtc::scoped_refptr<AudioTrackInterface> track =
AudioTrack::Create(kAudioTrackId, nullptr);
// Track but no SSRC.
EXPECT_TRUE(audio_rtp_sender_->SetTrack(track));
VerifyVoiceChannelNoInput();
// SSRC but no track.
EXPECT_TRUE(audio_rtp_sender_->SetTrack(nullptr));
audio_rtp_sender_->SetSsrc(kAudioSsrc);
VerifyVoiceChannelNoInput();
}
// Test that the media channel isn't enabled for sending if the video sender
// doesn't have both a track and SSRC.
TEST_F(RtpSenderReceiverTest, VideoSenderWithoutTrackAndSsrc) {
video_rtp_sender_ = new VideoRtpSender(video_channel_);
// Track but no SSRC.
EXPECT_TRUE(video_rtp_sender_->SetTrack(video_track_));
VerifyVideoChannelNoInput();
// SSRC but no track.
EXPECT_TRUE(video_rtp_sender_->SetTrack(nullptr));
video_rtp_sender_->SetSsrc(kVideoSsrc);
VerifyVideoChannelNoInput();
}
// Test that the media channel is enabled for sending when the audio sender
// has a track and SSRC, when the SSRC is set first.
TEST_F(RtpSenderReceiverTest, AudioSenderEarlyWarmupSsrcThenTrack) {
audio_rtp_sender_ = new AudioRtpSender(voice_channel_, nullptr);
rtc::scoped_refptr<AudioTrackInterface> track =
AudioTrack::Create(kAudioTrackId, nullptr);
audio_rtp_sender_->SetSsrc(kAudioSsrc);
audio_rtp_sender_->SetTrack(track);
VerifyVoiceChannelInput();
DestroyAudioRtpSender();
}
// Test that the media channel is enabled for sending when the audio sender
// has a track and SSRC, when the SSRC is set last.
TEST_F(RtpSenderReceiverTest, AudioSenderEarlyWarmupTrackThenSsrc) {
audio_rtp_sender_ = new AudioRtpSender(voice_channel_, nullptr);
rtc::scoped_refptr<AudioTrackInterface> track =
AudioTrack::Create(kAudioTrackId, nullptr);
audio_rtp_sender_->SetTrack(track);
audio_rtp_sender_->SetSsrc(kAudioSsrc);
VerifyVoiceChannelInput();
DestroyAudioRtpSender();
}
// Test that the media channel is enabled for sending when the video sender
// has a track and SSRC, when the SSRC is set first.
TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupSsrcThenTrack) {
AddVideoTrack();
video_rtp_sender_ = new VideoRtpSender(video_channel_);
video_rtp_sender_->SetSsrc(kVideoSsrc);
video_rtp_sender_->SetTrack(video_track_);
VerifyVideoChannelInput();
DestroyVideoRtpSender();
}
// Test that the media channel is enabled for sending when the video sender
// has a track and SSRC, when the SSRC is set last.
TEST_F(RtpSenderReceiverTest, VideoSenderEarlyWarmupTrackThenSsrc) {
AddVideoTrack();
video_rtp_sender_ = new VideoRtpSender(video_channel_);
video_rtp_sender_->SetTrack(video_track_);
video_rtp_sender_->SetSsrc(kVideoSsrc);
VerifyVideoChannelInput();
DestroyVideoRtpSender();
}
// Test that the media channel stops sending when the audio sender's SSRC is set
// to 0.
TEST_F(RtpSenderReceiverTest, AudioSenderSsrcSetToZero) {
CreateAudioRtpSender();
audio_rtp_sender_->SetSsrc(0);
VerifyVoiceChannelNoInput();
}
// Test that the media channel stops sending when the video sender's SSRC is set
// to 0.
TEST_F(RtpSenderReceiverTest, VideoSenderSsrcSetToZero) {
CreateAudioRtpSender();
audio_rtp_sender_->SetSsrc(0);
VerifyVideoChannelNoInput();
}
// Test that the media channel stops sending when the audio sender's track is
// set to null.
TEST_F(RtpSenderReceiverTest, AudioSenderTrackSetToNull) {
CreateAudioRtpSender();
EXPECT_TRUE(audio_rtp_sender_->SetTrack(nullptr));
VerifyVoiceChannelNoInput();
}
// Test that the media channel stops sending when the video sender's track is
// set to null.
TEST_F(RtpSenderReceiverTest, VideoSenderTrackSetToNull) {
CreateVideoRtpSender();
video_rtp_sender_->SetSsrc(0);
VerifyVideoChannelNoInput();
}
// Test that when the audio sender's SSRC is changed, the media channel stops
// sending with the old SSRC and starts sending with the new one.
TEST_F(RtpSenderReceiverTest, AudioSenderSsrcChanged) {
CreateAudioRtpSender();
audio_rtp_sender_->SetSsrc(kAudioSsrc2);
VerifyVoiceChannelNoInput(kAudioSsrc);
VerifyVoiceChannelInput(kAudioSsrc2);
audio_rtp_sender_ = nullptr;
VerifyVoiceChannelNoInput(kAudioSsrc2);
}
// Test that when the audio sender's SSRC is changed, the media channel stops
// sending with the old SSRC and starts sending with the new one.
TEST_F(RtpSenderReceiverTest, VideoSenderSsrcChanged) {
CreateVideoRtpSender();
video_rtp_sender_->SetSsrc(kVideoSsrc2);
VerifyVideoChannelNoInput(kVideoSsrc);
VerifyVideoChannelInput(kVideoSsrc2);
video_rtp_sender_ = nullptr;
VerifyVideoChannelNoInput(kVideoSsrc2);
}
TEST_F(RtpSenderReceiverTest, AudioSenderCanSetParameters) {
CreateAudioRtpSender();
RtpParameters params = audio_rtp_sender_->GetParameters();
EXPECT_EQ(1u, params.encodings.size());
EXPECT_TRUE(audio_rtp_sender_->SetParameters(params));
DestroyAudioRtpSender();
}
TEST_F(RtpSenderReceiverTest, SetAudioMaxSendBitrate) {
CreateAudioRtpSender();
EXPECT_EQ(-1, voice_media_channel_->max_bps());
webrtc::RtpParameters params = audio_rtp_sender_->GetParameters();
EXPECT_EQ(1, params.encodings.size());
EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
params.encodings[0].max_bitrate_bps = 1000;
EXPECT_TRUE(audio_rtp_sender_->SetParameters(params));
// Read back the parameters and verify they have been changed.
params = audio_rtp_sender_->GetParameters();
EXPECT_EQ(1, params.encodings.size());
EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
// Verify that the audio channel received the new parameters.
params = voice_media_channel_->GetRtpSendParameters(kAudioSsrc);
EXPECT_EQ(1, params.encodings.size());
EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
// Verify that the global bitrate limit has not been changed.
EXPECT_EQ(-1, voice_media_channel_->max_bps());
DestroyAudioRtpSender();
}
TEST_F(RtpSenderReceiverTest, VideoSenderCanSetParameters) {
CreateVideoRtpSender();
RtpParameters params = video_rtp_sender_->GetParameters();
EXPECT_EQ(1u, params.encodings.size());
EXPECT_TRUE(video_rtp_sender_->SetParameters(params));
DestroyVideoRtpSender();
}
TEST_F(RtpSenderReceiverTest, SetVideoMaxSendBitrate) {
CreateVideoRtpSender();
EXPECT_EQ(-1, video_media_channel_->max_bps());
webrtc::RtpParameters params = video_rtp_sender_->GetParameters();
EXPECT_EQ(1, params.encodings.size());
EXPECT_EQ(-1, params.encodings[0].max_bitrate_bps);
params.encodings[0].max_bitrate_bps = 1000;
EXPECT_TRUE(video_rtp_sender_->SetParameters(params));
// Read back the parameters and verify they have been changed.
params = video_rtp_sender_->GetParameters();
EXPECT_EQ(1, params.encodings.size());
EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
// Verify that the video channel received the new parameters.
params = video_media_channel_->GetRtpSendParameters(kVideoSsrc);
EXPECT_EQ(1, params.encodings.size());
EXPECT_EQ(1000, params.encodings[0].max_bitrate_bps);
// Verify that the global bitrate limit has not been changed.
EXPECT_EQ(-1, video_media_channel_->max_bps());
DestroyVideoRtpSender();
}
TEST_F(RtpSenderReceiverTest, AudioReceiverCanSetParameters) {
CreateAudioRtpReceiver();
RtpParameters params = audio_rtp_receiver_->GetParameters();
EXPECT_EQ(1u, params.encodings.size());
EXPECT_TRUE(audio_rtp_receiver_->SetParameters(params));
DestroyAudioRtpReceiver();
}
TEST_F(RtpSenderReceiverTest, VideoReceiverCanSetParameters) {
CreateVideoRtpReceiver();
RtpParameters params = video_rtp_receiver_->GetParameters();
EXPECT_EQ(1u, params.encodings.size());
EXPECT_TRUE(video_rtp_receiver_->SetParameters(params));
DestroyVideoRtpReceiver();
}
// Test that makes sure that a video track content hint translates to the proper
// value for sources that are not screencast.
TEST_F(RtpSenderReceiverTest, PropagatesVideoTrackContentHint) {
CreateVideoRtpSender();
video_track_->set_enabled(true);
// |video_track_| is not screencast by default.
EXPECT_EQ(rtc::Optional<bool>(false),
video_media_channel_->options().is_screencast);
// No content hint should be set by default.
EXPECT_EQ(VideoTrackInterface::ContentHint::kNone,
video_track_->content_hint());
// Setting detailed should turn a non-screencast source into screencast mode.
video_track_->set_content_hint(VideoTrackInterface::ContentHint::kDetailed);
EXPECT_EQ(rtc::Optional<bool>(true),
video_media_channel_->options().is_screencast);
// Removing the content hint should turn the track back into non-screencast
// mode.
video_track_->set_content_hint(VideoTrackInterface::ContentHint::kNone);
EXPECT_EQ(rtc::Optional<bool>(false),
video_media_channel_->options().is_screencast);
// Setting fluid should remain in non-screencast mode (its default).
video_track_->set_content_hint(VideoTrackInterface::ContentHint::kFluid);
EXPECT_EQ(rtc::Optional<bool>(false),
video_media_channel_->options().is_screencast);
DestroyVideoRtpSender();
}
// Test that makes sure that a video track content hint translates to the proper
// value for screencast sources.
TEST_F(RtpSenderReceiverTest,
PropagatesVideoTrackContentHintForScreencastSource) {
CreateVideoRtpSender(true);
video_track_->set_enabled(true);
// |video_track_| with a screencast source should be screencast by default.
EXPECT_EQ(rtc::Optional<bool>(true),
video_media_channel_->options().is_screencast);
// No content hint should be set by default.
EXPECT_EQ(VideoTrackInterface::ContentHint::kNone,
video_track_->content_hint());
// Setting fluid should turn a screencast source into non-screencast mode.
video_track_->set_content_hint(VideoTrackInterface::ContentHint::kFluid);
EXPECT_EQ(rtc::Optional<bool>(false),
video_media_channel_->options().is_screencast);
// Removing the content hint should turn the track back into screencast mode.
video_track_->set_content_hint(VideoTrackInterface::ContentHint::kNone);
EXPECT_EQ(rtc::Optional<bool>(true),
video_media_channel_->options().is_screencast);
// Setting detailed should still remain in screencast mode (its default).
video_track_->set_content_hint(VideoTrackInterface::ContentHint::kDetailed);
EXPECT_EQ(rtc::Optional<bool>(true),
video_media_channel_->options().is_screencast);
DestroyVideoRtpSender();
}
// Test that makes sure any content hints that are set on a track before
// VideoRtpSender is ready to send are still applied when it gets ready to send.
TEST_F(RtpSenderReceiverTest,
PropagatesVideoTrackContentHintSetBeforeEnabling) {
AddVideoTrack();
// Setting detailed overrides the default non-screencast mode. This should be
// applied even if the track is set on construction.
video_track_->set_content_hint(VideoTrackInterface::ContentHint::kDetailed);
video_rtp_sender_ = new VideoRtpSender(stream_->GetVideoTracks()[0],
stream_->label(), video_channel_);
video_track_->set_enabled(true);
// Sender is not ready to send (no SSRC) so no option should have been set.
EXPECT_EQ(rtc::Optional<bool>(),
video_media_channel_->options().is_screencast);
// Verify that the content hint is accounted for when video_rtp_sender_ does
// get enabled.
video_rtp_sender_->SetSsrc(kVideoSsrc);
EXPECT_EQ(rtc::Optional<bool>(true),
video_media_channel_->options().is_screencast);
// And removing the hint should go back to false (to verify that false was
// default correctly).
video_track_->set_content_hint(VideoTrackInterface::ContentHint::kNone);
EXPECT_EQ(rtc::Optional<bool>(false),
video_media_channel_->options().is_screencast);
DestroyVideoRtpSender();
}
} // namespace webrtc
|