blob: 26f8c82bd9bca40a5d9ad1bf387d86caaa8c57a6 [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
kjellandera69d9732016-08-31 07:33:05 -070016#include "webrtc/api/call/audio_receive_stream.h"
17#include "webrtc/api/call/audio_send_stream.h"
18#include "webrtc/api/call/audio_state.h"
brandtr25445d32016-10-23 23:37:14 -070019#include "webrtc/api/call/flexfec_receive_stream.h"
Honghai Zhang0e533ef2016-04-19 15:41:36 -070020#include "webrtc/base/networkroute.h"
ivoc14d5dbe2016-07-04 07:06:55 -070021#include "webrtc/base/platform_file.h"
stefanc1aeaf02015-10-15 07:26:07 -070022#include "webrtc/base/socket.h"
kjellandera69d9732016-08-31 07:33:05 -070023#include "webrtc/common_types.h"
pbos@webrtc.org16e03b72013-10-28 16:32:01 +000024#include "webrtc/video_receive_stream.h"
25#include "webrtc/video_send_stream.h"
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000026
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000027namespace webrtc {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000028
Fredrik Solenberg04f49312015-06-08 13:04:56 +020029class AudioProcessing;
skvlad11a9cbf2016-10-07 11:53:05 -070030class RtcEventLog;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000031
32const char* Version();
33
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020034enum class MediaType {
35 ANY,
36 AUDIO,
37 VIDEO,
38 DATA
39};
40
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000041class PacketReceiver {
42 public:
pbos@webrtc.orgcaba2d22014-05-14 13:57:12 +000043 enum DeliveryStatus {
44 DELIVERY_OK,
45 DELIVERY_UNKNOWN_SSRC,
46 DELIVERY_PACKET_ERROR,
47 };
48
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020049 virtual DeliveryStatus DeliverPacket(MediaType media_type,
50 const uint8_t* packet,
stefan68786d22015-09-08 05:36:15 -070051 size_t length,
52 const PacketTime& packet_time) = 0;
53
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000054 protected:
55 virtual ~PacketReceiver() {}
56};
57
pbos@webrtc.org841c8a42013-09-09 15:04:25 +000058// A Call instance can contain several send and/or receive streams. All streams
59// are assumed to have the same remote endpoint and will share bitrate estimates
60// etc.
61class Call {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000062 public:
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000063 struct Config {
skvlad11a9cbf2016-10-07 11:53:05 -070064 explicit Config(RtcEventLog* event_log) : event_log(event_log) {
65 RTC_DCHECK(event_log);
66 }
67
pbos@webrtc.orga73a6782014-10-14 11:52:10 +000068 static const int kDefaultStartBitrateBps;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000069
pbos@webrtc.org00873182014-11-25 14:03:34 +000070 // Bitrate config used until valid bitrate estimates are calculated. Also
71 // used to cap total bitrate used.
pbos@webrtc.org00873182014-11-25 14:03:34 +000072 struct BitrateConfig {
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020073 int min_bitrate_bps = 0;
74 int start_bitrate_bps = kDefaultStartBitrateBps;
75 int max_bitrate_bps = -1;
Stefan Holmere5904162015-03-26 11:11:06 +010076 } bitrate_config;
Fredrik Solenberg04f49312015-06-08 13:04:56 +020077
solenberg566ef242015-11-06 15:34:49 -080078 // AudioState which is possibly shared between multiple calls.
79 // TODO(solenberg): Change this to a shared_ptr once we can use C++11.
80 rtc::scoped_refptr<AudioState> audio_state;
81
82 // Audio Processing Module to be used in this call.
83 // TODO(solenberg): Change this to a shared_ptr once we can use C++11.
84 AudioProcessing* audio_processing = nullptr;
skvlad11a9cbf2016-10-07 11:53:05 -070085
86 // RtcEventLog to use for this call. Required.
87 // Use webrtc::RtcEventLog::CreateNull() for a null implementation.
88 RtcEventLog* event_log = nullptr;
mflodman@webrtc.org6879c8a2013-07-23 11:35:00 +000089 };
90
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +000091 struct Stats {
asapersson2e5cfcd2016-08-11 08:41:18 -070092 std::string ToString(int64_t time_ms) const;
93
sprang9c0b5512016-07-06 00:54:28 -070094 int send_bandwidth_bps = 0; // Estimated available send bandwidth.
95 int max_padding_bitrate_bps = 0; // Cumulative configured max padding.
96 int recv_bandwidth_bps = 0; // Estimated available receive bandwidth.
Fredrik Solenberg78fb3b32015-06-11 12:38:38 +020097 int64_t pacer_delay_ms = 0;
98 int64_t rtt_ms = -1;
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +000099 };
100
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000101 static Call* Create(const Call::Config& config);
pbos@webrtc.orgfd39e132013-08-14 13:52:52 +0000102
Fredrik Solenberg04f49312015-06-08 13:04:56 +0200103 virtual AudioSendStream* CreateAudioSendStream(
104 const AudioSendStream::Config& config) = 0;
105 virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
106
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200107 virtual AudioReceiveStream* CreateAudioReceiveStream(
108 const AudioReceiveStream::Config& config) = 0;
109 virtual void DestroyAudioReceiveStream(
110 AudioReceiveStream* receive_stream) = 0;
111
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000112 virtual VideoSendStream* CreateVideoSendStream(
perkj26091b12016-09-01 01:17:40 -0700113 VideoSendStream::Config config,
114 VideoEncoderConfig encoder_config) = 0;
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000115 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000116
pbos@webrtc.org5a636552013-11-20 10:40:25 +0000117 virtual VideoReceiveStream* CreateVideoReceiveStream(
Tommi733b5472016-06-10 17:58:01 +0200118 VideoReceiveStream::Config configuration) = 0;
pbos@webrtc.org2c46f8d2013-11-21 13:49:43 +0000119 virtual void DestroyVideoReceiveStream(
120 VideoReceiveStream* receive_stream) = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000121
brandtr25445d32016-10-23 23:37:14 -0700122 virtual FlexfecReceiveStream* CreateFlexfecReceiveStream(
123 FlexfecReceiveStream::Config configuration) = 0;
124 virtual void DestroyFlexfecReceiveStream(
125 FlexfecReceiveStream* receive_stream) = 0;
126
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000127 // All received RTP and RTCP packets for the call should be inserted to this
128 // PacketReceiver. The PacketReceiver pointer is valid as long as the
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000129 // Call instance exists.
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000130 virtual PacketReceiver* Receiver() = 0;
131
stefan@webrtc.org0bae1fa2014-11-05 14:05:29 +0000132 // Returns the call statistics, such as estimated send and receive bandwidth,
133 // pacing delay, etc.
134 virtual Stats GetStats() const = 0;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000135
pbos@webrtc.org00873182014-11-25 14:03:34 +0000136 // TODO(pbos): Like BitrateConfig above this is currently per-stream instead
137 // of maximum for entire Call. This should be fixed along with the above.
138 // Specifying a start bitrate (>0) will currently reset the current bitrate
139 // estimate. This is due to how the 'x-google-start-bitrate' flag is currently
140 // implemented.
141 virtual void SetBitrateConfig(
142 const Config::BitrateConfig& bitrate_config) = 0;
skvlad7a43d252016-03-22 15:32:27 -0700143
144 // TODO(skvlad): When the unbundled case with multiple streams for the same
145 // media type going over different networks is supported, track the state
146 // for each stream separately. Right now it's global per media type.
147 virtual void SignalChannelNetworkState(MediaType media,
148 NetworkState state) = 0;
pbos@webrtc.org26c0c412014-09-03 16:17:12 +0000149
michaelt79e05882016-11-08 02:50:09 -0800150 virtual void OnTransportOverheadChanged(
151 MediaType media,
152 int transport_overhead_per_packet) = 0;
153
Honghai Zhang0e533ef2016-04-19 15:41:36 -0700154 virtual void OnNetworkRouteChanged(
155 const std::string& transport_name,
156 const rtc::NetworkRoute& network_route) = 0;
157
stefanc1aeaf02015-10-15 07:26:07 -0700158 virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
159
pbos@webrtc.org841c8a42013-09-09 15:04:25 +0000160 virtual ~Call() {}
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000161};
Jelena Marusiccd670222015-07-16 09:30:09 +0200162
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000163} // namespace webrtc
164
mflodman@webrtc.orgb429e512013-12-18 09:46:22 +0000165#endif // WEBRTC_CALL_H_