| 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 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 std::string RTCTransportStatsIDFromBaseChannel( | 46 std::string RTCTransportStatsIDFromBaseChannel( |
| 47 const ProxyTransportMap& proxy_to_transport, | 47 const ProxyTransportMap& proxy_to_transport, |
| 48 const cricket::BaseChannel& base_channel) { | 48 const cricket::BaseChannel& base_channel) { |
| 49 auto proxy_it = proxy_to_transport.find(base_channel.content_name()); | 49 auto proxy_it = proxy_to_transport.find(base_channel.content_name()); |
| 50 if (proxy_it == proxy_to_transport.cend()) | 50 if (proxy_it == proxy_to_transport.cend()) |
| 51 return ""; | 51 return ""; |
| 52 return RTCTransportStatsIDFromTransportChannel( | 52 return RTCTransportStatsIDFromTransportChannel( |
| 53 proxy_it->second, cricket::ICE_CANDIDATE_COMPONENT_RTP); | 53 proxy_it->second, cricket::ICE_CANDIDATE_COMPONENT_RTP); |
| 54 } | 54 } |
| 55 | 55 |
| 56 std::string RTCInboundRTPStreamStatsIDFromSSRC(bool audio, uint32_t ssrc) { | |
| 57 return audio ? "RTCInboundRTPAudioStream_" + rtc::ToString<>(ssrc) | |
| 58 : "RTCInboundRTPVideoStream_" + rtc::ToString<>(ssrc); | |
| 59 } | |
| 60 | |
| 61 std::string RTCOutboundRTPStreamStatsIDFromSSRC(bool audio, uint32_t ssrc) { | 56 std::string RTCOutboundRTPStreamStatsIDFromSSRC(bool audio, uint32_t ssrc) { |
| 62 return audio ? "RTCOutboundRTPAudioStream_" + rtc::ToString<>(ssrc) | 57 return audio ? "RTCOutboundRTPAudioStream_" + rtc::ToString<>(ssrc) |
| 63 : "RTCOutboundRTPVideoStream_" + rtc::ToString<>(ssrc); | 58 : "RTCOutboundRTPVideoStream_" + rtc::ToString<>(ssrc); |
| 64 } | 59 } |
| 65 | 60 |
| 66 const char* CandidateTypeToRTCIceCandidateType(const std::string& type) { | 61 const char* CandidateTypeToRTCIceCandidateType(const std::string& type) { |
| 67 if (type == cricket::LOCAL_PORT_TYPE) | 62 if (type == cricket::LOCAL_PORT_TYPE) |
| 68 return RTCIceCandidateType::kHost; | 63 return RTCIceCandidateType::kHost; |
| 69 if (type == cricket::STUN_PORT_TYPE) | 64 if (type == cricket::STUN_PORT_TYPE) |
| 70 return RTCIceCandidateType::kSrflx; | 65 return RTCIceCandidateType::kSrflx; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 86 case DataChannelInterface::kClosing: | 81 case DataChannelInterface::kClosing: |
| 87 return RTCDataChannelState::kClosing; | 82 return RTCDataChannelState::kClosing; |
| 88 case DataChannelInterface::kClosed: | 83 case DataChannelInterface::kClosed: |
| 89 return RTCDataChannelState::kClosed; | 84 return RTCDataChannelState::kClosed; |
| 90 default: | 85 default: |
| 91 RTC_NOTREACHED(); | 86 RTC_NOTREACHED(); |
| 92 return nullptr; | 87 return nullptr; |
| 93 } | 88 } |
| 94 } | 89 } |
| 95 | 90 |
| 96 void SetInboundRTPStreamStatsFromMediaReceiverInfo( | |
| 97 const cricket::MediaReceiverInfo& media_receiver_info, | |
| 98 RTCInboundRTPStreamStats* inbound_stats) { | |
| 99 RTC_DCHECK(inbound_stats); | |
| 100 inbound_stats->ssrc = rtc::ToString<>(media_receiver_info.ssrc()); | |
| 101 // TODO(hbos): Support the remote case. crbug.com/657855 | |
| 102 inbound_stats->is_remote = false; | |
| 103 // TODO(hbos): Set |codec_id| when we have |RTCCodecStats|. Maybe relevant: | |
| 104 // |media_receiver_info.codec_name|. crbug.com/657854, 657855, 659117 | |
| 105 inbound_stats->packets_received = | |
| 106 static_cast<uint32_t>(media_receiver_info.packets_rcvd); | |
| 107 inbound_stats->bytes_received = | |
| 108 static_cast<uint64_t>(media_receiver_info.bytes_rcvd); | |
| 109 inbound_stats->fraction_lost = | |
| 110 static_cast<double>(media_receiver_info.fraction_lost); | |
| 111 } | |
| 112 | |
| 113 void SetInboundRTPStreamStatsFromVoiceReceiverInfo( | |
| 114 const cricket::VoiceReceiverInfo& voice_receiver_info, | |
| 115 RTCInboundRTPStreamStats* inbound_stats) { | |
| 116 SetInboundRTPStreamStatsFromMediaReceiverInfo( | |
| 117 voice_receiver_info, inbound_stats); | |
| 118 inbound_stats->media_type = "audio"; | |
| 119 inbound_stats->jitter = | |
| 120 static_cast<double>(voice_receiver_info.jitter_ms) / | |
| 121 rtc::kNumMillisecsPerSec; | |
| 122 } | |
| 123 | |
| 124 void SetInboundRTPStreamStatsFromVideoReceiverInfo( | |
| 125 const cricket::VideoReceiverInfo& video_receiver_info, | |
| 126 RTCInboundRTPStreamStats* inbound_stats) { | |
| 127 SetInboundRTPStreamStatsFromMediaReceiverInfo( | |
| 128 video_receiver_info, inbound_stats); | |
| 129 inbound_stats->media_type = "video"; | |
| 130 } | |
| 131 | |
| 132 void SetOutboundRTPStreamStatsFromMediaSenderInfo( | 91 void SetOutboundRTPStreamStatsFromMediaSenderInfo( |
| 133 const cricket::MediaSenderInfo& media_sender_info, | 92 const cricket::MediaSenderInfo& media_sender_info, |
| 134 RTCOutboundRTPStreamStats* outbound_stats) { | 93 RTCOutboundRTPStreamStats* outbound_stats) { |
| 135 RTC_DCHECK(outbound_stats); | 94 RTC_DCHECK(outbound_stats); |
| 136 outbound_stats->ssrc = rtc::ToString<>(media_sender_info.ssrc()); | 95 outbound_stats->ssrc = rtc::ToString<>(media_sender_info.ssrc()); |
| 137 // TODO(hbos): Support the remote case. crbug.com/657856 | 96 // TODO(hbos): Support the remote case. crbug.com/657856 |
| 138 outbound_stats->is_remote = false; | 97 outbound_stats->is_remote = false; |
| 139 // TODO(hbos): Set |codec_id| when we have |RTCCodecStats|. Maybe relevant: | 98 // TODO(hbos): Set |codec_id| when we have |RTCCodecStats|. Maybe relevant: |
| 140 // |media_sender_info.codec_name|. crbug.com/657854, 657856, 659117 | 99 // |media_sender_info.codec_name|. crbug.com/657854, 657856, 659117 |
| 141 outbound_stats->packets_sent = | 100 outbound_stats->packets_sent = |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 int64_t timestamp_us, const SessionStats& session_stats, | 453 int64_t timestamp_us, const SessionStats& session_stats, |
| 495 RTCStatsReport* report) const { | 454 RTCStatsReport* report) const { |
| 496 RTC_DCHECK(signaling_thread_->IsCurrent()); | 455 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 497 | 456 |
| 498 // Audio | 457 // Audio |
| 499 if (pc_->session()->voice_channel()) { | 458 if (pc_->session()->voice_channel()) { |
| 500 cricket::VoiceMediaInfo voice_media_info; | 459 cricket::VoiceMediaInfo voice_media_info; |
| 501 if (pc_->session()->voice_channel()->GetStats(&voice_media_info)) { | 460 if (pc_->session()->voice_channel()->GetStats(&voice_media_info)) { |
| 502 std::string transport_id = RTCTransportStatsIDFromBaseChannel( | 461 std::string transport_id = RTCTransportStatsIDFromBaseChannel( |
| 503 session_stats.proxy_to_transport, *pc_->session()->voice_channel()); | 462 session_stats.proxy_to_transport, *pc_->session()->voice_channel()); |
| 504 RTC_DCHECK(!transport_id.empty()); | |
| 505 // Inbound | |
| 506 for (const cricket::VoiceReceiverInfo& voice_receiver_info : | |
| 507 voice_media_info.receivers) { | |
| 508 // TODO(nisse): SSRC == 0 currently means none. Delete check when that | |
| 509 // is fixed. | |
| 510 if (voice_receiver_info.ssrc() == 0) | |
| 511 continue; | |
| 512 std::unique_ptr<RTCInboundRTPStreamStats> inbound_audio( | |
| 513 new RTCInboundRTPStreamStats( | |
| 514 RTCInboundRTPStreamStatsIDFromSSRC( | |
| 515 true, voice_receiver_info.ssrc()), | |
| 516 timestamp_us)); | |
| 517 SetInboundRTPStreamStatsFromVoiceReceiverInfo( | |
| 518 voice_receiver_info, inbound_audio.get()); | |
| 519 inbound_audio->transport_id = transport_id; | |
| 520 report->AddStats(std::move(inbound_audio)); | |
| 521 } | |
| 522 // Outbound | |
| 523 for (const cricket::VoiceSenderInfo& voice_sender_info : | 463 for (const cricket::VoiceSenderInfo& voice_sender_info : |
| 524 voice_media_info.senders) { | 464 voice_media_info.senders) { |
| 525 // TODO(nisse): SSRC == 0 currently means none. Delete check when that | 465 // TODO(nisse): SSRC == 0 currently means none. Delete check when that |
| 526 // is fixed. | 466 // is fixed. |
| 527 if (voice_sender_info.ssrc() == 0) | 467 if (voice_sender_info.ssrc() == 0) |
| 528 continue; | 468 continue; |
| 529 std::unique_ptr<RTCOutboundRTPStreamStats> outbound_audio( | 469 std::unique_ptr<RTCOutboundRTPStreamStats> outbound_audio( |
| 530 new RTCOutboundRTPStreamStats( | 470 new RTCOutboundRTPStreamStats( |
| 531 RTCOutboundRTPStreamStatsIDFromSSRC( | 471 RTCOutboundRTPStreamStatsIDFromSSRC( |
| 532 true, voice_sender_info.ssrc()), | 472 true, voice_sender_info.ssrc()), |
| 533 timestamp_us)); | 473 timestamp_us)); |
| 534 SetOutboundRTPStreamStatsFromVoiceSenderInfo( | 474 SetOutboundRTPStreamStatsFromVoiceSenderInfo( |
| 535 voice_sender_info, outbound_audio.get()); | 475 voice_sender_info, outbound_audio.get()); |
| 536 outbound_audio->transport_id = transport_id; | 476 if (!transport_id.empty()) |
| 477 outbound_audio->transport_id = transport_id; |
| 537 report->AddStats(std::move(outbound_audio)); | 478 report->AddStats(std::move(outbound_audio)); |
| 538 } | 479 } |
| 539 } | 480 } |
| 540 } | 481 } |
| 541 // Video | 482 // Video |
| 542 if (pc_->session()->video_channel()) { | 483 if (pc_->session()->video_channel()) { |
| 543 cricket::VideoMediaInfo video_media_info; | 484 cricket::VideoMediaInfo video_media_info; |
| 544 if (pc_->session()->video_channel()->GetStats(&video_media_info)) { | 485 if (pc_->session()->video_channel()->GetStats(&video_media_info)) { |
| 545 std::string transport_id = RTCTransportStatsIDFromBaseChannel( | 486 std::string transport_id = RTCTransportStatsIDFromBaseChannel( |
| 546 session_stats.proxy_to_transport, *pc_->session()->video_channel()); | 487 session_stats.proxy_to_transport, *pc_->session()->video_channel()); |
| 547 RTC_DCHECK(!transport_id.empty()); | |
| 548 // Inbound | |
| 549 for (const cricket::VideoReceiverInfo& video_receiver_info : | |
| 550 video_media_info.receivers) { | |
| 551 // TODO(nisse): SSRC == 0 currently means none. Delete check when that | |
| 552 // is fixed. | |
| 553 if (video_receiver_info.ssrc() == 0) | |
| 554 continue; | |
| 555 std::unique_ptr<RTCInboundRTPStreamStats> inbound_video( | |
| 556 new RTCInboundRTPStreamStats( | |
| 557 RTCInboundRTPStreamStatsIDFromSSRC( | |
| 558 false, video_receiver_info.ssrc()), | |
| 559 timestamp_us)); | |
| 560 SetInboundRTPStreamStatsFromVideoReceiverInfo( | |
| 561 video_receiver_info, inbound_video.get()); | |
| 562 inbound_video->transport_id = transport_id; | |
| 563 report->AddStats(std::move(inbound_video)); | |
| 564 } | |
| 565 // Outbound | |
| 566 for (const cricket::VideoSenderInfo& video_sender_info : | 488 for (const cricket::VideoSenderInfo& video_sender_info : |
| 567 video_media_info.senders) { | 489 video_media_info.senders) { |
| 568 // TODO(nisse): SSRC == 0 currently means none. Delete check when that | 490 // TODO(nisse): SSRC == 0 currently means none. Delete check when that |
| 569 // is fixed. | 491 // is fixed. |
| 570 if (video_sender_info.ssrc() == 0) | 492 if (video_sender_info.ssrc() == 0) |
| 571 continue; | 493 continue; |
| 572 std::unique_ptr<RTCOutboundRTPStreamStats> outbound_video( | 494 std::unique_ptr<RTCOutboundRTPStreamStats> outbound_video( |
| 573 new RTCOutboundRTPStreamStats( | 495 new RTCOutboundRTPStreamStats( |
| 574 RTCOutboundRTPStreamStatsIDFromSSRC( | 496 RTCOutboundRTPStreamStatsIDFromSSRC( |
| 575 false, video_sender_info.ssrc()), | 497 false, video_sender_info.ssrc()), |
| 576 timestamp_us)); | 498 timestamp_us)); |
| 577 SetOutboundRTPStreamStatsFromVideoSenderInfo( | 499 SetOutboundRTPStreamStatsFromVideoSenderInfo( |
| 578 video_sender_info, outbound_video.get()); | 500 video_sender_info, outbound_video.get()); |
| 579 outbound_video->transport_id = transport_id; | 501 if (!transport_id.empty()) |
| 502 outbound_video->transport_id = transport_id; |
| 580 report->AddStats(std::move(outbound_video)); | 503 report->AddStats(std::move(outbound_video)); |
| 581 } | 504 } |
| 582 } | 505 } |
| 583 } | 506 } |
| 584 } | 507 } |
| 585 | 508 |
| 586 void RTCStatsCollector::ProduceTransportStats_s( | 509 void RTCStatsCollector::ProduceTransportStats_s( |
| 587 int64_t timestamp_us, const SessionStats& session_stats, | 510 int64_t timestamp_us, const SessionStats& session_stats, |
| 588 const std::map<std::string, CertificateStatsPair>& transport_cert_stats, | 511 const std::map<std::string, CertificateStatsPair>& transport_cert_stats, |
| 589 RTCStatsReport* report) const { | 512 RTCStatsReport* report) const { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 679 const std::string& type) { | 602 const std::string& type) { |
| 680 return CandidateTypeToRTCIceCandidateType(type); | 603 return CandidateTypeToRTCIceCandidateType(type); |
| 681 } | 604 } |
| 682 | 605 |
| 683 const char* DataStateToRTCDataChannelStateForTesting( | 606 const char* DataStateToRTCDataChannelStateForTesting( |
| 684 DataChannelInterface::DataState state) { | 607 DataChannelInterface::DataState state) { |
| 685 return DataStateToRTCDataChannelState(state); | 608 return DataStateToRTCDataChannelState(state); |
| 686 } | 609 } |
| 687 | 610 |
| 688 } // namespace webrtc | 611 } // namespace webrtc |
| OLD | NEW |