voip_engine.h 3.4 KB

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