blob: 8039f2b70fec23777202dd984a94ad6cb683648b [file] [log] [blame]
Danil Chapovalov398a7c62017-10-24 17:07:05 +02001/*
2 * Copyright (c) 2017 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_RTCP_TRANSCEIVER_IMPL_H_
12#define MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_IMPL_H_
13
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010014#include <map>
Danil Chapovalov398a7c62017-10-24 17:07:05 +020015#include <memory>
16#include <string>
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010017#include <vector>
Danil Chapovalov398a7c62017-10-24 17:07:05 +020018
Danil Chapovalovd264df52018-06-14 12:59:38 +020019#include "absl/types/optional.h"
Danil Chapovalov398a7c62017-10-24 17:07:05 +020020#include "api/array_view.h"
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010021#include "modules/rtp_rtcp/source/rtcp_packet/common_header.h"
Danil Chapovalov7ca9ae22017-12-13 12:26:17 +010022#include "modules/rtp_rtcp/source/rtcp_packet/dlrr.h"
Danil Chapovalovd3282292017-11-13 13:46:02 +010023#include "modules/rtp_rtcp/source/rtcp_packet/remb.h"
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010024#include "modules/rtp_rtcp/source/rtcp_packet/report_block.h"
Danil Chapovalov7ca9ae22017-12-13 12:26:17 +010025#include "modules/rtp_rtcp/source/rtcp_packet/target_bitrate.h"
Danil Chapovalov398a7c62017-10-24 17:07:05 +020026#include "modules/rtp_rtcp/source/rtcp_transceiver_config.h"
Sebastian Janssonecb68972019-01-18 10:30:54 +010027#include "rtc_base/task_utils/repeating_task.h"
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010028#include "system_wrappers/include/ntp_time.h"
Danil Chapovalov398a7c62017-10-24 17:07:05 +020029
30namespace webrtc {
31//
32// Manage incoming and outgoing rtcp messages for multiple BUNDLED streams.
33//
34// This class is not thread-safe.
35class RtcpTransceiverImpl {
36 public:
37 explicit RtcpTransceiverImpl(const RtcpTransceiverConfig& config);
Danil Chapovalov067818f2018-09-10 09:59:51 +020038 RtcpTransceiverImpl(const RtcpTransceiverImpl&) = delete;
39 RtcpTransceiverImpl& operator=(const RtcpTransceiverImpl&) = delete;
Danil Chapovalov398a7c62017-10-24 17:07:05 +020040 ~RtcpTransceiverImpl();
41
Danil Chapovalov6318f132019-03-07 11:15:14 +010042 void StopPeriodicTask() { periodic_task_handle_.Stop(); }
43
Danil Chapovalova32d7102017-12-14 17:28:27 +010044 void AddMediaReceiverRtcpObserver(uint32_t remote_ssrc,
45 MediaReceiverRtcpObserver* observer);
46 void RemoveMediaReceiverRtcpObserver(uint32_t remote_ssrc,
47 MediaReceiverRtcpObserver* observer);
Danil Chapovalov7ca9ae22017-12-13 12:26:17 +010048
Danil Chapovalove3927c52018-03-06 14:33:20 +010049 void SetReadyToSend(bool ready);
50
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010051 void ReceivePacket(rtc::ArrayView<const uint8_t> packet, int64_t now_us);
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010052
Danil Chapovalov398a7c62017-10-24 17:07:05 +020053 void SendCompoundPacket();
54
Danil Chapovalov1de4b622017-12-13 13:35:10 +010055 void SetRemb(int64_t bitrate_bps, std::vector<uint32_t> ssrcs);
Danil Chapovalovd3282292017-11-13 13:46:02 +010056 void UnsetRemb();
Danil Chapovalovd5cae4d2017-12-14 11:14:35 +010057 // Temporary helpers to send pre-built TransportFeedback rtcp packet.
58 uint32_t sender_ssrc() const { return config_.feedback_ssrc; }
59 void SendRawPacket(rtc::ArrayView<const uint8_t> packet);
Danil Chapovalovd3282292017-11-13 13:46:02 +010060
Danil Chapovalov327c43c2017-11-27 17:23:04 +010061 void SendNack(uint32_t ssrc, std::vector<uint16_t> sequence_numbers);
62
Danil Chapovalov8d19e032017-11-28 19:53:33 +010063 void SendPictureLossIndication(uint32_t ssrc);
Danil Chapovalov2ddf98d2017-11-22 14:00:41 +010064 void SendFullIntraRequest(rtc::ArrayView<const uint32_t> ssrcs);
Danil Chapovalova7e418c2017-11-21 11:08:53 +010065
Per Kjellander16999812019-10-10 12:57:28 +020066 // SendCombinedRtcpPacket ignores rtcp mode and does not send a compound
67 // message. https://tools.ietf.org/html/rfc4585#section-3.1
68 void SendCombinedRtcpPacket(
69 std::vector<std::unique_ptr<rtcp::RtcpPacket>> rtcp_packets);
70
Danil Chapovalov398a7c62017-10-24 17:07:05 +020071 private:
Danil Chapovalova7e418c2017-11-21 11:08:53 +010072 class PacketSender;
Danil Chapovalov2ddf98d2017-11-22 14:00:41 +010073 struct RemoteSenderState;
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010074
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010075 void HandleReceivedPacket(const rtcp::CommonHeader& rtcp_packet_header,
76 int64_t now_us);
Danil Chapovalov7ca9ae22017-12-13 12:26:17 +010077 // Individual rtcp packet handlers.
78 void HandleBye(const rtcp::CommonHeader& rtcp_packet_header);
Danil Chapovalov319a6752017-11-30 14:56:52 +010079 void HandleSenderReport(const rtcp::CommonHeader& rtcp_packet_header,
80 int64_t now_us);
81 void HandleExtendedReports(const rtcp::CommonHeader& rtcp_packet_header,
82 int64_t now_us);
Danil Chapovalov7ca9ae22017-12-13 12:26:17 +010083 // Extended Reports blocks handlers.
84 void HandleDlrr(const rtcp::Dlrr& dlrr, int64_t now_us);
85 void HandleTargetBitrate(const rtcp::TargetBitrate& target_bitrate,
86 uint32_t remote_ssrc);
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010087
Danil Chapovalova7e418c2017-11-21 11:08:53 +010088 void ReschedulePeriodicCompoundPackets();
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010089 void SchedulePeriodicCompoundPackets(int64_t delay_ms);
Danil Chapovalova7e418c2017-11-21 11:08:53 +010090 // Creates compound RTCP packet, as defined in
91 // https://tools.ietf.org/html/rfc5506#section-2
92 void CreateCompoundPacket(PacketSender* sender);
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010093 // Sends RTCP packets.
Danil Chapovalova7e418c2017-11-21 11:08:53 +010094 void SendPeriodicCompoundPacket();
Danil Chapovalov8d19e032017-11-28 19:53:33 +010095 void SendImmediateFeedback(const rtcp::RtcpPacket& rtcp_packet);
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010096 // Generate Report Blocks to be send in Sender or Receiver Report.
Danil Chapovalov319a6752017-11-30 14:56:52 +010097 std::vector<rtcp::ReportBlock> CreateReportBlocks(int64_t now_us);
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010098
Danil Chapovalov398a7c62017-10-24 17:07:05 +020099 const RtcpTransceiverConfig config_;
100
Danil Chapovalove3927c52018-03-06 14:33:20 +0100101 bool ready_to_send_;
Danil Chapovalovd264df52018-06-14 12:59:38 +0200102 absl::optional<rtcp::Remb> remb_;
Danil Chapovalov7ca9ae22017-12-13 12:26:17 +0100103 // TODO(danilchap): Remove entries from remote_senders_ that are no longer
104 // needed.
Danil Chapovalov2ddf98d2017-11-22 14:00:41 +0100105 std::map<uint32_t, RemoteSenderState> remote_senders_;
Sebastian Janssonecb68972019-01-18 10:30:54 +0100106 RepeatingTaskHandle periodic_task_handle_;
Danil Chapovalov398a7c62017-10-24 17:07:05 +0200107};
108
109} // namespace webrtc
110
111#endif // MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_IMPL_H_