Chromium Code Reviews

Side by Side Diff: content/renderer/media/rtc_peer_connection_handler.cc

Issue 2317063002: WebRTCPeerConnectionHandler::getStats for the new stats collector API (Closed)
Patch Set: TODO to impl MockWebRTCPeerConnectionHandler::getStats in a follow-up instead Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff |
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/renderer/media/rtc_peer_connection_handler.h" 5 #include "content/renderer/media/rtc_peer_connection_handler.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
(...skipping 12 matching lines...)
23 #include "content/public/common/content_features.h" 23 #include "content/public/common/content_features.h"
24 #include "content/public/common/content_switches.h" 24 #include "content/public/common/content_switches.h"
25 #include "content/renderer/media/media_stream_constraints_util.h" 25 #include "content/renderer/media/media_stream_constraints_util.h"
26 #include "content/renderer/media/media_stream_track.h" 26 #include "content/renderer/media/media_stream_track.h"
27 #include "content/renderer/media/peer_connection_tracker.h" 27 #include "content/renderer/media/peer_connection_tracker.h"
28 #include "content/renderer/media/remote_media_stream_impl.h" 28 #include "content/renderer/media/remote_media_stream_impl.h"
29 #include "content/renderer/media/rtc_certificate.h" 29 #include "content/renderer/media/rtc_certificate.h"
30 #include "content/renderer/media/rtc_data_channel_handler.h" 30 #include "content/renderer/media/rtc_data_channel_handler.h"
31 #include "content/renderer/media/rtc_dtmf_sender_handler.h" 31 #include "content/renderer/media/rtc_dtmf_sender_handler.h"
32 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" 32 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h"
33 #include "content/renderer/media/webrtc/rtc_stats.h"
33 #include "content/renderer/media/webrtc/webrtc_media_stream_adapter.h" 34 #include "content/renderer/media/webrtc/webrtc_media_stream_adapter.h"
34 #include "content/renderer/media/webrtc_audio_device_impl.h" 35 #include "content/renderer/media/webrtc_audio_device_impl.h"
35 #include "content/renderer/media/webrtc_uma_histograms.h" 36 #include "content/renderer/media/webrtc_uma_histograms.h"
36 #include "content/renderer/render_thread_impl.h" 37 #include "content/renderer/render_thread_impl.h"
37 #include "media/base/media_switches.h" 38 #include "media/base/media_switches.h"
38 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" 39 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
39 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h" 40 #include "third_party/WebKit/public/platform/WebRTCAnswerOptions.h"
40 #include "third_party/WebKit/public/platform/WebRTCConfiguration.h" 41 #include "third_party/WebKit/public/platform/WebRTCConfiguration.h"
41 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" 42 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h"
42 #include "third_party/WebKit/public/platform/WebRTCICECandidate.h" 43 #include "third_party/WebKit/public/platform/WebRTCICECandidate.h"
(...skipping 623 matching lines...)
666 return; 667 return;
667 } 668 }
668 } 669 }
669 670
670 if (!pc->GetStats(observer.get(), track.get(), level)) { 671 if (!pc->GetStats(observer.get(), track.get(), level)) {
671 DVLOG(1) << "GetStats failed."; 672 DVLOG(1) << "GetStats failed.";
672 observer->OnComplete(StatsReports()); 673 observer->OnComplete(StatsReports());
673 } 674 }
674 } 675 }
675 676
677 // A stats collector callback that is invoked on the WebRTC signaling thread and
hta - Chromium 2016/09/20 16:26:45 Style: This sentence is quite hard to read. Sugge
hbos_chromium 2016/09/20 20:18:39 Done.
678 // posted to the |main_thread_| to deliver the resulting report to Blink as an
679 // |RTCStatsReport| (which is a type of |blink::WebRTCStatsReport|).
680 class GetRTCStatsCallback : public webrtc::RTCStatsCollectorCallback {
681 public:
682 static rtc::scoped_refptr<GetRTCStatsCallback> Create(
683 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread,
684 std::unique_ptr<blink::WebRTCStatsReportCallback> callback) {
685 return rtc::scoped_refptr<GetRTCStatsCallback>(
686 new rtc::RefCountedObject<GetRTCStatsCallback>(
687 main_thread, callback.release()));
688 }
689
690 void OnStatsDelivered(
691 const rtc::scoped_refptr<const webrtc::RTCStatsReport>& report) override {
692 main_thread_->PostTask(FROM_HERE,
693 base::Bind(&GetRTCStatsCallback::OnStatsDeliveredOnMainThread,
694 this, report));
695 }
696
697 void OnStatsDeliveredOnMainThread(
698 const rtc::scoped_refptr<const webrtc::RTCStatsReport>& report) {
699 DCHECK(main_thread_->BelongsToCurrentThread());
700 DCHECK(report);
701 callback_->OnStatsDelivered(std::unique_ptr<blink::WebRTCStatsReport>(
702 new RTCStatsReport(make_scoped_refptr(report.get()))));
703 }
704
705 protected:
706 GetRTCStatsCallback(
707 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread,
708 blink::WebRTCStatsReportCallback* callback)
709 : main_thread_(main_thread),
710 callback_(callback) {
711 }
712
713 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_;
714 std::unique_ptr<blink::WebRTCStatsReportCallback> callback_;
715 };
716
717 void GetRTCStatsOnSignalingThread(
718 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread,
719 scoped_refptr<webrtc::PeerConnectionInterface> native_peer_connection,
720 std::unique_ptr<blink::WebRTCStatsReportCallback> callback) {
721 TRACE_EVENT0("webrtc", "GetRTCStatsOnSignalingThread");
722
723 native_peer_connection->GetStats(
724 GetRTCStatsCallback::Create(main_thread, std::move(callback)));
725 }
726
676 class PeerConnectionUMAObserver : public webrtc::UMAObserver { 727 class PeerConnectionUMAObserver : public webrtc::UMAObserver {
677 public: 728 public:
678 PeerConnectionUMAObserver() {} 729 PeerConnectionUMAObserver() {}
679 ~PeerConnectionUMAObserver() override {} 730 ~PeerConnectionUMAObserver() override {}
680 void IncrementEnumCounter(webrtc::PeerConnectionEnumCounterType counter_type, 731 void IncrementEnumCounter(webrtc::PeerConnectionEnumCounterType counter_type,
681 int counter, 732 int counter,
682 int counter_max) override { 733 int counter_max) override {
683 switch (counter_type) { 734 switch (counter_type) {
684 case webrtc::kEnumCounterAddressFamily: 735 case webrtc::kEnumCounterAddressFamily:
685 UMA_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.IPMetrics", counter, 736 UMA_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.IPMetrics", counter,
(...skipping 810 matching lines...)
1496 blink::WebMediaStreamSource::TypeAudio; 1547 blink::WebMediaStreamSource::TypeAudio;
1497 if (request->hasSelector()) { 1548 if (request->hasSelector()) {
1498 track_type = request->component().source().getType(); 1549 track_type = request->component().source().getType();
1499 track_id = request->component().id().utf8(); 1550 track_id = request->component().id().utf8();
1500 } 1551 }
1501 1552
1502 GetStats(observer, webrtc::PeerConnectionInterface::kStatsOutputLevelStandard, 1553 GetStats(observer, webrtc::PeerConnectionInterface::kStatsOutputLevelStandard,
1503 track_id, track_type); 1554 track_id, track_type);
1504 } 1555 }
1505 1556
1506 // TODO(tommi): It's weird to have three {g|G}etStats methods. Clean this up. 1557 // TODO(tommi,hbos): It's weird to have three {g|G}etStats methods for the
1558 // legacy stats collector API and even more for the new stats API. Clean it up.
1559 // TODO(hbos): Rename old |getStats| and related functions to "getLegacyStats",
1560 // rename new |getStats|'s helper functions from "GetRTCStats*" to "GetStats*".
1507 void RTCPeerConnectionHandler::GetStats( 1561 void RTCPeerConnectionHandler::GetStats(
1508 webrtc::StatsObserver* observer, 1562 webrtc::StatsObserver* observer,
1509 webrtc::PeerConnectionInterface::StatsOutputLevel level, 1563 webrtc::PeerConnectionInterface::StatsOutputLevel level,
1510 const std::string& track_id, 1564 const std::string& track_id,
1511 blink::WebMediaStreamSource::Type track_type) { 1565 blink::WebMediaStreamSource::Type track_type) {
1512 DCHECK(thread_checker_.CalledOnValidThread()); 1566 DCHECK(thread_checker_.CalledOnValidThread());
1513 signaling_thread()->PostTask(FROM_HERE, 1567 signaling_thread()->PostTask(FROM_HERE,
1514 base::Bind(&GetStatsOnSignalingThread, native_peer_connection_, level, 1568 base::Bind(&GetStatsOnSignalingThread, native_peer_connection_, level,
1515 make_scoped_refptr(observer), track_id, track_type)); 1569 make_scoped_refptr(observer), track_id, track_type));
1516 } 1570 }
1517 1571
1572 void RTCPeerConnectionHandler::getStats(
1573 std::unique_ptr<blink::WebRTCStatsReportCallback> callback) {
1574 DCHECK(thread_checker_.CalledOnValidThread());
1575 signaling_thread()->PostTask(FROM_HERE,
1576 base::Bind(&GetRTCStatsOnSignalingThread,
1577 base::ThreadTaskRunnerHandle::Get(), native_peer_connection_,
1578 base::Passed(&callback)));
1579 }
1580
1518 void RTCPeerConnectionHandler::CloseClientPeerConnection() { 1581 void RTCPeerConnectionHandler::CloseClientPeerConnection() {
1519 DCHECK(thread_checker_.CalledOnValidThread()); 1582 DCHECK(thread_checker_.CalledOnValidThread());
1520 if (!is_closed_) 1583 if (!is_closed_)
1521 client_->closePeerConnection(); 1584 client_->closePeerConnection();
1522 } 1585 }
1523 1586
1524 void RTCPeerConnectionHandler::StartEventLog(IPC::PlatformFileForTransit file, 1587 void RTCPeerConnectionHandler::StartEventLog(IPC::PlatformFileForTransit file,
1525 int64_t max_file_size_bytes) { 1588 int64_t max_file_size_bytes) {
1526 DCHECK(thread_checker_.CalledOnValidThread()); 1589 DCHECK(thread_checker_.CalledOnValidThread());
1527 DCHECK(file != IPC::InvalidPlatformFileForTransit()); 1590 DCHECK(file != IPC::InvalidPlatformFileForTransit());
(...skipping 361 matching lines...)
1889 } 1952 }
1890 1953
1891 void RTCPeerConnectionHandler::ResetUMAStats() { 1954 void RTCPeerConnectionHandler::ResetUMAStats() {
1892 DCHECK(thread_checker_.CalledOnValidThread()); 1955 DCHECK(thread_checker_.CalledOnValidThread());
1893 num_local_candidates_ipv6_ = 0; 1956 num_local_candidates_ipv6_ = 0;
1894 num_local_candidates_ipv4_ = 0; 1957 num_local_candidates_ipv4_ = 0;
1895 ice_connection_checking_start_ = base::TimeTicks(); 1958 ice_connection_checking_start_ = base::TimeTicks();
1896 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); 1959 memset(ice_state_seen_, 0, sizeof(ice_state_seen_));
1897 } 1960 }
1898 } // namespace content 1961 } // namespace content
OLDNEW

Powered by Google App Engine