blob: f67b6907e5f7a1c3465b984dc23de768f6130631 [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
ossuf515ab82016-12-07 04:52:58 -080017#include "webrtc/base/networkroute.h"
18#include "webrtc/base/platform_file.h"
19#include "webrtc/base/socket.h"
20#include "webrtc/call/audio_receive_stream.h"
21#include "webrtc/call/audio_send_stream.h"
22#include "webrtc/call/audio_state.h"
brandtr7250b392016-12-19 01:13:46 -080023#include "webrtc/call/flexfec_receive_stream.h"
zstein7cb69d52017-05-08 11:52:38 -070024#include "webrtc/call/rtp_transport_controller_send_interface.h"
ossuf515ab82016-12-07 04:52:58 -080025#include "webrtc/common_types.h"
26#include "webrtc/video_receive_stream.h"
27#include "webrtc/video_send_stream.h"
28
29namespace webrtc {
30
31class AudioProcessing;
32class RtcEventLog;
33
ossuf515ab82016-12-07 04:52:58 -080034enum class MediaType {
35 ANY,
36 AUDIO,
37 VIDEO,
38 DATA
39};
40
41class PacketReceiver {
42 public:
43 enum DeliveryStatus {
44 DELIVERY_OK,
45 DELIVERY_UNKNOWN_SSRC,
46 DELIVERY_PACKET_ERROR,
47 };
48
49 virtual DeliveryStatus DeliverPacket(MediaType media_type,
50 const uint8_t* packet,
51 size_t length,
52 const PacketTime& packet_time) = 0;
53
54 protected:
55 virtual ~PacketReceiver() {}
56};
57
58// 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 {
62 public:
63 struct Config {
64 explicit Config(RtcEventLog* event_log) : event_log(event_log) {
65 RTC_DCHECK(event_log);
66 }
67
68 static const int kDefaultStartBitrateBps;
69
70 // Bitrate config used until valid bitrate estimates are calculated. Also
71 // used to cap total bitrate used.
72 struct BitrateConfig {
73 int min_bitrate_bps = 0;
74 int start_bitrate_bps = kDefaultStartBitrateBps;
75 int max_bitrate_bps = -1;
76 } bitrate_config;
77
78 // 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;
85
86 // RtcEventLog to use for this call. Required.
87 // Use webrtc::RtcEventLog::CreateNull() for a null implementation.
88 RtcEventLog* event_log = nullptr;
89 };
90
91 struct Stats {
92 std::string ToString(int64_t time_ms) const;
93
94 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.
97 int64_t pacer_delay_ms = 0;
98 int64_t rtt_ms = -1;
99 };
100
101 static Call* Create(const Call::Config& config);
102
zstein7cb69d52017-05-08 11:52:38 -0700103 // Allows mocking |transport_send| for testing.
104 static Call* Create(
105 const Call::Config& config,
106 std::unique_ptr<RtpTransportControllerSendInterface> transport_send);
107
ossuf515ab82016-12-07 04:52:58 -0800108 virtual AudioSendStream* CreateAudioSendStream(
109 const AudioSendStream::Config& config) = 0;
110 virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
111
112 virtual AudioReceiveStream* CreateAudioReceiveStream(
113 const AudioReceiveStream::Config& config) = 0;
114 virtual void DestroyAudioReceiveStream(
115 AudioReceiveStream* receive_stream) = 0;
116
117 virtual VideoSendStream* CreateVideoSendStream(
118 VideoSendStream::Config config,
119 VideoEncoderConfig encoder_config) = 0;
120 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
121
122 virtual VideoReceiveStream* CreateVideoReceiveStream(
123 VideoReceiveStream::Config configuration) = 0;
124 virtual void DestroyVideoReceiveStream(
125 VideoReceiveStream* receive_stream) = 0;
126
brandtrfb45c6c2017-01-27 06:47:55 -0800127 // In order for a created VideoReceiveStream to be aware that it is
128 // protected by a FlexfecReceiveStream, the latter should be created before
129 // the former.
ossuf515ab82016-12-07 04:52:58 -0800130 virtual FlexfecReceiveStream* CreateFlexfecReceiveStream(
brandtr446fcb62016-12-08 04:14:24 -0800131 const FlexfecReceiveStream::Config& config) = 0;
ossuf515ab82016-12-07 04:52:58 -0800132 virtual void DestroyFlexfecReceiveStream(
133 FlexfecReceiveStream* receive_stream) = 0;
134
135 // All received RTP and RTCP packets for the call should be inserted to this
136 // PacketReceiver. The PacketReceiver pointer is valid as long as the
137 // Call instance exists.
138 virtual PacketReceiver* Receiver() = 0;
139
140 // Returns the call statistics, such as estimated send and receive bandwidth,
141 // pacing delay, etc.
142 virtual Stats GetStats() const = 0;
143
144 // TODO(pbos): Like BitrateConfig above this is currently per-stream instead
145 // of maximum for entire Call. This should be fixed along with the above.
146 // Specifying a start bitrate (>0) will currently reset the current bitrate
147 // estimate. This is due to how the 'x-google-start-bitrate' flag is currently
148 // implemented.
149 virtual void SetBitrateConfig(
150 const Config::BitrateConfig& bitrate_config) = 0;
151
152 // TODO(skvlad): When the unbundled case with multiple streams for the same
153 // media type going over different networks is supported, track the state
154 // for each stream separately. Right now it's global per media type.
155 virtual void SignalChannelNetworkState(MediaType media,
156 NetworkState state) = 0;
157
158 virtual void OnTransportOverheadChanged(
159 MediaType media,
160 int transport_overhead_per_packet) = 0;
161
162 virtual void OnNetworkRouteChanged(
163 const std::string& transport_name,
164 const rtc::NetworkRoute& network_route) = 0;
165
166 virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
167
168 virtual ~Call() {}
169};
170
171} // namespace webrtc
172
173#endif // WEBRTC_CALL_CALL_H_