Cleanup SocketMonitor a little so that it can handle a change in transport channel. And cleanup some names and style and such as well.

This is a part of the big BUNDLE implementation at https://webrtc-codereview.appspot.com/45519004/

R=guoweis@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/49399004

Cr-Commit-Position: refs/heads/master@{#8720}
git-svn-id: http://webrtc.googlecode.com/svn/trunk@8720 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
pthatcher@webrtc.org 2015-03-13 18:25:21 +00:00
parent 990a00c30a
commit b4aac13810
5 changed files with 72 additions and 54 deletions

View File

@ -43,6 +43,7 @@
#include "webrtc/p2p/base/stunserver.h"
#include "webrtc/p2p/base/teststunserver.h"
#include "webrtc/p2p/base/testturnserver.h"
#include "webrtc/p2p/base/transportchannel.h"
#include "webrtc/p2p/client/basicportallocator.h"
#include "talk/session/media/channelmanager.h"
#include "talk/session/media/mediasession.h"

View File

@ -278,21 +278,28 @@ bool BaseChannel::SetRemoteContent(const MediaContentDescription* content,
}
void BaseChannel::StartConnectionMonitor(int cms) {
socket_monitor_.reset(new SocketMonitor(transport_channel_,
worker_thread(),
rtc::Thread::Current()));
socket_monitor_->SignalUpdate.connect(
// 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()));
connection_monitor_->SignalUpdate.connect(
this, &BaseChannel::OnConnectionMonitorUpdate);
socket_monitor_->Start(cms);
connection_monitor_->Start(cms);
}
void BaseChannel::StopConnectionMonitor() {
if (socket_monitor_) {
socket_monitor_->Stop();
socket_monitor_.reset();
if (connection_monitor_) {
connection_monitor_->Stop();
connection_monitor_.reset();
}
}
bool BaseChannel::GetConnectionStats(ConnectionInfos* infos) {
ASSERT(worker_thread_ == rtc::Thread::Current());
return transport_channel_->GetStats(infos);
}
void BaseChannel::set_rtcp_transport_channel(TransportChannel* channel) {
if (rtcp_transport_channel_ != channel) {
if (rtcp_transport_channel_) {
@ -1597,7 +1604,7 @@ void VoiceChannel::OnMessage(rtc::Message *pmsg) {
}
void VoiceChannel::OnConnectionMonitorUpdate(
SocketMonitor* monitor, const std::vector<ConnectionInfo>& infos) {
ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos) {
SignalConnectionMonitor(this, infos);
}
@ -2003,7 +2010,7 @@ void VideoChannel::OnMessage(rtc::Message *pmsg) {
}
void VideoChannel::OnConnectionMonitorUpdate(
SocketMonitor *monitor, const std::vector<ConnectionInfo> &infos) {
ConnectionMonitor* monitor, const std::vector<ConnectionInfo> &infos) {
SignalConnectionMonitor(this, infos);
}
@ -2372,7 +2379,7 @@ void DataChannel::OnMessage(rtc::Message *pmsg) {
}
void DataChannel::OnConnectionMonitorUpdate(
SocketMonitor* monitor, const std::vector<ConnectionInfo>& infos) {
ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos) {
SignalConnectionMonitor(this, infos);
}

View File

@ -73,7 +73,8 @@ enum SinkType {
class BaseChannel
: public rtc::MessageHandler, public sigslot::has_slots<>,
public MediaChannel::NetworkInterface {
public MediaChannel::NetworkInterface,
public ConnectionStatsGetter {
public:
BaseChannel(rtc::Thread* thread, MediaEngineInterface* media_engine,
MediaChannel* channel, BaseSession* session,
@ -130,6 +131,8 @@ class BaseChannel
// Monitoring
void StartConnectionMonitor(int cms);
void StopConnectionMonitor();
// For ConnectionStatsGetter, used by ConnectionMonitor
virtual bool GetConnectionStats(ConnectionInfos* infos) override;
void set_srtp_signal_silent_time(uint32 silent_time) {
srtp_filter_.set_signal_silent_time(silent_time);
@ -339,7 +342,7 @@ class BaseChannel
// Handled in derived classes
// Get the SRTP ciphers to use for RTP media
virtual void GetSrtpCiphers(std::vector<std::string>* ciphers) const = 0;
virtual void OnConnectionMonitorUpdate(SocketMonitor* monitor,
virtual void OnConnectionMonitorUpdate(ConnectionMonitor* monitor,
const std::vector<ConnectionInfo>& infos) = 0;
// Helper function for invoking bool-returning methods on the worker thread.
@ -370,7 +373,7 @@ class BaseChannel
SrtpFilter srtp_filter_;
RtcpMuxFilter rtcp_mux_filter_;
BundleFilter bundle_filter_;
rtc::scoped_ptr<SocketMonitor> socket_monitor_;
rtc::scoped_ptr<ConnectionMonitor> connection_monitor_;
bool enabled_;
bool writable_;
bool rtp_ready_to_send_;
@ -480,7 +483,7 @@ class VoiceChannel : public BaseChannel {
virtual void OnMessage(rtc::Message* pmsg);
virtual void GetSrtpCiphers(std::vector<std::string>* ciphers) const;
virtual void OnConnectionMonitorUpdate(
SocketMonitor* monitor, const std::vector<ConnectionInfo>& infos);
ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos);
virtual void OnMediaMonitorUpdate(
VoiceMediaChannel* media_channel, const VoiceMediaInfo& info);
void OnAudioMonitorUpdate(AudioMonitor* monitor, const AudioInfo& info);
@ -569,7 +572,7 @@ class VideoChannel : public BaseChannel {
virtual void OnMessage(rtc::Message* pmsg);
virtual void GetSrtpCiphers(std::vector<std::string>* ciphers) const;
virtual void OnConnectionMonitorUpdate(
SocketMonitor* monitor, const std::vector<ConnectionInfo>& infos);
ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos);
virtual void OnMediaMonitorUpdate(
VideoMediaChannel* media_channel, const VideoMediaInfo& info);
virtual void OnScreencastWindowEvent(uint32 ssrc,
@ -688,7 +691,7 @@ class DataChannel : public BaseChannel {
virtual void OnMessage(rtc::Message* pmsg);
virtual void GetSrtpCiphers(std::vector<std::string>* ciphers) const;
virtual void OnConnectionMonitorUpdate(
SocketMonitor* monitor, const std::vector<ConnectionInfo>& infos);
ConnectionMonitor* monitor, const std::vector<ConnectionInfo>& infos);
virtual void OnMediaMonitorUpdate(
DataMediaChannel* media_channel, const DataMediaInfo& info);
virtual bool ShouldSetupDtlsSrtp() const;

View File

@ -21,53 +21,53 @@ enum {
MSG_MONITOR_SIGNAL
};
SocketMonitor::SocketMonitor(TransportChannel* channel,
rtc::Thread* worker_thread,
rtc::Thread* monitor_thread) {
channel_ = channel;
channel_thread_ = worker_thread;
monitoring_thread_ = monitor_thread;
ConnectionMonitor::ConnectionMonitor(ConnectionStatsGetter* stats_getter,
rtc::Thread* worker_thread,
rtc::Thread* monitoring_thread) {
stats_getter_ = stats_getter;
worker_thread_ = worker_thread;
monitoring_thread_ = monitoring_thread;
monitoring_ = false;
}
SocketMonitor::~SocketMonitor() {
channel_thread_->Clear(this);
ConnectionMonitor::~ConnectionMonitor() {
worker_thread_->Clear(this);
monitoring_thread_->Clear(this);
}
void SocketMonitor::Start(int milliseconds) {
void ConnectionMonitor::Start(int milliseconds) {
rate_ = milliseconds;
if (rate_ < 250)
rate_ = 250;
channel_thread_->Post(this, MSG_MONITOR_START);
worker_thread_->Post(this, MSG_MONITOR_START);
}
void SocketMonitor::Stop() {
channel_thread_->Post(this, MSG_MONITOR_STOP);
void ConnectionMonitor::Stop() {
worker_thread_->Post(this, MSG_MONITOR_STOP);
}
void SocketMonitor::OnMessage(rtc::Message *message) {
void ConnectionMonitor::OnMessage(rtc::Message *message) {
rtc::CritScope cs(&crit_);
switch (message->message_id) {
case MSG_MONITOR_START:
ASSERT(rtc::Thread::Current() == channel_thread_);
ASSERT(rtc::Thread::Current() == worker_thread_);
if (!monitoring_) {
monitoring_ = true;
PollSocket(true);
PollConnectionStats_w();
}
break;
case MSG_MONITOR_STOP:
ASSERT(rtc::Thread::Current() == channel_thread_);
ASSERT(rtc::Thread::Current() == worker_thread_);
if (monitoring_) {
monitoring_ = false;
channel_thread_->Clear(this);
worker_thread_->Clear(this);
}
break;
case MSG_MONITOR_POLL:
ASSERT(rtc::Thread::Current() == channel_thread_);
PollSocket(true);
ASSERT(rtc::Thread::Current() == worker_thread_);
PollConnectionStats_w();
break;
case MSG_MONITOR_SIGNAL: {
@ -81,17 +81,16 @@ void SocketMonitor::OnMessage(rtc::Message *message) {
}
}
void SocketMonitor::PollSocket(bool poll) {
ASSERT(rtc::Thread::Current() == channel_thread_);
void ConnectionMonitor::PollConnectionStats_w() {
ASSERT(rtc::Thread::Current() == worker_thread_);
rtc::CritScope cs(&crit_);
// Gather connection infos
channel_->GetStats(&connection_infos_);
stats_getter_->GetConnectionStats(&connection_infos_);
// Signal the monitoring thread, start another poll timer
monitoring_thread_->Post(this, MSG_MONITOR_SIGNAL);
if (poll)
channel_thread_->PostDelayed(rate_, this, MSG_MONITOR_POLL);
worker_thread_->PostDelayed(rate_, this, MSG_MONITOR_POLL);
}
} // namespace cricket

View File

@ -13,36 +13,44 @@
#include <vector>
#include "webrtc/p2p/base/transportchannel.h"
#include "webrtc/base/criticalsection.h"
#include "webrtc/base/sigslot.h"
#include "webrtc/base/thread.h"
#include "webrtc/p2p/base/transport.h" // for ConnectionInfos
// TODO(pthatcher): Move these to connectionmonitor.h and
// connectionmonitor.cc, or just move them into channel.cc
namespace cricket {
class SocketMonitor : public rtc::MessageHandler,
public sigslot::has_slots<> {
class ConnectionStatsGetter {
public:
SocketMonitor(TransportChannel* channel,
rtc::Thread* worker_thread,
rtc::Thread* monitor_thread);
~SocketMonitor();
virtual ~ConnectionStatsGetter() {}
virtual bool GetConnectionStats(ConnectionInfos* infos) = 0;
};
class ConnectionMonitor : public rtc::MessageHandler,
public sigslot::has_slots<> {
public:
ConnectionMonitor(ConnectionStatsGetter* stats_getter,
rtc::Thread* worker_thread,
rtc::Thread* monitoring_thread);
~ConnectionMonitor();
void Start(int cms);
void Stop();
rtc::Thread* monitor_thread() { return monitoring_thread_; }
sigslot::signal2<SocketMonitor*,
sigslot::signal2<ConnectionMonitor*,
const std::vector<ConnectionInfo>&> SignalUpdate;
protected:
void OnMessage(rtc::Message* message);
void PollSocket(bool poll);
private:
void PollConnectionStats_w();
std::vector<ConnectionInfo> connection_infos_;
TransportChannel* channel_;
rtc::Thread* channel_thread_;
ConnectionStatsGetter* stats_getter_;
rtc::Thread* worker_thread_;
rtc::Thread* monitoring_thread_;
rtc::CriticalSection crit_;
uint32 rate_;