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"
|
2019-07-04 10:38:43 +02:00
|
|
|
#include "modules/rtp_rtcp/include/rtp_rtcp.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"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "rtc_base/constructor_magic.h"
|
|
|
|
|
#include "rtc_base/critical_section.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"
|
|
|
|
|
#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-11-17 01:38:43 -08:00
|
|
|
class OverheadObserver;
|
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:
|
2019-10-25 15:24:15 +02:00
|
|
|
RTPSender(const RtpRtcp::Configuration& config,
|
|
|
|
|
RtpPacketHistory* packet_history,
|
|
|
|
|
RtpPacketSender* packet_sender);
|
2019-07-04 10:38:43 +02:00
|
|
|
|
2016-08-09 07:43:25 -07:00
|
|
|
~RTPSender();
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2014-12-19 13:49:55 +00:00
|
|
|
void SetSendingMediaStatus(bool enabled);
|
2012-11-07 17:01:04 +00:00
|
|
|
bool SendingMedia() const;
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2016-08-18 02:01:49 -07:00
|
|
|
uint32_t TimestampOffset() const;
|
|
|
|
|
void SetTimestampOffset(uint32_t timestamp);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2018-12-21 09:23:38 -08:00
|
|
|
void SetRid(const std::string& rid);
|
|
|
|
|
|
2018-03-22 15:17:27 -07:00
|
|
|
void SetMid(const std::string& mid);
|
|
|
|
|
|
2016-08-09 07:43:25 -07:00
|
|
|
uint16_t SequenceNumber() const;
|
2013-04-08 11:08:41 +00:00
|
|
|
void SetSequenceNumber(uint16_t seq);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2014-11-24 08:25:50 +00:00
|
|
|
void SetCsrcs(const std::vector<uint32_t>& csrcs);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2017-01-10 08:58:32 -08:00
|
|
|
void SetMaxRtpPacketSize(size_t max_packet_size);
|
2013-01-25 10:53:38 +00:00
|
|
|
|
2018-10-29 11:22:05 +01:00
|
|
|
void SetExtmapAllowMixed(bool extmap_allow_mixed);
|
|
|
|
|
|
2013-01-25 10:53:38 +00:00
|
|
|
// RTP header extension
|
2014-12-19 13:49:55 +00:00
|
|
|
int32_t RegisterRtpHeaderExtension(RTPExtensionType type, uint8_t id);
|
2019-10-14 17:32:21 +02:00
|
|
|
bool RegisterRtpHeaderExtension(absl::string_view uri, int id);
|
2017-02-03 08:13:57 -08:00
|
|
|
bool IsRtpHeaderExtensionRegistered(RTPExtensionType type) const;
|
2014-12-19 13:49:55 +00:00
|
|
|
int32_t DeregisterRtpHeaderExtension(RTPExtensionType type);
|
2019-10-14 17:32:21 +02:00
|
|
|
void DeregisterRtpHeaderExtension(absl::string_view uri);
|
2011-12-16 14:31:37 +00:00
|
|
|
|
2019-07-12 17:33:46 +00:00
|
|
|
bool SupportsPadding() const;
|
|
|
|
|
bool SupportsRtxPayloadPadding() const;
|
2019-10-25 15:24:15 +02:00
|
|
|
|
|
|
|
|
std::vector<std::unique_ptr<RtpPacketToSend>> GeneratePadding(
|
|
|
|
|
size_t target_size_bytes,
|
|
|
|
|
bool media_has_been_sent);
|
|
|
|
|
|
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,
|
2015-01-12 21:51:21 +00:00
|
|
|
int64_t avg_rtt);
|
2012-01-16 11:06:31 +00:00
|
|
|
|
2018-03-14 12:39:24 +01:00
|
|
|
int32_t ReSendPacket(uint16_t packet_id);
|
2011-07-07 08:21:25 +00:00
|
|
|
|
2019-07-21 15:04:21 -04:00
|
|
|
// ACK.
|
|
|
|
|
void OnReceivedAckOnSsrc(int64_t extended_highest_sequence_number);
|
|
|
|
|
void OnReceivedAckOnRtxSsrc(int64_t extended_highest_sequence_number);
|
|
|
|
|
|
2013-01-25 10:53:38 +00:00
|
|
|
// RTX.
|
2015-01-13 14:15:15 +00:00
|
|
|
void SetRtxStatus(int mode);
|
|
|
|
|
int RtxStatus() const;
|
2019-10-17 13:02:27 +02:00
|
|
|
absl::optional<uint32_t> RtxSsrc() const { return rtx_ssrc_; }
|
2014-06-05 08:25:29 +00:00
|
|
|
|
2015-04-21 20:24:50 +08:00
|
|
|
void SetRtxPayloadType(int payload_type, int associated_payload_type);
|
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.
|
|
|
|
|
static rtc::ArrayView<const RtpExtensionSize> FecExtensionSizes();
|
|
|
|
|
|
2018-03-15 15:46:17 +01:00
|
|
|
// Size info for header extensions used by video packets.
|
|
|
|
|
static rtc::ArrayView<const RtpExtensionSize> VideoExtensionSizes();
|
|
|
|
|
|
2016-09-02 19:15:59 +02:00
|
|
|
// Create empty packet, fills ssrc, csrcs and reserve place for header
|
|
|
|
|
// extensions RtpSender updates before sending.
|
|
|
|
|
std::unique_ptr<RtpPacketToSend> AllocatePacket() const;
|
|
|
|
|
// 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.
|
|
|
|
|
bool AssignSequenceNumber(RtpPacketToSend* packet);
|
|
|
|
|
|
2017-05-17 05:08:38 -07:00
|
|
|
// Used for padding and FEC packets only.
|
2016-08-09 07:43:25 -07:00
|
|
|
size_t RtpHeaderLength() const;
|
|
|
|
|
uint16_t AllocateSequenceNumber(uint16_t packets_to_send);
|
2017-01-10 08:58:32 -08:00
|
|
|
// Including RTP headers.
|
|
|
|
|
size_t MaxRtpPacketSize() const;
|
2012-11-07 17:01:04 +00:00
|
|
|
|
2019-10-15 14:29:11 +02:00
|
|
|
uint32_t SSRC() const { return ssrc_; }
|
2015-03-04 12:58:35 +00:00
|
|
|
|
2019-10-15 14:29:11 +02:00
|
|
|
absl::optional<uint32_t> FlexfecSsrc() const { 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().
|
2019-08-27 18:16:26 +02:00
|
|
|
bool SendToNetwork(std::unique_ptr<RtpPacketToSend> packet);
|
|
|
|
|
|
2019-10-02 14:57:46 +02:00
|
|
|
// Pass a set of packets to RtpPacketSender instance, for paced or immediate
|
|
|
|
|
// sending to the network.
|
|
|
|
|
void EnqueuePackets(std::vector<std::unique_ptr<RtpPacketToSend>> packets);
|
|
|
|
|
|
2014-07-07 13:06:48 +00:00
|
|
|
void SetRtpState(const RtpState& rtp_state);
|
|
|
|
|
RtpState GetRtpState() const;
|
|
|
|
|
void SetRtxRtpState(const RtpState& rtp_state);
|
|
|
|
|
RtpState GetRtxRtpState() const;
|
|
|
|
|
|
2017-07-06 04:38:06 -07:00
|
|
|
int64_t LastTimestampTimeMs() const;
|
|
|
|
|
|
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
|
|
|
|
2016-02-02 08:31:45 -08:00
|
|
|
Clock* const clock_;
|
2017-09-07 07:53:45 -07:00
|
|
|
Random random_ RTC_GUARDED_BY(send_critsect_);
|
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_;
|
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
|
|
|
|
2016-02-02 08:31:45 -08:00
|
|
|
rtc::CriticalSection send_critsect_;
|
2012-11-13 21:12:39 +00:00
|
|
|
|
2017-09-07 07:53:45 -07:00
|
|
|
bool sending_media_ RTC_GUARDED_BY(send_critsect_);
|
2017-01-10 08:58:32 -08:00
|
|
|
size_t max_packet_size_;
|
2012-11-13 21:12:39 +00:00
|
|
|
|
2018-03-22 10:13:07 +01:00
|
|
|
int8_t last_payload_type_ RTC_GUARDED_BY(send_critsect_);
|
2012-11-13 21:12:39 +00:00
|
|
|
|
2017-09-07 07:53:45 -07:00
|
|
|
RtpHeaderExtensionMap rtp_header_extension_map_
|
|
|
|
|
RTC_GUARDED_BY(send_critsect_);
|
2012-11-13 21:12:39 +00:00
|
|
|
|
|
|
|
|
// RTP variables
|
2017-09-07 07:53:45 -07:00
|
|
|
uint32_t timestamp_offset_ RTC_GUARDED_BY(send_critsect_);
|
|
|
|
|
bool sequence_number_forced_ RTC_GUARDED_BY(send_critsect_);
|
|
|
|
|
uint16_t sequence_number_ RTC_GUARDED_BY(send_critsect_);
|
|
|
|
|
uint16_t sequence_number_rtx_ RTC_GUARDED_BY(send_critsect_);
|
2018-12-21 09:23:38 -08:00
|
|
|
// RID value to send in the RID or RepairedRID header extension.
|
|
|
|
|
std::string rid_ RTC_GUARDED_BY(send_critsect_);
|
2018-04-06 11:09:46 -07:00
|
|
|
// MID value to send in the MID header extension.
|
|
|
|
|
std::string mid_ RTC_GUARDED_BY(send_critsect_);
|
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.
|
|
|
|
|
bool ssrc_has_acked_ RTC_GUARDED_BY(send_critsect_);
|
|
|
|
|
bool rtx_ssrc_has_acked_ RTC_GUARDED_BY(send_critsect_);
|
2017-09-07 07:53:45 -07:00
|
|
|
uint32_t last_rtp_timestamp_ RTC_GUARDED_BY(send_critsect_);
|
|
|
|
|
int64_t capture_time_ms_ RTC_GUARDED_BY(send_critsect_);
|
|
|
|
|
int64_t last_timestamp_time_ms_ RTC_GUARDED_BY(send_critsect_);
|
|
|
|
|
bool last_packet_marker_bit_ RTC_GUARDED_BY(send_critsect_);
|
|
|
|
|
std::vector<uint32_t> csrcs_ RTC_GUARDED_BY(send_critsect_);
|
|
|
|
|
int rtx_ RTC_GUARDED_BY(send_critsect_);
|
2015-04-21 20:24:50 +08:00
|
|
|
// Mapping rtx_payload_type_map_[associated] = rtx.
|
2017-09-07 07:53:45 -07:00
|
|
|
std::map<int8_t, int8_t> rtx_payload_type_map_ RTC_GUARDED_BY(send_critsect_);
|
2019-07-12 17:33:46 +00:00
|
|
|
bool supports_bwe_extension_ RTC_GUARDED_BY(send_critsect_);
|
2014-03-26 14:27:34 +00:00
|
|
|
|
2016-07-13 09:11:28 -07:00
|
|
|
RateLimiter* const retransmission_rate_limiter_;
|
2016-01-21 05:42:04 -08:00
|
|
|
|
|
|
|
|
RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RTPSender);
|
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_
|