blob: 9855b600f050ebd64cd02a5639869c0b59c4e38e [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"
Honghai Zhang0e533ef2016-04-19 15:41:36 -070019#include "webrtc/base/networkroute.h"
ivoc14d5dbe2016-07-04 07:06:55 -070020#include "webrtc/base/platform_file.h"
stefanc1aeaf02015-10-15 07:26:07 -070021#include "webrtc/base/socket.h"
kjellandera69d9732016-08-31 07:33:05 -070022#include "webrtc/common_types.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;
skvlad11a9cbf2016-10-07 11:53:05 -070029class RtcEventLog;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000030
31const char* Version();
32
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020033enum class MediaType {
34 ANY,
35 AUDIO,
36 VIDEO,
37 DATA
38};
39
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000040class PacketReceiver {
41 public:
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +000042 enum DeliveryStatus {
43 DELIVERY_OK,
44 DELIVERY_UNKNOWN_SSRC,
45 DELIVERY_PACKET_ERROR,
46 };
47
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020048 virtual DeliveryStatus DeliverPacket(MediaType media_type,
49 const uint8_t* packet,
stefan68786d22015-09-08 05:36:15 -070050 size_t length,
51 const PacketTime& packet_time) = 0;
52
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000053 protected:
54 virtual ~PacketReceiver() {}
55};
56
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000057// Callback interface for reporting when a system overuse is detected.
pbos@webrtc.org42684be2014-10-03 11:25:45 +000058class LoadObserver {
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000059 public:
pbos@webrtc.org42684be2014-10-03 11:25:45 +000060 enum Load { kOveruse, kUnderuse };
61
62 // Triggered when overuse is detected or when we believe the system can take
63 // more load.
64 virtual void OnLoadUpdate(Load load) = 0;
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000065
66 protected:
pbos@webrtc.org42684be2014-10-03 11:25:45 +000067 virtual ~LoadObserver() {}
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000068};
69
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000070// A Call instance can contain several send and/or receive streams. All streams
71// are assumed to have the same remote endpoint and will share bitrate estimates
72// etc.
73class Call {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000074 public:
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000075 struct Config {
skvlad11a9cbf2016-10-07 11:53:05 -070076 explicit Config(RtcEventLog* event_log) : event_log(event_log) {
77 RTC_DCHECK(event_log);
78 }
79
pbos@webrtc.orga73a6782014-10-14 11:52:10 +000080 static const int kDefaultStartBitrateBps;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000081
pbos@webrtc.org00873182014-11-25 14:03:34 +000082 // Bitrate config used until valid bitrate estimates are calculated. Also
83 // used to cap total bitrate used.
pbos@webrtc.org00873182014-11-25 14:03:34 +000084 struct BitrateConfig {
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020085 int min_bitrate_bps = 0;
86 int start_bitrate_bps = kDefaultStartBitrateBps;
87 int max_bitrate_bps = -1;
Stefan Holmere5904162015-03-26 11:11:06 +010088 } bitrate_config;
Fredrik Solenberg04f49312015-06-08 13:04:56 +020089
solenberg566ef242015-11-06 15:34:49 -080090 // AudioState which is possibly shared between multiple calls.
91 // TODO(solenberg): Change this to a shared_ptr once we can use C++11.
92 rtc::scoped_refptr<AudioState> audio_state;
93
94 // Audio Processing Module to be used in this call.
95 // TODO(solenberg): Change this to a shared_ptr once we can use C++11.
96 AudioProcessing* audio_processing = nullptr;
skvlad11a9cbf2016-10-07 11:53:05 -070097
98 // RtcEventLog to use for this call. Required.
99 // Use webrtc::RtcEventLog::CreateNull() for a null implementation.
100 RtcEventLog* event_log = nullptr;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +0000101 };
102
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000103 struct Stats {
asapersson2e5cfcd2016-08-11 08:41:18 -0700104 std::string ToString(int64_t time_ms) const;
105
sprang9c0b5512016-07-06 00:54:28 -0700106 int send_bandwidth_bps = 0; // Estimated available send bandwidth.
107 int max_padding_bitrate_bps = 0; // Cumulative configured max padding.
108 int recv_bandwidth_bps = 0; // Estimated available receive bandwidth.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200109 int64_t pacer_delay_ms = 0;
110 int64_t rtt_ms = -1;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000111 };
112
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000113 static Call* Create(const Call::Config& config);
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000114
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200115 virtual AudioSendStream* CreateAudioSendStream(
116 const AudioSendStream::Config& config) = 0;
117 virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
118
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200119 virtual AudioReceiveStream* CreateAudioReceiveStream(
120 const AudioReceiveStream::Config& config) = 0;
121 virtual void DestroyAudioReceiveStream(
122 AudioReceiveStream* receive_stream) = 0;
123
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000124 virtual VideoSendStream* CreateVideoSendStream(
perkj26091b12016-09-01 01:17:40 -0700125 VideoSendStream::Config config,
126 VideoEncoderConfig encoder_config) = 0;
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000127 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000128
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000129 virtual VideoReceiveStream* CreateVideoReceiveStream(
Tommi733b5472016-06-10 17:58:01 +0200130 VideoReceiveStream::Config configuration) = 0;
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000131 virtual void DestroyVideoReceiveStream(
132 VideoReceiveStream* receive_stream) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000133
134 // All received RTP and RTCP packets for the call should be inserted to this
135 // PacketReceiver. The PacketReceiver pointer is valid as long as the
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000136 // Call instance exists.
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000137 virtual PacketReceiver* Receiver() = 0;
138
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000139 // Returns the call statistics, such as estimated send and receive bandwidth,
140 // pacing delay, etc.
141 virtual Stats GetStats() const = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000142
pbos@webrtc.org00873182014-11-25 14:03:34 +0000143 // TODO(pbos): Like BitrateConfig above this is currently per-stream instead
144 // of maximum for entire Call. This should be fixed along with the above.
145 // Specifying a start bitrate (>0) will currently reset the current bitrate
146 // estimate. This is due to how the 'x-google-start-bitrate' flag is currently
147 // implemented.
148 virtual void SetBitrateConfig(
149 const Config::BitrateConfig& bitrate_config) = 0;
skvlad7a43d252016-03-22 15:32:27 -0700150
151 // TODO(skvlad): When the unbundled case with multiple streams for the same
152 // media type going over different networks is supported, track the state
153 // for each stream separately. Right now it's global per media type.
154 virtual void SignalChannelNetworkState(MediaType media,
155 NetworkState state) = 0;
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000156
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700157 virtual void OnNetworkRouteChanged(
158 const std::string& transport_name,
159 const rtc::NetworkRoute& network_route) = 0;
160
stefanc1aeaf02015-10-15 07:26:07 -0700161 virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
162
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000163 virtual ~Call() {}
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000164};
Jelena Marusiccd670222015-07-16 09:30:09 +0200165
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000166} // namespace webrtc
167
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000168#endif // WEBRTC_CALL_H_