peer_connection_interface.h 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523
  1. /*
  2. * Copyright 2012 The WebRTC project authors. All Rights Reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. // This file contains the PeerConnection interface as defined in
  11. // https://w3c.github.io/webrtc-pc/#peer-to-peer-connections
  12. //
  13. // The PeerConnectionFactory class provides factory methods to create
  14. // PeerConnection, MediaStream and MediaStreamTrack objects.
  15. //
  16. // The following steps are needed to setup a typical call using WebRTC:
  17. //
  18. // 1. Create a PeerConnectionFactoryInterface. Check constructors for more
  19. // information about input parameters.
  20. //
  21. // 2. Create a PeerConnection object. Provide a configuration struct which
  22. // points to STUN and/or TURN servers used to generate ICE candidates, and
  23. // provide an object that implements the PeerConnectionObserver interface,
  24. // which is used to receive callbacks from the PeerConnection.
  25. //
  26. // 3. Create local MediaStreamTracks using the PeerConnectionFactory and add
  27. // them to PeerConnection by calling AddTrack (or legacy method, AddStream).
  28. //
  29. // 4. Create an offer, call SetLocalDescription with it, serialize it, and send
  30. // it to the remote peer
  31. //
  32. // 5. Once an ICE candidate has been gathered, the PeerConnection will call the
  33. // observer function OnIceCandidate. The candidates must also be serialized and
  34. // sent to the remote peer.
  35. //
  36. // 6. Once an answer is received from the remote peer, call
  37. // SetRemoteDescription with the remote answer.
  38. //
  39. // 7. Once a remote candidate is received from the remote peer, provide it to
  40. // the PeerConnection by calling AddIceCandidate.
  41. //
  42. // The receiver of a call (assuming the application is "call"-based) can decide
  43. // to accept or reject the call; this decision will be taken by the application,
  44. // not the PeerConnection.
  45. //
  46. // If the application decides to accept the call, it should:
  47. //
  48. // 1. Create PeerConnectionFactoryInterface if it doesn't exist.
  49. //
  50. // 2. Create a new PeerConnection.
  51. //
  52. // 3. Provide the remote offer to the new PeerConnection object by calling
  53. // SetRemoteDescription.
  54. //
  55. // 4. Generate an answer to the remote offer by calling CreateAnswer and send it
  56. // back to the remote peer.
  57. //
  58. // 5. Provide the local answer to the new PeerConnection by calling
  59. // SetLocalDescription with the answer.
  60. //
  61. // 6. Provide the remote ICE candidates by calling AddIceCandidate.
  62. //
  63. // 7. Once a candidate has been gathered, the PeerConnection will call the
  64. // observer function OnIceCandidate. Send these candidates to the remote peer.
  65. #ifndef API_PEER_CONNECTION_INTERFACE_H_
  66. #define API_PEER_CONNECTION_INTERFACE_H_
  67. #include <stdio.h>
  68. #include <memory>
  69. #include <string>
  70. #include <vector>
  71. #include "api/adaptation/resource.h"
  72. #include "api/async_resolver_factory.h"
  73. #include "api/audio/audio_mixer.h"
  74. #include "api/audio_codecs/audio_decoder_factory.h"
  75. #include "api/audio_codecs/audio_encoder_factory.h"
  76. #include "api/audio_options.h"
  77. #include "api/call/call_factory_interface.h"
  78. #include "api/crypto/crypto_options.h"
  79. #include "api/data_channel_interface.h"
  80. #include "api/dtls_transport_interface.h"
  81. #include "api/fec_controller.h"
  82. #include "api/ice_transport_interface.h"
  83. #include "api/jsep.h"
  84. #include "api/media_stream_interface.h"
  85. #include "api/neteq/neteq_factory.h"
  86. #include "api/network_state_predictor.h"
  87. #include "api/packet_socket_factory.h"
  88. #include "api/rtc_error.h"
  89. #include "api/rtc_event_log/rtc_event_log_factory_interface.h"
  90. #include "api/rtc_event_log_output.h"
  91. #include "api/rtp_receiver_interface.h"
  92. #include "api/rtp_sender_interface.h"
  93. #include "api/rtp_transceiver_interface.h"
  94. #include "api/sctp_transport_interface.h"
  95. #include "api/set_local_description_observer_interface.h"
  96. #include "api/set_remote_description_observer_interface.h"
  97. #include "api/stats/rtc_stats_collector_callback.h"
  98. #include "api/stats_types.h"
  99. #include "api/task_queue/task_queue_factory.h"
  100. #include "api/transport/bitrate_settings.h"
  101. #include "api/transport/enums.h"
  102. #include "api/transport/network_control.h"
  103. #include "api/transport/sctp_transport_factory_interface.h"
  104. #include "api/transport/webrtc_key_value_config.h"
  105. #include "api/turn_customizer.h"
  106. #include "media/base/media_config.h"
  107. #include "media/base/media_engine.h"
  108. // TODO(bugs.webrtc.org/7447): We plan to provide a way to let applications
  109. // inject a PacketSocketFactory and/or NetworkManager, and not expose
  110. // PortAllocator in the PeerConnection api.
  111. #include "p2p/base/port_allocator.h" // nogncheck
  112. #include "rtc_base/network_monitor_factory.h"
  113. #include "rtc_base/rtc_certificate.h"
  114. #include "rtc_base/rtc_certificate_generator.h"
  115. #include "rtc_base/socket_address.h"
  116. #include "rtc_base/ssl_certificate.h"
  117. #include "rtc_base/ssl_stream_adapter.h"
  118. #include "rtc_base/system/rtc_export.h"
  119. namespace rtc {
  120. class Thread;
  121. } // namespace rtc
  122. namespace webrtc {
  123. // MediaStream container interface.
  124. class StreamCollectionInterface : public rtc::RefCountInterface {
  125. public:
  126. // TODO(ronghuawu): Update the function names to c++ style, e.g. find -> Find.
  127. virtual size_t count() = 0;
  128. virtual MediaStreamInterface* at(size_t index) = 0;
  129. virtual MediaStreamInterface* find(const std::string& label) = 0;
  130. virtual MediaStreamTrackInterface* FindAudioTrack(const std::string& id) = 0;
  131. virtual MediaStreamTrackInterface* FindVideoTrack(const std::string& id) = 0;
  132. protected:
  133. // Dtor protected as objects shouldn't be deleted via this interface.
  134. ~StreamCollectionInterface() override = default;
  135. };
  136. class StatsObserver : public rtc::RefCountInterface {
  137. public:
  138. virtual void OnComplete(const StatsReports& reports) = 0;
  139. protected:
  140. ~StatsObserver() override = default;
  141. };
  142. enum class SdpSemantics { kPlanB, kUnifiedPlan };
  143. class RTC_EXPORT PeerConnectionInterface : public rtc::RefCountInterface {
  144. public:
  145. // See https://w3c.github.io/webrtc-pc/#dom-rtcsignalingstate
  146. enum SignalingState {
  147. kStable,
  148. kHaveLocalOffer,
  149. kHaveLocalPrAnswer,
  150. kHaveRemoteOffer,
  151. kHaveRemotePrAnswer,
  152. kClosed,
  153. };
  154. // See https://w3c.github.io/webrtc-pc/#dom-rtcicegatheringstate
  155. enum IceGatheringState {
  156. kIceGatheringNew,
  157. kIceGatheringGathering,
  158. kIceGatheringComplete
  159. };
  160. // See https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnectionstate
  161. enum class PeerConnectionState {
  162. kNew,
  163. kConnecting,
  164. kConnected,
  165. kDisconnected,
  166. kFailed,
  167. kClosed,
  168. };
  169. // See https://w3c.github.io/webrtc-pc/#dom-rtciceconnectionstate
  170. enum IceConnectionState {
  171. kIceConnectionNew,
  172. kIceConnectionChecking,
  173. kIceConnectionConnected,
  174. kIceConnectionCompleted,
  175. kIceConnectionFailed,
  176. kIceConnectionDisconnected,
  177. kIceConnectionClosed,
  178. kIceConnectionMax,
  179. };
  180. // TLS certificate policy.
  181. enum TlsCertPolicy {
  182. // For TLS based protocols, ensure the connection is secure by not
  183. // circumventing certificate validation.
  184. kTlsCertPolicySecure,
  185. // For TLS based protocols, disregard security completely by skipping
  186. // certificate validation. This is insecure and should never be used unless
  187. // security is irrelevant in that particular context.
  188. kTlsCertPolicyInsecureNoCheck,
  189. };
  190. struct RTC_EXPORT IceServer {
  191. IceServer();
  192. IceServer(const IceServer&);
  193. ~IceServer();
  194. // TODO(jbauch): Remove uri when all code using it has switched to urls.
  195. // List of URIs associated with this server. Valid formats are described
  196. // in RFC7064 and RFC7065, and more may be added in the future. The "host"
  197. // part of the URI may contain either an IP address or a hostname.
  198. std::string uri;
  199. std::vector<std::string> urls;
  200. std::string username;
  201. std::string password;
  202. TlsCertPolicy tls_cert_policy = kTlsCertPolicySecure;
  203. // If the URIs in |urls| only contain IP addresses, this field can be used
  204. // to indicate the hostname, which may be necessary for TLS (using the SNI
  205. // extension). If |urls| itself contains the hostname, this isn't
  206. // necessary.
  207. std::string hostname;
  208. // List of protocols to be used in the TLS ALPN extension.
  209. std::vector<std::string> tls_alpn_protocols;
  210. // List of elliptic curves to be used in the TLS elliptic curves extension.
  211. std::vector<std::string> tls_elliptic_curves;
  212. bool operator==(const IceServer& o) const {
  213. return uri == o.uri && urls == o.urls && username == o.username &&
  214. password == o.password && tls_cert_policy == o.tls_cert_policy &&
  215. hostname == o.hostname &&
  216. tls_alpn_protocols == o.tls_alpn_protocols &&
  217. tls_elliptic_curves == o.tls_elliptic_curves;
  218. }
  219. bool operator!=(const IceServer& o) const { return !(*this == o); }
  220. };
  221. typedef std::vector<IceServer> IceServers;
  222. enum IceTransportsType {
  223. // TODO(pthatcher): Rename these kTransporTypeXXX, but update
  224. // Chromium at the same time.
  225. kNone,
  226. kRelay,
  227. kNoHost,
  228. kAll
  229. };
  230. // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-24#section-4.1.1
  231. enum BundlePolicy {
  232. kBundlePolicyBalanced,
  233. kBundlePolicyMaxBundle,
  234. kBundlePolicyMaxCompat
  235. };
  236. // https://tools.ietf.org/html/draft-ietf-rtcweb-jsep-24#section-4.1.1
  237. enum RtcpMuxPolicy {
  238. kRtcpMuxPolicyNegotiate,
  239. kRtcpMuxPolicyRequire,
  240. };
  241. enum TcpCandidatePolicy {
  242. kTcpCandidatePolicyEnabled,
  243. kTcpCandidatePolicyDisabled
  244. };
  245. enum CandidateNetworkPolicy {
  246. kCandidateNetworkPolicyAll,
  247. kCandidateNetworkPolicyLowCost
  248. };
  249. enum ContinualGatheringPolicy { GATHER_ONCE, GATHER_CONTINUALLY };
  250. enum class RTCConfigurationType {
  251. // A configuration that is safer to use, despite not having the best
  252. // performance. Currently this is the default configuration.
  253. kSafe,
  254. // An aggressive configuration that has better performance, although it
  255. // may be riskier and may need extra support in the application.
  256. kAggressive
  257. };
  258. // TODO(hbos): Change into class with private data and public getters.
  259. // TODO(nisse): In particular, accessing fields directly from an
  260. // application is brittle, since the organization mirrors the
  261. // organization of the implementation, which isn't stable. So we
  262. // need getters and setters at least for fields which applications
  263. // are interested in.
  264. struct RTC_EXPORT RTCConfiguration {
  265. // This struct is subject to reorganization, both for naming
  266. // consistency, and to group settings to match where they are used
  267. // in the implementation. To do that, we need getter and setter
  268. // methods for all settings which are of interest to applications,
  269. // Chrome in particular.
  270. RTCConfiguration();
  271. RTCConfiguration(const RTCConfiguration&);
  272. explicit RTCConfiguration(RTCConfigurationType type);
  273. ~RTCConfiguration();
  274. bool operator==(const RTCConfiguration& o) const;
  275. bool operator!=(const RTCConfiguration& o) const;
  276. bool dscp() const { return media_config.enable_dscp; }
  277. void set_dscp(bool enable) { media_config.enable_dscp = enable; }
  278. bool cpu_adaptation() const {
  279. return media_config.video.enable_cpu_adaptation;
  280. }
  281. void set_cpu_adaptation(bool enable) {
  282. media_config.video.enable_cpu_adaptation = enable;
  283. }
  284. bool suspend_below_min_bitrate() const {
  285. return media_config.video.suspend_below_min_bitrate;
  286. }
  287. void set_suspend_below_min_bitrate(bool enable) {
  288. media_config.video.suspend_below_min_bitrate = enable;
  289. }
  290. bool prerenderer_smoothing() const {
  291. return media_config.video.enable_prerenderer_smoothing;
  292. }
  293. void set_prerenderer_smoothing(bool enable) {
  294. media_config.video.enable_prerenderer_smoothing = enable;
  295. }
  296. bool experiment_cpu_load_estimator() const {
  297. return media_config.video.experiment_cpu_load_estimator;
  298. }
  299. void set_experiment_cpu_load_estimator(bool enable) {
  300. media_config.video.experiment_cpu_load_estimator = enable;
  301. }
  302. int audio_rtcp_report_interval_ms() const {
  303. return media_config.audio.rtcp_report_interval_ms;
  304. }
  305. void set_audio_rtcp_report_interval_ms(int audio_rtcp_report_interval_ms) {
  306. media_config.audio.rtcp_report_interval_ms =
  307. audio_rtcp_report_interval_ms;
  308. }
  309. int video_rtcp_report_interval_ms() const {
  310. return media_config.video.rtcp_report_interval_ms;
  311. }
  312. void set_video_rtcp_report_interval_ms(int video_rtcp_report_interval_ms) {
  313. media_config.video.rtcp_report_interval_ms =
  314. video_rtcp_report_interval_ms;
  315. }
  316. static const int kUndefined = -1;
  317. // Default maximum number of packets in the audio jitter buffer.
  318. static const int kAudioJitterBufferMaxPackets = 200;
  319. // ICE connection receiving timeout for aggressive configuration.
  320. static const int kAggressiveIceConnectionReceivingTimeout = 1000;
  321. ////////////////////////////////////////////////////////////////////////
  322. // The below few fields mirror the standard RTCConfiguration dictionary:
  323. // https://w3c.github.io/webrtc-pc/#rtcconfiguration-dictionary
  324. ////////////////////////////////////////////////////////////////////////
  325. // TODO(pthatcher): Rename this ice_servers, but update Chromium
  326. // at the same time.
  327. IceServers servers;
  328. // TODO(pthatcher): Rename this ice_transport_type, but update
  329. // Chromium at the same time.
  330. IceTransportsType type = kAll;
  331. BundlePolicy bundle_policy = kBundlePolicyBalanced;
  332. RtcpMuxPolicy rtcp_mux_policy = kRtcpMuxPolicyRequire;
  333. std::vector<rtc::scoped_refptr<rtc::RTCCertificate>> certificates;
  334. int ice_candidate_pool_size = 0;
  335. //////////////////////////////////////////////////////////////////////////
  336. // The below fields correspond to constraints from the deprecated
  337. // constraints interface for constructing a PeerConnection.
  338. //
  339. // absl::optional fields can be "missing", in which case the implementation
  340. // default will be used.
  341. //////////////////////////////////////////////////////////////////////////
  342. // If set to true, don't gather IPv6 ICE candidates.
  343. // TODO(deadbeef): Remove this? IPv6 support has long stopped being
  344. // experimental
  345. bool disable_ipv6 = false;
  346. // If set to true, don't gather IPv6 ICE candidates on Wi-Fi.
  347. // Only intended to be used on specific devices. Certain phones disable IPv6
  348. // when the screen is turned off and it would be better to just disable the
  349. // IPv6 ICE candidates on Wi-Fi in those cases.
  350. bool disable_ipv6_on_wifi = false;
  351. // By default, the PeerConnection will use a limited number of IPv6 network
  352. // interfaces, in order to avoid too many ICE candidate pairs being created
  353. // and delaying ICE completion.
  354. //
  355. // Can be set to INT_MAX to effectively disable the limit.
  356. int max_ipv6_networks = cricket::kDefaultMaxIPv6Networks;
  357. // Exclude link-local network interfaces
  358. // from consideration for gathering ICE candidates.
  359. bool disable_link_local_networks = false;
  360. // If set to true, use RTP data channels instead of SCTP.
  361. // TODO(deadbeef): Remove this. We no longer commit to supporting RTP data
  362. // channels, though some applications are still working on moving off of
  363. // them.
  364. bool enable_rtp_data_channel = false;
  365. // Minimum bitrate at which screencast video tracks will be encoded at.
  366. // This means adding padding bits up to this bitrate, which can help
  367. // when switching from a static scene to one with motion.
  368. absl::optional<int> screencast_min_bitrate;
  369. // Use new combined audio/video bandwidth estimation?
  370. absl::optional<bool> combined_audio_video_bwe;
  371. // TODO(bugs.webrtc.org/9891) - Move to crypto_options
  372. // Can be used to disable DTLS-SRTP. This should never be done, but can be
  373. // useful for testing purposes, for example in setting up a loopback call
  374. // with a single PeerConnection.
  375. absl::optional<bool> enable_dtls_srtp;
  376. /////////////////////////////////////////////////
  377. // The below fields are not part of the standard.
  378. /////////////////////////////////////////////////
  379. // Can be used to disable TCP candidate generation.
  380. TcpCandidatePolicy tcp_candidate_policy = kTcpCandidatePolicyEnabled;
  381. // Can be used to avoid gathering candidates for a "higher cost" network,
  382. // if a lower cost one exists. For example, if both Wi-Fi and cellular
  383. // interfaces are available, this could be used to avoid using the cellular
  384. // interface.
  385. CandidateNetworkPolicy candidate_network_policy =
  386. kCandidateNetworkPolicyAll;
  387. // The maximum number of packets that can be stored in the NetEq audio
  388. // jitter buffer. Can be reduced to lower tolerated audio latency.
  389. int audio_jitter_buffer_max_packets = kAudioJitterBufferMaxPackets;
  390. // Whether to use the NetEq "fast mode" which will accelerate audio quicker
  391. // if it falls behind.
  392. bool audio_jitter_buffer_fast_accelerate = false;
  393. // The minimum delay in milliseconds for the audio jitter buffer.
  394. int audio_jitter_buffer_min_delay_ms = 0;
  395. // Whether the audio jitter buffer adapts the delay to retransmitted
  396. // packets.
  397. bool audio_jitter_buffer_enable_rtx_handling = false;
  398. // Timeout in milliseconds before an ICE candidate pair is considered to be
  399. // "not receiving", after which a lower priority candidate pair may be
  400. // selected.
  401. int ice_connection_receiving_timeout = kUndefined;
  402. // Interval in milliseconds at which an ICE "backup" candidate pair will be
  403. // pinged. This is a candidate pair which is not actively in use, but may
  404. // be switched to if the active candidate pair becomes unusable.
  405. //
  406. // This is relevant mainly to Wi-Fi/cell handoff; the application may not
  407. // want this backup cellular candidate pair pinged frequently, since it
  408. // consumes data/battery.
  409. int ice_backup_candidate_pair_ping_interval = kUndefined;
  410. // Can be used to enable continual gathering, which means new candidates
  411. // will be gathered as network interfaces change. Note that if continual
  412. // gathering is used, the candidate removal API should also be used, to
  413. // avoid an ever-growing list of candidates.
  414. ContinualGatheringPolicy continual_gathering_policy = GATHER_ONCE;
  415. // If set to true, candidate pairs will be pinged in order of most likely
  416. // to work (which means using a TURN server, generally), rather than in
  417. // standard priority order.
  418. bool prioritize_most_likely_ice_candidate_pairs = false;
  419. // Implementation defined settings. A public member only for the benefit of
  420. // the implementation. Applications must not access it directly, and should
  421. // instead use provided accessor methods, e.g., set_cpu_adaptation.
  422. struct cricket::MediaConfig media_config;
  423. // If set to true, only one preferred TURN allocation will be used per
  424. // network interface. UDP is preferred over TCP and IPv6 over IPv4. This
  425. // can be used to cut down on the number of candidate pairings.
  426. // Deprecated. TODO(webrtc:11026) Remove this flag once the downstream
  427. // dependency is removed.
  428. bool prune_turn_ports = false;
  429. // The policy used to prune turn port.
  430. PortPrunePolicy turn_port_prune_policy = NO_PRUNE;
  431. PortPrunePolicy GetTurnPortPrunePolicy() const {
  432. return prune_turn_ports ? PRUNE_BASED_ON_PRIORITY
  433. : turn_port_prune_policy;
  434. }
  435. // If set to true, this means the ICE transport should presume TURN-to-TURN
  436. // candidate pairs will succeed, even before a binding response is received.
  437. // This can be used to optimize the initial connection time, since the DTLS
  438. // handshake can begin immediately.
  439. bool presume_writable_when_fully_relayed = false;
  440. // If true, "renomination" will be added to the ice options in the transport
  441. // description.
  442. // See: https://tools.ietf.org/html/draft-thatcher-ice-renomination-00
  443. bool enable_ice_renomination = false;
  444. // If true, the ICE role is re-determined when the PeerConnection sets a
  445. // local transport description that indicates an ICE restart.
  446. //
  447. // This is standard RFC5245 ICE behavior, but causes unnecessary role
  448. // thrashing, so an application may wish to avoid it. This role
  449. // re-determining was removed in ICEbis (ICE v2).
  450. bool redetermine_role_on_ice_restart = true;
  451. // This flag is only effective when |continual_gathering_policy| is
  452. // GATHER_CONTINUALLY.
  453. //
  454. // If true, after the ICE transport type is changed such that new types of
  455. // ICE candidates are allowed by the new transport type, e.g. from
  456. // IceTransportsType::kRelay to IceTransportsType::kAll, candidates that
  457. // have been gathered by the ICE transport but not matching the previous
  458. // transport type and as a result not observed by PeerConnectionObserver,
  459. // will be surfaced to the observer.
  460. bool surface_ice_candidates_on_ice_transport_type_changed = false;
  461. // The following fields define intervals in milliseconds at which ICE
  462. // connectivity checks are sent.
  463. //
  464. // We consider ICE is "strongly connected" for an agent when there is at
  465. // least one candidate pair that currently succeeds in connectivity check
  466. // from its direction i.e. sending a STUN ping and receives a STUN ping
  467. // response, AND all candidate pairs have sent a minimum number of pings for
  468. // connectivity (this number is implementation-specific). Otherwise, ICE is
  469. // considered in "weak connectivity".
  470. //
  471. // Note that the above notion of strong and weak connectivity is not defined
  472. // in RFC 5245, and they apply to our current ICE implementation only.
  473. //
  474. // 1) ice_check_interval_strong_connectivity defines the interval applied to
  475. // ALL candidate pairs when ICE is strongly connected, and it overrides the
  476. // default value of this interval in the ICE implementation;
  477. // 2) ice_check_interval_weak_connectivity defines the counterpart for ALL
  478. // pairs when ICE is weakly connected, and it overrides the default value of
  479. // this interval in the ICE implementation;
  480. // 3) ice_check_min_interval defines the minimal interval (equivalently the
  481. // maximum rate) that overrides the above two intervals when either of them
  482. // is less.
  483. absl::optional<int> ice_check_interval_strong_connectivity;
  484. absl::optional<int> ice_check_interval_weak_connectivity;
  485. absl::optional<int> ice_check_min_interval;
  486. // The min time period for which a candidate pair must wait for response to
  487. // connectivity checks before it becomes unwritable. This parameter
  488. // overrides the default value in the ICE implementation if set.
  489. absl::optional<int> ice_unwritable_timeout;
  490. // The min number of connectivity checks that a candidate pair must sent
  491. // without receiving response before it becomes unwritable. This parameter
  492. // overrides the default value in the ICE implementation if set.
  493. absl::optional<int> ice_unwritable_min_checks;
  494. // The min time period for which a candidate pair must wait for response to
  495. // connectivity checks it becomes inactive. This parameter overrides the
  496. // default value in the ICE implementation if set.
  497. absl::optional<int> ice_inactive_timeout;
  498. // The interval in milliseconds at which STUN candidates will resend STUN
  499. // binding requests to keep NAT bindings open.
  500. absl::optional<int> stun_candidate_keepalive_interval;
  501. // Optional TurnCustomizer.
  502. // With this class one can modify outgoing TURN messages.
  503. // The object passed in must remain valid until PeerConnection::Close() is
  504. // called.
  505. webrtc::TurnCustomizer* turn_customizer = nullptr;
  506. // Preferred network interface.
  507. // A candidate pair on a preferred network has a higher precedence in ICE
  508. // than one on an un-preferred network, regardless of priority or network
  509. // cost.
  510. absl::optional<rtc::AdapterType> network_preference;
  511. // Configure the SDP semantics used by this PeerConnection. Note that the
  512. // WebRTC 1.0 specification requires kUnifiedPlan semantics. The
  513. // RtpTransceiver API is only available with kUnifiedPlan semantics.
  514. //
  515. // kPlanB will cause PeerConnection to create offers and answers with at
  516. // most one audio and one video m= section with multiple RtpSenders and
  517. // RtpReceivers specified as multiple a=ssrc lines within the section. This
  518. // will also cause PeerConnection to ignore all but the first m= section of
  519. // the same media type.
  520. //
  521. // kUnifiedPlan will cause PeerConnection to create offers and answers with
  522. // multiple m= sections where each m= section maps to one RtpSender and one
  523. // RtpReceiver (an RtpTransceiver), either both audio or both video. This
  524. // will also cause PeerConnection to ignore all but the first a=ssrc lines
  525. // that form a Plan B stream.
  526. //
  527. // For users who wish to send multiple audio/video streams and need to stay
  528. // interoperable with legacy WebRTC implementations or use legacy APIs,
  529. // specify kPlanB.
  530. //
  531. // For all other users, specify kUnifiedPlan.
  532. SdpSemantics sdp_semantics = SdpSemantics::kPlanB;
  533. // TODO(bugs.webrtc.org/9891) - Move to crypto_options or remove.
  534. // Actively reset the SRTP parameters whenever the DTLS transports
  535. // underneath are reset for every offer/answer negotiation.
  536. // This is only intended to be a workaround for crbug.com/835958
  537. // WARNING: This would cause RTP/RTCP packets decryption failure if not used
  538. // correctly. This flag will be deprecated soon. Do not rely on it.
  539. bool active_reset_srtp_params = false;
  540. // Defines advanced optional cryptographic settings related to SRTP and
  541. // frame encryption for native WebRTC. Setting this will overwrite any
  542. // settings set in PeerConnectionFactory (which is deprecated).
  543. absl::optional<CryptoOptions> crypto_options;
  544. // Configure if we should include the SDP attribute extmap-allow-mixed in
  545. // our offer. Although we currently do support this, it's not included in
  546. // our offer by default due to a previous bug that caused the SDP parser to
  547. // abort parsing if this attribute was present. This is fixed in Chrome 71.
  548. // TODO(webrtc:9985): Change default to true once sufficient time has
  549. // passed.
  550. bool offer_extmap_allow_mixed = false;
  551. // TURN logging identifier.
  552. // This identifier is added to a TURN allocation
  553. // and it intended to be used to be able to match client side
  554. // logs with TURN server logs. It will not be added if it's an empty string.
  555. std::string turn_logging_id;
  556. // Added to be able to control rollout of this feature.
  557. bool enable_implicit_rollback = false;
  558. // Whether network condition based codec switching is allowed.
  559. absl::optional<bool> allow_codec_switching;
  560. //
  561. // Don't forget to update operator== if adding something.
  562. //
  563. };
  564. // See: https://www.w3.org/TR/webrtc/#idl-def-rtcofferansweroptions
  565. struct RTCOfferAnswerOptions {
  566. static const int kUndefined = -1;
  567. static const int kMaxOfferToReceiveMedia = 1;
  568. // The default value for constraint offerToReceiveX:true.
  569. static const int kOfferToReceiveMediaTrue = 1;
  570. // These options are left as backwards compatibility for clients who need
  571. // "Plan B" semantics. Clients who have switched to "Unified Plan" semantics
  572. // should use the RtpTransceiver API (AddTransceiver) instead.
  573. //
  574. // offer_to_receive_X set to 1 will cause a media description to be
  575. // generated in the offer, even if no tracks of that type have been added.
  576. // Values greater than 1 are treated the same.
  577. //
  578. // If set to 0, the generated directional attribute will not include the
  579. // "recv" direction (meaning it will be "sendonly" or "inactive".
  580. int offer_to_receive_video = kUndefined;
  581. int offer_to_receive_audio = kUndefined;
  582. bool voice_activity_detection = true;
  583. bool ice_restart = false;
  584. // If true, will offer to BUNDLE audio/video/data together. Not to be
  585. // confused with RTCP mux (multiplexing RTP and RTCP together).
  586. bool use_rtp_mux = true;
  587. // If true, "a=packetization:<payload_type> raw" attribute will be offered
  588. // in the SDP for all video payload and accepted in the answer if offered.
  589. bool raw_packetization_for_video = false;
  590. // This will apply to all video tracks with a Plan B SDP offer/answer.
  591. int num_simulcast_layers = 1;
  592. // If true: Use SDP format from draft-ietf-mmusic-scdp-sdp-03
  593. // If false: Use SDP format from draft-ietf-mmusic-sdp-sdp-26 or later
  594. bool use_obsolete_sctp_sdp = false;
  595. RTCOfferAnswerOptions() = default;
  596. RTCOfferAnswerOptions(int offer_to_receive_video,
  597. int offer_to_receive_audio,
  598. bool voice_activity_detection,
  599. bool ice_restart,
  600. bool use_rtp_mux)
  601. : offer_to_receive_video(offer_to_receive_video),
  602. offer_to_receive_audio(offer_to_receive_audio),
  603. voice_activity_detection(voice_activity_detection),
  604. ice_restart(ice_restart),
  605. use_rtp_mux(use_rtp_mux) {}
  606. };
  607. // Used by GetStats to decide which stats to include in the stats reports.
  608. // |kStatsOutputLevelStandard| includes the standard stats for Javascript API;
  609. // |kStatsOutputLevelDebug| includes both the standard stats and additional
  610. // stats for debugging purposes.
  611. enum StatsOutputLevel {
  612. kStatsOutputLevelStandard,
  613. kStatsOutputLevelDebug,
  614. };
  615. // Accessor methods to active local streams.
  616. // This method is not supported with kUnifiedPlan semantics. Please use
  617. // GetSenders() instead.
  618. virtual rtc::scoped_refptr<StreamCollectionInterface> local_streams() = 0;
  619. // Accessor methods to remote streams.
  620. // This method is not supported with kUnifiedPlan semantics. Please use
  621. // GetReceivers() instead.
  622. virtual rtc::scoped_refptr<StreamCollectionInterface> remote_streams() = 0;
  623. // Add a new MediaStream to be sent on this PeerConnection.
  624. // Note that a SessionDescription negotiation is needed before the
  625. // remote peer can receive the stream.
  626. //
  627. // This has been removed from the standard in favor of a track-based API. So,
  628. // this is equivalent to simply calling AddTrack for each track within the
  629. // stream, with the one difference that if "stream->AddTrack(...)" is called
  630. // later, the PeerConnection will automatically pick up the new track. Though
  631. // this functionality will be deprecated in the future.
  632. //
  633. // This method is not supported with kUnifiedPlan semantics. Please use
  634. // AddTrack instead.
  635. virtual bool AddStream(MediaStreamInterface* stream) = 0;
  636. // Remove a MediaStream from this PeerConnection.
  637. // Note that a SessionDescription negotiation is needed before the
  638. // remote peer is notified.
  639. //
  640. // This method is not supported with kUnifiedPlan semantics. Please use
  641. // RemoveTrack instead.
  642. virtual void RemoveStream(MediaStreamInterface* stream) = 0;
  643. // Add a new MediaStreamTrack to be sent on this PeerConnection, and return
  644. // the newly created RtpSender. The RtpSender will be associated with the
  645. // streams specified in the |stream_ids| list.
  646. //
  647. // Errors:
  648. // - INVALID_PARAMETER: |track| is null, has a kind other than audio or video,
  649. // or a sender already exists for the track.
  650. // - INVALID_STATE: The PeerConnection is closed.
  651. virtual RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> AddTrack(
  652. rtc::scoped_refptr<MediaStreamTrackInterface> track,
  653. const std::vector<std::string>& stream_ids) = 0;
  654. // Remove an RtpSender from this PeerConnection.
  655. // Returns true on success.
  656. // TODO(steveanton): Replace with signature that returns RTCError.
  657. virtual bool RemoveTrack(RtpSenderInterface* sender) = 0;
  658. // Plan B semantics: Removes the RtpSender from this PeerConnection.
  659. // Unified Plan semantics: Stop sending on the RtpSender and mark the
  660. // corresponding RtpTransceiver direction as no longer sending.
  661. //
  662. // Errors:
  663. // - INVALID_PARAMETER: |sender| is null or (Plan B only) the sender is not
  664. // associated with this PeerConnection.
  665. // - INVALID_STATE: PeerConnection is closed.
  666. // TODO(bugs.webrtc.org/9534): Rename to RemoveTrack once the other signature
  667. // is removed.
  668. virtual RTCError RemoveTrackNew(
  669. rtc::scoped_refptr<RtpSenderInterface> sender);
  670. // AddTransceiver creates a new RtpTransceiver and adds it to the set of
  671. // transceivers. Adding a transceiver will cause future calls to CreateOffer
  672. // to add a media description for the corresponding transceiver.
  673. //
  674. // The initial value of |mid| in the returned transceiver is null. Setting a
  675. // new session description may change it to a non-null value.
  676. //
  677. // https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-addtransceiver
  678. //
  679. // Optionally, an RtpTransceiverInit structure can be specified to configure
  680. // the transceiver from construction. If not specified, the transceiver will
  681. // default to having a direction of kSendRecv and not be part of any streams.
  682. //
  683. // These methods are only available when Unified Plan is enabled (see
  684. // RTCConfiguration).
  685. //
  686. // Common errors:
  687. // - INTERNAL_ERROR: The configuration does not have Unified Plan enabled.
  688. // Adds a transceiver with a sender set to transmit the given track. The kind
  689. // of the transceiver (and sender/receiver) will be derived from the kind of
  690. // the track.
  691. // Errors:
  692. // - INVALID_PARAMETER: |track| is null.
  693. virtual RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>>
  694. AddTransceiver(rtc::scoped_refptr<MediaStreamTrackInterface> track) = 0;
  695. virtual RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>>
  696. AddTransceiver(rtc::scoped_refptr<MediaStreamTrackInterface> track,
  697. const RtpTransceiverInit& init) = 0;
  698. // Adds a transceiver with the given kind. Can either be MEDIA_TYPE_AUDIO or
  699. // MEDIA_TYPE_VIDEO.
  700. // Errors:
  701. // - INVALID_PARAMETER: |media_type| is not MEDIA_TYPE_AUDIO or
  702. // MEDIA_TYPE_VIDEO.
  703. virtual RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>>
  704. AddTransceiver(cricket::MediaType media_type) = 0;
  705. virtual RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>>
  706. AddTransceiver(cricket::MediaType media_type,
  707. const RtpTransceiverInit& init) = 0;
  708. // Creates a sender without a track. Can be used for "early media"/"warmup"
  709. // use cases, where the application may want to negotiate video attributes
  710. // before a track is available to send.
  711. //
  712. // The standard way to do this would be through "addTransceiver", but we
  713. // don't support that API yet.
  714. //
  715. // |kind| must be "audio" or "video".
  716. //
  717. // |stream_id| is used to populate the msid attribute; if empty, one will
  718. // be generated automatically.
  719. //
  720. // This method is not supported with kUnifiedPlan semantics. Please use
  721. // AddTransceiver instead.
  722. virtual rtc::scoped_refptr<RtpSenderInterface> CreateSender(
  723. const std::string& kind,
  724. const std::string& stream_id) = 0;
  725. // If Plan B semantics are specified, gets all RtpSenders, created either
  726. // through AddStream, AddTrack, or CreateSender. All senders of a specific
  727. // media type share the same media description.
  728. //
  729. // If Unified Plan semantics are specified, gets the RtpSender for each
  730. // RtpTransceiver.
  731. virtual std::vector<rtc::scoped_refptr<RtpSenderInterface>> GetSenders()
  732. const = 0;
  733. // If Plan B semantics are specified, gets all RtpReceivers created when a
  734. // remote description is applied. All receivers of a specific media type share
  735. // the same media description. It is also possible to have a media description
  736. // with no associated RtpReceivers, if the directional attribute does not
  737. // indicate that the remote peer is sending any media.
  738. //
  739. // If Unified Plan semantics are specified, gets the RtpReceiver for each
  740. // RtpTransceiver.
  741. virtual std::vector<rtc::scoped_refptr<RtpReceiverInterface>> GetReceivers()
  742. const = 0;
  743. // Get all RtpTransceivers, created either through AddTransceiver, AddTrack or
  744. // by a remote description applied with SetRemoteDescription.
  745. //
  746. // Note: This method is only available when Unified Plan is enabled (see
  747. // RTCConfiguration).
  748. virtual std::vector<rtc::scoped_refptr<RtpTransceiverInterface>>
  749. GetTransceivers() const = 0;
  750. // The legacy non-compliant GetStats() API. This correspond to the
  751. // callback-based version of getStats() in JavaScript. The returned metrics
  752. // are UNDOCUMENTED and many of them rely on implementation-specific details.
  753. // The goal is to DELETE THIS VERSION but we can't today because it is heavily
  754. // relied upon by third parties. See https://crbug.com/822696.
  755. //
  756. // This version is wired up into Chrome. Any stats implemented are
  757. // automatically exposed to the Web Platform. This has BYPASSED the Chrome
  758. // release processes for years and lead to cross-browser incompatibility
  759. // issues and web application reliance on Chrome-only behavior.
  760. //
  761. // This API is in "maintenance mode", serious regressions should be fixed but
  762. // adding new stats is highly discouraged.
  763. //
  764. // TODO(hbos): Deprecate and remove this when third parties have migrated to
  765. // the spec-compliant GetStats() API. https://crbug.com/822696
  766. virtual bool GetStats(StatsObserver* observer,
  767. MediaStreamTrackInterface* track, // Optional
  768. StatsOutputLevel level) = 0;
  769. // The spec-compliant GetStats() API. This correspond to the promise-based
  770. // version of getStats() in JavaScript. Implementation status is described in
  771. // api/stats/rtcstats_objects.h. For more details on stats, see spec:
  772. // https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-getstats
  773. // TODO(hbos): Takes shared ownership, use rtc::scoped_refptr<> instead. This
  774. // requires stop overriding the current version in third party or making third
  775. // party calls explicit to avoid ambiguity during switch. Make the future
  776. // version abstract as soon as third party projects implement it.
  777. virtual void GetStats(RTCStatsCollectorCallback* callback) = 0;
  778. // Spec-compliant getStats() performing the stats selection algorithm with the
  779. // sender. https://w3c.github.io/webrtc-pc/#dom-rtcrtpsender-getstats
  780. virtual void GetStats(
  781. rtc::scoped_refptr<RtpSenderInterface> selector,
  782. rtc::scoped_refptr<RTCStatsCollectorCallback> callback) = 0;
  783. // Spec-compliant getStats() performing the stats selection algorithm with the
  784. // receiver. https://w3c.github.io/webrtc-pc/#dom-rtcrtpreceiver-getstats
  785. virtual void GetStats(
  786. rtc::scoped_refptr<RtpReceiverInterface> selector,
  787. rtc::scoped_refptr<RTCStatsCollectorCallback> callback) = 0;
  788. // Clear cached stats in the RTCStatsCollector.
  789. // Exposed for testing while waiting for automatic cache clear to work.
  790. // https://bugs.webrtc.org/8693
  791. virtual void ClearStatsCache() {}
  792. // Create a data channel with the provided config, or default config if none
  793. // is provided. Note that an offer/answer negotiation is still necessary
  794. // before the data channel can be used.
  795. //
  796. // Also, calling CreateDataChannel is the only way to get a data "m=" section
  797. // in SDP, so it should be done before CreateOffer is called, if the
  798. // application plans to use data channels.
  799. virtual rtc::scoped_refptr<DataChannelInterface> CreateDataChannel(
  800. const std::string& label,
  801. const DataChannelInit* config) = 0;
  802. // NOTE: For the following 6 methods, it's only safe to dereference the
  803. // SessionDescriptionInterface on signaling_thread() (for example, calling
  804. // ToString).
  805. // Returns the more recently applied description; "pending" if it exists, and
  806. // otherwise "current". See below.
  807. virtual const SessionDescriptionInterface* local_description() const = 0;
  808. virtual const SessionDescriptionInterface* remote_description() const = 0;
  809. // A "current" description the one currently negotiated from a complete
  810. // offer/answer exchange.
  811. virtual const SessionDescriptionInterface* current_local_description()
  812. const = 0;
  813. virtual const SessionDescriptionInterface* current_remote_description()
  814. const = 0;
  815. // A "pending" description is one that's part of an incomplete offer/answer
  816. // exchange (thus, either an offer or a pranswer). Once the offer/answer
  817. // exchange is finished, the "pending" description will become "current".
  818. virtual const SessionDescriptionInterface* pending_local_description()
  819. const = 0;
  820. virtual const SessionDescriptionInterface* pending_remote_description()
  821. const = 0;
  822. // Tells the PeerConnection that ICE should be restarted. This triggers a need
  823. // for negotiation and subsequent CreateOffer() calls will act as if
  824. // RTCOfferAnswerOptions::ice_restart is true.
  825. // https://w3c.github.io/webrtc-pc/#dom-rtcpeerconnection-restartice
  826. // TODO(hbos): Remove default implementation when downstream projects
  827. // implement this.
  828. virtual void RestartIce() = 0;
  829. // Create a new offer.
  830. // The CreateSessionDescriptionObserver callback will be called when done.
  831. virtual void CreateOffer(CreateSessionDescriptionObserver* observer,
  832. const RTCOfferAnswerOptions& options) = 0;
  833. // Create an answer to an offer.
  834. // The CreateSessionDescriptionObserver callback will be called when done.
  835. virtual void CreateAnswer(CreateSessionDescriptionObserver* observer,
  836. const RTCOfferAnswerOptions& options) = 0;
  837. // Sets the local session description.
  838. //
  839. // According to spec, the local session description MUST be the same as was
  840. // returned by CreateOffer() or CreateAnswer() or else the operation should
  841. // fail. Our implementation however allows some amount of "SDP munging", but
  842. // please note that this is HIGHLY DISCOURAGED. If you do not intent to munge
  843. // SDP, the method below that doesn't take |desc| as an argument will create
  844. // the offer or answer for you.
  845. //
  846. // The observer is invoked as soon as the operation completes, which could be
  847. // before or after the SetLocalDescription() method has exited.
  848. virtual void SetLocalDescription(
  849. std::unique_ptr<SessionDescriptionInterface> desc,
  850. rtc::scoped_refptr<SetLocalDescriptionObserverInterface> observer) {}
  851. // Creates an offer or answer (depending on current signaling state) and sets
  852. // it as the local session description.
  853. //
  854. // The observer is invoked as soon as the operation completes, which could be
  855. // before or after the SetLocalDescription() method has exited.
  856. virtual void SetLocalDescription(
  857. rtc::scoped_refptr<SetLocalDescriptionObserverInterface> observer) {}
  858. // Like SetLocalDescription() above, but the observer is invoked with a delay
  859. // after the operation completes. This helps avoid recursive calls by the
  860. // observer but also makes it possible for states to change in-between the
  861. // operation completing and the observer getting called. This makes them racy
  862. // for synchronizing peer connection states to the application.
  863. // TODO(https://crbug.com/webrtc/11798): Delete these methods in favor of the
  864. // ones taking SetLocalDescriptionObserverInterface as argument.
  865. virtual void SetLocalDescription(SetSessionDescriptionObserver* observer,
  866. SessionDescriptionInterface* desc) = 0;
  867. virtual void SetLocalDescription(SetSessionDescriptionObserver* observer) {}
  868. // Sets the remote session description.
  869. //
  870. // (Unlike "SDP munging" before SetLocalDescription(), modifying a remote
  871. // offer or answer is allowed by the spec.)
  872. //
  873. // The observer is invoked as soon as the operation completes, which could be
  874. // before or after the SetRemoteDescription() method has exited.
  875. virtual void SetRemoteDescription(
  876. std::unique_ptr<SessionDescriptionInterface> desc,
  877. rtc::scoped_refptr<SetRemoteDescriptionObserverInterface> observer) = 0;
  878. // Like SetRemoteDescription() above, but the observer is invoked with a delay
  879. // after the operation completes. This helps avoid recursive calls by the
  880. // observer but also makes it possible for states to change in-between the
  881. // operation completing and the observer getting called. This makes them racy
  882. // for synchronizing peer connection states to the application.
  883. // TODO(https://crbug.com/webrtc/11798): Delete this method in favor of the
  884. // ones taking SetRemoteDescriptionObserverInterface as argument.
  885. virtual void SetRemoteDescription(SetSessionDescriptionObserver* observer,
  886. SessionDescriptionInterface* desc) {}
  887. // According to spec, we must only fire "negotiationneeded" if the Operations
  888. // Chain is empty. This method takes care of validating an event previously
  889. // generated with PeerConnectionObserver::OnNegotiationNeededEvent() to make
  890. // sure that even if there was a delay (e.g. due to a PostTask) between the
  891. // event being generated and the time of firing, the Operations Chain is empty
  892. // and the event is still valid to be fired.
  893. virtual bool ShouldFireNegotiationNeededEvent(uint32_t event_id) {
  894. return true;
  895. }
  896. virtual PeerConnectionInterface::RTCConfiguration GetConfiguration() = 0;
  897. // Sets the PeerConnection's global configuration to |config|.
  898. //
  899. // The members of |config| that may be changed are |type|, |servers|,
  900. // |ice_candidate_pool_size| and |prune_turn_ports| (though the candidate
  901. // pool size can't be changed after the first call to SetLocalDescription).
  902. // Note that this means the BUNDLE and RTCP-multiplexing policies cannot be
  903. // changed with this method.
  904. //
  905. // Any changes to STUN/TURN servers or ICE candidate policy will affect the
  906. // next gathering phase, and cause the next call to createOffer to generate
  907. // new ICE credentials, as described in JSEP. This also occurs when
  908. // |prune_turn_ports| changes, for the same reasoning.
  909. //
  910. // If an error occurs, returns false and populates |error| if non-null:
  911. // - INVALID_MODIFICATION if |config| contains a modified parameter other
  912. // than one of the parameters listed above.
  913. // - INVALID_RANGE if |ice_candidate_pool_size| is out of range.
  914. // - SYNTAX_ERROR if parsing an ICE server URL failed.
  915. // - INVALID_PARAMETER if a TURN server is missing |username| or |password|.
  916. // - INTERNAL_ERROR if an unexpected error occurred.
  917. //
  918. // TODO(nisse): Make this pure virtual once all Chrome subclasses of
  919. // PeerConnectionInterface implement it.
  920. virtual RTCError SetConfiguration(
  921. const PeerConnectionInterface::RTCConfiguration& config);
  922. // Provides a remote candidate to the ICE Agent.
  923. // A copy of the |candidate| will be created and added to the remote
  924. // description. So the caller of this method still has the ownership of the
  925. // |candidate|.
  926. // TODO(hbos): The spec mandates chaining this operation onto the operations
  927. // chain; deprecate and remove this version in favor of the callback-based
  928. // signature.
  929. virtual bool AddIceCandidate(const IceCandidateInterface* candidate) = 0;
  930. // TODO(hbos): Remove default implementation once implemented by downstream
  931. // projects.
  932. virtual void AddIceCandidate(std::unique_ptr<IceCandidateInterface> candidate,
  933. std::function<void(RTCError)> callback) {}
  934. // Removes a group of remote candidates from the ICE agent. Needed mainly for
  935. // continual gathering, to avoid an ever-growing list of candidates as
  936. // networks come and go.
  937. virtual bool RemoveIceCandidates(
  938. const std::vector<cricket::Candidate>& candidates) = 0;
  939. // SetBitrate limits the bandwidth allocated for all RTP streams sent by
  940. // this PeerConnection. Other limitations might affect these limits and
  941. // are respected (for example "b=AS" in SDP).
  942. //
  943. // Setting |current_bitrate_bps| will reset the current bitrate estimate
  944. // to the provided value.
  945. virtual RTCError SetBitrate(const BitrateSettings& bitrate) = 0;
  946. // Enable/disable playout of received audio streams. Enabled by default. Note
  947. // that even if playout is enabled, streams will only be played out if the
  948. // appropriate SDP is also applied. Setting |playout| to false will stop
  949. // playout of the underlying audio device but starts a task which will poll
  950. // for audio data every 10ms to ensure that audio processing happens and the
  951. // audio statistics are updated.
  952. // TODO(henrika): deprecate and remove this.
  953. virtual void SetAudioPlayout(bool playout) {}
  954. // Enable/disable recording of transmitted audio streams. Enabled by default.
  955. // Note that even if recording is enabled, streams will only be recorded if
  956. // the appropriate SDP is also applied.
  957. // TODO(henrika): deprecate and remove this.
  958. virtual void SetAudioRecording(bool recording) {}
  959. // Looks up the DtlsTransport associated with a MID value.
  960. // In the Javascript API, DtlsTransport is a property of a sender, but
  961. // because the PeerConnection owns the DtlsTransport in this implementation,
  962. // it is better to look them up on the PeerConnection.
  963. virtual rtc::scoped_refptr<DtlsTransportInterface> LookupDtlsTransportByMid(
  964. const std::string& mid) = 0;
  965. // Returns the SCTP transport, if any.
  966. virtual rtc::scoped_refptr<SctpTransportInterface> GetSctpTransport()
  967. const = 0;
  968. // Returns the current SignalingState.
  969. virtual SignalingState signaling_state() = 0;
  970. // Returns an aggregate state of all ICE *and* DTLS transports.
  971. // This is left in place to avoid breaking native clients who expect our old,
  972. // nonstandard behavior.
  973. // TODO(jonasolsson): deprecate and remove this.
  974. virtual IceConnectionState ice_connection_state() = 0;
  975. // Returns an aggregated state of all ICE transports.
  976. virtual IceConnectionState standardized_ice_connection_state() = 0;
  977. // Returns an aggregated state of all ICE and DTLS transports.
  978. virtual PeerConnectionState peer_connection_state() = 0;
  979. virtual IceGatheringState ice_gathering_state() = 0;
  980. // Returns the current state of canTrickleIceCandidates per
  981. // https://w3c.github.io/webrtc-pc/#attributes-1
  982. virtual absl::optional<bool> can_trickle_ice_candidates() {
  983. // TODO(crbug.com/708484): Remove default implementation.
  984. return absl::nullopt;
  985. }
  986. // When a resource is overused, the PeerConnection will try to reduce the load
  987. // on the sysem, for example by reducing the resolution or frame rate of
  988. // encoded streams. The Resource API allows injecting platform-specific usage
  989. // measurements. The conditions to trigger kOveruse or kUnderuse are up to the
  990. // implementation.
  991. // TODO(hbos): Make pure virtual when implemented by downstream projects.
  992. virtual void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) {}
  993. // Start RtcEventLog using an existing output-sink. Takes ownership of
  994. // |output| and passes it on to Call, which will take the ownership. If the
  995. // operation fails the output will be closed and deallocated. The event log
  996. // will send serialized events to the output object every |output_period_ms|.
  997. // Applications using the event log should generally make their own trade-off
  998. // regarding the output period. A long period is generally more efficient,
  999. // with potential drawbacks being more bursty thread usage, and more events
  1000. // lost in case the application crashes. If the |output_period_ms| argument is
  1001. // omitted, webrtc selects a default deemed to be workable in most cases.
  1002. virtual bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output,
  1003. int64_t output_period_ms) = 0;
  1004. virtual bool StartRtcEventLog(std::unique_ptr<RtcEventLogOutput> output) = 0;
  1005. // Stops logging the RtcEventLog.
  1006. virtual void StopRtcEventLog() = 0;
  1007. // Terminates all media, closes the transports, and in general releases any
  1008. // resources used by the PeerConnection. This is an irreversible operation.
  1009. //
  1010. // Note that after this method completes, the PeerConnection will no longer
  1011. // use the PeerConnectionObserver interface passed in on construction, and
  1012. // thus the observer object can be safely destroyed.
  1013. virtual void Close() = 0;
  1014. // The thread on which all PeerConnectionObserver callbacks will be invoked,
  1015. // as well as callbacks for other classes such as DataChannelObserver.
  1016. //
  1017. // Also the only thread on which it's safe to use SessionDescriptionInterface
  1018. // pointers.
  1019. // TODO(deadbeef): Make pure virtual when all subclasses implement it.
  1020. virtual rtc::Thread* signaling_thread() const { return nullptr; }
  1021. protected:
  1022. // Dtor protected as objects shouldn't be deleted via this interface.
  1023. ~PeerConnectionInterface() override = default;
  1024. };
  1025. // PeerConnection callback interface, used for RTCPeerConnection events.
  1026. // Application should implement these methods.
  1027. class PeerConnectionObserver {
  1028. public:
  1029. virtual ~PeerConnectionObserver() = default;
  1030. // Triggered when the SignalingState changed.
  1031. virtual void OnSignalingChange(
  1032. PeerConnectionInterface::SignalingState new_state) = 0;
  1033. // Triggered when media is received on a new stream from remote peer.
  1034. virtual void OnAddStream(rtc::scoped_refptr<MediaStreamInterface> stream) {}
  1035. // Triggered when a remote peer closes a stream.
  1036. virtual void OnRemoveStream(rtc::scoped_refptr<MediaStreamInterface> stream) {
  1037. }
  1038. // Triggered when a remote peer opens a data channel.
  1039. virtual void OnDataChannel(
  1040. rtc::scoped_refptr<DataChannelInterface> data_channel) = 0;
  1041. // Triggered when renegotiation is needed. For example, an ICE restart
  1042. // has begun.
  1043. // TODO(hbos): Delete in favor of OnNegotiationNeededEvent() when downstream
  1044. // projects have migrated.
  1045. virtual void OnRenegotiationNeeded() {}
  1046. // Used to fire spec-compliant onnegotiationneeded events, which should only
  1047. // fire when the Operations Chain is empty. The observer is responsible for
  1048. // queuing a task (e.g. Chromium: jump to main thread) to maybe fire the
  1049. // event. The event identified using |event_id| must only fire if
  1050. // PeerConnection::ShouldFireNegotiationNeededEvent() returns true since it is
  1051. // possible for the event to become invalidated by operations subsequently
  1052. // chained.
  1053. virtual void OnNegotiationNeededEvent(uint32_t event_id) {}
  1054. // Called any time the legacy IceConnectionState changes.
  1055. //
  1056. // Note that our ICE states lag behind the standard slightly. The most
  1057. // notable differences include the fact that "failed" occurs after 15
  1058. // seconds, not 30, and this actually represents a combination ICE + DTLS
  1059. // state, so it may be "failed" if DTLS fails while ICE succeeds.
  1060. //
  1061. // TODO(jonasolsson): deprecate and remove this.
  1062. virtual void OnIceConnectionChange(
  1063. PeerConnectionInterface::IceConnectionState new_state) {}
  1064. // Called any time the standards-compliant IceConnectionState changes.
  1065. virtual void OnStandardizedIceConnectionChange(
  1066. PeerConnectionInterface::IceConnectionState new_state) {}
  1067. // Called any time the PeerConnectionState changes.
  1068. virtual void OnConnectionChange(
  1069. PeerConnectionInterface::PeerConnectionState new_state) {}
  1070. // Called any time the IceGatheringState changes.
  1071. virtual void OnIceGatheringChange(
  1072. PeerConnectionInterface::IceGatheringState new_state) = 0;
  1073. // A new ICE candidate has been gathered.
  1074. virtual void OnIceCandidate(const IceCandidateInterface* candidate) = 0;
  1075. // Gathering of an ICE candidate failed.
  1076. // See https://w3c.github.io/webrtc-pc/#event-icecandidateerror
  1077. // |host_candidate| is a stringified socket address.
  1078. virtual void OnIceCandidateError(const std::string& host_candidate,
  1079. const std::string& url,
  1080. int error_code,
  1081. const std::string& error_text) {}
  1082. // Gathering of an ICE candidate failed.
  1083. // See https://w3c.github.io/webrtc-pc/#event-icecandidateerror
  1084. virtual void OnIceCandidateError(const std::string& address,
  1085. int port,
  1086. const std::string& url,
  1087. int error_code,
  1088. const std::string& error_text) {}
  1089. // Ice candidates have been removed.
  1090. // TODO(honghaiz): Make this a pure virtual method when all its subclasses
  1091. // implement it.
  1092. virtual void OnIceCandidatesRemoved(
  1093. const std::vector<cricket::Candidate>& candidates) {}
  1094. // Called when the ICE connection receiving status changes.
  1095. virtual void OnIceConnectionReceivingChange(bool receiving) {}
  1096. // Called when the selected candidate pair for the ICE connection changes.
  1097. virtual void OnIceSelectedCandidatePairChanged(
  1098. const cricket::CandidatePairChangeEvent& event) {}
  1099. // This is called when a receiver and its track are created.
  1100. // TODO(zhihuang): Make this pure virtual when all subclasses implement it.
  1101. // Note: This is called with both Plan B and Unified Plan semantics. Unified
  1102. // Plan users should prefer OnTrack, OnAddTrack is only called as backwards
  1103. // compatibility (and is called in the exact same situations as OnTrack).
  1104. virtual void OnAddTrack(
  1105. rtc::scoped_refptr<RtpReceiverInterface> receiver,
  1106. const std::vector<rtc::scoped_refptr<MediaStreamInterface>>& streams) {}
  1107. // This is called when signaling indicates a transceiver will be receiving
  1108. // media from the remote endpoint. This is fired during a call to
  1109. // SetRemoteDescription. The receiving track can be accessed by:
  1110. // |transceiver->receiver()->track()| and its associated streams by
  1111. // |transceiver->receiver()->streams()|.
  1112. // Note: This will only be called if Unified Plan semantics are specified.
  1113. // This behavior is specified in section 2.2.8.2.5 of the "Set the
  1114. // RTCSessionDescription" algorithm:
  1115. // https://w3c.github.io/webrtc-pc/#set-description
  1116. virtual void OnTrack(
  1117. rtc::scoped_refptr<RtpTransceiverInterface> transceiver) {}
  1118. // Called when signaling indicates that media will no longer be received on a
  1119. // track.
  1120. // With Plan B semantics, the given receiver will have been removed from the
  1121. // PeerConnection and the track muted.
  1122. // With Unified Plan semantics, the receiver will remain but the transceiver
  1123. // will have changed direction to either sendonly or inactive.
  1124. // https://w3c.github.io/webrtc-pc/#process-remote-track-removal
  1125. // TODO(hbos,deadbeef): Make pure virtual when all subclasses implement it.
  1126. virtual void OnRemoveTrack(
  1127. rtc::scoped_refptr<RtpReceiverInterface> receiver) {}
  1128. // Called when an interesting usage is detected by WebRTC.
  1129. // An appropriate action is to add information about the context of the
  1130. // PeerConnection and write the event to some kind of "interesting events"
  1131. // log function.
  1132. // The heuristics for defining what constitutes "interesting" are
  1133. // implementation-defined.
  1134. virtual void OnInterestingUsage(int usage_pattern) {}
  1135. };
  1136. // PeerConnectionDependencies holds all of PeerConnections dependencies.
  1137. // A dependency is distinct from a configuration as it defines significant
  1138. // executable code that can be provided by a user of the API.
  1139. //
  1140. // All new dependencies should be added as a unique_ptr to allow the
  1141. // PeerConnection object to be the definitive owner of the dependencies
  1142. // lifetime making injection safer.
  1143. struct RTC_EXPORT PeerConnectionDependencies final {
  1144. explicit PeerConnectionDependencies(PeerConnectionObserver* observer_in);
  1145. // This object is not copyable or assignable.
  1146. PeerConnectionDependencies(const PeerConnectionDependencies&) = delete;
  1147. PeerConnectionDependencies& operator=(const PeerConnectionDependencies&) =
  1148. delete;
  1149. // This object is only moveable.
  1150. PeerConnectionDependencies(PeerConnectionDependencies&&);
  1151. PeerConnectionDependencies& operator=(PeerConnectionDependencies&&) = default;
  1152. ~PeerConnectionDependencies();
  1153. // Mandatory dependencies
  1154. PeerConnectionObserver* observer = nullptr;
  1155. // Optional dependencies
  1156. // TODO(bugs.webrtc.org/7447): remove port allocator once downstream is
  1157. // updated. For now, you can only set one of allocator and
  1158. // packet_socket_factory, not both.
  1159. std::unique_ptr<cricket::PortAllocator> allocator;
  1160. std::unique_ptr<rtc::PacketSocketFactory> packet_socket_factory;
  1161. std::unique_ptr<webrtc::AsyncResolverFactory> async_resolver_factory;
  1162. std::unique_ptr<webrtc::IceTransportFactory> ice_transport_factory;
  1163. std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator;
  1164. std::unique_ptr<rtc::SSLCertificateVerifier> tls_cert_verifier;
  1165. std::unique_ptr<webrtc::VideoBitrateAllocatorFactory>
  1166. video_bitrate_allocator_factory;
  1167. };
  1168. // PeerConnectionFactoryDependencies holds all of the PeerConnectionFactory
  1169. // dependencies. All new dependencies should be added here instead of
  1170. // overloading the function. This simplifies dependency injection and makes it
  1171. // clear which are mandatory and optional. If possible please allow the peer
  1172. // connection factory to take ownership of the dependency by adding a unique_ptr
  1173. // to this structure.
  1174. struct RTC_EXPORT PeerConnectionFactoryDependencies final {
  1175. PeerConnectionFactoryDependencies();
  1176. // This object is not copyable or assignable.
  1177. PeerConnectionFactoryDependencies(const PeerConnectionFactoryDependencies&) =
  1178. delete;
  1179. PeerConnectionFactoryDependencies& operator=(
  1180. const PeerConnectionFactoryDependencies&) = delete;
  1181. // This object is only moveable.
  1182. PeerConnectionFactoryDependencies(PeerConnectionFactoryDependencies&&);
  1183. PeerConnectionFactoryDependencies& operator=(
  1184. PeerConnectionFactoryDependencies&&) = default;
  1185. ~PeerConnectionFactoryDependencies();
  1186. // Optional dependencies
  1187. rtc::Thread* network_thread = nullptr;
  1188. rtc::Thread* worker_thread = nullptr;
  1189. rtc::Thread* signaling_thread = nullptr;
  1190. std::unique_ptr<TaskQueueFactory> task_queue_factory;
  1191. std::unique_ptr<cricket::MediaEngineInterface> media_engine;
  1192. std::unique_ptr<CallFactoryInterface> call_factory;
  1193. std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory;
  1194. std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory;
  1195. std::unique_ptr<NetworkStatePredictorFactoryInterface>
  1196. network_state_predictor_factory;
  1197. std::unique_ptr<NetworkControllerFactoryInterface> network_controller_factory;
  1198. // This will only be used if CreatePeerConnection is called without a
  1199. // |port_allocator|, causing the default allocator and network manager to be
  1200. // used.
  1201. std::unique_ptr<rtc::NetworkMonitorFactory> network_monitor_factory;
  1202. std::unique_ptr<NetEqFactory> neteq_factory;
  1203. std::unique_ptr<SctpTransportFactoryInterface> sctp_factory;
  1204. std::unique_ptr<WebRtcKeyValueConfig> trials;
  1205. };
  1206. // PeerConnectionFactoryInterface is the factory interface used for creating
  1207. // PeerConnection, MediaStream and MediaStreamTrack objects.
  1208. //
  1209. // The simplest method for obtaiing one, CreatePeerConnectionFactory will
  1210. // create the required libjingle threads, socket and network manager factory
  1211. // classes for networking if none are provided, though it requires that the
  1212. // application runs a message loop on the thread that called the method (see
  1213. // explanation below)
  1214. //
  1215. // If an application decides to provide its own threads and/or implementation
  1216. // of networking classes, it should use the alternate
  1217. // CreatePeerConnectionFactory method which accepts threads as input, and use
  1218. // the CreatePeerConnection version that takes a PortAllocator as an argument.
  1219. class RTC_EXPORT PeerConnectionFactoryInterface
  1220. : public rtc::RefCountInterface {
  1221. public:
  1222. class Options {
  1223. public:
  1224. Options() {}
  1225. // If set to true, created PeerConnections won't enforce any SRTP
  1226. // requirement, allowing unsecured media. Should only be used for
  1227. // testing/debugging.
  1228. bool disable_encryption = false;
  1229. // Deprecated. The only effect of setting this to true is that
  1230. // CreateDataChannel will fail, which is not that useful.
  1231. bool disable_sctp_data_channels = false;
  1232. // If set to true, any platform-supported network monitoring capability
  1233. // won't be used, and instead networks will only be updated via polling.
  1234. //
  1235. // This only has an effect if a PeerConnection is created with the default
  1236. // PortAllocator implementation.
  1237. bool disable_network_monitor = false;
  1238. // Sets the network types to ignore. For instance, calling this with
  1239. // ADAPTER_TYPE_ETHERNET | ADAPTER_TYPE_LOOPBACK will ignore Ethernet and
  1240. // loopback interfaces.
  1241. int network_ignore_mask = rtc::kDefaultNetworkIgnoreMask;
  1242. // Sets the maximum supported protocol version. The highest version
  1243. // supported by both ends will be used for the connection, i.e. if one
  1244. // party supports DTLS 1.0 and the other DTLS 1.2, DTLS 1.0 will be used.
  1245. rtc::SSLProtocolVersion ssl_max_version = rtc::SSL_PROTOCOL_DTLS_12;
  1246. // Sets crypto related options, e.g. enabled cipher suites.
  1247. CryptoOptions crypto_options = CryptoOptions::NoGcm();
  1248. };
  1249. // Set the options to be used for subsequently created PeerConnections.
  1250. virtual void SetOptions(const Options& options) = 0;
  1251. // The preferred way to create a new peer connection. Simply provide the
  1252. // configuration and a PeerConnectionDependencies structure.
  1253. // TODO(benwright): Make pure virtual once downstream mock PC factory classes
  1254. // are updated.
  1255. virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
  1256. const PeerConnectionInterface::RTCConfiguration& configuration,
  1257. PeerConnectionDependencies dependencies);
  1258. // Deprecated; |allocator| and |cert_generator| may be null, in which case
  1259. // default implementations will be used.
  1260. //
  1261. // |observer| must not be null.
  1262. //
  1263. // Note that this method does not take ownership of |observer|; it's the
  1264. // responsibility of the caller to delete it. It can be safely deleted after
  1265. // Close has been called on the returned PeerConnection, which ensures no
  1266. // more observer callbacks will be invoked.
  1267. virtual rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
  1268. const PeerConnectionInterface::RTCConfiguration& configuration,
  1269. std::unique_ptr<cricket::PortAllocator> allocator,
  1270. std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
  1271. PeerConnectionObserver* observer);
  1272. // Returns the capabilities of an RTP sender of type |kind|.
  1273. // If for some reason you pass in MEDIA_TYPE_DATA, returns an empty structure.
  1274. // TODO(orphis): Make pure virtual when all subclasses implement it.
  1275. virtual RtpCapabilities GetRtpSenderCapabilities(
  1276. cricket::MediaType kind) const;
  1277. // Returns the capabilities of an RTP receiver of type |kind|.
  1278. // If for some reason you pass in MEDIA_TYPE_DATA, returns an empty structure.
  1279. // TODO(orphis): Make pure virtual when all subclasses implement it.
  1280. virtual RtpCapabilities GetRtpReceiverCapabilities(
  1281. cricket::MediaType kind) const;
  1282. virtual rtc::scoped_refptr<MediaStreamInterface> CreateLocalMediaStream(
  1283. const std::string& stream_id) = 0;
  1284. // Creates an AudioSourceInterface.
  1285. // |options| decides audio processing settings.
  1286. virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
  1287. const cricket::AudioOptions& options) = 0;
  1288. // Creates a new local VideoTrack. The same |source| can be used in several
  1289. // tracks.
  1290. virtual rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
  1291. const std::string& label,
  1292. VideoTrackSourceInterface* source) = 0;
  1293. // Creates an new AudioTrack. At the moment |source| can be null.
  1294. virtual rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
  1295. const std::string& label,
  1296. AudioSourceInterface* source) = 0;
  1297. // Starts AEC dump using existing file. Takes ownership of |file| and passes
  1298. // it on to VoiceEngine (via other objects) immediately, which will take
  1299. // the ownerhip. If the operation fails, the file will be closed.
  1300. // A maximum file size in bytes can be specified. When the file size limit is
  1301. // reached, logging is stopped automatically. If max_size_bytes is set to a
  1302. // value <= 0, no limit will be used, and logging will continue until the
  1303. // StopAecDump function is called.
  1304. // TODO(webrtc:6463): Delete default implementation when downstream mocks
  1305. // classes are updated.
  1306. virtual bool StartAecDump(FILE* file, int64_t max_size_bytes) {
  1307. return false;
  1308. }
  1309. // Stops logging the AEC dump.
  1310. virtual void StopAecDump() = 0;
  1311. protected:
  1312. // Dtor and ctor protected as objects shouldn't be created or deleted via
  1313. // this interface.
  1314. PeerConnectionFactoryInterface() {}
  1315. ~PeerConnectionFactoryInterface() override = default;
  1316. };
  1317. // CreateModularPeerConnectionFactory is implemented in the "peerconnection"
  1318. // build target, which doesn't pull in the implementations of every module
  1319. // webrtc may use.
  1320. //
  1321. // If an application knows it will only require certain modules, it can reduce
  1322. // webrtc's impact on its binary size by depending only on the "peerconnection"
  1323. // target and the modules the application requires, using
  1324. // CreateModularPeerConnectionFactory. For example, if an application
  1325. // only uses WebRTC for audio, it can pass in null pointers for the
  1326. // video-specific interfaces, and omit the corresponding modules from its
  1327. // build.
  1328. //
  1329. // If |network_thread| or |worker_thread| are null, the PeerConnectionFactory
  1330. // will create the necessary thread internally. If |signaling_thread| is null,
  1331. // the PeerConnectionFactory will use the thread on which this method is called
  1332. // as the signaling thread, wrapping it in an rtc::Thread object if needed.
  1333. RTC_EXPORT rtc::scoped_refptr<PeerConnectionFactoryInterface>
  1334. CreateModularPeerConnectionFactory(
  1335. PeerConnectionFactoryDependencies dependencies);
  1336. } // namespace webrtc
  1337. #endif // API_PEER_CONNECTION_INTERFACE_H_