1 2 /* 3 * Copyright 2011 The WebRTC project authors. All Rights Reserved. 4 * 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. 10 */ 11 12 #ifndef PC_PEER_CONNECTION_FACTORY_H_ 13 #define PC_PEER_CONNECTION_FACTORY_H_ 14 15 #include <memory> 16 #include <string> 17 18 #include "api/media_stream_interface.h" 19 #include "api/peer_connection_interface.h" 20 #include "api/scoped_refptr.h" 21 #include "media/sctp/sctp_transport_internal.h" 22 #include "pc/channel_manager.h" 23 #include "rtc_base/rtc_certificate_generator.h" 24 #include "rtc_base/thread.h" 25 26 namespace rtc { 27 class BasicNetworkManager; 28 class BasicPacketSocketFactory; 29 } // namespace rtc 30 31 namespace webrtc { 32 33 class RtcEventLog; 34 35 class PeerConnectionFactory : public PeerConnectionFactoryInterface { 36 public: 37 void SetOptions(const Options& options) override; 38 39 rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection( 40 const PeerConnectionInterface::RTCConfiguration& configuration, 41 std::unique_ptr<cricket::PortAllocator> allocator, 42 std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator, 43 PeerConnectionObserver* observer) override; 44 45 rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection( 46 const PeerConnectionInterface::RTCConfiguration& configuration, 47 PeerConnectionDependencies dependencies) override; 48 49 bool Initialize(); 50 51 RtpCapabilities GetRtpSenderCapabilities( 52 cricket::MediaType kind) const override; 53 54 RtpCapabilities GetRtpReceiverCapabilities( 55 cricket::MediaType kind) const override; 56 57 rtc::scoped_refptr<MediaStreamInterface> CreateLocalMediaStream( 58 const std::string& stream_id) override; 59 60 rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource( 61 const cricket::AudioOptions& options) override; 62 63 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack( 64 const std::string& id, 65 VideoTrackSourceInterface* video_source) override; 66 67 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack( 68 const std::string& id, 69 AudioSourceInterface* audio_source) override; 70 71 bool StartAecDump(FILE* file, int64_t max_size_bytes) override; 72 void StopAecDump() override; 73 74 virtual std::unique_ptr<cricket::SctpTransportInternalFactory> 75 CreateSctpTransportInternalFactory(); 76 77 virtual cricket::ChannelManager* channel_manager(); 78 signaling_thread()79 rtc::Thread* signaling_thread() { 80 // This method can be called on a different thread when the factory is 81 // created in CreatePeerConnectionFactory(). 82 return signaling_thread_; 83 } worker_thread()84 rtc::Thread* worker_thread() { return worker_thread_; } network_thread()85 rtc::Thread* network_thread() { return network_thread_; } 86 options()87 const Options& options() const { return options_; } 88 89 protected: 90 // This structure allows simple management of all new dependencies being added 91 // to the PeerConnectionFactory. 92 explicit PeerConnectionFactory( 93 PeerConnectionFactoryDependencies dependencies); 94 95 // Hook to let testing framework insert actions between 96 // "new RTCPeerConnection" and "pc.Initialize" ActionsBeforeInitializeForTesting(PeerConnectionInterface *)97 virtual void ActionsBeforeInitializeForTesting(PeerConnectionInterface*) {} 98 99 virtual ~PeerConnectionFactory(); 100 101 private: 102 bool IsTrialEnabled(absl::string_view key) const; 103 104 std::unique_ptr<RtcEventLog> CreateRtcEventLog_w(); 105 std::unique_ptr<Call> CreateCall_w(RtcEventLog* event_log); 106 107 bool wraps_current_thread_; 108 rtc::Thread* network_thread_; 109 rtc::Thread* worker_thread_; 110 rtc::Thread* signaling_thread_; 111 std::unique_ptr<rtc::Thread> owned_network_thread_; 112 std::unique_ptr<rtc::Thread> owned_worker_thread_; 113 const std::unique_ptr<TaskQueueFactory> task_queue_factory_; 114 Options options_; 115 std::unique_ptr<cricket::ChannelManager> channel_manager_; 116 std::unique_ptr<rtc::BasicNetworkManager> default_network_manager_; 117 std::unique_ptr<rtc::BasicPacketSocketFactory> default_socket_factory_; 118 std::unique_ptr<cricket::MediaEngineInterface> media_engine_; 119 std::unique_ptr<webrtc::CallFactoryInterface> call_factory_; 120 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory_; 121 std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory_; 122 std::unique_ptr<NetworkStatePredictorFactoryInterface> 123 network_state_predictor_factory_; 124 std::unique_ptr<NetworkControllerFactoryInterface> 125 injected_network_controller_factory_; 126 std::unique_ptr<NetEqFactory> neteq_factory_; 127 const std::unique_ptr<WebRtcKeyValueConfig> trials_; 128 }; 129 130 } // namespace webrtc 131 132 #endif // PC_PEER_CONNECTION_FACTORY_H_ 133