2016-10-20 04:54:48 -07:00
|
|
|
/*
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "call/flexfec_receive_stream_impl.h"
|
2016-10-20 04:54:48 -07:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <stddef.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <cstdint>
|
2017-01-17 01:33:54 -08:00
|
|
|
#include <string>
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <vector>
|
2016-12-21 06:37:18 -08:00
|
|
|
|
2018-11-28 16:47:49 +01:00
|
|
|
#include "api/array_view.h"
|
|
|
|
|
#include "api/call/transport.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "api/rtp_parameters.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#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 "modules/utility/include/process_thread.h"
|
|
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
|
#include "rtc_base/location.h"
|
|
|
|
|
#include "rtc_base/logging.h"
|
2018-04-04 15:49:32 +02:00
|
|
|
#include "rtc_base/strings/string_builder.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "system_wrappers/include/clock.h"
|
2016-10-20 04:54:48 -07:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
std::string FlexfecReceiveStream::Stats::ToString(int64_t time_ms) const {
|
2018-04-04 15:49:32 +02:00
|
|
|
char buf[1024];
|
|
|
|
|
rtc::SimpleStringBuilder ss(buf);
|
2016-10-20 04:54:48 -07:00
|
|
|
ss << "FlexfecReceiveStream stats: " << time_ms
|
|
|
|
|
<< ", {flexfec_bitrate_bps: " << flexfec_bitrate_bps << "}";
|
|
|
|
|
return ss.str();
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-08 04:17:53 -08:00
|
|
|
std::string FlexfecReceiveStream::Config::ToString() const {
|
2018-04-04 15:49:32 +02:00
|
|
|
char buf[1024];
|
|
|
|
|
rtc::SimpleStringBuilder ss(buf);
|
2016-12-08 04:17:53 -08:00
|
|
|
ss << "{payload_type: " << payload_type;
|
2021-06-14 10:54:20 +02:00
|
|
|
ss << ", remote_ssrc: " << rtp.remote_ssrc;
|
|
|
|
|
ss << ", local_ssrc: " << rtp.local_ssrc;
|
2016-12-08 04:17:53 -08:00
|
|
|
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];
|
2021-06-14 10:54:20 +02:00
|
|
|
ss << "], transport_cc: " << (rtp.transport_cc ? "on" : "off");
|
|
|
|
|
ss << ", rtp.extensions: [";
|
2016-12-08 04:17:53 -08:00
|
|
|
i = 0;
|
2021-06-14 10:54:20 +02:00
|
|
|
for (; i + 1 < rtp.extensions.size(); ++i)
|
|
|
|
|
ss << rtp.extensions[i].ToString() << ", ";
|
|
|
|
|
if (!rtp.extensions.empty())
|
|
|
|
|
ss << rtp.extensions[i].ToString();
|
2016-12-08 04:17:53 -08:00
|
|
|
ss << "]}";
|
|
|
|
|
return ss.str();
|
|
|
|
|
}
|
|
|
|
|
|
2017-01-13 07:41:19 -08:00
|
|
|
bool FlexfecReceiveStream::Config::IsCompleteAndEnabled() const {
|
|
|
|
|
// Check if FlexFEC is enabled.
|
|
|
|
|
if (payload_type < 0)
|
|
|
|
|
return false;
|
|
|
|
|
// Do we have the necessary SSRC information?
|
2021-06-14 10:54:20 +02:00
|
|
|
if (rtp.remote_ssrc == 0)
|
2017-01-13 07:41:19 -08:00
|
|
|
return false;
|
|
|
|
|
// TODO(brandtr): Update this check when we support multistream protection.
|
|
|
|
|
if (protected_media_ssrcs.size() != 1u)
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-20 04:54:48 -07:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
// TODO(brandtr): Update this function when we support multistream protection.
|
2016-11-15 05:26:45 -08:00
|
|
|
std::unique_ptr<FlexfecReceiver> MaybeCreateFlexfecReceiver(
|
2019-03-04 19:39:01 +01:00
|
|
|
Clock* clock,
|
2016-11-15 05:26:45 -08:00
|
|
|
const FlexfecReceiveStream::Config& config,
|
2016-12-21 06:37:18 -08:00
|
|
|
RecoveredPacketReceiver* recovered_packet_receiver) {
|
2016-12-08 04:17:53 -08:00
|
|
|
if (config.payload_type < 0) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_WARNING)
|
|
|
|
|
<< "Invalid FlexFEC payload type given. "
|
2020-01-14 12:11:31 +01:00
|
|
|
"This FlexfecReceiveStream will therefore be useless.";
|
2016-10-20 04:54:48 -07:00
|
|
|
return nullptr;
|
2016-11-15 05:26:45 -08:00
|
|
|
}
|
2016-12-08 04:17:53 -08:00
|
|
|
RTC_DCHECK_GE(config.payload_type, 0);
|
|
|
|
|
RTC_DCHECK_LE(config.payload_type, 127);
|
2021-06-14 10:54:20 +02:00
|
|
|
if (config.rtp.remote_ssrc == 0) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_WARNING)
|
|
|
|
|
<< "Invalid FlexFEC SSRC given. "
|
2020-01-14 12:11:31 +01:00
|
|
|
"This FlexfecReceiveStream will therefore be useless.";
|
2016-11-15 05:26:45 -08:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
if (config.protected_media_ssrcs.empty()) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_WARNING)
|
|
|
|
|
<< "No protected media SSRC supplied. "
|
2020-01-14 12:11:31 +01:00
|
|
|
"This FlexfecReceiveStream will therefore be useless.";
|
2016-11-15 05:26:45 -08:00
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (config.protected_media_ssrcs.size() > 1) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_WARNING)
|
2016-10-20 04:54:48 -07:00
|
|
|
<< "The supplied FlexfecConfig contained multiple protected "
|
|
|
|
|
"media streams, but our implementation currently only "
|
2016-11-15 05:26:45 -08:00
|
|
|
"supports protecting a single media stream. "
|
|
|
|
|
"To avoid confusion, disabling FlexFEC completely.";
|
|
|
|
|
return nullptr;
|
2016-10-20 04:54:48 -07:00
|
|
|
}
|
2016-11-15 05:26:45 -08:00
|
|
|
RTC_DCHECK_EQ(1U, config.protected_media_ssrcs.size());
|
2019-03-04 19:39:01 +01:00
|
|
|
return std::unique_ptr<FlexfecReceiver>(new FlexfecReceiver(
|
2021-06-14 10:54:20 +02:00
|
|
|
clock, config.rtp.remote_ssrc, config.protected_media_ssrcs[0],
|
2019-03-04 19:39:01 +01:00
|
|
|
recovered_packet_receiver));
|
2016-10-20 04:54:48 -07:00
|
|
|
}
|
|
|
|
|
|
2020-06-03 22:55:33 +02:00
|
|
|
std::unique_ptr<ModuleRtpRtcpImpl2> CreateRtpRtcpModule(
|
2019-03-04 19:39:01 +01:00
|
|
|
Clock* clock,
|
2017-01-17 01:33:54 -08:00
|
|
|
ReceiveStatistics* receive_statistics,
|
2019-08-19 12:42:58 +02:00
|
|
|
const FlexfecReceiveStreamImpl::Config& config,
|
2017-01-17 01:33:54 -08:00
|
|
|
RtcpRttStats* rtt_stats) {
|
2020-06-03 22:55:33 +02:00
|
|
|
RtpRtcpInterface::Configuration configuration;
|
2017-01-17 01:33:54 -08:00
|
|
|
configuration.audio = false;
|
|
|
|
|
configuration.receiver_only = true;
|
2019-03-04 19:39:01 +01:00
|
|
|
configuration.clock = clock;
|
2017-01-17 01:33:54 -08:00
|
|
|
configuration.receive_statistics = receive_statistics;
|
2019-08-19 12:42:58 +02:00
|
|
|
configuration.outgoing_transport = config.rtcp_send_transport;
|
2017-01-17 01:33:54 -08:00
|
|
|
configuration.rtt_stats = rtt_stats;
|
2021-06-14 10:54:20 +02:00
|
|
|
configuration.local_media_ssrc = config.rtp.local_ssrc;
|
2021-01-12 15:54:16 +00:00
|
|
|
return ModuleRtpRtcpImpl2::Create(configuration);
|
2017-01-17 01:33:54 -08:00
|
|
|
}
|
|
|
|
|
|
2016-10-20 04:54:48 -07:00
|
|
|
} // namespace
|
|
|
|
|
|
2016-12-19 01:13:46 -08:00
|
|
|
FlexfecReceiveStreamImpl::FlexfecReceiveStreamImpl(
|
2019-03-04 19:39:01 +01:00
|
|
|
Clock* clock,
|
2016-12-08 04:14:24 -08:00
|
|
|
const Config& config,
|
2017-01-17 01:33:54 -08:00
|
|
|
RecoveredPacketReceiver* recovered_packet_receiver,
|
|
|
|
|
RtcpRttStats* rtt_stats,
|
|
|
|
|
ProcessThread* process_thread)
|
|
|
|
|
: config_(config),
|
2019-03-04 19:39:01 +01:00
|
|
|
receiver_(MaybeCreateFlexfecReceiver(clock,
|
|
|
|
|
config_,
|
|
|
|
|
recovered_packet_receiver)),
|
|
|
|
|
rtp_receive_statistics_(ReceiveStatistics::Create(clock)),
|
|
|
|
|
rtp_rtcp_(CreateRtpRtcpModule(clock,
|
|
|
|
|
rtp_receive_statistics_.get(),
|
2019-08-19 12:42:58 +02:00
|
|
|
config_,
|
2017-01-17 01:33:54 -08:00
|
|
|
rtt_stats)),
|
|
|
|
|
process_thread_(process_thread) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_INFO) << "FlexfecReceiveStreamImpl: " << config_.ToString();
|
2017-01-17 01:33:54 -08:00
|
|
|
|
2021-05-31 17:36:47 +02:00
|
|
|
packet_sequence_checker_.Detach();
|
2021-05-31 14:26:05 +02:00
|
|
|
|
2017-01-17 01:33:54 -08:00
|
|
|
// RTCP reporting.
|
|
|
|
|
rtp_rtcp_->SetRTCPStatus(config_.rtcp_mode);
|
2017-03-03 03:20:24 -08:00
|
|
|
process_thread_->RegisterModule(rtp_rtcp_.get(), RTC_FROM_HERE);
|
2021-05-31 14:26:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FlexfecReceiveStreamImpl::~FlexfecReceiveStreamImpl() {
|
|
|
|
|
RTC_LOG(LS_INFO) << "~FlexfecReceiveStreamImpl: " << config_.ToString();
|
|
|
|
|
process_thread_->DeRegisterModule(rtp_rtcp_.get());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FlexfecReceiveStreamImpl::RegisterWithTransport(
|
|
|
|
|
RtpStreamReceiverControllerInterface* receiver_controller) {
|
2021-05-31 17:36:47 +02:00
|
|
|
RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
|
2021-05-31 14:26:05 +02:00
|
|
|
RTC_DCHECK(!rtp_stream_receiver_);
|
|
|
|
|
|
|
|
|
|
if (!receiver_)
|
|
|
|
|
return;
|
2017-06-21 01:05:22 -07:00
|
|
|
|
|
|
|
|
// TODO(nisse): OnRtpPacket in this class delegates all real work to
|
2021-05-31 14:26:05 +02:00
|
|
|
// `receiver_`. So maybe we don't need to implement RtpPacketSinkInterface
|
2017-06-21 01:05:22 -07:00
|
|
|
// here at all, we'd then delete the OnRtpPacket method and instead register
|
2021-05-31 14:26:05 +02:00
|
|
|
// `receiver_` as the RtpPacketSinkInterface for this stream.
|
2017-06-21 01:05:22 -07:00
|
|
|
rtp_stream_receiver_ =
|
2021-06-14 10:54:20 +02:00
|
|
|
receiver_controller->CreateReceiver(config_.rtp.remote_ssrc, this);
|
2016-10-20 04:54:48 -07:00
|
|
|
}
|
|
|
|
|
|
2021-05-31 14:26:05 +02:00
|
|
|
void FlexfecReceiveStreamImpl::UnregisterFromTransport() {
|
2021-05-31 17:36:47 +02:00
|
|
|
RTC_DCHECK_RUN_ON(&packet_sequence_checker_);
|
2021-05-31 14:26:05 +02:00
|
|
|
rtp_stream_receiver_.reset();
|
2016-10-20 04:54:48 -07:00
|
|
|
}
|
|
|
|
|
|
2017-02-16 06:52:32 -08:00
|
|
|
void FlexfecReceiveStreamImpl::OnRtpPacket(const RtpPacketReceived& packet) {
|
2016-10-20 04:54:48 -07:00
|
|
|
if (!receiver_)
|
2017-02-16 06:52:32 -08:00
|
|
|
return;
|
2017-01-17 01:33:54 -08:00
|
|
|
|
2017-02-16 06:52:32 -08:00
|
|
|
receiver_->OnRtpPacket(packet);
|
2017-01-17 01:33:54 -08:00
|
|
|
|
|
|
|
|
// Do not report media packets in the RTCP RRs generated by |rtp_rtcp_|.
|
2021-06-14 10:54:20 +02:00
|
|
|
if (packet.Ssrc() == config_.rtp.remote_ssrc) {
|
2018-09-14 08:26:32 +02:00
|
|
|
rtp_receive_statistics_->OnRtpPacket(packet);
|
2017-01-17 01:33:54 -08:00
|
|
|
}
|
2016-10-20 04:54:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO(brandtr): Implement this member function when we have designed the
|
|
|
|
|
// stats for FlexFEC.
|
2016-12-19 01:13:46 -08:00
|
|
|
FlexfecReceiveStreamImpl::Stats FlexfecReceiveStreamImpl::GetStats() const {
|
|
|
|
|
return FlexfecReceiveStream::Stats();
|
2016-10-20 04:54:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|