blob: 083f77e379e7ba2dec25718d3049c173a5f6f906 [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
Danil Chapovalov398a7c62017-10-24 17:07:05 +020066 private:
Danil Chapovalova7e418c2017-11-21 11:08:53 +010067 class PacketSender;
Danil Chapovalov2ddf98d2017-11-22 14:00:41 +010068 struct RemoteSenderState;
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010069
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010070 void HandleReceivedPacket(const rtcp::CommonHeader& rtcp_packet_header,
71 int64_t now_us);
Danil Chapovalov7ca9ae22017-12-13 12:26:17 +010072 // Individual rtcp packet handlers.
73 void HandleBye(const rtcp::CommonHeader& rtcp_packet_header);
Danil Chapovalov319a6752017-11-30 14:56:52 +010074 void HandleSenderReport(const rtcp::CommonHeader& rtcp_packet_header,
75 int64_t now_us);
76 void HandleExtendedReports(const rtcp::CommonHeader& rtcp_packet_header,
77 int64_t now_us);
Danil Chapovalov7ca9ae22017-12-13 12:26:17 +010078 // Extended Reports blocks handlers.
79 void HandleDlrr(const rtcp::Dlrr& dlrr, int64_t now_us);
80 void HandleTargetBitrate(const rtcp::TargetBitrate& target_bitrate,
81 uint32_t remote_ssrc);
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010082
Danil Chapovalova7e418c2017-11-21 11:08:53 +010083 void ReschedulePeriodicCompoundPackets();
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010084 void SchedulePeriodicCompoundPackets(int64_t delay_ms);
Danil Chapovalova7e418c2017-11-21 11:08:53 +010085 // Creates compound RTCP packet, as defined in
86 // https://tools.ietf.org/html/rfc5506#section-2
87 void CreateCompoundPacket(PacketSender* sender);
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010088 // Sends RTCP packets.
Danil Chapovalova7e418c2017-11-21 11:08:53 +010089 void SendPeriodicCompoundPacket();
Danil Chapovalov8d19e032017-11-28 19:53:33 +010090 void SendImmediateFeedback(const rtcp::RtcpPacket& rtcp_packet);
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010091 // Generate Report Blocks to be send in Sender or Receiver Report.
Danil Chapovalov319a6752017-11-30 14:56:52 +010092 std::vector<rtcp::ReportBlock> CreateReportBlocks(int64_t now_us);
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010093
Danil Chapovalov398a7c62017-10-24 17:07:05 +020094 const RtcpTransceiverConfig config_;
95
Danil Chapovalove3927c52018-03-06 14:33:20 +010096 bool ready_to_send_;
Danil Chapovalovd264df52018-06-14 12:59:38 +020097 absl::optional<rtcp::Remb> remb_;
Danil Chapovalov7ca9ae22017-12-13 12:26:17 +010098 // TODO(danilchap): Remove entries from remote_senders_ that are no longer
99 // needed.
Danil Chapovalov2ddf98d2017-11-22 14:00:41 +0100100 std::map<uint32_t, RemoteSenderState> remote_senders_;
Sebastian Janssonecb68972019-01-18 10:30:54 +0100101 RepeatingTaskHandle periodic_task_handle_;
Danil Chapovalov398a7c62017-10-24 17:07:05 +0200102};
103
104} // namespace webrtc
105
106#endif // MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_IMPL_H_