Reland of TransportController refactoring. (patchset #1 id:1 of https://codereview.webrtc.org/1358413003/ )
Reason for revert:
This CL just landed: https://codereview.chromium.org/1323243006/
Which fixes the FYI bots for the original CL, and breaks them for this revert.
Original issue's description:
> Revert of TransportController refactoring. (patchset #6 id:100001 of https://codereview.webrtc.org/1350523003/ )
>
> Reason for revert:
> This CL causes problems with the WebRTC-in-Chromium FYI bots. Presumably it needs to be done in several steps, where removed files are emptied instead of removed in the first step.
>
> Original issue's description:
> > TransportController refactoring.
> >
> > Getting rid of TransportProxy, and in its place adding a
> > TransportController class which will facilitate access to and manage
> > the lifetimes of Transports. These Transports will now be accessed
> > solely from the worker thread, simplifying their implementation.
> >
> > This refactoring also pulls Transport-related code out of BaseSession.
> > Which means that BaseChannels will now rely on the TransportController
> > interface to create channels, rather than BaseSession.
> >
> > Committed: https://crrev.com/47ee2f3b9f33e8938948c482c921d4e13a3acd83
> > Cr-Commit-Position: refs/heads/master@{#10022}
>
> TBR=pthatcher@webrtc.org,deadbeef@webrtc.org
> NOPRESUBMIT=true
> NOTREECHECKS=true
> NOTRY=true
>
> Committed: https://crrev.com/a81a42f584baa0d93a4b93da9632415e8922450c
> Cr-Commit-Position: refs/heads/master@{#10024}
TBR=pthatcher@webrtc.org,torbjorng@webrtc.org
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Review URL: https://codereview.webrtc.org/1361773005
Cr-Commit-Position: refs/heads/master@{#10036}
diff --git a/talk/session/media/channel.cc b/talk/session/media/channel.cc
index 3c5b9dd..1405c55 100644
--- a/talk/session/media/channel.cc
+++ b/talk/session/media/channel.cc
@@ -170,15 +170,17 @@
}
BaseChannel::BaseChannel(rtc::Thread* thread,
- MediaChannel* media_channel, BaseSession* session,
- const std::string& content_name, bool rtcp)
+ MediaChannel* media_channel,
+ TransportController* transport_controller,
+ const std::string& content_name,
+ bool rtcp)
: worker_thread_(thread),
- session_(session),
+ transport_controller_(transport_controller),
media_channel_(media_channel),
content_name_(content_name),
- rtcp_(rtcp),
- transport_channel_(NULL),
- rtcp_transport_channel_(NULL),
+ rtcp_transport_enabled_(rtcp),
+ transport_channel_(nullptr),
+ rtcp_transport_channel_(nullptr),
enabled_(false),
writable_(false),
rtp_ready_to_send_(false),
@@ -204,20 +206,31 @@
// 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_;
- set_transport_channel(nullptr);
- set_rtcp_transport_channel(nullptr);
+ // Note that we don't just call set_transport_channel(nullptr) because that
+ // would call a pure virtual method which we can't do from a destructor.
+ if (transport_channel_) {
+ DisconnectFromTransportChannel(transport_channel_);
+ transport_controller_->DestroyTransportChannel_w(
+ transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP);
+ }
+ if (rtcp_transport_channel_) {
+ DisconnectFromTransportChannel(rtcp_transport_channel_);
+ transport_controller_->DestroyTransportChannel_w(
+ transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP);
+ }
LOG(LS_INFO) << "Destroyed channel";
}
bool BaseChannel::Init() {
- if (!SetTransportChannels(session(), rtcp())) {
+ if (!SetTransport(content_name())) {
return false;
}
if (!SetDtlsSrtpCiphers(transport_channel(), false)) {
return false;
}
- if (rtcp() && !SetDtlsSrtpCiphers(rtcp_transport_channel(), true)) {
+ if (rtcp_transport_enabled() &&
+ !SetDtlsSrtpCiphers(rtcp_transport_channel(), true)) {
return false;
}
@@ -231,29 +244,35 @@
media_channel_->SetInterface(NULL);
}
-bool BaseChannel::SetTransportChannels(BaseSession* session, bool rtcp) {
- return worker_thread_->Invoke<bool>(Bind(
- &BaseChannel::SetTransportChannels_w, this, session, rtcp));
+bool BaseChannel::SetTransport(const std::string& transport_name) {
+ return worker_thread_->Invoke<bool>(
+ Bind(&BaseChannel::SetTransport_w, this, transport_name));
}
-bool BaseChannel::SetTransportChannels_w(BaseSession* session, bool rtcp) {
+bool BaseChannel::SetTransport_w(const std::string& transport_name) {
ASSERT(worker_thread_ == rtc::Thread::Current());
- set_transport_channel(session->CreateChannel(
- content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP));
+ if (transport_name == transport_name_) {
+ // Nothing to do if transport name isn't changing
+ return true;
+ }
+
+ set_transport_channel(transport_controller_->CreateTransportChannel_w(
+ transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTP));
if (!transport_channel()) {
return false;
}
- if (rtcp) {
- set_rtcp_transport_channel(session->CreateChannel(
- content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP));
+ if (rtcp_transport_enabled()) {
+ LOG(LS_INFO) << "Create RTCP TransportChannel for " << content_name()
+ << " on " << transport_name << " transport ";
+ set_rtcp_transport_channel(transport_controller_->CreateTransportChannel_w(
+ transport_name, cricket::ICE_CANDIDATE_COMPONENT_RTCP));
if (!rtcp_transport_channel()) {
return false;
}
- } else {
- set_rtcp_transport_channel(nullptr);
}
+ transport_name_ = transport_name;
return true;
}
@@ -261,42 +280,62 @@
ASSERT(worker_thread_ == rtc::Thread::Current());
TransportChannel* old_tc = transport_channel_;
-
- if (old_tc == new_tc) {
+ if (!old_tc && !new_tc) {
+ // Nothing to do
return;
}
+ ASSERT(old_tc != new_tc);
+
if (old_tc) {
DisconnectFromTransportChannel(old_tc);
- session()->DestroyChannel(
- content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTP);
+ transport_controller_->DestroyTransportChannel_w(
+ transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTP);
}
transport_channel_ = new_tc;
if (new_tc) {
ConnectToTransportChannel(new_tc);
+ for (const auto& pair : socket_options_) {
+ new_tc->SetOption(pair.first, pair.second);
+ }
}
+
+ // Update aggregate writable/ready-to-send state between RTP and RTCP upon
+ // setting new channel
+ UpdateWritableState_w();
+ SetReadyToSend(false, new_tc && new_tc->writable());
}
void BaseChannel::set_rtcp_transport_channel(TransportChannel* new_tc) {
ASSERT(worker_thread_ == rtc::Thread::Current());
TransportChannel* old_tc = rtcp_transport_channel_;
-
- if (old_tc == new_tc) {
+ if (!old_tc && !new_tc) {
+ // Nothing to do
return;
}
+ ASSERT(old_tc != new_tc);
+
if (old_tc) {
DisconnectFromTransportChannel(old_tc);
- session()->DestroyChannel(
- content_name(), cricket::ICE_CANDIDATE_COMPONENT_RTCP);
+ transport_controller_->DestroyTransportChannel_w(
+ transport_name_, cricket::ICE_CANDIDATE_COMPONENT_RTCP);
}
rtcp_transport_channel_ = new_tc;
if (new_tc) {
ConnectToTransportChannel(new_tc);
+ for (const auto& pair : rtcp_socket_options_) {
+ new_tc->SetOption(pair.first, pair.second);
+ }
}
+
+ // Update aggregate writable/ready-to-send state between RTP and RTCP upon
+ // setting new channel
+ UpdateWritableState_w();
+ SetReadyToSend(true, new_tc && new_tc->writable());
}
void BaseChannel::ConnectToTransportChannel(TransportChannel* tc) {
@@ -407,9 +446,13 @@
switch (type) {
case ST_RTP:
channel = transport_channel_;
+ socket_options_.push_back(
+ std::pair<rtc::Socket::Option, int>(opt, value));
break;
case ST_RTCP:
channel = rtcp_transport_channel_;
+ rtcp_socket_options_.push_back(
+ std::pair<rtc::Socket::Option, int>(opt, value));
break;
}
return channel ? channel->SetOption(opt, value) : -1;
@@ -417,12 +460,7 @@
void BaseChannel::OnWritableState(TransportChannel* channel) {
ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_);
- if (transport_channel_->writable()
- && (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) {
- ChannelWritable_w();
- } else {
- ChannelNotWritable_w();
- }
+ UpdateWritableState_w();
}
void BaseChannel::OnChannelRead(TransportChannel* channel,
@@ -440,26 +478,25 @@
}
void BaseChannel::OnReadyToSend(TransportChannel* channel) {
- SetReadyToSend(channel, true);
+ ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_);
+ SetReadyToSend(channel == rtcp_transport_channel_, true);
}
-void BaseChannel::SetReadyToSend(TransportChannel* channel, bool ready) {
- ASSERT(channel == transport_channel_ || channel == rtcp_transport_channel_);
- if (channel == transport_channel_) {
+void BaseChannel::SetReadyToSend(bool rtcp, bool ready) {
+ if (rtcp) {
+ rtcp_ready_to_send_ = ready;
+ } else {
rtp_ready_to_send_ = ready;
}
- if (channel == rtcp_transport_channel_) {
- rtcp_ready_to_send_ = ready;
- }
- if (!ready) {
- // Notify the MediaChannel when either rtp or rtcp channel can't send.
- media_channel_->OnReadyToSend(false);
- } else if (rtp_ready_to_send_ &&
- // In the case of rtcp mux |rtcp_transport_channel_| will be null.
- (rtcp_ready_to_send_ || !rtcp_transport_channel_)) {
+ 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);
}
}
@@ -581,7 +618,7 @@
if (ret != static_cast<int>(packet->size())) {
if (channel->GetError() == EWOULDBLOCK) {
LOG(LS_WARNING) << "Got EWOULDBLOCK from socket.";
- SetReadyToSend(channel, false);
+ SetReadyToSend(rtcp, false);
}
return false;
}
@@ -715,14 +752,21 @@
ChangeState();
}
+void BaseChannel::UpdateWritableState_w() {
+ if (transport_channel_ && transport_channel_->writable() &&
+ (!rtcp_transport_channel_ || rtcp_transport_channel_->writable())) {
+ ChannelWritable_w();
+ } else {
+ ChannelNotWritable_w();
+ }
+}
+
void BaseChannel::ChannelWritable_w() {
ASSERT(worker_thread_ == rtc::Thread::Current());
if (writable_)
return;
- LOG(LS_INFO) << "Channel socket writable ("
- << transport_channel_->content_name() << ", "
- << transport_channel_->component() << ")"
+ LOG(LS_INFO) << "Channel writable (" << content_name_ << ")"
<< (was_ever_writable_ ? "" : " for the first time");
std::vector<ConnectionInfo> infos;
@@ -739,13 +783,13 @@
// If we're doing DTLS-SRTP, now is the time.
if (!was_ever_writable_ && ShouldSetupDtlsSrtp()) {
if (!SetupDtlsSrtp(false)) {
- SignalDtlsSetupFailure(this, false);
+ SignalDtlsSetupFailure_w(false);
return;
}
if (rtcp_transport_channel_) {
if (!SetupDtlsSrtp(true)) {
- SignalDtlsSetupFailure(this, true);
+ SignalDtlsSetupFailure_w(true);
return;
}
}
@@ -788,8 +832,8 @@
bool BaseChannel::SetupDtlsSrtp(bool rtcp_channel) {
bool ret = false;
- TransportChannel *channel = rtcp_channel ?
- rtcp_transport_channel_ : transport_channel_;
+ TransportChannel* channel =
+ rtcp_channel ? rtcp_transport_channel_ : transport_channel_;
// No DTLS
if (!channel->IsDtlsActive())
@@ -884,9 +928,7 @@
if (!writable_)
return;
- LOG(LS_INFO) << "Channel socket not writable ("
- << transport_channel_->content_name() << ", "
- << transport_channel_->component() << ")";
+ LOG(LS_INFO) << "Channel not writable (" << content_name_ << ")";
writable_ = false;
ChangeState();
}
@@ -985,7 +1027,8 @@
void BaseChannel::ActivateRtcpMux_w() {
if (!rtcp_mux_filter_.IsActive()) {
rtcp_mux_filter_.SetActive();
- set_rtcp_transport_channel(NULL);
+ set_rtcp_transport_channel(nullptr);
+ rtcp_transport_enabled_ = false;
}
}
@@ -1004,7 +1047,11 @@
ret = rtcp_mux_filter_.SetAnswer(enable, src);
if (ret && rtcp_mux_filter_.IsActive()) {
// We activated RTCP mux, close down the RTCP transport.
- set_rtcp_transport_channel(NULL);
+ LOG(LS_INFO) << "Enabling rtcp-mux for " << content_name()
+ << " by destroying RTCP transport channel for "
+ << transport_name();
+ set_rtcp_transport_channel(nullptr);
+ rtcp_transport_enabled_ = false;
}
break;
case CA_UPDATE:
@@ -1231,14 +1278,16 @@
VoiceChannel::VoiceChannel(rtc::Thread* thread,
MediaEngineInterface* media_engine,
VoiceMediaChannel* media_channel,
- BaseSession* session,
+ TransportController* transport_controller,
const std::string& content_name,
bool rtcp)
- : BaseChannel(thread, media_channel, session, content_name,
+ : BaseChannel(thread,
+ media_channel,
+ transport_controller,
+ content_name,
rtcp),
media_engine_(media_engine),
- received_media_(false) {
-}
+ received_media_(false) {}
VoiceChannel::~VoiceChannel() {
StopAudioMonitor();
@@ -1264,11 +1313,12 @@
media_channel(), ssrc, renderer));
}
-bool VoiceChannel::SetAudioSend(uint32 ssrc, bool mute,
+bool VoiceChannel::SetAudioSend(uint32 ssrc,
+ bool mute,
const AudioOptions* options,
AudioRenderer* renderer) {
- return InvokeOnWorker(Bind(&VoiceMediaChannel::SetAudioSend,
- media_channel(), ssrc, mute, options, renderer));
+ return InvokeOnWorker(Bind(&VoiceMediaChannel::SetAudioSend, media_channel(),
+ ssrc, mute, options, renderer));
}
// TODO(juberti): Handle early media the right way. We should get an explicit
@@ -1583,14 +1633,16 @@
VideoChannel::VideoChannel(rtc::Thread* thread,
VideoMediaChannel* media_channel,
- BaseSession* session,
+ TransportController* transport_controller,
const std::string& content_name,
bool rtcp)
- : BaseChannel(thread, media_channel, session, content_name,
+ : BaseChannel(thread,
+ media_channel,
+ transport_controller,
+ content_name,
rtcp),
renderer_(NULL),
- previous_we_(rtc::WE_CLOSE) {
-}
+ previous_we_(rtc::WE_CLOSE) {}
bool VideoChannel::Init() {
if (!BaseChannel::Init()) {
@@ -1683,10 +1735,11 @@
return true;
}
-bool VideoChannel::SetVideoSend(uint32 ssrc, bool mute,
+bool VideoChannel::SetVideoSend(uint32 ssrc,
+ bool mute,
const VideoOptions* options) {
- return InvokeOnWorker(Bind(&VideoMediaChannel::SetVideoSend,
- media_channel(), ssrc, mute, options));
+ return InvokeOnWorker(Bind(&VideoMediaChannel::SetVideoSend, media_channel(),
+ ssrc, mute, options));
}
void VideoChannel::ChangeState() {
@@ -2021,13 +2074,16 @@
DataChannel::DataChannel(rtc::Thread* thread,
DataMediaChannel* media_channel,
- BaseSession* session,
+ TransportController* transport_controller,
const std::string& content_name,
bool rtcp)
- : BaseChannel(thread, media_channel, session, content_name, rtcp),
+ : BaseChannel(thread,
+ media_channel,
+ transport_controller,
+ content_name,
+ rtcp),
data_channel_type_(cricket::DCT_NONE),
- ready_to_send_data_(false) {
-}
+ ready_to_send_data_(false) {}
DataChannel::~DataChannel() {
StopMediaMonitor();
diff --git a/talk/session/media/channel.h b/talk/session/media/channel.h
index ec35f4c..0a7ce9d1 100644
--- a/talk/session/media/channel.h
+++ b/talk/session/media/channel.h
@@ -30,12 +30,15 @@
#include <string>
#include <vector>
+#include <map>
+#include <set>
+#include <utility>
#include "talk/media/base/mediachannel.h"
#include "talk/media/base/mediaengine.h"
#include "talk/media/base/streamparams.h"
#include "talk/media/base/videocapturer.h"
-#include "webrtc/p2p/base/session.h"
+#include "webrtc/p2p/base/transportcontroller.h"
#include "webrtc/p2p/client/socketmonitor.h"
#include "talk/session/media/audiomonitor.h"
#include "talk/session/media/bundlefilter.h"
@@ -74,8 +77,11 @@
public MediaChannel::NetworkInterface,
public ConnectionStatsGetter {
public:
- BaseChannel(rtc::Thread* thread, MediaChannel* channel, BaseSession* session,
- const std::string& content_name, bool rtcp);
+ BaseChannel(rtc::Thread* 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
@@ -83,8 +89,8 @@
void Deinit();
rtc::Thread* worker_thread() const { return worker_thread_; }
- BaseSession* session() const { return session_; }
- const std::string& content_name() { return content_name_; }
+ 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_;
}
@@ -109,6 +115,7 @@
// description doesn't support RTCP mux, setting the remote
// description will fail.
void ActivateRtcpMux();
+ bool SetTransport(const std::string& transport_name);
bool PushdownLocalDescription(const SessionDescription* local_desc,
ContentAction action,
std::string* error_desc);
@@ -135,7 +142,7 @@
void StartConnectionMonitor(int cms);
void StopConnectionMonitor();
// For ConnectionStatsGetter, used by ConnectionMonitor
- virtual bool GetConnectionStats(ConnectionInfos* infos) override;
+ bool GetConnectionStats(ConnectionInfos* infos) override;
void set_srtp_signal_silent_time(uint32 silent_time) {
srtp_filter_.set_signal_silent_time(silent_time);
@@ -158,19 +165,16 @@
sigslot::signal1<BaseChannel*> SignalFirstPacketReceived;
// Made public for easier testing.
- void SetReadyToSend(TransportChannel* channel, bool ready);
+ void SetReadyToSend(bool rtcp, bool ready);
// Only public for unit tests. Otherwise, consider protected.
virtual int SetOption(SocketType type, rtc::Socket::Option o, int val);
protected:
virtual MediaChannel* media_channel() const { return media_channel_; }
- // Sets the transport_channel_ and rtcp_transport_channel_. If
- // |rtcp| is false, set rtcp_transport_channel_ is set to NULL. Get
- // the transport channels from |session|.
- // TODO(pthatcher): Pass in a Transport instead of a BaseSession.
- bool SetTransportChannels(BaseSession* session, bool rtcp);
- bool SetTransportChannels_w(BaseSession* session, bool rtcp);
+ // 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);
void set_transport_channel(TransportChannel* transport);
void set_rtcp_transport_channel(TransportChannel* transport);
bool was_ever_writable() const { return was_ever_writable_; }
@@ -185,9 +189,11 @@
}
bool IsReadyToReceive() const;
bool IsReadyToSend() const;
- rtc::Thread* signaling_thread() { return session_->signaling_thread(); }
+ rtc::Thread* signaling_thread() {
+ return transport_controller_->signaling_thread();
+ }
SrtpFilter* srtp_filter() { return &srtp_filter_; }
- bool rtcp() const { return rtcp_; }
+ bool rtcp_transport_enabled() const { return rtcp_transport_enabled_; }
void ConnectToTransportChannel(TransportChannel* tc);
void DisconnectFromTransportChannel(TransportChannel* tc);
@@ -217,12 +223,9 @@
void HandlePacket(bool rtcp, rtc::Buffer* packet,
const rtc::PacketTime& packet_time);
- // Apply the new local/remote session description.
- void OnNewLocalDescription(BaseSession* session, ContentAction action);
- void OnNewRemoteDescription(BaseSession* session, ContentAction action);
-
void EnableMedia_w();
void DisableMedia_w();
+ void UpdateWritableState_w();
void ChannelWritable_w();
void ChannelNotWritable_w();
bool AddRecvStream_w(const StreamParams& sp);
@@ -293,15 +296,18 @@
private:
rtc::Thread* worker_thread_;
- BaseSession* session_;
+ TransportController* transport_controller_;
MediaChannel* media_channel_;
std::vector<StreamParams> local_streams_;
std::vector<StreamParams> remote_streams_;
const std::string content_name_;
- bool rtcp_;
+ std::string transport_name_;
+ bool rtcp_transport_enabled_;
TransportChannel* transport_channel_;
+ std::vector<std::pair<rtc::Socket::Option, int> > socket_options_;
TransportChannel* rtcp_transport_channel_;
+ std::vector<std::pair<rtc::Socket::Option, int> > rtcp_socket_options_;
SrtpFilter srtp_filter_;
RtcpMuxFilter rtcp_mux_filter_;
BundleFilter bundle_filter_;
@@ -323,16 +329,21 @@
// and input/output level monitoring.
class VoiceChannel : public BaseChannel {
public:
- VoiceChannel(rtc::Thread* thread, MediaEngineInterface* media_engine,
- VoiceMediaChannel* channel, BaseSession* session,
- const std::string& content_name, bool rtcp);
+ VoiceChannel(rtc::Thread* thread,
+ MediaEngineInterface* media_engine,
+ VoiceMediaChannel* channel,
+ TransportController* transport_controller,
+ const std::string& content_name,
+ bool rtcp);
~VoiceChannel();
bool Init();
bool SetRemoteRenderer(uint32 ssrc, AudioRenderer* renderer);
// Configure sending media on the stream with SSRC |ssrc|
// If there is only one sending stream SSRC 0 can be used.
- bool SetAudioSend(uint32 ssrc, bool mute, const AudioOptions* options,
+ bool SetAudioSend(uint32 ssrc,
+ bool mute,
+ const AudioOptions* options,
AudioRenderer* renderer);
// downcasts a MediaChannel
@@ -429,8 +440,10 @@
// VideoChannel is a specialization for video.
class VideoChannel : public BaseChannel {
public:
- VideoChannel(rtc::Thread* thread, VideoMediaChannel* channel,
- BaseSession* session, const std::string& content_name,
+ VideoChannel(rtc::Thread* thread,
+ VideoMediaChannel* channel,
+ TransportController* transport_controller,
+ const std::string& content_name,
bool rtcp);
~VideoChannel();
bool Init();
@@ -529,7 +542,7 @@
public:
DataChannel(rtc::Thread* thread,
DataMediaChannel* media_channel,
- BaseSession* session,
+ TransportController* transport_controller,
const std::string& content_name,
bool rtcp);
~DataChannel();
diff --git a/talk/session/media/channel_unittest.cc b/talk/session/media/channel_unittest.cc
index 22b1aef..d6e259d 100644
--- a/talk/session/media/channel_unittest.cc
+++ b/talk/session/media/channel_unittest.cc
@@ -33,7 +33,7 @@
#include "talk/media/base/rtpdump.h"
#include "talk/media/base/screencastid.h"
#include "talk/media/base/testutils.h"
-#include "webrtc/p2p/base/fakesession.h"
+#include "webrtc/p2p/base/faketransportcontroller.h"
#include "talk/session/media/channel.h"
#include "webrtc/base/fileutils.h"
#include "webrtc/base/gunit.h"
@@ -73,12 +73,12 @@
static const int kAudioPts[] = {0, 8};
static const int kVideoPts[] = {97, 99};
-template<class ChannelT,
- class MediaChannelT,
- class ContentT,
- class CodecT,
- class MediaInfoT,
- class OptionsT>
+template <class ChannelT,
+ class MediaChannelT,
+ class ContentT,
+ class CodecT,
+ class MediaInfoT,
+ class OptionsT>
class Traits {
public:
typedef ChannelT Channel;
@@ -98,25 +98,21 @@
cricket::AudioContentDescription,
cricket::AudioCodec,
cricket::VoiceMediaInfo,
- cricket::AudioOptions> {
-};
+ cricket::AudioOptions> {};
class VideoTraits : public Traits<cricket::VideoChannel,
cricket::FakeVideoMediaChannel,
cricket::VideoContentDescription,
cricket::VideoCodec,
cricket::VideoMediaInfo,
- cricket::VideoOptions> {
-};
+ cricket::VideoOptions> {};
class DataTraits : public Traits<cricket::DataChannel,
cricket::FakeDataMediaChannel,
cricket::DataContentDescription,
cricket::DataCodec,
cricket::DataMediaInfo,
- cricket::DataOptions> {
-};
-
+ cricket::DataOptions> {};
rtc::StreamInterface* Open(const std::string& path) {
return rtc::Filesystem::OpenFile(
@@ -130,10 +126,12 @@
enum Flags { RTCP = 0x1, RTCP_MUX = 0x2, SECURE = 0x4, SSRC_MUX = 0x8,
DTLS = 0x10 };
- ChannelTest(const uint8* rtp_data, int rtp_len,
- const uint8* rtcp_data, int rtcp_len)
- : session1_(true),
- session2_(false),
+ ChannelTest(const uint8* rtp_data,
+ int rtp_len,
+ const uint8* rtcp_data,
+ int rtcp_len)
+ : 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),
@@ -141,8 +139,7 @@
media_info_callbacks1_(),
media_info_callbacks2_(),
ssrc_(0),
- error_(T::MediaChannel::ERROR_NONE) {
- }
+ error_(T::MediaChannel::ERROR_NONE) {}
void CreateChannels(int flags1, int flags2) {
CreateChannels(new typename T::MediaChannel(NULL, typename T::Options()),
@@ -154,9 +151,11 @@
int flags1, int flags2, rtc::Thread* thread) {
media_channel1_ = ch1;
media_channel2_ = ch2;
- channel1_.reset(CreateChannel(thread, &media_engine_, ch1, &session1_,
+ channel1_.reset(CreateChannel(thread, &media_engine_, ch1,
+ &transport_controller1_,
(flags1 & RTCP) != 0));
- channel2_.reset(CreateChannel(thread, &media_engine_, ch2, &session2_,
+ channel2_.reset(CreateChannel(thread, &media_engine_, ch2,
+ &transport_controller2_,
(flags2 & RTCP) != 0));
channel1_->SignalMediaMonitor.connect(
this, &ChannelTest<T>::OnMediaMonitor);
@@ -179,15 +178,17 @@
if (flags1 & DTLS) {
// Confirmed to work with KT_RSA and KT_ECDSA.
- session1_.set_ssl_rtccertificate(rtc::RTCCertificate::Create(
- rtc::scoped_ptr<rtc::SSLIdentity>(rtc::SSLIdentity::Generate(
- "session1", rtc::KT_DEFAULT)).Pass()));
+ transport_controller1_.SetLocalCertificate(rtc::RTCCertificate::Create(
+ rtc::scoped_ptr<rtc::SSLIdentity>(
+ rtc::SSLIdentity::Generate("session1", rtc::KT_DEFAULT))
+ .Pass()));
}
if (flags2 & DTLS) {
// Confirmed to work with KT_RSA and KT_ECDSA.
- session2_.set_ssl_rtccertificate(rtc::RTCCertificate::Create(
- rtc::scoped_ptr<rtc::SSLIdentity>(rtc::SSLIdentity::Generate(
- "session2", rtc::KT_DEFAULT)).Pass()));
+ transport_controller2_.SetLocalCertificate(rtc::RTCCertificate::Create(
+ rtc::scoped_ptr<rtc::SSLIdentity>(
+ rtc::SSLIdentity::Generate("session2", rtc::KT_DEFAULT))
+ .Pass()));
}
// Add stream information (SSRC) to the local content but not to the remote
@@ -204,13 +205,14 @@
AddLegacyStreamInContent(kSsrc2, flags2, &remote_media_content2_);
}
}
- typename T::Channel* CreateChannel(rtc::Thread* thread,
- cricket::MediaEngineInterface* engine,
- typename T::MediaChannel* ch,
- cricket::BaseSession* session,
- bool rtcp) {
+ typename T::Channel* CreateChannel(
+ rtc::Thread* 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, session, cricket::CN_AUDIO, rtcp);
+ thread, engine, ch, transport_controller, cricket::CN_AUDIO, rtcp);
if (!channel->Init()) {
delete channel;
channel = NULL;
@@ -226,7 +228,7 @@
result = channel2_->SetRemoteContent(&remote_media_content1_,
CA_OFFER, NULL);
if (result) {
- session1_.Connect(&session2_);
+ transport_controller1_.Connect(&transport_controller2_);
result = channel2_->SetLocalContent(&local_media_content2_,
CA_ANSWER, NULL);
@@ -259,7 +261,7 @@
channel2_->Enable(true);
result = channel1_->SetRemoteContent(&remote_media_content2_,
CA_PRANSWER, NULL);
- session1_.Connect(&session2_);
+ transport_controller1_.Connect(&transport_controller2_);
}
return result;
}
@@ -286,11 +288,12 @@
return channel1_->RemoveRecvStream(id);
}
+ // Calling "_w" method here is ok since we only use one thread for this test
cricket::FakeTransport* GetTransport1() {
- return session1_.GetTransport(channel1_->content_name());
+ return transport_controller1_.GetTransport_w(channel1_->content_name());
}
cricket::FakeTransport* GetTransport2() {
- return session2_.GetTransport(channel2_->content_name());
+ return transport_controller2_.GetTransport_w(channel2_->content_name());
}
bool SendRtp1() {
@@ -769,7 +772,7 @@
EXPECT_TRUE(channel2_->SetRemoteContent(&content1, CA_OFFER, NULL));
EXPECT_EQ(1u, media_channel2_->recv_streams().size());
- session1_.Connect(&session2_);
+ transport_controller1_.Connect(&transport_controller2_);
// Channel 2 do not send anything.
typename T::Content content2;
@@ -832,7 +835,7 @@
CA_ANSWER, NULL));
EXPECT_FALSE(media_channel2_->playout());
EXPECT_FALSE(media_channel2_->sending());
- session1_.Connect(&session2_);
+ transport_controller1_.Connect(&transport_controller2_);
EXPECT_TRUE(media_channel1_->playout());
EXPECT_FALSE(media_channel1_->sending());
EXPECT_FALSE(media_channel2_->playout());
@@ -868,7 +871,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));
- session1_.Connect(&session2_);
+ transport_controller1_.Connect(&transport_controller2_);
EXPECT_TRUE(media_channel1_->playout());
EXPECT_FALSE(media_channel1_->sending()); // remote InActive
@@ -938,6 +941,8 @@
CreateChannels(0, 0);
EXPECT_TRUE(SendInitiate());
EXPECT_TRUE(SendAccept());
+ ASSERT_TRUE(GetTransport1());
+ ASSERT_TRUE(GetTransport2());
EXPECT_EQ(1U, GetTransport1()->channels().size());
EXPECT_EQ(1U, GetTransport2()->channels().size());
EXPECT_TRUE(SendRtp1());
@@ -953,6 +958,8 @@
CreateChannels(0, 0);
EXPECT_TRUE(SendInitiate());
EXPECT_TRUE(SendAccept());
+ ASSERT_TRUE(GetTransport1());
+ ASSERT_TRUE(GetTransport2());
EXPECT_EQ(1U, GetTransport1()->channels().size());
EXPECT_EQ(1U, GetTransport2()->channels().size());
EXPECT_FALSE(SendRtcp1());
@@ -966,6 +973,8 @@
CreateChannels(0, RTCP);
EXPECT_TRUE(SendInitiate());
EXPECT_TRUE(SendAccept());
+ ASSERT_TRUE(GetTransport1());
+ ASSERT_TRUE(GetTransport2());
EXPECT_EQ(1U, GetTransport1()->channels().size());
EXPECT_EQ(2U, GetTransport2()->channels().size());
EXPECT_FALSE(SendRtcp1());
@@ -979,6 +988,8 @@
CreateChannels(RTCP, 0);
EXPECT_TRUE(SendInitiate());
EXPECT_TRUE(SendAccept());
+ ASSERT_TRUE(GetTransport1());
+ ASSERT_TRUE(GetTransport2());
EXPECT_EQ(2U, GetTransport1()->channels().size());
EXPECT_EQ(1U, GetTransport2()->channels().size());
EXPECT_FALSE(SendRtcp1());
@@ -992,6 +1003,8 @@
CreateChannels(RTCP, RTCP);
EXPECT_TRUE(SendInitiate());
EXPECT_TRUE(SendAccept());
+ ASSERT_TRUE(GetTransport1());
+ ASSERT_TRUE(GetTransport2());
EXPECT_EQ(2U, GetTransport1()->channels().size());
EXPECT_EQ(2U, GetTransport2()->channels().size());
EXPECT_TRUE(SendRtcp1());
@@ -1007,6 +1020,8 @@
CreateChannels(RTCP | RTCP_MUX, RTCP);
EXPECT_TRUE(SendInitiate());
EXPECT_TRUE(SendAccept());
+ ASSERT_TRUE(GetTransport1());
+ ASSERT_TRUE(GetTransport2());
EXPECT_EQ(2U, GetTransport1()->channels().size());
EXPECT_EQ(2U, GetTransport2()->channels().size());
EXPECT_TRUE(SendRtcp1());
@@ -1021,6 +1036,8 @@
void SendRtcpMuxToRtcpMux() {
CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
EXPECT_TRUE(SendInitiate());
+ ASSERT_TRUE(GetTransport1());
+ ASSERT_TRUE(GetTransport2());
EXPECT_EQ(2U, GetTransport1()->channels().size());
EXPECT_EQ(1U, GetTransport2()->channels().size());
EXPECT_TRUE(SendAccept());
@@ -1045,6 +1062,8 @@
CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
channel1_->ActivateRtcpMux();
EXPECT_TRUE(SendInitiate());
+ ASSERT_TRUE(GetTransport1());
+ ASSERT_TRUE(GetTransport2());
EXPECT_EQ(1U, GetTransport1()->channels().size());
EXPECT_EQ(1U, GetTransport2()->channels().size());
EXPECT_TRUE(SendAccept());
@@ -1068,6 +1087,8 @@
CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
channel2_->ActivateRtcpMux();
EXPECT_TRUE(SendInitiate());
+ ASSERT_TRUE(GetTransport1());
+ ASSERT_TRUE(GetTransport2());
EXPECT_EQ(2U, GetTransport1()->channels().size());
EXPECT_EQ(1U, GetTransport2()->channels().size());
EXPECT_TRUE(SendAccept());
@@ -1093,6 +1114,8 @@
channel1_->ActivateRtcpMux();
channel2_->ActivateRtcpMux();
EXPECT_TRUE(SendInitiate());
+ ASSERT_TRUE(GetTransport1());
+ ASSERT_TRUE(GetTransport2());
EXPECT_EQ(1U, GetTransport1()->channels().size());
EXPECT_EQ(1U, GetTransport2()->channels().size());
EXPECT_TRUE(SendAccept());
@@ -1117,6 +1140,8 @@
CreateChannels(RTCP | RTCP_MUX, RTCP);
channel1_->ActivateRtcpMux();
EXPECT_TRUE(SendInitiate());
+ ASSERT_TRUE(GetTransport1());
+ ASSERT_TRUE(GetTransport2());
EXPECT_EQ(1U, GetTransport1()->channels().size());
EXPECT_EQ(2U, GetTransport2()->channels().size());
EXPECT_FALSE(SendAccept());
@@ -1126,6 +1151,8 @@
void SendEarlyRtcpMuxToRtcp() {
CreateChannels(RTCP | RTCP_MUX, RTCP);
EXPECT_TRUE(SendInitiate());
+ ASSERT_TRUE(GetTransport1());
+ ASSERT_TRUE(GetTransport2());
EXPECT_EQ(2U, GetTransport1()->channels().size());
EXPECT_EQ(2U, GetTransport2()->channels().size());
@@ -1156,6 +1183,8 @@
void SendEarlyRtcpMuxToRtcpMux() {
CreateChannels(RTCP | RTCP_MUX, RTCP | RTCP_MUX);
EXPECT_TRUE(SendInitiate());
+ ASSERT_TRUE(GetTransport1());
+ ASSERT_TRUE(GetTransport2());
EXPECT_EQ(2U, GetTransport1()->channels().size());
EXPECT_EQ(1U, GetTransport2()->channels().size());
@@ -1246,6 +1275,8 @@
EXPECT_TRUE(SendProvisionalAnswer());
EXPECT_TRUE(channel1_->secure());
EXPECT_TRUE(channel2_->secure());
+ ASSERT_TRUE(GetTransport1());
+ ASSERT_TRUE(GetTransport2());
EXPECT_EQ(2U, GetTransport1()->channels().size());
EXPECT_EQ(2U, GetTransport2()->channels().size());
EXPECT_TRUE(SendCustomRtcp1(kSsrc1));
@@ -1329,6 +1360,8 @@
CreateChannels(0, 0);
EXPECT_TRUE(SendInitiate());
EXPECT_TRUE(SendAccept());
+ ASSERT_TRUE(GetTransport1());
+ ASSERT_TRUE(GetTransport2());
EXPECT_EQ(1U, GetTransport1()->channels().size());
EXPECT_EQ(1U, GetTransport2()->channels().size());
EXPECT_TRUE(SendRtp1());
@@ -1393,6 +1426,8 @@
}
CreateChannels(flags, flags);
EXPECT_TRUE(SendInitiate());
+ ASSERT_TRUE(GetTransport1());
+ ASSERT_TRUE(GetTransport2());
EXPECT_EQ(2U, GetTransport1()->channels().size());
EXPECT_EQ(expected_channels, GetTransport2()->channels().size());
EXPECT_TRUE(SendAccept());
@@ -1581,6 +1616,8 @@
CreateChannels(RTCP, RTCP);
EXPECT_TRUE(SendInitiate());
EXPECT_TRUE(SendAccept());
+ ASSERT_TRUE(GetTransport1());
+ ASSERT_TRUE(GetTransport2());
EXPECT_EQ(2U, GetTransport1()->channels().size());
EXPECT_EQ(2U, GetTransport2()->channels().size());
@@ -1669,15 +1706,15 @@
EXPECT_TRUE(media_channel1_->ready_to_send());
// rtp channel becomes not ready to send will be propagated to mediachannel
- channel1_->SetReadyToSend(rtp, false);
+ channel1_->SetReadyToSend(false, false);
EXPECT_FALSE(media_channel1_->ready_to_send());
- channel1_->SetReadyToSend(rtp, true);
+ channel1_->SetReadyToSend(false, true);
EXPECT_TRUE(media_channel1_->ready_to_send());
// rtcp channel becomes not ready to send will be propagated to mediachannel
- channel1_->SetReadyToSend(rtcp, false);
+ channel1_->SetReadyToSend(true, false);
EXPECT_FALSE(media_channel1_->ready_to_send());
- channel1_->SetReadyToSend(rtcp, true);
+ channel1_->SetReadyToSend(true, true);
EXPECT_TRUE(media_channel1_->ready_to_send());
}
@@ -1696,13 +1733,13 @@
// should trigger the MediaChannel's OnReadyToSend.
rtp->SignalReadyToSend(rtp);
EXPECT_TRUE(media_channel1_->ready_to_send());
- channel1_->SetReadyToSend(rtp, false);
+ channel1_->SetReadyToSend(false, false);
EXPECT_FALSE(media_channel1_->ready_to_send());
}
protected:
- cricket::FakeSession session1_;
- cricket::FakeSession session2_;
+ cricket::FakeTransportController transport_controller1_;
+ cricket::FakeTransportController transport_controller2_;
cricket::FakeMediaEngine media_engine_;
// The media channels are owned by the voice channel objects below.
typename T::MediaChannel* media_channel1_;
@@ -1763,18 +1800,21 @@
: public ChannelTest<VoiceTraits> {
public:
typedef ChannelTest<VoiceTraits> Base;
- VoiceChannelTest() : Base(kPcmuFrame, sizeof(kPcmuFrame),
- kRtcpReport, sizeof(kRtcpReport)) {}
+ VoiceChannelTest()
+ : Base(kPcmuFrame, sizeof(kPcmuFrame), kRtcpReport, sizeof(kRtcpReport)) {
+ }
};
// override to add NULL parameter
-template<>
+template <>
cricket::VideoChannel* ChannelTest<VideoTraits>::CreateChannel(
- rtc::Thread* thread, cricket::MediaEngineInterface* engine,
- cricket::FakeVideoMediaChannel* ch, cricket::BaseSession* session,
+ rtc::Thread* thread,
+ cricket::MediaEngineInterface* engine,
+ cricket::FakeVideoMediaChannel* ch,
+ cricket::TransportController* transport_controller,
bool rtcp) {
cricket::VideoChannel* channel = new cricket::VideoChannel(
- thread, ch, session, cricket::CN_VIDEO, rtcp);
+ thread, ch, transport_controller, cricket::CN_VIDEO, rtcp);
if (!channel->Init()) {
delete channel;
channel = NULL;
@@ -1827,8 +1867,11 @@
: public ChannelTest<VideoTraits> {
public:
typedef ChannelTest<VideoTraits> Base;
- VideoChannelTest() : Base(kH264Packet, sizeof(kH264Packet),
- kRtcpReport, sizeof(kRtcpReport)) {}
+ VideoChannelTest()
+ : Base(kH264Packet,
+ sizeof(kH264Packet),
+ kRtcpReport,
+ sizeof(kRtcpReport)) {}
};
@@ -2519,13 +2562,15 @@
};
// Override to avoid engine channel parameter.
-template<>
+template <>
cricket::DataChannel* ChannelTest<DataTraits>::CreateChannel(
- rtc::Thread* thread, cricket::MediaEngineInterface* engine,
- cricket::FakeDataMediaChannel* ch, cricket::BaseSession* session,
+ rtc::Thread* thread,
+ cricket::MediaEngineInterface* engine,
+ cricket::FakeDataMediaChannel* ch,
+ cricket::TransportController* transport_controller,
bool rtcp) {
cricket::DataChannel* channel = new cricket::DataChannel(
- thread, ch, session, cricket::CN_DATA, rtcp);
+ thread, ch, transport_controller, cricket::CN_DATA, rtcp);
if (!channel->Init()) {
delete channel;
channel = NULL;
diff --git a/talk/session/media/channelmanager.cc b/talk/session/media/channelmanager.cc
index 9285543..201a031 100644
--- a/talk/session/media/channelmanager.cc
+++ b/talk/session/media/channelmanager.cc
@@ -318,23 +318,18 @@
VoiceChannel* ChannelManager::CreateVoiceChannel(
webrtc::MediaControllerInterface* media_controller,
- BaseSession* session,
+ TransportController* transport_controller,
const std::string& content_name,
bool rtcp,
const AudioOptions& options) {
return worker_thread_->Invoke<VoiceChannel*>(
- Bind(&ChannelManager::CreateVoiceChannel_w,
- this,
- media_controller,
- session,
- content_name,
- rtcp,
- options));
+ Bind(&ChannelManager::CreateVoiceChannel_w, this, media_controller,
+ transport_controller, content_name, rtcp, options));
}
VoiceChannel* ChannelManager::CreateVoiceChannel_w(
webrtc::MediaControllerInterface* media_controller,
- BaseSession* session,
+ TransportController* transport_controller,
const std::string& content_name,
bool rtcp,
const AudioOptions& options) {
@@ -346,9 +341,9 @@
if (!media_channel)
return nullptr;
- VoiceChannel* voice_channel = new VoiceChannel(
- worker_thread_, media_engine_.get(), media_channel,
- session, content_name, rtcp);
+ VoiceChannel* voice_channel =
+ new VoiceChannel(worker_thread_, media_engine_.get(), media_channel,
+ transport_controller, content_name, rtcp);
if (!voice_channel->Init()) {
delete voice_channel;
return nullptr;
@@ -379,23 +374,18 @@
VideoChannel* ChannelManager::CreateVideoChannel(
webrtc::MediaControllerInterface* media_controller,
- BaseSession* session,
+ TransportController* transport_controller,
const std::string& content_name,
bool rtcp,
const VideoOptions& options) {
return worker_thread_->Invoke<VideoChannel*>(
- Bind(&ChannelManager::CreateVideoChannel_w,
- this,
- media_controller,
- session,
- content_name,
- rtcp,
- options));
+ Bind(&ChannelManager::CreateVideoChannel_w, this, media_controller,
+ transport_controller, content_name, rtcp, options));
}
VideoChannel* ChannelManager::CreateVideoChannel_w(
webrtc::MediaControllerInterface* media_controller,
- BaseSession* session,
+ TransportController* transport_controller,
const std::string& content_name,
bool rtcp,
const VideoOptions& options) {
@@ -404,12 +394,12 @@
ASSERT(nullptr != media_controller);
VideoMediaChannel* media_channel =
media_engine_->CreateVideoChannel(media_controller->call_w(), options);
- if (media_channel == NULL)
+ if (media_channel == NULL) {
return NULL;
+ }
VideoChannel* video_channel = new VideoChannel(
- worker_thread_, media_channel,
- session, content_name, rtcp);
+ worker_thread_, media_channel, transport_controller, content_name, rtcp);
if (!video_channel->Init()) {
delete video_channel;
return NULL;
@@ -440,16 +430,20 @@
}
DataChannel* ChannelManager::CreateDataChannel(
- BaseSession* session, const std::string& content_name,
- bool rtcp, DataChannelType channel_type) {
+ TransportController* transport_controller,
+ const std::string& content_name,
+ bool rtcp,
+ DataChannelType channel_type) {
return worker_thread_->Invoke<DataChannel*>(
- Bind(&ChannelManager::CreateDataChannel_w, this, session, content_name,
- rtcp, channel_type));
+ Bind(&ChannelManager::CreateDataChannel_w, this, transport_controller,
+ content_name, rtcp, channel_type));
}
DataChannel* ChannelManager::CreateDataChannel_w(
- BaseSession* session, const std::string& content_name,
- bool rtcp, DataChannelType data_channel_type) {
+ TransportController* transport_controller,
+ const std::string& content_name,
+ bool rtcp,
+ DataChannelType data_channel_type) {
// This is ok to alloc from a thread other than the worker thread.
ASSERT(initialized_);
DataMediaChannel* media_channel = data_media_engine_->CreateChannel(
@@ -461,8 +455,7 @@
}
DataChannel* data_channel = new DataChannel(
- worker_thread_, media_channel,
- session, content_name, rtcp);
+ worker_thread_, media_channel, transport_controller, content_name, rtcp);
if (!data_channel->Init()) {
LOG(LS_WARNING) << "Failed to init data channel.";
delete data_channel;
diff --git a/talk/session/media/channelmanager.h b/talk/session/media/channelmanager.h
index 86bb972..5f76519 100644
--- a/talk/session/media/channelmanager.h
+++ b/talk/session/media/channelmanager.h
@@ -104,11 +104,10 @@
void Terminate();
// The operations below all occur on the worker thread.
-
// Creates a voice channel, to be associated with the specified session.
VoiceChannel* CreateVoiceChannel(
webrtc::MediaControllerInterface* media_controller,
- BaseSession* session,
+ TransportController* transport_controller,
const std::string& content_name,
bool rtcp,
const AudioOptions& options);
@@ -118,15 +117,16 @@
// associated with the specified session.
VideoChannel* CreateVideoChannel(
webrtc::MediaControllerInterface* media_controller,
- BaseSession* session,
+ TransportController* transport_controller,
const std::string& content_name,
bool rtcp,
const VideoOptions& options);
// Destroys a video channel created with the Create API.
void DestroyVideoChannel(VideoChannel* video_channel);
- DataChannel* CreateDataChannel(
- BaseSession* session, const std::string& content_name,
- bool rtcp, DataChannelType data_channel_type);
+ DataChannel* CreateDataChannel(TransportController* transport_controller,
+ const std::string& content_name,
+ bool rtcp,
+ DataChannelType data_channel_type);
// Destroys a data channel created with the Create API.
void DestroyDataChannel(DataChannel* data_channel);
@@ -241,21 +241,22 @@
void Terminate_w();
VoiceChannel* CreateVoiceChannel_w(
webrtc::MediaControllerInterface* media_controller,
- BaseSession* session,
+ TransportController* transport_controller,
const std::string& content_name,
bool rtcp,
const AudioOptions& options);
void DestroyVoiceChannel_w(VoiceChannel* voice_channel);
VideoChannel* CreateVideoChannel_w(
webrtc::MediaControllerInterface* media_controller,
- BaseSession* session,
+ TransportController* transport_controller,
const std::string& content_name,
bool rtcp,
const VideoOptions& options);
void DestroyVideoChannel_w(VideoChannel* video_channel);
- DataChannel* CreateDataChannel_w(
- BaseSession* session, const std::string& content_name,
- bool rtcp, DataChannelType data_channel_type);
+ DataChannel* CreateDataChannel_w(TransportController* transport_controller,
+ const std::string& content_name,
+ bool rtcp,
+ DataChannelType data_channel_type);
void DestroyDataChannel_w(DataChannel* data_channel);
bool SetAudioOptions_w(const AudioOptions& options, int delay_offset,
const Device* in_dev, const Device* out_dev);
diff --git a/talk/session/media/channelmanager_unittest.cc b/talk/session/media/channelmanager_unittest.cc
index 98c79c3..bbd5602 100644
--- a/talk/session/media/channelmanager_unittest.cc
+++ b/talk/session/media/channelmanager_unittest.cc
@@ -31,11 +31,11 @@
#include "talk/media/base/testutils.h"
#include "talk/media/devices/fakedevicemanager.h"
#include "talk/media/webrtc/fakewebrtccall.h"
-#include "webrtc/p2p/base/fakesession.h"
#include "talk/session/media/channelmanager.h"
#include "webrtc/base/gunit.h"
#include "webrtc/base/logging.h"
#include "webrtc/base/thread.h"
+#include "webrtc/p2p/base/faketransportcontroller.h"
namespace cricket {
@@ -57,14 +57,20 @@
}
~FakeMediaController() override {}
webrtc::Call* call_w() override { return call_; }
+
private:
webrtc::Call* call_;
};
class ChannelManagerTest : public testing::Test {
protected:
- ChannelManagerTest() : fake_call_(webrtc::Call::Config()),
- fake_mc_(&fake_call_), fme_(NULL), fdm_(NULL), fcm_(NULL), cm_(NULL) {}
+ ChannelManagerTest()
+ : fake_call_(webrtc::Call::Config()),
+ fake_mc_(&fake_call_),
+ fme_(NULL),
+ fdm_(NULL),
+ fcm_(NULL),
+ cm_(NULL) {}
virtual void SetUp() {
fme_ = new cricket::FakeMediaEngine();
@@ -75,7 +81,8 @@
fcm_ = new cricket::FakeCaptureManager();
cm_ = new cricket::ChannelManager(
fme_, fdme_, fdm_, fcm_, rtc::Thread::Current());
- session_ = new cricket::FakeSession(true);
+ transport_controller_ =
+ new cricket::FakeTransportController(ICEROLE_CONTROLLING);
std::vector<std::string> in_device_list, out_device_list, vid_device_list;
in_device_list.push_back("audio-in1");
@@ -90,7 +97,7 @@
}
virtual void TearDown() {
- delete session_;
+ delete transport_controller_;
delete cm_;
cm_ = NULL;
fdm_ = NULL;
@@ -107,7 +114,7 @@
cricket::FakeDeviceManager* fdm_;
cricket::FakeCaptureManager* fcm_;
cricket::ChannelManager* cm_;
- cricket::FakeSession* session_;
+ cricket::FakeTransportController* transport_controller_;
};
// Test that we startup/shutdown properly.
@@ -138,15 +145,16 @@
// Test that we can create and destroy a voice and video channel.
TEST_F(ChannelManagerTest, CreateDestroyChannels) {
EXPECT_TRUE(cm_->Init());
- cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
- &fake_mc_, session_, cricket::CN_AUDIO, false, AudioOptions());
+ cricket::VoiceChannel* voice_channel =
+ cm_->CreateVoiceChannel(&fake_mc_, transport_controller_,
+ cricket::CN_AUDIO, false, AudioOptions());
EXPECT_TRUE(voice_channel != nullptr);
- cricket::VideoChannel* video_channel = cm_->CreateVideoChannel(
- &fake_mc_, session_, cricket::CN_VIDEO, false, VideoOptions());
+ cricket::VideoChannel* video_channel =
+ cm_->CreateVideoChannel(&fake_mc_, transport_controller_,
+ cricket::CN_VIDEO, false, VideoOptions());
EXPECT_TRUE(video_channel != nullptr);
- cricket::DataChannel* data_channel =
- cm_->CreateDataChannel(session_, cricket::CN_DATA,
- false, cricket::DCT_RTP);
+ cricket::DataChannel* data_channel = cm_->CreateDataChannel(
+ transport_controller_, cricket::CN_DATA, false, cricket::DCT_RTP);
EXPECT_TRUE(data_channel != nullptr);
cm_->DestroyVideoChannel(video_channel);
cm_->DestroyVoiceChannel(voice_channel);
@@ -159,17 +167,19 @@
worker_.Start();
EXPECT_TRUE(cm_->set_worker_thread(&worker_));
EXPECT_TRUE(cm_->Init());
- delete session_;
- session_ = new cricket::FakeSession(&worker_, true);
- cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
- &fake_mc_, session_, cricket::CN_AUDIO, false, AudioOptions());
+ delete transport_controller_;
+ transport_controller_ =
+ new cricket::FakeTransportController(&worker_, ICEROLE_CONTROLLING);
+ cricket::VoiceChannel* voice_channel =
+ cm_->CreateVoiceChannel(&fake_mc_, transport_controller_,
+ cricket::CN_AUDIO, false, AudioOptions());
EXPECT_TRUE(voice_channel != nullptr);
- cricket::VideoChannel* video_channel = cm_->CreateVideoChannel(
- &fake_mc_, session_, cricket::CN_VIDEO, false, VideoOptions());
+ cricket::VideoChannel* video_channel =
+ cm_->CreateVideoChannel(&fake_mc_, transport_controller_,
+ cricket::CN_VIDEO, false, VideoOptions());
EXPECT_TRUE(video_channel != nullptr);
- cricket::DataChannel* data_channel =
- cm_->CreateDataChannel(session_, cricket::CN_DATA,
- false, cricket::DCT_RTP);
+ cricket::DataChannel* data_channel = cm_->CreateDataChannel(
+ transport_controller_, cricket::CN_DATA, false, cricket::DCT_RTP);
EXPECT_TRUE(data_channel != nullptr);
cm_->DestroyVideoChannel(video_channel);
cm_->DestroyVoiceChannel(voice_channel);
@@ -181,21 +191,22 @@
// to create a cricket::TransportChannel
TEST_F(ChannelManagerTest, NoTransportChannelTest) {
EXPECT_TRUE(cm_->Init());
- session_->set_fail_channel_creation(true);
+ transport_controller_->set_fail_channel_creation(true);
// The test is useless unless the session does not fail creating
// cricket::TransportChannel.
- ASSERT_TRUE(session_->CreateChannel(
+ ASSERT_TRUE(transport_controller_->CreateTransportChannel_w(
"audio", cricket::ICE_CANDIDATE_COMPONENT_RTP) == nullptr);
- cricket::VoiceChannel* voice_channel = cm_->CreateVoiceChannel(
- &fake_mc_, session_, cricket::CN_AUDIO, false, AudioOptions());
+ cricket::VoiceChannel* voice_channel =
+ cm_->CreateVoiceChannel(&fake_mc_, transport_controller_,
+ cricket::CN_AUDIO, false, AudioOptions());
EXPECT_TRUE(voice_channel == nullptr);
- cricket::VideoChannel* video_channel = cm_->CreateVideoChannel(
- &fake_mc_, session_, cricket::CN_VIDEO, false, VideoOptions());
+ cricket::VideoChannel* video_channel =
+ cm_->CreateVideoChannel(&fake_mc_, transport_controller_,
+ cricket::CN_VIDEO, false, VideoOptions());
EXPECT_TRUE(video_channel == nullptr);
- cricket::DataChannel* data_channel =
- cm_->CreateDataChannel(session_, cricket::CN_DATA,
- false, cricket::DCT_RTP);
+ cricket::DataChannel* data_channel = cm_->CreateDataChannel(
+ transport_controller_, cricket::CN_DATA, false, cricket::DCT_RTP);
EXPECT_TRUE(data_channel == nullptr);
cm_->Terminate();
}