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

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

Issue 396193005: Converts RTCOfferOptions to constriants in the glue code for createOffer. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix sync Created 6 years, 5 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> 7 #include <string>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 16 matching lines...) Expand all
27 #include "content/renderer/media/webrtc/webrtc_media_stream_adapter.h" 27 #include "content/renderer/media/webrtc/webrtc_media_stream_adapter.h"
28 #include "content/renderer/media/webrtc_audio_capturer.h" 28 #include "content/renderer/media/webrtc_audio_capturer.h"
29 #include "content/renderer/media/webrtc_audio_device_impl.h" 29 #include "content/renderer/media/webrtc_audio_device_impl.h"
30 #include "content/renderer/media/webrtc_uma_histograms.h" 30 #include "content/renderer/media/webrtc_uma_histograms.h"
31 #include "content/renderer/render_thread_impl.h" 31 #include "content/renderer/render_thread_impl.h"
32 #include "third_party/WebKit/public/platform/WebMediaConstraints.h" 32 #include "third_party/WebKit/public/platform/WebMediaConstraints.h"
33 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h" 33 #include "third_party/WebKit/public/platform/WebMediaStreamSource.h"
34 #include "third_party/WebKit/public/platform/WebRTCConfiguration.h" 34 #include "third_party/WebKit/public/platform/WebRTCConfiguration.h"
35 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" 35 #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h"
36 #include "third_party/WebKit/public/platform/WebRTCICECandidate.h" 36 #include "third_party/WebKit/public/platform/WebRTCICECandidate.h"
37 #include "third_party/WebKit/public/platform/WebRTCOfferOptions.h"
37 #include "third_party/WebKit/public/platform/WebRTCSessionDescription.h" 38 #include "third_party/WebKit/public/platform/WebRTCSessionDescription.h"
38 #include "third_party/WebKit/public/platform/WebRTCSessionDescriptionRequest.h" 39 #include "third_party/WebKit/public/platform/WebRTCSessionDescriptionRequest.h"
39 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h" 40 #include "third_party/WebKit/public/platform/WebRTCVoidRequest.h"
40 #include "third_party/WebKit/public/platform/WebURL.h" 41 #include "third_party/WebKit/public/platform/WebURL.h"
41 42
42 namespace content { 43 namespace content {
43 44
44 // Converter functions from libjingle types to WebKit types. 45 // Converter functions from libjingle types to WebKit types.
45 blink::WebRTCPeerConnectionHandlerClient::ICEGatheringState 46 blink::WebRTCPeerConnectionHandlerClient::ICEGatheringState
46 GetWebKitIceGatheringState( 47 GetWebKitIceGatheringState(
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 return description; 123 return description;
123 } 124 }
124 125
125 description.initialize(base::UTF8ToUTF16(native_desc->type()), 126 description.initialize(base::UTF8ToUTF16(native_desc->type()),
126 base::UTF8ToUTF16(sdp)); 127 base::UTF8ToUTF16(sdp));
127 return description; 128 return description;
128 } 129 }
129 130
130 // Converter functions from WebKit types to libjingle types. 131 // Converter functions from WebKit types to libjingle types.
131 132
132 static void GetNativeIceServers( 133 static void GetNativeRtcConfiguration(
133 const blink::WebRTCConfiguration& server_configuration, 134 const blink::WebRTCConfiguration& server_configuration,
134 webrtc::PeerConnectionInterface::IceServers* servers) { 135 webrtc::PeerConnectionInterface::RTCConfiguration* config) {
135 if (server_configuration.isNull() || !servers) 136 if (server_configuration.isNull() || !config)
136 return; 137 return;
137 for (size_t i = 0; i < server_configuration.numberOfServers(); ++i) { 138 for (size_t i = 0; i < server_configuration.numberOfServers(); ++i) {
138 webrtc::PeerConnectionInterface::IceServer server; 139 webrtc::PeerConnectionInterface::IceServer server;
139 const blink::WebRTCICEServer& webkit_server = 140 const blink::WebRTCICEServer& webkit_server =
140 server_configuration.server(i); 141 server_configuration.server(i);
141 server.username = base::UTF16ToUTF8(webkit_server.username()); 142 server.username = base::UTF16ToUTF8(webkit_server.username());
142 server.password = base::UTF16ToUTF8(webkit_server.credential()); 143 server.password = base::UTF16ToUTF8(webkit_server.credential());
143 server.uri = webkit_server.uri().spec(); 144 server.uri = webkit_server.uri().spec();
144 servers->push_back(server); 145 config->servers.push_back(server);
146 }
147
148 switch (server_configuration.iceTransports()) {
149 case blink::WebRTCIceTransportsNone:
150 config->type = webrtc::PeerConnectionInterface::kNone;
151 break;
152 case blink::WebRTCIceTransportsRelay:
153 config->type = webrtc::PeerConnectionInterface::kRelay;
154 break;
155 case blink::WebRTCIceTransportsAll:
156 config->type = webrtc::PeerConnectionInterface::kAll;
157 break;
158 default:
159 NOTREACHED();
145 } 160 }
146 } 161 }
147 162
148 class SessionDescriptionRequestTracker { 163 class SessionDescriptionRequestTracker {
149 public: 164 public:
150 SessionDescriptionRequestTracker(RTCPeerConnectionHandler* handler, 165 SessionDescriptionRequestTracker(RTCPeerConnectionHandler* handler,
151 PeerConnectionTracker::Action action) 166 PeerConnectionTracker::Action action)
152 : handler_(handler), action_(action) {} 167 : handler_(handler), action_(action) {}
153 168
154 void TrackOnSuccess(const webrtc::SessionDescriptionInterface* desc) { 169 void TrackOnSuccess(const webrtc::SessionDescriptionInterface* desc) {
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 std::set<RTCPeerConnectionHandler*> handlers( 409 std::set<RTCPeerConnectionHandler*> handlers(
395 g_peer_connection_handlers.Get().begin(), 410 g_peer_connection_handlers.Get().begin(),
396 g_peer_connection_handlers.Get().end()); 411 g_peer_connection_handlers.Get().end());
397 for (std::set<RTCPeerConnectionHandler*>::iterator handler = handlers.begin(); 412 for (std::set<RTCPeerConnectionHandler*>::iterator handler = handlers.begin();
398 handler != handlers.end(); 413 handler != handlers.end();
399 ++handler) { 414 ++handler) {
400 (*handler)->client_->releasePeerConnectionHandler(); 415 (*handler)->client_->releasePeerConnectionHandler();
401 } 416 }
402 } 417 }
403 418
419 void RTCPeerConnectionHandler::ConvertOfferOptionsToConstraints(
420 const blink::WebRTCOfferOptions& options,
421 RTCMediaConstraints* output) {
422 output->AddMandatory(
423 webrtc::MediaConstraintsInterface::kOfferToReceiveAudio,
424 options.offerToReceiveAudio() > 0 ? "true" : "false",
425 true);
426
427 output->AddMandatory(
428 webrtc::MediaConstraintsInterface::kOfferToReceiveVideo,
429 options.offerToReceiveVideo() > 0 ? "true" : "false",
430 true);
431
432 if (!options.voiceActivityDetection()) {
433 output->AddMandatory(
434 webrtc::MediaConstraintsInterface::kVoiceActivityDetection,
435 "false",
436 true);
437 }
438
439 if (options.iceRestart()) {
440 output->AddMandatory(
441 webrtc::MediaConstraintsInterface::kIceRestart, "true", true);
442 }
443 }
444
404 void RTCPeerConnectionHandler::associateWithFrame(blink::WebFrame* frame) { 445 void RTCPeerConnectionHandler::associateWithFrame(blink::WebFrame* frame) {
405 DCHECK(frame); 446 DCHECK(frame);
406 frame_ = frame; 447 frame_ = frame;
407 } 448 }
408 449
409 bool RTCPeerConnectionHandler::initialize( 450 bool RTCPeerConnectionHandler::initialize(
410 const blink::WebRTCConfiguration& server_configuration, 451 const blink::WebRTCConfiguration& server_configuration,
411 const blink::WebMediaConstraints& options) { 452 const blink::WebMediaConstraints& options) {
412 DCHECK(frame_); 453 DCHECK(frame_);
413 454
414 peer_connection_tracker_ = 455 peer_connection_tracker_ =
415 RenderThreadImpl::current()->peer_connection_tracker(); 456 RenderThreadImpl::current()->peer_connection_tracker();
416 457
417 webrtc::PeerConnectionInterface::IceServers servers; 458 webrtc::PeerConnectionInterface::RTCConfiguration config;
418 GetNativeIceServers(server_configuration, &servers); 459 GetNativeRtcConfiguration(server_configuration, &config);
419 460
420 RTCMediaConstraints constraints(options); 461 RTCMediaConstraints constraints(options);
421 462
422 native_peer_connection_ = 463 native_peer_connection_ =
423 dependency_factory_->CreatePeerConnection( 464 dependency_factory_->CreatePeerConnection(
424 servers, &constraints, frame_, this); 465 config, &constraints, frame_, this);
466
425 if (!native_peer_connection_.get()) { 467 if (!native_peer_connection_.get()) {
426 LOG(ERROR) << "Failed to initialize native PeerConnection."; 468 LOG(ERROR) << "Failed to initialize native PeerConnection.";
427 return false; 469 return false;
428 } 470 }
429 if (peer_connection_tracker_) 471 if (peer_connection_tracker_)
430 peer_connection_tracker_->RegisterPeerConnection( 472 peer_connection_tracker_->RegisterPeerConnection(
431 this, servers, constraints, frame_); 473 this, config, constraints, frame_);
432 474
433 uma_observer_ = new talk_base::RefCountedObject<PeerConnectionUMAObserver>(); 475 uma_observer_ = new talk_base::RefCountedObject<PeerConnectionUMAObserver>();
434 native_peer_connection_->RegisterUMAObserver(uma_observer_.get()); 476 native_peer_connection_->RegisterUMAObserver(uma_observer_.get());
435 return true; 477 return true;
436 } 478 }
437 479
438 bool RTCPeerConnectionHandler::InitializeForTest( 480 bool RTCPeerConnectionHandler::InitializeForTest(
439 const blink::WebRTCConfiguration& server_configuration, 481 const blink::WebRTCConfiguration& server_configuration,
440 const blink::WebMediaConstraints& options, 482 const blink::WebMediaConstraints& options,
441 PeerConnectionTracker* peer_connection_tracker) { 483 PeerConnectionTracker* peer_connection_tracker) {
442 webrtc::PeerConnectionInterface::IceServers servers; 484 webrtc::PeerConnectionInterface::RTCConfiguration config;
443 GetNativeIceServers(server_configuration, &servers); 485 GetNativeRtcConfiguration(server_configuration, &config);
444 486
445 RTCMediaConstraints constraints(options); 487 RTCMediaConstraints constraints(options);
446 native_peer_connection_ = 488 native_peer_connection_ =
447 dependency_factory_->CreatePeerConnection( 489 dependency_factory_->CreatePeerConnection(
448 servers, &constraints, NULL, this); 490 config, &constraints, NULL, this);
449 if (!native_peer_connection_.get()) { 491 if (!native_peer_connection_.get()) {
450 LOG(ERROR) << "Failed to initialize native PeerConnection."; 492 LOG(ERROR) << "Failed to initialize native PeerConnection.";
451 return false; 493 return false;
452 } 494 }
453 peer_connection_tracker_ = peer_connection_tracker; 495 peer_connection_tracker_ = peer_connection_tracker;
454 return true; 496 return true;
455 } 497 }
456 498
457 void RTCPeerConnectionHandler::createOffer( 499 void RTCPeerConnectionHandler::createOffer(
458 const blink::WebRTCSessionDescriptionRequest& request, 500 const blink::WebRTCSessionDescriptionRequest& request,
459 const blink::WebMediaConstraints& options) { 501 const blink::WebMediaConstraints& options) {
460 scoped_refptr<CreateSessionDescriptionRequest> description_request( 502 scoped_refptr<CreateSessionDescriptionRequest> description_request(
461 new talk_base::RefCountedObject<CreateSessionDescriptionRequest>( 503 new talk_base::RefCountedObject<CreateSessionDescriptionRequest>(
462 request, this, PeerConnectionTracker::ACTION_CREATE_OFFER)); 504 request, this, PeerConnectionTracker::ACTION_CREATE_OFFER));
463 RTCMediaConstraints constraints(options); 505 RTCMediaConstraints constraints(options);
464 native_peer_connection_->CreateOffer(description_request.get(), &constraints); 506 native_peer_connection_->CreateOffer(description_request.get(), &constraints);
465 507
466 if (peer_connection_tracker_) 508 if (peer_connection_tracker_)
467 peer_connection_tracker_->TrackCreateOffer(this, constraints); 509 peer_connection_tracker_->TrackCreateOffer(this, constraints);
468 } 510 }
469 511
512 void RTCPeerConnectionHandler::createOffer(
513 const blink::WebRTCSessionDescriptionRequest& request,
514 const blink::WebRTCOfferOptions& options) {
515 scoped_refptr<CreateSessionDescriptionRequest> description_request(
516 new talk_base::RefCountedObject<CreateSessionDescriptionRequest>(
517 request, this, PeerConnectionTracker::ACTION_CREATE_OFFER));
518
519 RTCMediaConstraints constraints;
520 ConvertOfferOptionsToConstraints(options, &constraints);
521 native_peer_connection_->CreateOffer(description_request.get(), &constraints);
522
523 if (peer_connection_tracker_)
524 peer_connection_tracker_->TrackCreateOffer(this, constraints);
525 }
526
470 void RTCPeerConnectionHandler::createAnswer( 527 void RTCPeerConnectionHandler::createAnswer(
471 const blink::WebRTCSessionDescriptionRequest& request, 528 const blink::WebRTCSessionDescriptionRequest& request,
472 const blink::WebMediaConstraints& options) { 529 const blink::WebMediaConstraints& options) {
473 scoped_refptr<CreateSessionDescriptionRequest> description_request( 530 scoped_refptr<CreateSessionDescriptionRequest> description_request(
474 new talk_base::RefCountedObject<CreateSessionDescriptionRequest>( 531 new talk_base::RefCountedObject<CreateSessionDescriptionRequest>(
475 request, this, PeerConnectionTracker::ACTION_CREATE_ANSWER)); 532 request, this, PeerConnectionTracker::ACTION_CREATE_ANSWER));
476 RTCMediaConstraints constraints(options); 533 RTCMediaConstraints constraints(options);
477 native_peer_connection_->CreateAnswer(description_request.get(), 534 native_peer_connection_->CreateAnswer(description_request.get(),
478 &constraints); 535 &constraints);
479 536
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
545 const webrtc::SessionDescriptionInterface* native_desc = 602 const webrtc::SessionDescriptionInterface* native_desc =
546 native_peer_connection_->remote_description(); 603 native_peer_connection_->remote_description();
547 blink::WebRTCSessionDescription description = 604 blink::WebRTCSessionDescription description =
548 CreateWebKitSessionDescription(native_desc); 605 CreateWebKitSessionDescription(native_desc);
549 return description; 606 return description;
550 } 607 }
551 608
552 bool RTCPeerConnectionHandler::updateICE( 609 bool RTCPeerConnectionHandler::updateICE(
553 const blink::WebRTCConfiguration& server_configuration, 610 const blink::WebRTCConfiguration& server_configuration,
554 const blink::WebMediaConstraints& options) { 611 const blink::WebMediaConstraints& options) {
555 webrtc::PeerConnectionInterface::IceServers servers; 612 webrtc::PeerConnectionInterface::RTCConfiguration config;
556 GetNativeIceServers(server_configuration, &servers); 613 GetNativeRtcConfiguration(server_configuration, &config);
557 RTCMediaConstraints constraints(options); 614 RTCMediaConstraints constraints(options);
558 615
559 if (peer_connection_tracker_) 616 if (peer_connection_tracker_)
560 peer_connection_tracker_->TrackUpdateIce(this, servers, constraints); 617 peer_connection_tracker_->TrackUpdateIce(this, config, constraints);
561 618
562 return native_peer_connection_->UpdateIce(servers, 619 return native_peer_connection_->UpdateIce(config.servers,
563 &constraints); 620 &constraints);
564 } 621 }
565 622
566 bool RTCPeerConnectionHandler::addICECandidate( 623 bool RTCPeerConnectionHandler::addICECandidate(
567 const blink::WebRTCVoidRequest& request, 624 const blink::WebRTCVoidRequest& request,
568 const blink::WebRTCICECandidate& candidate) { 625 const blink::WebRTCICECandidate& candidate) {
569 // Libjingle currently does not accept callbacks for addICECandidate. 626 // Libjingle currently does not accept callbacks for addICECandidate.
570 // For that reason we are going to call callbacks from here. 627 // For that reason we are going to call callbacks from here.
571 bool result = addICECandidate(candidate); 628 bool result = addICECandidate(candidate);
572 base::MessageLoop::current()->PostTask( 629 base::MessageLoop::current()->PostTask(
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 webrtc::SessionDescriptionInterface* native_desc = 986 webrtc::SessionDescriptionInterface* native_desc =
930 dependency_factory_->CreateSessionDescription(type, sdp, error); 987 dependency_factory_->CreateSessionDescription(type, sdp, error);
931 988
932 LOG_IF(ERROR, !native_desc) << "Failed to create native session description." 989 LOG_IF(ERROR, !native_desc) << "Failed to create native session description."
933 << " Type: " << type << " SDP: " << sdp; 990 << " Type: " << type << " SDP: " << sdp;
934 991
935 return native_desc; 992 return native_desc;
936 } 993 }
937 994
938 } // namespace content 995 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/rtc_peer_connection_handler.h ('k') | content/renderer/media/rtc_peer_connection_handler_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698