Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 1 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 2 | /* |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 3 | * Copyright 2011 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 4 | * |
kjellander | b24317b | 2016-02-10 15:54:43 | [diff] [blame] | 5 | * 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.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 10 | */ |
jlmiller@webrtc.org | 5f93d0a | 2015-01-20 21:36:13 | [diff] [blame] | 11 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 12 | #ifndef PC_PEER_CONNECTION_FACTORY_H_ |
| 13 | #define PC_PEER_CONNECTION_FACTORY_H_ |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 14 | |
Harald Alvestrand | ffd5dc7 | 2020-10-20 15:35:31 | [diff] [blame] | 15 | #include <stdint.h> |
| 16 | #include <stdio.h> |
Vojin Ilic | 504fc19 | 2021-05-31 12:02:28 | [diff] [blame] | 17 | |
kwiberg | d1fe281 | 2016-04-27 13:47:29 | [diff] [blame] | 18 | #include <memory> |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 19 | #include <string> |
| 20 | |
Harald Alvestrand | ffd5dc7 | 2020-10-20 15:35:31 | [diff] [blame] | 21 | #include "absl/strings/string_view.h" |
| 22 | #include "api/audio_options.h" |
| 23 | #include "api/fec_controller.h" |
Jonas Oreland | e62c2f2 | 2022-03-29 09:04:48 | [diff] [blame] | 24 | #include "api/field_trials_view.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 25 | #include "api/media_stream_interface.h" |
Harald Alvestrand | ffd5dc7 | 2020-10-20 15:35:31 | [diff] [blame] | 26 | #include "api/media_types.h" |
Harald Alvestrand | c24a218 | 2022-02-23 13:44:59 | [diff] [blame] | 27 | #include "api/metronome/metronome.h" |
Harald Alvestrand | ffd5dc7 | 2020-10-20 15:35:31 | [diff] [blame] | 28 | #include "api/neteq/neteq_factory.h" |
| 29 | #include "api/network_state_predictor.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 30 | #include "api/peer_connection_interface.h" |
Harald Alvestrand | a3dd772 | 2020-11-27 08:05:42 | [diff] [blame] | 31 | #include "api/rtc_error.h" |
Harald Alvestrand | ffd5dc7 | 2020-10-20 15:35:31 | [diff] [blame] | 32 | #include "api/rtc_event_log/rtc_event_log_factory_interface.h" |
| 33 | #include "api/rtp_parameters.h" |
Mirko Bonadei | d970807 | 2019-01-25 19:26:48 | [diff] [blame] | 34 | #include "api/scoped_refptr.h" |
Artem Titov | d15a575 | 2021-02-10 13:31:24 | [diff] [blame] | 35 | #include "api/sequence_checker.h" |
Harald Alvestrand | ffd5dc7 | 2020-10-20 15:35:31 | [diff] [blame] | 36 | #include "api/transport/network_control.h" |
| 37 | #include "api/transport/sctp_transport_factory_interface.h" |
Harald Alvestrand | ffd5dc7 | 2020-10-20 15:35:31 | [diff] [blame] | 38 | #include "call/call.h" |
Vojin Ilic | 504fc19 | 2021-05-31 12:02:28 | [diff] [blame] | 39 | #include "call/rtp_transport_controller_send_factory_interface.h" |
Harald Alvestrand | ffd5dc7 | 2020-10-20 15:35:31 | [diff] [blame] | 40 | #include "p2p/base/port_allocator.h" |
Harald Alvestrand | a39689c | 2020-10-15 08:34:31 | [diff] [blame] | 41 | #include "pc/connection_context.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 | [diff] [blame] | 42 | #include "rtc_base/checks.h" |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 43 | #include "rtc_base/rtc_certificate_generator.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 04:47:31 | [diff] [blame] | 44 | #include "rtc_base/thread.h" |
Harald Alvestrand | 5761e7b | 2021-01-29 14:45:08 | [diff] [blame] | 45 | #include "rtc_base/thread_annotations.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 46 | |
deadbeef | 41b0798 | 2015-12-01 23:01:24 | [diff] [blame] | 47 | namespace rtc { |
| 48 | class BasicNetworkManager; |
| 49 | class BasicPacketSocketFactory; |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 50 | } // namespace rtc |
deadbeef | 41b0798 | 2015-12-01 23:01:24 | [diff] [blame] | 51 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 52 | namespace webrtc { |
| 53 | |
perkj@webrtc.org | 81134d0 | 2015-01-12 08:30:16 | [diff] [blame] | 54 | class PeerConnectionFactory : public PeerConnectionFactoryInterface { |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 55 | public: |
Harald Alvestrand | ffd5dc7 | 2020-10-20 15:35:31 | [diff] [blame] | 56 | // Creates a PeerConnectionFactory. It returns nullptr on initialization |
| 57 | // error. |
| 58 | // |
| 59 | // The Dependencies structure allows simple management of all new |
| 60 | // dependencies being added to the PeerConnectionFactory. |
| 61 | static rtc::scoped_refptr<PeerConnectionFactory> Create( |
| 62 | PeerConnectionFactoryDependencies dependencies); |
| 63 | |
jbauch | cb56065 | 2016-08-04 12:20:32 | [diff] [blame] | 64 | void SetOptions(const Options& options) override; |
wu@webrtc.org | 97077a3 | 2013-10-25 21:18:33 | [diff] [blame] | 65 | |
Harald Alvestrand | a3dd772 | 2020-11-27 08:05:42 | [diff] [blame] | 66 | RTCErrorOr<rtc::scoped_refptr<PeerConnectionInterface>> |
| 67 | CreatePeerConnectionOrError( |
| 68 | const PeerConnectionInterface::RTCConfiguration& configuration, |
| 69 | PeerConnectionDependencies dependencies) override; |
| 70 | |
Florent Castelli | 72b751a | 2018-06-28 12:09:33 | [diff] [blame] | 71 | RtpCapabilities GetRtpSenderCapabilities( |
| 72 | cricket::MediaType kind) const override; |
| 73 | |
| 74 | RtpCapabilities GetRtpReceiverCapabilities( |
| 75 | cricket::MediaType kind) const override; |
| 76 | |
Seth Hampson | 845e878 | 2018-03-02 19:34:10 | [diff] [blame] | 77 | rtc::scoped_refptr<MediaStreamInterface> CreateLocalMediaStream( |
| 78 | const std::string& stream_id) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 79 | |
Steve Anton | 36b29d1 | 2017-10-30 16:57:42 | [diff] [blame] | 80 | rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource( |
hta | a2a49d9 | 2016-03-04 10:51:39 | [diff] [blame] | 81 | const cricket::AudioOptions& options) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 82 | |
perkj | a3ede6c | 2016-03-08 00:27:48 | [diff] [blame] | 83 | rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack( |
Harald Alvestrand | 041ecb8 | 2023-03-20 14:13:42 | [diff] [blame] | 84 | rtc::scoped_refptr<VideoTrackSourceInterface> video_source, |
| 85 | absl::string_view id) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 86 | |
Yves Gerey | 665174f | 2018-06-19 13:03:05 | [diff] [blame] | 87 | rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack( |
| 88 | const std::string& id, |
| 89 | AudioSourceInterface* audio_source) override; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 90 | |
Niels Möller | e8e4dc4 | 2019-06-11 12:04:16 | [diff] [blame] | 91 | bool StartAecDump(FILE* file, int64_t max_size_bytes) override; |
ivoc | 797ef12 | 2015-10-22 10:25:41 | [diff] [blame] | 92 | void StopAecDump() override; |
wu@webrtc.org | a989080 | 2013-12-13 00:21:03 | [diff] [blame] | 93 | |
Per Kjellander | 2bca008 | 2020-08-28 07:15:15 | [diff] [blame] | 94 | SctpTransportFactoryInterface* sctp_transport_factory() { |
Harald Alvestrand | a39689c | 2020-10-15 08:34:31 | [diff] [blame] | 95 | return context_->sctp_transport_factory(); |
Per Kjellander | 2bca008 | 2020-08-28 07:15:15 | [diff] [blame] | 96 | } |
Steve Anton | da6c095 | 2017-10-23 18:41:54 | [diff] [blame] | 97 | |
Harald Alvestrand | a39689c | 2020-10-15 08:34:31 | [diff] [blame] | 98 | rtc::Thread* signaling_thread() const { |
Karl Wiberg | 4ae6347 | 2019-02-21 23:57:06 | [diff] [blame] | 99 | // This method can be called on a different thread when the factory is |
| 100 | // created in CreatePeerConnectionFactory(). |
Harald Alvestrand | a39689c | 2020-10-15 08:34:31 | [diff] [blame] | 101 | return context_->signaling_thread(); |
Karl Wiberg | 4ae6347 | 2019-02-21 23:57:06 | [diff] [blame] | 102 | } |
Karl Wiberg | 4ae6347 | 2019-02-21 23:57:06 | [diff] [blame] | 103 | |
Tomas Gunnarsson | 95d2f47 | 2021-04-01 17:14:54 | [diff] [blame] | 104 | rtc::Thread* worker_thread() const { return context_->worker_thread(); } |
| 105 | |
Harald Alvestrand | 4da4a87 | 2020-11-04 10:34:21 | [diff] [blame] | 106 | const Options& options() const { |
| 107 | RTC_DCHECK_RUN_ON(signaling_thread()); |
| 108 | return options_; |
| 109 | } |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 110 | |
Jonas Oreland | 6c7f984 | 2022-04-19 15:24:10 | [diff] [blame] | 111 | const FieldTrialsView& field_trials() const { |
Danil Chapovalov | 539bca9 | 2023-12-06 15:08:02 | [diff] [blame] | 112 | return context_->env().field_trials(); |
Jonas Oreland | 6c7f984 | 2022-04-19 15:24:10 | [diff] [blame] | 113 | } |
Erik Språng | ceb4495 | 2020-09-22 09:36:35 | [diff] [blame] | 114 | |
Harald Alvestrand | 35f4b4c | 2022-05-16 10:36:43 | [diff] [blame] | 115 | cricket::MediaEngineInterface* media_engine() const; |
| 116 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 117 | protected: |
Harald Alvestrand | ffd5dc7 | 2020-10-20 15:35:31 | [diff] [blame] | 118 | // Constructor used by the static Create() method. Modifies the dependencies. |
| 119 | PeerConnectionFactory(rtc::scoped_refptr<ConnectionContext> context, |
| 120 | PeerConnectionFactoryDependencies* dependencies); |
| 121 | |
| 122 | // Constructor for use in testing. Ignores the possibility of initialization |
| 123 | // failure. The dependencies are passed in by std::move(). |
Benjamin Wright | 5234a49 | 2018-05-29 22:04:32 | [diff] [blame] | 124 | explicit PeerConnectionFactory( |
| 125 | PeerConnectionFactoryDependencies dependencies); |
| 126 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 127 | virtual ~PeerConnectionFactory(); |
| 128 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 129 | private: |
Harald Alvestrand | ffd5dc7 | 2020-10-20 15:35:31 | [diff] [blame] | 130 | rtc::Thread* network_thread() const { return context_->network_thread(); } |
| 131 | |
Erik Språng | 662678d | 2019-11-15 16:18:52 | [diff] [blame] | 132 | bool IsTrialEnabled(absl::string_view key) const; |
Harald Alvestrand | 9e334b7 | 2022-05-04 13:38:31 | [diff] [blame] | 133 | |
Henrik Boström | cf2856b | 2022-11-15 08:23:19 | [diff] [blame] | 134 | std::unique_ptr<Call> CreateCall_w( |
Danil Chapovalov | 3bdb49b | 2023-11-30 07:59:39 | [diff] [blame] | 135 | const Environment& env, |
Tony Herre | 5079e8a | 2024-07-29 05:54:20 | [diff] [blame] | 136 | const PeerConnectionInterface::RTCConfiguration& configuration, |
| 137 | std::unique_ptr<NetworkControllerFactoryInterface> |
| 138 | network_controller_factory); |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 139 | |
Harald Alvestrand | a39689c | 2020-10-15 08:34:31 | [diff] [blame] | 140 | rtc::scoped_refptr<ConnectionContext> context_; |
Harald Alvestrand | 4da4a87 | 2020-11-04 10:34:21 | [diff] [blame] | 141 | PeerConnectionFactoryInterface::Options options_ |
| 142 | RTC_GUARDED_BY(signaling_thread()); |
zhihuang | 38ede13 | 2017-06-15 19:52:32 | [diff] [blame] | 143 | std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory_; |
Ying Wang | 0dd1b0a | 2018-02-20 11:50:27 | [diff] [blame] | 144 | std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory_; |
Ying Wang | 0810a7c | 2019-04-10 11:48:24 | [diff] [blame] | 145 | std::unique_ptr<NetworkStatePredictorFactoryInterface> |
| 146 | network_state_predictor_factory_; |
Sebastian Jansson | dfce03a | 2018-05-18 16:05:10 | [diff] [blame] | 147 | std::unique_ptr<NetworkControllerFactoryInterface> |
| 148 | injected_network_controller_factory_; |
Ivo Creusen | c3d1f9b | 2019-11-01 10:47:51 | [diff] [blame] | 149 | std::unique_ptr<NetEqFactory> neteq_factory_; |
Vojin Ilic | 504fc19 | 2021-05-31 12:02:28 | [diff] [blame] | 150 | const std::unique_ptr<RtpTransportControllerSendFactoryInterface> |
| 151 | transport_controller_send_factory_; |
Henrik Boström | f887e07 | 2023-12-05 10:27:45 | [diff] [blame] | 152 | std::unique_ptr<Metronome> decode_metronome_ RTC_GUARDED_BY(worker_thread()); |
Zhaoliang Ma | f089d7e | 2024-01-08 02:44:15 | [diff] [blame] | 153 | std::unique_ptr<Metronome> encode_metronome_ RTC_GUARDED_BY(worker_thread()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 | [diff] [blame] | 154 | }; |
| 155 | |
| 156 | } // namespace webrtc |
| 157 | |
Steve Anton | 10542f2 | 2019-01-11 17:11:00 | [diff] [blame] | 158 | #endif // PC_PEER_CONNECTION_FACTORY_H_ |