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"
|
|
|
|
|
#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;
|
|
|
|
|
constexpr uint16_t kMaxInitRtpSeqNumber = 32767; // 2^15 -1.
|
|
|
|
|
constexpr uint32_t kTimestampTicksPerMs = 90;
|
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>(),
|
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},
|
|
|
|
|
{RtpGenericFrameDescriptorExtension01::kId,
|
|
|
|
|
RtpGenericFrameDescriptorExtension01::kMaxSizeBytes},
|
2018-03-15 15:46:17 +01: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);
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-09 19:54:10 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
2019-10-25 15:24:15 +02:00
|
|
|
RTPSender::RTPSender(const RtpRtcp::Configuration& config,
|
|
|
|
|
RtpPacketHistory* packet_history,
|
|
|
|
|
RtpPacketSender* packet_sender)
|
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),
|
2019-07-04 10:38:43 +02:00
|
|
|
flexfec_ssrc_(config.flexfec_sender
|
|
|
|
|
? absl::make_optional(config.flexfec_sender->ssrc())
|
|
|
|
|
: absl::nullopt),
|
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.
|
|
|
|
|
last_payload_type_(-1),
|
|
|
|
|
rtp_header_extension_map_(config.extmap_allow_mixed),
|
|
|
|
|
// RTP variables
|
|
|
|
|
sequence_number_forced_(false),
|
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
|
|
|
last_rtp_timestamp_(0),
|
|
|
|
|
capture_time_ms_(0),
|
|
|
|
|
last_timestamp_time_ms_(0),
|
|
|
|
|
last_packet_marker_bit_(false),
|
|
|
|
|
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) {
|
2019-07-04 10:38:43 +02:00
|
|
|
// This random initialization is not intended to be cryptographic strong.
|
|
|
|
|
timestamp_offset_ = random_.Rand<uint32_t>();
|
|
|
|
|
// Random start, 16 bits. Can't be 0.
|
|
|
|
|
sequence_number_rtx_ = random_.Rand(1, kMaxInitRtpSeqNumber);
|
|
|
|
|
sequence_number_ = random_.Rand(1, kMaxInitRtpSeqNumber);
|
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
|
|
|
}
|
|
|
|
|
|
2018-10-29 11:22:05 +01:00
|
|
|
void RTPSender::SetExtmapAllowMixed(bool extmap_allow_mixed) {
|
|
|
|
|
rtc::CritScope lock(&send_critsect_);
|
|
|
|
|
rtp_header_extension_map_.SetExtmapAllowMixed(extmap_allow_mixed);
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-19 13:49:55 +00:00
|
|
|
int32_t RTPSender::RegisterRtpHeaderExtension(RTPExtensionType type,
|
|
|
|
|
uint8_t id) {
|
2016-02-02 08:31:45 -08:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
2019-07-12 17:33:46 +00:00
|
|
|
bool registered = rtp_header_extension_map_.RegisterByType(id, type);
|
|
|
|
|
supports_bwe_extension_ = HasBweExtension(rtp_header_extension_map_);
|
|
|
|
|
return registered ? 0 : -1;
|
2011-12-16 14:31:37 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-14 17:32:21 +02:00
|
|
|
bool RTPSender::RegisterRtpHeaderExtension(absl::string_view uri, int id) {
|
2018-09-14 18:29:32 +02:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
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_);
|
|
|
|
|
return registered;
|
2018-09-14 18:29:32 +02:00
|
|
|
}
|
|
|
|
|
|
2017-02-03 08:13:57 -08:00
|
|
|
bool RTPSender::IsRtpHeaderExtensionRegistered(RTPExtensionType type) const {
|
2016-02-02 08:31:45 -08:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
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) {
|
2016-02-02 08:31:45 -08:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
2019-07-12 17:33:46 +00:00
|
|
|
int32_t deregistered = rtp_header_extension_map_.Deregister(type);
|
|
|
|
|
supports_bwe_extension_ = HasBweExtension(rtp_header_extension_map_);
|
|
|
|
|
return deregistered;
|
2011-12-16 14:31:37 +00:00
|
|
|
}
|
|
|
|
|
|
2019-10-14 17:32:21 +02:00
|
|
|
void RTPSender::DeregisterRtpHeaderExtension(absl::string_view uri) {
|
|
|
|
|
rtc::CritScope lock(&send_critsect_);
|
|
|
|
|
rtp_header_extension_map_.Deregister(uri);
|
|
|
|
|
supports_bwe_extension_ = HasBweExtension(rtp_header_extension_map_);
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2016-02-02 08:31:45 -08:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
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) {
|
2016-02-02 08:31:45 -08:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
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 {
|
2016-02-02 08:31:45 -08:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
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) {
|
2016-02-02 08:31:45 -08:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
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
|
|
|
}
|
|
|
|
|
packet->set_packet_type(RtpPacketToSend::Type::kRetransmission);
|
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) {
|
|
|
|
|
rtc::CritScope lock(&send_critsect_);
|
|
|
|
|
ssrc_has_acked_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RTPSender::OnReceivedAckOnRtxSsrc(
|
|
|
|
|
int64_t extended_highest_sequence_number) {
|
|
|
|
|
rtc::CritScope lock(&send_critsect_);
|
|
|
|
|
rtx_ssrc_has_acked_ = true;
|
|
|
|
|
}
|
|
|
|
|
|
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 {
|
|
|
|
|
rtc::CritScope lock(&send_critsect_);
|
|
|
|
|
return sending_media_ && supports_bwe_extension_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool RTPSender::SupportsRtxPayloadPadding() const {
|
|
|
|
|
rtc::CritScope lock(&send_critsect_);
|
|
|
|
|
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,
|
|
|
|
|
bool media_has_been_sent) {
|
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> {
|
|
|
|
|
return BuildRtxPacket(packet);
|
|
|
|
|
});
|
|
|
|
|
if (!packet) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bytes_left -= std::min(bytes_left, packet->payload_size());
|
|
|
|
|
packet->set_packet_type(RtpPacketToSend::Type::kPadding);
|
2019-07-05 16:53:43 +02:00
|
|
|
padding_packets.push_back(std::move(packet));
|
2019-06-26 15:49:27 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-07-15 20:33:40 +02:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
|
|
|
|
if (!sending_media_) {
|
|
|
|
|
return {};
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-26 15:49:27 +02:00
|
|
|
size_t padding_bytes_in_packet;
|
|
|
|
|
const size_t max_payload_size = max_packet_size_ - RtpHeaderLength();
|
|
|
|
|
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_);
|
2019-06-26 15:49:27 +02:00
|
|
|
padding_packet->set_packet_type(RtpPacketToSend::Type::kPadding);
|
|
|
|
|
padding_packet->SetMarker(false);
|
|
|
|
|
padding_packet->SetTimestamp(last_rtp_timestamp_);
|
|
|
|
|
padding_packet->set_capture_time_ms(capture_time_ms_);
|
|
|
|
|
if (rtx_ == kRtxOff) {
|
|
|
|
|
if (last_payload_type_ == -1) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
// Without RTX we can't send padding in the middle of frames.
|
|
|
|
|
// For audio marker bits doesn't mark the end of a frame and frames
|
|
|
|
|
// are usually a single packet, so for now we don't apply this rule
|
|
|
|
|
// for audio.
|
|
|
|
|
if (!audio_configured_ && !last_packet_marker_bit_) {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-15 14:29:11 +02:00
|
|
|
padding_packet->SetSsrc(ssrc_);
|
2019-06-26 15:49:27 +02:00
|
|
|
padding_packet->SetPayloadType(last_payload_type_);
|
|
|
|
|
padding_packet->SetSequenceNumber(sequence_number_++);
|
|
|
|
|
} 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;
|
|
|
|
|
}
|
|
|
|
|
// Only change the timestamp of padding packets sent over RTX.
|
|
|
|
|
// Padding only packets over RTP has to be sent as part of a media
|
|
|
|
|
// frame (and therefore the same timestamp).
|
|
|
|
|
int64_t now_ms = clock_->TimeInMilliseconds();
|
|
|
|
|
if (last_timestamp_time_ms_ > 0) {
|
|
|
|
|
padding_packet->SetTimestamp(padding_packet->Timestamp() +
|
|
|
|
|
(now_ms - last_timestamp_time_ms_) *
|
|
|
|
|
kTimestampTicksPerMs);
|
|
|
|
|
padding_packet->set_capture_time_ms(padding_packet->capture_time_ms() +
|
|
|
|
|
(now_ms - last_timestamp_time_ms_));
|
|
|
|
|
}
|
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->SetSequenceNumber(sequence_number_rtx_++);
|
|
|
|
|
padding_packet->SetPayloadType(rtx_payload_type_map_.begin()->second);
|
|
|
|
|
}
|
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-08 00:24:21 -07:00
|
|
|
size_t RTPSender::RtpHeaderLength() const {
|
2016-02-02 08:31:45 -08:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
2015-03-04 22:55:15 +00:00
|
|
|
size_t rtp_header_length = kRtpHeaderLength;
|
2014-11-24 08:25:50 +00:00
|
|
|
rtp_header_length += sizeof(uint32_t) * csrcs_.size();
|
2018-10-03 10:15:36 +02:00
|
|
|
rtp_header_length += RtpHeaderExtensionSize(kFecOrPaddingExtensionSizes,
|
|
|
|
|
rtp_header_extension_map_);
|
2013-01-25 10:53:38 +00:00
|
|
|
return rtp_header_length;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2015-04-14 21:28:08 +02:00
|
|
|
uint16_t RTPSender::AllocateSequenceNumber(uint16_t packets_to_send) {
|
2016-02-02 08:31:45 -08:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
2015-04-14 21:28:08 +02:00
|
|
|
uint16_t first_allocated_sequence_number = sequence_number_;
|
|
|
|
|
sequence_number_ += packets_to_send;
|
|
|
|
|
return first_allocated_sequence_number;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-09-02 19:15:59 +02:00
|
|
|
std::unique_ptr<RtpPacketToSend> RTPSender::AllocatePacket() const {
|
|
|
|
|
rtc::CritScope lock(&send_critsect_);
|
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.
|
|
|
|
|
//
|
|
|
|
|
// 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.
|
|
|
|
|
if (!ssrc_has_acked_) {
|
|
|
|
|
// 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) {
|
|
|
|
|
rtc::CritScope lock(&send_critsect_);
|
|
|
|
|
if (!sending_media_)
|
|
|
|
|
return false;
|
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
|
|
|
RTC_DCHECK(packet->Ssrc() == ssrc_);
|
2016-09-02 19:15:59 +02:00
|
|
|
packet->SetSequenceNumber(sequence_number_++);
|
|
|
|
|
|
|
|
|
|
// Remember marker bit to determine if padding can be inserted with
|
|
|
|
|
// sequence number following |packet|.
|
|
|
|
|
last_packet_marker_bit_ = packet->Marker();
|
2018-03-22 10:13:07 +01:00
|
|
|
// Remember payload type to use in the padding packet if rtx is disabled.
|
|
|
|
|
last_payload_type_ = packet->PayloadType();
|
2016-09-02 19:15:59 +02:00
|
|
|
// Save timestamps to generate timestamp field and extensions for the padding.
|
|
|
|
|
last_rtp_timestamp_ = packet->Timestamp();
|
|
|
|
|
last_timestamp_time_ms_ = clock_->TimeInMilliseconds();
|
|
|
|
|
capture_time_ms_ = packet->capture_time_ms();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2015-08-03 04:38:41 -07:00
|
|
|
|
2014-12-19 13:49:55 +00:00
|
|
|
void RTPSender::SetSendingMediaStatus(bool enabled) {
|
2016-02-02 08:31:45 -08:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
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 {
|
2016-02-02 08:31:45 -08:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
2013-01-25 10:53:38 +00:00
|
|
|
return sending_media_;
|
2011-07-07 08:21:25 +00:00
|
|
|
}
|
|
|
|
|
|
2016-08-18 02:01:49 -07:00
|
|
|
void RTPSender::SetTimestampOffset(uint32_t timestamp) {
|
2016-02-02 08:31:45 -08:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
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 {
|
2016-02-02 08:31:45 -08:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
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.
|
|
|
|
|
rtc::CritScope lock(&send_critsect_);
|
|
|
|
|
RTC_DCHECK_LE(rid.length(), RtpStreamId::kMaxValueSizeBytes);
|
|
|
|
|
rid_ = rid;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-22 15:17:27 -07:00
|
|
|
void RTPSender::SetMid(const std::string& mid) {
|
|
|
|
|
// This is configured via the API.
|
|
|
|
|
rtc::CritScope lock(&send_critsect_);
|
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;
|
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);
|
2016-02-02 08:31:45 -08:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
2014-11-24 08:25:50 +00:00
|
|
|
csrcs_ = csrcs;
|
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;
|
|
|
|
|
{
|
|
|
|
|
rtc::CritScope lock(&send_critsect_);
|
|
|
|
|
sequence_number_forced_ = true;
|
|
|
|
|
if (sequence_number_ != seq) {
|
|
|
|
|
updated_sequence_number = true;
|
|
|
|
|
}
|
|
|
|
|
sequence_number_ = seq;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 {
|
2016-02-02 08:31:45 -08:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
2013-01-25 10:53:38 +00:00
|
|
|
return 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.
|
|
|
|
|
{
|
|
|
|
|
rtc::CritScope lock(&send_critsect_);
|
|
|
|
|
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 sequence number.
|
|
|
|
|
rtx_packet->SetSequenceNumber(sequence_number_rtx_++);
|
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
|
|
|
|
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.
|
|
|
|
|
if (!rtx_ssrc_has_acked_) {
|
|
|
|
|
// 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
|
|
|
|
2018-02-22 14:18:06 +01:00
|
|
|
// Add original application data.
|
|
|
|
|
rtx_packet->set_application_data(packet.application_data());
|
|
|
|
|
|
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) {
|
2016-02-02 08:31:45 -08:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
2014-07-07 13:06:48 +00:00
|
|
|
sequence_number_ = rtp_state.sequence_number;
|
|
|
|
|
sequence_number_forced_ = true;
|
2016-08-18 02:01:49 -07:00
|
|
|
timestamp_offset_ = rtp_state.start_timestamp;
|
2016-08-22 03:39:23 -07:00
|
|
|
last_rtp_timestamp_ = rtp_state.timestamp;
|
2014-07-07 13:06:48 +00:00
|
|
|
capture_time_ms_ = rtp_state.capture_time_ms;
|
|
|
|
|
last_timestamp_time_ms_ = rtp_state.last_timestamp_time_ms;
|
2019-07-21 15:04:21 -04:00
|
|
|
ssrc_has_acked_ = rtp_state.ssrc_has_acked;
|
2014-07-07 13:06:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RtpState RTPSender::GetRtpState() const {
|
2016-02-02 08:31:45 -08:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
2014-07-07 13:06:48 +00:00
|
|
|
|
|
|
|
|
RtpState state;
|
|
|
|
|
state.sequence_number = sequence_number_;
|
2016-08-18 02:01:49 -07:00
|
|
|
state.start_timestamp = timestamp_offset_;
|
2016-08-22 03:39:23 -07:00
|
|
|
state.timestamp = last_rtp_timestamp_;
|
2014-07-07 13:06:48 +00:00
|
|
|
state.capture_time_ms = capture_time_ms_;
|
|
|
|
|
state.last_timestamp_time_ms = last_timestamp_time_ms_;
|
2019-07-21 15:04:21 -04:00
|
|
|
state.ssrc_has_acked = ssrc_has_acked_;
|
2014-07-07 13:06:48 +00:00
|
|
|
return state;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void RTPSender::SetRtxRtpState(const RtpState& rtp_state) {
|
2016-02-02 08:31:45 -08:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
2014-07-07 13:06:48 +00:00
|
|
|
sequence_number_rtx_ = 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 {
|
2016-02-02 08:31:45 -08:00
|
|
|
rtc::CritScope lock(&send_critsect_);
|
2014-07-07 13:06:48 +00:00
|
|
|
|
|
|
|
|
RtpState state;
|
|
|
|
|
state.sequence_number = sequence_number_rtx_;
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-06 04:38:06 -07:00
|
|
|
int64_t RTPSender::LastTimestampTimeMs() const {
|
|
|
|
|
rtc::CritScope lock(&send_critsect_);
|
|
|
|
|
return last_timestamp_time_ms_;
|
|
|
|
|
}
|
2012-11-07 17:01:04 +00:00
|
|
|
} // namespace webrtc
|