blob: 4319cc5e5b9b6991235c5febd2ed758238288153 [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"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000017#include "webrtc/video_receive_stream.h"
18#include "webrtc/video_send_stream.h"
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000019
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000020namespace webrtc {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000021
22class VoiceEngine;
23
24const char* Version();
25
26class PacketReceiver {
27 public:
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +000028 enum DeliveryStatus {
29 DELIVERY_OK,
30 DELIVERY_UNKNOWN_SSRC,
31 DELIVERY_PACKET_ERROR,
32 };
33
34 virtual DeliveryStatus DeliverPacket(const uint8_t* packet,
35 size_t length) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000036
37 protected:
38 virtual ~PacketReceiver() {}
39};
40
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000041// Callback interface for reporting when a system overuse is detected.
pbos@webrtc.org42684be2014-10-03 11:25:45 +000042class LoadObserver {
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000043 public:
pbos@webrtc.org42684be2014-10-03 11:25:45 +000044 enum Load { kOveruse, kUnderuse };
45
46 // Triggered when overuse is detected or when we believe the system can take
47 // more load.
48 virtual void OnLoadUpdate(Load load) = 0;
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000049
50 protected:
pbos@webrtc.org42684be2014-10-03 11:25:45 +000051 virtual ~LoadObserver() {}
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000052};
53
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000054// A Call instance can contain several send and/or receive streams. All streams
55// are assumed to have the same remote endpoint and will share bitrate estimates
56// etc.
57class Call {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000058 public:
pbos@webrtc.org26c0c412014-09-03 16:17:12 +000059 enum NetworkState {
60 kNetworkUp,
61 kNetworkDown,
62 };
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000063 struct Config {
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000064 explicit Config(newapi::Transport* send_transport)
Peter Boström76c53d32015-04-09 14:35:37 +020065 : send_transport(send_transport),
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +000066 voice_engine(NULL),
pbos@webrtc.org00873182014-11-25 14:03:34 +000067 overuse_callback(NULL) {}
pbos@webrtc.orga73a6782014-10-14 11:52:10 +000068
69 static const int kDefaultStartBitrateBps;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000070
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000071 newapi::Transport* send_transport;
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +000072
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000073 // VoiceEngine used for audio/video synchronization for this Call.
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +000074 VoiceEngine* voice_engine;
75
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000076 // Callback for overuse and normal usage based on the jitter of incoming
77 // captured frames. 'NULL' disables the callback.
pbos@webrtc.org42684be2014-10-03 11:25:45 +000078 LoadObserver* overuse_callback;
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +000079
pbos@webrtc.org00873182014-11-25 14:03:34 +000080 // Bitrate config used until valid bitrate estimates are calculated. Also
81 // used to cap total bitrate used.
pbos@webrtc.org00873182014-11-25 14:03:34 +000082 struct BitrateConfig {
83 BitrateConfig()
84 : min_bitrate_bps(0),
85 start_bitrate_bps(kDefaultStartBitrateBps),
86 max_bitrate_bps(-1) {}
87 int min_bitrate_bps;
88 int start_bitrate_bps;
89 int max_bitrate_bps;
Stefan Holmere5904162015-03-26 11:11:06 +010090 } bitrate_config;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000091 };
92
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +000093 struct Stats {
pbos@webrtc.org2b19f062014-12-11 13:26:09 +000094 Stats()
95 : send_bandwidth_bps(0),
96 recv_bandwidth_bps(0),
97 pacer_delay_ms(0),
98 rtt_ms(-1) {}
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +000099
100 int send_bandwidth_bps;
101 int recv_bandwidth_bps;
pkasting@chromium.org16825b12015-01-12 21:51:21 +0000102 int64_t pacer_delay_ms;
103 int64_t rtt_ms;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000104 };
105
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000106 static Call* Create(const Call::Config& config);
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000107
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000108 virtual VideoSendStream* CreateVideoSendStream(
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000109 const VideoSendStream::Config& config,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000110 const VideoEncoderConfig& encoder_config) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000111
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000112 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000113
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000114 virtual VideoReceiveStream* CreateVideoReceiveStream(
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000115 const VideoReceiveStream::Config& config) = 0;
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000116 virtual void DestroyVideoReceiveStream(
117 VideoReceiveStream* receive_stream) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000118
119 // All received RTP and RTCP packets for the call should be inserted to this
120 // PacketReceiver. The PacketReceiver pointer is valid as long as the
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000121 // Call instance exists.
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000122 virtual PacketReceiver* Receiver() = 0;
123
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000124 // Returns the call statistics, such as estimated send and receive bandwidth,
125 // pacing delay, etc.
126 virtual Stats GetStats() const = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000127
pbos@webrtc.org00873182014-11-25 14:03:34 +0000128 // TODO(pbos): Like BitrateConfig above this is currently per-stream instead
129 // of maximum for entire Call. This should be fixed along with the above.
130 // Specifying a start bitrate (>0) will currently reset the current bitrate
131 // estimate. This is due to how the 'x-google-start-bitrate' flag is currently
132 // implemented.
133 virtual void SetBitrateConfig(
134 const Config::BitrateConfig& bitrate_config) = 0;
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000135 virtual void SignalNetworkState(NetworkState state) = 0;
136
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000137 virtual ~Call() {}
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000138};
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000139} // namespace webrtc
140
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000141#endif // WEBRTC_CALL_H_