| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/media/rtc_peer_connection_handler.h" | 5 #include "content/renderer/media/rtc_peer_connection_handler.h" |
| 6 | 6 |
| 7 #include <string.h> | 7 #include <string.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/lazy_instance.h" | 14 #include "base/lazy_instance.h" |
| 15 #include "base/location.h" | 15 #include "base/location.h" |
| 16 #include "base/logging.h" | 16 #include "base/logging.h" |
| 17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
| 18 #include "base/metrics/sparse_histogram.h" | 18 #include "base/metrics/sparse_histogram.h" |
| 19 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/thread_task_runner_handle.h" | 21 #include "base/thread_task_runner_handle.h" |
| 22 #include "base/trace_event/trace_event.h" | 22 #include "base/trace_event/trace_event.h" |
| 23 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
| 24 #include "content/renderer/media/media_stream_audio_track.h" | 24 #include "content/renderer/media/media_stream_audio_track.h" |
| 25 #include "content/renderer/media/media_stream_constraints_util.h" |
| 25 #include "content/renderer/media/media_stream_track.h" | 26 #include "content/renderer/media/media_stream_track.h" |
| 26 #include "content/renderer/media/peer_connection_tracker.h" | 27 #include "content/renderer/media/peer_connection_tracker.h" |
| 27 #include "content/renderer/media/remote_media_stream_impl.h" | 28 #include "content/renderer/media/remote_media_stream_impl.h" |
| 28 #include "content/renderer/media/rtc_certificate.h" | 29 #include "content/renderer/media/rtc_certificate.h" |
| 29 #include "content/renderer/media/rtc_data_channel_handler.h" | 30 #include "content/renderer/media/rtc_data_channel_handler.h" |
| 30 #include "content/renderer/media/rtc_dtmf_sender_handler.h" | 31 #include "content/renderer/media/rtc_dtmf_sender_handler.h" |
| 31 #include "content/renderer/media/rtc_media_constraints.h" | |
| 32 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" | 32 #include "content/renderer/media/webrtc/peer_connection_dependency_factory.h" |
| 33 #include "content/renderer/media/webrtc/webrtc_media_stream_adapter.h" | 33 #include "content/renderer/media/webrtc/webrtc_media_stream_adapter.h" |
| 34 #include "content/renderer/media/webrtc_audio_capturer.h" | 34 #include "content/renderer/media/webrtc_audio_capturer.h" |
| 35 #include "content/renderer/media/webrtc_audio_device_impl.h" | 35 #include "content/renderer/media/webrtc_audio_device_impl.h" |
| 36 #include "content/renderer/media/webrtc_uma_histograms.h" | 36 #include "content/renderer/media/webrtc_uma_histograms.h" |
| 37 #include "content/renderer/render_thread_impl.h" | 37 #include "content/renderer/render_thread_impl.h" |
| 38 #include "media/base/media_switches.h" | 38 #include "media/base/media_switches.h" |
| 39 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" | 39 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" |
| 40 #include "third_party/WebKit/public/platform/WebRTCConfiguration.h" | 40 #include "third_party/WebKit/public/platform/WebRTCConfiguration.h" |
| 41 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" | 41 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 default: | 249 default: |
| 250 NOTREACHED(); | 250 NOTREACHED(); |
| 251 } | 251 } |
| 252 | 252 |
| 253 for (size_t i = 0; i < blink_config.numberOfCertificates(); ++i) { | 253 for (size_t i = 0; i < blink_config.numberOfCertificates(); ++i) { |
| 254 webrtc_config->certificates.push_back( | 254 webrtc_config->certificates.push_back( |
| 255 static_cast<RTCCertificate*>( | 255 static_cast<RTCCertificate*>( |
| 256 blink_config.certificate(i))->rtcCertificate()); | 256 blink_config.certificate(i))->rtcCertificate()); |
| 257 } | 257 } |
| 258 } | 258 } |
| 259 // Scan the basic and advanced constraints until a value is found. |
| 260 // If nothing is found, the default is returned. |
| 261 // Argument 2 is a pointer to class data member. |
| 262 // Note: This code is a near duplicate of code in media_stream_audio_processor. |
| 263 // Consider extracting to a generic helper file. |
| 264 // It is NOT behaving according to spec, so should not go into blink. |
| 265 bool ScanConstraintsForBoolean( |
| 266 const blink::WebMediaConstraints& constraints, |
| 267 blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker, |
| 268 bool the_default, |
| 269 bool* found) { |
| 270 const auto& the_field = constraints.basic().*picker; |
| 271 if (the_field.hasExact()) { |
| 272 if (found) { |
| 273 *found = true; |
| 274 } |
| 275 return the_field.exact(); |
| 276 } |
| 277 for (const auto& advanced_constraint : constraints.advanced()) { |
| 278 const auto& the_field = advanced_constraint.*picker; |
| 279 if (the_field.hasExact()) { |
| 280 if (found) { |
| 281 *found = true; |
| 282 } |
| 283 return the_field.exact(); |
| 284 } |
| 285 } |
| 286 if (found) { |
| 287 *found = false; |
| 288 } |
| 289 return the_default; |
| 290 } |
| 291 |
| 292 rtc::Optional<bool> ConstraintToOptional( |
| 293 const blink::WebMediaConstraints& constraints, |
| 294 blink::BooleanConstraint blink::WebMediaTrackConstraintSet::*picker) { |
| 295 bool found; |
| 296 bool the_value; |
| 297 the_value = ScanConstraintsForBoolean(constraints, picker, false, &found); |
| 298 if (found) { |
| 299 return rtc::Optional<bool>(the_value); |
| 300 } |
| 301 return rtc::Optional<bool>(); |
| 302 } |
| 303 |
| 304 void CopyConstraintsIntoRtcConfiguration( |
| 305 const blink::WebMediaConstraints constraints, |
| 306 webrtc::PeerConnectionInterface::RTCConfiguration* configuration) { |
| 307 // Copy info from constraints into configuration, if present. |
| 308 if (constraints.isEmpty()) { |
| 309 return; |
| 310 } |
| 311 |
| 312 // Note: IPv6 WebRTC value is "disable" while Blink is "enable". |
| 313 configuration->disable_ipv6 = !ScanConstraintsForBoolean( |
| 314 constraints, &blink::WebMediaTrackConstraintSet::enableIPv6, true, |
| 315 nullptr); |
| 316 // Note: If an optional is not present, webrtc decides on its own |
| 317 // what the value should be. |
| 318 configuration->enable_dscp = ConstraintToOptional( |
| 319 constraints, &blink::WebMediaTrackConstraintSet::enableDscp); |
| 320 configuration->cpu_overuse_detection = ConstraintToOptional( |
| 321 constraints, &blink::WebMediaTrackConstraintSet::googCpuOveruseDetection); |
| 322 configuration->enable_rtp_data_channel = ScanConstraintsForBoolean( |
| 323 constraints, &blink::WebMediaTrackConstraintSet::enableRtpDataChannels, |
| 324 false, nullptr); |
| 325 configuration->suspend_below_min_bitrate = ConstraintToOptional( |
| 326 constraints, &blink::WebMediaTrackConstraintSet:: |
| 327 googEnableVideoSuspendBelowMinBitrate); |
| 328 // TODO: Special treatment for screencast min bitrate, since it's an integer. |
| 329 // if (FindConstraint(constraints, |
| 330 // MediaConstraintsInterface::kScreencastMinBitrate, |
| 331 // &configuration->screencast_min_bitrate, NULL)) { |
| 332 // configuration->override_screencast_min_bitrate = true; |
| 333 // } |
| 334 configuration->combined_audio_video_bwe = ConstraintToOptional( |
| 335 constraints, |
| 336 &blink::WebMediaTrackConstraintSet::googCombinedAudioVideoBwe); |
| 337 configuration->enable_dtls_srtp = ConstraintToOptional( |
| 338 constraints, &blink::WebMediaTrackConstraintSet::enableDtlsSrtp); |
| 339 } |
| 259 | 340 |
| 260 class SessionDescriptionRequestTracker { | 341 class SessionDescriptionRequestTracker { |
| 261 public: | 342 public: |
| 262 SessionDescriptionRequestTracker( | 343 SessionDescriptionRequestTracker( |
| 263 const base::WeakPtr<RTCPeerConnectionHandler>& handler, | 344 const base::WeakPtr<RTCPeerConnectionHandler>& handler, |
| 264 const base::WeakPtr<PeerConnectionTracker>& tracker, | 345 const base::WeakPtr<PeerConnectionTracker>& tracker, |
| 265 PeerConnectionTracker::Action action) | 346 PeerConnectionTracker::Action action) |
| 266 : handler_(handler), tracker_(tracker), action_(action) {} | 347 : handler_(handler), tracker_(tracker), action_(action) {} |
| 267 | 348 |
| 268 void TrackOnSuccess(const webrtc::SessionDescriptionInterface* desc) { | 349 void TrackOnSuccess(const webrtc::SessionDescriptionInterface* desc) { |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 826 // Copy g_peer_connection_handlers since releasePeerConnectionHandler will | 907 // Copy g_peer_connection_handlers since releasePeerConnectionHandler will |
| 827 // remove an item. | 908 // remove an item. |
| 828 std::set<RTCPeerConnectionHandler*> handlers( | 909 std::set<RTCPeerConnectionHandler*> handlers( |
| 829 g_peer_connection_handlers.Get().begin(), | 910 g_peer_connection_handlers.Get().begin(), |
| 830 g_peer_connection_handlers.Get().end()); | 911 g_peer_connection_handlers.Get().end()); |
| 831 for (auto* handler : handlers) | 912 for (auto* handler : handlers) |
| 832 handler->client_->releasePeerConnectionHandler(); | 913 handler->client_->releasePeerConnectionHandler(); |
| 833 } | 914 } |
| 834 | 915 |
| 835 // static | 916 // static |
| 836 void RTCPeerConnectionHandler::ConvertOfferOptionsToConstraints( | 917 void RTCPeerConnectionHandler::ConvertOfferOptionsToWebrtcOfferOptions( |
| 837 const blink::WebRTCOfferOptions& options, | 918 const blink::WebRTCOfferOptions& options, |
| 838 RTCMediaConstraints* output) { | 919 webrtc::PeerConnectionInterface::RTCOfferAnswerOptions* output) { |
| 839 output->AddMandatory( | 920 output->offer_to_receive_audio = options.offerToReceiveAudio(); |
| 840 webrtc::MediaConstraintsInterface::kOfferToReceiveAudio, | 921 output->offer_to_receive_video = options.offerToReceiveVideo(); |
| 841 options.offerToReceiveAudio() > 0 ? "true" : "false", | 922 output->voice_activity_detection = options.voiceActivityDetection(); |
| 842 true); | 923 output->ice_restart = options.iceRestart(); |
| 924 } |
| 843 | 925 |
| 844 output->AddMandatory( | 926 void RTCPeerConnectionHandler::ConvertConstraintsToWebrtcOfferOptions( |
| 845 webrtc::MediaConstraintsInterface::kOfferToReceiveVideo, | 927 const blink::WebMediaConstraints& constraints, |
| 846 options.offerToReceiveVideo() > 0 ? "true" : "false", | 928 webrtc::PeerConnectionInterface::RTCOfferAnswerOptions* output) { |
| 847 true); | 929 if (constraints.isEmpty()) { |
| 848 | 930 return; |
| 849 if (!options.voiceActivityDetection()) { | |
| 850 output->AddMandatory( | |
| 851 webrtc::MediaConstraintsInterface::kVoiceActivityDetection, | |
| 852 "false", | |
| 853 true); | |
| 854 } | 931 } |
| 855 | 932 std::string failing_name; |
| 856 if (options.iceRestart()) { | 933 if (constraints.basic().hasMandatoryOutsideSet( |
| 857 output->AddMandatory( | 934 {constraints.basic().offerToReceiveAudio.name(), |
| 858 webrtc::MediaConstraintsInterface::kIceRestart, "true", true); | 935 constraints.basic().offerToReceiveVideo.name(), |
| 936 constraints.basic().voiceActivityDetection.name(), |
| 937 constraints.basic().iceRestart.name()}, |
| 938 failing_name)) { |
| 939 // TODO(hta): Reject the calling operation with "constraint error" |
| 940 // https://crbug.com/594894 |
| 941 DLOG(ERROR) << "Invalid mandatory constraint to CreateOffer/Answer: " |
| 942 << failing_name; |
| 859 } | 943 } |
| 944 GetConstraintValueAsInteger( |
| 945 constraints, &blink::WebMediaTrackConstraintSet::offerToReceiveAudio, |
| 946 &output->offer_to_receive_audio); |
| 947 GetConstraintValueAsInteger( |
| 948 constraints, &blink::WebMediaTrackConstraintSet::offerToReceiveVideo, |
| 949 &output->offer_to_receive_video); |
| 950 GetConstraintValueAsBoolean( |
| 951 constraints, &blink::WebMediaTrackConstraintSet::voiceActivityDetection, |
| 952 &output->voice_activity_detection); |
| 953 GetConstraintValueAsBoolean(constraints, |
| 954 &blink::WebMediaTrackConstraintSet::iceRestart, |
| 955 &output->ice_restart); |
| 860 } | 956 } |
| 861 | 957 |
| 862 void RTCPeerConnectionHandler::associateWithFrame(blink::WebFrame* frame) { | 958 void RTCPeerConnectionHandler::associateWithFrame(blink::WebFrame* frame) { |
| 863 DCHECK(thread_checker_.CalledOnValidThread()); | 959 DCHECK(thread_checker_.CalledOnValidThread()); |
| 864 DCHECK(frame); | 960 DCHECK(frame); |
| 865 frame_ = frame; | 961 frame_ = frame; |
| 866 } | 962 } |
| 867 | 963 |
| 868 bool RTCPeerConnectionHandler::initialize( | 964 bool RTCPeerConnectionHandler::initialize( |
| 869 const blink::WebRTCConfiguration& server_configuration, | 965 const blink::WebRTCConfiguration& server_configuration, |
| 870 const blink::WebMediaConstraints& options) { | 966 const blink::WebMediaConstraints& options) { |
| 871 DCHECK(thread_checker_.CalledOnValidThread()); | 967 DCHECK(thread_checker_.CalledOnValidThread()); |
| 872 DCHECK(frame_); | 968 DCHECK(frame_); |
| 873 | 969 |
| 874 peer_connection_tracker_ = | 970 peer_connection_tracker_ = |
| 875 RenderThreadImpl::current()->peer_connection_tracker()->AsWeakPtr(); | 971 RenderThreadImpl::current()->peer_connection_tracker()->AsWeakPtr(); |
| 876 | 972 |
| 877 webrtc::PeerConnectionInterface::RTCConfiguration config; | 973 webrtc::PeerConnectionInterface::RTCConfiguration config; |
| 878 GetNativeRtcConfiguration(server_configuration, &config); | 974 GetNativeRtcConfiguration(server_configuration, &config); |
| 879 config.disable_prerenderer_smoothing = | 975 config.disable_prerenderer_smoothing = |
| 880 !base::CommandLine::ForCurrentProcess()->HasSwitch( | 976 !base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 881 switches::kDisableRTCSmoothnessAlgorithm); | 977 switches::kDisableRTCSmoothnessAlgorithm); |
| 882 | 978 |
| 883 RTCMediaConstraints constraints(options); | 979 // Copy all the relevant constraints into |config|. |
| 980 CopyConstraintsIntoRtcConfiguration(options, &config); |
| 884 | 981 |
| 885 peer_connection_observer_ = new Observer(weak_factory_.GetWeakPtr()); | 982 peer_connection_observer_ = new Observer(weak_factory_.GetWeakPtr()); |
| 886 native_peer_connection_ = dependency_factory_->CreatePeerConnection( | 983 native_peer_connection_ = dependency_factory_->CreatePeerConnection( |
| 887 config, &constraints, frame_, peer_connection_observer_.get()); | 984 config, frame_, peer_connection_observer_.get()); |
| 888 | 985 |
| 889 if (!native_peer_connection_.get()) { | 986 if (!native_peer_connection_.get()) { |
| 890 LOG(ERROR) << "Failed to initialize native PeerConnection."; | 987 LOG(ERROR) << "Failed to initialize native PeerConnection."; |
| 891 return false; | 988 return false; |
| 892 } | 989 } |
| 893 | 990 |
| 894 if (peer_connection_tracker_) { | 991 if (peer_connection_tracker_) { |
| 895 peer_connection_tracker_->RegisterPeerConnection(this, config, options, | 992 peer_connection_tracker_->RegisterPeerConnection(this, config, options, |
| 896 frame_); | 993 frame_); |
| 897 } | 994 } |
| 898 | 995 |
| 899 uma_observer_ = new rtc::RefCountedObject<PeerConnectionUMAObserver>(); | 996 uma_observer_ = new rtc::RefCountedObject<PeerConnectionUMAObserver>(); |
| 900 native_peer_connection_->RegisterUMAObserver(uma_observer_.get()); | 997 native_peer_connection_->RegisterUMAObserver(uma_observer_.get()); |
| 901 return true; | 998 return true; |
| 902 } | 999 } |
| 903 | 1000 |
| 904 bool RTCPeerConnectionHandler::InitializeForTest( | 1001 bool RTCPeerConnectionHandler::InitializeForTest( |
| 905 const blink::WebRTCConfiguration& server_configuration, | 1002 const blink::WebRTCConfiguration& server_configuration, |
| 906 const blink::WebMediaConstraints& options, | 1003 const blink::WebMediaConstraints& options, |
| 907 const base::WeakPtr<PeerConnectionTracker>& peer_connection_tracker) { | 1004 const base::WeakPtr<PeerConnectionTracker>& peer_connection_tracker) { |
| 908 DCHECK(thread_checker_.CalledOnValidThread()); | 1005 DCHECK(thread_checker_.CalledOnValidThread()); |
| 909 webrtc::PeerConnectionInterface::RTCConfiguration config; | 1006 webrtc::PeerConnectionInterface::RTCConfiguration config; |
| 910 GetNativeRtcConfiguration(server_configuration, &config); | 1007 GetNativeRtcConfiguration(server_configuration, &config); |
| 911 | 1008 |
| 912 peer_connection_observer_ = new Observer(weak_factory_.GetWeakPtr()); | 1009 peer_connection_observer_ = new Observer(weak_factory_.GetWeakPtr()); |
| 913 RTCMediaConstraints constraints(options); | 1010 CopyConstraintsIntoRtcConfiguration(options, &config); |
| 1011 |
| 914 native_peer_connection_ = dependency_factory_->CreatePeerConnection( | 1012 native_peer_connection_ = dependency_factory_->CreatePeerConnection( |
| 915 config, &constraints, NULL, peer_connection_observer_.get()); | 1013 config, nullptr, peer_connection_observer_.get()); |
| 916 if (!native_peer_connection_.get()) { | 1014 if (!native_peer_connection_.get()) { |
| 917 LOG(ERROR) << "Failed to initialize native PeerConnection."; | 1015 LOG(ERROR) << "Failed to initialize native PeerConnection."; |
| 918 return false; | 1016 return false; |
| 919 } | 1017 } |
| 920 peer_connection_tracker_ = peer_connection_tracker; | 1018 peer_connection_tracker_ = peer_connection_tracker; |
| 921 return true; | 1019 return true; |
| 922 } | 1020 } |
| 923 | 1021 |
| 924 void RTCPeerConnectionHandler::createOffer( | 1022 void RTCPeerConnectionHandler::createOffer( |
| 925 const blink::WebRTCSessionDescriptionRequest& request, | 1023 const blink::WebRTCSessionDescriptionRequest& request, |
| 926 const blink::WebMediaConstraints& options) { | 1024 const blink::WebMediaConstraints& options) { |
| 927 DCHECK(thread_checker_.CalledOnValidThread()); | 1025 DCHECK(thread_checker_.CalledOnValidThread()); |
| 928 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createOffer"); | 1026 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createOffer"); |
| 929 | 1027 |
| 930 scoped_refptr<CreateSessionDescriptionRequest> description_request( | 1028 scoped_refptr<CreateSessionDescriptionRequest> description_request( |
| 931 new rtc::RefCountedObject<CreateSessionDescriptionRequest>( | 1029 new rtc::RefCountedObject<CreateSessionDescriptionRequest>( |
| 932 base::ThreadTaskRunnerHandle::Get(), request, | 1030 base::ThreadTaskRunnerHandle::Get(), request, |
| 933 weak_factory_.GetWeakPtr(), peer_connection_tracker_, | 1031 weak_factory_.GetWeakPtr(), peer_connection_tracker_, |
| 934 PeerConnectionTracker::ACTION_CREATE_OFFER)); | 1032 PeerConnectionTracker::ACTION_CREATE_OFFER)); |
| 935 | 1033 |
| 936 // TODO(tommi): Do this asynchronously via e.g. PostTaskAndReply. | 1034 // TODO(tommi): Do this asynchronously via e.g. PostTaskAndReply. |
| 937 RTCMediaConstraints constraints(options); | 1035 webrtc::PeerConnectionInterface::RTCOfferAnswerOptions webrtc_options; |
| 938 native_peer_connection_->CreateOffer(description_request.get(), &constraints); | 1036 ConvertConstraintsToWebrtcOfferOptions(options, &webrtc_options); |
| 1037 native_peer_connection_->CreateOffer(description_request.get(), |
| 1038 webrtc_options); |
| 939 | 1039 |
| 940 if (peer_connection_tracker_) | 1040 if (peer_connection_tracker_) |
| 941 peer_connection_tracker_->TrackCreateOffer(this, options); | 1041 peer_connection_tracker_->TrackCreateOffer(this, options); |
| 942 } | 1042 } |
| 943 | 1043 |
| 944 void RTCPeerConnectionHandler::createOffer( | 1044 void RTCPeerConnectionHandler::createOffer( |
| 945 const blink::WebRTCSessionDescriptionRequest& request, | 1045 const blink::WebRTCSessionDescriptionRequest& request, |
| 946 const blink::WebRTCOfferOptions& options) { | 1046 const blink::WebRTCOfferOptions& options) { |
| 947 DCHECK(thread_checker_.CalledOnValidThread()); | 1047 DCHECK(thread_checker_.CalledOnValidThread()); |
| 948 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createOffer"); | 1048 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createOffer"); |
| 949 | 1049 |
| 950 scoped_refptr<CreateSessionDescriptionRequest> description_request( | 1050 scoped_refptr<CreateSessionDescriptionRequest> description_request( |
| 951 new rtc::RefCountedObject<CreateSessionDescriptionRequest>( | 1051 new rtc::RefCountedObject<CreateSessionDescriptionRequest>( |
| 952 base::ThreadTaskRunnerHandle::Get(), request, | 1052 base::ThreadTaskRunnerHandle::Get(), request, |
| 953 weak_factory_.GetWeakPtr(), peer_connection_tracker_, | 1053 weak_factory_.GetWeakPtr(), peer_connection_tracker_, |
| 954 PeerConnectionTracker::ACTION_CREATE_OFFER)); | 1054 PeerConnectionTracker::ACTION_CREATE_OFFER)); |
| 955 | 1055 |
| 956 // TODO(tommi): Do this asynchronously via e.g. PostTaskAndReply. | 1056 // TODO(tommi): Do this asynchronously via e.g. PostTaskAndReply. |
| 957 RTCMediaConstraints constraints; | 1057 webrtc::PeerConnectionInterface::RTCOfferAnswerOptions webrtc_options; |
| 958 ConvertOfferOptionsToConstraints(options, &constraints); | 1058 ConvertOfferOptionsToWebrtcOfferOptions(options, &webrtc_options); |
| 959 native_peer_connection_->CreateOffer(description_request.get(), &constraints); | 1059 native_peer_connection_->CreateOffer(description_request.get(), |
| 1060 webrtc_options); |
| 960 | 1061 |
| 961 if (peer_connection_tracker_) | 1062 if (peer_connection_tracker_) |
| 962 peer_connection_tracker_->TrackCreateOffer(this, options); | 1063 peer_connection_tracker_->TrackCreateOffer(this, options); |
| 963 } | 1064 } |
| 964 | 1065 |
| 965 void RTCPeerConnectionHandler::createAnswer( | 1066 void RTCPeerConnectionHandler::createAnswer( |
| 966 const blink::WebRTCSessionDescriptionRequest& request, | 1067 const blink::WebRTCSessionDescriptionRequest& request, |
| 967 const blink::WebMediaConstraints& options) { | 1068 const blink::WebMediaConstraints& options) { |
| 968 DCHECK(thread_checker_.CalledOnValidThread()); | 1069 DCHECK(thread_checker_.CalledOnValidThread()); |
| 969 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createAnswer"); | 1070 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createAnswer"); |
| 970 scoped_refptr<CreateSessionDescriptionRequest> description_request( | 1071 scoped_refptr<CreateSessionDescriptionRequest> description_request( |
| 971 new rtc::RefCountedObject<CreateSessionDescriptionRequest>( | 1072 new rtc::RefCountedObject<CreateSessionDescriptionRequest>( |
| 972 base::ThreadTaskRunnerHandle::Get(), request, | 1073 base::ThreadTaskRunnerHandle::Get(), request, |
| 973 weak_factory_.GetWeakPtr(), peer_connection_tracker_, | 1074 weak_factory_.GetWeakPtr(), peer_connection_tracker_, |
| 974 PeerConnectionTracker::ACTION_CREATE_ANSWER)); | 1075 PeerConnectionTracker::ACTION_CREATE_ANSWER)); |
| 1076 webrtc::PeerConnectionInterface::RTCOfferAnswerOptions webrtc_options; |
| 1077 ConvertConstraintsToWebrtcOfferOptions(options, &webrtc_options); |
| 975 // TODO(tommi): Do this asynchronously via e.g. PostTaskAndReply. | 1078 // TODO(tommi): Do this asynchronously via e.g. PostTaskAndReply. |
| 976 RTCMediaConstraints constraints(options); | |
| 977 native_peer_connection_->CreateAnswer(description_request.get(), | 1079 native_peer_connection_->CreateAnswer(description_request.get(), |
| 978 &constraints); | 1080 webrtc_options); |
| 979 | 1081 |
| 980 if (peer_connection_tracker_) | 1082 if (peer_connection_tracker_) |
| 981 peer_connection_tracker_->TrackCreateAnswer(this, options); | 1083 peer_connection_tracker_->TrackCreateAnswer(this, options); |
| 982 } | 1084 } |
| 983 | 1085 |
| 984 bool IsOfferOrAnswer(const webrtc::SessionDescriptionInterface* native_desc) { | 1086 bool IsOfferOrAnswer(const webrtc::SessionDescriptionInterface* native_desc) { |
| 985 DCHECK(native_desc); | 1087 DCHECK(native_desc); |
| 986 return native_desc->type() == "offer" || native_desc->type() == "answer"; | 1088 return native_desc->type() == "offer" || native_desc->type() == "answer"; |
| 987 } | 1089 } |
| 988 | 1090 |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1125 native_peer_connection_); | 1227 native_peer_connection_); |
| 1126 RunSynchronousClosureOnSignalingThread( | 1228 RunSynchronousClosureOnSignalingThread( |
| 1127 base::Bind(&GetSdpAndTypeFromSessionDescription, description_cb, | 1229 base::Bind(&GetSdpAndTypeFromSessionDescription, description_cb, |
| 1128 base::Unretained(&sdp), base::Unretained(&type)), | 1230 base::Unretained(&sdp), base::Unretained(&type)), |
| 1129 "remoteDescription"); | 1231 "remoteDescription"); |
| 1130 | 1232 |
| 1131 return CreateWebKitSessionDescription(sdp, type); | 1233 return CreateWebKitSessionDescription(sdp, type); |
| 1132 } | 1234 } |
| 1133 | 1235 |
| 1134 bool RTCPeerConnectionHandler::updateICE( | 1236 bool RTCPeerConnectionHandler::updateICE( |
| 1135 const blink::WebRTCConfiguration& server_configuration, | 1237 const blink::WebRTCConfiguration& server_configuration) { |
| 1136 const blink::WebMediaConstraints& options) { | |
| 1137 DCHECK(thread_checker_.CalledOnValidThread()); | 1238 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1138 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::updateICE"); | 1239 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::updateICE"); |
| 1139 webrtc::PeerConnectionInterface::RTCConfiguration config; | 1240 webrtc::PeerConnectionInterface::RTCConfiguration config; |
| 1140 GetNativeRtcConfiguration(server_configuration, &config); | 1241 GetNativeRtcConfiguration(server_configuration, &config); |
| 1141 RTCMediaConstraints constraints(options); | |
| 1142 | 1242 |
| 1143 if (peer_connection_tracker_) | 1243 if (peer_connection_tracker_) |
| 1144 peer_connection_tracker_->TrackUpdateIce(this, config, options); | 1244 peer_connection_tracker_->TrackUpdateIce(this, config); |
| 1145 | 1245 |
| 1146 return native_peer_connection_->UpdateIce(config.servers, &constraints); | 1246 return native_peer_connection_->UpdateIce(config.servers); |
| 1147 } | 1247 } |
| 1148 | 1248 |
| 1149 bool RTCPeerConnectionHandler::addICECandidate( | 1249 bool RTCPeerConnectionHandler::addICECandidate( |
| 1150 const blink::WebRTCVoidRequest& request, | 1250 const blink::WebRTCVoidRequest& request, |
| 1151 const blink::WebRTCICECandidate& candidate) { | 1251 const blink::WebRTCICECandidate& candidate) { |
| 1152 DCHECK(thread_checker_.CalledOnValidThread()); | 1252 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1153 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::addICECandidate"); | 1253 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::addICECandidate"); |
| 1154 // Libjingle currently does not accept callbacks for addICECandidate. | 1254 // Libjingle currently does not accept callbacks for addICECandidate. |
| 1155 // For that reason we are going to call callbacks from here. | 1255 // For that reason we are going to call callbacks from here. |
| 1156 | 1256 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1227 PerSessionWebRTCAPIMetrics::GetInstance()->IncrementStreamCounter(); | 1327 PerSessionWebRTCAPIMetrics::GetInstance()->IncrementStreamCounter(); |
| 1228 | 1328 |
| 1229 WebRtcMediaStreamAdapter* adapter = | 1329 WebRtcMediaStreamAdapter* adapter = |
| 1230 new WebRtcMediaStreamAdapter(stream, dependency_factory_); | 1330 new WebRtcMediaStreamAdapter(stream, dependency_factory_); |
| 1231 local_streams_.push_back(adapter); | 1331 local_streams_.push_back(adapter); |
| 1232 | 1332 |
| 1233 webrtc::MediaStreamInterface* webrtc_stream = adapter->webrtc_media_stream(); | 1333 webrtc::MediaStreamInterface* webrtc_stream = adapter->webrtc_media_stream(); |
| 1234 track_metrics_.AddStream(MediaStreamTrackMetrics::SENT_STREAM, | 1334 track_metrics_.AddStream(MediaStreamTrackMetrics::SENT_STREAM, |
| 1235 webrtc_stream); | 1335 webrtc_stream); |
| 1236 | 1336 |
| 1237 RTCMediaConstraints constraints(options); | 1337 if (!options.isEmpty()) { |
| 1238 if (!constraints.GetMandatory().empty() || | |
| 1239 !constraints.GetOptional().empty()) { | |
| 1240 // TODO(perkj): |mediaConstraints| is the name of the optional constraints | 1338 // TODO(perkj): |mediaConstraints| is the name of the optional constraints |
| 1241 // argument in RTCPeerConnection.idl. It has been removed from the spec and | 1339 // argument in RTCPeerConnection.idl. It has been removed from the spec and |
| 1242 // should be removed from blink as well. | 1340 // should be removed from blink as well. |
| 1243 LOG(WARNING) | 1341 LOG(WARNING) |
| 1244 << "mediaConstraints is not a supported argument to addStream."; | 1342 << "mediaConstraints is not a supported argument to addStream."; |
| 1343 LOG(WARNING) << "mediaConstraints was " << options.toString().utf8(); |
| 1245 } | 1344 } |
| 1246 | 1345 |
| 1247 return native_peer_connection_->AddStream(webrtc_stream); | 1346 return native_peer_connection_->AddStream(webrtc_stream); |
| 1248 } | 1347 } |
| 1249 | 1348 |
| 1250 void RTCPeerConnectionHandler::removeStream( | 1349 void RTCPeerConnectionHandler::removeStream( |
| 1251 const blink::WebMediaStream& stream) { | 1350 const blink::WebMediaStream& stream) { |
| 1252 DCHECK(thread_checker_.CalledOnValidThread()); | 1351 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1253 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::removeStream"); | 1352 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::removeStream"); |
| 1254 // Find the webrtc stream. | 1353 // Find the webrtc stream. |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1671 } | 1770 } |
| 1672 | 1771 |
| 1673 void RTCPeerConnectionHandler::ResetUMAStats() { | 1772 void RTCPeerConnectionHandler::ResetUMAStats() { |
| 1674 DCHECK(thread_checker_.CalledOnValidThread()); | 1773 DCHECK(thread_checker_.CalledOnValidThread()); |
| 1675 num_local_candidates_ipv6_ = 0; | 1774 num_local_candidates_ipv6_ = 0; |
| 1676 num_local_candidates_ipv4_ = 0; | 1775 num_local_candidates_ipv4_ = 0; |
| 1677 ice_connection_checking_start_ = base::TimeTicks(); | 1776 ice_connection_checking_start_ = base::TimeTicks(); |
| 1678 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); | 1777 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); |
| 1679 } | 1778 } |
| 1680 } // namespace content | 1779 } // namespace content |
| OLD | NEW |