blob: 920c00660d837ae10e69912816baef41bc813035 [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)
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +000065 : webrtc_config(NULL),
66 send_transport(send_transport),
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +000067 voice_engine(NULL),
pbos@webrtc.org00873182014-11-25 14:03:34 +000068 overuse_callback(NULL) {}
pbos@webrtc.orga73a6782014-10-14 11:52:10 +000069
70 static const int kDefaultStartBitrateBps;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000071
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +000072 webrtc::Config* webrtc_config;
73
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000074 newapi::Transport* send_transport;
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +000075
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000076 // VoiceEngine used for audio/video synchronization for this Call.
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +000077 VoiceEngine* voice_engine;
78
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000079 // Callback for overuse and normal usage based on the jitter of incoming
80 // captured frames. 'NULL' disables the callback.
pbos@webrtc.org42684be2014-10-03 11:25:45 +000081 LoadObserver* overuse_callback;
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +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.orga73a6782014-10-14 11:52:10 +000085 // Note: This is currently set only for video and is per-stream rather of
86 // for the entire link.
87 // TODO(pbos): Set start bitrate for entire Call.
pbos@webrtc.org00873182014-11-25 14:03:34 +000088 struct BitrateConfig {
89 BitrateConfig()
90 : min_bitrate_bps(0),
91 start_bitrate_bps(kDefaultStartBitrateBps),
92 max_bitrate_bps(-1) {}
93 int min_bitrate_bps;
94 int start_bitrate_bps;
95 int max_bitrate_bps;
96 } stream_bitrates;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000097 };
98
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +000099 struct Stats {
100 Stats() : send_bandwidth_bps(0), recv_bandwidth_bps(0), pacer_delay_ms(0) {}
101
102 int send_bandwidth_bps;
103 int recv_bandwidth_bps;
104 int pacer_delay_ms;
105 };
106
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000107 static Call* Create(const Call::Config& config);
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000108
stefan@webrtc.org7e9315b2013-12-04 10:24:26 +0000109 static Call* Create(const Call::Config& config,
110 const webrtc::Config& webrtc_config);
111
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000112 virtual VideoSendStream* CreateVideoSendStream(
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000113 const VideoSendStream::Config& config,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000114 const VideoEncoderConfig& encoder_config) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000115
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(
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000119 const VideoReceiveStream::Config& config) = 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;
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000139 virtual void SignalNetworkState(NetworkState state) = 0;
140
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000141 virtual ~Call() {}
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000142};
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000143} // namespace webrtc
144
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000145#endif // WEBRTC_CALL_H_