Chromium Code Reviews| 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_API_ORTC_ORTCFACTORYINTERFACE_H_ | |
| 12 #define WEBRTC_API_ORTC_ORTCFACTORYINTERFACE_H_ | |
| 13 | |
| 14 #include <memory> | |
| 15 #include <string> | |
| 16 #include <utility> // For std::move. | |
| 17 | |
| 18 #include "webrtc/api/mediaconstraintsinterface.h" | |
| 19 #include "webrtc/api/mediastreaminterface.h" | |
| 20 #include "webrtc/api/mediatypes.h" | |
| 21 #include "webrtc/api/ortc/ortcrtpreceiverinterface.h" | |
| 22 #include "webrtc/api/ortc/ortcrtpsenderinterface.h" | |
| 23 #include "webrtc/api/ortc/packettransportinterface.h" | |
| 24 #include "webrtc/api/ortc/rtptransportcontrollerinterface.h" | |
| 25 #include "webrtc/api/ortc/rtptransportinterface.h" | |
| 26 #include "webrtc/api/ortc/udptransportinterface.h" | |
| 27 #include "webrtc/api/rtcerror.h" | |
| 28 #include "webrtc/api/rtpparameters.h" | |
| 29 #include "webrtc/base/network.h" | |
| 30 #include "webrtc/base/scoped_ref_ptr.h" | |
| 31 #include "webrtc/base/thread.h" | |
| 32 #include "webrtc/p2p/base/packetsocketfactory.h" | |
| 33 | |
| 34 namespace webrtc { | |
| 35 | |
| 36 // TODO(deadbeef): This should be part of /api/, but currently it's not and | |
| 37 // including its header violates checkdeps rules. | |
| 38 class AudioDeviceModule; | |
| 39 | |
| 40 // WARNING: This is experimental/under development, so use at your own risk; no | |
| 41 // guarantee about API stability is guaranteed here yet. | |
| 42 // | |
| 43 // This class is the ORTC analog of PeerConnectionFactory. It acts as a factory | |
| 44 // for ORTC objects that can be connected to each other. | |
| 45 // | |
| 46 // Some of these objects may not be represented by the ORTC specification, but | |
| 47 // follow the same general principles. | |
| 48 // | |
| 49 // If one of the factory methods takes another object as an argument, it MUST | |
| 50 // have been created by the same OrtcFactory. | |
| 51 // | |
| 52 // On object lifetimes: The factory must not be destroyed before destroying the | |
| 53 // objects it created, and the objects passed into the factory must not be | |
| 54 // destroyed before destroying the factory. | |
|
pthatcher1
2017/02/10 22:36:52
So, destruction order must be:
1. Objects created
Taylor Brandstetter
2017/02/14 06:55:04
Done.
| |
| 55 class OrtcFactoryInterface { | |
| 56 public: | |
| 57 // |network_thread| is the thread on which packets are sent and received. | |
| 58 // If null, a new rtc::Thread with a default socket server is created. | |
| 59 // | |
| 60 // |signaling_thread| is used for callbacks to the consumer of the API. If | |
| 61 // null, the current thread will be used, which assumes that the API consumer | |
| 62 // is running a message loop on this thread (either using an existing | |
| 63 // rtc::Thread, or by calling rtc::Thread::Current()->ProcessMessages). | |
| 64 // | |
| 65 // |network_manager| is used to determine which network interfaces are | |
| 66 // available. This is used for ICE, for example. If null, a default | |
| 67 // implementation will be used. Only accessed on |network_thread|. | |
| 68 // | |
| 69 // |socket_factory| is used (on the network thread) for creating sockets. If | |
| 70 // it's null, a default implementation will be used, which assumes | |
| 71 // |network_thread| is a normal rtc::Thread. | |
| 72 // | |
| 73 // |adm| is optional, and allows a different audio device implementation to | |
| 74 // be injected; otherwise a platform-specific module will be used that will | |
| 75 // use the default audio input. | |
| 76 // | |
| 77 // Note that the OrtcFactoryInterface does not take ownership of any of the | |
| 78 // objects passed in, and as previously stated, these objects can't be | |
| 79 // destroyed before the factory is. | |
| 80 static RTCErrorOr<std::unique_ptr<OrtcFactoryInterface>> Create( | |
| 81 rtc::Thread* network_thread, | |
| 82 rtc::Thread* signaling_thread, | |
| 83 rtc::NetworkManager* network_manager, | |
| 84 rtc::PacketSocketFactory* socket_factory, | |
| 85 AudioDeviceModule* adm); | |
| 86 | |
| 87 // Constructor for convenience which uses default implementations of | |
| 88 // everything (though does still require that the current thread runs a | |
| 89 // message loop; see above). | |
| 90 static RTCErrorOr<std::unique_ptr<OrtcFactoryInterface>> Create() { | |
| 91 return Create(nullptr, nullptr, nullptr, nullptr, nullptr); | |
| 92 } | |
| 93 | |
| 94 virtual ~OrtcFactoryInterface() {} | |
| 95 | |
| 96 // Creates an RTP transport controller, which is required for calls to | |
| 97 // CreateRtpTransport methods. If your application has some notion of a | |
| 98 // "call", you should create one transport controller per call. | |
|
pthatcher1
2017/02/10 22:36:52
Can you point out that you only need to create thi
Taylor Brandstetter
2017/02/14 06:55:04
Done.
| |
| 99 // TODO(deadbeef): Add MediaConfig and RtcEventLog arguments? | |
| 100 virtual RTCErrorOr<std::unique_ptr<RtpTransportControllerInterface>> | |
| 101 CreateRtpTransportController() = 0; | |
| 102 | |
| 103 // Creates an RTP transport using the provided packet transports and | |
| 104 // transport controller. | |
| 105 // | |
| 106 // |rtp| will be used for sending RTP packets, and |rtcp| for RTCP packets. | |
| 107 // | |
| 108 // |rtp| can't be null. |rtcp| can if RTCP muxing is being used immediately, | |
| 109 // meaning |rtcp_parameters.mux| is true. | |
| 110 // | |
| 111 // If |transport_controller| is null, one will automatically be created, and | |
| 112 // its lifetime managed by the returned RtpTransport. This should only be | |
| 113 // done if a single RtpTransport is being used to communicate with the remote | |
| 114 // endpoint. | |
| 115 virtual RTCErrorOr<std::unique_ptr<RtpTransportInterface>> CreateRtpTransport( | |
| 116 const RtcpParameters& rtcp_parameters, | |
| 117 PacketTransportInterface* rtp, | |
| 118 PacketTransportInterface* rtcp, | |
| 119 RtpTransportControllerInterface* transport_controller) = 0; | |
| 120 | |
| 121 // Returns the capabilities of an RTP sender of type |kind|. These | |
| 122 // capabilities can be used to determine what RtpParameters to use to create | |
| 123 // an RtpSender. | |
| 124 // | |
| 125 // If for some reason you pass in MEDIA_TYPE_DATA, returns an empty structure. | |
| 126 virtual RtpCapabilities GetRtpSenderCapabilities( | |
| 127 cricket::MediaType kind) const = 0; | |
| 128 | |
| 129 // Creates an RTP sender with |track|. Will not start sending until Send is | |
| 130 // called. | |
| 131 // | |
| 132 // |track| and |transport| must not be null. | |
| 133 virtual RTCErrorOr<std::unique_ptr<OrtcRtpSenderInterface>> CreateRtpSender( | |
| 134 rtc::scoped_refptr<MediaStreamTrackInterface> track, | |
| 135 RtpTransportInterface* transport) = 0; | |
| 136 | |
| 137 // Same as above, but allows creating the sender without a track. | |
| 138 // | |
| 139 // |kind| must be MEDIA_TYPE_AUDIO or MEDIA_TYPE_VIDEO. | |
| 140 virtual RTCErrorOr<std::unique_ptr<OrtcRtpSenderInterface>> CreateRtpSender( | |
| 141 cricket::MediaType kind, | |
| 142 RtpTransportInterface* transport) = 0; | |
| 143 | |
| 144 // Returns the capabilities of an RTP receiver of type |kind|. These | |
| 145 // capabilities can be used to determine what RtpParameters to use to create | |
| 146 // an RtpReceiver. | |
| 147 // | |
| 148 // If for some reason you pass in MEDIA_TYPE_DATA, returns an empty structure. | |
| 149 virtual RtpCapabilities GetRtpReceiverCapabilities( | |
| 150 cricket::MediaType kind) const = 0; | |
| 151 | |
| 152 // Creates an RTP receiver of type |kind|. Will not start receiving media | |
| 153 // until Receive is called. | |
| 154 // | |
| 155 // |kind| must be MEDIA_TYPE_AUDIO or MEDIA_TYPE_VIDEO. | |
| 156 // | |
| 157 // |transport| must not be null. | |
| 158 virtual RTCErrorOr<std::unique_ptr<OrtcRtpReceiverInterface>> | |
| 159 CreateRtpReceiver(cricket::MediaType kind, | |
| 160 RtpTransportInterface* transport) = 0; | |
| 161 | |
| 162 // Create a UDP transport with IP address family |family|, using a port | |
| 163 // within the specified range. | |
| 164 // | |
| 165 // |family| must be AF_INET or AF_INET6. | |
| 166 // | |
| 167 // |min_port|/|max_port| values of 0 indicate no range restriction. | |
| 168 // | |
| 169 // Returns an error if the transport wasn't successfully created. | |
| 170 virtual RTCErrorOr<std::unique_ptr<UdpTransportInterface>> | |
| 171 CreateUdpTransport(int family, uint16_t min_port, uint16_t max_port) = 0; | |
| 172 | |
| 173 // NOTE: The methods below to create tracks/sources return scoped_refptrs | |
| 174 // rather than unique_ptrs, because these interfaces are also used with | |
| 175 // PeerConnection, where everything is ref-counted. | |
| 176 | |
| 177 // Creates a audio source representing the default microphone input. | |
| 178 // |options| decides audio processing settings. | |
| 179 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource( | |
| 180 const cricket::AudioOptions& options) = 0; | |
| 181 | |
| 182 // Version of the above method that uses default options. | |
| 183 rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource() { | |
| 184 return CreateAudioSource(cricket::AudioOptions()); | |
| 185 } | |
| 186 | |
| 187 // Creates a video source object wrapping and taking ownership of |capturer|. | |
| 188 // | |
| 189 // |constraints| can be used for selection of resolution and frame rate, and | |
| 190 // may be null if no constraints are desired. | |
| 191 virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource( | |
| 192 std::unique_ptr<cricket::VideoCapturer> capturer, | |
| 193 const MediaConstraintsInterface* constraints) = 0; | |
| 194 | |
| 195 // Version of the above method that omits |constraints|. | |
| 196 rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource( | |
| 197 std::unique_ptr<cricket::VideoCapturer> capturer) { | |
| 198 return CreateVideoSource(std::move(capturer), nullptr); | |
| 199 } | |
| 200 | |
| 201 // Creates a new local video track wrapping |source|. The same |source| can | |
| 202 // be used in several tracks. | |
| 203 virtual rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack( | |
| 204 const std::string& id, | |
| 205 VideoTrackSourceInterface* source) = 0; | |
| 206 | |
| 207 // Creates an new local audio track wrapping |source|. | |
| 208 virtual rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack( | |
| 209 const std::string& id, | |
| 210 AudioSourceInterface* source) = 0; | |
| 211 | |
| 212 // Method for convenience that has no port range restrictions. | |
| 213 RTCErrorOr<std::unique_ptr<UdpTransportInterface>> CreateUdpTransport( | |
| 214 int family) { | |
| 215 return CreateUdpTransport(family, 0, 0); | |
| 216 } | |
|
pthatcher1
2017/02/10 22:36:52
This ought to go next to the other CreateUdpTransp
Taylor Brandstetter
2017/02/14 06:55:04
Done.
| |
| 217 }; | |
| 218 | |
| 219 } // namespace webrtc | |
| 220 | |
| 221 #endif // WEBRTC_API_ORTC_ORTCFACTORYINTERFACE_H_ | |
| OLD | NEW |