blob: 06479890ce151c4d8b667d489aaf7dff2f87e0be [file] [log] [blame]
ossuf515ab82016-12-07 04:52:58 -08001/*
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 */
10#ifndef WEBRTC_CALL_CALL_H_
11#define WEBRTC_CALL_CALL_H_
12
zstein7cb69d52017-05-08 11:52:38 -070013#include <memory>
ossuf515ab82016-12-07 04:52:58 -080014#include <string>
15#include <vector>
16
zstein4b979802017-06-02 14:37:37 -070017#include "webrtc/api/rtcerror.h"
ossuf515ab82016-12-07 04:52:58 -080018#include "webrtc/base/networkroute.h"
19#include "webrtc/base/platform_file.h"
20#include "webrtc/base/socket.h"
21#include "webrtc/call/audio_receive_stream.h"
22#include "webrtc/call/audio_send_stream.h"
23#include "webrtc/call/audio_state.h"
brandtr7250b392016-12-19 01:13:46 -080024#include "webrtc/call/flexfec_receive_stream.h"
zstein7cb69d52017-05-08 11:52:38 -070025#include "webrtc/call/rtp_transport_controller_send_interface.h"
ossuf515ab82016-12-07 04:52:58 -080026#include "webrtc/common_types.h"
27#include "webrtc/video_receive_stream.h"
28#include "webrtc/video_send_stream.h"
29
30namespace webrtc {
31
32class AudioProcessing;
33class RtcEventLog;
34
ossuf515ab82016-12-07 04:52:58 -080035enum class MediaType {
36 ANY,
37 AUDIO,
38 VIDEO,
39 DATA
40};
41
42class PacketReceiver {
43 public:
44 enum DeliveryStatus {
45 DELIVERY_OK,
46 DELIVERY_UNKNOWN_SSRC,
47 DELIVERY_PACKET_ERROR,
48 };
49
50 virtual DeliveryStatus DeliverPacket(MediaType media_type,
51 const uint8_t* packet,
52 size_t length,
53 const PacketTime& packet_time) = 0;
54
55 protected:
56 virtual ~PacketReceiver() {}
57};
58
59// A Call instance can contain several send and/or receive streams. All streams
60// are assumed to have the same remote endpoint and will share bitrate estimates
61// etc.
62class Call {
63 public:
64 struct Config {
65 explicit Config(RtcEventLog* event_log) : event_log(event_log) {
66 RTC_DCHECK(event_log);
67 }
68
69 static const int kDefaultStartBitrateBps;
70
71 // Bitrate config used until valid bitrate estimates are calculated. Also
zstein4b979802017-06-02 14:37:37 -070072 // used to cap total bitrate used. This comes from the remote connection.
ossuf515ab82016-12-07 04:52:58 -080073 struct BitrateConfig {
74 int min_bitrate_bps = 0;
75 int start_bitrate_bps = kDefaultStartBitrateBps;
76 int max_bitrate_bps = -1;
77 } bitrate_config;
78
zstein4b979802017-06-02 14:37:37 -070079 // The local client's bitrate preferences. The actual configuration used
80 // is a combination of this and |bitrate_config|. The combination is
81 // currently more complicated than a simple mask operation (see
82 // SetBitrateConfig and SetBitrateConfigMask). Assumes that 0 <= min <=
83 // start <= max holds for set parameters.
84 struct BitrateConfigMask {
85 rtc::Optional<int> min_bitrate_bps;
86 rtc::Optional<int> start_bitrate_bps;
87 rtc::Optional<int> max_bitrate_bps;
88 };
89
ossuf515ab82016-12-07 04:52:58 -080090 // AudioState which is possibly shared between multiple calls.
91 // TODO(solenberg): Change this to a shared_ptr once we can use C++11.
92 rtc::scoped_refptr<AudioState> audio_state;
93
94 // Audio Processing Module to be used in this call.
95 // TODO(solenberg): Change this to a shared_ptr once we can use C++11.
96 AudioProcessing* audio_processing = nullptr;
97
98 // RtcEventLog to use for this call. Required.
99 // Use webrtc::RtcEventLog::CreateNull() for a null implementation.
100 RtcEventLog* event_log = nullptr;
101 };
102
103 struct Stats {
104 std::string ToString(int64_t time_ms) const;
105
106 int send_bandwidth_bps = 0; // Estimated available send bandwidth.
107 int max_padding_bitrate_bps = 0; // Cumulative configured max padding.
108 int recv_bandwidth_bps = 0; // Estimated available receive bandwidth.
109 int64_t pacer_delay_ms = 0;
110 int64_t rtt_ms = -1;
111 };
112
113 static Call* Create(const Call::Config& config);
114
zstein7cb69d52017-05-08 11:52:38 -0700115 // Allows mocking |transport_send| for testing.
116 static Call* Create(
117 const Call::Config& config,
118 std::unique_ptr<RtpTransportControllerSendInterface> transport_send);
119
ossuf515ab82016-12-07 04:52:58 -0800120 virtual AudioSendStream* CreateAudioSendStream(
121 const AudioSendStream::Config& config) = 0;
122 virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
123
124 virtual AudioReceiveStream* CreateAudioReceiveStream(
125 const AudioReceiveStream::Config& config) = 0;
126 virtual void DestroyAudioReceiveStream(
127 AudioReceiveStream* receive_stream) = 0;
128
129 virtual VideoSendStream* CreateVideoSendStream(
130 VideoSendStream::Config config,
131 VideoEncoderConfig encoder_config) = 0;
132 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
133
134 virtual VideoReceiveStream* CreateVideoReceiveStream(
135 VideoReceiveStream::Config configuration) = 0;
136 virtual void DestroyVideoReceiveStream(
137 VideoReceiveStream* receive_stream) = 0;
138
brandtrfb45c6c2017-01-27 06:47:55 -0800139 // In order for a created VideoReceiveStream to be aware that it is
140 // protected by a FlexfecReceiveStream, the latter should be created before
141 // the former.
ossuf515ab82016-12-07 04:52:58 -0800142 virtual FlexfecReceiveStream* CreateFlexfecReceiveStream(
brandtr446fcb62016-12-08 04:14:24 -0800143 const FlexfecReceiveStream::Config& config) = 0;
ossuf515ab82016-12-07 04:52:58 -0800144 virtual void DestroyFlexfecReceiveStream(
145 FlexfecReceiveStream* receive_stream) = 0;
146
147 // All received RTP and RTCP packets for the call should be inserted to this
148 // PacketReceiver. The PacketReceiver pointer is valid as long as the
149 // Call instance exists.
150 virtual PacketReceiver* Receiver() = 0;
151
152 // Returns the call statistics, such as estimated send and receive bandwidth,
153 // pacing delay, etc.
154 virtual Stats GetStats() const = 0;
155
zstein4b979802017-06-02 14:37:37 -0700156 // The greater min and smaller max set by this and SetBitrateConfigMask will
157 // be used. The latest non-negative start value from either call will be used.
158 // Specifying a start bitrate (>0) will reset the current bitrate estimate.
159 // This is due to how the 'x-google-start-bitrate' flag is currently
160 // implemented. Passing -1 leaves the start bitrate unchanged. Behavior is not
161 // guaranteed for other negative values or 0.
ossuf515ab82016-12-07 04:52:58 -0800162 virtual void SetBitrateConfig(
163 const Config::BitrateConfig& bitrate_config) = 0;
164
zstein4b979802017-06-02 14:37:37 -0700165 // The greater min and smaller max set by this and SetBitrateConfig will be
166 // used. The latest non-negative start value form either call will be used.
167 // Specifying a start bitrate will reset the current bitrate estimate.
168 // Assumes 0 <= min <= start <= max holds for set parameters.
169 virtual void SetBitrateConfigMask(
170 const Config::BitrateConfigMask& bitrate_mask) = 0;
171
ossuf515ab82016-12-07 04:52:58 -0800172 // TODO(skvlad): When the unbundled case with multiple streams for the same
173 // media type going over different networks is supported, track the state
174 // for each stream separately. Right now it's global per media type.
175 virtual void SignalChannelNetworkState(MediaType media,
176 NetworkState state) = 0;
177
178 virtual void OnTransportOverheadChanged(
179 MediaType media,
180 int transport_overhead_per_packet) = 0;
181
182 virtual void OnNetworkRouteChanged(
183 const std::string& transport_name,
184 const rtc::NetworkRoute& network_route) = 0;
185
186 virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
187
188 virtual ~Call() {}
189};
190
191} // namespace webrtc
192
193#endif // WEBRTC_CALL_CALL_H_