Patrik Höglund | eeb79e9 | 2019-10-17 14:04:07 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 | |
Florent Castelli | f4673f9 | 2024-04-19 19:46:03 | [diff] [blame] | 11 | #include "api/audio/audio_device.h" |
Florent Castelli | 0afde76 | 2024-04-19 15:07:08 | [diff] [blame] | 12 | #include "api/audio/audio_processing.h" |
Danil Chapovalov | 037ab26 | 2024-11-01 10:43:08 | [diff] [blame] | 13 | #include "api/audio/builtin_audio_processing_builder.h" |
Patrik Höglund | eeb79e9 | 2019-10-17 14:04:07 | [diff] [blame] | 14 | #include "api/audio_codecs/audio_decoder_factory_template.h" |
| 15 | #include "api/audio_codecs/audio_encoder_factory_template.h" |
| 16 | #include "api/audio_codecs/opus/audio_decoder_opus.h" |
| 17 | #include "api/audio_codecs/opus/audio_encoder_opus.h" |
Patrik Höglund | eeb79e9 | 2019-10-17 14:04:07 | [diff] [blame] | 18 | #include "api/create_peerconnection_factory.h" |
Danil Chapovalov | b29ff00 | 2023-11-02 18:18:04 | [diff] [blame] | 19 | #include "api/enable_media.h" |
Patrik Höglund | eeb79e9 | 2019-10-17 14:04:07 | [diff] [blame] | 20 | #include "api/peer_connection_interface.h" |
| 21 | #include "api/rtc_event_log/rtc_event_log_factory.h" |
| 22 | #include "api/stats/rtcstats_objects.h" |
| 23 | #include "api/task_queue/default_task_queue_factory.h" |
philipel | 2b00c4e | 2023-03-31 15:20:40 | [diff] [blame] | 24 | #include "api/video_codecs/video_decoder_factory_template.h" |
| 25 | #include "api/video_codecs/video_decoder_factory_template_dav1d_adapter.h" |
| 26 | #include "api/video_codecs/video_decoder_factory_template_libvpx_vp8_adapter.h" |
| 27 | #include "api/video_codecs/video_decoder_factory_template_libvpx_vp9_adapter.h" |
| 28 | #include "api/video_codecs/video_decoder_factory_template_open_h264_adapter.h" |
| 29 | #include "api/video_codecs/video_encoder_factory_template.h" |
| 30 | #include "api/video_codecs/video_encoder_factory_template_libaom_av1_adapter.h" |
| 31 | #include "api/video_codecs/video_encoder_factory_template_libvpx_vp8_adapter.h" |
| 32 | #include "api/video_codecs/video_encoder_factory_template_libvpx_vp9_adapter.h" |
| 33 | #include "api/video_codecs/video_encoder_factory_template_open_h264_adapter.h" |
Patrik Höglund | eeb79e9 | 2019-10-17 14:04:07 | [diff] [blame] | 34 | |
Patrik Höglund | eeb79e9 | 2019-10-17 14:04:07 | [diff] [blame] | 35 | namespace webrtc { |
| 36 | |
Danil Chapovalov | b29ff00 | 2023-11-02 18:18:04 | [diff] [blame] | 37 | void CreateSomeMediaDeps(PeerConnectionFactoryDependencies& media_deps) { |
Patrik Höglund | eeb79e9 | 2019-10-17 14:04:07 | [diff] [blame] | 38 | media_deps.adm = AudioDeviceModule::CreateForTest( |
Danil Chapovalov | b29ff00 | 2023-11-02 18:18:04 | [diff] [blame] | 39 | AudioDeviceModule::kDummyAudio, media_deps.task_queue_factory.get()); |
Patrik Höglund | eeb79e9 | 2019-10-17 14:04:07 | [diff] [blame] | 40 | media_deps.audio_encoder_factory = |
| 41 | webrtc::CreateAudioEncoderFactory<webrtc::AudioEncoderOpus>(); |
| 42 | media_deps.audio_decoder_factory = |
| 43 | webrtc::CreateAudioDecoderFactory<webrtc::AudioDecoderOpus>(); |
philipel | 2b00c4e | 2023-03-31 15:20:40 | [diff] [blame] | 44 | media_deps.video_encoder_factory = |
| 45 | std::make_unique<VideoEncoderFactoryTemplate< |
| 46 | LibvpxVp8EncoderTemplateAdapter, LibvpxVp9EncoderTemplateAdapter, |
| 47 | OpenH264EncoderTemplateAdapter, LibaomAv1EncoderTemplateAdapter>>(); |
| 48 | media_deps.video_decoder_factory = |
| 49 | std::make_unique<VideoDecoderFactoryTemplate< |
| 50 | LibvpxVp8DecoderTemplateAdapter, LibvpxVp9DecoderTemplateAdapter, |
| 51 | OpenH264DecoderTemplateAdapter, Dav1dDecoderTemplateAdapter>>(); |
Danil Chapovalov | 037ab26 | 2024-11-01 10:43:08 | [diff] [blame] | 52 | media_deps.audio_processing_builder = |
| 53 | std::make_unique<BuiltinAudioProcessingBuilder>(); |
Patrik Höglund | eeb79e9 | 2019-10-17 14:04:07 | [diff] [blame] | 54 | } |
| 55 | |
Patrik Höglund | eeb79e9 | 2019-10-17 14:04:07 | [diff] [blame] | 56 | webrtc::PeerConnectionFactoryDependencies CreateSomePcfDeps() { |
| 57 | webrtc::PeerConnectionFactoryDependencies pcf_deps; |
| 58 | pcf_deps.task_queue_factory = CreateDefaultTaskQueueFactory(); |
| 59 | pcf_deps.signaling_thread = rtc::Thread::Current(); |
| 60 | pcf_deps.network_thread = rtc::Thread::Current(); |
| 61 | pcf_deps.worker_thread = rtc::Thread::Current(); |
Danil Chapovalov | 151003d | 2023-12-07 19:01:06 | [diff] [blame] | 62 | pcf_deps.event_log_factory = std::make_unique<webrtc::RtcEventLogFactory>(); |
Danil Chapovalov | b29ff00 | 2023-11-02 18:18:04 | [diff] [blame] | 63 | CreateSomeMediaDeps(pcf_deps); |
| 64 | EnableMedia(pcf_deps); |
Patrik Höglund | eeb79e9 | 2019-10-17 14:04:07 | [diff] [blame] | 65 | return pcf_deps; |
| 66 | } |
| 67 | |
Patrik Höglund | 2167163 | 2019-10-18 06:04:19 | [diff] [blame] | 68 | // NOTE: These "test cases" should pull in as much of WebRTC as possible to make |
| 69 | // sure most commonly used symbols are actually in libwebrtc.a. It's entirely |
| 70 | // possible these tests won't work at all times (maybe crash even), but that's |
| 71 | // fine. |
| 72 | void TestCase1ModularFactory() { |
Patrik Höglund | eeb79e9 | 2019-10-17 14:04:07 | [diff] [blame] | 73 | auto pcf_deps = CreateSomePcfDeps(); |
| 74 | auto peer_connection_factory = |
| 75 | webrtc::CreateModularPeerConnectionFactory(std::move(pcf_deps)); |
| 76 | webrtc::PeerConnectionInterface::RTCConfiguration rtc_config; |
Harald Alvestrand | f33f7a2 | 2021-05-09 14:58:57 | [diff] [blame] | 77 | auto result = peer_connection_factory->CreatePeerConnectionOrError( |
| 78 | rtc_config, PeerConnectionDependencies(nullptr)); |
| 79 | // Creation will fail because of null observer, but that's OK. |
| 80 | printf("peer_connection creation=%s\n", result.ok() ? "succeeded" : "failed"); |
Patrik Höglund | eeb79e9 | 2019-10-17 14:04:07 | [diff] [blame] | 81 | } |
| 82 | |
Patrik Höglund | 2167163 | 2019-10-18 06:04:19 | [diff] [blame] | 83 | void TestCase2RegularFactory() { |
Danil Chapovalov | b29ff00 | 2023-11-02 18:18:04 | [diff] [blame] | 84 | PeerConnectionFactoryDependencies media_deps; |
| 85 | media_deps.task_queue_factory = CreateDefaultTaskQueueFactory(); |
| 86 | CreateSomeMediaDeps(media_deps); |
Patrik Höglund | eeb79e9 | 2019-10-17 14:04:07 | [diff] [blame] | 87 | |
| 88 | auto peer_connection_factory = webrtc::CreatePeerConnectionFactory( |
| 89 | rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(), |
| 90 | std::move(media_deps.adm), std::move(media_deps.audio_encoder_factory), |
| 91 | std::move(media_deps.audio_decoder_factory), |
| 92 | std::move(media_deps.video_encoder_factory), |
| 93 | std::move(media_deps.video_decoder_factory), nullptr, nullptr); |
Patrik Höglund | 2167163 | 2019-10-18 06:04:19 | [diff] [blame] | 94 | webrtc::PeerConnectionInterface::RTCConfiguration rtc_config; |
Harald Alvestrand | f33f7a2 | 2021-05-09 14:58:57 | [diff] [blame] | 95 | auto result = peer_connection_factory->CreatePeerConnectionOrError( |
| 96 | rtc_config, PeerConnectionDependencies(nullptr)); |
| 97 | // Creation will fail because of null observer, but that's OK. |
| 98 | printf("peer_connection creation=%s\n", result.ok() ? "succeeded" : "failed"); |
Patrik Höglund | eeb79e9 | 2019-10-17 14:04:07 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | } // namespace webrtc |
Patrik Höglund | 2167163 | 2019-10-18 06:04:19 | [diff] [blame] | 102 | |
| 103 | int main(int argc, char** argv) { |
| 104 | webrtc::TestCase1ModularFactory(); |
| 105 | webrtc::TestCase2RegularFactory(); |
| 106 | return 0; |
| 107 | } |