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> | 7 #include <string> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/stl_util.h" |
13 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
14 #include "content/renderer/media/media_stream_dependency_factory.h" | 15 #include "content/renderer/media/media_stream_dependency_factory.h" |
15 #include "content/renderer/media/peer_connection_tracker.h" | 16 #include "content/renderer/media/peer_connection_tracker.h" |
| 17 #include "content/renderer/media/remote_media_stream_impl.h" |
16 #include "content/renderer/media/rtc_data_channel_handler.h" | 18 #include "content/renderer/media/rtc_data_channel_handler.h" |
17 #include "content/renderer/media/rtc_dtmf_sender_handler.h" | 19 #include "content/renderer/media/rtc_dtmf_sender_handler.h" |
18 #include "content/renderer/media/rtc_media_constraints.h" | 20 #include "content/renderer/media/rtc_media_constraints.h" |
19 #include "content/renderer/render_thread_impl.h" | 21 #include "content/renderer/render_thread_impl.h" |
20 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaConstraints
.h" | 22 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaConstraints
.h" |
21 // TODO(hta): Move the following include to WebRTCStatsRequest.h file. | 23 // TODO(hta): Move the following include to WebRTCStatsRequest.h file. |
22 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamSourc
e.h" | 24 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamSourc
e.h" |
23 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamTrack
.h" | 25 #include "third_party/WebKit/Source/Platform/chromium/public/WebMediaStreamTrack
.h" |
24 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCConfiguration
.h" | 26 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCConfiguration
.h" |
25 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCICECandidate.
h" | 27 #include "third_party/WebKit/Source/Platform/chromium/public/WebRTCICECandidate.
h" |
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 MediaStreamDependencyFactory* dependency_factory) | 318 MediaStreamDependencyFactory* dependency_factory) |
317 : PeerConnectionHandlerBase(dependency_factory), | 319 : PeerConnectionHandlerBase(dependency_factory), |
318 client_(client), | 320 client_(client), |
319 frame_(NULL), | 321 frame_(NULL), |
320 peer_connection_tracker_(NULL) { | 322 peer_connection_tracker_(NULL) { |
321 } | 323 } |
322 | 324 |
323 RTCPeerConnectionHandler::~RTCPeerConnectionHandler() { | 325 RTCPeerConnectionHandler::~RTCPeerConnectionHandler() { |
324 if (peer_connection_tracker_) | 326 if (peer_connection_tracker_) |
325 peer_connection_tracker_->UnregisterPeerConnection(this); | 327 peer_connection_tracker_->UnregisterPeerConnection(this); |
| 328 STLDeleteValues(&remote_streams_); |
326 } | 329 } |
327 | 330 |
328 void RTCPeerConnectionHandler::associateWithFrame(WebKit::WebFrame* frame) { | 331 void RTCPeerConnectionHandler::associateWithFrame(WebKit::WebFrame* frame) { |
329 DCHECK(frame); | 332 DCHECK(frame); |
330 frame_ = frame; | 333 frame_ = frame; |
331 } | 334 } |
332 | 335 |
333 bool RTCPeerConnectionHandler::initialize( | 336 bool RTCPeerConnectionHandler::initialize( |
334 const WebKit::WebRTCConfiguration& server_configuration, | 337 const WebKit::WebRTCConfiguration& server_configuration, |
335 const WebKit::WebMediaConstraints& options) { | 338 const WebKit::WebMediaConstraints& options) { |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
653 GetWebKitIceGatheringState(new_state); | 656 GetWebKitIceGatheringState(new_state); |
654 if (peer_connection_tracker_) | 657 if (peer_connection_tracker_) |
655 peer_connection_tracker_->TrackIceGatheringStateChange(this, state); | 658 peer_connection_tracker_->TrackIceGatheringStateChange(this, state); |
656 client_->didChangeICEGatheringState(state); | 659 client_->didChangeICEGatheringState(state); |
657 } | 660 } |
658 | 661 |
659 void RTCPeerConnectionHandler::OnAddStream( | 662 void RTCPeerConnectionHandler::OnAddStream( |
660 webrtc::MediaStreamInterface* stream_interface) { | 663 webrtc::MediaStreamInterface* stream_interface) { |
661 DCHECK(stream_interface); | 664 DCHECK(stream_interface); |
662 DCHECK(remote_streams_.find(stream_interface) == remote_streams_.end()); | 665 DCHECK(remote_streams_.find(stream_interface) == remote_streams_.end()); |
663 WebKit::WebMediaStream stream = | 666 |
664 CreateRemoteWebKitMediaStream(stream_interface); | 667 RemoteMediaStreamImpl* remote_stream = |
| 668 new RemoteMediaStreamImpl(stream_interface); |
| 669 remote_streams_.insert( |
| 670 std::pair<webrtc::MediaStreamInterface*, RemoteMediaStreamImpl*> ( |
| 671 stream_interface, remote_stream)); |
665 | 672 |
666 if (peer_connection_tracker_) | 673 if (peer_connection_tracker_) |
667 peer_connection_tracker_->TrackAddStream( | 674 peer_connection_tracker_->TrackAddStream( |
668 this, stream, PeerConnectionTracker::SOURCE_REMOTE); | 675 this, remote_stream->webkit_stream(), |
| 676 PeerConnectionTracker::SOURCE_REMOTE); |
669 | 677 |
670 remote_streams_.insert( | 678 client_->didAddRemoteStream(remote_stream->webkit_stream()); |
671 std::pair<webrtc::MediaStreamInterface*, | |
672 WebKit::WebMediaStream>(stream_interface, stream)); | |
673 client_->didAddRemoteStream(stream); | |
674 } | 679 } |
675 | 680 |
676 void RTCPeerConnectionHandler::OnRemoveStream( | 681 void RTCPeerConnectionHandler::OnRemoveStream( |
677 webrtc::MediaStreamInterface* stream_interface) { | 682 webrtc::MediaStreamInterface* stream_interface) { |
678 DCHECK(stream_interface); | 683 DCHECK(stream_interface); |
679 RemoteStreamMap::iterator it = remote_streams_.find(stream_interface); | 684 RemoteStreamMap::iterator it = remote_streams_.find(stream_interface); |
680 if (it == remote_streams_.end()) { | 685 if (it == remote_streams_.end()) { |
681 NOTREACHED() << "Stream not found"; | 686 NOTREACHED() << "Stream not found"; |
682 return; | 687 return; |
683 } | 688 } |
684 WebKit::WebMediaStream stream = it->second; | 689 |
685 DCHECK(!stream.isNull()); | 690 scoped_ptr<RemoteMediaStreamImpl> remote_stream(it->second); |
| 691 const WebKit::WebMediaStream& webkit_stream = remote_stream->webkit_stream(); |
| 692 DCHECK(!webkit_stream.isNull()); |
686 remote_streams_.erase(it); | 693 remote_streams_.erase(it); |
687 | 694 |
688 if (peer_connection_tracker_) | 695 if (peer_connection_tracker_) |
689 peer_connection_tracker_->TrackRemoveStream( | 696 peer_connection_tracker_->TrackRemoveStream( |
690 this, stream, PeerConnectionTracker::SOURCE_REMOTE); | 697 this, webkit_stream, PeerConnectionTracker::SOURCE_REMOTE); |
691 | 698 |
692 client_->didRemoveRemoteStream(stream); | 699 client_->didRemoveRemoteStream(webkit_stream); |
693 } | 700 } |
694 | 701 |
695 void RTCPeerConnectionHandler::OnIceCandidate( | 702 void RTCPeerConnectionHandler::OnIceCandidate( |
696 const webrtc::IceCandidateInterface* candidate) { | 703 const webrtc::IceCandidateInterface* candidate) { |
697 DCHECK(candidate); | 704 DCHECK(candidate); |
698 std::string sdp; | 705 std::string sdp; |
699 if (!candidate->ToString(&sdp)) { | 706 if (!candidate->ToString(&sdp)) { |
700 NOTREACHED() << "OnIceCandidate: Could not get SDP string."; | 707 NOTREACHED() << "OnIceCandidate: Could not get SDP string."; |
701 return; | 708 return; |
702 } | 709 } |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
741 webrtc::SessionDescriptionInterface* native_desc = | 748 webrtc::SessionDescriptionInterface* native_desc = |
742 dependency_factory_->CreateSessionDescription(type, sdp, error); | 749 dependency_factory_->CreateSessionDescription(type, sdp, error); |
743 | 750 |
744 LOG_IF(ERROR, !native_desc) << "Failed to create native session description." | 751 LOG_IF(ERROR, !native_desc) << "Failed to create native session description." |
745 << " Type: " << type << " SDP: " << sdp; | 752 << " Type: " << type << " SDP: " << sdp; |
746 | 753 |
747 return native_desc; | 754 return native_desc; |
748 } | 755 } |
749 | 756 |
750 } // namespace content | 757 } // namespace content |
OLD | NEW |