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
|
|
|
#ifndef MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_
|
|
|
|
|
#define MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_
|
2013-08-05 16:22:53 +00:00
|
|
|
|
2012-01-19 15:56:10 +00:00
|
|
|
#include <map>
|
2016-04-27 01:19:58 -07:00
|
|
|
#include <memory>
|
2018-03-22 15:17:27 -07:00
|
|
|
#include <string>
|
2015-12-10 05:05:27 -08:00
|
|
|
#include <utility>
|
|
|
|
|
#include <vector>
|
2012-01-19 15:56:10 +00:00
|
|
|
|
2018-11-05 13:27:35 +01:00
|
|
|
#include "absl/strings/string_view.h"
|
2018-06-14 12:59:38 +02:00
|
|
|
#include "absl/types/optional.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "api/array_view.h"
|
|
|
|
|
#include "api/call/transport.h"
|
2019-02-21 07:55:59 +01:00
|
|
|
#include "api/transport/webrtc_key_value_config.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/rtp_rtcp/include/flexfec_sender.h"
|
|
|
|
|
#include "modules/rtp_rtcp/include/rtp_header_extension_map.h"
|
2019-07-24 14:52:55 +02:00
|
|
|
#include "modules/rtp_rtcp/include/rtp_packet_sender.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "modules/rtp_rtcp/include/rtp_rtcp_defines.h"
|
|
|
|
|
#include "modules/rtp_rtcp/source/rtp_packet_history.h"
|
|
|
|
|
#include "modules/rtp_rtcp/source/rtp_rtcp_config.h"
|
2020-06-03 22:55:33 +02:00
|
|
|
#include "modules/rtp_rtcp/source/rtp_rtcp_interface.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/deprecation.h"
|
|
|
|
|
#include "rtc_base/random.h"
|
|
|
|
|
#include "rtc_base/rate_statistics.h"
|
2020-07-07 11:44:28 +02:00
|
|
|
#include "rtc_base/synchronization/mutex.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_base/thread_annotations.h"
|
2011-07-07 08:21:25 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
2013-01-25 10:53:38 +00:00
|
|
|
|
2018-10-17 17:27:25 -07:00
|
|
|
class FrameEncryptorInterface;
|
2016-07-13 09:11:28 -07:00
|
|
|
class RateLimiter;
|
2016-08-03 18:27:40 +02:00
|
|
|
class RtcEventLog;
|
|
|
|
|
class RtpPacketToSend;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2019-05-29 13:02:24 +02:00
|
|
|
class RTPSender {
|
2012-11-07 17:01:04 +00:00
|
|
|
public:
|
2020-06-03 22:55:33 +02:00
|
|
|
RTPSender(const RtpRtcpInterface::Configuration& config,
|
2019-10-25 15:24:15 +02:00
|
|
|
RtpPacketHistory* packet_history,
|
|
|
|
|
RtpPacketSender* packet_sender);
|
2019-07-04 10:38:43 +02:00
|
|
|
|
2020-09-29 09:46:21 +02:00
|
|
|
RTPSender() = delete;
|
|
|
|
|
RTPSender(const RTPSender&) = delete;
|
|
|
|
|
RTPSender& operator=(const RTPSender&) = delete;
|
|
|
|
|
|
2016-08-09 07:43:25 -07:00
|
|
|
~RTPSender();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2020-07-07 11:44:28 +02:00
|
|
|
void SetSendingMediaStatus(bool enabled) RTC_LOCKS_EXCLUDED(send_mutex_);
|
|
|
|
|
bool SendingMedia() const RTC_LOCKS_EXCLUDED(send_mutex_);
|
|
|
|
|
bool IsAudioConfigured() const RTC_LOCKS_EXCLUDED(send_mutex_);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2020-07-07 11:44:28 +02:00
|
|
|
uint32_t TimestampOffset() const RTC_LOCKS_EXCLUDED(send_mutex_);
|
|
|
|
|
void SetTimestampOffset(uint32_t timestamp) RTC_LOCKS_EXCLUDED(send_mutex_);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2020-07-07 11:44:28 +02:00
|
|
|
void SetRid(const std::string& rid) RTC_LOCKS_EXCLUDED(send_mutex_);
|
2018-12-21 09:23:38 -08:00
|
|
|
|
2020-07-07 11:44:28 +02:00
|
|
|
void SetMid(const std::string& mid) RTC_LOCKS_EXCLUDED(send_mutex_);
|
2018-03-22 15:17:27 -07:00
|
|
|
|
2020-07-07 11:44:28 +02:00
|
|
|
uint16_t SequenceNumber() const RTC_LOCKS_EXCLUDED(send_mutex_);
|
|
|
|
|
void SetSequenceNumber(uint16_t seq) RTC_LOCKS_EXCLUDED(send_mutex_);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2020-05-27 17:21:03 +02:00
|
|
|
void SetCsrcs(const std::vector<uint32_t>& csrcs)
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2020-05-27 17:21:03 +02:00
|
|
|
void SetMaxRtpPacketSize(size_t max_packet_size)
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
2013-01-25 10:53:38 +00:00
|
|
|
|
2020-05-27 17:21:03 +02:00
|
|
|
void SetExtmapAllowMixed(bool extmap_allow_mixed)
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
2018-10-29 11:22:05 +01:00
|
|
|
|
2013-01-25 10:53:38 +00:00
|
|
|
// RTP header extension
|
2020-05-27 17:21:03 +02:00
|
|
|
int32_t RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id)
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
2020-05-27 17:21:03 +02:00
|
|
|
bool RegisterRtpHeaderExtension(absl::string_view uri, int id)
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
2020-05-27 17:21:03 +02:00
|
|
|
bool IsRtpHeaderExtensionRegistered(RTPExtensionType type) const
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
2020-05-27 17:21:03 +02:00
|
|
|
int32_t DeregisterRtpHeaderExtension(RTPExtensionType type)
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
2020-05-27 17:21:03 +02:00
|
|
|
void DeregisterRtpHeaderExtension(absl::string_view uri)
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
2020-05-27 17:21:03 +02:00
|
|
|
|
2020-07-07 11:44:28 +02:00
|
|
|
bool SupportsPadding() const RTC_LOCKS_EXCLUDED(send_mutex_);
|
|
|
|
|
bool SupportsRtxPayloadPadding() const RTC_LOCKS_EXCLUDED(send_mutex_);
|
2019-10-25 15:24:15 +02:00
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<RtpPacketToSend>> GeneratePadding(
|
|
|
|
|
size_t target_size_bytes,
|
2020-07-07 11:44:28 +02:00
|
|
|
bool media_has_been_sent) RTC_LOCKS_EXCLUDED(send_mutex_);
|
2019-10-25 15:24:15 +02:00
|
|
|
|
2013-01-25 10:53:38 +00:00
|
|
|
// NACK.
|
2016-08-26 18:48:46 +02:00
|
|
|
void OnReceivedNack(const std::vector<uint16_t>& nack_sequence_numbers,
|
2020-07-07 11:44:28 +02:00
|
|
|
int64_t avg_rtt) RTC_LOCKS_EXCLUDED(send_mutex_);
|
2012-01-16 11:06:31 +00:00
|
|
|
|
2020-07-07 11:44:28 +02:00
|
|
|
int32_t ReSendPacket(uint16_t packet_id) RTC_LOCKS_EXCLUDED(send_mutex_);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2019-07-21 15:04:21 -04:00
|
|
|
// ACK.
|
2020-05-27 17:21:03 +02:00
|
|
|
void OnReceivedAckOnSsrc(int64_t extended_highest_sequence_number)
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
2020-05-27 17:21:03 +02:00
|
|
|
void OnReceivedAckOnRtxSsrc(int64_t extended_highest_sequence_number)
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
2019-07-21 15:04:21 -04:00
|
|
|
|
2013-01-25 10:53:38 +00:00
|
|
|
// RTX.
|
2020-07-07 11:44:28 +02:00
|
|
|
void SetRtxStatus(int mode) RTC_LOCKS_EXCLUDED(send_mutex_);
|
|
|
|
|
int RtxStatus() const RTC_LOCKS_EXCLUDED(send_mutex_);
|
|
|
|
|
absl::optional<uint32_t> RtxSsrc() const RTC_LOCKS_EXCLUDED(send_mutex_) {
|
2020-05-27 17:21:03 +02:00
|
|
|
return rtx_ssrc_;
|
|
|
|
|
}
|
2014-06-05 08:25:29 +00:00
|
|
|
|
2020-05-27 17:21:03 +02:00
|
|
|
void SetRtxPayloadType(int payload_type, int associated_payload_type)
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
2012-01-10 14:09:18 +00:00
|
|
|
|
2017-05-17 05:08:38 -07:00
|
|
|
// Size info for header extensions used by FEC packets.
|
2020-05-27 17:21:03 +02:00
|
|
|
static rtc::ArrayView<const RtpExtensionSize> FecExtensionSizes()
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
2017-05-17 05:08:38 -07:00
|
|
|
|
2018-03-15 15:46:17 +01:00
|
|
|
// Size info for header extensions used by video packets.
|
2020-05-27 17:21:03 +02:00
|
|
|
static rtc::ArrayView<const RtpExtensionSize> VideoExtensionSizes()
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
2018-03-15 15:46:17 +01:00
|
|
|
|
2020-05-07 18:18:32 +02:00
|
|
|
// Size info for header extensions used by audio packets.
|
2020-05-27 17:21:03 +02:00
|
|
|
static rtc::ArrayView<const RtpExtensionSize> AudioExtensionSizes()
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
2020-05-07 18:18:32 +02:00
|
|
|
|
2016-09-02 19:15:59 +02:00
|
|
|
// Create empty packet, fills ssrc, csrcs and reserve place for header
|
|
|
|
|
// extensions RtpSender updates before sending.
|
2020-05-27 17:21:03 +02:00
|
|
|
std::unique_ptr<RtpPacketToSend> AllocatePacket() const
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
2016-09-02 19:15:59 +02:00
|
|
|
// Allocate sequence number for provided packet.
|
|
|
|
|
// Save packet's fields to generate padding that doesn't break media stream.
|
|
|
|
|
// Return false if sending was turned off.
|
2020-05-27 17:21:03 +02:00
|
|
|
bool AssignSequenceNumber(RtpPacketToSend* packet)
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
2020-05-07 18:18:32 +02:00
|
|
|
// Maximum header overhead per fec/padding packet.
|
2020-05-27 17:21:03 +02:00
|
|
|
size_t FecOrPaddingPacketMaxRtpHeaderLength() const
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
2020-05-07 18:18:32 +02:00
|
|
|
// Expected header overhead per media packet.
|
2020-07-07 11:44:28 +02:00
|
|
|
size_t ExpectedPerPacketOverhead() const RTC_LOCKS_EXCLUDED(send_mutex_);
|
2020-05-27 17:21:03 +02:00
|
|
|
uint16_t AllocateSequenceNumber(uint16_t packets_to_send)
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
2017-01-10 08:58:32 -08:00
|
|
|
// Including RTP headers.
|
2020-07-07 11:44:28 +02:00
|
|
|
size_t MaxRtpPacketSize() const RTC_LOCKS_EXCLUDED(send_mutex_);
|
2012-11-07 17:01:04 +00:00
|
|
|
|
2020-07-07 11:44:28 +02:00
|
|
|
uint32_t SSRC() const RTC_LOCKS_EXCLUDED(send_mutex_) { return ssrc_; }
|
2015-03-04 12:58:35 +00:00
|
|
|
|
2020-07-07 11:44:28 +02:00
|
|
|
absl::optional<uint32_t> FlexfecSsrc() const RTC_LOCKS_EXCLUDED(send_mutex_) {
|
2020-05-27 17:21:03 +02:00
|
|
|
return flexfec_ssrc_;
|
|
|
|
|
}
|
2016-11-14 05:14:50 -08:00
|
|
|
|
2019-01-31 08:56:26 +01:00
|
|
|
// Sends packet to |transport_| or to the pacer, depending on configuration.
|
2019-10-02 14:57:46 +02:00
|
|
|
// TODO(bugs.webrtc.org/XXX): Remove in favor of EnqueuePackets().
|
2020-05-27 17:21:03 +02:00
|
|
|
bool SendToNetwork(std::unique_ptr<RtpPacketToSend> packet)
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
2019-08-27 18:16:26 +02:00
|
|
|
|
2019-10-02 14:57:46 +02:00
|
|
|
// Pass a set of packets to RtpPacketSender instance, for paced or immediate
|
|
|
|
|
// sending to the network.
|
2020-05-27 17:21:03 +02:00
|
|
|
void EnqueuePackets(std::vector<std::unique_ptr<RtpPacketToSend>> packets)
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
2019-10-02 14:57:46 +02:00
|
|
|
|
2020-07-07 11:44:28 +02:00
|
|
|
void SetRtpState(const RtpState& rtp_state) RTC_LOCKS_EXCLUDED(send_mutex_);
|
|
|
|
|
RtpState GetRtpState() const RTC_LOCKS_EXCLUDED(send_mutex_);
|
2020-05-27 17:21:03 +02:00
|
|
|
void SetRtxRtpState(const RtpState& rtp_state)
|
2020-07-07 11:44:28 +02:00
|
|
|
RTC_LOCKS_EXCLUDED(send_mutex_);
|
|
|
|
|
RtpState GetRtxRtpState() const RTC_LOCKS_EXCLUDED(send_mutex_);
|
2014-07-07 13:06:48 +00:00
|
|
|
|
2020-07-07 11:44:28 +02:00
|
|
|
int64_t LastTimestampTimeMs() const RTC_LOCKS_EXCLUDED(send_mutex_);
|
2017-07-06 04:38:06 -07:00
|
|
|
|
2012-11-07 17:01:04 +00:00
|
|
|
private:
|
2016-08-03 18:27:40 +02:00
|
|
|
std::unique_ptr<RtpPacketToSend> BuildRtxPacket(
|
|
|
|
|
const RtpPacketToSend& packet);
|
2012-11-13 21:12:39 +00:00
|
|
|
|
2016-08-03 18:27:40 +02:00
|
|
|
bool IsFecPacket(const RtpPacketToSend& packet) const;
|
2013-12-05 14:29:02 +00:00
|
|
|
|
2020-07-07 11:44:28 +02:00
|
|
|
void UpdateHeaderSizes() RTC_EXCLUSIVE_LOCKS_REQUIRED(send_mutex_);
|
2020-05-07 18:18:32 +02:00
|
|
|
|
2016-02-02 08:31:45 -08:00
|
|
|
Clock* const clock_;
|
2020-07-07 11:44:28 +02:00
|
|
|
Random random_ RTC_GUARDED_BY(send_mutex_);
|
2014-11-05 14:05:29 +00:00
|
|
|
|
2013-01-25 10:53:38 +00:00
|
|
|
const bool audio_configured_;
|
2019-02-06 22:48:11 +01:00
|
|
|
|
2019-10-15 14:29:11 +02:00
|
|
|
const uint32_t ssrc_;
|
|
|
|
|
const absl::optional<uint32_t> rtx_ssrc_;
|
2019-02-06 22:48:11 +01:00
|
|
|
const absl::optional<uint32_t> flexfec_ssrc_;
|
2020-04-16 15:07:56 +02:00
|
|
|
// Limits GeneratePadding() outcome to <=
|
|
|
|
|
// |max_padding_size_factor_| * |target_size_bytes|
|
|
|
|
|
const double max_padding_size_factor_;
|
2012-11-13 21:12:39 +00:00
|
|
|
|
2019-10-28 18:24:32 +01:00
|
|
|
RtpPacketHistory* const packet_history_;
|
|
|
|
|
RtpPacketSender* const paced_sender_;
|
2019-10-25 15:24:15 +02:00
|
|
|
|
2020-07-07 11:44:28 +02:00
|
|
|
mutable Mutex send_mutex_;
|
2012-11-13 21:12:39 +00:00
|
|
|
|
2020-07-07 11:44:28 +02:00
|
|
|
bool sending_media_ RTC_GUARDED_BY(send_mutex_);
|
2017-01-10 08:58:32 -08:00
|
|
|
size_t max_packet_size_;
|
2012-11-13 21:12:39 +00:00
|
|
|
|
2020-07-07 11:44:28 +02:00
|
|
|
int8_t last_payload_type_ RTC_GUARDED_BY(send_mutex_);
|
2012-11-13 21:12:39 +00:00
|
|
|
|
2020-07-07 11:44:28 +02:00
|
|
|
RtpHeaderExtensionMap rtp_header_extension_map_ RTC_GUARDED_BY(send_mutex_);
|
|
|
|
|
size_t max_media_packet_header_ RTC_GUARDED_BY(send_mutex_);
|
|
|
|
|
size_t max_padding_fec_packet_header_ RTC_GUARDED_BY(send_mutex_);
|
2012-11-13 21:12:39 +00:00
|
|
|
|
|
|
|
|
// RTP variables
|
2020-07-07 11:44:28 +02:00
|
|
|
uint32_t timestamp_offset_ RTC_GUARDED_BY(send_mutex_);
|
|
|
|
|
bool sequence_number_forced_ RTC_GUARDED_BY(send_mutex_);
|
|
|
|
|
uint16_t sequence_number_ RTC_GUARDED_BY(send_mutex_);
|
|
|
|
|
uint16_t sequence_number_rtx_ RTC_GUARDED_BY(send_mutex_);
|
2018-12-21 09:23:38 -08:00
|
|
|
// RID value to send in the RID or RepairedRID header extension.
|
2020-07-07 11:44:28 +02:00
|
|
|
std::string rid_ RTC_GUARDED_BY(send_mutex_);
|
2018-04-06 11:09:46 -07:00
|
|
|
// MID value to send in the MID header extension.
|
2020-07-07 11:44:28 +02:00
|
|
|
std::string mid_ RTC_GUARDED_BY(send_mutex_);
|
2020-03-10 14:12:48 +01:00
|
|
|
// Should we send MID/RID even when ACKed? (see below).
|
|
|
|
|
const bool always_send_mid_and_rid_;
|
2019-07-21 15:04:21 -04:00
|
|
|
// Track if any ACK has been received on the SSRC and RTX SSRC to indicate
|
|
|
|
|
// when to stop sending the MID and RID header extensions.
|
2020-07-07 11:44:28 +02:00
|
|
|
bool ssrc_has_acked_ RTC_GUARDED_BY(send_mutex_);
|
|
|
|
|
bool rtx_ssrc_has_acked_ RTC_GUARDED_BY(send_mutex_);
|
|
|
|
|
uint32_t last_rtp_timestamp_ RTC_GUARDED_BY(send_mutex_);
|
|
|
|
|
int64_t capture_time_ms_ RTC_GUARDED_BY(send_mutex_);
|
|
|
|
|
int64_t last_timestamp_time_ms_ RTC_GUARDED_BY(send_mutex_);
|
|
|
|
|
bool last_packet_marker_bit_ RTC_GUARDED_BY(send_mutex_);
|
|
|
|
|
std::vector<uint32_t> csrcs_ RTC_GUARDED_BY(send_mutex_);
|
|
|
|
|
int rtx_ RTC_GUARDED_BY(send_mutex_);
|
2015-04-21 20:24:50 +08:00
|
|
|
// Mapping rtx_payload_type_map_[associated] = rtx.
|
2020-07-07 11:44:28 +02:00
|
|
|
std::map<int8_t, int8_t> rtx_payload_type_map_ RTC_GUARDED_BY(send_mutex_);
|
|
|
|
|
bool supports_bwe_extension_ RTC_GUARDED_BY(send_mutex_);
|
2014-03-26 14:27:34 +00:00
|
|
|
|
2016-07-13 09:11:28 -07:00
|
|
|
RateLimiter* const retransmission_rate_limiter_;
|
2011-07-07 08:21:25 +00:00
|
|
|
};
|
|
|
|
|
|
2013-01-25 10:53:38 +00:00
|
|
|
} // namespace webrtc
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_RTP_RTCP_SOURCE_RTP_SENDER_H_
|