Danil Chapovalov | c63120a | 2023-11-03 10:32:24 | [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 "pc/test/enable_fake_media.h" |
| 12 | |
| 13 | #include <memory> |
| 14 | #include <utility> |
| 15 | |
| 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 | c63120a | 2023-11-03 10:32:24 | [diff] [blame] | 18 | #include "api/peer_connection_interface.h" |
| 19 | #include "call/call.h" |
| 20 | #include "call/call_config.h" |
| 21 | #include "media/base/fake_media_engine.h" |
| 22 | #include "pc/media_factory.h" |
| 23 | #include "rtc_base/checks.h" |
| 24 | |
| 25 | namespace webrtc { |
| 26 | |
| 27 | using ::cricket::FakeMediaEngine; |
| 28 | using ::cricket::MediaEngineInterface; |
| 29 | |
| 30 | void EnableFakeMedia( |
| 31 | PeerConnectionFactoryDependencies& deps, |
| 32 | absl::Nonnull<std::unique_ptr<FakeMediaEngine>> fake_media_engine) { |
| 33 | class FakeMediaFactory : public MediaFactory { |
| 34 | public: |
| 35 | explicit FakeMediaFactory( |
| 36 | absl::Nonnull<std::unique_ptr<FakeMediaEngine>> fake) |
| 37 | : fake_(std::move(fake)) {} |
| 38 | |
Tony Herre | 5079e8a | 2024-07-29 05:54:20 | [diff] [blame] | 39 | std::unique_ptr<Call> CreateCall(CallConfig config) override { |
| 40 | return Call::Create(std::move(config)); |
Danil Chapovalov | c63120a | 2023-11-03 10:32:24 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | std::unique_ptr<MediaEngineInterface> CreateMediaEngine( |
Danil Chapovalov | 680f103 | 2023-11-27 16:56:49 | [diff] [blame] | 44 | const Environment& /*env*/, |
Danil Chapovalov | c63120a | 2023-11-03 10:32:24 | [diff] [blame] | 45 | PeerConnectionFactoryDependencies& /*dependencies*/) { |
| 46 | RTC_CHECK(fake_ != nullptr) |
| 47 | << "CreateMediaEngine can be called at most once."; |
| 48 | return std::move(fake_); |
| 49 | } |
| 50 | |
| 51 | private: |
| 52 | absl::Nullable<std::unique_ptr<FakeMediaEngine>> fake_; |
| 53 | }; |
| 54 | |
| 55 | deps.media_factory = |
| 56 | std::make_unique<FakeMediaFactory>(std::move(fake_media_engine)); |
| 57 | } |
| 58 | |
| 59 | void EnableFakeMedia(PeerConnectionFactoryDependencies& deps) { |
| 60 | EnableFakeMedia(deps, std::make_unique<cricket::FakeMediaEngine>()); |
| 61 | } |
| 62 | |
| 63 | } // namespace webrtc |