blob: ac11794ca251904f4e184e28add1d731efd139ad [file] [log] [blame]
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +00001/*
2 * Copyright (c) 2013 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 */
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +000010#ifndef WEBRTC_CALL_H_
11#define WEBRTC_CALL_H_
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000012
13#include <string>
14#include <vector>
15
16#include "webrtc/common_types.h"
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020017#include "webrtc/audio_receive_stream.h"
Fredrik Solenberg04f49312015-06-08 13:04:56 +020018#include "webrtc/audio_send_stream.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000019#include "webrtc/video_receive_stream.h"
20#include "webrtc/video_send_stream.h"
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000021
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000022namespace webrtc {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000023
Fredrik Solenberg04f49312015-06-08 13:04:56 +020024class AudioDeviceModule;
25class AudioProcessing;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000026class VoiceEngine;
Fredrik Solenberg04f49312015-06-08 13:04:56 +020027class VoiceEngineObserver;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000028
29const char* Version();
30
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020031enum class MediaType {
32 ANY,
33 AUDIO,
34 VIDEO,
35 DATA
36};
37
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000038class PacketReceiver {
39 public:
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +000040 enum DeliveryStatus {
41 DELIVERY_OK,
42 DELIVERY_UNKNOWN_SSRC,
43 DELIVERY_PACKET_ERROR,
44 };
45
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020046 virtual DeliveryStatus DeliverPacket(MediaType media_type,
47 const uint8_t* packet,
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +000048 size_t length) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000049 protected:
50 virtual ~PacketReceiver() {}
51};
52
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000053// Callback interface for reporting when a system overuse is detected.
pbos@webrtc.org42684be2014-10-03 11:25:45 +000054class LoadObserver {
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000055 public:
pbos@webrtc.org42684be2014-10-03 11:25:45 +000056 enum Load { kOveruse, kUnderuse };
57
58 // Triggered when overuse is detected or when we believe the system can take
59 // more load.
60 virtual void OnLoadUpdate(Load load) = 0;
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000061
62 protected:
pbos@webrtc.org42684be2014-10-03 11:25:45 +000063 virtual ~LoadObserver() {}
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000064};
65
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000066// A Call instance can contain several send and/or receive streams. All streams
67// are assumed to have the same remote endpoint and will share bitrate estimates
68// etc.
69class Call {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000070 public:
pbos@webrtc.org26c0c412014-09-03 16:17:12 +000071 enum NetworkState {
72 kNetworkUp,
73 kNetworkDown,
74 };
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000075 struct Config {
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000076 explicit Config(newapi::Transport* send_transport)
Peter Boström76c53d32015-04-09 14:35:37 +020077 : send_transport(send_transport),
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +000078 voice_engine(NULL),
pbos@webrtc.org00873182014-11-25 14:03:34 +000079 overuse_callback(NULL) {}
pbos@webrtc.orga73a6782014-10-14 11:52:10 +000080
81 static const int kDefaultStartBitrateBps;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000082
Fredrik Solenberg04f49312015-06-08 13:04:56 +020083 // TODO(solenberg): Need to add media type to the interface for outgoing
84 // packets too.
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000085 newapi::Transport* send_transport;
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +000086
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000087 // VoiceEngine used for audio/video synchronization for this Call.
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +000088 VoiceEngine* voice_engine;
89
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000090 // Callback for overuse and normal usage based on the jitter of incoming
91 // captured frames. 'NULL' disables the callback.
pbos@webrtc.org42684be2014-10-03 11:25:45 +000092 LoadObserver* overuse_callback;
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +000093
pbos@webrtc.org00873182014-11-25 14:03:34 +000094 // Bitrate config used until valid bitrate estimates are calculated. Also
95 // used to cap total bitrate used.
pbos@webrtc.org00873182014-11-25 14:03:34 +000096 struct BitrateConfig {
97 BitrateConfig()
98 : min_bitrate_bps(0),
99 start_bitrate_bps(kDefaultStartBitrateBps),
100 max_bitrate_bps(-1) {}
101 int min_bitrate_bps;
102 int start_bitrate_bps;
103 int max_bitrate_bps;
Stefan Holmere5904162015-03-26 11:11:06 +0100104 } bitrate_config;
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200105
106 struct AudioConfig {
107 AudioDeviceModule* audio_device_manager;
108 AudioProcessing* audio_processing;
109 VoiceEngineObserver* voice_engine_observer;
110 } audio_config;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +0000111 };
112
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000113 struct Stats {
pbos@webrtc.org2b19f062014-12-11 13:26:09 +0000114 Stats()
115 : send_bandwidth_bps(0),
116 recv_bandwidth_bps(0),
117 pacer_delay_ms(0),
118 rtt_ms(-1) {}
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000119
120 int send_bandwidth_bps;
121 int recv_bandwidth_bps;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000122 int64_t pacer_delay_ms;
123 int64_t rtt_ms;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000124 };
125
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000126 static Call* Create(const Call::Config& config);
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000127
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200128 virtual AudioSendStream* CreateAudioSendStream(
129 const AudioSendStream::Config& config) = 0;
130 virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
131
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200132 virtual AudioReceiveStream* CreateAudioReceiveStream(
133 const AudioReceiveStream::Config& config) = 0;
134 virtual void DestroyAudioReceiveStream(
135 AudioReceiveStream* receive_stream) = 0;
136
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000137 virtual VideoSendStream* CreateVideoSendStream(
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000138 const VideoSendStream::Config& config,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000139 const VideoEncoderConfig& encoder_config) = 0;
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000140 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000141
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000142 virtual VideoReceiveStream* CreateVideoReceiveStream(
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000143 const VideoReceiveStream::Config& config) = 0;
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000144 virtual void DestroyVideoReceiveStream(
145 VideoReceiveStream* receive_stream) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000146
147 // All received RTP and RTCP packets for the call should be inserted to this
148 // PacketReceiver. The PacketReceiver pointer is valid as long as the
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000149 // Call instance exists.
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000150 virtual PacketReceiver* Receiver() = 0;
151
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000152 // Returns the call statistics, such as estimated send and receive bandwidth,
153 // pacing delay, etc.
154 virtual Stats GetStats() const = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000155
pbos@webrtc.org00873182014-11-25 14:03:34 +0000156 // TODO(pbos): Like BitrateConfig above this is currently per-stream instead
157 // of maximum for entire Call. This should be fixed along with the above.
158 // Specifying a start bitrate (>0) will currently reset the current bitrate
159 // estimate. This is due to how the 'x-google-start-bitrate' flag is currently
160 // implemented.
161 virtual void SetBitrateConfig(
162 const Config::BitrateConfig& bitrate_config) = 0;
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000163 virtual void SignalNetworkState(NetworkState state) = 0;
164
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000165 virtual ~Call() {}
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000166};
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000167} // namespace webrtc
168
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000169#endif // WEBRTC_CALL_H_