Change MockStatsObserver to grab values inside of OnComplete.
This is done since StatsReportCopyable is going away and the list of supported properties of the mock class is known. StatsReports holds a list of pointers to objects that cannot be cached, so this is a simple way to grab the values when they're available. R=perkj@webrtc.org Review URL: https://webrtc-codereview.appspot.com/32859004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7932 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
e728ee03ba
commit
209df9bf77
@ -117,67 +117,81 @@ class MockDataChannelObserver : public webrtc::DataChannelObserver {
|
|||||||
|
|
||||||
class MockStatsObserver : public webrtc::StatsObserver {
|
class MockStatsObserver : public webrtc::StatsObserver {
|
||||||
public:
|
public:
|
||||||
MockStatsObserver()
|
MockStatsObserver() : called_(false), stats_() {}
|
||||||
: called_(false) {}
|
|
||||||
virtual ~MockStatsObserver() {}
|
virtual ~MockStatsObserver() {}
|
||||||
|
|
||||||
virtual void OnComplete(const StatsReports& reports) {
|
virtual void OnComplete(const StatsReports& reports) {
|
||||||
|
ASSERT(!called_);
|
||||||
called_ = true;
|
called_ = true;
|
||||||
reports_.clear();
|
memset(&stats_, sizeof(stats_), 0);
|
||||||
reports_.reserve(reports.size());
|
stats_.number_of_reports = reports.size();
|
||||||
StatsReports::const_iterator it;
|
for (const auto* r : reports) {
|
||||||
for (it = reports.begin(); it != reports.end(); ++it)
|
if (r->type == StatsReport::kStatsReportTypeSsrc) {
|
||||||
reports_.push_back(StatsReportCopyable(*(*it)));
|
GetIntValue(r, StatsReport::kStatsValueNameAudioOutputLevel,
|
||||||
|
&stats_.audio_output_level);
|
||||||
|
GetIntValue(r, StatsReport::kStatsValueNameAudioInputLevel,
|
||||||
|
&stats_.audio_input_level);
|
||||||
|
GetIntValue(r, StatsReport::kStatsValueNameBytesReceived,
|
||||||
|
&stats_.bytes_received);
|
||||||
|
GetIntValue(r, StatsReport::kStatsValueNameBytesSent,
|
||||||
|
&stats_.bytes_sent);
|
||||||
|
} else if (r->type == StatsReport::kStatsReportTypeBwe) {
|
||||||
|
GetIntValue(r, StatsReport::kStatsValueNameAvailableReceiveBandwidth,
|
||||||
|
&stats_.available_receive_bandwidth);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool called() const { return called_; }
|
bool called() const { return called_; }
|
||||||
size_t number_of_reports() const { return reports_.size(); }
|
size_t number_of_reports() const { return stats_.number_of_reports; }
|
||||||
|
|
||||||
int AudioOutputLevel() {
|
int AudioOutputLevel() const {
|
||||||
return GetStatsValue(StatsReport::kStatsReportTypeSsrc,
|
ASSERT(called_);
|
||||||
StatsReport::kStatsValueNameAudioOutputLevel);
|
return stats_.audio_output_level;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AudioInputLevel() {
|
int AudioInputLevel() const {
|
||||||
return GetStatsValue(StatsReport::kStatsReportTypeSsrc,
|
ASSERT(called_);
|
||||||
StatsReport::kStatsValueNameAudioInputLevel);
|
return stats_.audio_input_level;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BytesReceived() {
|
int BytesReceived() const {
|
||||||
return GetStatsValue(StatsReport::kStatsReportTypeSsrc,
|
ASSERT(called_);
|
||||||
StatsReport::kStatsValueNameBytesReceived);
|
return stats_.bytes_received;
|
||||||
}
|
}
|
||||||
|
|
||||||
int BytesSent() {
|
int BytesSent() const {
|
||||||
return GetStatsValue(StatsReport::kStatsReportTypeSsrc,
|
ASSERT(called_);
|
||||||
StatsReport::kStatsValueNameBytesSent);
|
return stats_.bytes_sent;
|
||||||
}
|
}
|
||||||
|
|
||||||
int AvailableReceiveBandwidth() {
|
int AvailableReceiveBandwidth() const {
|
||||||
return GetStatsValue(StatsReport::kStatsReportTypeBwe,
|
ASSERT(called_);
|
||||||
StatsReport::kStatsValueNameAvailableReceiveBandwidth);
|
return stats_.available_receive_bandwidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int GetStatsValue(const std::string& type, StatsReport::StatsValueName name) {
|
bool GetIntValue(const StatsReport* report,
|
||||||
if (reports_.empty()) {
|
StatsReport::StatsValueName name,
|
||||||
return 0;
|
int* value) {
|
||||||
}
|
for (const auto& v : report->values) {
|
||||||
for (size_t i = 0; i < reports_.size(); ++i) {
|
if (v.name == name) {
|
||||||
if (reports_[i].type != type)
|
*value = rtc::FromString<int>(v.value);
|
||||||
continue;
|
return true;
|
||||||
webrtc::StatsReport::Values::const_iterator it =
|
|
||||||
reports_[i].values.begin();
|
|
||||||
for (; it != reports_[i].values.end(); ++it) {
|
|
||||||
if (it->name == name) {
|
|
||||||
return rtc::FromString<int>(it->value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
return false;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool called_;
|
bool called_;
|
||||||
std::vector<StatsReportCopyable> reports_;
|
struct {
|
||||||
|
size_t number_of_reports;
|
||||||
|
int audio_output_level;
|
||||||
|
int audio_input_level;
|
||||||
|
int bytes_received;
|
||||||
|
int bytes_sent;
|
||||||
|
int available_receive_bandwidth;
|
||||||
|
} stats_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace webrtc
|
} // namespace webrtc
|
||||||
|
Loading…
x
Reference in New Issue
Block a user