OLD | NEW |
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 <set> |
17 #include <vector> | 17 #include <vector> |
18 | 18 |
19 #include "webrtc/api/datachannel.h" | 19 #include "webrtc/api/datachannel.h" |
20 #include "webrtc/api/datachannelinterface.h" | 20 #include "webrtc/api/datachannelinterface.h" |
21 #include "webrtc/api/stats/rtcstats_objects.h" | 21 #include "webrtc/api/stats/rtcstats_objects.h" |
22 #include "webrtc/api/stats/rtcstatsreport.h" | 22 #include "webrtc/api/stats/rtcstatsreport.h" |
| 23 #include "webrtc/api/trackmediainfomap.h" |
23 #include "webrtc/base/asyncinvoker.h" | 24 #include "webrtc/base/asyncinvoker.h" |
24 #include "webrtc/base/optional.h" | 25 #include "webrtc/base/optional.h" |
25 #include "webrtc/base/refcount.h" | 26 #include "webrtc/base/refcount.h" |
26 #include "webrtc/base/scoped_ref_ptr.h" | 27 #include "webrtc/base/scoped_ref_ptr.h" |
27 #include "webrtc/base/sigslot.h" | 28 #include "webrtc/base/sigslot.h" |
28 #include "webrtc/base/sslidentity.h" | 29 #include "webrtc/base/sslidentity.h" |
29 #include "webrtc/base/timeutils.h" | 30 #include "webrtc/base/timeutils.h" |
30 #include "webrtc/media/base/mediachannel.h" | 31 #include "webrtc/media/base/mediachannel.h" |
31 | 32 |
32 namespace cricket { | 33 namespace cricket { |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 | 87 |
87 // Can be called on any thread. | 88 // Can be called on any thread. |
88 void AddPartialResults( | 89 void AddPartialResults( |
89 const rtc::scoped_refptr<RTCStatsReport>& partial_report); | 90 const rtc::scoped_refptr<RTCStatsReport>& partial_report); |
90 | 91 |
91 private: | 92 private: |
92 struct CertificateStatsPair { | 93 struct CertificateStatsPair { |
93 std::unique_ptr<rtc::SSLCertificateStats> local; | 94 std::unique_ptr<rtc::SSLCertificateStats> local; |
94 std::unique_ptr<rtc::SSLCertificateStats> remote; | 95 std::unique_ptr<rtc::SSLCertificateStats> remote; |
95 }; | 96 }; |
96 struct MediaInfo { | |
97 rtc::Optional<cricket::VoiceMediaInfo> voice; | |
98 rtc::Optional<cricket::VideoMediaInfo> video; | |
99 }; | |
100 | 97 |
101 void AddPartialResults_s(rtc::scoped_refptr<RTCStatsReport> partial_report); | 98 void AddPartialResults_s(rtc::scoped_refptr<RTCStatsReport> partial_report); |
102 void DeliverCachedReport(); | 99 void DeliverCachedReport(); |
103 | 100 |
104 // Produces |RTCCertificateStats|. | 101 // Produces |RTCCertificateStats|. |
105 void ProduceCertificateStats_n( | 102 void ProduceCertificateStats_n( |
106 int64_t timestamp_us, | 103 int64_t timestamp_us, |
107 const std::map<std::string, CertificateStatsPair>& transport_cert_stats, | 104 const std::map<std::string, CertificateStatsPair>& transport_cert_stats, |
108 RTCStatsReport* report) const; | 105 RTCStatsReport* report) const; |
109 // Produces |RTCCodecStats|. | 106 // Produces |RTCCodecStats|. |
110 void ProduceCodecStats_n( | 107 void ProduceCodecStats_n( |
111 int64_t timestamp_us, const MediaInfo& media_info, | 108 int64_t timestamp_us, const TrackMediaInfoMap& track_media_info_map, |
112 RTCStatsReport* report) const; | 109 RTCStatsReport* report) const; |
113 // Produces |RTCDataChannelStats|. | 110 // Produces |RTCDataChannelStats|. |
114 void ProduceDataChannelStats_s( | 111 void ProduceDataChannelStats_s( |
115 int64_t timestamp_us, RTCStatsReport* report) const; | 112 int64_t timestamp_us, RTCStatsReport* report) const; |
116 // Produces |RTCIceCandidatePairStats| and |RTCIceCandidateStats|. | 113 // Produces |RTCIceCandidatePairStats| and |RTCIceCandidateStats|. |
117 void ProduceIceCandidateAndPairStats_n( | 114 void ProduceIceCandidateAndPairStats_n( |
118 int64_t timestamp_us, const SessionStats& session_stats, | 115 int64_t timestamp_us, const SessionStats& session_stats, |
119 RTCStatsReport* report) const; | 116 RTCStatsReport* report) const; |
120 // Produces |RTCMediaStreamStats| and |RTCMediaStreamTrackStats|. | 117 // Produces |RTCMediaStreamStats| and |RTCMediaStreamTrackStats|. |
121 void ProduceMediaStreamAndTrackStats_s( | 118 void ProduceMediaStreamAndTrackStats_s( |
122 int64_t timestamp_us, RTCStatsReport* report) const; | 119 int64_t timestamp_us, RTCStatsReport* report) const; |
123 // Produces |RTCPeerConnectionStats|. | 120 // Produces |RTCPeerConnectionStats|. |
124 void ProducePeerConnectionStats_s( | 121 void ProducePeerConnectionStats_s( |
125 int64_t timestamp_us, RTCStatsReport* report) const; | 122 int64_t timestamp_us, RTCStatsReport* report) const; |
126 // Produces |RTCInboundRTPStreamStats| and |RTCOutboundRTPStreamStats|. | 123 // Produces |RTCInboundRTPStreamStats| and |RTCOutboundRTPStreamStats|. |
127 void ProduceRTPStreamStats_n( | 124 void ProduceRTPStreamStats_n( |
128 int64_t timestamp_us, const SessionStats& session_stats, | 125 int64_t timestamp_us, const SessionStats& session_stats, |
129 const MediaInfo& media_info, RTCStatsReport* report) const; | 126 const TrackMediaInfoMap& track_media_info_map, |
| 127 RTCStatsReport* report) const; |
130 // Produces |RTCTransportStats|. | 128 // Produces |RTCTransportStats|. |
131 void ProduceTransportStats_n( | 129 void ProduceTransportStats_n( |
132 int64_t timestamp_us, const SessionStats& session_stats, | 130 int64_t timestamp_us, const SessionStats& session_stats, |
133 const std::map<std::string, CertificateStatsPair>& transport_cert_stats, | 131 const std::map<std::string, CertificateStatsPair>& transport_cert_stats, |
134 RTCStatsReport* report) const; | 132 RTCStatsReport* report) const; |
135 | 133 |
136 // Helper function to stats-producing functions. | 134 // Helper function to stats-producing functions. |
137 std::map<std::string, CertificateStatsPair> | 135 std::map<std::string, CertificateStatsPair> |
138 PrepareTransportCertificateStats_n(const SessionStats& session_stats) const; | 136 PrepareTransportCertificateStats_n(const SessionStats& session_stats) const; |
139 std::unique_ptr<MediaInfo> PrepareMediaInfo_s() const; | 137 std::unique_ptr<TrackMediaInfoMap> PrepareTrackMediaInfoMap_s() const; |
140 | 138 |
141 // Slots for signals (sigslot) that are wired up to |pc_|. | 139 // Slots for signals (sigslot) that are wired up to |pc_|. |
142 void OnDataChannelCreated(DataChannel* channel); | 140 void OnDataChannelCreated(DataChannel* channel); |
143 // Slots for signals (sigslot) that are wired up to |channel|. | 141 // Slots for signals (sigslot) that are wired up to |channel|. |
144 void OnDataChannelOpened(DataChannel* channel); | 142 void OnDataChannelOpened(DataChannel* channel); |
145 void OnDataChannelClosed(DataChannel* channel); | 143 void OnDataChannelClosed(DataChannel* channel); |
146 | 144 |
147 PeerConnection* const pc_; | 145 PeerConnection* const pc_; |
148 rtc::Thread* const signaling_thread_; | 146 rtc::Thread* const signaling_thread_; |
149 rtc::Thread* const worker_thread_; | 147 rtc::Thread* const worker_thread_; |
150 rtc::Thread* const network_thread_; | 148 rtc::Thread* const network_thread_; |
151 rtc::AsyncInvoker invoker_; | 149 rtc::AsyncInvoker invoker_; |
152 | 150 |
153 int num_pending_partial_reports_; | 151 int num_pending_partial_reports_; |
154 int64_t partial_report_timestamp_us_; | 152 int64_t partial_report_timestamp_us_; |
155 rtc::scoped_refptr<RTCStatsReport> partial_report_; | 153 rtc::scoped_refptr<RTCStatsReport> partial_report_; |
156 std::vector<rtc::scoped_refptr<RTCStatsCollectorCallback>> callbacks_; | 154 std::vector<rtc::scoped_refptr<RTCStatsCollectorCallback>> callbacks_; |
157 | 155 |
158 // Set in |GetStatsReport|, used in |ProducePartialResultsOnNetworkThread| | 156 // Set in |GetStatsReport|, read in |ProducePartialResultsOnNetworkThread| and |
159 // (not passed as arguments to avoid copies). This is thread safe - it is set | 157 // |ProducePartialResultsOnSignalingThread|, reset after work is complete. Not |
160 // at the start of |GetStatsReport| after making sure there are no pending | 158 // passed as arguments to avoid copies. This is thread safe - when we |
161 // stats requests in progress. | 159 // set/reset we know there are no pending stats requests in progress. |
162 std::unique_ptr<ChannelNamePairs> channel_name_pairs_; | 160 std::unique_ptr<ChannelNamePairs> channel_name_pairs_; |
163 std::unique_ptr<MediaInfo> media_info_; | 161 std::unique_ptr<TrackMediaInfoMap> track_media_info_map_; |
164 | 162 |
165 // A timestamp, in microseconds, that is based on a timer that is | 163 // A timestamp, in microseconds, that is based on a timer that is |
166 // monotonically increasing. That is, even if the system clock is modified the | 164 // monotonically increasing. That is, even if the system clock is modified the |
167 // difference between the timer and this timestamp is how fresh the cached | 165 // difference between the timer and this timestamp is how fresh the cached |
168 // report is. | 166 // report is. |
169 int64_t cache_timestamp_us_; | 167 int64_t cache_timestamp_us_; |
170 int64_t cache_lifetime_us_; | 168 int64_t cache_lifetime_us_; |
171 rtc::scoped_refptr<const RTCStatsReport> cached_report_; | 169 rtc::scoped_refptr<const RTCStatsReport> cached_report_; |
172 | 170 |
173 // Data recorded and maintained by the stats collector during its lifetime. | 171 // Data recorded and maintained by the stats collector during its lifetime. |
(...skipping 17 matching lines...) Expand all Loading... |
191 }; | 189 }; |
192 | 190 |
193 const char* CandidateTypeToRTCIceCandidateTypeForTesting( | 191 const char* CandidateTypeToRTCIceCandidateTypeForTesting( |
194 const std::string& type); | 192 const std::string& type); |
195 const char* DataStateToRTCDataChannelStateForTesting( | 193 const char* DataStateToRTCDataChannelStateForTesting( |
196 DataChannelInterface::DataState state); | 194 DataChannelInterface::DataState state); |
197 | 195 |
198 } // namespace webrtc | 196 } // namespace webrtc |
199 | 197 |
200 #endif // WEBRTC_API_RTCSTATSCOLLECTOR_H_ | 198 #endif // WEBRTC_API_RTCSTATSCOLLECTOR_H_ |
OLD | NEW |