voip_base.h (4798B)
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 11 #ifndef API_VOIP_VOIP_BASE_H_ 12 #define API_VOIP_VOIP_BASE_H_ 13 14 #include <cstdint> 15 #include <optional> 16 17 #include "absl/base/attributes.h" 18 19 namespace webrtc { 20 21 class Transport; 22 23 // VoipBase interface 24 // 25 // VoipBase provides a management interface on a media session using a 26 // concept called 'channel'. A channel represents an interface handle 27 // for application to request various media session operations. This 28 // notion of channel is used throughout other interfaces as well. 29 // 30 // Underneath the interface, a channel id is mapped into an audio session 31 // object that is capable of sending and receiving a single RTP stream with 32 // another media endpoint. It's possible to create and use multiple active 33 // channels simultaneously which would mean that particular application 34 // session has RTP streams with multiple remote endpoints. 35 // 36 // A typical example for the usage context is outlined in VoipEngine 37 // header file. 38 39 enum class ChannelId : int {}; 40 41 enum class ABSL_MUST_USE_RESULT VoipResult { 42 // kOk indicates the function was successfully invoked with no error. 43 kOk, 44 // kInvalidArgument indicates the caller specified an invalid argument, such 45 // as an invalid ChannelId. 46 kInvalidArgument, 47 // kFailedPrecondition indicates that the operation was failed due to not 48 // satisfying prerequisite such as not setting codec type before sending. 49 kFailedPrecondition, 50 // kInternal is used to indicate various internal failures that are not the 51 // caller's fault. Further detail is commented on each function that uses this 52 // return value. 53 kInternal, 54 }; 55 56 class VoipBase { 57 public: 58 // Creates a channel. 59 // Each channel handle maps into one audio media session where each has 60 // its own separate module for send/receive rtp packet with one peer. 61 // Caller must set `transport`, Transport callback pointer to 62 // receive rtp/rtcp packets from corresponding media session in VoIP engine. 63 // VoipEngine framework expects applications to handle network I/O directly 64 // and injection for incoming RTP from remote endpoint is handled via 65 // VoipNetwork interface. `local_ssrc` is optional and when local_ssrc is not 66 // set, some random value will be used by voip engine. 67 // Returns a ChannelId created for caller to handle subsequent Channel 68 // operations. 69 virtual ChannelId CreateChannel(Transport* transport, 70 std::optional<uint32_t> local_ssrc) = 0; 71 72 // Releases `channel_id` that no longer has any use. 73 // Returns following VoipResult; 74 // kOk - `channel_id` is released. 75 // kInvalidArgument - `channel_id` is invalid. 76 // kInternal - Fails to stop audio output device. 77 virtual VoipResult ReleaseChannel(ChannelId channel_id) = 0; 78 79 // Starts sending on `channel_id`. This starts microphone if not started yet. 80 // Returns following VoipResult; 81 // kOk - Channel successfully started to send. 82 // kInvalidArgument - `channel_id` is invalid. 83 // kFailedPrecondition - Missing prerequisite on VoipCodec::SetSendCodec. 84 // kInternal - initialization has failed on selected microphone. 85 virtual VoipResult StartSend(ChannelId channel_id) = 0; 86 87 // Stops sending on `channel_id`. If this is the last active channel, it will 88 // stop microphone input from underlying audio platform layer. 89 // Returns following VoipResult; 90 // kOk - Channel successfully stopped to send. 91 // kInvalidArgument - `channel_id` is invalid. 92 // kInternal - Failed to stop the active microphone device. 93 virtual VoipResult StopSend(ChannelId channel_id) = 0; 94 95 // Starts playing on speaker device for `channel_id`. 96 // This will start underlying platform speaker device if not started. 97 // Returns following VoipResult; 98 // kOk - Channel successfully started to play out. 99 // kInvalidArgument - `channel_id` is invalid. 100 // kFailedPrecondition - Missing prerequisite on VoipCodec::SetReceiveCodecs. 101 // kInternal - Failed to initializate the selected speaker device. 102 virtual VoipResult StartPlayout(ChannelId channel_id) = 0; 103 104 // Stops playing on speaker device for `channel_id`. 105 // Returns following VoipResult; 106 // kOk - Channel successfully stopped t play out. 107 // kInvalidArgument - `channel_id` is invalid. 108 virtual VoipResult StopPlayout(ChannelId channel_id) = 0; 109 110 protected: 111 virtual ~VoipBase() = default; 112 }; 113 114 } // namespace webrtc 115 116 #endif // API_VOIP_VOIP_BASE_H_