peer_connection_factory.h 4.8 KB

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