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 11 matching lines...) Expand all Loading... |
22 #include "content/public/common/content_features.h" | 22 #include "content/public/common/content_features.h" |
23 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
24 #include "content/renderer/media/media_stream_constraints_util.h" | 24 #include "content/renderer/media/media_stream_constraints_util.h" |
25 #include "content/renderer/media/media_stream_track.h" | 25 #include "content/renderer/media/media_stream_track.h" |
26 #include "content/renderer/media/peer_connection_tracker.h" | 26 #include "content/renderer/media/peer_connection_tracker.h" |
27 #include "content/renderer/media/remote_media_stream_impl.h" | 27 #include "content/renderer/media/remote_media_stream_impl.h" |
28 #include "content/renderer/media/rtc_certificate.h" | 28 #include "content/renderer/media/rtc_certificate.h" |
29 #include "content/renderer/media/rtc_data_channel_handler.h" | 29 #include "content/renderer/media/rtc_data_channel_handler.h" |
30 #include "content/renderer/media/rtc_dtmf_sender_handler.h" | 30 #include "content/renderer/media/rtc_dtmf_sender_handler.h" |
31 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" | 31 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" |
| 32 #include "content/renderer/media/webrtc/rtc_rtp_receiver.h" |
32 #include "content/renderer/media/webrtc/rtc_stats.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" |
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 &blink::WebMediaTrackConstraintSet::iceRestart, | 918 &blink::WebMediaTrackConstraintSet::iceRestart, |
918 &output->ice_restart); | 919 &output->ice_restart); |
919 } | 920 } |
920 | 921 |
921 std::set<RTCPeerConnectionHandler*>* GetPeerConnectionHandlers() { | 922 std::set<RTCPeerConnectionHandler*>* GetPeerConnectionHandlers() { |
922 static std::set<RTCPeerConnectionHandler*>* handlers = | 923 static std::set<RTCPeerConnectionHandler*>* handlers = |
923 new std::set<RTCPeerConnectionHandler*>(); | 924 new std::set<RTCPeerConnectionHandler*>(); |
924 return handlers; | 925 return handlers; |
925 } | 926 } |
926 | 927 |
| 928 blink::WebMediaStreamTrack GetRemoteTrack( |
| 929 const std::map<webrtc::MediaStreamInterface*, |
| 930 std::unique_ptr<content::RemoteMediaStreamImpl>>& |
| 931 remote_streams, |
| 932 const blink::WebString& id, |
| 933 blink::WebMediaStreamTrack (blink::WebMediaStream::*get_track_method)( |
| 934 const blink::WebString& trackId) const) { |
| 935 // TODO(hbos): Tracks and streams are currently added/removed on a per-stream |
| 936 // basis, but tracks could be removed from a stream or added to an existing |
| 937 // stream. We need to listen to events of tracks being added and removed, and |
| 938 // have a list of tracks that is separate from the list of streams. |
| 939 // https://crbug.com/705901 |
| 940 for (const auto& remote_stream_pair : remote_streams) { |
| 941 blink::WebMediaStreamTrack web_track = |
| 942 (remote_stream_pair.second->webkit_stream().*get_track_method)(id); |
| 943 if (!web_track.isNull()) |
| 944 return web_track; |
| 945 } |
| 946 return blink::WebMediaStreamTrack(); |
| 947 } |
| 948 |
927 } // namespace | 949 } // namespace |
928 | 950 |
929 // Implementation of LocalRTCStatsRequest. | 951 // Implementation of LocalRTCStatsRequest. |
930 LocalRTCStatsRequest::LocalRTCStatsRequest(blink::WebRTCStatsRequest impl) | 952 LocalRTCStatsRequest::LocalRTCStatsRequest(blink::WebRTCStatsRequest impl) |
931 : impl_(impl) { | 953 : impl_(impl) { |
932 } | 954 } |
933 | 955 |
934 LocalRTCStatsRequest::LocalRTCStatsRequest() {} | 956 LocalRTCStatsRequest::LocalRTCStatsRequest() {} |
935 LocalRTCStatsRequest::~LocalRTCStatsRequest() {} | 957 LocalRTCStatsRequest::~LocalRTCStatsRequest() {} |
936 | 958 |
(...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1631 | 1653 |
1632 void RTCPeerConnectionHandler::getStats( | 1654 void RTCPeerConnectionHandler::getStats( |
1633 std::unique_ptr<blink::WebRTCStatsReportCallback> callback) { | 1655 std::unique_ptr<blink::WebRTCStatsReportCallback> callback) { |
1634 DCHECK(thread_checker_.CalledOnValidThread()); | 1656 DCHECK(thread_checker_.CalledOnValidThread()); |
1635 signaling_thread()->PostTask(FROM_HERE, | 1657 signaling_thread()->PostTask(FROM_HERE, |
1636 base::Bind(&GetRTCStatsOnSignalingThread, | 1658 base::Bind(&GetRTCStatsOnSignalingThread, |
1637 base::ThreadTaskRunnerHandle::Get(), native_peer_connection_, | 1659 base::ThreadTaskRunnerHandle::Get(), native_peer_connection_, |
1638 base::Passed(&callback))); | 1660 base::Passed(&callback))); |
1639 } | 1661 } |
1640 | 1662 |
| 1663 blink::WebVector<std::unique_ptr<blink::WebRTCRtpReceiver>> |
| 1664 RTCPeerConnectionHandler::getReceivers() { |
| 1665 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1666 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::getReceivers"); |
| 1667 |
| 1668 std::vector<rtc::scoped_refptr<webrtc::RtpReceiverInterface>> |
| 1669 webrtc_receivers = native_peer_connection_->GetReceivers(); |
| 1670 std::vector<std::unique_ptr<blink::WebRTCRtpReceiver>> web_receivers; |
| 1671 for (size_t i = 0; i < webrtc_receivers.size(); ++i) { |
| 1672 rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> webrtc_track = |
| 1673 webrtc_receivers[i]->track(); |
| 1674 DCHECK(webrtc_track); |
| 1675 // Create a reference to the receiver. Multiple |RTCRtpReceiver|s can |
| 1676 // reference the same webrtc track, see |id|. |
| 1677 blink::WebMediaStreamTrack web_track; |
| 1678 if (webrtc_track->kind() == webrtc::MediaStreamTrackInterface::kAudioKind) { |
| 1679 web_track = GetRemoteAudioTrack(webrtc_track->id()); |
| 1680 } else { |
| 1681 web_track = GetRemoteVideoTrack(webrtc_track->id()); |
| 1682 } |
| 1683 // TODO(hbos): Any existing remote track should be known but the case of a |
| 1684 // track being added or removed separately from streams is not handled |
| 1685 // properly, see todo in |GetRemoteTrack|. When that is addressed, DCHECK |
| 1686 // that the track is not null. https://crbug.com/705901 |
| 1687 if (!web_track.isNull()) { |
| 1688 web_receivers.push_back(base::MakeUnique<RTCRtpReceiver>( |
| 1689 webrtc_receivers[i].get(), web_track)); |
| 1690 } |
| 1691 } |
| 1692 |
| 1693 // |blink::WebVector|'s size must be known at construction, that is why |
| 1694 // |web_vectors| uses |std::vector| and needs to be moved before returning. |
| 1695 blink::WebVector<std::unique_ptr<blink::WebRTCRtpReceiver>> result( |
| 1696 web_receivers.size()); |
| 1697 for (size_t i = 0; i < web_receivers.size(); ++i) { |
| 1698 result[i] = std::move(web_receivers[i]); |
| 1699 } |
| 1700 return result; |
| 1701 } |
| 1702 |
1641 void RTCPeerConnectionHandler::CloseClientPeerConnection() { | 1703 void RTCPeerConnectionHandler::CloseClientPeerConnection() { |
1642 DCHECK(thread_checker_.CalledOnValidThread()); | 1704 DCHECK(thread_checker_.CalledOnValidThread()); |
1643 if (!is_closed_) | 1705 if (!is_closed_) |
1644 client_->closePeerConnection(); | 1706 client_->closePeerConnection(); |
1645 } | 1707 } |
1646 | 1708 |
1647 void RTCPeerConnectionHandler::StartEventLog(IPC::PlatformFileForTransit file, | 1709 void RTCPeerConnectionHandler::StartEventLog(IPC::PlatformFileForTransit file, |
1648 int64_t max_file_size_bytes) { | 1710 int64_t max_file_size_bytes) { |
1649 DCHECK(thread_checker_.CalledOnValidThread()); | 1711 DCHECK(thread_checker_.CalledOnValidThread()); |
1650 DCHECK(file != IPC::InvalidPlatformFileForTransit()); | 1712 DCHECK(file != IPC::InvalidPlatformFileForTransit()); |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1991 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 2053 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
1992 base::WaitableEvent::InitialState::NOT_SIGNALED); | 2054 base::WaitableEvent::InitialState::NOT_SIGNALED); |
1993 thread->PostTask(FROM_HERE, | 2055 thread->PostTask(FROM_HERE, |
1994 base::Bind(&RunSynchronousClosure, closure, | 2056 base::Bind(&RunSynchronousClosure, closure, |
1995 base::Unretained(trace_event_name), | 2057 base::Unretained(trace_event_name), |
1996 base::Unretained(&event))); | 2058 base::Unretained(&event))); |
1997 event.Wait(); | 2059 event.Wait(); |
1998 } | 2060 } |
1999 } | 2061 } |
2000 | 2062 |
| 2063 blink::WebMediaStreamTrack RTCPeerConnectionHandler::GetRemoteAudioTrack( |
| 2064 const std::string& track_id) const { |
| 2065 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2066 return GetRemoteTrack(remote_streams_, blink::WebString::fromUTF8(track_id), |
| 2067 &blink::WebMediaStream::getAudioTrack); |
| 2068 } |
| 2069 |
| 2070 blink::WebMediaStreamTrack RTCPeerConnectionHandler::GetRemoteVideoTrack( |
| 2071 const std::string& track_id) const { |
| 2072 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2073 return GetRemoteTrack(remote_streams_, blink::WebString::fromUTF8(track_id), |
| 2074 &blink::WebMediaStream::getVideoTrack); |
| 2075 } |
| 2076 |
2001 void RTCPeerConnectionHandler::ReportICEState( | 2077 void RTCPeerConnectionHandler::ReportICEState( |
2002 webrtc::PeerConnectionInterface::IceConnectionState new_state) { | 2078 webrtc::PeerConnectionInterface::IceConnectionState new_state) { |
2003 DCHECK(thread_checker_.CalledOnValidThread()); | 2079 DCHECK(thread_checker_.CalledOnValidThread()); |
2004 if (ice_state_seen_[new_state]) | 2080 if (ice_state_seen_[new_state]) |
2005 return; | 2081 return; |
2006 ice_state_seen_[new_state] = true; | 2082 ice_state_seen_[new_state] = true; |
2007 UMA_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.ConnectionState", new_state, | 2083 UMA_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.ConnectionState", new_state, |
2008 webrtc::PeerConnectionInterface::kIceConnectionMax); | 2084 webrtc::PeerConnectionInterface::kIceConnectionMax); |
2009 } | 2085 } |
2010 | 2086 |
2011 void RTCPeerConnectionHandler::ResetUMAStats() { | 2087 void RTCPeerConnectionHandler::ResetUMAStats() { |
2012 DCHECK(thread_checker_.CalledOnValidThread()); | 2088 DCHECK(thread_checker_.CalledOnValidThread()); |
2013 num_local_candidates_ipv6_ = 0; | 2089 num_local_candidates_ipv6_ = 0; |
2014 num_local_candidates_ipv4_ = 0; | 2090 num_local_candidates_ipv4_ = 0; |
2015 ice_connection_checking_start_ = base::TimeTicks(); | 2091 ice_connection_checking_start_ = base::TimeTicks(); |
2016 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); | 2092 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); |
2017 } | 2093 } |
2018 } // namespace content | 2094 } // namespace content |
OLD | NEW |