blob: b94029db4730c143c22a9b84c6372af1ca9e6d0f [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"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000019#include "webrtc/video_receive_stream.h"
20#include "webrtc/video_send_stream.h"
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000021
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000022namespace webrtc {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000023
Fredrik Solenberg04f49312015-06-08 13:04:56 +020024class AudioDeviceModule;
25class AudioProcessing;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000026class VoiceEngine;
Fredrik Solenberg04f49312015-06-08 13:04:56 +020027class VoiceEngineObserver;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000028
29const char* Version();
30
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020031enum class MediaType {
32 ANY,
33 AUDIO,
34 VIDEO,
35 DATA
36};
37
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000038class PacketReceiver {
39 public:
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +000040 enum DeliveryStatus {
41 DELIVERY_OK,
42 DELIVERY_UNKNOWN_SSRC,
43 DELIVERY_PACKET_ERROR,
44 };
45
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020046 virtual DeliveryStatus DeliverPacket(MediaType media_type,
47 const uint8_t* packet,
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +000048 size_t length) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000049 protected:
50 virtual ~PacketReceiver() {}
51};
52
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000053// Callback interface for reporting when a system overuse is detected.
pbos@webrtc.org42684be2014-10-03 11:25:45 +000054class LoadObserver {
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000055 public:
pbos@webrtc.org42684be2014-10-03 11:25:45 +000056 enum Load { kOveruse, kUnderuse };
57
58 // Triggered when overuse is detected or when we believe the system can take
59 // more load.
60 virtual void OnLoadUpdate(Load load) = 0;
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000061
62 protected:
pbos@webrtc.org42684be2014-10-03 11:25:45 +000063 virtual ~LoadObserver() {}
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000064};
65
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000066// A Call instance can contain several send and/or receive streams. All streams
67// are assumed to have the same remote endpoint and will share bitrate estimates
68// etc.
69class Call {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000070 public:
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000071 struct Config {
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020072 Config() = delete;
pbos@webrtc.org74fa4892013-08-23 09:19:30 +000073 explicit Config(newapi::Transport* send_transport)
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020074 : send_transport(send_transport) {}
pbos@webrtc.orga73a6782014-10-14 11:52:10 +000075
76 static const int kDefaultStartBitrateBps;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000077
Fredrik Solenberg04f49312015-06-08 13:04:56 +020078 // TODO(solenberg): Need to add media type to the interface for outgoing
79 // packets too.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020080 newapi::Transport* send_transport = nullptr;
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +000081
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000082 // VoiceEngine used for audio/video synchronization for this Call.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020083 VoiceEngine* voice_engine = nullptr;
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +000084
asapersson@webrtc.orgbdc5ed22014-01-31 10:05:07 +000085 // Callback for overuse and normal usage based on the jitter of incoming
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020086 // captured frames. 'nullptr' disables the callback.
87 LoadObserver* overuse_callback = nullptr;
mflodman@webrtc.orgeb16b812014-06-16 08:57:39 +000088
pbos@webrtc.org00873182014-11-25 14:03:34 +000089 // Bitrate config used until valid bitrate estimates are calculated. Also
90 // used to cap total bitrate used.
pbos@webrtc.org00873182014-11-25 14:03:34 +000091 struct BitrateConfig {
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020092 int min_bitrate_bps = 0;
93 int start_bitrate_bps = kDefaultStartBitrateBps;
94 int max_bitrate_bps = -1;
Stefan Holmere5904162015-03-26 11:11:06 +010095 } bitrate_config;
Fredrik Solenberg04f49312015-06-08 13:04:56 +020096
97 struct AudioConfig {
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020098 AudioDeviceModule* audio_device_manager = nullptr;
99 AudioProcessing* audio_processing = nullptr;
100 VoiceEngineObserver* voice_engine_observer = nullptr;
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200101 } audio_config;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +0000102 };
103
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000104 struct Stats {
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +0200105 int send_bandwidth_bps = 0;
106 int recv_bandwidth_bps = 0;
107 int64_t pacer_delay_ms = 0;
108 int64_t rtt_ms = -1;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000109 };
110
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000111 static Call* Create(const Call::Config& config);
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000112
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200113 virtual AudioSendStream* CreateAudioSendStream(
114 const AudioSendStream::Config& config) = 0;
115 virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
116
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200117 virtual AudioReceiveStream* CreateAudioReceiveStream(
118 const AudioReceiveStream::Config& config) = 0;
119 virtual void DestroyAudioReceiveStream(
120 AudioReceiveStream* receive_stream) = 0;
121
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000122 virtual VideoSendStream* CreateVideoSendStream(
pbos@webrtc.org6ae48c62014-06-06 10:49:19 +0000123 const VideoSendStream::Config& config,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000124 const VideoEncoderConfig& encoder_config) = 0;
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000125 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000126
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000127 virtual VideoReceiveStream* CreateVideoReceiveStream(
pbos@webrtc.org025f4f12013-06-05 11:33:21 +0000128 const VideoReceiveStream::Config& config) = 0;
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000129 virtual void DestroyVideoReceiveStream(
130 VideoReceiveStream* receive_stream) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000131
132 // All received RTP and RTCP packets for the call should be inserted to this
133 // PacketReceiver. The PacketReceiver pointer is valid as long as the
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000134 // Call instance exists.
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000135 virtual PacketReceiver* Receiver() = 0;
136
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000137 // Returns the call statistics, such as estimated send and receive bandwidth,
138 // pacing delay, etc.
139 virtual Stats GetStats() const = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000140
pbos@webrtc.org00873182014-11-25 14:03:34 +0000141 // TODO(pbos): Like BitrateConfig above this is currently per-stream instead
142 // of maximum for entire Call. This should be fixed along with the above.
143 // Specifying a start bitrate (>0) will currently reset the current bitrate
144 // estimate. This is due to how the 'x-google-start-bitrate' flag is currently
145 // implemented.
146 virtual void SetBitrateConfig(
147 const Config::BitrateConfig& bitrate_config) = 0;
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000148 virtual void SignalNetworkState(NetworkState state) = 0;
149
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000150 virtual ~Call() {}
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000151};
Jelena Marusiccd670222015-07-16 09:30:09 +0200152
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000153} // namespace webrtc
154
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000155#endif // WEBRTC_CALL_H_