| 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/enable_media.h" |
| 12 |
| 13 | #include <memory> |
| 14 | #include <utility> |
| 15 |
| 16 | #include "api/environment/environment.h" |
| 17 | #include "api/peer_connection_interface.h" |
| 18 | #include "call/create_call.h" |
| 19 | #include "media/engine/webrtc_media_engine.h" |
| 20 | #include "media/engine/webrtc_video_engine.h" |
| 21 | #include "media/engine/webrtc_voice_engine.h" |
| 22 | #include "pc/media_factory.h" |
| 23 |
| 24 | namespace webrtc { |
| 25 | namespace { |
| 26 |
| 27 | using ::cricket::CompositeMediaEngine; |
| 28 | using ::cricket::MediaEngineInterface; |
| 29 | using ::cricket::WebRtcVideoEngine; |
| 30 | using ::cricket::WebRtcVoiceEngine; |
| 31 |
| 32 | class MediaFactoryImpl : public MediaFactory { |
| 33 | public: |
| 34 | MediaFactoryImpl() = default; |
| 35 | MediaFactoryImpl(const MediaFactoryImpl&) = delete; |
| 36 | MediaFactoryImpl& operator=(const MediaFactoryImpl&) = delete; |
| 37 | ~MediaFactoryImpl() override = default; |
| 38 |
| 39 | std::unique_ptr<Call> CreateCall(const CallConfig& config) override { |
| 40 | return webrtc::CreateCall(config); |
| 41 | } |
| 42 |
| 43 | std::unique_ptr<MediaEngineInterface> CreateMediaEngine( |
| 44 | const Environment& env, |
| 45 | PeerConnectionFactoryDependencies& deps) override { |
| 46 | auto audio_engine = std::make_unique<WebRtcVoiceEngine>( |
| 47 | &env.task_queue_factory(), deps.adm.get(), |
| 48 | std::move(deps.audio_encoder_factory), |
| 49 | std::move(deps.audio_decoder_factory), std::move(deps.audio_mixer), |
| 50 | std::move(deps.audio_processing), std::move(deps.audio_frame_processor), |
| 51 | env.field_trials()); |
| 52 | auto video_engine = std::make_unique<WebRtcVideoEngine>( |
| 53 | std::move(deps.video_encoder_factory), |
| 54 | std::move(deps.video_decoder_factory), env.field_trials()); |
| 55 | return std::make_unique<CompositeMediaEngine>(std::move(audio_engine), |
| 56 | std::move(video_engine)); |
| 57 | } |
| 58 | }; |
| 59 |
| 60 | } // namespace |
| 61 |
| 62 | void EnableMedia(PeerConnectionFactoryDependencies& deps) { |
| 63 | if (deps.media_factory != nullptr) { |
| 64 | // Do nothing if media is already enabled. Overwriting media_factory can be |
| 65 | // harmful when a different (e.g. test-only) implementation is used. |
| 66 | return; |
| 67 | } |
| 68 | deps.media_factory = std::make_unique<MediaFactoryImpl>(); |
| 69 | } |
| 70 |
| 71 | } // namespace webrtc |
| 72 |