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 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 1585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1627 | 1628 |
| 1628 void RTCPeerConnectionHandler::getStats( | 1629 void RTCPeerConnectionHandler::getStats( |
| 1629 std::unique_ptr<blink::WebRTCStatsReportCallback> callback) { | 1630 std::unique_ptr<blink::WebRTCStatsReportCallback> callback) { |
| 1630 DCHECK(thread_checker_.CalledOnValidThread()); | 1631 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1631 signaling_thread()->PostTask(FROM_HERE, | 1632 signaling_thread()->PostTask(FROM_HERE, |
| 1632 base::Bind(&GetRTCStatsOnSignalingThread, | 1633 base::Bind(&GetRTCStatsOnSignalingThread, |
| 1633 base::ThreadTaskRunnerHandle::Get(), native_peer_connection_, | 1634 base::ThreadTaskRunnerHandle::Get(), native_peer_connection_, |
| 1634 base::Passed(&callback))); | 1635 base::Passed(&callback))); |
| 1635 } | 1636 } |
| 1636 | 1637 |
| 1638 blink::WebVector<std::unique_ptr<blink::WebRTCRtpReceiver>> | |
| 1639 RTCPeerConnectionHandler::getReceivers() { | |
| 1640 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1641 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::getReceivers"); | |
| 1642 | |
| 1643 std::vector<rtc::scoped_refptr<webrtc::RtpReceiverInterface>> | |
| 1644 webrtc_receivers = native_peer_connection_->GetReceivers(); | |
| 1645 std::vector<std::unique_ptr<blink::WebRTCRtpReceiver>> web_receivers; | |
| 1646 for (size_t i = 0; i < webrtc_receivers.size(); ++i) { | |
| 1647 rtc::scoped_refptr<webrtc::MediaStreamTrackInterface> webrtc_track = | |
| 1648 webrtc_receivers[i]->track(); | |
| 1649 DCHECK(webrtc_track); | |
| 1650 // Create a reference to the receiver. Multiple |RTCRtpReceiver|s can | |
| 1651 // reference the same webrtc track, see |id|. | |
| 1652 blink::WebMediaStreamTrack web_track; | |
| 1653 if (webrtc_track->kind() == webrtc::MediaStreamTrackInterface::kAudioKind) { | |
| 1654 web_track = GetRemoteAudioTrack(webrtc_track->id()); | |
| 1655 } else { | |
| 1656 web_track = GetRemoteVideoTrack(webrtc_track->id()); | |
| 1657 } | |
| 1658 // TODO(hbos): Any existing remote track should be known but the case of a | |
| 1659 // track being added or removed separately from streams is not handled | |
| 1660 // properly, see todo in |GetRemoteAudioTrack| and |GetRemoteVideoTrack|. | |
| 1661 // When that is addressed, DCHECK that the track is not null. | |
|
Guido Urdaneta
2017/03/27 17:12:23
reference crbug
hbos_chromium
2017/03/28 10:12:55
Done.
| |
| 1662 if (!web_track.isNull()) { | |
| 1663 web_receivers.push_back(std::unique_ptr<blink::WebRTCRtpReceiver>( | |
|
Guido Urdaneta
2017/03/27 17:12:23
use emplace_back or base::MakeUnique instead of un
hbos_chromium
2017/03/28 10:12:55
Done.
Guido Urdaneta
2017/03/28 14:27:03
Nit: I know I suggested emplace_back, but I overlo
hbos_chromium
2017/03/29 14:36:42
Done.
| |
| 1664 new RTCRtpReceiver(webrtc_receivers[i].get(), web_track))); | |
| 1665 } | |
| 1666 } | |
| 1667 | |
| 1668 // |blink::WebVector|'s size must be known at construction, that is why | |
| 1669 // |web_vectors| uses |std::vector| and needs to be moved before returning. | |
| 1670 blink::WebVector<std::unique_ptr<blink::WebRTCRtpReceiver>> result( | |
| 1671 web_receivers.size()); | |
| 1672 for (size_t i = 0; i < web_receivers.size(); ++i) { | |
| 1673 result[i] = std::move(web_receivers[i]); | |
| 1674 } | |
| 1675 return result; | |
| 1676 } | |
| 1677 | |
| 1637 void RTCPeerConnectionHandler::CloseClientPeerConnection() { | 1678 void RTCPeerConnectionHandler::CloseClientPeerConnection() { |
| 1638 DCHECK(thread_checker_.CalledOnValidThread()); | 1679 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1639 if (!is_closed_) | 1680 if (!is_closed_) |
| 1640 client_->closePeerConnection(); | 1681 client_->closePeerConnection(); |
| 1641 } | 1682 } |
| 1642 | 1683 |
| 1643 void RTCPeerConnectionHandler::StartEventLog(IPC::PlatformFileForTransit file, | 1684 void RTCPeerConnectionHandler::StartEventLog(IPC::PlatformFileForTransit file, |
| 1644 int64_t max_file_size_bytes) { | 1685 int64_t max_file_size_bytes) { |
| 1645 DCHECK(thread_checker_.CalledOnValidThread()); | 1686 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1646 DCHECK(file != IPC::InvalidPlatformFileForTransit()); | 1687 DCHECK(file != IPC::InvalidPlatformFileForTransit()); |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1987 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, | 2028 base::WaitableEvent event(base::WaitableEvent::ResetPolicy::AUTOMATIC, |
| 1988 base::WaitableEvent::InitialState::NOT_SIGNALED); | 2029 base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 1989 thread->PostTask(FROM_HERE, | 2030 thread->PostTask(FROM_HERE, |
| 1990 base::Bind(&RunSynchronousClosure, closure, | 2031 base::Bind(&RunSynchronousClosure, closure, |
| 1991 base::Unretained(trace_event_name), | 2032 base::Unretained(trace_event_name), |
| 1992 base::Unretained(&event))); | 2033 base::Unretained(&event))); |
| 1993 event.Wait(); | 2034 event.Wait(); |
| 1994 } | 2035 } |
| 1995 } | 2036 } |
| 1996 | 2037 |
| 2038 blink::WebMediaStreamTrack RTCPeerConnectionHandler::GetRemoteAudioTrack( | |
| 2039 const std::string& track_id) const { | |
|
Guido Urdaneta
2017/03/27 17:12:23
Since both methods are the same except for getAudi
hbos_chromium
2017/03/28 10:12:54
Done.
| |
| 2040 // TODO(hbos): Tracks and streams are currently added/removed on a per-stream | |
| 2041 // basis, but tracks could be removed from a stream or added to an existing | |
| 2042 // stream. We need to listen to events of tracks being added and removed, and | |
| 2043 // have a list of tracks that is separate from the list of streams. | |
| 2044 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 2045 blink::WebString id = blink::WebString::fromUTF8(track_id); | |
| 2046 for (const auto& remote_stream_pair : remote_streams_) { | |
| 2047 blink::WebMediaStreamTrack web_track = | |
| 2048 remote_stream_pair.second->webkit_stream().getAudioTrack(id); | |
| 2049 if (!web_track.isNull()) | |
| 2050 return web_track; | |
| 2051 } | |
| 2052 return blink::WebMediaStreamTrack(); | |
| 2053 } | |
| 2054 | |
| 2055 blink::WebMediaStreamTrack RTCPeerConnectionHandler::GetRemoteVideoTrack( | |
| 2056 const std::string& track_id) const { | |
| 2057 // TODO(hbos): Tracks and streams are currently added/removed on a per-stream | |
| 2058 // basis, but tracks could be removed from a stream or added to an existing | |
| 2059 // stream. We need to listen to events of tracks being added and removed, and | |
| 2060 // have a list of tracks that is separate from the list of streams. | |
| 2061 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 2062 blink::WebString id = blink::WebString::fromUTF8(track_id); | |
| 2063 for (const auto& remote_stream_pair : remote_streams_) { | |
| 2064 blink::WebMediaStreamTrack web_track = | |
| 2065 remote_stream_pair.second->webkit_stream().getVideoTrack(id); | |
| 2066 if (!web_track.isNull()) | |
| 2067 return web_track; | |
| 2068 } | |
| 2069 return blink::WebMediaStreamTrack(); | |
| 2070 } | |
| 2071 | |
| 1997 void RTCPeerConnectionHandler::ReportICEState( | 2072 void RTCPeerConnectionHandler::ReportICEState( |
| 1998 webrtc::PeerConnectionInterface::IceConnectionState new_state) { | 2073 webrtc::PeerConnectionInterface::IceConnectionState new_state) { |
| 1999 DCHECK(thread_checker_.CalledOnValidThread()); | 2074 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2000 if (ice_state_seen_[new_state]) | 2075 if (ice_state_seen_[new_state]) |
| 2001 return; | 2076 return; |
| 2002 ice_state_seen_[new_state] = true; | 2077 ice_state_seen_[new_state] = true; |
| 2003 UMA_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.ConnectionState", new_state, | 2078 UMA_HISTOGRAM_ENUMERATION("WebRTC.PeerConnection.ConnectionState", new_state, |
| 2004 webrtc::PeerConnectionInterface::kIceConnectionMax); | 2079 webrtc::PeerConnectionInterface::kIceConnectionMax); |
| 2005 } | 2080 } |
| 2006 | 2081 |
| 2007 void RTCPeerConnectionHandler::ResetUMAStats() { | 2082 void RTCPeerConnectionHandler::ResetUMAStats() { |
| 2008 DCHECK(thread_checker_.CalledOnValidThread()); | 2083 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2009 num_local_candidates_ipv6_ = 0; | 2084 num_local_candidates_ipv6_ = 0; |
| 2010 num_local_candidates_ipv4_ = 0; | 2085 num_local_candidates_ipv4_ = 0; |
| 2011 ice_connection_checking_start_ = base::TimeTicks(); | 2086 ice_connection_checking_start_ = base::TimeTicks(); |
| 2012 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); | 2087 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); |
| 2013 } | 2088 } |
| 2014 } // namespace content | 2089 } // namespace content |
| OLD | NEW |