blob: bff261f77a9ac14bc0b831098bccd8f5224cb237 [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 Naccefde92020-03-03 09:29:22 -080020
Tim Nac0df5fc2020-05-05 11:03:54 -070021// VoipEngine is the main interface serving as the entry point for all VoIP
22// APIs. A single instance of VoipEngine should suffice the most of the need for
23// typical VoIP applications as it handles multiple media sessions including a
24// specialized session type like ad-hoc mesh conferencing. Below example code
25// describes the typical sequence of API usage. Each API header contains more
26// description on what the methods are used for.
Tim Nac63bf102020-02-21 11:09:08 -080027//
Tim Nac0df5fc2020-05-05 11:03:54 -070028// // Caller is responsible of setting desired audio components.
29// VoipEngineConfig config;
30// config.encoder_factory = CreateBuiltinAudioEncoderFactory();
31// config.decoder_factory = CreateBuiltinAudioDecoderFactory();
32// config.task_queue_factory = CreateDefaultTaskQueueFactory();
33// config.audio_device =
34// AudioDeviceModule::Create(AudioDeviceModule::kPlatformDefaultAudio,
35// config.task_queue_factory.get());
36// config.audio_processing = AudioProcessingBuilder().Create();
Tim Nac63bf102020-02-21 11:09:08 -080037//
Tim Nac0df5fc2020-05-05 11:03:54 -070038// auto voip_engine = CreateVoipEngine(std::move(config));
39// if (!voip_engine) return some_failure;
Tim Nac63bf102020-02-21 11:09:08 -080040//
Tim Nac0df5fc2020-05-05 11:03:54 -070041// auto& voip_base = voip_engine->Base();
42// auto& voip_codec = voip_engine->Codec();
43// auto& voip_network = voip_engine->Network();
Tim Nac63bf102020-02-21 11:09:08 -080044//
Tim Nac0df5fc2020-05-05 11:03:54 -070045// absl::optional<ChannelId> channel =
46// voip_base.CreateChannel(&app_transport_);
47// if (!channel) return some_failure;
Tim Nac63bf102020-02-21 11:09:08 -080048//
Tim Nac0df5fc2020-05-05 11:03:54 -070049// // After SDP offer/answer, set payload type and codecs that have been
50// // decided through SDP negotiation.
51// voip_codec.SetSendCodec(*channel, ...);
52// voip_codec.SetReceiveCodecs(*channel, ...);
Tim Nac63bf102020-02-21 11:09:08 -080053//
Tim Nac0df5fc2020-05-05 11:03:54 -070054// // Start sending and playing RTP on voip channel.
55// voip_base.StartSend(*channel);
56// voip_base.StartPlayout(*channel);
Tim Nac63bf102020-02-21 11:09:08 -080057//
Tim Nac0df5fc2020-05-05 11:03:54 -070058// // Inject received RTP/RTCP through VoipNetwork interface.
59// voip_network.ReceivedRTPPacket(*channel, ...);
60// voip_network.ReceivedRTCPPacket(*channel, ...);
Tim Nac63bf102020-02-21 11:09:08 -080061//
62// // Stop and release voip channel.
Tim Nac0df5fc2020-05-05 11:03:54 -070063// voip_base.StopSend(*channel);
64// voip_base.StopPlayout(*channel);
65// voip_base.ReleaseChannel(*channel);
Tim Nac63bf102020-02-21 11:09:08 -080066//
Tim Nac0df5fc2020-05-05 11:03:54 -070067// Current VoipEngine defines three sub-API classes and is subject to expand in
68// near future.
Tim Nac63bf102020-02-21 11:09:08 -080069class VoipEngine {
70 public:
Tim Naccefde92020-03-03 09:29:22 -080071 virtual ~VoipEngine() = default;
72
Tim Nac63bf102020-02-21 11:09:08 -080073 // VoipBase is the audio session management interface that
Tim Nac0df5fc2020-05-05 11:03:54 -070074 // creates/releases/starts/stops an one-to-one audio media session.
Tim Naccefde92020-03-03 09:29:22 -080075 virtual VoipBase& Base() = 0;
Tim Nac63bf102020-02-21 11:09:08 -080076
77 // VoipNetwork provides injection APIs that would enable application
78 // to send and receive RTP/RTCP packets. There is no default network module
79 // that provides RTP transmission and reception.
Tim Naccefde92020-03-03 09:29:22 -080080 virtual VoipNetwork& Network() = 0;
Tim Nac63bf102020-02-21 11:09:08 -080081
82 // VoipCodec provides codec configuration APIs for encoder and decoders.
Tim Naccefde92020-03-03 09:29:22 -080083 virtual VoipCodec& Codec() = 0;
Jason Longa5347292020-08-18 13:22:39 -040084
85 // VoipDtmf provides DTMF event APIs to register and send DTMF events.
86 virtual VoipDtmf& Dtmf() = 0;
Tim Nac63bf102020-02-21 11:09:08 -080087};
88
89} // namespace webrtc
90
91#endif // API_VOIP_VOIP_ENGINE_H_