blob: 6ad716dff8e7267b68c22dd1d0021c7e7ee92152 [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"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000018#include "webrtc/video_receive_stream.h"
19#include "webrtc/video_send_stream.h"
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000020
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000021namespace webrtc {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000022
23class VoiceEngine;
24
25const char* Version();
26
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020027enum class MediaType {
28 ANY,
29 AUDIO,
30 VIDEO,
31 DATA
32};
33
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000034class PacketReceiver {
35 public:
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +000036 enum DeliveryStatus {
37 DELIVERY_OK,
38 DELIVERY_UNKNOWN_SSRC,
39 DELIVERY_PACKET_ERROR,
40 };
41
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020042 virtual DeliveryStatus DeliverPacket(MediaType media_type,
43 const uint8_t* packet,
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +000044 size_t length) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000045 protected:
46 virtual ~PacketReceiver() {}
47};
48
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000049// Callback interface for reporting when a system overuse is detected.
pbos@webrtc.org42684be2014-10-03 11:25:45 +000050class LoadObserver {
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000051 public:
pbos@webrtc.org42684be2014-10-03 11:25:45 +000052 enum Load { kOveruse, kUnderuse };
53
54 // Triggered when overuse is detected or when we believe the system can take
55 // more load.
56 virtual void OnLoadUpdate(Load load) = 0;
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000057
58 protected:
pbos@webrtc.org42684be2014-10-03 11:25:45 +000059 virtual ~LoadObserver() {}
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000060};
61
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000062// A Call instance can contain several send and/or receive streams. All streams
63// are assumed to have the same remote endpoint and will share bitrate estimates
64// etc.
65class Call {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000066 public:
pbos@webrtc.org26c0c412014-09-03 16:17:12 +000067 enum NetworkState {
68 kNetworkUp,
69 kNetworkDown,
70 };
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000071 struct Config {
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000072 explicit Config(newapi::Transport* send_transport)
Peter Boström76c53d32015-04-09 14:35:37 +020073 : send_transport(send_transport),
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +000074 voice_engine(NULL),
pbos@webrtc.org00873182014-11-25 14:03:34 +000075 overuse_callback(NULL) {}
pbos@webrtc.orga73a6782014-10-14 11:52:10 +000076
77 static const int kDefaultStartBitrateBps;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000078
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000079 newapi::Transport* send_transport;
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +000080
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000081 // VoiceEngine used for audio/video synchronization for this Call.
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +000082 VoiceEngine* voice_engine;
83
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000084 // Callback for overuse and normal usage based on the jitter of incoming
85 // captured frames. 'NULL' disables the callback.
pbos@webrtc.org42684be2014-10-03 11:25:45 +000086 LoadObserver* overuse_callback;
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +000087
pbos@webrtc.org00873182014-11-25 14:03:34 +000088 // Bitrate config used until valid bitrate estimates are calculated. Also
89 // used to cap total bitrate used.
pbos@webrtc.org00873182014-11-25 14:03:34 +000090 struct BitrateConfig {
91 BitrateConfig()
92 : min_bitrate_bps(0),
93 start_bitrate_bps(kDefaultStartBitrateBps),
94 max_bitrate_bps(-1) {}
95 int min_bitrate_bps;
96 int start_bitrate_bps;
97 int max_bitrate_bps;
Stefan Holmere5904162015-03-26 11:11:06 +010098 } bitrate_config;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000099 };
100
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000101 struct Stats {
pbos@webrtc.org2b19f062014-12-11 13:26:09 +0000102 Stats()
103 : send_bandwidth_bps(0),
104 recv_bandwidth_bps(0),
105 pacer_delay_ms(0),
106 rtt_ms(-1) {}
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000107
108 int send_bandwidth_bps;
109 int recv_bandwidth_bps;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000110 int64_t pacer_delay_ms;
111 int64_t rtt_ms;
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 Solenberg23fba1f2015-04-29 15:24:01 +0200116 virtual AudioReceiveStream* CreateAudioReceiveStream(
117 const AudioReceiveStream::Config& config) = 0;
118 virtual void DestroyAudioReceiveStream(
119 AudioReceiveStream* receive_stream) = 0;
120
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000121 virtual VideoSendStream* CreateVideoSendStream(
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000122 const VideoSendStream::Config& config,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000123 const VideoEncoderConfig& encoder_config) = 0;
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000124 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000125
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000126 virtual VideoReceiveStream* CreateVideoReceiveStream(
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000127 const VideoReceiveStream::Config& config) = 0;
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000128 virtual void DestroyVideoReceiveStream(
129 VideoReceiveStream* receive_stream) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000130
131 // All received RTP and RTCP packets for the call should be inserted to this
132 // PacketReceiver. The PacketReceiver pointer is valid as long as the
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000133 // Call instance exists.
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000134 virtual PacketReceiver* Receiver() = 0;
135
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000136 // Returns the call statistics, such as estimated send and receive bandwidth,
137 // pacing delay, etc.
138 virtual Stats GetStats() const = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000139
pbos@webrtc.org00873182014-11-25 14:03:34 +0000140 // TODO(pbos): Like BitrateConfig above this is currently per-stream instead
141 // of maximum for entire Call. This should be fixed along with the above.
142 // Specifying a start bitrate (>0) will currently reset the current bitrate
143 // estimate. This is due to how the 'x-google-start-bitrate' flag is currently
144 // implemented.
145 virtual void SetBitrateConfig(
146 const Config::BitrateConfig& bitrate_config) = 0;
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000147 virtual void SignalNetworkState(NetworkState state) = 0;
148
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000149 virtual ~Call() {}
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000150};
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000151} // namespace webrtc
152
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000153#endif // WEBRTC_CALL_H_