Tim Na | c0df5fc | 2020-05-05 11:03:54 -0700 | [diff] [blame] | 1 | /* |
| 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 Na | c63bf10 | 2020-02-21 11:09:08 -0800 | [diff] [blame] | 10 | |
| 11 | #ifndef API_VOIP_VOIP_ENGINE_H_ |
| 12 | #define API_VOIP_VOIP_ENGINE_H_ |
| 13 | |
Tim Na | c63bf10 | 2020-02-21 11:09:08 -0800 | [diff] [blame] | 14 | namespace webrtc { |
| 15 | |
Tim Na | ccefde9 | 2020-03-03 09:29:22 -0800 | [diff] [blame] | 16 | class VoipBase; |
| 17 | class VoipCodec; |
| 18 | class VoipNetwork; |
Jason Long | a534729 | 2020-08-18 13:22:39 -0400 | [diff] [blame] | 19 | class VoipDtmf; |
Tim Na | f4347f7 | 2020-10-28 13:51:24 -0700 | [diff] [blame] | 20 | class VoipStatistics; |
Tim Na | a58cae3 | 2020-11-13 11:07:43 -0800 | [diff] [blame^] | 21 | class VoipVolumeControl; |
Tim Na | ccefde9 | 2020-03-03 09:29:22 -0800 | [diff] [blame] | 22 | |
Tim Na | c0df5fc | 2020-05-05 11:03:54 -0700 | [diff] [blame] | 23 | // VoipEngine is the main interface serving as the entry point for all VoIP |
| 24 | // APIs. A single instance of VoipEngine should suffice the most of the need for |
| 25 | // typical VoIP applications as it handles multiple media sessions including a |
| 26 | // specialized session type like ad-hoc mesh conferencing. Below example code |
| 27 | // describes the typical sequence of API usage. Each API header contains more |
| 28 | // description on what the methods are used for. |
Tim Na | c63bf10 | 2020-02-21 11:09:08 -0800 | [diff] [blame] | 29 | // |
Tim Na | c0df5fc | 2020-05-05 11:03:54 -0700 | [diff] [blame] | 30 | // // Caller is responsible of setting desired audio components. |
| 31 | // VoipEngineConfig config; |
| 32 | // config.encoder_factory = CreateBuiltinAudioEncoderFactory(); |
| 33 | // config.decoder_factory = CreateBuiltinAudioDecoderFactory(); |
| 34 | // config.task_queue_factory = CreateDefaultTaskQueueFactory(); |
| 35 | // config.audio_device = |
| 36 | // AudioDeviceModule::Create(AudioDeviceModule::kPlatformDefaultAudio, |
| 37 | // config.task_queue_factory.get()); |
| 38 | // config.audio_processing = AudioProcessingBuilder().Create(); |
Tim Na | c63bf10 | 2020-02-21 11:09:08 -0800 | [diff] [blame] | 39 | // |
Tim Na | c0df5fc | 2020-05-05 11:03:54 -0700 | [diff] [blame] | 40 | // auto voip_engine = CreateVoipEngine(std::move(config)); |
| 41 | // if (!voip_engine) return some_failure; |
Tim Na | c63bf10 | 2020-02-21 11:09:08 -0800 | [diff] [blame] | 42 | // |
Tim Na | c0df5fc | 2020-05-05 11:03:54 -0700 | [diff] [blame] | 43 | // auto& voip_base = voip_engine->Base(); |
| 44 | // auto& voip_codec = voip_engine->Codec(); |
| 45 | // auto& voip_network = voip_engine->Network(); |
Tim Na | c63bf10 | 2020-02-21 11:09:08 -0800 | [diff] [blame] | 46 | // |
Tim Na | c0df5fc | 2020-05-05 11:03:54 -0700 | [diff] [blame] | 47 | // absl::optional<ChannelId> channel = |
| 48 | // voip_base.CreateChannel(&app_transport_); |
| 49 | // if (!channel) return some_failure; |
Tim Na | c63bf10 | 2020-02-21 11:09:08 -0800 | [diff] [blame] | 50 | // |
Tim Na | c0df5fc | 2020-05-05 11:03:54 -0700 | [diff] [blame] | 51 | // // After SDP offer/answer, set payload type and codecs that have been |
| 52 | // // decided through SDP negotiation. |
| 53 | // voip_codec.SetSendCodec(*channel, ...); |
| 54 | // voip_codec.SetReceiveCodecs(*channel, ...); |
Tim Na | c63bf10 | 2020-02-21 11:09:08 -0800 | [diff] [blame] | 55 | // |
Tim Na | c0df5fc | 2020-05-05 11:03:54 -0700 | [diff] [blame] | 56 | // // Start sending and playing RTP on voip channel. |
| 57 | // voip_base.StartSend(*channel); |
| 58 | // voip_base.StartPlayout(*channel); |
Tim Na | c63bf10 | 2020-02-21 11:09:08 -0800 | [diff] [blame] | 59 | // |
Tim Na | c0df5fc | 2020-05-05 11:03:54 -0700 | [diff] [blame] | 60 | // // Inject received RTP/RTCP through VoipNetwork interface. |
| 61 | // voip_network.ReceivedRTPPacket(*channel, ...); |
| 62 | // voip_network.ReceivedRTCPPacket(*channel, ...); |
Tim Na | c63bf10 | 2020-02-21 11:09:08 -0800 | [diff] [blame] | 63 | // |
| 64 | // // Stop and release voip channel. |
Tim Na | c0df5fc | 2020-05-05 11:03:54 -0700 | [diff] [blame] | 65 | // voip_base.StopSend(*channel); |
| 66 | // voip_base.StopPlayout(*channel); |
| 67 | // voip_base.ReleaseChannel(*channel); |
Tim Na | c63bf10 | 2020-02-21 11:09:08 -0800 | [diff] [blame] | 68 | // |
Tim Na | c0df5fc | 2020-05-05 11:03:54 -0700 | [diff] [blame] | 69 | // Current VoipEngine defines three sub-API classes and is subject to expand in |
| 70 | // near future. |
Tim Na | c63bf10 | 2020-02-21 11:09:08 -0800 | [diff] [blame] | 71 | class VoipEngine { |
| 72 | public: |
Tim Na | ccefde9 | 2020-03-03 09:29:22 -0800 | [diff] [blame] | 73 | virtual ~VoipEngine() = default; |
| 74 | |
Tim Na | c63bf10 | 2020-02-21 11:09:08 -0800 | [diff] [blame] | 75 | // VoipBase is the audio session management interface that |
Tim Na | c0df5fc | 2020-05-05 11:03:54 -0700 | [diff] [blame] | 76 | // creates/releases/starts/stops an one-to-one audio media session. |
Tim Na | ccefde9 | 2020-03-03 09:29:22 -0800 | [diff] [blame] | 77 | virtual VoipBase& Base() = 0; |
Tim Na | c63bf10 | 2020-02-21 11:09:08 -0800 | [diff] [blame] | 78 | |
| 79 | // VoipNetwork provides injection APIs that would enable application |
| 80 | // to send and receive RTP/RTCP packets. There is no default network module |
| 81 | // that provides RTP transmission and reception. |
Tim Na | ccefde9 | 2020-03-03 09:29:22 -0800 | [diff] [blame] | 82 | virtual VoipNetwork& Network() = 0; |
Tim Na | c63bf10 | 2020-02-21 11:09:08 -0800 | [diff] [blame] | 83 | |
| 84 | // VoipCodec provides codec configuration APIs for encoder and decoders. |
Tim Na | ccefde9 | 2020-03-03 09:29:22 -0800 | [diff] [blame] | 85 | virtual VoipCodec& Codec() = 0; |
Jason Long | a534729 | 2020-08-18 13:22:39 -0400 | [diff] [blame] | 86 | |
| 87 | // VoipDtmf provides DTMF event APIs to register and send DTMF events. |
| 88 | virtual VoipDtmf& Dtmf() = 0; |
Tim Na | f4347f7 | 2020-10-28 13:51:24 -0700 | [diff] [blame] | 89 | |
| 90 | // VoipStatistics provides performance metrics around audio decoding module |
| 91 | // and jitter buffer (NetEq). |
| 92 | virtual VoipStatistics& Statistics() = 0; |
Tim Na | a58cae3 | 2020-11-13 11:07:43 -0800 | [diff] [blame^] | 93 | |
| 94 | // VoipVolumeControl provides various input/output volume control. |
| 95 | virtual VoipVolumeControl& VolumeControl() = 0; |
Tim Na | c63bf10 | 2020-02-21 11:09:08 -0800 | [diff] [blame] | 96 | }; |
| 97 | |
| 98 | } // namespace webrtc |
| 99 | |
| 100 | #endif // API_VOIP_VOIP_ENGINE_H_ |