zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 1 | /* |
| 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 Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #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 Jedvert | 58b0316 | 2017-09-15 19:02:47 +0200 | [diff] [blame] | 14 | #include "api/video_codecs/video_decoder_factory.h" |
| 15 | #include "api/video_codecs/video_encoder_factory.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "call/callfactoryinterface.h" |
| 17 | #include "logging/rtc_event_log/rtc_event_log_factory_interface.h" |
| 18 | #include "media/engine/webrtcmediaengine.h" |
Magnus Jedvert | 58b0316 | 2017-09-15 19:02:47 +0200 | [diff] [blame] | 19 | #include "modules/audio_device/include/audio_device.h" |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #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" |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 24 | |
| 25 | namespace webrtc { |
| 26 | |
| 27 | rtc::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 | |
| 38 | rtc::scoped_refptr<PeerConnectionFactoryInterface> |
| 39 | CreatePeerConnectionFactory() { |
| 40 | return CreatePeerConnectionFactory(CreateBuiltinAudioEncoderFactory(), |
| 41 | CreateBuiltinAudioDecoderFactory()); |
| 42 | } |
| 43 | |
| 44 | // Note: all the other CreatePeerConnectionFactory variants just end up calling |
| 45 | // this, ultimately. |
peah | 17675ce | 2017-06-30 07:24:04 -0700 | [diff] [blame] | 46 | rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory( |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 47 | 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, |
peah | 17675ce | 2017-06-30 07:24:04 -0700 | [diff] [blame] | 55 | 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 | |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 62 | std::unique_ptr<cricket::MediaEngineInterface> media_engine( |
| 63 | cricket::WebRtcMediaEngineFactory::Create( |
| 64 | default_adm, audio_encoder_factory, audio_decoder_factory, |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 65 | video_encoder_factory, video_decoder_factory, audio_mixer, |
peah | 17675ce | 2017-06-30 07:24:04 -0700 | [diff] [blame] | 66 | audio_processing_use)); |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 67 | |
| 68 | std::unique_ptr<CallFactoryInterface> call_factory = CreateCallFactory(); |
| 69 | |
| 70 | std::unique_ptr<RtcEventLogFactoryInterface> event_log_factory = |
| 71 | CreateRtcEventLogFactory(); |
| 72 | |
| 73 | return CreateModularPeerConnectionFactory( |
Magnus Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame^] | 74 | network_thread, worker_thread, signaling_thread, std::move(media_engine), |
| 75 | std::move(call_factory), std::move(event_log_factory)); |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 76 | } |
| 77 | |
Magnus Jedvert | 58b0316 | 2017-09-15 19:02:47 +0200 | [diff] [blame] | 78 | rtc::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 Jedvert | 02e7a19 | 2017-09-23 17:21:32 +0200 | [diff] [blame^] | 104 | network_thread, worker_thread, signaling_thread, std::move(media_engine), |
Magnus Jedvert | 835cc0c | 2017-09-23 16:14:25 +0200 | [diff] [blame] | 105 | std::move(call_factory), std::move(event_log_factory)); |
Magnus Jedvert | 58b0316 | 2017-09-15 19:02:47 +0200 | [diff] [blame] | 106 | } |
| 107 | |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 108 | rtc::scoped_refptr<PeerConnectionFactoryInterface> |
| 109 | CreatePeerConnectionFactoryWithAudioMixer( |
| 110 | rtc::Thread* network_thread, |
| 111 | rtc::Thread* worker_thread, |
| 112 | rtc::Thread* signaling_thread, |
| 113 | AudioDeviceModule* default_adm, |
peah | 17675ce | 2017-06-30 07:24:04 -0700 | [diff] [blame] | 114 | 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 | |
| 125 | rtc::scoped_refptr<PeerConnectionFactoryInterface> |
| 126 | CreatePeerConnectionFactoryWithAudioMixer( |
| 127 | rtc::Thread* network_thread, |
| 128 | rtc::Thread* worker_thread, |
| 129 | rtc::Thread* signaling_thread, |
| 130 | AudioDeviceModule* default_adm, |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 131 | 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 | |
| 140 | rtc::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 | |
| 152 | rtc::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 |