Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(464)

Side by Side Diff: webrtc/api/ortc/ortcfactoryinterface.h

Issue 2675173003: Adding "adapter" ORTC objects on top of ChannelManager/BaseChannel/etc. (Closed)
Patch Set: Adding OrtcFactory unit tests. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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: objects should be destroyed in this order:
53 // 1. Objects created by the factory.
54 // 2. The factory itself.
55 // 3. Objects passed into OrtcFactoryInterface::Create.
56 class OrtcFactoryInterface {
57 public:
58 // |network_thread| is the thread on which packets are sent and received.
59 // If null, a new rtc::Thread with a default socket server is created.
60 //
61 // |signaling_thread| is used for callbacks to the consumer of the API. If
62 // null, the current thread will be used, which assumes that the API consumer
63 // is running a message loop on this thread (either using an existing
64 // rtc::Thread, or by calling rtc::Thread::Current()->ProcessMessages).
65 //
66 // |network_manager| is used to determine which network interfaces are
67 // available. This is used for ICE, for example. If null, a default
68 // implementation will be used. Only accessed on |network_thread|.
69 //
70 // |socket_factory| is used (on the network thread) for creating sockets. If
71 // it's null, a default implementation will be used, which assumes
72 // |network_thread| is a normal rtc::Thread.
73 //
74 // |adm| is optional, and allows a different audio device implementation to
75 // be injected; otherwise a platform-specific module will be used that will
76 // use the default audio input.
77 //
78 // Note that the OrtcFactoryInterface does not take ownership of any of the
79 // objects passed in, and as previously stated, these objects can't be
80 // destroyed before the factory is.
81 static RTCErrorOr<std::unique_ptr<OrtcFactoryInterface>> Create(
82 rtc::Thread* network_thread,
83 rtc::Thread* signaling_thread,
84 rtc::NetworkManager* network_manager,
85 rtc::PacketSocketFactory* socket_factory,
86 AudioDeviceModule* adm);
87
88 // Constructor for convenience which uses default implementations of
89 // everything (though does still require that the current thread runs a
90 // message loop; see above).
91 static RTCErrorOr<std::unique_ptr<OrtcFactoryInterface>> Create() {
92 return Create(nullptr, nullptr, nullptr, nullptr, nullptr);
93 }
94
95 virtual ~OrtcFactoryInterface() {}
96
97 // Creates an RTP transport controller, which is used in calls to
98 // CreateRtpTransport methods. If your application has some notion of a
99 // "call", you should create one transport controller per call.
100 //
101 // However, if you only are using one RtpTransport object, this doesn't need
102 // to be called explicitly; CreateRtpTransport will create one automatically
103 // if |rtp_transport_controller| is null. See below.
104 //
105 // TODO(deadbeef): Add MediaConfig and RtcEventLog arguments?
106 virtual RTCErrorOr<std::unique_ptr<RtpTransportControllerInterface>>
107 CreateRtpTransportController() = 0;
108
109 // Creates an RTP transport using the provided packet transports and
110 // transport controller.
111 //
112 // |rtp| will be used for sending RTP packets, and |rtcp| for RTCP packets.
113 //
114 // |rtp| can't be null. |rtcp| can if RTCP muxing is being used immediately,
115 // meaning |rtcp_parameters.mux| is true.
116 //
117 // If |transport_controller| is null, one will automatically be created, and
118 // its lifetime managed by the returned RtpTransport. This should only be
119 // done if a single RtpTransport is being used to communicate with the remote
120 // endpoint.
121 virtual RTCErrorOr<std::unique_ptr<RtpTransportInterface>> CreateRtpTransport(
122 const RtcpParameters& rtcp_parameters,
123 PacketTransportInterface* rtp,
124 PacketTransportInterface* rtcp,
125 RtpTransportControllerInterface* transport_controller) = 0;
126
127 // Returns the capabilities of an RTP sender of type |kind|. These
128 // capabilities can be used to determine what RtpParameters to use to create
129 // an RtpSender.
130 //
131 // If for some reason you pass in MEDIA_TYPE_DATA, returns an empty structure.
132 virtual RtpCapabilities GetRtpSenderCapabilities(
133 cricket::MediaType kind) const = 0;
134
135 // Creates an RTP sender with |track|. Will not start sending until Send is
136 // called.
137 //
138 // |track| and |transport| must not be null.
139 virtual RTCErrorOr<std::unique_ptr<OrtcRtpSenderInterface>> CreateRtpSender(
140 rtc::scoped_refptr<MediaStreamTrackInterface> track,
141 RtpTransportInterface* transport) = 0;
142
143 // Same as above, but allows creating the sender without a track.
144 //
145 // |kind| must be MEDIA_TYPE_AUDIO or MEDIA_TYPE_VIDEO.
146 virtual RTCErrorOr<std::unique_ptr<OrtcRtpSenderInterface>> CreateRtpSender(
147 cricket::MediaType kind,
148 RtpTransportInterface* transport) = 0;
149
150 // Returns the capabilities of an RTP receiver of type |kind|. These
151 // capabilities can be used to determine what RtpParameters to use to create
152 // an RtpReceiver.
153 //
154 // If for some reason you pass in MEDIA_TYPE_DATA, returns an empty structure.
155 virtual RtpCapabilities GetRtpReceiverCapabilities(
156 cricket::MediaType kind) const = 0;
157
158 // Creates an RTP receiver of type |kind|. Will not start receiving media
159 // until Receive is called.
160 //
161 // |kind| must be MEDIA_TYPE_AUDIO or MEDIA_TYPE_VIDEO.
162 //
163 // |transport| must not be null.
164 virtual RTCErrorOr<std::unique_ptr<OrtcRtpReceiverInterface>>
165 CreateRtpReceiver(cricket::MediaType kind,
166 RtpTransportInterface* transport) = 0;
167
168 // Create a UDP transport with IP address family |family|, using a port
169 // within the specified range.
170 //
171 // |family| must be AF_INET or AF_INET6.
172 //
173 // |min_port|/|max_port| values of 0 indicate no range restriction.
174 //
175 // Returns an error if the transport wasn't successfully created.
176 virtual RTCErrorOr<std::unique_ptr<UdpTransportInterface>>
177 CreateUdpTransport(int family, uint16_t min_port, uint16_t max_port) = 0;
178
179 // Method for convenience that has no port range restrictions.
180 RTCErrorOr<std::unique_ptr<UdpTransportInterface>> CreateUdpTransport(
181 int family) {
182 return CreateUdpTransport(family, 0, 0);
183 }
184
185 // NOTE: The methods below to create tracks/sources return scoped_refptrs
186 // rather than unique_ptrs, because these interfaces are also used with
187 // PeerConnection, where everything is ref-counted.
188
189 // Creates a audio source representing the default microphone input.
190 // |options| decides audio processing settings.
191 virtual rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
192 const cricket::AudioOptions& options) = 0;
193
194 // Version of the above method that uses default options.
195 rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource() {
196 return CreateAudioSource(cricket::AudioOptions());
197 }
198
199 // Creates a video source object wrapping and taking ownership of |capturer|.
200 //
201 // |constraints| can be used for selection of resolution and frame rate, and
202 // may be null if no constraints are desired.
203 virtual rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
204 std::unique_ptr<cricket::VideoCapturer> capturer,
205 const MediaConstraintsInterface* constraints) = 0;
206
207 // Version of the above method that omits |constraints|.
208 rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
209 std::unique_ptr<cricket::VideoCapturer> capturer) {
210 return CreateVideoSource(std::move(capturer), nullptr);
211 }
212
213 // Creates a new local video track wrapping |source|. The same |source| can
214 // be used in several tracks.
215 virtual rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
216 const std::string& id,
217 VideoTrackSourceInterface* source) = 0;
218
219 // Creates an new local audio track wrapping |source|.
220 virtual rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
221 const std::string& id,
222 AudioSourceInterface* source) = 0;
223 };
224
225 } // namespace webrtc
226
227 #endif // WEBRTC_API_ORTC_ORTCFACTORYINTERFACE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698