| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/devtools_bridge/session_dependency_factory.h" | 5 #include "components/devtools_bridge/session_dependency_factory.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/location.h" | 8 #include "base/location.h" |
| 9 #include "base/task_runner.h" | 9 #include "base/task_runner.h" |
| 10 #include "base/threading/thread.h" | 10 #include "base/threading/thread.h" |
| 11 #include "components/devtools_bridge/abstract_data_channel.h" | 11 #include "components/devtools_bridge/abstract_data_channel.h" |
| 12 #include "components/devtools_bridge/abstract_peer_connection.h" | 12 #include "components/devtools_bridge/abstract_peer_connection.h" |
| 13 #include "components/devtools_bridge/rtc_configuration.h" | 13 #include "components/devtools_bridge/rtc_configuration.h" |
| 14 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface
.h" | 14 #include "third_party/libjingle/source/talk/app/webrtc/mediaconstraintsinterface
.h" |
| 15 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h
" | 15 #include "third_party/libjingle/source/talk/app/webrtc/peerconnectioninterface.h
" |
| 16 #include "third_party/webrtc/base/bind.h" | 16 #include "third_party/webrtc/base/bind.h" |
| 17 #include "third_party/webrtc/base/messagehandler.h" | 17 #include "third_party/webrtc/base/messagehandler.h" |
| 18 #include "third_party/webrtc/base/messagequeue.h" | 18 #include "third_party/webrtc/base/messagequeue.h" |
| 19 #include "third_party/webrtc/base/ssladapter.h" | 19 #include "third_party/webrtc/base/ssladapter.h" |
| 20 #include "third_party/webrtc/base/thread.h" | 20 #include "third_party/webrtc/base/thread.h" |
| 21 | 21 |
| 22 namespace devtools_bridge { | 22 namespace devtools_bridge { |
| 23 | 23 |
| 24 class RTCConfiguration::Impl | 24 class RTCConfiguration::Impl |
| 25 : public RTCConfiguration, | 25 : public RTCConfiguration, |
| 26 public webrtc::PeerConnectionInterface::RTCConfiguration { | 26 public webrtc::PeerConnectionInterface::RTCConfiguration { |
| 27 public: | 27 public: |
| 28 | 28 void AddIceServer(const std::string& uri, |
| 29 virtual void AddIceServer( | 29 const std::string& username, |
| 30 const std::string& uri, | 30 const std::string& credential) override { |
| 31 const std::string& username, | |
| 32 const std::string& credential) override { | |
| 33 webrtc::PeerConnectionInterface::IceServer server; | 31 webrtc::PeerConnectionInterface::IceServer server; |
| 34 server.uri = uri; | 32 server.uri = uri; |
| 35 server.username = username; | 33 server.username = username; |
| 36 server.password = credential; | 34 server.password = credential; |
| 37 servers.push_back(server); | 35 servers.push_back(server); |
| 38 } | 36 } |
| 39 | 37 |
| 40 const Impl& impl() const override { | 38 const Impl& impl() const override { |
| 41 return *this; | 39 return *this; |
| 42 } | 40 } |
| 43 | 41 |
| 44 private: | 42 private: |
| 45 webrtc::PeerConnectionInterface::RTCConfiguration base_; | 43 webrtc::PeerConnectionInterface::RTCConfiguration base_; |
| 46 }; | 44 }; |
| 47 | 45 |
| 48 namespace { | 46 namespace { |
| 49 | 47 |
| 50 template <typename T> | 48 template <typename T> |
| 51 void CheckedRelease(rtc::scoped_refptr<T>* ptr) { | 49 void CheckedRelease(rtc::scoped_refptr<T>* ptr) { |
| 52 CHECK_EQ(0, ptr->release()->Release()); | 50 CHECK_EQ(0, ptr->release()->Release()); |
| 53 } | 51 } |
| 54 | 52 |
| 55 class MediaConstraints | 53 class MediaConstraints |
| 56 : public webrtc::MediaConstraintsInterface { | 54 : public webrtc::MediaConstraintsInterface { |
| 57 public: | 55 public: |
| 58 virtual ~MediaConstraints() {} | 56 ~MediaConstraints() override {} |
| 59 | 57 |
| 60 virtual const Constraints& GetMandatory() const override { | 58 const Constraints& GetMandatory() const override { return mandatory_; } |
| 61 return mandatory_; | |
| 62 } | |
| 63 | 59 |
| 64 virtual const Constraints& GetOptional() const override { | 60 const Constraints& GetOptional() const override { return optional_; } |
| 65 return optional_; | |
| 66 } | |
| 67 | 61 |
| 68 void AddMandatory(const std::string& key, const std::string& value) { | 62 void AddMandatory(const std::string& key, const std::string& value) { |
| 69 mandatory_.push_back(Constraint(key, value)); | 63 mandatory_.push_back(Constraint(key, value)); |
| 70 } | 64 } |
| 71 | 65 |
| 72 private: | 66 private: |
| 73 Constraints mandatory_; | 67 Constraints mandatory_; |
| 74 Constraints optional_; | 68 Constraints optional_; |
| 75 }; | 69 }; |
| 76 | 70 |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 webrtc::DataChannelInterface* data_channel, | 120 webrtc::DataChannelInterface* data_channel, |
| 127 scoped_ptr<AbstractDataChannel::Observer> observer) | 121 scoped_ptr<AbstractDataChannel::Observer> observer) |
| 128 : data_channel_(data_channel), | 122 : data_channel_(data_channel), |
| 129 observer_(observer.Pass()) { | 123 observer_(observer.Pass()) { |
| 130 } | 124 } |
| 131 | 125 |
| 132 void InitState() { | 126 void InitState() { |
| 133 open_ = data_channel_->state() == webrtc::DataChannelInterface::kOpen; | 127 open_ = data_channel_->state() == webrtc::DataChannelInterface::kOpen; |
| 134 } | 128 } |
| 135 | 129 |
| 136 virtual void OnStateChange() override { | 130 void OnStateChange() override { |
| 137 bool open = data_channel_->state() == webrtc::DataChannelInterface::kOpen; | 131 bool open = data_channel_->state() == webrtc::DataChannelInterface::kOpen; |
| 138 | 132 |
| 139 if (open == open_) return; | 133 if (open == open_) return; |
| 140 | 134 |
| 141 open_ = open; | 135 open_ = open; |
| 142 if (open) { | 136 if (open) { |
| 143 observer_->OnOpen(); | 137 observer_->OnOpen(); |
| 144 } else { | 138 } else { |
| 145 observer_->OnClose(); | 139 observer_->OnClose(); |
| 146 } | 140 } |
| 147 } | 141 } |
| 148 | 142 |
| 149 virtual void OnMessage(const webrtc::DataBuffer& buffer) override { | 143 void OnMessage(const webrtc::DataBuffer& buffer) override { |
| 150 observer_->OnMessage(buffer.data.data(), buffer.size()); | 144 observer_->OnMessage(buffer.data.data(), buffer.size()); |
| 151 } | 145 } |
| 152 | 146 |
| 153 private: | 147 private: |
| 154 webrtc::DataChannelInterface* const data_channel_; | 148 webrtc::DataChannelInterface* const data_channel_; |
| 155 scoped_ptr<AbstractDataChannel::Observer> const observer_; | 149 scoped_ptr<AbstractDataChannel::Observer> const observer_; |
| 156 bool open_; | 150 bool open_; |
| 157 }; | 151 }; |
| 158 | 152 |
| 159 /** | 153 /** |
| 160 * Thread-safe view on AbstractDataChannel. | 154 * Thread-safe view on AbstractDataChannel. |
| 161 */ | 155 */ |
| 162 class DataChannelProxyImpl : public AbstractDataChannel::Proxy { | 156 class DataChannelProxyImpl : public AbstractDataChannel::Proxy { |
| 163 public: | 157 public: |
| 164 DataChannelProxyImpl( | 158 DataChannelProxyImpl( |
| 165 SessionDependencyFactory* factory, | 159 SessionDependencyFactory* factory, |
| 166 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) | 160 rtc::scoped_refptr<webrtc::DataChannelInterface> data_channel) |
| 167 : data_channel_(data_channel), | 161 : data_channel_(data_channel), |
| 168 signaling_thread_task_runner_( | 162 signaling_thread_task_runner_( |
| 169 factory->signaling_thread_task_runner()) { | 163 factory->signaling_thread_task_runner()) { |
| 170 } | 164 } |
| 171 | 165 |
| 172 void StopOnSignalingThread() { | 166 void StopOnSignalingThread() { |
| 173 data_channel_ = NULL; | 167 data_channel_ = NULL; |
| 174 } | 168 } |
| 175 | 169 |
| 176 virtual void SendBinaryMessage(const void* data, size_t length) override { | 170 void SendBinaryMessage(const void* data, size_t length) override { |
| 177 auto buffer = make_scoped_ptr(new webrtc::DataBuffer(rtc::Buffer(), true)); | 171 auto buffer = make_scoped_ptr(new webrtc::DataBuffer(rtc::Buffer(), true)); |
| 178 buffer->data.SetData(data, length); | 172 buffer->data.SetData(data, length); |
| 179 | 173 |
| 180 signaling_thread_task_runner_->PostTask( | 174 signaling_thread_task_runner_->PostTask( |
| 181 FROM_HERE, base::Bind( | 175 FROM_HERE, base::Bind( |
| 182 &DataChannelProxyImpl::SendMessageOnSignalingThread, | 176 &DataChannelProxyImpl::SendMessageOnSignalingThread, |
| 183 this, | 177 this, |
| 184 base::Passed(&buffer))); | 178 base::Passed(&buffer))); |
| 185 } | 179 } |
| 186 | 180 |
| 187 virtual void Close() override { | 181 void Close() override { |
| 188 signaling_thread_task_runner_->PostTask( | 182 signaling_thread_task_runner_->PostTask( |
| 189 FROM_HERE, base::Bind(&DataChannelProxyImpl::CloseOnSignalingThread, | 183 FROM_HERE, base::Bind(&DataChannelProxyImpl::CloseOnSignalingThread, |
| 190 this)); | 184 this)); |
| 191 } | 185 } |
| 192 | 186 |
| 193 private: | 187 private: |
| 194 | 188 |
| 195 ~DataChannelProxyImpl() override {} | 189 ~DataChannelProxyImpl() override {} |
| 196 | 190 |
| 197 void SendMessageOnSignalingThread(scoped_ptr<webrtc::DataBuffer> message) { | 191 void SendMessageOnSignalingThread(scoped_ptr<webrtc::DataBuffer> message) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 214 public: | 208 public: |
| 215 DataChannelImpl( | 209 DataChannelImpl( |
| 216 SessionDependencyFactory* factory, | 210 SessionDependencyFactory* factory, |
| 217 rtc::Thread* const signaling_thread, | 211 rtc::Thread* const signaling_thread, |
| 218 rtc::scoped_refptr<webrtc::DataChannelInterface> impl) | 212 rtc::scoped_refptr<webrtc::DataChannelInterface> impl) |
| 219 : factory_(factory), | 213 : factory_(factory), |
| 220 signaling_thread_(signaling_thread), | 214 signaling_thread_(signaling_thread), |
| 221 impl_(impl) { | 215 impl_(impl) { |
| 222 } | 216 } |
| 223 | 217 |
| 224 ~DataChannelImpl() { | 218 ~DataChannelImpl() override { |
| 225 if (proxy_.get()) { | 219 if (proxy_.get()) { |
| 226 signaling_thread_->Invoke<void>(rtc::Bind( | 220 signaling_thread_->Invoke<void>(rtc::Bind( |
| 227 &DataChannelProxyImpl::StopOnSignalingThread, proxy_.get())); | 221 &DataChannelProxyImpl::StopOnSignalingThread, proxy_.get())); |
| 228 } | 222 } |
| 229 } | 223 } |
| 230 | 224 |
| 231 virtual void RegisterObserver(scoped_ptr<Observer> observer) override { | 225 void RegisterObserver(scoped_ptr<Observer> observer) override { |
| 232 observer_.reset(new DataChannelObserverImpl(impl_.get(), observer.Pass())); | 226 observer_.reset(new DataChannelObserverImpl(impl_.get(), observer.Pass())); |
| 233 signaling_thread_->Invoke<void>(rtc::Bind( | 227 signaling_thread_->Invoke<void>(rtc::Bind( |
| 234 &DataChannelImpl::RegisterObserverOnSignalingThread, this)); | 228 &DataChannelImpl::RegisterObserverOnSignalingThread, this)); |
| 235 } | 229 } |
| 236 | 230 |
| 237 virtual void UnregisterObserver() override { | 231 void UnregisterObserver() override { |
| 238 DCHECK(observer_.get() != NULL); | 232 DCHECK(observer_.get() != NULL); |
| 239 impl_->UnregisterObserver(); | 233 impl_->UnregisterObserver(); |
| 240 observer_.reset(); | 234 observer_.reset(); |
| 241 } | 235 } |
| 242 | 236 |
| 243 virtual void SendBinaryMessage(void* data, size_t length) override { | 237 void SendBinaryMessage(void* data, size_t length) override { |
| 244 SendMessage(data, length, true); | 238 SendMessage(data, length, true); |
| 245 } | 239 } |
| 246 | 240 |
| 247 virtual void SendTextMessage(void* data, size_t length) override { | 241 void SendTextMessage(void* data, size_t length) override { |
| 248 SendMessage(data, length, false); | 242 SendMessage(data, length, false); |
| 249 } | 243 } |
| 250 | 244 |
| 251 void SendMessage(void* data, size_t length, bool is_binary) { | 245 void SendMessage(void* data, size_t length, bool is_binary) { |
| 252 impl_->Send(webrtc::DataBuffer(rtc::Buffer(data, length), is_binary)); | 246 impl_->Send(webrtc::DataBuffer(rtc::Buffer(data, length), is_binary)); |
| 253 } | 247 } |
| 254 | 248 |
| 255 void Close() override { | 249 void Close() override { |
| 256 impl_->Close(); | 250 impl_->Close(); |
| 257 } | 251 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 278 }; | 272 }; |
| 279 | 273 |
| 280 class PeerConnectionObserverImpl | 274 class PeerConnectionObserverImpl |
| 281 : public webrtc::PeerConnectionObserver { | 275 : public webrtc::PeerConnectionObserver { |
| 282 public: | 276 public: |
| 283 PeerConnectionObserverImpl(AbstractPeerConnection::Delegate* delegate) | 277 PeerConnectionObserverImpl(AbstractPeerConnection::Delegate* delegate) |
| 284 : delegate_(delegate), | 278 : delegate_(delegate), |
| 285 connected_(false) { | 279 connected_(false) { |
| 286 } | 280 } |
| 287 | 281 |
| 288 virtual void OnAddStream(webrtc::MediaStreamInterface* stream) override {} | 282 void OnAddStream(webrtc::MediaStreamInterface* stream) override {} |
| 289 | 283 |
| 290 virtual void OnRemoveStream(webrtc::MediaStreamInterface* stream) override {} | 284 void OnRemoveStream(webrtc::MediaStreamInterface* stream) override {} |
| 291 | 285 |
| 292 virtual void OnDataChannel(webrtc::DataChannelInterface* data_channel) | 286 void OnDataChannel(webrtc::DataChannelInterface* data_channel) override {} |
| 293 override {} | |
| 294 | 287 |
| 295 virtual void OnRenegotiationNeeded() override {} | 288 void OnRenegotiationNeeded() override {} |
| 296 | 289 |
| 297 virtual void OnSignalingChange( | 290 void OnSignalingChange( |
| 298 webrtc::PeerConnectionInterface::SignalingState new_state) override { | 291 webrtc::PeerConnectionInterface::SignalingState new_state) override {} |
| 299 } | |
| 300 | 292 |
| 301 virtual void OnIceConnectionChange( | 293 void OnIceConnectionChange( |
| 302 webrtc::PeerConnectionInterface::IceConnectionState new_state) override { | 294 webrtc::PeerConnectionInterface::IceConnectionState new_state) override { |
| 303 bool connected = | 295 bool connected = |
| 304 new_state == webrtc::PeerConnectionInterface::kIceConnectionConnected || | 296 new_state == webrtc::PeerConnectionInterface::kIceConnectionConnected || |
| 305 new_state == webrtc::PeerConnectionInterface::kIceConnectionCompleted; | 297 new_state == webrtc::PeerConnectionInterface::kIceConnectionCompleted; |
| 306 | 298 |
| 307 if (connected != connected_) { | 299 if (connected != connected_) { |
| 308 connected_ = connected; | 300 connected_ = connected; |
| 309 delegate_->OnIceConnectionChange(connected_); | 301 delegate_->OnIceConnectionChange(connected_); |
| 310 } | 302 } |
| 311 } | 303 } |
| 312 | 304 |
| 313 virtual void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) | 305 void OnIceCandidate(const webrtc::IceCandidateInterface* candidate) override { |
| 314 override { | |
| 315 std::string sdp; | 306 std::string sdp; |
| 316 candidate->ToString(&sdp); | 307 candidate->ToString(&sdp); |
| 317 | 308 |
| 318 delegate_->OnIceCandidate( | 309 delegate_->OnIceCandidate( |
| 319 candidate->sdp_mid(), candidate->sdp_mline_index(), sdp); | 310 candidate->sdp_mid(), candidate->sdp_mline_index(), sdp); |
| 320 } | 311 } |
| 321 | 312 |
| 322 private: | 313 private: |
| 323 AbstractPeerConnection::Delegate* const delegate_; | 314 AbstractPeerConnection::Delegate* const delegate_; |
| 324 bool connected_; | 315 bool connected_; |
| 325 }; | 316 }; |
| 326 | 317 |
| 327 /** | 318 /** |
| 328 * Helper object which may outlive PeerConnectionImpl. Provides access | 319 * Helper object which may outlive PeerConnectionImpl. Provides access |
| 329 * to the connection and the delegate to operaion callback objects | 320 * to the connection and the delegate to operaion callback objects |
| 330 * in a safe way. Always accessible on the signaling thread. | 321 * in a safe way. Always accessible on the signaling thread. |
| 331 */ | 322 */ |
| 332 class PeerConnectionHolder : public rtc::RefCountInterface { | 323 class PeerConnectionHolder : public rtc::RefCountInterface { |
| 333 public: | 324 public: |
| 334 PeerConnectionHolder( | 325 PeerConnectionHolder( |
| 335 rtc::Thread* signaling_thread, | 326 rtc::Thread* signaling_thread, |
| 336 webrtc::PeerConnectionInterface* connection, | 327 webrtc::PeerConnectionInterface* connection, |
| 337 AbstractPeerConnection::Delegate* delegate) | 328 AbstractPeerConnection::Delegate* delegate) |
| 338 : signaling_thread_(signaling_thread), | 329 : signaling_thread_(signaling_thread), |
| 339 connection_(connection), | 330 connection_(connection), |
| 340 delegate_(delegate), | 331 delegate_(delegate), |
| 341 disposed_(false) { | 332 disposed_(false) { |
| 342 } | 333 } |
| 343 | 334 |
| 344 virtual ~PeerConnectionHolder() { | 335 ~PeerConnectionHolder() override { DCHECK(disposed_); } |
| 345 DCHECK(disposed_); | |
| 346 } | |
| 347 | 336 |
| 348 void Dispose() { | 337 void Dispose() { |
| 349 DCHECK(!IsDisposed()); | 338 DCHECK(!IsDisposed()); |
| 350 disposed_ = true; | 339 disposed_ = true; |
| 351 } | 340 } |
| 352 | 341 |
| 353 webrtc::PeerConnectionInterface* connection() { | 342 webrtc::PeerConnectionInterface* connection() { |
| 354 DCHECK(!IsDisposed()); | 343 DCHECK(!IsDisposed()); |
| 355 return connection_; | 344 return connection_; |
| 356 } | 345 } |
| (...skipping 17 matching lines...) Expand all Loading... |
| 374 | 363 |
| 375 class CreateAndSetHandler | 364 class CreateAndSetHandler |
| 376 : public webrtc::CreateSessionDescriptionObserver, | 365 : public webrtc::CreateSessionDescriptionObserver, |
| 377 public webrtc::SetSessionDescriptionObserver { | 366 public webrtc::SetSessionDescriptionObserver { |
| 378 public: | 367 public: |
| 379 explicit CreateAndSetHandler( | 368 explicit CreateAndSetHandler( |
| 380 rtc::scoped_refptr<PeerConnectionHolder> holder) | 369 rtc::scoped_refptr<PeerConnectionHolder> holder) |
| 381 : holder_(holder) { | 370 : holder_(holder) { |
| 382 } | 371 } |
| 383 | 372 |
| 384 virtual void OnSuccess(webrtc::SessionDescriptionInterface* desc) override { | 373 void OnSuccess(webrtc::SessionDescriptionInterface* desc) override { |
| 385 if (holder_->IsDisposed()) return; | 374 if (holder_->IsDisposed()) return; |
| 386 | 375 |
| 387 type_ = desc->type(); | 376 type_ = desc->type(); |
| 388 if (desc->ToString(&description_)) { | 377 if (desc->ToString(&description_)) { |
| 389 holder_->connection()->SetLocalDescription(this, desc); | 378 holder_->connection()->SetLocalDescription(this, desc); |
| 390 } else { | 379 } else { |
| 391 OnFailure("Can't serialize session description"); | 380 OnFailure("Can't serialize session description"); |
| 392 } | 381 } |
| 393 } | 382 } |
| 394 | 383 |
| 395 virtual void OnSuccess() override { | 384 void OnSuccess() override { |
| 396 if (holder_->IsDisposed()) return; | 385 if (holder_->IsDisposed()) return; |
| 397 | 386 |
| 398 if (type_ == webrtc::SessionDescriptionInterface::kOffer) { | 387 if (type_ == webrtc::SessionDescriptionInterface::kOffer) { |
| 399 holder_->delegate()->OnLocalOfferCreatedAndSetSet(description_); | 388 holder_->delegate()->OnLocalOfferCreatedAndSetSet(description_); |
| 400 } else { | 389 } else { |
| 401 DCHECK_EQ(webrtc::SessionDescriptionInterface::kAnswer, type_); | 390 DCHECK_EQ(webrtc::SessionDescriptionInterface::kAnswer, type_); |
| 402 | 391 |
| 403 holder_->delegate()->OnLocalAnswerCreatedAndSetSet(description_); | 392 holder_->delegate()->OnLocalAnswerCreatedAndSetSet(description_); |
| 404 } | 393 } |
| 405 } | 394 } |
| 406 | 395 |
| 407 virtual void OnFailure(const std::string& error) override { | 396 void OnFailure(const std::string& error) override { |
| 408 if (holder_->IsDisposed()) return; | 397 if (holder_->IsDisposed()) return; |
| 409 | 398 |
| 410 holder_->delegate()->OnFailure(error); | 399 holder_->delegate()->OnFailure(error); |
| 411 } | 400 } |
| 412 | 401 |
| 413 private: | 402 private: |
| 414 const rtc::scoped_refptr<PeerConnectionHolder> holder_; | 403 const rtc::scoped_refptr<PeerConnectionHolder> holder_; |
| 415 std::string type_; | 404 std::string type_; |
| 416 std::string description_; | 405 std::string description_; |
| 417 }; | 406 }; |
| 418 | 407 |
| 419 class SetRemoteDescriptionHandler | 408 class SetRemoteDescriptionHandler |
| 420 : public webrtc::SetSessionDescriptionObserver { | 409 : public webrtc::SetSessionDescriptionObserver { |
| 421 public: | 410 public: |
| 422 SetRemoteDescriptionHandler( | 411 SetRemoteDescriptionHandler( |
| 423 rtc::scoped_refptr<PeerConnectionHolder> holder) | 412 rtc::scoped_refptr<PeerConnectionHolder> holder) |
| 424 : holder_(holder) { | 413 : holder_(holder) { |
| 425 } | 414 } |
| 426 | 415 |
| 427 virtual void OnSuccess() override { | 416 void OnSuccess() override { |
| 428 if (holder_->IsDisposed()) return; | 417 if (holder_->IsDisposed()) return; |
| 429 | 418 |
| 430 holder_->delegate()->OnRemoteDescriptionSet(); | 419 holder_->delegate()->OnRemoteDescriptionSet(); |
| 431 } | 420 } |
| 432 | 421 |
| 433 virtual void OnFailure(const std::string& error) override { | 422 void OnFailure(const std::string& error) override { |
| 434 if (holder_->IsDisposed()) return; | 423 if (holder_->IsDisposed()) return; |
| 435 | 424 |
| 436 holder_->delegate()->OnFailure(error); | 425 holder_->delegate()->OnFailure(error); |
| 437 } | 426 } |
| 438 | 427 |
| 439 private: | 428 private: |
| 440 const rtc::scoped_refptr<PeerConnectionHolder> holder_; | 429 const rtc::scoped_refptr<PeerConnectionHolder> holder_; |
| 441 }; | 430 }; |
| 442 | 431 |
| 443 class PeerConnectionImpl : public AbstractPeerConnection { | 432 class PeerConnectionImpl : public AbstractPeerConnection { |
| 444 public: | 433 public: |
| 445 PeerConnectionImpl( | 434 PeerConnectionImpl( |
| 446 SessionDependencyFactory* const factory, | 435 SessionDependencyFactory* const factory, |
| 447 rtc::Thread* signaling_thread, | 436 rtc::Thread* signaling_thread, |
| 448 rtc::scoped_refptr<webrtc::PeerConnectionInterface> connection, | 437 rtc::scoped_refptr<webrtc::PeerConnectionInterface> connection, |
| 449 scoped_ptr<PeerConnectionObserverImpl> observer, | 438 scoped_ptr<PeerConnectionObserverImpl> observer, |
| 450 scoped_ptr<AbstractPeerConnection::Delegate> delegate) | 439 scoped_ptr<AbstractPeerConnection::Delegate> delegate) |
| 451 : factory_(factory), | 440 : factory_(factory), |
| 452 holder_(new rtc::RefCountedObject<PeerConnectionHolder>( | 441 holder_(new rtc::RefCountedObject<PeerConnectionHolder>( |
| 453 signaling_thread, connection.get(), delegate.get())), | 442 signaling_thread, connection.get(), delegate.get())), |
| 454 signaling_thread_(signaling_thread), | 443 signaling_thread_(signaling_thread), |
| 455 connection_(connection), | 444 connection_(connection), |
| 456 observer_(observer.Pass()), | 445 observer_(observer.Pass()), |
| 457 delegate_(delegate.Pass()) { | 446 delegate_(delegate.Pass()) { |
| 458 } | 447 } |
| 459 | 448 |
| 460 virtual ~PeerConnectionImpl() { | 449 ~PeerConnectionImpl() override { |
| 461 signaling_thread_->Invoke<void>(rtc::Bind( | 450 signaling_thread_->Invoke<void>(rtc::Bind( |
| 462 &PeerConnectionImpl::DisposeOnSignalingThread, this)); | 451 &PeerConnectionImpl::DisposeOnSignalingThread, this)); |
| 463 } | 452 } |
| 464 | 453 |
| 465 virtual void CreateAndSetLocalOffer() override { | 454 void CreateAndSetLocalOffer() override { |
| 466 connection_->CreateOffer(MakeCreateAndSetHandler(), NULL); | 455 connection_->CreateOffer(MakeCreateAndSetHandler(), NULL); |
| 467 } | 456 } |
| 468 | 457 |
| 469 virtual void CreateAndSetLocalAnswer() override { | 458 void CreateAndSetLocalAnswer() override { |
| 470 connection_->CreateAnswer(MakeCreateAndSetHandler(), NULL); | 459 connection_->CreateAnswer(MakeCreateAndSetHandler(), NULL); |
| 471 } | 460 } |
| 472 | 461 |
| 473 virtual void SetRemoteOffer(const std::string& description) override { | 462 void SetRemoteOffer(const std::string& description) override { |
| 474 SetRemoteDescription( | 463 SetRemoteDescription( |
| 475 webrtc::SessionDescriptionInterface::kOffer, description); | 464 webrtc::SessionDescriptionInterface::kOffer, description); |
| 476 } | 465 } |
| 477 | 466 |
| 478 virtual void SetRemoteAnswer(const std::string& description) override { | 467 void SetRemoteAnswer(const std::string& description) override { |
| 479 SetRemoteDescription( | 468 SetRemoteDescription( |
| 480 webrtc::SessionDescriptionInterface::kAnswer, description); | 469 webrtc::SessionDescriptionInterface::kAnswer, description); |
| 481 } | 470 } |
| 482 | 471 |
| 483 void SetRemoteDescription( | 472 void SetRemoteDescription( |
| 484 const std::string& type, const std::string& description) { | 473 const std::string& type, const std::string& description) { |
| 485 webrtc::SdpParseError error; | 474 webrtc::SdpParseError error; |
| 486 scoped_ptr<webrtc::SessionDescriptionInterface> value( | 475 scoped_ptr<webrtc::SessionDescriptionInterface> value( |
| 487 webrtc::CreateSessionDescription(type, description, &error)); | 476 webrtc::CreateSessionDescription(type, description, &error)); |
| 488 if (value == NULL) { | 477 if (value == NULL) { |
| 489 OnParseError(error); | 478 OnParseError(error); |
| 490 return; | 479 return; |
| 491 } | 480 } |
| 492 // Takes ownership on |value|. | 481 // Takes ownership on |value|. |
| 493 connection_->SetRemoteDescription( | 482 connection_->SetRemoteDescription( |
| 494 new rtc::RefCountedObject<SetRemoteDescriptionHandler>(holder_), | 483 new rtc::RefCountedObject<SetRemoteDescriptionHandler>(holder_), |
| 495 value.release()); | 484 value.release()); |
| 496 } | 485 } |
| 497 | 486 |
| 498 virtual void AddIceCandidate( | 487 void AddIceCandidate(const std::string& sdp_mid, |
| 499 const std::string& sdp_mid, | 488 int sdp_mline_index, |
| 500 int sdp_mline_index, | 489 const std::string& sdp) override { |
| 501 const std::string& sdp) override { | |
| 502 webrtc::SdpParseError error; | 490 webrtc::SdpParseError error; |
| 503 auto candidate = webrtc::CreateIceCandidate( | 491 auto candidate = webrtc::CreateIceCandidate( |
| 504 sdp_mid, sdp_mline_index, sdp, &error); | 492 sdp_mid, sdp_mline_index, sdp, &error); |
| 505 if (candidate == NULL) { | 493 if (candidate == NULL) { |
| 506 OnParseError(error); | 494 OnParseError(error); |
| 507 return; | 495 return; |
| 508 } | 496 } |
| 509 // Doesn't takes ownership. | 497 // Doesn't takes ownership. |
| 510 connection_->AddIceCandidate(candidate); | 498 connection_->AddIceCandidate(candidate); |
| 511 delete candidate; | 499 delete candidate; |
| 512 } | 500 } |
| 513 | 501 |
| 514 virtual scoped_ptr<AbstractDataChannel> CreateDataChannel( | 502 scoped_ptr<AbstractDataChannel> CreateDataChannel(int channelId) override { |
| 515 int channelId) override { | |
| 516 webrtc::DataChannelInit init; | 503 webrtc::DataChannelInit init; |
| 517 init.ordered = true; | 504 init.ordered = true; |
| 518 init.negotiated = true; | 505 init.negotiated = true; |
| 519 init.id = channelId; | 506 init.id = channelId; |
| 520 | 507 |
| 521 return make_scoped_ptr(new DataChannelImpl( | 508 return make_scoped_ptr(new DataChannelImpl( |
| 522 factory_, | 509 factory_, |
| 523 signaling_thread_, | 510 signaling_thread_, |
| 524 connection_->CreateDataChannel("", &init))); | 511 connection_->CreateDataChannel("", &init))); |
| 525 } | 512 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 555 : cleanup_on_signaling_thread_(cleanup_on_signaling_thread) { | 542 : cleanup_on_signaling_thread_(cleanup_on_signaling_thread) { |
| 556 signaling_thread_.SetName("signaling_thread", NULL); | 543 signaling_thread_.SetName("signaling_thread", NULL); |
| 557 signaling_thread_.Start(); | 544 signaling_thread_.Start(); |
| 558 worker_thread_.SetName("worker_thread", NULL); | 545 worker_thread_.SetName("worker_thread", NULL); |
| 559 worker_thread_.Start(); | 546 worker_thread_.Start(); |
| 560 | 547 |
| 561 factory_ = webrtc::CreatePeerConnectionFactory( | 548 factory_ = webrtc::CreatePeerConnectionFactory( |
| 562 &worker_thread_, &signaling_thread_, NULL, NULL, NULL); | 549 &worker_thread_, &signaling_thread_, NULL, NULL, NULL); |
| 563 } | 550 } |
| 564 | 551 |
| 565 virtual ~SessionDependencyFactoryImpl() { | 552 ~SessionDependencyFactoryImpl() override { |
| 566 if (signaling_thread_task_runner_.get()) | 553 if (signaling_thread_task_runner_.get()) |
| 567 signaling_thread_task_runner_->Stop(); | 554 signaling_thread_task_runner_->Stop(); |
| 568 | 555 |
| 569 signaling_thread_.Invoke<void>(rtc::Bind( | 556 signaling_thread_.Invoke<void>(rtc::Bind( |
| 570 &SessionDependencyFactoryImpl::DisposeOnSignalingThread, this)); | 557 &SessionDependencyFactoryImpl::DisposeOnSignalingThread, this)); |
| 571 } | 558 } |
| 572 | 559 |
| 573 virtual scoped_ptr<AbstractPeerConnection> CreatePeerConnection( | 560 scoped_ptr<AbstractPeerConnection> CreatePeerConnection( |
| 574 scoped_ptr<RTCConfiguration> config, | 561 scoped_ptr<RTCConfiguration> config, |
| 575 scoped_ptr<AbstractPeerConnection::Delegate> delegate) override { | 562 scoped_ptr<AbstractPeerConnection::Delegate> delegate) override { |
| 576 auto observer = make_scoped_ptr( | 563 auto observer = make_scoped_ptr( |
| 577 new PeerConnectionObserverImpl(delegate.get())); | 564 new PeerConnectionObserverImpl(delegate.get())); |
| 578 | 565 |
| 579 MediaConstraints constraints; | 566 MediaConstraints constraints; |
| 580 constraints.AddMandatory( | 567 constraints.AddMandatory( |
| 581 MediaConstraints::kEnableDtlsSrtp, MediaConstraints::kValueTrue); | 568 MediaConstraints::kEnableDtlsSrtp, MediaConstraints::kValueTrue); |
| 582 | 569 |
| 583 auto connection = factory_->CreatePeerConnection( | 570 auto connection = factory_->CreatePeerConnection( |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 } | 631 } |
| 645 | 632 |
| 646 // static | 633 // static |
| 647 scoped_ptr<SessionDependencyFactory> SessionDependencyFactory::CreateInstance( | 634 scoped_ptr<SessionDependencyFactory> SessionDependencyFactory::CreateInstance( |
| 648 const base::Closure& cleanup_on_signaling_thread) { | 635 const base::Closure& cleanup_on_signaling_thread) { |
| 649 return make_scoped_ptr(new SessionDependencyFactoryImpl( | 636 return make_scoped_ptr(new SessionDependencyFactoryImpl( |
| 650 cleanup_on_signaling_thread)); | 637 cleanup_on_signaling_thread)); |
| 651 } | 638 } |
| 652 | 639 |
| 653 } // namespace devtools_bridge | 640 } // namespace devtools_bridge |
| OLD | NEW |