Adds network thread to rtc::BaseChannel
BaseChannel do calls to transport_channel on network_thread,
while keep calls to media_engine on worker_thread.
It still works when network_thread == worker_thread.
BUG=webrtc:5645
R=pthatcher@webrtc.org
Review URL: https://codereview.webrtc.org/1903393004 .
Cr-Commit-Position: refs/heads/master@{#12690}
diff --git a/webrtc/api/peerconnectionfactory.cc b/webrtc/api/peerconnectionfactory.cc
index b2a3798..8c8fb6f 100644
--- a/webrtc/api/peerconnectionfactory.cc
+++ b/webrtc/api/peerconnectionfactory.cc
@@ -172,8 +172,9 @@
worker_thread_->Invoke<cricket::MediaEngineInterface*>(rtc::Bind(
&PeerConnectionFactory::CreateMediaEngine_w, this));
- channel_manager_.reset(
- new cricket::ChannelManager(media_engine, worker_thread_));
+ rtc::Thread* const network_thread = worker_thread_;
+ channel_manager_.reset(new cricket::ChannelManager(
+ media_engine, worker_thread_, network_thread));
channel_manager_->SetVideoRtxEnabled(true);
if (!channel_manager_->Init()) {
diff --git a/webrtc/api/statscollector_unittest.cc b/webrtc/api/statscollector_unittest.cc
index 2924c51..00b50b6 100644
--- a/webrtc/api/statscollector_unittest.cc
+++ b/webrtc/api/statscollector_unittest.cc
@@ -496,12 +496,15 @@
class StatsCollectorTest : public testing::Test {
protected:
StatsCollectorTest()
- : media_engine_(new cricket::FakeMediaEngine()),
- channel_manager_(
- new cricket::ChannelManager(media_engine_, rtc::Thread::Current())),
+ : worker_thread_(rtc::Thread::Current()),
+ network_thread_(rtc::Thread::Current()),
+ media_engine_(new cricket::FakeMediaEngine()),
+ channel_manager_(new cricket::ChannelManager(media_engine_,
+ worker_thread_,
+ network_thread_)),
media_controller_(
webrtc::MediaControllerInterface::Create(cricket::MediaConfig(),
- rtc::Thread::Current(),
+ worker_thread_,
channel_manager_.get())),
session_(media_controller_.get()) {
// By default, we ignore session GetStats calls.
@@ -760,6 +763,8 @@
srtp_crypto_suite);
}
+ rtc::Thread* const worker_thread_;
+ rtc::Thread* const network_thread_;
cricket::FakeMediaEngine* media_engine_;
std::unique_ptr<cricket::ChannelManager> channel_manager_;
std::unique_ptr<webrtc::MediaControllerInterface> media_controller_;
@@ -828,8 +833,9 @@
Return(true)));
MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
- cricket::VideoChannel video_channel(rtc::Thread::Current(), media_channel,
- nullptr, kVideoChannelName, false);
+ cricket::VideoChannel video_channel(worker_thread_, network_thread_,
+ media_channel, nullptr, kVideoChannelName,
+ false);
StatsReports reports; // returned values.
cricket::VideoSenderInfo video_sender_info;
cricket::VideoMediaInfo stats_read;
@@ -874,8 +880,9 @@
Return(true)));
MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
- cricket::VideoChannel video_channel(rtc::Thread::Current(), media_channel,
- nullptr, kVideoChannelName, false);
+ cricket::VideoChannel video_channel(worker_thread_, network_thread_,
+ media_channel, nullptr, kVideoChannelName,
+ false);
StatsReports reports; // returned values.
cricket::VideoSenderInfo video_sender_info;
@@ -949,8 +956,8 @@
StatsCollectorForTest stats(&pc_);
MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
- cricket::VideoChannel video_channel(rtc::Thread::Current(), media_channel,
- nullptr, "video", false);
+ cricket::VideoChannel video_channel(worker_thread_, network_thread_,
+ media_channel, nullptr, "video", false);
AddOutgoingVideoTrackStats();
stats.AddStream(stream_);
@@ -985,8 +992,9 @@
Return(true)));
MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
- cricket::VideoChannel video_channel(rtc::Thread::Current(), media_channel,
- nullptr, kVideoChannelName, false);
+ cricket::VideoChannel video_channel(worker_thread_, network_thread_,
+ media_channel, nullptr, kVideoChannelName,
+ false);
AddOutgoingVideoTrackStats();
stats.AddStream(stream_);
@@ -1053,8 +1061,8 @@
MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
// The transport_name known by the video channel.
const std::string kVcName("vcname");
- cricket::VideoChannel video_channel(rtc::Thread::Current(), media_channel,
- nullptr, kVcName, false);
+ cricket::VideoChannel video_channel(worker_thread_, network_thread_,
+ media_channel, nullptr, kVcName, false);
AddOutgoingVideoTrackStats();
stats.AddStream(stream_);
@@ -1111,8 +1119,8 @@
MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
// The transport_name known by the video channel.
const std::string kVcName("vcname");
- cricket::VideoChannel video_channel(rtc::Thread::Current(), media_channel,
- nullptr, kVcName, false);
+ cricket::VideoChannel video_channel(worker_thread_, network_thread_,
+ media_channel, nullptr, kVcName, false);
AddOutgoingVideoTrackStats();
stats.AddStream(stream_);
@@ -1137,8 +1145,8 @@
MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
// The transport_name known by the video channel.
const std::string kVcName("vcname");
- cricket::VideoChannel video_channel(rtc::Thread::Current(), media_channel,
- nullptr, kVcName, false);
+ cricket::VideoChannel video_channel(worker_thread_, network_thread_,
+ media_channel, nullptr, kVcName, false);
AddOutgoingVideoTrackStats();
stats.AddStream(stream_);
@@ -1192,8 +1200,9 @@
Return(true)));
MockVideoMediaChannel* media_channel = new MockVideoMediaChannel();
- cricket::VideoChannel video_channel(rtc::Thread::Current(), media_channel,
- nullptr, kVideoChannelName, false);
+ cricket::VideoChannel video_channel(worker_thread_, network_thread_,
+ media_channel, nullptr, kVideoChannelName,
+ false);
AddIncomingVideoTrackStats();
stats.AddStream(stream_);
@@ -1504,8 +1513,9 @@
MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
// The transport_name known by the voice channel.
const std::string kVcName("vcname");
- cricket::VoiceChannel voice_channel(rtc::Thread::Current(), media_engine_,
- media_channel, nullptr, kVcName, false);
+ cricket::VoiceChannel voice_channel(worker_thread_, network_thread_,
+ media_engine_, media_channel, nullptr,
+ kVcName, false);
AddOutgoingAudioTrackStats();
stats.AddStream(stream_);
stats.AddLocalAudioTrack(audio_track_, kSsrcOfTrack);
@@ -1539,8 +1549,9 @@
MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
// The transport_name known by the voice channel.
const std::string kVcName("vcname");
- cricket::VoiceChannel voice_channel(rtc::Thread::Current(), media_engine_,
- media_channel, nullptr, kVcName, false);
+ cricket::VoiceChannel voice_channel(worker_thread_, network_thread_,
+ media_engine_, media_channel, nullptr,
+ kVcName, false);
AddIncomingAudioTrackStats();
stats.AddStream(stream_);
@@ -1568,8 +1579,9 @@
MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
// The transport_name known by the voice channel.
const std::string kVcName("vcname");
- cricket::VoiceChannel voice_channel(rtc::Thread::Current(), media_engine_,
- media_channel, nullptr, kVcName, false);
+ cricket::VoiceChannel voice_channel(worker_thread_, network_thread_,
+ media_engine_, media_channel, nullptr,
+ kVcName, false);
AddOutgoingAudioTrackStats();
stats.AddStream(stream_);
stats.AddLocalAudioTrack(audio_track_.get(), kSsrcOfTrack);
@@ -1629,8 +1641,9 @@
MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
// The transport_name known by the voice channel.
const std::string kVcName("vcname");
- cricket::VoiceChannel voice_channel(rtc::Thread::Current(), media_engine_,
- media_channel, nullptr, kVcName, false);
+ cricket::VoiceChannel voice_channel(worker_thread_, network_thread_,
+ media_engine_, media_channel, nullptr,
+ kVcName, false);
// Create a local stream with a local audio track and adds it to the stats.
AddOutgoingAudioTrackStats();
@@ -1716,8 +1729,9 @@
MockVoiceMediaChannel* media_channel = new MockVoiceMediaChannel();
// The transport_name known by the voice channel.
const std::string kVcName("vcname");
- cricket::VoiceChannel voice_channel(rtc::Thread::Current(), media_engine_,
- media_channel, nullptr, kVcName, false);
+ cricket::VoiceChannel voice_channel(worker_thread_, network_thread_,
+ media_engine_, media_channel, nullptr,
+ kVcName, false);
// Create a local stream with a local audio track and adds it to the stats.
AddOutgoingAudioTrackStats();
diff --git a/webrtc/api/webrtcsession.cc b/webrtc/api/webrtcsession.cc
index 9f84840..c3ea1c8 100644
--- a/webrtc/api/webrtcsession.cc
+++ b/webrtc/api/webrtcsession.cc
@@ -1797,8 +1797,8 @@
this, &WebRtcSession::OnDtlsSetupFailure);
SignalVoiceChannelCreated();
- voice_channel_->transport_channel()->SignalSentPacket.connect(
- this, &WebRtcSession::OnSentPacket_w);
+ voice_channel_->SignalSentPacket.connect(this,
+ &WebRtcSession::OnSentPacket_w);
return true;
}
@@ -1814,8 +1814,8 @@
this, &WebRtcSession::OnDtlsSetupFailure);
SignalVideoChannelCreated();
- video_channel_->transport_channel()->SignalSentPacket.connect(
- this, &WebRtcSession::OnSentPacket_w);
+ video_channel_->SignalSentPacket.connect(this,
+ &WebRtcSession::OnSentPacket_w);
return true;
}
@@ -1836,8 +1836,7 @@
this, &WebRtcSession::OnDtlsSetupFailure);
SignalDataChannelCreated();
- data_channel_->transport_channel()->SignalSentPacket.connect(
- this, &WebRtcSession::OnSentPacket_w);
+ data_channel_->SignalSentPacket.connect(this, &WebRtcSession::OnSentPacket_w);
return true;
}
@@ -2155,8 +2154,7 @@
}
}
-void WebRtcSession::OnSentPacket_w(cricket::TransportChannel* channel,
- const rtc::SentPacket& sent_packet) {
+void WebRtcSession::OnSentPacket_w(const rtc::SentPacket& sent_packet) {
RTC_DCHECK(worker_thread()->IsCurrent());
media_controller_->call_w()->OnSentPacket(sent_packet);
}
diff --git a/webrtc/api/webrtcsession.h b/webrtc/api/webrtcsession.h
index 970f967..1408b22 100644
--- a/webrtc/api/webrtcsession.h
+++ b/webrtc/api/webrtcsession.h
@@ -465,8 +465,7 @@
void ReportNegotiatedCiphers(const cricket::TransportStats& stats);
- void OnSentPacket_w(cricket::TransportChannel* channel,
- const rtc::SentPacket& sent_packet);
+ void OnSentPacket_w(const rtc::SentPacket& sent_packet);
rtc::Thread* const signaling_thread_;
rtc::Thread* const worker_thread_;
diff --git a/webrtc/api/webrtcsession_unittest.cc b/webrtc/api/webrtcsession_unittest.cc
index 34d8258..87481a8 100644
--- a/webrtc/api/webrtcsession_unittest.cc
+++ b/webrtc/api/webrtcsession_unittest.cc
@@ -1316,6 +1316,8 @@
SetupLoopbackCall();
+ // Wait for channel to be ready for sending.
+ EXPECT_TRUE_WAIT(media_engine_->GetVideoChannel(0)->sending(), 100);
uint8_t test_packet[15] = {0};
rtc::PacketOptions options;
options.packet_id = 10;
diff --git a/webrtc/media/base/fakemediaengine.h b/webrtc/media/base/fakemediaengine.h
index 1cddda8..94e33fe 100644
--- a/webrtc/media/base/fakemediaengine.h
+++ b/webrtc/media/base/fakemediaengine.h
@@ -55,7 +55,9 @@
const std::list<std::string>& rtp_packets() const { return rtp_packets_; }
const std::list<std::string>& rtcp_packets() const { return rtcp_packets_; }
- bool SendRtp(const void* data, int len, const rtc::PacketOptions& options) {
+ bool SendRtp(const void* data,
+ size_t len,
+ const rtc::PacketOptions& options) {
if (!sending_) {
return false;
}
@@ -63,13 +65,13 @@
kMaxRtpPacketLen);
return Base::SendPacket(&packet, options);
}
- bool SendRtcp(const void* data, int len) {
+ bool SendRtcp(const void* data, size_t len) {
rtc::CopyOnWriteBuffer packet(reinterpret_cast<const uint8_t*>(data), len,
kMaxRtpPacketLen);
return Base::SendRtcp(&packet, rtc::PacketOptions());
}
- bool CheckRtp(const void* data, int len) {
+ bool CheckRtp(const void* data, size_t len) {
bool success = !rtp_packets_.empty();
if (success) {
std::string packet = rtp_packets_.front();
@@ -78,7 +80,7 @@
}
return success;
}
- bool CheckRtcp(const void* data, int len) {
+ bool CheckRtcp(const void* data, size_t len) {
bool success = !rtcp_packets_.empty();
if (success) {
std::string packet = rtcp_packets_.front();
diff --git a/webrtc/pc/channel.cc b/webrtc/pc/channel.cc
index 4d47e87..4e58c8f 100644
--- a/webrtc/pc/channel.cc
+++ b/webrtc/pc/channel.cc
@@ -37,12 +37,18 @@
channel->SetRawAudioSink(ssrc, std::move(*sink));
return true;
}
+
+struct SendPacketMessageData : public rtc::MessageData {
+ rtc::CopyOnWriteBuffer packet;
+ rtc::PacketOptions options;
+};
+
} // namespace
enum {
MSG_EARLYMEDIATIMEOUT = 1,
- MSG_RTPPACKET,
- MSG_RTCPPACKET,
+ MSG_SEND_RTP_PACKET,
+ MSG_SEND_RTCP_PACKET,
MSG_CHANNEL_ERROR,
MSG_READYTOSENDDATA,
MSG_DATARECEIVED,
@@ -61,11 +67,6 @@
}
}
-struct PacketMessageData : public rtc::MessageData {
- rtc::CopyOnWriteBuffer packet;
- rtc::PacketOptions options;
-};
-
struct VoiceChannelErrorMessageData : public rtc::MessageData {
VoiceChannelErrorMessageData(uint32_t in_ssrc,
VoiceMediaChannel::Error in_error)
@@ -142,30 +143,38 @@
send_params->max_bandwidth_bps = desc->bandwidth();
}
-BaseChannel::BaseChannel(rtc::Thread* thread,
+BaseChannel::BaseChannel(rtc::Thread* worker_thread,
+ rtc::Thread* network_thread,
MediaChannel* media_channel,
TransportController* transport_controller,
const std::string& content_name,
bool rtcp)
- : worker_thread_(thread),
- transport_controller_(transport_controller),
- media_channel_(media_channel),
+ : worker_thread_(worker_thread),
+ network_thread_(network_thread),
+
content_name_(content_name),
+
+ transport_controller_(transport_controller),
rtcp_transport_enabled_(rtcp),
transport_channel_(nullptr),
rtcp_transport_channel_(nullptr),
- enabled_(false),
- writable_(false),
rtp_ready_to_send_(false),
rtcp_ready_to_send_(false),
+ writable_(false),
was_ever_writable_(false),
- local_content_direction_(MD_INACTIVE),
- remote_content_direction_(MD_INACTIVE),
has_received_packet_(false),
dtls_keyed_(false),
secure_required_(false),
- rtp_abs_sendtime_extn_id_(-1) {
+ rtp_abs_sendtime_extn_id_(-1),
+
+ media_channel_(media_channel),
+ enabled_(false),
+ local_content_direction_(MD_INACTIVE),
+ remote_content_direction_(MD_INACTIVE) {
ASSERT(worker_thread_ == rtc::Thread::Current());
+ if (transport_controller) {
+ RTC_DCHECK_EQ(network_thread, transport_controller->worker_thread());
+ }
LOG(LS_INFO) << "Created channel for " << content_name;
}
@@ -174,14 +183,22 @@
ASSERT(worker_thread_ == rtc::Thread::Current());
Deinit();
StopConnectionMonitor();
- FlushRtcpMessages(); // Send any outstanding RTCP packets.
- worker_thread_->Clear(this); // eats any outstanding messages or packets
+ // Send any outstanding RTCP packets.
+ network_thread_->Invoke<void>(Bind(&BaseChannel::FlushRtcpMessages_n, this));
+ // Eats any outstanding messages or packets.
+ worker_thread_->Clear(&invoker_);
+ worker_thread_->Clear(this);
// We must destroy the media channel before the transport channel, otherwise
// the media channel may try to send on the dead transport channel. NULLing
// is not an effective strategy since the sends will come on another thread.
delete media_channel_;
- // Note that we don't just call set_transport_channel(nullptr) because that
+ // Note that we don't just call SetTransportChannel_n(nullptr) because that
// would call a pure virtual method which we can't do from a destructor.
+ network_thread_->Invoke<void>(Bind(&BaseChannel::DeinitNetwork_n, this));
+ LOG(LS_INFO) << "Destroyed channel";
+}
+
+void BaseChannel::DeinitNetwork_n() {
if (transport_channel_) {
DisconnectFromTransportChannel(transport_channel_);
transport_controller_->DestroyTransportChannel_w(
@@ -192,39 +209,49 @@
transport_controller_->DestroyTransportChannel_w(
transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP);
}
- LOG(LS_INFO) << "Destroyed channel";
+ network_thread_->Clear(this);
}
-bool BaseChannel::Init() {
- if (!SetTransport(content_name())) {
- return false;
- }
-
- if (!SetDtlsSrtpCryptoSuites(transport_channel(), false)) {
- return false;
- }
- if (rtcp_transport_enabled() &&
- !SetDtlsSrtpCryptoSuites(rtcp_transport_channel(), true)) {
+bool BaseChannel::Init_w() {
+ if (!network_thread_->Invoke<bool>(Bind(&BaseChannel::InitNetwork_n, this))) {
return false;
}
// Both RTP and RTCP channels are set, we can call SetInterface on
// media channel and it can set network options.
+ RTC_DCHECK(worker_thread_->IsCurrent());
media_channel_->SetInterface(this);
return true;
}
+bool BaseChannel::InitNetwork_n() {
+ RTC_DCHECK(network_thread_->IsCurrent());
+ if (!SetTransport_n(content_name())) {
+ return false;
+ }
+
+ if (!SetDtlsSrtpCryptoSuites_n(transport_channel_, false)) {
+ return false;
+ }
+ if (rtcp_transport_enabled() &&
+ !SetDtlsSrtpCryptoSuites_n(rtcp_transport_channel_, true)) {
+ return false;
+ }
+ return true;
+}
+
void BaseChannel::Deinit() {
+ RTC_DCHECK(worker_thread_->IsCurrent());
media_channel_->SetInterface(NULL);
}
bool BaseChannel::SetTransport(const std::string& transport_name) {
- return worker_thread_->Invoke<bool>(
- Bind(&BaseChannel::SetTransport_w, this, transport_name));
+ return network_thread_->Invoke<bool>(
+ Bind(&BaseChannel::SetTransport_n, this, transport_name));
}
-bool BaseChannel::SetTransport_w(const std::string& transport_name) {
- ASSERT(worker_thread_ == rtc::Thread::Current());
+bool BaseChannel::SetTransport_n(const std::string& transport_name) {
+ RTC_DCHECK(network_thread_->IsCurrent());
if (transport_name == transport_name_) {
// Nothing to do if transport name isn't changing
@@ -234,7 +261,7 @@
// When using DTLS-SRTP, we must reset the SrtpFilter every time the transport
// changes and wait until the DTLS handshake is complete to set the newly
// negotiated parameters.
- if (ShouldSetupDtlsSrtp()) {
+ if (ShouldSetupDtlsSrtp_n()) {
// Set |writable_| to false such that UpdateWritableState_w can set up
// DTLS-SRTP when the writable_ becomes true again.
writable_ = false;
@@ -245,19 +272,19 @@
if (rtcp_transport_enabled()) {
LOG(LS_INFO) << "Create RTCP TransportChannel for " << content_name()
<< " on " << transport_name << " transport ";
- set_rtcp_transport_channel(
+ SetRtcpTransportChannel_n(
transport_controller_->CreateTransportChannel_w(
transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP),
false /* update_writablity */);
- if (!rtcp_transport_channel()) {
+ if (!rtcp_transport_channel_) {
return false;
}
}
// We're not updating the writablity during the transition state.
- set_transport_channel(transport_controller_->CreateTransportChannel_w(
+ SetTransportChannel_n(transport_controller_->CreateTransportChannel_w(
transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP));
- if (!transport_channel()) {
+ if (!transport_channel_) {
return false;
}
@@ -266,14 +293,14 @@
// We can only update the RTCP ready to send after set_transport_channel has
// handled channel writability.
SetReadyToSend(
- true, rtcp_transport_channel() && rtcp_transport_channel()->writable());
+ true, rtcp_transport_channel_ && rtcp_transport_channel_->writable());
}
transport_name_ = transport_name;
return true;
}
-void BaseChannel::set_transport_channel(TransportChannel* new_tc) {
- ASSERT(worker_thread_ == rtc::Thread::Current());
+void BaseChannel::SetTransportChannel_n(TransportChannel* new_tc) {
+ RTC_DCHECK(network_thread_->IsCurrent());
TransportChannel* old_tc = transport_channel_;
if (!old_tc && !new_tc) {
@@ -299,13 +326,13 @@
// Update aggregate writable/ready-to-send state between RTP and RTCP upon
// setting new channel
- UpdateWritableState_w();
+ UpdateWritableState_n();
SetReadyToSend(false, new_tc && new_tc->writable());
}
-void BaseChannel::set_rtcp_transport_channel(TransportChannel* new_tc,
- bool update_writablity) {
- ASSERT(worker_thread_ == rtc::Thread::Current());
+void BaseChannel::SetRtcpTransportChannel_n(TransportChannel* new_tc,
+ bool update_writablity) {
+ RTC_DCHECK(network_thread_->IsCurrent());
TransportChannel* old_tc = rtcp_transport_channel_;
if (!old_tc && !new_tc) {
@@ -323,7 +350,7 @@
rtcp_transport_channel_ = new_tc;
if (new_tc) {
- RTC_CHECK(!(ShouldSetupDtlsSrtp() && srtp_filter_.IsActive()))
+ RTC_CHECK(!(ShouldSetupDtlsSrtp_n() && srtp_filter_.IsActive()))
<< "Setting RTCP for DTLS/SRTP after SrtpFilter is active "
<< "should never happen.";
ConnectToTransportChannel(new_tc);
@@ -335,13 +362,13 @@
if (update_writablity) {
// Update aggregate writable/ready-to-send state between RTP and RTCP upon
// setting new channel
- UpdateWritableState_w();
+ UpdateWritableState_n();
SetReadyToSend(true, new_tc && new_tc->writable());
}
}
void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) {
- ASSERT(worker_thread_ == rtc::Thread::Current());
+ RTC_DCHECK(network_thread_->IsCurrent());
tc->SignalWritableState.connect(this, &BaseChannel::OnWritableState);
tc->SignalReadPacket.connect(this, &BaseChannel::OnChannelRead);
@@ -349,15 +376,18 @@
tc->SignalDtlsState.connect(this, &BaseChannel::OnDtlsState);
tc->SignalSelectedCandidatePairChanged.connect(
this, &BaseChannel::OnSelectedCandidatePairChanged);
+ tc->SignalSentPacket.connect(this, &BaseChannel::SignalSentPacket_n);
}
void BaseChannel::DisconnectFromTransportChannel(TransportChannel* tc) {
- ASSERT(worker_thread_ == rtc::Thread::Current());
+ RTC_DCHECK(network_thread_->IsCurrent());
tc->SignalWritableState.disconnect(this);
tc->SignalReadPacket.disconnect(this);
tc->SignalReadyToSend.disconnect(this);
tc->SignalDtlsState.disconnect(this);
+ tc->SignalSelectedCandidatePairChanged.disconnect(this);
+ tc->SignalSentPacket.disconnect(this);
}
bool BaseChannel::Enable(bool enable) {
@@ -405,8 +435,11 @@
// We pass in the BaseChannel instead of the transport_channel_
// because if the transport_channel_ changes, the ConnectionMonitor
// would be pointing to the wrong TransportChannel.
- connection_monitor_.reset(new ConnectionMonitor(
- this, worker_thread(), rtc::Thread::Current()));
+ // We pass in the network thread because on that thread connection monitor
+ // will call BaseChannel::GetConnectionStats which must be called on the
+ // network thread.
+ connection_monitor_.reset(
+ new ConnectionMonitor(this, network_thread(), rtc::Thread::Current()));
connection_monitor_->SignalUpdate.connect(
this, &BaseChannel::OnConnectionMonitorUpdate);
connection_monitor_->Start(cms);
@@ -420,22 +453,27 @@
}
bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) {
- ASSERT(worker_thread_ == rtc::Thread::Current());
+ RTC_DCHECK(network_thread_->IsCurrent());
return transport_channel_->GetStats(infos);
}
-bool BaseChannel::IsReadyToReceive() const {
+bool BaseChannel::IsReadyToReceive_w() const {
// Receive data if we are enabled and have local content,
return enabled() && IsReceiveContentDirection(local_content_direction_);
}
-bool BaseChannel::IsReadyToSend() const {
+bool BaseChannel::IsReadyToSend_w() const {
// Send outgoing data if we are enabled, have local and remote content,
// and we have had some form of connectivity.
return enabled() && IsReceiveContentDirection(remote_content_direction_) &&
IsSendContentDirection(local_content_direction_) &&
- was_ever_writable() &&
- (srtp_filter_.IsActive() || !ShouldSetupDtlsSrtp());
+ network_thread_->Invoke<bool>(
+ Bind(&BaseChannel::IsTransportReadyToSend_n, this));
+}
+
+bool BaseChannel::IsTransportReadyToSend_n() const {
+ return was_ever_writable() &&
+ (srtp_filter_.IsActive() || !ShouldSetupDtlsSrtp_n());
}
bool BaseChannel::SendPacket(rtc::CopyOnWriteBuffer* packet,
@@ -450,7 +488,15 @@
int BaseChannel::SetOption(SocketType type, rtc::Socket::Option opt,
int value) {
- TransportChannel* channel = NULL;
+ return network_thread_->Invoke<int>(
+ Bind(&BaseChannel::SetOption_n, this, type, opt, value));
+}
+
+int BaseChannel::SetOption_n(SocketType type,
+ rtc::Socket::Option opt,
+ int value) {
+ RTC_DCHECK(network_thread_->IsCurrent());
+ TransportChannel* channel = nullptr;
switch (type) {
case ST_RTP:
channel = transport_channel_;
@@ -467,8 +513,10 @@
}
void BaseChannel::OnWritableState(TransportChannel* channel) {
- ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_);
- UpdateWritableState_w();
+ RTC_DCHECK(channel == transport_channel_ ||
+ channel == rtcp_transport_channel_);
+ RTC_DCHECK(network_thread_->IsCurrent());
+ UpdateWritableState_n();
}
void BaseChannel::OnChannelRead(TransportChannel* channel,
@@ -477,7 +525,7 @@
int flags) {
TRACE_EVENT0("webrtc", "BaseChannel::OnChannelRead");
// OnChannelRead gets called from P2PSocket; now pass data to MediaEngine
- ASSERT(worker_thread_ == rtc::Thread::Current());
+ RTC_DCHECK(network_thread_->IsCurrent());
// When using RTCP multiplexing we might get RTCP packets on the RTP
// transport. We feed RTP traffic into the demuxer to determine if it is RTCP.
@@ -493,7 +541,7 @@
void BaseChannel::OnDtlsState(TransportChannel* channel,
DtlsTransportState state) {
- if (!ShouldSetupDtlsSrtp()) {
+ if (!ShouldSetupDtlsSrtp_n()) {
return;
}
@@ -512,6 +560,8 @@
CandidatePairInterface* selected_candidate_pair,
int last_sent_packet_id) {
ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_);
+ RTC_DCHECK(network_thread_->IsCurrent());
+ std::string transport_name = channel->transport_name();
rtc::NetworkRoute network_route;
if (selected_candidate_pair) {
network_route = rtc::NetworkRoute(
@@ -519,26 +569,27 @@
selected_candidate_pair->remote_candidate().network_id(),
last_sent_packet_id);
}
- media_channel()->OnNetworkRouteChanged(channel->transport_name(),
- network_route);
+ invoker_.AsyncInvoke<void>(
+ worker_thread_, Bind(&MediaChannel::OnNetworkRouteChanged, media_channel_,
+ transport_name, network_route));
}
void BaseChannel::SetReadyToSend(bool rtcp, bool ready) {
+ RTC_DCHECK(network_thread_->IsCurrent());
if (rtcp) {
rtcp_ready_to_send_ = ready;
} else {
rtp_ready_to_send_ = ready;
}
- if (rtp_ready_to_send_ &&
- // In the case of rtcp mux |rtcp_transport_channel_| will be null.
- (rtcp_ready_to_send_ || !rtcp_transport_channel_)) {
- // Notify the MediaChannel when both rtp and rtcp channel can send.
- media_channel_->OnReadyToSend(true);
- } else {
- // Notify the MediaChannel when either rtp or rtcp channel can't send.
- media_channel_->OnReadyToSend(false);
- }
+ bool ready_to_send =
+ (rtp_ready_to_send_ &&
+ // In the case of rtcp mux |rtcp_transport_channel_| will be null.
+ (rtcp_ready_to_send_ || !rtcp_transport_channel_));
+
+ invoker_.AsyncInvoke<void>(
+ worker_thread_,
+ Bind(&MediaChannel::OnReadyToSend, media_channel_, ready_to_send));
}
bool BaseChannel::PacketIsRtcp(const TransportChannel* channel,
@@ -550,22 +601,23 @@
bool BaseChannel::SendPacket(bool rtcp,
rtc::CopyOnWriteBuffer* packet,
const rtc::PacketOptions& options) {
- // SendPacket gets called from MediaEngine, typically on an encoder thread.
- // If the thread is not our worker thread, we will post to our worker
- // so that the real work happens on our worker. This avoids us having to
+ // SendPacket gets called from MediaEngine, on a pacer or an encoder thread.
+ // If the thread is not our network thread, we will post to our network
+ // so that the real work happens on our network. This avoids us having to
// synchronize access to all the pieces of the send path, including
// SRTP and the inner workings of the transport channels.
// The only downside is that we can't return a proper failure code if
// needed. Since UDP is unreliable anyway, this should be a non-issue.
- if (rtc::Thread::Current() != worker_thread_) {
+ if (!network_thread_->IsCurrent()) {
// Avoid a copy by transferring the ownership of the packet data.
- int message_id = (!rtcp) ? MSG_RTPPACKET : MSG_RTCPPACKET;
- PacketMessageData* data = new PacketMessageData;
+ int message_id = rtcp ? MSG_SEND_RTCP_PACKET : MSG_SEND_RTP_PACKET;
+ SendPacketMessageData* data = new SendPacketMessageData;
data->packet = std::move(*packet);
data->options = options;
- worker_thread_->Post(this, message_id, data);
+ network_thread_->Post(this, message_id, data);
return true;
}
+ TRACE_EVENT0("webrtc", "BaseChannel::SendPacket");
// Now that we are on the correct thread, ensure we have a place to send this
// packet before doing anything. (We might get RTCP packets that we don't
@@ -589,6 +641,7 @@
updated_options = options;
// Protect if needed.
if (srtp_filter_.IsActive()) {
+ TRACE_EVENT0("webrtc", "SRTP Encode");
bool res;
uint8_t* data = packet->data();
int len = static_cast<int>(packet->size());
@@ -656,9 +709,9 @@
}
// Bon voyage.
- int ret =
- channel->SendPacket(packet->data<char>(), packet->size(), updated_options,
- (secure() && secure_dtls()) ? PF_SRTP_BYPASS : 0);
+ int flags = (secure() && secure_dtls()) ? PF_SRTP_BYPASS : PF_NORMAL;
+ int ret = channel->SendPacket(packet->data<char>(), packet->size(),
+ updated_options, flags);
if (ret != static_cast<int>(packet->size())) {
if (channel->GetError() == EWOULDBLOCK) {
LOG(LS_WARNING) << "Got EWOULDBLOCK from socket.";
@@ -687,6 +740,7 @@
void BaseChannel::HandlePacket(bool rtcp, rtc::CopyOnWriteBuffer* packet,
const rtc::PacketTime& packet_time) {
+ RTC_DCHECK(network_thread_->IsCurrent());
if (!WantsPacket(rtcp, packet)) {
return;
}
@@ -700,6 +754,7 @@
// Unprotect the packet, if needed.
if (srtp_filter_.IsActive()) {
+ TRACE_EVENT0("webrtc", "SRTP Decode");
char* data = packet->data<char>();
int len = static_cast<int>(packet->size());
bool res;
@@ -743,11 +798,22 @@
return;
}
- // Push it down to the media channel.
- if (!rtcp) {
- media_channel_->OnPacketReceived(packet, packet_time);
+ invoker_.AsyncInvoke<void>(
+ worker_thread_,
+ Bind(&BaseChannel::OnPacketReceived, this, rtcp, *packet, packet_time));
+}
+
+void BaseChannel::OnPacketReceived(bool rtcp,
+ const rtc::CopyOnWriteBuffer& packet,
+ const rtc::PacketTime& packet_time) {
+ RTC_DCHECK(worker_thread_->IsCurrent());
+ // Need to copy variable because OnRtcpReceived/OnPacketReceived
+ // requires non-const pointer to buffer. This doesn't memcpy the actual data.
+ rtc::CopyOnWriteBuffer data(packet);
+ if (rtcp) {
+ media_channel_->OnRtcpReceived(&data, packet_time);
} else {
- media_channel_->OnRtcpReceived(packet, packet_time);
+ media_channel_->OnPacketReceived(&data, packet_time);
}
}
@@ -786,7 +852,7 @@
LOG(LS_INFO) << "Channel enabled";
enabled_ = true;
- ChangeState();
+ ChangeState_w();
}
void BaseChannel::DisableMedia_w() {
@@ -796,20 +862,20 @@
LOG(LS_INFO) << "Channel disabled";
enabled_ = false;
- ChangeState();
+ ChangeState_w();
}
-void BaseChannel::UpdateWritableState_w() {
+void BaseChannel::UpdateWritableState_n() {
if (transport_channel_ && transport_channel_->writable() &&
(!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) {
- ChannelWritable_w();
+ ChannelWritable_n();
} else {
- ChannelNotWritable_w();
+ ChannelNotWritable_n();
}
}
-void BaseChannel::ChannelWritable_w() {
- ASSERT(worker_thread_ == rtc::Thread::Current());
+void BaseChannel::ChannelWritable_n() {
+ RTC_DCHECK(network_thread_->IsCurrent());
if (writable_) {
return;
}
@@ -829,15 +895,16 @@
}
was_ever_writable_ = true;
- MaybeSetupDtlsSrtp_w();
+ MaybeSetupDtlsSrtp_n();
writable_ = true;
ChangeState();
}
-void BaseChannel::SignalDtlsSetupFailure_w(bool rtcp) {
- ASSERT(worker_thread() == rtc::Thread::Current());
- signaling_thread()->Invoke<void>(Bind(
- &BaseChannel::SignalDtlsSetupFailure_s, this, rtcp));
+void BaseChannel::SignalDtlsSetupFailure_n(bool rtcp) {
+ RTC_DCHECK(network_thread_->IsCurrent());
+ invoker_.AsyncInvoke<void>(
+ signaling_thread(),
+ Bind(&BaseChannel::SignalDtlsSetupFailure_s, this, rtcp));
}
void BaseChannel::SignalDtlsSetupFailure_s(bool rtcp) {
@@ -845,26 +912,27 @@
SignalDtlsSetupFailure(this, rtcp);
}
-bool BaseChannel::SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp) {
+bool BaseChannel::SetDtlsSrtpCryptoSuites_n(TransportChannel* tc, bool rtcp) {
std::vector<int> crypto_suites;
// We always use the default SRTP crypto suites for RTCP, but we may use
// different crypto suites for RTP depending on the media type.
if (!rtcp) {
- GetSrtpCryptoSuites(&crypto_suites);
+ GetSrtpCryptoSuites_n(&crypto_suites);
} else {
GetDefaultSrtpCryptoSuites(&crypto_suites);
}
return tc->SetSrtpCryptoSuites(crypto_suites);
}
-bool BaseChannel::ShouldSetupDtlsSrtp() const {
+bool BaseChannel::ShouldSetupDtlsSrtp_n() const {
// Since DTLS is applied to all channels, checking RTP should be enough.
return transport_channel_ && transport_channel_->IsDtlsActive();
}
// This function returns true if either DTLS-SRTP is not in use
// *or* DTLS-SRTP is successfully set up.
-bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) {
+bool BaseChannel::SetupDtlsSrtp_n(bool rtcp_channel) {
+ RTC_DCHECK(network_thread_->IsCurrent());
bool ret = false;
TransportChannel* channel =
@@ -950,30 +1018,30 @@
return ret;
}
-void BaseChannel::MaybeSetupDtlsSrtp_w() {
+void BaseChannel::MaybeSetupDtlsSrtp_n() {
if (srtp_filter_.IsActive()) {
return;
}
- if (!ShouldSetupDtlsSrtp()) {
+ if (!ShouldSetupDtlsSrtp_n()) {
return;
}
- if (!SetupDtlsSrtp(false)) {
- SignalDtlsSetupFailure_w(false);
+ if (!SetupDtlsSrtp_n(false)) {
+ SignalDtlsSetupFailure_n(false);
return;
}
if (rtcp_transport_channel_) {
- if (!SetupDtlsSrtp(true)) {
- SignalDtlsSetupFailure_w(true);
+ if (!SetupDtlsSrtp_n(true)) {
+ SignalDtlsSetupFailure_n(true);
return;
}
}
}
-void BaseChannel::ChannelNotWritable_w() {
- ASSERT(worker_thread_ == rtc::Thread::Current());
+void BaseChannel::ChannelNotWritable_n() {
+ RTC_DCHECK(network_thread_->IsCurrent());
if (!writable_)
return;
@@ -982,7 +1050,7 @@
ChangeState();
}
-bool BaseChannel::SetRtpTransportParameters_w(
+bool BaseChannel::SetRtpTransportParameters(
const MediaContentDescription* content,
ContentAction action,
ContentSource src,
@@ -993,15 +1061,27 @@
}
// Cache secure_required_ for belt and suspenders check on SendPacket
+ return network_thread_->Invoke<bool>(
+ Bind(&BaseChannel::SetRtpTransportParameters_n, this, content, action,
+ src, error_desc));
+}
+
+bool BaseChannel::SetRtpTransportParameters_n(
+ const MediaContentDescription* content,
+ ContentAction action,
+ ContentSource src,
+ std::string* error_desc) {
+ RTC_DCHECK(network_thread_->IsCurrent());
+
if (src == CS_LOCAL) {
set_secure_required(content->crypto_required() != CT_NONE);
}
- if (!SetSrtp_w(content->cryptos(), action, src, error_desc)) {
+ if (!SetSrtp_n(content->cryptos(), action, src, error_desc)) {
return false;
}
- if (!SetRtcpMux_w(content->rtcp_mux(), action, src, error_desc)) {
+ if (!SetRtcpMux_n(content->rtcp_mux(), action, src, error_desc)) {
return false;
}
@@ -1010,19 +1090,18 @@
// |dtls| will be set to true if DTLS is active for transport channel and
// crypto is empty.
-bool BaseChannel::CheckSrtpConfig(const std::vector<CryptoParams>& cryptos,
- bool* dtls,
- std::string* error_desc) {
+bool BaseChannel::CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos,
+ bool* dtls,
+ std::string* error_desc) {
*dtls = transport_channel_->IsDtlsActive();
if (*dtls && !cryptos.empty()) {
- SafeSetError("Cryptos must be empty when DTLS is active.",
- error_desc);
+ SafeSetError("Cryptos must be empty when DTLS is active.", error_desc);
return false;
}
return true;
}
-bool BaseChannel::SetSrtp_w(const std::vector<CryptoParams>& cryptos,
+bool BaseChannel::SetSrtp_n(const std::vector<CryptoParams>& cryptos,
ContentAction action,
ContentSource src,
std::string* error_desc) {
@@ -1033,7 +1112,7 @@
}
bool ret = false;
bool dtls = false;
- ret = CheckSrtpConfig(cryptos, &dtls, error_desc);
+ ret = CheckSrtpConfig_n(cryptos, &dtls, error_desc);
if (!ret) {
return false;
}
@@ -1070,19 +1149,19 @@
}
void BaseChannel::ActivateRtcpMux() {
- worker_thread_->Invoke<void>(Bind(
- &BaseChannel::ActivateRtcpMux_w, this));
+ network_thread_->Invoke<void>(Bind(&BaseChannel::ActivateRtcpMux_n, this));
}
-void BaseChannel::ActivateRtcpMux_w() {
+void BaseChannel::ActivateRtcpMux_n() {
if (!rtcp_mux_filter_.IsActive()) {
rtcp_mux_filter_.SetActive();
- set_rtcp_transport_channel(nullptr, true);
+ SetRtcpTransportChannel_n(nullptr, true);
rtcp_transport_enabled_ = false;
}
}
-bool BaseChannel::SetRtcpMux_w(bool enable, ContentAction action,
+bool BaseChannel::SetRtcpMux_n(bool enable,
+ ContentAction action,
ContentSource src,
std::string* error_desc) {
bool ret = false;
@@ -1100,7 +1179,7 @@
LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name()
<< " by destroying RTCP transport channel for "
<< transport_name();
- set_rtcp_transport_channel(nullptr, true);
+ SetRtcpTransportChannel_n(nullptr, true);
rtcp_transport_enabled_ = false;
}
break;
@@ -1121,7 +1200,7 @@
if (rtcp_mux_filter_.IsActive()) {
// If the RTP transport is already writable, then so are we.
if (transport_channel_->writable()) {
- ChannelWritable_w();
+ ChannelWritable_n();
}
}
@@ -1285,23 +1364,38 @@
return ret;
}
-void BaseChannel::MaybeCacheRtpAbsSendTimeHeaderExtension(
+void BaseChannel::MaybeCacheRtpAbsSendTimeHeaderExtension_w(
const std::vector<RtpHeaderExtension>& extensions) {
+// Absolute Send Time extension id is used only with external auth,
+// so do not bother searching for it and making asyncronious call to set
+// something that is not used.
+#if defined(ENABLE_EXTERNAL_AUTH)
const RtpHeaderExtension* send_time_extension =
FindHeaderExtension(extensions, kRtpAbsoluteSenderTimeHeaderExtension);
- rtp_abs_sendtime_extn_id_ =
+ int rtp_abs_sendtime_extn_id =
send_time_extension ? send_time_extension->id : -1;
+ invoker_.AsyncInvoke<void>(
+ network_thread_, Bind(&BaseChannel::CacheRtpAbsSendTimeHeaderExtension_n,
+ this, rtp_abs_sendtime_extn_id));
+#endif
+}
+
+void BaseChannel::CacheRtpAbsSendTimeHeaderExtension_n(
+ int rtp_abs_sendtime_extn_id) {
+ rtp_abs_sendtime_extn_id_ = rtp_abs_sendtime_extn_id;
}
void BaseChannel::OnMessage(rtc::Message *pmsg) {
TRACE_EVENT0("webrtc", "BaseChannel::OnMessage");
switch (pmsg->message_id) {
- case MSG_RTPPACKET:
- case MSG_RTCPPACKET: {
- PacketMessageData* data = static_cast<PacketMessageData*>(pmsg->pdata);
- SendPacket(pmsg->message_id == MSG_RTCPPACKET, &data->packet,
- data->options);
- delete data; // because it is Posted
+ case MSG_SEND_RTP_PACKET:
+ case MSG_SEND_RTCP_PACKET: {
+ RTC_DCHECK(network_thread_->IsCurrent());
+ SendPacketMessageData* data =
+ static_cast<SendPacketMessageData*>(pmsg->pdata);
+ bool rtcp = pmsg->message_id == MSG_SEND_RTCP_PACKET;
+ SendPacket(rtcp, &data->packet, data->options);
+ delete data;
break;
}
case MSG_FIRSTPACKETRECEIVED: {
@@ -1311,25 +1405,39 @@
}
}
-void BaseChannel::FlushRtcpMessages() {
+void BaseChannel::FlushRtcpMessages_n() {
// Flush all remaining RTCP messages. This should only be called in
// destructor.
- ASSERT(rtc::Thread::Current() == worker_thread_);
+ RTC_DCHECK(network_thread_->IsCurrent());
rtc::MessageList rtcp_messages;
- worker_thread_->Clear(this, MSG_RTCPPACKET, &rtcp_messages);
- for (rtc::MessageList::iterator it = rtcp_messages.begin();
- it != rtcp_messages.end(); ++it) {
- worker_thread_->Send(this, MSG_RTCPPACKET, it->pdata);
+ network_thread_->Clear(this, MSG_SEND_RTCP_PACKET, &rtcp_messages);
+ for (const auto& message : rtcp_messages) {
+ network_thread_->Send(this, MSG_SEND_RTCP_PACKET, message.pdata);
}
}
-VoiceChannel::VoiceChannel(rtc::Thread* thread,
+void BaseChannel::SignalSentPacket_n(TransportChannel* /* channel */,
+ const rtc::SentPacket& sent_packet) {
+ RTC_DCHECK(network_thread_->IsCurrent());
+ invoker_.AsyncInvoke<void>(
+ worker_thread_,
+ rtc::Bind(&BaseChannel::SignalSentPacket_w, this, sent_packet));
+}
+
+void BaseChannel::SignalSentPacket_w(const rtc::SentPacket& sent_packet) {
+ RTC_DCHECK(worker_thread_->IsCurrent());
+ SignalSentPacket(sent_packet);
+}
+
+VoiceChannel::VoiceChannel(rtc::Thread* worker_thread,
+ rtc::Thread* network_thread,
MediaEngineInterface* media_engine,
VoiceMediaChannel* media_channel,
TransportController* transport_controller,
const std::string& content_name,
bool rtcp)
- : BaseChannel(thread,
+ : BaseChannel(worker_thread,
+ network_thread,
media_channel,
transport_controller,
content_name,
@@ -1346,8 +1454,8 @@
Deinit();
}
-bool VoiceChannel::Init() {
- if (!BaseChannel::Init()) {
+bool VoiceChannel::Init_w() {
+ if (!BaseChannel::Init_w()) {
return false;
}
return true;
@@ -1487,15 +1595,21 @@
}
}
-void VoiceChannel::ChangeState() {
+void BaseChannel::ChangeState() {
+ RTC_DCHECK(network_thread_->IsCurrent());
+ invoker_.AsyncInvoke<void>(worker_thread_,
+ Bind(&BaseChannel::ChangeState_w, this));
+}
+
+void VoiceChannel::ChangeState_w() {
// Render incoming data if we're the active call, and we have the local
// content. We receive data on the default channel and multiplexed streams.
- bool recv = IsReadyToReceive();
+ bool recv = IsReadyToReceive_w();
media_channel()->SetPlayout(recv);
// Send outgoing data if we're the active call, we have the remote content,
// and we have had some form of connectivity.
- bool send = IsReadyToSend();
+ bool send = IsReadyToSend_w();
media_channel()->SetSend(send);
LOG(LS_INFO) << "Changing voice state, recv=" << recv << " send=" << send;
@@ -1521,7 +1635,7 @@
return false;
}
- if (!SetRtpTransportParameters_w(content, action, CS_LOCAL, error_desc)) {
+ if (!SetRtpTransportParameters(content, action, CS_LOCAL, error_desc)) {
return false;
}
@@ -1547,7 +1661,7 @@
}
set_local_content_direction(content->direction());
- ChangeState();
+ ChangeState_w();
return true;
}
@@ -1566,7 +1680,7 @@
return false;
}
- if (!SetRtpTransportParameters_w(content, action, CS_REMOTE, error_desc)) {
+ if (!SetRtpTransportParameters(content, action, CS_REMOTE, error_desc)) {
return false;
}
@@ -1594,11 +1708,11 @@
}
if (audio->rtp_header_extensions_set()) {
- MaybeCacheRtpAbsSendTimeHeaderExtension(audio->rtp_header_extensions());
+ MaybeCacheRtpAbsSendTimeHeaderExtension_w(audio->rtp_header_extensions());
}
set_remote_content_direction(content->direction());
- ChangeState();
+ ChangeState_w();
return true;
}
@@ -1652,23 +1766,26 @@
SignalAudioMonitor(this, info);
}
-void VoiceChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const {
+void VoiceChannel::GetSrtpCryptoSuites_n(
+ std::vector<int>* crypto_suites) const {
GetSupportedAudioCryptoSuites(crypto_suites);
}
-VideoChannel::VideoChannel(rtc::Thread* thread,
+VideoChannel::VideoChannel(rtc::Thread* worker_thread,
+ rtc::Thread* network_thread,
VideoMediaChannel* media_channel,
TransportController* transport_controller,
const std::string& content_name,
bool rtcp)
- : BaseChannel(thread,
+ : BaseChannel(worker_thread,
+ network_thread,
media_channel,
transport_controller,
content_name,
rtcp) {}
-bool VideoChannel::Init() {
- if (!BaseChannel::Init()) {
+bool VideoChannel::Init_w() {
+ if (!BaseChannel::Init_w()) {
return false;
}
return true;
@@ -1723,10 +1840,11 @@
webrtc::RtpParameters parameters) {
return media_channel()->SetRtpParameters(ssrc, parameters);
}
-void VideoChannel::ChangeState() {
+
+void VideoChannel::ChangeState_w() {
// Send outgoing data if we're the active call, we have the remote content,
// and we have had some form of connectivity.
- bool send = IsReadyToSend();
+ bool send = IsReadyToSend_w();
if (!media_channel()->SetSend(send)) {
LOG(LS_ERROR) << "Failed to SetSend on video channel";
// TODO(gangji): Report error back to server.
@@ -1775,7 +1893,7 @@
return false;
}
- if (!SetRtpTransportParameters_w(content, action, CS_LOCAL, error_desc)) {
+ if (!SetRtpTransportParameters(content, action, CS_LOCAL, error_desc)) {
return false;
}
@@ -1801,7 +1919,7 @@
}
set_local_content_direction(content->direction());
- ChangeState();
+ ChangeState_w();
return true;
}
@@ -1820,8 +1938,7 @@
return false;
}
-
- if (!SetRtpTransportParameters_w(content, action, CS_REMOTE, error_desc)) {
+ if (!SetRtpTransportParameters(content, action, CS_REMOTE, error_desc)) {
return false;
}
@@ -1850,11 +1967,11 @@
}
if (video->rtp_header_extensions_set()) {
- MaybeCacheRtpAbsSendTimeHeaderExtension(video->rtp_header_extensions());
+ MaybeCacheRtpAbsSendTimeHeaderExtension_w(video->rtp_header_extensions());
}
set_remote_content_direction(content->direction());
- ChangeState();
+ ChangeState_w();
return true;
}
@@ -1885,16 +2002,19 @@
SignalMediaMonitor(this, info);
}
-void VideoChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const {
+void VideoChannel::GetSrtpCryptoSuites_n(
+ std::vector<int>* crypto_suites) const {
GetSupportedVideoCryptoSuites(crypto_suites);
}
-DataChannel::DataChannel(rtc::Thread* thread,
+DataChannel::DataChannel(rtc::Thread* worker_thread,
+ rtc::Thread* network_thread,
DataMediaChannel* media_channel,
TransportController* transport_controller,
const std::string& content_name,
bool rtcp)
- : BaseChannel(thread,
+ : BaseChannel(worker_thread,
+ network_thread,
media_channel,
transport_controller,
content_name,
@@ -1911,8 +2031,8 @@
Deinit();
}
-bool DataChannel::Init() {
- if (!BaseChannel::Init()) {
+bool DataChannel::Init_w() {
+ if (!BaseChannel::Init_w()) {
return false;
}
media_channel()->SignalDataReceived.connect(
@@ -1998,7 +2118,7 @@
}
if (data_channel_type_ == DCT_RTP) {
- if (!SetRtpTransportParameters_w(content, action, CS_LOCAL, error_desc)) {
+ if (!SetRtpTransportParameters(content, action, CS_LOCAL, error_desc)) {
return false;
}
}
@@ -2030,7 +2150,7 @@
}
set_local_content_direction(content->direction());
- ChangeState();
+ ChangeState_w();
return true;
}
@@ -2060,7 +2180,7 @@
LOG(LS_INFO) << "Setting remote data description";
if (data_channel_type_ == DCT_RTP &&
- !SetRtpTransportParameters_w(content, action, CS_REMOTE, error_desc)) {
+ !SetRtpTransportParameters(content, action, CS_REMOTE, error_desc)) {
return false;
}
@@ -2085,21 +2205,21 @@
}
set_remote_content_direction(content->direction());
- ChangeState();
+ ChangeState_w();
return true;
}
-void DataChannel::ChangeState() {
+void DataChannel::ChangeState_w() {
// Render incoming data if we're the active call, and we have the local
// content. We receive data on the default channel and multiplexed streams.
- bool recv = IsReadyToReceive();
+ bool recv = IsReadyToReceive_w();
if (!media_channel()->SetReceive(recv)) {
LOG(LS_ERROR) << "Failed to SetReceive on data channel";
}
// Send outgoing data if we're the active call, we have the remote content,
// and we have had some form of connectivity.
- bool send = IsReadyToSend();
+ bool send = IsReadyToSend_w();
if (!media_channel()->SetSend(send)) {
LOG(LS_ERROR) << "Failed to SetSend on data channel";
}
@@ -2195,12 +2315,12 @@
new DataChannelReadyToSendMessageData(writable));
}
-void DataChannel::GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const {
+void DataChannel::GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const {
GetSupportedDataCryptoSuites(crypto_suites);
}
-bool DataChannel::ShouldSetupDtlsSrtp() const {
- return (data_channel_type_ == DCT_RTP) && BaseChannel::ShouldSetupDtlsSrtp();
+bool DataChannel::ShouldSetupDtlsSrtp_n() const {
+ return data_channel_type_ == DCT_RTP && BaseChannel::ShouldSetupDtlsSrtp_n();
}
void DataChannel::OnStreamClosedRemotely(uint32_t sid) {
diff --git a/webrtc/pc/channel.h b/webrtc/pc/channel.h
index 4518301..df75245 100644
--- a/webrtc/pc/channel.h
+++ b/webrtc/pc/channel.h
@@ -19,6 +19,7 @@
#include <vector>
#include "webrtc/audio_sink.h"
+#include "webrtc/base/asyncinvoker.h"
#include "webrtc/base/asyncudpsocket.h"
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/network.h"
@@ -47,14 +48,17 @@
struct CryptoParams;
class MediaContentDescription;
-enum SinkType {
- SINK_PRE_CRYPTO, // Sink packets before encryption or after decryption.
- SINK_POST_CRYPTO // Sink packets after encryption or before decryption.
-};
-
// BaseChannel contains logic common to voice and video, including
-// enable, marshaling calls to a worker thread, and
+// enable, marshaling calls to a worker and network threads, and
// connection and media monitors.
+// BaseChannel assumes signaling and other threads are allowed to make
+// synchronous calls to the worker thread, the worker thread makes synchronous
+// calls only to the network thread, and the network thread can't be blocked by
+// other threads.
+// All methods with _n suffix must be called on network thread,
+// methods with _w suffix - on worker thread
+// and methods with _s suffix on signaling thread.
+// Network and worker threads may be the same thread.
//
// WARNING! SUBCLASSES MUST CALL Deinit() IN THEIR DESTRUCTORS!
// This is required to avoid a data race between the destructor modifying the
@@ -66,26 +70,22 @@
public MediaChannel::NetworkInterface,
public ConnectionStatsGetter {
public:
- BaseChannel(rtc::Thread* thread,
+ BaseChannel(rtc::Thread* worker_thread,
+ rtc::Thread* network_thread,
MediaChannel* channel,
TransportController* transport_controller,
const std::string& content_name,
bool rtcp);
virtual ~BaseChannel();
- bool Init();
- // Deinit may be called multiple times and is simply ignored if it's alreay
+ bool Init_w();
+ // Deinit may be called multiple times and is simply ignored if it's already
// done.
void Deinit();
rtc::Thread* worker_thread() const { return worker_thread_; }
+ rtc::Thread* network_thread() const { return network_thread_; }
const std::string& content_name() const { return content_name_; }
const std::string& transport_name() const { return transport_name_; }
- TransportChannel* transport_channel() const {
- return transport_channel_;
- }
- TransportChannel* rtcp_transport_channel() const {
- return rtcp_transport_channel_;
- }
bool enabled() const { return enabled_; }
// This function returns true if we are using SRTP.
@@ -143,18 +143,28 @@
}
sigslot::signal2<BaseChannel*, bool> SignalDtlsSetupFailure;
- void SignalDtlsSetupFailure_w(bool rtcp);
+ void SignalDtlsSetupFailure_n(bool rtcp);
void SignalDtlsSetupFailure_s(bool rtcp);
// Used for latency measurements.
sigslot::signal1<BaseChannel*> SignalFirstPacketReceived;
+ // Forward TransportChannel SignalSentPacket to worker thread.
+ sigslot::signal1<const rtc::SentPacket&> SignalSentPacket;
+
+ // Only public for unit tests. Otherwise, consider private.
+ TransportChannel* transport_channel() const { return transport_channel_; }
+ TransportChannel* rtcp_transport_channel() const {
+ return rtcp_transport_channel_;
+ }
+
// Made public for easier testing.
void SetReadyToSend(bool rtcp, bool ready);
// Only public for unit tests. Otherwise, consider protected.
int SetOption(SocketType type, rtc::Socket::Option o, int val)
override;
+ int SetOption_n(SocketType type, rtc::Socket::Option o, int val);
SrtpFilter* srtp_filter() { return &srtp_filter_; }
@@ -162,11 +172,11 @@
virtual MediaChannel* media_channel() const { return media_channel_; }
// Sets the |transport_channel_| (and |rtcp_transport_channel_|, if |rtcp_| is
// true). Gets the transport channels from |transport_controller_|.
- bool SetTransport_w(const std::string& transport_name);
+ bool SetTransport_n(const std::string& transport_name);
- void set_transport_channel(TransportChannel* transport);
- void set_rtcp_transport_channel(TransportChannel* transport,
- bool update_writablity);
+ void SetTransportChannel_n(TransportChannel* transport);
+ void SetRtcpTransportChannel_n(TransportChannel* transport,
+ bool update_writablity);
bool was_ever_writable() const { return was_ever_writable_; }
void set_local_content_direction(MediaContentDirection direction) {
@@ -178,8 +188,8 @@
void set_secure_required(bool secure_required) {
secure_required_ = secure_required;
}
- bool IsReadyToReceive() const;
- bool IsReadyToSend() const;
+ bool IsReadyToReceive_w() const;
+ bool IsReadyToSend_w() const;
rtc::Thread* signaling_thread() {
return transport_controller_->signaling_thread();
}
@@ -188,7 +198,7 @@
void ConnectToTransportChannel(TransportChannel* tc);
void DisconnectFromTransportChannel(TransportChannel* tc);
- void FlushRtcpMessages();
+ void FlushRtcpMessages_n();
// NetworkInterface implementation, called by MediaEngine
bool SendPacket(rtc::CopyOnWriteBuffer* packet,
@@ -217,28 +227,33 @@
bool SendPacket(bool rtcp,
rtc::CopyOnWriteBuffer* packet,
const rtc::PacketOptions& options);
+
virtual bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet);
void HandlePacket(bool rtcp, rtc::CopyOnWriteBuffer* packet,
const rtc::PacketTime& packet_time);
+ void OnPacketReceived(bool rtcp,
+ const rtc::CopyOnWriteBuffer& packet,
+ const rtc::PacketTime& packet_time);
void EnableMedia_w();
void DisableMedia_w();
- void UpdateWritableState_w();
- void ChannelWritable_w();
- void ChannelNotWritable_w();
+ void UpdateWritableState_n();
+ void ChannelWritable_n();
+ void ChannelNotWritable_n();
bool AddRecvStream_w(const StreamParams& sp);
bool RemoveRecvStream_w(uint32_t ssrc);
bool AddSendStream_w(const StreamParams& sp);
bool RemoveSendStream_w(uint32_t ssrc);
- virtual bool ShouldSetupDtlsSrtp() const;
+ virtual bool ShouldSetupDtlsSrtp_n() const;
// Do the DTLS key expansion and impose it on the SRTP/SRTCP filters.
// |rtcp_channel| indicates whether to set up the RTP or RTCP filter.
- bool SetupDtlsSrtp(bool rtcp_channel);
- void MaybeSetupDtlsSrtp_w();
+ bool SetupDtlsSrtp_n(bool rtcp_channel);
+ void MaybeSetupDtlsSrtp_n();
// Set the DTLS-SRTP cipher policy on this channel as appropriate.
- bool SetDtlsSrtpCryptoSuites(TransportChannel* tc, bool rtcp);
+ bool SetDtlsSrtpCryptoSuites_n(TransportChannel* tc, bool rtcp);
- virtual void ChangeState() = 0;
+ void ChangeState();
+ virtual void ChangeState_w() = 0;
// Gets the content info appropriate to the channel (audio or video).
virtual const ContentInfo* GetFirstContent(
@@ -255,25 +270,29 @@
virtual bool SetRemoteContent_w(const MediaContentDescription* content,
ContentAction action,
std::string* error_desc) = 0;
- bool SetRtpTransportParameters_w(const MediaContentDescription* content,
+ bool SetRtpTransportParameters(const MediaContentDescription* content,
+ ContentAction action,
+ ContentSource src,
+ std::string* error_desc);
+ bool SetRtpTransportParameters_n(const MediaContentDescription* content,
ContentAction action,
ContentSource src,
std::string* error_desc);
// Helper method to get RTP Absoulute SendTime extension header id if
// present in remote supported extensions list.
- void MaybeCacheRtpAbsSendTimeHeaderExtension(
+ void MaybeCacheRtpAbsSendTimeHeaderExtension_w(
const std::vector<RtpHeaderExtension>& extensions);
- bool CheckSrtpConfig(const std::vector<CryptoParams>& cryptos,
- bool* dtls,
- std::string* error_desc);
- bool SetSrtp_w(const std::vector<CryptoParams>& params,
+ bool CheckSrtpConfig_n(const std::vector<CryptoParams>& cryptos,
+ bool* dtls,
+ std::string* error_desc);
+ bool SetSrtp_n(const std::vector<CryptoParams>& params,
ContentAction action,
ContentSource src,
std::string* error_desc);
- void ActivateRtcpMux_w();
- bool SetRtcpMux_w(bool enable,
+ void ActivateRtcpMux_n();
+ bool SetRtcpMux_n(bool enable,
ContentAction action,
ContentSource src,
std::string* error_desc);
@@ -283,7 +302,7 @@
// Handled in derived classes
// Get the SRTP crypto suites to use for RTP media
- virtual void GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const = 0;
+ virtual void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const = 0;
virtual void OnConnectionMonitorUpdate(ConnectionMonitor* monitor,
const std::vector<ConnectionInfo>& infos) = 0;
@@ -294,13 +313,23 @@
}
private:
- rtc::Thread* worker_thread_;
- TransportController* transport_controller_;
- MediaChannel* media_channel_;
- std::vector<StreamParams> local_streams_;
- std::vector<StreamParams> remote_streams_;
+ bool InitNetwork_n();
+ void DeinitNetwork_n();
+ void SignalSentPacket_n(TransportChannel* channel,
+ const rtc::SentPacket& sent_packet);
+ void SignalSentPacket_w(const rtc::SentPacket& sent_packet);
+ bool IsTransportReadyToSend_n() const;
+ void CacheRtpAbsSendTimeHeaderExtension_n(int rtp_abs_sendtime_extn_id);
+
+ rtc::Thread* const worker_thread_;
+ rtc::Thread* const network_thread_;
+ rtc::AsyncInvoker invoker_;
const std::string content_name_;
+ std::unique_ptr<ConnectionMonitor> connection_monitor_;
+
+ // Transport related members that should be accessed from network thread.
+ TransportController* const transport_controller_;
std::string transport_name_;
bool rtcp_transport_enabled_;
TransportChannel* transport_channel_;
@@ -310,32 +339,40 @@
SrtpFilter srtp_filter_;
RtcpMuxFilter rtcp_mux_filter_;
BundleFilter bundle_filter_;
- std::unique_ptr<ConnectionMonitor> connection_monitor_;
- bool enabled_;
- bool writable_;
bool rtp_ready_to_send_;
bool rtcp_ready_to_send_;
+ bool writable_;
bool was_ever_writable_;
- MediaContentDirection local_content_direction_;
- MediaContentDirection remote_content_direction_;
bool has_received_packet_;
bool dtls_keyed_;
bool secure_required_;
int rtp_abs_sendtime_extn_id_;
+
+ // MediaChannel related members that should be access from worker thread.
+ MediaChannel* const media_channel_;
+ // Currently enabled_ flag accessed from signaling thread too, but it can
+ // be changed only when signaling thread does sunchronious call to worker
+ // thread, so it should be safe.
+ bool enabled_;
+ std::vector<StreamParams> local_streams_;
+ std::vector<StreamParams> remote_streams_;
+ MediaContentDirection local_content_direction_;
+ MediaContentDirection remote_content_direction_;
};
// VoiceChannel is a specialization that adds support for early media, DTMF,
// and input/output level monitoring.
class VoiceChannel : public BaseChannel {
public:
- VoiceChannel(rtc::Thread* thread,
+ VoiceChannel(rtc::Thread* worker_thread,
+ rtc::Thread* network_thread,
MediaEngineInterface* media_engine,
VoiceMediaChannel* channel,
TransportController* transport_controller,
const std::string& content_name,
bool rtcp);
~VoiceChannel();
- bool Init();
+ bool Init_w();
// Configure sending media on the stream with SSRC |ssrc|
// If there is only one sending stream SSRC 0 can be used.
@@ -345,7 +382,7 @@
AudioSource* source);
// downcasts a MediaChannel
- virtual VoiceMediaChannel* media_channel() const {
+ VoiceMediaChannel* media_channel() const override {
return static_cast<VoiceMediaChannel*>(BaseChannel::media_channel());
}
@@ -393,29 +430,31 @@
private:
// overrides from BaseChannel
- virtual void OnChannelRead(TransportChannel* channel,
- const char* data, size_t len,
- const rtc::PacketTime& packet_time,
- int flags);
- virtual void ChangeState();
- virtual const ContentInfo* GetFirstContent(const SessionDescription* sdesc);
- virtual bool SetLocalContent_w(const MediaContentDescription* content,
- ContentAction action,
- std::string* error_desc);
- virtual bool SetRemoteContent_w(const MediaContentDescription* content,
- ContentAction action,
- std::string* error_desc);
+ void OnChannelRead(TransportChannel* channel,
+ const char* data,
+ size_t len,
+ const rtc::PacketTime& packet_time,
+ int flags) override;
+ void ChangeState_w() override;
+ const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
+ bool SetLocalContent_w(const MediaContentDescription* content,
+ ContentAction action,
+ std::string* error_desc) override;
+ bool SetRemoteContent_w(const MediaContentDescription* content,
+ ContentAction action,
+ std::string* error_desc) override;
void HandleEarlyMediaTimeout();
bool InsertDtmf_w(uint32_t ssrc, int event, int duration);
bool SetOutputVolume_w(uint32_t ssrc, double volume);
bool GetStats_w(VoiceMediaInfo* stats);
- virtual void OnMessage(rtc::Message* pmsg);
- virtual void GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const;
- virtual void OnConnectionMonitorUpdate(
- ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos);
- virtual void OnMediaMonitorUpdate(
- VoiceMediaChannel* media_channel, const VoiceMediaInfo& info);
+ void OnMessage(rtc::Message* pmsg) override;
+ void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
+ void OnConnectionMonitorUpdate(
+ ConnectionMonitor* monitor,
+ const std::vector<ConnectionInfo>& infos) override;
+ void OnMediaMonitorUpdate(VoiceMediaChannel* media_channel,
+ const VoiceMediaInfo& info);
void OnAudioMonitorUpdate(AudioMonitor* monitor, const AudioInfo& info);
static const int kEarlyMediaTimeout = 1000;
@@ -435,16 +474,17 @@
// VideoChannel is a specialization for video.
class VideoChannel : public BaseChannel {
public:
- VideoChannel(rtc::Thread* thread,
+ VideoChannel(rtc::Thread* worker_thread,
+ rtc::Thread* netwokr_thread,
VideoMediaChannel* channel,
TransportController* transport_controller,
const std::string& content_name,
bool rtcp);
~VideoChannel();
- bool Init();
+ bool Init_w();
// downcasts a MediaChannel
- virtual VideoMediaChannel* media_channel() const {
+ VideoMediaChannel* media_channel() const override {
return static_cast<VideoMediaChannel*>(BaseChannel::media_channel());
}
@@ -469,24 +509,25 @@
private:
// overrides from BaseChannel
- virtual void ChangeState();
- virtual const ContentInfo* GetFirstContent(const SessionDescription* sdesc);
- virtual bool SetLocalContent_w(const MediaContentDescription* content,
- ContentAction action,
- std::string* error_desc);
- virtual bool SetRemoteContent_w(const MediaContentDescription* content,
- ContentAction action,
- std::string* error_desc);
+ void ChangeState_w() override;
+ const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
+ bool SetLocalContent_w(const MediaContentDescription* content,
+ ContentAction action,
+ std::string* error_desc) override;
+ bool SetRemoteContent_w(const MediaContentDescription* content,
+ ContentAction action,
+ std::string* error_desc) override;
bool GetStats_w(VideoMediaInfo* stats);
webrtc::RtpParameters GetRtpParameters_w(uint32_t ssrc) const;
bool SetRtpParameters_w(uint32_t ssrc, webrtc::RtpParameters parameters);
- virtual void OnMessage(rtc::Message* pmsg);
- virtual void GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const;
- virtual void OnConnectionMonitorUpdate(
- ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos);
- virtual void OnMediaMonitorUpdate(
- VideoMediaChannel* media_channel, const VideoMediaInfo& info);
+ void OnMessage(rtc::Message* pmsg) override;
+ void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
+ void OnConnectionMonitorUpdate(
+ ConnectionMonitor* monitor,
+ const std::vector<ConnectionInfo>& infos) override;
+ void OnMediaMonitorUpdate(VideoMediaChannel* media_channel,
+ const VideoMediaInfo& info);
std::unique_ptr<VideoMediaMonitor> media_monitor_;
@@ -501,13 +542,14 @@
// DataChannel is a specialization for data.
class DataChannel : public BaseChannel {
public:
- DataChannel(rtc::Thread* thread,
+ DataChannel(rtc::Thread* worker_thread,
+ rtc::Thread* network_thread,
DataMediaChannel* media_channel,
TransportController* transport_controller,
const std::string& content_name,
bool rtcp);
~DataChannel();
- bool Init();
+ bool Init_w();
virtual bool SendData(const SendDataParams& params,
const rtc::CopyOnWriteBuffer& payload,
@@ -535,7 +577,7 @@
protected:
// downcasts a MediaChannel.
- virtual DataMediaChannel* media_channel() const {
+ DataMediaChannel* media_channel() const override {
return static_cast<DataMediaChannel*>(BaseChannel::media_channel());
}
@@ -572,7 +614,7 @@
typedef rtc::TypedMessageData<bool> DataChannelReadyToSendMessageData;
// overrides from BaseChannel
- virtual const ContentInfo* GetFirstContent(const SessionDescription* sdesc);
+ const ContentInfo* GetFirstContent(const SessionDescription* sdesc) override;
// If data_channel_type_ is DCT_NONE, set it. Otherwise, check that
// it's the same as what was set previously. Returns false if it's
// set to one type one type and changed to another type later.
@@ -582,22 +624,23 @@
// DataContentDescription.
bool SetDataChannelTypeFromContent(const DataContentDescription* content,
std::string* error_desc);
- virtual bool SetLocalContent_w(const MediaContentDescription* content,
- ContentAction action,
- std::string* error_desc);
- virtual bool SetRemoteContent_w(const MediaContentDescription* content,
- ContentAction action,
- std::string* error_desc);
- virtual void ChangeState();
- virtual bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet);
+ bool SetLocalContent_w(const MediaContentDescription* content,
+ ContentAction action,
+ std::string* error_desc) override;
+ bool SetRemoteContent_w(const MediaContentDescription* content,
+ ContentAction action,
+ std::string* error_desc) override;
+ void ChangeState_w() override;
+ bool WantsPacket(bool rtcp, const rtc::CopyOnWriteBuffer* packet) override;
- virtual void OnMessage(rtc::Message* pmsg);
- virtual void GetSrtpCryptoSuites(std::vector<int>* crypto_suites) const;
- virtual void OnConnectionMonitorUpdate(
- ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos);
- virtual void OnMediaMonitorUpdate(
- DataMediaChannel* media_channel, const DataMediaInfo& info);
- virtual bool ShouldSetupDtlsSrtp() const;
+ void OnMessage(rtc::Message* pmsg) override;
+ void GetSrtpCryptoSuites_n(std::vector<int>* crypto_suites) const override;
+ void OnConnectionMonitorUpdate(
+ ConnectionMonitor* monitor,
+ const std::vector<ConnectionInfo>& infos) override;
+ void OnMediaMonitorUpdate(DataMediaChannel* media_channel,
+ const DataMediaInfo& info);
+ bool ShouldSetupDtlsSrtp_n() const override;
void OnDataReceived(
const ReceiveDataParams& params, const char* data, size_t len);
void OnDataChannelError(uint32_t ssrc, DataMediaChannel::Error error);
diff --git a/webrtc/pc/channel_unittest.cc b/webrtc/pc/channel_unittest.cc
index 6039065..8369c7a 100644
--- a/webrtc/pc/channel_unittest.cc
+++ b/webrtc/pc/channel_unittest.cc
@@ -10,24 +10,13 @@
#include <memory>
-#include "webrtc/base/arraysize.h"
-#include "webrtc/base/criticalsection.h"
-#include "webrtc/base/fileutils.h"
+#include "webrtc/base/array_view.h"
+#include "webrtc/base/buffer.h"
#include "webrtc/base/gunit.h"
-#include "webrtc/base/helpers.h"
#include "webrtc/base/logging.h"
-#include "webrtc/base/pathutils.h"
-#include "webrtc/base/signalthread.h"
-#include "webrtc/base/ssladapter.h"
-#include "webrtc/base/sslidentity.h"
-#include "webrtc/base/window.h"
#include "webrtc/media/base/fakemediaengine.h"
#include "webrtc/media/base/fakertp.h"
-#include "webrtc/media/base/fakescreencapturerfactory.h"
-#include "webrtc/media/base/fakevideocapturer.h"
#include "webrtc/media/base/mediachannel.h"
-#include "webrtc/media/base/rtpdump.h"
-#include "webrtc/media/base/screencastid.h"
#include "webrtc/media/base/testutils.h"
#include "webrtc/p2p/base/faketransportcontroller.h"
#include "webrtc/pc/channel.h"
@@ -46,19 +35,21 @@
using cricket::ScreencastId;
using cricket::StreamParams;
using cricket::TransportChannel;
-using rtc::WindowId;
-static const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1);
-static const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1);
-static const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1);
-static const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30);
-static const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15);
-static const cricket::DataCodec kGoogleDataCodec(101, "google-data");
-static const uint32_t kSsrc1 = 0x1111;
-static const uint32_t kSsrc2 = 0x2222;
-static const uint32_t kSsrc3 = 0x3333;
-static const int kAudioPts[] = {0, 8};
-static const int kVideoPts[] = {97, 99};
+namespace {
+const cricket::AudioCodec kPcmuCodec(0, "PCMU", 64000, 8000, 1);
+const cricket::AudioCodec kPcmaCodec(8, "PCMA", 64000, 8000, 1);
+const cricket::AudioCodec kIsacCodec(103, "ISAC", 40000, 16000, 1);
+const cricket::VideoCodec kH264Codec(97, "H264", 640, 400, 30);
+const cricket::VideoCodec kH264SvcCodec(99, "H264-SVC", 320, 200, 15);
+const cricket::DataCodec kGoogleDataCodec(101, "google-data");
+const uint32_t kSsrc1 = 0x1111;
+const uint32_t kSsrc2 = 0x2222;
+const uint32_t kSsrc3 = 0x3333;
+const int kAudioPts[] = {0, 8};
+const int kVideoPts[] = {97, 99};
+enum class NetworkIsWorker { Yes, No };
+} // namespace
template <class ChannelT,
class MediaChannelT,
@@ -76,10 +67,6 @@
typedef OptionsT Options;
};
-// Controls how long we wait for a session to send messages that we
-// expect, in milliseconds. We put it high to avoid flaky tests.
-static const int kEventTimeout = 5000;
-
class VoiceTraits : public Traits<cricket::VoiceChannel,
cricket::FakeVoiceMediaChannel,
cricket::AudioContentDescription,
@@ -101,12 +88,7 @@
cricket::DataMediaInfo,
cricket::DataOptions> {};
-rtc::StreamInterface* Open(const std::string& path) {
- return rtc::Filesystem::OpenFile(
- rtc::Pathname(path), "wb");
-}
-
-// Base class for Voice/VideoChannel tests
+// Base class for Voice/Video/DataChannel tests
template<class T>
class ChannelTest : public testing::Test, public sigslot::has_slots<> {
public:
@@ -114,40 +96,52 @@
DTLS = 0x10 };
ChannelTest(bool verify_playout,
- const uint8_t* rtp_data,
- int rtp_len,
- const uint8_t* rtcp_data,
- int rtcp_len)
+ rtc::ArrayView<const uint8_t> rtp_data,
+ rtc::ArrayView<const uint8_t> rtcp_data,
+ NetworkIsWorker network_is_worker)
: verify_playout_(verify_playout),
- transport_controller1_(cricket::ICEROLE_CONTROLLING),
- transport_controller2_(cricket::ICEROLE_CONTROLLED),
media_channel1_(NULL),
media_channel2_(NULL),
- rtp_packet_(reinterpret_cast<const char*>(rtp_data), rtp_len),
- rtcp_packet_(reinterpret_cast<const char*>(rtcp_data), rtcp_len),
+ rtp_packet_(rtp_data.data(), rtp_data.size()),
+ rtcp_packet_(rtcp_data.data(), rtcp_data.size()),
media_info_callbacks1_(),
- media_info_callbacks2_() {}
+ media_info_callbacks2_() {
+ if (network_is_worker == NetworkIsWorker::Yes) {
+ network_thread_ = rtc::Thread::Current();
+ } else {
+ network_thread_keeper_ = rtc::Thread::Create();
+ network_thread_keeper_->SetName("Network", nullptr);
+ network_thread_keeper_->Start();
+ network_thread_ = network_thread_keeper_.get();
+ }
+ transport_controller1_.reset(new cricket::FakeTransportController(
+ network_thread_, cricket::ICEROLE_CONTROLLING));
+ transport_controller2_.reset(new cricket::FakeTransportController(
+ network_thread_, cricket::ICEROLE_CONTROLLED));
+ }
void CreateChannels(int flags1, int flags2) {
CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
new typename T::MediaChannel(NULL, typename T::Options()),
- flags1, flags2, rtc::Thread::Current());
+ flags1, flags2);
}
- void CreateChannels(
- typename T::MediaChannel* ch1, typename T::MediaChannel* ch2,
- int flags1, int flags2, rtc::Thread* thread) {
+ void CreateChannels(typename T::MediaChannel* ch1,
+ typename T::MediaChannel* ch2,
+ int flags1,
+ int flags2) {
+ rtc::Thread* worker_thread = rtc::Thread::Current();
media_channel1_ = ch1;
media_channel2_ = ch2;
- channel1_.reset(CreateChannel(thread, &media_engine_, ch1,
- &transport_controller1_,
- (flags1 & RTCP) != 0));
- channel2_.reset(CreateChannel(thread, &media_engine_, ch2,
- &transport_controller2_,
- (flags2 & RTCP) != 0));
- channel1_->SignalMediaMonitor.connect(
- this, &ChannelTest<T>::OnMediaMonitor);
- channel2_->SignalMediaMonitor.connect(
- this, &ChannelTest<T>::OnMediaMonitor);
+ channel1_.reset(
+ CreateChannel(worker_thread, network_thread_, &media_engine_, ch1,
+ transport_controller1_.get(), (flags1 & RTCP) != 0));
+ channel2_.reset(
+ CreateChannel(worker_thread, network_thread_, &media_engine_, ch2,
+ transport_controller2_.get(), (flags2 & RTCP) != 0));
+ channel1_->SignalMediaMonitor.connect(this,
+ &ChannelTest<T>::OnMediaMonitor1);
+ channel2_->SignalMediaMonitor.connect(this,
+ &ChannelTest<T>::OnMediaMonitor2);
if ((flags1 & DTLS) && (flags2 & DTLS)) {
flags1 = (flags1 & ~SECURE);
flags2 = (flags2 & ~SECURE);
@@ -161,13 +155,13 @@
if (flags1 & DTLS) {
// Confirmed to work with KT_RSA and KT_ECDSA.
- transport_controller1_.SetLocalCertificate(
+ transport_controller1_->SetLocalCertificate(
rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT))));
}
if (flags2 & DTLS) {
// Confirmed to work with KT_RSA and KT_ECDSA.
- transport_controller2_.SetLocalCertificate(
+ transport_controller2_->SetLocalCertificate(
rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>(
rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT))));
}
@@ -187,14 +181,16 @@
}
}
typename T::Channel* CreateChannel(
- rtc::Thread* thread,
+ rtc::Thread* worker_thread,
+ rtc::Thread* network_thread,
cricket::MediaEngineInterface* engine,
typename T::MediaChannel* ch,
cricket::TransportController* transport_controller,
bool rtcp) {
- typename T::Channel* channel = new typename T::Channel(
- thread, engine, ch, transport_controller, cricket::CN_AUDIO, rtcp);
- if (!channel->Init()) {
+ typename T::Channel* channel =
+ new typename T::Channel(worker_thread, network_thread, engine, ch,
+ transport_controller, cricket::CN_AUDIO, rtcp);
+ if (!channel->Init_w()) {
delete channel;
channel = NULL;
}
@@ -209,7 +205,7 @@
result = channel2_->SetRemoteContent(&remote_media_content1_,
CA_OFFER, NULL);
if (result) {
- transport_controller1_.Connect(&transport_controller2_);
+ transport_controller1_->Connect(transport_controller2_.get());
result = channel2_->SetLocalContent(&local_media_content2_,
CA_ANSWER, NULL);
@@ -242,7 +238,7 @@
channel2_->Enable(true);
result = channel1_->SetRemoteContent(&remote_media_content2_,
CA_PRANSWER, NULL);
- transport_controller1_.Connect(&transport_controller2_);
+ transport_controller1_->Connect(transport_controller2_.get());
}
return result;
}
@@ -269,105 +265,92 @@
return channel1_->RemoveRecvStream(id);
}
- // Calling "_w" method here is ok since we only use one thread for this test
cricket::FakeTransport* GetTransport1() {
- return transport_controller1_.GetTransport_w(channel1_->content_name());
+ std::string name = channel1_->content_name();
+ return network_thread_->Invoke<cricket::FakeTransport*>(
+ [this, name] { return transport_controller1_->GetTransport_w(name); });
}
cricket::FakeTransport* GetTransport2() {
- return transport_controller2_.GetTransport_w(channel2_->content_name());
+ std::string name = channel2_->content_name();
+ return network_thread_->Invoke<cricket::FakeTransport*>(
+ [this, name] { return transport_controller2_->GetTransport_w(name); });
}
- bool SendRtp1() {
- return media_channel1_->SendRtp(rtp_packet_.c_str(),
- static_cast<int>(rtp_packet_.size()),
- rtc::PacketOptions());
+ void SendRtp1() {
+ media_channel1_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
+ rtc::PacketOptions());
}
- bool SendRtp2() {
- return media_channel2_->SendRtp(rtp_packet_.c_str(),
- static_cast<int>(rtp_packet_.size()),
- rtc::PacketOptions());
+ void SendRtp2() {
+ media_channel2_->SendRtp(rtp_packet_.data(), rtp_packet_.size(),
+ rtc::PacketOptions());
}
- bool SendRtcp1() {
- return media_channel1_->SendRtcp(rtcp_packet_.c_str(),
- static_cast<int>(rtcp_packet_.size()));
+ void SendRtcp1() {
+ media_channel1_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
}
- bool SendRtcp2() {
- return media_channel2_->SendRtcp(rtcp_packet_.c_str(),
- static_cast<int>(rtcp_packet_.size()));
+ void SendRtcp2() {
+ media_channel2_->SendRtcp(rtcp_packet_.data(), rtcp_packet_.size());
}
// Methods to send custom data.
- bool SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
- std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
- return media_channel1_->SendRtp(data.c_str(), static_cast<int>(data.size()),
- rtc::PacketOptions());
+ void SendCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
+ rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
+ media_channel1_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
}
- bool SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
- std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
- return media_channel2_->SendRtp(data.c_str(), static_cast<int>(data.size()),
- rtc::PacketOptions());
+ void SendCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
+ rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
+ media_channel2_->SendRtp(data.data(), data.size(), rtc::PacketOptions());
}
- bool SendCustomRtcp1(uint32_t ssrc) {
- std::string data(CreateRtcpData(ssrc));
- return media_channel1_->SendRtcp(data.c_str(),
- static_cast<int>(data.size()));
+ void SendCustomRtcp1(uint32_t ssrc) {
+ rtc::Buffer data = CreateRtcpData(ssrc);
+ media_channel1_->SendRtcp(data.data(), data.size());
}
- bool SendCustomRtcp2(uint32_t ssrc) {
- std::string data(CreateRtcpData(ssrc));
- return media_channel2_->SendRtcp(data.c_str(),
- static_cast<int>(data.size()));
+ void SendCustomRtcp2(uint32_t ssrc) {
+ rtc::Buffer data = CreateRtcpData(ssrc);
+ media_channel2_->SendRtcp(data.data(), data.size());
}
+
bool CheckRtp1() {
- return media_channel1_->CheckRtp(rtp_packet_.c_str(),
- static_cast<int>(rtp_packet_.size()));
+ return media_channel1_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
}
bool CheckRtp2() {
- return media_channel2_->CheckRtp(rtp_packet_.c_str(),
- static_cast<int>(rtp_packet_.size()));
+ return media_channel2_->CheckRtp(rtp_packet_.data(), rtp_packet_.size());
}
bool CheckRtcp1() {
- return media_channel1_->CheckRtcp(rtcp_packet_.c_str(),
- static_cast<int>(rtcp_packet_.size()));
+ return media_channel1_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
}
bool CheckRtcp2() {
- return media_channel2_->CheckRtcp(rtcp_packet_.c_str(),
- static_cast<int>(rtcp_packet_.size()));
+ return media_channel2_->CheckRtcp(rtcp_packet_.data(), rtcp_packet_.size());
}
// Methods to check custom data.
bool CheckCustomRtp1(uint32_t ssrc, int sequence_number, int pl_type = -1) {
- std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
- return media_channel1_->CheckRtp(data.c_str(),
- static_cast<int>(data.size()));
+ rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
+ return media_channel1_->CheckRtp(data.data(), data.size());
}
bool CheckCustomRtp2(uint32_t ssrc, int sequence_number, int pl_type = -1) {
- std::string data(CreateRtpData(ssrc, sequence_number, pl_type));
- return media_channel2_->CheckRtp(data.c_str(),
- static_cast<int>(data.size()));
+ rtc::Buffer data = CreateRtpData(ssrc, sequence_number, pl_type);
+ return media_channel2_->CheckRtp(data.data(), data.size());
}
bool CheckCustomRtcp1(uint32_t ssrc) {
- std::string data(CreateRtcpData(ssrc));
- return media_channel1_->CheckRtcp(data.c_str(),
- static_cast<int>(data.size()));
+ rtc::Buffer data = CreateRtcpData(ssrc);
+ return media_channel1_->CheckRtcp(data.data(), data.size());
}
bool CheckCustomRtcp2(uint32_t ssrc) {
- std::string data(CreateRtcpData(ssrc));
- return media_channel2_->CheckRtcp(data.c_str(),
- static_cast<int>(data.size()));
+ rtc::Buffer data = CreateRtcpData(ssrc);
+ return media_channel2_->CheckRtcp(data.data(), data.size());
}
- std::string CreateRtpData(uint32_t ssrc, int sequence_number, int pl_type) {
- std::string data(rtp_packet_);
+ rtc::Buffer CreateRtpData(uint32_t ssrc, int sequence_number, int pl_type) {
+ rtc::Buffer data(rtp_packet_.data(), rtp_packet_.size());
// Set SSRC in the rtp packet copy.
- rtc::SetBE32(const_cast<char*>(data.c_str()) + 8, ssrc);
- rtc::SetBE16(const_cast<char*>(data.c_str()) + 2, sequence_number);
+ rtc::SetBE32(data.data() + 8, ssrc);
+ rtc::SetBE16(data.data() + 2, sequence_number);
if (pl_type >= 0) {
- rtc::Set8(const_cast<char*>(data.c_str()), 1,
- static_cast<uint8_t>(pl_type));
+ rtc::Set8(data.data(), 1, static_cast<uint8_t>(pl_type));
}
return data;
}
- std::string CreateRtcpData(uint32_t ssrc) {
- std::string data(rtcp_packet_);
+ rtc::Buffer CreateRtcpData(uint32_t ssrc) {
+ rtc::Buffer data(rtcp_packet_.data(), rtcp_packet_.size());
// Set SSRC in the rtcp packet copy.
- rtc::SetBE32(const_cast<char*>(data.c_str()) + 4, ssrc);
+ rtc::SetBE32(data.data() + 4, ssrc);
return data;
}
@@ -408,86 +391,40 @@
return sdesc;
}
- class CallThread : public rtc::SignalThread {
- public:
- typedef bool (ChannelTest<T>::*Method)();
- CallThread(ChannelTest<T>* obj, Method method, bool* result = nullptr)
- : obj_(obj),
- method_(method),
- result_(false),
- result_ptr_(result) {
- if (result_ptr_)
- *result_ptr_ = false;
- }
-
- ~CallThread() {
- if (result_ptr_) {
- rtc::CritScope cs(&result_lock_);
- *result_ptr_ = result_;
- }
- }
-
- virtual void DoWork() {
- SetResult((*obj_.*method_)());
- }
-
- bool result() {
- rtc::CritScope cs(&result_lock_);
- return result_;
- }
-
- private:
- void SetResult(const bool& result) {
- rtc::CritScope cs(&result_lock_);
- result_ = result;
- }
-
- ChannelTest<T>* obj_;
- Method method_;
- rtc::CriticalSection result_lock_;
- bool result_ GUARDED_BY(result_lock_);
- bool* result_ptr_;
- };
-
// Will manage the lifetime of a CallThread, making sure it's
// destroyed before this object goes out of scope.
class ScopedCallThread {
public:
- using Method = typename CallThread::Method;
-
- ScopedCallThread(ChannelTest<T>* obj, Method method)
- : thread_(new CallThread(obj, method)) {
+ template <class FunctorT>
+ ScopedCallThread(const FunctorT& functor)
+ : thread_(rtc::Thread::Create()),
+ task_(new rtc::FunctorMessageHandler<void, FunctorT>(functor)) {
thread_->Start();
+ thread_->Post(task_.get());
}
- ~ScopedCallThread() {
- thread_->Destroy(true);
- }
+ ~ScopedCallThread() { thread_->Stop(); }
- bool result() const { return thread_->result(); }
+ rtc::Thread* thread() { return thread_.get(); }
private:
- CallThread* thread_;
+ std::unique_ptr<rtc::Thread> thread_;
+ std::unique_ptr<rtc::MessageHandler> task_;
};
- void CallOnThreadAndWaitForDone(typename CallThread::Method method,
- bool* result) {
- CallThread* thread = new CallThread(this, method, result);
- thread->Start();
- thread->Destroy(true);
- }
-
bool CodecMatches(const typename T::Codec& c1, const typename T::Codec& c2) {
return false; // overridden in specialized classes
}
- void OnMediaMonitor(typename T::Channel* channel,
- const typename T::MediaInfo& info) {
- if (channel == channel1_.get()) {
- media_info_callbacks1_++;
- } else if (channel == channel2_.get()) {
- media_info_callbacks2_++;
- }
+ void OnMediaMonitor1(typename T::Channel* channel,
+ const typename T::MediaInfo& info) {
+ RTC_DCHECK_EQ(channel, channel1_.get());
+ media_info_callbacks1_++;
+ }
+ void OnMediaMonitor2(typename T::Channel* channel,
+ const typename T::MediaInfo& info) {
+ RTC_DCHECK_EQ(channel, channel2_.get());
+ media_info_callbacks2_++;
}
cricket::CandidatePairInterface* last_selected_candidate_pair() {
@@ -792,7 +729,7 @@
EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
EXPECT_EQ(1u, media_channel2_->recv_streams().size());
- transport_controller1_.Connect(&transport_controller2_);
+ transport_controller1_->Connect(transport_controller2_.get());
// Channel 2 do not send anything.
typename T::Content content2;
@@ -803,7 +740,8 @@
EXPECT_TRUE(channel2_->Enable(true));
EXPECT_EQ(0u, media_channel2_->send_streams().size());
- EXPECT_TRUE(SendCustomRtp1(kSsrc1, 0));
+ SendCustomRtp1(kSsrc1, 0);
+ WaitForThreads();
EXPECT_TRUE(CheckCustomRtp2(kSsrc1, 0));
// Let channel 2 update the content by sending |stream2| and enable SRTP.
@@ -829,7 +767,8 @@
EXPECT_TRUE(channel1_->secure());
EXPECT_TRUE(channel2_->secure());
- EXPECT_TRUE(SendCustomRtp2(kSsrc2, 0));
+ SendCustomRtp2(kSsrc2, 0);
+ WaitForThreads();
EXPECT_TRUE(CheckCustomRtp1(kSsrc2, 0));
}
@@ -867,7 +806,7 @@
EXPECT_FALSE(media_channel2_->playout());
}
EXPECT_FALSE(media_channel2_->sending());
- transport_controller1_.Connect(&transport_controller2_);
+ transport_controller1_->Connect(transport_controller2_.get());
if (verify_playout_) {
EXPECT_TRUE(media_channel1_->playout());
}
@@ -915,7 +854,7 @@
EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
EXPECT_TRUE(channel2_->SetLocalContent(&content2, CA_PRANSWER, NULL));
EXPECT_TRUE(channel1_->SetRemoteContent(&content2, CA_PRANSWER, NULL));
- transport_controller1_.Connect(&transport_controller2_);
+ transport_controller1_->Connect(transport_controller2_.get());
if (verify_playout_) {
EXPECT_TRUE(media_channel1_->playout());
@@ -958,39 +897,47 @@
// Tests that when the transport channel signals a candidate pair change
// event, the media channel will receive a call on the network route change.
void TestNetworkRouteChanges() {
+ constexpr uint16_t kLocalNetId = 1;
+ constexpr uint16_t kRemoteNetId = 2;
+ constexpr int kLastPacketId = 100;
+
CreateChannels(0, 0);
cricket::TransportChannel* transport_channel1 =
channel1_->transport_channel();
- ASSERT_TRUE(transport_channel1 != nullptr);
+ ASSERT_TRUE(transport_channel1);
typename T::MediaChannel* media_channel1 =
static_cast<typename T::MediaChannel*>(channel1_->media_channel());
- ASSERT_TRUE(media_channel1 != nullptr);
+ ASSERT_TRUE(media_channel1);
- media_channel1_->set_num_network_route_changes(0);
- // The transport channel becomes disconnected.
- transport_channel1->SignalSelectedCandidatePairChanged(transport_channel1,
- nullptr, -1);
- EXPECT_EQ(1, media_channel1_->num_network_route_changes());
+ media_channel1->set_num_network_route_changes(0);
+ network_thread_->Invoke<void>([transport_channel1] {
+ // The transport channel becomes disconnected.
+ transport_channel1->SignalSelectedCandidatePairChanged(transport_channel1,
+ nullptr, -1);
+ });
+ WaitForThreads();
+ EXPECT_EQ(1, media_channel1->num_network_route_changes());
EXPECT_FALSE(media_channel1->last_network_route().connected);
+ media_channel1->set_num_network_route_changes(0);
- media_channel1_->set_num_network_route_changes(0);
- // The transport channel becomes connected.
- rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */);
- rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */);
- uint16_t local_net_id = 1;
- uint16_t remote_net_id = 2;
- int last_packet_id = 100;
- std::unique_ptr<cricket::CandidatePairInterface> candidate_pair(
- transport_controller1_.CreateFakeCandidatePair(
- local_address, local_net_id, remote_address, remote_net_id));
- transport_channel1->SignalSelectedCandidatePairChanged(
- transport_channel1, candidate_pair.get(), last_packet_id);
- EXPECT_EQ(1, media_channel1_->num_network_route_changes());
- rtc::NetworkRoute expected_network_route(local_net_id, remote_net_id,
- last_packet_id);
+ network_thread_->Invoke<void>([this, transport_channel1, media_channel1,
+ kLocalNetId, kRemoteNetId, kLastPacketId] {
+ // The transport channel becomes connected.
+ rtc::SocketAddress local_address("192.168.1.1", 1000 /* port number */);
+ rtc::SocketAddress remote_address("192.168.1.2", 2000 /* port number */);
+ std::unique_ptr<cricket::CandidatePairInterface> candidate_pair(
+ transport_controller1_->CreateFakeCandidatePair(
+ local_address, kLocalNetId, remote_address, kRemoteNetId));
+ transport_channel1->SignalSelectedCandidatePairChanged(
+ transport_channel1, candidate_pair.get(), kLastPacketId);
+ });
+ WaitForThreads();
+ EXPECT_EQ(1, media_channel1->num_network_route_changes());
+ rtc::NetworkRoute expected_network_route(kLocalNetId, kRemoteNetId,
+ kLastPacketId);
EXPECT_EQ(expected_network_route, media_channel1->last_network_route());
- EXPECT_EQ(last_packet_id,
+ EXPECT_EQ(kLastPacketId,
media_channel1->last_network_route().last_sent_packet_id);
}
@@ -1029,8 +976,7 @@
}
};
CreateChannels(new LastWordMediaChannel(), new LastWordMediaChannel(),
- RTCP | RTCP_MUX, RTCP | RTCP_MUX,
- rtc::Thread::Current());
+ RTCP | RTCP_MUX, RTCP | RTCP_MUX);
EXPECT_TRUE(SendInitiate());
EXPECT_TRUE(SendAccept());
EXPECT_TRUE(SendTerminate());
@@ -1045,8 +991,9 @@
ASSERT_TRUE(GetTransport2());
EXPECT_EQ(1U, GetTransport1()->channels().size());
EXPECT_EQ(1U, GetTransport2()->channels().size());
- EXPECT_TRUE(SendRtp1());
- EXPECT_TRUE(SendRtp2());
+ SendRtp1();
+ SendRtp2();
+ WaitForThreads();
EXPECT_TRUE(CheckRtp1());
EXPECT_TRUE(CheckRtp2());
EXPECT_TRUE(CheckNoRtp1());
@@ -1062,8 +1009,9 @@
ASSERT_TRUE(GetTransport2());
EXPECT_EQ(1U, GetTransport1()->channels().size());
EXPECT_EQ(1U, GetTransport2()->channels().size());
- EXPECT_FALSE(SendRtcp1());
- EXPECT_FALSE(SendRtcp2());
+ SendRtcp1();
+ SendRtcp2();
+ WaitForThreads();
EXPECT_TRUE(CheckNoRtcp1());
EXPECT_TRUE(CheckNoRtcp2());
}
@@ -1077,8 +1025,9 @@
ASSERT_TRUE(GetTransport2());
EXPECT_EQ(1U, GetTransport1()->channels().size());
EXPECT_EQ(2U, GetTransport2()->channels().size());
- EXPECT_FALSE(SendRtcp1());
- EXPECT_FALSE(SendRtcp2());
+ SendRtcp1();
+ SendRtcp2();
+ WaitForThreads();
EXPECT_TRUE(CheckNoRtcp1());
EXPECT_TRUE(CheckNoRtcp2());
}
@@ -1092,8 +1041,9 @@
ASSERT_TRUE(GetTransport2());
EXPECT_EQ(2U, GetTransport1()->channels().size());
EXPECT_EQ(1U, GetTransport2()->channels().size());
- EXPECT_FALSE(SendRtcp1());
- EXPECT_FALSE(SendRtcp2());
+ SendRtcp1();
+ SendRtcp2();
+ WaitForThreads();
EXPECT_TRUE(CheckNoRtcp1());
EXPECT_TRUE(CheckNoRtcp2());
}
@@ -1107,8 +1057,9 @@
ASSERT_TRUE(GetTransport2());
EXPECT_EQ(2U, GetTransport1()->channels().size());
EXPECT_EQ(2U, GetTransport2()->channels().size());
- EXPECT_TRUE(SendRtcp1());
- EXPECT_TRUE(SendRtcp2());
+ SendRtcp1();
+ SendRtcp2();
+ WaitForThreads();
EXPECT_TRUE(CheckRtcp1());
EXPECT_TRUE(CheckRtcp2());
EXPECT_TRUE(CheckNoRtcp1());
@@ -1124,8 +1075,9 @@
ASSERT_TRUE(GetTransport2());
EXPECT_EQ(2U, GetTransport1()->channels().size());
EXPECT_EQ(2U, GetTransport2()->channels().size());
- EXPECT_TRUE(SendRtcp1());
- EXPECT_TRUE(SendRtcp2());
+ SendRtcp1();
+ SendRtcp2();
+ WaitForThreads();
EXPECT_TRUE(CheckRtcp1());
EXPECT_TRUE(CheckRtcp2());
EXPECT_TRUE(CheckNoRtcp1());
@@ -1142,10 +1094,11 @@
EXPECT_EQ(1U, GetTransport2()->channels().size());
EXPECT_TRUE(SendAccept());
EXPECT_EQ(1U, GetTransport1()->channels().size());
- EXPECT_TRUE(SendRtp1());
- EXPECT_TRUE(SendRtp2());
- EXPECT_TRUE(SendRtcp1());
- EXPECT_TRUE(SendRtcp2());
+ SendRtp1();
+ SendRtp2();
+ SendRtcp1();
+ SendRtcp2();
+ WaitForThreads();
EXPECT_TRUE(CheckRtp1());
EXPECT_TRUE(CheckRtp2());
EXPECT_TRUE(CheckNoRtp1());
@@ -1167,10 +1120,11 @@
EXPECT_EQ(1U, GetTransport1()->channels().size());
EXPECT_EQ(1U, GetTransport2()->channels().size());
EXPECT_TRUE(SendAccept());
- EXPECT_TRUE(SendRtp1());
- EXPECT_TRUE(SendRtp2());
- EXPECT_TRUE(SendRtcp1());
- EXPECT_TRUE(SendRtcp2());
+ SendRtp1();
+ SendRtp2();
+ SendRtcp1();
+ SendRtcp2();
+ WaitForThreads();
EXPECT_TRUE(CheckRtp1());
EXPECT_TRUE(CheckRtp2());
EXPECT_TRUE(CheckNoRtp1());
@@ -1193,10 +1147,11 @@
EXPECT_EQ(1U, GetTransport2()->channels().size());
EXPECT_TRUE(SendAccept());
EXPECT_EQ(1U, GetTransport1()->channels().size());
- EXPECT_TRUE(SendRtp1());
- EXPECT_TRUE(SendRtp2());
- EXPECT_TRUE(SendRtcp1());
- EXPECT_TRUE(SendRtcp2());
+ SendRtp1();
+ SendRtp2();
+ SendRtcp1();
+ SendRtcp2();
+ WaitForThreads();
EXPECT_TRUE(CheckRtp1());
EXPECT_TRUE(CheckRtp2());
EXPECT_TRUE(CheckNoRtp1());
@@ -1220,10 +1175,11 @@
EXPECT_EQ(1U, GetTransport2()->channels().size());
EXPECT_TRUE(SendAccept());
EXPECT_EQ(1U, GetTransport1()->channels().size());
- EXPECT_TRUE(SendRtp1());
- EXPECT_TRUE(SendRtp2());
- EXPECT_TRUE(SendRtcp1());
- EXPECT_TRUE(SendRtcp2());
+ SendRtp1();
+ SendRtp2();
+ SendRtcp1();
+ SendRtcp2();
+ WaitForThreads();
EXPECT_TRUE(CheckRtp1());
EXPECT_TRUE(CheckRtp2());
EXPECT_TRUE(CheckNoRtp1());
@@ -1258,21 +1214,24 @@
// RTCP can be sent before the call is accepted, if the transport is ready.
// It should not be muxed though, as the remote side doesn't support mux.
- EXPECT_TRUE(SendRtcp1());
+ SendRtcp1();
+ WaitForThreads();
EXPECT_TRUE(CheckNoRtp2());
EXPECT_TRUE(CheckRtcp2());
// Send RTCP packet from callee and verify that it is received.
- EXPECT_TRUE(SendRtcp2());
+ SendRtcp2();
+ WaitForThreads();
EXPECT_TRUE(CheckNoRtp1());
EXPECT_TRUE(CheckRtcp1());
// Complete call setup and ensure everything is still OK.
EXPECT_TRUE(SendAccept());
EXPECT_EQ(2U, GetTransport1()->channels().size());
- EXPECT_TRUE(SendRtcp1());
+ SendRtcp1();
+ SendRtcp2();
+ WaitForThreads();
EXPECT_TRUE(CheckRtcp2());
- EXPECT_TRUE(SendRtcp2());
EXPECT_TRUE(CheckRtcp1());
}
@@ -1290,19 +1249,23 @@
// RTCP can't be sent yet, since the RTCP transport isn't writable, and
// we haven't yet received the accept that says we should mux.
- EXPECT_FALSE(SendRtcp1());
+ SendRtcp1();
+ WaitForThreads();
+ EXPECT_TRUE(CheckNoRtcp2());
// Send muxed RTCP packet from callee and verify that it is received.
- EXPECT_TRUE(SendRtcp2());
+ SendRtcp2();
+ WaitForThreads();
EXPECT_TRUE(CheckNoRtp1());
EXPECT_TRUE(CheckRtcp1());
// Complete call setup and ensure everything is still OK.
EXPECT_TRUE(SendAccept());
EXPECT_EQ(1U, GetTransport1()->channels().size());
- EXPECT_TRUE(SendRtcp1());
+ SendRtcp1();
+ SendRtcp2();
+ WaitForThreads();
EXPECT_TRUE(CheckRtcp2());
- EXPECT_TRUE(SendRtcp2());
EXPECT_TRUE(CheckRtcp1());
}
@@ -1320,17 +1283,19 @@
EXPECT_FALSE(channel1_->secure());
EXPECT_FALSE(channel2_->secure());
EXPECT_TRUE(SendInitiate());
- EXPECT_TRUE_WAIT(channel1_->writable(), kEventTimeout);
- EXPECT_TRUE_WAIT(channel2_->writable(), kEventTimeout);
+ WaitForThreads();
+ EXPECT_TRUE(channel1_->writable());
+ EXPECT_TRUE(channel2_->writable());
EXPECT_TRUE(SendAccept());
EXPECT_TRUE(channel1_->secure());
EXPECT_TRUE(channel2_->secure());
EXPECT_EQ(dtls1 && dtls2, channel1_->secure_dtls());
EXPECT_EQ(dtls1 && dtls2, channel2_->secure_dtls());
- EXPECT_TRUE(SendRtp1());
- EXPECT_TRUE(SendRtp2());
- EXPECT_TRUE(SendRtcp1());
- EXPECT_TRUE(SendRtcp2());
+ SendRtp1();
+ SendRtp2();
+ SendRtcp1();
+ SendRtcp2();
+ WaitForThreads();
EXPECT_TRUE(CheckRtp1());
EXPECT_TRUE(CheckRtp2());
EXPECT_TRUE(CheckNoRtp1());
@@ -1350,10 +1315,11 @@
EXPECT_TRUE(SendAccept());
EXPECT_FALSE(channel1_->secure());
EXPECT_FALSE(channel2_->secure());
- EXPECT_TRUE(SendRtp1());
- EXPECT_TRUE(SendRtp2());
- EXPECT_TRUE(SendRtcp1());
- EXPECT_TRUE(SendRtcp2());
+ SendRtp1();
+ SendRtp2();
+ SendRtcp1();
+ SendRtcp2();
+ WaitForThreads();
EXPECT_TRUE(CheckRtp1());
EXPECT_TRUE(CheckRtp2());
EXPECT_TRUE(CheckNoRtp1());
@@ -1379,15 +1345,18 @@
ASSERT_TRUE(GetTransport2());
EXPECT_EQ(2U, GetTransport1()->channels().size());
EXPECT_EQ(2U, GetTransport2()->channels().size());
- EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
+ WaitForThreads(); // Wait for 'sending' flag go through network thread.
+ SendCustomRtcp1(kSsrc1);
+ SendCustomRtp1(kSsrc1, ++sequence_number1_1);
+ WaitForThreads();
EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
- EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
// Send packets from callee and verify that it is received.
- EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
+ SendCustomRtcp2(kSsrc2);
+ SendCustomRtp2(kSsrc2, ++sequence_number2_2);
+ WaitForThreads();
EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
- EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
// Complete call setup and ensure everything is still OK.
@@ -1396,13 +1365,14 @@
EXPECT_EQ(1U, GetTransport2()->channels().size());
EXPECT_TRUE(channel1_->secure());
EXPECT_TRUE(channel2_->secure());
- EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
+ SendCustomRtcp1(kSsrc1);
+ SendCustomRtp1(kSsrc1, ++sequence_number1_1);
+ SendCustomRtcp2(kSsrc2);
+ SendCustomRtp2(kSsrc2, ++sequence_number2_2);
+ WaitForThreads();
EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
- EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1));
EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1));
- EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
- EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2));
EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2));
}
@@ -1411,20 +1381,20 @@
CreateChannels(RTCP, RTCP);
EXPECT_TRUE(SendInitiate());
EXPECT_TRUE(SendAccept());
- ScopedCallThread send_rtp1(this, &ChannelTest<T>::SendRtp1);
- ScopedCallThread send_rtp2(this, &ChannelTest<T>::SendRtp2);
- ScopedCallThread send_rtcp1(this, &ChannelTest<T>::SendRtcp1);
- ScopedCallThread send_rtcp2(this, &ChannelTest<T>::SendRtcp2);
- EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
- EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
- EXPECT_TRUE_WAIT(send_rtp1.result(), 1000);
- EXPECT_TRUE_WAIT(send_rtp2.result(), 1000);
+ ScopedCallThread send_rtp1([this] { SendRtp1(); });
+ ScopedCallThread send_rtp2([this] { SendRtp2(); });
+ ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
+ ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
+ rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
+ send_rtcp1.thread(),
+ send_rtcp2.thread()};
+ WaitForThreads(involved_threads);
+ EXPECT_TRUE(CheckRtp1());
+ EXPECT_TRUE(CheckRtp2());
EXPECT_TRUE(CheckNoRtp1());
EXPECT_TRUE(CheckNoRtp2());
- EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
- EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
- EXPECT_TRUE_WAIT(send_rtcp1.result(), 1000);
- EXPECT_TRUE_WAIT(send_rtcp2.result(), 1000);
+ EXPECT_TRUE(CheckRtcp1());
+ EXPECT_TRUE(CheckRtcp2());
EXPECT_TRUE(CheckNoRtcp1());
EXPECT_TRUE(CheckNoRtcp2());
}
@@ -1434,20 +1404,20 @@
CreateChannels(RTCP | SECURE, RTCP | SECURE);
EXPECT_TRUE(SendInitiate());
EXPECT_TRUE(SendAccept());
- ScopedCallThread send_rtp1(this, &ChannelTest<T>::SendRtp1);
- ScopedCallThread send_rtp2(this, &ChannelTest<T>::SendRtp2);
- ScopedCallThread send_rtcp1(this, &ChannelTest<T>::SendRtcp1);
- ScopedCallThread send_rtcp2(this, &ChannelTest<T>::SendRtcp2);
- EXPECT_TRUE_WAIT(CheckRtp1(), 1000);
- EXPECT_TRUE_WAIT(CheckRtp2(), 1000);
- EXPECT_TRUE_WAIT(send_rtp1.result(), 1000);
- EXPECT_TRUE_WAIT(send_rtp2.result(), 1000);
+ ScopedCallThread send_rtp1([this] { SendRtp1(); });
+ ScopedCallThread send_rtp2([this] { SendRtp2(); });
+ ScopedCallThread send_rtcp1([this] { SendRtcp1(); });
+ ScopedCallThread send_rtcp2([this] { SendRtcp2(); });
+ rtc::Thread* involved_threads[] = {send_rtp1.thread(), send_rtp2.thread(),
+ send_rtcp1.thread(),
+ send_rtcp2.thread()};
+ WaitForThreads(involved_threads);
+ EXPECT_TRUE(CheckRtp1());
+ EXPECT_TRUE(CheckRtp2());
EXPECT_TRUE(CheckNoRtp1());
EXPECT_TRUE(CheckNoRtp2());
- EXPECT_TRUE_WAIT(CheckRtcp1(), 1000);
- EXPECT_TRUE_WAIT(CheckRtcp2(), 1000);
- EXPECT_TRUE_WAIT(send_rtcp1.result(), 1000);
- EXPECT_TRUE_WAIT(send_rtcp2.result(), 1000);
+ EXPECT_TRUE(CheckRtcp1());
+ EXPECT_TRUE(CheckRtcp2());
EXPECT_TRUE(CheckNoRtcp1());
EXPECT_TRUE(CheckNoRtcp2());
}
@@ -1462,45 +1432,54 @@
ASSERT_TRUE(GetTransport2());
EXPECT_EQ(1U, GetTransport1()->channels().size());
EXPECT_EQ(1U, GetTransport2()->channels().size());
- EXPECT_TRUE(SendRtp1());
- EXPECT_TRUE(SendRtp2());
+ SendRtp1();
+ SendRtp2();
+ WaitForThreads();
EXPECT_TRUE(CheckRtp1());
EXPECT_TRUE(CheckRtp2());
EXPECT_TRUE(CheckNoRtp1());
EXPECT_TRUE(CheckNoRtp2());
// Lose writability, which should fail.
- GetTransport1()->SetWritable(false);
- EXPECT_FALSE(SendRtp1());
- EXPECT_TRUE(SendRtp2());
+ network_thread_->Invoke<void>(
+ [this] { GetTransport1()->SetWritable(false); });
+ SendRtp1();
+ SendRtp2();
+ WaitForThreads();
EXPECT_TRUE(CheckRtp1());
EXPECT_TRUE(CheckNoRtp2());
// Regain writability
- GetTransport1()->SetWritable(true);
+ network_thread_->Invoke<void>(
+ [this] { GetTransport1()->SetWritable(true); });
EXPECT_TRUE(media_channel1_->sending());
- EXPECT_TRUE(SendRtp1());
- EXPECT_TRUE(SendRtp2());
+ SendRtp1();
+ SendRtp2();
+ WaitForThreads();
EXPECT_TRUE(CheckRtp1());
EXPECT_TRUE(CheckRtp2());
EXPECT_TRUE(CheckNoRtp1());
EXPECT_TRUE(CheckNoRtp2());
// Lose writability completely
- GetTransport1()->SetDestination(NULL);
+ network_thread_->Invoke<void>(
+ [this] { GetTransport1()->SetDestination(NULL); });
EXPECT_TRUE(media_channel1_->sending());
// Should fail also.
- EXPECT_FALSE(SendRtp1());
- EXPECT_TRUE(SendRtp2());
+ SendRtp1();
+ SendRtp2();
+ WaitForThreads();
EXPECT_TRUE(CheckRtp1());
EXPECT_TRUE(CheckNoRtp2());
// Gain writability back
- GetTransport1()->SetDestination(GetTransport2());
+ network_thread_->Invoke<void>(
+ [this] { GetTransport1()->SetDestination(GetTransport2()); });
EXPECT_TRUE(media_channel1_->sending());
- EXPECT_TRUE(SendRtp1());
- EXPECT_TRUE(SendRtp2());
+ SendRtp1();
+ SendRtp2();
+ WaitForThreads();
EXPECT_TRUE(CheckRtp1());
EXPECT_TRUE(CheckRtp2());
EXPECT_TRUE(CheckNoRtp1());
@@ -1537,28 +1516,32 @@
EXPECT_FALSE(channel2_->bundle_filter()->FindPayloadType(pl_type2));
// Both channels can receive pl_type1 only.
- EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1));
+ SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type1);
+ SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1);
+ WaitForThreads();
EXPECT_TRUE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type1));
- EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type1));
EXPECT_TRUE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type1));
EXPECT_TRUE(CheckNoRtp1());
EXPECT_TRUE(CheckNoRtp2());
// RTCP test
- EXPECT_TRUE(SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2));
+ SendCustomRtp1(kSsrc1, ++sequence_number1_1, pl_type2);
+ SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2);
+ WaitForThreads();
EXPECT_FALSE(CheckCustomRtp2(kSsrc1, sequence_number1_1, pl_type2));
- EXPECT_TRUE(SendCustomRtp2(kSsrc2, ++sequence_number2_2, pl_type2));
EXPECT_FALSE(CheckCustomRtp1(kSsrc2, sequence_number2_2, pl_type2));
- EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
- EXPECT_TRUE(SendCustomRtcp2(kSsrc2));
+ SendCustomRtcp1(kSsrc1);
+ SendCustomRtcp2(kSsrc2);
+ WaitForThreads();
EXPECT_TRUE(CheckCustomRtcp1(kSsrc2));
EXPECT_TRUE(CheckNoRtcp1());
EXPECT_TRUE(CheckCustomRtcp2(kSsrc1));
EXPECT_TRUE(CheckNoRtcp2());
- EXPECT_TRUE(SendCustomRtcp1(kSsrc2));
- EXPECT_TRUE(SendCustomRtcp2(kSsrc1));
+ SendCustomRtcp1(kSsrc2);
+ SendCustomRtcp2(kSsrc1);
+ WaitForThreads();
// Bundle filter shouldn't filter out any RTCP.
EXPECT_TRUE(CheckCustomRtcp1(kSsrc1));
EXPECT_TRUE(CheckCustomRtcp2(kSsrc2));
@@ -1704,7 +1687,6 @@
}
void TestFlushRtcp() {
- bool send_rtcp1;
CreateChannels(RTCP, RTCP);
EXPECT_TRUE(SendInitiate());
EXPECT_TRUE(SendAccept());
@@ -1714,14 +1696,16 @@
EXPECT_EQ(2U, GetTransport2()->channels().size());
// Send RTCP1 from a different thread.
- CallOnThreadAndWaitForDone(&ChannelTest<T>::SendRtcp1, &send_rtcp1);
- EXPECT_TRUE(send_rtcp1);
+ ScopedCallThread send_rtcp([this] { SendRtcp1(); });
// The sending message is only posted. channel2_ should be empty.
EXPECT_TRUE(CheckNoRtcp2());
+ rtc::Thread* wait_for[] = {send_rtcp.thread()};
+ WaitForThreads(wait_for); // Ensure rtcp was posted
// When channel1_ is deleted, the RTCP packet should be sent out to
// channel2_.
channel1_.reset();
+ WaitForThreads();
EXPECT_TRUE(CheckRtcp2());
}
@@ -1744,18 +1728,13 @@
// So we need to pass in pl_type so that the packet can pass through
// the bundle filter before it can be processed by the srtp filter.
// The packet is not a valid srtp packet because it is too short.
- unsigned const char kBadPacket[] = {0x84,
- static_cast<unsigned char>(pl_type),
- 0x00,
- 0x01,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x00,
- 0x01};
+ static unsigned const char kBadPacket[] = {
+ 0x84, static_cast<unsigned char>(pl_type),
+ 0x00, 0x01,
+ 0x00, 0x00,
+ 0x00, 0x00,
+ 0x00, 0x00,
+ 0x00, 0x01};
CreateChannels(RTCP | SECURE, RTCP | SECURE);
EXPECT_FALSE(channel1_->secure());
EXPECT_FALSE(channel2_->secure());
@@ -1768,37 +1747,42 @@
&error_handler, &SrtpErrorHandler::OnSrtpError);
// Testing failures in sending packets.
- EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
- rtc::PacketOptions()));
+ media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
+ rtc::PacketOptions());
+ WaitForThreads();
// The first failure will trigger an error.
- EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
+ EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
// The next 250 ms failures will not trigger an error.
- EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
- rtc::PacketOptions()));
+ media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
+ rtc::PacketOptions());
// Wait for a while to ensure no message comes in.
+ WaitForThreads();
rtc::Thread::Current()->ProcessMessages(200);
EXPECT_EQ(cricket::SrtpFilter::ERROR_NONE, error_handler.error_);
EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
// Wait for a little more - the error will be triggered again.
rtc::Thread::Current()->ProcessMessages(200);
- EXPECT_FALSE(media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
- rtc::PacketOptions()));
- EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
+ media_channel2_->SendRtp(kBadPacket, sizeof(kBadPacket),
+ rtc::PacketOptions());
+ WaitForThreads();
+ EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
EXPECT_EQ(cricket::SrtpFilter::PROTECT, error_handler.mode_);
// Testing failures in receiving packets.
error_handler.error_ = cricket::SrtpFilter::ERROR_NONE;
error_handler.mode_ = cricket::SrtpFilter::UNPROTECT;
- cricket::TransportChannel* transport_channel =
- channel2_->transport_channel();
- transport_channel->SignalReadPacket(
- transport_channel, reinterpret_cast<const char*>(kBadPacket),
- sizeof(kBadPacket), rtc::PacketTime(), 0);
- EXPECT_EQ_WAIT(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_, 500);
+ network_thread_->Invoke<void>([this] {
+ cricket::TransportChannel* transport_channel =
+ channel2_->transport_channel();
+ transport_channel->SignalReadPacket(
+ transport_channel, reinterpret_cast<const char*>(kBadPacket),
+ sizeof(kBadPacket), rtc::PacketTime(), 0);
+ });
+ EXPECT_EQ(cricket::SrtpFilter::ERROR_FAIL, error_handler.error_);
EXPECT_EQ(cricket::SrtpFilter::UNPROTECT, error_handler.mode_);
}
@@ -1807,23 +1791,37 @@
TransportChannel* rtp = channel1_->transport_channel();
TransportChannel* rtcp = channel1_->rtcp_transport_channel();
EXPECT_FALSE(media_channel1_->ready_to_send());
- rtp->SignalReadyToSend(rtp);
+
+ network_thread_->Invoke<void>([rtp] { rtp->SignalReadyToSend(rtp); });
+ WaitForThreads();
EXPECT_FALSE(media_channel1_->ready_to_send());
- rtcp->SignalReadyToSend(rtcp);
+
+ network_thread_->Invoke<void>([rtcp] { rtcp->SignalReadyToSend(rtcp); });
+ WaitForThreads();
// MediaChannel::OnReadyToSend only be called when both rtp and rtcp
// channel are ready to send.
EXPECT_TRUE(media_channel1_->ready_to_send());
// rtp channel becomes not ready to send will be propagated to mediachannel
- channel1_->SetReadyToSend(false, false);
+ network_thread_->Invoke<void>(
+ [this] { channel1_->SetReadyToSend(false, false); });
+ WaitForThreads();
EXPECT_FALSE(media_channel1_->ready_to_send());
- channel1_->SetReadyToSend(false, true);
+
+ network_thread_->Invoke<void>(
+ [this] { channel1_->SetReadyToSend(false, true); });
+ WaitForThreads();
EXPECT_TRUE(media_channel1_->ready_to_send());
// rtcp channel becomes not ready to send will be propagated to mediachannel
- channel1_->SetReadyToSend(true, false);
+ network_thread_->Invoke<void>(
+ [this] { channel1_->SetReadyToSend(true, false); });
+ WaitForThreads();
EXPECT_FALSE(media_channel1_->ready_to_send());
- channel1_->SetReadyToSend(true, true);
+
+ network_thread_->Invoke<void>(
+ [this] { channel1_->SetReadyToSend(true, true); });
+ WaitForThreads();
EXPECT_TRUE(media_channel1_->ready_to_send());
}
@@ -1840,9 +1838,13 @@
EXPECT_FALSE(media_channel1_->ready_to_send());
// In the case of rtcp mux, the SignalReadyToSend() from rtp channel
// should trigger the MediaChannel's OnReadyToSend.
- rtp->SignalReadyToSend(rtp);
+ network_thread_->Invoke<void>([rtp] { rtp->SignalReadyToSend(rtp); });
+ WaitForThreads();
EXPECT_TRUE(media_channel1_->ready_to_send());
- channel1_->SetReadyToSend(false, false);
+
+ network_thread_->Invoke<void>(
+ [this] { channel1_->SetReadyToSend(false, false); });
+ WaitForThreads();
EXPECT_FALSE(media_channel1_->ready_to_send());
}
@@ -1894,11 +1896,34 @@
}
protected:
+ void WaitForThreads() { WaitForThreads(rtc::ArrayView<rtc::Thread*>()); }
+ static void ProcessThreadQueue(rtc::Thread* thread) {
+ RTC_DCHECK(thread->IsCurrent());
+ while (!thread->empty()) {
+ thread->ProcessMessages(0);
+ }
+ }
+ void WaitForThreads(rtc::ArrayView<rtc::Thread*> threads) {
+ // |threads| and current thread post packets to network thread.
+ for (rtc::Thread* thread : threads) {
+ thread->Invoke<void>([thread] { ProcessThreadQueue(thread); });
+ }
+ ProcessThreadQueue(rtc::Thread::Current());
+ // Network thread move them around and post back to worker = current thread.
+ if (!network_thread_->IsCurrent()) {
+ network_thread_->Invoke<void>(
+ [this] { ProcessThreadQueue(network_thread_); });
+ }
+ // Worker thread = current Thread process received messages.
+ ProcessThreadQueue(rtc::Thread::Current());
+ }
// TODO(pbos): Remove playout from all media channels and let renderers mute
// themselves.
const bool verify_playout_;
- cricket::FakeTransportController transport_controller1_;
- cricket::FakeTransportController transport_controller2_;
+ std::unique_ptr<rtc::Thread> network_thread_keeper_;
+ rtc::Thread* network_thread_;
+ std::unique_ptr<cricket::FakeTransportController> transport_controller1_;
+ std::unique_ptr<cricket::FakeTransportController> transport_controller2_;
cricket::FakeMediaEngine media_engine_;
// The media channels are owned by the voice channel objects below.
typename T::MediaChannel* media_channel1_;
@@ -1910,8 +1935,8 @@
typename T::Content remote_media_content1_;
typename T::Content remote_media_content2_;
// The RTP and RTCP packets to send in the tests.
- std::string rtp_packet_;
- std::string rtcp_packet_;
+ rtc::Buffer rtp_packet_;
+ rtc::Buffer rtcp_packet_;
int media_info_callbacks1_;
int media_info_callbacks2_;
cricket::CandidatePairInterface* last_selected_candidate_pair_;
@@ -1954,29 +1979,33 @@
audio->AddLegacyStream(ssrc);
}
-class VoiceChannelTest
- : public ChannelTest<VoiceTraits> {
+class VoiceChannelSingleThreadTest : public ChannelTest<VoiceTraits> {
public:
typedef ChannelTest<VoiceTraits> Base;
- VoiceChannelTest()
- : Base(true,
- kPcmuFrame,
- sizeof(kPcmuFrame),
- kRtcpReport,
- sizeof(kRtcpReport)) {}
+ VoiceChannelSingleThreadTest()
+ : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::Yes) {}
+};
+
+class VoiceChannelDoubleThreadTest : public ChannelTest<VoiceTraits> {
+ public:
+ typedef ChannelTest<VoiceTraits> Base;
+ VoiceChannelDoubleThreadTest()
+ : Base(true, kPcmuFrame, kRtcpReport, NetworkIsWorker::No) {}
};
// override to add NULL parameter
template <>
cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
- rtc::Thread* thread,
+ rtc::Thread* worker_thread,
+ rtc::Thread* network_thread,
cricket::MediaEngineInterface* engine,
cricket::FakeVideoMediaChannel* ch,
cricket::TransportController* transport_controller,
bool rtcp) {
- cricket::VideoChannel* channel = new cricket::VideoChannel(
- thread, ch, transport_controller, cricket::CN_VIDEO, rtcp);
- if (!channel->Init()) {
+ cricket::VideoChannel* channel =
+ new cricket::VideoChannel(worker_thread, network_thread, ch,
+ transport_controller, cricket::CN_VIDEO, rtcp);
+ if (!channel->Init_w()) {
delete channel;
channel = NULL;
}
@@ -2026,67 +2055,68 @@
video->AddLegacyStream(ssrc);
}
-class VideoChannelTest
- : public ChannelTest<VideoTraits> {
+class VideoChannelSingleThreadTest : public ChannelTest<VideoTraits> {
public:
typedef ChannelTest<VideoTraits> Base;
- VideoChannelTest()
- : Base(false,
- kH264Packet,
- sizeof(kH264Packet),
- kRtcpReport,
- sizeof(kRtcpReport)) {}
+ VideoChannelSingleThreadTest()
+ : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::Yes) {}
};
+class VideoChannelDoubleThreadTest : public ChannelTest<VideoTraits> {
+ public:
+ typedef ChannelTest<VideoTraits> Base;
+ VideoChannelDoubleThreadTest()
+ : Base(false, kH264Packet, kRtcpReport, NetworkIsWorker::No) {}
+};
-// VoiceChannelTest
-TEST_F(VoiceChannelTest, TestInit) {
+// VoiceChannelSingleThreadTest
+TEST_F(VoiceChannelSingleThreadTest, TestInit) {
Base::TestInit();
EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
}
-TEST_F(VoiceChannelTest, TestSetContents) {
+TEST_F(VoiceChannelSingleThreadTest, TestSetContents) {
Base::TestSetContents();
}
-TEST_F(VoiceChannelTest, TestSetContentsNullOffer) {
+TEST_F(VoiceChannelSingleThreadTest, TestSetContentsNullOffer) {
Base::TestSetContentsNullOffer();
}
-TEST_F(VoiceChannelTest, TestSetContentsRtcpMux) {
+TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMux) {
Base::TestSetContentsRtcpMux();
}
-TEST_F(VoiceChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
+TEST_F(VoiceChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
Base::TestSetContentsRtcpMux();
}
-TEST_F(VoiceChannelTest, TestSetRemoteContentUpdate) {
+TEST_F(VoiceChannelSingleThreadTest, TestSetRemoteContentUpdate) {
Base::TestSetRemoteContentUpdate();
}
-TEST_F(VoiceChannelTest, TestStreams) {
+TEST_F(VoiceChannelSingleThreadTest, TestStreams) {
Base::TestStreams();
}
-TEST_F(VoiceChannelTest, TestUpdateStreamsInLocalContent) {
+TEST_F(VoiceChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
Base::TestUpdateStreamsInLocalContent();
}
-TEST_F(VoiceChannelTest, TestUpdateRemoteStreamsInContent) {
+TEST_F(VoiceChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
Base::TestUpdateStreamsInRemoteContent();
}
-TEST_F(VoiceChannelTest, TestChangeStreamParamsInContent) {
+TEST_F(VoiceChannelSingleThreadTest, TestChangeStreamParamsInContent) {
Base::TestChangeStreamParamsInContent();
}
-TEST_F(VoiceChannelTest, TestPlayoutAndSendingStates) {
+TEST_F(VoiceChannelSingleThreadTest, TestPlayoutAndSendingStates) {
Base::TestPlayoutAndSendingStates();
}
-TEST_F(VoiceChannelTest, TestMuteStream) {
+TEST_F(VoiceChannelSingleThreadTest, TestMuteStream) {
CreateChannels(0, 0);
// Test that we can Mute the default channel even though the sending SSRC
// is unknown.
@@ -2108,123 +2138,123 @@
EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
}
-TEST_F(VoiceChannelTest, TestMediaContentDirection) {
+TEST_F(VoiceChannelSingleThreadTest, TestMediaContentDirection) {
Base::TestMediaContentDirection();
}
-TEST_F(VoiceChannelTest, TestNetworkRouteChanges) {
+TEST_F(VoiceChannelSingleThreadTest, TestNetworkRouteChanges) {
Base::TestNetworkRouteChanges();
}
-TEST_F(VoiceChannelTest, TestCallSetup) {
+TEST_F(VoiceChannelSingleThreadTest, TestCallSetup) {
Base::TestCallSetup();
}
-TEST_F(VoiceChannelTest, TestCallTeardownRtcpMux) {
+TEST_F(VoiceChannelSingleThreadTest, TestCallTeardownRtcpMux) {
Base::TestCallTeardownRtcpMux();
}
-TEST_F(VoiceChannelTest, SendRtpToRtp) {
+TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtp) {
Base::SendRtpToRtp();
}
-TEST_F(VoiceChannelTest, SendNoRtcpToNoRtcp) {
+TEST_F(VoiceChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
Base::SendNoRtcpToNoRtcp();
}
-TEST_F(VoiceChannelTest, SendNoRtcpToRtcp) {
+TEST_F(VoiceChannelSingleThreadTest, SendNoRtcpToRtcp) {
Base::SendNoRtcpToRtcp();
}
-TEST_F(VoiceChannelTest, SendRtcpToNoRtcp) {
+TEST_F(VoiceChannelSingleThreadTest, SendRtcpToNoRtcp) {
Base::SendRtcpToNoRtcp();
}
-TEST_F(VoiceChannelTest, SendRtcpToRtcp) {
+TEST_F(VoiceChannelSingleThreadTest, SendRtcpToRtcp) {
Base::SendRtcpToRtcp();
}
-TEST_F(VoiceChannelTest, SendRtcpMuxToRtcp) {
+TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcp) {
Base::SendRtcpMuxToRtcp();
}
-TEST_F(VoiceChannelTest, SendRtcpMuxToRtcpMux) {
+TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
Base::SendRtcpMuxToRtcpMux();
}
-TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRtcpMux) {
+TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Base::SendRequireRtcpMuxToRtcpMux();
}
-TEST_F(VoiceChannelTest, SendRtcpMuxToRequireRtcpMux) {
+TEST_F(VoiceChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Base::SendRtcpMuxToRequireRtcpMux();
}
-TEST_F(VoiceChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
+TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Base::SendRequireRtcpMuxToRequireRtcpMux();
}
-TEST_F(VoiceChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
+TEST_F(VoiceChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Base::SendRequireRtcpMuxToNoRtcpMux();
}
-TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcp) {
+TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
Base::SendEarlyRtcpMuxToRtcp();
}
-TEST_F(VoiceChannelTest, SendEarlyRtcpMuxToRtcpMux) {
+TEST_F(VoiceChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
Base::SendEarlyRtcpMuxToRtcpMux();
}
-TEST_F(VoiceChannelTest, SendSrtpToSrtpRtcpMux) {
+TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpRtcpMux) {
Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
}
-TEST_F(VoiceChannelTest, SendSrtpToRtp) {
+TEST_F(VoiceChannelSingleThreadTest, SendSrtpToRtp) {
Base::SendSrtpToSrtp();
}
-TEST_F(VoiceChannelTest, SendSrtcpMux) {
+TEST_F(VoiceChannelSingleThreadTest, SendSrtcpMux) {
Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
}
-TEST_F(VoiceChannelTest, SendDtlsSrtpToSrtp) {
+TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
MAYBE_SKIP_TEST(HaveDtlsSrtp);
Base::SendSrtpToSrtp(DTLS, 0);
}
-TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtp) {
+TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
MAYBE_SKIP_TEST(HaveDtlsSrtp);
Base::SendSrtpToSrtp(DTLS, DTLS);
}
-TEST_F(VoiceChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
+TEST_F(VoiceChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
MAYBE_SKIP_TEST(HaveDtlsSrtp);
Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
}
-TEST_F(VoiceChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
+TEST_F(VoiceChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
Base::SendEarlyMediaUsingRtcpMuxSrtp();
}
-TEST_F(VoiceChannelTest, SendRtpToRtpOnThread) {
+TEST_F(VoiceChannelSingleThreadTest, SendRtpToRtpOnThread) {
Base::SendRtpToRtpOnThread();
}
-TEST_F(VoiceChannelTest, SendSrtpToSrtpOnThread) {
+TEST_F(VoiceChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
Base::SendSrtpToSrtpOnThread();
}
-TEST_F(VoiceChannelTest, SendWithWritabilityLoss) {
+TEST_F(VoiceChannelSingleThreadTest, SendWithWritabilityLoss) {
Base::SendWithWritabilityLoss();
}
-TEST_F(VoiceChannelTest, TestMediaMonitor) {
+TEST_F(VoiceChannelSingleThreadTest, TestMediaMonitor) {
Base::TestMediaMonitor();
}
// Test that InsertDtmf properly forwards to the media channel.
-TEST_F(VoiceChannelTest, TestInsertDtmf) {
+TEST_F(VoiceChannelSingleThreadTest, TestInsertDtmf) {
CreateChannels(0, 0);
EXPECT_TRUE(SendInitiate());
EXPECT_TRUE(SendAccept());
@@ -2243,44 +2273,44 @@
3, 7, 120));
}
-TEST_F(VoiceChannelTest, TestSetContentFailure) {
+TEST_F(VoiceChannelSingleThreadTest, TestSetContentFailure) {
Base::TestSetContentFailure();
}
-TEST_F(VoiceChannelTest, TestSendTwoOffers) {
+TEST_F(VoiceChannelSingleThreadTest, TestSendTwoOffers) {
Base::TestSendTwoOffers();
}
-TEST_F(VoiceChannelTest, TestReceiveTwoOffers) {
+TEST_F(VoiceChannelSingleThreadTest, TestReceiveTwoOffers) {
Base::TestReceiveTwoOffers();
}
-TEST_F(VoiceChannelTest, TestSendPrAnswer) {
+TEST_F(VoiceChannelSingleThreadTest, TestSendPrAnswer) {
Base::TestSendPrAnswer();
}
-TEST_F(VoiceChannelTest, TestReceivePrAnswer) {
+TEST_F(VoiceChannelSingleThreadTest, TestReceivePrAnswer) {
Base::TestReceivePrAnswer();
}
-TEST_F(VoiceChannelTest, TestFlushRtcp) {
+TEST_F(VoiceChannelSingleThreadTest, TestFlushRtcp) {
Base::TestFlushRtcp();
}
-TEST_F(VoiceChannelTest, TestSrtpError) {
+TEST_F(VoiceChannelSingleThreadTest, TestSrtpError) {
Base::TestSrtpError(kAudioPts[0]);
}
-TEST_F(VoiceChannelTest, TestOnReadyToSend) {
+TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSend) {
Base::TestOnReadyToSend();
}
-TEST_F(VoiceChannelTest, TestOnReadyToSendWithRtcpMux) {
+TEST_F(VoiceChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
Base::TestOnReadyToSendWithRtcpMux();
}
// Test that we can scale the output volume properly for 1:1 calls.
-TEST_F(VoiceChannelTest, TestScaleVolume1to1Call) {
+TEST_F(VoiceChannelSingleThreadTest, TestScaleVolume1to1Call) {
CreateChannels(RTCP, RTCP);
EXPECT_TRUE(SendInitiate());
EXPECT_TRUE(SendAccept());
@@ -2304,7 +2334,7 @@
}
// Test that we can scale the output volume properly for multiway calls.
-TEST_F(VoiceChannelTest, TestScaleVolumeMultiwayCall) {
+TEST_F(VoiceChannelSingleThreadTest, TestScaleVolumeMultiwayCall) {
CreateChannels(RTCP, RTCP);
EXPECT_TRUE(SendInitiate());
EXPECT_TRUE(SendAccept());
@@ -2341,76 +2371,402 @@
EXPECT_DOUBLE_EQ(0.0, volume);
}
-TEST_F(VoiceChannelTest, SendBundleToBundle) {
+TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundle) {
Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
}
-TEST_F(VoiceChannelTest, SendBundleToBundleSecure) {
+TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleSecure) {
Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
}
-TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMux) {
+TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
}
-TEST_F(VoiceChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
+TEST_F(VoiceChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
}
-TEST_F(VoiceChannelTest, DefaultMaxBitrateIsUnlimited) {
+TEST_F(VoiceChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
Base::DefaultMaxBitrateIsUnlimited();
}
-TEST_F(VoiceChannelTest, CanChangeMaxBitrate) {
+TEST_F(VoiceChannelSingleThreadTest, CanChangeMaxBitrate) {
Base::CanChangeMaxBitrate();
}
-// VideoChannelTest
-TEST_F(VideoChannelTest, TestInit) {
+// VoiceChannelDoubleThreadTest
+TEST_F(VoiceChannelDoubleThreadTest, TestInit) {
Base::TestInit();
+ EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
+ EXPECT_TRUE(media_channel1_->dtmf_info_queue().empty());
}
-TEST_F(VideoChannelTest, TestSetContents) {
+TEST_F(VoiceChannelDoubleThreadTest, TestSetContents) {
Base::TestSetContents();
}
-TEST_F(VideoChannelTest, TestSetContentsNullOffer) {
+TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsNullOffer) {
Base::TestSetContentsNullOffer();
}
-TEST_F(VideoChannelTest, TestSetContentsRtcpMux) {
+TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMux) {
Base::TestSetContentsRtcpMux();
}
-TEST_F(VideoChannelTest, TestSetContentsRtcpMuxWithPrAnswer) {
+TEST_F(VoiceChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
Base::TestSetContentsRtcpMux();
}
-TEST_F(VideoChannelTest, TestSetRemoteContentUpdate) {
+TEST_F(VoiceChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
Base::TestSetRemoteContentUpdate();
}
-TEST_F(VideoChannelTest, TestStreams) {
+TEST_F(VoiceChannelDoubleThreadTest, TestStreams) {
Base::TestStreams();
}
-TEST_F(VideoChannelTest, TestUpdateStreamsInLocalContent) {
+TEST_F(VoiceChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
Base::TestUpdateStreamsInLocalContent();
}
-TEST_F(VideoChannelTest, TestUpdateRemoteStreamsInContent) {
+TEST_F(VoiceChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
Base::TestUpdateStreamsInRemoteContent();
}
-TEST_F(VideoChannelTest, TestChangeStreamParamsInContent) {
+TEST_F(VoiceChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
Base::TestChangeStreamParamsInContent();
}
-TEST_F(VideoChannelTest, TestPlayoutAndSendingStates) {
+TEST_F(VoiceChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
Base::TestPlayoutAndSendingStates();
}
-TEST_F(VideoChannelTest, TestMuteStream) {
+TEST_F(VoiceChannelDoubleThreadTest, TestMuteStream) {
+ CreateChannels(0, 0);
+ // Test that we can Mute the default channel even though the sending SSRC
+ // is unknown.
+ EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
+ EXPECT_TRUE(channel1_->SetAudioSend(0, false, nullptr, nullptr));
+ EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
+ EXPECT_TRUE(channel1_->SetAudioSend(0, true, nullptr, nullptr));
+ EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
+
+ // Test that we can not mute an unknown SSRC.
+ EXPECT_FALSE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
+
+ SendInitiate();
+ // After the local session description has been set, we can mute a stream
+ // with its SSRC.
+ EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, false, nullptr, nullptr));
+ EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
+ EXPECT_TRUE(channel1_->SetAudioSend(kSsrc1, true, nullptr, nullptr));
+ EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, TestMediaContentDirection) {
+ Base::TestMediaContentDirection();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, TestNetworkRouteChanges) {
+ Base::TestNetworkRouteChanges();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, TestCallSetup) {
+ Base::TestCallSetup();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
+ Base::TestCallTeardownRtcpMux();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtp) {
+ Base::SendRtpToRtp();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
+ Base::SendNoRtcpToNoRtcp();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendNoRtcpToRtcp) {
+ Base::SendNoRtcpToRtcp();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToNoRtcp) {
+ Base::SendRtcpToNoRtcp();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendRtcpToRtcp) {
+ Base::SendRtcpToRtcp();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
+ Base::SendRtcpMuxToRtcp();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
+ Base::SendRtcpMuxToRtcpMux();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
+ Base::SendRequireRtcpMuxToRtcpMux();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
+ Base::SendRtcpMuxToRequireRtcpMux();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
+ Base::SendRequireRtcpMuxToRequireRtcpMux();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
+ Base::SendRequireRtcpMuxToNoRtcpMux();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
+ Base::SendEarlyRtcpMuxToRtcp();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
+ Base::SendEarlyRtcpMuxToRtcpMux();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpRtcpMux) {
+ Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToRtp) {
+ Base::SendSrtpToSrtp();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendSrtcpMux) {
+ Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
+ MAYBE_SKIP_TEST(HaveDtlsSrtp);
+ Base::SendSrtpToSrtp(DTLS, 0);
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
+ MAYBE_SKIP_TEST(HaveDtlsSrtp);
+ Base::SendSrtpToSrtp(DTLS, DTLS);
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
+ MAYBE_SKIP_TEST(HaveDtlsSrtp);
+ Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
+ Base::SendEarlyMediaUsingRtcpMuxSrtp();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendRtpToRtpOnThread) {
+ Base::SendRtpToRtpOnThread();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
+ Base::SendSrtpToSrtpOnThread();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendWithWritabilityLoss) {
+ Base::SendWithWritabilityLoss();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, TestMediaMonitor) {
+ Base::TestMediaMonitor();
+}
+
+// Test that InsertDtmf properly forwards to the media channel.
+TEST_F(VoiceChannelDoubleThreadTest, TestInsertDtmf) {
+ CreateChannels(0, 0);
+ EXPECT_TRUE(SendInitiate());
+ EXPECT_TRUE(SendAccept());
+ EXPECT_EQ(0U, media_channel1_->dtmf_info_queue().size());
+
+ EXPECT_TRUE(channel1_->InsertDtmf(1, 3, 100));
+ EXPECT_TRUE(channel1_->InsertDtmf(2, 5, 110));
+ EXPECT_TRUE(channel1_->InsertDtmf(3, 7, 120));
+
+ ASSERT_EQ(3U, media_channel1_->dtmf_info_queue().size());
+ EXPECT_TRUE(
+ CompareDtmfInfo(media_channel1_->dtmf_info_queue()[0], 1, 3, 100));
+ EXPECT_TRUE(
+ CompareDtmfInfo(media_channel1_->dtmf_info_queue()[1], 2, 5, 110));
+ EXPECT_TRUE(
+ CompareDtmfInfo(media_channel1_->dtmf_info_queue()[2], 3, 7, 120));
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, TestSetContentFailure) {
+ Base::TestSetContentFailure();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, TestSendTwoOffers) {
+ Base::TestSendTwoOffers();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, TestReceiveTwoOffers) {
+ Base::TestReceiveTwoOffers();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, TestSendPrAnswer) {
+ Base::TestSendPrAnswer();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, TestReceivePrAnswer) {
+ Base::TestReceivePrAnswer();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, TestFlushRtcp) {
+ Base::TestFlushRtcp();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, TestSrtpError) {
+ Base::TestSrtpError(kAudioPts[0]);
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSend) {
+ Base::TestOnReadyToSend();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
+ Base::TestOnReadyToSendWithRtcpMux();
+}
+
+// Test that we can scale the output volume properly for 1:1 calls.
+TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolume1to1Call) {
+ CreateChannels(RTCP, RTCP);
+ EXPECT_TRUE(SendInitiate());
+ EXPECT_TRUE(SendAccept());
+ double volume;
+
+ // Default is (1.0).
+ EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
+ EXPECT_DOUBLE_EQ(1.0, volume);
+ // invalid ssrc.
+ EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
+
+ // Set scale to (1.5).
+ EXPECT_TRUE(channel1_->SetOutputVolume(0, 1.5));
+ EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
+ EXPECT_DOUBLE_EQ(1.5, volume);
+
+ // Set scale to (0).
+ EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
+ EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
+ EXPECT_DOUBLE_EQ(0.0, volume);
+}
+
+// Test that we can scale the output volume properly for multiway calls.
+TEST_F(VoiceChannelDoubleThreadTest, TestScaleVolumeMultiwayCall) {
+ CreateChannels(RTCP, RTCP);
+ EXPECT_TRUE(SendInitiate());
+ EXPECT_TRUE(SendAccept());
+ EXPECT_TRUE(AddStream1(1));
+ EXPECT_TRUE(AddStream1(2));
+
+ double volume;
+ // Default is (1.0).
+ EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
+ EXPECT_DOUBLE_EQ(1.0, volume);
+ EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
+ EXPECT_DOUBLE_EQ(1.0, volume);
+ EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
+ EXPECT_DOUBLE_EQ(1.0, volume);
+ // invalid ssrc.
+ EXPECT_FALSE(media_channel1_->GetOutputVolume(3, &volume));
+
+ // Set scale to (1.5) for ssrc = 1.
+ EXPECT_TRUE(channel1_->SetOutputVolume(1, 1.5));
+ EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
+ EXPECT_DOUBLE_EQ(1.5, volume);
+ EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
+ EXPECT_DOUBLE_EQ(1.0, volume);
+ EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
+ EXPECT_DOUBLE_EQ(1.0, volume);
+
+ // Set scale to (0) for all ssrcs.
+ EXPECT_TRUE(channel1_->SetOutputVolume(0, 0.0));
+ EXPECT_TRUE(media_channel1_->GetOutputVolume(0, &volume));
+ EXPECT_DOUBLE_EQ(0.0, volume);
+ EXPECT_TRUE(media_channel1_->GetOutputVolume(1, &volume));
+ EXPECT_DOUBLE_EQ(0.0, volume);
+ EXPECT_TRUE(media_channel1_->GetOutputVolume(2, &volume));
+ EXPECT_DOUBLE_EQ(0.0, volume);
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundle) {
+ Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, false);
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleSecure) {
+ Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), false, true);
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
+ Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, false);
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
+ Base::SendBundleToBundle(kAudioPts, arraysize(kAudioPts), true, true);
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
+ Base::DefaultMaxBitrateIsUnlimited();
+}
+
+TEST_F(VoiceChannelDoubleThreadTest, CanChangeMaxBitrate) {
+ Base::CanChangeMaxBitrate();
+}
+
+// VideoChannelSingleThreadTest
+TEST_F(VideoChannelSingleThreadTest, TestInit) {
+ Base::TestInit();
+}
+
+TEST_F(VideoChannelSingleThreadTest, TestSetContents) {
+ Base::TestSetContents();
+}
+
+TEST_F(VideoChannelSingleThreadTest, TestSetContentsNullOffer) {
+ Base::TestSetContentsNullOffer();
+}
+
+TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMux) {
+ Base::TestSetContentsRtcpMux();
+}
+
+TEST_F(VideoChannelSingleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
+ Base::TestSetContentsRtcpMux();
+}
+
+TEST_F(VideoChannelSingleThreadTest, TestSetRemoteContentUpdate) {
+ Base::TestSetRemoteContentUpdate();
+}
+
+TEST_F(VideoChannelSingleThreadTest, TestStreams) {
+ Base::TestStreams();
+}
+
+TEST_F(VideoChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
+ Base::TestUpdateStreamsInLocalContent();
+}
+
+TEST_F(VideoChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
+ Base::TestUpdateStreamsInRemoteContent();
+}
+
+TEST_F(VideoChannelSingleThreadTest, TestChangeStreamParamsInContent) {
+ Base::TestChangeStreamParamsInContent();
+}
+
+TEST_F(VideoChannelSingleThreadTest, TestPlayoutAndSendingStates) {
+ Base::TestPlayoutAndSendingStates();
+}
+
+TEST_F(VideoChannelSingleThreadTest, TestMuteStream) {
CreateChannels(0, 0);
// Test that we can Mute the default channel even though the sending SSRC
// is unknown.
@@ -2430,214 +2786,457 @@
EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
}
-TEST_F(VideoChannelTest, TestMediaContentDirection) {
+TEST_F(VideoChannelSingleThreadTest, TestMediaContentDirection) {
Base::TestMediaContentDirection();
}
-TEST_F(VideoChannelTest, TestNetworkRouteChanges) {
+TEST_F(VideoChannelSingleThreadTest, TestNetworkRouteChanges) {
Base::TestNetworkRouteChanges();
}
-TEST_F(VideoChannelTest, TestCallSetup) {
+TEST_F(VideoChannelSingleThreadTest, TestCallSetup) {
Base::TestCallSetup();
}
-TEST_F(VideoChannelTest, TestCallTeardownRtcpMux) {
+TEST_F(VideoChannelSingleThreadTest, TestCallTeardownRtcpMux) {
Base::TestCallTeardownRtcpMux();
}
-TEST_F(VideoChannelTest, SendRtpToRtp) {
+TEST_F(VideoChannelSingleThreadTest, SendRtpToRtp) {
Base::SendRtpToRtp();
}
-TEST_F(VideoChannelTest, SendNoRtcpToNoRtcp) {
+TEST_F(VideoChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
Base::SendNoRtcpToNoRtcp();
}
-TEST_F(VideoChannelTest, SendNoRtcpToRtcp) {
+TEST_F(VideoChannelSingleThreadTest, SendNoRtcpToRtcp) {
Base::SendNoRtcpToRtcp();
}
-TEST_F(VideoChannelTest, SendRtcpToNoRtcp) {
+TEST_F(VideoChannelSingleThreadTest, SendRtcpToNoRtcp) {
Base::SendRtcpToNoRtcp();
}
-TEST_F(VideoChannelTest, SendRtcpToRtcp) {
+TEST_F(VideoChannelSingleThreadTest, SendRtcpToRtcp) {
Base::SendRtcpToRtcp();
}
-TEST_F(VideoChannelTest, SendRtcpMuxToRtcp) {
+TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcp) {
Base::SendRtcpMuxToRtcp();
}
-TEST_F(VideoChannelTest, SendRtcpMuxToRtcpMux) {
+TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
Base::SendRtcpMuxToRtcpMux();
}
-TEST_F(VideoChannelTest, SendRequireRtcpMuxToRtcpMux) {
+TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRtcpMux) {
Base::SendRequireRtcpMuxToRtcpMux();
}
-TEST_F(VideoChannelTest, SendRtcpMuxToRequireRtcpMux) {
+TEST_F(VideoChannelSingleThreadTest, SendRtcpMuxToRequireRtcpMux) {
Base::SendRtcpMuxToRequireRtcpMux();
}
-TEST_F(VideoChannelTest, SendRequireRtcpMuxToRequireRtcpMux) {
+TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
Base::SendRequireRtcpMuxToRequireRtcpMux();
}
-TEST_F(VideoChannelTest, SendRequireRtcpMuxToNoRtcpMux) {
+TEST_F(VideoChannelSingleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
Base::SendRequireRtcpMuxToNoRtcpMux();
}
-TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcp) {
+TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
Base::SendEarlyRtcpMuxToRtcp();
}
-TEST_F(VideoChannelTest, SendEarlyRtcpMuxToRtcpMux) {
+TEST_F(VideoChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
Base::SendEarlyRtcpMuxToRtcpMux();
}
-TEST_F(VideoChannelTest, SendSrtpToSrtp) {
+TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtp) {
Base::SendSrtpToSrtp();
}
-TEST_F(VideoChannelTest, SendSrtpToRtp) {
+TEST_F(VideoChannelSingleThreadTest, SendSrtpToRtp) {
Base::SendSrtpToSrtp();
}
-TEST_F(VideoChannelTest, SendDtlsSrtpToSrtp) {
+TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToSrtp) {
MAYBE_SKIP_TEST(HaveDtlsSrtp);
Base::SendSrtpToSrtp(DTLS, 0);
}
-TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtp) {
+TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtp) {
MAYBE_SKIP_TEST(HaveDtlsSrtp);
Base::SendSrtpToSrtp(DTLS, DTLS);
}
-TEST_F(VideoChannelTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
+TEST_F(VideoChannelSingleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
MAYBE_SKIP_TEST(HaveDtlsSrtp);
Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
}
-TEST_F(VideoChannelTest, SendSrtcpMux) {
+TEST_F(VideoChannelSingleThreadTest, SendSrtcpMux) {
Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
}
-TEST_F(VideoChannelTest, SendEarlyMediaUsingRtcpMuxSrtp) {
+TEST_F(VideoChannelSingleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
Base::SendEarlyMediaUsingRtcpMuxSrtp();
}
-TEST_F(VideoChannelTest, SendRtpToRtpOnThread) {
+TEST_F(VideoChannelSingleThreadTest, SendRtpToRtpOnThread) {
Base::SendRtpToRtpOnThread();
}
-TEST_F(VideoChannelTest, SendSrtpToSrtpOnThread) {
+TEST_F(VideoChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
Base::SendSrtpToSrtpOnThread();
}
-TEST_F(VideoChannelTest, SendWithWritabilityLoss) {
+TEST_F(VideoChannelSingleThreadTest, SendWithWritabilityLoss) {
Base::SendWithWritabilityLoss();
}
-TEST_F(VideoChannelTest, TestMediaMonitor) {
+TEST_F(VideoChannelSingleThreadTest, TestMediaMonitor) {
Base::TestMediaMonitor();
}
-TEST_F(VideoChannelTest, TestSetContentFailure) {
+TEST_F(VideoChannelSingleThreadTest, TestSetContentFailure) {
Base::TestSetContentFailure();
}
-TEST_F(VideoChannelTest, TestSendTwoOffers) {
+TEST_F(VideoChannelSingleThreadTest, TestSendTwoOffers) {
Base::TestSendTwoOffers();
}
-TEST_F(VideoChannelTest, TestReceiveTwoOffers) {
+TEST_F(VideoChannelSingleThreadTest, TestReceiveTwoOffers) {
Base::TestReceiveTwoOffers();
}
-TEST_F(VideoChannelTest, TestSendPrAnswer) {
+TEST_F(VideoChannelSingleThreadTest, TestSendPrAnswer) {
Base::TestSendPrAnswer();
}
-TEST_F(VideoChannelTest, TestReceivePrAnswer) {
+TEST_F(VideoChannelSingleThreadTest, TestReceivePrAnswer) {
Base::TestReceivePrAnswer();
}
-TEST_F(VideoChannelTest, TestFlushRtcp) {
+TEST_F(VideoChannelSingleThreadTest, TestFlushRtcp) {
Base::TestFlushRtcp();
}
-TEST_F(VideoChannelTest, SendBundleToBundle) {
+TEST_F(VideoChannelSingleThreadTest, SendBundleToBundle) {
Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
}
-TEST_F(VideoChannelTest, SendBundleToBundleSecure) {
+TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleSecure) {
Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
}
-TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMux) {
+TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMux) {
Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
}
-TEST_F(VideoChannelTest, SendBundleToBundleWithRtcpMuxSecure) {
+TEST_F(VideoChannelSingleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
}
-TEST_F(VideoChannelTest, TestSrtpError) {
+TEST_F(VideoChannelSingleThreadTest, TestSrtpError) {
Base::TestSrtpError(kVideoPts[0]);
}
-TEST_F(VideoChannelTest, TestOnReadyToSend) {
+TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSend) {
Base::TestOnReadyToSend();
}
-TEST_F(VideoChannelTest, TestOnReadyToSendWithRtcpMux) {
+TEST_F(VideoChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
Base::TestOnReadyToSendWithRtcpMux();
}
-TEST_F(VideoChannelTest, DefaultMaxBitrateIsUnlimited) {
+TEST_F(VideoChannelSingleThreadTest, DefaultMaxBitrateIsUnlimited) {
Base::DefaultMaxBitrateIsUnlimited();
}
-TEST_F(VideoChannelTest, CanChangeMaxBitrate) {
+TEST_F(VideoChannelSingleThreadTest, CanChangeMaxBitrate) {
Base::CanChangeMaxBitrate();
}
-// DataChannelTest
+// VideoChannelDoubleThreadTest
+TEST_F(VideoChannelDoubleThreadTest, TestInit) {
+ Base::TestInit();
+}
-class DataChannelTest
- : public ChannelTest<DataTraits> {
+TEST_F(VideoChannelDoubleThreadTest, TestSetContents) {
+ Base::TestSetContents();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestSetContentsNullOffer) {
+ Base::TestSetContentsNullOffer();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMux) {
+ Base::TestSetContentsRtcpMux();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestSetContentsRtcpMuxWithPrAnswer) {
+ Base::TestSetContentsRtcpMux();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
+ Base::TestSetRemoteContentUpdate();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestStreams) {
+ Base::TestStreams();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
+ Base::TestUpdateStreamsInLocalContent();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
+ Base::TestUpdateStreamsInRemoteContent();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
+ Base::TestChangeStreamParamsInContent();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
+ Base::TestPlayoutAndSendingStates();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestMuteStream) {
+ CreateChannels(0, 0);
+ // Test that we can Mute the default channel even though the sending SSRC
+ // is unknown.
+ EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
+ EXPECT_TRUE(channel1_->SetVideoSend(0, false, nullptr));
+ EXPECT_TRUE(media_channel1_->IsStreamMuted(0));
+ EXPECT_TRUE(channel1_->SetVideoSend(0, true, nullptr));
+ EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
+ // Test that we can not mute an unknown SSRC.
+ EXPECT_FALSE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
+ SendInitiate();
+ // After the local session description has been set, we can mute a stream
+ // with its SSRC.
+ EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, false, nullptr));
+ EXPECT_TRUE(media_channel1_->IsStreamMuted(kSsrc1));
+ EXPECT_TRUE(channel1_->SetVideoSend(kSsrc1, true, nullptr));
+ EXPECT_FALSE(media_channel1_->IsStreamMuted(kSsrc1));
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestMediaContentDirection) {
+ Base::TestMediaContentDirection();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestNetworkRouteChanges) {
+ Base::TestNetworkRouteChanges();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestCallSetup) {
+ Base::TestCallSetup();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
+ Base::TestCallTeardownRtcpMux();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtp) {
+ Base::SendRtpToRtp();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
+ Base::SendNoRtcpToNoRtcp();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendNoRtcpToRtcp) {
+ Base::SendNoRtcpToRtcp();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendRtcpToNoRtcp) {
+ Base::SendRtcpToNoRtcp();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendRtcpToRtcp) {
+ Base::SendRtcpToRtcp();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
+ Base::SendRtcpMuxToRtcp();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
+ Base::SendRtcpMuxToRtcpMux();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRtcpMux) {
+ Base::SendRequireRtcpMuxToRtcpMux();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendRtcpMuxToRequireRtcpMux) {
+ Base::SendRtcpMuxToRequireRtcpMux();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToRequireRtcpMux) {
+ Base::SendRequireRtcpMuxToRequireRtcpMux();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendRequireRtcpMuxToNoRtcpMux) {
+ Base::SendRequireRtcpMuxToNoRtcpMux();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
+ Base::SendEarlyRtcpMuxToRtcp();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
+ Base::SendEarlyRtcpMuxToRtcpMux();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtp) {
+ Base::SendSrtpToSrtp();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendSrtpToRtp) {
+ Base::SendSrtpToSrtp();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToSrtp) {
+ MAYBE_SKIP_TEST(HaveDtlsSrtp);
+ Base::SendSrtpToSrtp(DTLS, 0);
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtp) {
+ MAYBE_SKIP_TEST(HaveDtlsSrtp);
+ Base::SendSrtpToSrtp(DTLS, DTLS);
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendDtlsSrtpToDtlsSrtpRtcpMux) {
+ MAYBE_SKIP_TEST(HaveDtlsSrtp);
+ Base::SendSrtpToSrtp(DTLS | RTCP_MUX, DTLS | RTCP_MUX);
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendSrtcpMux) {
+ Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendEarlyMediaUsingRtcpMuxSrtp) {
+ Base::SendEarlyMediaUsingRtcpMuxSrtp();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendRtpToRtpOnThread) {
+ Base::SendRtpToRtpOnThread();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
+ Base::SendSrtpToSrtpOnThread();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendWithWritabilityLoss) {
+ Base::SendWithWritabilityLoss();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestMediaMonitor) {
+ Base::TestMediaMonitor();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestSetContentFailure) {
+ Base::TestSetContentFailure();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestSendTwoOffers) {
+ Base::TestSendTwoOffers();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestReceiveTwoOffers) {
+ Base::TestReceiveTwoOffers();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestSendPrAnswer) {
+ Base::TestSendPrAnswer();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestReceivePrAnswer) {
+ Base::TestReceivePrAnswer();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestFlushRtcp) {
+ Base::TestFlushRtcp();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundle) {
+ Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, false);
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleSecure) {
+ Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), false, true);
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMux) {
+ Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, false);
+}
+
+TEST_F(VideoChannelDoubleThreadTest, SendBundleToBundleWithRtcpMuxSecure) {
+ Base::SendBundleToBundle(kVideoPts, arraysize(kVideoPts), true, true);
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestSrtpError) {
+ Base::TestSrtpError(kVideoPts[0]);
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSend) {
+ Base::TestOnReadyToSend();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
+ Base::TestOnReadyToSendWithRtcpMux();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, DefaultMaxBitrateIsUnlimited) {
+ Base::DefaultMaxBitrateIsUnlimited();
+}
+
+TEST_F(VideoChannelDoubleThreadTest, CanChangeMaxBitrate) {
+ Base::CanChangeMaxBitrate();
+}
+
+// DataChannelSingleThreadTest
+class DataChannelSingleThreadTest : public ChannelTest<DataTraits> {
public:
- typedef ChannelTest<DataTraits>
- Base;
- DataChannelTest()
- : Base(true,
- kDataPacket,
- sizeof(kDataPacket),
- kRtcpReport,
- sizeof(kRtcpReport)) {}
+ typedef ChannelTest<DataTraits> Base;
+ DataChannelSingleThreadTest()
+ : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::Yes) {}
+};
+
+// DataChannelDoubleThreadTest
+class DataChannelDoubleThreadTest : public ChannelTest<DataTraits> {
+ public:
+ typedef ChannelTest<DataTraits> Base;
+ DataChannelDoubleThreadTest()
+ : Base(true, kDataPacket, kRtcpReport, NetworkIsWorker::No) {}
};
// Override to avoid engine channel parameter.
template <>
cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
- rtc::Thread* thread,
+ rtc::Thread* worker_thread,
+ rtc::Thread* network_thread,
cricket::MediaEngineInterface* engine,
cricket::FakeDataMediaChannel* ch,
cricket::TransportController* transport_controller,
bool rtcp) {
- cricket::DataChannel* channel = new cricket::DataChannel(
- thread, ch, transport_controller, cricket::CN_DATA, rtcp);
- if (!channel->Init()) {
+ cricket::DataChannel* channel =
+ new cricket::DataChannel(worker_thread, network_thread, ch,
+ transport_controller, cricket::CN_DATA, rtcp);
+ if (!channel->Init_w()) {
delete channel;
channel = NULL;
}
return channel;
}
-template<>
+template <>
void ChannelTest<DataTraits>::CreateContent(
int flags,
const cricket::AudioCodec& audio_codec,
@@ -2652,14 +3251,14 @@
}
}
-template<>
+template <>
void ChannelTest<DataTraits>::CopyContent(
const cricket::DataContentDescription& source,
cricket::DataContentDescription* data) {
*data = source;
}
-template<>
+template <>
bool ChannelTest<DataTraits>::CodecMatches(const cricket::DataCodec& c1,
const cricket::DataCodec& c2) {
return c1.name == c2.name;
@@ -2673,132 +3272,272 @@
data->AddLegacyStream(ssrc);
}
-TEST_F(DataChannelTest, TestInit) {
+TEST_F(DataChannelSingleThreadTest, TestInit) {
Base::TestInit();
EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
}
-TEST_F(DataChannelTest, TestSetContents) {
+TEST_F(DataChannelSingleThreadTest, TestSetContents) {
Base::TestSetContents();
}
-TEST_F(DataChannelTest, TestSetContentsNullOffer) {
+TEST_F(DataChannelSingleThreadTest, TestSetContentsNullOffer) {
Base::TestSetContentsNullOffer();
}
-TEST_F(DataChannelTest, TestSetContentsRtcpMux) {
+TEST_F(DataChannelSingleThreadTest, TestSetContentsRtcpMux) {
Base::TestSetContentsRtcpMux();
}
-TEST_F(DataChannelTest, TestSetRemoteContentUpdate) {
+TEST_F(DataChannelSingleThreadTest, TestSetRemoteContentUpdate) {
Base::TestSetRemoteContentUpdate();
}
-TEST_F(DataChannelTest, TestStreams) {
+TEST_F(DataChannelSingleThreadTest, TestStreams) {
Base::TestStreams();
}
-TEST_F(DataChannelTest, TestUpdateStreamsInLocalContent) {
+TEST_F(DataChannelSingleThreadTest, TestUpdateStreamsInLocalContent) {
Base::TestUpdateStreamsInLocalContent();
}
-TEST_F(DataChannelTest, TestUpdateRemoteStreamsInContent) {
+TEST_F(DataChannelSingleThreadTest, TestUpdateRemoteStreamsInContent) {
Base::TestUpdateStreamsInRemoteContent();
}
-TEST_F(DataChannelTest, TestChangeStreamParamsInContent) {
+TEST_F(DataChannelSingleThreadTest, TestChangeStreamParamsInContent) {
Base::TestChangeStreamParamsInContent();
}
-TEST_F(DataChannelTest, TestPlayoutAndSendingStates) {
+TEST_F(DataChannelSingleThreadTest, TestPlayoutAndSendingStates) {
Base::TestPlayoutAndSendingStates();
}
-TEST_F(DataChannelTest, TestMediaContentDirection) {
+TEST_F(DataChannelSingleThreadTest, TestMediaContentDirection) {
Base::TestMediaContentDirection();
}
-TEST_F(DataChannelTest, TestCallSetup) {
+TEST_F(DataChannelSingleThreadTest, TestCallSetup) {
Base::TestCallSetup();
}
-TEST_F(DataChannelTest, TestCallTeardownRtcpMux) {
+TEST_F(DataChannelSingleThreadTest, TestCallTeardownRtcpMux) {
Base::TestCallTeardownRtcpMux();
}
-TEST_F(DataChannelTest, TestOnReadyToSend) {
+TEST_F(DataChannelSingleThreadTest, TestOnReadyToSend) {
Base::TestOnReadyToSend();
}
-TEST_F(DataChannelTest, TestOnReadyToSendWithRtcpMux) {
+TEST_F(DataChannelSingleThreadTest, TestOnReadyToSendWithRtcpMux) {
Base::TestOnReadyToSendWithRtcpMux();
}
-TEST_F(DataChannelTest, SendRtpToRtp) {
+TEST_F(DataChannelSingleThreadTest, SendRtpToRtp) {
Base::SendRtpToRtp();
}
-TEST_F(DataChannelTest, SendNoRtcpToNoRtcp) {
+TEST_F(DataChannelSingleThreadTest, SendNoRtcpToNoRtcp) {
Base::SendNoRtcpToNoRtcp();
}
-TEST_F(DataChannelTest, SendNoRtcpToRtcp) {
+TEST_F(DataChannelSingleThreadTest, SendNoRtcpToRtcp) {
Base::SendNoRtcpToRtcp();
}
-TEST_F(DataChannelTest, SendRtcpToNoRtcp) {
+TEST_F(DataChannelSingleThreadTest, SendRtcpToNoRtcp) {
Base::SendRtcpToNoRtcp();
}
-TEST_F(DataChannelTest, SendRtcpToRtcp) {
+TEST_F(DataChannelSingleThreadTest, SendRtcpToRtcp) {
Base::SendRtcpToRtcp();
}
-TEST_F(DataChannelTest, SendRtcpMuxToRtcp) {
+TEST_F(DataChannelSingleThreadTest, SendRtcpMuxToRtcp) {
Base::SendRtcpMuxToRtcp();
}
-TEST_F(DataChannelTest, SendRtcpMuxToRtcpMux) {
+TEST_F(DataChannelSingleThreadTest, SendRtcpMuxToRtcpMux) {
Base::SendRtcpMuxToRtcpMux();
}
-TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcp) {
+TEST_F(DataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcp) {
Base::SendEarlyRtcpMuxToRtcp();
}
-TEST_F(DataChannelTest, SendEarlyRtcpMuxToRtcpMux) {
+TEST_F(DataChannelSingleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
Base::SendEarlyRtcpMuxToRtcpMux();
}
-TEST_F(DataChannelTest, SendSrtpToSrtp) {
+TEST_F(DataChannelSingleThreadTest, SendSrtpToSrtp) {
Base::SendSrtpToSrtp();
}
-TEST_F(DataChannelTest, SendSrtpToRtp) {
+TEST_F(DataChannelSingleThreadTest, SendSrtpToRtp) {
Base::SendSrtpToSrtp();
}
-TEST_F(DataChannelTest, SendSrtcpMux) {
+TEST_F(DataChannelSingleThreadTest, SendSrtcpMux) {
Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
}
-TEST_F(DataChannelTest, SendRtpToRtpOnThread) {
+TEST_F(DataChannelSingleThreadTest, SendRtpToRtpOnThread) {
Base::SendRtpToRtpOnThread();
}
-TEST_F(DataChannelTest, SendSrtpToSrtpOnThread) {
+TEST_F(DataChannelSingleThreadTest, SendSrtpToSrtpOnThread) {
Base::SendSrtpToSrtpOnThread();
}
-TEST_F(DataChannelTest, SendWithWritabilityLoss) {
+TEST_F(DataChannelSingleThreadTest, SendWithWritabilityLoss) {
Base::SendWithWritabilityLoss();
}
-TEST_F(DataChannelTest, TestMediaMonitor) {
+TEST_F(DataChannelSingleThreadTest, TestMediaMonitor) {
Base::TestMediaMonitor();
}
-TEST_F(DataChannelTest, TestSendData) {
+TEST_F(DataChannelSingleThreadTest, TestSendData) {
+ CreateChannels(0, 0);
+ EXPECT_TRUE(SendInitiate());
+ EXPECT_TRUE(SendAccept());
+
+ cricket::SendDataParams params;
+ params.ssrc = 42;
+ unsigned char data[] = {'f', 'o', 'o'};
+ rtc::CopyOnWriteBuffer payload(data, 3);
+ cricket::SendDataResult result;
+ ASSERT_TRUE(media_channel1_->SendData(params, payload, &result));
+ EXPECT_EQ(params.ssrc, media_channel1_->last_sent_data_params().ssrc);
+ EXPECT_EQ("foo", media_channel1_->last_sent_data());
+}
+
+TEST_F(DataChannelDoubleThreadTest, TestInit) {
+ Base::TestInit();
+ EXPECT_FALSE(media_channel1_->IsStreamMuted(0));
+}
+
+TEST_F(DataChannelDoubleThreadTest, TestSetContents) {
+ Base::TestSetContents();
+}
+
+TEST_F(DataChannelDoubleThreadTest, TestSetContentsNullOffer) {
+ Base::TestSetContentsNullOffer();
+}
+
+TEST_F(DataChannelDoubleThreadTest, TestSetContentsRtcpMux) {
+ Base::TestSetContentsRtcpMux();
+}
+
+TEST_F(DataChannelDoubleThreadTest, TestSetRemoteContentUpdate) {
+ Base::TestSetRemoteContentUpdate();
+}
+
+TEST_F(DataChannelDoubleThreadTest, TestStreams) {
+ Base::TestStreams();
+}
+
+TEST_F(DataChannelDoubleThreadTest, TestUpdateStreamsInLocalContent) {
+ Base::TestUpdateStreamsInLocalContent();
+}
+
+TEST_F(DataChannelDoubleThreadTest, TestUpdateRemoteStreamsInContent) {
+ Base::TestUpdateStreamsInRemoteContent();
+}
+
+TEST_F(DataChannelDoubleThreadTest, TestChangeStreamParamsInContent) {
+ Base::TestChangeStreamParamsInContent();
+}
+
+TEST_F(DataChannelDoubleThreadTest, TestPlayoutAndSendingStates) {
+ Base::TestPlayoutAndSendingStates();
+}
+
+TEST_F(DataChannelDoubleThreadTest, TestMediaContentDirection) {
+ Base::TestMediaContentDirection();
+}
+
+TEST_F(DataChannelDoubleThreadTest, TestCallSetup) {
+ Base::TestCallSetup();
+}
+
+TEST_F(DataChannelDoubleThreadTest, TestCallTeardownRtcpMux) {
+ Base::TestCallTeardownRtcpMux();
+}
+
+TEST_F(DataChannelDoubleThreadTest, TestOnReadyToSend) {
+ Base::TestOnReadyToSend();
+}
+
+TEST_F(DataChannelDoubleThreadTest, TestOnReadyToSendWithRtcpMux) {
+ Base::TestOnReadyToSendWithRtcpMux();
+}
+
+TEST_F(DataChannelDoubleThreadTest, SendRtpToRtp) {
+ Base::SendRtpToRtp();
+}
+
+TEST_F(DataChannelDoubleThreadTest, SendNoRtcpToNoRtcp) {
+ Base::SendNoRtcpToNoRtcp();
+}
+
+TEST_F(DataChannelDoubleThreadTest, SendNoRtcpToRtcp) {
+ Base::SendNoRtcpToRtcp();
+}
+
+TEST_F(DataChannelDoubleThreadTest, SendRtcpToNoRtcp) {
+ Base::SendRtcpToNoRtcp();
+}
+
+TEST_F(DataChannelDoubleThreadTest, SendRtcpToRtcp) {
+ Base::SendRtcpToRtcp();
+}
+
+TEST_F(DataChannelDoubleThreadTest, SendRtcpMuxToRtcp) {
+ Base::SendRtcpMuxToRtcp();
+}
+
+TEST_F(DataChannelDoubleThreadTest, SendRtcpMuxToRtcpMux) {
+ Base::SendRtcpMuxToRtcpMux();
+}
+
+TEST_F(DataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcp) {
+ Base::SendEarlyRtcpMuxToRtcp();
+}
+
+TEST_F(DataChannelDoubleThreadTest, SendEarlyRtcpMuxToRtcpMux) {
+ Base::SendEarlyRtcpMuxToRtcpMux();
+}
+
+TEST_F(DataChannelDoubleThreadTest, SendSrtpToSrtp) {
+ Base::SendSrtpToSrtp();
+}
+
+TEST_F(DataChannelDoubleThreadTest, SendSrtpToRtp) {
+ Base::SendSrtpToSrtp();
+}
+
+TEST_F(DataChannelDoubleThreadTest, SendSrtcpMux) {
+ Base::SendSrtpToSrtp(RTCP_MUX, RTCP_MUX);
+}
+
+TEST_F(DataChannelDoubleThreadTest, SendRtpToRtpOnThread) {
+ Base::SendRtpToRtpOnThread();
+}
+
+TEST_F(DataChannelDoubleThreadTest, SendSrtpToSrtpOnThread) {
+ Base::SendSrtpToSrtpOnThread();
+}
+
+TEST_F(DataChannelDoubleThreadTest, SendWithWritabilityLoss) {
+ Base::SendWithWritabilityLoss();
+}
+
+TEST_F(DataChannelDoubleThreadTest, TestMediaMonitor) {
+ Base::TestMediaMonitor();
+}
+
+TEST_F(DataChannelDoubleThreadTest, TestSendData) {
CreateChannels(0, 0);
EXPECT_TRUE(SendInitiate());
EXPECT_TRUE(SendAccept());
diff --git a/webrtc/pc/channelmanager.cc b/webrtc/pc/channelmanager.cc
index f59a3df..6800d83 100644
--- a/webrtc/pc/channelmanager.cc
+++ b/webrtc/pc/channelmanager.cc
@@ -44,25 +44,26 @@
ChannelManager::ChannelManager(MediaEngineInterface* me,
DataEngineInterface* dme,
- rtc::Thread* worker_thread) {
- Construct(me, dme, worker_thread);
+ rtc::Thread* thread) {
+ Construct(me, dme, thread, thread);
}
ChannelManager::ChannelManager(MediaEngineInterface* me,
- rtc::Thread* worker_thread) {
- Construct(me,
- ConstructDataEngine(),
- worker_thread);
+ rtc::Thread* worker_thread,
+ rtc::Thread* network_thread) {
+ Construct(me, ConstructDataEngine(), worker_thread, network_thread);
}
void ChannelManager::Construct(MediaEngineInterface* me,
DataEngineInterface* dme,
- rtc::Thread* worker_thread) {
+ rtc::Thread* worker_thread,
+ rtc::Thread* network_thread) {
media_engine_.reset(me);
data_media_engine_.reset(dme);
initialized_ = false;
main_thread_ = rtc::Thread::Current();
worker_thread_ = worker_thread;
+ network_thread_ = network_thread;
audio_output_volume_ = kNotSetOutputVolume;
capturing_ = false;
enable_rtx_ = false;
@@ -144,18 +145,16 @@
if (initialized_) {
return false;
}
- ASSERT(worker_thread_ != NULL);
- if (!worker_thread_) {
- return false;
- }
- if (worker_thread_ != rtc::Thread::Current()) {
- // Do not allow invoking calls to other threads on the worker thread.
- worker_thread_->Invoke<bool>(rtc::Bind(
- &rtc::Thread::SetAllowBlockingCalls, worker_thread_, false));
+ RTC_DCHECK(network_thread_);
+ RTC_DCHECK(worker_thread_);
+ if (!network_thread_->IsCurrent()) {
+ // Do not allow invoking calls to other threads on the network thread.
+ network_thread_->Invoke<bool>(
+ rtc::Bind(&rtc::Thread::SetAllowBlockingCalls, network_thread_, false));
}
- initialized_ = worker_thread_->Invoke<bool>(Bind(
- &ChannelManager::InitMediaEngine_w, this));
+ initialized_ = worker_thread_->Invoke<bool>(
+ Bind(&ChannelManager::InitMediaEngine_w, this));
ASSERT(initialized_);
if (!initialized_) {
return false;
@@ -228,9 +227,9 @@
return nullptr;
VoiceChannel* voice_channel =
- new VoiceChannel(worker_thread_, media_engine_.get(), media_channel,
- transport_controller, content_name, rtcp);
- if (!voice_channel->Init()) {
+ new VoiceChannel(worker_thread_, network_thread_, media_engine_.get(),
+ media_channel, transport_controller, content_name, rtcp);
+ if (!voice_channel->Init_w()) {
delete voice_channel;
return nullptr;
}
@@ -286,9 +285,10 @@
return NULL;
}
- VideoChannel* video_channel = new VideoChannel(
- worker_thread_, media_channel, transport_controller, content_name, rtcp);
- if (!video_channel->Init()) {
+ VideoChannel* video_channel =
+ new VideoChannel(worker_thread_, network_thread_, media_channel,
+ transport_controller, content_name, rtcp);
+ if (!video_channel->Init_w()) {
delete video_channel;
return NULL;
}
@@ -344,9 +344,10 @@
return NULL;
}
- DataChannel* data_channel = new DataChannel(
- worker_thread_, media_channel, transport_controller, content_name, rtcp);
- if (!data_channel->Init()) {
+ DataChannel* data_channel =
+ new DataChannel(worker_thread_, network_thread_, media_channel,
+ transport_controller, content_name, rtcp);
+ if (!data_channel->Init_w()) {
LOG(LS_WARNING) << "Failed to init data channel.";
delete data_channel;
return NULL;
diff --git a/webrtc/pc/channelmanager.h b/webrtc/pc/channelmanager.h
index 72a2f05..1ecebf8 100644
--- a/webrtc/pc/channelmanager.h
+++ b/webrtc/pc/channelmanager.h
@@ -42,20 +42,31 @@
// ownership of these objects.
ChannelManager(MediaEngineInterface* me,
DataEngineInterface* dme,
- rtc::Thread* worker);
+ rtc::Thread* worker_and_network);
// Same as above, but gives an easier default DataEngine.
ChannelManager(MediaEngineInterface* me,
- rtc::Thread* worker);
+ rtc::Thread* worker,
+ rtc::Thread* network);
~ChannelManager();
// Accessors for the worker thread, allowing it to be set after construction,
// but before Init. set_worker_thread will return false if called after Init.
rtc::Thread* worker_thread() const { return worker_thread_; }
bool set_worker_thread(rtc::Thread* thread) {
- if (initialized_) return false;
+ if (initialized_) {
+ return false;
+ }
worker_thread_ = thread;
return true;
}
+ rtc::Thread* network_thread() const { return network_thread_; }
+ bool set_network_thread(rtc::Thread* thread) {
+ if (initialized_) {
+ return false;
+ }
+ network_thread_ = thread;
+ return true;
+ }
MediaEngineInterface* media_engine() { return media_engine_.get(); }
@@ -138,7 +149,8 @@
void Construct(MediaEngineInterface* me,
DataEngineInterface* dme,
- rtc::Thread* worker_thread);
+ rtc::Thread* worker_thread,
+ rtc::Thread* network_thread);
bool InitMediaEngine_w();
void DestructorDeletes_w();
void Terminate_w();
@@ -167,6 +179,7 @@
bool initialized_;
rtc::Thread* main_thread_;
rtc::Thread* worker_thread_;
+ rtc::Thread* network_thread_;
VoiceChannels voice_channels_;
VideoChannels video_channels_;
diff --git a/webrtc/pc/channelmanager_unittest.cc b/webrtc/pc/channelmanager_unittest.cc
index 8cb066b..0cedd8b 100644
--- a/webrtc/pc/channelmanager_unittest.cc
+++ b/webrtc/pc/channelmanager_unittest.cc
@@ -56,6 +56,7 @@
fme_ = NULL;
}
+ rtc::Thread network_;
rtc::Thread worker_;
cricket::FakeMediaEngine* fme_;
cricket::FakeDataEngine* fdme_;
@@ -77,14 +78,18 @@
// Test that we startup/shutdown properly with a worker thread.
TEST_F(ChannelManagerTest, StartupShutdownOnThread) {
+ network_.Start();
worker_.Start();
EXPECT_FALSE(cm_->initialized());
EXPECT_EQ(rtc::Thread::Current(), cm_->worker_thread());
+ EXPECT_TRUE(cm_->set_network_thread(&network_));
+ EXPECT_EQ(&network_, cm_->network_thread());
EXPECT_TRUE(cm_->set_worker_thread(&worker_));
EXPECT_EQ(&worker_, cm_->worker_thread());
EXPECT_TRUE(cm_->Init());
EXPECT_TRUE(cm_->initialized());
- // Setting the worker thread while initialized should fail.
+ // Setting the network or worker thread while initialized should fail.
+ EXPECT_FALSE(cm_->set_network_thread(rtc::Thread::Current()));
EXPECT_FALSE(cm_->set_worker_thread(rtc::Thread::Current()));
cm_->Terminate();
EXPECT_FALSE(cm_->initialized());
@@ -112,12 +117,14 @@
// Test that we can create and destroy a voice and video channel with a worker.
TEST_F(ChannelManagerTest, CreateDestroyChannelsOnThread) {
+ network_.Start();
worker_.Start();
EXPECT_TRUE(cm_->set_worker_thread(&worker_));
+ EXPECT_TRUE(cm_->set_network_thread(&network_));
EXPECT_TRUE(cm_->Init());
delete transport_controller_;
transport_controller_ =
- new cricket::FakeTransportController(&worker_, ICEROLE_CONTROLLING);
+ new cricket::FakeTransportController(&network_, ICEROLE_CONTROLLING);
cricket::VoiceChannel* voice_channel =
cm_->CreateVoiceChannel(&fake_mc_, transport_controller_,
cricket::CN_AUDIO, false, AudioOptions());