Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  RTCStatsIdGenerator.cpp

  Sprache: C
 

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this file,
 * You can obtain one at http://mozilla.org/MPL/2.0/. */


#include "RTCStatsIdGenerator.h"

#include <type_traits>

#include "RTCStatsReport.h"
#include "WebrtcGlobal.h"
#include "mozilla/RandomNum.h"

namespace mozilla {

RTCStatsIdGenerator::RTCStatsIdGenerator()
    : mSalt(RandomUint64().valueOr(0xa5a5a5a5)), mCounter(0) {}

void RTCStatsIdGenerator::RewriteIds(
    nsTArray<UniquePtr<dom::RTCStatsCollection>> aFromStats,
    dom::RTCStatsCollection* aIntoReport) {
  // Rewrite an id, whether it's Optional<nsString> (non-required webidl
  // member) or a plain nsString (required webidl member).
  auto rewriteId = [&](auto& id) {
    using T = std::decay_t<decltype(id)>;
    if constexpr (std::is_same_v<T, dom::Optional<nsString>>) {
      if (id.WasPassed()) {
        id.Value() = Id(id.Value());
      }
    } else {
      if (!id.IsEmpty()) {
        id = Id(id);
      }
    }
  };

  auto rewriteIds = [&](auto& aList, auto... aParam) {
    for (auto& stat : aList) {
      (rewriteId(stat.*aParam), ...);
    }
  };

  // Involves a lot of copying, since webidl dictionaries don't have
  // move semantics. Oh well.

  // Create a temporary to avoid double-rewriting any stats already in
  // aIntoReport.
  auto stats = MakeUnique<dom::RTCStatsCollection>();
  dom::FlattenStats(std::move(aFromStats), stats.get());

  using S = dom::RTCStats;
  using CS = dom::RTCCodecStats;
  using ICS = dom::RTCIceCandidateStats;
  using ICPS = dom::RTCIceCandidatePairStats;
  using RSS = dom::RTCRtpStreamStats;
  using IRSS = dom::RTCInboundRtpStreamStats;
  using ORSS = dom::RTCOutboundRtpStreamStats;
  using RIRSS = dom::RTCRemoteInboundRtpStreamStats;
  using RORSS = dom::RTCRemoteOutboundRtpStreamStats;
  using TS = dom::RTCTransportStats;

  rewriteIds(stats->mIceCandidatePairStats, &S::mId, &ICPS::mTransportId,
             &ICPS::mLocalCandidateId, &ICPS::mRemoteCandidateId);
  rewriteIds(stats->mIceCandidateStats, &S::mId, &ICS::mTransportId);
  rewriteIds(stats->mInboundRtpStreamStats, &S::mId, &RSS::mTransportId,
             &IRSS::mRemoteId, &RSS::mCodecId);
  rewriteIds(stats->mOutboundRtpStreamStats, &S::mId, &RSS::mTransportId,
             &ORSS::mRemoteId, &RSS::mCodecId);
  rewriteIds(stats->mRemoteInboundRtpStreamStats, &S::mId, &RSS::mTransportId,
             &RIRSS::mLocalId, &RSS::mCodecId);
  rewriteIds(stats->mRemoteOutboundRtpStreamStats, &S::mId, &RSS::mTransportId,
             &RORSS::mLocalId, &RSS::mCodecId);
  rewriteIds(stats->mCodecStats, &S::mId, &CS::mTransportId);
  rewriteIds(stats->mRtpContributingSourceStats, &S::mId);
  rewriteIds(stats->mTrickledIceCandidateStats, &S::mId, &ICS::mTransportId);
  rewriteIds(stats->mDataChannelStats, &S::mId);
  rewriteIds(stats->mTransportStats, &S::mId, &TS::mSelectedCandidatePairId);

  dom::MergeStats(std::move(stats), aIntoReport);
}

nsString RTCStatsIdGenerator::Id(const nsString& aKey) {
  if (!aKey.Length()) {
    MOZ_ASSERT(aKey.Length(), "Stats IDs should never be empty.");
    return aKey;
  }
  if (mAllocated.find(aKey) == mAllocated.end()) {
    mAllocated[aKey] = Generate();
  }
  return mAllocated[aKey];
}

nsString RTCStatsIdGenerator::Generate() {
  auto random = RandomUint64().valueOr(0x1a22);
  auto idNum = static_cast<uint32_t>(mSalt ^ ((mCounter++ << 16) | random));
  nsString id;
  id.AppendInt(idNum, 16);  // Append as hex
  return id;
}

}  // namespace mozilla

Messung V0.5 in Prozent
C=88 H=94 G=90

¤ Dauer der Verarbeitung: 0.11 Sekunden  (vorverarbeitet am  2026-08-25) ¤

*© Formatika GbR, Deutschland






Wurzel

Suchen

PVS Prover

Isabelle Prover

NIST Cobol Testsuite

Cephes Mathematical Library

Vienna Development Method

Haftungshinweis

Die Informationen auf dieser Webseite wurden nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit, noch Qualität der bereit gestellten Informationen zugesichert.

Bemerkung:

Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.






                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Open Source Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik

Statistik
#Sources=141584
#Domains=752002