blob: 8df7bd0571f18bb120fd79fea634a586845990b7 [file] [log] [blame]
Tim Nac0df5fc2020-05-05 18:03:541/*
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 */
Tim Nac63bf102020-02-21 19:09:0810
11#ifndef API_VOIP_VOIP_BASE_H_
12#define API_VOIP_VOIP_BASE_H_
13
Danil Chapovalov098da172021-01-14 15:15:3114#include "absl/base/attributes.h"
Tim Nac0df5fc2020-05-05 18:03:5415#include "absl/types/optional.h"
Tim Nac63bf102020-02-21 19:09:0816
17namespace webrtc {
18
Tim Naccefde92020-03-03 17:29:2219class Transport;
20
Tim Nac63bf102020-02-21 19:09:0821// VoipBase interface
22//
23// VoipBase provides a management interface on a media session using a
24// concept called 'channel'. A channel represents an interface handle
25// for application to request various media session operations. This
26// notion of channel is used throughout other interfaces as well.
27//
Tim Naccefde92020-03-03 17:29:2228// Underneath the interface, a channel id is mapped into an audio session
Tim Nac63bf102020-02-21 19:09:0829// object that is capable of sending and receiving a single RTP stream with
30// another media endpoint. It's possible to create and use multiple active
31// channels simultaneously which would mean that particular application
32// session has RTP streams with multiple remote endpoints.
33//
34// A typical example for the usage context is outlined in VoipEngine
35// header file.
Tim Naccefde92020-03-03 17:29:2236
37enum class ChannelId : int {};
38
Danil Chapovalov098da172021-01-14 15:15:3139enum class ABSL_MUST_USE_RESULT VoipResult {
Tim Nab223cb62020-11-20 17:34:4740 // kOk indicates the function was successfully invoked with no error.
41 kOk,
42 // kInvalidArgument indicates the caller specified an invalid argument, such
43 // as an invalid ChannelId.
44 kInvalidArgument,
45 // kFailedPrecondition indicates that the operation was failed due to not
46 // satisfying prerequisite such as not setting codec type before sending.
47 kFailedPrecondition,
48 // kInternal is used to indicate various internal failures that are not the
49 // caller's fault. Further detail is commented on each function that uses this
50 // return value.
51 kInternal,
52};
53
Tim Nac63bf102020-02-21 19:09:0854class VoipBase {
55 public:
Tim Naccefde92020-03-03 17:29:2256 // Creates a channel.
57 // Each channel handle maps into one audio media session where each has
58 // its own separate module for send/receive rtp packet with one peer.
Artem Titov0e61fdd2021-07-25 19:50:1459 // Caller must set `transport`, webrtc::Transport callback pointer to
Tim Naccefde92020-03-03 17:29:2260 // receive rtp/rtcp packets from corresponding media session in VoIP engine.
61 // VoipEngine framework expects applications to handle network I/O directly
62 // and injection for incoming RTP from remote endpoint is handled via
Artem Titov0e61fdd2021-07-25 19:50:1463 // VoipNetwork interface. `local_ssrc` is optional and when local_ssrc is not
Tim Naccefde92020-03-03 17:29:2264 // set, some random value will be used by voip engine.
Tim Nab223cb62020-11-20 17:34:4765 // Returns a ChannelId created for caller to handle subsequent Channel
66 // operations.
67 virtual ChannelId CreateChannel(Transport* transport,
68 absl::optional<uint32_t> local_ssrc) = 0;
Tim Nac63bf102020-02-21 19:09:0869
Artem Titov0e61fdd2021-07-25 19:50:1470 // Releases `channel_id` that no longer has any use.
Tim Nab223cb62020-11-20 17:34:4771 // Returns following VoipResult;
Artem Titov0e61fdd2021-07-25 19:50:1472 // kOk - `channel_id` is released.
73 // kInvalidArgument - `channel_id` is invalid.
Tim Nab223cb62020-11-20 17:34:4774 // kInternal - Fails to stop audio output device.
75 virtual VoipResult ReleaseChannel(ChannelId channel_id) = 0;
Tim Nac63bf102020-02-21 19:09:0876
Artem Titov0e61fdd2021-07-25 19:50:1477 // Starts sending on `channel_id`. This starts microphone if not started yet.
Tim Nab223cb62020-11-20 17:34:4778 // Returns following VoipResult;
79 // kOk - Channel successfully started to send.
Artem Titov0e61fdd2021-07-25 19:50:1480 // kInvalidArgument - `channel_id` is invalid.
Tim Nab223cb62020-11-20 17:34:4781 // kFailedPrecondition - Missing prerequisite on VoipCodec::SetSendCodec.
82 // kInternal - initialization has failed on selected microphone.
83 virtual VoipResult StartSend(ChannelId channel_id) = 0;
Tim Nac63bf102020-02-21 19:09:0884
Artem Titov0e61fdd2021-07-25 19:50:1485 // Stops sending on `channel_id`. If this is the last active channel, it will
Tim Nac63bf102020-02-21 19:09:0886 // stop microphone input from underlying audio platform layer.
Tim Nab223cb62020-11-20 17:34:4787 // Returns following VoipResult;
88 // kOk - Channel successfully stopped to send.
Artem Titov0e61fdd2021-07-25 19:50:1489 // kInvalidArgument - `channel_id` is invalid.
Tim Nab223cb62020-11-20 17:34:4790 // kInternal - Failed to stop the active microphone device.
91 virtual VoipResult StopSend(ChannelId channel_id) = 0;
Tim Nac63bf102020-02-21 19:09:0892
Artem Titov0e61fdd2021-07-25 19:50:1493 // Starts playing on speaker device for `channel_id`.
Tim Nac63bf102020-02-21 19:09:0894 // This will start underlying platform speaker device if not started.
Tim Nab223cb62020-11-20 17:34:4795 // Returns following VoipResult;
96 // kOk - Channel successfully started to play out.
Artem Titov0e61fdd2021-07-25 19:50:1497 // kInvalidArgument - `channel_id` is invalid.
Tim Nab223cb62020-11-20 17:34:4798 // kFailedPrecondition - Missing prerequisite on VoipCodec::SetReceiveCodecs.
99 // kInternal - Failed to initializate the selected speaker device.
100 virtual VoipResult StartPlayout(ChannelId channel_id) = 0;
Tim Nac63bf102020-02-21 19:09:08101
Artem Titov0e61fdd2021-07-25 19:50:14102 // Stops playing on speaker device for `channel_id`.
Tim Nab223cb62020-11-20 17:34:47103 // Returns following VoipResult;
104 // kOk - Channel successfully stopped t play out.
Artem Titov0e61fdd2021-07-25 19:50:14105 // kInvalidArgument - `channel_id` is invalid.
Tim Nab223cb62020-11-20 17:34:47106 virtual VoipResult StopPlayout(ChannelId channel_id) = 0;
Tim Nac63bf102020-02-21 19:09:08107
108 protected:
109 virtual ~VoipBase() = default;
110};
111
112} // namespace webrtc
113
114#endif // API_VOIP_VOIP_BASE_H_