| 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 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 using webrtc::DataChannelInterface; | 43 using webrtc::DataChannelInterface; |
| 44 using webrtc::IceCandidateInterface; | 44 using webrtc::IceCandidateInterface; |
| 45 using webrtc::MediaStreamInterface; | 45 using webrtc::MediaStreamInterface; |
| 46 using webrtc::PeerConnectionInterface; | 46 using webrtc::PeerConnectionInterface; |
| 47 using webrtc::PeerConnectionObserver; | 47 using webrtc::PeerConnectionObserver; |
| 48 using webrtc::StatsReport; | 48 using webrtc::StatsReport; |
| 49 using webrtc::StatsReportCopyable; | 49 using webrtc::StatsReportCopyable; |
| 50 using webrtc::StatsReports; | 50 using webrtc::StatsReports; |
| 51 | 51 |
| 52 namespace content { | 52 namespace content { |
| 53 namespace { |
| 53 | 54 |
| 54 // Converter functions from libjingle types to WebKit types. | 55 // Converter functions from libjingle types to WebKit types. |
| 55 blink::WebRTCPeerConnectionHandlerClient::ICEGatheringState | 56 blink::WebRTCPeerConnectionHandlerClient::ICEGatheringState |
| 56 GetWebKitIceGatheringState( | 57 GetWebKitIceGatheringState( |
| 57 webrtc::PeerConnectionInterface::IceGatheringState state) { | 58 webrtc::PeerConnectionInterface::IceGatheringState state) { |
| 58 using blink::WebRTCPeerConnectionHandlerClient; | 59 using blink::WebRTCPeerConnectionHandlerClient; |
| 59 switch (state) { | 60 switch (state) { |
| 60 case webrtc::PeerConnectionInterface::kIceGatheringNew: | 61 case webrtc::PeerConnectionInterface::kIceGatheringNew: |
| 61 return WebRTCPeerConnectionHandlerClient::ICEGatheringStateNew; | 62 return WebRTCPeerConnectionHandlerClient::ICEGatheringStateNew; |
| 62 case webrtc::PeerConnectionInterface::kIceGatheringGathering: | 63 case webrtc::PeerConnectionInterface::kIceGatheringGathering: |
| 63 return WebRTCPeerConnectionHandlerClient::ICEGatheringStateGathering; | 64 return WebRTCPeerConnectionHandlerClient::ICEGatheringStateGathering; |
| 64 case webrtc::PeerConnectionInterface::kIceGatheringComplete: | 65 case webrtc::PeerConnectionInterface::kIceGatheringComplete: |
| 65 return WebRTCPeerConnectionHandlerClient::ICEGatheringStateComplete; | 66 return WebRTCPeerConnectionHandlerClient::ICEGatheringStateComplete; |
| 66 default: | 67 default: |
| 67 NOTREACHED(); | 68 NOTREACHED(); |
| 68 return WebRTCPeerConnectionHandlerClient::ICEGatheringStateNew; | 69 return WebRTCPeerConnectionHandlerClient::ICEGatheringStateNew; |
| 69 } | 70 } |
| 70 } | 71 } |
| 71 | 72 |
| 72 static blink::WebRTCPeerConnectionHandlerClient::ICEConnectionState | 73 blink::WebRTCPeerConnectionHandlerClient::ICEConnectionState |
| 73 GetWebKitIceConnectionState( | 74 GetWebKitIceConnectionState( |
| 74 webrtc::PeerConnectionInterface::IceConnectionState ice_state) { | 75 webrtc::PeerConnectionInterface::IceConnectionState ice_state) { |
| 75 using blink::WebRTCPeerConnectionHandlerClient; | 76 using blink::WebRTCPeerConnectionHandlerClient; |
| 76 switch (ice_state) { | 77 switch (ice_state) { |
| 77 case webrtc::PeerConnectionInterface::kIceConnectionNew: | 78 case webrtc::PeerConnectionInterface::kIceConnectionNew: |
| 78 return WebRTCPeerConnectionHandlerClient::ICEConnectionStateStarting; | 79 return WebRTCPeerConnectionHandlerClient::ICEConnectionStateStarting; |
| 79 case webrtc::PeerConnectionInterface::kIceConnectionChecking: | 80 case webrtc::PeerConnectionInterface::kIceConnectionChecking: |
| 80 return WebRTCPeerConnectionHandlerClient::ICEConnectionStateChecking; | 81 return WebRTCPeerConnectionHandlerClient::ICEConnectionStateChecking; |
| 81 case webrtc::PeerConnectionInterface::kIceConnectionConnected: | 82 case webrtc::PeerConnectionInterface::kIceConnectionConnected: |
| 82 return WebRTCPeerConnectionHandlerClient::ICEConnectionStateConnected; | 83 return WebRTCPeerConnectionHandlerClient::ICEConnectionStateConnected; |
| 83 case webrtc::PeerConnectionInterface::kIceConnectionCompleted: | 84 case webrtc::PeerConnectionInterface::kIceConnectionCompleted: |
| 84 return WebRTCPeerConnectionHandlerClient::ICEConnectionStateCompleted; | 85 return WebRTCPeerConnectionHandlerClient::ICEConnectionStateCompleted; |
| 85 case webrtc::PeerConnectionInterface::kIceConnectionFailed: | 86 case webrtc::PeerConnectionInterface::kIceConnectionFailed: |
| 86 return WebRTCPeerConnectionHandlerClient::ICEConnectionStateFailed; | 87 return WebRTCPeerConnectionHandlerClient::ICEConnectionStateFailed; |
| 87 case webrtc::PeerConnectionInterface::kIceConnectionDisconnected: | 88 case webrtc::PeerConnectionInterface::kIceConnectionDisconnected: |
| 88 return WebRTCPeerConnectionHandlerClient::ICEConnectionStateDisconnected; | 89 return WebRTCPeerConnectionHandlerClient::ICEConnectionStateDisconnected; |
| 89 case webrtc::PeerConnectionInterface::kIceConnectionClosed: | 90 case webrtc::PeerConnectionInterface::kIceConnectionClosed: |
| 90 return WebRTCPeerConnectionHandlerClient::ICEConnectionStateClosed; | 91 return WebRTCPeerConnectionHandlerClient::ICEConnectionStateClosed; |
| 91 default: | 92 default: |
| 92 NOTREACHED(); | 93 NOTREACHED(); |
| 93 return WebRTCPeerConnectionHandlerClient::ICEConnectionStateClosed; | 94 return WebRTCPeerConnectionHandlerClient::ICEConnectionStateClosed; |
| 94 } | 95 } |
| 95 } | 96 } |
| 96 | 97 |
| 97 static blink::WebRTCPeerConnectionHandlerClient::SignalingState | 98 blink::WebRTCPeerConnectionHandlerClient::SignalingState |
| 98 GetWebKitSignalingState(webrtc::PeerConnectionInterface::SignalingState state) { | 99 GetWebKitSignalingState(webrtc::PeerConnectionInterface::SignalingState state) { |
| 99 using blink::WebRTCPeerConnectionHandlerClient; | 100 using blink::WebRTCPeerConnectionHandlerClient; |
| 100 switch (state) { | 101 switch (state) { |
| 101 case webrtc::PeerConnectionInterface::kStable: | 102 case webrtc::PeerConnectionInterface::kStable: |
| 102 return WebRTCPeerConnectionHandlerClient::SignalingStateStable; | 103 return WebRTCPeerConnectionHandlerClient::SignalingStateStable; |
| 103 case webrtc::PeerConnectionInterface::kHaveLocalOffer: | 104 case webrtc::PeerConnectionInterface::kHaveLocalOffer: |
| 104 return WebRTCPeerConnectionHandlerClient::SignalingStateHaveLocalOffer; | 105 return WebRTCPeerConnectionHandlerClient::SignalingStateHaveLocalOffer; |
| 105 case webrtc::PeerConnectionInterface::kHaveLocalPrAnswer: | 106 case webrtc::PeerConnectionInterface::kHaveLocalPrAnswer: |
| 106 return WebRTCPeerConnectionHandlerClient::SignalingStateHaveLocalPrAnswer; | 107 return WebRTCPeerConnectionHandlerClient::SignalingStateHaveLocalPrAnswer; |
| 107 case webrtc::PeerConnectionInterface::kHaveRemoteOffer: | 108 case webrtc::PeerConnectionInterface::kHaveRemoteOffer: |
| 108 return WebRTCPeerConnectionHandlerClient::SignalingStateHaveRemoteOffer; | 109 return WebRTCPeerConnectionHandlerClient::SignalingStateHaveRemoteOffer; |
| 109 case webrtc::PeerConnectionInterface::kHaveRemotePrAnswer: | 110 case webrtc::PeerConnectionInterface::kHaveRemotePrAnswer: |
| 110 return | 111 return |
| 111 WebRTCPeerConnectionHandlerClient::SignalingStateHaveRemotePrAnswer; | 112 WebRTCPeerConnectionHandlerClient::SignalingStateHaveRemotePrAnswer; |
| 112 case webrtc::PeerConnectionInterface::kClosed: | 113 case webrtc::PeerConnectionInterface::kClosed: |
| 113 return WebRTCPeerConnectionHandlerClient::SignalingStateClosed; | 114 return WebRTCPeerConnectionHandlerClient::SignalingStateClosed; |
| 114 default: | 115 default: |
| 115 NOTREACHED(); | 116 NOTREACHED(); |
| 116 return WebRTCPeerConnectionHandlerClient::SignalingStateClosed; | 117 return WebRTCPeerConnectionHandlerClient::SignalingStateClosed; |
| 117 } | 118 } |
| 118 } | 119 } |
| 119 | 120 |
| 120 static blink::WebRTCSessionDescription | 121 blink::WebRTCSessionDescription CreateWebKitSessionDescription( |
| 122 const std::string& sdp, const std::string& type) { |
| 123 blink::WebRTCSessionDescription description; |
| 124 description.initialize(base::UTF8ToUTF16(type), base::UTF8ToUTF16(sdp)); |
| 125 return description; |
| 126 } |
| 127 |
| 128 blink::WebRTCSessionDescription |
| 121 CreateWebKitSessionDescription( | 129 CreateWebKitSessionDescription( |
| 122 const webrtc::SessionDescriptionInterface* native_desc) { | 130 const webrtc::SessionDescriptionInterface* native_desc) { |
| 123 blink::WebRTCSessionDescription description; | |
| 124 if (!native_desc) { | 131 if (!native_desc) { |
| 125 LOG(ERROR) << "Native session description is null."; | 132 LOG(ERROR) << "Native session description is null."; |
| 126 return description; | 133 return blink::WebRTCSessionDescription(); |
| 127 } | 134 } |
| 128 | 135 |
| 129 std::string sdp; | 136 std::string sdp; |
| 130 if (!native_desc->ToString(&sdp)) { | 137 if (!native_desc->ToString(&sdp)) { |
| 131 LOG(ERROR) << "Failed to get SDP string of native session description."; | 138 LOG(ERROR) << "Failed to get SDP string of native session description."; |
| 132 return description; | 139 return blink::WebRTCSessionDescription(); |
| 133 } | 140 } |
| 134 | 141 |
| 135 description.initialize(base::UTF8ToUTF16(native_desc->type()), | 142 return CreateWebKitSessionDescription(sdp, native_desc->type()); |
| 136 base::UTF8ToUTF16(sdp)); | 143 } |
| 137 return description; | 144 |
| 145 void RunClosureWithTrace(const base::Closure& closure, |
| 146 const char* trace_event_name) { |
| 147 TRACE_EVENT0("webrtc", trace_event_name); |
| 148 closure.Run(); |
| 149 } |
| 150 |
| 151 void RunSynchronousClosure(const base::Closure& closure, |
| 152 const char* trace_event_name, |
| 153 base::WaitableEvent* event) { |
| 154 { |
| 155 TRACE_EVENT0("webrtc", trace_event_name); |
| 156 closure.Run(); |
| 157 } |
| 158 event->Signal(); |
| 159 } |
| 160 |
| 161 void GetSdpAndTypeFromSessionDescription( |
| 162 const base::Callback<const webrtc::SessionDescriptionInterface*()>& |
| 163 description_callback, |
| 164 std::string* sdp, std::string* type) { |
| 165 const webrtc::SessionDescriptionInterface* description = |
| 166 description_callback.Run(); |
| 167 if (description) { |
| 168 description->ToString(sdp); |
| 169 *type = description->type(); |
| 170 } |
| 138 } | 171 } |
| 139 | 172 |
| 140 // Converter functions from WebKit types to libjingle types. | 173 // Converter functions from WebKit types to libjingle types. |
| 141 | 174 |
| 142 static void GetNativeRtcConfiguration( | 175 void GetNativeRtcConfiguration( |
| 143 const blink::WebRTCConfiguration& server_configuration, | 176 const blink::WebRTCConfiguration& server_configuration, |
| 144 webrtc::PeerConnectionInterface::RTCConfiguration* config) { | 177 webrtc::PeerConnectionInterface::RTCConfiguration* config) { |
| 145 if (server_configuration.isNull() || !config) | 178 if (server_configuration.isNull() || !config) |
| 146 return; | 179 return; |
| 147 for (size_t i = 0; i < server_configuration.numberOfServers(); ++i) { | 180 for (size_t i = 0; i < server_configuration.numberOfServers(); ++i) { |
| 148 webrtc::PeerConnectionInterface::IceServer server; | 181 webrtc::PeerConnectionInterface::IceServer server; |
| 149 const blink::WebRTCICEServer& webkit_server = | 182 const blink::WebRTCICEServer& webkit_server = |
| 150 server_configuration.server(i); | 183 server_configuration.server(i); |
| 151 server.username = base::UTF16ToUTF8(webkit_server.username()); | 184 server.username = base::UTF16ToUTF8(webkit_server.username()); |
| 152 server.password = base::UTF16ToUTF8(webkit_server.credential()); | 185 server.password = base::UTF16ToUTF8(webkit_server.credential()); |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 303 : request_(request.get()), | 336 : request_(request.get()), |
| 304 main_thread_(base::ThreadTaskRunnerHandle::Get()) { | 337 main_thread_(base::ThreadTaskRunnerHandle::Get()) { |
| 305 // Measure the overall time it takes to satisfy a getStats request. | 338 // Measure the overall time it takes to satisfy a getStats request. |
| 306 TRACE_EVENT_ASYNC_BEGIN0("webrtc", "getStats_Native", this); | 339 TRACE_EVENT_ASYNC_BEGIN0("webrtc", "getStats_Native", this); |
| 307 signaling_thread_checker_.DetachFromThread(); | 340 signaling_thread_checker_.DetachFromThread(); |
| 308 } | 341 } |
| 309 | 342 |
| 310 void OnComplete(const StatsReports& reports) override { | 343 void OnComplete(const StatsReports& reports) override { |
| 311 DCHECK(signaling_thread_checker_.CalledOnValidThread()); | 344 DCHECK(signaling_thread_checker_.CalledOnValidThread()); |
| 312 TRACE_EVENT0("webrtc", "StatsResponse::OnComplete"); | 345 TRACE_EVENT0("webrtc", "StatsResponse::OnComplete"); |
| 313 // TODO(tommi): Get rid of these string copies some how. | 346 // TODO(tommi): Get rid of these string copies somehow. |
| 314 // We can't use webkit objects directly since they use a single threaded | 347 // We can't use webkit objects directly since they use a single threaded |
| 315 // heap allocator. | 348 // heap allocator. |
| 316 scoped_ptr<std::vector<StatsReportCopyable>> report_copies( | 349 scoped_ptr<std::vector<StatsReportCopyable>> report_copies( |
| 317 new std::vector<StatsReportCopyable>()); | 350 new std::vector<StatsReportCopyable>()); |
| 318 report_copies->reserve(reports.size()); | 351 report_copies->reserve(reports.size()); |
| 319 for (auto it : reports) | 352 for (auto it : reports) |
| 320 report_copies->push_back(StatsReportCopyable(*it)); | 353 report_copies->push_back(StatsReportCopyable(*it)); |
| 321 | 354 |
| 322 main_thread_->PostTask(FROM_HERE, | 355 main_thread_->PostTask(FROM_HERE, |
| 323 base::Bind(&StatsResponse::DeliverCallback, this, | 356 base::Bind(&StatsResponse::DeliverCallback, this, |
| (...skipping 28 matching lines...) Expand all Loading... |
| 352 blink::WebString::fromUTF8(value.display_name()), | 385 blink::WebString::fromUTF8(value.display_name()), |
| 353 blink::WebString::fromUTF8(value.value)); | 386 blink::WebString::fromUTF8(value.value)); |
| 354 } | 387 } |
| 355 } | 388 } |
| 356 | 389 |
| 357 rtc::scoped_refptr<LocalRTCStatsRequest> request_; | 390 rtc::scoped_refptr<LocalRTCStatsRequest> request_; |
| 358 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_; | 391 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_; |
| 359 base::ThreadChecker signaling_thread_checker_; | 392 base::ThreadChecker signaling_thread_checker_; |
| 360 }; | 393 }; |
| 361 | 394 |
| 362 // Implementation of LocalRTCStatsRequest. | |
| 363 LocalRTCStatsRequest::LocalRTCStatsRequest(blink::WebRTCStatsRequest impl) | |
| 364 : impl_(impl) { | |
| 365 } | |
| 366 | |
| 367 LocalRTCStatsRequest::LocalRTCStatsRequest() {} | |
| 368 LocalRTCStatsRequest::~LocalRTCStatsRequest() {} | |
| 369 | |
| 370 bool LocalRTCStatsRequest::hasSelector() const { | |
| 371 return impl_.hasSelector(); | |
| 372 } | |
| 373 | |
| 374 blink::WebMediaStreamTrack LocalRTCStatsRequest::component() const { | |
| 375 return impl_.component(); | |
| 376 } | |
| 377 | |
| 378 scoped_refptr<LocalRTCStatsResponse> LocalRTCStatsRequest::createResponse() { | |
| 379 return scoped_refptr<LocalRTCStatsResponse>( | |
| 380 new rtc::RefCountedObject<LocalRTCStatsResponse>(impl_.createResponse())); | |
| 381 } | |
| 382 | |
| 383 void LocalRTCStatsRequest::requestSucceeded( | |
| 384 const LocalRTCStatsResponse* response) { | |
| 385 impl_.requestSucceeded(response->webKitStatsResponse()); | |
| 386 } | |
| 387 | |
| 388 // Implementation of LocalRTCStatsResponse. | |
| 389 blink::WebRTCStatsResponse LocalRTCStatsResponse::webKitStatsResponse() const { | |
| 390 return impl_; | |
| 391 } | |
| 392 | |
| 393 size_t LocalRTCStatsResponse::addReport(blink::WebString type, | |
| 394 blink::WebString id, | |
| 395 double timestamp) { | |
| 396 return impl_.addReport(type, id, timestamp); | |
| 397 } | |
| 398 | |
| 399 void LocalRTCStatsResponse::addStatistic(size_t report, | |
| 400 blink::WebString name, | |
| 401 blink::WebString value) { | |
| 402 impl_.addStatistic(report, name, value); | |
| 403 } | |
| 404 | |
| 405 namespace { | |
| 406 | |
| 407 void GetStatsOnSignalingThread( | 395 void GetStatsOnSignalingThread( |
| 408 const scoped_refptr<webrtc::PeerConnectionInterface>& pc, | 396 const scoped_refptr<webrtc::PeerConnectionInterface>& pc, |
| 409 webrtc::PeerConnectionInterface::StatsOutputLevel level, | 397 webrtc::PeerConnectionInterface::StatsOutputLevel level, |
| 410 const scoped_refptr<webrtc::StatsObserver>& observer, | 398 const scoped_refptr<webrtc::StatsObserver>& observer, |
| 411 const std::string track_id, blink::WebMediaStreamSource::Type track_type) { | 399 const std::string track_id, blink::WebMediaStreamSource::Type track_type) { |
| 412 TRACE_EVENT0("webrtc", "GetStatsOnSignalingThread"); | 400 TRACE_EVENT0("webrtc", "GetStatsOnSignalingThread"); |
| 413 | 401 |
| 414 scoped_refptr<webrtc::MediaStreamTrackInterface> track; | 402 scoped_refptr<webrtc::MediaStreamTrackInterface> track; |
| 415 if (!track_id.empty()) { | 403 if (!track_id.empty()) { |
| 416 if (track_type == blink::WebMediaStreamSource::TypeAudio) { | 404 if (track_type == blink::WebMediaStreamSource::TypeAudio) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 471 NOTREACHED(); | 459 NOTREACHED(); |
| 472 } | 460 } |
| 473 } | 461 } |
| 474 }; | 462 }; |
| 475 | 463 |
| 476 base::LazyInstance<std::set<RTCPeerConnectionHandler*> >::Leaky | 464 base::LazyInstance<std::set<RTCPeerConnectionHandler*> >::Leaky |
| 477 g_peer_connection_handlers = LAZY_INSTANCE_INITIALIZER; | 465 g_peer_connection_handlers = LAZY_INSTANCE_INITIALIZER; |
| 478 | 466 |
| 479 } // namespace | 467 } // namespace |
| 480 | 468 |
| 469 // Implementation of LocalRTCStatsRequest. |
| 470 LocalRTCStatsRequest::LocalRTCStatsRequest(blink::WebRTCStatsRequest impl) |
| 471 : impl_(impl) { |
| 472 } |
| 473 |
| 474 LocalRTCStatsRequest::LocalRTCStatsRequest() {} |
| 475 LocalRTCStatsRequest::~LocalRTCStatsRequest() {} |
| 476 |
| 477 bool LocalRTCStatsRequest::hasSelector() const { |
| 478 return impl_.hasSelector(); |
| 479 } |
| 480 |
| 481 blink::WebMediaStreamTrack LocalRTCStatsRequest::component() const { |
| 482 return impl_.component(); |
| 483 } |
| 484 |
| 485 scoped_refptr<LocalRTCStatsResponse> LocalRTCStatsRequest::createResponse() { |
| 486 return scoped_refptr<LocalRTCStatsResponse>( |
| 487 new rtc::RefCountedObject<LocalRTCStatsResponse>(impl_.createResponse())); |
| 488 } |
| 489 |
| 490 void LocalRTCStatsRequest::requestSucceeded( |
| 491 const LocalRTCStatsResponse* response) { |
| 492 impl_.requestSucceeded(response->webKitStatsResponse()); |
| 493 } |
| 494 |
| 495 // Implementation of LocalRTCStatsResponse. |
| 496 blink::WebRTCStatsResponse LocalRTCStatsResponse::webKitStatsResponse() const { |
| 497 return impl_; |
| 498 } |
| 499 |
| 500 size_t LocalRTCStatsResponse::addReport(blink::WebString type, |
| 501 blink::WebString id, |
| 502 double timestamp) { |
| 503 return impl_.addReport(type, id, timestamp); |
| 504 } |
| 505 |
| 506 void LocalRTCStatsResponse::addStatistic(size_t report, |
| 507 blink::WebString name, |
| 508 blink::WebString value) { |
| 509 impl_.addStatistic(report, name, value); |
| 510 } |
| 511 |
| 481 // Receives notifications from a PeerConnection object about state changes, | 512 // Receives notifications from a PeerConnection object about state changes, |
| 482 // track addition/removal etc. The callbacks we receive here come on the | 513 // track addition/removal etc. The callbacks we receive here come on the |
| 483 // signaling thread, so this class takes care of delivering them to an | 514 // signaling thread, so this class takes care of delivering them to an |
| 484 // RTCPeerConnectionHandler instance on the main thread. | 515 // RTCPeerConnectionHandler instance on the main thread. |
| 485 // In order to do safe PostTask-ing, the class is reference counted and | 516 // In order to do safe PostTask-ing, the class is reference counted and |
| 486 // checks for the existence of the RTCPeerConnectionHandler instance before | 517 // checks for the existence of the RTCPeerConnectionHandler instance before |
| 487 // delivering callbacks on the main thread. | 518 // delivering callbacks on the main thread. |
| 488 class RTCPeerConnectionHandler::Observer | 519 class RTCPeerConnectionHandler::Observer |
| 489 : public base::RefCountedThreadSafe<RTCPeerConnectionHandler::Observer>, | 520 : public base::RefCountedThreadSafe<RTCPeerConnectionHandler::Observer>, |
| 490 public PeerConnectionObserver { | 521 public PeerConnectionObserver { |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 610 } | 641 } |
| 611 } | 642 } |
| 612 | 643 |
| 613 private: | 644 private: |
| 614 const base::WeakPtr<RTCPeerConnectionHandler> handler_; | 645 const base::WeakPtr<RTCPeerConnectionHandler> handler_; |
| 615 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_; | 646 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_; |
| 616 }; | 647 }; |
| 617 | 648 |
| 618 RTCPeerConnectionHandler::RTCPeerConnectionHandler( | 649 RTCPeerConnectionHandler::RTCPeerConnectionHandler( |
| 619 blink::WebRTCPeerConnectionHandlerClient* client, | 650 blink::WebRTCPeerConnectionHandlerClient* client, |
| 620 PeerConnectionDependencyFactory* dependency_factory, | 651 PeerConnectionDependencyFactory* dependency_factory) |
| 621 const scoped_refptr<base::SingleThreadTaskRunner>& signaling_thread) | |
| 622 : client_(client), | 652 : client_(client), |
| 623 dependency_factory_(dependency_factory), | 653 dependency_factory_(dependency_factory), |
| 624 frame_(NULL), | 654 frame_(NULL), |
| 625 signaling_thread_(signaling_thread), | |
| 626 num_data_channels_created_(0), | 655 num_data_channels_created_(0), |
| 627 num_local_candidates_ipv4_(0), | 656 num_local_candidates_ipv4_(0), |
| 628 num_local_candidates_ipv6_(0), | 657 num_local_candidates_ipv6_(0), |
| 629 weak_factory_(this) { | 658 weak_factory_(this) { |
| 630 g_peer_connection_handlers.Get().insert(this); | 659 g_peer_connection_handlers.Get().insert(this); |
| 631 } | 660 } |
| 632 | 661 |
| 633 RTCPeerConnectionHandler::~RTCPeerConnectionHandler() { | 662 RTCPeerConnectionHandler::~RTCPeerConnectionHandler() { |
| 634 DCHECK(thread_checker_.CalledOnValidThread()); | 663 DCHECK(thread_checker_.CalledOnValidThread()); |
| 635 g_peer_connection_handlers.Get().erase(this); | 664 g_peer_connection_handlers.Get().erase(this); |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 const blink::WebMediaConstraints& options) { | 772 const blink::WebMediaConstraints& options) { |
| 744 DCHECK(thread_checker_.CalledOnValidThread()); | 773 DCHECK(thread_checker_.CalledOnValidThread()); |
| 745 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createOffer"); | 774 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createOffer"); |
| 746 | 775 |
| 747 scoped_refptr<CreateSessionDescriptionRequest> description_request( | 776 scoped_refptr<CreateSessionDescriptionRequest> description_request( |
| 748 new rtc::RefCountedObject<CreateSessionDescriptionRequest>( | 777 new rtc::RefCountedObject<CreateSessionDescriptionRequest>( |
| 749 base::ThreadTaskRunnerHandle::Get(), request, | 778 base::ThreadTaskRunnerHandle::Get(), request, |
| 750 weak_factory_.GetWeakPtr(), peer_connection_tracker_, | 779 weak_factory_.GetWeakPtr(), peer_connection_tracker_, |
| 751 PeerConnectionTracker::ACTION_CREATE_OFFER)); | 780 PeerConnectionTracker::ACTION_CREATE_OFFER)); |
| 752 | 781 |
| 782 // TODO(tommi): Do this asynchronously via e.g. PostTaskAndReply. |
| 753 RTCMediaConstraints constraints(options); | 783 RTCMediaConstraints constraints(options); |
| 754 native_peer_connection_->CreateOffer(description_request.get(), &constraints); | 784 native_peer_connection_->CreateOffer(description_request.get(), &constraints); |
| 755 | 785 |
| 756 if (peer_connection_tracker_) | 786 if (peer_connection_tracker_) |
| 757 peer_connection_tracker_->TrackCreateOffer(this, constraints); | 787 peer_connection_tracker_->TrackCreateOffer(this, constraints); |
| 758 } | 788 } |
| 759 | 789 |
| 760 void RTCPeerConnectionHandler::createOffer( | 790 void RTCPeerConnectionHandler::createOffer( |
| 761 const blink::WebRTCSessionDescriptionRequest& request, | 791 const blink::WebRTCSessionDescriptionRequest& request, |
| 762 const blink::WebRTCOfferOptions& options) { | 792 const blink::WebRTCOfferOptions& options) { |
| 763 DCHECK(thread_checker_.CalledOnValidThread()); | 793 DCHECK(thread_checker_.CalledOnValidThread()); |
| 764 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createOffer"); | 794 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createOffer"); |
| 765 | 795 |
| 766 scoped_refptr<CreateSessionDescriptionRequest> description_request( | 796 scoped_refptr<CreateSessionDescriptionRequest> description_request( |
| 767 new rtc::RefCountedObject<CreateSessionDescriptionRequest>( | 797 new rtc::RefCountedObject<CreateSessionDescriptionRequest>( |
| 768 base::ThreadTaskRunnerHandle::Get(), request, | 798 base::ThreadTaskRunnerHandle::Get(), request, |
| 769 weak_factory_.GetWeakPtr(), peer_connection_tracker_, | 799 weak_factory_.GetWeakPtr(), peer_connection_tracker_, |
| 770 PeerConnectionTracker::ACTION_CREATE_OFFER)); | 800 PeerConnectionTracker::ACTION_CREATE_OFFER)); |
| 771 | 801 |
| 802 // TODO(tommi): Do this asynchronously via e.g. PostTaskAndReply. |
| 772 RTCMediaConstraints constraints; | 803 RTCMediaConstraints constraints; |
| 773 ConvertOfferOptionsToConstraints(options, &constraints); | 804 ConvertOfferOptionsToConstraints(options, &constraints); |
| 774 native_peer_connection_->CreateOffer(description_request.get(), &constraints); | 805 native_peer_connection_->CreateOffer(description_request.get(), &constraints); |
| 775 | 806 |
| 776 if (peer_connection_tracker_) | 807 if (peer_connection_tracker_) |
| 777 peer_connection_tracker_->TrackCreateOffer(this, constraints); | 808 peer_connection_tracker_->TrackCreateOffer(this, constraints); |
| 778 } | 809 } |
| 779 | 810 |
| 780 void RTCPeerConnectionHandler::createAnswer( | 811 void RTCPeerConnectionHandler::createAnswer( |
| 781 const blink::WebRTCSessionDescriptionRequest& request, | 812 const blink::WebRTCSessionDescriptionRequest& request, |
| 782 const blink::WebMediaConstraints& options) { | 813 const blink::WebMediaConstraints& options) { |
| 783 DCHECK(thread_checker_.CalledOnValidThread()); | 814 DCHECK(thread_checker_.CalledOnValidThread()); |
| 784 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createAnswer"); | 815 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createAnswer"); |
| 785 scoped_refptr<CreateSessionDescriptionRequest> description_request( | 816 scoped_refptr<CreateSessionDescriptionRequest> description_request( |
| 786 new rtc::RefCountedObject<CreateSessionDescriptionRequest>( | 817 new rtc::RefCountedObject<CreateSessionDescriptionRequest>( |
| 787 base::ThreadTaskRunnerHandle::Get(), request, | 818 base::ThreadTaskRunnerHandle::Get(), request, |
| 788 weak_factory_.GetWeakPtr(), peer_connection_tracker_, | 819 weak_factory_.GetWeakPtr(), peer_connection_tracker_, |
| 789 PeerConnectionTracker::ACTION_CREATE_ANSWER)); | 820 PeerConnectionTracker::ACTION_CREATE_ANSWER)); |
| 821 // TODO(tommi): Do this asynchronously via e.g. PostTaskAndReply. |
| 790 RTCMediaConstraints constraints(options); | 822 RTCMediaConstraints constraints(options); |
| 791 native_peer_connection_->CreateAnswer(description_request.get(), | 823 native_peer_connection_->CreateAnswer(description_request.get(), |
| 792 &constraints); | 824 &constraints); |
| 793 | 825 |
| 794 if (peer_connection_tracker_) | 826 if (peer_connection_tracker_) |
| 795 peer_connection_tracker_->TrackCreateAnswer(this, constraints); | 827 peer_connection_tracker_->TrackCreateAnswer(this, constraints); |
| 796 } | 828 } |
| 797 | 829 |
| 798 void RTCPeerConnectionHandler::setLocalDescription( | 830 void RTCPeerConnectionHandler::setLocalDescription( |
| 799 const blink::WebRTCVoidRequest& request, | 831 const blink::WebRTCVoidRequest& request, |
| (...skipping 23 matching lines...) Expand all Loading... |
| 823 peer_connection_tracker_->TrackSetSessionDescription( | 855 peer_connection_tracker_->TrackSetSessionDescription( |
| 824 this, sdp, type, PeerConnectionTracker::SOURCE_LOCAL); | 856 this, sdp, type, PeerConnectionTracker::SOURCE_LOCAL); |
| 825 } | 857 } |
| 826 | 858 |
| 827 scoped_refptr<SetSessionDescriptionRequest> set_request( | 859 scoped_refptr<SetSessionDescriptionRequest> set_request( |
| 828 new rtc::RefCountedObject<SetSessionDescriptionRequest>( | 860 new rtc::RefCountedObject<SetSessionDescriptionRequest>( |
| 829 base::ThreadTaskRunnerHandle::Get(), request, | 861 base::ThreadTaskRunnerHandle::Get(), request, |
| 830 weak_factory_.GetWeakPtr(), peer_connection_tracker_, | 862 weak_factory_.GetWeakPtr(), peer_connection_tracker_, |
| 831 PeerConnectionTracker::ACTION_SET_LOCAL_DESCRIPTION)); | 863 PeerConnectionTracker::ACTION_SET_LOCAL_DESCRIPTION)); |
| 832 | 864 |
| 833 // TODO(tommi): Run this on the signaling thread. | 865 signaling_thread()->PostTask(FROM_HERE, |
| 834 native_peer_connection_->SetLocalDescription(set_request.get(), native_desc); | 866 base::Bind(&RunClosureWithTrace, |
| 867 base::Bind(&webrtc::PeerConnectionInterface::SetLocalDescription, |
| 868 native_peer_connection_, set_request, |
| 869 base::Unretained(native_desc)), |
| 870 "SetLocalDescription")); |
| 835 } | 871 } |
| 836 | 872 |
| 837 void RTCPeerConnectionHandler::setRemoteDescription( | 873 void RTCPeerConnectionHandler::setRemoteDescription( |
| 838 const blink::WebRTCVoidRequest& request, | 874 const blink::WebRTCVoidRequest& request, |
| 839 const blink::WebRTCSessionDescription& description) { | 875 const blink::WebRTCSessionDescription& description) { |
| 840 DCHECK(thread_checker_.CalledOnValidThread()); | 876 DCHECK(thread_checker_.CalledOnValidThread()); |
| 841 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::setRemoteDescription"); | 877 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::setRemoteDescription"); |
| 842 std::string sdp = base::UTF16ToUTF8(description.sdp()); | 878 std::string sdp = base::UTF16ToUTF8(description.sdp()); |
| 843 std::string type = base::UTF16ToUTF8(description.type()); | 879 std::string type = base::UTF16ToUTF8(description.type()); |
| 844 | 880 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 860 if (peer_connection_tracker_) { | 896 if (peer_connection_tracker_) { |
| 861 peer_connection_tracker_->TrackSetSessionDescription( | 897 peer_connection_tracker_->TrackSetSessionDescription( |
| 862 this, sdp, type, PeerConnectionTracker::SOURCE_REMOTE); | 898 this, sdp, type, PeerConnectionTracker::SOURCE_REMOTE); |
| 863 } | 899 } |
| 864 | 900 |
| 865 scoped_refptr<SetSessionDescriptionRequest> set_request( | 901 scoped_refptr<SetSessionDescriptionRequest> set_request( |
| 866 new rtc::RefCountedObject<SetSessionDescriptionRequest>( | 902 new rtc::RefCountedObject<SetSessionDescriptionRequest>( |
| 867 base::ThreadTaskRunnerHandle::Get(), request, | 903 base::ThreadTaskRunnerHandle::Get(), request, |
| 868 weak_factory_.GetWeakPtr(), peer_connection_tracker_, | 904 weak_factory_.GetWeakPtr(), peer_connection_tracker_, |
| 869 PeerConnectionTracker::ACTION_SET_REMOTE_DESCRIPTION)); | 905 PeerConnectionTracker::ACTION_SET_REMOTE_DESCRIPTION)); |
| 870 // TODO(tommi): Run this on the signaling thread. | 906 signaling_thread()->PostTask(FROM_HERE, |
| 871 native_peer_connection_->SetRemoteDescription(set_request.get(), native_desc); | 907 base::Bind(&RunClosureWithTrace, |
| 908 base::Bind(&webrtc::PeerConnectionInterface::SetRemoteDescription, |
| 909 native_peer_connection_, set_request, |
| 910 base::Unretained(native_desc)), |
| 911 "SetRemoteDescription")); |
| 872 } | 912 } |
| 873 | 913 |
| 874 blink::WebRTCSessionDescription | 914 blink::WebRTCSessionDescription |
| 875 RTCPeerConnectionHandler::localDescription() { | 915 RTCPeerConnectionHandler::localDescription() { |
| 876 DCHECK(thread_checker_.CalledOnValidThread()); | 916 DCHECK(thread_checker_.CalledOnValidThread()); |
| 877 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::localDescription"); | 917 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::localDescription"); |
| 878 const webrtc::SessionDescriptionInterface* native_desc = | 918 |
| 879 native_peer_connection_->local_description(); | 919 // Since local_description returns a pointer to a non-reference-counted object |
| 880 blink::WebRTCSessionDescription description = | 920 // that lives on the signaling thread, we cannot fetch a pointer to it and use |
| 881 CreateWebKitSessionDescription(native_desc); | 921 // it directly here. Instead, we access the object completely on the signaling |
| 882 return description; | 922 // thread. |
| 923 std::string sdp, type; |
| 924 base::Callback<const webrtc::SessionDescriptionInterface*()> description_cb = |
| 925 base::Bind(&webrtc::PeerConnectionInterface::local_description, |
| 926 native_peer_connection_); |
| 927 RunSynchronousClosureOnSignalingThread( |
| 928 base::Bind(&GetSdpAndTypeFromSessionDescription, description_cb, |
| 929 base::Unretained(&sdp), base::Unretained(&type)), |
| 930 "localDescription"); |
| 931 |
| 932 return CreateWebKitSessionDescription(sdp, type); |
| 883 } | 933 } |
| 884 | 934 |
| 885 blink::WebRTCSessionDescription | 935 blink::WebRTCSessionDescription |
| 886 RTCPeerConnectionHandler::remoteDescription() { | 936 RTCPeerConnectionHandler::remoteDescription() { |
| 887 DCHECK(thread_checker_.CalledOnValidThread()); | 937 DCHECK(thread_checker_.CalledOnValidThread()); |
| 888 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::remoteDescription"); | 938 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::remoteDescription"); |
| 889 const webrtc::SessionDescriptionInterface* native_desc = | 939 // Since local_description returns a pointer to a non-reference-counted object |
| 890 native_peer_connection_->remote_description(); | 940 // that lives on the signaling thread, we cannot fetch a pointer to it and use |
| 891 blink::WebRTCSessionDescription description = | 941 // it directly here. Instead, we access the object completely on the signaling |
| 892 CreateWebKitSessionDescription(native_desc); | 942 // thread. |
| 893 return description; | 943 std::string sdp, type; |
| 944 base::Callback<const webrtc::SessionDescriptionInterface*()> description_cb = |
| 945 base::Bind(&webrtc::PeerConnectionInterface::remote_description, |
| 946 native_peer_connection_); |
| 947 RunSynchronousClosureOnSignalingThread( |
| 948 base::Bind(&GetSdpAndTypeFromSessionDescription, description_cb, |
| 949 base::Unretained(&sdp), base::Unretained(&type)), |
| 950 "remoteDescription"); |
| 951 |
| 952 return CreateWebKitSessionDescription(sdp, type); |
| 894 } | 953 } |
| 895 | 954 |
| 896 bool RTCPeerConnectionHandler::updateICE( | 955 bool RTCPeerConnectionHandler::updateICE( |
| 897 const blink::WebRTCConfiguration& server_configuration, | 956 const blink::WebRTCConfiguration& server_configuration, |
| 898 const blink::WebMediaConstraints& options) { | 957 const blink::WebMediaConstraints& options) { |
| 899 DCHECK(thread_checker_.CalledOnValidThread()); | 958 DCHECK(thread_checker_.CalledOnValidThread()); |
| 900 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::updateICE"); | 959 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::updateICE"); |
| 901 webrtc::PeerConnectionInterface::RTCConfiguration config; | 960 webrtc::PeerConnectionInterface::RTCConfiguration config; |
| 902 GetNativeRtcConfiguration(server_configuration, &config); | 961 GetNativeRtcConfiguration(server_configuration, &config); |
| 903 RTCMediaConstraints constraints(options); | 962 RTCMediaConstraints constraints(options); |
| 904 | 963 |
| 905 if (peer_connection_tracker_) | 964 if (peer_connection_tracker_) |
| 906 peer_connection_tracker_->TrackUpdateIce(this, config, constraints); | 965 peer_connection_tracker_->TrackUpdateIce(this, config, constraints); |
| 907 | 966 |
| 908 return native_peer_connection_->UpdateIce(config.servers, &constraints); | 967 return native_peer_connection_->UpdateIce(config.servers, &constraints); |
| 909 } | 968 } |
| 910 | 969 |
| 911 bool RTCPeerConnectionHandler::addICECandidate( | 970 bool RTCPeerConnectionHandler::addICECandidate( |
| 912 const blink::WebRTCVoidRequest& request, | 971 const blink::WebRTCVoidRequest& request, |
| 913 const blink::WebRTCICECandidate& candidate) { | 972 const blink::WebRTCICECandidate& candidate) { |
| 914 DCHECK(thread_checker_.CalledOnValidThread()); | 973 DCHECK(thread_checker_.CalledOnValidThread()); |
| 915 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::addICECandidate"); | 974 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::addICECandidate"); |
| 916 // Libjingle currently does not accept callbacks for addICECandidate. | 975 // Libjingle currently does not accept callbacks for addICECandidate. |
| 917 // For that reason we are going to call callbacks from here. | 976 // For that reason we are going to call callbacks from here. |
| 977 |
| 978 // TODO(tommi): Instead of calling addICECandidate here, we can do a |
| 979 // PostTaskAndReply kind of a thing. |
| 918 bool result = addICECandidate(candidate); | 980 bool result = addICECandidate(candidate); |
| 919 base::MessageLoop::current()->PostTask( | 981 base::MessageLoop::current()->PostTask( |
| 920 FROM_HERE, | 982 FROM_HERE, |
| 921 base::Bind(&RTCPeerConnectionHandler::OnaddICECandidateResult, | 983 base::Bind(&RTCPeerConnectionHandler::OnaddICECandidateResult, |
| 922 weak_factory_.GetWeakPtr(), request, result)); | 984 weak_factory_.GetWeakPtr(), request, result)); |
| 923 // On failure callback will be triggered. | 985 // On failure callback will be triggered. |
| 924 return true; | 986 return true; |
| 925 } | 987 } |
| 926 | 988 |
| 927 bool RTCPeerConnectionHandler::addICECandidate( | 989 bool RTCPeerConnectionHandler::addICECandidate( |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1007 for (ScopedVector<WebRtcMediaStreamAdapter>::iterator adapter_it = | 1069 for (ScopedVector<WebRtcMediaStreamAdapter>::iterator adapter_it = |
| 1008 local_streams_.begin(); adapter_it != local_streams_.end(); | 1070 local_streams_.begin(); adapter_it != local_streams_.end(); |
| 1009 ++adapter_it) { | 1071 ++adapter_it) { |
| 1010 if ((*adapter_it)->IsEqual(stream)) { | 1072 if ((*adapter_it)->IsEqual(stream)) { |
| 1011 webrtc_stream = (*adapter_it)->webrtc_media_stream(); | 1073 webrtc_stream = (*adapter_it)->webrtc_media_stream(); |
| 1012 local_streams_.erase(adapter_it); | 1074 local_streams_.erase(adapter_it); |
| 1013 break; | 1075 break; |
| 1014 } | 1076 } |
| 1015 } | 1077 } |
| 1016 DCHECK(webrtc_stream.get()); | 1078 DCHECK(webrtc_stream.get()); |
| 1079 // TODO(tommi): Make this async (PostTaskAndReply). |
| 1017 native_peer_connection_->RemoveStream(webrtc_stream.get()); | 1080 native_peer_connection_->RemoveStream(webrtc_stream.get()); |
| 1018 | 1081 |
| 1019 if (peer_connection_tracker_) { | 1082 if (peer_connection_tracker_) { |
| 1020 peer_connection_tracker_->TrackRemoveStream( | 1083 peer_connection_tracker_->TrackRemoveStream( |
| 1021 this, stream, PeerConnectionTracker::SOURCE_LOCAL); | 1084 this, stream, PeerConnectionTracker::SOURCE_LOCAL); |
| 1022 } | 1085 } |
| 1023 PerSessionWebRTCAPIMetrics::GetInstance()->DecrementStreamCounter(); | 1086 PerSessionWebRTCAPIMetrics::GetInstance()->DecrementStreamCounter(); |
| 1024 track_metrics_.RemoveStream(MediaStreamTrackMetrics::SENT_STREAM, | 1087 track_metrics_.RemoveStream(MediaStreamTrackMetrics::SENT_STREAM, |
| 1025 webrtc_stream.get()); | 1088 webrtc_stream.get()); |
| 1026 } | 1089 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 1054 track_id, track_type); | 1117 track_id, track_type); |
| 1055 } | 1118 } |
| 1056 | 1119 |
| 1057 // TODO(tommi): It's weird to have three {g|G}etStats methods. Clean this up. | 1120 // TODO(tommi): It's weird to have three {g|G}etStats methods. Clean this up. |
| 1058 void RTCPeerConnectionHandler::GetStats( | 1121 void RTCPeerConnectionHandler::GetStats( |
| 1059 webrtc::StatsObserver* observer, | 1122 webrtc::StatsObserver* observer, |
| 1060 webrtc::PeerConnectionInterface::StatsOutputLevel level, | 1123 webrtc::PeerConnectionInterface::StatsOutputLevel level, |
| 1061 const std::string& track_id, | 1124 const std::string& track_id, |
| 1062 blink::WebMediaStreamSource::Type track_type) { | 1125 blink::WebMediaStreamSource::Type track_type) { |
| 1063 DCHECK(thread_checker_.CalledOnValidThread()); | 1126 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1064 signaling_thread_->PostTask(FROM_HERE, | 1127 signaling_thread()->PostTask(FROM_HERE, |
| 1065 base::Bind(&GetStatsOnSignalingThread, native_peer_connection_, level, | 1128 base::Bind(&GetStatsOnSignalingThread, native_peer_connection_, level, |
| 1066 make_scoped_refptr(observer), track_id, track_type)); | 1129 make_scoped_refptr(observer), track_id, track_type)); |
| 1067 } | 1130 } |
| 1068 | 1131 |
| 1069 void RTCPeerConnectionHandler::CloseClientPeerConnection() { | 1132 void RTCPeerConnectionHandler::CloseClientPeerConnection() { |
| 1070 DCHECK(thread_checker_.CalledOnValidThread()); | 1133 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1071 if (client_) | 1134 if (client_) |
| 1072 client_->closePeerConnection(); | 1135 client_->closePeerConnection(); |
| 1073 } | 1136 } |
| 1074 | 1137 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1113 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createDTMFSender"); | 1176 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createDTMFSender"); |
| 1114 DVLOG(1) << "createDTMFSender."; | 1177 DVLOG(1) << "createDTMFSender."; |
| 1115 | 1178 |
| 1116 MediaStreamTrack* native_track = MediaStreamTrack::GetTrack(track); | 1179 MediaStreamTrack* native_track = MediaStreamTrack::GetTrack(track); |
| 1117 if (!native_track || !native_track->is_local_track() || | 1180 if (!native_track || !native_track->is_local_track() || |
| 1118 track.source().type() != blink::WebMediaStreamSource::TypeAudio) { | 1181 track.source().type() != blink::WebMediaStreamSource::TypeAudio) { |
| 1119 DLOG(ERROR) << "The DTMF sender requires a local audio track."; | 1182 DLOG(ERROR) << "The DTMF sender requires a local audio track."; |
| 1120 return nullptr; | 1183 return nullptr; |
| 1121 } | 1184 } |
| 1122 | 1185 |
| 1123 webrtc::AudioTrackInterface* audio_track = native_track->GetAudioAdapter(); | 1186 scoped_refptr<webrtc::AudioTrackInterface> audio_track = |
| 1187 native_track->GetAudioAdapter(); |
| 1124 rtc::scoped_refptr<webrtc::DtmfSenderInterface> sender( | 1188 rtc::scoped_refptr<webrtc::DtmfSenderInterface> sender( |
| 1125 native_peer_connection_->CreateDtmfSender(audio_track)); | 1189 native_peer_connection_->CreateDtmfSender(audio_track.get())); |
| 1126 if (!sender) { | 1190 if (!sender) { |
| 1127 DLOG(ERROR) << "Could not create native DTMF sender."; | 1191 DLOG(ERROR) << "Could not create native DTMF sender."; |
| 1128 return nullptr; | 1192 return nullptr; |
| 1129 } | 1193 } |
| 1130 if (peer_connection_tracker_) | 1194 if (peer_connection_tracker_) |
| 1131 peer_connection_tracker_->TrackCreateDTMFSender(this, track); | 1195 peer_connection_tracker_->TrackCreateDTMFSender(this, track); |
| 1132 | 1196 |
| 1133 return new RtcDtmfSenderHandler(sender); | 1197 return new RtcDtmfSenderHandler(sender); |
| 1134 } | 1198 } |
| 1135 | 1199 |
| 1136 void RTCPeerConnectionHandler::stop() { | 1200 void RTCPeerConnectionHandler::stop() { |
| 1137 DCHECK(thread_checker_.CalledOnValidThread()); | 1201 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1138 DVLOG(1) << "RTCPeerConnectionHandler::stop"; | 1202 DVLOG(1) << "RTCPeerConnectionHandler::stop"; |
| 1139 | 1203 |
| 1204 if (!client_) |
| 1205 return; // Already stopped. |
| 1206 |
| 1140 if (peer_connection_tracker_) | 1207 if (peer_connection_tracker_) |
| 1141 peer_connection_tracker_->TrackStop(this); | 1208 peer_connection_tracker_->TrackStop(this); |
| 1209 |
| 1142 native_peer_connection_->Close(); | 1210 native_peer_connection_->Close(); |
| 1211 |
| 1143 // The client_ pointer is not considered valid after this point and no further | 1212 // The client_ pointer is not considered valid after this point and no further |
| 1144 // callbacks must be made. | 1213 // callbacks must be made. |
| 1145 client_ = nullptr; | 1214 client_ = nullptr; |
| 1146 } | 1215 } |
| 1147 | 1216 |
| 1148 void RTCPeerConnectionHandler::OnSignalingChange( | 1217 void RTCPeerConnectionHandler::OnSignalingChange( |
| 1149 webrtc::PeerConnectionInterface::SignalingState new_state) { | 1218 webrtc::PeerConnectionInterface::SignalingState new_state) { |
| 1150 DCHECK(thread_checker_.CalledOnValidThread()); | 1219 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1151 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::OnSignalingChange"); | 1220 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::OnSignalingChange"); |
| 1152 | 1221 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1332 webrtc::SdpParseError* error) { | 1401 webrtc::SdpParseError* error) { |
| 1333 webrtc::SessionDescriptionInterface* native_desc = | 1402 webrtc::SessionDescriptionInterface* native_desc = |
| 1334 dependency_factory_->CreateSessionDescription(type, sdp, error); | 1403 dependency_factory_->CreateSessionDescription(type, sdp, error); |
| 1335 | 1404 |
| 1336 LOG_IF(ERROR, !native_desc) << "Failed to create native session description." | 1405 LOG_IF(ERROR, !native_desc) << "Failed to create native session description." |
| 1337 << " Type: " << type << " SDP: " << sdp; | 1406 << " Type: " << type << " SDP: " << sdp; |
| 1338 | 1407 |
| 1339 return native_desc; | 1408 return native_desc; |
| 1340 } | 1409 } |
| 1341 | 1410 |
| 1411 scoped_refptr<base::SingleThreadTaskRunner> |
| 1412 RTCPeerConnectionHandler::signaling_thread() const { |
| 1413 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1414 return dependency_factory_->GetWebRtcSignalingThread(); |
| 1415 } |
| 1416 |
| 1417 void RTCPeerConnectionHandler::RunSynchronousClosureOnSignalingThread( |
| 1418 const base::Closure& closure, |
| 1419 const char* trace_event_name) { |
| 1420 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1421 scoped_refptr<base::SingleThreadTaskRunner> thread(signaling_thread()); |
| 1422 if (!thread.get() || thread->BelongsToCurrentThread()) { |
| 1423 TRACE_EVENT0("webrtc", trace_event_name); |
| 1424 closure.Run(); |
| 1425 } else { |
| 1426 base::WaitableEvent event(false, false); |
| 1427 thread->PostTask(FROM_HERE, |
| 1428 base::Bind(&RunSynchronousClosure, closure, |
| 1429 base::Unretained(trace_event_name), |
| 1430 base::Unretained(&event))); |
| 1431 event.Wait(); |
| 1432 } |
| 1433 } |
| 1434 |
| 1342 } // namespace content | 1435 } // namespace content |
| OLD | NEW |