1*d9f75844SAndroid Build Coastguard Worker 2*d9f75844SAndroid Build Coastguard Worker /* 3*d9f75844SAndroid Build Coastguard Worker * Copyright 2011 The WebRTC project authors. All Rights Reserved. 4*d9f75844SAndroid Build Coastguard Worker * 5*d9f75844SAndroid Build Coastguard Worker * Use of this source code is governed by a BSD-style license 6*d9f75844SAndroid Build Coastguard Worker * that can be found in the LICENSE file in the root of the source 7*d9f75844SAndroid Build Coastguard Worker * tree. An additional intellectual property rights grant can be found 8*d9f75844SAndroid Build Coastguard Worker * in the file PATENTS. All contributing project authors may 9*d9f75844SAndroid Build Coastguard Worker * be found in the AUTHORS file in the root of the source tree. 10*d9f75844SAndroid Build Coastguard Worker */ 11*d9f75844SAndroid Build Coastguard Worker 12*d9f75844SAndroid Build Coastguard Worker #ifndef PC_PEER_CONNECTION_FACTORY_H_ 13*d9f75844SAndroid Build Coastguard Worker #define PC_PEER_CONNECTION_FACTORY_H_ 14*d9f75844SAndroid Build Coastguard Worker 15*d9f75844SAndroid Build Coastguard Worker #include <stdint.h> 16*d9f75844SAndroid Build Coastguard Worker #include <stdio.h> 17*d9f75844SAndroid Build Coastguard Worker 18*d9f75844SAndroid Build Coastguard Worker #include <memory> 19*d9f75844SAndroid Build Coastguard Worker #include <string> 20*d9f75844SAndroid Build Coastguard Worker 21*d9f75844SAndroid Build Coastguard Worker #include "absl/strings/string_view.h" 22*d9f75844SAndroid Build Coastguard Worker #include "api/audio_options.h" 23*d9f75844SAndroid Build Coastguard Worker #include "api/fec_controller.h" 24*d9f75844SAndroid Build Coastguard Worker #include "api/field_trials_view.h" 25*d9f75844SAndroid Build Coastguard Worker #include "api/media_stream_interface.h" 26*d9f75844SAndroid Build Coastguard Worker #include "api/media_types.h" 27*d9f75844SAndroid Build Coastguard Worker #include "api/metronome/metronome.h" 28*d9f75844SAndroid Build Coastguard Worker #include "api/neteq/neteq_factory.h" 29*d9f75844SAndroid Build Coastguard Worker #include "api/network_state_predictor.h" 30*d9f75844SAndroid Build Coastguard Worker #include "api/peer_connection_interface.h" 31*d9f75844SAndroid Build Coastguard Worker #include "api/rtc_error.h" 32*d9f75844SAndroid Build Coastguard Worker #include "api/rtc_event_log/rtc_event_log.h" 33*d9f75844SAndroid Build Coastguard Worker #include "api/rtc_event_log/rtc_event_log_factory_interface.h" 34*d9f75844SAndroid Build Coastguard Worker #include "api/rtp_parameters.h" 35*d9f75844SAndroid Build Coastguard Worker #include "api/scoped_refptr.h" 36*d9f75844SAndroid Build Coastguard Worker #include "api/sequence_checker.h" 37*d9f75844SAndroid Build Coastguard Worker #include "api/task_queue/task_queue_factory.h" 38*d9f75844SAndroid Build Coastguard Worker #include "api/transport/network_control.h" 39*d9f75844SAndroid Build Coastguard Worker #include "api/transport/sctp_transport_factory_interface.h" 40*d9f75844SAndroid Build Coastguard Worker #include "call/call.h" 41*d9f75844SAndroid Build Coastguard Worker #include "call/rtp_transport_controller_send_factory_interface.h" 42*d9f75844SAndroid Build Coastguard Worker #include "p2p/base/port_allocator.h" 43*d9f75844SAndroid Build Coastguard Worker #include "pc/connection_context.h" 44*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/checks.h" 45*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/rtc_certificate_generator.h" 46*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/thread.h" 47*d9f75844SAndroid Build Coastguard Worker #include "rtc_base/thread_annotations.h" 48*d9f75844SAndroid Build Coastguard Worker 49*d9f75844SAndroid Build Coastguard Worker namespace rtc { 50*d9f75844SAndroid Build Coastguard Worker class BasicNetworkManager; 51*d9f75844SAndroid Build Coastguard Worker class BasicPacketSocketFactory; 52*d9f75844SAndroid Build Coastguard Worker } // namespace rtc 53*d9f75844SAndroid Build Coastguard Worker 54*d9f75844SAndroid Build Coastguard Worker namespace webrtc { 55*d9f75844SAndroid Build Coastguard Worker 56*d9f75844SAndroid Build Coastguard Worker class RtcEventLog; 57*d9f75844SAndroid Build Coastguard Worker 58*d9f75844SAndroid Build Coastguard Worker class PeerConnectionFactory : public PeerConnectionFactoryInterface { 59*d9f75844SAndroid Build Coastguard Worker public: 60*d9f75844SAndroid Build Coastguard Worker // Creates a PeerConnectionFactory. It returns nullptr on initialization 61*d9f75844SAndroid Build Coastguard Worker // error. 62*d9f75844SAndroid Build Coastguard Worker // 63*d9f75844SAndroid Build Coastguard Worker // The Dependencies structure allows simple management of all new 64*d9f75844SAndroid Build Coastguard Worker // dependencies being added to the PeerConnectionFactory. 65*d9f75844SAndroid Build Coastguard Worker static rtc::scoped_refptr<PeerConnectionFactory> Create( 66*d9f75844SAndroid Build Coastguard Worker PeerConnectionFactoryDependencies dependencies); 67*d9f75844SAndroid Build Coastguard Worker 68*d9f75844SAndroid Build Coastguard Worker void SetOptions(const Options& options) override; 69*d9f75844SAndroid Build Coastguard Worker 70*d9f75844SAndroid Build Coastguard Worker RTCErrorOr<rtc::scoped_refptr<PeerConnectionInterface>> 71*d9f75844SAndroid Build Coastguard Worker CreatePeerConnectionOrError( 72*d9f75844SAndroid Build Coastguard Worker const PeerConnectionInterface::RTCConfiguration& configuration, 73*d9f75844SAndroid Build Coastguard Worker PeerConnectionDependencies dependencies) override; 74*d9f75844SAndroid Build Coastguard Worker 75*d9f75844SAndroid Build Coastguard Worker RtpCapabilities GetRtpSenderCapabilities( 76*d9f75844SAndroid Build Coastguard Worker cricket::MediaType kind) const override; 77*d9f75844SAndroid Build Coastguard Worker 78*d9f75844SAndroid Build Coastguard Worker RtpCapabilities GetRtpReceiverCapabilities( 79*d9f75844SAndroid Build Coastguard Worker cricket::MediaType kind) const override; 80*d9f75844SAndroid Build Coastguard Worker 81*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<MediaStreamInterface> CreateLocalMediaStream( 82*d9f75844SAndroid Build Coastguard Worker const std::string& stream_id) override; 83*d9f75844SAndroid Build Coastguard Worker 84*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource( 85*d9f75844SAndroid Build Coastguard Worker const cricket::AudioOptions& options) override; 86*d9f75844SAndroid Build Coastguard Worker 87*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack( 88*d9f75844SAndroid Build Coastguard Worker const std::string& id, 89*d9f75844SAndroid Build Coastguard Worker VideoTrackSourceInterface* video_source) override; 90*d9f75844SAndroid Build Coastguard Worker 91*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack( 92*d9f75844SAndroid Build Coastguard Worker const std::string& id, 93*d9f75844SAndroid Build Coastguard Worker AudioSourceInterface* audio_source) override; 94*d9f75844SAndroid Build Coastguard Worker 95*d9f75844SAndroid Build Coastguard Worker bool StartAecDump(FILE* file, int64_t max_size_bytes) override; 96*d9f75844SAndroid Build Coastguard Worker void StopAecDump() override; 97*d9f75844SAndroid Build Coastguard Worker sctp_transport_factory()98*d9f75844SAndroid Build Coastguard Worker SctpTransportFactoryInterface* sctp_transport_factory() { 99*d9f75844SAndroid Build Coastguard Worker return context_->sctp_transport_factory(); 100*d9f75844SAndroid Build Coastguard Worker } 101*d9f75844SAndroid Build Coastguard Worker signaling_thread()102*d9f75844SAndroid Build Coastguard Worker rtc::Thread* signaling_thread() const { 103*d9f75844SAndroid Build Coastguard Worker // This method can be called on a different thread when the factory is 104*d9f75844SAndroid Build Coastguard Worker // created in CreatePeerConnectionFactory(). 105*d9f75844SAndroid Build Coastguard Worker return context_->signaling_thread(); 106*d9f75844SAndroid Build Coastguard Worker } 107*d9f75844SAndroid Build Coastguard Worker worker_thread()108*d9f75844SAndroid Build Coastguard Worker rtc::Thread* worker_thread() const { return context_->worker_thread(); } 109*d9f75844SAndroid Build Coastguard Worker options()110*d9f75844SAndroid Build Coastguard Worker const Options& options() const { 111*d9f75844SAndroid Build Coastguard Worker RTC_DCHECK_RUN_ON(signaling_thread()); 112*d9f75844SAndroid Build Coastguard Worker return options_; 113*d9f75844SAndroid Build Coastguard Worker } 114*d9f75844SAndroid Build Coastguard Worker field_trials()115*d9f75844SAndroid Build Coastguard Worker const FieldTrialsView& field_trials() const { 116*d9f75844SAndroid Build Coastguard Worker return context_->field_trials(); 117*d9f75844SAndroid Build Coastguard Worker } 118*d9f75844SAndroid Build Coastguard Worker 119*d9f75844SAndroid Build Coastguard Worker cricket::MediaEngineInterface* media_engine() const; 120*d9f75844SAndroid Build Coastguard Worker 121*d9f75844SAndroid Build Coastguard Worker protected: 122*d9f75844SAndroid Build Coastguard Worker // Constructor used by the static Create() method. Modifies the dependencies. 123*d9f75844SAndroid Build Coastguard Worker PeerConnectionFactory(rtc::scoped_refptr<ConnectionContext> context, 124*d9f75844SAndroid Build Coastguard Worker PeerConnectionFactoryDependencies* dependencies); 125*d9f75844SAndroid Build Coastguard Worker 126*d9f75844SAndroid Build Coastguard Worker // Constructor for use in testing. Ignores the possibility of initialization 127*d9f75844SAndroid Build Coastguard Worker // failure. The dependencies are passed in by std::move(). 128*d9f75844SAndroid Build Coastguard Worker explicit PeerConnectionFactory( 129*d9f75844SAndroid Build Coastguard Worker PeerConnectionFactoryDependencies dependencies); 130*d9f75844SAndroid Build Coastguard Worker 131*d9f75844SAndroid Build Coastguard Worker virtual ~PeerConnectionFactory(); 132*d9f75844SAndroid Build Coastguard Worker 133*d9f75844SAndroid Build Coastguard Worker private: network_thread()134*d9f75844SAndroid Build Coastguard Worker rtc::Thread* network_thread() const { return context_->network_thread(); } 135*d9f75844SAndroid Build Coastguard Worker 136*d9f75844SAndroid Build Coastguard Worker bool IsTrialEnabled(absl::string_view key) const; 137*d9f75844SAndroid Build Coastguard Worker 138*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<RtcEventLog> CreateRtcEventLog_w(); 139*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<Call> CreateCall_w( 140*d9f75844SAndroid Build Coastguard Worker RtcEventLog* event_log, 141*d9f75844SAndroid Build Coastguard Worker const FieldTrialsView& field_trials, 142*d9f75844SAndroid Build Coastguard Worker const PeerConnectionInterface::RTCConfiguration& configuration); 143*d9f75844SAndroid Build Coastguard Worker 144*d9f75844SAndroid Build Coastguard Worker rtc::scoped_refptr<ConnectionContext> context_; 145*d9f75844SAndroid Build Coastguard Worker PeerConnectionFactoryInterface::Options options_ 146*d9f75844SAndroid Build Coastguard Worker RTC_GUARDED_BY(signaling_thread()); 147*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<TaskQueueFactory> task_queue_factory_; 148*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory_; 149*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory_; 150*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<NetworkStatePredictorFactoryInterface> 151*d9f75844SAndroid Build Coastguard Worker network_state_predictor_factory_; 152*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<NetworkControllerFactoryInterface> 153*d9f75844SAndroid Build Coastguard Worker injected_network_controller_factory_; 154*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<NetEqFactory> neteq_factory_; 155*d9f75844SAndroid Build Coastguard Worker const std::unique_ptr<RtpTransportControllerSendFactoryInterface> 156*d9f75844SAndroid Build Coastguard Worker transport_controller_send_factory_; 157*d9f75844SAndroid Build Coastguard Worker std::unique_ptr<Metronome> metronome_ RTC_GUARDED_BY(worker_thread()); 158*d9f75844SAndroid Build Coastguard Worker }; 159*d9f75844SAndroid Build Coastguard Worker 160*d9f75844SAndroid Build Coastguard Worker } // namespace webrtc 161*d9f75844SAndroid Build Coastguard Worker 162*d9f75844SAndroid Build Coastguard Worker #endif // PC_PEER_CONNECTION_FACTORY_H_ 163