Bug 1151139: Simplify how we choose which streams to gather stats from. r=mt

This commit is contained in:
Byron Campen [:bwc] 2015-04-03 17:27:57 -07:00
parent 6d99b864dc
commit 58d2647aa6
2 changed files with 27 additions and 37 deletions

View File

@ -323,7 +323,8 @@ namespace mozilla {
#ifdef MOZILLA_INTERNAL_API
RTCStatsQuery::RTCStatsQuery(bool internal) :
failed(false),
internalStats(internal) {
internalStats(internal),
grabAllLevels(false) {
}
RTCStatsQuery::~RTCStatsQuery() {
@ -2891,31 +2892,8 @@ PeerConnectionImpl::BuildStatsQuery_m(
}
}
// From the list of MediaPipelines, determine the set of NrIceMediaStreams
// we are interested in.
std::set<size_t> levelsToGrab;
if (aSelector) {
for (size_t p = 0; p < query->pipelines.Length(); ++p) {
size_t level = query->pipelines[p]->level();
levelsToGrab.insert(level);
}
} else {
// We want to grab all streams, so ignore the pipelines (this also ends up
// grabbing DataChannel streams, which is what we want)
for (size_t s = 0; s < mMedia->num_ice_media_streams(); ++s) {
levelsToGrab.insert(s);
}
}
for (auto s = levelsToGrab.begin(); s != levelsToGrab.end(); ++s) {
// TODO(bcampen@mozilla.com): I may need to revisit this for bundle.
// (Bug 786234)
RefPtr<NrIceMediaStream> temp(mMedia->ice_media_stream(*s));
RefPtr<TransportFlow> flow(mMedia->GetTransportFlow(*s, false));
// flow can be null for unused levels, such as unused DataChannels
if (temp && flow) {
query->streams.AppendElement(temp);
}
if (!aSelector) {
query->grabAllLevels = true;
}
return rv;
@ -3190,20 +3168,32 @@ PeerConnectionImpl::ExecuteStatsQuery_s(RTCStatsQuery *query) {
break;
}
}
if (!query->grabAllLevels) {
// If we're grabbing all levels, that means we want datachannels too,
// which don't have pipelines.
if (query->iceCtx->GetStream(p)) {
RecordIceStats_s(*query->iceCtx->GetStream(p),
query->internalStats,
query->now,
query->report);
}
}
}
// Gather stats from ICE
for (size_t s = 0; s != query->streams.Length(); ++s) {
RecordIceStats_s(*query->streams[s],
query->internalStats,
query->now,
query->report);
if (query->grabAllLevels) {
for (size_t i = 0; i < query->iceCtx->GetStreamCount(); ++i) {
if (query->iceCtx->GetStream(i)) {
RecordIceStats_s(*query->iceCtx->GetStream(i),
query->internalStats,
query->now,
query->report);
}
}
}
// NrIceCtx and NrIceMediaStream must be destroyed on STS, so it is not safe
// to dispatch them back to main.
// We clear streams first to maintain destruction order
query->streams.Clear();
// NrIceCtx must be destroyed on STS, so it is not safe
// to dispatch it back to main.
query->iceCtx = nullptr;
return NS_OK;
}

View File

@ -206,7 +206,7 @@ class RTCStatsQuery {
bool internalStats;
nsTArray<mozilla::RefPtr<mozilla::MediaPipeline>> pipelines;
mozilla::RefPtr<NrIceCtx> iceCtx;
nsTArray<mozilla::RefPtr<NrIceMediaStream>> streams;
bool grabAllLevels;
DOMHighResTimeStamp now;
};
#endif // MOZILLA_INTERNAL_API