Mirko Bonadei | 3cf8f3e | 2018-11-19 09:17:51 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | #include "api/create_peerconnection_factory.h" |
Mirko Bonadei | 2ff3f49 | 2018-11-22 09:00:13 +0100 | [diff] [blame] | 12 | |
| 13 | #include <memory> |
| 14 | #include <utility> |
| 15 | |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 16 | #include "api/audio/audio_mixer.h" |
| 17 | #include "api/audio_codecs/audio_decoder_factory.h" |
| 18 | #include "api/audio_codecs/audio_encoder_factory.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame^] | 19 | #include "api/call/call_factory_interface.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 20 | #include "api/fec_controller.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame^] | 21 | #include "api/peer_connection_interface.h" |
Yves Gerey | 3e70781 | 2018-11-28 16:47:49 +0100 | [diff] [blame] | 22 | #include "api/transport/network_control.h" |
Mirko Bonadei | 2ff3f49 | 2018-11-22 09:00:13 +0100 | [diff] [blame] | 23 | #include "api/video_codecs/video_decoder_factory.h" |
| 24 | #include "api/video_codecs/video_encoder_factory.h" |
| 25 | #include "logging/rtc_event_log/rtc_event_log_factory.h" |
| 26 | #include "logging/rtc_event_log/rtc_event_log_factory_interface.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame^] | 27 | #include "media/base/media_engine.h" |
| 28 | #include "media/engine/webrtc_media_engine.h" |
Mirko Bonadei | 2ff3f49 | 2018-11-22 09:00:13 +0100 | [diff] [blame] | 29 | #include "modules/audio_device/include/audio_device.h" |
| 30 | #include "modules/audio_processing/include/audio_processing.h" |
Mirko Bonadei | 2ff3f49 | 2018-11-22 09:00:13 +0100 | [diff] [blame] | 31 | #include "rtc_base/scoped_ref_ptr.h" |
| 32 | #include "rtc_base/thread.h" |
| 33 | |
| 34 | namespace webrtc { |
| 35 | |
| 36 | #if defined(USE_BUILTIN_SW_CODECS) |
| 37 | rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory( |
| 38 | rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory, |
| 39 | rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory) { |
| 40 | return CreatePeerConnectionFactoryWithAudioMixer( |
| 41 | nullptr /*network_thread*/, nullptr /*worker_thread*/, |
| 42 | nullptr /*signaling_thread*/, nullptr /*default_adm*/, |
| 43 | audio_encoder_factory, audio_decoder_factory, |
| 44 | nullptr /*video_encoder_factory*/, nullptr /*video_decoder_factory*/, |
| 45 | nullptr /*audio_mixer*/); |
| 46 | } |
| 47 | |
| 48 | // Note: all the other CreatePeerConnectionFactory variants just end up calling |
| 49 | // this, ultimately. |
| 50 | rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory( |
| 51 | rtc::Thread* network_thread, |
| 52 | rtc::Thread* worker_thread, |
| 53 | rtc::Thread* signaling_thread, |
| 54 | AudioDeviceModule* default_adm, |
| 55 | rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory, |
| 56 | rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory, |
| 57 | cricket::WebRtcVideoEncoderFactory* video_encoder_factory, |
| 58 | cricket::WebRtcVideoDecoderFactory* video_decoder_factory, |
| 59 | rtc::scoped_refptr<AudioMixer> audio_mixer, |
| 60 | rtc::scoped_refptr<AudioProcessing> audio_processing) { |
| 61 | rtc::scoped_refptr<AudioProcessing> audio_processing_use = audio_processing; |
| 62 | if (!audio_processing_use) { |
| 63 | audio_processing_use = AudioProcessingBuilder().Create(); |
| 64 | } |
| 65 | |
| 66 | std::unique_ptr<cricket::MediaEngineInterface> media_engine( |
| 67 | cricket::WebRtcMediaEngineFactory::Create( |
| 68 | default_adm, audio_encoder_factory, audio_decoder_factory, |
| 69 | video_encoder_factory, video_decoder_factory, audio_mixer, |
| 70 | audio_processing_use)); |
| 71 | |
| 72 | std::unique_ptr<CallFactoryInterface> call_factory = CreateCallFactory(); |
| 73 | |
| 74 | std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory = |
| 75 | CreateRtcEventLogFactory(); |
| 76 | |
| 77 | return CreateModularPeerConnectionFactory( |
| 78 | network_thread, worker_thread, signaling_thread, std::move(media_engine), |
| 79 | std::move(call_factory), std::move(event_log_factory)); |
| 80 | } |
| 81 | |
| 82 | rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory( |
| 83 | rtc::Thread* network_thread, |
| 84 | rtc::Thread* worker_thread, |
| 85 | rtc::Thread* signaling_thread, |
| 86 | AudioDeviceModule* default_adm, |
| 87 | rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory, |
| 88 | rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory, |
| 89 | cricket::WebRtcVideoEncoderFactory* video_encoder_factory, |
| 90 | cricket::WebRtcVideoDecoderFactory* video_decoder_factory, |
| 91 | rtc::scoped_refptr<AudioMixer> audio_mixer, |
| 92 | rtc::scoped_refptr<AudioProcessing> audio_processing, |
| 93 | std::unique_ptr<FecControllerFactoryInterface> fec_controller_factory, |
| 94 | std::unique_ptr<NetworkControllerFactoryInterface> |
| 95 | network_controller_factory) { |
| 96 | rtc::scoped_refptr<AudioProcessing> audio_processing_use = audio_processing; |
| 97 | if (!audio_processing_use) { |
| 98 | audio_processing_use = AudioProcessingBuilder().Create(); |
| 99 | } |
| 100 | |
| 101 | std::unique_ptr<cricket::MediaEngineInterface> media_engine( |
| 102 | cricket::WebRtcMediaEngineFactory::Create( |
| 103 | default_adm, audio_encoder_factory, audio_decoder_factory, |
| 104 | video_encoder_factory, video_decoder_factory, audio_mixer, |
| 105 | audio_processing_use)); |
| 106 | |
| 107 | std::unique_ptr<CallFactoryInterface> call_factory = CreateCallFactory(); |
| 108 | |
| 109 | std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory = |
| 110 | CreateRtcEventLogFactory(); |
| 111 | |
| 112 | return CreateModularPeerConnectionFactory( |
| 113 | network_thread, worker_thread, signaling_thread, std::move(media_engine), |
| 114 | std::move(call_factory), std::move(event_log_factory), |
| 115 | std::move(fec_controller_factory), std::move(network_controller_factory)); |
| 116 | } |
| 117 | #endif |
| 118 | |
| 119 | rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory( |
| 120 | rtc::Thread* network_thread, |
| 121 | rtc::Thread* worker_thread, |
| 122 | rtc::Thread* signaling_thread, |
| 123 | rtc::scoped_refptr<AudioDeviceModule> default_adm, |
| 124 | rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory, |
| 125 | rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory, |
| 126 | std::unique_ptr<VideoEncoderFactory> video_encoder_factory, |
| 127 | std::unique_ptr<VideoDecoderFactory> video_decoder_factory, |
| 128 | rtc::scoped_refptr<AudioMixer> audio_mixer, |
| 129 | rtc::scoped_refptr<AudioProcessing> audio_processing) { |
| 130 | if (!audio_processing) |
| 131 | audio_processing = AudioProcessingBuilder().Create(); |
| 132 | |
| 133 | std::unique_ptr<cricket::MediaEngineInterface> media_engine = |
| 134 | cricket::WebRtcMediaEngineFactory::Create( |
| 135 | default_adm, audio_encoder_factory, audio_decoder_factory, |
| 136 | std::move(video_encoder_factory), std::move(video_decoder_factory), |
| 137 | audio_mixer, audio_processing); |
| 138 | |
| 139 | std::unique_ptr<CallFactoryInterface> call_factory = CreateCallFactory(); |
| 140 | |
| 141 | std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory = |
| 142 | CreateRtcEventLogFactory(); |
| 143 | PeerConnectionFactoryDependencies dependencies; |
| 144 | dependencies.network_thread = network_thread; |
| 145 | dependencies.worker_thread = worker_thread; |
| 146 | dependencies.signaling_thread = signaling_thread; |
| 147 | dependencies.media_engine = std::move(media_engine); |
| 148 | dependencies.call_factory = std::move(call_factory); |
| 149 | dependencies.event_log_factory = std::move(event_log_factory); |
| 150 | return CreateModularPeerConnectionFactory(std::move(dependencies)); |
| 151 | } |
| 152 | |
| 153 | #if defined(USE_BUILTIN_SW_CODECS) |
| 154 | rtc::scoped_refptr<PeerConnectionFactoryInterface> |
| 155 | CreatePeerConnectionFactoryWithAudioMixer( |
| 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 | rtc::scoped_refptr<AudioMixer> audio_mixer) { |
| 165 | return CreatePeerConnectionFactory( |
| 166 | network_thread, worker_thread, signaling_thread, default_adm, |
| 167 | audio_encoder_factory, audio_decoder_factory, video_encoder_factory, |
| 168 | video_decoder_factory, audio_mixer, nullptr); |
| 169 | } |
| 170 | |
| 171 | rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory( |
| 172 | rtc::Thread* network_thread, |
| 173 | rtc::Thread* worker_thread, |
| 174 | rtc::Thread* signaling_thread, |
| 175 | AudioDeviceModule* default_adm, |
| 176 | rtc::scoped_refptr<AudioEncoderFactory> audio_encoder_factory, |
| 177 | rtc::scoped_refptr<AudioDecoderFactory> audio_decoder_factory, |
| 178 | cricket::WebRtcVideoEncoderFactory* video_encoder_factory, |
| 179 | cricket::WebRtcVideoDecoderFactory* video_decoder_factory) { |
| 180 | return CreatePeerConnectionFactoryWithAudioMixer( |
| 181 | network_thread, worker_thread, signaling_thread, default_adm, |
| 182 | audio_encoder_factory, audio_decoder_factory, video_encoder_factory, |
| 183 | video_decoder_factory, nullptr); |
| 184 | } |
| 185 | #endif |
| 186 | |
| 187 | } // namespace webrtc |