peer_connection_factory.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 "api/transport/media/media_transport_interface.h"
  18. #include "media/sctp/sctp_transport_internal.h"
  19. #include "pc/channel_manager.h"
  20. #include "rtc_base/rtc_certificate_generator.h"
  21. #include "rtc_base/thread.h"
  22. namespace rtc {
  23. class BasicNetworkManager;
  24. class BasicPacketSocketFactory;
  25. } // namespace rtc
  26. namespace webrtc {
  27. class RtcEventLog;
  28. class PeerConnectionFactory : public PeerConnectionFactoryInterface {
  29. public:
  30. void SetOptions(const Options& options) override;
  31. rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
  32. const PeerConnectionInterface::RTCConfiguration& configuration,
  33. std::unique_ptr<cricket::PortAllocator> allocator,
  34. std::unique_ptr<rtc::RTCCertificateGeneratorInterface> cert_generator,
  35. PeerConnectionObserver* observer) override;
  36. rtc::scoped_refptr<PeerConnectionInterface> CreatePeerConnection(
  37. const PeerConnectionInterface::RTCConfiguration& configuration,
  38. PeerConnectionDependencies dependencies) override;
  39. bool Initialize();
  40. RtpCapabilities GetRtpSenderCapabilities(
  41. cricket::MediaType kind) const override;
  42. RtpCapabilities GetRtpReceiverCapabilities(
  43. cricket::MediaType kind) const override;
  44. rtc::scoped_refptr<MediaStreamInterface> CreateLocalMediaStream(
  45. const std::string& stream_id) override;
  46. rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
  47. const cricket::AudioOptions& options) override;
  48. rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
  49. const std::string& id,
  50. VideoTrackSourceInterface* video_source) override;
  51. rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
  52. const std::string& id,
  53. AudioSourceInterface* audio_source) override;
  54. bool StartAecDump(FILE* file, int64_t max_size_bytes) override;
  55. void StopAecDump() override;
  56. virtual std::unique_ptr<cricket::SctpTransportInternalFactory>
  57. CreateSctpTransportInternalFactory();
  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. MediaTransportFactory* media_transport_factory() {
  68. return media_transport_factory_.get();
  69. }
  70. protected:
  71. // This structure allows simple management of all new dependencies being added
  72. // to the PeerConnectionFactory.
  73. explicit PeerConnectionFactory(
  74. PeerConnectionFactoryDependencies dependencies);
  75. // Hook to let testing framework insert actions between
  76. // "new RTCPeerConnection" and "pc.Initialize"
  77. virtual void ActionsBeforeInitializeForTesting(PeerConnectionInterface*) {}
  78. virtual ~PeerConnectionFactory();
  79. private:
  80. bool IsTrialEnabled(absl::string_view key) const;
  81. std::unique_ptr<RtcEventLog> CreateRtcEventLog_w();
  82. std::unique_ptr<Call> CreateCall_w(RtcEventLog* event_log);
  83. bool wraps_current_thread_;
  84. rtc::Thread* network_thread_;
  85. rtc::Thread* worker_thread_;
  86. rtc::Thread* signaling_thread_;
  87. std::unique_ptr<rtc::Thread> owned_network_thread_;
  88. std::unique_ptr<rtc::Thread> owned_worker_thread_;
  89. const std::unique_ptr<TaskQueueFactory> task_queue_factory_;
  90. Options options_;
  91. std::unique_ptr<cricket::ChannelManager> channel_manager_;
  92. std::unique_ptr<rtc::BasicNetworkManager> default_network_manager_;
  93. std::unique_ptr<rtc::BasicPacketSocketFactory> default_socket_factory_;
  94. std::unique_ptr<cricket::MediaEngineInterface> media_engine_;
  95. std::unique_ptr<webrtc::CallFactoryInterface> call_factory_;
  96. std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory_;
  97. std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory_;
  98. std::unique_ptr<NetworkStatePredictorFactoryInterface>
  99. network_state_predictor_factory_;
  100. std::unique_ptr<NetworkControllerFactoryInterface>
  101. injected_network_controller_factory_;
  102. std::unique_ptr<MediaTransportFactory> media_transport_factory_;
  103. std::unique_ptr<NetEqFactory> neteq_factory_;
  104. const std::unique_ptr<WebRtcKeyValueConfig> trials_;
  105. };
  106. } // namespace webrtc
  107. #endif // PC_PEER_CONNECTION_FACTORY_H_