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