Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(232)

Side by Side Diff: content/renderer/media/rtc_peer_connection_handler.cc

Issue 1729683002: Remove old-style constraints from Chrome internals (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: CL ready to submit Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
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 std::string failing_name;
tommi (sloooow) - chröme 2016/03/14 18:37:47 move scope to where it's needed
hta - Chromium 2016/03/15 06:47:33 Done.
848 930 if (constraints.isEmpty()) {
849 if (!options.voiceActivityDetection()) { 931 return;
850 output->AddMandatory(
851 webrtc::MediaConstraintsInterface::kVoiceActivityDetection,
852 "false",
853 true);
854 } 932 }
855 933 if (constraints.basic().hasMandatoryOutsideSet(
856 if (options.iceRestart()) { 934 {constraints.basic().offerToReceiveAudio.name(),
857 output->AddMandatory( 935 constraints.basic().offerToReceiveVideo.name(),
858 webrtc::MediaConstraintsInterface::kIceRestart, "true", true); 936 constraints.basic().voiceActivityDetection.name(),
937 constraints.basic().iceRestart.name()},
tommi (sloooow) - chröme 2016/03/14 18:37:47 just curious - did |git cl format| format this? (
hta - Chromium 2016/03/15 06:47:33 Yes, it did - I just wrote it and thought "huh", a
938 failing_name)) {
939 // TODO(hta): Reject the calling operation with "constraint error"
Guido Urdaneta 2016/03/14 16:28:21 crbug?
hta - Chromium 2016/03/15 06:47:33 Filed 594894.
940 DLOG(ERROR) << "Invalid mandatory constraint to CreateOffer/Answer: "
941 << failing_name;
859 } 942 }
943 GetConstraintValueAsInteger(
944 constraints, &blink::WebMediaTrackConstraintSet::offerToReceiveAudio,
945 &output->offer_to_receive_audio);
946 GetConstraintValueAsInteger(
947 constraints, &blink::WebMediaTrackConstraintSet::offerToReceiveVideo,
948 &output->offer_to_receive_video);
949 GetConstraintValueAsBoolean(
950 constraints, &blink::WebMediaTrackConstraintSet::voiceActivityDetection,
951 &output->voice_activity_detection);
952 GetConstraintValueAsBoolean(constraints,
953 &blink::WebMediaTrackConstraintSet::iceRestart,
954 &output->ice_restart);
860 } 955 }
861 956
862 void RTCPeerConnectionHandler::associateWithFrame(blink::WebFrame* frame) { 957 void RTCPeerConnectionHandler::associateWithFrame(blink::WebFrame* frame) {
863 DCHECK(thread_checker_.CalledOnValidThread()); 958 DCHECK(thread_checker_.CalledOnValidThread());
864 DCHECK(frame); 959 DCHECK(frame);
865 frame_ = frame; 960 frame_ = frame;
866 } 961 }
867 962
868 bool RTCPeerConnectionHandler::initialize( 963 bool RTCPeerConnectionHandler::initialize(
869 const blink::WebRTCConfiguration& server_configuration, 964 const blink::WebRTCConfiguration& server_configuration,
870 const blink::WebMediaConstraints& options) { 965 const blink::WebMediaConstraints& options) {
871 DCHECK(thread_checker_.CalledOnValidThread()); 966 DCHECK(thread_checker_.CalledOnValidThread());
872 DCHECK(frame_); 967 DCHECK(frame_);
873 968
874 peer_connection_tracker_ = 969 peer_connection_tracker_ =
875 RenderThreadImpl::current()->peer_connection_tracker()->AsWeakPtr(); 970 RenderThreadImpl::current()->peer_connection_tracker()->AsWeakPtr();
876 971
877 webrtc::PeerConnectionInterface::RTCConfiguration config; 972 webrtc::PeerConnectionInterface::RTCConfiguration config;
878 GetNativeRtcConfiguration(server_configuration, &config); 973 GetNativeRtcConfiguration(server_configuration, &config);
879 config.disable_prerenderer_smoothing = 974 config.disable_prerenderer_smoothing =
880 !base::CommandLine::ForCurrentProcess()->HasSwitch( 975 !base::CommandLine::ForCurrentProcess()->HasSwitch(
881 switches::kDisableRTCSmoothnessAlgorithm); 976 switches::kDisableRTCSmoothnessAlgorithm);
882 977
883 RTCMediaConstraints constraints(options); 978 // Copy all the relevant constraints into |config|.
979 CopyConstraintsIntoRtcConfiguration(options, &config);
884 980
885 peer_connection_observer_ = new Observer(weak_factory_.GetWeakPtr()); 981 peer_connection_observer_ = new Observer(weak_factory_.GetWeakPtr());
886 native_peer_connection_ = dependency_factory_->CreatePeerConnection( 982 native_peer_connection_ = dependency_factory_->CreatePeerConnection(
887 config, &constraints, frame_, peer_connection_observer_.get()); 983 config, frame_, peer_connection_observer_.get());
888 984
889 if (!native_peer_connection_.get()) { 985 if (!native_peer_connection_.get()) {
890 LOG(ERROR) << "Failed to initialize native PeerConnection."; 986 LOG(ERROR) << "Failed to initialize native PeerConnection.";
891 return false; 987 return false;
892 } 988 }
893 989
894 if (peer_connection_tracker_) { 990 if (peer_connection_tracker_) {
895 peer_connection_tracker_->RegisterPeerConnection(this, config, options, 991 peer_connection_tracker_->RegisterPeerConnection(this, config, options,
896 frame_); 992 frame_);
897 } 993 }
898 994
899 uma_observer_ = new rtc::RefCountedObject<PeerConnectionUMAObserver>(); 995 uma_observer_ = new rtc::RefCountedObject<PeerConnectionUMAObserver>();
900 native_peer_connection_->RegisterUMAObserver(uma_observer_.get()); 996 native_peer_connection_->RegisterUMAObserver(uma_observer_.get());
901 return true; 997 return true;
902 } 998 }
903 999
904 bool RTCPeerConnectionHandler::InitializeForTest( 1000 bool RTCPeerConnectionHandler::InitializeForTest(
905 const blink::WebRTCConfiguration& server_configuration, 1001 const blink::WebRTCConfiguration& server_configuration,
906 const blink::WebMediaConstraints& options, 1002 const blink::WebMediaConstraints& options,
907 const base::WeakPtr<PeerConnectionTracker>& peer_connection_tracker) { 1003 const base::WeakPtr<PeerConnectionTracker>& peer_connection_tracker) {
908 DCHECK(thread_checker_.CalledOnValidThread()); 1004 DCHECK(thread_checker_.CalledOnValidThread());
909 webrtc::PeerConnectionInterface::RTCConfiguration config; 1005 webrtc::PeerConnectionInterface::RTCConfiguration config;
910 GetNativeRtcConfiguration(server_configuration, &config); 1006 GetNativeRtcConfiguration(server_configuration, &config);
911 1007
912 peer_connection_observer_ = new Observer(weak_factory_.GetWeakPtr()); 1008 peer_connection_observer_ = new Observer(weak_factory_.GetWeakPtr());
913 RTCMediaConstraints constraints(options); 1009 CopyConstraintsIntoRtcConfiguration(options, &config);
1010
914 native_peer_connection_ = dependency_factory_->CreatePeerConnection( 1011 native_peer_connection_ = dependency_factory_->CreatePeerConnection(
915 config, &constraints, NULL, peer_connection_observer_.get()); 1012 config, nullptr, peer_connection_observer_.get());
916 if (!native_peer_connection_.get()) { 1013 if (!native_peer_connection_.get()) {
917 LOG(ERROR) << "Failed to initialize native PeerConnection."; 1014 LOG(ERROR) << "Failed to initialize native PeerConnection.";
918 return false; 1015 return false;
919 } 1016 }
920 peer_connection_tracker_ = peer_connection_tracker; 1017 peer_connection_tracker_ = peer_connection_tracker;
921 return true; 1018 return true;
922 } 1019 }
923 1020
924 void RTCPeerConnectionHandler::createOffer( 1021 void RTCPeerConnectionHandler::createOffer(
925 const blink::WebRTCSessionDescriptionRequest& request, 1022 const blink::WebRTCSessionDescriptionRequest& request,
926 const blink::WebMediaConstraints& options) { 1023 const blink::WebMediaConstraints& options) {
927 DCHECK(thread_checker_.CalledOnValidThread()); 1024 DCHECK(thread_checker_.CalledOnValidThread());
928 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createOffer"); 1025 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::createOffer");
929 1026
930 scoped_refptr<CreateSessionDescriptionRequest> description_request( 1027 scoped_refptr<CreateSessionDescriptionRequest> description_request(
931 new rtc::RefCountedObject<CreateSessionDescriptionRequest>( 1028 new rtc::RefCountedObject<CreateSessionDescriptionRequest>(
932 base::ThreadTaskRunnerHandle::Get(), request, 1029 base::ThreadTaskRunnerHandle::Get(), request,
933 weak_factory_.GetWeakPtr(), peer_connection_tracker_, 1030 weak_factory_.GetWeakPtr(), peer_connection_tracker_,
934 PeerConnectionTracker::ACTION_CREATE_OFFER)); 1031 PeerConnectionTracker::ACTION_CREATE_OFFER));
935 1032
936 // TODO(tommi): Do this asynchronously via e.g. PostTaskAndReply. 1033 // TODO(tommi): Do this asynchronously via e.g. PostTaskAndReply.
937 RTCMediaConstraints constraints(options); 1034 webrtc::PeerConnectionInterface::RTCOfferAnswerOptions webrtc_options;
938 native_peer_connection_->CreateOffer(description_request.get(), &constraints); 1035 ConvertConstraintsToWebrtcOfferOptions(options, &webrtc_options);
1036 // TODO(hta): Convert
Guido Urdaneta 2016/03/14 16:28:21 Convert what?
hta - Chromium 2016/03/15 06:47:33 Leftover comment. Removing.
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 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) { 1238 const blink::WebMediaConstraints& options) {
1137 DCHECK(thread_checker_.CalledOnValidThread()); 1239 DCHECK(thread_checker_.CalledOnValidThread());
1138 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::updateICE"); 1240 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::updateICE");
1139 webrtc::PeerConnectionInterface::RTCConfiguration config; 1241 webrtc::PeerConnectionInterface::RTCConfiguration config;
1140 GetNativeRtcConfiguration(server_configuration, &config); 1242 GetNativeRtcConfiguration(server_configuration, &config);
1141 RTCMediaConstraints constraints(options);
1142 1243
1143 if (peer_connection_tracker_) 1244 if (peer_connection_tracker_)
1144 peer_connection_tracker_->TrackUpdateIce(this, config, options); 1245 peer_connection_tracker_->TrackUpdateIce(this, config, options);
Guido Urdaneta 2016/03/14 16:28:21 should options be removed from here too? should it
hta - Chromium 2016/03/15 06:47:33 Yes, it should. Removing.
1145 1246
1146 return native_peer_connection_->UpdateIce(config.servers, &constraints); 1247 return native_peer_connection_->UpdateIce(config.servers);
1147 } 1248 }
1148 1249
1149 bool RTCPeerConnectionHandler::addICECandidate( 1250 bool RTCPeerConnectionHandler::addICECandidate(
1150 const blink::WebRTCVoidRequest& request, 1251 const blink::WebRTCVoidRequest& request,
1151 const blink::WebRTCICECandidate& candidate) { 1252 const blink::WebRTCICECandidate& candidate) {
1152 DCHECK(thread_checker_.CalledOnValidThread()); 1253 DCHECK(thread_checker_.CalledOnValidThread());
1153 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::addICECandidate"); 1254 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::addICECandidate");
1154 // Libjingle currently does not accept callbacks for addICECandidate. 1255 // Libjingle currently does not accept callbacks for addICECandidate.
1155 // For that reason we are going to call callbacks from here. 1256 // For that reason we are going to call callbacks from here.
1156 1257
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1227 PerSessionWebRTCAPIMetrics::GetInstance()->IncrementStreamCounter(); 1328 PerSessionWebRTCAPIMetrics::GetInstance()->IncrementStreamCounter();
1228 1329
1229 WebRtcMediaStreamAdapter* adapter = 1330 WebRtcMediaStreamAdapter* adapter =
1230 new WebRtcMediaStreamAdapter(stream, dependency_factory_); 1331 new WebRtcMediaStreamAdapter(stream, dependency_factory_);
1231 local_streams_.push_back(adapter); 1332 local_streams_.push_back(adapter);
1232 1333
1233 webrtc::MediaStreamInterface* webrtc_stream = adapter->webrtc_media_stream(); 1334 webrtc::MediaStreamInterface* webrtc_stream = adapter->webrtc_media_stream();
1234 track_metrics_.AddStream(MediaStreamTrackMetrics::SENT_STREAM, 1335 track_metrics_.AddStream(MediaStreamTrackMetrics::SENT_STREAM,
1235 webrtc_stream); 1336 webrtc_stream);
1236 1337
1237 RTCMediaConstraints constraints(options); 1338 if (!options.isEmpty()) {
1238 if (!constraints.GetMandatory().empty() ||
1239 !constraints.GetOptional().empty()) {
1240 // TODO(perkj): |mediaConstraints| is the name of the optional constraints 1339 // TODO(perkj): |mediaConstraints| is the name of the optional constraints
1241 // argument in RTCPeerConnection.idl. It has been removed from the spec and 1340 // argument in RTCPeerConnection.idl. It has been removed from the spec and
1242 // should be removed from blink as well. 1341 // should be removed from blink as well.
1243 LOG(WARNING) 1342 LOG(WARNING)
1244 << "mediaConstraints is not a supported argument to addStream."; 1343 << "mediaConstraints is not a supported argument to addStream.";
1344 LOG(WARNING) << "mediaConstraints was " << options.toString().utf8();
1245 } 1345 }
1246 1346
1247 return native_peer_connection_->AddStream(webrtc_stream); 1347 return native_peer_connection_->AddStream(webrtc_stream);
1248 } 1348 }
1249 1349
1250 void RTCPeerConnectionHandler::removeStream( 1350 void RTCPeerConnectionHandler::removeStream(
1251 const blink::WebMediaStream& stream) { 1351 const blink::WebMediaStream& stream) {
1252 DCHECK(thread_checker_.CalledOnValidThread()); 1352 DCHECK(thread_checker_.CalledOnValidThread());
1253 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::removeStream"); 1353 TRACE_EVENT0("webrtc", "RTCPeerConnectionHandler::removeStream");
1254 // Find the webrtc stream. 1354 // Find the webrtc stream.
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after
1671 } 1771 }
1672 1772
1673 void RTCPeerConnectionHandler::ResetUMAStats() { 1773 void RTCPeerConnectionHandler::ResetUMAStats() {
1674 DCHECK(thread_checker_.CalledOnValidThread()); 1774 DCHECK(thread_checker_.CalledOnValidThread());
1675 num_local_candidates_ipv6_ = 0; 1775 num_local_candidates_ipv6_ = 0;
1676 num_local_candidates_ipv4_ = 0; 1776 num_local_candidates_ipv4_ = 0;
1677 ice_connection_checking_start_ = base::TimeTicks(); 1777 ice_connection_checking_start_ = base::TimeTicks();
1678 memset(ice_state_seen_, 0, sizeof(ice_state_seen_)); 1778 memset(ice_state_seen_, 0, sizeof(ice_state_seen_));
1679 } 1779 }
1680 } // namespace content 1780 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698