OLD | NEW |
(Empty) | |
| 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 |
| 11 #ifndef WEBRTC_ORTC_ORTCFACTORY_H_ |
| 12 #define WEBRTC_ORTC_ORTCFACTORY_H_ |
| 13 |
| 14 #include <memory> |
| 15 #include <string> |
| 16 |
| 17 #include "webrtc/api/ortc/ortcfactoryinterface.h" |
| 18 #include "webrtc/base/constructormagic.h" |
| 19 #include "webrtc/base/scoped_ref_ptr.h" |
| 20 #include "webrtc/media/base/mediaengine.h" |
| 21 #include "webrtc/media/engine/webrtcmediaengine.h" |
| 22 #include "webrtc/pc/channelmanager.h" |
| 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, |
| 41 std::unique_ptr<cricket::MediaEngineInterface> media_engine); |
| 42 |
| 43 RTCErrorOr<std::unique_ptr<RtpTransportControllerInterface>> |
| 44 CreateRtpTransportController() override; |
| 45 |
| 46 RTCErrorOr<std::unique_ptr<RtpTransportInterface>> CreateRtpTransport( |
| 47 const RtcpParameters& rtcp_parameters, |
| 48 PacketTransportInterface* rtp, |
| 49 PacketTransportInterface* rtcp, |
| 50 RtpTransportControllerInterface* transport_controller) override; |
| 51 |
| 52 RtpCapabilities GetRtpSenderCapabilities( |
| 53 cricket::MediaType kind) const override; |
| 54 |
| 55 RTCErrorOr<std::unique_ptr<OrtcRtpSenderInterface>> CreateRtpSender( |
| 56 rtc::scoped_refptr<MediaStreamTrackInterface> track, |
| 57 RtpTransportInterface* transport) override; |
| 58 |
| 59 RTCErrorOr<std::unique_ptr<OrtcRtpSenderInterface>> CreateRtpSender( |
| 60 cricket::MediaType kind, |
| 61 RtpTransportInterface* transport) override; |
| 62 |
| 63 RtpCapabilities GetRtpReceiverCapabilities( |
| 64 cricket::MediaType kind) const override; |
| 65 |
| 66 RTCErrorOr<std::unique_ptr<OrtcRtpReceiverInterface>> CreateRtpReceiver( |
| 67 cricket::MediaType kind, |
| 68 RtpTransportInterface* transport) override; |
| 69 |
| 70 RTCErrorOr<std::unique_ptr<UdpTransportInterface>> |
| 71 CreateUdpTransport(int family, uint16_t min_port, uint16_t max_port) override; |
| 72 |
| 73 rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource( |
| 74 const cricket::AudioOptions& options) override; |
| 75 |
| 76 rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource( |
| 77 std::unique_ptr<cricket::VideoCapturer> capturer, |
| 78 const MediaConstraintsInterface* constraints) override; |
| 79 |
| 80 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack( |
| 81 const std::string& id, |
| 82 VideoTrackSourceInterface* source) override; |
| 83 |
| 84 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack( |
| 85 const std::string& id, |
| 86 AudioSourceInterface* source) override; |
| 87 |
| 88 rtc::Thread* network_thread() { return network_thread_; } |
| 89 rtc::Thread* worker_thread() { return worker_thread_.get(); } |
| 90 rtc::Thread* signaling_thread() { return signaling_thread_; } |
| 91 |
| 92 private: |
| 93 // Should only be called by OrtcFactoryInterface::Create. |
| 94 OrtcFactory(rtc::Thread* network_thread, |
| 95 rtc::Thread* signaling_thread, |
| 96 rtc::NetworkManager* network_manager, |
| 97 rtc::PacketSocketFactory* socket_factory, |
| 98 AudioDeviceModule* adm); |
| 99 |
| 100 // Performs initialization that can fail. Called by factory method after |
| 101 // construction, and if it fails, no object is returned. |
| 102 RTCError Initialize( |
| 103 std::unique_ptr<cricket::MediaEngineInterface> media_engine); |
| 104 std::unique_ptr<cricket::MediaEngineInterface> CreateMediaEngine_w(); |
| 105 |
| 106 // Threads and networking objects. |
| 107 rtc::Thread* network_thread_; |
| 108 rtc::Thread* signaling_thread_; |
| 109 rtc::NetworkManager* network_manager_; |
| 110 rtc::PacketSocketFactory* socket_factory_; |
| 111 AudioDeviceModule* adm_; |
| 112 // If we created/own the objects above, these will be non-null and thus will |
| 113 // be released automatically upon destruction. |
| 114 std::unique_ptr<rtc::Thread> owned_network_thread_; |
| 115 bool wraps_signaling_thread_ = false; |
| 116 std::unique_ptr<rtc::NetworkManager> owned_network_manager_; |
| 117 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_; |
| 118 // We always own the worker thread. |
| 119 std::unique_ptr<rtc::Thread> worker_thread_; |
| 120 // Media-releated objects. |
| 121 std::unique_ptr<RtcEventLog> null_event_log_; |
| 122 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory_; |
| 123 std::unique_ptr<cricket::ChannelManager> channel_manager_; |
| 124 |
| 125 friend class OrtcFactoryInterface; |
| 126 |
| 127 RTC_DISALLOW_COPY_AND_ASSIGN(OrtcFactory); |
| 128 }; |
| 129 |
| 130 } // namespace webrtc |
| 131 |
| 132 #endif // WEBRTC_ORTC_ORTCFACTORY_H_ |
OLD | NEW |