Chromium Code Reviews| 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 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 return | 110 return |
| 111 WebRTCPeerConnectionHandlerClient::SignalingStateHaveRemotePrAnswer; | 111 WebRTCPeerConnectionHandlerClient::SignalingStateHaveRemotePrAnswer; |
| 112 case webrtc::PeerConnectionInterface::kClosed: | 112 case webrtc::PeerConnectionInterface::kClosed: |
| 113 return WebRTCPeerConnectionHandlerClient::SignalingStateClosed; | 113 return WebRTCPeerConnectionHandlerClient::SignalingStateClosed; |
| 114 default: | 114 default: |
| 115 NOTREACHED(); | 115 NOTREACHED(); |
| 116 return WebRTCPeerConnectionHandlerClient::SignalingStateClosed; | 116 return WebRTCPeerConnectionHandlerClient::SignalingStateClosed; |
| 117 } | 117 } |
| 118 } | 118 } |
| 119 | 119 |
| 120 static blink::WebRTCSessionDescription CreateWebKitSessionDescription( | |
| 121 const std::string& sdp, const std::string& type) { | |
| 122 blink::WebRTCSessionDescription description; | |
| 123 description.initialize(base::UTF8ToUTF16(type), base::UTF8ToUTF16(sdp)); | |
| 124 return description; | |
| 125 } | |
| 126 | |
| 120 static blink::WebRTCSessionDescription | 127 static blink::WebRTCSessionDescription |
| 121 CreateWebKitSessionDescription( | 128 CreateWebKitSessionDescription( |
| 122 const webrtc::SessionDescriptionInterface* native_desc) { | 129 const webrtc::SessionDescriptionInterface* native_desc) { |
| 123 blink::WebRTCSessionDescription description; | |
| 124 if (!native_desc) { | 130 if (!native_desc) { |
| 125 LOG(ERROR) << "Native session description is null."; | 131 LOG(ERROR) << "Native session description is null."; |
| 126 return description; | 132 return blink::WebRTCSessionDescription(); |
| 127 } | 133 } |
| 128 | 134 |
| 129 std::string sdp; | 135 std::string sdp; |
| 130 if (!native_desc->ToString(&sdp)) { | 136 if (!native_desc->ToString(&sdp)) { |
| 131 LOG(ERROR) << "Failed to get SDP string of native session description."; | 137 LOG(ERROR) << "Failed to get SDP string of native session description."; |
| 132 return description; | 138 return blink::WebRTCSessionDescription(); |
| 133 } | 139 } |
| 134 | 140 |
| 135 description.initialize(base::UTF8ToUTF16(native_desc->type()), | 141 return CreateWebKitSessionDescription(sdp, native_desc->type()); |
| 136 base::UTF8ToUTF16(sdp)); | 142 } |
| 137 return description; | 143 |
| 144 void RunClosureWithTrace(const base::Closure& closure, | |
|
perkj_chrome
2014/11/05 10:31:02
static to be consistent with above. Or move all to
tommi (sloooow) - chröme
2014/11/05 10:50:38
Done. Moved all into an anonymous namespace. Had
| |
| 145 const char* trace_event_name) { | |
| 146 TRACE_EVENT0("webrtc", trace_event_name); | |
| 147 closure.Run(); | |
| 148 } | |
| 149 | |
| 150 void RunSynchronousClosure(const base::Closure& closure, | |
| 151 const char* trace_event_name, | |
| 152 base::WaitableEvent* event) { | |
| 153 { | |
| 154 TRACE_EVENT0("webrtc", trace_event_name); | |
| 155 closure.Run(); | |
| 156 } | |
| 157 event->Signal(); | |
| 158 } | |
| 159 | |
| 160 template<typename ResultType> | |
| 161 void RunSynchronousClosureWithResult( | |
|
perkj_chrome
2014/11/05 10:31:02
unused
tommi (sloooow) - chröme
2014/11/05 10:50:39
Done.
| |
| 162 const base::Callback<ResultType()>& closure, | |
| 163 const char* trace_event_name, | |
| 164 base::WaitableEvent* event, | |
| 165 ResultType* result) { | |
| 166 { | |
| 167 TRACE_EVENT0("webrtc", trace_event_name); | |
| 168 *result = closure.Run(); | |
| 169 } | |
| 170 event->Signal(); | |
| 171 } | |
| 172 | |
| 173 void RunSynchronousClosureOnThread( | |
|
perkj_chrome
2014/11/05 10:31:01
unused
tommi (sloooow) - chröme
2014/11/05 10:50:39
Done.
| |
| 174 const scoped_refptr<base::SingleThreadTaskRunner>& thread, | |
| 175 const base::Closure& closure, | |
| 176 const char* trace_event_name) { | |
| 177 if (thread->BelongsToCurrentThread()) { | |
| 178 TRACE_EVENT0("webrtc", trace_event_name); | |
| 179 closure.Run(); | |
| 180 } else { | |
| 181 base::WaitableEvent event(false, false); | |
| 182 thread->PostTask(FROM_HERE, | |
| 183 base::Bind(&RunSynchronousClosure, closure, | |
| 184 base::Unretained(trace_event_name), | |
| 185 base::Unretained(&event))); | |
| 186 event.Wait(); | |
| 187 } | |
| 188 } | |
| 189 | |
| 190 template<typename ResultType> | |
| 191 ResultType RunSynchronousClosureOnThreadWithResultT( | |
|
perkj_chrome
2014/11/05 10:31:01
unused?
tommi (sloooow) - chröme
2014/11/05 10:50:38
Done.
| |
| 192 const scoped_refptr<base::SingleThreadTaskRunner>& thread, | |
| 193 const base::Callback<ResultType()>& closure, | |
| 194 const char* trace_event_name) { | |
| 195 ResultType ret = ResultType(); | |
| 196 if (!thread.get() || thread->BelongsToCurrentThread()) { | |
| 197 TRACE_EVENT0("webrtc", trace_event_name); | |
| 198 ret = closure.Run(); | |
| 199 } else { | |
| 200 base::WaitableEvent event(false, false); | |
| 201 thread->PostTask(FROM_HERE, | |
| 202 base::Bind(&RunSynchronousClosureWithResult<ResultType>, closure, | |
| 203 base::Unretained(trace_event_name), base::Unretained(&event), | |
| 204 base::Unretained(&ret))); | |
| 205 event.Wait(); | |
| 206 } | |
| 207 | |
| 208 return ret; | |
| 209 } | |
| 210 | |
| 211 static void GetSessionDescription( | |
|
perkj_chrome
2014/11/05 10:31:02
suggest naming GetSdpAndTypeFromSessionDescription
tommi (sloooow) - chröme
2014/11/05 10:50:39
Done.
| |
| 212 const webrtc::SessionDescriptionInterface* session_description, | |
| 213 std::string* sdp, std::string* type) { | |
| 214 if (session_description) { | |
| 215 session_description->ToString(sdp); | |
| 216 *type = session_description->type(); | |
| 217 } | |
| 218 } | |
| 219 | |
| 220 void GetDescription( | |
| 221 const base::Callback<const webrtc::SessionDescriptionInterface*()>& | |
| 222 description, | |
|
perkj_chrome
2014/11/05 10:31:02
Can we rename |description| to something that indi
tommi (sloooow) - chröme
2014/11/05 10:50:39
Renamed to description_callback
| |
| 223 std::string* sdp, std::string* type) { | |
| 224 GetSessionDescription(description.Run(), sdp, type); | |
|
perkj_chrome
2014/11/05 10:31:02
Can you please join GetSessionDescription and GetD
tommi (sloooow) - chröme
2014/11/05 10:50:39
Done.
| |
| 138 } | 225 } |
| 139 | 226 |
| 140 // Converter functions from WebKit types to libjingle types. | 227 // Converter functions from WebKit types to libjingle types. |
| 141 | 228 |
| 142 static void GetNativeRtcConfiguration( | 229 static void GetNativeRtcConfiguration( |
| 143 const blink::WebRTCConfiguration& server_configuration, | 230 const blink::WebRTCConfiguration& server_configuration, |
| 144 webrtc::PeerConnectionInterface::RTCConfiguration* config) { | 231 webrtc::PeerConnectionInterface::RTCConfiguration* config) { |
| 145 if (server_configuration.isNull() || !config) | 232 if (server_configuration.isNull() || !config) |
| 146 return; | 233 return; |
| 147 for (size_t i = 0; i < server_configuration.numberOfServers(); ++i) { | 234 for (size_t i = 0; i < server_configuration.numberOfServers(); ++i) { |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 : request_(request.get()), | 390 : request_(request.get()), |
| 304 main_thread_(base::ThreadTaskRunnerHandle::Get()) { | 391 main_thread_(base::ThreadTaskRunnerHandle::Get()) { |
| 305 // Measure the overall time it takes to satisfy a getStats request. | 392 // Measure the overall time it takes to satisfy a getStats request. |
| 306 TRACE_EVENT_ASYNC_BEGIN0("webrtc", "getStats_Native", this); | 393 TRACE_EVENT_ASYNC_BEGIN0("webrtc", "getStats_Native", this); |
| 307 signaling_thread_checker_.DetachFromThread(); | 394 signaling_thread_checker_.DetachFromThread(); |
| 308 } | 395 } |
| 309 | 396 |
| 310 void OnComplete(const StatsReports& reports) override { | 397 void OnComplete(const StatsReports& reports) override { |
| 311 DCHECK(signaling_thread_checker_.CalledOnValidThread()); | 398 DCHECK(signaling_thread_checker_.CalledOnValidThread()); |
| 312 TRACE_EVENT0("webrtc", "StatsResponse::OnComplete"); | 399 TRACE_EVENT0("webrtc", "StatsResponse::OnComplete"); |
| 313 // TODO(tommi): Get rid of these string copies some how. | 400 // TODO(tommi): Get rid of these string copies somehow. |
| 314 // We can't use webkit objects directly since they use a single threaded | 401 // We can't use webkit objects directly since they use a single threaded |
| 315 // heap allocator. | 402 // heap allocator. |
| 316 scoped_ptr<std::vector<StatsReportCopyable>> report_copies( | 403 scoped_ptr<std::vector<StatsReportCopyable>> report_copies( |
| 317 new std::vector<StatsReportCopyable>()); | 404 new std::vector<StatsReportCopyable>()); |
| 318 report_copies->reserve(reports.size()); | 405 report_copies->reserve(reports.size()); |
| 319 for (auto it : reports) | 406 for (auto it : reports) |
| 320 report_copies->push_back(StatsReportCopyable(*it)); | 407 report_copies->push_back(StatsReportCopyable(*it)); |
| 321 | 408 |
| 322 main_thread_->PostTask(FROM_HERE, | 409 main_thread_->PostTask(FROM_HERE, |
| 323 base::Bind(&StatsResponse::DeliverCallback, this, | 410 base::Bind(&StatsResponse::DeliverCallback, this, |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 610 } | 697 } |
| 611 } | 698 } |
| 612 | 699 |
| 613 private: | 700 private: |
| 614 const base::WeakPtr<RTCPeerConnectionHandler> handler_; | 701 const base::WeakPtr<RTCPeerConnectionHandler> handler_; |
| 615 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_; | 702 const scoped_refptr<base::SingleThreadTaskRunner> main_thread_; |
| 616 }; | 703 }; |
| 617 | 704 |
| 618 RTCPeerConnectionHandler::RTCPeerConnectionHandler( | 705 RTCPeerConnectionHandler::RTCPeerConnectionHandler( |
| 619 blink::WebRTCPeerConnectionHandlerClient* client, | 706 blink::WebRTCPeerConnectionHandlerClient* client, |
| 620 PeerConnectionDependencyFactory* dependency_factory, | 707 PeerConnectionDependencyFactory* dependency_factory) |
| 621 const scoped_refptr<base::SingleThreadTaskRunner>& signaling_thread) | |
| 622 : client_(client), | 708 : client_(client), |
| 623 dependency_factory_(dependency_factory), | 709 dependency_factory_(dependency_factory), |
| 624 frame_(NULL), | 710 frame_(NULL), |
| 625 signaling_thread_(signaling_thread), | |
| 626 num_data_channels_created_(0), | 711 num_data_channels_created_(0), |
| 627 num_local_candidates_ipv4_(0), | 712 num_local_candidates_ipv4_(0), |
| 628 num_local_candidates_ipv6_(0), | 713 num_local_candidates_ipv6_(0), |
| 629 weak_factory_(this) { | 714 weak_factory_(this) { |
| 630 g_peer_connection_handlers.Get().insert(this); | 715 g_peer_connection_handlers.Get().insert(this); |
| 631 } | 716 } |
| 632 | 717 |
| 633 RTCPeerConnectionHandler::~RTCPeerConnectionHandler() { | 718 RTCPeerConnectionHandler::~RTCPeerConnectionHandler() { |
| 634 DCHECK(thread_checker_.CalledOnValidThread()); | 719 DCHECK(thread_checker_.CalledOnValidThread()); |
| 635 g_peer_connection_handlers.Get().erase(this); | 720 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) { | 828 const blink::WebMediaConstraints& options) { |
| 744 DCHECK(thread_checker_.CalledOnValidThread()); | 829 DCHECK(thread_checker_.CalledOnValidThread()); |
| 745 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createOffer"); | 830 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createOffer"); |
| 746 | 831 |
| 747 scoped_refptr<CreateSessionDescriptionRequest> description_request( | 832 scoped_refptr<CreateSessionDescriptionRequest> description_request( |
| 748 new rtc::RefCountedObject<CreateSessionDescriptionRequest>( | 833 new rtc::RefCountedObject<CreateSessionDescriptionRequest>( |
| 749 base::ThreadTaskRunnerHandle::Get(), request, | 834 base::ThreadTaskRunnerHandle::Get(), request, |
| 750 weak_factory_.GetWeakPtr(), peer_connection_tracker_, | 835 weak_factory_.GetWeakPtr(), peer_connection_tracker_, |
| 751 PeerConnectionTracker::ACTION_CREATE_OFFER)); | 836 PeerConnectionTracker::ACTION_CREATE_OFFER)); |
| 752 | 837 |
| 838 // TODO(tommi): Do this asynchronously via e.g. PostTaskAndReply. | |
| 753 RTCMediaConstraints constraints(options); | 839 RTCMediaConstraints constraints(options); |
| 754 native_peer_connection_->CreateOffer(description_request.get(), &constraints); | 840 native_peer_connection_->CreateOffer(description_request.get(), &constraints); |
| 755 | 841 |
| 756 if (peer_connection_tracker_) | 842 if (peer_connection_tracker_) |
| 757 peer_connection_tracker_->TrackCreateOffer(this, constraints); | 843 peer_connection_tracker_->TrackCreateOffer(this, constraints); |
| 758 } | 844 } |
| 759 | 845 |
| 760 void RTCPeerConnectionHandler::createOffer( | 846 void RTCPeerConnectionHandler::createOffer( |
| 761 const blink::WebRTCSessionDescriptionRequest& request, | 847 const blink::WebRTCSessionDescriptionRequest& request, |
| 762 const blink::WebRTCOfferOptions& options) { | 848 const blink::WebRTCOfferOptions& options) { |
| 763 DCHECK(thread_checker_.CalledOnValidThread()); | 849 DCHECK(thread_checker_.CalledOnValidThread()); |
| 764 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createOffer"); | 850 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createOffer"); |
| 765 | 851 |
| 766 scoped_refptr<CreateSessionDescriptionRequest> description_request( | 852 scoped_refptr<CreateSessionDescriptionRequest> description_request( |
| 767 new rtc::RefCountedObject<CreateSessionDescriptionRequest>( | 853 new rtc::RefCountedObject<CreateSessionDescriptionRequest>( |
| 768 base::ThreadTaskRunnerHandle::Get(), request, | 854 base::ThreadTaskRunnerHandle::Get(), request, |
| 769 weak_factory_.GetWeakPtr(), peer_connection_tracker_, | 855 weak_factory_.GetWeakPtr(), peer_connection_tracker_, |
| 770 PeerConnectionTracker::ACTION_CREATE_OFFER)); | 856 PeerConnectionTracker::ACTION_CREATE_OFFER)); |
| 771 | 857 |
| 858 // TODO(tommi): Do this asynchronously via e.g. PostTaskAndReply. | |
| 772 RTCMediaConstraints constraints; | 859 RTCMediaConstraints constraints; |
| 773 ConvertOfferOptionsToConstraints(options, &constraints); | 860 ConvertOfferOptionsToConstraints(options, &constraints); |
| 774 native_peer_connection_->CreateOffer(description_request.get(), &constraints); | 861 native_peer_connection_->CreateOffer(description_request.get(), &constraints); |
| 775 | 862 |
| 776 if (peer_connection_tracker_) | 863 if (peer_connection_tracker_) |
| 777 peer_connection_tracker_->TrackCreateOffer(this, constraints); | 864 peer_connection_tracker_->TrackCreateOffer(this, constraints); |
| 778 } | 865 } |
| 779 | 866 |
| 780 void RTCPeerConnectionHandler::createAnswer( | 867 void RTCPeerConnectionHandler::createAnswer( |
| 781 const blink::WebRTCSessionDescriptionRequest& request, | 868 const blink::WebRTCSessionDescriptionRequest& request, |
| 782 const blink::WebMediaConstraints& options) { | 869 const blink::WebMediaConstraints& options) { |
| 783 DCHECK(thread_checker_.CalledOnValidThread()); | 870 DCHECK(thread_checker_.CalledOnValidThread()); |
| 784 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createAnswer"); | 871 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createAnswer"); |
| 785 scoped_refptr<CreateSessionDescriptionRequest> description_request( | 872 scoped_refptr<CreateSessionDescriptionRequest> description_request( |
| 786 new rtc::RefCountedObject<CreateSessionDescriptionRequest>( | 873 new rtc::RefCountedObject<CreateSessionDescriptionRequest>( |
| 787 base::ThreadTaskRunnerHandle::Get(), request, | 874 base::ThreadTaskRunnerHandle::Get(), request, |
| 788 weak_factory_.GetWeakPtr(), peer_connection_tracker_, | 875 weak_factory_.GetWeakPtr(), peer_connection_tracker_, |
| 789 PeerConnectionTracker::ACTION_CREATE_ANSWER)); | 876 PeerConnectionTracker::ACTION_CREATE_ANSWER)); |
| 877 // TODO(tommi): Do this asynchronously via e.g. PostTaskAndReply. | |
| 790 RTCMediaConstraints constraints(options); | 878 RTCMediaConstraints constraints(options); |
| 791 native_peer_connection_->CreateAnswer(description_request.get(), | 879 native_peer_connection_->CreateAnswer(description_request.get(), |
| 792 &constraints); | 880 &constraints); |
| 793 | 881 |
| 794 if (peer_connection_tracker_) | 882 if (peer_connection_tracker_) |
| 795 peer_connection_tracker_->TrackCreateAnswer(this, constraints); | 883 peer_connection_tracker_->TrackCreateAnswer(this, constraints); |
| 796 } | 884 } |
| 797 | 885 |
| 798 void RTCPeerConnectionHandler::setLocalDescription( | 886 void RTCPeerConnectionHandler::setLocalDescription( |
| 799 const blink::WebRTCVoidRequest& request, | 887 const blink::WebRTCVoidRequest& request, |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 823 peer_connection_tracker_->TrackSetSessionDescription( | 911 peer_connection_tracker_->TrackSetSessionDescription( |
| 824 this, sdp, type, PeerConnectionTracker::SOURCE_LOCAL); | 912 this, sdp, type, PeerConnectionTracker::SOURCE_LOCAL); |
| 825 } | 913 } |
| 826 | 914 |
| 827 scoped_refptr<SetSessionDescriptionRequest> set_request( | 915 scoped_refptr<SetSessionDescriptionRequest> set_request( |
| 828 new rtc::RefCountedObject<SetSessionDescriptionRequest>( | 916 new rtc::RefCountedObject<SetSessionDescriptionRequest>( |
| 829 base::ThreadTaskRunnerHandle::Get(), request, | 917 base::ThreadTaskRunnerHandle::Get(), request, |
| 830 weak_factory_.GetWeakPtr(), peer_connection_tracker_, | 918 weak_factory_.GetWeakPtr(), peer_connection_tracker_, |
| 831 PeerConnectionTracker::ACTION_SET_LOCAL_DESCRIPTION)); | 919 PeerConnectionTracker::ACTION_SET_LOCAL_DESCRIPTION)); |
| 832 | 920 |
| 833 // TODO(tommi): Run this on the signaling thread. | 921 signaling_thread()->PostTask(FROM_HERE, |
| 834 native_peer_connection_->SetLocalDescription(set_request.get(), native_desc); | 922 base::Bind(&RunClosureWithTrace, |
| 923 base::Bind(&webrtc::PeerConnectionInterface::SetLocalDescription, | |
| 924 native_peer_connection_, set_request, | |
| 925 base::Unretained(native_desc)), | |
| 926 "SetLocalDescription")); | |
| 835 } | 927 } |
| 836 | 928 |
| 837 void RTCPeerConnectionHandler::setRemoteDescription( | 929 void RTCPeerConnectionHandler::setRemoteDescription( |
| 838 const blink::WebRTCVoidRequest& request, | 930 const blink::WebRTCVoidRequest& request, |
| 839 const blink::WebRTCSessionDescription& description) { | 931 const blink::WebRTCSessionDescription& description) { |
| 840 DCHECK(thread_checker_.CalledOnValidThread()); | 932 DCHECK(thread_checker_.CalledOnValidThread()); |
| 841 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::setRemoteDescription"); | 933 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::setRemoteDescription"); |
| 842 std::string sdp = base::UTF16ToUTF8(description.sdp()); | 934 std::string sdp = base::UTF16ToUTF8(description.sdp()); |
| 843 std::string type = base::UTF16ToUTF8(description.type()); | 935 std::string type = base::UTF16ToUTF8(description.type()); |
| 844 | 936 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 860 if (peer_connection_tracker_) { | 952 if (peer_connection_tracker_) { |
| 861 peer_connection_tracker_->TrackSetSessionDescription( | 953 peer_connection_tracker_->TrackSetSessionDescription( |
| 862 this, sdp, type, PeerConnectionTracker::SOURCE_REMOTE); | 954 this, sdp, type, PeerConnectionTracker::SOURCE_REMOTE); |
| 863 } | 955 } |
| 864 | 956 |
| 865 scoped_refptr<SetSessionDescriptionRequest> set_request( | 957 scoped_refptr<SetSessionDescriptionRequest> set_request( |
| 866 new rtc::RefCountedObject<SetSessionDescriptionRequest>( | 958 new rtc::RefCountedObject<SetSessionDescriptionRequest>( |
| 867 base::ThreadTaskRunnerHandle::Get(), request, | 959 base::ThreadTaskRunnerHandle::Get(), request, |
| 868 weak_factory_.GetWeakPtr(), peer_connection_tracker_, | 960 weak_factory_.GetWeakPtr(), peer_connection_tracker_, |
| 869 PeerConnectionTracker::ACTION_SET_REMOTE_DESCRIPTION)); | 961 PeerConnectionTracker::ACTION_SET_REMOTE_DESCRIPTION)); |
| 870 // TODO(tommi): Run this on the signaling thread. | 962 signaling_thread()->PostTask(FROM_HERE, |
| 871 native_peer_connection_->SetRemoteDescription(set_request.get(), native_desc); | 963 base::Bind(&RunClosureWithTrace, |
| 964 base::Bind(&webrtc::PeerConnectionInterface::SetRemoteDescription, | |
| 965 native_peer_connection_, set_request, | |
| 966 base::Unretained(native_desc)), | |
| 967 "SetRemoteDescription")); | |
| 872 } | 968 } |
| 873 | 969 |
| 874 blink::WebRTCSessionDescription | 970 blink::WebRTCSessionDescription |
| 875 RTCPeerConnectionHandler::localDescription() { | 971 RTCPeerConnectionHandler::localDescription() { |
| 876 DCHECK(thread_checker_.CalledOnValidThread()); | 972 DCHECK(thread_checker_.CalledOnValidThread()); |
| 877 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::localDescription"); | 973 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::localDescription"); |
| 878 const webrtc::SessionDescriptionInterface* native_desc = | 974 |
| 879 native_peer_connection_->local_description(); | 975 // Since local_description returns a pointer to a non-reference-counted object |
| 880 blink::WebRTCSessionDescription description = | 976 // that lives on the signaling thread, we cannot fetch a pointer to it and use |
| 881 CreateWebKitSessionDescription(native_desc); | 977 // it directly here. Instead, we access the object completely on the signaling |
| 882 return description; | 978 // thread. |
| 979 std::string sdp, type; | |
| 980 base::Callback<const webrtc::SessionDescriptionInterface*()> description = | |
|
perkj_chrome
2014/11/05 10:31:02
name get_description_cb?
tommi (sloooow) - chröme
2014/11/05 10:50:39
Done. changed to description_cb (since the functio
| |
| 981 base::Bind(&webrtc::PeerConnectionInterface::local_description, | |
| 982 native_peer_connection_); | |
| 983 RunSynchronousClosureOnThread( | |
| 984 base::Bind(&GetDescription, description, base::Unretained(&sdp), | |
| 985 base::Unretained(&type)), | |
| 986 "localDescription"); | |
| 987 | |
| 988 return CreateWebKitSessionDescription(sdp, type); | |
| 883 } | 989 } |
| 884 | 990 |
| 885 blink::WebRTCSessionDescription | 991 blink::WebRTCSessionDescription |
| 886 RTCPeerConnectionHandler::remoteDescription() { | 992 RTCPeerConnectionHandler::remoteDescription() { |
| 887 DCHECK(thread_checker_.CalledOnValidThread()); | 993 DCHECK(thread_checker_.CalledOnValidThread()); |
| 888 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::remoteDescription"); | 994 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::remoteDescription"); |
| 889 const webrtc::SessionDescriptionInterface* native_desc = | 995 // Since local_description returns a pointer to a non-reference-counted object |
| 890 native_peer_connection_->remote_description(); | 996 // that lives on the signaling thread, we cannot fetch a pointer to it and use |
| 891 blink::WebRTCSessionDescription description = | 997 // it directly here. Instead, we access the object completely on the signaling |
| 892 CreateWebKitSessionDescription(native_desc); | 998 // thread. |
| 893 return description; | 999 std::string sdp, type; |
| 1000 auto desc = base::Bind(&webrtc::PeerConnectionInterface::remote_description, | |
|
perkj_chrome
2014/11/05 10:31:02
please use base::Callback<const webrtc::SessionDes
tommi (sloooow) - chröme
2014/11/05 10:50:39
Done.
| |
| 1001 native_peer_connection_); | |
|
perkj_chrome
2014/11/05 10:31:02
nit: indentation
tommi (sloooow) - chröme
2014/11/05 10:50:39
Done.
| |
| 1002 RunSynchronousClosureOnThread( | |
| 1003 base::Bind(&GetDescription, desc, base::Unretained(&sdp), | |
| 1004 base::Unretained(&type)), | |
| 1005 "remoteDescription"); | |
| 1006 | |
| 1007 return CreateWebKitSessionDescription(sdp, type); | |
| 894 } | 1008 } |
| 895 | 1009 |
| 896 bool RTCPeerConnectionHandler::updateICE( | 1010 bool RTCPeerConnectionHandler::updateICE( |
| 897 const blink::WebRTCConfiguration& server_configuration, | 1011 const blink::WebRTCConfiguration& server_configuration, |
| 898 const blink::WebMediaConstraints& options) { | 1012 const blink::WebMediaConstraints& options) { |
| 899 DCHECK(thread_checker_.CalledOnValidThread()); | 1013 DCHECK(thread_checker_.CalledOnValidThread()); |
| 900 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::updateICE"); | 1014 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::updateICE"); |
| 901 webrtc::PeerConnectionInterface::RTCConfiguration config; | 1015 webrtc::PeerConnectionInterface::RTCConfiguration config; |
| 902 GetNativeRtcConfiguration(server_configuration, &config); | 1016 GetNativeRtcConfiguration(server_configuration, &config); |
| 903 RTCMediaConstraints constraints(options); | 1017 RTCMediaConstraints constraints(options); |
| 904 | 1018 |
| 905 if (peer_connection_tracker_) | 1019 if (peer_connection_tracker_) |
| 906 peer_connection_tracker_->TrackUpdateIce(this, config, constraints); | 1020 peer_connection_tracker_->TrackUpdateIce(this, config, constraints); |
| 907 | 1021 |
| 908 return native_peer_connection_->UpdateIce(config.servers, &constraints); | 1022 return native_peer_connection_->UpdateIce(config.servers, &constraints); |
| 909 } | 1023 } |
| 910 | 1024 |
| 911 bool RTCPeerConnectionHandler::addICECandidate( | 1025 bool RTCPeerConnectionHandler::addICECandidate( |
| 912 const blink::WebRTCVoidRequest& request, | 1026 const blink::WebRTCVoidRequest& request, |
| 913 const blink::WebRTCICECandidate& candidate) { | 1027 const blink::WebRTCICECandidate& candidate) { |
| 914 DCHECK(thread_checker_.CalledOnValidThread()); | 1028 DCHECK(thread_checker_.CalledOnValidThread()); |
| 915 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::addICECandidate"); | 1029 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::addICECandidate"); |
| 916 // Libjingle currently does not accept callbacks for addICECandidate. | 1030 // Libjingle currently does not accept callbacks for addICECandidate. |
| 917 // For that reason we are going to call callbacks from here. | 1031 // For that reason we are going to call callbacks from here. |
| 1032 | |
| 1033 // TODO(tommi): Instead of calling addICECandidate here, we can do a | |
| 1034 // PostTaskAndReply kind of a thing. | |
| 918 bool result = addICECandidate(candidate); | 1035 bool result = addICECandidate(candidate); |
| 919 base::MessageLoop::current()->PostTask( | 1036 base::MessageLoop::current()->PostTask( |
| 920 FROM_HERE, | 1037 FROM_HERE, |
| 921 base::Bind(&RTCPeerConnectionHandler::OnaddICECandidateResult, | 1038 base::Bind(&RTCPeerConnectionHandler::OnaddICECandidateResult, |
| 922 weak_factory_.GetWeakPtr(), request, result)); | 1039 weak_factory_.GetWeakPtr(), request, result)); |
| 923 // On failure callback will be triggered. | 1040 // On failure callback will be triggered. |
| 924 return true; | 1041 return true; |
| 925 } | 1042 } |
| 926 | 1043 |
| 927 bool RTCPeerConnectionHandler::addICECandidate( | 1044 bool RTCPeerConnectionHandler::addICECandidate( |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1007 for (ScopedVector<WebRtcMediaStreamAdapter>::iterator adapter_it = | 1124 for (ScopedVector<WebRtcMediaStreamAdapter>::iterator adapter_it = |
| 1008 local_streams_.begin(); adapter_it != local_streams_.end(); | 1125 local_streams_.begin(); adapter_it != local_streams_.end(); |
| 1009 ++adapter_it) { | 1126 ++adapter_it) { |
| 1010 if ((*adapter_it)->IsEqual(stream)) { | 1127 if ((*adapter_it)->IsEqual(stream)) { |
| 1011 webrtc_stream = (*adapter_it)->webrtc_media_stream(); | 1128 webrtc_stream = (*adapter_it)->webrtc_media_stream(); |
| 1012 local_streams_.erase(adapter_it); | 1129 local_streams_.erase(adapter_it); |
| 1013 break; | 1130 break; |
| 1014 } | 1131 } |
| 1015 } | 1132 } |
| 1016 DCHECK(webrtc_stream.get()); | 1133 DCHECK(webrtc_stream.get()); |
| 1134 // TODO(tommi): Make this async (PostTaskAndReply). | |
| 1017 native_peer_connection_->RemoveStream(webrtc_stream.get()); | 1135 native_peer_connection_->RemoveStream(webrtc_stream.get()); |
| 1018 | 1136 |
| 1019 if (peer_connection_tracker_) { | 1137 if (peer_connection_tracker_) { |
| 1020 peer_connection_tracker_->TrackRemoveStream( | 1138 peer_connection_tracker_->TrackRemoveStream( |
| 1021 this, stream, PeerConnectionTracker::SOURCE_LOCAL); | 1139 this, stream, PeerConnectionTracker::SOURCE_LOCAL); |
| 1022 } | 1140 } |
| 1023 PerSessionWebRTCAPIMetrics::GetInstance()->DecrementStreamCounter(); | 1141 PerSessionWebRTCAPIMetrics::GetInstance()->DecrementStreamCounter(); |
| 1024 track_metrics_.RemoveStream(MediaStreamTrackMetrics::SENT_STREAM, | 1142 track_metrics_.RemoveStream(MediaStreamTrackMetrics::SENT_STREAM, |
| 1025 webrtc_stream.get()); | 1143 webrtc_stream.get()); |
| 1026 } | 1144 } |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 1054 track_id, track_type); | 1172 track_id, track_type); |
| 1055 } | 1173 } |
| 1056 | 1174 |
| 1057 // TODO(tommi): It's weird to have three {g|G}etStats methods. Clean this up. | 1175 // TODO(tommi): It's weird to have three {g|G}etStats methods. Clean this up. |
| 1058 void RTCPeerConnectionHandler::GetStats( | 1176 void RTCPeerConnectionHandler::GetStats( |
| 1059 webrtc::StatsObserver* observer, | 1177 webrtc::StatsObserver* observer, |
| 1060 webrtc::PeerConnectionInterface::StatsOutputLevel level, | 1178 webrtc::PeerConnectionInterface::StatsOutputLevel level, |
| 1061 const std::string& track_id, | 1179 const std::string& track_id, |
| 1062 blink::WebMediaStreamSource::Type track_type) { | 1180 blink::WebMediaStreamSource::Type track_type) { |
| 1063 DCHECK(thread_checker_.CalledOnValidThread()); | 1181 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1064 signaling_thread_->PostTask(FROM_HERE, | 1182 signaling_thread()->PostTask(FROM_HERE, |
| 1065 base::Bind(&GetStatsOnSignalingThread, native_peer_connection_, level, | 1183 base::Bind(&GetStatsOnSignalingThread, native_peer_connection_, level, |
| 1066 make_scoped_refptr(observer), track_id, track_type)); | 1184 make_scoped_refptr(observer), track_id, track_type)); |
| 1067 } | 1185 } |
| 1068 | 1186 |
| 1069 void RTCPeerConnectionHandler::CloseClientPeerConnection() { | 1187 void RTCPeerConnectionHandler::CloseClientPeerConnection() { |
| 1070 DCHECK(thread_checker_.CalledOnValidThread()); | 1188 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1071 if (client_) | 1189 if (client_) |
| 1072 client_->closePeerConnection(); | 1190 client_->closePeerConnection(); |
| 1073 } | 1191 } |
| 1074 | 1192 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1113 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createDTMFSender"); | 1231 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createDTMFSender"); |
| 1114 DVLOG(1) << "createDTMFSender."; | 1232 DVLOG(1) << "createDTMFSender."; |
| 1115 | 1233 |
| 1116 MediaStreamTrack* native_track = MediaStreamTrack::GetTrack(track); | 1234 MediaStreamTrack* native_track = MediaStreamTrack::GetTrack(track); |
| 1117 if (!native_track || !native_track->is_local_track() || | 1235 if (!native_track || !native_track->is_local_track() || |
| 1118 track.source().type() != blink::WebMediaStreamSource::TypeAudio) { | 1236 track.source().type() != blink::WebMediaStreamSource::TypeAudio) { |
| 1119 DLOG(ERROR) << "The DTMF sender requires a local audio track."; | 1237 DLOG(ERROR) << "The DTMF sender requires a local audio track."; |
| 1120 return nullptr; | 1238 return nullptr; |
| 1121 } | 1239 } |
| 1122 | 1240 |
| 1123 webrtc::AudioTrackInterface* audio_track = native_track->GetAudioAdapter(); | 1241 scoped_refptr<webrtc::AudioTrackInterface> audio_track = |
| 1242 native_track->GetAudioAdapter(); | |
| 1124 rtc::scoped_refptr<webrtc::DtmfSenderInterface> sender( | 1243 rtc::scoped_refptr<webrtc::DtmfSenderInterface> sender( |
| 1125 native_peer_connection_->CreateDtmfSender(audio_track)); | 1244 native_peer_connection_->CreateDtmfSender(audio_track.get())); |
| 1126 if (!sender) { | 1245 if (!sender) { |
| 1127 DLOG(ERROR) << "Could not create native DTMF sender."; | 1246 DLOG(ERROR) << "Could not create native DTMF sender."; |
| 1128 return nullptr; | 1247 return nullptr; |
| 1129 } | 1248 } |
| 1130 if (peer_connection_tracker_) | 1249 if (peer_connection_tracker_) |
| 1131 peer_connection_tracker_->TrackCreateDTMFSender(this, track); | 1250 peer_connection_tracker_->TrackCreateDTMFSender(this, track); |
| 1132 | 1251 |
| 1133 return new RtcDtmfSenderHandler(sender); | 1252 return new RtcDtmfSenderHandler(sender); |
| 1134 } | 1253 } |
| 1135 | 1254 |
| 1136 void RTCPeerConnectionHandler::stop() { | 1255 void RTCPeerConnectionHandler::stop() { |
| 1137 DCHECK(thread_checker_.CalledOnValidThread()); | 1256 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1138 DVLOG(1) << "RTCPeerConnectionHandler::stop"; | 1257 DVLOG(1) << "RTCPeerConnectionHandler::stop"; |
| 1139 | 1258 |
| 1259 if (!client_) | |
| 1260 return; // Already stopped. | |
| 1261 | |
| 1140 if (peer_connection_tracker_) | 1262 if (peer_connection_tracker_) |
| 1141 peer_connection_tracker_->TrackStop(this); | 1263 peer_connection_tracker_->TrackStop(this); |
| 1264 | |
| 1142 native_peer_connection_->Close(); | 1265 native_peer_connection_->Close(); |
| 1266 | |
| 1143 // The client_ pointer is not considered valid after this point and no further | 1267 // The client_ pointer is not considered valid after this point and no further |
| 1144 // callbacks must be made. | 1268 // callbacks must be made. |
| 1145 client_ = nullptr; | 1269 client_ = nullptr; |
| 1146 } | 1270 } |
| 1147 | 1271 |
| 1148 void RTCPeerConnectionHandler::OnSignalingChange( | 1272 void RTCPeerConnectionHandler::OnSignalingChange( |
| 1149 webrtc::PeerConnectionInterface::SignalingState new_state) { | 1273 webrtc::PeerConnectionInterface::SignalingState new_state) { |
| 1150 DCHECK(thread_checker_.CalledOnValidThread()); | 1274 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1151 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::OnSignalingChange"); | 1275 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::OnSignalingChange"); |
| 1152 | 1276 |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1332 webrtc::SdpParseError* error) { | 1456 webrtc::SdpParseError* error) { |
| 1333 webrtc::SessionDescriptionInterface* native_desc = | 1457 webrtc::SessionDescriptionInterface* native_desc = |
| 1334 dependency_factory_->CreateSessionDescription(type, sdp, error); | 1458 dependency_factory_->CreateSessionDescription(type, sdp, error); |
| 1335 | 1459 |
| 1336 LOG_IF(ERROR, !native_desc) << "Failed to create native session description." | 1460 LOG_IF(ERROR, !native_desc) << "Failed to create native session description." |
| 1337 << " Type: " << type << " SDP: " << sdp; | 1461 << " Type: " << type << " SDP: " << sdp; |
| 1338 | 1462 |
| 1339 return native_desc; | 1463 return native_desc; |
| 1340 } | 1464 } |
| 1341 | 1465 |
| 1466 scoped_refptr<base::SingleThreadTaskRunner> | |
| 1467 RTCPeerConnectionHandler::signaling_thread() const { | |
| 1468 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1469 return dependency_factory_->GetWebRtcSignalingThread(); | |
| 1470 } | |
| 1471 | |
| 1472 void RTCPeerConnectionHandler::RunSynchronousClosureOnThread( | |
|
perkj_chrome
2014/11/05 10:31:01
Name RunSynchronousClosureOnSignalingThread?
tommi (sloooow) - chröme
2014/11/05 10:50:39
Done.
| |
| 1473 const base::Closure& closure, | |
| 1474 const char* trace_event_name) { | |
| 1475 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1476 scoped_refptr<base::SingleThreadTaskRunner> thread(signaling_thread()); | |
| 1477 if (!thread.get() || thread->BelongsToCurrentThread()) { | |
| 1478 TRACE_EVENT0("webrtc", trace_event_name); | |
| 1479 closure.Run(); | |
| 1480 } else { | |
| 1481 base::WaitableEvent event(false, false); | |
| 1482 thread->PostTask(FROM_HERE, | |
| 1483 base::Bind(&RunSynchronousClosure, closure, | |
| 1484 base::Unretained(trace_event_name), | |
| 1485 base::Unretained(&event))); | |
| 1486 event.Wait(); | |
| 1487 } | |
| 1488 } | |
| 1489 | |
| 1490 bool RTCPeerConnectionHandler::RunSynchronousClosureOnThreadWithResult( | |
|
perkj_chrome
2014/11/05 10:31:01
unused?
tommi (sloooow) - chröme
2014/11/05 10:50:38
Removed
| |
| 1491 const base::Callback<bool()>& closure, | |
| 1492 const char* trace_event_name) { | |
| 1493 DCHECK(thread_checker_.CalledOnValidThread()); | |
| 1494 return RunSynchronousClosureOnThreadWithResultT<bool>(signaling_thread(), | |
| 1495 closure, trace_event_name); | |
| 1496 } | |
| 1497 | |
| 1342 } // namespace content | 1498 } // namespace content |
| OLD | NEW |