voip_base.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_BASE_H_
  11. #define API_VOIP_VOIP_BASE_H_
  12. #include "absl/types/optional.h"
  13. namespace webrtc {
  14. class Transport;
  15. // VoipBase interface
  16. //
  17. // VoipBase provides a management interface on a media session using a
  18. // concept called 'channel'. A channel represents an interface handle
  19. // for application to request various media session operations. This
  20. // notion of channel is used throughout other interfaces as well.
  21. //
  22. // Underneath the interface, a channel id is mapped into an audio session
  23. // object that is capable of sending and receiving a single RTP stream with
  24. // another media endpoint. It's possible to create and use multiple active
  25. // channels simultaneously which would mean that particular application
  26. // session has RTP streams with multiple remote endpoints.
  27. //
  28. // A typical example for the usage context is outlined in VoipEngine
  29. // header file.
  30. enum class ChannelId : int {};
  31. class VoipBase {
  32. public:
  33. // Creates a channel.
  34. // Each channel handle maps into one audio media session where each has
  35. // its own separate module for send/receive rtp packet with one peer.
  36. // Caller must set |transport|, webrtc::Transport callback pointer to
  37. // receive rtp/rtcp packets from corresponding media session in VoIP engine.
  38. // VoipEngine framework expects applications to handle network I/O directly
  39. // and injection for incoming RTP from remote endpoint is handled via
  40. // VoipNetwork interface. |local_ssrc| is optional and when local_ssrc is not
  41. // set, some random value will be used by voip engine.
  42. // Returns value is optional as to indicate the failure to create channel.
  43. virtual absl::optional<ChannelId> CreateChannel(
  44. Transport* transport,
  45. absl::optional<uint32_t> local_ssrc) = 0;
  46. // Releases |channel_id| that no longer has any use.
  47. virtual void ReleaseChannel(ChannelId channel_id) = 0;
  48. // Starts sending on |channel_id|. This will start microphone if not started
  49. // yet. Returns false if initialization has failed on selected microphone
  50. // device. API is subject to expand to reflect error condition to application
  51. // later.
  52. virtual bool StartSend(ChannelId channel_id) = 0;
  53. // Stops sending on |channel_id|. If this is the last active channel, it will
  54. // stop microphone input from underlying audio platform layer.
  55. // Returns false if termination logic has failed on selected microphone
  56. // device. API is subject to expand to reflect error condition to application
  57. // later.
  58. virtual bool StopSend(ChannelId channel_id) = 0;
  59. // Starts playing on speaker device for |channel_id|.
  60. // This will start underlying platform speaker device if not started.
  61. // Returns false if initialization has failed
  62. // on selected speaker device. API is subject to expand to reflect error
  63. // condition to application later.
  64. virtual bool StartPlayout(ChannelId channel_id) = 0;
  65. // Stops playing on speaker device for |channel_id|.
  66. // If this is the last active channel playing, then it will stop speaker
  67. // from the platform layer.
  68. // Returns false if termination logic has failed on selected speaker device.
  69. // API is subject to expand to reflect error condition to application later.
  70. virtual bool StopPlayout(ChannelId channel_id) = 0;
  71. protected:
  72. virtual ~VoipBase() = default;
  73. };
  74. } // namespace webrtc
  75. #endif // API_VOIP_VOIP_BASE_H_