blob: ec43b18ad4f18130e99ae2c7aac2bdceecef81d3 [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"
Honghai Zhang0e533ef2016-04-19 15:41:36 -070020#include "webrtc/base/networkroute.h"
ivoc14d5dbe2016-07-04 07:06:55 -070021#include "webrtc/base/platform_file.h"
stefanc1aeaf02015-10-15 07:26:07 -070022#include "webrtc/base/socket.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000023#include "webrtc/video_receive_stream.h"
24#include "webrtc/video_send_stream.h"
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000025
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000026namespace webrtc {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000027
Fredrik Solenberg04f49312015-06-08 13:04:56 +020028class AudioProcessing;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000029
30const char* Version();
31
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020032enum class MediaType {
33 ANY,
34 AUDIO,
35 VIDEO,
36 DATA
37};
38
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000039class PacketReceiver {
40 public:
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +000041 enum DeliveryStatus {
42 DELIVERY_OK,
43 DELIVERY_UNKNOWN_SSRC,
44 DELIVERY_PACKET_ERROR,
45 };
46
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020047 virtual DeliveryStatus DeliverPacket(MediaType media_type,
48 const uint8_t* packet,
stefan68786d22015-09-08 05:36:15 -070049 size_t length,
50 const PacketTime& packet_time) = 0;
51
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000052 protected:
53 virtual ~PacketReceiver() {}
54};
55
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000056// Callback interface for reporting when a system overuse is detected.
pbos@webrtc.org42684be2014-10-03 11:25:45 +000057class LoadObserver {
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000058 public:
pbos@webrtc.org42684be2014-10-03 11:25:45 +000059 enum Load { kOveruse, kUnderuse };
60
61 // Triggered when overuse is detected or when we believe the system can take
62 // more load.
63 virtual void OnLoadUpdate(Load load) = 0;
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000064
65 protected:
pbos@webrtc.org42684be2014-10-03 11:25:45 +000066 virtual ~LoadObserver() {}
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000067};
68
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000069// A Call instance can contain several send and/or receive streams. All streams
70// are assumed to have the same remote endpoint and will share bitrate estimates
71// etc.
72class Call {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000073 public:
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000074 struct Config {
pbos@webrtc.orga73a6782014-10-14 11:52:10 +000075 static const int kDefaultStartBitrateBps;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000076
pbos@webrtc.org00873182014-11-25 14:03:34 +000077 // Bitrate config used until valid bitrate estimates are calculated. Also
78 // used to cap total bitrate used.
pbos@webrtc.org00873182014-11-25 14:03:34 +000079 struct BitrateConfig {
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020080 int min_bitrate_bps = 0;
81 int start_bitrate_bps = kDefaultStartBitrateBps;
82 int max_bitrate_bps = -1;
Stefan Holmere5904162015-03-26 11:11:06 +010083 } bitrate_config;
Fredrik Solenberg04f49312015-06-08 13:04:56 +020084
solenberg566ef242015-11-06 15:34:49 -080085 // AudioState which is possibly shared between multiple calls.
86 // TODO(solenberg): Change this to a shared_ptr once we can use C++11.
87 rtc::scoped_refptr<AudioState> audio_state;
88
89 // Audio Processing Module to be used in this call.
90 // TODO(solenberg): Change this to a shared_ptr once we can use C++11.
91 AudioProcessing* audio_processing = nullptr;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000092 };
93
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +000094 struct Stats {
asapersson2e5cfcd2016-08-11 08:41:18 -070095 std::string ToString(int64_t time_ms) const;
96
sprang9c0b5512016-07-06 00:54:28 -070097 int send_bandwidth_bps = 0; // Estimated available send bandwidth.
98 int max_padding_bitrate_bps = 0; // Cumulative configured max padding.
99 int recv_bandwidth_bps = 0; // Estimated available receive bandwidth.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200100 int64_t pacer_delay_ms = 0;
101 int64_t rtt_ms = -1;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000102 };
103
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000104 static Call* Create(const Call::Config& config);
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000105
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200106 virtual AudioSendStream* CreateAudioSendStream(
107 const AudioSendStream::Config& config) = 0;
108 virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
109
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200110 virtual AudioReceiveStream* CreateAudioReceiveStream(
111 const AudioReceiveStream::Config& config) = 0;
112 virtual void DestroyAudioReceiveStream(
113 AudioReceiveStream* receive_stream) = 0;
114
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000115 virtual VideoSendStream* CreateVideoSendStream(
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000116 const VideoSendStream::Config& config,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000117 const VideoEncoderConfig& encoder_config) = 0;
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000118 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000119
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000120 virtual VideoReceiveStream* CreateVideoReceiveStream(
Tommi733b5472016-06-10 17:58:01 +0200121 VideoReceiveStream::Config configuration) = 0;
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000122 virtual void DestroyVideoReceiveStream(
123 VideoReceiveStream* receive_stream) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000124
125 // All received RTP and RTCP packets for the call should be inserted to this
126 // PacketReceiver. The PacketReceiver pointer is valid as long as the
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000127 // Call instance exists.
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000128 virtual PacketReceiver* Receiver() = 0;
129
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000130 // Returns the call statistics, such as estimated send and receive bandwidth,
131 // pacing delay, etc.
132 virtual Stats GetStats() const = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000133
pbos@webrtc.org00873182014-11-25 14:03:34 +0000134 // TODO(pbos): Like BitrateConfig above this is currently per-stream instead
135 // of maximum for entire Call. This should be fixed along with the above.
136 // Specifying a start bitrate (>0) will currently reset the current bitrate
137 // estimate. This is due to how the 'x-google-start-bitrate' flag is currently
138 // implemented.
139 virtual void SetBitrateConfig(
140 const Config::BitrateConfig& bitrate_config) = 0;
skvlad7a43d252016-03-22 15:32:27 -0700141
142 // TODO(skvlad): When the unbundled case with multiple streams for the same
143 // media type going over different networks is supported, track the state
144 // for each stream separately. Right now it's global per media type.
145 virtual void SignalChannelNetworkState(MediaType media,
146 NetworkState state) = 0;
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000147
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700148 virtual void OnNetworkRouteChanged(
149 const std::string& transport_name,
150 const rtc::NetworkRoute& network_route) = 0;
151
stefanc1aeaf02015-10-15 07:26:07 -0700152 virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
153
ivoc14d5dbe2016-07-04 07:06:55 -0700154 virtual bool StartEventLog(rtc::PlatformFile log_file,
155 int64_t max_size_bytes) = 0;
156 virtual void StopEventLog() = 0;
157
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000158 virtual ~Call() {}
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000159};
Jelena Marusiccd670222015-07-16 09:30:09 +0200160
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000161} // namespace webrtc
162
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000163#endif // WEBRTC_CALL_H_