deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 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 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef ORTC_ORTCFACTORY_H_ |
| 12 | #define ORTC_ORTCFACTORY_H_ |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 13 | |
| 14 | #include <memory> |
| 15 | #include <string> |
| 16 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 17 | #include "api/ortc/ortcfactoryinterface.h" |
| 18 | #include "media/base/mediaengine.h" |
| 19 | #include "media/engine/webrtcmediaengine.h" |
| 20 | #include "pc/channelmanager.h" |
| 21 | #include "rtc_base/constructormagic.h" |
| 22 | #include "rtc_base/scoped_ref_ptr.h" |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | |
| 26 | // Implementation of OrtcFactoryInterface. |
| 27 | // |
| 28 | // See ortcfactoryinterface.h for documentation. |
| 29 | class OrtcFactory : public OrtcFactoryInterface { |
| 30 | public: |
| 31 | ~OrtcFactory() override; |
| 32 | |
| 33 | // Internal-only Create method that allows passing in a fake media engine, |
| 34 | // for testing. |
| 35 | static RTCErrorOr<std::unique_ptr<OrtcFactoryInterface>> Create( |
| 36 | rtc::Thread* network_thread, |
| 37 | rtc::Thread* signaling_thread, |
| 38 | rtc::NetworkManager* network_manager, |
| 39 | rtc::PacketSocketFactory* socket_factory, |
| 40 | AudioDeviceModule* adm, |
Karl Wiberg | 3e9e5b3 | 2017-11-06 05:01:56 +0100 | [diff] [blame] | 41 | std::unique_ptr<cricket::MediaEngineInterface> media_engine, |
| 42 | rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory, |
| 43 | rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory); |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 44 | |
| 45 | RTCErrorOr<std::unique_ptr<RtpTransportControllerInterface>> |
| 46 | CreateRtpTransportController() override; |
| 47 | |
| 48 | RTCErrorOr<std::unique_ptr<RtpTransportInterface>> CreateRtpTransport( |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 49 | const RtpTransportParameters& parameters, |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 50 | PacketTransportInterface* rtp, |
| 51 | PacketTransportInterface* rtcp, |
| 52 | RtpTransportControllerInterface* transport_controller) override; |
| 53 | |
zhihuang | d3501ad | 2017-03-03 14:39:06 -0800 | [diff] [blame] | 54 | RTCErrorOr<std::unique_ptr<SrtpTransportInterface>> CreateSrtpTransport( |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 55 | const RtpTransportParameters& parameters, |
zhihuang | d3501ad | 2017-03-03 14:39:06 -0800 | [diff] [blame] | 56 | PacketTransportInterface* rtp, |
| 57 | PacketTransportInterface* rtcp, |
| 58 | RtpTransportControllerInterface* transport_controller) override; |
| 59 | |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 60 | RtpCapabilities GetRtpSenderCapabilities( |
| 61 | cricket::MediaType kind) const override; |
| 62 | |
| 63 | RTCErrorOr<std::unique_ptr<OrtcRtpSenderInterface>> CreateRtpSender( |
| 64 | rtc::scoped_refptr<MediaStreamTrackInterface> track, |
| 65 | RtpTransportInterface* transport) override; |
| 66 | |
| 67 | RTCErrorOr<std::unique_ptr<OrtcRtpSenderInterface>> CreateRtpSender( |
| 68 | cricket::MediaType kind, |
| 69 | RtpTransportInterface* transport) override; |
| 70 | |
| 71 | RtpCapabilities GetRtpReceiverCapabilities( |
| 72 | cricket::MediaType kind) const override; |
| 73 | |
| 74 | RTCErrorOr<std::unique_ptr<OrtcRtpReceiverInterface>> CreateRtpReceiver( |
| 75 | cricket::MediaType kind, |
| 76 | RtpTransportInterface* transport) override; |
| 77 | |
| 78 | RTCErrorOr<std::unique_ptr<UdpTransportInterface>> |
| 79 | CreateUdpTransport(int family, uint16_t min_port, uint16_t max_port) override; |
| 80 | |
| 81 | rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource( |
| 82 | const cricket::AudioOptions& options) override; |
| 83 | |
| 84 | rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource( |
| 85 | std::unique_ptr<cricket::VideoCapturer> capturer, |
| 86 | const MediaConstraintsInterface* constraints) override; |
| 87 | |
| 88 | rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack( |
| 89 | const std::string& id, |
| 90 | VideoTrackSourceInterface* source) override; |
| 91 | |
| 92 | rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack( |
| 93 | const std::string& id, |
| 94 | AudioSourceInterface* source) override; |
| 95 | |
| 96 | rtc::Thread* network_thread() { return network_thread_; } |
| 97 | rtc::Thread* worker_thread() { return worker_thread_.get(); } |
| 98 | rtc::Thread* signaling_thread() { return signaling_thread_; } |
| 99 | |
| 100 | private: |
| 101 | // Should only be called by OrtcFactoryInterface::Create. |
| 102 | OrtcFactory(rtc::Thread* network_thread, |
| 103 | rtc::Thread* signaling_thread, |
| 104 | rtc::NetworkManager* network_manager, |
| 105 | rtc::PacketSocketFactory* socket_factory, |
Karl Wiberg | 3e9e5b3 | 2017-11-06 05:01:56 +0100 | [diff] [blame] | 106 | AudioDeviceModule* adm, |
| 107 | rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory, |
| 108 | rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory); |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 109 | |
sprang | db2a9fc | 2017-08-09 06:42:32 -0700 | [diff] [blame] | 110 | RTCErrorOr<std::unique_ptr<RtpTransportControllerInterface>> |
| 111 | CreateRtpTransportController(const RtpTransportParameters& parameters); |
| 112 | |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 113 | // Thread::Invoke doesn't support move-only arguments, so we need to remove |
| 114 | // the unique_ptr wrapper from media_engine. TODO(deadbeef): Fix this. |
| 115 | static RTCErrorOr<std::unique_ptr<OrtcFactoryInterface>> Create_s( |
| 116 | rtc::Thread* network_thread, |
| 117 | rtc::Thread* signaling_thread, |
| 118 | rtc::NetworkManager* network_manager, |
| 119 | rtc::PacketSocketFactory* socket_factory, |
| 120 | AudioDeviceModule* adm, |
Karl Wiberg | 3e9e5b3 | 2017-11-06 05:01:56 +0100 | [diff] [blame] | 121 | cricket::MediaEngineInterface* media_engine, |
| 122 | rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory, |
| 123 | rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory); |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 124 | |
| 125 | // Performs initialization that can fail. Called by factory method after |
| 126 | // construction, and if it fails, no object is returned. |
| 127 | RTCError Initialize( |
| 128 | std::unique_ptr<cricket::MediaEngineInterface> media_engine); |
| 129 | std::unique_ptr<cricket::MediaEngineInterface> CreateMediaEngine_w(); |
| 130 | |
| 131 | // Threads and networking objects. |
| 132 | rtc::Thread* network_thread_; |
| 133 | rtc::Thread* signaling_thread_; |
| 134 | rtc::NetworkManager* network_manager_; |
| 135 | rtc::PacketSocketFactory* socket_factory_; |
| 136 | AudioDeviceModule* adm_; |
| 137 | // If we created/own the objects above, these will be non-null and thus will |
| 138 | // be released automatically upon destruction. |
| 139 | std::unique_ptr<rtc::Thread> owned_network_thread_; |
| 140 | bool wraps_signaling_thread_ = false; |
| 141 | std::unique_ptr<rtc::NetworkManager> owned_network_manager_; |
| 142 | std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_; |
| 143 | // We always own the worker thread. |
| 144 | std::unique_ptr<rtc::Thread> worker_thread_; |
| 145 | // Media-releated objects. |
| 146 | std::unique_ptr<RtcEventLog> null_event_log_; |
ossu | eb1fde4 | 2017-05-02 06:46:30 -0700 | [diff] [blame] | 147 | rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory_; |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 148 | rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory_; |
| 149 | std::unique_ptr<cricket::ChannelManager> channel_manager_; |
| 150 | // Default CNAME to use for RtpTransports if none is passed in. |
| 151 | std::string default_cname_; |
| 152 | |
| 153 | friend class OrtcFactoryInterface; |
| 154 | |
| 155 | RTC_DISALLOW_COPY_AND_ASSIGN(OrtcFactory); |
| 156 | }; |
| 157 | |
| 158 | } // namespace webrtc |
| 159 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 160 | #endif // ORTC_ORTCFACTORY_H_ |