Danil Chapovalov | 082cb56 | 2023-10-31 12:51:16 | [diff] [blame] | 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 | |
Danil Chapovalov | ad49112 | 2024-10-14 09:33:37 | [diff] [blame] | 16 | #include "absl/base/nullability.h" |
Danil Chapovalov | 680f103 | 2023-11-27 16:56:49 | [diff] [blame] | 17 | #include "api/environment/environment.h" |
Danil Chapovalov | 082cb56 | 2023-10-31 12:51:16 | [diff] [blame] | 18 | #include "api/peer_connection_interface.h" |
Dor Hen | aefed55 | 2024-06-18 13:20:35 | [diff] [blame] | 19 | #include "api/scoped_refptr.h" |
| 20 | #include "call/call.h" |
| 21 | #include "call/call_config.h" |
Dor Hen | aefed55 | 2024-06-18 13:20:35 | [diff] [blame] | 22 | #include "media/base/media_engine.h" |
Danil Chapovalov | 082cb56 | 2023-10-31 12:51:16 | [diff] [blame] | 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 | using ::cricket::CompositeMediaEngine; |
| 31 | using ::cricket::MediaEngineInterface; |
| 32 | using ::cricket::WebRtcVideoEngine; |
| 33 | using ::cricket::WebRtcVoiceEngine; |
| 34 | |
| 35 | class MediaFactoryImpl : public MediaFactory { |
| 36 | public: |
| 37 | MediaFactoryImpl() = default; |
| 38 | MediaFactoryImpl(const MediaFactoryImpl&) = delete; |
| 39 | MediaFactoryImpl& operator=(const MediaFactoryImpl&) = delete; |
| 40 | ~MediaFactoryImpl() override = default; |
| 41 | |
Tony Herre | 5079e8a | 2024-07-29 05:54:20 | [diff] [blame] | 42 | std::unique_ptr<Call> CreateCall(CallConfig config) override { |
Per K | b4c1f2f6 | 2024-08-29 14:59:23 | [diff] [blame] | 43 | return webrtc::Call::Create(std::move(config)); |
Danil Chapovalov | 082cb56 | 2023-10-31 12:51:16 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | std::unique_ptr<MediaEngineInterface> CreateMediaEngine( |
Danil Chapovalov | 680f103 | 2023-11-27 16:56:49 | [diff] [blame] | 47 | const Environment& env, |
Danil Chapovalov | 082cb56 | 2023-10-31 12:51:16 | [diff] [blame] | 48 | PeerConnectionFactoryDependencies& deps) override { |
Danil Chapovalov | ad49112 | 2024-10-14 09:33:37 | [diff] [blame] | 49 | absl::Nullable<scoped_refptr<AudioProcessing>> audio_processing = |
Danil Chapovalov | dc03d87 | 2024-10-24 14:16:47 | [diff] [blame] | 50 | deps.audio_processing_builder != nullptr |
| 51 | ? std::move(deps.audio_processing_builder)->Build(env) |
Danil Chapovalov | c63e43f | 2024-11-18 11:57:26 | [diff] [blame] | 52 | #pragma clang diagnostic push |
| 53 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" |
Danil Chapovalov | ad49112 | 2024-10-14 09:33:37 | [diff] [blame] | 54 | : std::move(deps.audio_processing); |
Danil Chapovalov | c63e43f | 2024-11-18 11:57:26 | [diff] [blame] | 55 | #pragma clang diagnostic pop |
Danil Chapovalov | ad49112 | 2024-10-14 09:33:37 | [diff] [blame] | 56 | |
Danil Chapovalov | 082cb56 | 2023-10-31 12:51:16 | [diff] [blame] | 57 | auto audio_engine = std::make_unique<WebRtcVoiceEngine>( |
Danil Chapovalov | 680f103 | 2023-11-27 16:56:49 | [diff] [blame] | 58 | &env.task_queue_factory(), deps.adm.get(), |
Danil Chapovalov | 082cb56 | 2023-10-31 12:51:16 | [diff] [blame] | 59 | std::move(deps.audio_encoder_factory), |
| 60 | std::move(deps.audio_decoder_factory), std::move(deps.audio_mixer), |
Danil Chapovalov | ad49112 | 2024-10-14 09:33:37 | [diff] [blame] | 61 | std::move(audio_processing), std::move(deps.audio_frame_processor), |
Danil Chapovalov | 680f103 | 2023-11-27 16:56:49 | [diff] [blame] | 62 | env.field_trials()); |
Danil Chapovalov | 082cb56 | 2023-10-31 12:51:16 | [diff] [blame] | 63 | auto video_engine = std::make_unique<WebRtcVideoEngine>( |
| 64 | std::move(deps.video_encoder_factory), |
Danil Chapovalov | 680f103 | 2023-11-27 16:56:49 | [diff] [blame] | 65 | std::move(deps.video_decoder_factory), env.field_trials()); |
| 66 | return std::make_unique<CompositeMediaEngine>(std::move(audio_engine), |
Danil Chapovalov | 082cb56 | 2023-10-31 12:51:16 | [diff] [blame] | 67 | std::move(video_engine)); |
| 68 | } |
| 69 | }; |
| 70 | |
| 71 | } // namespace |
| 72 | |
| 73 | void EnableMedia(PeerConnectionFactoryDependencies& deps) { |
Danil Chapovalov | 4fd1cc7 | 2023-11-03 11:51:31 | [diff] [blame] | 74 | if (deps.media_factory != nullptr) { |
| 75 | // Do nothing if media is already enabled. Overwriting media_factory can be |
| 76 | // harmful when a different (e.g. test-only) implementation is used. |
| 77 | return; |
| 78 | } |
Danil Chapovalov | 082cb56 | 2023-10-31 12:51:16 | [diff] [blame] | 79 | deps.media_factory = std::make_unique<MediaFactoryImpl>(); |
| 80 | } |
| 81 | |
| 82 | } // namespace webrtc |