Tomas Gunnarsson | f25761d | 2020-06-03 22:55:33 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2020 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #ifndef MODULES_RTP_RTCP_SOURCE_RTP_RTCP_INTERFACE_H_ |
| 12 | #define MODULES_RTP_RTCP_SOURCE_RTP_RTCP_INTERFACE_H_ |
| 13 | |
| 14 | #include <memory> |
| 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
| 18 | #include "absl/types/optional.h" |
| 19 | #include "api/frame_transformer_interface.h" |
| 20 | #include "api/scoped_refptr.h" |
| 21 | #include "api/transport/webrtc_key_value_config.h" |
| 22 | #include "api/video/video_bitrate_allocation.h" |
| 23 | #include "modules/rtp_rtcp/include/receive_statistics.h" |
| 24 | #include "modules/rtp_rtcp/include/report_block_data.h" |
| 25 | #include "modules/rtp_rtcp/include/rtp_packet_sender.h" |
| 26 | #include "modules/rtp_rtcp/include/rtp_rtcp_defines.h" |
| 27 | #include "modules/rtp_rtcp/source/rtp_packet_to_send.h" |
| 28 | #include "modules/rtp_rtcp/source/rtp_sequence_number_map.h" |
| 29 | #include "modules/rtp_rtcp/source/video_fec_generator.h" |
| 30 | #include "rtc_base/constructor_magic.h" |
| 31 | |
| 32 | namespace webrtc { |
| 33 | |
| 34 | // Forward declarations. |
| 35 | class FrameEncryptorInterface; |
| 36 | class RateLimiter; |
| 37 | class RemoteBitrateEstimator; |
| 38 | class RtcEventLog; |
| 39 | class RTPSender; |
| 40 | class Transport; |
| 41 | class VideoBitrateAllocationObserver; |
| 42 | |
| 43 | class RtpRtcpInterface : public RtcpFeedbackSenderInterface { |
| 44 | public: |
| 45 | struct Configuration { |
| 46 | Configuration() = default; |
| 47 | Configuration(Configuration&& rhs) = default; |
| 48 | |
| 49 | // True for a audio version of the RTP/RTCP module object false will create |
| 50 | // a video version. |
| 51 | bool audio = false; |
| 52 | bool receiver_only = false; |
| 53 | |
| 54 | // The clock to use to read time. If nullptr then system clock will be used. |
| 55 | Clock* clock = nullptr; |
| 56 | |
| 57 | ReceiveStatisticsProvider* receive_statistics = nullptr; |
| 58 | |
| 59 | // Transport object that will be called when packets are ready to be sent |
| 60 | // out on the network. |
| 61 | Transport* outgoing_transport = nullptr; |
| 62 | |
| 63 | // Called when the receiver requests an intra frame. |
| 64 | RtcpIntraFrameObserver* intra_frame_callback = nullptr; |
| 65 | |
| 66 | // Called when the receiver sends a loss notification. |
| 67 | RtcpLossNotificationObserver* rtcp_loss_notification_observer = nullptr; |
| 68 | |
| 69 | // Called when we receive a changed estimate from the receiver of out |
| 70 | // stream. |
| 71 | RtcpBandwidthObserver* bandwidth_callback = nullptr; |
| 72 | |
| 73 | NetworkStateEstimateObserver* network_state_estimate_observer = nullptr; |
| 74 | TransportFeedbackObserver* transport_feedback_callback = nullptr; |
| 75 | VideoBitrateAllocationObserver* bitrate_allocation_observer = nullptr; |
| 76 | RtcpRttStats* rtt_stats = nullptr; |
| 77 | RtcpPacketTypeCounterObserver* rtcp_packet_type_counter_observer = nullptr; |
| 78 | // Called on receipt of RTCP report block from remote side. |
| 79 | // TODO(bugs.webrtc.org/10678): Remove RtcpStatisticsCallback in |
| 80 | // favor of ReportBlockDataObserver. |
| 81 | // TODO(bugs.webrtc.org/10679): Consider whether we want to use |
| 82 | // only getters or only callbacks. If we decide on getters, the |
| 83 | // ReportBlockDataObserver should also be removed in favor of |
| 84 | // GetLatestReportBlockData(). |
| 85 | RtcpStatisticsCallback* rtcp_statistics_callback = nullptr; |
| 86 | RtcpCnameCallback* rtcp_cname_callback = nullptr; |
| 87 | ReportBlockDataObserver* report_block_data_observer = nullptr; |
| 88 | |
| 89 | // Estimates the bandwidth available for a set of streams from the same |
| 90 | // client. |
| 91 | RemoteBitrateEstimator* remote_bitrate_estimator = nullptr; |
| 92 | |
| 93 | // Spread any bursts of packets into smaller bursts to minimize packet loss. |
| 94 | RtpPacketSender* paced_sender = nullptr; |
| 95 | |
| 96 | // Generates FEC packets. |
| 97 | // TODO(sprang): Wire up to RtpSenderEgress. |
| 98 | VideoFecGenerator* fec_generator = nullptr; |
| 99 | |
| 100 | BitrateStatisticsObserver* send_bitrate_observer = nullptr; |
| 101 | SendSideDelayObserver* send_side_delay_observer = nullptr; |
| 102 | RtcEventLog* event_log = nullptr; |
| 103 | SendPacketObserver* send_packet_observer = nullptr; |
| 104 | RateLimiter* retransmission_rate_limiter = nullptr; |
| 105 | StreamDataCountersCallback* rtp_stats_callback = nullptr; |
| 106 | |
| 107 | int rtcp_report_interval_ms = 0; |
| 108 | |
| 109 | // Update network2 instead of pacer_exit field of video timing extension. |
| 110 | bool populate_network2_timestamp = false; |
| 111 | |
| 112 | rtc::scoped_refptr<FrameTransformerInterface> frame_transformer; |
| 113 | |
| 114 | // E2EE Custom Video Frame Encryption |
| 115 | FrameEncryptorInterface* frame_encryptor = nullptr; |
| 116 | // Require all outgoing frames to be encrypted with a FrameEncryptor. |
| 117 | bool require_frame_encryption = false; |
| 118 | |
| 119 | // Corresponds to extmap-allow-mixed in SDP negotiation. |
| 120 | bool extmap_allow_mixed = false; |
| 121 | |
| 122 | // If true, the RTP sender will always annotate outgoing packets with |
| 123 | // MID and RID header extensions, if provided and negotiated. |
| 124 | // If false, the RTP sender will stop sending MID and RID header extensions, |
| 125 | // when it knows that the receiver is ready to demux based on SSRC. This is |
| 126 | // done by RTCP RR acking. |
| 127 | bool always_send_mid_and_rid = false; |
| 128 | |
| 129 | // If set, field trials are read from |field_trials|, otherwise |
| 130 | // defaults to webrtc::FieldTrialBasedConfig. |
| 131 | const WebRtcKeyValueConfig* field_trials = nullptr; |
| 132 | |
| 133 | // SSRCs for media and retransmission, respectively. |
| 134 | // FlexFec SSRC is fetched from |flexfec_sender|. |
| 135 | uint32_t local_media_ssrc = 0; |
| 136 | absl::optional<uint32_t> rtx_send_ssrc; |
| 137 | |
| 138 | bool need_rtp_packet_infos = false; |
| 139 | |
| 140 | // If true, the RTP packet history will select RTX packets based on |
| 141 | // heuristics such as send time, retransmission count etc, in order to |
| 142 | // make padding potentially more useful. |
| 143 | // If false, the last packet will always be picked. This may reduce CPU |
| 144 | // overhead. |
| 145 | bool enable_rtx_padding_prioritization = true; |
| 146 | |
Niels Möller | be810cb | 2020-12-02 14:25:03 +0100 | [diff] [blame] | 147 | // Estimate RTT as non-sender as described in |
| 148 | // https://tools.ietf.org/html/rfc3611#section-4.4 and #section-4.5 |
| 149 | bool non_sender_rtt_measurement = false; |
| 150 | |
Tomas Gunnarsson | f25761d | 2020-06-03 22:55:33 +0200 | [diff] [blame] | 151 | private: |
| 152 | RTC_DISALLOW_COPY_AND_ASSIGN(Configuration); |
| 153 | }; |
| 154 | |
| 155 | // ************************************************************************** |
| 156 | // Receiver functions |
| 157 | // ************************************************************************** |
| 158 | |
| 159 | virtual void IncomingRtcpPacket(const uint8_t* incoming_packet, |
| 160 | size_t incoming_packet_length) = 0; |
| 161 | |
| 162 | virtual void SetRemoteSSRC(uint32_t ssrc) = 0; |
| 163 | |
| 164 | // ************************************************************************** |
| 165 | // Sender |
| 166 | // ************************************************************************** |
| 167 | |
| 168 | // Sets the maximum size of an RTP packet, including RTP headers. |
| 169 | virtual void SetMaxRtpPacketSize(size_t size) = 0; |
| 170 | |
| 171 | // Returns max RTP packet size. Takes into account RTP headers and |
| 172 | // FEC/ULP/RED overhead (when FEC is enabled). |
| 173 | virtual size_t MaxRtpPacketSize() const = 0; |
| 174 | |
| 175 | virtual void RegisterSendPayloadFrequency(int payload_type, |
| 176 | int payload_frequency) = 0; |
| 177 | |
| 178 | // Unregisters a send payload. |
| 179 | // |payload_type| - payload type of codec |
| 180 | // Returns -1 on failure else 0. |
| 181 | virtual int32_t DeRegisterSendPayload(int8_t payload_type) = 0; |
| 182 | |
| 183 | virtual void SetExtmapAllowMixed(bool extmap_allow_mixed) = 0; |
| 184 | |
| 185 | // Register extension by uri, triggers CHECK on falure. |
| 186 | virtual void RegisterRtpHeaderExtension(absl::string_view uri, int id) = 0; |
| 187 | |
| 188 | virtual int32_t DeregisterSendRtpHeaderExtension(RTPExtensionType type) = 0; |
| 189 | virtual void DeregisterSendRtpHeaderExtension(absl::string_view uri) = 0; |
| 190 | |
| 191 | // Returns true if RTP module is send media, and any of the extensions |
| 192 | // required for bandwidth estimation is registered. |
| 193 | virtual bool SupportsPadding() const = 0; |
| 194 | // Same as SupportsPadding(), but additionally requires that |
| 195 | // SetRtxSendStatus() has been called with the kRtxRedundantPayloads option |
| 196 | // enabled. |
| 197 | virtual bool SupportsRtxPayloadPadding() const = 0; |
| 198 | |
| 199 | // Returns start timestamp. |
| 200 | virtual uint32_t StartTimestamp() const = 0; |
| 201 | |
| 202 | // Sets start timestamp. Start timestamp is set to a random value if this |
| 203 | // function is never called. |
| 204 | virtual void SetStartTimestamp(uint32_t timestamp) = 0; |
| 205 | |
| 206 | // Returns SequenceNumber. |
| 207 | virtual uint16_t SequenceNumber() const = 0; |
| 208 | |
| 209 | // Sets SequenceNumber, default is a random number. |
| 210 | virtual void SetSequenceNumber(uint16_t seq) = 0; |
| 211 | |
| 212 | virtual void SetRtpState(const RtpState& rtp_state) = 0; |
| 213 | virtual void SetRtxState(const RtpState& rtp_state) = 0; |
| 214 | virtual RtpState GetRtpState() const = 0; |
| 215 | virtual RtpState GetRtxState() const = 0; |
| 216 | |
| 217 | // Returns SSRC. |
| 218 | virtual uint32_t SSRC() const = 0; |
| 219 | |
| 220 | // Sets the value for sending in the RID (and Repaired) RTP header extension. |
| 221 | // RIDs are used to identify an RTP stream if SSRCs are not negotiated. |
| 222 | // If the RID and Repaired RID extensions are not registered, the RID will |
| 223 | // not be sent. |
| 224 | virtual void SetRid(const std::string& rid) = 0; |
| 225 | |
| 226 | // Sets the value for sending in the MID RTP header extension. |
| 227 | // The MID RTP header extension should be registered for this to do anything. |
| 228 | // Once set, this value can not be changed or removed. |
| 229 | virtual void SetMid(const std::string& mid) = 0; |
| 230 | |
| 231 | // Sets CSRC. |
| 232 | // |csrcs| - vector of CSRCs |
| 233 | virtual void SetCsrcs(const std::vector<uint32_t>& csrcs) = 0; |
| 234 | |
| 235 | // Turns on/off sending RTX (RFC 4588). The modes can be set as a combination |
| 236 | // of values of the enumerator RtxMode. |
| 237 | virtual void SetRtxSendStatus(int modes) = 0; |
| 238 | |
| 239 | // Returns status of sending RTX (RFC 4588). The returned value can be |
| 240 | // a combination of values of the enumerator RtxMode. |
| 241 | virtual int RtxSendStatus() const = 0; |
| 242 | |
| 243 | // Returns the SSRC used for RTX if set, otherwise a nullopt. |
| 244 | virtual absl::optional<uint32_t> RtxSsrc() const = 0; |
| 245 | |
| 246 | // Sets the payload type to use when sending RTX packets. Note that this |
| 247 | // doesn't enable RTX, only the payload type is set. |
| 248 | virtual void SetRtxSendPayloadType(int payload_type, |
| 249 | int associated_payload_type) = 0; |
| 250 | |
| 251 | // Returns the FlexFEC SSRC, if there is one. |
| 252 | virtual absl::optional<uint32_t> FlexfecSsrc() const = 0; |
| 253 | |
| 254 | // Sets sending status. Sends kRtcpByeCode when going from true to false. |
| 255 | // Returns -1 on failure else 0. |
| 256 | virtual int32_t SetSendingStatus(bool sending) = 0; |
| 257 | |
| 258 | // Returns current sending status. |
| 259 | virtual bool Sending() const = 0; |
| 260 | |
| 261 | // Starts/Stops media packets. On by default. |
| 262 | virtual void SetSendingMediaStatus(bool sending) = 0; |
| 263 | |
| 264 | // Returns current media sending status. |
| 265 | virtual bool SendingMedia() const = 0; |
| 266 | |
| 267 | // Returns whether audio is configured (i.e. Configuration::audio = true). |
| 268 | virtual bool IsAudioConfigured() const = 0; |
| 269 | |
| 270 | // Indicate that the packets sent by this module should be counted towards the |
| 271 | // bitrate estimate since the stream participates in the bitrate allocation. |
| 272 | virtual void SetAsPartOfAllocation(bool part_of_allocation) = 0; |
| 273 | |
Tomas Gunnarsson | f25761d | 2020-06-03 22:55:33 +0200 | [diff] [blame] | 274 | // Returns bitrate sent (post-pacing) per packet type. |
| 275 | virtual RtpSendRates GetSendRates() const = 0; |
| 276 | |
| 277 | virtual RTPSender* RtpSender() = 0; |
| 278 | virtual const RTPSender* RtpSender() const = 0; |
| 279 | |
| 280 | // Record that a frame is about to be sent. Returns true on success, and false |
| 281 | // if the module isn't ready to send. |
| 282 | virtual bool OnSendingRtpFrame(uint32_t timestamp, |
| 283 | int64_t capture_time_ms, |
| 284 | int payload_type, |
| 285 | bool force_sender_report) = 0; |
| 286 | |
| 287 | // Try to send the provided packet. Returns true iff packet matches any of |
| 288 | // the SSRCs for this module (media/rtx/fec etc) and was forwarded to the |
| 289 | // transport. |
| 290 | virtual bool TrySendPacket(RtpPacketToSend* packet, |
| 291 | const PacedPacketInfo& pacing_info) = 0; |
| 292 | |
Erik Språng | 1d50cb6 | 2020-07-02 17:41:32 +0200 | [diff] [blame] | 293 | // Update the FEC protection parameters to use for delta- and key-frames. |
| 294 | // Only used when deferred FEC is active. |
| 295 | virtual void SetFecProtectionParams( |
| 296 | const FecProtectionParams& delta_params, |
| 297 | const FecProtectionParams& key_params) = 0; |
| 298 | |
| 299 | // If deferred FEC generation is enabled, this method should be called after |
| 300 | // calling TrySendPacket(). Any generated FEC packets will be removed and |
| 301 | // returned from the FEC generator. |
| 302 | virtual std::vector<std::unique_ptr<RtpPacketToSend>> FetchFecPackets() = 0; |
| 303 | |
Tomas Gunnarsson | f25761d | 2020-06-03 22:55:33 +0200 | [diff] [blame] | 304 | virtual void OnPacketsAcknowledged( |
| 305 | rtc::ArrayView<const uint16_t> sequence_numbers) = 0; |
| 306 | |
| 307 | virtual std::vector<std::unique_ptr<RtpPacketToSend>> GeneratePadding( |
| 308 | size_t target_size_bytes) = 0; |
| 309 | |
| 310 | virtual std::vector<RtpSequenceNumberMap::Info> GetSentRtpPacketInfos( |
| 311 | rtc::ArrayView<const uint16_t> sequence_numbers) const = 0; |
| 312 | |
| 313 | // Returns an expected per packet overhead representing the main RTP header, |
| 314 | // any CSRCs, and the registered header extensions that are expected on all |
| 315 | // packets (i.e. disregarding things like abs capture time which is only |
| 316 | // populated on a subset of packets, but counting MID/RID type extensions |
| 317 | // when we expect to send them). |
| 318 | virtual size_t ExpectedPerPacketOverhead() const = 0; |
| 319 | |
| 320 | // ************************************************************************** |
| 321 | // RTCP |
| 322 | // ************************************************************************** |
| 323 | |
| 324 | // Returns RTCP status. |
| 325 | virtual RtcpMode RTCP() const = 0; |
| 326 | |
| 327 | // Sets RTCP status i.e on(compound or non-compound)/off. |
| 328 | // |method| - RTCP method to use. |
| 329 | virtual void SetRTCPStatus(RtcpMode method) = 0; |
| 330 | |
| 331 | // Sets RTCP CName (i.e unique identifier). |
| 332 | // Returns -1 on failure else 0. |
| 333 | virtual int32_t SetCNAME(const char* cname) = 0; |
| 334 | |
Tomas Gunnarsson | f25761d | 2020-06-03 22:55:33 +0200 | [diff] [blame] | 335 | // Returns remote NTP. |
| 336 | // Returns -1 on failure else 0. |
| 337 | virtual int32_t RemoteNTP(uint32_t* received_ntp_secs, |
| 338 | uint32_t* received_ntp_frac, |
| 339 | uint32_t* rtcp_arrival_time_secs, |
| 340 | uint32_t* rtcp_arrival_time_frac, |
| 341 | uint32_t* rtcp_timestamp) const = 0; |
| 342 | |
Tomas Gunnarsson | f25761d | 2020-06-03 22:55:33 +0200 | [diff] [blame] | 343 | // Returns current RTT (round-trip time) estimate. |
| 344 | // Returns -1 on failure else 0. |
| 345 | virtual int32_t RTT(uint32_t remote_ssrc, |
| 346 | int64_t* rtt, |
| 347 | int64_t* avg_rtt, |
| 348 | int64_t* min_rtt, |
| 349 | int64_t* max_rtt) const = 0; |
| 350 | |
| 351 | // Returns the estimated RTT, with fallback to a default value. |
| 352 | virtual int64_t ExpectedRetransmissionTimeMs() const = 0; |
| 353 | |
| 354 | // Forces a send of a RTCP packet. Periodic SR and RR are triggered via the |
| 355 | // process function. |
| 356 | // Returns -1 on failure else 0. |
| 357 | virtual int32_t SendRTCP(RTCPPacketType rtcp_packet_type) = 0; |
| 358 | |
Tomas Gunnarsson | f25761d | 2020-06-03 22:55:33 +0200 | [diff] [blame] | 359 | // Returns send statistics for the RTP and RTX stream. |
| 360 | virtual void GetSendStreamDataCounters( |
| 361 | StreamDataCounters* rtp_counters, |
| 362 | StreamDataCounters* rtx_counters) const = 0; |
| 363 | |
| 364 | // Returns received RTCP report block. |
| 365 | // Returns -1 on failure else 0. |
| 366 | // TODO(https://crbug.com/webrtc/10678): Remove this in favor of |
| 367 | // GetLatestReportBlockData(). |
| 368 | virtual int32_t RemoteRTCPStat( |
| 369 | std::vector<RTCPReportBlock>* receive_blocks) const = 0; |
| 370 | // A snapshot of Report Blocks with additional data of interest to statistics. |
| 371 | // Within this list, the sender-source SSRC pair is unique and per-pair the |
| 372 | // ReportBlockData represents the latest Report Block that was received for |
| 373 | // that pair. |
| 374 | virtual std::vector<ReportBlockData> GetLatestReportBlockData() const = 0; |
| 375 | |
Tomas Gunnarsson | f25761d | 2020-06-03 22:55:33 +0200 | [diff] [blame] | 376 | // (REMB) Receiver Estimated Max Bitrate. |
| 377 | // Schedules sending REMB on next and following sender/receiver reports. |
| 378 | void SetRemb(int64_t bitrate_bps, std::vector<uint32_t> ssrcs) override = 0; |
| 379 | // Stops sending REMB on next and following sender/receiver reports. |
| 380 | void UnsetRemb() override = 0; |
| 381 | |
Tomas Gunnarsson | f25761d | 2020-06-03 22:55:33 +0200 | [diff] [blame] | 382 | // (NACK) |
| 383 | |
| 384 | // Sends a Negative acknowledgement packet. |
| 385 | // Returns -1 on failure else 0. |
| 386 | // TODO(philipel): Deprecate this and start using SendNack instead, mostly |
| 387 | // because we want a function that actually send NACK for the specified |
| 388 | // packets. |
| 389 | virtual int32_t SendNACK(const uint16_t* nack_list, uint16_t size) = 0; |
| 390 | |
| 391 | // Sends NACK for the packets specified. |
| 392 | // Note: This assumes the caller keeps track of timing and doesn't rely on |
| 393 | // the RTP module to do this. |
| 394 | virtual void SendNack(const std::vector<uint16_t>& sequence_numbers) = 0; |
| 395 | |
| 396 | // Store the sent packets, needed to answer to a Negative acknowledgment |
| 397 | // requests. |
| 398 | virtual void SetStorePacketsStatus(bool enable, uint16_t numberToStore) = 0; |
| 399 | |
Tomas Gunnarsson | f25761d | 2020-06-03 22:55:33 +0200 | [diff] [blame] | 400 | virtual void SetVideoBitrateAllocation( |
| 401 | const VideoBitrateAllocation& bitrate) = 0; |
| 402 | |
| 403 | // ************************************************************************** |
| 404 | // Video |
| 405 | // ************************************************************************** |
| 406 | |
| 407 | // Requests new key frame. |
| 408 | // using PLI, https://tools.ietf.org/html/rfc4585#section-6.3.1.1 |
| 409 | void SendPictureLossIndication() { SendRTCP(kRtcpPli); } |
| 410 | // using FIR, https://tools.ietf.org/html/rfc5104#section-4.3.1.2 |
| 411 | void SendFullIntraRequest() { SendRTCP(kRtcpFir); } |
| 412 | |
| 413 | // Sends a LossNotification RTCP message. |
| 414 | // Returns -1 on failure else 0. |
| 415 | virtual int32_t SendLossNotification(uint16_t last_decoded_seq_num, |
| 416 | uint16_t last_received_seq_num, |
| 417 | bool decodability_flag, |
| 418 | bool buffering_allowed) = 0; |
| 419 | }; |
| 420 | |
| 421 | } // namespace webrtc |
| 422 | |
| 423 | #endif // MODULES_RTP_RTCP_SOURCE_RTP_RTCP_INTERFACE_H_ |