1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
|
/*
* Copyright (c) 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef CALL_DEGRADED_CALL_H_
#define CALL_DEGRADED_CALL_H_
#include <stddef.h>
#include <stdint.h>
#include <map>
#include <memory>
#include <string>
#include <vector>
#include "absl/strings/string_view.h"
#include "absl/types/optional.h"
#include "api/call/transport.h"
#include "api/fec_controller.h"
#include "api/media_types.h"
#include "api/rtp_headers.h"
#include "api/task_queue/pending_task_safety_flag.h"
#include "api/test/simulated_network.h"
#include "call/audio_receive_stream.h"
#include "call/audio_send_stream.h"
#include "call/call.h"
#include "call/fake_network_pipe.h"
#include "call/flexfec_receive_stream.h"
#include "call/packet_receiver.h"
#include "call/rtp_transport_controller_send_interface.h"
#include "call/simulated_network.h"
#include "call/video_receive_stream.h"
#include "call/video_send_stream.h"
#include "rtc_base/copy_on_write_buffer.h"
#include "rtc_base/network/sent_packet.h"
#include "rtc_base/task_queue.h"
#include "system_wrappers/include/clock.h"
#include "video/config/video_encoder_config.h"
namespace webrtc {
class DegradedCall : public Call, private PacketReceiver {
public:
struct TimeScopedNetworkConfig : public BuiltInNetworkBehaviorConfig {
TimeDelta duration = TimeDelta::PlusInfinity();
};
explicit DegradedCall(
std::unique_ptr<Call> call,
const std::vector<TimeScopedNetworkConfig>& send_configs,
const std::vector<TimeScopedNetworkConfig>& receive_configs);
~DegradedCall() override;
// Implements Call.
AudioSendStream* CreateAudioSendStream(
const AudioSendStream::Config& config) override;
void DestroyAudioSendStream(AudioSendStream* send_stream) override;
AudioReceiveStreamInterface* CreateAudioReceiveStream(
const AudioReceiveStreamInterface::Config& config) override;
void DestroyAudioReceiveStream(
AudioReceiveStreamInterface* receive_stream) override;
VideoSendStream* CreateVideoSendStream(
VideoSendStream::Config config,
VideoEncoderConfig encoder_config) override;
VideoSendStream* CreateVideoSendStream(
VideoSendStream::Config config,
VideoEncoderConfig encoder_config,
std::unique_ptr<FecController> fec_controller) override;
void DestroyVideoSendStream(VideoSendStream* send_stream) override;
VideoReceiveStreamInterface* CreateVideoReceiveStream(
VideoReceiveStreamInterface::Config configuration) override;
void DestroyVideoReceiveStream(
VideoReceiveStreamInterface* receive_stream) override;
FlexfecReceiveStream* CreateFlexfecReceiveStream(
const FlexfecReceiveStream::Config config) override;
void DestroyFlexfecReceiveStream(
FlexfecReceiveStream* receive_stream) override;
void AddAdaptationResource(rtc::scoped_refptr<Resource> resource) override;
PacketReceiver* Receiver() override;
RtpTransportControllerSendInterface* GetTransportControllerSend() override;
Stats GetStats() const override;
const FieldTrialsView& trials() const override;
TaskQueueBase* network_thread() const override;
TaskQueueBase* worker_thread() const override;
void SignalChannelNetworkState(MediaType media, NetworkState state) override;
void OnAudioTransportOverheadChanged(
int transport_overhead_per_packet) override;
void OnLocalSsrcUpdated(AudioReceiveStreamInterface& stream,
uint32_t local_ssrc) override;
void OnLocalSsrcUpdated(VideoReceiveStreamInterface& stream,
uint32_t local_ssrc) override;
void OnLocalSsrcUpdated(FlexfecReceiveStream& stream,
uint32_t local_ssrc) override;
void OnUpdateSyncGroup(AudioReceiveStreamInterface& stream,
absl::string_view sync_group) override;
void OnSentPacket(const rtc::SentPacket& sent_packet) override;
protected:
// Implements PacketReceiver.
void DeliverRtpPacket(
MediaType media_type,
RtpPacketReceived packet,
OnUndemuxablePacketHandler undemuxable_packet_handler) override;
void DeliverRtcpPacket(rtc::CopyOnWriteBuffer packet) override;
private:
class FakeNetworkPipeOnTaskQueue {
public:
FakeNetworkPipeOnTaskQueue(
TaskQueueBase* task_queue,
rtc::scoped_refptr<PendingTaskSafetyFlag> call_alive,
Clock* clock,
std::unique_ptr<NetworkBehaviorInterface> network_behavior);
void SendRtp(const uint8_t* packet,
size_t length,
const PacketOptions& options,
Transport* transport);
void SendRtcp(const uint8_t* packet, size_t length, Transport* transport);
void AddActiveTransport(Transport* transport);
void RemoveActiveTransport(Transport* transport);
private:
// Try to process packets on the fake network queue.
// Returns true if call resulted in a delayed process, false if queue empty.
bool Process();
Clock* const clock_;
TaskQueueBase* const task_queue_;
rtc::scoped_refptr<PendingTaskSafetyFlag> call_alive_;
FakeNetworkPipe pipe_;
absl::optional<int64_t> next_process_ms_ RTC_GUARDED_BY(&task_queue_);
};
// For audio/video send stream, a TransportAdapter instance is used to
// intercept packets to be sent, and put them into a common FakeNetworkPipe
// in such as way that they will eventually (unless dropped) be forwarded to
// the correct Transport for that stream.
class FakeNetworkPipeTransportAdapter : public Transport {
public:
FakeNetworkPipeTransportAdapter(FakeNetworkPipeOnTaskQueue* fake_network,
Call* call,
Clock* clock,
Transport* real_transport);
~FakeNetworkPipeTransportAdapter();
bool SendRtp(const uint8_t* packet,
size_t length,
const PacketOptions& options) override;
bool SendRtcp(const uint8_t* packet, size_t length) override;
private:
FakeNetworkPipeOnTaskQueue* const network_pipe_;
Call* const call_;
Clock* const clock_;
Transport* const real_transport_;
};
void SetClientBitratePreferences(
const webrtc::BitrateSettings& preferences) override;
void UpdateSendNetworkConfig();
void UpdateReceiveNetworkConfig();
Clock* const clock_;
const std::unique_ptr<Call> call_;
// For cancelling tasks on the network thread when DegradedCall is destroyed
rtc::scoped_refptr<PendingTaskSafetyFlag> call_alive_;
size_t send_config_index_;
const std::vector<TimeScopedNetworkConfig> send_configs_;
SimulatedNetwork* send_simulated_network_;
std::unique_ptr<FakeNetworkPipeOnTaskQueue> send_pipe_;
std::map<AudioSendStream*, std::unique_ptr<FakeNetworkPipeTransportAdapter>>
audio_send_transport_adapters_;
std::map<VideoSendStream*, std::unique_ptr<FakeNetworkPipeTransportAdapter>>
video_send_transport_adapters_;
size_t receive_config_index_;
const std::vector<TimeScopedNetworkConfig> receive_configs_;
SimulatedNetwork* receive_simulated_network_;
SequenceChecker received_packet_sequence_checker_;
std::unique_ptr<FakeNetworkPipe> receive_pipe_
RTC_GUARDED_BY(received_packet_sequence_checker_);
};
} // namespace webrtc
#endif // CALL_DEGRADED_CALL_H_
|