| 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 972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 983 // signaling thread, so this class takes care of delivering them to an | 983 // signaling thread, so this class takes care of delivering them to an |
| 984 // RTCPeerConnectionHandler instance on the main thread. | 984 // RTCPeerConnectionHandler instance on the main thread. |
| 985 // In order to do safe PostTask-ing, the class is reference counted and | 985 // In order to do safe PostTask-ing, the class is reference counted and |
| 986 // checks for the existence of the RTCPeerConnectionHandler instance before | 986 // checks for the existence of the RTCPeerConnectionHandler instance before |
| 987 // delivering callbacks on the main thread. | 987 // delivering callbacks on the main thread. |
| 988 class RTCPeerConnectionHandler::Observer | 988 class RTCPeerConnectionHandler::Observer |
| 989 : public base::RefCountedThreadSafe<RTCPeerConnectionHandler::Observer>, | 989 : public base::RefCountedThreadSafe<RTCPeerConnectionHandler::Observer>, |
| 990 public PeerConnectionObserver { | 990 public PeerConnectionObserver { |
| 991 public: | 991 public: |
| 992 Observer(const base::WeakPtr<RTCPeerConnectionHandler>& handler) | 992 Observer(const base::WeakPtr<RTCPeerConnectionHandler>& handler) |
| 993 : handler_(handler), main_thread_(base::ThreadTaskRunnerHandle::Get()) {} | 993 : handler_(handler), |
| 994 main_thread_(base::ThreadTaskRunnerHandle::Get()), |
| 995 track_adapter_map_(handler_->track_adapter_map_) { |
| 996 DCHECK(track_adapter_map_); |
| 997 } |
| 994 | 998 |
| 995 protected: | 999 protected: |
| 996 friend class base::RefCountedThreadSafe<RTCPeerConnectionHandler::Observer>; | 1000 friend class base::RefCountedThreadSafe<RTCPeerConnectionHandler::Observer>; |
| 997 virtual ~Observer() {} | 1001 virtual ~Observer() {} |
| 998 | 1002 |
| 999 void OnSignalingChange( | 1003 void OnSignalingChange( |
| 1000 PeerConnectionInterface::SignalingState new_state) override { | 1004 PeerConnectionInterface::SignalingState new_state) override { |
| 1001 if (!main_thread_->BelongsToCurrentThread()) { | 1005 if (!main_thread_->BelongsToCurrentThread()) { |
| 1002 main_thread_->PostTask(FROM_HERE, | 1006 main_thread_->PostTask(FROM_HERE, |
| 1003 base::Bind(&RTCPeerConnectionHandler::Observer::OnSignalingChange, | 1007 base::Bind(&RTCPeerConnectionHandler::Observer::OnSignalingChange, |
| 1004 this, new_state)); | 1008 this, new_state)); |
| 1005 } else if (handler_) { | 1009 } else if (handler_) { |
| 1006 handler_->OnSignalingChange(new_state); | 1010 handler_->OnSignalingChange(new_state); |
| 1007 } | 1011 } |
| 1008 } | 1012 } |
| 1009 | 1013 |
| 1010 void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) override { | 1014 void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) override { |
| 1011 DCHECK(stream); | 1015 DCHECK(stream); |
| 1012 std::unique_ptr<RemoteMediaStreamImpl> remote_stream( | 1016 std::unique_ptr<RemoteMediaStreamImpl> remote_stream( |
| 1013 new RemoteMediaStreamImpl(main_thread_, stream)); | 1017 new RemoteMediaStreamImpl(main_thread_, track_adapter_map_, stream)); |
| 1014 | 1018 |
| 1015 // The webkit object owned by RemoteMediaStreamImpl, will be initialized | 1019 // The webkit object owned by RemoteMediaStreamImpl, will be initialized |
| 1016 // asynchronously and the posted task will execude after that initialization | 1020 // asynchronously and the posted task will execude after that initialization |
| 1017 // is done. | 1021 // is done. |
| 1018 main_thread_->PostTask(FROM_HERE, | 1022 main_thread_->PostTask(FROM_HERE, |
| 1019 base::Bind(&RTCPeerConnectionHandler::Observer::OnAddStreamImpl, | 1023 base::Bind(&RTCPeerConnectionHandler::Observer::OnAddStreamImpl, |
| 1020 this, base::Passed(&remote_stream))); | 1024 this, base::Passed(&remote_stream))); |
| 1021 } | 1025 } |
| 1022 | 1026 |
| 1023 void OnRemoveStream( | 1027 void OnRemoveStream( |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1104 int sdp_mline_index, int component, int address_family) { | 1108 int sdp_mline_index, int component, int address_family) { |
| 1105 if (handler_) { | 1109 if (handler_) { |
| 1106 handler_->OnIceCandidate(sdp, sdp_mid, sdp_mline_index, component, | 1110 handler_->OnIceCandidate(sdp, sdp_mid, sdp_mline_index, component, |
| 1107 address_family); | 1111 address_family); |
| 1108 } | 1112 } |
| 1109 } | 1113 } |
| 1110 | 1114 |
| 1111 private: | 1115 private: |
| 1112 const base::WeakPtr<RTCPeerConnectionHandler> handler_; | 1116 const base::WeakPtr<RTCPeerConnectionHandler> handler_; |
| 1113 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_; | 1117 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_; |
| 1118 const scoped_refptr<WebRtcMediaStreamTrackAdapterMap> track_adapter_map_; |
| 1114 }; | 1119 }; |
| 1115 | 1120 |
| 1116 RTCPeerConnectionHandler::RTCPeerConnectionHandler( | 1121 RTCPeerConnectionHandler::RTCPeerConnectionHandler( |
| 1117 blink::WebRTCPeerConnectionHandlerClient* client, | 1122 blink::WebRTCPeerConnectionHandlerClient* client, |
| 1118 PeerConnectionDependencyFactory* dependency_factory) | 1123 PeerConnectionDependencyFactory* dependency_factory) |
| 1119 : client_(client), | 1124 : client_(client), |
| 1120 is_closed_(false), | 1125 is_closed_(false), |
| 1121 dependency_factory_(dependency_factory), | 1126 dependency_factory_(dependency_factory), |
| 1122 track_adapter_map_(new WebRtcMediaStreamTrackAdapterMap( | 1127 track_adapter_map_( |
| 1123 dependency_factory_, | 1128 new WebRtcMediaStreamTrackAdapterMap(dependency_factory_)), |
| 1124 base::ThreadTaskRunnerHandle::Get())), | |
| 1125 weak_factory_(this) { | 1129 weak_factory_(this) { |
| 1126 CHECK(client_); | 1130 CHECK(client_); |
| 1127 GetPeerConnectionHandlers()->insert(this); | 1131 GetPeerConnectionHandlers()->insert(this); |
| 1128 } | 1132 } |
| 1129 | 1133 |
| 1130 RTCPeerConnectionHandler::~RTCPeerConnectionHandler() { | 1134 RTCPeerConnectionHandler::~RTCPeerConnectionHandler() { |
| 1131 DCHECK(thread_checker_.CalledOnValidThread()); | 1135 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1132 | 1136 |
| 1133 Stop(); | 1137 Stop(); |
| 1134 | 1138 |
| (...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2123 } | 2127 } |
| 2124 | 2128 |
| 2125 void RTCPeerConnectionHandler::ResetUMAStats() { | 2129 void RTCPeerConnectionHandler::ResetUMAStats() { |
| 2126 DCHECK(thread_checker_.CalledOnValidThread()); | 2130 DCHECK(thread_checker_.CalledOnValidThread()); |
| 2127 num_local_candidates_ipv6_ = 0; | 2131 num_local_candidates_ipv6_ = 0; |
| 2128 num_local_candidates_ipv4_ = 0; | 2132 num_local_candidates_ipv4_ = 0; |
| 2129 ice_connection_checking_start_ = base::TimeTicks(); | 2133 ice_connection_checking_start_ = base::TimeTicks(); |
| 2130 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); | 2134 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); |
| 2131 } | 2135 } |
| 2132 } // namespace content | 2136 } // namespace content |
| OLD | NEW |