blob: caf0ee2d881951e5c28320086b6cf74c2c48ef92 [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
13#include <string>
14#include <vector>
15
ossuf515ab82016-12-07 04:52:58 -080016#include "webrtc/base/networkroute.h"
17#include "webrtc/base/platform_file.h"
18#include "webrtc/base/socket.h"
19#include "webrtc/call/audio_receive_stream.h"
20#include "webrtc/call/audio_send_stream.h"
21#include "webrtc/call/audio_state.h"
brandtr7250b392016-12-19 01:13:46 -080022#include "webrtc/call/flexfec_receive_stream.h"
ossuf515ab82016-12-07 04:52:58 -080023#include "webrtc/common_types.h"
24#include "webrtc/video_receive_stream.h"
25#include "webrtc/video_send_stream.h"
26
27namespace webrtc {
28
29class AudioProcessing;
30class RtcEventLog;
31
ossuf515ab82016-12-07 04:52:58 -080032enum class MediaType {
33 ANY,
34 AUDIO,
35 VIDEO,
36 DATA
37};
38
39class PacketReceiver {
40 public:
41 enum DeliveryStatus {
42 DELIVERY_OK,
43 DELIVERY_UNKNOWN_SSRC,
44 DELIVERY_PACKET_ERROR,
45 };
46
47 virtual DeliveryStatus DeliverPacket(MediaType media_type,
48 const uint8_t* packet,
49 size_t length,
50 const PacketTime& packet_time) = 0;
51
52 protected:
53 virtual ~PacketReceiver() {}
54};
55
56// A Call instance can contain several send and/or receive streams. All streams
57// are assumed to have the same remote endpoint and will share bitrate estimates
58// etc.
59class Call {
60 public:
61 struct Config {
62 explicit Config(RtcEventLog* event_log) : event_log(event_log) {
63 RTC_DCHECK(event_log);
64 }
65
66 static const int kDefaultStartBitrateBps;
67
68 // Bitrate config used until valid bitrate estimates are calculated. Also
69 // used to cap total bitrate used.
70 struct BitrateConfig {
71 int min_bitrate_bps = 0;
72 int start_bitrate_bps = kDefaultStartBitrateBps;
73 int max_bitrate_bps = -1;
74 } bitrate_config;
75
76 // AudioState which is possibly shared between multiple calls.
77 // TODO(solenberg): Change this to a shared_ptr once we can use C++11.
78 rtc::scoped_refptr<AudioState> audio_state;
79
80 // Audio Processing Module to be used in this call.
81 // TODO(solenberg): Change this to a shared_ptr once we can use C++11.
82 AudioProcessing* audio_processing = nullptr;
83
84 // RtcEventLog to use for this call. Required.
85 // Use webrtc::RtcEventLog::CreateNull() for a null implementation.
86 RtcEventLog* event_log = nullptr;
87 };
88
89 struct Stats {
90 std::string ToString(int64_t time_ms) const;
91
92 int send_bandwidth_bps = 0; // Estimated available send bandwidth.
93 int max_padding_bitrate_bps = 0; // Cumulative configured max padding.
94 int recv_bandwidth_bps = 0; // Estimated available receive bandwidth.
95 int64_t pacer_delay_ms = 0;
96 int64_t rtt_ms = -1;
97 };
98
99 static Call* Create(const Call::Config& config);
100
101 virtual AudioSendStream* CreateAudioSendStream(
102 const AudioSendStream::Config& config) = 0;
103 virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
104
105 virtual AudioReceiveStream* CreateAudioReceiveStream(
106 const AudioReceiveStream::Config& config) = 0;
107 virtual void DestroyAudioReceiveStream(
108 AudioReceiveStream* receive_stream) = 0;
109
110 virtual VideoSendStream* CreateVideoSendStream(
111 VideoSendStream::Config config,
112 VideoEncoderConfig encoder_config) = 0;
113 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
114
115 virtual VideoReceiveStream* CreateVideoReceiveStream(
116 VideoReceiveStream::Config configuration) = 0;
117 virtual void DestroyVideoReceiveStream(
118 VideoReceiveStream* receive_stream) = 0;
119
brandtrfb45c6c2017-01-27 06:47:55 -0800120 // In order for a created VideoReceiveStream to be aware that it is
121 // protected by a FlexfecReceiveStream, the latter should be created before
122 // the former.
ossuf515ab82016-12-07 04:52:58 -0800123 virtual FlexfecReceiveStream* CreateFlexfecReceiveStream(
brandtr446fcb62016-12-08 04:14:24 -0800124 const FlexfecReceiveStream::Config& config) = 0;
ossuf515ab82016-12-07 04:52:58 -0800125 virtual void DestroyFlexfecReceiveStream(
126 FlexfecReceiveStream* receive_stream) = 0;
127
128 // All received RTP and RTCP packets for the call should be inserted to this
129 // PacketReceiver. The PacketReceiver pointer is valid as long as the
130 // Call instance exists.
131 virtual PacketReceiver* Receiver() = 0;
132
133 // Returns the call statistics, such as estimated send and receive bandwidth,
134 // pacing delay, etc.
135 virtual Stats GetStats() const = 0;
136
137 // TODO(pbos): Like BitrateConfig above this is currently per-stream instead
138 // of maximum for entire Call. This should be fixed along with the above.
139 // Specifying a start bitrate (>0) will currently reset the current bitrate
140 // estimate. This is due to how the 'x-google-start-bitrate' flag is currently
141 // implemented.
142 virtual void SetBitrateConfig(
143 const Config::BitrateConfig& bitrate_config) = 0;
144
145 // TODO(skvlad): When the unbundled case with multiple streams for the same
146 // media type going over different networks is supported, track the state
147 // for each stream separately. Right now it's global per media type.
148 virtual void SignalChannelNetworkState(MediaType media,
149 NetworkState state) = 0;
150
151 virtual void OnTransportOverheadChanged(
152 MediaType media,
153 int transport_overhead_per_packet) = 0;
154
155 virtual void OnNetworkRouteChanged(
156 const std::string& transport_name,
157 const rtc::NetworkRoute& network_route) = 0;
158
159 virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
160
161 virtual ~Call() {}
162};
163
164} // namespace webrtc
165
166#endif // WEBRTC_CALL_CALL_H_