blob: 8d67a3fa95a6e022a5950192e48f129ab5e25f26 [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
11#ifndef WEBRTC_ORTC_ORTCFACTORY_H_
12#define WEBRTC_ORTC_ORTCFACTORY_H_
13
14#include <memory>
15#include <string>
16
17#include "webrtc/api/ortc/ortcfactoryinterface.h"
18#include "webrtc/base/constructormagic.h"
19#include "webrtc/base/scoped_ref_ptr.h"
20#include "webrtc/media/base/mediaengine.h"
21#include "webrtc/media/engine/webrtcmediaengine.h"
22#include "webrtc/pc/channelmanager.h"
23
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(
47 const RtcpParameters& rtcp_parameters,
48 PacketTransportInterface* rtp,
49 PacketTransportInterface* rtcp,
50 RtpTransportControllerInterface* transport_controller) override;
51
zhihuangd3501ad2017-03-03 14:39:06 -080052 RTCErrorOr<std::unique_ptr<SrtpTransportInterface>> CreateSrtpTransport(
53 const RtcpParameters& rtcp_parameters,
54 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
106 // Thread::Invoke doesn't support move-only arguments, so we need to remove
107 // the unique_ptr wrapper from media_engine. TODO(deadbeef): Fix this.
108 static RTCErrorOr<std::unique_ptr<OrtcFactoryInterface>> Create_s(
109 rtc::Thread* network_thread,
110 rtc::Thread* signaling_thread,
111 rtc::NetworkManager* network_manager,
112 rtc::PacketSocketFactory* socket_factory,
113 AudioDeviceModule* adm,
114 cricket::MediaEngineInterface* media_engine);
115
116 // Performs initialization that can fail. Called by factory method after
117 // construction, and if it fails, no object is returned.
118 RTCError Initialize(
119 std::unique_ptr<cricket::MediaEngineInterface> media_engine);
120 std::unique_ptr<cricket::MediaEngineInterface> CreateMediaEngine_w();
121
122 // Threads and networking objects.
123 rtc::Thread* network_thread_;
124 rtc::Thread* signaling_thread_;
125 rtc::NetworkManager* network_manager_;
126 rtc::PacketSocketFactory* socket_factory_;
127 AudioDeviceModule* adm_;
128 // If we created/own the objects above, these will be non-null and thus will
129 // be released automatically upon destruction.
130 std::unique_ptr<rtc::Thread> owned_network_thread_;
131 bool wraps_signaling_thread_ = false;
132 std::unique_ptr<rtc::NetworkManager> owned_network_manager_;
133 std::unique_ptr<rtc::PacketSocketFactory> owned_socket_factory_;
134 // We always own the worker thread.
135 std::unique_ptr<rtc::Thread> worker_thread_;
136 // Media-releated objects.
137 std::unique_ptr<RtcEventLog> null_event_log_;
138 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory_;
139 std::unique_ptr<cricket::ChannelManager> channel_manager_;
140 // Default CNAME to use for RtpTransports if none is passed in.
141 std::string default_cname_;
142
143 friend class OrtcFactoryInterface;
144
145 RTC_DISALLOW_COPY_AND_ASSIGN(OrtcFactory);
146};
147
148} // namespace webrtc
149
150#endif // WEBRTC_ORTC_ORTCFACTORY_H_