blob: 750fcf75863a222fbbc11b748b2008c49dbc029e [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,
Karl Wiberg3e9e5b32017-11-06 05:01:56 +010041 std::unique_ptr<cricket::MediaEngineInterface> media_engine,
42 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
43 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory);
deadbeefe814a0d2017-02-25 18:15:09 -080044
45 RTCErrorOr<std::unique_ptr<RtpTransportControllerInterface>>
46 CreateRtpTransportController() override;
47
48 RTCErrorOr<std::unique_ptr<RtpTransportInterface>> CreateRtpTransport(
sprangdb2a9fc2017-08-09 06:42:32 -070049 const RtpTransportParameters& parameters,
deadbeefe814a0d2017-02-25 18:15:09 -080050 PacketTransportInterface* rtp,
51 PacketTransportInterface* rtcp,
52 RtpTransportControllerInterface* transport_controller) override;
53
zhihuangd3501ad2017-03-03 14:39:06 -080054 RTCErrorOr<std::unique_ptr<SrtpTransportInterface>> CreateSrtpTransport(
sprangdb2a9fc2017-08-09 06:42:32 -070055 const RtpTransportParameters& parameters,
zhihuangd3501ad2017-03-03 14:39:06 -080056 PacketTransportInterface* rtp,
57 PacketTransportInterface* rtcp,
58 RtpTransportControllerInterface* transport_controller) override;
59
deadbeefe814a0d2017-02-25 18:15:09 -080060 RtpCapabilities GetRtpSenderCapabilities(
61 cricket::MediaType kind) const override;
62
63 RTCErrorOr<std::unique_ptr<OrtcRtpSenderInterface>> CreateRtpSender(
64 rtc::scoped_refptr<MediaStreamTrackInterface> track,
65 RtpTransportInterface* transport) override;
66
67 RTCErrorOr<std::unique_ptr<OrtcRtpSenderInterface>> CreateRtpSender(
68 cricket::MediaType kind,
69 RtpTransportInterface* transport) override;
70
71 RtpCapabilities GetRtpReceiverCapabilities(
72 cricket::MediaType kind) const override;
73
74 RTCErrorOr<std::unique_ptr<OrtcRtpReceiverInterface>> CreateRtpReceiver(
75 cricket::MediaType kind,
76 RtpTransportInterface* transport) override;
77
78 RTCErrorOr<std::unique_ptr<UdpTransportInterface>>
79 CreateUdpTransport(int family, uint16_t min_port, uint16_t max_port) override;
80
81 rtc::scoped_refptr<AudioSourceInterface> CreateAudioSource(
82 const cricket::AudioOptions& options) override;
83
84 rtc::scoped_refptr<VideoTrackSourceInterface> CreateVideoSource(
85 std::unique_ptr<cricket::VideoCapturer> capturer,
86 const MediaConstraintsInterface* constraints) override;
87
88 rtc::scoped_refptr<VideoTrackInterface> CreateVideoTrack(
89 const std::string& id,
90 VideoTrackSourceInterface* source) override;
91
92 rtc::scoped_refptr<AudioTrackInterface> CreateAudioTrack(
93 const std::string& id,
94 AudioSourceInterface* source) override;
95
96 rtc::Thread* network_thread() { return network_thread_; }
97 rtc::Thread* worker_thread() { return worker_thread_.get(); }
98 rtc::Thread* signaling_thread() { return signaling_thread_; }
99
100 private:
101 // Should only be called by OrtcFactoryInterface::Create.
102 OrtcFactory(rtc::Thread* network_thread,
103 rtc::Thread* signaling_thread,
104 rtc::NetworkManager* network_manager,
105 rtc::PacketSocketFactory* socket_factory,
Karl Wiberg3e9e5b32017-11-06 05:01:56 +0100106 AudioDeviceModule* adm,
107 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
108 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory);
deadbeefe814a0d2017-02-25 18:15:09 -0800109
sprangdb2a9fc2017-08-09 06:42:32 -0700110 RTCErrorOr<std::unique_ptr<RtpTransportControllerInterface>>
111 CreateRtpTransportController(const RtpTransportParameters& parameters);
112
deadbeefe814a0d2017-02-25 18:15:09 -0800113 // Thread::Invoke doesn't support move-only arguments, so we need to remove
114 // the unique_ptr wrapper from media_engine. TODO(deadbeef): Fix this.
115 static RTCErrorOr<std::unique_ptr<OrtcFactoryInterface>> Create_s(
116 rtc::Thread* network_thread,
117 rtc::Thread* signaling_thread,
118 rtc::NetworkManager* network_manager,
119 rtc::PacketSocketFactory* socket_factory,
120 AudioDeviceModule* adm,
Karl Wiberg3e9e5b32017-11-06 05:01:56 +0100121 cricket::MediaEngineInterface* media_engine,
122 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
123 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory);
deadbeefe814a0d2017-02-25 18:15:09 -0800124
125 // Performs initialization that can fail. Called by factory method after
126 // construction, and if it fails, no object is returned.
127 RTCError Initialize(
128 std::unique_ptr<cricket::MediaEngineInterface> media_engine);
129 std::unique_ptr<cricket::MediaEngineInterface> CreateMediaEngine_w();
130
131 // Threads and networking objects.
132 rtc::Thread* network_thread_;
133 rtc::Thread* signaling_thread_;
134 rtc::NetworkManager* network_manager_;
135 rtc::PacketSocketFactory* socket_factory_;
136 AudioDeviceModule* adm_;
137 // If we created/own the objects above, these will be non-null and thus will
138 // be released automatically upon destruction.
139 std::unique_ptr<rtc::Thread> owned_network_thread_;
140 bool wraps_signaling_thread_ = false;
141 std::unique_ptr<rtc::NetworkManager> owned_network_manager_;
142 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_;
143 // We always own the worker thread.
144 std::unique_ptr<rtc::Thread> worker_thread_;
145 // Media-releated objects.
146 std::unique_ptr<RtcEventLog> null_event_log_;
ossueb1fde42017-05-02 06:46:30 -0700147 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory_;
deadbeefe814a0d2017-02-25 18:15:09 -0800148 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory_;
149 std::unique_ptr<cricket::ChannelManager> channel_manager_;
150 // Default CNAME to use for RtpTransports if none is passed in.
151 std::string default_cname_;
152
153 friend class OrtcFactoryInterface;
154
155 RTC_DISALLOW_COPY_AND_ASSIGN(OrtcFactory);
156};
157
158} // namespace webrtc
159
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200160#endif // ORTC_ORTCFACTORY_H_