blob: 82fa50859f72305bcfc007f26e33dbedefc1ac3a [file] [log] [blame]
Seth Hampson845e8782018-03-02 11:34:10 -08001
henrike@webrtc.org28e20752013-07-10 00:45:36 +00002/*
kjellanderb24317b2016-02-10 07:54:43 -08003 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00004 *
kjellanderb24317b2016-02-10 07:54:43 -08005 * Use of this source code is governed by a BSD-style license
6 * that can be found in the LICENSE file in the root of the source
7 * tree. An additional intellectual property rights grant can be found
8 * in the file PATENTS. All contributing project authors may
9 * be found in the AUTHORS file in the root of the source tree.
henrike@webrtc.org28e20752013-07-10 00:45:36 +000010 */
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:13 +000011
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020012#ifndef PC_PEERCONNECTIONFACTORY_H_
13#define PC_PEERCONNECTIONFACTORY_H_
henrike@webrtc.org28e20752013-07-10 00:45:36 +000014
kwibergd1fe2812016-04-27 06:47:29 -070015#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:36 +000016#include <string>
17
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "api/mediastreaminterface.h"
19#include "api/peerconnectioninterface.h"
Steve Antonda6c0952017-10-23 11:41:54 -070020#include "media/sctp/sctptransportinternal.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "pc/channelmanager.h"
22#include "rtc_base/rtccertificategenerator.h"
23#include "rtc_base/scoped_ref_ptr.h"
24#include "rtc_base/thread.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000025
deadbeef41b07982015-12-01 15:01:24 -080026namespace rtc {
27class BasicNetworkManager;
28class BasicPacketSocketFactory;
Yves Gerey665174f2018-06-19 15:03:05 +020029} // namespace rtc
deadbeef41b07982015-12-01 15:01:24 -080030
henrike@webrtc.org28e20752013-07-10 00:45:36 +000031namespace webrtc {
32
skvlad11a9cbf2016-10-07 11:53:05 -070033class RtcEventLog;
34
perkj@webrtc.org81134d02015-01-12 08:30:16 +000035class PeerConnectionFactory : public PeerConnectionFactoryInterface {
henrike@webrtc.org28e20752013-07-10 00:45:36 +000036 public:
deadbeef112b2e92017-02-10 20:13:37 -080037 // Use the overloads of CreateVideoSource that take raw VideoCapturer
38 // pointers from PeerConnectionFactoryInterface.
39 // TODO(deadbeef): Remove this using statement once those overloads are
40 // removed.
41 using PeerConnectionFactoryInterface::CreateVideoSource;
42
jbauchcb560652016-08-04 05:20:32 -070043 void SetOptions(const Options& options) override;
wu@webrtc.org97077a32013-10-25 21:18:33 +000044
htaa2a49d92016-03-04 02:51:39 -080045 // Deprecated, use version without constraints.
deadbeef41b07982015-12-01 15:01:24 -080046 rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
47 const PeerConnectionInterface::RTCConfiguration& configuration,
48 const MediaConstraintsInterface* constraints,
kwibergd1fe2812016-04-27 06:47:29 -070049 std::unique_ptr<cricket::PortAllocator> allocator,
Henrik Boströmd03c23b2016-06-01 11:44:18 +020050 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
deadbeef41b07982015-12-01 15:01:24 -080051 PeerConnectionObserver* observer) override;
52
Steve Anton36b29d12017-10-30 09:57:42 -070053 rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
htaa2a49d92016-03-04 02:51:39 -080054 const PeerConnectionInterface::RTCConfiguration& configuration,
kwibergd1fe2812016-04-27 06:47:29 -070055 std::unique_ptr<cricket::PortAllocator> allocator,
Henrik Boströmd03c23b2016-06-01 11:44:18 +020056 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
htaa2a49d92016-03-04 02:51:39 -080057 PeerConnectionObserver* observer) override;
58
Benjamin Wright6f7e6d62018-05-02 13:46:31 -070059 rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
60 const PeerConnectionInterface::RTCConfiguration& configuration,
61 PeerConnectionDependencies dependencies) override;
62
henrike@webrtc.org28e20752013-07-10 00:45:36 +000063 bool Initialize();
64
Florent Castelli72b751a2018-06-28 14:09:33 +020065 RtpCapabilities GetRtpSenderCapabilities(
66 cricket::MediaType kind) const override;
67
68 RtpCapabilities GetRtpReceiverCapabilities(
69 cricket::MediaType kind) const override;
70
Seth Hampson845e8782018-03-02 11:34:10 -080071 rtc::scoped_refptr<MediaStreamInterface> CreateLocalMediaStream(
72 const std::string& stream_id) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000073
Steve Anton36b29d12017-10-30 09:57:42 -070074 rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
htaa2a49d92016-03-04 02:51:39 -080075 const cricket::AudioOptions& options) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076
Steve Anton36b29d12017-10-30 09:57:42 -070077 rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
deadbeef112b2e92017-02-10 20:13:37 -080078 std::unique_ptr<cricket::VideoCapturer> capturer) override;
htaa2a49d92016-03-04 02:51:39 -080079 // This version supports filtering on width, height and frame rate.
80 // For the "constraints=null" case, use the version without constraints.
81 // TODO(hta): Design a version without MediaConstraintsInterface.
82 // https://bugs.chromium.org/p/webrtc/issues/detail?id=5617
perkja3ede6c2016-03-08 01:27:48 +010083 rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
deadbeef112b2e92017-02-10 20:13:37 -080084 std::unique_ptr<cricket::VideoCapturer> capturer,
perkj@webrtc.org81134d02015-01-12 08:30:16 +000085 const MediaConstraintsInterface* constraints) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000086
perkja3ede6c2016-03-08 01:27:48 +010087 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
88 const std::string& id,
89 VideoTrackSourceInterface* video_source) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000090
Yves Gerey665174f2018-06-19 15:03:05 +020091 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
92 const std::string& id,
93 AudioSourceInterface* audio_source) override;
henrike@webrtc.org28e20752013-07-10 00:45:36 +000094
ivocd66b44d2016-01-15 03:06:36 -080095 bool StartAecDump(rtc::PlatformFile file, int64_t max_size_bytes) override;
ivoc797ef122015-10-22 03:25:41 -070096 void StopAecDump() override;
wu@webrtc.orga9890802013-12-13 00:21:03 +000097
Steve Antonda6c0952017-10-23 11:41:54 -070098 virtual std::unique_ptr<cricket::SctpTransportInternalFactory>
99 CreateSctpTransportInternalFactory();
100
nisseeaabdf62017-05-05 02:23:02 -0700101 virtual cricket::ChannelManager* channel_manager();
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000102 virtual rtc::Thread* signaling_thread();
103 virtual rtc::Thread* worker_thread();
danilchape9021a32016-05-17 01:52:02 -0700104 virtual rtc::Thread* network_thread();
wu@webrtc.org97077a32013-10-25 21:18:33 +0000105 const Options& options() const { return options_; }
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000106
107 protected:
kwiberg1e4e8cb2017-01-31 01:48:08 -0800108 PeerConnectionFactory(
danilchape9021a32016-05-17 01:52:02 -0700109 rtc::Thread* network_thread,
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000110 rtc::Thread* worker_thread,
111 rtc::Thread* signaling_thread,
zhihuang38ede132017-06-15 12:52:32 -0700112 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
113 std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
114 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory);
Ying Wang0dd1b0a2018-02-20 12:50:27 +0100115 PeerConnectionFactory(
116 rtc::Thread* network_thread,
117 rtc::Thread* worker_thread,
118 rtc::Thread* signaling_thread,
119 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
120 std::unique_ptr<webrtc::CallFactoryInterface> call_factory,
121 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory,
Sebastian Janssondfce03a2018-05-18 18:05:10 +0200122 std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory,
123 std::unique_ptr<NetworkControllerFactoryInterface>
124 network_controller_factory);
Benjamin Wright5234a492018-05-29 15:04:32 -0700125 // Use this implementation for all future use. This structure allows simple
126 // management of all new dependencies being added to the
127 // PeerConnectionFactory.
128 explicit PeerConnectionFactory(
129 PeerConnectionFactoryDependencies dependencies);
130
Harald Alvestrand19793842018-06-25 12:03:50 +0200131 // Hook to let testing framework insert actions between
132 // "new RTCPeerConnection" and "pc.Initialize"
133 virtual void ActionsBeforeInitializeForTesting(PeerConnectionInterface*) {}
134
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000135 virtual ~PeerConnectionFactory();
136
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000137 private:
eladalon248fd4f2017-09-06 05:18:15 -0700138 std::unique_ptr<RtcEventLog> CreateRtcEventLog_w();
zhihuang38ede132017-06-15 12:52:32 -0700139 std::unique_ptr<Call> CreateCall_w(RtcEventLog* event_log);
140
perkj@webrtc.org81134d02015-01-12 08:30:16 +0000141 bool wraps_current_thread_;
danilchape9021a32016-05-17 01:52:02 -0700142 rtc::Thread* network_thread_;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000143 rtc::Thread* worker_thread_;
danilchape9021a32016-05-17 01:52:02 -0700144 rtc::Thread* signaling_thread_;
zhihuang38ede132017-06-15 12:52:32 -0700145 std::unique_ptr<rtc::Thread> owned_network_thread_;
146 std::unique_ptr<rtc::Thread> owned_worker_thread_;
wu@webrtc.org97077a32013-10-25 21:18:33 +0000147 Options options_;
kwibergd1fe2812016-04-27 06:47:29 -0700148 std::unique_ptr<cricket::ChannelManager> channel_manager_;
kwibergd1fe2812016-04-27 06:47:29 -0700149 std::unique_ptr<rtc::BasicNetworkManager> default_network_manager_;
150 std::unique_ptr<rtc::BasicPacketSocketFactory> default_socket_factory_;
zhihuang38ede132017-06-15 12:52:32 -0700151 std::unique_ptr<cricket::MediaEngineInterface> media_engine_;
152 std::unique_ptr<webrtc::CallFactoryInterface> call_factory_;
153 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory_;
Ying Wang0dd1b0a2018-02-20 12:50:27 +0100154 std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory_;
Sebastian Janssondfce03a2018-05-18 18:05:10 +0200155 std::unique_ptr<NetworkControllerFactoryInterface>
156 injected_network_controller_factory_;
157 std::unique_ptr<NetworkControllerFactoryInterface>
158 bbr_network_controller_factory_;
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000159};
160
161} // namespace webrtc
162
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200163#endif // PC_PEERCONNECTIONFACTORY_H_