Revert of Use VoiceChannel/VideoChannel directly from RtpSender/RtpReceiver. (patchset #3 id:40001 of https://codereview.webrtc.org/2046173002/ )

Reason for revert:
Broke peerconnection_unittest somehow, due to introduction of thread check. Will fix and reland.

Original issue's description:
> Use VoiceChannel/VideoChannel directly from RtpSender/RtpReceiver.
>
> This eliminates the need for the extra layer of indirection provided by
> mediastreamprovider.h. It will thus make it easier to implement new
> functionality in RtpSender/RtpReceiver.
>
> It also brings us one step closer to the end goal of combining "senders"
> and "send streams". Currently the sender still needs to go through the
> BaseChannel and MediaChannel, using an SSRC as a key.
>
> R=pthatcher@webrtc.org
>
> Committed: https://crrev.com/bc5831999d3354509d75357b659b4bb8e39f8a6c
> Cr-Commit-Position: refs/heads/master@{#13285}

TBR=pthatcher@webrtc.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true

Review-Url: https://codereview.webrtc.org/2099843003
Cr-Commit-Position: refs/heads/master@{#13286}
This commit is contained in:
deadbeef
2016-06-24 14:13:06 -07:00
committed by Commit bot
parent bc5831999d
commit 1a7162dbc9
18 changed files with 905 additions and 654 deletions

View File

@ -15,8 +15,6 @@
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#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"
@ -27,10 +25,6 @@
#include "webrtc/api/videotrack.h"
#include "webrtc/base/gunit.h"
#include "webrtc/media/base/mediachannel.h"
#include "webrtc/media/base/fakemediaengine.h"
#include "webrtc/media/engine/fakewebrtccall.h"
#include "webrtc/p2p/base/faketransportcontroller.h"
#include "webrtc/pc/channelmanager.h"
using ::testing::_;
using ::testing::Exactly;
@ -47,56 +41,69 @@ static const uint32_t kAudioSsrc2 = 101;
namespace webrtc {
class RtpSenderReceiverTest : public testing::Test {
// Helper class to test RtpSender/RtpReceiver.
class MockAudioProvider : public AudioProviderInterface {
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_(webrtc::Call::Config()),
fake_media_controller_(&channel_manager_, &fake_call_),
stream_(MediaStream::Create(kStreamLabel1)) {
// Create channels to be used by the RtpSenders and RtpReceivers.
channel_manager_.Init();
voice_channel_ = channel_manager_.CreateVoiceChannel(
&fake_media_controller_, &fake_transport_controller_, cricket::CN_AUDIO,
nullptr, false, cricket::AudioOptions());
video_channel_ = channel_manager_.CreateVideoChannel(
&fake_media_controller_, &fake_transport_controller_, cricket::CN_VIDEO,
nullptr, false, 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_);
// TODO(nisse): Valid overrides commented out, because the gmock
// methods don't use any override declarations, and we want to avoid
// warnings from -Winconsistent-missing-override. See
// http://crbug.com/428099.
~MockAudioProvider() /* override */ {}
// 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));
MOCK_METHOD2(SetAudioPlayout,
void(uint32_t ssrc,
bool enable));
MOCK_METHOD4(SetAudioSend,
void(uint32_t ssrc,
bool enable,
const cricket::AudioOptions& options,
cricket::AudioSource* source));
MOCK_METHOD2(SetAudioPlayoutVolume, void(uint32_t ssrc, double volume));
MOCK_CONST_METHOD1(GetAudioRtpSendParameters, RtpParameters(uint32_t ssrc));
MOCK_METHOD2(SetAudioRtpSendParameters,
bool(uint32_t ssrc, const RtpParameters&));
MOCK_CONST_METHOD1(GetAudioRtpReceiveParameters,
RtpParameters(uint32_t ssrc));
MOCK_METHOD2(SetAudioRtpReceiveParameters,
bool(uint32_t ssrc, const RtpParameters&));
void SetRawAudioSink(
uint32_t, std::unique_ptr<AudioSinkInterface> sink) /* override */ {
sink_ = std::move(sink);
}
void TearDown() override { channel_manager_.Terminate(); }
private:
std::unique_ptr<AudioSinkInterface> sink_;
};
// Helper class to test RtpSender/RtpReceiver.
class MockVideoProvider : public VideoProviderInterface {
public:
virtual ~MockVideoProvider() {}
MOCK_METHOD3(SetVideoPlayout,
void(uint32_t ssrc,
bool enable,
rtc::VideoSinkInterface<cricket::VideoFrame>* sink));
MOCK_METHOD4(SetVideoSend,
void(uint32_t ssrc,
bool enable,
const cricket::VideoOptions* options,
rtc::VideoSourceInterface<cricket::VideoFrame>* source));
MOCK_CONST_METHOD1(GetVideoRtpSendParameters, RtpParameters(uint32_t ssrc));
MOCK_METHOD2(SetVideoRtpSendParameters,
bool(uint32_t ssrc, const RtpParameters&));
MOCK_CONST_METHOD1(GetVideoRtpReceiveParameters,
RtpParameters(uint32_t ssrc));
MOCK_METHOD2(SetVideoRtpReceiveParameters,
bool(uint32_t ssrc, const RtpParameters&));
};
class RtpSenderReceiverTest : public testing::Test {
public:
virtual void SetUp() {
stream_ = MediaStream::Create(kStreamLabel1);
}
void AddVideoTrack() {
rtc::scoped_refptr<VideoTrackSourceInterface> source(
@ -105,128 +112,68 @@ class RtpSenderReceiverTest : public testing::Test {
EXPECT_TRUE(stream_->AddTrack(video_track_));
}
void CreateAudioRtpSender() { CreateAudioRtpSender(nullptr); }
void CreateAudioRtpSender(rtc::scoped_refptr<LocalAudioSource> source) {
audio_track_ = AudioTrack::Create(kAudioTrackId, source);
void CreateAudioRtpSender() {
audio_track_ = AudioTrack::Create(kAudioTrackId, NULL);
EXPECT_TRUE(stream_->AddTrack(audio_track_));
EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
audio_rtp_sender_ =
new AudioRtpSender(stream_->GetAudioTracks()[0], stream_->label(),
voice_channel_, nullptr);
&audio_provider_, nullptr);
audio_rtp_sender_->SetSsrc(kAudioSsrc);
VerifyVoiceChannelInput();
}
void CreateVideoRtpSender() {
AddVideoTrack();
EXPECT_CALL(video_provider_,
SetVideoSend(kVideoSsrc, true, _, video_track_.get()));
video_rtp_sender_ = new VideoRtpSender(stream_->GetVideoTracks()[0],
stream_->label(), video_channel_);
stream_->label(), &video_provider_);
video_rtp_sender_->SetSsrc(kVideoSsrc);
VerifyVideoChannelInput();
}
void DestroyAudioRtpSender() {
EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _))
.Times(1);
audio_rtp_sender_ = nullptr;
VerifyVoiceChannelNoInput();
}
void DestroyVideoRtpSender() {
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _, nullptr))
.Times(1);
video_rtp_sender_ = nullptr;
VerifyVideoChannelNoInput();
}
void CreateAudioRtpReceiver() {
audio_track_ = AudioTrack::Create(
kAudioTrackId, RemoteAudioSource::Create(kAudioSsrc, NULL));
EXPECT_TRUE(stream_->AddTrack(audio_track_));
EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, true));
audio_rtp_receiver_ = new AudioRtpReceiver(stream_, kAudioTrackId,
kAudioSsrc, voice_channel_);
kAudioSsrc, &audio_provider_);
audio_track_ = audio_rtp_receiver_->audio_track();
VerifyVoiceChannelOutput();
}
void CreateVideoRtpReceiver() {
EXPECT_CALL(video_provider_, SetVideoPlayout(kVideoSsrc, true, _));
video_rtp_receiver_ =
new VideoRtpReceiver(stream_, kVideoTrackId, rtc::Thread::Current(),
kVideoSsrc, video_channel_);
kVideoSsrc, &video_provider_);
video_track_ = video_rtp_receiver_->video_track();
VerifyVideoChannelOutput();
}
void DestroyAudioRtpReceiver() {
EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, false));
audio_rtp_receiver_ = nullptr;
VerifyVoiceChannelNoOutput();
}
void DestroyVideoRtpReceiver() {
EXPECT_CALL(video_provider_, SetVideoPlayout(kVideoSsrc, false, NULL));
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:
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_;
MockAudioProvider audio_provider_;
MockVideoProvider video_provider_;
rtc::scoped_refptr<AudioRtpSender> audio_rtp_sender_;
rtc::scoped_refptr<VideoRtpSender> video_rtp_sender_;
rtc::scoped_refptr<AudioRtpReceiver> audio_rtp_receiver_;
@ -236,96 +183,72 @@ class RtpSenderReceiverTest : public testing::Test {
rtc::scoped_refptr<AudioTrackInterface> audio_track_;
};
// Test that |voice_channel_| is updated when an audio track is associated
// Test that |audio_provider_| is notified 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
// Test that |video_provider_| is notified 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
// Test that |audio_provider_| is notified when a remote audio and 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 that |video_provider_| is notified 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();
EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _));
audio_track_->set_enabled(false);
EXPECT_TRUE(voice_media_channel_->IsStreamMuted(kAudioSsrc));
EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
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);
EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, false));
audio_track_->set_enabled(false);
EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
EXPECT_EQ(0, volume);
EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, true));
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();
EXPECT_CALL(video_provider_,
SetVideoSend(kVideoSsrc, false, _, video_track_.get()));
video_track_->set_enabled(false);
EXPECT_CALL(video_provider_,
SetVideoSend(kVideoSsrc, true, _, video_track_.get()));
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();
@ -340,268 +263,282 @@ TEST_F(RtpSenderReceiverTest, RemoteVideoTrackState) {
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);
double volume = 0.5;
EXPECT_CALL(audio_provider_, SetAudioPlayoutVolume(kAudioSsrc, volume));
audio_track_->GetSource()->SetVolume(volume);
// Disable the audio track, this should prevent setting the volume.
EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, false));
audio_track_->set_enabled(false);
audio_track_->GetSource()->SetVolume(0.8);
EXPECT_TRUE(voice_media_channel_->GetOutputVolume(kAudioSsrc, &volume));
EXPECT_EQ(0, volume);
audio_track_->GetSource()->SetVolume(1.0);
// When the track is enabled, the previously set volume should take effect.
EXPECT_CALL(audio_provider_, SetAudioPlayout(kAudioSsrc, true));
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);
double new_volume = 0.8;
EXPECT_CALL(audio_provider_, SetAudioPlayoutVolume(kAudioSsrc, new_volume));
audio_track_->GetSource()->SetVolume(new_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 that provider methods aren't called without both a track and an SSRC.
TEST_F(RtpSenderReceiverTest, AudioSenderWithoutTrackAndSsrc) {
audio_rtp_sender_ = new AudioRtpSender(voice_channel_, nullptr);
rtc::scoped_refptr<AudioRtpSender> sender =
new AudioRtpSender(&audio_provider_, 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();
EXPECT_TRUE(sender->SetTrack(track));
EXPECT_TRUE(sender->SetTrack(nullptr));
sender->SetSsrc(kAudioSsrc);
sender->SetSsrc(0);
// Just let it get destroyed and make sure it doesn't call any methods on the
// provider interface.
}
// Test that the media channel isn't enabled for sending if the video sender
// doesn't have both a track and SSRC.
// Test that provider methods aren't called without both a track and an 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();
rtc::scoped_refptr<VideoRtpSender> sender =
new VideoRtpSender(&video_provider_);
EXPECT_TRUE(sender->SetTrack(video_track_));
EXPECT_TRUE(sender->SetTrack(nullptr));
sender->SetSsrc(kVideoSsrc);
sender->SetSsrc(0);
// Just let it get destroyed and make sure it doesn't call any methods on the
// provider interface.
}
// 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 that an audio sender calls the expected methods on the provider once
// it 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<AudioRtpSender> sender =
new AudioRtpSender(&audio_provider_, nullptr);
rtc::scoped_refptr<AudioTrackInterface> track =
AudioTrack::Create(kAudioTrackId, nullptr);
audio_rtp_sender_->SetSsrc(kAudioSsrc);
audio_rtp_sender_->SetTrack(track);
VerifyVoiceChannelInput();
sender->SetSsrc(kAudioSsrc);
EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
sender->SetTrack(track);
DestroyAudioRtpSender();
// Calls expected from destructor.
EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
}
// 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 that an audio sender calls the expected methods on the provider once
// it 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<AudioRtpSender> sender =
new AudioRtpSender(&audio_provider_, nullptr);
rtc::scoped_refptr<AudioTrackInterface> track =
AudioTrack::Create(kAudioTrackId, nullptr);
audio_rtp_sender_->SetTrack(track);
audio_rtp_sender_->SetSsrc(kAudioSsrc);
VerifyVoiceChannelInput();
sender->SetTrack(track);
EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
sender->SetSsrc(kAudioSsrc);
DestroyAudioRtpSender();
// Calls expected from destructor.
EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
}
// 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 that a video sender calls the expected methods on the provider once
// it 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();
rtc::scoped_refptr<VideoRtpSender> sender =
new VideoRtpSender(&video_provider_);
sender->SetSsrc(kVideoSsrc);
EXPECT_CALL(video_provider_,
SetVideoSend(kVideoSsrc, true, _, video_track_.get()));
sender->SetTrack(video_track_);
DestroyVideoRtpSender();
// Calls expected from destructor.
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _, nullptr))
.Times(1);
}
// 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 that a video sender calls the expected methods on the provider once
// it 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();
rtc::scoped_refptr<VideoRtpSender> sender =
new VideoRtpSender(&video_provider_);
sender->SetTrack(video_track_);
EXPECT_CALL(video_provider_,
SetVideoSend(kVideoSsrc, true, _, video_track_.get()));
sender->SetSsrc(kVideoSsrc);
DestroyVideoRtpSender();
// Calls expected from destructor.
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _, nullptr))
.Times(1);
}
// Test that the media channel stops sending when the audio sender's SSRC is set
// to 0.
// Test that the sender is disconnected from the provider when its SSRC is
// set to 0.
TEST_F(RtpSenderReceiverTest, AudioSenderSsrcSetToZero) {
CreateAudioRtpSender();
rtc::scoped_refptr<AudioTrackInterface> track =
AudioTrack::Create(kAudioTrackId, nullptr);
EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
rtc::scoped_refptr<AudioRtpSender> sender =
new AudioRtpSender(track, kStreamLabel1, &audio_provider_, nullptr);
sender->SetSsrc(kAudioSsrc);
audio_rtp_sender_->SetSsrc(0);
VerifyVoiceChannelNoInput();
EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
sender->SetSsrc(0);
// Make sure it's SetSsrc that called methods on the provider, and not the
// destructor.
EXPECT_CALL(audio_provider_, SetAudioSend(_, _, _, _)).Times(0);
}
// Test that the media channel stops sending when the video sender's SSRC is set
// to 0.
// Test that the sender is disconnected from the provider when its SSRC is
// set to 0.
TEST_F(RtpSenderReceiverTest, VideoSenderSsrcSetToZero) {
CreateAudioRtpSender();
AddVideoTrack();
EXPECT_CALL(video_provider_,
SetVideoSend(kVideoSsrc, true, _, video_track_.get()));
rtc::scoped_refptr<VideoRtpSender> sender =
new VideoRtpSender(video_track_, kStreamLabel1, &video_provider_);
sender->SetSsrc(kVideoSsrc);
audio_rtp_sender_->SetSsrc(0);
VerifyVideoChannelNoInput();
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _, nullptr))
.Times(1);
sender->SetSsrc(0);
// Make sure it's SetSsrc that called methods on the provider, and not the
// destructor.
EXPECT_CALL(video_provider_, SetVideoSend(_, _, _, _)).Times(0);
}
// Test that the media channel stops sending when the audio sender's track is
// set to null.
TEST_F(RtpSenderReceiverTest, AudioSenderTrackSetToNull) {
CreateAudioRtpSender();
rtc::scoped_refptr<AudioTrackInterface> track =
AudioTrack::Create(kAudioTrackId, nullptr);
EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
rtc::scoped_refptr<AudioRtpSender> sender =
new AudioRtpSender(track, kStreamLabel1, &audio_provider_, nullptr);
sender->SetSsrc(kAudioSsrc);
EXPECT_TRUE(audio_rtp_sender_->SetTrack(nullptr));
VerifyVoiceChannelNoInput();
// Expect that SetAudioSend will be called before the reference to the track
// is released.
EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, nullptr))
.Times(1)
.WillOnce(InvokeWithoutArgs([&track] {
EXPECT_LT(2, track->AddRef());
track->Release();
}));
EXPECT_TRUE(sender->SetTrack(nullptr));
// Make sure it's SetTrack that called methods on the provider, and not the
// destructor.
EXPECT_CALL(audio_provider_, SetAudioSend(_, _, _, _)).Times(0);
}
// Test that the media channel stops sending when the video sender's track is
// set to null.
TEST_F(RtpSenderReceiverTest, VideoSenderTrackSetToNull) {
CreateVideoRtpSender();
rtc::scoped_refptr<VideoTrackSourceInterface> source(
FakeVideoTrackSource::Create());
rtc::scoped_refptr<VideoTrackInterface> track =
VideoTrack::Create(kVideoTrackId, source);
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, true, _, track.get()));
rtc::scoped_refptr<VideoRtpSender> sender =
new VideoRtpSender(track, kStreamLabel1, &video_provider_);
sender->SetSsrc(kVideoSsrc);
video_rtp_sender_->SetSsrc(0);
VerifyVideoChannelNoInput();
// Expect that SetVideoSend will be called before the reference to the track
// is released.
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _, nullptr))
.Times(1)
.WillOnce(InvokeWithoutArgs([&track] {
EXPECT_LT(2, track->AddRef());
track->Release();
}));
EXPECT_TRUE(sender->SetTrack(nullptr));
// Make sure it's SetTrack that called methods on the provider, and not the
// destructor.
EXPECT_CALL(video_provider_, SetVideoSend(_, _, _, _)).Times(0);
}
// 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();
AddVideoTrack();
rtc::scoped_refptr<AudioTrackInterface> track =
AudioTrack::Create(kAudioTrackId, nullptr);
EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, true, _, _));
rtc::scoped_refptr<AudioRtpSender> sender =
new AudioRtpSender(track, kStreamLabel1, &audio_provider_, nullptr);
sender->SetSsrc(kAudioSsrc);
audio_rtp_sender_->SetSsrc(kAudioSsrc2);
VerifyVoiceChannelNoInput(kAudioSsrc);
VerifyVoiceChannelInput(kAudioSsrc2);
EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc, false, _, _)).Times(1);
EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc2, true, _, _)).Times(1);
sender->SetSsrc(kAudioSsrc2);
audio_rtp_sender_ = nullptr;
VerifyVoiceChannelNoInput(kAudioSsrc2);
// Calls expected from destructor.
EXPECT_CALL(audio_provider_, SetAudioSend(kAudioSsrc2, false, _, _)).Times(1);
}
// 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();
AddVideoTrack();
EXPECT_CALL(video_provider_,
SetVideoSend(kVideoSsrc, true, _, video_track_.get()));
rtc::scoped_refptr<VideoRtpSender> sender =
new VideoRtpSender(video_track_, kStreamLabel1, &video_provider_);
sender->SetSsrc(kVideoSsrc);
video_rtp_sender_->SetSsrc(kVideoSsrc2);
VerifyVideoChannelNoInput(kVideoSsrc);
VerifyVideoChannelInput(kVideoSsrc2);
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc, false, _, nullptr))
.Times(1);
EXPECT_CALL(video_provider_,
SetVideoSend(kVideoSsrc2, true, _, video_track_.get()))
.Times(1);
sender->SetSsrc(kVideoSsrc2);
video_rtp_sender_ = nullptr;
VerifyVideoChannelNoInput(kVideoSsrc2);
// Calls expected from destructor.
EXPECT_CALL(video_provider_, SetVideoSend(kVideoSsrc2, false, _, nullptr))
.Times(1);
}
TEST_F(RtpSenderReceiverTest, AudioSenderCanSetParameters) {
CreateAudioRtpSender();
EXPECT_CALL(audio_provider_, GetAudioRtpSendParameters(kAudioSsrc))
.WillOnce(Return(RtpParameters()));
EXPECT_CALL(audio_provider_, SetAudioRtpSendParameters(kAudioSsrc, _))
.WillOnce(Return(true));
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();
EXPECT_CALL(video_provider_, GetVideoRtpSendParameters(kVideoSsrc))
.WillOnce(Return(RtpParameters()));
EXPECT_CALL(video_provider_, SetVideoRtpSendParameters(kVideoSsrc, _))
.WillOnce(Return(true));
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();
EXPECT_CALL(audio_provider_, GetAudioRtpReceiveParameters(kAudioSsrc))
.WillOnce(Return(RtpParameters()));
EXPECT_CALL(audio_provider_, SetAudioRtpReceiveParameters(kAudioSsrc, _))
.WillOnce(Return(true));
RtpParameters params = audio_rtp_receiver_->GetParameters();
EXPECT_EQ(1u, params.encodings.size());
EXPECT_TRUE(audio_rtp_receiver_->SetParameters(params));
DestroyAudioRtpReceiver();
@ -610,8 +547,11 @@ TEST_F(RtpSenderReceiverTest, AudioReceiverCanSetParameters) {
TEST_F(RtpSenderReceiverTest, VideoReceiverCanSetParameters) {
CreateVideoRtpReceiver();
EXPECT_CALL(video_provider_, GetVideoRtpReceiveParameters(kVideoSsrc))
.WillOnce(Return(RtpParameters()));
EXPECT_CALL(video_provider_, SetVideoRtpReceiveParameters(kVideoSsrc, _))
.WillOnce(Return(true));
RtpParameters params = video_rtp_receiver_->GetParameters();
EXPECT_EQ(1u, params.encodings.size());
EXPECT_TRUE(video_rtp_receiver_->SetParameters(params));
DestroyVideoRtpReceiver();