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 | |
| 11 | #include "webrtc/api/audio_codecs/builtin_audio_decoder_factory.h" |
| 12 | #include "webrtc/api/audio_codecs/builtin_audio_encoder_factory.h" |
| 13 | #include "webrtc/api/peerconnectioninterface.h" |
| 14 | #include "webrtc/base/bind.h" |
| 15 | #include "webrtc/base/scoped_ref_ptr.h" |
| 16 | #include "webrtc/base/thread.h" |
| 17 | #include "webrtc/call/callfactoryinterface.h" |
| 18 | #include "webrtc/logging/rtc_event_log/rtc_event_log_factory_interface.h" |
| 19 | #include "webrtc/media/engine/webrtcmediaengine.h" |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 20 | #include "webrtc/modules/audio_processing/include/audio_processing.h" |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 21 | |
| 22 | namespace webrtc { |
| 23 | |
| 24 | rtc::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 | |
| 35 | rtc::scoped_refptr<PeerConnectionFactoryInterface> |
| 36 | CreatePeerConnectionFactory() { |
| 37 | return CreatePeerConnectionFactory(CreateBuiltinAudioEncoderFactory(), |
| 38 | CreateBuiltinAudioDecoderFactory()); |
| 39 | } |
| 40 | |
| 41 | // Note: all the other CreatePeerConnectionFactory variants just end up calling |
| 42 | // this, ultimately. |
peah | 17675ce | 2017-06-30 07:24:04 -0700 | [diff] [blame^] | 43 | rtc::scoped_refptr<PeerConnectionFactoryInterface> CreatePeerConnectionFactory( |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 44 | 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, |
peah | 17675ce | 2017-06-30 07:24:04 -0700 | [diff] [blame^] | 52 | 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 | |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 59 | std::unique_ptr<cricket::MediaEngineInterface> media_engine( |
| 60 | cricket::WebRtcMediaEngineFactory::Create( |
| 61 | default_adm, audio_encoder_factory, audio_decoder_factory, |
peah | a9cc40b | 2017-06-29 08:32:09 -0700 | [diff] [blame] | 62 | video_encoder_factory, video_decoder_factory, audio_mixer, |
peah | 17675ce | 2017-06-30 07:24:04 -0700 | [diff] [blame^] | 63 | audio_processing_use)); |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 64 | |
| 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 | |
| 77 | rtc::scoped_refptr<PeerConnectionFactoryInterface> |
| 78 | CreatePeerConnectionFactoryWithAudioMixer( |
| 79 | rtc::Thread* network_thread, |
| 80 | rtc::Thread* worker_thread, |
| 81 | rtc::Thread* signaling_thread, |
| 82 | AudioDeviceModule* default_adm, |
peah | 17675ce | 2017-06-30 07:24:04 -0700 | [diff] [blame^] | 83 | 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 | |
| 94 | rtc::scoped_refptr<PeerConnectionFactoryInterface> |
| 95 | CreatePeerConnectionFactoryWithAudioMixer( |
| 96 | rtc::Thread* network_thread, |
| 97 | rtc::Thread* worker_thread, |
| 98 | rtc::Thread* signaling_thread, |
| 99 | AudioDeviceModule* default_adm, |
zhihuang | 38ede13 | 2017-06-15 12:52:32 -0700 | [diff] [blame] | 100 | 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 | |
| 109 | rtc::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 | |
| 121 | rtc::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 |