| 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 #include "webrtc/pc/rtcstatscollector.h" | 11 #include "webrtc/pc/rtcstatscollector.h" |
| 12 | 12 |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <sstream> | 14 #include <sstream> |
| 15 #include <utility> | 15 #include <utility> |
| 16 #include <vector> | 16 #include <vector> |
| 17 | 17 |
| 18 #include "webrtc/api/mediastreaminterface.h" | 18 #include "webrtc/api/mediastreaminterface.h" |
| 19 #include "webrtc/api/peerconnectioninterface.h" | 19 #include "webrtc/api/peerconnectioninterface.h" |
| 20 #include "webrtc/media/base/mediachannel.h" | 20 #include "webrtc/media/base/mediachannel.h" |
| 21 #include "webrtc/p2p/base/candidate.h" | 21 #include "webrtc/p2p/base/candidate.h" |
| 22 #include "webrtc/p2p/base/p2pconstants.h" | 22 #include "webrtc/p2p/base/p2pconstants.h" |
| 23 #include "webrtc/p2p/base/port.h" | 23 #include "webrtc/p2p/base/port.h" |
| 24 #include "webrtc/pc/peerconnection.h" | 24 #include "webrtc/pc/peerconnection.h" |
| 25 #include "webrtc/pc/webrtcsession.h" | 25 #include "webrtc/pc/webrtcsession.h" |
| 26 #include "webrtc/rtc_base/checks.h" | 26 #include "webrtc/rtc_base/checks.h" |
| 27 #include "webrtc/rtc_base/stringutils.h" |
| 27 #include "webrtc/rtc_base/timeutils.h" | 28 #include "webrtc/rtc_base/timeutils.h" |
| 29 #include "webrtc/rtc_base/trace_event.h" |
| 28 | 30 |
| 29 namespace webrtc { | 31 namespace webrtc { |
| 30 | 32 |
| 31 namespace { | 33 namespace { |
| 32 | 34 |
| 35 const int kStatTypeMemberNameAndIdMaxLen = 120; |
| 36 |
| 37 std::string GetStatTypeMemberNameAndId(const RTCStats& stats, |
| 38 const RTCStatsMemberInterface* member) { |
| 39 RTC_DCHECK(strlen(stats.type()) + strlen(member->name()) |
| 40 + stats.id().size() + 3 < kStatTypeMemberNameAndIdMaxLen); |
| 41 char buffer[kStatTypeMemberNameAndIdMaxLen]; |
| 42 rtc::sprintfn(&buffer[0], sizeof(buffer), "%s.%s.%s", stats.type(), |
| 43 member->name(), stats.id().c_str()); |
| 44 return buffer; |
| 45 } |
| 46 |
| 33 std::string RTCCertificateIDFromFingerprint(const std::string& fingerprint) { | 47 std::string RTCCertificateIDFromFingerprint(const std::string& fingerprint) { |
| 34 return "RTCCertificate_" + fingerprint; | 48 return "RTCCertificate_" + fingerprint; |
| 35 } | 49 } |
| 36 | 50 |
| 37 std::string RTCCodecStatsIDFromDirectionMediaAndPayload( | 51 std::string RTCCodecStatsIDFromDirectionMediaAndPayload( |
| 38 bool inbound, bool audio, uint32_t payload_type) { | 52 bool inbound, bool audio, uint32_t payload_type) { |
| 39 // TODO(hbos): The present codec ID assignment is not sufficient to support | 53 // TODO(hbos): The present codec ID assignment is not sufficient to support |
| 40 // Unified Plan or unbundled connections in all cases. When we are able to | 54 // Unified Plan or unbundled connections in all cases. When we are able to |
| 41 // handle multiple m= lines of the same media type (and multiple BaseChannels | 55 // handle multiple m= lines of the same media type (and multiple BaseChannels |
| 42 // for the same type is possible?) this needs to be updated to differentiate | 56 // for the same type is possible?) this needs to be updated to differentiate |
| (...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 751 else | 765 else |
| 752 partial_report_->TakeMembersFrom(partial_report); | 766 partial_report_->TakeMembersFrom(partial_report); |
| 753 --num_pending_partial_reports_; | 767 --num_pending_partial_reports_; |
| 754 if (!num_pending_partial_reports_) { | 768 if (!num_pending_partial_reports_) { |
| 755 cache_timestamp_us_ = partial_report_timestamp_us_; | 769 cache_timestamp_us_ = partial_report_timestamp_us_; |
| 756 cached_report_ = partial_report_; | 770 cached_report_ = partial_report_; |
| 757 partial_report_ = nullptr; | 771 partial_report_ = nullptr; |
| 758 channel_name_pairs_.reset(); | 772 channel_name_pairs_.reset(); |
| 759 track_media_info_map_.reset(); | 773 track_media_info_map_.reset(); |
| 760 track_to_id_.clear(); | 774 track_to_id_.clear(); |
| 775 // Trace WebRTC Stats when getStats is called on Javascript. |
| 776 // This allows access to WebRTC stats from trace logs. To enable them, |
| 777 // select the "webrtc_stats" category when recording traces. |
| 778 for (const RTCStats& stats : *cached_report_) { |
| 779 for (const RTCStatsMemberInterface* member : stats.Members()) { |
| 780 if (member->is_defined()) { |
| 781 TRACE_EVENT_INSTANT2("webrtc_stats", "webrtc_stats", |
| 782 "value", member->ValueToString(), |
| 783 "type.name.id", GetStatTypeMemberNameAndId( |
| 784 stats, member)); |
| 785 } |
| 786 } |
| 787 } |
| 761 DeliverCachedReport(); | 788 DeliverCachedReport(); |
| 762 } | 789 } |
| 763 } | 790 } |
| 764 | 791 |
| 765 void RTCStatsCollector::DeliverCachedReport() { | 792 void RTCStatsCollector::DeliverCachedReport() { |
| 766 RTC_DCHECK(signaling_thread_->IsCurrent()); | 793 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 767 RTC_DCHECK(!callbacks_.empty()); | 794 RTC_DCHECK(!callbacks_.empty()); |
| 768 RTC_DCHECK(cached_report_); | 795 RTC_DCHECK(cached_report_); |
| 769 for (const rtc::scoped_refptr<RTCStatsCollectorCallback>& callback : | 796 for (const rtc::scoped_refptr<RTCStatsCollectorCallback>& callback : |
| 770 callbacks_) { | 797 callbacks_) { |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1248 const std::string& type) { | 1275 const std::string& type) { |
| 1249 return CandidateTypeToRTCIceCandidateType(type); | 1276 return CandidateTypeToRTCIceCandidateType(type); |
| 1250 } | 1277 } |
| 1251 | 1278 |
| 1252 const char* DataStateToRTCDataChannelStateForTesting( | 1279 const char* DataStateToRTCDataChannelStateForTesting( |
| 1253 DataChannelInterface::DataState state) { | 1280 DataChannelInterface::DataState state) { |
| 1254 return DataStateToRTCDataChannelState(state); | 1281 return DataStateToRTCDataChannelState(state); |
| 1255 } | 1282 } |
| 1256 | 1283 |
| 1257 } // namespace webrtc | 1284 } // namespace webrtc |
| OLD | NEW |