2011-07-07 08:21:25 +00:00
|
|
|
/*
|
2012-01-24 17:16:59 +00:00
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
2011-07-07 08:21:25 +00:00
|
|
|
*
|
|
|
|
|
* 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 "modules/rtp_rtcp/source/rtp_rtcp_impl.h"
|
2013-01-09 13:54:43 +00:00
|
|
|
|
2013-05-29 14:27:38 +00:00
|
|
|
#include <string.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2017-07-06 04:38:06 -07:00
|
|
|
#include <algorithm>
|
2018-10-23 12:03:01 +02:00
|
|
|
#include <cstdint>
|
2019-09-17 17:06:18 +02:00
|
|
|
#include <memory>
|
2015-02-06 13:10:19 +00:00
|
|
|
#include <set>
|
2016-02-26 16:26:20 +01:00
|
|
|
#include <string>
|
2018-10-23 12:03:01 +02:00
|
|
|
#include <utility>
|
2015-02-06 13:10:19 +00:00
|
|
|
|
2022-05-13 11:42:16 +02:00
|
|
|
#include "absl/strings/string_view.h"
|
2019-02-21 07:55:59 +01:00
|
|
|
#include "api/transport/field_trial_based_config.h"
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "modules/rtp_rtcp/source/rtcp_packet/dlrr.h"
|
2021-06-18 13:44:13 +02:00
|
|
|
#include "modules/rtp_rtcp/source/rtcp_sender.h"
|
2018-10-23 12:03:01 +02:00
|
|
|
#include "modules/rtp_rtcp/source/rtp_rtcp_config.h"
|
2021-06-18 13:44:13 +02:00
|
|
|
#include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/checks.h"
|
|
|
|
|
#include "rtc_base/logging.h"
|
2021-03-12 17:45:26 +01:00
|
|
|
#include "system_wrappers/include/ntp_time.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2013-01-16 10:27:33 +00:00
|
|
|
// Disable warning C4355: 'this' : used in base member initializer list.
|
2012-02-08 23:41:49 +00:00
|
|
|
#pragma warning(disable : 4355)
|
2011-07-07 08:21:25 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
2017-07-06 04:38:06 -07:00
|
|
|
namespace {
|
|
|
|
|
const int64_t kRtpRtcpRttProcessTimeMs = 1000;
|
|
|
|
|
const int64_t kRtpRtcpBitrateProcessTimeMs = 10;
|
2017-09-04 07:23:56 -07:00
|
|
|
const int64_t kDefaultExpectedRetransmissionTimeMs = 125;
|
2017-07-06 04:38:06 -07:00
|
|
|
} // namespace
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2019-10-28 15:51:36 +01:00
|
|
|
ModuleRtpRtcpImpl::RtpSenderContext::RtpSenderContext(
|
2020-06-03 22:55:33 +02:00
|
|
|
const RtpRtcpInterface::Configuration& config)
|
2020-03-30 10:01:29 +02:00
|
|
|
: packet_history(config.clock, config.enable_rtx_padding_prioritization),
|
2021-08-04 14:45:32 +02:00
|
|
|
sequencer_(config.local_media_ssrc,
|
|
|
|
|
config.rtx_send_ssrc,
|
|
|
|
|
/*require_marker_before_media_padding=*/!config.audio,
|
|
|
|
|
config.clock),
|
2019-10-28 18:24:32 +01:00
|
|
|
packet_sender(config, &packet_history),
|
2021-08-12 11:34:03 +02:00
|
|
|
non_paced_sender(&packet_sender, &sequencer_),
|
2019-10-28 18:24:32 +01:00
|
|
|
packet_generator(
|
2019-10-28 15:51:36 +01:00
|
|
|
config,
|
2019-10-28 18:24:32 +01:00
|
|
|
&packet_history,
|
2021-08-13 17:25:44 +02:00
|
|
|
config.paced_sender ? config.paced_sender : &non_paced_sender) {}
|
2019-10-28 15:51:36 +01:00
|
|
|
|
2020-06-03 08:54:39 +02:00
|
|
|
std::unique_ptr<RtpRtcp> RtpRtcp::DEPRECATED_Create(
|
|
|
|
|
const Configuration& configuration) {
|
|
|
|
|
RTC_DCHECK(configuration.clock);
|
|
|
|
|
return std::make_unique<ModuleRtpRtcpImpl>(configuration);
|
|
|
|
|
}
|
|
|
|
|
|
2012-05-11 11:08:54 +00:00
|
|
|
ModuleRtpRtcpImpl::ModuleRtpRtcpImpl(const Configuration& configuration)
|
2021-06-18 13:44:13 +02:00
|
|
|
: rtcp_sender_(
|
|
|
|
|
RTCPSender::Configuration::FromRtpRtcpConfiguration(configuration)),
|
2019-07-12 17:35:05 +00:00
|
|
|
rtcp_receiver_(configuration, this),
|
2013-01-21 07:42:11 +00:00
|
|
|
clock_(configuration.clock),
|
2017-07-06 04:38:06 -07:00
|
|
|
last_bitrate_process_time_(clock_->TimeInMilliseconds()),
|
|
|
|
|
last_rtt_process_time_(clock_->TimeInMilliseconds()),
|
2016-05-02 23:44:01 -07:00
|
|
|
packet_overhead_(28), // IPV4 UDP.
|
2017-12-15 12:25:01 +01:00
|
|
|
nack_last_time_sent_full_ms_(0),
|
2013-01-16 10:27:33 +00:00
|
|
|
nack_last_seq_number_sent_(0),
|
2013-11-20 12:46:11 +00:00
|
|
|
rtt_stats_(configuration.rtt_stats),
|
|
|
|
|
rtt_ms_(0) {
|
2017-03-20 03:52:39 -07:00
|
|
|
if (!configuration.receiver_only) {
|
2019-10-28 15:51:36 +01:00
|
|
|
rtp_sender_ = std::make_unique<RtpSenderContext>(configuration);
|
2017-03-20 03:52:39 -07:00
|
|
|
// Make sure rtcp sender use same timestamp offset as rtp sender.
|
2019-10-28 15:51:36 +01:00
|
|
|
rtcp_sender_.SetTimestampOffset(
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_generator.TimestampOffset());
|
2017-03-20 03:52:39 -07:00
|
|
|
}
|
2016-08-18 02:01:49 -07:00
|
|
|
|
|
|
|
|
// Set default packet size limit.
|
2017-01-10 08:58:32 -08:00
|
|
|
// TODO(nisse): Kind-of duplicates
|
|
|
|
|
// webrtc::VideoSendStream::Config::Rtp::kDefaultMaxPacketSize.
|
|
|
|
|
const size_t kTcpOverIpv4HeaderSize = 40;
|
|
|
|
|
SetMaxRtpPacketSize(IP_PACKET_SIZE - kTcpOverIpv4HeaderSize);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2018-02-07 09:38:31 +01:00
|
|
|
ModuleRtpRtcpImpl::~ModuleRtpRtcpImpl() = default;
|
|
|
|
|
|
2013-01-16 10:27:33 +00:00
|
|
|
// Process any pending tasks such as timeouts (non time critical events).
|
2016-02-25 04:50:01 -08:00
|
|
|
void ModuleRtpRtcpImpl::Process() {
|
2013-08-15 23:38:54 +00:00
|
|
|
const int64_t now = clock_->TimeInMilliseconds();
|
2013-01-16 10:27:33 +00:00
|
|
|
|
2017-03-20 03:52:39 -07:00
|
|
|
if (rtp_sender_) {
|
|
|
|
|
if (now >= last_bitrate_process_time_ + kRtpRtcpBitrateProcessTimeMs) {
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_sender.ProcessBitrateAndNotifyObservers();
|
2017-03-20 03:52:39 -07:00
|
|
|
last_bitrate_process_time_ = now;
|
2017-07-06 04:38:06 -07:00
|
|
|
}
|
2012-01-16 11:06:31 +00:00
|
|
|
}
|
2017-07-06 04:38:06 -07:00
|
|
|
|
2020-05-18 12:47:03 +02:00
|
|
|
// TODO(bugs.webrtc.org/11581): We update the RTT once a second, whereas other
|
|
|
|
|
// things that run in this method are updated much more frequently. Move the
|
|
|
|
|
// RTT checking over to the worker thread, which matches better with where the
|
|
|
|
|
// stats are maintained.
|
2015-02-26 12:57:47 +00:00
|
|
|
bool process_rtt = now >= last_rtt_process_time_ + kRtpRtcpRttProcessTimeMs;
|
|
|
|
|
if (rtcp_sender_.Sending()) {
|
2017-09-27 13:25:24 +02:00
|
|
|
// Process RTT if we have received a report block and we haven't
|
2021-07-28 23:57:33 +02:00
|
|
|
// processed RTT for at least `kRtpRtcpRttProcessTimeMs` milliseconds.
|
2020-05-18 12:47:03 +02:00
|
|
|
// Note that LastReceivedReportBlockMs() grabs a lock, so check
|
2021-07-28 23:57:33 +02:00
|
|
|
// `process_rtt` first.
|
2021-03-15 19:12:16 +01:00
|
|
|
if (process_rtt && rtt_stats_ != nullptr &&
|
2020-05-18 12:47:03 +02:00
|
|
|
rtcp_receiver_.LastReceivedReportBlockMs() > last_rtt_process_time_) {
|
2021-03-15 19:12:16 +01:00
|
|
|
int64_t max_rtt_ms = 0;
|
|
|
|
|
for (const auto& block : rtcp_receiver_.GetLatestReportBlockData()) {
|
|
|
|
|
if (block.last_rtt_ms() > max_rtt_ms) {
|
|
|
|
|
max_rtt_ms = block.last_rtt_ms();
|
|
|
|
|
}
|
2012-02-14 12:49:59 +00:00
|
|
|
}
|
2015-02-26 12:57:47 +00:00
|
|
|
// Report the rtt.
|
2021-03-15 19:12:16 +01:00
|
|
|
if (max_rtt_ms > 0) {
|
|
|
|
|
rtt_stats_->OnRttUpdate(max_rtt_ms);
|
|
|
|
|
}
|
2015-02-26 12:57:47 +00:00
|
|
|
}
|
2013-01-09 13:54:43 +00:00
|
|
|
|
2015-02-26 12:57:47 +00:00
|
|
|
// Verify receiver reports are delivered and the reported sequence number
|
|
|
|
|
// is increasing.
|
2020-05-18 12:47:03 +02:00
|
|
|
// TODO(bugs.webrtc.org/11581): The timeout value needs to be checked every
|
|
|
|
|
// few seconds (see internals of RtcpRrTimeout). Here, we may be polling it
|
|
|
|
|
// a couple of hundred times a second, which isn't great since it grabs a
|
|
|
|
|
// lock. Note also that LastReceivedReportBlockMs() (called above) and
|
|
|
|
|
// RtcpRrTimeout() both grab the same lock and check the same timer, so
|
|
|
|
|
// it should be possible to consolidate that work somehow.
|
2018-11-15 16:44:37 -08:00
|
|
|
if (rtcp_receiver_.RtcpRrTimeout()) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG_F(LS_WARNING) << "Timeout: No RTCP RR received.";
|
2018-11-15 16:44:37 -08:00
|
|
|
} else if (rtcp_receiver_.RtcpRrSequenceNumberTimeout()) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG_F(LS_WARNING) << "Timeout: No increase in RTCP RR extended "
|
|
|
|
|
"highest sequence number.";
|
2015-02-26 12:57:47 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// Report rtt from receiver.
|
2013-10-31 12:14:34 +00:00
|
|
|
if (process_rtt) {
|
2015-02-26 12:57:47 +00:00
|
|
|
int64_t rtt_ms;
|
|
|
|
|
if (rtt_stats_ && rtcp_receiver_.GetAndResetXrRrRtt(&rtt_ms)) {
|
|
|
|
|
rtt_stats_->OnRttUpdate(rtt_ms);
|
|
|
|
|
}
|
2012-02-08 23:41:49 +00:00
|
|
|
}
|
2015-02-26 12:57:47 +00:00
|
|
|
}
|
2013-10-31 12:14:34 +00:00
|
|
|
|
2015-02-26 12:57:47 +00:00
|
|
|
// Get processed rtt.
|
|
|
|
|
if (process_rtt) {
|
|
|
|
|
last_rtt_process_time_ = now;
|
2016-02-19 09:03:26 -08:00
|
|
|
if (rtt_stats_) {
|
|
|
|
|
// Make sure we have a valid RTT before setting.
|
|
|
|
|
int64_t last_rtt = rtt_stats_->LastProcessedRtt();
|
|
|
|
|
if (last_rtt >= 0)
|
|
|
|
|
set_rtt_ms(last_rtt);
|
|
|
|
|
}
|
2012-01-16 11:06:31 +00:00
|
|
|
}
|
|
|
|
|
|
2016-07-20 15:26:59 +02:00
|
|
|
if (rtcp_sender_.TimeToSendRTCPReport())
|
|
|
|
|
rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport);
|
2015-02-26 12:57:47 +00:00
|
|
|
|
2021-02-05 12:11:56 +01:00
|
|
|
if (rtcp_sender_.TMMBR() && rtcp_receiver_.UpdateTmmbrTimers()) {
|
2017-02-20 06:03:01 -08:00
|
|
|
rtcp_receiver_.NotifyTmmbrUpdated();
|
2012-01-16 11:06:31 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-13 14:15:15 +00:00
|
|
|
void ModuleRtpRtcpImpl::SetRtxSendStatus(int mode) {
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_generator.SetRtxStatus(mode);
|
2012-01-10 14:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-13 14:15:15 +00:00
|
|
|
int ModuleRtpRtcpImpl::RtxSendStatus() const {
|
2019-10-28 18:24:32 +01:00
|
|
|
return rtp_sender_ ? rtp_sender_->packet_generator.RtxStatus() : kRtxOff;
|
2014-06-05 08:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-21 20:24:50 +08:00
|
|
|
void ModuleRtpRtcpImpl::SetRtxSendPayloadType(int payload_type,
|
|
|
|
|
int associated_payload_type) {
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_generator.SetRtxPayloadType(payload_type,
|
|
|
|
|
associated_payload_type);
|
2013-04-12 14:55:46 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-17 13:02:27 +02:00
|
|
|
absl::optional<uint32_t> ModuleRtpRtcpImpl::RtxSsrc() const {
|
2019-10-28 18:24:32 +01:00
|
|
|
return rtp_sender_ ? rtp_sender_->packet_generator.RtxSsrc() : absl::nullopt;
|
2019-10-17 13:02:27 +02:00
|
|
|
}
|
|
|
|
|
|
2018-06-14 12:59:38 +02:00
|
|
|
absl::optional<uint32_t> ModuleRtpRtcpImpl::FlexfecSsrc() const {
|
2019-10-28 15:51:36 +01:00
|
|
|
if (rtp_sender_) {
|
2019-10-28 18:24:32 +01:00
|
|
|
return rtp_sender_->packet_generator.FlexfecSsrc();
|
2019-10-28 15:51:36 +01:00
|
|
|
}
|
2018-06-14 12:59:38 +02:00
|
|
|
return absl::nullopt;
|
2016-11-14 05:14:50 -08:00
|
|
|
}
|
|
|
|
|
|
2023-02-09 12:06:50 +01:00
|
|
|
void ModuleRtpRtcpImpl::IncomingRtcpPacket(
|
|
|
|
|
rtc::ArrayView<const uint8_t> rtcp_packet) {
|
|
|
|
|
rtcp_receiver_.IncomingPacket(rtcp_packet);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-04 16:49:25 +01:00
|
|
|
void ModuleRtpRtcpImpl::RegisterSendPayloadFrequency(int payload_type,
|
|
|
|
|
int payload_frequency) {
|
|
|
|
|
rtcp_sender_.SetRtpClockRate(payload_type, payload_frequency);
|
2016-02-26 16:31:37 +01:00
|
|
|
}
|
|
|
|
|
|
2015-01-21 08:22:50 +00:00
|
|
|
int32_t ModuleRtpRtcpImpl::DeRegisterSendPayload(const int8_t payload_type) {
|
2019-02-06 22:48:11 +01:00
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
uint32_t ModuleRtpRtcpImpl::StartTimestamp() const {
|
2019-10-28 18:24:32 +01:00
|
|
|
return rtp_sender_->packet_generator.TimestampOffset();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-01-16 10:27:33 +00:00
|
|
|
// Configure start timestamp, default is a random number.
|
2014-12-19 13:49:55 +00:00
|
|
|
void ModuleRtpRtcpImpl::SetStartTimestamp(const uint32_t timestamp) {
|
2016-08-18 02:01:49 -07:00
|
|
|
rtcp_sender_.SetTimestampOffset(timestamp);
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_generator.SetTimestampOffset(timestamp);
|
2020-02-07 10:05:15 +01:00
|
|
|
rtp_sender_->packet_sender.SetTimestampOffset(timestamp);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
uint16_t ModuleRtpRtcpImpl::SequenceNumber() const {
|
2021-08-12 11:34:03 +02:00
|
|
|
MutexLock lock(&rtp_sender_->sequencer_mutex);
|
|
|
|
|
return rtp_sender_->sequencer_.media_sequence_number();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-01-16 10:27:33 +00:00
|
|
|
// Set SequenceNumber, default is a random number.
|
2014-12-19 13:49:55 +00:00
|
|
|
void ModuleRtpRtcpImpl::SetSequenceNumber(const uint16_t seq_num) {
|
2021-08-12 11:34:03 +02:00
|
|
|
MutexLock lock(&rtp_sender_->sequencer_mutex);
|
|
|
|
|
rtp_sender_->sequencer_.set_media_sequence_number(seq_num);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-15 14:59:13 +02:00
|
|
|
void ModuleRtpRtcpImpl::SetRtpState(const RtpState& rtp_state) {
|
2021-08-12 11:34:03 +02:00
|
|
|
MutexLock lock(&rtp_sender_->sequencer_mutex);
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_generator.SetRtpState(rtp_state);
|
2021-08-12 11:34:03 +02:00
|
|
|
rtp_sender_->sequencer_.SetRtpState(rtp_state);
|
2016-08-18 02:01:49 -07:00
|
|
|
rtcp_sender_.SetTimestampOffset(rtp_state.start_timestamp);
|
2014-07-07 13:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
2016-04-15 14:59:13 +02:00
|
|
|
void ModuleRtpRtcpImpl::SetRtxState(const RtpState& rtp_state) {
|
2021-08-12 11:34:03 +02:00
|
|
|
MutexLock lock(&rtp_sender_->sequencer_mutex);
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_generator.SetRtxRtpState(rtp_state);
|
2021-08-12 11:34:03 +02:00
|
|
|
rtp_sender_->sequencer_.set_rtx_sequence_number(rtp_state.sequence_number);
|
2016-04-15 14:59:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RtpState ModuleRtpRtcpImpl::GetRtpState() const {
|
2021-08-12 11:34:03 +02:00
|
|
|
MutexLock lock(&rtp_sender_->sequencer_mutex);
|
2019-10-28 18:24:32 +01:00
|
|
|
RtpState state = rtp_sender_->packet_generator.GetRtpState();
|
2021-08-12 11:34:03 +02:00
|
|
|
rtp_sender_->sequencer_.PopulateRtpState(state);
|
2019-10-28 15:51:36 +01:00
|
|
|
return state;
|
2016-04-15 14:59:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RtpState ModuleRtpRtcpImpl::GetRtxState() const {
|
2021-08-12 11:34:03 +02:00
|
|
|
MutexLock lock(&rtp_sender_->sequencer_mutex);
|
|
|
|
|
RtpState state = rtp_sender_->packet_generator.GetRtxRtpState();
|
|
|
|
|
state.sequence_number = rtp_sender_->sequencer_.rtx_sequence_number();
|
|
|
|
|
return state;
|
2014-07-07 13:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
2022-05-13 11:42:16 +02:00
|
|
|
void ModuleRtpRtcpImpl::SetMid(absl::string_view mid) {
|
2018-03-22 15:17:27 -07:00
|
|
|
if (rtp_sender_) {
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_generator.SetMid(mid);
|
2018-03-22 15:17:27 -07:00
|
|
|
}
|
|
|
|
|
// TODO(bugs.webrtc.org/4050): If we end up supporting the MID SDES item for
|
|
|
|
|
// RTCP, this will need to be passed down to the RTCPSender also.
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-15 15:25:39 +00:00
|
|
|
// TODO(pbos): Handle media and RTX streams separately (separate RTCP
|
|
|
|
|
// feedbacks).
|
|
|
|
|
RTCPSender::FeedbackState ModuleRtpRtcpImpl::GetFeedbackState() {
|
|
|
|
|
RTCPSender::FeedbackState state;
|
2017-03-20 03:52:39 -07:00
|
|
|
// This is called also when receiver_only is true. Hence below
|
|
|
|
|
// checks that rtp_sender_ exists.
|
|
|
|
|
if (rtp_sender_) {
|
|
|
|
|
StreamDataCounters rtp_stats;
|
|
|
|
|
StreamDataCounters rtx_stats;
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_sender.GetDataCounters(&rtp_stats, &rtx_stats);
|
2017-03-20 03:52:39 -07:00
|
|
|
state.packets_sent =
|
|
|
|
|
rtp_stats.transmitted.packets + rtx_stats.transmitted.packets;
|
|
|
|
|
state.media_bytes_sent = rtp_stats.transmitted.payload_bytes +
|
|
|
|
|
rtx_stats.transmitted.payload_bytes;
|
2019-10-28 15:51:36 +01:00
|
|
|
state.send_bitrate =
|
2020-05-11 18:22:02 +02:00
|
|
|
rtp_sender_->packet_sender.GetSendRates().Sum().bps<uint32_t>();
|
2017-03-20 03:52:39 -07:00
|
|
|
}
|
2020-05-20 09:32:51 +02:00
|
|
|
state.receiver = &rtcp_receiver_;
|
2014-07-15 15:25:39 +00:00
|
|
|
|
2021-03-10 14:52:35 +01:00
|
|
|
uint32_t received_ntp_secs = 0;
|
|
|
|
|
uint32_t received_ntp_frac = 0;
|
|
|
|
|
state.remote_sr = 0;
|
|
|
|
|
if (rtcp_receiver_.NTP(&received_ntp_secs, &received_ntp_frac,
|
|
|
|
|
/*rtcp_arrival_time_secs=*/&state.last_rr_ntp_secs,
|
|
|
|
|
/*rtcp_arrival_time_frac=*/&state.last_rr_ntp_frac,
|
2021-03-10 15:05:55 +01:00
|
|
|
/*rtcp_timestamp=*/nullptr,
|
|
|
|
|
/*remote_sender_packet_count=*/nullptr,
|
|
|
|
|
/*remote_sender_octet_count=*/nullptr,
|
|
|
|
|
/*remote_sender_reports_count=*/nullptr)) {
|
2021-03-10 14:52:35 +01:00
|
|
|
state.remote_sr = ((received_ntp_secs & 0x0000ffff) << 16) +
|
|
|
|
|
((received_ntp_frac & 0xffff0000) >> 16);
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2018-04-16 11:16:21 +02:00
|
|
|
state.last_xr_rtis = rtcp_receiver_.ConsumeReceivedXrReferenceTimeInfo();
|
2014-07-15 15:25:39 +00:00
|
|
|
|
|
|
|
|
return state;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
int32_t ModuleRtpRtcpImpl::SetSendingStatus(const bool sending) {
|
2013-01-16 10:27:33 +00:00
|
|
|
if (rtcp_sender_.Sending() != sending) {
|
2022-09-15 11:11:20 +00:00
|
|
|
// Sends RTCP BYE when going from true to false
|
2021-04-23 20:31:08 +02:00
|
|
|
rtcp_sender_.SetSendingStatus(GetFeedbackState(), sending);
|
2012-02-08 23:41:49 +00:00
|
|
|
}
|
|
|
|
|
return 0;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-08 23:41:49 +00:00
|
|
|
bool ModuleRtpRtcpImpl::Sending() const {
|
2013-01-16 10:27:33 +00:00
|
|
|
return rtcp_sender_.Sending();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2014-12-19 13:49:55 +00:00
|
|
|
void ModuleRtpRtcpImpl::SetSendingMediaStatus(const bool sending) {
|
2022-07-05 15:50:11 +02:00
|
|
|
rtp_sender_->packet_generator.SetSendingMediaStatus(sending);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-02-08 23:41:49 +00:00
|
|
|
bool ModuleRtpRtcpImpl::SendingMedia() const {
|
2019-10-28 18:24:32 +01:00
|
|
|
return rtp_sender_ ? rtp_sender_->packet_generator.SendingMedia() : false;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2019-12-11 16:47:09 +01:00
|
|
|
bool ModuleRtpRtcpImpl::IsAudioConfigured() const {
|
|
|
|
|
return rtp_sender_ ? rtp_sender_->packet_generator.IsAudioConfigured()
|
|
|
|
|
: false;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-10 09:58:08 +02:00
|
|
|
void ModuleRtpRtcpImpl::SetAsPartOfAllocation(bool part_of_allocation) {
|
|
|
|
|
RTC_CHECK(rtp_sender_);
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_sender.ForceIncludeSendPacketsInAllocation(
|
2019-10-28 15:51:36 +01:00
|
|
|
part_of_allocation);
|
2018-10-10 09:58:08 +02:00
|
|
|
}
|
|
|
|
|
|
2019-03-04 16:49:25 +01:00
|
|
|
bool ModuleRtpRtcpImpl::OnSendingRtpFrame(uint32_t timestamp,
|
|
|
|
|
int64_t capture_time_ms,
|
|
|
|
|
int payload_type,
|
|
|
|
|
bool force_sender_report) {
|
|
|
|
|
if (!Sending())
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-06-18 13:44:51 +02:00
|
|
|
// TODO(bugs.webrtc.org/12873): Migrate this method and it's users to use
|
|
|
|
|
// optional Timestamps.
|
|
|
|
|
absl::optional<Timestamp> capture_time;
|
|
|
|
|
if (capture_time_ms > 0) {
|
|
|
|
|
capture_time = Timestamp::Millis(capture_time_ms);
|
|
|
|
|
}
|
|
|
|
|
absl::optional<int> payload_type_optional;
|
|
|
|
|
if (payload_type >= 0)
|
|
|
|
|
payload_type_optional = payload_type;
|
|
|
|
|
rtcp_sender_.SetLastRtpTime(timestamp, capture_time, payload_type_optional);
|
2019-03-04 16:49:25 +01:00
|
|
|
// Make sure an RTCP report isn't queued behind a key frame.
|
|
|
|
|
if (rtcp_sender_.TimeToSendRTCPReport(force_sender_report))
|
|
|
|
|
rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpReport);
|
|
|
|
|
|
|
|
|
|
return true;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2019-06-17 16:31:53 +02:00
|
|
|
bool ModuleRtpRtcpImpl::TrySendPacket(RtpPacketToSend* packet,
|
|
|
|
|
const PacedPacketInfo& pacing_info) {
|
2019-10-28 15:51:36 +01:00
|
|
|
RTC_DCHECK(rtp_sender_);
|
|
|
|
|
// TODO(sprang): Consider if we can remove this check.
|
2019-10-28 18:24:32 +01:00
|
|
|
if (!rtp_sender_->packet_generator.SendingMedia()) {
|
2019-10-28 15:51:36 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2021-08-12 11:34:03 +02:00
|
|
|
{
|
|
|
|
|
MutexLock lock(&rtp_sender_->sequencer_mutex);
|
|
|
|
|
if (packet->packet_type() == RtpPacketMediaType::kPadding &&
|
|
|
|
|
packet->Ssrc() == rtp_sender_->packet_generator.SSRC() &&
|
|
|
|
|
!rtp_sender_->sequencer_.CanSendPaddingOnMediaSsrc()) {
|
|
|
|
|
// New media packet preempted this generated padding packet, discard it.
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
bool is_flexfec =
|
|
|
|
|
packet->packet_type() == RtpPacketMediaType::kForwardErrorCorrection &&
|
|
|
|
|
packet->Ssrc() == rtp_sender_->packet_generator.FlexfecSsrc();
|
|
|
|
|
if (!is_flexfec) {
|
|
|
|
|
rtp_sender_->sequencer_.Sequence(*packet);
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_sender.SendPacket(packet, pacing_info);
|
2019-10-28 15:51:36 +01:00
|
|
|
return true;
|
2019-06-17 16:31:53 +02:00
|
|
|
}
|
|
|
|
|
|
2020-07-02 17:41:32 +02:00
|
|
|
void ModuleRtpRtcpImpl::SetFecProtectionParams(const FecProtectionParams&,
|
|
|
|
|
const FecProtectionParams&) {
|
|
|
|
|
// Deferred FEC not supported in deprecated RTP module.
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<RtpPacketToSend>>
|
|
|
|
|
ModuleRtpRtcpImpl::FetchFecPackets() {
|
|
|
|
|
// Deferred FEC not supported in deprecated RTP module.
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-08 16:53:06 +02:00
|
|
|
void ModuleRtpRtcpImpl::OnAbortedRetransmissions(
|
|
|
|
|
rtc::ArrayView<const uint16_t> sequence_numbers) {
|
|
|
|
|
RTC_DCHECK_NOTREACHED()
|
|
|
|
|
<< "Stream flushing not supported with legacy rtp modules.";
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-24 12:39:32 +02:00
|
|
|
void ModuleRtpRtcpImpl::OnPacketsAcknowledged(
|
|
|
|
|
rtc::ArrayView<const uint16_t> sequence_numbers) {
|
|
|
|
|
RTC_DCHECK(rtp_sender_);
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_history.CullAcknowledgedPackets(sequence_numbers);
|
2019-10-24 12:39:32 +02:00
|
|
|
}
|
|
|
|
|
|
2019-07-12 17:33:46 +00:00
|
|
|
bool ModuleRtpRtcpImpl::SupportsPadding() const {
|
2019-10-28 15:51:36 +01:00
|
|
|
RTC_DCHECK(rtp_sender_);
|
2019-10-28 18:24:32 +01:00
|
|
|
return rtp_sender_->packet_generator.SupportsPadding();
|
2019-07-12 17:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ModuleRtpRtcpImpl::SupportsRtxPayloadPadding() const {
|
2019-10-28 15:51:36 +01:00
|
|
|
RTC_DCHECK(rtp_sender_);
|
2019-10-28 18:24:32 +01:00
|
|
|
return rtp_sender_->packet_generator.SupportsRtxPayloadPadding();
|
2019-07-12 17:33:46 +00:00
|
|
|
}
|
|
|
|
|
|
2019-07-05 16:53:43 +02:00
|
|
|
std::vector<std::unique_ptr<RtpPacketToSend>>
|
|
|
|
|
ModuleRtpRtcpImpl::GeneratePadding(size_t target_size_bytes) {
|
2019-10-28 15:51:36 +01:00
|
|
|
RTC_DCHECK(rtp_sender_);
|
2021-08-12 11:34:03 +02:00
|
|
|
MutexLock lock(&rtp_sender_->sequencer_mutex);
|
2019-10-28 18:24:32 +01:00
|
|
|
return rtp_sender_->packet_generator.GeneratePadding(
|
2021-08-04 14:45:32 +02:00
|
|
|
target_size_bytes, rtp_sender_->packet_sender.MediaHasBeenSent(),
|
2021-08-12 11:34:03 +02:00
|
|
|
rtp_sender_->sequencer_.CanSendPaddingOnMediaSsrc());
|
2019-06-26 15:49:27 +02:00
|
|
|
}
|
|
|
|
|
|
2020-02-07 10:05:15 +01:00
|
|
|
std::vector<RtpSequenceNumberMap::Info>
|
|
|
|
|
ModuleRtpRtcpImpl::GetSentRtpPacketInfos(
|
|
|
|
|
rtc::ArrayView<const uint16_t> sequence_numbers) const {
|
|
|
|
|
RTC_DCHECK(rtp_sender_);
|
|
|
|
|
return rtp_sender_->packet_sender.GetSentRtpPacketInfos(sequence_numbers);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-07 18:18:32 +02:00
|
|
|
size_t ModuleRtpRtcpImpl::ExpectedPerPacketOverhead() const {
|
|
|
|
|
if (!rtp_sender_) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return rtp_sender_->packet_generator.ExpectedPerPacketOverhead();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-13 16:12:41 +02:00
|
|
|
void ModuleRtpRtcpImpl::OnPacketSendingThreadSwitched() {}
|
|
|
|
|
|
2017-01-10 08:58:32 -08:00
|
|
|
size_t ModuleRtpRtcpImpl::MaxRtpPacketSize() const {
|
2019-10-28 15:51:36 +01:00
|
|
|
RTC_DCHECK(rtp_sender_);
|
2019-10-28 18:24:32 +01:00
|
|
|
return rtp_sender_->packet_generator.MaxRtpPacketSize();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2017-01-10 08:58:32 -08:00
|
|
|
void ModuleRtpRtcpImpl::SetMaxRtpPacketSize(size_t rtp_packet_size) {
|
|
|
|
|
RTC_DCHECK_LE(rtp_packet_size, IP_PACKET_SIZE)
|
|
|
|
|
<< "rtp packet size too large: " << rtp_packet_size;
|
|
|
|
|
RTC_DCHECK_GT(rtp_packet_size, packet_overhead_)
|
|
|
|
|
<< "rtp packet size too small: " << rtp_packet_size;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-01-10 08:58:32 -08:00
|
|
|
rtcp_sender_.SetMaxRtpPacketSize(rtp_packet_size);
|
2019-10-28 15:51:36 +01:00
|
|
|
if (rtp_sender_) {
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_generator.SetMaxRtpPacketSize(rtp_packet_size);
|
2019-10-28 15:51:36 +01:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-10-02 02:36:56 -07:00
|
|
|
RtcpMode ModuleRtpRtcpImpl::RTCP() const {
|
2016-03-18 15:02:07 -07:00
|
|
|
return rtcp_sender_.Status();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-01-16 10:27:33 +00:00
|
|
|
// Configure RTCP status i.e on/off.
|
2015-10-02 02:36:56 -07:00
|
|
|
void ModuleRtpRtcpImpl::SetRTCPStatus(const RtcpMode method) {
|
2014-12-19 13:49:55 +00:00
|
|
|
rtcp_sender_.SetRTCPStatus(method);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2011-10-13 15:19:55 +00:00
|
|
|
|
2022-05-13 11:42:16 +02:00
|
|
|
int32_t ModuleRtpRtcpImpl::SetCNAME(absl::string_view c_name) {
|
2013-01-16 10:27:33 +00:00
|
|
|
return rtcp_sender_.SetCNAME(c_name);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-01-16 10:27:33 +00:00
|
|
|
// Get RoundTripTime.
|
2013-04-08 11:08:41 +00:00
|
|
|
int32_t ModuleRtpRtcpImpl::RTT(const uint32_t remote_ssrc,
|
2015-01-12 21:51:21 +00:00
|
|
|
int64_t* rtt,
|
|
|
|
|
int64_t* avg_rtt,
|
|
|
|
|
int64_t* min_rtt,
|
|
|
|
|
int64_t* max_rtt) const {
|
2014-04-24 22:10:24 +00:00
|
|
|
int32_t ret = rtcp_receiver_.RTT(remote_ssrc, rtt, avg_rtt, min_rtt, max_rtt);
|
|
|
|
|
if (rtt && *rtt == 0) {
|
|
|
|
|
// Try to get RTT from RtcpRttStats class.
|
2015-01-12 21:51:21 +00:00
|
|
|
*rtt = rtt_ms();
|
2014-04-24 22:10:24 +00:00
|
|
|
}
|
|
|
|
|
return ret;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2019-03-04 16:49:25 +01:00
|
|
|
int64_t ModuleRtpRtcpImpl::ExpectedRetransmissionTimeMs() const {
|
|
|
|
|
int64_t expected_retransmission_time_ms = rtt_ms();
|
|
|
|
|
if (expected_retransmission_time_ms > 0) {
|
|
|
|
|
return expected_retransmission_time_ms;
|
|
|
|
|
}
|
2021-07-28 23:57:33 +02:00
|
|
|
// No rtt available (`kRtpRtcpRttProcessTimeMs` not yet passed?), so try to
|
2019-03-04 16:49:25 +01:00
|
|
|
// poll avg_rtt_ms directly from rtcp receiver.
|
|
|
|
|
if (rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), nullptr,
|
|
|
|
|
&expected_retransmission_time_ms, nullptr,
|
|
|
|
|
nullptr) == 0) {
|
|
|
|
|
return expected_retransmission_time_ms;
|
|
|
|
|
}
|
|
|
|
|
return kDefaultExpectedRetransmissionTimeMs;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-16 10:27:33 +00:00
|
|
|
// Force a send of an RTCP packet.
|
|
|
|
|
// Normal SR and RR are triggered via the process function.
|
2015-05-11 10:17:43 +02:00
|
|
|
int32_t ModuleRtpRtcpImpl::SendRTCP(RTCPPacketType packet_type) {
|
|
|
|
|
return rtcp_sender_.SendRTCP(GetFeedbackState(), packet_type);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-09 09:47:53 +00:00
|
|
|
void ModuleRtpRtcpImpl::GetSendStreamDataCounters(
|
|
|
|
|
StreamDataCounters* rtp_counters,
|
|
|
|
|
StreamDataCounters* rtx_counters) const {
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_sender.GetDataCounters(rtp_counters, rtx_counters);
|
2014-12-09 09:47:53 +00:00
|
|
|
}
|
|
|
|
|
|
2013-01-16 10:27:33 +00:00
|
|
|
// Received RTCP report.
|
2019-05-27 12:19:33 +02:00
|
|
|
std::vector<ReportBlockData> ModuleRtpRtcpImpl::GetLatestReportBlockData()
|
|
|
|
|
const {
|
|
|
|
|
return rtcp_receiver_.GetLatestReportBlockData();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-12 17:45:26 +01:00
|
|
|
absl::optional<RtpRtcpInterface::SenderReportStats>
|
|
|
|
|
ModuleRtpRtcpImpl::GetSenderReportStats() const {
|
|
|
|
|
SenderReportStats stats;
|
|
|
|
|
uint32_t remote_timestamp_secs;
|
|
|
|
|
uint32_t remote_timestamp_frac;
|
|
|
|
|
uint32_t arrival_timestamp_secs;
|
|
|
|
|
uint32_t arrival_timestamp_frac;
|
|
|
|
|
if (rtcp_receiver_.NTP(&remote_timestamp_secs, &remote_timestamp_frac,
|
|
|
|
|
&arrival_timestamp_secs, &arrival_timestamp_frac,
|
2023-02-27 19:49:31 +01:00
|
|
|
&stats.last_remote_rtp_timestamp, &stats.packets_sent,
|
2021-03-12 17:45:26 +01:00
|
|
|
&stats.bytes_sent, &stats.reports_count)) {
|
|
|
|
|
stats.last_remote_timestamp.Set(remote_timestamp_secs,
|
|
|
|
|
remote_timestamp_frac);
|
|
|
|
|
stats.last_arrival_timestamp.Set(arrival_timestamp_secs,
|
|
|
|
|
arrival_timestamp_frac);
|
|
|
|
|
return stats;
|
|
|
|
|
}
|
|
|
|
|
return absl::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-03 14:51:22 +00:00
|
|
|
absl::optional<RtpRtcpInterface::NonSenderRttStats>
|
|
|
|
|
ModuleRtpRtcpImpl::GetNonSenderRttStats() const {
|
|
|
|
|
// This is not implemented for this legacy class.
|
|
|
|
|
return absl::nullopt;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-16 10:27:33 +00:00
|
|
|
// (REMB) Receiver Estimated Max Bitrate.
|
2017-12-13 13:35:10 +01:00
|
|
|
void ModuleRtpRtcpImpl::SetRemb(int64_t bitrate_bps,
|
|
|
|
|
std::vector<uint32_t> ssrcs) {
|
|
|
|
|
rtcp_sender_.SetRemb(bitrate_bps, std::move(ssrcs));
|
2011-09-20 13:52:04 +00:00
|
|
|
}
|
|
|
|
|
|
2017-10-10 17:46:26 +02:00
|
|
|
void ModuleRtpRtcpImpl::UnsetRemb() {
|
2017-10-18 13:32:57 +02:00
|
|
|
rtcp_sender_.UnsetRemb();
|
2011-09-20 13:52:04 +00:00
|
|
|
}
|
|
|
|
|
|
2018-10-29 11:22:05 +01:00
|
|
|
void ModuleRtpRtcpImpl::SetExtmapAllowMixed(bool extmap_allow_mixed) {
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_generator.SetExtmapAllowMixed(extmap_allow_mixed);
|
2018-10-29 11:22:05 +01:00
|
|
|
}
|
|
|
|
|
|
2019-10-14 17:32:21 +02:00
|
|
|
void ModuleRtpRtcpImpl::RegisterRtpHeaderExtension(absl::string_view uri,
|
2018-09-14 18:29:32 +02:00
|
|
|
int id) {
|
2019-10-28 15:51:36 +01:00
|
|
|
bool registered =
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_generator.RegisterRtpHeaderExtension(uri, id);
|
2019-10-14 17:32:21 +02:00
|
|
|
RTC_CHECK(registered);
|
2018-09-14 18:29:32 +02:00
|
|
|
}
|
|
|
|
|
|
2019-10-14 17:32:21 +02:00
|
|
|
void ModuleRtpRtcpImpl::DeregisterSendRtpHeaderExtension(
|
|
|
|
|
absl::string_view uri) {
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_generator.DeregisterRtpHeaderExtension(uri);
|
2019-10-14 17:32:21 +02:00
|
|
|
}
|
2011-12-16 14:31:37 +00:00
|
|
|
|
2016-08-22 08:26:15 -07:00
|
|
|
void ModuleRtpRtcpImpl::SetTmmbn(std::vector<rtcp::TmmbItem> bounding_set) {
|
|
|
|
|
rtcp_sender_.SetTmmbn(std::move(bounding_set));
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-01-16 10:27:33 +00:00
|
|
|
// Send a Negative acknowledgment packet.
|
2013-04-08 11:08:41 +00:00
|
|
|
int32_t ModuleRtpRtcpImpl::SendNACK(const uint16_t* nack_list,
|
|
|
|
|
const uint16_t size) {
|
2014-12-08 13:29:02 +00:00
|
|
|
uint16_t nack_length = size;
|
2013-04-08 11:08:41 +00:00
|
|
|
uint16_t start_id = 0;
|
2017-12-15 12:25:01 +01:00
|
|
|
int64_t now_ms = clock_->TimeInMilliseconds();
|
|
|
|
|
if (TimeToSendFullNackList(now_ms)) {
|
|
|
|
|
nack_last_time_sent_full_ms_ = now_ms;
|
2012-02-08 23:41:49 +00:00
|
|
|
} else {
|
2014-12-08 13:29:02 +00:00
|
|
|
// Only send extended list.
|
2013-01-16 10:27:33 +00:00
|
|
|
if (nack_last_seq_number_sent_ == nack_list[size - 1]) {
|
2014-12-08 13:29:02 +00:00
|
|
|
// Last sequence number is the same, do not send list.
|
2012-02-08 23:41:49 +00:00
|
|
|
return 0;
|
2014-12-08 13:29:02 +00:00
|
|
|
}
|
|
|
|
|
// Send new sequence numbers.
|
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
|
if (nack_last_seq_number_sent_ == nack_list[i]) {
|
|
|
|
|
start_id = i + 1;
|
|
|
|
|
break;
|
2012-12-21 17:46:24 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
2014-12-08 13:29:02 +00:00
|
|
|
nack_length = size - start_id;
|
2012-02-08 23:41:49 +00:00
|
|
|
}
|
2014-12-08 13:29:02 +00:00
|
|
|
|
2013-03-05 09:02:06 +00:00
|
|
|
// Our RTCP NACK implementation is limited to kRtcpMaxNackFields sequence
|
|
|
|
|
// numbers per RTCP packet.
|
2014-12-08 13:29:02 +00:00
|
|
|
if (nack_length > kRtcpMaxNackFields) {
|
|
|
|
|
nack_length = kRtcpMaxNackFields;
|
2013-03-05 09:02:06 +00:00
|
|
|
}
|
2014-12-08 13:29:02 +00:00
|
|
|
nack_last_seq_number_sent_ = nack_list[start_id + nack_length - 1];
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-03-12 03:30:23 -08:00
|
|
|
return rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpNack, nack_length,
|
|
|
|
|
&nack_list[start_id]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ModuleRtpRtcpImpl::SendNack(
|
|
|
|
|
const std::vector<uint16_t>& sequence_numbers) {
|
|
|
|
|
rtcp_sender_.SendRTCP(GetFeedbackState(), kRtcpNack, sequence_numbers.size(),
|
|
|
|
|
sequence_numbers.data());
|
2014-12-08 13:29:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool ModuleRtpRtcpImpl::TimeToSendFullNackList(int64_t now) const {
|
|
|
|
|
// Use RTT from RtcpRttStats class if provided.
|
2015-01-12 21:51:21 +00:00
|
|
|
int64_t rtt = rtt_ms();
|
2014-12-08 13:29:02 +00:00
|
|
|
if (rtt == 0) {
|
|
|
|
|
rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int64_t kStartUpRttMs = 100;
|
|
|
|
|
int64_t wait_time = 5 + ((rtt * 3) >> 1); // 5 + RTT * 1.5.
|
|
|
|
|
if (rtt == 0) {
|
|
|
|
|
wait_time = kStartUpRttMs;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-28 23:57:33 +02:00
|
|
|
// Send a full NACK list once within every `wait_time`.
|
2017-12-15 12:25:01 +01:00
|
|
|
return now - nack_last_time_sent_full_ms_ > wait_time;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-21 08:22:50 +00:00
|
|
|
// Store the sent packets, needed to answer to Negative acknowledgment requests.
|
2014-12-19 13:49:55 +00:00
|
|
|
void ModuleRtpRtcpImpl::SetStorePacketsStatus(const bool enable,
|
|
|
|
|
const uint16_t number_to_store) {
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_history.SetStorePacketsStatus(
|
2019-10-28 15:51:36 +01:00
|
|
|
enable ? RtpPacketHistory::StorageMode::kStoreAndCull
|
|
|
|
|
: RtpPacketHistory::StorageMode::kDisabled,
|
|
|
|
|
number_to_store);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-15 23:38:54 +00:00
|
|
|
bool ModuleRtpRtcpImpl::StorePackets() const {
|
2019-10-28 18:24:32 +01:00
|
|
|
return rtp_sender_->packet_history.GetStorageMode() !=
|
2019-10-28 15:51:36 +01:00
|
|
|
RtpPacketHistory::StorageMode::kDisabled;
|
2013-07-16 19:25:04 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-10 12:57:28 +02:00
|
|
|
void ModuleRtpRtcpImpl::SendCombinedRtcpPacket(
|
|
|
|
|
std::vector<std::unique_ptr<rtcp::RtcpPacket>> rtcp_packets) {
|
|
|
|
|
rtcp_sender_.SendCombinedRtcpPacket(std::move(rtcp_packets));
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-25 13:00:51 +01:00
|
|
|
int32_t ModuleRtpRtcpImpl::SendLossNotification(uint16_t last_decoded_seq_num,
|
|
|
|
|
uint16_t last_received_seq_num,
|
2019-06-03 14:37:50 +02:00
|
|
|
bool decodability_flag,
|
|
|
|
|
bool buffering_allowed) {
|
2019-02-25 13:00:51 +01:00
|
|
|
return rtcp_sender_.SendLossNotification(
|
|
|
|
|
GetFeedbackState(), last_decoded_seq_num, last_received_seq_num,
|
2019-06-03 14:37:50 +02:00
|
|
|
decodability_flag, buffering_allowed);
|
2019-02-25 13:00:51 +01:00
|
|
|
}
|
|
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
void ModuleRtpRtcpImpl::SetRemoteSSRC(const uint32_t ssrc) {
|
2013-01-16 10:27:33 +00:00
|
|
|
// Inform about the incoming SSRC.
|
|
|
|
|
rtcp_sender_.SetRemoteSSRC(ssrc);
|
|
|
|
|
rtcp_receiver_.SetRemoteSSRC(ssrc);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2021-06-15 23:01:57 +02:00
|
|
|
void ModuleRtpRtcpImpl::SetLocalSsrc(uint32_t local_ssrc) {
|
|
|
|
|
rtcp_receiver_.set_local_media_ssrc(local_ssrc);
|
|
|
|
|
rtcp_sender_.SetSsrc(local_ssrc);
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-11 18:22:02 +02:00
|
|
|
RtpSendRates ModuleRtpRtcpImpl::GetSendRates() const {
|
|
|
|
|
return rtp_sender_->packet_sender.GetSendRates();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2011-10-13 15:19:55 +00:00
|
|
|
void ModuleRtpRtcpImpl::OnRequestSendReport() {
|
2013-08-15 23:38:54 +00:00
|
|
|
SendRTCP(kRtcpSr);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-26 18:48:46 +02:00
|
|
|
void ModuleRtpRtcpImpl::OnReceivedNack(
|
|
|
|
|
const std::vector<uint16_t>& nack_sequence_numbers) {
|
2017-03-20 03:52:39 -07:00
|
|
|
if (!rtp_sender_)
|
|
|
|
|
return;
|
|
|
|
|
|
2019-10-28 15:51:36 +01:00
|
|
|
if (!StorePackets() || nack_sequence_numbers.empty()) {
|
2012-02-08 23:41:49 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2013-12-16 14:40:36 +00:00
|
|
|
// Use RTT from RtcpRttStats class if provided.
|
2015-01-12 21:51:21 +00:00
|
|
|
int64_t rtt = rtt_ms();
|
2013-12-16 14:40:36 +00:00
|
|
|
if (rtt == 0) {
|
|
|
|
|
rtcp_receiver_.RTT(rtcp_receiver_.RemoteSSRC(), NULL, &rtt, NULL, NULL);
|
|
|
|
|
}
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_generator.OnReceivedNack(nack_sequence_numbers, rtt);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-06-08 00:24:21 -07:00
|
|
|
void ModuleRtpRtcpImpl::OnReceivedRtcpReportBlocks(
|
|
|
|
|
const ReportBlockList& report_blocks) {
|
2020-02-06 17:10:08 +01:00
|
|
|
if (rtp_sender_) {
|
2019-02-06 22:48:11 +01:00
|
|
|
uint32_t ssrc = SSRC();
|
2019-07-21 15:04:21 -04:00
|
|
|
absl::optional<uint32_t> rtx_ssrc;
|
2019-10-28 18:24:32 +01:00
|
|
|
if (rtp_sender_->packet_generator.RtxStatus() != kRtxOff) {
|
|
|
|
|
rtx_ssrc = rtp_sender_->packet_generator.RtxSsrc();
|
2019-07-21 15:04:21 -04:00
|
|
|
}
|
2019-02-06 22:48:11 +01:00
|
|
|
|
|
|
|
|
for (const RTCPReportBlock& report_block : report_blocks) {
|
|
|
|
|
if (ssrc == report_block.source_ssrc) {
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_generator.OnReceivedAckOnSsrc(
|
2019-07-21 15:04:21 -04:00
|
|
|
report_block.extended_highest_sequence_number);
|
|
|
|
|
} else if (rtx_ssrc && *rtx_ssrc == report_block.source_ssrc) {
|
2019-10-28 18:24:32 +01:00
|
|
|
rtp_sender_->packet_generator.OnReceivedAckOnRtxSsrc(
|
2019-07-21 15:04:21 -04:00
|
|
|
report_block.extended_highest_sequence_number);
|
2019-02-06 22:48:11 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-06-08 00:24:21 -07:00
|
|
|
}
|
|
|
|
|
|
2015-01-12 21:51:21 +00:00
|
|
|
void ModuleRtpRtcpImpl::set_rtt_ms(int64_t rtt_ms) {
|
2020-05-10 11:24:43 +02:00
|
|
|
{
|
2020-07-09 01:34:42 +02:00
|
|
|
MutexLock lock(&mutex_rtt_);
|
2020-05-10 11:24:43 +02:00
|
|
|
rtt_ms_ = rtt_ms;
|
|
|
|
|
}
|
2019-10-28 15:51:36 +01:00
|
|
|
if (rtp_sender_) {
|
2022-03-04 15:03:02 +01:00
|
|
|
rtp_sender_->packet_history.SetRtt(TimeDelta::Millis(rtt_ms));
|
2019-10-28 15:51:36 +01:00
|
|
|
}
|
2013-11-20 12:46:11 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-12 21:51:21 +00:00
|
|
|
int64_t ModuleRtpRtcpImpl::rtt_ms() const {
|
2020-07-09 01:34:42 +02:00
|
|
|
MutexLock lock(&mutex_rtt_);
|
2013-11-20 12:46:11 +00:00
|
|
|
return rtt_ms_;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-01 05:18:09 -08:00
|
|
|
void ModuleRtpRtcpImpl::SetVideoBitrateAllocation(
|
2018-04-23 12:32:22 +02:00
|
|
|
const VideoBitrateAllocation& bitrate) {
|
2016-12-01 05:18:09 -08:00
|
|
|
rtcp_sender_.SetVideoBitrateAllocation(bitrate);
|
|
|
|
|
}
|
2019-03-04 16:49:25 +01:00
|
|
|
|
|
|
|
|
RTPSender* ModuleRtpRtcpImpl::RtpSender() {
|
2019-10-28 18:24:32 +01:00
|
|
|
return rtp_sender_ ? &rtp_sender_->packet_generator : nullptr;
|
2019-03-04 16:49:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const RTPSender* ModuleRtpRtcpImpl::RtpSender() const {
|
2019-10-28 18:24:32 +01:00
|
|
|
return rtp_sender_ ? &rtp_sender_->packet_generator : nullptr;
|
2019-03-04 16:49:25 +01:00
|
|
|
}
|
|
|
|
|
|
2015-02-06 13:10:19 +00:00
|
|
|
} // namespace webrtc
|