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

Side by Side Diff: webrtc/api/rtcstatscollector.h

Issue 2472113002: Correct stats for RTCPeerConnectionStats.dataChannels[Opened/Closed]. (Closed)
Patch Set: Addressed deadbeef's comments Created 4 years, 1 month 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 | « webrtc/api/peerconnection.cc ('k') | webrtc/api/rtcstatscollector.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #ifndef WEBRTC_API_RTCSTATSCOLLECTOR_H_ 11 #ifndef WEBRTC_API_RTCSTATSCOLLECTOR_H_
12 #define WEBRTC_API_RTCSTATSCOLLECTOR_H_ 12 #define WEBRTC_API_RTCSTATSCOLLECTOR_H_
13 13
14 #include <map> 14 #include <map>
15 #include <memory> 15 #include <memory>
16 #include <set>
16 #include <vector> 17 #include <vector>
17 18
19 #include "webrtc/api/datachannel.h"
18 #include "webrtc/api/datachannelinterface.h" 20 #include "webrtc/api/datachannelinterface.h"
19 #include "webrtc/api/stats/rtcstats_objects.h" 21 #include "webrtc/api/stats/rtcstats_objects.h"
20 #include "webrtc/api/stats/rtcstatsreport.h" 22 #include "webrtc/api/stats/rtcstatsreport.h"
21 #include "webrtc/base/asyncinvoker.h" 23 #include "webrtc/base/asyncinvoker.h"
22 #include "webrtc/base/refcount.h" 24 #include "webrtc/base/refcount.h"
23 #include "webrtc/base/scoped_ref_ptr.h" 25 #include "webrtc/base/scoped_ref_ptr.h"
26 #include "webrtc/base/sigslot.h"
24 #include "webrtc/base/sslidentity.h" 27 #include "webrtc/base/sslidentity.h"
25 #include "webrtc/base/timeutils.h" 28 #include "webrtc/base/timeutils.h"
26 29
27 namespace cricket { 30 namespace cricket {
28 class Candidate; 31 class Candidate;
29 } // namespace cricket 32 } // namespace cricket
30 33
31 namespace rtc { 34 namespace rtc {
32 class SSLCertificate; 35 class SSLCertificate;
33 } // namespace rtc 36 } // namespace rtc
34 37
35 namespace webrtc { 38 namespace webrtc {
36 39
37 class PeerConnection; 40 class PeerConnection;
38 struct SessionStats; 41 struct SessionStats;
39 42
40 class RTCStatsCollectorCallback : public virtual rtc::RefCountInterface { 43 class RTCStatsCollectorCallback : public virtual rtc::RefCountInterface {
41 public: 44 public:
42 virtual ~RTCStatsCollectorCallback() {} 45 virtual ~RTCStatsCollectorCallback() {}
43 46
44 virtual void OnStatsDelivered( 47 virtual void OnStatsDelivered(
45 const rtc::scoped_refptr<const RTCStatsReport>& report) = 0; 48 const rtc::scoped_refptr<const RTCStatsReport>& report) = 0;
46 }; 49 };
47 50
48 // All public methods of the collector are to be called on the signaling thread. 51 // All public methods of the collector are to be called on the signaling thread.
49 // Stats are gathered on the signaling, worker and network threads 52 // Stats are gathered on the signaling, worker and network threads
50 // asynchronously. The callback is invoked on the signaling thread. Resulting 53 // asynchronously. The callback is invoked on the signaling thread. Resulting
51 // reports are cached for |cache_lifetime_| ms. 54 // reports are cached for |cache_lifetime_| ms.
52 class RTCStatsCollector : public virtual rtc::RefCountInterface { 55 class RTCStatsCollector : public virtual rtc::RefCountInterface,
56 public sigslot::has_slots<> {
53 public: 57 public:
54 static rtc::scoped_refptr<RTCStatsCollector> Create( 58 static rtc::scoped_refptr<RTCStatsCollector> Create(
55 PeerConnection* pc, 59 PeerConnection* pc,
56 int64_t cache_lifetime_us = 50 * rtc::kNumMicrosecsPerMillisec); 60 int64_t cache_lifetime_us = 50 * rtc::kNumMicrosecsPerMillisec);
57 61
58 // Gets a recent stats report. If there is a report cached that is still fresh 62 // Gets a recent stats report. If there is a report cached that is still fresh
59 // it is returned, otherwise new stats are gathered and returned. A report is 63 // it is returned, otherwise new stats are gathered and returned. A report is
60 // considered fresh for |cache_lifetime_| ms. const RTCStatsReports are safe 64 // considered fresh for |cache_lifetime_| ms. const RTCStatsReports are safe
61 // to use across multiple threads and may be destructed on any thread. 65 // to use across multiple threads and may be destructed on any thread.
62 void GetStatsReport(rtc::scoped_refptr<RTCStatsCollectorCallback> callback); 66 void GetStatsReport(rtc::scoped_refptr<RTCStatsCollectorCallback> callback);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 // Produces |RTCTransportStats|. 115 // Produces |RTCTransportStats|.
112 void ProduceTransportStats_s( 116 void ProduceTransportStats_s(
113 int64_t timestamp_us, const SessionStats& session_stats, 117 int64_t timestamp_us, const SessionStats& session_stats,
114 const std::map<std::string, CertificateStatsPair>& transport_cert_stats, 118 const std::map<std::string, CertificateStatsPair>& transport_cert_stats,
115 RTCStatsReport* report) const; 119 RTCStatsReport* report) const;
116 120
117 // Helper function to stats-producing functions. 121 // Helper function to stats-producing functions.
118 std::map<std::string, CertificateStatsPair> 122 std::map<std::string, CertificateStatsPair>
119 PrepareTransportCertificateStats_s(const SessionStats& session_stats) const; 123 PrepareTransportCertificateStats_s(const SessionStats& session_stats) const;
120 124
125 // Slots for signals (sigslot) that are wired up to |pc_|.
126 void OnDataChannelCreated(DataChannel* channel);
127 // Slots for signals (sigslot) that are wired up to |channel|.
128 void OnDataChannelOpened(DataChannel* channel);
129 void OnDataChannelClosed(DataChannel* channel);
130
121 PeerConnection* const pc_; 131 PeerConnection* const pc_;
122 rtc::Thread* const signaling_thread_; 132 rtc::Thread* const signaling_thread_;
123 rtc::Thread* const worker_thread_; 133 rtc::Thread* const worker_thread_;
124 rtc::Thread* const network_thread_; 134 rtc::Thread* const network_thread_;
125 rtc::AsyncInvoker invoker_; 135 rtc::AsyncInvoker invoker_;
126 136
127 int num_pending_partial_reports_; 137 int num_pending_partial_reports_;
128 int64_t partial_report_timestamp_us_; 138 int64_t partial_report_timestamp_us_;
129 rtc::scoped_refptr<RTCStatsReport> partial_report_; 139 rtc::scoped_refptr<RTCStatsReport> partial_report_;
130 std::vector<rtc::scoped_refptr<RTCStatsCollectorCallback>> callbacks_; 140 std::vector<rtc::scoped_refptr<RTCStatsCollectorCallback>> callbacks_;
131 141
132 // A timestamp, in microseconds, that is based on a timer that is 142 // A timestamp, in microseconds, that is based on a timer that is
133 // monotonically increasing. That is, even if the system clock is modified the 143 // monotonically increasing. That is, even if the system clock is modified the
134 // difference between the timer and this timestamp is how fresh the cached 144 // difference between the timer and this timestamp is how fresh the cached
135 // report is. 145 // report is.
136 int64_t cache_timestamp_us_; 146 int64_t cache_timestamp_us_;
137 int64_t cache_lifetime_us_; 147 int64_t cache_lifetime_us_;
138 rtc::scoped_refptr<const RTCStatsReport> cached_report_; 148 rtc::scoped_refptr<const RTCStatsReport> cached_report_;
149
150 // Data recorded and maintained by the stats collector during its lifetime.
151 // Some stats are produced from this record instead of other components.
152 struct InternalRecord {
153 InternalRecord() : data_channels_opened(0),
154 data_channels_closed(0) {}
155
156 // The opened count goes up when a channel is fully opened and the closed
157 // count goes up if a previously opened channel has fully closed. The opened
158 // count does not go down when a channel closes, meaning (opened - closed)
159 // is the number of channels currently opened. A channel that is closed
160 // before reaching the open state does not affect these counters.
161 uint32_t data_channels_opened;
162 uint32_t data_channels_closed;
163 // Identifies by address channels that have been opened, which remain in the
164 // set until they have been fully closed.
165 std::set<uintptr_t> opened_data_channels;
166 };
167 InternalRecord internal_record_;
139 }; 168 };
140 169
141 const char* CandidateTypeToRTCIceCandidateTypeForTesting( 170 const char* CandidateTypeToRTCIceCandidateTypeForTesting(
142 const std::string& type); 171 const std::string& type);
143 const char* DataStateToRTCDataChannelStateForTesting( 172 const char* DataStateToRTCDataChannelStateForTesting(
144 DataChannelInterface::DataState state); 173 DataChannelInterface::DataState state);
145 174
146 } // namespace webrtc 175 } // namespace webrtc
147 176
148 #endif // WEBRTC_API_RTCSTATSCOLLECTOR_H_ 177 #endif // WEBRTC_API_RTCSTATSCOLLECTOR_H_
OLDNEW
« no previous file with comments | « webrtc/api/peerconnection.cc ('k') | webrtc/api/rtcstatscollector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698