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
This commit is contained in:
tommi@webrtc.org 2014-07-15 19:22:37 +00:00
parent 42fe4350fe
commit 47218956fc
2 changed files with 30 additions and 28 deletions

View File

@ -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) {

View File

@ -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,