blob: 89f1ee009b24bd9df6dff2bed338ce122005ee4c [file] [log] [blame]
deadbeefe814a0d2017-02-25 18:15:09 -08001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef ORTC_ORTCFACTORY_H_
12#define ORTC_ORTCFACTORY_H_
deadbeefe814a0d2017-02-25 18:15:09 -080013
14#include <memory>
15#include <string>
16
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#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"
deadbeefe814a0d2017-02-25 18:15:09 -080023
24namespace webrtc {
25
26// Implementation of OrtcFactoryInterface.
27//
28// See ortcfactoryinterface.h for documentation.
29class 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(
sprangdb2a9fc2017-08-09 06:42:32 -070047 const RtpTransportParameters& parameters,
deadbeefe814a0d2017-02-25 18:15:09 -080048 PacketTransportInterface* rtp,
49 PacketTransportInterface* rtcp,
50 RtpTransportControllerInterface* transport_controller) override;
51
zhihuangd3501ad2017-03-03 14:39:06 -080052 RTCErrorOr<std::unique_ptr<SrtpTransportInterface>> CreateSrtpTransport(
sprangdb2a9fc2017-08-09 06:42:32 -070053 const RtpTransportParameters& parameters,
zhihuangd3501ad2017-03-03 14:39:06 -080054 PacketTransportInterface* rtp,
55 PacketTransportInterface* rtcp,
56 RtpTransportControllerInterface* transport_controller) override;
57
deadbeefe814a0d2017-02-25 18:15:09 -080058 RtpCapabilities GetRtpSenderCapabilities(
59 cricket::MediaType kind) const override;
60
61 RTCErrorOr<std::unique_ptr<OrtcRtpSenderInterface>> CreateRtpSender(
62 rtc::scoped_refptr<MediaStreamTrackInterface> track,
63 RtpTransportInterface* transport) override;
64
65 RTCErrorOr<std::unique_ptr<OrtcRtpSenderInterface>> CreateRtpSender(
66 cricket::MediaType kind,
67 RtpTransportInterface* transport) override;
68
69 RtpCapabilities GetRtpReceiverCapabilities(
70 cricket::MediaType kind) const override;
71
72 RTCErrorOr<std::unique_ptr<OrtcRtpReceiverInterface>> CreateRtpReceiver(
73 cricket::MediaType kind,
74 RtpTransportInterface* transport) override;
75
76 RTCErrorOr<std::unique_ptr<UdpTransportInterface>>
77 CreateUdpTransport(int family, uint16_t min_port, uint16_t max_port) override;
78
79 rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
80 const cricket::AudioOptions& options) override;
81
82 rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
83 std::unique_ptr<cricket::VideoCapturer> capturer,
84 const MediaConstraintsInterface* constraints) override;
85
86 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
87 const std::string& id,
88 VideoTrackSourceInterface* source) override;
89
90 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
91 const std::string& id,
92 AudioSourceInterface* source) override;
93
94 rtc::Thread* network_thread() { return network_thread_; }
95 rtc::Thread* worker_thread() { return worker_thread_.get(); }
96 rtc::Thread* signaling_thread() { return signaling_thread_; }
97
98 private:
99 // Should only be called by OrtcFactoryInterface::Create.
100 OrtcFactory(rtc::Thread* network_thread,
101 rtc::Thread* signaling_thread,
102 rtc::NetworkManager* network_manager,
103 rtc::PacketSocketFactory* socket_factory,
104 AudioDeviceModule* adm);
105
sprangdb2a9fc2017-08-09 06:42:32 -0700106 RTCErrorOr<std::unique_ptr<RtpTransportControllerInterface>>
107 CreateRtpTransportController(const RtpTransportParameters& parameters);
108
deadbeefe814a0d2017-02-25 18:15:09 -0800109 // Thread::Invoke doesn't support move-only arguments, so we need to remove
110 // the unique_ptr wrapper from media_engine. TODO(deadbeef): Fix this.
111 static RTCErrorOr<std::unique_ptr<OrtcFactoryInterface>> Create_s(
112 rtc::Thread* network_thread,
113 rtc::Thread* signaling_thread,
114 rtc::NetworkManager* network_manager,
115 rtc::PacketSocketFactory* socket_factory,
116 AudioDeviceModule* adm,
117 cricket::MediaEngineInterface* media_engine);
118
119 // Performs initialization that can fail. Called by factory method after
120 // construction, and if it fails, no object is returned.
121 RTCError Initialize(
122 std::unique_ptr<cricket::MediaEngineInterface> media_engine);
123 std::unique_ptr<cricket::MediaEngineInterface> CreateMediaEngine_w();
124
125 // Threads and networking objects.
126 rtc::Thread* network_thread_;
127 rtc::Thread* signaling_thread_;
128 rtc::NetworkManager* network_manager_;
129 rtc::PacketSocketFactory* socket_factory_;
130 AudioDeviceModule* adm_;
131 // If we created/own the objects above, these will be non-null and thus will
132 // be released automatically upon destruction.
133 std::unique_ptr<rtc::Thread> owned_network_thread_;
134 bool wraps_signaling_thread_ = false;
135 std::unique_ptr<rtc::NetworkManager> owned_network_manager_;
136 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_;
137 // We always own the worker thread.
138 std::unique_ptr<rtc::Thread> worker_thread_;
139 // Media-releated objects.
140 std::unique_ptr<RtcEventLog> null_event_log_;
ossueb1fde42017-05-02 06:46:30 -0700141 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory_;
deadbeefe814a0d2017-02-25 18:15:09 -0800142 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory_;
143 std::unique_ptr<cricket::ChannelManager> channel_manager_;
144 // Default CNAME to use for RtpTransports if none is passed in.
145 std::string default_cname_;
146
147 friend class OrtcFactoryInterface;
148
149 RTC_DISALLOW_COPY_AND_ASSIGN(OrtcFactory);
150};
151
152} // namespace webrtc
153
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200154#endif // ORTC_ORTCFACTORY_H_