WebrtcGlobal.h (10501B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 #ifndef _WEBRTC_GLOBAL_H_ 6 #define _WEBRTC_GLOBAL_H_ 7 8 #include "WebrtcIPCTraits.h" 9 #include "ipc/EnumSerializer.h" 10 #include "ipc/IPCMessageUtilsSpecializations.h" 11 #include "mozilla/UniquePtr.h" 12 #include "mozilla/dom/BindingDeclarations.h" 13 #include "mozilla/dom/BindingIPCUtils.h" 14 #include "mozilla/dom/RTCDataChannelBinding.h" 15 #include "mozilla/dom/RTCStatsReportBinding.h" 16 17 typedef mozilla::dom::RTCStatsReportInternal StatsReport; 18 typedef nsTArray<mozilla::UniquePtr<StatsReport>> RTCReports; 19 typedef mozilla::dom::Sequence<nsString> WebrtcGlobalLog; 20 21 namespace mozilla { 22 namespace dom { 23 // Calls aFunction with all public members of aStats. 24 // Typical usage would have aFunction take a parameter pack. 25 // To avoid inconsistencies, this should be the only explicit list of the 26 // public RTCStatscollection members in C++. 27 template <typename Collection, typename Function> 28 static auto ForAllPublicRTCStatsCollectionMembers(Collection& aStats, 29 Function aFunction) { 30 static_assert(std::is_same_v<typename std::remove_const<Collection>::type, 31 RTCStatsCollection>, 32 "aStats must be a const or non-const RTCStatsCollection"); 33 return aFunction( 34 aStats.mInboundRtpStreamStats, aStats.mOutboundRtpStreamStats, 35 aStats.mRemoteInboundRtpStreamStats, aStats.mRemoteOutboundRtpStreamStats, 36 aStats.mMediaSourceStats, aStats.mVideoSourceStats, 37 aStats.mPeerConnectionStats, aStats.mRtpContributingSourceStats, 38 aStats.mIceCandidatePairStats, aStats.mIceCandidateStats, 39 aStats.mTrickledIceCandidateStats, aStats.mDataChannelStats, 40 aStats.mCodecStats); 41 } 42 43 // Calls aFunction with all members of aStats, including internal ones. 44 // Typical usage would have aFunction take a parameter pack. 45 // To avoid inconsistencies, this should be the only explicit list of the 46 // internal RTCStatscollection members in C++. 47 template <typename Collection, typename Function> 48 static auto ForAllRTCStatsCollectionMembers(Collection& aStats, 49 Function aFunction) { 50 static_assert(std::is_same_v<typename std::remove_const<Collection>::type, 51 RTCStatsCollection>, 52 "aStats must be a const or non-const RTCStatsCollection"); 53 return ForAllPublicRTCStatsCollectionMembers(aStats, [&](auto&... aMember) { 54 return aFunction(aMember..., aStats.mRawLocalCandidates, 55 aStats.mRawRemoteCandidates, aStats.mVideoFrameHistories, 56 aStats.mBandwidthEstimations); 57 }); 58 } 59 } // namespace dom 60 } // namespace mozilla 61 62 namespace IPC { 63 64 template <> 65 struct ParamTraits<mozilla::dom::RTCStatsType> 66 : public mozilla::dom::WebIDLEnumSerializer<mozilla::dom::RTCStatsType> {}; 67 68 template <> 69 struct ParamTraits<mozilla::dom::RTCStatsIceCandidatePairState> 70 : public mozilla::dom::WebIDLEnumSerializer< 71 mozilla::dom::RTCStatsIceCandidatePairState> {}; 72 73 template <> 74 struct ParamTraits<mozilla::dom::RTCIceCandidateType> 75 : public mozilla::dom::WebIDLEnumSerializer< 76 mozilla::dom::RTCIceCandidateType> {}; 77 78 template <> 79 struct ParamTraits<mozilla::dom::RTCBundlePolicy> 80 : public mozilla::dom::WebIDLEnumSerializer<mozilla::dom::RTCBundlePolicy> { 81 }; 82 83 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCIceServerInternal, mUrls, 84 mCredentialProvided, mUserNameProvided); 85 86 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCConfigurationInternal, 87 mBundlePolicy, mCertificatesProvided, 88 mIceServers, mIceTransportPolicy, 89 mPeerIdentityProvided, mSdpSemantics); 90 91 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCSdpParsingErrorInternal, 92 mLineNumber, mError); 93 94 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCSdpHistoryEntryInternal, 95 mTimestamp, mIsLocal, mSdp, mErrors); 96 97 template <> 98 struct ParamTraits<mozilla::dom::RTCStatsCollection> { 99 static void Write(MessageWriter* aWriter, 100 const mozilla::dom::RTCStatsCollection& aParam) { 101 mozilla::dom::ForAllRTCStatsCollectionMembers( 102 aParam, 103 [&](const auto&... aMember) { WriteParams(aWriter, aMember...); }); 104 } 105 106 static bool Read(MessageReader* aReader, 107 mozilla::dom::RTCStatsCollection* aResult) { 108 return mozilla::dom::ForAllRTCStatsCollectionMembers( 109 *aResult, 110 [&](auto&... aMember) { return ReadParams(aReader, aMember...); }); 111 } 112 }; 113 114 DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS( 115 mozilla::dom::RTCStatsReportInternal, mozilla::dom::RTCStatsCollection, 116 mClosed, mSdpHistory, mPcid, mBrowserId, mTimestamp, mCallDurationMs, 117 mIceRestarts, mIceRollbacks, mOfferer, mConfiguration); 118 119 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCStats, mId, mTimestamp, 120 mType); 121 122 DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS( 123 mozilla::dom::RTCIceCandidatePairStats, mozilla::dom::RTCStats, 124 mTransportId, mLocalCandidateId, mPriority, mNominated, mWritable, 125 mReadable, mRemoteCandidateId, mSelected, mComponentId, mState, mBytesSent, 126 mBytesReceived, mLastPacketSentTimestamp, mLastPacketReceivedTimestamp, 127 mTotalRoundTripTime, mResponsesReceived, mCurrentRoundTripTime); 128 129 DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS( 130 mozilla::dom::RTCIceCandidateStats, mozilla::dom::RTCStats, mCandidateType, 131 mPriority, mTransportId, mAddress, mRelayProtocol, mPort, mProtocol, 132 mProxied); 133 134 DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS( 135 mozilla::dom::RTCReceivedRtpStreamStats, mozilla::dom::RTCRtpStreamStats, 136 mPacketsReceived, mPacketsLost, mJitter, mDiscardedPackets, 137 mPacketsDiscarded); 138 139 DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS( 140 mozilla::dom::RTCInboundRtpStreamStats, 141 mozilla::dom::RTCReceivedRtpStreamStats, mTrackIdentifier, mRemoteId, 142 mFramesDecoded, mKeyFramesDecoded, mFramesDropped, mFrameWidth, 143 mFrameHeight, mFramesPerSecond, mQpSum, mTotalDecodeTime, 144 mTotalInterFrameDelay, mTotalSquaredInterFrameDelay, mPauseCount, 145 mTotalPausesDuration, mFreezeCount, mTotalFreezesDuration, 146 mLastPacketReceivedTimestamp, mHeaderBytesReceived, mFecPacketsReceived, 147 mFecPacketsDiscarded, mBytesReceived, mNackCount, mFirCount, mPliCount, 148 mTotalProcessingDelay, mEstimatedPlayoutTimestamp, mFramesReceived, 149 mJitterBufferDelay, mJitterBufferEmittedCount, mJitterBufferTargetDelay, 150 mJitterBufferMinimumDelay, mTotalSamplesReceived, mConcealedSamples, 151 mSilentConcealedSamples, mConcealmentEvents, 152 mInsertedSamplesForDeceleration, mRemovedSamplesForAcceleration, 153 mAudioLevel, mTotalAudioEnergy, mTotalSamplesDuration, 154 mFramesAssembledFromMultiplePackets, mTotalAssemblyTime); 155 156 DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS( 157 mozilla::dom::RTCRtpStreamStats, mozilla::dom::RTCStats, mSsrc, mKind, 158 mMediaType, mTransportId, mCodecId); 159 160 DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS( 161 mozilla::dom::RTCSentRtpStreamStats, mozilla::dom::RTCRtpStreamStats, 162 mPacketsSent, mBytesSent); 163 164 DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS( 165 mozilla::dom::RTCOutboundRtpStreamStats, 166 mozilla::dom::RTCSentRtpStreamStats, mRemoteId, mFramesEncoded, mQpSum, 167 mNackCount, mFirCount, mPliCount, mHeaderBytesSent, 168 mRetransmittedPacketsSent, mRetransmittedBytesSent, 169 mTotalEncodedBytesTarget, mFrameWidth, mFrameHeight, mFramesPerSecond, 170 mFramesSent, mHugeFramesSent, mTotalEncodeTime); 171 172 DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS( 173 mozilla::dom::RTCRemoteInboundRtpStreamStats, 174 mozilla::dom::RTCReceivedRtpStreamStats, mLocalId, mRoundTripTime, 175 mTotalRoundTripTime, mFractionLost, mRoundTripTimeMeasurements); 176 177 DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS( 178 mozilla::dom::RTCRemoteOutboundRtpStreamStats, 179 mozilla::dom::RTCSentRtpStreamStats, mLocalId, mRemoteTimestamp); 180 181 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCMediaSourceStats, mId, 182 mTimestamp, mType, mTrackIdentifier, mKind); 183 184 DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS( 185 mozilla::dom::RTCVideoSourceStats, mozilla::dom::RTCMediaSourceStats, 186 mWidth, mHeight, mFrames, mFramesPerSecond); 187 188 DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS( 189 mozilla::dom::RTCRTPContributingSourceStats, mozilla::dom::RTCStats, 190 mContributorSsrc, mInboundRtpStreamId); 191 192 DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS( 193 mozilla::dom::RTCPeerConnectionStats, mozilla::dom::RTCStats, 194 mDataChannelsOpened, mDataChannelsClosed); 195 196 DEFINE_IPC_SERIALIZER_WITH_FIELDS( 197 mozilla::dom::RTCVideoFrameHistoryEntryInternal, mWidth, mHeight, 198 mRotationAngle, mFirstFrameTimestamp, mLastFrameTimestamp, 199 mConsecutiveFrames, mLocalSsrc, mRemoteSsrc); 200 201 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCVideoFrameHistoryInternal, 202 mTrackIdentifier, mEntries); 203 204 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCBandwidthEstimationInternal, 205 mTrackIdentifier, mSendBandwidthBps, 206 mMaxPaddingBps, mReceiveBandwidthBps, 207 mPacerDelayMs, mRttMs); 208 209 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCDataChannelStats, mId, 210 mTimestamp, mType, mLabel, mProtocol, 211 mDataChannelIdentifier, mState, mMessagesSent, 212 mBytesSent, mMessagesReceived, mBytesReceived) 213 214 template <> 215 struct ParamTraits<mozilla::dom::RTCDataChannelState> 216 : public mozilla::dom::WebIDLEnumSerializer< 217 mozilla::dom::RTCDataChannelState> {}; 218 219 DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCCodecStats, mTimestamp, 220 mType, mId, mPayloadType, mCodecType, 221 mTransportId, mMimeType, mClockRate, 222 mChannels, mSdpFmtpLine) 223 224 template <> 225 struct ParamTraits<mozilla::dom::RTCCodecType> 226 : public mozilla::dom::WebIDLEnumSerializer<mozilla::dom::RTCCodecType> {}; 227 } // namespace IPC 228 229 #endif // _WEBRTC_GLOBAL_H_