blob: cc15ec6396b2a0b0028fa250890b56debce741ed [file] [log] [blame]
Danil Chapovalov082cb562023-10-31 12:51:161/*
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 Chapovalovad491122024-10-14 09:33:3716#include "absl/base/nullability.h"
Danil Chapovalov680f1032023-11-27 16:56:4917#include "api/environment/environment.h"
Danil Chapovalov082cb562023-10-31 12:51:1618#include "api/peer_connection_interface.h"
Dor Henaefed552024-06-18 13:20:3519#include "api/scoped_refptr.h"
20#include "call/call.h"
21#include "call/call_config.h"
Dor Henaefed552024-06-18 13:20:3522#include "media/base/media_engine.h"
Danil Chapovalov082cb562023-10-31 12:51:1623#include "media/engine/webrtc_video_engine.h"
24#include "media/engine/webrtc_voice_engine.h"
25#include "pc/media_factory.h"
26
27namespace webrtc {
28namespace {
29
30using ::cricket::CompositeMediaEngine;
31using ::cricket::MediaEngineInterface;
32using ::cricket::WebRtcVideoEngine;
33using ::cricket::WebRtcVoiceEngine;
34
35class 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 Herre5079e8a2024-07-29 05:54:2042 std::unique_ptr<Call> CreateCall(CallConfig config) override {
Per Kb4c1f2f62024-08-29 14:59:2343 return webrtc::Call::Create(std::move(config));
Danil Chapovalov082cb562023-10-31 12:51:1644 }
45
46 std::unique_ptr<MediaEngineInterface> CreateMediaEngine(
Danil Chapovalov680f1032023-11-27 16:56:4947 const Environment& env,
Danil Chapovalov082cb562023-10-31 12:51:1648 PeerConnectionFactoryDependencies& deps) override {
Danil Chapovalovad491122024-10-14 09:33:3749 absl::Nullable<scoped_refptr<AudioProcessing>> audio_processing =
Danil Chapovalovdc03d872024-10-24 14:16:4750 deps.audio_processing_builder != nullptr
51 ? std::move(deps.audio_processing_builder)->Build(env)
Danil Chapovalovc63e43f2024-11-18 11:57:2652#pragma clang diagnostic push
53#pragma clang diagnostic ignored "-Wdeprecated-declarations"
Danil Chapovalovad491122024-10-14 09:33:3754 : std::move(deps.audio_processing);
Danil Chapovalovc63e43f2024-11-18 11:57:2655#pragma clang diagnostic pop
Danil Chapovalovad491122024-10-14 09:33:3756
Danil Chapovalov082cb562023-10-31 12:51:1657 auto audio_engine = std::make_unique<WebRtcVoiceEngine>(
Danil Chapovalov680f1032023-11-27 16:56:4958 &env.task_queue_factory(), deps.adm.get(),
Danil Chapovalov082cb562023-10-31 12:51:1659 std::move(deps.audio_encoder_factory),
60 std::move(deps.audio_decoder_factory), std::move(deps.audio_mixer),
Danil Chapovalovad491122024-10-14 09:33:3761 std::move(audio_processing), std::move(deps.audio_frame_processor),
Danil Chapovalov680f1032023-11-27 16:56:4962 env.field_trials());
Danil Chapovalov082cb562023-10-31 12:51:1663 auto video_engine = std::make_unique<WebRtcVideoEngine>(
64 std::move(deps.video_encoder_factory),
Danil Chapovalov680f1032023-11-27 16:56:4965 std::move(deps.video_decoder_factory), env.field_trials());
66 return std::make_unique<CompositeMediaEngine>(std::move(audio_engine),
Danil Chapovalov082cb562023-10-31 12:51:1667 std::move(video_engine));
68 }
69};
70
71} // namespace
72
73void EnableMedia(PeerConnectionFactoryDependencies& deps) {
Danil Chapovalov4fd1cc72023-11-03 11:51:3174 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 Chapovalov082cb562023-10-31 12:51:1679 deps.media_factory = std::make_unique<MediaFactoryImpl>();
80}
81
82} // namespace webrtc