voip_engine.h 3.2 KB

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