blob: 3ba473fec07d09e5293a836218bba926ba8dcc1b [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"
solenberg566ef242015-11-06 15:34:49 -080019#include "webrtc/audio_state.h"
stefanc1aeaf02015-10-15 07:26:07 -070020#include "webrtc/base/socket.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000021#include "webrtc/video_receive_stream.h"
22#include "webrtc/video_send_stream.h"
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000023
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000024namespace webrtc {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000025
Fredrik Solenberg04f49312015-06-08 13:04:56 +020026class AudioProcessing;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000027
28const char* Version();
29
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020030enum class MediaType {
31 ANY,
32 AUDIO,
33 VIDEO,
34 DATA
35};
36
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000037class PacketReceiver {
38 public:
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +000039 enum DeliveryStatus {
40 DELIVERY_OK,
41 DELIVERY_UNKNOWN_SSRC,
42 DELIVERY_PACKET_ERROR,
43 };
44
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020045 virtual DeliveryStatus DeliverPacket(MediaType media_type,
46 const uint8_t* packet,
stefan68786d22015-09-08 05:36:15 -070047 size_t length,
48 const PacketTime& packet_time) = 0;
49
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000050 protected:
51 virtual ~PacketReceiver() {}
52};
53
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000054// Callback interface for reporting when a system overuse is detected.
pbos@webrtc.org42684be2014-10-03 11:25:45 +000055class LoadObserver {
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000056 public:
pbos@webrtc.org42684be2014-10-03 11:25:45 +000057 enum Load { kOveruse, kUnderuse };
58
59 // Triggered when overuse is detected or when we believe the system can take
60 // more load.
61 virtual void OnLoadUpdate(Load load) = 0;
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000062
63 protected:
pbos@webrtc.org42684be2014-10-03 11:25:45 +000064 virtual ~LoadObserver() {}
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000065};
66
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000067// A Call instance can contain several send and/or receive streams. All streams
68// are assumed to have the same remote endpoint and will share bitrate estimates
69// etc.
70class Call {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000071 public:
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000072 struct Config {
pbos@webrtc.orga73a6782014-10-14 11:52:10 +000073 static const int kDefaultStartBitrateBps;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000074
pbos@webrtc.org00873182014-11-25 14:03:34 +000075 // Bitrate config used until valid bitrate estimates are calculated. Also
76 // used to cap total bitrate used.
pbos@webrtc.org00873182014-11-25 14:03:34 +000077 struct BitrateConfig {
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020078 int min_bitrate_bps = 0;
79 int start_bitrate_bps = kDefaultStartBitrateBps;
80 int max_bitrate_bps = -1;
Stefan Holmere5904162015-03-26 11:11:06 +010081 } bitrate_config;
Fredrik Solenberg04f49312015-06-08 13:04:56 +020082
solenberg566ef242015-11-06 15:34:49 -080083 // AudioState which is possibly shared between multiple calls.
84 // TODO(solenberg): Change this to a shared_ptr once we can use C++11.
85 rtc::scoped_refptr<AudioState> audio_state;
86
87 // Audio Processing Module to be used in this call.
88 // TODO(solenberg): Change this to a shared_ptr once we can use C++11.
89 AudioProcessing* audio_processing = nullptr;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000090 };
91
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +000092 struct Stats {
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020093 int send_bandwidth_bps = 0;
94 int recv_bandwidth_bps = 0;
95 int64_t pacer_delay_ms = 0;
96 int64_t rtt_ms = -1;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +000097 };
98
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000099 static Call* Create(const Call::Config& config);
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000100
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200101 virtual AudioSendStream* CreateAudioSendStream(
102 const AudioSendStream::Config& config) = 0;
103 virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
104
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200105 virtual AudioReceiveStream* CreateAudioReceiveStream(
106 const AudioReceiveStream::Config& config) = 0;
107 virtual void DestroyAudioReceiveStream(
108 AudioReceiveStream* receive_stream) = 0;
109
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000110 virtual VideoSendStream* CreateVideoSendStream(
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000111 const VideoSendStream::Config& config,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000112 const VideoEncoderConfig& encoder_config) = 0;
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000113 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000114
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000115 virtual VideoReceiveStream* CreateVideoReceiveStream(
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000116 const VideoReceiveStream::Config& config) = 0;
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000117 virtual void DestroyVideoReceiveStream(
118 VideoReceiveStream* receive_stream) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000119
120 // All received RTP and RTCP packets for the call should be inserted to this
121 // PacketReceiver. The PacketReceiver pointer is valid as long as the
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000122 // Call instance exists.
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000123 virtual PacketReceiver* Receiver() = 0;
124
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000125 // Returns the call statistics, such as estimated send and receive bandwidth,
126 // pacing delay, etc.
127 virtual Stats GetStats() const = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000128
pbos@webrtc.org00873182014-11-25 14:03:34 +0000129 // TODO(pbos): Like BitrateConfig above this is currently per-stream instead
130 // of maximum for entire Call. This should be fixed along with the above.
131 // Specifying a start bitrate (>0) will currently reset the current bitrate
132 // estimate. This is due to how the 'x-google-start-bitrate' flag is currently
133 // implemented.
134 virtual void SetBitrateConfig(
135 const Config::BitrateConfig& bitrate_config) = 0;
skvlad7a43d252016-03-22 15:32:27 -0700136
137 // TODO(skvlad): When the unbundled case with multiple streams for the same
138 // media type going over different networks is supported, track the state
139 // for each stream separately. Right now it's global per media type.
140 virtual void SignalChannelNetworkState(MediaType media,
141 NetworkState state) = 0;
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000142
stefanc1aeaf02015-10-15 07:26:07 -0700143 virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
144
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000145 virtual ~Call() {}
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000146};
Jelena Marusiccd670222015-07-16 09:30:09 +0200147
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000148} // namespace webrtc
149
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000150#endif // WEBRTC_CALL_H_