Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7)

Side by Side Diff: talk/app/webrtc/statstypes.h

Issue 1610243002: Move talk/app/webrtc to webrtc/api (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Removed processing of api.gyp for Chromium builds Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « talk/app/webrtc/statscollector_unittest.cc ('k') | talk/app/webrtc/statstypes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * libjingle
3 * Copyright 2012 Google Inc.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 // This file contains structures used for retrieving statistics from an ongoing
29 // libjingle session.
30
31 #ifndef TALK_APP_WEBRTC_STATSTYPES_H_
32 #define TALK_APP_WEBRTC_STATSTYPES_H_
33
34 #include <algorithm>
35 #include <list>
36 #include <map>
37 #include <string>
38
39 #include "webrtc/base/basictypes.h"
40 #include "webrtc/base/common.h"
41 #include "webrtc/base/linked_ptr.h"
42 #include "webrtc/base/refcount.h"
43 #include "webrtc/base/scoped_ptr.h"
44 #include "webrtc/base/scoped_ref_ptr.h"
45 #include "webrtc/base/stringencode.h"
46 #include "webrtc/base/thread_checker.h"
47
48 namespace webrtc {
49
50 class StatsReport {
51 public:
52 // Indicates whether a track is for sending or receiving.
53 // Used in reports for audio/video tracks.
54 enum Direction {
55 kSend = 0,
56 kReceive,
57 };
58
59 enum StatsType {
60 // StatsReport types.
61 // A StatsReport of |type| = "googSession" contains overall information
62 // about the thing libjingle calls a session (which may contain one
63 // or more RTP sessions.
64 kStatsReportTypeSession,
65
66 // A StatsReport of |type| = "googTransport" contains information
67 // about a libjingle "transport".
68 kStatsReportTypeTransport,
69
70 // A StatsReport of |type| = "googComponent" contains information
71 // about a libjingle "channel" (typically, RTP or RTCP for a transport).
72 // This is intended to be the same thing as an ICE "Component".
73 kStatsReportTypeComponent,
74
75 // A StatsReport of |type| = "googCandidatePair" contains information
76 // about a libjingle "connection" - a single source/destination port pair.
77 // This is intended to be the same thing as an ICE "candidate pair".
78 kStatsReportTypeCandidatePair,
79
80 // A StatsReport of |type| = "VideoBWE" is statistics for video Bandwidth
81 // Estimation, which is global per-session. The |id| field is "bweforvideo"
82 // (will probably change in the future).
83 kStatsReportTypeBwe,
84
85 // A StatsReport of |type| = "ssrc" is statistics for a specific rtp stream.
86 // The |id| field is the SSRC in decimal form of the rtp stream.
87 kStatsReportTypeSsrc,
88
89 // A StatsReport of |type| = "remoteSsrc" is statistics for a specific
90 // rtp stream, generated by the remote end of the connection.
91 kStatsReportTypeRemoteSsrc,
92
93 // A StatsReport of |type| = "googTrack" is statistics for a specific media
94 // track. The |id| field is the track id.
95 kStatsReportTypeTrack,
96
97 // A StatsReport of |type| = "localcandidate" or "remotecandidate" is
98 // attributes on a specific ICE Candidate. It links to its connection pair
99 // by candidate id. The string value is taken from
100 // http://w3c.github.io/webrtc-stats/#rtcstatstype-enum*.
101 kStatsReportTypeIceLocalCandidate,
102 kStatsReportTypeIceRemoteCandidate,
103
104 // A StatsReport of |type| = "googCertificate" contains an SSL certificate
105 // transmitted by one of the endpoints of this connection. The |id| is
106 // controlled by the fingerprint, and is used to identify the certificate in
107 // the Channel stats (as "googLocalCertificateId" or
108 // "googRemoteCertificateId") and in any child certificates (as
109 // "googIssuerId").
110 kStatsReportTypeCertificate,
111
112 // A StatsReport of |type| = "datachannel" with statistics for a
113 // particular DataChannel.
114 kStatsReportTypeDataChannel,
115 };
116
117 enum StatsValueName {
118 kStatsValueNameActiveConnection,
119 kStatsValueNameAudioInputLevel,
120 kStatsValueNameAudioOutputLevel,
121 kStatsValueNameBytesReceived,
122 kStatsValueNameBytesSent,
123 kStatsValueNameCodecImplementationName,
124 kStatsValueNameDataChannelId,
125 kStatsValueNameMediaType,
126 kStatsValueNamePacketsLost,
127 kStatsValueNamePacketsReceived,
128 kStatsValueNamePacketsSent,
129 kStatsValueNameProtocol,
130 kStatsValueNameReceiving,
131 kStatsValueNameSelectedCandidatePairId,
132 kStatsValueNameSsrc,
133 kStatsValueNameState,
134 kStatsValueNameTransportId,
135
136 // Internal StatsValue names.
137 kStatsValueNameAccelerateRate,
138 kStatsValueNameActualEncBitrate,
139 kStatsValueNameAdaptationChanges,
140 kStatsValueNameAvailableReceiveBandwidth,
141 kStatsValueNameAvailableSendBandwidth,
142 kStatsValueNameAvgEncodeMs,
143 kStatsValueNameBandwidthLimitedResolution,
144 kStatsValueNameBucketDelay,
145 kStatsValueNameCaptureStartNtpTimeMs,
146 kStatsValueNameCandidateIPAddress,
147 kStatsValueNameCandidateNetworkType,
148 kStatsValueNameCandidatePortNumber,
149 kStatsValueNameCandidatePriority,
150 kStatsValueNameCandidateTransportType,
151 kStatsValueNameCandidateType,
152 kStatsValueNameChannelId,
153 kStatsValueNameCodecName,
154 kStatsValueNameComponent,
155 kStatsValueNameContentName,
156 kStatsValueNameCpuLimitedResolution,
157 kStatsValueNameCurrentDelayMs,
158 kStatsValueNameDecodeMs,
159 kStatsValueNameDecodingCNG,
160 kStatsValueNameDecodingCTN,
161 kStatsValueNameDecodingCTSG,
162 kStatsValueNameDecodingNormal,
163 kStatsValueNameDecodingPLC,
164 kStatsValueNameDecodingPLCCNG,
165 kStatsValueNameDer,
166 kStatsValueNameDtlsCipher,
167 kStatsValueNameEchoCancellationQualityMin,
168 kStatsValueNameEchoDelayMedian,
169 kStatsValueNameEchoDelayStdDev,
170 kStatsValueNameEchoReturnLoss,
171 kStatsValueNameEchoReturnLossEnhancement,
172 kStatsValueNameEncodeUsagePercent,
173 kStatsValueNameExpandRate,
174 kStatsValueNameFingerprint,
175 kStatsValueNameFingerprintAlgorithm,
176 kStatsValueNameFirsReceived,
177 kStatsValueNameFirsSent,
178 kStatsValueNameFrameHeightInput,
179 kStatsValueNameFrameHeightReceived,
180 kStatsValueNameFrameHeightSent,
181 kStatsValueNameFrameRateDecoded,
182 kStatsValueNameFrameRateInput,
183 kStatsValueNameFrameRateOutput,
184 kStatsValueNameFrameRateReceived,
185 kStatsValueNameFrameRateSent,
186 kStatsValueNameFrameWidthInput,
187 kStatsValueNameFrameWidthReceived,
188 kStatsValueNameFrameWidthSent,
189 kStatsValueNameInitiator,
190 kStatsValueNameIssuerId,
191 kStatsValueNameJitterBufferMs,
192 kStatsValueNameJitterReceived,
193 kStatsValueNameLabel,
194 kStatsValueNameLocalAddress,
195 kStatsValueNameLocalCandidateId,
196 kStatsValueNameLocalCandidateType,
197 kStatsValueNameLocalCertificateId,
198 kStatsValueNameMaxDecodeMs,
199 kStatsValueNameMinPlayoutDelayMs,
200 kStatsValueNameNacksReceived,
201 kStatsValueNameNacksSent,
202 kStatsValueNamePlisReceived,
203 kStatsValueNamePlisSent,
204 kStatsValueNamePreemptiveExpandRate,
205 kStatsValueNamePreferredJitterBufferMs,
206 kStatsValueNameRemoteAddress,
207 kStatsValueNameRemoteCandidateId,
208 kStatsValueNameRemoteCandidateType,
209 kStatsValueNameRemoteCertificateId,
210 kStatsValueNameRenderDelayMs,
211 kStatsValueNameRetransmitBitrate,
212 kStatsValueNameRtt,
213 kStatsValueNameSecondaryDecodedRate,
214 kStatsValueNameSendPacketsDiscarded,
215 kStatsValueNameSpeechExpandRate,
216 kStatsValueNameSrtpCipher,
217 kStatsValueNameTargetDelayMs,
218 kStatsValueNameTargetEncBitrate,
219 kStatsValueNameTrackId,
220 kStatsValueNameTransmitBitrate,
221 kStatsValueNameTransportType,
222 kStatsValueNameTypingNoiseState,
223 kStatsValueNameViewLimitedResolution,
224 kStatsValueNameWritable,
225 };
226
227 class IdBase : public rtc::RefCountInterface {
228 public:
229 ~IdBase() override;
230 StatsType type() const;
231
232 // Users of IdBase will be using the Id typedef, which is compatible with
233 // this Equals() function. It simply calls the protected (and overridden)
234 // Equals() method.
235 bool Equals(const rtc::scoped_refptr<IdBase>& other) const {
236 return Equals(*other.get());
237 }
238
239 virtual std::string ToString() const = 0;
240
241 protected:
242 // Protected since users of the IdBase type will be using the Id typedef.
243 virtual bool Equals(const IdBase& other) const;
244
245 IdBase(StatsType type); // Only meant for derived classes.
246 const StatsType type_;
247
248 static const char kSeparator = '_';
249 };
250
251 typedef rtc::scoped_refptr<IdBase> Id;
252
253 struct Value {
254 enum Type {
255 kInt, // int.
256 kInt64, // int64_t.
257 kFloat, // float.
258 kString, // std::string
259 kStaticString, // const char*.
260 kBool, // bool.
261 kId, // Id.
262 };
263
264 Value(StatsValueName name, int64_t value, Type int_type);
265 Value(StatsValueName name, float f);
266 Value(StatsValueName name, const std::string& value);
267 Value(StatsValueName name, const char* value);
268 Value(StatsValueName name, bool b);
269 Value(StatsValueName name, const Id& value);
270
271 ~Value();
272
273 // TODO(tommi): This compares name as well as value...
274 // I think we should only need to compare the value part and
275 // move the name part into a hash map.
276 bool Equals(const Value& other) const;
277
278 // Comparison operators. Return true iff the current instance is of the
279 // correct type and holds the same value. No conversion is performed so
280 // a string value of "123" is not equal to an int value of 123 and an int
281 // value of 123 is not equal to a float value of 123.0f.
282 // One exception to this is that types kInt and kInt64 can be compared and
283 // kString and kStaticString too.
284 bool operator==(const std::string& value) const;
285 bool operator==(const char* value) const;
286 bool operator==(int64_t value) const;
287 bool operator==(bool value) const;
288 bool operator==(float value) const;
289 bool operator==(const Id& value) const;
290
291 // Getters that allow getting the native value directly.
292 // The caller must know the type beforehand or else hit a check.
293 int int_val() const;
294 int64_t int64_val() const;
295 float float_val() const;
296 const char* static_string_val() const;
297 const std::string& string_val() const;
298 bool bool_val() const;
299 const Id& id_val() const;
300
301 // Returns the string representation of |name|.
302 const char* display_name() const;
303
304 // Converts the native value to a string representation of the value.
305 std::string ToString() const;
306
307 Type type() const { return type_; }
308
309 // TODO(tommi): Move |name| and |display_name| out of the Value struct.
310 const StatsValueName name;
311
312 private:
313 const Type type_;
314 // TODO(tommi): Use C++ 11 union and make value_ const.
315 union InternalType {
316 int int_;
317 int64_t int64_;
318 float float_;
319 bool bool_;
320 std::string* string_;
321 const char* static_string_;
322 Id* id_;
323 } value_;
324
325 private:
326 RTC_DISALLOW_COPY_AND_ASSIGN(Value);
327 };
328
329 // TODO(tommi): Consider using a similar approach to how we store Ids using
330 // scoped_refptr for values.
331 typedef rtc::linked_ptr<Value> ValuePtr;
332 typedef std::map<StatsValueName, ValuePtr> Values;
333
334 // Ownership of |id| is passed to |this|.
335 explicit StatsReport(const Id& id);
336
337 // Factory functions for various types of stats IDs.
338 static Id NewBandwidthEstimationId();
339 static Id NewTypedId(StatsType type, const std::string& id);
340 static Id NewTypedIntId(StatsType type, int id);
341 static Id NewIdWithDirection(
342 StatsType type, const std::string& id, Direction direction);
343 static Id NewCandidateId(bool local, const std::string& id);
344 static Id NewComponentId(
345 const std::string& content_name, int component);
346 static Id NewCandidatePairId(
347 const std::string& content_name, int component, int index);
348
349 const Id& id() const { return id_; }
350 StatsType type() const { return id_->type(); }
351 double timestamp() const { return timestamp_; }
352 void set_timestamp(double t) { timestamp_ = t; }
353 bool empty() const { return values_.empty(); }
354 const Values& values() const { return values_; }
355
356 const char* TypeToString() const;
357
358 void AddString(StatsValueName name, const std::string& value);
359 void AddString(StatsValueName name, const char* value);
360 void AddInt64(StatsValueName name, int64_t value);
361 void AddInt(StatsValueName name, int value);
362 void AddFloat(StatsValueName name, float value);
363 void AddBoolean(StatsValueName name, bool value);
364 void AddId(StatsValueName name, const Id& value);
365
366 const Value* FindValue(StatsValueName name) const;
367
368 private:
369 // The unique identifier for this object.
370 // This is used as a key for this report in ordered containers,
371 // so it must never be changed.
372 const Id id_;
373 double timestamp_; // Time since 1970-01-01T00:00:00Z in milliseconds.
374 Values values_;
375
376 RTC_DISALLOW_COPY_AND_ASSIGN(StatsReport);
377 };
378
379 // Typedef for an array of const StatsReport pointers.
380 // Ownership of the pointers held by this implementation is assumed to lie
381 // elsewhere and lifetime guarantees are made by the implementation that uses
382 // this type. In the StatsCollector, object ownership lies with the
383 // StatsCollection class.
384 typedef std::vector<const StatsReport*> StatsReports;
385
386 // A map from the report id to the report.
387 // This class wraps an STL container and provides a limited set of
388 // functionality in order to keep things simple.
389 class StatsCollection {
390 public:
391 StatsCollection();
392 ~StatsCollection();
393
394 typedef std::list<StatsReport*> Container;
395 typedef Container::iterator iterator;
396 typedef Container::const_iterator const_iterator;
397
398 const_iterator begin() const;
399 const_iterator end() const;
400 size_t size() const;
401
402 // Creates a new report object with |id| that does not already
403 // exist in the list of reports.
404 StatsReport* InsertNew(const StatsReport::Id& id);
405 StatsReport* FindOrAddNew(const StatsReport::Id& id);
406 StatsReport* ReplaceOrAddNew(const StatsReport::Id& id);
407
408 // Looks for a report with the given |id|. If one is not found, NULL
409 // will be returned.
410 StatsReport* Find(const StatsReport::Id& id);
411
412 private:
413 Container list_;
414 rtc::ThreadChecker thread_checker_;
415 };
416
417 } // namespace webrtc
418
419 #endif // TALK_APP_WEBRTC_STATSTYPES_H_
OLDNEW
« no previous file with comments | « talk/app/webrtc/statscollector_unittest.cc ('k') | talk/app/webrtc/statstypes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698