blob: d9143037c6edb4699d820fbfe402ceddd93a7c86 [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
kjellandera69d9732016-08-31 07:33:05 -070016#include "webrtc/api/call/audio_receive_stream.h"
17#include "webrtc/api/call/audio_send_stream.h"
18#include "webrtc/api/call/audio_state.h"
brandtr25445d32016-10-23 23:37:14 -070019#include "webrtc/api/call/flexfec_receive_stream.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"
kjellandera69d9732016-08-31 07:33:05 -070023#include "webrtc/common_types.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000024#include "webrtc/video_receive_stream.h"
25#include "webrtc/video_send_stream.h"
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000026
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000027namespace webrtc {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000028
Fredrik Solenberg04f49312015-06-08 13:04:56 +020029class AudioProcessing;
skvlad11a9cbf2016-10-07 11:53:05 -070030class RtcEventLog;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000031
32const char* Version();
33
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020034enum class MediaType {
35 ANY,
36 AUDIO,
37 VIDEO,
38 DATA
39};
40
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000041class PacketReceiver {
42 public:
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +000043 enum DeliveryStatus {
44 DELIVERY_OK,
45 DELIVERY_UNKNOWN_SSRC,
46 DELIVERY_PACKET_ERROR,
47 };
48
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020049 virtual DeliveryStatus DeliverPacket(MediaType media_type,
50 const uint8_t* packet,
stefan68786d22015-09-08 05:36:15 -070051 size_t length,
52 const PacketTime& packet_time) = 0;
53
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000054 protected:
55 virtual ~PacketReceiver() {}
56};
57
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000058// Callback interface for reporting when a system overuse is detected.
pbos@webrtc.org42684be2014-10-03 11:25:45 +000059class LoadObserver {
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000060 public:
pbos@webrtc.org42684be2014-10-03 11:25:45 +000061 enum Load { kOveruse, kUnderuse };
62
63 // Triggered when overuse is detected or when we believe the system can take
64 // more load.
65 virtual void OnLoadUpdate(Load load) = 0;
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000066
67 protected:
pbos@webrtc.org42684be2014-10-03 11:25:45 +000068 virtual ~LoadObserver() {}
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000069};
70
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000071// A Call instance can contain several send and/or receive streams. All streams
72// are assumed to have the same remote endpoint and will share bitrate estimates
73// etc.
74class Call {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000075 public:
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000076 struct Config {
skvlad11a9cbf2016-10-07 11:53:05 -070077 explicit Config(RtcEventLog* event_log) : event_log(event_log) {
78 RTC_DCHECK(event_log);
79 }
80
pbos@webrtc.orga73a6782014-10-14 11:52:10 +000081 static const int kDefaultStartBitrateBps;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000082
pbos@webrtc.org00873182014-11-25 14:03:34 +000083 // Bitrate config used until valid bitrate estimates are calculated. Also
84 // used to cap total bitrate used.
pbos@webrtc.org00873182014-11-25 14:03:34 +000085 struct BitrateConfig {
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020086 int min_bitrate_bps = 0;
87 int start_bitrate_bps = kDefaultStartBitrateBps;
88 int max_bitrate_bps = -1;
Stefan Holmere5904162015-03-26 11:11:06 +010089 } bitrate_config;
Fredrik Solenberg04f49312015-06-08 13:04:56 +020090
solenberg566ef242015-11-06 15:34:49 -080091 // AudioState which is possibly shared between multiple calls.
92 // TODO(solenberg): Change this to a shared_ptr once we can use C++11.
93 rtc::scoped_refptr<AudioState> audio_state;
94
95 // Audio Processing Module to be used in this call.
96 // TODO(solenberg): Change this to a shared_ptr once we can use C++11.
97 AudioProcessing* audio_processing = nullptr;
skvlad11a9cbf2016-10-07 11:53:05 -070098
99 // RtcEventLog to use for this call. Required.
100 // Use webrtc::RtcEventLog::CreateNull() for a null implementation.
101 RtcEventLog* event_log = nullptr;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +0000102 };
103
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000104 struct Stats {
asapersson2e5cfcd2016-08-11 08:41:18 -0700105 std::string ToString(int64_t time_ms) const;
106
sprang9c0b5512016-07-06 00:54:28 -0700107 int send_bandwidth_bps = 0; // Estimated available send bandwidth.
108 int max_padding_bitrate_bps = 0; // Cumulative configured max padding.
109 int recv_bandwidth_bps = 0; // Estimated available receive bandwidth.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200110 int64_t pacer_delay_ms = 0;
111 int64_t rtt_ms = -1;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000112 };
113
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000114 static Call* Create(const Call::Config& config);
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000115
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200116 virtual AudioSendStream* CreateAudioSendStream(
117 const AudioSendStream::Config& config) = 0;
118 virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
119
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200120 virtual AudioReceiveStream* CreateAudioReceiveStream(
121 const AudioReceiveStream::Config& config) = 0;
122 virtual void DestroyAudioReceiveStream(
123 AudioReceiveStream* receive_stream) = 0;
124
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000125 virtual VideoSendStream* CreateVideoSendStream(
perkj26091b12016-09-01 01:17:40 -0700126 VideoSendStream::Config config,
127 VideoEncoderConfig encoder_config) = 0;
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000128 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000129
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000130 virtual VideoReceiveStream* CreateVideoReceiveStream(
Tommi733b5472016-06-10 17:58:01 +0200131 VideoReceiveStream::Config configuration) = 0;
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000132 virtual void DestroyVideoReceiveStream(
133 VideoReceiveStream* receive_stream) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000134
brandtr25445d32016-10-23 23:37:14 -0700135 virtual FlexfecReceiveStream* CreateFlexfecReceiveStream(
136 FlexfecReceiveStream::Config configuration) = 0;
137 virtual void DestroyFlexfecReceiveStream(
138 FlexfecReceiveStream* receive_stream) = 0;
139
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000140 // All received RTP and RTCP packets for the call should be inserted to this
141 // PacketReceiver. The PacketReceiver pointer is valid as long as the
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000142 // Call instance exists.
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000143 virtual PacketReceiver* Receiver() = 0;
144
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000145 // Returns the call statistics, such as estimated send and receive bandwidth,
146 // pacing delay, etc.
147 virtual Stats GetStats() const = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000148
pbos@webrtc.org00873182014-11-25 14:03:34 +0000149 // TODO(pbos): Like BitrateConfig above this is currently per-stream instead
150 // of maximum for entire Call. This should be fixed along with the above.
151 // Specifying a start bitrate (>0) will currently reset the current bitrate
152 // estimate. This is due to how the 'x-google-start-bitrate' flag is currently
153 // implemented.
154 virtual void SetBitrateConfig(
155 const Config::BitrateConfig& bitrate_config) = 0;
skvlad7a43d252016-03-22 15:32:27 -0700156
157 // TODO(skvlad): When the unbundled case with multiple streams for the same
158 // media type going over different networks is supported, track the state
159 // for each stream separately. Right now it's global per media type.
160 virtual void SignalChannelNetworkState(MediaType media,
161 NetworkState state) = 0;
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000162
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700163 virtual void OnNetworkRouteChanged(
164 const std::string& transport_name,
165 const rtc::NetworkRoute& network_route) = 0;
166
stefanc1aeaf02015-10-15 07:26:07 -0700167 virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
168
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000169 virtual ~Call() {}
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000170};
Jelena Marusiccd670222015-07-16 09:30:09 +0200171
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000172} // namespace webrtc
173
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000174#endif // WEBRTC_CALL_H_