mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 1 | /* |
| 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.org | b429e51 | 2013-12-18 09:46:22 +0000 | [diff] [blame] | 10 | #ifndef WEBRTC_CALL_H_ |
| 11 | #define WEBRTC_CALL_H_ |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 12 | |
| 13 | #include <string> |
| 14 | #include <vector> |
| 15 | |
| 16 | #include "webrtc/common_types.h" |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 17 | #include "webrtc/video_receive_stream.h" |
| 18 | #include "webrtc/video_send_stream.h" |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 19 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 20 | namespace webrtc { |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 21 | |
| 22 | class VoiceEngine; |
| 23 | |
| 24 | const char* Version(); |
| 25 | |
| 26 | class PacketReceiver { |
| 27 | public: |
pbos@webrtc.org | caba2d2 | 2014-05-14 13:57:12 +0000 | [diff] [blame] | 28 | 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.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 36 | |
| 37 | protected: |
| 38 | virtual ~PacketReceiver() {} |
| 39 | }; |
| 40 | |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 +0000 | [diff] [blame] | 41 | // Callback interface for reporting when a system overuse is detected. |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 42 | class LoadObserver { |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 +0000 | [diff] [blame] | 43 | public: |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 44 | 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.org | bdc5ed2 | 2014-01-31 10:05:07 +0000 | [diff] [blame] | 49 | |
| 50 | protected: |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 51 | virtual ~LoadObserver() {} |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
pbos@webrtc.org | 841c8a4 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 54 | // 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. |
| 57 | class Call { |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 58 | public: |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 59 | enum NetworkState { |
| 60 | kNetworkUp, |
| 61 | kNetworkDown, |
| 62 | }; |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 63 | struct Config { |
pbos@webrtc.org | 74fa489 | 2013-08-23 09:19:30 +0000 | [diff] [blame] | 64 | explicit Config(newapi::Transport* send_transport) |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 65 | : webrtc_config(NULL), |
| 66 | send_transport(send_transport), |
pbos@webrtc.org | fd39e13 | 2013-08-14 13:52:52 +0000 | [diff] [blame] | 67 | voice_engine(NULL), |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame^] | 68 | overuse_callback(NULL) {} |
pbos@webrtc.org | a73a678 | 2014-10-14 11:52:10 +0000 | [diff] [blame] | 69 | |
| 70 | static const int kDefaultStartBitrateBps; |
mflodman@webrtc.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 71 | |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 72 | webrtc::Config* webrtc_config; |
| 73 | |
pbos@webrtc.org | 74fa489 | 2013-08-23 09:19:30 +0000 | [diff] [blame] | 74 | newapi::Transport* send_transport; |
pbos@webrtc.org | fd39e13 | 2013-08-14 13:52:52 +0000 | [diff] [blame] | 75 | |
pbos@webrtc.org | 841c8a4 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 76 | // VoiceEngine used for audio/video synchronization for this Call. |
pbos@webrtc.org | fd39e13 | 2013-08-14 13:52:52 +0000 | [diff] [blame] | 77 | VoiceEngine* voice_engine; |
| 78 | |
asapersson@webrtc.org | bdc5ed2 | 2014-01-31 10:05:07 +0000 | [diff] [blame] | 79 | // Callback for overuse and normal usage based on the jitter of incoming |
| 80 | // captured frames. 'NULL' disables the callback. |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 81 | LoadObserver* overuse_callback; |
mflodman@webrtc.org | eb16b81 | 2014-06-16 08:57:39 +0000 | [diff] [blame] | 82 | |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame^] | 83 | // Bitrate config used until valid bitrate estimates are calculated. Also |
| 84 | // used to cap total bitrate used. |
pbos@webrtc.org | a73a678 | 2014-10-14 11:52:10 +0000 | [diff] [blame] | 85 | // 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.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame^] | 88 | 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.org | 6879c8a | 2013-07-23 11:35:00 +0000 | [diff] [blame] | 97 | }; |
| 98 | |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 99 | 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.org | 841c8a4 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 107 | static Call* Create(const Call::Config& config); |
pbos@webrtc.org | fd39e13 | 2013-08-14 13:52:52 +0000 | [diff] [blame] | 108 | |
stefan@webrtc.org | 7e9315b | 2013-12-04 10:24:26 +0000 | [diff] [blame] | 109 | static Call* Create(const Call::Config& config, |
| 110 | const webrtc::Config& webrtc_config); |
| 111 | |
pbos@webrtc.org | 5a63655 | 2013-11-20 10:40:25 +0000 | [diff] [blame] | 112 | virtual VideoSendStream* CreateVideoSendStream( |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 113 | const VideoSendStream::Config& config, |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 114 | const VideoEncoderConfig& encoder_config) = 0; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 115 | |
pbos@webrtc.org | 2c46f8d | 2013-11-21 13:49:43 +0000 | [diff] [blame] | 116 | virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 117 | |
pbos@webrtc.org | 5a63655 | 2013-11-20 10:40:25 +0000 | [diff] [blame] | 118 | virtual VideoReceiveStream* CreateVideoReceiveStream( |
pbos@webrtc.org | 025f4f1 | 2013-06-05 11:33:21 +0000 | [diff] [blame] | 119 | const VideoReceiveStream::Config& config) = 0; |
pbos@webrtc.org | 2c46f8d | 2013-11-21 13:49:43 +0000 | [diff] [blame] | 120 | virtual void DestroyVideoReceiveStream( |
| 121 | VideoReceiveStream* receive_stream) = 0; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 122 | |
| 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.org | 841c8a4 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 125 | // Call instance exists. |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 126 | virtual PacketReceiver* Receiver() = 0; |
| 127 | |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 128 | // Returns the call statistics, such as estimated send and receive bandwidth, |
| 129 | // pacing delay, etc. |
| 130 | virtual Stats GetStats() const = 0; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 131 | |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame^] | 132 | // 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.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 139 | virtual void SignalNetworkState(NetworkState state) = 0; |
| 140 | |
pbos@webrtc.org | 841c8a4 | 2013-09-09 15:04:25 +0000 | [diff] [blame] | 141 | virtual ~Call() {} |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 142 | }; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 143 | } // namespace webrtc |
| 144 | |
mflodman@webrtc.org | b429e51 | 2013-12-18 09:46:22 +0000 | [diff] [blame] | 145 | #endif // WEBRTC_CALL_H_ |