blob: 37e1b14eaec2f111825e9d7bd19508ab4e94bc83 [file] [log] [blame]
Patrik Höglundeeb79e92019-10-17 16:04:07 +02001/*
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
11#include "api/audio_codecs/audio_decoder_factory_template.h"
12#include "api/audio_codecs/audio_encoder_factory_template.h"
13#include "api/audio_codecs/opus/audio_decoder_opus.h"
14#include "api/audio_codecs/opus/audio_encoder_opus.h"
15#include "api/call/call_factory_interface.h"
16#include "api/create_peerconnection_factory.h"
17#include "api/peer_connection_interface.h"
18#include "api/rtc_event_log/rtc_event_log_factory.h"
19#include "api/stats/rtcstats_objects.h"
20#include "api/task_queue/default_task_queue_factory.h"
21#include "api/video_codecs/builtin_video_decoder_factory.h"
22#include "api/video_codecs/builtin_video_encoder_factory.h"
23#include "media/engine/webrtc_media_engine.h"
24#include "modules/audio_device/include/audio_device.h"
25#include "modules/audio_processing/include/audio_processing.h"
26
Patrik Höglundeeb79e92019-10-17 16:04:07 +020027namespace webrtc {
28
29cricket::MediaEngineDependencies CreateSomeMediaDeps(
30 TaskQueueFactory* task_queue_factory) {
31 cricket::MediaEngineDependencies media_deps;
32 media_deps.task_queue_factory = task_queue_factory;
33 media_deps.adm = AudioDeviceModule::CreateForTest(
34 AudioDeviceModule::kDummyAudio, task_queue_factory);
35 media_deps.audio_encoder_factory =
36 webrtc::CreateAudioEncoderFactory<webrtc::AudioEncoderOpus>();
37 media_deps.audio_decoder_factory =
38 webrtc::CreateAudioDecoderFactory<webrtc::AudioDecoderOpus>();
39 media_deps.video_encoder_factory = CreateBuiltinVideoEncoderFactory();
40 media_deps.video_decoder_factory = webrtc::CreateBuiltinVideoDecoderFactory();
41 media_deps.audio_processing = webrtc::AudioProcessingBuilder().Create();
42 return media_deps;
43}
44
Patrik Höglundeeb79e92019-10-17 16:04:07 +020045webrtc::PeerConnectionFactoryDependencies CreateSomePcfDeps() {
46 webrtc::PeerConnectionFactoryDependencies pcf_deps;
47 pcf_deps.task_queue_factory = CreateDefaultTaskQueueFactory();
48 pcf_deps.signaling_thread = rtc::Thread::Current();
49 pcf_deps.network_thread = rtc::Thread::Current();
50 pcf_deps.worker_thread = rtc::Thread::Current();
51 pcf_deps.call_factory = webrtc::CreateCallFactory();
52 pcf_deps.event_log_factory = std::make_unique<webrtc::RtcEventLogFactory>(
53 pcf_deps.task_queue_factory.get());
54 auto media_deps = CreateSomeMediaDeps(pcf_deps.task_queue_factory.get());
55 pcf_deps.media_engine = cricket::CreateMediaEngine(std::move(media_deps));
56 return pcf_deps;
57}
58
Patrik Höglund21671632019-10-18 08:04:19 +020059// NOTE: These "test cases" should pull in as much of WebRTC as possible to make
60// sure most commonly used symbols are actually in libwebrtc.a. It's entirely
61// possible these tests won't work at all times (maybe crash even), but that's
62// fine.
63void TestCase1ModularFactory() {
Patrik Höglundeeb79e92019-10-17 16:04:07 +020064 auto pcf_deps = CreateSomePcfDeps();
65 auto peer_connection_factory =
66 webrtc::CreateModularPeerConnectionFactory(std::move(pcf_deps));
67 webrtc::PeerConnectionInterface::RTCConfiguration rtc_config;
68 auto peer_connection = peer_connection_factory->CreatePeerConnection(
69 rtc_config, nullptr, nullptr, nullptr);
Patrik Höglund21671632019-10-18 08:04:19 +020070 printf("peer_connection=%s\n", peer_connection == nullptr ? "nullptr" : "ok");
Patrik Höglundeeb79e92019-10-17 16:04:07 +020071}
72
Patrik Höglund21671632019-10-18 08:04:19 +020073void TestCase2RegularFactory() {
Patrik Höglundeeb79e92019-10-17 16:04:07 +020074 auto task_queue_factory = CreateDefaultTaskQueueFactory();
75 auto media_deps = CreateSomeMediaDeps(task_queue_factory.get());
76
77 auto peer_connection_factory = webrtc::CreatePeerConnectionFactory(
78 rtc::Thread::Current(), rtc::Thread::Current(), rtc::Thread::Current(),
79 std::move(media_deps.adm), std::move(media_deps.audio_encoder_factory),
80 std::move(media_deps.audio_decoder_factory),
81 std::move(media_deps.video_encoder_factory),
82 std::move(media_deps.video_decoder_factory), nullptr, nullptr);
Patrik Höglund21671632019-10-18 08:04:19 +020083 webrtc::PeerConnectionInterface::RTCConfiguration rtc_config;
84 auto peer_connection = peer_connection_factory->CreatePeerConnection(
85 rtc_config, nullptr, nullptr, nullptr);
86 printf("peer_connection=%s\n", peer_connection == nullptr ? "nullptr" : "ok");
Patrik Höglundeeb79e92019-10-17 16:04:07 +020087}
88
89} // namespace webrtc
Patrik Höglund21671632019-10-18 08:04:19 +020090
91int main(int argc, char** argv) {
92 webrtc::TestCase1ModularFactory();
93 webrtc::TestCase2RegularFactory();
94 return 0;
95}