blob: 5724b6b5d908c686052b5fd716e9882abcb137c0 [file] [log] [blame]
Tim Nac0df5fc2020-05-05 11:03:54 -07001/*
2 * Copyright (c) 2020 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 */
Tim Nac63bf102020-02-21 11:09:08 -080010
11#ifndef API_VOIP_VOIP_ENGINE_H_
12#define API_VOIP_VOIP_ENGINE_H_
13
Tim Nac63bf102020-02-21 11:09:08 -080014namespace webrtc {
15
Tim Naccefde92020-03-03 09:29:22 -080016class VoipBase;
17class VoipCodec;
18class VoipNetwork;
Jason Longa5347292020-08-18 13:22:39 -040019class VoipDtmf;
Tim Naf4347f72020-10-28 13:51:24 -070020class VoipStatistics;
Tim Naccefde92020-03-03 09:29:22 -080021
Tim Nac0df5fc2020-05-05 11:03:54 -070022// VoipEngine is the main interface serving as the entry point for all VoIP
23// APIs. A single instance of VoipEngine should suffice the most of the need for
24// typical VoIP applications as it handles multiple media sessions including a
25// specialized session type like ad-hoc mesh conferencing. Below example code
26// describes the typical sequence of API usage. Each API header contains more
27// description on what the methods are used for.
Tim Nac63bf102020-02-21 11:09:08 -080028//
Tim Nac0df5fc2020-05-05 11:03:54 -070029// // Caller is responsible of setting desired audio components.
30// VoipEngineConfig config;
31// config.encoder_factory = CreateBuiltinAudioEncoderFactory();
32// config.decoder_factory = CreateBuiltinAudioDecoderFactory();
33// config.task_queue_factory = CreateDefaultTaskQueueFactory();
34// config.audio_device =
35// AudioDeviceModule::Create(AudioDeviceModule::kPlatformDefaultAudio,
36// config.task_queue_factory.get());
37// config.audio_processing = AudioProcessingBuilder().Create();
Tim Nac63bf102020-02-21 11:09:08 -080038//
Tim Nac0df5fc2020-05-05 11:03:54 -070039// auto voip_engine = CreateVoipEngine(std::move(config));
40// if (!voip_engine) return some_failure;
Tim Nac63bf102020-02-21 11:09:08 -080041//
Tim Nac0df5fc2020-05-05 11:03:54 -070042// auto& voip_base = voip_engine->Base();
43// auto& voip_codec = voip_engine->Codec();
44// auto& voip_network = voip_engine->Network();
Tim Nac63bf102020-02-21 11:09:08 -080045//
Tim Nac0df5fc2020-05-05 11:03:54 -070046// absl::optional<ChannelId> channel =
47// voip_base.CreateChannel(&app_transport_);
48// if (!channel) return some_failure;
Tim Nac63bf102020-02-21 11:09:08 -080049//
Tim Nac0df5fc2020-05-05 11:03:54 -070050// // After SDP offer/answer, set payload type and codecs that have been
51// // decided through SDP negotiation.
52// voip_codec.SetSendCodec(*channel, ...);
53// voip_codec.SetReceiveCodecs(*channel, ...);
Tim Nac63bf102020-02-21 11:09:08 -080054//
Tim Nac0df5fc2020-05-05 11:03:54 -070055// // Start sending and playing RTP on voip channel.
56// voip_base.StartSend(*channel);
57// voip_base.StartPlayout(*channel);
Tim Nac63bf102020-02-21 11:09:08 -080058//
Tim Nac0df5fc2020-05-05 11:03:54 -070059// // Inject received RTP/RTCP through VoipNetwork interface.
60// voip_network.ReceivedRTPPacket(*channel, ...);
61// voip_network.ReceivedRTCPPacket(*channel, ...);
Tim Nac63bf102020-02-21 11:09:08 -080062//
63// // Stop and release voip channel.
Tim Nac0df5fc2020-05-05 11:03:54 -070064// voip_base.StopSend(*channel);
65// voip_base.StopPlayout(*channel);
66// voip_base.ReleaseChannel(*channel);
Tim Nac63bf102020-02-21 11:09:08 -080067//
Tim Nac0df5fc2020-05-05 11:03:54 -070068// Current VoipEngine defines three sub-API classes and is subject to expand in
69// near future.
Tim Nac63bf102020-02-21 11:09:08 -080070class VoipEngine {
71 public:
Tim Naccefde92020-03-03 09:29:22 -080072 virtual ~VoipEngine() = default;
73
Tim Nac63bf102020-02-21 11:09:08 -080074 // VoipBase is the audio session management interface that
Tim Nac0df5fc2020-05-05 11:03:54 -070075 // creates/releases/starts/stops an one-to-one audio media session.
Tim Naccefde92020-03-03 09:29:22 -080076 virtual VoipBase& Base() = 0;
Tim Nac63bf102020-02-21 11:09:08 -080077
78 // VoipNetwork provides injection APIs that would enable application
79 // to send and receive RTP/RTCP packets. There is no default network module
80 // that provides RTP transmission and reception.
Tim Naccefde92020-03-03 09:29:22 -080081 virtual VoipNetwork& Network() = 0;
Tim Nac63bf102020-02-21 11:09:08 -080082
83 // VoipCodec provides codec configuration APIs for encoder and decoders.
Tim Naccefde92020-03-03 09:29:22 -080084 virtual VoipCodec& Codec() = 0;
Jason Longa5347292020-08-18 13:22:39 -040085
86 // VoipDtmf provides DTMF event APIs to register and send DTMF events.
87 virtual VoipDtmf& Dtmf() = 0;
Tim Naf4347f72020-10-28 13:51:24 -070088
89 // VoipStatistics provides performance metrics around audio decoding module
90 // and jitter buffer (NetEq).
91 virtual VoipStatistics& Statistics() = 0;
Tim Nac63bf102020-02-21 11:09:08 -080092};
93
94} // namespace webrtc
95
96#endif // API_VOIP_VOIP_ENGINE_H_