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