blob: a62a7ae6f0508da3c9e30d43ae0cd9c0ffee6aaf [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"
14#include "call/callfactoryinterface.h"
15#include "logging/rtc_event_log/rtc_event_log_factory_interface.h"
16#include "media/engine/webrtcmediaengine.h"
17#include "modules/audio_processing/include/audio_processing.h"
18#include "rtc_base/bind.h"
19#include "rtc_base/scoped_ref_ptr.h"
20#include "rtc_base/thread.h"
zhihuang38ede132017-06-15 12:52:32 -070021
22namespace webrtc {
23
24rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
25 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
26 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory) {
27 return CreatePeerConnectionFactoryWithAudioMixer(
28 nullptr /*network_thread*/, nullptr /*worker_thread*/,
29 nullptr /*signaling_thread*/, nullptr /*default_adm*/,
30 audio_encoder_factory, audio_decoder_factory,
31 nullptr /*video_encoder_factory*/, nullptr /*video_decoder_factory*/,
32 nullptr /*audio_mixer*/);
33}
34
35rtc::scoped_refptr<PeerConnectionFactoryInterface>
36CreatePeerConnectionFactory() {
37 return CreatePeerConnectionFactory(CreateBuiltinAudioEncoderFactory(),
38 CreateBuiltinAudioDecoderFactory());
39}
40
41// Note: all the other CreatePeerConnectionFactory variants just end up calling
42// this, ultimately.
peah17675ce2017-06-30 07:24:04 -070043rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
zhihuang38ede132017-06-15 12:52:32 -070044 rtc::Thread* network_thread,
45 rtc::Thread* worker_thread,
46 rtc::Thread* signaling_thread,
47 AudioDeviceModule* default_adm,
48 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
49 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
50 cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
51 cricket::WebRtcVideoDecoderFactory* video_decoder_factory,
peah17675ce2017-06-30 07:24:04 -070052 rtc::scoped_refptr<AudioMixer> audio_mixer,
53 rtc::scoped_refptr<AudioProcessing> audio_processing) {
54 rtc::scoped_refptr<AudioProcessing> audio_processing_use = audio_processing;
55 if (!audio_processing_use) {
56 audio_processing_use = AudioProcessing::Create();
57 }
58
zhihuang38ede132017-06-15 12:52:32 -070059 std::unique_ptr<cricket::MediaEngineInterface> media_engine(
60 cricket::WebRtcMediaEngineFactory::Create(
61 default_adm, audio_encoder_factory, audio_decoder_factory,
peaha9cc40b2017-06-29 08:32:09 -070062 video_encoder_factory, video_decoder_factory, audio_mixer,
peah17675ce2017-06-30 07:24:04 -070063 audio_processing_use));
zhihuang38ede132017-06-15 12:52:32 -070064
65 std::unique_ptr<CallFactoryInterface> call_factory = CreateCallFactory();
66
67 std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory =
68 CreateRtcEventLogFactory();
69
70 return CreateModularPeerConnectionFactory(
71 network_thread, worker_thread, signaling_thread, default_adm,
72 audio_encoder_factory, audio_decoder_factory, video_encoder_factory,
73 video_decoder_factory, audio_mixer, std::move(media_engine),
74 std::move(call_factory), std::move(event_log_factory));
75}
76
77rtc::scoped_refptr<PeerConnectionFactoryInterface>
78CreatePeerConnectionFactoryWithAudioMixer(
79 rtc::Thread* network_thread,
80 rtc::Thread* worker_thread,
81 rtc::Thread* signaling_thread,
82 AudioDeviceModule* default_adm,
peah17675ce2017-06-30 07:24:04 -070083 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
84 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
85 cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
86 cricket::WebRtcVideoDecoderFactory* video_decoder_factory,
87 rtc::scoped_refptr<AudioMixer> audio_mixer) {
88 return CreatePeerConnectionFactory(
89 network_thread, worker_thread, signaling_thread, default_adm,
90 audio_encoder_factory, audio_decoder_factory, video_encoder_factory,
91 video_decoder_factory, audio_mixer, nullptr);
92}
93
94rtc::scoped_refptr<PeerConnectionFactoryInterface>
95CreatePeerConnectionFactoryWithAudioMixer(
96 rtc::Thread* network_thread,
97 rtc::Thread* worker_thread,
98 rtc::Thread* signaling_thread,
99 AudioDeviceModule* default_adm,
zhihuang38ede132017-06-15 12:52:32 -0700100 cricket::WebRtcVideoEncoderFactory* encoder_factory,
101 cricket::WebRtcVideoDecoderFactory* decoder_factory,
102 rtc::scoped_refptr<AudioMixer> audio_mixer) {
103 return CreatePeerConnectionFactoryWithAudioMixer(
104 network_thread, worker_thread, signaling_thread, default_adm,
105 CreateBuiltinAudioEncoderFactory(), CreateBuiltinAudioDecoderFactory(),
106 encoder_factory, decoder_factory, audio_mixer);
107}
108
109rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
110 rtc::Thread* network_thread,
111 rtc::Thread* worker_thread,
112 rtc::Thread* signaling_thread,
113 AudioDeviceModule* default_adm,
114 cricket::WebRtcVideoEncoderFactory* encoder_factory,
115 cricket::WebRtcVideoDecoderFactory* decoder_factory) {
116 return CreatePeerConnectionFactoryWithAudioMixer(
117 network_thread, worker_thread, signaling_thread, default_adm,
118 encoder_factory, decoder_factory, nullptr);
119}
120
121rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory(
122 rtc::Thread* network_thread,
123 rtc::Thread* worker_thread,
124 rtc::Thread* signaling_thread,
125 AudioDeviceModule* default_adm,
126 rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory,
127 rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory,
128 cricket::WebRtcVideoEncoderFactory* video_encoder_factory,
129 cricket::WebRtcVideoDecoderFactory* video_decoder_factory) {
130 return CreatePeerConnectionFactoryWithAudioMixer(
131 network_thread, worker_thread, signaling_thread, default_adm,
132 audio_encoder_factory, audio_decoder_factory, video_encoder_factory,
133 video_decoder_factory, nullptr);
134}
135
136} // namespace webrtc