Return false if PeerConnection::GetStats() is called on invalid tracks

Before calling StatsCollctor::GetStats() in PeerConnection::GetStats(), check if the track is valid. If not, return false.
A track is invalid if it is not a nullptr and there is no report data for it.

BUG=webrtc:6652

Review-Url: https://codereview.webrtc.org/2470023004
Cr-Commit-Position: refs/heads/master@{#14934}
This commit is contained in:
zhihuang 2016-11-04 11:38:15 -07:00 committed by Commit bot
parent 3326d0ac82
commit e9e94c3fee
4 changed files with 16 additions and 4 deletions

View File

@ -886,6 +886,13 @@ bool PeerConnection::GetStats(StatsObserver* observer,
}
stats_->UpdateStats(level);
// The StatsCollector is used to tell if a track is valid because it may
// remember tracks that the PeerConnection previously removed.
if (track && !stats_->IsValidTrack(track->id())) {
LOG(LS_WARNING) << "GetStats is called with an invalid track: "
<< track->id();
return false;
}
signaling_thread()->Post(RTC_FROM_HERE, this, MSG_GETSTATS,
new GetStatsMsg(observer, track));
return true;

View File

@ -1577,10 +1577,7 @@ TEST_F(PeerConnectionInterfaceTest, GetStatsForVideoTrack) {
}
// Test that we don't get statistics for an invalid track.
// TODO(tommi): Fix this test. DoGetStats will return true
// for the unknown track (since GetStats is async), but no
// data is returned for the track.
TEST_F(PeerConnectionInterfaceTest, DISABLED_GetStatsForInvalidTrack) {
TEST_F(PeerConnectionInterfaceTest, GetStatsForInvalidTrack) {
InitiateCall();
rtc::scoped_refptr<AudioTrackInterface> unknown_audio_track(
pc_factory_->CreateAudioTrack("unknown track", NULL));

View File

@ -549,6 +549,11 @@ StatsReport* StatsCollector::PrepareReport(
return report;
}
bool StatsCollector::IsValidTrack(const std::string& track_id) {
return reports_.Find(StatsReport::NewTypedId(
StatsReport::kStatsReportTypeTrack, track_id)) != nullptr;
}
StatsReport* StatsCollector::AddCertificateReports(
const rtc::SSLCertificate* cert) {
RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent());

View File

@ -78,6 +78,9 @@ class StatsCollector {
const StatsReport::Id& transport_id,
StatsReport::Direction direction);
// A track is invalid if there is no report data for it.
bool IsValidTrack(const std::string& track_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
// ignored.