From 47218956fc432432146f9dadd7e266089ac94448 Mon Sep 17 00:00:00 2001 From: "tommi@webrtc.org" <tommi@webrtc.org@4adac7df-926f-26a2-2b94-8c16560cd09d> Date: Tue, 15 Jul 2014 19:22:37 +0000 Subject: [PATCH] Minor refactoring of StatsCollector. * Make GetTimeNow a static method in the cc file. * Make GetTransportIdFromProxy a static method as well and not a class method. The second change is in preparation of removing the proxy_to_transport_ member variable which isn't needed and is just a copy from the session stats. R=xians@webrtc.org Review URL: https://webrtc-codereview.appspot.com/20959004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@6696 4adac7df-926f-26a2-2b94-8c16560cd09d --- talk/app/webrtc/statscollector.cc | 54 +++++++++++++++++-------------- talk/app/webrtc/statscollector.h | 4 --- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/talk/app/webrtc/statscollector.cc b/talk/app/webrtc/statscollector.cc index dd615ab89..b165841aa 100644 --- a/talk/app/webrtc/statscollector.cc +++ b/talk/app/webrtc/statscollector.cc @@ -236,6 +236,32 @@ void StatsReport::ReplaceValue(StatsReport::StatsValueName name, namespace { typedef std::map<std::string, StatsReport> StatsMap; +double GetTimeNow() { + return talk_base::Timing::WallTimeNow() * talk_base::kNumMillisecsPerSec; +} + +bool GetTransportIdFromProxy(const cricket::ProxyTransportMap& map, + const std::string& proxy, + std::string* transport) { + // TODO(hta): Remove handling of empty proxy name once tests do not use it. + if (proxy.empty()) { + transport->clear(); + return true; + } + + cricket::ProxyTransportMap::const_iterator found = map.find(proxy); + if (found == map.end()) { + LOG(LS_ERROR) << "No transport ID mapping for " << proxy; + return false; + } + + std::ostringstream ost; + // Component 1 is always used for RTP. + ost << "Channel-" << found->second << "-1"; + *transport = ost.str(); + return true; +} + std::string StatsId(const std::string& type, const std::string& id) { return type + "_" + id; } @@ -902,7 +928,8 @@ void StatsCollector::ExtractVoiceInfo() { return; } std::string transport_id; - if (!GetTransportIdFromProxy(session_->voice_channel()->content_name(), + if (!GetTransportIdFromProxy(proxy_to_transport_, + session_->voice_channel()->content_name(), &transport_id)) { LOG(LS_ERROR) << "Failed to get transport name for proxy " << session_->voice_channel()->content_name(); @@ -929,7 +956,8 @@ void StatsCollector::ExtractVideoInfo( return; } std::string transport_id; - if (!GetTransportIdFromProxy(session_->video_channel()->content_name(), + if (!GetTransportIdFromProxy(proxy_to_transport_, + session_->video_channel()->content_name(), &transport_id)) { LOG(LS_ERROR) << "Failed to get transport name for proxy " << session_->video_channel()->content_name(); @@ -946,28 +974,6 @@ void StatsCollector::ExtractVideoInfo( } } -double StatsCollector::GetTimeNow() { - return talk_base::Timing::WallTimeNow() * talk_base::kNumMillisecsPerSec; -} - -bool StatsCollector::GetTransportIdFromProxy(const std::string& proxy, - std::string* transport) { - // TODO(hta): Remove handling of empty proxy name once tests do not use it. - if (proxy.empty()) { - transport->clear(); - return true; - } - if (proxy_to_transport_.find(proxy) == proxy_to_transport_.end()) { - LOG(LS_ERROR) << "No transport ID mapping for " << proxy; - return false; - } - std::ostringstream ost; - // Component 1 is always used for RTP. - ost << "Channel-" << proxy_to_transport_[proxy] << "-1"; - *transport = ost.str(); - return true; -} - StatsReport* StatsCollector::GetReport(const std::string& type, const std::string& id, TrackDirection direction) { diff --git a/talk/app/webrtc/statscollector.h b/talk/app/webrtc/statscollector.h index f51cee842..a444da482 100644 --- a/talk/app/webrtc/statscollector.h +++ b/talk/app/webrtc/statscollector.h @@ -82,9 +82,6 @@ class StatsCollector { // Prepare an SSRC report for the given remote ssrc. Used internally. StatsReport* PrepareRemoteReport(uint32 ssrc, const std::string& transport, TrackDirection direction); - // Extracts the ID of a Transport belonging to an SSRC. Used internally. - bool GetTransportIdFromProxy(const std::string& proxy, - std::string* transport_id); // Method used by the unittest to force a update of stats since UpdateStats() // that occur less than kMinGatherStatsPeriod number of ms apart will be @@ -105,7 +102,6 @@ class StatsCollector { void ExtractSessionInfo(); void ExtractVoiceInfo(); void ExtractVideoInfo(PeerConnectionInterface::StatsOutputLevel level); - double GetTimeNow(); void BuildSsrcToTransportId(); webrtc::StatsReport* GetOrCreateReport(const std::string& type, const std::string& id,