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