blob: 779ffe9d0de68e015117792614e6d2a10e68e83d [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 {
sprang9c0b5512016-07-06 00:54:28 -070095 int send_bandwidth_bps = 0; // Estimated available send bandwidth.
96 int max_padding_bitrate_bps = 0; // Cumulative configured max padding.
97 int recv_bandwidth_bps = 0; // Estimated available receive bandwidth.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020098 int64_t pacer_delay_ms = 0;
99 int64_t rtt_ms = -1;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000100 };
101
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000102 static Call* Create(const Call::Config& config);
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000103
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200104 virtual AudioSendStream* CreateAudioSendStream(
105 const AudioSendStream::Config& config) = 0;
106 virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
107
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200108 virtual AudioReceiveStream* CreateAudioReceiveStream(
109 const AudioReceiveStream::Config& config) = 0;
110 virtual void DestroyAudioReceiveStream(
111 AudioReceiveStream* receive_stream) = 0;
112
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000113 virtual VideoSendStream* CreateVideoSendStream(
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000114 const VideoSendStream::Config& config,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000115 const VideoEncoderConfig& encoder_config) = 0;
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000116 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000117
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000118 virtual VideoReceiveStream* CreateVideoReceiveStream(
Tommi733b5472016-06-10 17:58:01 +0200119 VideoReceiveStream::Config configuration) = 0;
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000120 virtual void DestroyVideoReceiveStream(
121 VideoReceiveStream* receive_stream) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000122
123 // All received RTP and RTCP packets for the call should be inserted to this
124 // PacketReceiver. The PacketReceiver pointer is valid as long as the
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000125 // Call instance exists.
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000126 virtual PacketReceiver* Receiver() = 0;
127
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000128 // Returns the call statistics, such as estimated send and receive bandwidth,
129 // pacing delay, etc.
130 virtual Stats GetStats() const = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000131
pbos@webrtc.org00873182014-11-25 14:03:34 +0000132 // TODO(pbos): Like BitrateConfig above this is currently per-stream instead
133 // of maximum for entire Call. This should be fixed along with the above.
134 // Specifying a start bitrate (>0) will currently reset the current bitrate
135 // estimate. This is due to how the 'x-google-start-bitrate' flag is currently
136 // implemented.
137 virtual void SetBitrateConfig(
138 const Config::BitrateConfig& bitrate_config) = 0;
skvlad7a43d252016-03-22 15:32:27 -0700139
140 // TODO(skvlad): When the unbundled case with multiple streams for the same
141 // media type going over different networks is supported, track the state
142 // for each stream separately. Right now it's global per media type.
143 virtual void SignalChannelNetworkState(MediaType media,
144 NetworkState state) = 0;
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000145
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700146 virtual void OnNetworkRouteChanged(
147 const std::string& transport_name,
148 const rtc::NetworkRoute& network_route) = 0;
149
stefanc1aeaf02015-10-15 07:26:07 -0700150 virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
151
ivoc14d5dbe2016-07-04 07:06:55 -0700152 virtual bool StartEventLog(rtc::PlatformFile log_file,
153 int64_t max_size_bytes) = 0;
154 virtual void StopEventLog() = 0;
155
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000156 virtual ~Call() {}
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000157};
Jelena Marusiccd670222015-07-16 09:30:09 +0200158
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000159} // namespace webrtc
160
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000161#endif // WEBRTC_CALL_H_