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_sender.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2015-12-10 05:05:27 -08:00
|
|
|
#include <algorithm>
|
2018-09-13 15:36:20 +02:00
|
|
|
#include <limits>
|
2019-09-17 17:06:18 +02:00
|
|
|
#include <memory>
|
2018-03-22 15:17:27 -07:00
|
|
|
#include <string>
|
2015-04-21 20:24:50 +08:00
|
|
|
#include <utility>
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2018-11-02 10:54:56 +01:00
|
|
|
#include "absl/strings/match.h"
|
2018-12-21 09:23:38 -08:00
|
|
|
#include "api/array_view.h"
|
2019-08-07 12:24:53 +02:00
|
|
|
#include "api/rtc_event_log/rtc_event_log.h"
|
2017-10-03 16:11:34 +02:00
|
|
|
#include "logging/rtc_event_log/events/rtc_event_rtp_packet_outgoing.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/rtp_rtcp/include/rtp_cvo.h"
|
|
|
|
|
#include "modules/rtp_rtcp/source/byte_io.h"
|
2018-09-26 12:25:31 +02:00
|
|
|
#include "modules/rtp_rtcp/source/rtp_generic_frame_descriptor_extension.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/rtp_rtcp/source/rtp_header_extensions.h"
|
|
|
|
|
#include "modules/rtp_rtcp/source/rtp_packet_to_send.h"
|
|
|
|
|
#include "modules/rtp_rtcp/source/time_util.h"
|
|
|
|
|
#include "rtc_base/arraysize.h"
|
|
|
|
|
#include "rtc_base/checks.h"
|
2020-04-16 15:07:56 +02:00
|
|
|
#include "rtc_base/experiments/field_trial_parser.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/logging.h"
|
2017-11-22 10:42:26 +01:00
|
|
|
#include "rtc_base/numerics/safe_minmax.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/rate_limiter.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/time_utils.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2013-01-25 10:53:38 +00:00
|
|
|
|
2013-04-09 19:54:10 +00:00
|
|
|
namespace {
|
2016-08-03 18:27:40 +02:00
|
|
|
// Max in the RFC 3550 is 255 bytes, we limit it to be modulus 32 for SRTP.
|
|
|
|
|
constexpr size_t kMaxPaddingLength = 224;
|
2017-02-03 08:13:57 -08:00
|
|
|
constexpr size_t kMinAudioPaddingLength = 50;
|
2016-08-03 18:27:40 +02:00
|
|
|
constexpr size_t kRtpHeaderLength = 12;
|
2015-03-04 22:55:15 +00:00
|
|
|
|
2019-06-20 15:09:58 +02:00
|
|
|
// Min size needed to get payload padding from packet history.
|
|
|
|
|
constexpr int kMinPayloadPaddingBytes = 50;
|
|
|
|
|
|
2017-05-17 05:08:38 -07:00
|
|
|
template <typename Extension>
|
|
|
|
|
constexpr RtpExtensionSize CreateExtensionSize() {
|
|
|
|
|
return {Extension::kId, Extension::kValueSizeBytes};
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-21 09:23:38 -08:00
|
|
|
template <typename Extension>
|
|
|
|
|
constexpr RtpExtensionSize CreateMaxExtensionSize() {
|
|
|
|
|
return {Extension::kId, Extension::kMaxValueSizeBytes};
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-17 05:08:38 -07:00
|
|
|
// Size info for header extensions that might be used in padding or FEC packets.
|
2018-03-15 15:46:17 +01:00
|
|
|
constexpr RtpExtensionSize kFecOrPaddingExtensionSizes[] = {
|
2017-05-17 05:08:38 -07:00
|
|
|
CreateExtensionSize<AbsoluteSendTime>(),
|
|
|
|
|
CreateExtensionSize<TransmissionOffset>(),
|
|
|
|
|
CreateExtensionSize<TransportSequenceNumber>(),
|
|
|
|
|
CreateExtensionSize<PlayoutDelayLimits>(),
|
2018-12-21 09:23:38 -08:00
|
|
|
CreateMaxExtensionSize<RtpMid>(),
|
2019-12-09 09:37:42 -08:00
|
|
|
CreateExtensionSize<VideoTimingExtension>(),
|
2017-05-17 05:08:38 -07:00
|
|
|
};
|
|
|
|
|
|
2018-03-15 15:46:17 +01:00
|
|
|
// Size info for header extensions that might be used in video packets.
|
|
|
|
|
constexpr RtpExtensionSize kVideoExtensionSizes[] = {
|
|
|
|
|
CreateExtensionSize<AbsoluteSendTime>(),
|
2019-07-01 10:56:51 +02:00
|
|
|
CreateExtensionSize<AbsoluteCaptureTimeExtension>(),
|
2018-03-15 15:46:17 +01:00
|
|
|
CreateExtensionSize<TransmissionOffset>(),
|
|
|
|
|
CreateExtensionSize<TransportSequenceNumber>(),
|
|
|
|
|
CreateExtensionSize<PlayoutDelayLimits>(),
|
|
|
|
|
CreateExtensionSize<VideoOrientation>(),
|
|
|
|
|
CreateExtensionSize<VideoContentTypeExtension>(),
|
|
|
|
|
CreateExtensionSize<VideoTimingExtension>(),
|
2018-12-21 09:23:38 -08:00
|
|
|
CreateMaxExtensionSize<RtpStreamId>(),
|
|
|
|
|
CreateMaxExtensionSize<RepairedRtpStreamId>(),
|
|
|
|
|
CreateMaxExtensionSize<RtpMid>(),
|
2019-02-19 13:01:31 +01:00
|
|
|
{RtpGenericFrameDescriptorExtension00::kId,
|
|
|
|
|
RtpGenericFrameDescriptorExtension00::kMaxSizeBytes},
|
2018-03-15 15:46:17 +01:00
|
|
|
};
|
|
|
|
|
|
2020-05-07 18:18:32 +02:00
|
|
|
// Size info for header extensions that might be used in audio packets.
|
|
|
|
|
constexpr RtpExtensionSize kAudioExtensionSizes[] = {
|
|
|
|
|
CreateExtensionSize<AbsoluteSendTime>(),
|
|
|
|
|
CreateExtensionSize<AbsoluteCaptureTimeExtension>(),
|
|
|
|
|
CreateExtensionSize<AudioLevel>(),
|
|
|
|
|
CreateExtensionSize<InbandComfortNoiseExtension>(),
|
|
|
|
|
CreateExtensionSize<TransmissionOffset>(),
|
|
|
|
|
CreateExtensionSize<TransportSequenceNumber>(),
|
|
|
|
|
CreateMaxExtensionSize<RtpStreamId>(),
|
|
|
|
|
CreateMaxExtensionSize<RepairedRtpStreamId>(),
|
|
|
|
|
CreateMaxExtensionSize<RtpMid>(),
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Non-volatile extensions can be expected on all packets, if registered.
|
|
|
|
|
// Volatile ones, such as VideoContentTypeExtension which is only set on
|
|
|
|
|
// key-frames, are removed to simplify overhead calculations at the expense of
|
|
|
|
|
// some accuracy.
|
|
|
|
|
bool IsNonVolatile(RTPExtensionType type) {
|
|
|
|
|
switch (type) {
|
|
|
|
|
case kRtpExtensionTransmissionTimeOffset:
|
|
|
|
|
case kRtpExtensionAudioLevel:
|
2021-05-24 13:04:45 +02:00
|
|
|
case kRtpExtensionCsrcAudioLevel:
|
2020-05-07 18:18:32 +02:00
|
|
|
case kRtpExtensionAbsoluteSendTime:
|
|
|
|
|
case kRtpExtensionTransportSequenceNumber:
|
|
|
|
|
case kRtpExtensionTransportSequenceNumber02:
|
|
|
|
|
case kRtpExtensionRtpStreamId:
|
|
|
|
|
case kRtpExtensionMid:
|
|
|
|
|
case kRtpExtensionGenericFrameDescriptor00:
|
|
|
|
|
case kRtpExtensionGenericFrameDescriptor02:
|
|
|
|
|
return true;
|
|
|
|
|
case kRtpExtensionInbandComfortNoise:
|
|
|
|
|
case kRtpExtensionAbsoluteCaptureTime:
|
|
|
|
|
case kRtpExtensionVideoRotation:
|
|
|
|
|
case kRtpExtensionPlayoutDelay:
|
|
|
|
|
case kRtpExtensionVideoContentType:
|
2020-10-05 13:51:47 +02:00
|
|
|
case kRtpExtensionVideoLayersAllocation:
|
2020-05-07 18:18:32 +02:00
|
|
|
case kRtpExtensionVideoTiming:
|
2020-05-13 15:04:35 +02:00
|
|
|
case kRtpExtensionRepairedRtpStreamId:
|
2020-05-07 18:18:32 +02:00
|
|
|
case kRtpExtensionColorSpace:
|
2021-03-17 17:01:31 +01:00
|
|
|
case kRtpExtensionVideoFrameTrackingId:
|
2020-05-07 18:18:32 +02:00
|
|
|
return false;
|
|
|
|
|
case kRtpExtensionNone:
|
|
|
|
|
case kRtpExtensionNumberOfExtensions:
|
|
|
|
|
RTC_NOTREACHED();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2020-11-08 00:49:37 +01:00
|
|
|
RTC_CHECK_NOTREACHED();
|
2020-05-07 18:18:32 +02:00
|
|
|
}
|
|
|
|
|
|
2019-07-12 17:33:46 +00:00
|
|
|
bool HasBweExtension(const RtpHeaderExtensionMap& extensions_map) {
|
|
|
|
|
return extensions_map.IsRegistered(kRtpExtensionTransportSequenceNumber) ||
|
|
|
|
|
extensions_map.IsRegistered(kRtpExtensionTransportSequenceNumber02) ||
|
|
|
|
|
extensions_map.IsRegistered(kRtpExtensionAbsoluteSendTime) ||
|
|
|
|
|
extensions_map.IsRegistered(kRtpExtensionTransmissionTimeOffset);
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-16 15:07:56 +02:00
|
|
|
double GetMaxPaddingSizeFactor(const WebRtcKeyValueConfig* field_trials) {
|
2020-04-22 12:19:26 +02:00
|
|
|
// Too low factor means RTX payload padding is rarely used and ineffective.
|
|
|
|
|
// Too high means we risk interrupting regular media packets.
|
|
|
|
|
// In practice, 3x seems to yield reasonable results.
|
|
|
|
|
constexpr double kDefaultFactor = 3.0;
|
2020-04-16 15:07:56 +02:00
|
|
|
if (!field_trials) {
|
|
|
|
|
return kDefaultFactor;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
FieldTrialOptional<double> factor("factor", kDefaultFactor);
|
|
|
|
|
ParseFieldTrial({&factor}, field_trials->Lookup("WebRTC-LimitPaddingSize"));
|
|
|
|
|
RTC_CHECK_GE(factor.Value(), 0.0);
|
|
|
|
|
return factor.Value();
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-09 19:54:10 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
2020-06-03 22:55:33 +02:00
|
|
|
RTPSender::RTPSender(const RtpRtcpInterface::Configuration& config,
|
2019-10-25 15:24:15 +02:00
|
|
|
RtpPacketHistory* packet_history,
|
2021-08-04 14:45:32 +02:00
|
|
|
RtpPacketSender* packet_sender,
|
|
|
|
|
PacketSequencer* packet_sequencer)
|
2019-07-04 10:38:43 +02:00
|
|
|
: clock_(config.clock),
|
|
|
|
|
random_(clock_->TimeInMicroseconds()),
|
|
|
|
|
audio_configured_(config.audio),
|
2019-10-15 14:29:11 +02:00
|
|
|
ssrc_(config.local_media_ssrc),
|
|
|
|
|
rtx_ssrc_(config.rtx_send_ssrc),
|
2020-03-05 10:14:04 +01:00
|
|
|
flexfec_ssrc_(config.fec_generator ? config.fec_generator->FecSsrc()
|
|
|
|
|
: absl::nullopt),
|
2020-04-16 15:07:56 +02:00
|
|
|
max_padding_size_factor_(GetMaxPaddingSizeFactor(config.field_trials)),
|
2019-10-28 18:24:32 +01:00
|
|
|
packet_history_(packet_history),
|
|
|
|
|
paced_sender_(packet_sender),
|
2019-10-17 16:56:22 +02:00
|
|
|
sending_media_(true), // Default to sending media.
|
2019-07-04 10:38:43 +02:00
|
|
|
max_packet_size_(IP_PACKET_SIZE - 28), // Default is IP-v4/UDP.
|
|
|
|
|
rtp_header_extension_map_(config.extmap_allow_mixed),
|
|
|
|
|
// RTP variables
|
2021-08-04 14:45:32 +02:00
|
|
|
sequencer_(packet_sequencer),
|
2020-03-10 14:12:48 +01:00
|
|
|
always_send_mid_and_rid_(config.always_send_mid_and_rid),
|
2019-07-21 15:04:21 -04:00
|
|
|
ssrc_has_acked_(false),
|
|
|
|
|
rtx_ssrc_has_acked_(false),
|
2019-07-04 10:38:43 +02:00
|
|
|
csrcs_(),
|
|
|
|
|
rtx_(kRtxOff),
|
2019-07-12 17:33:46 +00:00
|
|
|
supports_bwe_extension_(false),
|
2019-10-25 15:24:15 +02:00
|
|
|
retransmission_rate_limiter_(config.retransmission_rate_limiter) {
|
2021-02-05 19:30:16 +01:00
|
|
|
UpdateHeaderSizes();
|
2019-07-04 10:38:43 +02:00
|
|
|
// This random initialization is not intended to be cryptographic strong.
|
|
|
|
|
timestamp_offset_ = random_.Rand<uint32_t>();
|
2019-10-25 15:24:15 +02:00
|
|
|
|
2019-08-26 19:00:05 +02:00
|
|
|
RTC_DCHECK(paced_sender_);
|
2019-10-25 15:24:15 +02:00
|
|
|
RTC_DCHECK(packet_history_);
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-01-19 15:56:10 +00:00
|
|
|
RTPSender::~RTPSender() {
|
2016-02-02 08:31:45 -08:00
|
|
|
// TODO(tommi): Use a thread checker to ensure the object is created and
|
|
|
|
|
// deleted on the same thread. At the moment this isn't possible due to
|
|
|
|
|
// voe::ChannelOwner in voice engine. To reproduce, run:
|
|
|
|
|
// voe_auto_test --automated --gtest_filter=*MixManyChannelsForStressOpus
|
|
|
|
|
|
|
|
|
|
// TODO(tommi,holmer): We don't grab locks in the dtor before accessing member
|
|
|
|
|
// variables but we grab them in all other methods. (what's the design?)
|
|
|
|
|
// Start documenting what thread we're on in what method so that it's easier
|
|
|
|
|
// to understand performance attributes and possibly remove locks.
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-17 05:08:38 -07:00
|
|
|
rtc::ArrayView<const RtpExtensionSize> RTPSender::FecExtensionSizes() {
|
2018-03-15 15:46:17 +01:00
|
|
|
return rtc::MakeArrayView(kFecOrPaddingExtensionSizes,
|
|
|
|
|
arraysize(kFecOrPaddingExtensionSizes));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rtc::ArrayView<const RtpExtensionSize> RTPSender::VideoExtensionSizes() {
|
|
|
|
|
return rtc::MakeArrayView(kVideoExtensionSizes,
|
|
|
|
|
arraysize(kVideoExtensionSizes));
|
2017-05-17 05:08:38 -07:00
|
|
|
}
|
|
|
|
|
|
2020-05-07 18:18:32 +02:00
|
|
|
rtc::ArrayView<const RtpExtensionSize> RTPSender::AudioExtensionSizes() {
|
|
|
|
|
return rtc::MakeArrayView(kAudioExtensionSizes,
|
|
|
|
|
arraysize(kAudioExtensionSizes));
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-29 11:22:05 +01:00
|
|
|
void RTPSender::SetExtmapAllowMixed(bool extmap_allow_mixed) {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2018-10-29 11:22:05 +01:00
|
|
|
rtp_header_extension_map_.SetExtmapAllowMixed(extmap_allow_mixed);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-14 17:32:21 +02:00
|
|
|
bool RTPSender::RegisterRtpHeaderExtension(absl::string_view uri, int id) {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2019-07-12 17:33:46 +00:00
|
|
|
bool registered = rtp_header_extension_map_.RegisterByUri(id, uri);
|
|
|
|
|
supports_bwe_extension_ = HasBweExtension(rtp_header_extension_map_);
|
2020-05-07 18:18:32 +02:00
|
|
|
UpdateHeaderSizes();
|
2019-07-12 17:33:46 +00:00
|
|
|
return registered;
|
2018-09-14 18:29:32 +02:00
|
|
|
}
|
|
|
|
|
|
2017-02-03 08:13:57 -08:00
|
|
|
bool RTPSender::IsRtpHeaderExtensionRegistered(RTPExtensionType type) const {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2015-03-04 22:55:15 +00:00
|
|
|
return rtp_header_extension_map_.IsRegistered(type);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-19 13:49:55 +00:00
|
|
|
int32_t RTPSender::DeregisterRtpHeaderExtension(RTPExtensionType type) {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2020-05-07 18:18:32 +02:00
|
|
|
rtp_header_extension_map_.Deregister(type);
|
2019-07-12 17:33:46 +00:00
|
|
|
supports_bwe_extension_ = HasBweExtension(rtp_header_extension_map_);
|
2020-05-07 18:18:32 +02:00
|
|
|
UpdateHeaderSizes();
|
|
|
|
|
return 0;
|
2011-12-16 14:31:37 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-14 17:32:21 +02:00
|
|
|
void RTPSender::DeregisterRtpHeaderExtension(absl::string_view uri) {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2019-10-14 17:32:21 +02:00
|
|
|
rtp_header_extension_map_.Deregister(uri);
|
|
|
|
|
supports_bwe_extension_ = HasBweExtension(rtp_header_extension_map_);
|
2020-05-07 18:18:32 +02:00
|
|
|
UpdateHeaderSizes();
|
2019-10-14 17:32:21 +02:00
|
|
|
}
|
|
|
|
|
|
2017-01-10 08:58:32 -08:00
|
|
|
void RTPSender::SetMaxRtpPacketSize(size_t max_packet_size) {
|
2017-08-09 17:22:01 -07:00
|
|
|
RTC_DCHECK_GE(max_packet_size, 100);
|
|
|
|
|
RTC_DCHECK_LE(max_packet_size, IP_PACKET_SIZE);
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2017-01-10 08:58:32 -08:00
|
|
|
max_packet_size_ = max_packet_size;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2017-01-10 08:58:32 -08:00
|
|
|
size_t RTPSender::MaxRtpPacketSize() const {
|
|
|
|
|
return max_packet_size_;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-13 14:15:15 +00:00
|
|
|
void RTPSender::SetRtxStatus(int mode) {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2013-03-15 23:21:52 +00:00
|
|
|
rtx_ = mode;
|
2014-06-05 08:25:29 +00:00
|
|
|
}
|
|
|
|
|
|
2015-01-13 14:15:15 +00:00
|
|
|
int RTPSender::RtxStatus() const {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2015-01-13 14:15:15 +00:00
|
|
|
return rtx_;
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-21 20:24:50 +08:00
|
|
|
void RTPSender::SetRtxPayloadType(int payload_type,
|
|
|
|
|
int associated_payload_type) {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK_LE(payload_type, 127);
|
|
|
|
|
RTC_DCHECK_LE(associated_payload_type, 127);
|
2015-04-21 20:24:50 +08:00
|
|
|
if (payload_type < 0) {
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_ERROR) << "Invalid RTX payload type: " << payload_type << ".";
|
2015-04-21 20:24:50 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rtx_payload_type_map_[associated_payload_type] = payload_type;
|
2015-04-13 17:48:08 +02:00
|
|
|
}
|
|
|
|
|
|
2018-03-14 12:39:24 +01:00
|
|
|
int32_t RTPSender::ReSendPacket(uint16_t packet_id) {
|
|
|
|
|
// Try to find packet in RTP packet history. Also verify RTT here, so that we
|
|
|
|
|
// don't retransmit too often.
|
2018-06-14 12:59:38 +02:00
|
|
|
absl::optional<RtpPacketHistory::PacketState> stored_packet =
|
2019-10-25 15:24:15 +02:00
|
|
|
packet_history_->GetPacketState(packet_id);
|
2019-05-08 10:15:05 -07:00
|
|
|
if (!stored_packet || stored_packet->pending_transmission) {
|
|
|
|
|
// Packet not found or already queued for retransmission, ignore.
|
2012-04-23 12:43:05 +00:00
|
|
|
return 0;
|
2012-01-16 11:06:31 +00:00
|
|
|
}
|
2018-03-09 12:27:24 +00:00
|
|
|
|
2019-02-20 13:14:34 +01:00
|
|
|
const int32_t packet_size = static_cast<int32_t>(stored_packet->packet_size);
|
2019-07-05 16:53:43 +02:00
|
|
|
const bool rtx = (RtxStatus() & kRtxRetransmitted) > 0;
|
2018-03-09 09:52:59 +01:00
|
|
|
|
2018-03-14 12:39:24 +01:00
|
|
|
std::unique_ptr<RtpPacketToSend> packet =
|
2019-10-25 15:24:15 +02:00
|
|
|
packet_history_->GetPacketAndMarkAsPending(
|
2019-08-26 19:00:05 +02:00
|
|
|
packet_id, [&](const RtpPacketToSend& stored_packet) {
|
|
|
|
|
// Check if we're overusing retransmission bitrate.
|
|
|
|
|
// TODO(sprang): Add histograms for nack success or failure
|
|
|
|
|
// reasons.
|
|
|
|
|
std::unique_ptr<RtpPacketToSend> retransmit_packet;
|
|
|
|
|
if (retransmission_rate_limiter_ &&
|
|
|
|
|
!retransmission_rate_limiter_->TryUseRate(packet_size)) {
|
|
|
|
|
return retransmit_packet;
|
|
|
|
|
}
|
|
|
|
|
if (rtx) {
|
|
|
|
|
retransmit_packet = BuildRtxPacket(stored_packet);
|
|
|
|
|
} else {
|
|
|
|
|
retransmit_packet =
|
2019-09-17 17:06:18 +02:00
|
|
|
std::make_unique<RtpPacketToSend>(stored_packet);
|
2019-08-26 19:00:05 +02:00
|
|
|
}
|
|
|
|
|
if (retransmit_packet) {
|
|
|
|
|
retransmit_packet->set_retransmitted_sequence_number(
|
|
|
|
|
stored_packet.SequenceNumber());
|
|
|
|
|
}
|
|
|
|
|
return retransmit_packet;
|
|
|
|
|
});
|
2018-03-14 12:39:24 +01:00
|
|
|
if (!packet) {
|
2015-08-03 04:38:41 -07:00
|
|
|
return -1;
|
2019-08-26 19:00:05 +02:00
|
|
|
}
|
2020-02-06 16:35:46 +01:00
|
|
|
packet->set_packet_type(RtpPacketMediaType::kRetransmission);
|
2020-09-29 11:53:39 +02:00
|
|
|
packet->set_fec_protect_packet(false);
|
2019-10-02 14:57:46 +02:00
|
|
|
std::vector<std::unique_ptr<RtpPacketToSend>> packets;
|
|
|
|
|
packets.emplace_back(std::move(packet));
|
|
|
|
|
paced_sender_->EnqueuePackets(std::move(packets));
|
2018-03-14 12:39:24 +01:00
|
|
|
|
2016-08-03 18:27:40 +02:00
|
|
|
return packet_size;
|
2012-01-10 14:09:18 +00:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2019-07-21 15:04:21 -04:00
|
|
|
void RTPSender::OnReceivedAckOnSsrc(int64_t extended_highest_sequence_number) {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2020-05-07 18:18:32 +02:00
|
|
|
bool update_required = !ssrc_has_acked_;
|
2019-07-21 15:04:21 -04:00
|
|
|
ssrc_has_acked_ = true;
|
2020-05-07 18:18:32 +02:00
|
|
|
if (update_required) {
|
|
|
|
|
UpdateHeaderSizes();
|
|
|
|
|
}
|
2019-07-21 15:04:21 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RTPSender::OnReceivedAckOnRtxSsrc(
|
|
|
|
|
int64_t extended_highest_sequence_number) {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2021-02-05 19:30:16 +01:00
|
|
|
bool update_required = !rtx_ssrc_has_acked_;
|
2019-07-21 15:04:21 -04:00
|
|
|
rtx_ssrc_has_acked_ = true;
|
2021-02-05 19:30:16 +01:00
|
|
|
if (update_required) {
|
|
|
|
|
UpdateHeaderSizes();
|
|
|
|
|
}
|
2019-07-21 15:04:21 -04:00
|
|
|
}
|
|
|
|
|
|
2016-08-26 18:48:46 +02:00
|
|
|
void RTPSender::OnReceivedNack(
|
|
|
|
|
const std::vector<uint16_t>& nack_sequence_numbers,
|
|
|
|
|
int64_t avg_rtt) {
|
2019-10-25 15:24:15 +02:00
|
|
|
packet_history_->SetRtt(5 + avg_rtt);
|
2016-07-13 09:11:28 -07:00
|
|
|
for (uint16_t seq_no : nack_sequence_numbers) {
|
2018-03-14 12:39:24 +01:00
|
|
|
const int32_t bytes_sent = ReSendPacket(seq_no);
|
2016-07-13 09:11:28 -07:00
|
|
|
if (bytes_sent < 0) {
|
2012-01-10 14:09:18 +00:00
|
|
|
// Failed to send one Sequence number. Give up the rest in this nack.
|
2017-11-09 11:09:25 +01:00
|
|
|
RTC_LOG(LS_WARNING) << "Failed resending RTP packet " << seq_no
|
|
|
|
|
<< ", Discard rest of packets.";
|
2012-01-10 14:09:18 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2019-07-12 17:33:46 +00:00
|
|
|
bool RTPSender::SupportsPadding() const {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2019-07-12 17:33:46 +00:00
|
|
|
return sending_media_ && supports_bwe_extension_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RTPSender::SupportsRtxPayloadPadding() const {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2019-07-12 17:33:46 +00:00
|
|
|
return sending_media_ && supports_bwe_extension_ &&
|
|
|
|
|
(rtx_ & kRtxRedundantPayloads);
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-25 15:24:15 +02:00
|
|
|
std::vector<std::unique_ptr<RtpPacketToSend>> RTPSender::GeneratePadding(
|
|
|
|
|
size_t target_size_bytes,
|
2021-08-04 14:45:32 +02:00
|
|
|
bool media_has_been_sent,
|
|
|
|
|
bool can_send_padding_on_media_ssrc) {
|
2019-06-26 15:49:27 +02:00
|
|
|
// This method does not actually send packets, it just generates
|
|
|
|
|
// them and puts them in the pacer queue. Since this should incur
|
|
|
|
|
// low overhead, keep the lock for the scope of the method in order
|
|
|
|
|
// to make the code more readable.
|
|
|
|
|
|
2019-07-05 16:53:43 +02:00
|
|
|
std::vector<std::unique_ptr<RtpPacketToSend>> padding_packets;
|
2019-06-26 15:49:27 +02:00
|
|
|
size_t bytes_left = target_size_bytes;
|
2019-07-15 20:33:40 +02:00
|
|
|
if (SupportsRtxPayloadPadding()) {
|
2019-07-12 17:35:56 +00:00
|
|
|
while (bytes_left >= kMinPayloadPaddingBytes) {
|
2019-06-26 15:49:27 +02:00
|
|
|
std::unique_ptr<RtpPacketToSend> packet =
|
2019-10-25 15:24:15 +02:00
|
|
|
packet_history_->GetPayloadPaddingPacket(
|
2019-06-26 15:49:27 +02:00
|
|
|
[&](const RtpPacketToSend& packet)
|
|
|
|
|
-> std::unique_ptr<RtpPacketToSend> {
|
2021-07-28 23:57:33 +02:00
|
|
|
// Limit overshoot, generate <= `max_padding_size_factor_` *
|
2020-04-16 15:07:56 +02:00
|
|
|
// target_size_bytes.
|
|
|
|
|
const size_t max_overshoot_bytes = static_cast<size_t>(
|
|
|
|
|
((max_padding_size_factor_ - 1.0) * target_size_bytes) +
|
|
|
|
|
0.5);
|
|
|
|
|
if (packet.payload_size() + kRtxHeaderSize >
|
|
|
|
|
max_overshoot_bytes + bytes_left) {
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
2019-06-26 15:49:27 +02:00
|
|
|
return BuildRtxPacket(packet);
|
|
|
|
|
});
|
|
|
|
|
if (!packet) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bytes_left -= std::min(bytes_left, packet->payload_size());
|
2020-02-06 16:35:46 +01:00
|
|
|
packet->set_packet_type(RtpPacketMediaType::kPadding);
|
2019-07-05 16:53:43 +02:00
|
|
|
padding_packets.push_back(std::move(packet));
|
2019-06-26 15:49:27 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2019-07-15 20:33:40 +02:00
|
|
|
if (!sending_media_) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-26 15:49:27 +02:00
|
|
|
size_t padding_bytes_in_packet;
|
2020-05-07 18:18:32 +02:00
|
|
|
const size_t max_payload_size =
|
2020-05-27 17:21:03 +02:00
|
|
|
max_packet_size_ - max_padding_fec_packet_header_;
|
2019-06-26 15:49:27 +02:00
|
|
|
if (audio_configured_) {
|
|
|
|
|
// Allow smaller padding packets for audio.
|
|
|
|
|
padding_bytes_in_packet = rtc::SafeClamp<size_t>(
|
|
|
|
|
bytes_left, kMinAudioPaddingLength,
|
|
|
|
|
rtc::SafeMin(max_payload_size, kMaxPaddingLength));
|
|
|
|
|
} else {
|
|
|
|
|
// Always send full padding packets. This is accounted for by the
|
|
|
|
|
// RtpPacketSender, which will make sure we don't send too much padding even
|
|
|
|
|
// if a single packet is larger than requested.
|
|
|
|
|
// We do this to avoid frequently sending small packets on higher bitrates.
|
|
|
|
|
padding_bytes_in_packet = rtc::SafeMin(max_payload_size, kMaxPaddingLength);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
while (bytes_left > 0) {
|
|
|
|
|
auto padding_packet =
|
2019-09-17 17:06:18 +02:00
|
|
|
std::make_unique<RtpPacketToSend>(&rtp_header_extension_map_);
|
2020-02-06 16:35:46 +01:00
|
|
|
padding_packet->set_packet_type(RtpPacketMediaType::kPadding);
|
2019-06-26 15:49:27 +02:00
|
|
|
padding_packet->SetMarker(false);
|
|
|
|
|
if (rtx_ == kRtxOff) {
|
2021-08-04 14:45:32 +02:00
|
|
|
bool can_send_padding = sequencer_
|
|
|
|
|
? sequencer_->CanSendPaddingOnMediaSsrc()
|
|
|
|
|
: can_send_padding_on_media_ssrc;
|
|
|
|
|
if (!can_send_padding) {
|
2019-06-26 15:49:27 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2021-08-03 20:24:13 +02:00
|
|
|
padding_packet->SetSsrc(ssrc_);
|
2021-08-04 14:45:32 +02:00
|
|
|
if (sequencer_) {
|
|
|
|
|
sequencer_->Sequence(*padding_packet);
|
|
|
|
|
}
|
2019-06-26 15:49:27 +02:00
|
|
|
} else {
|
|
|
|
|
// Without abs-send-time or transport sequence number a media packet
|
|
|
|
|
// must be sent before padding so that the timestamps used for
|
|
|
|
|
// estimation are correct.
|
2019-10-25 15:24:15 +02:00
|
|
|
if (!media_has_been_sent &&
|
2019-06-26 15:49:27 +02:00
|
|
|
!(rtp_header_extension_map_.IsRegistered(AbsoluteSendTime::kId) ||
|
|
|
|
|
rtp_header_extension_map_.IsRegistered(
|
|
|
|
|
TransportSequenceNumber::kId))) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
2021-02-22 13:34:31 +01:00
|
|
|
|
2019-10-15 14:29:11 +02:00
|
|
|
RTC_DCHECK(rtx_ssrc_);
|
|
|
|
|
padding_packet->SetSsrc(*rtx_ssrc_);
|
2019-06-26 15:49:27 +02:00
|
|
|
padding_packet->SetPayloadType(rtx_payload_type_map_.begin()->second);
|
2021-08-04 14:45:32 +02:00
|
|
|
if (sequencer_) {
|
|
|
|
|
sequencer_->Sequence(*padding_packet);
|
|
|
|
|
}
|
2019-06-26 15:49:27 +02:00
|
|
|
}
|
|
|
|
|
|
2019-07-05 16:53:43 +02:00
|
|
|
if (rtp_header_extension_map_.IsRegistered(TransportSequenceNumber::kId)) {
|
|
|
|
|
padding_packet->ReserveExtension<TransportSequenceNumber>();
|
|
|
|
|
}
|
2019-07-15 20:33:40 +02:00
|
|
|
if (rtp_header_extension_map_.IsRegistered(TransmissionOffset::kId)) {
|
|
|
|
|
padding_packet->ReserveExtension<TransmissionOffset>();
|
|
|
|
|
}
|
|
|
|
|
if (rtp_header_extension_map_.IsRegistered(AbsoluteSendTime::kId)) {
|
|
|
|
|
padding_packet->ReserveExtension<AbsoluteSendTime>();
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-26 15:49:27 +02:00
|
|
|
padding_packet->SetPadding(padding_bytes_in_packet);
|
|
|
|
|
bytes_left -= std::min(bytes_left, padding_bytes_in_packet);
|
2019-07-05 16:53:43 +02:00
|
|
|
padding_packets.push_back(std::move(padding_packet));
|
2019-06-26 15:49:27 +02:00
|
|
|
}
|
2019-07-05 16:53:43 +02:00
|
|
|
|
|
|
|
|
return padding_packets;
|
2019-06-26 15:49:27 +02:00
|
|
|
}
|
|
|
|
|
|
2019-08-27 18:16:26 +02:00
|
|
|
bool RTPSender::SendToNetwork(std::unique_ptr<RtpPacketToSend> packet) {
|
2016-08-03 18:27:40 +02:00
|
|
|
RTC_DCHECK(packet);
|
2013-05-16 11:10:31 +00:00
|
|
|
int64_t now_ms = clock_->TimeInMilliseconds();
|
|
|
|
|
|
2019-08-26 19:00:05 +02:00
|
|
|
auto packet_type = packet->packet_type();
|
|
|
|
|
RTC_CHECK(packet_type) << "Packet type must be set before sending.";
|
2019-07-05 16:53:43 +02:00
|
|
|
|
2019-08-26 19:00:05 +02:00
|
|
|
if (packet->capture_time_ms() <= 0) {
|
|
|
|
|
packet->set_capture_time_ms(now_ms);
|
2012-07-03 13:21:22 +00:00
|
|
|
}
|
2016-01-27 12:58:51 +01:00
|
|
|
|
2019-10-02 14:57:46 +02:00
|
|
|
std::vector<std::unique_ptr<RtpPacketToSend>> packets;
|
|
|
|
|
packets.emplace_back(std::move(packet));
|
|
|
|
|
paced_sender_->EnqueuePackets(std::move(packets));
|
2018-11-27 10:48:27 +01:00
|
|
|
|
2019-08-26 19:00:05 +02:00
|
|
|
return true;
|
2011-12-22 12:52:41 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-02 14:57:46 +02:00
|
|
|
void RTPSender::EnqueuePackets(
|
|
|
|
|
std::vector<std::unique_ptr<RtpPacketToSend>> packets) {
|
|
|
|
|
RTC_DCHECK(!packets.empty());
|
|
|
|
|
int64_t now_ms = clock_->TimeInMilliseconds();
|
|
|
|
|
for (auto& packet : packets) {
|
|
|
|
|
RTC_DCHECK(packet);
|
|
|
|
|
RTC_CHECK(packet->packet_type().has_value())
|
|
|
|
|
<< "Packet type must be set before sending.";
|
|
|
|
|
if (packet->capture_time_ms() <= 0) {
|
|
|
|
|
packet->set_capture_time_ms(now_ms);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
paced_sender_->EnqueuePackets(std::move(packets));
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-07 18:18:32 +02:00
|
|
|
size_t RTPSender::FecOrPaddingPacketMaxRtpHeaderLength() const {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2020-05-07 18:18:32 +02:00
|
|
|
return max_padding_fec_packet_header_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t RTPSender::ExpectedPerPacketOverhead() const {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2020-05-07 18:18:32 +02:00
|
|
|
return max_media_packet_header_;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-02 19:15:59 +02:00
|
|
|
std::unique_ptr<RtpPacketToSend> RTPSender::AllocatePacket() const {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2018-10-12 12:50:43 +02:00
|
|
|
// TODO(danilchap): Find better motivator and value for extra capacity.
|
|
|
|
|
// RtpPacketizer might slightly miscalulate needed size,
|
|
|
|
|
// SRTP may benefit from extra space in the buffer and do encryption in place
|
|
|
|
|
// saving reallocation.
|
|
|
|
|
// While sending slightly oversized packet increase chance of dropped packet,
|
|
|
|
|
// it is better than crash on drop packet without trying to send it.
|
|
|
|
|
static constexpr int kExtraCapacity = 16;
|
2019-09-17 17:06:18 +02:00
|
|
|
auto packet = std::make_unique<RtpPacketToSend>(
|
2018-10-12 12:50:43 +02:00
|
|
|
&rtp_header_extension_map_, max_packet_size_ + kExtraCapacity);
|
2019-10-15 14:29:11 +02:00
|
|
|
packet->SetSsrc(ssrc_);
|
2016-09-02 19:15:59 +02:00
|
|
|
packet->SetCsrcs(csrcs_);
|
|
|
|
|
// Reserve extensions, if registered, RtpSender set in SendToNetwork.
|
|
|
|
|
packet->ReserveExtension<AbsoluteSendTime>();
|
|
|
|
|
packet->ReserveExtension<TransmissionOffset>();
|
|
|
|
|
packet->ReserveExtension<TransportSequenceNumber>();
|
2019-01-31 08:56:26 +01:00
|
|
|
|
2019-07-21 15:04:21 -04:00
|
|
|
// BUNDLE requires that the receiver "bind" the received SSRC to the values
|
|
|
|
|
// in the MID and/or (R)RID header extensions if present. Therefore, the
|
|
|
|
|
// sender can reduce overhead by omitting these header extensions once it
|
|
|
|
|
// knows that the receiver has "bound" the SSRC.
|
2020-03-10 14:12:48 +01:00
|
|
|
// This optimization can be configured by setting
|
2021-07-28 23:57:33 +02:00
|
|
|
// `always_send_mid_and_rid_` appropriately.
|
2019-07-21 15:04:21 -04:00
|
|
|
//
|
|
|
|
|
// The algorithm here is fairly simple: Always attach a MID and/or RID (if
|
|
|
|
|
// configured) to the outgoing packets until an RTCP receiver report comes
|
|
|
|
|
// back for this SSRC. That feedback indicates the receiver must have
|
|
|
|
|
// received a packet with the SSRC and header extension(s), so the sender
|
|
|
|
|
// then stops attaching the MID and RID.
|
2020-03-10 14:12:48 +01:00
|
|
|
if (always_send_mid_and_rid_ || !ssrc_has_acked_) {
|
2019-07-21 15:04:21 -04:00
|
|
|
// These are no-ops if the corresponding header extension is not registered.
|
|
|
|
|
if (!mid_.empty()) {
|
|
|
|
|
packet->SetExtension<RtpMid>(mid_);
|
|
|
|
|
}
|
|
|
|
|
if (!rid_.empty()) {
|
|
|
|
|
packet->SetExtension<RtpStreamId>(rid_);
|
|
|
|
|
}
|
2018-12-21 09:23:38 -08:00
|
|
|
}
|
2016-09-02 19:15:59 +02:00
|
|
|
return packet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RTPSender::AssignSequenceNumber(RtpPacketToSend* packet) {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2021-08-04 14:45:32 +02:00
|
|
|
RTC_DCHECK(sequencer_);
|
2016-09-02 19:15:59 +02:00
|
|
|
if (!sending_media_)
|
|
|
|
|
return false;
|
2021-08-04 14:45:32 +02:00
|
|
|
sequencer_->Sequence(*packet);
|
2021-08-03 20:24:13 +02:00
|
|
|
return true;
|
2021-02-17 15:19:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RTPSender::AssignSequenceNumbersAndStoreLastPacketState(
|
|
|
|
|
rtc::ArrayView<std::unique_ptr<RtpPacketToSend>> packets) {
|
|
|
|
|
RTC_DCHECK(!packets.empty());
|
|
|
|
|
MutexLock lock(&send_mutex_);
|
2021-08-04 14:45:32 +02:00
|
|
|
RTC_DCHECK(sequencer_);
|
2021-02-17 15:19:06 +01:00
|
|
|
if (!sending_media_)
|
|
|
|
|
return false;
|
|
|
|
|
for (auto& packet : packets) {
|
2021-08-04 14:45:32 +02:00
|
|
|
sequencer_->Sequence(*packet);
|
2021-02-17 15:19:06 +01:00
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-19 13:49:55 +00:00
|
|
|
void RTPSender::SetSendingMediaStatus(bool enabled) {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2013-01-25 10:53:38 +00:00
|
|
|
sending_media_ = enabled;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2012-11-07 17:01:04 +00:00
|
|
|
bool RTPSender::SendingMedia() const {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2013-01-25 10:53:38 +00:00
|
|
|
return sending_media_;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2019-12-11 16:47:09 +01:00
|
|
|
bool RTPSender::IsAudioConfigured() const {
|
|
|
|
|
return audio_configured_;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-18 02:01:49 -07:00
|
|
|
void RTPSender::SetTimestampOffset(uint32_t timestamp) {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2016-08-18 02:01:49 -07:00
|
|
|
timestamp_offset_ = timestamp;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-18 02:01:49 -07:00
|
|
|
uint32_t RTPSender::TimestampOffset() const {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2016-08-18 02:01:49 -07:00
|
|
|
return timestamp_offset_;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2018-12-21 09:23:38 -08:00
|
|
|
void RTPSender::SetRid(const std::string& rid) {
|
|
|
|
|
// RID is used in simulcast scenario when multiple layers share the same mid.
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2018-12-21 09:23:38 -08:00
|
|
|
RTC_DCHECK_LE(rid.length(), RtpStreamId::kMaxValueSizeBytes);
|
|
|
|
|
rid_ = rid;
|
2020-05-07 18:18:32 +02:00
|
|
|
UpdateHeaderSizes();
|
2018-12-21 09:23:38 -08:00
|
|
|
}
|
|
|
|
|
|
2018-03-22 15:17:27 -07:00
|
|
|
void RTPSender::SetMid(const std::string& mid) {
|
|
|
|
|
// This is configured via the API.
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2019-07-21 15:04:21 -04:00
|
|
|
RTC_DCHECK_LE(mid.length(), RtpMid::kMaxValueSizeBytes);
|
2018-04-06 11:09:46 -07:00
|
|
|
mid_ = mid;
|
2020-05-07 18:18:32 +02:00
|
|
|
UpdateHeaderSizes();
|
2018-03-22 15:17:27 -07:00
|
|
|
}
|
|
|
|
|
|
2014-11-24 08:25:50 +00:00
|
|
|
void RTPSender::SetCsrcs(const std::vector<uint32_t>& csrcs) {
|
2017-09-04 07:23:56 -07:00
|
|
|
RTC_DCHECK_LE(csrcs.size(), kRtpCsrcSize);
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2014-11-24 08:25:50 +00:00
|
|
|
csrcs_ = csrcs;
|
2020-05-07 18:18:32 +02:00
|
|
|
UpdateHeaderSizes();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
void RTPSender::SetSequenceNumber(uint16_t seq) {
|
2019-07-24 14:15:51 +02:00
|
|
|
bool updated_sequence_number = false;
|
|
|
|
|
{
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2021-08-04 14:45:32 +02:00
|
|
|
RTC_DCHECK(sequencer_);
|
|
|
|
|
if (sequencer_->media_sequence_number() != seq) {
|
2019-07-24 14:15:51 +02:00
|
|
|
updated_sequence_number = true;
|
|
|
|
|
}
|
2021-08-04 14:45:32 +02:00
|
|
|
sequencer_->set_media_sequence_number(seq);
|
2019-07-24 14:15:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (updated_sequence_number) {
|
|
|
|
|
// Sequence number series has been reset to a new value, clear RTP packet
|
|
|
|
|
// history, since any packets there may conflict with new ones.
|
2019-10-25 15:24:15 +02:00
|
|
|
packet_history_->Clear();
|
2019-07-24 14:15:51 +02:00
|
|
|
}
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2013-04-08 11:08:41 +00:00
|
|
|
uint16_t RTPSender::SequenceNumber() const {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2021-08-04 14:45:32 +02:00
|
|
|
RTC_DCHECK(sequencer_);
|
|
|
|
|
return sequencer_->media_sequence_number();
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2019-02-11 11:30:03 +01:00
|
|
|
static void CopyHeaderAndExtensionsToRtxPacket(const RtpPacketToSend& packet,
|
|
|
|
|
RtpPacketToSend* rtx_packet) {
|
2018-12-21 09:23:38 -08:00
|
|
|
// Set the relevant fixed packet headers. The following are not set:
|
|
|
|
|
// * Payload type - it is replaced in rtx packets.
|
|
|
|
|
// * Sequence number - RTX has a separate sequence numbering.
|
|
|
|
|
// * SSRC - RTX stream has its own SSRC.
|
|
|
|
|
rtx_packet->SetMarker(packet.Marker());
|
|
|
|
|
rtx_packet->SetTimestamp(packet.Timestamp());
|
|
|
|
|
|
|
|
|
|
// Set the variable fields in the packet header:
|
|
|
|
|
// * CSRCs - must be set before header extensions.
|
|
|
|
|
// * Header extensions - replace Rid header with RepairedRid header.
|
|
|
|
|
const std::vector<uint32_t> csrcs = packet.Csrcs();
|
|
|
|
|
rtx_packet->SetCsrcs(csrcs);
|
2019-07-21 15:04:21 -04:00
|
|
|
for (int extension_num = kRtpExtensionNone + 1;
|
|
|
|
|
extension_num < kRtpExtensionNumberOfExtensions; ++extension_num) {
|
|
|
|
|
auto extension = static_cast<RTPExtensionType>(extension_num);
|
|
|
|
|
|
|
|
|
|
// Stream ID header extensions (MID, RSID) are sent per-SSRC. Since RTX
|
|
|
|
|
// operates on a different SSRC, the presence and values of these header
|
|
|
|
|
// extensions should be determined separately and not blindly copied.
|
|
|
|
|
if (extension == kRtpExtensionMid ||
|
|
|
|
|
extension == kRtpExtensionRtpStreamId) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2018-12-21 09:23:38 -08:00
|
|
|
|
|
|
|
|
// Empty extensions should be supported, so not checking |source.empty()|.
|
2019-07-21 15:04:21 -04:00
|
|
|
if (!packet.HasExtension(extension)) {
|
2018-12-21 09:23:38 -08:00
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-21 15:04:21 -04:00
|
|
|
rtc::ArrayView<const uint8_t> source = packet.FindExtension(extension);
|
2018-12-21 09:23:38 -08:00
|
|
|
|
|
|
|
|
rtc::ArrayView<uint8_t> destination =
|
2019-07-21 15:04:21 -04:00
|
|
|
rtx_packet->AllocateExtension(extension, source.size());
|
2018-12-21 09:23:38 -08:00
|
|
|
|
|
|
|
|
// Could happen if any:
|
|
|
|
|
// 1. Extension has 0 length.
|
|
|
|
|
// 2. Extension is not registered in destination.
|
|
|
|
|
// 3. Allocating extension in destination failed.
|
|
|
|
|
if (destination.empty() || source.size() != destination.size()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::memcpy(destination.begin(), source.begin(), destination.size());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<RtpPacketToSend> RTPSender::BuildRtxPacket(
|
|
|
|
|
const RtpPacketToSend& packet) {
|
2019-02-11 11:30:03 +01:00
|
|
|
std::unique_ptr<RtpPacketToSend> rtx_packet;
|
2018-12-21 09:23:38 -08:00
|
|
|
|
2016-08-03 18:27:40 +02:00
|
|
|
// Add original RTP header.
|
|
|
|
|
{
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2016-08-03 18:27:40 +02:00
|
|
|
if (!sending_media_)
|
|
|
|
|
return nullptr;
|
2013-03-15 23:21:52 +00:00
|
|
|
|
2019-10-15 14:29:11 +02:00
|
|
|
RTC_DCHECK(rtx_ssrc_);
|
Reland of Delete class SSRCDatabase, and its global ssrc registry. (patchset #1 id:1 of https://codereview.webrtc.org/2700413002/ )
Reason for revert:
Intend to fix perf problem and reland.
Original issue's description:
> Revert of Delete class SSRCDatabase, and its global ssrc registry. (patchset #20 id:370001 of https://codereview.webrtc.org/2644303002/ )
>
> Reason for revert:
> Breaks webrtc_perf_tests reliably:
> https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus5%29/builds/1780
> https://build.chromium.org/p/client.webrtc.perf/builders/Android32%20Tests%20%28L%20Nexus4%29/builds/178
>
> We're actively working on getting a quick version of webrtc_perf_tests up on the trybots again to prevent breakages like this: https://bugs.chromium.org/p/webrtc/issues/detail?id=7101
>
> Original issue's description:
> > Delete class SSRCDatabase, and its global ssrc registry,
> > and the method RTPSender::GenerateNewSSRC.
> >
> > It's now mandatory for higher layers to call SetSSRC, RTPSender
> > no longer allocates any ssrc by default.
> >
> > BUG=webrtc:4306,webrtc:6887
> >
> > Review-Url: https://codereview.webrtc.org/2644303002
> > Cr-Commit-Position: refs/heads/master@{#16670}
> > Committed: https://chromium.googlesource.com/external/webrtc/+/b78d4d13835f628e722a57abae2bf06ba3655921
>
> TBR=solenberg@webrtc.org,stefan@webrtc.org,danilchap@webrtc.org,ivoc@webrtc.org,nisse@webrtc.org
> NOTRY=True
> BUG=webrtc:4306,webrtc:6887
>
> Review-Url: https://codereview.webrtc.org/2700413002
> Cr-Commit-Position: refs/heads/master@{#16693}
> Committed: https://chromium.googlesource.com/external/webrtc/+/b5848ecbf5f7b310108546ec6b858fe93452f58e
TBR=solenberg@webrtc.org,stefan@webrtc.org,danilchap@webrtc.org,ivoc@webrtc.org,kjellander@webrtc.org,kjellander@google.com
# Not skipping CQ checks because original CL landed more than 1 days ago.
BUG=webrtc:4306,webrtc:6887
Review-Url: https://codereview.webrtc.org/2702203002
Cr-Commit-Position: refs/heads/master@{#16737}
2017-02-21 03:40:24 -08:00
|
|
|
|
Remove RED/RTX workaround from sender/receiver and VideoEngine2.
In older Chrome versions, the associated payload type in the RTX header
of retransmitted packets was always set to be the original media payload type,
regardless of the actual payload type of the packet. This meant that packets
encapsulated with RED headers had incorrect payload type information in the
RTX header. Due to an assumption in the receiver, this incorrect payload type
information would effectively be undone, leading to a working system.
Albeit working, this behaviour was undesired, and thus removed. In the interim,
several workarounds were introduced to not destroy interop between old and
new Chrome versions:
(1) https://codereview.webrtc.org/1649493004
- If no payload type mapping existed for RED over RTX, the payload type
of the underlying media would be used.
- If RED had been negotiated, received RTX packets would always be
assumed to contain RED.
(2) https://codereview.webrtc.org/1964473002
- If RED was removed from the remote description answer, it would be
disabled in the local receiver as well.
(3) https://codereview.webrtc.org/2033763002
- If RED was negotiated in the SDP, it would always be used, regardless
if ULPFEC was negotiated and used, or not.
Since the Chrome versions that exhibited the original bug now are very old,
this CL removes the workarounds from (1) and (2). In particular, after this
change, we will have the following behaviour:
- We assume that a payload type mapping for RED over RTX always is set.
If this is not the case, the RTX packet is not sent.
- The associated payload type of received RTX packets will always be obeyed.
- The (non)-existence of RED in the remote description does not affect the
local receiver.
The workaround in (3) still needs to exist, in order to interop with receivers
that did not have the workarounds in (1) and (2) removed. The change in (3)
can be removed in a couple of Chrome versions.
TESTED=Using AppRTC between patched Chrome (connected to ethernet) and standard Chrome M54 (connected to lossy internal Google WiFi), with and without FEC turned off using AppRTC flag. Also using "Munge SDP" sample on patched Chrome over loopback interface, with 100ms delay and 5% packet loss simulated using tc.
BUG=webrtc:6650
Review-Url: https://codereview.webrtc.org/2469093003
Cr-Commit-Position: refs/heads/master@{#15038}
2016-11-11 03:28:30 -08:00
|
|
|
// Replace payload type.
|
|
|
|
|
auto kv = rtx_payload_type_map_.find(packet.PayloadType());
|
2016-08-03 18:27:40 +02:00
|
|
|
if (kv == rtx_payload_type_map_.end())
|
Remove RED/RTX workaround from sender/receiver and VideoEngine2.
In older Chrome versions, the associated payload type in the RTX header
of retransmitted packets was always set to be the original media payload type,
regardless of the actual payload type of the packet. This meant that packets
encapsulated with RED headers had incorrect payload type information in the
RTX header. Due to an assumption in the receiver, this incorrect payload type
information would effectively be undone, leading to a working system.
Albeit working, this behaviour was undesired, and thus removed. In the interim,
several workarounds were introduced to not destroy interop between old and
new Chrome versions:
(1) https://codereview.webrtc.org/1649493004
- If no payload type mapping existed for RED over RTX, the payload type
of the underlying media would be used.
- If RED had been negotiated, received RTX packets would always be
assumed to contain RED.
(2) https://codereview.webrtc.org/1964473002
- If RED was removed from the remote description answer, it would be
disabled in the local receiver as well.
(3) https://codereview.webrtc.org/2033763002
- If RED was negotiated in the SDP, it would always be used, regardless
if ULPFEC was negotiated and used, or not.
Since the Chrome versions that exhibited the original bug now are very old,
this CL removes the workarounds from (1) and (2). In particular, after this
change, we will have the following behaviour:
- We assume that a payload type mapping for RED over RTX always is set.
If this is not the case, the RTX packet is not sent.
- The associated payload type of received RTX packets will always be obeyed.
- The (non)-existence of RED in the remote description does not affect the
local receiver.
The workaround in (3) still needs to exist, in order to interop with receivers
that did not have the workarounds in (1) and (2) removed. The change in (3)
can be removed in a couple of Chrome versions.
TESTED=Using AppRTC between patched Chrome (connected to ethernet) and standard Chrome M54 (connected to lossy internal Google WiFi), with and without FEC turned off using AppRTC flag. Also using "Munge SDP" sample on patched Chrome over loopback interface, with 100ms delay and 5% packet loss simulated using tc.
BUG=webrtc:6650
Review-Url: https://codereview.webrtc.org/2469093003
Cr-Commit-Position: refs/heads/master@{#15038}
2016-11-11 03:28:30 -08:00
|
|
|
return nullptr;
|
2019-02-11 11:30:03 +01:00
|
|
|
|
2019-09-17 17:06:18 +02:00
|
|
|
rtx_packet = std::make_unique<RtpPacketToSend>(&rtp_header_extension_map_,
|
|
|
|
|
max_packet_size_);
|
2019-02-11 11:30:03 +01:00
|
|
|
|
Remove RED/RTX workaround from sender/receiver and VideoEngine2.
In older Chrome versions, the associated payload type in the RTX header
of retransmitted packets was always set to be the original media payload type,
regardless of the actual payload type of the packet. This meant that packets
encapsulated with RED headers had incorrect payload type information in the
RTX header. Due to an assumption in the receiver, this incorrect payload type
information would effectively be undone, leading to a working system.
Albeit working, this behaviour was undesired, and thus removed. In the interim,
several workarounds were introduced to not destroy interop between old and
new Chrome versions:
(1) https://codereview.webrtc.org/1649493004
- If no payload type mapping existed for RED over RTX, the payload type
of the underlying media would be used.
- If RED had been negotiated, received RTX packets would always be
assumed to contain RED.
(2) https://codereview.webrtc.org/1964473002
- If RED was removed from the remote description answer, it would be
disabled in the local receiver as well.
(3) https://codereview.webrtc.org/2033763002
- If RED was negotiated in the SDP, it would always be used, regardless
if ULPFEC was negotiated and used, or not.
Since the Chrome versions that exhibited the original bug now are very old,
this CL removes the workarounds from (1) and (2). In particular, after this
change, we will have the following behaviour:
- We assume that a payload type mapping for RED over RTX always is set.
If this is not the case, the RTX packet is not sent.
- The associated payload type of received RTX packets will always be obeyed.
- The (non)-existence of RED in the remote description does not affect the
local receiver.
The workaround in (3) still needs to exist, in order to interop with receivers
that did not have the workarounds in (1) and (2) removed. The change in (3)
can be removed in a couple of Chrome versions.
TESTED=Using AppRTC between patched Chrome (connected to ethernet) and standard Chrome M54 (connected to lossy internal Google WiFi), with and without FEC turned off using AppRTC flag. Also using "Munge SDP" sample on patched Chrome over loopback interface, with 100ms delay and 5% packet loss simulated using tc.
BUG=webrtc:6650
Review-Url: https://codereview.webrtc.org/2469093003
Cr-Commit-Position: refs/heads/master@{#15038}
2016-11-11 03:28:30 -08:00
|
|
|
rtx_packet->SetPayloadType(kv->second);
|
2013-03-15 23:21:52 +00:00
|
|
|
|
2016-08-03 18:27:40 +02:00
|
|
|
// Replace SSRC.
|
2019-10-15 14:29:11 +02:00
|
|
|
rtx_packet->SetSsrc(*rtx_ssrc_);
|
2018-03-22 15:17:27 -07:00
|
|
|
|
2021-02-22 13:34:31 +01:00
|
|
|
// Replace sequence number.
|
2021-08-04 14:45:32 +02:00
|
|
|
if (sequencer_) {
|
|
|
|
|
sequencer_->Sequence(*rtx_packet);
|
|
|
|
|
}
|
2021-02-22 13:34:31 +01:00
|
|
|
|
2019-02-11 11:30:03 +01:00
|
|
|
CopyHeaderAndExtensionsToRtxPacket(packet, rtx_packet.get());
|
|
|
|
|
|
2019-07-21 15:04:21 -04:00
|
|
|
// RTX packets are sent on an SSRC different from the main media, so the
|
|
|
|
|
// decision to attach MID and/or RRID header extensions is completely
|
|
|
|
|
// separate from that of the main media SSRC.
|
|
|
|
|
//
|
|
|
|
|
// Note that RTX packets must used the RepairedRtpStreamId (RRID) header
|
|
|
|
|
// extension instead of the RtpStreamId (RID) header extension even though
|
|
|
|
|
// the payload is identical.
|
2020-03-10 14:12:48 +01:00
|
|
|
if (always_send_mid_and_rid_ || !rtx_ssrc_has_acked_) {
|
2019-07-21 15:04:21 -04:00
|
|
|
// These are no-ops if the corresponding header extension is not
|
|
|
|
|
// registered.
|
|
|
|
|
if (!mid_.empty()) {
|
|
|
|
|
rtx_packet->SetExtension<RtpMid>(mid_);
|
|
|
|
|
}
|
|
|
|
|
if (!rid_.empty()) {
|
|
|
|
|
rtx_packet->SetExtension<RepairedRtpStreamId>(rid_);
|
|
|
|
|
}
|
2018-12-21 09:23:38 -08:00
|
|
|
}
|
2016-08-03 18:27:40 +02:00
|
|
|
}
|
2019-02-11 11:30:03 +01:00
|
|
|
RTC_DCHECK(rtx_packet);
|
2016-08-03 18:27:40 +02:00
|
|
|
|
|
|
|
|
uint8_t* rtx_payload =
|
|
|
|
|
rtx_packet->AllocatePayload(packet.payload_size() + kRtxHeaderSize);
|
2019-02-11 11:30:03 +01:00
|
|
|
if (rtx_payload == nullptr)
|
|
|
|
|
return nullptr;
|
|
|
|
|
|
2013-03-15 23:21:52 +00:00
|
|
|
// Add OSN (original sequence number).
|
2016-08-03 18:27:40 +02:00
|
|
|
ByteWriter<uint16_t>::WriteBigEndian(rtx_payload, packet.SequenceNumber());
|
2013-03-15 23:21:52 +00:00
|
|
|
|
|
|
|
|
// Add original payload data.
|
2016-11-21 01:35:29 -08:00
|
|
|
auto payload = packet.payload();
|
|
|
|
|
memcpy(rtx_payload + kRtxHeaderSize, payload.data(), payload.size());
|
2016-08-03 18:27:40 +02:00
|
|
|
|
2021-01-27 18:05:04 +01:00
|
|
|
// Add original additional data.
|
2021-01-25 17:02:57 +01:00
|
|
|
rtx_packet->set_additional_data(packet.additional_data());
|
2018-02-22 14:18:06 +01:00
|
|
|
|
2019-07-24 10:47:20 +02:00
|
|
|
// Copy capture time so e.g. TransmissionOffset is correctly set.
|
|
|
|
|
rtx_packet->set_capture_time_ms(packet.capture_time_ms());
|
|
|
|
|
|
2016-08-03 18:27:40 +02:00
|
|
|
return rtx_packet;
|
2013-03-15 23:21:52 +00:00
|
|
|
}
|
|
|
|
|
|
2014-07-07 13:06:48 +00:00
|
|
|
void RTPSender::SetRtpState(const RtpState& rtp_state) {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2021-02-22 13:34:31 +01:00
|
|
|
|
2016-08-18 02:01:49 -07:00
|
|
|
timestamp_offset_ = rtp_state.start_timestamp;
|
2021-08-04 14:45:32 +02:00
|
|
|
if (sequencer_) {
|
|
|
|
|
sequencer_->SetRtpState(rtp_state);
|
|
|
|
|
}
|
2019-07-21 15:04:21 -04:00
|
|
|
ssrc_has_acked_ = rtp_state.ssrc_has_acked;
|
2020-05-07 18:18:32 +02:00
|
|
|
UpdateHeaderSizes();
|
2014-07-07 13:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RtpState RTPSender::GetRtpState() const {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2014-07-07 13:06:48 +00:00
|
|
|
|
|
|
|
|
RtpState state;
|
2016-08-18 02:01:49 -07:00
|
|
|
state.start_timestamp = timestamp_offset_;
|
2019-07-21 15:04:21 -04:00
|
|
|
state.ssrc_has_acked = ssrc_has_acked_;
|
2021-08-04 14:45:32 +02:00
|
|
|
if (sequencer_) {
|
2021-08-06 13:10:11 +02:00
|
|
|
sequencer_->PopulateRtpState(state);
|
2021-08-04 14:45:32 +02:00
|
|
|
}
|
2014-07-07 13:06:48 +00:00
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RTPSender::SetRtxRtpState(const RtpState& rtp_state) {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2021-08-04 14:45:32 +02:00
|
|
|
if (sequencer_) {
|
|
|
|
|
sequencer_->set_rtx_sequence_number(rtp_state.sequence_number);
|
|
|
|
|
}
|
2019-07-21 15:04:21 -04:00
|
|
|
rtx_ssrc_has_acked_ = rtp_state.ssrc_has_acked;
|
2014-07-07 13:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RtpState RTPSender::GetRtxRtpState() const {
|
2020-07-07 11:44:28 +02:00
|
|
|
MutexLock lock(&send_mutex_);
|
2014-07-07 13:06:48 +00:00
|
|
|
|
|
|
|
|
RtpState state;
|
2021-08-04 14:45:32 +02:00
|
|
|
if (sequencer_) {
|
|
|
|
|
state.sequence_number = sequencer_->rtx_sequence_number();
|
|
|
|
|
}
|
2016-08-18 02:01:49 -07:00
|
|
|
state.start_timestamp = timestamp_offset_;
|
2019-07-21 15:04:21 -04:00
|
|
|
state.ssrc_has_acked = rtx_ssrc_has_acked_;
|
2014-07-07 13:06:48 +00:00
|
|
|
|
|
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-07 18:18:32 +02:00
|
|
|
void RTPSender::UpdateHeaderSizes() {
|
|
|
|
|
const size_t rtp_header_length =
|
|
|
|
|
kRtpHeaderLength + sizeof(uint32_t) * csrcs_.size();
|
|
|
|
|
|
|
|
|
|
max_padding_fec_packet_header_ =
|
|
|
|
|
rtp_header_length + RtpHeaderExtensionSize(kFecOrPaddingExtensionSizes,
|
|
|
|
|
rtp_header_extension_map_);
|
|
|
|
|
|
|
|
|
|
// RtpStreamId and Mid are treated specially in that we check if they
|
2021-02-05 19:30:16 +01:00
|
|
|
// currently are being sent. RepairedRtpStreamId is ignored because it is sent
|
|
|
|
|
// instead of RtpStreamId on rtx packets and require the same size.
|
|
|
|
|
const bool send_mid_rid_on_rtx =
|
|
|
|
|
rtx_ssrc_.has_value() && !rtx_ssrc_has_acked_;
|
|
|
|
|
const bool send_mid_rid =
|
|
|
|
|
always_send_mid_and_rid_ || !ssrc_has_acked_ || send_mid_rid_on_rtx;
|
2020-05-07 18:18:32 +02:00
|
|
|
std::vector<RtpExtensionSize> non_volatile_extensions;
|
|
|
|
|
for (auto& extension :
|
|
|
|
|
audio_configured_ ? AudioExtensionSizes() : VideoExtensionSizes()) {
|
|
|
|
|
if (IsNonVolatile(extension.type)) {
|
|
|
|
|
switch (extension.type) {
|
|
|
|
|
case RTPExtensionType::kRtpExtensionMid:
|
|
|
|
|
if (send_mid_rid && !mid_.empty()) {
|
|
|
|
|
non_volatile_extensions.push_back(extension);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case RTPExtensionType::kRtpExtensionRtpStreamId:
|
|
|
|
|
if (send_mid_rid && !rid_.empty()) {
|
|
|
|
|
non_volatile_extensions.push_back(extension);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
non_volatile_extensions.push_back(extension);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
max_media_packet_header_ =
|
|
|
|
|
rtp_header_length + RtpHeaderExtensionSize(non_volatile_extensions,
|
|
|
|
|
rtp_header_extension_map_);
|
2021-02-05 19:30:16 +01:00
|
|
|
// Reserve extra bytes if packet might be resent in an rtx packet.
|
|
|
|
|
if (rtx_ssrc_.has_value()) {
|
|
|
|
|
max_media_packet_header_ += kRtxHeaderSize;
|
|
|
|
|
}
|
2020-05-07 18:18:32 +02:00
|
|
|
}
|
2012-11-07 17:01:04 +00:00
|
|
|
} // namespace webrtc
|