| 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 |
| 56 std::string RTCOutboundRTPStreamStatsIDFromSSRC(bool audio, uint32_t ssrc) { | 61 std::string RTCOutboundRTPStreamStatsIDFromSSRC(bool audio, uint32_t ssrc) { |
| 57 return audio ? "RTCOutboundRTPAudioStream_" + rtc::ToString<>(ssrc) | 62 return audio ? "RTCOutboundRTPAudioStream_" + rtc::ToString<>(ssrc) |
| 58 : "RTCOutboundRTPVideoStream_" + rtc::ToString<>(ssrc); | 63 : "RTCOutboundRTPVideoStream_" + rtc::ToString<>(ssrc); |
| 59 } | 64 } |
| 60 | 65 |
| 61 const char* CandidateTypeToRTCIceCandidateType(const std::string& type) { | 66 const char* CandidateTypeToRTCIceCandidateType(const std::string& type) { |
| 62 if (type == cricket::LOCAL_PORT_TYPE) | 67 if (type == cricket::LOCAL_PORT_TYPE) |
| 63 return RTCIceCandidateType::kHost; | 68 return RTCIceCandidateType::kHost; |
| 64 if (type == cricket::STUN_PORT_TYPE) | 69 if (type == cricket::STUN_PORT_TYPE) |
| 65 return RTCIceCandidateType::kSrflx; | 70 return RTCIceCandidateType::kSrflx; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 81 case DataChannelInterface::kClosing: | 86 case DataChannelInterface::kClosing: |
| 82 return RTCDataChannelState::kClosing; | 87 return RTCDataChannelState::kClosing; |
| 83 case DataChannelInterface::kClosed: | 88 case DataChannelInterface::kClosed: |
| 84 return RTCDataChannelState::kClosed; | 89 return RTCDataChannelState::kClosed; |
| 85 default: | 90 default: |
| 86 RTC_NOTREACHED(); | 91 RTC_NOTREACHED(); |
| 87 return nullptr; | 92 return nullptr; |
| 88 } | 93 } |
| 89 } | 94 } |
| 90 | 95 |
| 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 |
| 91 void SetOutboundRTPStreamStatsFromMediaSenderInfo( | 132 void SetOutboundRTPStreamStatsFromMediaSenderInfo( |
| 92 const cricket::MediaSenderInfo& media_sender_info, | 133 const cricket::MediaSenderInfo& media_sender_info, |
| 93 RTCOutboundRTPStreamStats* outbound_stats) { | 134 RTCOutboundRTPStreamStats* outbound_stats) { |
| 94 RTC_DCHECK(outbound_stats); | 135 RTC_DCHECK(outbound_stats); |
| 95 outbound_stats->ssrc = rtc::ToString<>(media_sender_info.ssrc()); | 136 outbound_stats->ssrc = rtc::ToString<>(media_sender_info.ssrc()); |
| 96 // TODO(hbos): Support the remote case. crbug.com/657856 | 137 // TODO(hbos): Support the remote case. crbug.com/657856 |
| 97 outbound_stats->is_remote = false; | 138 outbound_stats->is_remote = false; |
| 98 // TODO(hbos): Set |codec_id| when we have |RTCCodecStats|. Maybe relevant: | 139 // TODO(hbos): Set |codec_id| when we have |RTCCodecStats|. Maybe relevant: |
| 99 // |media_sender_info.codec_name|. crbug.com/657854, 657856, 659117 | 140 // |media_sender_info.codec_name|. crbug.com/657854, 657856, 659117 |
| 100 outbound_stats->packets_sent = | 141 outbound_stats->packets_sent = |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 int64_t timestamp_us, const SessionStats& session_stats, | 494 int64_t timestamp_us, const SessionStats& session_stats, |
| 454 RTCStatsReport* report) const { | 495 RTCStatsReport* report) const { |
| 455 RTC_DCHECK(signaling_thread_->IsCurrent()); | 496 RTC_DCHECK(signaling_thread_->IsCurrent()); |
| 456 | 497 |
| 457 // Audio | 498 // Audio |
| 458 if (pc_->session()->voice_channel()) { | 499 if (pc_->session()->voice_channel()) { |
| 459 cricket::VoiceMediaInfo voice_media_info; | 500 cricket::VoiceMediaInfo voice_media_info; |
| 460 if (pc_->session()->voice_channel()->GetStats(&voice_media_info)) { | 501 if (pc_->session()->voice_channel()->GetStats(&voice_media_info)) { |
| 461 std::string transport_id = RTCTransportStatsIDFromBaseChannel( | 502 std::string transport_id = RTCTransportStatsIDFromBaseChannel( |
| 462 session_stats.proxy_to_transport, *pc_->session()->voice_channel()); | 503 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 |
| 463 for (const cricket::VoiceSenderInfo& voice_sender_info : | 523 for (const cricket::VoiceSenderInfo& voice_sender_info : |
| 464 voice_media_info.senders) { | 524 voice_media_info.senders) { |
| 465 // TODO(nisse): SSRC == 0 currently means none. Delete check when that | 525 // TODO(nisse): SSRC == 0 currently means none. Delete check when that |
| 466 // is fixed. | 526 // is fixed. |
| 467 if (voice_sender_info.ssrc() == 0) | 527 if (voice_sender_info.ssrc() == 0) |
| 468 continue; | 528 continue; |
| 469 std::unique_ptr<RTCOutboundRTPStreamStats> outbound_audio( | 529 std::unique_ptr<RTCOutboundRTPStreamStats> outbound_audio( |
| 470 new RTCOutboundRTPStreamStats( | 530 new RTCOutboundRTPStreamStats( |
| 471 RTCOutboundRTPStreamStatsIDFromSSRC( | 531 RTCOutboundRTPStreamStatsIDFromSSRC( |
| 472 true, voice_sender_info.ssrc()), | 532 true, voice_sender_info.ssrc()), |
| 473 timestamp_us)); | 533 timestamp_us)); |
| 474 SetOutboundRTPStreamStatsFromVoiceSenderInfo( | 534 SetOutboundRTPStreamStatsFromVoiceSenderInfo( |
| 475 voice_sender_info, outbound_audio.get()); | 535 voice_sender_info, outbound_audio.get()); |
| 476 if (!transport_id.empty()) | 536 outbound_audio->transport_id = transport_id; |
| 477 outbound_audio->transport_id = transport_id; | |
| 478 report->AddStats(std::move(outbound_audio)); | 537 report->AddStats(std::move(outbound_audio)); |
| 479 } | 538 } |
| 480 } | 539 } |
| 481 } | 540 } |
| 482 // Video | 541 // Video |
| 483 if (pc_->session()->video_channel()) { | 542 if (pc_->session()->video_channel()) { |
| 484 cricket::VideoMediaInfo video_media_info; | 543 cricket::VideoMediaInfo video_media_info; |
| 485 if (pc_->session()->video_channel()->GetStats(&video_media_info)) { | 544 if (pc_->session()->video_channel()->GetStats(&video_media_info)) { |
| 486 std::string transport_id = RTCTransportStatsIDFromBaseChannel( | 545 std::string transport_id = RTCTransportStatsIDFromBaseChannel( |
| 487 session_stats.proxy_to_transport, *pc_->session()->video_channel()); | 546 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 |
| 488 for (const cricket::VideoSenderInfo& video_sender_info : | 566 for (const cricket::VideoSenderInfo& video_sender_info : |
| 489 video_media_info.senders) { | 567 video_media_info.senders) { |
| 490 // TODO(nisse): SSRC == 0 currently means none. Delete check when that | 568 // TODO(nisse): SSRC == 0 currently means none. Delete check when that |
| 491 // is fixed. | 569 // is fixed. |
| 492 if (video_sender_info.ssrc() == 0) | 570 if (video_sender_info.ssrc() == 0) |
| 493 continue; | 571 continue; |
| 494 std::unique_ptr<RTCOutboundRTPStreamStats> outbound_video( | 572 std::unique_ptr<RTCOutboundRTPStreamStats> outbound_video( |
| 495 new RTCOutboundRTPStreamStats( | 573 new RTCOutboundRTPStreamStats( |
| 496 RTCOutboundRTPStreamStatsIDFromSSRC( | 574 RTCOutboundRTPStreamStatsIDFromSSRC( |
| 497 false, video_sender_info.ssrc()), | 575 false, video_sender_info.ssrc()), |
| 498 timestamp_us)); | 576 timestamp_us)); |
| 499 SetOutboundRTPStreamStatsFromVideoSenderInfo( | 577 SetOutboundRTPStreamStatsFromVideoSenderInfo( |
| 500 video_sender_info, outbound_video.get()); | 578 video_sender_info, outbound_video.get()); |
| 501 if (!transport_id.empty()) | 579 outbound_video->transport_id = transport_id; |
| 502 outbound_video->transport_id = transport_id; | |
| 503 report->AddStats(std::move(outbound_video)); | 580 report->AddStats(std::move(outbound_video)); |
| 504 } | 581 } |
| 505 } | 582 } |
| 506 } | 583 } |
| 507 } | 584 } |
| 508 | 585 |
| 509 void RTCStatsCollector::ProduceTransportStats_s( | 586 void RTCStatsCollector::ProduceTransportStats_s( |
| 510 int64_t timestamp_us, const SessionStats& session_stats, | 587 int64_t timestamp_us, const SessionStats& session_stats, |
| 511 const std::map<std::string, CertificateStatsPair>& transport_cert_stats, | 588 const std::map<std::string, CertificateStatsPair>& transport_cert_stats, |
| 512 RTCStatsReport* report) const { | 589 RTCStatsReport* report) const { |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 const std::string& type) { | 679 const std::string& type) { |
| 603 return CandidateTypeToRTCIceCandidateType(type); | 680 return CandidateTypeToRTCIceCandidateType(type); |
| 604 } | 681 } |
| 605 | 682 |
| 606 const char* DataStateToRTCDataChannelStateForTesting( | 683 const char* DataStateToRTCDataChannelStateForTesting( |
| 607 DataChannelInterface::DataState state) { | 684 DataChannelInterface::DataState state) { |
| 608 return DataStateToRTCDataChannelState(state); | 685 return DataStateToRTCDataChannelState(state); |
| 609 } | 686 } |
| 610 | 687 |
| 611 } // namespace webrtc | 688 } // namespace webrtc |
| OLD | NEW |