2015-11-04 08:31:52 +01:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* 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_INCLUDE_RTP_RTCP_DEFINES_H_
|
|
|
|
|
#define MODULES_RTP_RTCP_INCLUDE_RTP_RTCP_DEFINES_H_
|
2015-11-04 08:31:52 +01:00
|
|
|
|
|
|
|
|
#include <stddef.h>
|
2019-07-05 19:08:33 +02:00
|
|
|
|
2015-11-04 08:31:52 +01:00
|
|
|
#include <list>
|
2019-10-10 12:57:28 +02:00
|
|
|
#include <memory>
|
2016-09-07 09:58:20 +02:00
|
|
|
#include <vector>
|
2015-11-04 08:31:52 +01:00
|
|
|
|
2020-05-11 18:22:02 +02:00
|
|
|
#include "absl/algorithm/container.h"
|
2019-03-21 15:48:49 +01:00
|
|
|
#include "absl/strings/string_view.h"
|
2019-05-07 09:29:15 -07:00
|
|
|
#include "absl/types/optional.h"
|
2018-06-26 10:44:13 +02:00
|
|
|
#include "absl/types/variant.h"
|
2019-05-07 09:29:15 -07:00
|
|
|
#include "api/array_view.h"
|
2017-10-04 12:38:53 +02:00
|
|
|
#include "api/audio_codecs/audio_format.h"
|
2017-12-15 14:40:10 +01:00
|
|
|
#include "api/rtp_headers.h"
|
2018-09-17 13:11:50 +02:00
|
|
|
#include "api/transport/network_types.h"
|
2019-07-24 11:38:03 +02:00
|
|
|
#include "modules/rtp_rtcp/source/rtcp_packet/remote_estimate.h"
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "system_wrappers/include/clock.h"
|
2015-11-04 08:31:52 +01:00
|
|
|
|
|
|
|
|
#define RTCP_CNAME_SIZE 256 // RFC 3550 page 44, including null termination
|
|
|
|
|
#define IP_PACKET_SIZE 1500 // we assume ethernet
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
2018-11-15 08:05:16 +01:00
|
|
|
class RtpPacket;
|
2020-07-02 17:41:32 +02:00
|
|
|
class RtpPacketToSend;
|
2015-11-04 08:31:52 +01:00
|
|
|
namespace rtcp {
|
|
|
|
|
class TransportFeedback;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int kVideoPayloadTypeFrequency = 90000;
|
2018-10-24 13:34:32 +02:00
|
|
|
|
|
|
|
|
// TODO(bugs.webrtc.org/6458): Remove this when all the depending projects are
|
|
|
|
|
// updated to correctly set rtp rate for RtcpSender.
|
2016-10-03 06:22:25 -07:00
|
|
|
const int kBogusRtpRateForAudioRtcp = 8000;
|
2015-11-04 08:31:52 +01:00
|
|
|
|
|
|
|
|
// Minimum RTP header size in bytes.
|
|
|
|
|
const uint8_t kRtpHeaderSize = 12;
|
|
|
|
|
|
2019-03-21 15:48:49 +01:00
|
|
|
bool IsLegalMidName(absl::string_view name);
|
|
|
|
|
bool IsLegalRsidName(absl::string_view name);
|
|
|
|
|
|
2018-09-24 14:50:48 +02:00
|
|
|
// This enum must not have any gaps, i.e., all integers between
|
|
|
|
|
// kRtpExtensionNone and kRtpExtensionNumberOfExtensions must be valid enum
|
|
|
|
|
// entries.
|
|
|
|
|
enum RTPExtensionType : int {
|
2015-11-04 08:31:52 +01:00
|
|
|
kRtpExtensionNone,
|
|
|
|
|
kRtpExtensionTransmissionTimeOffset,
|
|
|
|
|
kRtpExtensionAudioLevel,
|
2021-05-24 13:04:45 +02:00
|
|
|
kRtpExtensionCsrcAudioLevel,
|
2019-11-29 16:18:59 +01:00
|
|
|
kRtpExtensionInbandComfortNoise,
|
2015-11-04 08:31:52 +01:00
|
|
|
kRtpExtensionAbsoluteSendTime,
|
2019-07-01 10:56:51 +02:00
|
|
|
kRtpExtensionAbsoluteCaptureTime,
|
2015-11-04 08:31:52 +01:00
|
|
|
kRtpExtensionVideoRotation,
|
|
|
|
|
kRtpExtensionTransportSequenceNumber,
|
2019-02-21 14:09:20 +00:00
|
|
|
kRtpExtensionTransportSequenceNumber02,
|
2016-06-08 00:24:21 -07:00
|
|
|
kRtpExtensionPlayoutDelay,
|
2017-04-11 10:34:31 -07:00
|
|
|
kRtpExtensionVideoContentType,
|
2020-10-05 13:51:47 +02:00
|
|
|
kRtpExtensionVideoLayersAllocation,
|
2017-06-19 07:18:55 -07:00
|
|
|
kRtpExtensionVideoTiming,
|
2017-04-19 02:59:48 -07:00
|
|
|
kRtpExtensionRtpStreamId,
|
|
|
|
|
kRtpExtensionRepairedRtpStreamId,
|
2017-07-21 09:58:31 -07:00
|
|
|
kRtpExtensionMid,
|
2019-02-19 13:01:31 +01:00
|
|
|
kRtpExtensionGenericFrameDescriptor00,
|
|
|
|
|
kRtpExtensionGenericFrameDescriptor = kRtpExtensionGenericFrameDescriptor00,
|
2019-06-27 16:45:40 +02:00
|
|
|
kRtpExtensionGenericFrameDescriptor02,
|
2018-11-27 14:36:41 +01:00
|
|
|
kRtpExtensionColorSpace,
|
2021-03-17 17:01:31 +01:00
|
|
|
kRtpExtensionVideoFrameTrackingId,
|
2017-04-11 10:34:31 -07:00
|
|
|
kRtpExtensionNumberOfExtensions // Must be the last entity in the enum.
|
2015-11-04 08:31:52 +01:00
|
|
|
};
|
|
|
|
|
|
2015-12-10 09:51:54 -08:00
|
|
|
enum RTCPAppSubTypes { kAppSubtypeBwe = 0x00 };
|
2015-11-04 08:31:52 +01:00
|
|
|
|
|
|
|
|
// TODO(sprang): Make this an enum class once rtcp_receiver has been cleaned up.
|
|
|
|
|
enum RTCPPacketType : uint32_t {
|
|
|
|
|
kRtcpReport = 0x0001,
|
|
|
|
|
kRtcpSr = 0x0002,
|
|
|
|
|
kRtcpRr = 0x0004,
|
|
|
|
|
kRtcpSdes = 0x0008,
|
|
|
|
|
kRtcpBye = 0x0010,
|
|
|
|
|
kRtcpPli = 0x0020,
|
|
|
|
|
kRtcpNack = 0x0040,
|
|
|
|
|
kRtcpFir = 0x0080,
|
|
|
|
|
kRtcpTmmbr = 0x0100,
|
|
|
|
|
kRtcpTmmbn = 0x0200,
|
|
|
|
|
kRtcpSrReq = 0x0400,
|
Create new RTCP feedback message - LossIndication
Create a new RTCP feedback message for reporting the loss and/or non-decodability of video frames, to be used by the upcoming injectable VideoFrameBufferController. The new feedback message should report:
1. The sequence number of the last decoded non-discardable video frame. (TBD: If a multi-packet frame, should it be the sequence number of the first, last, or any of the packets?)
2. The sequence number of the last received RTP packet in the stream.
3. A decodability flag, whose specific meaning depends on the last-received
RTP sequence number. The decodability flag is true if and only if all of
the frame's dependencies are known to be decodable, and the frame itself
is not yet known to be unassemblable.
* Clarification #1: In a multi-packet frame, the first packet's
dependencies are known, but it is not yet known whether all parts
of the current frame will be received.
* Clarification #2: In a multi-packet frame, the dependencies would be
unknown if the first packet was not received. Then, the packet will
be known-unassemblable.
Bug: webrtc:10226
Change-Id: I1563c944477e3ed40235e82ab99a439414632aff
Reviewed-on: https://webrtc-review.googlesource.com/c/118931
Commit-Queue: Elad Alon <eladalon@webrtc.org>
Reviewed-by: Danil Chapovalov <danilchap@webrtc.org>
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26387}
2019-01-24 12:38:36 +01:00
|
|
|
kRtcpLossNotification = 0x2000,
|
2015-11-04 08:31:52 +01:00
|
|
|
kRtcpRemb = 0x10000,
|
|
|
|
|
kRtcpTransmissionTimeOffset = 0x20000,
|
|
|
|
|
kRtcpXrReceiverReferenceTime = 0x40000,
|
|
|
|
|
kRtcpXrDlrrReportBlock = 0x80000,
|
|
|
|
|
kRtcpTransportFeedback = 0x100000,
|
2016-12-01 05:18:09 -08:00
|
|
|
kRtcpXrTargetBitrate = 0x200000
|
2015-11-04 08:31:52 +01:00
|
|
|
};
|
|
|
|
|
|
2021-12-08 20:59:31 -08:00
|
|
|
enum class KeyFrameReqMethod : uint8_t {
|
|
|
|
|
kNone, // Don't request keyframes.
|
|
|
|
|
kPliRtcp, // Request keyframes through Picture Loss Indication.
|
|
|
|
|
kFirRtcp // Request keyframes through Full Intra-frame Request.
|
|
|
|
|
};
|
|
|
|
|
|
2015-11-04 08:31:52 +01:00
|
|
|
enum RtxMode {
|
|
|
|
|
kRtxOff = 0x0,
|
|
|
|
|
kRtxRetransmitted = 0x1, // Only send retransmissions over RTX.
|
|
|
|
|
kRtxRedundantPayloads = 0x2 // Preventively send redundant payloads
|
|
|
|
|
// instead of padding.
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const size_t kRtxHeaderSize = 2;
|
|
|
|
|
|
|
|
|
|
struct RTCPReportBlock {
|
|
|
|
|
RTCPReportBlock()
|
2017-08-09 06:13:45 -07:00
|
|
|
: sender_ssrc(0),
|
|
|
|
|
source_ssrc(0),
|
|
|
|
|
fraction_lost(0),
|
|
|
|
|
packets_lost(0),
|
|
|
|
|
extended_highest_sequence_number(0),
|
|
|
|
|
jitter(0),
|
|
|
|
|
last_sender_report_timestamp(0),
|
|
|
|
|
delay_since_last_sender_report(0) {}
|
|
|
|
|
|
|
|
|
|
RTCPReportBlock(uint32_t sender_ssrc,
|
2015-11-04 08:31:52 +01:00
|
|
|
uint32_t source_ssrc,
|
|
|
|
|
uint8_t fraction_lost,
|
2017-12-08 08:59:07 +01:00
|
|
|
int32_t packets_lost,
|
2017-08-09 06:13:45 -07:00
|
|
|
uint32_t extended_highest_sequence_number,
|
2015-11-04 08:31:52 +01:00
|
|
|
uint32_t jitter,
|
2017-08-09 06:13:45 -07:00
|
|
|
uint32_t last_sender_report_timestamp,
|
2015-11-04 08:31:52 +01:00
|
|
|
uint32_t delay_since_last_sender_report)
|
2017-08-09 06:13:45 -07:00
|
|
|
: sender_ssrc(sender_ssrc),
|
|
|
|
|
source_ssrc(source_ssrc),
|
|
|
|
|
fraction_lost(fraction_lost),
|
|
|
|
|
packets_lost(packets_lost),
|
|
|
|
|
extended_highest_sequence_number(extended_highest_sequence_number),
|
2015-11-04 08:31:52 +01:00
|
|
|
jitter(jitter),
|
2017-08-09 06:13:45 -07:00
|
|
|
last_sender_report_timestamp(last_sender_report_timestamp),
|
|
|
|
|
delay_since_last_sender_report(delay_since_last_sender_report) {}
|
2015-11-04 08:31:52 +01:00
|
|
|
|
|
|
|
|
// Fields as described by RFC 3550 6.4.2.
|
2017-11-15 16:28:20 +01:00
|
|
|
uint32_t sender_ssrc; // SSRC of sender of this report.
|
|
|
|
|
uint32_t source_ssrc; // SSRC of the RTP packet sender.
|
|
|
|
|
uint8_t fraction_lost;
|
2018-08-09 11:21:11 +02:00
|
|
|
int32_t packets_lost; // 24 bits valid.
|
2017-11-15 16:28:20 +01:00
|
|
|
uint32_t extended_highest_sequence_number;
|
2015-11-04 08:31:52 +01:00
|
|
|
uint32_t jitter;
|
2017-11-15 16:28:20 +01:00
|
|
|
uint32_t last_sender_report_timestamp;
|
|
|
|
|
uint32_t delay_since_last_sender_report;
|
2015-11-04 08:31:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
typedef std::list<RTCPReportBlock> ReportBlockList;
|
|
|
|
|
|
|
|
|
|
struct RtpState {
|
|
|
|
|
RtpState()
|
|
|
|
|
: sequence_number(0),
|
|
|
|
|
start_timestamp(0),
|
|
|
|
|
timestamp(0),
|
|
|
|
|
capture_time_ms(-1),
|
|
|
|
|
last_timestamp_time_ms(-1),
|
2019-07-21 15:04:21 -04:00
|
|
|
ssrc_has_acked(false) {}
|
2015-11-04 08:31:52 +01:00
|
|
|
uint16_t sequence_number;
|
|
|
|
|
uint32_t start_timestamp;
|
|
|
|
|
uint32_t timestamp;
|
|
|
|
|
int64_t capture_time_ms;
|
|
|
|
|
int64_t last_timestamp_time_ms;
|
2019-07-21 15:04:21 -04:00
|
|
|
bool ssrc_has_acked;
|
2015-11-04 08:31:52 +01:00
|
|
|
};
|
|
|
|
|
|
2017-05-29 08:16:37 -07:00
|
|
|
// Callback interface for packets recovered by FlexFEC or ULPFEC. In
|
|
|
|
|
// the FlexFEC case, the implementation should be able to demultiplex
|
|
|
|
|
// the recovered RTP packets based on SSRC.
|
|
|
|
|
class RecoveredPacketReceiver {
|
|
|
|
|
public:
|
|
|
|
|
virtual void OnRecoveredPacket(const uint8_t* packet, size_t length) = 0;
|
2015-11-04 08:31:52 +01:00
|
|
|
|
2017-05-29 08:16:37 -07:00
|
|
|
protected:
|
|
|
|
|
virtual ~RecoveredPacketReceiver() = default;
|
2015-11-04 08:31:52 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class RtcpIntraFrameObserver {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~RtcpIntraFrameObserver() {}
|
2018-05-28 12:53:50 +02:00
|
|
|
|
|
|
|
|
virtual void OnReceivedIntraFrameRequest(uint32_t ssrc) = 0;
|
2015-11-04 08:31:52 +01:00
|
|
|
};
|
|
|
|
|
|
2019-04-09 11:55:13 +02:00
|
|
|
// Observer for incoming LossNotification RTCP messages.
|
|
|
|
|
// See the documentation of LossNotification for details.
|
|
|
|
|
class RtcpLossNotificationObserver {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~RtcpLossNotificationObserver() = default;
|
|
|
|
|
|
|
|
|
|
virtual void OnReceivedLossNotification(uint32_t ssrc,
|
|
|
|
|
uint16_t seq_num_of_last_decodable,
|
|
|
|
|
uint16_t seq_num_of_last_received,
|
|
|
|
|
bool decodability_flag) = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2015-11-04 08:31:52 +01:00
|
|
|
class RtcpBandwidthObserver {
|
|
|
|
|
public:
|
|
|
|
|
// REMB or TMMBR
|
|
|
|
|
virtual void OnReceivedEstimatedBitrate(uint32_t bitrate) = 0;
|
|
|
|
|
|
|
|
|
|
virtual void OnReceivedRtcpReceiverReport(
|
|
|
|
|
const ReportBlockList& report_blocks,
|
|
|
|
|
int64_t rtt,
|
|
|
|
|
int64_t now_ms) = 0;
|
|
|
|
|
|
|
|
|
|
virtual ~RtcpBandwidthObserver() {}
|
|
|
|
|
};
|
|
|
|
|
|
2021-07-28 23:57:33 +02:00
|
|
|
// NOTE! `kNumMediaTypes` must be kept in sync with RtpPacketMediaType!
|
2020-05-11 18:22:02 +02:00
|
|
|
static constexpr size_t kNumMediaTypes = 5;
|
|
|
|
|
enum class RtpPacketMediaType : size_t {
|
|
|
|
|
kAudio, // Audio media packets.
|
|
|
|
|
kVideo, // Video media packets.
|
|
|
|
|
kRetransmission, // Retransmisions, sent as response to NACK.
|
|
|
|
|
kForwardErrorCorrection, // FEC packets.
|
|
|
|
|
kPadding = kNumMediaTypes - 1, // RTX or plain padding sent to maintain BWE.
|
2021-07-28 23:57:33 +02:00
|
|
|
// Again, don't forget to udate `kNumMediaTypes` if you add another value!
|
2020-02-06 16:35:46 +01:00
|
|
|
};
|
|
|
|
|
|
2019-04-23 12:00:11 +02:00
|
|
|
struct RtpPacketSendInfo {
|
|
|
|
|
public:
|
|
|
|
|
RtpPacketSendInfo() = default;
|
|
|
|
|
|
|
|
|
|
uint16_t transport_sequence_number = 0;
|
2021-06-15 19:04:24 +02:00
|
|
|
absl::optional<uint32_t> media_ssrc;
|
2021-07-28 23:57:33 +02:00
|
|
|
uint16_t rtp_sequence_number = 0; // Only valid if `media_ssrc` is set.
|
2021-04-30 11:06:47 +02:00
|
|
|
uint32_t rtp_timestamp = 0;
|
2019-04-23 12:00:11 +02:00
|
|
|
size_t length = 0;
|
2020-02-06 16:35:46 +01:00
|
|
|
absl::optional<RtpPacketMediaType> packet_type;
|
2019-04-23 12:00:11 +02:00
|
|
|
PacedPacketInfo pacing_info;
|
|
|
|
|
};
|
2020-02-06 16:35:46 +01:00
|
|
|
|
2019-07-24 11:38:03 +02:00
|
|
|
class NetworkStateEstimateObserver {
|
|
|
|
|
public:
|
|
|
|
|
virtual void OnRemoteNetworkEstimate(NetworkStateEstimate estimate) = 0;
|
|
|
|
|
virtual ~NetworkStateEstimateObserver() = default;
|
|
|
|
|
};
|
2019-04-23 12:00:11 +02:00
|
|
|
|
2015-11-04 08:31:52 +01:00
|
|
|
class TransportFeedbackObserver {
|
|
|
|
|
public:
|
|
|
|
|
TransportFeedbackObserver() {}
|
|
|
|
|
virtual ~TransportFeedbackObserver() {}
|
|
|
|
|
|
2019-04-24 08:09:20 +02:00
|
|
|
virtual void OnAddPacket(const RtpPacketSendInfo& packet_info) = 0;
|
2015-11-04 08:31:52 +01:00
|
|
|
virtual void OnTransportFeedback(const rtcp::TransportFeedback& feedback) = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2017-12-14 16:02:31 +01:00
|
|
|
// Interface for PacketRouter to send rtcp feedback on behalf of
|
|
|
|
|
// congestion controller.
|
|
|
|
|
// TODO(bugs.webrtc.org/8239): Remove and use RtcpTransceiver directly
|
|
|
|
|
// when RtcpTransceiver always present in rtp transport.
|
|
|
|
|
class RtcpFeedbackSenderInterface {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~RtcpFeedbackSenderInterface() = default;
|
2019-10-10 12:57:28 +02:00
|
|
|
virtual void SendCombinedRtcpPacket(
|
|
|
|
|
std::vector<std::unique_ptr<rtcp::RtcpPacket>> rtcp_packets) = 0;
|
2017-12-14 16:02:31 +01:00
|
|
|
virtual void SetRemb(int64_t bitrate_bps, std::vector<uint32_t> ssrcs) = 0;
|
|
|
|
|
virtual void UnsetRemb() = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2019-10-29 17:18:51 +01:00
|
|
|
class StreamFeedbackObserver {
|
|
|
|
|
public:
|
|
|
|
|
struct StreamPacketInfo {
|
2021-06-15 15:58:40 +00:00
|
|
|
bool received;
|
2021-06-15 19:04:24 +02:00
|
|
|
|
2021-07-28 23:57:33 +02:00
|
|
|
// `rtp_sequence_number` and `is_retransmission` are only valid if `ssrc`
|
2021-06-15 19:04:24 +02:00
|
|
|
// is populated.
|
|
|
|
|
absl::optional<uint32_t> ssrc;
|
|
|
|
|
uint16_t rtp_sequence_number;
|
|
|
|
|
bool is_retransmission;
|
2019-10-29 17:18:51 +01:00
|
|
|
};
|
|
|
|
|
virtual ~StreamFeedbackObserver() = default;
|
|
|
|
|
|
|
|
|
|
virtual void OnPacketFeedbackVector(
|
|
|
|
|
std::vector<StreamPacketInfo> packet_feedback_vector) = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class StreamFeedbackProvider {
|
|
|
|
|
public:
|
|
|
|
|
virtual void RegisterStreamFeedbackObserver(
|
|
|
|
|
std::vector<uint32_t> ssrcs,
|
|
|
|
|
StreamFeedbackObserver* observer) = 0;
|
|
|
|
|
virtual void DeRegisterStreamFeedbackObserver(
|
|
|
|
|
StreamFeedbackObserver* observer) = 0;
|
|
|
|
|
virtual ~StreamFeedbackProvider() = default;
|
|
|
|
|
};
|
|
|
|
|
|
2015-11-04 08:31:52 +01:00
|
|
|
class RtcpRttStats {
|
|
|
|
|
public:
|
|
|
|
|
virtual void OnRttUpdate(int64_t rtt) = 0;
|
|
|
|
|
|
|
|
|
|
virtual int64_t LastProcessedRtt() const = 0;
|
|
|
|
|
|
2015-12-10 09:51:54 -08:00
|
|
|
virtual ~RtcpRttStats() {}
|
2015-11-04 08:31:52 +01:00
|
|
|
};
|
|
|
|
|
|
2017-12-15 14:40:10 +01:00
|
|
|
struct RtpPacketCounter {
|
|
|
|
|
RtpPacketCounter()
|
|
|
|
|
: header_bytes(0), payload_bytes(0), padding_bytes(0), packets(0) {}
|
|
|
|
|
|
2020-06-29 13:56:15 +02:00
|
|
|
explicit RtpPacketCounter(const RtpPacket& packet);
|
|
|
|
|
|
2017-12-15 14:40:10 +01:00
|
|
|
void Add(const RtpPacketCounter& other) {
|
|
|
|
|
header_bytes += other.header_bytes;
|
|
|
|
|
payload_bytes += other.payload_bytes;
|
|
|
|
|
padding_bytes += other.padding_bytes;
|
|
|
|
|
packets += other.packets;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Subtract(const RtpPacketCounter& other) {
|
|
|
|
|
RTC_DCHECK_GE(header_bytes, other.header_bytes);
|
|
|
|
|
header_bytes -= other.header_bytes;
|
|
|
|
|
RTC_DCHECK_GE(payload_bytes, other.payload_bytes);
|
|
|
|
|
payload_bytes -= other.payload_bytes;
|
|
|
|
|
RTC_DCHECK_GE(padding_bytes, other.padding_bytes);
|
|
|
|
|
padding_bytes -= other.padding_bytes;
|
|
|
|
|
RTC_DCHECK_GE(packets, other.packets);
|
|
|
|
|
packets -= other.packets;
|
|
|
|
|
}
|
|
|
|
|
|
[Stats] Explicit RTP-RTX and RTP-FEC mappings. Unblocks simulcast stats.
--- Background ---
The webrtc::VideoSendStream::StreamStats are converted into
VideoSenderInfo objects which turn into "outbound-rtp" stats objects in
getStats() (or "ssrc" objects in legacy getStats()).
StreamStats are created for each type of substream: RTP media streams,
RTX streams and FlexFEC streams - each with individual packet counters.
The RTX stream is responsible for retransmissions of a referenced media
stream and the FlexFEC stream is responsible for FEC of a referenced
media stream. RTX/FEC streams do not show up as separate objects in
getStats(). Only the media streams become "outbound-rtp" objects, but
their packet and byte counters have to include the RTX and FEC counters.
--- Overview of this CL ---
This CL adds MergeInfoAboutOutboundRtpSubstreams(). It takes
StreamStats of all kinds as input, and outputs media-only StreamStats
- incorporating the RTX and FEC counters into the relevant media
StreamStats.
The merged StreamStats objects is a smaller set of objects than the
non-merged counterparts, but when aggregating all packet counters
together we end up with exact same packet and count as before.
Because WebRtcVideoSendStream::GetVideoSenderInfo() currently aggregates
the StreamStats into a single VideoSenderInfo (single "outbound-rtp"),
this CL should not have any observable side-effects. Prior to this CL:
aggregate StreamStats. After this CL: merge StreamStats and then
aggregate them.
However, when simulcast stats are implemented (WIP CL:
https://webrtc-review.googlesource.com/c/src/+/168120) each RTP media
stream should turn into an individual "outbound-rtp" object. We will
then no longer aggregate all StreamStats into a single "info". This CL
unblocks simulcast stats by providing StreamStats objects that could be
turned into individual VideoSenderInfos.
--- The Changes ---
1. Methods added to RtpConfig to be able to easily tell the relationship
between RTP, RTX and FEC ssrcs.
2. StreamStats gets a StreamType (kMedia, kRtx or kFlexfec) that
replaces the booleans (is_rtx, is_flexfec).
3. "referenced_media_ssrc" is added to StreamStats, making it possible
to tell which kRtx/kFlexFec stream stats need to be merged with which
kMedia StreamStats.
4. MergeInfoAboutOutboundRtpSubstreams() added and used.
Bug: webrtc:11439
Change-Id: Iaf9002041169a054ddfd32c7ea06bd1dc36c6bca
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/170826
Commit-Queue: Henrik Boström <hbos@webrtc.org>
Reviewed-by: Ilya Nikolaevskiy <ilnik@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Reviewed-by: Stefan Holmer <stefan@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#30869}
2020-03-24 13:30:50 +01:00
|
|
|
bool operator==(const RtpPacketCounter& other) const {
|
|
|
|
|
return header_bytes == other.header_bytes &&
|
|
|
|
|
payload_bytes == other.payload_bytes &&
|
|
|
|
|
padding_bytes == other.padding_bytes && packets == other.packets;
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-15 08:05:16 +01:00
|
|
|
// Not inlined, since use of RtpPacket would result in circular includes.
|
|
|
|
|
void AddPacket(const RtpPacket& packet);
|
2017-12-15 14:40:10 +01:00
|
|
|
|
|
|
|
|
size_t TotalBytes() const {
|
|
|
|
|
return header_bytes + payload_bytes + padding_bytes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t header_bytes; // Number of bytes used by RTP headers.
|
|
|
|
|
size_t payload_bytes; // Payload bytes, excluding RTP headers and padding.
|
|
|
|
|
size_t padding_bytes; // Number of padding bytes.
|
|
|
|
|
uint32_t packets; // Number of packets.
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Data usage statistics for a (rtp) stream.
|
|
|
|
|
struct StreamDataCounters {
|
|
|
|
|
StreamDataCounters();
|
|
|
|
|
|
|
|
|
|
void Add(const StreamDataCounters& other) {
|
|
|
|
|
transmitted.Add(other.transmitted);
|
|
|
|
|
retransmitted.Add(other.retransmitted);
|
|
|
|
|
fec.Add(other.fec);
|
|
|
|
|
if (other.first_packet_time_ms != -1 &&
|
|
|
|
|
(other.first_packet_time_ms < first_packet_time_ms ||
|
|
|
|
|
first_packet_time_ms == -1)) {
|
|
|
|
|
// Use oldest time.
|
|
|
|
|
first_packet_time_ms = other.first_packet_time_ms;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Subtract(const StreamDataCounters& other) {
|
|
|
|
|
transmitted.Subtract(other.transmitted);
|
|
|
|
|
retransmitted.Subtract(other.retransmitted);
|
|
|
|
|
fec.Subtract(other.fec);
|
|
|
|
|
if (other.first_packet_time_ms != -1 &&
|
|
|
|
|
(other.first_packet_time_ms > first_packet_time_ms ||
|
|
|
|
|
first_packet_time_ms == -1)) {
|
|
|
|
|
// Use youngest time.
|
|
|
|
|
first_packet_time_ms = other.first_packet_time_ms;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int64_t TimeSinceFirstPacketInMs(int64_t now_ms) const {
|
|
|
|
|
return (first_packet_time_ms == -1) ? -1 : (now_ms - first_packet_time_ms);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Returns the number of bytes corresponding to the actual media payload (i.e.
|
|
|
|
|
// RTP headers, padding, retransmissions and fec packets are excluded).
|
|
|
|
|
// Note this function does not have meaning for an RTX stream.
|
|
|
|
|
size_t MediaPayloadBytes() const {
|
|
|
|
|
return transmitted.payload_bytes - retransmitted.payload_bytes -
|
|
|
|
|
fec.payload_bytes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int64_t first_packet_time_ms; // Time when first packet is sent/received.
|
2019-04-02 15:11:48 +02:00
|
|
|
// The timestamp at which the last packet was received, i.e. the time of the
|
|
|
|
|
// local clock when it was received - not the RTP timestamp of that packet.
|
|
|
|
|
// https://w3c.github.io/webrtc-stats/#dom-rtcinboundrtpstreamstats-lastpacketreceivedtimestamp
|
|
|
|
|
absl::optional<int64_t> last_packet_received_timestamp_ms;
|
2017-12-15 14:40:10 +01:00
|
|
|
RtpPacketCounter transmitted; // Number of transmitted packets/bytes.
|
|
|
|
|
RtpPacketCounter retransmitted; // Number of retransmitted packets/bytes.
|
|
|
|
|
RtpPacketCounter fec; // Number of redundancy packets/bytes.
|
|
|
|
|
};
|
|
|
|
|
|
2020-05-11 18:22:02 +02:00
|
|
|
class RtpSendRates {
|
|
|
|
|
template <std::size_t... Is>
|
|
|
|
|
constexpr std::array<DataRate, sizeof...(Is)> make_zero_array(
|
|
|
|
|
std::index_sequence<Is...>) {
|
|
|
|
|
return {{(static_cast<void>(Is), DataRate::Zero())...}};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
RtpSendRates()
|
|
|
|
|
: send_rates_(
|
|
|
|
|
make_zero_array(std::make_index_sequence<kNumMediaTypes>())) {}
|
|
|
|
|
RtpSendRates(const RtpSendRates& rhs) = default;
|
|
|
|
|
RtpSendRates& operator=(const RtpSendRates&) = default;
|
|
|
|
|
|
|
|
|
|
DataRate& operator[](RtpPacketMediaType type) {
|
|
|
|
|
return send_rates_[static_cast<size_t>(type)];
|
|
|
|
|
}
|
|
|
|
|
const DataRate& operator[](RtpPacketMediaType type) const {
|
|
|
|
|
return send_rates_[static_cast<size_t>(type)];
|
|
|
|
|
}
|
|
|
|
|
DataRate Sum() const {
|
|
|
|
|
return absl::c_accumulate(send_rates_, DataRate::Zero());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
std::array<DataRate, kNumMediaTypes> send_rates_;
|
|
|
|
|
};
|
|
|
|
|
|
2017-12-15 14:40:10 +01:00
|
|
|
// Callback, called whenever byte/packet counts have been updated.
|
|
|
|
|
class StreamDataCountersCallback {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~StreamDataCountersCallback() {}
|
|
|
|
|
|
|
|
|
|
virtual void DataCountersUpdated(const StreamDataCounters& counters,
|
|
|
|
|
uint32_t ssrc) = 0;
|
|
|
|
|
};
|
|
|
|
|
|
2019-08-22 09:40:25 +02:00
|
|
|
// Information exposed through the GetStats api.
|
|
|
|
|
struct RtpReceiveStats {
|
2021-07-28 23:57:33 +02:00
|
|
|
// `packets_lost` and `jitter` are defined by RFC 3550, and exposed in the
|
2019-08-22 09:40:25 +02:00
|
|
|
// RTCReceivedRtpStreamStats dictionary, see
|
|
|
|
|
// https://w3c.github.io/webrtc-stats/#receivedrtpstats-dict*
|
|
|
|
|
int32_t packets_lost = 0;
|
|
|
|
|
uint32_t jitter = 0;
|
|
|
|
|
|
|
|
|
|
// Timestamp and counters exposed in RTCInboundRtpStreamStats, see
|
|
|
|
|
// https://w3c.github.io/webrtc-stats/#inboundrtpstats-dict*
|
|
|
|
|
absl::optional<int64_t> last_packet_received_timestamp_ms;
|
|
|
|
|
RtpPacketCounter packet_counter;
|
|
|
|
|
};
|
|
|
|
|
|
2019-05-07 14:39:05 +02:00
|
|
|
// Callback, used to notify an observer whenever new rates have been estimated.
|
|
|
|
|
class BitrateStatisticsObserver {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~BitrateStatisticsObserver() {}
|
|
|
|
|
|
|
|
|
|
virtual void Notify(uint32_t total_bitrate_bps,
|
|
|
|
|
uint32_t retransmit_bitrate_bps,
|
|
|
|
|
uint32_t ssrc) = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Callback, used to notify an observer whenever the send-side delay is updated.
|
|
|
|
|
class SendSideDelayObserver {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~SendSideDelayObserver() {}
|
|
|
|
|
virtual void SendSideDelayUpdated(int avg_delay_ms,
|
|
|
|
|
int max_delay_ms,
|
2019-05-16 18:38:20 +02:00
|
|
|
uint64_t total_delay_ms,
|
2019-05-07 14:39:05 +02:00
|
|
|
uint32_t ssrc) = 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Callback, used to notify an observer whenever a packet is sent to the
|
|
|
|
|
// transport.
|
|
|
|
|
// TODO(asapersson): This class will remove the need for SendSideDelayObserver.
|
|
|
|
|
// Remove SendSideDelayObserver once possible.
|
|
|
|
|
class SendPacketObserver {
|
|
|
|
|
public:
|
|
|
|
|
virtual ~SendPacketObserver() {}
|
|
|
|
|
virtual void OnSendPacket(uint16_t packet_id,
|
|
|
|
|
int64_t capture_time_ms,
|
|
|
|
|
uint32_t ssrc) = 0;
|
|
|
|
|
};
|
2020-07-02 17:41:32 +02:00
|
|
|
|
2015-11-04 08:31:52 +01:00
|
|
|
} // namespace webrtc
|
2017-09-15 06:47:31 +02:00
|
|
|
#endif // MODULES_RTP_RTCP_INCLUDE_RTP_RTCP_DEFINES_H_
|