blob: d0a0b5babe8d7d8dd4b34830e4cd0899ee639f11 [file] [log] [blame]
zhihuang38ede132017-06-15 12:52:32 -07001/*
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#include "api/audio_codecs/builtin_audio_decoder_factory.h"
12#include "api/audio_codecs/builtin_audio_encoder_factory.h"
13#include "api/peerconnectioninterface.h"
Magnus Jedvert58b03162017-09-15 19:02:47 +020014#include "api/video_codecs/video_decoder_factory.h"
15#include "api/video_codecs/video_encoder_factory.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020016#include "call/callfactoryinterface.h"
17#include "logging/rtc_event_log/rtc_event_log_factory_interface.h"
18#include "media/engine/webrtcmediaengine.h"
Magnus Jedvert58b03162017-09-15 19:02:47 +020019#include "modules/audio_device/include/audio_device.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "modules/audio_processing/include/audio_processing.h"
21#include "rtc_base/bind.h"
22#include "rtc_base/scoped_ref_ptr.h"
23#include "rtc_base/thread.h"
zhihuang38ede132017-06-15 12:52:32 -070024
25namespace webrtc {
26
27rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
28 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
29 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory) {
30 return CreatePeerConnectionFactoryWithAudioMixer(
31 nullptr /*network_thread*/, nullptr /*worker_thread*/,
32 nullptr /*signaling_thread*/, nullptr /*default_adm*/,
33 audio_encoder_factory, audio_decoder_factory,
34 nullptr /*video_encoder_factory*/, nullptr /*video_decoder_factory*/,
35 nullptr /*audio_mixer*/);
36}
37
38rtc::scoped_refptr<PeerConnectionFactoryInterface>
39CreatePeerConnectionFactory() {
40 return CreatePeerConnectionFactory(CreateBuiltinAudioEncoderFactory(),
41 CreateBuiltinAudioDecoderFactory());
42}
43
44// Note: all the other CreatePeerConnectionFactory variants just end up calling
45// this, ultimately.
peah17675ce2017-06-30 07:24:04 -070046rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
zhihuang38ede132017-06-15 12:52:32 -070047 rtc::Thread* network_thread,
48 rtc::Thread* worker_thread,
49 rtc::Thread* signaling_thread,
50 AudioDeviceModule* default_adm,
51 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
52 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
53 cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
54 cricket::WebRtcVideoDecoderFactory* video_decoder_factory,
peah17675ce2017-06-30 07:24:04 -070055 rtc::scoped_refptr<AudioMixer> audio_mixer,
56 rtc::scoped_refptr<AudioProcessing> audio_processing) {
57 rtc::scoped_refptr<AudioProcessing> audio_processing_use = audio_processing;
58 if (!audio_processing_use) {
59 audio_processing_use = AudioProcessing::Create();
60 }
61
zhihuang38ede132017-06-15 12:52:32 -070062 std::unique_ptr<cricket::MediaEngineInterface> media_engine(
63 cricket::WebRtcMediaEngineFactory::Create(
64 default_adm, audio_encoder_factory, audio_decoder_factory,
peaha9cc40b2017-06-29 08:32:09 -070065 video_encoder_factory, video_decoder_factory, audio_mixer,
peah17675ce2017-06-30 07:24:04 -070066 audio_processing_use));
zhihuang38ede132017-06-15 12:52:32 -070067
68 std::unique_ptr<CallFactoryInterface> call_factory = CreateCallFactory();
69
70 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory =
71 CreateRtcEventLogFactory();
72
73 return CreateModularPeerConnectionFactory(
Magnus Jedvert835cc0c2017-09-23 16:14:25 +020074 network_thread, worker_thread, signaling_thread, video_encoder_factory,
75 video_decoder_factory, std::move(media_engine), std::move(call_factory),
76 std::move(event_log_factory));
zhihuang38ede132017-06-15 12:52:32 -070077}
78
Magnus Jedvert58b03162017-09-15 19:02:47 +020079rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
80 rtc::Thread* network_thread,
81 rtc::Thread* worker_thread,
82 rtc::Thread* signaling_thread,
83 rtc::scoped_refptr<AudioDeviceModule> default_adm,
84 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
85 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
86 std::unique_ptr<VideoEncoderFactory> video_encoder_factory,
87 std::unique_ptr<VideoDecoderFactory> video_decoder_factory,
88 rtc::scoped_refptr<AudioMixer> audio_mixer,
89 rtc::scoped_refptr<AudioProcessing> audio_processing) {
90 if (!audio_processing)
91 audio_processing = AudioProcessing::Create();
92
93 std::unique_ptr<cricket::MediaEngineInterface> media_engine =
94 cricket::WebRtcMediaEngineFactory::Create(
95 default_adm, audio_encoder_factory, audio_decoder_factory,
96 std::move(video_encoder_factory), std::move(video_decoder_factory),
97 audio_mixer, audio_processing);
98
99 std::unique_ptr<CallFactoryInterface> call_factory = CreateCallFactory();
100
101 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory =
102 CreateRtcEventLogFactory();
103
104 return CreateModularPeerConnectionFactory(
Magnus Jedvert835cc0c2017-09-23 16:14:25 +0200105 network_thread, worker_thread, signaling_thread,
Magnus Jedvert58b03162017-09-15 19:02:47 +0200106 nullptr /* external_video_encoder_factory */,
Magnus Jedvert835cc0c2017-09-23 16:14:25 +0200107 nullptr /* external_video_decoder_factory */, std::move(media_engine),
108 std::move(call_factory), std::move(event_log_factory));
Magnus Jedvert58b03162017-09-15 19:02:47 +0200109}
110
zhihuang38ede132017-06-15 12:52:32 -0700111rtc::scoped_refptr<PeerConnectionFactoryInterface>
112CreatePeerConnectionFactoryWithAudioMixer(
113 rtc::Thread* network_thread,
114 rtc::Thread* worker_thread,
115 rtc::Thread* signaling_thread,
116 AudioDeviceModule* default_adm,
peah17675ce2017-06-30 07:24:04 -0700117 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
118 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
119 cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
120 cricket::WebRtcVideoDecoderFactory* video_decoder_factory,
121 rtc::scoped_refptr<AudioMixer> audio_mixer) {
122 return CreatePeerConnectionFactory(
123 network_thread, worker_thread, signaling_thread, default_adm,
124 audio_encoder_factory, audio_decoder_factory, video_encoder_factory,
125 video_decoder_factory, audio_mixer, nullptr);
126}
127
128rtc::scoped_refptr<PeerConnectionFactoryInterface>
129CreatePeerConnectionFactoryWithAudioMixer(
130 rtc::Thread* network_thread,
131 rtc::Thread* worker_thread,
132 rtc::Thread* signaling_thread,
133 AudioDeviceModule* default_adm,
zhihuang38ede132017-06-15 12:52:32 -0700134 cricket::WebRtcVideoEncoderFactory* encoder_factory,
135 cricket::WebRtcVideoDecoderFactory* decoder_factory,
136 rtc::scoped_refptr<AudioMixer> audio_mixer) {
137 return CreatePeerConnectionFactoryWithAudioMixer(
138 network_thread, worker_thread, signaling_thread, default_adm,
139 CreateBuiltinAudioEncoderFactory(), CreateBuiltinAudioDecoderFactory(),
140 encoder_factory, decoder_factory, audio_mixer);
141}
142
143rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
144 rtc::Thread* network_thread,
145 rtc::Thread* worker_thread,
146 rtc::Thread* signaling_thread,
147 AudioDeviceModule* default_adm,
148 cricket::WebRtcVideoEncoderFactory* encoder_factory,
149 cricket::WebRtcVideoDecoderFactory* decoder_factory) {
150 return CreatePeerConnectionFactoryWithAudioMixer(
151 network_thread, worker_thread, signaling_thread, default_adm,
152 encoder_factory, decoder_factory, nullptr);
153}
154
155rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
156 rtc::Thread* network_thread,
157 rtc::Thread* worker_thread,
158 rtc::Thread* signaling_thread,
159 AudioDeviceModule* default_adm,
160 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
161 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
162 cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
163 cricket::WebRtcVideoDecoderFactory* video_decoder_factory) {
164 return CreatePeerConnectionFactoryWithAudioMixer(
165 network_thread, worker_thread, signaling_thread, default_adm,
166 audio_encoder_factory, audio_decoder_factory, video_encoder_factory,
167 video_decoder_factory, nullptr);
168}
169
170} // namespace webrtc