blob: 357d12871992e371d3e460279d8e4c500ac79f16 [file] [log] [blame]
Seth Hampson845e8782018-03-02 19:34:101
henrike@webrtc.org28e20752013-07-10 00:45:362/*
kjellanderb24317b2016-02-10 15:54:433 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:364 *
kjellanderb24317b2016-02-10 15:54:435 * 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:3610 */
jlmiller@webrtc.org5f93d0a2015-01-20 21:36:1311
Steve Anton10542f22019-01-11 17:11:0012#ifndef PC_PEER_CONNECTION_FACTORY_H_
13#define PC_PEER_CONNECTION_FACTORY_H_
henrike@webrtc.org28e20752013-07-10 00:45:3614
Harald Alvestrandffd5dc72020-10-20 15:35:3115#include <stdint.h>
16#include <stdio.h>
Vojin Ilic504fc192021-05-31 12:02:2817
kwibergd1fe2812016-04-27 13:47:2918#include <memory>
henrike@webrtc.org28e20752013-07-10 00:45:3619#include <string>
20
Harald Alvestrandffd5dc72020-10-20 15:35:3121#include "absl/strings/string_view.h"
22#include "api/audio_options.h"
23#include "api/fec_controller.h"
Jonas Orelande62c2f22022-03-29 09:04:4824#include "api/field_trials_view.h"
Steve Anton10542f22019-01-11 17:11:0025#include "api/media_stream_interface.h"
Harald Alvestrandffd5dc72020-10-20 15:35:3126#include "api/media_types.h"
Harald Alvestrandc24a2182022-02-23 13:44:5927#include "api/metronome/metronome.h"
Harald Alvestrandffd5dc72020-10-20 15:35:3128#include "api/neteq/neteq_factory.h"
29#include "api/network_state_predictor.h"
Steve Anton10542f22019-01-11 17:11:0030#include "api/peer_connection_interface.h"
Harald Alvestranda3dd7722020-11-27 08:05:4231#include "api/rtc_error.h"
Harald Alvestrandffd5dc72020-10-20 15:35:3132#include "api/rtc_event_log/rtc_event_log_factory_interface.h"
33#include "api/rtp_parameters.h"
Mirko Bonadeid9708072019-01-25 19:26:4834#include "api/scoped_refptr.h"
Artem Titovd15a5752021-02-10 13:31:2435#include "api/sequence_checker.h"
Harald Alvestrandffd5dc72020-10-20 15:35:3136#include "api/transport/network_control.h"
37#include "api/transport/sctp_transport_factory_interface.h"
Harald Alvestrandffd5dc72020-10-20 15:35:3138#include "call/call.h"
Vojin Ilic504fc192021-05-31 12:02:2839#include "call/rtp_transport_controller_send_factory_interface.h"
Harald Alvestrandffd5dc72020-10-20 15:35:3140#include "p2p/base/port_allocator.h"
Harald Alvestranda39689c2020-10-15 08:34:3141#include "pc/connection_context.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0842#include "rtc_base/checks.h"
Steve Anton10542f22019-01-11 17:11:0043#include "rtc_base/rtc_certificate_generator.h"
Mirko Bonadei92ea95e2017-09-15 04:47:3144#include "rtc_base/thread.h"
Harald Alvestrand5761e7b2021-01-29 14:45:0845#include "rtc_base/thread_annotations.h"
henrike@webrtc.org28e20752013-07-10 00:45:3646
deadbeef41b07982015-12-01 23:01:2447namespace rtc {
48class BasicNetworkManager;
49class BasicPacketSocketFactory;
Yves Gerey665174f2018-06-19 13:03:0550} // namespace rtc
deadbeef41b07982015-12-01 23:01:2451
henrike@webrtc.org28e20752013-07-10 00:45:3652namespace webrtc {
53
perkj@webrtc.org81134d02015-01-12 08:30:1654class PeerConnectionFactory : public PeerConnectionFactoryInterface {
henrike@webrtc.org28e20752013-07-10 00:45:3655 public:
Harald Alvestrandffd5dc72020-10-20 15:35:3156 // 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
jbauchcb560652016-08-04 12:20:3264 void SetOptions(const Options& options) override;
wu@webrtc.org97077a32013-10-25 21:18:3365
Harald Alvestranda3dd7722020-11-27 08:05:4266 RTCErrorOr<rtc::scoped_refptr<PeerConnectionInterface>>
67 CreatePeerConnectionOrError(
68 const PeerConnectionInterface::RTCConfiguration& configuration,
69 PeerConnectionDependencies dependencies) override;
70
Florent Castelli72b751a2018-06-28 12:09:3371 RtpCapabilities GetRtpSenderCapabilities(
72 cricket::MediaType kind) const override;
73
74 RtpCapabilities GetRtpReceiverCapabilities(
75 cricket::MediaType kind) const override;
76
Seth Hampson845e8782018-03-02 19:34:1077 rtc::scoped_refptr<MediaStreamInterface> CreateLocalMediaStream(
78 const std::string& stream_id) override;
henrike@webrtc.org28e20752013-07-10 00:45:3679
Steve Anton36b29d12017-10-30 16:57:4280 rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
htaa2a49d92016-03-04 10:51:3981 const cricket::AudioOptions& options) override;
henrike@webrtc.org28e20752013-07-10 00:45:3682
perkja3ede6c2016-03-08 00:27:4883 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
Harald Alvestrand041ecb82023-03-20 14:13:4284 rtc::scoped_refptr<VideoTrackSourceInterface> video_source,
85 absl::string_view id) override;
henrike@webrtc.org28e20752013-07-10 00:45:3686
Yves Gerey665174f2018-06-19 13:03:0587 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
88 const std::string& id,
89 AudioSourceInterface* audio_source) override;
henrike@webrtc.org28e20752013-07-10 00:45:3690
Niels Möllere8e4dc42019-06-11 12:04:1691 bool StartAecDump(FILE* file, int64_t max_size_bytes) override;
ivoc797ef122015-10-22 10:25:4192 void StopAecDump() override;
wu@webrtc.orga9890802013-12-13 00:21:0393
Per Kjellander2bca0082020-08-28 07:15:1594 SctpTransportFactoryInterface* sctp_transport_factory() {
Harald Alvestranda39689c2020-10-15 08:34:3195 return context_->sctp_transport_factory();
Per Kjellander2bca0082020-08-28 07:15:1596 }
Steve Antonda6c0952017-10-23 18:41:5497
Harald Alvestranda39689c2020-10-15 08:34:3198 rtc::Thread* signaling_thread() const {
Karl Wiberg4ae63472019-02-21 23:57:0699 // This method can be called on a different thread when the factory is
100 // created in CreatePeerConnectionFactory().
Harald Alvestranda39689c2020-10-15 08:34:31101 return context_->signaling_thread();
Karl Wiberg4ae63472019-02-21 23:57:06102 }
Karl Wiberg4ae63472019-02-21 23:57:06103
Tomas Gunnarsson95d2f472021-04-01 17:14:54104 rtc::Thread* worker_thread() const { return context_->worker_thread(); }
105
Harald Alvestrand4da4a872020-11-04 10:34:21106 const Options& options() const {
107 RTC_DCHECK_RUN_ON(signaling_thread());
108 return options_;
109 }
henrike@webrtc.org28e20752013-07-10 00:45:36110
Jonas Oreland6c7f9842022-04-19 15:24:10111 const FieldTrialsView& field_trials() const {
Danil Chapovalov539bca92023-12-06 15:08:02112 return context_->env().field_trials();
Jonas Oreland6c7f9842022-04-19 15:24:10113 }
Erik Språngceb44952020-09-22 09:36:35114
Harald Alvestrand35f4b4c2022-05-16 10:36:43115 cricket::MediaEngineInterface* media_engine() const;
116
henrike@webrtc.org28e20752013-07-10 00:45:36117 protected:
Harald Alvestrandffd5dc72020-10-20 15:35:31118 // 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 Wright5234a492018-05-29 22:04:32124 explicit PeerConnectionFactory(
125 PeerConnectionFactoryDependencies dependencies);
126
henrike@webrtc.org28e20752013-07-10 00:45:36127 virtual ~PeerConnectionFactory();
128
henrike@webrtc.org28e20752013-07-10 00:45:36129 private:
Harald Alvestrandffd5dc72020-10-20 15:35:31130 rtc::Thread* network_thread() const { return context_->network_thread(); }
131
Erik Språng662678d2019-11-15 16:18:52132 bool IsTrialEnabled(absl::string_view key) const;
Harald Alvestrand9e334b72022-05-04 13:38:31133
Henrik Boströmcf2856b2022-11-15 08:23:19134 std::unique_ptr<Call> CreateCall_w(
Danil Chapovalov3bdb49b2023-11-30 07:59:39135 const Environment& env,
Tony Herre5079e8a2024-07-29 05:54:20136 const PeerConnectionInterface::RTCConfiguration& configuration,
137 std::unique_ptr<NetworkControllerFactoryInterface>
138 network_controller_factory);
zhihuang38ede132017-06-15 19:52:32139
Harald Alvestranda39689c2020-10-15 08:34:31140 rtc::scoped_refptr<ConnectionContext> context_;
Harald Alvestrand4da4a872020-11-04 10:34:21141 PeerConnectionFactoryInterface::Options options_
142 RTC_GUARDED_BY(signaling_thread());
zhihuang38ede132017-06-15 19:52:32143 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory_;
Ying Wang0dd1b0a2018-02-20 11:50:27144 std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory_;
Ying Wang0810a7c2019-04-10 11:48:24145 std::unique_ptr<NetworkStatePredictorFactoryInterface>
146 network_state_predictor_factory_;
Sebastian Janssondfce03a2018-05-18 16:05:10147 std::unique_ptr<NetworkControllerFactoryInterface>
148 injected_network_controller_factory_;
Ivo Creusenc3d1f9b2019-11-01 10:47:51149 std::unique_ptr<NetEqFactory> neteq_factory_;
Vojin Ilic504fc192021-05-31 12:02:28150 const std::unique_ptr<RtpTransportControllerSendFactoryInterface>
151 transport_controller_send_factory_;
Henrik Boströmf887e072023-12-05 10:27:45152 std::unique_ptr<Metronome> decode_metronome_ RTC_GUARDED_BY(worker_thread());
Zhaoliang Maf089d7e2024-01-08 02:44:15153 std::unique_ptr<Metronome> encode_metronome_ RTC_GUARDED_BY(worker_thread());
henrike@webrtc.org28e20752013-07-10 00:45:36154};
155
156} // namespace webrtc
157
Steve Anton10542f22019-01-11 17:11:00158#endif // PC_PEER_CONNECTION_FACTORY_H_