| 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 1087 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1098 }; | 1098 }; |
| 1099 | 1099 |
| 1100 RTCPeerConnectionHandler::RTCPeerConnectionHandler( | 1100 RTCPeerConnectionHandler::RTCPeerConnectionHandler( |
| 1101 blink::WebRTCPeerConnectionHandlerClient* client, | 1101 blink::WebRTCPeerConnectionHandlerClient* client, |
| 1102 PeerConnectionDependencyFactory* dependency_factory) | 1102 PeerConnectionDependencyFactory* dependency_factory) |
| 1103 : client_(client), | 1103 : client_(client), |
| 1104 is_closed_(false), | 1104 is_closed_(false), |
| 1105 dependency_factory_(dependency_factory), | 1105 dependency_factory_(dependency_factory), |
| 1106 track_adapter_map_( | 1106 track_adapter_map_( |
| 1107 new WebRtcMediaStreamTrackAdapterMap(dependency_factory_)), | 1107 new WebRtcMediaStreamTrackAdapterMap(dependency_factory_)), |
| 1108 stream_adapter_map_(new WebRtcMediaStreamAdapterMap(dependency_factory_, |
| 1109 track_adapter_map_)), |
| 1108 weak_factory_(this) { | 1110 weak_factory_(this) { |
| 1109 CHECK(client_); | 1111 CHECK(client_); |
| 1110 GetPeerConnectionHandlers()->insert(this); | 1112 GetPeerConnectionHandlers()->insert(this); |
| 1111 } | 1113 } |
| 1112 | 1114 |
| 1113 RTCPeerConnectionHandler::~RTCPeerConnectionHandler() { | 1115 RTCPeerConnectionHandler::~RTCPeerConnectionHandler() { |
| 1114 DCHECK(thread_checker_.CalledOnValidThread()); | 1116 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1115 | 1117 |
| 1116 Stop(); | 1118 Stop(); |
| 1117 | 1119 |
| (...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1517 } | 1519 } |
| 1518 | 1520 |
| 1519 return webkit_request.RequestSucceeded(); | 1521 return webkit_request.RequestSucceeded(); |
| 1520 } | 1522 } |
| 1521 | 1523 |
| 1522 bool RTCPeerConnectionHandler::AddStream( | 1524 bool RTCPeerConnectionHandler::AddStream( |
| 1523 const blink::WebMediaStream& stream, | 1525 const blink::WebMediaStream& stream, |
| 1524 const blink::WebMediaConstraints& options) { | 1526 const blink::WebMediaConstraints& options) { |
| 1525 DCHECK(thread_checker_.CalledOnValidThread()); | 1527 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1526 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::addStream"); | 1528 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::addStream"); |
| 1527 for (const auto& adapter : local_streams_) { | 1529 for (const auto& adapter_ref : local_streams_) { |
| 1528 if (adapter->IsEqual(stream)) { | 1530 if (adapter_ref->adapter().IsEqual(stream)) { |
| 1529 DVLOG(1) << "RTCPeerConnectionHandler::addStream called with the same " | 1531 DVLOG(1) << "RTCPeerConnectionHandler::addStream called with the same " |
| 1530 << "stream twice. id=" << stream.Id().Utf8(); | 1532 << "stream twice. id=" << stream.Id().Utf8(); |
| 1531 return false; | 1533 return false; |
| 1532 } | 1534 } |
| 1533 } | 1535 } |
| 1534 | 1536 |
| 1535 if (peer_connection_tracker_) { | 1537 if (peer_connection_tracker_) { |
| 1536 peer_connection_tracker_->TrackAddStream( | 1538 peer_connection_tracker_->TrackAddStream( |
| 1537 this, stream, PeerConnectionTracker::SOURCE_LOCAL); | 1539 this, stream, PeerConnectionTracker::SOURCE_LOCAL); |
| 1538 } | 1540 } |
| 1539 | 1541 |
| 1540 PerSessionWebRTCAPIMetrics::GetInstance()->IncrementStreamCounter(); | 1542 PerSessionWebRTCAPIMetrics::GetInstance()->IncrementStreamCounter(); |
| 1541 | 1543 |
| 1542 local_streams_.push_back(base::MakeUnique<WebRtcMediaStreamAdapter>( | 1544 local_streams_.push_back( |
| 1543 dependency_factory_, track_adapter_map_, stream)); | 1545 stream_adapter_map_->GetOrCreateLocalStreamAdapter(stream)); |
| 1544 | 1546 |
| 1545 webrtc::MediaStreamInterface* webrtc_stream = | 1547 webrtc::MediaStreamInterface* webrtc_stream = |
| 1546 local_streams_.back()->webrtc_media_stream(); | 1548 local_streams_.back()->adapter().webrtc_media_stream(); |
| 1547 track_metrics_.AddStream(MediaStreamTrackMetrics::SENT_STREAM, | 1549 track_metrics_.AddStream(MediaStreamTrackMetrics::SENT_STREAM, |
| 1548 webrtc_stream); | 1550 webrtc_stream); |
| 1549 | 1551 |
| 1550 if (!options.IsEmpty()) { | 1552 if (!options.IsEmpty()) { |
| 1551 // TODO(perkj): |mediaConstraints| is the name of the optional constraints | 1553 // TODO(perkj): |mediaConstraints| is the name of the optional constraints |
| 1552 // argument in RTCPeerConnection.idl. It has been removed from the spec and | 1554 // argument in RTCPeerConnection.idl. It has been removed from the spec and |
| 1553 // should be removed from blink as well. | 1555 // should be removed from blink as well. |
| 1554 LOG(WARNING) | 1556 LOG(WARNING) |
| 1555 << "mediaConstraints is not a supported argument to addStream."; | 1557 << "mediaConstraints is not a supported argument to addStream."; |
| 1556 LOG(WARNING) << "mediaConstraints was " << options.ToString().Utf8(); | 1558 LOG(WARNING) << "mediaConstraints was " << options.ToString().Utf8(); |
| 1557 } | 1559 } |
| 1558 | 1560 |
| 1559 return native_peer_connection_->AddStream(webrtc_stream); | 1561 return native_peer_connection_->AddStream(webrtc_stream); |
| 1560 } | 1562 } |
| 1561 | 1563 |
| 1562 void RTCPeerConnectionHandler::RemoveStream( | 1564 void RTCPeerConnectionHandler::RemoveStream( |
| 1563 const blink::WebMediaStream& stream) { | 1565 const blink::WebMediaStream& stream) { |
| 1564 DCHECK(thread_checker_.CalledOnValidThread()); | 1566 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1565 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::removeStream"); | 1567 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::removeStream"); |
| 1566 // Find the webrtc stream. | 1568 // Find the webrtc stream. |
| 1567 scoped_refptr<webrtc::MediaStreamInterface> webrtc_stream; | 1569 scoped_refptr<webrtc::MediaStreamInterface> webrtc_stream; |
| 1568 for (auto adapter_it = local_streams_.begin(); | 1570 for (auto adapter_it = local_streams_.begin(); |
| 1569 adapter_it != local_streams_.end(); ++adapter_it) { | 1571 adapter_it != local_streams_.end(); ++adapter_it) { |
| 1570 if ((*adapter_it)->IsEqual(stream)) { | 1572 if ((*adapter_it)->adapter().IsEqual(stream)) { |
| 1571 webrtc_stream = (*adapter_it)->webrtc_media_stream(); | 1573 webrtc_stream = (*adapter_it)->adapter().webrtc_media_stream(); |
| 1572 local_streams_.erase(adapter_it); | 1574 local_streams_.erase(adapter_it); |
| 1573 break; | 1575 break; |
| 1574 } | 1576 } |
| 1575 } | 1577 } |
| 1576 DCHECK(webrtc_stream.get()); | 1578 DCHECK(webrtc_stream.get()); |
| 1577 // TODO(tommi): Make this async (PostTaskAndReply). | 1579 // TODO(tommi): Make this async (PostTaskAndReply). |
| 1578 native_peer_connection_->RemoveStream(webrtc_stream.get()); | 1580 native_peer_connection_->RemoveStream(webrtc_stream.get()); |
| 1579 | 1581 |
| 1580 if (peer_connection_tracker_) { | 1582 if (peer_connection_tracker_) { |
| 1581 peer_connection_tracker_->TrackRemoveStream( | 1583 peer_connection_tracker_->TrackRemoveStream( |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1752 | 1754 |
| 1753 blink::WebRTCDTMFSenderHandler* RTCPeerConnectionHandler::CreateDTMFSender( | 1755 blink::WebRTCDTMFSenderHandler* RTCPeerConnectionHandler::CreateDTMFSender( |
| 1754 const blink::WebMediaStreamTrack& track) { | 1756 const blink::WebMediaStreamTrack& track) { |
| 1755 DCHECK(thread_checker_.CalledOnValidThread()); | 1757 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1756 DCHECK(!track.IsNull()); | 1758 DCHECK(!track.IsNull()); |
| 1757 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createDTMFSender"); | 1759 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createDTMFSender"); |
| 1758 DVLOG(1) << "createDTMFSender."; | 1760 DVLOG(1) << "createDTMFSender."; |
| 1759 | 1761 |
| 1760 // Find the WebRtc track referenced by the blink track's ID. | 1762 // Find the WebRtc track referenced by the blink track's ID. |
| 1761 webrtc::AudioTrackInterface* webrtc_track = nullptr; | 1763 webrtc::AudioTrackInterface* webrtc_track = nullptr; |
| 1762 for (const auto& adapter : local_streams_) { | 1764 for (const auto& adapter_ref : local_streams_) { |
| 1763 webrtc_track = | 1765 webrtc_track = adapter_ref->adapter().webrtc_media_stream()->FindAudioTrack( |
| 1764 adapter->webrtc_media_stream()->FindAudioTrack(track.Id().Utf8()); | 1766 track.Id().Utf8()); |
| 1765 if (webrtc_track) | 1767 if (webrtc_track) |
| 1766 break; | 1768 break; |
| 1767 } | 1769 } |
| 1768 if (!webrtc_track) { | 1770 if (!webrtc_track) { |
| 1769 DLOG(ERROR) << "Audio track with ID '" << track.Id().Utf8() | 1771 DLOG(ERROR) << "Audio track with ID '" << track.Id().Utf8() |
| 1770 << "' has no known WebRtc sink."; | 1772 << "' has no known WebRtc sink."; |
| 1771 return nullptr; | 1773 return nullptr; |
| 1772 } | 1774 } |
| 1773 | 1775 |
| 1774 rtc::scoped_refptr<webrtc::DtmfSenderInterface> sender( | 1776 rtc::scoped_refptr<webrtc::DtmfSenderInterface> sender( |
| (...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2068 } | 2070 } |
| 2069 | 2071 |
| 2070 void RTCPeerConnectionHandler::ResetUMAStats() { | 2072 void RTCPeerConnectionHandler::ResetUMAStats() { |
| 2071 DCHECK(thread_checker_.CalledOnValidThread()); | 2073 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2072 num_local_candidates_ipv6_ = 0; | 2074 num_local_candidates_ipv6_ = 0; |
| 2073 num_local_candidates_ipv4_ = 0; | 2075 num_local_candidates_ipv4_ = 0; |
| 2074 ice_connection_checking_start_ = base::TimeTicks(); | 2076 ice_connection_checking_start_ = base::TimeTicks(); |
| 2075 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); | 2077 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); |
| 2076 } | 2078 } |
| 2077 } // namespace content | 2079 } // namespace content |
| OLD | NEW |