2017-10-24 17:07:05 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2017 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_IMPL_H_
|
|
|
|
|
#define MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_IMPL_H_
|
|
|
|
|
|
2022-02-14 15:24:30 +01:00
|
|
|
#include <list>
|
2017-10-24 17:07:05 +02:00
|
|
|
#include <memory>
|
2024-08-29 13:00:40 +00:00
|
|
|
#include <optional>
|
2017-10-24 17:07:05 +02:00
|
|
|
#include <string>
|
2017-11-09 15:42:28 +01:00
|
|
|
#include <vector>
|
2017-10-24 17:07:05 +02:00
|
|
|
|
|
|
|
|
#include "api/array_view.h"
|
2021-05-21 18:08:04 +02:00
|
|
|
#include "api/units/timestamp.h"
|
2017-11-09 15:42:28 +01:00
|
|
|
#include "modules/rtp_rtcp/source/rtcp_packet/common_header.h"
|
2017-12-13 12:26:17 +01:00
|
|
|
#include "modules/rtp_rtcp/source/rtcp_packet/dlrr.h"
|
2017-11-13 13:46:02 +01:00
|
|
|
#include "modules/rtp_rtcp/source/rtcp_packet/remb.h"
|
2017-11-09 15:42:28 +01:00
|
|
|
#include "modules/rtp_rtcp/source/rtcp_packet/report_block.h"
|
2017-12-13 12:26:17 +01:00
|
|
|
#include "modules/rtp_rtcp/source/rtcp_packet/target_bitrate.h"
|
2017-10-24 17:07:05 +02:00
|
|
|
#include "modules/rtp_rtcp/source/rtcp_transceiver_config.h"
|
2021-09-20 20:47:26 +02:00
|
|
|
#include "rtc_base/containers/flat_map.h"
|
2019-01-18 10:30:54 +01:00
|
|
|
#include "rtc_base/task_utils/repeating_task.h"
|
2017-11-09 15:42:28 +01:00
|
|
|
#include "system_wrappers/include/ntp_time.h"
|
2017-10-24 17:07:05 +02:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
//
|
|
|
|
|
// Manage incoming and outgoing rtcp messages for multiple BUNDLED streams.
|
|
|
|
|
//
|
|
|
|
|
// This class is not thread-safe.
|
|
|
|
|
class RtcpTransceiverImpl {
|
|
|
|
|
public:
|
|
|
|
|
explicit RtcpTransceiverImpl(const RtcpTransceiverConfig& config);
|
2018-09-10 09:59:51 +02:00
|
|
|
RtcpTransceiverImpl(const RtcpTransceiverImpl&) = delete;
|
|
|
|
|
RtcpTransceiverImpl& operator=(const RtcpTransceiverImpl&) = delete;
|
2017-10-24 17:07:05 +02:00
|
|
|
~RtcpTransceiverImpl();
|
|
|
|
|
|
2019-03-07 11:15:14 +01:00
|
|
|
void StopPeriodicTask() { periodic_task_handle_.Stop(); }
|
|
|
|
|
|
2017-12-14 17:28:27 +01:00
|
|
|
void AddMediaReceiverRtcpObserver(uint32_t remote_ssrc,
|
|
|
|
|
MediaReceiverRtcpObserver* observer);
|
|
|
|
|
void RemoveMediaReceiverRtcpObserver(uint32_t remote_ssrc,
|
|
|
|
|
MediaReceiverRtcpObserver* observer);
|
2017-12-13 12:26:17 +01:00
|
|
|
|
2022-02-14 15:24:30 +01:00
|
|
|
// Returns false on failure, e.g. when there is already an handler for the
|
|
|
|
|
// `local_ssrc`.
|
|
|
|
|
bool AddMediaSender(uint32_t local_ssrc, RtpStreamRtcpHandler* handler);
|
|
|
|
|
bool RemoveMediaSender(uint32_t local_ssrc);
|
|
|
|
|
|
2018-03-06 14:33:20 +01:00
|
|
|
void SetReadyToSend(bool ready);
|
|
|
|
|
|
2021-05-21 18:08:04 +02:00
|
|
|
void ReceivePacket(rtc::ArrayView<const uint8_t> packet, Timestamp now);
|
2017-11-09 15:42:28 +01:00
|
|
|
|
2017-10-24 17:07:05 +02:00
|
|
|
void SendCompoundPacket();
|
|
|
|
|
|
2017-12-13 13:35:10 +01:00
|
|
|
void SetRemb(int64_t bitrate_bps, std::vector<uint32_t> ssrcs);
|
2017-11-13 13:46:02 +01:00
|
|
|
void UnsetRemb();
|
|
|
|
|
|
2017-11-27 17:23:04 +01:00
|
|
|
void SendNack(uint32_t ssrc, std::vector<uint16_t> sequence_numbers);
|
|
|
|
|
|
2017-11-28 19:53:33 +01:00
|
|
|
void SendPictureLossIndication(uint32_t ssrc);
|
2019-12-04 13:50:28 +01:00
|
|
|
// If new_request is true then requested sequence no. will increase for each
|
|
|
|
|
// requested ssrc.
|
|
|
|
|
void SendFullIntraRequest(rtc::ArrayView<const uint32_t> ssrcs,
|
|
|
|
|
bool new_request);
|
2017-11-21 11:08:53 +01:00
|
|
|
|
2019-10-10 12:57:28 +02:00
|
|
|
// SendCombinedRtcpPacket ignores rtcp mode and does not send a compound
|
|
|
|
|
// message. https://tools.ietf.org/html/rfc4585#section-3.1
|
|
|
|
|
void SendCombinedRtcpPacket(
|
|
|
|
|
std::vector<std::unique_ptr<rtcp::RtcpPacket>> rtcp_packets);
|
|
|
|
|
|
2017-10-24 17:07:05 +02:00
|
|
|
private:
|
2017-11-21 11:08:53 +01:00
|
|
|
class PacketSender;
|
2017-11-22 14:00:41 +01:00
|
|
|
struct RemoteSenderState;
|
2022-02-14 15:24:30 +01:00
|
|
|
struct LocalSenderState;
|
2022-02-21 13:23:06 +01:00
|
|
|
struct RrtrTimes {
|
|
|
|
|
// Received remote NTP timestamp in compact representation.
|
|
|
|
|
uint32_t received_remote_mid_ntp_time;
|
|
|
|
|
|
|
|
|
|
// Local NTP time when the report was received in compact representation.
|
|
|
|
|
uint32_t local_receive_mid_ntp_time;
|
|
|
|
|
};
|
2017-11-09 15:42:28 +01:00
|
|
|
|
2017-11-16 14:35:32 +01:00
|
|
|
void HandleReceivedPacket(const rtcp::CommonHeader& rtcp_packet_header,
|
2021-08-30 14:42:58 +02:00
|
|
|
Timestamp now,
|
2023-05-08 10:54:14 +02:00
|
|
|
std::vector<ReportBlockData>& report_blocks);
|
2017-12-13 12:26:17 +01:00
|
|
|
// Individual rtcp packet handlers.
|
|
|
|
|
void HandleBye(const rtcp::CommonHeader& rtcp_packet_header);
|
2017-11-30 14:56:52 +01:00
|
|
|
void HandleSenderReport(const rtcp::CommonHeader& rtcp_packet_header,
|
2021-08-30 14:42:58 +02:00
|
|
|
Timestamp now,
|
2023-05-08 10:54:14 +02:00
|
|
|
std::vector<ReportBlockData>& report_blocks);
|
2021-08-30 14:42:58 +02:00
|
|
|
void HandleReceiverReport(const rtcp::CommonHeader& rtcp_packet_header,
|
2023-05-08 10:54:14 +02:00
|
|
|
Timestamp now,
|
|
|
|
|
std::vector<ReportBlockData>& report_blocks);
|
|
|
|
|
void HandleReportBlocks(
|
2022-03-31 14:43:56 +02:00
|
|
|
uint32_t sender_ssrc,
|
2023-05-08 10:54:14 +02:00
|
|
|
Timestamp now,
|
|
|
|
|
rtc::ArrayView<const rtcp::ReportBlock> rtcp_report_blocks,
|
|
|
|
|
std::vector<ReportBlockData>& report_blocks);
|
2021-08-30 14:42:58 +02:00
|
|
|
void HandlePayloadSpecificFeedback(
|
|
|
|
|
const rtcp::CommonHeader& rtcp_packet_header,
|
|
|
|
|
Timestamp now);
|
|
|
|
|
void HandleRtpFeedback(const rtcp::CommonHeader& rtcp_packet_header,
|
|
|
|
|
Timestamp now);
|
2022-03-25 14:56:03 +01:00
|
|
|
void HandleFir(const rtcp::CommonHeader& rtcp_packet_header);
|
2022-03-18 17:48:57 +01:00
|
|
|
void HandlePli(const rtcp::CommonHeader& rtcp_packet_header);
|
|
|
|
|
void HandleRemb(const rtcp::CommonHeader& rtcp_packet_header, Timestamp now);
|
2022-03-18 14:49:12 +01:00
|
|
|
void HandleNack(const rtcp::CommonHeader& rtcp_packet_header);
|
|
|
|
|
void HandleTransportFeedback(const rtcp::CommonHeader& rtcp_packet_header,
|
|
|
|
|
Timestamp now);
|
2024-12-03 15:54:58 +00:00
|
|
|
void HandleCongestionControlFeedback(
|
|
|
|
|
const rtcp::CommonHeader& rtcp_packet_header,
|
|
|
|
|
Timestamp now);
|
2017-11-30 14:56:52 +01:00
|
|
|
void HandleExtendedReports(const rtcp::CommonHeader& rtcp_packet_header,
|
2021-05-21 18:08:04 +02:00
|
|
|
Timestamp now);
|
2017-12-13 12:26:17 +01:00
|
|
|
// Extended Reports blocks handlers.
|
2021-05-21 18:08:04 +02:00
|
|
|
void HandleDlrr(const rtcp::Dlrr& dlrr, Timestamp now);
|
2017-12-13 12:26:17 +01:00
|
|
|
void HandleTargetBitrate(const rtcp::TargetBitrate& target_bitrate,
|
|
|
|
|
uint32_t remote_ssrc);
|
2023-05-09 10:11:21 +02:00
|
|
|
void ProcessReportBlocks(Timestamp now,
|
|
|
|
|
rtc::ArrayView<const ReportBlockData> report_blocks);
|
2017-11-09 15:42:28 +01:00
|
|
|
|
2017-11-21 11:08:53 +01:00
|
|
|
void ReschedulePeriodicCompoundPackets();
|
2022-02-23 20:15:20 +01:00
|
|
|
void SchedulePeriodicCompoundPackets(TimeDelta delay);
|
2022-02-14 15:24:30 +01:00
|
|
|
// Appends RTCP sender and receiver reports to the `sender`.
|
|
|
|
|
// Both sender and receiver reports may have attached report blocks.
|
2022-04-04 13:28:08 +02:00
|
|
|
// Uses up to `config_.max_packet_size - reserved_bytes.per_packet`
|
|
|
|
|
// Returns list of sender ssrc in sender reports.
|
|
|
|
|
struct ReservedBytes {
|
|
|
|
|
size_t per_packet = 0;
|
|
|
|
|
size_t per_sender = 0;
|
2022-02-14 15:24:30 +01:00
|
|
|
};
|
2022-04-04 13:28:08 +02:00
|
|
|
std::vector<uint32_t> FillReports(Timestamp now,
|
|
|
|
|
ReservedBytes reserved_bytes,
|
|
|
|
|
PacketSender& rtcp_sender);
|
2022-02-04 16:27:30 +01:00
|
|
|
|
2017-11-21 11:08:53 +01:00
|
|
|
// Creates compound RTCP packet, as defined in
|
|
|
|
|
// https://tools.ietf.org/html/rfc5506#section-2
|
2022-02-04 16:27:30 +01:00
|
|
|
void CreateCompoundPacket(Timestamp now,
|
|
|
|
|
size_t reserved_bytes,
|
|
|
|
|
PacketSender& rtcp_sender);
|
|
|
|
|
|
2017-10-30 15:21:41 +01:00
|
|
|
// Sends RTCP packets.
|
2017-11-21 11:08:53 +01:00
|
|
|
void SendPeriodicCompoundPacket();
|
2017-11-28 19:53:33 +01:00
|
|
|
void SendImmediateFeedback(const rtcp::RtcpPacket& rtcp_packet);
|
2022-02-04 16:27:30 +01:00
|
|
|
// Generate Report Blocks to be send in Sender or Receiver Reports.
|
|
|
|
|
std::vector<rtcp::ReportBlock> CreateReportBlocks(Timestamp now,
|
|
|
|
|
size_t num_max_blocks);
|
2017-10-30 15:21:41 +01:00
|
|
|
|
2017-10-24 17:07:05 +02:00
|
|
|
const RtcpTransceiverConfig config_;
|
2023-05-24 15:49:23 +02:00
|
|
|
std::function<void(rtc::ArrayView<const uint8_t>)> rtcp_transport_;
|
2017-10-24 17:07:05 +02:00
|
|
|
|
2018-03-06 14:33:20 +01:00
|
|
|
bool ready_to_send_;
|
2024-08-29 13:00:40 +00:00
|
|
|
std::optional<rtcp::Remb> remb_;
|
2023-03-06 17:44:30 +01:00
|
|
|
// TODO(bugs.webrtc.org/8239): Remove entries from remote_senders_ that are no
|
|
|
|
|
// longer needed.
|
2021-09-20 20:47:26 +02:00
|
|
|
flat_map<uint32_t, RemoteSenderState> remote_senders_;
|
2022-02-14 15:24:30 +01:00
|
|
|
std::list<LocalSenderState> local_senders_;
|
|
|
|
|
flat_map<uint32_t, std::list<LocalSenderState>::iterator>
|
|
|
|
|
local_senders_by_ssrc_;
|
2022-02-21 13:23:06 +01:00
|
|
|
flat_map<uint32_t, RrtrTimes> received_rrtrs_;
|
2019-01-18 10:30:54 +01:00
|
|
|
RepeatingTaskHandle periodic_task_handle_;
|
2017-10-24 17:07:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|
|
|
|
|
|
|
|
|
|
#endif // MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_IMPL_H_
|