blob: d2971be5d50b4806316466c51c3998c2203cae52 [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 */
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020010#ifndef CALL_CALL_H_
11#define CALL_CALL_H_
ossuf515ab82016-12-07 04:52:58 -080012
zsteina5e0df62017-06-14 11:41:48 -070013#include <algorithm>
zstein7cb69d52017-05-08 11:52:38 -070014#include <memory>
ossuf515ab82016-12-07 04:52:58 -080015#include <string>
16#include <vector>
17
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020018#include "call/audio_receive_stream.h"
19#include "call/audio_send_stream.h"
Paulina Hensman11b34f42018-04-09 14:24:52 +020020#include "call/call_config.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020021#include "call/flexfec_receive_stream.h"
22#include "call/rtp_transport_controller_send_interface.h"
23#include "call/video_receive_stream.h"
24#include "call/video_send_stream.h"
Mirko Bonadei71207422017-09-15 13:58:09 +020025#include "common_types.h" // NOLINT(build/include)
Alex Narest78609d52017-10-20 10:37:47 +020026#include "rtc_base/bitrateallocationstrategy.h"
Danil Chapovalov292a73e2017-12-07 17:00:40 +010027#include "rtc_base/copyonwritebuffer.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020028#include "rtc_base/networkroute.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020029#include "rtc_base/socket.h"
ossuf515ab82016-12-07 04:52:58 -080030
31namespace webrtc {
32
ossuf515ab82016-12-07 04:52:58 -080033enum class MediaType {
34 ANY,
35 AUDIO,
36 VIDEO,
37 DATA
38};
39
40class PacketReceiver {
41 public:
42 enum DeliveryStatus {
43 DELIVERY_OK,
44 DELIVERY_UNKNOWN_SSRC,
45 DELIVERY_PACKET_ERROR,
46 };
47
48 virtual DeliveryStatus DeliverPacket(MediaType media_type,
Danil Chapovalov292a73e2017-12-07 17:00:40 +010049 rtc::CopyOnWriteBuffer packet,
ossuf515ab82016-12-07 04:52:58 -080050 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:
Niels Möller8366e172018-02-14 12:20:13 +010061 using Config = CallConfig;
ossuf515ab82016-12-07 04:52:58 -080062
63 struct Stats {
64 std::string ToString(int64_t time_ms) const;
65
66 int send_bandwidth_bps = 0; // Estimated available send bandwidth.
67 int max_padding_bitrate_bps = 0; // Cumulative configured max padding.
68 int recv_bandwidth_bps = 0; // Estimated available receive bandwidth.
69 int64_t pacer_delay_ms = 0;
70 int64_t rtt_ms = -1;
71 };
72
73 static Call* Create(const Call::Config& config);
74
zstein7cb69d52017-05-08 11:52:38 -070075 // Allows mocking |transport_send| for testing.
76 static Call* Create(
77 const Call::Config& config,
78 std::unique_ptr<RtpTransportControllerSendInterface> transport_send);
79
ossuf515ab82016-12-07 04:52:58 -080080 virtual AudioSendStream* CreateAudioSendStream(
81 const AudioSendStream::Config& config) = 0;
82 virtual void DestroyAudioSendStream(AudioSendStream* send_stream) = 0;
83
84 virtual AudioReceiveStream* CreateAudioReceiveStream(
85 const AudioReceiveStream::Config& config) = 0;
86 virtual void DestroyAudioReceiveStream(
87 AudioReceiveStream* receive_stream) = 0;
88
89 virtual VideoSendStream* CreateVideoSendStream(
90 VideoSendStream::Config config,
91 VideoEncoderConfig encoder_config) = 0;
Ying Wang3b790f32018-01-19 17:58:57 +010092 virtual VideoSendStream* CreateVideoSendStream(
93 VideoSendStream::Config config,
94 VideoEncoderConfig encoder_config,
95 std::unique_ptr<FecController> fec_controller);
ossuf515ab82016-12-07 04:52:58 -080096 virtual void DestroyVideoSendStream(VideoSendStream* send_stream) = 0;
97
98 virtual VideoReceiveStream* CreateVideoReceiveStream(
99 VideoReceiveStream::Config configuration) = 0;
100 virtual void DestroyVideoReceiveStream(
101 VideoReceiveStream* receive_stream) = 0;
102
brandtrfb45c6c2017-01-27 06:47:55 -0800103 // In order for a created VideoReceiveStream to be aware that it is
104 // protected by a FlexfecReceiveStream, the latter should be created before
105 // the former.
ossuf515ab82016-12-07 04:52:58 -0800106 virtual FlexfecReceiveStream* CreateFlexfecReceiveStream(
brandtr446fcb62016-12-08 04:14:24 -0800107 const FlexfecReceiveStream::Config& config) = 0;
ossuf515ab82016-12-07 04:52:58 -0800108 virtual void DestroyFlexfecReceiveStream(
109 FlexfecReceiveStream* receive_stream) = 0;
110
111 // All received RTP and RTCP packets for the call should be inserted to this
112 // PacketReceiver. The PacketReceiver pointer is valid as long as the
113 // Call instance exists.
114 virtual PacketReceiver* Receiver() = 0;
115
Sebastian Jansson8f83b422018-02-21 13:07:13 +0100116 // This is used to access the transport controller send instance owned by
117 // Call. The send transport controller is currently owned by Call for legacy
118 // reasons. (for instance variants of call tests are built on this assumtion)
119 // TODO(srte): Move ownership of transport controller send out of Call and
120 // remove this method interface.
121 virtual RtpTransportControllerSendInterface* GetTransportControllerSend() = 0;
122
ossuf515ab82016-12-07 04:52:58 -0800123 // Returns the call statistics, such as estimated send and receive bandwidth,
124 // pacing delay, etc.
125 virtual Stats GetStats() const = 0;
126
Alex Narest78609d52017-10-20 10:37:47 +0200127 virtual void SetBitrateAllocationStrategy(
128 std::unique_ptr<rtc::BitrateAllocationStrategy>
129 bitrate_allocation_strategy) = 0;
130
ossuf515ab82016-12-07 04:52:58 -0800131 // TODO(skvlad): When the unbundled case with multiple streams for the same
132 // media type going over different networks is supported, track the state
133 // for each stream separately. Right now it's global per media type.
134 virtual void SignalChannelNetworkState(MediaType media,
135 NetworkState state) = 0;
136
137 virtual void OnTransportOverheadChanged(
138 MediaType media,
139 int transport_overhead_per_packet) = 0;
140
ossuf515ab82016-12-07 04:52:58 -0800141 virtual void OnSentPacket(const rtc::SentPacket& sent_packet) = 0;
142
143 virtual ~Call() {}
144};
145
146} // namespace webrtc
147
Mirko Bonadei92ea95e2017-09-15 06:47:31 +0200148#endif // CALL_CALL_H_