blob: abbc40fe03048298fb843669395aa32e8ff25fdf [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
19#include "api/array_view.h"
Danil Chapovalovd3282292017-11-13 13:46:02 +010020#include "api/optional.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"
27#include "rtc_base/constructormagic.h"
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010028#include "rtc_base/weak_ptr.h"
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010029#include "system_wrappers/include/ntp_time.h"
Danil Chapovalov398a7c62017-10-24 17:07:05 +020030
31namespace webrtc {
32//
33// Manage incoming and outgoing rtcp messages for multiple BUNDLED streams.
34//
35// This class is not thread-safe.
36class RtcpTransceiverImpl {
37 public:
38 explicit RtcpTransceiverImpl(const RtcpTransceiverConfig& config);
39 ~RtcpTransceiverImpl();
40
Danil Chapovalova32d7102017-12-14 17:28:27 +010041 void AddMediaReceiverRtcpObserver(uint32_t remote_ssrc,
42 MediaReceiverRtcpObserver* observer);
43 void RemoveMediaReceiverRtcpObserver(uint32_t remote_ssrc,
44 MediaReceiverRtcpObserver* observer);
Danil Chapovalov7ca9ae22017-12-13 12:26:17 +010045
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010046 void ReceivePacket(rtc::ArrayView<const uint8_t> packet, int64_t now_us);
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010047
Danil Chapovalov398a7c62017-10-24 17:07:05 +020048 void SendCompoundPacket();
49
Danil Chapovalov1de4b622017-12-13 13:35:10 +010050 void SetRemb(int64_t bitrate_bps, std::vector<uint32_t> ssrcs);
Danil Chapovalovd3282292017-11-13 13:46:02 +010051 void UnsetRemb();
Danil Chapovalovd5cae4d2017-12-14 11:14:35 +010052 // Temporary helpers to send pre-built TransportFeedback rtcp packet.
53 uint32_t sender_ssrc() const { return config_.feedback_ssrc; }
54 void SendRawPacket(rtc::ArrayView<const uint8_t> packet);
Danil Chapovalovd3282292017-11-13 13:46:02 +010055
Danil Chapovalov327c43c2017-11-27 17:23:04 +010056 void SendNack(uint32_t ssrc, std::vector<uint16_t> sequence_numbers);
57
Danil Chapovalov8d19e032017-11-28 19:53:33 +010058 void SendPictureLossIndication(uint32_t ssrc);
Danil Chapovalov2ddf98d2017-11-22 14:00:41 +010059 void SendFullIntraRequest(rtc::ArrayView<const uint32_t> ssrcs);
Danil Chapovalova7e418c2017-11-21 11:08:53 +010060
Danil Chapovalov398a7c62017-10-24 17:07:05 +020061 private:
Danil Chapovalova7e418c2017-11-21 11:08:53 +010062 class PacketSender;
Danil Chapovalov2ddf98d2017-11-22 14:00:41 +010063 struct RemoteSenderState;
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010064
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010065 void HandleReceivedPacket(const rtcp::CommonHeader& rtcp_packet_header,
66 int64_t now_us);
Danil Chapovalov7ca9ae22017-12-13 12:26:17 +010067 // Individual rtcp packet handlers.
68 void HandleBye(const rtcp::CommonHeader& rtcp_packet_header);
Danil Chapovalov319a6752017-11-30 14:56:52 +010069 void HandleSenderReport(const rtcp::CommonHeader& rtcp_packet_header,
70 int64_t now_us);
71 void HandleExtendedReports(const rtcp::CommonHeader& rtcp_packet_header,
72 int64_t now_us);
Danil Chapovalov7ca9ae22017-12-13 12:26:17 +010073 // Extended Reports blocks handlers.
74 void HandleDlrr(const rtcp::Dlrr& dlrr, int64_t now_us);
75 void HandleTargetBitrate(const rtcp::TargetBitrate& target_bitrate,
76 uint32_t remote_ssrc);
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010077
Danil Chapovalova7e418c2017-11-21 11:08:53 +010078 void ReschedulePeriodicCompoundPackets();
Danil Chapovalovc0fd5f92017-11-16 14:35:32 +010079 void SchedulePeriodicCompoundPackets(int64_t delay_ms);
Danil Chapovalova7e418c2017-11-21 11:08:53 +010080 // Creates compound RTCP packet, as defined in
81 // https://tools.ietf.org/html/rfc5506#section-2
82 void CreateCompoundPacket(PacketSender* sender);
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010083 // Sends RTCP packets.
Danil Chapovalova7e418c2017-11-21 11:08:53 +010084 void SendPeriodicCompoundPacket();
Danil Chapovalov8d19e032017-11-28 19:53:33 +010085 void SendImmediateFeedback(const rtcp::RtcpPacket& rtcp_packet);
Danil Chapovalovd2f37d82017-11-09 15:42:28 +010086 // Generate Report Blocks to be send in Sender or Receiver Report.
Danil Chapovalov319a6752017-11-30 14:56:52 +010087 std::vector<rtcp::ReportBlock> CreateReportBlocks(int64_t now_us);
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010088
Danil Chapovalov398a7c62017-10-24 17:07:05 +020089 const RtcpTransceiverConfig config_;
90
Danil Chapovalovd3282292017-11-13 13:46:02 +010091 rtc::Optional<rtcp::Remb> remb_;
Danil Chapovalov7ca9ae22017-12-13 12:26:17 +010092 // TODO(danilchap): Remove entries from remote_senders_ that are no longer
93 // needed.
Danil Chapovalov2ddf98d2017-11-22 14:00:41 +010094 std::map<uint32_t, RemoteSenderState> remote_senders_;
Danil Chapovalov8c8d49e2017-10-30 15:21:41 +010095 rtc::WeakPtrFactory<RtcpTransceiverImpl> ptr_factory_;
96
Danil Chapovalov398a7c62017-10-24 17:07:05 +020097 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(RtcpTransceiverImpl);
98};
99
100} // namespace webrtc
101
102#endif // MODULES_RTP_RTCP_SOURCE_RTCP_TRANSCEIVER_IMPL_H_