зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1225722 - Modularize RTCStatsIdGenerator::RewriteIds somewhat. r=bwc
Differential Revision: https://phabricator.services.mozilla.com/D135864
This commit is contained in:
Родитель
2b179f4152
Коммит
362e85af4b
|
@ -2979,9 +2979,8 @@ RefPtr<dom::RTCStatsReportPromise> PeerConnectionImpl::GetStats(
|
||||||
->Then(
|
->Then(
|
||||||
mThread, __func__,
|
mThread, __func__,
|
||||||
[report = std::move(report), idGen = mIdGenerator](
|
[report = std::move(report), idGen = mIdGenerator](
|
||||||
const nsTArray<UniquePtr<dom::RTCStatsCollection>>&
|
nsTArray<UniquePtr<dom::RTCStatsCollection>> aStats) mutable {
|
||||||
aStats) mutable {
|
idGen->RewriteIds(std::move(aStats), report.get());
|
||||||
idGen->RewriteIds(aStats, report.get());
|
|
||||||
return dom::RTCStatsReportPromise::CreateAndResolve(
|
return dom::RTCStatsReportPromise::CreateAndResolve(
|
||||||
std::move(report), __func__);
|
std::move(report), __func__);
|
||||||
},
|
},
|
||||||
|
|
|
@ -166,9 +166,9 @@ already_AddRefed<Promise> RTCRtpReceiver::GetStats() {
|
||||||
->Then(
|
->Then(
|
||||||
mMainThread, __func__,
|
mMainThread, __func__,
|
||||||
[promise, window = mWindow, idGen = mIdGenerator](
|
[promise, window = mWindow, idGen = mIdGenerator](
|
||||||
const nsTArray<UniquePtr<RTCStatsCollection>>& aStats) {
|
nsTArray<UniquePtr<RTCStatsCollection>> aStats) {
|
||||||
RTCStatsCollection opaqueStats;
|
RTCStatsCollection opaqueStats;
|
||||||
idGen->RewriteIds(aStats, &opaqueStats);
|
idGen->RewriteIds(std::move(aStats), &opaqueStats);
|
||||||
|
|
||||||
RefPtr<RTCStatsReport> report(new RTCStatsReport(window));
|
RefPtr<RTCStatsReport> report(new RTCStatsReport(window));
|
||||||
report->Incorporate(opaqueStats);
|
report->Incorporate(opaqueStats);
|
||||||
|
|
|
@ -8,8 +8,8 @@
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
#include "mozilla/dom/RTCStatsReportBinding.h"
|
|
||||||
#include "mozilla/RandomNum.h"
|
#include "mozilla/RandomNum.h"
|
||||||
|
#include "RTCStatsReport.h"
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ RTCStatsIdGenerator::RTCStatsIdGenerator()
|
||||||
: mSalt(RandomUint64().valueOr(0xa5a5a5a5)), mCounter(0) {}
|
: mSalt(RandomUint64().valueOr(0xa5a5a5a5)), mCounter(0) {}
|
||||||
|
|
||||||
void RTCStatsIdGenerator::RewriteIds(
|
void RTCStatsIdGenerator::RewriteIds(
|
||||||
const nsTArray<UniquePtr<dom::RTCStatsCollection>>& aFromStats,
|
nsTArray<UniquePtr<dom::RTCStatsCollection>> aFromStats,
|
||||||
dom::RTCStatsCollection* aIntoReport) {
|
dom::RTCStatsCollection* aIntoReport) {
|
||||||
// Rewrite an Optional id
|
// Rewrite an Optional id
|
||||||
auto rewriteId = [&](dom::Optional<nsString>& id) {
|
auto rewriteId = [&](dom::Optional<nsString>& id) {
|
||||||
|
@ -26,13 +26,10 @@ void RTCStatsIdGenerator::RewriteIds(
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto assignWithOpaqueIds = [&](auto& aSource, auto& aDest) {
|
auto rewriteIds = [&](auto& aList) {
|
||||||
for (auto& stat : aSource) {
|
for (auto& stat : aList) {
|
||||||
rewriteId(stat.mId);
|
rewriteId(stat.mId);
|
||||||
}
|
}
|
||||||
if (!aDest.AppendElements(aSource, fallible)) {
|
|
||||||
mozalloc_handle_oom(0);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
auto rewriteRemoteIds = [&](auto& aList) {
|
auto rewriteRemoteIds = [&](auto& aList) {
|
||||||
|
@ -49,54 +46,37 @@ void RTCStatsIdGenerator::RewriteIds(
|
||||||
|
|
||||||
// Involves a lot of copying, since webidl dictionaries don't have
|
// Involves a lot of copying, since webidl dictionaries don't have
|
||||||
// move semantics. Oh well.
|
// move semantics. Oh well.
|
||||||
for (const auto& stats : aFromStats) {
|
|
||||||
for (auto& stat : stats->mIceCandidatePairStats) {
|
|
||||||
rewriteId(stat.mLocalCandidateId);
|
|
||||||
rewriteId(stat.mRemoteCandidateId);
|
|
||||||
};
|
|
||||||
assignWithOpaqueIds(stats->mIceCandidatePairStats,
|
|
||||||
aIntoReport->mIceCandidatePairStats);
|
|
||||||
|
|
||||||
assignWithOpaqueIds(stats->mIceCandidateStats,
|
// Create a temporary to avoid double-rewriting any stats already in
|
||||||
aIntoReport->mIceCandidateStats);
|
// aIntoReport.
|
||||||
|
auto stats = MakeUnique<dom::RTCStatsCollection>();
|
||||||
|
dom::FlattenStats(std::move(aFromStats), stats.get());
|
||||||
|
|
||||||
rewriteRemoteIds(stats->mInboundRtpStreamStats);
|
for (auto& stat : stats->mIceCandidatePairStats) {
|
||||||
assignWithOpaqueIds(stats->mInboundRtpStreamStats,
|
rewriteId(stat.mLocalCandidateId);
|
||||||
aIntoReport->mInboundRtpStreamStats);
|
rewriteId(stat.mRemoteCandidateId);
|
||||||
|
};
|
||||||
|
rewriteIds(stats->mIceCandidatePairStats);
|
||||||
|
|
||||||
rewriteRemoteIds(stats->mOutboundRtpStreamStats);
|
rewriteIds(stats->mIceCandidateStats);
|
||||||
assignWithOpaqueIds(stats->mOutboundRtpStreamStats,
|
|
||||||
aIntoReport->mOutboundRtpStreamStats);
|
|
||||||
|
|
||||||
rewriteLocalIds(stats->mRemoteInboundRtpStreamStats);
|
rewriteRemoteIds(stats->mInboundRtpStreamStats);
|
||||||
assignWithOpaqueIds(stats->mRemoteInboundRtpStreamStats,
|
rewriteIds(stats->mInboundRtpStreamStats);
|
||||||
aIntoReport->mRemoteInboundRtpStreamStats);
|
|
||||||
|
|
||||||
rewriteLocalIds(stats->mRemoteOutboundRtpStreamStats);
|
rewriteRemoteIds(stats->mOutboundRtpStreamStats);
|
||||||
assignWithOpaqueIds(stats->mRemoteOutboundRtpStreamStats,
|
rewriteIds(stats->mOutboundRtpStreamStats);
|
||||||
aIntoReport->mRemoteOutboundRtpStreamStats);
|
|
||||||
|
|
||||||
assignWithOpaqueIds(stats->mRtpContributingSourceStats,
|
rewriteLocalIds(stats->mRemoteInboundRtpStreamStats);
|
||||||
aIntoReport->mRtpContributingSourceStats);
|
rewriteIds(stats->mRemoteInboundRtpStreamStats);
|
||||||
assignWithOpaqueIds(stats->mTrickledIceCandidateStats,
|
|
||||||
aIntoReport->mTrickledIceCandidateStats);
|
rewriteLocalIds(stats->mRemoteOutboundRtpStreamStats);
|
||||||
assignWithOpaqueIds(stats->mDataChannelStats,
|
rewriteIds(stats->mRemoteOutboundRtpStreamStats);
|
||||||
aIntoReport->mDataChannelStats);
|
|
||||||
if (!aIntoReport->mRawLocalCandidates.AppendElements(
|
rewriteIds(stats->mRtpContributingSourceStats);
|
||||||
stats->mRawLocalCandidates, fallible) ||
|
rewriteIds(stats->mTrickledIceCandidateStats);
|
||||||
!aIntoReport->mRawRemoteCandidates.AppendElements(
|
rewriteIds(stats->mDataChannelStats);
|
||||||
stats->mRawRemoteCandidates, fallible) ||
|
|
||||||
!aIntoReport->mVideoFrameHistories.AppendElements(
|
dom::MergeStats(std::move(stats), aIntoReport);
|
||||||
stats->mVideoFrameHistories, fallible) ||
|
|
||||||
!aIntoReport->mBandwidthEstimations.AppendElements(
|
|
||||||
stats->mBandwidthEstimations, fallible)) {
|
|
||||||
// XXX(Bug 1632090) Instead of extending the array 1-by-1
|
|
||||||
// (which might involve multiple reallocations) and
|
|
||||||
// potentially crashing here, SetCapacity could be called
|
|
||||||
// outside the loop once.
|
|
||||||
mozalloc_handle_oom(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsString RTCStatsIdGenerator::Id(const nsString& aKey) {
|
nsString RTCStatsIdGenerator::Id(const nsString& aKey) {
|
||||||
|
|
|
@ -25,9 +25,8 @@ class RTCStatsIdGenerator {
|
||||||
RTCStatsIdGenerator();
|
RTCStatsIdGenerator();
|
||||||
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RTCStatsIdGenerator);
|
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RTCStatsIdGenerator);
|
||||||
|
|
||||||
void RewriteIds(
|
void RewriteIds(nsTArray<UniquePtr<dom::RTCStatsCollection>> aFromStats,
|
||||||
const nsTArray<UniquePtr<dom::RTCStatsCollection>>& aFromStats,
|
dom::RTCStatsCollection* aIntoReport);
|
||||||
dom::RTCStatsCollection* aIntoReport);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual ~RTCStatsIdGenerator(){};
|
virtual ~RTCStatsIdGenerator(){};
|
||||||
|
|
|
@ -130,4 +130,40 @@ void RTCStatsReport::Set(const nsAString& aKey, JS::Handle<JSObject*> aValue,
|
||||||
RTCStatsReport_Binding::MaplikeHelpers::Set(this, aKey, aValue, aRv);
|
RTCStatsReport_Binding::MaplikeHelpers::Set(this, aKey, aValue, aRv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MergeStats(UniquePtr<dom::RTCStatsCollection> aFromStats,
|
||||||
|
dom::RTCStatsCollection* aIntoStats) {
|
||||||
|
auto move = [&](auto& aSource, auto& aDest) {
|
||||||
|
if (!aDest.AppendElements(std::move(aSource), fallible)) {
|
||||||
|
mozalloc_handle_oom(0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
move(aFromStats->mIceCandidatePairStats, aIntoStats->mIceCandidatePairStats);
|
||||||
|
move(aFromStats->mIceCandidateStats, aIntoStats->mIceCandidateStats);
|
||||||
|
move(aFromStats->mInboundRtpStreamStats, aIntoStats->mInboundRtpStreamStats);
|
||||||
|
move(aFromStats->mOutboundRtpStreamStats,
|
||||||
|
aIntoStats->mOutboundRtpStreamStats);
|
||||||
|
move(aFromStats->mRemoteInboundRtpStreamStats,
|
||||||
|
aIntoStats->mRemoteInboundRtpStreamStats);
|
||||||
|
move(aFromStats->mRemoteOutboundRtpStreamStats,
|
||||||
|
aIntoStats->mRemoteOutboundRtpStreamStats);
|
||||||
|
move(aFromStats->mCodecStats, aIntoStats->mCodecStats);
|
||||||
|
move(aFromStats->mRtpContributingSourceStats,
|
||||||
|
aIntoStats->mRtpContributingSourceStats);
|
||||||
|
move(aFromStats->mTrickledIceCandidateStats,
|
||||||
|
aIntoStats->mTrickledIceCandidateStats);
|
||||||
|
move(aFromStats->mDataChannelStats, aIntoStats->mDataChannelStats);
|
||||||
|
move(aFromStats->mRawLocalCandidates, aIntoStats->mRawLocalCandidates);
|
||||||
|
move(aFromStats->mRawRemoteCandidates, aIntoStats->mRawRemoteCandidates);
|
||||||
|
move(aFromStats->mVideoFrameHistories, aIntoStats->mVideoFrameHistories);
|
||||||
|
move(aFromStats->mBandwidthEstimations, aIntoStats->mBandwidthEstimations);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FlattenStats(nsTArray<UniquePtr<dom::RTCStatsCollection>> aFromStats,
|
||||||
|
dom::RTCStatsCollection* aIntoStats) {
|
||||||
|
for (auto& stats : aFromStats) {
|
||||||
|
MergeStats(std::move(stats), aIntoStats);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace mozilla::dom
|
} // namespace mozilla::dom
|
||||||
|
|
|
@ -143,6 +143,12 @@ class RTCStatsReport final : public nsWrapperCache {
|
||||||
nsCOMPtr<nsPIDOMWindowInner> mParent;
|
nsCOMPtr<nsPIDOMWindowInner> mParent;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void MergeStats(UniquePtr<dom::RTCStatsCollection> aFromStats,
|
||||||
|
dom::RTCStatsCollection* aIntoStats);
|
||||||
|
|
||||||
|
void FlattenStats(nsTArray<UniquePtr<dom::RTCStatsCollection>> aFromStats,
|
||||||
|
dom::RTCStatsCollection* aIntoStats);
|
||||||
|
|
||||||
} // namespace dom
|
} // namespace dom
|
||||||
} // namespace mozilla
|
} // namespace mozilla
|
||||||
|
|
||||||
|
|
Загрузка…
Ссылка в новой задаче