Chromium Code Reviews| OLD | NEW |
|---|---|
| 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...) Expand all Loading... | |
| 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...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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. | |
| 678 // It is invoked on the WebRTC signaling thread and will post a task to invoke | |
| 679 // |callback| on the thread given in the |main_thread| argument. | |
| 680 // The argument to the callback will be a |blink::WebRTCStatsReport|. | |
| 681 class GetRTCStatsCallback : public webrtc::RTCStatsCollectorCallback { | |
| 682 public: | |
| 683 static rtc::scoped_refptr<GetRTCStatsCallback> Create( | |
| 684 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread, | |
| 685 std::unique_ptr<blink::WebRTCStatsReportCallback> callback) { | |
| 686 return rtc::scoped_refptr<GetRTCStatsCallback>( | |
| 687 new rtc::RefCountedObject<GetRTCStatsCallback>( | |
| 688 main_thread, callback.release())); | |
|
perkj_chrome
2016/09/21 12:21:33
std::move - avoid using raw pointer.
hbos_chromium
2016/09/21 19:05:21
RefCountedObject's template constructors does not
perkj_chrome
2016/09/22 05:37:50
I see, that should be fixed.
| |
| 689 } | |
| 690 | |
| 691 void OnStatsDelivered( | |
| 692 const rtc::scoped_refptr<const webrtc::RTCStatsReport>& report) override { | |
| 693 main_thread_->PostTask(FROM_HERE, | |
| 694 base::Bind(&GetRTCStatsCallback::OnStatsDeliveredOnMainThread, | |
| 695 this, report)); | |
| 696 } | |
| 697 | |
| 698 void OnStatsDeliveredOnMainThread( | |
| 699 const rtc::scoped_refptr<const webrtc::RTCStatsReport>& report) { | |
| 700 DCHECK(main_thread_->BelongsToCurrentThread()); | |
| 701 DCHECK(report); | |
| 702 callback_->OnStatsDelivered(std::unique_ptr<blink::WebRTCStatsReport>( | |
| 703 new RTCStatsReport(make_scoped_refptr(report.get())))); | |
| 704 } | |
| 705 | |
| 706 protected: | |
| 707 GetRTCStatsCallback( | |
| 708 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread, | |
| 709 blink::WebRTCStatsReportCallback* callback) | |
|
perkj_chrome
2016/09/21 12:21:33
std::unique_ptr<blink::WebRTCStatsReportCallback>
hbos_chromium
2016/09/21 19:05:21
See above.
| |
| 710 : main_thread_(main_thread), | |
| 711 callback_(callback) { | |
| 712 } | |
| 713 | |
| 714 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_; | |
| 715 std::unique_ptr<blink::WebRTCStatsReportCallback> callback_; | |
| 716 }; | |
| 717 | |
| 718 void GetRTCStatsOnSignalingThread( | |
| 719 const scoped_refptr<base::SingleThreadTaskRunner>& main_thread, | |
| 720 scoped_refptr<webrtc::PeerConnectionInterface> native_peer_connection, | |
| 721 std::unique_ptr<blink::WebRTCStatsReportCallback> callback) { | |
| 722 TRACE_EVENT0("webrtc", "GetRTCStatsOnSignalingThread"); | |
| 723 | |
| 724 native_peer_connection->GetStats( | |
| 725 GetRTCStatsCallback::Create(main_thread, std::move(callback))); | |
| 726 } | |
| 727 | |
| 676 class PeerConnectionUMAObserver : public webrtc::UMAObserver { | 728 class PeerConnectionUMAObserver : public webrtc::UMAObserver { |
| 677 public: | 729 public: |
| 678 PeerConnectionUMAObserver() {} | 730 PeerConnectionUMAObserver() {} |
| 679 ~PeerConnectionUMAObserver() override {} | 731 ~PeerConnectionUMAObserver() override {} |
| 680 void IncrementEnumCounter(webrtc::PeerConnectionEnumCounterType counter_type, | 732 void IncrementEnumCounter(webrtc::PeerConnectionEnumCounterType counter_type, |
| 681 int counter, | 733 int counter, |
| 682 int counter_max) override { | 734 int counter_max) override { |
| 683 switch (counter_type) { | 735 switch (counter_type) { |
| 684 case webrtc::kEnumCounterAddressFamily: | 736 case webrtc::kEnumCounterAddressFamily: |
| 685 UMA_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.IPMetrics", counter, | 737 UMA_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.IPMetrics", counter, |
| (...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1496 blink::WebMediaStreamSource::TypeAudio; | 1548 blink::WebMediaStreamSource::TypeAudio; |
| 1497 if (request->hasSelector()) { | 1549 if (request->hasSelector()) { |
| 1498 track_type = request->component().source().getType(); | 1550 track_type = request->component().source().getType(); |
| 1499 track_id = request->component().id().utf8(); | 1551 track_id = request->component().id().utf8(); |
| 1500 } | 1552 } |
| 1501 | 1553 |
| 1502 GetStats(observer, webrtc::PeerConnectionInterface::kStatsOutputLevelStandard, | 1554 GetStats(observer, webrtc::PeerConnectionInterface::kStatsOutputLevelStandard, |
| 1503 track_id, track_type); | 1555 track_id, track_type); |
| 1504 } | 1556 } |
| 1505 | 1557 |
| 1506 // TODO(tommi): It's weird to have three {g|G}etStats methods. Clean this up. | 1558 // TODO(tommi,hbos): It's weird to have three {g|G}etStats methods for the |
| 1559 // legacy stats collector API and even more for the new stats API. Clean it up. | |
| 1560 // TODO(hbos): Rename old |getStats| and related functions to "getLegacyStats", | |
| 1561 // rename new |getStats|'s helper functions from "GetRTCStats*" to "GetStats*". | |
| 1507 void RTCPeerConnectionHandler::GetStats( | 1562 void RTCPeerConnectionHandler::GetStats( |
| 1508 webrtc::StatsObserver* observer, | 1563 webrtc::StatsObserver* observer, |
| 1509 webrtc::PeerConnectionInterface::StatsOutputLevel level, | 1564 webrtc::PeerConnectionInterface::StatsOutputLevel level, |
| 1510 const std::string& track_id, | 1565 const std::string& track_id, |
| 1511 blink::WebMediaStreamSource::Type track_type) { | 1566 blink::WebMediaStreamSource::Type track_type) { |
| 1512 DCHECK(thread_checker_.CalledOnValidThread()); | 1567 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1513 signaling_thread()->PostTask(FROM_HERE, | 1568 signaling_thread()->PostTask(FROM_HERE, |
| 1514 base::Bind(&GetStatsOnSignalingThread, native_peer_connection_, level, | 1569 base::Bind(&GetStatsOnSignalingThread, native_peer_connection_, level, |
| 1515 make_scoped_refptr(observer), track_id, track_type)); | 1570 make_scoped_refptr(observer), track_id, track_type)); |
| 1516 } | 1571 } |
| 1517 | 1572 |
| 1573 void RTCPeerConnectionHandler::getStats( | |
| 1574 std::unique_ptr<blink::WebRTCStatsReportCallback> callback) { | |
| 1575 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1576 signaling_thread()->PostTask(FROM_HERE, | |
| 1577 base::Bind(&GetRTCStatsOnSignalingThread, | |
| 1578 base::ThreadTaskRunnerHandle::Get(), native_peer_connection_, | |
| 1579 base::Passed(&callback))); | |
| 1580 } | |
| 1581 | |
| 1518 void RTCPeerConnectionHandler::CloseClientPeerConnection() { | 1582 void RTCPeerConnectionHandler::CloseClientPeerConnection() { |
| 1519 DCHECK(thread_checker_.CalledOnValidThread()); | 1583 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1520 if (!is_closed_) | 1584 if (!is_closed_) |
| 1521 client_->closePeerConnection(); | 1585 client_->closePeerConnection(); |
| 1522 } | 1586 } |
| 1523 | 1587 |
| 1524 void RTCPeerConnectionHandler::StartEventLog(IPC::PlatformFileForTransit file, | 1588 void RTCPeerConnectionHandler::StartEventLog(IPC::PlatformFileForTransit file, |
| 1525 int64_t max_file_size_bytes) { | 1589 int64_t max_file_size_bytes) { |
| 1526 DCHECK(thread_checker_.CalledOnValidThread()); | 1590 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1527 DCHECK(file != IPC::InvalidPlatformFileForTransit()); | 1591 DCHECK(file != IPC::InvalidPlatformFileForTransit()); |
| (...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1889 } | 1953 } |
| 1890 | 1954 |
| 1891 void RTCPeerConnectionHandler::ResetUMAStats() { | 1955 void RTCPeerConnectionHandler::ResetUMAStats() { |
| 1892 DCHECK(thread_checker_.CalledOnValidThread()); | 1956 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1893 num_local_candidates_ipv6_ = 0; | 1957 num_local_candidates_ipv6_ = 0; |
| 1894 num_local_candidates_ipv4_ = 0; | 1958 num_local_candidates_ipv4_ = 0; |
| 1895 ice_connection_checking_start_ = base::TimeTicks(); | 1959 ice_connection_checking_start_ = base::TimeTicks(); |
| 1896 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); | 1960 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); |
| 1897 } | 1961 } |
| 1898 } // namespace content | 1962 } // namespace content |
| OLD | NEW |