1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898
|
/*
* Copyright 2012 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
// This file contains the PeerConnection interface as defined in
// http://dev.w3.org/2011/webrtc/editor/webrtc.html#peer-to-peer-connections.
// Applications must use this interface to implement peerconnection.
// PeerConnectionFactory class provides factory methods to create
// peerconnection, mediastream and media tracks objects.
//
// The Following steps are needed to setup a typical call using Jsep.
// 1. Create a PeerConnectionFactoryInterface. Check constructors for more
// information about input parameters.
// 2. Create a PeerConnection object. Provide a configuration string which
// points either to stun or turn server to generate ICE candidates and provide
// an object that implements the PeerConnectionObserver interface.
// 3. Create local MediaStream and MediaTracks using the PeerConnectionFactory
// and add it to PeerConnection by calling AddStream.
// 4. Create an offer and serialize it and send it to the remote peer.
// 5. Once an ice candidate have been found PeerConnection will call the
// observer function OnIceCandidate. The candidates must also be serialized and
// sent to the remote peer.
// 6. Once an answer is received from the remote peer, call
// SetLocalSessionDescription with the offer and SetRemoteSessionDescription
// with the remote answer.
// 7. Once a remote candidate is received from the remote peer, provide it to
// the peerconnection by calling AddIceCandidate.
// The Receiver of a call can decide to accept or reject the call.
// This decision will be taken by the application not peerconnection.
// If application decides to accept the call
// 1. Create PeerConnectionFactoryInterface if it doesn't exist.
// 2. Create a new PeerConnection.
// 3. Provide the remote offer to the new PeerConnection object by calling
// SetRemoteSessionDescription.
// 4. Generate an answer to the remote offer by calling CreateAnswer and send it
// back to the remote peer.
// 5. Provide the local answer to the new PeerConnection by calling
// SetLocalSessionDescription with the answer.
// 6. Provide the remote ice candidates by calling AddIceCandidate.
// 7. Once a candidate have been found PeerConnection will call the observer
// function OnIceCandidate. Send these candidates to the remote peer.
#ifndef WEBRTC_API_PEERCONNECTIONINTERFACE_H_
#define WEBRTC_API_PEERCONNECTIONINTERFACE_H_
#include <memory>
#include <ostream>
#include <string>
#include <utility>
#include <vector>
#include "webrtc/api/datachannelinterface.h"
#include "webrtc/api/dtmfsenderinterface.h"
#include "webrtc/api/jsep.h"
#include "webrtc/api/mediastreaminterface.h"
#include "webrtc/api/rtcstatscollector.h"
#include "webrtc/api/rtpreceiverinterface.h"
#include "webrtc/api/rtpsenderinterface.h"
#include "webrtc/api/statstypes.h"
#include "webrtc/api/umametrics.h"
#include "webrtc/base/fileutils.h"
#include "webrtc/base/network.h"
#include "webrtc/base/rtccertificate.h"
#include "webrtc/base/rtccertificategenerator.h"
#include "webrtc/base/socketaddress.h"
#include "webrtc/base/sslstreamadapter.h"
#include "webrtc/media/base/mediachannel.h"
#include "webrtc/p2p/base/portallocator.h"
namespace rtc {
class SSLIdentity;
class Thread;
}
namespace cricket {
class WebRtcVideoDecoderFactory;
class WebRtcVideoEncoderFactory;
}
namespace webrtc {
class AudioDeviceModule;
class AudioMixer;
class MediaConstraintsInterface;
// MediaStream container interface.
class StreamCollectionInterface : public rtc::RefCountInterface {
public:
// TODO(ronghuawu): Update the function names to c++ style, e.g. find -> Find.
virtual size_t count() = 0;
virtual MediaStreamInterface* at(size_t index) = 0;
virtual MediaStreamInterface* find(const std::string& label) = 0;
virtual MediaStreamTrackInterface* FindAudioTrack(
const std::string& id) = 0;
virtual MediaStreamTrackInterface* FindVideoTrack(
const std::string& id) = 0;
protected:
// Dtor protected as objects shouldn't be deleted via this interface.
~StreamCollectionInterface() {}
};
class StatsObserver : public rtc::RefCountInterface {
public:
// TODO(nisse, hbos): Old version, not passing ownership. Should
// perhaps be deprecated, but since all of this is a legacy
// interface anyway, probably best to leave as is until this class
// can be deleted.
virtual void OnComplete(const StatsReports& reports) {}
virtual void OnCompleteReports(std::unique_ptr<StatsReports> reports) {
OnComplete(*reports);
}
protected:
virtual ~StatsObserver() {}
};
// Enumeration to represent distinct classes of errors that an application
// may wish to act upon differently. These roughly map to DOMExceptions or
// RTCError "errorDetailEnum" values in the web API, as described in the
// comments below.
enum class RTCErrorType {
// No error.
NONE,
// A supplied parameter is valid, but currently unsupported.
// Maps to InvalidAccessError DOMException.
UNSUPPORTED_PARAMETER,
// General error indicating that a supplied parameter is invalid.
// Maps to InvalidAccessError or TypeError DOMException depending on context.
INVALID_PARAMETER,
// Slightly more specific than INVALID_PARAMETER; a parameter's value was
// outside the allowed range.
// Maps to RangeError DOMException.
INVALID_RANGE,
// Slightly more specific than INVALID_PARAMETER; an error occurred while
// parsing string input.
// Maps to SyntaxError DOMException.
SYNTAX_ERROR,
// The object does not support this operation in its current state.
// Maps to InvalidStateError DOMException.
INVALID_STATE,
// An attempt was made to modify the object in an invalid way.
// Maps to InvalidModificationError DOMException.
INVALID_MODIFICATION,
// An error occurred within an underlying network protocol.
// Maps to NetworkError DOMException.
NETWORK_ERROR,
// The operation failed due to an internal error.
// Maps to OperationError DOMException.
INTERNAL_ERROR,
};
// Roughly corresponds to RTCError in the web api. Holds an error type and
// possibly additional information specific to that error.
//
// Doesn't contain anything beyond a type now, but will in the future as more
// errors are implemented.
class RTCError {
public:
RTCError() : type_(RTCErrorType::NONE) {}
explicit RTCError(RTCErrorType type) : type_(type) {}
RTCErrorType type() const { return type_; }
void set_type(RTCErrorType type) { type_ = type; }
private:
RTCErrorType type_;
};
// Outputs the error as a friendly string.
// Update this method when adding a new error type.
std::ostream& operator<<(std::ostream& stream, RTCErrorType error);
class PeerConnectionInterface : public rtc::RefCountInterface {
public:
// See http://dev.w3.org/2011/webrtc/editor/webrtc.html#state-definitions .
enum SignalingState {
kStable,
kHaveLocalOffer,
kHaveLocalPrAnswer,
kHaveRemoteOffer,
kHaveRemotePrAnswer,
kClosed,
};
enum IceGatheringState {
kIceGatheringNew,
kIceGatheringGathering,
kIceGatheringComplete
};
enum IceConnectionState {
kIceConnectionNew,
kIceConnectionChecking,
kIceConnectionConnected,
kIceConnectionCompleted,
kIceConnectionFailed,
kIceConnectionDisconnected,
kIceConnectionClosed,
kIceConnectionMax,
};
// TLS certificate policy.
enum TlsCertPolicy {
// For TLS based protocols, ensure the connection is secure by not
// circumventing certificate validation.
kTlsCertPolicySecure,
// For TLS based protocols, disregard security completely by skipping
// certificate validation. This is insecure and should never be used unless
// security is irrelevant in that particular context.
kTlsCertPolicyInsecureNoCheck,
};
struct IceServer {
// TODO(jbauch): Remove uri when all code using it has switched to urls.
std::string uri;
std::vector<std::string> urls;
std::string username;
std::string password;
TlsCertPolicy tls_cert_policy = kTlsCertPolicySecure;
bool operator==(const IceServer& o) const {
return uri == o.uri && urls == o.urls && username == o.username &&
password == o.password && tls_cert_policy == o.tls_cert_policy;
}
bool operator!=(const IceServer& o) const { return !(*this == o); }
};
typedef std::vector<IceServer> IceServers;
enum IceTransportsType {
// TODO(pthatcher): Rename these kTransporTypeXXX, but update
// Chromium at the same time.
kNone,
kRelay,
kNoHost,
kAll
};
// https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-08#section-4.1.1
enum BundlePolicy {
kBundlePolicyBalanced,
kBundlePolicyMaxBundle,
kBundlePolicyMaxCompat
};
// https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-09#section-4.1.1
enum RtcpMuxPolicy {
kRtcpMuxPolicyNegotiate,
kRtcpMuxPolicyRequire,
};
enum TcpCandidatePolicy {
kTcpCandidatePolicyEnabled,
kTcpCandidatePolicyDisabled
};
enum CandidateNetworkPolicy {
kCandidateNetworkPolicyAll,
kCandidateNetworkPolicyLowCost
};
enum ContinualGatheringPolicy {
GATHER_ONCE,
GATHER_CONTINUALLY
};
enum class RTCConfigurationType {
// A configuration that is safer to use, despite not having the best
// performance. Currently this is the default configuration.
kSafe,
// An aggressive configuration that has better performance, although it
// may be riskier and may need extra support in the application.
kAggressive
};
// TODO(hbos): Change into class with private data and public getters.
// TODO(nisse): In particular, accessing fields directly from an
// application is brittle, since the organization mirrors the
// organization of the implementation, which isn't stable. So we
// need getters and setters at least for fields which applications
// are interested in.
struct RTCConfiguration {
// This struct is subject to reorganization, both for naming
// consistency, and to group settings to match where they are used
// in the implementation. To do that, we need getter and setter
// methods for all settings which are of interest to applications,
// Chrome in particular.
RTCConfiguration() = default;
RTCConfiguration(RTCConfigurationType type) {
if (type == RTCConfigurationType::kAggressive) {
// These parameters are also defined in Java and IOS configurations,
// so their values may be overwritten by the Java or IOS configuration.
bundle_policy = kBundlePolicyMaxBundle;
rtcp_mux_policy = kRtcpMuxPolicyRequire;
ice_connection_receiving_timeout =
kAggressiveIceConnectionReceivingTimeout;
// These parameters are not defined in Java or IOS configuration,
// so their values will not be overwritten.
enable_ice_renomination = true;
redetermine_role_on_ice_restart = false;
}
}
bool operator==(const RTCConfiguration& o) const;
bool operator!=(const RTCConfiguration& o) const;
bool dscp() { return media_config.enable_dscp; }
void set_dscp(bool enable) { media_config.enable_dscp = enable; }
// TODO(nisse): The corresponding flag in MediaConfig and
// elsewhere should be renamed enable_cpu_adaptation.
bool cpu_adaptation() {
return media_config.video.enable_cpu_overuse_detection;
}
void set_cpu_adaptation(bool enable) {
media_config.video.enable_cpu_overuse_detection = enable;
}
bool suspend_below_min_bitrate() {
return media_config.video.suspend_below_min_bitrate;
}
void set_suspend_below_min_bitrate(bool enable) {
media_config.video.suspend_below_min_bitrate = enable;
}
// TODO(nisse): The negation in the corresponding MediaConfig
// attribute is inconsistent, and it should be renamed at some
// point.
bool prerenderer_smoothing() {
return !media_config.video.disable_prerenderer_smoothing;
}
void set_prerenderer_smoothing(bool enable) {
media_config.video.disable_prerenderer_smoothing = !enable;
}
static const int kUndefined = -1;
// Default maximum number of packets in the audio jitter buffer.
static const int kAudioJitterBufferMaxPackets = 50;
// ICE connection receiving timeout for aggressive configuration.
static const int kAggressiveIceConnectionReceivingTimeout = 1000;
// TODO(pthatcher): Rename this ice_transport_type, but update
// Chromium at the same time.
IceTransportsType type = kAll;
// TODO(pthatcher): Rename this ice_servers, but update Chromium
// at the same time.
IceServers servers;
BundlePolicy bundle_policy = kBundlePolicyBalanced;
RtcpMuxPolicy rtcp_mux_policy = kRtcpMuxPolicyRequire;
TcpCandidatePolicy tcp_candidate_policy = kTcpCandidatePolicyEnabled;
CandidateNetworkPolicy candidate_network_policy =
kCandidateNetworkPolicyAll;
int audio_jitter_buffer_max_packets = kAudioJitterBufferMaxPackets;
bool audio_jitter_buffer_fast_accelerate = false;
int ice_connection_receiving_timeout = kUndefined; // ms
int ice_backup_candidate_pair_ping_interval = kUndefined; // ms
ContinualGatheringPolicy continual_gathering_policy = GATHER_ONCE;
std::vector<rtc::scoped_refptr<rtc::RTCCertificate>> certificates;
bool prioritize_most_likely_ice_candidate_pairs = false;
struct cricket::MediaConfig media_config;
// Flags corresponding to values set by constraint flags.
// rtc::Optional flags can be "missing", in which case the webrtc
// default applies.
bool disable_ipv6 = false;
bool enable_rtp_data_channel = false;
bool enable_quic = false;
rtc::Optional<int> screencast_min_bitrate;
rtc::Optional<bool> combined_audio_video_bwe;
rtc::Optional<bool> enable_dtls_srtp;
int ice_candidate_pool_size = 0;
bool prune_turn_ports = false;
// If set to true, this means the ICE transport should presume TURN-to-TURN
// candidate pairs will succeed, even before a binding response is received.
bool presume_writable_when_fully_relayed = false;
// If true, "renomination" will be added to the ice options in the transport
// description.
bool enable_ice_renomination = false;
// If true, ICE role is redetermined when peerconnection sets a local
// transport description that indicates an ICE restart.
bool redetermine_role_on_ice_restart = true;
//
// Don't forget to update operator== if adding something.
//
};
struct RTCOfferAnswerOptions {
static const int kUndefined = -1;
static const int kMaxOfferToReceiveMedia = 1;
// The default value for constraint offerToReceiveX:true.
static const int kOfferToReceiveMediaTrue = 1;
int offer_to_receive_video = kUndefined;
int offer_to_receive_audio = kUndefined;
bool voice_activity_detection = true;
bool ice_restart = false;
bool use_rtp_mux = true;
RTCOfferAnswerOptions() = default;
RTCOfferAnswerOptions(int offer_to_receive_video,
int offer_to_receive_audio,
bool voice_activity_detection,
bool ice_restart,
bool use_rtp_mux)
: offer_to_receive_video(offer_to_receive_video),
offer_to_receive_audio(offer_to_receive_audio),
voice_activity_detection(voice_activity_detection),
ice_restart(ice_restart),
use_rtp_mux(use_rtp_mux) {}
};
// Used by GetStats to decide which stats to include in the stats reports.
// |kStatsOutputLevelStandard| includes the standard stats for Javascript API;
// |kStatsOutputLevelDebug| includes both the standard stats and additional
// stats for debugging purposes.
enum StatsOutputLevel {
kStatsOutputLevelStandard,
kStatsOutputLevelDebug,
};
// Accessor methods to active local streams.
virtual rtc::scoped_refptr<StreamCollectionInterface>
local_streams() = 0;
// Accessor methods to remote streams.
virtual rtc::scoped_refptr<StreamCollectionInterface>
remote_streams() = 0;
// Add a new MediaStream to be sent on this PeerConnection.
// Note that a SessionDescription negotiation is needed before the
// remote peer can receive the stream.
virtual bool AddStream(MediaStreamInterface* stream) = 0;
// Remove a MediaStream from this PeerConnection.
// Note that a SessionDescription negotiation is need before the
// remote peer is notified.
virtual void RemoveStream(MediaStreamInterface* stream) = 0;
// TODO(deadbeef): Make the following two methods pure virtual once
// implemented by all subclasses of PeerConnectionInterface.
// Add a new MediaStreamTrack to be sent on this PeerConnection.
// |streams| indicates which stream labels the track should be associated
// with.
virtual rtc::scoped_refptr<RtpSenderInterface> AddTrack(
MediaStreamTrackInterface* track,
std::vector<MediaStreamInterface*> streams) {
return nullptr;
}
// Remove an RtpSender from this PeerConnection.
// Returns true on success.
virtual bool RemoveTrack(RtpSenderInterface* sender) {
return false;
}
// Returns pointer to the created DtmfSender on success.
// Otherwise returns NULL.
virtual rtc::scoped_refptr<DtmfSenderInterface> CreateDtmfSender(
AudioTrackInterface* track) = 0;
// TODO(deadbeef): Make these pure virtual once all subclasses implement them.
// |kind| must be "audio" or "video".
// |stream_id| is used to populate the msid attribute; if empty, one will
// be generated automatically.
virtual rtc::scoped_refptr<RtpSenderInterface> CreateSender(
const std::string& kind,
const std::string& stream_id) {
return rtc::scoped_refptr<RtpSenderInterface>();
}
virtual std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
const {
return std::vector<rtc::scoped_refptr<RtpSenderInterface>>();
}
virtual std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
const {
return std::vector<rtc::scoped_refptr<RtpReceiverInterface>>();
}
virtual bool GetStats(StatsObserver* observer,
MediaStreamTrackInterface* track,
StatsOutputLevel level) = 0;
// Gets stats using the new stats collection API, see webrtc/api/stats/. These
// will replace old stats collection API when the new API has matured enough.
// TODO(hbos): Default implementation that does nothing only exists as to not
// break third party projects. As soon as they have been updated this should
// be changed to "= 0;".
virtual void GetStats(RTCStatsCollectorCallback* callback) {}
virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
const std::string& label,
const DataChannelInit* config) = 0;
virtual const SessionDescriptionInterface* local_description() const = 0;
virtual const SessionDescriptionInterface* remote_description() const = 0;
// A "current" description the one currently negotiated from a complete
// offer/answer exchange.
virtual const SessionDescriptionInterface* current_local_description() const {
return nullptr;
}
virtual const SessionDescriptionInterface* current_remote_description()
const {
return nullptr;
}
// A "pending" description is one that's part of an incomplete offer/answer
// exchange (thus, either an offer or a pranswer). Once the offer/answer
// exchange is finished, the "pending" description will become "current".
virtual const SessionDescriptionInterface* pending_local_description() const {
return nullptr;
}
virtual const SessionDescriptionInterface* pending_remote_description()
const {
return nullptr;
}
// Create a new offer.
// The CreateSessionDescriptionObserver callback will be called when done.
virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
const MediaConstraintsInterface* constraints) {}
// TODO(jiayl): remove the default impl and the old interface when chromium
// code is updated.
virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
const RTCOfferAnswerOptions& options) {}
// Create an answer to an offer.
// The CreateSessionDescriptionObserver callback will be called when done.
virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
const RTCOfferAnswerOptions& options) {}
// Deprecated - use version above.
// TODO(hta): Remove and remove default implementations when all callers
// are updated.
virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
const MediaConstraintsInterface* constraints) {}
// Sets the local session description.
// JsepInterface takes the ownership of |desc| even if it fails.
// The |observer| callback will be called when done.
virtual void SetLocalDescription(SetSessionDescriptionObserver* observer,
SessionDescriptionInterface* desc) = 0;
// Sets the remote session description.
// JsepInterface takes the ownership of |desc| even if it fails.
// The |observer| callback will be called when done.
virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer,
SessionDescriptionInterface* desc) = 0;
// Restarts or updates the ICE Agent process of gathering local candidates
// and pinging remote candidates.
// TODO(deadbeef): Remove once Chrome is moved over to SetConfiguration.
virtual bool UpdateIce(const IceServers& configuration,
const MediaConstraintsInterface* constraints) {
return false;
}
virtual bool UpdateIce(const IceServers& configuration) { return false; }
// TODO(deadbeef): Make this pure virtual once all Chrome subclasses of
// PeerConnectionInterface implement it.
virtual PeerConnectionInterface::RTCConfiguration GetConfiguration() {
return PeerConnectionInterface::RTCConfiguration();
}
// Sets the PeerConnection's global configuration to |config|.
//
// The members of |config| that may be changed are |type|, |servers|,
// |ice_candidate_pool_size| and |prune_turn_ports| (though the candidate
// pool size can't be changed after the first call to SetLocalDescription).
// Note that this means the BUNDLE and RTCP-multiplexing policies cannot be
// changed with this method.
//
// Any changes to STUN/TURN servers or ICE candidate policy will affect the
// next gathering phase, and cause the next call to createOffer to generate
// new ICE credentials, as described in JSEP. This also occurs when
// |prune_turn_ports| changes, for the same reasoning.
//
// If an error occurs, returns false and populates |error| if non-null:
// - INVALID_MODIFICATION if |config| contains a modified parameter other
// than one of the parameters listed above.
// - INVALID_RANGE if |ice_candidate_pool_size| is out of range.
// - SYNTAX_ERROR if parsing an ICE server URL failed.
// - INVALID_PARAMETER if a TURN server is missing |username| or |password|.
// - INTERNAL_ERROR if an unexpected error occurred.
//
// TODO(deadbeef): Make this pure virtual once all Chrome subclasses of
// PeerConnectionInterface implement it.
virtual bool SetConfiguration(
const PeerConnectionInterface::RTCConfiguration& config,
RTCError* error) {
return false;
}
// Version without error output param for backwards compatibility.
// TODO(deadbeef): Remove once chromium is updated.
virtual bool SetConfiguration(
const PeerConnectionInterface::RTCConfiguration& config) {
return false;
}
// Provides a remote candidate to the ICE Agent.
// A copy of the |candidate| will be created and added to the remote
// description. So the caller of this method still has the ownership of the
// |candidate|.
// TODO(ronghuawu): Consider to change this so that the AddIceCandidate will
// take the ownership of the |candidate|.
virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0;
// Removes a group of remote candidates from the ICE agent.
virtual bool RemoveIceCandidates(
const std::vector<cricket::Candidate>& candidates) {
return false;
}
virtual void RegisterUMAObserver(UMAObserver* observer) = 0;
// Returns the current SignalingState.
virtual SignalingState signaling_state() = 0;
virtual IceConnectionState ice_connection_state() = 0;
virtual IceGatheringState ice_gathering_state() = 0;
// Starts RtcEventLog using existing file. Takes ownership of |file| and
// passes it on to Call, which will take the ownership. If the
// operation fails the file will be closed. The logging will stop
// automatically after 10 minutes have passed, or when the StopRtcEventLog
// function is called.
// TODO(ivoc): Make this pure virtual when Chrome is updated.
virtual bool StartRtcEventLog(rtc::PlatformFile file,
int64_t max_size_bytes) {
return false;
}
// Stops logging the RtcEventLog.
// TODO(ivoc): Make this pure virtual when Chrome is updated.
virtual void StopRtcEventLog() {}
// Terminates all media and closes the transport.
virtual void Close() = 0;
protected:
// Dtor protected as objects shouldn't be deleted via this interface.
~PeerConnectionInterface() {}
};
// PeerConnection callback interface. Application should implement these
// methods.
class PeerConnectionObserver {
public:
enum StateType {
kSignalingState,
kIceState,
};
// Triggered when the SignalingState changed.
virtual void OnSignalingChange(
PeerConnectionInterface::SignalingState new_state) = 0;
// TODO(deadbeef): Once all subclasses override the scoped_refptr versions
// of the below three methods, make them pure virtual and remove the raw
// pointer version.
// Triggered when media is received on a new stream from remote peer.
virtual void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) {}
// Deprecated; please use the version that uses a scoped_refptr.
virtual void OnAddStream(MediaStreamInterface* stream) {}
// Triggered when a remote peer close a stream.
virtual void OnRemoveStream(rtc::scoped_refptr<MediaStreamInterface> stream) {
}
// Deprecated; please use the version that uses a scoped_refptr.
virtual void OnRemoveStream(MediaStreamInterface* stream) {}
// Triggered when a remote peer opens a data channel.
virtual void OnDataChannel(
rtc::scoped_refptr<DataChannelInterface> data_channel){};
// Deprecated; please use the version that uses a scoped_refptr.
virtual void OnDataChannel(DataChannelInterface* data_channel) {}
// Triggered when renegotiation is needed. For example, an ICE restart
// has begun.
virtual void OnRenegotiationNeeded() = 0;
// Called any time the IceConnectionState changes.
virtual void OnIceConnectionChange(
PeerConnectionInterface::IceConnectionState new_state) = 0;
// Called any time the IceGatheringState changes.
virtual void OnIceGatheringChange(
PeerConnectionInterface::IceGatheringState new_state) = 0;
// A new ICE candidate has been gathered.
virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0;
// Ice candidates have been removed.
// TODO(honghaiz): Make this a pure virtual method when all its subclasses
// implement it.
virtual void OnIceCandidatesRemoved(
const std::vector<cricket::Candidate>& candidates) {}
// Called when the ICE connection receiving status changes.
virtual void OnIceConnectionReceivingChange(bool receiving) {}
// Called when a track is added to streams.
// TODO(zhihuang) Make this a pure virtual method when all its subclasses
// implement it.
virtual void OnAddTrack(
rtc::scoped_refptr<RtpReceiverInterface> receiver,
const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) {}
protected:
// Dtor protected as objects shouldn't be deleted via this interface.
~PeerConnectionObserver() {}
};
// PeerConnectionFactoryInterface is the factory interface use for creating
// PeerConnection, MediaStream and media tracks.
// PeerConnectionFactoryInterface will create required libjingle threads,
// socket and network manager factory classes for networking.
// If an application decides to provide its own threads and network
// implementation of these classes it should use the alternate
// CreatePeerConnectionFactory method which accepts threads as input and use the
// CreatePeerConnection version that takes a PortAllocator as an
// argument.
class PeerConnectionFactoryInterface : public rtc::RefCountInterface {
public:
class Options {
public:
Options()
: disable_encryption(false),
disable_sctp_data_channels(false),
disable_network_monitor(false),
network_ignore_mask(rtc::kDefaultNetworkIgnoreMask),
ssl_max_version(rtc::SSL_PROTOCOL_DTLS_12),
crypto_options(rtc::CryptoOptions::NoGcm()) {}
bool disable_encryption;
bool disable_sctp_data_channels;
bool disable_network_monitor;
// Sets the network types to ignore. For instance, calling this with
// ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
// loopback interfaces.
int network_ignore_mask;
// Sets the maximum supported protocol version. The highest version
// supported by both ends will be used for the connection, i.e. if one
// party supports DTLS 1.0 and the other DTLS 1.2, DTLS 1.0 will be used.
rtc::SSLProtocolVersion ssl_max_version;
// Sets crypto related options, e.g. enabled cipher suites.
rtc::CryptoOptions crypto_options;
};
virtual void SetOptions(const Options& options) = 0;
virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
const PeerConnectionInterface::RTCConfiguration& configuration,
const MediaConstraintsInterface* constraints,
std::unique_ptr<cricket::PortAllocator> allocator,
std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
PeerConnectionObserver* observer) = 0;
virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
const PeerConnectionInterface::RTCConfiguration& configuration,
std::unique_ptr<cricket::PortAllocator> allocator,
std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
PeerConnectionObserver* observer) = 0;
virtual rtc::scoped_refptr<MediaStreamInterface>
CreateLocalMediaStream(const std::string& label) = 0;
// Creates a AudioSourceInterface.
// |constraints| decides audio processing settings but can be NULL.
virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
const cricket::AudioOptions& options) = 0;
// Deprecated - use version above.
// Can use CopyConstraintsIntoAudioOptions to bridge the gap.
virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
const MediaConstraintsInterface* constraints) = 0;
// Creates a VideoTrackSourceInterface. The new source take ownership of
// |capturer|.
virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
cricket::VideoCapturer* capturer) = 0;
// A video source creator that allows selection of resolution and frame rate.
// |constraints| decides video resolution and frame rate but can
// be NULL.
// In the NULL case, use the version above.
virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
cricket::VideoCapturer* capturer,
const MediaConstraintsInterface* constraints) = 0;
// Creates a new local VideoTrack. The same |source| can be used in several
// tracks.
virtual rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
const std::string& label,
VideoTrackSourceInterface* source) = 0;
// Creates an new AudioTrack. At the moment |source| can be NULL.
virtual rtc::scoped_refptr<AudioTrackInterface>
CreateAudioTrack(const std::string& label,
AudioSourceInterface* source) = 0;
// Starts AEC dump using existing file. Takes ownership of |file| and passes
// it on to VoiceEngine (via other objects) immediately, which will take
// the ownerhip. If the operation fails, the file will be closed.
// A maximum file size in bytes can be specified. When the file size limit is
// reached, logging is stopped automatically. If max_size_bytes is set to a
// value <= 0, no limit will be used, and logging will continue until the
// StopAecDump function is called.
virtual bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) = 0;
// Stops logging the AEC dump.
virtual void StopAecDump() = 0;
// This function is deprecated and will be removed when Chrome is updated to
// use the equivalent function on PeerConnectionInterface.
// TODO(ivoc) Remove after Chrome is updated.
virtual bool StartRtcEventLog(rtc::PlatformFile file,
int64_t max_size_bytes) = 0;
// This function is deprecated and will be removed when Chrome is updated to
// use the equivalent function on PeerConnectionInterface.
// TODO(ivoc) Remove after Chrome is updated.
virtual bool StartRtcEventLog(rtc::PlatformFile file) = 0;
// This function is deprecated and will be removed when Chrome is updated to
// use the equivalent function on PeerConnectionInterface.
// TODO(ivoc) Remove after Chrome is updated.
virtual void StopRtcEventLog() = 0;
protected:
// Dtor and ctor protected as objects shouldn't be created or deleted via
// this interface.
PeerConnectionFactoryInterface() {}
~PeerConnectionFactoryInterface() {} // NOLINT
};
// Create a new instance of PeerConnectionFactoryInterface.
//
// This method relies on the thread it's called on as the "signaling thread"
// for the PeerConnectionFactory it creates.
//
// As such, if the current thread is not already running an rtc::Thread message
// loop, an application using this method must eventually either call
// rtc::Thread::Current()->Run(), or call
// rtc::Thread::Current()->ProcessMessages() within the application's own
// message loop.
rtc::scoped_refptr<PeerConnectionFactoryInterface>
CreatePeerConnectionFactory();
// Create a new instance of PeerConnectionFactoryInterface.
//
// |network_thread|, |worker_thread| and |signaling_thread| are
// the only mandatory parameters.
//
// If non-null, ownership of |default_adm|, |encoder_factory| and
// |decoder_factory| are transferred to the returned factory.
rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
rtc::Thread* network_thread,
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
AudioDeviceModule* default_adm,
cricket::WebRtcVideoEncoderFactory* encoder_factory,
cricket::WebRtcVideoDecoderFactory* decoder_factory);
// Create a new instance of PeerConnectionFactoryInterface with external audio
// mixer.
//
// If |audio_mixer| is null, an internal audio mixer will be created and used.
rtc::scoped_refptr<PeerConnectionFactoryInterface>
CreatePeerConnectionFactoryWithAudioMixer(
rtc::Thread* network_thread,
rtc::Thread* worker_thread,
rtc::Thread* signaling_thread,
AudioDeviceModule* default_adm,
cricket::WebRtcVideoEncoderFactory* encoder_factory,
cricket::WebRtcVideoDecoderFactory* decoder_factory,
rtc::scoped_refptr<AudioMixer> audio_mixer);
// Create a new instance of PeerConnectionFactoryInterface.
// Same thread is used as worker and network thread.
inline rtc::scoped_refptr<PeerConnectionFactoryInterface>
CreatePeerConnectionFactory(
rtc::Thread* worker_and_network_thread,
rtc::Thread* signaling_thread,
AudioDeviceModule* default_adm,
cricket::WebRtcVideoEncoderFactory* encoder_factory,
cricket::WebRtcVideoDecoderFactory* decoder_factory) {
return CreatePeerConnectionFactory(
worker_and_network_thread, worker_and_network_thread, signaling_thread,
default_adm, encoder_factory, decoder_factory);
}
} // namespace webrtc
#endif // WEBRTC_API_PEERCONNECTIONINTERFACE_H_
|