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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
|
/*
* Copyright (c) 2016 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.
*/
#include "call/flexfec_receive_stream_impl.h"
#include <stddef.h>
#include <cstdint>
#include <string>
#include <utility>
#include "api/array_view.h"
#include "api/call/transport.h"
#include "api/rtp_parameters.h"
#include "call/rtp_stream_receiver_controller_interface.h"
#include "modules/rtp_rtcp/include/flexfec_receiver.h"
#include "modules/rtp_rtcp/include/receive_statistics.h"
#include "modules/rtp_rtcp/source/rtp_packet_received.h"
#include "rtc_base/checks.h"
#include "rtc_base/logging.h"
#include "rtc_base/strings/string_builder.h"
#include "system_wrappers/include/clock.h"
namespace webrtc {
std::string FlexfecReceiveStream::Config::ToString() const {
char buf[1024];
rtc::SimpleStringBuilder ss(buf);
ss << "{payload_type: " << payload_type;
ss << ", remote_ssrc: " << rtp.remote_ssrc;
ss << ", local_ssrc: " << rtp.local_ssrc;
ss << ", protected_media_ssrcs: [";
size_t i = 0;
for (; i + 1 < protected_media_ssrcs.size(); ++i)
ss << protected_media_ssrcs[i] << ", ";
if (!protected_media_ssrcs.empty())
ss << protected_media_ssrcs[i];
ss << ", rtp.extensions: [";
i = 0;
for (; i + 1 < rtp.extensions.size(); ++i)
ss << rtp.extensions[i].ToString() << ", ";
if (!rtp.extensions.empty())
ss << rtp.extensions[i].ToString();
ss << "]}";
return ss.str();
}
bool FlexfecReceiveStream::Config::IsCompleteAndEnabled() const {
// Check if FlexFEC is enabled.
if (payload_type < 0)
return false;
// Do we have the necessary SSRC information?
if (rtp.remote_ssrc == 0)
return false;
// TODO(brandtr): Update this check when we support multistream protection.
if (protected_media_ssrcs.size() != 1u)
return false;
return true;
}
namespace {
// TODO(brandtr): Update this function when we support multistream protection.
std::unique_ptr<FlexfecReceiver> MaybeCreateFlexfecReceiver(
Clock* clock,
const FlexfecReceiveStream::Config& config,
RecoveredPacketReceiver* recovered_packet_receiver) {
if (config.payload_type < 0) {
RTC_LOG(LS_WARNING)
<< "Invalid FlexFEC payload type given. "
"This FlexfecReceiveStream will therefore be useless.";
return nullptr;
}
RTC_DCHECK_GE(config.payload_type, 0);
RTC_DCHECK_LE(config.payload_type, 127);
if (config.rtp.remote_ssrc == 0) {
RTC_LOG(LS_WARNING)
<< "Invalid FlexFEC SSRC given. "
"This FlexfecReceiveStream will therefore be useless.";
return nullptr;
}
if (config.protected_media_ssrcs.empty()) {
RTC_LOG(LS_WARNING)
<< "No protected media SSRC supplied. "
"This FlexfecReceiveStream will therefore be useless.";
return nullptr;
}
if (config.protected_media_ssrcs.size() > 1) {
RTC_LOG(LS_WARNING)
<< "The supplied FlexfecConfig contained multiple protected "
"media streams, but our implementation currently only "
"supports protecting a single media stream. "
"To avoid confusion, disabling FlexFEC completely.";
return nullptr;
}
RTC_DCHECK_EQ(1U, config.protected_media_ssrcs.size());
return std::unique_ptr<FlexfecReceiver>(new FlexfecReceiver(
clock, config.rtp.remote_ssrc, config.protected_media_ssrcs[0],
recovered_packet_receiver));
}
std::unique_ptr<ModuleRtpRtcpImpl2> CreateRtpRtcpModule(
Clock* clock,
ReceiveStatistics* receive_statistics,
const FlexfecReceiveStreamImpl::Config& config,
RtcpRttStats* rtt_stats) {
RtpRtcpInterface::Configuration configuration;
configuration.audio = false;
configuration.receiver_only = true;
configuration.clock = clock;
configuration.receive_statistics = receive_statistics;
configuration.outgoing_transport = config.rtcp_send_transport;
configuration.rtt_stats = rtt_stats;
configuration.local_media_ssrc = config.rtp.local_ssrc;
return ModuleRtpRtcpImpl2::Create(configuration);
}
} // namespace
FlexfecReceiveStreamImpl::FlexfecReceiveStreamImpl(
Clock* clock,
Config config,
RecoveredPacketReceiver* recovered_packet_receiver,
RtcpRttStats* rtt_stats)
: extension_map_(std::move(config.rtp.extensions)),
remote_ssrc_(config.rtp.remote_ssrc),
payload_type_(config.payload_type),
receiver_(
MaybeCreateFlexfecReceiver(clock, config, recovered_packet_receiver)),
rtp_receive_statistics_(ReceiveStatistics::Create(clock)),
rtp_rtcp_(CreateRtpRtcpModule(clock,
rtp_receive_statistics_.get(),
config,
rtt_stats)) {
RTC_LOG(LS_INFO) << "FlexfecReceiveStreamImpl: " << config.ToString();
RTC_DCHECK_GE(payload_type_, -1);
packet_sequence_checker_.Detach();
// RTCP reporting.
rtp_rtcp_->SetRTCPStatus(config.rtcp_mode);
}
FlexfecReceiveStreamImpl::~FlexfecReceiveStreamImpl() {
RTC_DLOG(LS_INFO) << "~FlexfecReceiveStreamImpl: ssrc: " << remote_ssrc_;
}
void FlexfecReceiveStreamImpl::RegisterWithTransport(
RtpStreamReceiverControllerInterface* receiver_controller) {
RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
RTC_DCHECK(!rtp_stream_receiver_);
if (!receiver_)
return;
// TODO(nisse): OnRtpPacket in this class delegates all real work to
// `receiver_`. So maybe we don't need to implement RtpPacketSinkInterface
// here at all, we'd then delete the OnRtpPacket method and instead register
// `receiver_` as the RtpPacketSinkInterface for this stream.
rtp_stream_receiver_ =
receiver_controller->CreateReceiver(remote_ssrc(), this);
}
void FlexfecReceiveStreamImpl::UnregisterFromTransport() {
RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
rtp_stream_receiver_.reset();
}
void FlexfecReceiveStreamImpl::OnRtpPacket(const RtpPacketReceived& packet) {
RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
if (!receiver_)
return;
receiver_->OnRtpPacket(packet);
// Do not report media packets in the RTCP RRs generated by `rtp_rtcp_`.
if (packet.Ssrc() == remote_ssrc()) {
rtp_receive_statistics_->OnRtpPacket(packet);
}
}
void FlexfecReceiveStreamImpl::SetPayloadType(int payload_type) {
RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
RTC_DCHECK_GE(payload_type, -1);
payload_type_ = payload_type;
}
int FlexfecReceiveStreamImpl::payload_type() const {
RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
return payload_type_;
}
void FlexfecReceiveStreamImpl::SetRtpExtensions(
std::vector<RtpExtension> extensions) {
RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
extension_map_.Reset(extensions);
}
RtpHeaderExtensionMap FlexfecReceiveStreamImpl::GetRtpExtensionMap() const {
RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
return extension_map_;
}
void FlexfecReceiveStreamImpl::SetLocalSsrc(uint32_t local_ssrc) {
RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
if (local_ssrc == rtp_rtcp_->local_media_ssrc())
return;
rtp_rtcp_->SetLocalSsrc(local_ssrc);
}
} // namespace webrtc
|