Bug 1602739 - P2 - make opaque stats IDs in PeerConnectionImpl;r=mjf

Differential Revision: https://phabricator.services.mozilla.com/D57949

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Nico Grunbaum 2019-12-20 20:20:34 +00:00
Родитель 271de92265
Коммит 8ef8e3598b
3 изменённых файлов: 83 добавлений и 23 удалений

Просмотреть файл

@ -315,7 +315,9 @@ var pedanticChecks = report => {
// Check that report is only-maplike
[...report.keys()].forEach(key => is(report[key], undefined,
`Report is not dictionary like, it lacks a property for key ${key}`));
report.forEach((statObj, mapKey) => {
info(`"${mapKey} = ${JSON.stringify(statObj, null, 2)}`);
});
// eslint-disable-next-line complexity
report.forEach((statObj, mapKey) => {
let tested = {};
@ -373,7 +375,8 @@ var pedanticChecks = report => {
if (isRemote) {
// local id
if (stat.localId) {
ok(report.has(stat.localId), "localId exists in report.");
ok(report.has(stat.localId),
`localId ${stat.localId} exists in report.`);
is(report.get(stat.localId).ssrc, stat.ssrc,
"remote ssrc and local ssrc match.");
is(report.get(stat.localId).remoteId, stat.id,
@ -382,7 +385,8 @@ var pedanticChecks = report => {
} else {
// remote id
if (stat.remoteId) {
ok(report.has(stat.remoteId), "remoteId exists in report.");
ok(report.has(stat.remoteId),
`remoteId ${stat.remoteId} exists in report.`);
is(report.get(stat.remoteId).ssrc, stat.ssrc,
"remote ssrc and local ssrc match.");
is(report.get(stat.remoteId).localId, stat.id,

Просмотреть файл

@ -312,6 +312,7 @@ PeerConnectionImpl::PeerConnectionImpl(const GlobalObject* aGlobal)
mPacketDumpEnabled(false),
mPacketDumpFlagsMutex("Packet dump flags mutex"),
mTimestampMaker(aGlobal),
mIdGenerator(new RTCStatsIdGenerator()),
listenPort(0),
connectPort(0),
connectStr(nullptr) {
@ -2738,7 +2739,9 @@ static UniquePtr<dom::RTCStatsCollection> GetSenderStats_s(
ssrc.apply([&s](uint32_t aSsrc) { s.mSsrc.Construct(aSsrc); });
s.mMediaType.Construct(kind); // mediaType is the old name for kind.
s.mKind.Construct(kind);
s.mRemoteId.Construct(remoteId);
if (remoteId.Length()) {
s.mRemoteId.Construct(remoteId);
}
s.mPacketsSent.Construct(aPipeline->RtpPacketsSent());
s.mBytesSent.Construct(aPipeline->RtpBytesSent());
@ -2816,6 +2819,35 @@ void PeerConnectionImpl::RecordConduitTelemetry() {
}));
}
template <class T>
void AssignWithOpaqueIds(dom::Sequence<T>& aSource, dom::Sequence<T>& aDest,
RefPtr<RTCStatsIdGenerator>& aGenerator) {
for (auto& stat : aSource) {
stat.mId.Value() = aGenerator->Id(stat.mId.Value());
}
aDest.AppendElements(aSource, fallible);
}
template <class T>
void RewriteRemoteIds(dom::Sequence<T>& aList,
RefPtr<RTCStatsIdGenerator>& aGenerator) {
for (auto& stat : aList) {
if (stat.mRemoteId.WasPassed()) {
stat.mRemoteId.Value() = aGenerator->Id(stat.mRemoteId.Value());
}
}
}
template <class T>
void RewriteLocalIds(dom::Sequence<T>& aList,
RefPtr<RTCStatsIdGenerator>& aGenerator) {
for (auto& stat : aList) {
if (stat.mLocalId.WasPassed()) {
stat.mLocalId.Value() = aGenerator->Id(stat.mLocalId.Value());
}
}
}
RefPtr<dom::RTCStatsReportPromise> PeerConnectionImpl::GetStats(
dom::MediaStreamTrack* aSelector, bool aInternalStats) {
nsTArray<RefPtr<dom::RTCStatsPromise>> promises;
@ -2900,32 +2932,53 @@ RefPtr<dom::RTCStatsReportPromise> PeerConnectionImpl::GetStats(
return dom::RTCStatsPromise::All(mThread, promises)
->Then(
mThread, __func__,
[report = std::move(report)](
[report = std::move(report), idGen = mIdGenerator](
const nsTArray<UniquePtr<dom::RTCStatsCollection>>&
aStats) mutable {
// Rewrite an Optional id
auto rewriteId = [&idGen](Optional<nsString>& id) {
if (id.WasPassed()) {
id.Value() = idGen->Id(id.Value());
}
};
// Involves a lot of copying, since webidl dictionaries don't have
// move semantics. Oh well.
for (const auto& stats : aStats) {
// Involves a lot of copying, since webidl dictionaries don't have
// move semantics. Oh well.
report->mIceCandidatePairStats.AppendElements(
stats->mIceCandidatePairStats, fallible);
report->mIceCandidateStats.AppendElements(
stats->mIceCandidateStats, fallible);
report->mInboundRtpStreamStats.AppendElements(
stats->mInboundRtpStreamStats, fallible);
report->mOutboundRtpStreamStats.AppendElements(
stats->mOutboundRtpStreamStats, fallible);
for (auto& stat : stats->mIceCandidatePairStats) {
rewriteId(stat.mLocalCandidateId);
rewriteId(stat.mRemoteCandidateId);
};
AssignWithOpaqueIds(stats->mIceCandidatePairStats,
report->mIceCandidatePairStats, idGen);
AssignWithOpaqueIds(stats->mIceCandidateStats,
report->mIceCandidateStats, idGen);
RewriteRemoteIds(stats->mInboundRtpStreamStats, idGen);
AssignWithOpaqueIds(stats->mInboundRtpStreamStats,
report->mInboundRtpStreamStats, idGen);
RewriteRemoteIds(stats->mOutboundRtpStreamStats, idGen);
AssignWithOpaqueIds(stats->mOutboundRtpStreamStats,
report->mOutboundRtpStreamStats, idGen);
RewriteLocalIds(stats->mRemoteInboundRtpStreamStats, idGen);
AssignWithOpaqueIds(stats->mRemoteInboundRtpStreamStats,
report->mRemoteInboundRtpStreamStats, idGen);
RewriteLocalIds(stats->mRemoteOutboundRtpStreamStats, idGen);
AssignWithOpaqueIds(stats->mRemoteOutboundRtpStreamStats,
report->mRemoteOutboundRtpStreamStats, idGen);
AssignWithOpaqueIds(stats->mRtpContributingSourceStats,
report->mRtpContributingSourceStats, idGen);
AssignWithOpaqueIds(stats->mTrickledIceCandidateStats,
report->mTrickledIceCandidateStats, idGen);
report->mRawLocalCandidates.AppendElements(
stats->mRawLocalCandidates, fallible);
report->mRawRemoteCandidates.AppendElements(
stats->mRawRemoteCandidates, fallible);
report->mRemoteInboundRtpStreamStats.AppendElements(
stats->mRemoteInboundRtpStreamStats, fallible);
report->mRemoteOutboundRtpStreamStats.AppendElements(
stats->mRemoteOutboundRtpStreamStats, fallible);
report->mRtpContributingSourceStats.AppendElements(
stats->mRtpContributingSourceStats, fallible);
report->mTrickledIceCandidateStats.AppendElements(
stats->mTrickledIceCandidateStats, fallible);
}
return dom::RTCStatsReportPromise::CreateAndResolve(
std::move(report), __func__);

Просмотреть файл

@ -40,6 +40,7 @@
#include "VideoSegment.h"
#include "mozilla/dom/RTCStatsReportBinding.h"
#include "mozilla/PeerIdentity.h"
#include "RTCStatsIdGenerator.h"
#include "RTCStatsReport.h"
namespace test {
@ -665,6 +666,8 @@ class PeerConnectionImpl final
dom::RTCStatsTimestampMaker mTimestampMaker;
RefPtr<RTCStatsIdGenerator> mIdGenerator;
public:
// these are temporary until the DataChannel Listen/Connect API is removed
unsigned short listenPort;