summaryrefslogtreecommitdiffstats
path: root/dom/media/webrtc/WebrtcGlobal.h
blob: e9ec2ced516b45b79850a59439d1ab975471c463 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/* 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/. */

#ifndef _WEBRTC_GLOBAL_H_
#define _WEBRTC_GLOBAL_H_

#include "WebrtcIPCTraits.h"
#include "ipc/EnumSerializer.h"
#include "ipc/IPCMessageUtilsSpecializations.h"
#include "mozilla/dom/BindingIPCUtils.h"
#include "mozilla/dom/BindingDeclarations.h"
#include "mozilla/dom/RTCDataChannelBinding.h"
#include "mozilla/dom/RTCStatsReportBinding.h"
#include "mozilla/UniquePtr.h"

typedef mozilla::dom::RTCStatsReportInternal StatsReport;
typedef nsTArray<mozilla::UniquePtr<StatsReport>> RTCReports;
typedef mozilla::dom::Sequence<nsString> WebrtcGlobalLog;

namespace mozilla {
namespace dom {
// Calls aFunction with all public members of aStats.
// Typical usage would have aFunction take a parameter pack.
// To avoid inconsistencies, this should be the only explicit list of the
// public RTCStatscollection members in C++.
template <typename Collection, typename Function>
static auto ForAllPublicRTCStatsCollectionMembers(Collection& aStats,
                                                  Function aFunction) {
  static_assert(std::is_same_v<typename std::remove_const<Collection>::type,
                               RTCStatsCollection>,
                "aStats must be a const or non-const RTCStatsCollection");
  return aFunction(
      aStats.mInboundRtpStreamStats, aStats.mOutboundRtpStreamStats,
      aStats.mRemoteInboundRtpStreamStats, aStats.mRemoteOutboundRtpStreamStats,
      aStats.mMediaSourceStats, aStats.mVideoSourceStats,
      aStats.mPeerConnectionStats, aStats.mRtpContributingSourceStats,
      aStats.mIceCandidatePairStats, aStats.mIceCandidateStats,
      aStats.mTrickledIceCandidateStats, aStats.mDataChannelStats,
      aStats.mCodecStats);
}

// Calls aFunction with all members of aStats, including internal ones.
// Typical usage would have aFunction take a parameter pack.
// To avoid inconsistencies, this should be the only explicit list of the
// internal RTCStatscollection members in C++.
template <typename Collection, typename Function>
static auto ForAllRTCStatsCollectionMembers(Collection& aStats,
                                            Function aFunction) {
  static_assert(std::is_same_v<typename std::remove_const<Collection>::type,
                               RTCStatsCollection>,
                "aStats must be a const or non-const RTCStatsCollection");
  return ForAllPublicRTCStatsCollectionMembers(aStats, [&](auto&... aMember) {
    return aFunction(aMember..., aStats.mRawLocalCandidates,
                     aStats.mRawRemoteCandidates, aStats.mVideoFrameHistories,
                     aStats.mBandwidthEstimations);
  });
}
}  // namespace dom
}  // namespace mozilla

namespace IPC {

template <>
struct ParamTraits<mozilla::dom::RTCStatsType>
    : public mozilla::dom::WebIDLEnumSerializer<mozilla::dom::RTCStatsType> {};

template <>
struct ParamTraits<mozilla::dom::RTCStatsIceCandidatePairState>
    : public mozilla::dom::WebIDLEnumSerializer<
          mozilla::dom::RTCStatsIceCandidatePairState> {};

template <>
struct ParamTraits<mozilla::dom::RTCIceCandidateType>
    : public mozilla::dom::WebIDLEnumSerializer<
          mozilla::dom::RTCIceCandidateType> {};

template <>
struct ParamTraits<mozilla::dom::RTCBundlePolicy>
    : public mozilla::dom::WebIDLEnumSerializer<mozilla::dom::RTCBundlePolicy> {
};

DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCIceServerInternal, mUrls,
                                  mCredentialProvided, mUserNameProvided);

DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCConfigurationInternal,
                                  mBundlePolicy, mCertificatesProvided,
                                  mIceServers, mIceTransportPolicy,
                                  mPeerIdentityProvided, mSdpSemantics);

DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCSdpParsingErrorInternal,
                                  mLineNumber, mError);

DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCSdpHistoryEntryInternal,
                                  mTimestamp, mIsLocal, mSdp, mErrors);

template <>
struct ParamTraits<mozilla::dom::RTCStatsCollection> {
  static void Write(MessageWriter* aWriter,
                    const mozilla::dom::RTCStatsCollection& aParam) {
    mozilla::dom::ForAllRTCStatsCollectionMembers(
        aParam,
        [&](const auto&... aMember) { WriteParams(aWriter, aMember...); });
  }

  static bool Read(MessageReader* aReader,
                   mozilla::dom::RTCStatsCollection* aResult) {
    return mozilla::dom::ForAllRTCStatsCollectionMembers(
        *aResult,
        [&](auto&... aMember) { return ReadParams(aReader, aMember...); });
  }
};

DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS(
    mozilla::dom::RTCStatsReportInternal, mozilla::dom::RTCStatsCollection,
    mClosed, mSdpHistory, mPcid, mBrowserId, mTimestamp, mCallDurationMs,
    mIceRestarts, mIceRollbacks, mOfferer, mConfiguration);

DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCStats, mId, mTimestamp,
                                  mType);

DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS(
    mozilla::dom::RTCIceCandidatePairStats, mozilla::dom::RTCStats,
    mTransportId, mLocalCandidateId, mPriority, mNominated, mWritable,
    mReadable, mRemoteCandidateId, mSelected, mComponentId, mState, mBytesSent,
    mBytesReceived, mLastPacketSentTimestamp, mLastPacketReceivedTimestamp);

DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS(
    mozilla::dom::RTCIceCandidateStats, mozilla::dom::RTCStats, mCandidateType,
    mPriority, mTransportId, mAddress, mRelayProtocol, mPort, mProtocol,
    mProxied);

DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS(
    mozilla::dom::RTCReceivedRtpStreamStats, mozilla::dom::RTCRtpStreamStats,
    mPacketsReceived, mPacketsLost, mJitter, mDiscardedPackets,
    mPacketsDiscarded);

DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS(
    mozilla::dom::RTCInboundRtpStreamStats,
    mozilla::dom::RTCReceivedRtpStreamStats, mTrackIdentifier, mRemoteId,
    mFramesDecoded, mFramesDropped, mFrameWidth, mFrameHeight, mFramesPerSecond,
    mQpSum, mTotalDecodeTime, mTotalInterFrameDelay,
    mTotalSquaredInterFrameDelay, mLastPacketReceivedTimestamp,
    mHeaderBytesReceived, mFecPacketsReceived, mFecPacketsDiscarded,
    mBytesReceived, mNackCount, mFirCount, mPliCount, mTotalProcessingDelay,
    // Always missing from libwebrtc stats
    // mEstimatedPlayoutTimestamp,
    mFramesReceived, mJitterBufferDelay, mJitterBufferEmittedCount,
    mTotalSamplesReceived, mConcealedSamples, mSilentConcealedSamples,
    mConcealmentEvents, mInsertedSamplesForDeceleration,
    mRemovedSamplesForAcceleration, mAudioLevel, mTotalAudioEnergy,
    mTotalSamplesDuration);

DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS(
    mozilla::dom::RTCRtpStreamStats, mozilla::dom::RTCStats, mSsrc, mKind,
    mMediaType, mTransportId, mCodecId);

DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS(
    mozilla::dom::RTCSentRtpStreamStats, mozilla::dom::RTCRtpStreamStats,
    mPacketsSent, mBytesSent);

DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS(
    mozilla::dom::RTCOutboundRtpStreamStats,
    mozilla::dom::RTCSentRtpStreamStats, mRemoteId, mFramesEncoded, mQpSum,
    mNackCount, mFirCount, mPliCount, mHeaderBytesSent,
    mRetransmittedPacketsSent, mRetransmittedBytesSent,
    mTotalEncodedBytesTarget, mFrameWidth, mFrameHeight, mFramesPerSecond,
    mFramesSent, mHugeFramesSent, mTotalEncodeTime);

DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS(
    mozilla::dom::RTCRemoteInboundRtpStreamStats,
    mozilla::dom::RTCReceivedRtpStreamStats, mLocalId, mRoundTripTime,
    mTotalRoundTripTime, mFractionLost, mRoundTripTimeMeasurements);

DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS(
    mozilla::dom::RTCRemoteOutboundRtpStreamStats,
    mozilla::dom::RTCSentRtpStreamStats, mLocalId, mRemoteTimestamp);

DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCMediaSourceStats, mId,
                                  mTimestamp, mType, mTrackIdentifier, mKind);

DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS(
    mozilla::dom::RTCVideoSourceStats, mozilla::dom::RTCMediaSourceStats,
    mWidth, mHeight, mFrames, mFramesPerSecond);

DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS(
    mozilla::dom::RTCRTPContributingSourceStats, mozilla::dom::RTCStats,
    mContributorSsrc, mInboundRtpStreamId);

DEFINE_IPC_SERIALIZER_WITH_SUPER_CLASS_AND_FIELDS(
    mozilla::dom::RTCPeerConnectionStats, mozilla::dom::RTCStats,
    mDataChannelsOpened, mDataChannelsClosed);

DEFINE_IPC_SERIALIZER_WITH_FIELDS(
    mozilla::dom::RTCVideoFrameHistoryEntryInternal, mWidth, mHeight,
    mRotationAngle, mFirstFrameTimestamp, mLastFrameTimestamp,
    mConsecutiveFrames, mLocalSsrc, mRemoteSsrc);

DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCVideoFrameHistoryInternal,
                                  mTrackIdentifier, mEntries);

DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCBandwidthEstimationInternal,
                                  mTrackIdentifier, mSendBandwidthBps,
                                  mMaxPaddingBps, mReceiveBandwidthBps,
                                  mPacerDelayMs, mRttMs);

DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCDataChannelStats, mId,
                                  mTimestamp, mType, mLabel, mProtocol,
                                  mDataChannelIdentifier, mState, mMessagesSent,
                                  mBytesSent, mMessagesReceived, mBytesReceived)

template <>
struct ParamTraits<mozilla::dom::RTCDataChannelState>
    : public mozilla::dom::WebIDLEnumSerializer<
          mozilla::dom::RTCDataChannelState> {};

DEFINE_IPC_SERIALIZER_WITH_FIELDS(mozilla::dom::RTCCodecStats, mTimestamp,
                                  mType, mId, mPayloadType, mCodecType,
                                  mTransportId, mMimeType, mClockRate,
                                  mChannels, mSdpFmtpLine)

template <>
struct ParamTraits<mozilla::dom::RTCCodecType>
    : public mozilla::dom::WebIDLEnumSerializer<mozilla::dom::RTCCodecType> {};
}  // namespace IPC

#endif  // _WEBRTC_GLOBAL_H_