blob: 79af61e88bec181fa890484aba6e0a571e79b6ed [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 Jedvert02e7a192017-09-23 17:21:32 +020074 network_thread, worker_thread, signaling_thread, std::move(media_engine),
75 std::move(call_factory), std::move(event_log_factory));
zhihuang38ede132017-06-15 12:52:32 -070076}
77
Magnus Jedvert58b03162017-09-15 19:02:47 +020078rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
79 rtc::Thread* network_thread,
80 rtc::Thread* worker_thread,
81 rtc::Thread* signaling_thread,
82 rtc::scoped_refptr<AudioDeviceModule> default_adm,
83 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
84 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
85 std::unique_ptr<VideoEncoderFactory> video_encoder_factory,
86 std::unique_ptr<VideoDecoderFactory> video_decoder_factory,
87 rtc::scoped_refptr<AudioMixer> audio_mixer,
88 rtc::scoped_refptr<AudioProcessing> audio_processing) {
89 if (!audio_processing)
90 audio_processing = AudioProcessing::Create();
91
92 std::unique_ptr<cricket::MediaEngineInterface> media_engine =
93 cricket::WebRtcMediaEngineFactory::Create(
94 default_adm, audio_encoder_factory, audio_decoder_factory,
95 std::move(video_encoder_factory), std::move(video_decoder_factory),
96 audio_mixer, audio_processing);
97
98 std::unique_ptr<CallFactoryInterface> call_factory = CreateCallFactory();
99
100 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory =
101 CreateRtcEventLogFactory();
102
103 return CreateModularPeerConnectionFactory(
Magnus Jedvert02e7a192017-09-23 17:21:32 +0200104 network_thread, worker_thread, signaling_thread, std::move(media_engine),
Magnus Jedvert835cc0c2017-09-23 16:14:25 +0200105 std::move(call_factory), std::move(event_log_factory));
Magnus Jedvert58b03162017-09-15 19:02:47 +0200106}
107
zhihuang38ede132017-06-15 12:52:32 -0700108rtc::scoped_refptr<PeerConnectionFactoryInterface>
109CreatePeerConnectionFactoryWithAudioMixer(
110 rtc::Thread* network_thread,
111 rtc::Thread* worker_thread,
112 rtc::Thread* signaling_thread,
113 AudioDeviceModule* default_adm,
peah17675ce2017-06-30 07:24:04 -0700114 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
115 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
116 cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
117 cricket::WebRtcVideoDecoderFactory* video_decoder_factory,
118 rtc::scoped_refptr<AudioMixer> audio_mixer) {
119 return CreatePeerConnectionFactory(
120 network_thread, worker_thread, signaling_thread, default_adm,
121 audio_encoder_factory, audio_decoder_factory, video_encoder_factory,
122 video_decoder_factory, audio_mixer, nullptr);
123}
124
125rtc::scoped_refptr<PeerConnectionFactoryInterface>
126CreatePeerConnectionFactoryWithAudioMixer(
127 rtc::Thread* network_thread,
128 rtc::Thread* worker_thread,
129 rtc::Thread* signaling_thread,
130 AudioDeviceModule* default_adm,
zhihuang38ede132017-06-15 12:52:32 -0700131 cricket::WebRtcVideoEncoderFactory* encoder_factory,
132 cricket::WebRtcVideoDecoderFactory* decoder_factory,
133 rtc::scoped_refptr<AudioMixer> audio_mixer) {
134 return CreatePeerConnectionFactoryWithAudioMixer(
135 network_thread, worker_thread, signaling_thread, default_adm,
136 CreateBuiltinAudioEncoderFactory(), CreateBuiltinAudioDecoderFactory(),
137 encoder_factory, decoder_factory, audio_mixer);
138}
139
140rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
141 rtc::Thread* network_thread,
142 rtc::Thread* worker_thread,
143 rtc::Thread* signaling_thread,
144 AudioDeviceModule* default_adm,
145 cricket::WebRtcVideoEncoderFactory* encoder_factory,
146 cricket::WebRtcVideoDecoderFactory* decoder_factory) {
147 return CreatePeerConnectionFactoryWithAudioMixer(
148 network_thread, worker_thread, signaling_thread, default_adm,
149 encoder_factory, decoder_factory, nullptr);
150}
151
152rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
153 rtc::Thread* network_thread,
154 rtc::Thread* worker_thread,
155 rtc::Thread* signaling_thread,
156 AudioDeviceModule* default_adm,
157 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
158 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
159 cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
160 cricket::WebRtcVideoDecoderFactory* video_decoder_factory) {
161 return CreatePeerConnectionFactoryWithAudioMixer(
162 network_thread, worker_thread, signaling_thread, default_adm,
163 audio_encoder_factory, audio_decoder_factory, video_encoder_factory,
164 video_decoder_factory, nullptr);
165}
166
167} // namespace webrtc