| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright 2012 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 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 396 // Wallclock time in ms. | 396 // Wallclock time in ms. |
| 397 double StatsCollector::GetTimeNow() { | 397 double StatsCollector::GetTimeNow() { |
| 398 return rtc::TimeUTCMicros() / | 398 return rtc::TimeUTCMicros() / |
| 399 static_cast<double>(rtc::kNumMicrosecsPerMillisec); | 399 static_cast<double>(rtc::kNumMicrosecsPerMillisec); |
| 400 } | 400 } |
| 401 | 401 |
| 402 // Adds a MediaStream with tracks that can be used as a |selector| in a call | 402 // Adds a MediaStream with tracks that can be used as a |selector| in a call |
| 403 // to GetStats. | 403 // to GetStats. |
| 404 void StatsCollector::AddStream(MediaStreamInterface* stream) { | 404 void StatsCollector::AddStream(MediaStreamInterface* stream) { |
| 405 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); | 405 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
| 406 RTC_DCHECK(stream != NULL); | 406 RTC_DCHECK(stream != nullptr); |
| 407 | 407 |
| 408 CreateTrackReports<AudioTrackVector>(stream->GetAudioTracks(), | 408 CreateTrackReports<AudioTrackVector>(stream->GetAudioTracks(), |
| 409 &reports_, track_ids_); | 409 &reports_, track_ids_); |
| 410 CreateTrackReports<VideoTrackVector>(stream->GetVideoTracks(), | 410 CreateTrackReports<VideoTrackVector>(stream->GetVideoTracks(), |
| 411 &reports_, track_ids_); | 411 &reports_, track_ids_); |
| 412 } | 412 } |
| 413 | 413 |
| 414 void StatsCollector::AddLocalAudioTrack(AudioTrackInterface* audio_track, | 414 void StatsCollector::AddLocalAudioTrack(AudioTrackInterface* audio_track, |
| 415 uint32_t ssrc) { | 415 uint32_t ssrc) { |
| 416 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); | 416 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
| 417 RTC_DCHECK(audio_track != NULL); | 417 RTC_DCHECK(audio_track != nullptr); |
| 418 #if RTC_DCHECK_IS_ON | 418 #if RTC_DCHECK_IS_ON |
| 419 for (const auto& track : local_audio_tracks_) | 419 for (const auto& track : local_audio_tracks_) |
| 420 RTC_DCHECK(track.first != audio_track || track.second != ssrc); | 420 RTC_DCHECK(track.first != audio_track || track.second != ssrc); |
| 421 #endif | 421 #endif |
| 422 | 422 |
| 423 local_audio_tracks_.push_back(std::make_pair(audio_track, ssrc)); | 423 local_audio_tracks_.push_back(std::make_pair(audio_track, ssrc)); |
| 424 | 424 |
| 425 // Create the kStatsReportTypeTrack report for the new track if there is no | 425 // Create the kStatsReportTypeTrack report for the new track if there is no |
| 426 // report yet. | 426 // report yet. |
| 427 StatsReport::Id id(StatsReport::NewTypedId(StatsReport::kStatsReportTypeTrack, | 427 StatsReport::Id id(StatsReport::NewTypedId(StatsReport::kStatsReportTypeTrack, |
| 428 audio_track->id())); | 428 audio_track->id())); |
| 429 StatsReport* report = reports_.Find(id); | 429 StatsReport* report = reports_.Find(id); |
| 430 if (!report) { | 430 if (!report) { |
| 431 report = reports_.InsertNew(id); | 431 report = reports_.InsertNew(id); |
| 432 report->AddString(StatsReport::kStatsValueNameTrackId, audio_track->id()); | 432 report->AddString(StatsReport::kStatsValueNameTrackId, audio_track->id()); |
| 433 } | 433 } |
| 434 } | 434 } |
| 435 | 435 |
| 436 void StatsCollector::RemoveLocalAudioTrack(AudioTrackInterface* audio_track, | 436 void StatsCollector::RemoveLocalAudioTrack(AudioTrackInterface* audio_track, |
| 437 uint32_t ssrc) { | 437 uint32_t ssrc) { |
| 438 RTC_DCHECK(audio_track != NULL); | 438 RTC_DCHECK(audio_track != nullptr); |
| 439 local_audio_tracks_.erase(std::remove_if(local_audio_tracks_.begin(), | 439 local_audio_tracks_.erase(std::remove_if(local_audio_tracks_.begin(), |
| 440 local_audio_tracks_.end(), | 440 local_audio_tracks_.end(), |
| 441 [audio_track, ssrc](const LocalAudioTrackVector::value_type& track) { | 441 [audio_track, ssrc](const LocalAudioTrackVector::value_type& track) { |
| 442 return track.first == audio_track && track.second == ssrc; | 442 return track.first == audio_track && track.second == ssrc; |
| 443 })); | 443 })); |
| 444 } | 444 } |
| 445 | 445 |
| 446 void StatsCollector::GetStats(MediaStreamTrackInterface* track, | 446 void StatsCollector::GetStats(MediaStreamTrackInterface* track, |
| 447 StatsReports* reports) { | 447 StatsReports* reports) { |
| 448 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); | 448 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
| 449 RTC_DCHECK(reports != NULL); | 449 RTC_DCHECK(reports != nullptr); |
| 450 RTC_DCHECK(reports->empty()); | 450 RTC_DCHECK(reports->empty()); |
| 451 | 451 |
| 452 rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; | 452 rtc::Thread::ScopedDisallowBlockingCalls no_blocking_calls; |
| 453 | 453 |
| 454 if (!track) { | 454 if (!track) { |
| 455 reports->reserve(reports_.size()); | 455 reports->reserve(reports_.size()); |
| 456 for (auto* r : reports_) | 456 for (auto* r : reports_) |
| 457 reports->push_back(r); | 457 reports->push_back(r); |
| 458 return; | 458 return; |
| 459 } | 459 } |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 StatsReport::Id id(StatsReport::NewIdWithDirection( | 523 StatsReport::Id id(StatsReport::NewIdWithDirection( |
| 524 local ? StatsReport::kStatsReportTypeSsrc | 524 local ? StatsReport::kStatsReportTypeSsrc |
| 525 : StatsReport::kStatsReportTypeRemoteSsrc, | 525 : StatsReport::kStatsReportTypeRemoteSsrc, |
| 526 rtc::ToString<uint32_t>(ssrc), direction)); | 526 rtc::ToString<uint32_t>(ssrc), direction)); |
| 527 StatsReport* report = reports_.Find(id); | 527 StatsReport* report = reports_.Find(id); |
| 528 | 528 |
| 529 // Use the ID of the track that is currently mapped to the SSRC, if any. | 529 // Use the ID of the track that is currently mapped to the SSRC, if any. |
| 530 std::string track_id; | 530 std::string track_id; |
| 531 if (!GetTrackIdBySsrc(ssrc, &track_id, direction)) { | 531 if (!GetTrackIdBySsrc(ssrc, &track_id, direction)) { |
| 532 if (!report) { | 532 if (!report) { |
| 533 // The ssrc is not used by any track or existing report, return NULL | 533 // The ssrc is not used by any track or existing report, return null |
| 534 // in such case to indicate no report is prepared for the ssrc. | 534 // in such case to indicate no report is prepared for the ssrc. |
| 535 return NULL; | 535 return nullptr; |
| 536 } | 536 } |
| 537 | 537 |
| 538 // The ssrc is not used by any existing track. Keeps the old track id | 538 // The ssrc is not used by any existing track. Keeps the old track id |
| 539 // since we want to report the stats for inactive ssrc. | 539 // since we want to report the stats for inactive ssrc. |
| 540 const StatsReport::Value* v = | 540 const StatsReport::Value* v = |
| 541 report->FindValue(StatsReport::kStatsValueNameTrackId); | 541 report->FindValue(StatsReport::kStatsValueNameTrackId); |
| 542 if (v) | 542 if (v) |
| 543 track_id = v->string_val(); | 543 track_id = v->string_val(); |
| 544 } | 544 } |
| 545 | 545 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 557 } | 557 } |
| 558 | 558 |
| 559 bool StatsCollector::IsValidTrack(const std::string& track_id) { | 559 bool StatsCollector::IsValidTrack(const std::string& track_id) { |
| 560 return reports_.Find(StatsReport::NewTypedId( | 560 return reports_.Find(StatsReport::NewTypedId( |
| 561 StatsReport::kStatsReportTypeTrack, track_id)) != nullptr; | 561 StatsReport::kStatsReportTypeTrack, track_id)) != nullptr; |
| 562 } | 562 } |
| 563 | 563 |
| 564 StatsReport* StatsCollector::AddCertificateReports( | 564 StatsReport* StatsCollector::AddCertificateReports( |
| 565 const rtc::SSLCertificate* cert) { | 565 const rtc::SSLCertificate* cert) { |
| 566 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); | 566 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
| 567 RTC_DCHECK(cert != NULL); | 567 RTC_DCHECK(cert != nullptr); |
| 568 | 568 |
| 569 std::unique_ptr<rtc::SSLCertificateStats> first_stats = cert->GetStats(); | 569 std::unique_ptr<rtc::SSLCertificateStats> first_stats = cert->GetStats(); |
| 570 StatsReport* first_report = nullptr; | 570 StatsReport* first_report = nullptr; |
| 571 StatsReport* prev_report = nullptr; | 571 StatsReport* prev_report = nullptr; |
| 572 for (rtc::SSLCertificateStats* stats = first_stats.get(); stats; | 572 for (rtc::SSLCertificateStats* stats = first_stats.get(); stats; |
| 573 stats = stats->issuer.get()) { | 573 stats = stats->issuer.get()) { |
| 574 StatsReport::Id id(StatsReport::NewTypedId( | 574 StatsReport::Id id(StatsReport::NewTypedId( |
| 575 StatsReport::kStatsReportTypeCertificate, stats->fingerprint)); | 575 StatsReport::kStatsReportTypeCertificate, stats->fingerprint)); |
| 576 | 576 |
| 577 StatsReport* report = reports_.ReplaceOrAddNew(id); | 577 StatsReport* report = reports_.ReplaceOrAddNew(id); |
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 902 | 902 |
| 903 void StatsCollector::UpdateStatsFromExistingLocalAudioTracks() { | 903 void StatsCollector::UpdateStatsFromExistingLocalAudioTracks() { |
| 904 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); | 904 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
| 905 // Loop through the existing local audio tracks. | 905 // Loop through the existing local audio tracks. |
| 906 for (const auto& it : local_audio_tracks_) { | 906 for (const auto& it : local_audio_tracks_) { |
| 907 AudioTrackInterface* track = it.first; | 907 AudioTrackInterface* track = it.first; |
| 908 uint32_t ssrc = it.second; | 908 uint32_t ssrc = it.second; |
| 909 StatsReport* report = | 909 StatsReport* report = |
| 910 GetReport(StatsReport::kStatsReportTypeSsrc, | 910 GetReport(StatsReport::kStatsReportTypeSsrc, |
| 911 rtc::ToString<uint32_t>(ssrc), StatsReport::kSend); | 911 rtc::ToString<uint32_t>(ssrc), StatsReport::kSend); |
| 912 if (report == NULL) { | 912 if (report == nullptr) { |
| 913 // This can happen if a local audio track is added to a stream on the | 913 // This can happen if a local audio track is added to a stream on the |
| 914 // fly and the report has not been set up yet. Do nothing in this case. | 914 // fly and the report has not been set up yet. Do nothing in this case. |
| 915 LOG(LS_ERROR) << "Stats report does not exist for ssrc " << ssrc; | 915 LOG(LS_ERROR) << "Stats report does not exist for ssrc " << ssrc; |
| 916 continue; | 916 continue; |
| 917 } | 917 } |
| 918 | 918 |
| 919 // The same ssrc can be used by both local and remote audio tracks. | 919 // The same ssrc can be used by both local and remote audio tracks. |
| 920 const StatsReport::Value* v = | 920 const StatsReport::Value* v = |
| 921 report->FindValue(StatsReport::kStatsValueNameTrackId); | 921 report->FindValue(StatsReport::kStatsValueNameTrackId); |
| 922 if (!v || v->string_val() != track->id()) | 922 if (!v || v->string_val() != track->id()) |
| 923 continue; | 923 continue; |
| 924 | 924 |
| 925 report->set_timestamp(stats_gathering_started_); | 925 report->set_timestamp(stats_gathering_started_); |
| 926 UpdateReportFromAudioTrack(track, report); | 926 UpdateReportFromAudioTrack(track, report); |
| 927 } | 927 } |
| 928 } | 928 } |
| 929 | 929 |
| 930 void StatsCollector::UpdateReportFromAudioTrack(AudioTrackInterface* track, | 930 void StatsCollector::UpdateReportFromAudioTrack(AudioTrackInterface* track, |
| 931 StatsReport* report) { | 931 StatsReport* report) { |
| 932 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); | 932 RTC_DCHECK(pc_->session()->signaling_thread()->IsCurrent()); |
| 933 RTC_DCHECK(track != NULL); | 933 RTC_DCHECK(track != nullptr); |
| 934 | 934 |
| 935 // Don't overwrite report values if they're not available. | 935 // Don't overwrite report values if they're not available. |
| 936 int signal_level; | 936 int signal_level; |
| 937 if (track->GetSignalLevel(&signal_level)) { | 937 if (track->GetSignalLevel(&signal_level)) { |
| 938 RTC_DCHECK_GE(signal_level, 0); | 938 RTC_DCHECK_GE(signal_level, 0); |
| 939 report->AddInt(StatsReport::kStatsValueNameAudioInputLevel, signal_level); | 939 report->AddInt(StatsReport::kStatsValueNameAudioInputLevel, signal_level); |
| 940 } | 940 } |
| 941 | 941 |
| 942 auto audio_processor(track->GetAudioProcessor()); | 942 auto audio_processor(track->GetAudioProcessor()); |
| 943 | 943 |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 988 StatsReport* report = entry.second; | 988 StatsReport* report = entry.second; |
| 989 report->set_timestamp(stats_gathering_started_); | 989 report->set_timestamp(stats_gathering_started_); |
| 990 } | 990 } |
| 991 } | 991 } |
| 992 | 992 |
| 993 void StatsCollector::ClearUpdateStatsCacheForTest() { | 993 void StatsCollector::ClearUpdateStatsCacheForTest() { |
| 994 stats_gathering_started_ = 0; | 994 stats_gathering_started_ = 0; |
| 995 } | 995 } |
| 996 | 996 |
| 997 } // namespace webrtc | 997 } // namespace webrtc |
| OLD | NEW |