Clean up StatsObserver's OnComplete methods (address TODOs).
R=perkj@webrtc.org Review URL: https://webrtc-codereview.appspot.com/29239004 git-svn-id: http://webrtc.googlecode.com/svn/trunk@7898 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
@@ -131,6 +131,7 @@ using webrtc::SessionDescriptionInterface;
|
|||||||
using webrtc::SetSessionDescriptionObserver;
|
using webrtc::SetSessionDescriptionObserver;
|
||||||
using webrtc::StatsObserver;
|
using webrtc::StatsObserver;
|
||||||
using webrtc::StatsReport;
|
using webrtc::StatsReport;
|
||||||
|
using webrtc::StatsReports;
|
||||||
using webrtc::VideoRendererInterface;
|
using webrtc::VideoRendererInterface;
|
||||||
using webrtc::VideoSourceInterface;
|
using webrtc::VideoSourceInterface;
|
||||||
using webrtc::VideoTrackInterface;
|
using webrtc::VideoTrackInterface;
|
||||||
@@ -985,7 +986,7 @@ class StatsObserverWrapper : public StatsObserver {
|
|||||||
|
|
||||||
virtual ~StatsObserverWrapper() {}
|
virtual ~StatsObserverWrapper() {}
|
||||||
|
|
||||||
virtual void OnComplete(const std::vector<StatsReport>& reports) OVERRIDE {
|
virtual void OnComplete(const StatsReports& reports) OVERRIDE {
|
||||||
ScopedLocalRefFrame local_ref_frame(jni());
|
ScopedLocalRefFrame local_ref_frame(jni());
|
||||||
jobjectArray j_reports = ReportsToJava(jni(), reports);
|
jobjectArray j_reports = ReportsToJava(jni(), reports);
|
||||||
jmethodID m = GetMethodID(jni(), *j_observer_class_, "onComplete",
|
jmethodID m = GetMethodID(jni(), *j_observer_class_, "onComplete",
|
||||||
@@ -996,22 +997,22 @@ class StatsObserverWrapper : public StatsObserver {
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
jobjectArray ReportsToJava(
|
jobjectArray ReportsToJava(
|
||||||
JNIEnv* jni, const std::vector<StatsReport>& reports) {
|
JNIEnv* jni, const StatsReports& reports) {
|
||||||
jobjectArray reports_array = jni->NewObjectArray(
|
jobjectArray reports_array = jni->NewObjectArray(
|
||||||
reports.size(), *j_stats_report_class_, NULL);
|
reports.size(), *j_stats_report_class_, NULL);
|
||||||
for (int i = 0; i < reports.size(); ++i) {
|
int i = 0;
|
||||||
|
for (const auto* report : reports) {
|
||||||
ScopedLocalRefFrame local_ref_frame(jni);
|
ScopedLocalRefFrame local_ref_frame(jni);
|
||||||
const StatsReport& report = reports[i];
|
jstring j_id = JavaStringFromStdString(jni, report->id);
|
||||||
jstring j_id = JavaStringFromStdString(jni, report.id);
|
jstring j_type = JavaStringFromStdString(jni, report->type);
|
||||||
jstring j_type = JavaStringFromStdString(jni, report.type);
|
jobjectArray j_values = ValuesToJava(jni, report->values);
|
||||||
jobjectArray j_values = ValuesToJava(jni, report.values);
|
|
||||||
jobject j_report = jni->NewObject(*j_stats_report_class_,
|
jobject j_report = jni->NewObject(*j_stats_report_class_,
|
||||||
j_stats_report_ctor_,
|
j_stats_report_ctor_,
|
||||||
j_id,
|
j_id,
|
||||||
j_type,
|
j_type,
|
||||||
report.timestamp,
|
report->timestamp,
|
||||||
j_values);
|
j_values);
|
||||||
jni->SetObjectArrayElement(reports_array, i, j_report);
|
jni->SetObjectArrayElement(reports_array, i++, j_report);
|
||||||
}
|
}
|
||||||
return reports_array;
|
return reports_array;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,12 +123,11 @@ class RTCStatsObserver : public StatsObserver {
|
|||||||
_peerConnection = peerConnection;
|
_peerConnection = peerConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void OnComplete(const std::vector<StatsReport>& reports) OVERRIDE {
|
virtual void OnComplete(const StatsReports& reports) OVERRIDE {
|
||||||
NSMutableArray* stats = [NSMutableArray arrayWithCapacity:reports.size()];
|
NSMutableArray* stats = [NSMutableArray arrayWithCapacity:reports.size()];
|
||||||
std::vector<StatsReport>::const_iterator it = reports.begin();
|
for (const auto* report : reports) {
|
||||||
for (; it != reports.end(); ++it) {
|
|
||||||
RTCStatsReport* statsReport =
|
RTCStatsReport* statsReport =
|
||||||
[[RTCStatsReport alloc] initWithStatsReport:*it];
|
[[RTCStatsReport alloc] initWithStatsReport:*report];
|
||||||
[stats addObject:statsReport];
|
[stats addObject:statsReport];
|
||||||
}
|
}
|
||||||
[_delegate peerConnection:_peerConnection didGetStats:stats];
|
[_delegate peerConnection:_peerConnection didGetStats:stats];
|
||||||
|
|||||||
@@ -113,18 +113,7 @@ class StreamCollectionInterface : public rtc::RefCountInterface {
|
|||||||
|
|
||||||
class StatsObserver : public rtc::RefCountInterface {
|
class StatsObserver : public rtc::RefCountInterface {
|
||||||
public:
|
public:
|
||||||
// TODO(tommi): Remove.
|
virtual void OnComplete(const StatsReports& reports) = 0;
|
||||||
virtual void OnComplete(const std::vector<StatsReport>& reports) {}
|
|
||||||
|
|
||||||
// TODO(tommi): Make pure virtual and remove implementation.
|
|
||||||
virtual void OnComplete(const StatsReports& reports) {
|
|
||||||
std::vector<StatsReportCopyable> report_copies;
|
|
||||||
for (size_t i = 0; i < reports.size(); ++i)
|
|
||||||
report_copies.push_back(StatsReportCopyable(*reports[i]));
|
|
||||||
std::vector<StatsReport>* r =
|
|
||||||
reinterpret_cast<std::vector<StatsReport>*>(&report_copies);
|
|
||||||
OnComplete(*r);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~StatsObserver() {}
|
virtual ~StatsObserver() {}
|
||||||
|
|||||||
Reference in New Issue
Block a user